WP_Theme_JSON::scope_selector │ public static │ WP 5.9.0

Function that scopes a selector with another one. This works a bit like SCSS nesting except the & operator isn't supported.

$scope = '.a, .b .c';
$selector = '> .x, .y';
$merged = scope_selector( $scope, $selector );
// $merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'

Метод класса: WP_Theme_JSON{}

Хуков нет.

Возвращает

string. Scoped selector.

Использование

$result = WP_Theme_JSON::scope_selector( $scope, $selector );
$scope(строка) (обязательный)
Selector to scope to.
$selector(строка) (обязательный)
Original selector.

Список изменений

С версии 5.9.0 Введена.
С версии 6.6.0 Added early return if missing scope or selector.

Код WP_Theme_JSON::scope_selector() WP 7.1.3

public static function scope_selector( $scope, $selector ) {
	if ( ! $scope || ! $selector ) {
		return $selector;
	}

	$scopes    = static::split_selector_list( $scope );
	$selectors = static::split_selector_list( $selector );

	$selectors_scoped = array();
	foreach ( $scopes as $outer ) {
		foreach ( $selectors as $inner ) {
			if ( ! empty( $outer ) && ! empty( $inner ) ) {
				$selectors_scoped[] = $outer . ' ' . $inner;
			} elseif ( empty( $outer ) ) {
				$selectors_scoped[] = $inner;
			} elseif ( empty( $inner ) ) {
				$selectors_scoped[] = $outer;
			}
		}
	}

	$result = implode( ', ', $selectors_scoped );
	return $result;
}