Always return upload directory information from wp_upload_dir(), even if there is an error. Append the error to the array. see #19235.

git-svn-id: http://core.svn.wordpress.org/trunk@21822 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Andrew Nacin 2012-09-11 22:06:49 +00:00
parent 3ebb9b4538
commit bc6087bc98
2 changed files with 16 additions and 9 deletions

View File

@ -1467,8 +1467,8 @@ function wp_upload_dir( $time = null ) {
$url = str_replace( UPLOADS, 'files', $url );
}
$bdir = $dir;
$burl = $url;
$basedir = $dir;
$baseurl = $url;
$subdir = '';
if ( get_option( 'uploads_use_yearmonth_folders' ) ) {
@ -1483,12 +1483,20 @@ function wp_upload_dir( $time = null ) {
$dir .= $subdir;
$url .= $subdir;
$uploads = apply_filters( 'upload_dir', array( 'path' => $dir, 'url' => $url, 'subdir' => $subdir, 'basedir' => $bdir, 'baseurl' => $burl, 'error' => false ) );
$uploads = apply_filters( 'upload_dir',
array(
'path' => $dir,
'url' => $url,
'subdir' => $subdir,
'basedir' => $basedir,
'baseurl' => $baseurl,
'error' => false,
) );
// Make sure we have an uploads dir
if ( ! wp_mkdir_p( $uploads['path'] ) ) {
$message = sprintf( __( 'Unable to create directory %s. Is its parent directory writable by the server?' ), $uploads['path'] );
return array( 'error' => $message );
$uploads['error'] = $message;
}
return $uploads;

View File

@ -223,11 +223,10 @@ function update_attached_file( $attachment_id, $file ) {
function _wp_relative_upload_path( $path ) {
$new_path = $path;
if ( ($uploads = wp_upload_dir()) && false === $uploads['error'] ) {
if ( 0 === strpos($new_path, $uploads['basedir']) ) {
$new_path = str_replace($uploads['basedir'], '', $new_path);
$new_path = ltrim($new_path, '/');
}
$uploads = wp_upload_dir();
if ( 0 === strpos( $new_path, $uploads['basedir'] ) ) {
$new_path = str_replace( $uploads['basedir'], '', $new_path );
$new_path = ltrim( $new_path, '/' );
}
return apply_filters( '_wp_relative_upload_path', $new_path, $path );