用户名出现空格有可能会被用作伪账号使用,这样对于网站的安全性是不利的。因此,建议为您开放注册的网站,最好在WordPress用户名中防止空格。
实现代码
add_filter('validate_username' , 'custom_validate_username', 10, 2);
function custom_validate_username($valid, $username ) {
if (preg_match("/\s/", $username)) {
// there are spaces
return $valid=false;
}
return $valid;
}
使用方法
在主题根目录下的functions.php
文件中<?php
下添加以上代码并保存。