2

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' );
2
  • 2
    have you looked here ? wordpress.stackexchange.com/questions/25910/…
    – user13279
    Commented Jan 4, 2012 at 8:16
  • Can you please post your solution as an answer so we can close this question out and help others looking for answers. Thanks! :) Commented Feb 7, 2012 at 3:03

1 Answer 1

3

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.

1
  • agree... delete things when the plugin is uninstalled, not deactivated. i deactivate stuff all the time when i need to debug things. Commented Feb 11, 2012 at 4:13

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.