Skip to content

Commit

Permalink
Clear styles cache when customizing the theme (#3812)
Browse files Browse the repository at this point in the history
  • Loading branch information
malithsen authored Jan 30, 2025
1 parent dee0523 commit 39c7201
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions includes/payment-methods/class-wc-stripe-upe-payment-gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ public function __construct() {
add_action( 'wc_ajax_wc_stripe_save_appearance', [ $this, 'save_appearance_ajax' ] );

add_filter( 'woocommerce_saved_payment_methods_list', [ $this, 'filter_saved_payment_methods_list' ], 10, 2 );

// Add hooks for clearing appearance transients when theme is updated
add_action( 'customize_save_after', [ $this, 'clear_appearance_transients' ] );
add_action( 'save_post', [ $this, 'clear_appearance_transients_block_theme' ], 10, 2 );
}

/**
Expand Down Expand Up @@ -2823,4 +2827,22 @@ public function save_appearance_ajax() {
);
}
}

/**
* Clears the appearance transients when a Block theme is updated or customized.
* This ensures the UPE appearance is regenerated with the new theme colors.
*/
public function clear_appearance_transients_block_theme( $post_id, $post ) {
if ( in_array( $post->post_type, [ 'wp_global_styles' ], true ) ) {
delete_transient( $this->get_appearance_transient_key( true ) );
}
}

/**
* Clears the appearance transients when a classic theme is updated or customized.
* This ensures the UPE appearance is regenerated with the new theme colors.
*/
public function clear_appearance_transients() {
delete_transient( $this->get_appearance_transient_key() );
}
}

0 comments on commit 39c7201

Please sign in to comment.