wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_split_selector_list › WordPress Function

Since7.1.0
Deprecatedn/a
wp_split_selector_list ( $selector )
Parameters:
  • (string) $selector CSS selector list.
    Required: Yes
Returns:
  • (string[]) Selectors.
Defined at:
Codex:

Splits a selector list by top-level commas.



Source

function wp_split_selector_list( $selector ) {
	if ( ! str_contains( $selector, ',' ) ) {
		return array( $selector );
	}

	$selectors         = array();
	$current_selector  = '';
	$parentheses_depth = 0;
	$selector_length   = strlen( $selector );

	for ( $i = 0; $i < $selector_length; $i++ ) {
		$char = $selector[ $i ];

		if ( '(' === $char ) {
			++$parentheses_depth;
		} elseif ( ')' === $char && $parentheses_depth > 0 ) {
			--$parentheses_depth;
		} elseif ( ',' === $char && 0 === $parentheses_depth ) {
			$selectors[]      = $current_selector;
			$current_selector = '';
			continue;
		}

		$current_selector .= $char;
	}

	$selectors[] = $current_selector;

	return $selectors;
}