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