The engines that were asked to purge. */ public static function purge_post( int $post_id ): array { $done = array(); $url = (string) get_permalink( $post_id ); self::attempt( $done, 'litespeed', defined( 'LSCWP_V' ), static function () use ( $post_id ): void { do_action( 'litespeed_purge_post', $post_id ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache's own purge hook. } ); self::attempt( $done, 'wp_rocket', function_exists( 'rocket_clean_post' ), static function () use ( $post_id ): void { rocket_clean_post( $post_id ); } ); self::attempt( $done, 'w3_total_cache', function_exists( 'w3tc_flush_post' ), static function () use ( $post_id ): void { w3tc_flush_post( $post_id ); } ); self::attempt( $done, 'wp_super_cache', function_exists( 'wp_cache_post_change' ), static function () use ( $post_id ): void { wp_cache_post_change( $post_id ); } ); self::attempt( $done, 'sg_optimizer', function_exists( 'sg_cachepress_purge_cache' ) && '' !== $url, static function () use ( $url ): void { sg_cachepress_purge_cache( $url ); } ); self::attempt( $done, 'wp_fastest_cache', class_exists( 'WpFastestCache' ), static function () use ( $post_id ): void { do_action( 'wpfc_clear_post_cache_by_id', false, $post_id ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WP Fastest Cache's own purge hook. } ); /** * Fires after GripMCP changed a post in a way cache plugins cannot * see, so a host or a cache plugin not covered here can purge it. * * @param int $post_id Post id. */ do_action( 'gripmcp/purge_post', $post_id ); return $done; } /** * Purge every cached page. Only for changes that reach across the site, * such as a live search and replace: a full purge makes every visitor's * next request rebuild a page. * * @return array The engines that were asked to purge. */ public static function purge_all(): array { $done = array(); self::attempt( $done, 'litespeed', defined( 'LSCWP_V' ), static function (): void { do_action( 'litespeed_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- LiteSpeed Cache's own purge hook. } ); self::attempt( $done, 'wp_rocket', function_exists( 'rocket_clean_domain' ), static function (): void { rocket_clean_domain(); } ); self::attempt( $done, 'w3_total_cache', function_exists( 'w3tc_flush_all' ), static function (): void { w3tc_flush_all(); } ); self::attempt( $done, 'wp_super_cache', function_exists( 'wp_cache_clear_cache' ), static function (): void { wp_cache_clear_cache(); } ); self::attempt( $done, 'sg_optimizer', function_exists( 'sg_cachepress_purge_cache' ), static function (): void { sg_cachepress_purge_cache(); } ); self::attempt( $done, 'wp_fastest_cache', class_exists( 'WpFastestCache' ), static function (): void { do_action( 'wpfc_clear_all_cache' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WP Fastest Cache's own purge hook. } ); self::attempt( $done, 'breeze', defined( 'BREEZE_VERSION' ), static function (): void { do_action( 'breeze_clear_all_cache' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Breeze's own purge hook. } ); self::attempt( $done, 'wp_optimize', class_exists( 'WPO_Page_Cache' ) && method_exists( 'WPO_Page_Cache', 'instance' ), static function (): void { $cache = \WPO_Page_Cache::instance(); if ( is_object( $cache ) && method_exists( $cache, 'purge' ) ) { $cache->purge(); } } ); self::attempt( $done, 'nginx_helper', defined( 'NGINX_HELPER_BASENAME' ), static function (): void { do_action( 'rt_nginx_helper_purge_all' ); // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Nginx Helper's own purge hook. } ); /** * Fires after GripMCP made a site-wide change cache plugins cannot * see, so a host or a cache plugin not covered here can purge. */ do_action( 'gripmcp/purge_all' ); return $done; } /** * Run one engine's purge if it is present, recording it by name. * * @param array $done Engines purged so far, by reference. * @param string $name Engine name for the report. * @param bool $present Whether the engine is loaded. * @param callable $purge The purge call. */ private static function attempt( array &$done, string $name, bool $present, callable $purge ): void { if ( ! $present ) { return; } try { $purge(); $done[] = $name; } catch ( \Throwable $e ) { // A stale page fixes itself when the cache expires; one engine's // failure must not stop the others or fail the caller's edit. unset( $e ); } } }