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

You appear to be a bot. Output may be restricted

Description

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

[

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

Usage

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

Parameters

$theme_json
( array ) required – The tree to extract setting 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 31 of 31
  protected static function get_setting_nodes( $theme_json, $selectors = array() ) {
    $nodes = array();
    if ( ! isset( $theme_json['settings'] ) ) {
      return $nodes;
    }

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

    // Calculate paths for blocks.
    if ( ! isset( $theme_json['settings']['blocks'] ) ) {
      return $nodes;
    }

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

      $nodes[] = array(
        'path'     => array( 'settings', 'blocks', $name ),
        'selector' => $selector,
      );
    }

    return $nodes;
  }
 

 View on GitHub View on Trac