WP_TIMEZONE_CHOICE() генерирует список временных зон для

Результат:

Изменения

Код функции

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' );

    // Загружаем переводы для континентов и городов.
    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;
        }

        // Проверяем, какие части зоны существуют.
        $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] );

        $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' ) : '' ),
        );
    }
    usort( $zonen, '_wp_timezone_choice_usort_callback' );

    $structure = array();

    if ( empty( $selected_zone ) ) {
        $structure[] = '';
    }

    foreach ( $zonen as $key => $zone ) {
        $value = array( $zone['continent'] );

        if ( empty( $zone['city'] ) ) {
            $display = $zone['t_continent'];
        } else {
            if ( ! isset( $zonen[ $key - 1 ] ) || $zonen[ $key - 1 ]['continent'] !== $zone['continent'] ) {
                $structure[] = '';
            }

            $value[] = $zone['city'];
            $display = $zone['t_city'];
            if ( ! empty( $zone['subcity'] ) ) {
                $value[]  = $zone['subcity'];
                $display .= ' - ' . $zone['t_subcity'];
            }
        }

        $value = implode( '/', $value );
        $selected = '';
        if ( $value === $selected_zone ) {
            $selected = 'selected="selected" ';
        }
        $structure[] = '';

        if ( ! empty( $zone['city'] ) && ( ! isset( $zonen[ $key + 1 ] ) || ( isset( $zonen[ $key + 1 ] ) && $zonen[ $key + 1 ]['continent'] !== $zone['continent'] ) ) ) {
            $structure[] = '';
        }
    }

    $structure[] = '';
    $selected = '';
    if ( 'UTC' === $selected_zone ) {
        $selected = 'selected="selected" ';
    }
    $structure[] = '';
    $structure[] = '';

    $structure[]  = '';
    $offset_range = array(
        -12, -11.5, -11, -10.5, -10, -9.5, -9, -8.5, -8, 
        -7.5, -7, -6.5, -6, -5.5, -5, -4.5, -4, -3.5, 
        -3, -2.5, -2, -1.5, -1, -0.5, 0, 0.5, 1, 
        1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 5.75, 
        6, 6.5, 7, 7.5, 8, 8.5, 8.75, 9, 9.5, 10, 
        10.5, 11, 11.5, 12, 12.75, 13, 13.75, 14,
    );
    foreach ( $offset_range as $offset ) {
        $offset_name = (0 <= $offset ? '+' . $offset : (string)$offset);
        $offset_value = 'UTC' . $offset_name;
        $selected = '';
        if ( $offset_value === $selected_zone ) {
            $selected = 'selected="selected" ';
        }
        $structure[] = '';
    }
    $structure[] = '';

    return implode( "n", $structure );
}

Связанные функции

Leave a Reply

Ваш адрес email не будет опубликован. Обязательные поля помечены *