您只需在保存评论之前检查输入的名称或电子邮件是否与任何管理员帐户匹配。
function restrict_admin_names() {
if ( !is_user_logged_in() ) {
$name = $_POST[\'author\']; // Get Submitted Name
$email = $_POST[\'email\']; // Get Submitted Email
$admins = get_super_admins(); // Get an array of admin login
$adminemail[] = \'\'; // Create an empty array of admin emails
$admindisplayname[] = \'\'; // Create an empty array of admin display names
// Create an array of admin emails and display names
foreach ($admins as $admin) {
$userdata = get_user_by( \'login\', $admin );
$adminemail[] = $userdata->user_email;
$admindisplayname[] = $userdata->display_name;
}
if ( isset($name) && in_array( $name, $admins) && in_array( $name, $admindisplayname) ) {
wp_die( __(\'Sorry, you can not use that name\', \'mytextdomain\' ) );
}
if ( isset($email) && in_array( $email, $adminemail) ) {
wp_die( __(\'Sorry, you can not use that email\', \'mytextdomain\' ) );
}
}
}
add_action(\'pre_comment_on_post\', \'restrict_admin_names\');
虽然它只是检查管理员,但您可以修改代码来检查任何用户角色或所有注册用户。
不用说,这段代码进入了你的主题functions.php
文件