Opened 15 years ago
Closed 15 years ago
#19656 closed defect (bug) (worksforme)
wp_update_user() not compatible with cast-to-array WP_User objects
| Reported by: | boonebgorges | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Users | Version: | 3.3 |
| Severity: | normal | Keywords: | has-patch |
| Cc: | Focuses: |
Description
Pre-3.3, it was possible to do something like this:
$user = get_userdata( $user_id ); $user->user_pass = 'mypass'; wp_update_user( get_object_vars( $user ) ); // or (array)$user
It doesn't work anymore, because the data required by wp_update_user() is stored in $user->data rather than in $user. (The second line only works because of the new and nifty magic methods.)
It would be nice to add a little backward compatibility for this method of generating params for wp_update_user(). The attached patch is one idea - maybe something like that, plus a _doing_it_wrong(), would be sufficient.
Attachments (1)
Change History (4)
#2
@
15 years ago
I don't think it's worth it, when all you need to do is replace get_object_vars( $user ) with get_object_vars( $user->data ).
Yes, that's what I've done in BuddyPress http://buddypress.trac.wordpress.org/changeset/5588. I do think it's important to do something, though, in part because wp_update_user() still returns $user_id even when you pass it malformed data, which makes it hard to tell when something like a password update has failed.
We could make wp_update_user() accept WP_User instances, though.
Yeah, that amounts to about the same thing, and it'd be great. (Was a bit more work than 19656.patch, which is why I didn't do it :) ).
#3
@
15 years ago
- Milestone Awaiting Review
- Resolution → worksforme
- Status new → closed
Actually, passing all of the user fields isn't necessary. It's better to pass only the values that you want to update:
$to_update = array( 'ID' => $user_id, 'user_pass' => 'mypass' ); wp_update_user( $to_update );
This should work fine in both WP 3.2 and WP 3.3.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
I don't think it's worth it, when all you need to do is replace
get_object_vars( $user )withget_object_vars( $user->data ).We could make wp_update_user() accept WP_User instances, though.