Skip to content

Instantly share code, notes, and snippets.

@patricksimpson
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patricksimpson/9310549 to your computer and use it in GitHub Desktop.
Save patricksimpson/9310549 to your computer and use it in GitHub Desktop.
The example script for dynamic functions in the updated super-cache (1.4)
<?php
/* NEW DYNAMIC FUNCTION */
define( 'OAM_DYNAMIC_YOUR_FUNCTION', 'CACHE_OAM_YOUR_TAG');
function OAM_your_function_filter( &$cachedata = 0) {
if (defined('OAM_DYNAMIC_YOUR_FUNCTION_TEXT'))
return str_replace( OAM_DYNAMIC_YOUR_FUNCTION, OAM_DYNAMIC_YOUR_FUNCTION_TEXT, $cachedata);
$text = OAM_your_function_filter_output();
if ( $cachedata === 0 )
define('OAM_DYNAMIC_YOUR_FUNCTION_TEXT', $text);
else
return str_replace( OAM_DYNAMIC_YOUR_FUNCTION, $text, $cachedata );
}
if(function_exists('add_cacheaction')) {
add_cacheaction( 'wpsc_cachedata', 'OAM_your_function_filter' );
}
function OAM_your_function_filter_output() {
$buffer = "";
ob_start();
echo "Dynamic output!";
//You can call wp functions, or other plugin functions.
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
function OAM_your_function_safety( $safety ) {
if ( defined('OAM_DYNAMIC_YOUR_FUNCTION_TEXT'))
return 1;
else
return 0;
}
if(function_exists('add_cacheaction')) {
add_cacheaction('wpsc_cachedata_safety', 'OAM_your_function_safety');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment