diff --git a/advanced-cache.php b/advanced-cache.php index 2b71dd1..afee91b 100644 --- a/advanced-cache.php +++ b/advanced-cache.php @@ -216,6 +216,7 @@ function wp_ffpc_callback($buffer) { /* check if caching is disabled for page type */ $nocache_key = 'nocache_'. $wp_ffpc_meta['type']; + /* don't cache if prevented by rule, also, log it */ if ( $wp_ffpc_config[$nocache_key] == 1 ) { wp_ffpc_log ( "not caching, prevented by settings for no-cache: " . $nocache_key ); return $buffer; diff --git a/readme.txt b/readme.txt index 72c92bc..f63f5a5 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i Tags: cache, APC, memcached, full page cache Requires at least: 3.0 Tested up to: 3.5.1 -Stable tag: 0.4.3 +Stable tag: 0.5 Fast Full Page Cache, backend can be memcached or APC @@ -44,8 +44,8 @@ Parts are based on [Hyper Cache](http://wordpress.org/extend/plugins/hyper-cache 1. Upload contents of `wp-ffpc.zip` to the `/wp-content/plugins/` directory 2. Enable WordPress cache by adding `define('WP_CACHE',true);` in wp-config.php 3. Activate the plugin through the `Plugins` menu in WordPress (please use network wide activation if used in a WordPress Network) -4. Fine tune the settings in `Settings` -> `wp-ffpc` menu in WordPress. -For WordPress Network, please visit the Network Admin panel, the options will be available under Network Admin Settings page, in WP-FFPC menu entry. +4. Check the settings in `Settings` -> `wp-ffpc` menu in WordPress. For WordPress Network, please visit the Network Admin panel, the options will be available under Network Admin Settings page, in WP-FFPC menu entry. +5. Save the settings. THIS STEP IS MANDATORY: without saving the settings, there will be no activated caching! == Frequently Asked Questions == @@ -60,18 +60,21 @@ You have to remove the default yum package, named `php-pecl-memcache` and instal == Changelog == = 0.5 = -2013.03.04 +2013.03.06 WARNING, MAJOR CHANGES! -* long-running %3C really fixed ( version 0.4.3 was dead end ) by the help of Mark Costlow -* UI cleanup, introducing tabbed interface +* default values bug ( causing %3C bug ) really fixed by the help of Mark Costlow +* UI cleanup, new tabbed layout * WP-FFPC options moved from global menu to under Settings in both Site and Network Admin interfaces * added 'persistent' checkbox for memcached connections * added support for multiple memcached servers, feature request from ivan.buttinoni ( ivanbuttinoni @ WordPress.org forum ) * case-sensitive string checks replaced with case-insensitives, contribution of Mark Costlow * refactored settings saving mechanism * additional syslog informations +* additional comments on the code +* lots of minor fixes +* donation link on the top = 0.4.3 = 2013.03.03 diff --git a/wp-ffpc-common.php b/wp-ffpc-common.php index 1de6721..257e8c6 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_INFO ); /* define log ending message */ define ('WP_FFPC_LOG_TYPE_MSG' , '; cache type: '. $wp_ffpc_config['cache_type'] ); @@ -103,7 +103,8 @@ function wp_ffpc_init( $wp_ffpc_config ) { default: return false; } - return $wp_ffpc_backend_status; + + return ( empty ( $wp_ffpc_backend_status ) ? false : $wp_ffpc_backend_status ); } /** diff --git a/css/wp-ffpc.admin.css b/wp-ffpc.admin.css similarity index 100% rename from css/wp-ffpc.admin.css rename to wp-ffpc.admin.css diff --git a/wp-ffpc.php b/wp-ffpc.php index 9fa2336..777af65 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -9,7 +9,9 @@ Author URI: http://petermolnar.eu/ License: GPL2 */ -/* Copyright 2010-2011 Peter Molnar (email : hello@petermolnar.eu ) +/* Copyright 2010-2013 Peter Molnar (email : hello@petermolnar.eu ) + + Many thanks to contributor Mark Costlow This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as @@ -63,7 +65,9 @@ define ( 'WP_FFPC_ACACHE_COMMON_FILE' , WP_FFPC_DIR. '/wp-ffpc-common.php' ); define ( 'WP_FFPC_CONFIG_VAR' , '$wp_ffpc_config' ); 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' ); +/* get the common functions */ include_once (WP_FFPC_DIR .'/wp-ffpc-common.php'); if (!class_exists('WPFFPC')) { @@ -85,6 +89,7 @@ if (!class_exists('WPFFPC')) { /* status, 0 = nothing happened*/ var $status = 0; + /* stores information if plugin is network active or not */ var $network = false; /** @@ -101,7 +106,7 @@ if (!class_exists('WPFFPC')) { $alive = wp_ffpc_init( $this->options ); /* don't register hooks if backend is dead */ - if ($alive) + if (!$alive) { /* init inactivation hooks */ add_action('switch_theme', array( $this , 'invalidate'), 0); @@ -120,7 +125,7 @@ if (!class_exists('WPFFPC')) { if( is_admin() ) { wp_enqueue_script ( "jquery-ui-tabs" ); - wp_enqueue_style( WP_FFPC_PARAM . '.admin.css' , WP_FFPC_URL . '/css/'. WP_FFPC_PARAM .'.admin.css', false, '0.1'); + wp_enqueue_style( WP_FFPC_PARAM . '.admin.css' , WP_FFPC_URL . '/' . WP_FFPC_PARAM .'.admin.css', false, '0.1'); } /* on activation */ @@ -132,7 +137,6 @@ if (!class_exists('WPFFPC')) { /* on uninstall */ register_uninstall_hook(__FILE__ , array( $this , 'uninstall') ); - /* init plugin in the admin section */ /* if multisite, admin page will be on network admin section */ if ( $this->network ) @@ -147,6 +151,10 @@ if (!class_exists('WPFFPC')) { * */ function activate ( ) { + + /* register options for first time */ + add_site_option( WP_FFPC_PARAM, $this->options , '' , 'yes'); + $this->save_settings( true ); } @@ -155,9 +163,6 @@ if (!class_exists('WPFFPC')) { * */ function admin_init () { - /* register options */ - add_site_option( WP_FFPC_PARAM, $this->options , '' , 'no'); - /* save parameter updates, if there are any */ if ( isset($_POST[WP_FFPC_PARAM . '-save']) ) { @@ -166,8 +171,8 @@ if (!class_exists('WPFFPC')) { header("Location: admin.php?page=" . WP_FFPC_OPTIONS_PAGE . "&saved=true"); } + /* we use settings menu, no need for highest level menu */ add_submenu_page('settings.php', 'Edit WP-FFPC options', __('WP-FFPC', WP_FFPC_PARAM ), 10, WP_FFPC_OPTIONS_PAGE , array ( $this , 'admin_panel' ) ); - //add_menu_page('Edit WP-FFPC options', __('WP-FFPC', WP_FFPC_PARAM ), 10, WP_FFPC_OPTIONS_PAGE , array ( $this , 'admin_panel' ) ); } /** @@ -203,27 +208,36 @@ if (!class_exists('WPFFPC')) {
-

This plugin helped your business? Buy me a coffee for having it :)

+

This plugin helped your business? Buy me a coffee for having it, please :)

-

+

- -

+ +

+ + + options['cache_type'] == 'memcached' && !class_exists('Memcached') ) : ?> +

