Make WordPress Core

Ticket #37465: wp_timezone_choice.2.patch

File wp_timezone_choice.2.patch, 3.8 KB (added by pbearne, 9 years ago)

add docblock to fliter

  • src/wp-includes/functions.php

     
    45334548        $structure[] = '<option ' . $selected . 'value="' . esc_attr( 'UTC' ) . '">' . __('UTC') . '</option>';
    45344549        $structure[] = '</optgroup>';
    45354550
    4536         // Do manual UTC offsets
    4537         $structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';
    4538         $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,
    4539                 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);
    4540         foreach ( $offset_range as $offset ) {
    4541                 if ( 0 <= $offset )
    4542                         $offset_name = '+' . $offset;
    4543                 else
    4544                         $offset_name = (string) $offset;
     4551        /**
     4552         * Filters if the UTC option are shown in the timezone dropdown.
     4553         *
     4554         * @since 4.6
     4555         *
     4556         * @param Bool true to show.
     4557         */
     4558        if( true === apply_filters( 'show_utc_offsets', empty( get_option('timezone_string') ) ) ) {
     4559                // Do manual UTC offsets
     4560                $structure[] = '<optgroup label="'. esc_attr__( 'Manual Offsets' ) .'">';
     4561                $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,
     4562                        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);
     4563                foreach ( $offset_range as $offset ) {
     4564                        if ( 0 <= $offset )
     4565                                $offset_name = '+' . $offset;
     4566                        else
     4567                                $offset_name = (string) $offset;
    45454568
    4546                 $offset_value = $offset_name;
    4547                 $offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);
    4548                 $offset_name = 'UTC' . $offset_name;
    4549                 $offset_value = 'UTC' . $offset_value;
    4550                 $selected = '';
    4551                 if ( $offset_value === $selected_zone )
    4552                         $selected = 'selected="selected" ';
    4553                 $structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";
     4569                        $offset_value = $offset_name;
     4570                        $offset_name = str_replace(array('.25','.5','.75'), array(':15',':30',':45'), $offset_name);
     4571                        $offset_name = 'UTC' . $offset_name;
     4572                        $offset_value = 'UTC' . $offset_value;
     4573                        $selected = '';
     4574                        if ( $offset_value === $selected_zone )
     4575                                $selected = 'selected="selected" ';
    45544576
     4577                        $structure[] = '<option ' . $selected . 'value="' . esc_attr( $offset_value ) . '">' . esc_html( $offset_name ) . "</option>";
     4578                }
     4579                $structure[] = '</optgroup>';
    45554580        }
    4556         $structure[] = '</optgroup>';
    45574581
    45584582        return join( "\n", $structure );
    45594583}
  • tests/phpunit/tests/functions/wp-timezone-choice.php

     
     1<?php
     2/**
     3 * Tests for size_format()
     4 *
     5 * @group functions.php
     6 * @ticket 36635
     7 */
     8
     9if ( ! defined( 'WPINC' ) ) {
     10        die;
     11}
     12
     13class Test_Functions_WP_Timezone_Choice extends WP_UnitTestCase {
     14
     15        public function _data_Timezone() {
     16                return array(
     17                        array( 'UTC+3', '/.*UTC\+3.*/s' ),
     18                        array( 'UTC-8', '/.*UTC-8.*/s' ),
     19                        array( 'UTC', '/.*UTC.*/s' ),
     20                        array( 'Pacific/Fakaofo', '/.*Pacific\/Fakaofo.*/s' ),
     21                        array( 'America/Toronto"', '/.*America\/Toronto.*/s' ),
     22                );
     23        }
     24
     25        /**
     26         * @dataProvider _data_Timezone
     27         *
     28         * @param $time_zone_string
     29         * @param $expected_in_return
     30         */
     31        public function test_wp_timezone_choice( $time_zone_string, $expected_in_return ) {
     32
     33                $this->assertRegExp( $expected_in_return, wp_timezone_choice( $time_zone_string ) );
     34        }
     35}
     36 No newline at end of file