name, rest (bool). */ public static function state() { $caches = array(); if ( defined( 'LSCWP_V' ) || class_exists( '\LiteSpeed\Core' ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- hook of LiteSpeed Cache. $rest = (bool) apply_filters( 'litespeed_conf', 'cache-rest' ); $caches['litespeed'] = array( 'name' => 'LiteSpeed Cache', 'rest' => $rest ); } if ( class_exists( '\WP_Rest_Cache_Plugin\Includes\Caching\Caching' ) ) { $caches['wp-rest-cache'] = array( 'name' => 'WP REST Cache', 'rest' => true ); } if ( class_exists( '\W3TC\Dispatcher' ) ) { $rest = false; try { $rest = 'cache' === \W3TC\Dispatcher::config()->get_string( 'pgcache.rest' ); } catch ( Exception $e ) { $rest = false; } $caches['w3-total-cache'] = array( 'name' => 'W3 Total Cache', 'rest' => $rest ); } $rest_cached = false; foreach ( $caches as $cache ) { $rest_cached = $rest_cached || $cache['rest']; } return array( 'rest_cached' => $rest_cached, 'caches' => $caches, ); } /** * Empty every cache that may still hold REST responses from before a rule change. * * @return void */ public static function purge() { $state = self::state(); if ( ! empty( $state['caches']['litespeed']['rest'] ) ) { // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- hook of LiteSpeed Cache. do_action( 'litespeed_purge_all', '3task Doorman rules changed' ); } if ( ! empty( $state['caches']['wp-rest-cache'] ) ) { \WP_Rest_Cache_Plugin\Includes\Caching\Caching::get_instance()->clear_caches( true ); } if ( ! empty( $state['caches']['w3-total-cache']['rest'] ) && function_exists( 'w3tc_flush_all' ) ) { w3tc_flush_all(); } } }