New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor with User_Setting class #1029
Labels
P1
Medium priority
QA: Eng
Requires specialized QA by an engineer
Type: Enhancement
Improvement of an existing feature
Milestone
Comments
6 tasks
A couple of comments on the description:
|
aaemnnosttv
changed the title
Refactor with User_Option class
Refactor with User_Setting class
Jan 13, 2020
Those all sound good to me @felixarntz, I've updated the title and description accordingly. |
IB ✅ |
@felixarntz This one has a partial dependency on the changes to the |
6 tasks
Code here looks solid; settings continue to work for me, so I think this one is QA ✅ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
P1
Medium priority
QA: Eng
Requires specialized QA by an engineer
Type: Enhancement
Improvement of an existing feature
Feature Description
In #859/#995 we introduced a new
Setting
class to model a single option/setting. This has the benefit of centralizing logic and behavior that belongs to a specific setting in a single class which extends the base.Site Kit also has many user options which WordPress implements as user meta. User options are slightly different than options or plain meta as the key is optionally prefixed with the blog prefix from
wpdb
depending on the site. This is because theusers
andusermeta
tables are network-wide tables in multisite, and so prefixes are used to identify site-specific entries.Classes which could be refactored as sub-classes of
User_Setting
are:Verification
Verification_File
Verification_Meta
Tracking
Similar to what was done in the issue above, we should also add a
User_Options_Interface
that both existingUser_Options
andEncrypted_User_Options
should implement.An individual
User_Setting
would then only require aUser_Options_Interface
as a constructor dependency. Each sub-class would keep its key defined with its constant.The
User_Setting
class would have aregister
method which callsregister_meta
internally and registers the option dynamically using methods to populate the arguments array similar toSetting
. The registered meta key must be with/without blog prefix according to whether or not the plugin is in network mode. The user options interface could require aget_meta_key( $option )
method to get the underlying meta key as its implementations would have access toContext:is_network_mode()
which is needed to conditionally prefix the option name.User_Setting
should also have a method for getting the respective meta key for its option. It would also be useful if there was a static method which could be used to apply the blog prefix to an arbitrary string for use in other places in the codebase, such asuninstall.php
.Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
User_Options_Interface
interface exposing the following methods:get( $option )
set( $option )
delete( $option )
get_meta_key( $option )
get_user_id()
switch_user( $user_id )
User_Options
andEncrypted_User_Options
should implementUser_Options_Interface
.User_Setting
class that receives aUser_Options_Interface
as sole constructor parameter and exposes the following methods:register()
register_meta()
, usingUser_Options_Interface::get_meta_key( static::OPTION )
and protected methodsget_type()
andget_sanitize_callback()
(the value forsingle
should always be true)get_default()
--> let's see if this is possible based on the filters WordPress core provideshas()
get()
set( $value )
delete()
Verification
,Verification_File
,Verification_Meta
, andTracking
should extendUser_Setting
.Implementation Brief
Core\Storage\User_Options_Interface
with methods as defined in ACOptions_Interface
Core\Storage\User_Setting
class, which implements the above interfaceget()
as WP does not offer the same kind of filters as for optionsparse_defaults
method as we have used beforeVerification
,Verification_File
,Verification_Meta
, andTracking
as instances ofUser_Setting
Transients
as a constructor dependency ofVerification_Meta
Verification_Meta::get_all()
toSite_Verification
Changelog entry
register_meta()
.The text was updated successfully, but these errors were encountered: