function wp_cache_manager_error_checks()
{
    global $wpmu_version, $wp_cache_debug, $wp_cache_cron_check, $cache_enabled, $super_cache_enabled, $wp_cache_config_file, $wp_cache_mobile_browsers, $wp_cache_mobile_prefixes, $wp_cache_mobile_browsers, $wp_cache_mobile_enabled, $wp_cache_mod_rewrite, $cache_path;
    global $dismiss_htaccess_warning, $dismiss_readable_warning, $dismiss_gc_warning, $wp_cache_shutdown_gc;
    if (!wpsupercache_site_admin()) {
        return false;
    }
    if (version_compare(PHP_VERSION, '5.3.0', '<') && (1 == ini_get('safe_mode') || "on" == strtolower(ini_get('safe_mode')))) {
        echo '<div id="message" class="updated fade"><h3>' . __('Warning! PHP Safe Mode Enabled!', 'wp-super-cache') . '</h3><p>' . __('You may experience problems running this plugin because SAFE MODE is enabled.', 'wp-super-cache') . ' ';
        if (!ini_get('safe_mode_gid')) {
            _e('Your server is set up to check the owner of PHP scripts before allowing them to read and write files.', 'wp-super-cache') . " ";
            printf(__('You or an administrator may be able to make it work by changing the group owner of the plugin scripts to match that of the web server user. The group owner of the %s/cache/ directory must also be changed. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details.', 'wp-super-cache'), WP_CONTENT_DIR);
        } else {
            _e('You or an administrator must disable this. See the <a href="http://php.net/features.safe-mode">safe mode manual page</a> for further details. This cannot be disabled in a .htaccess file unfortunately. It must be done in the php.ini config file.', 'wp-super-cache');
        }
        echo '</p></div>';
    }
    if ('' == get_option('permalink_structure')) {
        echo '<div id="message" class="updated fade"><h3>' . __('Permlink Structure Error', 'wp-super-cache') . '</h3>';
        echo "<p>" . __('A custom url or permalink structure is required for this plugin to work correctly. Please go to the <a href="options-permalink.php">Permalinks Options Page</a> to configure your permalinks.') . "</p>";
        echo '</div>';
        return false;
    }
    if ($wp_cache_debug || !$wp_cache_cron_check) {
        if (function_exists("wp_remote_get") == false) {
            $hostname = str_replace('http://', '', str_replace('https://', '', get_option('siteurl')));
            if (strpos($hostname, '/')) {
                $hostname = substr($hostname, 0, strpos($hostname, '/'));
            }
            $ip = gethostbyname($hostname);
            if (substr($ip, 0, 3) == '127' || substr($ip, 0, 7) == '192.168') {
                ?>
<div id="message" class="updated fade"><h3><?php 
                printf(__('Warning! Your hostname "%s" resolves to %s', 'wp-super-cache'), $hostname, $ip);
                ?>
</h3>
					<p><?php 
                printf(__('Your server thinks your hostname resolves to %s. Some services such as garbage collection by this plugin, and WordPress scheduled posts may not operate correctly.', 'wp-super-cache'), $ip);
                ?>
</p>
					<p><?php 
                printf(__('Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache'), 'http://wordpress.org/plugins/wp-super-cache/faq/');
                ?>
</p>
					</div>
					<?php 
                return false;
            } else {
                wp_cache_replace_line('^ *\\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
            }
        } else {
            $cron_url = get_option('siteurl') . '/wp-cron.php?check=' . wp_hash('187425');
            $cron = wp_remote_get($cron_url, array('timeout' => 0.01, 'blocking' => true));
            if (is_array($cron)) {
                if ($cron['response']['code'] == '404') {
                    ?>
<div id="message" class="updated fade"><h3>Warning! wp-cron.php not found!</h3>
					<p><?php 
                    _e('Unfortunately, WordPress cannot find the file wp-cron.php. This script is required for the correct operation of garbage collection by this plugin, WordPress scheduled posts as well as other critical activities.', 'wp-super-cache');
                    ?>
</p>
					<p><?php 
                    printf(__('Please see entry 16 in the <a href="%s">Troubleshooting section</a> of the readme.txt', 'wp-super-cache'), 'http://wordpress.org/plugins/wp-super-cache/faq/');
                    ?>
</p>
					</div>
					<?php 
                } else {
                    wp_cache_replace_line('^ *\\$wp_cache_cron_check', "\$wp_cache_cron_check = 1;", $wp_cache_config_file);
                }
            }
        }
    }
    if (!wp_cache_check_link() || !wp_cache_verify_config_file() || !wp_cache_verify_cache_dir()) {
        echo '<p>' . __("Cannot continue... fix previous problems and retry.", 'wp-super-cache') . '</p>';
        return false;
    }
    if (!wp_cache_check_global_config()) {
        return false;
    }
    if (1 == ini_get('zlib.output_compression') || "on" == strtolower(ini_get('zlib.output_compression'))) {
        ?>
<div id="message" class="updated fade"><h3><?php 
        _e('Zlib Output Compression Enabled!', 'wp-super-cache');
        ?>
</h3>
		<p><?php 
        _e('PHP is compressing the data sent to the visitors of your site. Disabling this is recommended as the plugin caches the compressed output once instead of compressing the same page over and over again. Also see #21 in the Troubleshooting section. See <a href="http://php.net/manual/en/zlib.configuration.php">this page</a> for instructions on modifying your php.ini.', 'wp-super-cache');
        ?>
</p></div><?php 
    }
    if ($cache_enabled == true && $super_cache_enabled == true && $wp_cache_mod_rewrite && !got_mod_rewrite()) {
        ?>
<div id="message" class="updated fade"><h3><?php 
        _e('Mod rewrite may not be installed!', 'wp-super-cache');
        ?>
</h3>
		<p><?php 
        _e('It appears that mod_rewrite is not installed. Sometimes this check isn&#8217;t 100% reliable, especially if you are not using Apache. Please verify that the mod_rewrite module is loaded. It is required for serving Super Cache static files. You will still be able to use legacy or PHP modes.', 'wp-super-cache');
        ?>
</p></div><?php 
    }
    if (!is_writeable_ACLSafe($wp_cache_config_file)) {
        if (!defined('SUBMITDISABLED')) {
            define("SUBMITDISABLED", 'disabled style="color: #aaa" ');
        }
        ?>
<div id="message" class="updated fade"><h3><?php 
        _e('Read Only Mode. Configuration cannot be changed.', 'wp-super-cache');
        ?>
</h3>
		<p><?php 
        printf(__('The WP Super Cache configuration file is <code>%s/wp-cache-config.php</code> and cannot be modified. That file must be writeable by the web server to make any changes.', 'wp-super-cache'), WP_CONTENT_DIR);
        ?>
		<?php 
        _e('A simple way of doing that is by changing the permissions temporarily using the CHMOD command or through your ftp client. Make sure it&#8217;s globally writeable and it should be fine.', 'wp-super-cache');
        ?>
</p>
		<p><?php 
        _e('<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache');
        ?>
</p>
		<?php 
        _e('Writeable:', 'wp-super-cache');
        ?>
 <code>chmod 666 <?php 
        echo WP_CONTENT_DIR;
        ?>
/wp-cache-config.php</code>
		<?php 
        _e('Read-only:', 'wp-super-cache');
        ?>
 <code>chmod 644 <?php 
        echo WP_CONTENT_DIR;
        ?>
/wp-cache-config.php</code></p>
		</div><?php 
    } elseif (!defined('SUBMITDISABLED')) {
        define("SUBMITDISABLED", ' ');
    }
    $valid_nonce = isset($_REQUEST['_wpnonce']) ? wp_verify_nonce($_REQUEST['_wpnonce'], 'wp-cache') : false;
    // Check that garbage collection is running
    if ($valid_nonce && isset($_POST['action']) && $_POST['action'] == 'dismiss_gc_warning') {
        wp_cache_replace_line('^ *\\$dismiss_gc_warning', "\$dismiss_gc_warning = 1;", $wp_cache_config_file);
        $dismiss_gc_warning = 1;
    } elseif (!isset($dismiss_gc_warning)) {
        $dismiss_gc_warning = 0;
    }
    if ($cache_enabled && (!isset($wp_cache_shutdown_gc) || $wp_cache_shutdown_gc == 0) && function_exists('get_gc_flag')) {
        $gc_flag = get_gc_flag();
        if ($dismiss_gc_warning == 0) {
            if (false == maybe_stop_gc($gc_flag) && false == wp_next_scheduled('wp_cache_gc')) {
                ?>
<div id="message" class="updated fade"><h3><?php 
                _e('Warning! Garbage collection is not scheduled!', 'wp-super-cache');
                ?>
</h3>
				<p><?php 
                _e('Garbage collection by this plugin clears out expired and old cached pages on a regular basis. Use <a href="#expirytime">this form</a> to enable it.', 'wp-super-cache');
                ?>
 </p>
				<form action="" method="POST">
				<input type="hidden" name="action" value="dismiss_gc_warning" />
				<input type="hidden" name="page" value="wpsupercache" />
				<?php 
                wp_nonce_field('wp-cache');
                ?>
				<input class='button-secondary' type='submit' value='<?php 
                _e('Dismiss', 'wp-super-cache');
                ?>
' />
				</form>
				<br />
				</div>
				<?php 
            }
        }
    }
    // Server could be running as the owner of the wp-content directory.  Therefore, if it's
    // writable, issue a warning only if the permissions aren't 755.
    if ($valid_nonce && isset($_POST['action']) && $_POST['action'] == 'dismiss_readable_warning') {
        wp_cache_replace_line('^ *\\$dismiss_readable_warning', "\$dismiss_readable_warning = 1;", $wp_cache_config_file);
        $dismiss_readable_warning = 1;
    } elseif (!isset($dismiss_readable_warning)) {
        $dismiss_readable_warning = 0;
    }
    if ($dismiss_readable_warning == 0 && is_writeable_ACLSafe(WP_CONTENT_DIR . '/')) {
        $wp_content_stat = stat(WP_CONTENT_DIR . '/');
        $wp_content_mode = decoct($wp_content_stat['mode'] & 0777);
        if (substr($wp_content_mode, -2) == '77') {
            ?>
<div id="message" class="updated fade"><h3><?php 
            printf(__('Warning! %s is writeable!', 'wp-super-cache'), WP_CONTENT_DIR);
            ?>
</h3>
			<p><?php 
            printf(__('You should change the permissions on %s and make it more restrictive. Use your ftp client, or the following command to fix things:', 'wp-super-cache'), WP_CONTENT_DIR);
            ?>
 <code>chmod 755 <?php 
            echo WP_CONTENT_DIR;
            ?>
/</code></p>
			<p><?php 
            _e('<a href="http://codex.wordpress.org/Changing_File_Permissions">This page</a> explains how to change file permissions.', 'wp-super-cache');
            ?>
</p>
			<form action="" method="POST">
			<input type="hidden" name="action" value="dismiss_readable_warning" />
			<input type="hidden" name="page" value="wpsupercache" />
			<?php 
            wp_nonce_field('wp-cache');
            ?>
			<input class='button-secondary' type='submit' value='<?php 
            _e('Dismiss', 'wp-super-cache');
            ?>
' />
			</form>
			<br />
			</div>
			<?php 
        }
    }
    if (function_exists("is_main_site") && true == is_main_site()) {
        $home_path = trailingslashit(get_home_path());
        $scrules = implode("\n", extract_from_markers($home_path . '.htaccess', 'WPSuperCache'));
        if ($cache_enabled && $wp_cache_mod_rewrite && !$wp_cache_mobile_enabled && strpos($scrules, addcslashes(implode('|', $wp_cache_mobile_browsers), ' '))) {
            echo '<div id="message" class="updated fade"><h3>' . __('Mobile rewrite rules detected', 'wp-super-cache') . "</h3>";
            echo "<p>" . __('For best performance you should enable "Mobile device support" or delete the mobile rewrite rules in your .htaccess. Look for the 2 lines with the text "2.0\\ MMP|240x320" and delete those.', 'wp-super-cache') . "</p><p>" . __('This will have no affect on ordinary users but mobile users will see uncached pages.', 'wp-super-cache') . "</p></div>";
        } elseif ($wp_cache_mod_rewrite && $cache_enabled && $wp_cache_mobile_enabled && $scrules != '' && (false == empty($wp_cache_mobile_prefixes) && false === strpos($scrules, addcslashes(implode('|', $wp_cache_mobile_prefixes), ' ')) || false == empty($wp_cache_mobile_browsers) && false === strpos($scrules, addcslashes(implode('|', $wp_cache_mobile_browsers), ' ')))) {
            ?>
			<div id="message" class="updated fade"><h3><?php 
            _e('Rewrite rules must be updated', 'wp-super-cache');
            ?>
</h3>
			<p><?php 
            _e('The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache');
            ?>
			<?php 
            _e('Mobile support requires extra rules in your .htaccess file, or you can set the plugin to legacy mode. Here are your options (in order of difficulty):', 'wp-super-cache');
            ?>
			<ol><li> <?php 
            _e('Set the plugin to legacy mode and enable mobile support.', 'wp-super-cache');
            ?>
</li>
			<li> <?php 
            _e('Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache');
            ?>
</li>
			<li> <?php 
            printf(__('Delete the plugin mod_rewrite rules in %s.htaccess enclosed by <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code> and let the plugin regenerate them by reloading this page.', 'wp-super-cache'), $home_path);
            ?>
</li>
			<li> <?php 
            printf(__('Add the rules yourself. Edit %s.htaccess and find the block of code enclosed by the lines <code># BEGIN WPSuperCache</code> and <code># END WPSuperCache</code>. There are two sections that look very similar. Just below the line <code>%%{HTTP:Cookie} !^.*(comment_author_|%s|wp-postpass_).*$</code> add these lines: (do it twice, once for each section)', 'wp-super-cache'), $home_path, wpsc_get_logged_in_cookie());
            ?>
</p>
			<div style='padding: 2px; margin: 2px; border: 1px solid #333; width:400px; overflow: scroll'><pre><?php 
            echo "RewriteCond %{HTTP_user_agent} !^.*(" . addcslashes(implode('|', $wp_cache_mobile_browsers), ' ') . ").*\nRewriteCond %{HTTP_user_agent} !^(" . addcslashes(implode('|', $wp_cache_mobile_prefixes), ' ') . ").*";
            ?>
</pre></div></li></ol></div><?php 
        }
        if ($cache_enabled && $super_cache_enabled && $wp_cache_mod_rewrite && $scrules == '') {
            ?>
<div id="message" class="updated fade"><h3><?php 
            _e('Rewrite rules must be updated', 'wp-super-cache');
            ?>
</h3>
		<p><?php 
            _e('The rewrite rules required by this plugin have changed or are missing. ', 'wp-super-cache');
            ?>
		<?php 
            _e('Scroll down the Advanced Settings page and click the <strong>Update Mod_Rewrite Rules</strong> button.', 'wp-super-cache');
            ?>
</p></div><?php 
        }
    }
    if ($wp_cache_mod_rewrite && $super_cache_enabled && function_exists('apache_get_modules')) {
        $mods = apache_get_modules();
        $required_modules = array('mod_mime' => __('Required to serve compressed supercache files properly.', 'wp-super-cache'), 'mod_headers' => __('Required to set caching information on supercache pages. IE7 users will see old pages without this module.', 'wp-super-cache'), 'mod_expires' => __('Set the expiry date on supercached pages. Visitors may not see new pages when they refresh or leave comments without this module.', 'wp-super-cache'));
        foreach ($required_modules as $req => $desc) {
            if (!in_array($req, $mods)) {
                $missing_mods[$req] = $desc;
            }
        }
        if (isset($missing_mods) && is_array($missing_mods)) {
            ?>
<div id="message" class="updated fade"><h3><?php 
            _e('Missing Apache Modules', 'wp-super-cache');
            ?>
</h3>
			<p><?php 
            __('The following Apache modules are missing. The plugin will work in legacy mode without them. In full Supercache mode, your visitors may see corrupted pages or out of date content however.', 'wp-super-cache');
            ?>
</p><?php 
            echo "<ul>";
            foreach ($missing_mods as $req => $desc) {
                echo "<li> {$req} - {$desc}</li>";
            }
            echo "</ul>";
            echo "</div>";
        }
    }
    if ($valid_nonce && isset($_POST['action']) && $_POST['action'] == 'dismiss_htaccess_warning') {
        wp_cache_replace_line('^ *\\$dismiss_htaccess_warning', "\$dismiss_htaccess_warning = 1;", $wp_cache_config_file);
        $dismiss_htaccess_warning = 1;
    } elseif (!isset($dismiss_htaccess_warning)) {
        $dismiss_htaccess_warning = 0;
    }
    if (isset($disable_supercache_htaccess_warning) == false) {
        $disable_supercache_htaccess_warning = false;
    }
    if ($dismiss_htaccess_warning == 0 && $wp_cache_mod_rewrite && $super_cache_enabled && $disable_supercache_htaccess_warning == false && get_option('siteurl') != get_option('home')) {
        $home_dir = str_replace(get_option('home'), '', get_option('siteurl'));
        ?>
<div id="message" class="updated fade"><h3><?php 
        _e('.htaccess file may need to be moved', 'wp-super-cache');
        ?>
</h3>
		<p><?php 
        _e('It appears you have WordPress installed in a sub directory as described <a href="http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory">here</a>. Unfortunately, WordPress writes to the .htaccess in the install directory, not where your site is served from.<br />When you update the rewrite rules in this plugin you will have to copy the file to where your site is hosted. This will be fixed in the future.', 'wp-super-cache');
        ?>
</p>
		<form action="" method="POST">
		<input type="hidden" name="action" value="dismiss_htaccess_warning" />
		<input type="hidden" name="page" value="wpsupercache" />
		<?php 
        wp_nonce_field('wp-cache');
        ?>
		<input class='button-secondary' type='submit' value='<?php 
        _e('Dismiss', 'wp-super-cache');
        ?>
' />
		</form>
		<br />
		</div><?php 
    }
    return true;
}
Example #2
0
function wp_cache_gc_cron()
{
    global $file_prefix, $cache_max_time, $cache_gc_email_me, $cache_time_interval;
    $msg = '';
    if ($cache_max_time == 0) {
        wp_cache_debug('Cache garbage collection disabled because cache expiry time is zero.', 5);
        return false;
    }
    $gc_flag = get_gc_flag();
    if (maybe_stop_gc($gc_flag)) {
        wp_cache_debug('GC flag found. GC cancelled.', 5);
        return false;
    }
    update_option('wpsupercache_gc_time', time());
    wp_cache_debug("wp_cache_gc_cron: Set GC Flag. ({$gc_flag})", 5);
    $fp = @fopen($gc_flag, 'w');
    @fclose($fp);
    wp_cache_debug('Cache garbage collection.', 5);
    if (!isset($cache_max_time)) {
        $cache_max_time = 600;
    }
    $start = time();
    $num = 0;
    if (false === ($num = wp_cache_phase2_clean_expired($file_prefix))) {
        wp_cache_debug('Cache Expiry cron job failed. Probably mutex locked.', 1);
        update_option('wpsupercache_gc_time', time() - ($cache_time_interval - 10));
        // if GC failed then run it again in one minute
        $msg .= __('Cache expiry cron job failed. Job will run again in 10 seconds.', 'wp-super-cache') . "\n";
    }
    if (time() - $start > 30) {
        wp_cache_debug("Cache Expiry cron job took more than 30 seconds to execute.\nYou should reduce the Expiry Time in the WP Super Cache admin page\nas you probably have more cache files than your server can handle efficiently.", 1);
        $msg .= __('Cache expiry cron job took more than 30 seconds. You should probably run the garbage collector more often.', 'wp-super-cache') . "\n";
    }
    if ($cache_gc_email_me) {
        if ($msg != '') {
            $msg = "The following warnings were generated by the WP Super Cache Garbage Collector:\n" . $msg;
        }
        $msg = "Hi,\n\nThe WP Super Cache Garbage Collector has now run, deleting " . (int) $num . " files and directories.\nIf you want to switch off these emails please see the WP Super Cache Advanced Settings\npage on your blog.\n\n{$msg}\nRegards,\nThe Garbage Collector.";
        wp_mail(get_option('admin_email'), sprintf(__('[%1$s] WP Super Cache GC Report', 'wp-super-cache'), site_url()), $msg);
    }
    @unlink($gc_flag);
    wp_cache_debug('GC completed. GC flag deleted.', 5);
    schedule_wp_gc(1);
}