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

feature(transients): as autoloaded options

parent 97c47f4e
No related branches found
No related tags found
1 merge request!42Feature/transients
Pipeline #213584 failed
## [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
......
......@@ -21,7 +21,8 @@ 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 */
protected $plugin_name;
......@@ -324,6 +325,12 @@ 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() {
$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;
......@@ -337,16 +344,13 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
} );
}
$plugins = get_transient( self::PLUGIN_INFO_TRANSIENT_NAME );
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 );
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment