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 ){
register_deactivation_hook( __FILE__, 'ppcontent_deactivate' );

1 Answer 1


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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