[wp-trac] [WordPress Trac] #59918: Allow wp_get_global_settings to return null if the value is not found.

WordPress Trac noreply at wordpress.org
Thu Nov 16 19:53:13 UTC 2023


#59918: Allow wp_get_global_settings to return null if the value is not found.
-------------------------+-----------------------------
 Reporter:  joemcgill    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 Currently, `wp_get_global_settings()` defaults to returning the entire
 settings object whenever the value specified in the first parameter does
 not exist in the settings object. This means that any code making use of
 this function has to do an additional check to make sure that the expected
 setting value is returned.

 What would be preferable in many cases is that the function would return
 `null` or `false` if the setting is not found instead.

 For example, if I want to get the layout settings for a theme, I would
 call `wp_get_global_settings( array( 'layout' ) );` but may end up with
 the setting values or (in the case of a theme that doesn't support the
 layout setting) the entire settings object. This happens because
 `wp_get_global_settings()` makes use of the `_wp_array_get()` helper
 function with the entire settings object passed as the third default
 value.

 For backwards compatibility, it would be nice to add a third parameter to
 `wp_get_global_settings()` that would allow you to adjust this default
 behavior so that you could force the function to return `null` if the
 setting is not found by adjusting the default value passed to
 `_wp_array_get()`.

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


More information about the wp-trac mailing list