Title: WP_Theme_JSON::get_feature_declarations_for_node
Published: August 8, 2023
Last modified: August 20, 2026

---

# WP_Theme_JSON::get_feature_declarations_for_node( object $metadata, object $node ): array

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#changelog)

Generates style declarations for a node’s features e.g., color, border, typography
etc. that have custom selectors in their related block’s metadata.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#parameters)󠁿

 `$metadata`objectrequired

The related block metadata containing selectors.

`$node`objectrequired

A merged theme.json node for block or variation.

## 󠀁[Return](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#return)󠁿

 array The style declarations for the node’s features with custom selectors.

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#source)󠁿

    ```php
    protected function get_feature_declarations_for_node( $metadata, &$node ) {
    	$declarations = array();

    	if ( ! isset( $metadata['selectors'] ) ) {
    		return $declarations;
    	}

    	$settings = $this->theme_json['settings'] ?? array();

    	foreach ( $metadata['selectors'] as $feature => $feature_selectors ) {
    		/*
    		 * Skip if this is the block's root selector, the custom CSS
    		 * selector, or the block doesn't have any styles for the feature.
    		 */
    		if ( 'root' === $feature || 'css' === $feature || empty( $node[ $feature ] ) ) {
    			continue;
    		}

    		if ( is_array( $feature_selectors ) ) {
    			foreach ( $feature_selectors as $subfeature => $subfeature_selector ) {
    				if ( 'root' === $subfeature || empty( $node[ $feature ][ $subfeature ] ) ) {
    					continue;
    				}

    				/*
    				 * Create temporary node containing only the subfeature data
    				 * to leverage existing `compute_style_properties` function.
    				 */
    				$subfeature_node = array(
    					$feature => array(
    						$subfeature => $node[ $feature ][ $subfeature ],
    					),
    				);

    				// Generate style declarations.
    				$new_declarations = static::compute_style_properties( $subfeature_node, $settings, null, $this->theme_json );

    				// Merge subfeature declarations into feature declarations.
    				if ( isset( $declarations[ $subfeature_selector ] ) ) {
    					foreach ( $new_declarations as $new_declaration ) {
    						$declarations[ $subfeature_selector ][] = $new_declaration;
    					}
    				} else {
    					$declarations[ $subfeature_selector ] = $new_declarations;
    				}

    				/*
    				 * Remove the subfeature from the block's node now its
    				 * styles will be included under its own selector not the
    				 * block's.
    				 */
    				unset( $node[ $feature ][ $subfeature ] );
    			}
    		}

    		/*
    		 * Now subfeatures have been processed and removed we can process
    		 * feature root selector or simple string selector.
    		 */
    		if (
    			is_string( $feature_selectors ) ||
    			( isset( $feature_selectors['root'] ) && $feature_selectors['root'] )
    		) {
    			$feature_selector = is_string( $feature_selectors ) ? $feature_selectors : $feature_selectors['root'];

    			/*
    			 * Create temporary node containing only the feature data
    			 * to leverage existing `compute_style_properties` function.
    			 */
    			$feature_node = array( $feature => $node[ $feature ] );

    			// Generate the style declarations.
    			$new_declarations = static::compute_style_properties( $feature_node, $settings, null, $this->theme_json );

    			/*
    			 * Merge new declarations with any that already exist for
    			 * the feature selector. This may occur when multiple block
    			 * support features use the same custom selector.
    			 */
    			if ( isset( $declarations[ $feature_selector ] ) ) {
    				foreach ( $new_declarations as $new_declaration ) {
    					$declarations[ $feature_selector ][] = $new_declaration;
    				}
    			} else {
    				$declarations[ $feature_selector ] = $new_declarations;
    			}

    			/*
    			 * Remove the feature from the block's node now its styles
    			 * will be included under its own selector not the block's.
    			 */
    			unset( $node[ $feature ] );
    		}
    	}

    	return $declarations;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/class-wp-theme-json.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/class-wp-theme-json.php#L5680)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/class-wp-theme-json.php#L5680-L5776)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#related)󠁿

| Used by | Description | 
| [WP_Theme_JSON::process_pseudo_selectors()](https://developer.wordpress.org/reference/classes/wp_theme_json/process_pseudo_selectors/)`wp-includes/class-wp-theme-json.php` |

Processes pseudo-selectors for any node (block or variation).

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wp_theme_json/get_feature_declarations_for_node/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.3.0](https://developer.wordpress.org/reference/since/6.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwp_theme_json%2Fget_feature_declarations_for_node%2F)
before being able to contribute a note or feedback.