W3cubDocs

/WordPress

WP_Duotone::get_selector( WP_Block_Type $block_type ): string|null

Get the CSS selector for a block type.

Description

This handles selectors defined in color.__experimentalDuotone support if filter.duotone support is not defined.

Parameters

$block_typeWP_Block_Typerequired
Block type to check for support.

Return

string|null The CSS selector or null if there is no support.

Source

private static function get_selector( $block_type ) {
	if ( ! ( $block_type instanceof WP_Block_Type ) ) {
		return null;
	}

	/*
	 * Backward compatibility with `supports.color.__experimentalDuotone`
	 * is provided via the `block_type_metadata_settings` filter. If
	 * `supports.filter.duotone` has not been set and the experimental
	 * property has been, the experimental property value is copied into
	 * `supports.filter.duotone`.
	 */
	$duotone_support = block_has_support( $block_type, array( 'filter', 'duotone' ) );
	if ( ! $duotone_support ) {
		return null;
	}

	/*
	 * If the experimental duotone support was set, that value is to be
	 * treated as a selector and requires scoping.
	 */
	$experimental_duotone = isset( $block_type->supports['color']['__experimentalDuotone'] )
		? $block_type->supports['color']['__experimentalDuotone']
		: false;
	if ( $experimental_duotone ) {
		$root_selector = wp_get_block_css_selector( $block_type );
		return is_string( $experimental_duotone )
			? WP_Theme_JSON::scope_selector( $root_selector, $experimental_duotone )
			: $root_selector;
	}

	// Regular filter.duotone support uses filter.duotone selectors with fallbacks.
	return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
}

Changelog

Version Description
6.3.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_duotone/get_selector