I'm developing the wordpress file monitor plus plugin.

Its purpose is to scan for altered files and it works fine for a single installation of WP. But when you look at multi-site it's not something that wants to be enabled on all sub sites, as they all share the same files and (to be honest) only a network admin should be the one that wants to be notified against file changes.

So my question is this:

How would I program it, to only be allowed to be installed/run from the root site of a multi-site installation? So: that means not allowing it to be network installed and only activated from the root blog.

Anyone know of any ways on how I could achieve this?

  • Per my answer to this duplicate question, you can also simply set Network: true in the plugin file's PHP header. This should allow the plugin to be activated on non-Multisite installations, but only allow it to be network-activated on Multisite networks.
    – Pat J
    Feb 21, 2017 at 16:11

3 Answers 3


You could check if the constant SITE_ID_CURRENT_SITE matches get_current_site()->id. The following does this for the activation. During runtime you have to check it again.

register_activation_hook( __FILE__, 'force_main_site_installation' );

function force_main_site_installation()
    if ( defined( 'SITE_ID_CURRENT_SITE' )
        and SITE_ID_CURRENT_SITE !== get_current_site()->id 
        if ( function_exists('deactivate_plugins') )
            deactivate_plugins( __FILE__ );
        die( 'Install this plugin on the main site only.' );
  • Thanks Toscho. That stuff you put in chat got me started in the correct direction. I'm now working on a class for my plugin that takes care of things if a multisite installation.
    – Scott
    Mar 6, 2012 at 18:08

First the explanation for the uninstall/activation/deactivation hooks.

Second: check for is_blog_installed( $blog_ID ); and then look into all the get_blog_whatever(); and get_blogaddress_whatever();` functions (I guess you use phpstorm as IDE, so autocomplete for functions should be available to you).

Edit: You could also try to restrict the available menu with registering the admin pages with network_admin_menu() (triggers only if is_network_admin()), user_admin_menu(); (triggers only if is_user_admin()) instead of admin_menu();.


Only this solution worked for me :

register_activation_hook( __FILE__,  function () {
    if ( is_multisite() && ! strpos( $_SERVER['REQUEST_URI'], 'wp-admin/network/plugins.php' ) ) {
        die ( __( '<script>alert("Activate this plugin only from the NETWORK DASHBOARD.");</script>') );
    // ...............

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.