Title: Force Plugin Activation to Fail
Last modified: August 19, 2016

---

# Force Plugin Activation to Fail

 *  [theirishthug](https://wordpress.org/support/users/theirishthug/)
 * (@theirishthug)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/force-plugin-activation-to-fail/)
 * I am writing a plugin that is reliant on other plugins being activated. Is there
   a way for my plugin’s activation function to tell WordPress that my plugin should
   fail to activate? I would then want to print a message to the user about why 
   the plugin did not activate.

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [18 years, 2 months ago](https://wordpress.org/support/topic/force-plugin-activation-to-fail/#post-755118)
 * I can’t find a particularly good user friendly way to do this, but I can offer
   what I’ve found so far.
 * This (psuedo)code is what I use at the moment for this sort of thing:
 *     ```
       function myplugin_activation_check(){
       	// check to see if this plugin will even work
       	if( check to see if plugin is not going to work ) {
       		deactivate_plugins(basename(__FILE__)); // Deactivate ourself
       		wp_die("Sorry, but you can't run this plugin, for whatever reason.");
       	}
       }
       register_activation_hook(__FILE__, 'myplugin_activation_check');
       ```
   
 * Basically it runs that function on activation, and if the plugin decides that
   it can’t work, it deactivates itself and spits out the big error message. Not
   the prettiest error, but I’m still working on it.
 *  [Miah](https://wordpress.org/support/users/miah/)
 * (@miah)
 * [18 years ago](https://wordpress.org/support/topic/force-plugin-activation-to-fail/#post-755405)
 * Any progress on this?
 * There’s a few things that I would like to see. First, WP should have something
   where you can throw a custom error. In my case, I’m building a plugin that checks
   for database collisions an activation.
 * It’s ugly, but that’s not my biggest issue. My biggest issue is that after throwing
   such an error, I hit ‘Back’ and the plugin page shows the thing was activated
   anyway. It’s like deactivate_plugins completely ignores me.
 * Does anyone know the reason for this?
 *  [Iva Koleva](https://wordpress.org/support/users/e-sense/)
 * (@e-sense)
 * [17 years, 11 months ago](https://wordpress.org/support/topic/force-plugin-activation-to-fail/#post-755429)
 * You could try this:
 *     ```
       //requirements check
       if(*there are missing plugin requirements*) {
               echo "Missing plugin requirements\n";
               exit;
       }
       ```
   
 * You put this before the rest of the code of your plugin.
 * So the result is, that when somebody activates the plugin and there are missing
   requirements, the plugin activation fails and the error is what you have written
   in your echo. 🙂

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Force Plugin Activation to Fail’ is closed to new replies.

## Tags

 * [fail](https://wordpress.org/support/topic-tag/fail/)

 * 3 replies
 * 4 participants
 * Last reply from: [Iva Koleva](https://wordpress.org/support/users/e-sense/)
 * Last activity: [17 years, 11 months ago](https://wordpress.org/support/topic/force-plugin-activation-to-fail/#post-755429)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
