block_has_support()
Checks whether the current block type supports the feature requested.
No Hooks.
Returns
true|false. Whether the feature is supported.
Usage
block_has_support( $block_type, $feature, $default_value );
- $block_type(WP_Block_Type|null) (required)
- Block type to check for support.
- $feature(string|array) (required)
- Feature slug, or path to a specific feature to check support for.
- $default_value(mixed)
- Fallback value for feature support.
Default:false
Changelog
| Since 5.8.0 | Introduced. |
| Since 6.4.0 | The $feature parameter now supports a string. |
block_has_support() block has support code WP 7.0
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 );
}