Better error response when fetching attachments. Props DD32. see #7944
git-svn-id: http://svn.automattic.com/wordpress/trunk@9327 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
15a965cf80
commit
2eb1ba967f
|
@ -604,10 +604,16 @@ class WP_Import {
|
|||
// fetch the remote url and write it to the placeholder file
|
||||
$headers = wp_get_http($url, $upload['file']);
|
||||
|
||||
//Request failed
|
||||
if ( ! $headers ) {
|
||||
@unlink($upload['file']);
|
||||
return new WP_Error( 'import_file_error', __('Remote server did not respond') );
|
||||
}
|
||||
|
||||
// make sure the fetch was successful
|
||||
if ( $headers['response'] != '200' ) {
|
||||
@unlink($upload['file']);
|
||||
return new WP_Error( 'import_file_error', sprintf(__('Remote file returned error response %d'), intval($headers['response'])) );
|
||||
return new WP_Error( 'import_file_error', sprintf(__('Remote file returned error response %1$d %2$s'), $headers['response'], get_status_header_desc($headers['response']) ) );
|
||||
}
|
||||
elseif ( isset($headers['content-length']) && filesize($upload['file']) != $headers['content-length'] ) {
|
||||
@unlink($upload['file']);
|
||||
|
|
|
@ -1051,6 +1051,8 @@ function wp_get_http( $url, $file_path = false, $deprecated = false ) {
|
|||
return false;
|
||||
|
||||
$headers = wp_remote_retrieve_headers( $response );
|
||||
$headers['response'] = $response['response']['code'];
|
||||
|
||||
if ( false == $file_path )
|
||||
return $headers;
|
||||
|
||||
|
|
Loading…
Reference in New Issue