Make WordPress Core

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#13267 closed defect (bug) (invalid)

get_metadata() is breaking assoc arrays

Reported by: apeatling's profile apeatling Owned by: ryan's profile ryan
Milestone: Priority: high
Severity: blocker Version: 3.0
Component: Database Keywords:
Focuses: Cc:

Description

I'm doing some work with the new update/delete/get_user_meta() functions and noticed that associative arrays are breaking. The returned array from get_user_meta() is always returning on a level below where it should be. The problem is compounded if you try and fetch existing values and then update.

From what I can see, the issue stems from the get_metadata() function.

Here's some code that highlights the problem, activate it and refresh the page a few times:

<?php
/*
Plugin Name: Usermeta Test
*/

function usermeta_test() {
	global $current_user;

	if ( empty( $current_user->ID ) )
		return false;

	$old_from_db = get_user_meta( $current_user->ID, 'um_test_old' );
	$new_from_db = get_usermeta( $current_user->ID, 'um_test_new' );

	$old_from_db['foo'][] = true;
	$new_from_db['foo'][] = true;

	update_user_meta( $current_user->ID, 'um_test_old', $old_from_db );
	update_usermeta( $current_user->ID, 'um_test_new', $new_from_db );

	var_dump( $old_from_db, $new_from_db );
}
add_action( 'init', 'usermeta_test' );
?>

I don't have a patch yet, I wanted to get the ticket up first.

Change History (3)

#1 @apeatling
15 years ago

New and old vars are backwards in the above example, but it still works fine.

#2 @apeatling
15 years ago

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

Missed the third arg in get_user_meta(), nothing to see here. :)

#3 @johnbillion
15 years ago

  • Milestone 3.0 deleted
Note: See TracTickets for help on using tickets.