Skip to content

Commit

Permalink
Added "wpsc_delete_related_pages_on_edit" filter to avoid cache deletes
Browse files Browse the repository at this point in the history
If the wpsc_delete_related_pages_on_edit filer returns 0 then only the
cache for the current post will be deleted. Otherwise the plugin will
delete the front page and paged archives of comments.

See #169
  • Loading branch information
donnchawp committed Feb 2, 2017
1 parent 98b5362 commit eadec4e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions wp-cache-phase2.php
Original file line number Diff line number Diff line change
Expand Up @@ -1133,21 +1133,19 @@ function wp_cache_post_id_gc( $siteurl, $post_id, $all = 'all' ) {
$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) );
$dir = get_current_url_supercache_dir( $post_id );
wp_cache_debug( "wp_cache_post_id_gc post_id: $post_id " . get_permalink( $post_id ) . " clearing cache in $dir.", 4 );
if ( $all == 'all' ) {
if ( $all ) {
prune_super_cache( $dir, true, true );
do_action( 'gc_cache', 'prune', $permalink );
@rmdir( $dir );
wp_cache_debug( "wp_cache_post_id_gc clearing cache in {$supercache_home}page/." );
$supercache_home = get_supercache_dir();
prune_super_cache( $supercache_home . 'page/', true );
do_action( 'gc_cache', 'prune', 'page/' );
} else {
wp_cache_debug( "wp_cache_post_id_gc clearing cached index files in $dir.", 4 );
prune_super_cache( $dir, true, true );
do_action( 'gc_cache', 'prune', $permalink );
}
wp_cache_debug( "wp_cache_post_id_gc clearing cache in {$dir}/page/.", 4 );
prune_super_cache( $dir . '/page/', true );
$supercache_home = get_supercache_dir();
wp_cache_debug( "wp_cache_post_id_gc clearing cache in {$supercache_home}/page/.", 4 );
prune_super_cache( $supercache_home . '/page/', true );
do_action( 'gc_cache', 'prune', '/page/' );
}

function wp_cache_post_change( $post_id ) {
Expand Down Expand Up @@ -1182,6 +1180,11 @@ function wp_cache_post_change( $post_id ) {
$all = true;
}

$all_backup = $all;
$all = apply_filters( 'wpsc_delete_related_pages_on_edit', $all ); // return 0 to disable deleting homepage and other pages.
if ( $all != $all_backup )
wp_cache_debug( 'wp_cache_post_change: $all changed by wpsc_delete_related_pages_on_edit filter: ' . intval( $all ) );

if ( $wp_cache_object_cache )
reset_oc_version();

Expand All @@ -1191,7 +1194,7 @@ function wp_cache_post_change( $post_id ) {
$dir = get_supercache_dir();
$siteurl = trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'https://', '', str_replace( 'http://', '', get_option( 'home' ) ) ) ) ) );
// make sure the front page has a rebuild file
wp_cache_post_id_gc( $siteurl, $post_id );
wp_cache_post_id_gc( $siteurl, $post_id, $all );
if ( $all == true ) {
wp_cache_debug( "Post change: supercache enabled: deleting cache files in " . $cache_path . 'supercache/' . $siteurl, 4 );
$files_to_check = get_all_supercache_filenames( $dir );
Expand Down

0 comments on commit eadec4e

Please sign in to comment.