Skip to content

Instantly share code, notes, and snippets.

@dlxsnippets
Last active September 12, 2022 00:50
Show Gist options
  • Save dlxsnippets/b989adc9ff8004cf11306317c96d6efb to your computer and use it in GitHub Desktop.
Save dlxsnippets/b989adc9ff8004cf11306317c96d6efb to your computer and use it in GitHub Desktop.
WordPress Function: is multisite. Check whether to perform multisite related tasks.
<?php
/**
* Checks if the plugin is installed and activated on a multisite install.
*
* @since 1.0.0
*
* @param bool $network_admin Check if in network admin.
* @param string $slug Plugin slug.
*
* @return true if multisite, false if not.
*/
public static function is_multisite( $network_admin = false, $slug = 'alerts-dlx' ) {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
$is_network_admin = false;
// Check if we're in network admin and the plugin slug is network activated.
if ( $network_admin ) {
if ( is_network_admin() ) {
if ( is_multisite() && is_plugin_active_for_network( $slug ) ) {
return true;
}
} else {
return false;
}
}
// Check if the plugin is network-activated on multisite.
if ( is_multisite() && is_plugin_active_for_network( $slug ) ) {
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment