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!
get_terms
or does it just not return anything?var_dump
on $terms, I get this:object(WP_Error)#246 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(16) "Invalid taxonomy" } } ["error_data"]=> array(0) { } } object(WP_Error)#248 (2) { ["errors"]=> array(1) { ["invalid_taxonomy"]=> array(1) { [0]=> string(16) "Invalid taxonomy" } } ["error_data"]=> array(0) { } }