Action uncanny-learndash-groups

ulgm_group_user_invited

Fires after a user is invited to a group, passing user, group, and order data.

add_action( 'ulgm_group_user_invited', $callback, 10, 3 );

Description

Fires after a user has been successfully invited to a group. Developers can use this hook to perform custom actions, such as logging invitation events, sending custom notifications, or modifying user permissions based on the invitation. The hook passes the invited user's data, the group ID, and the order ID, if applicable.


Usage

add_action( 'ulgm_group_user_invited', 'your_function_name', 10, 3 );

Parameters

$user_data (mixed)
This parameter contains the user's data for the user being invited.
$group_id (mixed)
This parameter contains the data of the user who has been invited to a group.
$order_id (mixed)
This parameter contains the unique identifier for the group to which the user has been invited.

Examples

/**
 * Example function to hook into ulgm_group_user_invited.
 * This function logs the invitation details and potentially sends a notification.
 *
 * @param mixed $user_data Data about the invited user.
 * @param mixed $group_id  The ID of the group the user is invited to.
 * @param mixed $order_id  The ID of the order associated with the invitation, if any.
 */
function my_custom_group_invite_handler( $user_data, $group_id, $order_id ) {
	// Log the invitation details for debugging or auditing purposes.
	error_log( sprintf(
		'User invited to group: User data - %s, Group ID - %s, Order ID - %s',
		print_r( $user_data, true ),
		$group_id,
		$order_id
	) );

	// You could potentially use this hook to send a custom email notification,
	// update a user's meta, or trigger other actions based on the invitation.

	// Example: Check if the invited user is a specific type and send a special notification.
	if ( isset( $user_data['user_login'] ) && 'special_user' === $user_data['user_login'] ) {
		// Replace with your actual notification sending logic.
		// For demonstration, we'll just log another message.
		error_log( 'Special user invited! Triggering custom notification.' );
		// wp_mail( '[email protected]', 'Special User Invited', 'A special user has been invited to group: ' . $group_id );
	}

	// If this were a filter, you would return a value here.
	// For example: return $modified_user_data;
}

// Hook the custom function to the ulgm_group_user_invited action.
// The '3' indicates that the function accepts 3 arguments ($user_data, $group_id, $order_id).
add_action( 'ulgm_group_user_invited', 'my_custom_group_invite_handler', 10, 3 );

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/class-group-management-helpers.php:335

'reason' => 'use_error_code',
						// '' if success or use_error_code or if needed a custom
					),
				);
			}
		}

		do_action( 'ulgm_group_user_invited', $user_data, $group_id, $order_id );
		$do_not_send_emails = apply_filters( 'ulgm_do_not_send_new_user_email', $do_not_send_emails, $user_data, $group_id, $order_id );

		if ( $do_not_send_emails ) {

			if ( ! $counter ) {
				$data['message'] = __( 'User has been added.' . $password_info, 'uncanny-learndash-groups' );
				SharedFunctions::delete_transient( null, $group_id );


Scroll to Top