From 43a50913d6d594e2abb99d7c0d24f8a306845230 Mon Sep 17 00:00:00 2001 From: isabel_brison Date: Fri, 8 Sep 2023 00:26:21 +0000 Subject: [PATCH] Editor: performance enhancements to `class-wp-theme-json`. Removes unnecessary sanitisation of hardcoded strings and avoids looping over style presets without classes or variables. Props flixos90. Fixes #59304. Built from https://develop.svn.wordpress.org/trunk@56545 git-svn-id: http://core.svn.wordpress.org/trunk@56057 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-wp-theme-json.php | 10 ++++++++-- wp-includes/version.php | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-includes/class-wp-theme-json.php b/wp-includes/class-wp-theme-json.php index e482799f4f..f4442471e1 100644 --- a/wp-includes/class-wp-theme-json.php +++ b/wp-includes/class-wp-theme-json.php @@ -1313,7 +1313,7 @@ class WP_Theme_JSON { continue; } - $class_name = sanitize_title( _wp_array_get( $layout_definition, array( 'className' ), false ) ); + $class_name = _wp_array_get( $layout_definition, array( 'className' ), false ); $spacing_rules = _wp_array_get( $layout_definition, array( 'spacingStyles' ), array() ); if ( @@ -1370,7 +1370,7 @@ class WP_Theme_JSON { ) { $valid_display_modes = array( 'block', 'flex', 'grid' ); foreach ( $layout_definitions as $layout_definition ) { - $class_name = sanitize_title( _wp_array_get( $layout_definition, array( 'className' ), false ) ); + $class_name = _wp_array_get( $layout_definition, array( 'className' ), false ); $base_style_rules = _wp_array_get( $layout_definition, array( 'baseStyles' ), array() ); if ( @@ -1567,6 +1567,9 @@ class WP_Theme_JSON { $stylesheet = ''; foreach ( static::PRESETS_METADATA as $preset_metadata ) { + if ( empty( $preset_metadata['classes'] ) ) { + continue; + } $slugs = static::get_settings_slugs( $settings, $preset_metadata, $origins ); foreach ( $preset_metadata['classes'] as $class => $property ) { foreach ( $slugs as $slug ) { @@ -1764,6 +1767,9 @@ class WP_Theme_JSON { protected static function compute_preset_vars( $settings, $origins ) { $declarations = array(); foreach ( static::PRESETS_METADATA as $preset_metadata ) { + if ( empty( $preset_metadata['css_vars'] ) ) { + continue; + } $values_by_slug = static::get_settings_values_by_slug( $settings, $preset_metadata, $origins ); foreach ( $values_by_slug as $slug => $value ) { $declarations[] = array( diff --git a/wp-includes/version.php b/wp-includes/version.php index a19fb27f3c..3d24c8f562 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56544'; +$wp_version = '6.4-alpha-56545'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.