Skip to content

Instantly share code, notes, and snippets.

@westonruter
Created January 28, 2014 08:09
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save westonruter/8663817 to your computer and use it in GitHub Desktop.
<?php
add_action( 'init', function () {
global $shortcode_tags;
foreach ( $shortcode_tags as $tag => $function ) {
$shortcode_tags[$tag] = function ( $attr, $content = null ) use ( $tag, $function ) {
$expires = 60;
$expires = apply_filters( 'shortcode_cache_expires', $expires, $tag );
$cache_key = $tag . md5( serialize( $attr ) ) . get_the_ID();
$cached = wp_cache_get( $cache_key );
if ( $cached === false ) {
ob_start();
call_user_func( $function, $attr, $content );
$cached = ob_get_clean();
wp_cache_set( $cache_key, $cached, null, $expires );
}
echo $cached;
};
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment