wp_timezone_choice( string $selected_zone, string $locale = null ): string
- Since
- 2.9.0, 4.7.0
- Source
wp-includes/functions.php:6613
Compatibility
- WordPress
- since 4.7.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$selected_zonestring- Selected timezone.
$localestringoptional- Locale to load the timezones in. Default current site locale.Default:
null
Return value
string
Performance profile
How much work a call to wp_timezone_choice() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 81–111
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_site_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 328.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below wp_timezone_choice() - optionnetwork option
get_site_option()one call below wp_timezone_choice()
Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 12 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_timezone_choice() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!empty($selected_zone) | 81–85 | unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), esc_attr__(), esc_attr(), __(), esc_attr__() |
!empty($selected_zone) | 82–86 | get_locale(), unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), esc_attr__(), esc_attr(), __(), esc_attr__() |
!empty($selected_zone) && !$selected_zone | 87–91 | unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), timezone_identifiers_list(), esc_attr__(), esc_attr(), __(), esc_attr__() |
empty($selected_zone) | 88–92 | unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), __(), esc_attr__(), esc_attr(), __(), esc_attr__() |
!empty($selected_zone) && !$selected_zone | 88–92 | get_locale(), unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), timezone_identifiers_list(), esc_attr__(), esc_attr(), __(), esc_attr__() |
empty($selected_zone) | 89–93 | get_locale(), unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), __(), esc_attr__(), esc_attr(), __(), esc_attr__() |
empty($selected_zone) && !$selected_zone | 94–98 | unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), __(), timezone_identifiers_list(), esc_attr__(), esc_attr(), __(), esc_attr__() |
empty($selected_zone) && !$selected_zone | 95–99 | get_locale(), unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), __(), timezone_identifiers_list(), esc_attr__(), esc_attr(), __(), esc_attr__() |
!empty($selected_zone) && $selected_zone | 99–103 | unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), timezone_identifiers_list(), esc_attr(), esc_html(), esc_attr__(), esc_attr(), __(), esc_attr__() |
!empty($selected_zone) && $selected_zone | 100–104 | get_locale(), unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), timezone_identifiers_list(), esc_attr(), esc_html(), esc_attr__(), esc_attr(), __(), esc_attr__() |
empty($selected_zone) && $selected_zone | 106–110 | unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), __(), timezone_identifiers_list(), esc_attr(), esc_html(), esc_attr__(), esc_attr(), __(), esc_attr__() |
empty($selected_zone) && $selected_zone | 107–111 | get_locale(), unload_textdomain(), load_textdomain(), timezone_identifiers_list(), usort(), __(), timezone_identifiers_list(), esc_attr(), esc_html(), esc_attr__(), esc_attr(), __(), esc_attr__() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 324 | 81–110 | 37 | 4 fewer instructions than PHP 8.5 |
| 8.5 | 328 | 81–111 | 37 | |
| 8.4 | 328 | 81–111 | 37 | 24 fewer instructions than PHP 8.3 |
| 8.3 | 352 | 87–120 | 37 | |
| 8.2 | 352 | 87–120 | 37 | |
| 8.1 | 352 | 87–120 | 37 | 3 fewer instructions than PHP 7.4 |
| 7.4 | 355 | 87–120 | 37 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 8
- get_locale()Retrieves the current locale.
- unload_textdomain()Unloads translations for a text domain.
- load_textdomain()Loads a .mo file into the text domain $domain.
- translate()Retrieves the translation of $text.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
- esc_html()Escaping for HTML blocks.
- esc_attr__()Retrieves the translation of $text and escapes it for safe use in an attribute.
Source code
function wp_timezone_choice( $selected_zone, $locale = null ) { static $mo_loaded = false, $locale_loaded = null; $continents = array( 'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific' ); // Load translations for continents and cities. if ( ! $mo_loaded || $locale !== $locale_loaded ) { $locale_loaded = $locale ? $locale : get_locale(); $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; unload_textdomain( 'continents-cities', true ); load_textdomain( 'continents-cities', $mofile, $locale_loaded ); $mo_loaded = true; } $tz_identifiers = timezone_identifiers_list(); $zonen = array(); foreach ( $tz_identifiers as $zone ) { $zone = explode( '/', $zone ); if ( ! in_array( $zone[0], $continents, true ) ) { continue; } // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later. $exists = array( 0 => ( isset( $zone[0] ) && $zone[0] ), 1 => ( isset( $zone[1] ) && $zone[1] ), 2 => ( isset( $zone[2] ) && $zone[2] ), ); $exists[3] = ( $exists[0] && 'Etc' !== $zone[0] ); $exists[4] = ( $exists[1] && $exists[3] ); $exists[5] = ( $exists[2] && $exists[3] ); // phpcs:disable WordPress.WP.I18n.LowLevelTranslationFunction,WordPress.WP.I18n.NonSingularStringLiteralText $zonen[] = array( 'continent' => ( $exists[0] ? $zone[0] : '' ), 'city' => ( $exists[1] ? $zone[1] : '' ), 'subcity' => ( $exists[2] ? $zone[2] : '' ), 't_continent' => ( $exists[3] ? translate( str_replace( '_', ' ', $zone[0] ), 'continents-cities' ) : '' ), 't_city' => ( $exists[4] ? translate( str_replace( '_', ' ', $zone[1] ), 'continents-cities' ) : '' ), 't_subcity' => ( $exists[5] ? translate( str_replace( '_', ' ', $zone[2] ), 'continents-cities' ) : '' ), ); // phpcs:enable } usort( $zonen, '_wp_timezone_choice_usort_callback' ); $structure = array(); if ( empty( $selected_zone ) ) { $structure[] = '<option selected="selected" value="">' . __( 'Select a city' ) . '</option>'; } // If this is a deprecated, but valid, timezone string, display it at the top of the list as-is. if ( in_array( $selected_zone, $tz_identifiers, true ) === false && in_array( $selected_zone, timezone_identifiers_list( DateTimeZone::ALL_WITH_BC ), true ) ) { $structure[] = '<option selected="selected" value="' . esc_attr( $selected_zone ) . '">' . esc_html( $selected_zone ) . '</option>'; } foreach ( $zonen as $key => $zone ) { // Build value in an array to join later. $value = array( $zone['continent'] ); if ( empty( $zone['city'] ) ) { // It's at the continent level (generally won't happen). $display = $zone['t_continent']; } else { // It's inside a continent group. // Continent optgroup. if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) { $label = $zone['t_continent']; $structure[] = '<optgroup label="' . esc_attr( $label ) . '">'; } // Add the city to the value. $value[] = $zone['city']; $display = $zone['t_city']; if ( ! empty( $zone['subcity'] ) ) {Changelog
Introduced in 2.9.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
$locale parameter.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/functions.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.