Make WordPress Core

Opened 28 hours ago

Last modified 28 hours ago

#66902 new enhancement

Abilities API: Read and write manual UTC offsets as the timezone setting

Reported by: jorgefilipecosta Owned by:
Priority: normal Milestone: 7.3
Component: Abilities API Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description (last modified by jorgefilipecosta)

The settings abilities expose timezone_string as timezone. Sites using a manual offset like UTC+2 have an empty timezone_string and store the offset in gmt_offset, so core/settings-get returns an empty timezone and core/settings-update cannot set an offset. Exposing gmt_offset directly is not an option because core computes it from timezone_string, and only the Settings > General form keeps both in sync.

This ticket makes timezone also accept and return the offsets offered on Settings > General, e.g: UTC+2 or UTC-5.5. Writing an offset stores gmt_offset and empties timezone_string, the same way the form does. The conversion logic moves from wp-admin into functions shared by the screen and the abilities, which also fixes Settings > General selecting UTC+0 for sites on UTC+0.5 or UTC-0.5.

Follow-up to #64616.

PR at: ​https://github.com/WordPress/wordpress-develop/pull/16385

Change History (2)

This ticket was mentioned in ​PR #16385 on ​WordPress/wordpress-develop by ​@jorgefilipecosta.


28 hours ago
#1

Stacked on ​https://github.com/WordPress/wordpress-develop/pull/10892. Only the last two commits belong to this PR.

Follow-up to ​https://github.com/WordPress/wordpress-develop/pull/10892.

A site on a manual UTC offset, such as UTC+2, keeps timezone_string empty and stores the offset in gmt_offset. So core/settings-get returned an empty timezone, and core/settings-update could not set an offset. This PR implements the following changes:

  • Adds wp_get_timezone_offset_choices(), wp_get_timezone_offset_choice() and wp_parse_timezone_offset_choice(): the manual offsets that wp_timezone_choice() offers, and the two conversions Settings > General did inline. wp_timezone_choice(), wp-admin/options.php and wp-admin/options-general.php use them.
  • timezone accepts and returns those offsets (UTC+2, UTC-5.5, UTC+0) next to timezone identifiers.
    • Reading: a site without a timezone string reads as the value of its gmt_offset.
    • Writing: an offset stores gmt_offset and empties timezone_string. An identifier, UTC included, stores timezone_string as before.
    • An offset the list does not offer (UTC+2.0, UTC+15, UTC-0) is refused with settings_invalid_value. A refused call writes neither option. The offset is written first, so a call stopped between the two writes leaves the site on its timezone string.
  • Settings > General now selects UTC+0.5 and UTC-0.5 for a site on those offsets. It selected UTC+0 before.
  • Shape change: core/settings-get (7.2) now returns UTC+2, not "", for a site on a manual offset. After a null reset, timezone reads as the stored offset instead of being left out. The timezone description names the offsets.
  • The settings REST route is unchanged. Offsets there could be later work.

Testing

Verify unit tests are passing:

vendor/bin/phpunit --group abilities-api,option,date
vendor/bin/phpunit -c tests/phpunit/multisite.xml --group abilities-api,option,date

AI disclosure: the change and tests were drafted with AI assistance (Claude Code).

#2 @jorgefilipecosta
28 hours ago

  • Description modified (diff)
  • Summary Abilities API: Read and write manual UTC offsets as the `timezone` setting → Abilities API: Read and write manual UTC offsets as the timezone setting
Note: See TracTickets for help on using tickets.