prefix . 'hvac_certificates'; $table_exists = $wpdb->get_var("SHOW TABLES LIKE '$table_name'") === $table_name; if (!$table_exists) { throw new Exception("Certificate database tables are not properly set up."); } // Basic empty stats $certificate_stats = array( 'total' => 0, 'active' => 0, 'revoked' => 0, 'emailed' => 0 ); // Get user's events for filtering $events = get_posts(array( 'post_type' => 'tribe_events', 'posts_per_page' => -1, 'post_status' => 'publish', 'author' => $current_user_id )); // Get basic stats without using the certificate manager class $event_ids = array(); foreach ($events as $event) { $event_ids[] = $event->ID; } if (!empty($event_ids)) { $event_ids_string = implode(',', array_map('intval', $event_ids)); // Only run query if we have events if (!empty($event_ids_string)) { $stats_query = "SELECT COUNT(*) as total, SUM(CASE WHEN revoked = 0 THEN 1 ELSE 0 END) as active, SUM(CASE WHEN revoked = 1 THEN 1 ELSE 0 END) as revoked, SUM(CASE WHEN email_sent = 1 THEN 1 ELSE 0 END) as emailed FROM {$wpdb->prefix}hvac_certificates WHERE event_id IN ($event_ids_string)"; $result = $wpdb->get_row($stats_query); if ($result) { $certificate_stats = array( 'total' => intval($result->total), 'active' => intval($result->active), 'revoked' => intval($result->revoked), 'emailed' => intval($result->emailed) ); } } } // Empty certificates array to start with $certificates = array(); $total_certificates = 0; $total_pages = 0; $page = isset($_GET['certificate_page']) ? absint($_GET['certificate_page']) : 1; $per_page = 20; } catch (Exception $e) { echo '
View and manage all certificates you've generated for event attendees.
No certificates found matching your filters.
0 || (isset($_GET['filter_status']) && $_GET['filter_status'] !== 'active')) : ?>Clear filters to see all your certificates.
Generate certificates for your event attendees on the Generate Certificates page.