ulgm_groups_registration_form_before_email
Fires before the email field is displayed on the group registration form.
add_action( 'ulgm_groups_registration_form_before_email', $callback, 10, 1 );
Description
Fires before the email field is displayed on the user registration form. Developers can use this hook to add custom fields or modify the existing form structure before the email input.
Usage
add_action( 'ulgm_groups_registration_form_before_email', 'your_function_name', 10, 1 );
Examples
<?php
/**
* Example: Add a validation rule to check if the email is already in use
* when the 'ulgm_groups_registration_form_before_email' action hook is triggered.
*/
add_action( 'ulgm_groups_registration_form_before_email', 'my_custom_email_validation_for_groups_registration', 10, 0 );
if ( ! function_exists( 'my_custom_email_validation_for_groups_registration' ) ) {
/**
* Performs a custom validation on the email field before the email input is displayed
* in the Uncanny Groups registration form.
*/
function my_custom_email_validation_for_groups_registration() {
// Only proceed if the form has been submitted
if ( isset( $_POST['ulgm_user_email'] ) && ! empty( $_POST['ulgm_user_email'] ) ) {
$submitted_email = sanitize_email( $_POST['ulgm_user_email'] );
// Check if the email already exists in WordPress
$user_by_email = email_exists( $submitted_email );
if ( $user_by_email ) {
// Add a JavaScript alert to notify the user immediately.
// In a real-world scenario, you might want to use AJAX
// or store the error in a session and display it on the form load.
?>
<script type="text/javascript">
alert('<?php echo esc_js( sprintf( __( 'The email address %s is already registered. Please use a different email or log in.', 'your-text-domain' ), $submitted_email ) ); ?>');
</script>
<?php
// Potentially stop form submission or set an error flag here if possible
// depending on how the Uncanny Groups plugin handles errors.
}
}
}
}
?>
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:54
value="<?php if ( ulgm_filter_has_var( 'ulgm_user_last', INPUT_POST ) ) {
echo sanitize_text_field( ulgm_filter_input( 'ulgm_user_last', INPUT_POST ) );
} ?>"
type="text"/></td>
</tr>
<!-- Last name __ END -->
<?php do_action( 'ulgm_groups_registration_form_after_last_name' ); ?>
<?php do_action( 'ulgm_groups_registration_form_before_email' ); ?>
<!-- Email / Username __ START -->
<tr>
<td class="label"><label
for="ulgm_user_email"><?php esc_html_e( 'Email / Username', 'uncanny-learndash-groups' ); ?></label>
</td>
<td class="input">
<input name="ulgm_user_email"