[wp-trac] [WordPress Trac] #37178: Add $cache_only parameter to get_option

WordPress Trac noreply at wordpress.org
Sun Nov 28 17:14:38 UTC 2021


#37178: Add $cache_only parameter to get_option
-------------------------------------------------+-------------------------
 Reporter:  joostdevalk                          |       Owner:  (none)
     Type:  enhancement                          |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Options, Meta APIs                   |     Version:
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch dev-feedback needs-unit-   |     Focuses:
  tests                                          |  performance
-------------------------------------------------+-------------------------
Changes (by desrosj):

 * milestone:   => Awaiting Review


Comment:

 Readding a milestone. Seems like it was lost at some point.

 Also, copying over some of my findings from exploring this in
 ticket:54459#comment:2:


 > I took a look and reacquainted with how `get_option()` works because I
 feel like this has come up somewhere for me in the past.
 >
 > It seems there are a few ways to accomplish this already. Because this
 change would be an opt-in change, I'm wondering if these are better
 options because they don't require additional arguments to be added.
 >
 > - Using the `pre_cache_alloptions` filter, someone could check `! isset(
 $alloptions['myoption'] )` and add the default value for that option.
 `wp_load_alloptions()` fetches all options with `autoload = 'yes'` (unless
 there are no options set to `autoload`).
 > - At some point during the bootstrap process after
 `wp_load_alloptions()` has been called (or after calling it early on), a
 dev could run code that checks the keys present in the `alloptions` cache,
 and add their own known `autoload` options with default values before
 updating that cache.
 > - The same as previous, a dev could add their keys to the `notoptions`
 cache, and the function would fall back to returning the passed default
 value without a query.
 >
 > Personally, I like option 3 because it allows a different default to be
 passed in different locations where `get_option()` is called if desired. A
 filter could be probably be added to allow someone to adjust the
 `notoptions` cache before it's updated to make this easier.
 >
 > Another way to protect these extra queries is to have a list of
 registered options. But this is really the same thing as the `alloption`
 list, except it would include the ones that don't currently exist.

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


More information about the wp-trac mailing list