wpseek.com
A WordPress-centric search engine for devs and theme authors
wp_build_state_selector › WordPress Function
Since7.1.0
Deprecatedn/a
› wp_build_state_selector ( $base_selector, $block_selector, $state, $block_name = null )
| Parameters: (4) |
|
| Returns: |
|
| Defined at: |
|
| Codex: | |
| Change Log: |
|
Builds a scoped selector from a block selector and optional pseudo-state.
Source
function wp_build_state_selector( $base_selector, $block_selector, $state, $block_name = null ) {
if ( ! is_string( $block_selector ) || '' === trim( $block_selector ) ) {
return $base_selector . $state;
}
$selectors = wp_split_selector_list( $block_selector );
$scoped_selectors = array();
foreach ( $selectors as $selector ) {
$selector = trim( $selector );
if ( '' === $selector ) {
continue;
}
$ancestor = wp_get_state_selector_ancestor( $selector, $block_name );
$selector = substr( $selector, strlen( $ancestor ) );
/*
* Replace only the leading block selector part (e.g. class name,
* attribute selector, ID, or tag name) with the block instance selector.
* Preserve anything after that prefix, including modifier classes on the
* same element and combinators without spaces.
*/
if ( preg_match( '/^([.#]?[-_a-zA-Z0-9]+|\[[^\]]+\])/', $selector, $matches ) ) {
$scoped_selectors[] = $ancestor . $base_selector . substr( $selector, strlen( $matches[0] ) ) . $state;
continue;
}
$scoped_selectors[] = $ancestor . $base_selector . $state;
}
return empty( $scoped_selectors )
? $base_selector . $state
: implode( ', ', $scoped_selectors );
}