check_tables();
if (!$tables_exist) {
echo '
Certificate database tables are not properly set up. Please contact the administrator.
';
return;
}
// Get filtering parameters
$filter_event = isset($_GET['filter_event']) ? absint($_GET['filter_event']) : 0;
$filter_status = isset($_GET['filter_status']) ? sanitize_text_field($_GET['filter_status']) : 'active';
$page = isset($_GET['certificate_page']) ? absint($_GET['certificate_page']) : 1;
$per_page = 20;
// Build filter args
$filter_args = array(
'page' => $page,
'per_page' => $per_page,
'orderby' => 'date_generated',
'order' => 'DESC',
);
// Add event filter if selected
if ($filter_event > 0) {
$filter_args['event_id'] = $filter_event;
}
// Add status filter
if ($filter_status === 'active') {
$filter_args['revoked'] = 0;
} elseif ($filter_status === 'revoked') {
$filter_args['revoked'] = 1;
}
// Default 'all' doesn't add a filter
// Get user's events for filtering using direct database query (bypassing TEC interference)
global $wpdb;
// Build author filter
$author_filter = current_user_can('edit_others_posts') ? '' : 'AND post_author = ' . intval($current_user_id);
// Get events directly from database
$events = $wpdb->get_results(
"SELECT ID, post_title, post_date
FROM {$wpdb->posts}
WHERE post_type = 'tribe_events'
AND post_status = 'publish'
{$author_filter}
ORDER BY post_date DESC"
);
// Check if user has any events
if (empty($events)) {
// No certificates to show since user has no events
$certificates = array();
$total_certificates = 0;
$total_pages = 0;
$certificate_stats = array(
'total' => 0,
'active' => 0,
'revoked' => 0,
'emailed' => 0
);
} else {
// Get certificates for the current user with filters
$certificates = $certificate_manager->get_user_certificates($current_user_id, $filter_args);
// Get total certificate count for pagination
$total_certificates = $certificate_manager->get_user_certificate_count($current_user_id, $filter_args);
$total_pages = ceil($total_certificates / $per_page);
// Get certificate statistics
$certificate_stats = $certificate_manager->get_user_certificate_stats($current_user_id);
}
// Get header and footer
get_header();
} catch (Exception $e) {
echo 'Error initializing certificate system: ' . esc_html($e->getMessage()) . '
';
return;
}
?>
Certificate Listing
No certificates found matching your filters.
0 || $filter_status !== 'active') : ?>
Clear filters to see all your certificates.
Generate certificates for your event attendees on the Generate Certificates page.
| Certificate # |
Event |
Attendee |
Date Generated |
Status |
Actions |
certificate_number;
$event_id = $certificate->event_id;
$attendee_id = $certificate->attendee_id;
$generated_date = date_i18n(get_option('date_format'), strtotime($certificate->date_generated));
$is_revoked = (bool) $certificate->revoked;
$is_emailed = (bool) $certificate->email_sent;
// Get event and attendee information
$event_title = get_the_title($event_id);
$attendee_name = get_post_meta($attendee_id, '_tribe_tickets_full_name', true);
if (empty($attendee_name)) {
$attendee_name = 'Attendee #' . $attendee_id;
}
// Status text and class
$status_text = $is_revoked ? 'Revoked' : 'Active';
$status_class = $is_revoked ? 'hvac-status-revoked' : 'hvac-status-active';
?>
|
|
|
|
revoked_date)) : ?>
revoked_date))); ?>
|
Certificate has been revoked
|
1) : ?>
×
Certificate Preview
admin_url('admin-ajax.php'),
'viewNonce' => wp_create_nonce('hvac_view_certificate'),
'emailNonce' => wp_create_nonce('hvac_email_certificate'),
'revokeNonce' => wp_create_nonce('hvac_revoke_certificate')
));
// Close the try block
get_footer();
?>