3

Is there a way to allow plugin to be activated only from NETWORK DASHBOARD (if using Multisite).

In not multisite, allow to be activated normally.

7

You can specify that a plugin is Network Only in the plugin's header information.

/*
Plugin Name: Name of Plugin
Plugin URI: Link to plugin information
Description: Plugin Description
[...]
Network: Optional. Specify "Network: true" to require that a plugin is activated
       across all sites in an installation. This will prevent a plugin from being
       activated on a single site when Multisite is enabled.
*/

See get_plugin_data().

Network: true in a non-multisite plugin will allow the plugin to work (quick test on my local installation confirms that).

You could also try using the all_plugins filter to hide it from the plugin list if your site is a Multisite installation and the user isn't in the Network admin screen:

add_filter( 'all_plugins', 'wpse257256_hide_my_plugin' );
function wpse257256_hide_my_plugin( $plugins ) {
    if ( is_multisite() && ! is_network_admin() ) {
        unset( $plugins['my-plugin-name/my-plugin-file.php'] );
    }
    return $plugins;
}

Reference

  • Wow! I'd never seen the Network: true header before reading this. I tested it seems to work in both multisite and non-multisite. Thanx! – Paul 'Sparrow Hawk' Biron Feb 20 '17 at 21:55
  • @Paul'SparrowHawk'Biron -- I'd never noticed the Network: true header before either, but then I'd never needed it before. (I found it by accident: I was searching the Developer Guide for is_network_admin() and the search suggestions included is_network_only_plugin().) – Pat J Feb 20 '17 at 23:56
  • This right here is what makes SE so great. This is exactly what I needed! – Dustin Snider Jul 26 '17 at 15:48

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