Store uploads according to the parent post date when using year/month sub-directories

git-svn-id: http://svn.automattic.com/wordpress/trunk@9663 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
azaozz 2008-11-13 18:22:00 +00:00
parent 706f9a2c9c
commit bd2112f197
2 changed files with 7 additions and 3 deletions

View File

@ -213,7 +213,7 @@ function validate_file_to_edit( $file, $allowed_files = '' ) {
* @param array $overrides Optional. An associative array of names=>values to override default variables with extract( $overrides, EXTR_OVERWRITE ).
* @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 ) {
function wp_handle_upload( &$file, $overrides = false, $time = null ) {
// The default error handler.
if (! function_exists( 'wp_handle_upload_error' ) ) {
function wp_handle_upload_error( &$file, $message ) {
@ -281,7 +281,7 @@ function wp_handle_upload( &$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

@ -173,7 +173,11 @@ win.send_to_editor('<?php echo addslashes($html); ?>');
*/
function media_handle_upload($file_id, $post_id, $post_data = array()) {
$overrides = array('test_form'=>false);
$file = wp_handle_upload($_FILES[$file_id], $overrides);
$post = get_post($post_id);
$time = $post->post_date_gmt;
$file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
if ( isset($file['error']) )
return new WP_Error( 'upload_error', $file['error'] );