Skip to content

Commit

Permalink
Add remaining changes from GB PR44363
Browse files Browse the repository at this point in the history
  • Loading branch information
hellofromtonya committed Sep 26, 2022
1 parent e006b20 commit 48c8fea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/wp-includes/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,12 +283,10 @@ public static function get_block_data() {
*
* @param WP_Theme_JSON_Data Class to access and update the underlying data.
*/
$theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data( $config, 'core' ) );
$theme_json = apply_filters( 'theme_json_blocks', new WP_Theme_JSON_Data( $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( $config, 'core' );
return new WP_Theme_JSON( $config, 'blocks' );
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ class WP_Theme_JSON {
* The sources of data this object can represent.
*
* @since 5.8.0
* @since 6.1.0 Added 'blocks'.
* @var string[]
*/
const VALID_ORIGINS = array(
'default',
'blocks',
'theme',
'custom',
);
Expand Down
18 changes: 15 additions & 3 deletions src/wp-includes/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,21 @@ function wp_get_global_stylesheet( $types = array() ) {
}

/*
* If variables are part of the stylesheet,
* we add them for all origins (default, theme, user).
* If variables are part of the stylesheet, then 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' ) );
/*
* Only use the default, theme, and custom origins. Why?
* Because styles for `blocks` origin are added at a later phase
* (i.e. in the render cycle). Here, only the ones in use are rendered.
* @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' ) );
}

Expand All @@ -133,6 +139,12 @@ function wp_get_global_stylesheet( $types = array() ) {
*/
$styles_rest = '';
if ( ! empty( $types ) ) {
/*
* Only use the default, theme, and custom origins. Why?
* Because styles for `blocks` origin are added at a later phase
* (i.e. in the render cycle). Here, only the ones in use are rendered.
* @see wp_add_global_styles_for_blocks
*/
$origins = array( 'default', 'theme', 'custom' );
if ( ! $supports_theme_json ) {
$origins = array( 'default' );
Expand Down

0 comments on commit 48c8fea

Please sign in to comment.