Action uncanny-learndash-groups

ulgm_groups_registration_form_before_enrollment_key

Fires before the enrollment key field is displayed on the group registration form.

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

Description

Fired just before the enrollment key field is displayed on the group registration form. Developers can use this hook to add custom fields or modify the form's layout before the enrollment key input.


Usage

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

Examples

/**
 * Example function to add custom validation or modification to the enrollment key field
 * before it's displayed on the Uncanny Groups user registration form.
 *
 * @param array $form_data An array containing the current form data, including user details and group information.
 *                         (Assuming this hook might pass data, though the source doesn't explicitly show it).
 */
add_action( 'ulgm_groups_registration_form_before_enrollment_key', function ( $form_data = [] ) {

	// Example: If a specific user role is attempting to register,
	// you might want to pre-fill the enrollment key field or disable it.
	// This is a hypothetical example as the hook's context for $form_data is not fully clear from the snippet.
	// In a real scenario, you would likely access WordPress user data or plugin-specific settings here.

	// Let's assume we want to add a small note if the user is logged in,
	// indicating that their role might influence enrollment.
	if ( is_user_logged_in() ) {
		echo '<p style="font-size: 0.9em; color: #555;">(Note: Your current role may affect enrollment key requirements.)</p>';
	}

	// Another hypothetical scenario: if you wanted to programmatically set the enrollment key
	// based on some external factor (though this is less common for a 'before' hook).
	// For instance, if you had a special offer code to apply for a specific group.
	/*
	if ( isset( $form_data['group_id'] ) && $form_data['group_id'] === 123 ) {
		// This would require modifying the HTML output, which is tricky within an action hook.
		// A filter hook might be more appropriate for modifying input values directly.
		// For demonstration, this is just illustrative of the thought process.
		echo '<script>document.getElementById("code_registration").value = "SPECIALCODE4YOU";</script>';
	}
	*/

	// The primary use case for this hook is likely to inject HTML (like additional labels,
	// help text, or custom input fields) or to conditionally display the enrollment key field.

}, 10, 1 ); // Priority 10, accepting 1 argument.

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:105

oninput="check(this)"
							   class="required"
							   placeholder="<?php esc_html_e( 'Confirm Password', 'uncanny-learndash-groups' ); ?>"
							   type="password"/></td>
				</tr>
				<!-- Confirm Password __ END -->
				<?php do_action( 'ulgm_groups_registration_form_after_password_confirm' ); ?>
				<?php do_action( 'ulgm_groups_registration_form_before_enrollment_key' ); ?>
				<!--  Enrollment key __ START -->
				<tr>
					<td class="label"><label
								for="code_registration"><?php esc_html_e( 'Enrollment key', 'uncanny-learndash-groups' ); ?></label>
					</td>
					<td class="input">
						<input name="ulgm_code_registration" id="code_registration"


Scroll to Top