[wp-hackers] Best way to abort Plugin installation

Otto otto at ottodestruct.com
Mon Mar 29 13:58:24 UTC 2010


Making a plugin deactivate itself is easy. Showing a pretty error
message when doing it, not so much.

Here's a simple way to deactivate:

// require PHP 5
function plugin_activation_check(){
	if (version_compare(PHP_VERSION, '5.0.0', '<')) {
		deactivate_plugins(basename(__FILE__)); // Deactivate ourself
		wp_die("Sorry, you can't activate without PHP 5.");
	}
}
register_activation_hook(__FILE__, 'plugin_activation_check');

The problem is that you really can't do anything else here in a nice
way except wp_die.

The page call that actually activates the plugin does a wp_redirect
back to the plugins.php page. So on that redirected page load, your
plugin isn't active anymore, and thus you have no way to display a
message.

-Otto


More information about the wp-hackers mailing list