Action
uncanny-automator
uo_new_group_created
Fires after a new group is successfully created, passing the new group's ID and the user ID who created it.
add_action( 'uo_new_group_created', $callback, 10, 2 );
Description
Fires after a new Uncanny Groups group is successfully created and all initial setup is complete. Developers can use this hook to perform custom actions, such as sending custom notifications, updating related data, or integrating with other systems, based on the newly created group's ID and the user ID who initiated the creation.
Usage
add_action( 'uo_new_group_created', 'your_function_name', 10, 2 );
Parameters
-
$group_id(mixed) - The `$group_id` parameter contains the unique identifier for the newly created Uncanny Group.
-
$user_id(mixed) - This parameter contains the unique identifier for the newly created Uncanny Group.
Examples
/**
* Example function hooked to the 'uo_new_group_created' action.
* This function logs the creation of a new group and sends a notification email.
*
* @param int $group_id The ID of the newly created Uncanny Group.
* @param int $user_id The ID of the user who created the group (likely the group leader).
*/
function my_custom_group_creation_handler( $group_id, $user_id ) {
// Log the event for debugging purposes.
error_log( "New Uncanny Group created! Group ID: {$group_id}, User ID: {$user_id}" );
// Fetch user data.
$user = get_user_by( 'id', $user_id );
if ( $user ) {
// Construct an email subject.
$subject = sprintf( __( 'New Uncanny Group "%s" Created', 'my-text-domain' ), get_the_title( $group_id ) );
// Construct the email body.
$message = sprintf(
__( 'Hello %s,', 'my-text-domain' ) . "nn" .
__( 'A new Uncanny Group has been successfully created: "%s" (ID: %d).', 'my-text-domain' ) . "nn" .
__( 'You can manage this group from your dashboard.', 'my-text-domain' ) . "nn" .
__( 'Thank you,', 'my-text-domain' ) . "n" .
__( 'Your Website Team', 'my-text-domain' ),
$user->display_name,
get_the_title( $group_id ),
$group_id
);
// Send an email notification to the group leader.
wp_mail( $user->user_email, $subject, $message );
// You could also perform other actions here, such as:
// - Updating a custom meta field for the user related to group leadership.
// - Triggering another internal process.
// - Adding the group to a custom reporting system.
}
}
add_action( 'uo_new_group_created', 'my_custom_group_creation_handler', 10, 2 );
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/integrations/uncanny-groups/actions/uog-createuncannygroup.php:270
update_post_meta( $group_id, uncanny_learndash_groupsSharedFunctions::$code_group_id_meta_key, $code_group_id );
update_user_meta( $user_id, '_ulgm_custom_order_id', $order_id );
if ( 'yes' !== get_option( 'do_not_add_group_leader_as_member', 'no' ) ) {
uncanny_learndash_groupsRestApiEndPoints::add_existing_user( array( 'user_email' => $user->user_email ), true, $group_id, $order_id, 'redeemed', false );
}
do_action( 'uo_new_group_created', $group_id, $user_id );
$tokens = array(
'GROUP_ID' => $group_id,
'GROUP_COURSES' => $this->get_group_names( $group_id ),
'GROUP_LEADER_EMAILS' => $this->get_group_leaders_email_addresses( $group_id ),
);