post_status && ! wp_is_post_revision( $post_id ) ) { $this->pending = true; } } /** * Schedules a purge. */ public function schedule_always() { $this->pending = true; } /** * Schedules a purge when a template is published or unpublished. * * @param string $new_status New status. * @param string $old_status Old status. * @param \WP_Post $post Post. */ public function on_status( $new_status, $old_status, $post ) { if ( Post_Type::POST_TYPE === $post->post_type && $new_status !== $old_status && ( 'publish' === $new_status || 'publish' === $old_status ) ) { $this->pending = true; } } /** * Schedules a purge after an Elementor save of a template. * * @param \Elementor\Core\Base\Document $document Document. */ public function on_elementor_save( $document ) { if ( $document instanceof Elementor\Documents\Theme_Document && 'publish' === get_post_status( $document->get_main_id() ) ) { $this->pending = true; } } /** * Purges once at the end of the request. */ public function maybe_purge() { if ( $this->pending ) { self::purge_all(); } } /** * Clears the cache of popular caching plugins and hosts. */ public static function purge_all() { // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Hooks of caching plugins. 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 ( class_exists( 'WpFastestCache' ) && method_exists( 'WpFastestCache', 'deleteCache' ) ) { $wpfc = new \WpFastestCache(); $wpfc->deleteCache( true ); } if ( function_exists( 'sg_cachepress_purge_cache' ) ) { sg_cachepress_purge_cache(); } if ( class_exists( 'WPO_Page_Cache' ) && method_exists( 'WPO_Page_Cache', 'instance' ) ) { \WPO_Page_Cache::instance()->purge(); } if ( class_exists( 'autoptimizeCache' ) && method_exists( 'autoptimizeCache', 'clearall' ) ) { \autoptimizeCache::clearall(); } do_action( 'litespeed_purge_all' ); do_action( 'breeze_clear_all_cache' ); do_action( 'rt_nginx_helper_purge_all' ); do_action( 'cachify_flush_cache' ); if ( class_exists( 'WpeCommon' ) ) { if ( method_exists( 'WpeCommon', 'purge_memcached' ) ) { \WpeCommon::purge_memcached(); } if ( method_exists( 'WpeCommon', 'purge_varnish_cache' ) ) { \WpeCommon::purge_varnish_cache(); } } // phpcs:enable /** * Fires after Buildify cleared page caches. Use it to clear a custom cache or CDN. */ do_action( 'buildify_purge_cache' ); } }