PluginProbe
ManageWP Worker / 4.9.34
ManageWP Worker v4.9.34
4.9.38 4.9.37 4.9.36 4.9.35 4.9.34 3.8.7 3.8.8 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.18 3.9.19 3.9.2 3.9.20 3.9.21 3.9.22 3.9.23 3.9.24 All 73 releases
worker / src / MWP / WordPress / Provider / Plugin.php

Plugin.php in ManageWP Worker 4.9.34, at src/MWP/WordPress/Provider/Plugin.php

128 lines 3.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * This file is part of the ManageWP Worker plugin.
4 *
5 * (c) ManageWP LLC <[email protected]>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10
11 class MWP_WordPress_Provider_Plugin implements MWP_WordPress_Provider_Interface
12 {
13
14 const STATUS_ACTIVE_NETWORK = 'active-network';
15
16 const STATUS_ACTIVE = 'active';
17
18 const STATUS_MUST_USE = 'must-use';
19
20 const STATUS_INACTIVE = 'inactive';
21
22 const STATUS_DROP_IN = 'drop-in';
23
24 private $context;
25
26 public function __construct(MWP_WordPress_Context $context)
27 {
28 $this->context = $context;
29 }
30
31 public function fetch(array $options = array())
32 {
33 $regularPlugins = $this->context->getPlugins();
34 $mustUsePlugins = $this->context->getMustUsePlugins();
35 $dropInPlugins = $this->context->getDropInPlugins();
36 $plugins = array();
37
38 $pluginInfo = array(
39 'name' => 'Name',
40 'pluginUri' => 'PluginURI',
41 'version' => 'Version',
42 'description' => 'Description',
43 'author' => 'Author',
44 'authorUri' => 'AuthorURI',
45 );
46
47 if (empty($options['fetchDescription'])) {
48 unset($pluginInfo['description']);
49 }
50
51 foreach ($regularPlugins as $basename => $details) {
52 $plugin = array(
53 // This is the plugin identifier; ie. "worker/init.php".
54 'basename' => $basename,
55 // Plugin's own directory name (if it exists), or filename minus ".php" extension Ie. "worker".
56 'slug' => $this->getSlugFromBasename($basename),
57 // 'Network' property can have a valid value or 'false' and is always present.
58 // It signifies whether the plugin can only be activated network wide.
59 'networkOnly' => $details['Network'],
60 );
61
62 foreach ($pluginInfo as $property => $info) {
63 if (empty($details[$info])) {
64 $plugin[$property] = null;
65 continue;
66 }
67
68 $plugin[$property] = $this->context->seemsUtf8($details[$info]) ? $details[$info] : utf8_encode($details[$info]);
69 }
70
71 $plugin['status'] = $this->getPluginStatus($basename);
72
73 $plugins[] = $plugin;
74 }
75
76 foreach ($mustUsePlugins as $basename => $details) {
77 $plugin = array(
78 'basename' => $basename,
79 'slug' => $this->getSlugFromBasename($basename),
80 );
81
82 foreach ($pluginInfo as $property => $info) {
83 $plugin[$property] = !empty($details[$info]) ? $details[$info] : null;
84 }
85
86 $plugin['status'] = self::STATUS_MUST_USE;
87 $plugins[] = $plugin;
88 }
89
90 foreach ($dropInPlugins as $basename => $details) {
91 $plugin = array(
92 'basename' => $basename,
93 'type' => self::STATUS_DROP_IN,
94 );
95
96 foreach ($pluginInfo as $property => $info) {
97 $plugin[$property] = !empty($details[$info]) ? $details[$info] : null;
98 }
99
100 $plugins[] = $plugin;
101 }
102
103 return $plugins;
104 }
105
106 private function getSlugFromBasename($file)
107 {
108 if (false === strpos($file, '/')) {
109 $slug = basename($file, '.php');
110 } else {
111 $slug = dirname($file);
112 }
113
114 return $slug;
115 }
116
117 private function getPluginStatus($file)
118 {
119 if ($this->context->isPluginActiveForNetwork($file)) {
120 return self::STATUS_ACTIVE_NETWORK;
121 } elseif ($this->context->isPluginActive($file)) {
122 return self::STATUS_ACTIVE;
123 }
124
125 return self::STATUS_INACTIVE;
126 }
127 }
128