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
45b639a3
Commit
45b639a3
authored
5 years ago
by
vasili.guruli
Browse files
Options
Downloads
Patches
Plain Diff
Unit test fix, plus some code correction
parent
aa142ffb
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!19
Feature/minimum plugin version check demo1
Pipeline
#9910
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
-47
29 additions, 47 deletions
src/Basic_Requirement_Checker.php
with
29 additions
and
47 deletions
src/Basic_Requirement_Checker.php
+
29
−
47
View file @
45b639a3
...
...
@@ -17,10 +17,9 @@
const
PLUGIN_INFO_KEY_NAME
=
'name'
;
const
PLUGIN_INFO_VERSION
=
'version'
;
const
PLUGIN_INFO_FAKE_REQUIRED_MINIMUM_VERSION
=
'0.0'
;
const
PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME
=
0
;
const
PLUGIN_INFO_APPEND_PLUGIN_DATA
=
'required_version'
;
const
PLUGIN_INFO_
REQUIRED_PLUGINS_
TRANSIENT_NAME
=
'require_plugins_data'
;
const
PLUGIN_INFO_
IS_WP_PLUGIN_INSTALLED_TRANSIENT_NAME
=
'is_wp_plugin_installed'
;
const
PLUGIN_INFO_TRANSIENT_NAME
=
'require_plugins_data'
;
const
PLUGIN_INFO_
TRANSIENT_EXPIRATION_TIME
=
0
;
/** @var string */
protected
$plugin_name
;
...
...
@@ -285,16 +284,6 @@
return
defined
(
'OPENSSL_VERSION_NUMBER'
)
&&
OPENSSL_VERSION_NUMBER
>
(
int
)
$required_version
;
}
/**
* @return array Transient Names
*/
private
function
transient_names
()
{
return
array
(
self
::
PLUGIN_INFO_REQUIRED_PLUGINS_TRANSIENT_NAME
,
self
::
PLUGIN_INFO_IS_WP_PLUGIN_INSTALLED_TRANSIENT_NAME
,
);
}
/**
* @param $notices array
*
...
...
@@ -315,24 +304,21 @@
}
/**
* Check the plugins directory and retrieve installed plugin file or plugin data.
*
* @param $transient_name
* @param $plugin_file
* Check the plugins directory and retrieve all plugin files with plugin data.
*
* @return array
|bool
* @return array
*/
private
static
function
retrieve_plugins_data_in_transient
(
$transient_name
,
$plugin_file
=
''
)
{
private
static
function
retrieve_plugins_data_in_transient
()
{
$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
=
get_transient
(
$transient_name
);
if
(
$plugins
===
false
)
{
$plugins
=
!
empty
(
$plugin_file
)
?
array_key_exists
(
$plugin_file
,
get_plugins
()
)
:
get_plugins
();
set_transient
(
$transient_name
,
$plugins
,
self
::
PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME
);
$plugins
=
function_exists
(
'get_plugins'
)
?
get_plugins
()
:
array
();
set_transient
(
self
::
PLUGIN_INFO_TRANSIENT_NAME
,
$plugins
,
self
::
PLUGIN_INFO_TRANSIENT_EXPIRATION_TIME
);
}
return
$plugins
;
...
...
@@ -346,7 +332,8 @@
private
function
retrieve_required_plugins_data
()
{
$require_plugins
=
array
();
$plugins
=
self
::
retrieve_plugins_data_in_transient
(
self
::
PLUGIN_INFO_REQUIRED_PLUGINS_TRANSIENT_NAME
);
$plugins
=
self
::
retrieve_plugins_data_in_transient
();
if
(
is_array
(
$plugins
)
)
{
if
(
count
(
$plugins
)
>
0
)
{
if
(
!
empty
(
$this
->
plugin_require
)
)
{
foreach
(
$this
->
plugin_require
as
$plugin
)
{
...
...
@@ -354,8 +341,9 @@
$plugin_version
=
$plugin
[
self
::
PLUGIN_INFO_VERSION
];
if
(
self
::
is_wp_plugin_active
(
$plugin_file_name
)
)
{
$require_plugins
[
$plugin
[
$plugin_file_name
]
]
=
$plugins
[
$plugin_file_name
];
$require_plugins
[
$plugin
[
$plugin_file_name
]
][
self
::
PLUGIN_INFO_APPEND_PLUGIN_DATA
]
=
$plugin_version
;
$require_plugins
[
$plugin_file_name
]
=
$plugins
[
$plugin_file_name
];
$require_plugins
[
$plugin_file_name
][
self
::
PLUGIN_INFO_APPEND_PLUGIN_DATA
]
=
$plugin_version
;
}
}
}
}
...
...
@@ -434,7 +422,7 @@
$nice_name
=
$plugin_info
[
self
::
PLUGIN_INFO_KEY_NICE_NAME
];
if
(
!
self
::
is_wp_plugin_active
(
$name
)
)
{
if
(
!
self
::
is_wp_plugin_installed
(
self
::
PLUGIN_INFO_IS_WP_PLUGIN_INSTALLED_TRANSIENT_NAME
,
$name
)
)
{
if
(
!
self
::
is_wp_plugin_installed
(
$name
)
)
{
$install_url
=
$this
->
prepare_plugin_repository_install_url
(
$plugin_info
);
return
$this
->
prepare_notice_message
(
sprintf
(
wp_kses
(
__
(
'The “%s” plugin requires free %s plugin. <a href="%s">Install %s →</a>'
,
...
...
@@ -475,17 +463,13 @@
* Checks if plugin is installed. Needs to be enabled in deferred way.
*
* @param string $plugin_file
* @param string $transient_name
*
* @return bool
*/
public
static
function
is_wp_plugin_installed
(
$transient_name
,
$plugin_file
)
{
if
(
isset
(
$plugin_file
)
)
{
return
self
::
retrieve_plugins_data_in_transient
(
$transient_name
,
$plugin_file
);
}
public
static
function
is_wp_plugin_installed
(
$plugin_file
)
{
$plugins_data
=
self
::
retrieve_plugins_data_in_transient
();
return
false
;
return
array_key_exists
(
$plugin_file
,
(
array
)
$plugins_data
)
;
}
/**
...
...
@@ -582,9 +566,7 @@
if
(
isset
(
$this
->
plugin_file
)
)
{
deactivate_plugins
(
plugin_basename
(
$this
->
plugin_file
)
);
foreach
(
$this
->
transient_names
()
as
$transient_name
)
{
delete_transient
(
$transient_name
);
}
delete_transient
(
self
::
PLUGIN_INFO_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