Skip to content

Instantly share code, notes, and snippets.

@rafsuntaskin
Last active June 1, 2023 17:01
Show Gist options
  • Save rafsuntaskin/339b037d2e2dd20874db652b581ea55b to your computer and use it in GitHub Desktop.
Save rafsuntaskin/339b037d2e2dd20874db652b581ea55b to your computer and use it in GitHub Desktop.
cache buster for AR page and TC Checkout on pantheo
<?php
add_action( 'init', 'rt_et_bust_cache_varnish_pantheon' );
function rt_et_bust_cache_varnish_pantheon() {
/*
* Set or replace $regex_path_patterns accordingly.
*
* We don't set this variable for you, so you must define it
* yourself per your specific use case before the following conditional.
*
* Example: anything in the /news/ directory
*/
$regex_path_patterns = array(
'/attendee-registration/',
'/tickets-checkout/',
);
// Loop through the patterns.
foreach ( $regex_path_patterns as $regex_path_pattern ) {
if ( preg_match( '#^'. $regex_path_pattern . '?#', $_SERVER['REQUEST_URI'] ) ) {
setcookie( 'NO_CACHE', '1', time() + 0, $regex_path_pattern, $_SERVER['HTTP_HOST'] );
// No need to continue the loop once there's a match.
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment