Make WordPress Core

Changeset 59253


Ignore:
Timestamp:
10/18/2024 02:24:46 PM (7 weeks ago)
Author:
joemcgill
Message:

Editor: Improve performance of WP_Theme_JSON::compute_style_properties

This improves the logic in WP_Theme_JSON::compute_style_properties to address a number of performance issues.

Props spacedmonkey.
Fixes #59595.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-theme-json.php

    r59213 r59253  
    23152315     */
    23162316    protected static function compute_style_properties( $styles, $settings = array(), $properties = null, $theme_json = null, $selector = null, $use_root_padding = null ) {
     2317        if ( empty( $styles ) ) {
     2318            return array();
     2319        }
     2320
    23172321        if ( null === $properties ) {
    23182322            $properties = static::PROPERTIES_METADATA;
    23192323        }
    2320 
    2321         $declarations = array();
    2322         if ( empty( $styles ) ) {
    2323             return $declarations;
    2324         }
    2325 
     2324        $declarations             = array();
    23262325        $root_variable_duplicates = array();
     2326        $root_style_length        = strlen( '--wp--style--root--' );
    23272327
    23282328        foreach ( $properties as $css_property => $value_path ) {
     2329            if ( ! is_array( $value_path ) ) {
     2330                continue;
     2331            }
     2332
     2333            $is_root_style = str_starts_with( $css_property, '--wp--style--root--' );
     2334            if ( $is_root_style && ( static::ROOT_BLOCK_SELECTOR !== $selector || ! $use_root_padding ) ) {
     2335                continue;
     2336            }
     2337
    23292338            $value = static::get_property_value( $styles, $value_path, $theme_json );
    23302339
    2331             if ( str_starts_with( $css_property, '--wp--style--root--' ) && ( static::ROOT_BLOCK_SELECTOR !== $selector || ! $use_root_padding ) ) {
    2332                 continue;
    2333             }
    23342340            /*
    23352341             * Root-level padding styles don't currently support strings with CSS shorthand values.
     
    23402346            }
    23412347
    2342             if ( str_starts_with( $css_property, '--wp--style--root--' ) && $use_root_padding ) {
    2343                 $root_variable_duplicates[] = substr( $css_property, strlen( '--wp--style--root--' ) );
    2344             }
    2345 
    2346             /*
    2347              * Look up protected properties, keyed by value path.
    2348              * Skip protected properties that are explicitly set to `null`.
    2349              */
    2350             if ( is_array( $value_path ) ) {
    2351                 $path_string = implode( '.', $value_path );
    2352                 if (
    2353                     isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
    2354                     _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
    2355                 ) {
    2356                     continue;
    2357                 }
     2348            if ( $is_root_style && $use_root_padding ) {
     2349                $root_variable_duplicates[] = substr( $css_property, $root_style_length );
    23582350            }
    23592351
     
    23842376            $has_missing_value = empty( $value ) && ! is_numeric( $value );
    23852377            if ( $has_missing_value || is_array( $value ) ) {
     2378                continue;
     2379            }
     2380
     2381            /*
     2382             * Look up protected properties, keyed by value path.
     2383             * Skip protected properties that are explicitly set to `null`.
     2384             */
     2385            $path_string = implode( '.', $value_path );
     2386            if (
     2387                isset( static::PROTECTED_PROPERTIES[ $path_string ] ) &&
     2388                _wp_array_get( $settings, static::PROTECTED_PROPERTIES[ $path_string ], null ) === null
     2389            ) {
    23862390                continue;
    23872391            }
Note: See TracChangeset for help on using the changeset viewer.