Skip to content

Commit 56145f8

Browse files
committed
Editor: Add selectors field to block type definition
Adds support for the new selectors property for block types. It adds it to the allowed metadata when registering a block type, makes the WP_Block_Type class aware of it, exposes it through the block types REST API, and the get_block_editor_server_block_settings function. Corresponding work in the Gutenberg plugin: WordPress/gutenberg#46496. Fixes #57585. Props aaronrobertshaw, hellofromTonya. Built from https://develop.svn.wordpress.org/trunk@55673 git-svn-id: http://core.svn.wordpress.org/trunk@55185 1a063a9b-81f0-0310-95a4-ce76da25c4cd
1 parent 47ef384 commit 56145f8

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

wp-admin/includes/post.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,6 +2178,7 @@ function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
21782178
* of a block relevant for client registration.
21792179
*
21802180
* @since 5.0.0
2181+
* @since 6.3.0 Added `selectors` field.
21812182
*
21822183
* @return array An associative array of registered block data.
21832184
*/
@@ -2192,6 +2193,7 @@ function get_block_editor_server_block_settings() {
21922193
'attributes' => 'attributes',
21932194
'provides_context' => 'providesContext',
21942195
'uses_context' => 'usesContext',
2196+
'selectors' => 'selectors',
21952197
'supports' => 'supports',
21962198
'category' => 'category',
21972199
'styles' => 'styles',

wp-includes/blocks.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ function get_block_metadata_i18n_schema() {
300300
* @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields.
301301
* @since 5.9.0 Added support for `variations` and `viewScript` fields.
302302
* @since 6.1.0 Added support for `render` field.
303+
* @since 6.3.0 Added `selectors` field.
303304
*
304305
* @param string $file_or_folder Path to the JSON file with metadata definition for
305306
* the block or path to the folder where the `block.json` file is located.
@@ -382,6 +383,7 @@ function register_block_type_from_metadata( $file_or_folder, $args = array() ) {
382383
'attributes' => 'attributes',
383384
'providesContext' => 'provides_context',
384385
'usesContext' => 'uses_context',
386+
'selectors' => 'selectors',
385387
'supports' => 'supports',
386388
'styles' => 'styles',
387389
'variations' => 'variations',

wp-includes/class-wp-block-type.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ class WP_Block_Type {
117117
*/
118118
public $variations = array();
119119

120+
/**
121+
* Custom CSS selectors for theme.json style generation.
122+
*
123+
* @since 6.3.0
124+
* @var array
125+
*/
126+
public $selectors = array();
127+
120128
/**
121129
* Supported features.
122130
*
@@ -245,6 +253,7 @@ class WP_Block_Type {
245253
* @since 6.1.0 Added the `editor_script_handles`, `script_handles`, `view_script_handles,
246254
* `editor_style_handles`, and `style_handles` properties.
247255
* Deprecated the `editor_script`, `script`, `view_script`, `editor_style`, and `style` properties.
256+
* @since 6.3.0 Added the `selectors` property.
248257
*
249258
* @see register_block_type()
250259
*
@@ -268,6 +277,7 @@ class WP_Block_Type {
268277
* @type string|null $textdomain The translation textdomain.
269278
* @type array[] $styles Alternative block styles.
270279
* @type array[] $variations Block variations.
280+
* @type array $selectors Custom CSS selectors for theme.json style generation.
271281
* @type array|null $supports Supported features.
272282
* @type array|null $example Structured data for the block preview.
273283
* @type callable|null $render_callback Block type render callback.

wp-includes/rest-api/endpoints/class-wp-rest-block-types-controller.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ public function get_item( $request ) {
237237
*
238238
* @since 5.5.0
239239
* @since 5.9.0 Renamed `$block_type` to `$item` to match parent class for PHP 8 named parameter support.
240+
* @since 6.3.0 Added `selectors` field.
240241
*
241242
* @param WP_Block_Type $item Block type data.
242243
* @param WP_REST_Request $request Full details about the request.
@@ -278,6 +279,7 @@ public function prepare_item_for_response( $item, $request ) {
278279
'ancestor',
279280
'provides_context',
280281
'uses_context',
282+
'selectors',
281283
'supports',
282284
'styles',
283285
'textdomain',
@@ -379,6 +381,7 @@ protected function prepare_links( $block_type ) {
379381
* Retrieves the block type' schema, conforming to JSON Schema.
380382
*
381383
* @since 5.5.0
384+
* @since 6.3.0 Added `selectors` field.
382385
*
383386
* @return array Item schema data.
384387
*/
@@ -518,6 +521,14 @@ public function get_item_schema() {
518521
'context' => array( 'embed', 'view', 'edit' ),
519522
'readonly' => true,
520523
),
524+
'selectors' => array(
525+
'description' => __( 'Custom CSS selectors.' ),
526+
'type' => 'object',
527+
'default' => array(),
528+
'properties' => array(),
529+
'context' => array( 'embed', 'view', 'edit' ),
530+
'readonly' => true,
531+
),
521532
'supports' => array(
522533
'description' => __( 'Block supports.' ),
523534
'type' => 'object',

wp-includes/version.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @global string $wp_version
1818
*/
19-
$wp_version = '6.3-alpha-55672';
19+
$wp_version = '6.3-alpha-55673';
2020

2121
/**
2222
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

0 commit comments

Comments
 (0)