WordPress.org

Make WordPress Core

Ticket #6913: time_format_6913_rev2.diff

File time_format_6913_rev2.diff, 10.3 KB (added by regulatethis, 10 years ago)
  • wp-admin/includes/post.php

     
    8181                }
    8282        }
    8383
     84        // Let's handle the conversion to 24 hour time if the user has chosen 12 hour for posting
     85        if( !empty( $_POST['editor_time_format'] ) && $_POST['editor_time_format'] == '12_hour' ) {
     86                // If only the meridiem has been switched, we still need to update the time...
     87                if( !empty( $_POST['hidden_meridiem'] ) && $_POST['hidden_meridiem'] != $_POST['meridiem'] )
     88                        $_POST['edit_date'] = '1';
     89               
     90                // "Convert" hour back to 24-hour format if necessary, taking the meridiem into account...
     91                if ( !empty( $_POST['editor_time_format'] ) && $_POST['editor_time_format'] == '12_hour' ) {
     92                       
     93                        // Do the conversion...
     94                        $_POST['hh'] = $_POST['hh'] < 12 ? $_POST['hh'] : $_POST['hh'] - 12;
     95                       
     96                        if ( $_POST['meridiem'] == 'pm' ) {
     97                                $_POST['hh'] += 12;
     98                        }
     99                }
     100        }
     101               
    84102        if (!empty ( $_POST['edit_date'] ) ) {
    85103                $aa = $_POST['aa'];
    86104                $mm = $_POST['mm'];
  • wp-admin/includes/schema.php

     
    185185        add_option('what_to_show', 'posts');
    186186        add_option('date_format', __('F j, Y'));
    187187        add_option('time_format', __('g:i a'));
     188        add_option('g_editor_time_format', '24_hour');
    188189        add_option('links_updated_date_format', __('F j, Y g:i a'));
    189190        add_option('links_recently_updated_prepend', '<em>');
    190191        add_option('links_recently_updated_append', '</em>');
  • wp-admin/includes/template.php

     
    844844
    845845        $time_adj = time() + (get_option( 'gmt_offset' ) * 3600 );
    846846        $post_date = ($for_post) ? $post->post_date : $comment->comment_date;
     847
     848        $time_format = get_user_option('editor_time_format');
     849        if ( empty($time_format) || $time_format == 'default')
     850                $time_format = get_option('g_editor_time_format');
     851
     852        $hour_format = $time_format == '12_hour' ? 'g' : 'H';
     853
    847854        $jj = ($edit) ? mysql2date( 'd', $post_date ) : gmdate( 'd', $time_adj );
    848855        $mm = ($edit) ? mysql2date( 'm', $post_date ) : gmdate( 'm', $time_adj );
    849856        $aa = ($edit) ? mysql2date( 'Y', $post_date ) : gmdate( 'Y', $time_adj );
    850         $hh = ($edit) ? mysql2date( 'H', $post_date ) : gmdate( 'H', $time_adj );
     857        $hh = ($edit) ? mysql2date( $hour_format, $post_date ) : gmdate( $hour_format, $time_adj );
    851858        $mn = ($edit) ? mysql2date( 'i', $post_date ) : gmdate( 'i', $time_adj );
    852859        $ss = ($edit) ? mysql2date( 's', $post_date ) : gmdate( 's', $time_adj );
    853 
     860       
     861        if( '12_hour' == $time_format ) {
     862                $meridiem = ($edit) ? date( 'a', strtotime($post_date) ) : date( 'a' );
     863                $locale_meridiem = ($edit) ? $wp_locale->get_meridiem( date( 'A', strtotime($post_date) ) ) : $wp_locale->get_meridiem( date( 'A' ) );
     864                $locale_am = $wp_locale->get_meridiem( 'AM' );
     865                $locale_pm = $wp_locale->get_meridiem( 'PM' );
     866        }
    854867        $month = "<select id=\"mm\" name=\"mm\"$tab_index_attribute>\n";
    855868        for ( $i = 1; $i < 13; $i = $i +1 ) {
    856869                $month .= "\t\t\t" . '<option value="' . zeroise($i, 2) . '"';
     
    864877        $year = '<input type="text" id="aa" name="aa" value="' . $aa . '" size="4" maxlength="5"' . $tab_index_attribute . ' autocomplete="off"  />';
    865878        $hour = '<input type="text" id="hh" name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off"  />';
    866879        $minute = '<input type="text" id="mn" name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off"  />';
     880       
     881        if( '12_hour' == $time_format ) {
     882                $am_selected = $meridiem == 'am' ? 'selected="selected"' : '';
     883                $pm_selected = $meridiem == 'pm' ? 'selected="selected"' : '';
     884               
     885                $meridiem_drop_down = '<select name="meridiem" id="meridiem"' . $tab_index_attribute . '>' . PHP_EOL;
     886                $meridiem_drop_down .= '        <option value="am" ' . $am_selected . '>' . $locale_am . '</option>' . PHP_EOL;
     887                $meridiem_drop_down .= '        <option value="pm" ' . $pm_selected . '>' . $locale_pm . '</option>' . PHP_EOL;
     888                $meridiem_drop_down .= '</selected>' . PHP_EOL;
     889        }
     890       
    867891        printf(_c('%1$s%2$s, %3$s <br />@ %4$s : %5$s|1: month input, 2: day input, 3: year input, 4: hour input, 5: minute input'), $month, $day, $year, $hour, $minute);
     892       
     893        if ( '12_hour' == $time_format )
     894                echo $meridiem_drop_down;
     895       
    868896        echo "\n\n";
    869897        foreach ( array('mm', 'jj', 'aa', 'hh', 'mn') as $timeunit )
    870898                echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $$timeunit . '" />' . "\n";
     899
     900        if( '12_hour' == $time_format )
     901                echo '<input type="hidden" id="hidden_meridiem" name="hidden_meridiem" value="' . $meridiem . '" />';
     902
    871903?>
    872904
    873905<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />
     906<input type="hidden" id="editor_time_format" name="editor_time_format" value="<?php echo $time_format; ?>" />
    874907<?php
    875908}
    876909
  • wp-admin/includes/user.php

     
    8080        else
    8181                $user->admin_color = 'fresh';
    8282
     83        if ( !update ) {
     84                $user->editor_time_format = 'default'; // Default to global setting for new users.
     85        } else if ( isset( $_POST['editor_time_format'] ) ) {
     86                echo $_POST['editor_time_format'];
     87                exit;
     88                $user->editor_time_format = $_POST['editor_time_format'];
     89        } else {
     90                $user->editor_time_format = 'default';
     91        }
     92               
    8393        $errors = new WP_Error();
    8494
    8595        /* checking that username has been typed */
  • wp-admin/options-general.php

     
    9898<?php _e('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date formatting</a>. Click "Save Changes" to update sample output.') ?></td>
    9999</tr>
    100100<tr>
     101<th scope="row"><?php _e('Editor Time Format') ?></th>
     102<td>
     103<?php
     104        $current_time_format = get_option('g_editor_time_format');
     105        if ( empty($current_time_format) )
     106                $current_time_format = '24_hour';
     107?>
     108        <label for="g_editor_time_format_12"><input name="g_editor_time_format" id="g_editor_time_format_12" type="radio" value="12_hour" <?php checked('12_hour', $current_time_format);?> />&nbsp;12-hour <i>2:35pm</i></label><br />
     109        <label for="g_editor_time_format_24"><input name="g_editor_time_format" id="g_editor_time_format_24" type="radio" value="24_hour" <?php checked('24_hour', $current_time_format);?> />&nbsp;24-hour <i>14:35</i></label><br />
     110</tr>
     111<tr>
    101112<th scope="row"><?php _e('Week Starts On') ?></th>
    102113<td><select name="start_of_week" id="start_of_week">
    103114<?php
     
    112123
    113124<p class="submit"><input type="submit" name="Submit" value="<?php _e('Save Changes') ?>" />
    114125<input type="hidden" name="action" value="update" />
    115 <input type="hidden" name="page_options" value="<?php if ( ! defined( 'WP_SITEURL' ) ) echo 'siteurl,'; if ( ! defined( 'WP_HOME' ) ) echo 'home,'; ?>blogname,blogdescription,admin_email,users_can_register,gmt_offset,date_format,time_format,start_of_week,comment_registration,default_role" />
     126<input type="hidden" name="page_options" value="<?php if ( ! defined( 'WP_SITEURL' ) ) echo 'siteurl,'; if ( ! defined( 'WP_HOME' ) ) echo 'home,'; ?>blogname,blogdescription,admin_email,users_can_register,gmt_offset,date_format,time_format,g_editor_time_format,start_of_week,comment_registration,default_role" />
    116127</p>
    117128</form>
    118129
  • wp-admin/user-edit.php

     
    161161        </tr>
    162162<?php endif; ?>
    163163<tr>
     164<th scope="row"><?php _e('Editor Time Format')?></th>
     165<td>
     166        <?php
     167                $default_time_format = get_option('g_editor_time_format');
     168                $default_time_format = $default_time_format == '24_hour' ? '24-hour' : '12-hour';
     169               
     170                $current_time_format = get_user_option('editor_time_format', $user_id);
     171                if ( empty($current_time_format) )
     172                        $current_time_format = 'default';
     173        ?>
     174        <label for="editor_time_format_default"><input name="editor_time_format" id="editor_time_format_default" type="radio" value="default" <?php checked('default', $current_time_format);?> />&nbsp;Default <i>Use global setting (<?php echo $default_time_format; ?>)</i></label><br />
     175        <label for="editor_time_format_12"><input name="editor_time_format" id="editor_time_format_12" type="radio" value="12_hour" <?php checked('12_hour', $current_time_format);?> />&nbsp;12-hour <i>2:35pm</i></label><br />
     176        <label for="editor_time_format_24"><input name="editor_time_format" id="editor_time_format_24" type="radio" value="24_hour" <?php checked('24_hour', $current_time_format);?> />&nbsp;24-hour <i>14:35</i></label><br />
     177</td>
     178</tr>
     179<tr>
    164180<th scope="row"><?php _e('Admin Color Scheme')?></th>
    165181<td>
    166182<?php
  • wp-includes/registration.php

     
    9191 * 'jabber' - User's Jabber account.
    9292 * 'aim' - User's AOL IM account.
    9393 * 'yim' - User's Yahoo IM account.
     94 * 'editor_time_format' - A string used to set the user's chosen time format for the editor (12_hour or 24_hour)
    9495 *
    9596 * @since 2.0.0
    9697 * @uses $wpdb WordPress database layer.
     
    157158        if ( empty($admin_color) )
    158159                $admin_color = 'fresh';
    159160        $admin_color = preg_replace('|[^a-z0-9 _.\-@]|i', '', $admin_color);
    160 
     161       
     162        if ( empty($editor_time_format) ) {
     163                $editor_time_format = 'default';
     164        } else {
     165                if ( $editor_time_format != '12_hour' && $editor_time_format != '24_hour' ) {
     166                        $editor_time_format = 'default';
     167                }
     168        }
     169       
    161170        if ( empty($user_registered) )
    162171                $user_registered = gmdate('Y-m-d H:i:s');
    163172
     
    181190        update_usermeta( $user_id, 'yim', $yim );
    182191        update_usermeta( $user_id, 'rich_editing', $rich_editing);
    183192        update_usermeta( $user_id, 'admin_color', $admin_color);
     193        update_usermeta( $user_id, 'editor_time_format', $editor_time_format);
    184194
    185195        if ( $update && isset($role) ) {
    186196                $user = new WP_User($user_id);