// 获取评论用户的ip,参考wp-includes/comment.php
function ludou_getIP() {
$ip = $_SERVER['REMOTE_ADDR'];
$ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $ip );
return $ip;
}
function ludou_only_one_comment( $commentdata ) {
global $wpdb;
$currentUser = wp_get_current_user();
// 不限制管理员发表评论
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('本站每篇文章只允许评论一次。<a href="'.get_permalink($commentdata['comment_post_ID']).'">点此返回</a>');
}
return $commentdata;
}
add_action( 'preprocess_comment' , 'ludou_only_one_comment', 20);
function ludou_is_administrator($user_id) {
$user = get_userdata($user_id);
if(!empty($user->roles) && in_array('administrator', $user->roles))
return 1; // 是管理员
else
return 0; // 非管理员
}
function ludou_is_administrator() {
// wp_get_current_user函数仅限在主题的functions.php中使用
$currentUser = wp_get_current_user();
if(!empty($currentUser->roles) && in_array('administrator', $currentUser->roles))
return 1; // 是管理员
else
return 0; // 非管理员
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有