REST API: Add gmt_offset
and timezone_string
to the base /wp-json
response.
The site's current timezone offset is an important piece of information for any REST API client that needs to manipulate dates. It has not been previously available. Expose both the `gmt_offset` (the site's current offset from UTC in hours) and `timezone_string` (which also provides information about daylight savings time) via the "site info" endpoint (the base `/wp-json` response). Also update the `wp-api-generated.js` fixture file with the changes to the default API responses. Props sagarkbhatt. Fixes #39854. Merges [40238] to the 4.7 branch. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@40336 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
966fca980f
commit
8e68bdace3
@ -1010,13 +1010,15 @@ class WP_REST_Server {
|
|||||||
public function get_index( $request ) {
|
public function get_index( $request ) {
|
||||||
// General site data.
|
// General site data.
|
||||||
$available = array(
|
$available = array(
|
||||||
'name' => get_option( 'blogname' ),
|
'name' => get_option( 'blogname' ),
|
||||||
'description' => get_option( 'blogdescription' ),
|
'description' => get_option( 'blogdescription' ),
|
||||||
'url' => get_option( 'siteurl' ),
|
'url' => get_option( 'siteurl' ),
|
||||||
'home' => home_url(),
|
'home' => home_url(),
|
||||||
'namespaces' => array_keys( $this->namespaces ),
|
'gmt_offset' => get_option( 'gmt_offset' ),
|
||||||
'authentication' => array(),
|
'timezone_string' => get_option( 'timezone_string' ),
|
||||||
'routes' => $this->get_data_for_routes( $this->get_routes(), $request['context'] ),
|
'namespaces' => array_keys( $this->namespaces ),
|
||||||
|
'authentication' => array(),
|
||||||
|
'routes' => $this->get_data_for_routes( $this->get_routes(), $request['context'] ),
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = new WP_REST_Response( $available );
|
$response = new WP_REST_Response( $available );
|
||||||
|
@ -646,6 +646,8 @@ class Tests_REST_Server extends WP_Test_REST_TestCase {
|
|||||||
$this->assertArrayHasKey( 'description', $data );
|
$this->assertArrayHasKey( 'description', $data );
|
||||||
$this->assertArrayHasKey( 'url', $data );
|
$this->assertArrayHasKey( 'url', $data );
|
||||||
$this->assertArrayHasKey( 'home', $data );
|
$this->assertArrayHasKey( 'home', $data );
|
||||||
|
$this->assertArrayHasKey( 'gmt_offset', $data );
|
||||||
|
$this->assertArrayHasKey( 'timezone_string', $data );
|
||||||
$this->assertArrayHasKey( 'namespaces', $data );
|
$this->assertArrayHasKey( 'namespaces', $data );
|
||||||
$this->assertArrayHasKey( 'authentication', $data );
|
$this->assertArrayHasKey( 'authentication', $data );
|
||||||
$this->assertArrayHasKey( 'routes', $data );
|
$this->assertArrayHasKey( 'routes', $data );
|
||||||
|
@ -10,6 +10,8 @@ mockedApiResponse.Schema = {
|
|||||||
"description": "Just another WordPress site",
|
"description": "Just another WordPress site",
|
||||||
"url": "http://example.org",
|
"url": "http://example.org",
|
||||||
"home": "http://example.org",
|
"home": "http://example.org",
|
||||||
|
"gmt_offset": "0",
|
||||||
|
"timezone_string": "",
|
||||||
"namespaces": [
|
"namespaces": [
|
||||||
"oembed/1.0",
|
"oembed/1.0",
|
||||||
"wp/v2"
|
"wp/v2"
|
||||||
|
Loading…
Reference in New Issue
Block a user