I have simple code:
add_action('init', 'categoryTransfer');
function categoryTransfer(){
//some code
for($i=0; $i < count($categories); $i++)
wp_create_category($categories[$i]->name);
}
But when it executes i get:
Fatal error: Call to undefined function wp_create_category() in /Users/noname/Sites/wp-content/plugins/my_plugin/my_plugin.php on line 95
Where is a problem?
This function is declared in
wp-admin/includes/taxonomy.php
.This file will be loaded in
wp-admin/includes/admin.php
.And that now is called in
wp-admin/admin.php
.So the solution is: Use the hook
'admin_init'
or require all necessary files manually. But donât do that on every request.