flush_post( $post_id ); } /** * Post changed action * * @link https://developer.wordpress.org/reference/hooks/save_post/ * * @param integer $post_id Post ID. * @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 ); } // if attachment changed - parent post has to be flushed // since there are usually attachments content like title // on the page (gallery). if ( isset( $post->post_type ) && 'attachment' === $post->post_type ) { $post_id = $post->post_parent; $post = get_post( $post_id ); } if ( ! Util_Environment::is_flushable_post( $post, 'posts', Dispatcher::config() ) ) { return $post_id; } $cacheflush = Dispatcher::component( 'CacheFlush' ); $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 ); } /** * Change action */ public function on_change() { $cacheflush = Dispatcher::component( 'CacheFlush' ); $cacheflush->flush_posts(); } }