PluginProbe
Import WP – CSV & XML Import Export for WordPress / trunk
Import WP – CSV & XML Import Export for WordPress vtrunk
2.14.24 2.14.23 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.9.0 2.9.1 trunk 0.1.6 All 142 releases
jc-importer / class / Common / Compatibility / CompatibilityManager.php

CompatibilityManager.php in Import WP – CSV & XML Import Export for WordPress trunk, at class/Common/Compatibility/CompatibilityManager.php

71 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace ImportWP\Common\Compatibility;
4
5 use ImportWP\Common\Filesystem\Filesystem;
6 use ImportWP\Common\Properties\Properties;
7
8 class CompatibilityManager
9 {
10 /**
11 * @var Properties
12 */
13 public $properties;
14 /**
15 *
16 * @var Filesystem
17 */
18 public $filesystem;
19
20 public function __construct($properties, $filesystem)
21 {
22 $this->properties = $properties;
23 $this->filesystem = $filesystem;
24
25 // Checks the compatibility mode MU plugin version and updates if it's out of date.
26 add_action('admin_init', array($this, 'muplugin_version_check'), 1);
27
28 add_action('iwp/compat/register_muplugin_uninstall', [$this, 'remove_muplugin_on_deactivation']);
29 }
30
31 public function muplugin_version_check()
32 {
33 if (isset($_GET['page']) && $_GET['page'] === 'importwp') {
34 if (true === $this->is_muplugin_update_required()) {
35 return $this->copy_muplugin();
36 }
37 }
38
39 return false;
40 }
41
42 public function is_muplugin_update_required()
43 {
44 if (version_compare(get_option('iwp_muplugin_version', 0), $this->properties->mu_plugin_version, '<')) {
45 return true;
46 }
47
48 return false;
49 }
50
51 public function copy_muplugin()
52 {
53 if (!wp_mkdir_p(dirname($this->properties->mu_plugin_dest)) || !$this->filesystem->copy($this->properties->mu_plugin_source, $this->properties->mu_plugin_dest)) {
54 return false;
55 }
56
57 update_option('iwp_muplugin_version', $this->properties->mu_plugin_version);
58
59 return true;
60 }
61
62 public function remove_muplugin_on_deactivation()
63 {
64
65 if ($this->filesystem->file_exists($this->properties->mu_plugin_dest)) {
66 @unlink($this->properties->mu_plugin_dest);
67 delete_option('iwp_muplugin_version');
68 }
69 }
70 }
71