WordPress.org

Forums

[resolved] wp_insert_user in WP 3.0 (13 posts)

  1. Clifton Griffin
    Member
    Posted 4 years ago #

    I've noticed that wp_insert_user uses email_exists to block registration of users that have the same e-mail address as other users.

    This is causing one of my plugins (Simple LDAP Login) to fail on user creation in many instances. Particularly if the user I'm creating from LDAP doesn't have an e-mail address in LDAP.

    It seems that a blank e-mail address is returned as already existing by email_exists with a default installation.

    Since I don't want to just make up an e-mail address for the sake of uniqueness, I need another solution. Has anyone else seen issues with this new function version?

    Does anyone have any ideas for avoiding this error?

    Thanks,
    Clif

  2. Clifton Griffin
    Member
    Posted 4 years ago #

    No one have any input on this?

    I really need an answer.

    <shameless bump>

  3. Ryan Fitzer
    Member
    Posted 4 years ago #

    I'm needing a fix as well. This was not an issue in earlier versions of WP. I'm importing users from another CMS which allows for duplicate email addresses.

  4. Ryan Fitzer
    Member
    Posted 4 years ago #

    Ok, so further testing shows that I'm actually receiving the user id back from the call to wp_insert_user(), but the user is still not being created. No clue on this one.

    Example:

    `$userId = wp_insert_user( $userdata );
    if ( is_wp_error($temp) ) :
    echo $userId->get_error_message() . '
    ';
    else :
    echo $userId . '
    ';
    endif;
    '

  5. Ryan Fitzer
    Member
    Posted 4 years ago #

    Looks like my code block got borked. Another try:

    $userId = wp_insert_user( $userdata );
    if ( is_wp_error($temp) ) :
        echo $userId->get_error_message();
    else :
        echo $userId;
    endif;
  6. Ryan Fitzer
    Member
    Posted 4 years ago #

    I see the error in the if statement $temp should be $userId. Fixed it and still same result.

  7. Ryan Fitzer
    Member
    Posted 4 years ago #

    Looks like I've hijacked this thread so this will be my last post. Found the issue. Was just misunderstanding the function. If you predefine the id for the user, wp looks for that id in order to update it in the DB. I thought it would create the user with that specific id.

  8. Clifton Griffin
    Member
    Posted 4 years ago #

    No worries, Ryan.

    I still haven't found any good solution on this.

  9. asiersanchez
    Member
    Posted 4 years ago #

    Hi Clifgriffin, I have the same problem. I have two days importing users and not working well.

    At least I know that is by empty email......

    Have you fixed it? If I fix it, I tell you.

  10. asiersanchez
    Member
    Posted 4 years ago #

    I have solved the issue.
    I have modified the file wp-includes/registration.php
    I have commented the line 143 and 144.

    //if ( !$update && ! defined( 'WP_IMPORTING' ) && email_exists($user_email) )
         //return new WP_Error('existing_user_email', __('This email address is already registered.') );

    Now, the function wp_insert_user don't check if the email field is empty.

  11. Clifton Griffin
    Member
    Posted 4 years ago #

    I considered that solution, but I really want to make my plugin work with WP3+ without modifying or replacing wp_insert_user.

    Anyone else have input? I might just have to cave in.

  12. Clifton Griffin
    Member
    Posted 4 years ago #

    I fixed this without modifying wp_insert_user.

    I noticed that get_user_by_email is the function that returns "true" and throws everything off and that it is pluggable. So I did this:

    if ( !function_exists('get_user_by_email') ) :
    /**
     * Retrieve user info by email.
     *
     * @since 2.5
     *
     * @param string $email User's email address
     * @return bool|object False on failure, User DB row object
     */
    function get_user_by_email($email) {
    	if(strlen($email) == 0 || empty($email) || $email == "" || strpos($email, "@") == false)
    	{
    		return false;
    	}
    	else
    	{
    		return get_user_by('email', $email);
    	}
    }
    endif;

    Basically, this prevents the admin account from returning as a duplicate for any user being created without an e-mail address.

  13. dblackw
    Member
    Posted 4 years ago #

    now wp-includes/registration is gone in 3.1 anyone no how to access the registration functions

Topic Closed

This topic has been closed to new replies.

About this Topic