Uses wp_checkdate to return a valid Gregorian-calendar value for post_date.
Description
If post_date is not provided, this first checks post_date_gmt if provided, then falls back to use the current time. For back-compat purposes in wp_insert_post, an empty post_date and an invalid post_date_gmt will continue to return '1970-01-01 00:00:00' rather than false.
Parameters
$post_datestringoptional
The date in mysql format (Y-m-d H:i:s).Default: ''
$post_date_gmtstringoptional
The GMT date in mysql format (Y-m-d H:i:s).Default: ''
Return
string|false
A valid Gregorian-calendar date string, or false on failure.
Uses · 3
current_time()Retrieves the current time based on specified type.
get_date_from_gmt()Given a date in UTC or GMT timezone, returns that date in the timezone of the site.
wp_checkdate()Tests if the supplied date is valid for the Gregorian calendar.
5340functionwp_resolve_post_date($post_date='',$post_date_gmt=''){5341// If the date is empty, set the date to now.5342if(empty($post_date)||'0000-00-00 00:00:00'===$post_date){5343if(empty($post_date_gmt)||'0000-00-00 00:00:00'===$post_date_gmt){5344$post_date=current_time('mysql');5345}else{5346$post_date=get_date_from_gmt($post_date_gmt);5347}5348}53495350// Validate the date.5351$month=(int)substr($post_date,5,2);5352$day=(int)substr($post_date,8,2);5353$year=(int)substr($post_date,0,4);53545355$valid_date=wp_checkdate($month,$day,$year,$post_date);53565357if(!$valid_date){5358returnfalse;5359}5360return$post_date;5361}
History
Introduced in 5.7.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/post.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.