Action uncanny-learndash-groups

ulgm_groups_registration_form_before_last_name

Fires before the last name field is displayed on the group registration form.

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

Description

Fires before the last name field is displayed on the user registration form. Developers can use this hook to insert custom fields, modify existing elements, or add validation logic before the last name input. This hook is part of the core registration form generation process.


Usage

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

Examples

<?php
/**
 * Example function to add a custom field before the last name field on the ULGm registration form.
 *
 * This function demonstrates how to hook into 'ulgm_groups_registration_form_before_last_name'
 * to inject additional form elements. In this example, we're adding a 'Middle Name' field.
 *
 * @param array $form_data An array containing existing form data if any.
 */
function my_custom_ulgm_registration_middle_name_field( $form_data = array() ) {
	?>
	<!-- Middle name __ START -->
	<tr>
		<td class="label"><label for="ulgm_user_middle"><?php esc_html_e( 'Middle Name', 'my-custom-plugin' ); ?></label></td>
		<td class="input">
			<input name="ulgm_user_middle"
				   id="ulgm_user_middle"
				   value="<?php
				   // Check if middle name was submitted and sanitize/echo it.
				   if ( ulgm_filter_has_var( 'ulgm_user_middle', INPUT_POST ) ) {
					   echo sanitize_text_field( ulgm_filter_input( 'ulgm_user_middle', INPUT_POST ) );
				   } elseif ( ! empty( $form_data['ulgm_user_middle'] ) ) {
					   echo esc_attr( $form_data['ulgm_user_middle'] );
				   }
				   ?>"
				   type="text"/>
		</td>
	</tr>
	<!-- Middle name __ END -->
	<?php
}
add_action( 'ulgm_groups_registration_form_before_last_name', 'my_custom_ulgm_registration_middle_name_field', 10, 1 );

/**
 * Example function to save the custom middle name field when the form is submitted.
 * This is a hypothetical hook that would be needed to process the custom field.
 * In a real scenario, you would need to find the appropriate hook for form submission
 * in the Uncanny LearnDash Groups plugin to save this data.
 *
 * @param int $user_id The ID of the newly created or updated user.
 */
function save_my_custom_ulgm_registration_middle_name( $user_id ) {
	// Check if the middle name field was submitted.
	if ( ulgm_filter_has_var( 'ulgm_user_middle', INPUT_POST ) ) {
		$middle_name = sanitize_text_field( ulgm_filter_input( 'ulgm_user_middle', INPUT_POST ) );

		// You would typically save this to user meta.
		// For example:
		// update_user_meta( $user_id, 'middle_name', $middle_name );
	}
}
// NOTE: The hook 'ulgm_groups_registration_form_saved' or similar would be needed for this.
// Add this action hook once you identify the correct hook for form submission processing.
// add_action( 'ulgm_groups_registration_form_saved', 'save_my_custom_ulgm_registration_middle_name', 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:36

value="<?php if ( ulgm_filter_has_var( 'ulgm_user_first', INPUT_POST ) ) {
								   echo sanitize_text_field( ulgm_filter_input( 'ulgm_user_first', INPUT_POST ) );
							   } ?>"
							   type="text"/></td>
				</tr>
				<!-- First name __ END -->
				<?php do_action( 'ulgm_groups_registration_form_after_first_name' ); ?>
				<?php do_action( 'ulgm_groups_registration_form_before_last_name' ); ?>
				<!-- Last name  __ START -->
				<tr>
					<td class="label"><label
								for="ulgm_user_last"><?php esc_html_e( 'Last name', 'uncanny-learndash-groups' ); ?></label>
					</td>
					<td class="input">
						<input name="ulgm_user_last"


Scroll to Top