@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * @version 1.0.0 |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Contains the subscriptions widget. |
@@ -27,15 +27,15 @@ discard block |
||
27 | 27 | 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
28 | 28 | 'class_name' => __CLASS__, |
29 | 29 | 'base_id' => 'wpinv_subscriptions', |
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
30 | + 'name' => __('GetPaid > Subscriptions', 'invoicing'), |
|
31 | 31 | 'widget_ops' => array( |
32 | 32 | 'classname' => 'getpaid-subscriptions bsui', |
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
33 | + 'description' => esc_html__("Displays the current user's subscriptions.", 'invoicing'), |
|
34 | 34 | ), |
35 | 35 | 'arguments' => array( |
36 | 36 | 'title' => array( |
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
37 | + 'title' => __('Widget title', 'invoicing'), |
|
38 | + 'desc' => __('Enter widget title.', 'invoicing'), |
|
39 | 39 | 'type' => 'text', |
40 | 40 | 'desc_tip' => true, |
41 | 41 | 'default' => '', |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | |
46 | 46 | ); |
47 | 47 | |
48 | - parent::__construct( $options ); |
|
48 | + parent::__construct($options); |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -56,12 +56,12 @@ discard block |
||
56 | 56 | public function get_subscriptions() { |
57 | 57 | |
58 | 58 | // Prepare license args. |
59 | - $args = array( |
|
59 | + $args = array( |
|
60 | 60 | 'customer_in' => get_current_user_id(), |
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
61 | + 'paged' => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1, |
|
62 | 62 | ); |
63 | 63 | |
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
64 | + return new GetPaid_Subscriptions_Query($args); |
|
65 | 65 | |
66 | 66 | } |
67 | 67 | |
@@ -74,14 +74,14 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @return mixed|string|bool |
76 | 76 | */ |
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
77 | + public function output($args = array(), $widget_args = array(), $content = '') { |
|
78 | 78 | |
79 | 79 | // Ensure that the user is logged in. |
80 | - if ( ! is_user_logged_in() ) { |
|
80 | + if (!is_user_logged_in()) { |
|
81 | 81 | |
82 | 82 | return aui()->alert( |
83 | 83 | array( |
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
84 | + 'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')), |
|
85 | 85 | 'type' => 'error', |
86 | 86 | ) |
87 | 87 | ); |
@@ -89,8 +89,8 @@ discard block |
||
89 | 89 | } |
90 | 90 | |
91 | 91 | // Are we displaying a single subscription? |
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
92 | + if (isset($_GET['subscription'])) { |
|
93 | + return $this->display_single_subscription(intval($_GET['subscription'])); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | // Retrieve the user's subscriptions. |
@@ -100,27 +100,27 @@ discard block |
||
100 | 100 | ob_start(); |
101 | 101 | |
102 | 102 | // Backwards compatibility. |
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
103 | + do_action('wpinv_before_user_subscriptions'); |
|
104 | 104 | |
105 | 105 | // Display errors and notices. |
106 | 106 | wpinv_print_errors(); |
107 | 107 | |
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
108 | + do_action('getpaid_license_manager_before_subscriptions', $subscriptions); |
|
109 | 109 | |
110 | 110 | // Print the table header. |
111 | 111 | $this->print_table_header(); |
112 | 112 | |
113 | 113 | // Print table body. |
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
114 | + $this->print_table_body($subscriptions->get_results()); |
|
115 | 115 | |
116 | 116 | // Print table footer. |
117 | 117 | $this->print_table_footer(); |
118 | 118 | |
119 | 119 | // Print the navigation. |
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
120 | + $this->print_navigation($subscriptions->get_total()); |
|
121 | 121 | |
122 | 122 | // Backwards compatibility. |
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
123 | + do_action('wpinv_after_user_subscriptions'); |
|
124 | 124 | |
125 | 125 | // Return the output. |
126 | 126 | return ob_get_clean(); |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | public function get_subscriptions_table_columns() { |
136 | 136 | |
137 | 137 | $columns = array( |
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
138 | + 'subscription' => __('Subscription', 'invoicing'), |
|
139 | + 'amount' => __('Amount', 'invoicing'), |
|
140 | + 'renewal-date' => __('Next payment', 'invoicing'), |
|
141 | + 'status' => __('Status', 'invoicing'), |
|
142 | 142 | ); |
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
144 | + return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | /** |
@@ -156,9 +156,9 @@ discard block |
||
156 | 156 | |
157 | 157 | <thead> |
158 | 158 | <tr> |
159 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
160 | - <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>"> |
|
161 | - <?php echo esc_html( $label ); ?> |
|
159 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
160 | + <th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>"> |
|
161 | + <?php echo esc_html($label); ?> |
|
162 | 162 | </th> |
163 | 163 | <?php endforeach; ?> |
164 | 164 | </tr> |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * |
174 | 174 | * @param WPInv_Subscription[] $subscriptions |
175 | 175 | */ |
176 | - public function print_table_body( $subscriptions ) { |
|
176 | + public function print_table_body($subscriptions) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
178 | + if (empty($subscriptions)) { |
|
179 | 179 | $this->print_table_body_no_subscriptions(); |
180 | 180 | } else { |
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
181 | + $this->print_table_body_subscriptions($subscriptions); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | } |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | - <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
|
196 | + <td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>"> |
|
197 | 197 | |
198 | 198 | <?php |
199 | 199 | echo aui()->alert( |
200 | 200 | array( |
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
201 | + 'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')), |
|
202 | 202 | 'type' => 'warning', |
203 | 203 | ) |
204 | 204 | ); |
@@ -216,12 +216,12 @@ discard block |
||
216 | 216 | * |
217 | 217 | * @param WPInv_Subscription[] $subscriptions |
218 | 218 | */ |
219 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
219 | + public function print_table_body_subscriptions($subscriptions) { |
|
220 | 220 | |
221 | 221 | ?> |
222 | 222 | <tbody> |
223 | 223 | |
224 | - <?php foreach ( $subscriptions as $subscription ) : ?> |
|
224 | + <?php foreach ($subscriptions as $subscription) : ?> |
|
225 | 225 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
226 | 226 | <?php |
227 | 227 | wpinv_get_template( |
@@ -247,28 +247,28 @@ discard block |
||
247 | 247 | * @since 1.0.0 |
248 | 248 | * @return string |
249 | 249 | */ |
250 | - public function add_row_actions( $content, $subscription ) { |
|
250 | + public function add_row_actions($content, $subscription) { |
|
251 | 251 | |
252 | 252 | // Prepare row actions. |
253 | 253 | $actions = array(); |
254 | 254 | |
255 | 255 | // View subscription action. |
256 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
257 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
258 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
256 | + $view_url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page'))); |
|
257 | + $view_url = esc_url(add_query_arg('subscription', (int) $subscription->get_id(), $view_url)); |
|
258 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __('Manage Subscription', 'invoicing') . '</a>'; |
|
259 | 259 | |
260 | 260 | // Filter the actions. |
261 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
261 | + $actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription); |
|
262 | 262 | |
263 | - $sanitized = array(); |
|
264 | - foreach ( $actions as $key => $action ) { |
|
265 | - $key = sanitize_html_class( $key ); |
|
266 | - $action = wp_kses_post( $action ); |
|
263 | + $sanitized = array(); |
|
264 | + foreach ($actions as $key => $action) { |
|
265 | + $key = sanitize_html_class($key); |
|
266 | + $action = wp_kses_post($action); |
|
267 | 267 | $sanitized[] = "<span class='$key'>$action</span>"; |
268 | 268 | } |
269 | 269 | |
270 | 270 | $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
271 | - $row_actions .= implode( ' | ', $sanitized ); |
|
271 | + $row_actions .= implode(' | ', $sanitized); |
|
272 | 272 | $row_actions .= '</small>'; |
273 | 273 | |
274 | 274 | return $content . $row_actions; |
@@ -284,9 +284,9 @@ discard block |
||
284 | 284 | |
285 | 285 | <tfoot> |
286 | 286 | <tr> |
287 | - <?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?> |
|
288 | - <th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>"> |
|
289 | - <?php echo esc_html( $label ); ?> |
|
287 | + <?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?> |
|
288 | + <th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>"> |
|
289 | + <?php echo esc_html($label); ?> |
|
290 | 290 | </th> |
291 | 291 | <?php endforeach; ?> |
292 | 292 | </tr> |
@@ -302,22 +302,22 @@ discard block |
||
302 | 302 | * |
303 | 303 | * @param int $total |
304 | 304 | */ |
305 | - public function print_navigation( $total ) { |
|
305 | + public function print_navigation($total) { |
|
306 | 306 | |
307 | - if ( $total < 1 ) { |
|
307 | + if ($total < 1) { |
|
308 | 308 | |
309 | 309 | // Out-of-bounds, run the query again without LIMIT for total count. |
310 | - $args = array( |
|
310 | + $args = array( |
|
311 | 311 | 'customer_in' => get_current_user_id(), |
312 | 312 | 'fields' => 'id', |
313 | 313 | ); |
314 | 314 | |
315 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
315 | + $count_query = new GetPaid_Subscriptions_Query($args); |
|
316 | 316 | $total = $count_query->get_total(); |
317 | 317 | } |
318 | 318 | |
319 | 319 | // Abort if we do not have pages. |
320 | - if ( 2 > $total ) { |
|
320 | + if (2 > $total) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | |
@@ -330,9 +330,9 @@ discard block |
||
330 | 330 | echo wp_kses_post( |
331 | 331 | getpaid_paginate_links( |
332 | 332 | array( |
333 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
333 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
334 | 334 | 'format' => '?paged=%#%', |
335 | - 'total' => (int) ceil( $total / 10 ), |
|
335 | + 'total' => (int) ceil($total / 10), |
|
336 | 336 | ) |
337 | 337 | ) |
338 | 338 | ); |
@@ -349,42 +349,42 @@ discard block |
||
349 | 349 | * |
350 | 350 | * @return array |
351 | 351 | */ |
352 | - public function get_single_subscription_columns( $subscription ) { |
|
352 | + public function get_single_subscription_columns($subscription) { |
|
353 | 353 | |
354 | 354 | // Prepare subscription detail columns. |
355 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
356 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
355 | + $subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_invoice_id(), $subscription->get_id()); |
|
356 | + $items_count = empty($subscription_group) ? 1 : count($subscription_group['items']); |
|
357 | 357 | $fields = apply_filters( |
358 | 358 | 'getpaid_single_subscription_details_fields', |
359 | 359 | array( |
360 | - 'status' => __( 'Status', 'invoicing' ), |
|
361 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
362 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
363 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
364 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
365 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
366 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
360 | + 'status' => __('Status', 'invoicing'), |
|
361 | + 'initial_amount' => __('Initial amount', 'invoicing'), |
|
362 | + 'recurring_amount' => __('Recurring amount', 'invoicing'), |
|
363 | + 'start_date' => __('Start date', 'invoicing'), |
|
364 | + 'expiry_date' => __('Next payment', 'invoicing'), |
|
365 | + 'payments' => __('Payments', 'invoicing'), |
|
366 | + 'item' => _n('Item', 'Items', $items_count, 'invoicing'), |
|
367 | 367 | ), |
368 | 368 | $subscription |
369 | 369 | ); |
370 | 370 | |
371 | - if ( isset( $fields['expiry_date'] ) ) { |
|
371 | + if (isset($fields['expiry_date'])) { |
|
372 | 372 | |
373 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
374 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
373 | + if (!$subscription->is_active() || $subscription->is_last_renewal()) { |
|
374 | + $fields['expiry_date'] = __('End date', 'invoicing'); |
|
375 | 375 | } |
376 | 376 | |
377 | - if ( 'pending' == $subscription->get_status() ) { |
|
378 | - unset( $fields['expiry_date'] ); |
|
377 | + if ('pending' == $subscription->get_status()) { |
|
378 | + unset($fields['expiry_date']); |
|
379 | 379 | } |
380 | 380 | } |
381 | 381 | |
382 | - if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) { |
|
383 | - unset( $fields['start_date'] ); |
|
382 | + if (isset($fields['start_date']) && 'pending' == $subscription->get_status()) { |
|
383 | + unset($fields['start_date']); |
|
384 | 384 | } |
385 | 385 | |
386 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
387 | - unset( $fields['initial_amount'] ); |
|
386 | + if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) { |
|
387 | + unset($fields['initial_amount']); |
|
388 | 388 | } |
389 | 389 | |
390 | 390 | return $fields; |
@@ -397,16 +397,16 @@ discard block |
||
397 | 397 | * |
398 | 398 | * @return string |
399 | 399 | */ |
400 | - public function display_single_subscription( $subscription ) { |
|
400 | + public function display_single_subscription($subscription) { |
|
401 | 401 | |
402 | 402 | // Fetch the subscription. |
403 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
403 | + $subscription = new WPInv_Subscription((int) $subscription); |
|
404 | 404 | |
405 | - if ( ! $subscription->exists() ) { |
|
405 | + if (!$subscription->exists()) { |
|
406 | 406 | |
407 | 407 | return aui()->alert( |
408 | 408 | array( |
409 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
409 | + 'content' => wp_kses_post(__('Subscription not found.', 'invoicing')), |
|
410 | 410 | 'type' => 'error', |
411 | 411 | ) |
412 | 412 | ); |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | } |
415 | 415 | |
416 | 416 | // Ensure that the user owns this subscription key. |
417 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
417 | + if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) { |
|
418 | 418 | |
419 | 419 | return aui()->alert( |
420 | 420 | array( |
421 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
421 | + 'content' => wp_kses_post(__('You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing')), |
|
422 | 422 | 'type' => 'error', |
423 | 423 | ) |
424 | 424 | ); |