diff --git a/admin/class-fastcgi-purger.php b/admin/class-fastcgi-purger.php index 44f299b9..0862cfa5 100644 --- a/admin/class-fastcgi-purger.php +++ b/admin/class-fastcgi-purger.php @@ -28,6 +28,15 @@ public function purge_url( $url, $feed = true ) { global $nginx_helper_admin; + /** + * Filters the URL to be purged. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + */ + $url = apply_filters( 'rt_nginx_helper_purge_url', $url ); + $this->log( '- Purging URL | ' . $url ); $parse = wp_parse_url( $url ); @@ -166,6 +175,12 @@ public function purge_all() { $this->log( '* Purged Everything!' ); $this->log( '* * * * *' ); + /** + * Fire an action after the FastCGI cache has been purged. + * + * @since 2.1.0 + */ + do_action( 'rt_nginx_helper_after_fastcgi_purge_all' ); } } diff --git a/admin/class-phpredis-purger.php b/admin/class-phpredis-purger.php index 46cb353a..1943b426 100644 --- a/admin/class-phpredis-purger.php +++ b/admin/class-phpredis-purger.php @@ -85,6 +85,12 @@ public function purge_all() { $this->log( '* * * * *' ); + /** + * Fire an action after the Redis cache has been purged. + * + * @since 2.1.0 + */ + do_action( 'rt_nginx_helper_after_redis_purge_all' ); } /** @@ -97,6 +103,15 @@ public function purge_url( $url, $feed = true ) { global $nginx_helper_admin; + /** + * Filters the URL to be purged. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + */ + $url = apply_filters( 'rt_nginx_helper_purge_url', $url ); + $parse = wp_parse_url( $url ); if ( ! isset( $parse['path'] ) ) { diff --git a/admin/class-predis-purger.php b/admin/class-predis-purger.php index 2413e3f9..27a04cbd 100644 --- a/admin/class-predis-purger.php +++ b/admin/class-predis-purger.php @@ -82,6 +82,12 @@ public function purge_all() { $this->log( '* * * * *' ); + /** + * Fire an action after the Redis cache has been purged. + * + * @since 2.1.0 + */ + do_action( 'rt_nginx_helper_after_redis_purge_all' ); } /** @@ -94,6 +100,15 @@ public function purge_url( $url, $feed = true ) { global $nginx_helper_admin; + /** + * Filters the URL to be purged. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + */ + $url = apply_filters( 'rt_nginx_helper_purge_url', $url ); + $this->log( '- Purging URL | ' . $url ); $parse = wp_parse_url( $url ); diff --git a/admin/class-purger.php b/admin/class-purger.php index f0548330..4899c428 100644 --- a/admin/class-purger.php +++ b/admin/class-purger.php @@ -397,6 +397,15 @@ protected function delete_cache_file_for( $url ) { // Set path to cached file. $cached_file = $cache_path . substr( $hash, -1 ) . '/' . substr( $hash, -3, 2 ) . '/' . $hash; + /** + * Filters the cached file name. + * + * @since 2.1.0 + * + * @param string $cached_file Cached file name. + */ + $cached_file = apply_filters( 'rt_nginx_helper_purge_cached_file', $cached_file ); + // Verify cached file exists. if ( ! file_exists( $cached_file ) ) { @@ -408,6 +417,16 @@ protected function delete_cache_file_for( $url ) { // Delete the cached file. if ( unlink( $cached_file ) ) { $this->log( '- - ' . $url . ' *** PURGED ***' ); + + /** + * Fire an action after deleting file from cache. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + * @param string $cached_file Cached file name. + */ + do_action( 'rt_nginx_helper_purged_file', $url, $cached_file ); } else { $this->log( '- - An error occurred deleting the cache file. Check the server logs for a PHP warning.', 'ERROR' ); } @@ -420,6 +439,23 @@ protected function delete_cache_file_for( $url ) { * @param string $url URL to do remote request. */ protected function do_remote_get( $url ) { + /** + * Filters the URL to be purged. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + */ + $url = apply_filters( 'rt_nginx_helper_remote_purge_url', $url ); + + /** + * Fire an action before purging URL. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + */ + do_action( 'rt_nginx_helper_before_remote_purge_url', $url ); $response = wp_remote_get( $url ); @@ -447,6 +483,15 @@ protected function do_remote_get( $url ) { } + /** + * Fire an action after remote purge request. + * + * @since 2.1.0 + * + * @param string $url URL to be purged. + * @param array $response Array of results including HTTP headers. + */ + do_action( 'rt_nginx_helper_after_remote_purge_url', $url, $response ); } }