Only allow plugin to be activated on root site of multisite

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.' );
    }
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)