Action uncanny-learndash-groups

ulgm_new_user_registration_by_form_before

Fires before a new user is registered via the form, providing access to POST data.

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

Description

Fires before a new user is created via the registration form. Developers can use this hook to intercept and modify the user registration data (`$_POST`) or perform actions before user creation, such as custom validation or logging. It fires after initial error checking but before `wp_insert_user`.


Usage

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

Parameters

$_POST (mixed)
This parameter contains all the data submitted through the registration form in a `$_POST` array.

Examples

/**
 * Example of how to hook into ulgm_new_user_registration_by_form_before.
 * This example will log the incoming POST data to a file before the user is created.
 */
add_action(
	'ulgm_new_user_registration_by_form_before',
	function ( $post_data ) {
		// Ensure we have some data to log.
		if ( ! empty( $post_data ) ) {
			// Define a log file path. In a real scenario, consider using a more robust logging solution or storing it within WP_CONTENT_DIR.
			$log_file = WP_CONTENT_DIR . '/ulgm-registration-log.txt';

			// Prepare the log entry.
			$log_entry = sprintf(
				"[%s] New user registration attempt. POST data: %sn",
				current_time( 'mysql' ),
				print_r( $post_data, true ) // 'true' returns the output as a string
			);

			// Append the log entry to the file. FILE_APPEND flag ensures we don't overwrite existing logs. LOCK_EX prevents concurrent writes.
			file_put_contents( $log_file, $log_entry, FILE_APPEND | LOCK_EX );
		}
	},
	10, // Default priority
	1  // Number of arguments accepted by the callback function
);

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

$errors = $this->ulgm_registration_errors()->get_error_messages();

		if ( ! empty( $errors ) ) {
			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,


Scroll to Top