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

Modify LifterLMS Fields prior to performing submit handler validations.


Parameters Parameters

$posted_data

(array) (Required) User submitted form data (passed by reference).

$location

(string) (Required) Form location ID.

$fields

(array[]) (Required) Array of LifterLMS Form Fields (passed by reference).


Top ↑

Return Return

(void)


Top ↑

Source Source

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

				// When updating a password, the `password_current` is mandatory.
				if ( 'account' === $location && 'password_current' === $field_id ) {
					// Get `password` field.
					$password_index = LLMS_Forms::instance()->get_field_by( $fields, 'id', 'password', 'index' );
					// If a `passowrd` feld has been submitted then the `password_current` cannot be skipped.
					if ( false !== $password_index &&
							! empty( $posted_data[ $fields[ $password_index ]['name'] ] ) ) {
						continue;
					}
				}

				// Remove the field so we don't accidentally save an empty value later.
				unset( $posted_data[ $fields[ $index ]['name'] ] );

				// Mark the field as optional (for validation purposes).
				$fields[ $index ]['required'] = false;

				// Check if there's a confirm field and do the same.
				$con_index = LLMS_Forms::instance()->get_field_by( $fields, 'id', "{$field_id}_confirm", 'index' );
				if ( false !== $con_index && empty( $posted_data[ $fields[ $con_index ]['name'] ] ) ) {
					unset( $posted_data[ $fields[ $con_index ]['name'] ] );
					$fields[ $con_index ]['required'] = false;
				}
			}
		}

	}

	/**
	 * Modify LifterLMS Fields to allow some address fields to be conditionally required
	 *
	 * Uses available country locale information to remove the "required" attribute for state
	 * and zip code fields when a user has chosen a country that doesn't use states and/or
	 * zip codes.
	 *
	 * @since 5.0.0
	 *
	 * @param array   $posted_data User submitted form data (passed by reference).
	 * @param string  $location    Form location ID.
	 * @param array[] $fields      Array of LifterLMS Form Fields (passed by reference).
	 * @return void
	 */
	public function maybe_modify_required_address_fields( &$posted_data, $location, &$fields ) {

		// Only proceed if we have a country to review.


Top ↑

Changelog Changelog

Changelog
Version Description
5.1.0 Do not allow submitting a password change without providing a password_current
5.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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