Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#13088 closed defect (bug) (fixed)

update_usermeta() and update_user_meta() behave differently

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

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

Download all attachments as: .zip

Change History (11)

@mdawaffe
16 years ago

#1 @mdawaffe
16 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 :)

#2 @nacin
16 years ago

  • Milestone Unassigned → 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
16 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
16 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.

@mdawaffe
16 years ago

#5 @mdawaffe
16 years ago

13088.b.diff

More accurate (more complicated) backward compatibility.

#6 @ryan
16 years ago

  • Resolution → fixed
  • Status new → 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
16 years ago

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

#8 @TobiasBg
16 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
16 years ago

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

Note: See TracTickets for help on using tickets.