PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.3.1
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.3.1
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
blank-theme 5 years ago Optimizer.php 2 years ago wp-staging-optimizer.php 2 years ago
Optimizer.php
81 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 public function installOptimizer(): bool
46 {
47 if (file_exists($this->dest) && $this->mustUpdateOptimizer() === false) {
48 return false;
49 }
50
51 if ((new Filesystem())->mkdir($this->mudir)) {
52 return @copy($this->source, $this->dest);
53 }
54
55 return false;
56 }
57
58 /**
59 * Check if the Optimizer must use plugin must be updated
60 * @return bool
61 */
62 private function mustUpdateOptimizer(): bool
63 {
64 $isVersionNumber = defined('WPSTG_OPTIMIZER_VERSION') ? WPSTG_OPTIMIZER_VERSION : false;
65
66 $update = false;
67
68 if ($isVersionNumber === false) {
69 return true;
70 }
71
72 $mustVersionNumber = defined('WPSTG_OPTIMIZER_MUVERSION') ? WPSTG_OPTIMIZER_MUVERSION : false;
73
74 if ($mustVersionNumber) {
75 $update = version_compare($isVersionNumber, $mustVersionNumber, '!=');
76 }
77
78 return $update;
79 }
80 }
81