summaryrefslogtreecommitdiff
blob: 2bf80939952649d26d1e75a006b3493d18f36a96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php

/**
 * Business Hours: Localized week
 *
 * @since 7.1
 */
class WPCOM_REST_API_V2_Endpoint_Business_Hours extends WP_REST_Controller {
	function __construct() {
		$this->namespace = 'wpcom/v2';
		$this->rest_base = 'business-hours';
		// This endpoint *does not* need to connect directly to Jetpack sites.
		add_action( 'rest_api_init', array( $this, 'register_routes' ) );
	}

	public function register_routes() {
		// GET /sites/<blog_id>/business-hours/localized-week - Return the localized
		register_rest_route( $this->namespace, '/' . $this->rest_base . '/localized-week', array(
			array(
				'methods'  => WP_REST_Server::READABLE,
				'callback' => array( $this, 'get_localized_week' ),
			)
		) );
	}

	/**
	 * Retreives localized business hours
	 *
	 * @return array data object containing information about business hours
	 */
	public function get_localized_week() {
		global $wp_locale;

		return array(
			'days'        => array(
				'Sun' => $wp_locale->get_weekday( 0 ),
				'Mon' => $wp_locale->get_weekday( 1 ),
				'Tue' => $wp_locale->get_weekday( 2 ),
				'Wed' => $wp_locale->get_weekday( 3 ),
				'Thu' => $wp_locale->get_weekday( 4 ),
				'Fri' => $wp_locale->get_weekday( 5 ),
				'Sat' => $wp_locale->get_weekday( 6 ),
			),
			'startOfWeek' => (int) get_option( 'start_of_week', 0 ),
		);
	}
}

wpcom_rest_api_v2_load_plugin( 'WPCOM_REST_API_V2_Endpoint_Business_Hours' );