154 * @var array|null |
163 * @var array|null |
155 */ |
164 */ |
156 public $provides_context = null; |
165 public $provides_context = null; |
157 |
166 |
158 /** |
167 /** |
159 * Block type editor script handle. |
168 * Block type editor only script handle. |
160 * |
169 * |
161 * @since 5.0.0 |
170 * @since 5.0.0 |
162 * @var string|null |
171 * @var string|null |
163 */ |
172 */ |
164 public $editor_script = null; |
173 public $editor_script = null; |
165 |
174 |
166 /** |
175 /** |
167 * Block type front end script handle. |
176 * Block type front end and editor script handle. |
168 * |
177 * |
169 * @since 5.0.0 |
178 * @since 5.0.0 |
170 * @var string|null |
179 * @var string|null |
171 */ |
180 */ |
172 public $script = null; |
181 public $script = null; |
173 |
182 |
174 /** |
183 /** |
175 * Block type editor style handle. |
184 * Block type front end only script handle. |
|
185 * |
|
186 * @since 5.9.0 |
|
187 * @var string|null |
|
188 */ |
|
189 public $view_script = null; |
|
190 |
|
191 /** |
|
192 * Block type editor only style handle. |
176 * |
193 * |
177 * @since 5.0.0 |
194 * @since 5.0.0 |
178 * @var string|null |
195 * @var string|null |
179 */ |
196 */ |
180 public $editor_style = null; |
197 public $editor_style = null; |
181 |
198 |
182 /** |
199 /** |
183 * Block type front end style handle. |
200 * Block type front end and editor style handle. |
184 * |
201 * |
185 * @since 5.0.0 |
202 * @since 5.0.0 |
186 * @var string|null |
203 * @var string|null |
187 */ |
204 */ |
188 public $style = null; |
205 public $style = null; |
|
206 |
|
207 /** |
|
208 * Attributes supported by every block. |
|
209 * |
|
210 * @since 6.0.0 |
|
211 * @var array |
|
212 */ |
|
213 const GLOBAL_ATTRIBUTES = array( |
|
214 'lock' => array( 'type' => 'object' ), |
|
215 ); |
189 |
216 |
190 /** |
217 /** |
191 * Constructor. |
218 * Constructor. |
192 * |
219 * |
193 * Will populate object properties from the provided arguments. |
220 * Will populate object properties from the provided arguments. |
196 * @since 5.5.0 Added the `title`, `category`, `parent`, `icon`, `description`, |
223 * @since 5.5.0 Added the `title`, `category`, `parent`, `icon`, `description`, |
197 * `keywords`, `textdomain`, `styles`, `supports`, `example`, |
224 * `keywords`, `textdomain`, `styles`, `supports`, `example`, |
198 * `uses_context`, and `provides_context` properties. |
225 * `uses_context`, and `provides_context` properties. |
199 * @since 5.6.0 Added the `api_version` property. |
226 * @since 5.6.0 Added the `api_version` property. |
200 * @since 5.8.0 Added the `variations` property. |
227 * @since 5.8.0 Added the `variations` property. |
|
228 * @since 5.9.0 Added the `view_script` property. |
|
229 * @since 6.0.0 Added the `ancestor` property. |
201 * |
230 * |
202 * @see register_block_type() |
231 * @see register_block_type() |
203 * |
232 * |
204 * @param string $block_type Block type name including namespace. |
233 * @param string $block_type Block type name including namespace. |
205 * @param array|string $args { |
234 * @param array|string $args { |
210 * @type string $title Human-readable block type label. |
239 * @type string $title Human-readable block type label. |
211 * @type string|null $category Block type category classification, used in |
240 * @type string|null $category Block type category classification, used in |
212 * search interfaces to arrange block types by category. |
241 * search interfaces to arrange block types by category. |
213 * @type array|null $parent Setting parent lets a block require that it is only |
242 * @type array|null $parent Setting parent lets a block require that it is only |
214 * available when nested within the specified blocks. |
243 * available when nested within the specified blocks. |
|
244 * @type array|null $ancestor Setting ancestor makes a block available only inside the specified |
|
245 * block types at any position of the ancestor's block subtree. |
215 * @type string|null $icon Block type icon. |
246 * @type string|null $icon Block type icon. |
216 * @type string $description A detailed block type description. |
247 * @type string $description A detailed block type description. |
217 * @type array $keywords Additional keywords to produce block type as |
248 * @type string[] $keywords Additional keywords to produce block type as |
218 * result in search interfaces. |
249 * result in search interfaces. |
219 * @type string|null $textdomain The translation textdomain. |
250 * @type string|null $textdomain The translation textdomain. |
220 * @type array $styles Alternative block styles. |
251 * @type array $styles Alternative block styles. |
221 * @type array $variations Block variations. |
252 * @type array $variations Block variations. |
222 * @type array|null $supports Supported features. |
253 * @type array|null $supports Supported features. |
223 * @type array|null $example Structured data for the block preview. |
254 * @type array|null $example Structured data for the block preview. |
224 * @type callable|null $render_callback Block type render callback. |
255 * @type callable|null $render_callback Block type render callback. |
225 * @type array|null $attributes Block type attributes property schemas. |
256 * @type array|null $attributes Block type attributes property schemas. |
226 * @type array $uses_context Context values inherited by blocks of this type. |
257 * @type array $uses_context Context values inherited by blocks of this type. |
227 * @type array|null $provides_context Context provided by blocks of this type. |
258 * @type array|null $provides_context Context provided by blocks of this type. |
228 * @type string|null $editor_script Block type editor script handle. |
259 * @type string|null $editor_script Block type editor only script handle. |
229 * @type string|null $script Block type front end script handle. |
260 * @type string|null $script Block type front end and editor script handle. |
230 * @type string|null $editor_style Block type editor style handle. |
261 * @type string|null $view_script Block type front end only script handle. |
231 * @type string|null $style Block type front end style handle. |
262 * @type string|null $editor_style Block type editor only style handle. |
|
263 * @type string|null $style Block type front end and editor style handle. |
232 * } |
264 * } |
233 */ |
265 */ |
234 public function __construct( $block_type, $args = array() ) { |
266 public function __construct( $block_type, $args = array() ) { |
235 $this->name = $block_type; |
267 $this->name = $block_type; |
236 |
268 |
330 'render_callback' => null, |
362 'render_callback' => null, |
331 ) |
363 ) |
332 ); |
364 ); |
333 |
365 |
334 $args['name'] = $this->name; |
366 $args['name'] = $this->name; |
|
367 |
|
368 // Setup attributes if needed. |
|
369 if ( ! isset( $args['attributes'] ) || ! is_array( $args['attributes'] ) ) { |
|
370 $args['attributes'] = array(); |
|
371 } |
|
372 |
|
373 // Register core attributes. |
|
374 foreach ( static::GLOBAL_ATTRIBUTES as $attr_key => $attr_schema ) { |
|
375 if ( ! array_key_exists( $attr_key, $args['attributes'] ) ) { |
|
376 $args['attributes'][ $attr_key ] = $attr_schema; |
|
377 } |
|
378 } |
335 |
379 |
336 /** |
380 /** |
337 * Filters the arguments for registering a block type. |
381 * Filters the arguments for registering a block type. |
338 * |
382 * |
339 * @since 5.5.0 |
383 * @since 5.5.0 |