| Conditions | 6 |
| Paths | 4 |
| Total Lines | 24 |
| Lines | 3 |
| Ratio | 12.5 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 42 | public function get_from_wpcom() { |
||
| 43 | |||
| 44 | $request = sprintf( '/sites/%d/purchases', \Jetpack_Options::get_option( 'id' ) ); |
||
| 45 | $response = Client::wpcom_json_api_request_as_blog( $request, '1.1', array( 'owner' => 'site' ) ); |
||
| 46 | |||
| 47 | // Bail if there was an error or malformed response. |
||
| 48 | View Code Duplication | if ( is_wp_error( $response ) || ! is_array( $response ) || ! isset( $response['body'] ) ) { |
|
| 49 | return false; |
||
| 50 | } |
||
| 51 | |||
| 52 | $body = wp_remote_retrieve_body( $response ); |
||
| 53 | if ( is_wp_error( $body ) ) { |
||
| 54 | return false; |
||
| 55 | } |
||
| 56 | // Decode the results. |
||
| 57 | $results = json_decode( $body, true ); |
||
| 58 | |||
| 59 | // Bail if there were no results or plan details returned. |
||
| 60 | if ( ! is_array( $results ) ) { |
||
| 61 | return false; |
||
| 62 | } |
||
| 63 | update_option( self::OPTION_CACHE, $results ); |
||
| 64 | return $results; |
||
| 65 | } |
||
| 66 | |||
| 68 |