Skip to content

Commit 9c44ef8

Browse files
authored
Merge pull request #154 from rtCamp/release/1-9-12
Update readme files and minor fixes
2 parents 385c5da + b863145 commit 9c44ef8

File tree

6 files changed

+92
-69
lines changed

6 files changed

+92
-69
lines changed

README.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Nginx Helper #
22
**Contributors:** rtcamp, rahul286, saurabhshukla, manishsongirkar36, faishal, desaiuditd, darren-slatten, jk3us, daankortenbach, telofy, pjv, llonchj, jinnko, weskoop, bcole808, gungeekatx, rohanveer, chandrapatel, gagan0123, ravanh, michaelbeil, samedwards, niwreg, entr, nuvoPoint
33

4-
**Tags:** nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
5-
**Requires at least:** 3.0
6-
**Tested up to:** 4.9.5
7-
**Stable tag:** 1.9.11
8-
**License:** GPLv2 or later (of-course)
9-
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10-
**Donate Link:** http://rtcamp.com/donate/
4+
**Tags:** nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis, redis-cache, rewrite, permalinks
5+
**Requires at least:** 3.0
6+
**Tested up to:** 4.9.8
7+
**Stable tag:** 1.9.12
8+
**License:** GPLv2 or later (of-course)
9+
**License URI:** http://www.gnu.org/licenses/gpl-2.0.html
10+
**Donate Link:** http://rtcamp.com/donate/
1111

1212
Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.
1313

@@ -98,13 +98,15 @@ To purge a page immediately, follow these instructions:
9898

9999
**Q. Can I override the redis hostname, port and prefix?**
100100

101-
Yes, you can force override the redis hostname, port or prefix by using defines. For example:
101+
Yes, you can force override the redis hostname, port or prefix by defining constant in wp-config.php. For example:
102102

103-
`define('RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '10.0.0.1');`
103+
```
104+
define( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '10.0.0.1' );
104105
105-
`define('RT_WP_NGINX_HELPER_REDIS_PORT', '6000');`
106+
define( 'RT_WP_NGINX_HELPER_REDIS_PORT', '6000' );
106107
107-
`define('RT_WP_NGINX_HELPER_REDIS_PREFIX', 'page-cache:');`
108+
define( 'RT_WP_NGINX_HELPER_REDIS_PREFIX', 'page-cache:' );
109+
```
108110

109111

