I'm working on a custom event scheduler for my website that allows people to easily go in and set the article to post in the future. The reason I'm overriding the normal Wordpress functionality is because I wanted to make it super easy to choose the date, since the sermons should only be posted on a Sunday. So I have a custom dropdown calendar that only allows you to select the Sunday's of a month.
Anyways my problem is that all my posts give an error of "Missed Schedule" in the admin panel. I'm able to get around this by using the "post_status" => "future" to list posts on the page, but this is kinda "hacky"...
Why would this code be giving me that "Missed Schedule" error?
function cfc_reset_sermondate( $data ) {
if($data['post_type'] == 'sermon_post') {
if($_POST['cfc_sermon_date']) {
$date = $_POST['cfc_sermon_date'];
// $date = DateTime::createFromFormat('D - M j, Y', $date);
// $date = $date->format('Y-m-d');
$date = createFromFormat($date);
$postDate = strtotime($date);
$data['post_date'] = $date;
$todaysDate = strtotime( date( 'Y-m-d' ) );
if ( $postDate > $todaysDate ) {
$data['post_status'] = 'future';
}
}
}
return $data;
}
add_filter( 'wp_insert_post_data', 'cfc_reset_sermondate', '99', 1);
Here's the createFromFormat function:
function createFromFormat($date_ugly) {
$schedule = 'Sunday - Sep 15, 2000';
// %Y, %m and %d correspond to date()'s Y m and d.
// %I corresponds to H, %M to i and %p to a
$ugly = strptime($date_ugly, '%A - %b %e, %Y');
$ymd = sprintf(
// This is a format string that takes six total decimal
// arguments, then left-pads them with zeros to either
// 4 or 2 characters, as needed
'%04d-%02d-%02d',
$ugly['tm_year'] + 1900, // This will be "111", so we need to add 1900.
$ugly['tm_mon'] + 1, // This will be the month minus one, so we add one.
$ugly['tm_mday'],
$ugly['tm_hour'],
$ugly['tm_min'],
$ugly['tm_sec']
);
$new_schedule = new DateTime($ymd);
return $new_schedule->format('Y-m-d');
}

