Filter uncanny-learndash-groups

ulgm_group_created_buddyboss_force_logout

Filters whether BuddyBoss users are forced to log out after a group is created.

add_filter( 'ulgm_group_created_buddyboss_force_logout', $callback, 10, 1 );

Description

Filters whether to force a BuddyBoss user logout after a group is created. Return false to prevent logout. Use this to conditionally disable the forced logout behavior based on specific criteria or user roles. This hook fires during the group creation process.


Usage

add_filter( 'ulgm_group_created_buddyboss_force_logout', 'your_function_name', 10, 1 );

Parameters

$this (mixed)
This parameter is a boolean value that determines whether a forced logout should occur.

Return Value

The filtered value.


Examples

/**
 * Example of how to hook into the 'ulgm_group_created_buddyboss_force_logout' filter.
 *
 * This example demonstrates how to prevent the forced logout initiated by the
 * BuddyBoss integration when a user is part of a newly created group.
 *
 * @param bool $force_logout The default value, which is true, indicating a forced logout.
 * @param object $buddyboss_sync_instance The instance of the BuddyBoss sync class.
 * @return bool Returns false to prevent the forced logout, or true to allow it.
 */
add_filter( 'ulgm_group_created_buddyboss_force_logout', function( $force_logout, $buddyboss_sync_instance ) {

	// In this specific example, we want to *prevent* the forced logout
	// if the user is a member of a specific "VIP" group.
	// Replace 'your_vip_group_id' with the actual ID of your VIP group.
	$vip_group_id = 123; // Example VIP group ID

	if ( ! is_user_logged_in() ) {
		return $force_logout; // If not logged in, don't change the filter behavior
	}

	$current_user_id = get_current_user_id();

	// Check if the user is a member of the VIP group
	if ( function_exists( 'groups_is_user_member' ) && groups_is_user_member( $current_user_id, $vip_group_id ) ) {
		// If the user is a VIP, we don't want to force them to log out.
		// So, we return false to override the default 'true' value.
		return false;
	}

	// If the user is not a VIP, or if the group isn't a VIP group,
	// then we allow the default behavior by returning the original value.
	return $force_logout;

}, 10, 2 ); // Priority 10, accepts 2 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/buddyboss/buddy-boss-sync.php:66

public function forced_logout() {
		if ( true !== apply_filters( 'ulgm_group_created_buddyboss_force_logout', true, $this ) ) {
			return;
		}
		if ( is_user_logged_in() ) {

			$user_id          = get_current_user_id();
			$uog_forced_login = get_user_meta( $user_id, 'uog_forced_login', true );
			if ( $uog_forced_login ) {
				wp_logout();
				update_user_meta( $user_id, 'uog_forced_login', 0 );
			}
		}
	}


Scroll to Top