[wp-trac] [WordPress Trac] #14805: PHP warning in edit_user() during email check for new user
WordPress Trac
wp-trac at lists.automattic.com
Tue Sep 7 16:09:53 UTC 2010
#14805: PHP warning in edit_user() during email check for new user
------------------------------+---------------------------------------------
Reporter: coffee2code | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Warnings/Notices | Version: 3.0.1
Severity: minor | Keywords: has-patch
------------------------------+---------------------------------------------
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.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14805>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list