PluginProbe ʕ •ᴥ•ʔ
WP STAGING – WordPress Backup, Restore, Migration & Clone / 3.8.2
WP STAGING – WordPress Backup, Restore, Migration & Clone v3.8.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 / Adapter / WpAdapter.php
wp-staging / Framework / Adapter Last commit date
Database 2 years ago Database.php 2 years ago DateTimeAdapter.php 4 years ago Directory.php 2 years ago Maintenance.php 4 years ago PhpAdapter.php 2 years ago SourceDatabase.php 2 years ago WpAdapter.php 3 years ago
WpAdapter.php
112 lines
1 <?php
2
3 namespace WPStaging\Framework\Adapter;
4
5 /**
6 * Class WP
7 * Adapter to maintain wordpress core function for WP backward compatibility support and deprecated functions
8 *
9 * @package WPStaging\Framework\Adapter
10 */
11 class WpAdapter
12 {
13 /**
14 * Is the current request doing some ajax
15 * Alternative to wp_doing_ajax() as it is not available for WP < 4.7
16 * This implementation is without hooks
17 *
18 * @return bool
19 */
20 public function doingAjax()
21 {
22 return defined('DOING_AJAX') && DOING_AJAX;
23 }
24
25 /**
26 * @return bool
27 */
28 public function isWpCliRequest()
29 {
30 return defined('WP_CLI') && WP_CLI;
31 }
32
33 /**
34 * Alternative to is_plugin_active.
35 * WordPress is_plugin_active is not available until admin_init hook,
36 * We needs its functionality before that.
37 *
38 * @param string $plugin
39 * @return bool
40 */
41 public function isPluginActive($plugin)
42 {
43 // Prevent filters tampering with the active plugins list, such as wpstg-optimizer.php itself.
44 remove_all_filters('option_active_plugins');
45 return in_array($plugin, (array) get_option('active_plugins', [])) || $this->isPluginNetworkActive($plugin);
46 }
47
48 /**
49 * Alternative to is_plugin_active_for_network.
50 * WordPress is_plugin_active_for_network is not available until admin_init hook,
51 * We needs its functionality before that.
52 *
53 * @param string $plugin
54 * @return bool
55 */
56 public function isPluginNetworkActive($plugin)
57 {
58 if (!is_multisite()) {
59 return false;
60 }
61
62 // Prevent filters tampering with the active plugins list, such as wpstg-optimizer.php itself.
63 remove_all_filters('site_option_active_sitewide_plugins');
64 $plugins = get_site_option('active_sitewide_plugins');
65 if (isset($plugins[$plugin])) {
66 return true;
67 }
68
69 return false;
70 }
71
72 /*
73 * Return the current network id
74 * Use get_current_network_id in WP >= 4.6
75 * Use get_current_site()->id in WP < 4.6, >= 3.7
76 * Use get_current_site()->ID in WP < 3.7
77 *
78 * @return int
79 */
80 public function getCurrentNetworkId()
81 {
82 // Early bail if not multisite
83 if (!is_multisite()) {
84 return 1;
85 }
86
87 // For WP >= 4.6
88 if (is_callable('get_current_network_id')) {
89 return get_current_network_id();
90 }
91
92 // If get_current_site is not available return 1
93 if (!is_callable('get_current_site')) {
94 return 1;
95 }
96
97 $currentSite = get_current_site();
98
99 // For WP >= 3.7 and < 4.6
100 if (property_exists($currentSite, 'id')) {
101 $currentSite->id;
102 }
103
104 // For WP < 3.7
105 if (property_exists($currentSite, 'ID')) {
106 $currentSite->ID;
107 }
108
109 return 1;
110 }
111 }
112