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

In this article

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’ ], ]

Parameters

$theme_jsonarrayrequired
The tree to extract setting nodes from.
$selectorsarrayoptional
List of selectors per block.

Default:array()

Return

array An array of setting nodes metadata.

Source

 *    'path'      => array( 'typography', 'fontFamilies' ),
 *    'value_key' => 'fontFamily',
 * );
 * $values_by_slug = get_settings_values_by_slug();
 * // $values_by_slug === array(
 * //   'sans-serif' => '"Helvetica Neue", sans-serif',
 * //   'serif'      => 'Georgia, serif',
 * // );
 * </code>
 *
 * @since 5.9.0
 * @since 6.6.0 Passing $settings to the callbacks defined in static::PRESETS_METADATA.
 *
 * @param array    $settings        Settings to process.
 * @param array    $preset_metadata One of the PRESETS_METADATA values.
 * @param string[] $origins         List of origins to process.
 * @return array Array of presets where each key is a slug and each value is the preset value.
 */
protected static function get_settings_values_by_slug( $settings, $preset_metadata, $origins ) {
	$preset_per_origin = _wp_array_get( $settings, $preset_metadata['path'], array() );

	$result = array();
	foreach ( $origins as $origin ) {
		if ( ! isset( $preset_per_origin[ $origin ] ) ) {
			continue;
		}
		foreach ( $preset_per_origin[ $origin ] as $preset ) {
			$slug = _wp_to_kebab_case( $preset['slug'] );

			$value = '';
			if ( isset( $preset_metadata['value_key'], $preset[ $preset_metadata['value_key'] ] ) ) {

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.