wp_cache_post_change() │ WPSCache 1.0
Hooks from the function
Return
null
. Nothing (null).
Usage
wp_cache_post_change( $post_id );
- $post_id (required)
- -
wp_cache_post_change() wp cache post change code WPSCache 1.12.4
function wp_cache_post_change( $post_id ) { global $file_prefix, $cache_path, $blog_id, $super_cache_enabled, $blog_cache_dir, $wp_cache_refresh_single_only; static $last_processed = -1; if ( $post_id == $last_processed ) { $action = current_filter(); wp_cache_debug( "wp_cache_post_change({$action}): Already processed post $post_id.", 4 ); return $post_id; } $post = get_post( $post_id ); $ptype = is_object( $post ) ? get_post_type_object( $post->post_type ) : null; if ( empty( $ptype ) || ! $ptype->public ) { return $post_id; } // Allow plugins to reject cache clears for specific posts. if ( ! apply_filters( 'wp_super_cache_clear_post_cache', true, $post ) ) { return $post_id; } // Some users are inexplicibly seeing this error on scheduled posts. // define this constant to disable the post status check. if ( ! defined( 'WPSCFORCEUPDATE' ) && ! in_array( get_post_status( $post ), array( 'publish', 'private' ), true ) ) { wp_cache_debug( 'wp_cache_post_change: draft post, not deleting any cache files.', 4 ); return $post_id; } $last_processed = $post_id; if ( ! wp_cache_writers_entry() ) { return $post_id; } if ( isset( $wp_cache_refresh_single_only ) && $wp_cache_refresh_single_only && ( isset( $_SERVER['HTTP_REFERER'] ) && strpos( $_SERVER['HTTP_REFERER'], 'edit-comments.php' ) || strpos( $_SERVER['REQUEST_URI'], 'wp-comments-post.php' ) ) ) { if ( defined( 'DONOTDELETECACHE' ) ) { wp_cache_debug( "wp_cache_post_change: comment detected and it's moderated or spam. Not deleting cached files.", 4 ); return $post_id; } else { wp_cache_debug( 'wp_cache_post_change: comment detected. only deleting post page.', 4 ); $all = false; } } else { $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 ) ); } // Delete supercache files whenever a post change event occurs, even if supercache is currently disabled. $dir = get_supercache_dir(); // make sure the front page has a rebuild file if ( false == wp_cache_post_id_gc( $post_id, $all ) ) { wp_cache_debug( 'wp_cache_post_change: not deleting any cache files as GC of post returned false' ); wp_cache_writers_exit(); return false; } if ( $all == true ) { wp_cache_debug( 'Post change: supercache enabled: deleting cache files in ' . $dir ); wpsc_rebuild_files( $dir ); do_action( 'gc_cache', 'prune', 'homepage' ); if ( 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 ); /** * It's possible that page_for_posts is zero. * Quick fix to reduce issues in debugging. */ wp_cache_debug( 'Post change: page_for_posts ' . get_option( 'page_for_posts' ), 4 ); if ( get_option( 'page_for_posts' ) ) { $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( get_option( 'page_for_posts' ) ) ) ); wp_cache_debug( 'Post change: Deleting files in: ' . str_replace( '//', '/', $dir . $permalink ) ); wpsc_rebuild_files( $dir . $permalink ); do_action( 'gc_cache', 'prune', $permalink ); } } } else { wp_cache_debug( 'wp_cache_post_change: not deleting all pages.', 4 ); } wp_cache_debug( "wp_cache_post_change: checking {$blog_cache_dir}meta/", 4 ); $supercache_files_deleted = false; if ( $handle = @opendir( $blog_cache_dir ) ) { while ( false !== ( $file = readdir( $handle ) ) ) { if ( str_contains( $file, $file_prefix ) ) { if ( strpos( $file, '.html' ) ) { // delete old wpcache files immediately wp_cache_debug( "wp_cache_post_change: Deleting obsolete wpcache cache+meta files: $file" ); @unlink( $blog_cache_dir . $file ); @unlink( $blog_cache_dir . 'meta/' . str_replace( '.html', '.meta', $file ) ); continue; } else { $meta = json_decode( wp_cache_get_legacy_cache( $blog_cache_dir . 'meta/' . $file ), true ); if ( false == is_array( $meta ) ) { wp_cache_debug( "Post change cleaning up stray file: $file", 4 ); @unlink( $blog_cache_dir . 'meta/' . $file ); @unlink( $blog_cache_dir . $file ); continue; } if ( $post_id > 0 && $meta ) { $permalink = trailingslashit( str_replace( get_option( 'home' ), '', get_permalink( $post_id ) ) ); if ( $meta['blog_id'] == $blog_id && ( ( $all == true && ! $meta['post'] ) || $meta['post'] == $post_id ) ) { wp_cache_debug( "Post change: deleting post wp-cache files for {$meta[ 'uri' ]}: $file", 4 ); @unlink( $blog_cache_dir . 'meta/' . $file ); @unlink( $blog_cache_dir . $file ); if ( false == $supercache_files_deleted && $super_cache_enabled == true ) { wp_cache_debug( "Post change: deleting supercache files for {$permalink}" ); wpsc_rebuild_files( $dir . $permalink ); $supercache_files_deleted = true; do_action( 'gc_cache', 'rebuild', $permalink ); } } } elseif ( $meta['blog_id'] == $blog_id ) { wp_cache_debug( "Post change: deleting wp-cache files for {$meta[ 'uri' ]}: $file", 4 ); @unlink( $blog_cache_dir . 'meta/' . $file ); @unlink( $blog_cache_dir . $file ); if ( $super_cache_enabled == true ) { wp_cache_debug( "Post change: deleting supercache files for {$meta[ 'uri' ]}" ); wpsc_rebuild_files( $dir . $meta['uri'] ); do_action( 'gc_cache', 'rebuild', trailingslashit( $meta['uri'] ) ); } } } } } closedir( $handle ); } wp_cache_writers_exit(); return $post_id; }