ulgm_groups_registration_form_after_first_name
Fires after the "First Name" field is displayed on the ULGM group registration form.
add_action( 'ulgm_groups_registration_form_after_first_name', $callback, 10, 1 );
Description
Fires after the 'First Name' field on the user registration form. Developers can use this hook to add custom fields or modify the existing form structure immediately following the first name input.
Usage
add_action( 'ulgm_groups_registration_form_after_first_name', 'your_function_name', 10, 1 );
Examples
<?php
/**
* Example function to add a custom field after the first name field in the registration form.
*
* This function demonstrates how to hook into 'ulgm_groups_registration_form_after_first_name'
* to add an additional input field, for example, a middle initial.
*
* @param string $form_html The current HTML of the registration form.
* @return string The modified HTML of the registration form.
*/
add_action( 'ulgm_groups_registration_form_after_first_name', function( $form_html ) {
// Retrieve and sanitize any previously submitted value for the middle initial.
$middle_initial_value = '';
if ( ulgm_filter_has_var( 'ulgm_user_middle_initial', INPUT_POST ) ) {
$middle_initial_value = sanitize_text_field( ulgm_filter_input( 'ulgm_user_middle_initial', INPUT_POST ) );
}
// Construct the HTML for the new field and append it to the existing form HTML.
$new_field_html = '
<!-- Middle initial __ START -->
<tr>
<td class="label"><label for="ulgm_user_middle_initial">' . esc_html__( 'Middle Initial', 'your-text-domain' ) . '</label></td>
<td class="input">
<input name="ulgm_user_middle_initial"
id="ulgm_user_middle_initial"
value="' . esc_attr( $middle_initial_value ) . '"
type="text"
maxlength="1"
style="width: 50px;" />
</td>
</tr>
<!-- Middle initial __ END -->
';
// The hook 'ulgm_groups_registration_form_after_first_name' might not inherently pass the entire form HTML.
// Assuming the hook expects to echo output directly or append to a buffer.
// If the hook *does* pass the form_html and expects it back, then the following would be appropriate:
// return $form_html . $new_field_html;
// For this example, we assume it's meant to echo directly or modify an output buffer.
echo $new_field_html;
}, 10, 1 ); // Priority 10, accepts 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:35
required="required"
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">