Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-super.../plugins
File: dynamic-cache-test.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* On the Advanced Settings page enable "Enable dynamic caching" and clear
[3] Fix | Delete
* the cache.
[4] Fix | Delete
*
[5] Fix | Delete
* Plugin authors: NEVER define the template tag for your users. Make them
[6] Fix | Delete
* choose one so it will be unique to their site.
[7] Fix | Delete
*
[8] Fix | Delete
* There are two examples in this file. Both use template tags that must be
[9] Fix | Delete
* kept secret.
[10] Fix | Delete
*
[11] Fix | Delete
* GLOSSARY:
[12] Fix | Delete
*
[13] Fix | Delete
* Dynamic content: the text or widget you want to show visitors to your site
[14] Fix | Delete
* that changes every time it's viewed.
[15] Fix | Delete
* Placeholder/template tag: the string of random characters placed in your
[16] Fix | Delete
* theme file or printed in an action where the dynamic content will go.
[17] Fix | Delete
* Output buffer (ob): any text that is printed by PHP to be sent to the browser
[18] Fix | Delete
* but captured by PHP for further manipulation.
[19] Fix | Delete
* OB Callback function: A function that is called when the output buffer is
[20] Fix | Delete
* filled with a html page. The contents of the page are passed to the function
[21] Fix | Delete
* for processing.
[22] Fix | Delete
*
[23] Fix | Delete
* **** MAKE SURE YOU KEEP THE TEMPLATE TAG SECRET ****
[24] Fix | Delete
* You should probably add 'deny from all' to the .htaccess in the cache directory
[25] Fix | Delete
* so visitors can't directly load any cached html files and discover the secret
[26] Fix | Delete
* tag. Or you can move the cache directory out of the web path and set the
[27] Fix | Delete
* cache location to that new directory on the advanced settings page.
[28] Fix | Delete
*
[29] Fix | Delete
*/
[30] Fix | Delete
[31] Fix | Delete
/*
[32] Fix | Delete
* EXAMPLE 1
[33] Fix | Delete
* http://ocaoimh.ie/2013/10/21/shiny-new-dynamic-content-wp-super-cache/
[34] Fix | Delete
* Replace a string in your theme with the dynamic content.
[35] Fix | Delete
*
[36] Fix | Delete
* dynamic_cache_test_init()
[37] Fix | Delete
* This function is the first one to be called. This function hooks
[38] Fix | Delete
* dynamic_cache_test_template() to the WordPress action, wp_footer.
[39] Fix | Delete
* This script is loaded before WordPress is and the add_action()
[40] Fix | Delete
* function isn't defined at this time.
[41] Fix | Delete
* This init function hooks onto the cache action "add_cacheaction"
[42] Fix | Delete
* that fires after WordPress (and add_action) is loaded.
[43] Fix | Delete
*
[44] Fix | Delete
*
[45] Fix | Delete
* dynamic_cache_test_template_tag()
[46] Fix | Delete
* This function hooks on to wp_footer and displays the secret template
[47] Fix | Delete
* tag that will be replaced by our dynamic content on each page view.
[48] Fix | Delete
*
[49] Fix | Delete
*
[50] Fix | Delete
* dynamic_cache_test_filter()
[51] Fix | Delete
* This function hooks on to the filter through which all the cached data
[52] Fix | Delete
* sent to visitors is sent.
[53] Fix | Delete
* In this simple example the template tag is replaced by a html comment
[54] Fix | Delete
* containing the text "Hello world at " and the current server time.
[55] Fix | Delete
* If you want to use the output of a WordPress plugin or command you
[56] Fix | Delete
* must enable "late init" on the settings page. Each time you reload
[57] Fix | Delete
* the cached page this time will change. View the page source to examine
[58] Fix | Delete
* this text.
[59] Fix | Delete
*
[60] Fix | Delete
* Chronology of a request:
[61] Fix | Delete
* 1. dynamic_cache_test_init() hooks dynamic_cache_test_template_tag() on
[62] Fix | Delete
* to the wp_footer action. dynamic_cache_test_filter() is hooked on to
[63] Fix | Delete
* the wpsc_cachedata filter.
[64] Fix | Delete
* 2. An output buffer is created by WP Super Cache.
[65] Fix | Delete
* 3. Most of the page is generated by WordPress.
[66] Fix | Delete
* 4. The wp_footer action fires and the TAG is printed to the page.
[67] Fix | Delete
* 5. Processing continues and the page is created.
[68] Fix | Delete
* 6. The output buffer finishes. A WP Super Cache callback function runs
[69] Fix | Delete
* and saves the output buffer to a cache file. The wpsc_cachedata
[70] Fix | Delete
* filter is called.
[71] Fix | Delete
* 7. The function dynamic_cache_test_filter() runs and replaces the TAG in
[72] Fix | Delete
* the buffer with the "Hello world" string.
[73] Fix | Delete
* 8. The output buffer is pushed to the browser to be displayed.
[74] Fix | Delete
*/
[75] Fix | Delete
define( 'DYNAMIC_CACHE_TEST_TAG', '' ); // Change this to a secret placeholder tag.
[76] Fix | Delete
if ( '' !== DYNAMIC_CACHE_TEST_TAG ) {
[77] Fix | Delete
function dynamic_cache_test_safety( $safety ) {
[78] Fix | Delete
return 1;
[79] Fix | Delete
}
[80] Fix | Delete
add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_cache_test_safety' );
[81] Fix | Delete
[82] Fix | Delete
function dynamic_cache_test_filter( $cachedata ) {
[83] Fix | Delete
return str_replace( DYNAMIC_CACHE_TEST_TAG, '<!-- Hello world at ' . date( 'H:i:s' ) . ' -->', $cachedata );
[84] Fix | Delete
}
[85] Fix | Delete
add_cacheaction( 'wpsc_cachedata', 'dynamic_cache_test_filter' );
[86] Fix | Delete
[87] Fix | Delete
function dynamic_cache_test_template_tag() {
[88] Fix | Delete
echo DYNAMIC_CACHE_TEST_TAG; // This is the template tag.
[89] Fix | Delete
}
[90] Fix | Delete
[91] Fix | Delete
function dynamic_cache_test_init() {
[92] Fix | Delete
add_action( 'wp_footer', 'dynamic_cache_test_template_tag' );
[93] Fix | Delete
}
[94] Fix | Delete
add_cacheaction( 'add_cacheaction', 'dynamic_cache_test_init' );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/*
[98] Fix | Delete
* EXAMPLE 2
[99] Fix | Delete
*
[100] Fix | Delete
* This is going to be complicated. Hang on!
[101] Fix | Delete
*
[102] Fix | Delete
* When the cache file for a new page is generated the plugin uses an output
[103] Fix | Delete
* buffer to capture the page. A callback function processes the buffer and
[104] Fix | Delete
* writes to the cache file. The placeholder tag for any dynamic content has
[105] Fix | Delete
* to be written to that cache file but also, it has to be replaced with
[106] Fix | Delete
* dynamic content before the page is shown to the user.
[107] Fix | Delete
* More on output buffers here: http://php.net/ob_start
[108] Fix | Delete
*
[109] Fix | Delete
* Unfortunately an extra output buffer is often required when capturing dynamic
[110] Fix | Delete
* content such as sidebar widgets. Due to a quirk of the way PHP works it's
[111] Fix | Delete
* not possible to have an output buffer run in an output buffer callback. That
[112] Fix | Delete
* dynamic content has to be generated before the callback function is reached.
[113] Fix | Delete
* The following error occurs when an output buffer is created in the
[114] Fix | Delete
* callback function of another output buffer:
[115] Fix | Delete
* "PHP Fatal error: ob_start(): Cannot use output buffering in output buffering display handlers in..."
[116] Fix | Delete
*
[117] Fix | Delete
* In this example the function add_action() isn't available when this file is
[118] Fix | Delete
* loaded so dynamic_output_buffer_init() is hooked on to the "add_cacheaction"
[119] Fix | Delete
* cacheaction. That function then hooks dynamic_output_buffer_test() on to the
[120] Fix | Delete
* familiar wp_footer action.
[121] Fix | Delete
*
[122] Fix | Delete
* The first time dynamic_output_buffer_test() runs it generates the dynamic
[123] Fix | Delete
* content and captures it with ob_start() in the DYNAMIC_OB_TEXT constant.
[124] Fix | Delete
*
[125] Fix | Delete
* When the main WP Super Cache output buffer is ready the callback is called.
[126] Fix | Delete
* This fires the wpsc_cachedata_safety filter. If the DYNAMIC_OB_TEXT constant
[127] Fix | Delete
* is set, which means dynamic content is ready, then it returns 1, a signal
[128] Fix | Delete
* that everything is ok.
[129] Fix | Delete
* Finally, the wpsc_cachedata filter is run. The function
[130] Fix | Delete
* dynamic_output_buffer_test() is hooked on to it. Since DYNAMIC_OB_TEXT is
[131] Fix | Delete
* set it replaces the placeholder text with that constant.
[132] Fix | Delete
* The resulting html is then sent to the browser.
[133] Fix | Delete
*
[134] Fix | Delete
* Already cached pages call the safety filter, and then the wpsc_cachedata
[135] Fix | Delete
* filter so any hooked function must be ready to generate dynamic content. The
[136] Fix | Delete
* very last line of dynamic_output_buffer_test() replaces the placeholder tag
[137] Fix | Delete
* with the dynamic content in the cache file.
[138] Fix | Delete
*
[139] Fix | Delete
* Use an output buffer to capture dynamic content while the page is generated
[140] Fix | Delete
* and insert into the right place:
[141] Fix | Delete
* Remember to add the DYNAMIC_OUTPUT_BUFFER_TAG text (as defined below) to
[142] Fix | Delete
* your theme where the dynamic content should be.
[143] Fix | Delete
*
[144] Fix | Delete
* dynamic_output_buffer_test() is a function that uses the wpsc_cachedata
[145] Fix | Delete
* filter to add a small message and the current server time to every web
[146] Fix | Delete
* page. The time increments on every reload.
[147] Fix | Delete
*
[148] Fix | Delete
*/
[149] Fix | Delete
[150] Fix | Delete
define( 'DYNAMIC_OUTPUT_BUFFER_TAG', '' ); // Change this to a secret placeholder tag.
[151] Fix | Delete
[152] Fix | Delete
if ( '' !== DYNAMIC_OUTPUT_BUFFER_TAG ) {
[153] Fix | Delete
function dynamic_output_buffer_test( $cachedata = 0 ) {
[154] Fix | Delete
if ( defined( 'DYNAMIC_OB_TEXT' ) ) {
[155] Fix | Delete
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, DYNAMIC_OB_TEXT, $cachedata );
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
ob_start();
[159] Fix | Delete
// call the sidebar function, do something dynamic
[160] Fix | Delete
echo '<p>This is a test. The current time on the server is: ' . date( 'H:i:s' ) . '</p>';
[161] Fix | Delete
$text = ob_get_contents();
[162] Fix | Delete
ob_end_clean();
[163] Fix | Delete
[164] Fix | Delete
if ( 0 === $cachedata ) { // called directly from the theme so store the output.
[165] Fix | Delete
define( 'DYNAMIC_OB_TEXT', $text );
[166] Fix | Delete
} else { // called via the wpsc_cachedata filter. We only get here in cached pages in wp-cache-phase1.php.
[167] Fix | Delete
return str_replace( DYNAMIC_OUTPUT_BUFFER_TAG, $text, $cachedata );
[168] Fix | Delete
}
[169] Fix | Delete
}
[170] Fix | Delete
add_cacheaction( 'wpsc_cachedata', 'dynamic_output_buffer_test' );
[171] Fix | Delete
[172] Fix | Delete
function dynamic_output_buffer_init() {
[173] Fix | Delete
add_action( 'wp_footer', 'dynamic_output_buffer_test' );
[174] Fix | Delete
}
[175] Fix | Delete
add_cacheaction( 'add_cacheaction', 'dynamic_output_buffer_init' );
[176] Fix | Delete
[177] Fix | Delete
function dynamic_output_buffer_test_safety( $safety ) {
[178] Fix | Delete
if ( defined( 'DYNAMIC_OB_TEXT' ) ) {// this is set when you call dynamic_output_buffer_test() from the theme.
[179] Fix | Delete
return 1; // ready to replace tag with dynamic content.
[180] Fix | Delete
} else {
[181] Fix | Delete
return 0; // tag cannot be replaced.
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
add_cacheaction( 'wpsc_cachedata_safety', 'dynamic_output_buffer_test_safety' );
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function