WP_Theme_JSON::get_block_selectors( object $block_type, string $root_selector ): array

In this article

Returns the selectors metadata for a block.

Parameters

$block_typeobjectrequired
The block type.
$root_selectorstringrequired
The block’s root selector.

Return

array The custom selectors set by the block.

Source

protected static function get_block_selectors( $block_type, $root_selector ) {
	if ( ! empty( $block_type->selectors ) ) {
		return $block_type->selectors;
	}

	$selectors = array( 'root' => $root_selector );
	foreach ( static::BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS as $key => $feature ) {
		$feature_selector = wp_get_block_css_selector( $block_type, $key );
		if ( null !== $feature_selector ) {
			$selectors[ $feature ] = array( 'root' => $feature_selector );
		}
	}

	return $selectors;
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

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