My plugin code is below. In the myPlugin_cleanup() function, I’m creating some categories and assigning term id 1 as the parent.
Due to the known bug with creating categories via script (the category_children array does not get created and results in a fatal error when pages containing category listings are accessed), I’ve placed the clean_term_cache() call directly below the function that creates my categories.
However, its not working. The category_children option is not getting created.
Interestingly, if I create a plugin whose sole function is to execute the clean_term_cache(”,’category’) call, it fixes the problem and creates the category_children option with the correct values.
I’m just not sure why its not working in the same plugin that creates the categories.
What might I be missing?
function myPlugin_activate(){
if ( get_option( 'myPlugin_activated' ) !== "1"){
//comment out any function you don't want to run
myPlugin_copy('themes');
myPlugin_copy('plugins');
myPlugin_images();
myPlugin_options();
myPlugin_settings();
myPlugin_widgets();
myPlugin_links();
myPlugin_posts();
myPlugin_pages();
myPlugin_custom_menus();
myPlugin_cleanup();
clean_term_cache('','category'); //does not work here
update_option('myPlugin_activated', "1");
}
}
function myPlugin_cleanup(){
//include dependencies
require_once(ABSPATH.'/wp-admin/includes/taxonomy.php');
if(!get_cat_ID('nofollow')){wp_create_category('nofollow',1);}
if(!get_cat_ID('noindex')){wp_create_category('noindex',1);}
clean_term_cache('','category'); //Does not appear to work here either.
}
register_activation_hook(__FILE__, 'myPlugin_activate');
?>