Skip to content

Commit

Permalink
ver 1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Richmond committed Oct 29, 2013
1 parent 5089bd1 commit ef80e12
Show file tree
Hide file tree
Showing 11 changed files with 3,550 additions and 6,361 deletions.
5,827 changes: 105 additions & 5,722 deletions Changelog.txt

Large diffs are not rendered by default.

Binary file added languages/wp-super-cache-sr_RS.mo
Binary file not shown.
2,686 changes: 2,686 additions & 0 deletions languages/wp-super-cache-sr_RS.po

Large diffs are not rendered by default.

113 changes: 113 additions & 0 deletions plugins/dynamic-cache-test.php
@@ -0,0 +1,113 @@
<?php

/*
* A function that uses the wpsc_cachedata filter to add a small message
* and the current server time to every web page. The time increments
* on every reload.
*
* On the Advanced Settings page enable "Enable dynamic caching".
*
* dynamic_cache_test_init()
* This function is the first one to be called. This function hooks
* dynamic_cache_test_template() to the WordPress action, wp_footer.
* This script is loaded before WordPress is and the add_action()
* function isn't defined at this time.
* This init function hooks onto the cache action "add_cacheaction"
* that fires after WordPress (and add_action) is loaded.
*
*
* dynamic_cache_test_template_tag()
* This function hooks on to wp_footer and displays the secret template
* tag that will be replaced by our dynamic content on each page view.
*
*
* dynamic_cache_test_filter()
* This function hooks on to the filter through which all the cached data
* sent to visitors is sent.
* In this simple example the template tag is replaced by a html comment
* containing the text "Hello world at " and the current server time.
* If you want to use the output of a WordPress plugin or command you
* must enable "late init" on the settings page. Each time you reload
* the cached page this time will change. View the page source to examine
* this text.
*
* Plugin authors: NEVER define the template tag for your users. Make them
* choose one so it will be unique to their site.
*
* **** MAKE SURE YOU KEEP THE TEMPLATE TAG SECRET ****
*
*/


/*
* Uncomment the code below, enable dynamic caching on the Advanced Settings
* page and clear the cache.
* Be sure to define DYNAMIC_CACHE_TEST_TAG too. Make it a random string
* that will never appear on your website. In your own application this
* tag can be whatever you like.
*/

