Action uncanny-learndash-groups

ulgm_seats_removed

Fires after seats are removed from a group, providing the difference, group ID, and code group ID.

add_action( 'ulgm_seats_removed', $callback, 10, 3 );

Description

Fires after seats have been removed from a group, indicating a reduction in allocated seats. Developers can use this action to perform cleanup tasks, log changes, or trigger other related processes based on the number of seats removed and the affected group IDs.


Usage

add_action( 'ulgm_seats_removed', 'your_function_name', 10, 3 );

Parameters

$diff (mixed)
The `$diff` parameter contains the difference in the number of seats allocated to the group before and after the removal.
$group_id (mixed)
This parameter contains the difference in the number of seats between the old and new group configurations, indicating how many seats were removed.
$code_group_id (mixed)
This parameter represents the ID of the group from which seats were removed.

Examples

<?php
/**
 * Hook: ulgm_seats_removed
 * Type: action
 * Parameters:
 * - $diff (mixed): The number of seats that were removed.
 * - $group_id (mixed): The ID of the group from which seats were removed.
 * - $code_group_id (mixed): The ID of the code group associated with the seats.
 */

/**
 * Example callback function for the ulgm_seats_removed action hook.
 *
 * This function demonstrates how to respond when seats are removed from a group.
 * In this example, we'll log the action to the WordPress debug log.
 *
 * @param int $diff The number of seats that were removed.
 * @param int $group_id The ID of the group.
 * @param int $code_group_id The ID of the code group.
 */
function my_custom_ulgm_seats_removed_handler( $diff, $group_id, $code_group_id ) {
    // Ensure we are in a WordPress environment
    if ( ! did_action( 'init' ) ) {
        return;
    }

    // Log the event for debugging or tracking purposes
    if ( WP_DEBUG === true ) {
        error_log( sprintf(
            'ULGM: Seats removed from group ID %d. Number of seats removed: %d. Associated code group ID: %d.',
            $group_id,
            $diff,
            $code_group_id
        ) );
    }

    // You could also perform other actions here, such as:
    // - Sending an email notification to the group administrator.
    // - Updating a custom analytics counter.
    // - Triggering other related processes.
}
add_action( 'ulgm_seats_removed', 'my_custom_ulgm_seats_removed_handler', 10, 3 );

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/class-edit-group-wizard.php:284
src/classes/learndash/learndash-groups-post-edit-additions.php:1052
src/classes/handlers/class-gm-seat-handler.php:283

$fetch_code_count = $wpdb->get_var( $wpdb->prepare( 'SELECT COUNT(code) AS available FROM ' . $wpdb->prefix . SharedFunctions::$db_group_codes_tbl . ' WHERE group_id = %d AND student_id IS NULL LIMIT %d', $code_group_id, $diff ) );
				if ( ! empty( $fetch_code_count ) && $fetch_code_count >= $diff ) {
					//difference seats are empty, lets delete them
					$sql = $wpdb->prepare( 'DELETE FROM ' . $wpdb->prefix . SharedFunctions::$db_group_codes_tbl . ' WHERE group_id = %d AND student_id IS NULL LIMIT %d', $code_group_id, $diff );
					$wpdb->query( $sql );
					update_post_meta( $group_id, '_ulgm_total_seats', $existing_seats - $diff );

					do_action( 'ulgm_seats_removed', $diff, $group_id, $code_group_id );
				}
			} elseif ( $number_of_seats_entered < $combined ) {
				$edit_group_page_url = add_query_arg( 'seat-available-error', 'yes', $edit_group_page_url );
				$redirect            = $edit_group_page_url;
				wp_safe_redirect( $redirect );
				exit;
			}

Scroll to Top