Skip to content
Snippets Groups Projects
Commit c1fb927e authored by Grzegorz Rola's avatar Grzegorz Rola
Browse files

feature(transients): as autoloaded options

parent ef5296a8
No related branches found
No related tags found
1 merge request!43feature(transients): as autoloaded options
Pipeline #213780 passed
This commit is part of merge request !43. Comments created here will be created in the context of that merge request.
......@@ -33,6 +33,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
const CACHE_TIME = 16;
const EXPIRATION_TIME = 'expiration_time';
const PLUGINS = 'plugins';
/** @var string */
protected $plugin_name;
......@@ -395,10 +399,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
try {
$plugins_option_value = json_decode( get_option( self::PLUGIN_INFO_TRANSIENT_NAME . '' ), true );
if ( is_array( $plugins_option_value )
&& isset( $plugins_option_value['expiration_time'], $plugins_option_value['plugins'] )
&& (int) $plugins_option_value['expiration_time'] > $current_time
&& 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['plugins'];
return $plugins_option_value[ self::PLUGINS ];
}
} catch ( \RuntimeException $e ) {
// Exception can be thrown when option is not json encoded
......@@ -419,8 +423,8 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, self::CACHE_TIME );
} else {
update_option( self::PLUGIN_INFO_TRANSIENT_NAME, json_encode( array(
'expiration_time' => $current_time + self::CACHE_TIME,
'plugins' => $plugins,
self::EXPIRATION_TIME => $current_time + self::CACHE_TIME,
self::PLUGINS => $plugins,
) ) );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment