Database
1 day ago
Database.php
1 day ago
DatabaseInterface.php
1 year ago
DateTimeAdapter.php
1 day ago
Directory.php
1 day ago
DirectoryInterface.php
1 year ago
Maintenance.php
1 day ago
PhpAdapter.php
1 day ago
SourceDatabase.php
1 day ago
WpAdapter.php
1 day ago
WpAdapter.php
122 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Adapter; |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | class WpAdapter |
| 12 | { |
| 13 | |
| 14 | const FILTER_OPTION_ACTIVE_PLUGINS = 'option_active_plugins'; |
| 15 | |
| 16 | |
| 17 | const FILTER_SITE_OPTION_ACTIVE_SITEWIDE_PLUGINS = 'site_option_active_sitewide_plugins'; |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | public function doingAjax() |
| 27 | { |
| 28 | return defined('DOING_AJAX') && DOING_AJAX; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | public function isWpCliRequest() |
| 35 | { |
| 36 | return defined('WP_CLI') && WP_CLI; |
| 37 | } |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | public function isPluginActive($plugin) |
| 48 | { |
| 49 | |
| 50 | remove_all_filters(self::FILTER_OPTION_ACTIVE_PLUGINS); |
| 51 | return in_array($plugin, (array) get_option('active_plugins', [])) || $this->isPluginNetworkActive($plugin); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | public function isPluginNetworkActive($plugin) |
| 63 | { |
| 64 | if (!is_multisite()) { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | |
| 69 | remove_all_filters(self::FILTER_SITE_OPTION_ACTIVE_SITEWIDE_PLUGINS); |
| 70 | $plugins = get_site_option('active_sitewide_plugins'); |
| 71 | if (isset($plugins[$plugin])) { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | public function getCurrentNetworkId() |
| 87 | { |
| 88 | |
| 89 | if (!is_multisite()) { |
| 90 | return 1; |
| 91 | } |
| 92 | |
| 93 | |
| 94 | if (is_callable('get_current_network_id')) { |
| 95 | return get_current_network_id(); |
| 96 | } |
| 97 | |
| 98 | |
| 99 | if (!is_callable('get_current_site')) { |
| 100 | return 1; |
| 101 | } |
| 102 | |
| 103 | $currentSite = get_current_site(); |
| 104 | |
| 105 | if (!is_object($currentSite)) { |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | |
| 110 | if (property_exists($currentSite, 'id')) { |
| 111 | $currentSite->id; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | if (property_exists($currentSite, 'ID')) { |
| 116 | $currentSite->ID; |
| 117 | } |
| 118 | |
| 119 | return 1; |
| 120 | } |
| 121 | } |
| 122 |