Problem with wp_create_category

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:

Read More
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?

Related posts

Leave a Reply

1 comment

  1. 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.