Cache
2 years ago
DBPermissions.php
2 years ago
DataEncoder.php
2 years ago
Escape.php
2 years ago
Glob.php
2 years ago
Hooks.php
2 years ago
Math.php
2 years ago
PluginInfo.php
2 years ago
Sanitize.php
2 years ago
ServerVars.php
2 years ago
SlashMode.php
5 years ago
Strings.php
2 years ago
Times.php
2 years ago
Urls.php
2 years ago
Version.php
2 years ago
WpDefaultDirectories.php
2 years ago
PluginInfo.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Utils; |
| 4 | |
| 5 | class PluginInfo |
| 6 | { |
| 7 | /** |
| 8 | * Checks if the admin menu can be displayed. The different cases are: |
| 9 | * - if the free only version is active; |
| 10 | * - if the pro version is active then the free version must be active and compatible with the pro version. |
| 11 | * - if the free is not require for pro. |
| 12 | * |
| 13 | * @return bool |
| 14 | */ |
| 15 | public function canShowAdminMenu(): bool |
| 16 | { |
| 17 | if (!defined('WPSTGPRO_VERSION')) { |
| 18 | return true; |
| 19 | } |
| 20 | |
| 21 | if (defined('WPSTG_REQUIRE_FREE') && !WPSTG_REQUIRE_FREE) { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | if (wpstgIsFreeActiveInNetworkOrCurrentSite()) { |
| 26 | return true; |
| 27 | } |
| 28 | |
| 29 | if (wpstgIsFreeVersionCompatible()) { |
| 30 | return true; |
| 31 | } |
| 32 | |
| 33 | return false; |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @return array |
| 38 | */ |
| 39 | public function getAllActivePluginsInSubsites(): array |
| 40 | { |
| 41 | if (!is_multisite()) { |
| 42 | return []; |
| 43 | } |
| 44 | |
| 45 | $activePlugins = []; |
| 46 | $sites = get_sites(); |
| 47 | |
| 48 | foreach ($sites as $site) { |
| 49 | switch_to_blog($site->blog_id); |
| 50 | |
| 51 | $activeForCurrent = (array) get_option('active_plugins', []); |
| 52 | $activeWithPath = array_map( |
| 53 | function ($plugin) { |
| 54 | return trailingslashit(WP_PLUGIN_DIR) . $plugin; |
| 55 | }, |
| 56 | $activeForCurrent |
| 57 | ); |
| 58 | |
| 59 | $activePlugins = array_merge($activePlugins, $activeWithPath); |
| 60 | |
| 61 | restore_current_blog(); |
| 62 | } |
| 63 | |
| 64 | return array_unique($activePlugins); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * @return array |
| 69 | */ |
| 70 | public function getAllActiveThemesInSubsites(): array |
| 71 | { |
| 72 | if (!is_multisite()) { |
| 73 | return []; |
| 74 | } |
| 75 | |
| 76 | $activeThemes = []; |
| 77 | $sites = get_sites(); |
| 78 | |
| 79 | remove_all_filters('stylesheet_directory'); // to get the real value of get_stylesheet_directory(). |
| 80 | remove_all_filters('template_directory'); // to get the real value of get_template_directory(). |
| 81 | |
| 82 | foreach ($sites as $site) { |
| 83 | switch_to_blog($site->blog_id); |
| 84 | |
| 85 | $activeThemes[] = get_stylesheet_directory(); |
| 86 | $activeThemes[] = get_template_directory(); |
| 87 | |
| 88 | restore_current_blog(); |
| 89 | } |
| 90 | |
| 91 | return array_unique($activeThemes); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Get active parent and child themes |
| 96 | * @return array |
| 97 | */ |
| 98 | public function getActiveThemes(): array |
| 99 | { |
| 100 | $activeThemes = []; |
| 101 | |
| 102 | remove_all_filters('stylesheet_directory'); // to get the real value of get_stylesheet_directory(). |
| 103 | remove_all_filters('template_directory'); // to get the real value of get_template_directory(). |
| 104 | |
| 105 | $activeThemes[] = get_stylesheet_directory(); // child theme |
| 106 | $activeThemes[] = get_template_directory(); // parent theme |
| 107 | |
| 108 | return array_unique($activeThemes); |
| 109 | } |
| 110 | } |
| 111 |