Make WordPress Core

Changeset 59262


Ignore:
Timestamp:
10/21/2024 04:46:39 AM (6 weeks ago)
Author:
ramonopoly
Message:

Theme JSON: remove redundant styles check and relocate $selectors assignment.

In WP_Theme_JSON::get_block_nodes(), remove redundant check for $theme_json['styles'], which means WP_Theme_JSON::get_blocks_metadata() is only called if necessary.

Also skip unnecessary $selector assignment if only nodes are to be returned.

Props ramonopoly, mukesh27.
Fixes #62234.

File:
1 edited

Legend:

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

    r59253 r59262  
    27082708     */
    27092709    private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) {
    2710         $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
    2711         $nodes     = array();
    2712         if ( ! isset( $theme_json['styles'] ) ) {
    2713             return $nodes;
    2714         }
    2715 
    2716         // Blocks.
     2710        $nodes = array();
     2711
    27172712        if ( ! isset( $theme_json['styles']['blocks'] ) ) {
    27182713            return $nodes;
     
    27212716        $include_variations      = $options['include_block_style_variations'] ?? false;
    27222717        $include_node_paths_only = $options['include_node_paths_only'] ?? false;
     2718
     2719        // If only node paths are to be returned, skip selector assignment.
     2720        if ( ! $include_node_paths_only ) {
     2721            $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors;
     2722        }
    27232723
    27242724        foreach ( $theme_json['styles']['blocks'] as $name => $node ) {
Note: See TracChangeset for help on using the changeset viewer.