Skip to content

Commit b16a2c0

Browse files
committed
Date and time presets from Viper007Bond. see WordPress#7552
git-svn-id: https://develop.svn.wordpress.org/trunk@9131 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1a372cc commit b16a2c0

2 files changed

Lines changed: 105 additions & 14 deletions

File tree

wp-admin/options-general.php

Lines changed: 90 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,39 @@
1212
$title = __('General Settings');
1313
$parent_file = 'options-general.php';
1414

15+
/**
16+
* Display JavaScript on the page.
17+
*
18+
* @package WordPress
19+
* @subpackage General_Settings_Panel
20+
*/
21+
function add_js() {
22+
?>
23+
<script type="text/javascript">
24+
//<![CDATA[
25+
jQuery(document).ready(function($){
26+
$("input[name='date_format']").click(function(){
27+
if ( "date_format_custom_radio" != $(this).attr("id") )
28+
$("input[name='date_format_custom']").val( $(this).val() );
29+
});
30+
$("input[name='date_format_custom']").focus(function(){
31+
$("#date_format_custom_radio").attr("checked", "checked");
32+
});
33+
34+
$("input[name='time_format']").click(function(){
35+
if ( "time_format_custom_radio" != $(this).attr("id") )
36+
$("input[name='time_format_custom']").val( $(this).val() );
37+
});
38+
$("input[name='time_format_custom']").focus(function(){
39+
$("#time_format_custom_radio").attr("checked", "checked");
40+
});
41+
});
42+
//]]>
43+
</script>
44+
<?php
45+
}
46+
add_filter('admin_head', 'add_js');
47+
1548
include('./admin-header.php');
1649
?>
1750

@@ -96,14 +129,66 @@
96129
</tr>
97130
<tr>
98131
<th scope="row"><label for="date_format"><?php _e('Date Format') ?></label></th>
99-
<td><input name="date_format" type="text" id="date_format" size="30" value="<?php form_option('date_format'); ?>" /><br />
100-
<?php _e('Output:') ?> <strong><?php echo mysql2date(get_option('date_format'), current_time('mysql')); ?></strong></td>
132+
<td>
133+
<fieldset><legend class="hidden"><?php _e('Date Format') ?></legend>
134+
<?php
135+
136+
$date_formats = apply_filters( 'date_formats', array(
137+
__('F j, Y'),
138+
'Y/m/d',
139+
'm/d/Y',
140+
'd/m/Y',
141+
) );
142+
143+
$custom = TRUE;
144+
145+
foreach ( $date_formats as $format ) {
146+
echo "\t<label title='" . attribute_escape($format) . "'><input type='radio' name='date_format' value='" . attribute_escape($format) . "'";
147+
if ( get_option('date_format') === $format ) { // checked() uses "==" rather than "==="
148+
echo " checked='checked'";
149+
$custom = FALSE;
150+
}
151+
echo ' /> ' . gmdate( $format, current_time('timestamp') ) . "</label><br />\n";
152+
}
153+
154+
echo ' <label><input type="radio" name="date_format" id="date_format_custom_radio" value="\c\u\s\t\o\m"';
155+
checked( $custom, TRUE );
156+
echo '/> ' . __('Custom') . ': </label><input type="text" name="date_format_custom" value="' . attribute_escape( get_option('date_format') ) . '" size="30" /> ' . gmdate( get_option('date_format'), current_time('timestamp') ) . "</label>\n";
157+
158+
echo "\t<p>" . __('<a href="http://codex.wordpress.org/Formatting_Date_and_Time">Documentation on date formatting</a>. Click "Save Changes" to update sample output.') . "</p>\n";
159+
?>
160+
</fieldset>
161+
</td>
101162
</tr>
102163
<tr>
103164
<th scope="row"><label for="time_format"><?php _e('Time Format') ?></label></th>
104-
<td><input name="time_format" type="text" id="time_format" size="30" value="<?php form_option('time_format'); ?>" /><br />
105-
<?php _e('Output:') ?> <strong><?php echo gmdate(get_option('time_format'), current_time('timestamp')); ?></strong><br />
106-
<?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>
165+
<td>
166+
<fieldset><legend class="hidden"><?php _e('Time Format') ?></legend>
167+
<?php
168+
169+
$time_formats = apply_filters( 'time_formats', array(
170+
__('g:i a'),
171+
'g:i A',
172+
'H:i',
173+
) );
174+
175+
$custom = TRUE;
176+
177+
foreach ( $time_formats as $format ) {
178+
echo "\t<label title='" . attribute_escape($format) . "'><input type='radio' name='time_format' value='" . attribute_escape($format) . "'";
179+
if ( get_option('time_format') === $format ) { // checked() uses "==" rather than "==="
180+
echo " checked='checked'";
181+
$custom = FALSE;
182+
}
183+
echo ' /> ' . gmdate( $format, current_time('timestamp') ) . "</label><br />\n";
184+
}
185+
186+
echo ' <label><input type="radio" name="time_format" id="time_format_custom_radio" value="\c\u\s\t\o\m"';
187+
checked( $custom, TRUE );
188+
echo '/> ' . __('Custom') . ': </label><input type="text" name="time_format_custom" value="' . attribute_escape( get_option('time_format') ) . '" size="30" /> ' . gmdate( get_option('time_format'), current_time('timestamp') ) . "</label>\n";
189+
?>
190+
</fieldset>
191+
</td>
107192
</tr>
108193
<tr>
109194
<th scope="row"><label for="start_of_week"><?php _e('Week Starts On') ?></label></th>

wp-admin/options.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,33 +41,39 @@
4141
switch($action) {
4242

4343
case 'update':
44-
$any_changed = 0;
45-
4644
$option_page = $_POST[ 'option_page' ];
4745
check_admin_referer( $option_page . '-options' );
4846

4947
if ( !isset( $whitelist_options[ $option_page ] ) )
5048
wp_die( __( 'Error! Options page not found.' ) );
5149

52-
if ( $option_page == 'options' ) {
50+
if ( 'options' == $option_page ) {
5351
$options = explode(',', stripslashes( $_POST[ 'page_options' ] ));
5452
} else {
5553
$options = $whitelist_options[ $option_page ];
5654
}
5755

58-
if ($options) {
59-
foreach ($options as $option) {
56+
// Handle custom date/time formats
57+
if ( 'general' == $option_page ) {
58+
if ( !empty($_POST['date_format']) && !empty($_POST['date_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['date_format'] ) )
59+
$_POST['date_format'] = $_POST['date_format_custom'];
60+
if ( !empty($_POST['time_format']) && !empty($_POST['time_format_custom']) && '\c\u\s\t\o\m' == stripslashes( $_POST['time_format'] ) )
61+
$_POST['time_format'] = $_POST['time_format_custom'];
62+
}
63+
64+
if ( $options ) {
65+
foreach ( $options as $option ) {
6066
$option = trim($option);
6167
$value = $_POST[$option];
62-
if(!is_array($value)) $value = trim($value);
68+
if ( !is_array($value) ) $value = trim($value);
6369
$value = stripslashes_deep($value);
6470
update_option($option, $value);
6571
}
6672
}
6773

68-
$goback = add_query_arg('updated', 'true', wp_get_referer());
69-
wp_redirect($goback);
70-
break;
74+
$goback = add_query_arg( 'updated', 'true', wp_get_referer() );
75+
wp_redirect( $goback );
76+
break;
7177

7278
default:
7379
include('admin-header.php'); ?>

0 commit comments

Comments
 (0)