Nginx Helper - Version 1.9.7

Version Description

  • Remove timestamp if cron or wp-cli #114 - by samedwards
  • Fixed notices and warnings.
Download this release

Release Info

Developer chandrapatel
Plugin Icon 128x128 Nginx Helper
Version 1.9.7
Comparing to
See all releases

Code changes from version 1.9.6 to 1.9.7

Files changed (5) hide show
  1. composer.json +1 -1
  2. nginx-helper.php +7 -3
  3. purger.php +36 -27
  4. readme.txt +11 -7
  5. redis-purger.php +36 -33
composer.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "rtcamp/nginx-helper",
3
- "description": "Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/published. Also does few more things.",
4
  "keywords": ["wordpress", "plugin", "nginx", "nginx-helper", "fastcgi", "redis-cahce", "redis", "cache"],
5
  "homepage": "https://rtcamp.com/nginx-helper/",
6
  "license": "GPL-2.0+",
1
  {
2
  "name": "rtcamp/nginx-helper",
3
+ "description": "Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/published. Also does a few more things.",
4
  "keywords": ["wordpress", "plugin", "nginx", "nginx-helper", "fastcgi", "redis-cahce", "redis", "cache"],
5
  "homepage": "https://rtcamp.com/nginx-helper/",
6
  "license": "GPL-2.0+",
nginx-helper.php CHANGED
@@ -2,13 +2,13 @@
2
  /*
3
  Plugin Name: Nginx Helper
4
  Plugin URI: https://rtcamp.com/nginx-helper/
5
- Description: Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things.
6
- Version: 1.9.6
7
  Author: rtCamp
8
  Author URI: https://rtcamp.com
9
  Text Domain: nginx-helper
10
  Requires at least: 3.0
11
- Tested up to: 4.3
12
  */
13
 
14
  namespace rtCamp\WP\Nginx {
@@ -271,6 +271,10 @@ namespace rtCamp\WP\Nginx {
271
 
272
  if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
273
  return;
 
 
 
 
274
  $timestamps = "\n<!--" .
275
  "Cached using Nginx-Helper on " . current_time( 'mysql' ) . ". " .
276
  "It took " . get_num_queries() . " queries executed in " . timer_stop() . " seconds." .
2
  /*
3
  Plugin Name: Nginx Helper
4
  Plugin URI: https://rtcamp.com/nginx-helper/
5
+ Description: Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.
6
+ Version: 1.9.7
7
  Author: rtCamp
8
  Author URI: https://rtcamp.com
9
  Text Domain: nginx-helper
10
  Requires at least: 3.0
11
+ Tested up to: 4.5.2
12
  */
13
 
14
  namespace rtCamp\WP\Nginx {
271
 
272
  if ( defined( 'DOING_AJAX' ) && DOING_AJAX )
273
  return;
274
+ if ( defined( 'DOING_CRON' ) && DOING_CRON )
275
+ return;
276
+ if ( defined( 'WP_CLI' ) && WP_CLI )
277
+ return;
278
  $timestamps = "\n<!--" .
279
  "Cached using Nginx-Helper on " . current_time( 'mysql' ) . ". " .
280
  "It took " . get_num_queries() . " queries executed in " . timer_stop() . " seconds." .
purger.php CHANGED
@@ -758,6 +758,10 @@ namespace rtCamp\WP\Nginx {
758
  /** Source - http://stackoverflow.com/a/1360437/156336 **/
759
 
760
  function unlinkRecursive( $dir, $deleteRootToo ) {
 
 
 
 
761
  if ( ! $dh = opendir( $dir ) ) {
762
  return;
763
  }
@@ -780,49 +784,54 @@ namespace rtCamp\WP\Nginx {
780
  return;
781
  }
782
 
783
- function purge_urls() {
784
 
785
  global $rt_wp_nginx_helper;
786
 
787
  $parse = parse_url( site_url() );
788
 
 
 
 
 
 
 
789
  switch ($rt_wp_nginx_helper->options['purge_method']) {
 
790
  case 'unlink_files':
791
  $_url_purge_base = $parse[ 'scheme' ] . '://' . $parse[ 'host' ];
792
 
793
- if( isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ) {
794
- $purge_urls = explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] );
795
-
796
- foreach ($purge_urls as $purge_url ) {
797
- $purge_url = trim( $purge_url );
798
-
799
- if( strpos( $purge_url, '*' ) === false ) {
800
- $purge_url = $_url_purge_base . $purge_url;
801
- $this->log( "- Purging URL | " . $url );
802
- $this->_delete_cache_file_for( $purge_url );
803
- }
804
- }
805
- }
806
  break;
 
807
  case 'get_request':
808
  // Go to default case
809
  default:
810
  $_url_purge_base = $parse[ 'scheme' ] . '://' . $parse[ 'host' ] . '/purge';
811
 
812
- if( isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ) {
813
- $purge_urls = explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] );
814
-
815
- foreach ($purge_urls as $purge_url ) {
816
- $purge_url = trim( $purge_url );
817
-
818
- if( strpos( $purge_url, '*' ) === false ) {
819
- $purge_url = $_url_purge_base . $purge_url;
820
- $this->log( "- Purging URL | " . $url );
821
- $this->_do_remote_get( $purge_url );
822
- }
823
- }
824
- }
825
  break;
 
826
  }
827
 
828
  }
758
  /** Source - http://stackoverflow.com/a/1360437/156336 **/
759
 
760
  function unlinkRecursive( $dir, $deleteRootToo ) {
761
+ if ( ! is_dir( $dir ) ) {
762
+ return;
763
+ }
764
+
765
  if ( ! $dh = opendir( $dir ) ) {
766
  return;
767
  }
784
  return;
785
  }
786
 
787
+ function purge_urls() {
788
 
789
  global $rt_wp_nginx_helper;
790
 
791
  $parse = parse_url( site_url() );
792
 
793
+ $purge_urls = isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ?
794
+ explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] ) : array();
795
+
796
+ // Allow plugins/themes to modify/extend urls. Pass urls array in first parameter, second says if wildcards are allowed
797
+ $purge_urls = apply_filters('rt_nginx_helper_purge_urls', $purge_urls, false);
798
+
799
  switch ($rt_wp_nginx_helper->options['purge_method']) {
800
+
801
  case 'unlink_files':
802
  $_url_purge_base = $parse[ 'scheme' ] . '://' . $parse[ 'host' ];
803
 
804
+ if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
805
+ foreach ($purge_urls as $purge_url ) {
806
+ $purge_url = trim( $purge_url );
807
+
808
+ if( strpos( $purge_url, '*' ) === false ) {
809
+ $purge_url = $_url_purge_base . $purge_url;
810
+ $this->log( "- Purging URL | " . $purge_url );
811
+ $this->_delete_cache_file_for( $purge_url );
812
+ }
813
+ }
814
+ }
 
 
815
  break;
816
+
817
  case 'get_request':
818
  // Go to default case
819
  default:
820
  $_url_purge_base = $parse[ 'scheme' ] . '://' . $parse[ 'host' ] . '/purge';
821
 
822
+ if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
823
+ foreach ($purge_urls as $purge_url ) {
824
+ $purge_url = trim( $purge_url );
825
+
826
+ if( strpos( $purge_url, '*' ) === false ) {
827
+ $purge_url = $_url_purge_base . $purge_url;
828
+ $this->log( "- Purging URL | " . $purge_url );
829
+ $this->_do_remote_get( $purge_url );
830
+ }
831
+ }
832
+ }
 
 
833
  break;
