Make WordPress Core

Changeset 47251


Ignore:
Timestamp:
02/10/2020 11:45:50 PM (5 years ago)
Author:
SergeyBiryukov
Message:

Media: In media_sideload_image(), store the original attachment URL in the _source_url post meta value.

Props dshanske, joemcgill, antpb.
Fixes #48164.

File:
1 edited

Legend:

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

    r47219 r47251  
    968968 * @since 4.8.0 Introduced the 'id' option within the `$return` parameter.
    969969 * @since 5.3.0 The `$post_id` parameter was made optional.
     970 * @since 5.4.0 The original URL of the attachment is stored in the `_source_url`
     971 *              post meta value.
    970972 *
    971973 * @param string $file    The URL of the image to download.
    972974 * @param int    $post_id Optional. The post ID the media is to be associated with.
    973975 * @param string $desc    Optional. Description of the image.
    974  * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL), or 'id' (attachment ID). Default 'html'.
     976 * @param string $return  Optional. Accepts 'html' (image tag html) or 'src' (URL),
     977 *                        or 'id' (attachment ID). Default 'html'.
    975978 * @return string|WP_Error Populated HTML img tag on success, WP_Error object otherwise.
    976979 */
     
    10031006            @unlink( $file_array['tmp_name'] );
    10041007            return $id;
    1005             // If attachment id was requested, return it early.
    1006         } elseif ( 'id' === $return ) {
     1008        }
     1009
     1010        // Store the original attachment source in meta.
     1011        add_post_meta( $id, '_source_url', $file );
     1012
     1013        // If attachment id was requested, return it.
     1014        if ( 'id' === $return ) {
    10071015            return $id;
    10081016        }
Note: See TracChangeset for help on using the changeset viewer.