From 156611cb47c5d2d0376700f08d2360521920618c Mon Sep 17 00:00:00 2001 From: Harold Kyle Date: Tue, 9 Apr 2013 00:31:27 -0400 Subject: [PATCH 1/5] has_cap numeric user levels have been deprecated since 2.0, changed to manage_options --- wp-ffpc-abstract.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-ffpc-abstract.php b/wp-ffpc-abstract.php index dc5d5ba..77627d6 100644 --- a/wp-ffpc-abstract.php +++ b/wp-ffpc-abstract.php @@ -65,7 +65,7 @@ if (!class_exists('WP_Plugins_Abstract')) { protected $donation_link; protected $button_save; protected $button_delete; - protected $capability = 10; + protected $capability = 'manage_options'; protected $donation_business_name; protected $donation_item_name; protected $broadcast_message; From c3329aa4d1e94aa4b8df5b329488d29d8024524d Mon Sep 17 00:00:00 2001 From: Harold Kyle Date: Tue, 9 Apr 2013 00:32:07 -0400 Subject: [PATCH 2/5] fixed undefined index notices --- wp-ffpc-acache.php | 4 ++-- wp-ffpc-class.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index 17cd914..6428f8c 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -96,14 +96,14 @@ foreach ( $wp_ffpc_keys as $internal => $key ) { } /* serve cache 404 status */ -if ( $wp_ffpc_values['meta']['status'] == 404 ) { +if ( isset( $wp_ffpc_values['meta']['status'] ) && $wp_ffpc_values['meta']['status'] == 404 ) { header("HTTP/1.1 404 Not Found"); flush(); die(); } /* server redirect cache */ -if ( $wp_ffpc_values['meta']['redirect'] ) { +if ( isset( $wp_ffpc_values['meta']['redirect'] ) && $wp_ffpc_values['meta']['redirect'] ) { header('Location: ' . $wp_ffpc_values['meta']['redirect'] ); flush(); die(); diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 8dc4de2..92b4805 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -582,7 +582,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { plugin_constant ); ?>
- status == 5 || $this->shell_function == false ) : ?> + status == 5 || $this->shell_function == false ) : ?> Since precaching may take a very long time, it's done through a background CLI process in order not to run out of max execution time of PHP. Please enable one of the following functions if you whish to use precaching: " , $this->plugin_constant ) ?>shell_possibilities ); ?> From d64f49958f0f988b4022e75361f50527688c4ca4 Mon Sep 17 00:00:00 2001 From: Harold Kyle Date: Tue, 9 Apr 2013 13:19:02 -0400 Subject: [PATCH 3/5] fixed grouping of if statement for $_GET of self::key_precache_disabled --- wp-ffpc-class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 92b4805..811158f 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -264,7 +264,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) { /** * if options were saved, display saved message */ - if (isset($_GET[ self::key_precache ]) && $_GET[ self::key_precache ]=='true' || $this->status == 4) : ?> + if ( ( isset($_GET[ self::key_precache ]) && $_GET[ self::key_precache ]=='true' ) || $this->status == 4) : ?>

plugin_constant ) ?>

Date: Tue, 9 Apr 2013 15:40:03 -0400 Subject: [PATCH 4/5] exclude caching for requests with cookie name(s) starting with a certain string --- wp-ffpc-acache.php | 25 +++++++++++++++++++++---- wp-ffpc-class.php | 37 +++++++++++++++++++++++++++++++++---- wp-ffpc-nginx-sample.conf | 4 ++++ wp-ffpc.php | 1 + 4 files changed, 59 insertions(+), 8 deletions(-) diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index 6428f8c..23c4da1 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -53,17 +53,34 @@ else return false; /* no cache for for logged in users normally, only if enabled */ -if ( $wp_ffpc_config['cache_loggedin'] == 0 ) { +if ( $wp_ffpc_config['cache_loggedin'] == 0 || $wp_ffpc_config['nocache_cookies'] ) { + + $nocache_cookies = array(); + if( $wp_ffpc_config['nocache_cookies'] ){ + $nocache_cookies = array_map('trim',explode(",", $wp_ffpc_config['nocache_cookies'] ) ); + } + foreach ($_COOKIE as $n=>$v) { // test cookie makes to cache not work!!! if ($n == 'wordpress_test_cookie') continue; // wp 2.5 and wp 2.3 have different cookie prefix, skip cache if a post password cookie is present, also - if ( (substr($n, 0, 14) == 'wordpressuser_' || substr($n, 0, 10) == 'wordpress_' || substr($n, 0, 12) == 'wp-postpass_') && !$wp_ffpc_config['cache_loggedin'] ) { - return false; + if ( $wp_ffpc_config['cache_loggedin'] == 0 ) { + if ( (substr($n, 0, 14) == 'wordpressuser_' || substr($n, 0, 10) == 'wordpress_' || substr($n, 0, 12) == 'wp-postpass_') && !$wp_ffpc_config['cache_loggedin'] ) { + return false; + } + } + /* check for any matches to user-added cookies to no-cache */ + if ( ! empty( $nocache_cookies ) ){ + foreach ( $nocache_cookies as $nocache_cookie ) { + if( strpos( $n, $nocache_cookie ) === 0 ) { + return false; + } + } } } } + /* canonical redirect storage */ $wp_ffpc_redirect = null; @@ -146,7 +163,7 @@ if ( !empty( $wp_ffpc_values['meta']['pingback'] ) ) /* for debugging */ if ( $wp_ffpc_config['response_header'] ) - header( 'X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type'] ); + header( 'X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type'] .' via PHP'); /* HTML data */ echo $wp_ffpc_values['data']; diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 811158f..6d841a7 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -391,7 +391,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
- plugin_constant); ?> + If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?>
@@ -420,7 +420,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
options['log_info'],true); ?> /> - plugin_constant); ?> + plugin_constant); ?>
@@ -440,7 +440,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
- +
options['sync_protocols'],true); ?> /> @@ -501,6 +501,14 @@ if ( ! class_exists( 'WP_FFPC' ) ) { options['nocache_page'],true); ?> /> plugin_constant); ?>
+ +
+ +
+
+ + If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?> +
@@ -519,7 +527,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
options['persistent'],true); ?> /> - plugin_constant); ?> + plugin_constant); ?>
@@ -784,6 +792,27 @@ if ( ! class_exists( 'WP_FFPC' ) ) { else $nginx = str_replace ( 'LOGGEDIN_EXCEPTION' , '' , $nginx ); + /* nginx can skip caching for visitors with certain cookies specified in the options */ + if( $this->options['nocache_cookies'] ) { + $cookies = str_replace( ",","|", $this->options['nocache_cookies'] ); + $cookies = str_replace( " ","", $cookies ); + $cookie_exception = '# avoid cache for cookies specified + if ($http_cookie ~* ' . $cookies . ' ) { + set $memcached_request 0; + }'; + $nginx = str_replace ( 'COOKIES_EXCEPTION' , $cookie_exception , $nginx ); + } else { + $nginx = str_replace ( 'COOKIES_EXCEPTION' , '' , $nginx ); + } + + /* add custom response header if specified in the options */ + if( $this->options['response_header'] ){ + $response_header = 'add_header X-Cache-Engine "WP-FFPC with ' . $this->options['cache_type'] .' via nginx";'; + $nginx = str_replace ( 'RESPONSE_HEADER' , $response_header , $nginx ); + } else{ + $nginx = str_replace ( 'RESPONSE_HEADER' , '' , $nginx ); + } + return $nginx; } diff --git a/wp-ffpc-nginx-sample.conf b/wp-ffpc-nginx-sample.conf index 16817f3..372b8f9 100644 --- a/wp-ffpc-nginx-sample.conf +++ b/wp-ffpc-nginx-sample.conf @@ -144,7 +144,10 @@ MEMCACHED_SERVERS LOGGEDIN_EXCEPTION + COOKIES_EXCEPTION + if ( $memcached_request = 1) { + RESPONSE_HEADER memcached_pass memcached-servers; error_page 404 = @rewrites; } @@ -156,6 +159,7 @@ MEMCACHED_SERVERS ## rewrite rules location @rewrites { + add_header X-Cache-Engine ""; rewrite ^ /index.php?$args last; } diff --git a/wp-ffpc.php b/wp-ffpc.php index 6008330..8a18386 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -43,6 +43,7 @@ $wp_ffpc_defaults = array ( 'nocache_archive' => false, 'nocache_single' => false, 'nocache_page' => false, + 'nocache_cookies' => false, 'sync_protocols' => false, 'persistent' => false, 'response_header' => false, From 306462d1458790e7d276a844733015c0cce6cc82 Mon Sep 17 00:00:00 2001 From: Harold Kyle Date: Fri, 19 Apr 2013 16:32:51 -0400 Subject: [PATCH 5/5] trying to roll back cookie changes --- wp-ffpc-acache.php | 25 ++++--------------------- wp-ffpc-class.php | 37 ++++--------------------------------- wp-ffpc-nginx-sample.conf | 4 ---- wp-ffpc.php | 1 - 4 files changed, 8 insertions(+), 59 deletions(-) diff --git a/wp-ffpc-acache.php b/wp-ffpc-acache.php index 23c4da1..6428f8c 100644 --- a/wp-ffpc-acache.php +++ b/wp-ffpc-acache.php @@ -53,34 +53,17 @@ else return false; /* no cache for for logged in users normally, only if enabled */ -if ( $wp_ffpc_config['cache_loggedin'] == 0 || $wp_ffpc_config['nocache_cookies'] ) { - - $nocache_cookies = array(); - if( $wp_ffpc_config['nocache_cookies'] ){ - $nocache_cookies = array_map('trim',explode(",", $wp_ffpc_config['nocache_cookies'] ) ); - } - +if ( $wp_ffpc_config['cache_loggedin'] == 0 ) { foreach ($_COOKIE as $n=>$v) { // test cookie makes to cache not work!!! if ($n == 'wordpress_test_cookie') continue; // wp 2.5 and wp 2.3 have different cookie prefix, skip cache if a post password cookie is present, also - if ( $wp_ffpc_config['cache_loggedin'] == 0 ) { - if ( (substr($n, 0, 14) == 'wordpressuser_' || substr($n, 0, 10) == 'wordpress_' || substr($n, 0, 12) == 'wp-postpass_') && !$wp_ffpc_config['cache_loggedin'] ) { - return false; - } - } - /* check for any matches to user-added cookies to no-cache */ - if ( ! empty( $nocache_cookies ) ){ - foreach ( $nocache_cookies as $nocache_cookie ) { - if( strpos( $n, $nocache_cookie ) === 0 ) { - return false; - } - } + if ( (substr($n, 0, 14) == 'wordpressuser_' || substr($n, 0, 10) == 'wordpress_' || substr($n, 0, 12) == 'wp-postpass_') && !$wp_ffpc_config['cache_loggedin'] ) { + return false; } } } - /* canonical redirect storage */ $wp_ffpc_redirect = null; @@ -163,7 +146,7 @@ if ( !empty( $wp_ffpc_values['meta']['pingback'] ) ) /* for debugging */ if ( $wp_ffpc_config['response_header'] ) - header( 'X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type'] .' via PHP'); + header( 'X-Cache-Engine: WP-FFPC with ' . $wp_ffpc_config['cache_type'] ); /* HTML data */ echo $wp_ffpc_values['data']; diff --git a/wp-ffpc-class.php b/wp-ffpc-class.php index 6d841a7..811158f 100644 --- a/wp-ffpc-class.php +++ b/wp-ffpc-class.php @@ -391,7 +391,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
- If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?> + plugin_constant); ?>
@@ -420,7 +420,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
options['log_info'],true); ?> /> - plugin_constant); ?> + plugin_constant); ?>
@@ -440,7 +440,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
- +
options['sync_protocols'],true); ?> /> @@ -501,14 +501,6 @@ if ( ! class_exists( 'WP_FFPC' ) ) { options['nocache_page'],true); ?> /> plugin_constant); ?>
- -
- -
-
- - If you are caching with nginx, you should update your nginx configuration and reload nginx after changing this value.', $this->plugin_constant); ?> -
@@ -527,7 +519,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
options['persistent'],true); ?> /> - plugin_constant); ?> + plugin_constant); ?>
@@ -792,27 +784,6 @@ if ( ! class_exists( 'WP_FFPC' ) ) { else $nginx = str_replace ( 'LOGGEDIN_EXCEPTION' , '' , $nginx ); - /* nginx can skip caching for visitors with certain cookies specified in the options */ - if( $this->options['nocache_cookies'] ) { - $cookies = str_replace( ",","|", $this->options['nocache_cookies'] ); - $cookies = str_replace( " ","", $cookies ); - $cookie_exception = '# avoid cache for cookies specified - if ($http_cookie ~* ' . $cookies . ' ) { - set $memcached_request 0; - }'; - $nginx = str_replace ( 'COOKIES_EXCEPTION' , $cookie_exception , $nginx ); - } else { - $nginx = str_replace ( 'COOKIES_EXCEPTION' , '' , $nginx ); - } - - /* add custom response header if specified in the options */ - if( $this->options['response_header'] ){ - $response_header = 'add_header X-Cache-Engine "WP-FFPC with ' . $this->options['cache_type'] .' via nginx";'; - $nginx = str_replace ( 'RESPONSE_HEADER' , $response_header , $nginx ); - } else{ - $nginx = str_replace ( 'RESPONSE_HEADER' , '' , $nginx ); - } - return $nginx; } diff --git a/wp-ffpc-nginx-sample.conf b/wp-ffpc-nginx-sample.conf index 372b8f9..16817f3 100644 --- a/wp-ffpc-nginx-sample.conf +++ b/wp-ffpc-nginx-sample.conf @@ -144,10 +144,7 @@ MEMCACHED_SERVERS LOGGEDIN_EXCEPTION - COOKIES_EXCEPTION - if ( $memcached_request = 1) { - RESPONSE_HEADER memcached_pass memcached-servers; error_page 404 = @rewrites; } @@ -159,7 +156,6 @@ MEMCACHED_SERVERS ## rewrite rules location @rewrites { - add_header X-Cache-Engine ""; rewrite ^ /index.php?$args last; } diff --git a/wp-ffpc.php b/wp-ffpc.php index 8a18386..6008330 100644 --- a/wp-ffpc.php +++ b/wp-ffpc.php @@ -43,7 +43,6 @@ $wp_ffpc_defaults = array ( 'nocache_archive' => false, 'nocache_single' => false, 'nocache_page' => false, - 'nocache_cookies' => false, 'sync_protocols' => false, 'persistent' => false, 'response_header' => false,