|
1
|
|
|
<?php namespace EmailLog\Core\UI\ListTable; |
|
2
|
|
|
|
|
3
|
|
|
use EmailLog\Core\EmailLog as EmailLog; |
|
4
|
|
|
|
|
5
|
2 |
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
|
6
|
|
|
require_once ABSPATH . WPINC . '/class-wp-list-table.php'; |
|
7
|
|
|
} |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Table to display Email Logs. |
|
11
|
|
|
* |
|
12
|
|
|
* Based on Custom List Table Example by Matt Van Andel. |
|
13
|
|
|
*/ |
|
14
|
|
|
class LogListTable extends \WP_List_Table { |
|
15
|
|
|
/** |
|
16
|
|
|
* @var object The page where this table is rendered. |
|
17
|
|
|
* |
|
18
|
|
|
* @since 2.0 |
|
19
|
|
|
*/ |
|
20
|
|
|
protected $page; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Set up a constructor that references the parent constructor. |
|
24
|
|
|
* |
|
25
|
|
|
* We use the parent reference to set some default configs. |
|
26
|
|
|
*/ |
|
27
|
2 |
|
public function __construct( $page, $args = array() ) { |
|
28
|
2 |
|
$this->page = $page; |
|
29
|
|
|
|
|
30
|
2 |
|
$args = wp_parse_args( $args, array( |
|
31
|
2 |
|
'singular' => 'email-log', // singular name of the listed records |
|
32
|
2 |
|
'plural' => 'email-logs', // plural name of the listed records |
|
33
|
2 |
|
'ajax' => false, // does this table support ajax? |
|
34
|
2 |
|
'screen' => $this->page->get_screen(), |
|
35
|
2 |
|
) ); |
|
36
|
|
|
|
|
37
|
2 |
|
parent::__construct( $args ); |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Adds extra markup in the toolbars before or after the list. |
|
42
|
|
|
* |
|
43
|
|
|
* @access protected |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $which Add the markup after (bottom) or before (top) the list. |
|
46
|
|
|
*/ |
|
47
|
|
|
protected function extra_tablenav( $which ) { |
|
48
|
|
|
if ( 'top' == $which ) { |
|
49
|
|
|
// The code that goes before the table is here. |
|
50
|
|
|
echo '<span id = "el-pro-msg">'; |
|
51
|
|
|
_e( 'More fields are available in Pro addon. ', 'email-log' ); |
|
52
|
|
|
echo '<a href = "http://sudarmuthu.com/out/buy-email-log-more-fields-addon" style = "color:red">'; |
|
53
|
|
|
_e( 'Buy Now', 'email-log' ); |
|
54
|
|
|
echo '</a>'; |
|
55
|
|
|
echo '</span>'; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
if ( 'bottom' == $which ) { |
|
59
|
|
|
// The code that goes after the table is here. |
|
60
|
|
|
echo '<p> </p>'; |
|
61
|
|
|
echo '<p> </p>'; |
|
62
|
|
|
|
|
63
|
|
|
echo '<p>'; |
|
64
|
|
|
_e( 'The following are the list of pro addons that are currently available for purchase.', 'email-log' ); |
|
65
|
|
|
echo '</p>'; |
|
66
|
|
|
|
|
67
|
|
|
echo '<ul style="list-style:disc; padding-left:35px">'; |
|
68
|
|
|
|
|
69
|
|
|
echo '<li>'; |
|
70
|
|
|
echo '<strong>', __( 'Email Log - Resend Email', 'email-log' ), '</strong>', ' - '; |
|
71
|
|
|
echo __( 'Adds the ability to resend email from logs.', 'email-log' ); |
|
72
|
|
|
echo ' <a href = "http://sudarmuthu.com/wordpress/email-log/pro-addons#resend-email-addon">', __( 'More Info', 'email-log' ), '</a>.'; |
|
73
|
|
|
echo ' <a href = "http://sudarmuthu.com/out/buy-email-log-resend-email-addon">', __( 'Buy now', 'email-log' ), '</a>'; |
|
74
|
|
|
echo '</li>'; |
|
75
|
|
|
|
|
76
|
|
|
echo '<li>'; |
|
77
|
|
|
echo '<strong>', __( 'Email Log - More fields', 'email-log' ), '</strong>', ' - '; |
|
78
|
|
|
echo __( 'Adds more fields (From, CC, BCC, Reply To, Attachment) to the logs page.', 'email-log' ); |
|
79
|
|
|
echo ' <a href = "http://sudarmuthu.com/wordpress/email-log/pro-addons#more-fields-addon">', __( 'More Info', 'email-log' ), '</a>.'; |
|
80
|
|
|
echo ' <a href = "http://sudarmuthu.com/out/buy-email-log-more-fields-addon">', __( 'Buy now', 'email-log' ), '</a>'; |
|
81
|
|
|
echo '</li>'; |
|
82
|
|
|
|
|
83
|
|
|
echo '<li>'; |
|
84
|
|
|
echo '<strong>', __( 'Email Log - Forward Email', 'email-log' ), '</strong>', ' - '; |
|
85
|
|
|
echo __( 'This addon allows you to send a copy of all emails send from WordPress to another email address', 'email-log' ); |
|
86
|
|
|
echo ' <a href = "http://sudarmuthu.com/wordpress/email-log/pro-addons#forward-email-addon">', __( 'More Info', 'email-log' ), '</a>.'; |
|
87
|
|
|
echo ' <a href = "http://sudarmuthu.com/out/buy-email-log-forward-email-addon">', __( 'Buy now', 'email-log' ), '</a>'; |
|
88
|
|
|
echo '</li>'; |
|
89
|
|
|
|
|
90
|
|
|
echo '</ul>'; |
|
91
|
|
|
} |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Returns the list of column and title names. |
|
96
|
|
|
* |
|
97
|
|
|
* @see WP_List_Table::::single_row_columns() |
|
98
|
|
|
* |
|
99
|
|
|
* @return array An associative array containing column information: 'slugs'=>'Visible Titles'. |
|
100
|
|
|
*/ |
|
101
|
2 |
|
public function get_columns() { |
|
102
|
|
|
$columns = array( |
|
103
|
2 |
|
'cb' => '<input type="checkbox" />', //Render a checkbox instead of text |
|
104
|
2 |
|
'sent_date' => __( 'Sent at', 'email-log' ), |
|
105
|
2 |
|
'to' => __( 'To', 'email-log' ), |
|
106
|
2 |
|
'subject' => __( 'Subject', 'email-log' ), |
|
107
|
2 |
|
); |
|
108
|
|
|
|
|
109
|
2 |
|
return apply_filters( EmailLog::HOOK_LOG_COLUMNS, $columns ); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
/** |
|
113
|
|
|
* Returns the list of columns. |
|
114
|
|
|
* |
|
115
|
|
|
* @access protected |
|
116
|
|
|
* |
|
117
|
|
|
* @return array An associative array containing all the columns that should be sortable: 'slugs'=>array('data_values',bool). |
|
|
|
|
|
|
118
|
|
|
*/ |
|
119
|
|
|
protected function get_sortable_columns() { |
|
120
|
|
|
$sortable_columns = array( |
|
121
|
|
|
'sent_date' => array( 'sent_date', true ), //true means it's already sorted |
|
122
|
|
|
'to' => array( 'to_email', false ), |
|
123
|
|
|
'subject' => array( 'subject', false ), |
|
124
|
|
|
); |
|
125
|
|
|
return $sortable_columns; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Returns value for default columns. |
|
130
|
|
|
* |
|
131
|
|
|
* @access protected |
|
132
|
|
|
* |
|
133
|
|
|
* @param object $item |
|
134
|
|
|
* @param string $column_name |
|
135
|
|
|
*/ |
|
136
|
|
|
protected function column_default( $item, $column_name ) { |
|
137
|
|
|
do_action( EmailLog::HOOK_LOG_DISPLAY_COLUMNS, $column_name, $item ); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Display sent date column. |
|
142
|
|
|
* |
|
143
|
|
|
* @access protected |
|
144
|
|
|
* |
|
145
|
|
|
* @param object $item Current item object. |
|
146
|
|
|
* @return string Markup to be displayed for the column. |
|
147
|
|
|
*/ |
|
148
|
|
|
protected function column_sent_date( $item ) { |
|
149
|
|
|
$email_date = mysql2date( |
|
150
|
|
|
sprintf( __( '%s @ %s', 'email-log' ), get_option( 'date_format', 'F j, Y' ), get_option( 'time_format', 'g:i A' ) ), |
|
151
|
|
|
$item->sent_date |
|
152
|
|
|
); |
|
153
|
|
|
|
|
154
|
|
|
$actions = array(); |
|
155
|
|
|
|
|
156
|
|
|
$content_ajax_url = add_query_arg( |
|
157
|
|
|
array( |
|
158
|
|
|
'action' => 'display_email_message', |
|
159
|
|
|
'log_id' => $item->id, |
|
160
|
|
|
'TB_iframe' => 'true', |
|
161
|
|
|
'width' => '600', |
|
162
|
|
|
'height' => '550', |
|
163
|
|
|
), |
|
164
|
|
|
'admin-ajax.php' |
|
165
|
|
|
); |
|
166
|
|
|
|
|
167
|
|
|
$actions['view-content'] = sprintf( '<a href="%1$s" class="thickbox" title="%2$s">%3$s</a>', |
|
168
|
|
|
esc_url( $content_ajax_url ), |
|
169
|
|
|
__( 'Email Content', 'email-log' ), |
|
170
|
|
|
__( 'View Content', 'email-log' ) |
|
171
|
|
|
); |
|
172
|
|
|
|
|
173
|
|
|
$delete_url = add_query_arg( |
|
174
|
|
|
array( |
|
175
|
|
|
'page' => $_REQUEST['page'], |
|
176
|
|
|
'action' => 'delete', |
|
177
|
|
|
$this->_args['singular'] => $item->id, |
|
178
|
|
|
) |
|
179
|
|
|
); |
|
180
|
|
|
$delete_url = add_query_arg( $this->page->get_nonce_args(), $delete_url ); |
|
181
|
|
|
|
|
182
|
|
|
$actions['delete'] = sprintf( '<a href="%s">%s</a>', |
|
183
|
|
|
esc_url( $delete_url ), |
|
184
|
|
|
__( 'Delete', 'email-log' ) |
|
185
|
|
|
); |
|
186
|
|
|
|
|
187
|
|
|
/** |
|
188
|
|
|
* This filter can be used to modify the list of row actions that are displayed. |
|
189
|
|
|
* |
|
190
|
|
|
* @since 1.8 |
|
191
|
|
|
* |
|
192
|
|
|
* @param array $actions List of actions. |
|
193
|
|
|
* @param object $item The current log item. |
|
194
|
|
|
*/ |
|
195
|
|
|
$actions = apply_filters( 'el_row_actions', $actions, $item ); |
|
196
|
|
|
|
|
197
|
|
|
return sprintf( '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
198
|
|
|
/*$1%s*/ $email_date, |
|
199
|
|
|
/*$2%s*/ $item->id, |
|
200
|
|
|
/*$3%s*/ $this->row_actions( $actions ) |
|
201
|
|
|
); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
/** |
|
205
|
|
|
* To field. |
|
206
|
|
|
* |
|
207
|
|
|
* @access protected |
|
208
|
|
|
* |
|
209
|
|
|
* @param object $item |
|
210
|
|
|
* @return string |
|
211
|
|
|
*/ |
|
212
|
|
|
protected function column_to( $item ) { |
|
213
|
|
|
return esc_html( $item->to_email ); |
|
214
|
|
|
} |
|
215
|
|
|
|
|
216
|
|
|
/** |
|
217
|
|
|
* Subject field. |
|
218
|
|
|
* |
|
219
|
|
|
* @access protected |
|
220
|
|
|
* |
|
221
|
|
|
* @param object $item |
|
222
|
|
|
* @return string |
|
223
|
|
|
*/ |
|
224
|
|
|
protected function column_subject( $item ) { |
|
225
|
|
|
return esc_html( $item->subject ); |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
/** |
|
229
|
|
|
* Markup for action column. |
|
230
|
|
|
* |
|
231
|
|
|
* @access protected |
|
232
|
|
|
* |
|
233
|
|
|
* @param object $item |
|
234
|
|
|
* @return string |
|
235
|
|
|
*/ |
|
236
|
|
|
protected function column_cb( $item ) { |
|
237
|
|
|
return sprintf( |
|
238
|
|
|
'<input type="checkbox" name="%1$s[]" value="%2$s" />', |
|
239
|
|
|
/*$1%s*/ $this->_args['singular'], |
|
240
|
|
|
/*$2%s*/ $item->id |
|
241
|
|
|
); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
/** |
|
245
|
|
|
* Specify the list of bulk actions. |
|
246
|
|
|
* |
|
247
|
|
|
* @access protected |
|
248
|
|
|
* |
|
249
|
|
|
* @return array An associative array containing all the bulk actions: 'slugs'=>'Visible Titles'. |
|
250
|
|
|
*/ |
|
251
|
|
|
protected function get_bulk_actions() { |
|
252
|
|
|
$actions = array( |
|
253
|
|
|
'delete' => __( 'Delete', 'email-log' ), |
|
254
|
|
|
'delete-all' => __( 'Delete All Logs', 'email-log' ), |
|
255
|
|
|
); |
|
256
|
|
|
return $actions; |
|
257
|
|
|
} |
|
258
|
|
|
|
|
259
|
|
|
/** |
|
260
|
|
|
* Handles bulk actions. |
|
261
|
|
|
* |
|
262
|
|
|
* @access protected. |
|
263
|
|
|
*/ |
|
264
|
|
|
protected function process_bulk_action() { |
|
265
|
|
|
if ( 'delete' === $this->current_action() ) { |
|
266
|
|
|
$this->page->delete_logs_by_id( $_GET[ $this->_args['singular'] ] ); |
|
267
|
|
|
} elseif ( 'delete-all' === $this->current_action() ) { |
|
268
|
|
|
$this->page->delete_all_logs(); |
|
269
|
|
|
} |
|
270
|
|
|
} |
|
271
|
|
|
|
|
272
|
|
|
/** |
|
273
|
|
|
* Prepare data for display. |
|
274
|
|
|
*/ |
|
275
|
|
|
public function prepare_items() { |
|
276
|
|
|
$this->_column_headers = $this->get_column_info(); |
|
277
|
|
|
|
|
278
|
|
|
// Handle bulk actions. |
|
279
|
|
|
$this->process_bulk_action(); |
|
280
|
|
|
|
|
281
|
|
|
// Get current page number. |
|
282
|
|
|
$current_page_no = $this->get_pagenum(); |
|
283
|
|
|
$per_page = $this->page->get_per_page(); |
|
284
|
|
|
|
|
285
|
|
|
list( $items, $total_items ) = $this->page->get_table_manager()->fetch_log_items( $_GET, $per_page, $current_page_no ); |
|
286
|
|
|
|
|
287
|
|
|
$this->items = $items; |
|
288
|
|
|
|
|
289
|
|
|
// Register pagination options & calculations. |
|
290
|
|
|
$this->set_pagination_args( array( |
|
291
|
|
|
'total_items' => $total_items, |
|
292
|
|
|
'per_page' => $per_page, |
|
293
|
|
|
'total_pages' => ceil( $total_items / $per_page ), |
|
294
|
|
|
) ); |
|
295
|
|
|
} |
|
296
|
|
|
|
|
297
|
|
|
/** |
|
298
|
|
|
* Displays default message when no items are found. |
|
299
|
|
|
*/ |
|
300
|
|
|
public function no_items() { |
|
301
|
|
|
_e( 'Your email log is empty', 'email-log' ); |
|
302
|
|
|
} |
|
303
|
|
|
} |
|
304
|
|
|
|
This check looks for the generic type
arrayas a return type and suggests a more specific type. This type is inferred from the actual code.