diff --git a/CHANGELOG.md b/CHANGELOG.md index 31863922e28691f3d6e9b2a3752a164ed652cc2d..5af358ae90081d473aab6d5e2976581421bb02a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,9 @@ -## [3.5.2] - 2023-02-10 - +## [3.6.0] - 2023-06-22 ### Changed +- Plugin info transient changed to auto loaded option (expiration 0) +## [3.5.2] - 2023-02-10 +### Changed - Removed arrows from user-facing messages. ## [3.5.1] - 2022-08-30 diff --git a/src/Basic_Requirement_Checker.php b/src/Basic_Requirement_Checker.php index e942fff8eb0b035898fe8b16a7cc20eabad5f70c..818046552ddd297ec628f59f4422eb01411185ba 100644 --- a/src/Basic_Requirement_Checker.php +++ b/src/Basic_Requirement_Checker.php @@ -21,9 +21,10 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { const PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION = '0.0'; const PLUGIN_INFO_APPEND_PLUGIN_DATA = 'required_version'; const PLUGIN_INFO_TRANSIENT_NAME = 'require_plugins_data'; - const PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME = 16; + const EXPIRATION_TRANSIENT_NAME = 'require_plugins_data_exp'; + const CACHE_TIME = 300; - /** @var string */ + /** @var string */ protected $plugin_name; /** @var string */ private $plugin_file; @@ -324,29 +325,32 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { * @return array In format [ 'plugindir/pluginfile.php' => ['Name' => 'Plugin Name', 'Version' => '1.0.1', ...], ] */ private static function retrieve_plugins_data_in_transient() { - static $never_executed = true; - if ( $never_executed ) { - $never_executed = false; - /** Required when WC starts later and these data should be in cache */ - add_filter( 'extra_plugin_headers', function ( $headers = array() ) { - $headers[] = 'WC tested up to'; - $headers[] = 'WC requires at least'; - $headers[] = 'Woo'; - - return array_unique( $headers ); - } ); - } - + $current_time = time(); $plugins = get_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); + $expiration_time = get_transient( self::EXPIRATION_TRANSIENT_NAME ); + $is_expired = ! $expiration_time || $current_time > $expiration_time; + + if ( $plugins === false || $is_expired ) { + static $never_executed = true; + if ( $never_executed ) { + $never_executed = false; + /** Required when WC starts later and these data should be in cache */ + add_filter( 'extra_plugin_headers', function ( $headers = array() ) { + $headers[] = 'WC tested up to'; + $headers[] = 'WC requires at least'; + $headers[] = 'Woo'; + + return array_unique( $headers ); + } ); + } - if ( $plugins === false ) { if ( ! function_exists( 'get_plugins' ) ) { require_once ABSPATH . '/wp-admin/includes/plugin.php'; } $plugins = function_exists( 'get_plugins' ) ? get_plugins() : array(); - set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, - self::PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME ); + set_transient( self::PLUGIN_INFO_TRANSIENT_NAME, $plugins, 0 ); + set_transient( self::EXPIRATION_TRANSIENT_NAME, $current_time + self::CACHE_TIME , 0 ); } return $plugins; @@ -615,6 +619,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { */ public function handle_transient_delete_action() { delete_transient( self::PLUGIN_INFO_TRANSIENT_NAME ); + delete_transient( self::EXPIRATION_TRANSIENT_NAME ); } /**