From 04a39428edfb67a12a697893c971d96e2f583fe5 Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Thu, 22 Jun 2023 18:56:29 +0200 Subject: [PATCH] feature(transients): as autoloaded options --- src/Basic_Requirement_Checker.php | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Basic_Requirement_Checker.php b/src/Basic_Requirement_Checker.php index 0fc063e..6b5a6e0 100644 --- a/src/Basic_Requirement_Checker.php +++ b/src/Basic_Requirement_Checker.php @@ -396,17 +396,12 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { if ( $use_transients ) { return get_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); } else { - try { - $plugins_option_value = json_decode( get_option( self::PLUGIN_INFO_TRANSIENT_NAME, '' ), true ); - if ( is_array( $plugins_option_value ) - && isset( $plugins_option_value[ self::EXPIRATION_TIME ], $plugins_option_value[ self::PLUGINS ] ) - && (int) $plugins_option_value[ self::EXPIRATION_TIME ] > $current_time - ) { - return $plugins_option_value[ self::PLUGINS ]; - } - } catch ( \RuntimeException $e ) { - // Exception can be thrown when option is not json encoded - // Do nothing + $plugins_option_value = get_option( self::PLUGIN_INFO_TRANSIENT_NAME ); + if ( is_array( $plugins_option_value ) + && isset( $plugins_option_value[ self::EXPIRATION_TIME ], $plugins_option_value[ self::PLUGINS ] ) + && (int) $plugins_option_value[ self::EXPIRATION_TIME ] > $current_time + ) { + return $plugins_option_value[ self::PLUGINS ]; } } @@ -422,12 +417,11 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { if ( $use_transients ) { set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, self::CACHE_TIME ); } else { - update_option( self::PLUGIN_INFO_TRANSIENT_NAME, json_encode( array( + update_option( self::PLUGIN_INFO_TRANSIENT_NAME, array( self::EXPIRATION_TIME => $current_time + self::CACHE_TIME, self::PLUGINS => $plugins, - ) ) ); + ) ); } - } /** -- GitLab