LLMS_Admin_User_Custom_Fields::validate_fields( mixed $user )

Validate custom fields By default only checks for valid as core fields don’t have any special validation If adding custom fields, hook into the action run after required validation to add special validation rules for your field


Description Description


Parameters Parameters

$user

(mixed) (Required) Instance of WP_User or WP User ID


Top ↑

Return Return

(mixed) false if no validation errors, string (the error message) if validation errors occurred


Top ↑

Source Source

File: includes/admin/class.llms.admin.user.custom.fields.php

	public function validate_fields( $user ) {

		// ensure there's no missing required fields
		foreach ( $this->fields as $field => $data ) {

			// return an error message for empty required fields
			if ( empty( $_POST[ $field ] ) && $data['required'] ) {

				return sprintf( __( 'Required field "%s" is missing.', 'lifterlms' ), $data['label'] );

			} // End if().
			else {

				/**
				 * Run custom validation against the field
				 * If filter function returns a truthy, validation will stop, fields will not be saved,
				 * and an error message will be displayed on screen
				 * This should return false or a string which will be used as the error message
				 * @since  2.7.0
				 */
				$error_msg = apply_filters( 'lifterlms_validate_custom_user_field_' . $field, false, $field, $user );

				if ( $error_msg ) {

					return $error_msg;

				}
			}
		}

		return false;

	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.7.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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