Beispiel #1
0
 public static function setupCaching()
 {
     self::$cacheType = wfConfig::get('cacheType');
     if (self::$cacheType != 'php' && self::$cacheType != 'falcon') {
         return;
         //cache is disabled
     }
     if (wfUtils::hasLoginCookie()) {
         add_action('publish_post', 'wfCache::action_publishPost');
         add_action('publish_page', 'wfCache::action_publishPost');
         foreach (array('clean_object_term_cache', 'clean_post_cache', 'clean_term_cache', 'clean_page_cache', 'after_switch_theme', 'customize_save_after', 'activated_plugin', 'deactivated_plugin', 'update_option_sidebars_widgets') as $action) {
             add_action($action, 'wfCache::action_clearPageCache');
             //Schedules a cache clear for immediately so it won't lag current request.
         }
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             foreach (array('/\\/wp\\-admin\\/options\\.php$/', '/\\/wp\\-admin\\/options\\-permalink\\.php$/') as $pattern) {
                 if (preg_match($pattern, $_SERVER['REQUEST_URI'])) {
                     self::scheduleCacheClear();
                     break;
                 }
             }
         }
     }
     add_action('wordfence_cache_clear', 'wfCache::scheduledCacheClear');
     add_action('wordfence_update_blocked_IPs', 'wfCache::scheduleUpdateBlockedIPs');
     add_action('comment_post', 'wfCache::action_commentPost');
     //Might not be logged in
     add_filter('wp_redirect', 'wfCache::redirectFilter');
     //Routines to clear cache run even if cache is disabled
     $file = self::fileFromRequest($_SERVER['HTTP_HOST'] ? $_SERVER['HTTP_HOST'] : $_SERVER['SERVER_NAME'], $_SERVER['REQUEST_URI']);
     $fileDeleted = false;
     $doDelete = false;
     if ($_SERVER['REQUEST_METHOD'] != 'GET') {
         //If our URL is hit with a POST, PUT, DELETE or any other non 'GET' request, then clear cache.
         $doDelete = true;
     }
     if ($doDelete) {
         @unlink($file);
         $fileDeleted = true;
     }
     add_action('wp_logout', 'wfCache::logout');
     if (self::isCachable()) {
         if (!$fileDeleted && self::$cacheType == 'php') {
             //Then serve the file if it's still valid
             $stat = @stat($file);
             if ($stat) {
                 $age = time() - $stat[9];
                 if ($age < 10000) {
                     readfile($file);
                     //sends file to stdout
                     die;
                 }
             }
         }
         ob_start('wfCache::obComplete');
         //Setup routine to store the file
     }
 }