[wp-trac] [WordPress Trac] #51699: The only correct method to check for existence of option

WordPress Trac noreply at wordpress.org
Wed Jul 28 10:04:16 UTC 2021


#51699: The only correct method to check for existence of option
--------------------------------+------------------------------
 Reporter:  ttodua              |       Owner:  (none)
     Type:  enhancement         |      Status:  reopened
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:
--------------------------------+------------------------------

Comment (by rupw):

 In addition to pre_option_{$option} you should use the alloptions and
 notoptions caches to save database queries

 - if the key exists in alloptions return true
 - if the key exists in notoptions return false
 - only then make the database query
 - if the value exists save it in alloptions (after running the usual
 filters); if not add the key to notoptions

 so that if we all option_exists() and get_option() it will make at most
 one database query, and ditto if you call option_exists() twice for the
 same key it will make at most one database query. (However this is
 starting to duplicate a lot of the get_option logic, so maybe this should
 use that or be built into that somehow instead.)

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


More information about the wp-trac mailing list