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

WordPress Trac noreply at wordpress.org
Thu May 4 16:08:34 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 flixos90):

 Chiming in here again after a long while, I am concerned with the current
 direction. It seems we are discussing whether to use `get_option()` or
 `register_setting()` to define the type for an option - FWIW, both of
 those solutions have problems:
 * If we put a new parameter on `get_option()` for the type, that's a
 clunky API: A single option may be retrieved in several places. Having to
 remember in every single function call to put the right `$type` value will
 inevitably lead to errors based on developers making mistakes.
 * Using `register_setting()` is more appropriate from that concern's
 perspective, however it also has several other side effects. Certainly, we
 should not use the existing `type` field of that function since that is
 heavily used already, and if that suddenly would define what
 `get_option()` returns, that would be a backward compatibility break.

 In other words, neither of these approaches are suitable. I think we need
 a central function to control this (like `register_setting()`), but it
 also needs to be decoupled from any existing fields/information that
 already exists in core as it won't be the same.

 Thinking out loud, that could either be a separate new function (something
 like `set_option_database_type( $option, $type )`), or we use a new
 `database_type` argument on `register_setting()`. Or we do both, with the
 function being the source of truth, and `register_setting()`'s new
 argument could ''optionally'' be used, passing the value through to that
 function.

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


More information about the wp-trac mailing list