@@ -3,9 +3,9 @@ discard block |
||
3 | 3 | * Displays a list of all subscriptions rules |
4 | 4 | */ |
5 | 5 | |
6 | -if ( ! defined( 'ABSPATH' ) ) exit; |
|
6 | +if (!defined('ABSPATH')) exit; |
|
7 | 7 | |
8 | -if ( ! class_exists( 'WP_List_Table' ) ) { |
|
8 | +if (!class_exists('WP_List_Table')) { |
|
9 | 9 | include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
10 | 10 | } |
11 | 11 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $this->prepare_query(); |
80 | 80 | |
81 | - $this->base_url = remove_query_arg( 'status' ); |
|
81 | + $this->base_url = remove_query_arg('status'); |
|
82 | 82 | |
83 | 83 | } |
84 | 84 | |
@@ -91,13 +91,13 @@ discard block |
||
91 | 91 | $query = array( |
92 | 92 | 'number' => $this->per_page, |
93 | 93 | 'paged' => $this->get_paged(), |
94 | - 'status' => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all', |
|
95 | - 'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id', |
|
96 | - 'order' => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC', |
|
94 | + 'status' => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? $_GET['status'] : 'all', |
|
95 | + 'orderby' => (isset($_GET['orderby'])) ? $_GET['orderby'] : 'id', |
|
96 | + 'order' => (isset($_GET['order'])) ? $_GET['order'] : 'DESC', |
|
97 | 97 | 'customer_in' => $this->get_user_in(), |
98 | 98 | ); |
99 | 99 | |
100 | - if ( is_array( $query['customer_in'] ) && empty( $query['customer_in'] ) ) { |
|
100 | + if (is_array($query['customer_in']) && empty($query['customer_in'])) { |
|
101 | 101 | $this->total_count = 0; |
102 | 102 | $this->current_total_count = 0; |
103 | 103 | $this->items = array(); |
@@ -106,15 +106,15 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | // Prepare class properties. |
109 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
109 | + $this->query = new GetPaid_Subscriptions_Query($query); |
|
110 | 110 | $this->total_count = $this->query->get_total(); |
111 | 111 | $this->current_total_count = $this->query->get_total(); |
112 | 112 | $this->items = $this->query->get_results(); |
113 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
113 | + $this->status_counts = getpaid_get_subscription_status_counts($query); |
|
114 | 114 | |
115 | - if ( 'all' != $query['status'] ) { |
|
116 | - unset( $query['status'] ); |
|
117 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
115 | + if ('all' != $query['status']) { |
|
116 | + unset($query['status']); |
|
117 | + $this->total_count = getpaid_get_subscriptions($query, 'count'); |
|
118 | 118 | } |
119 | 119 | |
120 | 120 | } |
@@ -126,14 +126,14 @@ discard block |
||
126 | 126 | public function get_user_in() { |
127 | 127 | |
128 | 128 | // Abort if no user. |
129 | - if ( empty( $_GET['s'] ) ) { |
|
129 | + if (empty($_GET['s'])) { |
|
130 | 130 | return null; |
131 | 131 | } |
132 | 132 | |
133 | 133 | // Or invalid user. |
134 | - $user = wp_unslash( sanitize_text_field( $_REQUEST['s'] ) ); |
|
134 | + $user = wp_unslash(sanitize_text_field($_REQUEST['s'])); |
|
135 | 135 | |
136 | - if ( empty( $user ) ) { |
|
136 | + if (empty($user)) { |
|
137 | 137 | return null; |
138 | 138 | } |
139 | 139 | |
@@ -162,26 +162,26 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function get_views() { |
164 | 164 | |
165 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
165 | + $current = isset($_GET['status']) ? $_GET['status'] : 'all'; |
|
166 | 166 | $views = array( |
167 | 167 | |
168 | 168 | 'all' => sprintf( |
169 | 169 | '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
170 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
170 | + esc_url(add_query_arg('status', false, $this->base_url)), |
|
171 | 171 | $current === 'all' ? ' class="current"' : '', |
172 | - __('All','invoicing' ), |
|
172 | + __('All', 'invoicing'), |
|
173 | 173 | $this->total_count |
174 | 174 | ) |
175 | 175 | |
176 | 176 | ); |
177 | 177 | |
178 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
178 | + foreach (array_filter($this->status_counts) as $status => $count) { |
|
179 | 179 | |
180 | - $views[ $status ] = sprintf( |
|
180 | + $views[$status] = sprintf( |
|
181 | 181 | '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
182 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
182 | + esc_url(add_query_arg('status', urlencode($status), $this->base_url)), |
|
183 | 183 | $current === $status ? ' class="current"' : '', |
184 | - esc_html( getpaid_get_subscription_status_label( $status ) ), |
|
184 | + esc_html(getpaid_get_subscription_status_label($status)), |
|
185 | 185 | $count |
186 | 186 | ); |
187 | 187 | |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | * @since 1.0.0 |
199 | 199 | * @return string |
200 | 200 | */ |
201 | - public function column_default( $item, $column_name ) { |
|
202 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
201 | + public function column_default($item, $column_name) { |
|
202 | + return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | /** |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | * @param WPInv_Subscription $item |
209 | 209 | * @return string |
210 | 210 | */ |
211 | - public function column_cb( $item ) { |
|
212 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
211 | + public function column_cb($item) { |
|
212 | + return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id())); |
|
213 | 213 | } |
214 | 214 | |
215 | 215 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | * @since 1.0.0 |
220 | 220 | * @return string |
221 | 221 | */ |
222 | - public function column_status( $item ) { |
|
222 | + public function column_status($item) { |
|
223 | 223 | return $item->get_status_label_html(); |
224 | 224 | } |
225 | 225 | |
@@ -230,44 +230,44 @@ discard block |
||
230 | 230 | * @since 1.0.0 |
231 | 231 | * @return string |
232 | 232 | */ |
233 | - public function column_subscription( $item ) { |
|
233 | + public function column_subscription($item) { |
|
234 | 234 | |
235 | - $username = __( '(Missing User)', 'invoicing' ); |
|
235 | + $username = __('(Missing User)', 'invoicing'); |
|
236 | 236 | |
237 | - $user = get_userdata( $item->get_customer_id() ); |
|
238 | - if ( $user ) { |
|
237 | + $user = get_userdata($item->get_customer_id()); |
|
238 | + if ($user) { |
|
239 | 239 | |
240 | 240 | $username = sprintf( |
241 | 241 | '<a href="user-edit.php?user_id=%s">%s</a>', |
242 | - absint( $user->ID ), |
|
243 | - ! empty( $user->display_name ) ? esc_html( $user->display_name ) : sanitize_email( $user->user_email ) |
|
242 | + absint($user->ID), |
|
243 | + !empty($user->display_name) ? esc_html($user->display_name) : sanitize_email($user->user_email) |
|
244 | 244 | ); |
245 | 245 | |
246 | 246 | } |
247 | 247 | |
248 | 248 | // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
249 | 249 | $column_content = sprintf( |
250 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
251 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
252 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
250 | + _x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'), |
|
251 | + '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">', |
|
252 | + '<strong>' . esc_attr($item->get_id()) . '</strong>', '</a>', |
|
253 | 253 | $username |
254 | 254 | ); |
255 | 255 | |
256 | 256 | $row_actions = array(); |
257 | 257 | |
258 | 258 | // View subscription. |
259 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
260 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
259 | + $view_url = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions'))); |
|
260 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>'; |
|
261 | 261 | |
262 | 262 | // View invoice. |
263 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
263 | + $invoice = get_post($item->get_parent_invoice_id()); |
|
264 | 264 | |
265 | - if ( ! empty( $invoice ) ) { |
|
266 | - $invoice_url = get_edit_post_link( $invoice ); |
|
267 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
265 | + if (!empty($invoice)) { |
|
266 | + $invoice_url = get_edit_post_link($invoice); |
|
267 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __('View Invoice', 'invoicing') . '</a>'; |
|
268 | 268 | } |
269 | 269 | |
270 | - $delete_url = esc_url( |
|
270 | + $delete_url = esc_url( |
|
271 | 271 | wp_nonce_url( |
272 | 272 | add_query_arg( |
273 | 273 | array( |
@@ -279,11 +279,11 @@ discard block |
||
279 | 279 | 'getpaid-nonce' |
280 | 280 | ) |
281 | 281 | ); |
282 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
282 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __('Delete Subscription', 'invoicing') . '</a>'; |
|
283 | 283 | |
284 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
284 | + $row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item)); |
|
285 | 285 | |
286 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
286 | + return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions; |
|
287 | 287 | } |
288 | 288 | |
289 | 289 | /** |
@@ -293,8 +293,8 @@ discard block |
||
293 | 293 | * @since 1.0.0 |
294 | 294 | * @return string |
295 | 295 | */ |
296 | - public function column_renewal_date( $item ) { |
|
297 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
296 | + public function column_renewal_date($item) { |
|
297 | + return getpaid_format_date_value($item->get_expiration()); |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | /** |
@@ -304,27 +304,27 @@ discard block |
||
304 | 304 | * @since 1.0.0 |
305 | 305 | * @return string |
306 | 306 | */ |
307 | - public function column_start_date( $item ) { |
|
307 | + public function column_start_date($item) { |
|
308 | 308 | |
309 | 309 | $gateway = $item->get_parent_invoice()->get_gateway_title(); |
310 | 310 | |
311 | - if ( empty( $gateway ) ) { |
|
312 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
311 | + if (empty($gateway)) { |
|
312 | + return getpaid_format_date_value($item->get_date_created()); |
|
313 | 313 | } |
314 | 314 | |
315 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $item ); |
|
316 | - if ( ! empty( $url ) ) { |
|
315 | + $url = apply_filters('getpaid_remote_subscription_profile_url', '', $item); |
|
316 | + if (!empty($url)) { |
|
317 | 317 | |
318 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
319 | - __( 'Via %s', 'invoicing' ), |
|
320 | - '<strong><a href="' . esc_url( $url ) . '" target="_blank">' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</a></strong>' |
|
318 | + return getpaid_format_date_value($item->get_date_created()) . '<br>' . sprintf( |
|
319 | + __('Via %s', 'invoicing'), |
|
320 | + '<strong><a href="' . esc_url($url) . '" target="_blank">' . esc_html($item->get_parent_invoice()->get_gateway_title()) . '</a></strong>' |
|
321 | 321 | ); |
322 | 322 | |
323 | 323 | } |
324 | 324 | |
325 | - return getpaid_format_date_value( $item->get_date_created() ) . '<br>' . sprintf( |
|
326 | - __( 'Via %s', 'invoicing' ), |
|
327 | - '<strong>' . esc_html( $item->get_parent_invoice()->get_gateway_title() ) . '</strong>' |
|
325 | + return getpaid_format_date_value($item->get_date_created()) . '<br>' . sprintf( |
|
326 | + __('Via %s', 'invoicing'), |
|
327 | + '<strong>' . esc_html($item->get_parent_invoice()->get_gateway_title()) . '</strong>' |
|
328 | 328 | ); |
329 | 329 | |
330 | 330 | } |
@@ -336,8 +336,8 @@ discard block |
||
336 | 336 | * @since 1.0.19 |
337 | 337 | * @return string |
338 | 338 | */ |
339 | - public static function column_amount( $item ) { |
|
340 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
339 | + public static function column_amount($item) { |
|
340 | + $amount = getpaid_get_formatted_subscription_amount($item); |
|
341 | 341 | return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
342 | 342 | } |
343 | 343 | |
@@ -348,9 +348,9 @@ discard block |
||
348 | 348 | * @since 1.0.0 |
349 | 349 | * @return string |
350 | 350 | */ |
351 | - public function column_renewals( $item ) { |
|
351 | + public function column_renewals($item) { |
|
352 | 352 | $max_bills = $item->get_bill_times(); |
353 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
353 | + return $item->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | /** |
@@ -360,15 +360,15 @@ discard block |
||
360 | 360 | * @since 1.0.0 |
361 | 361 | * @return string |
362 | 362 | */ |
363 | - public function column_item( $item ) { |
|
364 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
363 | + public function column_item($item) { |
|
364 | + $subscription_group = getpaid_get_invoice_subscription_group($item->get_parent_invoice_id(), $item->get_id()); |
|
365 | 365 | |
366 | - if ( empty( $subscription_group ) ) { |
|
367 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
366 | + if (empty($subscription_group)) { |
|
367 | + return $this->generate_item_markup($item->get_product_id()); |
|
368 | 368 | } |
369 | 369 | |
370 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
371 | - return implode( ' | ', $markup ); |
|
370 | + $markup = array_map(array($this, 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
371 | + return implode(' | ', $markup); |
|
372 | 372 | |
373 | 373 | } |
374 | 374 | |
@@ -379,16 +379,16 @@ discard block |
||
379 | 379 | * @since 1.0.0 |
380 | 380 | * @return string |
381 | 381 | */ |
382 | - public static function generate_item_markup( $item_id ) { |
|
383 | - $item = get_post( $item_id ); |
|
382 | + public static function generate_item_markup($item_id) { |
|
383 | + $item = get_post($item_id); |
|
384 | 384 | |
385 | - if ( ! empty( $item ) ) { |
|
386 | - $link = get_edit_post_link( $item ); |
|
387 | - $link = esc_url( $link ); |
|
388 | - $name = esc_html( get_the_title( $item ) ); |
|
385 | + if (!empty($item)) { |
|
386 | + $link = get_edit_post_link($item); |
|
387 | + $link = esc_url($link); |
|
388 | + $name = esc_html(get_the_title($item)); |
|
389 | 389 | return wpinv_current_user_can_manage_invoicing() ? "<a href='$link'>$name</a>" : $name; |
390 | 390 | } else { |
391 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
391 | + return sprintf(__('Item #%s', 'invoicing'), $item_id); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | } |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * @return int |
400 | 400 | */ |
401 | 401 | public function get_paged() { |
402 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
402 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
403 | 403 | } |
404 | 404 | |
405 | 405 | /** |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | $hidden = array(); |
413 | 413 | $sortable = $this->get_sortable_columns(); |
414 | 414 | |
415 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
415 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
416 | 416 | |
417 | 417 | $this->set_pagination_args( |
418 | 418 | array( |
419 | 419 | 'total_items' => $this->current_total_count, |
420 | 420 | 'per_page' => $this->per_page, |
421 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
421 | + 'total_pages' => ceil($this->current_total_count / $this->per_page) |
|
422 | 422 | ) |
423 | 423 | ); |
424 | 424 | } |
@@ -428,18 +428,18 @@ discard block |
||
428 | 428 | * |
429 | 429 | * @return array |
430 | 430 | */ |
431 | - public function get_columns(){ |
|
431 | + public function get_columns() { |
|
432 | 432 | $columns = array( |
433 | 433 | 'cb' => '<input type="checkbox" />', |
434 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
435 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
436 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
437 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
438 | - 'item' => __( 'Items', 'invoicing' ), |
|
439 | - 'status' => __( 'Status', 'invoicing' ), |
|
434 | + 'subscription' => __('Subscription', 'invoicing'), |
|
435 | + 'start_date' => __('Start Date', 'invoicing'), |
|
436 | + 'renewal_date' => __('Next Payment', 'invoicing'), |
|
437 | + 'renewals' => __('Payments', 'invoicing'), |
|
438 | + 'item' => __('Items', 'invoicing'), |
|
439 | + 'status' => __('Status', 'invoicing'), |
|
440 | 440 | ); |
441 | 441 | |
442 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
442 | + return apply_filters('manage_getpaid_subscriptions_table_columns', $columns); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | /** |
@@ -449,15 +449,15 @@ discard block |
||
449 | 449 | */ |
450 | 450 | public function get_sortable_columns() { |
451 | 451 | $sortable = array( |
452 | - 'subscription' => array( 'id', true ), |
|
453 | - 'start_date' => array( 'created', true ), |
|
454 | - 'renewal_date' => array( 'expiration', true ), |
|
455 | - 'renewals' => array( 'bill_times', true ), |
|
456 | - 'item' => array( 'product_id', true ), |
|
457 | - 'status' => array( 'status', true ), |
|
452 | + 'subscription' => array('id', true), |
|
453 | + 'start_date' => array('created', true), |
|
454 | + 'renewal_date' => array('expiration', true), |
|
455 | + 'renewals' => array('bill_times', true), |
|
456 | + 'item' => array('product_id', true), |
|
457 | + 'status' => array('status', true), |
|
458 | 458 | ); |
459 | 459 | |
460 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
460 | + return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | /** |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | * @return bool |
467 | 467 | */ |
468 | 468 | public function has_items() { |
469 | - return ! empty( $this->current_total_count ); |
|
469 | + return !empty($this->current_total_count); |
|
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |