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_json
arrayrequired- The tree to extract style nodes from.
$selectors
arrayoptional- List of selectors per block.
Default:
array()
Source
*
* @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,
* )
*
* @since 5.8.0
* @since 5.9.0 Added the `$origins` parameter.
*
* @param array $settings Settings to process.
* @param string[] $origins List of origins to process.
* @return array The modified $declarations.
*/
protected static function compute_preset_vars( $settings, $origins ) {
$declarations = array();
foreach ( static::PRESETS_METADATA as $preset_metadata ) {
if ( empty( $preset_metadata['css_vars'] ) ) {
Changelog
Version | Description |
---|---|
5.8.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.