WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#14805 closed defect (bug) (duplicate)

PHP warning in edit_user() during email check for new user

Reported by: coffee2code Owned by:
Milestone: Priority: normal
Severity: minor Version: 3.0.1
Component: Warnings/Notices Keywords: has-patch
Focuses: Cc:

Description

In edit_user() (in wp-admin/includes/user.php), there is this line:

elseif ( ( $owner_id = email_exists($user->user_email) ) && $owner_id != $user->ID )

Essentially, it's saying "if this email exists and the owner of that email isn't the user being edited". The problem is that edit_user() is also used when creating a user. At the top of the function you'll find this:

	if ( $user_id != 0 ) {
		$update = true;
		$user->ID = (int) $user_id;
		$userdata = get_userdata( $user_id );
		$user->user_login = $wpdb->escape( $userdata->user_login );
	} else {
		$update = false;
		$user = '';
	}

$user->ID only gets set if a user is being updated and not when one is being created. A new user doesn't receive an ID until the very end of the function as a result of a call to wp_insert_user(). So that first bit of code can generate a PHP warning. In practice I believe the normal flow of WP has a separate, earlier email_exists() check elsewhere preventing this function from being called (and thus the warning not often tripped). However, I don't believe that should be relied upon in the event the workflow changes (or a plugin calls edit_user() directly). (Other monkeying by plugins can get there as well, which is how I think I tripped it.)

Besides, the fix is very minor and logically straightforward. Basically, check if email_exists and that it's either a new user or an existing user who doesn't already have that email.

Attachments (1)

14805.diff (909 bytes) - added by coffee2code 4 years ago.
Patch mentioned in ticket.

Download all attachments as: .zip

Change History (4)

coffee2code4 years ago

Patch mentioned in ticket.

comment:1 nacin4 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

This ticket sounds vaguely familiar.

#14286

:-)

comment:2 follow-up: coffee2code4 years ago

Oops! I guess I didn't remove that one off my to-be-reported list. (and apparently didn't do a thorough enough ticket search either!)

comment:3 in reply to: ↑ 2 nacin4 years ago

Replying to coffee2code:

(and apparently didn't do a thorough enough ticket search either!)

Well, I cheated. I was certain it was previously reported and that you were the reporter, because it had a few of us wishing that all bug reports came neatly packaged with such detail. :-)

Note: See TracTickets for help on using tickets.