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