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?

  • 1
    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 5 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');

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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