From be6941ec62f2e14c273709c56bce84a8f48dada8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:10:57 +0200 Subject: [PATCH 1/7] Fire an action after FastCGI purge_all() --- admin/class-fastcgi-purger.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/admin/class-fastcgi-purger.php b/admin/class-fastcgi-purger.php index 44f299b9..0968f977 100644 --- a/admin/class-fastcgi-purger.php +++ b/admin/class-fastcgi-purger.php @@ -166,6 +166,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' ); } } From da0056ce24d9cdca7ee756a43c22820587524627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:11:10 +0200 Subject: [PATCH 2/7] Fire an action after Redis purge_all() --- admin/class-phpredis-purger.php | 6 ++++++ admin/class-predis-purger.php | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/admin/class-phpredis-purger.php b/admin/class-phpredis-purger.php index 46cb353a..76e92f52 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' ); } /** diff --git a/admin/class-predis-purger.php b/admin/class-predis-purger.php index 2413e3f9..7c61af81 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' ); } /** From 7d2ce226c1ec97e34d6f4fae354b3806654745e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:16:28 +0200 Subject: [PATCH 3/7] Add filter for the URL to be purged --- admin/class-fastcgi-purger.php | 9 +++++++++ admin/class-phpredis-purger.php | 9 +++++++++ admin/class-predis-purger.php | 9 +++++++++ admin/class-purger.php | 8 ++++++++ 4 files changed, 35 insertions(+) diff --git a/admin/class-fastcgi-purger.php b/admin/class-fastcgi-purger.php index 0968f977..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 ); diff --git a/admin/class-phpredis-purger.php b/admin/class-phpredis-purger.php index 76e92f52..1943b426 100644 --- a/admin/class-phpredis-purger.php +++ b/admin/class-phpredis-purger.php @@ -103,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 7c61af81..27a04cbd 100644 --- a/admin/class-predis-purger.php +++ b/admin/class-predis-purger.php @@ -100,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..1c26e1f8 100644 --- a/admin/class-purger.php +++ b/admin/class-purger.php @@ -420,6 +420,14 @@ 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 ); $response = wp_remote_get( $url ); From 5ad52f8e646b935df94fb989725da04d0e290673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:17:00 +0200 Subject: [PATCH 4/7] Add filter for the cached file name --- admin/class-purger.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/admin/class-purger.php b/admin/class-purger.php index 1c26e1f8..b462ab3e 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 ) ) { From 1fa6949e7cc542149652592428a344e9133c6a6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:17:49 +0200 Subject: [PATCH 5/7] Add action for after deleting file from cache --- admin/class-purger.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/admin/class-purger.php b/admin/class-purger.php index b462ab3e..d421c329 100644 --- a/admin/class-purger.php +++ b/admin/class-purger.php @@ -417,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' ); } From 8f1724531be54f8bbd74c47ce320ecbd1e6d7c4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:18:24 +0200 Subject: [PATCH 6/7] Add an action before purge request --- admin/class-purger.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/admin/class-purger.php b/admin/class-purger.php index d421c329..a738cd08 100644 --- a/admin/class-purger.php +++ b/admin/class-purger.php @@ -448,6 +448,15 @@ protected function do_remote_get( $url ) { */ $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 ); if ( is_wp_error( $response ) ) { From 54b7f7581de7dfc11510a4d9f9d5776e98561fba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Viemero=CC=88?= Date: Thu, 28 Feb 2019 22:18:30 +0200 Subject: [PATCH 7/7] Add an action after purge request --- admin/class-purger.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/admin/class-purger.php b/admin/class-purger.php index a738cd08..4899c428 100644 --- a/admin/class-purger.php +++ b/admin/class-purger.php @@ -483,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 ); } }