From b054b952bc853362c49c7a61e4f75b1511eb3a7b Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Tue, 6 Oct 2015 14:10:00 +0000 Subject: [PATCH] Transients, add filters for `$expiration`: * `'expiration_pre_set_site_transient_' . $transient` * `'expiration_pre_set_transient_' . $transient` Props chriscct7, wpsmith, nacin. Fixes #21330. git-svn-id: https://develop.svn.wordpress.org/trunk@34865 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/option.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/wp-includes/option.php b/src/wp-includes/option.php index 701e485cf9..4ee24fdf4b 100644 --- a/src/wp-includes/option.php +++ b/src/wp-includes/option.php @@ -695,6 +695,19 @@ function set_transient( $transient, $value, $expiration = 0 ) { */ $value = apply_filters( 'pre_set_transient_' . $transient, $value, $expiration, $transient ); + /** + * Filter the expiration for a transient before its value is set. + * + * The dynamic portion of the hook name, `$transient`, refers to the transient name. + * + * @since 4.4.0 + * + * @param mixed $value New value of transient. + * @param int $expiration Time until expiration in seconds. + * @param string $transient Transient name. + */ + $expiration = apply_filters( 'expiration_pre_set_transient_' . $transient, $expiration, $value, $transient ); + if ( wp_using_ext_object_cache() ) { $result = wp_cache_set( $transient, $value, 'transient', $expiration ); } else { @@ -1589,6 +1602,19 @@ function set_site_transient( $transient, $value, $expiration = 0 ) { $expiration = (int) $expiration; + /** + * Filter the expiration for a transient before its value is set. + * + * The dynamic portion of the hook name, `$transient`, refers to the transient name. + * + * @since 4.4.0 + * + * @param mixed $value New value of transient. + * @param int $expiration Time until expiration in seconds. + * @param string $transient Transient name. + */ + $expiration = apply_filters( 'expiration_pre_set_site_transient_' . $transient, $expiration, $value, $transient ); + if ( wp_using_ext_object_cache() ) { $result = wp_cache_set( $transient, $value, 'site-transient', $expiration ); } else {