[wp-trac] [WordPress Trac] #43360: Third parameter for get_option function to return default value instead of empty string
WordPress Trac
noreply at wordpress.org
Mon Feb 19 22:45:55 UTC 2018
#43360: Third parameter for get_option function to return default value instead of
empty string
--------------------------------+------------------------------
Reporter: farhan.noor | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: 4.9.4
Severity: normal | Resolution:
Keywords: close 2nd-opinion | Focuses:
--------------------------------+------------------------------
Changes (by SergeyBiryukov):
* keywords: has-patch => close 2nd-opinion
* component: General => Options, Meta APIs
Comment:
Hi @farhan.noor, welcome to WordPress Trac!
> For example, there is an option field 'test' exist in the option table
but without any value(NULL or empty). Now `get_option('test', 'Hello
World')` function will return an empty string as it is; from the database
but developer may be expecting "Hello World" in return.
That seems like expected behavior to me. All scalar option values
ultimately stored in a `longtext` field in the database, which means that
they're retrieved as strings, and an empty string is a valid value. See
the discussion in #31820.
You could use the `option_{$option}` filter to perform a more strict
check, see an example in comment:3:ticket:31820.
[attachment:option.php] is not a proper patch, see the
[https://make.wordpress.org/core/handbook/tutorials/trac/submitting-a-patch/
handbook entry on submitting a patch].
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43360#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list