• Resolved Clifton Griffin

    (@clifgriffin)


    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

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter Clifton Griffin

    (@clifgriffin)

    No one have any input on this?

    I really need an answer.

    <shameless bump>

    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.

    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;

    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;

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

    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.

    Thread Starter Clifton Griffin

    (@clifgriffin)

    No worries, Ryan.

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

    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.

    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.

    Thread Starter Clifton Griffin

    (@clifgriffin)

    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.

    Thread Starter Clifton Griffin

    (@clifgriffin)

    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.

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

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘wp_insert_user in WP 3.0’ is closed to new replies.