Gets preset values keyed by slugs based on settings and metadata.
Description
$settings = array(
'typography' => array(
'fontFamilies' => array(
array(
'slug' => 'sansSerif',
'fontFamily' => '"Helvetica Neue", sans-serif',
),
array(
'slug' => 'serif',
'colors' => 'Georgia, serif',
)
),
),
);
$meta = array(
'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',
// );
Parameters
$settings
arrayrequired- Settings to process.
$preset_metadata
arrayrequired- One of the PRESETS_METADATA values.
$origins
string[]required- List of origins to process.
Source
$declaration_block = array_reduce(
$declarations,
static function ( $carry, $element ) {
return $carry .= $element['name'] . ': ' . $element['value'] . ';'; },
''
);
return $selector . '{' . $declaration_block . '}';
}
/**
* Given a settings array, returns the generated rulesets
* for the preset classes.
*
* @since 5.8.0
* @since 5.9.0 Added the `$origins` parameter.
*
* @param array $settings Settings to process.
* @param string $selector Selector wrapping the classes.
* @param string[] $origins List of origins to process.
* @return string The result of processing the presets.
*/
protected static function compute_preset_classes( $settings, $selector, $origins ) {
if ( static::ROOT_BLOCK_SELECTOR === $selector ) {
/*
* Classes at the global level do not need any CSS prefixed,
* and we don't want to increase its specificity.
*/
$selector = '';
}
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.