From 9e467a68509ee46ea6df11cdb0955ec5d4781652 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Fri, 24 Oct 2008 18:22:43 +0000 Subject: [PATCH] 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 --- wp-admin/import/wordpress.php | 8 +++++++- wp-includes/functions.php | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/wp-admin/import/wordpress.php b/wp-admin/import/wordpress.php index dfed4012cf..40e84a7cc9 100644 --- a/wp-admin/import/wordpress.php +++ b/wp-admin/import/wordpress.php @@ -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']); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index ab8c818c9d..282bab9364 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -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;