Skip to content

Commit

Permalink
Merge pull request #175 from Automattic/169_do_not_delete_so_much
Browse files Browse the repository at this point in the history
No need to delete the "page_on_front" as it's already done. It was causing every cached page to be deleted.

Fixed #169 and #98
  • Loading branch information
donnchawp authored Feb 2, 2017
2 parents bc1a73d + eadec4e commit f55dcb5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 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 All @@ -1206,7 +1209,6 @@ function wp_cache_post_change( $post_id ) {
if( $all == true && get_option( 'show_on_front' ) == 'page' ) {
wp_cache_debug( "Post change: deleting page_on_front and page_for_posts pages.", 4 );
wp_cache_debug( "Post change: page_on_front " . get_option( 'page_on_front' ), 4 );
wp_cache_post_id_gc( $siteurl, get_option( 'page_on_front' ), 'single' );
$permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) );
$files_to_check = get_all_supercache_filenames( $dir . $permalink );
foreach( $files_to_check as $cache_file ) {
Expand Down

0 comments on commit f55dcb5

Please sign in to comment.