Astra_After_Setup_Theme::modify_theme_palette_names( WP_Theme_JSON_Data $theme_json )
Modify theme palette names.
Description
Parameters
- $theme_json
-
(WP_Theme_JSON_Data) (Required) settings.
Return
(WP_Theme_JSON_Data)
Source
File: inc/class-astra-after-setup-theme.php
public function modify_theme_palette_names( $theme_json ) {
/** @psalm-suppress UndefinedDocblockClass */
$json_data = $theme_json->get_data();
$new_palette_data = array();
if ( ! empty( $json_data['settings']['color']['palette']['theme'] ) ) {
$palette = $json_data['settings']['color']['palette']['theme'];
$color_labels = Astra_Global_Palette::get_palette_labels(); // Use the reusable function for labels.
$name_pair = array();
foreach ( $color_labels as $index => $label ) {
$name_pair[ 'ast-global-color-' . $index ] = $label;
}
foreach ( $palette as $index => $color_data ) {
$slug = ! empty( $color_data['slug'] ) ? $color_data['slug'] : '';
$new_palette_data[ $index ] = array(
'name' => $name_pair[ $slug ],
'slug' => $slug,
'color' => $color_data['color'],
);
}
}
if ( ! empty( $new_palette_data ) ) {
$new_data = array(
'version' => 1,
'settings' => array(
'color' => array(
'palette' => array(
'theme' => $new_palette_data,
),
),
),
);
/** @psalm-suppress UndefinedDocblockClass */
$theme_json->update_with( $new_data );
}
return $theme_json;
}
Expand full source code Collapse full source code View on Trac