WordPress用户时间周期限制发布文章数量

将以下代码放入WordPress主题的function.php文件中,并保存:

//设定每篇文章的发布间隔
function force_time_between_posts($data, $postarr) {
global $wpdb;
if (empty($postarr['ID'])) return $data; $latest = $wpdb->get_var("
SELECT post_date
FROM {$wpdb->posts}
WHERE post_status IN('future','publish')
AND post_type = 'post'
AND ID != {$postarr['ID']}
ORDER BY post_date DESC
LIMIT 1");
$distance = 5; // 时间间隔(分钟)
$latest = strtotime($latest);
$current = strtotime($data['post_date']);
if ($latest < $current) { $diff = $current - $latest; } else { $diff = 0; } if ($diff >= 0 && $diff < ($distance * 60)) {
return false;
}else{
return $data;
}
}
add_action('wp_insert_post_data','force_time_between_posts',1,2);
//设定每篇文章的发布间隔 
function force_time_between_posts($data, $postarr) {
 global $wpdb;
 if (empty($postarr['ID'])) return $data;  $latest = $wpdb->get_var("
 SELECT post_date
 FROM {$wpdb->posts} 
 WHERE post_status IN('future','publish') 
 AND post_type = 'post' 
 AND ID != {$postarr['ID']}
 ORDER BY post_date DESC
 LIMIT 1");
 $distance = 5; // 时间间隔(分钟)
 $latest = strtotime($latest);
 $current = strtotime($data['post_date']);
 if ($latest < $current) { $diff = $current - $latest; } else { $diff = 0; } if ($diff >= 0 && $diff < ($distance * 60)) {
return false;
 }else{
     return $data;
 }
}
add_action('wp_insert_post_data','force_time_between_posts',1,2);
//设定每篇文章的发布间隔 function force_time_between_posts($data, $postarr) { global $wpdb; if (empty($postarr['ID'])) return $data; $latest = $wpdb->get_var(" SELECT post_date FROM {$wpdb->posts} WHERE post_status IN('future','publish') AND post_type = 'post' AND ID != {$postarr['ID']} ORDER BY post_date DESC LIMIT 1"); $distance = 5; // 时间间隔(分钟) $latest = strtotime($latest); $current = strtotime($data['post_date']); if ($latest < $current) { $diff = $current - $latest; } else { $diff = 0; } if ($diff >= 0 && $diff < ($distance * 60)) { return false; }else{ return $data; } } add_action('wp_insert_post_data','force_time_between_posts',1,2);
© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
The sacrifices you make today will pay dividends in the future.
今天的牺牲和努力未来都会有回报
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容