WordPress.org

Make WordPress Core

Ticket #26798: post.php.2.diff

File post.php.2.diff, 990 bytes (added by mobius5150, 7 years ago)
  • post.php

     
    28022802                $post_date = current_time('mysql');
    28032803
    28042804                // validate the date
    2805                 $mm = substr( $post_date, 5, 2 );
    2806                 $jj = substr( $post_date, 8, 2 );
    2807                 $aa = substr( $post_date, 0, 4 );
    2808                 $valid_date = wp_checkdate( $mm, $jj, $aa, $post_date );
     2805                preg_match("/^(?P<year>\d{4})-(?P<month>0?[1-9]|1[012])-(?P<day>0?[1-9]|[12][0-9]|3[01])/", $post_date, $matches);
     2806               
     2807                $valid_date = false;
     2808                if ( count( $matches ) >= 6 ) // Each capture group in the REGEX creates two array elements
     2809                    $valid_date = wp_checkdate( (int) $matches['month'], (int) $matches['day'], (int) $matches['year'], $post_date );
     2810               
    28092811                if ( !$valid_date ) {
    28102812                        if ( $wp_error )
    28112813                                return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );