post_type ) { return; } $was_shown = $before instanceof \WP_Post && 'publish' === $before->post_status; if ( 'publish' !== $after->post_status && ! $was_shown ) { return; // A draft that stays a draft. } self::shared_tab( (int) $post_id, false ); } /** * A shared tab scheduled for later went live: WordPress publishes it without the hooks of an update. * * @param \WP_Post $post Post published. */ public static function scheduled( $post ): void { if ( $post instanceof \WP_Post && Library::POST_TYPE === $post->post_type ) { self::shared_tab( (int) $post->ID, false ); } } /** * Pages showing a shared tab: every product when the tab shows on its own, the products it is added to otherwise. * * @param int $id Shared tab. * @param bool $all_pages Purge everything whatever the setting. */ private static function shared_tab( int $id, bool $all_pages ): void { if ( self::$all ) { return; } if ( $all_pages || '' !== (string) get_post_meta( $id, Library::META_SCOPE, true ) ) { self::everything(); return; } if ( isset( self::$shared_tabs[ $id ] ) ) { return; // Already looked up: a save changes the post and its metas. } self::$shared_tabs[ $id ] = true; $ids = Library::products_using( $id, self::MAX_PRODUCTS + 1 ); if ( count( $ids ) > self::MAX_PRODUCTS ) { self::everything(); return; } self::products( $ids ); } /** * Products to purge at the end of the request. * * @param int[] $ids Product ids. */ private static function products( array $ids ): void { foreach ( $ids as $id ) { self::$products[ (int) $id ] = true; } } /** Every page to purge at the end of the request (the WooCommerce tabs of every product changed). */ public static function everything(): void { self::$all = true; } /** End of the request: purges the pages collected. */ public static function flush(): void { $all = self::$all; $products = array_keys( self::$products ); self::$all = false; self::$products = array(); self::$shared_tabs = array(); $ids = array(); if ( ! $all ) { foreach ( $products as $id ) { if ( 'publish' === get_post_status( $id ) ) { $ids[] = $id; } } if ( ! $ids ) { return; } $all = count( $ids ) > self::MAX_PRODUCTS; } if ( $all ) { do_action( 'litespeed_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache hook. if ( function_exists( 'rocket_clean_domain' ) ) { rocket_clean_domain(); } if ( function_exists( 'w3tc_flush_all' ) ) { w3tc_flush_all(); } if ( function_exists( 'wp_cache_clear_cache' ) ) { wp_cache_clear_cache(); } if ( function_exists( 'wpfc_clear_all_cache' ) ) { wpfc_clear_all_cache(); } $ids = array(); } else { foreach ( $ids as $id ) { do_action( 'litespeed_purge_post', $id ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache hook. if ( function_exists( 'rocket_clean_post' ) ) { rocket_clean_post( $id ); } if ( function_exists( 'w3tc_flush_post' ) ) { w3tc_flush_post( $id ); } if ( function_exists( 'wpsc_delete_post_cache' ) ) { wpsc_delete_post_cache( $id ); } if ( function_exists( 'wpfc_clear_post_cache_by_id' ) ) { wpfc_clear_post_cache_by_id( $id ); } } } /** * Product pages whose tabs changed, once the cache plugins ProdTabs knows have been asked to purge them. For a * host cache or another cache plugin. * * @param int[] $ids Product ids; empty when every page is concerned. */ do_action( 'prodtabs_purge_cache', $ids ); } }