Form_User_Account
extends Form
in package
User account edit profile form functionality.
Tags
Table of Contents
Constants
- EXTRA_VALIDATION_HOOK = 'pnet_validation'
- The extra_validation hook base name.
- FORM_ACTION = 'account_edit'
- The admin_post hook action name.
- FORM_CONTAINER = 'form-user-account.php'
- Form container partial.
- FORM_NAME = 'account_maintenance'
- The name attribute of the form.
- NEXT_PAGE = ''
- The page to redirect to when closing form response banner.
- NONCE_ACTION = 'update_account'
- The form nonce action.
- NONCE_ACTION_EMAIL = 'change_email'
- The email change nonce action.
- NONCE_ACTION_PASSWORD = 'change_password'
- The password change nonce action.
- NONCE_EMAIL = 'token-em'
- The nonce name for email cancellation.
- NONCE_NAME = 'token'
- The nonce name.
- NONCE_PASSWORD = 'token-pwd'
- The nonce name for password cancellation.
- NOTIFICATION_CONTAINER = 'notification.php'
- Message container partial.
- RESPONSE_PAGE = ''
- The page to redirect to for form submission response.
Properties
- $form_container : string
- The fully qualified path to the form container partial.
- $form_header : string
- The text before the form.
- $http_handler : HTTP_Handler
- The instance of the HTTP_Handler class.
- $instances : array<string|int, object>
- The array of instances of this class and sub-classes.
- $messages : Messages
- The instance of the Messages class.
- $next_url : string
- The fully qualified path to the next page after closing the success banner.
- $notification_container : string
- The fully qualified path to the message container partial.
- $notifications : array<string|int, string>
- The marked up notifications to display at top of form.
- $pending_email_change : bool
- The flag to indicate q pending email change.
- $pending_password_change : bool
- The flag to indicate a pending password change.
- $progress_container : string
- The progress indicator container markup.
- $recaptcha_site_key : string
- Google reCAPTCHA V3 site key.
- $response_url : string
- The fully qualified path to the submission response target.
- $success_message_code : string
- The success message code.
- $user : User
- The instance of the User class.
- $user_account : User_Account
- The instance of the User_Account class.
- $user_data : array<string|int, mixed>
- The user profile basic data.
- $user_home_url : string
- The fully qualified path to the user home page.
- $user_id : int
- The current user id.
- $validation_hook : string
- The name of the extra validation hook.
Methods
- get_form_action() : string
- Return the form action.
- get_instance() : object
- Creates and/or returns the instance of this class.
- get_validation_hook() : string
- Return the extra validation hook name.
- handle_submission() : void
- Handle the form submission.
- render() : void
- Render the form.
- __construct() : void
- Initialise the class.
- add_notifications() : void
- Add conditional messages to form.
- cancel_email_change() : bool
- Cancel a pending email change.
- cancel_password_change() : bool
- Cancel a pending password change.
- do_intercepts() : void
- Take special actions before initialising the form.
- do_submission() : WP_Error
- Execute the submission request.
- enqueue_assets() : void
- Enqueue the resources.
- get_inline_script() : string
- Get the inline JavaScript.
- render_success_notification() : void
- Render the success notification.
- set_form_header() : void
- Set the form header text.
- set_form_values() : void
- Initialise the values used in the form.
- validate_email() : WP_Error
- Validate the email address.
- validate_submission() : WP_Error
- Validate the submitted form contents.
Constants
EXTRA_VALIDATION_HOOK
The extra_validation hook base name.
protected
string
EXTRA_VALIDATION_HOOK
= 'pnet_validation'
Tags
FORM_ACTION
The admin_post hook action name.
protected
string
FORM_ACTION
= 'account_edit'
Tags
FORM_CONTAINER
Form container partial.
protected
string
FORM_CONTAINER
= 'form-user-account.php'
Tags
FORM_NAME
The name attribute of the form.
protected
string
FORM_NAME
= 'account_maintenance'
Tags
NEXT_PAGE
The page to redirect to when closing form response banner.
protected
string
NEXT_PAGE
= ''
- Override this constant in the child class.
- Page name must start with a slash to be appended to home_url().
Tags
NONCE_ACTION
The form nonce action.
protected
string
NONCE_ACTION
= 'update_account'
Tags
NONCE_ACTION_EMAIL
The email change nonce action.
protected
string
NONCE_ACTION_EMAIL
= 'change_email'
Tags
NONCE_ACTION_PASSWORD
The password change nonce action.
protected
string
NONCE_ACTION_PASSWORD
= 'change_password'
Tags
NONCE_EMAIL
The nonce name for email cancellation.
protected
string
NONCE_EMAIL
= 'token-em'
.
Tags
NONCE_NAME
The nonce name.
protected
string
NONCE_NAME
= 'token'
Tags
NONCE_PASSWORD
The nonce name for password cancellation.
protected
string
NONCE_PASSWORD
= 'token-pwd'
.
Tags
NOTIFICATION_CONTAINER
Message container partial.
protected
string
NOTIFICATION_CONTAINER
= 'notification.php'
Tags
RESPONSE_PAGE
The page to redirect to for form submission response.
protected
string
RESPONSE_PAGE
= ''
- Override this constant in the child class.
Tags
Properties
$form_container
The fully qualified path to the form container partial.
protected
string
$form_container
= ''
Tags
$form_header
The text before the form.
protected
string
$form_header
= ''
- This is the text to display between the page content and the form.
- Describes the required field markup.
- Set in set_form_header() to allow translation.
Tags
$http_handler
The instance of the HTTP_Handler class.
protected
HTTP_Handler
$http_handler
Tags
$instances
The array of instances of this class and sub-classes.
protected
static array<string|int, object>
$instances
= array()
Tags
$messages
The instance of the Messages class.
protected
Messages
$messages
Tags
$next_url
The fully qualified path to the next page after closing the success banner.
protected
string
$next_url
= ''
- Blank means no redirection.
Tags
$notification_container
The fully qualified path to the message container partial.
protected
string
$notification_container
= ''
Tags
$notifications
The marked up notifications to display at top of form.
protected
array<string|int, string>
$notifications
= array()
Tags
$pending_email_change
The flag to indicate q pending email change.
protected
bool
$pending_email_change
= false
Tags
$pending_password_change
The flag to indicate a pending password change.
protected
bool
$pending_password_change
= false
Tags
$progress_container
The progress indicator container markup.
protected
string
$progress_container
= ''
Tags
$recaptcha_site_key
Google reCAPTCHA V3 site key.
protected
string
$recaptcha_site_key
= ''
Tags
$response_url
The fully qualified path to the submission response target.
protected
string
$response_url
= ''
Tags
$success_message_code
The success message code.
protected
string
$success_message_code
= ''
- This is the key to the success message from the message handler.
- It is of the form "success_{FORM_ACTION}"
Tags
$user
The instance of the User class.
protected
User
$user
Tags
$user_account
The instance of the User_Account class.
protected
User_Account
$user_account
Tags
$user_data
The user profile basic data.
protected
array<string|int, mixed>
$user_data
= array()
- This is of the form that Wp userdata provides.
- It includes standard user metadata.
Tags
$user_home_url
The fully qualified path to the user home page.
protected
string
$user_home_url
= ''
Tags
$user_id
The current user id.
protected
int
$user_id
= 0
Tags
$validation_hook
The name of the extra validation hook.
protected
string
$validation_hook
= ''
- This adds the FORM_ACTION to the EXTRA_VALIDATION_HOOK constant.
Tags
Methods
get_form_action()
Return the form action.
public
get_form_action() : string
- This is the {action} part of the admin_post hook.
Tags
Return values
string —The form action.
get_instance()
Creates and/or returns the instance of this class.
public
static get_instance() : object
Tags
Return values
object —The instance of this class.
get_validation_hook()
Return the extra validation hook name.
public
get_validation_hook() : string
Tags
Return values
string —The hook name.
handle_submission()
Handle the form submission.
public
handle_submission() : void
- Validate nonce.
- Call validate_submission(). This is unique to each child class.
- Apply filter for extra validation if required (eg reCAPTCHA).
- Call do_submission(). This is unique to each child class.
- Redirect back to form page.
Tags
render()
Render the form.
public
render() : void
- Intercept any required actions before rendering form.
- Add any conditional notifications.
- Display form or notification if form submitted successfully.
- Enqueue form assets.
Tags
__construct()
Initialise the class.
protected
__construct() : void
Tags
add_notifications()
Add conditional messages to form.
protected
add_notifications([array<string|int, string> $get_vars = array() ]) : void
Parameters
- $get_vars : array<string|int, string> = array()
-
The sanitised $_GET arguments.
Tags
cancel_email_change()
Cancel a pending email change.
protected
cancel_email_change([array<string|int, string> $get_vars = array() ]) : bool
Parameters
- $get_vars : array<string|int, string> = array()
-
The sanitised $_GET vars, including a nonce.
Tags
Return values
bool —Success or failure.
cancel_password_change()
Cancel a pending password change.
protected
cancel_password_change([array<string|int, string> $get_vars = array() ]) : bool
Parameters
- $get_vars : array<string|int, string> = array()
-
{ The sanitised $_GET vars, including a nonce. @type string $key The hashed new email address. }
Tags
Return values
bool —Success or failure.
do_intercepts()
Take special actions before initialising the form.
protected
do_intercepts([array<string|int, string> $get_vars = array() ]) : void
Parameters
- $get_vars : array<string|int, string> = array()
-
{ The sanitised $_GET arguments, including a nonce. @type string $action The action to take. }
Tags
do_submission()
Execute the submission request.
protected
do_submission(WP_Error $errors, array<string|int, string> $post_vars, array<string|int, string> $server_vars) : WP_Error
Parameters
- $errors : WP_Error
-
The WP_Error object to use if errors.
- $post_vars : array<string|int, string>
-
The sanitised $_POST arguments.
- $server_vars : array<string|int, string>
-
The sanitised $_SERVER arguments.
Tags
Return values
WP_Error —The maybe modified WP_Error object.
enqueue_assets()
Enqueue the resources.
protected
enqueue_assets() : void
Tags
get_inline_script()
Get the inline JavaScript.
protected
get_inline_script() : string
Tags
Return values
string —The inline script.
render_success_notification()
Render the success notification.
protected
render_success_notification() : void
Tags
set_form_header()
Set the form header text.
protected
set_form_header() : void
- (Maybe) extend this in child classes to set specific instructions for that form.
Tags
set_form_values()
Initialise the values used in the form.
protected
set_form_values(array<string|int, string> $get_vars, array<string|int, string> $server_vars) : void
Parameters
- $get_vars : array<string|int, string>
-
The sanitised $_GET arguments.
- $server_vars : array<string|int, string>
-
The sanitised $_SERVER arguments.
Tags
validate_email()
Validate the email address.
protected
validate_email(array<string|int, string> $post_vars, WP_Error $errors) : WP_Error
Parameters
- $post_vars : array<string|int, string>
-
The sanitised $_POST arguments.
- $errors : WP_Error
-
The WP_Error object to use if errors.
Tags
Return values
WP_Error —The maybe modified WP_Error object.
validate_submission()
Validate the submitted form contents.
protected
validate_submission(WP_Error $errors, array<string|int, string> $post_vars, array<string|int, string> $server_vars) : WP_Error
Parameters
- $errors : WP_Error
-
The WP_Error object to use if errors.
- $post_vars : array<string|int, string>
-
The sanitised $_POST arguments.
- $server_vars : array<string|int, string>
-
The sanitised $_SERVER arguments.
Tags
Return values
WP_Error —The maybe modified WP_Error object.