LLMS_Person_Handler::validate_login_fields( array $data )

Validate login form fields


Parameters Parameters

$data

(array) (Required) Array of user-submitted data, usually from $_POST.


Top ↑

Return Return

(WP_Error|true) Returns an error object or true if the submission is valid.


Top ↑

Source Source

File: includes/class.llms.person.handler.php

	protected static function validate_login_fields( $data ) {

		$err = new WP_Error();

		$fields = self::get_login_fields();

		foreach ( $fields as $field ) {

			$name  = isset( $field['name'] ) ? $field['name'] : $field['id'];
			$label = isset( $field['label'] ) ? $field['label'] : $name;

			$field_type = isset( $field['type'] ) ? $field['type'] : '';
			$val        = isset( $data[ $name ] ) ? $data[ $name ] : '';

			// Ensure required fields are submitted.
			if ( ! empty( $field['required'] ) && empty( $val ) ) {

				$err->add( $field['id'], sprintf( __( '%s is a required field', 'lifterlms' ), $label ), 'required' );
				continue;

			}

			// Email fields must be emails.
			if ( 'email' === $field_type && ! is_email( $val ) ) {
				$err->add( $field['id'], sprintf( __( '%s must be a valid email address', 'lifterlms' ), $label ), 'invalid' );
			}
		}

		$valid = $err->has_errors() ? $err : true;

		/**
		 * Filters the validation result of user-submitted login data
		 *
		 * @since 4.21.0
		 *
		 * @param WP_Error|boolean $valid An error object containing validation errors or `true` if no validation errors found.
		 * @param array            $data  User submitted login data.
		 */
		return apply_filters( 'llms_after_user_login_data_validation', $valid, $data );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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