function wp_cache_disable_plugin() { global $wp_cache_config_file, $wp_rewrite; if (file_exists(ABSPATH . 'wp-config.php')) { $global_config_file = ABSPATH . 'wp-config.php'; } else { $global_config_file = dirname(ABSPATH) . '/wp-config.php'; } $line = 'define(\'WP_CACHE\', true);'; if (strpos(file_get_contents($global_config_file), $line) && (!is_writeable_ACLSafe($global_config_file) || !wp_cache_replace_line('define *\\( *\'WP_CACHE\'', '//' . $line, $global_config_file))) { wp_die("Could not remove WP_CACHE define from {$global_config_file}. Please edit that file and remove the line containing the text 'WP_CACHE'. Then refresh this page."); } uninstall_supercache(WP_CONTENT_DIR . '/cache'); $file_not_deleted = false; if (@file_exists(WP_CONTENT_DIR . "/advanced-cache.php")) { if (false == @unlink(WP_CONTENT_DIR . "/advanced-cache.php")) { $file_not_deleted[] = 'advanced-cache.php'; } } if (@file_exists(WP_CONTENT_DIR . "/wp-cache-config.php")) { if (false == unlink(WP_CONTENT_DIR . "/wp-cache-config.php")) { $file_not_deleted[] = 'wp-cache-config.php'; } } if ($file_not_deleted) { $msg = "<p>One or more files could not be deleted. These files and directories must be made writeable:</p>\n <ol><li>" . WP_CONTENT_DIR . "</li>\n"; $code = "<ul>\n"; foreach ((array) $file_not_deleted as $filename) { $msg .= "<li>" . WP_CONTENT_DIR . "/{$filename}</li>"; $code .= "<li><code>chmod 666 " . WP_CONTENT_DIR . "/{$filename}</code></li>\n"; } $code .= "</ul>\n"; $msg .= "</ol>\n<p>First try fixing the directory permissions with this command and refresh this page:<br /><br /><code>chmod 777 " . WP_CONTENT_DIR . "</code><br /><br />If you still see this error, you have to fix the permissions on the files themselves and refresh this page again:</p> {$code}\n<p>Don't forgot to fix things later:<br /><code>chmod 755 " . WP_CONTENT_DIR . "</code></p><p>If you don't know what <strong>chmod</strong> is use <a href='http://www.google.ie/search?hl=en&q=ftp+chmod+777'>this Google search</a> to find out all about it.</p><p>Please refresh this page when the permissions have been modified.</p>"; wp_die($msg); } extract(wpsc_get_htaccess_info()); if ($scrules != '' && insert_with_markers($home_path . '.htaccess', 'WPSuperCache', array())) { $wp_rewrite->flush_rules(); } elseif ($scrules != '') { wp_mail(get_option('admin_email'), __('Supercache Uninstall Problems', 'wp-super-cache'), sprintf(__("Dear User,\n\nWP Super Cache was removed from your blog but the mod_rewrite rules\nin your .htaccess were not.\n\nPlease edit the following file and remove the code\nbetween 'BEGIN WPSuperCache' and 'END WPSuperCache'. Please backup the file first!\n\n%s\n\nRegards,\nWP Super Cache Plugin\nhttp://wordpress.org/extend/plugins/wp-super-cache/", 'wp-super-cache'), ABSPATH . '/.htaccess')); } }
function wpsc_remove_marker($filename, $marker) { if (!file_exists($filename) || is_writeable_ACLSafe($filename)) { if (!file_exists($filename)) { return ''; } else { $markerdata = explode("\n", implode('', file($filename))); } $f = fopen($filename, 'w'); $foundit = false; if ($markerdata) { $state = true; foreach ($markerdata as $n => $markerline) { if (strpos($markerline, '# BEGIN ' . $marker) !== false) { $state = false; } if ($state) { if ($n + 1 < count($markerdata)) { fwrite($f, "{$markerline}\n"); } else { fwrite($f, "{$markerline}"); } } if (strpos($markerline, '# END ' . $marker) !== false) { $state = true; } } } return true; } else { return false; } }
function wpsc_update_htaccess_form($short_form = true) { global $wpmu_version; extract(wpsc_get_htaccess_info()); if (!is_writeable_ACLSafe($home_path . ".htaccess")) { echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><h4>" . __('Cannot update .htaccess', 'wp-super-cache') . "</h4><p>" . sprintf(__('The file <code>%s.htaccess</code> cannot be modified by the web server. Please correct this using the chmod command or your ftp client.', 'wp-super-cache'), $home_path) . "</p><p>" . __('Refresh this page when the file permissions have been modified.') . "</p><p>" . sprintf(__('Alternatively, you can edit your <code>%s.htaccess</code> file manually and add the following code (before any WordPress rules):', 'wp-super-cache'), $home_path) . "</p>"; echo "<p><pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p></div>"; } else { if ($short_form == false) { echo "<div style='padding:0 8px;color:#9f6000;background-color:#feefb3;border:1px solid #9f6000;'><p>" . sprintf(__('To serve static html files your server must have the correct mod_rewrite rules added to a file called <code>%s.htaccess</code>', 'wp-super-cache'), $home_path) . " "; if (!function_exists('is_site_admin')) { _e("You must edit the file yourself add the following rules.", 'wp-super-cache'); } else { _e("You can edit the file yourself add the following rules.", 'wp-super-cache'); } echo __(" Make sure they appear before any existing WordPress rules. ", 'wp-super-cache') . "</p>"; echo "<pre># BEGIN WPSuperCache\n" . wp_specialchars($rules) . "# END WPSuperCache</pre></p>"; echo "<p>" . sprintf(__('Rules must be added to %s too:', 'wp-super-cache'), WP_CONTENT_DIR . "/cache/.htaccess") . "</p>"; echo "<pre># BEGIN supercache\n" . wp_specialchars($gziprules) . "# END supercache</pre></p>"; } if (!isset($wpmu_version) || $wpmu_version == '') { echo '<form name="updatehtaccess" action="#modrewrite" method="post">'; echo '<input type="hidden" name="updatehtaccess" value="1" />'; echo '<div class="submit"><input type="submit" ' . SUBMITDISABLED . 'id="updatehtaccess" value="' . __('Update Mod_Rewrite Rules', 'wp-super-cache') . ' »" /></div>'; wp_nonce_field('wp-cache'); echo "</form></div>\n"; } } }