_wp_timezone_choice_usort_callback

The timeline below displays how wordpress function _wp_timezone_choice_usort_callback has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Sort-helper for timezones.
 *
 * @since 2.9.0
 * @access private
 *
 * @param array $a
 * @param array $b
 * @return int
 */
function _wp_timezone_choice_usort_callback($a, $b)
{
    // Don't use translated versions of Etc.
    if ('Etc' === $a['continent'] && 'Etc' === $b['continent']) {
        // Make the order of these more like the old dropdown.
        if (str_starts_with($a['city'], 'GMT+') && str_starts_with($b['city'], 'GMT+')) {
            return -1 * strnatcasecmp($a['city'], $b['city']);
        }
        if ('UTC' === $a['city']) {
            if (str_starts_with($b['city'], 'GMT+')) {
                return 1;
            }
            return -1;
        }
        if ('UTC' === $b['city']) {
            if (str_starts_with($a['city'], 'GMT+')) {
                return -1;
            }
            return 1;
        }
        return strnatcasecmp($a['city'], $b['city']);
    }
    if ($a['t_continent'] === $b['t_continent']) {
        if ($a['t_city'] === $b['t_city']) {
            return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
        }
        return strnatcasecmp($a['t_city'], $b['t_city']);
    } else {
        // Force Etc to the bottom of the list.
        if ('Etc' === $a['continent']) {
            return 1;
        }
        if ('Etc' === $b['continent']) {
            return -1;
        }
        return strnatcasecmp($a['t_continent'], $b['t_continent']);
    }
}

WordPress Version: 6.3

/**
 * Sort-helper for timezones.
 *
 * @since 2.9.0
 * @access private
 *
 * @param array $a
 * @param array $b
 * @return int
 */
function _wp_timezone_choice_usort_callback($a, $b)
{
    // Don't use translated versions of Etc.
    if ('Etc' === $a['continent'] && 'Etc' === $b['continent']) {
        // Make the order of these more like the old dropdown.
        if (str_starts_with($a['city'], 'GMT+') && str_starts_with($b['city'], 'GMT+')) {
            return -1 * strnatcasecmp($a['city'], $b['city']);
        }
        if ('UTC' === $a['city']) {
            if (str_starts_with($b['city'], 'GMT+')) {
                return 1;
            }
            return -1;
        }
        if ('UTC' === $b['city']) {
            if (str_starts_with($a['city'], 'GMT+')) {
                return -1;
            }
            return 1;
        }
        return strnatcasecmp($a['city'], $b['city']);
    }
    if ($a['t_continent'] == $b['t_continent']) {
        if ($a['t_city'] == $b['t_city']) {
            return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
        }
        return strnatcasecmp($a['t_city'], $b['t_city']);
    } else {
        // Force Etc to the bottom of the list.
        if ('Etc' === $a['continent']) {
            return 1;
        }
        if ('Etc' === $b['continent']) {
            return -1;
        }
        return strnatcasecmp($a['t_continent'], $b['t_continent']);
    }
}

WordPress Version: 5.4

/**
 * Sort-helper for timezones.
 *
 * @since 2.9.0
 * @access private
 *
 * @param array $a
 * @param array $b
 * @return int
 */
function _wp_timezone_choice_usort_callback($a, $b)
{
    // Don't use translated versions of Etc.
    if ('Etc' === $a['continent'] && 'Etc' === $b['continent']) {
        // Make the order of these more like the old dropdown.
        if ('GMT+' === substr($a['city'], 0, 4) && 'GMT+' === substr($b['city'], 0, 4)) {
            return -1 * strnatcasecmp($a['city'], $b['city']);
        }
        if ('UTC' === $a['city']) {
            if ('GMT+' === substr($b['city'], 0, 4)) {
                return 1;
            }
            return -1;
        }
        if ('UTC' === $b['city']) {
            if ('GMT+' === substr($a['city'], 0, 4)) {
                return -1;
            }
            return 1;
        }
        return strnatcasecmp($a['city'], $b['city']);
    }
    if ($a['t_continent'] == $b['t_continent']) {
        if ($a['t_city'] == $b['t_city']) {
            return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
        }
        return strnatcasecmp($a['t_city'], $b['t_city']);
    } else {
        // Force Etc to the bottom of the list.
        if ('Etc' === $a['continent']) {
            return 1;
        }
        if ('Etc' === $b['continent']) {
            return -1;
        }
        return strnatcasecmp($a['t_continent'], $b['t_continent']);
    }
}

WordPress Version: 4.0

/**
 * Sort-helper for timezones.
 *
 * @since 2.9.0
 * @access private
 *
 * @param array $a
 * @param array $b
 * @return int
 */
function _wp_timezone_choice_usort_callback($a, $b)
{
    // Don't use translated versions of Etc
    if ('Etc' === $a['continent'] && 'Etc' === $b['continent']) {
        // Make the order of these more like the old dropdown
        if ('GMT+' === substr($a['city'], 0, 4) && 'GMT+' === substr($b['city'], 0, 4)) {
            return -1 * strnatcasecmp($a['city'], $b['city']);
        }
        if ('UTC' === $a['city']) {
            if ('GMT+' === substr($b['city'], 0, 4)) {
                return 1;
            }
            return -1;
        }
        if ('UTC' === $b['city']) {
            if ('GMT+' === substr($a['city'], 0, 4)) {
                return -1;
            }
            return 1;
        }
        return strnatcasecmp($a['city'], $b['city']);
    }
    if ($a['t_continent'] == $b['t_continent']) {
        if ($a['t_city'] == $b['t_city']) {
            return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
        }
        return strnatcasecmp($a['t_city'], $b['t_city']);
    } else {
        // Force Etc to the bottom of the list
        if ('Etc' === $a['continent']) {
            return 1;
        }
        if ('Etc' === $b['continent']) {
            return -1;
        }
        return strnatcasecmp($a['t_continent'], $b['t_continent']);
    }
}

WordPress Version: 3.7

/**
 * Sort-helper for timezones.
 *
 * @since 2.9.0
 *
 * @param array $a
 * @param array $b
 * @return int
 */
function _wp_timezone_choice_usort_callback($a, $b)
{
    // Don't use translated versions of Etc
    if ('Etc' === $a['continent'] && 'Etc' === $b['continent']) {
        // Make the order of these more like the old dropdown
        if ('GMT+' === substr($a['city'], 0, 4) && 'GMT+' === substr($b['city'], 0, 4)) {
            return -1 * strnatcasecmp($a['city'], $b['city']);
        }
        if ('UTC' === $a['city']) {
            if ('GMT+' === substr($b['city'], 0, 4)) {
                return 1;
            }
            return -1;
        }
        if ('UTC' === $b['city']) {
            if ('GMT+' === substr($a['city'], 0, 4)) {
                return -1;
            }
            return 1;
        }
        return strnatcasecmp($a['city'], $b['city']);
    }
    if ($a['t_continent'] == $b['t_continent']) {
        if ($a['t_city'] == $b['t_city']) {
            return strnatcasecmp($a['t_subcity'], $b['t_subcity']);
        }
        return strnatcasecmp($a['t_city'], $b['t_city']);
    } else {
        // Force Etc to the bottom of the list
        if ('Etc' === $a['continent']) {
            return 1;
        }
        if ('Etc' === $b['continent']) {
            return -1;
        }
        return strnatcasecmp($a['t_continent'], $b['t_continent']);
    }
}