Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| WP_REST_Help_Center_Support_Activity | |
0.00% |
0 / 16 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| register_rest_route | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
2 | |||
| get_support_activity | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WP_REST_Help_Center_Support_Activity file. |
| 4 | * |
| 5 | * @package automattic/jetpack-mu-wpcom |
| 6 | */ |
| 7 | |
| 8 | namespace A8C\FSE; |
| 9 | |
| 10 | use Automattic\Jetpack\Connection\Client; |
| 11 | |
| 12 | /** |
| 13 | * Class WP_REST_Help_Center_Support_Activity. |
| 14 | */ |
| 15 | class WP_REST_Help_Center_Support_Activity extends \WP_REST_Controller { |
| 16 | /** |
| 17 | * WP_REST_Help_Center_Support_Activity constructor. |
| 18 | */ |
| 19 | public function __construct() { |
| 20 | $this->namespace = 'help-center'; |
| 21 | $this->rest_base = '/support-activity'; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Register available routes. |
| 26 | */ |
| 27 | public function register_rest_route() { |
| 28 | register_rest_route( |
| 29 | $this->namespace, |
| 30 | $this->rest_base, |
| 31 | array( |
| 32 | 'methods' => \WP_REST_Server::READABLE, |
| 33 | 'callback' => array( $this, 'get_support_activity' ), |
| 34 | 'permission_callback' => 'is_user_logged_in', |
| 35 | ) |
| 36 | ); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get support activity through Jetpack. |
| 41 | */ |
| 42 | public function get_support_activity() { |
| 43 | $body = Client::wpcom_json_api_request_as_user( '/support-activity' ); |
| 44 | |
| 45 | if ( is_wp_error( $body ) ) { |
| 46 | return $body; |
| 47 | } |
| 48 | |
| 49 | $response = json_decode( wp_remote_retrieve_body( $body ) ); |
| 50 | |
| 51 | return rest_ensure_response( $response ); |
| 52 | } |
| 53 | } |