Passed
Push — master ( f4ec69...bb5579 )
by Brian
05:20
created
widgets/subscriptions.php 1 patch
Spacing   +72 added lines, -72 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'     => '',
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 		);
47 47
 
48 48
 
49
-		parent::__construct( $options );
49
+		parent::__construct($options);
50 50
 	}
51 51
 
52 52
 	/**
@@ -57,12 +57,12 @@  discard block
 block discarded – undo
57 57
 	public function get_subscriptions() {
58 58
 
59 59
 		// Prepare license args.
60
-		$args  = array(
60
+		$args = array(
61 61
 			'customer_in' => get_current_user_id(),
62
-			'paged'       => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
62
+			'paged'       => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
63 63
 		);
64 64
 
65
-		return new GetPaid_Subscriptions_Query( $args );
65
+		return new GetPaid_Subscriptions_Query($args);
66 66
 
67 67
 	}
68 68
 
@@ -75,14 +75,14 @@  discard block
 block discarded – undo
75 75
 	 *
76 76
 	 * @return mixed|string|bool
77 77
 	 */
78
-	public function output( $args = array(), $widget_args = array(), $content = '' ) {
78
+	public function output($args = array(), $widget_args = array(), $content = '') {
79 79
 
80 80
 		// Ensure that the user is logged in.
81
-		if ( ! is_user_logged_in() ) {
81
+		if (!is_user_logged_in()) {
82 82
 
83 83
 			return aui()->alert(
84 84
 				array(
85
-					'content' => wp_kses_post( __( 'You need to log-in or create an account to view this section.', 'invoicing' ) ),
85
+					'content' => wp_kses_post(__('You need to log-in or create an account to view this section.', 'invoicing')),
86 86
 					'type'    => 'error',
87 87
 				)
88 88
 			);
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 		}
91 91
 
92 92
 		// Are we displaying a single subscription?
93
-		if ( isset( $_GET['subscription'] ) ) {
94
-			return $this->display_single_subscription( trim( $_GET['subscription'] ) );
93
+		if (isset($_GET['subscription'])) {
94
+			return $this->display_single_subscription(trim($_GET['subscription']));
95 95
 		}
96 96
 
97 97
 		// Retrieve the user's subscriptions.
@@ -101,27 +101,27 @@  discard block
 block discarded – undo
101 101
 		ob_start();
102 102
 
103 103
 		// Backwards compatibility.
104
-		do_action( 'wpinv_before_user_subscriptions' );
104
+		do_action('wpinv_before_user_subscriptions');
105 105
 
106 106
 		// Display errors and notices.
107 107
 		wpinv_print_errors();
108 108
 
109
-		do_action( 'getpaid_license_manager_before_subscriptions', $subscriptions );
109
+		do_action('getpaid_license_manager_before_subscriptions', $subscriptions);
110 110
 
111 111
 		// Print the table header.
112 112
 		$this->print_table_header();
113 113
 
114 114
 		// Print table body.
115
-		$this->print_table_body( $subscriptions->get_results() );
115
+		$this->print_table_body($subscriptions->get_results());
116 116
 
117 117
 		// Print table footer.
118 118
 		$this->print_table_footer();
119 119
 
120 120
 		// Print the navigation.
121
-		$this->print_navigation( $subscriptions->get_total() );
121
+		$this->print_navigation($subscriptions->get_total());
122 122
 
123 123
 		// Backwards compatibility.
124
-		do_action( 'wpinv_after_user_subscriptions' );
124
+		do_action('wpinv_after_user_subscriptions');
125 125
 
126 126
 		// Return the output.
127 127
 		return ob_get_clean();
@@ -136,13 +136,13 @@  discard block
 block discarded – undo
136 136
 	public function get_subscriptions_table_columns() {
137 137
 
138 138
 		$columns = array(
139
-			'subscription'   => __( 'Subscription', 'invoicing' ),
140
-			'amount'         => __( 'Amount', 'invoicing' ),
141
-			'renewal-date'   => __( 'Next payment', 'invoicing' ),
142
-			'status'         => __( 'Status', 'invoicing' ),
139
+			'subscription'   => __('Subscription', 'invoicing'),
140
+			'amount'         => __('Amount', 'invoicing'),
141
+			'renewal-date'   => __('Next payment', 'invoicing'),
142
+			'status'         => __('Status', 'invoicing'),
143 143
 		);
144 144
 
145
-		return apply_filters( 'getpaid_frontend_subscriptions_table_columns', $columns );
145
+		return apply_filters('getpaid_frontend_subscriptions_table_columns', $columns);
146 146
 	}
147 147
 
148 148
 	/**
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 
158 158
 				<thead>
159 159
 					<tr>
160
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
161
-							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class( $key ); ?>">
162
-								<?php echo sanitize_text_field( $label ); ?>
160
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
161
+							<th scope="col" class="font-weight-bold getpaid-subscriptions-table-<?php echo sanitize_html_class($key); ?>">
162
+								<?php echo sanitize_text_field($label); ?>
163 163
 							</th>
164 164
 						<?php endforeach; ?>
165 165
 					</tr>
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 	 *
175 175
 	 * @param WPInv_Subscription[] $subscriptions
176 176
 	 */
177
-	public function print_table_body( $subscriptions ) {
177
+	public function print_table_body($subscriptions) {
178 178
 
179
-		if ( empty( $subscriptions ) ) {
179
+		if (empty($subscriptions)) {
180 180
 			$this->print_table_body_no_subscriptions();
181 181
 		} else {
182
-			$this->print_table_body_subscriptions( $subscriptions );
182
+			$this->print_table_body_subscriptions($subscriptions);
183 183
 		}
184 184
 
185 185
 	}
@@ -194,12 +194,12 @@  discard block
 block discarded – undo
194 194
 		<tbody>
195 195
 
196 196
 			<tr>
197
-				<td colspan="<?php echo count( $this->get_subscriptions_table_columns() ); ?>">
197
+				<td colspan="<?php echo count($this->get_subscriptions_table_columns()); ?>">
198 198
 
199 199
 					<?php
200 200
 						echo aui()->alert(
201 201
 							array(
202
-								'content' => wp_kses_post( __( 'No subscriptions found.', 'invoicing' ) ),
202
+								'content' => wp_kses_post(__('No subscriptions found.', 'invoicing')),
203 203
 								'type'    => 'warning',
204 204
 							)
205 205
 						);
@@ -217,12 +217,12 @@  discard block
 block discarded – undo
217 217
 	 *
218 218
 	 * @param WPInv_Subscription[] $subscriptions
219 219
 	 */
220
-	public function print_table_body_subscriptions( $subscriptions ) {
220
+	public function print_table_body_subscriptions($subscriptions) {
221 221
 
222 222
 		?>
223 223
 		<tbody>
224 224
 
225
-			<?php foreach ( $subscriptions as $subscription ) : ?>
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 228
 						wpinv_get_template(
@@ -248,28 +248,28 @@  discard block
 block discarded – undo
248 248
 	 * @since       1.0.0
249 249
 	 * @return      string
250 250
 	 */
251
-	public function add_row_actions( $content, $subscription ) {
251
+	public function add_row_actions($content, $subscription) {
252 252
 
253 253
 		// Prepare row actions.
254 254
 		$actions = array();
255 255
 
256 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>';
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 260
 
261 261
 		// Filter the actions.
262
-		$actions = apply_filters( 'getpaid_subscriptions_table_subscription_actions', $actions, $subscription );
262
+		$actions = apply_filters('getpaid_subscriptions_table_subscription_actions', $actions, $subscription);
263 263
 
264
-		$sanitized  = array();
265
-		foreach ( $actions as $key => $action ) {
266
-			$key         = sanitize_html_class( $key );
267
-			$action      = wp_kses_post( $action );
264
+		$sanitized = array();
265
+		foreach ($actions as $key => $action) {
266
+			$key         = sanitize_html_class($key);
267
+			$action      = wp_kses_post($action);
268 268
 			$sanitized[] = "<span class='$key'>$action</span>";
269 269
 		}
270 270
 
271 271
 		$row_actions  = "<small class='form-text getpaid-subscription-item-actions'>";
272
-		$row_actions .= implode( ' | ', $sanitized );
272
+		$row_actions .= implode(' | ', $sanitized);
273 273
 		$row_actions .= '</small>';
274 274
 
275 275
 		return $content . $row_actions;
@@ -285,9 +285,9 @@  discard block
 block discarded – undo
285 285
 
286 286
 				<tfoot>
287 287
 					<tr>
288
-						<?php foreach ( $this->get_subscriptions_table_columns() as $key => $label ) : ?>
289
-							<th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class( $key ); ?>">
290
-								<?php echo sanitize_text_field( $label ); ?>
288
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
289
+							<th class="font-weight-bold getpaid-subscriptions-<?php echo sanitize_html_class($key); ?>">
290
+								<?php echo sanitize_text_field($label); ?>
291 291
 							</th>
292 292
 						<?php endforeach; ?>
293 293
 					</tr>
@@ -303,22 +303,22 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param int $total
305 305
 	 */
306
-	public function print_navigation( $total ) {
306
+	public function print_navigation($total) {
307 307
 
308
-		if ( $total < 1 ) {
308
+		if ($total < 1) {
309 309
 
310 310
 			// Out-of-bounds, run the query again without LIMIT for total count.
311
-			$args  = array(
311
+			$args = array(
312 312
 				'customer_in' => get_current_user_id(),
313 313
 				'fields'      => 'id',
314 314
 			);
315 315
 
316
-			$count_query = new GetPaid_Subscriptions_Query( $args );
316
+			$count_query = new GetPaid_Subscriptions_Query($args);
317 317
 			$total       = $count_query->get_total();
318 318
 		}
319 319
 
320 320
 		// Abort if we do not have pages.
321
-		if ( 2 > $total ) {
321
+		if (2 > $total) {
322 322
 			return;
323 323
 		}
324 324
 
@@ -330,9 +330,9 @@  discard block
 block discarded – undo
330 330
 
331 331
 				echo 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
 			?>
@@ -348,29 +348,29 @@  discard block
 block discarded – undo
348 348
 	 *
349 349
 	 * @return array
350 350
 	 */
351
-	public function get_single_subscription_columns( $subscription ) {
351
+	public function get_single_subscription_columns($subscription) {
352 352
 
353 353
 		// Prepare subscription detail columns.
354 354
 		$fields = apply_filters(
355 355
 			'getpaid_single_subscription_details_fields',
356 356
 			array(
357
-				'status'           => __( 'Status', 'invoicing' ),
358
-				'initial_amount'   => __( 'Initial amount', 'invoicing' ),
359
-				'recurring_amount' => __( 'Recurring amount', 'invoicing' ),
360
-				'start_date'       => __( 'Start date', 'invoicing' ),
361
-				'expiry_date'      => __( 'Next payment', 'invoicing' ),
362
-				'payments'         => __( 'Payments', 'invoicing' ),
363
-				'item'             => __( 'Item', 'invoicing' ),
357
+				'status'           => __('Status', 'invoicing'),
358
+				'initial_amount'   => __('Initial amount', 'invoicing'),
359
+				'recurring_amount' => __('Recurring amount', 'invoicing'),
360
+				'start_date'       => __('Start date', 'invoicing'),
361
+				'expiry_date'      => __('Next payment', 'invoicing'),
362
+				'payments'         => __('Payments', 'invoicing'),
363
+				'item'             => __('Item', 'invoicing'),
364 364
 			),
365 365
 			$subscription
366 366
 		);
367 367
 
368
-		if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
369
-			$fields['expiry_date'] = __( 'End date', 'invoicing' );
368
+		if (!$subscription->is_active() || $subscription->is_last_renewal()) {
369
+			$fields['expiry_date'] = __('End date', 'invoicing');
370 370
 		}
371 371
 
372
-		if ( $subscription->get_initial_amount() == $subscription->get_recurring_amount() ) {
373
-			unset( $fields['initial_amount'] );
372
+		if ($subscription->get_initial_amount() == $subscription->get_recurring_amount()) {
373
+			unset($fields['initial_amount']);
374 374
 		}
375 375
 
376 376
 		return $fields;
@@ -383,16 +383,16 @@  discard block
 block discarded – undo
383 383
 	 *
384 384
 	 * @return string
385 385
 	 */
386
-	public function display_single_subscription( $subscription ) {
386
+	public function display_single_subscription($subscription) {
387 387
 
388 388
 		// Fetch the subscription.
389
-		$subscription = new WPInv_Subscription( (int) $subscription );
389
+		$subscription = new WPInv_Subscription((int) $subscription);
390 390
 
391
-		if ( ! $subscription->get_id() ) {
391
+		if (!$subscription->get_id()) {
392 392
 
393 393
 			return aui()->alert(
394 394
 				array(
395
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
395
+					'content' => wp_kses_post(__('Subscription not found.', 'invoicing')),
396 396
 					'type'    => 'error',
397 397
 				)
398 398
 			);
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 		}
401 401
 
402 402
 		// Ensure that the user owns this subscription key.
403
-		if ( get_current_user_id() != $subscription->get_customer_id() && current_user_can( 'edit_options' ) ) {
403
+		if (get_current_user_id() != $subscription->get_customer_id() && current_user_can('edit_options')) {
404 404
 
405 405
 			return aui()->alert(
406 406
 				array(
407
-					'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' ) ),
407
+					'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')),
408 408
 					'type'    => 'error',
409 409
 				)
410 410
 			);
Please login to merge, or discard this patch.