From 1508e5bf0fa3ad2d001de08eab4dee49985bb322 Mon Sep 17 00:00:00 2001 From: ramonopoly Date: Mon, 21 Oct 2024 04:46:39 +0000 Subject: [PATCH] Theme JSON: remove redundant styles check and relocate $selectors assignment. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. git-svn-id: https://develop.svn.wordpress.org/trunk@59262 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-theme-json.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 3d3feb72de471..6b16cef16a35b 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2707,13 +2707,8 @@ private static function update_separator_declarations( $declarations ) { * @return array The block nodes in theme.json. */ private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) { - $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; - $nodes = array(); - if ( ! isset( $theme_json['styles'] ) ) { - return $nodes; - } + $nodes = array(); - // Blocks. if ( ! isset( $theme_json['styles']['blocks'] ) ) { return $nodes; } @@ -2721,6 +2716,11 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt $include_variations = $options['include_block_style_variations'] ?? false; $include_node_paths_only = $options['include_node_paths_only'] ?? false; + // If only node paths are to be returned, skip selector assignment. + if ( ! $include_node_paths_only ) { + $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; + } + foreach ( $theme_json['styles']['blocks'] as $name => $node ) { $node_path = array( 'styles', 'blocks', $name ); if ( $include_node_paths_only ) {