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

WordPress Trac noreply at wordpress.org
Mon Jan 11 18:09:12 UTC 2021


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

 * status:  new => closed
 * resolution:   => invalid


Comment:

 Replying to [comment:3 ttodua]:
 > @apedog well, select 1 might be good also, i am not SQL master, you
 might adopt that. Just found in internet, that the method i posted is
 fastest among others, however, you can tell your thoughts.
 >
 >
 > @SergeyBiryukov  thanks, but the $default option is not even related to
 this ticket. the ticket is about "existence" of option (nevertheless it's
 value, let it be string, boolean, or whatever, even no-one knows what
 value specific option might have, string, bool, or whatever). So, your
 offered one is not related to the problem directly, and doesn't solve it.

 @SergeyBiryukov is correct and the default option actually does the work
 that you're willing to achieve with your custom function. The $default
 option is just like your return value for the existence i-e: you're
 returning 'boolean' while $default in
 [https://developer.wordpress.org/reference/functions/get_option/#parameters
 get_options] is allowing us to set 'string' something to return if option
 doesn't exists.

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


More information about the wp-trac mailing list