Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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.' );
    }
}
share|improve this answer
    
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. –  Brady Mar 6 '12 at 18:08
add comment

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();.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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