[wp-trac] [WordPress Trac] #29646: wp_insert_attachment() doesn't allow to add post_parent for orphan attachments

WordPress Trac noreply at wordpress.org
Fri Sep 12 18:12:09 UTC 2014


#29646: wp_insert_attachment() doesn't allow to add post_parent for orphan
attachments
----------------------------+-----------------------------
 Reporter:  dikiy_forester  |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  General         |    Version:  4.0
 Severity:  normal          |   Keywords:
  Focuses:                  |
----------------------------+-----------------------------
 If you try to insert orphan attachment with post_parent=0 to the post and
 pass parameter $parent, it won't has effect, because 'post_parent' from
 $args array won't be replaced with another one from $defaults array.

 {{{
 function wp_insert_attachment( $args, $file = false, $parent = 0 ) {
         $defaults = array(
                 'file'        => $file,
                 'post_parent' => $parent
         );
         $data = wp_parse_args( $args, $defaults );

         $data['post_type'] = 'attachment';

         return wp_insert_post( $data );
 }
 }}}

 In the WP3.9.2 it was treated with following code:

 {{{
         if ( !empty($parent) )
                 $object['post_parent'] = $parent;
 }}}

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


More information about the wp-trac mailing list