Cache
2 years ago
ThirdParty
2 years ago
DBPermissions.php
2 years ago
Escape.php
2 years ago
Hooks.php
2 years ago
Math.php
2 years ago
PluginInfo.php
2 years ago
Sanitize.php
3 years ago
ServerVars.php
2 years ago
SlashMode.php
5 years ago
Strings.php
2 years ago
Times.php
2 years ago
Urls.php
3 years ago
WpDefaultDirectories.php
3 years ago
PluginInfo.php
106 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 | * |
| 12 | * @return bool |
| 13 | */ |
| 14 | public function canShowAdminMenu(): bool |
| 15 | { |
| 16 | if (!defined('WPSTGPRO_VERSION')) { |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | if (wpstgIsFreeActiveInNetworkOrCurrentSite()) { |
| 21 | return true; |
| 22 | } |
| 23 | |
| 24 | if (wpstgIsFreeVersionCompatible()) { |
| 25 | return true; |
| 26 | } |
| 27 | |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * @return array |
| 33 | */ |
| 34 | public function getAllActivePluginsInSubsites(): array |
| 35 | { |
| 36 | if (!is_multisite()) { |
| 37 | return []; |
| 38 | } |
| 39 | |
| 40 | $activePlugins = []; |
| 41 | $sites = get_sites(); |
| 42 | |
| 43 | foreach ($sites as $site) { |
| 44 | switch_to_blog($site->blog_id); |
| 45 | |
| 46 | $activeForCurrent = (array) get_option('active_plugins', []); |
| 47 | $activeWithPath = array_map( |
| 48 | function ($plugin) { |
| 49 | return trailingslashit(WP_PLUGIN_DIR) . $plugin; |
| 50 | }, |
| 51 | $activeForCurrent |
| 52 | ); |
| 53 | |
| 54 | $activePlugins = array_merge($activePlugins, $activeWithPath); |
| 55 | |
| 56 | restore_current_blog(); |
| 57 | } |
| 58 | |
| 59 | return array_unique($activePlugins); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @return array |
| 64 | */ |
| 65 | public function getAllActiveThemesInSubsites(): array |
| 66 | { |
| 67 | if (!is_multisite()) { |
| 68 | return []; |
| 69 | } |
| 70 | |
| 71 | $activeThemes = []; |
| 72 | $sites = get_sites(); |
| 73 | |
| 74 | remove_all_filters('stylesheet_directory'); // to get the real value of get_stylesheet_directory(). |
| 75 | remove_all_filters('template_directory'); // to get the real value of get_template_directory(). |
| 76 | |
| 77 | foreach ($sites as $site) { |
| 78 | switch_to_blog($site->blog_id); |
| 79 | |
| 80 | $activeThemes[] = get_stylesheet_directory(); |
| 81 | $activeThemes[] = get_template_directory(); |
| 82 | |
| 83 | restore_current_blog(); |
| 84 | } |
| 85 | |
| 86 | return array_unique($activeThemes); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Get active parent and child themes |
| 91 | * @return array |
| 92 | */ |
| 93 | public function getActiveThemes(): array |
| 94 | { |
| 95 | $activeThemes = []; |
| 96 | |
| 97 | remove_all_filters('stylesheet_directory'); // to get the real value of get_stylesheet_directory(). |
| 98 | remove_all_filters('template_directory'); // to get the real value of get_template_directory(). |
| 99 | |
| 100 | $activeThemes[] = get_stylesheet_directory(); // child theme |
| 101 | $activeThemes[] = get_template_directory(); // parent theme |
| 102 | |
| 103 | return array_unique($activeThemes); |
| 104 | } |
| 105 | } |
| 106 |