Make WordPress Core

Ticket #3944: admin-functions-php.diff

File admin-functions-php.diff, 1.8 KB (added by jhodgdon, 18 years ago)

Fix to make sure all posts created/updated have valid post_date fields

  • E:/EclipseWork/WordPressDev/wp-admin/admin-functions.php

     
    102102                $hh = ($hh > 23 ) ? $hh -24 : $hh;
    103103                $mn = ($mn > 59 ) ? $mn -60 : $mn;
    104104                $ss = ($ss > 59 ) ? $ss -60 : $ss;
    105                 $_POST['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
    106                 $_POST['post_date_gmt'] = get_gmt_from_date( $_POST['post_date'] );
     105       
     106        // Ensure a real, valid date here before saving to database
     107        // by converting to a Unix timestamp and then back
     108        $tmp_post_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     109        $tmp_post_date = strtotime( $tmp_post_date );
     110        $tmp_post_date = date('Y-m-d H:i:s', $tmp_post_date );
     111       
     112                $_POST['post_date'] = $tmp_post_date;
     113                $_POST['post_date_gmt'] = get_gmt_from_date( $tmp_post_date );
    107114        }
    108115
    109116        // Create the post.
     
    268275                $hh = ($hh > 23 ) ? $hh -24 : $hh;
    269276                $mn = ($mn > 59 ) ? $mn -60 : $mn;
    270277                $ss = ($ss > 59 ) ? $ss -60 : $ss;
    271                 $_POST['post_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    272                 $_POST['post_date_gmt'] = get_gmt_from_date( "$aa-$mm-$jj $hh:$mn:$ss" );
     278
     279        // Ensure a real, valid date here before saving to database
     280        // by converting to a Unix timestamp and then back
     281        $tmp_post_date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     282        $tmp_post_date = strtotime( $tmp_post_date );
     283        $tmp_post_date = date('Y-m-d H:i:s', $tmp_post_date );
     284       
     285        $_POST['post_date'] = $tmp_post_date;
     286                $_POST['post_date_gmt'] = get_gmt_from_date( $tmp_post_date );
    273287        }