@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | */ |
15 | 15 | function wpinv_subscriptions_page() { |
16 | 16 | |
17 | - ?> |
|
17 | + ?> |
|
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | 20 | <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
@@ -22,27 +22,27 @@ discard block |
||
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | - // Verify user permissions. |
|
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
25 | + // Verify user permissions. |
|
26 | + if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
27 | 27 | |
28 | - echo aui()->alert( |
|
29 | - array( |
|
30 | - 'type' => 'danger', |
|
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | - ) |
|
33 | - ); |
|
28 | + echo aui()->alert( |
|
29 | + array( |
|
30 | + 'type' => 'danger', |
|
31 | + 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
32 | + ) |
|
33 | + ); |
|
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
36 | 36 | |
37 | - // Display a single subscription. |
|
38 | - wpinv_recurring_subscription_details(); |
|
39 | - } else { |
|
37 | + // Display a single subscription. |
|
38 | + wpinv_recurring_subscription_details(); |
|
39 | + } else { |
|
40 | 40 | |
41 | - // Display a list of available subscriptions. |
|
42 | - getpaid_print_subscriptions_list(); |
|
43 | - } |
|
41 | + // Display a list of available subscriptions. |
|
42 | + getpaid_print_subscriptions_list(); |
|
43 | + } |
|
44 | 44 | |
45 | - ?> |
|
45 | + ?> |
|
46 | 46 | |
47 | 47 | </div> |
48 | 48 | </div> |
@@ -59,10 +59,10 @@ discard block |
||
59 | 59 | */ |
60 | 60 | function getpaid_print_subscriptions_list() { |
61 | 61 | |
62 | - $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | - $subscribers_table->prepare_items(); |
|
62 | + $subscribers_table = new WPInv_Subscriptions_List_Table(); |
|
63 | + $subscribers_table->prepare_items(); |
|
64 | 64 | |
65 | - ?> |
|
65 | + ?> |
|
66 | 66 | <form id="subscribers-filter" class="bsui" method="get"> |
67 | 67 | <input type="hidden" name="page" value="wpinv-subscriptions" /> |
68 | 68 | <?php $subscribers_table->views(); ?> |
@@ -80,41 +80,41 @@ discard block |
||
80 | 80 | */ |
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | - // Fetch the subscription. |
|
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->exists() ) { |
|
83 | + // Fetch the subscription. |
|
84 | + $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | + if ( ! $sub->exists() ) { |
|
86 | 86 | |
87 | - echo aui()->alert( |
|
88 | - array( |
|
89 | - 'type' => 'danger', |
|
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
91 | - ) |
|
92 | - ); |
|
87 | + echo aui()->alert( |
|
88 | + array( |
|
89 | + 'type' => 'danger', |
|
90 | + 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
91 | + ) |
|
92 | + ); |
|
93 | 93 | |
94 | - return; |
|
95 | - } |
|
94 | + return; |
|
95 | + } |
|
96 | 96 | |
97 | - // Use metaboxes to display the subscription details. |
|
98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
97 | + // Use metaboxes to display the subscription details. |
|
98 | + add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
99 | + add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
100 | 100 | |
101 | - $subscription_id = $sub->get_id(); |
|
102 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
103 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
101 | + $subscription_id = $sub->get_id(); |
|
102 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
103 | + $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
104 | 104 | |
105 | - if ( 1 < count( $subscription_groups ) ) { |
|
106 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
107 | - } |
|
105 | + if ( 1 < count( $subscription_groups ) ) { |
|
106 | + add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
107 | + } |
|
108 | 108 | |
109 | - if ( ! empty( $subscription_group ) ) { |
|
110 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
111 | - } |
|
109 | + if ( ! empty( $subscription_group ) ) { |
|
110 | + add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
111 | + } |
|
112 | 112 | |
113 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
113 | + add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
114 | 114 | |
115 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
115 | + do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
116 | 116 | |
117 | - ?> |
|
117 | + ?> |
|
118 | 118 | |
119 | 119 | <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
120 | 120 | |
@@ -154,45 +154,45 @@ discard block |
||
154 | 154 | */ |
155 | 155 | function getpaid_admin_subscription_details_metabox( $sub ) { |
156 | 156 | |
157 | - // Subscription items. |
|
158 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
159 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
160 | - |
|
161 | - // Prepare subscription detail columns. |
|
162 | - $fields = apply_filters( |
|
163 | - 'getpaid_subscription_admin_page_fields', |
|
164 | - array( |
|
165 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
166 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
167 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
168 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
169 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
170 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
171 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
172 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
173 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
174 | - 'status' => __( 'Status', 'invoicing' ), |
|
175 | - ) |
|
176 | - ); |
|
177 | - |
|
178 | - if ( ! $sub->is_active() ) { |
|
179 | - |
|
180 | - if ( isset( $fields['renews_on'] ) ) { |
|
181 | - unset( $fields['renews_on'] ); |
|
182 | - } |
|
183 | - |
|
184 | - if ( isset( $fields['gateway'] ) ) { |
|
185 | - unset( $fields['gateway'] ); |
|
186 | - } |
|
187 | - |
|
188 | - } |
|
189 | - |
|
190 | - $profile_id = $sub->get_profile_id(); |
|
191 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
192 | - unset( $fields['profile_id'] ); |
|
193 | - } |
|
194 | - |
|
195 | - ?> |
|
157 | + // Subscription items. |
|
158 | + $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
159 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
160 | + |
|
161 | + // Prepare subscription detail columns. |
|
162 | + $fields = apply_filters( |
|
163 | + 'getpaid_subscription_admin_page_fields', |
|
164 | + array( |
|
165 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
166 | + 'customer' => __( 'Customer', 'invoicing' ), |
|
167 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
168 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
169 | + 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
170 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
171 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
172 | + 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
173 | + 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
174 | + 'status' => __( 'Status', 'invoicing' ), |
|
175 | + ) |
|
176 | + ); |
|
177 | + |
|
178 | + if ( ! $sub->is_active() ) { |
|
179 | + |
|
180 | + if ( isset( $fields['renews_on'] ) ) { |
|
181 | + unset( $fields['renews_on'] ); |
|
182 | + } |
|
183 | + |
|
184 | + if ( isset( $fields['gateway'] ) ) { |
|
185 | + unset( $fields['gateway'] ); |
|
186 | + } |
|
187 | + |
|
188 | + } |
|
189 | + |
|
190 | + $profile_id = $sub->get_profile_id(); |
|
191 | + if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
192 | + unset( $fields['profile_id'] ); |
|
193 | + } |
|
194 | + |
|
195 | + ?> |
|
196 | 196 | |
197 | 197 | <table class="table table-borderless" style="font-size: 14px;"> |
198 | 198 | <tbody> |
@@ -226,20 +226,20 @@ discard block |
||
226 | 226 | */ |
227 | 227 | function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
228 | 228 | |
229 | - $username = __( '(Missing User)', 'invoicing' ); |
|
229 | + $username = __( '(Missing User)', 'invoicing' ); |
|
230 | 230 | |
231 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
232 | - if ( $user ) { |
|
231 | + $user = get_userdata( $subscription->get_customer_id() ); |
|
232 | + if ( $user ) { |
|
233 | 233 | |
234 | - $username = sprintf( |
|
235 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
236 | - absint( $user->ID ), |
|
237 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
238 | - ); |
|
234 | + $username = sprintf( |
|
235 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
236 | + absint( $user->ID ), |
|
237 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
238 | + ); |
|
239 | 239 | |
240 | - } |
|
240 | + } |
|
241 | 241 | |
242 | - echo $username; |
|
242 | + echo $username; |
|
243 | 243 | } |
244 | 244 | add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
245 | 245 | |
@@ -249,8 +249,8 @@ discard block |
||
249 | 249 | * @param WPInv_Subscription $subscription |
250 | 250 | */ |
251 | 251 | function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
252 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
253 | - echo "<span>$amount</span>"; |
|
252 | + $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
253 | + echo "<span>$amount</span>"; |
|
254 | 254 | } |
255 | 255 | add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
256 | 256 | |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | * @param WPInv_Subscription $subscription |
261 | 261 | */ |
262 | 262 | function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
263 | - echo '#' . absint( $subscription->get_id() ); |
|
263 | + echo '#' . absint( $subscription->get_id() ); |
|
264 | 264 | } |
265 | 265 | add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
266 | 266 | |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | * @param WPInv_Subscription $subscription |
271 | 271 | */ |
272 | 272 | function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
273 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
273 | + echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
274 | 274 | } |
275 | 275 | add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
276 | 276 | |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | * @param WPInv_Subscription $subscription |
281 | 281 | */ |
282 | 282 | function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
283 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
283 | + echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
284 | 284 | } |
285 | 285 | add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
286 | 286 | |
@@ -290,8 +290,8 @@ discard block |
||
290 | 290 | * @param WPInv_Subscription $subscription |
291 | 291 | */ |
292 | 292 | function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
293 | - $max_bills = $subscription->get_bill_times(); |
|
294 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
293 | + $max_bills = $subscription->get_bill_times(); |
|
294 | + echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
295 | 295 | } |
296 | 296 | add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
297 | 297 | /** |
@@ -302,13 +302,13 @@ discard block |
||
302 | 302 | */ |
303 | 303 | function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
304 | 304 | |
305 | - if ( empty( $subscription_group ) ) { |
|
306 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
307 | - return; |
|
308 | - } |
|
305 | + if ( empty( $subscription_group ) ) { |
|
306 | + echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
307 | + return; |
|
308 | + } |
|
309 | 309 | |
310 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
311 | - echo implode( ' | ', $markup ); |
|
310 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
311 | + echo implode( ' | ', $markup ); |
|
312 | 312 | |
313 | 313 | } |
314 | 314 | add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
@@ -320,13 +320,13 @@ discard block |
||
320 | 320 | */ |
321 | 321 | function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
322 | 322 | |
323 | - $gateway = $subscription->get_gateway(); |
|
323 | + $gateway = $subscription->get_gateway(); |
|
324 | 324 | |
325 | - if ( ! empty( $gateway ) ) { |
|
326 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
327 | - } else { |
|
328 | - echo "—"; |
|
329 | - } |
|
325 | + if ( ! empty( $gateway ) ) { |
|
326 | + echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
327 | + } else { |
|
328 | + echo "—"; |
|
329 | + } |
|
330 | 330 | |
331 | 331 | } |
332 | 332 | add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | * @param WPInv_Subscription $subscription |
338 | 338 | */ |
339 | 339 | function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
340 | - echo $subscription->get_status_label_html(); |
|
340 | + echo $subscription->get_status_label_html(); |
|
341 | 341 | } |
342 | 342 | add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
343 | 343 | |
@@ -348,29 +348,29 @@ discard block |
||
348 | 348 | */ |
349 | 349 | function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
350 | 350 | |
351 | - $profile_id = $subscription->get_profile_id(); |
|
352 | - |
|
353 | - $input = aui()->input( |
|
354 | - array( |
|
355 | - 'type' => 'text', |
|
356 | - 'id' => 'wpinv_subscription_profile_id', |
|
357 | - 'name' => 'wpinv_subscription_profile_id', |
|
358 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
359 | - 'label_type' => 'hidden', |
|
360 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
361 | - 'value' => sanitize_text_field( $profile_id ), |
|
362 | - 'input_group_right' => '', |
|
363 | - 'no_wrap' => true, |
|
364 | - ) |
|
365 | - ); |
|
366 | - |
|
367 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
368 | - |
|
369 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
370 | - if ( ! empty( $url ) ) { |
|
371 | - $url = esc_url_raw( $url ); |
|
372 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
373 | - } |
|
351 | + $profile_id = $subscription->get_profile_id(); |
|
352 | + |
|
353 | + $input = aui()->input( |
|
354 | + array( |
|
355 | + 'type' => 'text', |
|
356 | + 'id' => 'wpinv_subscription_profile_id', |
|
357 | + 'name' => 'wpinv_subscription_profile_id', |
|
358 | + 'label' => __( 'Profile Id', 'invoicing' ), |
|
359 | + 'label_type' => 'hidden', |
|
360 | + 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
361 | + 'value' => sanitize_text_field( $profile_id ), |
|
362 | + 'input_group_right' => '', |
|
363 | + 'no_wrap' => true, |
|
364 | + ) |
|
365 | + ); |
|
366 | + |
|
367 | + echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
368 | + |
|
369 | + $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
370 | + if ( ! empty( $url ) ) { |
|
371 | + $url = esc_url_raw( $url ); |
|
372 | + echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
373 | + } |
|
374 | 374 | |
375 | 375 | } |
376 | 376 | add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
@@ -382,39 +382,39 @@ discard block |
||
382 | 382 | */ |
383 | 383 | function getpaid_admin_subscription_update_metabox( $subscription ) { |
384 | 384 | |
385 | - ?> |
|
385 | + ?> |
|
386 | 386 | <div class="mt-3"> |
387 | 387 | |
388 | 388 | <?php |
389 | - echo aui()->select( |
|
390 | - array( |
|
391 | - 'options' => getpaid_get_subscription_statuses(), |
|
392 | - 'name' => 'subscription_status', |
|
393 | - 'id' => 'subscription_status_update_select', |
|
394 | - 'required' => true, |
|
395 | - 'no_wrap' => false, |
|
396 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
397 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
398 | - 'select2' => true, |
|
399 | - 'value' => $subscription->get_status( 'edit' ), |
|
400 | - ) |
|
401 | - ); |
|
402 | - ?> |
|
389 | + echo aui()->select( |
|
390 | + array( |
|
391 | + 'options' => getpaid_get_subscription_statuses(), |
|
392 | + 'name' => 'subscription_status', |
|
393 | + 'id' => 'subscription_status_update_select', |
|
394 | + 'required' => true, |
|
395 | + 'no_wrap' => false, |
|
396 | + 'label' => __( 'Subscription Status', 'invoicing' ), |
|
397 | + 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
398 | + 'select2' => true, |
|
399 | + 'value' => $subscription->get_status( 'edit' ), |
|
400 | + ) |
|
401 | + ); |
|
402 | + ?> |
|
403 | 403 | |
404 | 404 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
405 | 405 | |
406 | 406 | <?php |
407 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
407 | + submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
408 | 408 | |
409 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
410 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
411 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
409 | + $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
410 | + $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
411 | + $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
412 | 412 | |
413 | - if ( $subscription->is_active() ) { |
|
414 | - echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
415 | - } |
|
413 | + if ( $subscription->is_active() ) { |
|
414 | + echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
|
415 | + } |
|
416 | 416 | |
417 | - echo '</div></div>'; |
|
417 | + echo '</div></div>'; |
|
418 | 418 | } |
419 | 419 | |
420 | 420 | /** |
@@ -424,33 +424,33 @@ discard block |
||
424 | 424 | */ |
425 | 425 | function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
426 | 426 | |
427 | - $columns = apply_filters( |
|
428 | - 'getpaid_subscription_related_invoices_columns', |
|
429 | - array( |
|
430 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
431 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
432 | - 'date' => __( 'Date', 'invoicing' ), |
|
433 | - 'status' => __( 'Status', 'invoicing' ), |
|
434 | - 'total' => __( 'Total', 'invoicing' ), |
|
435 | - ), |
|
436 | - $subscription |
|
437 | - ); |
|
438 | - |
|
439 | - // Prepare the invoices. |
|
440 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
441 | - $parent = $subscription->get_parent_invoice(); |
|
442 | - |
|
443 | - if ( $parent->get_id() ) { |
|
444 | - $payments = array_merge( array( $parent ), $payments ); |
|
445 | - } |
|
446 | - |
|
447 | - $table_class = 'w-100 bg-white'; |
|
448 | - |
|
449 | - if ( ! is_admin() ) { |
|
450 | - $table_class = 'table table-bordered table-striped'; |
|
451 | - } |
|
452 | - |
|
453 | - ?> |
|
427 | + $columns = apply_filters( |
|
428 | + 'getpaid_subscription_related_invoices_columns', |
|
429 | + array( |
|
430 | + 'invoice' => __( 'Invoice', 'invoicing' ), |
|
431 | + 'relationship' => __( 'Relationship', 'invoicing' ), |
|
432 | + 'date' => __( 'Date', 'invoicing' ), |
|
433 | + 'status' => __( 'Status', 'invoicing' ), |
|
434 | + 'total' => __( 'Total', 'invoicing' ), |
|
435 | + ), |
|
436 | + $subscription |
|
437 | + ); |
|
438 | + |
|
439 | + // Prepare the invoices. |
|
440 | + $payments = $subscription->get_child_payments( ! is_admin() ); |
|
441 | + $parent = $subscription->get_parent_invoice(); |
|
442 | + |
|
443 | + if ( $parent->get_id() ) { |
|
444 | + $payments = array_merge( array( $parent ), $payments ); |
|
445 | + } |
|
446 | + |
|
447 | + $table_class = 'w-100 bg-white'; |
|
448 | + |
|
449 | + if ( ! is_admin() ) { |
|
450 | + $table_class = 'table table-bordered table-striped'; |
|
451 | + } |
|
452 | + |
|
453 | + ?> |
|
454 | 454 | <div class="m-0" style="overflow: auto;"> |
455 | 455 | |
456 | 456 | <table class="<?php echo $table_class; ?>"> |
@@ -458,14 +458,14 @@ discard block |
||
458 | 458 | <thead> |
459 | 459 | <tr> |
460 | 460 | <?php |
461 | - foreach ( $columns as $key => $label ) { |
|
462 | - $key = esc_attr( $key ); |
|
463 | - $label = sanitize_text_field( $label ); |
|
464 | - $class = 'text-left'; |
|
465 | - |
|
466 | - echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
467 | - } |
|
468 | - ?> |
|
461 | + foreach ( $columns as $key => $label ) { |
|
462 | + $key = esc_attr( $key ); |
|
463 | + $label = sanitize_text_field( $label ); |
|
464 | + $class = 'text-left'; |
|
465 | + |
|
466 | + echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
467 | + } |
|
468 | + ?> |
|
469 | 469 | </tr> |
470 | 470 | </thead> |
471 | 471 | |
@@ -481,68 +481,68 @@ discard block |
||
481 | 481 | |
482 | 482 | <?php |
483 | 483 | |
484 | - foreach( $payments as $payment ) : |
|
484 | + foreach( $payments as $payment ) : |
|
485 | 485 | |
486 | - // Ensure that we have an invoice. |
|
487 | - $payment = new WPInv_Invoice( $payment ); |
|
486 | + // Ensure that we have an invoice. |
|
487 | + $payment = new WPInv_Invoice( $payment ); |
|
488 | 488 | |
489 | - // Abort if the invoice is invalid. |
|
490 | - if ( ! $payment->get_id() ) { |
|
491 | - continue; |
|
492 | - } |
|
489 | + // Abort if the invoice is invalid. |
|
490 | + if ( ! $payment->get_id() ) { |
|
491 | + continue; |
|
492 | + } |
|
493 | 493 | |
494 | - echo '<tr>'; |
|
494 | + echo '<tr>'; |
|
495 | 495 | |
496 | - foreach ( array_keys( $columns ) as $key ) { |
|
496 | + foreach ( array_keys( $columns ) as $key ) { |
|
497 | 497 | |
498 | - $class = 'text-left'; |
|
498 | + $class = 'text-left'; |
|
499 | 499 | |
500 | - echo "<td class='p-2 $class'>"; |
|
500 | + echo "<td class='p-2 $class'>"; |
|
501 | 501 | |
502 | - switch( $key ) { |
|
502 | + switch( $key ) { |
|
503 | 503 | |
504 | - case 'total': |
|
505 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
506 | - break; |
|
504 | + case 'total': |
|
505 | + echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
506 | + break; |
|
507 | 507 | |
508 | - case 'relationship': |
|
509 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
510 | - break; |
|
508 | + case 'relationship': |
|
509 | + echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
510 | + break; |
|
511 | 511 | |
512 | - case 'date': |
|
513 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
514 | - break; |
|
512 | + case 'date': |
|
513 | + echo getpaid_format_date_value( $payment->get_date_created() ); |
|
514 | + break; |
|
515 | 515 | |
516 | - case 'status': |
|
516 | + case 'status': |
|
517 | 517 | |
518 | - $status = $payment->get_status_nicename(); |
|
519 | - if ( is_admin() ) { |
|
520 | - $status = $payment->get_status_label_html(); |
|
521 | - } |
|
518 | + $status = $payment->get_status_nicename(); |
|
519 | + if ( is_admin() ) { |
|
520 | + $status = $payment->get_status_label_html(); |
|
521 | + } |
|
522 | 522 | |
523 | - echo $status; |
|
524 | - break; |
|
523 | + echo $status; |
|
524 | + break; |
|
525 | 525 | |
526 | - case 'invoice': |
|
527 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
526 | + case 'invoice': |
|
527 | + $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
528 | 528 | |
529 | - if ( ! is_admin() ) { |
|
530 | - $link = esc_url( $payment->get_view_url() ); |
|
531 | - } |
|
529 | + if ( ! is_admin() ) { |
|
530 | + $link = esc_url( $payment->get_view_url() ); |
|
531 | + } |
|
532 | 532 | |
533 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
534 | - echo "<a href='$link'>$invoice</a>"; |
|
535 | - break; |
|
536 | - } |
|
533 | + $invoice = sanitize_text_field( $payment->get_number() ); |
|
534 | + echo "<a href='$link'>$invoice</a>"; |
|
535 | + break; |
|
536 | + } |
|
537 | 537 | |
538 | - echo '</td>'; |
|
538 | + echo '</td>'; |
|
539 | 539 | |
540 | - } |
|
540 | + } |
|
541 | 541 | |
542 | - echo '</tr>'; |
|
542 | + echo '</tr>'; |
|
543 | 543 | |
544 | - endforeach; |
|
545 | - ?> |
|
544 | + endforeach; |
|
545 | + ?> |
|
546 | 546 | |
547 | 547 | </tbody> |
548 | 548 | |
@@ -560,42 +560,42 @@ discard block |
||
560 | 560 | */ |
561 | 561 | function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
562 | 562 | |
563 | - // Fetch the subscription group. |
|
564 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
563 | + // Fetch the subscription group. |
|
564 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
565 | 565 | |
566 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
567 | - return; |
|
568 | - } |
|
566 | + if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
567 | + return; |
|
568 | + } |
|
569 | 569 | |
570 | - // Prepare table columns. |
|
571 | - $columns = apply_filters( |
|
572 | - 'getpaid_subscription_item_details_columns', |
|
573 | - array( |
|
574 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
575 | - 'price' => __( 'Price', 'invoicing' ), |
|
576 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
577 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
578 | - 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
579 | - 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
580 | - ), |
|
581 | - $subscription |
|
582 | - ); |
|
570 | + // Prepare table columns. |
|
571 | + $columns = apply_filters( |
|
572 | + 'getpaid_subscription_item_details_columns', |
|
573 | + array( |
|
574 | + 'item_name' => __( 'Item', 'invoicing' ), |
|
575 | + 'price' => __( 'Price', 'invoicing' ), |
|
576 | + 'tax' => __( 'Tax', 'invoicing' ), |
|
577 | + 'discount' => __( 'Discount', 'invoicing' ), |
|
578 | + 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
579 | + 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
580 | + ), |
|
581 | + $subscription |
|
582 | + ); |
|
583 | 583 | |
584 | - // Prepare the invoices. |
|
584 | + // Prepare the invoices. |
|
585 | 585 | |
586 | - $invoice = $subscription->get_parent_invoice(); |
|
586 | + $invoice = $subscription->get_parent_invoice(); |
|
587 | 587 | |
588 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
589 | - unset( $columns['tax'] ); |
|
590 | - } |
|
588 | + if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
589 | + unset( $columns['tax'] ); |
|
590 | + } |
|
591 | 591 | |
592 | - $table_class = 'w-100 bg-white'; |
|
592 | + $table_class = 'w-100 bg-white'; |
|
593 | 593 | |
594 | - if ( ! is_admin() ) { |
|
595 | - $table_class = 'table table-bordered table-striped'; |
|
596 | - } |
|
594 | + if ( ! is_admin() ) { |
|
595 | + $table_class = 'table table-bordered table-striped'; |
|
596 | + } |
|
597 | 597 | |
598 | - ?> |
|
598 | + ?> |
|
599 | 599 | <div class="m-0" style="overflow: auto;"> |
600 | 600 | |
601 | 601 | <table class="<?php echo $table_class; ?>"> |
@@ -604,14 +604,14 @@ discard block |
||
604 | 604 | <tr> |
605 | 605 | <?php |
606 | 606 | |
607 | - foreach ( $columns as $key => $label ) { |
|
608 | - $key = esc_attr( $key ); |
|
609 | - $label = sanitize_text_field( $label ); |
|
610 | - $class = 'text-left'; |
|
607 | + foreach ( $columns as $key => $label ) { |
|
608 | + $key = esc_attr( $key ); |
|
609 | + $label = sanitize_text_field( $label ); |
|
610 | + $class = 'text-left'; |
|
611 | 611 | |
612 | - echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
613 | - } |
|
614 | - ?> |
|
612 | + echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
613 | + } |
|
614 | + ?> |
|
615 | 615 | </tr> |
616 | 616 | </thead> |
617 | 617 | |
@@ -619,60 +619,60 @@ discard block |
||
619 | 619 | |
620 | 620 | <?php |
621 | 621 | |
622 | - foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
622 | + foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
623 | 623 | |
624 | - echo '<tr>'; |
|
624 | + echo '<tr>'; |
|
625 | 625 | |
626 | - foreach ( array_keys( $columns ) as $key ) { |
|
626 | + foreach ( array_keys( $columns ) as $key ) { |
|
627 | 627 | |
628 | - $class = 'text-left'; |
|
628 | + $class = 'text-left'; |
|
629 | 629 | |
630 | - echo "<td class='p-2 $class'>"; |
|
630 | + echo "<td class='p-2 $class'>"; |
|
631 | 631 | |
632 | - switch( $key ) { |
|
632 | + switch( $key ) { |
|
633 | 633 | |
634 | - case 'item_name': |
|
635 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
636 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
634 | + case 'item_name': |
|
635 | + $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
636 | + $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
637 | 637 | |
638 | - if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) { |
|
639 | - echo sanitize_text_field( $item_name ); |
|
640 | - } else { |
|
641 | - printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] ); |
|
642 | - } |
|
638 | + if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) { |
|
639 | + echo sanitize_text_field( $item_name ); |
|
640 | + } else { |
|
641 | + printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] ); |
|
642 | + } |
|
643 | 643 | |
644 | - break; |
|
644 | + break; |
|
645 | 645 | |
646 | - case 'price': |
|
647 | - echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
648 | - break; |
|
646 | + case 'price': |
|
647 | + echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
648 | + break; |
|
649 | 649 | |
650 | - case 'tax': |
|
651 | - echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
652 | - break; |
|
650 | + case 'tax': |
|
651 | + echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
652 | + break; |
|
653 | 653 | |
654 | - case 'discount': |
|
655 | - echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
656 | - break; |
|
654 | + case 'discount': |
|
655 | + echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
656 | + break; |
|
657 | 657 | |
658 | - case 'initial': |
|
659 | - echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
660 | - break; |
|
658 | + case 'initial': |
|
659 | + echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
660 | + break; |
|
661 | 661 | |
662 | - case 'recurring': |
|
663 | - echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
664 | - break; |
|
662 | + case 'recurring': |
|
663 | + echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
664 | + break; |
|
665 | 665 | |
666 | - } |
|
666 | + } |
|
667 | 667 | |
668 | - echo '</td>'; |
|
668 | + echo '</td>'; |
|
669 | 669 | |
670 | - } |
|
670 | + } |
|
671 | 671 | |
672 | - echo '</tr>'; |
|
672 | + echo '</tr>'; |
|
673 | 673 | |
674 | - endforeach; |
|
675 | - ?> |
|
674 | + endforeach; |
|
675 | + ?> |
|
676 | 676 | |
677 | 677 | </tbody> |
678 | 678 | |
@@ -690,34 +690,34 @@ discard block |
||
690 | 690 | */ |
691 | 691 | function getpaid_admin_subscription_related_subscriptions_metabox( $subscription ) { |
692 | 692 | |
693 | - // Fetch the subscription groups. |
|
694 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
695 | - |
|
696 | - if ( empty( $subscription_groups ) ) { |
|
697 | - return; |
|
698 | - } |
|
699 | - |
|
700 | - // Prepare table columns. |
|
701 | - $columns = apply_filters( |
|
702 | - 'getpaid_subscription_related_subscriptions_columns', |
|
703 | - array( |
|
704 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
705 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
706 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
707 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
708 | - 'item' => __( 'Items', 'invoicing' ), |
|
709 | - 'status' => __( 'Status', 'invoicing' ), |
|
710 | - ), |
|
711 | - $subscription |
|
712 | - ); |
|
713 | - |
|
714 | - $table_class = 'w-100 bg-white'; |
|
715 | - |
|
716 | - if ( ! is_admin() ) { |
|
717 | - $table_class = 'table table-bordered table-striped'; |
|
718 | - } |
|
719 | - |
|
720 | - ?> |
|
693 | + // Fetch the subscription groups. |
|
694 | + $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
695 | + |
|
696 | + if ( empty( $subscription_groups ) ) { |
|
697 | + return; |
|
698 | + } |
|
699 | + |
|
700 | + // Prepare table columns. |
|
701 | + $columns = apply_filters( |
|
702 | + 'getpaid_subscription_related_subscriptions_columns', |
|
703 | + array( |
|
704 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
705 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
706 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
707 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
708 | + 'item' => __( 'Items', 'invoicing' ), |
|
709 | + 'status' => __( 'Status', 'invoicing' ), |
|
710 | + ), |
|
711 | + $subscription |
|
712 | + ); |
|
713 | + |
|
714 | + $table_class = 'w-100 bg-white'; |
|
715 | + |
|
716 | + if ( ! is_admin() ) { |
|
717 | + $table_class = 'table table-bordered table-striped'; |
|
718 | + } |
|
719 | + |
|
720 | + ?> |
|
721 | 721 | <div class="m-0" style="overflow: auto;"> |
722 | 722 | |
723 | 723 | <table class="<?php echo $table_class; ?>"> |
@@ -726,14 +726,14 @@ discard block |
||
726 | 726 | <tr> |
727 | 727 | <?php |
728 | 728 | |
729 | - foreach ( $columns as $key => $label ) { |
|
730 | - $key = esc_attr( $key ); |
|
731 | - $label = sanitize_text_field( $label ); |
|
732 | - $class = 'text-left'; |
|
729 | + foreach ( $columns as $key => $label ) { |
|
730 | + $key = esc_attr( $key ); |
|
731 | + $label = sanitize_text_field( $label ); |
|
732 | + $class = 'text-left'; |
|
733 | 733 | |
734 | - echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
735 | - } |
|
736 | - ?> |
|
734 | + echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
|
735 | + } |
|
736 | + ?> |
|
737 | 737 | </tr> |
738 | 738 | </thead> |
739 | 739 | |
@@ -741,74 +741,74 @@ discard block |
||
741 | 741 | |
742 | 742 | <?php |
743 | 743 | |
744 | - foreach( $subscription_groups as $subscription_group ) : |
|
744 | + foreach( $subscription_groups as $subscription_group ) : |
|
745 | 745 | |
746 | - // Do not list current subscription. |
|
747 | - if ( (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
748 | - continue; |
|
749 | - } |
|
746 | + // Do not list current subscription. |
|
747 | + if ( (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
748 | + continue; |
|
749 | + } |
|
750 | 750 | |
751 | - // Ensure the subscription exists. |
|
752 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
751 | + // Ensure the subscription exists. |
|
752 | + $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
753 | 753 | |
754 | - if ( ! $_suscription->exists() ) { |
|
755 | - continue; |
|
756 | - } |
|
754 | + if ( ! $_suscription->exists() ) { |
|
755 | + continue; |
|
756 | + } |
|
757 | 757 | |
758 | - echo '<tr>'; |
|
758 | + echo '<tr>'; |
|
759 | 759 | |
760 | - foreach ( array_keys( $columns ) as $key ) { |
|
760 | + foreach ( array_keys( $columns ) as $key ) { |
|
761 | 761 | |
762 | - $class = 'text-left'; |
|
762 | + $class = 'text-left'; |
|
763 | 763 | |
764 | - echo "<td class='p-2 $class'>"; |
|
764 | + echo "<td class='p-2 $class'>"; |
|
765 | 765 | |
766 | - switch( $key ) { |
|
766 | + switch( $key ) { |
|
767 | 767 | |
768 | - case 'status': |
|
769 | - echo $_suscription->get_status_label_html(); |
|
770 | - break; |
|
768 | + case 'status': |
|
769 | + echo $_suscription->get_status_label_html(); |
|
770 | + break; |
|
771 | 771 | |
772 | - case 'item': |
|
773 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
774 | - echo implode( ' | ', $markup ); |
|
775 | - break; |
|
772 | + case 'item': |
|
773 | + $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
774 | + echo implode( ' | ', $markup ); |
|
775 | + break; |
|
776 | 776 | |
777 | - case 'renewals': |
|
778 | - $max_bills = $_suscription->get_bill_times(); |
|
779 | - echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
780 | - break; |
|
777 | + case 'renewals': |
|
778 | + $max_bills = $_suscription->get_bill_times(); |
|
779 | + echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
780 | + break; |
|
781 | 781 | |
782 | - case 'renewal_date': |
|
783 | - echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
784 | - break; |
|
782 | + case 'renewal_date': |
|
783 | + echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
784 | + break; |
|
785 | 785 | |
786 | - case 'start_date': |
|
787 | - echo getpaid_format_date_value( $_suscription->get_date_created() ); |
|
788 | - break; |
|
786 | + case 'start_date': |
|
787 | + echo getpaid_format_date_value( $_suscription->get_date_created() ); |
|
788 | + break; |
|
789 | 789 | |
790 | - case 'subscription': |
|
791 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
792 | - printf( |
|
793 | - '%1$s#%2$s%3$s', |
|
794 | - '<a href="' . esc_url( $url ) . '">', |
|
795 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
796 | - '</a>' |
|
797 | - ); |
|
790 | + case 'subscription': |
|
791 | + $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
792 | + printf( |
|
793 | + '%1$s#%2$s%3$s', |
|
794 | + '<a href="' . esc_url( $url ) . '">', |
|
795 | + '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
796 | + '</a>' |
|
797 | + ); |
|
798 | 798 | |
799 | - echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
800 | - break; |
|
799 | + echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
800 | + break; |
|
801 | 801 | |
802 | - } |
|
802 | + } |
|
803 | 803 | |
804 | - echo '</td>'; |
|
804 | + echo '</td>'; |
|
805 | 805 | |
806 | - } |
|
806 | + } |
|
807 | 807 | |
808 | - echo '</tr>'; |
|
808 | + echo '</tr>'; |
|
809 | 809 | |
810 | - endforeach; |
|
811 | - ?> |
|
810 | + endforeach; |
|
811 | + ?> |
|
812 | 812 | |
813 | 813 | </tbody> |
814 | 814 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | * Contains functions that display the subscriptions admin page. |
4 | 4 | */ |
5 | 5 | |
6 | -defined( 'ABSPATH' ) || exit; |
|
6 | +defined('ABSPATH') || exit; |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * Render the Subscriptions page |
@@ -17,22 +17,22 @@ discard block |
||
17 | 17 | ?> |
18 | 18 | |
19 | 19 | <div class="wrap"> |
20 | - <h1><?php echo esc_html( get_admin_page_title() ); ?></h1> |
|
20 | + <h1><?php echo esc_html(get_admin_page_title()); ?></h1> |
|
21 | 21 | <div class="bsui"> |
22 | 22 | |
23 | 23 | <?php |
24 | 24 | |
25 | 25 | // Verify user permissions. |
26 | - if ( ! wpinv_current_user_can_manage_invoicing() ) { |
|
26 | + if (!wpinv_current_user_can_manage_invoicing()) { |
|
27 | 27 | |
28 | 28 | echo aui()->alert( |
29 | 29 | array( |
30 | 30 | 'type' => 'danger', |
31 | - 'content' => __( 'You are not permitted to view this page.', 'invoicing' ), |
|
31 | + 'content' => __('You are not permitted to view this page.', 'invoicing'), |
|
32 | 32 | ) |
33 | 33 | ); |
34 | 34 | |
35 | - } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) { |
|
35 | + } else if (!empty($_GET['id']) && is_numeric($_GET['id'])) { |
|
36 | 36 | |
37 | 37 | // Display a single subscription. |
38 | 38 | wpinv_recurring_subscription_details(); |
@@ -81,13 +81,13 @@ discard block |
||
81 | 81 | function wpinv_recurring_subscription_details() { |
82 | 82 | |
83 | 83 | // Fetch the subscription. |
84 | - $sub = new WPInv_Subscription( (int) $_GET['id'] ); |
|
85 | - if ( ! $sub->exists() ) { |
|
84 | + $sub = new WPInv_Subscription((int) $_GET['id']); |
|
85 | + if (!$sub->exists()) { |
|
86 | 86 | |
87 | 87 | echo aui()->alert( |
88 | 88 | array( |
89 | 89 | 'type' => 'danger', |
90 | - 'content' => __( 'Subscription not found.', 'invoicing' ), |
|
90 | + 'content' => __('Subscription not found.', 'invoicing'), |
|
91 | 91 | ) |
92 | 92 | ); |
93 | 93 | |
@@ -95,45 +95,45 @@ discard block |
||
95 | 95 | } |
96 | 96 | |
97 | 97 | // Use metaboxes to display the subscription details. |
98 | - add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' ); |
|
99 | - add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' ); |
|
98 | + add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high'); |
|
99 | + add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side'); |
|
100 | 100 | |
101 | 101 | $subscription_id = $sub->get_id(); |
102 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() ); |
|
103 | - $subscription_group = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) ); |
|
102 | + $subscription_groups = getpaid_get_invoice_subscription_groups($sub->get_parent_invoice_id()); |
|
103 | + $subscription_group = wp_list_filter($subscription_groups, compact('subscription_id')); |
|
104 | 104 | |
105 | - if ( 1 < count( $subscription_groups ) ) { |
|
106 | - add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' ); |
|
105 | + if (1 < count($subscription_groups)) { |
|
106 | + add_meta_box('getpaid_admin_subscription_related_subscriptions_metabox', __('Related Subscriptions', 'invoicing'), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced'); |
|
107 | 107 | } |
108 | 108 | |
109 | - if ( ! empty( $subscription_group ) ) { |
|
110 | - add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' ); |
|
109 | + if (!empty($subscription_group)) { |
|
110 | + add_meta_box('getpaid_admin_subscription_item_details_metabox', __('Subscription Items', 'invoicing'), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low'); |
|
111 | 111 | } |
112 | 112 | |
113 | - add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' ); |
|
113 | + add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Related Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced'); |
|
114 | 114 | |
115 | - do_action( 'getpaid_admin_single_subscription_register_metabox', $sub ); |
|
115 | + do_action('getpaid_admin_single_subscription_register_metabox', $sub); |
|
116 | 116 | |
117 | 117 | ?> |
118 | 118 | |
119 | - <form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>"> |
|
119 | + <form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>"> |
|
120 | 120 | |
121 | - <?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?> |
|
122 | - <?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?> |
|
123 | - <?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?> |
|
121 | + <?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?> |
|
122 | + <?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?> |
|
123 | + <?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?> |
|
124 | 124 | <input type="hidden" name="getpaid-admin-action" value="update_single_subscription" /> |
125 | - <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" /> |
|
125 | + <input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" /> |
|
126 | 126 | |
127 | 127 | <div id="poststuff"> |
128 | 128 | <div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>"> |
129 | 129 | |
130 | 130 | <div id="postbox-container-1" class="postbox-container"> |
131 | - <?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?> |
|
131 | + <?php do_meta_boxes(get_current_screen(), 'side', $sub); ?> |
|
132 | 132 | </div> |
133 | 133 | |
134 | 134 | <div id="postbox-container-2" class="postbox-container"> |
135 | - <?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?> |
|
136 | - <?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?> |
|
135 | + <?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?> |
|
136 | + <?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?> |
|
137 | 137 | </div> |
138 | 138 | |
139 | 139 | </div> |
@@ -152,44 +152,44 @@ discard block |
||
152 | 152 | * |
153 | 153 | * @param WPInv_Subscription $sub |
154 | 154 | */ |
155 | -function getpaid_admin_subscription_details_metabox( $sub ) { |
|
155 | +function getpaid_admin_subscription_details_metabox($sub) { |
|
156 | 156 | |
157 | 157 | // Subscription items. |
158 | - $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() ); |
|
159 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
158 | + $subscription_group = getpaid_get_invoice_subscription_group($sub->get_parent_invoice_id(), $sub->get_id()); |
|
159 | + $items_count = empty($subscription_group) ? 1 : count($subscription_group['items']); |
|
160 | 160 | |
161 | 161 | // Prepare subscription detail columns. |
162 | 162 | $fields = apply_filters( |
163 | 163 | 'getpaid_subscription_admin_page_fields', |
164 | 164 | array( |
165 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
166 | - 'customer' => __( 'Customer', 'invoicing' ), |
|
167 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
168 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
169 | - 'renews_on' => __( 'Next Payment', 'invoicing' ), |
|
170 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
171 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
172 | - 'gateway' => __( 'Payment Method', 'invoicing' ), |
|
173 | - 'profile_id' => __( 'Profile ID', 'invoicing' ), |
|
174 | - 'status' => __( 'Status', 'invoicing' ), |
|
165 | + 'subscription' => __('Subscription', 'invoicing'), |
|
166 | + 'customer' => __('Customer', 'invoicing'), |
|
167 | + 'amount' => __('Amount', 'invoicing'), |
|
168 | + 'start_date' => __('Start Date', 'invoicing'), |
|
169 | + 'renews_on' => __('Next Payment', 'invoicing'), |
|
170 | + 'renewals' => __('Payments', 'invoicing'), |
|
171 | + 'item' => _n('Item', 'Items', $items_count, 'invoicing'), |
|
172 | + 'gateway' => __('Payment Method', 'invoicing'), |
|
173 | + 'profile_id' => __('Profile ID', 'invoicing'), |
|
174 | + 'status' => __('Status', 'invoicing'), |
|
175 | 175 | ) |
176 | 176 | ); |
177 | 177 | |
178 | - if ( ! $sub->is_active() ) { |
|
178 | + if (!$sub->is_active()) { |
|
179 | 179 | |
180 | - if ( isset( $fields['renews_on'] ) ) { |
|
181 | - unset( $fields['renews_on'] ); |
|
180 | + if (isset($fields['renews_on'])) { |
|
181 | + unset($fields['renews_on']); |
|
182 | 182 | } |
183 | 183 | |
184 | - if ( isset( $fields['gateway'] ) ) { |
|
185 | - unset( $fields['gateway'] ); |
|
184 | + if (isset($fields['gateway'])) { |
|
185 | + unset($fields['gateway']); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
189 | 189 | |
190 | 190 | $profile_id = $sub->get_profile_id(); |
191 | - if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) { |
|
192 | - unset( $fields['profile_id'] ); |
|
191 | + if (empty($profile_id) && isset($fields['profile_id'])) { |
|
192 | + unset($fields['profile_id']); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | ?> |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | <table class="table table-borderless" style="font-size: 14px;"> |
198 | 198 | <tbody> |
199 | 199 | |
200 | - <?php foreach ( $fields as $key => $label ) : ?> |
|
200 | + <?php foreach ($fields as $key => $label) : ?> |
|
201 | 201 | |
202 | - <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>"> |
|
202 | + <tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>"> |
|
203 | 203 | |
204 | 204 | <th class="w-25" style="font-weight: 500;"> |
205 | - <?php echo sanitize_text_field( $label ); ?> |
|
205 | + <?php echo sanitize_text_field($label); ?> |
|
206 | 206 | </th> |
207 | 207 | |
208 | 208 | <td class="w-75 text-muted"> |
209 | - <?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub, $subscription_group ); ?> |
|
209 | + <?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub, $subscription_group); ?> |
|
210 | 210 | </td> |
211 | 211 | |
212 | 212 | </tr> |
@@ -224,129 +224,129 @@ discard block |
||
224 | 224 | * |
225 | 225 | * @param WPInv_Subscription $subscription |
226 | 226 | */ |
227 | -function getpaid_admin_subscription_metabox_display_customer( $subscription ) { |
|
227 | +function getpaid_admin_subscription_metabox_display_customer($subscription) { |
|
228 | 228 | |
229 | - $username = __( '(Missing User)', 'invoicing' ); |
|
229 | + $username = __('(Missing User)', 'invoicing'); |
|
230 | 230 | |
231 | - $user = get_userdata( $subscription->get_customer_id() ); |
|
232 | - if ( $user ) { |
|
231 | + $user = get_userdata($subscription->get_customer_id()); |
|
232 | + if ($user) { |
|
233 | 233 | |
234 | 234 | $username = sprintf( |
235 | 235 | '<a href="user-edit.php?user_id=%s">%s</a>', |
236 | - absint( $user->ID ), |
|
237 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
236 | + absint($user->ID), |
|
237 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
238 | 238 | ); |
239 | 239 | |
240 | 240 | } |
241 | 241 | |
242 | 242 | echo $username; |
243 | 243 | } |
244 | -add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' ); |
|
244 | +add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer'); |
|
245 | 245 | |
246 | 246 | /** |
247 | 247 | * Displays the subscription amount. |
248 | 248 | * |
249 | 249 | * @param WPInv_Subscription $subscription |
250 | 250 | */ |
251 | -function getpaid_admin_subscription_metabox_display_amount( $subscription ) { |
|
252 | - $amount = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) ); |
|
251 | +function getpaid_admin_subscription_metabox_display_amount($subscription) { |
|
252 | + $amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription)); |
|
253 | 253 | echo "<span>$amount</span>"; |
254 | 254 | } |
255 | -add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' ); |
|
255 | +add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount'); |
|
256 | 256 | |
257 | 257 | /** |
258 | 258 | * Displays the subscription id. |
259 | 259 | * |
260 | 260 | * @param WPInv_Subscription $subscription |
261 | 261 | */ |
262 | -function getpaid_admin_subscription_metabox_display_id( $subscription ) { |
|
263 | - echo '#' . absint( $subscription->get_id() ); |
|
262 | +function getpaid_admin_subscription_metabox_display_id($subscription) { |
|
263 | + echo '#' . absint($subscription->get_id()); |
|
264 | 264 | } |
265 | -add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' ); |
|
265 | +add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id'); |
|
266 | 266 | |
267 | 267 | /** |
268 | 268 | * Displays the subscription renewal date. |
269 | 269 | * |
270 | 270 | * @param WPInv_Subscription $subscription |
271 | 271 | */ |
272 | -function getpaid_admin_subscription_metabox_display_start_date( $subscription ) { |
|
273 | - echo getpaid_format_date_value( $subscription->get_date_created() ); |
|
272 | +function getpaid_admin_subscription_metabox_display_start_date($subscription) { |
|
273 | + echo getpaid_format_date_value($subscription->get_date_created()); |
|
274 | 274 | } |
275 | -add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' ); |
|
275 | +add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date'); |
|
276 | 276 | |
277 | 277 | /** |
278 | 278 | * Displays the subscription renewal date. |
279 | 279 | * |
280 | 280 | * @param WPInv_Subscription $subscription |
281 | 281 | */ |
282 | -function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) { |
|
283 | - echo getpaid_format_date_value( $subscription->get_expiration() ); |
|
282 | +function getpaid_admin_subscription_metabox_display_renews_on($subscription) { |
|
283 | + echo getpaid_format_date_value($subscription->get_expiration()); |
|
284 | 284 | } |
285 | -add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' ); |
|
285 | +add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on'); |
|
286 | 286 | |
287 | 287 | /** |
288 | 288 | * Displays the subscription renewal count. |
289 | 289 | * |
290 | 290 | * @param WPInv_Subscription $subscription |
291 | 291 | */ |
292 | -function getpaid_admin_subscription_metabox_display_renewals( $subscription ) { |
|
292 | +function getpaid_admin_subscription_metabox_display_renewals($subscription) { |
|
293 | 293 | $max_bills = $subscription->get_bill_times(); |
294 | - echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
294 | + echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
295 | 295 | } |
296 | -add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' ); |
|
296 | +add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals'); |
|
297 | 297 | /** |
298 | 298 | * Displays the subscription item. |
299 | 299 | * |
300 | 300 | * @param WPInv_Subscription $subscription |
301 | 301 | * @param false|array $subscription_group |
302 | 302 | */ |
303 | -function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) { |
|
303 | +function getpaid_admin_subscription_metabox_display_item($subscription, $subscription_group = false) { |
|
304 | 304 | |
305 | - if ( empty( $subscription_group ) ) { |
|
306 | - echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() ); |
|
305 | + if (empty($subscription_group)) { |
|
306 | + echo WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id()); |
|
307 | 307 | return; |
308 | 308 | } |
309 | 309 | |
310 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
311 | - echo implode( ' | ', $markup ); |
|
310 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
311 | + echo implode(' | ', $markup); |
|
312 | 312 | |
313 | 313 | } |
314 | -add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 ); |
|
314 | +add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2); |
|
315 | 315 | |
316 | 316 | /** |
317 | 317 | * Displays the subscription gateway. |
318 | 318 | * |
319 | 319 | * @param WPInv_Subscription $subscription |
320 | 320 | */ |
321 | -function getpaid_admin_subscription_metabox_display_gateway( $subscription ) { |
|
321 | +function getpaid_admin_subscription_metabox_display_gateway($subscription) { |
|
322 | 322 | |
323 | 323 | $gateway = $subscription->get_gateway(); |
324 | 324 | |
325 | - if ( ! empty( $gateway ) ) { |
|
326 | - echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) ); |
|
325 | + if (!empty($gateway)) { |
|
326 | + echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway)); |
|
327 | 327 | } else { |
328 | 328 | echo "—"; |
329 | 329 | } |
330 | 330 | |
331 | 331 | } |
332 | -add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' ); |
|
332 | +add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway'); |
|
333 | 333 | |
334 | 334 | /** |
335 | 335 | * Displays the subscription status. |
336 | 336 | * |
337 | 337 | * @param WPInv_Subscription $subscription |
338 | 338 | */ |
339 | -function getpaid_admin_subscription_metabox_display_status( $subscription ) { |
|
339 | +function getpaid_admin_subscription_metabox_display_status($subscription) { |
|
340 | 340 | echo $subscription->get_status_label_html(); |
341 | 341 | } |
342 | -add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' ); |
|
342 | +add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status'); |
|
343 | 343 | |
344 | 344 | /** |
345 | 345 | * Displays the subscription profile id. |
346 | 346 | * |
347 | 347 | * @param WPInv_Subscription $subscription |
348 | 348 | */ |
349 | -function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) { |
|
349 | +function getpaid_admin_subscription_metabox_display_profile_id($subscription) { |
|
350 | 350 | |
351 | 351 | $profile_id = $subscription->get_profile_id(); |
352 | 352 | |
@@ -355,32 +355,32 @@ discard block |
||
355 | 355 | 'type' => 'text', |
356 | 356 | 'id' => 'wpinv_subscription_profile_id', |
357 | 357 | 'name' => 'wpinv_subscription_profile_id', |
358 | - 'label' => __( 'Profile Id', 'invoicing' ), |
|
358 | + 'label' => __('Profile Id', 'invoicing'), |
|
359 | 359 | 'label_type' => 'hidden', |
360 | - 'placeholder' => __( 'Profile Id', 'invoicing' ), |
|
361 | - 'value' => sanitize_text_field( $profile_id ), |
|
360 | + 'placeholder' => __('Profile Id', 'invoicing'), |
|
361 | + 'value' => sanitize_text_field($profile_id), |
|
362 | 362 | 'input_group_right' => '', |
363 | 363 | 'no_wrap' => true, |
364 | 364 | ) |
365 | 365 | ); |
366 | 366 | |
367 | - echo str_ireplace( 'form-control', 'regular-text', $input ); |
|
367 | + echo str_ireplace('form-control', 'regular-text', $input); |
|
368 | 368 | |
369 | - $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription ); |
|
370 | - if ( ! empty( $url ) ) { |
|
371 | - $url = esc_url_raw( $url ); |
|
372 | - echo ' <a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
369 | + $url = apply_filters('getpaid_remote_subscription_profile_url', '', $subscription); |
|
370 | + if (!empty($url)) { |
|
371 | + $url = esc_url_raw($url); |
|
372 | + echo ' <a href="' . $url . '" title="' . __('View in Gateway', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>'; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | } |
376 | -add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' ); |
|
376 | +add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id'); |
|
377 | 377 | |
378 | 378 | /** |
379 | 379 | * Displays the subscriptions update metabox. |
380 | 380 | * |
381 | 381 | * @param WPInv_Subscription $subscription |
382 | 382 | */ |
383 | -function getpaid_admin_subscription_update_metabox( $subscription ) { |
|
383 | +function getpaid_admin_subscription_update_metabox($subscription) { |
|
384 | 384 | |
385 | 385 | ?> |
386 | 386 | <div class="mt-3"> |
@@ -393,10 +393,10 @@ discard block |
||
393 | 393 | 'id' => 'subscription_status_update_select', |
394 | 394 | 'required' => true, |
395 | 395 | 'no_wrap' => false, |
396 | - 'label' => __( 'Subscription Status', 'invoicing' ), |
|
397 | - 'help_text' => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ), |
|
396 | + 'label' => __('Subscription Status', 'invoicing'), |
|
397 | + 'help_text' => __('Updating the status will trigger related actions and hooks', 'invoicing'), |
|
398 | 398 | 'select2' => true, |
399 | - 'value' => $subscription->get_status( 'edit' ), |
|
399 | + 'value' => $subscription->get_status('edit'), |
|
400 | 400 | ) |
401 | 401 | ); |
402 | 402 | ?> |
@@ -404,13 +404,13 @@ discard block |
||
404 | 404 | <div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;"> |
405 | 405 | |
406 | 406 | <?php |
407 | - submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false ); |
|
407 | + submit_button(__('Update', 'invoicing'), 'primary', 'submit', false); |
|
408 | 408 | |
409 | - $url = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) ); |
|
410 | - $anchor = __( 'Renew Subscription', 'invoicing' ); |
|
411 | - $title = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' ); |
|
409 | + $url = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce')); |
|
410 | + $anchor = __('Renew Subscription', 'invoicing'); |
|
411 | + $title = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing'); |
|
412 | 412 | |
413 | - if ( $subscription->is_active() ) { |
|
413 | + if ($subscription->is_active()) { |
|
414 | 414 | echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>"; |
415 | 415 | } |
416 | 416 | |
@@ -422,31 +422,31 @@ discard block |
||
422 | 422 | * |
423 | 423 | * @param WPInv_Subscription $subscription |
424 | 424 | */ |
425 | -function getpaid_admin_subscription_invoice_details_metabox( $subscription ) { |
|
425 | +function getpaid_admin_subscription_invoice_details_metabox($subscription) { |
|
426 | 426 | |
427 | 427 | $columns = apply_filters( |
428 | 428 | 'getpaid_subscription_related_invoices_columns', |
429 | 429 | array( |
430 | - 'invoice' => __( 'Invoice', 'invoicing' ), |
|
431 | - 'relationship' => __( 'Relationship', 'invoicing' ), |
|
432 | - 'date' => __( 'Date', 'invoicing' ), |
|
433 | - 'status' => __( 'Status', 'invoicing' ), |
|
434 | - 'total' => __( 'Total', 'invoicing' ), |
|
430 | + 'invoice' => __('Invoice', 'invoicing'), |
|
431 | + 'relationship' => __('Relationship', 'invoicing'), |
|
432 | + 'date' => __('Date', 'invoicing'), |
|
433 | + 'status' => __('Status', 'invoicing'), |
|
434 | + 'total' => __('Total', 'invoicing'), |
|
435 | 435 | ), |
436 | 436 | $subscription |
437 | 437 | ); |
438 | 438 | |
439 | 439 | // Prepare the invoices. |
440 | - $payments = $subscription->get_child_payments( ! is_admin() ); |
|
440 | + $payments = $subscription->get_child_payments(!is_admin()); |
|
441 | 441 | $parent = $subscription->get_parent_invoice(); |
442 | 442 | |
443 | - if ( $parent->get_id() ) { |
|
444 | - $payments = array_merge( array( $parent ), $payments ); |
|
443 | + if ($parent->get_id()) { |
|
444 | + $payments = array_merge(array($parent), $payments); |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | $table_class = 'w-100 bg-white'; |
448 | 448 | |
449 | - if ( ! is_admin() ) { |
|
449 | + if (!is_admin()) { |
|
450 | 450 | $table_class = 'table table-bordered table-striped'; |
451 | 451 | } |
452 | 452 | |
@@ -458,9 +458,9 @@ discard block |
||
458 | 458 | <thead> |
459 | 459 | <tr> |
460 | 460 | <?php |
461 | - foreach ( $columns as $key => $label ) { |
|
462 | - $key = esc_attr( $key ); |
|
463 | - $label = sanitize_text_field( $label ); |
|
461 | + foreach ($columns as $key => $label) { |
|
462 | + $key = esc_attr($key); |
|
463 | + $label = sanitize_text_field($label); |
|
464 | 464 | $class = 'text-left'; |
465 | 465 | |
466 | 466 | echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
@@ -471,52 +471,52 @@ discard block |
||
471 | 471 | |
472 | 472 | <tbody> |
473 | 473 | |
474 | - <?php if ( empty( $payments ) ) : ?> |
|
474 | + <?php if (empty($payments)) : ?> |
|
475 | 475 | <tr> |
476 | 476 | <td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted"> |
477 | - <?php _e( 'This subscription has no invoices.', 'invoicing' ); ?> |
|
477 | + <?php _e('This subscription has no invoices.', 'invoicing'); ?> |
|
478 | 478 | </td> |
479 | 479 | </tr> |
480 | 480 | <?php endif; ?> |
481 | 481 | |
482 | 482 | <?php |
483 | 483 | |
484 | - foreach( $payments as $payment ) : |
|
484 | + foreach ($payments as $payment) : |
|
485 | 485 | |
486 | 486 | // Ensure that we have an invoice. |
487 | - $payment = new WPInv_Invoice( $payment ); |
|
487 | + $payment = new WPInv_Invoice($payment); |
|
488 | 488 | |
489 | 489 | // Abort if the invoice is invalid. |
490 | - if ( ! $payment->get_id() ) { |
|
490 | + if (!$payment->get_id()) { |
|
491 | 491 | continue; |
492 | 492 | } |
493 | 493 | |
494 | 494 | echo '<tr>'; |
495 | 495 | |
496 | - foreach ( array_keys( $columns ) as $key ) { |
|
496 | + foreach (array_keys($columns) as $key) { |
|
497 | 497 | |
498 | 498 | $class = 'text-left'; |
499 | 499 | |
500 | 500 | echo "<td class='p-2 $class'>"; |
501 | 501 | |
502 | - switch( $key ) { |
|
502 | + switch ($key) { |
|
503 | 503 | |
504 | 504 | case 'total': |
505 | - echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>'; |
|
505 | + echo '<strong>' . wpinv_price($payment->get_total(), $payment->get_currency()) . '</strong>'; |
|
506 | 506 | break; |
507 | 507 | |
508 | 508 | case 'relationship': |
509 | - echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' ); |
|
509 | + echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing'); |
|
510 | 510 | break; |
511 | 511 | |
512 | 512 | case 'date': |
513 | - echo getpaid_format_date_value( $payment->get_date_created() ); |
|
513 | + echo getpaid_format_date_value($payment->get_date_created()); |
|
514 | 514 | break; |
515 | 515 | |
516 | 516 | case 'status': |
517 | 517 | |
518 | 518 | $status = $payment->get_status_nicename(); |
519 | - if ( is_admin() ) { |
|
519 | + if (is_admin()) { |
|
520 | 520 | $status = $payment->get_status_label_html(); |
521 | 521 | } |
522 | 522 | |
@@ -524,13 +524,13 @@ discard block |
||
524 | 524 | break; |
525 | 525 | |
526 | 526 | case 'invoice': |
527 | - $link = esc_url( get_edit_post_link( $payment->get_id() ) ); |
|
527 | + $link = esc_url(get_edit_post_link($payment->get_id())); |
|
528 | 528 | |
529 | - if ( ! is_admin() ) { |
|
530 | - $link = esc_url( $payment->get_view_url() ); |
|
529 | + if (!is_admin()) { |
|
530 | + $link = esc_url($payment->get_view_url()); |
|
531 | 531 | } |
532 | 532 | |
533 | - $invoice = sanitize_text_field( $payment->get_number() ); |
|
533 | + $invoice = sanitize_text_field($payment->get_number()); |
|
534 | 534 | echo "<a href='$link'>$invoice</a>"; |
535 | 535 | break; |
536 | 536 | } |
@@ -558,12 +558,12 @@ discard block |
||
558 | 558 | * |
559 | 559 | * @param WPInv_Subscription $subscription |
560 | 560 | */ |
561 | -function getpaid_admin_subscription_item_details_metabox( $subscription ) { |
|
561 | +function getpaid_admin_subscription_item_details_metabox($subscription) { |
|
562 | 562 | |
563 | 563 | // Fetch the subscription group. |
564 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() ); |
|
564 | + $subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_payment_id(), $subscription->get_id()); |
|
565 | 565 | |
566 | - if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) { |
|
566 | + if (empty($subscription_group) || empty($subscription_group['items'])) { |
|
567 | 567 | return; |
568 | 568 | } |
569 | 569 | |
@@ -571,12 +571,12 @@ discard block |
||
571 | 571 | $columns = apply_filters( |
572 | 572 | 'getpaid_subscription_item_details_columns', |
573 | 573 | array( |
574 | - 'item_name' => __( 'Item', 'invoicing' ), |
|
575 | - 'price' => __( 'Price', 'invoicing' ), |
|
576 | - 'tax' => __( 'Tax', 'invoicing' ), |
|
577 | - 'discount' => __( 'Discount', 'invoicing' ), |
|
578 | - 'initial' => __( 'Initial Amount', 'invoicing' ), |
|
579 | - 'recurring' => __( 'Recurring Amount', 'invoicing' ), |
|
574 | + 'item_name' => __('Item', 'invoicing'), |
|
575 | + 'price' => __('Price', 'invoicing'), |
|
576 | + 'tax' => __('Tax', 'invoicing'), |
|
577 | + 'discount' => __('Discount', 'invoicing'), |
|
578 | + 'initial' => __('Initial Amount', 'invoicing'), |
|
579 | + 'recurring' => __('Recurring Amount', 'invoicing'), |
|
580 | 580 | ), |
581 | 581 | $subscription |
582 | 582 | ); |
@@ -585,13 +585,13 @@ discard block |
||
585 | 585 | |
586 | 586 | $invoice = $subscription->get_parent_invoice(); |
587 | 587 | |
588 | - if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) { |
|
589 | - unset( $columns['tax'] ); |
|
588 | + if ((!wpinv_use_taxes() || !$invoice->is_taxable()) && isset($columns['tax'])) { |
|
589 | + unset($columns['tax']); |
|
590 | 590 | } |
591 | 591 | |
592 | 592 | $table_class = 'w-100 bg-white'; |
593 | 593 | |
594 | - if ( ! is_admin() ) { |
|
594 | + if (!is_admin()) { |
|
595 | 595 | $table_class = 'table table-bordered table-striped'; |
596 | 596 | } |
597 | 597 | |
@@ -604,9 +604,9 @@ discard block |
||
604 | 604 | <tr> |
605 | 605 | <?php |
606 | 606 | |
607 | - foreach ( $columns as $key => $label ) { |
|
608 | - $key = esc_attr( $key ); |
|
609 | - $label = sanitize_text_field( $label ); |
|
607 | + foreach ($columns as $key => $label) { |
|
608 | + $key = esc_attr($key); |
|
609 | + $label = sanitize_text_field($label); |
|
610 | 610 | $class = 'text-left'; |
611 | 611 | |
612 | 612 | echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
@@ -619,48 +619,48 @@ discard block |
||
619 | 619 | |
620 | 620 | <?php |
621 | 621 | |
622 | - foreach( $subscription_group['items'] as $subscription_group_item ) : |
|
622 | + foreach ($subscription_group['items'] as $subscription_group_item) : |
|
623 | 623 | |
624 | 624 | echo '<tr>'; |
625 | 625 | |
626 | - foreach ( array_keys( $columns ) as $key ) { |
|
626 | + foreach (array_keys($columns) as $key) { |
|
627 | 627 | |
628 | 628 | $class = 'text-left'; |
629 | 629 | |
630 | 630 | echo "<td class='p-2 $class'>"; |
631 | 631 | |
632 | - switch( $key ) { |
|
632 | + switch ($key) { |
|
633 | 633 | |
634 | 634 | case 'item_name': |
635 | - $item_name = get_the_title( $subscription_group_item['item_id'] ); |
|
636 | - $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name; |
|
635 | + $item_name = get_the_title($subscription_group_item['item_id']); |
|
636 | + $item_name = empty($item_name) ? $subscription_group_item['item_name'] : $item_name; |
|
637 | 637 | |
638 | - if ( $invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity'] ) { |
|
639 | - echo sanitize_text_field( $item_name ); |
|
638 | + if ($invoice->get_template() == 'amount' || 1 === (int) $subscription_group_item['quantity']) { |
|
639 | + echo sanitize_text_field($item_name); |
|
640 | 640 | } else { |
641 | - printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (int) $subscription_group_item['quantity'] ); |
|
641 | + printf('%1$s x %2$d', sanitize_text_field($item_name), (int) $subscription_group_item['quantity']); |
|
642 | 642 | } |
643 | 643 | |
644 | 644 | break; |
645 | 645 | |
646 | 646 | case 'price': |
647 | - echo wpinv_price( $subscription_group_item['price'], $invoice->get_currency() ); |
|
647 | + echo wpinv_price($subscription_group_item['price'], $invoice->get_currency()); |
|
648 | 648 | break; |
649 | 649 | |
650 | 650 | case 'tax': |
651 | - echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() ); |
|
651 | + echo wpinv_price($subscription_group_item['tax'], $invoice->get_currency()); |
|
652 | 652 | break; |
653 | 653 | |
654 | 654 | case 'discount': |
655 | - echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() ); |
|
655 | + echo wpinv_price($subscription_group_item['discount'], $invoice->get_currency()); |
|
656 | 656 | break; |
657 | 657 | |
658 | 658 | case 'initial': |
659 | - echo wpinv_price( $subscription_group_item['subtotal'], $invoice->get_currency() ); |
|
659 | + echo wpinv_price($subscription_group_item['subtotal'], $invoice->get_currency()); |
|
660 | 660 | break; |
661 | 661 | |
662 | 662 | case 'recurring': |
663 | - echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>'; |
|
663 | + echo '<strong>' . wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency()) . '</strong>'; |
|
664 | 664 | break; |
665 | 665 | |
666 | 666 | } |
@@ -688,12 +688,12 @@ discard block |
||
688 | 688 | * |
689 | 689 | * @param WPInv_Subscription $subscription |
690 | 690 | */ |
691 | -function getpaid_admin_subscription_related_subscriptions_metabox( $subscription ) { |
|
691 | +function getpaid_admin_subscription_related_subscriptions_metabox($subscription) { |
|
692 | 692 | |
693 | 693 | // Fetch the subscription groups. |
694 | - $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() ); |
|
694 | + $subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_payment_id()); |
|
695 | 695 | |
696 | - if ( empty( $subscription_groups ) ) { |
|
696 | + if (empty($subscription_groups)) { |
|
697 | 697 | return; |
698 | 698 | } |
699 | 699 | |
@@ -701,19 +701,19 @@ discard block |
||
701 | 701 | $columns = apply_filters( |
702 | 702 | 'getpaid_subscription_related_subscriptions_columns', |
703 | 703 | array( |
704 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
705 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
706 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
707 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
708 | - 'item' => __( 'Items', 'invoicing' ), |
|
709 | - 'status' => __( 'Status', 'invoicing' ), |
|
704 | + 'subscription' => __('Subscription', 'invoicing'), |
|
705 | + 'start_date' => __('Start Date', 'invoicing'), |
|
706 | + 'renewal_date' => __('Next Payment', 'invoicing'), |
|
707 | + 'renewals' => __('Payments', 'invoicing'), |
|
708 | + 'item' => __('Items', 'invoicing'), |
|
709 | + 'status' => __('Status', 'invoicing'), |
|
710 | 710 | ), |
711 | 711 | $subscription |
712 | 712 | ); |
713 | 713 | |
714 | 714 | $table_class = 'w-100 bg-white'; |
715 | 715 | |
716 | - if ( ! is_admin() ) { |
|
716 | + if (!is_admin()) { |
|
717 | 717 | $table_class = 'table table-bordered table-striped'; |
718 | 718 | } |
719 | 719 | |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | <tr> |
727 | 727 | <?php |
728 | 728 | |
729 | - foreach ( $columns as $key => $label ) { |
|
730 | - $key = esc_attr( $key ); |
|
731 | - $label = sanitize_text_field( $label ); |
|
729 | + foreach ($columns as $key => $label) { |
|
730 | + $key = esc_attr($key); |
|
731 | + $label = sanitize_text_field($label); |
|
732 | 732 | $class = 'text-left'; |
733 | 733 | |
734 | 734 | echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>"; |
@@ -741,62 +741,62 @@ discard block |
||
741 | 741 | |
742 | 742 | <?php |
743 | 743 | |
744 | - foreach( $subscription_groups as $subscription_group ) : |
|
744 | + foreach ($subscription_groups as $subscription_group) : |
|
745 | 745 | |
746 | 746 | // Do not list current subscription. |
747 | - if ( (int) $subscription_group['subscription_id'] === $subscription->get_id() ) { |
|
747 | + if ((int) $subscription_group['subscription_id'] === $subscription->get_id()) { |
|
748 | 748 | continue; |
749 | 749 | } |
750 | 750 | |
751 | 751 | // Ensure the subscription exists. |
752 | - $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] ); |
|
752 | + $_suscription = new WPInv_Subscription($subscription_group['subscription_id']); |
|
753 | 753 | |
754 | - if ( ! $_suscription->exists() ) { |
|
754 | + if (!$_suscription->exists()) { |
|
755 | 755 | continue; |
756 | 756 | } |
757 | 757 | |
758 | 758 | echo '<tr>'; |
759 | 759 | |
760 | - foreach ( array_keys( $columns ) as $key ) { |
|
760 | + foreach (array_keys($columns) as $key) { |
|
761 | 761 | |
762 | 762 | $class = 'text-left'; |
763 | 763 | |
764 | 764 | echo "<td class='p-2 $class'>"; |
765 | 765 | |
766 | - switch( $key ) { |
|
766 | + switch ($key) { |
|
767 | 767 | |
768 | 768 | case 'status': |
769 | 769 | echo $_suscription->get_status_label_html(); |
770 | 770 | break; |
771 | 771 | |
772 | 772 | case 'item': |
773 | - $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
774 | - echo implode( ' | ', $markup ); |
|
773 | + $markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
774 | + echo implode(' | ', $markup); |
|
775 | 775 | break; |
776 | 776 | |
777 | 777 | case 'renewals': |
778 | 778 | $max_bills = $_suscription->get_bill_times(); |
779 | - echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
779 | + echo $_suscription->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
780 | 780 | break; |
781 | 781 | |
782 | 782 | case 'renewal_date': |
783 | - echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "—"; |
|
783 | + echo $_suscription->is_active() ? getpaid_format_date_value($_suscription->get_expiration()) : "—"; |
|
784 | 784 | break; |
785 | 785 | |
786 | 786 | case 'start_date': |
787 | - echo getpaid_format_date_value( $_suscription->get_date_created() ); |
|
787 | + echo getpaid_format_date_value($_suscription->get_date_created()); |
|
788 | 788 | break; |
789 | 789 | |
790 | 790 | case 'subscription': |
791 | - $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url(); |
|
791 | + $url = is_admin() ? admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($_suscription->get_id())) : $_suscription->get_view_url(); |
|
792 | 792 | printf( |
793 | 793 | '%1$s#%2$s%3$s', |
794 | - '<a href="' . esc_url( $url ) . '">', |
|
795 | - '<strong>' . intval( $_suscription->get_id() ) . '</strong>', |
|
794 | + '<a href="' . esc_url($url) . '">', |
|
795 | + '<strong>' . intval($_suscription->get_id()) . '</strong>', |
|
796 | 796 | '</a>' |
797 | 797 | ); |
798 | 798 | |
799 | - echo WPInv_Subscriptions_List_Table::column_amount( $_suscription ); |
|
799 | + echo WPInv_Subscriptions_List_Table::column_amount($_suscription); |
|
800 | 800 | break; |
801 | 801 | |
802 | 802 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | if ( ! defined( 'ABSPATH' ) ) exit; |
7 | 7 | |
8 | 8 | if ( ! class_exists( 'WP_List_Table' ) ) { |
9 | - include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
9 | + include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php'; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | /** |
@@ -14,406 +14,406 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_List_Table extends WP_List_Table { |
16 | 16 | |
17 | - /** |
|
18 | - * URL of this page |
|
19 | - * |
|
20 | - * @var string |
|
21 | - * @since 1.0.19 |
|
22 | - */ |
|
23 | - public $base_url; |
|
24 | - |
|
25 | - /** |
|
26 | - * Query |
|
27 | - * |
|
28 | - * @var GetPaid_Subscriptions_Query |
|
29 | - * @since 1.0.19 |
|
30 | - */ |
|
31 | - public $query; |
|
32 | - |
|
33 | - /** |
|
34 | - * Total subscriptions |
|
35 | - * |
|
36 | - * @var string |
|
37 | - * @since 1.0.0 |
|
38 | - */ |
|
39 | - public $total_count; |
|
40 | - |
|
41 | - /** |
|
42 | - * Current status subscriptions |
|
43 | - * |
|
44 | - * @var string |
|
45 | - * @since 1.0.0 |
|
46 | - */ |
|
47 | - public $current_total_count; |
|
48 | - |
|
49 | - /** |
|
50 | - * Status counts |
|
51 | - * |
|
52 | - * @var array |
|
53 | - * @since 1.0.19 |
|
54 | - */ |
|
55 | - public $status_counts; |
|
56 | - |
|
57 | - /** |
|
58 | - * Number of results to show per page |
|
59 | - * |
|
60 | - * @var int |
|
61 | - * @since 1.0.0 |
|
62 | - */ |
|
63 | - public $per_page = 10; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor function. |
|
67 | - */ |
|
68 | - public function __construct() { |
|
69 | - |
|
70 | - parent::__construct( |
|
71 | - array( |
|
72 | - 'singular' => 'subscription', |
|
73 | - 'plural' => 'subscriptions', |
|
74 | - ) |
|
75 | - ); |
|
76 | - |
|
77 | - $this->process_bulk_action(); |
|
78 | - |
|
79 | - $this->prepare_query(); |
|
80 | - |
|
81 | - $this->base_url = remove_query_arg( 'status' ); |
|
82 | - |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * Prepares the display query |
|
87 | - */ |
|
88 | - public function prepare_query() { |
|
89 | - |
|
90 | - // Prepare query args. |
|
91 | - $query = array( |
|
92 | - 'number' => $this->per_page, |
|
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', |
|
97 | - ); |
|
98 | - |
|
99 | - // Prepare class properties. |
|
100 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
101 | - $this->total_count = $this->query->get_total(); |
|
102 | - $this->current_total_count = $this->query->get_total(); |
|
103 | - $this->items = $this->query->get_results(); |
|
104 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
105 | - |
|
106 | - if ( 'all' != $query['status'] ) { |
|
107 | - unset( $query['status'] ); |
|
108 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
109 | - } |
|
110 | - |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Gets the list of views available on this table. |
|
115 | - * |
|
116 | - * The format is an associative array: |
|
117 | - * - `'id' => 'link'` |
|
118 | - * |
|
119 | - * @since 1.0.0 |
|
120 | - * |
|
121 | - * @return array |
|
122 | - */ |
|
123 | - public function get_views() { |
|
124 | - |
|
125 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
126 | - $views = array( |
|
127 | - |
|
128 | - 'all' => sprintf( |
|
129 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
130 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
131 | - $current === 'all' ? ' class="current"' : '', |
|
132 | - __('All','invoicing' ), |
|
133 | - $this->total_count |
|
134 | - ) |
|
135 | - |
|
136 | - ); |
|
137 | - |
|
138 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
139 | - |
|
140 | - $views[ $status ] = sprintf( |
|
141 | - '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
142 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
143 | - $current === $status ? ' class="current"' : '', |
|
144 | - sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
145 | - $count |
|
146 | - ); |
|
147 | - |
|
148 | - } |
|
149 | - |
|
150 | - return $views; |
|
151 | - |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Render most columns |
|
156 | - * |
|
157 | - * @access private |
|
158 | - * @since 1.0.0 |
|
159 | - * @return string |
|
160 | - */ |
|
161 | - public function column_default( $item, $column_name ) { |
|
162 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
163 | - } |
|
164 | - |
|
165 | - /** |
|
166 | - * This is how checkbox column renders. |
|
167 | - * |
|
168 | - * @param WPInv_Subscription $item |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function column_cb( $item ) { |
|
172 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Status column |
|
177 | - * |
|
178 | - * @param WPInv_Subscription $item |
|
179 | - * @since 1.0.0 |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function column_status( $item ) { |
|
183 | - return $item->get_status_label_html(); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Subscription column |
|
188 | - * |
|
189 | - * @param WPInv_Subscription $item |
|
190 | - * @since 1.0.0 |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function column_subscription( $item ) { |
|
194 | - |
|
195 | - $username = __( '(Missing User)', 'invoicing' ); |
|
196 | - |
|
197 | - $user = get_userdata( $item->get_customer_id() ); |
|
198 | - if ( $user ) { |
|
199 | - |
|
200 | - $username = sprintf( |
|
201 | - '<a href="user-edit.php?user_id=%s">%s</a>', |
|
202 | - absint( $user->ID ), |
|
203 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
204 | - ); |
|
205 | - |
|
206 | - } |
|
207 | - |
|
208 | - // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
209 | - $column_content = sprintf( |
|
210 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
211 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
212 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
213 | - $username |
|
214 | - ); |
|
215 | - |
|
216 | - $row_actions = array(); |
|
217 | - |
|
218 | - // View subscription. |
|
219 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
220 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
221 | - |
|
222 | - // View invoice. |
|
223 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
224 | - |
|
225 | - if ( ! empty( $invoice ) ) { |
|
226 | - $invoice_url = get_edit_post_link( $invoice ); |
|
227 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
228 | - } |
|
229 | - |
|
230 | - $delete_url = esc_url( |
|
231 | - wp_nonce_url( |
|
232 | - add_query_arg( |
|
233 | - array( |
|
234 | - 'getpaid-admin-action' => 'subscription_manual_delete', |
|
235 | - 'id' => $item->get_id(), |
|
236 | - ) |
|
237 | - ), |
|
238 | - 'getpaid-nonce', |
|
239 | - 'getpaid-nonce' |
|
240 | - ) |
|
241 | - ); |
|
242 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
243 | - |
|
244 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
245 | - |
|
246 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
247 | - } |
|
248 | - |
|
249 | - /** |
|
250 | - * Renewal date column |
|
251 | - * |
|
252 | - * @param WPInv_Subscription $item |
|
253 | - * @since 1.0.0 |
|
254 | - * @return string |
|
255 | - */ |
|
256 | - public function column_renewal_date( $item ) { |
|
257 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * Start date column |
|
262 | - * |
|
263 | - * @param WPInv_Subscription $item |
|
264 | - * @since 1.0.0 |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function column_start_date( $item ) { |
|
268 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
269 | - } |
|
270 | - |
|
271 | - /** |
|
272 | - * Amount column |
|
273 | - * |
|
274 | - * @param WPInv_Subscription $item |
|
275 | - * @since 1.0.19 |
|
276 | - * @return string |
|
277 | - */ |
|
278 | - public static function column_amount( $item ) { |
|
279 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
280 | - return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
281 | - } |
|
282 | - |
|
283 | - /** |
|
284 | - * Billing Times column |
|
285 | - * |
|
286 | - * @param WPInv_Subscription $item |
|
287 | - * @since 1.0.0 |
|
288 | - * @return string |
|
289 | - */ |
|
290 | - public function column_renewals( $item ) { |
|
291 | - $max_bills = $item->get_bill_times(); |
|
292 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
293 | - } |
|
294 | - |
|
295 | - /** |
|
296 | - * Product ID column |
|
297 | - * |
|
298 | - * @param WPInv_Subscription $item |
|
299 | - * @since 1.0.0 |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function column_item( $item ) { |
|
303 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
304 | - |
|
305 | - if ( empty( $subscription_group ) ) { |
|
306 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
307 | - } |
|
308 | - |
|
309 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
310 | - return implode( ' | ', $markup ); |
|
311 | - |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Generates the items markup. |
|
316 | - * |
|
317 | - * @param int $item_id |
|
318 | - * @since 1.0.0 |
|
319 | - * @return string |
|
320 | - */ |
|
321 | - public static function generate_item_markup( $item_id ) { |
|
322 | - $item = get_post( $item_id ); |
|
323 | - |
|
324 | - if ( ! empty( $item ) ) { |
|
325 | - $link = get_edit_post_link( $item ); |
|
326 | - $link = esc_url( $link ); |
|
327 | - $name = esc_html( get_the_title( $item ) ); |
|
328 | - return "<a href='$link'>$name</a>"; |
|
329 | - } else { |
|
330 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
331 | - } |
|
332 | - |
|
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Retrieve the current page number |
|
337 | - * |
|
338 | - * @return int |
|
339 | - */ |
|
340 | - public function get_paged() { |
|
341 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Setup the final data for the table |
|
346 | - * |
|
347 | - */ |
|
348 | - public function prepare_items() { |
|
349 | - |
|
350 | - $columns = $this->get_columns(); |
|
351 | - $hidden = array(); |
|
352 | - $sortable = $this->get_sortable_columns(); |
|
353 | - |
|
354 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
355 | - |
|
356 | - $this->set_pagination_args( |
|
357 | - array( |
|
358 | - 'total_items' => $this->current_total_count, |
|
359 | - 'per_page' => $this->per_page, |
|
360 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
361 | - ) |
|
362 | - ); |
|
363 | - } |
|
364 | - |
|
365 | - /** |
|
366 | - * Table columns |
|
367 | - * |
|
368 | - * @return array |
|
369 | - */ |
|
370 | - public function get_columns(){ |
|
371 | - $columns = array( |
|
372 | - 'cb' => '<input type="checkbox" />', |
|
373 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
374 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
375 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
376 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
377 | - 'item' => __( 'Items', 'invoicing' ), |
|
378 | - 'status' => __( 'Status', 'invoicing' ), |
|
379 | - ); |
|
380 | - |
|
381 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
382 | - } |
|
383 | - |
|
384 | - /** |
|
385 | - * Sortable table columns. |
|
386 | - * |
|
387 | - * @return array |
|
388 | - */ |
|
389 | - public function get_sortable_columns() { |
|
390 | - $sortable = array( |
|
391 | - 'subscription' => array( 'id', true ), |
|
392 | - 'start_date' => array( 'created', true ), |
|
393 | - 'renewal_date' => array( 'expiration', true ), |
|
394 | - 'renewals' => array( 'bill_times', true ), |
|
395 | - 'item' => array( 'product_id', true ), |
|
396 | - 'status' => array( 'status', true ), |
|
397 | - ); |
|
398 | - |
|
399 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Whether the table has items to display or not |
|
404 | - * |
|
405 | - * @return bool |
|
406 | - */ |
|
407 | - public function has_items() { |
|
408 | - return ! empty( $this->current_total_count ); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Processes bulk actions. |
|
413 | - * |
|
414 | - */ |
|
415 | - public function process_bulk_action() { |
|
416 | - |
|
417 | - } |
|
17 | + /** |
|
18 | + * URL of this page |
|
19 | + * |
|
20 | + * @var string |
|
21 | + * @since 1.0.19 |
|
22 | + */ |
|
23 | + public $base_url; |
|
24 | + |
|
25 | + /** |
|
26 | + * Query |
|
27 | + * |
|
28 | + * @var GetPaid_Subscriptions_Query |
|
29 | + * @since 1.0.19 |
|
30 | + */ |
|
31 | + public $query; |
|
32 | + |
|
33 | + /** |
|
34 | + * Total subscriptions |
|
35 | + * |
|
36 | + * @var string |
|
37 | + * @since 1.0.0 |
|
38 | + */ |
|
39 | + public $total_count; |
|
40 | + |
|
41 | + /** |
|
42 | + * Current status subscriptions |
|
43 | + * |
|
44 | + * @var string |
|
45 | + * @since 1.0.0 |
|
46 | + */ |
|
47 | + public $current_total_count; |
|
48 | + |
|
49 | + /** |
|
50 | + * Status counts |
|
51 | + * |
|
52 | + * @var array |
|
53 | + * @since 1.0.19 |
|
54 | + */ |
|
55 | + public $status_counts; |
|
56 | + |
|
57 | + /** |
|
58 | + * Number of results to show per page |
|
59 | + * |
|
60 | + * @var int |
|
61 | + * @since 1.0.0 |
|
62 | + */ |
|
63 | + public $per_page = 10; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor function. |
|
67 | + */ |
|
68 | + public function __construct() { |
|
69 | + |
|
70 | + parent::__construct( |
|
71 | + array( |
|
72 | + 'singular' => 'subscription', |
|
73 | + 'plural' => 'subscriptions', |
|
74 | + ) |
|
75 | + ); |
|
76 | + |
|
77 | + $this->process_bulk_action(); |
|
78 | + |
|
79 | + $this->prepare_query(); |
|
80 | + |
|
81 | + $this->base_url = remove_query_arg( 'status' ); |
|
82 | + |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * Prepares the display query |
|
87 | + */ |
|
88 | + public function prepare_query() { |
|
89 | + |
|
90 | + // Prepare query args. |
|
91 | + $query = array( |
|
92 | + 'number' => $this->per_page, |
|
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', |
|
97 | + ); |
|
98 | + |
|
99 | + // Prepare class properties. |
|
100 | + $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
101 | + $this->total_count = $this->query->get_total(); |
|
102 | + $this->current_total_count = $this->query->get_total(); |
|
103 | + $this->items = $this->query->get_results(); |
|
104 | + $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
105 | + |
|
106 | + if ( 'all' != $query['status'] ) { |
|
107 | + unset( $query['status'] ); |
|
108 | + $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
109 | + } |
|
110 | + |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Gets the list of views available on this table. |
|
115 | + * |
|
116 | + * The format is an associative array: |
|
117 | + * - `'id' => 'link'` |
|
118 | + * |
|
119 | + * @since 1.0.0 |
|
120 | + * |
|
121 | + * @return array |
|
122 | + */ |
|
123 | + public function get_views() { |
|
124 | + |
|
125 | + $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
126 | + $views = array( |
|
127 | + |
|
128 | + 'all' => sprintf( |
|
129 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
130 | + esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
131 | + $current === 'all' ? ' class="current"' : '', |
|
132 | + __('All','invoicing' ), |
|
133 | + $this->total_count |
|
134 | + ) |
|
135 | + |
|
136 | + ); |
|
137 | + |
|
138 | + foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
139 | + |
|
140 | + $views[ $status ] = sprintf( |
|
141 | + '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
|
142 | + esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
143 | + $current === $status ? ' class="current"' : '', |
|
144 | + sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
145 | + $count |
|
146 | + ); |
|
147 | + |
|
148 | + } |
|
149 | + |
|
150 | + return $views; |
|
151 | + |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Render most columns |
|
156 | + * |
|
157 | + * @access private |
|
158 | + * @since 1.0.0 |
|
159 | + * @return string |
|
160 | + */ |
|
161 | + public function column_default( $item, $column_name ) { |
|
162 | + return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
163 | + } |
|
164 | + |
|
165 | + /** |
|
166 | + * This is how checkbox column renders. |
|
167 | + * |
|
168 | + * @param WPInv_Subscription $item |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function column_cb( $item ) { |
|
172 | + return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Status column |
|
177 | + * |
|
178 | + * @param WPInv_Subscription $item |
|
179 | + * @since 1.0.0 |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function column_status( $item ) { |
|
183 | + return $item->get_status_label_html(); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Subscription column |
|
188 | + * |
|
189 | + * @param WPInv_Subscription $item |
|
190 | + * @since 1.0.0 |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function column_subscription( $item ) { |
|
194 | + |
|
195 | + $username = __( '(Missing User)', 'invoicing' ); |
|
196 | + |
|
197 | + $user = get_userdata( $item->get_customer_id() ); |
|
198 | + if ( $user ) { |
|
199 | + |
|
200 | + $username = sprintf( |
|
201 | + '<a href="user-edit.php?user_id=%s">%s</a>', |
|
202 | + absint( $user->ID ), |
|
203 | + ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
204 | + ); |
|
205 | + |
|
206 | + } |
|
207 | + |
|
208 | + // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
|
209 | + $column_content = sprintf( |
|
210 | + _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
211 | + '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
212 | + '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
213 | + $username |
|
214 | + ); |
|
215 | + |
|
216 | + $row_actions = array(); |
|
217 | + |
|
218 | + // View subscription. |
|
219 | + $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
220 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
221 | + |
|
222 | + // View invoice. |
|
223 | + $invoice = get_post( $item->get_parent_invoice_id() ); |
|
224 | + |
|
225 | + if ( ! empty( $invoice ) ) { |
|
226 | + $invoice_url = get_edit_post_link( $invoice ); |
|
227 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
228 | + } |
|
229 | + |
|
230 | + $delete_url = esc_url( |
|
231 | + wp_nonce_url( |
|
232 | + add_query_arg( |
|
233 | + array( |
|
234 | + 'getpaid-admin-action' => 'subscription_manual_delete', |
|
235 | + 'id' => $item->get_id(), |
|
236 | + ) |
|
237 | + ), |
|
238 | + 'getpaid-nonce', |
|
239 | + 'getpaid-nonce' |
|
240 | + ) |
|
241 | + ); |
|
242 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
243 | + |
|
244 | + $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
245 | + |
|
246 | + return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
247 | + } |
|
248 | + |
|
249 | + /** |
|
250 | + * Renewal date column |
|
251 | + * |
|
252 | + * @param WPInv_Subscription $item |
|
253 | + * @since 1.0.0 |
|
254 | + * @return string |
|
255 | + */ |
|
256 | + public function column_renewal_date( $item ) { |
|
257 | + return getpaid_format_date_value( $item->get_expiration() ); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * Start date column |
|
262 | + * |
|
263 | + * @param WPInv_Subscription $item |
|
264 | + * @since 1.0.0 |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function column_start_date( $item ) { |
|
268 | + return getpaid_format_date_value( $item->get_date_created() ); |
|
269 | + } |
|
270 | + |
|
271 | + /** |
|
272 | + * Amount column |
|
273 | + * |
|
274 | + * @param WPInv_Subscription $item |
|
275 | + * @since 1.0.19 |
|
276 | + * @return string |
|
277 | + */ |
|
278 | + public static function column_amount( $item ) { |
|
279 | + $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
280 | + return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
|
281 | + } |
|
282 | + |
|
283 | + /** |
|
284 | + * Billing Times column |
|
285 | + * |
|
286 | + * @param WPInv_Subscription $item |
|
287 | + * @since 1.0.0 |
|
288 | + * @return string |
|
289 | + */ |
|
290 | + public function column_renewals( $item ) { |
|
291 | + $max_bills = $item->get_bill_times(); |
|
292 | + return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
293 | + } |
|
294 | + |
|
295 | + /** |
|
296 | + * Product ID column |
|
297 | + * |
|
298 | + * @param WPInv_Subscription $item |
|
299 | + * @since 1.0.0 |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function column_item( $item ) { |
|
303 | + $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
304 | + |
|
305 | + if ( empty( $subscription_group ) ) { |
|
306 | + return $this->generate_item_markup( $item->get_product_id() ); |
|
307 | + } |
|
308 | + |
|
309 | + $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
310 | + return implode( ' | ', $markup ); |
|
311 | + |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Generates the items markup. |
|
316 | + * |
|
317 | + * @param int $item_id |
|
318 | + * @since 1.0.0 |
|
319 | + * @return string |
|
320 | + */ |
|
321 | + public static function generate_item_markup( $item_id ) { |
|
322 | + $item = get_post( $item_id ); |
|
323 | + |
|
324 | + if ( ! empty( $item ) ) { |
|
325 | + $link = get_edit_post_link( $item ); |
|
326 | + $link = esc_url( $link ); |
|
327 | + $name = esc_html( get_the_title( $item ) ); |
|
328 | + return "<a href='$link'>$name</a>"; |
|
329 | + } else { |
|
330 | + return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
331 | + } |
|
332 | + |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Retrieve the current page number |
|
337 | + * |
|
338 | + * @return int |
|
339 | + */ |
|
340 | + public function get_paged() { |
|
341 | + return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Setup the final data for the table |
|
346 | + * |
|
347 | + */ |
|
348 | + public function prepare_items() { |
|
349 | + |
|
350 | + $columns = $this->get_columns(); |
|
351 | + $hidden = array(); |
|
352 | + $sortable = $this->get_sortable_columns(); |
|
353 | + |
|
354 | + $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
355 | + |
|
356 | + $this->set_pagination_args( |
|
357 | + array( |
|
358 | + 'total_items' => $this->current_total_count, |
|
359 | + 'per_page' => $this->per_page, |
|
360 | + 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
361 | + ) |
|
362 | + ); |
|
363 | + } |
|
364 | + |
|
365 | + /** |
|
366 | + * Table columns |
|
367 | + * |
|
368 | + * @return array |
|
369 | + */ |
|
370 | + public function get_columns(){ |
|
371 | + $columns = array( |
|
372 | + 'cb' => '<input type="checkbox" />', |
|
373 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
374 | + 'start_date' => __( 'Start Date', 'invoicing' ), |
|
375 | + 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
376 | + 'renewals' => __( 'Payments', 'invoicing' ), |
|
377 | + 'item' => __( 'Items', 'invoicing' ), |
|
378 | + 'status' => __( 'Status', 'invoicing' ), |
|
379 | + ); |
|
380 | + |
|
381 | + return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
382 | + } |
|
383 | + |
|
384 | + /** |
|
385 | + * Sortable table columns. |
|
386 | + * |
|
387 | + * @return array |
|
388 | + */ |
|
389 | + public function get_sortable_columns() { |
|
390 | + $sortable = array( |
|
391 | + 'subscription' => array( 'id', true ), |
|
392 | + 'start_date' => array( 'created', true ), |
|
393 | + 'renewal_date' => array( 'expiration', true ), |
|
394 | + 'renewals' => array( 'bill_times', true ), |
|
395 | + 'item' => array( 'product_id', true ), |
|
396 | + 'status' => array( 'status', true ), |
|
397 | + ); |
|
398 | + |
|
399 | + return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Whether the table has items to display or not |
|
404 | + * |
|
405 | + * @return bool |
|
406 | + */ |
|
407 | + public function has_items() { |
|
408 | + return ! empty( $this->current_total_count ); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Processes bulk actions. |
|
413 | + * |
|
414 | + */ |
|
415 | + public function process_bulk_action() { |
|
416 | + |
|
417 | + } |
|
418 | 418 | |
419 | 419 | } |
@@ -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,21 +91,21 @@ 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 | ); |
98 | 98 | |
99 | 99 | // Prepare class properties. |
100 | - $this->query = new GetPaid_Subscriptions_Query( $query ); |
|
100 | + $this->query = new GetPaid_Subscriptions_Query($query); |
|
101 | 101 | $this->total_count = $this->query->get_total(); |
102 | 102 | $this->current_total_count = $this->query->get_total(); |
103 | 103 | $this->items = $this->query->get_results(); |
104 | - $this->status_counts = getpaid_get_subscription_status_counts( $query ); |
|
104 | + $this->status_counts = getpaid_get_subscription_status_counts($query); |
|
105 | 105 | |
106 | - if ( 'all' != $query['status'] ) { |
|
107 | - unset( $query['status'] ); |
|
108 | - $this->total_count = getpaid_get_subscriptions( $query, 'count' ); |
|
106 | + if ('all' != $query['status']) { |
|
107 | + unset($query['status']); |
|
108 | + $this->total_count = getpaid_get_subscriptions($query, 'count'); |
|
109 | 109 | } |
110 | 110 | |
111 | 111 | } |
@@ -122,26 +122,26 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function get_views() { |
124 | 124 | |
125 | - $current = isset( $_GET['status'] ) ? $_GET['status'] : 'all'; |
|
125 | + $current = isset($_GET['status']) ? $_GET['status'] : 'all'; |
|
126 | 126 | $views = array( |
127 | 127 | |
128 | 128 | 'all' => sprintf( |
129 | 129 | '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
130 | - esc_url( add_query_arg( 'status', false, $this->base_url ) ), |
|
130 | + esc_url(add_query_arg('status', false, $this->base_url)), |
|
131 | 131 | $current === 'all' ? ' class="current"' : '', |
132 | - __('All','invoicing' ), |
|
132 | + __('All', 'invoicing'), |
|
133 | 133 | $this->total_count |
134 | 134 | ) |
135 | 135 | |
136 | 136 | ); |
137 | 137 | |
138 | - foreach ( array_filter( $this->status_counts ) as $status => $count ) { |
|
138 | + foreach (array_filter($this->status_counts) as $status => $count) { |
|
139 | 139 | |
140 | - $views[ $status ] = sprintf( |
|
140 | + $views[$status] = sprintf( |
|
141 | 141 | '<a href="%s" %s>%s <span class="count">(%d)</span></a>', |
142 | - esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ), |
|
142 | + esc_url(add_query_arg('status', urlencode($status), $this->base_url)), |
|
143 | 143 | $current === $status ? ' class="current"' : '', |
144 | - sanitize_text_field( getpaid_get_subscription_status_label( $status ) ), |
|
144 | + sanitize_text_field(getpaid_get_subscription_status_label($status)), |
|
145 | 145 | $count |
146 | 146 | ); |
147 | 147 | |
@@ -158,8 +158,8 @@ discard block |
||
158 | 158 | * @since 1.0.0 |
159 | 159 | * @return string |
160 | 160 | */ |
161 | - public function column_default( $item, $column_name ) { |
|
162 | - return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name ); |
|
161 | + public function column_default($item, $column_name) { |
|
162 | + return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param WPInv_Subscription $item |
169 | 169 | * @return string |
170 | 170 | */ |
171 | - public function column_cb( $item ) { |
|
172 | - return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) ); |
|
171 | + public function column_cb($item) { |
|
172 | + return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id())); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | /** |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @since 1.0.0 |
180 | 180 | * @return string |
181 | 181 | */ |
182 | - public function column_status( $item ) { |
|
182 | + public function column_status($item) { |
|
183 | 183 | return $item->get_status_label_html(); |
184 | 184 | } |
185 | 185 | |
@@ -190,44 +190,44 @@ discard block |
||
190 | 190 | * @since 1.0.0 |
191 | 191 | * @return string |
192 | 192 | */ |
193 | - public function column_subscription( $item ) { |
|
193 | + public function column_subscription($item) { |
|
194 | 194 | |
195 | - $username = __( '(Missing User)', 'invoicing' ); |
|
195 | + $username = __('(Missing User)', 'invoicing'); |
|
196 | 196 | |
197 | - $user = get_userdata( $item->get_customer_id() ); |
|
198 | - if ( $user ) { |
|
197 | + $user = get_userdata($item->get_customer_id()); |
|
198 | + if ($user) { |
|
199 | 199 | |
200 | 200 | $username = sprintf( |
201 | 201 | '<a href="user-edit.php?user_id=%s">%s</a>', |
202 | - absint( $user->ID ), |
|
203 | - ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email ) |
|
202 | + absint($user->ID), |
|
203 | + !empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email) |
|
204 | 204 | ); |
205 | 205 | |
206 | 206 | } |
207 | 207 | |
208 | 208 | // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name |
209 | 209 | $column_content = sprintf( |
210 | - _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ), |
|
211 | - '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">', |
|
212 | - '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>', |
|
210 | + _x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'), |
|
211 | + '<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">', |
|
212 | + '<strong>' . esc_attr($item->get_id()) . '</strong>', '</a>', |
|
213 | 213 | $username |
214 | 214 | ); |
215 | 215 | |
216 | 216 | $row_actions = array(); |
217 | 217 | |
218 | 218 | // View subscription. |
219 | - $view_url = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) )); |
|
220 | - $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>'; |
|
219 | + $view_url = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions'))); |
|
220 | + $row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>'; |
|
221 | 221 | |
222 | 222 | // View invoice. |
223 | - $invoice = get_post( $item->get_parent_invoice_id() ); |
|
223 | + $invoice = get_post($item->get_parent_invoice_id()); |
|
224 | 224 | |
225 | - if ( ! empty( $invoice ) ) { |
|
226 | - $invoice_url = get_edit_post_link( $invoice ); |
|
227 | - $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>'; |
|
225 | + if (!empty($invoice)) { |
|
226 | + $invoice_url = get_edit_post_link($invoice); |
|
227 | + $row_actions['invoice'] = '<a href="' . $invoice_url . '">' . __('View Invoice', 'invoicing') . '</a>'; |
|
228 | 228 | } |
229 | 229 | |
230 | - $delete_url = esc_url( |
|
230 | + $delete_url = esc_url( |
|
231 | 231 | wp_nonce_url( |
232 | 232 | add_query_arg( |
233 | 233 | array( |
@@ -239,11 +239,11 @@ discard block |
||
239 | 239 | 'getpaid-nonce' |
240 | 240 | ) |
241 | 241 | ); |
242 | - $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __( 'Delete Subscription', 'invoicing' ) . '</a>'; |
|
242 | + $row_actions['delete'] = '<a class="text-danger" href="' . $delete_url . '">' . __('Delete Subscription', 'invoicing') . '</a>'; |
|
243 | 243 | |
244 | - $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) ); |
|
244 | + $row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item)); |
|
245 | 245 | |
246 | - return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions; |
|
246 | + return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions; |
|
247 | 247 | } |
248 | 248 | |
249 | 249 | /** |
@@ -253,8 +253,8 @@ discard block |
||
253 | 253 | * @since 1.0.0 |
254 | 254 | * @return string |
255 | 255 | */ |
256 | - public function column_renewal_date( $item ) { |
|
257 | - return getpaid_format_date_value( $item->get_expiration() ); |
|
256 | + public function column_renewal_date($item) { |
|
257 | + return getpaid_format_date_value($item->get_expiration()); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | /** |
@@ -264,8 +264,8 @@ discard block |
||
264 | 264 | * @since 1.0.0 |
265 | 265 | * @return string |
266 | 266 | */ |
267 | - public function column_start_date( $item ) { |
|
268 | - return getpaid_format_date_value( $item->get_date_created() ); |
|
267 | + public function column_start_date($item) { |
|
268 | + return getpaid_format_date_value($item->get_date_created()); |
|
269 | 269 | } |
270 | 270 | |
271 | 271 | /** |
@@ -275,8 +275,8 @@ discard block |
||
275 | 275 | * @since 1.0.19 |
276 | 276 | * @return string |
277 | 277 | */ |
278 | - public static function column_amount( $item ) { |
|
279 | - $amount = getpaid_get_formatted_subscription_amount( $item ); |
|
278 | + public static function column_amount($item) { |
|
279 | + $amount = getpaid_get_formatted_subscription_amount($item); |
|
280 | 280 | return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>"; |
281 | 281 | } |
282 | 282 | |
@@ -287,9 +287,9 @@ discard block |
||
287 | 287 | * @since 1.0.0 |
288 | 288 | * @return string |
289 | 289 | */ |
290 | - public function column_renewals( $item ) { |
|
290 | + public function column_renewals($item) { |
|
291 | 291 | $max_bills = $item->get_bill_times(); |
292 | - return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "∞" : $max_bills ); |
|
292 | + return $item->get_times_billed() . ' / ' . (empty($max_bills) ? "∞" : $max_bills); |
|
293 | 293 | } |
294 | 294 | |
295 | 295 | /** |
@@ -299,15 +299,15 @@ discard block |
||
299 | 299 | * @since 1.0.0 |
300 | 300 | * @return string |
301 | 301 | */ |
302 | - public function column_item( $item ) { |
|
303 | - $subscription_group = getpaid_get_invoice_subscription_group( $item->get_parent_invoice_id(), $item->get_id() ); |
|
302 | + public function column_item($item) { |
|
303 | + $subscription_group = getpaid_get_invoice_subscription_group($item->get_parent_invoice_id(), $item->get_id()); |
|
304 | 304 | |
305 | - if ( empty( $subscription_group ) ) { |
|
306 | - return $this->generate_item_markup( $item->get_product_id() ); |
|
305 | + if (empty($subscription_group)) { |
|
306 | + return $this->generate_item_markup($item->get_product_id()); |
|
307 | 307 | } |
308 | 308 | |
309 | - $markup = array_map( array( $this, 'generate_item_markup' ), array_keys( $subscription_group['items'] ) ); |
|
310 | - return implode( ' | ', $markup ); |
|
309 | + $markup = array_map(array($this, 'generate_item_markup'), array_keys($subscription_group['items'])); |
|
310 | + return implode(' | ', $markup); |
|
311 | 311 | |
312 | 312 | } |
313 | 313 | |
@@ -318,16 +318,16 @@ discard block |
||
318 | 318 | * @since 1.0.0 |
319 | 319 | * @return string |
320 | 320 | */ |
321 | - public static function generate_item_markup( $item_id ) { |
|
322 | - $item = get_post( $item_id ); |
|
321 | + public static function generate_item_markup($item_id) { |
|
322 | + $item = get_post($item_id); |
|
323 | 323 | |
324 | - if ( ! empty( $item ) ) { |
|
325 | - $link = get_edit_post_link( $item ); |
|
326 | - $link = esc_url( $link ); |
|
327 | - $name = esc_html( get_the_title( $item ) ); |
|
324 | + if (!empty($item)) { |
|
325 | + $link = get_edit_post_link($item); |
|
326 | + $link = esc_url($link); |
|
327 | + $name = esc_html(get_the_title($item)); |
|
328 | 328 | return "<a href='$link'>$name</a>"; |
329 | 329 | } else { |
330 | - return sprintf( __( 'Item #%s', 'invoicing' ), $item_id ); |
|
330 | + return sprintf(__('Item #%s', 'invoicing'), $item_id); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | * @return int |
339 | 339 | */ |
340 | 340 | public function get_paged() { |
341 | - return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1; |
|
341 | + return isset($_GET['paged']) ? absint($_GET['paged']) : 1; |
|
342 | 342 | } |
343 | 343 | |
344 | 344 | /** |
@@ -351,13 +351,13 @@ discard block |
||
351 | 351 | $hidden = array(); |
352 | 352 | $sortable = $this->get_sortable_columns(); |
353 | 353 | |
354 | - $this->_column_headers = array( $columns, $hidden, $sortable ); |
|
354 | + $this->_column_headers = array($columns, $hidden, $sortable); |
|
355 | 355 | |
356 | 356 | $this->set_pagination_args( |
357 | 357 | array( |
358 | 358 | 'total_items' => $this->current_total_count, |
359 | 359 | 'per_page' => $this->per_page, |
360 | - 'total_pages' => ceil( $this->current_total_count / $this->per_page ) |
|
360 | + 'total_pages' => ceil($this->current_total_count / $this->per_page) |
|
361 | 361 | ) |
362 | 362 | ); |
363 | 363 | } |
@@ -367,18 +367,18 @@ discard block |
||
367 | 367 | * |
368 | 368 | * @return array |
369 | 369 | */ |
370 | - public function get_columns(){ |
|
370 | + public function get_columns() { |
|
371 | 371 | $columns = array( |
372 | 372 | 'cb' => '<input type="checkbox" />', |
373 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
374 | - 'start_date' => __( 'Start Date', 'invoicing' ), |
|
375 | - 'renewal_date' => __( 'Next Payment', 'invoicing' ), |
|
376 | - 'renewals' => __( 'Payments', 'invoicing' ), |
|
377 | - 'item' => __( 'Items', 'invoicing' ), |
|
378 | - 'status' => __( 'Status', 'invoicing' ), |
|
373 | + 'subscription' => __('Subscription', 'invoicing'), |
|
374 | + 'start_date' => __('Start Date', 'invoicing'), |
|
375 | + 'renewal_date' => __('Next Payment', 'invoicing'), |
|
376 | + 'renewals' => __('Payments', 'invoicing'), |
|
377 | + 'item' => __('Items', 'invoicing'), |
|
378 | + 'status' => __('Status', 'invoicing'), |
|
379 | 379 | ); |
380 | 380 | |
381 | - return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns ); |
|
381 | + return apply_filters('manage_getpaid_subscriptions_table_columns', $columns); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | /** |
@@ -388,15 +388,15 @@ discard block |
||
388 | 388 | */ |
389 | 389 | public function get_sortable_columns() { |
390 | 390 | $sortable = array( |
391 | - 'subscription' => array( 'id', true ), |
|
392 | - 'start_date' => array( 'created', true ), |
|
393 | - 'renewal_date' => array( 'expiration', true ), |
|
394 | - 'renewals' => array( 'bill_times', true ), |
|
395 | - 'item' => array( 'product_id', true ), |
|
396 | - 'status' => array( 'status', true ), |
|
391 | + 'subscription' => array('id', true), |
|
392 | + 'start_date' => array('created', true), |
|
393 | + 'renewal_date' => array('expiration', true), |
|
394 | + 'renewals' => array('bill_times', true), |
|
395 | + 'item' => array('product_id', true), |
|
396 | + 'status' => array('status', true), |
|
397 | 397 | ); |
398 | 398 | |
399 | - return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable ); |
|
399 | + return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable); |
|
400 | 400 | } |
401 | 401 | |
402 | 402 | /** |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | * @return bool |
406 | 406 | */ |
407 | 407 | public function has_items() { |
408 | - return ! empty( $this->current_total_count ); |
|
408 | + return !empty($this->current_total_count); |
|
409 | 409 | } |
410 | 410 | |
411 | 411 | /** |