Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Credentials | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
56 | |
0.00% |
0 / 1 |
| get_credential_array | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Class to handle Rewind |
| 4 | * |
| 5 | * @package automattic/jetpack-protect-plugin |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Protect; |
| 9 | |
| 10 | use Automattic\Jetpack\Connection\Client; |
| 11 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 12 | use Jetpack_Options; |
| 13 | |
| 14 | /** |
| 15 | * Class that handles the rewind api call. |
| 16 | */ |
| 17 | class Credentials { |
| 18 | /** |
| 19 | * Get the rewind state, if no creds are set the state will be 'awaiting_for_credentials' |
| 20 | * |
| 21 | * @return bool |
| 22 | */ |
| 23 | public static function get_credential_array() { |
| 24 | $blog_id = Jetpack_Options::get_option( 'id' ); |
| 25 | $is_connected = ( new Connection_Manager() )->is_connected(); |
| 26 | |
| 27 | if ( ! $blog_id || ! $is_connected ) { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | $api_url = sprintf( '/sites/%d/scan', $blog_id ); |
| 32 | |
| 33 | $response = Client::wpcom_json_api_request_as_blog( |
| 34 | $api_url, |
| 35 | '2', |
| 36 | array( 'method' => 'GET' ), |
| 37 | null, |
| 38 | 'wpcom' |
| 39 | ); |
| 40 | |
| 41 | $response_code = wp_remote_retrieve_response_code( $response ); |
| 42 | |
| 43 | if ( is_wp_error( $response ) || 200 !== $response_code ) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | $parsed_response = json_decode( $response['body'] ); |
| 48 | |
| 49 | if ( ! $parsed_response ) { |
| 50 | return false; |
| 51 | } |
| 52 | |
| 53 | return isset( $parsed_response->credentials ) ? $parsed_response->credentials : array(); |
| 54 | } |
| 55 | } |