wp_render_block_visibility_support( string $block_content, array $block ): string
- Since
- 6.9.0, 7.0.0
- Source
wp-includes/block-supports/block-visibility.php:20
Compatibility
- WordPress
- since 7.0.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in 3 of the 5 tracked releases, added in 7.0.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_block_visibility_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
- 12–97
- 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 130.
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_visibility_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 · 7 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_render_block_visibility_support() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 12–20 | ::WP_Block_Type_Registry(), ->get_registered() |
$block_visibility !== false | 25–38 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support() |
$block_visibility !== false && block_has_support() && is_array($block_visibility) && !empty($block_visibility) && is_array($viewport_config) && !empty($viewport_config) && empty($hidden_on) | 54–58 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON() |
$block_visibility !== false && block_has_support() && is_array($block_visibility) && !empty($block_visibility) && is_array($viewport_config) && !empty($viewport_config) && !empty($hidden_on) && empty($block_content) | 67–72 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), sort(), wp_style_engine_get_stylesheet_from_css_rules() |
$block_visibility !== false && block_has_support() && is_array($block_visibility) && !empty($block_visibility) && is_array($viewport_config) && !empty($viewport_config) && !empty($hidden_on) && !empty($block_content) && !->next_tag() | 74–79 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), sort(), wp_style_engine_get_stylesheet_from_css_rules(), selector(), ->next_tag() |
$block_visibility !== false && block_has_support() && is_array($block_visibility) && !empty($block_visibility) && is_array($viewport_config) && !empty($viewport_config) && !empty($hidden_on) && !empty($block_content) | 88–93 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), sort(), wp_style_engine_get_stylesheet_from_css_rules(), selector(), ->next_tag(), ->add_class(), ->get_tag(), ->next_tag(), ->get_updated_html() |
$block_visibility !== false && block_has_support() && is_array($block_visibility) && !empty($block_visibility) && is_array($viewport_config) && !empty($viewport_config) && !empty($hidden_on) && !empty($block_content) | 92–97 | ::WP_Block_Type_Registry(), ->get_registered(), block_has_support(), wp_get_global_settings(), ::WP_Theme_JSON(), sort(), wp_style_engine_get_stylesheet_from_css_rules(), selector(), ->next_tag(), ->add_class(), ->get_tag(), ->set_attribute(), ->next_tag(), ->get_updated_html() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 130 | 12–97 | 22 | |
| 8.5 | 130 | 12–97 | 22 | |
| 8.4 | 130 | 12–97 | 22 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 133 | 12–100 | 22 | |
| 8.2 | 133 | 12–100 | 22 | |
| 8.1 | 133 | 12–100 | 22 | |
| 7.4 | 133 | 12–100 | 22 |
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_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_Theme_JSON::get_viewport_media_queries()Returns CSS media queries for responsive viewport style states.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function wp_render_block_visibility_support( $block_content, $block ) { $block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] ); if ( ! $block_type ) { return $block_content; } $block_visibility = $block['attrs']['metadata']['blockVisibility'] ?? null; // Hide the block whenever the value is boolean false, regardless of the // block's current visibility support. This prevents blocks that previously // supported visibility from unintentionally appearing on the front end // after their support was disabled. if ( false === $block_visibility ) { return ''; } if ( ! block_has_support( $block_type, 'visibility', true ) ) { return $block_content; } if ( is_array( $block_visibility ) && ! empty( $block_visibility ) ) { $viewport_config = $block_visibility['viewport'] ?? null; if ( ! is_array( $viewport_config ) || empty( $viewport_config ) ) { return $block_content; } $viewport_settings = wp_get_global_settings( array( 'viewport' ) ); $viewport_media_queries = WP_Theme_JSON::get_viewport_media_queries( $viewport_settings, array( 'include_desktop' => true, ) ); /* * Viewport media queries are keyed by style-state names (`@mobile`, * `@tablet`, and `@desktop`). Block visibility metadata and generated * classes use plain viewport names, so map the keys at this boundary. */ $block_visibility_media_queries = array(); foreach ( $viewport_media_queries as $viewport_state => $media_query ) { $block_visibility_media_queries[ ltrim( $viewport_state, '@' ) ] = $media_query; } $viewport_media_queries = $block_visibility_media_queries; $hidden_on = array(); // Collect which viewport the block is hidden on (only known viewport sizes). foreach ( $viewport_config as $viewport_config_size => $is_visible ) { if ( false === $is_visible && isset( $viewport_media_queries[ $viewport_config_size ] ) ) { $hidden_on[] = $viewport_config_size; } } // If no viewport sizes have visibility set to false, return unchanged. if ( empty( $hidden_on ) ) { return $block_content; } // Maintain consistent order of viewport sizes for class name generation. sort( $hidden_on ); $css_rules = array(); $class_names = array(); foreach ( $hidden_on as $hidden_viewport_size ) { /* * If these values ever become user-defined, * they should be sanitized and kebab-cased. */ $visibility_class = 'wp-block-hidden-' . $hidden_viewport_size; $class_names[] = $visibility_class; $css_rules[] = array( 'selector' => '.' . $visibility_class, 'declarations' => array( 'display' => 'none !important', ), 'rules_group' => $viewport_media_queries[ $hidden_viewport_size ], );Changelog
Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.
Signature, return type and hooks compared across 3 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/block-supports/block-visibility.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.