block_has_support( WP_Block_Type $block_type, string|array $feature, mixed $default_value = false ): bool
- Since
- 5.8.0, 6.4.0
- Source
wp-includes/blocks.php:2557
Compatibility
- WordPress
- since 6.4.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_typeWP_Block_Type- Block type to check for support.
$featurestring|array- Feature slug, or path to a specific feature to check support for.
$default_valuemixedoptional- Fallback value for feature support. Default false.Default:
false
Return value
bool- Whether the feature is supported.
Performance profile
How much work a call to block_has_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
- Trivial
- Scaling
- Constant
- Instructions
- 9–28
- Plugin surface
- None
- Called by
- 29
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 34.
Nothing here hands control to plugin code.
29 places 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 block_has_support() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 9–25 | none |
$block_type instanceof && is_array($feature) | 22–28 | _wp_array_get() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 34 instructions, 9–28 executed per call, 6 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 · 1
- _wp_array_get()Accesses an array in depth based on a path of keys.
Used by · 29
- WP_Duotone::get_selector()Get the CSS selector for a block type.
- WP_Duotone::register_duotone_support()Registers the style and colors block attributes for block types that support it.
- WP_Theme_JSON::get_layout_styles()Gets the CSS layout rules for a particular block from theme.json layout definitions.
- _wp_add_block_level_preset_styles()Render the block level presets stylesheet.
- _wp_add_block_level_presets_class()Update the block content with block level presets class name.
- apply_block_hooks_to_content()Runs the hooked blocks algorithm on the given content.
- wp_apply_alignment_support()Adds CSS classes for block alignment to the incoming attributes array.
- wp_apply_aria_label_support()Add the aria-label to the output.
- wp_apply_custom_classname_support()Adds the custom classnames to the output.
- wp_apply_dimensions_support()Adds CSS classes for block dimensions to the incoming attributes array.
- wp_apply_generated_classname_support()Adds the generated classnames to the output.
- wp_apply_shadow_support()Add CSS classes and inline styles for shadow features to the incoming attributes array.
Show all 29
- wp_apply_spacing_support()Adds CSS classes for block spacing to the incoming attributes array.
- wp_has_border_feature_support()Checks whether the current block type supports the border feature requested.
- wp_register_alignment_support()Registers the align block attribute for block types that support it.
- wp_register_aria_label_support()Registers the aria-label block attribute for block types that support it.
- wp_register_background_support()Registers the style block attribute for block types that support it.
- wp_register_border_support()Registers the style attribute used by the border feature if needed for block types that support borders.
- wp_register_custom_classname_support()Registers the custom classname block attribute for block types that support it.
- wp_register_dimensions_support()Registers the style block attribute for block types that support it.
- wp_register_layout_support()Registers the layout block attribute for block types that support it.
- wp_register_position_support()Registers the style block attribute for block types that support it.
- wp_register_shadow_support()Registers the style and shadow block attributes for block types that support it.
- wp_register_spacing_support()Registers the style block attribute for block types that support it.
- wp_render_background_support()Renders the background styles to the block wrapper.
- wp_render_block_visibility_support()Render nothing if the block is hidden.
- wp_render_dimensions_support()Renders server-side dimensions styles to the block wrapper.
- wp_render_layout_support_flag()Renders the layout config to the block wrapper.
- wp_render_position_support()Renders position styles to the block wrapper.
Source code
function block_has_support( $block_type, $feature, $default_value = false ) { $block_support = $default_value; if ( $block_type instanceof WP_Block_Type ) { if ( is_array( $feature ) && count( $feature ) === 1 ) { $feature = $feature[0]; } if ( is_array( $feature ) ) { $block_support = _wp_array_get( $block_type->supports, $feature, $default_value ); } elseif ( isset( $block_type->supports[ $feature ] ) ) { $block_support = $block_type->supports[ $feature ]; } } return true === $block_support || is_array( $block_support );}Changelog
Introduced in 5.8.0. One change between 6.7.7 and 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$block_type retyped from WP_Block_Type to WP_Block_Type|null.verified against source$feature parameter now supports a string.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/blocks.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.