Skip to content

Instantly share code, notes, and snippets.

@michael-cannon
Last active December 18, 2015 19:29
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 michael-cannon/5833685 to your computer and use it in GitHub Desktop.
Save michael-cannon/5833685 to your computer and use it in GitHub Desktop.
Filter testimonials_widget_cache_get and testimonials_widget_cache_set example
add_filter( 'testimonials_widget_cache_get', array( $this, 'cache_get' ) );
add_filter( 'testimonials_widget_cache_set', array( $this, 'cache_set' ), 10, 2 );
public static function cache_get( $args ) {
$hash = self::create_hash( $args );
$do_cache = apply_filters( 'testimonials_widget_disable_cache', true );
$no_cache = isset( $args['no_cache'] ) && Testimonials_Widget_Settings::is_true( $args['no_cache'] );
if ( ! $do_cache || $no_cache ) {
delete_transient( $hash );
return false;
}
$data = get_transient( $hash );
return $data;
}
public static function cache_set( $data, $args ) {
$hash = self::create_hash( $args );
set_transient( $hash, $data, self::$cache_period );
return $data;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment