Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions src/wp-includes/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,8 +953,6 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
* @return string Filtered block content.
*/
function wp_render_layout_support_flag( $block_content, $block ) {
static $global_styles = null;

$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$block_supports_layout = block_has_support( $block_type, 'layout', false ) || block_has_support( $block_type, '__experimentalLayout', false );
$style_attr = $block['attrs']['style'] ?? array();
Expand Down Expand Up @@ -1167,10 +1165,8 @@ function wp_render_layout_support_flag( $block_content, $block ) {

// Get default blockGap value from global styles for use in layouts like grid.
// Check style variation first, then block-specific styles, then fall back to root styles.
$block_name = $block['blockName'] ?? '';
if ( null === $global_styles ) {
$global_styles = wp_get_global_styles();
}
$block_name = $block['blockName'] ?? '';
$global_styles = wp_get_global_styles();

// Check if the block has an active style variation with a blockGap value.
// Only check the registry if the className contains a variation class to avoid unnecessary lookups.
Expand Down
33 changes: 30 additions & 3 deletions src/wp-includes/global-styles-and-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,34 @@ function wp_get_global_styles( $path = array(), $context = array() ) {
&& is_array( $context['transforms'] )
&& in_array( 'resolve-variables', $context['transforms'], true );

$merged_data = WP_Theme_JSON_Resolver::get_merged_data( $origin );
$cache_group = 'theme_json';
$cache_key = 'wp_get_global_styles_' . $origin;
if ( $resolve_variables ) {
$merged_data = WP_Theme_JSON::resolve_variables( $merged_data );
$cache_key .= '_resolved';
}

/*
* Ignore cache when the development mode is set to 'theme', so it doesn't interfere with the theme
* developer's workflow.
*/
$can_use_cached = ! wp_is_development_mode( 'theme' );

$styles = false;
if ( $can_use_cached ) {
$styles = wp_cache_get( $cache_key, $cache_group );
}

if ( false === $styles ) {
$merged_data = WP_Theme_JSON_Resolver::get_merged_data( $origin );
if ( $resolve_variables ) {
$merged_data = WP_Theme_JSON::resolve_variables( $merged_data );
}
$styles = $merged_data->get_raw_data()['styles'];
if ( $can_use_cached ) {
wp_cache_set( $cache_key, $styles, $cache_group );
}
}
$styles = $merged_data->get_raw_data()['styles'];

return _wp_array_get( $styles, $path, $styles );
}

Expand Down Expand Up @@ -432,6 +455,10 @@ function wp_clean_theme_json_cache() {
wp_cache_delete( 'wp_get_global_styles_svg_filters', 'theme_json' );
wp_cache_delete( 'wp_get_global_settings_custom', 'theme_json' );
wp_cache_delete( 'wp_get_global_settings_theme', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_custom', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_custom_resolved', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_theme', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_theme_resolved', 'theme_json' );
wp_cache_delete( 'wp_get_global_styles_custom_css', 'theme_json' );
wp_cache_delete( 'wp_get_theme_data_template_parts', 'theme_json' );
WP_Theme_JSON_Resolver::clean_cached_data();
Expand Down
Loading