username_exists() - WordPress 函数参考中文文档

返回介绍

username_exists()

发布于 2017-09-11 字数2305 浏览 1021 评论 0

username_exists( string $username )

Checks whether the given username exists.


描述


参数

$username

(string)
(Required)
Username.


返回值

(int|false) The user’s ID on success, and false on failure.


源代码

File: wp-includes/user.php

function username_exists( $username ) {
	if ( $user = get_user_by( 'login', $username ) ) {
		return $user->ID;
	}
	return false;
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

Uses

  • wp-includes/pluggable.php:
    get_user_by()

Used By

  • wp-admin/includes/upgrade.php:
    wp_install()
  • wp-admin/includes/user.php:
    edit_user()
  • wp-admin/includes/class-wp-importer.php:
    WP_Importer::set_user()
  • wp-includes/user.php:
    register_new_user()
  • wp-includes/user.php:
    wp_insert_user()
  • wp-includes/ms-functions.php:
    wpmu_activate_signup()
  • wp-includes/ms-functions.php:
    wpmu_validate_user_signup()
  • wp-includes/ms-functions.php:
    wpmu_validate_blog_signup()
  • Show 3 more used by
    Hide more used by


User Contributed Notes

  1. Skip to note content

    You must log in to vote on the helpfulness of this noteVote results for this note: -1You must log in to vote on the helpfulness of this note

    Contributed by Codex

    Example
    Use username_exists() in your scripts to decide whether the given username exists.

    
    $username = sanitize_text_field( $_POST['username'] );
    if ( username_exists( $username ) ) {
    	echo "Username In Use!";
    else {
    	echo "Username Not In Use!";
    }
    

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!