/*
define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // CHANGE THIS!
define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // CHANGE THIS!
if ( DYNAMIC_CACHE_TEST_TAG == '' )
return false;
// To use an output buffer when generating the dynamic section of your web page
// you must generate the HTML/JS/CSS and store it before the page is completed.
// That stored text is used by the wpsc_cachedata filter later when the same
// function is called again.
// You must also create a safety function. This function checks that your newly
// cached page is ready to be processed by the wpsc_cachedata filter. It's not
// required for already cached pages.
// See dynamic_output_buffer_test_safety() for an example. You must add this
// to avoid the following error:
// "PHP Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in..."
//
// Steps to run example plugin:
// 1. Add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined above) to your theme where the dynamic content should be.
// 2. Call dynamic_output_buffer_test() from your theme or an action like wp_footer
// 3. Clear all cached files.
function dynamic_output_buffer_test( &$cachedata = 0 ) {
if ( defined( 'DYNAMIC_OB_TEXT' ) )
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
ob_start();
// call the sidebar function, do something dynamic
echo "<p>This is a test. The current time on the server is: " . date( 'H:i:s' ) . "</p>";
$text = ob_get_contents();
ob_end_clean();
if ( $cachedata === 0 ) // called directly from the theme so store the output
define( 'DYNAMIC_OB_TEXT', $text );
else // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
}
add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
function dynamic_output_buffer_test_safety( $safety ) {
if ( defined( 'DYNAMIC_OB_TEXT' ) )
return 1; // ready to replace tag with dynamic content.
else
return 0; // tag cannot be replaced.
}
add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
function dynamic_cache_test_filter( &$cachedata) {
return str_replace( DYNAMIC_CACHE_TEST_TAG, "<!-- Hello world at " . date( 'H:i:s' ) . " -->", $cachedata );
}
add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
function dynamic_cache_test_template_tag() {
echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag
}
function dynamic_cache_test_init() {
add_action( 'wp_footer', 'dynamic_cache_test_template_tag' );
}
add_cacheaction( 'add_cacheaction', 'dynamic_cache_test_init' );
*/
?>
4 changes: 2 additions & 2 deletions plugins/searchengine.php
Expand Up @@ -8,9 +8,9 @@ function wp_supercache_searchengine( $string ) {
if( $string != '' )
return $string;

if( $_COOKIE[ '7a1254cba80da02d5478d91cfd0a873a' ] == 1 ) {
if( isset( $_COOKIE[ '7a1254cba80da02d5478d91cfd0a873a' ] ) && $_COOKIE[ '7a1254cba80da02d5478d91cfd0a873a' ] == 1 ) {
$string = 'searchengine';
} elseif( $_SERVER[ 'HTTP_REFERER' ] != '' ) {
} elseif( isset( $_SERVER[ 'HTTP_REFERER' ] ) && $_SERVER[ 'HTTP_REFERER' ] != '' ) {
if( is_array( $passingthrough ) == false )
return $string;

Expand Down
70 changes: 22 additions & 48 deletions readme.txt
@@ -1,8 +1,8 @@
=== WP Super Cache ===
Contributors: donncha, automattic
Tags: performance,caching,wp-cache,wp-super-cache,cache
Tested up to: 3.5.1
Stable tag: 1.3.2
Tested up to: 3.6.1
Stable tag: 1.4
Requires at least: 3.0

A very fast caching engine for WordPress that produces static html files.
Expand Down Expand Up @@ -56,10 +56,16 @@ The cache directory, usually wp-content/cache/ is only for temporary files. Do n

== Upgrade Notice ==

= 1.3.2 =
IMPORTANT - Dynamic cached content now disabled by default. See advanced settings page. Better mangling of the mfunc tag in comments. Jetpack Mobile Theme support.
= 1.4 =
Dynamic cached content now disabled by default. mfunc replaced by wpsc_cachedata filter. Read http://ocaoimh.ie/y/6j before updating if you use mfunc/mclude/dynamic-cached-content.

== Changelog ==
= 1.4 =
* Replace legacy mfunc/mnclude/dynamic-cached-content functionality with a "wpsc_cachedata" cacheaction filter.
* Added dynamic-cache-test.php plugin example wpsc_cachedata filter plugin.
* Delete post, tag and category cache when a post changes from draft to publish or vice versa. Props @Biranit.
* Update advanced-cache.php and wp-config.php if wp-cache-phase1.php doesn't load, usually happening after migrating to a new hosting service.
* Misc bugfixes.

= 1.3.2 =
* Any mfunc/mclude/dynamic-cached-content tags in comments are now removed.
Expand Down Expand Up @@ -375,60 +381,27 @@ No, it will do the opposite. Super Cache files are compressed and stored that wa

= How do I make certain parts of the page stay dynamic? =

Note: from version 1.4 this functionality will be disabled by default. You will have to enable it on the settings page.
Note: this functionality is disabled by default. You will have to enable it on the Advanced Settings page.

There are 2 ways of doing this. You can use Javascript to draw the part of the page you want to keep dynamic. That's what Google Adsense and many widgets from external sites do. Or you can use a WP Super Cache tag to do the job but you can't use mod_rewrite mode caching. You have to switch to PHP or legacy caching.
There are 2 ways of doing this. You can use Javascript to draw the part of the page you want to keep dynamic. That's what Google Adsense and many widgets from external sites do and is the recommended way. Or you can use a WP Super Cache filter to do the job but you can't use mod_rewrite mode caching. You have to switch to PHP or legacy caching.

There are a few ways to do this, you can have functions that stay dynamic or you can include other files on every page load. To execute PHP code on every page load you can use either the "dynamic-cached-content", "mfunc", or "mclude" tags. The "dynamic-cached-content" tag is easier to use but the other tags can still be used. Make sure you duplicate the PHP code when using these tags. The first code is executed when the page is cached, while the second chunk of code is executed when the cached page is served to the next visitor.
WP Super Cache 1.4 introduced a cacheaction filter called wpsc_cachedata. The cached page to be displayed goes through this filter and allows modification of the page. If the page contains a placeholder tag the filter can be used to replace that tag with your dynamically generated html.
The function that hooks on to the wpsc_cachedata filter should be put in a file in the WP Super Cache plugins folder unless you use the late_init feature. An example plugin is included. Edit [dynamic-cache-test.php](http://svn.wp-plugins.org/wp-super-cache/trunk/plugins/dynamic-cache-test.php) to see the example code.
There are two example functions there. There's a simple function that replaces a string (or tag) you define when the cached page is served. The other example function uses an output buffer to generate the dynamic content. Due to a limitation in how PHP works the output buffer code MUST run before the wpsc_cachedata filter is hit, at least for when a page is cached. It doesn't matter when serving cached pages. See [this post](http://ocaoimh.ie/y/6j) for a more technical and longer explanation.
To execute WordPress functions you must enable the 'Late init' feature on the advanced settings page.

= dynamic-cached-content example =

This code will include the file adverts.php and will execute the functions "print_sidebar_ad()" and "do_more_stuff()". Make sure there's no space before or after the PHP tags.

`<!--dynamic-cached-content--><?php
include_once( ABSPATH . '/scripts/adverts.php' );
print_sidebar_ad();
do_more_stuff();
?><!--
include_once( ABSPATH . '/scripts/adverts.php' );
print_sidebar_ad();
do_more_stuff();
--><!--/dynamic-cached-content-->`

= mfunc example =

To execute the function "function_name()":

`<!--mfunc function_name( 'parameter', 'another_parameter' ) -->
<?php function_name( 'parameter', 'another_parameter' ) ?>
<!--/mfunc-->`

= mclude example =
To include another file:

`<!--mclude file.php-->
<?php include_once( ABSPATH . 'file.php' ); ?>
<!--/mclude-->`

That will include file.php under the ABSPATH directory, which is the same as where your wp-config.php file is located.

Example:
`<!--mfunc date( 'Y-m-d H:i:s' ) -->
<?php date( 'Y-m-d H:i:s' ) ?>
<!--/mfunc-->`

= How do I use WordPress functions in cached dynamic pages? =

See the next qestion, you have to load WordPress before the cached file is served.

= How do I delay serving the cache until the "init" action fires? =

Cached files are served before almost all of WordPress is loaded. While that's great for performance it's a pain when you want to extend the plugin using a core part of WordPress. Set $wp_super_cache_late_init to "1" in wp-content/wp-cache-config.php and cached files will be served when "init" fires. WordPress and it's plugins will be loaded now. This is very useful when you are using the mfunc tag in your theme.
Cached files are served before almost all of WordPress is loaded. While that's great for performance it's a pain when you want to extend the plugin using a core part of WordPress. Enable 'Late init' mode on the Advanced settings page and cached files will be served when "init" fires. WordPress and it's plugins will be loaded now.

= Why don't WP UserOnline, Popularity Contest, WP Postratings or plugin X not work or update on my blog now? =

This plugin caches entire pages but some plugins think they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript/AJAX methods or the dynamic-cached-content/mfunc/mclude code described in the previous answer to update or display dynamic information.
This plugin caches entire pages but some plugins think they can run PHP code every time a page loads. To fix this, the plugin needs to use Javascript/AJAX methods or the wpsc_cachedata filter described in the previous answer to update or display dynamic information.

= Why do my WP Super Cache plugin disappear when I upgrade the plugin? =

WordPress deletes the plugin folder when it updates a plugin. This is the same with WP Super Cache so any modified files in wp-super-cache/plugins/ will be deleted. You can define the variable $wp_cache_plugins_dir in wp-config.php or wp-content/wp-cache-config.php and point it at a directory outside of the wp-super-cache folder. The plugin will look there for it's plugins.

= What does the Cache Rebuild feature do? =

Expand Down Expand Up @@ -590,3 +563,4 @@ Translators who did a great job converting the text of the plugin to their nativ
* [Nata Strazda](http://www.webhostingrating.com/) (Lithuanian)
* [Alexander Alexandrov](http://www.designcontest.com/) (Belarusian)
* [Michail Bogdanov](http://www.webhostinghub.com/) (Romanian)
* [Anja Skrba](http://science.webhostinggeeks.com/wordpress-super-cache) (Serbo-Croatian)
2 changes: 2 additions & 0 deletions wp-cache-base.php
Expand Up @@ -19,6 +19,8 @@ class CacheMeta {
if( defined( 'SUBDOMAIN_INSTALL' ) && constant( 'SUBDOMAIN_INSTALL' ) == true ) {
$blogcacheid = $WPSC_HTTP_HOST;
} else {
if ( isset( $base ) == false )
$base = '';
$request_uri = preg_replace('/[ <>\'\"\r\n\t\(\)]/', '', str_replace( '..', '', $_SERVER['REQUEST_URI'] ) );
if( strpos( $request_uri, '/', 1 ) ) {
if( $base == '/' ) {
Expand Down

0 comments on commit ef80e12

Please sign in to comment.