Action uncanny-learndash-groups

bp_ld_sync/learndash_group_updated

Fires when a LearnDash group is updated, allowing integrations to sync associated data.

add_action( 'bp_ld_sync/learndash_group_updated', $callback, 10, 1 );

Description

Fires after a LearnDash group is updated. Developers can use this hook to trigger custom actions, such as synchronizing group data or performing additional updates, when a LearnDash group associated with a BuddyBoss group is modified.


Usage

add_action( 'bp_ld_sync/learndash_group_updated', 'your_function_name', 10, 1 );

Parameters

$group_id (mixed)
This parameter contains the ID of the LearnDash group that was updated.

Examples

add_action( 'bp_ld_sync/learndash_group_updated', 'my_learndash_group_updated_handler', 10, 1 );

/**
 * Handles the event when a LearnDash group is updated via BuddyBoss.
 *
 * This function is triggered by the 'bp_ld_sync/learndash_group_updated' action.
 * It demonstrates how to access the group ID and perform an action, such as
 * syncing group members to LearnDash or updating group-related settings.
 *
 * @param int $group_id The ID of the BuddyBoss group that was updated.
 */
function my_learndash_group_updated_handler( $group_id ) {
	// Ensure the $group_id is a valid integer.
	if ( ! is_numeric( $group_id ) || $group_id <= 0 ) {
		return;
	}

	// Get the BuddyBoss group object.
	$group = groups_get_group( array( 'group_id' => $group_id ) );

	// Check if the group object exists.
	if ( ! $group || is_wp_error( $group ) ) {
		error_log( "BuddyBoss group not found for ID: {$group_id}" );
		return;
	}

	// In a real-world scenario, you might:
	// 1. Fetch associated LearnDash courses for this BuddyBoss group.
	// 2. Get members of the BuddyBoss group.
	// 3. Sync these members with the LearnDash courses (e.g., enroll them).

	// Example: Log a message indicating the group update.
	error_log( "BuddyBoss group updated: '{$group->name}' (ID: {$group_id}). Initiating LearnDash sync." );

	// --- Placeholder for actual LearnDash sync logic ---
	// For example, you might call a function to enroll group members into courses:
	// $this->sync_group_members_to_learndash_courses( $group_id, $group->get_members() );
	// or update course access based on group settings.
	// --- End placeholder ---

	// You could also use a filter to allow other plugins to modify the sync process.
	// For instance, to conditionally prevent the sync for specific groups:
	// if ( apply_filters( 'my_prevent_learndash_group_sync', false, $group_id, $group ) ) {
	//     error_log( "Skipping LearnDash sync for group ID {$group_id} due to filter." );
	//     return;
	// }

	// Further actions based on the updated group can be added here.
}

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:42

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
	}


Scroll to Top