WP_Theme_JSON::get_block_element_selectors( string $root_selector ): array

In this article

Generates all the element selectors for a block.

Parameters

$root_selectorstringrequired
The block’s root CSS selector.

Return

array The block’s element selectors.

Source

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;
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

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