Opened 11 years ago
Closed 9 years ago
#26906 closed defect (bug) (wontfix)
wp_user_update does not update custom user meta fields
Reported by: | simongcc | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.8 |
Component: | Users | Keywords: | needs-patch needs-unit-tests |
Focuses: | Cc: |
Description
Version: 3.8
Problem explanation:
according to user.php => wp_update_user()
in line Add additional custom fields, the loop did do the job and read the custom fields into the array and store in $userdata, however,
when wp_insert_user($userdata) read the data and insert the data into DB, the custom fields are gone and not being saved
Cause of the problem:
in wp_insert_user()
because final data are using
$data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
and this method exclude all the custom fields other than default variables.
Suggested solution:
add a foreach to read all the key name from $userdata at the beginning of wp_user_data()
when using compact using foreach and $$var to create the array for output
Workaround or other solution:
I think most people are doing this using update_user_meta() to accomplish the job but if there is many fields, this might not be very effective.
Change History (2)
#2
@
9 years ago
- Keywords needs-patch needs-unit-tests added
- Milestone Awaiting Review deleted
- Resolution set to wontfix
- Status changed from new to closed
Closing as wontfix. Complete lack of interest on the ticket over the last 2 years, and by now, most developers affected would have worked around this in their plugins. Feel free to reopen when more interest re-emerges (particularly if there's a patch)
In suggested solution:
add a foreach to read all the key name from $userdata at the beginning of
wp_user_data()should be wp_insert_user()