Last active
September 11, 2025 18:56
-
-
Save dlxsnippets/0d10d13237806b0d59f0b1826254f69d to your computer and use it in GitHub Desktop.
Function to Determine if Multisite is Active and Enabled
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Checks if the plugin is on a multisite install and if plugin is active for network. | |
| * | |
| * @param bool $network_admin Whether to check if in the network admin. | |
| * @param bool $network_activated Whether the plugin is active for the network. | |
| * @param mixed $plugin_file Path to the plugin file. | |
| * | |
| * @return bool True if multisite, false if not. If in network admin, true if plugin is active for network, false if not. If not in network admin, true if plugin is active for the site, 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