Make WordPress Core


Ignore:
Timestamp:
08/30/2017 03:03:08 PM (7 years ago)
Author:
joemcgill
Message:

Media: Ensure 'media_handle_upload()' returns 'WP_Error' on failure.

This fixes an issue where failures when inserting the attachment post via
wp_insert_attachment() would result in a return value of 0 instead of a
WP_Error object, as documented. This is addressed by passing true as the
fourth param (added in WP 4.7.0) when calling wp_insert_attachment().

Props mrasharirfan, flixos90.
Fixes #41726.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r40597 r41323  
    379379
    380380    // Save the data
    381     $id = wp_insert_attachment($attachment, $file, $post_id);
     381    $id = wp_insert_attachment( $attachment, $file, $post_id, true );
    382382    if ( !is_wp_error($id) ) {
    383383        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
Note: See TracChangeset for help on using the changeset viewer.