Skip to content

Commit

Permalink
Editor: performance enhancements to class-wp-theme-json.
Browse files Browse the repository at this point in the history
Removes unnecessary sanitisation of hardcoded strings and avoids looping over style presets without classes or variables.

Props flixos90.
Fixes #59304.


git-svn-id: https://develop.svn.wordpress.org/trunk@56545 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
tellthemachines committed Sep 8, 2023
1 parent 9de4142 commit b693aeb
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -1313,7 +1313,7 @@ protected function get_layout_styles( $block_metadata ) {
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 (
Expand Down Expand Up @@ -1370,7 +1370,7 @@ protected function get_layout_styles( $block_metadata ) {
) {
$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 (
Expand Down Expand Up @@ -1567,6 +1567,9 @@ protected static function compute_preset_classes( $settings, $selector, $origins

$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 ) {
Expand Down Expand Up @@ -1764,6 +1767,9 @@ protected static function replace_slug_in_string( $input, $slug ) {
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(
Expand Down

0 comments on commit b693aeb

Please sign in to comment.