Make WordPress Core


Ignore:
Timestamp:
10/07/2022 09:38:15 AM (2 years ago)
Author:
audrasjb
Message:

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 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r54162 r54408  
    114114
    115115    /*
    116      * If variables are part of the stylesheet,
    117      * we add them for all origins (default, theme, user).
     116     * If variables are part of the stylesheet, then add them.
    118117     * This is so themes without a theme.json still work as before 5.9:
    119118     * they can override the default presets.
     
    122121    $styles_variables = '';
    123122    if ( in_array( 'variables', $types, true ) ) {
    124         $styles_variables = $tree->get_stylesheet( array( 'variables' ) );
     123        /*
     124         * Only use the default, theme, and custom origins. Why?
     125         * Because styles for `blocks` origin are added at a later phase
     126         * (i.e. in the render cycle). Here, only the ones in use are rendered.
     127         * @see wp_add_global_styles_for_blocks
     128         */
     129        $origins          = array( 'default', 'theme', 'custom' );
     130        $styles_variables = $tree->get_stylesheet( array( 'variables' ), $origins );
    125131        $types            = array_diff( $types, array( 'variables' ) );
    126132    }
     
    134140    $styles_rest = '';
    135141    if ( ! empty( $types ) ) {
     142        /*
     143         * Only use the default, theme, and custom origins. Why?
     144         * Because styles for `blocks` origin are added at a later phase
     145         * (i.e. in the render cycle). Here, only the ones in use are rendered.
     146         * @see wp_add_global_styles_for_blocks
     147         */
    136148        $origins = array( 'default', 'theme', 'custom' );
    137149        if ( ! $supports_theme_json ) {
     
    204216    foreach ( $block_nodes as $metadata ) {
    205217        $block_css = $tree->get_styles_for_block( $metadata );
     218
     219        if ( ! wp_should_load_separate_core_block_assets() ) {
     220            wp_add_inline_style( 'global-styles', $block_css );
     221            continue;
     222        }
    206223
    207224        if ( isset( $metadata['name'] ) ) {
Note: See TracChangeset for help on using the changeset viewer.