﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	severity	resolution	keywords	cc
12629	function to remove custom taxonomies and all their terms	sillybean		"I think there should be an easy way for plugins that create custom taxonomies to clean up after themselves on deactivation. I went over taxonomy.php pretty thoroughly and didn't find anything that does this directly.

The function below removes the custom taxonomies and terms from the various tables while leaving the built-in taxonomies alone.

{{{
<php
/*
assuming taxonomies for actor, director, and genre have been created on plugin activation...
*/

function remove_taxonomy($taxonomy) {
	if (!$taxonomy->_builtin) {
		global $wp_taxonomies;
		$terms = get_terms($taxonomy); 
		foreach ($terms as $term) {
			wp_delete_term( $term->term_id, $taxonomy );
		}
		unset($wp_taxonomies[$taxonomy]);
	}
}

function deactivate_custom_taxes() {
	remove_taxonomy('genre');
	remove_taxonomy('actor');
	remove_taxonomy('director');
	remove_taxonomy('post_tag');  // this will fail silently
	// do we need to flush the rewrite rules? 
	$GLOBALS['wp_rewrite']->flush_rules();
}

register_deactivation_hook( __FILE__, 'deactivate_custom_taxes' );
?>
}}}

If you like the idea, the remove_taxonomy() function could go into taxonomy.php, and then we'd document the deactivation procedure."	feature request	assigned	normal	Future Release	Taxonomy		normal			steph@… kevinB 24-7@…
