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 void */ 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 ( '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; } $cacheflush = Dispatcher::component( 'CacheFlush' ); $cacheflush->flush_post( $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 ); } /** * Change action */ public function on_change() { $cacheflush = Dispatcher::component( 'CacheFlush' ); $cacheflush->flush_posts(); } }