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