Make WordPress Core


Ignore:
Timestamp:
06/17/2024 10:06:38 AM (2 years ago)
Author:
oandregal
Message:

Global Styles: Avoid unnecessary processing of theme.json variation partials.

Props aaronrobertshaw, oandregal, mukesh27.
See #61451.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-supports/block-style-variations.php

    r58422 r58423  
    475475 */
    476476function wp_register_block_style_variations_from_theme() {
     477        /*
     478         * Skip any registration of styles if no theme.json or variation partials are present.
     479         *
     480         * Given the possibility of hybrid themes, this check can't rely on if the theme
     481         * is a block theme or not. Instead:
     482         *   - If there is a primary theme.json, continue.
     483         *   - If there is a partials directory, continue.
     484         *   - The only variations to be registered from the global styles user origin,
     485         *     are those that have been copied in from the selected theme style variation.
     486         *     For a theme style variation to be selected it would have to have a partial
     487         *     theme.json file covered by the previous check.
     488         */
     489        $has_partials_directory = is_dir( get_stylesheet_directory() . '/styles' ) || is_dir( get_template_directory() . '/styles' );
     490        if ( ! wp_theme_has_theme_json() && ! $has_partials_directory ) {
     491                return;
     492        }
     493
    477494        // Partials from `/styles`.
    478495        $variations_partials = WP_Theme_JSON_Resolver::get_style_variations( 'block' );
Note: See TracChangeset for help on using the changeset viewer.