@@ -14,143 +14,143 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class WPInv_Subscriptions_Widget extends WP_Super_Duper { |
16 | 16 | |
17 | - /** |
|
18 | - * Register the widget with WordPress. |
|
19 | - * |
|
20 | - */ |
|
21 | - public function __construct() { |
|
22 | - |
|
23 | - $options = array( |
|
24 | - 'textdomain' => 'invoicing', |
|
25 | - 'block-icon' => 'controls-repeat', |
|
26 | - 'block-category' => 'widgets', |
|
27 | - 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | - 'class_name' => __CLASS__, |
|
29 | - 'base_id' => 'wpinv_subscriptions', |
|
30 | - 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | - 'widget_ops' => array( |
|
32 | - 'classname' => 'getpaid-subscriptions bsui', |
|
33 | - 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | - ), |
|
35 | - 'arguments' => array( |
|
36 | - 'title' => array( |
|
37 | - 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | - 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | - 'type' => 'text', |
|
40 | - 'desc_tip' => true, |
|
41 | - 'default' => '', |
|
42 | - 'advanced' => false, |
|
43 | - ), |
|
44 | - ), |
|
45 | - |
|
46 | - ); |
|
47 | - |
|
48 | - parent::__construct( $options ); |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Retrieves current user's subscriptions. |
|
53 | - * |
|
54 | - * @return GetPaid_Subscriptions_Query |
|
55 | - */ |
|
56 | - public function get_subscriptions() { |
|
57 | - |
|
58 | - // Prepare license args. |
|
59 | - $args = array( |
|
60 | - 'customer_in' => get_current_user_id(), |
|
61 | - 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | - ); |
|
63 | - |
|
64 | - return new GetPaid_Subscriptions_Query( $args ); |
|
65 | - |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * The Super block output function. |
|
70 | - * |
|
71 | - * @param array $args |
|
72 | - * @param array $widget_args |
|
73 | - * @param string $content |
|
74 | - * |
|
75 | - * @return mixed|string|bool |
|
76 | - */ |
|
77 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | - |
|
79 | - // Ensure that the user is logged in. |
|
80 | - if ( ! is_user_logged_in() ) { |
|
81 | - |
|
82 | - return aui()->alert( |
|
83 | - array( |
|
84 | - 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | - 'type' => 'error', |
|
86 | - ) |
|
87 | - ); |
|
88 | - |
|
89 | - } |
|
90 | - |
|
91 | - // Are we displaying a single subscription? |
|
92 | - if ( isset( $_GET['subscription'] ) ) { |
|
93 | - return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | - } |
|
95 | - |
|
96 | - // Retrieve the user's subscriptions. |
|
97 | - $subscriptions = $this->get_subscriptions(); |
|
98 | - |
|
99 | - // Start the output buffer. |
|
100 | - ob_start(); |
|
101 | - |
|
102 | - // Backwards compatibility. |
|
103 | - do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | - |
|
105 | - // Display errors and notices. |
|
106 | - wpinv_print_errors(); |
|
107 | - |
|
108 | - do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | - |
|
110 | - // Print the table header. |
|
111 | - $this->print_table_header(); |
|
112 | - |
|
113 | - // Print table body. |
|
114 | - $this->print_table_body( $subscriptions->get_results() ); |
|
115 | - |
|
116 | - // Print table footer. |
|
117 | - $this->print_table_footer(); |
|
118 | - |
|
119 | - // Print the navigation. |
|
120 | - $this->print_navigation( $subscriptions->get_total() ); |
|
121 | - |
|
122 | - // Backwards compatibility. |
|
123 | - do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | - |
|
125 | - // Return the output. |
|
126 | - return ob_get_clean(); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * Retrieves the subscription columns. |
|
132 | - * |
|
133 | - * @return array |
|
134 | - */ |
|
135 | - public function get_subscriptions_table_columns() { |
|
17 | + /** |
|
18 | + * Register the widget with WordPress. |
|
19 | + * |
|
20 | + */ |
|
21 | + public function __construct() { |
|
22 | + |
|
23 | + $options = array( |
|
24 | + 'textdomain' => 'invoicing', |
|
25 | + 'block-icon' => 'controls-repeat', |
|
26 | + 'block-category' => 'widgets', |
|
27 | + 'block-keywords' => "['invoicing','subscriptions', 'getpaid']", |
|
28 | + 'class_name' => __CLASS__, |
|
29 | + 'base_id' => 'wpinv_subscriptions', |
|
30 | + 'name' => __( 'GetPaid > Subscriptions', 'invoicing' ), |
|
31 | + 'widget_ops' => array( |
|
32 | + 'classname' => 'getpaid-subscriptions bsui', |
|
33 | + 'description' => esc_html__( "Displays the current user's subscriptions.", 'invoicing' ), |
|
34 | + ), |
|
35 | + 'arguments' => array( |
|
36 | + 'title' => array( |
|
37 | + 'title' => __( 'Widget title', 'invoicing' ), |
|
38 | + 'desc' => __( 'Enter widget title.', 'invoicing' ), |
|
39 | + 'type' => 'text', |
|
40 | + 'desc_tip' => true, |
|
41 | + 'default' => '', |
|
42 | + 'advanced' => false, |
|
43 | + ), |
|
44 | + ), |
|
45 | + |
|
46 | + ); |
|
47 | + |
|
48 | + parent::__construct( $options ); |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Retrieves current user's subscriptions. |
|
53 | + * |
|
54 | + * @return GetPaid_Subscriptions_Query |
|
55 | + */ |
|
56 | + public function get_subscriptions() { |
|
57 | + |
|
58 | + // Prepare license args. |
|
59 | + $args = array( |
|
60 | + 'customer_in' => get_current_user_id(), |
|
61 | + 'paged' => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1, |
|
62 | + ); |
|
63 | + |
|
64 | + return new GetPaid_Subscriptions_Query( $args ); |
|
65 | + |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * The Super block output function. |
|
70 | + * |
|
71 | + * @param array $args |
|
72 | + * @param array $widget_args |
|
73 | + * @param string $content |
|
74 | + * |
|
75 | + * @return mixed|string|bool |
|
76 | + */ |
|
77 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
78 | + |
|
79 | + // Ensure that the user is logged in. |
|
80 | + if ( ! is_user_logged_in() ) { |
|
81 | + |
|
82 | + return aui()->alert( |
|
83 | + array( |
|
84 | + 'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ), |
|
85 | + 'type' => 'error', |
|
86 | + ) |
|
87 | + ); |
|
88 | + |
|
89 | + } |
|
90 | + |
|
91 | + // Are we displaying a single subscription? |
|
92 | + if ( isset( $_GET['subscription'] ) ) { |
|
93 | + return $this->display_single_subscription( intval( $_GET['subscription'] ) ); |
|
94 | + } |
|
95 | + |
|
96 | + // Retrieve the user's subscriptions. |
|
97 | + $subscriptions = $this->get_subscriptions(); |
|
98 | + |
|
99 | + // Start the output buffer. |
|
100 | + ob_start(); |
|
101 | + |
|
102 | + // Backwards compatibility. |
|
103 | + do_action( 'wpinv_before_user_subscriptions' ); |
|
104 | + |
|
105 | + // Display errors and notices. |
|
106 | + wpinv_print_errors(); |
|
107 | + |
|
108 | + do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions ); |
|
109 | + |
|
110 | + // Print the table header. |
|
111 | + $this->print_table_header(); |
|
112 | + |
|
113 | + // Print table body. |
|
114 | + $this->print_table_body( $subscriptions->get_results() ); |
|
115 | + |
|
116 | + // Print table footer. |
|
117 | + $this->print_table_footer(); |
|
118 | + |
|
119 | + // Print the navigation. |
|
120 | + $this->print_navigation( $subscriptions->get_total() ); |
|
121 | + |
|
122 | + // Backwards compatibility. |
|
123 | + do_action( 'wpinv_after_user_subscriptions' ); |
|
124 | + |
|
125 | + // Return the output. |
|
126 | + return ob_get_clean(); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * Retrieves the subscription columns. |
|
132 | + * |
|
133 | + * @return array |
|
134 | + */ |
|
135 | + public function get_subscriptions_table_columns() { |
|
136 | 136 | |
137 | - $columns = array( |
|
138 | - 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | - 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | - 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | - 'status' => __( 'Status', 'invoicing' ), |
|
142 | - ); |
|
137 | + $columns = array( |
|
138 | + 'subscription' => __( 'Subscription', 'invoicing' ), |
|
139 | + 'amount' => __( 'Amount', 'invoicing' ), |
|
140 | + 'renewal-date' => __( 'Next payment', 'invoicing' ), |
|
141 | + 'status' => __( 'Status', 'invoicing' ), |
|
142 | + ); |
|
143 | 143 | |
144 | - return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | - } |
|
144 | + return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns ); |
|
145 | + } |
|
146 | 146 | |
147 | - /** |
|
148 | - * Displays the table header. |
|
149 | - * |
|
150 | - */ |
|
151 | - public function print_table_header() { |
|
147 | + /** |
|
148 | + * Displays the table header. |
|
149 | + * |
|
150 | + */ |
|
151 | + public function print_table_header() { |
|
152 | 152 | |
153 | - ?> |
|
153 | + ?> |
|
154 | 154 | |
155 | 155 | <table class="table table-bordered table-striped"> |
156 | 156 | |
@@ -166,121 +166,121 @@ discard block |
||
166 | 166 | |
167 | 167 | <?php |
168 | 168 | |
169 | - } |
|
169 | + } |
|
170 | 170 | |
171 | - /** |
|
172 | - * Displays the table body. |
|
173 | - * |
|
174 | - * @param WPInv_Subscription[] $subscriptions |
|
175 | - */ |
|
176 | - public function print_table_body( $subscriptions ) { |
|
171 | + /** |
|
172 | + * Displays the table body. |
|
173 | + * |
|
174 | + * @param WPInv_Subscription[] $subscriptions |
|
175 | + */ |
|
176 | + public function print_table_body( $subscriptions ) { |
|
177 | 177 | |
178 | - if ( empty( $subscriptions ) ) { |
|
179 | - $this->print_table_body_no_subscriptions(); |
|
180 | - } else { |
|
181 | - $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | - } |
|
178 | + if ( empty( $subscriptions ) ) { |
|
179 | + $this->print_table_body_no_subscriptions(); |
|
180 | + } else { |
|
181 | + $this->print_table_body_subscriptions( $subscriptions ); |
|
182 | + } |
|
183 | 183 | |
184 | - } |
|
184 | + } |
|
185 | 185 | |
186 | - /** |
|
187 | - * Displays the table body if no subscriptions were found. |
|
188 | - * |
|
189 | - */ |
|
190 | - public function print_table_body_no_subscriptions() { |
|
186 | + /** |
|
187 | + * Displays the table body if no subscriptions were found. |
|
188 | + * |
|
189 | + */ |
|
190 | + public function print_table_body_no_subscriptions() { |
|
191 | 191 | |
192 | - ?> |
|
192 | + ?> |
|
193 | 193 | <tbody> |
194 | 194 | |
195 | 195 | <tr> |
196 | 196 | <td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>"> |
197 | 197 | |
198 | 198 | <?php |
199 | - echo aui()->alert( |
|
200 | - array( |
|
201 | - 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | - 'type' => 'warning', |
|
203 | - ) |
|
204 | - ); |
|
205 | - ?> |
|
199 | + echo aui()->alert( |
|
200 | + array( |
|
201 | + 'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ), |
|
202 | + 'type' => 'warning', |
|
203 | + ) |
|
204 | + ); |
|
205 | + ?> |
|
206 | 206 | |
207 | 207 | </td> |
208 | 208 | </tr> |
209 | 209 | |
210 | 210 | </tbody> |
211 | 211 | <?php |
212 | - } |
|
212 | + } |
|
213 | 213 | |
214 | - /** |
|
215 | - * Displays the table body if subscriptions were found. |
|
216 | - * |
|
217 | - * @param WPInv_Subscription[] $subscriptions |
|
218 | - */ |
|
219 | - public function print_table_body_subscriptions( $subscriptions ) { |
|
214 | + /** |
|
215 | + * Displays the table body if subscriptions were found. |
|
216 | + * |
|
217 | + * @param WPInv_Subscription[] $subscriptions |
|
218 | + */ |
|
219 | + public function print_table_body_subscriptions( $subscriptions ) { |
|
220 | 220 | |
221 | - ?> |
|
221 | + ?> |
|
222 | 222 | <tbody> |
223 | 223 | |
224 | 224 | <?php foreach ( $subscriptions as $subscription ) : ?> |
225 | 225 | <tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>"> |
226 | 226 | <?php |
227 | - wpinv_get_template( |
|
228 | - 'subscriptions/subscriptions-table-row.php', |
|
229 | - array( |
|
230 | - 'subscription' => $subscription, |
|
231 | - 'widget' => $this, |
|
232 | - ) |
|
233 | - ); |
|
234 | - ?> |
|
227 | + wpinv_get_template( |
|
228 | + 'subscriptions/subscriptions-table-row.php', |
|
229 | + array( |
|
230 | + 'subscription' => $subscription, |
|
231 | + 'widget' => $this, |
|
232 | + ) |
|
233 | + ); |
|
234 | + ?> |
|
235 | 235 | </tr> |
236 | 236 | <?php endforeach; ?> |
237 | 237 | |
238 | 238 | </tbody> |
239 | 239 | <?php |
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * Adds row actions to a column |
|
244 | - * |
|
245 | - * @param string $content column content |
|
246 | - * @param WPInv_Subscription $subscription |
|
247 | - * @since 1.0.0 |
|
248 | - * @return string |
|
249 | - */ |
|
250 | - public function add_row_actions( $content, $subscription ) { |
|
251 | - |
|
252 | - // Prepare row actions. |
|
253 | - $actions = array(); |
|
254 | - |
|
255 | - // View subscription action. |
|
256 | - $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
257 | - $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
258 | - $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
259 | - |
|
260 | - // Filter the actions. |
|
261 | - $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
262 | - |
|
263 | - $sanitized = array(); |
|
264 | - foreach ( $actions as $key => $action ) { |
|
265 | - $key = sanitize_html_class( $key ); |
|
266 | - $action = wp_kses_post( $action ); |
|
267 | - $sanitized[] = "<span class='$key'>$action</span>"; |
|
268 | - } |
|
269 | - |
|
270 | - $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
271 | - $row_actions .= implode( ' | ', $sanitized ); |
|
272 | - $row_actions .= '</small>'; |
|
273 | - |
|
274 | - return $content . $row_actions; |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Displays the table footer. |
|
279 | - * |
|
280 | - */ |
|
281 | - public function print_table_footer() { |
|
282 | - |
|
283 | - ?> |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * Adds row actions to a column |
|
244 | + * |
|
245 | + * @param string $content column content |
|
246 | + * @param WPInv_Subscription $subscription |
|
247 | + * @since 1.0.0 |
|
248 | + * @return string |
|
249 | + */ |
|
250 | + public function add_row_actions( $content, $subscription ) { |
|
251 | + |
|
252 | + // Prepare row actions. |
|
253 | + $actions = array(); |
|
254 | + |
|
255 | + // View subscription action. |
|
256 | + $view_url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) ); |
|
257 | + $view_url = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) ); |
|
258 | + $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>'; |
|
259 | + |
|
260 | + // Filter the actions. |
|
261 | + $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription ); |
|
262 | + |
|
263 | + $sanitized = array(); |
|
264 | + foreach ( $actions as $key => $action ) { |
|
265 | + $key = sanitize_html_class( $key ); |
|
266 | + $action = wp_kses_post( $action ); |
|
267 | + $sanitized[] = "<span class='$key'>$action</span>"; |
|
268 | + } |
|
269 | + |
|
270 | + $row_actions = "<small class='form-text getpaid-subscription-item-actions'>"; |
|
271 | + $row_actions .= implode( ' | ', $sanitized ); |
|
272 | + $row_actions .= '</small>'; |
|
273 | + |
|
274 | + return $content . $row_actions; |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Displays the table footer. |
|
279 | + * |
|
280 | + */ |
|
281 | + public function print_table_footer() { |
|
282 | + |
|
283 | + ?> |
|
284 | 284 | |
285 | 285 | <tfoot> |
286 | 286 | <tr> |
@@ -295,144 +295,144 @@ discard block |
||
295 | 295 | </table> |
296 | 296 | <?php |
297 | 297 | |
298 | - } |
|
298 | + } |
|
299 | 299 | |
300 | - /** |
|
301 | - * Displays the navigation. |
|
302 | - * |
|
303 | - * @param int $total |
|
304 | - */ |
|
305 | - public function print_navigation( $total ) { |
|
300 | + /** |
|
301 | + * Displays the navigation. |
|
302 | + * |
|
303 | + * @param int $total |
|
304 | + */ |
|
305 | + public function print_navigation( $total ) { |
|
306 | 306 | |
307 | - if ( $total < 1 ) { |
|
307 | + if ( $total < 1 ) { |
|
308 | 308 | |
309 | - // Out-of-bounds, run the query again without LIMIT for total count. |
|
310 | - $args = array( |
|
311 | - 'customer_in' => get_current_user_id(), |
|
312 | - 'fields' => 'id', |
|
313 | - ); |
|
309 | + // Out-of-bounds, run the query again without LIMIT for total count. |
|
310 | + $args = array( |
|
311 | + 'customer_in' => get_current_user_id(), |
|
312 | + 'fields' => 'id', |
|
313 | + ); |
|
314 | 314 | |
315 | - $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
316 | - $total = $count_query->get_total(); |
|
317 | - } |
|
315 | + $count_query = new GetPaid_Subscriptions_Query( $args ); |
|
316 | + $total = $count_query->get_total(); |
|
317 | + } |
|
318 | 318 | |
319 | - // Abort if we do not have pages. |
|
320 | - if ( 2 > $total ) { |
|
321 | - return; |
|
322 | - } |
|
319 | + // Abort if we do not have pages. |
|
320 | + if ( 2 > $total ) { |
|
321 | + return; |
|
322 | + } |
|
323 | 323 | |
324 | - ?> |
|
324 | + ?> |
|
325 | 325 | |
326 | 326 | <div class="getpaid-subscriptions-pagination"> |
327 | 327 | <?php |
328 | - $big = 999999; |
|
329 | - |
|
330 | - echo wp_kses_post( |
|
331 | - getpaid_paginate_links( |
|
332 | - array( |
|
333 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | - 'format' => '?paged=%#%', |
|
335 | - 'total' => (int) ceil( $total / 10 ), |
|
336 | - ) |
|
337 | - ) |
|
338 | - ); |
|
339 | - ?> |
|
328 | + $big = 999999; |
|
329 | + |
|
330 | + echo wp_kses_post( |
|
331 | + getpaid_paginate_links( |
|
332 | + array( |
|
333 | + 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
334 | + 'format' => '?paged=%#%', |
|
335 | + 'total' => (int) ceil( $total / 10 ), |
|
336 | + ) |
|
337 | + ) |
|
338 | + ); |
|
339 | + ?> |
|
340 | 340 | </div> |
341 | 341 | |
342 | 342 | <?php |
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Returns a single subscription's columns. |
|
347 | - * |
|
348 | - * @param WPInv_Subscription $subscription |
|
349 | - * |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public function get_single_subscription_columns( $subscription ) { |
|
353 | - |
|
354 | - // Prepare subscription detail columns. |
|
355 | - $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
356 | - $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
357 | - $fields = apply_filters( |
|
358 | - 'getpaid_single_subscription_details_fields', |
|
359 | - array( |
|
360 | - 'status' => __( 'Status', 'invoicing' ), |
|
361 | - 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
362 | - 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
363 | - 'start_date' => __( 'Start date', 'invoicing' ), |
|
364 | - 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
365 | - 'payments' => __( 'Payments', 'invoicing' ), |
|
366 | - 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
367 | - ), |
|
368 | - $subscription |
|
369 | - ); |
|
370 | - |
|
371 | - if ( isset( $fields['expiry_date'] ) ) { |
|
372 | - |
|
373 | - if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
374 | - $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
375 | - } |
|
376 | - |
|
377 | - if ( 'pending' == $subscription->get_status() ) { |
|
378 | - unset( $fields['expiry_date'] ); |
|
379 | - } |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Returns a single subscription's columns. |
|
347 | + * |
|
348 | + * @param WPInv_Subscription $subscription |
|
349 | + * |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public function get_single_subscription_columns( $subscription ) { |
|
353 | + |
|
354 | + // Prepare subscription detail columns. |
|
355 | + $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() ); |
|
356 | + $items_count = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] ); |
|
357 | + $fields = apply_filters( |
|
358 | + 'getpaid_single_subscription_details_fields', |
|
359 | + array( |
|
360 | + 'status' => __( 'Status', 'invoicing' ), |
|
361 | + 'initial_amount' => __( 'Initial amount', 'invoicing' ), |
|
362 | + 'recurring_amount' => __( 'Recurring amount', 'invoicing' ), |
|
363 | + 'start_date' => __( 'Start date', 'invoicing' ), |
|
364 | + 'expiry_date' => __( 'Next payment', 'invoicing' ), |
|
365 | + 'payments' => __( 'Payments', 'invoicing' ), |
|
366 | + 'item' => _n( 'Item', 'Items', $items_count, 'invoicing' ), |
|
367 | + ), |
|
368 | + $subscription |
|
369 | + ); |
|
370 | + |
|
371 | + if ( isset( $fields['expiry_date'] ) ) { |
|
372 | + |
|
373 | + if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) { |
|
374 | + $fields['expiry_date'] = __( 'End date', 'invoicing' ); |
|
375 | + } |
|
376 | + |
|
377 | + if ( 'pending' == $subscription->get_status() ) { |
|
378 | + unset( $fields['expiry_date'] ); |
|
379 | + } |
|
380 | 380 | } |
381 | 381 | |
382 | - if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) { |
|
383 | - unset( $fields['start_date'] ); |
|
384 | - } |
|
385 | - |
|
386 | - if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
387 | - unset( $fields['initial_amount'] ); |
|
388 | - } |
|
389 | - |
|
390 | - return $fields; |
|
391 | - } |
|
392 | - |
|
393 | - /** |
|
394 | - * Displays a single subscription. |
|
395 | - * |
|
396 | - * @param string $subscription |
|
397 | - * |
|
398 | - * @return string |
|
399 | - */ |
|
400 | - public function display_single_subscription( $subscription ) { |
|
401 | - |
|
402 | - // Fetch the subscription. |
|
403 | - $subscription = new WPInv_Subscription( (int) $subscription ); |
|
404 | - |
|
405 | - if ( ! $subscription->exists() ) { |
|
406 | - |
|
407 | - return aui()->alert( |
|
408 | - array( |
|
409 | - 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
410 | - 'type' => 'error', |
|
411 | - ) |
|
412 | - ); |
|
413 | - |
|
414 | - } |
|
415 | - |
|
416 | - // Ensure that the user owns this subscription key. |
|
417 | - if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
418 | - |
|
419 | - return aui()->alert( |
|
420 | - array( |
|
421 | - 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
422 | - 'type' => 'error', |
|
423 | - ) |
|
424 | - ); |
|
425 | - |
|
426 | - } |
|
427 | - |
|
428 | - return wpinv_get_template_html( |
|
429 | - 'subscriptions/subscription-details.php', |
|
430 | - array( |
|
431 | - 'subscription' => $subscription, |
|
432 | - 'widget' => $this, |
|
433 | - ) |
|
434 | - ); |
|
435 | - |
|
436 | - } |
|
382 | + if ( isset( $fields['start_date'] ) && 'pending' == $subscription->get_status() ) { |
|
383 | + unset( $fields['start_date'] ); |
|
384 | + } |
|
385 | + |
|
386 | + if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) { |
|
387 | + unset( $fields['initial_amount'] ); |
|
388 | + } |
|
389 | + |
|
390 | + return $fields; |
|
391 | + } |
|
392 | + |
|
393 | + /** |
|
394 | + * Displays a single subscription. |
|
395 | + * |
|
396 | + * @param string $subscription |
|
397 | + * |
|
398 | + * @return string |
|
399 | + */ |
|
400 | + public function display_single_subscription( $subscription ) { |
|
401 | + |
|
402 | + // Fetch the subscription. |
|
403 | + $subscription = new WPInv_Subscription( (int) $subscription ); |
|
404 | + |
|
405 | + if ( ! $subscription->exists() ) { |
|
406 | + |
|
407 | + return aui()->alert( |
|
408 | + array( |
|
409 | + 'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ), |
|
410 | + 'type' => 'error', |
|
411 | + ) |
|
412 | + ); |
|
413 | + |
|
414 | + } |
|
415 | + |
|
416 | + // Ensure that the user owns this subscription key. |
|
417 | + if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) { |
|
418 | + |
|
419 | + return aui()->alert( |
|
420 | + array( |
|
421 | + 'content' => wp_kses_post( __( 'You do not have permission to view this subscription. Ensure that you are logged in to the account that owns the subscription.', 'invoicing' ) ), |
|
422 | + 'type' => 'error', |
|
423 | + ) |
|
424 | + ); |
|
425 | + |
|
426 | + } |
|
427 | + |
|
428 | + return wpinv_get_template_html( |
|
429 | + 'subscriptions/subscription-details.php', |
|
430 | + array( |
|
431 | + 'subscription' => $subscription, |
|
432 | + 'widget' => $this, |
|
433 | + ) |
|
434 | + ); |
|
435 | + |
|
436 | + } |
|
437 | 437 | |
438 | 438 | } |