110112
### FAQ - Nginx Map ###
@@ -132,6 +134,9 @@ Please post your problem in [our free support forum](http://community.rtcamp.com
132134

133135
## Changelog ##
134136

137+
### 1.9.12 ###
138+
* Allow override Redis host/port/prefix by defining constant in wp-config.php [#152](https://github.com/rtCamp/nginx-helper/pull/152) - by [vincent-lu](https://github.com/vincent-lu)
139+
135140
### 1.9.11 ###
136141
* Fixed issue where permalinks without trailing slash does not purging [#124](https://github.com/rtCamp/nginx-helper/issues/124) - by Patrick
137142
* Check whether role exist or not before removing capability. [#134](https://github.com/rtCamp/nginx-helper/pull/134) - by [1gor](https://github.com/1gor)
@@ -362,6 +367,5 @@ Fix url escaping [#82](https://github.com/rtCamp/nginx-helper/pull/82) - by
362367

363368
## Upgrade Notice ##
364369

365-
### 1.9.11 ###
366-
* Fixed issue where permalinks without trailing slash does not purging [#124](https://github.com/rtCamp/nginx-helper/issues/124) - by Patrick
367-
* Check whether role exist or not before removing capability. [#134](https://github.com/rtCamp/nginx-helper/pull/134) - by [1gor](https://github.com/1gor)
370+
### 1.9.12 ###
371+
* Allow override Redis host/port/prefix by defining constant in wp-config.php [#152](https://github.com/rtCamp/nginx-helper/pull/152) - by [vincent-lu](https://github.com/vincent-lu)

admin/lib/nginx-general.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function nginx_general_options_page()
5252
$rt_wp_nginx_helper->options['purge_page_on_deleted_comment'] = ( isset( $_POST['purge_page_on_deleted_comment'] ) and ( $_POST['purge_page_on_deleted_comment'] == 1 ) ) ? 1 : 0;
5353

5454
$rt_wp_nginx_helper->options['purge_method'] = ( isset( $_POST['purge_method'] ) ) ? $_POST['purge_method'] : 'get_request';
55-
56-
$rt_wp_nginx_helper->options['purge_url'] = ( isset( $_POST['purge_url'] ) && ! empty( $_POST['purge_url'] ) ) ? esc_textarea( $_POST['purge_url'] ) : '';
55+
56+
$rt_wp_nginx_helper->options['purge_url'] = ( isset( $_POST['purge_url'] ) && ! empty( $_POST['purge_url'] ) ) ? esc_textarea( $_POST['purge_url'] ) : '';
5757
}
5858
if ( isset( $_POST['cache_method'] ) && $_POST['cache_method'] = "enable_redis" ) {
5959
$rt_wp_nginx_helper->options['redis_hostname'] = ( isset( $_POST['redis_hostname'] ) ) ? $_POST['redis_hostname'] : '127.0.0.1';
@@ -174,33 +174,33 @@ function nginx_general_options_page()
174174
$redis_port = ( empty( $rt_wp_nginx_helper->options['redis_port'] ) ) ? '6379' : $rt_wp_nginx_helper->options['redis_port'];
175175
$redis_prefix = ( empty( $rt_wp_nginx_helper->options['redis_prefix'] ) ) ? 'nginx-cache:' : $rt_wp_nginx_helper->options['redis_prefix'];
176176

177-
$redis_hostname = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $redis_hostname;
178-
$redis_port = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? RT_WP_NGINX_HELPER_REDIS_PORT : $redis_port;
179-
$redis_prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $redis_prefix;
177+
$redis_hostname = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $redis_hostname;
178+
$redis_port = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? RT_WP_NGINX_HELPER_REDIS_PORT : $redis_port;
179+
$redis_prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $redis_prefix;
180180

181-
$redis_hostname_readonly = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? 'readonly="readonly"' : '';
182-
$redis_port_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? 'readonly="readonly"' : '';
183-
$redis_prefix_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? 'readonly="readonly"' : '';
181+
$redis_hostname_readonly = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? 'readonly="readonly"' : '';
182+
$redis_port_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? 'readonly="readonly"' : '';
183+
$redis_prefix_readonly = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? 'readonly="readonly"' : '';
184184
?>
185185
<tr>
186186
<th><label for="redis_hostname"><?php _e( 'Hostname', 'nginx-helper' ); ?></label></th>
187187
<td>
188188
<input id="redis_hostname" class="medium-text" type="text" name="redis_hostname" value="<?php echo $redis_hostname; ?>" <?php echo $redis_hostname_readonly; ?> />
189-
<?php if ($redis_hostname_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
189+
<?php if ($redis_hostname_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
190190
</td>
191191
</tr>
192192
<tr>
193193
<th><label for="redis_port"><?php _e( 'Port', 'nginx-helper' ); ?></label></th>
194194
<td>
195195
<input id="redis_port" class="medium-text" type="text" name="redis_port" value="<?php echo $redis_port; ?>" <?php echo $redis_port_readonly; ?> />
196-
<?php if ($redis_port_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
196+
<?php if ($redis_port_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
197197
</td>
198198
</tr>
199199
<tr>
200200
<th><label for="redis_prefix"><?php _e( 'Prefix', 'nginx-helper' ); ?></label></th>
201201
<td>
202202
<input id="redis_prefix" class="medium-text" type="text" name="redis_prefix" value="<?php echo $redis_prefix; ?>" <?php echo $redis_prefix_readonly; ?> />
203-
<?php if ($redis_prefix_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
203+
<?php if ($redis_prefix_readonly) echo '<p class="description">Overridden by global define</p>'; ?>
204204
</td>
205205
</tr>
206206
</table>
@@ -416,7 +416,7 @@ function nginx_general_options_page()
416416
$log = fopen( $path . 'nginx.log', 'w' );
417417
fclose( $log );
418418
}
419-
419+
420420
if ( !is_writable( $path . 'nginx.log' ) ) {
421421
?>
422422
<span class="error fade" style="display : block"><p><?php printf( __( 'Can\'t write on log file.<br /><br />Check you have write permission on <strong>%s</strong>', 'nginx-helper' ), $rt_wp_nginx_helper->functional_asset_path() . 'nginx.log' ); ?></p></span><?php }

includes/redis-delete.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,27 @@
55

66
global $myredis, $rt_wp_nginx_helper, $redis_api, $lua, $rt_wp_nginx_purger;
77

8-
$host = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
9-
$port = defined('RT_WP_NGINX_HELPER_REDIS_PORT') ? RT_WP_NGINX_HELPER_REDIS_PORT : $rt_wp_nginx_helper->options['redis_port'];
8+
$host = defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
9+
$port = defined( 'RT_WP_NGINX_HELPER_REDIS_PORT' ) ? RT_WP_NGINX_HELPER_REDIS_PORT : $rt_wp_nginx_helper->options['redis_port'];
10+
1011
$redis_api = '';
1112

1213
if ( class_exists( 'Redis' ) ) { // Use PHP5-Redis if installed.
1314
try {
1415
$myredis = new Redis();
1516
$myredis->connect( $host, $port, 5 );
1617
$redis_api = 'php-redis';
17-
} catch ( Exception $e ) {
18+
} catch ( Exception $e ) {
1819
if( isset($rt_wp_nginx_purger) && !empty($rt_wp_nginx_purger) ) {
19-
$rt_wp_nginx_purger->log( $e->getMessage(), 'ERROR' );
20+
$rt_wp_nginx_purger->log( $e->getMessage(), 'ERROR' );
2021
}
2122
}
2223
} else {
2324
if( ! class_exists( 'Predis\Autoloader' ) ) {
2425
require_once 'predis.php';
2526
}
2627
Predis\Autoloader::register();
27-
28+
2829
//redis server parameter
2930
$myredis = new Predis\Client( [
3031
'host' => $host,
@@ -34,9 +35,9 @@
3435
try {
3536
$myredis->connect();
3637
$redis_api = 'predis';
37-
} catch ( Exception $e ) {
38+
} catch ( Exception $e ) {
3839
if( isset($rt_wp_nginx_purger) && !empty($rt_wp_nginx_purger) ) {
39-
$rt_wp_nginx_purger->log( $e->getMessage(), 'ERROR' );
40+
$rt_wp_nginx_purger->log( $e->getMessage(), 'ERROR' );
4041
}
4142
}
4243
}
@@ -57,9 +58,9 @@
5758
*/
5859

5960
function delete_multi_keys( $key )
60-
{
61+
{
6162
global $myredis, $redis_api, $rt_wp_nginx_purger;
62-
63+
6364
try {
6465
if ( !empty( $myredis ) ) {
6566
$matching_keys = $myredis->keys( $key );
@@ -143,4 +144,4 @@ function delete_keys_by_wildcard( $pattern )
143144
} catch ( Exception $e ) { $rt_wp_nginx_purger->log( $e->getMessage(), 'ERROR' ); }
144145
}
145146

146-
?>
147+
?>

nginx-helper.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
* Plugin Name: Nginx Helper
44
* Plugin URI: https://rtcamp.com/nginx-helper/
55
* 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.11
6+
* Version: 1.9.12
77
* Author: rtCamp
88
* Author URI: https://rtcamp.com
99
* Text Domain: nginx-helper
1010
* Requires at least: 3.0
11-
* Tested up to: 4.9.5
11+
* Tested up to: 4.9.8
1212
*
1313
* @package nginx-helper
1414
*/
@@ -414,12 +414,12 @@ function rt_nginx_get_news() {
414414
return;
415415
}
416416

417-
require_once( ABSPATH . WPINC . '/feed.php' );
417+
require_once ABSPATH . WPINC . '/feed.php';
418418

419419
$maxitems = 0;
420420

421421
// Get a SimplePie feed object from the specified feed source.
422-
$rss = fetch_feed( 'http://rtcamp.com/blog/feed/' );
422+
$rss = fetch_feed( 'https://rtcamp.com/blog/feed/' );
423423

424424
// Checks that the object is created correctly.
425425
if ( ! is_wp_error( $rss ) ) {

readme.txt

+20-5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ Tags: nginx, cache, purge, nginx map, nginx cache, maps, fastcgi, proxy, redis,
55
License: GPLv2 or later (of-course)
66
License URI: http://www.gnu.org/licenses/gpl-2.0.html
77
Requires at least: 3.0
8-
Tested up to: 4.9.5
9-
Stable tag: 1.9.11
8+
Tested up to: 4.9.8
9+
Stable tag: 1.9.12
1010

1111
Cleans nginx's fastcgi/proxy cache or redis-cache whenever a post is edited/published. Also does a few more things.
1212

@@ -92,6 +92,19 @@ To purge a page immediately, follow these instructions:
9292
* Just open this in a browser and the page will be purged instantly.
9393
* Needless to say, this won't work, if you have a page or taxonomy called 'purge'.
9494

95+
= FAQ - Nginx Redis Cache =
96+
97+
**Q. Can I override the redis hostname, port and prefix?**
98+
99+
Yes, you can force override the redis hostname, port or prefix by defining constant in wp-config.php. For example:
100+
101+
```
102+
define('RT_WP_NGINX_HELPER_REDIS_HOSTNAME', '10.0.0.1');
103+
104+
define('RT_WP_NGINX_HELPER_REDIS_PORT', '6000');
105+
106+
define('RT_WP_NGINX_HELPER_REDIS_PREFIX', 'page-cache:');
107+
```
95108

96109
= FAQ - Nginx Map =
97110

@@ -114,6 +127,9 @@ Please post your problem in [our free support forum](http://community.rtcamp.com
114127

115128
== Changelog ==
116129

130+
= 1.9.12 =
131+
* Allow override Redis host/port/prefix by defining constant in wp-config.php [#152](https://github.com/rtCamp/nginx-helper/pull/152) - by [vincent-lu](https://github.com/vincent-lu)
132+
117133
= 1.9.11 =
118134
* Fixed issue where permalinks without trailing slash does not purging [#124](https://github.com/rtCamp/nginx-helper/issues/124) - by Patrick
119135
* Check whether role exist or not before removing capability. [#134](https://github.com/rtCamp/nginx-helper/pull/134) - by [1gor](https://github.com/1gor)
@@ -344,6 +360,5 @@ Fix url escaping [#82](https://github.com/rtCamp/nginx-helper/pull/82) - by
344360

345361
== Upgrade Notice ==
346362

347-
= 1.9.11 =
348-
* Fixed issue where permalinks without trailing slash does not purging [#124](https://github.com/rtCamp/nginx-helper/issues/124) - by Patrick
349-
* Check whether role exist or not before removing capability. [#134](https://github.com/rtCamp/nginx-helper/pull/134) - by [1gor](https://github.com/1gor)
363+
= 1.9.12 =
364+
* Allow override Redis host/port/prefix by defining constant in wp-config.php [#152](https://github.com/rtCamp/nginx-helper/pull/152) - by [vincent-lu](https://github.com/vincent-lu)

redis-purger.php

+27-24
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ function purgePost( $_ID )
118118
} else {
119119
$this->_purge_by_options( $_ID, $blog_id, $rt_wp_nginx_helper->options['purge_page_on_mod'], $rt_wp_nginx_helper->options['purge_archive_on_edit'], $rt_wp_nginx_helper->options['purge_archive_on_edit'] );
120120
}
121-
121+
122122
$this->purge_urls();
123-
123+
124124
$this->log( "Function purgePost END ^^^" );
125125
}
126126

@@ -220,9 +220,9 @@ function purgeUrl( $url, $feed = true ) {
220220
$parse['path'] = '';
221221
}
222222

223-
$host = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
223+
$host = defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
224224

225-
$prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
225+
$prefix = defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
226226

227227
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'];
228228

@@ -675,11 +675,12 @@ function purge_on_check_ajax_referer( $action, $result )
675675
function true_purge_all()
676676
{
677677
global $rt_wp_nginx_helper;
678-
$prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
678+
679+
$prefix = defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
679680
$prefix = trim( $prefix );
680-
681+
681682
$this->log( '* * * * *' );
682-
683+
683684
// If Purge Cache link click from network admin then purge all
684685
if( is_network_admin() ) {
685686
delete_keys_by_wildcard( $prefix . '*' );
@@ -690,49 +691,51 @@ function true_purge_all()
690691
delete_keys_by_wildcard( $prefix . $parse['scheme'] . 'GET' . $parse['host'] . $parse['path'] . '*' );
691692
$this->log( '* ' . get_home_url() . ' Purged! * ' );
692693
}
693-
694+
694695
$this->log( '* * * * *' );
695696
}
696-
697+
697698
function purge_urls()
698699
{
699700
global $rt_wp_nginx_helper;
700-
701+
701702
$parse = parse_url( site_url() );
702-
$host = defined('RT_WP_NGINX_HELPER_REDIS_HOSTNAME') ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
703-
$prefix = defined('RT_WP_NGINX_HELPER_REDIS_PREFIX') ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
703+
704+
$host = defined( 'RT_WP_NGINX_HELPER_REDIS_HOSTNAME' ) ? RT_WP_NGINX_HELPER_REDIS_HOSTNAME : $rt_wp_nginx_helper->options['redis_hostname'];
705+
$prefix = defined( 'RT_WP_NGINX_HELPER_REDIS_PREFIX' ) ? RT_WP_NGINX_HELPER_REDIS_PREFIX : $rt_wp_nginx_helper->options['redis_prefix'];
706+
704707
$_url_purge_base = $prefix . $parse['scheme'] . 'GET' . $parse['host'];
705-
708+
706709
$purge_urls = isset( $rt_wp_nginx_helper->options['purge_url'] ) && ! empty( $rt_wp_nginx_helper->options['purge_url'] ) ?
707710
explode( "\r\n", $rt_wp_nginx_helper->options['purge_url'] ) : array();
708-
709-
// Allow plugins/themes to modify/extend urls. Pass urls array in first parameter, second says if wildcards are allowed
710-
$purge_urls = apply_filters('rt_nginx_helper_purge_urls', $purge_urls, true);
711-
712-
if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
711+
712+
// Allow plugins/themes to modify/extend urls. Pass urls array in first parameter, second says if wildcards are allowed
713+
$purge_urls = apply_filters('rt_nginx_helper_purge_urls', $purge_urls, true);
714+
715+
if( is_array( $purge_urls ) && ! empty( $purge_urls ) ) {
713716
foreach ($purge_urls as $purge_url ) {
714717
$purge_url = trim( $purge_url );
715-
718+
716719
if( strpos( $purge_url, '*' ) === false ) {
717720
$purge_url = $_url_purge_base . $purge_url;
718721
$status = delete_single_key( $purge_url );
719722
if( $status ) {
720-
$this->log( "- Purge URL | " . $purge_url );
723+
$this->log( "- Purge URL | " . $purge_url );
721724
} else {
722-
$this->log( "- Not Found | " . $purge_url, 'ERROR' );
725+
$this->log( "- Not Found | " . $purge_url, 'ERROR' );
723726
}
724727
} else {
725728
$purge_url = $_url_purge_base . $purge_url;
726729
$status = delete_keys_by_wildcard( $purge_url );
727730
if( $status ) {
728-
$this->log( "- Purge Wild Card URL | " . $purge_url . " | ". $status . " url purged" );
731+
$this->log( "- Purge Wild Card URL | " . $purge_url . " | ". $status . " url purged" );
729732
} else {
730-
$this->log( "- Not Found | " . $purge_url, 'ERROR' );
733+
$this->log( "- Not Found | " . $purge_url, 'ERROR' );
731734
}
732735
}
733736
}
734737
}
735738
}
736-
739+
737740
}
738741
}

0 commit comments

Comments
 (0)