Last active
December 18, 2015 19:29
-
-
Save michael-cannon/5833685 to your computer and use it in GitHub Desktop.
Filter testimonials_widget_cache_get and testimonials_widget_cache_set example
This file contains 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
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