LLMS_Form_Handler::submit_fields( array $posted_data, string $location, array[] $fields, string $action )

Form fields submission


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.


Top ↑

Return Return

(int|WP_Error) WP_User ID on success, error object on failure.


Top ↑

Source Source

File: includes/forms/class-llms-form-handler.php

		// 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 );
		}

		// Sanitize.
		$posted_data = $this->validator->sanitize_fields( wp_unslash( $posted_data ), $fields );

		$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 );

		$user_id = $this->insert( $action, $posted_data, $fields );
		if ( is_wp_error( $user_id ) ) {
			return $this->submit_error( $user_id, $posted_data, $action );
		}

		if ( 'registration' === $action ) {

			/**
			 * Deprecated user creation hook
			 *
			 * @since Unknown.
			 * @deprecated 5.0.0
			 *
			 * @param int    $user_id     WP_User ID of the newly created user.
			 * @param array  $posted_data Array of user-submitted data.
			 * @param string $location    Form location.
			 */
			do_action( 'lifterlms_created_person', $user_id, $posted_data, $location );

			/**
			 * Fire an action after a user has been registered
			 *
			 * @since 3.0.0
			 * @since 5.0.0 Moved from `LLMS_Person_Handler::register()`.
			 *
			 * @param int    $user_id     WP_User ID of the user.
			 * @param array  $posted_data Array of user submitted data.
			 * @param string $location    Form location.
			 */
			do_action( 'lifterlms_user_registered', $user_id, $posted_data, $location );

		} elseif ( 'update' === $action ) {

			/**
			 * Fire an action after a user has been updated
			 *
			 * @since 3.0.0
			 * @since 5.0.0 Moved from `LLMS_Person_Handler::update()`.
			 *
			 * @param int    $user_id     WP_User ID of the user.
			 * @param array  $posted_data Array of user submitted data.
			 * @param string $location    Form location.
			 */
			do_action( 'lifterlms_user_updated', $user_id, $posted_data, $location );

		}

		return $user_id;

	}

	/**
	 * Ensure all errors objects encountered during form submission are filterable.
	 *
	 * @since 5.0.0
	 *
	 * @param WP_Error $error Error object.
	 * @param array    $posted_data User-submitted form data.
	 * @param string   $action Form action, either "registration" or "update".
	 * @return WP_Error
	 */
	protected function submit_error( $error, $posted_data, $action ) {

		/**
		 * Filter the error return when the insert/update fails.
		 *
		 * The dynamic portion of this hook, `$action`, can be either "registration" or "update".
		 *


Top ↑

Changelog Changelog

Changelog
Version Description
5.1.0 Added "lifterlms*user*${action}_required_data" filter, to filter the required fields validity of the form submission.
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.