PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backups, Restore, Migration & Clone / 4.11.0
WP STAGING – WordPress Backups, Restore, Migration & Clone v4.11.0
4.11.0 4.10.0 4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 4.8.1 trunk 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.10.0 3.2.0 3.3.1 3.3.2 3.3.3 3.4.1 3.4.3 3.5.0 3.6.0 3.7.1 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.8.7 3.9.0 3.9.1 3.9.2 3.9.3 3.9.4 4.0.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.0 4.7.0 4.7.1 4.7.2 4.7.3 4.8.0
wp-staging / Framework / CloningProcess / ExcludedPlugins.php
wp-staging / Framework / CloningProcess Last commit date
Data 1 day ago Database 1 day ago CloningDto.php 1 day ago ExcludedPlugins.php 1 day ago
ExcludedPlugins.php
170 lines
1 <?php
2
3 namespace WPStaging\Framework\CloningProcess;
4
5 use WPStaging\Core\WPStaging;
6 use WPStaging\Framework\Adapter\Directory;
7 use WPStaging\Framework\Facades\Hooks;
8 use WPStaging\Framework\Filesystem\PathIdentifier;
9 use WPStaging\Staging\CloneOptions;
10
11
12
13
14 class ExcludedPlugins
15 {
16
17
18
19 const EXCLUDED_PLUGINS_KEY = 'excluded_plugins';
20
21
22
23
24 private $excludedPlugins;
25
26
27 private $pluginsPath;
28
29
30 private $absPath;
31
32
33
34
35
36
37
38 public function __construct($dirAdapter = null)
39 {
40 if ($dirAdapter === null) {
41 $dirAdapter = WPStaging::make(Directory::class);
42 }
43
44 $this->pluginsPath = $dirAdapter->getPluginsDirectory();
45 $this->absPath = $dirAdapter->getAbsPath();
46 $this->excludedPlugins = [
47 'wps-hide-login',
48 'wp-super-cache',
49 'peters-login-redirect',
50 'wp-spamshield',
51 ];
52 }
53
54
55
56
57
58
59
60
61
62
63
64
65
66 public function getPluginsToExclude()
67 {
68 return $this->excludedPlugins;
69 }
70
71
72
73
74
75
76 public function getPluginsToExcludeWithIdentifier()
77 {
78 return array_map(function ($plugin) {
79 return PathIdentifier::IDENTIFIER_PLUGINS . $plugin;
80 }, $this->excludedPlugins);
81 }
82
83
84
85
86
87
88 public function getPluginsToExcludeWithRelativePath()
89 {
90 $relativePath = str_replace($this->absPath, '/', $this->pluginsPath);
91 $relativePath = trailingslashit($relativePath);
92 return array_map(function ($plugin) use ($relativePath) {
93 return $relativePath . $plugin;
94 }, $this->excludedPlugins);
95 }
96
97
98
99
100
101
102 public function getPluginsToExcludeFullPath()
103 {
104 $pluginsPath = $this->pluginsPath;
105 return array_map(function ($plugin) use ($pluginsPath) {
106 return $pluginsPath . $plugin;
107 }, $this->excludedPlugins);
108 }
109
110
111
112
113
114
115
116
117 public function getFilteredPluginsToExclude($installedPlugins = [])
118 {
119
120 if (is_multisite()) {
121 $filteredExcludedPlugins = apply_filters(Directory::FILTER_CLONE_MU_EXCLUDED_FOLDERS, $this->getPluginsToExcludeWithRelativePath());
122 } else {
123 $filteredExcludedPlugins = apply_filters(Directory::FILTER_CLONE_EXCLUDED_FOLDERS, $this->getPluginsToExcludeWithRelativePath());
124 }
125
126 if ($installedPlugins === []) {
127 $installedPlugins = get_plugins();
128 $installedPlugins = array_keys($installedPlugins);
129 }
130
131 $relativePath = str_replace($this->absPath, '/', $this->pluginsPath);
132 $relativePath = trailingslashit($relativePath);
133
134 $filteredExcludedPlugins = array_filter($filteredExcludedPlugins, function ($path) use ($installedPlugins, $relativePath) {
135 foreach ($installedPlugins as $plugin) {
136 $plugin = $relativePath . explode('/', $plugin)[0];
137 if (strpos($path, $plugin) === 0) {
138 return true;
139 }
140 }
141
142 return false;
143 });
144
145
146 $filteredExcludedPlugins = array_values($filteredExcludedPlugins);
147
148
149
150
151
152
153
154 return array_map(function ($path) use ($relativePath) {
155 $plugin = str_replace($relativePath, '', $path);
156 return explode('/', $plugin)[0];
157 }, $filteredExcludedPlugins);
158 }
159
160
161
162
163
164
165 public function getExcludedPlugins()
166 {
167 return (new CloneOptions())->get(self::EXCLUDED_PLUGINS_KEY);
168 }
169 }
170