1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Business Hours: Localized week |
5
|
|
|
* |
6
|
|
|
* @since 7.1 |
7
|
|
|
*/ |
8
|
|
|
class WPCOM_REST_API_V2_Endpoint_Business_Hours extends WP_REST_Controller { |
9
|
|
|
function __construct() { |
10
|
|
|
$this->namespace = 'wpcom/v2'; |
11
|
|
|
$this->rest_base = 'business-hours'; |
12
|
|
|
// This endpoint *does not* need to connect directly to Jetpack sites. |
13
|
|
|
add_action( 'rest_api_init', array( $this, 'register_routes' ) ); |
14
|
|
|
} |
15
|
|
|
|
16
|
|
|
public function register_routes() { |
17
|
|
|
// GET /sites/<blog_id>/business-hours/localized-week - Return the localized |
18
|
|
|
register_rest_route( $this->namespace, '/' . $this->rest_base . '/localized-week', array( |
19
|
|
|
array( |
20
|
|
|
'methods' => WP_REST_Server::READABLE, |
21
|
|
|
'callback' => array( $this, 'get_localized_week' ), |
22
|
|
|
) |
23
|
|
|
) ); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Retreives localized business hours |
28
|
|
|
* |
29
|
|
|
* @return array data object containing information about business hours |
30
|
|
|
*/ |
31
|
|
|
public function get_localized_week() { |
32
|
|
|
global $wp_locale; |
33
|
|
|
|
34
|
|
|
return array( |
35
|
|
|
'days' => array( |
36
|
|
|
'Sun' => $wp_locale->get_weekday( 0 ), |
37
|
|
|
'Mon' => $wp_locale->get_weekday( 1 ), |
38
|
|
|
'Tue' => $wp_locale->get_weekday( 2 ), |
39
|
|
|
'Wed' => $wp_locale->get_weekday( 3 ), |
40
|
|
|
'Thu' => $wp_locale->get_weekday( 4 ), |
41
|
|
|
'Fri' => $wp_locale->get_weekday( 5 ), |
42
|
|
|
'Sat' => $wp_locale->get_weekday( 6 ), |
43
|
|
|
), |
44
|
|
|
'startOfWeek' => (int) get_option( 'start_of_week', 0 ), |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Business_Hours' ); |
50
|
|
|
|