admin管理员组文章数量:1391999
Can someone please give me a function to limit a specific User ID to 5 comments per post? I found several questions on how to put a limit of one comment per post on all users. However, I need to place the limit on only a single User ID. When I tried to modify the code to specify a single user ID it instead applied the limit to all users based on that one ID.
I found a plugin Limit Comments and Word Count that includes an option to place a limit on a specific User ID but for some reason that plugin doesn't work on my site. When I place the limit then no comments will go through for that User ID. It just gives a blank screen after hitting the comment button.
Anyway, if someone can give me a simple function to limit the number of comments per post from a specific User ID I would very much appreciate it. Thanks!
Can someone please give me a function to limit a specific User ID to 5 comments per post? I found several questions on how to put a limit of one comment per post on all users. However, I need to place the limit on only a single User ID. When I tried to modify the code to specify a single user ID it instead applied the limit to all users based on that one ID.
I found a plugin Limit Comments and Word Count that includes an option to place a limit on a specific User ID but for some reason that plugin doesn't work on my site. When I place the limit then no comments will go through for that User ID. It just gives a blank screen after hitting the comment button.
Anyway, if someone can give me a simple function to limit the number of comments per post from a specific User ID I would very much appreciate it. Thanks!
Share Improve this question asked Apr 6, 2020 at 6:31 rrhdevrrhdev 11 bronze badge1 Answer
Reset to default 0This is a simple approach to check whether a user has commented on the post, or not. If they have commented on the post, then disable comment form.
global $current_user;
$args = array('user_id' => $current_user->ID);
$usercomment = get_comments($args);
if(count($usercomment) >= 1){
echo 'Comment form disabled';
} else {
comment_form();
}
本文标签: How to limit specific user ID to 5 comments per post
版权声明:本文标题:How to limit specific user ID to 5 comments per post? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744593424a2614631.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论