Make WordPress Core

Opened 7 months ago

Last modified 7 months ago

#59918 new enhancement

Allow wp_get_global_settings to return null if the value is not found.

Reported by: joemcgill's profile joemcgill Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 5.9
Component: General Keywords: has-patch 2nd-opinion needs-unit-tests
Focuses: Cc:


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().

Change History (4)

This ticket was mentioned in PR #5678 on WordPress/wordpress-develop by @joemcgill.

7 months ago

  • Keywords has-patch added

This is a proof of concept. Would need unit tests added.

Trac ticket:

#2 @joemcgill
7 months ago

  • Keywords 2nd-opinion added

@jorgefilipecosta since you were involved in the original issue (#54336) where this function was added, I'm curious if you have any feedback or concerns about why the full settings object was chosen as the default in the first place?

#3 @joemcgill
7 months ago

Looking at this more, it would probably be a good idea to apply the same signature and behavior to wp_get_global_styles() as well, for consistency sake.

#4 @jorbin
7 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version set to 5.9

wp_get_global_settings was introduced in 5.9, so setting the version.

At first glance, I think this could make sense for 6.5, but I'll defer to after the 2nd opinion that was requested.

Note: See TracTickets for help on using tickets.