Unserialize `get_metadata()` results when 'key' is omitted.
Props mattkeys, nacin. Fixes #15030. git-svn-id: https://develop.svn.wordpress.org/trunk@30115 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
cdc35000f9
commit
9a84da90c3
|
@ -478,8 +478,13 @@ function get_metadata($meta_type, $object_id, $meta_key = '', $single = false) {
|
||||||
$meta_cache = $meta_cache[$object_id];
|
$meta_cache = $meta_cache[$object_id];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !$meta_key )
|
if ( ! $meta_key ) {
|
||||||
|
foreach ( $meta_cache as &$meta_values ) {
|
||||||
|
$meta_values = array_map( 'maybe_unserialize', $meta_values );
|
||||||
|
}
|
||||||
|
|
||||||
return $meta_cache;
|
return $meta_cache;
|
||||||
|
}
|
||||||
|
|
||||||
if ( isset($meta_cache[$meta_key]) ) {
|
if ( isset($meta_cache[$meta_key]) ) {
|
||||||
if ( $single )
|
if ( $single )
|
||||||
|
|
|
@ -263,4 +263,41 @@ class Tests_Meta extends WP_UnitTestCase {
|
||||||
$this->assertFalse( update_metadata_by_mid( 'user', array( 1 ), 'meta_new_value' ) );
|
$this->assertFalse( update_metadata_by_mid( 'user', array( 1 ), 'meta_new_value' ) );
|
||||||
$this->assertFalse( delete_metadata_by_mid( 'user', array( 1 ) ) );
|
$this->assertFalse( delete_metadata_by_mid( 'user', array( 1 ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 15030
|
||||||
|
*/
|
||||||
|
public function test_get_metadata_with_empty_key_array_value_should_be_unserialized() {
|
||||||
|
$data = array( 1, 2 );
|
||||||
|
add_metadata( 'user', $this->author->ID, 'foo', $data );
|
||||||
|
$found = get_metadata( 'user', $this->author->ID );
|
||||||
|
|
||||||
|
$this->assertSame( array( $data ), $found['foo'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 15030
|
||||||
|
*/
|
||||||
|
public function test_get_metadata_with_empty_key_object_value_should_be_unserialized() {
|
||||||
|
$data = new stdClass;
|
||||||
|
$data->foo = 'bar';
|
||||||
|
add_metadata( 'user', $this->author->ID, 'foo', $data );
|
||||||
|
$found = get_metadata( 'user', $this->author->ID );
|
||||||
|
|
||||||
|
$this->assertEquals( array( $data ), $found['foo'] );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ticket 15030
|
||||||
|
*/
|
||||||
|
public function test_get_metadata_with_empty_key_nested_array_value_should_be_unserialized() {
|
||||||
|
$data = array(
|
||||||
|
array( 1, 2 ),
|
||||||
|
array( 3, 4 ),
|
||||||
|
);
|
||||||
|
add_metadata( 'user', $this->author->ID, 'foo', $data );
|
||||||
|
$found = get_metadata( 'user', $this->author->ID );
|
||||||
|
|
||||||
|
$this->assertSame( array( $data ), $found['foo'] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue