WP_Theme_JSON::get_setting_nodes() WordPress Method

The get_setting_nodes() method is used to retrieve an array of setting objects for a given WP_Theme object. Each setting object contains three properties: id, title and type. The id is the setting identifier, the title is the human-readable name of the setting, and the type is the data type of the setting value. The get_setting_nodes() method accepts two arguments: the WP_Theme object and an array of setting identifiers. The get_setting_nodes() method returns an array of setting objects or an empty array if no setting objects could be found.

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

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


Description

[ [ ‘path’ => [‘path’, ‘to’, ‘some’, ‘node’ ], ‘selector’ => ‘CSS selector for some node’ ], [ ‘path’ => [ ‘path’, ‘to’, ‘other’, ‘node’ ], ‘selector’ => ‘CSS selector for other node’ ], ]


Top ↑

Parameters

$theme_json

(array)(Required)The tree to extract setting nodes from.

$selectors

(array)(Optional)List of selectors per block.

Default value: array()


Top ↑

Return

(array)


Top ↑

Source

File: wp-includes/class-wp-theme-json.php

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

Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.