@@ 154-160 (lines=7) @@ | ||
151 | $response_code = wp_remote_retrieve_response_code( $result ); |
|
152 | $body_json = json_decode( wp_remote_retrieve_body( $result ) ); |
|
153 | ||
154 | if( 200 !== $response_code ) { |
|
155 | if ( isset( $body_json->error ) ) { |
|
156 | return new WP_Error( $body_json->error, $body_json->message ); |
|
157 | } else { |
|
158 | return new WP_Error( 'server_error', sprintf( __( "Request failed with code %s" ), $response_code ) ); |
|
159 | } |
|
160 | } |
|
161 | ||
162 | if ( isset( $body_json->access_token ) ) { |
|
163 | // check if this matches the existing token before replacing |
|
@@ 217-223 (lines=7) @@ | ||
214 | $response_code = wp_remote_retrieve_response_code( $result ); |
|
215 | $body_json = json_decode( wp_remote_retrieve_body( $result ) ); |
|
216 | ||
217 | if( 200 !== $response_code ) { |
|
218 | if ( isset( $body_json->error ) ) { |
|
219 | return new WP_Error( $body_json->error, $body_json->message ); |
|
220 | } else { |
|
221 | return new WP_Error( 'server_error', sprintf( __( "Request failed with code %s" ), $response_code ) ); |
|
222 | } |
|
223 | } |
|
224 | ||
225 | return true; |
|
226 | } |