WP_Theme_JSON::get_style_nodes() – Builds metadata for the style nodes, which returns in the form of:

You appear to be a bot. Output may be restricted

Description

Builds metadata for the style nodes, which returns in the form of:

[

  • [
  • 'path' => [ 'path', 'to', 'some', 'node' ],
  • 'selector' => 'CSS selector for some node',
  • 'duotone' => 'CSS selector for duotone for some node'
  • ],
  • [
  • 'path' => ['path', 'to', 'other', 'node' ],
  • 'selector' => 'CSS selector for other node',
  • 'duotone' => null
  • ],
  • ]

Usage

$array = WP_Theme_JSON::get_style_nodes( $theme_json, $selectors );

Parameters

$theme_json
( array ) required – The tree to extract style nodes from.
$selectors
( array ) optional – List of selectors per block.

Returns

array

Source

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

1 to 55 of 55
  protected static function get_style_nodes( $theme_json, $selectors = array() ) {
    $nodes = array();
    if ( ! isset( $theme_json['styles'] ) ) {
      return $nodes;
    }

    // Top-level.
    $nodes[] = array(
      'path'     => array( 'styles' ),
      'selector' => static::ROOT_BLOCK_SELECTOR,
    );

    if ( isset( $theme_json['styles']['elements'] ) ) {
      foreach ( $theme_json['styles']['elements'] as $element => $node ) {
        $nodes[] = array(
          'path'     => array( 'styles', 'elements', $element ),
          'selector' => static::ELEMENTS[ $element ],
        );
      }
    }

    // Blocks.
    if ( ! isset( $theme_json['styles']['blocks'] ) ) {
      return $nodes;
    }

    foreach ( $theme_json['styles']['blocks'] as $name => $node ) {
      $selector = null;
      if ( isset( $selectors[ $name ]['selector'] ) ) {
        $selector = $selectors[ $name ]['selector'];
      }

      $duotone_selector = null;
      if ( isset( $selectors[ $name ]['duotone'] ) ) {
        $duotone_selector = $selectors[ $name ]['duotone'];
      }

      $nodes[] = array(
        'path'     => array( 'styles', 'blocks', $name ),
        'selector' => $selector,
        'duotone'  => $duotone_selector,
      );

      if ( isset( $theme_json['styles']['blocks'][ $name ]['elements'] ) ) {
        foreach ( $theme_json['styles']['blocks'][ $name ]['elements'] as $element => $node ) {
          $nodes[] = array(
            'path'     => array( 'styles', 'blocks', $name, 'elements', $element ),
            'selector' => $selectors[ $name ]['elements'][ $element ],
          );
        }
      }
    }

    return $nodes;
  }
 

 View on GitHub View on Trac