Site icon Hip-Hop Website Design and Development

How to remove plugin-specific custom taxonomy terms when plugin is uninstalled?

I’m trying to write a class that would allow for easy removal of all plugin-related data when the plugin is uninstalled. Specifically, I want it to remove plugin options, custom post type entries, and custom taxonomies and their terms.

What I have written mostly works, but the get_terms function returns an ‘invalid_taxonomy’ error. Looking into it further, I found that the global $wp_taxonomies does not recognize the custom taxonomies created by the plugin during the uninstall.php process.

So my question is: How does one remove custom taxonomy terms when a plugin is uninstalled?

Here is my code: http://pastebin.com/geH1wzRC

Bonus points if you can tell me how to avoid loading this class twice if two plugins contain it. I tried just wrapping the class in if( !class_exists( 'WP_Plugin_Janitor' ) ) { ... } but then the class never loaded.

EDIT I was able to prevent the class from loading more than once by putting the class in a separate file and wrapping the include_once statement in the if( !class_exists( statement.

Thanks in advance!