Completed
Push — master ( 04a827...87ad6d )
by Kiran
32s queued 28s
created
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-address.php 2 patches
Indentation   +277 added lines, -277 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -16,85 +16,85 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Meta_Box_Invoice_Address {
18 18
 
19
-	/**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
24
-	public static function output( $post ) {
25
-
26
-		// Prepare the invoice.
27
-		$invoice  = new WPInv_Invoice( $post );
28
-		$customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-		$customer = new WP_User( $customer );
30
-		$display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-		wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
32
-
33
-		// Address fields.
34
-		$address_fields = array(
35
-			'first_name' => array(
36
-				'label' => __( 'First Name', 'invoicing' ),
37
-				'type'  => 'text',
38
-			),
39
-			'last_name'  => array(
40
-				'label' => __( 'Last Name', 'invoicing' ),
41
-				'type'  => 'text',
42
-			),
43
-			'company'    => array(
44
-				'label' => __( 'Company', 'invoicing' ),
45
-				'type'  => 'text',
46
-				'class' => 'getpaid-recalculate-prices-on-change',
47
-			),
48
-			'vat_number' => array(
49
-				'label' => __( 'VAT Number', 'invoicing' ),
50
-				'type'  => 'text',
51
-				'class' => 'getpaid-recalculate-prices-on-change',
52
-			),
53
-			'address'    => array(
54
-				'label' => __( 'Address', 'invoicing' ),
55
-				'type'  => 'text',
56
-			),
57
-			'city'       => array(
58
-				'label' => __( 'City', 'invoicing' ),
59
-				'type'  => 'text',
60
-			),
61
-			'country'    => array(
62
-				'label'       => __( 'Country', 'invoicing' ),
63
-				'type'        => 'select',
64
-				'class'       => 'getpaid-recalculate-prices-on-change',
65
-				'options'     => wpinv_get_country_list(),
66
-				'placeholder' => __( 'Choose a country', 'invoicing' ),
67
-			),
68
-			'state'      => array(
69
-				'label' => __( 'State', 'invoicing' ),
70
-				'type'  => 'text',
71
-				'class' => 'getpaid-recalculate-prices-on-change',
72
-			),
73
-			'zip'        => array(
74
-				'label' => __( 'Zip', 'invoicing' ),
75
-				'type'  => 'text',
76
-			),
77
-			'phone'      => array(
78
-				'label' => __( 'Phone', 'invoicing' ),
79
-				'type'  => 'text',
80
-			),
81
-		);
82
-
83
-		$states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
84
-
85
-		if ( ! empty( $states ) ) {
86
-			$address_fields['state']['type']        = 'select';
87
-			$address_fields['state']['options']     = $states;
88
-			$address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
89
-		}
90
-
91
-		// Maybe remove the VAT field.
92
-		if ( ! wpinv_use_taxes() ) {
93
-			unset( $address_fields['vat_number'] );
94
-		}
95
-
96
-		$address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
97
-		?>
19
+    /**
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24
+    public static function output( $post ) {
25
+
26
+        // Prepare the invoice.
27
+        $invoice  = new WPInv_Invoice( $post );
28
+        $customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
+        $customer = new WP_User( $customer );
30
+        $display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
+        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
32
+
33
+        // Address fields.
34
+        $address_fields = array(
35
+            'first_name' => array(
36
+                'label' => __( 'First Name', 'invoicing' ),
37
+                'type'  => 'text',
38
+            ),
39
+            'last_name'  => array(
40
+                'label' => __( 'Last Name', 'invoicing' ),
41
+                'type'  => 'text',
42
+            ),
43
+            'company'    => array(
44
+                'label' => __( 'Company', 'invoicing' ),
45
+                'type'  => 'text',
46
+                'class' => 'getpaid-recalculate-prices-on-change',
47
+            ),
48
+            'vat_number' => array(
49
+                'label' => __( 'VAT Number', 'invoicing' ),
50
+                'type'  => 'text',
51
+                'class' => 'getpaid-recalculate-prices-on-change',
52
+            ),
53
+            'address'    => array(
54
+                'label' => __( 'Address', 'invoicing' ),
55
+                'type'  => 'text',
56
+            ),
57
+            'city'       => array(
58
+                'label' => __( 'City', 'invoicing' ),
59
+                'type'  => 'text',
60
+            ),
61
+            'country'    => array(
62
+                'label'       => __( 'Country', 'invoicing' ),
63
+                'type'        => 'select',
64
+                'class'       => 'getpaid-recalculate-prices-on-change',
65
+                'options'     => wpinv_get_country_list(),
66
+                'placeholder' => __( 'Choose a country', 'invoicing' ),
67
+            ),
68
+            'state'      => array(
69
+                'label' => __( 'State', 'invoicing' ),
70
+                'type'  => 'text',
71
+                'class' => 'getpaid-recalculate-prices-on-change',
72
+            ),
73
+            'zip'        => array(
74
+                'label' => __( 'Zip', 'invoicing' ),
75
+                'type'  => 'text',
76
+            ),
77
+            'phone'      => array(
78
+                'label' => __( 'Phone', 'invoicing' ),
79
+                'type'  => 'text',
80
+            ),
81
+        );
82
+
83
+        $states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
84
+
85
+        if ( ! empty( $states ) ) {
86
+            $address_fields['state']['type']        = 'select';
87
+            $address_fields['state']['options']     = $states;
88
+            $address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
89
+        }
90
+
91
+        // Maybe remove the VAT field.
92
+        if ( ! wpinv_use_taxes() ) {
93
+            unset( $address_fields['vat_number'] );
94
+        }
95
+
96
+        $address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
97
+        ?>
98 98
 
99 99
 		<style>
100 100
 			#wpinv-address label {
@@ -119,19 +119,19 @@  discard block
 block discarded – undo
119 119
 							<div id="getpaid-invoice-email-wrapper" class="d-none">
120 120
 								<input type="hidden" id="getpaid-invoice-create-new-user" name="wpinv_new_user" value="" />
121 121
 								<?php
122
-									aui()->input(
123
-										array(
124
-											'type'        => 'text',
125
-											'id'          => 'getpaid-invoice-new-user-email',
126
-											'name'        => 'wpinv_email',
127
-											'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
128
-											'label_type'  => 'vertical',
129
-											'placeholder' => '[email protected]',
130
-											'class'       => 'form-control-sm',
131
-										),
132
-										true
133
-									);
134
-								?>
122
+                                    aui()->input(
123
+                                        array(
124
+                                            'type'        => 'text',
125
+                                            'id'          => 'getpaid-invoice-new-user-email',
126
+                                            'name'        => 'wpinv_email',
127
+                                            'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
128
+                                            'label_type'  => 'vertical',
129
+                                            'placeholder' => '[email protected]',
130
+                                            'class'       => 'form-control-sm',
131
+                                        ),
132
+                                        true
133
+                                    );
134
+                                ?>
135 135
 							</div>
136 136
 						</div>
137 137
 						<div class="col-12 col-sm-6 form-group mb-3 mt-sm-4">
@@ -155,39 +155,39 @@  discard block
 block discarded – undo
155 155
 							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper">
156 156
 								<?php
157 157
 
158
-									if ( 'select' === $field['type'] ) {
159
-										aui()->select(
160
-											array(
161
-												'id'               => 'wpinv_' . $key,
162
-												'name'             => 'wpinv_' . $key,
163
-												'label'            => $field['label'],
164
-												'label_type'       => 'vertical',
165
-												'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
166
-												'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
167
-												'value'            => $invoice->get( $key, 'edit' ),
168
-												'options'          => $field['options'],
169
-												'data-allow-clear' => 'false',
170
-												'select2'          => true,
171
-											),
172
-											true
173
-										);
174
-									} else {
175
-										aui()->input(
176
-											array(
177
-												'type'        => $field['type'],
178
-												'id'          => 'wpinv_' . $key,
179
-												'name'        => 'wpinv_' . $key,
180
-												'label'       => $field['label'],
181
-												'label_type'  => 'vertical',
182
-												'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
183
-												'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
184
-												'value'       => $invoice->get( $key, 'edit' ),
185
-											),
186
-											true
187
-										);
188
-									}
189
-
190
-								?>
158
+                                    if ( 'select' === $field['type'] ) {
159
+                                        aui()->select(
160
+                                            array(
161
+                                                'id'               => 'wpinv_' . $key,
162
+                                                'name'             => 'wpinv_' . $key,
163
+                                                'label'            => $field['label'],
164
+                                                'label_type'       => 'vertical',
165
+                                                'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
166
+                                                'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
167
+                                                'value'            => $invoice->get( $key, 'edit' ),
168
+                                                'options'          => $field['options'],
169
+                                                'data-allow-clear' => 'false',
170
+                                                'select2'          => true,
171
+                                            ),
172
+                                            true
173
+                                        );
174
+                                    } else {
175
+                                        aui()->input(
176
+                                            array(
177
+                                                'type'        => $field['type'],
178
+                                                'id'          => 'wpinv_' . $key,
179
+                                                'name'        => 'wpinv_' . $key,
180
+                                                'label'       => $field['label'],
181
+                                                'label_type'  => 'vertical',
182
+                                                'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
183
+                                                'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
184
+                                                'value'       => $invoice->get( $key, 'edit' ),
185
+                                            ),
186
+                                            true
187
+                                        );
188
+                                    }
189
+
190
+                                ?>
191 191
 							</div>
192 192
 						<?php endforeach; ?>
193 193
 					</div>
@@ -198,48 +198,48 @@  discard block
 block discarded – undo
198 198
 						<div class="row">
199 199
 							<div class="col-12 col-sm-6">
200 200
 								<?php
201
-									aui()->select(
202
-										array(
203
-											'id'          => 'wpinv_template',
204
-											'name'        => 'wpinv_template',
205
-											'label'       => __( 'Template', 'invoicing' ),
206
-											'label_type'  => 'vertical',
207
-											'placeholder' => __( 'Choose a template', 'invoicing' ),
208
-											'class'       => 'form-control-sm',
209
-											'value'       => $invoice->get_template( 'edit' ),
210
-											'options'     => array(
211
-												'quantity' => __( 'Quantity', 'invoicing' ),
212
-												'hours'    => __( 'Hours', 'invoicing' ),
213
-											),
214
-											'data-allow-clear' => 'false',
215
-											'select2'     => true,
216
-										),
217
-										true
218
-									);
219
-								?>
201
+                                    aui()->select(
202
+                                        array(
203
+                                            'id'          => 'wpinv_template',
204
+                                            'name'        => 'wpinv_template',
205
+                                            'label'       => __( 'Template', 'invoicing' ),
206
+                                            'label_type'  => 'vertical',
207
+                                            'placeholder' => __( 'Choose a template', 'invoicing' ),
208
+                                            'class'       => 'form-control-sm',
209
+                                            'value'       => $invoice->get_template( 'edit' ),
210
+                                            'options'     => array(
211
+                                                'quantity' => __( 'Quantity', 'invoicing' ),
212
+                                                'hours'    => __( 'Hours', 'invoicing' ),
213
+                                            ),
214
+                                            'data-allow-clear' => 'false',
215
+                                            'select2'     => true,
216
+                                        ),
217
+                                        true
218
+                                    );
219
+                                ?>
220 220
 							</div>
221 221
 							<div class="col-12 col-sm-6">
222 222
 								<?php
223 223
 
224
-									// Set currency.
225
-									aui()->select(
226
-										array(
227
-											'id'          => 'wpinv_currency',
228
-											'name'        => 'wpinv_currency',
229
-											'label'       => __( 'Currency', 'invoicing' ),
230
-											'label_type'  => 'vertical',
231
-											'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
232
-											'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
-											'value'       => $invoice->get_currency( 'edit' ),
234
-											'required'    => false,
235
-											'data-allow-clear' => 'false',
236
-											'select2'     => true,
237
-											'options'     => wpinv_get_currencies(),
238
-										),
239
-										true
240
-									);
241
-
242
-								?>
224
+                                    // Set currency.
225
+                                    aui()->select(
226
+                                        array(
227
+                                            'id'          => 'wpinv_currency',
228
+                                            'name'        => 'wpinv_currency',
229
+                                            'label'       => __( 'Currency', 'invoicing' ),
230
+                                            'label_type'  => 'vertical',
231
+                                            'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
232
+                                            'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
+                                            'value'       => $invoice->get_currency( 'edit' ),
234
+                                            'required'    => false,
235
+                                            'data-allow-clear' => 'false',
236
+                                            'select2'     => true,
237
+                                            'options'     => wpinv_get_currencies(),
238
+                                        ),
239
+                                        true
240
+                                    );
241
+
242
+                                ?>
243 243
 							</div>
244 244
 						</div>
245 245
 
@@ -249,123 +249,123 @@  discard block
 block discarded – undo
249 249
 					<div class="row">
250 250
 						<div class="col-12 col-sm-6">
251 251
 							<?php
252
-								aui()->input(
253
-									array(
254
-										'type'        => 'text',
255
-										'id'          => 'wpinv_company_id',
256
-										'name'        => 'wpinv_company_id',
257
-										'label'       => __( 'Company ID', 'invoicing' ),
258
-										'label_type'  => 'vertical',
259
-										'placeholder' => '',
260
-										'class'       => 'form-control-sm',
261
-										'value'       => $invoice->get_company_id( 'edit' ),
262
-									),
263
-									true
264
-								);
265
-							?>
252
+                                aui()->input(
253
+                                    array(
254
+                                        'type'        => 'text',
255
+                                        'id'          => 'wpinv_company_id',
256
+                                        'name'        => 'wpinv_company_id',
257
+                                        'label'       => __( 'Company ID', 'invoicing' ),
258
+                                        'label_type'  => 'vertical',
259
+                                        'placeholder' => '',
260
+                                        'class'       => 'form-control-sm',
261
+                                        'value'       => $invoice->get_company_id( 'edit' ),
262
+                                    ),
263
+                                    true
264
+                                );
265
+                            ?>
266 266
 						</div>
267 267
 					</div>
268 268
 
269 269
 					<?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?>
270 270
 			</div>
271 271
 		<?php
272
-	}
273
-
274
-	/**
275
-	 * Save meta box data.
276
-	 *
277
-	 * @param int $post_id
278
-	 * @param array $posted the posted data.
279
-	 */
280
-	public static function save( $post_id, $posted ) {
281
-
282
-		// Prepare the invoice.
283
-		$invoice = new WPInv_Invoice( $post_id );
284
-
285
-		// Load new data.
286
-		$invoice->set_props(
287
-			array(
288
-				'template'       => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null,
289
-				'email_cc'       => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null,
290
-				'disable_taxes'  => ! empty( $posted['disable_taxes'] ),
291
-				'currency'       => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null,
292
-				'gateway'        => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null,
293
-				'address'        => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null,
294
-				'vat_number'     => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null,
295
-				'company'        => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null,
296
-				'company_id'     => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null,
297
-				'zip'            => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null,
298
-				'state'          => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null,
299
-				'city'           => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null,
300
-				'country'        => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null,
301
-				'phone'          => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null,
302
-				'first_name'     => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null,
303
-				'last_name'      => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null,
304
-				'author'         => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null,
305
-				'date_created'   => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null,
306
-				'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null,
307
-				'due_date'       => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null,
308
-				'number'         => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null,
309
-				'status'         => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null,
310
-			)
311
-		);
312
-
313
-		// Discount code.
314
-		if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
315
-
316
-			if ( isset( $posted['wpinv_discount_code'] ) ) {
317
-				$invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) );
318
-			}
319
-
320
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
321
-			if ( $discount->exists() ) {
322
-				$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
323
-			} else {
324
-				$invoice->remove_discount( 'discount_code' );
325
-			}
326
-
327
-			// Recalculate totals.
328
-			$invoice->recalculate_total();
329
-
330
-		}
331
-
332
-		// If we're creating a new user...
333
-		if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) {
334
-
335
-			// Attempt to create the user.
336
-			$user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
337
-
338
-			// If successful, update the invoice author.
339
-			if ( is_numeric( $user ) ) {
340
-				$invoice->set_author( $user );
341
-			} else {
342
-				wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
343
-			}
344
-		}
345
-
346
-		// Do not send new invoice notifications.
347
-		$GLOBALS['wpinv_skip_invoice_notification'] = true;
348
-
349
-		// Save the invoice.
350
-		$invoice->save();
351
-
352
-		// Save the user address.
353
-		getpaid_save_invoice_user_address( $invoice );
354
-
355
-		// Undo do not send new invoice notifications.
356
-		$GLOBALS['wpinv_skip_invoice_notification'] = false;
357
-
358
-		// (Maybe) send new user notification.
359
-		$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
360
-		if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
361
-			wp_send_new_user_notifications( $user, 'user' );
362
-		}
363
-
364
-		if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) {
365
-			getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
366
-		}
367
-
368
-		// Fires after an invoice is saved.
369
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
370
-	}
272
+    }
273
+
274
+    /**
275
+     * Save meta box data.
276
+     *
277
+     * @param int $post_id
278
+     * @param array $posted the posted data.
279
+     */
280
+    public static function save( $post_id, $posted ) {
281
+
282
+        // Prepare the invoice.
283
+        $invoice = new WPInv_Invoice( $post_id );
284
+
285
+        // Load new data.
286
+        $invoice->set_props(
287
+            array(
288
+                'template'       => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null,
289
+                'email_cc'       => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null,
290
+                'disable_taxes'  => ! empty( $posted['disable_taxes'] ),
291
+                'currency'       => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null,
292
+                'gateway'        => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null,
293
+                'address'        => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null,
294
+                'vat_number'     => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null,
295
+                'company'        => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null,
296
+                'company_id'     => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null,
297
+                'zip'            => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null,
298
+                'state'          => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null,
299
+                'city'           => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null,
300
+                'country'        => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null,
301
+                'phone'          => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null,
302
+                'first_name'     => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null,
303
+                'last_name'      => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null,
304
+                'author'         => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null,
305
+                'date_created'   => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null,
306
+                'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null,
307
+                'due_date'       => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null,
308
+                'number'         => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null,
309
+                'status'         => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null,
310
+            )
311
+        );
312
+
313
+        // Discount code.
314
+        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
315
+
316
+            if ( isset( $posted['wpinv_discount_code'] ) ) {
317
+                $invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) );
318
+            }
319
+
320
+            $discount = new WPInv_Discount( $invoice->get_discount_code() );
321
+            if ( $discount->exists() ) {
322
+                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
323
+            } else {
324
+                $invoice->remove_discount( 'discount_code' );
325
+            }
326
+
327
+            // Recalculate totals.
328
+            $invoice->recalculate_total();
329
+
330
+        }
331
+
332
+        // If we're creating a new user...
333
+        if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) {
334
+
335
+            // Attempt to create the user.
336
+            $user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
337
+
338
+            // If successful, update the invoice author.
339
+            if ( is_numeric( $user ) ) {
340
+                $invoice->set_author( $user );
341
+            } else {
342
+                wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
343
+            }
344
+        }
345
+
346
+        // Do not send new invoice notifications.
347
+        $GLOBALS['wpinv_skip_invoice_notification'] = true;
348
+
349
+        // Save the invoice.
350
+        $invoice->save();
351
+
352
+        // Save the user address.
353
+        getpaid_save_invoice_user_address( $invoice );
354
+
355
+        // Undo do not send new invoice notifications.
356
+        $GLOBALS['wpinv_skip_invoice_notification'] = false;
357
+
358
+        // (Maybe) send new user notification.
359
+        $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
360
+        if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
361
+            wp_send_new_user_notifications( $user, 'user' );
362
+        }
363
+
364
+        if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) {
365
+            getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
366
+        }
367
+
368
+        // Fires after an invoice is saved.
369
+        do_action( 'wpinv_invoice_metabox_saved', $invoice );
370
+    }
371 371
 }
Please login to merge, or discard this patch.
Spacing   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,79 +21,79 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-	public static function output( $post ) {
24
+	public static function output($post) {
25 25
 
26 26
 		// Prepare the invoice.
27
-		$invoice  = new WPInv_Invoice( $post );
28
-		$customer = $invoice->exists() ? $invoice->get_user_id( 'edit' ) : get_current_user_id();
29
-		$customer = new WP_User( $customer );
30
-		$display  = sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email );
31
-		wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
27
+		$invoice  = new WPInv_Invoice($post);
28
+		$customer = $invoice->exists() ? $invoice->get_user_id('edit') : get_current_user_id();
29
+		$customer = new WP_User($customer);
30
+		$display  = sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email);
31
+		wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
32 32
 
33 33
 		// Address fields.
34 34
 		$address_fields = array(
35 35
 			'first_name' => array(
36
-				'label' => __( 'First Name', 'invoicing' ),
36
+				'label' => __('First Name', 'invoicing'),
37 37
 				'type'  => 'text',
38 38
 			),
39 39
 			'last_name'  => array(
40
-				'label' => __( 'Last Name', 'invoicing' ),
40
+				'label' => __('Last Name', 'invoicing'),
41 41
 				'type'  => 'text',
42 42
 			),
43 43
 			'company'    => array(
44
-				'label' => __( 'Company', 'invoicing' ),
44
+				'label' => __('Company', 'invoicing'),
45 45
 				'type'  => 'text',
46 46
 				'class' => 'getpaid-recalculate-prices-on-change',
47 47
 			),
48 48
 			'vat_number' => array(
49
-				'label' => __( 'VAT Number', 'invoicing' ),
49
+				'label' => __('VAT Number', 'invoicing'),
50 50
 				'type'  => 'text',
51 51
 				'class' => 'getpaid-recalculate-prices-on-change',
52 52
 			),
53 53
 			'address'    => array(
54
-				'label' => __( 'Address', 'invoicing' ),
54
+				'label' => __('Address', 'invoicing'),
55 55
 				'type'  => 'text',
56 56
 			),
57 57
 			'city'       => array(
58
-				'label' => __( 'City', 'invoicing' ),
58
+				'label' => __('City', 'invoicing'),
59 59
 				'type'  => 'text',
60 60
 			),
61 61
 			'country'    => array(
62
-				'label'       => __( 'Country', 'invoicing' ),
62
+				'label'       => __('Country', 'invoicing'),
63 63
 				'type'        => 'select',
64 64
 				'class'       => 'getpaid-recalculate-prices-on-change',
65 65
 				'options'     => wpinv_get_country_list(),
66
-				'placeholder' => __( 'Choose a country', 'invoicing' ),
66
+				'placeholder' => __('Choose a country', 'invoicing'),
67 67
 			),
68 68
 			'state'      => array(
69
-				'label' => __( 'State', 'invoicing' ),
69
+				'label' => __('State', 'invoicing'),
70 70
 				'type'  => 'text',
71 71
 				'class' => 'getpaid-recalculate-prices-on-change',
72 72
 			),
73 73
 			'zip'        => array(
74
-				'label' => __( 'Zip', 'invoicing' ),
74
+				'label' => __('Zip', 'invoicing'),
75 75
 				'type'  => 'text',
76 76
 			),
77 77
 			'phone'      => array(
78
-				'label' => __( 'Phone', 'invoicing' ),
78
+				'label' => __('Phone', 'invoicing'),
79 79
 				'type'  => 'text',
80 80
 			),
81 81
 		);
82 82
 
83
-		$states = wpinv_get_country_states( $invoice->get_country( 'edit' ) );
83
+		$states = wpinv_get_country_states($invoice->get_country('edit'));
84 84
 
85
-		if ( ! empty( $states ) ) {
85
+		if (!empty($states)) {
86 86
 			$address_fields['state']['type']        = 'select';
87 87
 			$address_fields['state']['options']     = $states;
88
-			$address_fields['state']['placeholder'] = __( 'Choose a state', 'invoicing' );
88
+			$address_fields['state']['placeholder'] = __('Choose a state', 'invoicing');
89 89
 		}
90 90
 
91 91
 		// Maybe remove the VAT field.
92
-		if ( ! wpinv_use_taxes() ) {
93
-			unset( $address_fields['vat_number'] );
92
+		if (!wpinv_use_taxes()) {
93
+			unset($address_fields['vat_number']);
94 94
 		}
95 95
 
96
-		$address_fields = apply_filters( 'getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice );
96
+		$address_fields = apply_filters('getpaid_admin_edit_invoice_address_fields', $address_fields, $invoice);
97 97
 		?>
98 98
 
99 99
 		<style>
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 						<div class="col-12 col-sm-6">
108 108
 							<div id="getpaid-invoice-user-id-wrapper" class="form-group mb-3">
109 109
 								<div>
110
-									<label for="post_author_override"><?php esc_html_e( 'Customer', 'invoicing' ); ?></label>
110
+									<label for="post_author_override"><?php esc_html_e('Customer', 'invoicing'); ?></label>
111 111
 								</div>
112 112
 								<div>
113
-									<select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e( 'Search for a customer by email or name', 'invoicing' ); ?>">
114
-										<option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html( $display ); ?> </option>)
113
+									<select name="post_author_override" id="wpinv_post_author_override" class="getpaid-customer-search form-control regular-text" data-placeholder="<?php esc_attr_e('Search for a customer by email or name', 'invoicing'); ?>">
114
+										<option selected="selected" value="<?php echo (int) $customer->ID; ?>"><?php echo esc_html($display); ?> </option>)
115 115
 									</select>
116 116
 								</div>
117 117
 							</div>
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 											'type'        => 'text',
125 125
 											'id'          => 'getpaid-invoice-new-user-email',
126 126
 											'name'        => 'wpinv_email',
127
-											'label'       => __( 'Email', 'invoicing' ) . '<span class="required">*</span>',
127
+											'label'       => __('Email', 'invoicing') . '<span class="required">*</span>',
128 128
 											'label_type'  => 'vertical',
129 129
 											'placeholder' => '[email protected]',
130 130
 											'class'       => 'form-control-sm',
@@ -135,36 +135,36 @@  discard block
 block discarded – undo
135 135
 							</div>
136 136
 						</div>
137 137
 						<div class="col-12 col-sm-6 form-group mb-3 mt-sm-4">
138
-							<?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
138
+							<?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?>
139 139
 								<a id="getpaid-invoice-fill-user-details" class="button button-small button-secondary" href="javascript:void(0)">
140 140
 									<i aria-hidden="true" class="fa fa-refresh"></i>
141
-									<?php esc_html_e( 'Fill User Details', 'invoicing' ); ?>
141
+									<?php esc_html_e('Fill User Details', 'invoicing'); ?>
142 142
 								</a>
143 143
 								<a id="getpaid-invoice-create-new-user-button" class="button button-small button-secondary" href="javascript:void(0)">
144 144
 									<i aria-hidden="true" class="fa fa-plus"></i>
145
-									<?php esc_html_e( 'Add New User', 'invoicing' ); ?>
145
+									<?php esc_html_e('Add New User', 'invoicing'); ?>
146 146
 								</a>
147 147
 								<a id="getpaid-invoice-cancel-create-new-user" class="button button-small button-secondary d-none" href="javascript:void(0)">
148 148
 									<i aria-hidden="true" class="fa fa-close"></i>
149
-									<?php esc_html_e( 'Cancel', 'invoicing' ); ?>
149
+									<?php esc_html_e('Cancel', 'invoicing'); ?>
150 150
 								</a>
151 151
 							<?php endif; ?>
152 152
 						</div>
153 153
 
154
-						<?php foreach ( $address_fields as $key => $field ) : ?>
155
-							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr( $key ); ?>--wrapper">
154
+						<?php foreach ($address_fields as $key => $field) : ?>
155
+							<div class="col-12 col-sm-6 getpaid-invoice-address-field__<?php echo esc_attr($key); ?>--wrapper">
156 156
 								<?php
157 157
 
158
-									if ( 'select' === $field['type'] ) {
158
+									if ('select' === $field['type']) {
159 159
 										aui()->select(
160 160
 											array(
161 161
 												'id'               => 'wpinv_' . $key,
162 162
 												'name'             => 'wpinv_' . $key,
163 163
 												'label'            => $field['label'],
164 164
 												'label_type'       => 'vertical',
165
-												'placeholder'      => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
166
-												'class'            => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
167
-												'value'            => $invoice->get( $key, 'edit' ),
165
+												'placeholder'      => isset($field['placeholder']) ? $field['placeholder'] : '',
166
+												'class'            => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''),
167
+												'value'            => $invoice->get($key, 'edit'),
168 168
 												'options'          => $field['options'],
169 169
 												'data-allow-clear' => 'false',
170 170
 												'select2'          => true,
@@ -179,9 +179,9 @@  discard block
 block discarded – undo
179 179
 												'name'        => 'wpinv_' . $key,
180 180
 												'label'       => $field['label'],
181 181
 												'label_type'  => 'vertical',
182
-												'placeholder' => isset( $field['placeholder'] ) ? $field['placeholder'] : '',
183
-												'class'       => 'form-control-sm ' . ( isset( $field['class'] ) ? $field['class'] : '' ),
184
-												'value'       => $invoice->get( $key, 'edit' ),
182
+												'placeholder' => isset($field['placeholder']) ? $field['placeholder'] : '',
183
+												'class'       => 'form-control-sm ' . (isset($field['class']) ? $field['class'] : ''),
184
+												'value'       => $invoice->get($key, 'edit'),
185 185
 											),
186 186
 											true
187 187
 										);
@@ -192,8 +192,8 @@  discard block
 block discarded – undo
192 192
 						<?php endforeach; ?>
193 193
 					</div>
194 194
 
195
-					<?php if ( ! apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) : ?>
196
-						<?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?>
195
+					<?php if (!apply_filters('getpaid_use_new_invoice_items_metabox', false)) : ?>
196
+						<?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?>
197 197
 
198 198
 						<div class="row">
199 199
 							<div class="col-12 col-sm-6">
@@ -202,14 +202,14 @@  discard block
 block discarded – undo
202 202
 										array(
203 203
 											'id'          => 'wpinv_template',
204 204
 											'name'        => 'wpinv_template',
205
-											'label'       => __( 'Template', 'invoicing' ),
205
+											'label'       => __('Template', 'invoicing'),
206 206
 											'label_type'  => 'vertical',
207
-											'placeholder' => __( 'Choose a template', 'invoicing' ),
207
+											'placeholder' => __('Choose a template', 'invoicing'),
208 208
 											'class'       => 'form-control-sm',
209
-											'value'       => $invoice->get_template( 'edit' ),
209
+											'value'       => $invoice->get_template('edit'),
210 210
 											'options'     => array(
211
-												'quantity' => __( 'Quantity', 'invoicing' ),
212
-												'hours'    => __( 'Hours', 'invoicing' ),
211
+												'quantity' => __('Quantity', 'invoicing'),
212
+												'hours'    => __('Hours', 'invoicing'),
213 213
 											),
214 214
 											'data-allow-clear' => 'false',
215 215
 											'select2'     => true,
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 										array(
227 227
 											'id'          => 'wpinv_currency',
228 228
 											'name'        => 'wpinv_currency',
229
-											'label'       => __( 'Currency', 'invoicing' ),
229
+											'label'       => __('Currency', 'invoicing'),
230 230
 											'label_type'  => 'vertical',
231
-											'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
231
+											'placeholder' => __('Select Invoice Currency', 'invoicing'),
232 232
 											'class'       => 'form-control-sm getpaid-recalculate-prices-on-change',
233
-											'value'       => $invoice->get_currency( 'edit' ),
233
+											'value'       => $invoice->get_currency('edit'),
234 234
 											'required'    => false,
235 235
 											'data-allow-clear' => 'false',
236 236
 											'select2'     => true,
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 							</div>
244 244
 						</div>
245 245
 
246
-						<?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?>
246
+						<?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?>
247 247
 					<?php endif; ?>
248 248
 
249 249
 					<div class="row">
@@ -254,11 +254,11 @@  discard block
 block discarded – undo
254 254
 										'type'        => 'text',
255 255
 										'id'          => 'wpinv_company_id',
256 256
 										'name'        => 'wpinv_company_id',
257
-										'label'       => __( 'Company ID', 'invoicing' ),
257
+										'label'       => __('Company ID', 'invoicing'),
258 258
 										'label_type'  => 'vertical',
259 259
 										'placeholder' => '',
260 260
 										'class'       => 'form-control-sm',
261
-										'value'       => $invoice->get_company_id( 'edit' ),
261
+										'value'       => $invoice->get_company_id('edit'),
262 262
 									),
263 263
 									true
264 264
 								);
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
 						</div>
267 267
 					</div>
268 268
 
269
-					<?php do_action( 'getpaid_after_metabox_invoice_address', $invoice ); ?>
269
+					<?php do_action('getpaid_after_metabox_invoice_address', $invoice); ?>
270 270
 			</div>
271 271
 		<?php
272 272
 	}
@@ -277,51 +277,51 @@  discard block
 block discarded – undo
277 277
 	 * @param int $post_id
278 278
 	 * @param array $posted the posted data.
279 279
 	 */
280
-	public static function save( $post_id, $posted ) {
280
+	public static function save($post_id, $posted) {
281 281
 
282 282
 		// Prepare the invoice.
283
-		$invoice = new WPInv_Invoice( $post_id );
283
+		$invoice = new WPInv_Invoice($post_id);
284 284
 
285 285
 		// Load new data.
286 286
 		$invoice->set_props(
287 287
 			array(
288
-				'template'       => isset( $posted['wpinv_template'] ) ? wpinv_clean( $posted['wpinv_template'] ) : null,
289
-				'email_cc'       => isset( $posted['wpinv_cc'] ) ? wpinv_clean( $posted['wpinv_cc'] ) : null,
290
-				'disable_taxes'  => ! empty( $posted['disable_taxes'] ),
291
-				'currency'       => isset( $posted['wpinv_currency'] ) ? wpinv_clean( $posted['wpinv_currency'] ) : null,
292
-				'gateway'        => ( $invoice->needs_payment() && isset( $posted['wpinv_gateway'] ) ) ? wpinv_clean( $posted['wpinv_gateway'] ) : null,
293
-				'address'        => isset( $posted['wpinv_address'] ) ? wpinv_clean( $posted['wpinv_address'] ) : null,
294
-				'vat_number'     => isset( $posted['wpinv_vat_number'] ) ? wpinv_clean( $posted['wpinv_vat_number'] ) : null,
295
-				'company'        => isset( $posted['wpinv_company'] ) ? wpinv_clean( $posted['wpinv_company'] ) : null,
296
-				'company_id'     => isset( $posted['wpinv_company_id'] ) ? wpinv_clean( $posted['wpinv_company_id'] ) : null,
297
-				'zip'            => isset( $posted['wpinv_zip'] ) ? wpinv_clean( $posted['wpinv_zip'] ) : null,
298
-				'state'          => isset( $posted['wpinv_state'] ) ? wpinv_clean( $posted['wpinv_state'] ) : null,
299
-				'city'           => isset( $posted['wpinv_city'] ) ? wpinv_clean( $posted['wpinv_city'] ) : null,
300
-				'country'        => isset( $posted['wpinv_country'] ) ? wpinv_clean( $posted['wpinv_country'] ) : null,
301
-				'phone'          => isset( $posted['wpinv_phone'] ) ? wpinv_clean( $posted['wpinv_phone'] ) : null,
302
-				'first_name'     => isset( $posted['wpinv_first_name'] ) ? wpinv_clean( $posted['wpinv_first_name'] ) : null,
303
-				'last_name'      => isset( $posted['wpinv_last_name'] ) ? wpinv_clean( $posted['wpinv_last_name'] ) : null,
304
-				'author'         => isset( $posted['post_author_override'] ) ? wpinv_clean( $posted['post_author_override'] ) : null,
305
-				'date_created'   => isset( $posted['date_created'] ) ? wpinv_clean( $posted['date_created'] ) : null,
306
-				'date_completed' => isset( $posted['wpinv_date_completed'] ) ? wpinv_clean( $posted['wpinv_date_completed'] ) : null,
307
-				'due_date'       => isset( $posted['wpinv_due_date'] ) ? wpinv_clean( $posted['wpinv_due_date'] ) : null,
308
-				'number'         => isset( $posted['wpinv_number'] ) ? wpinv_clean( $posted['wpinv_number'] ) : null,
309
-				'status'         => isset( $posted['wpinv_status'] ) ? wpinv_clean( $posted['wpinv_status'] ) : null,
288
+				'template'       => isset($posted['wpinv_template']) ? wpinv_clean($posted['wpinv_template']) : null,
289
+				'email_cc'       => isset($posted['wpinv_cc']) ? wpinv_clean($posted['wpinv_cc']) : null,
290
+				'disable_taxes'  => !empty($posted['disable_taxes']),
291
+				'currency'       => isset($posted['wpinv_currency']) ? wpinv_clean($posted['wpinv_currency']) : null,
292
+				'gateway'        => ($invoice->needs_payment() && isset($posted['wpinv_gateway'])) ? wpinv_clean($posted['wpinv_gateway']) : null,
293
+				'address'        => isset($posted['wpinv_address']) ? wpinv_clean($posted['wpinv_address']) : null,
294
+				'vat_number'     => isset($posted['wpinv_vat_number']) ? wpinv_clean($posted['wpinv_vat_number']) : null,
295
+				'company'        => isset($posted['wpinv_company']) ? wpinv_clean($posted['wpinv_company']) : null,
296
+				'company_id'     => isset($posted['wpinv_company_id']) ? wpinv_clean($posted['wpinv_company_id']) : null,
297
+				'zip'            => isset($posted['wpinv_zip']) ? wpinv_clean($posted['wpinv_zip']) : null,
298
+				'state'          => isset($posted['wpinv_state']) ? wpinv_clean($posted['wpinv_state']) : null,
299
+				'city'           => isset($posted['wpinv_city']) ? wpinv_clean($posted['wpinv_city']) : null,
300
+				'country'        => isset($posted['wpinv_country']) ? wpinv_clean($posted['wpinv_country']) : null,
301
+				'phone'          => isset($posted['wpinv_phone']) ? wpinv_clean($posted['wpinv_phone']) : null,
302
+				'first_name'     => isset($posted['wpinv_first_name']) ? wpinv_clean($posted['wpinv_first_name']) : null,
303
+				'last_name'      => isset($posted['wpinv_last_name']) ? wpinv_clean($posted['wpinv_last_name']) : null,
304
+				'author'         => isset($posted['post_author_override']) ? wpinv_clean($posted['post_author_override']) : null,
305
+				'date_created'   => isset($posted['date_created']) ? wpinv_clean($posted['date_created']) : null,
306
+				'date_completed' => isset($posted['wpinv_date_completed']) ? wpinv_clean($posted['wpinv_date_completed']) : null,
307
+				'due_date'       => isset($posted['wpinv_due_date']) ? wpinv_clean($posted['wpinv_due_date']) : null,
308
+				'number'         => isset($posted['wpinv_number']) ? wpinv_clean($posted['wpinv_number']) : null,
309
+				'status'         => isset($posted['wpinv_status']) ? wpinv_clean($posted['wpinv_status']) : null,
310 310
 			)
311 311
 		);
312 312
 
313 313
 		// Discount code.
314
-		if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
314
+		if (!$invoice->is_paid() && !$invoice->is_refunded()) {
315 315
 
316
-			if ( isset( $posted['wpinv_discount_code'] ) ) {
317
-				$invoice->set_discount_code( wpinv_clean( $posted['wpinv_discount_code'] ) );
316
+			if (isset($posted['wpinv_discount_code'])) {
317
+				$invoice->set_discount_code(wpinv_clean($posted['wpinv_discount_code']));
318 318
 			}
319 319
 
320
-			$discount = new WPInv_Discount( $invoice->get_discount_code() );
321
-			if ( $discount->exists() ) {
322
-				$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
320
+			$discount = new WPInv_Discount($invoice->get_discount_code());
321
+			if ($discount->exists()) {
322
+				$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
323 323
 			} else {
324
-				$invoice->remove_discount( 'discount_code' );
324
+				$invoice->remove_discount('discount_code');
325 325
 			}
326 326
 
327 327
 			// Recalculate totals.
@@ -330,16 +330,16 @@  discard block
 block discarded – undo
330 330
 		}
331 331
 
332 332
 		// If we're creating a new user...
333
-		if ( ! empty( $posted['wpinv_new_user'] ) && is_email( stripslashes( $posted['wpinv_email'] ) ) ) {
333
+		if (!empty($posted['wpinv_new_user']) && is_email(stripslashes($posted['wpinv_email']))) {
334 334
 
335 335
 			// Attempt to create the user.
336
-			$user = wpinv_create_user( sanitize_email( stripslashes( $posted['wpinv_email'] ) ), $invoice->get_first_name() . $invoice->get_last_name() );
336
+			$user = wpinv_create_user(sanitize_email(stripslashes($posted['wpinv_email'])), $invoice->get_first_name() . $invoice->get_last_name());
337 337
 
338 338
 			// If successful, update the invoice author.
339
-			if ( is_numeric( $user ) ) {
340
-				$invoice->set_author( $user );
339
+			if (is_numeric($user)) {
340
+				$invoice->set_author($user);
341 341
 			} else {
342
-				wpinv_error_log( $user->get_error_message(), __( 'Invoice add new user', 'invoicing' ), __FILE__, __LINE__ );
342
+				wpinv_error_log($user->get_error_message(), __('Invoice add new user', 'invoicing'), __FILE__, __LINE__);
343 343
 			}
344 344
 		}
345 345
 
@@ -350,22 +350,22 @@  discard block
 block discarded – undo
350 350
 		$invoice->save();
351 351
 
352 352
 		// Save the user address.
353
-		getpaid_save_invoice_user_address( $invoice );
353
+		getpaid_save_invoice_user_address($invoice);
354 354
 
355 355
 		// Undo do not send new invoice notifications.
356 356
 		$GLOBALS['wpinv_skip_invoice_notification'] = false;
357 357
 
358 358
 		// (Maybe) send new user notification.
359
-		$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
360
-		if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ) ) ) {
361
-			wp_send_new_user_notifications( $user, 'user' );
359
+		$should_send_notification = wpinv_get_option('disable_new_user_emails');
360
+		if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification))) {
361
+			wp_send_new_user_notifications($user, 'user');
362 362
 		}
363 363
 
364
-		if ( ! empty( $posted['send_to_customer'] ) && ! $invoice->is_draft() ) {
365
-			getpaid()->get( 'invoice_emails' )->user_invoice( $invoice, true );
364
+		if (!empty($posted['send_to_customer']) && !$invoice->is_draft()) {
365
+			getpaid()->get('invoice_emails')->user_invoice($invoice, true);
366 366
 		}
367 367
 
368 368
 		// Fires after an invoice is saved.
369
-		do_action( 'wpinv_invoice_metabox_saved', $invoice );
369
+		do_action('wpinv_invoice_metabox_saved', $invoice);
370 370
 	}
371 371
 }
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -128,7 +128,7 @@
 block discarded – undo
128 128
 
129 129
 				if( !$version || version_compare($version,'5.999','>')){
130 130
 					$url .= 'assets/js/fa-iconpicker-v6.min.js';
131
-				}else{
131
+				} else{
132 132
 					$url .= 'assets/js/fa-iconpicker-v5.min.js';
133 133
 				}
134 134
 
Please login to merge, or discard this patch.
Indentation   +821 added lines, -821 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,406 +21,406 @@  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
-	 */
29
-	class WP_Font_Awesome_Settings {
30
-
31
-		/**
32
-		 * Class version version.
33
-		 *
34
-		 * @var string
35
-		 */
36
-		public $version = '1.1.7';
37
-
38
-		/**
39
-		 * Class textdomain.
40
-		 *
41
-		 * @var string
42
-		 */
43
-		public $textdomain = 'font-awesome-settings';
44
-
45
-		/**
46
-		 * Latest version of Font Awesome at time of publish published.
47
-		 *
48
-		 * @var string
49
-		 */
50
-		public $latest = "6.4.2";
51
-
52
-		/**
53
-		 * The title.
54
-		 *
55
-		 * @var string
56
-		 */
57
-		public $name = 'Font Awesome';
58
-
59
-		/**
60
-		 * Holds the settings values.
61
-		 *
62
-		 * @var array
63
-		 */
64
-		private $settings;
65
-
66
-		/**
67
-		 * WP_Font_Awesome_Settings instance.
68
-		 *
69
-		 * @access private
70
-		 * @since  1.0.0
71
-		 * @var    WP_Font_Awesome_Settings There can be only one!
72
-		 */
73
-		private static $instance = null;
74
-
75
-		/**
76
-		 * Main WP_Font_Awesome_Settings Instance.
77
-		 *
78
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
79
-		 *
80
-		 * @since 1.0.0
81
-		 * @static
82
-		 * @return WP_Font_Awesome_Settings - Main instance.
83
-		 */
84
-		public static function instance() {
85
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
86
-				self::$instance = new WP_Font_Awesome_Settings;
87
-
88
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
89
-
90
-				if ( is_admin() ) {
91
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
92
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
93
-					add_action( 'admin_init', array( self::$instance, 'constants' ) );
94
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
95
-				}
96
-
97
-				do_action( 'wp_font_awesome_settings_loaded' );
98
-			}
99
-
100
-			return self::$instance;
101
-		}
102
-
103
-		/**
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     */
29
+    class WP_Font_Awesome_Settings {
30
+
31
+        /**
32
+         * Class version version.
33
+         *
34
+         * @var string
35
+         */
36
+        public $version = '1.1.7';
37
+
38
+        /**
39
+         * Class textdomain.
40
+         *
41
+         * @var string
42
+         */
43
+        public $textdomain = 'font-awesome-settings';
44
+
45
+        /**
46
+         * Latest version of Font Awesome at time of publish published.
47
+         *
48
+         * @var string
49
+         */
50
+        public $latest = "6.4.2";
51
+
52
+        /**
53
+         * The title.
54
+         *
55
+         * @var string
56
+         */
57
+        public $name = 'Font Awesome';
58
+
59
+        /**
60
+         * Holds the settings values.
61
+         *
62
+         * @var array
63
+         */
64
+        private $settings;
65
+
66
+        /**
67
+         * WP_Font_Awesome_Settings instance.
68
+         *
69
+         * @access private
70
+         * @since  1.0.0
71
+         * @var    WP_Font_Awesome_Settings There can be only one!
72
+         */
73
+        private static $instance = null;
74
+
75
+        /**
76
+         * Main WP_Font_Awesome_Settings Instance.
77
+         *
78
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
79
+         *
80
+         * @since 1.0.0
81
+         * @static
82
+         * @return WP_Font_Awesome_Settings - Main instance.
83
+         */
84
+        public static function instance() {
85
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
86
+                self::$instance = new WP_Font_Awesome_Settings;
87
+
88
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
89
+
90
+                if ( is_admin() ) {
91
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
92
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
93
+                    add_action( 'admin_init', array( self::$instance, 'constants' ) );
94
+                    add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
95
+                }
96
+
97
+                do_action( 'wp_font_awesome_settings_loaded' );
98
+            }
99
+
100
+            return self::$instance;
101
+        }
102
+
103
+        /**
104 104
          * Define any constants that may be needed by other packages.
105 105
          *
106
-		 * @return void
107
-		 */
108
-		public function constants(){
106
+         * @return void
107
+         */
108
+        public function constants(){
109 109
 
110
-			// register iconpicker constant
111
-			if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) {
112
-				$url = $this->get_path_url();
113
-				$version = $this->settings['version'];
110
+            // register iconpicker constant
111
+            if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) {
112
+                $url = $this->get_path_url();
113
+                $version = $this->settings['version'];
114 114
 
115
-				if( !$version || version_compare($version,'5.999','>')){
116
-					$url .= 'assets/js/fa-iconpicker-v6.min.js';
117
-				}else{
118
-					$url .= 'assets/js/fa-iconpicker-v5.min.js';
119
-				}
115
+                if( !$version || version_compare($version,'5.999','>')){
116
+                    $url .= 'assets/js/fa-iconpicker-v6.min.js';
117
+                }else{
118
+                    $url .= 'assets/js/fa-iconpicker-v5.min.js';
119
+                }
120 120
 
121
-				define( 'FAS_ICONPICKER_JS_URL', $url );
121
+                define( 'FAS_ICONPICKER_JS_URL', $url );
122 122
 
123
-			}
123
+            }
124 124
 
125 125
             // Set a constant if pro enbaled
126
-			if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) {
127
-				define( 'FAS_PRO', true );
128
-			}
129
-		}
130
-
131
-		/**
132
-		 * Get the url path to the current folder.
133
-		 *
134
-		 * @return string
135
-		 */
136
-		public function get_path_url() {
137
-			$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
138
-			$content_url = untrailingslashit( WP_CONTENT_URL );
139
-
140
-			// Replace http:// to https://.
141
-			if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
142
-				$content_url = str_replace( 'http://', 'https://', $content_url );
143
-			}
144
-
145
-			// Check if we are inside a plugin
146
-			$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
147
-			$url = str_replace( $content_dir, $content_url, $file_dir );
148
-
149
-			return trailingslashit( $url );
150
-		}
151
-
152
-		/**
153
-		 * Initiate the settings and add the required action hooks.
154
-		 *
155
-		 * @since 1.0.8 Settings name wrong - FIXED
156
-		 */
157
-		public function init() {
158
-			// Download fontawesome locally.
159
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
160
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
161
-
162
-			$this->settings = $this->get_settings();
163
-
164
-			// Check if the official plugin is active and use that instead if so.
165
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
166
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
167
-					add_action( 'admin_head', array( $this, 'add_generator' ), 99 );
168
-				}
169
-
170
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
171
-					add_action( 'wp_head', array( $this, 'add_generator' ), 99 );
172
-				}
173
-
174
-				if ( $this->settings['type'] == 'CSS' ) {
175
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
176
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
177
-						//add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend
178
-					}
179
-
180
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
181
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
182
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
183
-					}
184
-				} else {
185
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
186
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
187
-					}
188
-
189
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
190
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
191
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
192
-					}
193
-				}
194
-
195
-				// remove font awesome if set to do so
196
-				if ( $this->settings['dequeue'] == '1' ) {
197
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
198
-				}
199
-			}
200
-
201
-		}
202
-
203
-		/**
204
-		 * Add FA to the FSE.
205
-		 *
206
-		 * @param $editor_settings
207
-		 * @param $block_editor_context
208
-		 *
209
-		 * @return array
210
-		 */
211
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
212
-
213
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
214
-				$url = $this->get_url();
215
-				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
216
-			}
217
-
218
-			return $editor_settings;
219
-		}
220
-
221
-		/**
222
-		 * Add FA to the FSE.
223
-		 *
224
-		 * @param $editor_settings
225
-		 * @param $block_editor_context
226
-		 *
227
-		 * @return array
228
-		 */
229
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
230
-
231
-			$url = $this->get_url();
232
-			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
233
-
234
-			return $editor_settings;
235
-		}
236
-
237
-		/**
238
-		 * Adds the Font Awesome styles.
239
-		 */
240
-		public function enqueue_style() {
241
-			// build url
242
-			$url = $this->get_url();
243
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
244
-
245
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
246
-			wp_register_style( 'font-awesome', $url, array(), $version );
247
-			wp_enqueue_style( 'font-awesome' );
248
-
249
-			// RTL language support CSS.
250
-			if ( is_rtl() ) {
251
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
252
-			}
253
-
254
-			if ( $this->settings['shims'] ) {
255
-				$url = $this->get_url( true );
256
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
257
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
258
-				wp_enqueue_style( 'font-awesome-shims' );
259
-			}
260
-		}
261
-
262
-		/**
263
-		 * Adds the Font Awesome JS.
264
-		 */
265
-		public function enqueue_scripts() {
266
-			// build url
267
-			$url = $this->get_url();
268
-
269
-			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
270
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
271
-			wp_register_script( 'font-awesome', $url, array(), null );
272
-			wp_enqueue_script( 'font-awesome' );
273
-
274
-			if ( $this->settings['shims'] ) {
275
-				$url = $this->get_url( true );
276
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
277
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
278
-				wp_enqueue_script( 'font-awesome-shims' );
279
-			}
280
-		}
281
-
282
-		/**
283
-		 * Get the url of the Font Awesome files.
284
-		 *
285
-		 * @param bool $shims If this is a shim file or not.
286
-		 * @param bool $local Load locally if allowed.
287
-		 *
288
-		 * @return string The url to the file.
289
-		 */
290
-		public function get_url( $shims = false, $local = true ) {
291
-			$script  = $shims ? 'v4-shims' : 'all';
292
-			$sub     = $this->settings['pro'] ? 'pro' : 'use';
293
-			$type    = $this->settings['type'];
294
-			$version = $this->settings['version'];
295
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
296
-			$url     = '';
297
-
298
-			if ( $type == 'KIT' && $kit_url ) {
299
-				if ( $shims ) {
300
-					// if its a kit then we don't add shims here
301
-					return '';
302
-				}
303
-				$url .= $kit_url; // CDN
304
-				$url .= "?wpfas=true"; // set our var so our version is not removed
305
-			} else {
306
-				$v = '';
307
-				// Check and load locally.
308
-				if ( $local && $this->has_local() ) {
309
-					$script .= ".min";
310
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
311
-					$url .= $this->get_fonts_url(); // Local fonts url.
312
-				} else {
313
-					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
314
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
315
-				}
316
-				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
317
-				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
318
-				$url .= "?wpfas=true" . $v; // set our var so our version is not removed
319
-			}
320
-
321
-			return $url;
322
-		}
323
-
324
-		/**
325
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
326
-		 *
327
-		 * 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.
328
-		 *
329
-		 * @param $url
330
-		 * @param $original_url
331
-		 * @param $_context
332
-		 *
333
-		 * @return string The filtered url.
334
-		 */
335
-		public function remove_font_awesome( $url, $original_url, $_context ) {
336
-
337
-			if ( $_context == 'display'
338
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
339
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
340
-			) {// it's a font-awesome-url (probably)
341
-
342
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
343
-					if ( $this->settings['type'] == 'JS' ) {
344
-						if ( $this->settings['js-pseudo'] ) {
345
-							$url .= "' data-search-pseudo-elements defer='defer";
346
-						} else {
347
-							$url .= "' defer='defer";
348
-						}
349
-					}
350
-				} else {
351
-					$url = ''; // removing the url removes the file
352
-				}
353
-
354
-			}
355
-
356
-			return $url;
357
-		}
358
-
359
-		/**
360
-		 * Register the database settings with WordPress.
361
-		 */
362
-		public function register_settings() {
363
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
364
-		}
365
-
366
-		/**
367
-		 * Add the WordPress settings menu item.
368
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
369
-		 */
370
-		public function menu_item() {
371
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
372
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
373
-				$this,
374
-				'settings_page'
375
-			) );
376
-		}
377
-
378
-		/**
379
-		 * Get the current Font Awesome output settings.
380
-		 *
381
-		 * @return array The array of settings.
382
-		 */
383
-		public function get_settings() {
384
-			$db_settings = get_option( 'wp-font-awesome-settings' );
385
-
386
-			$defaults = array(
387
-				'type'      => 'CSS', // type to use, CSS or JS or KIT
388
-				'version'   => '', // latest
389
-				'enqueue'   => '', // front and backend
390
-				'shims'     => '0', // default OFF now in 2020
391
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
392
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
393
-				'pro'       => '0', // if pro CDN url should be used
394
-				'local'     => '0', // Store fonts locally.
395
-				'local_version' => '', // Local fonts version.
396
-				'kit-url'   => '', // the kit url
397
-			);
398
-
399
-			$settings = wp_parse_args( $db_settings, $defaults );
400
-
401
-			/**
402
-			 * Filter the Font Awesome settings.
403
-			 *
404
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
405
-			 */
406
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
407
-		}
408
-
409
-		/**
410
-		 * The settings page html output.
411
-		 */
412
-		public function settings_page() {
413
-			if ( ! current_user_can( 'manage_options' ) ) {
414
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
415
-			}
416
-
417
-			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
418
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
419
-				$this->get_latest_version( $force_api = true );
420
-			}
421
-
422
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
423
-				?>
126
+            if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) {
127
+                define( 'FAS_PRO', true );
128
+            }
129
+        }
130
+
131
+        /**
132
+         * Get the url path to the current folder.
133
+         *
134
+         * @return string
135
+         */
136
+        public function get_path_url() {
137
+            $content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
138
+            $content_url = untrailingslashit( WP_CONTENT_URL );
139
+
140
+            // Replace http:// to https://.
141
+            if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
142
+                $content_url = str_replace( 'http://', 'https://', $content_url );
143
+            }
144
+
145
+            // Check if we are inside a plugin
146
+            $file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
147
+            $url = str_replace( $content_dir, $content_url, $file_dir );
148
+
149
+            return trailingslashit( $url );
150
+        }
151
+
152
+        /**
153
+         * Initiate the settings and add the required action hooks.
154
+         *
155
+         * @since 1.0.8 Settings name wrong - FIXED
156
+         */
157
+        public function init() {
158
+            // Download fontawesome locally.
159
+            add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
160
+            add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
161
+
162
+            $this->settings = $this->get_settings();
163
+
164
+            // Check if the official plugin is active and use that instead if so.
165
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
166
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
167
+                    add_action( 'admin_head', array( $this, 'add_generator' ), 99 );
168
+                }
169
+
170
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
171
+                    add_action( 'wp_head', array( $this, 'add_generator' ), 99 );
172
+                }
173
+
174
+                if ( $this->settings['type'] == 'CSS' ) {
175
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
176
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
177
+                        //add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend
178
+                    }
179
+
180
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
181
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
182
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
183
+                    }
184
+                } else {
185
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
186
+                        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
187
+                    }
188
+
189
+                    if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
190
+                        add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
191
+                        add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
192
+                    }
193
+                }
194
+
195
+                // remove font awesome if set to do so
196
+                if ( $this->settings['dequeue'] == '1' ) {
197
+                    add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
198
+                }
199
+            }
200
+
201
+        }
202
+
203
+        /**
204
+         * Add FA to the FSE.
205
+         *
206
+         * @param $editor_settings
207
+         * @param $block_editor_context
208
+         *
209
+         * @return array
210
+         */
211
+        public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
212
+
213
+            if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
214
+                $url = $this->get_url();
215
+                $editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
216
+            }
217
+
218
+            return $editor_settings;
219
+        }
220
+
221
+        /**
222
+         * Add FA to the FSE.
223
+         *
224
+         * @param $editor_settings
225
+         * @param $block_editor_context
226
+         *
227
+         * @return array
228
+         */
229
+        public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
230
+
231
+            $url = $this->get_url();
232
+            $editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
233
+
234
+            return $editor_settings;
235
+        }
236
+
237
+        /**
238
+         * Adds the Font Awesome styles.
239
+         */
240
+        public function enqueue_style() {
241
+            // build url
242
+            $url = $this->get_url();
243
+            $version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
244
+
245
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
246
+            wp_register_style( 'font-awesome', $url, array(), $version );
247
+            wp_enqueue_style( 'font-awesome' );
248
+
249
+            // RTL language support CSS.
250
+            if ( is_rtl() ) {
251
+                wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
252
+            }
253
+
254
+            if ( $this->settings['shims'] ) {
255
+                $url = $this->get_url( true );
256
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
257
+                wp_register_style( 'font-awesome-shims', $url, array(), $version );
258
+                wp_enqueue_style( 'font-awesome-shims' );
259
+            }
260
+        }
261
+
262
+        /**
263
+         * Adds the Font Awesome JS.
264
+         */
265
+        public function enqueue_scripts() {
266
+            // build url
267
+            $url = $this->get_url();
268
+
269
+            $deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
270
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
271
+            wp_register_script( 'font-awesome', $url, array(), null );
272
+            wp_enqueue_script( 'font-awesome' );
273
+
274
+            if ( $this->settings['shims'] ) {
275
+                $url = $this->get_url( true );
276
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
277
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
278
+                wp_enqueue_script( 'font-awesome-shims' );
279
+            }
280
+        }
281
+
282
+        /**
283
+         * Get the url of the Font Awesome files.
284
+         *
285
+         * @param bool $shims If this is a shim file or not.
286
+         * @param bool $local Load locally if allowed.
287
+         *
288
+         * @return string The url to the file.
289
+         */
290
+        public function get_url( $shims = false, $local = true ) {
291
+            $script  = $shims ? 'v4-shims' : 'all';
292
+            $sub     = $this->settings['pro'] ? 'pro' : 'use';
293
+            $type    = $this->settings['type'];
294
+            $version = $this->settings['version'];
295
+            $kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
296
+            $url     = '';
297
+
298
+            if ( $type == 'KIT' && $kit_url ) {
299
+                if ( $shims ) {
300
+                    // if its a kit then we don't add shims here
301
+                    return '';
302
+                }
303
+                $url .= $kit_url; // CDN
304
+                $url .= "?wpfas=true"; // set our var so our version is not removed
305
+            } else {
306
+                $v = '';
307
+                // Check and load locally.
308
+                if ( $local && $this->has_local() ) {
309
+                    $script .= ".min";
310
+                    $v .= '&ver=' . strip_tags( $this->settings['local_version'] );
311
+                    $url .= $this->get_fonts_url(); // Local fonts url.
312
+                } else {
313
+                    $url .= "https://$sub.fontawesome.com/releases/"; // CDN
314
+                    $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
315
+                }
316
+                $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
317
+                $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
318
+                $url .= "?wpfas=true" . $v; // set our var so our version is not removed
319
+            }
320
+
321
+            return $url;
322
+        }
323
+
324
+        /**
325
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
326
+         *
327
+         * 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.
328
+         *
329
+         * @param $url
330
+         * @param $original_url
331
+         * @param $_context
332
+         *
333
+         * @return string The filtered url.
334
+         */
335
+        public function remove_font_awesome( $url, $original_url, $_context ) {
336
+
337
+            if ( $_context == 'display'
338
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
339
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
340
+            ) {// it's a font-awesome-url (probably)
341
+
342
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
343
+                    if ( $this->settings['type'] == 'JS' ) {
344
+                        if ( $this->settings['js-pseudo'] ) {
345
+                            $url .= "' data-search-pseudo-elements defer='defer";
346
+                        } else {
347
+                            $url .= "' defer='defer";
348
+                        }
349
+                    }
350
+                } else {
351
+                    $url = ''; // removing the url removes the file
352
+                }
353
+
354
+            }
355
+
356
+            return $url;
357
+        }
358
+
359
+        /**
360
+         * Register the database settings with WordPress.
361
+         */
362
+        public function register_settings() {
363
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
364
+        }
365
+
366
+        /**
367
+         * Add the WordPress settings menu item.
368
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
369
+         */
370
+        public function menu_item() {
371
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
372
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
373
+                $this,
374
+                'settings_page'
375
+            ) );
376
+        }
377
+
378
+        /**
379
+         * Get the current Font Awesome output settings.
380
+         *
381
+         * @return array The array of settings.
382
+         */
383
+        public function get_settings() {
384
+            $db_settings = get_option( 'wp-font-awesome-settings' );
385
+
386
+            $defaults = array(
387
+                'type'      => 'CSS', // type to use, CSS or JS or KIT
388
+                'version'   => '', // latest
389
+                'enqueue'   => '', // front and backend
390
+                'shims'     => '0', // default OFF now in 2020
391
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
392
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
393
+                'pro'       => '0', // if pro CDN url should be used
394
+                'local'     => '0', // Store fonts locally.
395
+                'local_version' => '', // Local fonts version.
396
+                'kit-url'   => '', // the kit url
397
+            );
398
+
399
+            $settings = wp_parse_args( $db_settings, $defaults );
400
+
401
+            /**
402
+             * Filter the Font Awesome settings.
403
+             *
404
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
405
+             */
406
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
407
+        }
408
+
409
+        /**
410
+         * The settings page html output.
411
+         */
412
+        public function settings_page() {
413
+            if ( ! current_user_can( 'manage_options' ) ) {
414
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
415
+            }
416
+
417
+            // a hidden way to force the update of the version number via api instead of waiting the 48 hours
418
+            if ( isset( $_REQUEST['force-version-check'] ) ) {
419
+                $this->get_latest_version( $force_api = true );
420
+            }
421
+
422
+            if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
423
+                ?>
424 424
                 <style>
425 425
                     .wpfas-kit-show {
426 426
                         display: none;
@@ -446,16 +446,16 @@  discard block
 block discarded – undo
446 446
                     <h1><?php echo $this->name; ?></h1>
447 447
                     <form method="post" action="options.php" class="fas-settings-form">
448 448
 						<?php
449
-						settings_fields( 'wp-font-awesome-settings' );
450
-						do_settings_sections( 'wp-font-awesome-settings' );
451
-						$table_class = '';
452
-						if ( $this->settings['type'] ) {
453
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
454
-						}
455
-						if ( ! empty( $this->settings['pro'] ) ) {
456
-							$table_class .= ' wpfas-has-pro';
457
-						}
458
-						?>
449
+                        settings_fields( 'wp-font-awesome-settings' );
450
+                        do_settings_sections( 'wp-font-awesome-settings' );
451
+                        $table_class = '';
452
+                        if ( $this->settings['type'] ) {
453
+                            $table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
454
+                        }
455
+                        if ( ! empty( $this->settings['pro'] ) ) {
456
+                            $table_class .= ' wpfas-has-pro';
457
+                        }
458
+                        ?>
459 459
 						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
460 460
 							<?php if ( $this->has_local() ) { ?>
461 461
                                 <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div>
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
                                 <td>
481 481
                                     <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 :(?>"/>
482 482
                                     <span><?php
483
-										echo wp_sprintf(
484
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ),
485
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
486
-											'</a>'
487
-										);
488
-										?></span>
483
+                                        echo wp_sprintf(
484
+                                            __( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ),
485
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
486
+                                            '</a>'
487
+                                        );
488
+                                        ?></span>
489 489
                                 </td>
490 490
                             </tr>
491 491
 
@@ -526,14 +526,14 @@  discard block
 block discarded – undo
526 526
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
527 527
                                     <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')}"/>
528 528
                                     <span><?php
529
-										echo wp_sprintf(
530
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'ayecode-connect' ),
531
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
532
-											' <i class="fas fa-external-link-alt"></i></a>',
533
-											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
534
-											' <i class="fas fa-external-link-alt"></i></a>'
535
-										);
536
-										?></span>
529
+                                        echo wp_sprintf(
530
+                                            __( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'ayecode-connect' ),
531
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
532
+                                            ' <i class="fas fa-external-link-alt"></i></a>',
533
+                                            '<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
534
+                                            ' <i class="fas fa-external-link-alt"></i></a>'
535
+                                        );
536
+                                        ?></span>
537 537
                                 </td>
538 538
                             </tr>
539 539
 
@@ -587,8 +587,8 @@  discard block
 block discarded – undo
587 587
                         </table>
588 588
                         <div class="fas-buttons">
589 589
 							<?php
590
-							submit_button();
591
-							?>
590
+                            submit_button();
591
+                            ?>
592 592
                             <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p>
593 593
 
594 594
                         </div>
@@ -597,414 +597,414 @@  discard block
 block discarded – undo
597 597
                     <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div>
598 598
                 </div>
599 599
 				<?php
600
-			}
601
-		}
602
-
603
-		/**
604
-		 * Check a version number is valid and if so return it or else return an empty string.
605
-		 *
606
-		 * @param $version string The version number to check.
607
-		 *
608
-		 * @since 1.0.6
609
-		 *
610
-		 * @return string Either a valid version number or an empty string.
611
-		 */
612
-		public function validate_version_number( $version ) {
613
-
614
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
615
-				// valid
616
-			} else {
617
-				$version = '';// not validated
618
-			}
619
-
620
-			return $version;
621
-		}
622
-
623
-
624
-		/**
625
-		 * Get the latest version of Font Awesome.
626
-		 *
627
-		 * 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.
628
-		 *
629
-		 * @since 1.0.7
630
-		 * @return mixed|string The latest version number found.
631
-		 */
632
-		public function get_latest_version( $force_api = false ) {
633
-			$latest_version = $this->latest;
634
-
635
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
636
-
637
-			if ( $cache === false || $force_api ) { // its not set
638
-				$api_ver = $this->get_latest_version_from_api();
639
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
640
-					$latest_version = $api_ver;
641
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
642
-				}
643
-			} elseif ( $this->validate_version_number( $cache ) ) {
644
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
645
-					$latest_version = $cache;
646
-				}
647
-			}
648
-
649
-			// Check and auto download fonts locally.
650
-			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 ) ) {
651
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
652
-					$this->download_package( $latest_version );
653
-				}
654
-			}
655
-
656
-			return $latest_version;
657
-		}
658
-
659
-		/**
660
-		 * Get the latest Font Awesome version from the github API.
661
-		 *
662
-		 * @since 1.0.7
663
-		 * @return string The latest version number or `0` on API fail.
664
-		 */
665
-		public function get_latest_version_from_api() {
666
-			$version  = "0";
667
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
668
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
669
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
670
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
671
-					$version = $api_response['tag_name'];
672
-				}
673
-			}
674
-
675
-			return $version;
676
-		}
677
-
678
-		/**
679
-		 * Inline CSS for RTL language support.
680
-		 *
681
-		 * @since 1.0.13
682
-		 * @return string Inline CSS.
683
-		 */
684
-		public function rtl_inline_css() {
685
-			$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}';
686
-
687
-			return $inline_css;
688
-		}
689
-
690
-		/**
691
-		 * Show any warnings as an admin notice.
692
-		 *
693
-		 * @return void
694
-		 */
695
-		public function admin_notices() {
696
-			$settings = $this->settings;
697
-
698
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
699
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
700
-					?>
600
+            }
601
+        }
602
+
603
+        /**
604
+         * Check a version number is valid and if so return it or else return an empty string.
605
+         *
606
+         * @param $version string The version number to check.
607
+         *
608
+         * @since 1.0.6
609
+         *
610
+         * @return string Either a valid version number or an empty string.
611
+         */
612
+        public function validate_version_number( $version ) {
613
+
614
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
615
+                // valid
616
+            } else {
617
+                $version = '';// not validated
618
+            }
619
+
620
+            return $version;
621
+        }
622
+
623
+
624
+        /**
625
+         * Get the latest version of Font Awesome.
626
+         *
627
+         * 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.
628
+         *
629
+         * @since 1.0.7
630
+         * @return mixed|string The latest version number found.
631
+         */
632
+        public function get_latest_version( $force_api = false ) {
633
+            $latest_version = $this->latest;
634
+
635
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
636
+
637
+            if ( $cache === false || $force_api ) { // its not set
638
+                $api_ver = $this->get_latest_version_from_api();
639
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
640
+                    $latest_version = $api_ver;
641
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
642
+                }
643
+            } elseif ( $this->validate_version_number( $cache ) ) {
644
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
645
+                    $latest_version = $cache;
646
+                }
647
+            }
648
+
649
+            // Check and auto download fonts locally.
650
+            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 ) ) {
651
+                if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
652
+                    $this->download_package( $latest_version );
653
+                }
654
+            }
655
+
656
+            return $latest_version;
657
+        }
658
+
659
+        /**
660
+         * Get the latest Font Awesome version from the github API.
661
+         *
662
+         * @since 1.0.7
663
+         * @return string The latest version number or `0` on API fail.
664
+         */
665
+        public function get_latest_version_from_api() {
666
+            $version  = "0";
667
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
668
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
669
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
670
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
671
+                    $version = $api_response['tag_name'];
672
+                }
673
+            }
674
+
675
+            return $version;
676
+        }
677
+
678
+        /**
679
+         * Inline CSS for RTL language support.
680
+         *
681
+         * @since 1.0.13
682
+         * @return string Inline CSS.
683
+         */
684
+        public function rtl_inline_css() {
685
+            $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}';
686
+
687
+            return $inline_css;
688
+        }
689
+
690
+        /**
691
+         * Show any warnings as an admin notice.
692
+         *
693
+         * @return void
694
+         */
695
+        public function admin_notices() {
696
+            $settings = $this->settings;
697
+
698
+            if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
699
+                if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
700
+                    ?>
701 701
                     <div class="notice  notice-error is-dismissible">
702 702
                         <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p>
703 703
                     </div>
704 704
 					<?php
705
-				}
706
-			} else {
707
-				if ( ! empty( $settings ) ) {
708
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
709
-						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
710
-						?>
705
+                }
706
+            } else {
707
+                if ( ! empty( $settings ) ) {
708
+                    if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
709
+                        $link = admin_url('options-general.php?page=wp-font-awesome-settings');
710
+                        ?>
711 711
                         <div class="notice  notice-error is-dismissible">
712 712
                             <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
713 713
                         </div>
714 714
 						<?php
715
-					}
716
-				}
717
-			}
718
-		}
719
-
720
-		/**
721
-		 * Handle fontawesome add settings to download fontawesome to store locally.
722
-		 *
723
-		 * @since 1.1.1
724
-		 *
725
-		 * @param string $option The option name.
726
-		 * @param mixed  $value  The option value.
727
-		 */
728
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
729
-			// Do nothing if WordPress is being installed.
730
-			if ( wp_installing() ) {
731
-				return;
732
-			}
733
-
734
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
735
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
736
-
737
-				if ( ! empty( $version ) ) {
738
-					$response = $this->download_package( $version, $value );
739
-
740
-					if ( is_wp_error( $response ) ) {
741
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
742
-					}
743
-				}
744
-			}
745
-		}
746
-
747
-		/**
748
-		 * Handle fontawesome update settings to download fontawesome to store locally.
749
-		 *
750
-		 * @since 1.1.0
751
-		 *
752
-		 * @param mixed $old_value The old option value.
753
-		 * @param mixed $value     The new option value.
754
-		 */
755
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
756
-			// Do nothing if WordPress is being installed.
757
-			if ( wp_installing() ) {
758
-				return;
759
-			}
760
-
761
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
762
-				// Old values
763
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
764
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
765
-
766
-				// New values
767
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
768
-
769
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
-					$response = $this->download_package( $new_version, $new_value );
771
-
772
-					if ( is_wp_error( $response ) ) {
773
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
774
-					}
775
-				}
776
-			}
777
-		}
778
-
779
-		/**
780
-		 * Get the fonts directory local path.
781
-		 *
782
-		 * @since 1.1.0
783
-		 *
784
-		 * @param string Fonts directory local path.
785
-		 */
786
-		public function get_fonts_dir() {
787
-			$upload_dir = wp_upload_dir( null, false );
788
-
789
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
790
-		}
791
-
792
-		/**
793
-		 * Get the fonts directory local url.
794
-		 *
795
-		 * @since 1.1.0
796
-		 *
797
-		 * @param string Fonts directory local url.
798
-		 */
799
-		public function get_fonts_url() {
800
-			$upload_dir = wp_upload_dir( null, false );
801
-
802
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
803
-		}
804
-
805
-		/**
806
-		 * Check whether load locally active.
807
-		 *
808
-		 * @since 1.1.0
809
-		 *
810
-		 * @return bool True if active else false.
811
-		 */
812
-		public function has_local() {
813
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
814
-				return true;
815
-			}
816
-
817
-			return false;
818
-		}
819
-
820
-		/**
821
-		 * Get the WP Filesystem access.
822
-		 *
823
-		 * @since 1.1.0
824
-		 *
825
-		 * @return object The WP Filesystem.
826
-		 */
827
-		public function get_wp_filesystem() {
828
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
829
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
830
-			}
831
-
832
-			$access_type = get_filesystem_method();
833
-
834
-			if ( $access_type === 'direct' ) {
835
-				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
836
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
837
-
838
-				/* Initialize the API */
839
-				if ( ! WP_Filesystem( $creds ) ) {
840
-					/* Any problems and we exit */
841
-					return false;
842
-				}
843
-
844
-				global $wp_filesystem;
845
-
846
-				return $wp_filesystem;
847
-				/* Do our file manipulations below */
848
-			} else if ( defined( 'FTP_USER' ) ) {
849
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
850
-
851
-				/* Initialize the API */
852
-				if ( ! WP_Filesystem( $creds ) ) {
853
-					/* Any problems and we exit */
854
-					return false;
855
-				}
856
-
857
-				global $wp_filesystem;
858
-
859
-				return $wp_filesystem;
860
-			} else {
861
-				/* Don't have direct write access. Prompt user with our notice */
862
-				return false;
863
-			}
864
-		}
865
-
866
-		/**
867
-		 * Download the fontawesome package file.
868
-		 *
869
-		 * @since 1.1.0
870
-		 *
871
-		 * @param mixed $version The font awesome.
872
-		 * @param array $option Fontawesome settings.
873
-		 * @return WP_ERROR|bool Error on fail and true on success.
874
-		 */
875
-		public function download_package( $version, $option = array() ) {
876
-			$filename = 'fontawesome-free-' . $version . '-web';
877
-			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
878
-
879
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
880
-				require_once ABSPATH . 'wp-admin/includes/file.php';
881
-			}
882
-
883
-			$download_file = download_url( esc_url_raw( $url ) );
884
-
885
-			if ( is_wp_error( $download_file ) ) {
886
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) );
887
-			} else if ( empty( $download_file ) ) {
888
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) );
889
-			}
890
-
891
-			$response = $this->extract_package( $download_file, $filename, true );
892
-
893
-			// Update local version.
894
-			if ( is_wp_error( $response ) ) {
895
-				return $response;
896
-			} else if ( $response ) {
897
-				if ( empty( $option ) ) {
898
-					$option = get_option( 'wp-font-awesome-settings' );
899
-				}
900
-
901
-				$option['local_version'] = $version;
902
-
903
-				// Remove action to prevent looping.
904
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
905
-
906
-				update_option( 'wp-font-awesome-settings', $option );
907
-
908
-				return true;
909
-			}
910
-
911
-			return false;
912
-		}
913
-
914
-		/**
915
-		 * Extract the fontawesome package file.
916
-		 *
917
-		 * @since 1.1.0
918
-		 *
919
-		 * @param string $package The package file path.
920
-		 * @param string $dirname Package file name.
921
-		 * @param bool   $delete_package Delete temp file or not.
922
-		 * @return WP_Error|bool True on success WP_Error on fail.
923
-		 */
924
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
925
-			global $wp_filesystem;
926
-
927
-			$wp_filesystem = $this->get_wp_filesystem();
928
-
929
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
930
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) );
931
-			} else if ( empty( $wp_filesystem ) ) {
932
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) );
933
-			}
934
-
935
-			$fonts_dir = $this->get_fonts_dir();
936
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
937
-
938
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
939
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
940
-			}
941
-
942
-			// Unzip package to working directory.
943
-			$result = unzip_file( $package, $fonts_tmp_dir );
944
-
945
-			if ( is_wp_error( $result ) ) {
946
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
947
-
948
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
949
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) );
950
-				}
951
-
952
-				return $result;
953
-			}
954
-
955
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
956
-				$wp_filesystem->delete( $fonts_dir, true );
957
-			}
958
-
959
-			$extract_dir = $fonts_tmp_dir;
960
-
961
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
962
-				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
963
-			}
964
-
965
-			try {
966
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
967
-			} catch ( Exception $e ) {
968
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) );
969
-			}
970
-
971
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
972
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
973
-			}
974
-
975
-			// Once extracted, delete the package if required.
976
-			if ( $delete_package ) {
977
-				unlink( $package );
978
-			}
979
-
980
-			return $return;
981
-		}
982
-
983
-		/**
984
-		 * Output the version in the header.
985
-		 */
986
-		public function add_generator() {
987
-			$file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
988
-			$plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
989
-
990
-			// Find source plugin/theme.
991
-			$source = array();
992
-			if ( strpos( $file, $plugins_dir ) !== false ) {
993
-				$source = explode( "/", plugin_basename( $file ) );
994
-			} else if ( function_exists( 'get_theme_root' ) ) {
995
-				$themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
996
-
997
-				if ( strpos( $file, $themes_dir ) !== false ) {
998
-					$source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
999
-				}
1000
-			}
1001
-
1002
-			echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />';
1003
-		}
1004
-	}
1005
-
1006
-	/**
1007
-	 * Run the class if found.
1008
-	 */
1009
-	WP_Font_Awesome_Settings::instance();
715
+                    }
716
+                }
717
+            }
718
+        }
719
+
720
+        /**
721
+         * Handle fontawesome add settings to download fontawesome to store locally.
722
+         *
723
+         * @since 1.1.1
724
+         *
725
+         * @param string $option The option name.
726
+         * @param mixed  $value  The option value.
727
+         */
728
+        public function add_option_wp_font_awesome_settings( $option, $value ) {
729
+            // Do nothing if WordPress is being installed.
730
+            if ( wp_installing() ) {
731
+                return;
732
+            }
733
+
734
+            if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
735
+                $version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
736
+
737
+                if ( ! empty( $version ) ) {
738
+                    $response = $this->download_package( $version, $value );
739
+
740
+                    if ( is_wp_error( $response ) ) {
741
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
742
+                    }
743
+                }
744
+            }
745
+        }
746
+
747
+        /**
748
+         * Handle fontawesome update settings to download fontawesome to store locally.
749
+         *
750
+         * @since 1.1.0
751
+         *
752
+         * @param mixed $old_value The old option value.
753
+         * @param mixed $value     The new option value.
754
+         */
755
+        public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
756
+            // Do nothing if WordPress is being installed.
757
+            if ( wp_installing() ) {
758
+                return;
759
+            }
760
+
761
+            if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
762
+                // Old values
763
+                $old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
764
+                $old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
765
+
766
+                // New values
767
+                $new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
768
+
769
+                if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
+                    $response = $this->download_package( $new_version, $new_value );
771
+
772
+                    if ( is_wp_error( $response ) ) {
773
+                        add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
774
+                    }
775
+                }
776
+            }
777
+        }
778
+
779
+        /**
780
+         * Get the fonts directory local path.
781
+         *
782
+         * @since 1.1.0
783
+         *
784
+         * @param string Fonts directory local path.
785
+         */
786
+        public function get_fonts_dir() {
787
+            $upload_dir = wp_upload_dir( null, false );
788
+
789
+            return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
790
+        }
791
+
792
+        /**
793
+         * Get the fonts directory local url.
794
+         *
795
+         * @since 1.1.0
796
+         *
797
+         * @param string Fonts directory local url.
798
+         */
799
+        public function get_fonts_url() {
800
+            $upload_dir = wp_upload_dir( null, false );
801
+
802
+            return $upload_dir['baseurl'] .  '/ayefonts/fa/';
803
+        }
804
+
805
+        /**
806
+         * Check whether load locally active.
807
+         *
808
+         * @since 1.1.0
809
+         *
810
+         * @return bool True if active else false.
811
+         */
812
+        public function has_local() {
813
+            if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
814
+                return true;
815
+            }
816
+
817
+            return false;
818
+        }
819
+
820
+        /**
821
+         * Get the WP Filesystem access.
822
+         *
823
+         * @since 1.1.0
824
+         *
825
+         * @return object The WP Filesystem.
826
+         */
827
+        public function get_wp_filesystem() {
828
+            if ( ! function_exists( 'get_filesystem_method' ) ) {
829
+                require_once( ABSPATH . "/wp-admin/includes/file.php" );
830
+            }
831
+
832
+            $access_type = get_filesystem_method();
833
+
834
+            if ( $access_type === 'direct' ) {
835
+                /* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
836
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
837
+
838
+                /* Initialize the API */
839
+                if ( ! WP_Filesystem( $creds ) ) {
840
+                    /* Any problems and we exit */
841
+                    return false;
842
+                }
843
+
844
+                global $wp_filesystem;
845
+
846
+                return $wp_filesystem;
847
+                /* Do our file manipulations below */
848
+            } else if ( defined( 'FTP_USER' ) ) {
849
+                $creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
850
+
851
+                /* Initialize the API */
852
+                if ( ! WP_Filesystem( $creds ) ) {
853
+                    /* Any problems and we exit */
854
+                    return false;
855
+                }
856
+
857
+                global $wp_filesystem;
858
+
859
+                return $wp_filesystem;
860
+            } else {
861
+                /* Don't have direct write access. Prompt user with our notice */
862
+                return false;
863
+            }
864
+        }
865
+
866
+        /**
867
+         * Download the fontawesome package file.
868
+         *
869
+         * @since 1.1.0
870
+         *
871
+         * @param mixed $version The font awesome.
872
+         * @param array $option Fontawesome settings.
873
+         * @return WP_ERROR|bool Error on fail and true on success.
874
+         */
875
+        public function download_package( $version, $option = array() ) {
876
+            $filename = 'fontawesome-free-' . $version . '-web';
877
+            $url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
878
+
879
+            if ( ! function_exists( 'wp_handle_upload' ) ) {
880
+                require_once ABSPATH . 'wp-admin/includes/file.php';
881
+            }
882
+
883
+            $download_file = download_url( esc_url_raw( $url ) );
884
+
885
+            if ( is_wp_error( $download_file ) ) {
886
+                return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) );
887
+            } else if ( empty( $download_file ) ) {
888
+                return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) );
889
+            }
890
+
891
+            $response = $this->extract_package( $download_file, $filename, true );
892
+
893
+            // Update local version.
894
+            if ( is_wp_error( $response ) ) {
895
+                return $response;
896
+            } else if ( $response ) {
897
+                if ( empty( $option ) ) {
898
+                    $option = get_option( 'wp-font-awesome-settings' );
899
+                }
900
+
901
+                $option['local_version'] = $version;
902
+
903
+                // Remove action to prevent looping.
904
+                remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
905
+
906
+                update_option( 'wp-font-awesome-settings', $option );
907
+
908
+                return true;
909
+            }
910
+
911
+            return false;
912
+        }
913
+
914
+        /**
915
+         * Extract the fontawesome package file.
916
+         *
917
+         * @since 1.1.0
918
+         *
919
+         * @param string $package The package file path.
920
+         * @param string $dirname Package file name.
921
+         * @param bool   $delete_package Delete temp file or not.
922
+         * @return WP_Error|bool True on success WP_Error on fail.
923
+         */
924
+        public function extract_package( $package, $dirname = '', $delete_package = false ) {
925
+            global $wp_filesystem;
926
+
927
+            $wp_filesystem = $this->get_wp_filesystem();
928
+
929
+            if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
930
+                return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) );
931
+            } else if ( empty( $wp_filesystem ) ) {
932
+                return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) );
933
+            }
934
+
935
+            $fonts_dir = $this->get_fonts_dir();
936
+            $fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
937
+
938
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
939
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
940
+            }
941
+
942
+            // Unzip package to working directory.
943
+            $result = unzip_file( $package, $fonts_tmp_dir );
944
+
945
+            if ( is_wp_error( $result ) ) {
946
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
947
+
948
+                if ( 'incompatible_archive' === $result->get_error_code() ) {
949
+                    return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) );
950
+                }
951
+
952
+                return $result;
953
+            }
954
+
955
+            if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
956
+                $wp_filesystem->delete( $fonts_dir, true );
957
+            }
958
+
959
+            $extract_dir = $fonts_tmp_dir;
960
+
961
+            if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
962
+                $extract_dir .= $dirname . DIRECTORY_SEPARATOR;
963
+            }
964
+
965
+            try {
966
+                $return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
967
+            } catch ( Exception $e ) {
968
+                $return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) );
969
+            }
970
+
971
+            if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
972
+                $wp_filesystem->delete( $fonts_tmp_dir, true );
973
+            }
974
+
975
+            // Once extracted, delete the package if required.
976
+            if ( $delete_package ) {
977
+                unlink( $package );
978
+            }
979
+
980
+            return $return;
981
+        }
982
+
983
+        /**
984
+         * Output the version in the header.
985
+         */
986
+        public function add_generator() {
987
+            $file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
988
+            $plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
989
+
990
+            // Find source plugin/theme.
991
+            $source = array();
992
+            if ( strpos( $file, $plugins_dir ) !== false ) {
993
+                $source = explode( "/", plugin_basename( $file ) );
994
+            } else if ( function_exists( 'get_theme_root' ) ) {
995
+                $themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
996
+
997
+                if ( strpos( $file, $themes_dir ) !== false ) {
998
+                    $source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
999
+                }
1000
+            }
1001
+
1002
+            echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />';
1003
+        }
1004
+    }
1005
+
1006
+    /**
1007
+     * Run the class if found.
1008
+     */
1009
+    WP_Font_Awesome_Settings::instance();
1010 1010
 }
Please login to merge, or discard this patch.
Spacing   +242 added lines, -242 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.
@@ -82,19 +82,19 @@  discard block
 block discarded – undo
82 82
 		 * @return WP_Font_Awesome_Settings - Main instance.
83 83
 		 */
84 84
 		public static function instance() {
85
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
85
+			if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) {
86 86
 				self::$instance = new WP_Font_Awesome_Settings;
87 87
 
88
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
88
+				add_action('init', array(self::$instance, 'init')); // set settings
89 89
 
90
-				if ( is_admin() ) {
91
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
92
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
93
-					add_action( 'admin_init', array( self::$instance, 'constants' ) );
94
-					add_action( 'admin_notices', array( self::$instance, 'admin_notices' ) );
90
+				if (is_admin()) {
91
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
92
+					add_action('admin_init', array(self::$instance, 'register_settings'));
93
+					add_action('admin_init', array(self::$instance, 'constants'));
94
+					add_action('admin_notices', array(self::$instance, 'admin_notices'));
95 95
 				}
96 96
 
97
-				do_action( 'wp_font_awesome_settings_loaded' );
97
+				do_action('wp_font_awesome_settings_loaded');
98 98
 			}
99 99
 
100 100
 			return self::$instance;
@@ -105,26 +105,26 @@  discard block
 block discarded – undo
105 105
          *
106 106
 		 * @return void
107 107
 		 */
108
-		public function constants(){
108
+		public function constants() {
109 109
 
110 110
 			// register iconpicker constant
111
-			if ( ! defined( 'FAS_ICONPICKER_JS_URL' ) ) {
111
+			if (!defined('FAS_ICONPICKER_JS_URL')) {
112 112
 				$url = $this->get_path_url();
113 113
 				$version = $this->settings['version'];
114 114
 
115
-				if( !$version || version_compare($version,'5.999','>')){
115
+				if (!$version || version_compare($version, '5.999', '>')) {
116 116
 					$url .= 'assets/js/fa-iconpicker-v6.min.js';
117
-				}else{
117
+				} else {
118 118
 					$url .= 'assets/js/fa-iconpicker-v5.min.js';
119 119
 				}
120 120
 
121
-				define( 'FAS_ICONPICKER_JS_URL', $url );
121
+				define('FAS_ICONPICKER_JS_URL', $url);
122 122
 
123 123
 			}
124 124
 
125 125
             // Set a constant if pro enbaled
126
-			if ( ! defined( 'FAS_PRO' ) && $this->settings['pro'] ) {
127
-				define( 'FAS_PRO', true );
126
+			if (!defined('FAS_PRO') && $this->settings['pro']) {
127
+				define('FAS_PRO', true);
128 128
 			}
129 129
 		}
130 130
 
@@ -134,19 +134,19 @@  discard block
 block discarded – undo
134 134
 		 * @return string
135 135
 		 */
136 136
 		public function get_path_url() {
137
-			$content_dir = wp_normalize_path( untrailingslashit( WP_CONTENT_DIR ) );
138
-			$content_url = untrailingslashit( WP_CONTENT_URL );
137
+			$content_dir = wp_normalize_path(untrailingslashit(WP_CONTENT_DIR));
138
+			$content_url = untrailingslashit(WP_CONTENT_URL);
139 139
 
140 140
 			// Replace http:// to https://.
141
-			if ( strpos( $content_url, 'http://' ) === 0 && strpos( plugins_url(), 'https://' ) === 0 ) {
142
-				$content_url = str_replace( 'http://', 'https://', $content_url );
141
+			if (strpos($content_url, 'http://') === 0 && strpos(plugins_url(), 'https://') === 0) {
142
+				$content_url = str_replace('http://', 'https://', $content_url);
143 143
 			}
144 144
 
145 145
 			// Check if we are inside a plugin
146
-			$file_dir = str_replace( "/includes", "", wp_normalize_path( dirname( __FILE__ ) ) );
147
-			$url = str_replace( $content_dir, $content_url, $file_dir );
146
+			$file_dir = str_replace("/includes", "", wp_normalize_path(dirname(__FILE__)));
147
+			$url = str_replace($content_dir, $content_url, $file_dir);
148 148
 
149
-			return trailingslashit( $url );
149
+			return trailingslashit($url);
150 150
 		}
151 151
 
152 152
 		/**
@@ -156,45 +156,45 @@  discard block
 block discarded – undo
156 156
 		 */
157 157
 		public function init() {
158 158
 			// Download fontawesome locally.
159
-			add_action( 'add_option_wp-font-awesome-settings', array( $this, 'add_option_wp_font_awesome_settings' ), 10, 2 );
160
-			add_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
159
+			add_action('add_option_wp-font-awesome-settings', array($this, 'add_option_wp_font_awesome_settings'), 10, 2);
160
+			add_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2);
161 161
 
162 162
 			$this->settings = $this->get_settings();
163 163
 
164 164
 			// Check if the official plugin is active and use that instead if so.
165
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
166
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
167
-					add_action( 'admin_head', array( $this, 'add_generator' ), 99 );
165
+			if (!defined('FONTAWESOME_PLUGIN_FILE')) {
166
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
167
+					add_action('admin_head', array($this, 'add_generator'), 99);
168 168
 				}
169 169
 
170
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
171
-					add_action( 'wp_head', array( $this, 'add_generator' ), 99 );
170
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
171
+					add_action('wp_head', array($this, 'add_generator'), 99);
172 172
 				}
173 173
 
174
-				if ( $this->settings['type'] == 'CSS' ) {
175
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
176
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
174
+				if ($this->settings['type'] == 'CSS') {
175
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
176
+						add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000);
177 177
 						//add_action( 'wp_footer', array( $this, 'enqueue_style' ), 5000 ); // not sure why this was added, seems to break frontend
178 178
 					}
179 179
 
180
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
181
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
182
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_styles' ), 10, 2 );
180
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
181
+						add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000);
182
+						add_filter('block_editor_settings_all', array($this, 'enqueue_editor_styles'), 10, 2);
183 183
 					}
184 184
 				} else {
185
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
186
-						add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
185
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
186
+						add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000);
187 187
 					}
188 188
 
189
-					if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
190
-						add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
191
-						add_filter( 'block_editor_settings_all', array( $this, 'enqueue_editor_scripts' ), 10, 2 );
189
+					if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
190
+						add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000);
191
+						add_filter('block_editor_settings_all', array($this, 'enqueue_editor_scripts'), 10, 2);
192 192
 					}
193 193
 				}
194 194
 
195 195
 				// remove font awesome if set to do so
196
-				if ( $this->settings['dequeue'] == '1' ) {
197
-					add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
196
+				if ($this->settings['dequeue'] == '1') {
197
+					add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3);
198 198
 				}
199 199
 			}
200 200
 
@@ -208,9 +208,9 @@  discard block
 block discarded – undo
208 208
 		 *
209 209
 		 * @return array
210 210
 		 */
211
-		public function enqueue_editor_styles( $editor_settings, $block_editor_context ){
211
+		public function enqueue_editor_styles($editor_settings, $block_editor_context) {
212 212
 
213
-			if ( ! empty( $editor_settings['__unstableResolvedAssets']['styles'] ) ) {
213
+			if (!empty($editor_settings['__unstableResolvedAssets']['styles'])) {
214 214
 				$url = $this->get_url();
215 215
 				$editor_settings['__unstableResolvedAssets']['styles'] .= "<link rel='stylesheet' id='font-awesome-css'  href='$url' media='all' />";
216 216
 			}
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 		 *
227 227
 		 * @return array
228 228
 		 */
229
-		public function enqueue_editor_scripts( $editor_settings, $block_editor_context ){
229
+		public function enqueue_editor_scripts($editor_settings, $block_editor_context) {
230 230
 
231 231
 			$url = $this->get_url();
232 232
 			$editor_settings['__unstableResolvedAssets']['scripts'] .= "<script src='$url' id='font-awesome-js'></script>";
@@ -240,22 +240,22 @@  discard block
 block discarded – undo
240 240
 		public function enqueue_style() {
241 241
 			// build url
242 242
 			$url = $this->get_url();
243
-			$version = ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ? strip_tags( $this->settings['local_version'] ) : null;
243
+			$version = !empty($this->settings['local']) && empty($this->settings['pro']) ? strip_tags($this->settings['local_version']) : null;
244 244
 
245
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
246
-			wp_register_style( 'font-awesome', $url, array(), $version );
247
-			wp_enqueue_style( 'font-awesome' );
245
+			wp_deregister_style('font-awesome'); // deregister in case its already there
246
+			wp_register_style('font-awesome', $url, array(), $version);
247
+			wp_enqueue_style('font-awesome');
248 248
 
249 249
 			// RTL language support CSS.
250
-			if ( is_rtl() ) {
251
-				wp_add_inline_style( 'font-awesome', $this->rtl_inline_css() );
250
+			if (is_rtl()) {
251
+				wp_add_inline_style('font-awesome', $this->rtl_inline_css());
252 252
 			}
253 253
 
254
-			if ( $this->settings['shims'] ) {
255
-				$url = $this->get_url( true );
256
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
257
-				wp_register_style( 'font-awesome-shims', $url, array(), $version );
258
-				wp_enqueue_style( 'font-awesome-shims' );
254
+			if ($this->settings['shims']) {
255
+				$url = $this->get_url(true);
256
+				wp_deregister_style('font-awesome-shims'); // deregister in case its already there
257
+				wp_register_style('font-awesome-shims', $url, array(), $version);
258
+				wp_enqueue_style('font-awesome-shims');
259 259
 			}
260 260
 		}
261 261
 
@@ -267,15 +267,15 @@  discard block
 block discarded – undo
267 267
 			$url = $this->get_url();
268 268
 
269 269
 			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
270
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
271
-			wp_register_script( 'font-awesome', $url, array(), null );
272
-			wp_enqueue_script( 'font-awesome' );
270
+			call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there
271
+			wp_register_script('font-awesome', $url, array(), null);
272
+			wp_enqueue_script('font-awesome');
273 273
 
274
-			if ( $this->settings['shims'] ) {
275
-				$url = $this->get_url( true );
276
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
277
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
278
-				wp_enqueue_script( 'font-awesome-shims' );
274
+			if ($this->settings['shims']) {
275
+				$url = $this->get_url(true);
276
+				call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there
277
+				wp_register_script('font-awesome-shims', $url, array(), null);
278
+				wp_enqueue_script('font-awesome-shims');
279 279
 			}
280 280
 		}
281 281
 
@@ -287,16 +287,16 @@  discard block
 block discarded – undo
287 287
 		 *
288 288
 		 * @return string The url to the file.
289 289
 		 */
290
-		public function get_url( $shims = false, $local = true ) {
290
+		public function get_url($shims = false, $local = true) {
291 291
 			$script  = $shims ? 'v4-shims' : 'all';
292 292
 			$sub     = $this->settings['pro'] ? 'pro' : 'use';
293 293
 			$type    = $this->settings['type'];
294 294
 			$version = $this->settings['version'];
295
-			$kit_url = $this->settings['kit-url'] ? esc_url( $this->settings['kit-url'] ) : '';
295
+			$kit_url = $this->settings['kit-url'] ? esc_url($this->settings['kit-url']) : '';
296 296
 			$url     = '';
297 297
 
298
-			if ( $type == 'KIT' && $kit_url ) {
299
-				if ( $shims ) {
298
+			if ($type == 'KIT' && $kit_url) {
299
+				if ($shims) {
300 300
 					// if its a kit then we don't add shims here
301 301
 					return '';
302 302
 				}
@@ -305,13 +305,13 @@  discard block
 block discarded – undo
305 305
 			} else {
306 306
 				$v = '';
307 307
 				// Check and load locally.
308
-				if ( $local && $this->has_local() ) {
308
+				if ($local && $this->has_local()) {
309 309
 					$script .= ".min";
310
-					$v .= '&ver=' . strip_tags( $this->settings['local_version'] );
310
+					$v .= '&ver=' . strip_tags($this->settings['local_version']);
311 311
 					$url .= $this->get_fonts_url(); // Local fonts url.
312 312
 				} else {
313 313
 					$url .= "https://$sub.fontawesome.com/releases/"; // CDN
314
-					$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
314
+					$url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
315 315
 				}
316 316
 				$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
317 317
 				$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
 		 *
333 333
 		 * @return string The filtered url.
334 334
 		 */
335
-		public function remove_font_awesome( $url, $original_url, $_context ) {
335
+		public function remove_font_awesome($url, $original_url, $_context) {
336 336
 
337
-			if ( $_context == 'display'
338
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
339
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
337
+			if ($_context == 'display'
338
+			     && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false)
339
+			     && (strstr($url, ".js") !== false || strstr($url, ".css") !== false)
340 340
 			) {// it's a font-awesome-url (probably)
341 341
 
342
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
343
-					if ( $this->settings['type'] == 'JS' ) {
344
-						if ( $this->settings['js-pseudo'] ) {
342
+				if (strstr($url, "wpfas=true") !== false) {
343
+					if ($this->settings['type'] == 'JS') {
344
+						if ($this->settings['js-pseudo']) {
345 345
 							$url .= "' data-search-pseudo-elements defer='defer";
346 346
 						} else {
347 347
 							$url .= "' defer='defer";
@@ -360,7 +360,7 @@  discard block
 block discarded – undo
360 360
 		 * Register the database settings with WordPress.
361 361
 		 */
362 362
 		public function register_settings() {
363
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
363
+			register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings');
364 364
 		}
365 365
 
366 366
 		/**
@@ -369,10 +369,10 @@  discard block
 block discarded – undo
369 369
 		 */
370 370
 		public function menu_item() {
371 371
 			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
372
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
372
+			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
373 373
 				$this,
374 374
 				'settings_page'
375
-			) );
375
+			));
376 376
 		}
377 377
 
378 378
 		/**
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
 		 * @return array The array of settings.
382 382
 		 */
383 383
 		public function get_settings() {
384
-			$db_settings = get_option( 'wp-font-awesome-settings' );
384
+			$db_settings = get_option('wp-font-awesome-settings');
385 385
 
386 386
 			$defaults = array(
387 387
 				'type'      => 'CSS', // type to use, CSS or JS or KIT
@@ -396,30 +396,30 @@  discard block
 block discarded – undo
396 396
 				'kit-url'   => '', // the kit url
397 397
 			);
398 398
 
399
-			$settings = wp_parse_args( $db_settings, $defaults );
399
+			$settings = wp_parse_args($db_settings, $defaults);
400 400
 
401 401
 			/**
402 402
 			 * Filter the Font Awesome settings.
403 403
 			 *
404 404
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
405 405
 			 */
406
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
406
+			return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults);
407 407
 		}
408 408
 
409 409
 		/**
410 410
 		 * The settings page html output.
411 411
 		 */
412 412
 		public function settings_page() {
413
-			if ( ! current_user_can( 'manage_options' ) ) {
414
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'ayecode-connect' ) );
413
+			if (!current_user_can('manage_options')) {
414
+				wp_die(__('You do not have sufficient permissions to access this page.', 'ayecode-connect'));
415 415
 			}
416 416
 
417 417
 			// a hidden way to force the update of the version number via api instead of waiting the 48 hours
418
-			if ( isset( $_REQUEST['force-version-check'] ) ) {
419
-				$this->get_latest_version( $force_api = true );
418
+			if (isset($_REQUEST['force-version-check'])) {
419
+				$this->get_latest_version($force_api = true);
420 420
 			}
421 421
 
422
-			if ( ! defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
422
+			if (!defined('FONTAWESOME_PLUGIN_FILE')) {
423 423
 				?>
424 424
                 <style>
425 425
                     .wpfas-kit-show {
@@ -446,42 +446,42 @@  discard block
 block discarded – undo
446 446
                     <h1><?php echo $this->name; ?></h1>
447 447
                     <form method="post" action="options.php" class="fas-settings-form">
448 448
 						<?php
449
-						settings_fields( 'wp-font-awesome-settings' );
450
-						do_settings_sections( 'wp-font-awesome-settings' );
449
+						settings_fields('wp-font-awesome-settings');
450
+						do_settings_sections('wp-font-awesome-settings');
451 451
 						$table_class = '';
452
-						if ( $this->settings['type'] ) {
453
-							$table_class .= 'wpfas-' . sanitize_html_class( strtolower( $this->settings['type'] ) ) . '-set';
452
+						if ($this->settings['type']) {
453
+							$table_class .= 'wpfas-' . sanitize_html_class(strtolower($this->settings['type'])) . '-set';
454 454
 						}
455
-						if ( ! empty( $this->settings['pro'] ) ) {
455
+						if (!empty($this->settings['pro'])) {
456 456
 							$table_class .= ' wpfas-has-pro';
457 457
 						}
458 458
 						?>
459
-						<?php if ( $this->settings['type'] != 'KIT' && ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) ) { ?>
460
-							<?php if ( $this->has_local() ) { ?>
461
-                                <div class="notice notice-info"><p><strong><?php _e( 'Font Awesome fonts are loading locally.', 'ayecode-connect' ); ?></strong></p></div>
459
+						<?php if ($this->settings['type'] != 'KIT' && !empty($this->settings['local']) && empty($this->settings['pro'])) { ?>
460
+							<?php if ($this->has_local()) { ?>
461
+                                <div class="notice notice-info"><p><strong><?php _e('Font Awesome fonts are loading locally.', 'ayecode-connect'); ?></strong></p></div>
462 462
 							<?php } else { ?>
463
-                                <div class="notice notice-error"><p><strong><?php _e( 'Font Awesome fonts are not loading locally!', 'ayecode-connect' ); ?></strong></p></div>
463
+                                <div class="notice notice-error"><p><strong><?php _e('Font Awesome fonts are not loading locally!', 'ayecode-connect'); ?></strong></p></div>
464 464
 							<?php } ?>
465 465
 						<?php } ?>
466
-                        <table class="form-table wpfas-table-settings <?php echo esc_attr( $table_class ); ?>">
466
+                        <table class="form-table wpfas-table-settings <?php echo esc_attr($table_class); ?>">
467 467
                             <tr valign="top">
468
-                                <th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'ayecode-connect' ); ?></label></th>
468
+                                <th scope="row"><label for="wpfas-type"><?php _e('Type', 'ayecode-connect'); ?></label></th>
469 469
                                 <td>
470 470
                                     <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');}">
471
-                                        <option value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'ayecode-connect' ); ?></option>
472
-                                        <option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option>
473
-                                        <option value="KIT" <?php selected( $this->settings['type'], 'KIT' ); ?>><?php _e( 'Kits (settings managed on fontawesome.com)', 'ayecode-connect' ); ?></option>
471
+                                        <option value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'ayecode-connect'); ?></option>
472
+                                        <option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option>
473
+                                        <option value="KIT" <?php selected($this->settings['type'], 'KIT'); ?>><?php _e('Kits (settings managed on fontawesome.com)', 'ayecode-connect'); ?></option>
474 474
                                     </select>
475 475
                                 </td>
476 476
                             </tr>
477 477
 
478 478
                             <tr valign="top" class="wpfas-kit-show">
479
-                                <th scope="row"><label for="wpfas-kit-url"><?php _e( 'Kit URL', 'ayecode-connect' ); ?></label></th>
479
+                                <th scope="row"><label for="wpfas-kit-url"><?php _e('Kit URL', 'ayecode-connect'); ?></label></th>
480 480
                                 <td>
481
-                                    <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 :(?>"/>
481
+                                    <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 :(?>"/>
482 482
                                     <span><?php
483 483
 										echo wp_sprintf(
484
-											__( 'Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect' ),
484
+											__('Requires a free account with Font Awesome. %sGet kit url%s', 'ayecode-connect'),
485 485
 											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/kits"><i class="fas fa-external-link-alt"></i>',
486 486
 											'</a>'
487 487
 										);
@@ -490,44 +490,44 @@  discard block
 block discarded – undo
490 490
                             </tr>
491 491
 
492 492
                             <tr valign="top" class="wpfas-kit-hide">
493
-                                <th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'ayecode-connect' ); ?></label></th>
493
+                                <th scope="row"><label for="wpfas-version"><?php _e('Version', 'ayecode-connect'); ?></label></th>
494 494
                                 <td>
495 495
                                     <select name="wp-font-awesome-settings[version]" id="wpfas-version">
496
-                                        <option value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo wp_sprintf( __( 'Latest - %s (default)', 'ayecode-connect' ), $this->get_latest_version() ); ?></option>
497
-                                        <option value="6.1.0" <?php selected( $this->settings['version'], '6.1.0' ); ?>>6.1.0</option>
498
-                                        <option value="6.0.0" <?php selected( $this->settings['version'], '6.0.0' ); ?>>6.0.0</option>
499
-                                        <option value="5.15.4" <?php selected( $this->settings['version'], '5.15.4' ); ?>>5.15.4</option>
500
-                                        <option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>5.6.0</option>
501
-                                        <option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>5.5.0</option>
502
-                                        <option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>5.4.0</option>
503
-                                        <option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>5.3.0</option>
504
-                                        <option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>5.2.0</option>
505
-                                        <option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>5.1.0</option>
506
-                                        <option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>4.7.1 (CSS only)</option>
496
+                                        <option value="" <?php selected($this->settings['version'], ''); ?>><?php echo wp_sprintf(__('Latest - %s (default)', 'ayecode-connect'), $this->get_latest_version()); ?></option>
497
+                                        <option value="6.1.0" <?php selected($this->settings['version'], '6.1.0'); ?>>6.1.0</option>
498
+                                        <option value="6.0.0" <?php selected($this->settings['version'], '6.0.0'); ?>>6.0.0</option>
499
+                                        <option value="5.15.4" <?php selected($this->settings['version'], '5.15.4'); ?>>5.15.4</option>
500
+                                        <option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>>5.6.0</option>
501
+                                        <option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>5.5.0</option>
502
+                                        <option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>5.4.0</option>
503
+                                        <option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>5.3.0</option>
504
+                                        <option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>5.2.0</option>
505
+                                        <option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>5.1.0</option>
506
+                                        <option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>4.7.1 (CSS only)</option>
507 507
                                     </select>
508 508
                                 </td>
509 509
                             </tr>
510 510
 
511 511
                             <tr valign="top">
512
-                                <th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'ayecode-connect' ); ?></label></th>
512
+                                <th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'ayecode-connect'); ?></label></th>
513 513
                                 <td>
514 514
                                     <select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue">
515
-                                        <option value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'ayecode-connect' ); ?></option>
516
-                                        <option value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'ayecode-connect' ); ?></option>
517
-                                        <option value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'ayecode-connect' ); ?></option>
515
+                                        <option value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'ayecode-connect'); ?></option>
516
+                                        <option value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'ayecode-connect'); ?></option>
517
+                                        <option value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'ayecode-connect'); ?></option>
518 518
                                     </select>
519 519
                                 </td>
520 520
                             </tr>
521 521
 
522 522
                             <tr valign="top" class="wpfas-kit-hide">
523 523
                                 <th scope="row"><label
524
-                                            for="wpfas-pro"><?php _e( 'Enable pro', 'ayecode-connect' ); ?></label></th>
524
+                                            for="wpfas-pro"><?php _e('Enable pro', 'ayecode-connect'); ?></label></th>
525 525
                                 <td>
526 526
                                     <input type="hidden" name="wp-font-awesome-settings[pro]" value="0"/>
527
-                                    <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')}"/>
527
+                                    <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')}"/>
528 528
                                     <span><?php
529 529
 										echo wp_sprintf(
530
-											__( 'Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'ayecode-connect' ),
530
+											__('Requires a subscription. %sLearn more%s  %sManage my allowed domains%s', 'ayecode-connect'),
531 531
 											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/referral?a=c9b89e1418">',
532 532
 											' <i class="fas fa-external-link-alt"></i></a>',
533 533
 											'<a rel="noopener noreferrer" target="_blank" href="https://fontawesome.com/account/cdn">',
@@ -538,49 +538,49 @@  discard block
 block discarded – undo
538 538
                             </tr>
539 539
 
540 540
                             <tr valign="top" class="wpfas-kit-hide wpfas-hide-pro">
541
-                                <th scope="row"><label for="wpfas-local"><?php _e( 'Load Fonts Locally', 'ayecode-connect' ); ?></label></th>
541
+                                <th scope="row"><label for="wpfas-local"><?php _e('Load Fonts Locally', 'ayecode-connect'); ?></label></th>
542 542
                                 <td>
543 543
                                     <input type="hidden" name="wp-font-awesome-settings[local]" value="0"/>
544
-                                    <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr( $this->settings['local_version'] ); ?>"/>
545
-                                    <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked( $this->settings['local'], '1' ); ?> id="wpfas-local"/>
546
-                                    <span><?php _e( '(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect' ); ?></span>
544
+                                    <input type="hidden" name="wp-font-awesome-settings[local_version]" value="<?php echo esc_attr($this->settings['local_version']); ?>"/>
545
+                                    <input type="checkbox" name="wp-font-awesome-settings[local]" value="1" <?php checked($this->settings['local'], '1'); ?> id="wpfas-local"/>
546
+                                    <span><?php _e('(For free version only) Load FontAwesome fonts from locally. This downloads FontAwesome fonts from fontawesome.com & stores at the local site.', 'ayecode-connect'); ?></span>
547 547
                                 </td>
548 548
                             </tr>
549 549
 
550 550
                             <tr valign="top" class="wpfas-kit-hide">
551 551
                                 <th scope="row"><label
552
-                                            for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'ayecode-connect' ); ?></label>
552
+                                            for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'ayecode-connect'); ?></label>
553 553
                                 </th>
554 554
                                 <td>
555 555
                                     <input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/>
556 556
                                     <input type="checkbox" name="wp-font-awesome-settings[shims]"
557
-                                           value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/>
558
-                                    <span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect' ); ?></span>
557
+                                           value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/>
558
+                                    <span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'ayecode-connect'); ?></span>
559 559
                                 </td>
560 560
                             </tr>
561 561
 
562 562
                             <tr valign="top" class="wpfas-kit-hide">
563 563
                                 <th scope="row"><label
564
-                                            for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'ayecode-connect' ); ?></label>
564
+                                            for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'ayecode-connect'); ?></label>
565 565
                                 </th>
566 566
                                 <td>
567 567
                                     <input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/>
568 568
                                     <input type="checkbox" name="wp-font-awesome-settings[js-pseudo]"
569
-                                           value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?>
569
+                                           value="1" <?php checked($this->settings['js-pseudo'], '1'); ?>
570 570
                                            id="wpfas-js-pseudo"/>
571
-                                    <span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect' ); ?></span>
571
+                                    <span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'ayecode-connect'); ?></span>
572 572
                                 </td>
573 573
                             </tr>
574 574
 
575 575
                             <tr valign="top">
576 576
                                 <th scope="row"><label
577
-                                            for="wpfas-dequeue"><?php _e( 'Dequeue', 'ayecode-connect' ); ?></label></th>
577
+                                            for="wpfas-dequeue"><?php _e('Dequeue', 'ayecode-connect'); ?></label></th>
578 578
                                 <td>
579 579
                                     <input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/>
580 580
                                     <input type="checkbox" name="wp-font-awesome-settings[dequeue]"
581
-                                           value="1" <?php checked( $this->settings['dequeue'], '1' ); ?>
581
+                                           value="1" <?php checked($this->settings['dequeue'], '1'); ?>
582 582
                                            id="wpfas-dequeue"/>
583
-                                    <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.', 'ayecode-connect' ); ?></span>
583
+                                    <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.', 'ayecode-connect'); ?></span>
584 584
                                 </td>
585 585
                             </tr>
586 586
 
@@ -589,12 +589,12 @@  discard block
 block discarded – undo
589 589
 							<?php
590 590
 							submit_button();
591 591
 							?>
592
-                            <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro','ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p>
592
+                            <p class="submit"><a href="https://fontawesome.com/referral?a=c9b89e1418" class="button button-secondary"><?php _e('Get 24,000+ more icons with Font Awesome Pro', 'ayecode-connect'); ?> <i class="fas fa-external-link-alt"></i></a></p>
593 593
 
594 594
                         </div>
595 595
                     </form>
596 596
 
597
-                    <div id="wpfas-version"><?php echo wp_sprintf(__( 'Version: %s (affiliate links provided)', 'ayecode-connect' ), $this->version ); ?></div>
597
+                    <div id="wpfas-version"><?php echo wp_sprintf(__('Version: %s (affiliate links provided)', 'ayecode-connect'), $this->version); ?></div>
598 598
                 </div>
599 599
 				<?php
600 600
 			}
@@ -609,12 +609,12 @@  discard block
 block discarded – undo
609 609
 		 *
610 610
 		 * @return string Either a valid version number or an empty string.
611 611
 		 */
612
-		public function validate_version_number( $version ) {
612
+		public function validate_version_number($version) {
613 613
 
614
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
614
+			if (version_compare($version, '0.0.1', '>=') >= 0) {
615 615
 				// valid
616 616
 			} else {
617
-				$version = '';// not validated
617
+				$version = ''; // not validated
618 618
 			}
619 619
 
620 620
 			return $version;
@@ -629,27 +629,27 @@  discard block
 block discarded – undo
629 629
 		 * @since 1.0.7
630 630
 		 * @return mixed|string The latest version number found.
631 631
 		 */
632
-		public function get_latest_version( $force_api = false ) {
632
+		public function get_latest_version($force_api = false) {
633 633
 			$latest_version = $this->latest;
634 634
 
635
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
635
+			$cache = get_transient('wp-font-awesome-settings-version');
636 636
 
637
-			if ( $cache === false || $force_api ) { // its not set
637
+			if ($cache === false || $force_api) { // its not set
638 638
 				$api_ver = $this->get_latest_version_from_api();
639
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
639
+				if (version_compare($api_ver, $this->latest, '>=') >= 0) {
640 640
 					$latest_version = $api_ver;
641
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
641
+					set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS);
642 642
 				}
643
-			} elseif ( $this->validate_version_number( $cache ) ) {
644
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
643
+			} elseif ($this->validate_version_number($cache)) {
644
+				if (version_compare($cache, $this->latest, '>=') >= 0) {
645 645
 					$latest_version = $cache;
646 646
 				}
647 647
 			}
648 648
 
649 649
 			// Check and auto download fonts locally.
650
-			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 ) ) {
651
-				if ( version_compare( $latest_version, $this->settings['local_version'], '>' ) && is_admin() && ! wp_doing_ajax() ) {
652
-					$this->download_package( $latest_version );
650
+			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)) {
651
+				if (version_compare($latest_version, $this->settings['local_version'], '>') && is_admin() && !wp_doing_ajax()) {
652
+					$this->download_package($latest_version);
653 653
 				}
654 654
 			}
655 655
 
@@ -664,10 +664,10 @@  discard block
 block discarded – undo
664 664
 		 */
665 665
 		public function get_latest_version_from_api() {
666 666
 			$version  = "0";
667
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
668
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
669
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
670
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
667
+			$response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest");
668
+			if (!is_wp_error($response) && is_array($response)) {
669
+				$api_response = json_decode(wp_remote_retrieve_body($response), true);
670
+				if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) {
671 671
 					$version = $api_response['tag_name'];
672 672
 				}
673 673
 			}
@@ -695,21 +695,21 @@  discard block
 block discarded – undo
695 695
 		public function admin_notices() {
696 696
 			$settings = $this->settings;
697 697
 
698
-			if ( defined( 'FONTAWESOME_PLUGIN_FILE' ) ) {
699
-				if ( ! empty( $_REQUEST['page'] ) && $_REQUEST['page'] == 'wp-font-awesome-settings' ) {
698
+			if (defined('FONTAWESOME_PLUGIN_FILE')) {
699
+				if (!empty($_REQUEST['page']) && $_REQUEST['page'] == 'wp-font-awesome-settings') {
700 700
 					?>
701 701
                     <div class="notice  notice-error is-dismissible">
702
-                        <p><?php _e( 'The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect' ); ?></p>
702
+                        <p><?php _e('The Official Font Awesome Plugin is active, please adjust your settings there.', 'ayecode-connect'); ?></p>
703 703
                     </div>
704 704
 					<?php
705 705
 				}
706 706
 			} else {
707
-				if ( ! empty( $settings ) ) {
708
-					if ( $settings['type'] != 'KIT' && $settings['pro'] && ( $settings['version'] == '' || version_compare( $settings['version'], '6', '>=' ) ) ) {
707
+				if (!empty($settings)) {
708
+					if ($settings['type'] != 'KIT' && $settings['pro'] && ($settings['version'] == '' || version_compare($settings['version'], '6', '>='))) {
709 709
 						$link = admin_url('options-general.php?page=wp-font-awesome-settings');
710 710
 						?>
711 711
                         <div class="notice  notice-error is-dismissible">
712
-                            <p><?php echo wp_sprintf( __( 'Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect' ),"<a href='". esc_url_raw( $link )."'>","</a>" ); ?></p>
712
+                            <p><?php echo wp_sprintf(__('Font Awesome Pro v6 requires the use of a kit, please setup your kit in %ssettings.%s', 'ayecode-connect'), "<a href='" . esc_url_raw($link) . "'>", "</a>"); ?></p>
713 713
                         </div>
714 714
 						<?php
715 715
 					}
@@ -725,20 +725,20 @@  discard block
 block discarded – undo
725 725
 		 * @param string $option The option name.
726 726
 		 * @param mixed  $value  The option value.
727 727
 		 */
728
-		public function add_option_wp_font_awesome_settings( $option, $value ) {
728
+		public function add_option_wp_font_awesome_settings($option, $value) {
729 729
 			// Do nothing if WordPress is being installed.
730
-			if ( wp_installing() ) {
730
+			if (wp_installing()) {
731 731
 				return;
732 732
 			}
733 733
 
734
-			if ( ! empty( $value['local'] ) && empty( $value['pro'] ) && ! ( ! empty( $value['type'] ) && $value['type'] == 'KIT' ) ) {
735
-				$version = isset( $value['version'] ) && $value['version'] ? $value['version'] : $this->get_latest_version();
734
+			if (!empty($value['local']) && empty($value['pro']) && !(!empty($value['type']) && $value['type'] == 'KIT')) {
735
+				$version = isset($value['version']) && $value['version'] ? $value['version'] : $this->get_latest_version();
736 736
 
737
-				if ( ! empty( $version ) ) {
738
-					$response = $this->download_package( $version, $value );
737
+				if (!empty($version)) {
738
+					$response = $this->download_package($version, $value);
739 739
 
740
-					if ( is_wp_error( $response ) ) {
741
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
740
+					if (is_wp_error($response)) {
741
+						add_settings_error('general', 'fontawesome_download', __('ERROR:', 'ayecode-connect') . ' ' . $response->get_error_message(), 'error');
742 742
 					}
743 743
 				}
744 744
 			}
@@ -752,25 +752,25 @@  discard block
 block discarded – undo
752 752
 		 * @param mixed $old_value The old option value.
753 753
 		 * @param mixed $value     The new option value.
754 754
 		 */
755
-		public function update_option_wp_font_awesome_settings( $old_value, $new_value ) {
755
+		public function update_option_wp_font_awesome_settings($old_value, $new_value) {
756 756
 			// Do nothing if WordPress is being installed.
757
-			if ( wp_installing() ) {
757
+			if (wp_installing()) {
758 758
 				return;
759 759
 			}
760 760
 
761
-			if ( ! empty( $new_value['local'] ) && empty( $new_value['pro'] ) && ! ( ! empty( $new_value['type'] ) && $new_value['type'] == 'KIT' ) ) {
761
+			if (!empty($new_value['local']) && empty($new_value['pro']) && !(!empty($new_value['type']) && $new_value['type'] == 'KIT')) {
762 762
 				// Old values
763
-				$old_version = isset( $old_value['version'] ) && $old_value['version'] ? $old_value['version'] : ( isset( $old_value['local_version'] ) ? $old_value['local_version'] : '' );
764
-				$old_local = isset( $old_value['local'] ) ? (int) $old_value['local'] : 0;
763
+				$old_version = isset($old_value['version']) && $old_value['version'] ? $old_value['version'] : (isset($old_value['local_version']) ? $old_value['local_version'] : '');
764
+				$old_local = isset($old_value['local']) ? (int) $old_value['local'] : 0;
765 765
 
766 766
 				// New values
767
-				$new_version = isset( $new_value['version'] ) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
767
+				$new_version = isset($new_value['version']) && $new_value['version'] ? $new_value['version'] : $this->get_latest_version();
768 768
 
769
-				if ( empty( $old_local ) || $old_version !== $new_version || ! file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
770
-					$response = $this->download_package( $new_version, $new_value );
769
+				if (empty($old_local) || $old_version !== $new_version || !file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) {
770
+					$response = $this->download_package($new_version, $new_value);
771 771
 
772
-					if ( is_wp_error( $response ) ) {
773
-						add_settings_error( 'general', 'fontawesome_download', __( 'ERROR:', 'ayecode-connect' ) . ' ' . $response->get_error_message(), 'error' );
772
+					if (is_wp_error($response)) {
773
+						add_settings_error('general', 'fontawesome_download', __('ERROR:', 'ayecode-connect') . ' ' . $response->get_error_message(), 'error');
774 774
 					}
775 775
 				}
776 776
 			}
@@ -784,9 +784,9 @@  discard block
 block discarded – undo
784 784
 		 * @param string Fonts directory local path.
785 785
 		 */
786 786
 		public function get_fonts_dir() {
787
-			$upload_dir = wp_upload_dir( null, false );
787
+			$upload_dir = wp_upload_dir(null, false);
788 788
 
789
-			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR .  'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
789
+			return $upload_dir['basedir'] . DIRECTORY_SEPARATOR . 'ayefonts' . DIRECTORY_SEPARATOR . 'fa' . DIRECTORY_SEPARATOR;
790 790
 		}
791 791
 
792 792
 		/**
@@ -797,9 +797,9 @@  discard block
 block discarded – undo
797 797
 		 * @param string Fonts directory local url.
798 798
 		 */
799 799
 		public function get_fonts_url() {
800
-			$upload_dir = wp_upload_dir( null, false );
800
+			$upload_dir = wp_upload_dir(null, false);
801 801
 
802
-			return $upload_dir['baseurl'] .  '/ayefonts/fa/';
802
+			return $upload_dir['baseurl'] . '/ayefonts/fa/';
803 803
 		}
804 804
 
805 805
 		/**
@@ -810,7 +810,7 @@  discard block
 block discarded – undo
810 810
 		 * @return bool True if active else false.
811 811
 		 */
812 812
 		public function has_local() {
813
-			if ( ! empty( $this->settings['local'] ) && empty( $this->settings['pro'] ) && file_exists( $this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css' ) ) {
813
+			if (!empty($this->settings['local']) && empty($this->settings['pro']) && file_exists($this->get_fonts_dir() . 'css' . DIRECTORY_SEPARATOR . 'all.css')) {
814 814
 				return true;
815 815
 			}
816 816
 
@@ -825,18 +825,18 @@  discard block
 block discarded – undo
825 825
 		 * @return object The WP Filesystem.
826 826
 		 */
827 827
 		public function get_wp_filesystem() {
828
-			if ( ! function_exists( 'get_filesystem_method' ) ) {
829
-				require_once( ABSPATH . "/wp-admin/includes/file.php" );
828
+			if (!function_exists('get_filesystem_method')) {
829
+				require_once(ABSPATH . "/wp-admin/includes/file.php");
830 830
 			}
831 831
 
832 832
 			$access_type = get_filesystem_method();
833 833
 
834
-			if ( $access_type === 'direct' ) {
834
+			if ($access_type === 'direct') {
835 835
 				/* You can safely run request_filesystem_credentials() without any issues and don't need to worry about passing in a URL */
836
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
836
+				$creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array());
837 837
 
838 838
 				/* Initialize the API */
839
-				if ( ! WP_Filesystem( $creds ) ) {
839
+				if (!WP_Filesystem($creds)) {
840 840
 					/* Any problems and we exit */
841 841
 					return false;
842 842
 				}
@@ -845,11 +845,11 @@  discard block
 block discarded – undo
845 845
 
846 846
 				return $wp_filesystem;
847 847
 				/* Do our file manipulations below */
848
-			} else if ( defined( 'FTP_USER' ) ) {
849
-				$creds = request_filesystem_credentials( trailingslashit( site_url() ) . 'wp-admin/', '', false, false, array() );
848
+			} else if (defined('FTP_USER')) {
849
+				$creds = request_filesystem_credentials(trailingslashit(site_url()) . 'wp-admin/', '', false, false, array());
850 850
 
851 851
 				/* Initialize the API */
852
-				if ( ! WP_Filesystem( $creds ) ) {
852
+				if (!WP_Filesystem($creds)) {
853 853
 					/* Any problems and we exit */
854 854
 					return false;
855 855
 				}
@@ -872,38 +872,38 @@  discard block
 block discarded – undo
872 872
 		 * @param array $option Fontawesome settings.
873 873
 		 * @return WP_ERROR|bool Error on fail and true on success.
874 874
 		 */
875
-		public function download_package( $version, $option = array() ) {
875
+		public function download_package($version, $option = array()) {
876 876
 			$filename = 'fontawesome-free-' . $version . '-web';
877 877
 			$url = 'https://use.fontawesome.com/releases/v' . $version . '/' . $filename . '.zip';
878 878
 
879
-			if ( ! function_exists( 'wp_handle_upload' ) ) {
879
+			if (!function_exists('wp_handle_upload')) {
880 880
 				require_once ABSPATH . 'wp-admin/includes/file.php';
881 881
 			}
882 882
 
883
-			$download_file = download_url( esc_url_raw( $url ) );
883
+			$download_file = download_url(esc_url_raw($url));
884 884
 
885
-			if ( is_wp_error( $download_file ) ) {
886
-				return new WP_Error( 'fontawesome_download_failed', __( $download_file->get_error_message(), 'ayecode-connect' ) );
887
-			} else if ( empty( $download_file ) ) {
888
-				return new WP_Error( 'fontawesome_download_failed', __( 'Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect' ) );
885
+			if (is_wp_error($download_file)) {
886
+				return new WP_Error('fontawesome_download_failed', __($download_file->get_error_message(), 'ayecode-connect'));
887
+			} else if (empty($download_file)) {
888
+				return new WP_Error('fontawesome_download_failed', __('Something went wrong in downloading the font awesome to store locally.', 'ayecode-connect'));
889 889
 			}
890 890
 
891
-			$response = $this->extract_package( $download_file, $filename, true );
891
+			$response = $this->extract_package($download_file, $filename, true);
892 892
 
893 893
 			// Update local version.
894
-			if ( is_wp_error( $response ) ) {
894
+			if (is_wp_error($response)) {
895 895
 				return $response;
896
-			} else if ( $response ) {
897
-				if ( empty( $option ) ) {
898
-					$option = get_option( 'wp-font-awesome-settings' );
896
+			} else if ($response) {
897
+				if (empty($option)) {
898
+					$option = get_option('wp-font-awesome-settings');
899 899
 				}
900 900
 
901 901
 				$option['local_version'] = $version;
902 902
 
903 903
 				// Remove action to prevent looping.
904
-				remove_action( 'update_option_wp-font-awesome-settings', array( $this, 'update_option_wp_font_awesome_settings' ), 10, 2 );
904
+				remove_action('update_option_wp-font-awesome-settings', array($this, 'update_option_wp_font_awesome_settings'), 10, 2);
905 905
 
906
-				update_option( 'wp-font-awesome-settings', $option );
906
+				update_option('wp-font-awesome-settings', $option);
907 907
 
908 908
 				return true;
909 909
 			}
@@ -921,60 +921,60 @@  discard block
 block discarded – undo
921 921
 		 * @param bool   $delete_package Delete temp file or not.
922 922
 		 * @return WP_Error|bool True on success WP_Error on fail.
923 923
 		 */
924
-		public function extract_package( $package, $dirname = '', $delete_package = false ) {
924
+		public function extract_package($package, $dirname = '', $delete_package = false) {
925 925
 			global $wp_filesystem;
926 926
 
927 927
 			$wp_filesystem = $this->get_wp_filesystem();
928 928
 
929
-			if ( empty( $wp_filesystem ) && isset( $wp_filesystem->errors ) && is_wp_error( $wp_filesystem->errors ) && $wp_filesystem->errors->get_error_code() ) {
930
-				return new WP_Error( 'fontawesome_filesystem_error', __( $wp_filesystem->errors->get_error_message(), 'ayecode-connect' ) );
931
-			} else if ( empty( $wp_filesystem ) ) {
932
-				return new WP_Error( 'fontawesome_filesystem_error', __( 'Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect' ) );
929
+			if (empty($wp_filesystem) && isset($wp_filesystem->errors) && is_wp_error($wp_filesystem->errors) && $wp_filesystem->errors->get_error_code()) {
930
+				return new WP_Error('fontawesome_filesystem_error', __($wp_filesystem->errors->get_error_message(), 'ayecode-connect'));
931
+			} else if (empty($wp_filesystem)) {
932
+				return new WP_Error('fontawesome_filesystem_error', __('Failed to initialise WP_Filesystem while trying to download the Font Awesome package.', 'ayecode-connect'));
933 933
 			}
934 934
 
935 935
 			$fonts_dir = $this->get_fonts_dir();
936
-			$fonts_tmp_dir = dirname( $fonts_dir ) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
936
+			$fonts_tmp_dir = dirname($fonts_dir) . DIRECTORY_SEPARATOR . 'fa-tmp' . DIRECTORY_SEPARATOR;
937 937
 
938
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
939
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
938
+			if ($wp_filesystem->is_dir($fonts_tmp_dir)) {
939
+				$wp_filesystem->delete($fonts_tmp_dir, true);
940 940
 			}
941 941
 
942 942
 			// Unzip package to working directory.
943
-			$result = unzip_file( $package, $fonts_tmp_dir );
943
+			$result = unzip_file($package, $fonts_tmp_dir);
944 944
 
945
-			if ( is_wp_error( $result ) ) {
946
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
945
+			if (is_wp_error($result)) {
946
+				$wp_filesystem->delete($fonts_tmp_dir, true);
947 947
 
948
-				if ( 'incompatible_archive' === $result->get_error_code() ) {
949
-					return new WP_Error( 'fontawesome_incompatible_archive', __( $result->get_error_message(), 'ayecode-connect' ) );
948
+				if ('incompatible_archive' === $result->get_error_code()) {
949
+					return new WP_Error('fontawesome_incompatible_archive', __($result->get_error_message(), 'ayecode-connect'));
950 950
 				}
951 951
 
952 952
 				return $result;
953 953
 			}
954 954
 
955
-			if ( $wp_filesystem->is_dir( $fonts_dir ) ) {
956
-				$wp_filesystem->delete( $fonts_dir, true );
955
+			if ($wp_filesystem->is_dir($fonts_dir)) {
956
+				$wp_filesystem->delete($fonts_dir, true);
957 957
 			}
958 958
 
959 959
 			$extract_dir = $fonts_tmp_dir;
960 960
 
961
-			if ( $dirname && $wp_filesystem->is_dir( $extract_dir . $dirname . DIRECTORY_SEPARATOR ) ) {
961
+			if ($dirname && $wp_filesystem->is_dir($extract_dir . $dirname . DIRECTORY_SEPARATOR)) {
962 962
 				$extract_dir .= $dirname . DIRECTORY_SEPARATOR;
963 963
 			}
964 964
 
965 965
 			try {
966
-				$return = $wp_filesystem->move( $extract_dir, $fonts_dir, true );
967
-			} catch ( Exception $e ) {
968
-				$return = new WP_Error( 'fontawesome_move_package', __( 'Fail to move font awesome package!', 'ayecode-connect' ) );
966
+				$return = $wp_filesystem->move($extract_dir, $fonts_dir, true);
967
+			} catch (Exception $e) {
968
+				$return = new WP_Error('fontawesome_move_package', __('Fail to move font awesome package!', 'ayecode-connect'));
969 969
 			}
970 970
 
971
-			if ( $wp_filesystem->is_dir( $fonts_tmp_dir ) ) {
972
-				$wp_filesystem->delete( $fonts_tmp_dir, true );
971
+			if ($wp_filesystem->is_dir($fonts_tmp_dir)) {
972
+				$wp_filesystem->delete($fonts_tmp_dir, true);
973 973
 			}
974 974
 
975 975
 			// Once extracted, delete the package if required.
976
-			if ( $delete_package ) {
977
-				unlink( $package );
976
+			if ($delete_package) {
977
+				unlink($package);
978 978
 			}
979 979
 
980 980
 			return $return;
@@ -984,22 +984,22 @@  discard block
 block discarded – undo
984 984
 		 * Output the version in the header.
985 985
 		 */
986 986
 		public function add_generator() {
987
-			$file = str_replace( array( "/", "\\" ), "/", realpath( __FILE__ ) );
988
-			$plugins_dir = str_replace( array( "/", "\\" ), "/", realpath( WP_PLUGIN_DIR ) );
987
+			$file = str_replace(array("/", "\\"), "/", realpath(__FILE__));
988
+			$plugins_dir = str_replace(array("/", "\\"), "/", realpath(WP_PLUGIN_DIR));
989 989
 
990 990
 			// Find source plugin/theme.
991 991
 			$source = array();
992
-			if ( strpos( $file, $plugins_dir ) !== false ) {
993
-				$source = explode( "/", plugin_basename( $file ) );
994
-			} else if ( function_exists( 'get_theme_root' ) ) {
995
-				$themes_dir = str_replace( array( "/", "\\" ), "/", realpath( get_theme_root() ) );
992
+			if (strpos($file, $plugins_dir) !== false) {
993
+				$source = explode("/", plugin_basename($file));
994
+			} else if (function_exists('get_theme_root')) {
995
+				$themes_dir = str_replace(array("/", "\\"), "/", realpath(get_theme_root()));
996 996
 
997
-				if ( strpos( $file, $themes_dir ) !== false ) {
998
-					$source = explode( "/", ltrim( str_replace( $themes_dir, "", $file ), "/" ) );
997
+				if (strpos($file, $themes_dir) !== false) {
998
+					$source = explode("/", ltrim(str_replace($themes_dir, "", $file), "/"));
999 999
 				}
1000 1000
 			}
1001 1001
 
1002
-			echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr( $this->version ) . '"' . ( ! empty( $source[0] ) ? ' data-ac-source="' . esc_attr( $source[0] ) . '"' : '' ) . ' />';
1002
+			echo '<meta name="generator" content="WP Font Awesome Settings v' . esc_attr($this->version) . '"' . (!empty($source[0]) ? ' data-ac-source="' . esc_attr($source[0]) . '"' : '') . ' />';
1003 1003
 		}
1004 1004
 	}
1005 1005
 
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -57,8 +57,8 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+        $anchor = __( 'Deactivate', 'invoicing' );
61
+        $title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64 64
     } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+        $anchor = __( 'Activate', 'invoicing' );
77
+        $title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
@@ -121,13 +121,13 @@  discard block
 block discarded – undo
121 121
             $types = wpinv_get_discount_types();
122 122
 
123 123
             foreach ( $types as $name => $type ) {
124
-			echo '<option value="' . esc_attr( $name ) . '"';
124
+            echo '<option value="' . esc_attr( $name ) . '"';
125 125
 
126
-			if ( isset( $_GET['discount_type'] ) ) {
127
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
126
+            if ( isset( $_GET['discount_type'] ) ) {
127
+                selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
128 128
                 }
129 129
 
130
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
130
+            echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
131 131
             }
132 132
         ?>
133 133
     </select>
@@ -154,15 +154,15 @@  discard block
 block discarded – undo
154 154
         // Filter vat rule type
155 155
         if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
156 156
             $meta_query[] = array(
157
-				'key'     => '_wpi_discount_type',
158
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
159
-				'compare' => '=',
160
-			);
161
-			}
157
+                'key'     => '_wpi_discount_type',
158
+                'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
159
+                'compare' => '=',
160
+            );
161
+            }
162 162
 
163 163
         if ( ! empty( $meta_query ) ) {
164 164
             $vars['meta_query'] = $meta_query;
165
-			}
165
+            }
166 166
     }
167 167
 
168 168
     return $vars;
Please login to merge, or discard this patch.
Spacing   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -1,51 +1,51 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( ! defined( 'WPINC' ) ) {
3
+if (!defined('WPINC')) {
4 4
     exit;
5 5
 }
6 6
 
7
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
8
-function wpinv_discount_custom_column( $column ) {
7
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
8
+function wpinv_discount_custom_column($column) {
9 9
     global $post;
10 10
 
11
-    $discount = new WPInv_Discount( $post );
11
+    $discount = new WPInv_Discount($post);
12 12
 
13
-    switch ( $column ) {
13
+    switch ($column) {
14 14
         case 'code':
15
-            echo esc_html( $discount->get_code() );
15
+            echo esc_html($discount->get_code());
16 16
             break;
17 17
         case 'amount':
18
-            echo wp_kses_post( $discount->get_formatted_amount() );
18
+            echo wp_kses_post($discount->get_formatted_amount());
19 19
             break;
20 20
         case 'usage':
21
-            echo wp_kses_post( $discount->get_usage() );
21
+            echo wp_kses_post($discount->get_usage());
22 22
             break;
23 23
         case 'start_date':
24
-            echo wp_kses_post( getpaid_format_date_value( $discount->get_start_date() ) );
24
+            echo wp_kses_post(getpaid_format_date_value($discount->get_start_date()));
25 25
             break;
26 26
         case 'expiry_date':
27
-            echo wp_kses_post( getpaid_format_date_value( $discount->get_expiration_date(), __( 'Never', 'invoicing' ) ) );
27
+            echo wp_kses_post(getpaid_format_date_value($discount->get_expiration_date(), __('Never', 'invoicing')));
28 28
             break;
29 29
     }
30 30
 }
31 31
 
32
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 90, 2 );
33
-function wpinv_post_row_actions( $actions, $post ) {
34
-    $post_type = ! empty( $post->post_type ) ? $post->post_type : '';
32
+add_filter('post_row_actions', 'wpinv_post_row_actions', 90, 2);
33
+function wpinv_post_row_actions($actions, $post) {
34
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
35 35
 
36
-    if ( $post_type == 'wpi_discount' ) {
37
-        $actions = wpinv_discount_row_actions( $post, $actions );
36
+    if ($post_type == 'wpi_discount') {
37
+        $actions = wpinv_discount_row_actions($post, $actions);
38 38
     }
39 39
 
40 40
     return $actions;
41 41
 }
42 42
 
43
-function wpinv_discount_row_actions( $discount, $row_actions ) {
44
-    $row_actions  = array();
45
-    $edit_link = get_edit_post_link( $discount->ID );
46
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
43
+function wpinv_discount_row_actions($discount, $row_actions) {
44
+    $row_actions = array();
45
+    $edit_link = get_edit_post_link($discount->ID);
46
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
47 47
 
48
-    if ( in_array( strtolower( $discount->post_status ), array( 'publish' ) ) && wpinv_current_user_can( 'deactivate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
48
+    if (in_array(strtolower($discount->post_status), array('publish')) && wpinv_current_user_can('deactivate_discount', array('discount' => (int) $discount->ID))) {
49 49
 
50 50
         $url = wp_nonce_url(
51 51
             add_query_arg(
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'getpaid-nonce',
58 58
             'getpaid-nonce'
59 59
         );
60
-		$anchor = __( 'Deactivate', 'invoicing' );
61
-		$title  = esc_attr__( 'Are you sure you want to deactivate this discount?', 'invoicing' );
60
+		$anchor = __('Deactivate', 'invoicing');
61
+		$title  = esc_attr__('Are you sure you want to deactivate this discount?', 'invoicing');
62 62
         $row_actions['deactivate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
63 63
 
64
-    } elseif ( in_array( strtolower( $discount->post_status ), array( 'pending', 'draft' ) ) && wpinv_current_user_can( 'activate_discount', array( 'discount' => (int) $discount->ID ) ) ) {
64
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft')) && wpinv_current_user_can('activate_discount', array('discount' => (int) $discount->ID))) {
65 65
 
66
-        $url    = wp_nonce_url(
66
+        $url = wp_nonce_url(
67 67
             add_query_arg(
68 68
                 array(
69 69
                     'getpaid-admin-action' => 'activate_discount',
@@ -73,14 +73,14 @@  discard block
 block discarded – undo
73 73
             'getpaid-nonce',
74 74
             'getpaid-nonce'
75 75
         );
76
-		$anchor = __( 'Activate', 'invoicing' );
77
-		$title  = esc_attr__( 'Are you sure you want to activate this discount?', 'invoicing' );
76
+		$anchor = __('Activate', 'invoicing');
77
+		$title  = esc_attr__('Are you sure you want to activate this discount?', 'invoicing');
78 78
         $row_actions['activate'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
79 79
 
80 80
     }
81 81
 
82
-    if ( wpinv_current_user_can( 'delete_discount', array( 'discount' => (int) $discount->ID ) ) ) {
83
-        $url    = esc_url(
82
+    if (wpinv_current_user_can('delete_discount', array('discount' => (int) $discount->ID))) {
83
+        $url = esc_url(
84 84
             wp_nonce_url(
85 85
                 add_query_arg(
86 86
                     array(
@@ -93,12 +93,12 @@  discard block
 block discarded – undo
93 93
             )
94 94
     );
95 95
 
96
-        $anchor = __( 'Delete', 'invoicing' );
97
-        $title  = esc_attr__( 'Are you sure you want to delete this discount?', 'invoicing' );
96
+        $anchor = __('Delete', 'invoicing');
97
+        $title  = esc_attr__('Are you sure you want to delete this discount?', 'invoicing');
98 98
         $row_actions['delete'] = "<a href='$url' onclick='return confirm(\"$title\")'>$anchor</a>";
99 99
     }
100 100
 
101
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
101
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
102 102
 
103 103
     return $row_actions;
104 104
 }
@@ -106,68 +106,68 @@  discard block
 block discarded – undo
106 106
 function wpinv_restrict_manage_posts() {
107 107
     global $typenow;
108 108
 
109
-    if ( 'wpi_discount' == $typenow ) {
109
+    if ('wpi_discount' == $typenow) {
110 110
         wpinv_discount_filters();
111 111
     }
112 112
 }
113
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
113
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
114 114
 
115 115
 function wpinv_discount_filters() {
116 116
 
117 117
     ?>
118 118
     <select name="discount_type" id="dropdown_wpinv_discount_type">
119
-        <option value=""><?php esc_html_e( 'Show all types', 'invoicing' ); ?></option>
119
+        <option value=""><?php esc_html_e('Show all types', 'invoicing'); ?></option>
120 120
         <?php
121 121
             $types = wpinv_get_discount_types();
122 122
 
123
-            foreach ( $types as $name => $type ) {
124
-			echo '<option value="' . esc_attr( $name ) . '"';
123
+            foreach ($types as $name => $type) {
124
+			echo '<option value="' . esc_attr($name) . '"';
125 125
 
126
-			if ( isset( $_GET['discount_type'] ) ) {
127
-				selected( $name, sanitize_text_field( $_GET['discount_type'] ) );
126
+			if (isset($_GET['discount_type'])) {
127
+				selected($name, sanitize_text_field($_GET['discount_type']));
128 128
                 }
129 129
 
130
-			echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
130
+			echo '>' . esc_html__($type, 'invoicing') . '</option>';
131 131
             }
132 132
         ?>
133 133
     </select>
134 134
     <?php
135 135
 }
136 136
 
137
-function wpinv_request( $vars ) {
137
+function wpinv_request($vars) {
138 138
     global $typenow, $wp_post_statuses;
139 139
 
140
-    if ( getpaid_is_invoice_post_type( $typenow ) ) {
141
-        if ( ! isset( $vars['post_status'] ) ) {
142
-            $post_statuses = wpinv_get_invoice_statuses( false, false, $typenow );
140
+    if (getpaid_is_invoice_post_type($typenow)) {
141
+        if (!isset($vars['post_status'])) {
142
+            $post_statuses = wpinv_get_invoice_statuses(false, false, $typenow);
143 143
 
144
-            foreach ( $post_statuses as $status => $value ) {
145
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
146
-                    unset( $post_statuses[ $status ] );
144
+            foreach ($post_statuses as $status => $value) {
145
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
146
+                    unset($post_statuses[$status]);
147 147
                 }
148 148
             }
149 149
 
150
-            $vars['post_status'] = array_keys( $post_statuses );
150
+            $vars['post_status'] = array_keys($post_statuses);
151 151
         }
152
-} elseif ( 'wpi_discount' == $typenow ) {
153
-        $meta_query = ! empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
152
+} elseif ('wpi_discount' == $typenow) {
153
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
154 154
         // Filter vat rule type
155
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
155
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
156 156
             $meta_query[] = array(
157 157
 				'key'     => '_wpi_discount_type',
158
-				'value'   => sanitize_key( urldecode( $_GET['discount_type'] ) ),
158
+				'value'   => sanitize_key(urldecode($_GET['discount_type'])),
159 159
 				'compare' => '=',
160 160
 			);
161 161
 			}
162 162
 
163
-        if ( ! empty( $meta_query ) ) {
163
+        if (!empty($meta_query)) {
164 164
             $vars['meta_query'] = $meta_query;
165 165
 			}
166 166
     }
167 167
 
168 168
     return $vars;
169 169
 }
170
-add_filter( 'request', 'wpinv_request' );
170
+add_filter('request', 'wpinv_request');
171 171
 
172 172
 /**
173 173
  * Create a page and store the ID in an option.
@@ -179,61 +179,61 @@  discard block
 block discarded – undo
179 179
  * @param int $post_parent (default: 0) Parent for the new page
180 180
  * @return int page ID
181 181
  */
182
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
182
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
183 183
     global $wpdb;
184 184
 
185
-    $option_value = wpinv_get_option( $option );
185
+    $option_value = wpinv_get_option($option);
186 186
 
187
-    if ( ! empty( $option_value ) && ( $page_object = get_post( $option_value ) ) ) {
188
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
187
+    if (!empty($option_value) && ($page_object = get_post($option_value))) {
188
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
189 189
             // Valid page is already in place
190 190
             return $page_object->ID;
191 191
         }
192 192
     }
193 193
 
194
-    if ( ! empty( $post_parent ) ) {
195
-        $page = get_page_by_path( $post_parent );
196
-        if ( $page ) {
194
+    if (!empty($post_parent)) {
195
+        $page = get_page_by_path($post_parent);
196
+        if ($page) {
197 197
             $post_parent = $page->ID;
198 198
         } else {
199 199
             $post_parent = '';
200 200
         }
201 201
     }
202 202
 
203
-    if ( strlen( $page_content ) > 0 ) {
203
+    if (strlen($page_content) > 0) {
204 204
         // Search for an existing page with the specified page content (typically a shortcode)
205
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
205
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
206 206
     } else {
207 207
         // Search for an existing page with the specified page slug
208
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
208
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
209 209
     }
210 210
 
211
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
211
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
212 212
 
213
-    if ( $valid_page_found ) {
214
-        if ( $option ) {
215
-            wpinv_update_option( $option, $valid_page_found );
213
+    if ($valid_page_found) {
214
+        if ($option) {
215
+            wpinv_update_option($option, $valid_page_found);
216 216
         }
217 217
         return $valid_page_found;
218 218
     }
219 219
 
220 220
     // Search for a matching valid trashed page
221
-    if ( strlen( $page_content ) > 0 ) {
221
+    if (strlen($page_content) > 0) {
222 222
         // Search for an existing page with the specified page content (typically a shortcode)
223
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
223
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
224 224
     } else {
225 225
         // Search for an existing page with the specified page slug
226
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
226
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
227 227
     }
228 228
 
229
-    if ( $trashed_page_found ) {
229
+    if ($trashed_page_found) {
230 230
         $page_id   = $trashed_page_found;
231 231
         $page_data = array(
232 232
             'ID'          => $page_id,
233 233
             'post_status' => 'publish',
234 234
             'post_parent' => $post_parent,
235 235
         );
236
-        wp_update_post( $page_data );
236
+        wp_update_post($page_data);
237 237
     } else {
238 238
         $page_data = array(
239 239
             'post_status'    => 'publish',
@@ -245,11 +245,11 @@  discard block
 block discarded – undo
245 245
             'post_parent'    => $post_parent,
246 246
             'comment_status' => 'closed',
247 247
         );
248
-        $page_id = wp_insert_post( $page_data );
248
+        $page_id = wp_insert_post($page_data);
249 249
     }
250 250
 
251
-    if ( $option ) {
252
-        wpinv_update_option( $option, (int) $page_id );
251
+    if ($option) {
252
+        wpinv_update_option($option, (int) $page_id);
253 253
     }
254 254
 
255 255
     return $page_id;
@@ -262,11 +262,11 @@  discard block
 block discarded – undo
262 262
  *
263 263
  * @return array
264 264
  */
265
-function wpinv_add_aui_screens( $screen_ids ) {
265
+function wpinv_add_aui_screens($screen_ids) {
266 266
 
267 267
     // load on these pages if set
268
-    $screen_ids = array_merge( $screen_ids, wpinv_get_screen_ids() );
268
+    $screen_ids = array_merge($screen_ids, wpinv_get_screen_ids());
269 269
 
270 270
     return $screen_ids;
271 271
 }
272
-add_filter( 'aui_screen_ids', 'wpinv_add_aui_screens' );
272
+add_filter('aui_screen_ids', 'wpinv_add_aui_screens');
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-customer-data-store.php 2 patches
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,196 +15,196 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Customer_Data_Store {
17 17
 
18
-	/*
18
+    /*
19 19
 	|--------------------------------------------------------------------------
20 20
 	| CRUD Methods
21 21
 	|--------------------------------------------------------------------------
22 22
 	*/
23 23
 
24
-	/**
25
-	 * Method to create a new customer in the database.
26
-	 *
27
-	 * @param GetPaid_Customer $customer customer object.
28
-	 */
29
-	public function create( &$customer ) {
30
-		global $wpdb;
31
-
32
-		$values  = array();
33
-		$formats = array();
34
-
35
-		$fields = self::get_database_fields();
36
-		unset( $fields['id'] );
37
-
38
-		foreach ( $fields as $key => $format ) {
39
-			$values[ $key ] = $customer->get( $key, 'edit' );
40
-			$formats[]      = $format;
41
-		}
42
-
43
-		$result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
44
-
45
-		if ( $result ) {
46
-			$customer->set_id( $wpdb->insert_id );
47
-			$customer->apply_changes();
48
-			$customer->clear_cache();
49
-			do_action( 'getpaid_new_customer', $customer );
50
-			return true;
51
-		}
52
-
53
-		return false;
54
-	}
55
-
56
-	/**
57
-	 * Method to read a customer from the database.
58
-	 *
59
-	 * @param GetPaid_Customer $customer customer object.
60
-	 *
61
-	 */
62
-	public function read( &$customer ) {
63
-		global $wpdb;
64
-
65
-		$customer->set_defaults();
66
-
67
-		if ( ! $customer->get_id() ) {
68
-			$customer->last_error = 'Invalid customer.';
69
-			$customer->set_id( 0 );
70
-			return false;
71
-		}
72
-
73
-		// Maybe retrieve from the cache.
74
-		$raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
75
-
76
-		// If not found, retrieve from the db.
77
-		if ( false === $raw_customer ) {
78
-
79
-			$raw_customer = $wpdb->get_row(
80
-				$wpdb->prepare(
81
-					"SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d",
82
-					$customer->get_id()
83
-				)
84
-			);
85
-
86
-			// Update the cache with our data
87
-			wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
88
-
89
-		}
90
-
91
-		if ( ! $raw_customer ) {
92
-			$raw_customer->last_error = 'Invalid customer.';
93
-			return false;
94
-		}
95
-
96
-		// Loop through raw customer fields.
97
-		foreach ( (array) $raw_customer as $key => $value ) {
98
-			$customer->set( $key, $value );
99
-		}
100
-
101
-		$customer->set_object_read( true );
102
-		do_action( 'getpaid_read_customer', $customer );
103
-
104
-	}
105
-
106
-	/**
107
-	 * Method to update a customer in the database.
108
-	 *
109
-	 * @param GetPaid_Customer $customer Customer object.
110
-	 */
111
-	public function update( &$customer ) {
112
-		global $wpdb;
113
-
114
-		do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
115
-
116
-		$changes = $customer->get_changes();
117
-		$values  = array();
118
-		$format  = array();
119
-
120
-		foreach ( self::get_database_fields() as $key => $format ) {
121
-			if ( array_key_exists( $key, $changes ) ) {
122
-				$values[ $key ] = $customer->get( $key, 'edit' );
123
-				$formats[]      = $format;
124
-			}
125
-		}
126
-
127
-		if ( empty( $values ) ) {
128
-			return;
129
-		}
130
-
131
-		$wpdb->update(
132
-			$wpdb->prefix . 'getpaid_customers',
133
-			$values,
134
-			array(
135
-				'id' => $customer->get_id(),
136
-			),
137
-			$formats,
138
-			'%d'
139
-		);
140
-
141
-		// Apply the changes.
142
-		$customer->apply_changes();
143
-
144
-		// Delete cache.
145
-		$customer->clear_cache();
146
-
147
-		// Fire a hook.
148
-		do_action( 'getpaid_update_customer', $customer );
149
-
150
-	}
151
-
152
-	/**
153
-	 * Method to delete a customer from the database.
154
-	 *
155
-	 * @param GetPaid_Customer $customer
156
-	 */
157
-	public function delete( &$customer ) {
158
-		global $wpdb;
159
-
160
-		do_action( 'getpaid_before_delete_customer', $customer );
161
-
162
-		$wpdb->delete(
163
-			$wpdb->prefix . 'getpaid_customers',
164
-			array(
165
-				'id' => $customer->get_id(),
166
-			),
167
-			'%d'
168
-		);
169
-
170
-		// Delete cache.
171
-		$customer->clear_cache();
172
-
173
-		// Fire a hook.
174
-		do_action( 'getpaid_delete_customer', $customer );
175
-
176
-		$customer->set_id( 0 );
177
-	}
178
-
179
-	/*
24
+    /**
25
+     * Method to create a new customer in the database.
26
+     *
27
+     * @param GetPaid_Customer $customer customer object.
28
+     */
29
+    public function create( &$customer ) {
30
+        global $wpdb;
31
+
32
+        $values  = array();
33
+        $formats = array();
34
+
35
+        $fields = self::get_database_fields();
36
+        unset( $fields['id'] );
37
+
38
+        foreach ( $fields as $key => $format ) {
39
+            $values[ $key ] = $customer->get( $key, 'edit' );
40
+            $formats[]      = $format;
41
+        }
42
+
43
+        $result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
44
+
45
+        if ( $result ) {
46
+            $customer->set_id( $wpdb->insert_id );
47
+            $customer->apply_changes();
48
+            $customer->clear_cache();
49
+            do_action( 'getpaid_new_customer', $customer );
50
+            return true;
51
+        }
52
+
53
+        return false;
54
+    }
55
+
56
+    /**
57
+     * Method to read a customer from the database.
58
+     *
59
+     * @param GetPaid_Customer $customer customer object.
60
+     *
61
+     */
62
+    public function read( &$customer ) {
63
+        global $wpdb;
64
+
65
+        $customer->set_defaults();
66
+
67
+        if ( ! $customer->get_id() ) {
68
+            $customer->last_error = 'Invalid customer.';
69
+            $customer->set_id( 0 );
70
+            return false;
71
+        }
72
+
73
+        // Maybe retrieve from the cache.
74
+        $raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
75
+
76
+        // If not found, retrieve from the db.
77
+        if ( false === $raw_customer ) {
78
+
79
+            $raw_customer = $wpdb->get_row(
80
+                $wpdb->prepare(
81
+                    "SELECT * FROM {$wpdb->prefix}getpaid_customers WHERE id = %d",
82
+                    $customer->get_id()
83
+                )
84
+            );
85
+
86
+            // Update the cache with our data
87
+            wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
88
+
89
+        }
90
+
91
+        if ( ! $raw_customer ) {
92
+            $raw_customer->last_error = 'Invalid customer.';
93
+            return false;
94
+        }
95
+
96
+        // Loop through raw customer fields.
97
+        foreach ( (array) $raw_customer as $key => $value ) {
98
+            $customer->set( $key, $value );
99
+        }
100
+
101
+        $customer->set_object_read( true );
102
+        do_action( 'getpaid_read_customer', $customer );
103
+
104
+    }
105
+
106
+    /**
107
+     * Method to update a customer in the database.
108
+     *
109
+     * @param GetPaid_Customer $customer Customer object.
110
+     */
111
+    public function update( &$customer ) {
112
+        global $wpdb;
113
+
114
+        do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
115
+
116
+        $changes = $customer->get_changes();
117
+        $values  = array();
118
+        $format  = array();
119
+
120
+        foreach ( self::get_database_fields() as $key => $format ) {
121
+            if ( array_key_exists( $key, $changes ) ) {
122
+                $values[ $key ] = $customer->get( $key, 'edit' );
123
+                $formats[]      = $format;
124
+            }
125
+        }
126
+
127
+        if ( empty( $values ) ) {
128
+            return;
129
+        }
130
+
131
+        $wpdb->update(
132
+            $wpdb->prefix . 'getpaid_customers',
133
+            $values,
134
+            array(
135
+                'id' => $customer->get_id(),
136
+            ),
137
+            $formats,
138
+            '%d'
139
+        );
140
+
141
+        // Apply the changes.
142
+        $customer->apply_changes();
143
+
144
+        // Delete cache.
145
+        $customer->clear_cache();
146
+
147
+        // Fire a hook.
148
+        do_action( 'getpaid_update_customer', $customer );
149
+
150
+    }
151
+
152
+    /**
153
+     * Method to delete a customer from the database.
154
+     *
155
+     * @param GetPaid_Customer $customer
156
+     */
157
+    public function delete( &$customer ) {
158
+        global $wpdb;
159
+
160
+        do_action( 'getpaid_before_delete_customer', $customer );
161
+
162
+        $wpdb->delete(
163
+            $wpdb->prefix . 'getpaid_customers',
164
+            array(
165
+                'id' => $customer->get_id(),
166
+            ),
167
+            '%d'
168
+        );
169
+
170
+        // Delete cache.
171
+        $customer->clear_cache();
172
+
173
+        // Fire a hook.
174
+        do_action( 'getpaid_delete_customer', $customer );
175
+
176
+        $customer->set_id( 0 );
177
+    }
178
+
179
+    /*
180 180
 	|--------------------------------------------------------------------------
181 181
 	| Additional Methods
182 182
 	|--------------------------------------------------------------------------
183 183
 	*/
184
-	public static function get_database_fields() {
185
-
186
-		$fields = array(
187
-			'id'             => '%d',
188
-			'user_id'        => '%d',
189
-			'email'          => '%s',
190
-			'email_cc'       => '%s',
191
-			'status'         => '%s',
192
-			'purchase_value' => '%f',
193
-			'purchase_count' => '%d',
194
-			'date_created'   => '%s',
195
-			'date_modified'  => '%s',
196
-			'uuid'           => '%s',
197
-		);
198
-
199
-		// Add address fields.
200
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
201
-
202
-			// Skip id, user_id and email.
203
-			if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
-				$fields[ $field ] = '%s';
205
-			}
206
-		}
207
-
208
-		return $fields;
209
-	}
184
+    public static function get_database_fields() {
185
+
186
+        $fields = array(
187
+            'id'             => '%d',
188
+            'user_id'        => '%d',
189
+            'email'          => '%s',
190
+            'email_cc'       => '%s',
191
+            'status'         => '%s',
192
+            'purchase_value' => '%f',
193
+            'purchase_count' => '%d',
194
+            'date_created'   => '%s',
195
+            'date_modified'  => '%s',
196
+            'uuid'           => '%s',
197
+        );
198
+
199
+        // Add address fields.
200
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
201
+
202
+            // Skip id, user_id and email.
203
+            if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
+                $fields[ $field ] = '%s';
205
+            }
206
+        }
207
+
208
+        return $fields;
209
+    }
210 210
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Customer_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -26,27 +26,27 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @param GetPaid_Customer $customer customer object.
28 28
 	 */
29
-	public function create( &$customer ) {
29
+	public function create(&$customer) {
30 30
 		global $wpdb;
31 31
 
32 32
 		$values  = array();
33 33
 		$formats = array();
34 34
 
35 35
 		$fields = self::get_database_fields();
36
-		unset( $fields['id'] );
36
+		unset($fields['id']);
37 37
 
38
-		foreach ( $fields as $key => $format ) {
39
-			$values[ $key ] = $customer->get( $key, 'edit' );
38
+		foreach ($fields as $key => $format) {
39
+			$values[$key] = $customer->get($key, 'edit');
40 40
 			$formats[]      = $format;
41 41
 		}
42 42
 
43
-		$result = $wpdb->insert( $wpdb->prefix . 'getpaid_customers', $values, $formats );
43
+		$result = $wpdb->insert($wpdb->prefix . 'getpaid_customers', $values, $formats);
44 44
 
45
-		if ( $result ) {
46
-			$customer->set_id( $wpdb->insert_id );
45
+		if ($result) {
46
+			$customer->set_id($wpdb->insert_id);
47 47
 			$customer->apply_changes();
48 48
 			$customer->clear_cache();
49
-			do_action( 'getpaid_new_customer', $customer );
49
+			do_action('getpaid_new_customer', $customer);
50 50
 			return true;
51 51
 		}
52 52
 
@@ -59,22 +59,22 @@  discard block
 block discarded – undo
59 59
 	 * @param GetPaid_Customer $customer customer object.
60 60
 	 *
61 61
 	 */
62
-	public function read( &$customer ) {
62
+	public function read(&$customer) {
63 63
 		global $wpdb;
64 64
 
65 65
 		$customer->set_defaults();
66 66
 
67
-		if ( ! $customer->get_id() ) {
67
+		if (!$customer->get_id()) {
68 68
 			$customer->last_error = 'Invalid customer.';
69
-			$customer->set_id( 0 );
69
+			$customer->set_id(0);
70 70
 			return false;
71 71
 		}
72 72
 
73 73
 		// Maybe retrieve from the cache.
74
-		$raw_customer = wp_cache_get( $customer->get_id(), 'getpaid_customers' );
74
+		$raw_customer = wp_cache_get($customer->get_id(), 'getpaid_customers');
75 75
 
76 76
 		// If not found, retrieve from the db.
77
-		if ( false === $raw_customer ) {
77
+		if (false === $raw_customer) {
78 78
 
79 79
 			$raw_customer = $wpdb->get_row(
80 80
 				$wpdb->prepare(
@@ -84,22 +84,22 @@  discard block
 block discarded – undo
84 84
 			);
85 85
 
86 86
 			// Update the cache with our data
87
-			wp_cache_set( $customer->get_id(), $raw_customer, 'getpaid_customers' );
87
+			wp_cache_set($customer->get_id(), $raw_customer, 'getpaid_customers');
88 88
 
89 89
 		}
90 90
 
91
-		if ( ! $raw_customer ) {
91
+		if (!$raw_customer) {
92 92
 			$raw_customer->last_error = 'Invalid customer.';
93 93
 			return false;
94 94
 		}
95 95
 
96 96
 		// Loop through raw customer fields.
97
-		foreach ( (array) $raw_customer as $key => $value ) {
98
-			$customer->set( $key, $value );
97
+		foreach ((array) $raw_customer as $key => $value) {
98
+			$customer->set($key, $value);
99 99
 		}
100 100
 
101
-		$customer->set_object_read( true );
102
-		do_action( 'getpaid_read_customer', $customer );
101
+		$customer->set_object_read(true);
102
+		do_action('getpaid_read_customer', $customer);
103 103
 
104 104
 	}
105 105
 
@@ -108,23 +108,23 @@  discard block
 block discarded – undo
108 108
 	 *
109 109
 	 * @param GetPaid_Customer $customer Customer object.
110 110
 	 */
111
-	public function update( &$customer ) {
111
+	public function update(&$customer) {
112 112
 		global $wpdb;
113 113
 
114
-		do_action( 'getpaid_before_update_customer', $customer, $customer->get_changes() );
114
+		do_action('getpaid_before_update_customer', $customer, $customer->get_changes());
115 115
 
116 116
 		$changes = $customer->get_changes();
117 117
 		$values  = array();
118 118
 		$format  = array();
119 119
 
120
-		foreach ( self::get_database_fields() as $key => $format ) {
121
-			if ( array_key_exists( $key, $changes ) ) {
122
-				$values[ $key ] = $customer->get( $key, 'edit' );
120
+		foreach (self::get_database_fields() as $key => $format) {
121
+			if (array_key_exists($key, $changes)) {
122
+				$values[$key] = $customer->get($key, 'edit');
123 123
 				$formats[]      = $format;
124 124
 			}
125 125
 		}
126 126
 
127
-		if ( empty( $values ) ) {
127
+		if (empty($values)) {
128 128
 			return;
129 129
 		}
130 130
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 		$customer->clear_cache();
146 146
 
147 147
 		// Fire a hook.
148
-		do_action( 'getpaid_update_customer', $customer );
148
+		do_action('getpaid_update_customer', $customer);
149 149
 
150 150
 	}
151 151
 
@@ -154,10 +154,10 @@  discard block
 block discarded – undo
154 154
 	 *
155 155
 	 * @param GetPaid_Customer $customer
156 156
 	 */
157
-	public function delete( &$customer ) {
157
+	public function delete(&$customer) {
158 158
 		global $wpdb;
159 159
 
160
-		do_action( 'getpaid_before_delete_customer', $customer );
160
+		do_action('getpaid_before_delete_customer', $customer);
161 161
 
162 162
 		$wpdb->delete(
163 163
 			$wpdb->prefix . 'getpaid_customers',
@@ -171,9 +171,9 @@  discard block
 block discarded – undo
171 171
 		$customer->clear_cache();
172 172
 
173 173
 		// Fire a hook.
174
-		do_action( 'getpaid_delete_customer', $customer );
174
+		do_action('getpaid_delete_customer', $customer);
175 175
 
176
-		$customer->set_id( 0 );
176
+		$customer->set_id(0);
177 177
 	}
178 178
 
179 179
 	/*
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 		);
198 198
 
199 199
 		// Add address fields.
200
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
200
+		foreach (array_keys(getpaid_user_address_fields()) as $field) {
201 201
 
202 202
 			// Skip id, user_id and email.
203
-			if ( ! in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
204
-				$fields[ $field ] = '%s';
203
+			if (!in_array($field, array('id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid'), true)) {
204
+				$fields[$field] = '%s';
205 205
 			}
206 206
 		}
207 207
 
Please login to merge, or discard this patch.
includes/class-getpaid-customer.php 2 patches
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -15,69 +15,69 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Customer extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23 23
     protected $data_store_name = 'customer';
24 24
 
25 25
     /**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'customer';
31
-
32
-	/**
33
-	 * Get the customer if ID is passed, otherwise the customer is new and empty.
34
-	 *
35
-	 * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36
-	 */
37
-	public function __construct( $customer = 0 ) {
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'customer';
31
+
32
+    /**
33
+     * Get the customer if ID is passed, otherwise the customer is new and empty.
34
+     *
35
+     * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36
+     */
37
+    public function __construct( $customer = 0 ) {
38 38
 
39 39
         // Setup default customer data.
40 40
         $this->setup_default_data();
41 41
 
42
-		if ( is_numeric( $customer ) ) {
43
-			$this->set_id( $customer );
44
-		} elseif ( $customer instanceof self ) {
45
-			$this->set_id( $customer->get_id() );
46
-		} elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
-			$this->set_id( $customer_id );
48
-		} elseif ( ! empty( $customer->id ) ) {
49
-			$this->set_id( $customer->id );
50
-		}
42
+        if ( is_numeric( $customer ) ) {
43
+            $this->set_id( $customer );
44
+        } elseif ( $customer instanceof self ) {
45
+            $this->set_id( $customer->get_id() );
46
+        } elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
+            $this->set_id( $customer_id );
48
+        } elseif ( ! empty( $customer->id ) ) {
49
+            $this->set_id( $customer->id );
50
+        }
51 51
 
52 52
         // Load the datastore.
53
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
53
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
54 54
 
55
-		if ( $this->get_id() > 0 ) {
56
-			$this->data_store->read( $this );
55
+        if ( $this->get_id() > 0 ) {
56
+            $this->data_store->read( $this );
57 57
         }
58 58
 
59 59
         $this->set_object_read( true );
60
-	}
60
+    }
61 61
 
62 62
     /**
63
-	 * Sets up default customer data.
64
-	 */
65
-	private function setup_default_data() {
63
+     * Sets up default customer data.
64
+     */
65
+    private function setup_default_data() {
66 66
 
67 67
         $this->data = array(
68
-			'user_id'        => 0,
69
-			'email'          => '',
70
-			'email_cc'       => '',
71
-			'status'         => 'active',
72
-			'purchase_value' => 0,
73
-			'purchase_count' => 0,
74
-			'date_created'   => current_time( 'mysql' ),
75
-			'date_modified'  => current_time( 'mysql' ),
76
-			'uuid'           => wp_generate_uuid4(),
77
-		);
68
+            'user_id'        => 0,
69
+            'email'          => '',
70
+            'email_cc'       => '',
71
+            'status'         => 'active',
72
+            'purchase_value' => 0,
73
+            'purchase_count' => 0,
74
+            'date_created'   => current_time( 'mysql' ),
75
+            'date_modified'  => current_time( 'mysql' ),
76
+            'uuid'           => wp_generate_uuid4(),
77
+        );
78 78
 
79 79
         // Add address fields.
80
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
80
+        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
81 81
 
82 82
             if ( isset( $this->data[ $field ] ) ) {
83 83
                 continue;
@@ -95,22 +95,22 @@  discard block
 block discarded – undo
95 95
                 continue;
96 96
             }
97 97
 
98
-			$this->data[ $field ] = '';
99
-		}
98
+            $this->data[ $field ] = '';
99
+        }
100 100
 
101 101
         $this->default_data = $this->data;
102
-	}
103
-
104
-	/**
105
-	 * Given a customer email or user id, it returns a customer id.
106
-	 *
107
-	 * @static
108
-	 * @param string $value
109
-	 * @since 1.0.15
110
-	 * @return int
111
-	 */
112
-	public static function get_customer_id_by( $value, $by = 'email' ) {
113
-		global $wpdb;
102
+    }
103
+
104
+    /**
105
+     * Given a customer email or user id, it returns a customer id.
106
+     *
107
+     * @static
108
+     * @param string $value
109
+     * @since 1.0.15
110
+     * @return int
111
+     */
112
+    public static function get_customer_id_by( $value, $by = 'email' ) {
113
+        global $wpdb;
114 114
 
115 115
         // Prepare value.
116 116
         if ( 'email' === $by ) {
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
             return 0;
126 126
         }
127 127
 
128
-		// Maybe retrieve from the cache.
128
+        // Maybe retrieve from the cache.
129 129
         $cache_key   = 'getpaid_customer_ids_by_' . $by;
130
-		$customer_id = wp_cache_get( $value, $cache_key );
131
-		if ( false !== $customer_id ) {
132
-			return $customer_id;
133
-		}
130
+        $customer_id = wp_cache_get( $value, $cache_key );
131
+        if ( false !== $customer_id ) {
132
+            return $customer_id;
133
+        }
134 134
 
135 135
         if ( 'email' === $by ) {
136 136
             $customer_id = (int) $wpdb->get_var(
@@ -142,23 +142,23 @@  discard block
 block discarded – undo
142 142
             );
143 143
         }
144 144
 
145
-		// Update the cache with our data
146
-		wp_cache_set( $value, $customer_id, $cache_key );
145
+        // Update the cache with our data
146
+        wp_cache_set( $value, $customer_id, $cache_key );
147 147
 
148
-		return $customer_id;
148
+        return $customer_id;
149 149
 
150
-	}
150
+    }
151 151
 
152
-	/**
152
+    /**
153 153
      * Clears the customer's cache.
154 154
      */
155 155
     public function clear_cache() {
156 156
         wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' );
157 157
         wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' );
158
-		wp_cache_delete( $this->get_id(), 'getpaid_customers' );
159
-	}
158
+        wp_cache_delete( $this->get_id(), 'getpaid_customers' );
159
+    }
160 160
 
161
-	/*
161
+    /*
162 162
 	|--------------------------------------------------------------------------
163 163
 	| CRUD methods
164 164
 	|--------------------------------------------------------------------------
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
             return call_user_func( array( $this, 'get_' . $key ), $context );
190 190
         }
191 191
 
192
-		return $this->get_prop( $key, $context );
192
+        return $this->get_prop( $key, $context );
193 193
 
194 194
     }
195 195
 
196
-	/*
196
+    /*
197 197
 	|--------------------------------------------------------------------------
198 198
 	| Setters
199 199
 	|--------------------------------------------------------------------------
@@ -216,114 +216,114 @@  discard block
 block discarded – undo
216 216
             return call_user_func( array( $this, 'set_' . $key ), $value );
217 217
         }
218 218
 
219
-		return $this->set_prop( $key, $value );
219
+        return $this->set_prop( $key, $value );
220 220
 
221 221
     }
222 222
 
223
-	/**
224
-	 * Sets customer status.
225
-	 *
226
-	 * @since 1.0.0
227
-	 * @param  string $status New status.
228
-	 */
229
-	public function set_status( $status ) {
230
-
231
-		if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
-			return $this->set_prop( 'status', $status );
233
-		}
234
-
235
-		$this->set_prop( 'status', 'inactive' );
236
-	}
237
-
238
-	/**
239
-	 * Sets the purchase value.
240
-	 *
241
-	 * @since 1.0.0
242
-	 * @param float $purchase_value.
243
-	 */
244
-	public function set_purchase_value( $purchase_value ) {
245
-		$this->set_prop( 'purchase_value', (float) $purchase_value );
246
-	}
223
+    /**
224
+     * Sets customer status.
225
+     *
226
+     * @since 1.0.0
227
+     * @param  string $status New status.
228
+     */
229
+    public function set_status( $status ) {
230
+
231
+        if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
+            return $this->set_prop( 'status', $status );
233
+        }
234
+
235
+        $this->set_prop( 'status', 'inactive' );
236
+    }
237
+
238
+    /**
239
+     * Sets the purchase value.
240
+     *
241
+     * @since 1.0.0
242
+     * @param float $purchase_value.
243
+     */
244
+    public function set_purchase_value( $purchase_value ) {
245
+        $this->set_prop( 'purchase_value', (float) $purchase_value );
246
+    }
247 247
 
248 248
     /**
249
-	 * Sets the purchase count.
250
-	 *
251
-	 * @since 1.0.0
252
-	 * @param int $purchase_count.
253
-	 */
254
-	public function set_purchase_count( $purchase_count ) {
255
-		$this->set_prop( 'purchase_count', absint( $purchase_count ) );
256
-	}
249
+     * Sets the purchase count.
250
+     *
251
+     * @since 1.0.0
252
+     * @param int $purchase_count.
253
+     */
254
+    public function set_purchase_count( $purchase_count ) {
255
+        $this->set_prop( 'purchase_count', absint( $purchase_count ) );
256
+    }
257 257
 
258 258
     /**
259
-	 * Sets the user id.
260
-	 *
261
-	 * @since 1.0.0
262
-	 * @param int $user_id.
263
-	 */
264
-	public function set_user_id( $user_id ) {
265
-		$this->set_prop( 'user_id', absint( $user_id ) );
266
-	}
259
+     * Sets the user id.
260
+     *
261
+     * @since 1.0.0
262
+     * @param int $user_id.
263
+     */
264
+    public function set_user_id( $user_id ) {
265
+        $this->set_prop( 'user_id', absint( $user_id ) );
266
+    }
267 267
 
268 268
     /**
269
-	 * Sets the email.
270
-	 *
271
-	 * @since 1.0.0
272
-	 * @param string $email.
273
-	 */
274
-	public function set_email( $email ) {
269
+     * Sets the email.
270
+     *
271
+     * @since 1.0.0
272
+     * @param string $email.
273
+     */
274
+    public function set_email( $email ) {
275 275
         $email = is_string( $email ) ? sanitize_email( $email ) : '';
276
-		$this->set_prop( 'email', $email );
277
-	}
276
+        $this->set_prop( 'email', $email );
277
+    }
278 278
 
279 279
     /**
280
-	 * Sets the email cc.
281
-	 *
282
-	 * @since 1.0.0
283
-	 * @param string $email_cc.
284
-	 */
285
-	public function set_email_cc( $email_cc ) {
280
+     * Sets the email cc.
281
+     *
282
+     * @since 1.0.0
283
+     * @param string $email_cc.
284
+     */
285
+    public function set_email_cc( $email_cc ) {
286 286
         $email_cc = implode( ', ', wp_parse_list( $email_cc ) );
287
-		$this->set_prop( 'email_cc', $email_cc );
288
-	}
287
+        $this->set_prop( 'email_cc', $email_cc );
288
+    }
289 289
 
290 290
     /**
291
-	 * Sets the created date.
292
-	 *
293
-	 * @since 1.0.0
294
-	 * @param  string $date_created date created.
295
-	 */
296
-	public function set_date_created( $date_created ) {
291
+     * Sets the created date.
292
+     *
293
+     * @since 1.0.0
294
+     * @param  string $date_created date created.
295
+     */
296
+    public function set_date_created( $date_created ) {
297 297
 
298
-		$date = strtotime( $date_created );
298
+        $date = strtotime( $date_created );
299 299
 
300 300
         if ( $date && $date_created !== '0000-00-00 00:00:00'  && $date_created !== '0000-00-00 00:00' ) {
301 301
             $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) );
302 302
             return;
303
-		}
303
+        }
304 304
 
305
-		$this->set_prop( 'date_created', null );
306
-	}
305
+        $this->set_prop( 'date_created', null );
306
+    }
307 307
 
308 308
     /**
309
-	 * Sets the created date.
310
-	 *
311
-	 * @since 1.0.0
312
-	 * @param  string $date_modified date created.
313
-	 */
314
-	public function set_date_modified( $date_modified ) {
309
+     * Sets the created date.
310
+     *
311
+     * @since 1.0.0
312
+     * @param  string $date_modified date created.
313
+     */
314
+    public function set_date_modified( $date_modified ) {
315 315
 
316
-		$date = strtotime( $date_modified );
316
+        $date = strtotime( $date_modified );
317 317
 
318 318
         if ( $date && $date_modified !== '0000-00-00 00:00:00'  && $date_modified !== '0000-00-00 00:00' ) {
319 319
             $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) );
320 320
             return;
321
-		}
321
+        }
322 322
 
323
-		$this->set_prop( 'date_modified', null );
324
-	}
323
+        $this->set_prop( 'date_modified', null );
324
+    }
325 325
 
326
-	/*
326
+    /*
327 327
 	|--------------------------------------------------------------------------
328 328
 	| Additional methods
329 329
 	|--------------------------------------------------------------------------
@@ -332,12 +332,12 @@  discard block
 block discarded – undo
332 332
 	|
333 333
 	*/
334 334
 
335
-	/**
336
-	 * Saves the customer.
337
-	 *
338
-	 * @since 1.0.0
339
-	 */
340
-	public function save() {
335
+    /**
336
+     * Saves the customer.
337
+     *
338
+     * @since 1.0.0
339
+     */
340
+    public function save() {
341 341
 
342 342
         $maybe_set = array(
343 343
             'uuid'         => wp_generate_uuid4(),
@@ -354,29 +354,29 @@  discard block
 block discarded – undo
354 354
 
355 355
         $this->set( 'date_modified', current_time( 'mysql' ) );
356 356
 
357
-		return parent::save();
358
-	}
357
+        return parent::save();
358
+    }
359 359
 
360 360
     /**
361
-	 * Helper method to clone a customer from a user ID.
362
-	 *
363
-	 * @since 1.0.0
364
-	 * @param int $user_id.
365
-	 */
366
-	public function clone_user( $user_id ) {
361
+     * Helper method to clone a customer from a user ID.
362
+     *
363
+     * @since 1.0.0
364
+     * @param int $user_id.
365
+     */
366
+    public function clone_user( $user_id ) {
367 367
         $user = get_userdata( $user_id );
368 368
 
369 369
         if ( empty( $user ) ) {
370 370
             return;
371 371
         }
372 372
 
373
-		$this->set_user_id( $user->ID );
373
+        $this->set_user_id( $user->ID );
374 374
         $this->set_email( $user->user_email );
375 375
         $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) );
376 376
         $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) );
377 377
         $this->set( 'first_name', $user->first_name );
378 378
         $this->set( 'last_name', $user->last_name );
379
-		$this->set_date_created( $user->user_registered );
379
+        $this->set_date_created( $user->user_registered );
380 380
 
381 381
         // Fetch extra data from WC or old GetPaid.
382 382
         $prefixes = array(
@@ -400,18 +400,18 @@  discard block
 block discarded – undo
400 400
                     continue;
401 401
                 }
402 402
             }
403
-		}
404
-	}
403
+        }
404
+    }
405 405
 
406 406
     /**
407
-	 * Helper method to migrate an existing user ID to the new customers table.
408
-	 *
409
-	 * @since 1.0.0
410
-	 * @param int $user_id.
411
-	 */
412
-	public function migrate_from_user( $user_id ) {
407
+     * Helper method to migrate an existing user ID to the new customers table.
408
+     *
409
+     * @since 1.0.0
410
+     * @param int $user_id.
411
+     */
412
+    public function migrate_from_user( $user_id ) {
413 413
         $this->clone_user( $user_id );
414 414
         do_action( 'getpaid_customer_migrated_from_user', $this, $user_id );
415 415
         $this->save();
416
-	}
416
+    }
417 417
 }
Please login to merge, or discard this patch.
Spacing   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @since   1.0.15
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Customer class.
@@ -34,29 +34,29 @@  discard block
 block discarded – undo
34 34
 	 *
35 35
 	 * @param int|string|GetPaid_Customer|object $customer customer id, object, or email.
36 36
 	 */
37
-	public function __construct( $customer = 0 ) {
37
+	public function __construct($customer = 0) {
38 38
 
39 39
         // Setup default customer data.
40 40
         $this->setup_default_data();
41 41
 
42
-		if ( is_numeric( $customer ) ) {
43
-			$this->set_id( $customer );
44
-		} elseif ( $customer instanceof self ) {
45
-			$this->set_id( $customer->get_id() );
46
-		} elseif ( is_string( $customer ) && $customer_id = self::get_customer_id_by( $customer, 'email' ) ) {
47
-			$this->set_id( $customer_id );
48
-		} elseif ( ! empty( $customer->id ) ) {
49
-			$this->set_id( $customer->id );
42
+		if (is_numeric($customer)) {
43
+			$this->set_id($customer);
44
+		} elseif ($customer instanceof self) {
45
+			$this->set_id($customer->get_id());
46
+		} elseif (is_string($customer) && $customer_id = self::get_customer_id_by($customer, 'email')) {
47
+			$this->set_id($customer_id);
48
+		} elseif (!empty($customer->id)) {
49
+			$this->set_id($customer->id);
50 50
 		}
51 51
 
52 52
         // Load the datastore.
53
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
53
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
54 54
 
55
-		if ( $this->get_id() > 0 ) {
56
-			$this->data_store->read( $this );
55
+		if ($this->get_id() > 0) {
56
+			$this->data_store->read($this);
57 57
         }
58 58
 
59
-        $this->set_object_read( true );
59
+        $this->set_object_read(true);
60 60
 	}
61 61
 
62 62
     /**
@@ -71,31 +71,31 @@  discard block
 block discarded – undo
71 71
 			'status'         => 'active',
72 72
 			'purchase_value' => 0,
73 73
 			'purchase_count' => 0,
74
-			'date_created'   => current_time( 'mysql' ),
75
-			'date_modified'  => current_time( 'mysql' ),
74
+			'date_created'   => current_time('mysql'),
75
+			'date_modified'  => current_time('mysql'),
76 76
 			'uuid'           => wp_generate_uuid4(),
77 77
 		);
78 78
 
79 79
         // Add address fields.
80
-		foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
80
+		foreach (array_keys(getpaid_user_address_fields()) as $field) {
81 81
 
82
-            if ( isset( $this->data[ $field ] ) ) {
82
+            if (isset($this->data[$field])) {
83 83
                 continue;
84 84
             }
85 85
 
86 86
             // Country.
87
-            if ( 'country' === $field ) {
88
-                $this->data[ $field ] = wpinv_get_default_country();
87
+            if ('country' === $field) {
88
+                $this->data[$field] = wpinv_get_default_country();
89 89
                 continue;
90 90
             }
91 91
 
92 92
             // State.
93
-            if ( 'state' === $field ) {
94
-                $this->data[ $field ] = wpinv_get_default_state();
93
+            if ('state' === $field) {
94
+                $this->data[$field] = wpinv_get_default_state();
95 95
                 continue;
96 96
             }
97 97
 
98
-			$this->data[ $field ] = '';
98
+			$this->data[$field] = '';
99 99
 		}
100 100
 
101 101
         $this->default_data = $this->data;
@@ -109,41 +109,41 @@  discard block
 block discarded – undo
109 109
 	 * @since 1.0.15
110 110
 	 * @return int
111 111
 	 */
112
-	public static function get_customer_id_by( $value, $by = 'email' ) {
112
+	public static function get_customer_id_by($value, $by = 'email') {
113 113
 		global $wpdb;
114 114
 
115 115
         // Prepare value.
116
-        if ( 'email' === $by ) {
117
-            $value = sanitize_email( $value );
118
-        } elseif ( 'user_id' === $by ) {
119
-            $value = absint( $value );
116
+        if ('email' === $by) {
117
+            $value = sanitize_email($value);
118
+        } elseif ('user_id' === $by) {
119
+            $value = absint($value);
120 120
         } else {
121 121
             return 0;
122 122
         }
123 123
 
124
-        if ( empty( $value ) ) {
124
+        if (empty($value)) {
125 125
             return 0;
126 126
         }
127 127
 
128 128
 		// Maybe retrieve from the cache.
129
-        $cache_key   = 'getpaid_customer_ids_by_' . $by;
130
-		$customer_id = wp_cache_get( $value, $cache_key );
131
-		if ( false !== $customer_id ) {
129
+        $cache_key = 'getpaid_customer_ids_by_' . $by;
130
+		$customer_id = wp_cache_get($value, $cache_key);
131
+		if (false !== $customer_id) {
132 132
 			return $customer_id;
133 133
 		}
134 134
 
135
-        if ( 'email' === $by ) {
135
+        if ('email' === $by) {
136 136
             $customer_id = (int) $wpdb->get_var(
137
-                $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value )
137
+                $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE email=%s LIMIT 1", $value)
138 138
             );
139
-        } elseif ( 'user_id' === $by ) {
139
+        } elseif ('user_id' === $by) {
140 140
             $customer_id = (int) $wpdb->get_var(
141
-                $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value )
141
+                $wpdb->prepare("SELECT id FROM {$wpdb->prefix}getpaid_customers WHERE user_id=%d LIMIT 1", $value)
142 142
             );
143 143
         }
144 144
 
145 145
 		// Update the cache with our data
146
-		wp_cache_set( $value, $customer_id, $cache_key );
146
+		wp_cache_set($value, $customer_id, $cache_key);
147 147
 
148 148
 		return $customer_id;
149 149
 
@@ -153,9 +153,9 @@  discard block
 block discarded – undo
153 153
      * Clears the customer's cache.
154 154
      */
155 155
     public function clear_cache() {
156
-        wp_cache_delete( $this->get( 'email' ), 'getpaid_customer_ids_by_email' );
157
-        wp_cache_delete( $this->get( 'user_id' ), 'getpaid_customer_ids_by_user_id' );
158
-		wp_cache_delete( $this->get_id(), 'getpaid_customers' );
156
+        wp_cache_delete($this->get('email'), 'getpaid_customer_ids_by_email');
157
+        wp_cache_delete($this->get('user_id'), 'getpaid_customer_ids_by_user_id');
158
+		wp_cache_delete($this->get_id(), 'getpaid_customers');
159 159
 	}
160 160
 
161 161
 	/*
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
      * @param  string $key The key to fetch.
180 180
      * @param  string $context View or edit context.
181 181
      */
182
-    public function get( $key, $context = 'view' ) {
182
+    public function get($key, $context = 'view') {
183 183
 
184 184
         // Maybe strip _wpinv_ prefix from key.
185
-        $key = str_replace( '_wpinv_', '', $key );
185
+        $key = str_replace('_wpinv_', '', $key);
186 186
 
187 187
         // Check if we have a helper method for that.
188
-        if ( method_exists( $this, 'get_' . $key ) ) {
189
-            return call_user_func( array( $this, 'get_' . $key ), $context );
188
+        if (method_exists($this, 'get_' . $key)) {
189
+            return call_user_func(array($this, 'get_' . $key), $context);
190 190
         }
191 191
 
192
-		return $this->get_prop( $key, $context );
192
+		return $this->get_prop($key, $context);
193 193
 
194 194
     }
195 195
 
@@ -209,14 +209,14 @@  discard block
 block discarded – undo
209 209
      * @param string $key The key to fetch.
210 210
      * @param mixed $value The new value.
211 211
      */
212
-    public function set( $key, $value ) {
212
+    public function set($key, $value) {
213 213
 
214 214
         // Check if we have a helper method for that.
215
-        if ( method_exists( $this, 'set_' . $key ) ) {
216
-            return call_user_func( array( $this, 'set_' . $key ), $value );
215
+        if (method_exists($this, 'set_' . $key)) {
216
+            return call_user_func(array($this, 'set_' . $key), $value);
217 217
         }
218 218
 
219
-		return $this->set_prop( $key, $value );
219
+		return $this->set_prop($key, $value);
220 220
 
221 221
     }
222 222
 
@@ -226,13 +226,13 @@  discard block
 block discarded – undo
226 226
 	 * @since 1.0.0
227 227
 	 * @param  string $status New status.
228 228
 	 */
229
-	public function set_status( $status ) {
229
+	public function set_status($status) {
230 230
 
231
-		if ( in_array( $status, array( 'active', 'inactive', 'blocked' ), true ) ) {
232
-			return $this->set_prop( 'status', $status );
231
+		if (in_array($status, array('active', 'inactive', 'blocked'), true)) {
232
+			return $this->set_prop('status', $status);
233 233
 		}
234 234
 
235
-		$this->set_prop( 'status', 'inactive' );
235
+		$this->set_prop('status', 'inactive');
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
 	 * @since 1.0.0
242 242
 	 * @param float $purchase_value.
243 243
 	 */
244
-	public function set_purchase_value( $purchase_value ) {
245
-		$this->set_prop( 'purchase_value', (float) $purchase_value );
244
+	public function set_purchase_value($purchase_value) {
245
+		$this->set_prop('purchase_value', (float) $purchase_value);
246 246
 	}
247 247
 
248 248
     /**
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 	 * @since 1.0.0
252 252
 	 * @param int $purchase_count.
253 253
 	 */
254
-	public function set_purchase_count( $purchase_count ) {
255
-		$this->set_prop( 'purchase_count', absint( $purchase_count ) );
254
+	public function set_purchase_count($purchase_count) {
255
+		$this->set_prop('purchase_count', absint($purchase_count));
256 256
 	}
257 257
 
258 258
     /**
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 	 * @since 1.0.0
262 262
 	 * @param int $user_id.
263 263
 	 */
264
-	public function set_user_id( $user_id ) {
265
-		$this->set_prop( 'user_id', absint( $user_id ) );
264
+	public function set_user_id($user_id) {
265
+		$this->set_prop('user_id', absint($user_id));
266 266
 	}
267 267
 
268 268
     /**
@@ -271,9 +271,9 @@  discard block
 block discarded – undo
271 271
 	 * @since 1.0.0
272 272
 	 * @param string $email.
273 273
 	 */
274
-	public function set_email( $email ) {
275
-        $email = is_string( $email ) ? sanitize_email( $email ) : '';
276
-		$this->set_prop( 'email', $email );
274
+	public function set_email($email) {
275
+        $email = is_string($email) ? sanitize_email($email) : '';
276
+		$this->set_prop('email', $email);
277 277
 	}
278 278
 
279 279
     /**
@@ -282,9 +282,9 @@  discard block
 block discarded – undo
282 282
 	 * @since 1.0.0
283 283
 	 * @param string $email_cc.
284 284
 	 */
285
-	public function set_email_cc( $email_cc ) {
286
-        $email_cc = implode( ', ', wp_parse_list( $email_cc ) );
287
-		$this->set_prop( 'email_cc', $email_cc );
285
+	public function set_email_cc($email_cc) {
286
+        $email_cc = implode(', ', wp_parse_list($email_cc));
287
+		$this->set_prop('email_cc', $email_cc);
288 288
 	}
289 289
 
290 290
     /**
@@ -293,16 +293,16 @@  discard block
 block discarded – undo
293 293
 	 * @since 1.0.0
294 294
 	 * @param  string $date_created date created.
295 295
 	 */
296
-	public function set_date_created( $date_created ) {
296
+	public function set_date_created($date_created) {
297 297
 
298
-		$date = strtotime( $date_created );
298
+		$date = strtotime($date_created);
299 299
 
300
-        if ( $date && $date_created !== '0000-00-00 00:00:00'  && $date_created !== '0000-00-00 00:00' ) {
301
-            $this->set_prop( 'date_created', gmdate( 'Y-m-d H:i:s', $date ) );
300
+        if ($date && $date_created !== '0000-00-00 00:00:00' && $date_created !== '0000-00-00 00:00') {
301
+            $this->set_prop('date_created', gmdate('Y-m-d H:i:s', $date));
302 302
             return;
303 303
 		}
304 304
 
305
-		$this->set_prop( 'date_created', null );
305
+		$this->set_prop('date_created', null);
306 306
 	}
307 307
 
308 308
     /**
@@ -311,16 +311,16 @@  discard block
 block discarded – undo
311 311
 	 * @since 1.0.0
312 312
 	 * @param  string $date_modified date created.
313 313
 	 */
314
-	public function set_date_modified( $date_modified ) {
314
+	public function set_date_modified($date_modified) {
315 315
 
316
-		$date = strtotime( $date_modified );
316
+		$date = strtotime($date_modified);
317 317
 
318
-        if ( $date && $date_modified !== '0000-00-00 00:00:00'  && $date_modified !== '0000-00-00 00:00' ) {
319
-            $this->set_prop( 'date_modified', gmdate( 'Y-m-d H:i:s', $date ) );
318
+        if ($date && $date_modified !== '0000-00-00 00:00:00' && $date_modified !== '0000-00-00 00:00') {
319
+            $this->set_prop('date_modified', gmdate('Y-m-d H:i:s', $date));
320 320
             return;
321 321
 		}
322 322
 
323
-		$this->set_prop( 'date_modified', null );
323
+		$this->set_prop('date_modified', null);
324 324
 	}
325 325
 
326 326
 	/*
@@ -341,18 +341,18 @@  discard block
 block discarded – undo
341 341
 
342 342
         $maybe_set = array(
343 343
             'uuid'         => wp_generate_uuid4(),
344
-            'date_created' => current_time( 'mysql' ),
344
+            'date_created' => current_time('mysql'),
345 345
         );
346 346
 
347
-        foreach ( $maybe_set as $key => $value ) {
348
-            $current_value = $this->get( $key );
347
+        foreach ($maybe_set as $key => $value) {
348
+            $current_value = $this->get($key);
349 349
 
350
-            if ( empty( $current_value ) ) {
351
-                $this->set( $key, $value );
350
+            if (empty($current_value)) {
351
+                $this->set($key, $value);
352 352
             }
353 353
         }
354 354
 
355
-        $this->set( 'date_modified', current_time( 'mysql' ) );
355
+        $this->set('date_modified', current_time('mysql'));
356 356
 
357 357
 		return parent::save();
358 358
 	}
@@ -363,20 +363,20 @@  discard block
 block discarded – undo
363 363
 	 * @since 1.0.0
364 364
 	 * @param int $user_id.
365 365
 	 */
366
-	public function clone_user( $user_id ) {
367
-        $user = get_userdata( $user_id );
366
+	public function clone_user($user_id) {
367
+        $user = get_userdata($user_id);
368 368
 
369
-        if ( empty( $user ) ) {
369
+        if (empty($user)) {
370 370
             return;
371 371
         }
372 372
 
373
-		$this->set_user_id( $user->ID );
374
-        $this->set_email( $user->user_email );
375
-        $this->set_purchase_value( getpaid_get_user_total_spend( $user->ID ) );
376
-        $this->set_purchase_count( getpaid_count_user_invoices( $user->ID ) );
377
-        $this->set( 'first_name', $user->first_name );
378
-        $this->set( 'last_name', $user->last_name );
379
-		$this->set_date_created( $user->user_registered );
373
+		$this->set_user_id($user->ID);
374
+        $this->set_email($user->user_email);
375
+        $this->set_purchase_value(getpaid_get_user_total_spend($user->ID));
376
+        $this->set_purchase_count(getpaid_count_user_invoices($user->ID));
377
+        $this->set('first_name', $user->first_name);
378
+        $this->set('last_name', $user->last_name);
379
+		$this->set_date_created($user->user_registered);
380 380
 
381 381
         // Fetch extra data from WC or old GetPaid.
382 382
         $prefixes = array(
@@ -385,18 +385,18 @@  discard block
 block discarded – undo
385 385
             '',
386 386
         );
387 387
 
388
-        foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
388
+        foreach (array_keys(getpaid_user_address_fields()) as $field) {
389 389
 
390
-            foreach ( $prefixes as $prefix ) {
390
+            foreach ($prefixes as $prefix) {
391 391
 
392 392
                 // Meta table.
393
-                $value = get_user_meta( $user_id, $prefix . $field, true );
393
+                $value = get_user_meta($user_id, $prefix . $field, true);
394 394
 
395 395
                 // UWP table.
396
-                $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
396
+                $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
397 397
 
398
-                if ( ! empty( $value ) ) {
399
-                    $this->set( $field, $value );
398
+                if (!empty($value)) {
399
+                    $this->set($field, $value);
400 400
                     continue;
401 401
                 }
402 402
             }
@@ -409,9 +409,9 @@  discard block
 block discarded – undo
409 409
 	 * @since 1.0.0
410 410
 	 * @param int $user_id.
411 411
 	 */
412
-	public function migrate_from_user( $user_id ) {
413
-        $this->clone_user( $user_id );
414
-        do_action( 'getpaid_customer_migrated_from_user', $this, $user_id );
412
+	public function migrate_from_user($user_id) {
413
+        $this->clone_user($user_id);
414
+        do_action('getpaid_customer_migrated_from_user', $this, $user_id);
415 415
         $this->save();
416 416
 	}
417 417
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-invoice-items.php 2 patches
Indentation   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -75,16 +75,16 @@  discard block
 block discarded – undo
75 75
             $class .= ' wpi-recurring';
76 76
         }
77 77
 
78
-		$refund_url = wp_nonce_url(
79
-			add_query_arg(
80
-				array(
81
-					'getpaid-admin-action' => 'refund_invoice',
82
-					'invoice_id'           => $invoice->get_id(),
83
-				)
84
-			),
85
-			'getpaid-nonce',
86
-			'getpaid-nonce'
87
-		);
78
+        $refund_url = wp_nonce_url(
79
+            add_query_arg(
80
+                array(
81
+                    'getpaid-admin-action' => 'refund_invoice',
82
+                    'invoice_id'           => $invoice->get_id(),
83
+                )
84
+            ),
85
+            'getpaid-nonce',
86
+            'getpaid-nonce'
87
+        );
88 88
     ?>
89 89
 
90 90
         <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>">
@@ -96,8 +96,8 @@  discard block
 block discarded – undo
96 96
                             <th class="
97 97
                             <?php
98 98
                             echo esc_attr( $key );
99
-							echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100
-							?>
99
+                            echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100
+                            ?>
101 101
 							"><?php echo wp_kses_post( $label ); ?></th>
102 102
                         <?php endforeach; ?>
103 103
                     </tr>
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
                 <tbody class="wpinv-line-items">
107 107
                     <?php
108 108
                         foreach ( $invoice->get_items() as $int => $item ) {
109
-						self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
109
+                        self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
110 110
                         }
111 111
                     ?>
112 112
                 </tbody>
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
                                                         <?php
152 152
                                                         wpinv_html_select(
153 153
                                                             array(
154
-																'options'          => $item_types,
155
-																'name'             => '_wpinv_quick[type]',
156
-																'id'               => '_wpinv_quick_type',
157
-																'selected'         => 'custom',
158
-																'show_option_all'  => false,
159
-																'show_option_none' => false,
160
-																'class'            => 'gdmbx2-text-medium wpinv-quick-type',
154
+                                                                'options'          => $item_types,
155
+                                                                'name'             => '_wpinv_quick[type]',
156
+                                                                'id'               => '_wpinv_quick_type',
157
+                                                                'selected'         => 'custom',
158
+                                                                'show_option_all'  => false,
159
+                                                                'show_option_none' => false,
160
+                                                                'class'            => 'gdmbx2-text-medium wpinv-quick-type',
161 161
                                                             )
162 162
                                                         );
163 163
                                                             ?>
@@ -172,16 +172,16 @@  discard block
 block discarded – undo
172 172
                                                             <?php
173 173
                                                                 wpinv_html_select(
174 174
                                                                     array(
175
-																		'options'          => array_merge(
176
-																			array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
177
-																			getpaid_get_tax_rules()
178
-																		),
179
-																		'name'             => '_wpinv_quick[vat_rule]',
180
-																		'id'               => '_wpinv_quick_vat_rule',
181
-																		'show_option_all'  => false,
182
-																		'show_option_none' => false,
183
-																		'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
184
-																		'selected'         => 'digital',
175
+                                                                        'options'          => array_merge(
176
+                                                                            array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
177
+                                                                            getpaid_get_tax_rules()
178
+                                                                        ),
179
+                                                                        'name'             => '_wpinv_quick[vat_rule]',
180
+                                                                        'id'               => '_wpinv_quick_vat_rule',
181
+                                                                        'show_option_all'  => false,
182
+                                                                        'show_option_none' => false,
183
+                                                                        'class'            => 'gdmbx2-text-medium wpinv-quick-vat-rule',
184
+                                                                        'selected'         => 'digital',
185 185
                                                                     )
186 186
                                                                 );
187 187
                                                             ?>
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
                                                             <?php
195 195
                                                                 wpinv_html_select(
196 196
                                                                     array(
197
-																		'options'          => array_merge(
198
-																			array( '' => __( 'Select VAT Class', 'invoicing' ) ),
199
-																			getpaid_get_tax_classes()
200
-																		),
201
-																		'name'             => '_wpinv_quick[vat_class]',
202
-																		'id'               => '_wpinv_quick_vat_class',
203
-																		'show_option_all'  => false,
204
-																		'show_option_none' => false,
205
-																		'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
206
-																		'selected'         => '_standard',
197
+                                                                        'options'          => array_merge(
198
+                                                                            array( '' => __( 'Select VAT Class', 'invoicing' ) ),
199
+                                                                            getpaid_get_tax_classes()
200
+                                                                        ),
201
+                                                                        'name'             => '_wpinv_quick[vat_class]',
202
+                                                                        'id'               => '_wpinv_quick_vat_class',
203
+                                                                        'show_option_all'  => false,
204
+                                                                        'show_option_none' => false,
205
+                                                                        'class'            => 'gdmbx2-text-medium wpinv-quick-vat-class',
206
+                                                                        'selected'         => '_standard',
207 207
                                                                     )
208 208
                                                                 );
209 209
                                                             ?>
@@ -294,37 +294,37 @@  discard block
 block discarded – undo
294 294
 								</p>
295 295
 								<?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?>
296 296
 									<?php
297
-										aui()->input(
298
-											array(
299
-												'type'  => 'checkbox',
300
-												'name'  => 'getpaid_refund_remote',
301
-												'id'    => 'getpaid_refund_remote',
302
-												'label' => sprintf(
303
-													'Refund payment in %s',
304
-													wpinv_get_gateway_admin_label( $invoice->get_gateway() )
305
-												),
306
-												'value' => 1,
307
-												'class' => 'getpaid-refund-field',
308
-											),
309
-											true
310
-										);
311
-									?>
297
+                                        aui()->input(
298
+                                            array(
299
+                                                'type'  => 'checkbox',
300
+                                                'name'  => 'getpaid_refund_remote',
301
+                                                'id'    => 'getpaid_refund_remote',
302
+                                                'label' => sprintf(
303
+                                                    'Refund payment in %s',
304
+                                                    wpinv_get_gateway_admin_label( $invoice->get_gateway() )
305
+                                                ),
306
+                                                'value' => 1,
307
+                                                'class' => 'getpaid-refund-field',
308
+                                            ),
309
+                                            true
310
+                                        );
311
+                                    ?>
312 312
 								<?php endif; ?>
313 313
 
314 314
 								<?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?>
315 315
 									<?php
316
-										aui()->input(
317
-											array(
318
-												'type'  => 'checkbox',
319
-												'name'  => 'getpaid_cancel_subscription',
320
-												'id'    => 'getpaid_cancel_subscription',
321
-												'label' => __( 'Cancel subscription', 'invoicing' ),
322
-												'value' => 1,
323
-												'class' => 'getpaid-refund-field',
324
-											),
325
-											true
326
-										);
327
-									?>
316
+                                        aui()->input(
317
+                                            array(
318
+                                                'type'  => 'checkbox',
319
+                                                'name'  => 'getpaid_cancel_subscription',
320
+                                                'id'    => 'getpaid_cancel_subscription',
321
+                                                'label' => __( 'Cancel subscription', 'invoicing' ),
322
+                                                'value' => 1,
323
+                                                'class' => 'getpaid-refund-field',
324
+                                            ),
325
+                                            true
326
+                                        );
327
+                                    ?>
328 328
 								<?php endif; ?>
329 329
                             </div>
330 330
                             <div class="modal-footer">
@@ -364,23 +364,23 @@  discard block
 block discarded – undo
364 364
                 <?php
365 365
                     if ( $invoice->is_paid() ) {
366 366
 
367
-						printf(
368
-							'<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
369
-							esc_html__( 'Refund', 'invoicing' )
370
-						);
367
+                        printf(
368
+                            '<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
369
+                            esc_html__( 'Refund', 'invoicing' )
370
+                        );
371 371
                     } elseif ( ! $invoice->is_refunded() ) {
372
-						wpinv_item_dropdown(
373
-							array(
374
-								'name'           => 'wpinv_invoice_item',
375
-								'id'             => 'wpinv_invoice_item',
376
-								'show_recurring' => true,
377
-								'class'          => 'wpi_select2',
378
-							)
379
-						);
380
-
381
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
382
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
383
-						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
372
+                        wpinv_item_dropdown(
373
+                            array(
374
+                                'name'           => 'wpinv_invoice_item',
375
+                                'id'             => 'wpinv_invoice_item',
376
+                                'show_recurring' => true,
377
+                                'class'          => 'wpi_select2',
378
+                            )
379
+                        );
380
+
381
+                        echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
382
+                        echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
383
+                        echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
384 384
 
385 385
                     }
386 386
                 ?>
@@ -397,72 +397,72 @@  discard block
 block discarded – undo
397 397
             <?php foreach ( array_keys( $columns ) as $column ) : ?>
398 398
                 <td class="
399 399
 					<?php
400
-						echo esc_attr( $column );
401
-						echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
402
-					?>
400
+                        echo esc_attr( $column );
401
+                        echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
402
+                    ?>
403 403
 				">
404 404
                     <?php
405 405
                         switch ( $column ) {
406
-						case 'id':
407
-							echo (int) $item->get_id();
408
-							break;
409
-						case 'title':
410
-							printf(
411
-								'<a href="%s" target="_blank">%s</a>',
412
-								esc_url( get_edit_post_link( $item->get_id() ) ),
413
-								esc_html( $item->get_raw_name() )
414
-							);
415
-
416
-							$summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
417
-							if ( $summary !== '' ) {
418
-								printf(
419
-									'<span class="meta">%s</span>',
420
-									wp_kses_post( wpautop( $summary ) )
421
-								);
422
-							}
423
-
424
-							printf(
425
-								'<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
426
-								esc_attr( $item->get_raw_name() ),
427
-								(int) $item->get_id()
428
-							);
429
-
430
-							printf(
431
-								'<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
432
-								(int) $item->get_id(),
433
-								esc_attr( $item->get_description() )
434
-							);
435
-
436
-							break;
437
-						case 'price':
438
-							printf(
439
-								'<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
440
-								esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
441
-								(int) $item->get_id()
442
-							);
443
-
444
-							break;
445
-						case 'qty':
446
-							printf(
447
-								'<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
448
-								floatval( $item->get_quantity() ),
449
-								(int) $item->get_id()
450
-							);
451
-
452
-							break;
453
-						case 'total':
454
-							wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
455
-
456
-							break;
457
-						case 'tax':
458
-							echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
459
-
460
-							break;
461
-						case 'action':
462
-							if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
463
-								echo '<i class="fa fa-trash wpinv-item-remove"></i>';
406
+                        case 'id':
407
+                            echo (int) $item->get_id();
408
+                            break;
409
+                        case 'title':
410
+                            printf(
411
+                                '<a href="%s" target="_blank">%s</a>',
412
+                                esc_url( get_edit_post_link( $item->get_id() ) ),
413
+                                esc_html( $item->get_raw_name() )
414
+                            );
415
+
416
+                            $summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
417
+                            if ( $summary !== '' ) {
418
+                                printf(
419
+                                    '<span class="meta">%s</span>',
420
+                                    wp_kses_post( wpautop( $summary ) )
421
+                                );
422
+                            }
423
+
424
+                            printf(
425
+                                '<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
426
+                                esc_attr( $item->get_raw_name() ),
427
+                                (int) $item->get_id()
428
+                            );
429
+
430
+                            printf(
431
+                                '<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
432
+                                (int) $item->get_id(),
433
+                                esc_attr( $item->get_description() )
434
+                            );
435
+
436
+                            break;
437
+                        case 'price':
438
+                            printf(
439
+                                '<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
440
+                                esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
441
+                                (int) $item->get_id()
442
+                            );
443
+
444
+                            break;
445
+                        case 'qty':
446
+                            printf(
447
+                                '<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
448
+                                floatval( $item->get_quantity() ),
449
+                                (int) $item->get_id()
450
+                            );
451
+
452
+                            break;
453
+                        case 'total':
454
+                            wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
455
+
456
+                            break;
457
+                        case 'tax':
458
+                            echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
459
+
460
+                            break;
461
+                        case 'action':
462
+                            if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
463
+                                echo '<i class="fa fa-trash wpinv-item-remove"></i>';
464 464
                                 }
465
-							break;
465
+                            break;
466 466
                         }
467 467
                         do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice );
468 468
                     ?>
@@ -473,10 +473,10 @@  discard block
 block discarded – undo
473 473
     }
474 474
 
475 475
     /**
476
-	 * Output the metabox.
477
-	 *
478
-	 * @param WP_Post $post
479
-	 */
476
+     * Output the metabox.
477
+     *
478
+     * @param WP_Post $post
479
+     */
480 480
     public static function output2( $post ) {
481 481
 
482 482
         // Prepare the invoice.
Please login to merge, or discard this patch.
Spacing   +171 added lines, -171 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -16,62 +16,62 @@  discard block
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Meta_Box_Invoice_Items {
18 18
 
19
-    public static function get_columns( $invoice ) {
19
+    public static function get_columns($invoice) {
20 20
         $use_taxes = $invoice->is_taxable() && wpinv_use_taxes();
21 21
         $columns   = array(
22
-            'id'     => __( 'ID', 'invoicing' ),
23
-            'title'  => __( 'Item', 'invoicing' ),
22
+            'id'     => __('ID', 'invoicing'),
23
+            'title'  => __('Item', 'invoicing'),
24 24
             'price'  => sprintf(
25 25
                 '<span class="getpaid-hide-if-hours getpaid-hide-if-quantity">%s</span>
26 26
                 <span class="getpaid-hide-if-hours hide-if-amount">%s</span>
27 27
                 <span class="getpaid-hide-if-quantity hide-if-amount">%s</span>',
28
-                __( 'Amount', 'invoicing' ),
29
-                __( 'Price', 'invoicing' ),
30
-                __( 'Rate', 'invoicing' )
28
+                __('Amount', 'invoicing'),
29
+                __('Price', 'invoicing'),
30
+                __('Rate', 'invoicing')
31 31
             ),
32 32
             'qty'    => sprintf(
33 33
                 '<span class="getpaid-hide-if-hours">%s</span><span class="getpaid-hide-if-quantity">%s</span>',
34
-                __( 'Quantity', 'invoicing' ),
35
-                __( 'Hours', 'invoicing' )
34
+                __('Quantity', 'invoicing'),
35
+                __('Hours', 'invoicing')
36 36
             ),
37
-            'total'  => __( 'Total', 'invoicing' ),
37
+            'total'  => __('Total', 'invoicing'),
38 38
             'tax'    => $invoice->get_item_tax_name(),
39 39
             'action' => '',
40 40
         );
41 41
 
42
-        if ( ! $use_taxes ) {
43
-            unset( $columns['tax'] );
42
+        if (!$use_taxes) {
43
+            unset($columns['tax']);
44 44
         }
45 45
 
46 46
         return $columns;
47 47
     }
48 48
 
49
-    public static function output( $post, $invoice = false ) {
49
+    public static function output($post, $invoice = false) {
50 50
 
51
-        if ( apply_filters( 'getpaid_use_new_invoice_items_metabox', false ) ) {
52
-            return self::output2( $post );
51
+        if (apply_filters('getpaid_use_new_invoice_items_metabox', false)) {
52
+            return self::output2($post);
53 53
         }
54 54
 
55
-        $post_id    = ! empty( $post->ID ) ? $post->ID : 0;
56
-        $invoice    = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice( $post_id );
55
+        $post_id    = !empty($post->ID) ? $post->ID : 0;
56
+        $invoice    = $invoice instanceof WPInv_Invoice ? $invoice : new WPInv_Invoice($post_id);
57 57
         $use_taxes  = $invoice->is_taxable() && wpinv_use_taxes();
58
-        $item_types = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
59
-        $columns    = self::get_columns( $invoice );
60
-        $cols       = count( $columns );
58
+        $item_types = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
59
+        $columns    = self::get_columns($invoice);
60
+        $cols       = count($columns);
61 61
         $class      = '';
62 62
 
63
-        unset( $item_types['adv'] );
64
-        unset( $item_types['package'] );
63
+        unset($item_types['adv']);
64
+        unset($item_types['package']);
65 65
 
66
-        if ( $invoice->is_paid() ) {
66
+        if ($invoice->is_paid()) {
67 67
             $class .= ' wpinv-paid';
68 68
         }
69 69
 
70
-        if ( $invoice->is_refunded() ) {
70
+        if ($invoice->is_refunded()) {
71 71
             $class .= ' wpinv-refunded';
72 72
         }
73 73
 
74
-        if ( $invoice->is_recurring() ) {
74
+        if ($invoice->is_recurring()) {
75 75
             $class .= ' wpi-recurring';
76 76
         }
77 77
 
@@ -87,26 +87,26 @@  discard block
 block discarded – undo
87 87
 		);
88 88
     ?>
89 89
 
90
-        <div class="wpinv-items-wrap<?php echo esc_attr( $class ); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr( $invoice->get_status() ); ?>">
90
+        <div class="wpinv-items-wrap<?php echo esc_attr($class); ?>" id="wpinv_items_wrap" data-status="<?php echo esc_attr($invoice->get_status()); ?>">
91 91
             <table id="wpinv_items" class="wpinv-items" cellspacing="0" cellpadding="0">
92 92
 
93 93
                 <thead>
94 94
                     <tr>
95
-                        <?php foreach ( $columns as $key => $label ) : ?>
95
+                        <?php foreach ($columns as $key => $label) : ?>
96 96
                             <th class="
97 97
                             <?php
98
-                            echo esc_attr( $key );
98
+                            echo esc_attr($key);
99 99
 							echo 'total' == $key || 'qty' == $key ? ' hide-if-amount' : '';
100 100
 							?>
101
-							"><?php echo wp_kses_post( $label ); ?></th>
101
+							"><?php echo wp_kses_post($label); ?></th>
102 102
                         <?php endforeach; ?>
103 103
                     </tr>
104 104
                 </thead>
105 105
 
106 106
                 <tbody class="wpinv-line-items">
107 107
                     <?php
108
-                        foreach ( $invoice->get_items() as $int => $item ) {
109
-						self::output_row( $columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd' );
108
+                        foreach ($invoice->get_items() as $int => $item) {
109
+						self::output_row($columns, $item, $invoice, $int % 2 == 0 ? 'even' : 'odd');
110 110
                         }
111 111
                     ?>
112 112
                 </tbody>
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                                             <div class="wp-clearfix">
124 124
                                                 <label class="wpi-item-name">
125 125
                                                     <span class="input-text-wrap">
126
-                                                        <input type="text" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]">
126
+                                                        <input type="text" style="width: 100%" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="wpinv-quick-item-name" name="_wpinv_quick[name]">
127 127
                                                     </span>
128 128
                                                 </label>
129 129
                                             </div>
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
                                             <div class="wp-clearfix">
132 132
                                                 <label class="wpi-item-price">
133 133
                                                     <span class="input-text-wrap">
134
-                                                    <input type="text" style="width: 200px" placeholder="<?php esc_attr_e( 'Item Price', 'invoicing' ); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]">
135
-                                                        &times; <input type="text" style="width: 140px" placeholder="<?php esc_attr_e( 'Item Quantity', 'invoicing' ); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]">
134
+                                                    <input type="text" style="width: 200px" placeholder="<?php esc_attr_e('Item Price', 'invoicing'); ?>" class="wpinv-quick-item-price" name="_wpinv_quick[price]">
135
+                                                        &times; <input type="text" style="width: 140px" placeholder="<?php esc_attr_e('Item Quantity', 'invoicing'); ?>" class="wpinv-quick-item-qty" name="_wpinv_quick[qty]">
136 136
                                                     </span>
137 137
                                                 </label>
138 138
                                             </div>
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                                             <div class="wp-clearfix">
141 141
                                                 <label class="wpi-item-name">
142 142
                                                     <span class="input-text-wrap">
143
-                                                        <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e( 'Item Description', 'invoicing' ); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea>
143
+                                                        <textarea rows="4" style="width: 100%" placeholder="<?php esc_attr_e('Item Description', 'invoicing'); ?>" class="wpinv-quick-item-description" name="_wpinv_quick[description]"></textarea>
144 144
                                                     </span>
145 145
                                                 </label>
146 146
                                             </div>
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                                                 </label>
166 166
                                             </div>
167 167
 
168
-                                            <?php if ( $use_taxes ) : ?>
168
+                                            <?php if ($use_taxes) : ?>
169 169
                                                 <div class="wp-clearfix">
170 170
                                                     <label class="wpi-vat-rule">
171 171
                                                         <span class="input-text-wrap">
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
                                                                 wpinv_html_select(
174 174
                                                                     array(
175 175
 																		'options'          => array_merge(
176
-																			array( '' => __( 'Select VAT Rule', 'invoicing' ) ),
176
+																			array('' => __('Select VAT Rule', 'invoicing')),
177 177
 																			getpaid_get_tax_rules()
178 178
 																		),
179 179
 																		'name'             => '_wpinv_quick[vat_rule]',
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
                                                                 wpinv_html_select(
196 196
                                                                     array(
197 197
 																		'options'          => array_merge(
198
-																			array( '' => __( 'Select VAT Class', 'invoicing' ) ),
198
+																			array('' => __('Select VAT Class', 'invoicing')),
199 199
 																			getpaid_get_tax_classes()
200 200
 																		),
201 201
 																		'name'             => '_wpinv_quick[vat_class]',
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                                                             'type'    => 'checkbox',
220 220
                                                             'name'    => '_wpinv_quick[one-time]',
221 221
                                                             'id'      => '_wpinv_quick-one-time',
222
-                                                            'label'   => __( "One time item (won't be saved to regular items list)", 'invoicing' ),
222
+                                                            'label'   => __("One time item (won't be saved to regular items list)", 'invoicing'),
223 223
                                                             'value'   => 1,
224 224
                                                             'no_wrap' => true,
225 225
                                                             'checked' => false,
@@ -243,39 +243,39 @@  discard block
 block discarded – undo
243 243
                         </td>
244 244
                     </tr>
245 245
                     <tr class="totals">
246
-                        <td colspan="<?php echo ( (int) $cols - 4 ); ?>"></td>
246
+                        <td colspan="<?php echo ((int) $cols - 4); ?>"></td>
247 247
                         <td colspan="4">
248 248
                             <table cellspacing="0" cellpadding="0">
249 249
                                 <tr class="subtotal">
250
-                                    <td class="name"><?php esc_html_e( 'Sub Total:', 'invoicing' ); ?></td>
251
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() ); ?></td>
250
+                                    <td class="name"><?php esc_html_e('Sub Total:', 'invoicing'); ?></td>
251
+                                    <td class="total"><?php wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency()); ?></td>
252 252
                                     <td class="action"></td>
253 253
                                 </tr>
254 254
                                 <tr class="discount">
255
-                                    <td class="name"><?php esc_html_e( 'Discount:', 'invoicing' ); ?></td>
256
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() ); ?></td>
255
+                                    <td class="name"><?php esc_html_e('Discount:', 'invoicing'); ?></td>
256
+                                    <td class="total"><?php wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency()); ?></td>
257 257
                                     <td class="action"></td>
258 258
                                 </tr>
259
-                                <?php if ( $use_taxes ) : ?>
260
-                                <?php if ( is_array( $taxes = $invoice->get_taxes() ) && wpinv_display_individual_tax_rates() ) { ?>
261
-                                <?php foreach ( $taxes as $tax_key => $tax_item ) { ?>
259
+                                <?php if ($use_taxes) : ?>
260
+                                <?php if (is_array($taxes = $invoice->get_taxes()) && wpinv_display_individual_tax_rates()) { ?>
261
+                                <?php foreach ($taxes as $tax_key => $tax_item) { ?>
262 262
                                 <tr class="tax">
263
-                                    <td class="name"><?php echo esc_html( $invoice->get_tax_item_name( $tax_key, $tax_item, ':' ) ); ?></td>
264
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_tax_item_amount( $tax_key, $tax_item ), $invoice->get_currency() ); ?></td>
263
+                                    <td class="name"><?php echo esc_html($invoice->get_tax_item_name($tax_key, $tax_item, ':')); ?></td>
264
+                                    <td class="total"><?php wpinv_the_price($invoice->get_tax_item_amount($tax_key, $tax_item), $invoice->get_currency()); ?></td>
265 265
                                     <td class="action"></td>
266 266
                                 </tr>
267 267
                                 <?php } ?>
268 268
                                 <?php } else { ?>
269 269
                                 <tr class="tax">
270
-                                    <td class="name"><?php esc_html_e( 'Tax:', 'invoicing' ); ?></td>
271
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() ); ?></td>
270
+                                    <td class="name"><?php esc_html_e('Tax:', 'invoicing'); ?></td>
271
+                                    <td class="total"><?php wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency()); ?></td>
272 272
                                     <td class="action"></td>
273 273
                                 </tr>
274 274
                                 <?php } ?>
275 275
                                 <?php endif; ?>
276 276
                                 <tr class="total">
277
-                                    <td class="name"><?php esc_html_e( 'Total:', 'invoicing' ); ?></td>
278
-                                    <td class="total"><?php wpinv_the_price( $invoice->get_total(), $invoice->get_currency() ); ?></td>
277
+                                    <td class="name"><?php esc_html_e('Total:', 'invoicing'); ?></td>
278
+                                    <td class="total"><?php wpinv_the_price($invoice->get_total(), $invoice->get_currency()); ?></td>
279 279
                                     <td class="action"></td>
280 280
                                 </tr>
281 281
                             </table>
@@ -291,18 +291,18 @@  discard block
 block discarded – undo
291 291
                      <div class="modal-dialog modal-dialog-centered" role="document">
292 292
                         <div class="modal-content">
293 293
                             <div class="modal-header">
294
-                                <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e( 'Refund Payment', 'invoicing' ); ?></h5>
295
-                                <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
296
-                                    <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
294
+                                <h5 class="modal-title" id="getpaid-refund-invoice-modal-label"><?php esc_html_e('Refund Payment', 'invoicing'); ?></h5>
295
+                                <button type="button" class="close btn-close" data-bs-dismiss="modal" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
296
+                                    <?php if (empty($GLOBALS['aui_bs5'])) : ?>
297 297
                                         <span aria-hidden="true">×</span>
298 298
                                     <?php endif; ?>
299 299
                                 </button>
300 300
                             </div>
301 301
                             <div class="modal-body">
302 302
 								<p>
303
-									<?php esc_html_e( 'Are you sure you want to refund this payment?', 'invoicing' ); ?>
303
+									<?php esc_html_e('Are you sure you want to refund this payment?', 'invoicing'); ?>
304 304
 								</p>
305
-								<?php if ( getpaid_payment_gateway_supports( $invoice->get_gateway(), 'refunds' ) ) : ?>
305
+								<?php if (getpaid_payment_gateway_supports($invoice->get_gateway(), 'refunds')) : ?>
306 306
 									<?php
307 307
 										aui()->input(
308 308
 											array(
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
 												'id'    => 'getpaid_refund_remote',
312 312
 												'label' => sprintf(
313 313
 													'Refund payment in %s',
314
-													wpinv_get_gateway_admin_label( $invoice->get_gateway() )
314
+													wpinv_get_gateway_admin_label($invoice->get_gateway())
315 315
 												),
316 316
 												'value' => 1,
317 317
 												'class' => 'getpaid-refund-field',
@@ -321,14 +321,14 @@  discard block
 block discarded – undo
321 321
 									?>
322 322
 								<?php endif; ?>
323 323
 
324
-								<?php if ( getpaid_get_invoice_subscriptions( $invoice ) ) : ?>
324
+								<?php if (getpaid_get_invoice_subscriptions($invoice)) : ?>
325 325
 									<?php
326 326
 										aui()->input(
327 327
 											array(
328 328
 												'type'  => 'checkbox',
329 329
 												'name'  => 'getpaid_cancel_subscription',
330 330
 												'id'    => 'getpaid_cancel_subscription',
331
-												'label' => __( 'Cancel subscription', 'invoicing' ),
331
+												'label' => __('Cancel subscription', 'invoicing'),
332 332
 												'value' => 1,
333 333
 												'class' => 'getpaid-refund-field',
334 334
 											),
@@ -338,12 +338,12 @@  discard block
 block discarded – undo
338 338
 								<?php endif; ?>
339 339
                             </div>
340 340
                             <div class="modal-footer">
341
-                                <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
341
+                                <button type="button" class="btn btn-secondary getpaid-cancel" data-bs-dismiss="modal" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
342 342
                                 <a
343
-									href="<?php echo esc_url_raw( $refund_url ); ?>"
344
-									data-href="<?php echo esc_url_raw( $refund_url ); ?>"
343
+									href="<?php echo esc_url_raw($refund_url); ?>"
344
+									data-href="<?php echo esc_url_raw($refund_url); ?>"
345 345
 									class="btn btn-primary getpaid-refund-payment-button"
346
-								><?php esc_html_e( 'Refund', 'invoicing' ); ?></a>
346
+								><?php esc_html_e('Refund', 'invoicing'); ?></a>
347 347
 								<script>
348 348
 									// Update the refund URL when the user changes the refund options.
349 349
 									jQuery( function( $ ) {
@@ -369,13 +369,13 @@  discard block
 block discarded – undo
369 369
 
370 370
             <div class="wpinv-actions">
371 371
                 <?php
372
-                    if ( $invoice->is_paid() ) {
372
+                    if ($invoice->is_paid()) {
373 373
 
374 374
 						printf(
375 375
 							'<span class="bsui"><button type="button" class="button button-primary" data-toggle="modal" data-bs-toggle="modal" data-bs-target="#getpaid-refund-invoice-modal" data-target="#getpaid-refund-invoice-modal">%s</button></span>',
376
-							esc_html__( 'Refund', 'invoicing' )
376
+							esc_html__('Refund', 'invoicing')
377 377
 						);
378
-                    } elseif ( ! $invoice->is_refunded() ) {
378
+                    } elseif (!$invoice->is_refunded()) {
379 379
 						wpinv_item_dropdown(
380 380
 							array(
381 381
 								'name'           => 'wpinv_invoice_item',
@@ -385,66 +385,66 @@  discard block
 block discarded – undo
385 385
 							)
386 386
 						);
387 387
 
388
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf( esc_html__( 'Add item to %s', 'invoicing' ), esc_html( $invoice->get_label() ) ) . '</button>';
389
-						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__( 'Create new item', 'invoicing' ) . '</button>';
390
-						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__( 'Recalculate Totals', 'invoicing' ) . '</button>';
388
+						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-add-item">' . sprintf(esc_html__('Add item to %s', 'invoicing'), esc_html($invoice->get_label())) . '</button>';
389
+						echo '&nbsp;' . '<button type="button" class="button button-primary" id="wpinv-new-item">' . esc_html__('Create new item', 'invoicing') . '</button>';
390
+						echo '&nbsp;' . '<button type="button" class="button button-primary wpinv-flr" id="wpinv-recalc-totals">' . esc_html__('Recalculate Totals', 'invoicing') . '</button>';
391 391
 
392 392
                     }
393 393
                 ?>
394
-                <?php do_action( 'wpinv_invoice_items_actions', $invoice ); ?>
394
+                <?php do_action('wpinv_invoice_items_actions', $invoice); ?>
395 395
             </div>
396 396
         </div>
397 397
         <?php
398 398
     }
399 399
 
400
-    public static function output_row( $columns, $item, $invoice, $class = 'even' ) {
400
+    public static function output_row($columns, $item, $invoice, $class = 'even') {
401 401
 
402 402
     ?>
403
-        <tr class="item item-<?php echo esc_attr( $class ); ?>" data-item-id="<?php echo esc_attr( $item->get_id() ); ?>">
404
-            <?php foreach ( array_keys( $columns ) as $column ) : ?>
403
+        <tr class="item item-<?php echo esc_attr($class); ?>" data-item-id="<?php echo esc_attr($item->get_id()); ?>">
404
+            <?php foreach (array_keys($columns) as $column) : ?>
405 405
                 <td class="
406 406
 					<?php
407
-						echo esc_attr( $column );
407
+						echo esc_attr($column);
408 408
 						echo 'total' == $column || 'qty' == $column ? ' hide-if-amount' : '';
409 409
 					?>
410 410
 				">
411 411
                     <?php
412
-                        switch ( $column ) {
412
+                        switch ($column) {
413 413
 						case 'id':
414 414
 							echo (int) $item->get_id();
415 415
 							break;
416 416
 						case 'title':
417 417
 							printf(
418 418
 								'<a href="%s" target="_blank">%s</a>',
419
-								esc_url( get_edit_post_link( $item->get_id() ) ),
420
-								esc_html( $item->get_raw_name() )
419
+								esc_url(get_edit_post_link($item->get_id())),
420
+								esc_html($item->get_raw_name())
421 421
 							);
422 422
 
423
-							$summary = apply_filters( 'getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice );
424
-							if ( $summary !== '' ) {
423
+							$summary = apply_filters('getpaid_admin_invoice_line_item_summary', $item->get_description(), $item, $invoice);
424
+							if ($summary !== '') {
425 425
 								printf(
426 426
 									'<span class="meta">%s</span>',
427
-									wp_kses_post( wpautop( $summary ) )
427
+									wp_kses_post(wpautop($summary))
428 428
 								);
429 429
 							}
430 430
 
431 431
 							printf(
432 432
 								'<input type="hidden" value="%s" name="getpaid_items[%s][name]" class="getpaid-recalculate-prices-on-change" />',
433
-								esc_attr( $item->get_raw_name() ),
433
+								esc_attr($item->get_raw_name()),
434 434
 								(int) $item->get_id()
435 435
 							);
436 436
 
437 437
 							printf(
438 438
 								'<textarea style="display: none;" name="getpaid_items[%s][description]" class="getpaid-recalculate-prices-on-change">%s</textarea>',
439 439
 								(int) $item->get_id(),
440
-								esc_attr( $item->get_description() )
440
+								esc_attr($item->get_description())
441 441
 							);
442 442
 
443 443
 							break;
444 444
 						case 'price':
445 445
 							printf(
446 446
 								'<input type="text" value="%s" name="getpaid_items[%s][price]" style="width: 100px;" class="getpaid-admin-invoice-item-price getpaid-recalculate-prices-on-change" />',
447
-								esc_attr( getpaid_unstandardize_amount( $item->get_price() ) ),
447
+								esc_attr(getpaid_unstandardize_amount($item->get_price())),
448 448
 								(int) $item->get_id()
449 449
 							);
450 450
 
@@ -452,26 +452,26 @@  discard block
 block discarded – undo
452 452
 						case 'qty':
453 453
 							printf(
454 454
 								'<input type="text" style="width: 100px;" value="%s" name="getpaid_items[%s][quantity]" class="getpaid-admin-invoice-item-quantity getpaid-recalculate-prices-on-change" />',
455
-								floatval( $item->get_quantity() ),
455
+								floatval($item->get_quantity()),
456 456
 								(int) $item->get_id()
457 457
 							);
458 458
 
459 459
 							break;
460 460
 						case 'total':
461
-							wpinv_the_price( $item->get_sub_total(), $invoice->get_currency() );
461
+							wpinv_the_price($item->get_sub_total(), $invoice->get_currency());
462 462
 
463 463
 							break;
464 464
 						case 'tax':
465
-							echo floatval( wpinv_round_amount( getpaid_get_invoice_tax_rate( $invoice, $item ), 2 ) ) . '%';
465
+							echo floatval(wpinv_round_amount(getpaid_get_invoice_tax_rate($invoice, $item), 2)) . '%';
466 466
 
467 467
 							break;
468 468
 						case 'action':
469
-							if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
469
+							if (!$invoice->is_paid() && !$invoice->is_refunded()) {
470 470
 								echo '<i class="fa fa-trash wpinv-item-remove"></i>';
471 471
                                 }
472 472
 							break;
473 473
                         }
474
-                        do_action( 'getpaid_admin_edit_invoice_item_' . $column, $item, $invoice );
474
+                        do_action('getpaid_admin_edit_invoice_item_' . $column, $item, $invoice);
475 475
                     ?>
476 476
                 </td>
477 477
             <?php endforeach; ?>
@@ -484,10 +484,10 @@  discard block
 block discarded – undo
484 484
 	 *
485 485
 	 * @param WP_Post $post
486 486
 	 */
487
-    public static function output2( $post ) {
487
+    public static function output2($post) {
488 488
 
489 489
         // Prepare the invoice.
490
-        $invoice = new WPInv_Invoice( $post );
490
+        $invoice = new WPInv_Invoice($post);
491 491
 
492 492
         // Invoice items.
493 493
         $items = $invoice->get_items();
@@ -495,28 +495,28 @@  discard block
 block discarded – undo
495 495
         $totals = array(
496 496
 
497 497
             'subtotal' => array(
498
-                'label' => __( 'Items Subtotal', 'invoicing' ),
499
-                'value' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
498
+                'label' => __('Items Subtotal', 'invoicing'),
499
+                'value' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
500 500
             ),
501 501
 
502 502
             'discount' => array(
503
-                'label' => __( 'Total Discount', 'invoicing' ),
504
-                'value' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
503
+                'label' => __('Total Discount', 'invoicing'),
504
+                'value' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
505 505
             ),
506 506
 
507 507
             'tax'      => array(
508
-                'label' => __( 'Total Tax', 'invoicing' ),
509
-                'value' => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
508
+                'label' => __('Total Tax', 'invoicing'),
509
+                'value' => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
510 510
             ),
511 511
 
512 512
             'total'    => array(
513
-                'label' => __( 'Invoice Total', 'invoicing' ),
514
-                'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
513
+                'label' => __('Invoice Total', 'invoicing'),
514
+                'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
515 515
             ),
516 516
         );
517 517
 
518
-        if ( ! wpinv_use_taxes() ) {
519
-            unset( $totals['tax'] );
518
+        if (!wpinv_use_taxes()) {
519
+            unset($totals['tax']);
520 520
         }
521 521
 
522 522
         $item_args = array(
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
             'orderby'        => 'title',
525 525
             'order'          => 'ASC',
526 526
             'posts_per_page' => -1,
527
-            'post_status'    => array( 'publish' ),
527
+            'post_status'    => array('publish'),
528 528
             'meta_query'     => array(
529 529
                 array(
530 530
                     'key'     => '_wpinv_type',
@@ -552,10 +552,10 @@  discard block
 block discarded – undo
552 552
             }
553 553
         </style>
554 554
 
555
-                <div class="bsui getpaid-invoice-items-inner <?php echo empty( $items ) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;">
555
+                <div class="bsui getpaid-invoice-items-inner <?php echo empty($items) ? 'no-items' : 'has-items'; ?> <?php echo $invoice->is_paid() || $invoice->is_refunded() ? 'not-editable' : 'editable'; ?>" style="margin-top: 1.5rem; padding: 0 12px 12px;">
556 556
 
557
-                    <?php if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) : ?>
558
-                        <?php do_action( 'wpinv_meta_box_before_invoice_template_row', $invoice->get_id() ); ?>
557
+                    <?php if (!$invoice->is_paid() && !$invoice->is_refunded()) : ?>
558
+                        <?php do_action('wpinv_meta_box_before_invoice_template_row', $invoice->get_id()); ?>
559 559
 
560 560
                         <div class="row">
561 561
                             <div class="col-12 col-sm-6">
@@ -564,15 +564,15 @@  discard block
 block discarded – undo
564 564
                                         array(
565 565
                                             'id'          => 'wpinv_template',
566 566
                                             'name'        => 'wpinv_template',
567
-                                            'label'       => __( 'Template', 'invoicing' ),
567
+                                            'label'       => __('Template', 'invoicing'),
568 568
                                             'label_type'  => 'vertical',
569
-                                            'placeholder' => __( 'Choose a template', 'invoicing' ),
569
+                                            'placeholder' => __('Choose a template', 'invoicing'),
570 570
                                             'class'       => 'form-control-sm',
571
-                                            'value'       => $invoice->get_template( 'edit' ),
571
+                                            'value'       => $invoice->get_template('edit'),
572 572
                                             'options'     => array(
573
-                                                'quantity' => __( 'Quantity', 'invoicing' ),
574
-                                                'hours'    => __( 'Hours', 'invoicing' ),
575
-                                                'amount'   => __( 'Amount Only', 'invoicing' ),
573
+                                                'quantity' => __('Quantity', 'invoicing'),
574
+                                                'hours'    => __('Hours', 'invoicing'),
575
+                                                'amount'   => __('Amount Only', 'invoicing'),
576 576
                                             ),
577 577
                                             'data-allow-clear' => 'false',
578 578
                                             'select2'     => true,
@@ -589,11 +589,11 @@  discard block
 block discarded – undo
589 589
                                         array(
590 590
                                             'id'          => 'wpinv_currency',
591 591
                                             'name'        => 'wpinv_currency',
592
-                                            'label'       => __( 'Currency', 'invoicing' ),
592
+                                            'label'       => __('Currency', 'invoicing'),
593 593
                                             'label_type'  => 'vertical',
594
-                                            'placeholder' => __( 'Select Invoice Currency', 'invoicing' ),
594
+                                            'placeholder' => __('Select Invoice Currency', 'invoicing'),
595 595
                                             'class'       => 'form-control-sm',
596
-                                            'value'       => $invoice->get_currency( 'edit' ),
596
+                                            'value'       => $invoice->get_currency('edit'),
597 597
                                             'required'    => false,
598 598
                                             'data-allow-clear' => 'false',
599 599
                                             'select2'     => true,
@@ -606,24 +606,24 @@  discard block
 block discarded – undo
606 606
                             </div>
607 607
                         </div>
608 608
 
609
-                        <?php do_action( 'wpinv_meta_box_invoice_template_row', $invoice->get_id() ); ?>
609
+                        <?php do_action('wpinv_meta_box_invoice_template_row', $invoice->get_id()); ?>
610 610
                     <?php endif; ?>
611 611
 
612 612
                     <table cellpadding="0" cellspacing="0" class="getpaid_invoice_items">
613 613
                         <thead>
614 614
                             <tr>
615
-                                <th class="getpaid-item" colspan="2"><?php esc_html_e( 'Item', 'invoicing' ); ?></th>
615
+                                <th class="getpaid-item" colspan="2"><?php esc_html_e('Item', 'invoicing'); ?></th>
616 616
                                 <th class="getpaid-quantity hide-if-amount text-right">
617
-                                    <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
618
-                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span>
617
+                                    <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span>
618
+                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span>
619 619
                                 </th>
620 620
                                 <th class="getpaid-price hide-if-amount text-right">
621
-                                    <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Price', 'invoicing' ); ?></span>
622
-                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Rate', 'invoicing' ); ?></span>
621
+                                    <span class="getpaid-hide-if-hours"><?php esc_html_e('Price', 'invoicing'); ?></span>
622
+                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e('Rate', 'invoicing'); ?></span>
623 623
                                 </th>
624 624
                                 <th class="getpaid-item-subtotal text-right">
625
-                                    <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span>
626
-                                    <span class="hide-if-amount"><?php esc_html_e( 'Total', 'invoicing' ); ?></span>
625
+                                    <span class="getpaid-hide-if-hours getpaid-hide-if-quantity"><?php esc_html_e('Amount', 'invoicing'); ?></span>
626
+                                    <span class="hide-if-amount"><?php esc_html_e('Total', 'invoicing'); ?></span>
627 627
                                 </th>
628 628
                                 <th class="getpaid-item-actions hide-if-not-editable" width="70px">&nbsp;</th>
629 629
                             </tr>
@@ -631,8 +631,8 @@  discard block
 block discarded – undo
631 631
 		                <tbody class="getpaid_invoice_line_items">
632 632
                             <tr class="hide-if-has-items hide-if-not-editable">
633 633
                                 <td colspan="2" class="pt-4 pb-4">
634
-                                    <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Items', 'invoicing' ); ?></button>
635
-                                    <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button>
634
+                                    <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Items', 'invoicing'); ?></button>
635
+                                    <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button>
636 636
                                 </td>
637 637
                                 <td class="hide-if-amount">&nbsp;</th>
638 638
                                 <td class="hide-if-amount">&nbsp;</th>
@@ -664,11 +664,11 @@  discard block
 block discarded – undo
664 664
                             <div class="col-12 col-sm-6 offset-sm-6">
665 665
                                 <table class="getpaid-invoice-totals text-right w-100">
666 666
                                     <tbody>
667
-                                        <?php foreach ( apply_filters( 'getpaid_invoice_subtotal_rows', $totals, $invoice ) as $key => $data ) : ?>
668
-                                            <tr class="getpaid-totals-<?php echo esc_attr( $key ); ?>">
669
-                                                <td class="label"><?php echo esc_html( $data['label'] ); ?>:</td>
667
+                                        <?php foreach (apply_filters('getpaid_invoice_subtotal_rows', $totals, $invoice) as $key => $data) : ?>
668
+                                            <tr class="getpaid-totals-<?php echo esc_attr($key); ?>">
669
+                                                <td class="label"><?php echo esc_html($data['label']); ?>:</td>
670 670
                                                 <td width="1%"></td>
671
-                                                <td class="value"><?php echo wp_kses_post( $data['value'] ); ?></td>
671
+                                                <td class="value"><?php echo wp_kses_post($data['value']); ?></td>
672 672
                                             </tr>
673 673
                                         <?php endforeach; ?>
674 674
                                     </tbody>
@@ -681,18 +681,18 @@  discard block
 block discarded – undo
681 681
                     <div class="getpaid-invoice-item-actions hide-if-no-items hide-if-not-editable">
682 682
                         <div class="row">
683 683
                             <div class="text-left col-12 col-sm-8">
684
-                                <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e( 'Add Existing Item', 'invoicing' ); ?></button>
685
-                                <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e( 'Create New Item', 'invoicing' ); ?></button>
686
-                                <?php do_action( 'getpaid-invoice-items-actions', $invoice ); ?>
684
+                                <button type="button" class="button button-primary add-invoice-item" data-toggle="modal" data-target="#getpaid-add-items-to-invoice"><?php esc_html_e('Add Existing Item', 'invoicing'); ?></button>
685
+                                <button type="button" class="button button-secondary create-invoice-item" data-toggle="modal" data-target="#getpaid-create-invoice-item"><?php esc_html_e('Create New Item', 'invoicing'); ?></button>
686
+                                <?php do_action('getpaid-invoice-items-actions', $invoice); ?>
687 687
                             </div>
688 688
                             <div class="text-right col-12 col-sm-4">
689
-                                <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e( 'Recalculate Totals', 'invoicing' ); ?></button>
689
+                                <button type="button" class="button button-primary recalculate-totals-button"><?php esc_html_e('Recalculate Totals', 'invoicing'); ?></button>
690 690
                             </div>
691 691
                         </div>
692 692
                     </div>
693 693
 
694 694
                     <div class="getpaid-invoice-item-actions hide-if-editable">
695
-                        <p class="description m-2 text-right text-muted"><?php esc_html_e( 'This invoice is no longer editable', 'invoicing' ); ?></p>
695
+                        <p class="description m-2 text-right text-muted"><?php esc_html_e('This invoice is no longer editable', 'invoicing'); ?></p>
696 696
                     </div>
697 697
 
698 698
                     <!-- Add items to an invoice -->
@@ -700,9 +700,9 @@  discard block
 block discarded – undo
700 700
                         <div class="modal-dialog modal-dialog-centered" role="document">
701 701
                             <div class="modal-content">
702 702
                                 <div class="modal-header">
703
-                                    <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e( 'Add Item(s)', 'invoicing' ); ?></h5>
704
-                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
705
-                                        <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
703
+                                    <h5 class="modal-title" id="getpaid-add-item-to-invoice-label"><?php esc_html_e('Add Item(s)', 'invoicing'); ?></h5>
704
+                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
705
+                                        <?php if (empty($GLOBALS['aui_bs5'])) : ?>
706 706
                                             <span aria-hidden="true">×</span>
707 707
                                         <?php endif; ?>
708 708
                                     </button>
@@ -711,10 +711,10 @@  discard block
 block discarded – undo
711 711
                                     <table class="widefat">
712 712
                                         <thead>
713 713
                                             <tr>
714
-                                                <th class="pl-0 text-left"><?php esc_html_e( 'Item', 'invoicing' ); ?></th>
714
+                                                <th class="pl-0 text-left"><?php esc_html_e('Item', 'invoicing'); ?></th>
715 715
                                                 <th class="pr-0 text-right hide-if-amount">
716
-                                                    <span class="getpaid-hide-if-hours"><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
717
-                                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e( 'Hours', 'invoicing' ); ?></span>
716
+                                                    <span class="getpaid-hide-if-hours"><?php esc_html_e('Quantity', 'invoicing'); ?></span>
717
+                                                    <span class="getpaid-hide-if-quantity"><?php esc_html_e('Hours', 'invoicing'); ?></span>
718 718
                                                 </th>
719 719
                                             </tr>
720 720
                                         </thead>
@@ -722,9 +722,9 @@  discard block
 block discarded – undo
722 722
 								            <tr>
723 723
 									            <td class="pl-0 text-left">
724 724
                                                     <select class="regular-text getpaid-add-invoice-item-select">
725
-                                                        <option value="" selected="selected" disabled><?php esc_html_e( 'Select an item…', 'invoicing' ); ?></option>
726
-                                                        <?php foreach ( get_posts( $item_args ) as $item ) : ?>
727
-                                                        <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html( $item->post_title ); ?></option>
725
+                                                        <option value="" selected="selected" disabled><?php esc_html_e('Select an item…', 'invoicing'); ?></option>
726
+                                                        <?php foreach (get_posts($item_args) as $item) : ?>
727
+                                                        <option value="<?php echo (int) $item->ID; ?>"><?php echo esc_html($item->post_title); ?></option>
728 728
                                                         <?php endforeach; ?>
729 729
                                                     </select>
730 730
                                                 </td>
@@ -736,8 +736,8 @@  discard block
 block discarded – undo
736 736
 						            </table>
737 737
                                 </div>
738 738
                                 <div class="modal-footer">
739
-                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
740
-                                    <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e( 'Add', 'invoicing' ); ?></button>
739
+                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
740
+                                    <button type="button" class="btn btn-primary getpaid-add" data-dismiss="modal"><?php esc_html_e('Add', 'invoicing'); ?></button>
741 741
                                 </div>
742 742
                             </div>
743 743
                         </div>
@@ -748,9 +748,9 @@  discard block
 block discarded – undo
748 748
                         <div class="modal-dialog modal-dialog-centered" role="document">
749 749
                             <div class="modal-content">
750 750
                                 <div class="modal-header">
751
-                                    <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e( 'Create Item', 'invoicing' ); ?></h5>
752
-                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
753
-                                        <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
751
+                                    <h5 class="modal-title" id="getpaid-create-invoice-item-label"><?php esc_html_e('Create Item', 'invoicing'); ?></h5>
752
+                                    <button type="button" class="close btn-close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
753
+                                        <?php if (empty($GLOBALS['aui_bs5'])) : ?>
754 754
                                             <span aria-hidden="true">×</span>
755 755
                                         <?php endif; ?>
756 756
                                     </button>
@@ -759,27 +759,27 @@  discard block
 block discarded – undo
759 759
                                     <div class="getpaid-create-item-div">
760 760
                                         <input type="hidden" name="id" value="new" class="form-control form-control-sm item-id">
761 761
                                         <label class="form-group mb-3 w-100">
762
-                                            <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span>
763
-                                            <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name">
762
+                                            <span><?php esc_html_e('Name', 'invoicing'); ?></span>
763
+                                            <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name">
764 764
                                         </label>
765 765
                                         <label class="form-group mb-3 w-100">
766
-                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span>
767
-                                            <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span>
768
-                                            <input type="text" name="price" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control form-control-sm item-price">
766
+                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span>
767
+                                            <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span>
768
+                                            <input type="text" name="price" placeholder="<?php echo esc_attr(wpinv_sanitize_amount(0)); ?>" class="form-control form-control-sm item-price">
769 769
                                         </label>
770 770
                                         <label class="form-group mb-3 w-100 hide-if-amount">
771
-                                            <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
771
+                                            <span><?php esc_html_e('Quantity', 'invoicing'); ?></span>
772 772
                                             <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity">
773 773
                                         </label>
774 774
                                         <label class="form-group mb-3 w-100">
775
-                                            <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span>
776
-                                            <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea>
775
+                                            <span><?php esc_html_e('Item Description', 'invoicing'); ?></span>
776
+                                            <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea>
777 777
                                         </label>
778 778
                                     </div>
779 779
                                 </div>
780 780
                                 <div class="modal-footer">
781
-                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
782
-                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Create', 'invoicing' ); ?></button>
781
+                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
782
+                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Create', 'invoicing'); ?></button>
783 783
                                 </div>
784 784
                             </div>
785 785
                         </div>
@@ -790,9 +790,9 @@  discard block
 block discarded – undo
790 790
                         <div class="modal-dialog modal-dialog-centered" role="document">
791 791
                             <div class="modal-content">
792 792
                                 <div class="modal-header">
793
-                                    <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e( 'Edit Item', 'invoicing' ); ?></h5>
794
-                                    <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e( 'Close', 'invoicing' ); ?>">
795
-                                        <?php if ( empty( $GLOBALS['aui_bs5'] ) ) : ?>
793
+                                    <h5 class="modal-title" id="getpaid-edit-invoice-item-label"><?php esc_html_e('Edit Item', 'invoicing'); ?></h5>
794
+                                    <button type="button" class="close close" data-dismiss="modal" aria-label="<?php esc_html_e('Close', 'invoicing'); ?>">
795
+                                        <?php if (empty($GLOBALS['aui_bs5'])) : ?>
796 796
                                             <span aria-hidden="true">×</span>
797 797
                                         <?php endif; ?>
798 798
                                     </button>
@@ -801,27 +801,27 @@  discard block
 block discarded – undo
801 801
                                     <div class="getpaid-edit-item-div">
802 802
                                         <input type="hidden" name="id" class="form-control form-control-sm item-id">
803 803
                                         <label class="form-group mb-3 w-100">
804
-                                            <span><?php esc_html_e( 'Name', 'invoicing' ); ?></span>
805
-                                            <input type="text" name="name" placeholder="<?php esc_attr_e( 'Item Name', 'invoicing' ); ?>" class="form-control form-control-sm item-name">
804
+                                            <span><?php esc_html_e('Name', 'invoicing'); ?></span>
805
+                                            <input type="text" name="name" placeholder="<?php esc_attr_e('Item Name', 'invoicing'); ?>" class="form-control form-control-sm item-name">
806 806
                                         </label>
807 807
                                         <label class="form-group mb-3 w-100">
808
-                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e( 'Amount', 'invoicing' ); ?></span>
809
-                                            <span class="hide-if-amount"><?php esc_html_e( 'Price', 'invoicing' ); ?></span>
810
-                                            <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount( 0 ); ?>" class="form-control form-control-sm item-price">
808
+                                            <span class="getpaid-hide-if-hours getpaid-hide-if-quantity item-price"><?php esc_html_e('Amount', 'invoicing'); ?></span>
809
+                                            <span class="hide-if-amount"><?php esc_html_e('Price', 'invoicing'); ?></span>
810
+                                            <input type="text" name="price" placeholder="<?php wpinv_sanitize_amount(0); ?>" class="form-control form-control-sm item-price">
811 811
                                         </label>
812 812
                                         <label class="form-group mb-3 w-100 hide-if-amount">
813
-                                            <span><?php esc_html_e( 'Quantity', 'invoicing' ); ?></span>
813
+                                            <span><?php esc_html_e('Quantity', 'invoicing'); ?></span>
814 814
                                             <input type="text" name="quantity" placeholder="1" class="form-control form-control-sm item-quantity">
815 815
                                         </label>
816 816
                                         <label class="form-group mb-3 w-100">
817
-                                            <span><?php esc_html_e( 'Item Description', 'invoicing' ); ?></span>
818
-                                            <textarea name="description" placeholder="<?php esc_attr_e( 'Enter a description for this item', 'invoicing' ); ?>" class="form-control item-description"></textarea>
817
+                                            <span><?php esc_html_e('Item Description', 'invoicing'); ?></span>
818
+                                            <textarea name="description" placeholder="<?php esc_attr_e('Enter a description for this item', 'invoicing'); ?>" class="form-control item-description"></textarea>
819 819
                                         </label>
820 820
                                     </div>
821 821
                                 </div>
822 822
                                 <div class="modal-footer">
823
-                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e( 'Cancel', 'invoicing' ); ?></button>
824
-                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e( 'Save', 'invoicing' ); ?></button>
823
+                                    <button type="button" class="btn btn-secondary getpaid-cancel" data-dismiss="modal"><?php esc_html_e('Cancel', 'invoicing'); ?></button>
824
+                                    <button type="button" class="btn btn-primary getpaid-save" data-dismiss="modal"><?php esc_html_e('Save', 'invoicing'); ?></button>
825 825
                                 </div>
826 826
                             </div>
827 827
                         </div>
Please login to merge, or discard this patch.
includes/class-getpaid-tax.php 2 patches
Indentation   +192 added lines, -192 removed lines patch added patch discarded remove patch
@@ -13,199 +13,199 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Tax {
15 15
 
16
-	/**
17
-	 * Calculates tax for a line item.
18
-	 *
19
-	 * @param  float   $price              The price to calc tax on.
20
-	 * @param  array   $rates              The rates to apply.
21
-	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
-	 * @return array                       Array of tax name => tax amount.
23
-	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
-
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
28
-		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
30
-		}
31
-
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
-
34
-	}
35
-
36
-	/**
37
-	 * Calc tax from inclusive price.
38
-	 *
39
-	 * @param  float $price Price to calculate tax for.
40
-	 * @param  array $rates Array of tax rates.
41
-	 * @return array
42
-	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
44
-		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
-
47
-		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
-
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
55
-		}
56
-
57
-		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
-
60
-		return $taxes;
61
-	}
62
-
63
-	/**
64
-	 * Calc tax from exclusive price.
65
-	 *
66
-	 * @param  float $price Price to calculate tax for.
67
-	 * @param  array $rates Array of tax rates.
68
-	 * @return array
69
-	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
71
-		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
-
74
-		foreach ( $tax_rates as $name => $rate ) {
75
-
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
-
79
-		}
80
-
81
-		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
-
84
-		return $taxes;
85
-	}
86
-
87
-	/**
88
-	 * Get's an array of all tax rates.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public static function get_all_tax_rates() {
93
-
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
95
-
96
-		return apply_filters(
97
-			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get's an array of default tax rates.
105
-	 *
106
-	 * @return array
107
-	 */
108
-	public static function get_default_tax_rates() {
109
-
110
-		return apply_filters(
111
-			'getpaid_get_default_tax_rates',
112
-			array(
113
-				array(
114
-					'country' => wpinv_get_default_country(),
115
-					'state'   => wpinv_get_default_state(),
116
-					'global'  => true,
117
-					'rate'    => wpinv_get_default_tax_rate(),
118
-					'name'    => __( 'Tax', 'invoicing' ),
119
-				),
120
-			)
121
-		);
122
-
123
-	}
124
-
125
-	/**
126
-	 * Get's an array of all tax rules.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public static function get_all_tax_rules() {
131
-
132
-		$rules = get_option(
133
-			'wpinv_tax_rules',
134
-			array(
135
-				array(
136
-					'key'               => 'physical',
137
-					'label'             => __( 'Physical Item', 'invoicing' ),
138
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
139
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
140
-				),
141
-				array(
142
-					'key'               => 'digital',
143
-					'label'             => __( 'Digital Item', 'invoicing' ),
144
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
145
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
146
-				),
147
-        	)
148
-		);
149
-
150
-		return apply_filters(
151
-			'getpaid_tax_rules',
152
-			array_filter( array_values( wpinv_parse_list( $rules ) ) )
153
-		);
154
-
155
-	}
156
-
157
-	/**
158
-	 * Get's an array of tax rates for a given address.
159
-	 *
160
-	 * @param string $country
161
-	 * @param string $state
162
-	 * @return array
163
-	 */
164
-	public static function get_address_tax_rates( $country, $state ) {
165
-
166
-		$all_tax_rates  = self::get_all_tax_rates();
167
-		$matching_rates = array_merge(
168
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
169
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
170
-		);
171
-
172
-		foreach ( $matching_rates as $i => $rate ) {
173
-
174
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
175
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
176
-				unset( $matching_rates[ $i ] );
177
-			}
16
+    /**
17
+     * Calculates tax for a line item.
18
+     *
19
+     * @param  float   $price              The price to calc tax on.
20
+     * @param  array   $rates              The rates to apply.
21
+     * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
+     * @return array                       Array of tax name => tax amount.
23
+     */
24
+    public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
+
26
+        if ( $price_includes_tax ) {
27
+            $taxes = self::calc_inclusive_tax( $price, $rates );
28
+        } else {
29
+            $taxes = self::calc_exclusive_tax( $price, $rates );
30
+        }
31
+
32
+        return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
+
34
+    }
35
+
36
+    /**
37
+     * Calc tax from inclusive price.
38
+     *
39
+     * @param  float $price Price to calculate tax for.
40
+     * @param  array $rates Array of tax rates.
41
+     * @return array
42
+     */
43
+    public static function calc_inclusive_tax( $price, $rates ) {
44
+        $taxes     = array();
45
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
+
47
+        // Add tax rates.
48
+        $tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
+
50
+        foreach ( $tax_rates as $name => $rate ) {
51
+            $the_rate       = ( $rate / 100 ) / $tax_rate;
52
+            $net_price      = $price - ( $the_rate * $price );
53
+            $tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
+            $taxes[ $name ] = $tax_amount;
55
+        }
56
+
57
+        // Round all taxes to precision (4DP) before passing them back.
58
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
+
60
+        return $taxes;
61
+    }
62
+
63
+    /**
64
+     * Calc tax from exclusive price.
65
+     *
66
+     * @param  float $price Price to calculate tax for.
67
+     * @param  array $rates Array of tax rates.
68
+     * @return array
69
+     */
70
+    public static function calc_exclusive_tax( $price, $rates ) {
71
+        $taxes     = array();
72
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
+
74
+        foreach ( $tax_rates as $name => $rate ) {
75
+
76
+            $tax_amount     = $price * ( $rate / 100 );
77
+            $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
+
79
+        }
80
+
81
+        // Round all taxes to precision (4DP) before passing them back.
82
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
+
84
+        return $taxes;
85
+    }
86
+
87
+    /**
88
+     * Get's an array of all tax rates.
89
+     *
90
+     * @return array
91
+     */
92
+    public static function get_all_tax_rates() {
93
+
94
+        $rates = get_option( 'wpinv_tax_rates', array() );
95
+
96
+        return apply_filters(
97
+            'getpaid_get_all_tax_rates',
98
+            array_filter( wpinv_parse_list( $rates ) )
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get's an array of default tax rates.
105
+     *
106
+     * @return array
107
+     */
108
+    public static function get_default_tax_rates() {
109
+
110
+        return apply_filters(
111
+            'getpaid_get_default_tax_rates',
112
+            array(
113
+                array(
114
+                    'country' => wpinv_get_default_country(),
115
+                    'state'   => wpinv_get_default_state(),
116
+                    'global'  => true,
117
+                    'rate'    => wpinv_get_default_tax_rate(),
118
+                    'name'    => __( 'Tax', 'invoicing' ),
119
+                ),
120
+            )
121
+        );
122
+
123
+    }
124
+
125
+    /**
126
+     * Get's an array of all tax rules.
127
+     *
128
+     * @return array
129
+     */
130
+    public static function get_all_tax_rules() {
131
+
132
+        $rules = get_option(
133
+            'wpinv_tax_rules',
134
+            array(
135
+                array(
136
+                    'key'               => 'physical',
137
+                    'label'             => __( 'Physical Item', 'invoicing' ),
138
+                    'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
139
+                    'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
140
+                ),
141
+                array(
142
+                    'key'               => 'digital',
143
+                    'label'             => __( 'Digital Item', 'invoicing' ),
144
+                    'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
145
+                    'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
146
+                ),
147
+            )
148
+        );
149
+
150
+        return apply_filters(
151
+            'getpaid_tax_rules',
152
+            array_filter( array_values( wpinv_parse_list( $rules ) ) )
153
+        );
154
+
155
+    }
156
+
157
+    /**
158
+     * Get's an array of tax rates for a given address.
159
+     *
160
+     * @param string $country
161
+     * @param string $state
162
+     * @return array
163
+     */
164
+    public static function get_address_tax_rates( $country, $state ) {
165
+
166
+        $all_tax_rates  = self::get_all_tax_rates();
167
+        $matching_rates = array_merge(
168
+            wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
169
+            wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
170
+        );
171
+
172
+        foreach ( $matching_rates as $i => $rate ) {
173
+
174
+            $states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
175
+            if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
176
+                unset( $matching_rates[ $i ] );
177
+            }
178 178
 }
179 179
 
180
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
181
-
182
-	}
183
-
184
-	/**
185
-	 * Sums a set of taxes to form a single total. Result is rounded to precision.
186
-	 *
187
-	 * @param  array $taxes Array of taxes.
188
-	 * @return float
189
-	 */
190
-	public static function get_tax_total( $taxes ) {
191
-		return self::round( array_sum( $taxes ) );
192
-	}
193
-
194
-	/**
195
-	 * Round to precision.
196
-	 *
197
-	 * Filter example: to return rounding to .5 cents you'd use:
198
-	 *
199
-	 * function euro_5cent_rounding( $in ) {
200
-	 *      return round( $in / 5, 2 ) * 5;
201
-	 * }
202
-	 * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
203
-	 *
204
-	 * @param float|int $in Value to round.
205
-	 * @return float
206
-	 */
207
-	public static function round( $in ) {
208
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
209
-	}
180
+        return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
181
+
182
+    }
183
+
184
+    /**
185
+     * Sums a set of taxes to form a single total. Result is rounded to precision.
186
+     *
187
+     * @param  array $taxes Array of taxes.
188
+     * @return float
189
+     */
190
+    public static function get_tax_total( $taxes ) {
191
+        return self::round( array_sum( $taxes ) );
192
+    }
193
+
194
+    /**
195
+     * Round to precision.
196
+     *
197
+     * Filter example: to return rounding to .5 cents you'd use:
198
+     *
199
+     * function euro_5cent_rounding( $in ) {
200
+     *      return round( $in / 5, 2 ) * 5;
201
+     * }
202
+     * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
203
+     *
204
+     * @param float|int $in Value to round.
205
+     * @return float
206
+     */
207
+    public static function round( $in ) {
208
+        return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
209
+    }
210 210
 
211 211
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 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
  * Class GetPaid_Tax
@@ -21,15 +21,15 @@  discard block
 block discarded – undo
21 21
 	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22 22
 	 * @return array                       Array of tax name => tax amount.
23 23
 	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
24
+	public static function calc_tax($price, $rates, $price_includes_tax = false) {
25 25
 
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
26
+		if ($price_includes_tax) {
27
+			$taxes = self::calc_inclusive_tax($price, $rates);
28 28
 		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
29
+			$taxes = self::calc_exclusive_tax($price, $rates);
30 30
 		}
31 31
 
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
32
+		return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax);
33 33
 
34 34
 	}
35 35
 
@@ -40,22 +40,22 @@  discard block
 block discarded – undo
40 40
 	 * @param  array $rates Array of tax rates.
41 41
 	 * @return array
42 42
 	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
43
+	public static function calc_inclusive_tax($price, $rates) {
44 44
 		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
45
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
46 46
 
47 47
 		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
48
+		$tax_rate  = 1 + (array_sum($tax_rates) / 100);
49 49
 
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
50
+		foreach ($tax_rates as $name => $rate) {
51
+			$the_rate       = ($rate / 100) / $tax_rate;
52
+			$net_price      = $price - ($the_rate * $price);
53
+			$tax_amount     = apply_filters('getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price);
54
+			$taxes[$name] = $tax_amount;
55 55
 		}
56 56
 
57 57
 		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
58
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
59 59
 
60 60
 		return $taxes;
61 61
 	}
@@ -67,19 +67,19 @@  discard block
 block discarded – undo
67 67
 	 * @param  array $rates Array of tax rates.
68 68
 	 * @return array
69 69
 	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
70
+	public static function calc_exclusive_tax($price, $rates) {
71 71
 		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
72
+		$tax_rates = wp_list_pluck($rates, 'rate', 'name');
73 73
 
74
-		foreach ( $tax_rates as $name => $rate ) {
74
+		foreach ($tax_rates as $name => $rate) {
75 75
 
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
76
+			$tax_amount     = $price * ($rate / 100);
77
+			$taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price);
78 78
 
79 79
 		}
80 80
 
81 81
 		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
82
+		$taxes = array_map(array(__CLASS__, 'round'), $taxes);
83 83
 
84 84
 		return $taxes;
85 85
 	}
@@ -91,11 +91,11 @@  discard block
 block discarded – undo
91 91
 	 */
92 92
 	public static function get_all_tax_rates() {
93 93
 
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
94
+		$rates = get_option('wpinv_tax_rates', array());
95 95
 
96 96
 		return apply_filters(
97 97
 			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
98
+			array_filter(wpinv_parse_list($rates))
99 99
 		);
100 100
 
101 101
 	}
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 					'state'   => wpinv_get_default_state(),
116 116
 					'global'  => true,
117 117
 					'rate'    => wpinv_get_default_tax_rate(),
118
-					'name'    => __( 'Tax', 'invoicing' ),
118
+					'name'    => __('Tax', 'invoicing'),
119 119
 				),
120 120
 			)
121 121
 		);
@@ -134,22 +134,22 @@  discard block
 block discarded – undo
134 134
 			array(
135 135
 				array(
136 136
 					'key'               => 'physical',
137
-					'label'             => __( 'Physical Item', 'invoicing' ),
138
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
139
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
137
+					'label'             => __('Physical Item', 'invoicing'),
138
+					'tax_base'          => wpinv_get_option('tax_base', 'billing'),
139
+					'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'),
140 140
 				),
141 141
 				array(
142 142
 					'key'               => 'digital',
143
-					'label'             => __( 'Digital Item', 'invoicing' ),
144
-					'tax_base'          => wpinv_get_option( 'tax_base', 'billing' ),
145
-					'same_country_rule' => wpinv_get_option( 'vat_same_country_rule', 'vat_too' ),
143
+					'label'             => __('Digital Item', 'invoicing'),
144
+					'tax_base'          => wpinv_get_option('tax_base', 'billing'),
145
+					'same_country_rule' => wpinv_get_option('vat_same_country_rule', 'vat_too'),
146 146
 				),
147 147
         	)
148 148
 		);
149 149
 
150 150
 		return apply_filters(
151 151
 			'getpaid_tax_rules',
152
-			array_filter( array_values( wpinv_parse_list( $rules ) ) )
152
+			array_filter(array_values(wpinv_parse_list($rules)))
153 153
 		);
154 154
 
155 155
 	}
@@ -161,23 +161,23 @@  discard block
 block discarded – undo
161 161
 	 * @param string $state
162 162
 	 * @return array
163 163
 	 */
164
-	public static function get_address_tax_rates( $country, $state ) {
164
+	public static function get_address_tax_rates($country, $state) {
165 165
 
166 166
 		$all_tax_rates  = self::get_all_tax_rates();
167 167
 		$matching_rates = array_merge(
168
-			wp_list_filter( $all_tax_rates, array( 'country' => $country ) ),
169
-			wp_list_filter( $all_tax_rates, array( 'country' => '' ) )
168
+			wp_list_filter($all_tax_rates, array('country' => $country)),
169
+			wp_list_filter($all_tax_rates, array('country' => ''))
170 170
 		);
171 171
 
172
-		foreach ( $matching_rates as $i => $rate ) {
172
+		foreach ($matching_rates as $i => $rate) {
173 173
 
174
-			$states = array_filter( wpinv_clean( explode( ',', strtolower( $rate['state'] ) ) ) );
175
-			if ( empty( $rate['global'] ) && ! in_array( strtolower( $state ), $states ) ) {
176
-				unset( $matching_rates[ $i ] );
174
+			$states = array_filter(wpinv_clean(explode(',', strtolower($rate['state']))));
175
+			if (empty($rate['global']) && !in_array(strtolower($state), $states)) {
176
+				unset($matching_rates[$i]);
177 177
 			}
178 178
 }
179 179
 
180
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
180
+		return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state);
181 181
 
182 182
 	}
183 183
 
@@ -187,8 +187,8 @@  discard block
 block discarded – undo
187 187
 	 * @param  array $taxes Array of taxes.
188 188
 	 * @return float
189 189
 	 */
190
-	public static function get_tax_total( $taxes ) {
191
-		return self::round( array_sum( $taxes ) );
190
+	public static function get_tax_total($taxes) {
191
+		return self::round(array_sum($taxes));
192 192
 	}
193 193
 
194 194
 	/**
@@ -204,8 +204,8 @@  discard block
 block discarded – undo
204 204
 	 * @param float|int $in Value to round.
205 205
 	 * @return float
206 206
 	 */
207
-	public static function round( $in ) {
208
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
207
+	public static function round($in) {
208
+		return apply_filters('getpaid_tax_round', round($in, 4), $in);
209 209
 	}
210 210
 
211 211
 }
Please login to merge, or discard this patch.
templates/emails/invoice-totals.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -8,22 +8,22 @@  discard block
 block discarded – undo
8 8
  * @var WPInv_Invoice $invoice
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 // Totals rows.
14
-$totals = getpaid_invoice_totals_rows( $invoice );
14
+$totals = getpaid_invoice_totals_rows($invoice);
15 15
 
16
-do_action( 'getpaid_before_email_line_totals', $invoice, $totals );
16
+do_action('getpaid_before_email_line_totals', $invoice, $totals);
17 17
 
18 18
 ?>
19 19
 
20 20
 
21
-<?php if ( has_action( 'wpinv_email_footer_buttons' ) ) : ?>
21
+<?php if (has_action('wpinv_email_footer_buttons')) : ?>
22 22
 
23 23
     <tr class="wpinv_cart_footer_row">
24 24
 
25
-        <td colspan="<?php echo ( (int) $column_count ); ?>">
26
-            <?php do_action( 'wpinv_email_footer_buttons' ); ?>
25
+        <td colspan="<?php echo ((int) $column_count); ?>">
26
+            <?php do_action('wpinv_email_footer_buttons'); ?>
27 27
         </td>
28 28
 
29 29
     </tr>
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
 <?php endif; ?>
32 32
 
33 33
 
34
-<?php foreach ( $totals as $key => $label ) : ?>
34
+<?php foreach ($totals as $key => $label) : ?>
35 35
 
36
-    <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html( $key ); ?>_row">
36
+    <tr class="wpinv_cart_footer_row wpinv_cart_<?php echo esc_html($key); ?>_row">
37 37
 
38
-        <td colspan="<?php echo absint( ( $column_count - 1 ) ); ?>" class="wpinv_cart_<?php echo esc_html( $key ); ?>_label text-right">
39
-            <strong><?php echo esc_html( $label ); ?>:</strong>
38
+        <td colspan="<?php echo absint(($column_count - 1)); ?>" class="wpinv_cart_<?php echo esc_html($key); ?>_label text-right">
39
+            <strong><?php echo esc_html($label); ?>:</strong>
40 40
         </td>
41 41
 
42
-        <td class="wpinv_cart_<?php echo esc_html( $key ); ?> text-right">
42
+        <td class="wpinv_cart_<?php echo esc_html($key); ?> text-right">
43 43
 
44 44
             <?php
45 45
 
46 46
                 // Total tax.
47
-                if ( 'tax' == $key ) {
48
-                    wpinv_the_price( $invoice->get_total_tax(), $invoice->get_currency() );
47
+                if ('tax' == $key) {
48
+                    wpinv_the_price($invoice->get_total_tax(), $invoice->get_currency());
49 49
                 }
50 50
 
51 51
                 // Individual taxes.
52
-                if ( 0 === strpos( $key, 'tax__' ) ) {
53
-                    wpinv_the_price( $invoice->get_tax_total_by_name( str_replace( 'tax__', '', $key ) ), $invoice->get_currency() );
52
+                if (0 === strpos($key, 'tax__')) {
53
+                    wpinv_the_price($invoice->get_tax_total_by_name(str_replace('tax__', '', $key)), $invoice->get_currency());
54 54
                 }
55 55
 
56
-                if ( 'fee' == $key ) {
57
-                    wpinv_the_price( $invoice->get_total_fees(), $invoice->get_currency() );
56
+                if ('fee' == $key) {
57
+                    wpinv_the_price($invoice->get_total_fees(), $invoice->get_currency());
58 58
                 }
59 59
 
60 60
                 // Total discount.
61
-                if ( 'discount' == $key ) {
62
-                    wpinv_the_price( $invoice->get_total_discount(), $invoice->get_currency() );
61
+                if ('discount' == $key) {
62
+                    wpinv_the_price($invoice->get_total_discount(), $invoice->get_currency());
63 63
                 }
64 64
 
65 65
                 // Sub total.
66
-                if ( 'subtotal' == $key ) {
67
-                    wpinv_the_price( $invoice->get_subtotal(), $invoice->get_currency() );
66
+                if ('subtotal' == $key) {
67
+                    wpinv_the_price($invoice->get_subtotal(), $invoice->get_currency());
68 68
                 }
69 69
 
70 70
                 // Total.
71
-                if ( 'total' == $key ) {
72
-                    wpinv_the_price( $invoice->get_total(), $invoice->get_currency() );
71
+                if ('total' == $key) {
72
+                    wpinv_the_price($invoice->get_total(), $invoice->get_currency());
73 73
                 }
74 74
 
75 75
                 // Fires when printing a cart total in an email.
76
-                do_action( "getpaid_email_cart_totals_$key", $invoice );
76
+                do_action("getpaid_email_cart_totals_$key", $invoice);
77 77
 
78 78
             ?>
79 79
 
@@ -85,4 +85,4 @@  discard block
 block discarded – undo
85 85
 
86 86
 <?php
87 87
 
88
-    do_action( 'getpaid_after_email_line_totals', $invoice, $totals );
88
+    do_action('getpaid_after_email_line_totals', $invoice, $totals);
Please login to merge, or discard this patch.
includes/invoice-functions.php 2 patches
Spacing   +373 added lines, -373 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 the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( sanitize_text_field( $_GET['invoice_key'] ) );
22
+    $invoice = new WPInv_Invoice(sanitize_text_field($_GET['invoice_key']));
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field( $_GET['invoice_key'] ) ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == sanitize_text_field($_GET['invoice_key'])) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && sanitize_text_field( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && sanitize_text_field($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can( 'view_invoice', array( 'invoice' => $invoice ) ) || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can('view_invoice', array('invoice' => $invoice)) || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,16 +77,16 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84 84
     // Ensure the quotes addon is installed.
85
-    if ( ! defined( 'WPINV_QUOTES_VERSION' ) ) {
86
-        unset( $post_types['wpi_quote'] );
85
+    if (!defined('WPINV_QUOTES_VERSION')) {
86
+        unset($post_types['wpi_quote']);
87 87
     }
88 88
 
89
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
89
+    return apply_filters('getpaid_invoice_post_types', $post_types);
90 90
 }
91 91
 
92 92
 /**
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
  *
96 96
  * @param string $post_type The post type to check for.
97 97
  */
98
-function getpaid_is_invoice_post_type( $post_type ) {
99
-    return is_scalar( $post_type ) && ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
98
+function getpaid_is_invoice_post_type($post_type) {
99
+    return is_scalar($post_type) && !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
100 100
 }
101 101
 
102 102
 /**
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
107 107
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
108 108
  */
109
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
109
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
110 110
     $data['invoice_id'] = 0;
111
-    return wpinv_insert_invoice( $data, $wp_error );
111
+    return wpinv_insert_invoice($data, $wp_error);
112 112
 }
113 113
 
114 114
 /**
@@ -118,35 +118,35 @@  discard block
 block discarded – undo
118 118
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
119 119
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
120 120
  */
121
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
121
+function wpinv_update_invoice($data = array(), $wp_error = false) {
122 122
 
123 123
     // Backwards compatibility.
124
-    if ( ! empty( $data['ID'] ) ) {
124
+    if (!empty($data['ID'])) {
125 125
         $data['invoice_id'] = $data['ID'];
126 126
     }
127 127
 
128 128
     // Do we have an invoice id?
129
-    if ( empty( $data['invoice_id'] ) ) {
130
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
129
+    if (empty($data['invoice_id'])) {
130
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
131 131
     }
132 132
 
133 133
     // Retrieve the invoice.
134
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
134
+    $invoice = wpinv_get_invoice($data['invoice_id']);
135 135
 
136 136
     // And abort if it does not exist.
137
-    if ( empty( $invoice ) ) {
138
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
137
+    if (empty($invoice)) {
138
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
139 139
     }
140 140
 
141 141
     // Do not update totals for paid / refunded invoices.
142
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
142
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
143 143
 
144
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
145
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
144
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
145
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
146 146
         }
147 147
 }
148 148
 
149
-    return wpinv_insert_invoice( $data, $wp_error );
149
+    return wpinv_insert_invoice($data, $wp_error);
150 150
 
151 151
 }
152 152
 
@@ -157,62 +157,62 @@  discard block
 block discarded – undo
157 157
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
158 158
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
159 159
  */
160
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
160
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
161 161
 
162 162
     // Ensure that we have invoice data.
163
-    if ( empty( $data ) ) {
163
+    if (empty($data)) {
164 164
         return false;
165 165
     }
166 166
 
167 167
     // The invoice id will be provided when updating an invoice.
168
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
168
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
169 169
 
170 170
     // Retrieve the invoice.
171
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
171
+    $invoice = new WPInv_Invoice($data['invoice_id']);
172 172
 
173 173
     // Do we have an error?
174
-    if ( ! empty( $invoice->last_error ) ) {
175
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
174
+    if (!empty($invoice->last_error)) {
175
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
176 176
     }
177 177
 
178 178
     // Backwards compatibility (billing address).
179
-    if ( ! empty( $data['user_info'] ) ) {
179
+    if (!empty($data['user_info'])) {
180 180
 
181
-        foreach ( $data['user_info'] as $key => $value ) {
181
+        foreach ($data['user_info'] as $key => $value) {
182 182
 
183
-            if ( $key == 'discounts' ) {
183
+            if ($key == 'discounts') {
184 184
                 $value = (array) $value;
185
-                $data['discount_code'] = empty( $value ) ? null : $value[0];
185
+                $data['discount_code'] = empty($value) ? null : $value[0];
186 186
             } else {
187
-                $data[ $key ] = $value;
187
+                $data[$key] = $value;
188 188
             }
189 189
 }
190 190
 }
191 191
 
192 192
     // Backwards compatibility.
193
-    if ( ! empty( $data['payment_details'] ) ) {
193
+    if (!empty($data['payment_details'])) {
194 194
 
195
-        foreach ( $data['payment_details'] as $key => $value ) {
196
-            $data[ $key ] = $value;
195
+        foreach ($data['payment_details'] as $key => $value) {
196
+            $data[$key] = $value;
197 197
         }
198 198
 }
199 199
 
200 200
     // Set up the owner of the invoice.
201
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
201
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
202 202
 
203 203
     // Make sure the user exists.
204
-    if ( ! get_userdata( $user_id ) ) {
205
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
204
+    if (!get_userdata($user_id)) {
205
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
206 206
     }
207 207
 
208
-    $address = wpinv_get_user_address( $user_id );
208
+    $address = wpinv_get_user_address($user_id);
209 209
 
210
-    foreach ( $address as $key => $value ) {
210
+    foreach ($address as $key => $value) {
211 211
 
212
-        if ( $value == '' ) {
213
-            $address[ $key ] = null;
212
+        if ($value == '') {
213
+            $address[$key] = null;
214 214
         } else {
215
-            $address[ $key ] = wpinv_clean( $value );
215
+            $address[$key] = wpinv_clean($value);
216 216
         }
217 217
 }
218 218
 
@@ -221,101 +221,101 @@  discard block
 block discarded – undo
221 221
         array(
222 222
 
223 223
             // Basic info.
224
-            'template'          => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
225
-            'email_cc'          => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
226
-            'date_created'      => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
227
-            'due_date'          => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
228
-            'date_completed'    => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
229
-            'number'            => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
230
-            'key'               => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
231
-            'status'            => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
232
-            'post_type'         => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
233
-            'user_ip'           => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
234
-            'parent_id'         => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
235
-            'mode'              => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
236
-            'description'       => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
224
+            'template'          => isset($data['template']) ? wpinv_clean($data['template']) : null,
225
+            'email_cc'          => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
226
+            'date_created'      => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
227
+            'due_date'          => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
228
+            'date_completed'    => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
229
+            'number'            => isset($data['number']) ? wpinv_clean($data['number']) : null,
230
+            'key'               => isset($data['key']) ? wpinv_clean($data['key']) : null,
231
+            'status'            => isset($data['status']) ? wpinv_clean($data['status']) : null,
232
+            'post_type'         => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
233
+            'user_ip'           => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
234
+            'parent_id'         => isset($data['parent']) ? intval($data['parent']) : null,
235
+            'mode'              => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
236
+            'description'       => isset($data['description']) ? wp_kses_post($data['description']) : null,
237 237
 
238 238
             // Payment info.
239
-            'disable_taxes'     => ! empty( $data['disable_taxes'] ),
240
-            'currency'          => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
241
-            'gateway'           => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
242
-            'transaction_id'    => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
243
-            'discount_code'     => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
244
-            'payment_form'      => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
245
-            'submission_id'     => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
246
-            'subscription_id'   => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
247
-            'is_viewed'         => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
248
-            'fees'              => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
249
-            'discounts'         => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
250
-            'taxes'             => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
239
+            'disable_taxes'     => !empty($data['disable_taxes']),
240
+            'currency'          => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
241
+            'gateway'           => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
242
+            'transaction_id'    => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
243
+            'discount_code'     => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
244
+            'payment_form'      => isset($data['payment_form']) ? intval($data['payment_form']) : null,
245
+            'submission_id'     => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
246
+            'subscription_id'   => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
247
+            'is_viewed'         => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
248
+            'fees'              => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
249
+            'discounts'         => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
250
+            'taxes'             => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
251 251
 
252 252
             // Billing details.
253 253
             'user_id'           => $data['user_id'],
254
-            'first_name'        => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
255
-            'last_name'         => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
256
-            'address'           => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'],
257
-            'vat_number'        => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
258
-            'company'           => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
259
-            'zip'               => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
260
-            'state'             => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
261
-            'city'              => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
262
-            'country'           => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
263
-            'phone'             => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
264
-            'address_confirmed' => ! empty( $data['address_confirmed'] ),
254
+            'first_name'        => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
255
+            'last_name'         => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
256
+            'address'           => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
257
+            'vat_number'        => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
258
+            'company'           => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
259
+            'zip'               => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
260
+            'state'             => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
261
+            'city'              => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
262
+            'country'           => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
263
+            'phone'             => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
264
+            'address_confirmed' => !empty($data['address_confirmed']),
265 265
 
266 266
         )
267 267
     );
268 268
 
269 269
     // Backwards compatibililty.
270
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
270
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
271 271
         $data['items'] = array();
272 272
 
273
-        foreach ( $data['cart_details'] as $_item ) {
273
+        foreach ($data['cart_details'] as $_item) {
274 274
 
275 275
             // Ensure that we have an item id.
276
-            if ( empty( $_item['id'] ) ) {
276
+            if (empty($_item['id'])) {
277 277
                 continue;
278 278
             }
279 279
 
280 280
             // Retrieve the item.
281
-            $item = new GetPaid_Form_Item( $_item['id'] );
281
+            $item = new GetPaid_Form_Item($_item['id']);
282 282
 
283 283
             // Ensure that it is purchasable.
284
-            if ( ! $item->can_purchase() ) {
284
+            if (!$item->can_purchase()) {
285 285
                 continue;
286 286
             }
287 287
 
288 288
             // Set quantity.
289
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
290
-                $item->set_quantity( $_item['quantity'] );
289
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
290
+                $item->set_quantity($_item['quantity']);
291 291
             }
292 292
 
293 293
             // Set price.
294
-            if ( isset( $_item['item_price'] ) ) {
295
-                $item->set_price( $_item['item_price'] );
294
+            if (isset($_item['item_price'])) {
295
+                $item->set_price($_item['item_price']);
296 296
             }
297 297
 
298
-            if ( isset( $_item['custom_price'] ) ) {
299
-                $item->set_price( $_item['custom_price'] );
298
+            if (isset($_item['custom_price'])) {
299
+                $item->set_price($_item['custom_price']);
300 300
             }
301 301
 
302 302
             // Set name.
303
-            if ( ! empty( $_item['name'] ) ) {
304
-                $item->set_name( $_item['name'] );
303
+            if (!empty($_item['name'])) {
304
+                $item->set_name($_item['name']);
305 305
             }
306 306
 
307 307
             // Set description.
308
-            if ( isset( $_item['description'] ) ) {
309
-                $item->set_custom_description( $_item['description'] );
308
+            if (isset($_item['description'])) {
309
+                $item->set_custom_description($_item['description']);
310 310
             }
311 311
 
312 312
             // Set meta.
313
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
313
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
314 314
 
315
-                $item->set_item_meta( $_item['meta'] );
315
+                $item->set_item_meta($_item['meta']);
316 316
 
317
-                if ( isset( $_item['meta']['description'] ) ) {
318
-                    $item->set_custom_description( $_item['meta']['description'] );
317
+                if (isset($_item['meta']['description'])) {
318
+                    $item->set_custom_description($_item['meta']['description']);
319 319
                 }
320 320
             }
321 321
 
@@ -325,14 +325,14 @@  discard block
 block discarded – undo
325 325
     }
326 326
 
327 327
     // Add invoice items.
328
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
328
+    if (!empty($data['items']) && is_array($data['items'])) {
329 329
 
330
-        $invoice->set_items( array() );
330
+        $invoice->set_items(array());
331 331
 
332
-        foreach ( $data['items'] as $item ) {
332
+        foreach ($data['items'] as $item) {
333 333
 
334
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
335
-                $invoice->add_item( $item );
334
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
335
+                $invoice->add_item($item);
336 336
             }
337 337
 }
338 338
 }
@@ -341,30 +341,30 @@  discard block
 block discarded – undo
341 341
     $invoice->recalculate_total();
342 342
     $invoice->save();
343 343
 
344
-    if ( ! $invoice->get_id() ) {
345
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
344
+    if (!$invoice->get_id()) {
345
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
346 346
     }
347 347
 
348 348
     // Add private note.
349
-    if ( ! empty( $data['private_note'] ) ) {
350
-        $invoice->add_note( $data['private_note'] );
349
+    if (!empty($data['private_note'])) {
350
+        $invoice->add_note($data['private_note']);
351 351
     }
352 352
 
353 353
     // User notes.
354
-    if ( ! empty( $data['user_note'] ) ) {
355
-        $invoice->add_note( $data['user_note'], true );
354
+    if (!empty($data['user_note'])) {
355
+        $invoice->add_note($data['user_note'], true);
356 356
     }
357 357
 
358 358
     // Created via.
359
-    if ( isset( $data['created_via'] ) ) {
360
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
359
+    if (isset($data['created_via'])) {
360
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
361 361
     }
362 362
 
363 363
     // Backwards compatiblity.
364
-    if ( $invoice->is_quote() ) {
364
+    if ($invoice->is_quote()) {
365 365
 
366
-        if ( isset( $data['valid_until'] ) ) {
367
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
366
+        if (isset($data['valid_until'])) {
367
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
368 368
         }
369 369
 }
370 370
 
@@ -378,20 +378,20 @@  discard block
 block discarded – undo
378 378
  * @param $bool $deprecated
379 379
  * @return WPInv_Invoice|null
380 380
  */
381
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
381
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
382 382
 
383 383
     // If we are retrieving the invoice from the cart...
384
-    if ( $deprecated && empty( $invoice ) ) {
384
+    if ($deprecated && empty($invoice)) {
385 385
         $invoice = (int) getpaid_get_current_invoice_id();
386 386
     }
387 387
 
388 388
     // Retrieve the invoice.
389
-    if ( ! is_a( $invoice, 'WPInv_Invoice' ) ) {
390
-        $invoice = new WPInv_Invoice( $invoice );
389
+    if (!is_a($invoice, 'WPInv_Invoice')) {
390
+        $invoice = new WPInv_Invoice($invoice);
391 391
     }
392 392
 
393 393
     // Check if it exists.
394
-    if ( $invoice->exists() ) {
394
+    if ($invoice->exists()) {
395 395
         return $invoice;
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
  * @param array $args Args to search for.
405 405
  * @return WPInv_Invoice[]|int[]|object
406 406
  */
407
-function wpinv_get_invoices( $args ) {
407
+function wpinv_get_invoices($args) {
408 408
 
409 409
     // Prepare args.
410 410
     $args = wp_parse_args(
411 411
         $args,
412 412
         array(
413
-            'status' => array_keys( wpinv_get_invoice_statuses() ),
413
+            'status' => array_keys(wpinv_get_invoice_statuses()),
414 414
             'type'   => 'wpi_invoice',
415
-            'limit'  => get_option( 'posts_per_page' ),
415
+            'limit'  => get_option('posts_per_page'),
416 416
             'return' => 'objects',
417 417
         )
418 418
     );
@@ -430,24 +430,24 @@  discard block
 block discarded – undo
430 430
         'post__in'       => 'include',
431 431
     );
432 432
 
433
-    foreach ( $map_legacy as $to => $from ) {
434
-        if ( isset( $args[ $from ] ) ) {
435
-            $args[ $to ] = $args[ $from ];
436
-            unset( $args[ $from ] );
433
+    foreach ($map_legacy as $to => $from) {
434
+        if (isset($args[$from])) {
435
+            $args[$to] = $args[$from];
436
+            unset($args[$from]);
437 437
         }
438 438
     }
439 439
 
440 440
     // Backwards compatibility.
441
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
441
+    if (!empty($args['email']) && empty($args['user'])) {
442 442
         $args['user'] = $args['email'];
443
-        unset( $args['email'] );
443
+        unset($args['email']);
444 444
     }
445 445
 
446 446
     // Handle cases where the user is set as an email.
447
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
448
-        $user = get_user_by( 'email', $args['user'] );
447
+    if (!empty($args['author']) && is_email($args['author'])) {
448
+        $user = get_user_by('email', $args['user']);
449 449
 
450
-        if ( $user ) {
450
+        if ($user) {
451 451
             $args['author'] = $user->user_email;
452 452
         }
453 453
 }
@@ -457,31 +457,31 @@  discard block
 block discarded – undo
457 457
 
458 458
     // Show all posts.
459 459
     $paginate = true;
460
-    if ( isset( $args['paginate'] ) ) {
460
+    if (isset($args['paginate'])) {
461 461
 
462 462
         $paginate = $args['paginate'];
463
-        $args['no_found_rows'] = empty( $args['paginate'] );
464
-        unset( $args['paginate'] );
463
+        $args['no_found_rows'] = empty($args['paginate']);
464
+        unset($args['paginate']);
465 465
 
466 466
     }
467 467
 
468 468
     // Whether to return objects or fields.
469 469
     $return = $args['return'];
470
-    unset( $args['return'] );
470
+    unset($args['return']);
471 471
 
472 472
     // Get invoices.
473
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
473
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
474 474
 
475 475
     // Prepare the results.
476
-    if ( 'objects' === $return ) {
477
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
478
-    } elseif ( 'self' === $return ) {
476
+    if ('objects' === $return) {
477
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
478
+    } elseif ('self' === $return) {
479 479
         return $invoices;
480 480
     } else {
481 481
         $results = $invoices->posts;
482 482
     }
483 483
 
484
-    if ( $paginate ) {
484
+    if ($paginate) {
485 485
         return (object) array(
486 486
             'invoices'      => $results,
487 487
             'total'         => $invoices->found_posts,
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
  * @param string $transaction_id The transaction id to check.
500 500
  * @return int Invoice id on success or 0 on failure
501 501
  */
502
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
503
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
502
+function wpinv_get_id_by_transaction_id($transaction_id) {
503
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
504 504
 }
505 505
 
506 506
 /**
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
  * @param string $invoice_number The invoice number to check.
510 510
  * @return int Invoice id on success or 0 on failure
511 511
  */
512
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
513
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
512
+function wpinv_get_id_by_invoice_number($invoice_number) {
513
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
514 514
 }
515 515
 
516 516
 /**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
  * @param string $invoice_key The invoice key to check.
520 520
  * @return int Invoice id on success or 0 on failure
521 521
  */
522
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
523
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
522
+function wpinv_get_invoice_id_by_key($invoice_key) {
523
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
524 524
 }
525 525
 
526 526
 /**
@@ -530,19 +530,19 @@  discard block
 block discarded – undo
530 530
  * @param string $type Optionally filter by type i.e customer|system
531 531
  * @return array|null
532 532
  */
533
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
533
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
534 534
 
535 535
     // Prepare the invoice.
536
-    $invoice = wpinv_get_invoice( $invoice );
537
-    if ( empty( $invoice ) ) {
536
+    $invoice = wpinv_get_invoice($invoice);
537
+    if (empty($invoice)) {
538 538
         return null;
539 539
     }
540 540
 
541 541
     // Fetch notes.
542
-    $notes = getpaid_notes()->get_invoice_notes( $invoice->get_id(), $type );
542
+    $notes = getpaid_notes()->get_invoice_notes($invoice->get_id(), $type);
543 543
 
544 544
     // Filter the notes.
545
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
545
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
546 546
 }
547 547
 
548 548
 /**
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
  *
551 551
  * @param string $post_type
552 552
  */
553
-function wpinv_get_user_invoices_columns( $post_type = 'wpi_invoice' ) {
553
+function wpinv_get_user_invoices_columns($post_type = 'wpi_invoice') {
554 554
 
555
-    $label   = getpaid_get_post_type_label( $post_type, false );
556
-    $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
555
+    $label   = getpaid_get_post_type_label($post_type, false);
556
+    $label   = empty($label) ? __('Invoice', 'invoicing') : sanitize_text_field($label);
557 557
     $columns = array(
558 558
 
559 559
 		'invoice-number'  => array(
@@ -562,22 +562,22 @@  discard block
 block discarded – undo
562 562
 		),
563 563
 
564 564
 		'created-date'    => array(
565
-			'title' => __( 'Created Date', 'invoicing' ),
565
+			'title' => __('Created Date', 'invoicing'),
566 566
 			'class' => 'text-left',
567 567
 		),
568 568
 
569 569
 		'payment-date'    => array(
570
-			'title' => __( 'Payment Date', 'invoicing' ),
570
+			'title' => __('Payment Date', 'invoicing'),
571 571
 			'class' => 'text-left',
572 572
 		),
573 573
 
574 574
 		'invoice-status'  => array(
575
-			'title' => __( 'Status', 'invoicing' ),
575
+			'title' => __('Status', 'invoicing'),
576 576
 			'class' => 'text-center',
577 577
 		),
578 578
 
579 579
 		'invoice-total'   => array(
580
-			'title' => __( 'Total', 'invoicing' ),
580
+			'title' => __('Total', 'invoicing'),
581 581
 			'class' => 'text-right',
582 582
 		),
583 583
 
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 
589 589
 	);
590 590
 
591
-    return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
591
+    return apply_filters('wpinv_user_invoices_columns', $columns, $post_type);
592 592
 }
593 593
 
594 594
 /**
@@ -598,59 +598,59 @@  discard block
 block discarded – undo
598 598
 
599 599
     // Find the invoice.
600 600
     $invoice_id = getpaid_get_current_invoice_id();
601
-    $invoice = new WPInv_Invoice( $invoice_id );
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603 603
     // Abort if non was found.
604
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
604
+    if (empty($invoice_id) || $invoice->is_draft()) {
605 605
 
606 606
         return aui()->alert(
607 607
             array(
608 608
                 'type'    => 'warning',
609
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
609
+                'content' => __('We could not find your invoice', 'invoicing'),
610 610
             )
611 611
         );
612 612
 
613 613
     }
614 614
 
615 615
     // Can the user view this invoice?
616
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
616
+    if (!wpinv_can_view_receipt($invoice_id)) {
617 617
 
618 618
         return aui()->alert(
619 619
             array(
620 620
                 'type'    => 'warning',
621
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
621
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
622 622
             )
623 623
         );
624 624
 
625 625
     }
626 626
 
627 627
     // Load the template.
628
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
628
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
629 629
 
630 630
 }
631 631
 
632 632
 /**
633 633
  * Displays the invoice history.
634 634
  */
635
-function getpaid_invoice_history( $user_id = 0, $post_type = 'wpi_invoice' ) {
635
+function getpaid_invoice_history($user_id = 0, $post_type = 'wpi_invoice') {
636 636
 
637 637
     // Ensure that we have a user id.
638
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
638
+    if (empty($user_id) || !is_numeric($user_id)) {
639 639
         $user_id = get_current_user_id();
640 640
     }
641 641
 
642
-    $label = getpaid_get_post_type_label( $post_type );
643
-    $label = empty( $label ) ? __( 'Invoices', 'invoicing' ) : sanitize_text_field( $label );
642
+    $label = getpaid_get_post_type_label($post_type);
643
+    $label = empty($label) ? __('Invoices', 'invoicing') : sanitize_text_field($label);
644 644
 
645 645
     // View user id.
646
-    if ( empty( $user_id ) ) {
646
+    if (empty($user_id)) {
647 647
 
648 648
         return aui()->alert(
649 649
             array(
650 650
                 'type'    => 'warning',
651 651
                 'content' => sprintf(
652
-                    __( 'You must be logged in to view your %s.', 'invoicing' ),
653
-                    strtolower( $label )
652
+                    __('You must be logged in to view your %s.', 'invoicing'),
653
+                    strtolower($label)
654 654
                 ),
655 655
             )
656 656
         );
@@ -660,22 +660,22 @@  discard block
 block discarded – undo
660 660
     // Fetch invoices.
661 661
     $invoices = wpinv_get_invoices(
662 662
         array(
663
-            'page'     => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
663
+            'page'     => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
664 664
             'user'     => $user_id,
665 665
             'paginate' => true,
666 666
             'type'     => $post_type,
667
-            'status'   => array_keys( wpinv_get_invoice_statuses( false, false, $post_type ) ),
667
+            'status'   => array_keys(wpinv_get_invoice_statuses(false, false, $post_type)),
668 668
         )
669 669
     );
670 670
 
671
-    if ( empty( $invoices->total ) ) {
671
+    if (empty($invoices->total)) {
672 672
 
673 673
         return aui()->alert(
674 674
             array(
675 675
                 'type'    => 'info',
676 676
                 'content' => sprintf(
677
-                    __( 'No %s found.', 'invoicing' ),
678
-                    strtolower( $label )
677
+                    __('No %s found.', 'invoicing'),
678
+                    strtolower($label)
679 679
                 ),
680 680
             )
681 681
         );
@@ -683,38 +683,38 @@  discard block
 block discarded – undo
683 683
     }
684 684
 
685 685
     // Load the template.
686
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices', 'post_type' ) );
686
+    return wpinv_get_template_html('invoice-history.php', compact('invoices', 'post_type'));
687 687
 
688 688
 }
689 689
 
690 690
 /**
691 691
  * Formats an invoice number given an invoice type.
692 692
  */
693
-function wpinv_format_invoice_number( $number, $type = '' ) {
693
+function wpinv_format_invoice_number($number, $type = '') {
694 694
 
695 695
     // Allow other plugins to overide this.
696
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
697
-    if ( null !== $check ) {
696
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
697
+    if (null !== $check) {
698 698
         return $check;
699 699
     }
700 700
 
701 701
     // Ensure that we have a numeric number.
702
-    if ( ! is_numeric( $number ) ) {
702
+    if (!is_numeric($number)) {
703 703
         return $number;
704 704
     }
705 705
 
706 706
     // Format the number.
707
-    $padd             = absint( (int) wpinv_get_option( 'invoice_number_padd', 5 ) );
708
-    $prefix           = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_prefix', 'INV-' ) );
709
-    $prefix           = sanitize_text_field( apply_filters( 'getpaid_invoice_type_prefix', $prefix, $type ) );
710
-    $postfix          = sanitize_text_field( (string) wpinv_get_option( 'invoice_number_postfix' ) );
711
-    $postfix          = sanitize_text_field( apply_filters( 'getpaid_invoice_type_postfix', $postfix, $type ) );
712
-    $formatted_number = zeroise( absint( $number ), $padd );
707
+    $padd             = absint((int) wpinv_get_option('invoice_number_padd', 5));
708
+    $prefix           = sanitize_text_field((string) wpinv_get_option('invoice_number_prefix', 'INV-'));
709
+    $prefix           = sanitize_text_field(apply_filters('getpaid_invoice_type_prefix', $prefix, $type));
710
+    $postfix          = sanitize_text_field((string) wpinv_get_option('invoice_number_postfix'));
711
+    $postfix          = sanitize_text_field(apply_filters('getpaid_invoice_type_postfix', $postfix, $type));
712
+    $formatted_number = zeroise(absint($number), $padd);
713 713
 
714 714
     // Add the prefix and post fix.
715 715
     $formatted_number = $prefix . $formatted_number . $postfix;
716 716
 
717
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
717
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
718 718
 }
719 719
 
720 720
 /**
@@ -723,58 +723,58 @@  discard block
 block discarded – undo
723 723
  * @param string $type.
724 724
  * @return int|null|bool
725 725
  */
726
-function wpinv_get_next_invoice_number( $type = '' ) {
726
+function wpinv_get_next_invoice_number($type = '') {
727 727
 
728 728
     // Allow plugins to overide this.
729
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
730
-    if ( null !== $check ) {
729
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
730
+    if (null !== $check) {
731 731
         return $check;
732 732
     }
733 733
 
734 734
     // Ensure sequential invoice numbers is active.
735
-    if ( ! wpinv_sequential_number_active() ) {
735
+    if (!wpinv_sequential_number_active()) {
736 736
         return false;
737 737
     }
738 738
 
739 739
     // Retrieve the current number and the start number.
740
-    $number = (int) get_option( 'wpinv_last_invoice_number', 0 );
741
-    $start  = absint( (int) wpinv_get_option( 'invoice_sequence_start', 1 ) );
740
+    $number = (int) get_option('wpinv_last_invoice_number', 0);
741
+    $start  = absint((int) wpinv_get_option('invoice_sequence_start', 1));
742 742
 
743 743
     // Ensure that we are starting at a positive integer.
744
-    $start  = max( $start, 1 );
744
+    $start  = max($start, 1);
745 745
 
746 746
     // If this is the first invoice, use the start number.
747
-    $number = max( $start, $number );
747
+    $number = max($start, $number);
748 748
 
749 749
     // Format the invoice number.
750
-    $formatted_number = wpinv_format_invoice_number( $number, $type );
750
+    $formatted_number = wpinv_format_invoice_number($number, $type);
751 751
 
752 752
     // Ensure that this number is unique.
753
-    $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $formatted_number, 'number' );
753
+    $invoice_id = WPInv_Invoice::get_invoice_id_by_field($formatted_number, 'number');
754 754
 
755 755
     // We found a match. Nice.
756
-    if ( empty( $invoice_id ) ) {
757
-        update_option( 'wpinv_last_invoice_number', $number );
758
-        return apply_filters( 'wpinv_get_next_invoice_number', $number );
756
+    if (empty($invoice_id)) {
757
+        update_option('wpinv_last_invoice_number', $number);
758
+        return apply_filters('wpinv_get_next_invoice_number', $number);
759 759
     }
760 760
 
761
-    update_option( 'wpinv_last_invoice_number', $number + 1 );
762
-    return wpinv_get_next_invoice_number( $type );
761
+    update_option('wpinv_last_invoice_number', $number + 1);
762
+    return wpinv_get_next_invoice_number($type);
763 763
 
764 764
 }
765 765
 
766 766
 /**
767 767
  * The prefix used for invoice paths.
768 768
  */
769
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
770
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
769
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
770
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
771 771
 }
772 772
 
773
-function wpinv_generate_post_name( $post_ID ) {
774
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
775
-    $post_name = sanitize_title( $prefix . $post_ID );
773
+function wpinv_generate_post_name($post_ID) {
774
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
775
+    $post_name = sanitize_title($prefix . $post_ID);
776 776
 
777
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
777
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
778 778
 }
779 779
 
780 780
 /**
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
  *
783 783
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
784 784
  */
785
-function wpinv_is_invoice_viewed( $invoice ) {
786
-    $invoice = new WPInv_Invoice( $invoice );
785
+function wpinv_is_invoice_viewed($invoice) {
786
+    $invoice = new WPInv_Invoice($invoice);
787 787
     return (bool) $invoice->get_is_viewed();
788 788
 }
789 789
 
@@ -792,17 +792,17 @@  discard block
 block discarded – undo
792 792
  *
793 793
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
794 794
  */
795
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
796
-    $invoice = new WPInv_Invoice( $invoice );
795
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
796
+    $invoice = new WPInv_Invoice($invoice);
797 797
 
798
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
799
-        $invoice->set_is_viewed( true );
798
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
799
+        $invoice->set_is_viewed(true);
800 800
         $invoice->save();
801 801
     }
802 802
 
803 803
 }
804
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
805
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
804
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
805
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
806 806
 
807 807
 /**
808 808
  * Processes an invoice refund.
@@ -811,26 +811,26 @@  discard block
 block discarded – undo
811 811
  * @param array $status_transition
812 812
  * @todo: descrease customer/store earnings
813 813
  */
814
-function getpaid_maybe_process_refund( $invoice, $status_transition ) {
814
+function getpaid_maybe_process_refund($invoice, $status_transition) {
815 815
 
816
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
816
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
817 817
         return;
818 818
     }
819 819
 
820 820
     $discount_code = $invoice->get_discount_code();
821
-    if ( ! empty( $discount_code ) ) {
822
-        $discount = wpinv_get_discount_obj( $discount_code );
821
+    if (!empty($discount_code)) {
822
+        $discount = wpinv_get_discount_obj($discount_code);
823 823
 
824
-        if ( $discount->exists() ) {
824
+        if ($discount->exists()) {
825 825
             $discount->increase_usage( -1 );
826 826
         }
827 827
 }
828 828
 
829
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice->get_id() );
830
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice->get_id() );
831
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice->get_id() );
829
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice->get_id());
830
+    do_action('wpinv_refund_invoice', $invoice, $invoice->get_id());
831
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice->get_id());
832 832
 }
833
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2 );
833
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 2);
834 834
 
835 835
 
836 836
 /**
@@ -838,47 +838,47 @@  discard block
 block discarded – undo
838 838
  *
839 839
  * @param int $invoice_id
840 840
  */
841
-function getpaid_process_invoice_payment( $invoice_id ) {
841
+function getpaid_process_invoice_payment($invoice_id) {
842 842
 
843 843
     // Fetch the invoice.
844
-    $invoice = new WPInv_Invoice( $invoice_id );
844
+    $invoice = new WPInv_Invoice($invoice_id);
845 845
 
846 846
     // We only want to do this once.
847
-    if ( 1 == get_post_meta( $invoice->get_id(), 'wpinv_processed_payment', true ) ) {
847
+    if (1 == get_post_meta($invoice->get_id(), 'wpinv_processed_payment', true)) {
848 848
         return;
849 849
     }
850 850
 
851
-    update_post_meta( $invoice->get_id(), 'wpinv_processed_payment', 1 );
851
+    update_post_meta($invoice->get_id(), 'wpinv_processed_payment', 1);
852 852
 
853 853
     // Fires when processing a payment.
854
-    do_action( 'getpaid_process_payment', $invoice );
854
+    do_action('getpaid_process_payment', $invoice);
855 855
 
856 856
     // Fire an action for each invoice item.
857
-    foreach ( $invoice->get_items() as $item ) {
858
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
857
+    foreach ($invoice->get_items() as $item) {
858
+        do_action('getpaid_process_item_payment', $item, $invoice);
859 859
     }
860 860
 
861 861
     // Increase discount usage.
862 862
     $discount_code = $invoice->get_discount_code();
863
-    if ( ! empty( $discount_code ) && ! $invoice->is_renewal() ) {
864
-        $discount = wpinv_get_discount_obj( $discount_code );
863
+    if (!empty($discount_code) && !$invoice->is_renewal()) {
864
+        $discount = wpinv_get_discount_obj($discount_code);
865 865
 
866
-        if ( $discount->exists() ) {
866
+        if ($discount->exists()) {
867 867
             $discount->increase_usage();
868 868
         }
869 869
 }
870 870
 
871 871
     // Record reverse vat.
872
-    if ( 'invoice' === $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
872
+    if ('invoice' === $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
873 873
 
874 874
         $taxes = $invoice->get_total_tax();
875
-        if ( empty( $taxes ) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction( $invoice->get_country() ) ) {
876
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
875
+        if (empty($taxes) && GetPaid_Payment_Form_Submission_Taxes::is_eu_transaction($invoice->get_country())) {
876
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
877 877
         }
878 878
 }
879 879
 
880 880
 }
881
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
881
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
882 882
 
883 883
 /**
884 884
  * Returns an array of invoice item columns
@@ -886,13 +886,13 @@  discard block
 block discarded – undo
886 886
  * @param int|WPInv_Invoice $invoice
887 887
  * @return array
888 888
  */
889
-function getpaid_invoice_item_columns( $invoice ) {
889
+function getpaid_invoice_item_columns($invoice) {
890 890
 
891 891
     // Prepare the invoice.
892
-    $invoice = new WPInv_Invoice( $invoice );
892
+    $invoice = new WPInv_Invoice($invoice);
893 893
 
894 894
     // Abort if there is no invoice.
895
-    if ( 0 == $invoice->get_id() ) {
895
+    if (0 == $invoice->get_id()) {
896 896
         return array();
897 897
     }
898 898
 
@@ -900,52 +900,52 @@  discard block
 block discarded – undo
900 900
     $columns = apply_filters(
901 901
         'getpaid_invoice_item_columns',
902 902
         array(
903
-            'name'     => __( 'Item', 'invoicing' ),
904
-            'price'    => __( 'Price', 'invoicing' ),
905
-            'tax_rate' => __( 'Tax Rate', 'invoicing' ),
906
-            'quantity' => __( 'Quantity', 'invoicing' ),
907
-            'subtotal' => __( 'Item Subtotal', 'invoicing' ),
903
+            'name'     => __('Item', 'invoicing'),
904
+            'price'    => __('Price', 'invoicing'),
905
+            'tax_rate' => __('Tax Rate', 'invoicing'),
906
+            'quantity' => __('Quantity', 'invoicing'),
907
+            'subtotal' => __('Item Subtotal', 'invoicing'),
908 908
         ),
909 909
         $invoice
910 910
     );
911 911
 
912 912
     // Quantities.
913
-    if ( isset( $columns['quantity'] ) ) {
913
+    if (isset($columns['quantity'])) {
914 914
 
915
-        if ( 'hours' == $invoice->get_template() ) {
916
-            $columns['quantity'] = __( 'Hours', 'invoicing' );
915
+        if ('hours' == $invoice->get_template()) {
916
+            $columns['quantity'] = __('Hours', 'invoicing');
917 917
         }
918 918
 
919
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
920
-            unset( $columns['quantity'] );
919
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
920
+            unset($columns['quantity']);
921 921
         }
922 922
     }
923 923
 
924 924
     // Price.
925
-    if ( isset( $columns['price'] ) ) {
925
+    if (isset($columns['price'])) {
926 926
 
927
-        if ( 'amount' == $invoice->get_template() ) {
928
-            $columns['price'] = __( 'Amount', 'invoicing' );
927
+        if ('amount' == $invoice->get_template()) {
928
+            $columns['price'] = __('Amount', 'invoicing');
929 929
         }
930 930
 
931
-        if ( 'hours' == $invoice->get_template() ) {
932
-            $columns['price'] = __( 'Rate', 'invoicing' );
931
+        if ('hours' == $invoice->get_template()) {
932
+            $columns['price'] = __('Rate', 'invoicing');
933 933
         }
934 934
 }
935 935
 
936 936
     // Sub total.
937
-    if ( isset( $columns['subtotal'] ) ) {
937
+    if (isset($columns['subtotal'])) {
938 938
 
939
-        if ( 'amount' == $invoice->get_template() ) {
940
-            unset( $columns['subtotal'] );
939
+        if ('amount' == $invoice->get_template()) {
940
+            unset($columns['subtotal']);
941 941
         }
942 942
 }
943 943
 
944 944
     // Tax rates.
945
-    if ( isset( $columns['tax_rate'] ) ) {
945
+    if (isset($columns['tax_rate'])) {
946 946
 
947
-        if ( 0 == $invoice->get_total_tax() ) {
948
-            unset( $columns['tax_rate'] );
947
+        if (0 == $invoice->get_total_tax()) {
948
+            unset($columns['tax_rate']);
949 949
         }
950 950
     }
951 951
 
@@ -958,53 +958,53 @@  discard block
 block discarded – undo
958 958
  * @param int|WPInv_Invoice $invoice
959 959
  * @return array
960 960
  */
961
-function getpaid_invoice_totals_rows( $invoice ) {
961
+function getpaid_invoice_totals_rows($invoice) {
962 962
 
963 963
     // Prepare the invoice.
964
-    $invoice = new WPInv_Invoice( $invoice );
964
+    $invoice = new WPInv_Invoice($invoice);
965 965
 
966 966
     // Abort if there is no invoice.
967
-    if ( 0 == $invoice->get_id() ) {
967
+    if (0 == $invoice->get_id()) {
968 968
         return array();
969 969
     }
970 970
 
971 971
     $totals = apply_filters(
972 972
         'getpaid_invoice_totals_rows',
973 973
         array(
974
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
975
-            'shipping' => __( 'Shipping', 'invoicing' ),
976
-            'tax'      => __( 'Tax', 'invoicing' ),
977
-            'fee'      => __( 'Fee', 'invoicing' ),
978
-            'discount' => __( 'Discount', 'invoicing' ),
979
-            'total'    => __( 'Total', 'invoicing' ),
974
+            'subtotal' => __('Subtotal', 'invoicing'),
975
+            'shipping' => __('Shipping', 'invoicing'),
976
+            'tax'      => __('Tax', 'invoicing'),
977
+            'fee'      => __('Fee', 'invoicing'),
978
+            'discount' => __('Discount', 'invoicing'),
979
+            'total'    => __('Total', 'invoicing'),
980 980
         ),
981 981
         $invoice
982 982
     );
983 983
 
984
-    if ( ! $invoice->has_shipping() ) {
985
-        unset( $totals['shipping'] );
984
+    if (!$invoice->has_shipping()) {
985
+        unset($totals['shipping']);
986 986
     }
987 987
 
988
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
989
-        unset( $totals['tax'] );
988
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
989
+        unset($totals['tax']);
990 990
     }
991 991
 
992 992
     // If we have taxes, display individual taxes.
993
-    if ( isset( $totals['tax'] ) && wpinv_display_individual_tax_rates() ) {
993
+    if (isset($totals['tax']) && wpinv_display_individual_tax_rates()) {
994 994
 
995 995
         $new_totals = array();
996
-        foreach ( $totals as $key => $label ) {
996
+        foreach ($totals as $key => $label) {
997 997
 
998
-            if ( 'tax' !== $key ) {
999
-                $new_totals[ $key ] = $label;
998
+            if ('tax' !== $key) {
999
+                $new_totals[$key] = $label;
1000 1000
                 continue;
1001 1001
             }
1002 1002
 
1003
-            $taxes = array_keys( $invoice->get_taxes() );
1004
-            if ( ! empty( $taxes ) ) {
1003
+            $taxes = array_keys($invoice->get_taxes());
1004
+            if (!empty($taxes)) {
1005 1005
 
1006
-                foreach ( $taxes as $tax ) {
1007
-                    $new_totals[ 'tax__' . $tax ] = $tax;
1006
+                foreach ($taxes as $tax) {
1007
+                    $new_totals['tax__' . $tax] = $tax;
1008 1008
                 }
1009 1009
             }
1010 1010
         }
@@ -1012,12 +1012,12 @@  discard block
 block discarded – undo
1012 1012
         $totals = $new_totals;
1013 1013
     }
1014 1014
 
1015
-    if ( 0 == $invoice->get_total_fees() && isset( $totals['fee'] ) ) {
1016
-        unset( $totals['fee'] );
1015
+    if (0 == $invoice->get_total_fees() && isset($totals['fee'])) {
1016
+        unset($totals['fee']);
1017 1017
     }
1018 1018
 
1019
-    if ( 0 == $invoice->get_total_discount() && isset( $totals['discount'] ) ) {
1020
-        unset( $totals['discount'] );
1019
+    if (0 == $invoice->get_total_discount() && isset($totals['discount'])) {
1020
+        unset($totals['discount']);
1021 1021
     }
1022 1022
 
1023 1023
     return $totals;
@@ -1028,47 +1028,47 @@  discard block
 block discarded – undo
1028 1028
  *
1029 1029
  * @param WPInv_Invoice $invoice
1030 1030
  */
1031
-function getpaid_new_invoice( $invoice ) {
1031
+function getpaid_new_invoice($invoice) {
1032 1032
 
1033
-    if ( ! $invoice->get_status() ) {
1033
+    if (!$invoice->get_status()) {
1034 1034
         return;
1035 1035
     }
1036 1036
 
1037 1037
     // Add an invoice created note.
1038 1038
     $invoice->add_note(
1039 1039
         sprintf(
1040
-            __( '%1$s created with the status "%2$s".', 'invoicing' ),
1041
-            ucfirst( $invoice->get_invoice_quote_type() ),
1042
-            wpinv_status_nicename( $invoice->get_status(), $invoice )
1040
+            __('%1$s created with the status "%2$s".', 'invoicing'),
1041
+            ucfirst($invoice->get_invoice_quote_type()),
1042
+            wpinv_status_nicename($invoice->get_status(), $invoice)
1043 1043
         )
1044 1044
     );
1045 1045
 
1046 1046
 }
1047
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice' );
1047
+add_action('getpaid_new_invoice', 'getpaid_new_invoice');
1048 1048
 
1049 1049
 /**
1050 1050
  * This function updates invoice caches.
1051 1051
  *
1052 1052
  * @param WPInv_Invoice $invoice
1053 1053
  */
1054
-function getpaid_update_invoice_caches( $invoice ) {
1054
+function getpaid_update_invoice_caches($invoice) {
1055 1055
 
1056 1056
     // Cache invoice number.
1057
-    wp_cache_set( $invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids' );
1057
+    wp_cache_set($invoice->get_number(), $invoice->get_id(), 'getpaid_invoice_numbers_to_invoice_ids');
1058 1058
 
1059 1059
     // Cache invoice key.
1060
-    wp_cache_set( $invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids' );
1060
+    wp_cache_set($invoice->get_key(), $invoice->get_id(), 'getpaid_invoice_keys_to_invoice_ids');
1061 1061
 
1062 1062
     // (Maybe) cache transaction id.
1063 1063
     $transaction_id = $invoice->get_transaction_id();
1064 1064
 
1065
-    if ( ! empty( $transaction_id ) ) {
1066
-        wp_cache_set( $transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
1065
+    if (!empty($transaction_id)) {
1066
+        wp_cache_set($transaction_id, $invoice->get_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids');
1067 1067
     }
1068 1068
 
1069 1069
 }
1070
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5 );
1071
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5 );
1070
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5);
1071
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5);
1072 1072
 
1073 1073
 /**
1074 1074
  * Duplicates an invoice.
@@ -1078,7 +1078,7 @@  discard block
 block discarded – undo
1078 1078
  * @param  WPInv_Invoice $old_invoice The invoice to duplicate
1079 1079
  * @return WPInv_Invoice The new invoice.
1080 1080
  */
1081
-function getpaid_duplicate_invoice( $old_invoice ) {
1081
+function getpaid_duplicate_invoice($old_invoice) {
1082 1082
 
1083 1083
     // Create the new invoice.
1084 1084
     $invoice = new WPInv_Invoice();
@@ -1138,136 +1138,136 @@  discard block
 block discarded – undo
1138 1138
  * @param WPInv_Invoice $invoice
1139 1139
  * @return array
1140 1140
  */
1141
-function getpaid_get_invoice_meta( $invoice ) {
1141
+function getpaid_get_invoice_meta($invoice) {
1142 1142
 
1143 1143
     // Load the invoice meta.
1144 1144
     $meta = array(
1145 1145
 
1146 1146
         'number'         => array(
1147 1147
             'label' => sprintf(
1148
-                __( '%s Number', 'invoicing' ),
1149
-                ucfirst( $invoice->get_invoice_quote_type() )
1148
+                __('%s Number', 'invoicing'),
1149
+                ucfirst($invoice->get_invoice_quote_type())
1150 1150
             ),
1151
-            'value' => sanitize_text_field( $invoice->get_number() ),
1151
+            'value' => sanitize_text_field($invoice->get_number()),
1152 1152
         ),
1153 1153
 
1154 1154
         'status'         => array(
1155 1155
             'label' => sprintf(
1156
-                __( '%s Status', 'invoicing' ),
1157
-                ucfirst( $invoice->get_invoice_quote_type() )
1156
+                __('%s Status', 'invoicing'),
1157
+                ucfirst($invoice->get_invoice_quote_type())
1158 1158
             ),
1159 1159
             'value' => $invoice->get_status_label_html(),
1160 1160
         ),
1161 1161
 
1162 1162
         'date'           => array(
1163 1163
             'label' => sprintf(
1164
-                __( '%s Date', 'invoicing' ),
1165
-                ucfirst( $invoice->get_invoice_quote_type() )
1164
+                __('%s Date', 'invoicing'),
1165
+                ucfirst($invoice->get_invoice_quote_type())
1166 1166
             ),
1167
-            'value' => getpaid_format_date( $invoice->get_created_date() ),
1167
+            'value' => getpaid_format_date($invoice->get_created_date()),
1168 1168
         ),
1169 1169
 
1170 1170
         'date_paid'      => array(
1171
-            'label' => __( 'Paid On', 'invoicing' ),
1172
-            'value' => getpaid_format_date( $invoice->get_completed_date() ),
1171
+            'label' => __('Paid On', 'invoicing'),
1172
+            'value' => getpaid_format_date($invoice->get_completed_date()),
1173 1173
         ),
1174 1174
 
1175 1175
         'gateway'        => array(
1176
-            'label' => __( 'Payment Method', 'invoicing' ),
1177
-            'value' => sanitize_text_field( $invoice->get_gateway_title() ),
1176
+            'label' => __('Payment Method', 'invoicing'),
1177
+            'value' => sanitize_text_field($invoice->get_gateway_title()),
1178 1178
         ),
1179 1179
 
1180 1180
         'transaction_id' => array(
1181
-            'label' => __( 'Transaction ID', 'invoicing' ),
1182
-            'value' => sanitize_text_field( $invoice->get_transaction_id() ),
1181
+            'label' => __('Transaction ID', 'invoicing'),
1182
+            'value' => sanitize_text_field($invoice->get_transaction_id()),
1183 1183
         ),
1184 1184
 
1185 1185
         'due_date'       => array(
1186
-            'label' => __( 'Due Date', 'invoicing' ),
1187
-            'value' => getpaid_format_date( $invoice->get_due_date() ),
1186
+            'label' => __('Due Date', 'invoicing'),
1187
+            'value' => getpaid_format_date($invoice->get_due_date()),
1188 1188
         ),
1189 1189
 
1190 1190
         'vat_number'     => array(
1191
-            'label' => __( 'VAT Number', 'invoicing' ),
1192
-            'value' => sanitize_text_field( $invoice->get_vat_number() ),
1191
+            'label' => __('VAT Number', 'invoicing'),
1192
+            'value' => sanitize_text_field($invoice->get_vat_number()),
1193 1193
         ),
1194 1194
 
1195 1195
     );
1196 1196
 
1197
-    $additional_meta = get_post_meta( $invoice->get_id(), 'additional_meta_data', true );
1197
+    $additional_meta = get_post_meta($invoice->get_id(), 'additional_meta_data', true);
1198 1198
 
1199
-    if ( ! empty( $additional_meta ) ) {
1199
+    if (!empty($additional_meta)) {
1200 1200
 
1201
-        foreach ( $additional_meta as $label => $value ) {
1202
-            $meta[ sanitize_key( $label ) ] = array(
1203
-                'label' => esc_html( $label ),
1204
-                'value' => esc_html( $value ),
1201
+        foreach ($additional_meta as $label => $value) {
1202
+            $meta[sanitize_key($label)] = array(
1203
+                'label' => esc_html($label),
1204
+                'value' => esc_html($value),
1205 1205
             );
1206 1206
         }
1207 1207
 }
1208 1208
     // If it is not paid, remove the date of payment.
1209
-    if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
1210
-        unset( $meta['date_paid'] );
1211
-        unset( $meta['transaction_id'] );
1209
+    if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1210
+        unset($meta['date_paid']);
1211
+        unset($meta['transaction_id']);
1212 1212
     }
1213 1213
 
1214
-    if ( ! $invoice->is_paid() || 'none' == $invoice->get_gateway() ) {
1215
-        unset( $meta['gateway'] );
1214
+    if (!$invoice->is_paid() || 'none' == $invoice->get_gateway()) {
1215
+        unset($meta['gateway']);
1216 1216
     }
1217 1217
 
1218 1218
     // Only display the due date if due dates are enabled.
1219
-    if ( ! $invoice->needs_payment() || ! wpinv_get_option( 'overdue_active' ) ) {
1220
-        unset( $meta['due_date'] );
1219
+    if (!$invoice->needs_payment() || !wpinv_get_option('overdue_active')) {
1220
+        unset($meta['due_date']);
1221 1221
     }
1222 1222
 
1223 1223
     // Only display the vat number if taxes are enabled.
1224
-    if ( ! wpinv_use_taxes() ) {
1225
-        unset( $meta['vat_number'] );
1224
+    if (!wpinv_use_taxes()) {
1225
+        unset($meta['vat_number']);
1226 1226
     }
1227 1227
 
1228 1228
     // Link to the parent invoice.
1229
-    if ( $invoice->get_parent_id() > 0 ) {
1229
+    if ($invoice->get_parent_id() > 0) {
1230 1230
 
1231 1231
         $meta['parent'] = array(
1232 1232
 
1233 1233
             'label' => sprintf(
1234
-                __( 'Parent %s', 'invoicing' ),
1235
-                ucfirst( $invoice->get_invoice_quote_type() )
1234
+                __('Parent %s', 'invoicing'),
1235
+                ucfirst($invoice->get_invoice_quote_type())
1236 1236
             ),
1237 1237
 
1238
-            'value' => wpinv_invoice_link( $invoice->get_parent_id() ),
1238
+            'value' => wpinv_invoice_link($invoice->get_parent_id()),
1239 1239
 
1240 1240
         );
1241 1241
 
1242 1242
     }
1243 1243
 
1244
-    if ( $invoice->is_recurring() ) {
1244
+    if ($invoice->is_recurring()) {
1245 1245
 
1246
-        $subscription = getpaid_get_invoice_subscriptions( $invoice );
1247
-        if ( ! empty( $subscription ) && ! is_array( $subscription ) && $subscription->exists() ) {
1246
+        $subscription = getpaid_get_invoice_subscriptions($invoice);
1247
+        if (!empty($subscription) && !is_array($subscription) && $subscription->exists()) {
1248 1248
 
1249 1249
             // Display the renewal date.
1250
-            if ( $subscription->is_active() && 'cancelled' != $subscription->get_status() ) {
1250
+            if ($subscription->is_active() && 'cancelled' != $subscription->get_status()) {
1251 1251
 
1252 1252
                 $meta['renewal_date'] = array(
1253
-                    'label' => __( 'Renews On', 'invoicing' ),
1254
-                    'value' => getpaid_format_date( $subscription->get_expiration() ) .
1253
+                    'label' => __('Renews On', 'invoicing'),
1254
+                    'value' => getpaid_format_date($subscription->get_expiration()) .
1255 1255
                     sprintf(
1256 1256
                         ' <a class="small" href="%s">%s<a>',
1257 1257
                         $subscription->get_view_url(),
1258
-                        __( '(View Subscription)', 'invoicing' )
1258
+                        __('(View Subscription)', 'invoicing')
1259 1259
                     ),
1260 1260
                 );
1261 1261
 
1262 1262
             }
1263 1263
 
1264
-            if ( $invoice->is_parent() ) {
1264
+            if ($invoice->is_parent()) {
1265 1265
 
1266 1266
                 // Display the recurring amount.
1267 1267
                 $meta['recurring_total'] = array(
1268 1268
 
1269
-                    'label' => __( 'Recurring Amount', 'invoicing' ),
1270
-                    'value' => wpinv_price( $subscription->get_recurring_amount(), $invoice->get_currency() ),
1269
+                    'label' => __('Recurring Amount', 'invoicing'),
1270
+                    'value' => wpinv_price($subscription->get_recurring_amount(), $invoice->get_currency()),
1271 1271
 
1272 1272
                 );
1273 1273
 
@@ -1278,13 +1278,13 @@  discard block
 block discarded – undo
1278 1278
     // Add the invoice total to the meta.
1279 1279
     $meta['invoice_total'] = array(
1280 1280
 
1281
-        'label' => __( 'Total Amount', 'invoicing' ),
1282
-        'value' => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
1281
+        'label' => __('Total Amount', 'invoicing'),
1282
+        'value' => wpinv_price($invoice->get_total(), $invoice->get_currency()),
1283 1283
 
1284 1284
     );
1285 1285
 
1286 1286
     // Provide a way for third party plugins to filter the meta.
1287
-    $meta = apply_filters( 'getpaid_invoice_meta_data', $meta, $invoice );
1287
+    $meta = apply_filters('getpaid_invoice_meta_data', $meta, $invoice);
1288 1288
 
1289 1289
     return $meta;
1290 1290
 
@@ -1323,12 +1323,12 @@  discard block
 block discarded – undo
1323 1323
  * @param GetPaid_Form_Item $item
1324 1324
  * @return float
1325 1325
  */
1326
-function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1326
+function getpaid_get_invoice_tax_rate($invoice, $item) {
1327 1327
 
1328
-    $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1329
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1330
-    $rates   = wp_list_pluck( $rates, 'rate' );
1328
+    $rates   = getpaid_get_item_tax_rates($item, $invoice->get_country(), $invoice->get_state());
1329
+	$rates = getpaid_filter_item_tax_rates($item, $rates);
1330
+    $rates   = wp_list_pluck($rates, 'rate');
1331 1331
 
1332
-    return array_sum( $rates );
1332
+    return array_sum($rates);
1333 1333
 
1334 1334
 }
Please login to merge, or discard this patch.
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69 69
 function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
70
+    return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
71 71
 }
72 72
 
73 73
 /**
@@ -556,37 +556,37 @@  discard block
 block discarded – undo
556 556
     $label   = empty( $label ) ? __( 'Invoice', 'invoicing' ) : sanitize_text_field( $label );
557 557
     $columns = array(
558 558
 
559
-		'invoice-number'  => array(
560
-			'title' => $label,
561
-			'class' => 'text-left',
562
-		),
559
+        'invoice-number'  => array(
560
+            'title' => $label,
561
+            'class' => 'text-left',
562
+        ),
563 563
 
564
-		'created-date'    => array(
565
-			'title' => __( 'Created Date', 'invoicing' ),
566
-			'class' => 'text-left',
567
-		),
564
+        'created-date'    => array(
565
+            'title' => __( 'Created Date', 'invoicing' ),
566
+            'class' => 'text-left',
567
+        ),
568 568
 
569
-		'payment-date'    => array(
570
-			'title' => __( 'Payment Date', 'invoicing' ),
571
-			'class' => 'text-left',
572
-		),
569
+        'payment-date'    => array(
570
+            'title' => __( 'Payment Date', 'invoicing' ),
571
+            'class' => 'text-left',
572
+        ),
573 573
 
574
-		'invoice-status'  => array(
575
-			'title' => __( 'Status', 'invoicing' ),
576
-			'class' => 'text-center',
577
-		),
574
+        'invoice-status'  => array(
575
+            'title' => __( 'Status', 'invoicing' ),
576
+            'class' => 'text-center',
577
+        ),
578 578
 
579
-		'invoice-total'   => array(
580
-			'title' => __( 'Total', 'invoicing' ),
581
-			'class' => 'text-right',
582
-		),
579
+        'invoice-total'   => array(
580
+            'title' => __( 'Total', 'invoicing' ),
581
+            'class' => 'text-right',
582
+        ),
583 583
 
584
-		'invoice-actions' => array(
585
-			'title' => '&nbsp;',
586
-			'class' => 'text-center',
587
-		),
584
+        'invoice-actions' => array(
585
+            'title' => '&nbsp;',
586
+            'class' => 'text-center',
587
+        ),
588 588
 
589
-	);
589
+    );
590 590
 
591 591
     return apply_filters( 'wpinv_user_invoices_columns', $columns, $post_type );
592 592
 }
@@ -1297,22 +1297,22 @@  discard block
 block discarded – undo
1297 1297
  */
1298 1298
 function getpaid_get_invoice_status_classes() {
1299 1299
 
1300
-	return apply_filters(
1301
-		'getpaid_get_invoice_status_classes',
1302
-		array(
1300
+    return apply_filters(
1301
+        'getpaid_get_invoice_status_classes',
1302
+        array(
1303 1303
             'wpi-quote-declined' => 'bg-danger',
1304 1304
             'wpi-failed'         => 'bg-danger',
1305
-			'wpi-processing'     => 'bg-info',
1306
-			'wpi-onhold'         => 'bg-warning text-dark',
1307
-			'wpi-quote-accepted' => 'bg-success',
1308
-			'publish'            => 'bg-success',
1309
-			'wpi-renewal'        => 'bg-primary',
1305
+            'wpi-processing'     => 'bg-info',
1306
+            'wpi-onhold'         => 'bg-warning text-dark',
1307
+            'wpi-quote-accepted' => 'bg-success',
1308
+            'publish'            => 'bg-success',
1309
+            'wpi-renewal'        => 'bg-primary',
1310 1310
             'wpi-cancelled'      => 'bg-secondary',
1311 1311
             'wpi-pending'        => 'bg-dark text-white',
1312 1312
             'wpi-quote-pending'  => 'bg-dark text-white',
1313 1313
             'wpi-refunded'       => 'bg-secondary',
1314
-		)
1315
-	);
1314
+        )
1315
+    );
1316 1316
 
1317 1317
 }
1318 1318
 
@@ -1326,7 +1326,7 @@  discard block
 block discarded – undo
1326 1326
 function getpaid_get_invoice_tax_rate( $invoice, $item ) {
1327 1327
 
1328 1328
     $rates   = getpaid_get_item_tax_rates( $item, $invoice->get_country(), $invoice->get_state() );
1329
-	$rates   = getpaid_filter_item_tax_rates( $item, $rates );
1329
+    $rates   = getpaid_filter_item_tax_rates( $item, $rates );
1330 1330
     $rates   = wp_list_pluck( $rates, 'rate' );
1331 1331
 
1332 1332
     return array_sum( $rates );
Please login to merge, or discard this patch.