diff --git a/advanced-cache.php b/advanced-cache.php index afee91b..1d641a5 100644 --- a/advanced-cache.php +++ b/advanced-cache.php @@ -11,6 +11,14 @@ if ( !WP_CACHE ) if (!isset($wp_ffpc_config)) return false; +/* check if config is network active or active for this very site */ +if (!empty ( $wp_ffpc_config['network'] ) ) + $wp_ffpc_config = $wp_ffpc_config['network']; +elseif ( !empty ( $wp_ffpc_config[ $_SERVER['HTTP_HOST' ] ] ) ) + $wp_ffpc_config = $wp_ffpc_config[ $_SERVER['HTTP_HOST' ] ]; +else + return false; + /* request uri */ $wp_ffpc_uri = $_SERVER['REQUEST_URI']; /* query string */ diff --git a/readme.txt b/readme.txt index 812e6a5..289af63 100644 --- a/readme.txt +++ b/readme.txt @@ -23,12 +23,12 @@ WP-FFPC is a full page cache plugin for WordPress. Supports memcached server or * fallback to no caching if any error or problem occurs * syslog & debug settings for troubleshooting * supports multiple memcached backends -* Wordpress Network compatible(2) +* Wordpress Network compatible (2) * nginx compatible(3) (1) pingback hostname will always be generated from the accessed domain, otherwise speed would get highly compromised -(2) If enabled as network-wide plugin in a WordPress Network, the configuration will only be available for network admins at the network admin panel, will be system-wide and will be applied for every blog. +(2) Plugin is capable of either Network wide or per site settings, meaning if not network-wide enabled, settings could vary from site to site, plugin could be turned off and on without interfering other sites. (3) nginx compatility means that if used with PHP Memcache or PHP Memcached extension, the created memcached entries can be read and served directly from nginx. If used with APC, this feature is not available (no APC module for nginx). @@ -56,6 +56,13 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal == Changelog == += 0.6 = +*development branch* + +* true WordPress Network support: + * if enabled network-wide, settings will be the same for every site + * if enabled only per site settings could vary from site to site and cache could be active or disabled on a per site basis without interfering other sites + = 0.5.1 = *2013.03.07* diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index 257e8c6..070e070 100644 --- a/wp-ffpc-common.php +++ b/wp-ffpc-common.php @@ -13,7 +13,7 @@ global $wp_nmc_redirect; if (!defined('WP_FFPC_PARAM')) define ( 'WP_FFPC_PARAM' , 'wp-ffpc' ); /* log level */ -define ('WP_FFPC_LOG_LEVEL' , LOG_INFO ); +define ('WP_FFPC_LOG_LEVEL' , LOG_WARNING ); /* define log ending message */ define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] ); diff --git a/wp-ffpc.php b/wp-ffpc.php index cc27fcd..616c2fd 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -67,6 +67,10 @@ define ( 'WP_FFPC_SERVER_LIST_SEPARATOR' , ',' ); define ( 'WP_FFPC_SERVER_SEPARATOR', ':' ); define ( 'WP_FFPC_DONATION_LINK', 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XU3DG7LLA76WC' ); define ( 'WP_FFPC_FILE' , plugin_basename(__FILE__) ); +define ( 'WP_FFPC_PLUGIN' , 'wp-ffpc/wp-ffpc.php' ); + +if ( ! function_exists( 'is_plugin_active_for_network' ) ) + require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); /* get the common functions */ include_once (WP_FFPC_DIR .'/wp-ffpc-common.php'); @@ -81,6 +85,10 @@ if (!class_exists('WPFFPC')) { /* for options array */ var $options = array(); + /* stores options for all sites & all data */ + var $all_options = array(); + /* key for current options array */ + var $options_key = ''; /* for default options array */ var $defaults = array(); /* memcached server object */ @@ -265,7 +273,7 @@ if (!class_exists('WPFFPC')) {
Backend status:
', WP_FFPC_PARAM );
- $init = wp_ffpc_init( $this->options);
+ $init = wp_ffpc_init( $this->options );
/* we need to go through all servers */
foreach ( $this->options['servers'] as $server_string => $server ) {
echo $server['host'] . ":" . $server['port'] ." => ";
@@ -545,17 +553,19 @@ if (!class_exists('WPFFPC')) {
*
*/
function check_for_network( ) {
- if ( is_multisite() )
+
+ $this->options_key = $_SERVER['HTTP_HOST'];
+
+ if ( is_plugin_active_for_network ( WP_FFPC_PLUGIN ) )
{
- $plugins = get_site_option( 'active_sitewide_plugins');
- /* see if plugins is active */
- if ( isset($plugins['wp-ffpc/wp-ffpc.php']) )
- {
- $this->network = true;
- /* replace settings link */
- $this->settingslink = str_replace( 'options-general.php' , 'settings.php' , $this->settingslink );
- }
+ /* set active for network */
+ $this->network = true;
+ /* replace settings link */
+ $this->settingslink = str_replace( 'options-general.php' , 'settings.php' , $this->settingslink );
+ /* set options key */
+ $this->options_key = 'network';
}
+
}
/**
@@ -563,8 +573,10 @@ if (!class_exists('WPFFPC')) {
*
*/
function deactivate ( ) {
- if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
- @unlink (WP_FFPC_ACACHE_MAIN_FILE);
+ //if (@file_exists (WP_FFPC_ACACHE_MAIN_FILE))
+ // @unlink (WP_FFPC_ACACHE_MAIN_FILE);
+ $this->save_settings( false, true );
+ //$this->generate_config ( true );
}
/**
@@ -602,10 +614,13 @@ if (!class_exists('WPFFPC')) {
}
/**
- * generates main advanced-cache system-wide config file
+ * generates main advanced-cache config file
+ *
+ * @param $delete_current
+ * deletes current config settings on deactivation
*
*/
- function generate_config() {
+ function generate_config( ) {
$acache = WP_FFPC_ACACHE_MAIN_FILE;
/* is file currently exists, delete it*/
@@ -616,10 +631,15 @@ if (!class_exists('WPFFPC')) {
if ( @file_exists( $acache ))
return false;
+ /* if no config left, don't create empty config */
+ if ( empty ( $this->all_options ) )
+ return false;
+
+ //if ( is_plugin_active_for_network ( WP_FFPC_PLUGIN ) && !is_plugin_active ( WP_FFPC_PLUGIN ) )
+ // return false;
+
$string = 'options , true ) . ';';
-
+ $string .= WP_FFPC_CONFIG_VAR .' = ' .var_export( $this->all_options , true ) . ';';
$string .= "\n\ninclude_once ('" . WP_FFPC_ACACHE_COMMON_FILE . "');\ninclude_once ('" . WP_FFPC_ACACHE_INC_FILE . "');\n";
file_put_contents($acache, $string);
@@ -661,7 +681,14 @@ if (!class_exists('WPFFPC')) {
$this->defaults = $defaults;
/* maps saved options and defaults */
- $this->options = get_site_option( WP_FFPC_PARAM , $defaults, false );
+ //$this->options = get_site_option( WP_FFPC_PARAM , $defaults, false );
+
+ $this->all_options = get_site_option( WP_FFPC_PARAM );
+
+ if ( ! empty ( $this->all_options[ $this->options_key ] ) )
+ $this->options = array_merge ( $defaults, $this->all_options[ $this->options_key ] );
+ else
+ $this->options = $defaults;
}
@@ -736,54 +763,25 @@ if (!class_exists('WPFFPC')) {
* boolean: true if the function is called on plugin activation
*
*/
- function save_settings ( $firstrun = false ) {
+ function save_settings ( $firstrun = false, $delete_current = false ) {
- $options = $this->defaults;
-
- /* only try to update defaults if it's not first run and $_POST is not empty */
- if ( !$firstrun && !empty ( $_POST ) )
- {
- foreach ( $options as $key => $default )
- {
- /* $_POST element is available */
- if (!empty($_POST[$key]))
- {
- $update = $_POST[$key];
- /* get rid of slashed */
- if ( strlen( $update ) !=0 &&!is_numeric($update) )
- $update = stripslashes($update);
-
- $options[$key] = $update;
- }
- /* empty $_POST element: when HTML form posted, empty checkboxes a 0 values will not be
- part of the $_POST array, thus we need to check if this is the situation by
- checking the types of the elements, since a missing value could mean update from 1 to 0
- */
- elseif ( empty( $_POST[$key] ) && ( is_bool ( $default ) || is_int( $default ) ) )
- {
- $options[$key] = 0;
- }
- }
- }
-
- $this->options = $options;
-
- /* set up server array from hosts config var */
- $this->split_hosts();
+ if ( $delete_current )
+ unset ( $this->all_options[ $this->options_key ] );
+ else
+ $this->update_settings( $firstrun );
/* save options */
- update_site_option( WP_FFPC_PARAM , $this->options );
+ update_site_option( WP_FFPC_PARAM , $this->all_options );
/* invalidate cache, this is neccessary */
$this->invalidate('system_flush');
/* if it's not for the first run, generate the config file */
if ( ! $firstrun )
- $this->generate_config();
+ $this->generate_config( );
}
-
/**
*
*
@@ -830,6 +828,43 @@ if (!class_exists('WPFFPC')) {
wp_ffpc_log ( "plugin uninstalled ");
}
+
+ function update_settings ( $firstrun = false ) {
+ $options = $this->defaults;
+
+ /* only try to update defaults if it's not first run and $_POST is not empty */
+ if ( !$firstrun && !empty ( $_POST ) )
+ {
+ foreach ( $options as $key => $default )
+ {
+ /* $_POST element is available */
+ if (!empty($_POST[$key]))
+ {
+ $update = $_POST[$key];
+ /* get rid of slashed */
+ if ( strlen( $update ) !=0 &&!is_numeric($update) )
+ $update = stripslashes($update);
+
+ $options[$key] = $update;
+ }
+ /* empty $_POST element: when HTML form posted, empty checkboxes a 0 values will not be
+ part of the $_POST array, thus we need to check if this is the situation by
+ checking the types of the elements, since a missing value could mean update from 1 to 0
+ */
+ elseif ( empty( $_POST[$key] ) && ( is_bool ( $default ) || is_int( $default ) ) )
+ {
+ $options[$key] = 0;
+ }
+ }
+ }
+
+ $this->options = $options;
+
+ /* set up server array from hosts config var */
+ $this->split_hosts();
+
+ $this->all_options[ $this->options_key ] = $this->options;
+ }
}
}