确定给定的用户名是否存在。
原型
username_exists( string $username )
描述
有关此功能和类似主题功能的更多信息,请查看Theme Developer Handbook中的Conditional Tags文章。
参数
$username
(string)
(Required)
用户名。
返回值
(int|false)
成功时用户的ID,失败时为false。
源文件
路径:wp-includes/user.php
<?php
...
function username_exists( $username ) {
if ( $user = get_user_by( 'login', $username ) ) {
$user_id = $user->ID;
} else {
$user_id = false;
}
/**
* Filters whether the given username exists or not.
*
* @since 4.9.0
*
* @param int|false $user_id The user's ID on success, and false on failure.
* @param string $username Username to check.
*/
return apply_filters( 'username_exists', $user_id, $username );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/username_exists/