Filter uncanny-learndash-groups

ulgm_new_user_code_registration

Filters user login and POST data before registering a new user with a code.

add_filter( 'ulgm_new_user_code_registration', $callback, 10, 2 );

Description

Filters the data array used to register a new user via a code-based registration process. Developers can modify user details like username, password, and email before the user is created in WordPress. This hook runs after initial validation and before `wp_insert_user`.


Usage

add_filter( 'ulgm_new_user_code_registration', 'your_function_name', 10, 2 );

Parameters

$user_login (mixed)
This parameter contains the username of the user being registered.
$_POST (mixed)
This parameter represents the username of the user being registered.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of filtering user registration data before insertion.
 * This function demonstrates how to modify user login, email, or name
 * before the user is inserted into the WordPress database.
 *
 * @param array $user_data An array containing user registration data.
 * @return array The modified user registration data.
 */
add_filter( 'ulgm_new_user_code_registration', 'my_custom_user_registration_filter', 10, 1 );

function my_custom_user_registration_filter( $user_data ) {
    // Example: Append a prefix to the username for all new registrations
    if ( isset( $user_data['user_login'] ) ) {
        $user_data['user_login'] = 'temp_' . $user_data['user_login'];
    }

    // Example: Ensure the first name is always capitalized
    if ( isset( $user_data['first_name'] ) ) {
        $user_data['first_name'] = ucwords( $user_data['first_name'] );
    }

    // Example: If an email is missing, assign a placeholder (though typically required)
    if ( empty( $user_data['user_email'] ) ) {
        $user_data['user_email'] = 'no-email-' . uniqid() . '@example.com';
    }

    // Return the modified user data array
    return $user_data;
}
?>

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/classes/group-management/group-management-registration.php:244

return;
		}

		do_action( 'ulgm_new_user_registration_by_form_before', $_POST );
		// only create the user in if there are no errors
		$role        = ! empty( $user_role ) ? $user_role : get_option( 'default_role', 'subscriber' );
		$new_user_id = wp_insert_user(
			apply_filters(
				'ulgm_new_user_code_registration',
				array(
					'user_login'      => $user_login,
					'user_pass'       => $user_pass,
					'user_email'      => $user_email,
					'first_name'      => $user_first,
					'last_name'       => $user_last,


Scroll to Top