LLMS_Admin_User_Custom_Fields::validate_fields( WP_User|int $user )

Validate custom fields

Description Description

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.

Top ↑

Parameters Parameters


(WP_User|int) (Required) Instance of WP_User or WP User ID.

Top ↑

Return Return

(string|bool) false if no validation errors or the error message (as a sttring) 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'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing

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

			} 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
				 * @param boolean     $error_message The error message when validation issues are encountered. Return `false` when no validation issues.
				 * @param string      $field         Field id.
				 * @param WP_User|int $user          Instance of WP_User or WP User ID.
				$error_msg = apply_filters( "lifterlms_validate_custom_user_field_{$field}", false, $field, $user );

				if ( $error_msg ) {

					return $error_msg;


		return false;


Top ↑

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.