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 created a list of terms under 'category' when activate plugin. When deactive the plugin, I want to delete them. My function doesn't work, how to make this working?

function ppcontent_deactivate() {

    $terms = get_terms( 'category' );

    foreach( $terms as $term ){
        wp_delete_term($term->term_id,'category');
    }
}
register_deactivation_hook( __FILE__, 'ppcontent_deactivate' );
share|improve this question
2  
have you looked here ? wordpress.stackexchange.com/questions/25910/… –  user13279 Jan 4 '12 at 8:16
    
that helps, thanks! –  Jenny Jan 4 '12 at 9:26
    
Can you please post your solution as an answer so we can close this question out and help others looking for answers. Thanks! :) –  Brian Fegter Feb 7 '12 at 3:03

1 Answer 1

up vote 3 down vote accepted

I recommend not deleting the terms at the point of deactivation.

Instead why don't you delete the terms at the point of uninstallation?

You can use the uninstall hook: http://codex.wordpress.org/Function_Reference/register_uninstall_hook

Or bypass that.

The plugin should create a file named 'uninstall.php' in the base plugin folder. This file will be called, if it exists, during the uninstall process bypassing the uninstall hook.

This may be easier to manage code wise and sometimes people would like to deactivate a plugin and not lose all their data.

share|improve this answer
    
agree... delete things when the plugin is uninstalled, not deactivated. i deactivate stuff all the time when i need to debug things. –  helgatheviking Feb 11 '12 at 4:13

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.