[wp-trac] [WordPress Trac] #30454: A slug can't be registered when it uses wp_insert_post fuinction in wp_cron event

WordPress Trac noreply at wordpress.org
Sat Nov 22 08:23:20 UTC 2014


#30454: A slug can't be registered when it uses wp_insert_post fuinction in wp_cron
event
-------------------------------+-----------------------------
 Reporter:  horike             |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  trunk
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 When I execute below program, the slug is empty.
 If post_status is pending, It occurs.
 {{{
 add_filter( 'cron_schedules', function() {
         $schedules['panpanpan'] = array( 'interval' => 60, 'display' => 1
 . 'min' );
         return $schedules;
 } );

 register_activation_hook( __FILE__, function(){
         $interval = 60;
         $action_time = time() + $interval;
         wp_clear_scheduled_hook( 'panpanpan_event' );
         wp_schedule_event( $action_time, 'panpanpan', 'panpanpan_event' );
 } );

 add_action( 'panpanpan_event', function() {
         $args = array(
                 'post_name' => 'test_slug_' . time(),
                 'post_date' => date_i18n('Y/m/d'),
                 'post_type' => 'post',
                 'post_status' => 'pending',
                 'post_title' => 'title',
                 'post_content' => 'content'
         );
         wp_insert_post($args);
 } );

 }}}

 wp-includes/post.php line 3165 - 3167. I think that current_user_can
 function  is not operate in wp_cron event.
 {{{
 if ( 'pending' == $post_status && !current_user_can( 'publish_posts' ) ) {
         $post_name = '';
 }
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/30454>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list