Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wp-basic-requirements
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-basic-requirements
Commits
b293acfb
Commit
b293acfb
authored
1 year ago
by
Grzegorz Rola
Browse files
Options
Downloads
Patches
Plain Diff
feature(transients): as autoloaded options
parent
c7af1af2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!43
feature(transients): as autoloaded options
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+2
-2
2 additions, 2 deletions
CHANGELOG.md
src/Basic_Requirement_Checker.php
+48
-22
48 additions, 22 deletions
src/Basic_Requirement_Checker.php
with
50 additions
and
24 deletions
CHANGELOG.md
+
2
−
2
View file @
b293acfb
## [3.6.
0
] - 2023-06-22
## [3.6.
1
] - 2023-06-22
### Changed
-
Plugin info transient changed to auto loaded option
(expiration 0)
-
Plugin info transient changed to auto loaded option
## [3.5.2] - 2023-02-10
### Changed
...
...
This diff is collapsed.
Click to expand it.
src/Basic_Requirement_Checker.php
+
48
−
22
View file @
b293acfb
...
...
@@ -29,11 +29,13 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
const
PLUGIN_INFO_APPEND_PLUGIN_DATA
=
'required_version'
;
const
PLUGIN_INFO_TRANSIENT_NAME
=
'wpdesk_plugins_data'
;
const
PLUGIN_INFO_TRANSIENT_NAME
=
'wpdesk_
requirements_
plugins_data'
;
const
EXPIRATION_TRANSIENT_NAME
=
'wpdesk_plugins_data_exp'
;
const
CACHE_TIME
=
16
;
const
CACHE_TIME
=
300
;
const
EXPIRATION_TIME
=
'expiration_time'
;
const
PLUGINS
=
'plugins'
;
/** @var string */
protected
$plugin_name
;
...
...
@@ -355,17 +357,10 @@ 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
(
$use_transients
=
true
)
{
$current_time
=
time
();
if
(
$use_transients
)
{
$plugins
=
get_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
$expiration_time
=
get_transient
(
self
::
EXPIRATION_TRANSIENT_NAME
);
}
else
{
$plugins
=
get_option
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
$expiration_time
=
get_option
(
self
::
EXPIRATION_TRANSIENT_NAME
);
}
$is_expired
=
!
$expiration_time
||
$current_time
>
$expiration_time
;
$current_time
=
time
();
$plugins
=
self
::
get_plugins_data_from_cache
(
$use_transients
,
$current_time
);
if
(
$plugins
===
false
||
$is_expired
)
{
if
(
$plugins
===
false
)
{
static
$never_executed
=
true
;
if
(
$never_executed
)
{
$never_executed
=
false
;
...
...
@@ -384,18 +379,51 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
}
$plugins
=
function_exists
(
'get_plugins'
)
?
get_plugins
()
:
array
();
if
(
$use_transients
)
{
set_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
,
0
);
set_transient
(
self
::
EXPIRATION_TRANSIENT_NAME
,
$current_time
+
self
::
CACHE_TIME
,
0
);
}
else
{
update_option
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
);
update_option
(
self
::
EXPIRATION_TRANSIENT_NAME
,
$current_time
+
self
::
CACHE_TIME
);
}
self
::
update_plugins_data_in_cache
(
$plugins
,
$use_transients
,
$current_time
);
}
return
$plugins
;
}
/**
* @param bool $use_transients
* @param int $current_time
*
* @return array|false
*/
private
static
function
get_plugins_data_from_cache
(
$use_transients
,
$current_time
)
{
if
(
$use_transients
)
{
return
get_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
}
else
{
$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
];
}
}
return
false
;
}
/**
* @param array $plugins
* @param bool $use_transients
* @param int $current_time
*/
private
static
function
update_plugins_data_in_cache
(
$plugins
,
$use_transients
,
$current_time
)
{
if
(
$use_transients
)
{
set_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
,
self
::
CACHE_TIME
);
}
else
{
update_option
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
array
(
self
::
EXPIRATION_TIME
=>
$current_time
+
self
::
CACHE_TIME
,
self
::
PLUGINS
=>
$plugins
,
)
);
}
}
/**
* Check the plugins directory and retrieve all required plugin files with plugin data.
*
...
...
@@ -674,9 +702,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) {
*/
public
function
clear_plugin_info_data
()
{
delete_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
delete_transient
(
self
::
EXPIRATION_TRANSIENT_NAME
);
delete_option
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
delete_option
(
self
::
EXPIRATION_TRANSIENT_NAME
);
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment