Add custom taxonomy for publication through cron job

I am trying to add custom taxonomy with post using cron job. The problem is that from wordpress 4.7, it verifies if the current user has the ability to assign taxonomy. Crob's work does not have the capacity.

I am using this to register custom taxonomoy




add_action (& # 39; init & # 39 ;, & # 39; create_locations_hierarchical_taxonomy & # 39 ;, 0);

function create_locations_hierarchical_taxonomy () {

// Add new taxonomy, make it hierarchical as categories
// first do the part of the translations for GUI

$ labels = array (
& # 39; name & # 39; => _x (& # 39; Locations & # 39 ;, & # 39; general name of taxonomy & # 39;),
& # 39; singular_name & # 39; => _x (& # 39; Location & # 39 ;, & # 39; singular name of taxonomy & # 39;),
& # 39; search_items & # 39; => __ (& # 39; Search Locations & # 39;),
& # 39; all_items & # 39; => __ (& # 39; All locations & # 39;),
& # 39; parent_item & # 39; => __ (& # 39; Location of the father & # 39;),
& # 39; parent_item_colon & # 39; => __ (& # 39; Parent Location: & # 39;),
& # 39; edit_item & # 39; => __ (& # 39; Edit location & # 39;),
& # 39; update_item & # 39; => __ (& # 39; Update location & # 39;),
& # 39; add_new_item & # 39; => __ (& # 39; Add new location & # 39;),
& # 39; new_item_name & # 39; => __ (& # 39; New Location Name & # 39;),
& # 39; menu_name & # 39; => __ (& # 39; Locations & # 39;),
);

// Now register the taxonomy

register_taxonomy (& # 39; location & # 39 ;, array (& # 39; post & # 39;), array (
& # 39; hierarchical & # 39; => true,
& # 39; labels & # 39; => $ tags,
& # 39; show_ui & # 39; => true,
& # 39; show_admin_column & # 39; => true,
& # 39; query_var & # 39; => true,
& # 39; rewrite & # 39; => array (& # 39; slug & # 39; => & # 39; location & # 39;),
));

And this script to assign taxonomy matrix with $ post_arr

        
        
        
        $ post_location = array_map (& # 39; intval & # 39 ;, $ post_location);
if ($ post_type == & # 39; post & # 39;) {
$ post_arr['tax_input'] = $ post_location;
}

Currently, my script can create a custom taxonomy but can not be assigned with a publication.

Referee:
https://core.trac.wordpress.org/browser/tags/5.1/src/wp-includes/post.php#L3784