ulgm_reconcile_on_upgrade
Filters whether to perform a reconciliation of user data after an upgrade, allowing control over the process.
add_filter( 'ulgm_reconcile_on_upgrade', $callback, 10, 1 );
Description
Allows developers to control whether group reconciliation occurs after a LearnDash group upgrade. By default, reconciliation is enabled (returns true). Developers can return false to disable it, preventing automatic re-evaluation of group memberships and seat availability during upgrade processes.
Usage
add_filter( 'ulgm_reconcile_on_upgrade', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of using the ulgm_reconcile_on_upgrade filter hook.
*
* This example demonstrates how to conditionally prevent reconciliation
* after a user upgrade if a certain condition is met.
*
* @param bool $reconcile_now Whether to proceed with reconciliation.
* @return bool The modified value indicating whether to reconcile.
*/
add_filter( 'ulgm_reconcile_on_upgrade', function( $reconcile_now ) {
// Let's say we have a custom flag or setting that, if enabled,
// means we don't want to automatically reconcile after an upgrade
// if the group is already full.
$disable_reconciliation_if_full = get_option( 'ulgm_disable_reconcile_if_full', false );
if ( $disable_reconciliation_if_full ) {
// Assuming $group_id is accessible in this context (e.g., passed as another argument if the filter supported it,
// or fetched from global/post data if relevant). For demonstration, we'll simulate it.
// In a real scenario, you'd need to ensure $group_id is available.
// Let's pretend we fetched it from a transient or global.
$group_id = absint( $_POST['group_id'] ?? 0 ); // Example of fetching, adjust as needed.
if ( $group_id > 0 ) {
$total_seats = (int) ulgm()->group_management->seat->total_seats( $group_id );
$enrolled_seats = (int) ulgm()->group_management->count_users_enrolled_in_group( $group_id ) + (int) ulgm()->group_management->users_invited_in_group( $group_id );
// If the group is full, and we have the setting to disable reconciliation, return false.
if ( $enrolled_seats >= $total_seats ) {
return false;
}
}
}
// Otherwise, return the original value, allowing reconciliation.
return $reconcile_now;
}, 10, 1 );
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/admin/migrate-learndash-groups.php:202
$status = SharedFunctions::$not_started_status;
}
Group_Management_Helpers::add_existing_user( $user_data, true, $group_id, $order_id, $status, false, true );
}
// Let's reconcile too
if ( true === apply_filters( 'ulgm_reconcile_on_upgrade', true ) ) {
$total_seats = (int) ulgm()->group_management->seat->total_seats( $group_id );
$remaining_seats = (int) ulgm()->group_management->seat->remaining_seats( $group_id );
$enrolled_seats = (int) ulgm()->group_management->count_users_enrolled_in_group( $group_id ) + (int) ulgm()->group_management->users_invited_in_group( $group_id );
GroupManagementInterface::is_reconcile_required( $group_id, $total_seats, $enrolled_seats, $remaining_seats, true );
}
return true;