Passed
Push — master ( 662c2f...5f58dc )
by Brian
10:10
created
widgets/subscriptions.php 2 patches
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.
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 esc_attr( $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 esc_attr($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
 						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
                             true
@@ -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 esc_attr( $key ); ?>">
290
-								<?php echo esc_html( $label ); ?>
288
+						<?php foreach ($this->get_subscriptions_table_columns() as $key => $label) : ?>
289
+							<th class="font-weight-bold getpaid-subscriptions-<?php echo esc_attr($key); ?>">
290
+								<?php echo esc_html($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
 
@@ -331,9 +331,9 @@  discard block
 block discarded – undo
331 331
 				echo wp_kses_post(
332 332
 					getpaid_paginate_links(
333 333
 						array(
334
-							'base'   => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
334
+							'base'   => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
335 335
 							'format' => '?paged=%#%',
336
-							'total'  => (int) ceil( $total / 10 ),
336
+							'total'  => (int) ceil($total / 10),
337 337
 						)
338 338
 					)
339 339
 				);
@@ -350,43 +350,43 @@  discard block
 block discarded – undo
350 350
 	 *
351 351
 	 * @return array
352 352
 	 */
353
-	public function get_single_subscription_columns( $subscription ) {
353
+	public function get_single_subscription_columns($subscription) {
354 354
 
355 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'] );
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 358
 		$fields             = apply_filters(
359 359
 			'getpaid_single_subscription_details_fields',
360 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' ),
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 368
 			),
369 369
 			$subscription,
370 370
 			$items_count
371 371
 		);
372 372
 
373
-		if ( isset( $fields['expiry_date'] ) ) {
373
+		if (isset($fields['expiry_date'])) {
374 374
 
375
-			if ( ! $subscription->is_active() || $subscription->is_last_renewal() ) {
376
-				$fields['expiry_date'] = __( 'End date', 'invoicing' );
375
+			if (!$subscription->is_active() || $subscription->is_last_renewal()) {
376
+				$fields['expiry_date'] = __('End date', 'invoicing');
377 377
 			}
378 378
 
379
-			if ( 'pending' === $subscription->get_status() ) {
380
-				unset( $fields['expiry_date'] );
379
+			if ('pending' === $subscription->get_status()) {
380
+				unset($fields['expiry_date']);
381 381
 			}
382 382
 		}
383 383
 
384
-		if ( isset( $fields['start_date'] ) && 'pending' === $subscription->get_status() ) {
385
-			unset( $fields['start_date'] );
384
+		if (isset($fields['start_date']) && 'pending' === $subscription->get_status()) {
385
+			unset($fields['start_date']);
386 386
 		}
387 387
 
388
-		if ( $subscription->get_initial_amount() === $subscription->get_recurring_amount() ) {
389
-			unset( $fields['initial_amount'] );
388
+		if ($subscription->get_initial_amount() === $subscription->get_recurring_amount()) {
389
+			unset($fields['initial_amount']);
390 390
 		}
391 391
 
392 392
 		return $fields;
@@ -399,16 +399,16 @@  discard block
 block discarded – undo
399 399
 	 *
400 400
 	 * @return string
401 401
 	 */
402
-	public function display_single_subscription( $subscription ) {
402
+	public function display_single_subscription($subscription) {
403 403
 
404 404
 		// Fetch the subscription.
405
-		$subscription = new WPInv_Subscription( (int) $subscription );
405
+		$subscription = new WPInv_Subscription((int) $subscription);
406 406
 
407
-		if ( ! $subscription->exists() ) {
407
+		if (!$subscription->exists()) {
408 408
 
409 409
 			return aui()->alert(
410 410
 				array(
411
-					'content' => wp_kses_post( __( 'Subscription not found.', 'invoicing' ) ),
411
+					'content' => wp_kses_post(__('Subscription not found.', 'invoicing')),
412 412
 					'type'    => 'error',
413 413
 				)
414 414
 			);
@@ -416,11 +416,11 @@  discard block
 block discarded – undo
416 416
 		}
417 417
 
418 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() ) {
419
+		if (get_current_user_id() != $subscription->get_customer_id() && !wpinv_current_user_can_manage_invoicing()) {
420 420
 
421 421
 			return aui()->alert(
422 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' ) ),
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 424
 					'type'    => 'error',
425 425
 				)
426 426
 			);
Please login to merge, or discard this patch.
includes/class-getpaid-notification-email-sender.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Notification_Email_Sender {
14 14
 
15 15
     /**
16
-	 * Whether or not we should inline CSS into the email.
17
-	 */
18
-	public $inline_css = true;
16
+     * Whether or not we should inline CSS into the email.
17
+     */
18
+    public $inline_css = true;
19 19
 
20 20
     /**
21
-	 * The wp_mail() data.
22
-	 */
21
+     * The wp_mail() data.
22
+     */
23 23
     public $wp_mail_data = null;
24 24
 
25 25
     /**
26
-	 * Sends a new email.
26
+     * Sends a new email.
27 27
      *
28 28
      * @param string|array $to The recipients email or an array of recipient emails.
29 29
      * @param string $subject The email's subject.
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
      * @param array $attachments The email attachments.
32 32
      *
33 33
      * @return bool
34
-	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
34
+     */
35
+    public function send( $to, $subject, $email, $attachments = array() ) {
36 36
 
37
-		/*
37
+        /*
38 38
 		 * Allow to filter data on per-email basis.
39 39
 		 */
40
-		$data = apply_filters(
41
-			'getpaid_email_data',
42
-			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
-				'headers'     => $this->get_headers(),
47
-				'attachments' => $attachments,
48
-			),
49
-			$this
50
-		);
40
+        $data = apply_filters(
41
+            'getpaid_email_data',
42
+            array(
43
+                'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
+                'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
+                'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
+                'headers'     => $this->get_headers(),
47
+                'attachments' => $attachments,
48
+            ),
49
+            $this
50
+        );
51 51
 
52 52
         // Remove slashes.
53 53
         $data               = (array) wp_unslash( $data );
54 54
 
55 55
         // Cache it.
56
-		$this->wp_mail_data = $data;
56
+        $this->wp_mail_data = $data;
57 57
 
58
-		// Attach our own hooks.
59
-		$this->before_sending();
58
+        // Attach our own hooks.
59
+        $this->before_sending();
60 60
 
61 61
         $result = false;
62 62
 
63 63
         foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
64
+            $result = $this->_send( $to, $data );
65 65
         }
66 66
 
67
-		// Remove our hooks.
68
-		$this->after_sending();
67
+        // Remove our hooks.
68
+        $this->after_sending();
69 69
 
70
-		$this->wp_mail_data = null;
70
+        $this->wp_mail_data = null;
71 71
 
72
-		return $result;
73
-	}
72
+        return $result;
73
+    }
74 74
 
75
-	/**
76
-	 * Does the actual sending.
75
+    /**
76
+     * Does the actual sending.
77 77
      *
78 78
      * @param string $to The recipient's email.
79 79
      * @param array $data The email's data.
@@ -81,81 +81,81 @@  discard block
 block discarded – undo
81 81
      * @param array $attachments The email attachments.
82 82
      *
83 83
      * @return bool
84
-	 */
85
-	protected function _send( $to, $data ) {
86
-
87
-		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
-
90
-		// Send the actual email.
91
-		$result = call_user_func(
92
-			$sending_function,
93
-			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
-			$data['email'],
96
-			$data['headers'],
97
-			$data['attachments']
98
-		);
99
-
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
-		}
104
-
105
-		return $result;
106
-	}
84
+     */
85
+    protected function _send( $to, $data ) {
86
+
87
+        // Prepare the sending function.
88
+        $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
+
90
+        // Send the actual email.
91
+        $result = call_user_func(
92
+            $sending_function,
93
+            $to,
94
+            html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
+            $data['email'],
96
+            $data['headers'],
97
+            $data['attachments']
98
+        );
99
+
100
+        if ( ! $result ) {
101
+            $log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
+            wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
+        }
104
+
105
+        return $result;
106
+    }
107 107
 
108 108
     /**
109
-	 * Retrieves email headers.
110
-	 */
111
-	public function get_headers() {
109
+     * Retrieves email headers.
110
+     */
111
+    public function get_headers() {
112 112
 
113
-		$name       = $this->get_from_name();
114
-		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
113
+        $name       = $this->get_from_name();
114
+        $reply_to   = $this->get_reply_to();
115
+        $headers    = array( "Reply-To:$name <$reply_to>" );
116 116
 
117
-		return apply_filters( 'getpaid_email_headers', $headers, $this );
117
+        return apply_filters( 'getpaid_email_headers', $headers, $this );
118 118
 
119
-	}
119
+    }
120 120
 
121 121
     /**
122
-	 * Fires before an email is sent
123
-	 *
124
-	 * @since 1.0.0
125
-	 */
126
-	public function before_sending() {
122
+     * Fires before an email is sent
123
+     *
124
+     * @since 1.0.0
125
+     */
126
+    public function before_sending() {
127 127
 
128 128
         do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
129
+        add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
+        add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
+        add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
+        add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
133 133
 
134
-	}
134
+    }
135 135
 
136 136
     /**
137
-	 * Returns the from name.
138
-	 */
139
-	public function get_from_name() {
137
+     * Returns the from name.
138
+     */
139
+    public function get_from_name() {
140 140
 
141 141
         $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name = get_bloginfo( 'name' );
143
+        if ( empty( $from_name ) ) {
144
+            $from_name = get_bloginfo( 'name' );
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+        return wp_specialchars_decode( $from_name, ENT_QUOTES );
148 148
     }
149 149
 
150 150
     /**
151
-	 * Returns the from email.
152
-	 */
153
-	public function get_from_address() {
151
+     * Returns the from email.
152
+     */
153
+    public function get_from_address() {
154 154
 
155 155
         $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address = $this->default_from_address();
157
+        if ( ! is_email( $from_address ) ) {
158
+            $from_address = $this->default_from_address();
159 159
         }
160 160
 
161 161
         return $from_address;
@@ -163,75 +163,75 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     /**
166
-	 * The default emails from address.
167
-	 *
168
-	 * Defaults to wordpress@$sitename
169
-	 * Some hosts will block outgoing mail from this address if it doesn't exist,
170
-	 * but there's no easy alternative. Defaulting to admin_email might appear to be
171
-	 * another option, but some hosts may refuse to relay mail from an unknown domain.
172
-	 *
173
-	 */
174
-	public function default_from_address() {
175
-
176
-		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
180
-		}
181
-
182
-		$from_email = 'wordpress@' . $sitename;
183
-
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
166
+     * The default emails from address.
167
+     *
168
+     * Defaults to wordpress@$sitename
169
+     * Some hosts will block outgoing mail from this address if it doesn't exist,
170
+     * but there's no easy alternative. Defaulting to admin_email might appear to be
171
+     * another option, but some hosts may refuse to relay mail from an unknown domain.
172
+     *
173
+     */
174
+    public function default_from_address() {
175
+
176
+        // Get the site domain and get rid of www.
177
+        $sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
+        if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
+            $sitename = substr( $sitename, 4 );
180
+        }
181
+
182
+        $from_email = 'wordpress@' . $sitename;
183
+
184
+        return apply_filters( 'getpaid_default_from_address', $from_email );
185 185
 
186 186
     }
187 187
 
188 188
     /**
189
-	 * Get the email reply-to.
190
-	 *
191
-	 *
192
-	 * @return string The email reply-to address.
193
-	 */
194
-	public function get_reply_to() {
189
+     * Get the email reply-to.
190
+     *
191
+     *
192
+     * @return string The email reply-to address.
193
+     */
194
+    public function get_reply_to() {
195 195
 
196
-		$reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
196
+        $reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to = get_option( 'admin_email' );
200
-		}
198
+        if ( ! is_email( $reply_to ) ) {
199
+            $reply_to = get_option( 'admin_email' );
200
+        }
201 201
 
202
-		return $reply_to;
202
+        return $reply_to;
203 203
     }
204 204
 
205 205
     /**
206
-	 * Get the email content type.
207
-	 *
208
-	 */
209
-	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
206
+     * Get the email content type.
207
+     *
208
+     */
209
+    public function get_content_type() {
210
+        return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
211 211
     }
212 212
 
213 213
     /**
214
-	 * Ensures that our email messages are not messed up by template plugins.
215
-	 *
216
-	 * @return array wp_mail_data.
217
-	 */
218
-	public function ensure_email_content( $args ) {
219
-		$args['message'] = $this->wp_mail_data['email'];
220
-		return $args;
214
+     * Ensures that our email messages are not messed up by template plugins.
215
+     *
216
+     * @return array wp_mail_data.
217
+     */
218
+    public function ensure_email_content( $args ) {
219
+        $args['message'] = $this->wp_mail_data['email'];
220
+        return $args;
221 221
     }
222 222
 
223 223
     /**
224
-	 * A little house keeping after an email is sent.
225
-	 *
226
- 	 */
227
-	public function after_sending() {
224
+     * A little house keeping after an email is sent.
225
+     *
226
+     */
227
+    public function after_sending() {
228 228
 
229 229
         do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
230
+        remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
+        remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
+        remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
+        remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
234 234
 
235
-	}
235
+    }
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This function is responsible for sending emails.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      *
33 33
      * @return bool
34 34
 	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
35
+	public function send($to, $subject, $email, $attachments = array()) {
36 36
 
37 37
 		/*
38 38
 		 * Allow to filter data on per-email basis.
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		$data = apply_filters(
41 41
 			'getpaid_email_data',
42 42
 			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( wp_strip_all_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
43
+				'to'          => array_filter(array_unique(wpinv_parse_list($to))),
44
+				'subject'     => htmlspecialchars_decode(wp_strip_all_tags($subject), ENT_QUOTES),
45
+				'email'       => apply_filters('wpinv_mail_content', $email),
46 46
 				'headers'     => $this->get_headers(),
47 47
 				'attachments' => $attachments,
48 48
 			),
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		);
51 51
 
52 52
         // Remove slashes.
53
-        $data               = (array) wp_unslash( $data );
53
+        $data = (array) wp_unslash($data);
54 54
 
55 55
         // Cache it.
56 56
 		$this->wp_mail_data = $data;
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 
61 61
         $result = false;
62 62
 
63
-        foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
63
+        foreach ($this->wp_mail_data['to'] as $to) {
64
+			$result = $this->_send($to, $data);
65 65
         }
66 66
 
67 67
 		// Remove our hooks.
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @return bool
84 84
 	 */
85
-	protected function _send( $to, $data ) {
85
+	protected function _send($to, $data) {
86 86
 
87 87
 		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
88
+		$sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail');
89 89
 
90 90
 		// Send the actual email.
91 91
 		$result = call_user_func(
92 92
 			$sending_function,
93 93
 			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
94
+			html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')),
95 95
 			$data['email'],
96 96
 			$data['headers'],
97 97
 			$data['attachments']
98 98
 		);
99 99
 
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
100
+		if (!$result) {
101
+			$log_message = wp_sprintf(__("\nTime: %1\$s\nTo: %2\$s\nSubject: %3\$s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']);
102
+			wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__);
103 103
 		}
104 104
 
105 105
 		return $result;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$name       = $this->get_from_name();
114 114
 		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
115
+		$headers    = array("Reply-To:$name <$reply_to>");
116 116
 
117
-		return apply_filters( 'getpaid_email_headers', $headers, $this );
117
+		return apply_filters('getpaid_email_headers', $headers, $this);
118 118
 
119 119
 	}
120 120
 
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function before_sending() {
127 127
 
128
-        do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
128
+        do_action('getpaid_before_send_email', $this);
129
+		add_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
130
+		add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
131
+		add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
132
+		add_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
133 133
 
134 134
 	}
135 135
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function get_from_name() {
140 140
 
141
-        $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
141
+        $from_name = wpinv_get_option('email_from_name', get_bloginfo('name'));
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name = get_bloginfo( 'name' );
143
+		if (empty($from_name)) {
144
+			$from_name = get_bloginfo('name');
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+		return wp_specialchars_decode($from_name, ENT_QUOTES);
148 148
     }
149 149
 
150 150
     /**
@@ -152,9 +152,9 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function get_from_address() {
154 154
 
155
-        $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
155
+        $from_address = wpinv_get_option('email_from', $this->default_from_address());
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
157
+		if (!is_email($from_address)) {
158 158
 			$from_address = $this->default_from_address();
159 159
         }
160 160
 
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	public function default_from_address() {
175 175
 
176 176
 		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
177
+		$sitename = strtolower($_SERVER['SERVER_NAME']);
178
+		if (substr($sitename, 0, 4) == 'www.') {
179
+			$sitename = substr($sitename, 4);
180 180
 		}
181 181
 
182 182
 		$from_email = 'wordpress@' . $sitename;
183 183
 
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
184
+		return apply_filters('getpaid_default_from_address', $from_email);
185 185
 
186 186
     }
187 187
 
@@ -193,10 +193,10 @@  discard block
 block discarded – undo
193 193
 	 */
194 194
 	public function get_reply_to() {
195 195
 
196
-		$reply_to = current( wpinv_parse_list( wpinv_get_admin_email() ) );
196
+		$reply_to = current(wpinv_parse_list(wpinv_get_admin_email()));
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to = get_option( 'admin_email' );
198
+		if (!is_email($reply_to)) {
199
+			$reply_to = get_option('admin_email');
200 200
 		}
201 201
 
202 202
 		return $reply_to;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 */
209 209
 	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
210
+		return apply_filters('getpaid_email_content_type', 'text/html', $this);
211 211
     }
212 212
 
213 213
     /**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return array wp_mail_data.
217 217
 	 */
218
-	public function ensure_email_content( $args ) {
218
+	public function ensure_email_content($args) {
219 219
 		$args['message'] = $this->wp_mail_data['email'];
220 220
 		return $args;
221 221
     }
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
  	 */
227 227
 	public function after_sending() {
228 228
 
229
-        do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
229
+        do_action('getpaid_after_send_email', $this->wp_mail_data);
230
+		remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
231
+		remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
232
+		remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
233
+		remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
234 234
 
235 235
 	}
236 236
 
Please login to merge, or discard this patch.
includes/class-bp-getpaid-component.php 2 patches
Indentation   +132 added lines, -132 removed lines patch added patch discarded remove patch
@@ -17,45 +17,45 @@  discard block
 block discarded – undo
17 17
  */
18 18
 class BP_GetPaid_Component extends BP_Component {
19 19
 
20
-	/**
21
-	 * Start the component setup process.
22
-	 *
23
-	 * @since 2.1.5
24
-	 */
25
-	public function __construct() {
26
-		parent::start(
27
-			'getpaid',
28
-			'GetPaid',
29
-			buddypress()->plugin_dir,
30
-			array(
31
-				'adminbar_myaccount_order' => 30,
32
-			)
33
-		);
34
-	}
20
+    /**
21
+     * Start the component setup process.
22
+     *
23
+     * @since 2.1.5
24
+     */
25
+    public function __construct() {
26
+        parent::start(
27
+            'getpaid',
28
+            'GetPaid',
29
+            buddypress()->plugin_dir,
30
+            array(
31
+                'adminbar_myaccount_order' => 30,
32
+            )
33
+        );
34
+    }
35 35
 
36 36
     /**
37
-	 * Set up component global variables.
38
-	 *
39
-	 * @since 2.1.5
40
-	 *
41
-	 *
42
-	 * @param array $args {
43
-	 *     All values are optional.
44
-	 *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
-	 *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
-	 *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
-	 *                                           component has a root directory (the slug will be overridden by the
48
-	 *                                           post_name of the directory page). Default: the slug of the directory page
49
-	 *                                           if one is found, otherwise an empty string.
50
-	 *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
-	 *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
-	 *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
-	 *                                           'Search Groups...'.
54
-	 *     @type array    $global_tables         Optional. An array of database table names.
55
-	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56
-	 * }
57
-	 */
58
-	public function setup_globals( $args = array() ) {
37
+     * Set up component global variables.
38
+     *
39
+     * @since 2.1.5
40
+     *
41
+     *
42
+     * @param array $args {
43
+     *     All values are optional.
44
+     *     @type string   $slug                  The component slug. Used to construct certain URLs, such as 'friends' in
45
+     *                                           http://example.com/members/joe/friends/. Default: the value of $this->id.
46
+     *     @type string   $root_slug             The component root slug. Note that this value is generally unused if the
47
+     *                                           component has a root directory (the slug will be overridden by the
48
+     *                                           post_name of the directory page). Default: the slug of the directory page
49
+     *                                           if one is found, otherwise an empty string.
50
+     *     @type bool     $has_directory         Set to true if the component requires an associated WordPress page.
51
+     *     @type callable $notification_callback Optional. The callable function that formats the component's notifications.
52
+     *     @type string   $search_term           Optional. The placeholder text in the component directory search box. Eg,
53
+     *                                           'Search Groups...'.
54
+     *     @type array    $global_tables         Optional. An array of database table names.
55
+     *     @type array    $meta_tables           Optional. An array of metadata table names.
56
+     * }
57
+     */
58
+    public function setup_globals( $args = array() ) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
                 'has_directory' => false,
65 65
             )
66 66
         );
67
-	}
68
-
69
-	/**
70
-	 * Set up component navigation.
71
-	 *
72
-	 * @since 2.1.5
73
-	 *
74
-	 * @see BP_Component::setup_nav() for a description of arguments.
75
-	 *
76
-	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
-	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
-	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
-
81
-		// Abort if the integration is inactive.
67
+    }
68
+
69
+    /**
70
+     * Set up component navigation.
71
+     *
72
+     * @since 2.1.5
73
+     *
74
+     * @see BP_Component::setup_nav() for a description of arguments.
75
+     *
76
+     * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77
+     * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78
+     */
79
+    public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
80
+
81
+        // Abort if the integration is inactive.
82 82
         if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
83 83
             return;
84 84
         }
@@ -88,25 +88,25 @@  discard block
 block discarded – undo
88 88
             return;
89 89
         }
90 90
 
91
-		// Determine user to use.
92
-		$user_domain   = bp_loggedin_user_domain();
93
-		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
95
-
96
-		// Add 'Payments' to the main navigation.
97
-		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
-			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
91
+        // Determine user to use.
92
+        $user_domain   = bp_loggedin_user_domain();
93
+        $slug          = 'getpaid';
94
+        $payments_link = trailingslashit( $user_domain . $slug );
95
+
96
+        // Add 'Payments' to the main navigation.
97
+        $main_nav = array(
98
+            'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
99
+            'slug'                    => $slug,
100
+            'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
+            'screen_function'         => array( $this, 'display_current_tab' ),
102
+            'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
103 103
             'show_for_displayed_user' => false,
104
-			'item_css_id'             => $this->id,
105
-			'parent_url'              => $user_domain,
106
-			'parent_slug'             => buddypress()->slug,
107
-		);
104
+            'item_css_id'             => $this->id,
105
+            'parent_url'              => $user_domain,
106
+            'parent_slug'             => buddypress()->slug,
107
+        );
108 108
 
109
-		// Add the subnav items to the payments nav item if we are using a theme that supports this.
109
+        // Add the subnav items to the payments nav item if we are using a theme that supports this.
110 110
         foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
111 111
 
112 112
             $sub_nav[] = array(
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118 118
                 'screen_function'         => function() use ( $tab ) {
119
-					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120
-					$this->display_current_tab();
119
+                    $GLOBALS['getpaid_bp_current_tab'] = $tab;
120
+                    $this->display_current_tab();
121 121
                 },
122 122
                 'show_for_displayed_user' => false,
123 123
                 'item_css_id'             => "getpaid-bp-$_slug",
@@ -125,27 +125,27 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
129
-	}
130
-
131
-	/**
132
-	 * Set up the component entries in the WordPress Admin Bar.
133
-	 *
134
-	 * @since 2.1.5
135
-	 *
136
-	 * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
-	 *      parameter array.
138
-	 *
139
-	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
-	 *                            description.
141
-	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
128
+        parent::setup_nav( $main_nav, $sub_nav );
129
+    }
143 130
 
144
-		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
146
-
147
-			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
131
+    /**
132
+     * Set up the component entries in the WordPress Admin Bar.
133
+     *
134
+     * @since 2.1.5
135
+     *
136
+     * @see BP_Component::setup_nav() for a description of the $wp_admin_nav
137
+     *      parameter array.
138
+     *
139
+     * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140
+     *                            description.
141
+     */
142
+    public function setup_admin_bar( $wp_admin_nav = array() ) {
143
+
144
+        // Menus for logged in user.
145
+        if ( is_user_logged_in() ) {
146
+
147
+            // Setup the logged in user variables.
148
+            $payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
@@ -168,48 +168,48 @@  discard block
 block discarded – undo
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
172
-	}
173
-
174
-	/**
175
-	 * Retrieves the current tab.
176
-	 *
177
-	 * @since 2.1.5
178
-	 */
179
-	public function get_current_tab() {
180
-		global $getpaid_bp_current_tab;
181
-
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
183
-			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
185
-				'content' => '[wpinv_history]',
186
-				'icon'    => 'fas fa-file-invoice',
187
-			);
188
-		}
189
-
190
-		return $getpaid_bp_current_tab;
191
-	}
192
-
193
-	/**
194
-	 * Displays the current tab.
195
-	 *
196
-	 * @since 2.1.5
197
-	 */
198
-	public function display_current_tab() {
199
-
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
171
+        parent::setup_admin_bar( $wp_admin_nav );
172
+    }
173
+
174
+    /**
175
+     * Retrieves the current tab.
176
+     *
177
+     * @since 2.1.5
178
+     */
179
+    public function get_current_tab() {
180
+        global $getpaid_bp_current_tab;
181
+
182
+        if ( empty( $getpaid_bp_current_tab ) ) {
183
+            return array(
184
+                'label'   => __( 'Invoices', 'invoicing' ),
185
+                'content' => '[wpinv_history]',
186
+                'icon'    => 'fas fa-file-invoice',
187
+            );
188
+        }
189
+
190
+        return $getpaid_bp_current_tab;
191
+    }
192
+
193
+    /**
194
+     * Displays the current tab.
195
+     *
196
+     * @since 2.1.5
197
+     */
198
+    public function display_current_tab() {
199
+
200
+        add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
+        $template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
202 202
 
203 203
         bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
204
-	}
205
-
206
-	/**
207
-	 * Handles the actual display of the current tab.
208
-	 *
209
-	 * @since 2.1.5
210
-	 */
211
-	public function handle_display_current_tab() {
212
-		echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
-	}
204
+    }
205
+
206
+    /**
207
+     * Handles the actual display of the current tab.
208
+     *
209
+     * @since 2.1.5
210
+     */
211
+    public function handle_display_current_tab() {
212
+        echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
213
+    }
214 214
 
215 215
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 // Exit if accessed directly.
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * Main GetPaid Class.
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 *     @type array    $meta_tables           Optional. An array of metadata table names.
56 56
 	 * }
57 57
 	 */
58
-	public function setup_globals( $args = array() ) {
58
+	public function setup_globals($args = array()) {
59 59
         parent::setup_globals(
60 60
             array(
61 61
                 'id'            => 'getpaid',
@@ -76,30 +76,30 @@  discard block
 block discarded – undo
76 76
 	 * @param array $main_nav Optional. See BP_Component::setup_nav() for description.
77 77
 	 * @param array $sub_nav  Optional. See BP_Component::setup_nav() for description.
78 78
 	 */
79
-	public function setup_nav( $main_nav = array(), $sub_nav = array() ) {
79
+	public function setup_nav($main_nav = array(), $sub_nav = array()) {
80 80
 
81 81
 		// Abort if the integration is inactive.
82
-        if ( ! getpaid_is_buddypress_integration_active() || ! is_user_logged_in() ) {
82
+        if (!getpaid_is_buddypress_integration_active() || !is_user_logged_in()) {
83 83
             return;
84 84
         }
85 85
 
86 86
         // Or a user is not viewing their profile.
87
-        if ( bp_displayed_user_id() !== bp_loggedin_user_id() ) {
87
+        if (bp_displayed_user_id() !== bp_loggedin_user_id()) {
88 88
             return;
89 89
         }
90 90
 
91 91
 		// Determine user to use.
92 92
 		$user_domain   = bp_loggedin_user_domain();
93 93
 		$slug          = 'getpaid';
94
-		$payments_link = trailingslashit( $user_domain . $slug );
94
+		$payments_link = trailingslashit($user_domain . $slug);
95 95
 
96 96
 		// Add 'Payments' to the main navigation.
97 97
 		$main_nav = array(
98
-			'name'                    => _x( 'Billing', 'BuddyPress profile payments screen nav', 'invoicing' ),
98
+			'name'                    => _x('Billing', 'BuddyPress profile payments screen nav', 'invoicing'),
99 99
 			'slug'                    => $slug,
100
-			'position'                => apply_filters( 'wpinv_bp_nav_position', wpinv_get_option( 'wpinv_menu_position', 91 ), $slug ),
101
-			'screen_function'         => array( $this, 'display_current_tab' ),
102
-			'default_subnav_slug'     => apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
100
+			'position'                => apply_filters('wpinv_bp_nav_position', wpinv_get_option('wpinv_menu_position', 91), $slug),
101
+			'screen_function'         => array($this, 'display_current_tab'),
102
+			'default_subnav_slug'     => apply_filters('getpaid_default_tab', 'gp-edit-address'),
103 103
             'show_for_displayed_user' => false,
104 104
 			'item_css_id'             => $this->id,
105 105
 			'parent_url'              => $user_domain,
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 		);
108 108
 
109 109
 		// Add the subnav items to the payments nav item if we are using a theme that supports this.
110
-        foreach ( getpaid_get_user_content_tabs() as $_slug => $tab ) {
110
+        foreach (getpaid_get_user_content_tabs() as $_slug => $tab) {
111 111
 
112 112
             $sub_nav[] = array(
113 113
                 'name'                    => $tab['label'],
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 'parent_url'              => $payments_link,
116 116
                 'parent_slug'             => $slug,
117 117
                 'position'                => 10,
118
-                'screen_function'         => function() use ( $tab ) {
118
+                'screen_function'         => function() use ($tab) {
119 119
 					$GLOBALS['getpaid_bp_current_tab'] = $tab;
120 120
 					$this->display_current_tab();
121 121
                 },
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
         }
127 127
 
128
-		parent::setup_nav( $main_nav, $sub_nav );
128
+		parent::setup_nav($main_nav, $sub_nav);
129 129
 	}
130 130
 
131 131
 	/**
@@ -139,36 +139,36 @@  discard block
 block discarded – undo
139 139
 	 * @param array $wp_admin_nav See BP_Component::setup_admin_bar() for a
140 140
 	 *                            description.
141 141
 	 */
142
-	public function setup_admin_bar( $wp_admin_nav = array() ) {
142
+	public function setup_admin_bar($wp_admin_nav = array()) {
143 143
 
144 144
 		// Menus for logged in user.
145
-		if ( is_user_logged_in() ) {
145
+		if (is_user_logged_in()) {
146 146
 
147 147
 			// Setup the logged in user variables.
148
-			$payments_link = trailingslashit( bp_loggedin_user_domain() . 'getpaid/' );
148
+			$payments_link = trailingslashit(bp_loggedin_user_domain() . 'getpaid/');
149 149
 
150 150
             // Add the "Payments" sub menu.
151 151
             $wp_admin_nav[] = array(
152 152
                 'parent' => buddypress()->my_account_menu_id,
153 153
                 'id'     => 'my-account-getpaid',
154
-                'title'  => _x( 'Billing', 'BuddyPress my account payments sub nav', 'invoicing' ),
155
-                'href'   => $payments_link . apply_filters( 'getpaid_default_tab', 'gp-edit-address' ),
154
+                'title'  => _x('Billing', 'BuddyPress my account payments sub nav', 'invoicing'),
155
+                'href'   => $payments_link . apply_filters('getpaid_default_tab', 'gp-edit-address'),
156 156
             );
157 157
 
158
-            foreach ( getpaid_get_user_content_tabs() as $slug => $tab ) {
158
+            foreach (getpaid_get_user_content_tabs() as $slug => $tab) {
159 159
 
160 160
                 $wp_admin_nav[] = array(
161 161
                     'parent'   => 'my-account-getpaid',
162 162
                     'id'       => 'my-account-getpaid' . $slug,
163 163
                     'title'    => $tab['label'],
164
-                    'href'     => trailingslashit( $payments_link . $slug ),
164
+                    'href'     => trailingslashit($payments_link . $slug),
165 165
                     'position' => 20,
166 166
                 );
167 167
 
168 168
             }
169 169
 }
170 170
 
171
-		parent::setup_admin_bar( $wp_admin_nav );
171
+		parent::setup_admin_bar($wp_admin_nav);
172 172
 	}
173 173
 
174 174
 	/**
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 	public function get_current_tab() {
180 180
 		global $getpaid_bp_current_tab;
181 181
 
182
-		if ( empty( $getpaid_bp_current_tab ) ) {
182
+		if (empty($getpaid_bp_current_tab)) {
183 183
 			return array(
184
-				'label'   => __( 'Invoices', 'invoicing' ),
184
+				'label'   => __('Invoices', 'invoicing'),
185 185
 				'content' => '[wpinv_history]',
186 186
 				'icon'    => 'fas fa-file-invoice',
187 187
 			);
@@ -197,10 +197,10 @@  discard block
 block discarded – undo
197 197
 	 */
198 198
 	public function display_current_tab() {
199 199
 
200
-		add_action( 'bp_template_content', array( $this, 'handle_display_current_tab' ) );
201
-		$template = apply_filters( 'bp_core_template_plugin', 'members/single/plugins' );
200
+		add_action('bp_template_content', array($this, 'handle_display_current_tab'));
201
+		$template = apply_filters('bp_core_template_plugin', 'members/single/plugins');
202 202
 
203
-        bp_core_load_template( apply_filters( 'wpinv_bp_core_template_plugin', $template ) );
203
+        bp_core_load_template(apply_filters('wpinv_bp_core_template_plugin', $template));
204 204
 	}
205 205
 
206 206
 	/**
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
 	 * @since 2.1.5
210 210
 	 */
211 211
 	public function handle_display_current_tab() {
212
-		echo getpaid_prepare_user_content_tab( $this->get_current_tab() );
212
+		echo getpaid_prepare_user_content_tab($this->get_current_tab());
213 213
 	}
214 214
 
215 215
 }
Please login to merge, or discard this patch.
includes/subscription-functions.php 2 patches
Spacing   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@  discard block
 block discarded – undo
13 13
  * @return      WPInv_Subscription[]|WPInv_Subscription|false
14 14
  * @since       2.3.0
15 15
  */
16
-function getpaid_get_invoice_subscriptions( $invoice ) {
16
+function getpaid_get_invoice_subscriptions($invoice) {
17 17
 
18 18
     // Retrieve subscription groups.
19
-    $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' );
19
+    $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id');
20 20
 
21 21
     // No subscription groups, normal subscription.
22
-    if ( empty( $subscription_ids ) ) {
23
-        return getpaid_subscriptions()->get_invoice_subscription( $invoice );
22
+    if (empty($subscription_ids)) {
23
+        return getpaid_subscriptions()->get_invoice_subscription($invoice);
24 24
     }
25 25
 
26 26
     // Subscription groups.
27
-    return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) );
27
+    return array_filter(array_map('getpaid_get_subscription', $subscription_ids));
28 28
 
29 29
 }
30 30
 
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
  * @return      array
36 36
  * @since       2.3.0
37 37
  */
38
-function getpaid_get_invoice_subscription_groups( $invoice_id ) {
39
-    $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true );
40
-    return empty( $subscription_groups ) ? array() : $subscription_groups;
38
+function getpaid_get_invoice_subscription_groups($invoice_id) {
39
+    $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true);
40
+    return empty($subscription_groups) ? array() : $subscription_groups;
41 41
 }
42 42
 
43 43
 /**
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
  * @return      array|false
49 49
  * @since       2.3.0
50 50
  */
51
-function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52
-    $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54
-    return reset( $matching_group );
51
+function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) {
52
+    $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id);
53
+	$matching_group = wp_list_filter($subscription_groups, compact('subscription_id'));
54
+    return reset($matching_group);
55 55
 }
56 56
 
57 57
 /**
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
  * @since       2.3.0
62 62
  * @return WPInv_Subscription|false
63 63
  */
64
-function getpaid_get_subscription( $subscription ) {
64
+function getpaid_get_subscription($subscription) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
66
+	if (!is_a($subscription, 'WPInv_Subscription')) {
67
+		$subscription = new WPInv_Subscription($subscription);
68 68
 	}
69 69
 
70 70
 	return $subscription->exists() ? $subscription : false;
@@ -79,26 +79,26 @@  discard block
 block discarded – undo
79 79
  *
80 80
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
81 81
  */
82
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
82
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
83 83
 
84 84
 	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
85
+	if ('count' == $return) {
86 86
 		$args['fields'] = 'id';
87 87
 		$args['number'] = 1;
88 88
 	}
89 89
 
90 90
 	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
91
+	if ('results' == $return) {
92 92
 		$args['count_total'] = false;
93 93
 	}
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+	$query = new GetPaid_Subscriptions_Query($args);
96 96
 
97
-	if ( 'results' == $return ) {
97
+	if ('results' == $return) {
98 98
 		return $query->get_results();
99 99
 	}
100 100
 
101
-	if ( 'count' == $return ) {
101
+	if ('count' == $return) {
102 102
 		return $query->get_total();
103 103
 	}
104 104
 
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	return apply_filters(
116 116
 		'getpaid_get_subscription_statuses',
117 117
 		array(
118
-			'pending'   => __( 'Pending', 'invoicing' ),
119
-			'trialling' => __( 'Trialing', 'invoicing' ),
120
-			'active'    => __( 'Active', 'invoicing' ),
121
-			'failing'   => __( 'Failing', 'invoicing' ),
122
-			'expired'   => __( 'Expired', 'invoicing' ),
123
-			'completed' => __( 'Complete', 'invoicing' ),
124
-			'cancelled' => __( 'Cancelled', 'invoicing' ),
118
+			'pending'   => __('Pending', 'invoicing'),
119
+			'trialling' => __('Trialing', 'invoicing'),
120
+			'active'    => __('Active', 'invoicing'),
121
+			'failing'   => __('Failing', 'invoicing'),
122
+			'expired'   => __('Expired', 'invoicing'),
123
+			'completed' => __('Complete', 'invoicing'),
124
+			'cancelled' => __('Cancelled', 'invoicing'),
125 125
 		)
126 126
 	);
127 127
 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @return string
134 134
  */
135
-function getpaid_get_subscription_status_label( $status ) {
135
+function getpaid_get_subscription_status_label($status) {
136 136
 	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
137
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
138 138
 }
139 139
 
140 140
 /**
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
  *
165 165
  * @return array
166 166
  */
167
-function getpaid_get_subscription_status_counts( $args = array() ) {
167
+function getpaid_get_subscription_status_counts($args = array()) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
169
+	$statuses = array_keys(getpaid_get_subscription_statuses());
170 170
 	$counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
172
+	foreach ($statuses as $status) {
173
+		$_args             = wp_parse_args("status=$status", $args);
174
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
175 175
 	}
176 176
 
177 177
 	return $counts;
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
 		array(
191 191
 
192 192
 			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
193
+				'singular' => __('%s day', 'invoicing'),
194
+				'plural'   => __('%d days', 'invoicing'),
195 195
 			),
196 196
 
197 197
 			'week'  => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
198
+				'singular' => __('%s week', 'invoicing'),
199
+				'plural'   => __('%d weeks', 'invoicing'),
200 200
 			),
201 201
 
202 202
 			'month' => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
203
+				'singular' => __('%s month', 'invoicing'),
204
+				'plural'   => __('%d months', 'invoicing'),
205 205
 			),
206 206
 
207 207
 			'year'  => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
208
+				'singular' => __('%s year', 'invoicing'),
209
+				'plural'   => __('%d years', 'invoicing'),
210 210
 			),
211 211
 
212 212
 		)
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
  * @param string $trial_period
221 221
  * @return int
222 222
  */
223
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
223
+function getpaid_get_subscription_trial_period_interval($trial_period) {
224
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
225 225
 }
226 226
 
227 227
 /**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
  * @param string $trial_period
231 231
  * @return string
232 232
  */
233
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
233
+function getpaid_get_subscription_trial_period_period($trial_period) {
234
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
235 235
 }
236 236
 
237 237
 /**
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
  * @param int $interval
242 242
  * @return string
243 243
  */
244
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
244
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
245
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
246
+	return strtolower(sanitize_text_field($label));
247 247
 }
248 248
 
249 249
 /**
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
  * @param string $period
253 253
  * @return string
254 254
  */
255
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
255
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
256 256
 
257 257
 	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
258
+	$period  = strtolower($period);
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
260
+	if (isset($periods[$period])) {
261
+		return sprintf($periods[$period]['singular'], $singular_prefix);
262 262
 	}
263 263
 
264 264
 	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
265
+	foreach ($periods as $key => $data) {
266
+		if (strpos($key, $period) === 0) {
267
+			return sprintf($data['singular'], $singular_prefix);
268 268
 		}
269 269
 	}
270 270
 
@@ -279,19 +279,19 @@  discard block
 block discarded – undo
279 279
  * @param int $interval
280 280
  * @return string
281 281
  */
282
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
282
+function getpaid_get_plural_subscription_period_label($period, $interval) {
283 283
 
284 284
 	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
285
+	$period  = strtolower($period);
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
287
+	if (isset($periods[$period])) {
288
+		return sprintf($periods[$period]['plural'], $interval);
289 289
 	}
290 290
 
291 291
 	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
292
+	foreach ($periods as $key => $data) {
293
+		if (strpos($key, $period) === 0) {
294
+			return sprintf($data['plural'], $interval);
295 295
 		}
296 296
 	}
297 297
 
@@ -305,33 +305,33 @@  discard block
 block discarded – undo
305 305
  * @param WPInv_Subscription $subscription
306 306
  * @return string
307 307
  */
308
-function getpaid_get_formatted_subscription_amount( $subscription ) {
308
+function getpaid_get_formatted_subscription_amount($subscription) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
310
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
311
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
312
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
313 313
 	$bill_times = $subscription->get_bill_times();
314 314
 	$bill_times_less = $bill_times - 1;
315 315
 
316
-	if ( ! empty( $bill_times ) ) {
316
+	if (!empty($bill_times)) {
317 317
 		$bill_times = $subscription->get_frequency() * $bill_times;
318
-		$bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() );
319
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
+		$bill_times_less = getpaid_get_subscription_period_label($subscription->get_frequency(), $bill_times - $subscription->get_frequency());
319
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
320 320
 	}
321 321
 
322 322
 	// Trial periods.
323
-	if ( $subscription->has_trial_period() ) {
323
+	if ($subscription->has_trial_period()) {
324 324
 
325
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
326
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
325
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
326
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
327 327
 
328
-		if ( empty( $bill_times ) ) {
328
+		if (empty($bill_times)) {
329 329
 
330 330
 			return sprintf(
331 331
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
332
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
332
+				_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
333 333
 				$initial,
334
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
335 335
 				$recurring,
336 336
 				$period
337 337
 			);
@@ -340,9 +340,9 @@  discard block
 block discarded – undo
340 340
 
341 341
 		return sprintf(
342 342
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
343
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
343
+			_x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'),
344 344
 			$initial,
345
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
345
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
346 346
 			$recurring,
347 347
 			$period,
348 348
 			$bill_times
@@ -350,13 +350,13 @@  discard block
 block discarded – undo
350 350
 
351 351
 	}
352 352
 
353
-	if ( $initial != $recurring ) {
353
+	if ($initial != $recurring) {
354 354
 
355
-		if ( empty( $bill_times ) ) {
355
+		if (empty($bill_times)) {
356 356
 
357 357
 			return sprintf(
358 358
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
359
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
359
+				_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
360 360
 				$initial,
361 361
 				$recurring,
362 362
 				$period
@@ -366,7 +366,7 @@  discard block
 block discarded – undo
366 366
 
367 367
 		return sprintf(
368 368
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
369
+			_x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'),
370 370
 			$initial,
371 371
 			$recurring,
372 372
 			$period,
@@ -375,11 +375,11 @@  discard block
 block discarded – undo
375 375
 
376 376
 	}
377 377
 
378
-	if ( empty( $bill_times ) ) {
378
+	if (empty($bill_times)) {
379 379
 
380 380
 		return sprintf(
381 381
 			// translators: $1: is the recurring amount, $2: is the recurring period
382
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
382
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
383 383
 			$initial,
384 384
 			$period
385 385
 		);
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
 
389 389
 	return sprintf(
390 390
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
391
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
391
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
392 392
 		$bill_times,
393 393
 		$initial,
394 394
 		$period
@@ -402,8 +402,8 @@  discard block
 block discarded – undo
402 402
  * @param WPInv_Invoice $invoice
403 403
  * @return WPInv_Subscription|false
404 404
  */
405
-function getpaid_get_invoice_subscription( $invoice ) {
406
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
405
+function getpaid_get_invoice_subscription($invoice) {
406
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
407 407
 }
408 408
 
409 409
 /**
@@ -411,9 +411,9 @@  discard block
 block discarded – undo
411 411
  *
412 412
  * @param WPInv_Invoice $invoice
413 413
  */
414
-function getpaid_activate_invoice_subscription( $invoice ) {
415
-	$subscription = getpaid_get_invoice_subscription( $invoice );
416
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
414
+function getpaid_activate_invoice_subscription($invoice) {
415
+	$subscription = getpaid_get_invoice_subscription($invoice);
416
+	if (is_a($subscription, 'WPInv_Subscription')) {
417 417
 		$subscription->activate();
418 418
 	}
419 419
 }
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
  * @return WPInv_Subscriptions
425 425
  */
426 426
 function getpaid_subscriptions() {
427
-	return getpaid()->get( 'subscriptions' );
427
+	return getpaid()->get('subscriptions');
428 428
 }
429 429
 
430 430
 /**
@@ -433,13 +433,13 @@  discard block
 block discarded – undo
433 433
  * @since 2.3.0
434 434
  * @return WPInv_Subscription|bool
435 435
  */
436
-function wpinv_get_invoice_subscription( $invoice ) {
436
+function wpinv_get_invoice_subscription($invoice) {
437 437
 
438 438
     // Retrieve the invoice.
439
-    $invoice = new WPInv_Invoice( $invoice );
439
+    $invoice = new WPInv_Invoice($invoice);
440 440
 
441 441
     // Ensure it is a recurring invoice.
442
-    if ( ! $invoice->is_recurring() ) {
442
+    if (!$invoice->is_recurring()) {
443 443
         return false;
444 444
     }
445 445
 
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
 		)
452 452
 	);
453 453
 
454
-	return empty( $subscription ) ? false : $subscription[0];
454
+	return empty($subscription) ? false : $subscription[0];
455 455
 
456 456
 }
457 457
 
@@ -466,50 +466,50 @@  discard block
 block discarded – undo
466 466
  * @param GetPaid_Form_Item|WPInv_Item $cart_item
467 467
  * @return string
468 468
  */
469
-function getpaid_get_recurring_item_key( $cart_item ) {
469
+function getpaid_get_recurring_item_key($cart_item) {
470 470
 
471 471
 	$cart_key     = 'renews_';
472 472
 	$interval     = $cart_item->get_recurring_interval();
473
-	$period       = $cart_item->get_recurring_period( true );
473
+	$period       = $cart_item->get_recurring_period(true);
474 474
 	$length       = $cart_item->get_recurring_limit() * $interval;
475
-	$trial_period = $cart_item->get_trial_period( true );
475
+	$trial_period = $cart_item->get_trial_period(true);
476 476
 	$trial_length = $cart_item->get_trial_interval();
477 477
 
478 478
 	// First start with the billing interval and period
479
-	switch ( $interval ) {
479
+	switch ($interval) {
480 480
 		case 1:
481
-			if ( 'day' == $period ) {
481
+			if ('day' == $period) {
482 482
 				$cart_key .= 'daily';
483 483
 			} else {
484
-				$cart_key .= sprintf( '%sly', $period );
484
+				$cart_key .= sprintf('%sly', $period);
485 485
 			}
486 486
 			break;
487 487
 		case 2:
488
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
488
+			$cart_key .= sprintf('every_2nd_%s', $period);
489 489
 			break;
490 490
 		case 3:
491
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
491
+			$cart_key .= sprintf('every_3rd_%s', $period);
492 492
 		    break;
493 493
 		default:
494
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
494
+			$cart_key .= sprintf('every_%dth_%s', $interval, $period);
495 495
 			break;
496 496
 	}
497 497
 
498 498
 	// Maybe add the optional maximum billing periods...
499
-	if ( $length > 0 ) {
499
+	if ($length > 0) {
500 500
 		$cart_key .= '_for_';
501
-		$cart_key .= sprintf( '%d_%s', $length, $period );
502
-		if ( $length > 1 ) {
501
+		$cart_key .= sprintf('%d_%s', $length, $period);
502
+		if ($length > 1) {
503 503
 			$cart_key .= 's';
504 504
 		}
505 505
 	}
506 506
 
507 507
 	// And an optional free trial.
508
-	if ( $cart_item->has_free_trial() ) {
509
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
508
+	if ($cart_item->has_free_trial()) {
509
+		$cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period);
510 510
 	}
511 511
 
512
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
512
+	return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item);
513 513
 }
514 514
 
515 515
 /**
@@ -518,14 +518,14 @@  discard block
 block discarded – undo
518 518
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
519 519
  * @return array
520 520
  */
521
-function getpaid_get_subscription_groups( $invoice ) {
521
+function getpaid_get_subscription_groups($invoice) {
522 522
 
523 523
 	// Generate subscription groups.
524 524
 	$subscription_groups = array();
525
-	foreach ( $invoice->get_items() as $item ) {
525
+	foreach ($invoice->get_items() as $item) {
526 526
 
527
-		if ( $item->is_recurring() ) {
528
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
527
+		if ($item->is_recurring()) {
528
+			$subscription_groups[getpaid_get_recurring_item_key($item)][] = $item;
529 529
 		}
530 530
 }
531 531
 
@@ -541,19 +541,19 @@  discard block
 block discarded – undo
541 541
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
542 542
  * @return array
543 543
  */
544
-function getpaid_calculate_subscription_totals( $invoice ) {
544
+function getpaid_calculate_subscription_totals($invoice) {
545 545
 
546 546
 	// Generate subscription groups.
547
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
547
+	$subscription_groups = getpaid_get_subscription_groups($invoice);
548 548
 
549 549
 	// Now let's calculate the totals for each group of subscriptions
550 550
 	$subscription_totals = array();
551 551
 
552
-	foreach ( $subscription_groups as $subscription_key => $items ) {
552
+	foreach ($subscription_groups as $subscription_key => $items) {
553 553
 
554
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
554
+		if (empty($subscription_totals[$subscription_key])) {
555 555
 
556
-			$subscription_totals[ $subscription_key ] = array(
556
+			$subscription_totals[$subscription_key] = array(
557 557
 				'initial_total'   => 0,
558 558
 				'recurring_total' => 0,
559 559
 				'items'           => array(),
@@ -566,33 +566,33 @@  discard block
 block discarded – undo
566 566
 		 * Get the totals of the group.
567 567
 		 * @var GetPaid_Form_Item $item
568 568
 		 */
569
-		foreach ( $items as $item ) {
569
+		foreach ($items as $item) {
570 570
 
571
-			$subscription_totals[ $subscription_key ]['items'][ $item->get_id() ]  = $item->prepare_data_for_saving();
572
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
573
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
574
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
575
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
576
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
577
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
571
+			$subscription_totals[$subscription_key]['items'][$item->get_id()] = $item->prepare_data_for_saving();
572
+			$subscription_totals[$subscription_key]['item_id']                 = $item->get_id();
573
+			$subscription_totals[$subscription_key]['period']                  = $item->get_recurring_period(true);
574
+			$subscription_totals[$subscription_key]['interval']                = $item->get_recurring_interval();
575
+			$subscription_totals[$subscription_key]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
576
+			$subscription_totals[$subscription_key]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
577
+			$subscription_totals[$subscription_key]['recurring_limit']         = $item->get_recurring_limit();
578 578
 
579 579
 			// Calculate the next renewal date.
580
-			$period       = $item->get_recurring_period( true );
580
+			$period       = $item->get_recurring_period(true);
581 581
 			$interval     = $item->get_recurring_interval();
582 582
 
583 583
 			// If the subscription item has a trial period...
584
-			if ( $item->has_free_trial() ) {
585
-				$period   = $item->get_trial_period( true );
584
+			if ($item->has_free_trial()) {
585
+				$period   = $item->get_trial_period(true);
586 586
 				$interval = $item->get_trial_interval();
587
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
587
+				$subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period;
588 588
 			}
589 589
 
590
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
590
+			$subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp')));
591 591
 
592 592
 		}
593 593
 }
594 594
 
595
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
595
+	return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice);
596 596
 }
597 597
 
598 598
 /**
@@ -601,18 +601,18 @@  discard block
 block discarded – undo
601 601
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
602 602
  * @return array
603 603
  */
604
-function getpaid_should_group_subscriptions( $invoice ) {
604
+function getpaid_should_group_subscriptions($invoice) {
605 605
 
606 606
 	$recurring_items = 0;
607 607
 
608
-	foreach ( $invoice->get_items() as $item ) {
608
+	foreach ($invoice->get_items() as $item) {
609 609
 
610
-		if ( $item->is_recurring() ) {
611
-			$recurring_items ++;
610
+		if ($item->is_recurring()) {
611
+			$recurring_items++;
612 612
 		}
613 613
 }
614 614
 
615
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
615
+	return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice);
616 616
 }
617 617
 
618 618
 /**
@@ -622,12 +622,12 @@  discard block
 block discarded – undo
622 622
  * @param int|false $subscription_id
623 623
  * @return int
624 624
  */
625
-function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
625
+function getpaid_count_subscription_invoices($parent_invoice_id, $subscription_id = false) {
626 626
 	global $wpdb;
627 627
 
628 628
 	$parent_invoice_id = (int) $parent_invoice_id;
629 629
 
630
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
630
+	if (false === $subscription_id || !(bool) get_post_meta($parent_invoice_id, '_wpinv_subscription_id', true)) {
631 631
 
632 632
 		return (int) $wpdb->get_var(
633 633
 			$wpdb->prepare(
@@ -649,10 +649,10 @@  discard block
 block discarded – undo
649 649
 
650 650
 	$count = 0;
651 651
 
652
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
652
+	foreach (wp_parse_id_list($invoice_ids) as $invoice_id) {
653 653
 
654
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
655
-			$count ++;
654
+		if ($invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta($invoice_id, '_wpinv_subscription_id', true)) {
655
+			$count++;
656 656
 			continue;
657 657
 		}
658 658
 }
Please login to merge, or discard this patch.
Indentation   +323 added lines, -323 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  */
51 51
 function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52 52
     $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
53
+    $matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54 54
     return reset( $matching_group );
55 55
 }
56 56
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
  */
64 64
 function getpaid_get_subscription( $subscription ) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
68
-	}
66
+    if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
+        $subscription = new WPInv_Subscription( $subscription );
68
+    }
69 69
 
70
-	return $subscription->exists() ? $subscription : false;
70
+    return $subscription->exists() ? $subscription : false;
71 71
 }
72 72
 
73 73
 /**
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
83 83
 
84
-	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
86
-		$args['fields'] = 'id';
87
-		$args['number'] = 1;
88
-	}
84
+    // Do not retrieve all fields if we just want the count.
85
+    if ( 'count' == $return ) {
86
+        $args['fields'] = 'id';
87
+        $args['number'] = 1;
88
+    }
89 89
 
90
-	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
92
-		$args['count_total'] = false;
93
-	}
90
+    // Do not count all matches if we just want the results.
91
+    if ( 'results' == $return ) {
92
+        $args['count_total'] = false;
93
+    }
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+    $query = new GetPaid_Subscriptions_Query( $args );
96 96
 
97
-	if ( 'results' == $return ) {
98
-		return $query->get_results();
99
-	}
97
+    if ( 'results' == $return ) {
98
+        return $query->get_results();
99
+    }
100 100
 
101
-	if ( 'count' == $return ) {
102
-		return $query->get_total();
103
-	}
101
+    if ( 'count' == $return ) {
102
+        return $query->get_total();
103
+    }
104 104
 
105
-	return $query;
105
+    return $query;
106 106
 }
107 107
 
108 108
 /**
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function getpaid_get_subscription_statuses() {
114 114
 
115
-	return apply_filters(
116
-		'getpaid_get_subscription_statuses',
117
-		array(
118
-			'pending'   => __( 'Pending', 'invoicing' ),
119
-			'trialling' => __( 'Trialing', 'invoicing' ),
120
-			'active'    => __( 'Active', 'invoicing' ),
121
-			'failing'   => __( 'Failing', 'invoicing' ),
122
-			'expired'   => __( 'Expired', 'invoicing' ),
123
-			'completed' => __( 'Complete', 'invoicing' ),
124
-			'cancelled' => __( 'Cancelled', 'invoicing' ),
125
-		)
126
-	);
115
+    return apply_filters(
116
+        'getpaid_get_subscription_statuses',
117
+        array(
118
+            'pending'   => __( 'Pending', 'invoicing' ),
119
+            'trialling' => __( 'Trialing', 'invoicing' ),
120
+            'active'    => __( 'Active', 'invoicing' ),
121
+            'failing'   => __( 'Failing', 'invoicing' ),
122
+            'expired'   => __( 'Expired', 'invoicing' ),
123
+            'completed' => __( 'Complete', 'invoicing' ),
124
+            'cancelled' => __( 'Cancelled', 'invoicing' ),
125
+        )
126
+    );
127 127
 
128 128
 }
129 129
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function getpaid_get_subscription_status_label( $status ) {
136
-	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
136
+    $statuses = getpaid_get_subscription_statuses();
137
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
138 138
 }
139 139
 
140 140
 /**
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
  */
145 145
 function getpaid_get_subscription_status_classes() {
146 146
 
147
-	return apply_filters(
148
-		'getpaid_get_subscription_status_classes',
149
-		array(
150
-			'pending'   => 'bg-dark',
151
-			'trialling' => 'bg-info',
152
-			'active'    => 'bg-success',
153
-			'failing'   => 'bg-warning text-dark',
154
-			'expired'   => 'bg-danger',
155
-			'completed' => 'bg-primary',
156
-			'cancelled' => 'bg-secondary',
157
-		)
158
-	);
147
+    return apply_filters(
148
+        'getpaid_get_subscription_status_classes',
149
+        array(
150
+            'pending'   => 'bg-dark',
151
+            'trialling' => 'bg-info',
152
+            'active'    => 'bg-success',
153
+            'failing'   => 'bg-warning text-dark',
154
+            'expired'   => 'bg-danger',
155
+            'completed' => 'bg-primary',
156
+            'cancelled' => 'bg-secondary',
157
+        )
158
+    );
159 159
 
160 160
 }
161 161
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function getpaid_get_subscription_status_counts( $args = array() ) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
170
-	$counts   = array();
169
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
170
+    $counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
-	}
172
+    foreach ( $statuses as $status ) {
173
+        $_args             = wp_parse_args( "status=$status", $args );
174
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
+    }
176 176
 
177
-	return $counts;
177
+    return $counts;
178 178
 
179 179
 }
180 180
 
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function getpaid_get_subscription_periods() {
187 187
 
188
-	return apply_filters(
189
-		'getpaid_get_subscription_periods',
190
-		array(
188
+    return apply_filters(
189
+        'getpaid_get_subscription_periods',
190
+        array(
191 191
 
192
-			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
195
-			),
192
+            'day'   => array(
193
+                'singular' => __( '%s day', 'invoicing' ),
194
+                'plural'   => __( '%d days', 'invoicing' ),
195
+            ),
196 196
 
197
-			'week'  => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
200
-			),
197
+            'week'  => array(
198
+                'singular' => __( '%s week', 'invoicing' ),
199
+                'plural'   => __( '%d weeks', 'invoicing' ),
200
+            ),
201 201
 
202
-			'month' => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
205
-			),
202
+            'month' => array(
203
+                'singular' => __( '%s month', 'invoicing' ),
204
+                'plural'   => __( '%d months', 'invoicing' ),
205
+            ),
206 206
 
207
-			'year'  => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
210
-			),
207
+            'year'  => array(
208
+                'singular' => __( '%s year', 'invoicing' ),
209
+                'plural'   => __( '%d years', 'invoicing' ),
210
+            ),
211 211
 
212
-		)
213
-	);
212
+        )
213
+    );
214 214
 
215 215
 }
216 216
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
  * @return int
222 222
  */
223 223
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
224
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
225 225
 }
226 226
 
227 227
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
  * @return string
232 232
  */
233 233
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
234
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
235 235
 }
236 236
 
237 237
 /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
  * @return string
243 243
  */
244 244
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
245
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
+    return strtolower( sanitize_text_field( $label ) );
247 247
 }
248 248
 
249 249
 /**
@@ -254,22 +254,22 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
256 256
 
257
-	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
257
+    $periods = getpaid_get_subscription_periods();
258
+    $period  = strtolower( $period );
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
-	}
260
+    if ( isset( $periods[ $period ] ) ) {
261
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
+    }
263 263
 
264
-	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
268
-		}
269
-	}
264
+    // Backwards compatibility.
265
+    foreach ( $periods as $key => $data ) {
266
+        if ( strpos( $key, $period ) === 0 ) {
267
+            return sprintf( $data['singular'], $singular_prefix );
268
+        }
269
+    }
270 270
 
271
-	// Invalid string.
272
-	return '';
271
+    // Invalid string.
272
+    return '';
273 273
 }
274 274
 
275 275
 /**
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
283 283
 
284
-	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
284
+    $periods = getpaid_get_subscription_periods();
285
+    $period  = strtolower( $period );
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
289
-	}
287
+    if ( isset( $periods[ $period ] ) ) {
288
+        return sprintf( $periods[ $period ]['plural'], $interval );
289
+    }
290 290
 
291
-	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
295
-		}
296
-	}
291
+    // Backwards compatibility.
292
+    foreach ( $periods as $key => $data ) {
293
+        if ( strpos( $key, $period ) === 0 ) {
294
+            return sprintf( $data['plural'], $interval );
295
+        }
296
+    }
297 297
 
298
-	// Invalid string.
299
-	return '';
298
+    // Invalid string.
299
+    return '';
300 300
 }
301 301
 
302 302
 /**
@@ -307,92 +307,92 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function getpaid_get_formatted_subscription_amount( $subscription ) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
-	$bill_times = $subscription->get_bill_times();
314
-	$bill_times_less = $bill_times - 1;
315
-
316
-	if ( ! empty( $bill_times ) ) {
317
-		$bill_times = $subscription->get_frequency() * $bill_times;
318
-		$bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() );
319
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
320
-	}
321
-
322
-	// Trial periods.
323
-	if ( $subscription->has_trial_period() ) {
324
-
325
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
326
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
327
-
328
-		if ( empty( $bill_times ) ) {
329
-
330
-			return sprintf(
331
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
332
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
333
-				$initial,
334
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
335
-				$recurring,
336
-				$period
337
-			);
338
-
339
-		}
340
-
341
-		return sprintf(
342
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
343
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
344
-			$initial,
345
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
-			$recurring,
347
-			$period,
348
-			$bill_times
349
-		);
350
-
351
-	}
352
-
353
-	if ( $initial != $recurring ) {
354
-
355
-		if ( empty( $bill_times ) ) {
356
-
357
-			return sprintf(
358
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
359
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
360
-				$initial,
361
-				$recurring,
362
-				$period
363
-			);
364
-
365
-		}
366
-
367
-		return sprintf(
368
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
370
-			$initial,
371
-			$recurring,
372
-			$period,
373
-			$bill_times_less
374
-		);
375
-
376
-	}
377
-
378
-	if ( empty( $bill_times ) ) {
379
-
380
-		return sprintf(
381
-			// translators: $1: is the recurring amount, $2: is the recurring period
382
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
383
-			$initial,
384
-			$period
385
-		);
386
-
387
-	}
388
-
389
-	return sprintf(
390
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
391
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
392
-		$bill_times,
393
-		$initial,
394
-		$period
395
-	);
310
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
+    $bill_times = $subscription->get_bill_times();
314
+    $bill_times_less = $bill_times - 1;
315
+
316
+    if ( ! empty( $bill_times ) ) {
317
+        $bill_times = $subscription->get_frequency() * $bill_times;
318
+        $bill_times_less = getpaid_get_subscription_period_label( $subscription->get_frequency(), $bill_times - $subscription->get_frequency() );
319
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
320
+    }
321
+
322
+    // Trial periods.
323
+    if ( $subscription->has_trial_period() ) {
324
+
325
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
326
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
327
+
328
+        if ( empty( $bill_times ) ) {
329
+
330
+            return sprintf(
331
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
332
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
333
+                $initial,
334
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
335
+                $recurring,
336
+                $period
337
+            );
338
+
339
+        }
340
+
341
+        return sprintf(
342
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
343
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
344
+            $initial,
345
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
+            $recurring,
347
+            $period,
348
+            $bill_times
349
+        );
350
+
351
+    }
352
+
353
+    if ( $initial != $recurring ) {
354
+
355
+        if ( empty( $bill_times ) ) {
356
+
357
+            return sprintf(
358
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
359
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
360
+                $initial,
361
+                $recurring,
362
+                $period
363
+            );
364
+
365
+        }
366
+
367
+        return sprintf(
368
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
369
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
370
+            $initial,
371
+            $recurring,
372
+            $period,
373
+            $bill_times_less
374
+        );
375
+
376
+    }
377
+
378
+    if ( empty( $bill_times ) ) {
379
+
380
+        return sprintf(
381
+            // translators: $1: is the recurring amount, $2: is the recurring period
382
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
383
+            $initial,
384
+            $period
385
+        );
386
+
387
+    }
388
+
389
+    return sprintf(
390
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
391
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
392
+        $bill_times,
393
+        $initial,
394
+        $period
395
+    );
396 396
 
397 397
 }
398 398
 
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
  * @return WPInv_Subscription|false
404 404
  */
405 405
 function getpaid_get_invoice_subscription( $invoice ) {
406
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
406
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
407 407
 }
408 408
 
409 409
 /**
@@ -412,10 +412,10 @@  discard block
 block discarded – undo
412 412
  * @param WPInv_Invoice $invoice
413 413
  */
414 414
 function getpaid_activate_invoice_subscription( $invoice ) {
415
-	$subscription = getpaid_get_invoice_subscription( $invoice );
416
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
417
-		$subscription->activate();
418
-	}
415
+    $subscription = getpaid_get_invoice_subscription( $invoice );
416
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
417
+        $subscription->activate();
418
+    }
419 419
 }
420 420
 
421 421
 /**
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
  * @return WPInv_Subscriptions
425 425
  */
426 426
 function getpaid_subscriptions() {
427
-	return getpaid()->get( 'subscriptions' );
427
+    return getpaid()->get( 'subscriptions' );
428 428
 }
429 429
 
430 430
 /**
@@ -443,15 +443,15 @@  discard block
 block discarded – undo
443 443
         return false;
444 444
     }
445 445
 
446
-	// Fetch the invoice subscription.
447
-	$subscription = getpaid_get_subscriptions(
448
-		array(
449
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
450
-			'number'     => 1,
451
-		)
452
-	);
446
+    // Fetch the invoice subscription.
447
+    $subscription = getpaid_get_subscriptions(
448
+        array(
449
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
450
+            'number'     => 1,
451
+        )
452
+    );
453 453
 
454
-	return empty( $subscription ) ? false : $subscription[0];
454
+    return empty( $subscription ) ? false : $subscription[0];
455 455
 
456 456
 }
457 457
 
@@ -468,48 +468,48 @@  discard block
 block discarded – undo
468 468
  */
469 469
 function getpaid_get_recurring_item_key( $cart_item ) {
470 470
 
471
-	$cart_key     = 'renews_';
472
-	$interval     = $cart_item->get_recurring_interval();
473
-	$period       = $cart_item->get_recurring_period( true );
474
-	$length       = $cart_item->get_recurring_limit() * $interval;
475
-	$trial_period = $cart_item->get_trial_period( true );
476
-	$trial_length = $cart_item->get_trial_interval();
477
-
478
-	// First start with the billing interval and period
479
-	switch ( $interval ) {
480
-		case 1:
481
-			if ( 'day' == $period ) {
482
-				$cart_key .= 'daily';
483
-			} else {
484
-				$cart_key .= sprintf( '%sly', $period );
485
-			}
486
-			break;
487
-		case 2:
488
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
489
-			break;
490
-		case 3:
491
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
492
-		    break;
493
-		default:
494
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
495
-			break;
496
-	}
497
-
498
-	// Maybe add the optional maximum billing periods...
499
-	if ( $length > 0 ) {
500
-		$cart_key .= '_for_';
501
-		$cart_key .= sprintf( '%d_%s', $length, $period );
502
-		if ( $length > 1 ) {
503
-			$cart_key .= 's';
504
-		}
505
-	}
506
-
507
-	// And an optional free trial.
508
-	if ( $cart_item->has_free_trial() ) {
509
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
510
-	}
511
-
512
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
471
+    $cart_key     = 'renews_';
472
+    $interval     = $cart_item->get_recurring_interval();
473
+    $period       = $cart_item->get_recurring_period( true );
474
+    $length       = $cart_item->get_recurring_limit() * $interval;
475
+    $trial_period = $cart_item->get_trial_period( true );
476
+    $trial_length = $cart_item->get_trial_interval();
477
+
478
+    // First start with the billing interval and period
479
+    switch ( $interval ) {
480
+        case 1:
481
+            if ( 'day' == $period ) {
482
+                $cart_key .= 'daily';
483
+            } else {
484
+                $cart_key .= sprintf( '%sly', $period );
485
+            }
486
+            break;
487
+        case 2:
488
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
489
+            break;
490
+        case 3:
491
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
492
+            break;
493
+        default:
494
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
495
+            break;
496
+    }
497
+
498
+    // Maybe add the optional maximum billing periods...
499
+    if ( $length > 0 ) {
500
+        $cart_key .= '_for_';
501
+        $cart_key .= sprintf( '%d_%s', $length, $period );
502
+        if ( $length > 1 ) {
503
+            $cart_key .= 's';
504
+        }
505
+    }
506
+
507
+    // And an optional free trial.
508
+    if ( $cart_item->has_free_trial() ) {
509
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
510
+    }
511
+
512
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
513 513
 }
514 514
 
515 515
 /**
@@ -520,16 +520,16 @@  discard block
 block discarded – undo
520 520
  */
521 521
 function getpaid_get_subscription_groups( $invoice ) {
522 522
 
523
-	// Generate subscription groups.
524
-	$subscription_groups = array();
525
-	foreach ( $invoice->get_items() as $item ) {
523
+    // Generate subscription groups.
524
+    $subscription_groups = array();
525
+    foreach ( $invoice->get_items() as $item ) {
526 526
 
527
-		if ( $item->is_recurring() ) {
528
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
529
-		}
527
+        if ( $item->is_recurring() ) {
528
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
529
+        }
530 530
 }
531 531
 
532
-	return $subscription_groups;
532
+    return $subscription_groups;
533 533
 }
534 534
 
535 535
 /**
@@ -543,56 +543,56 @@  discard block
 block discarded – undo
543 543
  */
544 544
 function getpaid_calculate_subscription_totals( $invoice ) {
545 545
 
546
-	// Generate subscription groups.
547
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
546
+    // Generate subscription groups.
547
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
548 548
 
549
-	// Now let's calculate the totals for each group of subscriptions
550
-	$subscription_totals = array();
549
+    // Now let's calculate the totals for each group of subscriptions
550
+    $subscription_totals = array();
551 551
 
552
-	foreach ( $subscription_groups as $subscription_key => $items ) {
552
+    foreach ( $subscription_groups as $subscription_key => $items ) {
553 553
 
554
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
554
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
555 555
 
556
-			$subscription_totals[ $subscription_key ] = array(
557
-				'initial_total'   => 0,
558
-				'recurring_total' => 0,
559
-				'items'           => array(),
560
-				'trialling'       => false,
561
-			);
556
+            $subscription_totals[ $subscription_key ] = array(
557
+                'initial_total'   => 0,
558
+                'recurring_total' => 0,
559
+                'items'           => array(),
560
+                'trialling'       => false,
561
+            );
562 562
 
563
-		}
563
+        }
564 564
 
565
-		/**
566
-		 * Get the totals of the group.
567
-		 * @var GetPaid_Form_Item $item
568
-		 */
569
-		foreach ( $items as $item ) {
565
+        /**
566
+         * Get the totals of the group.
567
+         * @var GetPaid_Form_Item $item
568
+         */
569
+        foreach ( $items as $item ) {
570 570
 
571
-			$subscription_totals[ $subscription_key ]['items'][ $item->get_id() ]  = $item->prepare_data_for_saving();
572
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
573
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
574
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
575
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
576
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
577
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
571
+            $subscription_totals[ $subscription_key ]['items'][ $item->get_id() ]  = $item->prepare_data_for_saving();
572
+            $subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
573
+            $subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
574
+            $subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
575
+            $subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
576
+            $subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
577
+            $subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
578 578
 
579
-			// Calculate the next renewal date.
580
-			$period       = $item->get_recurring_period( true );
581
-			$interval     = $item->get_recurring_interval();
579
+            // Calculate the next renewal date.
580
+            $period       = $item->get_recurring_period( true );
581
+            $interval     = $item->get_recurring_interval();
582 582
 
583
-			// If the subscription item has a trial period...
584
-			if ( $item->has_free_trial() ) {
585
-				$period   = $item->get_trial_period( true );
586
-				$interval = $item->get_trial_interval();
587
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
588
-			}
583
+            // If the subscription item has a trial period...
584
+            if ( $item->has_free_trial() ) {
585
+                $period   = $item->get_trial_period( true );
586
+                $interval = $item->get_trial_interval();
587
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
588
+            }
589 589
 
590
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
590
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
591 591
 
592
-		}
592
+        }
593 593
 }
594 594
 
595
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
595
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
596 596
 }
597 597
 
598 598
 /**
@@ -603,16 +603,16 @@  discard block
 block discarded – undo
603 603
  */
604 604
 function getpaid_should_group_subscriptions( $invoice ) {
605 605
 
606
-	$recurring_items = 0;
606
+    $recurring_items = 0;
607 607
 
608
-	foreach ( $invoice->get_items() as $item ) {
608
+    foreach ( $invoice->get_items() as $item ) {
609 609
 
610
-		if ( $item->is_recurring() ) {
611
-			$recurring_items ++;
612
-		}
610
+        if ( $item->is_recurring() ) {
611
+            $recurring_items ++;
612
+        }
613 613
 }
614 614
 
615
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
615
+    return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
616 616
 }
617 617
 
618 618
 /**
@@ -623,39 +623,39 @@  discard block
 block discarded – undo
623 623
  * @return int
624 624
  */
625 625
 function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
626
-	global $wpdb;
626
+    global $wpdb;
627 627
 
628
-	$parent_invoice_id = (int) $parent_invoice_id;
628
+    $parent_invoice_id = (int) $parent_invoice_id;
629 629
 
630
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
630
+    if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
631 631
 
632
-		return (int) $wpdb->get_var(
633
-			$wpdb->prepare(
634
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
635
-				$parent_invoice_id,
636
-				$parent_invoice_id
637
-			)
638
-		);
632
+        return (int) $wpdb->get_var(
633
+            $wpdb->prepare(
634
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
635
+                $parent_invoice_id,
636
+                $parent_invoice_id
637
+            )
638
+        );
639 639
 
640
-	}
640
+    }
641 641
 
642
-	$invoice_ids = $wpdb->get_col(
643
-		$wpdb->prepare(
644
-			"SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
645
-			$parent_invoice_id,
646
-			$parent_invoice_id
647
-		)
648
-	);
642
+    $invoice_ids = $wpdb->get_col(
643
+        $wpdb->prepare(
644
+            "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
645
+            $parent_invoice_id,
646
+            $parent_invoice_id
647
+        )
648
+    );
649 649
 
650
-	$count = 0;
650
+    $count = 0;
651 651
 
652
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
652
+    foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
653 653
 
654
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
655
-			$count ++;
656
-			continue;
657
-		}
654
+        if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
655
+            $count ++;
656
+            continue;
657
+        }
658 658
 }
659 659
 
660
-	return $count;
660
+    return $count;
661 661
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
62
-			'page'       => 1,
63
-			'exclude'    => array(),
64
-			'orderby'    => 'date',
65
-			'order'      => 'DESC',
66
-			'type'       => wpinv_item_types(),
67
-			'meta_query' => array(),
68
-			'return'     => 'objects',
69
-			'paginate'   => false,
60
+            'status'     => array( 'publish' ),
61
+            'limit'      => get_option( 'posts_per_page' ),
62
+            'page'       => 1,
63
+            'exclude'    => array(),
64
+            'orderby'    => 'date',
65
+            'order'      => 'DESC',
66
+            'type'       => wpinv_item_types(),
67
+            'meta_query' => array(),
68
+            'return'     => 'objects',
69
+            'paginate'   => false,
70 70
         )
71 71
     );
72 72
 
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
 
207 207
 function wpinv_get_item_types() {
208 208
     $item_types = array(
209
-		'custom' => __( 'Standard', 'invoicing' ),
210
-		'fee'    => __( 'Fee', 'invoicing' ),
211
-	);
209
+        'custom' => __( 'Standard', 'invoicing' ),
210
+        'fee'    => __( 'Fee', 'invoicing' ),
211
+    );
212 212
     return apply_filters( 'wpinv_get_item_types', $item_types );
213 213
 }
214 214
 
@@ -249,17 +249,17 @@  discard block
 block discarded – undo
249 249
 function wpinv_get_random_items( $num = 3, $post_ids = true ) {
250 250
     if ( $post_ids ) {
251 251
         $args = array(
252
-			'post_type'  => 'wpi_item',
253
-			'orderby'    => 'rand',
254
-			'post_count' => $num,
255
-			'fields'     => 'ids',
256
-		);
252
+            'post_type'  => 'wpi_item',
253
+            'orderby'    => 'rand',
254
+            'post_count' => $num,
255
+            'fields'     => 'ids',
256
+        );
257 257
     } else {
258 258
         $args = array(
259
-			'post_type'  => 'wpi_item',
260
-			'orderby'    => 'rand',
261
-			'post_count' => $num,
262
-		);
259
+            'post_type'  => 'wpi_item',
260
+            'orderby'    => 'rand',
261
+            'post_count' => $num,
262
+        );
263 263
     }
264 264
 
265 265
     $args  = apply_filters( 'wpinv_get_random_items', $args );
@@ -427,10 +427,10 @@  discard block
 block discarded – undo
427 427
     $bill_times_less = $bill_times - 1;
428 428
 
429 429
     if ( ! empty( $bill_times ) ) {
430
-		$bill_times = $item->get_recurring_interval() * $bill_times;
430
+        $bill_times = $item->get_recurring_interval() * $bill_times;
431 431
         $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
432
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
433
-	}
432
+        $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
433
+    }
434 434
 
435 435
     if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
436 436
         $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
Please login to merge, or discard this patch.
Spacing   +131 added lines, -131 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  *
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' === strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $value );
29
+    if ('id' === strtolower($field)) {
30
+        return wpinv_get_item_by_id($value);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return empty( $id ) ? false : wpinv_get_item( $id );
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return empty($id) ? false : wpinv_get_item($id);
35 35
 
36 36
 }
37 37
 
@@ -41,24 +41,24 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
 
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->exists() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57 57
     $args = wp_parse_args(
58 58
         $args,
59 59
         array(
60
-			'status'     => array( 'publish' ),
61
-			'limit'      => get_option( 'posts_per_page' ),
60
+			'status'     => array('publish'),
61
+			'limit'      => get_option('posts_per_page'),
62 62
 			'page'       => 1,
63 63
 			'exclude'    => array(),
64 64
 			'orderby'    => 'date',
@@ -78,44 +78,44 @@  discard block
 block discarded – undo
78 78
         'fields'         => 'ids',
79 79
         'orderby'        => $args['orderby'],
80 80
         'order'          => $args['order'],
81
-        'paged'          => absint( $args['page'] ),
81
+        'paged'          => absint($args['page']),
82 82
     );
83 83
 
84
-    if ( ! empty( $args['exclude'] ) ) {
85
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
84
+    if (!empty($args['exclude'])) {
85
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
86 86
     }
87 87
 
88
-    if ( ! $args['paginate'] ) {
88
+    if (!$args['paginate']) {
89 89
         $wp_query_args['no_found_rows'] = true;
90 90
     }
91 91
 
92
-    if ( ! empty( $args['search'] ) ) {
92
+    if (!empty($args['search'])) {
93 93
         $wp_query_args['s'] = $args['search'];
94 94
     }
95 95
 
96
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
97
-        $types = wpinv_parse_list( $args['type'] );
96
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
97
+        $types = wpinv_parse_list($args['type']);
98 98
         $wp_query_args['meta_query'][] = array(
99 99
             'key'     => '_wpinv_type',
100
-            'value'   => implode( ',', $types ),
100
+            'value'   => implode(',', $types),
101 101
             'compare' => 'IN',
102 102
         );
103 103
     }
104 104
 
105
-    $wp_query_args = apply_filters( 'wpinv_get_items_args', $wp_query_args, $args );
105
+    $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
106 106
 
107 107
     // Get results.
108
-    $items = new WP_Query( $wp_query_args );
108
+    $items = new WP_Query($wp_query_args);
109 109
 
110
-    if ( 'objects' === $args['return'] ) {
111
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
112
-    } elseif ( 'self' === $args['return'] ) {
110
+    if ('objects' === $args['return']) {
111
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
112
+    } elseif ('self' === $args['return']) {
113 113
         return $items;
114 114
     } else {
115 115
         $return = $items->posts;
116 116
     }
117 117
 
118
-    if ( $args['paginate'] ) {
118
+    if ($args['paginate']) {
119 119
         return (object) array(
120 120
             'items'         => $return,
121 121
             'total'         => $items->found_posts,
@@ -127,12 +127,12 @@  discard block
 block discarded – undo
127 127
 
128 128
 }
129 129
 
130
-function wpinv_is_free_item( $item_id = 0 ) {
131
-    if ( empty( $item_id ) ) {
130
+function wpinv_is_free_item($item_id = 0) {
131
+    if (empty($item_id)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    $item = new WPInv_Item( $item_id );
135
+    $item = new WPInv_Item($item_id);
136 136
 
137 137
     return $item->is_free();
138 138
 }
@@ -142,21 +142,21 @@  discard block
 block discarded – undo
142 142
  *
143 143
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
144 144
  */
145
-function wpinv_item_is_editable( $item = 0 ) {
145
+function wpinv_item_is_editable($item = 0) {
146 146
 
147 147
     // Fetch the item.
148
-    $item = new WPInv_Item( $item );
148
+    $item = new WPInv_Item($item);
149 149
 
150 150
     // Check if it is editable.
151 151
     return $item->is_editable();
152 152
 }
153 153
 
154
-function wpinv_get_item_price( $item_id = 0 ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_get_item_price($item_id = 0) {
155
+    if (empty($item_id)) {
156 156
         return false;
157 157
     }
158 158
 
159
-    $item = new WPInv_Item( $item_id );
159
+    $item = new WPInv_Item($item_id);
160 160
 
161 161
     return $item->get_price();
162 162
 }
@@ -166,88 +166,88 @@  discard block
 block discarded – undo
166 166
  *
167 167
  * @param WPInv_Item|int $item
168 168
  */
169
-function wpinv_is_recurring_item( $item = 0 ) {
170
-    $item = new WPInv_Item( $item );
169
+function wpinv_is_recurring_item($item = 0) {
170
+    $item = new WPInv_Item($item);
171 171
     return $item->is_recurring();
172 172
 }
173 173
 
174
-function wpinv_item_price( $item_id = 0 ) {
175
-    if ( empty( $item_id ) ) {
174
+function wpinv_item_price($item_id = 0) {
175
+    if (empty($item_id)) {
176 176
         return false;
177 177
     }
178 178
 
179
-    $price = wpinv_get_item_price( $item_id );
180
-    $price = wpinv_price( $price );
179
+    $price = wpinv_get_item_price($item_id);
180
+    $price = wpinv_price($price);
181 181
 
182
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
182
+    return apply_filters('wpinv_item_price', $price, $item_id);
183 183
 }
184 184
 
185
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
186
-    if ( is_null( $amount_override ) ) {
187
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
185
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
186
+    if (is_null($amount_override)) {
187
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
188 188
     } else {
189 189
         $original_price = $amount_override;
190 190
     }
191 191
 
192 192
     $price = $original_price;
193 193
 
194
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
194
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
195 195
 }
196 196
 
197
-function wpinv_item_custom_singular_name( $item_id ) {
198
-    if ( empty( $item_id ) ) {
197
+function wpinv_item_custom_singular_name($item_id) {
198
+    if (empty($item_id)) {
199 199
         return false;
200 200
     }
201 201
 
202
-    $item = new WPInv_Item( $item_id );
202
+    $item = new WPInv_Item($item_id);
203 203
 
204 204
     return $item->get_custom_singular_name();
205 205
 }
206 206
 
207 207
 function wpinv_get_item_types() {
208 208
     $item_types = array(
209
-		'custom' => __( 'Standard', 'invoicing' ),
210
-		'fee'    => __( 'Fee', 'invoicing' ),
209
+		'custom' => __('Standard', 'invoicing'),
210
+		'fee'    => __('Fee', 'invoicing'),
211 211
 	);
212
-    return apply_filters( 'wpinv_get_item_types', $item_types );
212
+    return apply_filters('wpinv_get_item_types', $item_types);
213 213
 }
214 214
 
215 215
 function wpinv_item_types() {
216 216
     $item_types = wpinv_get_item_types();
217 217
 
218
-    return ( ! empty( $item_types ) ? array_keys( $item_types ) : array() );
218
+    return (!empty($item_types) ? array_keys($item_types) : array());
219 219
 }
220 220
 
221
-function wpinv_get_item_type( $item_id ) {
222
-    if ( empty( $item_id ) ) {
221
+function wpinv_get_item_type($item_id) {
222
+    if (empty($item_id)) {
223 223
         return false;
224 224
     }
225 225
 
226
-    $item = new WPInv_Item( $item_id );
226
+    $item = new WPInv_Item($item_id);
227 227
 
228 228
     return $item->get_type();
229 229
 }
230 230
 
231
-function wpinv_item_type( $item_id ) {
231
+function wpinv_item_type($item_id) {
232 232
     $item_types = wpinv_get_item_types();
233 233
 
234
-    $item_type = wpinv_get_item_type( $item_id );
234
+    $item_type = wpinv_get_item_type($item_id);
235 235
 
236
-    if ( empty( $item_type ) ) {
236
+    if (empty($item_type)) {
237 237
         $item_type = '-';
238 238
     }
239 239
 
240
-    $item_type = isset( $item_types[ $item_type ] ) ? $item_types[ $item_type ] : __( $item_type, 'invoicing' );
240
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
241 241
 
242
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
242
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
243 243
 }
244 244
 
245
-function wpinv_get_random_item( $post_ids = true ) {
246
-    wpinv_get_random_items( 1, $post_ids );
245
+function wpinv_get_random_item($post_ids = true) {
246
+    wpinv_get_random_items(1, $post_ids);
247 247
 }
248 248
 
249
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
250
-    if ( $post_ids ) {
249
+function wpinv_get_random_items($num = 3, $post_ids = true) {
250
+    if ($post_ids) {
251 251
         $args = array(
252 252
 			'post_type'  => 'wpi_item',
253 253
 			'orderby'    => 'rand',
@@ -262,9 +262,9 @@  discard block
 block discarded – undo
262 262
 		);
263 263
     }
264 264
 
265
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
265
+    $args = apply_filters('wpinv_get_random_items', $args);
266 266
 
267
-    return get_posts( $args );
267
+    return get_posts($args);
268 268
 }
269 269
 
270 270
 /**
@@ -273,13 +273,13 @@  discard block
 block discarded – undo
273 273
  * @param WPInv_Item|int $item
274 274
  * @param bool $html
275 275
  */
276
-function wpinv_get_item_suffix( $item, $html = true ) {
276
+function wpinv_get_item_suffix($item, $html = true) {
277 277
 
278
-    $item   = new WPInv_Item( $item );
279
-    $suffix = $item->is_recurring() ? ' ' . __( '(r)', 'invoicing' ) : '';
280
-    $suffix = $html ? $suffix : wp_strip_all_tags( $suffix );
278
+    $item   = new WPInv_Item($item);
279
+    $suffix = $item->is_recurring() ? ' ' . __('(r)', 'invoicing') : '';
280
+    $suffix = $html ? $suffix : wp_strip_all_tags($suffix);
281 281
 
282
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
282
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
283 283
 }
284 284
 
285 285
 /**
@@ -288,9 +288,9 @@  discard block
 block discarded – undo
288 288
  * @param WPInv_Item|int $item
289 289
  * @param bool $force_delete
290 290
  */
291
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
292
-    $item = new WPInv_Item( $item );
293
-    $item->delete( $force_delete );
291
+function wpinv_remove_item($item = 0, $force_delete = false) {
292
+    $item = new WPInv_Item($item);
293
+    $item->delete($force_delete);
294 294
 }
295 295
 
296 296
 /**
@@ -329,44 +329,44 @@  discard block
 block discarded – undo
329 329
  * @param bool $wp_error whether or not to return a WP_Error on failure.
330 330
  * @return bool|WP_Error|WPInv_Item
331 331
  */
332
-function wpinv_create_item( $args = array(), $wp_error = false ) {
332
+function wpinv_create_item($args = array(), $wp_error = false) {
333 333
 
334 334
     // Prepare the item.
335
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
336
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
337
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
335
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
336
+        $type = empty($args['type']) ? 'custom' : $args['type'];
337
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
338 338
 
339
-        if ( ! empty( $item ) ) {
339
+        if (!empty($item)) {
340 340
             $args['ID'] = $item->get_id();
341 341
         }
342 342
     }
343 343
 
344 344
     // Do we have an item?
345
-    if ( ! empty( $args['ID'] ) ) {
346
-        $item = new WPInv_Item( $args['ID'] );
345
+    if (!empty($args['ID'])) {
346
+        $item = new WPInv_Item($args['ID']);
347 347
     } else {
348 348
         $item = new WPInv_Item();
349 349
     }
350 350
 
351 351
     // Do we have an error?
352
-    if ( ! empty( $item->last_error ) ) {
353
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
352
+    if (!empty($item->last_error)) {
353
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
354 354
     }
355 355
 
356 356
     // Update item props.
357
-    $item->set_props( $args );
357
+    $item->set_props($args);
358 358
 
359 359
     // Save the item.
360 360
     $item->save();
361 361
 
362 362
     // Do we have an error?
363
-    if ( ! empty( $item->last_error ) ) {
364
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
363
+    if (!empty($item->last_error)) {
364
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
365 365
     }
366 366
 
367 367
     // Was the item saved?
368
-    if ( ! $item->get_id() ) {
369
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
368
+    if (!$item->get_id()) {
369
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
370 370
     }
371 371
 
372 372
     return $item;
@@ -378,14 +378,14 @@  discard block
 block discarded – undo
378 378
  *
379 379
  * @see wpinv_create_item()
380 380
  */
381
-function wpinv_update_item( $args = array(), $wp_error = false ) {
382
-    return wpinv_create_item( $args, $wp_error );
381
+function wpinv_update_item($args = array(), $wp_error = false) {
382
+    return wpinv_create_item($args, $wp_error);
383 383
 }
384 384
 
385 385
 /**
386 386
  * Sanitizes a recurring period
387 387
  */
388
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
388
+function getpaid_sanitize_recurring_period($period, $full = false) {
389 389
 
390 390
     $periods = array(
391 391
         'D' => 'day',
@@ -394,16 +394,16 @@  discard block
 block discarded – undo
394 394
         'Y' => 'year',
395 395
     );
396 396
 
397
-    if ( ! isset( $periods[ $period ] ) ) {
397
+    if (!isset($periods[$period])) {
398 398
         $period = 'D';
399 399
     }
400 400
 
401
-    return $full ? $periods[ $period ] : $period;
401
+    return $full ? $periods[$period] : $period;
402 402
 
403 403
 }
404 404
 
405
-function wpinv_item_max_buyable_quantity( $item_id ) {
406
-    return apply_filters( 'wpinv_item_max_buyable_quantity', 5, $item_id );
405
+function wpinv_item_max_buyable_quantity($item_id) {
406
+    return apply_filters('wpinv_item_max_buyable_quantity', 5, $item_id);
407 407
 }
408 408
 
409 409
 /**
@@ -411,47 +411,47 @@  discard block
 block discarded – undo
411 411
  *
412 412
  * @param WPInv_Item|GetPaid_Form_Item $item
413 413
  */
414
-function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) {
414
+function getpaid_item_recurring_price_help_text($item, $currency = '', $_initial_price = false, $_recurring_price = false) {
415 415
 
416 416
     // Abort if it is not recurring.
417
-    if ( ! $item->is_recurring() ) {
417
+    if (!$item->is_recurring()) {
418 418
         return '';
419 419
     }
420 420
 
421
-    $initial_price   = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price;
422
-    $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price;
423
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
421
+    $initial_price   = false === $_initial_price ? wpinv_price($item->get_initial_price(), $currency) : $_initial_price;
422
+    $recurring_price = false === $_recurring_price ? wpinv_price($item->get_recurring_price(), $currency) : $_recurring_price;
423
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
424 424
     $initial_class   = 'getpaid-item-initial-price';
425 425
     $recurring_class = 'getpaid-item-recurring-price';
426 426
     $bill_times      = $item->get_recurring_limit();
427 427
     $bill_times_less = $bill_times - 1;
428 428
 
429
-    if ( ! empty( $bill_times ) ) {
429
+    if (!empty($bill_times)) {
430 430
 		$bill_times = $item->get_recurring_interval() * $bill_times;
431
-        $bill_times_less = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times - $item->get_recurring_interval() );
432
-		$bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times );
431
+        $bill_times_less = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times - $item->get_recurring_interval());
432
+		$bill_times = getpaid_get_subscription_period_label($item->get_recurring_period(), $bill_times);
433 433
 	}
434 434
 
435
-    if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) {
436
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
437
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
435
+    if ($item instanceof GetPaid_Form_Item && false === $_initial_price) {
436
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
437
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
438 438
     }
439 439
 
440
-    if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) {
441
-        return __( 'Free forever', 'invoicing' );
440
+    if (wpinv_price(0, $currency) == $initial_price && wpinv_price(0, $currency) == $recurring_price) {
441
+        return __('Free forever', 'invoicing');
442 442
     }
443 443
 
444 444
     // For free trial items.
445
-    if ( $item->has_free_trial() ) {
446
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
445
+    if ($item->has_free_trial()) {
446
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
447 447
 
448
-        if ( wpinv_price( 0, $currency ) == $initial_price ) {
448
+        if (wpinv_price(0, $currency) == $initial_price) {
449 449
 
450
-            if ( empty( $bill_times ) ) {
450
+            if (empty($bill_times)) {
451 451
 
452 452
                 return sprintf(
453 453
                     // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
454
-                    _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
454
+                    _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
455 455
                     "<span class='getpaid-item-trial-period'>$trial_period</span>",
456 456
                     "<span class='$recurring_class'>$recurring_price</span>",
457 457
                     "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 
462 462
             return sprintf(
463 463
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times
464
-                _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ),
464
+                _x('Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing'),
465 465
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
466 466
                 "<span class='$recurring_class'>$recurring_price</span>",
467 467
                 "<span class='getpaid-item-recurring-period'>$period</span>",
@@ -470,11 +470,11 @@  discard block
 block discarded – undo
470 470
 
471 471
         }
472 472
 
473
-        if ( empty( $bill_times ) ) {
473
+        if (empty($bill_times)) {
474 474
 
475 475
             return sprintf(
476 476
                 // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
477
-                _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
477
+                _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
478 478
                 "<span class='$initial_class'>$initial_price</span>",
479 479
                 "<span class='getpaid-item-trial-period'>$trial_period</span>",
480 480
                 "<span class='$recurring_class'>$recurring_price</span>",
@@ -485,7 +485,7 @@  discard block
 block discarded – undo
485 485
 
486 486
         return sprintf(
487 487
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times
488
-            _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ),
488
+            _x('%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing'),
489 489
             "<span class='$initial_class'>$initial_price</span>",
490 490
             "<span class='getpaid-item-trial-period'>$trial_period</span>",
491 491
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -495,13 +495,13 @@  discard block
 block discarded – undo
495 495
 
496 496
     }
497 497
 
498
-    if ( $initial_price == $recurring_price ) {
498
+    if ($initial_price == $recurring_price) {
499 499
 
500
-        if ( empty( $bill_times ) ) {
500
+        if (empty($bill_times)) {
501 501
 
502 502
             return sprintf(
503 503
                 // translators: $1: is the recurring price, $2: is the susbcription period
504
-                _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
504
+                _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
505 505
                 "<span class='$recurring_class'>$recurring_price</span>",
506 506
                 "<span class='getpaid-item-recurring-period'>$period</span>"
507 507
             );
@@ -510,7 +510,7 @@  discard block
 block discarded – undo
510 510
 
511 511
         return sprintf(
512 512
             // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times
513
-            _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
513
+            _x('%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
514 514
             "<span class='$recurring_class'>$recurring_price</span>",
515 515
             "<span class='getpaid-item-recurring-period'>$period</span>",
516 516
             "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>"
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
 
519 519
     }
520 520
 
521
-    if ( $initial_price == wpinv_price( 0, $currency ) ) {
521
+    if ($initial_price == wpinv_price(0, $currency)) {
522 522
 
523
-        if ( empty( $bill_times ) ) {
523
+        if (empty($bill_times)) {
524 524
 
525 525
             return sprintf(
526 526
                 // translators: $1: is the recurring period, $2: is the recurring price
527
-                _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ),
527
+                _x('Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing'),
528 528
                 "<span class='getpaid-item-recurring-period'>$period</span>",
529 529
                 "<span class='$recurring_class'>$recurring_price</span>"
530 530
             );
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
 
534 534
         return sprintf(
535 535
             // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times
536
-            _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ),
536
+            _x('Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing'),
537 537
             "<span class='getpaid-item-recurring-period'>$period</span>",
538 538
             "<span class='$recurring_class'>$recurring_price</span>",
539 539
             "<span class='getpaid-item-recurring-bill-times'>$bill_times_less</span>"
@@ -541,11 +541,11 @@  discard block
 block discarded – undo
541 541
 
542 542
     }
543 543
 
544
-    if ( empty( $bill_times ) ) {
544
+    if (empty($bill_times)) {
545 545
 
546 546
         return sprintf(
547 547
             // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
548
-            _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
548
+            _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
549 549
             "<span class='$initial_class'>$initial_price</span>",
550 550
             "<span class='$recurring_class'>$recurring_price</span>",
551 551
             "<span class='getpaid-item-recurring-period'>$period</span>"
@@ -555,7 +555,7 @@  discard block
 block discarded – undo
555 555
 
556 556
     return sprintf(
557 557
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times
558
-        _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ),
558
+        _x('Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing'),
559 559
         "<span class='$initial_class'>$initial_price</span>",
560 560
         "<span class='$recurring_class'>$recurring_price</span>",
561 561
         "<span class='getpaid-item-recurring-period'>$period</span>",
Please login to merge, or discard this patch.
templates/payment-forms/elements/date.php 2 patches
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -12,59 +12,59 @@
 block discarded – undo
12 12
 $label       = empty( $label ) ? '' : wp_kses_post( $label );
13 13
 $label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14 14
 if ( ! empty( $required ) ) {
15
-	$label .= "<span class='text-danger'> *</span>";
15
+    $label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20 20
 if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
21
+    $disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
+    $disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
+    $disabled_dates = array_filter( explode( ',', $disabled_dates ) );
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+    foreach ( $disabled_dates as $disabled_date ) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+        $disabled_date = trim( $disabled_date );
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
30
-			$disable_dates[] = $disabled_date;
31
-			continue;
32
-		}
29
+        if ( false === strpos( $disabled_date, '|' ) ) {
30
+            $disable_dates[] = $disabled_date;
31
+            continue;
32
+        }
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
35
-		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
38
-		);
34
+        $disabled_date   = explode( '|', $disabled_date );
35
+        $disable_dates[] = array(
36
+            'from' => trim( $disabled_date[0] ),
37
+            'to'   => trim( $disabled_date[1] ),
38
+        );
39 39
 
40
-	}
40
+    }
41 41
 }
42 42
 
43 43
 $options = array(
44
-	'data-default-date'     => empty( $default_date ) ? false : $default_date,
45
-	'data-min-date'         => empty( $min_date ) ? false : $min_date,
46
-	'data-max-date'         => empty( $max_date ) ? false : $max_date,
47
-	'data-mode'             => empty( $mode ) ? 'single' : $mode,
48
-	'data-alt-format'       => get_option( 'date_format', 'F j, Y' ),
49
-	'data-date-format'      => 'Y-m-d',
50
-	'data-alt-input'        => 'true',
51
-	'data-disable_alt'      => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
52
-	'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
44
+    'data-default-date'     => empty( $default_date ) ? false : $default_date,
45
+    'data-min-date'         => empty( $min_date ) ? false : $min_date,
46
+    'data-max-date'         => empty( $max_date ) ? false : $max_date,
47
+    'data-mode'             => empty( $mode ) ? 'single' : $mode,
48
+    'data-alt-format'       => get_option( 'date_format', 'F j, Y' ),
49
+    'data-date-format'      => 'Y-m-d',
50
+    'data-alt-input'        => 'true',
51
+    'data-disable_alt'      => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
52
+    'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
53 53
 );
54 54
 
55 55
 aui()->input(
56
-	array(
57
-		'name'             => esc_attr( $id ),
58
-		'id'               => esc_attr( $element_id ),
59
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
60
-		'required'         => ! empty( $required ),
61
-		'label'            => $label,
62
-		'label_type'       => 'vertical',
63
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
64
-		'type'             => 'datepicker',
65
-		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
66
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
67
-		'value'            => $query_value,
68
-	),
69
-	true
56
+    array(
57
+        'name'             => esc_attr( $id ),
58
+        'id'               => esc_attr( $element_id ),
59
+        'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
60
+        'required'         => ! empty( $required ),
61
+        'label'            => $label,
62
+        'label_type'       => 'vertical',
63
+        'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
64
+        'type'             => 'datepicker',
65
+        'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
66
+        'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
67
+        'value'            => $query_value,
68
+    ),
69
+    true
70 70
 );
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -7,63 +7,63 @@
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12
-$label       = empty( $label ) ? '' : wp_kses_post( $label );
13
-$label_class = sanitize_key( preg_replace( '/[^A-Za-z0-9_-]/', '-', $label ) );
14
-if ( ! empty( $required ) ) {
12
+$label       = empty($label) ? '' : wp_kses_post($label);
13
+$label_class = sanitize_key(preg_replace('/[^A-Za-z0-9_-]/', '-', $label));
14
+if (!empty($required)) {
15 15
 	$label .= "<span class='text-danger'> *</span>";
16 16
 }
17 17
 
18 18
 $disable_dates = array();
19 19
 
20
-if ( ! empty( $disabled_dates ) ) {
21
-	$disabled_dates = preg_replace( '/\s+/', '', $disabled_dates );
22
-	$disabled_dates = str_ireplace( 'today', current_time( 'Y-m-d' ), $disabled_dates );
23
-	$disabled_dates = array_filter( explode( ',', $disabled_dates ) );
20
+if (!empty($disabled_dates)) {
21
+	$disabled_dates = preg_replace('/\s+/', '', $disabled_dates);
22
+	$disabled_dates = str_ireplace('today', current_time('Y-m-d'), $disabled_dates);
23
+	$disabled_dates = array_filter(explode(',', $disabled_dates));
24 24
 
25
-	foreach ( $disabled_dates as $disabled_date ) {
25
+	foreach ($disabled_dates as $disabled_date) {
26 26
 
27
-		$disabled_date = trim( $disabled_date );
27
+		$disabled_date = trim($disabled_date);
28 28
 
29
-		if ( false === strpos( $disabled_date, '|' ) ) {
29
+		if (false === strpos($disabled_date, '|')) {
30 30
 			$disable_dates[] = $disabled_date;
31 31
 			continue;
32 32
 		}
33 33
 
34
-		$disabled_date   = explode( '|', $disabled_date );
34
+		$disabled_date   = explode('|', $disabled_date);
35 35
 		$disable_dates[] = array(
36
-			'from' => trim( $disabled_date[0] ),
37
-			'to'   => trim( $disabled_date[1] ),
36
+			'from' => trim($disabled_date[0]),
37
+			'to'   => trim($disabled_date[1]),
38 38
 		);
39 39
 
40 40
 	}
41 41
 }
42 42
 
43 43
 $options = array(
44
-	'data-default-date'     => empty( $default_date ) ? false : $default_date,
45
-	'data-min-date'         => empty( $min_date ) ? false : $min_date,
46
-	'data-max-date'         => empty( $max_date ) ? false : $max_date,
47
-	'data-mode'             => empty( $mode ) ? 'single' : $mode,
48
-	'data-alt-format'       => get_option( 'date_format', 'F j, Y' ),
44
+	'data-default-date'     => empty($default_date) ? false : $default_date,
45
+	'data-min-date'         => empty($min_date) ? false : $min_date,
46
+	'data-max-date'         => empty($max_date) ? false : $max_date,
47
+	'data-mode'             => empty($mode) ? 'single' : $mode,
48
+	'data-alt-format'       => get_option('date_format', 'F j, Y'),
49 49
 	'data-date-format'      => 'Y-m-d',
50 50
 	'data-alt-input'        => 'true',
51
-	'data-disable_alt'      => empty( $disabled_dates ) ? false : wp_json_encode( $disable_dates ),
52
-	'data-disable_days_alt' => empty( $disable_days ) ? false : wp_json_encode( wp_parse_id_list( $disable_days ) ),
51
+	'data-disable_alt'      => empty($disabled_dates) ? false : wp_json_encode($disable_dates),
52
+	'data-disable_days_alt' => empty($disable_days) ? false : wp_json_encode(wp_parse_id_list($disable_days)),
53 53
 );
54 54
 
55 55
 aui()->input(
56 56
 	array(
57
-		'name'             => esc_attr( $id ),
58
-		'id'               => esc_attr( $element_id ),
59
-		'placeholder'      => empty( $placeholder ) ? '' : esc_attr( $placeholder ),
60
-		'required'         => ! empty( $required ),
57
+		'name'             => esc_attr($id),
58
+		'id'               => esc_attr($element_id),
59
+		'placeholder'      => empty($placeholder) ? '' : esc_attr($placeholder),
60
+		'required'         => !empty($required),
61 61
 		'label'            => $label,
62 62
 		'label_type'       => 'vertical',
63
-		'help_text'        => empty( $description ) ? '' : wp_kses_post( $description ),
63
+		'help_text'        => empty($description) ? '' : wp_kses_post($description),
64 64
 		'type'             => 'datepicker',
65 65
 		'class'            => $label_class . ' getpaid-init-flatpickr flatpickr-input',
66
-		'extra_attributes' => array_filter( apply_filters( 'getpaid_date_field_attributes', $options ) ),
66
+		'extra_attributes' => array_filter(apply_filters('getpaid_date_field_attributes', $options)),
67 67
 		'value'            => $query_value,
68 68
 	),
69 69
 	true
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 2 patches
Indentation   +384 added lines, -384 removed lines patch added patch discarded remove patch
@@ -20,237 +20,237 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		$installed = get_option( 'gepaid_installed_on' );
52
-
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
55
-		}
56
-
57
-		if ( method_exists( $this, $method ) ) {
58
-			$this->$method();
59
-		}
60
-
61
-	}
62
-
63
-	/**
64
-	 * Do a fresh install.
65
-	 *
66
-	 */
67
-	public function upgrade_from_0() {
68
-		$this->create_subscriptions_table();
69
-		$this->create_invoices_table();
70
-		$this->create_invoice_items_table();
71
-
72
-		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
-	}
75
-
76
-	/**
77
-	 * Upgrade to 0.0.5
78
-	 *
79
-	 */
80
-	public function upgrade_from_004() {
81
-		global $wpdb;
82
-
83
-		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
-
88
-			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
91
-			}
92
-		}
93
-
94
-		// Item meta key changes
95
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
97
-
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
-
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
105
-			}
106
-		}
107
-
108
-		$this->upgrade_from_102();
109
-	}
110
-
111
-	/**
112
-	 * Upgrade to 1.0.3
113
-	 *
114
-	 */
115
-	public function upgrade_from_102() {
116
-		$this->create_subscriptions_table();
117
-		$this->upgrade_from_118();
118
-	}
119
-
120
-	/**
121
-	 * Upgrade to version 2.0.0.
122
-	 *
123
-	 */
124
-	public function upgrade_from_118() {
125
-		$this->create_invoices_table();
126
-		$this->create_invoice_items_table();
127
-		$this->migrate_old_invoices();
128
-	}
129
-
130
-	/**
131
-	 * Upgrade to version 2.0.8.
132
-	 *
133
-	 */
134
-	public function upgrade_from_207() {
135
-		global $wpdb;
136
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
137
-		$this->upgrade_from_2615();
138
-	}
139
-
140
-	/**
141
-	 * Upgrade to version 2.6.16.
142
-	 *
143
-	 */
144
-	public function upgrade_from_2615() {
145
-		global $wpdb;
146
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
148
-	}
149
-
150
-	/**
151
-	 * Give administrators the capability to manage GetPaid.
152
-	 *
153
-	 */
154
-	public function add_capabilities() {
155
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
156
-	}
157
-
158
-	/**
159
-	 * Retreives GetPaid pages.
160
-	 *
161
-	 */
162
-	public static function get_pages() {
163
-
164
-		return apply_filters(
165
-			'wpinv_create_pages',
166
-			array(
167
-
168
-				// Checkout page.
169
-				'checkout_page'             => array(
170
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
172
-					'content' => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        $installed = get_option( 'gepaid_installed_on' );
52
+
53
+        if ( empty( $installed ) ) {
54
+            update_option( 'gepaid_installed_on', time() );
55
+        }
56
+
57
+        if ( method_exists( $this, $method ) ) {
58
+            $this->$method();
59
+        }
60
+
61
+    }
62
+
63
+    /**
64
+     * Do a fresh install.
65
+     *
66
+     */
67
+    public function upgrade_from_0() {
68
+        $this->create_subscriptions_table();
69
+        $this->create_invoices_table();
70
+        $this->create_invoice_items_table();
71
+
72
+        // Save default tax rates.
73
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
+    }
75
+
76
+    /**
77
+     * Upgrade to 0.0.5
78
+     *
79
+     */
80
+    public function upgrade_from_004() {
81
+        global $wpdb;
82
+
83
+        // Invoices.
84
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
+        if ( ! empty( $results ) ) {
86
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
+
88
+            // Clean post cache
89
+            foreach ( $results as $row ) {
90
+                clean_post_cache( $row->ID );
91
+            }
92
+        }
93
+
94
+        // Item meta key changes
95
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
+        $results = $wpdb->get_results( $query );
97
+
98
+        if ( ! empty( $results ) ) {
99
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
+
103
+            foreach ( $results as $row ) {
104
+                clean_post_cache( $row->post_id );
105
+            }
106
+        }
107
+
108
+        $this->upgrade_from_102();
109
+    }
110
+
111
+    /**
112
+     * Upgrade to 1.0.3
113
+     *
114
+     */
115
+    public function upgrade_from_102() {
116
+        $this->create_subscriptions_table();
117
+        $this->upgrade_from_118();
118
+    }
119
+
120
+    /**
121
+     * Upgrade to version 2.0.0.
122
+     *
123
+     */
124
+    public function upgrade_from_118() {
125
+        $this->create_invoices_table();
126
+        $this->create_invoice_items_table();
127
+        $this->migrate_old_invoices();
128
+    }
129
+
130
+    /**
131
+     * Upgrade to version 2.0.8.
132
+     *
133
+     */
134
+    public function upgrade_from_207() {
135
+        global $wpdb;
136
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
137
+        $this->upgrade_from_2615();
138
+    }
139
+
140
+    /**
141
+     * Upgrade to version 2.6.16.
142
+     *
143
+     */
144
+    public function upgrade_from_2615() {
145
+        global $wpdb;
146
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
148
+    }
149
+
150
+    /**
151
+     * Give administrators the capability to manage GetPaid.
152
+     *
153
+     */
154
+    public function add_capabilities() {
155
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
156
+    }
157
+
158
+    /**
159
+     * Retreives GetPaid pages.
160
+     *
161
+     */
162
+    public static function get_pages() {
163
+
164
+        return apply_filters(
165
+            'wpinv_create_pages',
166
+            array(
167
+
168
+                // Checkout page.
169
+                'checkout_page'             => array(
170
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
172
+                    'content' => '
173 173
 						<!-- wp:shortcode -->
174 174
 						[wpinv_checkout]
175 175
 						<!-- /wp:shortcode -->
176 176
 					',
177
-					'parent'  => '',
178
-				),
179
-
180
-				// Invoice history page.
181
-				'invoice_history_page'      => array(
182
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
184
-					'content' => '
177
+                    'parent'  => '',
178
+                ),
179
+
180
+                // Invoice history page.
181
+                'invoice_history_page'      => array(
182
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
184
+                    'content' => '
185 185
 					<!-- wp:shortcode -->
186 186
 					[wpinv_history]
187 187
 					<!-- /wp:shortcode -->
188 188
 				',
189
-					'parent'  => '',
190
-				),
191
-
192
-				// Success page content.
193
-				'success_page'              => array(
194
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
196
-					'content' => '
189
+                    'parent'  => '',
190
+                ),
191
+
192
+                // Success page content.
193
+                'success_page'              => array(
194
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
196
+                    'content' => '
197 197
 					<!-- wp:shortcode -->
198 198
 					[wpinv_receipt]
199 199
 					<!-- /wp:shortcode -->
200 200
 				',
201
-					'parent'  => 'gp-checkout',
202
-				),
203
-
204
-				// Failure page content.
205
-				'failure_page'              => array(
206
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
209
-					'parent'  => 'gp-checkout',
210
-				),
211
-
212
-				// Subscriptions history page.
213
-				'invoice_subscription_page' => array(
214
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
216
-					'content' => '
201
+                    'parent'  => 'gp-checkout',
202
+                ),
203
+
204
+                // Failure page content.
205
+                'failure_page'              => array(
206
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
209
+                    'parent'  => 'gp-checkout',
210
+                ),
211
+
212
+                // Subscriptions history page.
213
+                'invoice_subscription_page' => array(
214
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
216
+                    'content' => '
217 217
 					<!-- wp:shortcode -->
218 218
 					[wpinv_subscriptions]
219 219
 					<!-- /wp:shortcode -->
220 220
 				',
221
-					'parent'  => '',
222
-				),
221
+                    'parent'  => '',
222
+                ),
223 223
 
224
-			)
225
-		);
224
+            )
225
+        );
226 226
 
227
-	}
227
+    }
228 228
 
229
-	/**
230
-	 * Re-create GetPaid pages.
231
-	 *
232
-	 */
233
-	public function create_pages() {
229
+    /**
230
+     * Re-create GetPaid pages.
231
+     *
232
+     */
233
+    public function create_pages() {
234 234
 
235
-		foreach ( self::get_pages() as $key => $page ) {
236
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
237
-		}
235
+        foreach ( self::get_pages() as $key => $page ) {
236
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
237
+        }
238 238
 
239
-	}
239
+    }
240 240
 
241
-	/**
242
-	 * Create subscriptions table.
243
-	 *
244
-	 */
245
-	public function create_subscriptions_table() {
241
+    /**
242
+     * Create subscriptions table.
243
+     *
244
+     */
245
+    public function create_subscriptions_table() {
246 246
 
247
-		global $wpdb;
247
+        global $wpdb;
248 248
 
249
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
249
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
250 250
 
251
-		// Create tables.
252
-		$charset_collate = $wpdb->get_charset_collate();
253
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
251
+        // Create tables.
252
+        $charset_collate = $wpdb->get_charset_collate();
253
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
254 254
 			id bigint(20) unsigned NOT NULL auto_increment,
255 255
 			customer_id bigint(20) NOT NULL,
256 256
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -273,22 +273,22 @@  discard block
 block discarded – undo
273 273
 			KEY customer_and_status (customer_id, status)
274 274
 		  ) $charset_collate;";
275 275
 
276
-		dbDelta( $sql );
276
+        dbDelta( $sql );
277 277
 
278
-	}
278
+    }
279 279
 
280
-	/**
281
-	 * Create invoices table.
282
-	 *
283
-	 */
284
-	public function create_invoices_table() {
285
-		global $wpdb;
280
+    /**
281
+     * Create invoices table.
282
+     *
283
+     */
284
+    public function create_invoices_table() {
285
+        global $wpdb;
286 286
 
287
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
287
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
288 288
 
289
-		// Create tables.
290
-		$charset_collate = $wpdb->get_charset_collate();
291
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
289
+        // Create tables.
290
+        $charset_collate = $wpdb->get_charset_collate();
291
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
292 292
 			post_id BIGINT(20) NOT NULL,
293 293
             `number` VARCHAR(100),
294 294
             `key` VARCHAR(100),
@@ -324,22 +324,22 @@  discard block
 block discarded – undo
324 324
 			KEY `key` (`key`)
325 325
 		  ) $charset_collate;";
326 326
 
327
-		dbDelta( $sql );
327
+        dbDelta( $sql );
328 328
 
329
-	}
329
+    }
330 330
 
331
-	/**
332
-	 * Create invoice items table.
333
-	 *
334
-	 */
335
-	public function create_invoice_items_table() {
336
-		global $wpdb;
331
+    /**
332
+     * Create invoice items table.
333
+     *
334
+     */
335
+    public function create_invoice_items_table() {
336
+        global $wpdb;
337 337
 
338
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
338
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
339 339
 
340
-		// Create tables.
341
-		$charset_collate = $wpdb->get_charset_collate();
342
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
340
+        // Create tables.
341
+        $charset_collate = $wpdb->get_charset_collate();
342
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
343 343
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
344 344
             post_id BIGINT(20) NOT NULL,
345 345
             item_id BIGINT(20) NOT NULL,
@@ -361,159 +361,159 @@  discard block
 block discarded – undo
361 361
 			KEY post_id (post_id)
362 362
 		  ) $charset_collate;";
363 363
 
364
-		dbDelta( $sql );
365
-
366
-	}
367
-
368
-	/**
369
-	 * Migrates old invoices to new invoices.
370
-	 *
371
-	 */
372
-	public function migrate_old_invoices() {
373
-		global $wpdb;
374
-
375
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
378
-		$invoices            = array_unique(
379
-			get_posts(
380
-				array(
381
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
382
-					'posts_per_page' => -1,
383
-					'fields'         => 'ids',
384
-					'post_status'    => array_keys( get_post_stati() ),
385
-					'exclude'        => (array) $migrated,
386
-				)
387
-			)
388
-		);
389
-
390
-		// Abort if we do not have any invoices.
391
-		if ( empty( $invoices ) ) {
392
-			return;
393
-		}
394
-
395
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396
-
397
-		$invoice_rows = array();
398
-		foreach ( $invoices as $invoice ) {
399
-
400
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
401
-
402
-			if ( empty( $invoice->ID ) ) {
403
-				return;
404
-			}
405
-
406
-			$fields = array(
407
-				'post_id'            => $invoice->ID,
408
-				'number'             => $invoice->get_number(),
409
-				'key'                => $invoice->get_key(),
410
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
411
-				'mode'               => $invoice->mode,
412
-				'user_ip'            => $invoice->get_ip(),
413
-				'first_name'         => $invoice->get_first_name(),
414
-				'last_name'          => $invoice->get_last_name(),
415
-				'address'            => $invoice->get_address(),
416
-				'city'               => $invoice->city,
417
-				'state'              => $invoice->state,
418
-				'country'            => $invoice->country,
419
-				'zip'                => $invoice->zip,
420
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
421
-				'gateway'            => $invoice->get_gateway(),
422
-				'transaction_id'     => $invoice->get_transaction_id(),
423
-				'currency'           => $invoice->get_currency(),
424
-				'subtotal'           => $invoice->get_subtotal(),
425
-				'tax'                => $invoice->get_tax(),
426
-				'fees_total'         => $invoice->get_fees_total(),
427
-				'total'              => $invoice->get_total(),
428
-				'discount'           => $invoice->get_discount(),
429
-				'discount_code'      => $invoice->get_discount_code(),
430
-				'disable_taxes'      => $invoice->disable_taxes,
431
-				'due_date'           => $invoice->get_due_date(),
432
-				'completed_date'     => $invoice->get_completed_date(),
433
-				'company'            => $invoice->company,
434
-				'vat_number'         => $invoice->vat_number,
435
-				'vat_rate'           => $invoice->vat_rate,
436
-				'custom_meta'        => $invoice->payment_meta,
437
-			);
438
-
439
-			foreach ( $fields as $key => $val ) {
440
-				if ( is_null( $val ) ) {
441
-					$val = '';
442
-				}
443
-				$val = maybe_serialize( $val );
444
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
445
-			}
446
-
447
-			$fields = implode( ', ', $fields );
448
-			$invoice_rows[] = "($fields)";
449
-
450
-			$item_rows    = array();
451
-			$item_columns = array();
452
-			foreach ( $invoice->get_cart_details() as $details ) {
453
-				$fields = array(
454
-					'post_id'          => $invoice->ID,
455
-					'item_id'          => $details['id'],
456
-					'item_name'        => $details['name'],
457
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
458
-					'vat_rate'         => $details['vat_rate'],
459
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
460
-					'tax'              => $details['tax'],
461
-					'item_price'       => $details['item_price'],
462
-					'custom_price'     => $details['custom_price'],
463
-					'quantity'         => $details['quantity'],
464
-					'discount'         => $details['discount'],
465
-					'subtotal'         => $details['subtotal'],
466
-					'price'            => $details['price'],
467
-					'meta'             => $details['meta'],
468
-					'fees'             => $details['fees'],
469
-				);
470
-
471
-				$item_columns = array_keys( $fields );
472
-
473
-				foreach ( $fields as $key => $val ) {
474
-					if ( is_null( $val ) ) {
475
-						$val = '';
476
-					}
477
-					$val = maybe_serialize( $val );
478
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
479
-				}
480
-
481
-				$fields = implode( ', ', $fields );
482
-				$item_rows[] = "($fields)";
483
-			}
484
-
485
-			$item_rows    = implode( ', ', $item_rows );
486
-			$item_columns = implode( ', ', $item_columns );
487
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
488
-		}
489
-
490
-		if ( empty( $invoice_rows ) ) {
491
-			return;
492
-		}
493
-
494
-		$invoice_rows = implode( ', ', $invoice_rows );
495
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
496
-
497
-	}
498
-
499
-	/**
500
-	 * Migrates old invoices to new invoices.
501
-	 *
502
-	 */
503
-	public static function rename_gateways_label() {
504
-		global $wpdb;
505
-
506
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
507
-
508
-			$wpdb->update(
509
-				$wpdb->prefix . 'getpaid_invoices',
510
-				array( 'gateway' => $gateway ),
511
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
512
-				'%s',
513
-				'%s'
514
-			);
515
-
516
-		}
517
-	}
364
+        dbDelta( $sql );
365
+
366
+    }
367
+
368
+    /**
369
+     * Migrates old invoices to new invoices.
370
+     *
371
+     */
372
+    public function migrate_old_invoices() {
373
+        global $wpdb;
374
+
375
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
378
+        $invoices            = array_unique(
379
+            get_posts(
380
+                array(
381
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
382
+                    'posts_per_page' => -1,
383
+                    'fields'         => 'ids',
384
+                    'post_status'    => array_keys( get_post_stati() ),
385
+                    'exclude'        => (array) $migrated,
386
+                )
387
+            )
388
+        );
389
+
390
+        // Abort if we do not have any invoices.
391
+        if ( empty( $invoices ) ) {
392
+            return;
393
+        }
394
+
395
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396
+
397
+        $invoice_rows = array();
398
+        foreach ( $invoices as $invoice ) {
399
+
400
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
401
+
402
+            if ( empty( $invoice->ID ) ) {
403
+                return;
404
+            }
405
+
406
+            $fields = array(
407
+                'post_id'            => $invoice->ID,
408
+                'number'             => $invoice->get_number(),
409
+                'key'                => $invoice->get_key(),
410
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
411
+                'mode'               => $invoice->mode,
412
+                'user_ip'            => $invoice->get_ip(),
413
+                'first_name'         => $invoice->get_first_name(),
414
+                'last_name'          => $invoice->get_last_name(),
415
+                'address'            => $invoice->get_address(),
416
+                'city'               => $invoice->city,
417
+                'state'              => $invoice->state,
418
+                'country'            => $invoice->country,
419
+                'zip'                => $invoice->zip,
420
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
421
+                'gateway'            => $invoice->get_gateway(),
422
+                'transaction_id'     => $invoice->get_transaction_id(),
423
+                'currency'           => $invoice->get_currency(),
424
+                'subtotal'           => $invoice->get_subtotal(),
425
+                'tax'                => $invoice->get_tax(),
426
+                'fees_total'         => $invoice->get_fees_total(),
427
+                'total'              => $invoice->get_total(),
428
+                'discount'           => $invoice->get_discount(),
429
+                'discount_code'      => $invoice->get_discount_code(),
430
+                'disable_taxes'      => $invoice->disable_taxes,
431
+                'due_date'           => $invoice->get_due_date(),
432
+                'completed_date'     => $invoice->get_completed_date(),
433
+                'company'            => $invoice->company,
434
+                'vat_number'         => $invoice->vat_number,
435
+                'vat_rate'           => $invoice->vat_rate,
436
+                'custom_meta'        => $invoice->payment_meta,
437
+            );
438
+
439
+            foreach ( $fields as $key => $val ) {
440
+                if ( is_null( $val ) ) {
441
+                    $val = '';
442
+                }
443
+                $val = maybe_serialize( $val );
444
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
445
+            }
446
+
447
+            $fields = implode( ', ', $fields );
448
+            $invoice_rows[] = "($fields)";
449
+
450
+            $item_rows    = array();
451
+            $item_columns = array();
452
+            foreach ( $invoice->get_cart_details() as $details ) {
453
+                $fields = array(
454
+                    'post_id'          => $invoice->ID,
455
+                    'item_id'          => $details['id'],
456
+                    'item_name'        => $details['name'],
457
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
458
+                    'vat_rate'         => $details['vat_rate'],
459
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
460
+                    'tax'              => $details['tax'],
461
+                    'item_price'       => $details['item_price'],
462
+                    'custom_price'     => $details['custom_price'],
463
+                    'quantity'         => $details['quantity'],
464
+                    'discount'         => $details['discount'],
465
+                    'subtotal'         => $details['subtotal'],
466
+                    'price'            => $details['price'],
467
+                    'meta'             => $details['meta'],
468
+                    'fees'             => $details['fees'],
469
+                );
470
+
471
+                $item_columns = array_keys( $fields );
472
+
473
+                foreach ( $fields as $key => $val ) {
474
+                    if ( is_null( $val ) ) {
475
+                        $val = '';
476
+                    }
477
+                    $val = maybe_serialize( $val );
478
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
479
+                }
480
+
481
+                $fields = implode( ', ', $fields );
482
+                $item_rows[] = "($fields)";
483
+            }
484
+
485
+            $item_rows    = implode( ', ', $item_rows );
486
+            $item_columns = implode( ', ', $item_columns );
487
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
488
+        }
489
+
490
+        if ( empty( $invoice_rows ) ) {
491
+            return;
492
+        }
493
+
494
+        $invoice_rows = implode( ', ', $invoice_rows );
495
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
496
+
497
+    }
498
+
499
+    /**
500
+     * Migrates old invoices to new invoices.
501
+     *
502
+     */
503
+    public static function rename_gateways_label() {
504
+        global $wpdb;
505
+
506
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
507
+
508
+            $wpdb->update(
509
+                $wpdb->prefix . 'getpaid_invoices',
510
+                array( 'gateway' => $gateway ),
511
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
512
+                '%s',
513
+                '%s'
514
+            );
515
+
516
+        }
517
+    }
518 518
 
519 519
 }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  * @since   2.0.2
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 /**
14 14
  * The main installer/updater class.
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
 	 *
26 26
 	 * @param string $upgrade_from The current invoicing version.
27 27
 	 */
28
-	public function upgrade_db( $upgrade_from ) {
28
+	public function upgrade_db($upgrade_from) {
29 29
 
30 30
 		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
31
+		update_option('wpinv_version', WPINV_VERSION);
32 32
 
33 33
 		// Setup the invoice Custom Post Type.
34 34
 		GetPaid_Post_Types::register_post_types();
@@ -48,13 +48,13 @@  discard block
 block discarded – undo
48 48
 		// Create any missing database tables.
49 49
 		$method = "upgrade_from_$upgrade_from";
50 50
 
51
-		$installed = get_option( 'gepaid_installed_on' );
51
+		$installed = get_option('gepaid_installed_on');
52 52
 
53
-		if ( empty( $installed ) ) {
54
-			update_option( 'gepaid_installed_on', time() );
53
+		if (empty($installed)) {
54
+			update_option('gepaid_installed_on', time());
55 55
 		}
56 56
 
57
-		if ( method_exists( $this, $method ) ) {
57
+		if (method_exists($this, $method)) {
58 58
 			$this->$method();
59 59
 		}
60 60
 
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		$this->create_invoice_items_table();
71 71
 
72 72
 		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
73
+		update_option('wpinv_tax_rates', wpinv_get_data('tax-rates'));
74 74
 	}
75 75
 
76 76
 	/**
@@ -81,27 +81,27 @@  discard block
 block discarded – undo
81 81
 		global $wpdb;
82 82
 
83 83
 		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
84
+		$results = $wpdb->get_results("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
85
+		if (!empty($results)) {
86
+			$wpdb->query("UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )");
87 87
 
88 88
 			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
89
+			foreach ($results as $row) {
90
+				clean_post_cache($row->ID);
91 91
 			}
92 92
 		}
93 93
 
94 94
 		// Item meta key changes
95 95
 		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
96
+		$results = $wpdb->get_results($query);
97 97
 
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
98
+		if (!empty($results)) {
99
+			$wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )");
100
+			$wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'");
101
+			$wpdb->query('UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'");
102 102
 
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
103
+			foreach ($results as $row) {
104
+				clean_post_cache($row->post_id);
105 105
 			}
106 106
 		}
107 107
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 */
134 134
 	public function upgrade_from_207() {
135 135
 		global $wpdb;
136
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
136
+		$wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);");
137 137
 		$this->upgrade_from_2615();
138 138
 	}
139 139
 
@@ -143,8 +143,8 @@  discard block
 block discarded – undo
143 143
 	 */
144 144
 	public function upgrade_from_2615() {
145 145
 		global $wpdb;
146
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';" );
147
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';" );
146
+		$wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN item_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY custom_price DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY price DECIMAL(16,4) NOT NULL DEFAULT '0';");
147
+		$wpdb->query("ALTER TABLE {$wpdb->prefix}getpaid_invoices MODIFY COLUMN subtotal DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY tax DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY fees_total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY total DECIMAL(16,4) NOT NULL DEFAULT '0', MODIFY discount DECIMAL(16,4) NOT NULL DEFAULT '0';");
148 148
 	}
149 149
 
150 150
 	/**
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 */
154 154
 	public function add_capabilities() {
155
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
155
+		$GLOBALS['wp_roles']->add_cap('administrator', 'manage_invoicing');
156 156
 	}
157 157
 
158 158
 	/**
@@ -167,8 +167,8 @@  discard block
 block discarded – undo
167 167
 
168 168
 				// Checkout page.
169 169
 				'checkout_page'             => array(
170
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
171
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
170
+					'name'    => _x('gp-checkout', 'Page slug', 'invoicing'),
171
+					'title'   => _x('Checkout', 'Page title', 'invoicing'),
172 172
 					'content' => '
173 173
 						<!-- wp:shortcode -->
174 174
 						[wpinv_checkout]
@@ -179,8 +179,8 @@  discard block
 block discarded – undo
179 179
 
180 180
 				// Invoice history page.
181 181
 				'invoice_history_page'      => array(
182
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
183
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
182
+					'name'    => _x('gp-invoices', 'Page slug', 'invoicing'),
183
+					'title'   => _x('My Invoices', 'Page title', 'invoicing'),
184 184
 					'content' => '
185 185
 					<!-- wp:shortcode -->
186 186
 					[wpinv_history]
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 
192 192
 				// Success page content.
193 193
 				'success_page'              => array(
194
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
195
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
194
+					'name'    => _x('gp-receipt', 'Page slug', 'invoicing'),
195
+					'title'   => _x('Payment Confirmation', 'Page title', 'invoicing'),
196 196
 					'content' => '
197 197
 					<!-- wp:shortcode -->
198 198
 					[wpinv_receipt]
@@ -203,16 +203,16 @@  discard block
 block discarded – undo
203 203
 
204 204
 				// Failure page content.
205 205
 				'failure_page'              => array(
206
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
207
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
208
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
206
+					'name'    => _x('gp-transaction-failed', 'Page slug', 'invoicing'),
207
+					'title'   => _x('Transaction Failed', 'Page title', 'invoicing'),
208
+					'content' => __('Your transaction failed, please try again or contact site support.', 'invoicing'),
209 209
 					'parent'  => 'gp-checkout',
210 210
 				),
211 211
 
212 212
 				// Subscriptions history page.
213 213
 				'invoice_subscription_page' => array(
214
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
215
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
214
+					'name'    => _x('gp-subscriptions', 'Page slug', 'invoicing'),
215
+					'title'   => _x('My Subscriptions', 'Page title', 'invoicing'),
216 216
 					'content' => '
217 217
 					<!-- wp:shortcode -->
218 218
 					[wpinv_subscriptions]
@@ -232,8 +232,8 @@  discard block
 block discarded – undo
232 232
 	 */
233 233
 	public function create_pages() {
234 234
 
235
-		foreach ( self::get_pages() as $key => $page ) {
236
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
235
+		foreach (self::get_pages() as $key => $page) {
236
+			wpinv_create_page(esc_sql($page['name']), $key, $page['title'], $page['content'], $page['parent']);
237 237
 		}
238 238
 
239 239
 	}
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 			KEY customer_and_status (customer_id, status)
274 274
 		  ) $charset_collate;";
275 275
 
276
-		dbDelta( $sql );
276
+		dbDelta($sql);
277 277
 
278 278
 	}
279 279
 
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
 			KEY `key` (`key`)
325 325
 		  ) $charset_collate;";
326 326
 
327
-		dbDelta( $sql );
327
+		dbDelta($sql);
328 328
 
329 329
 	}
330 330
 
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 			KEY post_id (post_id)
362 362
 		  ) $charset_collate;";
363 363
 
364
-		dbDelta( $sql );
364
+		dbDelta($sql);
365 365
 
366 366
 	}
367 367
 
@@ -374,32 +374,32 @@  discard block
 block discarded – undo
374 374
 
375 375
 		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
376 376
 		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
377
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
377
+		$migrated            = $wpdb->get_col("SELECT post_id FROM $invoices_table");
378 378
 		$invoices            = array_unique(
379 379
 			get_posts(
380 380
 				array(
381
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
381
+					'post_type'      => array('wpi_invoice', 'wpi_quote'),
382 382
 					'posts_per_page' => -1,
383 383
 					'fields'         => 'ids',
384
-					'post_status'    => array_keys( get_post_stati() ),
384
+					'post_status'    => array_keys(get_post_stati()),
385 385
 					'exclude'        => (array) $migrated,
386 386
 				)
387 387
 			)
388 388
 		);
389 389
 
390 390
 		// Abort if we do not have any invoices.
391
-		if ( empty( $invoices ) ) {
391
+		if (empty($invoices)) {
392 392
 			return;
393 393
 		}
394 394
 
395 395
 		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
396 396
 
397 397
 		$invoice_rows = array();
398
-		foreach ( $invoices as $invoice ) {
398
+		foreach ($invoices as $invoice) {
399 399
 
400
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
400
+			$invoice = new WPInv_Legacy_Invoice($invoice);
401 401
 
402
-			if ( empty( $invoice->ID ) ) {
402
+			if (empty($invoice->ID)) {
403 403
 				return;
404 404
 			}
405 405
 
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
 				'post_id'            => $invoice->ID,
408 408
 				'number'             => $invoice->get_number(),
409 409
 				'key'                => $invoice->get_key(),
410
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
410
+				'type'               => str_replace('wpi_', '', $invoice->post_type),
411 411
 				'mode'               => $invoice->mode,
412 412
 				'user_ip'            => $invoice->get_ip(),
413 413
 				'first_name'         => $invoice->get_first_name(),
@@ -436,27 +436,27 @@  discard block
 block discarded – undo
436 436
 				'custom_meta'        => $invoice->payment_meta,
437 437
 			);
438 438
 
439
-			foreach ( $fields as $key => $val ) {
440
-				if ( is_null( $val ) ) {
439
+			foreach ($fields as $key => $val) {
440
+				if (is_null($val)) {
441 441
 					$val = '';
442 442
 				}
443
-				$val = maybe_serialize( $val );
444
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
443
+				$val = maybe_serialize($val);
444
+				$fields[$key] = $wpdb->prepare('%s', $val);
445 445
 			}
446 446
 
447
-			$fields = implode( ', ', $fields );
447
+			$fields = implode(', ', $fields);
448 448
 			$invoice_rows[] = "($fields)";
449 449
 
450 450
 			$item_rows    = array();
451 451
 			$item_columns = array();
452
-			foreach ( $invoice->get_cart_details() as $details ) {
452
+			foreach ($invoice->get_cart_details() as $details) {
453 453
 				$fields = array(
454 454
 					'post_id'          => $invoice->ID,
455 455
 					'item_id'          => $details['id'],
456 456
 					'item_name'        => $details['name'],
457
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
457
+					'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
458 458
 					'vat_rate'         => $details['vat_rate'],
459
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
459
+					'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
460 460
 					'tax'              => $details['tax'],
461 461
 					'item_price'       => $details['item_price'],
462 462
 					'custom_price'     => $details['custom_price'],
@@ -468,31 +468,31 @@  discard block
 block discarded – undo
468 468
 					'fees'             => $details['fees'],
469 469
 				);
470 470
 
471
-				$item_columns = array_keys( $fields );
471
+				$item_columns = array_keys($fields);
472 472
 
473
-				foreach ( $fields as $key => $val ) {
474
-					if ( is_null( $val ) ) {
473
+				foreach ($fields as $key => $val) {
474
+					if (is_null($val)) {
475 475
 						$val = '';
476 476
 					}
477
-					$val = maybe_serialize( $val );
478
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
477
+					$val = maybe_serialize($val);
478
+					$fields[$key] = $wpdb->prepare('%s', $val);
479 479
 				}
480 480
 
481
-				$fields = implode( ', ', $fields );
481
+				$fields = implode(', ', $fields);
482 482
 				$item_rows[] = "($fields)";
483 483
 			}
484 484
 
485
-			$item_rows    = implode( ', ', $item_rows );
486
-			$item_columns = implode( ', ', $item_columns );
487
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
485
+			$item_rows    = implode(', ', $item_rows);
486
+			$item_columns = implode(', ', $item_columns);
487
+			$wpdb->query("INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows");
488 488
 		}
489 489
 
490
-		if ( empty( $invoice_rows ) ) {
490
+		if (empty($invoice_rows)) {
491 491
 			return;
492 492
 		}
493 493
 
494
-		$invoice_rows = implode( ', ', $invoice_rows );
495
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
494
+		$invoice_rows = implode(', ', $invoice_rows);
495
+		$wpdb->query("INSERT INTO $invoices_table VALUES $invoice_rows");
496 496
 
497 497
 	}
498 498
 
@@ -503,12 +503,12 @@  discard block
 block discarded – undo
503 503
 	public static function rename_gateways_label() {
504 504
 		global $wpdb;
505 505
 
506
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
506
+		foreach (array_keys(wpinv_get_payment_gateways()) as $gateway) {
507 507
 
508 508
 			$wpdb->update(
509 509
 				$wpdb->prefix . 'getpaid_invoices',
510
-				array( 'gateway' => $gateway ),
511
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
510
+				array('gateway' => $gateway),
511
+				array('gateway' => wpinv_get_gateway_admin_label($gateway)),
512 512
 				'%s',
513 513
 				'%s'
514 514
 			);
Please login to merge, or discard this patch.
includes/reports/class-getpaid-reports-export.php 2 patches
Indentation   +188 added lines, -188 removed lines patch added patch discarded remove patch
@@ -12,47 +12,47 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Reports_Export {
14 14
 
15
-	/**
16
-	 * Displays the reports tab.
17
-	 *
18
-	 */
19
-	public function display() {
20
-
21
-		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
24
-		}
25
-		$this->display_subscription_export();
26
-		echo '</div>';
27
-
28
-	}
29
-
30
-	/**
31
-	 * Retrieves the download url.
32
-	 *
33
-	 */
34
-	public function get_download_url( $post_type ) {
35
-
36
-		return wp_nonce_url(
37
-			add_query_arg(
38
-				array(
39
-					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
41
-				)
42
-			),
43
-			'getpaid-nonce',
44
-			'getpaid-nonce'
45
-		);
46
-
47
-	}
48
-
49
-	/**
50
-	 * Displays a single post type export card.
51
-	 *
52
-	 */
53
-	public function display_post_type_export( $post_type ) {
54
-
55
-		?>
15
+    /**
16
+     * Displays the reports tab.
17
+     *
18
+     */
19
+    public function display() {
20
+
21
+        echo "<div class='row mt-4' style='max-width: 920px;' >";
22
+        foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
+            $this->display_post_type_export( $post_type );
24
+        }
25
+        $this->display_subscription_export();
26
+        echo '</div>';
27
+
28
+    }
29
+
30
+    /**
31
+     * Retrieves the download url.
32
+     *
33
+     */
34
+    public function get_download_url( $post_type ) {
35
+
36
+        return wp_nonce_url(
37
+            add_query_arg(
38
+                array(
39
+                    'getpaid-admin-action' => 'export_invoices',
40
+                    'post_type'            => urlencode( $post_type ),
41
+                )
42
+            ),
43
+            'getpaid-nonce',
44
+            'getpaid-nonce'
45
+        );
46
+
47
+    }
48
+
49
+    /**
50
+     * Displays a single post type export card.
51
+     *
52
+     */
53
+    public function display_post_type_export( $post_type ) {
54
+
55
+        ?>
56 56
 
57 57
 		<div class="col-12 col-md-6">
58 58
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -60,11 +60,11 @@  discard block
 block discarded – undo
60 60
 				<div class="card-header">
61 61
 					<strong>
62 62
 						<?php
63
-							printf(
64
-								esc_html__( 'Export %s', 'invoicing' ),
65
-								esc_html( getpaid_get_post_type_label( $post_type ) )
66
-							);
67
-						?>
63
+                            printf(
64
+                                esc_html__( 'Export %s', 'invoicing' ),
65
+                                esc_html( getpaid_get_post_type_label( $post_type ) )
66
+                            );
67
+                        ?>
68 68
 					</strong>
69 69
 				</div>
70 70
 
@@ -73,12 +73,12 @@  discard block
 block discarded – undo
73 73
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
74 74
 
75 75
 						<?php
76
-							$this->generate_from_date( $post_type );
77
-							$this->generate_to_date( $post_type );
78
-							$this->generate_post_status_select( $post_type );
79
-							$this->generate_file_type_select( $post_type );
80
-							submit_button( __( 'Download', 'invoicing' ) );
81
-						?>
76
+                            $this->generate_from_date( $post_type );
77
+                            $this->generate_to_date( $post_type );
78
+                            $this->generate_post_status_select( $post_type );
79
+                            $this->generate_file_type_select( $post_type );
80
+                            submit_button( __( 'Download', 'invoicing' ) );
81
+                        ?>
82 82
 
83 83
 					</form>
84 84
 
@@ -89,135 +89,135 @@  discard block
 block discarded – undo
89 89
 
90 90
 		<?php
91 91
 
92
-	}
93
-
94
-	/**
95
-	 * Generates the from date input field.
96
-	 *
97
-	 */
98
-	public function generate_from_date( $post_type ) {
99
-
100
-		aui()->input(
101
-			array(
102
-				'type'             => 'datepicker',
103
-				'id'               => esc_attr( "$post_type-from_date" ),
104
-				'name'             => 'from_date',
105
-				'label'            => __( 'From Date', 'invoicing' ),
106
-				'label_type'       => 'vertical',
107
-				'placeholder'      => 'YYYY-MM-DD',
108
-				'extra_attributes' => array(
109
-					'data-enable-time' => 'false',
110
-					'data-allow-input' => 'true',
111
-				),
112
-			),
113
-			true
114
-		);
115
-
116
-	}
117
-
118
-	/**
119
-	 * Generates the to date input field.
120
-	 *
121
-	 */
122
-	public function generate_to_date( $post_type ) {
123
-
124
-		aui()->input(
125
-			array(
126
-				'type'             => 'datepicker',
127
-				'id'               => esc_attr( "$post_type-to_date" ),
128
-				'name'             => 'to_date',
129
-				'label'            => __( 'To Date', 'invoicing' ),
130
-				'label_type'       => 'vertical',
131
-				'placeholder'      => 'YYYY-MM-DD',
132
-				'extra_attributes' => array(
133
-					'data-enable-time' => 'false',
134
-					'data-allow-input' => 'true',
135
-				),
136
-			),
137
-			true
138
-		);
139
-	}
140
-
141
-	/**
142
-	 * Generates the to post status select field.
143
-	 *
144
-	 */
145
-	public function generate_post_status_select( $post_type ) {
146
-
147
-		if ( 'subscriptions' === $post_type ) {
148
-			$options = getpaid_get_subscription_statuses();
149
-		} else {
150
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
151
-		}
152
-
153
-		aui()->select(
154
-			array(
155
-				'name'        => 'status',
156
-				'id'          => esc_attr( "$post_type-status" ),
157
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
158
-				'label'       => __( 'Status', 'invoicing' ),
159
-				'label_type'  => 'vertical',
160
-				'label_class' => 'd-block',
161
-				'options'     => $options,
162
-			),
163
-			true
164
-		);
165
-
166
-	}
167
-
168
-	/**
169
-	 * Generates the to file type select field.
170
-	 *
171
-	 */
172
-	public function generate_file_type_select( $post_type ) {
173
-
174
-		aui()->select(
175
-			array(
176
-				'name'        => 'file_type',
177
-				'id'          => esc_attr( "$post_type-file_type" ),
178
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
179
-				'label'       => __( 'Export File', 'invoicing' ),
180
-				'label_type'  => 'vertical',
181
-				'label_class' => 'd-block',
182
-				'value'       => 'csv',
183
-				'options'     => array(
184
-					'csv'  => __( 'CSV', 'invoicing' ),
185
-					'xml'  => __( 'XML', 'invoicing' ),
186
-					'json' => __( 'JSON', 'invoicing' ),
187
-				),
188
-			),
189
-			true
190
-		);
191
-
192
-	}
193
-
194
-	/**
195
-	 * Displays a field's markup.
196
-	 *
197
-	 */
198
-	public function display_markup( $markup ) {
199
-
200
-		echo wp_kses(
201
-			str_replace(
202
-				array(
203
-					'form-control',
204
-					'custom-select',
205
-				),
206
-				'regular-text',
207
-				$markup
208
-			),
209
-			getpaid_allowed_html()
210
-		);
211
-
212
-	}
213
-
214
-	/**
215
-	 * Displays a subscription export card.
216
-	 *
217
-	 */
218
-	public function display_subscription_export() {
219
-
220
-		?>
92
+    }
93
+
94
+    /**
95
+     * Generates the from date input field.
96
+     *
97
+     */
98
+    public function generate_from_date( $post_type ) {
99
+
100
+        aui()->input(
101
+            array(
102
+                'type'             => 'datepicker',
103
+                'id'               => esc_attr( "$post_type-from_date" ),
104
+                'name'             => 'from_date',
105
+                'label'            => __( 'From Date', 'invoicing' ),
106
+                'label_type'       => 'vertical',
107
+                'placeholder'      => 'YYYY-MM-DD',
108
+                'extra_attributes' => array(
109
+                    'data-enable-time' => 'false',
110
+                    'data-allow-input' => 'true',
111
+                ),
112
+            ),
113
+            true
114
+        );
115
+
116
+    }
117
+
118
+    /**
119
+     * Generates the to date input field.
120
+     *
121
+     */
122
+    public function generate_to_date( $post_type ) {
123
+
124
+        aui()->input(
125
+            array(
126
+                'type'             => 'datepicker',
127
+                'id'               => esc_attr( "$post_type-to_date" ),
128
+                'name'             => 'to_date',
129
+                'label'            => __( 'To Date', 'invoicing' ),
130
+                'label_type'       => 'vertical',
131
+                'placeholder'      => 'YYYY-MM-DD',
132
+                'extra_attributes' => array(
133
+                    'data-enable-time' => 'false',
134
+                    'data-allow-input' => 'true',
135
+                ),
136
+            ),
137
+            true
138
+        );
139
+    }
140
+
141
+    /**
142
+     * Generates the to post status select field.
143
+     *
144
+     */
145
+    public function generate_post_status_select( $post_type ) {
146
+
147
+        if ( 'subscriptions' === $post_type ) {
148
+            $options = getpaid_get_subscription_statuses();
149
+        } else {
150
+            $options = wpinv_get_invoice_statuses( true, false, $post_type );
151
+        }
152
+
153
+        aui()->select(
154
+            array(
155
+                'name'        => 'status',
156
+                'id'          => esc_attr( "$post_type-status" ),
157
+                'placeholder' => __( 'All Statuses', 'invoicing' ),
158
+                'label'       => __( 'Status', 'invoicing' ),
159
+                'label_type'  => 'vertical',
160
+                'label_class' => 'd-block',
161
+                'options'     => $options,
162
+            ),
163
+            true
164
+        );
165
+
166
+    }
167
+
168
+    /**
169
+     * Generates the to file type select field.
170
+     *
171
+     */
172
+    public function generate_file_type_select( $post_type ) {
173
+
174
+        aui()->select(
175
+            array(
176
+                'name'        => 'file_type',
177
+                'id'          => esc_attr( "$post_type-file_type" ),
178
+                'placeholder' => __( 'Select File Type', 'invoicing' ),
179
+                'label'       => __( 'Export File', 'invoicing' ),
180
+                'label_type'  => 'vertical',
181
+                'label_class' => 'd-block',
182
+                'value'       => 'csv',
183
+                'options'     => array(
184
+                    'csv'  => __( 'CSV', 'invoicing' ),
185
+                    'xml'  => __( 'XML', 'invoicing' ),
186
+                    'json' => __( 'JSON', 'invoicing' ),
187
+                ),
188
+            ),
189
+            true
190
+        );
191
+
192
+    }
193
+
194
+    /**
195
+     * Displays a field's markup.
196
+     *
197
+     */
198
+    public function display_markup( $markup ) {
199
+
200
+        echo wp_kses(
201
+            str_replace(
202
+                array(
203
+                    'form-control',
204
+                    'custom-select',
205
+                ),
206
+                'regular-text',
207
+                $markup
208
+            ),
209
+            getpaid_allowed_html()
210
+        );
211
+
212
+    }
213
+
214
+    /**
215
+     * Displays a subscription export card.
216
+     *
217
+     */
218
+    public function display_subscription_export() {
219
+
220
+        ?>
221 221
 
222 222
 		<div class="col-12 col-md-6">
223 223
 			<div class="card m-0 p-0" style="max-width:100%">
@@ -233,12 +233,12 @@  discard block
 block discarded – undo
233 233
 					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
234 234
 
235 235
 						<?php
236
-							$this->generate_from_date( 'subscriptions' );
237
-							$this->generate_to_date( 'subscriptions' );
238
-							$this->generate_post_status_select( 'subscriptions' );
239
-							$this->generate_file_type_select( 'subscriptions' );
240
-							submit_button( __( 'Download', 'invoicing' ) );
241
-						?>
236
+                            $this->generate_from_date( 'subscriptions' );
237
+                            $this->generate_to_date( 'subscriptions' );
238
+                            $this->generate_post_status_select( 'subscriptions' );
239
+                            $this->generate_file_type_select( 'subscriptions' );
240
+                            submit_button( __( 'Download', 'invoicing' ) );
241
+                        ?>
242 242
 
243 243
 					</form>
244 244
 
@@ -249,6 +249,6 @@  discard block
 block discarded – undo
249 249
 
250 250
 		<?php
251 251
 
252
-	}
252
+    }
253 253
 
254 254
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Reports_Export Class.
@@ -19,8 +19,8 @@  discard block
 block discarded – undo
19 19
 	public function display() {
20 20
 
21 21
 		echo "<div class='row mt-4' style='max-width: 920px;' >";
22
-		foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) {
23
-			$this->display_post_type_export( $post_type );
22
+		foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) {
23
+			$this->display_post_type_export($post_type);
24 24
 		}
25 25
 		$this->display_subscription_export();
26 26
 		echo '</div>';
@@ -31,13 +31,13 @@  discard block
 block discarded – undo
31 31
 	 * Retrieves the download url.
32 32
 	 *
33 33
 	 */
34
-	public function get_download_url( $post_type ) {
34
+	public function get_download_url($post_type) {
35 35
 
36 36
 		return wp_nonce_url(
37 37
 			add_query_arg(
38 38
 				array(
39 39
 					'getpaid-admin-action' => 'export_invoices',
40
-					'post_type'            => urlencode( $post_type ),
40
+					'post_type'            => urlencode($post_type),
41 41
 				)
42 42
 			),
43 43
 			'getpaid-nonce',
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 	 * Displays a single post type export card.
51 51
 	 *
52 52
 	 */
53
-	public function display_post_type_export( $post_type ) {
53
+	public function display_post_type_export($post_type) {
54 54
 
55 55
 		?>
56 56
 
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 					<strong>
62 62
 						<?php
63 63
 							printf(
64
-								esc_html__( 'Export %s', 'invoicing' ),
65
-								esc_html( getpaid_get_post_type_label( $post_type ) )
64
+								esc_html__('Export %s', 'invoicing'),
65
+								esc_html(getpaid_get_post_type_label($post_type))
66 66
 							);
67 67
 						?>
68 68
 					</strong>
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 
71 71
 				<div class="card-body">
72 72
 
73
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>">
73
+					<form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>">
74 74
 
75 75
 						<?php
76
-							$this->generate_from_date( $post_type );
77
-							$this->generate_to_date( $post_type );
78
-							$this->generate_post_status_select( $post_type );
79
-							$this->generate_file_type_select( $post_type );
80
-							submit_button( __( 'Download', 'invoicing' ) );
76
+							$this->generate_from_date($post_type);
77
+							$this->generate_to_date($post_type);
78
+							$this->generate_post_status_select($post_type);
79
+							$this->generate_file_type_select($post_type);
80
+							submit_button(__('Download', 'invoicing'));
81 81
 						?>
82 82
 
83 83
 					</form>
@@ -95,14 +95,14 @@  discard block
 block discarded – undo
95 95
 	 * Generates the from date input field.
96 96
 	 *
97 97
 	 */
98
-	public function generate_from_date( $post_type ) {
98
+	public function generate_from_date($post_type) {
99 99
 
100 100
 		aui()->input(
101 101
 			array(
102 102
 				'type'             => 'datepicker',
103
-				'id'               => esc_attr( "$post_type-from_date" ),
103
+				'id'               => esc_attr("$post_type-from_date"),
104 104
 				'name'             => 'from_date',
105
-				'label'            => __( 'From Date', 'invoicing' ),
105
+				'label'            => __('From Date', 'invoicing'),
106 106
 				'label_type'       => 'vertical',
107 107
 				'placeholder'      => 'YYYY-MM-DD',
108 108
 				'extra_attributes' => array(
@@ -119,14 +119,14 @@  discard block
 block discarded – undo
119 119
 	 * Generates the to date input field.
120 120
 	 *
121 121
 	 */
122
-	public function generate_to_date( $post_type ) {
122
+	public function generate_to_date($post_type) {
123 123
 
124 124
 		aui()->input(
125 125
 			array(
126 126
 				'type'             => 'datepicker',
127
-				'id'               => esc_attr( "$post_type-to_date" ),
127
+				'id'               => esc_attr("$post_type-to_date"),
128 128
 				'name'             => 'to_date',
129
-				'label'            => __( 'To Date', 'invoicing' ),
129
+				'label'            => __('To Date', 'invoicing'),
130 130
 				'label_type'       => 'vertical',
131 131
 				'placeholder'      => 'YYYY-MM-DD',
132 132
 				'extra_attributes' => array(
@@ -142,20 +142,20 @@  discard block
 block discarded – undo
142 142
 	 * Generates the to post status select field.
143 143
 	 *
144 144
 	 */
145
-	public function generate_post_status_select( $post_type ) {
145
+	public function generate_post_status_select($post_type) {
146 146
 
147
-		if ( 'subscriptions' === $post_type ) {
147
+		if ('subscriptions' === $post_type) {
148 148
 			$options = getpaid_get_subscription_statuses();
149 149
 		} else {
150
-			$options = wpinv_get_invoice_statuses( true, false, $post_type );
150
+			$options = wpinv_get_invoice_statuses(true, false, $post_type);
151 151
 		}
152 152
 
153 153
 		aui()->select(
154 154
 			array(
155 155
 				'name'        => 'status',
156
-				'id'          => esc_attr( "$post_type-status" ),
157
-				'placeholder' => __( 'All Statuses', 'invoicing' ),
158
-				'label'       => __( 'Status', 'invoicing' ),
156
+				'id'          => esc_attr("$post_type-status"),
157
+				'placeholder' => __('All Statuses', 'invoicing'),
158
+				'label'       => __('Status', 'invoicing'),
159 159
 				'label_type'  => 'vertical',
160 160
 				'label_class' => 'd-block',
161 161
 				'options'     => $options,
@@ -169,21 +169,21 @@  discard block
 block discarded – undo
169 169
 	 * Generates the to file type select field.
170 170
 	 *
171 171
 	 */
172
-	public function generate_file_type_select( $post_type ) {
172
+	public function generate_file_type_select($post_type) {
173 173
 
174 174
 		aui()->select(
175 175
 			array(
176 176
 				'name'        => 'file_type',
177
-				'id'          => esc_attr( "$post_type-file_type" ),
178
-				'placeholder' => __( 'Select File Type', 'invoicing' ),
179
-				'label'       => __( 'Export File', 'invoicing' ),
177
+				'id'          => esc_attr("$post_type-file_type"),
178
+				'placeholder' => __('Select File Type', 'invoicing'),
179
+				'label'       => __('Export File', 'invoicing'),
180 180
 				'label_type'  => 'vertical',
181 181
 				'label_class' => 'd-block',
182 182
 				'value'       => 'csv',
183 183
 				'options'     => array(
184
-					'csv'  => __( 'CSV', 'invoicing' ),
185
-					'xml'  => __( 'XML', 'invoicing' ),
186
-					'json' => __( 'JSON', 'invoicing' ),
184
+					'csv'  => __('CSV', 'invoicing'),
185
+					'xml'  => __('XML', 'invoicing'),
186
+					'json' => __('JSON', 'invoicing'),
187 187
 				),
188 188
 			),
189 189
 			true
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 	 * Displays a field's markup.
196 196
 	 *
197 197
 	 */
198
-	public function display_markup( $markup ) {
198
+	public function display_markup($markup) {
199 199
 
200 200
 		echo wp_kses(
201 201
 			str_replace(
@@ -224,20 +224,20 @@  discard block
 block discarded – undo
224 224
 
225 225
 				<div class="card-header">
226 226
 					<strong>
227
-						<?php esc_html_e( 'Export Subscriptions', 'invoicing' ); ?>
227
+						<?php esc_html_e('Export Subscriptions', 'invoicing'); ?>
228 228
 					</strong>
229 229
 				</div>
230 230
 
231 231
 				<div class="card-body">
232 232
 
233
-					<form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>">
233
+					<form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>">
234 234
 
235 235
 						<?php
236
-							$this->generate_from_date( 'subscriptions' );
237
-							$this->generate_to_date( 'subscriptions' );
238
-							$this->generate_post_status_select( 'subscriptions' );
239
-							$this->generate_file_type_select( 'subscriptions' );
240
-							submit_button( __( 'Download', 'invoicing' ) );
236
+							$this->generate_from_date('subscriptions');
237
+							$this->generate_to_date('subscriptions');
238
+							$this->generate_post_status_select('subscriptions');
239
+							$this->generate_file_type_select('subscriptions');
240
+							submit_button(__('Download', 'invoicing'));
241 241
 						?>
242 242
 
243 243
 					</form>
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 2 patches
Spacing   +214 added lines, -214 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * Bail if we are not in WP.
14 14
  */
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if (!defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
19 19
 /**
20 20
  * Only add if the class does not already exist.
21 21
  */
22
-if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
22
+if (!class_exists('WP_Font_Awesome_Settings')) {
23 23
 
24 24
 	/**
25 25
 	 * A Class to be able to change settings for Font Awesome.
@@ -92,18 +92,18 @@  discard block
 block discarded – undo
92 92
 		 * @return WP_Font_Awesome_Settings - Main instance.
93 93
 		 */
94 94
 		public static function instance() {
95
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
95
+			if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) {
96 96
 				self::$instance = new WP_Font_Awesome_Settings;
97 97
 
98
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
98
+				add_action('init', array(self::$instance, 'init')); // set settings
99 99
 
100
-				if ( is_admin() ) {
101
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
102
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
103
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
100
+				if (is_admin()) {
101
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
102
+					add_action('admin_init', array(self::$instance, 'register_settings'));
103
+					add_action('admin_notices', array(self::$instance, 'admin_notices'));
104 104
 				}
105 105
 
106
-				do_action( 'wp_font_awesome_settings_loaded' );
106
+				do_action('wp_font_awesome_settings_loaded');
107 107
 			}
108 108
 
109 109
 			return self::$instance;
@@ -116,40 +116,40 @@  discard block
 block discarded – undo
116 116
 		 */
117 117
 		public function init() {
118 118
 			// Download fontawesome locally.
119
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
120
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
119
+			add_action('add_option_wp-font-awesome-settings', array($this, 'add_option_wp_font_awesome_settings'), 10, 2);
120
+			add_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2);
121 121
 
122 122
 			$this->settings = $this->get_settings();
123 123
 
124 124
 			// check if the official plugin is active and use that instead if so.
125
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
125
+			if (!defined('FONTAWESOME_PLUGIN_FILE')) {
126 126
 
127
-				if ( $this->settings['type'] == 'CSS' ) {
127
+				if ($this->settings['type'] == 'CSS') {
128 128
 
129
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
130
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
129
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
130
+						add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000);
131 131
 					}
132 132
 
133
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
134
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
135
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
133
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
134
+						add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000);
135
+						add_filter('block_editor_settings_all', array($this, 'enqueue_editor_styles'), 10, 2);
136 136
 					}
137 137
 
138 138
 				} else {
139 139
 
140
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
141
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
140
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
141
+						add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000);
142 142
 					}
143 143
 
144
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
145
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
146
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
144
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
145
+						add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000);
146
+						add_filter('block_editor_settings_all', array($this, 'enqueue_editor_scripts'), 10, 2);
147 147
 					}
148 148
 				}
149 149
 
150 150
 				// remove font awesome if set to do so
151
-				if ( $this->settings['dequeue'] == '1' ) {
152
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
151
+				if ($this->settings['dequeue'] == '1') {
152
+					add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3);
153 153
 				}
154 154
 			}
155 155
 
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 		 *
164 164
 		 * @return array
165 165
 		 */
166
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
166
+		public function enqueue_editor_styles($editor_settings, $block_editor_context) {
167 167
 
168
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
168
+			if (!empty($editor_settings['__unstableResolvedAssets']['styles'])) {
169 169
 				$url = $this->get_url();
170 170
 				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
171 171
 			}
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 		 *
182 182
 		 * @return array
183 183
 		 */
184
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
184
+		public function enqueue_editor_scripts($editor_settings, $block_editor_context) {
185 185
 
186 186
 			$url = $this->get_url();
187 187
 			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
@@ -195,22 +195,22 @@  discard block
 block discarded – undo
195 195
 		public function enqueue_style() {
196 196
 			// build url
197 197
 			$url = $this->get_url();
198
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
198
+			$version = !empty($this->settings['local']) && empty($this->settings['pro']) ? strip_tags($this->settings['local_version']) : null;
199 199
 
200
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
201
-			wp_register_style( 'font-awesome', $url, array(), $version );
202
-			wp_enqueue_style( 'font-awesome' );
200
+			wp_deregister_style('font-awesome'); // deregister in case its already there
201
+			wp_register_style('font-awesome', $url, array(), $version);
202
+			wp_enqueue_style('font-awesome');
203 203
 
204 204
 			// RTL language support CSS.
205
-			if ( is_rtl() ) {
206
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
205
+			if (is_rtl()) {
206
+				wp_add_inline_style('font-awesome', $this->rtl_inline_css());
207 207
 			}
208 208
 
209
-			if ( $this->settings['shims'] ) {
210
-				$url = $this->get_url( true );
211
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
212
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
213
-				wp_enqueue_style( 'font-awesome-shims' );
209
+			if ($this->settings['shims']) {
210
+				$url = $this->get_url(true);
211
+				wp_deregister_style('font-awesome-shims'); // deregister in case its already there
212
+				wp_register_style('font-awesome-shims', $url, array(), $version);
213
+				wp_enqueue_style('font-awesome-shims');
214 214
 			}
215 215
 		}
216 216
 
@@ -222,15 +222,15 @@  discard block
 block discarded – undo
222 222
 			$url = $this->get_url();
223 223
 
224 224
 			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
225
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
226
-			wp_register_script( 'font-awesome', $url, array(), null );
227
-			wp_enqueue_script( 'font-awesome' );
225
+			call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there
226
+			wp_register_script('font-awesome', $url, array(), null);
227
+			wp_enqueue_script('font-awesome');
228 228
 
229
-			if ( $this->settings['shims'] ) {
230
-				$url = $this->get_url( true );
231
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
232
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
233
-				wp_enqueue_script( 'font-awesome-shims' );
229
+			if ($this->settings['shims']) {
230
+				$url = $this->get_url(true);
231
+				call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there
232
+				wp_register_script('font-awesome-shims', $url, array(), null);
233
+				wp_enqueue_script('font-awesome-shims');
234 234
 			}
235 235
 		}
236 236
 
@@ -242,16 +242,16 @@  discard block
 block discarded – undo
242 242
 		 *
243 243
 		 * @return string The url to the file.
244 244
 		 */
245
-		public function get_url( $shims = false, $local = true ) {
245
+		public function get_url($shims = false, $local = true) {
246 246
 			$script  = $shims ? 'v4-shims' : 'all';
247 247
 			$sub     = $this->settings['pro'] ? 'pro' : 'use';
248 248
 			$type    = $this->settings['type'];
249 249
 			$version = $this->settings['version'];
250
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
250
+			$kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : '';
251 251
 			$url     = '';
252 252
 
253
-			if ( $type == 'KIT' && $kit_url ) {
254
-				if ( $shims ) {
253
+			if ($type == 'KIT' && $kit_url) {
254
+				if ($shims) {
255 255
 					// if its a kit then we don't add shims here
256 256
 					return '';
257 257
 				}
@@ -260,13 +260,13 @@  discard block
 block discarded – undo
260 260
 			} else {
261 261
 				$v = '';
262 262
 				// Check and load locally.
263
-				if ( $local && $this->has_local() ) {
263
+				if ($local && $this->has_local()) {
264 264
 					$script .= ".min";
265
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
265
+					$v .= '&ver=' . strip_tags($this->settings['local_version']);
266 266
 					$url .= $this->get_fonts_url(); // Local fonts url.
267 267
 				} else {
268 268
 					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
269
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
269
+					$url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
270 270
 				}
271 271
 				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
272 272
 				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
@@ -287,16 +287,16 @@  discard block
 block discarded – undo
287 287
 		 *
288 288
 		 * @return string The filtered url.
289 289
 		 */
290
-		public function remove_font_awesome( $url, $original_url, $_context ) {
290
+		public function remove_font_awesome($url, $original_url, $_context) {
291 291
 
292
-			if ( $_context == 'display'
293
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
294
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
292
+			if ($_context == 'display'
293
+			     && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false)
294
+			     && (strstr($url, ".js") !== false || strstr($url, ".css") !== false)
295 295
 			) {// it's a font-awesome-url (probably)
296 296
 
297
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
298
-					if ( $this->settings['type'] == 'JS' ) {
299
-						if ( $this->settings['js-pseudo'] ) {
297
+				if (strstr($url, "wpfas=true") !== false) {
298
+					if ($this->settings['type'] == 'JS') {
299
+						if ($this->settings['js-pseudo']) {
300 300
 							$url .= "' data-search-pseudo-elements defer='defer";
301 301
 						} else {
302 302
 							$url .= "' defer='defer";
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 		 * Register the database settings with WordPress.
316 316
 		 */
317 317
 		public function register_settings() {
318
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
318
+			register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings');
319 319
 		}
320 320
 
321 321
 		/**
@@ -324,10 +324,10 @@  discard block
 block discarded – undo
324 324
 		 */
325 325
 		public function menu_item() {
326 326
 			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
327
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
327
+			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
328 328
 				$this,
329 329
 				'settings_page'
330
-			) );
330
+			));
331 331
 		}
332 332
 
333 333
 		/**
@@ -336,7 +336,7 @@  discard block
 block discarded – undo
336 336
 		 * @return array The array of settings.
337 337
 		 */
338 338
 		public function get_settings() {
339
-			$db_settings = get_option( 'wp-font-awesome-settings' );
339
+			$db_settings = get_option('wp-font-awesome-settings');
340 340
 
341 341
 			$defaults = array(
342 342
 				'type'      => 'CSS', // type to use, CSS or JS or KIT
@@ -351,30 +351,30 @@  discard block
 block discarded – undo
351 351
 				'kit-url'   => '', // the kit url
352 352
 			);
353 353
 
354
-			$settings = wp_parse_args( $db_settings, $defaults );
354
+			$settings = wp_parse_args($db_settings, $defaults);
355 355
 
356 356
 			/**
357 357
 			 * Filter the Font Awesome settings.
358 358
 			 *
359 359
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
360 360
 			 */
361
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
361
+			return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults);
362 362
 		}
363 363
 
364 364
 		/**
365 365
 		 * The settings page html output.
366 366
 		 */
367 367
 		public function settings_page() {
368
-			if ( ! current_user_can( 'manage_options' ) ) {
369
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
368
+			if (!current_user_can('manage_options')) {
369
+				wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings'));
370 370
 			}
371 371
 
372 372
 			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
373
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
374
-				$this->get_latest_version( $force_api = true );
373
+			if (isset($_REQUEST['force-version-check'])) {
374
+				$this->get_latest_version($force_api = true);
375 375
 			}
376 376
 
377
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
377
+			if (!defined('FONTAWESOME_PLUGIN_FILE')) {
378 378
 				?>
379 379
                 <style>
380 380
                     .wpfas-kit-show {
@@ -401,42 +401,42 @@  discard block
 block discarded – undo
401 401
                     <h1><?php echo $this->name; ?></h1>
402 402
                     <form method="post" action="options.php" class="fas-settings-form">
403 403
 						<?php
404
-						settings_fields( 'wp-font-awesome-settings' );
405
-						do_settings_sections( 'wp-font-awesome-settings' );
404
+						settings_fields('wp-font-awesome-settings');
405
+						do_settings_sections('wp-font-awesome-settings');
406 406
 						$table_class = '';
407
-						if ( $this->settings['type'] ) {
408
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
407
+						if ($this->settings['type']) {
408
+							$table_class .= 'wpfas-' . sanitize_html_class(strtolower($this->settings['type'])) . '-set';
409 409
 						}
410
-						if ( ! empty( $this->settings['pro'] ) ) {
410
+						if (!empty($this->settings['pro'])) {
411 411
 							$table_class .= ' wpfas-has-pro';
412 412
 						}
413 413
 						?>
414
-						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
415
-							<?php if ( $this->has_local() ) { ?>
416
-							<div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'font-awesome-settings' ); ?></strong></p></div>
414
+						<?php if ($this->settings['type'] != 'KIT' && !empty($this->settings['local']) && empty($this->settings['pro'])) { ?>
415
+							<?php if ($this->has_local()) { ?>
416
+							<div class="notice notice-info"><p><strong><?php _e('Font Awesome fonts are loading locally.', 'font-awesome-settings'); ?></strong></p></div>
417 417
 							<?php } else { ?>
418
-							<div class="notice notice-error"><p><strong><?php _e( 'Font Awesome fonts are not loading locally!', 'font-awesome-settings' ); ?></strong></p></div>
418
+							<div class="notice notice-error"><p><strong><?php _e('Font Awesome fonts are not loading locally!', 'font-awesome-settings'); ?></strong></p></div>
419 419
 							<?php } ?>
420 420
 						<?php } ?>
421
-                        <table class="form-table wpfas-table-settings <?php echo esc_attr( $table_class ); ?>">
421
+                        <table class="form-table wpfas-table-settings <?php echo esc_attr($table_class); ?>">
422 422
                             <tr valign="top">
423
-                                <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th>
423
+                                <th scope="row"><label for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th>
424 424
                                 <td>
425 425
                                     <select name="wp-font-awesome-settings[type]" id="wpfas-type" onchange="if(this.value=='KIT'){jQuery('.wpfas-table-settings').addClass('wpfas-kit-set');}else{jQuery('.wpfas-table-settings').removeClass('wpfas-kit-set');}">
426
-                                        <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option>
427
-                                        <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option>
428
-                                        <option value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'font-awesome-settings' ); ?></option>
426
+                                        <option value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option>
427
+                                        <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option>
428
+                                        <option value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'font-awesome-settings'); ?></option>
429 429
                                     </select>
430 430
                                 </td>
431 431
                             </tr>
432 432
 
433 433
                             <tr valign="top" class="wpfas-kit-show">
434
-                                <th scope="row"><label for="wpfas-kit-url"><?php _e( 'Kit URL', 'font-awesome-settings' ); ?></label></th>
434
+                                <th scope="row"><label for="wpfas-kit-url"><?php _e('Kit URL', 'font-awesome-settings'); ?></label></th>
435 435
                                 <td>
436
-                                    <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
436
+                                    <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr($this->settings['kit-url']); ?>" placeholder="<?php echo 'https://kit.font'; echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
437 437
                                     <span><?php
438 438
 										echo sprintf(
439
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
439
+											__('Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings'),
440 440
 											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
441 441
 											'</a>'
442 442
 										);
@@ -445,44 +445,44 @@  discard block
 block discarded – undo
445 445
                             </tr>
446 446
 
447 447
                             <tr valign="top" class="wpfas-kit-hide">
448
-                                <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th>
448
+                                <th scope="row"><label for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th>
449 449
                                 <td>
450 450
                                     <select name="wp-font-awesome-settings[version]" id="wpfas-version">
451
-                                        <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?></option>
452
-                                        <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>>6.1.0</option>
453
-                                        <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>>6.0.0</option>
454
-                                        <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>>5.15.4</option>
455
-                                        <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>5.6.0</option>
456
-                                        <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option>
457
-                                        <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option>
458
-                                        <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option>
459
-                                        <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option>
460
-                                        <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option>
461
-                                        <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option>
451
+                                        <option value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?></option>
452
+                                        <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>>6.1.0</option>
453
+                                        <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>>6.0.0</option>
454
+                                        <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>>5.15.4</option>
455
+                                        <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>>5.6.0</option>
456
+                                        <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>5.5.0</option>
457
+                                        <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>5.4.0</option>
458
+                                        <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>5.3.0</option>
459
+                                        <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>5.2.0</option>
460
+                                        <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>5.1.0</option>
461
+                                        <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>4.7.1 (CSS only)</option>
462 462
                                     </select>
463 463
                                 </td>
464 464
                             </tr>
465 465
 
466 466
                             <tr valign="top">
467
-                                <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th>
467
+                                <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th>
468 468
                                 <td>
469 469
                                     <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue">
470
-                                        <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option>
471
-                                        <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option>
472
-                                        <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option>
470
+                                        <option value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option>
471
+                                        <option value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option>
472
+                                        <option value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option>
473 473
                                     </select>
474 474
                                 </td>
475 475
                             </tr>
476 476
 
477 477
                             <tr valign="top" class="wpfas-kit-hide">
478 478
                                 <th scope="row"><label
479
-                                            for="wpfas-pro"><?php _e( 'Enable pro', 'font-awesome-settings' ); ?></label></th>
479
+                                            for="wpfas-pro"><?php _e('Enable pro', 'font-awesome-settings'); ?></label></th>
480 480
                                 <td>
481 481
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
482
-                                    <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/>
482
+                                    <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked($this->settings['pro'], '1'); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/>
483 483
                                     <span><?php
484 484
 										echo wp_sprintf(
485
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
485
+											__('Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings'),
486 486
 											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
487 487
 											' <i class="fas fa-external-link-alt"></i></a>',
488 488
 											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
@@ -493,49 +493,49 @@  discard block
 block discarded – undo
493 493
                             </tr>
494 494
 
495 495
 							<tr valign="top" class="wpfas-kit-hide wpfas-hide-pro">
496
-								<th scope="row"><label for="wpfas-local"><?php _e( 'Load Fonts Locally', 'font-awesome-settings' ); ?></label></th>
496
+								<th scope="row"><label for="wpfas-local"><?php _e('Load Fonts Locally', 'font-awesome-settings'); ?></label></th>
497 497
 								<td>
498 498
 									<input type="hidden" name="wp-font-awesome-settings[local]" value="0"/>
499
-									<input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr( $this->settings['local_version'] ); ?>"/>
500
-									<input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked( $this->settings['local'], '1' ); ?> id="wpfas-local"/>
501
-									<span><?php _e( '(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'font-awesome-settings' ); ?></span>
499
+									<input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr($this->settings['local_version']); ?>"/>
500
+									<input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked($this->settings['local'], '1'); ?> id="wpfas-local"/>
501
+									<span><?php _e('(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'font-awesome-settings'); ?></span>
502 502
 								</td>
503 503
 							</tr>
504 504
 
505 505
                             <tr valign="top" class="wpfas-kit-hide">
506 506
                                 <th scope="row"><label
507
-                                            for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label>
507
+                                            for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label>
508 508
                                 </th>
509 509
                                 <td>
510 510
                                     <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/>
511 511
                                     <input type="checkbox" name="wp-font-awesome-settings[shims]"
512
-                                           value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/>
513
-                                    <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span>
512
+                                           value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/>
513
+                                    <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span>
514 514
                                 </td>
515 515
                             </tr>
516 516
 
517 517
                             <tr valign="top" class="wpfas-kit-hide">
518 518
                                 <th scope="row"><label
519
-                                            for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label>
519
+                                            for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label>
520 520
                                 </th>
521 521
                                 <td>
522 522
                                     <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/>
523 523
                                     <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]"
524
-                                           value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?>
524
+                                           value="1" <?php checked($this->settings['js-pseudo'], '1'); ?>
525 525
                                            id="wpfas-js-pseudo"/>
526
-                                    <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span>
526
+                                    <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span>
527 527
                                 </td>
528 528
                             </tr>
529 529
 
530 530
                             <tr valign="top">
531 531
                                 <th scope="row"><label
532
-                                            for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th>
532
+                                            for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th>
533 533
                                 <td>
534 534
                                     <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/>
535 535
                                     <input type="checkbox" name="wp-font-awesome-settings[dequeue]"
536
-                                           value="1" <?php checked( $this->settings['dequeue'], '1' ); ?>
536
+                                           value="1" <?php checked($this->settings['dequeue'], '1'); ?>
537 537
                                            id="wpfas-dequeue"/>
538
-                                    <span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span>
538
+                                    <span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span>
539 539
                                 </td>
540 540
                             </tr>
541 541
 
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
 							<?php
545 545
 							submit_button();
546 546
 							?>
547
-                            <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p>
547
+                            <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro', 'font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p>
548 548
 
549 549
                         </div>
550 550
                     </form>
551 551
 
552
-                    <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div>
552
+                    <div id="wpfas-version"><?php echo sprintf(__('Version: %s (affiliate links provided)', 'font-awesome-settings'), $this->version); ?></div>
553 553
                 </div>
554 554
 				<?php
555 555
 			}
@@ -564,12 +564,12 @@  discard block
 block discarded – undo
564 564
 		 *
565 565
 		 * @return string Either a valid version number or an empty string.
566 566
 		 */
567
-		public function validate_version_number( $version ) {
567
+		public function validate_version_number($version) {
568 568
 
569
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
569
+			if (version_compare($version, '0.0.1', '>=') >= 0) {
570 570
 				// valid
571 571
 			} else {
572
-				$version = '';// not validated
572
+				$version = ''; // not validated
573 573
 			}
574 574
 
575 575
 			return $version;
@@ -584,27 +584,27 @@  discard block
 block discarded – undo
584 584
 		 * @since 1.0.7
585 585
 		 * @return mixed|string The latest version number found.
586 586
 		 */
587
-		public function get_latest_version( $force_api = false ) {
587
+		public function get_latest_version($force_api = false) {
588 588
 			$latest_version = $this->latest;
589 589
 
590
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
590
+			$cache = get_transient('wp-font-awesome-settings-version');
591 591
 
592
-			if ( $cache === false || $force_api ) { // its not set
592
+			if ($cache === false || $force_api) { // its not set
593 593
 				$api_ver = $this->get_latest_version_from_api();
594
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
594
+				if (version_compare($api_ver, $this->latest, '>=') >= 0) {
595 595
 					$latest_version = $api_ver;
596
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
596
+					set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS);
597 597
 				}
598
-			} elseif ( $this->validate_version_number( $cache ) ) {
599
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
598
+			} elseif ($this->validate_version_number($cache)) {
599
+				if (version_compare($cache, $this->latest, '>=') >= 0) {
600 600
 					$latest_version = $cache;
601 601
 				}
602 602
 			}
603 603
 
604 604
 			// Check and auto download fonts locally.
605
-			if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
606
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
607
-					$this->download_package( $latest_version );
605
+			if (empty($this->settings['pro']) && empty($this->settings['version']) && $this->settings['type'] != 'KIT' && !empty($this->settings['local']) && !empty($this->settings['local_version']) && !empty($latest_version)) {
606
+				if (version_compare($latest_version, $this->settings['local_version'], '>') && is_admin() && !wp_doing_ajax()) {
607
+					$this->download_package($latest_version);
608 608
 				}
609 609
 			}
610 610
 
@@ -619,10 +619,10 @@  discard block
 block discarded – undo
619 619
 		 */
620 620
 		public function get_latest_version_from_api() {
621 621
 			$version  = "0";
622
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
623
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
624
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
625
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
622
+			$response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest");
623
+			if (!is_wp_error($response) && is_array($response)) {
624
+				$api_response = json_decode(wp_remote_retrieve_body($response), true);
625
+				if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) {
626 626
 					$version = $api_response['tag_name'];
627 627
 				}
628 628
 			}
@@ -650,21 +650,21 @@  discard block
 block discarded – undo
650 650
 		public function admin_notices() {
651 651
 			$settings = $this->settings;
652 652
 
653
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
654
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
653
+			if (defined('FONTAWESOME_PLUGIN_FILE')) {
654
+				if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') {
655 655
 					?>
656 656
                     <div class="notice  notice-error is-dismissible">
657
-                        <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p>
657
+                        <p><?php _e('The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings'); ?></p>
658 658
                     </div>
659 659
 					<?php
660 660
 				}
661 661
 			} else {
662
-				if ( ! empty( $settings ) ) {
663
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
662
+				if (!empty($settings)) {
663
+					if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) {
664 664
 						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
665 665
 						?>
666 666
                         <div class="notice  notice-error is-dismissible">
667
-                            <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
667
+                            <p><?php echo sprintf(__('Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings'), "<a href='" . esc_url_raw($link) . "'>", "</a>"); ?></p>
668 668
                         </div>
669 669
 						<?php
670 670
 					}
@@ -680,20 +680,20 @@  discard block
 block discarded – undo
680 680
 		 * @param string $option The option name.
681 681
 		 * @param mixed  $value  The option value.
682 682
 		 */
683
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
683
+		public function add_option_wp_font_awesome_settings($option, $value) {
684 684
 			// Do nothing if WordPress is being installed.
685
-			if ( wp_installing() ) {
685
+			if (wp_installing()) {
686 686
 				return;
687 687
 			}
688 688
 
689
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
690
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
689
+			if (!empty($value['local']) && empty($value['pro']) && !(!empty($value['type']) && $value['type'] == 'KIT')) {
690
+				$version = isset($value['version']) && $value['version'] ? $value['version'] : $this->get_latest_version();
691 691
 
692
-				if ( ! empty( $version ) ) {
693
-					$response = $this->download_package( $version, $value );
692
+				if (!empty($version)) {
693
+					$response = $this->download_package($version, $value);
694 694
 
695
-					if ( is_wp_error( $response ) ) {
696
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
695
+					if (is_wp_error($response)) {
696
+						add_settings_error('general', 'fontawesome_download', __('ERROR:', 'font-awesome-settings') . ' ' . $response->get_error_message(), 'error');
697 697
 					}
698 698
 				}
699 699
 			}
@@ -707,25 +707,25 @@  discard block
 block discarded – undo
707 707
 		 * @param mixed $old_value The old option value.
708 708
 		 * @param mixed $value     The new option value.
709 709
 		 */
710
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
710
+		public function update_option_wp_font_awesome_settings($old_value, $new_value) {
711 711
 			// Do nothing if WordPress is being installed.
712
-			if ( wp_installing() ) {
712
+			if (wp_installing()) {
713 713
 				return;
714 714
 			}
715 715
 
716
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
716
+			if (!empty($new_value['local']) && empty($new_value['pro']) && !(!empty($new_value['type']) && $new_value['type'] == 'KIT')) {
717 717
 				// Old values
718
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
719
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
718
+				$old_version = isset($old_value['version']) && $old_value['version'] ? $old_value['version'] : (isset($old_value['local_version']) ? $old_value['local_version'] : '');
719
+				$old_local = isset($old_value['local']) ? (int) $old_value['local'] : 0;
720 720
 
721 721
 				// New values
722
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
722
+				$new_version = isset($new_value['version']) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
723 723
 
724
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
725
-					$response = $this->download_package( $new_version, $new_value );
724
+				if (empty($old_local) || $old_version !== $new_version || !file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) {
725
+					$response = $this->download_package($new_version, $new_value);
726 726
 
727
-					if ( is_wp_error( $response ) ) {
728
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
727
+					if (is_wp_error($response)) {
728
+						add_settings_error('general', 'fontawesome_download', __('ERROR:', 'font-awesome-settings') . ' ' . $response->get_error_message(), 'error');
729 729
 					}
730 730
 				}
731 731
 			}
@@ -739,9 +739,9 @@  discard block
 block discarded – undo
739 739
 		 * @param string Fonts directory local path.
740 740
 		 */
741 741
 		public function get_fonts_dir() {
742
-			$upload_dir = wp_upload_dir( null, false );
742
+			$upload_dir = wp_upload_dir(null, false);
743 743
 
744
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
744
+			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
745 745
 		}
746 746
 
747 747
 		/**
@@ -752,9 +752,9 @@  discard block
 block discarded – undo
752 752
 		 * @param string Fonts directory local url.
753 753
 		 */
754 754
 		public function get_fonts_url() {
755
-			$upload_dir = wp_upload_dir( null, false );
755
+			$upload_dir = wp_upload_dir(null, false);
756 756
 
757
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
757
+			return $upload_dir['baseurl'] . '/ayefonts/fa/';
758 758
 		}
759 759
 
760 760
 		/**
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 		 * @return bool True if active else false.
766 766
 		 */
767 767
 		public function has_local() {
768
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
768
+			if (!empty($this->settings['local']) && empty($this->settings['pro']) && file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) {
769 769
 				return true;
770 770
 			}
771 771
 
@@ -780,18 +780,18 @@  discard block
 block discarded – undo
780 780
 		 * @return object The WP Filesystem.
781 781
 		 */
782 782
 		public function get_wp_filesystem() {
783
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
784
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
783
+			if (!function_exists('get_filesystem_method')) {
784
+				require_once(ABSPATH . "/wp-admin/includes/file.php");
785 785
 			}
786 786
 
787 787
 			$access_type = get_filesystem_method();
788 788
 
789
-			if ( $access_type === 'direct' ) {
789
+			if ($access_type === 'direct') {
790 790
 				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
791
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
791
+				$creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array());
792 792
 
793 793
 				/* Initialize the API */
794
-				if ( ! WP_Filesystem( $creds ) ) {
794
+				if (!WP_Filesystem($creds)) {
795 795
 					/* Any problems and we exit */
796 796
 					return false;
797 797
 				}
@@ -800,11 +800,11 @@  discard block
 block discarded – undo
800 800
 
801 801
 				return $wp_filesystem;
802 802
 				/* Do our file manipulations below */
803
-			} else if ( defined( 'FTP_USER' ) ) {
804
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
803
+			} else if (defined('FTP_USER')) {
804
+				$creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array());
805 805
 
806 806
 				/* Initialize the API */
807
-				if ( ! WP_Filesystem( $creds ) ) {
807
+				if (!WP_Filesystem($creds)) {
808 808
 					/* Any problems and we exit */
809 809
 					return false;
810 810
 				}
@@ -827,38 +827,38 @@  discard block
 block discarded – undo
827 827
 		 * @param array $option Fontawesome settings.
828 828
 		 * @return WP_ERROR|bool Error on fail and true on success.
829 829
 		 */
830
-		public function download_package( $version, $option = array() ) {
830
+		public function download_package($version, $option = array()) {
831 831
 			$filename = 'fontawesome-free-' . $version . '-web';
832 832
 			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
833 833
 
834
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
834
+			if (!function_exists('wp_handle_upload')) {
835 835
 				require_once ABSPATH . 'wp-admin/includes/file.php';
836 836
 			}
837 837
 
838
-			$download_file = download_url( esc_url_raw( $url ) );
838
+			$download_file = download_url(esc_url_raw($url));
839 839
 
840
-			if ( is_wp_error( $download_file ) ) {
841
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
842
-			} else if ( empty( $download_file ) ) {
843
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
840
+			if (is_wp_error($download_file)) {
841
+				return new WP_Error('fontawesome_download_failed', __($download_file->get_error_message(), 'font-awesome-settings'));
842
+			} else if (empty($download_file)) {
843
+				return new WP_Error('fontawesome_download_failed', __('Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings'));
844 844
 			}
845 845
 
846
-			$response = $this->extract_package( $download_file, $filename, true );
846
+			$response = $this->extract_package($download_file, $filename, true);
847 847
 
848 848
 			// Update local version.
849
-			if ( is_wp_error( $response ) ) {
849
+			if (is_wp_error($response)) {
850 850
 				return $response;
851
-			} else if ( $response ) {
852
-				if ( empty( $option ) ) {
853
-					$option = get_option( 'wp-font-awesome-settings' );
851
+			} else if ($response) {
852
+				if (empty($option)) {
853
+					$option = get_option('wp-font-awesome-settings');
854 854
 				}
855 855
 
856 856
 				$option['local_version'] = $version;
857 857
 
858 858
 				// Remove action to prevent looping.
859
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
859
+				remove_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2);
860 860
 
861
-				update_option( 'wp-font-awesome-settings', $option );
861
+				update_option('wp-font-awesome-settings', $option);
862 862
 
863 863
 				return true;
864 864
 			}
@@ -876,60 +876,60 @@  discard block
 block discarded – undo
876 876
 		 * @param bool   $delete_package Delete temp file or not.
877 877
 		 * @return WP_Error|bool True on success WP_Error on fail.
878 878
 		 */
879
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
879
+		public function extract_package($package, $dirname = '', $delete_package = false) {
880 880
 			global $wp_filesystem;
881 881
 
882 882
 			$wp_filesystem = $this->get_wp_filesystem();
883 883
 
884
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
885
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
886
-			} else if ( empty( $wp_filesystem ) ) {
887
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
884
+			if (empty($wp_filesystem) && isset($wp_filesystem->errors) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
885
+				return new WP_Error('fontawesome_filesystem_error', __($wp_filesystem->errors->get_error_message(), 'font-awesome-settings'));
886
+			} else if (empty($wp_filesystem)) {
887
+				return new WP_Error('fontawesome_filesystem_error', __('Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings'));
888 888
 			}
889 889
 
890 890
 			$fonts_dir = $this->get_fonts_dir();
891
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
891
+			$fonts_tmp_dir = dirname($fonts_dir) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
892 892
 
893
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
894
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
893
+			if ($wp_filesystem->is_dir($fonts_tmp_dir)) {
894
+				$wp_filesystem->delete($fonts_tmp_dir, true);
895 895
 			}
896 896
 
897 897
 			// Unzip package to working directory.
898
-			$result = unzip_file( $package, $fonts_tmp_dir );
898
+			$result = unzip_file($package, $fonts_tmp_dir);
899 899
 
900
-			if ( is_wp_error( $result ) ) {
901
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
900
+			if (is_wp_error($result)) {
901
+				$wp_filesystem->delete($fonts_tmp_dir, true);
902 902
 
903
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
904
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
903
+				if ('incompatible_archive' === $result->get_error_code()) {
904
+					return new WP_Error('fontawesome_incompatible_archive', __($result->get_error_message(), 'font-awesome-settings'));
905 905
 				}
906 906
 
907 907
 				return $result;
908 908
 			}
909 909
 
910
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
911
-				$wp_filesystem->delete( $fonts_dir, true );
910
+			if ($wp_filesystem->is_dir($fonts_dir)) {
911
+				$wp_filesystem->delete($fonts_dir, true);
912 912
 			}
913 913
 
914 914
 			$extract_dir = $fonts_tmp_dir;
915 915
 
916
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
916
+			if ($dirname && $wp_filesystem->is_dir($extract_dir . $dirname . DIRECTORY_SEPARATOR)) {
917 917
 				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
918 918
 			}
919 919
 
920 920
 			try {
921
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
922
-			} catch ( Exception $e ) {
923
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
921
+				$return = $wp_filesystem->move($extract_dir, $fonts_dir, true);
922
+			} catch (Exception $e) {
923
+				$return = new WP_Error('fontawesome_move_package', __('Fail to move font awesome package!', 'font-awesome-settings'));
924 924
 			}
925 925
 
926
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
927
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
926
+			if ($wp_filesystem->is_dir($fonts_tmp_dir)) {
927
+				$wp_filesystem->delete($fonts_tmp_dir, true);
928 928
 			}
929 929
 
930 930
 			// Once extracted, delete the package if required.
931
-			if ( $delete_package ) {
932
-				unlink( $package );
931
+			if ($delete_package) {
932
+				unlink($package);
933 933
 			}
934 934
 
935 935
 			return $return;
Please login to merge, or discard this patch.
Indentation   +763 added lines, -763 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,362 +21,362 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @since 1.0.11 Font Awesome Pro now supported.
30
-	 * @since 1.0.11 Font Awesome Kits now supported.
31
-	 * @since 1.0.13 RTL language support added.
32
-	 * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
33
-	 * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
34
-	 * @since 1.1.0 Option added to load FontAwesome locally.
35
-	 * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
36
-	 * @since 1.1.2 Bumped the latest version to 6.3.0 - CHANGED.
37
-	 * @ver 1.0.15
38
-	 * @todo decide how to implement textdomain
39
-	 */
40
-	class WP_Font_Awesome_Settings {
41
-
42
-		/**
43
-		 * Class version version.
44
-		 *
45
-		 * @var string
46
-		 */
47
-		public $version = '1.1.2';
48
-
49
-		/**
50
-		 * Class textdomain.
51
-		 *
52
-		 * @var string
53
-		 */
54
-		public $textdomain = 'font-awesome-settings';
55
-
56
-		/**
57
-		 * Latest version of Font Awesome at time of publish published.
58
-		 *
59
-		 * @var string
60
-		 */
61
-		public $latest = "6.3.0";
62
-
63
-		/**
64
-		 * The title.
65
-		 *
66
-		 * @var string
67
-		 */
68
-		public $name = 'Font Awesome';
69
-
70
-		/**
71
-		 * Holds the settings values.
72
-		 *
73
-		 * @var array
74
-		 */
75
-		private $settings;
76
-
77
-		/**
78
-		 * WP_Font_Awesome_Settings instance.
79
-		 *
80
-		 * @access private
81
-		 * @since  1.0.0
82
-		 * @var    WP_Font_Awesome_Settings There can be only one!
83
-		 */
84
-		private static $instance = null;
85
-
86
-		/**
87
-		 * Main WP_Font_Awesome_Settings Instance.
88
-		 *
89
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
90
-		 *
91
-		 * @since 1.0.0
92
-		 * @static
93
-		 * @return WP_Font_Awesome_Settings - Main instance.
94
-		 */
95
-		public static function instance() {
96
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
97
-				self::$instance = new WP_Font_Awesome_Settings;
98
-
99
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
100
-
101
-				if ( is_admin() ) {
102
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
103
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
104
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
105
-				}
106
-
107
-				do_action( 'wp_font_awesome_settings_loaded' );
108
-			}
109
-
110
-			return self::$instance;
111
-		}
112
-
113
-		/**
114
-		 * Initiate the settings and add the required action hooks.
115
-		 *
116
-		 * @since 1.0.8 Settings name wrong - FIXED
117
-		 */
118
-		public function init() {
119
-			// Download fontawesome locally.
120
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
121
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
122
-
123
-			$this->settings = $this->get_settings();
124
-
125
-			// check if the official plugin is active and use that instead if so.
126
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
127
-
128
-				if ( $this->settings['type'] == 'CSS' ) {
129
-
130
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
131
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
132
-					}
133
-
134
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
135
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
136
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
137
-					}
138
-
139
-				} else {
140
-
141
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
142
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
143
-					}
144
-
145
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
146
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
147
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
148
-					}
149
-				}
150
-
151
-				// remove font awesome if set to do so
152
-				if ( $this->settings['dequeue'] == '1' ) {
153
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
154
-				}
155
-			}
156
-
157
-		}
158
-
159
-		/**
160
-		 * Add FA to the FSE.
161
-		 *
162
-		 * @param $editor_settings
163
-		 * @param $block_editor_context
164
-		 *
165
-		 * @return array
166
-		 */
167
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
168
-
169
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
170
-				$url = $this->get_url();
171
-				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
172
-			}
173
-
174
-			return $editor_settings;
175
-		}
176
-
177
-		/**
178
-		 * Add FA to the FSE.
179
-		 *
180
-		 * @param $editor_settings
181
-		 * @param $block_editor_context
182
-		 *
183
-		 * @return array
184
-		 */
185
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
186
-
187
-			$url = $this->get_url();
188
-			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
189
-
190
-			return $editor_settings;
191
-		}
192
-
193
-		/**
194
-		 * Adds the Font Awesome styles.
195
-		 */
196
-		public function enqueue_style() {
197
-			// build url
198
-			$url = $this->get_url();
199
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
200
-
201
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
202
-			wp_register_style( 'font-awesome', $url, array(), $version );
203
-			wp_enqueue_style( 'font-awesome' );
204
-
205
-			// RTL language support CSS.
206
-			if ( is_rtl() ) {
207
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
208
-			}
209
-
210
-			if ( $this->settings['shims'] ) {
211
-				$url = $this->get_url( true );
212
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
213
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
214
-				wp_enqueue_style( 'font-awesome-shims' );
215
-			}
216
-		}
217
-
218
-		/**
219
-		 * Adds the Font Awesome JS.
220
-		 */
221
-		public function enqueue_scripts() {
222
-			// build url
223
-			$url = $this->get_url();
224
-
225
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
226
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
227
-			wp_register_script( 'font-awesome', $url, array(), null );
228
-			wp_enqueue_script( 'font-awesome' );
229
-
230
-			if ( $this->settings['shims'] ) {
231
-				$url = $this->get_url( true );
232
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
233
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
234
-				wp_enqueue_script( 'font-awesome-shims' );
235
-			}
236
-		}
237
-
238
-		/**
239
-		 * Get the url of the Font Awesome files.
240
-		 *
241
-		 * @param bool $shims If this is a shim file or not.
242
-		 * @param bool $local Load locally if allowed.
243
-		 *
244
-		 * @return string The url to the file.
245
-		 */
246
-		public function get_url( $shims = false, $local = true ) {
247
-			$script  = $shims ? 'v4-shims' : 'all';
248
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
249
-			$type    = $this->settings['type'];
250
-			$version = $this->settings['version'];
251
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
252
-			$url     = '';
253
-
254
-			if ( $type == 'KIT' && $kit_url ) {
255
-				if ( $shims ) {
256
-					// if its a kit then we don't add shims here
257
-					return '';
258
-				}
259
-				$url .= $kit_url; // CDN
260
-				$url .= "?wpfas=true"; // set our var so our version is not removed
261
-			} else {
262
-				$v = '';
263
-				// Check and load locally.
264
-				if ( $local && $this->has_local() ) {
265
-					$script .= ".min";
266
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
267
-					$url .= $this->get_fonts_url(); // Local fonts url.
268
-				} else {
269
-					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
270
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
271
-				}
272
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
273
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
274
-				$url .= "?wpfas=true" . $v; // set our var so our version is not removed
275
-			}
276
-
277
-			return $url;
278
-		}
279
-
280
-		/**
281
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
282
-		 *
283
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
284
-		 *
285
-		 * @param $url
286
-		 * @param $original_url
287
-		 * @param $_context
288
-		 *
289
-		 * @return string The filtered url.
290
-		 */
291
-		public function remove_font_awesome( $url, $original_url, $_context ) {
292
-
293
-			if ( $_context == 'display'
294
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
295
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
296
-			) {// it's a font-awesome-url (probably)
297
-
298
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
299
-					if ( $this->settings['type'] == 'JS' ) {
300
-						if ( $this->settings['js-pseudo'] ) {
301
-							$url .= "' data-search-pseudo-elements defer='defer";
302
-						} else {
303
-							$url .= "' defer='defer";
304
-						}
305
-					}
306
-				} else {
307
-					$url = ''; // removing the url removes the file
308
-				}
309
-
310
-			}
311
-
312
-			return $url;
313
-		}
314
-
315
-		/**
316
-		 * Register the database settings with WordPress.
317
-		 */
318
-		public function register_settings() {
319
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
320
-		}
321
-
322
-		/**
323
-		 * Add the WordPress settings menu item.
324
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
325
-		 */
326
-		public function menu_item() {
327
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
328
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
329
-				$this,
330
-				'settings_page'
331
-			) );
332
-		}
333
-
334
-		/**
335
-		 * Get the current Font Awesome output settings.
336
-		 *
337
-		 * @return array The array of settings.
338
-		 */
339
-		public function get_settings() {
340
-			$db_settings = get_option( 'wp-font-awesome-settings' );
341
-
342
-			$defaults = array(
343
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
344
-				'version'   => '', // latest
345
-				'enqueue'   => '', // front and backend
346
-				'shims'     => '0', // default OFF now in 2020
347
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
348
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
349
-				'pro'       => '0', // if pro CDN url should be used
350
-				'local'     => '0', // Store fonts locally.
351
-				'local_version' => '', // Local fonts version.
352
-				'kit-url'   => '', // the kit url
353
-			);
354
-
355
-			$settings = wp_parse_args( $db_settings, $defaults );
356
-
357
-			/**
358
-			 * Filter the Font Awesome settings.
359
-			 *
360
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
361
-			 */
362
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
363
-		}
364
-
365
-		/**
366
-		 * The settings page html output.
367
-		 */
368
-		public function settings_page() {
369
-			if ( ! current_user_can( 'manage_options' ) ) {
370
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
371
-			}
372
-
373
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
374
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
375
-				$this->get_latest_version( $force_api = true );
376
-			}
377
-
378
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
379
-				?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @since 1.0.11 Font Awesome Pro now supported.
30
+     * @since 1.0.11 Font Awesome Kits now supported.
31
+     * @since 1.0.13 RTL language support added.
32
+     * @since 1.0.14 Warning added for v6 pro requires kit and will now not work if official FA plugin installed.
33
+     * @since 1.0.15 Font Awesome will now load in the FSE if enable din the backend.
34
+     * @since 1.1.0 Option added to load FontAwesome locally.
35
+     * @since 1.1.1 Requires to re-save settings to load locally when option does not exists - FIXED.
36
+     * @since 1.1.2 Bumped the latest version to 6.3.0 - CHANGED.
37
+     * @ver 1.0.15
38
+     * @todo decide how to implement textdomain
39
+     */
40
+    class WP_Font_Awesome_Settings {
41
+
42
+        /**
43
+         * Class version version.
44
+         *
45
+         * @var string
46
+         */
47
+        public $version = '1.1.2';
48
+
49
+        /**
50
+         * Class textdomain.
51
+         *
52
+         * @var string
53
+         */
54
+        public $textdomain = 'font-awesome-settings';
55
+
56
+        /**
57
+         * Latest version of Font Awesome at time of publish published.
58
+         *
59
+         * @var string
60
+         */
61
+        public $latest = "6.3.0";
62
+
63
+        /**
64
+         * The title.
65
+         *
66
+         * @var string
67
+         */
68
+        public $name = 'Font Awesome';
69
+
70
+        /**
71
+         * Holds the settings values.
72
+         *
73
+         * @var array
74
+         */
75
+        private $settings;
76
+
77
+        /**
78
+         * WP_Font_Awesome_Settings instance.
79
+         *
80
+         * @access private
81
+         * @since  1.0.0
82
+         * @var    WP_Font_Awesome_Settings There can be only one!
83
+         */
84
+        private static $instance = null;
85
+
86
+        /**
87
+         * Main WP_Font_Awesome_Settings Instance.
88
+         *
89
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
90
+         *
91
+         * @since 1.0.0
92
+         * @static
93
+         * @return WP_Font_Awesome_Settings - Main instance.
94
+         */
95
+        public static function instance() {
96
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
97
+                self::$instance = new WP_Font_Awesome_Settings;
98
+
99
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
100
+
101
+                if ( is_admin() ) {
102
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
103
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
104
+                    add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
105
+                }
106
+
107
+                do_action( 'wp_font_awesome_settings_loaded' );
108
+            }
109
+
110
+            return self::$instance;
111
+        }
112
+
113
+        /**
114
+         * Initiate the settings and add the required action hooks.
115
+         *
116
+         * @since 1.0.8 Settings name wrong - FIXED
117
+         */
118
+        public function init() {
119
+            // Download fontawesome locally.
120
+            add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
121
+            add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
122
+
123
+            $this->settings = $this->get_settings();
124
+
125
+            // check if the official plugin is active and use that instead if so.
126
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
127
+
128
+                if ( $this->settings['type'] == 'CSS' ) {
129
+
130
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
131
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
132
+                    }
133
+
134
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
135
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
136
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
137
+                    }
138
+
139
+                } else {
140
+
141
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
142
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
143
+                    }
144
+
145
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
146
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
147
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
148
+                    }
149
+                }
150
+
151
+                // remove font awesome if set to do so
152
+                if ( $this->settings['dequeue'] == '1' ) {
153
+                    add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
154
+                }
155
+            }
156
+
157
+        }
158
+
159
+        /**
160
+         * Add FA to the FSE.
161
+         *
162
+         * @param $editor_settings
163
+         * @param $block_editor_context
164
+         *
165
+         * @return array
166
+         */
167
+        public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
168
+
169
+            if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
170
+                $url = $this->get_url();
171
+                $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
172
+            }
173
+
174
+            return $editor_settings;
175
+        }
176
+
177
+        /**
178
+         * Add FA to the FSE.
179
+         *
180
+         * @param $editor_settings
181
+         * @param $block_editor_context
182
+         *
183
+         * @return array
184
+         */
185
+        public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
186
+
187
+            $url = $this->get_url();
188
+            $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
189
+
190
+            return $editor_settings;
191
+        }
192
+
193
+        /**
194
+         * Adds the Font Awesome styles.
195
+         */
196
+        public function enqueue_style() {
197
+            // build url
198
+            $url = $this->get_url();
199
+            $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
200
+
201
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
202
+            wp_register_style( 'font-awesome', $url, array(), $version );
203
+            wp_enqueue_style( 'font-awesome' );
204
+
205
+            // RTL language support CSS.
206
+            if ( is_rtl() ) {
207
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
208
+            }
209
+
210
+            if ( $this->settings['shims'] ) {
211
+                $url = $this->get_url( true );
212
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
213
+                wp_register_style( 'font-awesome-shims', $url, array(), $version );
214
+                wp_enqueue_style( 'font-awesome-shims' );
215
+            }
216
+        }
217
+
218
+        /**
219
+         * Adds the Font Awesome JS.
220
+         */
221
+        public function enqueue_scripts() {
222
+            // build url
223
+            $url = $this->get_url();
224
+
225
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
226
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
227
+            wp_register_script( 'font-awesome', $url, array(), null );
228
+            wp_enqueue_script( 'font-awesome' );
229
+
230
+            if ( $this->settings['shims'] ) {
231
+                $url = $this->get_url( true );
232
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
233
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
234
+                wp_enqueue_script( 'font-awesome-shims' );
235
+            }
236
+        }
237
+
238
+        /**
239
+         * Get the url of the Font Awesome files.
240
+         *
241
+         * @param bool $shims If this is a shim file or not.
242
+         * @param bool $local Load locally if allowed.
243
+         *
244
+         * @return string The url to the file.
245
+         */
246
+        public function get_url( $shims = false, $local = true ) {
247
+            $script  = $shims ? 'v4-shims' : 'all';
248
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
249
+            $type    = $this->settings['type'];
250
+            $version = $this->settings['version'];
251
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
252
+            $url     = '';
253
+
254
+            if ( $type == 'KIT' && $kit_url ) {
255
+                if ( $shims ) {
256
+                    // if its a kit then we don't add shims here
257
+                    return '';
258
+                }
259
+                $url .= $kit_url; // CDN
260
+                $url .= "?wpfas=true"; // set our var so our version is not removed
261
+            } else {
262
+                $v = '';
263
+                // Check and load locally.
264
+                if ( $local && $this->has_local() ) {
265
+                    $script .= ".min";
266
+                    $v .= '&ver=' . strip_tags( $this->settings['local_version'] );
267
+                    $url .= $this->get_fonts_url(); // Local fonts url.
268
+                } else {
269
+                    $url .= "https://$sub.fontawesome.com/releases/"; // CDN
270
+                    $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
271
+                }
272
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
273
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
274
+                $url .= "?wpfas=true" . $v; // set our var so our version is not removed
275
+            }
276
+
277
+            return $url;
278
+        }
279
+
280
+        /**
281
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
282
+         *
283
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
284
+         *
285
+         * @param $url
286
+         * @param $original_url
287
+         * @param $_context
288
+         *
289
+         * @return string The filtered url.
290
+         */
291
+        public function remove_font_awesome( $url, $original_url, $_context ) {
292
+
293
+            if ( $_context == 'display'
294
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
295
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
296
+            ) {// it's a font-awesome-url (probably)
297
+
298
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
299
+                    if ( $this->settings['type'] == 'JS' ) {
300
+                        if ( $this->settings['js-pseudo'] ) {
301
+                            $url .= "' data-search-pseudo-elements defer='defer";
302
+                        } else {
303
+                            $url .= "' defer='defer";
304
+                        }
305
+                    }
306
+                } else {
307
+                    $url = ''; // removing the url removes the file
308
+                }
309
+
310
+            }
311
+
312
+            return $url;
313
+        }
314
+
315
+        /**
316
+         * Register the database settings with WordPress.
317
+         */
318
+        public function register_settings() {
319
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
320
+        }
321
+
322
+        /**
323
+         * Add the WordPress settings menu item.
324
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
325
+         */
326
+        public function menu_item() {
327
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
328
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
329
+                $this,
330
+                'settings_page'
331
+            ) );
332
+        }
333
+
334
+        /**
335
+         * Get the current Font Awesome output settings.
336
+         *
337
+         * @return array The array of settings.
338
+         */
339
+        public function get_settings() {
340
+            $db_settings = get_option( 'wp-font-awesome-settings' );
341
+
342
+            $defaults = array(
343
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
344
+                'version'   => '', // latest
345
+                'enqueue'   => '', // front and backend
346
+                'shims'     => '0', // default OFF now in 2020
347
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
348
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
349
+                'pro'       => '0', // if pro CDN url should be used
350
+                'local'     => '0', // Store fonts locally.
351
+                'local_version' => '', // Local fonts version.
352
+                'kit-url'   => '', // the kit url
353
+            );
354
+
355
+            $settings = wp_parse_args( $db_settings, $defaults );
356
+
357
+            /**
358
+             * Filter the Font Awesome settings.
359
+             *
360
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
361
+             */
362
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
363
+        }
364
+
365
+        /**
366
+         * The settings page html output.
367
+         */
368
+        public function settings_page() {
369
+            if ( ! current_user_can( 'manage_options' ) ) {
370
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
371
+            }
372
+
373
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
374
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
375
+                $this->get_latest_version( $force_api = true );
376
+            }
377
+
378
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
379
+                ?>
380 380
                 <style>
381 381
                     .wpfas-kit-show {
382 382
                         display: none;
@@ -402,16 +402,16 @@  discard block
 block discarded – undo
402 402
                     <h1><?php echo $this->name; ?></h1>
403 403
                     <form method="post" action="options.php" class="fas-settings-form">
404 404
 						<?php
405
-						settings_fields( 'wp-font-awesome-settings' );
406
-						do_settings_sections( 'wp-font-awesome-settings' );
407
-						$table_class = '';
408
-						if ( $this->settings['type'] ) {
409
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
410
-						}
411
-						if ( ! empty( $this->settings['pro'] ) ) {
412
-							$table_class .= ' wpfas-has-pro';
413
-						}
414
-						?>
405
+                        settings_fields( 'wp-font-awesome-settings' );
406
+                        do_settings_sections( 'wp-font-awesome-settings' );
407
+                        $table_class = '';
408
+                        if ( $this->settings['type'] ) {
409
+                            $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
410
+                        }
411
+                        if ( ! empty( $this->settings['pro'] ) ) {
412
+                            $table_class .= ' wpfas-has-pro';
413
+                        }
414
+                        ?>
415 415
 						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
416 416
 							<?php if ( $this->has_local() ) { ?>
417 417
 							<div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'font-awesome-settings' ); ?></strong></p></div>
@@ -436,12 +436,12 @@  discard block
 block discarded – undo
436 436
                                 <td>
437 437
                                     <input class="regular-text" id="wpfas-kit-url" type="url" name="wp-font-awesome-settings[kit-url]" value="<?php echo esc_attr( $this->settings['kit-url'] ); ?>" placeholder="<?php echo 'https://kit.font';echo 'awesome.com/123abc.js'; // this won't pass theme check :(?>"/>
438 438
                                     <span><?php
439
-										echo sprintf(
440
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
441
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
442
-											'</a>'
443
-										);
444
-										?></span>
439
+                                        echo sprintf(
440
+                                            __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'font-awesome-settings' ),
441
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
442
+                                            '</a>'
443
+                                        );
444
+                                        ?></span>
445 445
                                 </td>
446 446
                             </tr>
447 447
 
@@ -482,14 +482,14 @@  discard block
 block discarded – undo
482 482
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
483 483
                                     <input type="checkbox" name="wp-font-awesome-settings[pro]" value="1" <?php checked( $this->settings['pro'], '1' ); ?> id="wpfas-pro" onchange="if(jQuery(this).is(':checked')){jQuery('.wpfas-table-settings').addClass('wpfas-has-pro')}else{jQuery('.wpfas-table-settings').removeClass('wpfas-has-pro')}"/>
484 484
                                     <span><?php
485
-										echo wp_sprintf(
486
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
487
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
488
-											' <i class="fas fa-external-link-alt"></i></a>',
489
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
490
-											' <i class="fas fa-external-link-alt"></i></a>'
491
-										);
492
-										?></span>
485
+                                        echo wp_sprintf(
486
+                                            __( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'font-awesome-settings' ),
487
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
488
+                                            ' <i class="fas fa-external-link-alt"></i></a>',
489
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
490
+                                            ' <i class="fas fa-external-link-alt"></i></a>'
491
+                                        );
492
+                                        ?></span>
493 493
                                 </td>
494 494
                             </tr>
495 495
 
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
                         </table>
544 544
                         <div class="fas-buttons">
545 545
 							<?php
546
-							submit_button();
547
-							?>
546
+                            submit_button();
547
+                            ?>
548 548
                             <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 14,000+ more icons with Font Awesome Pro','font-awesome-settings'); ?> <i class="fas fa-external-link-alt"></i></a></p>
549 549
 
550 550
                         </div>
@@ -553,392 +553,392 @@  discard block
 block discarded – undo
553 553
                     <div id="wpfas-version"><?php echo sprintf(__( 'Version: %s (affiliate links provided)', 'font-awesome-settings' ), $this->version ); ?></div>
554 554
                 </div>
555 555
 				<?php
556
-			}
557
-		}
558
-
559
-		/**
560
-		 * Check a version number is valid and if so return it or else return an empty string.
561
-		 *
562
-		 * @param $version string The version number to check.
563
-		 *
564
-		 * @since 1.0.6
565
-		 *
566
-		 * @return string Either a valid version number or an empty string.
567
-		 */
568
-		public function validate_version_number( $version ) {
569
-
570
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
571
-				// valid
572
-			} else {
573
-				$version = '';// not validated
574
-			}
575
-
576
-			return $version;
577
-		}
578
-
579
-
580
-		/**
581
-		 * Get the latest version of Font Awesome.
582
-		 *
583
-		 * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
584
-		 *
585
-		 * @since 1.0.7
586
-		 * @return mixed|string The latest version number found.
587
-		 */
588
-		public function get_latest_version( $force_api = false ) {
589
-			$latest_version = $this->latest;
590
-
591
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
592
-
593
-			if ( $cache === false || $force_api ) { // its not set
594
-				$api_ver = $this->get_latest_version_from_api();
595
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
596
-					$latest_version = $api_ver;
597
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
598
-				}
599
-			} elseif ( $this->validate_version_number( $cache ) ) {
600
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
601
-					$latest_version = $cache;
602
-				}
603
-			}
604
-
605
-			// Check and auto download fonts locally.
606
-			if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
607
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
608
-					$this->download_package( $latest_version );
609
-				}
610
-			}
611
-
612
-			return $latest_version;
613
-		}
614
-
615
-		/**
616
-		 * Get the latest Font Awesome version from the github API.
617
-		 *
618
-		 * @since 1.0.7
619
-		 * @return string The latest version number or `0` on API fail.
620
-		 */
621
-		public function get_latest_version_from_api() {
622
-			$version  = "0";
623
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
624
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
625
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
626
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
627
-					$version = $api_response['tag_name'];
628
-				}
629
-			}
630
-
631
-			return $version;
632
-		}
633
-
634
-		/**
635
-		 * Inline CSS for RTL language support.
636
-		 *
637
-		 * @since 1.0.13
638
-		 * @return string Inline CSS.
639
-		 */
640
-		public function rtl_inline_css() {
641
-			$inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
642
-
643
-			return $inline_css;
644
-		}
645
-
646
-		/**
647
-		 * Show any warnings as an admin notice.
648
-		 *
649
-		 * @return void
650
-		 */
651
-		public function admin_notices() {
652
-			$settings = $this->settings;
653
-
654
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
655
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
656
-					?>
556
+            }
557
+        }
558
+
559
+        /**
560
+         * Check a version number is valid and if so return it or else return an empty string.
561
+         *
562
+         * @param $version string The version number to check.
563
+         *
564
+         * @since 1.0.6
565
+         *
566
+         * @return string Either a valid version number or an empty string.
567
+         */
568
+        public function validate_version_number( $version ) {
569
+
570
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
571
+                // valid
572
+            } else {
573
+                $version = '';// not validated
574
+            }
575
+
576
+            return $version;
577
+        }
578
+
579
+
580
+        /**
581
+         * Get the latest version of Font Awesome.
582
+         *
583
+         * We check for a cached version and if none we will check for a live version via API and then cache it for 48 hours.
584
+         *
585
+         * @since 1.0.7
586
+         * @return mixed|string The latest version number found.
587
+         */
588
+        public function get_latest_version( $force_api = false ) {
589
+            $latest_version = $this->latest;
590
+
591
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
592
+
593
+            if ( $cache === false || $force_api ) { // its not set
594
+                $api_ver = $this->get_latest_version_from_api();
595
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
596
+                    $latest_version = $api_ver;
597
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
598
+                }
599
+            } elseif ( $this->validate_version_number( $cache ) ) {
600
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
601
+                    $latest_version = $cache;
602
+                }
603
+            }
604
+
605
+            // Check and auto download fonts locally.
606
+            if ( empty( $this->settings['pro'] ) && empty( $this->settings['version'] ) && $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && ! empty( $this->settings['local_version'] ) && ! empty( $latest_version ) ) {
607
+                if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
608
+                    $this->download_package( $latest_version );
609
+                }
610
+            }
611
+
612
+            return $latest_version;
613
+        }
614
+
615
+        /**
616
+         * Get the latest Font Awesome version from the github API.
617
+         *
618
+         * @since 1.0.7
619
+         * @return string The latest version number or `0` on API fail.
620
+         */
621
+        public function get_latest_version_from_api() {
622
+            $version  = "0";
623
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
624
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
625
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
626
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
627
+                    $version = $api_response['tag_name'];
628
+                }
629
+            }
630
+
631
+            return $version;
632
+        }
633
+
634
+        /**
635
+         * Inline CSS for RTL language support.
636
+         *
637
+         * @since 1.0.13
638
+         * @return string Inline CSS.
639
+         */
640
+        public function rtl_inline_css() {
641
+            $inline_css = '[dir=rtl] .fa-address,[dir=rtl] .fa-address-card,[dir=rtl] .fa-adjust,[dir=rtl] .fa-alarm-clock,[dir=rtl] .fa-align-left,[dir=rtl] .fa-align-right,[dir=rtl] .fa-analytics,[dir=rtl] .fa-angle-double-left,[dir=rtl] .fa-angle-double-right,[dir=rtl] .fa-angle-left,[dir=rtl] .fa-angle-right,[dir=rtl] .fa-arrow-alt-circle-left,[dir=rtl] .fa-arrow-alt-circle-right,[dir=rtl] .fa-arrow-alt-from-left,[dir=rtl] .fa-arrow-alt-from-right,[dir=rtl] .fa-arrow-alt-left,[dir=rtl] .fa-arrow-alt-right,[dir=rtl] .fa-arrow-alt-square-left,[dir=rtl] .fa-arrow-alt-square-right,[dir=rtl] .fa-arrow-alt-to-left,[dir=rtl] .fa-arrow-alt-to-right,[dir=rtl] .fa-arrow-circle-left,[dir=rtl] .fa-arrow-circle-right,[dir=rtl] .fa-arrow-from-left,[dir=rtl] .fa-arrow-from-right,[dir=rtl] .fa-arrow-left,[dir=rtl] .fa-arrow-right,[dir=rtl] .fa-arrow-square-left,[dir=rtl] .fa-arrow-square-right,[dir=rtl] .fa-arrow-to-left,[dir=rtl] .fa-arrow-to-right,[dir=rtl] .fa-balance-scale-left,[dir=rtl] .fa-balance-scale-right,[dir=rtl] .fa-bed,[dir=rtl] .fa-bed-bunk,[dir=rtl] .fa-bed-empty,[dir=rtl] .fa-border-left,[dir=rtl] .fa-border-right,[dir=rtl] .fa-calendar-check,[dir=rtl] .fa-caret-circle-left,[dir=rtl] .fa-caret-circle-right,[dir=rtl] .fa-caret-left,[dir=rtl] .fa-caret-right,[dir=rtl] .fa-caret-square-left,[dir=rtl] .fa-caret-square-right,[dir=rtl] .fa-cart-arrow-down,[dir=rtl] .fa-cart-plus,[dir=rtl] .fa-chart-area,[dir=rtl] .fa-chart-bar,[dir=rtl] .fa-chart-line,[dir=rtl] .fa-chart-line-down,[dir=rtl] .fa-chart-network,[dir=rtl] .fa-chart-pie,[dir=rtl] .fa-chart-pie-alt,[dir=rtl] .fa-chart-scatter,[dir=rtl] .fa-check-circle,[dir=rtl] .fa-check-square,[dir=rtl] .fa-chevron-circle-left,[dir=rtl] .fa-chevron-circle-right,[dir=rtl] .fa-chevron-double-left,[dir=rtl] .fa-chevron-double-right,[dir=rtl] .fa-chevron-left,[dir=rtl] .fa-chevron-right,[dir=rtl] .fa-chevron-square-left,[dir=rtl] .fa-chevron-square-right,[dir=rtl] .fa-clock,[dir=rtl] .fa-file,[dir=rtl] .fa-file-alt,[dir=rtl] .fa-file-archive,[dir=rtl] .fa-file-audio,[dir=rtl] .fa-file-chart-line,[dir=rtl] .fa-file-chart-pie,[dir=rtl] .fa-file-code,[dir=rtl] .fa-file-excel,[dir=rtl] .fa-file-image,[dir=rtl] .fa-file-pdf,[dir=rtl] .fa-file-powerpoint,[dir=rtl] .fa-file-video,[dir=rtl] .fa-file-word,[dir=rtl] .fa-flag,[dir=rtl] .fa-folder,[dir=rtl] .fa-folder-open,[dir=rtl] .fa-hand-lizard,[dir=rtl] .fa-hand-point-down,[dir=rtl] .fa-hand-point-left,[dir=rtl] .fa-hand-point-right,[dir=rtl] .fa-hand-point-up,[dir=rtl] .fa-hand-scissors,[dir=rtl] .fa-image,[dir=rtl] .fa-long-arrow-alt-left,[dir=rtl] .fa-long-arrow-alt-right,[dir=rtl] .fa-long-arrow-left,[dir=rtl] .fa-long-arrow-right,[dir=rtl] .fa-luggage-cart,[dir=rtl] .fa-moon,[dir=rtl] .fa-pencil,[dir=rtl] .fa-pencil-alt,[dir=rtl] .fa-play-circle,[dir=rtl] .fa-project-diagram,[dir=rtl] .fa-quote-left,[dir=rtl] .fa-quote-right,[dir=rtl] .fa-shopping-cart,[dir=rtl] .fa-thumbs-down,[dir=rtl] .fa-thumbs-up,[dir=rtl] .fa-user-chart{filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=0, mirror=1);transform:scale(-1,1)}[dir=rtl] .fa-spin{animation-direction:reverse}';
642
+
643
+            return $inline_css;
644
+        }
645
+
646
+        /**
647
+         * Show any warnings as an admin notice.
648
+         *
649
+         * @return void
650
+         */
651
+        public function admin_notices() {
652
+            $settings = $this->settings;
653
+
654
+            if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
655
+                if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
656
+                    ?>
657 657
                     <div class="notice  notice-error is-dismissible">
658 658
                         <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'font-awesome-settings' ); ?></p>
659 659
                     </div>
660 660
 					<?php
661
-				}
662
-			} else {
663
-				if ( ! empty( $settings ) ) {
664
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
665
-						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
666
-						?>
661
+                }
662
+            } else {
663
+                if ( ! empty( $settings ) ) {
664
+                    if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
665
+                        $link = admin_url('options-general.php?page=wp-font-awesome-settings');
666
+                        ?>
667 667
                         <div class="notice  notice-error is-dismissible">
668 668
                             <p><?php echo sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'font-awesome-settings' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
669 669
                         </div>
670 670
 						<?php
671
-					}
672
-				}
673
-			}
674
-		}
675
-
676
-		/**
677
-		 * Handle fontawesome add settings to download fontawesome to store locally.
678
-		 *
679
-		 * @since 1.1.1
680
-		 *
681
-		 * @param string $option The option name.
682
-		 * @param mixed  $value  The option value.
683
-		 */
684
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
685
-			// Do nothing if WordPress is being installed.
686
-			if ( wp_installing() ) {
687
-				return;
688
-			}
689
-
690
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
691
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
692
-
693
-				if ( ! empty( $version ) ) {
694
-					$response = $this->download_package( $version, $value );
695
-
696
-					if ( is_wp_error( $response ) ) {
697
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
698
-					}
699
-				}
700
-			}
701
-		}
702
-
703
-		/**
704
-		 * Handle fontawesome update settings to download fontawesome to store locally.
705
-		 *
706
-		 * @since 1.1.0
707
-		 *
708
-		 * @param mixed $old_value The old option value.
709
-		 * @param mixed $value     The new option value.
710
-		 */
711
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
712
-			// Do nothing if WordPress is being installed.
713
-			if ( wp_installing() ) {
714
-				return;
715
-			}
716
-
717
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
718
-				// Old values
719
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
720
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
721
-
722
-				// New values
723
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
724
-
725
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
726
-					$response = $this->download_package( $new_version, $new_value );
727
-
728
-					if ( is_wp_error( $response ) ) {
729
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
730
-					}
731
-				}
732
-			}
733
-		}
734
-
735
-		/**
736
-		 * Get the fonts directory local path.
737
-		 *
738
-		 * @since 1.1.0
739
-		 *
740
-		 * @param string Fonts directory local path.
741
-		 */
742
-		public function get_fonts_dir() {
743
-			$upload_dir = wp_upload_dir( null, false );
744
-
745
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
746
-		}
747
-
748
-		/**
749
-		 * Get the fonts directory local url.
750
-		 *
751
-		 * @since 1.1.0
752
-		 *
753
-		 * @param string Fonts directory local url.
754
-		 */
755
-		public function get_fonts_url() {
756
-			$upload_dir = wp_upload_dir( null, false );
757
-
758
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
759
-		}
760
-
761
-		/**
762
-		 * Check whether load locally active.
763
-		 *
764
-		 * @since 1.1.0
765
-		 *
766
-		 * @return bool True if active else false.
767
-		 */
768
-		public function has_local() {
769
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
-				return true;
771
-			}
772
-
773
-			return false;
774
-		}
775
-
776
-		/**
777
-		 * Get the WP Filesystem access.
778
-		 *
779
-		 * @since 1.1.0
780
-		 *
781
-		 * @return object The WP Filesystem.
782
-		 */
783
-		public function get_wp_filesystem() {
784
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
785
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
786
-			}
787
-
788
-			$access_type = get_filesystem_method();
789
-
790
-			if ( $access_type === 'direct' ) {
791
-				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
792
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
793
-
794
-				/* Initialize the API */
795
-				if ( ! WP_Filesystem( $creds ) ) {
796
-					/* Any problems and we exit */
797
-					return false;
798
-				}
799
-
800
-				global $wp_filesystem;
801
-
802
-				return $wp_filesystem;
803
-				/* Do our file manipulations below */
804
-			} else if ( defined( 'FTP_USER' ) ) {
805
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
806
-
807
-				/* Initialize the API */
808
-				if ( ! WP_Filesystem( $creds ) ) {
809
-					/* Any problems and we exit */
810
-					return false;
811
-				}
812
-
813
-				global $wp_filesystem;
814
-
815
-				return $wp_filesystem;
816
-			} else {
817
-				/* Don't have direct write access. Prompt user with our notice */
818
-				return false;
819
-			}
820
-		}
821
-
822
-		/**
823
-		 * Download the fontawesome package file.
824
-		 *
825
-		 * @since 1.1.0
826
-		 *
827
-		 * @param mixed $version The font awesome.
828
-		 * @param array $option Fontawesome settings.
829
-		 * @return WP_ERROR|bool Error on fail and true on success.
830
-		 */
831
-		public function download_package( $version, $option = array() ) {
832
-			$filename = 'fontawesome-free-' . $version . '-web';
833
-			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
834
-
835
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
836
-				require_once ABSPATH . 'wp-admin/includes/file.php';
837
-			}
838
-
839
-			$download_file = download_url( esc_url_raw( $url ) );
840
-
841
-			if ( is_wp_error( $download_file ) ) {
842
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
843
-			} else if ( empty( $download_file ) ) {
844
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
845
-			}
846
-
847
-			$response = $this->extract_package( $download_file, $filename, true );
848
-
849
-			// Update local version.
850
-			if ( is_wp_error( $response ) ) {
851
-				return $response;
852
-			} else if ( $response ) {
853
-				if ( empty( $option ) ) {
854
-					$option = get_option( 'wp-font-awesome-settings' );
855
-				}
856
-
857
-				$option['local_version'] = $version;
858
-
859
-				// Remove action to prevent looping.
860
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
861
-
862
-				update_option( 'wp-font-awesome-settings', $option );
863
-
864
-				return true;
865
-			}
866
-
867
-			return false;
868
-		}
869
-
870
-		/**
871
-		 * Extract the fontawesome package file.
872
-		 *
873
-		 * @since 1.1.0
874
-		 *
875
-		 * @param string $package The package file path.
876
-		 * @param string $dirname Package file name.
877
-		 * @param bool   $delete_package Delete temp file or not.
878
-		 * @return WP_Error|bool True on success WP_Error on fail.
879
-		 */
880
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
881
-			global $wp_filesystem;
882
-
883
-			$wp_filesystem = $this->get_wp_filesystem();
884
-
885
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
886
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
887
-			} else if ( empty( $wp_filesystem ) ) {
888
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
889
-			}
890
-
891
-			$fonts_dir = $this->get_fonts_dir();
892
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
893
-
894
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
895
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
896
-			}
897
-
898
-			// Unzip package to working directory.
899
-			$result = unzip_file( $package, $fonts_tmp_dir );
900
-
901
-			if ( is_wp_error( $result ) ) {
902
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
903
-
904
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
905
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
906
-				}
907
-
908
-				return $result;
909
-			}
910
-
911
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
912
-				$wp_filesystem->delete( $fonts_dir, true );
913
-			}
914
-
915
-			$extract_dir = $fonts_tmp_dir;
916
-
917
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
918
-				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
919
-			}
920
-
921
-			try {
922
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
923
-			} catch ( Exception $e ) {
924
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
925
-			}
926
-
927
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
928
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
929
-			}
930
-
931
-			// Once extracted, delete the package if required.
932
-			if ( $delete_package ) {
933
-				unlink( $package );
934
-			}
935
-
936
-			return $return;
937
-		}
938
-	}
939
-
940
-	/**
941
-	 * Run the class if found.
942
-	 */
943
-	WP_Font_Awesome_Settings::instance();
671
+                    }
672
+                }
673
+            }
674
+        }
675
+
676
+        /**
677
+         * Handle fontawesome add settings to download fontawesome to store locally.
678
+         *
679
+         * @since 1.1.1
680
+         *
681
+         * @param string $option The option name.
682
+         * @param mixed  $value  The option value.
683
+         */
684
+        public function add_option_wp_font_awesome_settings( $option, $value ) {
685
+            // Do nothing if WordPress is being installed.
686
+            if ( wp_installing() ) {
687
+                return;
688
+            }
689
+
690
+            if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
691
+                $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
692
+
693
+                if ( ! empty( $version ) ) {
694
+                    $response = $this->download_package( $version, $value );
695
+
696
+                    if ( is_wp_error( $response ) ) {
697
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
698
+                    }
699
+                }
700
+            }
701
+        }
702
+
703
+        /**
704
+         * Handle fontawesome update settings to download fontawesome to store locally.
705
+         *
706
+         * @since 1.1.0
707
+         *
708
+         * @param mixed $old_value The old option value.
709
+         * @param mixed $value     The new option value.
710
+         */
711
+        public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
712
+            // Do nothing if WordPress is being installed.
713
+            if ( wp_installing() ) {
714
+                return;
715
+            }
716
+
717
+            if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
718
+                // Old values
719
+                $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
720
+                $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
721
+
722
+                // New values
723
+                $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
724
+
725
+                if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
726
+                    $response = $this->download_package( $new_version, $new_value );
727
+
728
+                    if ( is_wp_error( $response ) ) {
729
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'font-awesome-settings' ) . ' ' . $response->get_error_message(), 'error' );
730
+                    }
731
+                }
732
+            }
733
+        }
734
+
735
+        /**
736
+         * Get the fonts directory local path.
737
+         *
738
+         * @since 1.1.0
739
+         *
740
+         * @param string Fonts directory local path.
741
+         */
742
+        public function get_fonts_dir() {
743
+            $upload_dir = wp_upload_dir( null, false );
744
+
745
+            return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
746
+        }
747
+
748
+        /**
749
+         * Get the fonts directory local url.
750
+         *
751
+         * @since 1.1.0
752
+         *
753
+         * @param string Fonts directory local url.
754
+         */
755
+        public function get_fonts_url() {
756
+            $upload_dir = wp_upload_dir( null, false );
757
+
758
+            return $upload_dir['baseurl'] .  '/ayefonts/fa/';
759
+        }
760
+
761
+        /**
762
+         * Check whether load locally active.
763
+         *
764
+         * @since 1.1.0
765
+         *
766
+         * @return bool True if active else false.
767
+         */
768
+        public function has_local() {
769
+            if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
+                return true;
771
+            }
772
+
773
+            return false;
774
+        }
775
+
776
+        /**
777
+         * Get the WP Filesystem access.
778
+         *
779
+         * @since 1.1.0
780
+         *
781
+         * @return object The WP Filesystem.
782
+         */
783
+        public function get_wp_filesystem() {
784
+            if ( ! function_exists( 'get_filesystem_method' ) ) {
785
+                require_once( ABSPATH . "/wp-admin/includes/file.php" );
786
+            }
787
+
788
+            $access_type = get_filesystem_method();
789
+
790
+            if ( $access_type === 'direct' ) {
791
+                /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
792
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
793
+
794
+                /* Initialize the API */
795
+                if ( ! WP_Filesystem( $creds ) ) {
796
+                    /* Any problems and we exit */
797
+                    return false;
798
+                }
799
+
800
+                global $wp_filesystem;
801
+
802
+                return $wp_filesystem;
803
+                /* Do our file manipulations below */
804
+            } else if ( defined( 'FTP_USER' ) ) {
805
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
806
+
807
+                /* Initialize the API */
808
+                if ( ! WP_Filesystem( $creds ) ) {
809
+                    /* Any problems and we exit */
810
+                    return false;
811
+                }
812
+
813
+                global $wp_filesystem;
814
+
815
+                return $wp_filesystem;
816
+            } else {
817
+                /* Don't have direct write access. Prompt user with our notice */
818
+                return false;
819
+            }
820
+        }
821
+
822
+        /**
823
+         * Download the fontawesome package file.
824
+         *
825
+         * @since 1.1.0
826
+         *
827
+         * @param mixed $version The font awesome.
828
+         * @param array $option Fontawesome settings.
829
+         * @return WP_ERROR|bool Error on fail and true on success.
830
+         */
831
+        public function download_package( $version, $option = array() ) {
832
+            $filename = 'fontawesome-free-' . $version . '-web';
833
+            $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
834
+
835
+            if ( ! function_exists( 'wp_handle_upload' ) ) {
836
+                require_once ABSPATH . 'wp-admin/includes/file.php';
837
+            }
838
+
839
+            $download_file = download_url( esc_url_raw( $url ) );
840
+
841
+            if ( is_wp_error( $download_file ) ) {
842
+                return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'font-awesome-settings' ) );
843
+            } else if ( empty( $download_file ) ) {
844
+                return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'font-awesome-settings' ) );
845
+            }
846
+
847
+            $response = $this->extract_package( $download_file, $filename, true );
848
+
849
+            // Update local version.
850
+            if ( is_wp_error( $response ) ) {
851
+                return $response;
852
+            } else if ( $response ) {
853
+                if ( empty( $option ) ) {
854
+                    $option = get_option( 'wp-font-awesome-settings' );
855
+                }
856
+
857
+                $option['local_version'] = $version;
858
+
859
+                // Remove action to prevent looping.
860
+                remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
861
+
862
+                update_option( 'wp-font-awesome-settings', $option );
863
+
864
+                return true;
865
+            }
866
+
867
+            return false;
868
+        }
869
+
870
+        /**
871
+         * Extract the fontawesome package file.
872
+         *
873
+         * @since 1.1.0
874
+         *
875
+         * @param string $package The package file path.
876
+         * @param string $dirname Package file name.
877
+         * @param bool   $delete_package Delete temp file or not.
878
+         * @return WP_Error|bool True on success WP_Error on fail.
879
+         */
880
+        public function extract_package( $package, $dirname = '', $delete_package = false ) {
881
+            global $wp_filesystem;
882
+
883
+            $wp_filesystem = $this->get_wp_filesystem();
884
+
885
+            if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
886
+                return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'font-awesome-settings' ) );
887
+            } else if ( empty( $wp_filesystem ) ) {
888
+                return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'font-awesome-settings' ) );
889
+            }
890
+
891
+            $fonts_dir = $this->get_fonts_dir();
892
+            $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
893
+
894
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
895
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
896
+            }
897
+
898
+            // Unzip package to working directory.
899
+            $result = unzip_file( $package, $fonts_tmp_dir );
900
+
901
+            if ( is_wp_error( $result ) ) {
902
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
903
+
904
+                if ( 'incompatible_archive' === $result->get_error_code() ) {
905
+                    return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'font-awesome-settings' ) );
906
+                }
907
+
908
+                return $result;
909
+            }
910
+
911
+            if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
912
+                $wp_filesystem->delete( $fonts_dir, true );
913
+            }
914
+
915
+            $extract_dir = $fonts_tmp_dir;
916
+
917
+            if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
918
+                $extract_dir .= $dirname . DIRECTORY_SEPARATOR;
919
+            }
920
+
921
+            try {
922
+                $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
923
+            } catch ( Exception $e ) {
924
+                $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'font-awesome-settings' ) );
925
+            }
926
+
927
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
928
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
929
+            }
930
+
931
+            // Once extracted, delete the package if required.
932
+            if ( $delete_package ) {
933
+                unlink( $package );
934
+            }
935
+
936
+            return $return;
937
+        }
938
+    }
939
+
940
+    /**
941
+     * Run the class if found.
942
+     */
943
+    WP_Font_Awesome_Settings::instance();
944 944
 }
Please login to merge, or discard this patch.