From af2253b29f6efee744d4676df1397d08cc5dab27 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Wed, 8 Feb 2023 02:17:04 +0530 Subject: [PATCH 1/8] feat: adds checkbox for skipping feeds --- admin/class-fastcgi-purger.php | 4 +-- admin/class-nginx-helper-admin.php | 1 + .../partials/nginx-helper-general-options.php | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/admin/class-fastcgi-purger.php b/admin/class-fastcgi-purger.php index 687d8625..cce53b57 100644 --- a/admin/class-fastcgi-purger.php +++ b/admin/class-fastcgi-purger.php @@ -57,7 +57,7 @@ public function purge_url( $url, $feed = true ) { $this->delete_cache_file_for( $_url_purge ); - if ( $feed ) { + if ( $feed && ! empty( $nginx_helper_admin->options['purge_feeds'] ) ) { $feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/'; $this->delete_cache_file_for( $feed_url ); @@ -79,7 +79,7 @@ public function purge_url( $url, $feed = true ) { $this->do_remote_get( $_url_purge ); - if ( $feed ) { + if ( $feed && ! empty( $nginx_helper_admin->options['purge_feeds'] ) ) { $feed_url = rtrim( $_url_purge_base, '/' ) . '/feed/'; $this->do_remote_get( $feed_url ); diff --git a/admin/class-nginx-helper-admin.php b/admin/class-nginx-helper-admin.php index d94d86b9..cc30df57 100644 --- a/admin/class-nginx-helper-admin.php +++ b/admin/class-nginx-helper-admin.php @@ -272,6 +272,7 @@ public function nginx_helper_default_settings() { 'purge_page_on_mod' => 1, 'purge_page_on_new_comment' => 1, 'purge_page_on_deleted_comment' => 1, + 'purge_feeds' => 1, 'redis_hostname' => '127.0.0.1', 'redis_port' => '6379', 'redis_prefix' => 'nginx-cache:', diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index 0dc388a4..8c559b31 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -38,6 +38,7 @@ 'purge_page_on_mod' => FILTER_SANITIZE_STRING, 'purge_page_on_new_comment' => FILTER_SANITIZE_STRING, 'purge_page_on_deleted_comment' => FILTER_SANITIZE_STRING, + 'purge_feeds' => FILTER_SANITIZE_STRING, 'smart_http_expire_form_nonce' => FILTER_SANITIZE_STRING, ); @@ -490,6 +491,38 @@ + + + + + +
+

+ +

+
+
+ + +   + + + + +
+
+
From ccbbd934fee51fef68b709fad1d0a539ba1a0d54 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 25 Mar 2024 19:22:13 +0530 Subject: [PATCH 2/8] fix: fixes spacing --- .../partials/nginx-helper-general-options.php | 112 +++++++++--------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index e587ea70..99edeb0f 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -166,31 +166,31 @@ >   PURGE/url %2$s', - esc_html__( 'Using a GET request to', 'nginx-helper' ), - esc_html__( '(Default option)', 'nginx-helper' ) - ), - array( 'strong' => array() ) - ); + echo wp_kses( + sprintf( + '%1$s PURGE/url %2$s', + esc_html__( 'Using a GET request to', 'nginx-helper' ), + esc_html__( '(Default option)', 'nginx-helper' ) + ), + array( 'strong' => array() ) + ); ?>
ngx_cache_purge' - ), - array( - 'strong' => array(), - 'a' => array( - 'href' => array(), - ), - ) - ); + echo wp_kses( + sprintf( + // translators: %s Nginx cache purge module link. + __( 'Uses the %s module.', 'nginx-helper' ), + 'ngx_cache_purge' + ), + array( + 'strong' => array(), + 'a' => array( + 'href' => array(), + ), + ) + ); ?> @@ -199,15 +199,15 @@ >  
RT_WP_NGINX_HELPER_CACHE_PATH. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key "$scheme$request_method$host$request_uri").', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'Checks for matching cache file in RT_WP_NGINX_HELPER_CACHE_PATH. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key "$scheme$request_method$host$request_uri").', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?> @@ -287,7 +287,7 @@   @@ -295,10 +295,10 @@ />   post (or page/custom post) is modified or added.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a post (or page/custom post) is modified or added.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -308,7 +308,7 @@   @@ -316,10 +316,10 @@ />   published post (or page/custom post) is trashed', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a published post (or page/custom post) is trashed', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -339,7 +339,7 @@   @@ -347,10 +347,10 @@ >   post is published.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a post is published.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -360,7 +360,7 @@   @@ -368,10 +368,10 @@ >   comment is approved/published.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a comment is approved/published.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -381,7 +381,7 @@   @@ -389,10 +389,10 @@ >   comment is unapproved/deleted.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a comment is unapproved/deleted.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -510,7 +510,7 @@   @@ -518,10 +518,10 @@ />   feeds along with posts & pages.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'purge feeds along with posts & pages.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
From eba37e5b05be633734f381376545d16194de2510 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 25 Mar 2024 19:24:08 +0530 Subject: [PATCH 3/8] fix: fixes spacing --- admin/partials/nginx-helper-general-options.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index 99edeb0f..2fdca798 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -166,14 +166,14 @@ >   PURGE/url %2$s', - esc_html__( 'Using a GET request to', 'nginx-helper' ), - esc_html__( '(Default option)', 'nginx-helper' ) - ), - array( 'strong' => array() ) - ); + echo wp_kses( + sprintf( + '%1$s PURGE/url %2$s', + esc_html__( 'Using a GET request to', 'nginx-helper' ), + esc_html__( '(Default option)', 'nginx-helper' ) + ), + array( 'strong' => array() ) + ); ?>
From 85db7e20e8a34f91a75637fe5b0e8ceee28f821c Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 25 Mar 2024 19:29:29 +0530 Subject: [PATCH 4/8] fix: fixes spacing --- .../partials/nginx-helper-general-options.php | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index 2fdca798..948133c2 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -178,19 +178,19 @@
ngx_cache_purge' - ), - array( - 'strong' => array(), - 'a' => array( - 'href' => array(), - ), - ) - ); + echo wp_kses( + sprintf( + // translators: %s Nginx cache purge module link. + __( 'Uses the %s module.', 'nginx-helper' ), + 'ngx_cache_purge' + ), + array( + 'strong' => array(), + 'a' => array( + 'href' => array(), + ), + ) + ); ?> From 1c2eafc615a08cf8c77f9ec2cbbc9c985b4a4782 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 25 Mar 2024 19:47:13 +0530 Subject: [PATCH 5/8] fix: fixes spacing --- .../partials/nginx-helper-general-options.php | 334 +++++++++--------- 1 file changed, 167 insertions(+), 167 deletions(-) diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index 948133c2..ab0f2605 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -199,15 +199,15 @@ >  
RT_WP_NGINX_HELPER_CACHE_PATH. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key "$scheme$request_method$host$request_uri").', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'Checks for matching cache file in RT_WP_NGINX_HELPER_CACHE_PATH. Does not require any other modules. Requires that the cache be stored on the same server as WordPress. You must also be using the default nginx cache options (levels=1:2) and (fastcgi_cache_key "$scheme$request_method$host$request_uri").', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?> @@ -287,7 +287,7 @@   @@ -295,10 +295,10 @@ />   post (or page/custom post) is modified or added.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a post (or page/custom post) is modified or added.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -308,7 +308,7 @@   @@ -316,10 +316,10 @@ />   published post (or page/custom post) is trashed', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a published post (or page/custom post) is trashed', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -339,7 +339,7 @@   @@ -347,10 +347,10 @@ >   post is published.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a post is published.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -360,7 +360,7 @@   @@ -368,10 +368,10 @@ >   comment is approved/published.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a comment is approved/published.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -381,7 +381,7 @@   @@ -389,10 +389,10 @@ >   comment is unapproved/deleted.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a comment is unapproved/deleted.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -414,7 +414,7 @@   @@ -422,10 +422,10 @@ />   post (or page/custom post) is modified or added.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a post (or page/custom post) is modified or added.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -435,7 +435,7 @@   @@ -443,10 +443,10 @@ />   published post (or page/custom post) is trashed.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a published post (or page/custom post) is trashed.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -457,7 +457,7 @@   @@ -465,10 +465,10 @@ />   comment is approved/published.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a comment is approved/published.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -478,7 +478,7 @@   @@ -486,10 +486,10 @@ />   comment is unapproved/deleted.', 'nginx-helper' ), - array( 'strong' => array() ) - ); + echo wp_kses( + __( 'when a comment is unapproved/deleted.', 'nginx-helper' ), + array( 'strong' => array() ) + ); ?>
@@ -497,38 +497,38 @@
- - - +
-

