[wp-trac] [WordPress Trac] #38690: Introduce classes for settings
WordPress Trac
noreply at wordpress.org
Mon Nov 7 08:53:15 UTC 2016
#38690: Introduce classes for settings
--------------------------------+-------------------------------------
Reporter: flixos90 | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version:
Severity: normal | Keywords: needs-patch 2nd-opinion
Focuses: |
--------------------------------+-------------------------------------
Let's add classes surrounding settings to provide a better structure for
dealing with them. It will also allow us to get rid of some globals if we
are in a position to remove them (in terms of BC).
Here is what I have in mind:
* A `WP_Settings` class should be introduced that contains `get()`,
`update()`, `add()` and `delete()` methods. This will mostly be copy-paste
from the related functions. The functions themselves will become wrappers.
* A `WP_Settings_Registry` will be introduced. It should contain all
methods that handle registered settings (mostly introduced in 4.7). Again,
the functions would become wrappers. We could get rid of the
`$wp_registered_settings` global here and store these in a class property
instead.
* The `WP_Settings_Registry` instance will be contained by the
`WP_Settings` instance as a public property.
* A function `wp_settings()` will be introduced to access the
`WP_Settings` instance or generate it if it does not exist yet. I'm not
sure yet how to store the instance: The easy way is a global, but I was
wondering where we're at with plans like a `WP::get( 'settings' )` so that
we could do it differently. Anyway, let's assume a global first.
I think it would be a good pattern to build the class in a flexible way,
so that the registry instance and database instance are passed to the
class constructor. The following is how I would envision the
`wp_settings()` function:
{{{
function wp_settings() {
global $wp_settings;
if ( ! isset( $wp_settings ) ) {
$wp_settings = new WP_Settings( new WP_Settings_Registry(),
$GLOBALS['wpdb'] );
}
return $wp_settings;
}
}}}
I think once we agree on an approach, we should do something similar for
metadata. But let's have the discussion in here first and open the other
ticket afterwards.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/38690>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list