Make WordPress Core

Ticket #19629: sideload_id_19629.diff

File sideload_id_19629.diff, 1.2 KB (added by MrGregWaugh, 8 years ago)

Patch to return id that includes is_wp_error() check

  • html/wp-admin/includes/media.php

    diff --git a/html/wp-admin/includes/media.php b/html/wp-admin/includes/media.php
    index ede25b3..3dcf91a 100644
    a b function wp_media_upload_handler() { 
    856856 * @param string $file    The URL of the image to download.
    857857 * @param int    $post_id The post ID the media is to be associated with.
    858858 * @param string $desc    Optional. Description of the image.
    859  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.
     859 * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
    860860 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
    861861 */
    862862function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
    function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) 
    886886                if ( is_wp_error( $id ) ) {
    887887                        @unlink( $file_array['tmp_name'] );
    888888                        return $id;
     889                // If attachment id was requested, return it early.
     890                } elseif ( $return === 'id' ) {
     891                        return $id;
    889892                }
    890893
    891894                $src = wp_get_attachment_url( $id );