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 )
| Parameters: (3) |
|
| Returns: |
|
| Defined at: |
|
| Codex: |
Builds a scoped selector from a block selector and optional pseudo-state.
Related Functions: wp_update_core, wp_update_user, wp_add_state_style_group, wp_update_category, wp_split_selector_list
Source
function wp_build_state_selector( $base_selector, $block_selector, $state ) {
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;
}
/*
* 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[] = $base_selector . substr( $selector, strlen( $matches[0] ) ) . $state;
continue;
}
$scoped_selectors[] = $base_selector . $state;
}
return empty( $scoped_selectors )
? $base_selector . $state
: implode( ', ', $scoped_selectors );
}