admin管理员组文章数量:1024074
Hi my wordpress users are able to submit posts. But I want to limit the number of posts that they can submit. Can you help me?
I already tried / and / but they dont work.
Thanks!
Hi my wordpress users are able to submit posts. But I want to limit the number of posts that they can submit. Can you help me?
I already tried https://wordpress/plugins/bainternet-posts-creation-limits/ and https://cs.wordpress/plugins/wpsite-limit-posts/ but they dont work.
Thanks!
Share Improve this question asked Jun 8, 2015 at 18:49 Vale BoccaccioVale Boccaccio 1 2- 2 Please read How to Ask. – kaiser Commented Jun 8, 2015 at 19:01
- By default, subscribers can't create posts at all so, first off, how was that hacked into place? – s_ha_dum Commented Jun 8, 2015 at 19:18
1 Answer
Reset to default 5This solution uses the publish post hook. What's happening here is that when a post is published, it runs the custom post_published_limit
function we create below.
The $max_posts is set statically here, you can expand it to pull the value from elsewhere, but that's beyond the scope of the question being asked. However there is plenty of literature describing how to do that.
The function then gets the count of posts of the author currently trying to publish.
If the $count exceeds the $max_posts the function will save it as a draft instead of publishing it.
function post_published_limit( $ID, $post ) {
$max_posts = 5; // change this or set it as an option that you can retrieve.
$author = $post->post_author; // Post author ID.
$count = count_user_posts( $author, 'post'); // get author post count
if ( $count > $max_posts ) {
// count too high, let's set it to draft.
$post->post_status = 'draft';
wp_update_post( $post);
}
}
add_action( 'publish_post', 'post_published_limit', 10, 2 );
Hi my wordpress users are able to submit posts. But I want to limit the number of posts that they can submit. Can you help me?
I already tried / and / but they dont work.
Thanks!
Hi my wordpress users are able to submit posts. But I want to limit the number of posts that they can submit. Can you help me?
I already tried https://wordpress/plugins/bainternet-posts-creation-limits/ and https://cs.wordpress/plugins/wpsite-limit-posts/ but they dont work.
Thanks!
Share Improve this question asked Jun 8, 2015 at 18:49 Vale BoccaccioVale Boccaccio 1 2- 2 Please read How to Ask. – kaiser Commented Jun 8, 2015 at 19:01
- By default, subscribers can't create posts at all so, first off, how was that hacked into place? – s_ha_dum Commented Jun 8, 2015 at 19:18
1 Answer
Reset to default 5This solution uses the publish post hook. What's happening here is that when a post is published, it runs the custom post_published_limit
function we create below.
The $max_posts is set statically here, you can expand it to pull the value from elsewhere, but that's beyond the scope of the question being asked. However there is plenty of literature describing how to do that.
The function then gets the count of posts of the author currently trying to publish.
If the $count exceeds the $max_posts the function will save it as a draft instead of publishing it.
function post_published_limit( $ID, $post ) {
$max_posts = 5; // change this or set it as an option that you can retrieve.
$author = $post->post_author; // Post author ID.
$count = count_user_posts( $author, 'post'); // get author post count
if ( $count > $max_posts ) {
// count too high, let's set it to draft.
$post->post_status = 'draft';
wp_update_post( $post);
}
}
add_action( 'publish_post', 'post_published_limit', 10, 2 );
本文标签: Wordpress limit post that subscriber can create
版权声明:本文标题:Wordpress limit post that subscriber can create 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745512819a2153903.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论