You've already forked wp-bootstrap
v0.3.3 - Fix style variation bridge to read from theme palette origin
WordPress puts active variation colors in the 'theme' palette origin, not 'custom'. Detection now compares theme origin against base defaults. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -152,40 +152,39 @@ add_action( 'wp_enqueue_scripts', 'wp_bootstrap_rtl_styles', 20 );
|
||||
*/
|
||||
if ( ! function_exists( 'wp_bootstrap_variation_colors' ) ) :
|
||||
function wp_bootstrap_variation_colors() {
|
||||
// Check if user has customized colors (selected a variation or edited
|
||||
// colors in the Site Editor). The custom origin palette will contain
|
||||
// our theme slugs (base, contrast, primary, etc.) only when a variation
|
||||
// or manual color override has been saved.
|
||||
$custom_palette = wp_get_global_settings( array( 'color', 'palette', 'custom' ) );
|
||||
$has_variation = false;
|
||||
if ( ! empty( $custom_palette ) && is_array( $custom_palette ) ) {
|
||||
foreach ( $custom_palette as $entry ) {
|
||||
if ( isset( $entry['slug'] ) && in_array( $entry['slug'], array( 'base', 'contrast', 'primary' ), true ) ) {
|
||||
$has_variation = true;
|
||||
break;
|
||||
// Read the theme origin palette — this contains the base theme.json
|
||||
// colors merged with the active style variation (if any).
|
||||
$theme_palette = wp_get_global_settings( array( 'color', 'palette', 'theme' ) );
|
||||
$colors = array();
|
||||
if ( ! empty( $theme_palette ) && is_array( $theme_palette ) ) {
|
||||
foreach ( $theme_palette as $entry ) {
|
||||
if ( ! empty( $entry['slug'] ) && ! empty( $entry['color'] ) ) {
|
||||
$colors[ $entry['slug'] ] = $entry['color'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Compare against base theme.json defaults to detect an active variation.
|
||||
// WordPress puts variation colors in the 'theme' origin, not 'custom'.
|
||||
$base_defaults = array(
|
||||
'base' => '#ffffff',
|
||||
'contrast' => '#212529',
|
||||
'primary' => '#0d6efd',
|
||||
);
|
||||
|
||||
$is_default = true;
|
||||
foreach ( $base_defaults as $slug => $default_color ) {
|
||||
if ( ! empty( $colors[ $slug ] ) && strtolower( $colors[ $slug ] ) !== $default_color ) {
|
||||
$is_default = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// No variation active — let Bootstrap's compiled CSS handle both modes.
|
||||
if ( ! $has_variation ) {
|
||||
if ( $is_default ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Merge palette origins: default < theme < custom.
|
||||
// Query each origin separately because the combined API omits 'custom'.
|
||||
$colors = array();
|
||||
foreach ( array( 'default', 'theme', 'custom' ) as $origin ) {
|
||||
$origin_palette = wp_get_global_settings( array( 'color', 'palette', $origin ) );
|
||||
if ( ! empty( $origin_palette ) && is_array( $origin_palette ) ) {
|
||||
foreach ( $origin_palette as $entry ) {
|
||||
if ( ! empty( $entry['slug'] ) && ! empty( $entry['color'] ) ) {
|
||||
$colors[ $entry['slug'] ] = $entry['color'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $colors['base'] ) || empty( $colors['contrast'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user