Created
June 6, 2012 08:47
-
-
Save peterchester/2880732 to your computer and use it in GitHub Desktop.
Hyper Cache Site Option
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/wp-content/plugins/hyper-cache/options.php b/wp-content/plugins/hyper-cache/options.php | |
index 9daa572..cbc1e7e 100644 | |
--- a/wp-content/plugins/hyper-cache/options.php | |
+++ b/wp-content/plugins/hyper-cache/options.php | |
@@ -1,6 +1,6 @@ | |
<?php | |
-$options = get_option('hyper'); | |
+$options = hyper_get_options(); | |
if (!isset($options['notranslation']) || !$options['notranslation']) | |
{ | |
@@ -44,7 +44,7 @@ if (isset($_POST['save'])) | |
else { | |
$error = true; | |
} | |
- update_option('hyper', $options); | |
+ hyper_update_options($options); | |
// When the cache does not expire | |
if (isset($options['expire_type']) && $options['expire_type'] == 'none') | |
@@ -256,7 +256,7 @@ else | |
<tr valign="top"> | |
<th><?php _e('Mobile agent list', 'hyper-cache'); ?></th> | |
<td> | |
- <textarea wrap="off" rows="4" cols="70" name="options[mobile_agents]"><?php echo htmlspecialchars($options['mobile_agents']); ?></textarea> | |
+ <textarea wrap="off" rows="4" cols="70" name="options[mobile_agents]"><?php echo isset($options['mobile_agents'])?htmlspecialchars($options['mobile_agents']):''; ?></textarea> | |
<div class="hints"> | |
<?php _e('One per line mobile agents to check for when a page is requested.', 'hyper-cache'); ?> | |
<?php _e('The mobile agent string is matched against the agent a device is sending to the server.', 'hyper-cache'); ?> | |
diff --git a/wp-content/plugins/hyper-cache/plugin.php b/wp-content/plugins/hyper-cache/plugin.php | |
index dd70acf..9f8dfb8 100644 | |
--- a/wp-content/plugins/hyper-cache/plugin.php | |
+++ b/wp-content/plugins/hyper-cache/plugin.php | |
@@ -37,24 +37,14 @@ $hyper_invalidated_post_id = null; | |
register_activation_hook(__FILE__, 'hyper_activate'); | |
function hyper_activate() | |
{ | |
- $options = get_option('hyper'); | |
+ $options = hyper_get_options(); | |
+ hyper_initialize($options); | |
+} | |
+function hyper_initialize($options) | |
+{ | |
wp_clear_scheduled_hook('hyper_clean'); | |
- if (!is_array($options)) { | |
- $options = array(); | |
- $options['comment'] = 1; | |
- $options['archive'] = 1; | |
- $options['timeout'] = 1440; | |
- $options['redirects'] = 1; | |
- $options['notfound'] = 1; | |
- $options['clean_interval'] = 60; | |
- $options['gzip'] = 1; | |
- $options['store_compressed'] = 1; | |
- $options['expire_type'] = 'post'; | |
- update_option('hyper', $options); | |
- } | |
- | |
$buffer = hyper_generate_config($options); | |
$file = @fopen(ABSPATH . 'wp-content/advanced-cache.php', 'wb'); | |
@fwrite($file, $buffer); | |
@@ -73,7 +63,7 @@ function hyper_clean() | |
hyper_log('start cleaning'); | |
- $options = get_option('hyper'); | |
+ $options = hyper_get_options(); | |
$timeout = $options['timeout']*60; | |
if ($timeout == 0) return; | |
@@ -117,10 +107,22 @@ function hyper_deactivate() | |
} | |
} | |
-add_action('admin_menu', 'hyper_admin_menu'); | |
-function hyper_admin_menu() | |
-{ | |
- add_options_page('Hyper Cache', 'Hyper Cache', 'manage_options', 'hyper-cache/options.php'); | |
+if (is_multisite()) { | |
+ add_action('network_admin_menu', 'hyper_network_admin_menu'); | |
+ function hyper_network_admin_menu() | |
+ { | |
+ add_submenu_page( 'settings.php', 'Hyper Cache', 'Hyper Cache', 'manage_sites', 'hyper-cache', 'hyper_network_admin_page' ); | |
+ } | |
+ function hyper_network_admin_page() | |
+ { | |
+ require_once('options.php'); | |
+ } | |
+} else { | |
+ add_action('admin_menu', 'hyper_admin_menu'); | |
+ function hyper_admin_menu() | |
+ { | |
+ add_options_page('Hyper Cache', 'Hyper Cache', 'manage_options', 'hyper-cache/options.php'); | |
+ } | |
} | |
// Completely invalidate the cache. The hyper-cache directory is renamed | |
@@ -168,7 +170,7 @@ function hyper_cache_invalidate_post($post_id) | |
return; | |
} | |
- $options = get_option('hyper'); | |
+ $options = hyper_get_options(); | |
if ($options['expire_type'] == 'none') | |
{ | |
@@ -450,4 +452,41 @@ function hyper_generate_config(&$options) | |
return $buffer; | |
} | |
+ | |
+function hyper_get_options() | |
+{ | |
+ $options = get_site_option('hyper'); | |
+ | |
+ // Reverse compatibility - first check if we have saved the options to this blog's options table. | |
+ if (!is_array($options)) { | |
+ $options = get_option('hyper'); | |
+ if (is_array($options)) { | |
+ hyper_update_options($options); | |
+ delete_option('hyper'); | |
+ } | |
+ } | |
+ | |
+ // If there are still no options, then use defaults. | |
+ if (!is_array($options)) { | |
+ $options = array(); | |
+ $options['comment'] = 1; | |
+ $options['archive'] = 1; | |
+ $options['timeout'] = 1440; | |
+ $options['redirects'] = 1; | |
+ $options['notfound'] = 1; | |
+ $options['clean_interval'] = 60; | |
+ $options['gzip'] = 1; | |
+ $options['store_compressed'] = 1; | |
+ $options['expire_type'] = 'post'; | |
+ hyper_update_options($options); | |
+ } | |
+ hyper_initialize($options); | |
+ | |
+ return $options; | |
+} | |
+ | |
+function hyper_update_options($options) | |
+{ | |
+ update_site_option('hyper',$options); | |
+} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment