Make WordPress Core

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#13088 closed defect (bug) (fixed)

update_usermeta() and update_user_meta() behave differently

Reported by: mdawaffe Owned by:
Milestone: 3.0 Priority: normal
Severity: major Version: 3.0
Component: Users Keywords: meta
Focuses: Cc:



The old function, update_usermeta(), deletes the meta row if the passed value is empty.

The new function, update_user_meta(), goes through the meta API function update_metadata(), which does not delete the meta row if the passed value is empty.

update_usermeta() is marked as deprecated, but, because of this difference, is not an alias of update_user_meta(). Instead, the function is fully defined in deprecated.php.


update_user_option() used to go through update_usermeta() and now goes through update_user_meta(), so it's behavior has changed.


Multisite signups are wonky: source:/trunk/wp-includes/ms-functions.php@14190#L789


Switch update_user_option() back to update_usermeta().

Add delete_user_meta() logic to update_user_option().

Use delete_user_meta() where needed instead.

Attachments (2)

13088.diff (1.4 KB) - added by mdawaffe 6 years ago.
13088.b.diff (1.5 KB) - added by mdawaffe 6 years ago.

Download all attachments as: .zip

Change History (11)

6 years ago

#1 @mdawaffe
6 years ago


Switches wpmu_create_user() to use delete_user_option().

Adds delete_user_meta() logic to update_user_option(). This simple test isn't 100% backward compatible since update_usermeta() serializes the value before doing the empty() check. So empty arrays don't cause the row to be deleted in update_usermeta(), but they do cause the row to be deleted in the above patched version of update_user_option().

Untested :)

#2 @nacin
6 years ago

  • Milestone changed from Unassigned to 3.0

People may deliberately use array() to store empty data, knowing that other values will cause the meta row to be deleted. We've seen that in other situations.

#3 follow-up: @nacin
6 years ago

I kept forgetting to move over those checks in wpmu_new_user.

Maybe we just do:

if ( ! is_array( $newvalue ) && empty( $newvalue ) )
  // delete

#4 in reply to: ↑ 3 @mdawaffe
6 years ago

Replying to nacin:

Maybe we just do:

if ( ! is_array( $newvalue ) && empty( $newvalue ) )
  // delete

Maybe if ( is_scalar( $newvalue ) && empty( $newvalue ) ) ? Empty objects are dealt with the same way as empty arrays.

6 years ago

#5 @mdawaffe
6 years ago


More accurate (more complicated) backward compatibility.

#6 @ryan
6 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [14193]) Bring back delete on empty value for update_user_option() to preserve back compat. Switch to delete_user_option() in core. Props mdawaffe. fixes #13088

#7 @ryan
6 years ago

(In [14194]) Remove fat finger typo. see #13088

#8 @TobiasBg
6 years ago

// For backward compatibility.  See differences between update_user_meta() and deprecated update_user_meta().

I don't get this one :-) Is there a typo in one of the functions' names?

#9 @nacin
6 years ago

(In [14196]) Fix typo in inline docs. props TobiasBg. see #13088

Note: See TracTickets for help on using tickets.