how is it possible that using wp_insert_category throw a fatal error?

how is it possible that using wp_insert_category throw a fatal error ?

I am using it as explained : http://codex.wordpress.org/Function_Reference/wp_insert_category
with no change except:

$cat_defaults = array(
    'cat_name' => 'some_name',
    'category_description' => 'as asdfasdf sdf adfa fas f',
    'category_nicename' => '',
    'category_parent' => '',
    'taxonomy' => 'category'
 );
$someSome = wp_insert_category($cat_defaults);

i dont know if its relevant however i execute it on add_action( 'init', array($this, 'registerCustoms') );

And i get the following error :

Fatal error: Call to undefined function wp_insert_category() in /home1/stodeckc/public_html/podio-wp-sync/wp-content/plugins/podio_management/libs/appSync/appSync_custom.php on line 61

Any ideas?

4 Answers
4

The init action is the wrong place. This is because init runs on all requests, admin or front-end, but the wp_insert_category function is an admin-side only function. You generally don’t insert categories from the front end.

Move to a more specific action, one that will be run in the admin side. Probably from your plugin’s admin pages.

Leave a Comment