ulgm_add_deleted_seats_to_tota_count
Filters the total count, potentially adding deleted seats back for specific group scenarios.
add_filter( 'ulgm_add_deleted_seats_to_tota_count', $callback, 10, 1 );
Description
Filters the total seat count for a group. Developers can use this hook to add or subtract seats from the calculated total. It's important to note that this hook fires after deleted seats have been retrieved but before they are potentially added back to the count.
Usage
add_filter( 'ulgm_add_deleted_seats_to_tota_count', 'your_function_name', 10, 1 );
Parameters
-
$ld_group_id(mixed) - This parameter is a boolean value indicating whether to include deleted seats in the total count.
Return Value
The filtered value.
Examples
add_filter(
'ulgm_add_deleted_seats_to_tota_count',
function( $include_deleted_seats, $ld_group_id ) {
// This filter allows developers to conditionally include deleted seats in the total count.
// For example, we might want to exclude them if a certain user role is logged in,
// or if the group is in a specific status.
// Example: Only include deleted seats if the group is not marked as 'archived'.
// Assuming you have a function to get group meta data.
$group_status = get_post_meta( $ld_group_id, 'group_status', true );
if ( 'archived' === $group_status ) {
return false; // Do not include deleted seats if the group is archived.
}
// If the group is not archived, return the original value (which is usually true).
return $include_deleted_seats;
},
10, // Priority
2 // Number of accepted 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/handlers/class-gm-seat-handler.php:73
src/classes/handlers/class-gm-seat-handler.php:187
public function total_seats( $ld_group_id ) {
global $wpdb;
$group_id = $this->get_code_group_id( $ld_group_id );
if ( empty( $group_id ) || 0 === absint( $group_id ) ) {
return 0;
}
$total_seats = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(ID) FROM {$wpdb->prefix}" . ulgm()->db->tbl_group_codes . ' WHERE group_id = %d', $group_id ) );
$deleted_seats = 0;
if ( true === apply_filters( 'ulgm_add_deleted_seats_to_tota_count', true, $ld_group_id ) ) {
$deleted_seats = $this->deleted_seats( $ld_group_id );
}
return absint( $total_seats ) + $deleted_seats;
}