Make WordPress Core

Ticket #3944: post-php.diff

File post-php.diff, 1.7 KB (added by JDTrower, 17 years ago)

Fix to make sure all posts created/updated have valid post_date fields based on the patch for admin-functions.php.

  • post.php

     
    8686                $hh = ($hh > 23 ) ? $hh -24 : $hh;
    8787                $mn = ($mn > 59 ) ? $mn -60 : $mn;
    8888                $ss = ($ss > 59 ) ? $ss -60 : $ss;
    89                 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    90                 $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
     89               
     90                // Ensure a real, valid date here before saving to database
     91            // by converting to a Unix timestamp and then back
     92            $tmp_post_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     93            $tmp_post_date = strtotime( $tmp_post_date );
     94            $tmp_post_date = date('Y-m-d H:i:s', $tmp_post_date );
     95                         
     96            $_POST['post_date'] = $tmp_post_date;
     97            $_POST['post_date_gmt'] = get_gmt_from_date( $tmp_post_date );
    9198        }
    9299
    93100        // Meta Stuff
     
    277284                $hh = ($hh > 23 ) ? $hh -24 : $hh;
    278285                $mn = ($mn > 59 ) ? $mn -60 : $mn;
    279286                $ss = ($ss > 59 ) ? $ss -60 : $ss;
    280                 $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
    281                 $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
     287               
     288                // Ensure a real, valid date here before saving to database
     289                // by converting to a Unix timestamp and then back
     290            $tmp_post_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     291            $tmp_post_date = strtotime( $tmp_post_date );
     292            $tmp_post_date = date('Y-m-d H:i:s', $tmp_post_date );
     293                         
     294            $_POST['post_date'] = $tmp_post_date;
     295            $_POST['post_date_gmt'] = get_gmt_from_date( $tmp_post_date );
    282296        }
    283297
    284298        // Create the post.