I have a plugin that currently doesn’t support network activation. The best fix for this of course is to fix it 🙂 which I plan to do. However I wonder if there is a temporary solution I can use to prevent network activation in the meantime, perhaps a workflow similar to:
- Detect if the activation is network-wide (how??)
- Display message that it’s currently not supported, and I stink, I’m sorry
- Interrupt the activation or deactivate
Or, other suggestions accepted. Thanks.
For clarification: Multisite activation is fine, just not network-wide activation.
The answers here are overthought and too complex. Why deactivating the plugin instead of preventing activation? Something as simple as calling die(‘your error message here) upon activation will do the job.
Then when you try to activate in the panel, you will get a nice error on top of the page, with your error message.
A plugin header
Network: false
will be ignored by WordPress … unfortunately. But the activation hook gets a parameter$network_wide
, and we can use that to deactivate the plugin during activation:You could simply hide it from the network-plugins list.
And display a one-time network admin notice. Adapting the Q&A add_role() run only once?.
Or use this other technique: Add a notice to users upon first login to the admin area
(This is untested)
And then on
admin_notices
check for thewpse76145_network_activate_notice
option and display notice.Note: It would be better not to hardcode ‘myplugin/myplugin.php’ – I think replacing it with
plugin_basename(__FILE__);
would work (and be preferable).Edit if multi-site activation is ok, then you could use
switch_to_blog()
to activate on each plug-in individually. I would still display a notice as you’ve not done what the user has asked.