Ticket #17416: 17416.2.diff

File 17416.2.diff, 12.1 KB (added by aaroncampbell, 2 years ago)
Line 
1Index: wp-admin/includes/dashboard.php
2===================================================================
3--- wp-admin/includes/dashboard.php     (revision 17916)
4+++ wp-admin/includes/dashboard.php     (working copy)
5@@ -1208,10 +1208,10 @@
6                        'user-agent'    => 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )
7                );
8 
9-               $raw_response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
10+               $response = wp_remote_post( 'http://api.wordpress.org/core/browse-happy/1.0/', $options );
11 
12-               if ( is_wp_error( $raw_response ) || 200 != $raw_response['response']['code'] )
13-                       return;
14+               if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
15+                       return false;
16 
17                /**
18                 * Response should be an array with:
19@@ -1224,7 +1224,7 @@
20                 *  'img_src' - string - An image representing the browser
21                 *  'img_src_ssl' - string - An image (over SSL) representing the browser
22                 */
23-               $response = unserialize( $raw_response['body'] );
24+               $response = unserialize( wp_remote_retrieve_body( $response ) );
25 
26                if ( ! $response )
27                        return;
28Index: wp-admin/includes/file.php
29===================================================================
30--- wp-admin/includes/file.php  (revision 17916)
31+++ wp-admin/includes/file.php  (working copy)
32@@ -490,9 +490,9 @@
33                return $response;
34        }
35 
36-       if ( $response['response']['code'] != '200' ){
37+       if ( 200 != wp_remote_retrieve_response_code( $response ) ){
38                unlink( $tmpfname );
39-               return new WP_Error( 'http_404', trim( $response['response']['message'] ) );
40+               return new WP_Error( 'http_404', trim( wp_remote_retrieve_response_message( $response ) ) );
41        }
42 
43        return $tmpfname;
44Index: wp-admin/includes/plugin-install.php
45===================================================================
46--- wp-admin/includes/plugin-install.php        (revision 17916)
47+++ wp-admin/includes/plugin-install.php        (working copy)
48@@ -45,9 +45,9 @@
49                if ( is_wp_error($request) ) {
50                        $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
51                } else {
52-                       $res = unserialize($request['body']);
53+                       $res = unserialize( wp_remote_retrieve_body( $request ) );
54                        if ( false === $res )
55-                               $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), $request['body']);
56+                               $res = new WP_Error('plugins_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
57                }
58        } elseif ( !is_wp_error($res) ) {
59                $res->external = true;
60@@ -367,4 +367,3 @@
61        exit;
62 }
63 add_action('install_plugins_pre_plugin-information', 'install_plugin_information');
64-
65Index: wp-admin/includes/schema.php
66===================================================================
67--- wp-admin/includes/schema.php        (revision 17916)
68+++ wp-admin/includes/schema.php        (working copy)
69@@ -762,7 +762,7 @@
70                $page = wp_remote_get( 'http://' . $hostname, array( 'timeout' => 5, 'httpversion' => '1.1' ) );
71                if ( is_wp_error( $page ) )
72                        $errstr = $page->get_error_message();
73-               elseif ( 200 == $page['response']['code'] )
74+               elseif ( 200 == wp_remote_retrieve_response_code( $page ) )
75                                $vhost_ok = true;
76 
77                if ( ! $vhost_ok ) {
78Index: wp-admin/includes/theme.php
79===================================================================
80--- wp-admin/includes/theme.php (revision 17916)
81+++ wp-admin/includes/theme.php (working copy)
82@@ -396,9 +396,9 @@
83                if ( is_wp_error($request) ) {
84                        $res = new WP_Error('themes_api_failed', __('An Unexpected HTTP Error occurred during the API request.'), $request->get_error_message() );
85                } else {
86-                       $res = unserialize($request['body']);
87+                       $res = unserialize( wp_remote_retrieve_body( $request ) );
88                        if ( ! $res )
89-                       $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), $request['body']);
90+                       $res = new WP_Error('themes_api_failed', __('An unknown error occurred.'), wp_remote_retrieve_body( $request ) );
91                }
92        }
93        //var_dump(array($args, $res));
94Index: wp-includes/class-feed.php
95===================================================================
96--- wp-includes/class-feed.php  (revision 17916)
97+++ wp-includes/class-feed.php  (working copy)
98@@ -80,9 +80,9 @@
99                                $this->error = 'WP HTTP Error: ' . $res->get_error_message();
100                                $this->success = false;
101                        } else {
102-                               $this->headers = $res['headers'];
103-                               $this->body = $res['body'];
104-                               $this->status_code = $res['response']['code'];
105+                               $this->headers = wp_remote_retrieve_headers( $res );
106+                               $this->body = wp_remote_retrieve_body( $res );
107+                               $this->status_code = wp_remote_retrieve_response_code( $res );
108                        }
109                } else {
110                        if ( ! $this->body = file_get_contents($url) ) {
111@@ -91,4 +91,4 @@
112                        }
113                }
114        }
115-}
116\ No newline at end of file
117+}
118Index: wp-includes/class-wp-http-ixr-client.php
119===================================================================
120--- wp-includes/class-wp-http-ixr-client.php    (revision 17916)
121+++ wp-includes/class-wp-http-ixr-client.php    (working copy)
122@@ -64,16 +64,16 @@
123                        return false;
124                }
125 
126-               if ( $response['response']['code'] != 200 ) {
127-                       $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})");
128+               if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
129+                       $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')');
130                        return false;
131                }
132 
133                if ( $this->debug )
134-                       echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
135+                       echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
136 
137                // Now parse what we've got back
138-               $this->message = new IXR_Message( $response['body'] );
139+               $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
140                if ( ! $this->message->parse() ) {
141                        // XML error
142                        $this->error = new IXR_Error(-32700, 'parse error. not well formed');
143@@ -90,4 +90,4 @@
144                return true;
145        }
146 }
147-?>
148\ No newline at end of file
149+?>
150Index: wp-includes/comment.php
151===================================================================
152--- wp-includes/comment.php     (revision 17916)
153+++ wp-includes/comment.php     (working copy)
154@@ -1619,11 +1619,11 @@
155        if ( is_wp_error( $response ) )
156                return false;
157 
158-       if ( isset( $response['headers']['x-pingback'] ) )
159-               return $response['headers']['x-pingback'];
160+       if ( wp_remote_retrieve_header( $response, 'x-pingback' ) )
161+               return wp_remote_retrieve_header( $response, 'x-pingback' );
162 
163        // Not an (x)html, sgml, or xml page, no use going further.
164-       if ( isset( $response['headers']['content-type'] ) && preg_match('#(image|audio|video|model)/#is', $response['headers']['content-type']) )
165+       if ( preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header( $response, 'content-type' )) )
166                return false;
167 
168        // Now do a GET since we're going to look in the html headers (and we're sure its not a binary file)
169@@ -1632,7 +1632,7 @@
170        if ( is_wp_error( $response ) )
171                return false;
172 
173-       $contents = $response['body'];
174+       $contents = wp_remote_retrieve_body( $response );
175 
176        $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
177        $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
178Index: wp-includes/functions.php
179===================================================================
180--- wp-includes/functions.php   (revision 17916)
181+++ wp-includes/functions.php   (working copy)
182@@ -600,7 +600,7 @@
183 
184        wp_protect_special_option( $option );
185 
186-       /*
187+       /*
188         * FIXME the next two lines of code are not necessary and should be removed.
189         * @see http://core.trac.wordpress.org/ticket/13480
190         */
191@@ -1305,7 +1305,7 @@
192                return false;
193 
194        $headers = wp_remote_retrieve_headers( $response );
195-       $headers['response'] = $response['response']['code'];
196+       $headers['response'] = wp_remote_retrieve_response_code( $response );
197 
198        // WP_HTTP no longer follows redirects for HEAD requests.
199        if ( 'HEAD' == $options['method'] && in_array($headers['response'], array(301, 302)) && isset( $headers['location'] ) ) {
200@@ -1320,7 +1320,7 @@
201        if ( !$out_fp )
202                return $headers;
203 
204-       fwrite( $out_fp,  $response['body']);
205+       fwrite( $out_fp,  wp_remote_retrieve_body( $response ) );
206        fclose($out_fp);
207        clearstatcache();
208 
209@@ -1556,7 +1556,7 @@
210        if ( is_wp_error( $response ) )
211                return false;
212 
213-       return $response['body'];
214+       return wp_remote_retrieve_body( $response );
215 }
216 
217 /**
218@@ -2876,26 +2876,26 @@
219  * @param string $title Error title.
220  * @param string|array $args Optional arguements to control behaviour.
221  */
222-function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
223+function _xmlrpc_wp_die_handler( $message, $title = '', $args = array() ) {
224        global $wp_xmlrpc_server;
225        $defaults = array( 'response' => 500 );
226 
227        $r = wp_parse_args($args, $defaults);
228 
229-       if ( $wp_xmlrpc_server ) {
230-               $error = new IXR_Error( $r['response'] , $message);
231-               $wp_xmlrpc_server->output( $error->getXml() );
232+       if ( $wp_xmlrpc_server ) {
233+               $error = new IXR_Error( $r['response'] , $message);
234+               $wp_xmlrpc_server->output( $error->getXml() );
235        }
236        die();
237 }
238 
239 /**
240  * Filter to enable special wp_die handler for xmlrpc requests.
241- *
242+ *
243  * @since 3.2.0
244  * @access private
245  */
246-function _xmlrpc_wp_die_filter() {
247+function _xmlrpc_wp_die_filter() {
248        return '_xmlrpc_wp_die_handler';
249 }
250 
251Index: wp-includes/rss.php
252===================================================================
253--- wp-includes/rss.php (revision 17916)
254+++ wp-includes/rss.php (working copy)
255@@ -555,7 +555,7 @@
256        // Snoopy returns headers unprocessed.
257        // Also note, WP_HTTP lowercases all keys, Snoopy did not.
258        $return_headers = array();
259-       foreach ( $resp['headers'] as $key => $value ) {
260+       foreach ( wp_remote_retrieve_headers( $resp ) as $key => $value ) {
261                if ( !is_array($value) ) {
262                        $return_headers[] = "$key: $value";
263                } else {
264@@ -565,10 +565,10 @@
265        }
266 
267        $response = new stdClass;
268-       $response->status = $resp['response']['code'];
269-       $response->response_code = $resp['response']['code'];
270+       $response->status = wp_remote_retrieve_response_code( $resp );
271+       $response->response_code = wp_remote_retrieve_response_code( $resp );
272        $response->headers = $return_headers;
273-       $response->results = $resp['body'];
274+       $response->results = wp_remote_retrieve_body( $resp );
275 
276        return $response;
277 }
278Index: wp-includes/update.php
279===================================================================
280--- wp-includes/update.php      (revision 17916)
281+++ wp-includes/update.php      (working copy)
282@@ -71,13 +71,10 @@
283 
284        $response = wp_remote_get($url, $options);
285 
286-       if ( is_wp_error( $response ) )
287+       if ( is_wp_error( $response ) || 200 != wp_remote_retrieve_response_code( $response ) )
288                return false;
289 
290-       if ( 200 != $response['response']['code'] )
291-               return false;
292-
293-       $body = trim( $response['body'] );
294+       $body = trim( wp_remote_retrieve_body( $response ) );
295        $body = str_replace(array("\r\n", "\r"), "\n", $body);
296        $new_options = array();
297        foreach ( explode( "\n\n", $body ) as $entry ) {
298@@ -175,14 +172,11 @@
299 
300        $raw_response = wp_remote_post('http://api.wordpress.org/plugins/update-check/1.0/', $options);
301 
302-       if ( is_wp_error( $raw_response ) )
303+       if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
304                return false;
305 
306-       if ( 200 != $raw_response['response']['code'] )
307-               return false;
308+       $response = unserialize( wp_remote_retrieve_body( $raw_response ) );
309 
310-       $response = unserialize( $raw_response['body'] );
311-
312        if ( false !== $response )
313                $new_option->response = $response;
314        else
315@@ -273,17 +267,14 @@
316 
317        $raw_response = wp_remote_post( 'http://api.wordpress.org/themes/update-check/1.0/', $options );
318 
319-       if ( is_wp_error( $raw_response ) )
320+       if ( is_wp_error( $raw_response ) || 200 != wp_remote_retrieve_response_code( $raw_response ) )
321                return false;
322 
323-       if ( 200 != $raw_response['response']['code'] )
324-               return false;
325-
326        $new_update = new stdClass;
327        $new_update->last_checked = time( );
328        $new_update->checked = $checked;
329 
330-       $response = unserialize( $raw_response['body'] );
331+       $response = unserialize( wp_remote_retrieve_body( $raw_response ) );
332        if ( false !== $response )
333                $new_update->response = $response;
334