Better error response when fetching attachments. Props DD32. see #7944
git-svn-id: https://develop.svn.wordpress.org/trunk@9327 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
979442ccd6
commit
9e467a6850
@ -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
Block a user