Ejemplo n.º 1
0
 public static function ajax_saveCacheConfig_callback()
 {
     $cacheType = $_POST['cacheType'];
     if ($cacheType == 'falcon' || $cacheType == 'php') {
         $plugins = get_plugins();
         $badPlugins = array();
         foreach ($plugins as $pluginFile => $data) {
             if (is_plugin_active($pluginFile)) {
                 if ($pluginFile == 'w3-total-cache/w3-total-cache.php') {
                     $badPlugins[] = "W3 Total Cache";
                 } else {
                     if ($pluginFile == 'quick-cache/quick-cache.php') {
                         $badPlugins[] = "Quick Cache";
                     } else {
                         if ($pluginFile == "wp-super-cache/wp-cache.php") {
                             $badPlugins[] = "WP Super Cache";
                         } else {
                             if ($pluginFile == "wp-fast-cache/wp-fast-cache.php") {
                                 $badPlugins[] = "WP Fast Cache";
                             } else {
                                 if ($pluginFile == "wp-fastest-cache/wpFastestCache.php") {
                                     $badPlugins[] = "WP Fastest Cache";
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (count($badPlugins) > 0) {
             return array('errorMsg' => "You can not enable caching in Wordfence with other caching plugins enabled. This may cause conflicts. You need to disable other caching plugins first. Wordfence caching is very fast and does not require other caching plugins to be active. The plugins you have that conflict are: " . implode(', ', $badPlugins) . ". Disable these plugins, then return to this page and enable Wordfence caching.");
         }
         $siteURL = site_url();
         if (preg_match('/^https?:\\/\\/[^\\/]+\\/[^\\/]+\\/[^\\/]+\\/.+/i', $siteURL)) {
             return array('errorMsg' => "Wordfence caching currently does not support sites that are installed in a subdirectory and have a home page that is more than 2 directory levels deep. e.g. we don't support sites who's home page is http://example.com/levelOne/levelTwo/levelThree");
         }
     }
     if ($cacheType == 'falcon') {
         if (!get_option('permalink_structure', '')) {
             return array('errorMsg' => "You need to enable Permalinks for your site to use Falcon Engine. You can enable Permalinks in WordPress by going to the Settings - Permalinks menu and enabling it there. Permalinks change your site URL structure from something that looks like /p=123 to pretty URLs like /my-new-post-today/ that are generally more search engine friendly.");
         }
     }
     $warnHtaccess = false;
     if ($cacheType == 'disable' || $cacheType == 'php') {
         $removeError = wfCache::addHtaccessCode('remove');
         $removeError2 = wfCache::updateBlockedIPs('remove');
         if ($removeError || $removeError2) {
             $warnHtaccess = true;
         }
     }
     if ($cacheType == 'php' || $cacheType == 'falcon') {
         $err = wfCache::cacheDirectoryTest();
         if ($err) {
             return array('ok' => 1, 'heading' => "Could not write to cache directory", 'body' => "To enable caching, Wordfence needs to be able to create and write to the /wp-content/wfcache/ directory. We did some tests that indicate this is not possible. You need to manually create the /wp-content/wfcache/ directory and make it writable by Wordfence. The error we encountered was during our tests was: {$err}");
         }
     }
     //Mainly we clear the cache here so that any footer cache diagnostic comments are rebuilt. We could just leave it intact unless caching is being disabled.
     if ($cacheType != wfConfig::get('cacheType', false)) {
         wfCache::scheduleCacheClear();
     }
     $htMsg = "";
     if ($warnHtaccess) {
         $htMsg = " <strong style='color: #F00;'>Warning: We could not remove the caching code from your .htaccess file. you need to remove this manually yourself.</strong> ";
     }
     if ($cacheType == 'disable') {
         wfConfig::set('cacheType', false);
         return array('ok' => 1, 'heading' => "Caching successfully disabled.", 'body' => "{$htMsg}Caching has been disabled on your system.<br /><br /><center><input type='button' name='wfReload' value='Click here now to refresh this page' onclick='window.location.reload(true);' /></center>");
     } else {
         if ($cacheType == 'php') {
             wfConfig::set('cacheType', 'php');
             return array('ok' => 1, 'heading' => "Wordfence Basic Caching Enabled", 'body' => "{$htMsg}Wordfence basic caching has been enabled on your system.<br /><br /><center><input type='button' name='wfReload' value='Click here now to refresh this page' onclick='window.location.reload(true);' /></center>");
         } else {
             if ($cacheType == 'falcon') {
                 if ($_POST['noEditHtaccess'] != '1') {
                     $err = wfCache::addHtaccessCode('add');
                     if ($err) {
                         return array('ok' => 1, 'heading' => "Wordfence could not edit .htaccess", 'body' => "Wordfence could not edit your .htaccess code. The error was: " . $err);
                     }
                 }
                 wfConfig::set('cacheType', 'falcon');
                 wfCache::scheduleUpdateBlockedIPs();
                 //Runs every 5 mins until we change cachetype
                 return array('ok' => 1, 'heading' => "Wordfence Falcon Engine Activated!", 'body' => "Wordfence Falcon Engine has been activated on your system. You will see this icon appear on the Wordfence admin pages as long as Falcon is active indicating your site is running in high performance mode:<div class='wfFalconImage'></div><center><input type='button' name='wfReload' value='Click here now to refresh this page' onclick='window.location.reload(true);' /></center>");
             }
         }
     }
     return array('errorMsg' => "An error occurred.");
 }