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.



Built from https://develop.svn.wordpress.org/trunk@59262


git-svn-id: http://core.svn.wordpress.org/trunk@58654 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ramonopoly 2024-10-21 04:48:16 +00:00
parent b571e7c6f1
commit 339ee19db1
2 changed files with 7 additions and 7 deletions

View File

@ -2707,13 +2707,8 @@ class WP_Theme_JSON {
* @return array The block nodes in theme.json. * @return array The block nodes in theme.json.
*/ */
private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) { private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) {
$selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; $nodes = array();
$nodes = array();
if ( ! isset( $theme_json['styles'] ) ) {
return $nodes;
}
// Blocks.
if ( ! isset( $theme_json['styles']['blocks'] ) ) { if ( ! isset( $theme_json['styles']['blocks'] ) ) {
return $nodes; return $nodes;
} }
@ -2721,6 +2716,11 @@ class WP_Theme_JSON {
$include_variations = $options['include_block_style_variations'] ?? false; $include_variations = $options['include_block_style_variations'] ?? false;
$include_node_paths_only = $options['include_node_paths_only'] ?? 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 ) { foreach ( $theme_json['styles']['blocks'] as $name => $node ) {
$node_path = array( 'styles', 'blocks', $name ); $node_path = array( 'styles', 'blocks', $name );
if ( $include_node_paths_only ) { if ( $include_node_paths_only ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.7-beta3-59261'; $wp_version = '6.7-beta3-59262';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.