@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | } |
9 | 9 | |
10 | 10 | if ( ! class_exists( 'WP_List_Table' ) ) { |
11 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
11 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -16,479 +16,479 @@ discard block |
||
16 | 16 | */ |
17 | 17 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
18 | 18 | |
19 | - /** |
|
20 | - * URL of this page |
|
21 | - * |
|
22 | - * @var string |
|
23 | - * @since 1.0.19 |
|
24 | - */ |
|
25 | - public $base_url; |
|
26 | - |
|
27 | - /** |
|
28 | - * Query |
|
29 | - * |
|
30 | - * @var GetPaid_Subscriptions_Query |
|
31 | - * @since 1.0.19 |
|
32 | - */ |
|
33 | - public $query; |
|
34 | - |
|
35 | - /** |
|
36 | - * Total subscriptions |
|
37 | - * |
|
38 | - * @var string |
|
39 | - * @since 1.0.0 |
|
40 | - */ |
|
41 | - public $total_count; |
|
42 | - |
|
43 | - /** |
|
44 | - * Current status subscriptions |
|
45 | - * |
|
46 | - * @var string |
|
47 | - * @since 1.0.0 |
|
48 | - */ |
|
49 | - public $current_total_count; |
|
50 | - |
|
51 | - /** |
|
52 | - * Status counts |
|
53 | - * |
|
54 | - * @var array |
|
55 | - * @since 1.0.19 |
|
56 | - */ |
|
57 | - public $status_counts; |
|
58 | - |
|
59 | - /** |
|
60 | - * Number of results to show per page |
|
61 | - * |
|
62 | - * @var int |
|
63 | - * @since 1.0.0 |
|
64 | - */ |
|
65 | - public $per_page = 10; |
|
66 | - |
|
67 | - /** |
|
68 | - * Constructor function. |
|
69 | - */ |
|
70 | - public function __construct() { |
|
71 | - |
|
72 | - parent::__construct( |
|
73 | - array( |
|
74 | - 'singular' => 'subscription', |
|
75 | - 'plural' => 'subscriptions', |
|
76 | - ) |
|
77 | - ); |
|
78 | - |
|
79 | - $this->process_bulk_action(); |
|
80 | - |
|
81 | - $this->prepare_query(); |
|
82 | - |
|
83 | - $this->base_url = remove_query_arg( 'status' ); |
|
84 | - |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Prepares the display query |
|
89 | - */ |
|
90 | - public function prepare_query() { |
|
91 | - |
|
92 | - // Prepare query args. |
|
93 | - $query = array( |
|
94 | - 'number' => $this->per_page, |
|
95 | - 'paged' => $this->get_paged(), |
|
96 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
97 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
98 | - 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
99 | - 'customer_in' => $this->get_user_in(), |
|
100 | - ); |
|
101 | - |
|
102 | - if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
103 | - $this->total_count = 0; |
|
104 | - $this->current_total_count = 0; |
|
105 | - $this->items = array(); |
|
106 | - $this->status_counts = array(); |
|
107 | - return; |
|
108 | - } |
|
109 | - |
|
110 | - // Prepare class properties. |
|
111 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
112 | - $this->total_count = $this->query->get_total(); |
|
113 | - $this->current_total_count = $this->query->get_total(); |
|
114 | - $this->items = $this->query->get_results(); |
|
115 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
116 | - |
|
117 | - if ( 'all' != $query['status'] ) { |
|
118 | - unset( $query['status'] ); |
|
119 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
120 | - } |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get user in. |
|
126 | - * |
|
127 | - */ |
|
128 | - public function get_user_in() { |
|
129 | - |
|
130 | - // Abort if no user. |
|
131 | - if ( empty( $_GET['s'] ) ) { |
|
132 | - return null; |
|
133 | - } |
|
134 | - |
|
135 | - // Or invalid user. |
|
136 | - $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
137 | - |
|
138 | - if ( empty( $user ) ) { |
|
139 | - return null; |
|
140 | - } |
|
141 | - |
|
142 | - // Search matching users. |
|
143 | - $user = '*' . $user . '*'; |
|
144 | - $users = new WP_User_Query( |
|
145 | - array( |
|
146 | - 'fields' => 'ID', |
|
147 | - 'search' => $user, |
|
148 | - 'count_total' => false, |
|
149 | - ) |
|
150 | - ); |
|
151 | - |
|
152 | - return $users->get_results(); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Gets the list of views available on this table. |
|
157 | - * |
|
158 | - * The format is an associative array: |
|
159 | - * - `'id' => 'link'` |
|
160 | - * |
|
161 | - * @since 1.0.0 |
|
162 | - * |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - public function get_views() { |
|
166 | - |
|
167 | - $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
168 | - $views = array( |
|
169 | - |
|
170 | - 'all' => sprintf( |
|
171 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
172 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
173 | - $current === 'all' ? ' class="current"' : '', |
|
174 | - __( 'All', 'invoicing' ), |
|
175 | - $this->total_count |
|
176 | - ), |
|
177 | - |
|
178 | - ); |
|
179 | - |
|
180 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
181 | - |
|
182 | - $views[ $status ] = sprintf( |
|
183 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
184 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
185 | - $current === $status ? ' class="current"' : '', |
|
186 | - esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
187 | - $count |
|
188 | - ); |
|
189 | - |
|
190 | - } |
|
191 | - |
|
192 | - return $views; |
|
193 | - |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Render most columns |
|
198 | - * |
|
199 | - * @access private |
|
200 | - * @since 1.0.0 |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function column_default( $item, $column_name ) { |
|
204 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * This is how checkbox column renders. |
|
209 | - * |
|
210 | - * @param WPInv_Subscription $item |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function column_cb( $item ) { |
|
214 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * Status column |
|
219 | - * |
|
220 | - * @param WPInv_Subscription $item |
|
221 | - * @since 1.0.0 |
|
222 | - * @return string |
|
223 | - */ |
|
224 | - public function column_status( $item ) { |
|
225 | - $extra = $item->has_status( 'expired' ) ? '<small class="text-muted d-block">' . wp_sprintf( _x( 'On: %s', 'Expired On:', 'invoicing' ), getpaid_format_date_value( $item->get_expiration() ) ) . '</small>' : ''; |
|
226 | - |
|
227 | - return $item->get_status_label_html() . $extra; |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Subscription column |
|
232 | - * |
|
233 | - * @param WPInv_Subscription $item |
|
234 | - * @since 1.0.0 |
|
235 | - * @return string |
|
236 | - */ |
|
237 | - public function column_subscription( $item ) { |
|
238 | - |
|
239 | - $username = __( '(Missing User)', 'invoicing' ); |
|
240 | - |
|
241 | - $user = get_userdata( $item->get_customer_id() ); |
|
242 | - $capabilities = wpinv_current_user_can_manage_invoicing(); |
|
243 | - |
|
244 | - if ( $user ) { |
|
245 | - $username = sprintf( |
|
246 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
247 | - absint( $user->ID ), |
|
248 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
249 | - ); |
|
250 | - } |
|
251 | - |
|
252 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
253 | - $column_content = sprintf( |
|
254 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
255 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
256 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
257 | - '</a>', |
|
258 | - $username |
|
259 | - ); |
|
260 | - |
|
261 | - $row_actions = array(); |
|
262 | - |
|
263 | - // View subscription. |
|
264 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
265 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
266 | - |
|
267 | - // View invoice. |
|
268 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
269 | - |
|
270 | - if ( ! empty( $invoice ) ) { |
|
271 | - $invoice_url = get_edit_post_link( $invoice ); |
|
272 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
273 | - } |
|
274 | - |
|
275 | - $delete_url = esc_url( |
|
276 | - wp_nonce_url( |
|
277 | - add_query_arg( |
|
278 | - array( |
|
279 | - 'getpaid-admin-action' => 'subscription_manual_delete', |
|
280 | - 'id' => $item->get_id(), |
|
281 | - ) |
|
282 | - ), |
|
283 | - 'getpaid-nonce', |
|
284 | - 'getpaid-nonce' |
|
285 | - ) |
|
286 | - ); |
|
287 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
288 | - |
|
289 | - if ( ! $capabilities ) { |
|
290 | - $row_actions = array(); |
|
291 | - } |
|
292 | - |
|
293 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
294 | - |
|
295 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
296 | - } |
|
297 | - |
|
298 | - /** |
|
299 | - * Renewal date column |
|
300 | - * |
|
301 | - * @param WPInv_Subscription $item |
|
302 | - * @since 1.0.0 |
|
303 | - * @return string |
|
304 | - */ |
|
305 | - public function column_renewal_date( $item ) { |
|
306 | - if ( $item->has_status( 'active trialling' ) ) { |
|
307 | - $value = getpaid_format_date_value( $item->get_expiration() ); |
|
308 | - } else { |
|
309 | - $value = '-'; |
|
310 | - } |
|
311 | - |
|
312 | - return $value; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Start date column |
|
317 | - * |
|
318 | - * @param WPInv_Subscription $item |
|
319 | - * @since 1.0.0 |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - public function column_start_date( $item ) { |
|
323 | - |
|
324 | - $gateway = $item->get_parent_invoice()->get_gateway_title(); |
|
325 | - |
|
326 | - if ( empty( $gateway ) ) { |
|
327 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
328 | - } |
|
329 | - |
|
330 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
331 | - if ( ! empty( $url ) ) { |
|
332 | - |
|
333 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
334 | - __( 'Via %s', 'invoicing' ), |
|
335 | - '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
336 | - ); |
|
337 | - |
|
338 | - } |
|
339 | - |
|
340 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
341 | - __( 'Via %s', 'invoicing' ), |
|
342 | - '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
343 | - ); |
|
344 | - |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Amount column |
|
349 | - * |
|
350 | - * @param WPInv_Subscription $item |
|
351 | - * @since 1.0.19 |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - public static function column_amount( $item ) { |
|
355 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
356 | - return "<span class='text-muted form-text mt-2 mb-2 ms-1 ml-1'>$amount</span>"; |
|
357 | - } |
|
358 | - |
|
359 | - /** |
|
360 | - * Billing Times column |
|
361 | - * |
|
362 | - * @param WPInv_Subscription $item |
|
363 | - * @since 1.0.0 |
|
364 | - * @return string |
|
365 | - */ |
|
366 | - public function column_renewals( $item ) { |
|
367 | - $max_bills = $item->get_bill_times(); |
|
368 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
369 | - } |
|
370 | - |
|
371 | - /** |
|
372 | - * Product ID column |
|
373 | - * |
|
374 | - * @param WPInv_Subscription $item |
|
375 | - * @since 1.0.0 |
|
376 | - * @return string |
|
377 | - */ |
|
378 | - public function column_item( $item ) { |
|
379 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
380 | - |
|
381 | - if ( empty( $subscription_group ) ) { |
|
382 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
383 | - } |
|
384 | - |
|
385 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
386 | - return implode( ' | ', $markup ); |
|
387 | - |
|
388 | - } |
|
389 | - |
|
390 | - /** |
|
391 | - * Generates the items markup. |
|
392 | - * |
|
393 | - * @param int $item_id |
|
394 | - * @since 1.0.0 |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - public static function generate_item_markup( $item_id ) { |
|
398 | - $item = get_post( $item_id ); |
|
399 | - |
|
400 | - if ( ! empty( $item ) ) { |
|
401 | - $link = get_edit_post_link( $item ); |
|
402 | - $name = esc_html( get_the_title( $item ) ); |
|
403 | - return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$name</a>" : $name; |
|
404 | - } else { |
|
405 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
406 | - } |
|
407 | - |
|
408 | - } |
|
409 | - |
|
410 | - /** |
|
411 | - * Retrieve the current page number |
|
412 | - * |
|
413 | - * @return int |
|
414 | - */ |
|
415 | - public function get_paged() { |
|
416 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
417 | - } |
|
418 | - |
|
419 | - /** |
|
420 | - * Setup the final data for the table |
|
421 | - * |
|
422 | - */ |
|
423 | - public function prepare_items() { |
|
424 | - |
|
425 | - $columns = $this->get_columns(); |
|
426 | - $hidden = array(); |
|
427 | - $sortable = $this->get_sortable_columns(); |
|
428 | - |
|
429 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
430 | - |
|
431 | - $this->set_pagination_args( |
|
432 | - array( |
|
433 | - 'total_items' => $this->current_total_count, |
|
434 | - 'per_page' => $this->per_page, |
|
435 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
436 | - ) |
|
437 | - ); |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Table columns |
|
442 | - * |
|
443 | - * @return array |
|
444 | - */ |
|
445 | - public function get_columns() { |
|
446 | - $columns = array( |
|
447 | - 'cb' => '<input type="checkbox" />', |
|
448 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
449 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
450 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
451 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
452 | - 'item' => __( 'Items', 'invoicing' ), |
|
453 | - 'status' => __( 'Status', 'invoicing' ), |
|
454 | - ); |
|
455 | - |
|
456 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Sortable table columns. |
|
461 | - * |
|
462 | - * @return array |
|
463 | - */ |
|
464 | - public function get_sortable_columns() { |
|
465 | - $sortable = array( |
|
466 | - 'subscription' => array( 'id', true ), |
|
467 | - 'start_date' => array( 'created', true ), |
|
468 | - 'renewal_date' => array( 'expiration', true ), |
|
469 | - 'renewals' => array( 'bill_times', true ), |
|
470 | - 'item' => array( 'product_id', true ), |
|
471 | - 'status' => array( 'status', true ), |
|
472 | - ); |
|
473 | - |
|
474 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Whether the table has items to display or not |
|
479 | - * |
|
480 | - * @return bool |
|
481 | - */ |
|
482 | - public function has_items() { |
|
483 | - return ! empty( $this->current_total_count ); |
|
484 | - } |
|
485 | - |
|
486 | - /** |
|
487 | - * Processes bulk actions. |
|
488 | - * |
|
489 | - */ |
|
490 | - public function process_bulk_action() { |
|
491 | - |
|
492 | - } |
|
19 | + /** |
|
20 | + * URL of this page |
|
21 | + * |
|
22 | + * @var string |
|
23 | + * @since 1.0.19 |
|
24 | + */ |
|
25 | + public $base_url; |
|
26 | + |
|
27 | + /** |
|
28 | + * Query |
|
29 | + * |
|
30 | + * @var GetPaid_Subscriptions_Query |
|
31 | + * @since 1.0.19 |
|
32 | + */ |
|
33 | + public $query; |
|
34 | + |
|
35 | + /** |
|
36 | + * Total subscriptions |
|
37 | + * |
|
38 | + * @var string |
|
39 | + * @since 1.0.0 |
|
40 | + */ |
|
41 | + public $total_count; |
|
42 | + |
|
43 | + /** |
|
44 | + * Current status subscriptions |
|
45 | + * |
|
46 | + * @var string |
|
47 | + * @since 1.0.0 |
|
48 | + */ |
|
49 | + public $current_total_count; |
|
50 | + |
|
51 | + /** |
|
52 | + * Status counts |
|
53 | + * |
|
54 | + * @var array |
|
55 | + * @since 1.0.19 |
|
56 | + */ |
|
57 | + public $status_counts; |
|
58 | + |
|
59 | + /** |
|
60 | + * Number of results to show per page |
|
61 | + * |
|
62 | + * @var int |
|
63 | + * @since 1.0.0 |
|
64 | + */ |
|
65 | + public $per_page = 10; |
|
66 | + |
|
67 | + /** |
|
68 | + * Constructor function. |
|
69 | + */ |
|
70 | + public function __construct() { |
|
71 | + |
|
72 | + parent::__construct( |
|
73 | + array( |
|
74 | + 'singular' => 'subscription', |
|
75 | + 'plural' => 'subscriptions', |
|
76 | + ) |
|
77 | + ); |
|
78 | + |
|
79 | + $this->process_bulk_action(); |
|
80 | + |
|
81 | + $this->prepare_query(); |
|
82 | + |
|
83 | + $this->base_url = remove_query_arg( 'status' ); |
|
84 | + |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Prepares the display query |
|
89 | + */ |
|
90 | + public function prepare_query() { |
|
91 | + |
|
92 | + // Prepare query args. |
|
93 | + $query = array( |
|
94 | + 'number' => $this->per_page, |
|
95 | + 'paged' => $this->get_paged(), |
|
96 | + 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
97 | + 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
98 | + 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
99 | + 'customer_in' => $this->get_user_in(), |
|
100 | + ); |
|
101 | + |
|
102 | + if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
103 | + $this->total_count = 0; |
|
104 | + $this->current_total_count = 0; |
|
105 | + $this->items = array(); |
|
106 | + $this->status_counts = array(); |
|
107 | + return; |
|
108 | + } |
|
109 | + |
|
110 | + // Prepare class properties. |
|
111 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
112 | + $this->total_count = $this->query->get_total(); |
|
113 | + $this->current_total_count = $this->query->get_total(); |
|
114 | + $this->items = $this->query->get_results(); |
|
115 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
116 | + |
|
117 | + if ( 'all' != $query['status'] ) { |
|
118 | + unset( $query['status'] ); |
|
119 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
120 | + } |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get user in. |
|
126 | + * |
|
127 | + */ |
|
128 | + public function get_user_in() { |
|
129 | + |
|
130 | + // Abort if no user. |
|
131 | + if ( empty( $_GET['s'] ) ) { |
|
132 | + return null; |
|
133 | + } |
|
134 | + |
|
135 | + // Or invalid user. |
|
136 | + $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
137 | + |
|
138 | + if ( empty( $user ) ) { |
|
139 | + return null; |
|
140 | + } |
|
141 | + |
|
142 | + // Search matching users. |
|
143 | + $user = '*' . $user . '*'; |
|
144 | + $users = new WP_User_Query( |
|
145 | + array( |
|
146 | + 'fields' => 'ID', |
|
147 | + 'search' => $user, |
|
148 | + 'count_total' => false, |
|
149 | + ) |
|
150 | + ); |
|
151 | + |
|
152 | + return $users->get_results(); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Gets the list of views available on this table. |
|
157 | + * |
|
158 | + * The format is an associative array: |
|
159 | + * - `'id' => 'link'` |
|
160 | + * |
|
161 | + * @since 1.0.0 |
|
162 | + * |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + public function get_views() { |
|
166 | + |
|
167 | + $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
168 | + $views = array( |
|
169 | + |
|
170 | + 'all' => sprintf( |
|
171 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
172 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
173 | + $current === 'all' ? ' class="current"' : '', |
|
174 | + __( 'All', 'invoicing' ), |
|
175 | + $this->total_count |
|
176 | + ), |
|
177 | + |
|
178 | + ); |
|
179 | + |
|
180 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
181 | + |
|
182 | + $views[ $status ] = sprintf( |
|
183 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
184 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
185 | + $current === $status ? ' class="current"' : '', |
|
186 | + esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
187 | + $count |
|
188 | + ); |
|
189 | + |
|
190 | + } |
|
191 | + |
|
192 | + return $views; |
|
193 | + |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Render most columns |
|
198 | + * |
|
199 | + * @access private |
|
200 | + * @since 1.0.0 |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function column_default( $item, $column_name ) { |
|
204 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * This is how checkbox column renders. |
|
209 | + * |
|
210 | + * @param WPInv_Subscription $item |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function column_cb( $item ) { |
|
214 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * Status column |
|
219 | + * |
|
220 | + * @param WPInv_Subscription $item |
|
221 | + * @since 1.0.0 |
|
222 | + * @return string |
|
223 | + */ |
|
224 | + public function column_status( $item ) { |
|
225 | + $extra = $item->has_status( 'expired' ) ? '<small class="text-muted d-block">' . wp_sprintf( _x( 'On: %s', 'Expired On:', 'invoicing' ), getpaid_format_date_value( $item->get_expiration() ) ) . '</small>' : ''; |
|
226 | + |
|
227 | + return $item->get_status_label_html() . $extra; |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Subscription column |
|
232 | + * |
|
233 | + * @param WPInv_Subscription $item |
|
234 | + * @since 1.0.0 |
|
235 | + * @return string |
|
236 | + */ |
|
237 | + public function column_subscription( $item ) { |
|
238 | + |
|
239 | + $username = __( '(Missing User)', 'invoicing' ); |
|
240 | + |
|
241 | + $user = get_userdata( $item->get_customer_id() ); |
|
242 | + $capabilities = wpinv_current_user_can_manage_invoicing(); |
|
243 | + |
|
244 | + if ( $user ) { |
|
245 | + $username = sprintf( |
|
246 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
247 | + absint( $user->ID ), |
|
248 | + ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
249 | + ); |
|
250 | + } |
|
251 | + |
|
252 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
253 | + $column_content = sprintf( |
|
254 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
255 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
256 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
257 | + '</a>', |
|
258 | + $username |
|
259 | + ); |
|
260 | + |
|
261 | + $row_actions = array(); |
|
262 | + |
|
263 | + // View subscription. |
|
264 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
265 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
266 | + |
|
267 | + // View invoice. |
|
268 | + $invoice = get_post( $item->get_parent_invoice_id() ); |
|
269 | + |
|
270 | + if ( ! empty( $invoice ) ) { |
|
271 | + $invoice_url = get_edit_post_link( $invoice ); |
|
272 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
273 | + } |
|
274 | + |
|
275 | + $delete_url = esc_url( |
|
276 | + wp_nonce_url( |
|
277 | + add_query_arg( |
|
278 | + array( |
|
279 | + 'getpaid-admin-action' => 'subscription_manual_delete', |
|
280 | + 'id' => $item->get_id(), |
|
281 | + ) |
|
282 | + ), |
|
283 | + 'getpaid-nonce', |
|
284 | + 'getpaid-nonce' |
|
285 | + ) |
|
286 | + ); |
|
287 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
288 | + |
|
289 | + if ( ! $capabilities ) { |
|
290 | + $row_actions = array(); |
|
291 | + } |
|
292 | + |
|
293 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
294 | + |
|
295 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
296 | + } |
|
297 | + |
|
298 | + /** |
|
299 | + * Renewal date column |
|
300 | + * |
|
301 | + * @param WPInv_Subscription $item |
|
302 | + * @since 1.0.0 |
|
303 | + * @return string |
|
304 | + */ |
|
305 | + public function column_renewal_date( $item ) { |
|
306 | + if ( $item->has_status( 'active trialling' ) ) { |
|
307 | + $value = getpaid_format_date_value( $item->get_expiration() ); |
|
308 | + } else { |
|
309 | + $value = '-'; |
|
310 | + } |
|
311 | + |
|
312 | + return $value; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Start date column |
|
317 | + * |
|
318 | + * @param WPInv_Subscription $item |
|
319 | + * @since 1.0.0 |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + public function column_start_date( $item ) { |
|
323 | + |
|
324 | + $gateway = $item->get_parent_invoice()->get_gateway_title(); |
|
325 | + |
|
326 | + if ( empty( $gateway ) ) { |
|
327 | + return getpaid_format_date_value( $item->get_date_created() ); |
|
328 | + } |
|
329 | + |
|
330 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
331 | + if ( ! empty( $url ) ) { |
|
332 | + |
|
333 | + return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
334 | + __( 'Via %s', 'invoicing' ), |
|
335 | + '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
336 | + ); |
|
337 | + |
|
338 | + } |
|
339 | + |
|
340 | + return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
341 | + __( 'Via %s', 'invoicing' ), |
|
342 | + '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
343 | + ); |
|
344 | + |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Amount column |
|
349 | + * |
|
350 | + * @param WPInv_Subscription $item |
|
351 | + * @since 1.0.19 |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + public static function column_amount( $item ) { |
|
355 | + $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
356 | + return "<span class='text-muted form-text mt-2 mb-2 ms-1 ml-1'>$amount</span>"; |
|
357 | + } |
|
358 | + |
|
359 | + /** |
|
360 | + * Billing Times column |
|
361 | + * |
|
362 | + * @param WPInv_Subscription $item |
|
363 | + * @since 1.0.0 |
|
364 | + * @return string |
|
365 | + */ |
|
366 | + public function column_renewals( $item ) { |
|
367 | + $max_bills = $item->get_bill_times(); |
|
368 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
369 | + } |
|
370 | + |
|
371 | + /** |
|
372 | + * Product ID column |
|
373 | + * |
|
374 | + * @param WPInv_Subscription $item |
|
375 | + * @since 1.0.0 |
|
376 | + * @return string |
|
377 | + */ |
|
378 | + public function column_item( $item ) { |
|
379 | + $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
380 | + |
|
381 | + if ( empty( $subscription_group ) ) { |
|
382 | + return $this->generate_item_markup( $item->get_product_id() ); |
|
383 | + } |
|
384 | + |
|
385 | + $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
386 | + return implode( ' | ', $markup ); |
|
387 | + |
|
388 | + } |
|
389 | + |
|
390 | + /** |
|
391 | + * Generates the items markup. |
|
392 | + * |
|
393 | + * @param int $item_id |
|
394 | + * @since 1.0.0 |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + public static function generate_item_markup( $item_id ) { |
|
398 | + $item = get_post( $item_id ); |
|
399 | + |
|
400 | + if ( ! empty( $item ) ) { |
|
401 | + $link = get_edit_post_link( $item ); |
|
402 | + $name = esc_html( get_the_title( $item ) ); |
|
403 | + return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$name</a>" : $name; |
|
404 | + } else { |
|
405 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
406 | + } |
|
407 | + |
|
408 | + } |
|
409 | + |
|
410 | + /** |
|
411 | + * Retrieve the current page number |
|
412 | + * |
|
413 | + * @return int |
|
414 | + */ |
|
415 | + public function get_paged() { |
|
416 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
417 | + } |
|
418 | + |
|
419 | + /** |
|
420 | + * Setup the final data for the table |
|
421 | + * |
|
422 | + */ |
|
423 | + public function prepare_items() { |
|
424 | + |
|
425 | + $columns = $this->get_columns(); |
|
426 | + $hidden = array(); |
|
427 | + $sortable = $this->get_sortable_columns(); |
|
428 | + |
|
429 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
430 | + |
|
431 | + $this->set_pagination_args( |
|
432 | + array( |
|
433 | + 'total_items' => $this->current_total_count, |
|
434 | + 'per_page' => $this->per_page, |
|
435 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
436 | + ) |
|
437 | + ); |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Table columns |
|
442 | + * |
|
443 | + * @return array |
|
444 | + */ |
|
445 | + public function get_columns() { |
|
446 | + $columns = array( |
|
447 | + 'cb' => '<input type="checkbox" />', |
|
448 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
449 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
450 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
451 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
452 | + 'item' => __( 'Items', 'invoicing' ), |
|
453 | + 'status' => __( 'Status', 'invoicing' ), |
|
454 | + ); |
|
455 | + |
|
456 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Sortable table columns. |
|
461 | + * |
|
462 | + * @return array |
|
463 | + */ |
|
464 | + public function get_sortable_columns() { |
|
465 | + $sortable = array( |
|
466 | + 'subscription' => array( 'id', true ), |
|
467 | + 'start_date' => array( 'created', true ), |
|
468 | + 'renewal_date' => array( 'expiration', true ), |
|
469 | + 'renewals' => array( 'bill_times', true ), |
|
470 | + 'item' => array( 'product_id', true ), |
|
471 | + 'status' => array( 'status', true ), |
|
472 | + ); |
|
473 | + |
|
474 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Whether the table has items to display or not |
|
479 | + * |
|
480 | + * @return bool |
|
481 | + */ |
|
482 | + public function has_items() { |
|
483 | + return ! empty( $this->current_total_count ); |
|
484 | + } |
|
485 | + |
|
486 | + /** |
|
487 | + * Processes bulk actions. |
|
488 | + * |
|
489 | + */ |
|
490 | + public function process_bulk_action() { |
|
491 | + |
|
492 | + } |
|
493 | 493 | |
494 | 494 | } |
@@ -3,11 +3,11 @@ discard block |
||
3 | 3 | * Displays a list of all subscriptions rules |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
6 | +if (!defined('ABSPATH')) { |
|
7 | 7 | exit; |
8 | 8 | } |
9 | 9 | |
10 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
10 | +if (!class_exists('WP_List_Table')) { |
|
11 | 11 | include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
12 | 12 | } |
13 | 13 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | |
81 | 81 | $this->prepare_query(); |
82 | 82 | |
83 | - $this->base_url = remove_query_arg( 'status' ); |
|
83 | + $this->base_url = remove_query_arg('status'); |
|
84 | 84 | |
85 | 85 | } |
86 | 86 | |
@@ -93,13 +93,13 @@ discard block |
||
93 | 93 | $query = array( |
94 | 94 | 'number' => $this->per_page, |
95 | 95 | 'paged' => $this->get_paged(), |
96 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? sanitize_text_field( $_GET['status'] ) : 'all', |
|
97 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? sanitize_text_field( $_GET['orderby'] ) : 'id', |
|
98 | - 'order' => ( isset( $_GET['order'] ) ) ? sanitize_text_field( $_GET['order'] ) : 'DESC', |
|
96 | + 'status' => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? sanitize_text_field($_GET['status']) : 'all', |
|
97 | + 'orderby' => (isset($_GET['orderby'])) ? sanitize_text_field($_GET['orderby']) : 'id', |
|
98 | + 'order' => (isset($_GET['order'])) ? sanitize_text_field($_GET['order']) : 'DESC', |
|
99 | 99 | 'customer_in' => $this->get_user_in(), |
100 | 100 | ); |
101 | 101 | |
102 | - if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
102 | + if (is_array($query['customer_in']) && empty($query['customer_in'])) { |
|
103 | 103 | $this->total_count = 0; |
104 | 104 | $this->current_total_count = 0; |
105 | 105 | $this->items = array(); |
@@ -108,15 +108,15 @@ discard block |
||
108 | 108 | } |
109 | 109 | |
110 | 110 | // Prepare class properties. |
111 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
111 | + $this->query = new GetPaid_Subscriptions_Query($query); |
|
112 | 112 | $this->total_count = $this->query->get_total(); |
113 | 113 | $this->current_total_count = $this->query->get_total(); |
114 | 114 | $this->items = $this->query->get_results(); |
115 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
115 | + $this->status_counts = getpaid_get_subscription_status_counts($query); |
|
116 | 116 | |
117 | - if ( 'all' != $query['status'] ) { |
|
118 | - unset( $query['status'] ); |
|
119 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
117 | + if ('all' != $query['status']) { |
|
118 | + unset($query['status']); |
|
119 | + $this->total_count = getpaid_get_subscriptions($query, 'count'); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | } |
@@ -128,14 +128,14 @@ discard block |
||
128 | 128 | public function get_user_in() { |
129 | 129 | |
130 | 130 | // Abort if no user. |
131 | - if ( empty( $_GET['s'] ) ) { |
|
131 | + if (empty($_GET['s'])) { |
|
132 | 132 | return null; |
133 | 133 | } |
134 | 134 | |
135 | 135 | // Or invalid user. |
136 | - $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
136 | + $user = wp_unslash(sanitize_text_field($_REQUEST['s'])); |
|
137 | 137 | |
138 | - if ( empty( $user ) ) { |
|
138 | + if (empty($user)) { |
|
139 | 139 | return null; |
140 | 140 | } |
141 | 141 | |
@@ -164,26 +164,26 @@ discard block |
||
164 | 164 | */ |
165 | 165 | public function get_views() { |
166 | 166 | |
167 | - $current = isset( $_GET['status'] ) ? sanitize_text_field( $_GET['status'] ) : 'all'; |
|
167 | + $current = isset($_GET['status']) ? sanitize_text_field($_GET['status']) : 'all'; |
|
168 | 168 | $views = array( |
169 | 169 | |
170 | 170 | 'all' => sprintf( |
171 | 171 | '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
172 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
172 | + esc_url(add_query_arg('status', false, $this->base_url)), |
|
173 | 173 | $current === 'all' ? ' class="current"' : '', |
174 | - __( 'All', 'invoicing' ), |
|
174 | + __('All', 'invoicing'), |
|
175 | 175 | $this->total_count |
176 | 176 | ), |
177 | 177 | |
178 | 178 | ); |
179 | 179 | |
180 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
180 | + foreach (array_filter($this->status_counts) as $status => $count) { |
|
181 | 181 | |
182 | - $views[ $status ] = sprintf( |
|
182 | + $views[$status] = sprintf( |
|
183 | 183 | '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
184 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
184 | + esc_url(add_query_arg('status', urlencode($status), $this->base_url)), |
|
185 | 185 | $current === $status ? ' class="current"' : '', |
186 | - esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
186 | + esc_html(getpaid_get_subscription_status_label($status)), |
|
187 | 187 | $count |
188 | 188 | ); |
189 | 189 | |
@@ -200,8 +200,8 @@ discard block |
||
200 | 200 | * @since 1.0.0 |
201 | 201 | * @return string |
202 | 202 | */ |
203 | - public function column_default( $item, $column_name ) { |
|
204 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
203 | + public function column_default($item, $column_name) { |
|
204 | + return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name); |
|
205 | 205 | } |
206 | 206 | |
207 | 207 | /** |
@@ -210,8 +210,8 @@ discard block |
||
210 | 210 | * @param WPInv_Subscription $item |
211 | 211 | * @return string |
212 | 212 | */ |
213 | - public function column_cb( $item ) { |
|
214 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
213 | + public function column_cb($item) { |
|
214 | + return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id())); |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | /** |
@@ -221,8 +221,8 @@ discard block |
||
221 | 221 | * @since 1.0.0 |
222 | 222 | * @return string |
223 | 223 | */ |
224 | - public function column_status( $item ) { |
|
225 | - $extra = $item->has_status( 'expired' ) ? '<small class="text-muted d-block">' . wp_sprintf( _x( 'On: %s', 'Expired On:', 'invoicing' ), getpaid_format_date_value( $item->get_expiration() ) ) . '</small>' : ''; |
|
224 | + public function column_status($item) { |
|
225 | + $extra = $item->has_status('expired') ? '<small class="text-muted d-block">' . wp_sprintf(_x('On: %s', 'Expired On:', 'invoicing'), getpaid_format_date_value($item->get_expiration())) . '</small>' : ''; |
|
226 | 226 | |
227 | 227 | return $item->get_status_label_html() . $extra; |
228 | 228 | } |
@@ -234,26 +234,26 @@ discard block |
||
234 | 234 | * @since 1.0.0 |
235 | 235 | * @return string |
236 | 236 | */ |
237 | - public function column_subscription( $item ) { |
|
237 | + public function column_subscription($item) { |
|
238 | 238 | |
239 | - $username = __( '(Missing User)', 'invoicing' ); |
|
239 | + $username = __('(Missing User)', 'invoicing'); |
|
240 | 240 | |
241 | - $user = get_userdata( $item->get_customer_id() ); |
|
241 | + $user = get_userdata($item->get_customer_id()); |
|
242 | 242 | $capabilities = wpinv_current_user_can_manage_invoicing(); |
243 | 243 | |
244 | - if ( $user ) { |
|
244 | + if ($user) { |
|
245 | 245 | $username = sprintf( |
246 | 246 | '<a href="user-edit.php?user_id=%s">%s</a>', |
247 | - absint( $user->ID ), |
|
248 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
247 | + absint($user->ID), |
|
248 | + !empty($user->display_name) ? esc_html($user->display_name) : sanitize_email($user->user_email) |
|
249 | 249 | ); |
250 | 250 | } |
251 | 251 | |
252 | 252 | // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
253 | 253 | $column_content = sprintf( |
254 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
255 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
256 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', |
|
254 | + _x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'), |
|
255 | + '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">', |
|
256 | + '<strong>' . esc_attr($item->get_id()) . '</strong>', |
|
257 | 257 | '</a>', |
258 | 258 | $username |
259 | 259 | ); |
@@ -261,18 +261,18 @@ discard block |
||
261 | 261 | $row_actions = array(); |
262 | 262 | |
263 | 263 | // View subscription. |
264 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ) ); |
|
265 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
264 | + $view_url = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions'))); |
|
265 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>'; |
|
266 | 266 | |
267 | 267 | // View invoice. |
268 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
268 | + $invoice = get_post($item->get_parent_invoice_id()); |
|
269 | 269 | |
270 | - if ( ! empty( $invoice ) ) { |
|
271 | - $invoice_url = get_edit_post_link( $invoice ); |
|
272 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
270 | + if (!empty($invoice)) { |
|
271 | + $invoice_url = get_edit_post_link($invoice); |
|
272 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __('View Invoice', 'invoicing') . '</a>'; |
|
273 | 273 | } |
274 | 274 | |
275 | - $delete_url = esc_url( |
|
275 | + $delete_url = esc_url( |
|
276 | 276 | wp_nonce_url( |
277 | 277 | add_query_arg( |
278 | 278 | array( |
@@ -284,15 +284,15 @@ discard block |
||
284 | 284 | 'getpaid-nonce' |
285 | 285 | ) |
286 | 286 | ); |
287 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
287 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __('Delete Subscription', 'invoicing') . '</a>'; |
|
288 | 288 | |
289 | - if ( ! $capabilities ) { |
|
289 | + if (!$capabilities) { |
|
290 | 290 | $row_actions = array(); |
291 | 291 | } |
292 | 292 | |
293 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
293 | + $row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item)); |
|
294 | 294 | |
295 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
295 | + return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions; |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | /** |
@@ -302,9 +302,9 @@ discard block |
||
302 | 302 | * @since 1.0.0 |
303 | 303 | * @return string |
304 | 304 | */ |
305 | - public function column_renewal_date( $item ) { |
|
306 | - if ( $item->has_status( 'active trialling' ) ) { |
|
307 | - $value = getpaid_format_date_value( $item->get_expiration() ); |
|
305 | + public function column_renewal_date($item) { |
|
306 | + if ($item->has_status('active trialling')) { |
|
307 | + $value = getpaid_format_date_value($item->get_expiration()); |
|
308 | 308 | } else { |
309 | 309 | $value = '-'; |
310 | 310 | } |
@@ -319,27 +319,27 @@ discard block |
||
319 | 319 | * @since 1.0.0 |
320 | 320 | * @return string |
321 | 321 | */ |
322 | - public function column_start_date( $item ) { |
|
322 | + public function column_start_date($item) { |
|
323 | 323 | |
324 | 324 | $gateway = $item->get_parent_invoice()->get_gateway_title(); |
325 | 325 | |
326 | - if ( empty( $gateway ) ) { |
|
327 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
326 | + if (empty($gateway)) { |
|
327 | + return getpaid_format_date_value($item->get_date_created()); |
|
328 | 328 | } |
329 | 329 | |
330 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
331 | - if ( ! empty( $url ) ) { |
|
330 | + $url = apply_filters('getpaid_remote_subscription_profile_url', '', $item); |
|
331 | + if (!empty($url)) { |
|
332 | 332 | |
333 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
334 | - __( 'Via %s', 'invoicing' ), |
|
335 | - '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
333 | + return getpaid_format_date_value($item->get_date_created()) . '<br>' . sprintf( |
|
334 | + __('Via %s', 'invoicing'), |
|
335 | + '<strong><a href="' . esc_url($url) . '" target="_blank">' . esc_html($item->get_parent_invoice()->get_gateway_title()) . '</a></strong>' |
|
336 | 336 | ); |
337 | 337 | |
338 | 338 | } |
339 | 339 | |
340 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
341 | - __( 'Via %s', 'invoicing' ), |
|
342 | - '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
340 | + return getpaid_format_date_value($item->get_date_created()) . '<br>' . sprintf( |
|
341 | + __('Via %s', 'invoicing'), |
|
342 | + '<strong>' . esc_html($item->get_parent_invoice()->get_gateway_title()) . '</strong>' |
|
343 | 343 | ); |
344 | 344 | |
345 | 345 | } |
@@ -351,8 +351,8 @@ discard block |
||
351 | 351 | * @since 1.0.19 |
352 | 352 | * @return string |
353 | 353 | */ |
354 | - public static function column_amount( $item ) { |
|
355 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
354 | + public static function column_amount($item) { |
|
355 | + $amount = getpaid_get_formatted_subscription_amount($item); |
|
356 | 356 | return "<span class='text-muted form-text mt-2 mb-2 ms-1 ml-1'>$amount</span>"; |
357 | 357 | } |
358 | 358 | |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | * @since 1.0.0 |
364 | 364 | * @return string |
365 | 365 | */ |
366 | - public function column_renewals( $item ) { |
|
366 | + public function column_renewals($item) { |
|
367 | 367 | $max_bills = $item->get_bill_times(); |
368 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? '∞' : $max_bills ); |
|
368 | + return $item->get_times_billed() . ' / ' . (empty($max_bills) ? '∞' : $max_bills); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | /** |
@@ -375,15 +375,15 @@ discard block |
||
375 | 375 | * @since 1.0.0 |
376 | 376 | * @return string |
377 | 377 | */ |
378 | - public function column_item( $item ) { |
|
379 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
378 | + public function column_item($item) { |
|
379 | + $subscription_group = getpaid_get_invoice_subscription_group($item->get_parent_invoice_id(), $item->get_id()); |
|
380 | 380 | |
381 | - if ( empty( $subscription_group ) ) { |
|
382 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
381 | + if (empty($subscription_group)) { |
|
382 | + return $this->generate_item_markup($item->get_product_id()); |
|
383 | 383 | } |
384 | 384 | |
385 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
386 | - return implode( ' | ', $markup ); |
|
385 | + $markup = array_map(array($this, 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
386 | + return implode(' | ', $markup); |
|
387 | 387 | |
388 | 388 | } |
389 | 389 | |
@@ -394,15 +394,15 @@ discard block |
||
394 | 394 | * @since 1.0.0 |
395 | 395 | * @return string |
396 | 396 | */ |
397 | - public static function generate_item_markup( $item_id ) { |
|
398 | - $item = get_post( $item_id ); |
|
397 | + public static function generate_item_markup($item_id) { |
|
398 | + $item = get_post($item_id); |
|
399 | 399 | |
400 | - if ( ! empty( $item ) ) { |
|
401 | - $link = get_edit_post_link( $item ); |
|
402 | - $name = esc_html( get_the_title( $item ) ); |
|
403 | - return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ( $link ? esc_url( $link ) : '#' ) . "'>$name</a>" : $name; |
|
400 | + if (!empty($item)) { |
|
401 | + $link = get_edit_post_link($item); |
|
402 | + $name = esc_html(get_the_title($item)); |
|
403 | + return wpinv_current_user_can_manage_invoicing() ? "<a href='" . ($link ? esc_url($link) : '#') . "'>$name</a>" : $name; |
|
404 | 404 | } else { |
405 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
405 | + return sprintf(__('Item #%s', 'invoicing'), $item_id); |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | * @return int |
414 | 414 | */ |
415 | 415 | public function get_paged() { |
416 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
416 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -426,13 +426,13 @@ discard block |
||
426 | 426 | $hidden = array(); |
427 | 427 | $sortable = $this->get_sortable_columns(); |
428 | 428 | |
429 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
429 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
430 | 430 | |
431 | 431 | $this->set_pagination_args( |
432 | 432 | array( |
433 | 433 | 'total_items' => $this->current_total_count, |
434 | 434 | 'per_page' => $this->per_page, |
435 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ), |
|
435 | + 'total_pages' => ceil($this->current_total_count / $this->per_page), |
|
436 | 436 | ) |
437 | 437 | ); |
438 | 438 | } |
@@ -445,15 +445,15 @@ discard block |
||
445 | 445 | public function get_columns() { |
446 | 446 | $columns = array( |
447 | 447 | 'cb' => '<input type="checkbox" />', |
448 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
449 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
450 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
451 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
452 | - 'item' => __( 'Items', 'invoicing' ), |
|
453 | - 'status' => __( 'Status', 'invoicing' ), |
|
448 | + 'subscription' => __('Subscription', 'invoicing'), |
|
449 | + 'start_date' => __('Start Date', 'invoicing'), |
|
450 | + 'renewal_date' => __('Next Payment', 'invoicing'), |
|
451 | + 'renewals' => __('Payments', 'invoicing'), |
|
452 | + 'item' => __('Items', 'invoicing'), |
|
453 | + 'status' => __('Status', 'invoicing'), |
|
454 | 454 | ); |
455 | 455 | |
456 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
456 | + return apply_filters('manage_getpaid_subscriptions_table_columns', $columns); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -463,15 +463,15 @@ discard block |
||
463 | 463 | */ |
464 | 464 | public function get_sortable_columns() { |
465 | 465 | $sortable = array( |
466 | - 'subscription' => array( 'id', true ), |
|
467 | - 'start_date' => array( 'created', true ), |
|
468 | - 'renewal_date' => array( 'expiration', true ), |
|
469 | - 'renewals' => array( 'bill_times', true ), |
|
470 | - 'item' => array( 'product_id', true ), |
|
471 | - 'status' => array( 'status', true ), |
|
466 | + 'subscription' => array('id', true), |
|
467 | + 'start_date' => array('created', true), |
|
468 | + 'renewal_date' => array('expiration', true), |
|
469 | + 'renewals' => array('bill_times', true), |
|
470 | + 'item' => array('product_id', true), |
|
471 | + 'status' => array('status', true), |
|
472 | 472 | ); |
473 | 473 | |
474 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
474 | + return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable); |
|
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return bool |
481 | 481 | */ |
482 | 482 | public function has_items() { |
483 | - return ! empty( $this->current_total_count ); |
|
483 | + return !empty($this->current_total_count); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |