Last active
August 29, 2015 13:56
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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