[wp-trac] [WordPress Trac] #55942: Add a "value type" parameter to get_option() and get_metadata()

WordPress Trac noreply at wordpress.org
Fri Apr 28 07:59:36 UTC 2023


#55942: Add a "value type" parameter to get_option() and get_metadata()
-------------------------------------------------+-------------------------
 Reporter:  azaozz                               |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  6.3
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch has-unit-tests needs-      |     Focuses:
  testing                                        |  performance
-------------------------------------------------+-------------------------

Comment (by knutsp):

 I suggest adding 'bool' as alias of 'boolean' and 'int' as alias of
 'integer' for `$value_type` just before calling `wp_get_db_value_types()`,
 by something as simple as:
 {{{#!php
 $value_type = $value_type === 'bool' ? 'boolean' : $value_type;
 $value_type = $value_type === 'int'  ? 'integer' : $value_type;
 }}}

 because this gives compliance with the types used in PHP for type hints
 and checking of function parametres, return values and properties, and in
 docblocks. Other reasons:

 1. PHP developers tends to intuitively expect those shorter type aliases
 to work
 2. Not having to check the documentation ''again'' just because one may
 have forgot which "version" of types are expected by WP
 3. In line with `WP_Query`, `get_user_by()` and `get_term_by()` in respect
 to 'ID' versus 'id' or the exact column name
 4. In line with Robustness principle
 [https://en.wikipedia.org/wiki/Robustness_principle] "be conservative in
 what you send, be liberal in what you accept"

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


More information about the wp-trac mailing list