WordPress.org

Make WordPress Core

Ticket #39072: gmt_offset_rest_api.diff

File gmt_offset_rest_api.diff, 1.9 KB (added by jshreve, 5 years ago)
  • wp-includes/default-filters.php

     
    385385add_action( 'rest_api_init', 'register_initial_settings',  10 );
    386386add_action( 'rest_api_init', 'create_initial_rest_routes', 99 );
    387387add_action( 'parse_request', 'rest_api_loaded' );
     388add_filter( 'rest_pre_update_setting', 'rest_pre_update_settings', 10, 4 );
    388389
    389390/**
    390391 * Filters formerly mixed into wp-includes
  • wp-includes/option.php

     
    17711771                'description'  => __( 'A city in the same timezone as you.' ),
    17721772        ) );
    17731773
     1774        register_setting( 'general', 'gmt_offset', array(
     1775                'show_in_rest' => true,
     1776                'type'         => 'string',
     1777                'description'  => __( 'UTC timezone offset.' ),
     1778        ) );
     1779
    17741780        register_setting( 'general', 'date_format', array(
    17751781                'show_in_rest' => true,
    17761782                'type'         => 'string',
     
    20102016
    20112017        return $registered[ $option ]['default'];
    20122018}
     2019
     2020/**
     2021 * Runs before the value of an option is updated via the REST API.
     2022 *
     2023 * @param bool   $result Whether to override the default behavior for updating the
     2024 *                       value of a setting.
     2025 * @param string $name   Setting name (as shown in REST API responses).
     2026 * @param mixed  $value  Updated setting value.
     2027 * @param array  $args   Arguments passed to register_setting() for this setting.
     2028 * @return bool False if value was not updated and true if value was updated.
     2029 */
     2030function rest_pre_update_settings( $result, $name, $value, $args ) {
     2031        switch ( $name ) {
     2032                case 'gmt_offset':
     2033                        update_option( 'timezone_string', '' );
     2034                        update_option( 'gmt_offset', $value );
     2035                        return true;
     2036                default:
     2037                        return $result;
     2038        }
     2039}