Before copying files (rename()
) to the final destination I set time parameter for wp_upload_dir()
(instead of trying to make wp_handle_upload()
to pass it) and it transfers files to appropriate directories now.
$uploads = wp_upload_dir( $upload_date );
$output_dir = $uploads[ 'path' ];
rename( $filename, $new_filepath );