Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.59% |
12 / 17 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| WP_REST_Help_Center_Email_Support_Enabled | |
70.59% |
12 / 17 |
|
66.67% |
2 / 3 |
4.41 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| register_rest_route | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
1 | |||
| get_email_support_configuration | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * WP_REST_Help_Center_Email_Support_Enabled file. |
| 4 | * |
| 5 | * @package automattic/jetpack-help-center |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Help_Center; |
| 9 | |
| 10 | /** |
| 11 | * Class WP_REST_Help_Center_Email_Support_Enabled. |
| 12 | */ |
| 13 | class WP_REST_Help_Center_Email_Support_Enabled extends WP_REST_Help_Center_Controller { |
| 14 | /** |
| 15 | * WP_REST_Help_Center_Email_Support_Enabled constructor. |
| 16 | * |
| 17 | * @param Wpcom_Request_Client|null $wpcom_request_client WP.com request client. |
| 18 | */ |
| 19 | public function __construct( ?Wpcom_Request_Client $wpcom_request_client = null ) { |
| 20 | parent::__construct( $wpcom_request_client ); |
| 21 | $this->namespace = 'help-center'; |
| 22 | $this->rest_base = '/support-availability'; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Register available routes. |
| 27 | */ |
| 28 | public function register_rest_route() { |
| 29 | register_rest_route( |
| 30 | $this->namespace, |
| 31 | $this->rest_base . '/email', |
| 32 | array( |
| 33 | 'methods' => \WP_REST_Server::READABLE, |
| 34 | 'callback' => array( $this, 'get_email_support_configuration' ), |
| 35 | 'permission_callback' => '__return_true', |
| 36 | ) |
| 37 | ); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Should return if email contact is enabled for the user. |
| 42 | */ |
| 43 | public function get_email_support_configuration() { |
| 44 | $body = $this->wpcom_request_client->request( 'help/eligibility/email/mine' ); |
| 45 | |
| 46 | if ( is_wp_error( $body ) ) { |
| 47 | return $body; |
| 48 | } |
| 49 | |
| 50 | $response = json_decode( wp_remote_retrieve_body( $body ) ); |
| 51 | |
| 52 | return rest_ensure_response( $response ); |
| 53 | } |
| 54 | } |