| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPAdminify\Inc\Classes; |
| 4 |
|
| 5 |
// no direct access allowed |
| 6 |
if ( ! defined( 'ABSPATH' ) ) { |
| 7 |
exit; |
| 8 |
} |
| 9 |
|
| 10 |
/** |
| 11 |
* @package WPAdminify |
| 12 |
* Multisite Helper |
| 13 |
* |
| 14 |
* @author Jewel Theme <support@jeweltheme.com> |
| 15 |
*/ |
| 16 |
|
| 17 |
class Multisite_Helper { |
| 18 |
|
| 19 |
public function is_network_active() { |
| 20 |
if ( ! function_exists( 'is_plugin_active_for_network' ) || ! function_exists( 'is_plugin_active' ) ) { |
| 21 |
require_once ABSPATH . '/wp-admin/includes/plugin.php'; |
| 22 |
} |
| 23 |
|
| 24 |
return ( is_plugin_active_for_network( 'adminify/adminify.php' ) ? true : false ); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Check Multisite Supports |
| 29 |
* |
| 30 |
* @return void |
| 31 |
*/ |
| 32 |
public function is_multisite_supported() { |
| 33 |
return ( $this->is_network_active() && apply_filters( 'wp_adminify_ms_support', false ) ? true : false ); |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Check if it needed to switch blog |
| 38 |
* |
| 39 |
* @return void |
| 40 |
*/ |
| 41 |
public function needs_to_switch_blog() { |
| 42 |
if ( ! $this->is_multisite_supported() ) { |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
global $blueprint; |
| 47 |
|
| 48 |
if ( empty( $blueprint ) || get_current_blog_id() === $blueprint ) { |
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
return true; |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Construct array of excluded sites |
| 57 |
* |
| 58 |
* @return array The array of excluded sites. |
| 59 |
*/ |
| 60 |
public function get_excluded_sites() { |
| 61 |
global $blueprint; |
| 62 |
|
| 63 |
$array = []; |
| 64 |
|
| 65 |
// Include blueprint site if it is defined. |
| 66 |
if ( ! empty( $blueprint ) ) { |
| 67 |
$array[] = $blueprint; |
| 68 |
} |
| 69 |
|
| 70 |
if ( get_site_option( 'wp_adminify_multisite_exclude' ) ) { |
| 71 |
$excluded_sites = get_site_option( 'wp_adminify_multisite_exclude' ); |
| 72 |
$excluded_sites = str_replace( ' ', '', $excluded_sites ); |
| 73 |
$excluded_sites = explode( ',', $excluded_sites ); |
| 74 |
} else { |
| 75 |
$excluded_sites = []; |
| 76 |
} |
| 77 |
|
| 78 |
$excluded_sites = array_merge( $array, $excluded_sites ); |
| 79 |
|
| 80 |
return $excluded_sites; |
| 81 |
} |
| 82 |
} |
| 83 |
|