post_type, self::SITE_WIDE_TYPES, true ) ) { self::purge_pages(); return; } if ( ! is_post_type_viewable( $post->post_type ) ) { return; } if ( 'publish' !== $new_status && 'publish' !== $old_status ) { return; } if ( $new_status !== $old_status ) { self::purge_pages(); return; } self::purge_post( $post ); } /** * A post was deleted. * * @param int $post_id Post ID. */ public static function post_id_changed( $post_id ) { $post = get_post( $post_id ); if ( $post && 'publish' === $post->post_status ) { self::purge_pages(); } } /** * A comment changed. * * @param int $comment_id Comment ID. */ public static function comment_changed( $comment_id ) { $comment = get_comment( $comment_id ); if ( $comment && $comment->comment_post_ID ) { AIOM_Page_Cache::purge_url( (string) get_permalink( (int) $comment->comment_post_ID ) ); } } /** * A comment was approved, unapproved, spammed or trashed. * * @param string $new_status New status. * @param string $old_status Old status. * @param WP_Comment $comment Comment. */ public static function comment_status( $new_status, $old_status, $comment ) { if ( $comment instanceof WP_Comment && $new_status !== $old_status ) { self::comment_changed( (int) $comment->comment_ID ); } } /** * Stock changed. * * @param object|int $product Product. */ public static function product_changed( $product ) { $id = is_object( $product ) && method_exists( $product, 'get_id' ) ? $product->get_id() : (int) $product; $post = get_post( $id ); if ( $post ) { self::purge_post( $post ); } } /** * Purge a post and the listings that show it. * * @param WP_Post $post Post. */ public static function purge_post( WP_Post $post ) { if ( self::$purged_all ) { return; } $urls = array( get_permalink( $post ), home_url( '/' ) ); if ( get_option( 'page_for_posts' ) ) { $urls[] = get_permalink( (int) get_option( 'page_for_posts' ) ); } $archive = get_post_type_archive_link( $post->post_type ); if ( $archive ) { $urls[] = $archive; } $urls[] = get_author_posts_url( (int) $post->post_author ); foreach ( get_object_taxonomies( $post->post_type ) as $tax ) { $terms = get_the_terms( $post, $tax ); if ( is_array( $terms ) ) { foreach ( $terms as $term ) { $link = get_term_link( $term ); if ( is_string( $link ) ) { $urls[] = $link; } } } } foreach ( array_unique( array_filter( $urls ) ) as $url ) { AIOM_Page_Cache::purge_url( (string) $url ); } } }