Filter uncanny-learndash-groups

ulgm_is_reconcile_required

Filters whether reconciliation is required for a group, allowing custom logic based on group details and seat availability.

add_filter( 'ulgm_is_reconcile_required', $callback, 10, 5 );

Description

This filter hook `ulgm_is_reconcile_required` determines if a group's seat reconciliation is necessary. Developers can modify the default `true` value to prevent or force reconciliation based on custom logic, group ID, seat counts, or frontend context. It's crucial for managing complex seat allocation scenarios.


Usage

add_filter( 'ulgm_is_reconcile_required', 'your_function_name', 10, 5 );

Parameters

$front_end (mixed)
This parameter is a boolean indicating whether a reconciliation is required, defaulting to true.
$group_id (mixed)
This parameter indicates whether the reconciliation check is being performed on the front-end of the website.
$total_seats (mixed)
This parameter contains the unique identifier for the group being checked.
$enrolled_seats (mixed)
The total number of available seats for the group.
$remaining_seats (mixed)
This parameter represents the number of seats that are currently not occupied within the group.

Return Value

The filtered value.


Examples

/**
 * Example of using the 'ulgm_is_reconcile_required' filter to customize when seat reconciliation is needed.
 *
 * This example will force reconciliation if the group is not in a front-end context
 * and if the enrolled seats are greater than or equal to the total seats,
 * indicating a potential issue even if remaining seats are not zero.
 */
add_filter( 'ulgm_is_reconcile_required', function ( $should_reconcile, $front_end, $group_id, $total_seats, $enrolled_seats, $remaining_seats ) {

    // Only apply custom logic if not in a front-end context.
    if ( ! $front_end ) {
        // If enrolled seats are equal to or exceed total seats, it's a good indicator
        // that reconciliation might be needed to correct discrepancies, even if
        // remaining_seats is technically not zero due to some other calculation.
        if ( $enrolled_seats >= $total_seats ) {
            // We want to force reconciliation in this specific scenario.
            return true;
        }
    }

    // If our custom logic didn't trigger a reconciliation,
    // return the original value passed to the filter.
    return $should_reconcile;
}, 10, 6 );

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/group-management/group-management-interface.php:1133

public static function is_reconcile_required( $group_id, $total_seats, $enrolled_seats, $remaining_seats, $front_end = false ) {
		if ( false === apply_filters( 'ulgm_is_reconcile_required', true, $front_end, $group_id, $total_seats, $enrolled_seats, $remaining_seats ) ) {
			return false;
		}

		if ( SharedFunctions::is_pool_seats_enabled_for_current_parent_group( $group_id ) ) {

			return self::reconcile_pooled_group_seats( $group_id, $total_seats, $enrolled_seats, $remaining_seats );
		}

		if ( ! empty( get_post_meta( $group_id, '_ulgm_seats_before_pooling', true ) ) ) {
			$previous_count = get_post_meta( $group_id, '_ulgm_seats_before_pooling', true );
			$code_group_id  = ulgm()->group_management->seat->get_code_group_id( $group_id );
			LearndashGroupsPostEditAdditions::update_seat_count( $group_id, $code_group_id, $previous_count );
			LearndashGroupsPostEditAdditions::update_user_redeemed_seat_func( $group_id );
			delete_post_meta( $group_id, '_ulgm_seats_before_pooling' );
		}

		if ( ( $remaining_seats === $total_seats ) && $enrolled_seats > 0 ) {
			// remaining seats are equal to total seats but there are users in the group, reconcile!
			$group_leaders = LearndashFunctionOverrides::learndash_get_groups_administrators( $group_id, true );
			$group_users   = LearndashFunctionOverrides::learndash_get_groups_users( $group_id, true );
			LearndashGroupsPostEditAdditions::update_group_seat_counts( $group_id, true, $group_users, $group_leaders );

			return true;
		}

		if ( ( $remaining_seats !== $total_seats ) && ( $enrolled_seats + $remaining_seats ) !== $total_seats ) {
			$group_leaders = LearndashFunctionOverrides::learndash_get_groups_administrators( $group_id, true );
			$group_users   = LearndashFunctionOverrides::learndash_get_groups_users( $group_id, true );
			LearndashGroupsPostEditAdditions::update_group_seat_counts( $group_id, true, $group_users, $group_leaders );

			return true;
		}

		return false;
	}


Scroll to Top