+ + + - - -
+

-

-
-
- + + +
+
+   - -
-
+ +
+ + +

@@ -560,16 +560,16 @@
- - - - - + + + + +
- /> - -
+ /> + +
- +


'; - echo wp_kses( - sprintf( - // translators: %s file url. - __( 'Check you have write permission on %s', 'nginx-helper' ), - esc_url( $log_path . 'map.conf' ) - ), - array( 'strong' => array() ) - ); + esc_html_e( 'Can\'t write on map file.', 'nginx-helper' ); + echo '

'; + echo wp_kses( + sprintf( + // translators: %s file url. + __( 'Check you have write permission on %s', 'nginx-helper' ), + esc_url( $log_path . 'map.conf' ) + ), + array( 'strong' => array() ) + ); ?>

- +
- %2$s', - esc_html__( 'Nginx Map path to include in nginx settings', 'nginx-helper' ), - esc_html__( '(recommended)', 'nginx-helper' ) - ); - ?> + %2$s', + esc_html__( 'Nginx Map path to include in nginx settings', 'nginx-helper' ), + esc_html__( '(recommended)', 'nginx-helper' ) + ); + ?>
@@ -718,7 +718,7 @@ echo '

'; echo wp_kses( sprintf( - // translators: %s file url. + // translators: %s file url. __( 'Check you have write permission on %s', 'nginx-helper' ), esc_url( $log_path . 'nginx.log' ) ), @@ -733,71 +733,71 @@ - - - - - - - - - - - - - - - + + + + + + + + + + + + + + - + +
- - - - - -
- - - - - -
- - - -
- - - - -

