Make WordPress Core

Changeset 16383


Ignore:
Timestamp:
11/15/2010 12:53:11 PM (14 years ago)
Author:
scribu
Message:

Make media_handle_sideload() return attachment id instead of URL. Props joostdevalk. Fixes #15432

File:
1 edited

Legend:

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

    r16340 r16383  
    240240
    241241/**
    242  * {@internal Missing Short Description}}
    243  *
    244  * @since unknown
    245  *
    246  * @param unknown_type $file_array
    247  * @param unknown_type $post_id
    248  * @param unknown_type $desc
    249  * @param unknown_type $post_data
    250  * @return unknown
     242 * This handles a sideloaded file in the same way as an uploaded file is handled by {@link media_handle_upload()}
     243 *
     244 * @since 2.6
     245 *
     246 * @param array $file_array Array similar to a {@link $_FILES} upload array
     247 * @param int $post_id The post ID the media is associated with
     248 * @param string $desc Description of the sideloaded file
     249 * @param array $post_data allows you to overwrite some of the attachment
     250 * @return int|object The ID of the attachment or a WP_Error on failure
    251251 */
    252252function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
     
    284284    // Save the attachment metadata
    285285    $id = wp_insert_attachment($attachment, $file, $post_id);
    286     if ( !is_wp_error($id) ) {
     286    if ( !is_wp_error($id) )
    287287        wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
    288         return $url;
    289     }
     288
    290289    return $id;
    291290}
     
    519518
    520519        // If error storing temporarily, unlink
    521         if ( is_wp_error($tmp) ) {
     520        if ( is_wp_error( $tmp ) ) {
    522521            @unlink($file_array['tmp_name']);
    523522            $file_array['tmp_name'] = '';
     
    525524
    526525        // do the validation and storage stuff
    527         $id = media_handle_sideload($file_array, $post_id, @$desc);
    528         $src = $id;
     526        $id = media_handle_sideload( $file_array, $post_id, @$desc );
     527        $src = get_attachment_link( $id );
    529528
    530529        // If error storing permanently, unlink
Note: See TracChangeset for help on using the changeset viewer.