Skip to content

Commit

Permalink
Theme JSON: remove redundant styles check and relocate $selectors ass…
Browse files Browse the repository at this point in the history
…ignment.

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
  • Loading branch information
ramonjd committed Oct 21, 2024
1 parent 9de0f74 commit 1508e5b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/wp-includes/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -2707,20 +2707,20 @@ 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;
}

$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 ) {
Expand Down

0 comments on commit 1508e5b

Please sign in to comment.