- -

+
+ + + + + +
+ + + + + +
+ + + +
+ + + +

+ +

+ -
- \ No newline at end of file + From 1bcedea43643f03c118d349885d9e48089dbd0b7 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 25 Mar 2024 19:51:53 +0530 Subject: [PATCH 6/8] fix: fixes spacing --- .../partials/nginx-helper-general-options.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index ab0f2605..bc100ab3 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -178,9 +178,9 @@
ngx_cache_purge' ), @@ -368,7 +368,7 @@ >   comment is approved/published.', 'nginx-helper' ), array( 'strong' => array() ) ); @@ -646,7 +646,7 @@ echo '

'; echo wp_kses( sprintf( - // translators: %s file url. + // translators: %s file url. __( 'Check you have write permission on %s', 'nginx-helper' ), esc_url( $log_path . 'map.conf' ) ), @@ -656,7 +656,7 @@

@@ -782,14 +782,14 @@ + if ( $error_log_filesize ) { + ?>

- +

+ ?> From 01424b0b0dbcf11b93658572b1018c12c6eb69b5 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 25 Mar 2024 20:03:04 +0530 Subject: [PATCH 7/8] refactor: makes 'purge_feeds' disable by default --- admin/class-nginx-helper-admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/admin/class-nginx-helper-admin.php b/admin/class-nginx-helper-admin.php index f91289a7..d47760d7 100644 --- a/admin/class-nginx-helper-admin.php +++ b/admin/class-nginx-helper-admin.php @@ -272,7 +272,7 @@ public function nginx_helper_default_settings() { 'purge_page_on_mod' => 1, 'purge_page_on_new_comment' => 1, 'purge_page_on_deleted_comment' => 1, - 'purge_feeds' => 1, + 'purge_feeds' => 0, 'redis_hostname' => '127.0.0.1', 'redis_port' => '6379', 'redis_prefix' => 'nginx-cache:', From 5d779c4488d440e403fc47014d947ff8be3b61f7 Mon Sep 17 00:00:00 2001 From: Amaan Khan Date: Mon, 1 Apr 2024 15:50:19 +0530 Subject: [PATCH 8/8] refactor: updates default options handling logic --- admin/class-nginx-helper-admin.php | 2 +- admin/partials/nginx-helper-general-options.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/admin/class-nginx-helper-admin.php b/admin/class-nginx-helper-admin.php index d47760d7..f91289a7 100644 --- a/admin/class-nginx-helper-admin.php +++ b/admin/class-nginx-helper-admin.php @@ -272,7 +272,7 @@ public function nginx_helper_default_settings() { 'purge_page_on_mod' => 1, 'purge_page_on_new_comment' => 1, 'purge_page_on_deleted_comment' => 1, - 'purge_feeds' => 0, + 'purge_feeds' => 1, 'redis_hostname' => '127.0.0.1', 'redis_port' => '6379', 'redis_prefix' => 'nginx-cache:', diff --git a/admin/partials/nginx-helper-general-options.php b/admin/partials/nginx-helper-general-options.php index bc100ab3..ef1423dc 100644 --- a/admin/partials/nginx-helper-general-options.php +++ b/admin/partials/nginx-helper-general-options.php @@ -59,6 +59,18 @@ $nginx_helper_admin->nginx_helper_default_settings() ); + $site_options = get_site_option( 'rt_wp_nginx_helper_options', array() ); + + // Uncheck checkbox fields whose default value is `1` but user has unchecked. + foreach ( $nginx_helper_admin->nginx_helper_default_settings() as $default_setting_field => $default_setting_value ) { + + if ( 1 === $default_setting_value && isset( $site_options[ $default_setting_field ] ) && empty( $all_inputs[ $default_setting_field ] ) ) { + + $nginx_settings[ $default_setting_field ] = 0; + + } + } + if ( ( ! is_numeric( $nginx_settings['log_filesize'] ) ) || ( empty( $nginx_settings['log_filesize'] ) ) ) { $error_log_filesize = __( 'Log file size must be a number.', 'nginx-helper' ); unset( $nginx_settings['log_filesize'] );