PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 4.8.0
WP STAGING – WordPress Backup, Restore, Migration & Clone v4.8.0
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 / Backend / Optimizer / Optimizer.php
wp-staging / Backend / Optimizer Last commit date
Optimizer.php 1 month ago wp-staging-optimizer.php 1 year ago
Optimizer.php
96 lines
1 <?php
2
3 namespace WPStaging\Backend\Optimizer;
4
5 use WPStaging\Framework\Filesystem\Filesystem;
6
7 // No Direct Access
8 if (!defined("WPINC")) {
9 die;
10 }
11
12 /**
13 * Optimizer
14 */
15 class Optimizer
16 {
17 /**
18 * @var string
19 */
20 private $mudir;
21
22 /**
23 * @var string
24 */
25 private $source;
26
27 /**
28 * @var string
29 */
30 private $dest;
31
32 /**
33 * Optimizer constructor.
34 *
35 * If changes are made to this, also check uninstall.php!
36 */
37 public function __construct()
38 {
39 $this->mudir = ( defined('WPMU_PLUGIN_DIR') && defined('WPMU_PLUGIN_URL') ) ? WPMU_PLUGIN_DIR : trailingslashit(WP_CONTENT_DIR) . 'mu-plugins';
40
41 $this->source = trailingslashit(WPSTG_PLUGIN_DIR) . 'Backend/Optimizer/wp-staging-optimizer.php';
42 $this->dest = trailingslashit($this->mudir) . 'wp-staging-optimizer.php';
43 }
44
45 /**
46 * Install Optimizer
47 *
48 * @return bool
49 */
50 public function installOptimizer(): bool
51 {
52 if (file_exists($this->dest) && $this->mustUpdateOptimizer() === false) {
53 return false;
54 }
55
56 if (file_exists($this->dest) && !is_writable($this->dest)) {
57 return false;
58 }
59
60 if (!(new Filesystem())->mkdir($this->mudir)) {
61 return false;
62 }
63
64 // Avoid emitting E_WARNING from copy() when destination is not writable.
65 if (!is_writable($this->mudir)) {
66 return false;
67 }
68
69 return @copy($this->source, $this->dest);
70 }
71
72 /**
73 * Check if the Optimizer must use plugin must be updated
74 *
75 * @return bool
76 */
77 private function mustUpdateOptimizer(): bool
78 {
79 $isVersionNumber = defined('WPSTG_OPTIMIZER_VERSION') ? WPSTG_OPTIMIZER_VERSION : false;
80
81 $update = false;
82
83 if ($isVersionNumber === false) {
84 return true;
85 }
86
87 $mustVersionNumber = defined('WPSTG_OPTIMIZER_MUVERSION') ? WPSTG_OPTIMIZER_MUVERSION : false;
88
89 if ($mustVersionNumber) {
90 $update = version_compare($isVersionNumber, $mustVersionNumber, '!=');
91 }
92
93 return $update;
94 }
95 }
96