ulgm_group_created_buddyboss_force_login
Filters whether to force login when a BuddyBoss group is created, allowing customization.
add_filter( 'ulgm_group_created_buddyboss_force_login', $callback, 10, 3 );
Description
Fires after a BuddyBoss group is created, determining if the group creator should be force-logged in. Developers can return `false` to prevent the forced login. This filter runs before user login is potentially affected, allowing modification of the login behavior.
Usage
add_filter( 'ulgm_group_created_buddyboss_force_login', 'your_function_name', 10, 3 );
Parameters
-
$group_id(mixed) - This parameter determines whether the login should be forced for the user.
-
$user_id(mixed) - This parameter represents the unique identifier of the group that has just been created.
-
$this(mixed) - This parameter passes the ID of the user who created the group.
Return Value
The filtered value.
Examples
// Prevent forced login for specific groups or users when a BuddyBoss group is created.
// This filter allows developers to conditionally prevent the 'force_login' action
// triggered after a BuddyBoss group is successfully created.
add_filter( 'ulgm_group_created_buddyboss_force_login', function( $should_force_login, $group_id, $user_id, $buddyboss_sync_instance ) {
// Example: Do not force login if the group is a "Public" type (assuming a custom meta key for group type).
// You would replace 'your_custom_group_type_meta_key' and 'public' with actual values from your setup.
$group_type = get_post_meta( $group_id, 'your_custom_group_type_meta_key', true );
if ( 'public' === $group_type ) {
// If the group is 'public', return false to prevent the force login.
return false;
}
// Example: Do not force login for a specific user ID.
$restricted_user_id = 123; // Replace with the actual user ID to restrict.
if ( $user_id === $restricted_user_id ) {
// If the user is restricted, return false to prevent the force login.
return false;
}
// If none of the above conditions are met, proceed with the default behavior.
return $should_force_login;
}, 10, 4 );
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/buddyboss/buddy-boss-sync.php:38
public function group_created( $group_id, $user_id ) {
if ( true === apply_filters( 'ulgm_group_created_buddyboss_force_login', true, $group_id, $user_id, $this ) ) {
$this->force_login( $user_id );
}
add_filter( 'bp_loggedin_user_id', array( $this, 'bp_loggedin_user_id' ), 99, 1 );
do_action( 'bp_ld_sync/learndash_group_updated', $group_id ); //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
}