WordPress.org

Make WordPress Core

Changeset 40238


Ignore:
Timestamp:
03/07/2017 05:47:32 AM (3 years ago)
Author:
jnylen0
Message:

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.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r40038 r40238  
    10131013        // General site data.
    10141014        $available = array(
    1015             'name'           => get_option( 'blogname' ),
    1016             'description'    => get_option( 'blogdescription' ),
    1017             'url'            => get_option( 'siteurl' ),
    1018             'home'           => home_url(),
    1019             'namespaces'     => array_keys( $this->namespaces ),
    1020             'authentication' => array(),
    1021             'routes'         => $this->get_data_for_routes( $this->get_routes(), $request['context'] ),
     1015            'name'            => get_option( 'blogname' ),
     1016            'description'     => get_option( 'blogdescription' ),
     1017            'url'             => get_option( 'siteurl' ),
     1018            'home'            => home_url(),
     1019            'gmt_offset'      => get_option( 'gmt_offset' ),
     1020            'timezone_string' => get_option( 'timezone_string' ),
     1021            'namespaces'      => array_keys( $this->namespaces ),
     1022            'authentication'  => array(),
     1023            'routes'          => $this->get_data_for_routes( $this->get_routes(), $request['context'] ),
    10221024        );
    10231025
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r38947 r40238  
    647647        $this->assertArrayHasKey( 'url', $data );
    648648        $this->assertArrayHasKey( 'home', $data );
     649        $this->assertArrayHasKey( 'gmt_offset', $data );
     650        $this->assertArrayHasKey( 'timezone_string', $data );
    649651        $this->assertArrayHasKey( 'namespaces', $data );
    650652        $this->assertArrayHasKey( 'authentication', $data );
  • trunk/tests/qunit/fixtures/wp-api-generated.js

    r40121 r40238  
    1111    "url": "http://example.org",
    1212    "home": "http://example.org",
     13    "gmt_offset": "0",
     14    "timezone_string": "",
    1315    "namespaces": [
    1416        "oembed/1.0",
Note: See TracChangeset for help on using the changeset viewer.