touch_time

Print out HTML form date elements for editing post or comment publish date.

Description

touch_time( (int) $edit = 1, (int) $for_post = 1, (int) $tab_index = 0, (int) $multi = 0 ); 

Parameters (4)

0. $edit — Optional. (int) => 1
Accepts 1|true for editing the date, 0|false for adding the date.
1. $for_post — Optional. (int) => 1
Accepts 1|true for applying the date to a post, 0|false for a comment.
2. $tab_index — Optional. (int)
The tabindex attribute to add. Default 0.
3. $multi — Optional. (int)
Whether the additional fields and buttons should be added. Default 0|false.

Usage

  1. if ( !function_exists( 'touch_time' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/template.php'; 
  3.  
  4. // Accepts 1|true for editing the date, 0|false for adding the date. 
  5. $edit = 1; 
  6.  
  7. // Accepts 1|true for applying the date to a post, 0|false for a comment. 
  8. $for_post = 1; 
  9.  
  10. // The tabindex attribute to add. Default 0. 
  11. $tab_index = -1; 
  12.  
  13. // Optional. Whether the additional fields and buttons should be added. 
  14. // Default 0|false. 
  15. $multi = -1; 
  16.  
  17. // NOTICE! Understand what this does before running. 
  18. $result = touch_time($edit, $for_post, $tab_index, $multi); 
  19.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/template.php  
  1. function touch_time( $edit = 1, $for_post = 1, $tab_index = 0, $multi = 0 ) { 
  2. global $wp_locale; 
  3. $post = get_post(); 
  4.  
  5. if ( $for_post ) 
  6. $edit = ! ( in_array($post->post_status, array('draft', 'pending') ) && (!$post->post_date_gmt || '0000-00-00 00:00:00' == $post->post_date_gmt ) ); 
  7.  
  8. $tab_index_attribute = ''; 
  9. if ( (int) $tab_index > 0 ) 
  10. $tab_index_attribute = " tabindex=\"$tab_index\""; 
  11.  
  12. // todo: Remove this? 
  13. // echo '<label for="timestamp" style="display: block;"><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp"'.$tab_index_attribute.' /> '.__( 'Edit timestamp' ).'</label><br />'; 
  14.  
  15. $time_adj = current_time('timestamp'); 
  16. $post_date = ($for_post) ? $post->post_date : get_comment()->comment_date; 
  17. $jj = ($edit) ? mysql2date( 'd', $post_date, false ) : gmdate( 'd', $time_adj ); 
  18. $mm = ($edit) ? mysql2date( 'm', $post_date, false ) : gmdate( 'm', $time_adj ); 
  19. $aa = ($edit) ? mysql2date( 'Y', $post_date, false ) : gmdate( 'Y', $time_adj ); 
  20. $hh = ($edit) ? mysql2date( 'H', $post_date, false ) : gmdate( 'H', $time_adj ); 
  21. $mn = ($edit) ? mysql2date( 'i', $post_date, false ) : gmdate( 'i', $time_adj ); 
  22. $ss = ($edit) ? mysql2date( 's', $post_date, false ) : gmdate( 's', $time_adj ); 
  23.  
  24. $cur_jj = gmdate( 'd', $time_adj ); 
  25. $cur_mm = gmdate( 'm', $time_adj ); 
  26. $cur_aa = gmdate( 'Y', $time_adj ); 
  27. $cur_hh = gmdate( 'H', $time_adj ); 
  28. $cur_mn = gmdate( 'i', $time_adj ); 
  29.  
  30. $month = '<label><span class="screen-reader-text">' . __( 'Month' ) . '</span><select ' . ( $multi ? '' : 'id="mm" ' ) . 'name="mm"' . $tab_index_attribute . ">\n"; 
  31. for ( $i = 1; $i < 13; $i = $i +1 ) { 
  32. $monthnum = zeroise($i, 2); 
  33. $monthtext = $wp_locale->get_month_abbrev( $wp_locale->get_month( $i ) ); 
  34. $month .= "\t\t\t" . '<option value="' . $monthnum . '" data-text="' . $monthtext . '" ' . selected( $monthnum, $mm, false ) . '>'; 
  35. /** translators: 1: month number (01, 02, etc.), 2: month abbreviation */ 
  36. $month .= sprintf( __( '%1$s-%2$s' ), $monthnum, $monthtext ) . "</option>\n"; 
  37. $month .= '</select></label>'; 
  38.  
  39. $day = '<label><span class="screen-reader-text">' . __( 'Day' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="jj" ' ) . 'name="jj" value="' . $jj . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  40. $year = '<label><span class="screen-reader-text">' . __( 'Year' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="aa" ' ) . 'name="aa" value="' . $aa . '" size="4" maxlength="4"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  41. $hour = '<label><span class="screen-reader-text">' . __( 'Hour' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="hh" ' ) . 'name="hh" value="' . $hh . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  42. $minute = '<label><span class="screen-reader-text">' . __( 'Minute' ) . '</span><input type="text" ' . ( $multi ? '' : 'id="mn" ' ) . 'name="mn" value="' . $mn . '" size="2" maxlength="2"' . $tab_index_attribute . ' autocomplete="off" /></label>'; 
  43.  
  44. echo '<div class="timestamp-wrap">'; 
  45. /** translators: 1: month, 2: day, 3: year, 4: hour, 5: minute */ 
  46. printf( __( '%1$s %2$s, %3$s @ %4$s:%5$s' ), $month, $day, $year, $hour, $minute ); 
  47.  
  48. echo '</div><input type="hidden" id="ss" name="ss" value="' . $ss . '" />'; 
  49.  
  50. if ( $multi ) return; 
  51.  
  52. echo "\n\n"; 
  53. $map = array( 
  54. 'mm' => array( $mm, $cur_mm ),  
  55. 'jj' => array( $jj, $cur_jj ),  
  56. 'aa' => array( $aa, $cur_aa ),  
  57. 'hh' => array( $hh, $cur_hh ),  
  58. 'mn' => array( $mn, $cur_mn ),  
  59. ); 
  60. foreach ( $map as $timeunit => $value ) { 
  61. list( $unit, $curr ) = $value; 
  62.  
  63. echo '<input type="hidden" id="hidden_' . $timeunit . '" name="hidden_' . $timeunit . '" value="' . $unit . '" />' . "\n"; 
  64. $cur_timeunit = 'cur_' . $timeunit; 
  65. echo '<input type="hidden" id="' . $cur_timeunit . '" name="' . $cur_timeunit . '" value="' . $curr . '" />' . "\n"; 
  66. ?> 
  67.  
  68. <p> 
  69. <a href="#edit_timestamp" class="save-timestamp hide-if-no-js button"><?php _e('OK'); ?></a> 
  70. <a href="#edit_timestamp" class="cancel-timestamp hide-if-no-js button-cancel"><?php _e('Cancel'); ?></a> 
  71. </p> 
  72. <?php