WordPress.org

Make WordPress Core

Ticket #19629: sideload_id_19629.2.diff

File sideload_id_19629.2.diff, 1.3 KB (added by mikeschroder, 3 years ago)

Adding @since for feature and applies from src/

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

    diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php
    index c4090174f..4a2e7c2e7 100644
    function wp_media_upload_handler() { 
    852852 *
    853853 * @since 2.6.0
    854854 * @since 4.2.0 Introduced the `$return` parameter.
     855 * @since 4.8.0 Introduced the 'id' option within the `$return` parameter.
    855856 *
    856857 * @param string $file    The URL of the image to download.
    857858 * @param int    $post_id The post ID the media is to be associated with.
    858859 * @param string $desc    Optional. Description of the image.
    859  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL). Default 'html'.
     860 * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
    860861 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
    861862 */
    862863function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) {
    function media_sideload_image( $file, $post_id, $desc = null, $return = 'html' ) 
    886887                if ( is_wp_error( $id ) ) {
    887888                        @unlink( $file_array['tmp_name'] );
    888889                        return $id;
     890                // If attachment id was requested, return it early.
     891                } elseif ( $return === 'id' ) {
     892                        return $id;
    889893                }
    890894
    891895                $src = wp_get_attachment_url( $id );