PHP Class Themosis\User\UserFactory

Inheritance: extends Themosis\Field\Wrapper, implements Themosis\User\IUser
Show file Open project: themosis/framework

Protected Properties

Property Type Description
$action Themosis\Hook\IHook
$capability string The capability in order to save custom data.
$fields array The user custom fields.
$hasNonce boolean Globally check if nonce inputs are inserted.
$rules array Validation rules for custom fields.
$sections array The user sections.
$validator Themosis\Validation\IValidate Validator instance.
$view Illuminate\View\View The user core/container view.

Public Methods

Method Description
__construct ( Illuminate\View\View $view, Themosis\Validation\IValidate $validator, Themosis\Hook\IHook $action ) Build a UserFactory instance.
addFields ( array $fields, string $capability = 'edit_users' ) : Themosis\User\IUser Register custom fields for users.
addSections ( array $sections ) : Themosis\User\IUser Register sections for user custom fields.
current ( ) : User Look at the current user and return an instance.
displayFields ( $user ) Render the user fields.
get ( integer $id ) : User Return a User instance using its ID.
hasSections ( ) : boolean Check if there are any sections defined.
make ( string $username, string $password, string $email ) : User Create a new WordPress user.
saveFields ( integer $id, array $oldData = [] ) Triggered by the 'user_register' && 'profile_update' hooks.
validate ( array $rules = [] ) : Themosis\User\IUser Register validation rules for user custom fields.

Protected Methods

Method Description
createUser ( integer $id ) : User Create a new User instance.
isUsingSections ( array $fields ) Check if the defined fields are using the sections defined or not.
parseCredentials ( array $credentials ) Check if given credentials to create a new WordPress user are valid.
parseTheFields ( array $fields ) : array Parse the list of registered fields. Remove the sections if defined.
register ( integer $id, array $fields ) Register custom user meta.
setDefaultValue ( WP_User | string $user, array $fields ) : array Set the default 'value' property for all fields.

Method Details

__construct() public method

Build a UserFactory instance.
public __construct ( Illuminate\View\View $view, Themosis\Validation\IValidate $validator, Themosis\Hook\IHook $action )
$view Illuminate\View\View The user core view.
$validator Themosis\Validation\IValidate Validator instance.
$action Themosis\Hook\IHook

addFields() public method

Register custom fields for users.
public addFields ( array $fields, string $capability = 'edit_users' ) : Themosis\User\IUser
$fields array The user custom fields. By sections or not.
$capability string The minimum capability required to save user custom fields data.
return Themosis\User\IUser

addSections() public method

Register sections for user custom fields.
public addSections ( array $sections ) : Themosis\User\IUser
$sections array A list of sections to register.
return Themosis\User\IUser

createUser() protected method

Create a new User instance.
protected createUser ( integer $id ) : User
$id integer
return User

current() public method

Look at the current user and return an instance.
public current ( ) : User
return User

displayFields() public method

Render the user fields.
public displayFields ( $user )

get() public method

Return a User instance using its ID.
public get ( integer $id ) : User
$id integer
return User

hasSections() public method

Check if there are any sections defined.
public hasSections ( ) : boolean
return boolean

isUsingSections() protected method

If there are sections and the fields are not set to use a section, trigger an error.
protected isUsingSections ( array $fields )
$fields array

make() public method

Create a new WordPress user.
public make ( string $username, string $password, string $email ) : User
$username string
$password string
$email string
return User | \WP_Error

parseCredentials() protected method

Check if given credentials to create a new WordPress user are valid.
protected parseCredentials ( array $credentials )
$credentials array

parseTheFields() protected method

Parse the list of registered fields. Remove the sections if defined.
protected parseTheFields ( array $fields ) : array
$fields array The fields.
return array A clean list of fields.

register() protected method

Register custom user meta.
protected register ( integer $id, array $fields )
$id integer The user_ID
$fields array The custom fields to register.

saveFields() public method

Used in order to save custom fields for the users.
public saveFields ( integer $id, array $oldData = [] )
$id integer The user ID.
$oldData array Null by default. If user update, contains an array of previous user data.

setDefaultValue() protected method

Set the default 'value' property for all fields.
protected setDefaultValue ( WP_User | string $user, array $fields ) : array
$user WP_User | string
$fields array
return array

validate() public method

Register validation rules for user custom fields.
public validate ( array $rules = [] ) : Themosis\User\IUser
$rules array
return Themosis\User\IUser

Property Details

$action protected property

protected IHook,Themosis\Hook $action
return Themosis\Hook\IHook

$capability protected property

The capability in order to save custom data.
protected string $capability
return string

$fields protected property

The user custom fields.
protected array $fields
return array

$hasNonce protected static property

Globally check if nonce inputs are inserted.
protected static bool $hasNonce
return boolean

$rules protected property

Validation rules for custom fields.
protected array $rules
return array

$sections protected property

The user sections.
protected array $sections
return array

$validator protected property

Validator instance.
protected IValidate,Themosis\Validation $validator
return Themosis\Validation\IValidate

$view protected property

The user core/container view.
protected View,Illuminate\View $view
return Illuminate\View\View