Passed
Push — master ( 15a985...3bfe39 )
by Brian
05:01
created
widgets/subscriptions.php 1 patch
Indentation   +347 added lines, -347 removed lines patch added patch discarded remove patch
@@ -14,143 +14,143 @@  discard block
 block discarded – undo
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,122 +166,122 @@  discard block
 block discarded – undo
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
-						aui()->alert(
200
-							array(
201
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
-								'type'    => 'warning',
203
-							),
199
+                        aui()->alert(
200
+                            array(
201
+                                'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
+                                'type'    => 'warning',
203
+                            ),
204 204
                             true
205
-						);
206
-					?>
205
+                        );
206
+                    ?>
207 207
 
208 208
 				</td>
209 209
 			</tr>
210 210
 
211 211
 		</tbody>
212 212
 		<?php
213
-	}
213
+    }
214 214
 
215
-	/**
216
-	 * Displays the table body if subscriptions were found.
217
-	 *
218
-	 * @param WPInv_Subscription[] $subscriptions
219
-	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
215
+    /**
216
+     * Displays the table body if subscriptions were found.
217
+     *
218
+     * @param WPInv_Subscription[] $subscriptions
219
+     */
220
+    public function print_table_body_subscriptions( $subscriptions ) {
221 221
 
222
-		?>
222
+        ?>
223 223
 		<tbody>
224 224
 
225 225
 			<?php foreach ( $subscriptions as $subscription ) : ?>
226 226
 				<tr class="getpaid-subscriptions-table-row subscription-<?php echo (int) $subscription->get_id(); ?>">
227 227
 					<?php
228
-						wpinv_get_template(
229
-							'subscriptions/subscriptions-table-row.php',
230
-							array(
231
-								'subscription' => $subscription,
232
-								'widget'       => $this,
233
-							)
234
-						);
235
-					?>
228
+                        wpinv_get_template(
229
+                            'subscriptions/subscriptions-table-row.php',
230
+                            array(
231
+                                'subscription' => $subscription,
232
+                                'widget'       => $this,
233
+                            )
234
+                        );
235
+                    ?>
236 236
 				</tr>
237 237
 			<?php endforeach; ?>
238 238
 
239 239
 		</tbody>
240 240
 		<?php
241
-	}
242
-
243
-	/**
244
-	 * Adds row actions to a column
245
-	 *
246
-	 * @param string $content column content
247
-	 * @param WPInv_Subscription $subscription
248
-	 * @since       1.0.0
249
-	 * @return      string
250
-	 */
251
-	public function add_row_actions( $content, $subscription ) {
252
-
253
-		// Prepare row actions.
254
-		$actions = array();
255
-
256
-		// View subscription action.
257
-		$view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
-		$view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
-		$actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
-
261
-		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
-
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
268
-			$sanitized[] = "<span class='$key'>$action</span>";
269
-		}
270
-
271
-		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
273
-		$row_actions .= '</small>';
274
-
275
-		return $content . $row_actions;
276
-	}
277
-
278
-	/**
279
-	 * Displays the table footer.
280
-	 *
281
-	 */
282
-	public function print_table_footer() {
283
-
284
-		?>
241
+    }
242
+
243
+    /**
244
+     * Adds row actions to a column
245
+     *
246
+     * @param string $content column content
247
+     * @param WPInv_Subscription $subscription
248
+     * @since       1.0.0
249
+     * @return      string
250
+     */
251
+    public function add_row_actions( $content, $subscription ) {
252
+
253
+        // Prepare row actions.
254
+        $actions = array();
255
+
256
+        // View subscription action.
257
+        $view_url        = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
258
+        $view_url        = esc_url( add_query_arg( 'subscription', (int) $subscription->get_id(), $view_url ) );
259
+        $actions['view'] = "<a href='$view_url' class='text-decoration-none'>" . __( 'Manage Subscription', 'invoicing' ) . '</a>';
260
+
261
+        // Filter the actions.
262
+        $actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
263
+
264
+        $sanitized  = array();
265
+        foreach ( $actions as $key => $action ) {
266
+            $key         = sanitize_html_class( $key );
267
+            $action      = wp_kses_post( $action );
268
+            $sanitized[] = "<span class='$key'>$action</span>";
269
+        }
270
+
271
+        $row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
+        $row_actions .= implode( ' | ', $sanitized );
273
+        $row_actions .= '</small>';
274
+
275
+        return $content . $row_actions;
276
+    }
277
+
278
+    /**
279
+     * Displays the table footer.
280
+     *
281
+     */
282
+    public function print_table_footer() {
283
+
284
+        ?>
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
@@ -296,145 +296,145 @@  discard block
 block discarded – undo
296 296
 			</table>
297 297
 		<?php
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Displays the navigation.
303
-	 *
304
-	 * @param int $total
305
-	 */
306
-	public function print_navigation( $total ) {
301
+    /**
302
+     * Displays the navigation.
303
+     *
304
+     * @param int $total
305
+     */
306
+    public function print_navigation( $total ) {
307 307
 
308
-		if ( $total < 1 ) {
308
+        if ( $total < 1 ) {
309 309
 
310
-			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
312
-				'customer_in' => get_current_user_id(),
313
-				'fields'      => 'id',
314
-			);
310
+            // Out-of-bounds, run the query again without LIMIT for total count.
311
+            $args  = array(
312
+                'customer_in' => get_current_user_id(),
313
+                'fields'      => 'id',
314
+            );
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
317
-			$total       = $count_query->get_total();
318
-		}
316
+            $count_query = new GetPaid_Subscriptions_Query( $args );
317
+            $total       = $count_query->get_total();
318
+        }
319 319
 
320
-		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
322
-			return;
323
-		}
320
+        // Abort if we do not have pages.
321
+        if ( 2 > $total ) {
322
+            return;
323
+        }
324 324
 
325
-		?>
325
+        ?>
326 326
 
327 327
 		<div class="getpaid-subscriptions-pagination">
328 328
 			<?php
329
-				$big = 999999;
330
-
331
-				echo wp_kses_post(
332
-					getpaid_paginate_links(
333
-						array(
334
-							'base'   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
335
-							'format' => '?paged=%#%',
336
-							'total'  => (int) ceil( $total / 10 ),
337
-						)
338
-					)
339
-				);
340
-			?>
329
+                $big = 999999;
330
+
331
+                echo wp_kses_post(
332
+                    getpaid_paginate_links(
333
+                        array(
334
+                            'base'   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
335
+                            'format' => '?paged=%#%',
336
+                            'total'  => (int) ceil( $total / 10 ),
337
+                        )
338
+                    )
339
+                );
340
+            ?>
341 341
 		</div>
342 342
 
343 343
 		<?php
344
-	}
345
-
346
-	/**
347
-	 * Returns a single subscription's columns.
348
-	 *
349
-	 * @param WPInv_Subscription $subscription
350
-	 *
351
-	 * @return array
352
-	 */
353
-	public function get_single_subscription_columns( $subscription ) {
354
-
355
-		// Prepare subscription detail columns.
356
-		$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
357
-		$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
358
-		$fields             = apply_filters(
359
-			'getpaid_single_subscription_details_fields',
360
-			array(
361
-				'status'           => __( 'Status', 'invoicing' ),
362
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
363
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
364
-				'start_date'       => __( 'Start date', 'invoicing' ),
365
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
366
-				'payments'         => __( 'Payments', 'invoicing' ),
367
-				'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
368
-			),
369
-			$subscription,
370
-			$items_count
371
-		);
372
-
373
-		if ( isset( $fields['expiry_date'] ) ) {
374
-
375
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
376
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
377
-			}
378
-
379
-			if ( 'pending' === $subscription->get_status() ) {
380
-				unset( $fields['expiry_date'] );
381
-			}
382
-		}
383
-
384
-		if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) {
385
-			unset( $fields['start_date'] );
386
-		}
387
-
388
-		if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) {
389
-			unset( $fields['initial_amount'] );
390
-		}
391
-
392
-		return $fields;
393
-	}
394
-
395
-	/**
396
-	 * Displays a single subscription.
397
-	 *
398
-	 * @param string $subscription
399
-	 *
400
-	 * @return string
401
-	 */
402
-	public function display_single_subscription( $subscription ) {
403
-
404
-		// Fetch the subscription.
405
-		$subscription = new WPInv_Subscription( (int) $subscription );
406
-
407
-		if ( ! $subscription->exists() ) {
408
-
409
-			return aui()->alert(
410
-				array(
411
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
412
-					'type'    => 'error',
413
-				)
414
-			);
415
-
416
-		}
417
-
418
-		// Ensure that the user owns this subscription key.
419
-		if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
420
-
421
-			return aui()->alert(
422
-				array(
423
-					'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' ) ),
424
-					'type'    => 'error',
425
-				)
426
-			);
427
-
428
-		}
429
-
430
-		return wpinv_get_template_html(
431
-			'subscriptions/subscription-details.php',
432
-			array(
433
-				'subscription' => $subscription,
434
-				'widget'       => $this,
435
-			)
436
-		);
437
-
438
-	}
344
+    }
345
+
346
+    /**
347
+     * Returns a single subscription's columns.
348
+     *
349
+     * @param WPInv_Subscription $subscription
350
+     *
351
+     * @return array
352
+     */
353
+    public function get_single_subscription_columns( $subscription ) {
354
+
355
+        // Prepare subscription detail columns.
356
+        $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_invoice_id(), $subscription->get_id() );
357
+        $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
358
+        $fields             = apply_filters(
359
+            'getpaid_single_subscription_details_fields',
360
+            array(
361
+                'status'           => __( 'Status', 'invoicing' ),
362
+                'initial_amount'   => __( 'Initial amount', 'invoicing' ),
363
+                'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
364
+                'start_date'       => __( 'Start date', 'invoicing' ),
365
+                'expiry_date'      => __( 'Next payment', 'invoicing' ),
366
+                'payments'         => __( 'Payments', 'invoicing' ),
367
+                'item'             => _n( 'Item', 'Items', $items_count, 'invoicing' ),
368
+            ),
369
+            $subscription,
370
+            $items_count
371
+        );
372
+
373
+        if ( isset( $fields['expiry_date'] ) ) {
374
+
375
+            if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
376
+                $fields['expiry_date'] = __( 'End date', 'invoicing' );
377
+            }
378
+
379
+            if ( 'pending' === $subscription->get_status() ) {
380
+                unset( $fields['expiry_date'] );
381
+            }
382
+        }
383
+
384
+        if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) {
385
+            unset( $fields['start_date'] );
386
+        }
387
+
388
+        if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) {
389
+            unset( $fields['initial_amount'] );
390
+        }
391
+
392
+        return $fields;
393
+    }
394
+
395
+    /**
396
+     * Displays a single subscription.
397
+     *
398
+     * @param string $subscription
399
+     *
400
+     * @return string
401
+     */
402
+    public function display_single_subscription( $subscription ) {
403
+
404
+        // Fetch the subscription.
405
+        $subscription = new WPInv_Subscription( (int) $subscription );
406
+
407
+        if ( ! $subscription->exists() ) {
408
+
409
+            return aui()->alert(
410
+                array(
411
+                    'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
412
+                    'type'    => 'error',
413
+                )
414
+            );
415
+
416
+        }
417
+
418
+        // Ensure that the user owns this subscription key.
419
+        if ( get_current_user_id() != $subscription->get_customer_id() && ! wpinv_current_user_can_manage_invoicing() ) {
420
+
421
+            return aui()->alert(
422
+                array(
423
+                    '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' ) ),
424
+                    'type'    => 'error',
425
+                )
426
+            );
427
+
428
+        }
429
+
430
+        return wpinv_get_template_html(
431
+            'subscriptions/subscription-details.php',
432
+            array(
433
+                'subscription' => $subscription,
434
+                'widget'       => $this,
435
+            )
436
+        );
437
+
438
+    }
439 439
 
440 440
 }
Please login to merge, or discard this patch.