防止冒充昵称或邮箱留言_phpMyAdmin修改admin登录账号

10-03 | 夜光 | IT记录

如果wordpress博主设置评论不需要审核批准就能发表, 那么有可能被人冒名顶替管理员或其他注册用户进行留言. WordPress 是以email 来识别留言者的, 也就是说, 只要有人知道管理员的邮箱, 那就可以冒充他留言. 虽说管理员可以随后删除这些评论, 但是万一管理员长期不在线或者有人恶意留言那还是挺麻烦的,下面做法功能是防止冒充管理员或注册用户的昵称或邮箱(在wordpress后台”用户”里面的设置)

方法一:修改wordpress源文件
WordPress根目录, 打开wp-comments-post.php文件查找

if ( '' == $comment_content )

在它之前追加以下代码:

//防止冒充留言_Start
if (!$user->ID) {
	$result_set = $wpdb->get_results("SELECT display_name, user_email FROM $wpdb->users WHERE display_name = '" . $comment_author . "' OR user_email = '" . $comment_author_email . "'");
	if ($result_set) {
		if ($result_set[0]->display_name == $comment_author) {
			wp_die( __('Error: you are not allowed to use the nickname that you entered.') );
		} else {
			wp_die( __('Error: you are not allowed to use the email that you entered.') );
		}
	}
}
//防止冒充留言_End

方法二:在主题functions.php中添加如下代码

function commenter_check($incoming_comment){
    $isposing = 0;
    if($incoming_comment['comment_author'] == '要保护的昵称') { $isposing = 1; }
    if($incoming_comment['comment_author_email'] == '要保护的邮箱') { $isposing = 1; }
    if(!$isposing || is_user_logged_in()) { return $incoming_comment; }
    wp_die('错误:请勿冒充博主发表评论。');
}
add_filter('preprocess_comment','commenter_check');

附加:phpMyAdmin修改admin登录账号
修改WP的admin账号

本文标签: ,
本文链接: wordpress-posing-as-a-message-to-prevent/
版权所有: 玻璃泉, 转载请注明本文出处。

2个评论

  1. 还没碰到过这么无聊的人…

  2. @lfzyx
    建博的目的就是为了学各种程式用法的,重在知道如何实现,其他无所谓