uo_redirect_after_group_created
Filters the redirect URL after a group is successfully created, allowing modification of the destination.
add_filter( 'uo_redirect_after_group_created', $callback, 10, 1 );
Description
Filters the redirect URL after a group is successfully created. Developers can modify this URL to send users to a different page, such as the newly created group's page or a custom success message. This hook fires after the group is saved to the database.
Usage
add_filter( 'uo_redirect_after_group_created', 'your_function_name', 10, 1 );
Parameters
-
$group_id(mixed) - This parameter contains the URL to redirect to after a group has been successfully created, which includes a query argument to indicate that the group was just created.
Return Value
The filtered value.
Examples
/**
* Modify the redirect URL after a group is successfully created.
*
* This filter allows developers to change the default redirect URL,
* for example, to redirect to a custom success page or to append
* additional query parameters for tracking or messaging.
*
* @param string $redirect_url The default redirect URL.
* @param int $group_id The ID of the newly created group.
* @return string The modified redirect URL.
*/
add_filter( 'uo_redirect_after_group_created', function( $redirect_url, $group_id ) {
// Example: Append a specific message parameter if the group was created via a specific form ID.
// This assumes you have a way to know which form was used, perhaps by checking $_POST data.
if ( isset( $_POST['creation_form_id'] ) && $_POST['creation_form_id'] === 'new_member_welcome_form' ) {
$redirect_url .= '&message=welcome_new_member';
}
// Example: Log the group creation and the redirect URL for debugging or analytics.
// This is useful for tracking successful group creations.
error_log( sprintf( 'Group created with ID %d. Redirecting to: %s', $group_id, $redirect_url ) );
// Always return the URL, whether modified or not.
return $redirect_url;
}, 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/classes/helpers/process-manual-group.php:198
$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;
}
if ( ulgm_filter_has_var( 'group_page_id', INPUT_POST ) ) {
$redirect = apply_filters( 'uo_redirect_after_group_created', get_permalink( ulgm_filter_input( 'group_page_id', INPUT_POST ) ) . '?is-group-created=yes', $group_id );
wp_safe_redirect( $redirect );
exit;
}
return $group_id;
}
}