Support » Networking WordPress » Determine if a Plugin is "Network Activated"

  • Resolved Curtiss Grymala

    (@cgrymala)


    I am trying to work on a new plug-in that offers site-by-site administration options when it’s activated normally or network-wide options when it’s either network activated or added as a “mu-plugin”. However, I’m not sure how to determine whether the plug-in has been activated normally or through network activation.

    Is there any kind of function or array I can utilize in WordPress to determine if a plug-in is part of the normal active plug-ins collection or the network active plug-ins?

    I have tried looking for a function similar to is_plugin_active() that would check for network activation, but I haven’t turned anything up. Any advice or suggestions would be greatly appreciated. Thank you.

Viewing 8 replies - 1 through 8 (of 8 total)
  • have a look at this plugin’s guts:

    http://wordpress.org/extend/plugins/network-privacy/

    (or I’m thinking of globall netowrok wide options there…)

    Uh… brain fart. Buddypress forces network activation. If you han handle ignoring most of the code, you’ll find it in there too.

    Thanks, Andrea. I also had a brain-fart and realized that the “WPMU Plugin Stats” plug-in displays information about whether a plug-in is “Network Activated” or not, and took a look at it. The solution I came up with so far is:

    if( !function_exists( 'is_plugin_network_active' ) ) {
    	function is_plugin_network_active( $plugin_file ) {
    		return ( array_key_exists( $plugin_file, maybe_unserialize( get_site_option( 'active_sitewide_plugins') ) ) );
    	}
    }

    I’ll take a look at BuddyPress and Network Privacy to see if they’re doing things a different way or not. Thanks for your help.

    nah, that’ll probably do it for ya.

    Man, we’re both brain farting all over the place here. 😀

    Bump:

    While looking through the WordPress source code, investigating a different issue, I came across the is_plugin_active_for_network() function.

    Turns out I don’t need a custom function to check if a plugin is network activated, it’s already built into the core; just not documented yet (which I might try to solve if I can figure out how to add a new page to the codex).

    Just go type a page name into the codex. If you’re logged in you’ll get a message to create that page.

    PLEASE DO.

    Also, handy tip if you’re writing a plugin and you want to force it to network activate.

    Put Network: true in the plugin header.

    Yeah, I found that out while pouring through the source code the other day. That is a really handy tip; which I’ll be testing on some upcoming plugins. Thanks again, Andrea.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Determine if a Plugin is "Network Activated"’ is closed to new replies.