wordpress评论夜间自动改为必须审核
/**
* WordPress控制评论状态的钩子:pre_comment_approved - 龙笑天下
* https://www.ilxtx.com/wordpress-filter-pre-comment-approved.html
* 实用方法:新增评论规则 -- 晚上23:30-9:00的评论全部设为待审核
*/
function lxtx_limit_comment_to_pending($approved, $commentdata){
date_default_timezone_set('Asia/Shanghai'); //设置为东八区上海时间
$time = time();
$t1 = date("Y-m-d",$time).' 09:00:00';
$t2 = date("Y-m-d",$time).' 23:30:00';
$short_t1 = strtotime($t1);
$short_t2 = strtotime($t2);
if( ($time>$short_t2 || $time<$short_t1) && !current_user_can('manage_options') ){
$approved = 0;
}
return $approved;
}
add_action('pre_comment_approved', 'lxtx_limit_comment_to_pending', 10, 2);