@@ -2690,13 +2690,15 @@ private static function update_separator_declarations( $declarations ) {
2690
2690
* @since 6.1.0
2691
2691
* @since 6.3.0 Refactored and stabilized selectors API.
2692
2692
* @since 6.6.0 Added optional selectors and options for generating block nodes.
2693
+ * @since 6.7.0 Added $include_node_paths_only option.
2693
2694
*
2694
2695
* @param array $theme_json The theme.json converted to an array.
2695
2696
* @param array $selectors Optional list of selectors per block.
2696
2697
* @param array $options {
2697
2698
* Optional. An array of options for now used for internal purposes only (may change without notice).
2698
2699
*
2699
- * @type bool $include_block_style_variations Includes nodes for block style variations. Default false.
2700
+ * @type bool $include_block_style_variations Include nodes for block style variations. Default false.
2701
+ * @type bool $include_node_paths_only Return only block nodes node paths. Default false.
2700
2702
* }
2701
2703
* @return array The block nodes in theme.json.
2702
2704
*/
@@ -2712,57 +2714,82 @@ private static function get_block_nodes( $theme_json, $selectors = array(), $opt
2712
2714
return $ nodes ;
2713
2715
}
2714
2716
2717
+ $ include_variations = $ options ['include_block_style_variations ' ] ?? false ;
2718
+ $ include_node_paths_only = $ options ['include_node_paths_only ' ] ?? false ;
2719
+
2715
2720
foreach ( $ theme_json ['styles ' ]['blocks ' ] as $ name => $ node ) {
2716
- $ selector = null ;
2717
- if ( isset ( $ selectors [ $ name ]['selector ' ] ) ) {
2718
- $ selector = $ selectors [ $ name ]['selector ' ];
2719
- }
2721
+ $ node_path = array ( 'styles ' , 'blocks ' , $ name );
2722
+ if ( $ include_node_paths_only ) {
2723
+ $ nodes [] = array (
2724
+ 'path ' => $ node_path ,
2725
+ );
2726
+ } else {
2727
+ $ selector = null ;
2728
+ if ( isset ( $ selectors [ $ name ]['selector ' ] ) ) {
2729
+ $ selector = $ selectors [ $ name ]['selector ' ];
2730
+ }
2720
2731
2721
- $ duotone_selector = null ;
2722
- if ( isset ( $ selectors [ $ name ]['duotone ' ] ) ) {
2723
- $ duotone_selector = $ selectors [ $ name ]['duotone ' ];
2724
- }
2732
+ $ duotone_selector = null ;
2733
+ if ( isset ( $ selectors [ $ name ]['duotone ' ] ) ) {
2734
+ $ duotone_selector = $ selectors [ $ name ]['duotone ' ];
2735
+ }
2725
2736
2726
- $ feature_selectors = null ;
2727
- if ( isset ( $ selectors [ $ name ]['selectors ' ] ) ) {
2728
- $ feature_selectors = $ selectors [ $ name ]['selectors ' ];
2729
- }
2737
+ $ feature_selectors = null ;
2738
+ if ( isset ( $ selectors [ $ name ]['selectors ' ] ) ) {
2739
+ $ feature_selectors = $ selectors [ $ name ]['selectors ' ];
2740
+ }
2730
2741
2731
- $ variation_selectors = array ();
2732
- $ include_variations = $ options [ ' include_block_style_variations ' ] ?? false ;
2733
- if ( $ include_variations && isset ( $ node ['variations ' ] ) ) {
2734
- foreach ( $ node [ ' variations ' ] as $ variation => $ node ) {
2735
- $ variation_selectors [] = array (
2736
- ' path ' => array ( ' styles ' , ' blocks ' , $ name, ' variations ' , $ variation ) ,
2737
- ' selector ' => $ selectors [ $ name ][ ' styleVariations ' ][ $ variation ],
2738
- );
2742
+ $ variation_selectors = array ();
2743
+ if ( $ include_variations && isset ( $ node [ ' variations ' ] ) ) {
2744
+ foreach ( $ node ['variations ' ] as $ variation => $ node ) {
2745
+ $ variation_selectors [] = array (
2746
+ ' path ' => array ( ' styles ' , ' blocks ' , $ name , ' variations ' , $ variation ),
2747
+ ' selector ' => $ selectors [ $ name ][ ' styleVariations ' ][ $ variation ] ,
2748
+ );
2749
+ }
2739
2750
}
2740
- }
2741
2751
2742
- $ nodes [] = array (
2743
- 'name ' => $ name ,
2744
- 'path ' => array ( 'styles ' , 'blocks ' , $ name ),
2745
- 'selector ' => $ selector ,
2746
- 'selectors ' => $ feature_selectors ,
2747
- 'duotone ' => $ duotone_selector ,
2748
- 'features ' => $ feature_selectors ,
2749
- 'variations ' => $ variation_selectors ,
2750
- 'css ' => $ selector ,
2751
- );
2752
+ $ nodes [] = array (
2753
+ 'name ' => $ name ,
2754
+ 'path ' => $ node_path ,
2755
+ 'selector ' => $ selector ,
2756
+ 'selectors ' => $ feature_selectors ,
2757
+ 'duotone ' => $ duotone_selector ,
2758
+ 'features ' => $ feature_selectors ,
2759
+ 'variations ' => $ variation_selectors ,
2760
+ 'css ' => $ selector ,
2761
+ );
2762
+ }
2752
2763
2753
2764
if ( isset ( $ theme_json ['styles ' ]['blocks ' ][ $ name ]['elements ' ] ) ) {
2754
2765
foreach ( $ theme_json ['styles ' ]['blocks ' ][ $ name ]['elements ' ] as $ element => $ node ) {
2766
+ $ node_path = array ( 'styles ' , 'blocks ' , $ name , 'elements ' , $ element );
2767
+ if ( $ include_node_paths_only ) {
2768
+ $ nodes [] = array (
2769
+ 'path ' => $ node_path ,
2770
+ );
2771
+ continue ;
2772
+ }
2773
+
2755
2774
$ nodes [] = array (
2756
- 'path ' => array ( ' styles ' , ' blocks ' , $ name , ' elements ' , $ element ) ,
2775
+ 'path ' => $ node_path ,
2757
2776
'selector ' => $ selectors [ $ name ]['elements ' ][ $ element ],
2758
2777
);
2759
2778
2760
2779
// Handle any pseudo selectors for the element.
2761
2780
if ( isset ( static ::VALID_ELEMENT_PSEUDO_SELECTORS [ $ element ] ) ) {
2762
2781
foreach ( static ::VALID_ELEMENT_PSEUDO_SELECTORS [ $ element ] as $ pseudo_selector ) {
2763
2782
if ( isset ( $ theme_json ['styles ' ]['blocks ' ][ $ name ]['elements ' ][ $ element ][ $ pseudo_selector ] ) ) {
2783
+ $ node_path = array ( 'styles ' , 'blocks ' , $ name , 'elements ' , $ element );
2784
+ if ( $ include_node_paths_only ) {
2785
+ $ nodes [] = array (
2786
+ 'path ' => $ node_path ,
2787
+ );
2788
+ continue ;
2789
+ }
2790
+
2764
2791
$ nodes [] = array (
2765
- 'path ' => array ( ' styles ' , ' blocks ' , $ name , ' elements ' , $ element ) ,
2792
+ 'path ' => $ node_path ,
2766
2793
'selector ' => static ::append_to_selector ( $ selectors [ $ name ]['elements ' ][ $ element ], $ pseudo_selector ),
2767
2794
);
2768
2795
}
@@ -3236,7 +3263,11 @@ public function merge( $incoming ) {
3236
3263
* some values provide exceptions, namely style values that are
3237
3264
* objects and represent unique definitions for the style.
3238
3265
*/
3239
- $ style_nodes = static ::get_styles_block_nodes ();
3266
+ $ style_nodes = static ::get_block_nodes (
3267
+ $ this ->theme_json ,
3268
+ array (),
3269
+ array ( 'include_node_paths_only ' => true )
3270
+ );
3240
3271
foreach ( $ style_nodes as $ style_node ) {
3241
3272
$ path = $ style_node ['path ' ];
3242
3273
/*
0 commit comments