Make WordPress Core

Ticket #37813: 37813.diff

File 37813.diff, 1.2 KB (added by mrahmadawais, 8 years ago)

Enhancement: wp_insert_attachment can now return WP_Error on failure

  • wp-includes/post.php

     
    46974697 *
    46984698 * @see wp_insert_post()
    46994699 *
    4700  * @param string|array $args   Arguments for inserting an attachment.
    4701  * @param string       $file   Optional. Filename.
    4702  * @param int          $parent Optional. Parent post ID.
    4703  * @return int Attachment ID.
     4700 * @param string|array  $args   Arguments for inserting an attachment.
     4701 * @param strings               $file   Optional. Filename.
     4702 * @param int                   $parent Optional. Parent post ID.
     4703 * @param bool                  $wp_error Optional. Whether to allow return of WP_Error on failure. Default false.
     4704 * @return int|WP_Error The Attachment ID on success. If set true WP_Error on failure.
    47044705 */
    4705 function wp_insert_attachment( $args, $file = false, $parent = 0 ) {
     4706function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) {
    47064707        $defaults = array(
    47074708                'file'        => $file,
    47084709                'post_parent' => 0
     
    47164717
    47174718        $data['post_type'] = 'attachment';
    47184719
    4719         return wp_insert_post( $data );
     4720        return wp_insert_post( $data, $wp_error );
    47204721}
    47214722
    47224723/**