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