[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 21:47:18 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:  General      |    Version:  4.9.4
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 `get_option($option, $default = false)` function returns empty string if
 the required field exist but doesn't contain any value e.g. NULL or empty
 string.

 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.

 To avoid this situation third parameter may be introduced for
 `get_option()`  function which will decide to return NULL/empty-string or
 default value. Here is my proposed solution

 `get_option( $option, $default = false, $return_null = true)`

 Now calling `get_option('test', 'Hello World', false)` function for above
 problem will return default value which is '''Hello World'''.

 wp-includes\options.php file requires little changes to address the above
 enhancement.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/43360>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list