834
+
835
  }
836
 
837
  }
readme.txt CHANGED
@@ -1,14 +1,14 @@
1
  === Nginx Helper ===
2
- Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123
3
  Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
4
  Requires at least: 3.0
5
- Tested up to: 4.5
6
- Stable tag: 1.9.6
7
  License: GPLv2 or later (of-course)
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate Link: http://rtcamp.com/donate/
10
 
11
- Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does few more things.
12
 
13
  == Description ==
14
 
@@ -114,6 +114,10 @@ Please post your problem in [our free support forum](http://community.rtcamp.com
114
 
115
  == Changelog ==
116
 
 
 
 
 
117
  = 1.9.6 =
118
  * Fixed cache purging on post publish.
119
  * Error fixed when redis server not installed.
@@ -322,6 +326,6 @@ Fix url escaping [#82](https://github.com/rtCamp/nginx-helper/pull/82) - by
322
 
323
  == Upgrade Notice ==
324
 
325
- = 1.9.6 =
326
- * Fixed cache purging on post publish.
327
- * Error fixed when redis server not installed.
1
  === Nginx Helper ===
2
+ Contributors: rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards
3
  Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
4
  Requires at least: 3.0
5
+ Tested up to: 4.5.2
6
+ Stable tag: 1.9.7
7
  License: GPLv2 or later (of-course)
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
  Donate Link: http://rtcamp.com/donate/
10
 
11
+ Cleans nginx's fastcgi/proxy cache or redis-cahce whenever a post is edited/published. Also does a few more things.
12
 
13
  == Description ==
14
 
114
 
115
  == Changelog ==
116
 
117
+ = 1.9.7 =
118
+ * Remove timestamp if cron or wp-cli [#114](https://github.com/rtCamp/nginx-helper/pull/114) - by [samedwards](https://profiles.wordpress.org/samedwards/)
119
+ * Fixed notices and warnings.
120
+
121
  = 1.9.6 =
122
  * Fixed cache purging on post publish.
123
  * Error fixed when redis server not installed.
326
 
327
  == Upgrade Notice ==
328
 
329
+ = 1.9.7 =
330
+ * Remove timestamp if cron or wp-cli [#114](https://github.com/rtCamp/nginx-helper/pull/114) - by [samedwards](https://profiles.wordpress.org/samedwards/)
331
+ * Fixed notices and warnings.
redis-purger.php CHANGED
@@ -665,45 +665,48 @@ namespace rtCamp\WP\Nginx {
665
  $this->log( "* Purged Everything!" );
666
  $this->log( "* * * * *" );
667
  //delete_multi_keys("*");
668
- delete_keys_by_wildcard("*");
669
- }
670
-
671
- function purge_urls()
672
  {
673
  global $rt_wp_nginx_helper;
674
-
675
- $parse = parse_url( site_url() );
676
  $host = $rt_wp_nginx_helper->options['redis_hostname'];
677
  $prefix = $rt_wp_nginx_helper->options['redis_prefix'];
678
  $_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
679
 
680
- if( isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ) {
681
- $purge_urls = explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] );
682
-
683
- foreach ($purge_urls as $purge_url ) {
684
- $purge_url = trim( $purge_url );
685
-
686
- if( strpos( $purge_url, '*' ) === false ) {
687
- $purge_url = $_url_purge_base . $purge_url;
688
- $status = delete_single_key( $purge_url );
689
- if( $status ) {
690
- $this->log( "- Purge URL | " . $purge_url );
691
- } else {
692
- $this->log( "- Not Found | " . $purge_url, 'ERROR' );
693
- }
694
- } else {
695
- $purge_url = $_url_purge_base . $purge_url;
696
- $status = delete_keys_by_wildcard( $purge_url );
697
- if( $status ) {
698
- $this->log( "- Purge Wild Card URL | " . $purge_url . " | ". $status . " url purged" );
699
- } else {
700
- $this->log( "- Not Found | " . $purge_url, 'ERROR' );
 
 
 
 
 
 
 
701
  }
702
- }
703
- }
704
- }
705
- }
706
-
707
  }
708
-
709
  }
