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 Jul 22, 2011 at 16:59
  • Custom fields for authors.
    – AmberKayle
    Jul 28, 2011 at 18:58

1 Answer 1


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 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.