LLMS_Form_Handler::validate_fields( array $posted_data, string $location, array[] $fields, string $action )
Form fields submission validation.
Parameters Parameters
- $posted_data
-
(array) (Required) User-submitted form data.
- $location
-
(string) (Required) Form location ID.
- $fields
-
(array[]) (Required) Array of LifterLMS Form Fields.
- $action
-
(string) (Required) User action to perform.
Return Return
(boolean|WP_Error) Returns true
on success and an error object on failure.
Source Source
File: includes/forms/class-llms-form-handler.php
protected function validate_fields( $posted_data, $location, $fields, $action ) { /** * Run an action immediately prior to user registration or update. * * The dynamic portion of this hook, `$action`, can be either "registration" or "update". * * @since 3.0.0 * @since 5.0.0 Moved from `LLMS_Person_Handler::update()` & LLMS_Person_Handler::register(). * Added parameters `$fields` and `$args`. * Triggered by `do_action_ref_array()` instead of `do_action()` allowing modification * of `$posted_data` and `$fields` via hooks. * * @param array $posted_data Array of user-submitted data (passed by reference). * @param string $location Form location. * @param array[] $fields Array of LifterLMS Form Fields (passed by reference). */ do_action_ref_array( "lifterlms_before_user_{$action}", array( &$posted_data, $location, &$fields ) ); // Check for all required fields. $required = $this->validator->validate_required_fields( $posted_data, $fields ); /** * Filter the required fields validity of the form submission. * * The dynamic portion of this hook, `$action`, can be either "registration" or "update". * * @since 5.0.1 * * @param WP_Error|true $valid Error object containing required validation errors or true when the data is valid. * @param array $posted_data Array of user-submitted data. * @param string $location Form location. */ $required = apply_filters( "lifterlms_user_{$action}_required_data", $required, $posted_data, $location ); if ( is_wp_error( $required ) ) { return $this->submit_error( $required, $posted_data, $action ); } $posted_data = wp_unslash( $posted_data ); $valid = $this->validator->validate_fields( $posted_data, $fields ); if ( is_wp_error( $valid ) ) { return $this->submit_error( $valid, $posted_data, $action ); } // Validate matching fields. $matches = $this->validator->validate_matching_fields( $posted_data, $fields ); if ( is_wp_error( $matches ) ) { return $this->submit_error( $matches, $posted_data, $action ); } /** * Filter the validity of the form submission. * * The dynamic portion of this hook, `$action`, can be either "registration" or "update". * * @since 3.0.0 * @since 5.0.0 Unknown. * * @param WP_Error|true $valid Error object containing validation errors or true when the data is valid. * @param array $posted_data Array of user-submitted data. * @param string $location Form location. */ $valid = apply_filters( "lifterlms_user_{$action}_data", true, $posted_data, $location ); if ( is_wp_error( $valid ) ) { return $this->submit_error( $valid, $posted_data, $action ); } /** * Run an action immediately after user registration/update fields have been validated. * * The dynamic portion of this hook, `$action`, can be either "registration" or "update". * * @since 3.0.0 * @since 5.0.0 Moved from `LLMS_Person_Handler::update()` & LLMS_Person_Handler::register(). * Added parameters `$fields` and `$args`. * * @param array $posted_data Array of user-submitted data. * @param string $location Form location. * @param array[] $fields Array of LifterLMS Form Fields. */ do_action( "lifterlms_user_{$action}_after_validation", $posted_data, $location, $fields ); return true; }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
7.0.0 | Introduced. |