wp_render_dimensions_support( string $block_content, array $block ): string
- Since
- 6.5.0
- Source
wp-includes/block-supports/dimensions.php:120
Description
This block support uses the render_block hook to ensure that it is also applied to non-server-rendered blocks.
Compatibility
- WordPress
- since 6.5.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
$block_contentstring- Rendered block content.
$blockarray- Block object.
Return value
string- Filtered block content.
Performance profile
How much work a call to wp_render_dimensions_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
- Light
- Scaling
- Scales with input
- Instructions
- 22–100
- 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 123.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What one call costs · 8 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_render_dimensions_support() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 22–26 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support() |
wp_should_skip_block_supports_serialization() | 28–32 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization() |
!wp_should_skip_block_supports_serialization() && empty($styles) | 53–61 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization(), wp_is_explicit_aspect_ratio_value(), dimensions() |
!wp_should_skip_block_supports_serialization() && !empty($styles) && !->next_tag() | 62–70 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization(), wp_is_explicit_aspect_ratio_value(), dimensions(), wp_style_engine_get_styles(), ->next_tag(), ->get_updated_html() |
!wp_should_skip_block_supports_serialization() && ->next_tag() && empty($existing_style) | 77–85 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization(), wp_is_explicit_aspect_ratio_value(), dimensions(), wp_style_engine_get_styles(), ->next_tag(), ->get_attribute(), ->set_attribute(), ->get_updated_html() |
!wp_should_skip_block_supports_serialization() && ->next_tag() && !empty($existing_style) | 83–92 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization(), wp_is_explicit_aspect_ratio_value(), dimensions(), wp_style_engine_get_styles(), ->next_tag(), ->get_attribute(), str_ends_with(), ->set_attribute(), ->get_updated_html() |
!wp_should_skip_block_supports_serialization() && !empty($styles) && ->next_tag() && empty($existing_style) | 84–93 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization(), wp_is_explicit_aspect_ratio_value(), dimensions(), wp_style_engine_get_styles(), ->next_tag(), ->get_attribute(), ->set_attribute(), explode(), ->get_updated_html() |
!wp_should_skip_block_supports_serialization() && !empty($styles) && ->next_tag() && !empty($existing_style) | 90–100 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_should_skip_block_supports_serialization(), wp_is_explicit_aspect_ratio_value(), dimensions(), wp_style_engine_get_styles(), ->next_tag(), ->get_attribute(), str_ends_with(), ->set_attribute(), explode(), ->get_updated_html() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 123 | 22–100 | 18 | |
| 8.5 | 123 | 22–100 | 18 | |
| 8.4 | 123 | 22–100 | 18 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 126 | 22–100 | 18 | |
| 8.2 | 126 | 22–100 | 18 | |
| 8.1 | 126 | 22–100 | 18 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 127 | 22–101 | 18 |
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 · 9
- block_has_support()Checks whether the current block type supports the feature requested.
- wp_should_skip_block_supports_serialization()Checks whether serialization of the current block's supported properties should occur.
- wp_is_explicit_aspect_ratio_value()Checks whether an aspectRatio block-support value is explicitly set.
- wp_style_engine_get_styles()Global public interface method to generate styles from a single style object, e.g. the value of a block's attributes.style object or the top level styles in theme.json.
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- str_contains()Polyfill for `str_contains()` function added in PHP 8.0.
- WP_Block_Type_Registry::get_instance()::get_registered()
- WP_Block_Type_Registry::get_instance()Utility method to retrieve the main instance of the class.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function wp_render_dimensions_support( $block_content, $block ) { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); $block_attributes = ( isset( $block['attrs'] ) && is_array( $block['attrs'] ) ) ? $block['attrs'] : array(); $has_aspect_ratio_support = block_has_support( $block_type, array( 'dimensions', 'aspectRatio' ), false ); if ( ! $has_aspect_ratio_support || wp_should_skip_block_supports_serialization( $block_type, 'dimensions', 'aspectRatio' ) ) { return $block_content; } $dimensions_block_styles = array(); $dimensions_block_styles['aspectRatio'] = $block_attributes['style']['dimensions']['aspectRatio'] ?? null; // To ensure the aspect ratio does not get overridden by `minHeight` or `height` unset any existing rule. if ( wp_is_explicit_aspect_ratio_value( $dimensions_block_styles['aspectRatio'] ) ) { $dimensions_block_styles['minHeight'] = 'unset'; $dimensions_block_styles['height'] = 'unset'; } elseif ( isset( $block_attributes['style']['dimensions']['minHeight'] ) || isset( $block_attributes['minHeight'] ) ) { $dimensions_block_styles['aspectRatio'] = 'unset'; } $styles = wp_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) ); if ( ! empty( $styles['css'] ) ) { // Inject dimensions styles to the first element, presuming it's the wrapper, if it exists. $tags = new WP_HTML_Tag_Processor( $block_content ); if ( $tags->next_tag() ) { $existing_style = $tags->get_attribute( 'style' ); $updated_style = ''; if ( ! empty( $existing_style ) ) { $updated_style = $existing_style; if ( ! str_ends_with( $existing_style, ';' ) ) { $updated_style .= ';'; } } $updated_style .= $styles['css']; $tags->set_attribute( 'style', $updated_style ); if ( ! empty( $styles['classnames'] ) ) { foreach ( explode( ' ', $styles['classnames'] ) as $class_name ) { if ( str_contains( $class_name, 'aspect-ratio' ) && ! wp_is_explicit_aspect_ratio_value( $block_attributes['style']['dimensions']['aspectRatio'] ?? null ) ) { continue; } $tags->add_class( $class_name ); } } } return $tags->get_updated_html(); } return $block_content;}Changelog
Introduced in 6.5.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/block-supports/dimensions.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.