Skip to content

Instantly share code, notes, and snippets.

@dlxsnippets
Created August 22, 2024 15:18
Show Gist options
  • Save dlxsnippets/0d10d13237806b0d59f0b1826254f69d to your computer and use it in GitHub Desktop.
Save dlxsnippets/0d10d13237806b0d59f0b1826254f69d to your computer and use it in GitHub Desktop.
Function to Determine if Multisite is Active and Enabled
<?php
/**
* Checks if the plugin is on a multisite install.
*
* @param bool $network_admin Check if in network admin.
* @param bool $network_activated Check if plugin is network activated.
* @param string $plugin_file Path to the plugin file.
*
* @return true if multisite, false if not.
*/
function dlx_is_multisite( $network_admin = false, $network_activated = false, $plugin_file = __FILE__ ) {
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
require_once ABSPATH . '/wp-admin/includes/plugin.php';
}
if ( $network_admin ) {
if ( is_network_admin() ) {
if ( is_multisite() ) {
if ( $network_activated ) {
if ( is_plugin_active_for_network( plugin_basename( $plugin_file ) ) ) {
return true;
}
} else {
return true;
}
}
} else {
return false;
}
}
if ( is_multisite() ) {
if ( $network_activated ) {
if ( is_plugin_active_for_network( plugin_basename( $plugin_file ) ) ) {
return true;
}
} else {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment