uo_new_group_created
Fires after a new group is successfully created, providing the new group's ID and leader's ID.
add_action( 'uo_new_group_created', $callback, 10, 2 );
Description
Fired after a new user-created group is successfully established. This hook passes the new group's ID and its leader's user ID. Developers can use this to trigger custom actions upon group creation, such as sending additional notifications or updating related metadata.
Usage
add_action( 'uo_new_group_created', 'your_function_name', 10, 2 );
Parameters
-
$group_id(mixed) - This parameter contains the unique identifier for the newly created group.
-
$group_leader_id(mixed) - The ID of the newly created group.
Examples
/**
* Example callback function for the 'uo_new_group_created' action hook.
* This function logs the creation of a new group and potentially triggers other actions.
*
* @param int $group_id The ID of the newly created group.
* @param int $group_leader_id The ID of the user who is the leader of the new group.
*/
function my_handle_new_group_creation( $group_id, $group_leader_id ) {
// Ensure we have valid IDs before proceeding.
if ( ! is_numeric( $group_id ) || ! is_numeric( $group_leader_id ) ) {
error_log( 'uo_new_group_created hook received invalid group_id or group_leader_id.' );
return;
}
// Log the event for debugging or auditing purposes.
$group_title = get_the_title( $group_id ); // Assuming group IDs are post IDs.
$leader_user = get_userdata( $group_leader_id );
if ( $group_title && $leader_user ) {
$message = sprintf(
'New group created: "%s" (ID: %d) with leader "%s" (ID: %d).',
esc_html( $group_title ),
absint( $group_id ),
esc_html( $leader_user->display_name ),
absint( $group_leader_id )
);
error_log( $message );
// You could also trigger other actions here, like sending a notification
// to an administrator, updating user roles, or adding meta data.
// For instance, let's add a meta field to the group post.
update_post_meta( $group_id, '_group_creation_processed', current_time( 'mysql' ) );
// Example: If you wanted to send a custom email to the group leader
// from an admin perspective, you could do it here.
// wp_mail( $leader_user->user_email, 'Your New Group is Ready!', 'Congratulations on creating your new group!' );
} else {
error_log( sprintf(
'uo_new_group_created hook: Could not retrieve group title for ID %d or user data for ID %d.',
absint( $group_id ),
absint( $group_leader_id )
) );
}
}
add_action( 'uo_new_group_created', 'my_handle_new_group_creation', 10, 2 ); // 10 is the priority, 2 is the number of accepted arguments.
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/helpers/process-manual-group.php:188
}
// Send Welcome email, for extra validation we are sending in the user id and getting user data from WP because there may be filters
Group_Management_Helpers::send_welcome_email( $group_leader_id, $plain_password, $ulgm_group_leader_welcome_email_subject, $ulgm_group_leader_welcome_email_body, $group_title, $group_id );
}
do_action( 'uo_new_group_created', $group_id, $group_leader_id );
if ( ! ulgm_filter_has_var( 'is_front_end', INPUT_POST ) && ! is_null( $_post ) ) {
$post_type_object = get_post_type_object( 'groups' );
$action = '&action=edit';
$link = admin_url( sprintf( $post_type_object->_edit_link . $action, $group_id ) );
wp_safe_redirect( $link );
exit;