Make WordPress Core

Changeset 30115


Ignore:
Timestamp:
10/30/2014 10:24:22 AM (12 years ago)
Author:
boonebgorges
Message:

Unserialize get_metadata() results when 'key' is omitted.

Props mattkeys, nacin.
Fixes #15030.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/meta.php

    r30105 r30115  
    479479        }
    480480
    481         if ( !$meta_key )
     481        if ( ! $meta_key ) {
     482                foreach ( $meta_cache as &$meta_values ) {
     483                        $meta_values = array_map( 'maybe_unserialize', $meta_values );
     484                }
     485
    482486                return $meta_cache;
     487        }
    483488
    484489        if ( isset($meta_cache[$meta_key]) ) {
  • trunk/tests/phpunit/tests/meta.php

    r29855 r30115  
    264264                $this->assertFalse( delete_metadata_by_mid( 'user', array( 1 ) ) );
    265265        }
     266
     267        /**
     268         * @ticket 15030
     269         */
     270        public function test_get_metadata_with_empty_key_array_value_should_be_unserialized() {
     271                $data = array( 1, 2 );
     272                add_metadata( 'user', $this->author->ID, 'foo', $data );
     273                $found = get_metadata( 'user', $this->author->ID );
     274
     275                $this->assertSame( array( $data ), $found['foo'] );
     276        }
     277
     278        /**
     279         * @ticket 15030
     280         */
     281        public function test_get_metadata_with_empty_key_object_value_should_be_unserialized() {
     282                $data = new stdClass;
     283                $data->foo = 'bar';
     284                add_metadata( 'user', $this->author->ID, 'foo', $data );
     285                $found = get_metadata( 'user', $this->author->ID );
     286
     287                $this->assertEquals( array( $data ), $found['foo'] );
     288        }
     289
     290        /**
     291         * @ticket 15030
     292         */
     293        public function test_get_metadata_with_empty_key_nested_array_value_should_be_unserialized() {
     294                $data = array(
     295                        array( 1, 2 ),
     296                        array( 3, 4 ),
     297                );
     298                add_metadata( 'user', $this->author->ID, 'foo', $data );
     299                $found = get_metadata( 'user', $this->author->ID );
     300
     301                $this->assertSame( array( $data ), $found['foo'] );
     302        }
    266303}
Note: See TracChangeset for help on using the changeset viewer.