Skip to content

Commit e3f828d

Browse files
authored
Merge pull request #2 from gridpane/release-homepage-purge-excludes-constant
excludes constant
2 parents 8deccfb + a6aa9e0 commit e3f828d

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

admin/class-nginx-helper-admin.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ public function nginx_helper_default_settings() {
291291
'redis_database_set_by_constant' => 0,
292292
'redis_username_set_by_constant' => 0,
293293
'redis_password_socket_set_by_constant' => 0,
294+
'homepage_purge_post_type_exceptions' => array(),
294295
);
295296

296297
}
@@ -316,14 +317,18 @@ public function nginx_helper_settings() {
316317
$this->nginx_helper_default_settings()
317318
);
318319

320+
if ( defined( 'RT_WP_NGINX_HELPER_HOMEPAGE_PURGE_EXCEPTIONS' ) ) {
321+
$data['homepage_purge_post_type_exceptions'] = RT_WP_NGINX_HELPER_HOMEPAGE_PURGE_EXCEPTIONS;
322+
}
323+
319324
if ( defined( 'RT_WP_NGINX_HELPER_PURGE_METHOD' ) ) {
320-
$data['purge_method'] = RT_WP_NGINX_HELPER_PURGE_METHOD;
321-
$data['purge_method_set_by_constant'] = 1;
325+
$data['purge_method'] = RT_WP_NGINX_HELPER_PURGE_METHOD;
326+
$data['purge_method_set_by_constant'] = 1;
322327
}
323328

324329
if ( defined( 'RT_WP_NGINX_HELPER_CACHE_METHOD' ) ) {
325-
$data['cache_method'] = RT_WP_NGINX_HELPER_CACHE_METHOD;
326-
$data['cache_method_set_by_constant'] = 1;
330+
$data['cache_method'] = RT_WP_NGINX_HELPER_CACHE_METHOD;
331+
$data['cache_method_set_by_constant'] = 1;
327332

328333
if ( 'enable_fastcgi' === RT_WP_NGINX_HELPER_CACHE_METHOD ) {
329334
$data['enable_purge'] = 1;

admin/class-purger.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ public function purge_post( $post_id ) {
147147
return;
148148
}
149149

150+
$_post_type = get_post_type( $post_id );
151+
150152
switch ( current_filter() ) {
151153

152154
case 'publish_post':
@@ -170,7 +172,6 @@ public function purge_post( $post_id ) {
170172
break;
171173

172174
default:
173-
$_post_type = get_post_type( $post_id );
174175
$this->log( '* * * * *' );
175176
$this->log( '* Blog :: ' . addslashes( get_bloginfo( 'name' ) ) . ' ( ' . $blog_id . ' ).' );
176177
$this->log( "* Custom post type '" . $_post_type . "' :: " . get_the_title( $post_id ) . ' ( ' . $post_id . ' ).' );
@@ -182,8 +183,22 @@ public function purge_post( $post_id ) {
182183

183184
$this->log( 'Function purge_post BEGIN ===' );
184185

186+
# Here we need something more granular
187+
# to allow a post type to trigger its purge
188+
# but skip the homepage purge
189+
# can use array, if found, skip purge homepage
190+
# [ 'post_type1', 'post_type1' ]
191+
# we can also do exceptions by post/page slug too
192+
185193
if ( 1 === (int) $nginx_helper_admin->options['purge_homepage_on_edit'] ) {
186-
$this->_purge_homepage();
194+
if ( ! in_array( $_post_type, $nginx_helper_admin->options['homepage_purge_post_type_exceptions'], true ) ) {
195+
$this->_purge_homepage();
196+
} else {
197+
$this->log('* * * * *');
198+
$this->log('* Post Type update - ' . $_post_type . ' - homepage purge trigger excluded...');
199+
$this->log('* ' . $_post_type . ' in constant array: RT_WP_NGINX_HELPER_HOMEPAGE_PURGE_EXCEPTIONS');
200+
$this->log('* * * * *');
201+
}
187202
}
188203

189204
if ( 'comment_post' === current_filter() || 'wp_set_comment_status' === current_filter() ) {

0 commit comments

Comments
 (0)