-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theme Json: Don't output double selectors for elements inside blocks #40889
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this here instead of naming
WP_Theme_JSON_Gutenberg
the class in6.1
? Is there a specific reason?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason is that when we come to add more compat versions of this file we need to change the class name to the specific version and add a new one to the next compat folder which can create conflicts. Keeping the
WP_Theme_JSON_Gutenberg
in experimental is more stable and predictable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I see any difference in having
WP_Theme_JSON_Gutenberg extends WP_Theme_JSON_6_0
in the6.1
folder. I thinkexperimental
is the folder for changes that are not planned for the next WP release - thus the name. If we know something is going to be in6.1
for example we should add it just there. --cc @gzioloThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's how things are done for this particular class that gets updated in every WordPress major release.