-
Notifications
You must be signed in to change notification settings - Fork 15
/
email-logs.class.php
108 lines (84 loc) · 2.7 KB
/
email-logs.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace WPSparkPost;
// If ABSPATH is defined, we assume WP is calling us.
// Otherwise, this could be an illicit direct request.
if (!defined('ABSPATH')) exit();
if (!class_exists('WP_List_Table')) {
require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
}
class SparkPostEmailLogs extends \WP_List_Table
{
function __construct()
{
global $status, $page;
//Set parent defaults
parent::__construct(array(
'singular' => 'log',
'plural' => 'logs',
'ajax' => false
));
}
public static function record_count()
{
global $wpdb;
$sql = "SELECT COUNT(*) FROM {$wpdb->prefix}sp_email_logs";
return $wpdb->get_var($sql);
}
function get_logs($per_page = 10, $page = 1)
{
global $wpdb;
$wpdb->show_errors();
$sql = "SELECT * FROM {$wpdb->prefix}sp_email_logs ORDER BY `created_at` DESC LIMIT $per_page";
$sql .= ' OFFSET ' . ($page - 1) * $per_page;
return $wpdb->get_results($sql, 'ARRAY_A');
}
function get_columns()
{
$columns = [
'subject' => 'Subject',
'wp_mail_args' => 'wp_mail Arguments',
'sent_at' => 'Generated At',
'content' => 'Request Data',
'response' => 'Response Data'
];
return $columns;
}
function column_subject($item)
{
return $item['subject'];
}
function column_sent_at($item)
{
return $item['created_at'];
}
function column_content($item)
{
return '<textarea style="width: 100%" rows="5">' . $item['content'] . '</textarea>';
}
function column_wp_mail_args($item)
{
return '<textarea style="width: 100%" rows="5">' . $item['wp_mail_args'] . '</textarea>';
}
function column_response($item)
{
return '<textarea style="width: 100%" rows="5">' . $item['response'] . '</textarea>';
}
function column_name($item)
{
return $item['name'];
}
function prepare_items()
{
$per_page = 10;
$page = $this->get_pagenum();
$columns = $this->get_columns();
$this->_column_headers = array($columns);
$this->items = $this->get_logs($per_page, $page);
$total_items = $this->record_count();
$this->set_pagination_args(array(
'total_items' => $total_items, //WE have to calculate the total number of items
'per_page' => $per_page, //WE have to determine how many items to show on a page
'total_pages' => ceil($total_items / $per_page) //WE have to calculate the total number of pages
));
}
}