Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.