I want to be able to prevent a plugin being activated when certain conditions are present.
Looking through core it seemed to make sense to use the activate_plugin hook (line 540 of wp-admin/includes/plugin.php).
The function I’ve hooked in checks for the conditions and through logging I’ve confirmed that the conditions are are all present. Then I return an error, like so;
return new WP_Error('plugin_conditions', __('This plugin cannot be activated at this time.'));
However, the plugin is activated successfully and no error is shown.
So two questions;
1) Do you think I’m using the right hook to check for my conditions?
2) Why, when my conditions are present, does returning a new WP_Error not stop the plugin activation and show my error message?
I notice a few lines below the activate_plugin hook (line 559) there is similar code to return a WP_Error object when unexpected output it generated. This obviously works and I’m not sure how my implementation differs.
- The topic ‘Returning an error with activate_plugin hook’ is closed to new replies.