username_exists example

update_option( 'siteurl', $guessurl );

        // If not a public site, don't ping.         if ( ! $is_public ) {
            update_option( 'default_pingback_flag', 0 );
        }

        /* * Create default user. If the user already exists, the user tables are * being shared among sites. Just set the role in that case. */
        $user_id        = username_exists( $user_name );
        $user_password  = trim( $user_password );
        $email_password = false;
        $user_created   = false;

        if ( ! $user_id && empty( $user_password ) ) {
            $user_password = wp_generate_password( 12, false );
            $message       = __( '<strong><em>Note that password</em></strong> carefully! It is a <em>random</em> password that was generated just for you.' );
            $user_id       = wp_create_user( $user_name$user_password$user_email );
            update_user_meta( $user_id, 'default_password_nag', true );
            $email_password = true;
            $user_created   = true;
        }
$limited_email_domains = get_site_option( 'limited_email_domains' );
    if ( is_array( $limited_email_domains ) && ! empty( $limited_email_domains ) ) {
        $limited_email_domains = array_map( 'strtolower', $limited_email_domains );
        $emaildomain           = strtolower( substr( $user_email, 1 + strpos( $user_email, '@' ) ) );
        if ( ! in_array( $emaildomain$limited_email_domains, true ) ) {
            $errors->add( 'user_email', __( 'Sorry, that email address is not allowed!' ) );
        }
    }

    // Check if the username has been used already.     if ( username_exists( $user_name ) ) {
        $errors->add( 'user_name', __( 'Sorry, that username already exists!' ) );
    }

    // Check if the email address has been used already.     if ( email_exists( $user_email ) ) {
        $errors->add(
            'user_email',
            sprintf(
                /* translators: %s: Link to the login page. */
                __( '<strong>Error:</strong> This email address is already registered. <a href="%s">Log in</a> with this address or choose another one.' ),
                wp_login_url()
            )
$user_id  = email_exists( $email );
    if ( ! $user_id ) { // Create a new user with a random password.         /** * Fires immediately before a new user is created via the network site-new.php page. * * @since 4.5.0 * * @param string $email Email of the non-existent user. */
        do_action( 'pre_network_site_new_created_user', $email );

        $user_id = username_exists( $domain );
        if ( $user_id ) {
            wp_die( __( 'The domain or path entered conflicts with an existing username.' ) );
        }
        $password = wp_generate_password( 12, false );
        $user_id  = wpmu_create_user( $domain$password$email );
        if ( false === $user_id ) {
            wp_die( __( 'There was an error creating the user.' ) );
        }

        /** * Fires after a new user has been created via the network site-new.php page. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. */
return $blog_id;
    }

    /** * @param int $user_id * @return int|void */
    public function set_user( $user_id ) {
        if ( is_numeric( $user_id ) ) {
            $user_id = (int) $user_id;
        } else {
            $user_id = (int) username_exists( $user_id );
        }

        if ( ! $user_id || ! wp_set_current_user( $user_id ) ) {
            fwrite( STDERR, "Error: can not find user\n" );
            exit;
        }

        return $user_id;
    }

    /** * Sorts by strlen, longest string first. * * @param string $a * @param string $b * @return int */
$errors->add( 'pass', __( '<strong>Error:</strong> Passwords do not match. Please enter the same password in both password fields.' ), array( 'form-field' => 'pass1' ) );
    }

    if ( ! empty( $pass1 ) ) {
        $user->user_pass = $pass1;
    }

    if ( ! $update && isset( $_POST['user_login'] ) && ! validate_username( $_POST['user_login'] ) ) {
        $errors->add( 'user_login', __( '<strong>Error:</strong> This username is invalid because it uses illegal characters. Please enter a valid username.' ) );
    }

    if ( ! $update && username_exists( $user->user_login ) ) {
        $errors->add( 'user_login', __( '<strong>Error:</strong> This username is already registered. Please choose another one.' ) );
    }

    /** This filter is documented in wp-includes/user.php */
    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );

    if ( in_array( strtolower( $user->user_login )array_map( 'strtolower', $illegal_logins ), true ) ) {
        $errors->add( 'invalid_username', __( '<strong>Error:</strong> Sorry, that username is not allowed.' ) );
    }

    // Checking email address.
// Remove any non-printable chars from the login string to see if we have ended up with an empty username.     $user_login = trim( $pre_user_login );

    // user_login must be between 0 and 60 characters.     if ( empty( $user_login ) ) {
        return new WP_Error( 'empty_user_login', __( 'Cannot create a user with an empty login name.' ) );
    } elseif ( mb_strlen( $user_login ) > 60 ) {
        return new WP_Error( 'user_login_too_long', __( 'Username may not be longer than 60 characters.' ) );
    }

    if ( ! $update && username_exists( $user_login ) ) {
        return new WP_Error( 'existing_user_login', __( 'Sorry, that username already exists!' ) );
    }

    /** * Filters the list of disallowed usernames. * * @since 4.4.0 * * @param array $usernames Array of disallowed usernames. */
    $illegal_logins = (array) apply_filters( 'illegal_user_logins', array() );

    
Home | Imprint | This part of the site doesn't use cookies.