wpseek.com
Eine auf WordPress spezialiserte Suchmaschine für Entwickler und Theme-Autoren



wp_split_selector_list › WordPress Function

Seit7.1.0
Veraltetn/v
wp_split_selector_list ( $selector )
Parameter:
  • (string) $selector CSS selector list.
    Erforderlich: Ja
Gibt zurück:
  • (string[]) Selectors.
Definiert in:
Codex:

Splits a selector list by top-level commas.



Quellcode

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