Theme JSON: include block style variations in path only output of get_block_nodes

An `$include_node_paths_only` option to `get_block_nodes()` was introduced to improve performance.

When set to `true`, this option tells the function to only return paths, and not selectors, for consumers that only needed paths to style values.

For one of the conditional blocks, block style variations wasn't included.

This commit adds them to the array of paths following the existing model `$node[]['path' => [], 'variations' => ['path' => []]]`.

Follow-up to [61858].

Props aaronrobertshaw, ramonopoly.
Fixes #62399.



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


git-svn-id: http://core.svn.wordpress.org/trunk@58804 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ramonopoly 2024-11-19 04:44:19 +00:00
parent c6e76c3c5b
commit 70b4a18c97
2 changed files with 14 additions and 2 deletions

View File

@ -2722,9 +2722,21 @@ class WP_Theme_JSON {
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 ) {
$nodes[] = array( $variation_paths = array();
if ( $include_variations && isset( $node['variations'] ) ) {
foreach ( $node['variations'] as $variation => $variation_node ) {
$variation_paths[] = array(
'path' => array( 'styles', 'blocks', $name, 'variations', $variation ),
);
}
}
$node = array(
'path' => $node_path, 'path' => $node_path,
); );
if ( ! empty( $variation_paths ) ) {
$node['variations'] = $variation_paths;
}
$nodes[] = $node;
} else { } else {
$selector = null; $selector = null;
if ( isset( $selectors[ $name ]['selector'] ) ) { if ( isset( $selectors[ $name ]['selector'] ) ) {

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.8-alpha-59417'; $wp_version = '6.8-alpha-59418';
/** /**
* 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.