WordPress.org

Make WordPress Core

Changeset 49148


Ignore:
Timestamp:
10/14/2020 07:02:22 PM (14 months ago)
Author:
SergeyBiryukov
Message:

Users: Introduce email_exists filter, to complement username_exists.

Props garrett-eclipse, apermo, mukesh27, Mista-Flo, sebastian.pisula, mikelopez.
Fixes #51379. See #35509.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r49139 r49148  
    15871587 * @since 2.0.0
    15881588 *
    1589  * @param string $username Username.
    1590  * @return int|false The user's ID on success, and false on failure.
     1589 * @param string $username The username to check for existence.
     1590 * @return int|false The user ID on success, false on failure.
    15911591 */
    15921592function username_exists( $username ) {
     
    15991599
    16001600    /**
    1601      * Filters whether the given username exists or not.
     1601     * Filters whether the given username exists.
    16021602     *
    16031603     * @since 4.9.0
    16041604     *
    1605      * @param int|false $user_id  The user's ID on success, and false on failure.
     1605     * @param int|false $user_id  The user ID associated with the username,
     1606     *                            or false if the username does not exist.
    16061607     * @param string    $username Username to check.
    16071608     */
     
    16191620 *
    16201621 * @param string $email Email.
    1621  * @return int|false The user's ID on success, and false on failure.
     1622 * @return int|false The user ID on success, false on failure.
    16221623 */
    16231624function email_exists( $email ) {
    16241625    $user = get_user_by( 'email', $email );
    16251626    if ( $user ) {
    1626         return $user->ID;
    1627     }
    1628     return false;
     1627        $user_id = $user->ID;
     1628    } else {
     1629        $user_id = false;
     1630    }
     1631
     1632    /**
     1633     * Filters whether the given email exists.
     1634     *
     1635     * @since 5.6.0
     1636     *
     1637     * @param int|false $user_id The user ID associated with the email,
     1638     *                           or false if the email does not exist.
     1639     * @param string    $email   Email.
     1640     */
     1641    return apply_filters( 'email_exists', $user_id, $email );
    16291642}
    16301643
     
    16331646 *
    16341647 * @since 2.0.1
    1635  * @since 4.4.0 Empty sanitized usernames are now considered invalid
     1648 * @since 4.4.0 Empty sanitized usernames are now considered invalid.
    16361649 *
    16371650 * @param string $username Username.
    1638  * @return bool Whether username given is valid
     1651 * @return bool Whether username given is valid.
    16391652 */
    16401653function validate_username( $username ) {
     
    16431656
    16441657    /**
    1645      * Filters whether the provided username is valid or not.
     1658     * Filters whether the provided username is valid.
    16461659     *
    16471660     * @since 2.0.1
     
    18341847    /*
    18351848     * If there is no update, just check for `email_exists`. If there is an update,
    1836      * check if current email and new email are the same, or not, and check `email_exists`
     1849     * check if current email and new email are the same, and check `email_exists`
    18371850     * accordingly.
    18381851     */
Note: See TracChangeset for help on using the changeset viewer.