Skip to content

Commit

Permalink
Editor: refactor and stabilize selectors API.
Browse files Browse the repository at this point in the history
Restructures the block.json selectors API by moving `__experimentalSelector` props into their own config, stabilizing the selectors API, and enabling more flexible styling options.

Props ramonopoly, spacedmonkey, aaronrobertshaw, onemaggie.
Fixes #58586.


git-svn-id: https://develop.svn.wordpress.org/trunk@56058 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
tellthemachines committed Jun 27, 2023
1 parent 456ebf5 commit 8b9d8d8
Show file tree
Hide file tree
Showing 4 changed files with 680 additions and 131 deletions.
16 changes: 11 additions & 5 deletions src/wp-includes/block-supports/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function _wp_add_block_level_presets_class( $block_content, $block ) {
* @internal
*
* @since 6.2.0
* @since 6.3.0 Updated preset styles to use Selectors API.
* @access private
*
* @param string|null $pre_render The pre-rendered content. Default null.
Expand Down Expand Up @@ -95,11 +96,16 @@ function _wp_add_block_level_preset_styles( $pre_render, $block ) {
$registry = WP_Block_Type_Registry::get_instance();
$blocks = $registry->get_all_registered();
foreach ( $blocks as $block_type ) {
if (
isset( $block_type->supports['__experimentalSelector'] ) &&
is_string( $block_type->supports['__experimentalSelector'] )
) {
$variables_root_selector .= ',' . $block_type->supports['__experimentalSelector'];
/*
* We only want to append selectors for block's using custom selectors
* i.e. not `wp-block-<name>`.
*/
$has_custom_selector =
( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) ||
( isset( $block_type->selectors['root'] ) && is_string( $block_type->selectors['root'] ) );

if ( $has_custom_selector ) {
$variables_root_selector .= ',' . wp_get_block_css_selector( $block_type );
}
}
$variables_root_selector = WP_Theme_JSON::scope_selector( $class_name, $variables_root_selector );
Expand Down
Loading

0 comments on commit 8b9d8d8

Please sign in to comment.