Skip to content

Instantly share code, notes, and snippets.

@thomasmb
Created April 10, 2020 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasmb/29bbf6ff0c08227a4d4abac8cf1c7809 to your computer and use it in GitHub Desktop.
Save thomasmb/29bbf6ff0c08227a4d4abac8cf1c7809 to your computer and use it in GitHub Desktop.
WP Nginx helper purge cache on multiple domains
<?php
/**
* When the site admin is hosted on a different domain, this filter can be used to
* purge the cache of the exposed site
*/
add_filter( 'rt_nginx_helper_purge_url', function( $url ){
$find = 'admin-domain.com';
$replace = 'live-domain.com';
if( stripos( $url, $find ) !== false ) {
global $nginx_purger;
if( isset( $nginx_purger ) && method_exists( $nginx_purger, 'purge_url' ) ) {
$live_url = str_replace( $find, $replace, $url );
$nginx_purger->purge_url( $live_url );
}
}
return $url;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment