-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Theme Json: Don't output double selectors for elements inside blocks (#…
- Loading branch information
Showing
5 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
/** | ||
* WP_Theme_JSON_Gutenberg class | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Class that encapsulates the processing of structures that adhere to the theme.json spec. | ||
* | ||
* This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes). | ||
* This is a low-level API that may need to do breaking changes. Please, | ||
* use get_global_settings, get_global_styles, and get_global_stylesheet instead. | ||
* | ||
* @access private | ||
*/ | ||
class WP_Theme_JSON_6_1 extends WP_Theme_JSON_6_0 { | ||
/** | ||
* Returns the metadata for each block. | ||
* | ||
* Example: | ||
* | ||
* { | ||
* 'core/paragraph': { | ||
* 'selector': 'p', | ||
* 'elements': { | ||
* 'link' => '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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
/** | ||
* WP_Theme_JSON_Gutenberg class | ||
* | ||
* @package gutenberg | ||
*/ | ||
|
||
/** | ||
* Class that encapsulates the processing of structures that adhere to the theme.json spec. | ||
* | ||
* This class is for internal core usage and is not supposed to be used by extenders (plugins and/or themes). | ||
* This is a low-level API that may need to do breaking changes. Please, | ||
* use get_global_settings, get_global_styles, and get_global_stylesheet instead. | ||
* | ||
* @access private | ||
*/ | ||
class WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_6_1 { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters