Add WordPress timezone support and fix dashboard phone number display

- Add format_timestamp_with_timezone() helper to convert UTC to WP timezone
- Update all timestamp displays to use WordPress timezone setting
- Fix dashboard showing call SID instead of phone numbers in From field
- Fix dashboard showing "System" instead of actual phone numbers in To field
- Query actual from_number and to_number fields for dashboard display

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-08-13 17:48:28 -07:00
parent 9ccd78c125
commit f84914281d

View File

@@ -32,6 +32,27 @@ class TWP_Admin {
return false; return false;
} }
/**
* Format timestamp with WordPress timezone
*
* @param string $timestamp Database timestamp (assumed to be in UTC)
* @param string $format Date format string
* @return string Formatted date in WordPress timezone
*/
private function format_timestamp_with_timezone($timestamp, $format = 'M j, Y g:i A') {
// Get WordPress timezone
$timezone = wp_timezone();
// Create DateTime object from the UTC timestamp
$date = new DateTime($timestamp, new DateTimeZone('UTC'));
// Convert to WordPress timezone
$date->setTimezone($timezone);
// Return formatted date
return $date->format($format);
}
/** /**
* Register admin menu * Register admin menu
*/ */
@@ -2527,7 +2548,7 @@ class TWP_Admin {
foreach ($recent_calls as $call) { foreach ($recent_calls as $call) {
?> ?>
<tr> <tr>
<td><?php echo esc_html(date('M j, Y g:i A', strtotime($call->created_at))); ?></td> <td><?php echo esc_html($this->format_timestamp_with_timezone($call->created_at)); ?></td>
<td><?php echo esc_html($call->from_number ?: 'N/A'); ?></td> <td><?php echo esc_html($call->from_number ?: 'N/A'); ?></td>
<td><?php echo esc_html($call->to_number ?: 'N/A'); ?></td> <td><?php echo esc_html($call->to_number ?: 'N/A'); ?></td>
<td><?php echo esc_html($call->agent_name ?: 'N/A'); ?></td> <td><?php echo esc_html($call->agent_name ?: 'N/A'); ?></td>
@@ -2651,7 +2672,7 @@ class TWP_Admin {
foreach ($voicemails as $voicemail) { foreach ($voicemails as $voicemail) {
?> ?>
<tr> <tr>
<td><?php echo esc_html(date('M j, Y g:i A', strtotime($voicemail->created_at))); ?></td> <td><?php echo esc_html($this->format_timestamp_with_timezone($voicemail->created_at)); ?></td>
<td><?php echo esc_html($voicemail->from_number); ?></td> <td><?php echo esc_html($voicemail->from_number); ?></td>
<td><?php echo esc_html($voicemail->workflow_name ?: 'N/A'); ?></td> <td><?php echo esc_html($voicemail->workflow_name ?: 'N/A'); ?></td>
<td><?php echo $voicemail->duration ? esc_html($voicemail->duration . 's') : 'Unknown'; ?></td> <td><?php echo $voicemail->duration ? esc_html($voicemail->duration . 's') : 'Unknown'; ?></td>
@@ -2704,7 +2725,7 @@ class TWP_Admin {
foreach ($logs as $log) { foreach ($logs as $log) {
?> ?>
<tr> <tr>
<td><?php echo esc_html(date('M j, Y g:i A', strtotime($log->created_at))); ?></td> <td><?php echo esc_html($this->format_timestamp_with_timezone($log->created_at)); ?></td>
<td><?php echo esc_html($log->from_number ?: 'Unknown'); ?></td> <td><?php echo esc_html($log->from_number ?: 'Unknown'); ?></td>
<td><?php echo esc_html($log->to_number ?: 'System'); ?></td> <td><?php echo esc_html($log->to_number ?: 'System'); ?></td>
<td> <td>
@@ -3391,9 +3412,9 @@ class TWP_Admin {
} }
if ($log_table_exists) { if ($log_table_exists) {
// Get recent calls from last 24 hours // Get recent calls from last 24 hours with phone numbers
$recent_calls = $wpdb->get_results( $recent_calls = $wpdb->get_results(
"SELECT call_sid, status, duration, updated_at "SELECT call_sid, from_number, to_number, status, duration, updated_at
FROM $log_table FROM $log_table
WHERE updated_at >= DATE_SUB(NOW(), INTERVAL 24 HOUR) WHERE updated_at >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
ORDER BY updated_at DESC ORDER BY updated_at DESC
@@ -3407,10 +3428,14 @@ class TWP_Admin {
$formatted_calls = array(); $formatted_calls = array();
foreach ($recent_calls as $call) { foreach ($recent_calls as $call) {
// Format phone numbers for display
$from_display = $call->from_number ?: 'Unknown';
$to_display = $call->to_number ?: 'Unknown';
$formatted_calls[] = array( $formatted_calls[] = array(
'time' => date('H:i', strtotime($call->updated_at)), 'time' => $this->format_timestamp_with_timezone($call->updated_at, 'H:i'),
'from' => substr($call->call_sid, 0, 10) . '...', 'from' => $from_display,
'to' => 'System', 'to' => $to_display,
'status' => ucfirst($call->status), 'status' => ucfirst($call->status),
'duration' => $call->duration ? $call->duration . 's' : '-' 'duration' => $call->duration ? $call->duration . 's' : '-'
); );
@@ -4720,7 +4745,7 @@ class TWP_Admin {
<br><small style="color: #666;">Received on</small> <br><small style="color: #666;">Received on</small>
</td> </td>
<td> <td>
<?php echo esc_html(date('M j, H:i', strtotime($conversation->last_message_time))); ?> <?php echo esc_html($this->format_timestamp_with_timezone($conversation->last_message_time, 'M j, H:i')); ?>
<br> <br>
<small style="color: <?php echo $conversation->last_message_direction === 'incoming' ? '#d63384' : '#0f5132'; ?>;"> <small style="color: <?php echo $conversation->last_message_direction === 'incoming' ? '#d63384' : '#0f5132'; ?>;">
<?php echo $conversation->last_message_direction === 'incoming' ? '← Received' : '→ Sent'; ?> <?php echo $conversation->last_message_direction === 'incoming' ? '← Received' : '→ Sent'; ?>