@@ 202-212 (lines=11) @@ | ||
199 | $response_code = wp_remote_retrieve_response_code( $result ); |
|
200 | $body_json = json_decode( wp_remote_retrieve_body( $result ) ); |
|
201 | ||
202 | if ( 200 !== $response_code ) { |
|
203 | if ( isset( $body_json->error ) ) { |
|
204 | return new WP_Error( $body_json->error, $body_json->message ); |
|
205 | } else { |
|
206 | return new WP_Error( |
|
207 | 'server_error', |
|
208 | /* translators: %s is an HTTP status code retured from an API request. Ex. – 400 */ |
|
209 | sprintf( __( 'Request failed with code %s', 'jetpack' ), $response_code ) |
|
210 | ); |
|
211 | } |
|
212 | } |
|
213 | ||
214 | if ( isset( $body_json->access_token ) && is_user_logged_in() ) { |
|
215 | // Check if this matches the existing token before replacing. |
|
@@ 269-275 (lines=7) @@ | ||
266 | $response_code = wp_remote_retrieve_response_code( $result ); |
|
267 | $body_json = json_decode( wp_remote_retrieve_body( $result ) ); |
|
268 | ||
269 | if( 200 !== $response_code ) { |
|
270 | if ( isset( $body_json->error ) ) { |
|
271 | return new WP_Error( $body_json->error, $body_json->message ); |
|
272 | } else { |
|
273 | return new WP_Error( 'server_error', sprintf( __( 'Request failed with code %s', 'jetpack' ), $response_code ) ); |
|
274 | } |
|
275 | } |
|
276 | ||
277 | return true; |
|
278 | } |