WP_Theme_JSON::get_feature_selector( $feature_selectors, string $feature_key, string $default_selector ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only by core. It is listed here for completeness.

Returns the appropriate selector for a block support feature’s preset CSS variables.

Description

If the block defines a feature-level selector (as a string or an object with a root key), that selector is returned. Otherwise, the block’s default selector is used.

Parameters

string|array<string, string>> $feature_selectors The block’s feature selectors map.
$feature_keystringrequired
The feature to look up (e.g. 'dimensions').
$default_selectorstringrequired
Fallback selector.

Return

string The resolved selector.

Source

private static function get_feature_selector( array $feature_selectors, string $feature_key, string $default_selector ): string {
	if ( ! isset( $feature_selectors[ $feature_key ] ) ) {
		return $default_selector;
	}

	$feature = $feature_selectors[ $feature_key ];

	if ( is_string( $feature ) ) {
		return $feature;
	}

	if ( isset( $feature['root'] ) && is_string( $feature['root'] ) ) {
		return $feature['root'];
	}

	return $default_selector;
}

Changelog

VersionDescription
7.1.0Introduced.

User Contributed Notes

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