[wp-trac] [WordPress Trac] #19373: wp_insert_post() should not contain current_user_can() checks

WordPress Trac noreply at wordpress.org
Fri Apr 12 08:54:06 UTC 2019

#19373: wp_insert_post() should not contain current_user_can() checks
 Reporter:  alexkingorg  |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  Future Release
Component:  Taxonomy     |     Version:  3.0
 Severity:  major        |  Resolution:
 Keywords:  has-patch    |     Focuses:

Comment (by kevinwhoffman):

 I just wasted hours trying to figure out why terms were not being assigned
 when `wp_insert_post()` was called via WP Cron. After finding this ticket,
 I discovered that a user capability check is preventing terms from being
 assigned because there is no user in WP Cron.

 For those looking to assign terms from a custom taxonomy to a post via WP
 Cron, you will have to call `wp_set_post_terms()` after `wp_insert_post()`
 as mentioned in the original report. Here is a snippet that allows you to
 assign terms using the same post array that you would normally pass to

 foreach( $post_array['tax_input'] as $taxonomy => $terms ) {
         wp_set_post_terms( $post_id, $terms, $taxonomy  );

Ticket URL: <https://core.trac.wordpress.org/ticket/19373#comment:48>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list