Automattic\WooCommerce\EmailEditor\Integrations\Utils
Styles_Helper::palette_definitions
Every color the palette defines, one entry per slug, highest priority origin first.
WP_Theme_JSON layers origins so a later one wins, so they are read in reverse of that order. One entry per slug matters because a lookup reads the first and the stylesheet's cascade reads the last, which would give a block a different color by route. An entry needs a usable slug and color to be kept, and an incomplete one does not claim its slug.
Метод класса: Styles_Helper{}
Хуков нет.
Возвращает
array. Flat list of color definitions, one per slug, each with a usable slug and color.
Использование
$result = Styles_Helper::palette_definitions( $settings ): array;
- $settings(массив) (обязательный)
- Theme settings array, as WP_Theme_JSON::get_settings() returns it.
Код Styles_Helper::palette_definitions() Styles Helper::palette definitions WC 11.3.0
public static function palette_definitions( array $settings ): array {
$palette = $settings['color']['palette'] ?? array();
// The palette arrives through a filter, and a non-array origin is a TypeError in
// array_merge() rather than a warning.
$definitions = array();
foreach ( array( 'custom', 'theme', 'blocks', 'default' ) as $origin ) {
if ( isset( $palette[ $origin ] ) && is_array( $palette[ $origin ] ) ) {
$definitions = array_merge( $definitions, $palette[ $origin ] );
}
}
$by_slug = array();
foreach ( $definitions as $definition ) {
if ( ! is_array( $definition ) ) {
continue;
}
$slug = $definition['slug'] ?? null;
$color = $definition['color'] ?? null;
// An entry has to be usable to claim the slug, or it shuts out an origin that defines
// the same slug properly.
if ( ! is_string( $slug ) || '' === $slug || ! is_string( $color ) || '' === trim( $color ) ) {
continue;
}
// First origin wins, so a slug already seen is a lower-priority duplicate.
if ( ! array_key_exists( $slug, $by_slug ) ) {
$by_slug[ $slug ] = $definition;
}
}
return array_values( $by_slug );
}