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

WordPress Trac noreply at wordpress.org
Fri Jul 10 17:19:22 UTC 2020


#43941: Add default value to register meta
-------------------------------------------------+-------------------------
 Reporter:  spacedmonkey                         |       Owner:
                                                 |  TimothyBlynJacobs
     Type:  enhancement                          |      Status:  reopened
 Priority:  normal                               |   Milestone:  5.5
Component:  Options, Meta APIs                   |     Version:  4.6
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-dev-  |     Focuses:  rest-api
  note                                           |
-------------------------------------------------+-------------------------

Comment (by johnjamesjacoby):

 Super excited to see this committed!! ❤️

 > These params are optional so have to be at the end.

 In my own code (and in bbPress 2.x) nearly all function parameters are
 defined as optional but with correctly cast default values. This approach
 allows for maintaining consistent function signatures. It will not spill
 PHP notices when "required" parameter values are falsy. It forces every
 function (and the rest of the surrounding application) to internally
 consider and pre-flight check all of the parameter values before
 proceeding.

 Having the signature more closely match `get_metadata()` and
 `get_metadata_raw()` seems preferable.

 It is not immediately obvious in the code when or why
 `get_metadata_default()` would accept an empty `$object_id`. It seems
 obscure enough that a signature change like I'm proposing below might be
 less likely to hang people up (with accompanying docs to explain why it's
 different):

 {{{
 function get_metadata_default( $meta_type, $object_id = 0, $meta_key = '',
 $single = false ) {
 }}}

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


More information about the wp-trac mailing list