diff --git a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php index 67e59062a4f903..19b8611df0a4d5 100644 --- a/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php +++ b/lib/compat/wordpress-5.9/class-wp-theme-json-5-9.php @@ -541,6 +541,11 @@ protected static function get_blocks_metadata() { foreach ( static::ELEMENTS as $el_name => $el_selector ) { $element_selector = array(); foreach ( $block_selectors as $selector ) { + if ( $selector === $el_selector ) { + $element_selector = array( $el_selector ); + break; + } + $element_selector[] = $selector . ' ' . $el_selector; } static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector ); diff --git a/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php b/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php similarity index 99% rename from lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php rename to lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php index 668082863114fa..1a0945b1754223 100644 --- a/lib/compat/wordpress-6.0/class-wp-theme-json-gutenberg.php +++ b/lib/compat/wordpress-6.0/class-wp-theme-json-6-0.php @@ -14,7 +14,7 @@ * * @access private */ -class WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_5_9 { +class WP_Theme_JSON_6_0 extends WP_Theme_JSON_5_9 { /** * Metadata for style properties. * diff --git a/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php new file mode 100644 index 00000000000000..cea9bd77cf17e6 --- /dev/null +++ b/lib/compat/wordpress-6.1/class-wp-theme-json-6-1.php @@ -0,0 +1,90 @@ + 'link selector', + * 'etc' => 'element selector' + * } + * }, + * 'core/heading': { + * 'selector': 'h1', + * 'elements': {} + * }, + * 'core/image': { + * 'selector': '.wp-block-image', + * 'duotone': 'img', + * 'elements': {} + * } + * } + * + * @return array Block metadata. + */ + protected static function get_blocks_metadata() { + if ( null !== static::$blocks_metadata ) { + return static::$blocks_metadata; + } + + static::$blocks_metadata = array(); + + $registry = WP_Block_Type_Registry::get_instance(); + $blocks = $registry->get_all_registered(); + foreach ( $blocks as $block_name => $block_type ) { + if ( + isset( $block_type->supports['__experimentalSelector'] ) && + is_string( $block_type->supports['__experimentalSelector'] ) + ) { + static::$blocks_metadata[ $block_name ]['selector'] = $block_type->supports['__experimentalSelector']; + } else { + static::$blocks_metadata[ $block_name ]['selector'] = '.wp-block-' . str_replace( '/', '-', str_replace( 'core/', '', $block_name ) ); + } + + if ( + isset( $block_type->supports['color']['__experimentalDuotone'] ) && + is_string( $block_type->supports['color']['__experimentalDuotone'] ) + ) { + static::$blocks_metadata[ $block_name ]['duotone'] = $block_type->supports['color']['__experimentalDuotone']; + } + + // Assign defaults, then overwrite those that the block sets by itself. + // If the block selector is compounded, will append the element to each + // individual block selector. + $block_selectors = explode( ',', static::$blocks_metadata[ $block_name ]['selector'] ); + foreach ( static::ELEMENTS as $el_name => $el_selector ) { + $element_selector = array(); + foreach ( $block_selectors as $selector ) { + if ( $selector === $el_selector ) { + $element_selector = array( $el_selector ); + break; + } + + $element_selector[] = $selector . ' ' . $el_selector; + } + static::$blocks_metadata[ $block_name ]['elements'][ $el_name ] = implode( ',', $element_selector ); + } + } + + return static::$blocks_metadata; + } +} diff --git a/lib/experimental/class-wp-theme-json-gutenberg.php b/lib/experimental/class-wp-theme-json-gutenberg.php new file mode 100644 index 00000000000000..3d6bf949e7f835 --- /dev/null +++ b/lib/experimental/class-wp-theme-json-gutenberg.php @@ -0,0 +1,19 @@ +