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.



git-svn-id: http://core.svn.wordpress.org/trunk@22105 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-10-03 18:49:37 +00:00
parent 6774dba76d
commit 4cbc20ada1
2 changed files with 12 additions and 4 deletions

View File

@ -1,7 +1,7 @@
<?php
/**
* Functions for reading, writing, modifying, and deleting files on the file system.
* Includes functionality for theme-specific files as well as operations for uploading,
* Includes functionality for theme-specific files as well as operations for uploading,
* archiving, and rendering output when necessary.
*
* @package WordPress
@ -227,6 +227,7 @@ function validate_file_to_edit( $file, $allowed_files = '' ) {
* @uses delete_transient
* @param array $file Reference to a single element of $_FILES. Call the function once for each uploaded file.
* @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
* @param string $time Optional. Time formatted in 'yyyy/mm'.
* @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
*/
function wp_handle_upload( &$file, $overrides = false, $time = null ) {
@ -359,9 +360,10 @@ function wp_handle_upload( &$file, $overrides = false, $time = null ) {
* @uses wp_unique_filename
* @param array $file an array similar to that of a PHP $_FILES POST array
* @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
* @param string $time Optional. Time formatted in 'yyyy/mm'.
* @return array On success, returns an associative array of file attributes. On failure, returns $overrides['upload_error_handler'](&$file, $message ) or array( 'error'=>$message ).
*/
function wp_handle_sideload( &$file, $overrides = false ) {
function wp_handle_sideload( &$file, $overrides = false, $time = null ) {
// The default error handler.
if (! function_exists( 'wp_handle_upload_error' ) ) {
function wp_handle_upload_error( &$file, $message ) {
@ -438,7 +440,7 @@ function wp_handle_sideload( &$file, $overrides = false ) {
}
// A writable uploads dir will pass this test. Again, there's no point overriding this one.
if ( ! ( ( $uploads = wp_upload_dir() ) && false === $uploads['error'] ) )
if ( ! ( ( $uploads = wp_upload_dir( $time ) ) && false === $uploads['error'] ) )
return $upload_error_handler( $file, $uploads['error'] );
$filename = wp_unique_filename( $uploads['path'], $file['name'], $unique_filename_callback );

View File

@ -269,7 +269,13 @@ function media_handle_upload($file_id, $post_id, $post_data = array(), $override
function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_sideload($file_array, $overrides);
$time = current_time( 'mysql' );
if ( $post = get_post( $post_id ) ) {
if ( substr( $post->post_date, 0, 4 ) > 0 )
$time = $post->post_date;
}
$file = wp_handle_sideload( $file_array, $overrides, $time );
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );