So, if a plugin should not ever be installed on an older version of WordPress, whats the best way to go about it? What I normally do is something like this:

if ( ! function_exists( 'get_post_format' ) ) {
    $error_handler = set_error_handler( 'my_plugin_die' );
    trigger_error( '', E_USER_ERROR );

function my_plugin_die( $errno, $errstr, $errfile, $errline ) {
    global $wp_version;
    exit( 'This plugin requires WordPress version 3.0 or greater. You are currently using version ' . $wp_version . '. Please <a target="_top" href="' . esc_url( admin_url( 'update-core.php' ) ) . '">upgrade to the latest version of WordPress</a> before installing this plugin.' );

I place this straight in the plugin file - outside of any class. It seems to work well in all of my testing, but seems rather harsh. Is there any chance of a plugin having this code will ever be activated?

How to you deal with situations like this? There seems to be absolutely no documentation on this kind of thing.

1 Answer 1


I think you're taking the right approach: version-checking and die. The only thing I might recommend would be to hook it into the Plugin activation hook.

Out of curiosity, though: why aren't you using wp_die() (Codex ref)?

As a side note: I would love to see the Theme and Plugin repositories implement some sort of UI similar to AMO, that indicates whether a given Theme/Plugin is compatible with the user's current WordPress version. Plugins have a Requires: WordPress-version header tag that would work sufficiently for this functionality, and I would think that Themes could implement the same, just as easily.

p.s. I would strongly recommend against using the "Compatibility rating"; that functionality is beyond broken.

  • Plugin activation hook might be a good idea. I'll have to look into it and do some testing. wp_die() is anot a good choice here imo. The goal is to have a message printed in the little yellow box where the plugins errors are printed when they cannot be installed. Doesn't make sense to me to bring the user to a page that they have probably never seen before that has no navigation.
    – mfields
    Commented Jul 17, 2011 at 19:12
  • Hmm... let's investigate, and see if there's a way to hook into that particular Admin Alert. There probably is... Commented Jul 17, 2011 at 19:21
  • Thanks for taking a look :) I haven't treally looked into this too deeply since 3.0. At that time this was the only method I found that provided the results that I was after.
    – mfields
    Commented Jul 17, 2011 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.