You've already forked wp-bootstrap
perf: color variation CSS transient caching and Twig auto_reload fix (v1.0.9)
- functions.php: cache wp_bootstrap_variation_colors() output in a 24-hour transient keyed by md5(get_stylesheet()); invalidate on switch_theme and save_post_wp_global_styles so Design Editor changes apply immediately - TwigService.php: change auto_reload from hardcoded true to WP_DEBUG so Twig stops stat()-ing compiled template files on every production request Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -175,6 +175,17 @@ add_action( 'wp_enqueue_scripts', 'wp_bootstrap_rtl_styles', 20 );
|
||||
*/
|
||||
if ( ! function_exists( 'wp_bootstrap_variation_colors' ) ) :
|
||||
function wp_bootstrap_variation_colors() {
|
||||
$transient_key = 'wp_bootstrap_variation_css_' . md5( get_stylesheet() );
|
||||
$cached_css = get_transient( $transient_key );
|
||||
|
||||
if ( false !== $cached_css ) {
|
||||
// '' means default palette (no inline CSS needed); non-empty string is the computed CSS.
|
||||
if ( '' !== $cached_css ) {
|
||||
wp_add_inline_style( 'wp-bootstrap-style', $cached_css );
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 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' ) );
|
||||
@@ -205,10 +216,12 @@ if ( ! function_exists( 'wp_bootstrap_variation_colors' ) ) :
|
||||
|
||||
// No variation active — let Bootstrap's compiled CSS handle both modes.
|
||||
if ( $is_default ) {
|
||||
set_transient( $transient_key, '', DAY_IN_SECONDS );
|
||||
return;
|
||||
}
|
||||
|
||||
if ( empty( $colors['base'] ) || empty( $colors['contrast'] ) ) {
|
||||
set_transient( $transient_key, '', DAY_IN_SECONDS );
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -280,6 +293,9 @@ if ( ! function_exists( 'wp_bootstrap_variation_colors' ) ) :
|
||||
. '[data-bs-theme=light]{' . $light_css . '}'
|
||||
. '[data-bs-theme=dark]{' . $dark_css . '}';
|
||||
|
||||
// Cache for 24 hours; invalidated on theme switch or global-styles save.
|
||||
set_transient( $transient_key, $css, DAY_IN_SECONDS );
|
||||
|
||||
// Attach after the compiled stylesheet so variation values override
|
||||
// Bootstrap's hardcoded dark-mode defaults via source order.
|
||||
wp_add_inline_style( 'wp-bootstrap-style', $css );
|
||||
@@ -287,6 +303,16 @@ if ( ! function_exists( 'wp_bootstrap_variation_colors' ) ) :
|
||||
endif;
|
||||
add_action( 'wp_enqueue_scripts', 'wp_bootstrap_variation_colors', 30 );
|
||||
|
||||
/**
|
||||
* Invalidate the color variation CSS transient when global styles or theme change.
|
||||
*/
|
||||
add_action( 'switch_theme', function () {
|
||||
delete_transient( 'wp_bootstrap_variation_css_' . md5( get_stylesheet() ) );
|
||||
} );
|
||||
add_action( 'save_post_wp_global_styles', function () {
|
||||
delete_transient( 'wp_bootstrap_variation_css_' . md5( get_stylesheet() ) );
|
||||
} );
|
||||
|
||||
/**
|
||||
* Build Bootstrap surface CSS variables for a given background/foreground pair.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user