+ + + options['cache_type'] == 'memcache' && !class_exists('Memcache') ) : ?> +

- options['cache_type'] == 'memcached' && $memcached_protocol == 'binary' ) : ?> -

+ options['cache_type'] == 'memcache' && $memcached_protocol == 'binary' ) : ?> +

options['cache_type'] == 'memcached' || $this->options['cache_type'] == 'memcache' ) : ?> -
+

Backend status:
', WP_FFPC_PARAM ); $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'] ." => "; $server_status = ( empty($init) || $init[$server_string] == 0 ) ? 'down' : 'up & running' ; @@ -531,6 +546,9 @@ if (!class_exists('WPFFPC')) { /** * invalidate cache + * + * @param $post_id + * id of post to be removed from cache entries */ function invalidate ( $post_id ) { wp_ffpc_clear ( $post_id ); @@ -619,10 +637,9 @@ if (!class_exists('WPFFPC')) { $this->defaults = $defaults; + /* maps saved options and defaults */ $this->options = get_site_option( WP_FFPC_PARAM , $defaults, false ); - $this->split_hosts(); - } /** @@ -675,6 +692,13 @@ if (!class_exists('WPFFPC')) { /** * function to be able to store redirects + * + * @param $redirect_url + * url of required wordpress redirect + * + * @param $requested_url + * currently unused + * */ function redirect_canonical($redirect_url, $requested_url) { global $wp_nmc_redirect; @@ -685,43 +709,62 @@ if (!class_exists('WPFFPC')) { /** * save settings function * + * @param firstrun + * boolean: true if the function is called on plugin activation + * */ function save_settings ( $firstrun = false ) { - $defaults = $this->defaults; + $options = $this->defaults; - foreach ( $defaults as $key => $default ) + /* only try to update defaults if it's not first run and $_POST is not empty */ + if ( !$firstrun && !empty ( $_POST ) ) { - if (!empty($_POST[$key])) + foreach ( $options as $key => $default ) { - $update = $_POST[$key]; - if ( strlen( $update ) !=0 && !is_numeric($update) ) - $update = stripslashes($update); - } - elseif ( ( empty( $_POST[$name] ) && is_bool ( $default ) ) || is_int( $default ) ) - { - $update = 0; - } - else - { - $update = $this->options[$key]; - } + /* $_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; + $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(); + /* save options */ update_site_option( WP_FFPC_PARAM , $this->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(); } + /** + * splits config parameter "hosts" into an array of server string, host and port + * to be used in later config + * + */ function split_hosts ( ) { $servers = explode( WP_FFPC_SERVER_LIST_SEPARATOR , $this->options['hosts']); @@ -750,6 +793,7 @@ if (!class_exists('WPFFPC')) { */ function uninstall ( ) { delete_site_option( WP_FFPC_PARAM ); + wp_ffpc_log ( "plugin uninstalled "); } }