WP_Theme_JSON::process_pseudo_selectors( array $node, string $base_selector, array $settings, string $block_name, array|null $block_metadata = null, array|null $style_variation = null ): array
- Source
wp-includes/class-wp-theme-json.php:965
Compatibility
- WordPress
- core
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 2 of the 5 tracked releases, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$nodearray- The node data (block or variation).
$base_selectorstring- The base selector.
$settingsarray- The theme settings.
$block_namestring- The block name.
$block_metadataarray|nulloptional- Metadata about the block to get styles for.Default:
null $style_variationarray|nulloptional- Style variation metadata.Default:
null
Return value
array- Array of pseudo-selector declarations.
Performance profile
How much work a call to WP_Theme_JSON::process_pseudo_selectors() 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
- Trivial
- Scaling
- Constant
- Instructions
- 6–15
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 102.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
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::process_pseudo_selectors() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 6–10 | none |
!empty($declarations) && isset($pseudo_declarations[$selector]) | 15 | array_merge() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 101 | 6–15 | 10 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 102 | 6–15 | 10 | |
| 8.4 | 102 | 6–15 | 10 | |
| 8.3 | 102 | 6–15 | 10 | |
| 8.2 | 102 | 6–15 | 10 | |
| 8.1 | 102 | 6–15 | 10 | 19 more instructions than PHP 7.4 |
| 7.4 | 83 | 14–19 | 8 |
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 · 6
- WP_Theme_JSON::get_feature_declarations_for_node()Generates style declarations for a node's features e.g., color, border, typography etc. that have custom selectors in their related block's metadata.
- static::update_paragraph_text_indent_selector()
- static::update_button_width_declarations()
- static::get_block_style_variation_feature_selector()
- static::append_to_selector()
- static::compute_style_properties()
Used by · 1
- WP_Theme_JSON::get_styles_for_block()Gets the CSS rules for a particular block from theme.json.
Source code
private function process_pseudo_selectors( $node, $base_selector, $settings, $block_name, $block_metadata = null, $style_variation = null ) { $pseudo_declarations = array(); $add_declarations = static function ( $selector, $declarations ) use ( &$pseudo_declarations ) { if ( empty( $declarations ) ) { return; } if ( isset( $pseudo_declarations[ $selector ] ) ) { $pseudo_declarations[ $selector ] = array_merge( $pseudo_declarations[ $selector ], $declarations ); } else { $pseudo_declarations[ $selector ] = $declarations; } }; if ( ! isset( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block_name ] ) ) { return $pseudo_declarations; } foreach ( static::VALID_BLOCK_PSEUDO_SELECTORS[ $block_name ] as $pseudo_selector ) { if ( isset( $node[ $pseudo_selector ] ) ) { $pseudo_node = $node[ $pseudo_selector ]; if ( is_array( $block_metadata ) ) { $feature_declarations = $this->get_feature_declarations_for_node( $block_metadata, $pseudo_node ); $feature_declarations = static::update_paragraph_text_indent_selector( $feature_declarations, $settings, $block_name ); $feature_declarations = static::update_button_width_declarations( $feature_declarations, $settings ); foreach ( $feature_declarations as $feature_selector => $declarations ) { $target_selector = is_array( $style_variation ) ? static::get_block_style_variation_feature_selector( $style_variation, $feature_selector ) : $feature_selector; $combined_selector = static::append_to_selector( $target_selector, $pseudo_selector ); $add_declarations( $combined_selector, $declarations ); } } $combined_selector = static::append_to_selector( $base_selector, $pseudo_selector ); $declarations = static::compute_style_properties( $pseudo_node, $settings, null, null ); $add_declarations( $combined_selector, $declarations ); } } return $pseudo_declarations; }Changelog
2 changes between 7.0.4 and 7.1.0.
Signature, return type and hooks compared across 2 parsed releases.
$block_metadata added.verified against source$style_variation added.verified against sourceAbout 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.