WP_Duotone::get_selector
Get the CSS selector for a block type.
This handles selectors defined in color.__experimentalDuotone support if filter.duotone support is not defined.
Method of the class: WP_Duotone{}
No Hooks.
Returns
String|null. The CSS selector or null if there is no support.
Usage
$result = WP_Duotone::get_selector( $block_type );
- $block_type(WP_Block_Type) (required)
- Block type to check for support.
Changelog
| Since 6.3.0 | Introduced. |
WP_Duotone::get_selector() WP Duotone::get selector code WP 7.0
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 = $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 );
}