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;
}