WP_Theme_JSON::get_block_nodes( array $theme_json, array $selectors = array(), array $options = array() ): array
- Since
- 6.1.0, 6.3.0, 6.6.0, 6.7.0, 7.1.0
- Source
wp-includes/class-wp-theme-json.php:3519
Compatibility
- WordPress
- since 7.1.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 theme.json converted to an array.
$selectorsarrayoptional- Optional 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: falseInclude nodes for block style variations.$include_node_paths_onlybooldefault: falseReturn only block nodes node paths.
Return value
array- The block nodes in theme.json.
Performance profile
How much work a call to WP_Theme_JSON::get_block_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
- Scaling
- Scales with input
- Instructions
- 26–27
- Plugin surface
- None
- Called by
- 0
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 524.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Theme_JSON::get_block_nodes() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
isset($value) && !$options | 26–27 | ::get_viewport_media_queries() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 523 | 26–27 | 79 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 524 | 26–27 | 79 | |
| 8.4 | 524 | 26–27 | 79 | |
| 8.3 | 524 | 26–27 | 79 | |
| 8.2 | 524 | 26–27 | 79 | |
| 8.1 | 524 | 26–27 | 79 | |
| 7.4 | 524 | 26–27 | 79 |
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.
Uses · 3
- static::get_viewport_media_queries()
- static::get_blocks_metadata()
- static::append_to_selector()
Source code
private static function get_block_nodes( $theme_json, $selectors = array(), $options = array() ) { $nodes = array(); if ( ! isset( $theme_json['styles']['blocks'] ) ) { return $nodes; } $include_variations = $options['include_block_style_variations'] ?? false; $include_node_paths_only = $options['include_node_paths_only'] ?? false; $responsive_media_queries = static::get_viewport_media_queries( $theme_json['settings']['viewport'] ?? null ); // If only node paths are to be returned, skip selector assignment. if ( ! $include_node_paths_only ) { $selectors = empty( $selectors ) ? static::get_blocks_metadata() : $selectors; } foreach ( $theme_json['styles']['blocks'] as $name => $node ) { $node_path = array( 'styles', 'blocks', $name ); if ( $include_node_paths_only ) { $variation_paths = array(); if ( $include_variations && isset( $node['variations'] ) ) { foreach ( $node['variations'] as $variation => $variation_node ) { $variation_paths[] = array( 'path' => array( 'styles', 'blocks', $name, 'variations', $variation ), ); } } $node = array( 'path' => $node_path, ); if ( ! empty( $variation_paths ) ) { $node['variations'] = $variation_paths; } $nodes[] = $node; } else { $selector = null; if ( isset( $selectors[ $name ]['selector'] ) ) { $selector = $selectors[ $name ]['selector']; } $duotone_selector = null; if ( isset( $selectors[ $name ]['duotone'] ) ) { $duotone_selector = $selectors[ $name ]['duotone']; } $feature_selectors = null; if ( isset( $selectors[ $name ]['selectors'] ) ) { $feature_selectors = $selectors[ $name ]['selectors']; } $variation_selectors = array(); if ( $include_variations && isset( $node['variations'] ) ) { foreach ( $node['variations'] as $variation => $node ) { $variation_selectors[] = array( 'name' => $variation, 'path' => array( 'styles', 'blocks', $name, 'variations', $variation ), 'selector' => $selectors[ $name ]['styleVariations'][ $variation ], ); } } $nodes[] = array( 'name' => $name, 'path' => $node_path, 'selector' => $selector, 'selectors' => $feature_selectors, 'elements' => $selectors[ $name ]['elements'] ?? array(), 'duotone' => $duotone_selector, 'variations' => $variation_selectors, 'css' => $selector, ); // Responsive block nodes: emit one node per breakpoint that has styles. // These are rendered immediately after the base block node so that // the cascade order is: .block{} → @media{.block{}} foreach ( array_keys( $responsive_media_queries ) as $breakpoint ) { if ( isset( $theme_json['styles']['blocks'][ $name ][ $breakpoint ] ) ) { $nodes[] = array( 'name' => $name,Changelog
Introduced in 6.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 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.