block_has_support( WP_Block_Type $block_type, string|array $feature, mixed $default_value = false ): bool

In this article

Checks whether the current block type supports the feature requested.

Parameters

$block_typeWP_Block_Typerequired
Block type to check for support.
$featurestring|arrayrequired
Feature slug, or path to a specific feature to check support for.
$default_valuemixedoptional
Fallback value for feature support.

Default:false

Return

bool Whether the feature is supported.

Source

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

VersionDescription
6.4.0The $feature parameter now supports a string.
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.