我正在为我的网站开发一个定制的事件调度器,让人们可以轻松地进入并设置文章在将来发布。我之所以要覆盖正常的Wordpress功能,是因为我想让选择日期变得非常容易,因为布道应该只在周日发布。因此,我有一个自定义下拉日历,只允许您选择一个月的星期日。
无论如何,我的问题是,我所有的帖子在管理面板中都给出了一个“错过时间表”的错误。我可以通过使用“post\\u status”=>“future”在页面上列出帖子来绕过这个问题,但这有点“黑客”。。。
为什么这段代码会给我那个“错过计划”的错误?
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);
以下是createFromFormat函数: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\');
}
