From c13a3989c338568cfd08047f20bb32a4e7481569 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 3 Oct 2024 12:01:41 +0530 Subject: [PATCH 01/11] Improve performance --- src/wp-includes/class-wp-theme-json.php | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index cbe266bfad0cc..e5e53eb82fcfd 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3236,17 +3236,19 @@ public function merge( $incoming ) { * some values provide exceptions, namely style values that are * objects and represent unique definitions for the style. */ - $style_nodes = static::get_styles_block_nodes(); - foreach ( $style_nodes as $style_node ) { - $path = $style_node['path']; - /* - * Background image styles should be replaced, not merged, - * as they themselves are specific object definitions for the style. - */ - $background_image_path = array_merge( $path, static::PROPERTIES_METADATA['background-image'] ); - $content = _wp_array_get( $incoming_data, $background_image_path, null ); - if ( isset( $content ) ) { - _wp_array_set( $this->theme_json, $background_image_path, $content ); + if ( isset( $incoming_data['styles']['blocks'] ) && is_array( $incoming_data['styles']['blocks'] ) ) { + foreach ( $incoming_data['styles']['blocks'] as $block_name => $block_styles ) { + /* + * Background image styles should be replaced, not merged, + * as they themselves are specific object definitions for the style. + */ + if ( isset( $block_styles['background']['backgroundImage'] ) ) { + $background_image_path = array_merge( array( 'styles', 'blocks', $block_name ), static::PROPERTIES_METADATA['background-image'] ); + $content = _wp_array_get( $incoming_data, $background_image_path, null ); + if ( isset( $content ) ) { + _wp_array_set( $this->theme_json, $background_image_path, $content ); + } + } } } } From 46640a7e77b5e6f718203af373fce4c0ac2c021b Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Mon, 7 Oct 2024 11:48:34 +0530 Subject: [PATCH 02/11] Introduce get_block_node_paths() --- src/wp-includes/class-wp-theme-json.php | 71 ++++++++++++++++++++----- 1 file changed, 58 insertions(+), 13 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index e5e53eb82fcfd..ecab04f0c05fc 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3101,6 +3101,53 @@ protected static function get_metadata_boolean( $data, $path, $default_value = f return $default_value; } + /** + * An internal method to get the block nodes from a theme.json file. + * + * @since 6.7.0 + * + * @param array $theme_json The theme.json converted to an array. + * @return array The block nodes in theme.json. + */ + private static function get_block_node_paths( $theme_json ) { + $nodes = array(); + if ( ! isset( $theme_json['styles'] ) ) { + return $nodes; + } + + // Blocks. + if ( ! isset( $theme_json['styles']['blocks'] ) ) { + return $nodes; + } + + foreach ( $theme_json['styles']['blocks'] as $name => $node ) { + $nodes[] = array( + 'path' => array( 'styles', 'blocks', $name ), + ); + + if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { + foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { + $nodes[] = array( + 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), + ); + + // Handle any pseudo selectors for the element. + if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) { + foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { + if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) { + $nodes[] = array( + 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), + ); + } + } + } + } + } + } + + return $nodes; + } + /** * Merges new incoming data. * @@ -3236,19 +3283,17 @@ public function merge( $incoming ) { * some values provide exceptions, namely style values that are * objects and represent unique definitions for the style. */ - if ( isset( $incoming_data['styles']['blocks'] ) && is_array( $incoming_data['styles']['blocks'] ) ) { - foreach ( $incoming_data['styles']['blocks'] as $block_name => $block_styles ) { - /* - * Background image styles should be replaced, not merged, - * as they themselves are specific object definitions for the style. - */ - if ( isset( $block_styles['background']['backgroundImage'] ) ) { - $background_image_path = array_merge( array( 'styles', 'blocks', $block_name ), static::PROPERTIES_METADATA['background-image'] ); - $content = _wp_array_get( $incoming_data, $background_image_path, null ); - if ( isset( $content ) ) { - _wp_array_set( $this->theme_json, $background_image_path, $content ); - } - } + $style_nodes = static::get_block_node_paths( $this->theme_json ); + foreach ( $style_nodes as $style_node ) { + $path = $style_node['path']; + /* + * Background image styles should be replaced, not merged, + * as they themselves are specific object definitions for the style. + */ + $background_image_path = array_merge( $path, static::PROPERTIES_METADATA['background-image'] ); + $content = _wp_array_get( $incoming_data, $background_image_path, null ); + if ( isset( $content ) ) { + _wp_array_set( $this->theme_json, $background_image_path, $content ); } } } From 76e0140f145a8053ece8fb2e31f822d71f2fe662 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 8 Oct 2024 16:13:07 +0530 Subject: [PATCH 03/11] Add options that include node path and block elements --- src/wp-includes/class-wp-theme-json.php | 155 ++++++++++-------------- 1 file changed, 65 insertions(+), 90 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index ecab04f0c05fc..e4e64668cfd2c 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2696,7 +2696,9 @@ private static function update_separator_declarations( $declarations ) { * @param array $options { * Optional. An array of options for now used for internal purposes only (may change without notice). * - * @type bool $include_block_style_variations Includes nodes for block style variations. Default false. + * @type bool $include_block_style_variations Includes nodes for block style variations. Default false. + * @type bool $include_node_paths_only Includes node path for block nodes. Default false. + * @type bool $include_block_elements Includes block elements for block nodes. Default true. * } * @return array The block nodes in theme.json. */ @@ -2713,58 +2715,78 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt } foreach ( $theme_json['styles']['blocks'] as $name => $node ) { - $selector = null; - if ( isset( $selectors[ $name ]['selector'] ) ) { - $selector = $selectors[ $name ]['selector']; - } - $duotone_selector = null; - if ( isset( $selectors[ $name ]['duotone'] ) ) { - $duotone_selector = $selectors[ $name ]['duotone']; - } + $include_node_paths_only = $options['include_node_paths_only'] ?? false; + + $node_path = array( 'styles', 'blocks', $name ); + if ( $include_node_paths_only ) { + $nodes[] = $node_path; + } else { + $selector = null; + if ( isset( $selectors[ $name ]['selector'] ) ) { + $selector = $selectors[ $name ]['selector']; + } - $feature_selectors = null; - if ( isset( $selectors[ $name ]['selectors'] ) ) { - $feature_selectors = $selectors[ $name ]['selectors']; - } + $duotone_selector = null; + if ( isset( $selectors[ $name ]['duotone'] ) ) { + $duotone_selector = $selectors[ $name ]['duotone']; + } - $variation_selectors = array(); - $include_variations = $options['include_block_style_variations'] ?? false; - if ( $include_variations && isset( $node['variations'] ) ) { - foreach ( $node['variations'] as $variation => $node ) { - $variation_selectors[] = array( - 'path' => array( 'styles', 'blocks', $name, 'variations', $variation ), - 'selector' => $selectors[ $name ]['styleVariations'][ $variation ], - ); + $feature_selectors = null; + if ( isset( $selectors[ $name ]['selectors'] ) ) { + $feature_selectors = $selectors[ $name ]['selectors']; + } + + $variation_selectors = array(); + $include_variations = $options['include_block_style_variations'] ?? false; + if ( $include_variations && isset( $node['variations'] ) ) { + foreach ( $node['variations'] as $variation => $node ) { + $variation_selectors[] = array( + 'path' => array( 'styles', 'blocks', $name, 'variations', $variation ), + 'selector' => $selectors[ $name ]['styleVariations'][ $variation ], + ); + } } + + $nodes[] = array( + 'name' => $name, + 'path' => $node_path, + 'selector' => $selector, + 'selectors' => $feature_selectors, + 'duotone' => $duotone_selector, + 'features' => $feature_selectors, + 'variations' => $variation_selectors, + 'css' => $selector, + ); } - $nodes[] = array( - 'name' => $name, - 'path' => array( 'styles', 'blocks', $name ), - 'selector' => $selector, - 'selectors' => $feature_selectors, - 'duotone' => $duotone_selector, - 'features' => $feature_selectors, - 'variations' => $variation_selectors, - 'css' => $selector, - ); + $include_block_elements = $options['include_block_elements'] ?? true; - if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { + if ( $include_block_elements && isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { - $nodes[] = array( - 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), - 'selector' => $selectors[ $name ]['elements'][ $element ], - ); + $node_path = array( 'styles', 'blocks', $name, 'elements', $element ); + if ( $include_node_paths_only ) { + $nodes[] = $node_path; + } else { + $nodes[] = array( + 'path' => $node_path, + 'selector' => $selectors[ $name ]['elements'][ $element ], + ); + } // Handle any pseudo selectors for the element. if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) { - $nodes[] = array( - 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), - 'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ), - ); + $node_path = array( 'styles', 'blocks', $name, 'elements', $element ); + if ( $include_node_paths_only ) { + $nodes[] = $node_path; + } else { + $nodes[] = array( + 'path' => $node_path, + 'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ), + ); + } } } } @@ -3101,53 +3123,6 @@ protected static function get_metadata_boolean( $data, $path, $default_value = f return $default_value; } - /** - * An internal method to get the block nodes from a theme.json file. - * - * @since 6.7.0 - * - * @param array $theme_json The theme.json converted to an array. - * @return array The block nodes in theme.json. - */ - private static function get_block_node_paths( $theme_json ) { - $nodes = array(); - if ( ! isset( $theme_json['styles'] ) ) { - return $nodes; - } - - // Blocks. - if ( ! isset( $theme_json['styles']['blocks'] ) ) { - return $nodes; - } - - foreach ( $theme_json['styles']['blocks'] as $name => $node ) { - $nodes[] = array( - 'path' => array( 'styles', 'blocks', $name ), - ); - - if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { - foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { - $nodes[] = array( - 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), - ); - - // Handle any pseudo selectors for the element. - if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) { - foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { - if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) { - $nodes[] = array( - 'path' => array( 'styles', 'blocks', $name, 'elements', $element ), - ); - } - } - } - } - } - } - - return $nodes; - } - /** * Merges new incoming data. * @@ -3283,14 +3258,14 @@ public function merge( $incoming ) { * some values provide exceptions, namely style values that are * objects and represent unique definitions for the style. */ - $style_nodes = static::get_block_node_paths( $this->theme_json ); + $style_options = array( 'include_node_paths_only' => true ); + $style_nodes = static::get_block_nodes( $this->theme_json, array(), $style_options ); foreach ( $style_nodes as $style_node ) { - $path = $style_node['path']; /* * Background image styles should be replaced, not merged, * as they themselves are specific object definitions for the style. */ - $background_image_path = array_merge( $path, static::PROPERTIES_METADATA['background-image'] ); + $background_image_path = array_merge( $style_node, static::PROPERTIES_METADATA['background-image'] ); $content = _wp_array_get( $incoming_data, $background_image_path, null ); if ( isset( $content ) ) { _wp_array_set( $this->theme_json, $background_image_path, $content ); From 82dc69aab5ec87d93a5fb86d5fe656b15840ae5e Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Tue, 8 Oct 2024 16:15:41 +0530 Subject: [PATCH 04/11] Apply suggestions from code review --- src/wp-includes/class-wp-theme-json.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index e4e64668cfd2c..3454b101f8b4b 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2717,7 +2717,6 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt foreach ( $theme_json['styles']['blocks'] as $name => $node ) { $include_node_paths_only = $options['include_node_paths_only'] ?? false; - $node_path = array( 'styles', 'blocks', $name ); if ( $include_node_paths_only ) { $nodes[] = $node_path; From 867ae4a9aedefb2d9c7d96769ccb5c85a134c869 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 9 Oct 2024 10:31:28 +0530 Subject: [PATCH 05/11] Remove "include_block_elements" parameter --- src/wp-includes/class-wp-theme-json.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 3454b101f8b4b..96bfc7f678f7d 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2698,7 +2698,6 @@ private static function update_separator_declarations( $declarations ) { * * @type bool $include_block_style_variations Includes nodes for block style variations. Default false. * @type bool $include_node_paths_only Includes node path for block nodes. Default false. - * @type bool $include_block_elements Includes block elements for block nodes. Default true. * } * @return array The block nodes in theme.json. */ @@ -2759,9 +2758,7 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt ); } - $include_block_elements = $options['include_block_elements'] ?? true; - - if ( $include_block_elements && isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { + if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) { foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { $node_path = array( 'styles', 'blocks', $name, 'elements', $element ); if ( $include_node_paths_only ) { From dbbd01066088984f1a41ab24a83e58a46b9a27c4 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Wed, 9 Oct 2024 10:57:05 +0530 Subject: [PATCH 06/11] Address review feedbacks --- src/wp-includes/class-wp-theme-json.php | 29 ++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 96bfc7f678f7d..6e6d1ba81d815 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2718,7 +2718,9 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt $include_node_paths_only = $options['include_node_paths_only'] ?? false; $node_path = array( 'styles', 'blocks', $name ); if ( $include_node_paths_only ) { - $nodes[] = $node_path; + $nodes[] = array( + 'path' => $node_path, + ); } else { $selector = null; if ( isset( $selectors[ $name ]['selector'] ) ) { @@ -2762,27 +2764,33 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) { $node_path = array( 'styles', 'blocks', $name, 'elements', $element ); if ( $include_node_paths_only ) { - $nodes[] = $node_path; - } else { $nodes[] = array( - 'path' => $node_path, - 'selector' => $selectors[ $name ]['elements'][ $element ], + 'path' => $node_path, ); + continue; } + $nodes[] = array( + 'path' => $node_path, + 'selector' => $selectors[ $name ]['elements'][ $element ], + ); + // Handle any pseudo selectors for the element. if ( isset( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] ) ) { foreach ( static::VALID_ELEMENT_PSEUDO_SELECTORS[ $element ] as $pseudo_selector ) { if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'][ $element ][ $pseudo_selector ] ) ) { $node_path = array( 'styles', 'blocks', $name, 'elements', $element ); if ( $include_node_paths_only ) { - $nodes[] = $node_path; - } else { $nodes[] = array( - 'path' => $node_path, - 'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ), + 'path' => $node_path, ); + continue; } + + $nodes[] = array( + 'path' => $node_path, + 'selector' => static::append_to_selector( $selectors[ $name ]['elements'][ $element ], $pseudo_selector ), + ); } } } @@ -3257,11 +3265,12 @@ public function merge( $incoming ) { $style_options = array( 'include_node_paths_only' => true ); $style_nodes = static::get_block_nodes( $this->theme_json, array(), $style_options ); foreach ( $style_nodes as $style_node ) { + $path = $style_node['path']; /* * Background image styles should be replaced, not merged, * as they themselves are specific object definitions for the style. */ - $background_image_path = array_merge( $style_node, static::PROPERTIES_METADATA['background-image'] ); + $background_image_path = array_merge( $path, static::PROPERTIES_METADATA['background-image'] ); $content = _wp_array_get( $incoming_data, $background_image_path, null ); if ( isset( $content ) ) { _wp_array_set( $this->theme_json, $background_image_path, $content ); From 2adb26ae9aa4342b02566e6b73de3947fe0245cb Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 10 Oct 2024 11:32:29 +0530 Subject: [PATCH 07/11] Remove variable Co-authored-by: Felix Arntz --- src/wp-includes/class-wp-theme-json.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 6e6d1ba81d815..20dd7b80df565 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -3262,8 +3262,11 @@ public function merge( $incoming ) { * some values provide exceptions, namely style values that are * objects and represent unique definitions for the style. */ - $style_options = array( 'include_node_paths_only' => true ); - $style_nodes = static::get_block_nodes( $this->theme_json, array(), $style_options ); + $style_nodes = static::get_block_nodes( + $this->theme_json, + array(), + array( 'include_node_paths_only' => true ) + ); foreach ( $style_nodes as $style_node ) { $path = $style_node['path']; /* From 58dfa83c019ac5d5e3d7d0312df0907025d8e570 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 10 Oct 2024 11:50:08 +0530 Subject: [PATCH 08/11] Update new variable description --- src/wp-includes/class-wp-theme-json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index 20dd7b80df565..b59013c794dc6 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2697,7 +2697,7 @@ private static function update_separator_declarations( $declarations ) { * Optional. An array of options for now used for internal purposes only (may change without notice). * * @type bool $include_block_style_variations Includes nodes for block style variations. Default false. - * @type bool $include_node_paths_only Includes node path for block nodes. Default false. + * @type bool $include_node_paths_only Return only block nodes node paths. Default false. * } * @return array The block nodes in theme.json. */ From 35e4ed432212d8c2fb984efe86e968662dc83ba9 Mon Sep 17 00:00:00 2001 From: Mukesh Panchal Date: Thu, 10 Oct 2024 12:07:51 +0530 Subject: [PATCH 09/11] Unit tests for new changes --- tests/phpunit/tests/theme/wpThemeJson.php | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/tests/phpunit/tests/theme/wpThemeJson.php b/tests/phpunit/tests/theme/wpThemeJson.php index 2de327dd7c47e..01370ffcc27e9 100644 --- a/tests/phpunit/tests/theme/wpThemeJson.php +++ b/tests/phpunit/tests/theme/wpThemeJson.php @@ -2443,6 +2443,60 @@ public function test_merge_incoming_background_styles() { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * This test covers `get_block_nodes` with the `$include_node_paths_only` option. + * When `true`, `$include_node_paths_only` should return only the paths of the block nodes. + * + * @ticket 61858 + */ + public function test_return_block_node_paths() { + $theme_json = new ReflectionClass( 'WP_Theme_JSON' ); + + $func = $theme_json->getMethod( 'get_block_nodes' ); + $func->setAccessible( true ); + + $theme_json = array( + 'version' => WP_Theme_JSON::LATEST_SCHEMA, + 'styles' => array( + 'typography' => array( + 'fontSize' => '16px', + ), + 'blocks' => array( + 'core/button' => array( + 'color' => array( + 'background' => 'red', + ), + ), + 'core/group' => array( + 'elements' => array( + 'link' => array( + 'color' => array( + 'background' => 'blue', + ), + ), + ), + ), + ), + ), + ); + + $block_nodes = $func->invoke( null, $theme_json, array(), array( 'include_node_paths_only' => true ) ); + + $expected = array( + array( + 'path' => array( 'styles', 'blocks', 'core/button' ), + ), + array( + 'path' => array( 'styles', 'blocks', 'core/group' ), + ), + array( + 'path' => array( 'styles', 'blocks', 'core/group', 'elements', 'link' ), + ), + ); + + $this->assertEquals( $expected, $block_nodes ); + } + /** * @ticket 54336 */ From 115dc4e20c85971d604233031e5ef7e615ef7d51 Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 10 Oct 2024 13:54:44 -0700 Subject: [PATCH 10/11] Add since annotation for the method change. --- src/wp-includes/class-wp-theme-json.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index b59013c794dc6..f6ba9f5d09de6 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2690,13 +2690,14 @@ private static function update_separator_declarations( $declarations ) { * @since 6.1.0 * @since 6.3.0 Refactored and stabilized selectors API. * @since 6.6.0 Added optional selectors and options for generating block nodes. + * @since 6.7.0 Added $include_node_paths_only option. * * @param array $theme_json The theme.json converted to an array. * @param array $selectors Optional list of selectors per block. * @param array $options { * Optional. An array of options for now used for internal purposes only (may change without notice). * - * @type bool $include_block_style_variations Includes nodes for block style variations. Default false. + * @type bool $include_block_style_variations Include nodes for block style variations. Default false. * @type bool $include_node_paths_only Return only block nodes node paths. Default false. * } * @return array The block nodes in theme.json. From 0eb736b01172554e5a7ea1efe371eddd7be9589f Mon Sep 17 00:00:00 2001 From: Felix Arntz Date: Thu, 10 Oct 2024 13:56:04 -0700 Subject: [PATCH 11/11] Move option variable assignments before the loops. --- src/wp-includes/class-wp-theme-json.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/class-wp-theme-json.php b/src/wp-includes/class-wp-theme-json.php index f6ba9f5d09de6..8603a4cbbd169 100644 --- a/src/wp-includes/class-wp-theme-json.php +++ b/src/wp-includes/class-wp-theme-json.php @@ -2714,9 +2714,10 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt return $nodes; } - foreach ( $theme_json['styles']['blocks'] as $name => $node ) { + $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; + foreach ( $theme_json['styles']['blocks'] as $name => $node ) { $node_path = array( 'styles', 'blocks', $name ); if ( $include_node_paths_only ) { $nodes[] = array( @@ -2739,7 +2740,6 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt } $variation_selectors = array(); - $include_variations = $options['include_block_style_variations'] ?? false; if ( $include_variations && isset( $node['variations'] ) ) { foreach ( $node['variations'] as $variation => $node ) { $variation_selectors[] = array(