Created
April 10, 2020 13:56
-
-
Save thomasmb/29bbf6ff0c08227a4d4abac8cf1c7809 to your computer and use it in GitHub Desktop.
WP Nginx helper purge cache on multiple domains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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