WP_Theme_JSON::get_block_element_selectors()protected staticWP 6.3.0

Generates all the element selectors for a block.

Method of the class: WP_Theme_JSON{}

No Hooks.

Return

Array. The block's element selectors.

Usage

$result = WP_Theme_JSON::get_block_element_selectors( $root_selector );
$root_selector(string) (required)
The block's root CSS selector.

Changelog

Since 6.3.0 Introduced.

WP_Theme_JSON::get_block_element_selectors() code WP 6.6.2

protected static function get_block_element_selectors( $root_selector ) {
	/*
	 * Assign defaults, then override those that the block sets by itself.
	 * If the block selector is compounded, will append the element to each
	 * individual block selector.
	 */
	$block_selectors   = explode( ',', $root_selector );
	$element_selectors = array();
	foreach ( static::ELEMENTS as $el_name => $el_selector ) {
		$element_selector = array();
		foreach ( $block_selectors as $selector ) {
			if ( $selector === $el_selector ) {
				$element_selector = array( $el_selector );
				break;
			}
			$element_selector[] = static::prepend_to_selector( $el_selector, $selector . ' ' );
		}
		$element_selectors[ $el_name ] = implode( ',', $element_selector );
	}

	return $element_selectors;
}