In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to restrict non-administrator users to comment once after the article in WordPress. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
Let's not say whether this requirement is useful or not. after all, WordPress is for people with all kinds of needs. This function is also relatively simple to implement, as long as every time a user's comment is entered into the database, look for the same user name or mailbox from all the comments in the current article, and if so, skip to the error page.
The implementation code can be put into the functions.php of the current topic (the judgment of IP has also been added here, which is more secure):
/ / to get the ip of the comment user, refer to wp-includes/comment.phpfunction ludou_getIP () {$ip = $_ SERVER ['REMOTE_ADDR']; $ip = preg_replace (' / [^ 0-9aMurray FARAUR. /','', $ip); return $ip;} function ludou_only_one_comment ($commentdata) {global $wpdb; $currentUser = wp_get_current_user () / / does not restrict if (empty ($currentUser- > roles) | |! in_array ('administrator', $currentUser- > roles)) {$bool = $wpdb- > get_var ("SELECT comment_ID FROM $wpdb- > comments WHERE comment_post_ID =". $commentdata [' comment_post_ID']. " AND (comment_author ='". $commentdata ['comment_author']."' OR comment_author_email ='". $commentdata ['comment_author_email']."' OR comment_author_IP ='".ludou _ getIP ()."') LIMIT 0,1; "); if ($bool) wp_die ('comments are only allowed once per article on this site. Click here to return');} return $commentdata;} add_action ('preprocess_comment',' ludou_only_one_comment', 20)
There is no limit on the number of comments made by the administrator, so let's take a look at the way to determine whether the user is an administrator:
Determine whether the user of the specified id is an administrator
This requirement is very simple to implement, a few lines of code are done, share:
Function ludou_is_administrator ($user_id) {$user = get_userdata ($user_id); if (! empty ($user- > roles) & & in_array ('administrator', $user- > roles)) return 1; / / is administrator else return 0; / / non-administrator}
Determine whether the currently logged-in user is an administrator
If you are judging whether the currently logged-in user is an administrator, you can use the following function:
The function ludou_is_administrator () {/ / wp_get_current_user function is limited to using $currentUser = wp_get_current_user () in the theme's functions.php; if (! empty ($currentUser- > roles) & & in_array ('administrator', $currentUser- > roles)) return 1; / / is administrator else return 0 / / non-administrator} this is the end of the article on "how to restrict non-administrator users to comment once after the article in WordPress". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 243
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.