-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Add blocks
to the list of valid origins for theme.json
#44363
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,14 +92,22 @@ function gutenberg_get_global_stylesheet( $types = array() ) { | |
|
||
/* | ||
* If variables are part of the stylesheet, | ||
* we add them for all origins (default, theme, user). | ||
* we add them. | ||
* | ||
* This is so themes without a theme.json still work as before 5.9: | ||
* they can override the default presets. | ||
* See https://core.trac.wordpress.org/ticket/54782 | ||
*/ | ||
$styles_variables = ''; | ||
if ( in_array( 'variables', $types, true ) ) { | ||
$styles_variables = $tree->get_stylesheet( array( 'variables' ) ); | ||
/* | ||
* We only use the default, theme, and custom origins. | ||
* This is because styles for blocks origin are added | ||
* at a later phase (render cycle) so we only render the ones in use. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given that the styles are output in other parts of code, isn't there the risk that priority 'default', 'block, 'theme', and 'custom' is not respected? How do we ensure this order? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've looked for every usage of this function (including core) and all instances have been updated. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let me expand this. The Note that a filter |
||
* @see wp_add_global_styles_for_blocks | ||
*/ | ||
$origins = array( 'default', 'theme', 'custom' ); | ||
$styles_variables = $tree->get_stylesheet( array( 'variables' ), $origins ); | ||
$types = array_diff( $types, array( 'variables' ) ); | ||
} | ||
|
||
|
@@ -111,6 +119,12 @@ function gutenberg_get_global_stylesheet( $types = array() ) { | |
*/ | ||
$styles_rest = ''; | ||
if ( ! empty( $types ) ) { | ||
/* | ||
* We only use the default, theme, and custom origins. | ||
* This is because styles for blocks origin are added | ||
* at a later phase (render cycle) so we only render the ones in use. | ||
* @see wp_add_global_styles_for_blocks | ||
*/ | ||
$origins = array( 'default', 'theme', 'custom' ); | ||
if ( ! $supports_theme_json ) { | ||
$origins = array( 'default' ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,12 +141,10 @@ public static function get_block_data() { | |
* | ||
* @param WP_Theme_JSON_Data_Gutenberg Class to access and update the underlying data. | ||
*/ | ||
$theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'core' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changing this name here does not have any effect because it was not being used anywhere. It has started to be used when it was added to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By using an unregistered origin this is what was happening:
This was working as expected. But only by coincidence. If the blocks origin was able to define presets this won't work. The reason is it'll work this way:
Essentially, this is the sort of tricky dormant bug waiting to happen. |
||
$theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data_Gutenberg( $config, 'blocks' ) ); | ||
$config = $theme_json->get_data(); | ||
|
||
// Core here means it's the lower level part of the styles chain. | ||
// It can be a core or a third-party block. | ||
return new WP_Theme_JSON_Gutenberg( $config, 'core' ); | ||
return new WP_Theme_JSON_Gutenberg( $config, 'blocks' ); | ||
} | ||
|
||
/** | ||
|
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.
blocks was missing