[WordPress教程] WordPress限制用户后台投稿时间 -静鱼客栈

2021-09-22 0 959

对于WordPress很多不会开发的小伙伴,主题没有前端投稿功能,只有默认的后端投稿但又想不让他们频繁投稿就需要WordPress限制用户后台投稿时间,下面我写了段小代码请放到主题函数文件中。


function Ruike_limit_submission_time($new_status, $old_status, $post) {
	global $wpdb;
	$uid=get_current_user_id();
    $last_post = $wpdb->get_var("SELECT post_date FROM $wpdb->posts WHERE post_author='{$uid}' AND post_status='publish' AND post_type = 'post' ORDER BY post_date DESC LIMIT 1");
    $latest  = strtotime($last_post);
	$msn='您投稿也太勤快了吧,先歇会儿,您可以返回<a href="'.admin_url('edit.php').'" rel="external nofollow" >文章管理</a>';
	if ((current_time('timestamp') - $latest) < 12000 ){
		if($new_status=='auto-draft'){
			wp_die($msn);
		}
		
    }
}
add_action('transition_post_status','Ruike_limit_submission_time',10,3);

以上代码未必对所有主题起作用,但是实测在我们瑞课主题是有效管用的,今天的WordPress限制用户后台投稿时间教程就写到这里吧,如果您有好的方案可以告诉我们来更新此教程。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

静鱼客栈 学习中心 [WordPress教程] WordPress限制用户后台投稿时间 -静鱼客栈 https://wp.muooy.cn/8962.html

静鱼客栈的帅逼站长~

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务