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

In this article

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

Description

[ [ ‘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 ], ]

Parameters

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

Default:array()

Return

array An array of style nodes metadata.

Source


			$result[ $slug ] = $value;
		}
	}
	return $result;
}

/**
 * Similar to get_settings_values_by_slug, but doesn't compute the value.
 *
 * @since 5.9.0
 *
 * @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 the key and value are both the slug.
 */
protected static function get_settings_slugs( $settings, $preset_metadata, $origins = null ) {
	if ( null === $origins ) {
		$origins = static::VALID_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'] );

			// Use the array as a set so we don't get duplicates.
			$result[ $slug ] = $slug;
		}
	}
	return $result;
}

/**
 * Transforms a slug into a CSS Custom Property.
 *
 * @since 5.9.0
 *
 * @param string $input String to replace.
 * @param string $slug  The slug value to use to generate the custom property.
 * @return string The CSS Custom Property. Something along the lines of `--wp--preset--color--black`.
 */
protected static function replace_slug_in_string( $input, $slug ) {
	return strtr( $input, array( '$slug' => $slug ) );
}

/**
 * Given the block settings, extracts the CSS Custom Properties
 * for the presets and adds them to the $declarations array
 * following the format:
 *
 *     array(
 *       'name'  => 'property_name',
 *       'value' => 'property_value,
 *     )
 *

Changelog

VersionDescription
5.8.0Introduced.

User Contributed Notes

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