Ticket #7793: 7793.r9046.diff

File 7793.r9046.diff, 2.3 KB (added by jacobsantos, 5 years ago)

Error checking for the HTTP API based off of r9046

Line 
1Index: wp-admin/update-links.php
2===================================================================
3--- wp-admin/update-links.php   (revision 9046)
4+++ wp-admin/update-links.php   (working copy)
5@@ -38,6 +38,9 @@
6 
7 $response = wp_remote_get('http://api.pingomatic.com/updated-batch/', $options);
8 
9+if ( is_wp_error( $response ) )
10+       wp_die(__('Request Failed.'));
11+
12 if ( $response['response']['code'] != 200 )
13        wp_die(__('Request Failed.'));
14 
15Index: wp-includes/comment.php
16===================================================================
17--- wp-includes/comment.php     (revision 9046)
18+++ wp-includes/comment.php     (working copy)
19@@ -1316,7 +1316,10 @@
20                'excerpt' => urlencode($excerpt)
21        );
22 
23-       wp_remote_post($trackback_url, $options);
24+       $response = wp_remote_post($trackback_url, $options);
25+       
26+       if ( is_wp_error( $response ) )
27+               return;
28 
29        $tb_url = addslashes( $trackback_url );
30        $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', '$tb_url') WHERE ID = %d", $ID) );
31Index: wp-includes/functions.php
32===================================================================
33--- wp-includes/functions.php   (revision 9046)
34+++ wp-includes/functions.php   (working copy)
35@@ -1039,6 +1039,9 @@
36 
37        $response = wp_remote_request($url, $options);
38 
39+       if ( is_wp_error( $response ) )
40+               return false;
41+
42        $headers = wp_remote_retrieve_headers( $response );
43        if ( false == $file_path )
44                return $headers;
45@@ -1072,6 +1075,10 @@
46  */
47 function wp_get_http_headers( $url, $deprecated = false ) {
48        $response = wp_remote_head( $url );
49+
50+       if ( is_wp_error( $response ) )
51+               return false;
52+
53        return wp_remote_retrieve_headers( $response );
54 }
55 
56@@ -1240,11 +1247,9 @@
57  * @uses wp_remote_get()
58  *
59  * @param string $uri URI/URL of web page to retrieve.
60- * @return string HTTP content.
61+ * @return bool|string HTTP content. False on failure.
62  */
63 function wp_remote_fopen( $uri ) {
64-       // parse url() should not be used for validation of URLs.
65-       // Keeping anyway, since the Filter extension is not available on all servers.
66        $parsed_url = @parse_url( $uri );
67 
68        if ( !$parsed_url || !is_array( $parsed_url ) )
69@@ -1255,6 +1260,9 @@
70 
71        $response = wp_remote_get( $uri, $options );
72 
73+       if ( is_wp_error( $response ) )
74+               return false;
75+
76        return $response['body'];
77 }
78