Action uncanny-learndash-groups

ulgm_groups_registration_form_before_password

Fires just before the password field is displayed on the group registration form.

add_action( 'ulgm_groups_registration_form_before_password', $callback, 10, 1 );

Description

Fires before the password field is displayed on the user registration form. Developers can use this hook to add custom fields, modify existing ones, or inject content before the password input element.


Usage

add_action( 'ulgm_groups_registration_form_before_password', 'your_function_name', 10, 1 );

Examples

// Add a custom field before the password field on the user registration form.
// This example adds a "Confirm Password" field for better user experience.
function my_ulgm_add_confirm_password_field() {
	?>
	<tr>
		<td class="label"><label for="confirm_password"><?php esc_html_e( 'Confirm Password', 'my-text-domain' ); ?></label></td>
		<td class="input">
			<input name="ulgm_user_confirm_pass" id="confirm_password" class="required" type="password" />
		</td>
	</tr>
	<?php
}
add_action( 'ulgm_groups_registration_form_before_password', 'my_ulgm_add_confirm_password_field', 10 );

// Add validation for the "Confirm Password" field.
// This function will run after the form is submitted and can check if the passwords match.
function my_ulgm_validate_confirm_password( $errors ) {
	if ( ! empty( $_POST['ulgm_user_pass'] ) && ! empty( $_POST['ulgm_user_confirm_pass'] ) ) {
		if ( $_POST['ulgm_user_pass'] !== $_POST['ulgm_user_confirm_pass'] ) {
			$errors['ulgm_user_confirm_pass'] = __( 'Passwords do not match.', 'my-text-domain' );
		}
	} elseif ( empty( $_POST['ulgm_user_pass'] ) || empty( $_POST['ulgm_user_confirm_pass'] ) ) {
		// This check assumes 'ulgm_user_pass' is already handled by the 'required' class.
		// We might want to add a more robust check here if the core field isn't strictly required.
		$errors['ulgm_user_confirm_pass'] = __( 'Please enter both password fields.', 'my-text-domain' );
	}
	return $errors;
}
// The hook for validation usually happens after the form submission processing.
// This hook isn't explicitly provided by the example, but a common pattern is to
// hook into a form submission or validation action. Assuming a hypothetical hook:
// add_filter( 'ulgm_groups_registration_form_validation', 'my_ulgm_validate_confirm_password', 10, 1 );
// Since we don't have the exact validation hook, let's show a hypothetical example
// that would be hooked into the form submission process if the plugin provided one.

// If the plugin offers a hook to access user data before it's saved, you could use that for validation too.
// For example, if there was a hook like 'ulgm_groups_registration_before_user_save':
/*
function my_ulgm_validate_confirm_password_on_save( $user_data ) {
    if ( ! empty( $user_data['user_pass'] ) && ! empty( $_POST['ulgm_user_confirm_pass'] ) ) {
        if ( $user_data['user_pass'] !== $_POST['ulgm_user_confirm_pass'] ) {
            // This would require the hook to allow returning errors or stopping the process.
            // For demonstration, let's assume we can trigger a WordPress user creation error.
            wp_die( __( 'Passwords do not match.', 'my-text-domain' ) );
        }
    } elseif ( empty( $user_data['user_pass'] ) || empty( $_POST['ulgm_user_confirm_pass'] ) ) {
         wp_die( __( 'Please enter both password fields.', 'my-text-domain' ) );
    }
    return $user_data; // Important to return the modified or original data
}
// add_action( 'ulgm_groups_registration_before_user_save', 'my_ulgm_validate_confirm_password_on_save', 10, 1 );
*/
?>

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/includes/forms/user-registration-form.php:72

value="<?php if ( ulgm_filter_has_var( 'ulgm_user_email', INPUT_POST ) ) {
								   echo sanitize_email( ulgm_filter_input( 'ulgm_user_email', INPUT_POST ) );
							   } ?>"
							   class="required" type="email"/></td>
				</tr>
				<!-- Email / Username __ END -->
				<?php do_action( 'ulgm_groups_registration_form_after_email' ); ?>
				<?php do_action( 'ulgm_groups_registration_form_before_password' ); ?>
				<!-- Password  __ START -->
				<tr>
					<td class="label"><label
								for="password"><?php esc_html_e( 'Password', 'uncanny-learndash-groups' ); ?></label>
					</td>
					<td class="input">
						<input name="ulgm_user_pass" id="password"


Scroll to Top