wp_render_block_states_support( string $block_content, array $block ): string
- Since
- 7.1.0
- Source
wp-includes/block-supports/states.php:540
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 1 of the 5 tracked releases, added in 7.1.0, and compiles on PHP 7.4 through 8.6-dev.
Parameters
$block_contentstring- The block's rendered HTML.
$blockarray- The block data including blockName and attrs.
Return value
string- Modified block content with injected state styles.
Performance profile
How much work a call to wp_render_block_states_support() 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
- Moderate
- Scaling
- Scales with input
- Instructions
- 5–67
- Plugin surface
- None
- Called by
- 0
Only touches the object cache, via wp_cache_get().
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 273.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- cacheobject cache
wp_cache_get()one call below wp_render_block_states_support()
Further down the call graph this can also reach hook, option, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_render_block_states_support() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 5–7 | none |
!empty($block) && !empty($block_content) | 15 | ::WP_Block_Type_Registry(), ->get_registered() |
!empty($block) && !empty($block_content) && empty($css_rules) | 38–42 | ::WP_Block_Type_Registry(), ->get_registered(), wp_get_global_settings(), ::WP_Theme_JSON() |
!empty($block) && !empty($block_content) && !empty($css_rules) && !->next_tag() | 59–64 | ::WP_Block_Type_Registry(), ->get_registered(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_block_state_unique_class(), wp_style_engine_get_stylesheet_from_css_rules(), selector(), ->next_tag(), ->get_updated_html() |
!empty($block) && !empty($block_content) && !empty($css_rules) && ->next_tag() | 62–67 | ::WP_Block_Type_Registry(), ->get_registered(), wp_get_global_settings(), ::WP_Theme_JSON(), wp_get_block_state_unique_class(), wp_style_engine_get_stylesheet_from_css_rules(), selector(), ->next_tag(), ->add_class(), ->get_updated_html() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 273 instructions, 5–67 executed per call, 41 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.
Uses · 16
- wp_get_global_settings()Gets the settings resulting of merging core, theme, and user data.
- wp_get_block_state_style_rules()Builds compiled state style rules, preserving the selector each rule targets.
- wp_get_root_state_style()Returns a style object with nested state keys removed.
- wp_get_block_state_element_selectors()Generates all element selectors for a block root selector.
- wp_get_block_css_selector()Determines the CSS selector for the block type and property provided, returning it if available.
- wp_add_block_state_style_rule()Adds a compiled state style rule to a rule list.
- wp_get_block_state_unique_class()Returns a unique class for a set of state style rules.
- wp_get_state_declarations_with_background_resets()Adds background reset declarations to prevent gradient/solid color conflicts.
- wp_build_state_selector()Builds a scoped selector from a block selector and optional pseudo-state.
- wp_get_state_declarations_with_fallback_border_styles()Adds fallback border-style declarations for visible border declarations.
- wp_style_engine_get_stylesheet_from_css_rules()Returns compiled CSS from a collection of selectors and declarations.
- WP_Block_Type_Registry::get_instance()::get_registered()
Show all 16
- WP_Block_Type_Registry::get_instance()Utility method to retrieve the main instance of the class.
- WP_Theme_JSON::get_viewport_media_queries()Returns CSS media queries for responsive viewport style states.
- WP_Style_Engine_CSS_Declarations::__construct()Constructor for this object.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function wp_render_block_states_support( $block_content, $block ) { if ( empty( $block['blockName'] ) || empty( $block_content ) ) { return $block_content; } $block_name = $block['blockName']; $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_name ); if ( ! $block_type ) { return $block_content; } $supported_pseudo_states = WP_Theme_JSON::VALID_BLOCK_PSEUDO_SELECTORS[ $block_name ] ?? array(); $style = $block['attrs']['style'] ?? array(); $css_rules = array(); $viewport_settings = wp_get_global_settings( array( 'viewport' ) ); $responsive_media_queries = WP_Theme_JSON::get_viewport_media_queries( $viewport_settings ); foreach ( $supported_pseudo_states as $pseudo_state ) { if ( empty( $style[ $pseudo_state ] ) || ! is_array( $style[ $pseudo_state ] ) ) { continue; } $css_rules = array_merge( $css_rules, wp_get_block_state_style_rules( array( $pseudo_state => $style[ $pseudo_state ] ), $block_type ) ); } foreach ( $responsive_media_queries as $breakpoint => $media_query ) { if ( empty( $style[ $breakpoint ] ) || ! is_array( $style[ $breakpoint ] ) ) { continue; } $root_state_style = wp_get_root_state_style( $style[ $breakpoint ], array_merge( array( 'elements' ), $supported_pseudo_states ) ); if ( ! empty( $root_state_style ) ) { $css_rules = array_merge( $css_rules, wp_get_block_state_style_rules( array( '' => $root_state_style ), $block_type, $media_query ) ); } if ( ! empty( $style[ $breakpoint ]['elements'] ) && is_array( $style[ $breakpoint ]['elements'] ) ) { $element_selectors = wp_get_block_state_element_selectors( wp_get_block_css_selector( $block_type ) ); foreach ( $style[ $breakpoint ]['elements'] as $element_name => $element_style ) { if ( empty( $element_style ) || ! is_array( $element_style ) || empty( $element_selectors[ $element_name ] ) ) { continue; } $element_pseudo_states = WP_Theme_JSON::VALID_ELEMENT_PSEUDO_SELECTORS[ $element_name ] ?? array(); $root_element_style = wp_get_root_state_style( $element_style, $element_pseudo_states ); wp_add_block_state_style_rule( $css_rules, '', $element_selectors[ $element_name ],Changelog
Introduced in 7.1.0.
Signature, return type and hooks compared across 1 parsed release.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/block-supports/states.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.