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