From 33bcf4ec8712eef5c4b5077a136e26b5b3a5e1ce Mon Sep 17 00:00:00 2001 From: ryan Date: Thu, 2 Oct 2008 00:32:21 +0000 Subject: [PATCH] Error checking for HTTP requests. Props jacobsantos. see #7793 git-svn-id: http://svn.automattic.com/wordpress/trunk@9051 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/update-links.php | 3 +++ wp-includes/comment.php | 5 ++++- wp-includes/functions.php | 14 +++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/wp-admin/update-links.php b/wp-admin/update-links.php index 976769d23..a60aa6e44 100644 --- a/wp-admin/update-links.php +++ b/wp-admin/update-links.php @@ -38,6 +38,9 @@ $options['headers'] = array( $response = wp_remote_get('http://api.pingomatic.com/updated-batch/', $options); +if ( is_wp_error( $response ) ) + wp_die(__('Request Failed.')); + if ( $response['response']['code'] != 200 ) wp_die(__('Request Failed.')); diff --git a/wp-includes/comment.php b/wp-includes/comment.php index aa773857c..a5e344651 100644 --- a/wp-includes/comment.php +++ b/wp-includes/comment.php @@ -1316,7 +1316,10 @@ function trackback($trackback_url, $title, $excerpt, $ID) { 'excerpt' => urlencode($excerpt) ); - wp_remote_post($trackback_url, $options); + $response = wp_remote_post($trackback_url, $options); + + if ( is_wp_error( $response ) ) + return; $tb_url = addslashes( $trackback_url ); $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = %d", $ID) ); diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 3aaa53533..45fae39e0 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1039,6 +1039,9 @@ function wp_get_http( $url, $file_path = false, $deprecated = false ) { $response = wp_remote_request($url, $options); + if ( is_wp_error( $response ) ) + return false; + $headers = wp_remote_retrieve_headers( $response ); if ( false == $file_path ) return $headers; @@ -1072,6 +1075,10 @@ function wp_get_http( $url, $file_path = false, $deprecated = false ) { */ function wp_get_http_headers( $url, $deprecated = false ) { $response = wp_remote_head( $url ); + + if ( is_wp_error( $response ) ) + return false; + return wp_remote_retrieve_headers( $response ); } @@ -1240,11 +1247,9 @@ function add_magic_quotes( $array ) { * @uses wp_remote_get() * * @param string $uri URI/URL of web page to retrieve. - * @return string HTTP content. + * @return bool|string HTTP content. False on failure. */ function wp_remote_fopen( $uri ) { - // parse url() should not be used for validation of URLs. - // Keeping anyway, since the Filter extension is not available on all servers. $parsed_url = @parse_url( $uri ); if ( !$parsed_url || !is_array( $parsed_url ) ) @@ -1255,6 +1260,9 @@ function wp_remote_fopen( $uri ) { $response = wp_remote_get( $uri, $options ); + if ( is_wp_error( $response ) ) + return false; + return $response['body']; }