@@ -2719,15 +2719,17 @@ private static function update_separator_declarations( $declarations ) {
2719
2719
/**
2720
2720
* An internal method to get the block nodes from a theme.json file.
2721
2721
*
2722
- * @since 6.1.0
2723
- *
2724
2722
* @param array $theme_json The theme.json converted to an array.
2725
2723
* @param array $selectors Optional list of selectors per block.
2726
- * @param array $options An array of options to facilitate filtering node generation
2727
- * The options currently supported are:
2728
- * - `include_block_style_variations` which includes CSS for block style variations.
2724
+ * @param array $options {
2725
+ * Optional. An array of options for now used for internal purposes only (may change without notice).
2726
+ *
2727
+ * @type bool $include_block_style_variations Includes nodes for block style variations. Default false.
2728
+ * @type bool $include_node_paths_only Return only block nodes node paths. Default false.
2729
+ * }
2729
2730
* @return array The block nodes in theme.json.
2730
2731
*/
2732
+
2731
2733
private static function get_block_nodes ( $ theme_json , $ selectors = array (), $ options = array () ) {
2732
2734
$ selectors = empty ( $ selectors ) ? static ::get_blocks_metadata () : $ selectors ;
2733
2735
$ nodes = array ();
@@ -2741,55 +2743,78 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt
2741
2743
}
2742
2744
2743
2745
foreach ( $ theme_json ['styles ' ]['blocks ' ] as $ name => $ node ) {
2744
- $ selector = null ;
2745
- if ( isset ( $ selectors [ $ name ]['selector ' ] ) ) {
2746
- $ selector = $ selectors [ $ name ]['selector ' ];
2747
- }
2748
-
2749
- $ duotone_selector = null ;
2750
- if ( isset ( $ selectors [ $ name ]['duotone ' ] ) ) {
2751
- $ duotone_selector = $ selectors [ $ name ]['duotone ' ];
2752
- }
2746
+ $ include_node_paths_only = $ options ['include_node_paths_only ' ] ?? false ;
2747
+ $ node_path = array ( 'styles ' , 'blocks ' , $ name );
2748
+ if ( $ include_node_paths_only ) {
2749
+ $ nodes [] = array (
2750
+ 'path ' => $ node_path ,
2751
+ );
2752
+ } else {
2753
+ $ selector = null ;
2754
+ if ( isset ( $ selectors [ $ name ]['selector ' ] ) ) {
2755
+ $ selector = $ selectors [ $ name ]['selector ' ];
2756
+ }
2753
2757
2754
- $ feature_selectors = null ;
2755
- if ( isset ( $ selectors [ $ name ]['selectors ' ] ) ) {
2756
- $ feature_selectors = $ selectors [ $ name ]['selectors ' ];
2757
- }
2758
+ $ duotone_selector = null ;
2759
+ if ( isset ( $ selectors [ $ name ]['duotone ' ] ) ) {
2760
+ $ duotone_selector = $ selectors [ $ name ]['duotone ' ];
2761
+ }
2758
2762
2759
- $ variation_selectors = array ();
2760
- $ include_variations = $ options ['include_block_style_variations ' ] ?? false ;
2761
- if ( $ include_variations && isset ( $ node ['variations ' ] ) ) {
2762
- foreach ( $ node ['variations ' ] as $ variation => $ node ) {
2763
- $ variation_selectors [] = array (
2764
- 'path ' => array ( 'styles ' , 'blocks ' , $ name , 'variations ' , $ variation ),
2765
- 'selector ' => $ selectors [ $ name ]['styleVariations ' ][ $ variation ],
2766
- );
2763
+ $ feature_selectors = null ;
2764
+ if ( isset ( $ selectors [ $ name ]['selectors ' ] ) ) {
2765
+ $ feature_selectors = $ selectors [ $ name ]['selectors ' ];
2767
2766
}
2768
- }
2769
2767
2770
- $ nodes [] = array (
2771
- 'name ' => $ name ,
2772
- 'path ' => array ( 'styles ' , 'blocks ' , $ name ),
2773
- 'selector ' => $ selector ,
2774
- 'selectors ' => $ feature_selectors ,
2775
- 'duotone ' => $ duotone_selector ,
2776
- 'variations ' => $ variation_selectors ,
2777
- 'css ' => $ selector ,
2778
- );
2768
+ $ variation_selectors = array ();
2769
+ $ include_variations = $ options ['include_block_style_variations ' ] ?? false ;
2770
+ if ( $ include_variations && isset ( $ node ['variations ' ] ) ) {
2771
+ foreach ( $ node ['variations ' ] as $ variation => $ node ) {
2772
+ $ variation_selectors [] = array (
2773
+ 'path ' => array ( 'styles ' , 'blocks ' , $ name , 'variations ' , $ variation ),
2774
+ 'selector ' => $ selectors [ $ name ]['styleVariations ' ][ $ variation ],
2775
+ );
2776
+ }
2777
+ }
2779
2778
2779
+ $ nodes [] = array (
2780
+ 'name ' => $ name ,
2781
+ 'path ' => $ node_path ,
2782
+ 'selector ' => $ selector ,
2783
+ 'selectors ' => $ feature_selectors ,
2784
+ 'duotone ' => $ duotone_selector ,
2785
+ 'variations ' => $ variation_selectors ,
2786
+ 'css ' => $ selector ,
2787
+ );
2788
+ }
2780
2789
if ( isset ( $ theme_json ['styles ' ]['blocks ' ][ $ name ]['elements ' ] ) ) {
2781
2790
foreach ( $ theme_json ['styles ' ]['blocks ' ][ $ name ]['elements ' ] as $ element => $ node ) {
2791
+ $ node_path = array ( 'styles ' , 'blocks ' , $ name , 'elements ' , $ element );
2792
+ if ( $ include_node_paths_only ) {
2793
+ $ nodes [] = array (
2794
+ 'path ' => $ node_path ,
2795
+ );
2796
+ continue ;
2797
+ }
2798
+
2782
2799
$ nodes [] = array (
2783
- 'path ' => array ( ' styles ' , ' blocks ' , $ name , ' elements ' , $ element ) ,
2800
+ 'path ' => $ node_path ,
2784
2801
'selector ' => $ selectors [ $ name ]['elements ' ][ $ element ],
2785
2802
);
2786
2803
2787
2804
// Handle any pseudo selectors for the element.
2788
2805
if ( isset ( static ::VALID_ELEMENT_PSEUDO_SELECTORS [ $ element ] ) ) {
2789
2806
foreach ( static ::VALID_ELEMENT_PSEUDO_SELECTORS [ $ element ] as $ pseudo_selector ) {
2790
2807
if ( isset ( $ theme_json ['styles ' ]['blocks ' ][ $ name ]['elements ' ][ $ element ][ $ pseudo_selector ] ) ) {
2808
+ $ node_path = array ( 'styles ' , 'blocks ' , $ name , 'elements ' , $ element );
2809
+ if ( $ include_node_paths_only ) {
2810
+ $ nodes [] = array (
2811
+ 'path ' => $ node_path ,
2812
+ );
2813
+ continue ;
2814
+ }
2815
+
2791
2816
$ nodes [] = array (
2792
- 'path ' => array ( ' styles ' , ' blocks ' , $ name , ' elements ' , $ element ) ,
2817
+ 'path ' => $ node_path ,
2793
2818
'selector ' => static ::append_to_selector ( $ selectors [ $ name ]['elements ' ][ $ element ], $ pseudo_selector ),
2794
2819
);
2795
2820
}
@@ -3264,7 +3289,11 @@ public function merge( $incoming ) {
3264
3289
* some values provide exceptions, namely style values that are
3265
3290
* objects and represent unique definitions for the style.
3266
3291
*/
3267
- $ style_nodes = static ::get_styles_block_nodes ();
3292
+ $ style_nodes = static ::get_block_nodes (
3293
+ $ this ->theme_json ,
3294
+ array (),
3295
+ array ( 'include_node_paths_only ' => true )
3296
+ );
3268
3297
foreach ( $ style_nodes as $ style_node ) {
3269
3298
$ path = $ style_node ['path ' ];
3270
3299
/*
0 commit comments