Ticket #1837: bug1837_drafts_shouldnt_get_auto_timestamped.diff

File bug1837_drafts_shouldnt_get_auto_timestamped.diff, 3.4 KB (added by coffee2code, 7 years ago)

The patch I mentioned.

  • wp-admin/admin-functions.php

     
    839839 
    840840function touch_time($edit = 1, $for_post = 1) { 
    841841        global $month, $post, $comment; 
    842         if ($for_post && ('draft' == $post->post_status)) { 
    843                 $checked = 'checked="checked" '; 
    844                 $edit = false; 
    845         } else { 
    846                 $checked = ' '; 
    847         } 
    848842 
    849         echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" '.$checked.'/> <label for="timestamp">'.__('Edit timestamp').'</label></legend>'; 
     843        if ( $for_post ) 
     844                $edit = ( ('draft' == $post->post_status) && (!$post->post_date || '0000-00-00 00:00:00' == $post->post_date) ) ? false : true; 
    850845 
     846        echo '<fieldset><legend><input type="checkbox" class="checkbox" name="edit_date" value="1" id="timestamp" /> <label for="timestamp">'.__('Edit timestamp').'</label></legend>'; 
     847 
    851848        $time_adj = time() + (get_settings('gmt_offset') * 3600); 
    852849        $post_date = ($for_post) ? $post->post_date : $comment->comment_date; 
    853850        $jj = ($edit) ? mysql2date('d', $post_date) : gmdate('d', $time_adj); 
     
    876873<input type="text" id="hh" name="hh" value="<?php echo $hh ?>" size="2" maxlength="2" /> :  
    877874<input type="text" id="mn" name="mn" value="<?php echo $mn ?>" size="2" maxlength="2" />  
    878875<input type="hidden" id="ss" name="ss" value="<?php echo $ss ?>" size="2" maxlength="2" />  
    879 <?php _e('Existing timestamp'); ?>:  
    880         <?php 
    881  
    882         // We might need to readjust to display proper existing timestamp 
    883         if ($for_post && ('draft' == $post->post_status)) { 
    884                 $jj = mysql2date('d', $post_date); 
    885                 $mm = mysql2date('m', $post_date); 
    886                 $aa = mysql2date('Y', $post_date); 
    887                 $hh = mysql2date('H', $post_date); 
    888                 $mn = mysql2date('i', $post_date); 
    889                 $ss = mysql2date('s', $post_date); 
     876<?php 
     877        if ( $edit ) { 
     878                _e('Existing timestamp'); 
     879                echo ": {$month[$mm]} $jj, $aa @ $hh:$mn"; 
    890880        } 
    891         echo "{$month[$mm]} $jj, $aa @ $hh:$mn"; 
    892881?> 
    893882</fieldset> 
    894883        <?php 
  • wp-includes/functions-post.php

     
    5454                $post_name = sanitize_title($post_name); 
    5555        } 
    5656         
    57         if (empty($post_date)) 
    58                 $post_date = current_time('mysql'); 
    59         if (empty($post_date_gmt))  
    60                 $post_date_gmt = get_gmt_from_date($post_date); 
     57        // If the post date is empty (due to having been new or a draft) and status is not 'draft', set date to now 
     58        if (empty($post_date)) { 
     59                if ( 'draft' != $post_status ) 
     60                        $post_date = current_time('mysql'); 
     61        } 
     62        if (empty($post_date_gmt)) { 
     63                if ( 'draft' != $post_status ) 
     64                        $post_date_gmt = get_gmt_from_date($post_date); 
     65        } 
    6166 
    6267        if ( empty($comment_status) ) { 
    6368                if ( $update ) 
     
    376381        else  
    377382                $post_cats = $post['post_category']; 
    378383 
     384        // Drafts shouldn't be assigned a date unless explicitly done so by the user 
     385        if ( 'draft' == $post['post_status'] && empty($postarr['edit_date']) && empty($postarr['post_date']) &&  
     386             ('0000-00-00 00:00:00' == $post['post_date']) ) 
     387                $clear_date = true; 
     388        else 
     389                $clear_date = false; 
     390 
    379391        // Merge old and new fields with new fields overwriting old ones. 
    380392        $postarr = array_merge($post, $postarr); 
    381393        $postarr['post_category'] = $post_cats;  
    382  
     394        if ( $clear_date ) { 
     395                $postarr['post_date'] = ''; 
     396                $postarr['post_date_gmt'] = ''; 
     397        } 
    383398        return wp_insert_post($postarr); 
    384399} 
    385400