Editor: Add missing `blocks` origin to `theme.json`.
This changeset updates the blocks origin name from core to blocks and adds it to the list of valid origins for `theme.json`. (See the original fix in [https://github.com//pull/3319 Gutenberg's PR 44363]). Why? - This new origin was missing from the list. - The `core` name is not reflective of what it does, as this data origin is related to block styles, whether they come with WordPress or third-party blocks. - The existing filter for this piece of data is called `theme_json_blocks`, to reflect it filters "block" data. - Though `core` origin was used in the past for `default`, this commit reverts it. Why? It was confusing. The goal is to use names that communicate what part of the pipeline are processing (`default > blocks > theme > custom`). How? - Renames the string, from `core` to `blocks`. - Adds `blocks` to the list of valid origins. - Verifies that the `$theme_json->get_stylesheet()` call uses the proper `$origins` at all times. Follow-up to [54162], [54251]. Props oandregal, czapla, jorgefilipecosta, scruffian, bernhard-reiter hellofromTonya. See #56467. Built from https://develop.svn.wordpress.org/trunk@54408 git-svn-id: http://core.svn.wordpress.org/trunk@53967 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a1518e3bc4
commit
ae50e2c014
|
@ -295,12 +295,10 @@ class WP_Theme_JSON_Resolver {
|
||||||
*
|
*
|
||||||
* @param WP_Theme_JSON_Data Class to access and update the underlying 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();
|
$config = $theme_json->get_data();
|
||||||
|
|
||||||
// Core here means it's the lower level part of the styles chain.
|
return new WP_Theme_JSON( $config, 'blocks' );
|
||||||
// It can be a core or a third-party block.
|
|
||||||
return new WP_Theme_JSON( $config, 'core' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -50,10 +50,12 @@ class WP_Theme_JSON {
|
||||||
* The sources of data this object can represent.
|
* The sources of data this object can represent.
|
||||||
*
|
*
|
||||||
* @since 5.8.0
|
* @since 5.8.0
|
||||||
|
* @since 6.1.0 Added 'blocks'.
|
||||||
* @var string[]
|
* @var string[]
|
||||||
*/
|
*/
|
||||||
const VALID_ORIGINS = array(
|
const VALID_ORIGINS = array(
|
||||||
'default',
|
'default',
|
||||||
|
'blocks',
|
||||||
'theme',
|
'theme',
|
||||||
'custom',
|
'custom',
|
||||||
);
|
);
|
||||||
|
|
|
@ -113,15 +113,21 @@ function wp_get_global_stylesheet( $types = array() ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If variables are part of the stylesheet,
|
* If variables are part of the stylesheet, then add them.
|
||||||
* we add them for all origins (default, theme, user).
|
|
||||||
* This is so themes without a theme.json still work as before 5.9:
|
* This is so themes without a theme.json still work as before 5.9:
|
||||||
* they can override the default presets.
|
* they can override the default presets.
|
||||||
* See https://core.trac.wordpress.org/ticket/54782
|
* See https://core.trac.wordpress.org/ticket/54782
|
||||||
*/
|
*/
|
||||||
$styles_variables = '';
|
$styles_variables = '';
|
||||||
if ( in_array( 'variables', $types, true ) ) {
|
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' ) );
|
$types = array_diff( $types, array( 'variables' ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +139,12 @@ function wp_get_global_stylesheet( $types = array() ) {
|
||||||
*/
|
*/
|
||||||
$styles_rest = '';
|
$styles_rest = '';
|
||||||
if ( ! empty( $types ) ) {
|
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' );
|
$origins = array( 'default', 'theme', 'custom' );
|
||||||
if ( ! $supports_theme_json ) {
|
if ( ! $supports_theme_json ) {
|
||||||
$origins = array( 'default' );
|
$origins = array( 'default' );
|
||||||
|
@ -204,6 +216,11 @@ function wp_add_global_styles_for_blocks() {
|
||||||
foreach ( $block_nodes as $metadata ) {
|
foreach ( $block_nodes as $metadata ) {
|
||||||
$block_css = $tree->get_styles_for_block( $metadata );
|
$block_css = $tree->get_styles_for_block( $metadata );
|
||||||
|
|
||||||
|
if ( ! wp_should_load_separate_core_block_assets() ) {
|
||||||
|
wp_add_inline_style( 'global-styles', $block_css );
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset( $metadata['name'] ) ) {
|
if ( isset( $metadata['name'] ) ) {
|
||||||
$block_name = str_replace( 'core/', '', $metadata['name'] );
|
$block_name = str_replace( 'core/', '', $metadata['name'] );
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -2409,14 +2409,11 @@ function wp_enqueue_global_styles() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we are loading CSS for each block separately, then we can load the theme.json CSS conditionally.
|
* If loading the CSS for each block separately, then load the theme.json CSS conditionally.
|
||||||
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
|
* This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
|
||||||
|
* This filter must be registered before calling wp_get_global_stylesheet();
|
||||||
*/
|
*/
|
||||||
if ( $separate_assets ) {
|
add_filter( 'theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
|
||||||
add_filter( 'theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
|
|
||||||
// Add each block as an inline css.
|
|
||||||
wp_add_global_styles_for_blocks();
|
|
||||||
}
|
|
||||||
|
|
||||||
$stylesheet = wp_get_global_stylesheet();
|
$stylesheet = wp_get_global_stylesheet();
|
||||||
|
|
||||||
|
@ -2427,6 +2424,9 @@ function wp_enqueue_global_styles() {
|
||||||
wp_register_style( 'global-styles', false, array(), true, true );
|
wp_register_style( 'global-styles', false, array(), true, true );
|
||||||
wp_add_inline_style( 'global-styles', $stylesheet );
|
wp_add_inline_style( 'global-styles', $stylesheet );
|
||||||
wp_enqueue_style( 'global-styles' );
|
wp_enqueue_style( 'global-styles' );
|
||||||
|
|
||||||
|
// Add each block as an inline css.
|
||||||
|
wp_add_global_styles_for_blocks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.1-beta3-54407';
|
$wp_version = '6.1-beta3-54408';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue