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