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: https://github.com/WordPress/gutenberg/pull/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
This commit is contained in:
parent
47ef384731
commit
56145f874a
|
@ -2178,6 +2178,7 @@ function taxonomy_meta_box_sanitize_cb_input( $taxonomy, $terms ) {
|
||||||
* of a block relevant for client registration.
|
* of a block relevant for client registration.
|
||||||
*
|
*
|
||||||
* @since 5.0.0
|
* @since 5.0.0
|
||||||
|
* @since 6.3.0 Added `selectors` field.
|
||||||
*
|
*
|
||||||
* @return array An associative array of registered block data.
|
* @return array An associative array of registered block data.
|
||||||
*/
|
*/
|
||||||
|
@ -2192,6 +2193,7 @@ function get_block_editor_server_block_settings() {
|
||||||
'attributes' => 'attributes',
|
'attributes' => 'attributes',
|
||||||
'provides_context' => 'providesContext',
|
'provides_context' => 'providesContext',
|
||||||
'uses_context' => 'usesContext',
|
'uses_context' => 'usesContext',
|
||||||
|
'selectors' => 'selectors',
|
||||||
'supports' => 'supports',
|
'supports' => 'supports',
|
||||||
'category' => 'category',
|
'category' => 'category',
|
||||||
'styles' => 'styles',
|
'styles' => 'styles',
|
||||||
|
|
|
@ -300,6 +300,7 @@ function get_block_metadata_i18n_schema() {
|
||||||
* @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields.
|
* @since 5.7.0 Added support for `textdomain` field and i18n handling for all translatable fields.
|
||||||
* @since 5.9.0 Added support for `variations` and `viewScript` fields.
|
* @since 5.9.0 Added support for `variations` and `viewScript` fields.
|
||||||
* @since 6.1.0 Added support for `render` field.
|
* @since 6.1.0 Added support for `render` field.
|
||||||
|
* @since 6.3.0 Added `selectors` field.
|
||||||
*
|
*
|
||||||
* @param string $file_or_folder Path to the JSON file with metadata definition for
|
* @param string $file_or_folder Path to the JSON file with metadata definition for
|
||||||
* the block or path to the folder where the `block.json` file is located.
|
* 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() ) {
|
||||||
'attributes' => 'attributes',
|
'attributes' => 'attributes',
|
||||||
'providesContext' => 'provides_context',
|
'providesContext' => 'provides_context',
|
||||||
'usesContext' => 'uses_context',
|
'usesContext' => 'uses_context',
|
||||||
|
'selectors' => 'selectors',
|
||||||
'supports' => 'supports',
|
'supports' => 'supports',
|
||||||
'styles' => 'styles',
|
'styles' => 'styles',
|
||||||
'variations' => 'variations',
|
'variations' => 'variations',
|
||||||
|
|
|
@ -117,6 +117,14 @@ class WP_Block_Type {
|
||||||
*/
|
*/
|
||||||
public $variations = array();
|
public $variations = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom CSS selectors for theme.json style generation.
|
||||||
|
*
|
||||||
|
* @since 6.3.0
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public $selectors = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Supported features.
|
* Supported features.
|
||||||
*
|
*
|
||||||
|
@ -245,6 +253,7 @@ class WP_Block_Type {
|
||||||
* @since 6.1.0 Added the `editor_script_handles`, `script_handles`, `view_script_handles,
|
* @since 6.1.0 Added the `editor_script_handles`, `script_handles`, `view_script_handles,
|
||||||
* `editor_style_handles`, and `style_handles` properties.
|
* `editor_style_handles`, and `style_handles` properties.
|
||||||
* Deprecated the `editor_script`, `script`, `view_script`, `editor_style`, and `style` properties.
|
* Deprecated the `editor_script`, `script`, `view_script`, `editor_style`, and `style` properties.
|
||||||
|
* @since 6.3.0 Added the `selectors` property.
|
||||||
*
|
*
|
||||||
* @see register_block_type()
|
* @see register_block_type()
|
||||||
*
|
*
|
||||||
|
@ -268,6 +277,7 @@ class WP_Block_Type {
|
||||||
* @type string|null $textdomain The translation textdomain.
|
* @type string|null $textdomain The translation textdomain.
|
||||||
* @type array[] $styles Alternative block styles.
|
* @type array[] $styles Alternative block styles.
|
||||||
* @type array[] $variations Block variations.
|
* @type array[] $variations Block variations.
|
||||||
|
* @type array $selectors Custom CSS selectors for theme.json style generation.
|
||||||
* @type array|null $supports Supported features.
|
* @type array|null $supports Supported features.
|
||||||
* @type array|null $example Structured data for the block preview.
|
* @type array|null $example Structured data for the block preview.
|
||||||
* @type callable|null $render_callback Block type render callback.
|
* @type callable|null $render_callback Block type render callback.
|
||||||
|
|
|
@ -237,6 +237,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||||
*
|
*
|
||||||
* @since 5.5.0
|
* @since 5.5.0
|
||||||
* @since 5.9.0 Renamed `$block_type` to `$item` to match parent class for PHP 8 named parameter support.
|
* @since 5.9.0 Renamed `$block_type` to `$item` to match parent class for PHP 8 named parameter support.
|
||||||
|
* @since 6.3.0 Added `selectors` field.
|
||||||
*
|
*
|
||||||
* @param WP_Block_Type $item Block type data.
|
* @param WP_Block_Type $item Block type data.
|
||||||
* @param WP_REST_Request $request Full details about the request.
|
* @param WP_REST_Request $request Full details about the request.
|
||||||
|
@ -278,6 +279,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||||
'ancestor',
|
'ancestor',
|
||||||
'provides_context',
|
'provides_context',
|
||||||
'uses_context',
|
'uses_context',
|
||||||
|
'selectors',
|
||||||
'supports',
|
'supports',
|
||||||
'styles',
|
'styles',
|
||||||
'textdomain',
|
'textdomain',
|
||||||
|
@ -379,6 +381,7 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||||
* Retrieves the block type' schema, conforming to JSON Schema.
|
* Retrieves the block type' schema, conforming to JSON Schema.
|
||||||
*
|
*
|
||||||
* @since 5.5.0
|
* @since 5.5.0
|
||||||
|
* @since 6.3.0 Added `selectors` field.
|
||||||
*
|
*
|
||||||
* @return array Item schema data.
|
* @return array Item schema data.
|
||||||
*/
|
*/
|
||||||
|
@ -518,6 +521,14 @@ class WP_REST_Block_Types_Controller extends WP_REST_Controller {
|
||||||
'context' => array( 'embed', 'view', 'edit' ),
|
'context' => array( 'embed', 'view', 'edit' ),
|
||||||
'readonly' => true,
|
'readonly' => true,
|
||||||
),
|
),
|
||||||
|
'selectors' => array(
|
||||||
|
'description' => __( 'Custom CSS selectors.' ),
|
||||||
|
'type' => 'object',
|
||||||
|
'default' => array(),
|
||||||
|
'properties' => array(),
|
||||||
|
'context' => array( 'embed', 'view', 'edit' ),
|
||||||
|
'readonly' => true,
|
||||||
|
),
|
||||||
'supports' => array(
|
'supports' => array(
|
||||||
'description' => __( 'Block supports.' ),
|
'description' => __( 'Block supports.' ),
|
||||||
'type' => 'object',
|
'type' => 'object',
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.3-alpha-55672';
|
$wp_version = '6.3-alpha-55673';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue