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
34881485
You need to sign in or sign up before continuing.
Commit
34881485
authored
5 years ago
by
vasili.guruli
Browse files
Options
Downloads
Patches
Plain Diff
Small fixes / Optimization
parent
8a219ac1
No related branches found
No related tags found
1 merge request
!19
Feature/minimum plugin version check demo1
Pipeline
#9649
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
+29
-23
29 additions, 23 deletions
src/Basic_Requirement_Checker.php
with
29 additions
and
23 deletions
src/Basic_Requirement_Checker.php
+
29
−
23
View file @
34881485
...
...
@@ -16,7 +16,8 @@
const
PLUGIN_INFO_KEY_NICE_NAME
=
'nice_name'
;
const
PLUGIN_INFO_KEY_NAME
=
'name'
;
const
PLUGIN_INFO_VERSION
=
'version'
;
const
PLUGIN_INFO_REQUIRED_VERSION
=
'required_version'
;
const
PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION
=
'0.0'
;
const
PLUGIN_INFO_TRANSIENT_NAME
=
'require_plugins_data'
;
/** @var string */
protected
$plugin_name
;
...
...
@@ -117,7 +118,8 @@
$this
->
plugin_require
[
$plugin_name
]
=
array
(
self
::
PLUGIN_INFO_KEY_NAME
=>
$plugin_name
,
self
::
PLUGIN_INFO_KEY_NICE_NAME
=>
$nice_plugin_name
===
null
?
$plugin_name
:
$nice_plugin_name
,
self
::
PLUGIN_INFO_VERSION
=>
$plugin_require_version
===
null
?
'0.0'
:
$plugin_require_version
,
self
::
PLUGIN_INFO_VERSION
=>
$plugin_require_version
===
null
?
self
::
PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION
:
$plugin_require_version
,
);
return
$this
;
...
...
@@ -135,7 +137,7 @@
public
function
add_plugin_repository_require
(
$plugin_name
,
$version
,
$nice_plugin_name
=
null
)
{
$this
->
plugin_require
[
$plugin_name
]
=
array
(
self
::
PLUGIN_INFO_KEY_NAME
=>
$plugin_name
,
'version'
=>
$version
,
self
::
PLUGIN_INFO_VERSION
=>
$version
,
'repository_url'
=>
'http://downloads.wordpress.org/plugin/'
.
dirname
(
$plugin_name
)
.
'.latest-stable.zip'
,
self
::
PLUGIN_INFO_KEY_NICE_NAME
=>
$nice_plugin_name
===
null
?
$plugin_name
:
$nice_plugin_name
);
...
...
@@ -208,7 +210,7 @@
$notices
=
$this
->
append_plugin_require_notices
(
$notices
);
$notices
=
$this
->
append_module_require_notices
(
$notices
);
$notices
=
$this
->
append_settings_require_notices
(
$notices
);
$notices
=
$this
->
check_minimum_require_plugins_version_and_
display
_notices
(
$notices
);
$notices
=
$this
->
check_minimum_require_plugins_version_and_
append
_notices
(
$notices
);
return
$notices
;
}
...
...
@@ -285,13 +287,13 @@
*
* @return array
*/
private
function
check_minimum_require_plugins_version_and_
display
_notices
(
$notices
)
{
private
function
check_minimum_require_plugins_version_and_
append
_notices
(
$notices
)
{
if
(
$this
->
require_plugins
()
>
0
)
{
foreach
(
$this
->
require_plugins
()
as
$plugin
)
{
if
(
$plugin
[
ucfirst
(
self
::
PLUGIN_INFO_VERSION
)
]
<
$plugin
[
self
::
PLUGIN_INFO_REQUIRED_VERSION
]
)
{
if
(
count
(
$this
->
retrieve_
require_plugins
()
)
>
0
)
{
foreach
(
$this
->
retrieve_
require_plugins
()
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
[
self
::
PLUGIN_INFO_REQUIRED_VERSION
],
$plugin
[
ucfirst
(
self
::
PLUGIN_INFO_KEY_NAME
)
]
)
);
esc_html
(
$this
->
plugin_name
),
$plugin
[
'required_version'
],
$plugin
[
ucfirst
(
self
::
PLUGIN_INFO_KEY_NAME
)
]
)
);
}
}
}
...
...
@@ -304,30 +306,34 @@
*
* @return array
*/
p
ublic
function
require_plugins
()
{
p
rivate
function
retrieve_
require_plugins
()
{
$require_plugins
=
array
();
$plugins
=
array
();
if
(
file_exists
(
ABSPATH
.
'/wp-admin/includes/plugin.php'
)
)
{
if
(
function_exists
(
'get_transient'
)
)
{
$plugins
=
get_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
);
if
(
false
===
$plugins
)
{
if
(
!
function_exists
(
'get_plugins'
)
)
{
require_once
ABSPATH
.
'/wp-admin/includes/plugin.php'
;
}
$get_existing_plugins
=
(
get_plugins
()
?
get_plugins
()
:
array
()
);
$plugins
=
get_plugins
();
if
(
!
empty
(
$this
->
plugin_require
)
)
{
foreach
(
$this
->
plugin_require
as
$plugin
)
{
if
(
!
isset
(
$plugin
[
self
::
PLUGIN_INFO_VERSION
]
)
)
{
unset
(
$this
->
plugin_require
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
]
);
}
else
{
if
(
self
::
is_wp_plugin_active
(
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
)
)
{
$require_plugins
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
]
=
$get_existing_
plugins
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
];
$require_plugins
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
][
self
::
PLUGIN_INFO_REQUIRED_VERSION
]
=
$plugin
[
self
::
PLUGIN_INFO_VERSION
];
$require_plugins
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
]
=
$
plugins
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
];
$require_plugins
[
$plugin
[
self
::
PLUGIN_INFO_KEY_NAME
]
][
'required_version'
]
=
$plugin
[
self
::
PLUGIN_INFO_VERSION
];
}
}
}
set_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
,
DAY_IN_SECONDS
);
}
}
return
$
require_
plugins
;
return
$plugins
;
}
/**
...
...
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