From 914bcf91c4cc2e00d2a05fff8442ee37512145e1 Mon Sep 17 00:00:00 2001 From: Giuseppe Arcifa Date: Wed, 4 Dec 2024 10:37:58 +0100 Subject: [PATCH] Refactored `Transient::get()` method to reproduce the same WP filters behaviour --- includes/Helpers/Transient.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/includes/Helpers/Transient.php b/includes/Helpers/Transient.php index 196d611..b92d2a1 100644 --- a/includes/Helpers/Transient.php +++ b/includes/Helpers/Transient.php @@ -49,16 +49,17 @@ public static function get( string $key ) { $data = \get_option( $key ); if ( is_array( $data ) && isset( $data['expires_at'], $data['value'] ) ) { if ( $data['expires_at'] > time() ) { - /** - * Implement the filters as used in {@see get_transient()}. - */ - return apply_filters( "transient_{$key}", $data['value'], $key ); + $value = $data['value']; } else { \delete_option( $key ); + $value = false; } } - return false; + /** + * Implement the filters as used in {@see get_transient()}. + */ + return apply_filters( "transient_{$key}", $value, $key ); } /**