Make WordPress Core


Ignore:
Timestamp:
09/20/2012 10:46:50 AM (11 years ago)
Author:
westi
Message:

Posting: Improve the invalid date protection code based on feedback from nacin.

  • Introduce a wp_checkdate() function with a single filter to centralise the code that validates dates.
  • Improve the error message
  • Correctly handle the return value of wp_insert_post which is not always a WP_Error on failure

Fixes #17180

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/post.php

    r21921 r21922  
    123123        $mn = ($mn > 59 ) ? $mn -60 : $mn;
    124124        $ss = ($ss > 59 ) ? $ss -60 : $ss;
    125         $valid_date = apply_filters( '_wp_translate_postdata_valid_date', checkdate( $mm, $jj, $aa ), $post_data );
     125        $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     126        $valid_date = wp_checkdate( $mm, $jj, $aa, $post_data['post_date'] );
    126127        if ( !$valid_date ) {
    127             return new WP_Error( 'invalid_date', __( 'Woops, the provided date is invalid.' ) );
    128         }
    129         $post_data['post_date'] = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", $aa, $mm, $jj, $hh, $mn, $ss );
     128            return new WP_Error( 'invalid_date', __( 'Whoops, the provided date is invalid.' ) );
     129        }
    130130        $post_data['post_date_gmt'] = get_gmt_from_date( $post_data['post_date'] );
    131131    }
Note: See TracChangeset for help on using the changeset viewer.