Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
37.93% |
11 / 29 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| WPCOM_REST_API_V2_Endpoint_Business_Hours | |
42.31% |
11 / 26 |
|
33.33% |
1 / 3 |
4.73 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| register_routes | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
1 | |||
| get_localized_week | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Build localized strings for use with the Business Hours Block. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 9 | exit( 0 ); |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Business Hours: Localized week |
| 14 | * |
| 15 | * @since 7.1 |
| 16 | */ |
| 17 | class WPCOM_REST_API_V2_Endpoint_Business_Hours extends WP_REST_Controller { |
| 18 | /** |
| 19 | * Constructor. |
| 20 | */ |
| 21 | public function __construct() { |
| 22 | $this->namespace = 'wpcom/v2'; |
| 23 | $this->rest_base = 'business-hours'; |
| 24 | // This endpoint *does not* need to connect directly to Jetpack sites. |
| 25 | add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Register endpoint route. |
| 30 | */ |
| 31 | public function register_routes() { |
| 32 | // GET /sites/<blog_id>/business-hours/localized-week - Return the localized. |
| 33 | register_rest_route( |
| 34 | $this->namespace, |
| 35 | '/' . $this->rest_base . '/localized-week', |
| 36 | array( |
| 37 | array( |
| 38 | 'methods' => WP_REST_Server::READABLE, |
| 39 | 'callback' => array( $this, 'get_localized_week' ), |
| 40 | 'permission_callback' => '__return_true', |
| 41 | ), |
| 42 | ) |
| 43 | ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Retreives localized business hours |
| 48 | * |
| 49 | * @return array data object containing information about business hours |
| 50 | */ |
| 51 | public function get_localized_week() { |
| 52 | global $wp_locale; |
| 53 | |
| 54 | return array( |
| 55 | 'days' => array( |
| 56 | 'Sun' => $wp_locale->get_weekday( 0 ), |
| 57 | 'Mon' => $wp_locale->get_weekday( 1 ), |
| 58 | 'Tue' => $wp_locale->get_weekday( 2 ), |
| 59 | 'Wed' => $wp_locale->get_weekday( 3 ), |
| 60 | 'Thu' => $wp_locale->get_weekday( 4 ), |
| 61 | 'Fri' => $wp_locale->get_weekday( 5 ), |
| 62 | 'Sat' => $wp_locale->get_weekday( 6 ), |
| 63 | ), |
| 64 | 'startOfWeek' => (int) get_option( 'start_of_week', 0 ), |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Business_Hours' ); |