wp_render_position_support( string $block_content, array $block ): string
- Since
- 6.2.0
- Source
wp-includes/block-supports/position.php:42
Compatibility
- WordPress
- since 6.2.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_position_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
- 18–93
- 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 127.
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_position_support()
Further down the call graph this can also reach hook. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_render_position_support() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 18–22 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support() |
!empty($value) && empty($position_styles) | 58–79 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), wp_unique_id() |
!empty($value) && !empty($position_styles) | 71–93 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), wp_unique_id(), wp_style_engine_get_stylesheet_from_css_rules(), position(), ->next_tag() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 127 | 18–93 | 21 | |
| 8.5 | 127 | 18–93 | 21 | |
| 8.4 | 127 | 18–93 | 21 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 130 | 18–96 | 21 | |
| 8.2 | 130 | 18–96 | 21 | |
| 8.1 | 130 | 18–96 | 21 | |
| 7.4 | 130 | 18–96 | 21 |
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 · 7
- block_has_support()Checks whether the current block type supports the feature requested.
- wp_get_global_settings()Gets the settings resulting of merging core, theme, and user data.
- wp_unique_id()Gets unique ID.
- 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()
- 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_position_support( $block_content, $block ) { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); $has_position_support = block_has_support( $block_type, 'position', false ); if ( ! $has_position_support || empty( $block['attrs']['style']['position'] ) ) { return $block_content; } $global_settings = wp_get_global_settings(); $theme_has_sticky_support = $global_settings['position']['sticky'] ?? false; $theme_has_fixed_support = $global_settings['position']['fixed'] ?? false; // Only allow output for position types that the theme supports. $allowed_position_types = array(); if ( true === $theme_has_sticky_support ) { $allowed_position_types[] = 'sticky'; } if ( true === $theme_has_fixed_support ) { $allowed_position_types[] = 'fixed'; } $style_attribute = $block['attrs']['style'] ?? null; $class_name = wp_unique_id( 'wp-container-' ); $selector = ".$class_name"; $position_styles = array(); $position_type = $style_attribute['position']['type'] ?? ''; $wrapper_classes = array(); if ( in_array( $position_type, $allowed_position_types, true ) ) { $wrapper_classes[] = $class_name; $wrapper_classes[] = 'is-position-' . $position_type; $sides = array( 'top', 'right', 'bottom', 'left' ); foreach ( $sides as $side ) { $side_value = $style_attribute['position'][ $side ] ?? null; if ( null !== $side_value ) { /* * For fixed or sticky top positions, * ensure the value includes an offset for the logged in admin bar. */ if ( 'top' === $side && ( 'fixed' === $position_type || 'sticky' === $position_type ) ) { // Ensure 0 values can be used in `calc()` calculations. if ( '0' === $side_value || 0 === $side_value ) { $side_value = '0px'; } // Ensure current side value also factors in the height of the logged in admin bar. $side_value = "calc($side_value + var(--wp-admin--admin-bar--position-offset, 0px))"; } $position_styles[] = array( 'selector' => $selector, 'declarations' => array( $side => $side_value, ), ); } } $position_styles[] = array( 'selector' => $selector, 'declarations' => array( 'position' => $position_type, 'z-index' => '10', ), ); } if ( ! empty( $position_styles ) ) { /*Changelog
Introduced in 6.2.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/position.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.