flush_post( $post_id ); } /** * Post changed action * * @link https://developer.wordpress.org/reference/hooks/save_post/ * @link https://developer.wordpress.org/reference/hooks/pre_trash_post/ * @link https://developer.wordpress.org/reference/hooks/before_delete_post/ * * @param int|bool $post_id Post ID or a boolean if running on the "pre_trash_post" hook filter. * @param WP_Post $post Post. * * @return int|bool|null */ public function on_post_change( $post_id, $post = null ) { if ( is_null( $post ) ) { $post = get_post( $post_id ); } $config = Dispatcher::config(); $cacheflush = Dispatcher::component( 'CacheFlush' ); // If the post is an attachment, we need to get and flush its parent post. if ( isset( $post->post_type ) && 'attachment' === $post->post_type && Util_Environment::is_flushable_post( get_post( $post->post_parent ), 'posts', $config ) ) { $cacheflush->flush_post( $post->post_parent ); } // Check if the original post is flushable. if ( Util_Environment::is_flushable_post( $post, 'posts', $config ) ) { $cacheflush->flush_post( $post_id ); } return $post_id; } /** * Comment change action. * * @param integer $comment_id Comment ID. */ public function on_comment_change( $comment_id ) { $post_id = 0; if ( $comment_id ) { $comment = get_comment( $comment_id, ARRAY_A ); $post_id = ( ! empty( $comment['comment_post_ID'] ) ? (int) $comment['comment_post_ID'] : 0 ); } $this->on_post_change( $post_id ); } /** * Comment status action fired immediately after transitioning a comment’s status from one to another * in the database and removing the comment, but prior to all status transition hooks. * * @link https://developer.wordpress.org/reference/functions/wp_set_comment_status/ * * @param integer $comment_id Comment ID. * @param string $status Status. */ public function on_comment_status( $comment_id, $status ) { $this->on_comment_change( $comment_id ); } /** * Callback: Flush posts after a multisite blog is updated. * * @since 2.7.6 * * @link https://developer.wordpress.org/reference/hooks/wp_update_site/ * @param \WP_Site $new_site New site object. * @param \WP_Site $old_site Old site object. */ public function on_update_site( \WP_Site $new_site, \WP_Site $old_site ) { if ( $new_site->domain !== $old_site->domain || $new_site->path !== $old_site->path || $new_site->public !== $old_site->public || $new_site->archived !== $old_site->archived || $new_site->lang_id !== $old_site->lang_id ) { w3tc_flush_posts(); } } }