665
  $this->log( "* Purged Everything!" );
666
  $this->log( "* * * * *" );
667
  //delete_multi_keys("*");
668
+ delete_keys_by_wildcard("*");
669
+ }
670
+
671
+ function purge_urls()
672
  {
673
  global $rt_wp_nginx_helper;
674
+
675
+ $parse = parse_url( site_url() );
676
  $host = $rt_wp_nginx_helper->options['redis_hostname'];
677
  $prefix = $rt_wp_nginx_helper->options['redis_prefix'];
678
  $_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
679
 
680
+ $purge_urls = isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ?
681
+ explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] ) : array();
682
+
683
+ // Allow plugins/themes to modify/extend urls. Pass urls array in first parameter, second says if wildcards are allowed
684
+ $purge_urls = apply_filters('rt_nginx_helper_purge_urls', $purge_urls, true);
685
+
686
+ if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
687
+ foreach ($purge_urls as $purge_url ) {
688
+ $purge_url = trim( $purge_url );
689
+
690
+ if( strpos( $purge_url, '*' ) === false ) {
691
+ $purge_url = $_url_purge_base . $purge_url;
692
+ $status = delete_single_key( $purge_url );
693
+ if( $status ) {
694
+ $this->log( "- Purge URL | " . $purge_url );
695
+ } else {
696
+ $this->log( "- Not Found | " . $purge_url, 'ERROR' );
697
+ }
698
+ } else {
699
+ $purge_url = $_url_purge_base . $purge_url;
700
+ $status = delete_keys_by_wildcard( $purge_url );
701
+ if( $status ) {
702
+ $this->log( "- Purge Wild Card URL | " . $purge_url . " | ". $status . " url purged" );
703
+ } else {
704
+ $this->log( "- Not Found | " . $purge_url, 'ERROR' );
705
+ }
706
+ }
707
+ }
708
  }
709
+ }
710
+
 
 
 
711
  }
 
712
  }