wppaste
WordPress

WP_Theme_JSON::get_style_nodes( array $theme_json, array $selectors = array(), array $options = array() ): array

Since
5.8.0, 6.6.0
Source
wp-includes/class-wp-theme-json.php:2584
Builds metadata for the style nodes, which returns in the form of:

Description

[ [ 'path' => [ 'path', 'to', 'some', 'node' ], 'selector' => 'CSS selector for some node', 'duotone' => 'CSS selector for duotone for some node' ], [ 'path' => ['path', 'to', 'other', 'node' ], 'selector' => 'CSS selector for other node', 'duotone' => null ], ]

Compatibility

WordPress
since 6.6.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$theme_jsonarray
The tree to extract style nodes from.
$selectorsarrayoptional
List of selectors per block.Default: array()
$optionsarrayoptional
An array of options for now used for internal purposes only (may change without notice).Default: array()
  • $include_block_style_variationsbooldefault: false

    Includes style nodes for block style variations.

Return value

array
An array of style nodes metadata.

Performance profile

How much work a call to WP_Theme_JSON::get_style_nodes() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Light

Touches nothing outside its own arguments.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
7–35

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 83.

Plugin surface
1 hook

Third-party callbacks on 'wp_theme_json_get_style_nodes' run inside this call, and their cost is not bounded by anything here.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()called directly

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme_JSON::get_style_nodes() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always7–22none
isset($theme_json) && isset($value)30–35::get_block_nodes(), apply_filters()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 83 instructions, 7–35 executed per call, 12 branches. The work does not change between versions.

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 1

One hook fires while WP_Theme_JSON::get_style_nodes() runs, in this order:

  1. apply_filters( wp_theme_json_get_style_nodes )filterline 2640 (+56 into the body)

    Filters the list of style nodes with metadata.

Uses · 3

  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • static::append_to_selector()
  • static::get_block_nodes()

Source code

	protected static function get_style_nodes( $theme_json, $selectors = array(), $options = array() ) {		$nodes = array();		if ( ! isset( $theme_json['styles'] ) ) {			return $nodes;		} 		// Top-level.		$nodes[] = array(			'path'     => array( 'styles' ),			'selector' => static::ROOT_BLOCK_SELECTOR,		); 		if ( isset( $theme_json['styles']['elements'] ) ) {			foreach ( self::ELEMENTS as $element => $selector ) {				if ( ! isset( $theme_json['styles']['elements'][ $element ] ) ) {					continue;				}				$nodes[] = array(					'path'     => array( 'styles', 'elements', $element ),					'selector' => static::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']['elements'][ $element ][ $pseudo_selector ] ) ) {							$nodes[] = array(								'path'     => array( 'styles', 'elements', $element ),								'selector' => static::append_to_selector( static::ELEMENTS[ $element ], $pseudo_selector ),							);						}					}				}			}		} 		// Blocks.		if ( ! isset( $theme_json['styles']['blocks'] ) ) {			return $nodes;		} 		$block_nodes = static::get_block_nodes( $theme_json, $selectors, $options );		foreach ( $block_nodes as $block_node ) {			$nodes[] = $block_node;		} 		/**		 * Filters the list of style nodes with metadata.		 *		 * This allows for things like loading block CSS independently.		 *		 * @since 6.1.0		 *		 * @param array $nodes Style nodes with metadata.		 */		return apply_filters( 'wp_theme_json_get_style_nodes', $nodes );	}

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

6.6.0
Added options array for modifying generated nodes.from the docblock
5.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-theme-json.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.