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
Issue boards
Milestones
Wiki
Code
Merge requests
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
wpdesk
wp-basic-requirements
Commits
4f81bddd
Commit
4f81bddd
authored
5 years ago
by
vasili.guruli
Browse files
Options
Downloads
Patches
Plain Diff
Small changes
parent
34881485
No related branches found
No related tags found
1 merge request
!19
Feature/minimum plugin version check demo1
Pipeline
#9680
passed with warnings
5 years ago
Stage: tools
Stage: tests
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Basic_Requirement_Checker.php
+39
-17
39 additions, 17 deletions
src/Basic_Requirement_Checker.php
with
39 additions
and
17 deletions
src/Basic_Requirement_Checker.php
+
39
−
17
View file @
4f81bddd
...
...
@@ -18,6 +18,7 @@
const
PLUGIN_INFO_VERSION
=
'version'
;
const
PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION
=
'0.0'
;
const
PLUGIN_INFO_TRANSIENT_NAME
=
'require_plugins_data'
;
const
PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME
=
0
;
/** @var string */
protected
$plugin_name
;
...
...
@@ -289,8 +290,8 @@
*/
private
function
check_minimum_require_plugins_version_and_append_notices
(
$notices
)
{
if
(
count
(
$this
->
retrieve_require_plugins
()
)
>
0
)
{
foreach
(
$this
->
retrieve_require_plugins
()
as
$plugin
)
{
if
(
count
(
$this
->
retrieve_require
d
_plugins
_data
()
)
>
0
)
{
foreach
(
$this
->
retrieve_require
d
_plugins
_data
()
as
$plugin
)
{
if
(
$plugin
[
ucfirst
(
self
::
PLUGIN_INFO_VERSION
)
]
<
$plugin
[
'required_version'
]
)
{
$notices
[]
=
$this
->
prepare_notice_message
(
sprintf
(
__
(
'The “%s” plugin requires at least %s version of %s to work correctly. Please update it'
,
$this
->
get_text_domain
()
),
esc_html
(
$this
->
plugin_name
),
$plugin
[
'required_version'
],
$plugin
[
ucfirst
(
self
::
PLUGIN_INFO_KEY_NAME
)
]
)
);
...
...
@@ -302,13 +303,11 @@
}
/**
* Check the plugins directory and retrieve all
required
plugin files with plugin data.
* Check the plugins directory and retrieve all plugin files with plugin data.
*
* @return array
*/
private
function
retrieve_require_plugins
()
{
$require_plugins
=
array
();
$plugins
=
array
();
private
function
retrieve_plugins_data
()
{
if
(
function_exists
(
'get_transient'
)
)
{
$plugins
=
get_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
...
...
@@ -318,7 +317,27 @@
require_once
ABSPATH
.
'/wp-admin/includes/plugin.php'
;
}
$plugins
=
get_plugins
();
$plugins
=
function_exists
(
'get_plugins'
)
?
get_plugins
()
:
array
();
set_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
,
self
::
PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME
);
}
return
$plugins
;
}
return
array
();
}
/**
* Check the plugins directory and retrieve all required plugin files with plugin data.
*
* @return array
*/
private
function
retrieve_required_plugins_data
()
{
$require_plugins
=
array
();
if
(
count
(
$this
->
retrieve_plugins_data
()
)
>
0
)
{
$plugins
=
$this
->
retrieve_plugins_data
();
if
(
!
empty
(
$this
->
plugin_require
)
)
{
foreach
(
$this
->
plugin_require
as
$plugin
)
{
...
...
@@ -328,12 +347,9 @@
}
}
}
set_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
,
DAY_IN_SECONDS
);
}
}
return
$plugins
;
return
$
require_
plugins
;
}
/**
...
...
@@ -551,6 +567,8 @@
public
function
handle_deactivate_action
()
{
if
(
isset
(
$this
->
plugin_file
)
)
{
deactivate_plugins
(
plugin_basename
(
$this
->
plugin_file
)
);
delete_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
}
}
...
...
@@ -565,6 +583,10 @@
foreach
(
$this
->
notices
as
$notice
)
{
echo
$notice
;
}
if
(
function_exists
(
'delete_transient'
)
)
{
delete_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
}
}
}
}
\ No newline at end of file
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