[wp-trac] [WordPress Trac] #26906: wp_user_update does not update custom user meta fields

WordPress Trac noreply at wordpress.org
Wed Jan 22 08:39:37 UTC 2014


#26906: wp_user_update does not update custom user meta fields
--------------------------+-----------------------------
 Reporter:  simongcc      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Users         |    Version:  3.8
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/26906>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list