Make WordPress Core

Changeset 22105


Ignore:
Timestamp:
10/03/2012 06:49:37 PM (12 years ago)
Author:
nacin
Message:

Pass the post date to wp_upload_dir() during sideloads, just as we do uploads. Ensures that sideloaded images make it into the right uploads directory.

props solarisssmoke, fixes #16777.

Location:
trunk/wp-admin/includes
Files:
2 edited

Legend:

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

    r21350 r22105  
    22/**
    33 * Functions for reading, writing, modifying, and deleting files on the file system.
    4  * Includes functionality for theme-specific files as well as operations for uploading, 
     4 * Includes functionality for theme-specific files as well as operations for uploading,
    55 * archiving, and rendering output when necessary.
    66 *
     
    228228 * @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file.
    229229 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
     230 * @param string $time Optional. Time formatted in 'yyyy/mm'.
    230231 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
    231232 */
     
    360361 * @param array $file an array similar to that of a PHP $_FILES POST array
    361362 * @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
     363 * @param string $time Optional. Time formatted in 'yyyy/mm'.
    362364 * @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
    363365 */
    364 function wp_handle_sideload( &$file, $overrides = false ) {
     366function wp_handle_sideload( &$file, $overrides = false, $time = null ) {
    365367    // The default error handler.
    366368    if (! function_exists( 'wp_handle_upload_error' ) ) {
     
    439441
    440442    // A writable uploads dir will pass this test. Again, there's no point overriding this one.
    441     if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
     443    if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) )
    442444        return $upload_error_handler( $file, $uploads['error'] );
    443445
  • trunk/wp-admin/includes/media.php

    r22093 r22105  
    270270    $overrides = array('test_form'=>false);
    271271
    272     $file = wp_handle_sideload($file_array, $overrides);
     272    $time = current_time( 'mysql' );
     273    if ( $post = get_post( $post_id ) ) {
     274        if ( substr( $post->post_date, 0, 4 ) > 0 )
     275            $time = $post->post_date;
     276    }
     277
     278    $file = wp_handle_sideload( $file_array, $overrides, $time );
    273279    if ( isset($file['error']) )
    274280        return new WP_Error( 'upload_error', $file['error'] );
Note: See TracChangeset for help on using the changeset viewer.