[wp-trac] [WordPress Trac] #43941: Add default value to register meta

WordPress Trac noreply at wordpress.org
Mon Sep 23 18:59:32 UTC 2019


#43941: Add default value to register meta
---------------------------------------------+---------------------------
 Reporter:  spacedmonkey                     |       Owner:  spacedmonkey
     Type:  enhancement                      |      Status:  assigned
 Priority:  normal                           |   Milestone:  5.3
Component:  Options, Meta APIs               |     Version:  4.6
 Severity:  normal                           |  Resolution:
 Keywords:  has-patch has-unit-tests commit  |     Focuses:  rest-api
---------------------------------------------+---------------------------
Changes (by TimothyBlynJacobs):

 * keywords:  has-patch has-unit-tests early => has-patch has-unit-tests
     commit
 * milestone:  5.4 => 5.3


Comment:

 We found an infinite loop that occurred during `wp_install()` when
 bootstrapping PHPUnit. The issues comes down to creating a `WP_User`
 instance. To do that, the `get_caps_data` function is called which tries
 to load the `wp_capabilities` meta key.

 When a new user is constructed, this meta key won't exist, so the
 `get_metadata_default` function is called. This calls the
 `filter_default_metadata`. That function uses `get_object_subtype` to
 determine the correct registered meta key entry to use.
 `get_object_subtype` then tries to create a `WP_User` instance. And now we
 loop.

 I think this problem would occur anywhere where `get_metadata` is called
 during the bootstrapping of a WP model of some kind. I think this is
 constrained to `WP_User`, but I haven't been able to check for sure yet.
 It might be possible to workaround this by unhooking the default meta
 filter during the `get_user_meta` call.

 ----

 Additionally, it looks like there might be an issue with the default meta
 value changing to return `null` instead of an empty string or array if no
 default value is registered is set when registering a meta key, but at
 least one is specified for the meta type.

 We also need to decide how meta defaults should work with custom filters.
 Right now, in `update_metadata` we unhook the default filter to get the
 raw current value, but that won't work if someone provides a default by
 using a filter.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/43941#comment:32>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list