[wp-trac] [WordPress Trac] #37813: Missing $wp_error parameter for wp_insert_attachment

WordPress Trac noreply at wordpress.org
Wed Aug 24 15:37:39 UTC 2016


#37813: Missing $wp_error parameter for wp_insert_attachment
----------------------------+-----------------------------
 Reporter:  grapplerulrich  |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Media           |    Version:  2.0
 Severity:  normal          |   Keywords:
  Focuses:  administration  |
----------------------------+-----------------------------
 `wp_insert_attachment()` uses `wp_insert_post()` which has a parameter
 whether to allow return of WP_Error on failure.

 It is not possible to do the same for `wp_insert_attachment()`.

 This would be my suggested patch.

 {{{#!php
 <?php
 function wp_insert_attachment( $args, $file = false, $parent = 0,
 $wp_error = false ) {
     $defaults = array(
         'file'        => $file,
         'post_parent' => 0
     );

     $data = wp_parse_args( $args, $defaults );

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

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

     return wp_insert_post( $data, $wp_error );
 }
 }}}


 Related: #32318

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


More information about the wp-trac mailing list