Make WordPress Core

Opened 23 months ago

#56326 new defect (bug)

get_metadata_raw doesn't unserialize when retrieving all meta_keys for a post_id

Reported by: nickchomey's profile nickchomey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: major Version: 6.0
Component: Options, Meta APIs Keywords:
Focuses: Cc:


(Preface: this is a bug report for WP Core, not BuddyPress - I'm just sharing the following details for context/reproducibility).

I'm working with BuddyPress and bbPress, which creates a meta_key "_bbp_group_ids" for the forum post when you associate that forum with a buddypress group. The meta_value for this key is an array, which gets serialized by update_post_meta().

When I retrieve all meta_keys for that forum post, it returns an array, but the _bbp_group_ids key has a value of something like "a:1:{i:0;i:58;}"

When I use xdebug to step through the code, the problem seems to start here in get_metadata_raw().

If the data is in the wp_cache, it then just retrieves and returns that on line 653

If it isn't in the cache (such as when I clear it manually in my code to test this), it goes through the motions, eventually ending up here in update_meta_cache(), where it retrieves the data from the database, but then doesn't run maybe_unserialize before setting the cache.

Then, we're back to where we were before - with line 656 of get_metadata_raw() just returning whatever is in the cache. It only runs maybe_unserialize if a single meta_key is being requested.

So, some sort of looping, maybe_unserialize mechanism has to be either added to update_meta_cache() or to get_metadata_raw(). Of course, people are probably aware of this foible and have thus probably created workarounds to deal with receiving serialized post_meta data... So, I leave it to you guys to figure out how to best address this.

Change History (0)

Note: See TracTickets for help on using tickets.