[wp-trac] [WordPress Trac] #51699: The only correct method to check for existence of option
WordPress Trac
noreply at wordpress.org
Mon Jan 11 19:18:25 UTC 2021
#51699: The only correct method to check for existence of option
--------------------------------+------------------------------
Reporter: ttodua | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Resolution:
Keywords: | Focuses:
--------------------------------+------------------------------
Changes (by apedog):
* status: closed => reopened
* resolution: invalid =>
Comment:
I don't think this is an invalid ticket. I'd say an {{{option_exists()}}}
function would be a valuable addition to the API. I know ''I'' searched
for such a function quite often when I started with WordPress.
@SergeyBiryukov's solution does work. But it's a workaround. It makes
creative use of {{{get_option}}}'s optional parameter and results in non-
human-readable code (it is not immidiately obvious what the code does).
And it relies on the test string not being used as the value of the option
(either intentionally or accidentally). ie. it's not foolproof 100% of the
time.
This is ok for most purposes, but it does not, ''strictly speaking'', test
the database if the option exists.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51699#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list