[wp-trac] [WordPress Trac] #38176: Add 'default' to register_setting
WordPress Trac
noreply at wordpress.org
Tue Sep 27 19:17:45 UTC 2016
#38176: Add 'default' to register_setting
--------------------------------+-----------------------------
Reporter: rmccue | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Keywords: has-patch
Focuses: |
--------------------------------+-----------------------------
Imagine a future where you don't need to pass your default settings every
time you call `get_option`. Instead, you simply pass into
`register_setting` once.
Attached patch does this. Also moves the `register_setting` group of
functions from `wp-admin` to `wp-includes/option.php` to allow usage
everywhere, rather than just in the admin. This is probably a Good Idea
with the changes made in #37885, as `register_setting` is now also useful
for the REST API, not just the admin.
This ''does'' do some funky meta-programming that sucks a bit: if you call
`get_option( 'option_name' )` without a default parameter, it uses the
registered default. If you call `get_option( 'option_name', false )`, it
uses the value you passed in (`false`) '''even though''' this is the
default parameter value. This isn't great, but allows us to do this nicely
with backwards compatibility and is somewhat less surprising.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38176>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list