WP_Theme_JSON::scope_selector() – Function that scopes a selector with another one. This works a bit like SCSS nesting except the `&` operator isn’t supported.

You appear to be a bot. Output may be restricted

Description

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

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

Usage

$string = WP_Theme_JSON::scope_selector( $scope, $selector );

Parameters

$scope
( string ) required – Selector to scope to.
$selector
( string ) required – Original selector.

Returns

string Scoped selector.

Source

File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:

1 to 13 of 13
  protected static function scope_selector( $scope, $selector ) {
    $scopes    = explode( ',', $scope );
    $selectors = explode( ',', $selector );

    $selectors_scoped = array();
    foreach ( $scopes as $outer ) {
      foreach ( $selectors as $inner ) {
        $selectors_scoped[] = trim( $outer ) . ' ' . trim( $inner );
      }
    }

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

 View on GitHub View on Trac