[wp-trac] [WordPress Trac] #56326: get_metadata_raw doesn't unserialize when retrieving all meta_keys for a post_id

WordPress Trac noreply at wordpress.org
Tue Aug 2 22:43:42 UTC 2022


#56326: get_metadata_raw doesn't unserialize when retrieving all meta_keys for a
post_id
--------------------------------+-----------------------------
 Reporter:  nickchomey          |      Owner:  (none)
     Type:  defect (bug)        |     Status:  new
 Priority:  normal              |  Milestone:  Awaiting Review
Component:  Options, Meta APIs  |    Version:  6.0
 Severity:  major               |   Keywords:
  Focuses:                      |
--------------------------------+-----------------------------
 (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 [https://core.trac.wordpress.org/browser/tags/6.0/src/wp-
 includes/meta.php#L641 get_metadata_raw()].

 If the data is in the wp_cache, it then just retrieves and returns that on
 [https://core.trac.wordpress.org/browser/tags/6.0/src/wp-
 includes/meta.php#L653 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
 [https://core.trac.wordpress.org/browser/tags/6.0/src/wp-
 includes/meta.php#L1172 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
 [https://core.trac.wordpress.org/browser/tags/6.0/src/wp-
 includes/meta.php#L656 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/56326>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list