WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 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:

Description

Problem

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.

Impact

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

Example

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

Ideas

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 4 years ago.
13088.b.diff (1.5 KB) - added by mdawaffe 4 years ago.

Download all attachments as: .zip

Change History (11)

mdawaffe4 years ago

comment:1 mdawaffe4 years ago

13088.diff

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 :)

comment:2 nacin4 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.

comment:3 follow-up: nacin4 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

comment:4 in reply to: ↑ 3 mdawaffe4 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.

mdawaffe4 years ago

comment:5 mdawaffe4 years ago

13088.b.diff

More accurate (more complicated) backward compatibility.

comment:6 ryan4 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

comment:7 ryan4 years ago

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

comment:8 TobiasBg4 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?

comment:9 nacin4 years ago

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

Note: See TracTickets for help on using tickets.