|
1
|
|
|
<?php |
|
|
|
|
|
|
2
|
|
|
/** |
|
3
|
|
|
* Payment History Table Class |
|
4
|
|
|
* |
|
5
|
|
|
* @package Give |
|
6
|
|
|
* @subpackage Admin/Payments |
|
7
|
|
|
* @copyright Copyright (c) 2016, Give |
|
8
|
|
|
* @license https://opensource.org/licenses/gpl-license GNU Public License |
|
9
|
|
|
* @since 1.0 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// Exit if accessed directly. |
|
13
|
|
|
if ( ! defined( 'ABSPATH' ) ) { |
|
14
|
|
|
exit; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
// Load WP_List_Table if not loaded. |
|
18
|
|
|
if ( ! class_exists( 'WP_List_Table' ) ) { |
|
19
|
|
|
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Give_Payment_History_Table Class |
|
24
|
|
|
* |
|
25
|
|
|
* Renders the Payment History table on the Payment History page |
|
26
|
|
|
* |
|
27
|
|
|
* @since 1.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
class Give_Payment_History_Table extends WP_List_Table { |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Number of results to show per page |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
* @since 1.0 |
|
36
|
|
|
*/ |
|
37
|
|
|
public $per_page = 30; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* URL of this page |
|
41
|
|
|
* |
|
42
|
|
|
* @var string |
|
43
|
|
|
* @since 1.0.1 |
|
44
|
|
|
*/ |
|
45
|
|
|
public $base_url; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Total number of payments |
|
49
|
|
|
* |
|
50
|
|
|
* @var int |
|
51
|
|
|
* @since 1.0 |
|
52
|
|
|
*/ |
|
53
|
|
|
public $total_count; |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Total number of complete payments |
|
57
|
|
|
* |
|
58
|
|
|
* @var int |
|
59
|
|
|
* @since 1.0 |
|
60
|
|
|
*/ |
|
61
|
|
|
public $complete_count; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Total number of pending payments |
|
65
|
|
|
* |
|
66
|
|
|
* @var int |
|
67
|
|
|
* @since 1.0 |
|
68
|
|
|
*/ |
|
69
|
|
|
public $pending_count; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Total number of processing payments |
|
73
|
|
|
* |
|
74
|
|
|
* @var int |
|
75
|
|
|
* @since 1.8.9 |
|
76
|
|
|
*/ |
|
77
|
|
|
public $processing_count; |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Total number of refunded payments |
|
81
|
|
|
* |
|
82
|
|
|
* @var int |
|
83
|
|
|
* @since 1.0 |
|
84
|
|
|
*/ |
|
85
|
|
|
public $refunded_count; |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Total number of failed payments |
|
89
|
|
|
* |
|
90
|
|
|
* @var int |
|
91
|
|
|
* @since 1.0 |
|
92
|
|
|
*/ |
|
93
|
|
|
public $failed_count; |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Total number of revoked payments |
|
97
|
|
|
* |
|
98
|
|
|
* @var int |
|
99
|
|
|
* @since 1.0 |
|
100
|
|
|
*/ |
|
101
|
|
|
public $revoked_count; |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Total number of cancelled payments |
|
105
|
|
|
* |
|
106
|
|
|
* @var int |
|
107
|
|
|
* @since 1.4 |
|
108
|
|
|
*/ |
|
109
|
|
|
public $cancelled_count; |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Total number of abandoned payments |
|
113
|
|
|
* |
|
114
|
|
|
* @var int |
|
115
|
|
|
* @since 1.6 |
|
116
|
|
|
*/ |
|
117
|
|
|
public $abandoned_count; |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Get things started. |
|
121
|
|
|
* |
|
122
|
|
|
* @since 1.0 |
|
123
|
|
|
* @uses Give_Payment_History_Table::get_payment_counts() |
|
124
|
|
|
* @see WP_List_Table::__construct() |
|
125
|
|
|
*/ |
|
126
|
|
|
public function __construct() { |
|
127
|
|
|
|
|
128
|
|
|
// Set parent defaults. |
|
129
|
|
|
parent::__construct( array( |
|
130
|
|
|
'singular' => give_get_forms_label_singular(), // Singular name of the listed records. |
|
131
|
|
|
'plural' => give_get_forms_label_plural(), // Plural name of the listed records. |
|
132
|
|
|
'ajax' => false, // Does this table support ajax? |
|
133
|
|
|
) ); |
|
134
|
|
|
|
|
135
|
|
|
$this->get_payment_counts(); |
|
136
|
|
|
$this->process_bulk_action(); |
|
137
|
|
|
$this->base_url = admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Add donation search filter. |
|
142
|
|
|
* |
|
143
|
|
|
* @return void |
|
144
|
|
|
*/ |
|
145
|
|
|
public function advanced_filters() { |
|
146
|
|
|
$start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
|
147
|
|
|
$end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : null; |
|
148
|
|
|
$status = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : ''; |
|
149
|
|
|
$donor = isset( $_GET['donor'] ) ? sanitize_text_field( $_GET['donor'] ) : ''; |
|
150
|
|
|
$search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : ''; |
|
151
|
|
|
?> |
|
152
|
|
|
<div id="give-payment-filters"> |
|
153
|
|
|
<span id="give-payment-date-filters"> |
|
154
|
|
|
<label for="start-date" |
|
155
|
|
|
class="give-start-date-label"><?php esc_html_e( 'Start Date:', 'give' ); ?></label> |
|
156
|
|
|
<input type="text" id="start-date" name="start-date" class="give_datepicker" |
|
157
|
|
|
value="<?php echo $start_date; ?>" placeholder="mm/dd/yyyy" /> |
|
158
|
|
|
<label for="end-date" class="give-end-date-label"><?php esc_html_e( 'End Date:', 'give' ); ?></label> |
|
159
|
|
|
<input type="text" id="end-date" name="end-date" class="give_datepicker" |
|
160
|
|
|
value="<?php echo $end_date; ?>" placeholder="mm/dd/yyyy" /> |
|
161
|
|
|
<input type="submit" class="button-secondary" value="<?php esc_attr_e( 'Apply', 'give' ); ?>" /> |
|
162
|
|
|
</span> |
|
163
|
|
|
<?php if ( ! empty( $status ) ) : ?> |
|
164
|
|
|
<input type="hidden" name="status" value="<?php echo esc_attr( $status ); ?>" /> |
|
165
|
|
|
<?php endif; ?> |
|
166
|
|
|
<?php if ( ! empty( $start_date ) || ! empty( $end_date ) || ! empty( $donor )|| ! empty( $search ) ) : ?> |
|
167
|
|
|
<a href="<?php echo admin_url( 'edit.php?post_type=give_forms&page=give-payment-history' ); ?>" |
|
168
|
|
|
class="button-secondary"><?php esc_html_e( 'Clear Filter', 'give' ); ?></a> |
|
169
|
|
|
<?php endif; ?> |
|
170
|
|
|
<?php $this->search_box( esc_html__( 'Search', 'give' ), 'give-payments' ); ?> |
|
171
|
|
|
</div> |
|
172
|
|
|
|
|
173
|
|
|
<?php |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Show the search field |
|
178
|
|
|
* |
|
179
|
|
|
* @since 1.0 |
|
180
|
|
|
* @access public |
|
181
|
|
|
* |
|
182
|
|
|
* @param string $text Label for the search box |
|
183
|
|
|
* @param string $input_id ID of the search box |
|
184
|
|
|
* |
|
185
|
|
|
* @return void |
|
186
|
|
|
*/ |
|
187
|
|
|
public function search_box( $text, $input_id ) { |
|
188
|
|
|
if ( empty( $_REQUEST['s'] ) && ! $this->has_items() ) { |
|
189
|
|
|
return; |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
$input_id = $input_id . '-search-input'; |
|
193
|
|
|
|
|
194
|
|
|
if ( ! empty( $_REQUEST['orderby'] ) ) { |
|
195
|
|
|
echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />'; |
|
196
|
|
|
} |
|
197
|
|
|
if ( ! empty( $_REQUEST['order'] ) ) { |
|
198
|
|
|
echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />'; |
|
199
|
|
|
} |
|
200
|
|
|
?> |
|
201
|
|
|
<p class="search-box" role="search"> |
|
202
|
|
|
<?php |
|
203
|
|
|
/** |
|
204
|
|
|
* Fires in the payment history search box. |
|
205
|
|
|
* |
|
206
|
|
|
* Allows you to add new elements before the search box. |
|
207
|
|
|
* |
|
208
|
|
|
* @since 1.7 |
|
209
|
|
|
*/ |
|
210
|
|
|
do_action( 'give_payment_history_search' ); |
|
211
|
|
|
?> |
|
212
|
|
|
<label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label> |
|
213
|
|
|
<input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" /> |
|
214
|
|
|
<?php submit_button( $text, 'button', false, false, array( |
|
215
|
|
|
'ID' => 'search-submit', |
|
216
|
|
|
) ); ?><br /> |
|
217
|
|
|
</p> |
|
218
|
|
|
<?php |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
/** |
|
222
|
|
|
* Retrieve the view types |
|
223
|
|
|
* |
|
224
|
|
|
* @access public |
|
225
|
|
|
* @since 1.0 |
|
226
|
|
|
* @return array $views All the views available |
|
227
|
|
|
*/ |
|
228
|
|
|
public function get_views() { |
|
229
|
|
|
|
|
230
|
|
|
$current = isset( $_GET['status'] ) ? $_GET['status'] : ''; |
|
231
|
|
|
$total_count = ' <span class="count">(' . $this->total_count . ')</span>'; |
|
232
|
|
|
$complete_count = ' <span class="count">(' . $this->complete_count . ')</span>'; |
|
233
|
|
|
$cancelled_count = ' <span class="count">(' . $this->cancelled_count . ')</span>'; |
|
234
|
|
|
$pending_count = ' <span class="count">(' . $this->pending_count . ')</span>'; |
|
235
|
|
|
$processing_count = ' <span class="count">(' . $this->processing_count . ')</span>'; |
|
236
|
|
|
$refunded_count = ' <span class="count">(' . $this->refunded_count . ')</span>'; |
|
237
|
|
|
$failed_count = ' <span class="count">(' . $this->failed_count . ')</span>'; |
|
238
|
|
|
$abandoned_count = ' <span class="count">(' . $this->abandoned_count . ')</span>'; |
|
239
|
|
|
$revoked_count = ' <span class="count">(' . $this->revoked_count . ')</span>'; |
|
240
|
|
|
|
|
241
|
|
|
$views = array( |
|
242
|
|
|
'all' => sprintf( '<a href="%s"%s>%s</a>', remove_query_arg( array( |
|
243
|
|
|
'status', |
|
244
|
|
|
'paged', |
|
245
|
|
|
) ), $current === 'all' || $current == '' ? ' class="current"' : '', esc_html__( 'All', 'give' ) . $total_count ), |
|
246
|
|
|
'publish' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
247
|
|
|
'status' => 'publish', |
|
248
|
|
|
'paged' => false, |
|
249
|
|
|
) ) ), $current === 'publish' ? ' class="current"' : '', esc_html__( 'Completed', 'give' ) . $complete_count ), |
|
250
|
|
|
'pending' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
251
|
|
|
'status' => 'pending', |
|
252
|
|
|
'paged' => false, |
|
253
|
|
|
) ) ), $current === 'pending' ? ' class="current"' : '', esc_html__( 'Pending', 'give' ) . $pending_count ), |
|
254
|
|
|
'processing' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
255
|
|
|
'status' => 'processing', |
|
256
|
|
|
'paged' => false, |
|
257
|
|
|
) ) ), $current === 'processing' ? ' class="current"' : '', esc_html__( 'Processing', 'give' ) . $processing_count ), |
|
258
|
|
|
'refunded' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
259
|
|
|
'status' => 'refunded', |
|
260
|
|
|
'paged' => false, |
|
261
|
|
|
) ) ), $current === 'refunded' ? ' class="current"' : '', esc_html__( 'Refunded', 'give' ) . $refunded_count ), |
|
262
|
|
|
'revoked' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
263
|
|
|
'status' => 'revoked', |
|
264
|
|
|
'paged' => false, |
|
265
|
|
|
) ) ), $current === 'revoked' ? ' class="current"' : '', esc_html__( 'Revoked', 'give' ) . $revoked_count ), |
|
266
|
|
|
'failed' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
267
|
|
|
'status' => 'failed', |
|
268
|
|
|
'paged' => false, |
|
269
|
|
|
) ) ), $current === 'failed' ? ' class="current"' : '', esc_html__( 'Failed', 'give' ) . $failed_count ), |
|
270
|
|
|
'cancelled' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
271
|
|
|
'status' => 'cancelled', |
|
272
|
|
|
'paged' => false, |
|
273
|
|
|
) ) ), $current === 'cancelled' ? ' class="current"' : '', esc_html__( 'Cancelled', 'give' ) . $cancelled_count ), |
|
274
|
|
|
'abandoned' => sprintf( '<a href="%s"%s>%s</a>', esc_url( add_query_arg( array( |
|
275
|
|
|
'status' => 'abandoned', |
|
276
|
|
|
'paged' => false, |
|
277
|
|
|
) ) ), $current === 'abandoned' ? ' class="current"' : '', esc_html__( 'Abandoned', 'give' ) . $abandoned_count ), |
|
278
|
|
|
); |
|
279
|
|
|
|
|
280
|
|
|
return apply_filters( 'give_payments_table_views', $views ); |
|
281
|
|
|
} |
|
282
|
|
|
|
|
283
|
|
|
/** |
|
284
|
|
|
* Retrieve the table columns |
|
285
|
|
|
* |
|
286
|
|
|
* @access public |
|
287
|
|
|
* @since 1.0 |
|
288
|
|
|
* @return array $columns Array of all the list table columns |
|
289
|
|
|
*/ |
|
290
|
|
|
public function get_columns() { |
|
291
|
|
|
$columns = array( |
|
292
|
|
|
'cb' => '<input type="checkbox" />', // Render a checkbox instead of text. |
|
293
|
|
|
'donation' => esc_html__( 'Donation', 'give' ), |
|
294
|
|
|
'donation_form' => esc_html__( 'Donation Form', 'give' ), |
|
295
|
|
|
'status' => esc_html__( 'Status', 'give' ), |
|
296
|
|
|
'date' => esc_html__( 'Date', 'give' ), |
|
297
|
|
|
'amount' => esc_html__( 'Amount', 'give' ), |
|
298
|
|
|
'details' => esc_html__( 'Details', 'give' ), |
|
299
|
|
|
); |
|
300
|
|
|
|
|
301
|
|
|
return apply_filters( 'give_payments_table_columns', $columns ); |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* Retrieve the table's sortable columns |
|
306
|
|
|
* |
|
307
|
|
|
* @access public |
|
308
|
|
|
* @since 1.0 |
|
309
|
|
|
* @return array Array of all the sortable columns |
|
310
|
|
|
*/ |
|
311
|
|
|
public function get_sortable_columns() { |
|
312
|
|
|
$columns = array( |
|
313
|
|
|
'donation' => array( 'ID', true ), |
|
314
|
|
|
'donation_form' => array( 'donation_form', false ), |
|
315
|
|
|
'status' => array( 'status', false ), |
|
316
|
|
|
'amount' => array( 'amount', false ), |
|
317
|
|
|
'date' => array( 'date', false ), |
|
318
|
|
|
); |
|
319
|
|
|
|
|
320
|
|
|
return apply_filters( 'give_payments_table_sortable_columns', $columns ); |
|
321
|
|
|
} |
|
322
|
|
|
|
|
323
|
|
|
/** |
|
324
|
|
|
* Gets the name of the primary column. |
|
325
|
|
|
* |
|
326
|
|
|
* @since 1.5 |
|
327
|
|
|
* @access protected |
|
328
|
|
|
* |
|
329
|
|
|
* @return string Name of the primary column. |
|
330
|
|
|
*/ |
|
331
|
|
|
protected function get_primary_column_name() { |
|
332
|
|
|
return 'donation'; |
|
333
|
|
|
} |
|
334
|
|
|
|
|
335
|
|
|
/** |
|
336
|
|
|
* This function renders most of the columns in the list table. |
|
337
|
|
|
* |
|
338
|
|
|
* @access public |
|
339
|
|
|
* @since 1.0 |
|
340
|
|
|
* |
|
341
|
|
|
* @param Give_Payment $payment Payment ID. |
|
342
|
|
|
* @param string $column_name The name of the column |
|
343
|
|
|
* |
|
344
|
|
|
* @return string Column Name |
|
345
|
|
|
*/ |
|
346
|
|
|
public function column_default( $payment, $column_name ) { |
|
347
|
|
|
|
|
348
|
|
|
$single_donation_url = esc_url( add_query_arg( 'id', $payment->ID, admin_url( 'edit.php?post_type=give_forms&page=give-payment-history&view=view-payment-details' ) ) ); |
|
349
|
|
|
$row_actions = $this->get_row_actions( $payment ); |
|
350
|
|
|
|
|
351
|
|
|
switch ( $column_name ) { |
|
352
|
|
|
case 'donation' : |
|
353
|
|
|
$value = sprintf( '<a href="%1$s" data-tooltip="%2$s">#%3$s</a> %4$s %5$s<br>', $single_donation_url, sprintf( esc_attr__( 'View Donation #%s', 'give' ), $payment->ID ), $payment->ID, esc_html__( 'by', 'give' ), $this->get_donor( $payment ) ); |
|
354
|
|
|
$value .= $this->get_donor_email( $payment ); |
|
355
|
|
|
$value .= $this->row_actions( $row_actions ); |
|
356
|
|
|
break; |
|
357
|
|
|
|
|
358
|
|
|
case 'amount' : |
|
359
|
|
|
$amount = ! empty( $payment->total ) ? $payment->total : 0; |
|
360
|
|
|
$value = give_currency_filter( give_format_amount( $amount ), give_get_payment_currency_code( $payment->ID ) ); |
|
361
|
|
|
$value .= sprintf( '<br><small>%1$s %2$s</small>', __( 'via', 'give' ), give_get_gateway_admin_label( $payment->gateway ) ); |
|
362
|
|
|
break; |
|
363
|
|
|
|
|
364
|
|
|
case 'donation_form' : |
|
365
|
|
|
$form_title = empty( $payment->form_title ) ? sprintf( __( 'Untitled (#%s)', 'give' ), $payment->form_id ) : $payment->form_title; |
|
366
|
|
|
$value = '<a href="' . admin_url( 'post.php?post=' . $payment->form_id . '&action=edit' ) . '">' . $form_title . '</a>'; |
|
367
|
|
|
$level = give_get_payment_form_title( $payment->meta, true ); |
|
|
|
|
|
|
368
|
|
|
|
|
369
|
|
|
if ( ! empty( $level ) ) { |
|
370
|
|
|
$value .= $level; |
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
break; |
|
374
|
|
|
|
|
375
|
|
|
case 'date' : |
|
376
|
|
|
$date = strtotime( $payment->date ); |
|
377
|
|
|
$value = date_i18n( give_date_format(), $date ); |
|
378
|
|
|
break; |
|
379
|
|
|
|
|
380
|
|
|
case 'status' : |
|
381
|
|
|
$value = $this->get_payment_status( $payment ); |
|
382
|
|
|
break; |
|
383
|
|
|
|
|
384
|
|
|
case 'details' : |
|
385
|
|
|
$value = sprintf( '<div class="give-payment-details-link-wrap"><a href="%1$s" class="give-payment-details-link button button-small" data-tooltip="%2$s" aria-label="%2$s"><span class="dashicons dashicons-visibility"></span></a></div>', $single_donation_url, sprintf( esc_attr__( 'View Donation #%s', 'give' ), $payment->ID ) ); |
|
386
|
|
|
break; |
|
387
|
|
|
|
|
388
|
|
|
default: |
|
389
|
|
|
$value = isset( $payment->$column_name ) ? $payment->$column_name : ''; |
|
390
|
|
|
break; |
|
391
|
|
|
|
|
392
|
|
|
}// End switch(). |
|
|
|
|
|
|
393
|
|
|
|
|
394
|
|
|
return apply_filters( 'give_payments_table_column', $value, $payment->ID, $column_name ); |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
/** |
|
398
|
|
|
* Get donor email html. |
|
399
|
|
|
* |
|
400
|
|
|
* @access public |
|
401
|
|
|
* @since 1.0 |
|
402
|
|
|
* |
|
403
|
|
|
* @param Give_Payment $payment Contains all the data of the payment |
|
404
|
|
|
* |
|
405
|
|
|
* @return string Data shown in the Email column |
|
406
|
|
|
*/ |
|
407
|
|
|
public function get_donor_email( $payment ) { |
|
408
|
|
|
|
|
409
|
|
|
$email = give_get_payment_user_email( $payment->ID ); |
|
410
|
|
|
|
|
411
|
|
|
if ( empty( $email ) ) { |
|
412
|
|
|
$email = esc_html__( '(unknown)', 'give' ); |
|
413
|
|
|
} |
|
414
|
|
|
|
|
415
|
|
|
$value = '<a href="mailto:' . $email . '" data-tooltip="' . esc_attr__( 'Email donor', 'give' ) . '">' . $email . '</a>'; |
|
416
|
|
|
|
|
417
|
|
|
return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'email' ); |
|
418
|
|
|
} |
|
419
|
|
|
|
|
420
|
|
|
/** |
|
421
|
|
|
* Get Row Actions |
|
422
|
|
|
* |
|
423
|
|
|
* @since 1.6 |
|
424
|
|
|
* |
|
425
|
|
|
* @param Give_Payment $payment |
|
426
|
|
|
* |
|
427
|
|
|
* @return array $actions |
|
428
|
|
|
*/ |
|
429
|
|
|
function get_row_actions( $payment ) { |
|
|
|
|
|
|
430
|
|
|
|
|
431
|
|
|
$actions = array(); |
|
432
|
|
|
$email = give_get_payment_user_email( $payment->ID ); |
|
433
|
|
|
|
|
434
|
|
|
// Add search term string back to base URL. |
|
435
|
|
|
$search_terms = ( isset( $_GET['s'] ) ? trim( $_GET['s'] ) : '' ); |
|
436
|
|
|
if ( ! empty( $search_terms ) ) { |
|
437
|
|
|
$this->base_url = add_query_arg( 's', $search_terms, $this->base_url ); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
if ( give_is_payment_complete( $payment->ID ) && ! empty( $email ) ) { |
|
441
|
|
|
|
|
442
|
|
|
$actions['email_links'] = sprintf( '<a class="resend-single-donation-receipt" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( add_query_arg( array( |
|
443
|
|
|
'give-action' => 'email_links', |
|
444
|
|
|
'purchase_id' => $payment->ID, |
|
445
|
|
|
), $this->base_url ), 'give_payment_nonce' ), sprintf( esc_attr__( 'Resend Donation %s Receipt', 'give' ), $payment->ID ), esc_html__( 'Resend Receipt', 'give' ) ); |
|
446
|
|
|
|
|
447
|
|
|
} |
|
448
|
|
|
|
|
449
|
|
|
$actions['delete'] = sprintf( '<a class="delete-single-donation" href="%1$s" aria-label="%2$s">%3$s</a>', wp_nonce_url( add_query_arg( array( |
|
450
|
|
|
'give-action' => 'delete_payment', |
|
451
|
|
|
'purchase_id' => $payment->ID, |
|
452
|
|
|
), $this->base_url ), 'give_donation_nonce' ), sprintf( esc_attr__( 'Delete Donation %s', 'give' ), $payment->ID ), esc_html__( 'Delete', 'give' ) ); |
|
453
|
|
|
|
|
454
|
|
|
return apply_filters( 'give_payment_row_actions', $actions, $payment ); |
|
455
|
|
|
} |
|
456
|
|
|
|
|
457
|
|
|
|
|
458
|
|
|
/** |
|
459
|
|
|
* Get payment status html. |
|
460
|
|
|
* |
|
461
|
|
|
* @access public |
|
462
|
|
|
* @since 1.0 |
|
463
|
|
|
* |
|
464
|
|
|
* @param Give_Payment $payment Contains all the data of the payment |
|
465
|
|
|
* |
|
466
|
|
|
* @return string Data shown in the Email column |
|
467
|
|
|
*/ |
|
468
|
|
|
function get_payment_status( $payment ) { |
|
|
|
|
|
|
469
|
|
|
$value = '<div class="give-donation-status status-' . sanitize_title( give_get_payment_status( $payment, true ) ) . '"><span class="give-donation-status-icon"></span> ' . give_get_payment_status( $payment, true ) . '</div>'; |
|
470
|
|
|
if ( $payment->mode == 'test' ) { |
|
471
|
|
|
$value .= ' <span class="give-item-label give-item-label-orange give-test-mode-transactions-label" data-tooltip="' . esc_attr__( 'This donation was made in test mode.', 'give' ) . '">' . esc_html__( 'Test', 'give' ) . '</span>'; |
|
472
|
|
|
} |
|
473
|
|
|
|
|
474
|
|
|
return $value; |
|
475
|
|
|
} |
|
476
|
|
|
|
|
477
|
|
|
/** |
|
478
|
|
|
* Get checkbox html. |
|
479
|
|
|
* |
|
480
|
|
|
* @access public |
|
481
|
|
|
* @since 1.0 |
|
482
|
|
|
* |
|
483
|
|
|
* @param Give_Payment $payment Contains all the data for the checkbox column. |
|
484
|
|
|
* |
|
485
|
|
|
* @return string Displays a checkbox. |
|
486
|
|
|
*/ |
|
487
|
|
|
public function column_cb( $payment ) { |
|
488
|
|
|
return sprintf( '<input type="checkbox" name="%1$s[]" value="%2$s" />', 'payment', $payment->ID ); |
|
489
|
|
|
} |
|
490
|
|
|
|
|
491
|
|
|
/** |
|
492
|
|
|
* Get payment ID html. |
|
493
|
|
|
* |
|
494
|
|
|
* @access public |
|
495
|
|
|
* @since 1.0 |
|
496
|
|
|
* |
|
497
|
|
|
* @param Give_Payment $payment Contains all the data for the checkbox column. |
|
498
|
|
|
* |
|
499
|
|
|
* @return string Displays a checkbox. |
|
500
|
|
|
*/ |
|
501
|
|
|
public function get_payment_id( $payment ) { |
|
502
|
|
|
return '<span class="give-payment-id">' . give_get_payment_number( $payment->ID ) . '</span>'; |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
/** |
|
506
|
|
|
* Get donor html. |
|
507
|
|
|
* |
|
508
|
|
|
* @access public |
|
509
|
|
|
* @since 1.0 |
|
510
|
|
|
* |
|
511
|
|
|
* @param Give_Payment $payment Contains all the data of the payment |
|
512
|
|
|
* |
|
513
|
|
|
* @return string Data shown in the User column |
|
514
|
|
|
*/ |
|
515
|
|
|
public function get_donor( $payment ) { |
|
516
|
|
|
|
|
517
|
|
|
$donor_id = give_get_payment_donor_id( $payment->ID ); |
|
518
|
|
|
$donor_billing_name = give_get_donor_name_by( $payment->ID, 'donation' ); |
|
519
|
|
|
$donor_name = give_get_donor_name_by( $donor_id, 'donor' ); |
|
520
|
|
|
|
|
521
|
|
|
$value = ''; |
|
522
|
|
|
if ( ! empty( $donor_id ) ) { |
|
523
|
|
|
|
|
524
|
|
|
// Check whether the donor name and WP_User name is same or not. |
|
525
|
|
|
if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
|
526
|
|
|
$value .= $donor_billing_name . ' ('; |
|
527
|
|
|
} |
|
528
|
|
|
|
|
529
|
|
|
$value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-donors&view=overview&id=$donor_id" ) ) . '">' . $donor_name . '</a>'; |
|
530
|
|
|
|
|
531
|
|
|
// Check whether the donor name and WP_User name is same or not. |
|
532
|
|
|
if ( sanitize_title( $donor_billing_name ) != sanitize_title( $donor_name ) ) { |
|
533
|
|
|
$value .= ')'; |
|
534
|
|
|
} |
|
535
|
|
|
} else { |
|
536
|
|
|
$email = give_get_payment_user_email( $payment->ID ); |
|
537
|
|
|
$value .= '<a href="' . esc_url( admin_url( "edit.php?post_type=give_forms&page=give-payment-history&s=$email" ) ) . '">' . esc_html__( '(donor missing)', 'give' ) . '</a>'; |
|
538
|
|
|
} |
|
539
|
|
|
|
|
540
|
|
|
return apply_filters( 'give_payments_table_column', $value, $payment->ID, 'donor' ); |
|
541
|
|
|
} |
|
542
|
|
|
|
|
543
|
|
|
/** |
|
544
|
|
|
* Retrieve the bulk actions |
|
545
|
|
|
* |
|
546
|
|
|
* @access public |
|
547
|
|
|
* @since 1.0 |
|
548
|
|
|
* @return array $actions Array of the bulk actions |
|
549
|
|
|
*/ |
|
550
|
|
|
public function get_bulk_actions() { |
|
551
|
|
|
$actions = array( |
|
552
|
|
|
'delete' => __( 'Delete', 'give' ), |
|
553
|
|
|
'set-status-publish' => __( 'Set To Completed', 'give' ), |
|
554
|
|
|
'set-status-pending' => __( 'Set To Pending', 'give' ), |
|
555
|
|
|
'set-status-processing' => __( 'Set To Processing', 'give' ), |
|
556
|
|
|
'set-status-refunded' => __( 'Set To Refunded', 'give' ), |
|
557
|
|
|
'set-status-revoked' => __( 'Set To Revoked', 'give' ), |
|
558
|
|
|
'set-status-failed' => __( 'Set To Failed', 'give' ), |
|
559
|
|
|
'set-status-cancelled' => __( 'Set To Cancelled', 'give' ), |
|
560
|
|
|
'set-status-abandoned' => __( 'Set To Abandoned', 'give' ), |
|
561
|
|
|
'set-status-preapproval' => __( 'Set To Preapproval', 'give' ), |
|
562
|
|
|
'resend-receipt' => __( 'Resend Email Receipts', 'give' ), |
|
563
|
|
|
); |
|
564
|
|
|
|
|
565
|
|
|
return apply_filters( 'give_payments_table_bulk_actions', $actions ); |
|
566
|
|
|
} |
|
567
|
|
|
|
|
568
|
|
|
/** |
|
569
|
|
|
* Process the bulk actions |
|
570
|
|
|
* |
|
571
|
|
|
* @access public |
|
572
|
|
|
* @since 1.0 |
|
573
|
|
|
* @return void |
|
574
|
|
|
*/ |
|
575
|
|
|
public function process_bulk_action() { |
|
576
|
|
|
$ids = isset( $_GET['payment'] ) ? $_GET['payment'] : false; |
|
577
|
|
|
$action = $this->current_action(); |
|
578
|
|
|
|
|
579
|
|
|
if ( ! is_array( $ids ) ) { |
|
580
|
|
|
$ids = array( $ids ); |
|
581
|
|
|
} |
|
582
|
|
|
|
|
583
|
|
|
if ( empty( $action ) ) { |
|
584
|
|
|
return; |
|
585
|
|
|
} |
|
586
|
|
|
|
|
587
|
|
|
foreach ( $ids as $id ) { |
|
588
|
|
|
|
|
589
|
|
|
// Detect when a bulk action is being triggered. |
|
590
|
|
|
switch ( $this->current_action() ) { |
|
591
|
|
|
|
|
592
|
|
|
case'delete': |
|
593
|
|
|
give_delete_donation( $id ); |
|
594
|
|
|
break; |
|
595
|
|
|
|
|
596
|
|
|
case 'set-status-publish': |
|
597
|
|
|
give_update_payment_status( $id, 'publish' ); |
|
598
|
|
|
break; |
|
599
|
|
|
|
|
600
|
|
|
case 'set-status-pending': |
|
601
|
|
|
give_update_payment_status( $id, 'pending' ); |
|
602
|
|
|
break; |
|
603
|
|
|
|
|
604
|
|
|
case 'set-status-processing': |
|
605
|
|
|
give_update_payment_status( $id, 'processing' ); |
|
606
|
|
|
break; |
|
607
|
|
|
|
|
608
|
|
|
case 'set-status-refunded': |
|
609
|
|
|
give_update_payment_status( $id, 'refunded' ); |
|
610
|
|
|
break; |
|
611
|
|
|
case 'set-status-revoked': |
|
612
|
|
|
give_update_payment_status( $id, 'revoked' ); |
|
613
|
|
|
break; |
|
614
|
|
|
|
|
615
|
|
|
case 'set-status-failed': |
|
616
|
|
|
give_update_payment_status( $id, 'failed' ); |
|
617
|
|
|
break; |
|
618
|
|
|
|
|
619
|
|
|
case 'set-status-cancelled': |
|
620
|
|
|
give_update_payment_status( $id, 'cancelled' ); |
|
621
|
|
|
break; |
|
622
|
|
|
|
|
623
|
|
|
case 'set-status-abandoned': |
|
624
|
|
|
give_update_payment_status( $id, 'abandoned' ); |
|
625
|
|
|
break; |
|
626
|
|
|
|
|
627
|
|
|
case 'set-status-preapproval': |
|
628
|
|
|
give_update_payment_status( $id, 'preapproval' ); |
|
629
|
|
|
break; |
|
630
|
|
|
|
|
631
|
|
|
case 'resend-receipt': |
|
632
|
|
|
give_email_donation_receipt( $id, false ); |
|
633
|
|
|
break; |
|
634
|
|
|
}// End switch(). |
|
|
|
|
|
|
635
|
|
|
|
|
636
|
|
|
/** |
|
637
|
|
|
* Fires after triggering bulk action on payments table. |
|
638
|
|
|
* |
|
639
|
|
|
* @since 1.7 |
|
640
|
|
|
* |
|
641
|
|
|
* @param int $id The ID of the payment. |
|
642
|
|
|
* @param string $current_action The action that is being triggered. |
|
643
|
|
|
*/ |
|
644
|
|
|
do_action( 'give_payments_table_do_bulk_action', $id, $this->current_action() ); |
|
645
|
|
|
}// End foreach(). |
|
|
|
|
|
|
646
|
|
|
|
|
647
|
|
|
} |
|
648
|
|
|
|
|
649
|
|
|
/** |
|
650
|
|
|
* Retrieve the payment counts |
|
651
|
|
|
* |
|
652
|
|
|
* @access public |
|
653
|
|
|
* @since 1.0 |
|
654
|
|
|
* @return void |
|
655
|
|
|
*/ |
|
656
|
|
|
public function get_payment_counts() { |
|
657
|
|
|
|
|
658
|
|
|
$args = array(); |
|
659
|
|
|
|
|
660
|
|
|
if ( isset( $_GET['user'] ) ) { |
|
661
|
|
|
$args['user'] = urldecode( $_GET['user'] ); |
|
662
|
|
|
} elseif ( isset( $_GET['donor'] ) ) { |
|
663
|
|
|
$args['donor'] = absint( $_GET['donor'] ); |
|
664
|
|
|
} elseif ( isset( $_GET['s'] ) ) { |
|
665
|
|
|
$is_user = strpos( $_GET['s'], strtolower( 'user:' ) ) !== false; |
|
666
|
|
|
if ( $is_user ) { |
|
667
|
|
|
$args['user'] = absint( trim( str_replace( 'user:', '', strtolower( $_GET['s'] ) ) ) ); |
|
668
|
|
|
unset( $args['s'] ); |
|
669
|
|
|
} else { |
|
670
|
|
|
$args['s'] = sanitize_text_field( $_GET['s'] ); |
|
671
|
|
|
} |
|
672
|
|
|
} |
|
673
|
|
|
|
|
674
|
|
|
if ( ! empty( $_GET['start-date'] ) ) { |
|
675
|
|
|
$args['start-date'] = urldecode( $_GET['start-date'] ); |
|
676
|
|
|
} |
|
677
|
|
|
|
|
678
|
|
|
if ( ! empty( $_GET['end-date'] ) ) { |
|
679
|
|
|
$args['end-date'] = urldecode( $_GET['end-date'] ); |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
$payment_count = give_count_payments( $args ); |
|
683
|
|
|
$this->complete_count = $payment_count->publish; |
|
684
|
|
|
$this->pending_count = $payment_count->pending; |
|
685
|
|
|
$this->processing_count = $payment_count->processing; |
|
686
|
|
|
$this->refunded_count = $payment_count->refunded; |
|
687
|
|
|
$this->failed_count = $payment_count->failed; |
|
688
|
|
|
$this->revoked_count = $payment_count->revoked; |
|
689
|
|
|
$this->cancelled_count = $payment_count->cancelled; |
|
690
|
|
|
$this->abandoned_count = $payment_count->abandoned; |
|
691
|
|
|
|
|
692
|
|
|
foreach ( $payment_count as $count ) { |
|
693
|
|
|
$this->total_count += $count; |
|
694
|
|
|
} |
|
695
|
|
|
} |
|
696
|
|
|
|
|
697
|
|
|
/** |
|
698
|
|
|
* Retrieve all the data for all the payments. |
|
699
|
|
|
* |
|
700
|
|
|
* @access public |
|
701
|
|
|
* @since 1.0 |
|
702
|
|
|
* @return array objects in array containing all the data for the payments |
|
703
|
|
|
*/ |
|
704
|
|
|
public function payments_data() { |
|
705
|
|
|
|
|
706
|
|
|
$per_page = $this->per_page; |
|
707
|
|
|
$orderby = isset( $_GET['orderby'] ) ? urldecode( $_GET['orderby'] ) : 'ID'; |
|
708
|
|
|
$order = isset( $_GET['order'] ) ? $_GET['order'] : 'DESC'; |
|
709
|
|
|
$user = isset( $_GET['user'] ) ? $_GET['user'] : null; |
|
710
|
|
|
$donor = isset( $_GET['donor'] ) ? $_GET['donor'] : null; |
|
711
|
|
|
$status = isset( $_GET['status'] ) ? $_GET['status'] : give_get_payment_status_keys(); |
|
712
|
|
|
$meta_key = isset( $_GET['meta_key'] ) ? $_GET['meta_key'] : null; |
|
713
|
|
|
$year = isset( $_GET['year'] ) ? $_GET['year'] : null; |
|
714
|
|
|
$month = isset( $_GET['m'] ) ? $_GET['m'] : null; |
|
715
|
|
|
$day = isset( $_GET['day'] ) ? $_GET['day'] : null; |
|
716
|
|
|
$search = isset( $_GET['s'] ) ? sanitize_text_field( $_GET['s'] ) : null; |
|
717
|
|
|
$start_date = isset( $_GET['start-date'] ) ? sanitize_text_field( $_GET['start-date'] ) : null; |
|
718
|
|
|
$end_date = isset( $_GET['end-date'] ) ? sanitize_text_field( $_GET['end-date'] ) : $start_date; |
|
719
|
|
|
|
|
720
|
|
|
if ( ! empty( $search ) ) { |
|
721
|
|
|
$status = 'any'; // Force all payment statuses when searching. |
|
722
|
|
|
} |
|
723
|
|
|
|
|
724
|
|
|
$args = array( |
|
725
|
|
|
'output' => 'payments', |
|
726
|
|
|
'number' => $per_page, |
|
727
|
|
|
'page' => isset( $_GET['paged'] ) ? $_GET['paged'] : null, |
|
728
|
|
|
'orderby' => $orderby, |
|
729
|
|
|
'order' => $order, |
|
730
|
|
|
'user' => $user, |
|
731
|
|
|
'donor' => $donor, |
|
732
|
|
|
'status' => $status, |
|
733
|
|
|
'meta_key' => $meta_key, |
|
734
|
|
|
'year' => $year, |
|
735
|
|
|
'month' => $month, |
|
736
|
|
|
'day' => $day, |
|
737
|
|
|
's' => $search, |
|
738
|
|
|
'start_date' => $start_date, |
|
739
|
|
|
'end_date' => $end_date, |
|
740
|
|
|
); |
|
741
|
|
|
|
|
742
|
|
|
if ( is_string( $search ) && false !== strpos( $search, 'txn:' ) ) { |
|
743
|
|
|
$args['search_in_notes'] = true; |
|
744
|
|
|
$args['s'] = trim( str_replace( 'txn:', '', $args['s'] ) ); |
|
745
|
|
|
} |
|
746
|
|
|
|
|
747
|
|
|
$p_query = new Give_Payments_Query( $args ); |
|
748
|
|
|
|
|
749
|
|
|
return $p_query->get_payments(); |
|
750
|
|
|
|
|
751
|
|
|
} |
|
752
|
|
|
|
|
753
|
|
|
/** |
|
754
|
|
|
* Setup the final data for the table |
|
755
|
|
|
* |
|
756
|
|
|
* @access public |
|
757
|
|
|
* @since 1.0 |
|
758
|
|
|
* @uses Give_Payment_History_Table::get_columns() |
|
759
|
|
|
* @uses Give_Payment_History_Table::get_sortable_columns() |
|
760
|
|
|
* @uses Give_Payment_History_Table::payments_data() |
|
761
|
|
|
* @uses WP_List_Table::get_pagenum() |
|
762
|
|
|
* @uses WP_List_Table::set_pagination_args() |
|
763
|
|
|
* @return void |
|
764
|
|
|
*/ |
|
765
|
|
|
public function prepare_items() { |
|
766
|
|
|
|
|
767
|
|
|
wp_reset_vars( array( 'action', 'payment', 'orderby', 'order', 's' ) ); |
|
768
|
|
|
|
|
769
|
|
|
$columns = $this->get_columns(); |
|
770
|
|
|
$hidden = array(); // No hidden columns. |
|
771
|
|
|
$sortable = $this->get_sortable_columns(); |
|
772
|
|
|
$data = $this->payments_data(); |
|
773
|
|
|
$status = isset( $_GET['status'] ) ? $_GET['status'] : 'any'; |
|
774
|
|
|
|
|
775
|
|
|
$this->_column_headers = array( $columns, $hidden, $sortable ); |
|
776
|
|
|
|
|
777
|
|
|
switch ( $status ) { |
|
778
|
|
|
case 'publish': |
|
779
|
|
|
$total_items = $this->complete_count; |
|
780
|
|
|
break; |
|
781
|
|
|
case 'pending': |
|
782
|
|
|
$total_items = $this->pending_count; |
|
783
|
|
|
break; |
|
784
|
|
|
case 'processing': |
|
785
|
|
|
$total_items = $this->processing_count; |
|
786
|
|
|
break; |
|
787
|
|
|
case 'refunded': |
|
788
|
|
|
$total_items = $this->refunded_count; |
|
789
|
|
|
break; |
|
790
|
|
|
case 'failed': |
|
791
|
|
|
$total_items = $this->failed_count; |
|
792
|
|
|
break; |
|
793
|
|
|
case 'revoked': |
|
794
|
|
|
$total_items = $this->revoked_count; |
|
795
|
|
|
break; |
|
796
|
|
|
case 'cancelled': |
|
797
|
|
|
$total_items = $this->cancelled_count; |
|
798
|
|
|
break; |
|
799
|
|
|
case 'abandoned': |
|
800
|
|
|
$total_items = $this->abandoned_count; |
|
801
|
|
|
break; |
|
802
|
|
|
case 'any': |
|
803
|
|
|
$total_items = $this->total_count; |
|
804
|
|
|
break; |
|
805
|
|
|
default: |
|
806
|
|
|
// Retrieve the count of the non-default-Give status. |
|
807
|
|
|
$count = wp_count_posts( 'give_payment' ); |
|
808
|
|
|
$total_items = isset( $count->{$status} ) ? $count->{$status} : 0; |
|
809
|
|
|
break; |
|
810
|
|
|
} |
|
811
|
|
|
|
|
812
|
|
|
$this->items = $data; |
|
813
|
|
|
|
|
814
|
|
|
$this->set_pagination_args( array( |
|
815
|
|
|
'total_items' => $total_items, |
|
816
|
|
|
// We have to calculate the total number of items. |
|
817
|
|
|
'per_page' => $this->per_page, |
|
818
|
|
|
// We have to determine how many items to show on a page. |
|
819
|
|
|
'total_pages' => ceil( $total_items / $this->per_page ), |
|
820
|
|
|
// We have to calculate the total number of pages. |
|
821
|
|
|
) ); |
|
822
|
|
|
} |
|
823
|
|
|
} |
|
824
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.