WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a plugin that will be using custom fields added by a theme.

Because of this, it would be ideal if my plugin not be able to activate should these fields not exist.

How do I go about displaying an error and forcing the activation to fail?

share|improve this question
Custom fields as in post meta? Sounds kind of weird, because you would need to check all post meta on activation – onetrickpony Jul 22 '11 at 16:59
Custom fields for authors. – AmberKayle Jul 28 '11 at 18:58
up vote 2 down vote accepted

Code like this can do the trick.

function plugin_activation_check(){
    if ( some_check_here() ) {
        // this is the fail case
        deactivate_plugins(basename(__FILE__)); // Deactivate ourself
        wp_die("Message to user.");
register_activation_hook(__FILE__, 'plugin_activation_check');
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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