deactivate_plugins not working in my register_activation_hook function

I just figured out for myself, after not being able to get the deactivate_plugins function to work and not finding any helpful documentation on it, how to prevent my plugin from being activated under certain conditions.
My new workaround is to use die() in my register_activation_hook, under the desired condition. Now, I know you are not supposed to put any output in your register_activation_hook function, but it just works perfectly for me. It successfully stopped the activation of my plugin, and it even put the text from my die statement nicely into the box at the top that tells the user that the plugin could not be activated. I had also tried using wp_die() but it really did die with nothing on the screen but my message in a box. I liked it better just using die().
In my install function I put:

global $wp_version;
if (version_compare($wp_version, "2.6", "<"))
	die("This Plugin requires WordPress version 2.6 or higher");

This way people can only install my plugin if they are not running a really old version of WordPress.

2 thoughts on “deactivate_plugins not working in my register_activation_hook function

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.