Passed
Branch master (3a0618)
by Stiofan
05:00
created
includes/wpinv-subscription.php 2 patches
Indentation   +1035 added lines, -1035 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id'
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id'
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,34 +141,34 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
-	}
158
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
+    }
163 163
 
164
-	/**
164
+    /**
165 165
      * Checks if a subscription key is set.
166 166
      */
167 167
     public function _isset( $key ) {
168 168
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
169
-	}
169
+    }
170 170
 
171
-	/*
171
+    /*
172 172
 	|--------------------------------------------------------------------------
173 173
 	| CRUD methods
174 174
 	|--------------------------------------------------------------------------
@@ -177,545 +177,545 @@  discard block
 block discarded – undo
177 177
 	|
178 178
     */
179 179
 
180
-	/*
181
-	|--------------------------------------------------------------------------
182
-	| Getters
183
-	|--------------------------------------------------------------------------
184
-	*/
180
+    /*
181
+	|--------------------------------------------------------------------------
182
+	| Getters
183
+	|--------------------------------------------------------------------------
184
+	*/
185
+
186
+    /**
187
+     * Get customer id.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return int
192
+     */
193
+    public function get_customer_id( $context = 'view' ) {
194
+        return (int) $this->get_prop( 'customer_id', $context );
195
+    }
196
+
197
+    /**
198
+     * Get customer information.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return WP_User|false WP_User object on success, false on failure.
203
+     */
204
+    public function get_customer( $context = 'view' ) {
205
+        return get_userdata( $this->get_customer_id( $context ) );
206
+    }
207
+
208
+    /**
209
+     * Get parent invoice id.
210
+     *
211
+     * @since 1.0.19
212
+     * @param  string $context View or edit context.
213
+     * @return int
214
+     */
215
+    public function get_parent_invoice_id( $context = 'view' ) {
216
+        return (int) $this->get_prop( 'parent_payment_id', $context );
217
+    }
218
+
219
+    /**
220
+     * Alias for self::get_parent_invoice_id().
221
+     *
222
+     * @since 1.0.19
223
+     * @param  string $context View or edit context.
224
+     * @return int
225
+     */
226
+    public function get_parent_payment_id( $context = 'view' ) {
227
+        return $this->get_parent_invoice_id( $context );
228
+    }
229
+
230
+    /**
231
+     * Alias for self::get_parent_invoice_id().
232
+     *
233
+     * @since  1.0.0
234
+     * @return int
235
+     */
236
+    public function get_original_payment_id( $context = 'view' ) {
237
+        return $this->get_parent_invoice_id( $context );
238
+    }
239
+
240
+    /**
241
+     * Get parent invoice.
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return WPInv_Invoice
246
+     */
247
+    public function get_parent_invoice( $context = 'view' ) {
248
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+    }
250
+
251
+    /**
252
+     * Alias for self::get_parent_invoice().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return WPInv_Invoice
257
+     */
258
+    public function get_parent_payment( $context = 'view' ) {
259
+        return $this->get_parent_invoice( $context );
260
+    }
261
+
262
+    /**
263
+     * Get subscription's product id.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return int
268
+     */
269
+    public function get_product_id( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'product_id', $context );
271
+    }
272
+
273
+    /**
274
+     * Get the subscription product.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return WPInv_Item
279
+     */
280
+    public function get_product( $context = 'view' ) {
281
+        return new WPInv_Item( $this->get_product_id( $context ) );
282
+    }
283
+
284
+    /**
285
+     * Get parent invoice's gateway.
286
+     *
287
+     * Here for backwards compatibility.
288
+     *
289
+     * @since 1.0.19
290
+     * @param  string $context View or edit context.
291
+     * @return string
292
+     */
293
+    public function get_gateway( $context = 'view' ) {
294
+        return $this->get_parent_invoice( $context )->get_gateway();
295
+    }
296
+
297
+    /**
298
+     * Get the period of a renewal.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_period( $context = 'view' ) {
305
+        return $this->get_prop( 'period', $context );
306
+    }
307
+
308
+    /**
309
+     * Get number of periods each renewal is valid for.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return int
314
+     */
315
+    public function get_frequency( $context = 'view' ) {
316
+        return (int) $this->get_prop( 'frequency', $context );
317
+    }
318
+
319
+    /**
320
+     * Get the initial amount for the subscription.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return float
325
+     */
326
+    public function get_initial_amount( $context = 'view' ) {
327
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+    }
329
+
330
+    /**
331
+     * Get the recurring amount for the subscription.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return float
336
+     */
337
+    public function get_recurring_amount( $context = 'view' ) {
338
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+    }
340
+
341
+    /**
342
+     * Get number of times that this subscription can be renewed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  string $context View or edit context.
346
+     * @return int
347
+     */
348
+    public function get_bill_times( $context = 'view' ) {
349
+        return (int) $this->get_prop( 'bill_times', $context );
350
+    }
351
+
352
+    /**
353
+     * Get transaction id of this subscription's parent invoice.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  string $context View or edit context.
357
+     * @return string
358
+     */
359
+    public function get_transaction_id( $context = 'view' ) {
360
+        return $this->get_prop( 'transaction_id', $context );
361
+    }
362
+
363
+    /**
364
+     * Get the date that the subscription was created.
365
+     *
366
+     * @since 1.0.19
367
+     * @param  string $context View or edit context.
368
+     * @return string
369
+     */
370
+    public function get_created( $context = 'view' ) {
371
+        return $this->get_prop( 'created', $context );
372
+    }
373
+
374
+    /**
375
+     * Alias for self::get_created().
376
+     *
377
+     * @since 1.0.19
378
+     * @param  string $context View or edit context.
379
+     * @return string
380
+     */
381
+    public function get_date_created( $context = 'view' ) {
382
+        return $this->get_created( $context );
383
+    }
384
+
385
+    /**
386
+     * Retrieves the creation date in a timestamp
387
+     *
388
+     * @since  1.0.0
389
+     * @return int
390
+     */
391
+    public function get_time_created() {
392
+        $created = $this->get_date_created();
393
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
+    }
395
+
396
+    /**
397
+     * Get GMT date when the subscription was created.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_created_gmt( $context = 'view' ) {
404
+        $date = $this->get_date_created( $context );
405
+
406
+        if ( $date ) {
407
+            $date = get_gmt_from_date( $date );
408
+        }
409
+        return $date;
410
+    }
411
+
412
+    /**
413
+     * Get the date that the subscription will renew.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return string
418
+     */
419
+    public function get_next_renewal_date( $context = 'view' ) {
420
+        return $this->get_prop( 'expiration', $context );
421
+    }
422
+
423
+    /**
424
+     * Alias for self::get_next_renewal_date().
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return string
429
+     */
430
+    public function get_expiration( $context = 'view' ) {
431
+        return $this->get_next_renewal_date( $context );
432
+    }
433
+
434
+    /**
435
+     * Retrieves the expiration date in a timestamp
436
+     *
437
+     * @since  1.0.0
438
+     * @return int
439
+     */
440
+    public function get_expiration_time() {
441
+        $expiration = $this->get_expiration();
442
+
443
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
+            return current_time( 'timestamp' );
445
+        }
446
+
447
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+    }
450
+
451
+    /**
452
+     * Get GMT date when the subscription will renew.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
459
+        $date = $this->get_next_renewal_date( $context );
460
+
461
+        if ( $date ) {
462
+            $date = get_gmt_from_date( $date );
463
+        }
464
+        return $date;
465
+    }
466
+
467
+    /**
468
+     * Get the subscription's trial period.
469
+     *
470
+     * @since 1.0.19
471
+     * @param  string $context View or edit context.
472
+     * @return string
473
+     */
474
+    public function get_trial_period( $context = 'view' ) {
475
+        return $this->get_prop( 'trial_period', $context );
476
+    }
477
+
478
+    /**
479
+     * Get the subscription's status.
480
+     *
481
+     * @since 1.0.19
482
+     * @param  string $context View or edit context.
483
+     * @return string
484
+     */
485
+    public function get_status( $context = 'view' ) {
486
+        return $this->get_prop( 'status', $context );
487
+    }
488
+
489
+    /**
490
+     * Get the subscription's profile id.
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_profile_id( $context = 'view' ) {
497
+        return $this->get_prop( 'profile_id', $context );
498
+    }
499
+
500
+    /*
501
+	|--------------------------------------------------------------------------
502
+	| Setters
503
+	|--------------------------------------------------------------------------
504
+	*/
505
+
506
+    /**
507
+     * Set customer id.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  int $value The customer's id.
511
+     */
512
+    public function set_customer_id( $value ) {
513
+        $this->set_prop( 'customer_id', (int) $value );
514
+    }
515
+
516
+    /**
517
+     * Set parent invoice id.
518
+     *
519
+     * @since 1.0.19
520
+     * @param  int $value The parent invoice id.
521
+     */
522
+    public function set_parent_invoice_id( $value ) {
523
+        $this->set_prop( 'parent_payment_id', (int) $value );
524
+    }
525
+
526
+    /**
527
+     * Alias for self::set_parent_invoice_id().
528
+     *
529
+     * @since 1.0.19
530
+     * @param  int $value The parent invoice id.
531
+     */
532
+    public function set_parent_payment_id( $value ) {
533
+        $this->set_parent_invoice_id( $value );
534
+    }
535
+
536
+    /**
537
+     * Alias for self::set_parent_invoice_id().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  int $value The parent invoice id.
541
+     */
542
+    public function set_original_payment_id( $value ) {
543
+        $this->set_parent_invoice_id( $value );
544
+    }
545
+
546
+    /**
547
+     * Set subscription's product id.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  int $value The subscription product id.
551
+     */
552
+    public function set_product_id( $value ) {
553
+        $this->set_prop( 'product_id', (int) $value );
554
+    }
555
+
556
+    /**
557
+     * Set the period of a renewal.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $value The renewal period.
561
+     */
562
+    public function set_period( $value ) {
563
+        $this->set_prop( 'period', $value );
564
+    }
565
+
566
+    /**
567
+     * Set number of periods each renewal is valid for.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  int $value The subscription frequency.
571
+     */
572
+    public function set_frequency( $value ) {
573
+        $value = empty( $value ) ? 1 : (int) $value;
574
+        $this->set_prop( 'frequency', absint( $value ) );
575
+    }
576
+
577
+    /**
578
+     * Set the initial amount for the subscription.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  float $value The initial subcription amount.
582
+     */
583
+    public function set_initial_amount( $value ) {
584
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+    }
586
+
587
+    /**
588
+     * Set the recurring amount for the subscription.
589
+     *
590
+     * @since 1.0.19
591
+     * @param  float $value The recurring subcription amount.
592
+     */
593
+    public function set_recurring_amount( $value ) {
594
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+    }
596
+
597
+    /**
598
+     * Set number of times that this subscription can be renewed.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  int $value Bill times.
602
+     */
603
+    public function set_bill_times( $value ) {
604
+        $this->set_prop( 'bill_times', (int) $value );
605
+    }
606
+
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
609
+     *
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
612
+     */
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
+    }
616
+
617
+    /**
618
+     * Set date when this subscription started.
619
+     *
620
+     * @since 1.0.19
621
+     * @param string $value strtotime compliant date.
622
+     */
623
+    public function set_created( $value ) {
624
+        $date = strtotime( $value );
625
+
626
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
+            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+            return;
629
+        }
630
+
631
+        $this->set_prop( 'created', '' );
185 632
 
186
-	/**
187
-	 * Get customer id.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return int
192
-	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
195
-	}
196
-
197
-	/**
198
-	 * Get customer information.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return WP_User|false WP_User object on success, false on failure.
203
-	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
206
-	}
207
-
208
-	/**
209
-	 * Get parent invoice id.
210
-	 *
211
-	 * @since 1.0.19
212
-	 * @param  string $context View or edit context.
213
-	 * @return int
214
-	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
-	}
218
-
219
-	/**
220
-	 * Alias for self::get_parent_invoice_id().
221
-	 *
222
-	 * @since 1.0.19
223
-	 * @param  string $context View or edit context.
224
-	 * @return int
225
-	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
228
-	}
633
+    }
229 634
 
230
-	/**
231
-     * Alias for self::get_parent_invoice_id().
635
+    /**
636
+     * Alias for self::set_created().
232 637
      *
233
-     * @since  1.0.0
234
-     * @return int
638
+     * @since 1.0.19
639
+     * @param string $value strtotime compliant date.
235 640
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
238 643
     }
239 644
 
240
-	/**
241
-	 * Get parent invoice.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return WPInv_Invoice
246
-	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
-	}
250
-
251
-	/**
252
-	 * Alias for self::get_parent_invoice().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return WPInv_Invoice
257
-	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
260
-	}
261
-
262
-	/**
263
-	 * Get subscription's product id.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return int
268
-	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
271
-	}
272
-
273
-	/**
274
-	 * Get the subscription product.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return WPInv_Item
279
-	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
-	}
283
-
284
-	/**
285
-	 * Get parent invoice's gateway.
286
-	 *
287
-	 * Here for backwards compatibility.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @param  string $context View or edit context.
291
-	 * @return string
292
-	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
295
-	}
296
-
297
-	/**
298
-	 * Get the period of a renewal.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
306
-	}
307
-
308
-	/**
309
-	 * Get number of periods each renewal is valid for.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return int
314
-	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
317
-	}
318
-
319
-	/**
320
-	 * Get the initial amount for the subscription.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return float
325
-	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
-	}
329
-
330
-	/**
331
-	 * Get the recurring amount for the subscription.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return float
336
-	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
-	}
340
-
341
-	/**
342
-	 * Get number of times that this subscription can be renewed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  string $context View or edit context.
346
-	 * @return int
347
-	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
350
-	}
351
-
352
-	/**
353
-	 * Get transaction id of this subscription's parent invoice.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  string $context View or edit context.
357
-	 * @return string
358
-	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
361
-	}
362
-
363
-	/**
364
-	 * Get the date that the subscription was created.
365
-	 *
366
-	 * @since 1.0.19
367
-	 * @param  string $context View or edit context.
368
-	 * @return string
369
-	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
372
-	}
373
-
374
-	/**
375
-	 * Alias for self::get_created().
376
-	 *
377
-	 * @since 1.0.19
378
-	 * @param  string $context View or edit context.
379
-	 * @return string
380
-	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
383
-	}
384
-
385
-	/**
386
-	 * Retrieves the creation date in a timestamp
387
-	 *
388
-	 * @since  1.0.0
389
-	 * @return int
390
-	 */
391
-	public function get_time_created() {
392
-		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
-	}
395
-
396
-	/**
397
-	 * Get GMT date when the subscription was created.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
645
+    /**
646
+     * Set the date that the subscription will renew.
647
+     *
648
+     * @since 1.0.19
649
+     * @param string $value strtotime compliant date.
650
+     */
651
+    public function set_next_renewal_date( $value ) {
652
+        $date = strtotime( $value );
405 653
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
654
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
+            return;
408 657
         }
409
-		return $date;
410
-	}
411
-
412
-	/**
413
-	 * Get the date that the subscription will renew.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return string
418
-	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
421
-	}
422
-
423
-	/**
424
-	 * Alias for self::get_next_renewal_date().
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return string
429
-	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
432
-	}
433
-
434
-	/**
435
-	 * Retrieves the expiration date in a timestamp
436
-	 *
437
-	 * @since  1.0.0
438
-	 * @return int
439
-	 */
440
-	public function get_expiration_time() {
441
-		$expiration = $this->get_expiration();
442
-
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
445
-		}
446
-
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
-	}
450
-
451
-	/**
452
-	 * Get GMT date when the subscription will renew.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
460 658
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
463
-        }
464
-		return $date;
465
-	}
466
-
467
-	/**
468
-	 * Get the subscription's trial period.
469
-	 *
470
-	 * @since 1.0.19
471
-	 * @param  string $context View or edit context.
472
-	 * @return string
473
-	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
476
-	}
477
-
478
-	/**
479
-	 * Get the subscription's status.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param  string $context View or edit context.
483
-	 * @return string
484
-	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
487
-	}
488
-
489
-	/**
490
-	 * Get the subscription's profile id.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
498
-	}
499
-
500
-	/*
501
-	|--------------------------------------------------------------------------
502
-	| Setters
503
-	|--------------------------------------------------------------------------
504
-	*/
659
+        $this->set_prop( 'expiration', '' );
505 660
 
506
-	/**
507
-	 * Set customer id.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  int $value The customer's id.
511
-	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
514
-	}
515
-
516
-	/**
517
-	 * Set parent invoice id.
518
-	 *
519
-	 * @since 1.0.19
520
-	 * @param  int $value The parent invoice id.
521
-	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
-	}
525
-
526
-	/**
527
-	 * Alias for self::set_parent_invoice_id().
528
-	 *
529
-	 * @since 1.0.19
530
-	 * @param  int $value The parent invoice id.
531
-	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
534
-	}
661
+    }
535 662
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
663
+    /**
664
+     * Alias for self::set_next_renewal_date().
538 665
      *
539 666
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
667
+     * @param string $value strtotime compliant date.
541 668
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
544
-	}
545
-
546
-	/**
547
-	 * Set subscription's product id.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  int $value The subscription product id.
551
-	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
554
-	}
555
-
556
-	/**
557
-	 * Set the period of a renewal.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $value The renewal period.
561
-	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
564
-	}
565
-
566
-	/**
567
-	 * Set number of periods each renewal is valid for.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  int $value The subscription frequency.
571
-	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
575
-	}
576
-
577
-	/**
578
-	 * Set the initial amount for the subscription.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  float $value The initial subcription amount.
582
-	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
-	}
586
-
587
-	/**
588
-	 * Set the recurring amount for the subscription.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param  float $value The recurring subcription amount.
592
-	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
-	}
596
-
597
-	/**
598
-	 * Set number of times that this subscription can be renewed.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  int $value Bill times.
602
-	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
605
-	}
606
-
607
-	/**
608
-	 * Get transaction id of this subscription's parent invoice.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param string $value Bill times.
612
-	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
-	}
616
-
617
-	/**
618
-	 * Set date when this subscription started.
619
-	 *
620
-	 * @since 1.0.19
621
-	 * @param string $value strtotime compliant date.
622
-	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
669
+    public function set_expiration( $value ) {
670
+        $this->set_next_renewal_date( $value );
671
+    }
625 672
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
673
+    /**
674
+     * Set the subscription's trial period.
675
+     *
676
+     * @since 1.0.19
677
+     * @param string $value trial period e.g 1 year.
678
+     */
679
+    public function set_trial_period( $value ) {
680
+        $this->set_prop( 'trial_period', $value );
681
+    }
682
+
683
+    /**
684
+     * Set the subscription's status.
685
+     *
686
+     * @since 1.0.19
687
+     * @param string $new_status    New subscription status.
688
+     */
689
+    public function set_status( $new_status ) {
690
+
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
628 693
             return;
629 694
         }
630 695
 
631
-		$this->set_prop( 'created', '' );
696
+        $old_status = $this->get_status();
697
+        $this->set_prop( 'status', $new_status );
632 698
 
633
-	}
699
+        if ( true === $this->object_read && $old_status !== $new_status ) {
700
+            $this->status_transition = array(
701
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
+                'to'     => $new_status,
703
+            );
704
+        }
634 705
 
635
-	/**
636
-	 * Alias for self::set_created().
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param string $value strtotime compliant date.
640
-	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
643 706
     }
644 707
 
645
-	/**
646
-	 * Set the date that the subscription will renew.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @param string $value strtotime compliant date.
650
-	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
708
+    /**
709
+     * Set the subscription's (remote) profile id.
710
+     *
711
+     * @since 1.0.19
712
+     * @param  string $value the remote profile id.
713
+     */
714
+    public function set_profile_id( $value ) {
715
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
+    }
653 717
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
-            return;
657
-		}
658
-
659
-		$this->set_prop( 'expiration', '' );
660
-
661
-	}
662
-
663
-	/**
664
-	 * Alias for self::set_next_renewal_date().
665
-	 *
666
-	 * @since 1.0.19
667
-	 * @param string $value strtotime compliant date.
668
-	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
671
-    }
672
-
673
-	/**
674
-	 * Set the subscription's trial period.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param string $value trial period e.g 1 year.
678
-	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
681
-	}
682
-
683
-	/**
684
-	 * Set the subscription's status.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param string $new_status    New subscription status.
688
-	 */
689
-	public function set_status( $new_status ) {
690
-
691
-		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
693
-			return;
694
-		}
695
-
696
-		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
698
-
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
700
-			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
-				'to'     => $new_status,
703
-			);
704
-		}
705
-
706
-	}
707
-
708
-	/**
709
-	 * Set the subscription's (remote) profile id.
710
-	 *
711
-	 * @since 1.0.19
712
-	 * @param  string $value the remote profile id.
713
-	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
-	}
717
-
718
-	/*
718
+    /*
719 719
 	|--------------------------------------------------------------------------
720 720
 	| Boolean methods
721 721
 	|--------------------------------------------------------------------------
@@ -724,55 +724,55 @@  discard block
 block discarded – undo
724 724
 	|
725 725
 	*/
726 726
 
727
-	/**
727
+    /**
728 728
      * Checks if the subscription has a given status.
729
-	 *
730
-	 * @param string|array String or array of strings to check for.
731
-	 * @return bool
729
+     *
730
+     * @param string|array String or array of strings to check for.
731
+     * @return bool
732 732
      */
733 733
     public function has_status( $status ) {
734 734
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
735
-	}
735
+    }
736 736
 
737
-	/**
737
+    /**
738 738
      * Checks if the subscription has a trial period.
739
-	 *
740
-	 * @return bool
739
+     *
740
+     * @return bool
741 741
      */
742 742
     public function has_trial_period() {
743
-		$period = $this->get_trial_period();
743
+        $period = $this->get_trial_period();
744 744
         return ! empty( $period );
745
-	}
746
-
747
-	/**
748
-	 * Is the subscription active?
749
-	 *
750
-	 * @return bool
751
-	 */
752
-	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
-	}
755
-
756
-	/**
757
-	 * Is the subscription expired?
758
-	 *
759
-	 * @return bool
760
-	 */
761
-	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
-	}
764
-
765
-	/**
766
-	 * Is this the last renewals?
767
-	 *
768
-	 * @return bool
769
-	 */
770
-	public function is_last_renewal() {
771
-		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
-	}
774
-
775
-	/*
745
+    }
746
+
747
+    /**
748
+     * Is the subscription active?
749
+     *
750
+     * @return bool
751
+     */
752
+    public function is_active() {
753
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
+    }
755
+
756
+    /**
757
+     * Is the subscription expired?
758
+     *
759
+     * @return bool
760
+     */
761
+    public function is_expired() {
762
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
+    }
764
+
765
+    /**
766
+     * Is this the last renewals?
767
+     *
768
+     * @return bool
769
+     */
770
+    public function is_last_renewal() {
771
+        $max_bills = $this->get_bill_times();
772
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
+    }
774
+
775
+    /*
776 776
 	|--------------------------------------------------------------------------
777 777
 	| Additional methods
778 778
 	|--------------------------------------------------------------------------
@@ -781,27 +781,27 @@  discard block
 block discarded – undo
781 781
 	|
782 782
 	*/
783 783
 
784
-	/**
785
-	 * Backwards compatibilty.
786
-	 */
787
-	public function create( $data = array() ) {
784
+    /**
785
+     * Backwards compatibilty.
786
+     */
787
+    public function create( $data = array() ) {
788 788
 
789
-		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
792
-		}
789
+        // Set the properties.
790
+        if ( is_array( $data ) ) {
791
+            $this->set_props( $data );
792
+        }
793 793
 
794
-		// Save the item.
795
-		return $this->save();
794
+        // Save the item.
795
+        return $this->save();
796 796
 
797
-	}
797
+    }
798 798
 
799
-	/**
800
-	 * Backwards compatibilty.
801
-	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
804
-	}
799
+    /**
800
+     * Backwards compatibilty.
801
+     */
802
+    public function update( $args = array() ) {
803
+        return $this->create( $args );
804
+    }
805 805
 
806 806
     /**
807 807
      * Retrieve renewal payments for a subscription
@@ -811,22 +811,22 @@  discard block
 block discarded – undo
811 811
      */
812 812
     public function get_child_payments( $hide_pending = true ) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
818
-		}
816
+        if ( ! $hide_pending ) {
817
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
818
+        }
819 819
 
820 820
         return get_posts(
821
-			array(
822
-            	'post_parent'    => $this->get_parent_payment_id(),
823
-            	'numberposts'    => -1,
824
-            	'post_status'    => $statuses,
825
-            	'orderby'        => 'ID',
826
-            	'order'          => 'ASC',
827
-            	'post_type'      => 'wpi_invoice'
828
-			)
829
-		);
821
+            array(
822
+                'post_parent'    => $this->get_parent_payment_id(),
823
+                'numberposts'    => -1,
824
+                'post_status'    => $statuses,
825
+                'orderby'        => 'ID',
826
+                'order'          => 'ASC',
827
+                'post_type'      => 'wpi_invoice'
828
+            )
829
+        );
830 830
     }
831 831
 
832 832
     /**
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
      * @return int
837 837
      */
838 838
     public function get_total_payments() {
839
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
839
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
840 840
     }
841 841
 
842 842
     /**
@@ -860,57 +860,57 @@  discard block
 block discarded – undo
860 860
      *
861 861
      * @since  2.4
862 862
      * @param  array $args Array of values for the payment, including amount and transaction ID
863
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
863
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
864 864
      * @return bool
865 865
      */
866 866
     public function add_payment( $args = array(), $invoice = false ) {
867 867
 
868
-		// Process each payment once.
868
+        // Process each payment once.
869 869
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
870 870
             return false;
871 871
         }
872 872
 
873
-		// Are we creating a new invoice?
874
-		if ( empty( $invoice ) ) {
875
-			$invoice = $this->create_payment();
873
+        // Are we creating a new invoice?
874
+        if ( empty( $invoice ) ) {
875
+            $invoice = $this->create_payment();
876 876
 
877
-			if ( empty( $invoice ) ) {
878
-				return false;
879
-			}
877
+            if ( empty( $invoice ) ) {
878
+                return false;
879
+            }
880 880
 
881
-		}
881
+        }
882 882
 
883
-		$invoice->set_status( 'wpi-renewal' );
883
+        $invoice->set_status( 'wpi-renewal' );
884 884
 
885
-		// Maybe set a transaction id.
886
-		if ( ! empty( $args['transaction_id'] ) ) {
887
-			$invoice->set_transaction_id( $args['transaction_id'] );
888
-		}
885
+        // Maybe set a transaction id.
886
+        if ( ! empty( $args['transaction_id'] ) ) {
887
+            $invoice->set_transaction_id( $args['transaction_id'] );
888
+        }
889 889
 
890
-		// Set the completed date.
891
-		$invoice->set_completed_date( current_time( 'mysql' ) );
890
+        // Set the completed date.
891
+        $invoice->set_completed_date( current_time( 'mysql' ) );
892 892
 
893
-		// And the gateway.
894
-		if ( ! empty( $args['gateway'] ) ) {
895
-			$invoice->set_gateway( $args['gateway'] );
896
-		}
893
+        // And the gateway.
894
+        if ( ! empty( $args['gateway'] ) ) {
895
+            $invoice->set_gateway( $args['gateway'] );
896
+        }
897 897
 
898
-		$invoice->save();
898
+        $invoice->save();
899 899
 
900
-		if ( ! $invoice->exists() ) {
901
-			return false;
902
-		}
900
+        if ( ! $invoice->exists() ) {
901
+            return false;
902
+        }
903 903
 
904
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
905
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
904
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
905
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
906 906
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
907 907
 
908 908
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
909 909
 
910 910
         return $invoice->get_id();
911
-	}
911
+    }
912 912
 
913
-	/**
913
+    /**
914 914
      * Creates a new invoice and returns it.
915 915
      *
916 916
      * @since  1.0.19
@@ -918,124 +918,124 @@  discard block
 block discarded – undo
918 918
      */
919 919
     public function create_payment() {
920 920
 
921
-		$parent_invoice = $this->get_parent_payment();
922
-
923
-		if ( ! $parent_invoice->exists() ) {
924
-			return false;
925
-		}
926
-
927
-		// Duplicate the parent invoice.
928
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
929
-		$invoice->set_parent_id( $parent_invoice->get_id() );
930
-		$invoice->set_subscription_id( $this->get_id() );
931
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
932
-
933
-		// Set invoice items.
934
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
935
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
936
-		$invoice_items      = array();
937
-
938
-		foreach ( $invoice->get_items() as $item ) {
939
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
940
-				$invoice_items[] = $item;
941
-			}
942
-		}
943
-
944
-		$invoice->set_items( $invoice_items );
945
-
946
-		if ( ! empty( $subscription_group['fees'] ) ) {
947
-			$invoice->set_fees( $subscription_group['fees'] );
948
-		}
949
-
950
-		// Maybe recalculate discount (Pre-GetPaid Fix).
951
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
952
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
953
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
954
-		}
955
-
956
-		$invoice->recalculate_total();
957
-		$invoice->set_status( 'wpi-pending' );
958
-		$invoice->save();
959
-
960
-		return $invoice->exists() ? $invoice : false;
961
-    }
962
-
963
-	/**
964
-	 * Renews or completes a subscription
965
-	 *
966
-	 * @since  1.0.0
967
-	 * @return int The subscription's id
968
-	 */
969
-	public function renew() {
970
-
971
-		// Complete subscription if applicable
972
-		if ( $this->is_last_renewal() ) {
973
-			return $this->complete();
974
-		}
975
-
976
-		// Calculate new expiration
977
-		$frequency      = $this->get_frequency();
978
-		$period         = $this->get_period();
979
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
980
-
981
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
982
-		$this->set_status( 'active' );
983
-		$this->save();
984
-
985
-		do_action( 'getpaid_subscription_renewed', $this );
986
-
987
-		return $this->get_id();
988
-	}
989
-
990
-	/**
991
-	 * Marks a subscription as completed
992
-	 *
993
-	 * Subscription is completed when the number of payments matches the billing_times field
994
-	 *
995
-	 * @since  1.0.0
996
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
997
-	 */
998
-	public function complete() {
999
-
1000
-		// Only mark a subscription as complete if it's not already cancelled.
1001
-		if ( $this->has_status( 'cancelled' ) ) {
1002
-			return false;
1003
-		}
1004
-
1005
-		$this->set_status( 'completed' );
1006
-		return $this->save();
1007
-
1008
-	}
1009
-
1010
-	/**
1011
-	 * Marks a subscription as expired
1012
-	 *
1013
-	 * @since  1.0.0
1014
-	 * @param  bool $check_expiration
1015
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1016
-	 */
1017
-	public function expire( $check_expiration = false ) {
1018
-
1019
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1020
-			// Do not mark as expired since real expiration date is in the future
1021
-			return false;
1022
-		}
1023
-
1024
-		$this->set_status( 'expired' );
1025
-		return $this->save();
1026
-
1027
-	}
1028
-
1029
-	/**
1030
-	 * Marks a subscription as failing
1031
-	 *
1032
-	 * @since  2.4.2
1033
-	 * @return int Subscription id.
1034
-	 */
1035
-	public function failing() {
1036
-		$this->set_status( 'failing' );
1037
-		return $this->save();
1038
-	}
921
+        $parent_invoice = $this->get_parent_payment();
922
+
923
+        if ( ! $parent_invoice->exists() ) {
924
+            return false;
925
+        }
926
+
927
+        // Duplicate the parent invoice.
928
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
929
+        $invoice->set_parent_id( $parent_invoice->get_id() );
930
+        $invoice->set_subscription_id( $this->get_id() );
931
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
932
+
933
+        // Set invoice items.
934
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
935
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
936
+        $invoice_items      = array();
937
+
938
+        foreach ( $invoice->get_items() as $item ) {
939
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
940
+                $invoice_items[] = $item;
941
+            }
942
+        }
943
+
944
+        $invoice->set_items( $invoice_items );
945
+
946
+        if ( ! empty( $subscription_group['fees'] ) ) {
947
+            $invoice->set_fees( $subscription_group['fees'] );
948
+        }
949
+
950
+        // Maybe recalculate discount (Pre-GetPaid Fix).
951
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
952
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
953
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
954
+        }
955
+
956
+        $invoice->recalculate_total();
957
+        $invoice->set_status( 'wpi-pending' );
958
+        $invoice->save();
959
+
960
+        return $invoice->exists() ? $invoice : false;
961
+    }
962
+
963
+    /**
964
+     * Renews or completes a subscription
965
+     *
966
+     * @since  1.0.0
967
+     * @return int The subscription's id
968
+     */
969
+    public function renew() {
970
+
971
+        // Complete subscription if applicable
972
+        if ( $this->is_last_renewal() ) {
973
+            return $this->complete();
974
+        }
975
+
976
+        // Calculate new expiration
977
+        $frequency      = $this->get_frequency();
978
+        $period         = $this->get_period();
979
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
980
+
981
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
982
+        $this->set_status( 'active' );
983
+        $this->save();
984
+
985
+        do_action( 'getpaid_subscription_renewed', $this );
986
+
987
+        return $this->get_id();
988
+    }
989
+
990
+    /**
991
+     * Marks a subscription as completed
992
+     *
993
+     * Subscription is completed when the number of payments matches the billing_times field
994
+     *
995
+     * @since  1.0.0
996
+     * @return int|bool Subscription id or false if the subscription is cancelled.
997
+     */
998
+    public function complete() {
999
+
1000
+        // Only mark a subscription as complete if it's not already cancelled.
1001
+        if ( $this->has_status( 'cancelled' ) ) {
1002
+            return false;
1003
+        }
1004
+
1005
+        $this->set_status( 'completed' );
1006
+        return $this->save();
1007
+
1008
+    }
1009
+
1010
+    /**
1011
+     * Marks a subscription as expired
1012
+     *
1013
+     * @since  1.0.0
1014
+     * @param  bool $check_expiration
1015
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1016
+     */
1017
+    public function expire( $check_expiration = false ) {
1018
+
1019
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1020
+            // Do not mark as expired since real expiration date is in the future
1021
+            return false;
1022
+        }
1023
+
1024
+        $this->set_status( 'expired' );
1025
+        return $this->save();
1026
+
1027
+    }
1028
+
1029
+    /**
1030
+     * Marks a subscription as failing
1031
+     *
1032
+     * @since  2.4.2
1033
+     * @return int Subscription id.
1034
+     */
1035
+    public function failing() {
1036
+        $this->set_status( 'failing' );
1037
+        return $this->save();
1038
+    }
1039 1039
 
1040 1040
     /**
1041 1041
      * Marks a subscription as cancelled
@@ -1044,19 +1044,19 @@  discard block
 block discarded – undo
1044 1044
      * @return int Subscription id.
1045 1045
      */
1046 1046
     public function cancel() {
1047
-		$this->set_status( 'cancelled' );
1048
-		return $this->save();
1047
+        $this->set_status( 'cancelled' );
1048
+        return $this->save();
1049 1049
     }
1050 1050
 
1051
-	/**
1052
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1053
-	 *
1054
-	 * @since  1.0.0
1055
-	 * @return bool
1056
-	 */
1057
-	public function can_cancel() {
1058
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1059
-	}
1051
+    /**
1052
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1053
+     *
1054
+     * @since  1.0.0
1055
+     * @return bool
1056
+     */
1057
+    public function can_cancel() {
1058
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1059
+    }
1060 1060
 
1061 1061
     /**
1062 1062
      * Returns an array of subscription statuses that can be cancelled
@@ -1069,96 +1069,96 @@  discard block
 block discarded – undo
1069 1069
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1070 1070
     }
1071 1071
 
1072
-	/**
1073
-	 * Retrieves the URL to cancel subscription
1074
-	 *
1075
-	 * @since  1.0.0
1076
-	 * @return string
1077
-	 */
1078
-	public function get_cancel_url() {
1079
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1080
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1081
-	}
1082
-
1083
-	/**
1084
-	 * Retrieves the URL to view a subscription
1085
-	 *
1086
-	 * @since  1.0.19
1087
-	 * @return string
1088
-	 */
1089
-	public function get_view_url() {
1090
-
1091
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1092
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1093
-
1094
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1095
-	}
1096
-
1097
-	/**
1098
-	 * Determines if subscription can be manually renewed
1099
-	 *
1100
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1101
-	 * that can be renewed manually
1102
-	 *
1103
-	 * @since  2.5
1104
-	 * @return bool
1105
-	 */
1106
-	public function can_renew() {
1107
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1108
-	}
1109
-
1110
-	/**
1111
-	 * Retrieves the URL to renew a subscription
1112
-	 *
1113
-	 * @since  2.5
1114
-	 * @return string
1115
-	 */
1116
-	public function get_renew_url() {
1117
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1118
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1119
-	}
1120
-
1121
-	/**
1122
-	 * Determines if subscription can have their payment method updated
1123
-	 *
1124
-	 * @since  1.0.0
1125
-	 * @return bool
1126
-	 */
1127
-	public function can_update() {
1128
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1129
-	}
1130
-
1131
-	/**
1132
-	 * Retrieves the URL to update subscription
1133
-	 *
1134
-	 * @since  1.0.0
1135
-	 * @return string
1136
-	 */
1137
-	public function get_update_url() {
1138
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1139
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1140
-	}
1141
-
1142
-	/**
1143
-	 * Retrieves the subscription status label
1144
-	 *
1145
-	 * @since  1.0.0
1146
-	 * @return string
1147
-	 */
1148
-	public function get_status_label() {
1149
-		return getpaid_get_subscription_status_label( $this->get_status() );
1150
-	}
1151
-
1152
-	/**
1153
-	 * Retrieves the subscription status class
1154
-	 *
1155
-	 * @since  1.0.19
1156
-	 * @return string
1157
-	 */
1158
-	public function get_status_class() {
1159
-		$statuses = getpaid_get_subscription_status_classes();
1160
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1161
-	}
1072
+    /**
1073
+     * Retrieves the URL to cancel subscription
1074
+     *
1075
+     * @since  1.0.0
1076
+     * @return string
1077
+     */
1078
+    public function get_cancel_url() {
1079
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1080
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1081
+    }
1082
+
1083
+    /**
1084
+     * Retrieves the URL to view a subscription
1085
+     *
1086
+     * @since  1.0.19
1087
+     * @return string
1088
+     */
1089
+    public function get_view_url() {
1090
+
1091
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1092
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1093
+
1094
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1095
+    }
1096
+
1097
+    /**
1098
+     * Determines if subscription can be manually renewed
1099
+     *
1100
+     * This method is filtered by payment gateways in order to return true on subscriptions
1101
+     * that can be renewed manually
1102
+     *
1103
+     * @since  2.5
1104
+     * @return bool
1105
+     */
1106
+    public function can_renew() {
1107
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1108
+    }
1109
+
1110
+    /**
1111
+     * Retrieves the URL to renew a subscription
1112
+     *
1113
+     * @since  2.5
1114
+     * @return string
1115
+     */
1116
+    public function get_renew_url() {
1117
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1118
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1119
+    }
1120
+
1121
+    /**
1122
+     * Determines if subscription can have their payment method updated
1123
+     *
1124
+     * @since  1.0.0
1125
+     * @return bool
1126
+     */
1127
+    public function can_update() {
1128
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1129
+    }
1130
+
1131
+    /**
1132
+     * Retrieves the URL to update subscription
1133
+     *
1134
+     * @since  1.0.0
1135
+     * @return string
1136
+     */
1137
+    public function get_update_url() {
1138
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1139
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1140
+    }
1141
+
1142
+    /**
1143
+     * Retrieves the subscription status label
1144
+     *
1145
+     * @since  1.0.0
1146
+     * @return string
1147
+     */
1148
+    public function get_status_label() {
1149
+        return getpaid_get_subscription_status_label( $this->get_status() );
1150
+    }
1151
+
1152
+    /**
1153
+     * Retrieves the subscription status class
1154
+     *
1155
+     * @since  1.0.19
1156
+     * @return string
1157
+     */
1158
+    public function get_status_class() {
1159
+        $statuses = getpaid_get_subscription_status_classes();
1160
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1161
+    }
1162 1162
 
1163 1163
     /**
1164 1164
      * Retrieves the subscription status label
@@ -1168,11 +1168,11 @@  discard block
 block discarded – undo
1168 1168
      */
1169 1169
     public function get_status_label_html() {
1170 1170
 
1171
-		$status_label = sanitize_text_field( $this->get_status_label() );
1172
-		$class        = esc_attr( $this->get_status_class() );
1173
-		$status       = sanitize_html_class( $this->get_status() );
1171
+        $status_label = sanitize_text_field( $this->get_status_label() );
1172
+        $class        = esc_attr( $this->get_status_class() );
1173
+        $status       = sanitize_html_class( $this->get_status() );
1174 1174
 
1175
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1175
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1176 1176
     }
1177 1177
 
1178 1178
     /**
@@ -1183,75 +1183,75 @@  discard block
 block discarded – undo
1183 1183
      * @return bool
1184 1184
      */
1185 1185
     public function payment_exists( $txn_id = '' ) {
1186
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1186
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1187 1187
         return ! empty( $invoice_id );
1188
-	}
1189
-
1190
-	/**
1191
-	 * Handle the status transition.
1192
-	 */
1193
-	protected function status_transition() {
1194
-		$status_transition = $this->status_transition;
1195
-
1196
-		// Reset status transition variable.
1197
-		$this->status_transition = false;
1198
-
1199
-		if ( $status_transition ) {
1200
-			try {
1201
-
1202
-				// Fire a hook for the status change.
1203
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1204
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1205
-
1206
-				if ( ! empty( $status_transition['from'] ) ) {
1207
-
1208
-					/* translators: 1: old subscription status 2: new subscription status */
1209
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1210
-
1211
-					// Note the transition occurred.
1212
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1213
-
1214
-					// Fire another hook.
1215
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1216
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1217
-
1218
-				} else {
1219
-					/* translators: %s: new invoice status */
1220
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1221
-
1222
-					// Note the transition occurred.
1223
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1224
-
1225
-				}
1226
-			} catch ( Exception $e ) {
1227
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1228
-			}
1229
-		}
1230
-
1231
-	}
1232
-
1233
-	/**
1234
-	 * Save data to the database.
1235
-	 *
1236
-	 * @since 1.0.19
1237
-	 * @return int subscription ID
1238
-	 */
1239
-	public function save() {
1240
-		parent::save();
1241
-		$this->status_transition();
1242
-		return $this->get_id();
1243
-	}
1244
-
1245
-	/**
1246
-	 * Activates a subscription.
1247
-	 *
1248
-	 * @since 1.0.19
1249
-	 * @return int subscription ID
1250
-	 */
1251
-	public function activate() {
1252
-		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1253
-		$this->set_status( $status );
1254
-		return $this->save();
1255
-	}
1188
+    }
1189
+
1190
+    /**
1191
+     * Handle the status transition.
1192
+     */
1193
+    protected function status_transition() {
1194
+        $status_transition = $this->status_transition;
1195
+
1196
+        // Reset status transition variable.
1197
+        $this->status_transition = false;
1198
+
1199
+        if ( $status_transition ) {
1200
+            try {
1201
+
1202
+                // Fire a hook for the status change.
1203
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1204
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1205
+
1206
+                if ( ! empty( $status_transition['from'] ) ) {
1207
+
1208
+                    /* translators: 1: old subscription status 2: new subscription status */
1209
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1210
+
1211
+                    // Note the transition occurred.
1212
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1213
+
1214
+                    // Fire another hook.
1215
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1216
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1217
+
1218
+                } else {
1219
+                    /* translators: %s: new invoice status */
1220
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1221
+
1222
+                    // Note the transition occurred.
1223
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1224
+
1225
+                }
1226
+            } catch ( Exception $e ) {
1227
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1228
+            }
1229
+        }
1230
+
1231
+    }
1232
+
1233
+    /**
1234
+     * Save data to the database.
1235
+     *
1236
+     * @since 1.0.19
1237
+     * @return int subscription ID
1238
+     */
1239
+    public function save() {
1240
+        parent::save();
1241
+        $this->status_transition();
1242
+        return $this->get_id();
1243
+    }
1244
+
1245
+    /**
1246
+     * Activates a subscription.
1247
+     *
1248
+     * @since 1.0.19
1249
+     * @return int subscription ID
1250
+     */
1251
+    public function activate() {
1252
+        $status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1253
+        $this->set_status( $status );
1254
+        return $this->save();
1255
+    }
1256 1256
 
1257 1257
 }
Please login to merge, or discard this patch.
Spacing   +230 added lines, -230 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
  * The Subscription Class
@@ -68,27 +68,27 @@  discard block
 block discarded – undo
68 68
 	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69 69
 	 * @param  bool $deprecated
70 70
 	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
71
+	function __construct($subscription = 0, $deprecated = false) {
72 72
 
73
-		parent::__construct( $subscription );
73
+		parent::__construct($subscription);
74 74
 
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
75
+		if (!$deprecated && !empty($subscription) && is_numeric($subscription)) {
76
+			$this->set_id($subscription);
77
+		} elseif ($subscription instanceof self) {
78
+			$this->set_id($subscription->get_id());
79
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) {
80
+			$this->set_id($subscription_id);
81
+		} elseif (!empty($subscription->id)) {
82
+			$this->set_id($subscription->id);
83 83
 		} else {
84
-			$this->set_object_read( true );
84
+			$this->set_object_read(true);
85 85
 		}
86 86
 
87 87
 		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
88
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
89 89
 
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
90
+		if ($this->get_id() > 0) {
91
+			$this->data_store->read($this);
92 92
 		}
93 93
 
94 94
 	}
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @since 1.0.19
104 104
 	 * @return int
105 105
 	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
106
+	public static function get_subscription_id_by_field($value, $field = 'profile_id') {
107 107
         global $wpdb;
108 108
 
109 109
 		// Trim the value.
110
-		$value = trim( $value );
110
+		$value = trim($value);
111 111
 
112
-		if ( empty( $value ) ) {
112
+		if (empty($value)) {
113 113
 			return 0;
114 114
 		}
115 115
 
116
-		if ( 'invoice_id' == $field ) {
116
+		if ('invoice_id' == $field) {
117 117
 			$field = 'parent_payment_id';
118 118
 		}
119 119
 
@@ -125,28 +125,28 @@  discard block
 block discarded – undo
125 125
 		);
126 126
 
127 127
 		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
128
+		if (empty($field) || !in_array($field, $fields)) {
129 129
 			return 0;
130 130
 		}
131 131
 
132 132
 		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
133
+		$subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids");
134
+		if (!empty($subscription_id)) {
135 135
 			return $subscription_id;
136 136
 		}
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
140 140
         $subscription_id  = (int) $wpdb->get_var(
141
-            $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
141
+            $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
144
+		if (empty($subscription_id)) {
145 145
 			return 0;
146 146
 		}
147 147
 
148 148
 		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
149
+		wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids");
150 150
 
151 151
 		return $subscription_id;
152 152
 	}
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
158
+		wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids');
159
+		wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids');
160
+		wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids');
161
+		wp_cache_delete($this->get_id(), 'getpaid_subscriptions');
162 162
 	}
163 163
 
164 164
 	/**
165 165
      * Checks if a subscription key is set.
166 166
      */
167
-    public function _isset( $key ) {
168
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
167
+    public function _isset($key) {
168
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
169 169
 	}
170 170
 
171 171
 	/*
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	 * @param  string $context View or edit context.
191 191
 	 * @return int
192 192
 	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
193
+	public function get_customer_id($context = 'view') {
194
+		return (int) $this->get_prop('customer_id', $context);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 	 * @param  string $context View or edit context.
202 202
 	 * @return WP_User|false WP_User object on success, false on failure.
203 203
 	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
204
+	public function get_customer($context = 'view') {
205
+		return get_userdata($this->get_customer_id($context));
206 206
 	}
207 207
 
208 208
 	/**
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param  string $context View or edit context.
213 213
 	 * @return int
214 214
 	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
215
+	public function get_parent_invoice_id($context = 'view') {
216
+		return (int) $this->get_prop('parent_payment_id', $context);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 * @param  string $context View or edit context.
224 224
 	 * @return int
225 225
 	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
226
+    public function get_parent_payment_id($context = 'view') {
227
+        return $this->get_parent_invoice_id($context);
228 228
 	}
229 229
 
230 230
 	/**
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      * @since  1.0.0
234 234
      * @return int
235 235
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
236
+    public function get_original_payment_id($context = 'view') {
237
+        return $this->get_parent_invoice_id($context);
238 238
     }
239 239
 
240 240
 	/**
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @param  string $context View or edit context.
245 245
 	 * @return WPInv_Invoice
246 246
 	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
247
+	public function get_parent_invoice($context = 'view') {
248
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
249 249
 	}
250 250
 
251 251
 	/**
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 	 * @param  string $context View or edit context.
256 256
 	 * @return WPInv_Invoice
257 257
 	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
258
+    public function get_parent_payment($context = 'view') {
259
+        return $this->get_parent_invoice($context);
260 260
 	}
261 261
 
262 262
 	/**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @param  string $context View or edit context.
267 267
 	 * @return int
268 268
 	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
269
+	public function get_product_id($context = 'view') {
270
+		return (int) $this->get_prop('product_id', $context);
271 271
 	}
272 272
 
273 273
 	/**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * @param  string $context View or edit context.
278 278
 	 * @return WPInv_Item
279 279
 	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
280
+	public function get_product($context = 'view') {
281
+		return new WPInv_Item($this->get_product_id($context));
282 282
 	}
283 283
 
284 284
 	/**
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 	 * @param  string $context View or edit context.
291 291
 	 * @return string
292 292
 	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
293
+	public function get_gateway($context = 'view') {
294
+		return $this->get_parent_invoice($context)->get_gateway();
295 295
 	}
296 296
 
297 297
 	/**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @param  string $context View or edit context.
302 302
 	 * @return string
303 303
 	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
304
+	public function get_period($context = 'view') {
305
+		return $this->get_prop('period', $context);
306 306
 	}
307 307
 
308 308
 	/**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 	 * @param  string $context View or edit context.
313 313
 	 * @return int
314 314
 	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
315
+	public function get_frequency($context = 'view') {
316
+		return (int) $this->get_prop('frequency', $context);
317 317
 	}
318 318
 
319 319
 	/**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context View or edit context.
324 324
 	 * @return float
325 325
 	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
326
+	public function get_initial_amount($context = 'view') {
327
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
328 328
 	}
329 329
 
330 330
 	/**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
 	 * @param  string $context View or edit context.
335 335
 	 * @return float
336 336
 	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
337
+	public function get_recurring_amount($context = 'view') {
338
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
339 339
 	}
340 340
 
341 341
 	/**
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @param  string $context View or edit context.
346 346
 	 * @return int
347 347
 	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
348
+	public function get_bill_times($context = 'view') {
349
+		return (int) $this->get_prop('bill_times', $context);
350 350
 	}
351 351
 
352 352
 	/**
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 	 * @param  string $context View or edit context.
357 357
 	 * @return string
358 358
 	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
359
+	public function get_transaction_id($context = 'view') {
360
+		return $this->get_prop('transaction_id', $context);
361 361
 	}
362 362
 
363 363
 	/**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 	 * @param  string $context View or edit context.
368 368
 	 * @return string
369 369
 	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
370
+	public function get_created($context = 'view') {
371
+		return $this->get_prop('created', $context);
372 372
 	}
373 373
 
374 374
 	/**
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
 	 * @param  string $context View or edit context.
379 379
 	 * @return string
380 380
 	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
381
+	public function get_date_created($context = 'view') {
382
+		return $this->get_created($context);
383 383
 	}
384 384
 
385 385
 	/**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 	 */
391 391
 	public function get_time_created() {
392 392
 		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
393
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
394 394
 	}
395 395
 
396 396
 	/**
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 * @param  string $context View or edit context.
401 401
 	 * @return string
402 402
 	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
403
+	public function get_date_created_gmt($context = 'view') {
404
+        $date = $this->get_date_created($context);
405 405
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
406
+        if ($date) {
407
+            $date = get_gmt_from_date($date);
408 408
         }
409 409
 		return $date;
410 410
 	}
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 	 * @param  string $context View or edit context.
417 417
 	 * @return string
418 418
 	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
419
+	public function get_next_renewal_date($context = 'view') {
420
+		return $this->get_prop('expiration', $context);
421 421
 	}
422 422
 
423 423
 	/**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	 * @param  string $context View or edit context.
428 428
 	 * @return string
429 429
 	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
430
+	public function get_expiration($context = 'view') {
431
+		return $this->get_next_renewal_date($context);
432 432
 	}
433 433
 
434 434
 	/**
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	public function get_expiration_time() {
441 441
 		$expiration = $this->get_expiration();
442 442
 
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
443
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
444
+			return current_time('timestamp');
445 445
 		}
446 446
 
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
447
+		$expiration = strtotime($expiration, current_time('timestamp'));
448
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
449 449
 	}
450 450
 
451 451
 	/**
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 	 * @param  string $context View or edit context.
456 456
 	 * @return string
457 457
 	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
458
+	public function get_next_renewal_date_gmt($context = 'view') {
459
+        $date = $this->get_next_renewal_date($context);
460 460
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
461
+        if ($date) {
462
+            $date = get_gmt_from_date($date);
463 463
         }
464 464
 		return $date;
465 465
 	}
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 	 * @param  string $context View or edit context.
472 472
 	 * @return string
473 473
 	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
474
+	public function get_trial_period($context = 'view') {
475
+		return $this->get_prop('trial_period', $context);
476 476
 	}
477 477
 
478 478
 	/**
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 * @param  string $context View or edit context.
483 483
 	 * @return string
484 484
 	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
485
+	public function get_status($context = 'view') {
486
+		return $this->get_prop('status', $context);
487 487
 	}
488 488
 
489 489
 	/**
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 * @param  string $context View or edit context.
494 494
 	 * @return string
495 495
 	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
496
+	public function get_profile_id($context = 'view') {
497
+		return $this->get_prop('profile_id', $context);
498 498
 	}
499 499
 
500 500
 	/*
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
 	 * @since 1.0.19
510 510
 	 * @param  int $value The customer's id.
511 511
 	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
512
+	public function set_customer_id($value) {
513
+		$this->set_prop('customer_id', (int) $value);
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @since 1.0.19
520 520
 	 * @param  int $value The parent invoice id.
521 521
 	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
522
+	public function set_parent_invoice_id($value) {
523
+		$this->set_prop('parent_payment_id', (int) $value);
524 524
 	}
525 525
 
526 526
 	/**
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @since 1.0.19
530 530
 	 * @param  int $value The parent invoice id.
531 531
 	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
532
+    public function set_parent_payment_id($value) {
533
+        $this->set_parent_invoice_id($value);
534 534
 	}
535 535
 
536 536
 	/**
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
      * @since 1.0.19
540 540
 	 * @param  int $value The parent invoice id.
541 541
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
542
+    public function set_original_payment_id($value) {
543
+        $this->set_parent_invoice_id($value);
544 544
 	}
545 545
 
546 546
 	/**
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
 	 * @since 1.0.19
550 550
 	 * @param  int $value The subscription product id.
551 551
 	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
552
+	public function set_product_id($value) {
553
+		$this->set_prop('product_id', (int) $value);
554 554
 	}
555 555
 
556 556
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @since 1.0.19
560 560
 	 * @param  string $value The renewal period.
561 561
 	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
562
+	public function set_period($value) {
563
+		$this->set_prop('period', $value);
564 564
 	}
565 565
 
566 566
 	/**
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	 * @since 1.0.19
570 570
 	 * @param  int $value The subscription frequency.
571 571
 	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
572
+	public function set_frequency($value) {
573
+		$value = empty($value) ? 1 : (int) $value;
574
+		$this->set_prop('frequency', absint($value));
575 575
 	}
576 576
 
577 577
 	/**
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @since 1.0.19
581 581
 	 * @param  float $value The initial subcription amount.
582 582
 	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
583
+	public function set_initial_amount($value) {
584
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
585 585
 	}
586 586
 
587 587
 	/**
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 	 * @since 1.0.19
591 591
 	 * @param  float $value The recurring subcription amount.
592 592
 	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
593
+	public function set_recurring_amount($value) {
594
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
595 595
 	}
596 596
 
597 597
 	/**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @since 1.0.19
601 601
 	 * @param  int $value Bill times.
602 602
 	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
603
+	public function set_bill_times($value) {
604
+		$this->set_prop('bill_times', (int) $value);
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param string $value Bill times.
612 612
 	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
613
+	public function set_transaction_id($value) {
614
+		$this->set_prop('transaction_id', sanitize_text_field($value));
615 615
 	}
616 616
 
617 617
 	/**
@@ -620,15 +620,15 @@  discard block
 block discarded – undo
620 620
 	 * @since 1.0.19
621 621
 	 * @param string $value strtotime compliant date.
622 622
 	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
623
+	public function set_created($value) {
624
+        $date = strtotime($value);
625 625
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
626
+        if ($date && $value !== '0000-00-00 00:00:00') {
627
+            $this->set_prop('created', date('Y-m-d H:i:s', $date));
628 628
             return;
629 629
         }
630 630
 
631
-		$this->set_prop( 'created', '' );
631
+		$this->set_prop('created', '');
632 632
 
633 633
 	}
634 634
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 	 * @since 1.0.19
639 639
 	 * @param string $value strtotime compliant date.
640 640
 	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
641
+	public function set_date_created($value) {
642
+		$this->set_created($value);
643 643
     }
644 644
 
645 645
 	/**
@@ -648,15 +648,15 @@  discard block
 block discarded – undo
648 648
 	 * @since 1.0.19
649 649
 	 * @param string $value strtotime compliant date.
650 650
 	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
651
+	public function set_next_renewal_date($value) {
652
+		$date = strtotime($value);
653 653
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
654
+        if ($date && $value !== '0000-00-00 00:00:00') {
655
+            $this->set_prop('expiration', date('Y-m-d H:i:s', $date));
656 656
             return;
657 657
 		}
658 658
 
659
-		$this->set_prop( 'expiration', '' );
659
+		$this->set_prop('expiration', '');
660 660
 
661 661
 	}
662 662
 
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 	 * @since 1.0.19
667 667
 	 * @param string $value strtotime compliant date.
668 668
 	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
669
+	public function set_expiration($value) {
670
+		$this->set_next_renewal_date($value);
671 671
     }
672 672
 
673 673
 	/**
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
 	 * @since 1.0.19
677 677
 	 * @param string $value trial period e.g 1 year.
678 678
 	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
679
+	public function set_trial_period($value) {
680
+		$this->set_prop('trial_period', $value);
681 681
 	}
682 682
 
683 683
 	/**
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
 	 * @since 1.0.19
687 687
 	 * @param string $new_status    New subscription status.
688 688
 	 */
689
-	public function set_status( $new_status ) {
689
+	public function set_status($new_status) {
690 690
 
691 691
 		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
692
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
693 693
 			return;
694 694
 		}
695 695
 
696 696
 		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
697
+		$this->set_prop('status', $new_status);
698 698
 
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
699
+		if (true === $this->object_read && $old_status !== $new_status) {
700 700
 			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
701
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
702 702
 				'to'     => $new_status,
703 703
 			);
704 704
 		}
@@ -711,8 +711,8 @@  discard block
 block discarded – undo
711 711
 	 * @since 1.0.19
712 712
 	 * @param  string $value the remote profile id.
713 713
 	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
714
+	public function set_profile_id($value) {
715
+		$this->set_prop('profile_id', sanitize_text_field($value));
716 716
 	}
717 717
 
718 718
 	/*
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @param string|array String or array of strings to check for.
731 731
 	 * @return bool
732 732
      */
733
-    public function has_status( $status ) {
734
-        return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
733
+    public function has_status($status) {
734
+        return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status)));
735 735
 	}
736 736
 
737 737
 	/**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
      */
742 742
     public function has_trial_period() {
743 743
 		$period = $this->get_trial_period();
744
-        return ! empty( $period );
744
+        return !empty($period);
745 745
 	}
746 746
 
747 747
 	/**
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 	 * @return bool
751 751
 	 */
752 752
 	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
+		return $this->has_status('active trialling') && !$this->is_expired();
754 754
 	}
755 755
 
756 756
 	/**
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 	 * @return bool
760 760
 	 */
761 761
 	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
762
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql'));
763 763
 	}
764 764
 
765 765
 	/**
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	 */
770 770
 	public function is_last_renewal() {
771 771
 		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
+		return !empty($max_bills) && $max_bills <= $this->get_times_billed();
773 773
 	}
774 774
 
775 775
 	/*
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
 	/**
785 785
 	 * Backwards compatibilty.
786 786
 	 */
787
-	public function create( $data = array() ) {
787
+	public function create($data = array()) {
788 788
 
789 789
 		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
790
+		if (is_array($data)) {
791
+			$this->set_props($data);
792 792
 		}
793 793
 
794 794
 		// Save the item.
@@ -799,8 +799,8 @@  discard block
 block discarded – undo
799 799
 	/**
800 800
 	 * Backwards compatibilty.
801 801
 	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
802
+	public function update($args = array()) {
803
+		return $this->create($args);
804 804
 	}
805 805
 
806 806
     /**
@@ -809,12 +809,12 @@  discard block
 block discarded – undo
809 809
      * @since  1.0.0
810 810
      * @return WP_Post[]
811 811
      */
812
-    public function get_child_payments( $hide_pending = true ) {
812
+    public function get_child_payments($hide_pending = true) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+		$statuses = array('publish', 'wpi-processing', 'wpi-renewal');
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
816
+		if (!$hide_pending) {
817
+			$statuses = array_keys(wpinv_get_invoice_statuses());
818 818
 		}
819 819
 
820 820
         return get_posts(
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
      * @return int
837 837
      */
838 838
     public function get_total_payments() {
839
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
839
+		return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id());
840 840
     }
841 841
 
842 842
     /**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
     public function get_times_billed() {
849 849
         $times_billed = $this->get_total_payments();
850 850
 
851
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
851
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
852 852
             $times_billed--;
853 853
         }
854 854
 
@@ -863,49 +863,49 @@  discard block
 block discarded – undo
863 863
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
864 864
      * @return bool
865 865
      */
866
-    public function add_payment( $args = array(), $invoice = false ) {
866
+    public function add_payment($args = array(), $invoice = false) {
867 867
 
868 868
 		// Process each payment once.
869
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
870 870
             return false;
871 871
         }
872 872
 
873 873
 		// Are we creating a new invoice?
874
-		if ( empty( $invoice ) ) {
874
+		if (empty($invoice)) {
875 875
 			$invoice = $this->create_payment();
876 876
 
877
-			if ( empty( $invoice ) ) {
877
+			if (empty($invoice)) {
878 878
 				return false;
879 879
 			}
880 880
 
881 881
 		}
882 882
 
883
-		$invoice->set_status( 'wpi-renewal' );
883
+		$invoice->set_status('wpi-renewal');
884 884
 
885 885
 		// Maybe set a transaction id.
886
-		if ( ! empty( $args['transaction_id'] ) ) {
887
-			$invoice->set_transaction_id( $args['transaction_id'] );
886
+		if (!empty($args['transaction_id'])) {
887
+			$invoice->set_transaction_id($args['transaction_id']);
888 888
 		}
889 889
 
890 890
 		// Set the completed date.
891
-		$invoice->set_completed_date( current_time( 'mysql' ) );
891
+		$invoice->set_completed_date(current_time('mysql'));
892 892
 
893 893
 		// And the gateway.
894
-		if ( ! empty( $args['gateway'] ) ) {
895
-			$invoice->set_gateway( $args['gateway'] );
894
+		if (!empty($args['gateway'])) {
895
+			$invoice->set_gateway($args['gateway']);
896 896
 		}
897 897
 
898 898
 		$invoice->save();
899 899
 
900
-		if ( ! $invoice->exists() ) {
900
+		if (!$invoice->exists()) {
901 901
 			return false;
902 902
 		}
903 903
 
904
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
905
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
906
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
904
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
905
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
906
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
907 907
 
908
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
908
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
909 909
 
910 910
         return $invoice->get_id();
911 911
 	}
@@ -920,41 +920,41 @@  discard block
 block discarded – undo
920 920
 
921 921
 		$parent_invoice = $this->get_parent_payment();
922 922
 
923
-		if ( ! $parent_invoice->exists() ) {
923
+		if (!$parent_invoice->exists()) {
924 924
 			return false;
925 925
 		}
926 926
 
927 927
 		// Duplicate the parent invoice.
928
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
929
-		$invoice->set_parent_id( $parent_invoice->get_id() );
930
-		$invoice->set_subscription_id( $this->get_id() );
931
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
928
+		$invoice = getpaid_duplicate_invoice($parent_invoice);
929
+		$invoice->set_parent_id($parent_invoice->get_id());
930
+		$invoice->set_subscription_id($this->get_id());
931
+		$invoice->set_remote_subscription_id($this->get_profile_id());
932 932
 
933 933
 		// Set invoice items.
934
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
935
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
934
+		$subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id());
935
+		$allowed_items      = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']);
936 936
 		$invoice_items      = array();
937 937
 
938
-		foreach ( $invoice->get_items() as $item ) {
939
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
938
+		foreach ($invoice->get_items() as $item) {
939
+			if (in_array($item->get_id(), $allowed_items)) {
940 940
 				$invoice_items[] = $item;
941 941
 			}
942 942
 		}
943 943
 
944
-		$invoice->set_items( $invoice_items );
944
+		$invoice->set_items($invoice_items);
945 945
 
946
-		if ( ! empty( $subscription_group['fees'] ) ) {
947
-			$invoice->set_fees( $subscription_group['fees'] );
946
+		if (!empty($subscription_group['fees'])) {
947
+			$invoice->set_fees($subscription_group['fees']);
948 948
 		}
949 949
 
950 950
 		// Maybe recalculate discount (Pre-GetPaid Fix).
951
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
952
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
953
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
951
+		$discount = new WPInv_Discount($invoice->get_discount_code());
952
+		if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) {
953
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
954 954
 		}
955 955
 
956 956
 		$invoice->recalculate_total();
957
-		$invoice->set_status( 'wpi-pending' );
957
+		$invoice->set_status('wpi-pending');
958 958
 		$invoice->save();
959 959
 
960 960
 		return $invoice->exists() ? $invoice : false;
@@ -969,20 +969,20 @@  discard block
 block discarded – undo
969 969
 	public function renew() {
970 970
 
971 971
 		// Complete subscription if applicable
972
-		if ( $this->is_last_renewal() ) {
972
+		if ($this->is_last_renewal()) {
973 973
 			return $this->complete();
974 974
 		}
975 975
 
976 976
 		// Calculate new expiration
977 977
 		$frequency      = $this->get_frequency();
978 978
 		$period         = $this->get_period();
979
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
979
+		$new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time());
980 980
 
981
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
982
-		$this->set_status( 'active' );
981
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
982
+		$this->set_status('active');
983 983
 		$this->save();
984 984
 
985
-		do_action( 'getpaid_subscription_renewed', $this );
985
+		do_action('getpaid_subscription_renewed', $this);
986 986
 
987 987
 		return $this->get_id();
988 988
 	}
@@ -998,11 +998,11 @@  discard block
 block discarded – undo
998 998
 	public function complete() {
999 999
 
1000 1000
 		// Only mark a subscription as complete if it's not already cancelled.
1001
-		if ( $this->has_status( 'cancelled' ) ) {
1001
+		if ($this->has_status('cancelled')) {
1002 1002
 			return false;
1003 1003
 		}
1004 1004
 
1005
-		$this->set_status( 'completed' );
1005
+		$this->set_status('completed');
1006 1006
 		return $this->save();
1007 1007
 
1008 1008
 	}
@@ -1014,14 +1014,14 @@  discard block
 block discarded – undo
1014 1014
 	 * @param  bool $check_expiration
1015 1015
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1016 1016
 	 */
1017
-	public function expire( $check_expiration = false ) {
1017
+	public function expire($check_expiration = false) {
1018 1018
 
1019
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1019
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1020 1020
 			// Do not mark as expired since real expiration date is in the future
1021 1021
 			return false;
1022 1022
 		}
1023 1023
 
1024
-		$this->set_status( 'expired' );
1024
+		$this->set_status('expired');
1025 1025
 		return $this->save();
1026 1026
 
1027 1027
 	}
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
 	 * @return int Subscription id.
1034 1034
 	 */
1035 1035
 	public function failing() {
1036
-		$this->set_status( 'failing' );
1036
+		$this->set_status('failing');
1037 1037
 		return $this->save();
1038 1038
 	}
1039 1039
 
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      * @return int Subscription id.
1045 1045
      */
1046 1046
     public function cancel() {
1047
-		$this->set_status( 'cancelled' );
1047
+		$this->set_status('cancelled');
1048 1048
 		return $this->save();
1049 1049
     }
1050 1050
 
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 	 * @return bool
1056 1056
 	 */
1057 1057
 	public function can_cancel() {
1058
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1058
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1059 1059
 	}
1060 1060
 
1061 1061
     /**
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
      * @return      array
1067 1067
      */
1068 1068
     public function get_cancellable_statuses() {
1069
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1069
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1070 1070
     }
1071 1071
 
1072 1072
 	/**
@@ -1076,8 +1076,8 @@  discard block
 block discarded – undo
1076 1076
 	 * @return string
1077 1077
 	 */
1078 1078
 	public function get_cancel_url() {
1079
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1080
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1079
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1080
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1081 1081
 	}
1082 1082
 
1083 1083
 	/**
@@ -1088,10 +1088,10 @@  discard block
 block discarded – undo
1088 1088
 	 */
1089 1089
 	public function get_view_url() {
1090 1090
 
1091
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1092
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1091
+		$url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1092
+		$url = add_query_arg('subscription', $this->get_id(), $url);
1093 1093
 
1094
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1094
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1095 1095
 	}
1096 1096
 
1097 1097
 	/**
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 	 * @return bool
1105 1105
 	 */
1106 1106
 	public function can_renew() {
1107
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1107
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1108 1108
 	}
1109 1109
 
1110 1110
 	/**
@@ -1114,8 +1114,8 @@  discard block
 block discarded – undo
1114 1114
 	 * @return string
1115 1115
 	 */
1116 1116
 	public function get_renew_url() {
1117
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1118
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1117
+		$url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce');
1118
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1119 1119
 	}
1120 1120
 
1121 1121
 	/**
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 	 * @return bool
1126 1126
 	 */
1127 1127
 	public function can_update() {
1128
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1128
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1129 1129
 	}
1130 1130
 
1131 1131
 	/**
@@ -1135,8 +1135,8 @@  discard block
 block discarded – undo
1135 1135
 	 * @return string
1136 1136
 	 */
1137 1137
 	public function get_update_url() {
1138
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1139
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1138
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id()));
1139
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1140 1140
 	}
1141 1141
 
1142 1142
 	/**
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
 	 * @return string
1147 1147
 	 */
1148 1148
 	public function get_status_label() {
1149
-		return getpaid_get_subscription_status_label( $this->get_status() );
1149
+		return getpaid_get_subscription_status_label($this->get_status());
1150 1150
 	}
1151 1151
 
1152 1152
 	/**
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 	 */
1158 1158
 	public function get_status_class() {
1159 1159
 		$statuses = getpaid_get_subscription_status_classes();
1160
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1160
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark';
1161 1161
 	}
1162 1162
 
1163 1163
     /**
@@ -1168,9 +1168,9 @@  discard block
 block discarded – undo
1168 1168
      */
1169 1169
     public function get_status_label_html() {
1170 1170
 
1171
-		$status_label = sanitize_text_field( $this->get_status_label() );
1172
-		$class        = esc_attr( $this->get_status_class() );
1173
-		$status       = sanitize_html_class( $this->get_status() );
1171
+		$status_label = sanitize_text_field($this->get_status_label());
1172
+		$class        = esc_attr($this->get_status_class());
1173
+		$status       = sanitize_html_class($this->get_status());
1174 1174
 
1175 1175
 		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1176 1176
     }
@@ -1182,9 +1182,9 @@  discard block
 block discarded – undo
1182 1182
      * @param  string $txn_id The transaction ID from the merchant processor
1183 1183
      * @return bool
1184 1184
      */
1185
-    public function payment_exists( $txn_id = '' ) {
1186
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1187
-        return ! empty( $invoice_id );
1185
+    public function payment_exists($txn_id = '') {
1186
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1187
+        return !empty($invoice_id);
1188 1188
 	}
1189 1189
 
1190 1190
 	/**
@@ -1196,35 +1196,35 @@  discard block
 block discarded – undo
1196 1196
 		// Reset status transition variable.
1197 1197
 		$this->status_transition = false;
1198 1198
 
1199
-		if ( $status_transition ) {
1199
+		if ($status_transition) {
1200 1200
 			try {
1201 1201
 
1202 1202
 				// Fire a hook for the status change.
1203
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1204
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1203
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1204
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1205 1205
 
1206
-				if ( ! empty( $status_transition['from'] ) ) {
1206
+				if (!empty($status_transition['from'])) {
1207 1207
 
1208 1208
 					/* translators: 1: old subscription status 2: new subscription status */
1209
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1209
+					$transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to']));
1210 1210
 
1211 1211
 					// Note the transition occurred.
1212
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1212
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1213 1213
 
1214 1214
 					// Fire another hook.
1215
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1216
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1215
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1216
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1217 1217
 
1218 1218
 				} else {
1219 1219
 					/* translators: %s: new invoice status */
1220
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1220
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1221 1221
 
1222 1222
 					// Note the transition occurred.
1223
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1223
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1224 1224
 
1225 1225
 				}
1226
-			} catch ( Exception $e ) {
1227
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1226
+			} catch (Exception $e) {
1227
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1228 1228
 			}
1229 1229
 		}
1230 1230
 
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
 	 */
1251 1251
 	public function activate() {
1252 1252
 		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1253
-		$this->set_status( $status );
1253
+		$this->set_status($status);
1254 1254
 		return $this->save();
1255 1255
 	}
1256 1256
 
Please login to merge, or discard this patch.
templates/payment-forms/form.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -7,44 +7,44 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Make sure that the form is active.
13
-if ( ! $form->is_active() ) {
13
+if (!$form->is_active()) {
14 14
     echo aui()->alert(
15 15
         array(
16 16
             'type'    => 'warning',
17
-            'content' => __( 'This payment form is no longer active', 'invoicing' ),
17
+            'content' => __('This payment form is no longer active', 'invoicing'),
18 18
         )
19 19
     );
20 20
     return;
21 21
 }
22 22
 
23 23
 // Fires before displaying a payment form.
24
-do_action( 'getpaid_before_payment_form', $form );
24
+do_action('getpaid_before_payment_form', $form);
25 25
 ?>
26 26
 
27
-<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint( $form->get_id() ); ?> bsui position-relative' method='POST' data-key='<?php echo uniqid('gpf'); ?>' data-currency='<?php echo esc_attr( empty( $form->invoice ) ? wpinv_get_currency() : $form->invoice->get_currency() ); ?>'>
27
+<form class='getpaid-payment-form getpaid-payment-form-<?php echo absint($form->get_id()); ?> bsui position-relative' method='POST' data-key='<?php echo uniqid('gpf'); ?>' data-currency='<?php echo esc_attr(empty($form->invoice) ? wpinv_get_currency() : $form->invoice->get_currency()); ?>'>
28 28
 
29 29
 
30 30
     <?php
31 31
     
32 32
         // Fires when printing the top of a payment form.
33
-        do_action( 'getpaid_payment_form_top', $form );
33
+        do_action('getpaid_payment_form_top', $form);
34 34
 
35 35
         // And the optional invoice id.
36
-        if ( ! empty( $form->invoice ) ) {
37
-            echo getpaid_hidden_field( 'invoice_id', $form->invoice->get_id() );
36
+        if (!empty($form->invoice)) {
37
+            echo getpaid_hidden_field('invoice_id', $form->invoice->get_id());
38 38
         }
39 39
 
40 40
         // We also want to include the form id.
41
-        echo getpaid_hidden_field( 'form_id', $form->get_id() );
41
+        echo getpaid_hidden_field('form_id', $form->get_id());
42 42
 
43 43
         // And an indication that this is a payment form submission.
44
-        echo getpaid_hidden_field( 'getpaid_payment_form_submission', '1' );
44
+        echo getpaid_hidden_field('getpaid_payment_form_submission', '1');
45 45
 
46 46
         // Fires before displaying payment form elements.
47
-        do_action( 'getpaid_payment_form_before_elements', $form );
47
+        do_action('getpaid_payment_form_before_elements', $form);
48 48
 
49 49
         // Display the elements.
50 50
         ?>
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
             <div class="row">
53 53
                 <?php
54 54
 
55
-                    foreach ( $form->get_elements() as $element ) {
55
+                    foreach ($form->get_elements() as $element) {
56 56
 
57
-                        if ( isset( $element['type'] ) ) {
58
-                            $grid_class = esc_attr( getpaid_get_form_element_grid_class( $element ) );
57
+                        if (isset($element['type'])) {
58
+                            $grid_class = esc_attr(getpaid_get_form_element_grid_class($element));
59 59
                             echo "<div class='$grid_class'>";
60
-                            do_action( 'getpaid_payment_form_element', $element, $form );
61
-                            do_action( "getpaid_payment_form_element_{$element['type']}_template", $element, $form );
60
+                            do_action('getpaid_payment_form_element', $element, $form);
61
+                            do_action("getpaid_payment_form_element_{$element['type']}_template", $element, $form);
62 62
                             echo "</div>";
63 63
                         }
64 64
 
@@ -70,16 +70,16 @@  discard block
 block discarded – undo
70 70
 
71 71
         <?php
72 72
         // Fires after displaying payment form elements.
73
-        do_action( 'getpaid_payment_form_after_elements', $form );
73
+        do_action('getpaid_payment_form_after_elements', $form);
74 74
 
75 75
         echo "<div class='getpaid-payment-form-errors alert alert-danger d-none'></div>";
76 76
 
77
-        if ( wpinv_current_user_can_manage_invoicing() ) {
77
+        if (wpinv_current_user_can_manage_invoicing()) {
78 78
 
79 79
             edit_post_link(
80
-                __( 'Edit this form.', 'invoicing' ),
80
+                __('Edit this form.', 'invoicing'),
81 81
                 '<small class="form-text text-muted">',
82
-                '&nbsp;' . __( 'This is only visible to website administators.', 'invoicing' ) . '</small>',
82
+                '&nbsp;' . __('This is only visible to website administators.', 'invoicing') . '</small>',
83 83
                 $form->get_id(),
84 84
                 'text-danger'
85 85
             );
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
     <div class="loading_div overlay overlay-black position-absolute row m-0 rounded overflow-hidden" style="height: 100%;width: 100%;top: 0px;z-index: 2;display:none;">
93 93
         <div class="spinner-border mx-auto align-self-center text-white" role="status">
94
-            <span class="sr-only"><?php _e( 'Loading...', 'invoicing' );?></span>
94
+            <span class="sr-only"><?php _e('Loading...', 'invoicing'); ?></span>
95 95
         </div>
96 96
     </div>
97 97
 
@@ -100,4 +100,4 @@  discard block
 block discarded – undo
100 100
 <?php
101 101
 
102 102
 // Fires after displaying a payment form.
103
-do_action( 'getpaid_after_payment_form', $form );
103
+do_action('getpaid_after_payment_form', $form);
Please login to merge, or discard this patch.
templates/payment-forms/cart.php 1 patch
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -7,27 +7,27 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Cart table columns.
13 13
 $columns = array(
14
-    'name'     => __( 'Item', 'invoicing' ),
15
-    'price'    => __( 'Price', 'invoicing' ),
16
-    'quantity' => __( 'Quantity', 'invoicing' ),
17
-    'subtotal' => __( 'Subtotal', 'invoicing' ),
14
+    'name'     => __('Item', 'invoicing'),
15
+    'price'    => __('Price', 'invoicing'),
16
+    'quantity' => __('Quantity', 'invoicing'),
17
+    'subtotal' => __('Subtotal', 'invoicing'),
18 18
 );
19 19
 
20
-if ( ! empty( $form->invoice ) ) {
21
-    $columns = getpaid_invoice_item_columns( $form->invoice );
20
+if (!empty($form->invoice)) {
21
+    $columns = getpaid_invoice_item_columns($form->invoice);
22 22
 }
23 23
 
24
-if ( isset( $columns['tax_rate'] ) ) {
25
-    unset( $columns['tax_rate'] );
24
+if (isset($columns['tax_rate'])) {
25
+    unset($columns['tax_rate']);
26 26
 }
27 27
 
28
-$columns = apply_filters( 'getpaid_payment_form_cart_table_columns', $columns, $form );
28
+$columns = apply_filters('getpaid_payment_form_cart_table_columns', $columns, $form);
29 29
 
30
-do_action( 'getpaid_before_payment_form_cart', $form );
30
+do_action('getpaid_before_payment_form_cart', $form);
31 31
 
32 32
 ?>
33 33
     <div class="getpaid-payment-form-items-cart border form-group">
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
 
36 36
         <div class="getpaid-payment-form-items-cart-header font-weight-bold bg-light border-bottom py-2 px-3">
37 37
             <div class="form-row">
38
-                <?php foreach ( $columns as $key => $label ) : ?>
39
-                    <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-form-cart-item-<?php echo sanitize_html_class( $key ); ?>">
40
-                        <?php echo sanitize_text_field( $label ); ?>
38
+                <?php foreach ($columns as $key => $label) : ?>
39
+                    <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-form-cart-item-<?php echo sanitize_html_class($key); ?>">
40
+                        <?php echo sanitize_text_field($label); ?>
41 41
                     </div>
42 42
                 <?php endforeach; ?>
43 43
             </div>
@@ -46,16 +46,16 @@  discard block
 block discarded – undo
46 46
         <?php
47 47
 
48 48
             // Display the item totals.
49
-            foreach ( $form->get_items() as $item ) {
50
-                wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'columns' ) );
49
+            foreach ($form->get_items() as $item) {
50
+                wpinv_get_template('payment-forms/cart-item.php', compact('form', 'item', 'columns'));
51 51
             }
52 52
 
53 53
             // Display the cart totals.
54
-            wpinv_get_template( 'payment-forms/cart-totals.php', compact( 'form' ) );
54
+            wpinv_get_template('payment-forms/cart-totals.php', compact('form'));
55 55
 
56 56
         ?>
57 57
     </div>
58 58
 
59 59
 <?php 
60 60
 
61
-do_action( 'getpaid_after_payment_form_cart', $form );
61
+do_action('getpaid_after_payment_form_cart', $form);
Please login to merge, or discard this patch.
vendor/ayecode/wp-ayecode-ui/includes/ayecode-ui-settings.php 3 patches
Spacing   +381 added lines, -381 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( 'AyeCode_UI_Settings' ) ) {
22
+if (!class_exists('AyeCode_UI_Settings')) {
23 23
 
24 24
 	/**
25 25
 	 * A Class to be able to change settings for Font Awesome.
@@ -98,23 +98,23 @@  discard block
 block discarded – undo
98 98
 		 * @return AyeCode_UI_Settings - Main instance.
99 99
 		 */
100 100
 		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
101
+			if (!isset(self::$instance) && !(self::$instance instanceof AyeCode_UI_Settings)) {
102 102
 
103 103
 				self::$instance = new AyeCode_UI_Settings;
104 104
 
105
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
105
+				add_action('init', array(self::$instance, 'init')); // set settings
106 106
 
107
-				if ( is_admin() ) {
108
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
107
+				if (is_admin()) {
108
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
109
+					add_action('admin_init', array(self::$instance, 'register_settings'));
110 110
 
111 111
 					// Maybe show example page
112
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
112
+					add_action('template_redirect', array(self::$instance, 'maybe_show_examples'));
113 113
 				}
114 114
 
115
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
115
+				add_action('customize_register', array(self::$instance, 'customizer_settings'));
116 116
 
117
-				do_action( 'ayecode_ui_settings_loaded' );
117
+				do_action('ayecode_ui_settings_loaded');
118 118
 			}
119 119
 
120 120
 			return self::$instance;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 		/**
124 124
 		 * Setup some constants.
125 125
 		 */
126
-		public function constants(){
126
+		public function constants() {
127 127
 			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128 128
 			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129 129
 			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
@@ -143,25 +143,25 @@  discard block
 block discarded – undo
143 143
 			 *
144 144
 			 * We load super early in case there is a theme version that might change the colors
145 145
 			 */
146
-			if ( $this->settings['css'] ) {
147
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
146
+			if ($this->settings['css']) {
147
+				add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 1);
148 148
 			}
149
-			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
149
+			if ($this->settings['css_backend'] && $this->load_admin_scripts()) {
150
+				add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 1);
151 151
 			}
152 152
 
153 153
 			// maybe load JS
154
-			if ( $this->settings['js'] ) {
154
+			if ($this->settings['js']) {
155 155
 				$priority = $this->is_bs3_compat() ? 100 : 1;
156
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
156
+				add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), $priority);
157 157
 			}
158
-			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
158
+			if ($this->settings['js_backend'] && $this->load_admin_scripts()) {
159
+				add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 1);
160 160
 			}
161 161
 
162 162
 			// Maybe set the HTML font size
163
-			if ( $this->settings['html_font_size'] ) {
164
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
163
+			if ($this->settings['html_font_size']) {
164
+				add_action('wp_footer', array($this, 'html_font_size'), 10);
165 165
 			}
166 166
 
167 167
 
@@ -172,14 +172,14 @@  discard block
 block discarded – undo
172 172
 		 *
173 173
 		 * @return bool
174 174
 		 */
175
-		public function load_admin_scripts(){
175
+		public function load_admin_scripts() {
176 176
 			$result = true;
177 177
 
178 178
 			// check if specifically disabled
179
-			if(!empty($this->settings['disable_admin'])){
180
-				$url_parts = explode("\n",$this->settings['disable_admin']);
181
-				foreach($url_parts as $part){
182
-					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
179
+			if (!empty($this->settings['disable_admin'])) {
180
+				$url_parts = explode("\n", $this->settings['disable_admin']);
181
+				foreach ($url_parts as $part) {
182
+					if (strpos($_SERVER['REQUEST_URI'], trim($part)) !== false) {
183 183
 						return false; // return early, no point checking further
184 184
 					}
185 185
 				}
@@ -191,9 +191,9 @@  discard block
 block discarded – undo
191 191
 		/**
192 192
 		 * Add a html font size to the footer.
193 193
 		 */
194
-		public function html_font_size(){
194
+		public function html_font_size() {
195 195
 			$this->settings = $this->get_settings();
196
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
196
+			echo "<style>html{font-size:" . absint($this->settings['html_font_size']) . "px;}</style>";
197 197
 		}
198 198
 
199 199
 		/**
@@ -201,10 +201,10 @@  discard block
 block discarded – undo
201 201
 		 * 
202 202
 		 * @return bool
203 203
 		 */
204
-		public function is_aui_screen(){
204
+		public function is_aui_screen() {
205 205
 			$load = false;
206 206
 			// check if we should load or not
207
-			if ( is_admin() ) {
207
+			if (is_admin()) {
208 208
 				// Only enable on set pages
209 209
 				$aui_screens = array(
210 210
 					'page',
@@ -212,13 +212,13 @@  discard block
 block discarded – undo
212 212
 					'settings_page_ayecode-ui-settings',
213 213
 					'appearance_page_gutenberg-widgets'
214 214
 				);
215
-				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
215
+				$screen_ids = apply_filters('aui_screen_ids', $aui_screens);
216 216
 
217 217
 				$screen = get_current_screen();
218 218
 
219 219
 //				echo '###'.$screen->id;
220 220
 				
221
-				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
221
+				if ($screen && in_array($screen->id, $screen_ids)) {
222 222
 					$load = true;
223 223
 				}
224 224
 			}
@@ -231,25 +231,25 @@  discard block
 block discarded – undo
231 231
 		 */
232 232
 		public function enqueue_style() {
233 233
 
234
-			if( is_admin() && !$this->is_aui_screen()){
234
+			if (is_admin() && !$this->is_aui_screen()) {
235 235
 				// don't add wp-admin scripts if not requested to
236
-			}else{
236
+			} else {
237 237
 				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 238
 
239 239
 				$rtl = is_rtl() ? '-rtl' : '';
240 240
 
241
-				if($this->settings[$css_setting]){
242
-					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
-					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
-					wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
-					wp_enqueue_style( 'ayecode-ui' );
241
+				if ($this->settings[$css_setting]) {
242
+					$compatibility = $this->settings[$css_setting] == 'core' ? false : true;
243
+					$url = $this->settings[$css_setting] == 'core' ? $this->url . 'assets/css/ayecode-ui' . $rtl . '.css' : $this->url . 'assets/css/ayecode-ui-compatibility' . $rtl . '.css';
244
+					wp_register_style('ayecode-ui', $url, array(), $this->latest);
245
+					wp_enqueue_style('ayecode-ui');
246 246
 
247 247
 					// flatpickr
248
-					wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
248
+					wp_register_style('flatpickr', $this->url . 'assets/css/flatpickr.min.css', array(), $this->latest);
249 249
 
250 250
 
251 251
 					// fix some wp-admin issues
252
-					if(is_admin()){
252
+					if (is_admin()) {
253 253
 						$custom_css = "
254 254
                 body{
255 255
                     background-color: #f1f1f1;
@@ -295,11 +295,11 @@  discard block
 block discarded – undo
295 295
 						    padding: 0;
296 296
 						}
297 297
 					";
298
-						wp_add_inline_style( 'ayecode-ui', $custom_css );
298
+						wp_add_inline_style('ayecode-ui', $custom_css);
299 299
 					}
300 300
 
301 301
 					// custom changes
302
-					wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
302
+					wp_add_inline_style('ayecode-ui', self::custom_css($compatibility));
303 303
 
304 304
 				}
305 305
 			}
@@ -559,7 +559,7 @@  discard block
 block discarded – undo
559 559
 				function aui_init_flatpickr(){
560 560
 					if ( typeof jQuery.fn.flatpickr === "function" && !$aui_doing_init_flatpickr) {
561 561
 						$aui_doing_init_flatpickr = true;
562
-						<?php if ( ! empty( $flatpickr_locale ) ) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?>
562
+						<?php if (!empty($flatpickr_locale)) { ?>try{flatpickr.localize(<?php echo $flatpickr_locale; ?>);}catch(err){console.log(err.message);}<?php } ?>
563 563
 						jQuery('input[data-aui-init="flatpickr"]:not(.flatpickr-input)').flatpickr();
564 564
 					}
565 565
 					$aui_doing_init_flatpickr = false;
@@ -989,10 +989,10 @@  discard block
 block discarded – undo
989 989
 			/*
990 990
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
991 991
 			 */
992
-			return str_replace( array(
992
+			return str_replace(array(
993 993
 				'<script>',
994 994
 				'</script>'
995
-			), '', self::minify_js($output) );
995
+			), '', self::minify_js($output));
996 996
 		}
997 997
 
998 998
 
@@ -1006,13 +1006,13 @@  discard block
 block discarded – undo
1006 1006
 			ob_start();
1007 1007
 			?>
1008 1008
 			<script>
1009
-				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1009
+				<?php if (defined('FUSION_BUILDER_VERSION')) { ?>
1010 1010
 				/* With Avada builder */
1011 1011
 
1012 1012
 				<?php } ?>
1013 1013
 			</script>
1014 1014
 			<?php
1015
-			return str_replace( array(
1015
+			return str_replace(array(
1016 1016
 				'<script>',
1017 1017
 				'</script>'
1018 1018
 			), '', ob_get_clean());
@@ -1023,7 +1023,7 @@  discard block
 block discarded – undo
1023 1023
 		 *
1024 1024
 		 * If this remains small then its best to use this than to add another JS file.
1025 1025
 		 */
1026
-		public function inline_script_file_browser(){
1026
+		public function inline_script_file_browser() {
1027 1027
 			ob_start();
1028 1028
 			?>
1029 1029
 			<script>
@@ -1038,10 +1038,10 @@  discard block
 block discarded – undo
1038 1038
 			/*
1039 1039
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1040 1040
 			 */
1041
-			return str_replace( array(
1041
+			return str_replace(array(
1042 1042
 				'<script>',
1043 1043
 				'</script>'
1044
-			), '', $output );
1044
+			), '', $output);
1045 1045
 		}
1046 1046
 
1047 1047
 		/**
@@ -1049,50 +1049,50 @@  discard block
 block discarded – undo
1049 1049
 		 */
1050 1050
 		public function enqueue_scripts() {
1051 1051
 
1052
-			if( is_admin() && !$this->is_aui_screen()){
1052
+			if (is_admin() && !$this->is_aui_screen()) {
1053 1053
 				// don't add wp-admin scripts if not requested to
1054
-			}else {
1054
+			} else {
1055 1055
 
1056 1056
 				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1057 1057
 
1058 1058
 				// select2
1059
-				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1059
+				wp_register_script('select2', $this->url . 'assets/js/select2.min.js', array('jquery'), $this->select2_version);
1060 1060
 
1061 1061
 				// flatpickr
1062
-				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1062
+				wp_register_script('flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest);
1063 1063
 
1064 1064
 				// Bootstrap file browser
1065
-				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1066
-				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1065
+				wp_register_script('aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array('jquery'), $this->select2_version);
1066
+				wp_add_inline_script('aui-custom-file-input', $this->inline_script_file_browser());
1067 1067
 
1068 1068
 				$load_inline = false;
1069 1069
 
1070
-				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1070
+				if ($this->settings[$js_setting] == 'core-popper') {
1071 1071
 					// Bootstrap bundle
1072 1072
 					$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1073
-					wp_register_script( 'bootstrap-js-bundle', $url, array(
1073
+					wp_register_script('bootstrap-js-bundle', $url, array(
1074 1074
 						'select2',
1075 1075
 						'jquery'
1076
-					), $this->latest, $this->is_bs3_compat() );
1076
+					), $this->latest, $this->is_bs3_compat());
1077 1077
 					// if in admin then add to footer for compatibility.
1078
-					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1078
+					is_admin() ? wp_enqueue_script('bootstrap-js-bundle', '', null, null, true) : wp_enqueue_script('bootstrap-js-bundle');
1079 1079
 					$script = $this->inline_script();
1080
-					wp_add_inline_script( 'bootstrap-js-bundle', $script );
1081
-				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1080
+					wp_add_inline_script('bootstrap-js-bundle', $script);
1081
+				} elseif ($this->settings[$js_setting] == 'popper') {
1082 1082
 					$url = $this->url . 'assets/js/popper.min.js';
1083
-					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1084
-					wp_enqueue_script( 'bootstrap-js-popper' );
1083
+					wp_register_script('bootstrap-js-popper', $url, array('select2', 'jquery'), $this->latest);
1084
+					wp_enqueue_script('bootstrap-js-popper');
1085 1085
 					$load_inline = true;
1086 1086
 				} else {
1087 1087
 					$load_inline = true;
1088 1088
 				}
1089 1089
 
1090 1090
 				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1091
-				if ( $load_inline ) {
1092
-					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1093
-					wp_enqueue_script( 'bootstrap-dummy' );
1091
+				if ($load_inline) {
1092
+					wp_register_script('bootstrap-dummy', '', array('select2', 'jquery'));
1093
+					wp_enqueue_script('bootstrap-dummy');
1094 1094
 					$script = $this->inline_script();
1095
-					wp_add_inline_script( 'bootstrap-dummy', $script );
1095
+					wp_add_inline_script('bootstrap-dummy', $script);
1096 1096
 				}
1097 1097
 			}
1098 1098
 
@@ -1101,9 +1101,9 @@  discard block
 block discarded – undo
1101 1101
 		/**
1102 1102
 		 * Enqueue flatpickr if called.
1103 1103
 		 */
1104
-		public function enqueue_flatpickr(){
1105
-			wp_enqueue_style( 'flatpickr' );
1106
-			wp_enqueue_script( 'flatpickr' );
1104
+		public function enqueue_flatpickr() {
1105
+			wp_enqueue_style('flatpickr');
1106
+			wp_enqueue_script('flatpickr');
1107 1107
 		}
1108 1108
 
1109 1109
 		/**
@@ -1115,15 +1115,15 @@  discard block
 block discarded – undo
1115 1115
 
1116 1116
 			$url = '';
1117 1117
 			// check if we are inside a plugin
1118
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1118
+			$file_dir = str_replace("/includes", "", wp_normalize_path(dirname(__FILE__)));
1119 1119
 
1120 1120
 			// add check in-case user has changed wp-content dir name.
1121 1121
 			$wp_content_folder_name = basename(WP_CONTENT_DIR);
1122
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1123
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
1122
+			$dir_parts = explode("/$wp_content_folder_name/", $file_dir);
1123
+			$url_parts = explode("/$wp_content_folder_name/", plugins_url());
1124 1124
 
1125
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1126
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1125
+			if (!empty($url_parts[0]) && !empty($dir_parts[1])) {
1126
+				$url = trailingslashit($url_parts[0] . "/$wp_content_folder_name/" . $dir_parts[1]);
1127 1127
 			}
1128 1128
 
1129 1129
 			return $url;
@@ -1133,7 +1133,7 @@  discard block
 block discarded – undo
1133 1133
 		 * Register the database settings with WordPress.
1134 1134
 		 */
1135 1135
 		public function register_settings() {
1136
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1136
+			register_setting('ayecode-ui-settings', 'ayecode-ui-settings');
1137 1137
 		}
1138 1138
 
1139 1139
 		/**
@@ -1142,10 +1142,10 @@  discard block
 block discarded – undo
1142 1142
 		 */
1143 1143
 		public function menu_item() {
1144 1144
 			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1145
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1145
+			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1146 1146
 				$this,
1147 1147
 				'settings_page'
1148
-			) );
1148
+			));
1149 1149
 		}
1150 1150
 
1151 1151
 		/**
@@ -1153,7 +1153,7 @@  discard block
 block discarded – undo
1153 1153
 		 *
1154 1154
 		 * @return array
1155 1155
 		 */
1156
-		public function theme_js_settings(){
1156
+		public function theme_js_settings() {
1157 1157
 			return array(
1158 1158
 				'ayetheme' => 'popper',
1159 1159
 				'listimia' => 'required',
@@ -1169,17 +1169,17 @@  discard block
 block discarded – undo
1169 1169
 		 */
1170 1170
 		public function get_settings() {
1171 1171
 
1172
-			$db_settings = get_option( 'ayecode-ui-settings' );
1172
+			$db_settings = get_option('ayecode-ui-settings');
1173 1173
 			$js_default = 'core-popper';
1174 1174
 			$js_default_backend = $js_default;
1175 1175
 
1176 1176
 			// maybe set defaults (if no settings set)
1177
-			if(empty($db_settings)){
1178
-				$active_theme = strtolower( get_template() ); // active parent theme.
1177
+			if (empty($db_settings)) {
1178
+				$active_theme = strtolower(get_template()); // active parent theme.
1179 1179
 				$theme_js_settings = self::theme_js_settings();
1180
-				if(isset($theme_js_settings[$active_theme])){
1180
+				if (isset($theme_js_settings[$active_theme])) {
1181 1181
 					$js_default = $theme_js_settings[$active_theme];
1182
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1182
+					$js_default_backend = isset($theme_js_settings[$active_theme . "_backend"]) ? $theme_js_settings[$active_theme . "_backend"] : $js_default;
1183 1183
 				}
1184 1184
 			}
1185 1185
 
@@ -1192,14 +1192,14 @@  discard block
 block discarded – undo
1192 1192
 				'disable_admin'     =>  '', // URL snippets to disable loading on admin
1193 1193
 			);
1194 1194
 
1195
-			$settings = wp_parse_args( $db_settings, $defaults );
1195
+			$settings = wp_parse_args($db_settings, $defaults);
1196 1196
 
1197 1197
 			/**
1198 1198
 			 * Filter the Bootstrap settings.
1199 1199
 			 *
1200 1200
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1201 1201
 			 */
1202
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1202
+			return $this->settings = apply_filters('ayecode-ui-settings', $settings, $db_settings, $defaults);
1203 1203
 		}
1204 1204
 
1205 1205
 
@@ -1207,90 +1207,90 @@  discard block
 block discarded – undo
1207 1207
 		 * The settings page html output.
1208 1208
 		 */
1209 1209
 		public function settings_page() {
1210
-			if ( ! current_user_can( 'manage_options' ) ) {
1211
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1210
+			if (!current_user_can('manage_options')) {
1211
+				wp_die(__('You do not have sufficient permissions to access this page.', 'aui'));
1212 1212
 			}
1213 1213
 			?>
1214 1214
 			<div class="wrap">
1215 1215
 				<h1><?php echo $this->name; ?></h1>
1216
-				<p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p>
1216
+				<p><?php _e("Here you can adjust settings if you are having compatibility issues.", 'aui'); ?></p>
1217 1217
 				<form method="post" action="options.php">
1218 1218
 					<?php
1219
-					settings_fields( 'ayecode-ui-settings' );
1220
-					do_settings_sections( 'ayecode-ui-settings' );
1219
+					settings_fields('ayecode-ui-settings');
1220
+					do_settings_sections('ayecode-ui-settings');
1221 1221
 					?>
1222 1222
 
1223
-					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
1223
+					<h2><?php _e('Frontend', 'aui'); ?></h2>
1224 1224
 					<table class="form-table wpbs-table-settings">
1225 1225
 						<tr valign="top">
1226 1226
 							<th scope="row"><label
1227
-									for="wpbs-css"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
1227
+									for="wpbs-css"><?php _e('Load CSS', 'aui'); ?></label></th>
1228 1228
 							<td>
1229 1229
 								<select name="ayecode-ui-settings[css]" id="wpbs-css">
1230
-									<option	value="compatibility" <?php selected( $this->settings['css'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'aui' ); ?></option>
1231
-									<option value="core" <?php selected( $this->settings['css'], 'core' ); ?>><?php _e( 'Full Mode', 'aui' ); ?></option>
1232
-									<option	value="" <?php selected( $this->settings['css'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
1230
+									<option	value="compatibility" <?php selected($this->settings['css'], 'compatibility'); ?>><?php _e('Compatibility Mode (default)', 'aui'); ?></option>
1231
+									<option value="core" <?php selected($this->settings['css'], 'core'); ?>><?php _e('Full Mode', 'aui'); ?></option>
1232
+									<option	value="" <?php selected($this->settings['css'], ''); ?>><?php _e('Disabled', 'aui'); ?></option>
1233 1233
 								</select>
1234 1234
 							</td>
1235 1235
 						</tr>
1236 1236
 
1237 1237
 						<tr valign="top">
1238 1238
 							<th scope="row"><label
1239
-									for="wpbs-js"><?php _e( 'Load JS', 'aui' ); ?></label></th>
1239
+									for="wpbs-js"><?php _e('Load JS', 'aui'); ?></label></th>
1240 1240
 							<td>
1241 1241
 								<select name="ayecode-ui-settings[js]" id="wpbs-js">
1242
-									<option	value="core-popper" <?php selected( $this->settings['js'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
1243
-									<option value="popper" <?php selected( $this->settings['js'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
1244
-									<option value="required" <?php selected( $this->settings['js'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
1245
-									<option	value="" <?php selected( $this->settings['js'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
1242
+									<option	value="core-popper" <?php selected($this->settings['js'], 'core-popper'); ?>><?php _e('Core + Popper (default)', 'aui'); ?></option>
1243
+									<option value="popper" <?php selected($this->settings['js'], 'popper'); ?>><?php _e('Popper', 'aui'); ?></option>
1244
+									<option value="required" <?php selected($this->settings['js'], 'required'); ?>><?php _e('Required functions only', 'aui'); ?></option>
1245
+									<option	value="" <?php selected($this->settings['js'], ''); ?>><?php _e('Disabled (not recommended)', 'aui'); ?></option>
1246 1246
 								</select>
1247 1247
 							</td>
1248 1248
 						</tr>
1249 1249
 
1250 1250
 						<tr valign="top">
1251 1251
 							<th scope="row"><label
1252
-									for="wpbs-font_size"><?php _e( 'HTML Font Size (px)', 'aui' ); ?></label></th>
1252
+									for="wpbs-font_size"><?php _e('HTML Font Size (px)', 'aui'); ?></label></th>
1253 1253
 							<td>
1254
-								<input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint( $this->settings['html_font_size']); ?>" placeholder="16" />
1255
-								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.",'aui');?></p>
1254
+								<input type="number" name="ayecode-ui-settings[html_font_size]" id="wpbs-font_size" value="<?php echo absint($this->settings['html_font_size']); ?>" placeholder="16" />
1255
+								<p class="description" ><?php _e("Our font sizing is rem (responsive based) here you can set the html font size in-case your theme is setting it too low.", 'aui'); ?></p>
1256 1256
 							</td>
1257 1257
 						</tr>
1258 1258
 
1259 1259
 					</table>
1260 1260
 
1261
-					<h2><?php _e( 'Backend', 'aui' ); ?> (wp-admin)</h2>
1261
+					<h2><?php _e('Backend', 'aui'); ?> (wp-admin)</h2>
1262 1262
 					<table class="form-table wpbs-table-settings">
1263 1263
 						<tr valign="top">
1264 1264
 							<th scope="row"><label
1265
-									for="wpbs-css-admin"><?php _e( 'Load CSS', 'aui' ); ?></label></th>
1265
+									for="wpbs-css-admin"><?php _e('Load CSS', 'aui'); ?></label></th>
1266 1266
 							<td>
1267 1267
 								<select name="ayecode-ui-settings[css_backend]" id="wpbs-css-admin">
1268
-									<option	value="compatibility" <?php selected( $this->settings['css_backend'], 'compatibility' ); ?>><?php _e( 'Compatibility Mode (default)', 'aui' ); ?></option>
1269
-									<option value="core" <?php selected( $this->settings['css_backend'], 'core' ); ?>><?php _e( 'Full Mode (will cause style issues)', 'aui' ); ?></option>
1270
-									<option	value="" <?php selected( $this->settings['css_backend'], '' ); ?>><?php _e( 'Disabled', 'aui' ); ?></option>
1268
+									<option	value="compatibility" <?php selected($this->settings['css_backend'], 'compatibility'); ?>><?php _e('Compatibility Mode (default)', 'aui'); ?></option>
1269
+									<option value="core" <?php selected($this->settings['css_backend'], 'core'); ?>><?php _e('Full Mode (will cause style issues)', 'aui'); ?></option>
1270
+									<option	value="" <?php selected($this->settings['css_backend'], ''); ?>><?php _e('Disabled', 'aui'); ?></option>
1271 1271
 								</select>
1272 1272
 							</td>
1273 1273
 						</tr>
1274 1274
 
1275 1275
 						<tr valign="top">
1276 1276
 							<th scope="row"><label
1277
-									for="wpbs-js-admin"><?php _e( 'Load JS', 'aui' ); ?></label></th>
1277
+									for="wpbs-js-admin"><?php _e('Load JS', 'aui'); ?></label></th>
1278 1278
 							<td>
1279 1279
 								<select name="ayecode-ui-settings[js_backend]" id="wpbs-js-admin">
1280
-									<option	value="core-popper" <?php selected( $this->settings['js_backend'], 'core-popper' ); ?>><?php _e( 'Core + Popper (default)', 'aui' ); ?></option>
1281
-									<option value="popper" <?php selected( $this->settings['js_backend'], 'popper' ); ?>><?php _e( 'Popper', 'aui' ); ?></option>
1282
-									<option value="required" <?php selected( $this->settings['js_backend'], 'required' ); ?>><?php _e( 'Required functions only', 'aui' ); ?></option>
1283
-									<option	value="" <?php selected( $this->settings['js_backend'], '' ); ?>><?php _e( 'Disabled (not recommended)', 'aui' ); ?></option>
1280
+									<option	value="core-popper" <?php selected($this->settings['js_backend'], 'core-popper'); ?>><?php _e('Core + Popper (default)', 'aui'); ?></option>
1281
+									<option value="popper" <?php selected($this->settings['js_backend'], 'popper'); ?>><?php _e('Popper', 'aui'); ?></option>
1282
+									<option value="required" <?php selected($this->settings['js_backend'], 'required'); ?>><?php _e('Required functions only', 'aui'); ?></option>
1283
+									<option	value="" <?php selected($this->settings['js_backend'], ''); ?>><?php _e('Disabled (not recommended)', 'aui'); ?></option>
1284 1284
 								</select>
1285 1285
 							</td>
1286 1286
 						</tr>
1287 1287
 
1288 1288
 						<tr valign="top">
1289 1289
 							<th scope="row"><label
1290
-									for="wpbs-disable-admin"><?php _e( 'Disable load on URL', 'aui' ); ?></label></th>
1290
+									for="wpbs-disable-admin"><?php _e('Disable load on URL', 'aui'); ?></label></th>
1291 1291
 							<td>
1292
-								<p><?php _e( 'If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'aui' ); ?></p>
1293
-								<textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php &#10;action=go"><?php echo $this->settings['disable_admin'];?></textarea>
1292
+								<p><?php _e('If you have backend conflict you can enter a partial URL argument that will disable the loading of AUI on those pages. Add each argument on a new line.', 'aui'); ?></p>
1293
+								<textarea name="ayecode-ui-settings[disable_admin]" rows="10" cols="50" id="wpbs-disable-admin" class="large-text code" spellcheck="false" placeholder="myplugin.php &#10;action=go"><?php echo $this->settings['disable_admin']; ?></textarea>
1294 1294
 
1295 1295
 							</td>
1296 1296
 						</tr>
@@ -1308,9 +1308,9 @@  discard block
 block discarded – undo
1308 1308
 			<?php
1309 1309
 		}
1310 1310
 
1311
-		public function customizer_settings($wp_customize){
1311
+		public function customizer_settings($wp_customize) {
1312 1312
 			$wp_customize->add_section('aui_settings', array(
1313
-				'title'    => __('AyeCode UI','aui'),
1313
+				'title'    => __('AyeCode UI', 'aui'),
1314 1314
 				'priority' => 120,
1315 1315
 			));
1316 1316
 
@@ -1324,8 +1324,8 @@  discard block
 block discarded – undo
1324 1324
 				'type'              => 'option',
1325 1325
 				'transport'         => 'refresh',
1326 1326
 			));
1327
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1328
-				'label'    => __('Primary Color','aui'),
1327
+			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1328
+				'label'    => __('Primary Color', 'aui'),
1329 1329
 				'section'  => 'aui_settings',
1330 1330
 				'settings' => 'aui_options[color_primary]',
1331 1331
 			)));
@@ -1337,8 +1337,8 @@  discard block
 block discarded – undo
1337 1337
 				'type'              => 'option',
1338 1338
 				'transport'         => 'refresh',
1339 1339
 			));
1340
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1341
-				'label'    => __('Secondary Color','aui'),
1340
+			$wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1341
+				'label'    => __('Secondary Color', 'aui'),
1342 1342
 				'section'  => 'aui_settings',
1343 1343
 				'settings' => 'aui_options[color_secondary]',
1344 1344
 			)));
@@ -1364,12 +1364,12 @@  discard block
 block discarded – undo
1364 1364
 			.collapse.show:not(.in){display: inherit;}
1365 1365
 			.fade.show{opacity: 1;}
1366 1366
 
1367
-			<?php if( defined( 'SVQ_THEME_VERSION' ) ){ ?>
1367
+			<?php if (defined('SVQ_THEME_VERSION')) { ?>
1368 1368
 			/* KLEO theme specific */
1369 1369
 			.kleo-main-header .navbar-collapse.collapse.show:not(.in){display: block !important;}
1370 1370
 			<?php } ?>
1371 1371
 
1372
-			<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1372
+			<?php if (defined('FUSION_BUILDER_VERSION')) { ?>
1373 1373
 			/* With Avada builder */
1374 1374
 			body.modal-open .modal.in  {opacity:1;z-index: 99999}
1375 1375
 			body.modal-open .modal.bsui.in .modal-content  {box-shadow: none;}
@@ -1377,10 +1377,10 @@  discard block
 block discarded – undo
1377 1377
 			<?php } ?>
1378 1378
 			</style>
1379 1379
 			<?php
1380
-			return str_replace( array(
1380
+			return str_replace(array(
1381 1381
 				'<style>',
1382 1382
 				'</style>'
1383
-			), '', self::minify_css( ob_get_clean() ) );
1383
+			), '', self::minify_css(ob_get_clean()));
1384 1384
 		}
1385 1385
 
1386 1386
 
@@ -1397,16 +1397,16 @@  discard block
 block discarded – undo
1397 1397
 				<?php
1398 1398
 
1399 1399
 					// BS v3 compat
1400
-					if( self::is_bs3_compat() ){
1400
+					if (self::is_bs3_compat()) {
1401 1401
 					    echo self::bs3_compat_css();
1402 1402
 					}
1403 1403
 
1404
-					if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1405
-						echo self::css_primary($primary_color,$compatibility);
1404
+					if (!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL) {
1405
+						echo self::css_primary($primary_color, $compatibility);
1406 1406
 					}
1407 1407
 
1408
-					if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1409
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
1408
+					if (!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL) {
1409
+						echo self::css_secondary($settings['color_secondary'], $compatibility);
1410 1410
 					}
1411 1411
 
1412 1412
 					// Set admin bar z-index lower when modal is open.
@@ -1419,10 +1419,10 @@  discard block
 block discarded – undo
1419 1419
 			/*
1420 1420
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1421 1421
 			 */
1422
-			return str_replace( array(
1422
+			return str_replace(array(
1423 1423
 				'<style>',
1424 1424
 				'</style>'
1425
-			), '', self::minify_css( ob_get_clean() ) );
1425
+			), '', self::minify_css(ob_get_clean()));
1426 1426
 		}
1427 1427
 
1428 1428
 		/**
@@ -1430,48 +1430,48 @@  discard block
 block discarded – undo
1430 1430
 		 *
1431 1431
 		 * @return bool
1432 1432
 		 */
1433
-		public static function is_bs3_compat(){
1433
+		public static function is_bs3_compat() {
1434 1434
 			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1435 1435
 		}
1436 1436
 
1437
-		public static function css_primary($color_code,$compatibility){;
1437
+		public static function css_primary($color_code, $compatibility) {;
1438 1438
 			$color_code = sanitize_hex_color($color_code);
1439
-			if(!$color_code){return '';}
1439
+			if (!$color_code) {return ''; }
1440 1440
 			/**
1441 1441
 			 * c = color, b = background color, o = border-color, f = fill
1442 1442
 			 */
1443 1443
 			$selectors = array(
1444 1444
 				'a' => array('c'),
1445
-				'.btn-primary' => array('b','o'),
1446
-				'.btn-primary.disabled' => array('b','o'),
1447
-				'.btn-primary:disabled' => array('b','o'),
1448
-				'.btn-outline-primary' => array('c','o'),
1449
-				'.btn-outline-primary:hover' => array('b','o'),
1450
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1451
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1452
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1445
+				'.btn-primary' => array('b', 'o'),
1446
+				'.btn-primary.disabled' => array('b', 'o'),
1447
+				'.btn-primary:disabled' => array('b', 'o'),
1448
+				'.btn-outline-primary' => array('c', 'o'),
1449
+				'.btn-outline-primary:hover' => array('b', 'o'),
1450
+				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b', 'o'),
1451
+				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b', 'o'),
1452
+				'.show>.btn-outline-primary.dropdown-toggle' => array('b', 'o'),
1453 1453
 				'.btn-link' => array('c'),
1454 1454
 				'.dropdown-item.active' => array('b'),
1455
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1456
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1455
+				'.custom-control-input:checked~.custom-control-label::before' => array('b', 'o'),
1456
+				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b', 'o'),
1457 1457
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1458 1458
 //				'.custom-range::-moz-range-thumb' => array('b'),
1459 1459
 //				'.custom-range::-ms-thumb' => array('b'),
1460 1460
 				'.nav-pills .nav-link.active' => array('b'),
1461 1461
 				'.nav-pills .show>.nav-link' => array('b'),
1462 1462
 				'.page-link' => array('c'),
1463
-				'.page-item.active .page-link' => array('b','o'),
1463
+				'.page-item.active .page-link' => array('b', 'o'),
1464 1464
 				'.badge-primary' => array('b'),
1465
-				'.alert-primary' => array('b','o'),
1465
+				'.alert-primary' => array('b', 'o'),
1466 1466
 				'.progress-bar' => array('b'),
1467
-				'.list-group-item.active' => array('b','o'),
1468
-				'.bg-primary' => array('b','f'),
1467
+				'.list-group-item.active' => array('b', 'o'),
1468
+				'.bg-primary' => array('b', 'f'),
1469 1469
 				'.btn-link.btn-primary' => array('c'),
1470 1470
 				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1471 1471
 			);
1472 1472
 
1473 1473
 			$important_selectors = array(
1474
-				'.bg-primary' => array('b','f'),
1474
+				'.bg-primary' => array('b', 'f'),
1475 1475
 				'.border-primary' => array('o'),
1476 1476
 				'.text-primary' => array('c'),
1477 1477
 			);
@@ -1488,116 +1488,116 @@  discard block
 block discarded – undo
1488 1488
 			$output = '';
1489 1489
 
1490 1490
 			// build rules into each type
1491
-			foreach($selectors as $selector => $types){
1492
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1493
-				$types = array_combine($types,$types);
1494
-				if(isset($types['c'])){$color[] = $selector;}
1495
-				if(isset($types['b'])){$background[] = $selector;}
1496
-				if(isset($types['o'])){$border[] = $selector;}
1497
-				if(isset($types['f'])){$fill[] = $selector;}
1491
+			foreach ($selectors as $selector => $types) {
1492
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1493
+				$types = array_combine($types, $types);
1494
+				if (isset($types['c'])) {$color[] = $selector; }
1495
+				if (isset($types['b'])) {$background[] = $selector; }
1496
+				if (isset($types['o'])) {$border[] = $selector; }
1497
+				if (isset($types['f'])) {$fill[] = $selector; }
1498 1498
 			}
1499 1499
 
1500 1500
 			// build rules into each type
1501
-			foreach($important_selectors as $selector => $types){
1502
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1503
-				$types = array_combine($types,$types);
1504
-				if(isset($types['c'])){$color_i[] = $selector;}
1505
-				if(isset($types['b'])){$background_i[] = $selector;}
1506
-				if(isset($types['o'])){$border_i[] = $selector;}
1507
-				if(isset($types['f'])){$fill_i[] = $selector;}
1501
+			foreach ($important_selectors as $selector => $types) {
1502
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1503
+				$types = array_combine($types, $types);
1504
+				if (isset($types['c'])) {$color_i[] = $selector; }
1505
+				if (isset($types['b'])) {$background_i[] = $selector; }
1506
+				if (isset($types['o'])) {$border_i[] = $selector; }
1507
+				if (isset($types['f'])) {$fill_i[] = $selector; }
1508 1508
 			}
1509 1509
 
1510 1510
 			// add any color rules
1511
-			if(!empty($color)){
1512
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1511
+			if (!empty($color)) {
1512
+				$output .= implode(",", $color) . "{color: $color_code;} ";
1513 1513
 			}
1514
-			if(!empty($color_i)){
1515
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1514
+			if (!empty($color_i)) {
1515
+				$output .= implode(",", $color_i) . "{color: $color_code !important;} ";
1516 1516
 			}
1517 1517
 
1518 1518
 			// add any background color rules
1519
-			if(!empty($background)){
1520
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1519
+			if (!empty($background)) {
1520
+				$output .= implode(",", $background) . "{background-color: $color_code;} ";
1521 1521
 			}
1522
-			if(!empty($background_i)){
1523
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1522
+			if (!empty($background_i)) {
1523
+				$output .= implode(",", $background_i) . "{background-color: $color_code !important;} ";
1524 1524
 			}
1525 1525
 
1526 1526
 			// add any border color rules
1527
-			if(!empty($border)){
1528
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1527
+			if (!empty($border)) {
1528
+				$output .= implode(",", $border) . "{border-color: $color_code;} ";
1529 1529
 			}
1530
-			if(!empty($border_i)){
1531
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1530
+			if (!empty($border_i)) {
1531
+				$output .= implode(",", $border_i) . "{border-color: $color_code !important;} ";
1532 1532
 			}
1533 1533
 
1534 1534
 			// add any fill color rules
1535
-			if(!empty($fill)){
1536
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1535
+			if (!empty($fill)) {
1536
+				$output .= implode(",", $fill) . "{fill: $color_code;} ";
1537 1537
 			}
1538
-			if(!empty($fill_i)){
1539
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1538
+			if (!empty($fill_i)) {
1539
+				$output .= implode(",", $fill_i) . "{fill: $color_code !important;} ";
1540 1540
 			}
1541 1541
 
1542 1542
 
1543 1543
 			$prefix = $compatibility ? ".bsui " : "";
1544 1544
 
1545 1545
 			// darken
1546
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1547
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1548
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1546
+			$darker_075 = self::css_hex_lighten_darken($color_code, "-0.075");
1547
+			$darker_10 = self::css_hex_lighten_darken($color_code, "-0.10");
1548
+			$darker_125 = self::css_hex_lighten_darken($color_code, "-0.125");
1549 1549
 
1550 1550
 			// lighten
1551
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1551
+			$lighten_25 = self::css_hex_lighten_darken($color_code, "0.25");
1552 1552
 
1553 1553
 			// opacity see https://css-tricks.com/8-digit-hex-codes/
1554
-			$op_25 = $color_code."40"; // 25% opacity
1554
+			$op_25 = $color_code . "40"; // 25% opacity
1555 1555
 
1556 1556
 
1557 1557
 			// button states
1558
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1559
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1560
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1561
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1558
+			$output .= $prefix . " .btn-primary:hover{background-color: " . $darker_075 . ";    border-color: " . $darker_10 . ";} ";
1559
+			$output .= $prefix . " .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1560
+			$output .= $prefix . " .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: " . $darker_10 . ";    border-color: " . $darker_125 . ";} ";
1561
+			$output .= $prefix . " .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1562 1562
 
1563 1563
 
1564 1564
 			// dropdown's
1565
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1565
+			$output .= $prefix . " .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1566 1566
 
1567 1567
 
1568 1568
 			// input states
1569
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1569
+			$output .= $prefix . " .form-control:focus{border-color: " . $lighten_25 . ";box-shadow: 0 0 0 0.2rem $op_25;} ";
1570 1570
 
1571 1571
 			// page link
1572
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1572
+			$output .= $prefix . " .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1573 1573
 
1574 1574
 			return $output;
1575 1575
 		}
1576 1576
 
1577
-		public static function css_secondary($color_code,$compatibility){;
1577
+		public static function css_secondary($color_code, $compatibility) {;
1578 1578
 			$color_code = sanitize_hex_color($color_code);
1579
-			if(!$color_code){return '';}
1579
+			if (!$color_code) {return ''; }
1580 1580
 			/**
1581 1581
 			 * c = color, b = background color, o = border-color, f = fill
1582 1582
 			 */
1583 1583
 			$selectors = array(
1584
-				'.btn-secondary' => array('b','o'),
1585
-				'.btn-secondary.disabled' => array('b','o'),
1586
-				'.btn-secondary:disabled' => array('b','o'),
1587
-				'.btn-outline-secondary' => array('c','o'),
1588
-				'.btn-outline-secondary:hover' => array('b','o'),
1584
+				'.btn-secondary' => array('b', 'o'),
1585
+				'.btn-secondary.disabled' => array('b', 'o'),
1586
+				'.btn-secondary:disabled' => array('b', 'o'),
1587
+				'.btn-outline-secondary' => array('c', 'o'),
1588
+				'.btn-outline-secondary:hover' => array('b', 'o'),
1589 1589
 				'.btn-outline-secondary.disabled' => array('c'),
1590 1590
 				'.btn-outline-secondary:disabled' => array('c'),
1591
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1592
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1593
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1591
+				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b', 'o'),
1592
+				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b', 'o'),
1593
+				'.btn-outline-secondary.dropdown-toggle' => array('b', 'o'),
1594 1594
 				'.badge-secondary' => array('b'),
1595
-				'.alert-secondary' => array('b','o'),
1595
+				'.alert-secondary' => array('b', 'o'),
1596 1596
 				'.btn-link.btn-secondary' => array('c'),
1597 1597
 			);
1598 1598
 
1599 1599
 			$important_selectors = array(
1600
-				'.bg-secondary' => array('b','f'),
1600
+				'.bg-secondary' => array('b', 'f'),
1601 1601
 				'.border-secondary' => array('o'),
1602 1602
 				'.text-secondary' => array('c'),
1603 1603
 			);
@@ -1614,77 +1614,77 @@  discard block
 block discarded – undo
1614 1614
 			$output = '';
1615 1615
 
1616 1616
 			// build rules into each type
1617
-			foreach($selectors as $selector => $types){
1618
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1619
-				$types = array_combine($types,$types);
1620
-				if(isset($types['c'])){$color[] = $selector;}
1621
-				if(isset($types['b'])){$background[] = $selector;}
1622
-				if(isset($types['o'])){$border[] = $selector;}
1623
-				if(isset($types['f'])){$fill[] = $selector;}
1617
+			foreach ($selectors as $selector => $types) {
1618
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1619
+				$types = array_combine($types, $types);
1620
+				if (isset($types['c'])) {$color[] = $selector; }
1621
+				if (isset($types['b'])) {$background[] = $selector; }
1622
+				if (isset($types['o'])) {$border[] = $selector; }
1623
+				if (isset($types['f'])) {$fill[] = $selector; }
1624 1624
 			}
1625 1625
 
1626 1626
 			// build rules into each type
1627
-			foreach($important_selectors as $selector => $types){
1628
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1629
-				$types = array_combine($types,$types);
1630
-				if(isset($types['c'])){$color_i[] = $selector;}
1631
-				if(isset($types['b'])){$background_i[] = $selector;}
1632
-				if(isset($types['o'])){$border_i[] = $selector;}
1633
-				if(isset($types['f'])){$fill_i[] = $selector;}
1627
+			foreach ($important_selectors as $selector => $types) {
1628
+				$selector = $compatibility ? ".bsui " . $selector : $selector;
1629
+				$types = array_combine($types, $types);
1630
+				if (isset($types['c'])) {$color_i[] = $selector; }
1631
+				if (isset($types['b'])) {$background_i[] = $selector; }
1632
+				if (isset($types['o'])) {$border_i[] = $selector; }
1633
+				if (isset($types['f'])) {$fill_i[] = $selector; }
1634 1634
 			}
1635 1635
 
1636 1636
 			// add any color rules
1637
-			if(!empty($color)){
1638
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1637
+			if (!empty($color)) {
1638
+				$output .= implode(",", $color) . "{color: $color_code;} ";
1639 1639
 			}
1640
-			if(!empty($color_i)){
1641
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1640
+			if (!empty($color_i)) {
1641
+				$output .= implode(",", $color_i) . "{color: $color_code !important;} ";
1642 1642
 			}
1643 1643
 
1644 1644
 			// add any background color rules
1645
-			if(!empty($background)){
1646
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1645
+			if (!empty($background)) {
1646
+				$output .= implode(",", $background) . "{background-color: $color_code;} ";
1647 1647
 			}
1648
-			if(!empty($background_i)){
1649
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1648
+			if (!empty($background_i)) {
1649
+				$output .= implode(",", $background_i) . "{background-color: $color_code !important;} ";
1650 1650
 			}
1651 1651
 
1652 1652
 			// add any border color rules
1653
-			if(!empty($border)){
1654
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1653
+			if (!empty($border)) {
1654
+				$output .= implode(",", $border) . "{border-color: $color_code;} ";
1655 1655
 			}
1656
-			if(!empty($border_i)){
1657
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1656
+			if (!empty($border_i)) {
1657
+				$output .= implode(",", $border_i) . "{border-color: $color_code !important;} ";
1658 1658
 			}
1659 1659
 
1660 1660
 			// add any fill color rules
1661
-			if(!empty($fill)){
1662
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1661
+			if (!empty($fill)) {
1662
+				$output .= implode(",", $fill) . "{fill: $color_code;} ";
1663 1663
 			}
1664
-			if(!empty($fill_i)){
1665
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1664
+			if (!empty($fill_i)) {
1665
+				$output .= implode(",", $fill_i) . "{fill: $color_code !important;} ";
1666 1666
 			}
1667 1667
 
1668 1668
 
1669 1669
 			$prefix = $compatibility ? ".bsui " : "";
1670 1670
 
1671 1671
 			// darken
1672
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1673
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1674
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1672
+			$darker_075 = self::css_hex_lighten_darken($color_code, "-0.075");
1673
+			$darker_10 = self::css_hex_lighten_darken($color_code, "-0.10");
1674
+			$darker_125 = self::css_hex_lighten_darken($color_code, "-0.125");
1675 1675
 
1676 1676
 			// lighten
1677
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1677
+			$lighten_25 = self::css_hex_lighten_darken($color_code, "0.25");
1678 1678
 
1679 1679
 			// opacity see https://css-tricks.com/8-digit-hex-codes/
1680
-			$op_25 = $color_code."40"; // 25% opacity
1680
+			$op_25 = $color_code . "40"; // 25% opacity
1681 1681
 
1682 1682
 
1683 1683
 			// button states
1684
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1685
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1686
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1687
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1684
+			$output .= $prefix . " .btn-secondary:hover{background-color: " . $darker_075 . ";    border-color: " . $darker_10 . ";} ";
1685
+			$output .= $prefix . " .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1686
+			$output .= $prefix . " .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: " . $darker_10 . ";    border-color: " . $darker_125 . ";} ";
1687
+			$output .= $prefix . " .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1688 1688
 
1689 1689
 
1690 1690
 			return $output;
@@ -1720,8 +1720,8 @@  discard block
 block discarded – undo
1720 1720
 		/**
1721 1721
 		 * Check if we should display examples.
1722 1722
 		 */
1723
-		public function maybe_show_examples(){
1724
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1723
+		public function maybe_show_examples() {
1724
+			if (current_user_can('manage_options') && isset($_REQUEST['preview-aui'])) {
1725 1725
 				echo "<head>";
1726 1726
 				wp_head();
1727 1727
 				echo "</head>";
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
 		 *
1738 1738
 		 * @return string
1739 1739
 		 */
1740
-		public function get_examples(){
1740
+		public function get_examples() {
1741 1741
 			$output = '';
1742 1742
 
1743 1743
 
@@ -1843,74 +1843,74 @@  discard block
 block discarded – undo
1843 1843
 		 */
1844 1844
 		public static function calendar_params() {
1845 1845
 			$params = array(
1846
-				'month_long_1' => __( 'January', 'aui' ),
1847
-				'month_long_2' => __( 'February', 'aui' ),
1848
-				'month_long_3' => __( 'March', 'aui' ),
1849
-				'month_long_4' => __( 'April', 'aui' ),
1850
-				'month_long_5' => __( 'May', 'aui' ),
1851
-				'month_long_6' => __( 'June', 'aui' ),
1852
-				'month_long_7' => __( 'July', 'aui' ),
1853
-				'month_long_8' => __( 'August', 'aui' ),
1854
-				'month_long_9' => __( 'September', 'aui' ),
1855
-				'month_long_10' => __( 'October', 'aui' ),
1856
-				'month_long_11' => __( 'November', 'aui' ),
1857
-				'month_long_12' => __( 'December', 'aui' ),
1858
-				'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1859
-				'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1860
-				'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1861
-				'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1862
-				'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1863
-				'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1864
-				'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1865
-				'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1866
-				'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1867
-				'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1868
-				'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1869
-				'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1870
-				'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1871
-				'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1872
-				'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1873
-				'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1874
-				'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1875
-				'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1876
-				'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1877
-				'day_s2_1' => __( 'Su', 'aui' ),
1878
-				'day_s2_2' => __( 'Mo', 'aui' ),
1879
-				'day_s2_3' => __( 'Tu', 'aui' ),
1880
-				'day_s2_4' => __( 'We', 'aui' ),
1881
-				'day_s2_5' => __( 'Th', 'aui' ),
1882
-				'day_s2_6' => __( 'Fr', 'aui' ),
1883
-				'day_s2_7' => __( 'Sa', 'aui' ),
1884
-				'day_s3_1' => __( 'Sun', 'aui' ),
1885
-				'day_s3_2' => __( 'Mon', 'aui' ),
1886
-				'day_s3_3' => __( 'Tue', 'aui' ),
1887
-				'day_s3_4' => __( 'Wed', 'aui' ),
1888
-				'day_s3_5' => __( 'Thu', 'aui' ),
1889
-				'day_s3_6' => __( 'Fri', 'aui' ),
1890
-				'day_s3_7' => __( 'Sat', 'aui' ),
1891
-				'day_s5_1' => __( 'Sunday', 'aui' ),
1892
-				'day_s5_2' => __( 'Monday', 'aui' ),
1893
-				'day_s5_3' => __( 'Tuesday', 'aui' ),
1894
-				'day_s5_4' => __( 'Wednesday', 'aui' ),
1895
-				'day_s5_5' => __( 'Thursday', 'aui' ),
1896
-				'day_s5_6' => __( 'Friday', 'aui' ),
1897
-				'day_s5_7' => __( 'Saturday', 'aui' ),
1898
-				'am_lower' => __( 'am', 'aui' ),
1899
-				'pm_lower' => __( 'pm', 'aui' ),
1900
-				'am_upper' => __( 'AM', 'aui' ),
1901
-				'pm_upper' => __( 'PM', 'aui' ),
1902
-				'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1846
+				'month_long_1' => __('January', 'aui'),
1847
+				'month_long_2' => __('February', 'aui'),
1848
+				'month_long_3' => __('March', 'aui'),
1849
+				'month_long_4' => __('April', 'aui'),
1850
+				'month_long_5' => __('May', 'aui'),
1851
+				'month_long_6' => __('June', 'aui'),
1852
+				'month_long_7' => __('July', 'aui'),
1853
+				'month_long_8' => __('August', 'aui'),
1854
+				'month_long_9' => __('September', 'aui'),
1855
+				'month_long_10' => __('October', 'aui'),
1856
+				'month_long_11' => __('November', 'aui'),
1857
+				'month_long_12' => __('December', 'aui'),
1858
+				'month_s_1' => _x('Jan', 'January abbreviation', 'aui'),
1859
+				'month_s_2' => _x('Feb', 'February abbreviation', 'aui'),
1860
+				'month_s_3' => _x('Mar', 'March abbreviation', 'aui'),
1861
+				'month_s_4' => _x('Apr', 'April abbreviation', 'aui'),
1862
+				'month_s_5' => _x('May', 'May abbreviation', 'aui'),
1863
+				'month_s_6' => _x('Jun', 'June abbreviation', 'aui'),
1864
+				'month_s_7' => _x('Jul', 'July abbreviation', 'aui'),
1865
+				'month_s_8' => _x('Aug', 'August abbreviation', 'aui'),
1866
+				'month_s_9' => _x('Sep', 'September abbreviation', 'aui'),
1867
+				'month_s_10' => _x('Oct', 'October abbreviation', 'aui'),
1868
+				'month_s_11' => _x('Nov', 'November abbreviation', 'aui'),
1869
+				'month_s_12' => _x('Dec', 'December abbreviation', 'aui'),
1870
+				'day_s1_1' => _x('S', 'Sunday initial', 'aui'),
1871
+				'day_s1_2' => _x('M', 'Monday initial', 'aui'),
1872
+				'day_s1_3' => _x('T', 'Tuesday initial', 'aui'),
1873
+				'day_s1_4' => _x('W', 'Wednesday initial', 'aui'),
1874
+				'day_s1_5' => _x('T', 'Friday initial', 'aui'),
1875
+				'day_s1_6' => _x('F', 'Thursday initial', 'aui'),
1876
+				'day_s1_7' => _x('S', 'Saturday initial', 'aui'),
1877
+				'day_s2_1' => __('Su', 'aui'),
1878
+				'day_s2_2' => __('Mo', 'aui'),
1879
+				'day_s2_3' => __('Tu', 'aui'),
1880
+				'day_s2_4' => __('We', 'aui'),
1881
+				'day_s2_5' => __('Th', 'aui'),
1882
+				'day_s2_6' => __('Fr', 'aui'),
1883
+				'day_s2_7' => __('Sa', 'aui'),
1884
+				'day_s3_1' => __('Sun', 'aui'),
1885
+				'day_s3_2' => __('Mon', 'aui'),
1886
+				'day_s3_3' => __('Tue', 'aui'),
1887
+				'day_s3_4' => __('Wed', 'aui'),
1888
+				'day_s3_5' => __('Thu', 'aui'),
1889
+				'day_s3_6' => __('Fri', 'aui'),
1890
+				'day_s3_7' => __('Sat', 'aui'),
1891
+				'day_s5_1' => __('Sunday', 'aui'),
1892
+				'day_s5_2' => __('Monday', 'aui'),
1893
+				'day_s5_3' => __('Tuesday', 'aui'),
1894
+				'day_s5_4' => __('Wednesday', 'aui'),
1895
+				'day_s5_5' => __('Thursday', 'aui'),
1896
+				'day_s5_6' => __('Friday', 'aui'),
1897
+				'day_s5_7' => __('Saturday', 'aui'),
1898
+				'am_lower' => __('am', 'aui'),
1899
+				'pm_lower' => __('pm', 'aui'),
1900
+				'am_upper' => __('AM', 'aui'),
1901
+				'pm_upper' => __('PM', 'aui'),
1902
+				'firstDayOfWeek' => (int) get_option('start_of_week'),
1903 1903
 				'time_24hr' => false,
1904
-				'year' => __( 'Year', 'aui' ),
1905
-				'hour' => __( 'Hour', 'aui' ),
1906
-				'minute' => __( 'Minute', 'aui' ),
1907
-				'weekAbbreviation' => __( 'Wk', 'aui' ),
1908
-				'rangeSeparator' => __( ' to ', 'aui' ),
1909
-				'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1910
-				'toggleTitle' => __( 'Click to toggle', 'aui' )
1904
+				'year' => __('Year', 'aui'),
1905
+				'hour' => __('Hour', 'aui'),
1906
+				'minute' => __('Minute', 'aui'),
1907
+				'weekAbbreviation' => __('Wk', 'aui'),
1908
+				'rangeSeparator' => __(' to ', 'aui'),
1909
+				'scrollTitle' => __('Scroll to increment', 'aui'),
1910
+				'toggleTitle' => __('Click to toggle', 'aui')
1911 1911
 			);
1912 1912
 
1913
-			return apply_filters( 'ayecode_ui_calendar_params', $params );
1913
+			return apply_filters('ayecode_ui_calendar_params', $params);
1914 1914
 		}
1915 1915
 
1916 1916
 		/**
@@ -1923,47 +1923,47 @@  discard block
 block discarded – undo
1923 1923
 		public static function flatpickr_locale() {
1924 1924
 			$params = self::calendar_params();
1925 1925
 
1926
-			if ( is_string( $params ) ) {
1927
-				$params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1926
+			if (is_string($params)) {
1927
+				$params = html_entity_decode($params, ENT_QUOTES, 'UTF-8');
1928 1928
 			} else {
1929
-				foreach ( (array) $params as $key => $value ) {
1930
-					if ( ! is_scalar( $value ) ) {
1929
+				foreach ((array) $params as $key => $value) {
1930
+					if (!is_scalar($value)) {
1931 1931
 						continue;
1932 1932
 					}
1933 1933
 
1934
-					$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1934
+					$params[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
1935 1935
 				}
1936 1936
 			}
1937 1937
 
1938 1938
 			$day_s3 = array();
1939 1939
 			$day_s5 = array();
1940 1940
 
1941
-			for ( $i = 1; $i <= 7; $i ++ ) {
1942
-				$day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1943
-				$day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1941
+			for ($i = 1; $i <= 7; $i++) {
1942
+				$day_s3[] = addslashes($params['day_s3_' . $i]);
1943
+				$day_s5[] = addslashes($params['day_s3_' . $i]);
1944 1944
 			}
1945 1945
 
1946 1946
 			$month_s = array();
1947 1947
 			$month_long = array();
1948 1948
 
1949
-			for ( $i = 1; $i <= 12; $i ++ ) {
1950
-				$month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1951
-				$month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1949
+			for ($i = 1; $i <= 12; $i++) {
1950
+				$month_s[] = addslashes($params['month_s_' . $i]);
1951
+				$month_long[] = addslashes($params['month_long_' . $i]);
1952 1952
 			}
1953 1953
 
1954 1954
 ob_start();
1955
-if ( 0 ) { ?><script><?php } ?>
1955
+if (0) { ?><script><?php } ?>
1956 1956
 {
1957 1957
 	weekdays: {
1958
-		shorthand: ['<?php echo implode( "','", $day_s3 ); ?>'],
1959
-		longhand: ['<?php echo implode( "','", $day_s5 ); ?>'],
1958
+		shorthand: ['<?php echo implode("','", $day_s3); ?>'],
1959
+		longhand: ['<?php echo implode("','", $day_s5); ?>'],
1960 1960
 	},
1961 1961
 	months: {
1962
-		shorthand: ['<?php echo implode( "','", $month_s ); ?>'],
1963
-		longhand: ['<?php echo implode( "','", $month_long ); ?>'],
1962
+		shorthand: ['<?php echo implode("','", $month_s); ?>'],
1963
+		longhand: ['<?php echo implode("','", $month_long); ?>'],
1964 1964
 	},
1965 1965
 	daysInMonth: [31,28,31,30,31,30,31,31,30,31,30,31],
1966
-	firstDayOfWeek: <?php echo (int) $params[ 'firstDayOfWeek' ]; ?>,
1966
+	firstDayOfWeek: <?php echo (int) $params['firstDayOfWeek']; ?>,
1967 1967
 	ordinal: function (nth) {
1968 1968
 		var s = nth % 100;
1969 1969
 		if (s > 3 && s < 21)
@@ -1979,21 +1979,21 @@  discard block
 block discarded – undo
1979 1979
 				return "th";
1980 1980
 		}
1981 1981
 	},
1982
-	rangeSeparator: '<?php echo addslashes( $params[ 'rangeSeparator' ] ); ?>',
1983
-	weekAbbreviation: '<?php echo addslashes( $params[ 'weekAbbreviation' ] ); ?>',
1984
-	scrollTitle: '<?php echo addslashes( $params[ 'scrollTitle' ] ); ?>',
1985
-	toggleTitle: '<?php echo addslashes( $params[ 'toggleTitle' ] ); ?>',
1986
-	amPM: ['<?php echo addslashes( $params[ 'am_upper' ] ); ?>','<?php echo addslashes( $params[ 'pm_upper' ] ); ?>'],
1987
-	yearAriaLabel: '<?php echo addslashes( $params[ 'year' ] ); ?>',
1988
-	hourAriaLabel: '<?php echo addslashes( $params[ 'hour' ] ); ?>',
1989
-	minuteAriaLabel: '<?php echo addslashes( $params[ 'minute' ] ); ?>',
1990
-	time_24hr: <?php echo ( $params[ 'time_24hr' ] ? 'true' : 'false' ) ; ?>
1982
+	rangeSeparator: '<?php echo addslashes($params['rangeSeparator']); ?>',
1983
+	weekAbbreviation: '<?php echo addslashes($params['weekAbbreviation']); ?>',
1984
+	scrollTitle: '<?php echo addslashes($params['scrollTitle']); ?>',
1985
+	toggleTitle: '<?php echo addslashes($params['toggleTitle']); ?>',
1986
+	amPM: ['<?php echo addslashes($params['am_upper']); ?>','<?php echo addslashes($params['pm_upper']); ?>'],
1987
+	yearAriaLabel: '<?php echo addslashes($params['year']); ?>',
1988
+	hourAriaLabel: '<?php echo addslashes($params['hour']); ?>',
1989
+	minuteAriaLabel: '<?php echo addslashes($params['minute']); ?>',
1990
+	time_24hr: <?php echo ($params['time_24hr'] ? 'true' : 'false'); ?>
1991 1991
 }
1992
-<?php if ( 0 ) { ?></script><?php } ?>
1992
+<?php if (0) { ?></script><?php } ?>
1993 1993
 <?php
1994 1994
 			$locale = ob_get_clean();
1995 1995
 
1996
-			return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
1996
+			return apply_filters('ayecode_ui_flatpickr_locale', trim($locale));
1997 1997
 		}
1998 1998
 
1999 1999
 		/**
@@ -2005,20 +2005,20 @@  discard block
 block discarded – undo
2005 2005
 		 */
2006 2006
 		public static function select2_params() {
2007 2007
 			$params = array(
2008
-				'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2009
-				'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2010
-				'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2011
-				'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2012
-				'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2013
-				'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2014
-				'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2015
-				'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2016
-				'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2017
-				'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2018
-				'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2008
+				'i18n_select_state_text'    => esc_attr__('Select an option&hellip;', 'aui'),
2009
+				'i18n_no_matches'           => _x('No matches found', 'enhanced select', 'aui'),
2010
+				'i18n_ajax_error'           => _x('Loading failed', 'enhanced select', 'aui'),
2011
+				'i18n_input_too_short_1'    => _x('Please enter 1 or more characters', 'enhanced select', 'aui'),
2012
+				'i18n_input_too_short_n'    => _x('Please enter %item% or more characters', 'enhanced select', 'aui'),
2013
+				'i18n_input_too_long_1'     => _x('Please delete 1 character', 'enhanced select', 'aui'),
2014
+				'i18n_input_too_long_n'     => _x('Please delete %item% characters', 'enhanced select', 'aui'),
2015
+				'i18n_selection_too_long_1' => _x('You can only select 1 item', 'enhanced select', 'aui'),
2016
+				'i18n_selection_too_long_n' => _x('You can only select %item% items', 'enhanced select', 'aui'),
2017
+				'i18n_load_more'            => _x('Loading more results&hellip;', 'enhanced select', 'aui'),
2018
+				'i18n_searching'            => _x('Searching&hellip;', 'enhanced select', 'aui')
2019 2019
 			);
2020 2020
 
2021
-			return apply_filters( 'ayecode_ui_select2_params', $params );
2021
+			return apply_filters('ayecode_ui_select2_params', $params);
2022 2022
 		}
2023 2023
 
2024 2024
 		/**
@@ -2031,17 +2031,17 @@  discard block
 block discarded – undo
2031 2031
 		public static function select2_locale() {
2032 2032
 			$params = self::select2_params();
2033 2033
 
2034
-			foreach ( (array) $params as $key => $value ) {
2035
-				if ( ! is_scalar( $value ) ) {
2034
+			foreach ((array) $params as $key => $value) {
2035
+				if (!is_scalar($value)) {
2036 2036
 					continue;
2037 2037
 				}
2038 2038
 
2039
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2039
+				$params[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
2040 2040
 			}
2041 2041
 
2042
-			$locale = json_encode( $params );
2042
+			$locale = json_encode($params);
2043 2043
 
2044
-			return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2044
+			return apply_filters('ayecode_ui_select2_locale', trim($locale));
2045 2045
 		}
2046 2046
 
2047 2047
 		/**
@@ -2054,35 +2054,35 @@  discard block
 block discarded – undo
2054 2054
 		public static function timeago_locale() {
2055 2055
 			$params = array(
2056 2056
 				'prefix_ago' => '',
2057
-				'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ),
2058
-				'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ',
2057
+				'suffix_ago' => ' ' . _x('ago', 'time ago', 'aui'),
2058
+				'prefix_after' => _x('after', 'time ago', 'aui') . ' ',
2059 2059
 				'suffix_after' => '',
2060
-				'seconds' => _x( 'less than a minute', 'time ago', 'aui' ),
2061
-				'minute' => _x( 'about a minute', 'time ago', 'aui' ),
2062
-				'minutes' => _x( '%d minutes', 'time ago', 'aui' ),
2063
-				'hour' => _x( 'about an hour', 'time ago', 'aui' ),
2064
-				'hours' => _x( 'about %d hours', 'time ago', 'aui' ),
2065
-				'day' => _x( 'a day', 'time ago', 'aui' ),
2066
-				'days' => _x( '%d days', 'time ago', 'aui' ),
2067
-				'month' => _x( 'about a month', 'time ago', 'aui' ),
2068
-				'months' => _x( '%d months', 'time ago', 'aui' ),
2069
-				'year' => _x( 'about a year', 'time ago', 'aui' ),
2070
-				'years' => _x( '%d years', 'time ago', 'aui' ),
2060
+				'seconds' => _x('less than a minute', 'time ago', 'aui'),
2061
+				'minute' => _x('about a minute', 'time ago', 'aui'),
2062
+				'minutes' => _x('%d minutes', 'time ago', 'aui'),
2063
+				'hour' => _x('about an hour', 'time ago', 'aui'),
2064
+				'hours' => _x('about %d hours', 'time ago', 'aui'),
2065
+				'day' => _x('a day', 'time ago', 'aui'),
2066
+				'days' => _x('%d days', 'time ago', 'aui'),
2067
+				'month' => _x('about a month', 'time ago', 'aui'),
2068
+				'months' => _x('%d months', 'time ago', 'aui'),
2069
+				'year' => _x('about a year', 'time ago', 'aui'),
2070
+				'years' => _x('%d years', 'time ago', 'aui'),
2071 2071
 			);
2072 2072
 
2073
-			$params = apply_filters( 'ayecode_ui_timeago_params', $params );
2073
+			$params = apply_filters('ayecode_ui_timeago_params', $params);
2074 2074
 
2075
-			foreach ( (array) $params as $key => $value ) {
2076
-				if ( ! is_scalar( $value ) ) {
2075
+			foreach ((array) $params as $key => $value) {
2076
+				if (!is_scalar($value)) {
2077 2077
 					continue;
2078 2078
 				}
2079 2079
 
2080
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2080
+				$params[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8');
2081 2081
 			}
2082 2082
 
2083
-			$locale = json_encode( $params );
2083
+			$locale = json_encode($params);
2084 2084
 
2085
-			return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2085
+			return apply_filters('ayecode_ui_timeago_locale', trim($locale));
2086 2086
 		}
2087 2087
 
2088 2088
 		/**
@@ -2093,7 +2093,7 @@  discard block
 block discarded – undo
2093 2093
 		 * @return mixed
2094 2094
 		 */
2095 2095
 		public static function minify_js($input) {
2096
-			if(trim($input) === "") return $input;
2096
+			if (trim($input) === "") return $input;
2097 2097
 			return preg_replace(
2098 2098
 				array(
2099 2099
 					// Remove comment(s)
@@ -2125,7 +2125,7 @@  discard block
 block discarded – undo
2125 2125
 		 * @return mixed
2126 2126
 		 */
2127 2127
 		public static function minify_css($input) {
2128
-			if(trim($input) === "") return $input;
2128
+			if (trim($input) === "") return $input;
2129 2129
 			return preg_replace(
2130 2130
 				array(
2131 2131
 					// Remove comment(s)
Please login to merge, or discard this patch.
Braces   +14 added lines, -6 removed lines patch added patch discarded remove patch
@@ -126,8 +126,12 @@  discard block
 block discarded – undo
126 126
 		public function constants(){
127 127
 			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128 128
 			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
-			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
-			if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
129
+			if (!defined('AUI_PRIMARY_COLOR')) {
130
+			    define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
131
+			}
132
+			if (!defined('AUI_SECONDARY_COLOR')) {
133
+			    define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
134
+			}
131 135
 		}
132 136
 
133 137
 		/**
@@ -233,7 +237,7 @@  discard block
 block discarded – undo
233 237
 
234 238
 			if( is_admin() && !$this->is_aui_screen()){
235 239
 				// don't add wp-admin scripts if not requested to
236
-			}else{
240
+			} else{
237 241
 				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 242
 
239 243
 				$rtl = is_rtl() ? '-rtl' : '';
@@ -1051,7 +1055,7 @@  discard block
 block discarded – undo
1051 1055
 
1052 1056
 			if( is_admin() && !$this->is_aui_screen()){
1053 1057
 				// don't add wp-admin scripts if not requested to
1054
-			}else {
1058
+			} else {
1055 1059
 
1056 1060
 				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1057 1061
 
@@ -2093,7 +2097,9 @@  discard block
 block discarded – undo
2093 2097
 		 * @return mixed
2094 2098
 		 */
2095 2099
 		public static function minify_js($input) {
2096
-			if(trim($input) === "") return $input;
2100
+			if(trim($input) === "") {
2101
+			    return $input;
2102
+			}
2097 2103
 			return preg_replace(
2098 2104
 				array(
2099 2105
 					// Remove comment(s)
@@ -2125,7 +2131,9 @@  discard block
 block discarded – undo
2125 2131
 		 * @return mixed
2126 2132
 		 */
2127 2133
 		public static function minify_css($input) {
2128
-			if(trim($input) === "") return $input;
2134
+			if(trim($input) === "") {
2135
+			    return $input;
2136
+			}
2129 2137
 			return preg_replace(
2130 2138
 				array(
2131 2139
 					// Remove comment(s)
Please login to merge, or discard this patch.
Indentation   +1223 added lines, -1223 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,236 +21,236 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'AyeCode_UI_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class AyeCode_UI_Settings
28
-	 * @ver 1.0.0
29
-	 * @todo decide how to implement textdomain
30
-	 */
31
-	class AyeCode_UI_Settings {
32
-
33
-		/**
34
-		 * Class version version.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public $version = '0.1.49';
39
-
40
-		/**
41
-		 * Class textdomain.
42
-		 *
43
-		 * @var string
44
-		 */
45
-		public $textdomain = 'aui';
46
-
47
-		/**
48
-		 * Latest version of Bootstrap at time of publish published.
49
-		 *
50
-		 * @var string
51
-		 */
52
-		public $latest = "4.5.3";
53
-
54
-		/**
55
-		 * Current version of select2 being used.
56
-		 *
57
-		 * @var string
58
-		 */
59
-		public $select2_version = "4.0.11";
60
-
61
-		/**
62
-		 * The title.
63
-		 *
64
-		 * @var string
65
-		 */
66
-		public $name = 'AyeCode UI';
67
-
68
-		/**
69
-		 * The relative url to the assets.
70
-		 *
71
-		 * @var string
72
-		 */
73
-		public $url = '';
74
-
75
-		/**
76
-		 * Holds the settings values.
77
-		 *
78
-		 * @var array
79
-		 */
80
-		private $settings;
81
-
82
-		/**
83
-		 * AyeCode_UI_Settings instance.
84
-		 *
85
-		 * @access private
86
-		 * @since  1.0.0
87
-		 * @var    AyeCode_UI_Settings There can be only one!
88
-		 */
89
-		private static $instance = null;
90
-
91
-		/**
92
-		 * Main AyeCode_UI_Settings Instance.
93
-		 *
94
-		 * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
-		 *
96
-		 * @since 1.0.0
97
-		 * @static
98
-		 * @return AyeCode_UI_Settings - Main instance.
99
-		 */
100
-		public static function instance() {
101
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
-
103
-				self::$instance = new AyeCode_UI_Settings;
104
-
105
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
-
107
-				if ( is_admin() ) {
108
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
-
111
-					// Maybe show example page
112
-					add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
-				}
114
-
115
-				add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
-
117
-				do_action( 'ayecode_ui_settings_loaded' );
118
-			}
119
-
120
-			return self::$instance;
121
-		}
122
-
123
-		/**
124
-		 * Setup some constants.
125
-		 */
126
-		public function constants(){
127
-			define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
-			define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
-			if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
-			if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
-		}
132
-
133
-		/**
134
-		 * Initiate the settings and add the required action hooks.
135
-		 */
136
-		public function init() {
137
-			$this->constants();
138
-			$this->settings = $this->get_settings();
139
-			$this->url = $this->get_url();
140
-
141
-			/**
142
-			 * Maybe load CSS
143
-			 *
144
-			 * We load super early in case there is a theme version that might change the colors
145
-			 */
146
-			if ( $this->settings['css'] ) {
147
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
-			}
149
-			if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
-			}
152
-
153
-			// maybe load JS
154
-			if ( $this->settings['js'] ) {
155
-				$priority = $this->is_bs3_compat() ? 100 : 1;
156
-				add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
-			}
158
-			if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
-				add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
-			}
161
-
162
-			// Maybe set the HTML font size
163
-			if ( $this->settings['html_font_size'] ) {
164
-				add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
-			}
166
-
167
-
168
-		}
169
-
170
-		/**
171
-		 * Check if we should load the admin scripts or not.
172
-		 *
173
-		 * @return bool
174
-		 */
175
-		public function load_admin_scripts(){
176
-			$result = true;
177
-
178
-			// check if specifically disabled
179
-			if(!empty($this->settings['disable_admin'])){
180
-				$url_parts = explode("\n",$this->settings['disable_admin']);
181
-				foreach($url_parts as $part){
182
-					if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
-						return false; // return early, no point checking further
184
-					}
185
-				}
186
-			}
187
-
188
-			return $result;
189
-		}
190
-
191
-		/**
192
-		 * Add a html font size to the footer.
193
-		 */
194
-		public function html_font_size(){
195
-			$this->settings = $this->get_settings();
196
-			echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
-		}
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class AyeCode_UI_Settings
28
+     * @ver 1.0.0
29
+     * @todo decide how to implement textdomain
30
+     */
31
+    class AyeCode_UI_Settings {
32
+
33
+        /**
34
+         * Class version version.
35
+         *
36
+         * @var string
37
+         */
38
+        public $version = '0.1.49';
39
+
40
+        /**
41
+         * Class textdomain.
42
+         *
43
+         * @var string
44
+         */
45
+        public $textdomain = 'aui';
46
+
47
+        /**
48
+         * Latest version of Bootstrap at time of publish published.
49
+         *
50
+         * @var string
51
+         */
52
+        public $latest = "4.5.3";
53
+
54
+        /**
55
+         * Current version of select2 being used.
56
+         *
57
+         * @var string
58
+         */
59
+        public $select2_version = "4.0.11";
60
+
61
+        /**
62
+         * The title.
63
+         *
64
+         * @var string
65
+         */
66
+        public $name = 'AyeCode UI';
67
+
68
+        /**
69
+         * The relative url to the assets.
70
+         *
71
+         * @var string
72
+         */
73
+        public $url = '';
74
+
75
+        /**
76
+         * Holds the settings values.
77
+         *
78
+         * @var array
79
+         */
80
+        private $settings;
81
+
82
+        /**
83
+         * AyeCode_UI_Settings instance.
84
+         *
85
+         * @access private
86
+         * @since  1.0.0
87
+         * @var    AyeCode_UI_Settings There can be only one!
88
+         */
89
+        private static $instance = null;
90
+
91
+        /**
92
+         * Main AyeCode_UI_Settings Instance.
93
+         *
94
+         * Ensures only one instance of AyeCode_UI_Settings is loaded or can be loaded.
95
+         *
96
+         * @since 1.0.0
97
+         * @static
98
+         * @return AyeCode_UI_Settings - Main instance.
99
+         */
100
+        public static function instance() {
101
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof AyeCode_UI_Settings ) ) {
102
+
103
+                self::$instance = new AyeCode_UI_Settings;
104
+
105
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
106
+
107
+                if ( is_admin() ) {
108
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
109
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
110
+
111
+                    // Maybe show example page
112
+                    add_action( 'template_redirect', array( self::$instance,'maybe_show_examples' ) );
113
+                }
198 114
 
199
-		/**
200
-		 * Check if the current admin screen should load scripts.
201
-		 * 
202
-		 * @return bool
203
-		 */
204
-		public function is_aui_screen(){
205
-			$load = false;
206
-			// check if we should load or not
207
-			if ( is_admin() ) {
208
-				// Only enable on set pages
209
-				$aui_screens = array(
210
-					'page',
211
-					'post',
212
-					'settings_page_ayecode-ui-settings',
213
-					'appearance_page_gutenberg-widgets'
214
-				);
215
-				$screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
216
-
217
-				$screen = get_current_screen();
115
+                add_action( 'customize_register', array( self::$instance, 'customizer_settings' ));
116
+
117
+                do_action( 'ayecode_ui_settings_loaded' );
118
+            }
119
+
120
+            return self::$instance;
121
+        }
122
+
123
+        /**
124
+         * Setup some constants.
125
+         */
126
+        public function constants(){
127
+            define('AUI_PRIMARY_COLOR_ORIGINAL', "#1e73be");
128
+            define('AUI_SECONDARY_COLOR_ORIGINAL', '#6c757d');
129
+            if (!defined('AUI_PRIMARY_COLOR')) define('AUI_PRIMARY_COLOR', AUI_PRIMARY_COLOR_ORIGINAL);
130
+            if (!defined('AUI_SECONDARY_COLOR')) define('AUI_SECONDARY_COLOR', AUI_SECONDARY_COLOR_ORIGINAL);
131
+        }
132
+
133
+        /**
134
+         * Initiate the settings and add the required action hooks.
135
+         */
136
+        public function init() {
137
+            $this->constants();
138
+            $this->settings = $this->get_settings();
139
+            $this->url = $this->get_url();
140
+
141
+            /**
142
+             * Maybe load CSS
143
+             *
144
+             * We load super early in case there is a theme version that might change the colors
145
+             */
146
+            if ( $this->settings['css'] ) {
147
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
148
+            }
149
+            if ( $this->settings['css_backend'] && $this->load_admin_scripts() ) {
150
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 1 );
151
+            }
152
+
153
+            // maybe load JS
154
+            if ( $this->settings['js'] ) {
155
+                $priority = $this->is_bs3_compat() ? 100 : 1;
156
+                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), $priority );
157
+            }
158
+            if ( $this->settings['js_backend'] && $this->load_admin_scripts() ) {
159
+                add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 1 );
160
+            }
161
+
162
+            // Maybe set the HTML font size
163
+            if ( $this->settings['html_font_size'] ) {
164
+                add_action( 'wp_footer', array( $this, 'html_font_size' ), 10 );
165
+            }
166
+
167
+
168
+        }
169
+
170
+        /**
171
+         * Check if we should load the admin scripts or not.
172
+         *
173
+         * @return bool
174
+         */
175
+        public function load_admin_scripts(){
176
+            $result = true;
177
+
178
+            // check if specifically disabled
179
+            if(!empty($this->settings['disable_admin'])){
180
+                $url_parts = explode("\n",$this->settings['disable_admin']);
181
+                foreach($url_parts as $part){
182
+                    if( strpos($_SERVER['REQUEST_URI'], trim($part)) !== false ){
183
+                        return false; // return early, no point checking further
184
+                    }
185
+                }
186
+            }
187
+
188
+            return $result;
189
+        }
190
+
191
+        /**
192
+         * Add a html font size to the footer.
193
+         */
194
+        public function html_font_size(){
195
+            $this->settings = $this->get_settings();
196
+            echo "<style>html{font-size:".absint($this->settings['html_font_size'])."px;}</style>";
197
+        }
198
+
199
+        /**
200
+         * Check if the current admin screen should load scripts.
201
+         * 
202
+         * @return bool
203
+         */
204
+        public function is_aui_screen(){
205
+            $load = false;
206
+            // check if we should load or not
207
+            if ( is_admin() ) {
208
+                // Only enable on set pages
209
+                $aui_screens = array(
210
+                    'page',
211
+                    'post',
212
+                    'settings_page_ayecode-ui-settings',
213
+                    'appearance_page_gutenberg-widgets'
214
+                );
215
+                $screen_ids = apply_filters( 'aui_screen_ids', $aui_screens );
216
+
217
+                $screen = get_current_screen();
218 218
 
219 219
 //				echo '###'.$screen->id;
220 220
 				
221
-				if ( $screen && in_array( $screen->id, $screen_ids ) ) {
222
-					$load = true;
223
-				}
224
-			}
221
+                if ( $screen && in_array( $screen->id, $screen_ids ) ) {
222
+                    $load = true;
223
+                }
224
+            }
225 225
 
226
-			return $load;
227
-		}
226
+            return $load;
227
+        }
228 228
 
229
-		/**
230
-		 * Adds the styles.
231
-		 */
232
-		public function enqueue_style() {
229
+        /**
230
+         * Adds the styles.
231
+         */
232
+        public function enqueue_style() {
233 233
 
234
-			if( is_admin() && !$this->is_aui_screen()){
235
-				// don't add wp-admin scripts if not requested to
236
-			}else{
237
-				$css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
234
+            if( is_admin() && !$this->is_aui_screen()){
235
+                // don't add wp-admin scripts if not requested to
236
+            }else{
237
+                $css_setting = current_action() == 'wp_enqueue_scripts' ? 'css' : 'css_backend';
238 238
 
239
-				$rtl = is_rtl() ? '-rtl' : '';
239
+                $rtl = is_rtl() ? '-rtl' : '';
240 240
 
241
-				if($this->settings[$css_setting]){
242
-					$compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
-					$url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
-					wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
-					wp_enqueue_style( 'ayecode-ui' );
241
+                if($this->settings[$css_setting]){
242
+                    $compatibility = $this->settings[$css_setting]=='core' ? false : true;
243
+                    $url = $this->settings[$css_setting]=='core' ? $this->url.'assets/css/ayecode-ui'.$rtl.'.css' : $this->url.'assets/css/ayecode-ui-compatibility'.$rtl.'.css';
244
+                    wp_register_style( 'ayecode-ui', $url, array(), $this->latest );
245
+                    wp_enqueue_style( 'ayecode-ui' );
246 246
 
247
-					// flatpickr
248
-					wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
247
+                    // flatpickr
248
+                    wp_register_style( 'flatpickr', $this->url.'assets/css/flatpickr.min.css', array(), $this->latest );
249 249
 
250 250
 
251
-					// fix some wp-admin issues
252
-					if(is_admin()){
253
-						$custom_css = "
251
+                    // fix some wp-admin issues
252
+                    if(is_admin()){
253
+                        $custom_css = "
254 254
                 body{
255 255
                     background-color: #f1f1f1;
256 256
                     font-family: -apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Oxygen-Sans,Ubuntu,Cantarell,\"Helvetica Neue\",sans-serif;
@@ -292,35 +292,35 @@  discard block
 block discarded – undo
292 292
 				}
293 293
                 ";
294 294
 
295
-						// @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
296
-						$custom_css .= "
295
+                        // @todo, remove once fixed :: fix for this bug https://github.com/WordPress/gutenberg/issues/14377
296
+                        $custom_css .= "
297 297
 						.edit-post-sidebar input[type=color].components-text-control__input{
298 298
 						    padding: 0;
299 299
 						}
300 300
 					";
301
-						wp_add_inline_style( 'ayecode-ui', $custom_css );
302
-					}
301
+                        wp_add_inline_style( 'ayecode-ui', $custom_css );
302
+                    }
303 303
 
304
-					// custom changes
305
-					wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
304
+                    // custom changes
305
+                    wp_add_inline_style( 'ayecode-ui', self::custom_css($compatibility) );
306 306
 
307
-				}
308
-			}
307
+                }
308
+            }
309 309
 
310 310
 
311
-		}
311
+        }
312
+
313
+        /**
314
+         * Get inline script used if bootstrap enqueued
315
+         *
316
+         * If this remains small then its best to use this than to add another JS file.
317
+         */
318
+        public function inline_script() {
319
+            // Flatpickr calendar locale
320
+            $flatpickr_locale = self::flatpickr_locale();
312 321
 
313
-		/**
314
-		 * Get inline script used if bootstrap enqueued
315
-		 *
316
-		 * If this remains small then its best to use this than to add another JS file.
317
-		 */
318
-		public function inline_script() {
319
-			// Flatpickr calendar locale
320
-			$flatpickr_locale = self::flatpickr_locale();
321
-
322
-			ob_start();
323
-			?>
322
+            ob_start();
323
+            ?>
324 324
 			<script>
325 325
 				/**
326 326
 				 * An AUI bootstrap adaptation of GreedyNav.js ( by Luke Jackson ).
@@ -985,29 +985,29 @@  discard block
 block discarded – undo
985 985
 
986 986
 			</script>
987 987
 			<?php
988
-			$output = ob_get_clean();
988
+            $output = ob_get_clean();
989 989
 
990 990
 
991 991
 
992
-			/*
992
+            /*
993 993
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
994 994
 			 */
995
-			return str_replace( array(
996
-				'<script>',
997
-				'</script>'
998
-			), '', self::minify_js($output) );
999
-		}
1000
-
1001
-
1002
-		/**
1003
-		 * JS to help with conflict issues with other plugins and themes using bootstrap v3.
1004
-		 *
1005
-		 * @TODO we may need this when other conflicts arrise.
1006
-		 * @return mixed
1007
-		 */
1008
-		public static function bs3_compat_js() {
1009
-			ob_start();
1010
-			?>
995
+            return str_replace( array(
996
+                '<script>',
997
+                '</script>'
998
+            ), '', self::minify_js($output) );
999
+        }
1000
+
1001
+
1002
+        /**
1003
+         * JS to help with conflict issues with other plugins and themes using bootstrap v3.
1004
+         *
1005
+         * @TODO we may need this when other conflicts arrise.
1006
+         * @return mixed
1007
+         */
1008
+        public static function bs3_compat_js() {
1009
+            ob_start();
1010
+            ?>
1011 1011
 			<script>
1012 1012
 				<?php if( defined( 'FUSION_BUILDER_VERSION' ) ){ ?>
1013 1013
 				/* With Avada builder */
@@ -1015,20 +1015,20 @@  discard block
 block discarded – undo
1015 1015
 				<?php } ?>
1016 1016
 			</script>
1017 1017
 			<?php
1018
-			return str_replace( array(
1019
-				'<script>',
1020
-				'</script>'
1021
-			), '', ob_get_clean());
1022
-		}
1023
-
1024
-		/**
1025
-		 * Get inline script used if bootstrap file browser enqueued.
1026
-		 *
1027
-		 * If this remains small then its best to use this than to add another JS file.
1028
-		 */
1029
-		public function inline_script_file_browser(){
1030
-			ob_start();
1031
-			?>
1018
+            return str_replace( array(
1019
+                '<script>',
1020
+                '</script>'
1021
+            ), '', ob_get_clean());
1022
+        }
1023
+
1024
+        /**
1025
+         * Get inline script used if bootstrap file browser enqueued.
1026
+         *
1027
+         * If this remains small then its best to use this than to add another JS file.
1028
+         */
1029
+        public function inline_script_file_browser(){
1030
+            ob_start();
1031
+            ?>
1032 1032
 			<script>
1033 1033
 				// run on doc ready
1034 1034
 				jQuery(document).ready(function () {
@@ -1036,192 +1036,192 @@  discard block
 block discarded – undo
1036 1036
 				});
1037 1037
 			</script>
1038 1038
 			<?php
1039
-			$output = ob_get_clean();
1039
+            $output = ob_get_clean();
1040 1040
 
1041
-			/*
1041
+            /*
1042 1042
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1043 1043
 			 */
1044
-			return str_replace( array(
1045
-				'<script>',
1046
-				'</script>'
1047
-			), '', $output );
1048
-		}
1049
-
1050
-		/**
1051
-		 * Adds the Font Awesome JS.
1052
-		 */
1053
-		public function enqueue_scripts() {
1054
-
1055
-			if( is_admin() && !$this->is_aui_screen()){
1056
-				// don't add wp-admin scripts if not requested to
1057
-			}else {
1058
-
1059
-				$js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1060
-
1061
-				// select2
1062
-				wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1063
-
1064
-				// flatpickr
1065
-				wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1066
-
1067
-				// Bootstrap file browser
1068
-				wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1069
-				wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1070
-
1071
-				$load_inline = false;
1072
-
1073
-				if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1074
-					// Bootstrap bundle
1075
-					$url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1076
-					wp_register_script( 'bootstrap-js-bundle', $url, array(
1077
-						'select2',
1078
-						'jquery'
1079
-					), $this->latest, $this->is_bs3_compat() );
1080
-					// if in admin then add to footer for compatibility.
1081
-					is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1082
-					$script = $this->inline_script();
1083
-					wp_add_inline_script( 'bootstrap-js-bundle', $script );
1084
-				} elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1085
-					$url = $this->url . 'assets/js/popper.min.js';
1086
-					wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1087
-					wp_enqueue_script( 'bootstrap-js-popper' );
1088
-					$load_inline = true;
1089
-				} else {
1090
-					$load_inline = true;
1091
-				}
1092
-
1093
-				// Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1094
-				if ( $load_inline ) {
1095
-					wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1096
-					wp_enqueue_script( 'bootstrap-dummy' );
1097
-					$script = $this->inline_script();
1098
-					wp_add_inline_script( 'bootstrap-dummy', $script );
1099
-				}
1100
-			}
1101
-
1102
-		}
1103
-
1104
-		/**
1105
-		 * Enqueue flatpickr if called.
1106
-		 */
1107
-		public function enqueue_flatpickr(){
1108
-			wp_enqueue_style( 'flatpickr' );
1109
-			wp_enqueue_script( 'flatpickr' );
1110
-		}
1111
-
1112
-		/**
1113
-		 * Get the url path to the current folder.
1114
-		 *
1115
-		 * @return string
1116
-		 */
1117
-		public function get_url() {
1118
-
1119
-			$url = '';
1120
-			// check if we are inside a plugin
1121
-			$file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1122
-
1123
-			// add check in-case user has changed wp-content dir name.
1124
-			$wp_content_folder_name = basename(WP_CONTENT_DIR);
1125
-			$dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1126
-			$url_parts = explode("/$wp_content_folder_name/",plugins_url());
1127
-
1128
-			if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1129
-				$url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1130
-			}
1131
-
1132
-			return $url;
1133
-		}
1134
-
1135
-		/**
1136
-		 * Register the database settings with WordPress.
1137
-		 */
1138
-		public function register_settings() {
1139
-			register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1140
-		}
1141
-
1142
-		/**
1143
-		 * Add the WordPress settings menu item.
1144
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
1145
-		 */
1146
-		public function menu_item() {
1147
-			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1148
-			call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1149
-				$this,
1150
-				'settings_page'
1151
-			) );
1152
-		}
1153
-
1154
-		/**
1155
-		 * Get a list of themes and their default JS settings.
1156
-		 *
1157
-		 * @return array
1158
-		 */
1159
-		public function theme_js_settings(){
1160
-			return array(
1161
-				'ayetheme' => 'popper',
1162
-				'listimia' => 'required',
1163
-				'listimia_backend' => 'core-popper',
1164
-				//'avada'    => 'required', // removed as we now add compatibility
1165
-			);
1166
-		}
1167
-
1168
-		/**
1169
-		 * Get the current Font Awesome output settings.
1170
-		 *
1171
-		 * @return array The array of settings.
1172
-		 */
1173
-		public function get_settings() {
1174
-
1175
-			$db_settings = get_option( 'ayecode-ui-settings' );
1176
-			$js_default = 'core-popper';
1177
-			$js_default_backend = $js_default;
1178
-
1179
-			// maybe set defaults (if no settings set)
1180
-			if(empty($db_settings)){
1181
-				$active_theme = strtolower( get_template() ); // active parent theme.
1182
-				$theme_js_settings = self::theme_js_settings();
1183
-				if(isset($theme_js_settings[$active_theme])){
1184
-					$js_default = $theme_js_settings[$active_theme];
1185
-					$js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1186
-				}
1187
-			}
1188
-
1189
-			$defaults = array(
1190
-				'css'       => 'compatibility', // core, compatibility
1191
-				'js'        => $js_default, // js to load, core-popper, popper
1192
-				'html_font_size'        => '16', // js to load, core-popper, popper
1193
-				'css_backend'       => 'compatibility', // core, compatibility
1194
-				'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1195
-				'disable_admin'     =>  '', // URL snippets to disable loading on admin
1196
-			);
1197
-
1198
-			$settings = wp_parse_args( $db_settings, $defaults );
1199
-
1200
-			/**
1201
-			 * Filter the Bootstrap settings.
1202
-			 *
1203
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1204
-			 */
1205
-			return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1206
-		}
1207
-
1044
+            return str_replace( array(
1045
+                '<script>',
1046
+                '</script>'
1047
+            ), '', $output );
1048
+        }
1049
+
1050
+        /**
1051
+         * Adds the Font Awesome JS.
1052
+         */
1053
+        public function enqueue_scripts() {
1054
+
1055
+            if( is_admin() && !$this->is_aui_screen()){
1056
+                // don't add wp-admin scripts if not requested to
1057
+            }else {
1058
+
1059
+                $js_setting = current_action() == 'wp_enqueue_scripts' ? 'js' : 'js_backend';
1060
+
1061
+                // select2
1062
+                wp_register_script( 'select2', $this->url . 'assets/js/select2.min.js', array( 'jquery' ), $this->select2_version );
1063
+
1064
+                // flatpickr
1065
+                wp_register_script( 'flatpickr', $this->url . 'assets/js/flatpickr.min.js', array(), $this->latest );
1066
+
1067
+                // Bootstrap file browser
1068
+                wp_register_script( 'aui-custom-file-input', $url = $this->url . 'assets/js/bs-custom-file-input.min.js', array( 'jquery' ), $this->select2_version );
1069
+                wp_add_inline_script( 'aui-custom-file-input', $this->inline_script_file_browser() );
1070
+
1071
+                $load_inline = false;
1072
+
1073
+                if ( $this->settings[ $js_setting ] == 'core-popper' ) {
1074
+                    // Bootstrap bundle
1075
+                    $url = $this->url . 'assets/js/bootstrap.bundle.min.js';
1076
+                    wp_register_script( 'bootstrap-js-bundle', $url, array(
1077
+                        'select2',
1078
+                        'jquery'
1079
+                    ), $this->latest, $this->is_bs3_compat() );
1080
+                    // if in admin then add to footer for compatibility.
1081
+                    is_admin() ? wp_enqueue_script( 'bootstrap-js-bundle', '', null, null, true ) : wp_enqueue_script( 'bootstrap-js-bundle' );
1082
+                    $script = $this->inline_script();
1083
+                    wp_add_inline_script( 'bootstrap-js-bundle', $script );
1084
+                } elseif ( $this->settings[ $js_setting ] == 'popper' ) {
1085
+                    $url = $this->url . 'assets/js/popper.min.js';
1086
+                    wp_register_script( 'bootstrap-js-popper', $url, array( 'select2', 'jquery' ), $this->latest );
1087
+                    wp_enqueue_script( 'bootstrap-js-popper' );
1088
+                    $load_inline = true;
1089
+                } else {
1090
+                    $load_inline = true;
1091
+                }
1208 1092
 
1209
-		/**
1210
-		 * The settings page html output.
1211
-		 */
1212
-		public function settings_page() {
1213
-			if ( ! current_user_can( 'manage_options' ) ) {
1214
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1215
-			}
1216
-			?>
1093
+                // Load needed inline scripts by faking the loading of a script if the main script is not being loaded
1094
+                if ( $load_inline ) {
1095
+                    wp_register_script( 'bootstrap-dummy', '', array( 'select2', 'jquery' ) );
1096
+                    wp_enqueue_script( 'bootstrap-dummy' );
1097
+                    $script = $this->inline_script();
1098
+                    wp_add_inline_script( 'bootstrap-dummy', $script );
1099
+                }
1100
+            }
1101
+
1102
+        }
1103
+
1104
+        /**
1105
+         * Enqueue flatpickr if called.
1106
+         */
1107
+        public function enqueue_flatpickr(){
1108
+            wp_enqueue_style( 'flatpickr' );
1109
+            wp_enqueue_script( 'flatpickr' );
1110
+        }
1111
+
1112
+        /**
1113
+         * Get the url path to the current folder.
1114
+         *
1115
+         * @return string
1116
+         */
1117
+        public function get_url() {
1118
+
1119
+            $url = '';
1120
+            // check if we are inside a plugin
1121
+            $file_dir = str_replace( "/includes","", wp_normalize_path( dirname( __FILE__ ) ) );
1122
+
1123
+            // add check in-case user has changed wp-content dir name.
1124
+            $wp_content_folder_name = basename(WP_CONTENT_DIR);
1125
+            $dir_parts = explode("/$wp_content_folder_name/",$file_dir);
1126
+            $url_parts = explode("/$wp_content_folder_name/",plugins_url());
1127
+
1128
+            if(!empty($url_parts[0]) && !empty($dir_parts[1])){
1129
+                $url = trailingslashit( $url_parts[0]."/$wp_content_folder_name/".$dir_parts[1] );
1130
+            }
1131
+
1132
+            return $url;
1133
+        }
1134
+
1135
+        /**
1136
+         * Register the database settings with WordPress.
1137
+         */
1138
+        public function register_settings() {
1139
+            register_setting( 'ayecode-ui-settings', 'ayecode-ui-settings' );
1140
+        }
1141
+
1142
+        /**
1143
+         * Add the WordPress settings menu item.
1144
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
1145
+         */
1146
+        public function menu_item() {
1147
+            $menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
1148
+            call_user_func( $menu_function, $this->name, $this->name, 'manage_options', 'ayecode-ui-settings', array(
1149
+                $this,
1150
+                'settings_page'
1151
+            ) );
1152
+        }
1153
+
1154
+        /**
1155
+         * Get a list of themes and their default JS settings.
1156
+         *
1157
+         * @return array
1158
+         */
1159
+        public function theme_js_settings(){
1160
+            return array(
1161
+                'ayetheme' => 'popper',
1162
+                'listimia' => 'required',
1163
+                'listimia_backend' => 'core-popper',
1164
+                //'avada'    => 'required', // removed as we now add compatibility
1165
+            );
1166
+        }
1167
+
1168
+        /**
1169
+         * Get the current Font Awesome output settings.
1170
+         *
1171
+         * @return array The array of settings.
1172
+         */
1173
+        public function get_settings() {
1174
+
1175
+            $db_settings = get_option( 'ayecode-ui-settings' );
1176
+            $js_default = 'core-popper';
1177
+            $js_default_backend = $js_default;
1178
+
1179
+            // maybe set defaults (if no settings set)
1180
+            if(empty($db_settings)){
1181
+                $active_theme = strtolower( get_template() ); // active parent theme.
1182
+                $theme_js_settings = self::theme_js_settings();
1183
+                if(isset($theme_js_settings[$active_theme])){
1184
+                    $js_default = $theme_js_settings[$active_theme];
1185
+                    $js_default_backend = isset($theme_js_settings[$active_theme."_backend"]) ? $theme_js_settings[$active_theme."_backend"] : $js_default;
1186
+                }
1187
+            }
1188
+
1189
+            $defaults = array(
1190
+                'css'       => 'compatibility', // core, compatibility
1191
+                'js'        => $js_default, // js to load, core-popper, popper
1192
+                'html_font_size'        => '16', // js to load, core-popper, popper
1193
+                'css_backend'       => 'compatibility', // core, compatibility
1194
+                'js_backend'        => $js_default_backend, // js to load, core-popper, popper
1195
+                'disable_admin'     =>  '', // URL snippets to disable loading on admin
1196
+            );
1197
+
1198
+            $settings = wp_parse_args( $db_settings, $defaults );
1199
+
1200
+            /**
1201
+             * Filter the Bootstrap settings.
1202
+             *
1203
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
1204
+             */
1205
+            return $this->settings = apply_filters( 'ayecode-ui-settings', $settings, $db_settings, $defaults );
1206
+        }
1207
+
1208
+
1209
+        /**
1210
+         * The settings page html output.
1211
+         */
1212
+        public function settings_page() {
1213
+            if ( ! current_user_can( 'manage_options' ) ) {
1214
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'aui' ) );
1215
+            }
1216
+            ?>
1217 1217
 			<div class="wrap">
1218 1218
 				<h1><?php echo $this->name; ?></h1>
1219 1219
 				<p><?php _e("Here you can adjust settings if you are having compatibility issues.",'aui');?></p>
1220 1220
 				<form method="post" action="options.php">
1221 1221
 					<?php
1222
-					settings_fields( 'ayecode-ui-settings' );
1223
-					do_settings_sections( 'ayecode-ui-settings' );
1224
-					?>
1222
+                    settings_fields( 'ayecode-ui-settings' );
1223
+                    do_settings_sections( 'ayecode-ui-settings' );
1224
+                    ?>
1225 1225
 
1226 1226
 					<h2><?php _e( 'Frontend', 'aui' ); ?></h2>
1227 1227
 					<table class="form-table wpbs-table-settings">
@@ -1301,60 +1301,60 @@  discard block
 block discarded – undo
1301 1301
 					</table>
1302 1302
 
1303 1303
 					<?php
1304
-					submit_button();
1305
-					?>
1304
+                    submit_button();
1305
+                    ?>
1306 1306
 				</form>
1307 1307
 
1308 1308
 				<div id="wpbs-version"><?php echo $this->version; ?></div>
1309 1309
 			</div>
1310 1310
 
1311 1311
 			<?php
1312
-		}
1313
-
1314
-		public function customizer_settings($wp_customize){
1315
-			$wp_customize->add_section('aui_settings', array(
1316
-				'title'    => __('AyeCode UI','aui'),
1317
-				'priority' => 120,
1318
-			));
1319
-
1320
-			//  =============================
1321
-			//  = Color Picker              =
1322
-			//  =============================
1323
-			$wp_customize->add_setting('aui_options[color_primary]', array(
1324
-				'default'           => AUI_PRIMARY_COLOR,
1325
-				'sanitize_callback' => 'sanitize_hex_color',
1326
-				'capability'        => 'edit_theme_options',
1327
-				'type'              => 'option',
1328
-				'transport'         => 'refresh',
1329
-			));
1330
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1331
-				'label'    => __('Primary Color','aui'),
1332
-				'section'  => 'aui_settings',
1333
-				'settings' => 'aui_options[color_primary]',
1334
-			)));
1335
-
1336
-			$wp_customize->add_setting('aui_options[color_secondary]', array(
1337
-				'default'           => '#6c757d',
1338
-				'sanitize_callback' => 'sanitize_hex_color',
1339
-				'capability'        => 'edit_theme_options',
1340
-				'type'              => 'option',
1341
-				'transport'         => 'refresh',
1342
-			));
1343
-			$wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1344
-				'label'    => __('Secondary Color','aui'),
1345
-				'section'  => 'aui_settings',
1346
-				'settings' => 'aui_options[color_secondary]',
1347
-			)));
1348
-		}
1349
-
1350
-		/**
1351
-		 * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1352
-		 *
1353
-		 * @return mixed
1354
-		 */
1355
-		public static function bs3_compat_css() {
1356
-			ob_start();
1357
-			?>
1312
+        }
1313
+
1314
+        public function customizer_settings($wp_customize){
1315
+            $wp_customize->add_section('aui_settings', array(
1316
+                'title'    => __('AyeCode UI','aui'),
1317
+                'priority' => 120,
1318
+            ));
1319
+
1320
+            //  =============================
1321
+            //  = Color Picker              =
1322
+            //  =============================
1323
+            $wp_customize->add_setting('aui_options[color_primary]', array(
1324
+                'default'           => AUI_PRIMARY_COLOR,
1325
+                'sanitize_callback' => 'sanitize_hex_color',
1326
+                'capability'        => 'edit_theme_options',
1327
+                'type'              => 'option',
1328
+                'transport'         => 'refresh',
1329
+            ));
1330
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_primary', array(
1331
+                'label'    => __('Primary Color','aui'),
1332
+                'section'  => 'aui_settings',
1333
+                'settings' => 'aui_options[color_primary]',
1334
+            )));
1335
+
1336
+            $wp_customize->add_setting('aui_options[color_secondary]', array(
1337
+                'default'           => '#6c757d',
1338
+                'sanitize_callback' => 'sanitize_hex_color',
1339
+                'capability'        => 'edit_theme_options',
1340
+                'type'              => 'option',
1341
+                'transport'         => 'refresh',
1342
+            ));
1343
+            $wp_customize->add_control( new WP_Customize_Color_Control($wp_customize, 'color_secondary', array(
1344
+                'label'    => __('Secondary Color','aui'),
1345
+                'section'  => 'aui_settings',
1346
+                'settings' => 'aui_options[color_secondary]',
1347
+            )));
1348
+        }
1349
+
1350
+        /**
1351
+         * CSS to help with conflict issues with other plugins and themes using bootstrap v3.
1352
+         *
1353
+         * @return mixed
1354
+         */
1355
+        public static function bs3_compat_css() {
1356
+            ob_start();
1357
+            ?>
1358 1358
 			<style>
1359 1359
 			/* Bootstrap 3 compatibility */
1360 1360
 			body.modal-open .modal-backdrop.show:not(.in) {opacity:0.5;}
@@ -1380,579 +1380,579 @@  discard block
 block discarded – undo
1380 1380
 			<?php } ?>
1381 1381
 			</style>
1382 1382
 			<?php
1383
-			return str_replace( array(
1384
-				'<style>',
1385
-				'</style>'
1386
-			), '', self::minify_css( ob_get_clean() ) );
1387
-		}
1383
+            return str_replace( array(
1384
+                '<style>',
1385
+                '</style>'
1386
+            ), '', self::minify_css( ob_get_clean() ) );
1387
+        }
1388 1388
 
1389 1389
 
1390
-		public static function custom_css($compatibility = true) {
1391
-			$settings = get_option('aui_options');
1390
+        public static function custom_css($compatibility = true) {
1391
+            $settings = get_option('aui_options');
1392 1392
 
1393
-			ob_start();
1393
+            ob_start();
1394 1394
 
1395
-			$primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1396
-			$secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1397
-				//AUI_PRIMARY_COLOR_ORIGINAL
1398
-			?>
1395
+            $primary_color = !empty($settings['color_primary']) ? $settings['color_primary'] : AUI_PRIMARY_COLOR;
1396
+            $secondary_color = !empty($settings['color_secondary']) ? $settings['color_secondary'] : AUI_SECONDARY_COLOR;
1397
+                //AUI_PRIMARY_COLOR_ORIGINAL
1398
+            ?>
1399 1399
 			<style>
1400 1400
 				<?php
1401 1401
 
1402
-					// BS v3 compat
1403
-					if( self::is_bs3_compat() ){
1404
-					    echo self::bs3_compat_css();
1405
-					}
1402
+                    // BS v3 compat
1403
+                    if( self::is_bs3_compat() ){
1404
+                        echo self::bs3_compat_css();
1405
+                    }
1406 1406
 
1407
-					if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1408
-						echo self::css_primary($primary_color,$compatibility);
1409
-					}
1407
+                    if(!is_admin() && $primary_color != AUI_PRIMARY_COLOR_ORIGINAL){
1408
+                        echo self::css_primary($primary_color,$compatibility);
1409
+                    }
1410 1410
 
1411
-					if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1412
-						echo self::css_secondary($settings['color_secondary'],$compatibility);
1413
-					}
1411
+                    if(!is_admin() && $secondary_color != AUI_SECONDARY_COLOR_ORIGINAL){
1412
+                        echo self::css_secondary($settings['color_secondary'],$compatibility);
1413
+                    }
1414 1414
 
1415
-					// Set admin bar z-index lower when modal is open.
1416
-					echo ' body.modal-open #wpadminbar{z-index:999}';
1415
+                    // Set admin bar z-index lower when modal is open.
1416
+                    echo ' body.modal-open #wpadminbar{z-index:999}';
1417 1417
                 ?>
1418 1418
 			</style>
1419 1419
 			<?php
1420 1420
 
1421 1421
 
1422
-			/*
1422
+            /*
1423 1423
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1424 1424
 			 */
1425
-			return str_replace( array(
1426
-				'<style>',
1427
-				'</style>'
1428
-			), '', self::minify_css( ob_get_clean() ) );
1429
-		}
1430
-
1431
-		/**
1432
-		 * Check if we should add booststrap 3 compatibility changes.
1433
-		 *
1434
-		 * @return bool
1435
-		 */
1436
-		public static function is_bs3_compat(){
1437
-			return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1438
-		}
1439
-
1440
-		public static function css_primary($color_code,$compatibility){;
1441
-			$color_code = sanitize_hex_color($color_code);
1442
-			if(!$color_code){return '';}
1443
-			/**
1444
-			 * c = color, b = background color, o = border-color, f = fill
1445
-			 */
1446
-			$selectors = array(
1447
-				'a' => array('c'),
1448
-				'.btn-primary' => array('b','o'),
1449
-				'.btn-primary.disabled' => array('b','o'),
1450
-				'.btn-primary:disabled' => array('b','o'),
1451
-				'.btn-outline-primary' => array('c','o'),
1452
-				'.btn-outline-primary:hover' => array('b','o'),
1453
-				'.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1454
-				'.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1455
-				'.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1456
-				'.btn-link' => array('c'),
1457
-				'.dropdown-item.active' => array('b'),
1458
-				'.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1459
-				'.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1425
+            return str_replace( array(
1426
+                '<style>',
1427
+                '</style>'
1428
+            ), '', self::minify_css( ob_get_clean() ) );
1429
+        }
1430
+
1431
+        /**
1432
+         * Check if we should add booststrap 3 compatibility changes.
1433
+         *
1434
+         * @return bool
1435
+         */
1436
+        public static function is_bs3_compat(){
1437
+            return defined('AYECODE_UI_BS3_COMPAT') || defined('SVQ_THEME_VERSION') || defined('FUSION_BUILDER_VERSION');
1438
+        }
1439
+
1440
+        public static function css_primary($color_code,$compatibility){;
1441
+            $color_code = sanitize_hex_color($color_code);
1442
+            if(!$color_code){return '';}
1443
+            /**
1444
+             * c = color, b = background color, o = border-color, f = fill
1445
+             */
1446
+            $selectors = array(
1447
+                'a' => array('c'),
1448
+                '.btn-primary' => array('b','o'),
1449
+                '.btn-primary.disabled' => array('b','o'),
1450
+                '.btn-primary:disabled' => array('b','o'),
1451
+                '.btn-outline-primary' => array('c','o'),
1452
+                '.btn-outline-primary:hover' => array('b','o'),
1453
+                '.btn-outline-primary:not(:disabled):not(.disabled).active' => array('b','o'),
1454
+                '.btn-outline-primary:not(:disabled):not(.disabled):active' => array('b','o'),
1455
+                '.show>.btn-outline-primary.dropdown-toggle' => array('b','o'),
1456
+                '.btn-link' => array('c'),
1457
+                '.dropdown-item.active' => array('b'),
1458
+                '.custom-control-input:checked~.custom-control-label::before' => array('b','o'),
1459
+                '.custom-checkbox .custom-control-input:indeterminate~.custom-control-label::before' => array('b','o'),
1460 1460
 //				'.custom-range::-webkit-slider-thumb' => array('b'), // these break the inline rules...
1461 1461
 //				'.custom-range::-moz-range-thumb' => array('b'),
1462 1462
 //				'.custom-range::-ms-thumb' => array('b'),
1463
-				'.nav-pills .nav-link.active' => array('b'),
1464
-				'.nav-pills .show>.nav-link' => array('b'),
1465
-				'.page-link' => array('c'),
1466
-				'.page-item.active .page-link' => array('b','o'),
1467
-				'.badge-primary' => array('b'),
1468
-				'.alert-primary' => array('b','o'),
1469
-				'.progress-bar' => array('b'),
1470
-				'.list-group-item.active' => array('b','o'),
1471
-				'.bg-primary' => array('b','f'),
1472
-				'.btn-link.btn-primary' => array('c'),
1473
-				'.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1474
-			);
1475
-
1476
-			$important_selectors = array(
1477
-				'.bg-primary' => array('b','f'),
1478
-				'.border-primary' => array('o'),
1479
-				'.text-primary' => array('c'),
1480
-			);
1481
-
1482
-			$color = array();
1483
-			$color_i = array();
1484
-			$background = array();
1485
-			$background_i = array();
1486
-			$border = array();
1487
-			$border_i = array();
1488
-			$fill = array();
1489
-			$fill_i = array();
1490
-
1491
-			$output = '';
1492
-
1493
-			// build rules into each type
1494
-			foreach($selectors as $selector => $types){
1495
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1496
-				$types = array_combine($types,$types);
1497
-				if(isset($types['c'])){$color[] = $selector;}
1498
-				if(isset($types['b'])){$background[] = $selector;}
1499
-				if(isset($types['o'])){$border[] = $selector;}
1500
-				if(isset($types['f'])){$fill[] = $selector;}
1501
-			}
1502
-
1503
-			// build rules into each type
1504
-			foreach($important_selectors as $selector => $types){
1505
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1506
-				$types = array_combine($types,$types);
1507
-				if(isset($types['c'])){$color_i[] = $selector;}
1508
-				if(isset($types['b'])){$background_i[] = $selector;}
1509
-				if(isset($types['o'])){$border_i[] = $selector;}
1510
-				if(isset($types['f'])){$fill_i[] = $selector;}
1511
-			}
1512
-
1513
-			// add any color rules
1514
-			if(!empty($color)){
1515
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1516
-			}
1517
-			if(!empty($color_i)){
1518
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1519
-			}
1520
-
1521
-			// add any background color rules
1522
-			if(!empty($background)){
1523
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1524
-			}
1525
-			if(!empty($background_i)){
1526
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1527
-			}
1528
-
1529
-			// add any border color rules
1530
-			if(!empty($border)){
1531
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1532
-			}
1533
-			if(!empty($border_i)){
1534
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1535
-			}
1536
-
1537
-			// add any fill color rules
1538
-			if(!empty($fill)){
1539
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1540
-			}
1541
-			if(!empty($fill_i)){
1542
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1543
-			}
1544
-
1545
-
1546
-			$prefix = $compatibility ? ".bsui " : "";
1547
-
1548
-			// darken
1549
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1550
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1551
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1552
-
1553
-			// lighten
1554
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1555
-
1556
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1557
-			$op_25 = $color_code."40"; // 25% opacity
1558
-
1559
-
1560
-			// button states
1561
-			$output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1562
-			$output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1563
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1564
-			$output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1565
-
1566
-
1567
-			// dropdown's
1568
-			$output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1569
-
1570
-
1571
-			// input states
1572
-			$output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1573
-
1574
-			// page link
1575
-			$output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1576
-
1577
-			return $output;
1578
-		}
1579
-
1580
-		public static function css_secondary($color_code,$compatibility){;
1581
-			$color_code = sanitize_hex_color($color_code);
1582
-			if(!$color_code){return '';}
1583
-			/**
1584
-			 * c = color, b = background color, o = border-color, f = fill
1585
-			 */
1586
-			$selectors = array(
1587
-				'.btn-secondary' => array('b','o'),
1588
-				'.btn-secondary.disabled' => array('b','o'),
1589
-				'.btn-secondary:disabled' => array('b','o'),
1590
-				'.btn-outline-secondary' => array('c','o'),
1591
-				'.btn-outline-secondary:hover' => array('b','o'),
1592
-				'.btn-outline-secondary.disabled' => array('c'),
1593
-				'.btn-outline-secondary:disabled' => array('c'),
1594
-				'.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1595
-				'.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1596
-				'.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1597
-				'.badge-secondary' => array('b'),
1598
-				'.alert-secondary' => array('b','o'),
1599
-				'.btn-link.btn-secondary' => array('c'),
1600
-			);
1601
-
1602
-			$important_selectors = array(
1603
-				'.bg-secondary' => array('b','f'),
1604
-				'.border-secondary' => array('o'),
1605
-				'.text-secondary' => array('c'),
1606
-			);
1607
-
1608
-			$color = array();
1609
-			$color_i = array();
1610
-			$background = array();
1611
-			$background_i = array();
1612
-			$border = array();
1613
-			$border_i = array();
1614
-			$fill = array();
1615
-			$fill_i = array();
1616
-
1617
-			$output = '';
1618
-
1619
-			// build rules into each type
1620
-			foreach($selectors as $selector => $types){
1621
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1622
-				$types = array_combine($types,$types);
1623
-				if(isset($types['c'])){$color[] = $selector;}
1624
-				if(isset($types['b'])){$background[] = $selector;}
1625
-				if(isset($types['o'])){$border[] = $selector;}
1626
-				if(isset($types['f'])){$fill[] = $selector;}
1627
-			}
1628
-
1629
-			// build rules into each type
1630
-			foreach($important_selectors as $selector => $types){
1631
-				$selector = $compatibility ? ".bsui ".$selector : $selector;
1632
-				$types = array_combine($types,$types);
1633
-				if(isset($types['c'])){$color_i[] = $selector;}
1634
-				if(isset($types['b'])){$background_i[] = $selector;}
1635
-				if(isset($types['o'])){$border_i[] = $selector;}
1636
-				if(isset($types['f'])){$fill_i[] = $selector;}
1637
-			}
1638
-
1639
-			// add any color rules
1640
-			if(!empty($color)){
1641
-				$output .= implode(",",$color) . "{color: $color_code;} ";
1642
-			}
1643
-			if(!empty($color_i)){
1644
-				$output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1645
-			}
1646
-
1647
-			// add any background color rules
1648
-			if(!empty($background)){
1649
-				$output .= implode(",",$background) . "{background-color: $color_code;} ";
1650
-			}
1651
-			if(!empty($background_i)){
1652
-				$output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1653
-			}
1654
-
1655
-			// add any border color rules
1656
-			if(!empty($border)){
1657
-				$output .= implode(",",$border) . "{border-color: $color_code;} ";
1658
-			}
1659
-			if(!empty($border_i)){
1660
-				$output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1661
-			}
1662
-
1663
-			// add any fill color rules
1664
-			if(!empty($fill)){
1665
-				$output .= implode(",",$fill) . "{fill: $color_code;} ";
1666
-			}
1667
-			if(!empty($fill_i)){
1668
-				$output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1669
-			}
1670
-
1671
-
1672
-			$prefix = $compatibility ? ".bsui " : "";
1673
-
1674
-			// darken
1675
-			$darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1676
-			$darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1677
-			$darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1678
-
1679
-			// lighten
1680
-			$lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1681
-
1682
-			// opacity see https://css-tricks.com/8-digit-hex-codes/
1683
-			$op_25 = $color_code."40"; // 25% opacity
1684
-
1685
-
1686
-			// button states
1687
-			$output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1688
-			$output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1689
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1690
-			$output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1691
-
1692
-
1693
-			return $output;
1694
-		}
1695
-
1696
-		/**
1697
-		 * Increases or decreases the brightness of a color by a percentage of the current brightness.
1698
-		 *
1699
-		 * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1700
-		 * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1701
-		 *
1702
-		 * @return  string
1703
-		 */
1704
-		public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1705
-			$hexCode = ltrim($hexCode, '#');
1706
-
1707
-			if (strlen($hexCode) == 3) {
1708
-				$hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1709
-			}
1710
-
1711
-			$hexCode = array_map('hexdec', str_split($hexCode, 2));
1712
-
1713
-			foreach ($hexCode as & $color) {
1714
-				$adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1715
-				$adjustAmount = ceil($adjustableLimit * $adjustPercent);
1716
-
1717
-				$color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1718
-			}
1719
-
1720
-			return '#' . implode($hexCode);
1721
-		}
1722
-
1723
-		/**
1724
-		 * Check if we should display examples.
1725
-		 */
1726
-		public function maybe_show_examples(){
1727
-			if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1728
-				echo "<head>";
1729
-				wp_head();
1730
-				echo "</head>";
1731
-				echo "<body>";
1732
-				echo $this->get_examples();
1733
-				echo "</body>";
1734
-				exit;
1735
-			}
1736
-		}
1737
-
1738
-		/**
1739
-		 * Get developer examples.
1740
-		 *
1741
-		 * @return string
1742
-		 */
1743
-		public function get_examples(){
1744
-			$output = '';
1745
-
1746
-
1747
-			// open form
1748
-			$output .= "<form class='p-5 m-5 border rounded'>";
1749
-
1750
-			// input example
1751
-			$output .= aui()->input(array(
1752
-				'type'  =>  'text',
1753
-				'id'    =>  'text-example',
1754
-				'name'    =>  'text-example',
1755
-				'placeholder'   => 'text placeholder',
1756
-				'title'   => 'Text input example',
1757
-				'value' =>  '',
1758
-				'required'  => false,
1759
-				'help_text' => 'help text',
1760
-				'label' => 'Text input example label'
1761
-			));
1762
-
1763
-			// input example
1764
-			$output .= aui()->input(array(
1765
-				'type'  =>  'url',
1766
-				'id'    =>  'text-example2',
1767
-				'name'    =>  'text-example',
1768
-				'placeholder'   => 'url placeholder',
1769
-				'title'   => 'Text input example',
1770
-				'value' =>  '',
1771
-				'required'  => false,
1772
-				'help_text' => 'help text',
1773
-				'label' => 'Text input example label'
1774
-			));
1775
-
1776
-			// checkbox example
1777
-			$output .= aui()->input(array(
1778
-				'type'  =>  'checkbox',
1779
-				'id'    =>  'checkbox-example',
1780
-				'name'    =>  'checkbox-example',
1781
-				'placeholder'   => 'checkbox-example',
1782
-				'title'   => 'Checkbox example',
1783
-				'value' =>  '1',
1784
-				'checked'   => true,
1785
-				'required'  => false,
1786
-				'help_text' => 'help text',
1787
-				'label' => 'Checkbox checked'
1788
-			));
1789
-
1790
-			// checkbox example
1791
-			$output .= aui()->input(array(
1792
-				'type'  =>  'checkbox',
1793
-				'id'    =>  'checkbox-example2',
1794
-				'name'    =>  'checkbox-example2',
1795
-				'placeholder'   => 'checkbox-example',
1796
-				'title'   => 'Checkbox example',
1797
-				'value' =>  '1',
1798
-				'checked'   => false,
1799
-				'required'  => false,
1800
-				'help_text' => 'help text',
1801
-				'label' => 'Checkbox un-checked'
1802
-			));
1803
-
1804
-			// switch example
1805
-			$output .= aui()->input(array(
1806
-				'type'  =>  'checkbox',
1807
-				'id'    =>  'switch-example',
1808
-				'name'    =>  'switch-example',
1809
-				'placeholder'   => 'checkbox-example',
1810
-				'title'   => 'Switch example',
1811
-				'value' =>  '1',
1812
-				'checked'   => true,
1813
-				'switch'    => true,
1814
-				'required'  => false,
1815
-				'help_text' => 'help text',
1816
-				'label' => 'Switch on'
1817
-			));
1818
-
1819
-			// switch example
1820
-			$output .= aui()->input(array(
1821
-				'type'  =>  'checkbox',
1822
-				'id'    =>  'switch-example2',
1823
-				'name'    =>  'switch-example2',
1824
-				'placeholder'   => 'checkbox-example',
1825
-				'title'   => 'Switch example',
1826
-				'value' =>  '1',
1827
-				'checked'   => false,
1828
-				'switch'    => true,
1829
-				'required'  => false,
1830
-				'help_text' => 'help text',
1831
-				'label' => 'Switch off'
1832
-			));
1833
-
1834
-			// close form
1835
-			$output .= "</form>";
1836
-
1837
-			return $output;
1838
-		}
1839
-
1840
-		/**
1841
-		 * Calendar params.
1842
-		 *
1843
-		 * @since 0.1.44
1844
-		 *
1845
-		 * @return array Calendar params.
1846
-		 */
1847
-		public static function calendar_params() {
1848
-			$params = array(
1849
-				'month_long_1' => __( 'January', 'aui' ),
1850
-				'month_long_2' => __( 'February', 'aui' ),
1851
-				'month_long_3' => __( 'March', 'aui' ),
1852
-				'month_long_4' => __( 'April', 'aui' ),
1853
-				'month_long_5' => __( 'May', 'aui' ),
1854
-				'month_long_6' => __( 'June', 'aui' ),
1855
-				'month_long_7' => __( 'July', 'aui' ),
1856
-				'month_long_8' => __( 'August', 'aui' ),
1857
-				'month_long_9' => __( 'September', 'aui' ),
1858
-				'month_long_10' => __( 'October', 'aui' ),
1859
-				'month_long_11' => __( 'November', 'aui' ),
1860
-				'month_long_12' => __( 'December', 'aui' ),
1861
-				'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1862
-				'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1863
-				'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1864
-				'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1865
-				'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1866
-				'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1867
-				'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1868
-				'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1869
-				'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1870
-				'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1871
-				'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1872
-				'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1873
-				'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1874
-				'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1875
-				'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1876
-				'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1877
-				'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1878
-				'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1879
-				'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1880
-				'day_s2_1' => __( 'Su', 'aui' ),
1881
-				'day_s2_2' => __( 'Mo', 'aui' ),
1882
-				'day_s2_3' => __( 'Tu', 'aui' ),
1883
-				'day_s2_4' => __( 'We', 'aui' ),
1884
-				'day_s2_5' => __( 'Th', 'aui' ),
1885
-				'day_s2_6' => __( 'Fr', 'aui' ),
1886
-				'day_s2_7' => __( 'Sa', 'aui' ),
1887
-				'day_s3_1' => __( 'Sun', 'aui' ),
1888
-				'day_s3_2' => __( 'Mon', 'aui' ),
1889
-				'day_s3_3' => __( 'Tue', 'aui' ),
1890
-				'day_s3_4' => __( 'Wed', 'aui' ),
1891
-				'day_s3_5' => __( 'Thu', 'aui' ),
1892
-				'day_s3_6' => __( 'Fri', 'aui' ),
1893
-				'day_s3_7' => __( 'Sat', 'aui' ),
1894
-				'day_s5_1' => __( 'Sunday', 'aui' ),
1895
-				'day_s5_2' => __( 'Monday', 'aui' ),
1896
-				'day_s5_3' => __( 'Tuesday', 'aui' ),
1897
-				'day_s5_4' => __( 'Wednesday', 'aui' ),
1898
-				'day_s5_5' => __( 'Thursday', 'aui' ),
1899
-				'day_s5_6' => __( 'Friday', 'aui' ),
1900
-				'day_s5_7' => __( 'Saturday', 'aui' ),
1901
-				'am_lower' => __( 'am', 'aui' ),
1902
-				'pm_lower' => __( 'pm', 'aui' ),
1903
-				'am_upper' => __( 'AM', 'aui' ),
1904
-				'pm_upper' => __( 'PM', 'aui' ),
1905
-				'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1906
-				'time_24hr' => false,
1907
-				'year' => __( 'Year', 'aui' ),
1908
-				'hour' => __( 'Hour', 'aui' ),
1909
-				'minute' => __( 'Minute', 'aui' ),
1910
-				'weekAbbreviation' => __( 'Wk', 'aui' ),
1911
-				'rangeSeparator' => __( ' to ', 'aui' ),
1912
-				'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1913
-				'toggleTitle' => __( 'Click to toggle', 'aui' )
1914
-			);
1915
-
1916
-			return apply_filters( 'ayecode_ui_calendar_params', $params );
1917
-		}
1918
-
1919
-		/**
1920
-		 * Flatpickr calendar localize.
1921
-		 *
1922
-		 * @since 0.1.44
1923
-		 *
1924
-		 * @return string Calendar locale.
1925
-		 */
1926
-		public static function flatpickr_locale() {
1927
-			$params = self::calendar_params();
1928
-
1929
-			if ( is_string( $params ) ) {
1930
-				$params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1931
-			} else {
1932
-				foreach ( (array) $params as $key => $value ) {
1933
-					if ( ! is_scalar( $value ) ) {
1934
-						continue;
1935
-					}
1936
-
1937
-					$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1938
-				}
1939
-			}
1463
+                '.nav-pills .nav-link.active' => array('b'),
1464
+                '.nav-pills .show>.nav-link' => array('b'),
1465
+                '.page-link' => array('c'),
1466
+                '.page-item.active .page-link' => array('b','o'),
1467
+                '.badge-primary' => array('b'),
1468
+                '.alert-primary' => array('b','o'),
1469
+                '.progress-bar' => array('b'),
1470
+                '.list-group-item.active' => array('b','o'),
1471
+                '.bg-primary' => array('b','f'),
1472
+                '.btn-link.btn-primary' => array('c'),
1473
+                '.select2-container .select2-results__option--highlighted.select2-results__option[aria-selected=true]' => array('b'),
1474
+            );
1475
+
1476
+            $important_selectors = array(
1477
+                '.bg-primary' => array('b','f'),
1478
+                '.border-primary' => array('o'),
1479
+                '.text-primary' => array('c'),
1480
+            );
1481
+
1482
+            $color = array();
1483
+            $color_i = array();
1484
+            $background = array();
1485
+            $background_i = array();
1486
+            $border = array();
1487
+            $border_i = array();
1488
+            $fill = array();
1489
+            $fill_i = array();
1490
+
1491
+            $output = '';
1492
+
1493
+            // build rules into each type
1494
+            foreach($selectors as $selector => $types){
1495
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1496
+                $types = array_combine($types,$types);
1497
+                if(isset($types['c'])){$color[] = $selector;}
1498
+                if(isset($types['b'])){$background[] = $selector;}
1499
+                if(isset($types['o'])){$border[] = $selector;}
1500
+                if(isset($types['f'])){$fill[] = $selector;}
1501
+            }
1502
+
1503
+            // build rules into each type
1504
+            foreach($important_selectors as $selector => $types){
1505
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1506
+                $types = array_combine($types,$types);
1507
+                if(isset($types['c'])){$color_i[] = $selector;}
1508
+                if(isset($types['b'])){$background_i[] = $selector;}
1509
+                if(isset($types['o'])){$border_i[] = $selector;}
1510
+                if(isset($types['f'])){$fill_i[] = $selector;}
1511
+            }
1512
+
1513
+            // add any color rules
1514
+            if(!empty($color)){
1515
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1516
+            }
1517
+            if(!empty($color_i)){
1518
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1519
+            }
1520
+
1521
+            // add any background color rules
1522
+            if(!empty($background)){
1523
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1524
+            }
1525
+            if(!empty($background_i)){
1526
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1527
+            }
1528
+
1529
+            // add any border color rules
1530
+            if(!empty($border)){
1531
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1532
+            }
1533
+            if(!empty($border_i)){
1534
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1535
+            }
1536
+
1537
+            // add any fill color rules
1538
+            if(!empty($fill)){
1539
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1540
+            }
1541
+            if(!empty($fill_i)){
1542
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1543
+            }
1544
+
1545
+
1546
+            $prefix = $compatibility ? ".bsui " : "";
1547
+
1548
+            // darken
1549
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1550
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1551
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1552
+
1553
+            // lighten
1554
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1555
+
1556
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1557
+            $op_25 = $color_code."40"; // 25% opacity
1558
+
1559
+
1560
+            // button states
1561
+            $output .= $prefix ." .btn-primary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1562
+            $output .= $prefix ." .btn-outline-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-primary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1563
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active, $prefix .btn-primary:not(:disabled):not(.disabled).active, .show>$prefix .btn-primary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1564
+            $output .= $prefix ." .btn-primary:not(:disabled):not(.disabled):active:focus, $prefix .btn-primary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-primary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1565
+
1566
+
1567
+            // dropdown's
1568
+            $output .= $prefix ." .dropdown-item.active, $prefix .dropdown-item:active{background-color: $color_code;} ";
1569
+
1570
+
1571
+            // input states
1572
+            $output .= $prefix ." .form-control:focus{border-color: ".$lighten_25.";box-shadow: 0 0 0 0.2rem $op_25;} ";
1573
+
1574
+            // page link
1575
+            $output .= $prefix ." .page-link:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1576
+
1577
+            return $output;
1578
+        }
1579
+
1580
+        public static function css_secondary($color_code,$compatibility){;
1581
+            $color_code = sanitize_hex_color($color_code);
1582
+            if(!$color_code){return '';}
1583
+            /**
1584
+             * c = color, b = background color, o = border-color, f = fill
1585
+             */
1586
+            $selectors = array(
1587
+                '.btn-secondary' => array('b','o'),
1588
+                '.btn-secondary.disabled' => array('b','o'),
1589
+                '.btn-secondary:disabled' => array('b','o'),
1590
+                '.btn-outline-secondary' => array('c','o'),
1591
+                '.btn-outline-secondary:hover' => array('b','o'),
1592
+                '.btn-outline-secondary.disabled' => array('c'),
1593
+                '.btn-outline-secondary:disabled' => array('c'),
1594
+                '.btn-outline-secondary:not(:disabled):not(.disabled):active' => array('b','o'),
1595
+                '.btn-outline-secondary:not(:disabled):not(.disabled).active' => array('b','o'),
1596
+                '.btn-outline-secondary.dropdown-toggle' => array('b','o'),
1597
+                '.badge-secondary' => array('b'),
1598
+                '.alert-secondary' => array('b','o'),
1599
+                '.btn-link.btn-secondary' => array('c'),
1600
+            );
1601
+
1602
+            $important_selectors = array(
1603
+                '.bg-secondary' => array('b','f'),
1604
+                '.border-secondary' => array('o'),
1605
+                '.text-secondary' => array('c'),
1606
+            );
1607
+
1608
+            $color = array();
1609
+            $color_i = array();
1610
+            $background = array();
1611
+            $background_i = array();
1612
+            $border = array();
1613
+            $border_i = array();
1614
+            $fill = array();
1615
+            $fill_i = array();
1616
+
1617
+            $output = '';
1618
+
1619
+            // build rules into each type
1620
+            foreach($selectors as $selector => $types){
1621
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1622
+                $types = array_combine($types,$types);
1623
+                if(isset($types['c'])){$color[] = $selector;}
1624
+                if(isset($types['b'])){$background[] = $selector;}
1625
+                if(isset($types['o'])){$border[] = $selector;}
1626
+                if(isset($types['f'])){$fill[] = $selector;}
1627
+            }
1628
+
1629
+            // build rules into each type
1630
+            foreach($important_selectors as $selector => $types){
1631
+                $selector = $compatibility ? ".bsui ".$selector : $selector;
1632
+                $types = array_combine($types,$types);
1633
+                if(isset($types['c'])){$color_i[] = $selector;}
1634
+                if(isset($types['b'])){$background_i[] = $selector;}
1635
+                if(isset($types['o'])){$border_i[] = $selector;}
1636
+                if(isset($types['f'])){$fill_i[] = $selector;}
1637
+            }
1638
+
1639
+            // add any color rules
1640
+            if(!empty($color)){
1641
+                $output .= implode(",",$color) . "{color: $color_code;} ";
1642
+            }
1643
+            if(!empty($color_i)){
1644
+                $output .= implode(",",$color_i) . "{color: $color_code !important;} ";
1645
+            }
1646
+
1647
+            // add any background color rules
1648
+            if(!empty($background)){
1649
+                $output .= implode(",",$background) . "{background-color: $color_code;} ";
1650
+            }
1651
+            if(!empty($background_i)){
1652
+                $output .= implode(",",$background_i) . "{background-color: $color_code !important;} ";
1653
+            }
1654
+
1655
+            // add any border color rules
1656
+            if(!empty($border)){
1657
+                $output .= implode(",",$border) . "{border-color: $color_code;} ";
1658
+            }
1659
+            if(!empty($border_i)){
1660
+                $output .= implode(",",$border_i) . "{border-color: $color_code !important;} ";
1661
+            }
1662
+
1663
+            // add any fill color rules
1664
+            if(!empty($fill)){
1665
+                $output .= implode(",",$fill) . "{fill: $color_code;} ";
1666
+            }
1667
+            if(!empty($fill_i)){
1668
+                $output .= implode(",",$fill_i) . "{fill: $color_code !important;} ";
1669
+            }
1670
+
1671
+
1672
+            $prefix = $compatibility ? ".bsui " : "";
1673
+
1674
+            // darken
1675
+            $darker_075 = self::css_hex_lighten_darken($color_code,"-0.075");
1676
+            $darker_10 = self::css_hex_lighten_darken($color_code,"-0.10");
1677
+            $darker_125 = self::css_hex_lighten_darken($color_code,"-0.125");
1678
+
1679
+            // lighten
1680
+            $lighten_25 = self::css_hex_lighten_darken($color_code,"0.25");
1681
+
1682
+            // opacity see https://css-tricks.com/8-digit-hex-codes/
1683
+            $op_25 = $color_code."40"; // 25% opacity
1684
+
1685
+
1686
+            // button states
1687
+            $output .= $prefix ." .btn-secondary:hover{background-color: ".$darker_075.";    border-color: ".$darker_10.";} ";
1688
+            $output .= $prefix ." .btn-outline-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-outline-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-outline-secondary.dropdown-toggle:focus{box-shadow: 0 0 0 0.2rem $op_25;} ";
1689
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active, $prefix .btn-secondary:not(:disabled):not(.disabled).active, .show>$prefix .btn-secondary.dropdown-toggle{background-color: ".$darker_10.";    border-color: ".$darker_125.";} ";
1690
+            $output .= $prefix ." .btn-secondary:not(:disabled):not(.disabled):active:focus, $prefix .btn-secondary:not(:disabled):not(.disabled).active:focus, .show>$prefix .btn-secondary.dropdown-toggle:focus {box-shadow: 0 0 0 0.2rem $op_25;} ";
1691
+
1692
+
1693
+            return $output;
1694
+        }
1695
+
1696
+        /**
1697
+         * Increases or decreases the brightness of a color by a percentage of the current brightness.
1698
+         *
1699
+         * @param   string  $hexCode        Supported formats: `#FFF`, `#FFFFFF`, `FFF`, `FFFFFF`
1700
+         * @param   float   $adjustPercent  A number between -1 and 1. E.g. 0.3 = 30% lighter; -0.4 = 40% darker.
1701
+         *
1702
+         * @return  string
1703
+         */
1704
+        public static function css_hex_lighten_darken($hexCode, $adjustPercent) {
1705
+            $hexCode = ltrim($hexCode, '#');
1706
+
1707
+            if (strlen($hexCode) == 3) {
1708
+                $hexCode = $hexCode[0] . $hexCode[0] . $hexCode[1] . $hexCode[1] . $hexCode[2] . $hexCode[2];
1709
+            }
1710
+
1711
+            $hexCode = array_map('hexdec', str_split($hexCode, 2));
1712
+
1713
+            foreach ($hexCode as & $color) {
1714
+                $adjustableLimit = $adjustPercent < 0 ? $color : 255 - $color;
1715
+                $adjustAmount = ceil($adjustableLimit * $adjustPercent);
1716
+
1717
+                $color = str_pad(dechex($color + $adjustAmount), 2, '0', STR_PAD_LEFT);
1718
+            }
1719
+
1720
+            return '#' . implode($hexCode);
1721
+        }
1722
+
1723
+        /**
1724
+         * Check if we should display examples.
1725
+         */
1726
+        public function maybe_show_examples(){
1727
+            if(current_user_can('manage_options') && isset($_REQUEST['preview-aui'])){
1728
+                echo "<head>";
1729
+                wp_head();
1730
+                echo "</head>";
1731
+                echo "<body>";
1732
+                echo $this->get_examples();
1733
+                echo "</body>";
1734
+                exit;
1735
+            }
1736
+        }
1737
+
1738
+        /**
1739
+         * Get developer examples.
1740
+         *
1741
+         * @return string
1742
+         */
1743
+        public function get_examples(){
1744
+            $output = '';
1745
+
1746
+
1747
+            // open form
1748
+            $output .= "<form class='p-5 m-5 border rounded'>";
1749
+
1750
+            // input example
1751
+            $output .= aui()->input(array(
1752
+                'type'  =>  'text',
1753
+                'id'    =>  'text-example',
1754
+                'name'    =>  'text-example',
1755
+                'placeholder'   => 'text placeholder',
1756
+                'title'   => 'Text input example',
1757
+                'value' =>  '',
1758
+                'required'  => false,
1759
+                'help_text' => 'help text',
1760
+                'label' => 'Text input example label'
1761
+            ));
1762
+
1763
+            // input example
1764
+            $output .= aui()->input(array(
1765
+                'type'  =>  'url',
1766
+                'id'    =>  'text-example2',
1767
+                'name'    =>  'text-example',
1768
+                'placeholder'   => 'url placeholder',
1769
+                'title'   => 'Text input example',
1770
+                'value' =>  '',
1771
+                'required'  => false,
1772
+                'help_text' => 'help text',
1773
+                'label' => 'Text input example label'
1774
+            ));
1775
+
1776
+            // checkbox example
1777
+            $output .= aui()->input(array(
1778
+                'type'  =>  'checkbox',
1779
+                'id'    =>  'checkbox-example',
1780
+                'name'    =>  'checkbox-example',
1781
+                'placeholder'   => 'checkbox-example',
1782
+                'title'   => 'Checkbox example',
1783
+                'value' =>  '1',
1784
+                'checked'   => true,
1785
+                'required'  => false,
1786
+                'help_text' => 'help text',
1787
+                'label' => 'Checkbox checked'
1788
+            ));
1789
+
1790
+            // checkbox example
1791
+            $output .= aui()->input(array(
1792
+                'type'  =>  'checkbox',
1793
+                'id'    =>  'checkbox-example2',
1794
+                'name'    =>  'checkbox-example2',
1795
+                'placeholder'   => 'checkbox-example',
1796
+                'title'   => 'Checkbox example',
1797
+                'value' =>  '1',
1798
+                'checked'   => false,
1799
+                'required'  => false,
1800
+                'help_text' => 'help text',
1801
+                'label' => 'Checkbox un-checked'
1802
+            ));
1803
+
1804
+            // switch example
1805
+            $output .= aui()->input(array(
1806
+                'type'  =>  'checkbox',
1807
+                'id'    =>  'switch-example',
1808
+                'name'    =>  'switch-example',
1809
+                'placeholder'   => 'checkbox-example',
1810
+                'title'   => 'Switch example',
1811
+                'value' =>  '1',
1812
+                'checked'   => true,
1813
+                'switch'    => true,
1814
+                'required'  => false,
1815
+                'help_text' => 'help text',
1816
+                'label' => 'Switch on'
1817
+            ));
1818
+
1819
+            // switch example
1820
+            $output .= aui()->input(array(
1821
+                'type'  =>  'checkbox',
1822
+                'id'    =>  'switch-example2',
1823
+                'name'    =>  'switch-example2',
1824
+                'placeholder'   => 'checkbox-example',
1825
+                'title'   => 'Switch example',
1826
+                'value' =>  '1',
1827
+                'checked'   => false,
1828
+                'switch'    => true,
1829
+                'required'  => false,
1830
+                'help_text' => 'help text',
1831
+                'label' => 'Switch off'
1832
+            ));
1833
+
1834
+            // close form
1835
+            $output .= "</form>";
1836
+
1837
+            return $output;
1838
+        }
1839
+
1840
+        /**
1841
+         * Calendar params.
1842
+         *
1843
+         * @since 0.1.44
1844
+         *
1845
+         * @return array Calendar params.
1846
+         */
1847
+        public static function calendar_params() {
1848
+            $params = array(
1849
+                'month_long_1' => __( 'January', 'aui' ),
1850
+                'month_long_2' => __( 'February', 'aui' ),
1851
+                'month_long_3' => __( 'March', 'aui' ),
1852
+                'month_long_4' => __( 'April', 'aui' ),
1853
+                'month_long_5' => __( 'May', 'aui' ),
1854
+                'month_long_6' => __( 'June', 'aui' ),
1855
+                'month_long_7' => __( 'July', 'aui' ),
1856
+                'month_long_8' => __( 'August', 'aui' ),
1857
+                'month_long_9' => __( 'September', 'aui' ),
1858
+                'month_long_10' => __( 'October', 'aui' ),
1859
+                'month_long_11' => __( 'November', 'aui' ),
1860
+                'month_long_12' => __( 'December', 'aui' ),
1861
+                'month_s_1' => _x( 'Jan', 'January abbreviation', 'aui' ),
1862
+                'month_s_2' => _x( 'Feb', 'February abbreviation', 'aui' ),
1863
+                'month_s_3' => _x( 'Mar', 'March abbreviation', 'aui' ),
1864
+                'month_s_4' => _x( 'Apr', 'April abbreviation', 'aui' ),
1865
+                'month_s_5' => _x( 'May', 'May abbreviation', 'aui' ),
1866
+                'month_s_6' => _x( 'Jun', 'June abbreviation', 'aui' ),
1867
+                'month_s_7' => _x( 'Jul', 'July abbreviation', 'aui' ),
1868
+                'month_s_8' => _x( 'Aug', 'August abbreviation', 'aui' ),
1869
+                'month_s_9' => _x( 'Sep', 'September abbreviation', 'aui' ),
1870
+                'month_s_10' => _x( 'Oct', 'October abbreviation', 'aui' ),
1871
+                'month_s_11' => _x( 'Nov', 'November abbreviation', 'aui' ),
1872
+                'month_s_12' => _x( 'Dec', 'December abbreviation', 'aui' ),
1873
+                'day_s1_1' => _x( 'S', 'Sunday initial', 'aui' ),
1874
+                'day_s1_2' => _x( 'M', 'Monday initial', 'aui' ),
1875
+                'day_s1_3' => _x( 'T', 'Tuesday initial', 'aui' ),
1876
+                'day_s1_4' => _x( 'W', 'Wednesday initial', 'aui' ),
1877
+                'day_s1_5' => _x( 'T', 'Friday initial', 'aui' ),
1878
+                'day_s1_6' => _x( 'F', 'Thursday initial', 'aui' ),
1879
+                'day_s1_7' => _x( 'S', 'Saturday initial', 'aui' ),
1880
+                'day_s2_1' => __( 'Su', 'aui' ),
1881
+                'day_s2_2' => __( 'Mo', 'aui' ),
1882
+                'day_s2_3' => __( 'Tu', 'aui' ),
1883
+                'day_s2_4' => __( 'We', 'aui' ),
1884
+                'day_s2_5' => __( 'Th', 'aui' ),
1885
+                'day_s2_6' => __( 'Fr', 'aui' ),
1886
+                'day_s2_7' => __( 'Sa', 'aui' ),
1887
+                'day_s3_1' => __( 'Sun', 'aui' ),
1888
+                'day_s3_2' => __( 'Mon', 'aui' ),
1889
+                'day_s3_3' => __( 'Tue', 'aui' ),
1890
+                'day_s3_4' => __( 'Wed', 'aui' ),
1891
+                'day_s3_5' => __( 'Thu', 'aui' ),
1892
+                'day_s3_6' => __( 'Fri', 'aui' ),
1893
+                'day_s3_7' => __( 'Sat', 'aui' ),
1894
+                'day_s5_1' => __( 'Sunday', 'aui' ),
1895
+                'day_s5_2' => __( 'Monday', 'aui' ),
1896
+                'day_s5_3' => __( 'Tuesday', 'aui' ),
1897
+                'day_s5_4' => __( 'Wednesday', 'aui' ),
1898
+                'day_s5_5' => __( 'Thursday', 'aui' ),
1899
+                'day_s5_6' => __( 'Friday', 'aui' ),
1900
+                'day_s5_7' => __( 'Saturday', 'aui' ),
1901
+                'am_lower' => __( 'am', 'aui' ),
1902
+                'pm_lower' => __( 'pm', 'aui' ),
1903
+                'am_upper' => __( 'AM', 'aui' ),
1904
+                'pm_upper' => __( 'PM', 'aui' ),
1905
+                'firstDayOfWeek' => (int) get_option( 'start_of_week' ),
1906
+                'time_24hr' => false,
1907
+                'year' => __( 'Year', 'aui' ),
1908
+                'hour' => __( 'Hour', 'aui' ),
1909
+                'minute' => __( 'Minute', 'aui' ),
1910
+                'weekAbbreviation' => __( 'Wk', 'aui' ),
1911
+                'rangeSeparator' => __( ' to ', 'aui' ),
1912
+                'scrollTitle' => __( 'Scroll to increment', 'aui' ),
1913
+                'toggleTitle' => __( 'Click to toggle', 'aui' )
1914
+            );
1915
+
1916
+            return apply_filters( 'ayecode_ui_calendar_params', $params );
1917
+        }
1918
+
1919
+        /**
1920
+         * Flatpickr calendar localize.
1921
+         *
1922
+         * @since 0.1.44
1923
+         *
1924
+         * @return string Calendar locale.
1925
+         */
1926
+        public static function flatpickr_locale() {
1927
+            $params = self::calendar_params();
1928
+
1929
+            if ( is_string( $params ) ) {
1930
+                $params = html_entity_decode( $params, ENT_QUOTES, 'UTF-8' );
1931
+            } else {
1932
+                foreach ( (array) $params as $key => $value ) {
1933
+                    if ( ! is_scalar( $value ) ) {
1934
+                        continue;
1935
+                    }
1936
+
1937
+                    $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
1938
+                }
1939
+            }
1940 1940
 
1941
-			$day_s3 = array();
1942
-			$day_s5 = array();
1941
+            $day_s3 = array();
1942
+            $day_s5 = array();
1943 1943
 
1944
-			for ( $i = 1; $i <= 7; $i ++ ) {
1945
-				$day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1946
-				$day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1947
-			}
1944
+            for ( $i = 1; $i <= 7; $i ++ ) {
1945
+                $day_s3[] = addslashes( $params[ 'day_s3_' . $i ] );
1946
+                $day_s5[] = addslashes( $params[ 'day_s3_' . $i ] );
1947
+            }
1948 1948
 
1949
-			$month_s = array();
1950
-			$month_long = array();
1949
+            $month_s = array();
1950
+            $month_long = array();
1951 1951
 
1952
-			for ( $i = 1; $i <= 12; $i ++ ) {
1953
-				$month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1954
-				$month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1955
-			}
1952
+            for ( $i = 1; $i <= 12; $i ++ ) {
1953
+                $month_s[] = addslashes( $params[ 'month_s_' . $i ] );
1954
+                $month_long[] = addslashes( $params[ 'month_long_' . $i ] );
1955
+            }
1956 1956
 
1957 1957
 ob_start();
1958 1958
 if ( 0 ) { ?><script><?php } ?>
@@ -1994,184 +1994,184 @@  discard block
 block discarded – undo
1994 1994
 }
1995 1995
 <?php if ( 0 ) { ?></script><?php } ?>
1996 1996
 <?php
1997
-			$locale = ob_get_clean();
1998
-
1999
-			return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
2000
-		}
2001
-
2002
-		/**
2003
-		 * Select2 JS params.
2004
-		 *
2005
-		 * @since 0.1.44
2006
-		 *
2007
-		 * @return array Select2 JS params.
2008
-		 */
2009
-		public static function select2_params() {
2010
-			$params = array(
2011
-				'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2012
-				'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2013
-				'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2014
-				'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2015
-				'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2016
-				'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2017
-				'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2018
-				'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2019
-				'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2020
-				'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2021
-				'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2022
-			);
2023
-
2024
-			return apply_filters( 'ayecode_ui_select2_params', $params );
2025
-		}
2026
-
2027
-		/**
2028
-		 * Select2 JS localize.
2029
-		 *
2030
-		 * @since 0.1.44
2031
-		 *
2032
-		 * @return string Select2 JS locale.
2033
-		 */
2034
-		public static function select2_locale() {
2035
-			$params = self::select2_params();
2036
-
2037
-			foreach ( (array) $params as $key => $value ) {
2038
-				if ( ! is_scalar( $value ) ) {
2039
-					continue;
2040
-				}
2041
-
2042
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2043
-			}
2044
-
2045
-			$locale = json_encode( $params );
2046
-
2047
-			return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2048
-		}
2049
-
2050
-		/**
2051
-		 * Time ago JS localize.
2052
-		 *
2053
-		 * @since 0.1.47
2054
-		 *
2055
-		 * @return string Time ago JS locale.
2056
-		 */
2057
-		public static function timeago_locale() {
2058
-			$params = array(
2059
-				'prefix_ago' => '',
2060
-				'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ),
2061
-				'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ',
2062
-				'suffix_after' => '',
2063
-				'seconds' => _x( 'less than a minute', 'time ago', 'aui' ),
2064
-				'minute' => _x( 'about a minute', 'time ago', 'aui' ),
2065
-				'minutes' => _x( '%d minutes', 'time ago', 'aui' ),
2066
-				'hour' => _x( 'about an hour', 'time ago', 'aui' ),
2067
-				'hours' => _x( 'about %d hours', 'time ago', 'aui' ),
2068
-				'day' => _x( 'a day', 'time ago', 'aui' ),
2069
-				'days' => _x( '%d days', 'time ago', 'aui' ),
2070
-				'month' => _x( 'about a month', 'time ago', 'aui' ),
2071
-				'months' => _x( '%d months', 'time ago', 'aui' ),
2072
-				'year' => _x( 'about a year', 'time ago', 'aui' ),
2073
-				'years' => _x( '%d years', 'time ago', 'aui' ),
2074
-			);
2075
-
2076
-			$params = apply_filters( 'ayecode_ui_timeago_params', $params );
2077
-
2078
-			foreach ( (array) $params as $key => $value ) {
2079
-				if ( ! is_scalar( $value ) ) {
2080
-					continue;
2081
-				}
2082
-
2083
-				$params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2084
-			}
2085
-
2086
-			$locale = json_encode( $params );
2087
-
2088
-			return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2089
-		}
2090
-
2091
-		/**
2092
-		 * JavaScript Minifier
2093
-		 *
2094
-		 * @param $input
2095
-		 *
2096
-		 * @return mixed
2097
-		 */
2098
-		public static function minify_js($input) {
2099
-			if(trim($input) === "") return $input;
2100
-			return preg_replace(
2101
-				array(
2102
-					// Remove comment(s)
2103
-					'#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
2104
-					// Remove white-space(s) outside the string and regex
2105
-					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
2106
-					// Remove the last semicolon
2107
-					'#;+\}#',
2108
-					// Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
2109
-					'#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
2110
-					// --ibid. From `foo['bar']` to `foo.bar`
2111
-					'#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
2112
-				),
2113
-				array(
2114
-					'$1',
2115
-					'$1$2',
2116
-					'}',
2117
-					'$1$3',
2118
-					'$1.$3'
2119
-				),
2120
-				$input);
2121
-		}
1997
+            $locale = ob_get_clean();
1998
+
1999
+            return apply_filters( 'ayecode_ui_flatpickr_locale', trim( $locale ) );
2000
+        }
2001
+
2002
+        /**
2003
+         * Select2 JS params.
2004
+         *
2005
+         * @since 0.1.44
2006
+         *
2007
+         * @return array Select2 JS params.
2008
+         */
2009
+        public static function select2_params() {
2010
+            $params = array(
2011
+                'i18n_select_state_text'    => esc_attr__( 'Select an option&hellip;', 'aui' ),
2012
+                'i18n_no_matches'           => _x( 'No matches found', 'enhanced select', 'aui' ),
2013
+                'i18n_ajax_error'           => _x( 'Loading failed', 'enhanced select', 'aui' ),
2014
+                'i18n_input_too_short_1'    => _x( 'Please enter 1 or more characters', 'enhanced select', 'aui' ),
2015
+                'i18n_input_too_short_n'    => _x( 'Please enter %item% or more characters', 'enhanced select', 'aui' ),
2016
+                'i18n_input_too_long_1'     => _x( 'Please delete 1 character', 'enhanced select', 'aui' ),
2017
+                'i18n_input_too_long_n'     => _x( 'Please delete %item% characters', 'enhanced select', 'aui' ),
2018
+                'i18n_selection_too_long_1' => _x( 'You can only select 1 item', 'enhanced select', 'aui' ),
2019
+                'i18n_selection_too_long_n' => _x( 'You can only select %item% items', 'enhanced select', 'aui' ),
2020
+                'i18n_load_more'            => _x( 'Loading more results&hellip;', 'enhanced select', 'aui' ),
2021
+                'i18n_searching'            => _x( 'Searching&hellip;', 'enhanced select', 'aui' )
2022
+            );
2023
+
2024
+            return apply_filters( 'ayecode_ui_select2_params', $params );
2025
+        }
2026
+
2027
+        /**
2028
+         * Select2 JS localize.
2029
+         *
2030
+         * @since 0.1.44
2031
+         *
2032
+         * @return string Select2 JS locale.
2033
+         */
2034
+        public static function select2_locale() {
2035
+            $params = self::select2_params();
2036
+
2037
+            foreach ( (array) $params as $key => $value ) {
2038
+                if ( ! is_scalar( $value ) ) {
2039
+                    continue;
2040
+                }
2122 2041
 
2123
-		/**
2124
-		 * Minify CSS
2125
-		 *
2126
-		 * @param $input
2127
-		 *
2128
-		 * @return mixed
2129
-		 */
2130
-		public static function minify_css($input) {
2131
-			if(trim($input) === "") return $input;
2132
-			return preg_replace(
2133
-				array(
2134
-					// Remove comment(s)
2135
-					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
2136
-					// Remove unused white-space(s)
2137
-					'#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
2138
-					// Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
2139
-					'#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
2140
-					// Replace `:0 0 0 0` with `:0`
2141
-					'#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
2142
-					// Replace `background-position:0` with `background-position:0 0`
2143
-					'#(background-position):0(?=[;\}])#si',
2144
-					// Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
2145
-					'#(?<=[\s:,\-])0+\.(\d+)#s',
2146
-					// Minify string value
2147
-					'#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
2148
-					'#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
2149
-					// Minify HEX color code
2150
-					'#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
2151
-					// Replace `(border|outline):none` with `(border|outline):0`
2152
-					'#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
2153
-					// Remove empty selector(s)
2154
-					'#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
2155
-				),
2156
-				array(
2157
-					'$1',
2158
-					'$1$2$3$4$5$6$7',
2159
-					'$1',
2160
-					':0',
2161
-					'$1:0 0',
2162
-					'.$1',
2163
-					'$1$3',
2164
-					'$1$2$4$5',
2165
-					'$1$2$3',
2166
-					'$1:0',
2167
-					'$1$2'
2168
-				),
2169
-				$input);
2170
-		}
2171
-	}
2042
+                $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2043
+            }
2044
+
2045
+            $locale = json_encode( $params );
2046
+
2047
+            return apply_filters( 'ayecode_ui_select2_locale', trim( $locale ) );
2048
+        }
2049
+
2050
+        /**
2051
+         * Time ago JS localize.
2052
+         *
2053
+         * @since 0.1.47
2054
+         *
2055
+         * @return string Time ago JS locale.
2056
+         */
2057
+        public static function timeago_locale() {
2058
+            $params = array(
2059
+                'prefix_ago' => '',
2060
+                'suffix_ago' => ' ' . _x( 'ago', 'time ago', 'aui' ),
2061
+                'prefix_after' => _x( 'after', 'time ago', 'aui' ) . ' ',
2062
+                'suffix_after' => '',
2063
+                'seconds' => _x( 'less than a minute', 'time ago', 'aui' ),
2064
+                'minute' => _x( 'about a minute', 'time ago', 'aui' ),
2065
+                'minutes' => _x( '%d minutes', 'time ago', 'aui' ),
2066
+                'hour' => _x( 'about an hour', 'time ago', 'aui' ),
2067
+                'hours' => _x( 'about %d hours', 'time ago', 'aui' ),
2068
+                'day' => _x( 'a day', 'time ago', 'aui' ),
2069
+                'days' => _x( '%d days', 'time ago', 'aui' ),
2070
+                'month' => _x( 'about a month', 'time ago', 'aui' ),
2071
+                'months' => _x( '%d months', 'time ago', 'aui' ),
2072
+                'year' => _x( 'about a year', 'time ago', 'aui' ),
2073
+                'years' => _x( '%d years', 'time ago', 'aui' ),
2074
+            );
2075
+
2076
+            $params = apply_filters( 'ayecode_ui_timeago_params', $params );
2077
+
2078
+            foreach ( (array) $params as $key => $value ) {
2079
+                if ( ! is_scalar( $value ) ) {
2080
+                    continue;
2081
+                }
2172 2082
 
2173
-	/**
2174
-	 * Run the class if found.
2175
-	 */
2176
-	AyeCode_UI_Settings::instance();
2083
+                $params[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
2084
+            }
2085
+
2086
+            $locale = json_encode( $params );
2087
+
2088
+            return apply_filters( 'ayecode_ui_timeago_locale', trim( $locale ) );
2089
+        }
2090
+
2091
+        /**
2092
+         * JavaScript Minifier
2093
+         *
2094
+         * @param $input
2095
+         *
2096
+         * @return mixed
2097
+         */
2098
+        public static function minify_js($input) {
2099
+            if(trim($input) === "") return $input;
2100
+            return preg_replace(
2101
+                array(
2102
+                    // Remove comment(s)
2103
+                    '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#',
2104
+                    // Remove white-space(s) outside the string and regex
2105
+                    '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s',
2106
+                    // Remove the last semicolon
2107
+                    '#;+\}#',
2108
+                    // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}`
2109
+                    '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i',
2110
+                    // --ibid. From `foo['bar']` to `foo.bar`
2111
+                    '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i'
2112
+                ),
2113
+                array(
2114
+                    '$1',
2115
+                    '$1$2',
2116
+                    '}',
2117
+                    '$1$3',
2118
+                    '$1.$3'
2119
+                ),
2120
+                $input);
2121
+        }
2122
+
2123
+        /**
2124
+         * Minify CSS
2125
+         *
2126
+         * @param $input
2127
+         *
2128
+         * @return mixed
2129
+         */
2130
+        public static function minify_css($input) {
2131
+            if(trim($input) === "") return $input;
2132
+            return preg_replace(
2133
+                array(
2134
+                    // Remove comment(s)
2135
+                    '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')|\/\*(?!\!)(?>.*?\*\/)|^\s*|\s*$#s',
2136
+                    // Remove unused white-space(s)
2137
+                    '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/))|\s*+;\s*+(})\s*+|\s*+([*$~^|]?+=|[{};,>~]|\s(?![0-9\.])|!important\b)\s*+|([[(:])\s++|\s++([])])|\s++(:)\s*+(?!(?>[^{}"\']++|"(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')*+{)|^\s++|\s++\z|(\s)\s+#si',
2138
+                    // Replace `0(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)` with `0`
2139
+                    '#(?<=[\s:])(0)(cm|em|ex|in|mm|pc|pt|px|vh|vw|%)#si',
2140
+                    // Replace `:0 0 0 0` with `:0`
2141
+                    '#:(0\s+0|0\s+0\s+0\s+0)(?=[;\}]|\!important)#i',
2142
+                    // Replace `background-position:0` with `background-position:0 0`
2143
+                    '#(background-position):0(?=[;\}])#si',
2144
+                    // Replace `0.6` with `.6`, but only when preceded by `:`, `,`, `-` or a white-space
2145
+                    '#(?<=[\s:,\-])0+\.(\d+)#s',
2146
+                    // Minify string value
2147
+                    '#(\/\*(?>.*?\*\/))|(?<!content\:)([\'"])([a-z_][a-z0-9\-_]*?)\2(?=[\s\{\}\];,])#si',
2148
+                    '#(\/\*(?>.*?\*\/))|(\burl\()([\'"])([^\s]+?)\3(\))#si',
2149
+                    // Minify HEX color code
2150
+                    '#(?<=[\s:,\-]\#)([a-f0-6]+)\1([a-f0-6]+)\2([a-f0-6]+)\3#i',
2151
+                    // Replace `(border|outline):none` with `(border|outline):0`
2152
+                    '#(?<=[\{;])(border|outline):none(?=[;\}\!])#',
2153
+                    // Remove empty selector(s)
2154
+                    '#(\/\*(?>.*?\*\/))|(^|[\{\}])(?:[^\s\{\}]+)\{\}#s'
2155
+                ),
2156
+                array(
2157
+                    '$1',
2158
+                    '$1$2$3$4$5$6$7',
2159
+                    '$1',
2160
+                    ':0',
2161
+                    '$1:0 0',
2162
+                    '.$1',
2163
+                    '$1$3',
2164
+                    '$1$2$4$5',
2165
+                    '$1$2$3',
2166
+                    '$1:0',
2167
+                    '$1$2'
2168
+                ),
2169
+                $input);
2170
+        }
2171
+    }
2172
+
2173
+    /**
2174
+     * Run the class if found.
2175
+     */
2176
+    AyeCode_UI_Settings::instance();
2177 2177
 }
2178 2178
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-getpaid-invoice-notification-emails.php 2 patches
Indentation   +412 added lines, -412 removed lines patch added patch discarded remove patch
@@ -12,473 +12,473 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Invoice_Notification_Emails {
14 14
 
15
-	/**
16
-	 * The array of invoice email actions.
17
-	 *
18
-	 * @param array
19
-	 */
20
-	public $invoice_actions;
21
-
22
-	/**
23
-	 * Class constructor
24
-	 *
25
-	 */
26
-	public function __construct() {
27
-
28
-		$this->invoice_actions = apply_filters(
29
-			'getpaid_notification_email_invoice_triggers',
30
-			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
-				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
-				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
-				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
-				'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
-				'getpaid_invoice_status_publish'        => 'completed_invoice',
37
-				'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
-				'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
-				'getpaid_new_customer_note'             => 'user_note',
40
-				'getpaid_daily_maintenance'             => 'overdue',
41
-			)
42
-		);
43
-
44
-		$this->init_hooks();
45
-
46
-	}
47
-
48
-	/**
49
-	 * Registers email hooks.
50
-	 */
51
-	public function init_hooks() {
52
-
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
-
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
58
-		}
59
-	}
60
-
61
-	/**
62
-	 * Registers an email hook for an invoice action.
63
-	 * 
64
-	 * @param string $hook
65
-	 * @param string|array $email_type
66
-	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
68
-
69
-		$email_type = wpinv_parse_list( $email_type );
70
-
71
-		foreach ( $email_type as $type ) {
72
-
73
-			$email = new GetPaid_Notification_Email( $type );
74
-
75
-			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
77
-				continue;
78
-			}
79
-
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
82
-				continue;
83
-			}
84
-
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
-		}
87
-
88
-	}
89
-
90
-	/**
91
-	 * Filters invoice merge tags.
92
-	 *
93
-	 * @param array $merge_tags
94
-	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
-	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
97
-
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
-			return array_merge(
100
-				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
102
-			);
103
-		}
104
-
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
-			return array_merge(
107
-				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
109
-			);
110
-		}
111
-
112
-		return $merge_tags;
113
-
114
-	}
115
-
116
-	/**
117
-	 * Generates invoice merge tags.
118
-	 *
119
-	 * @param WPInv_Invoice $invoice
120
-	 * @return array
121
-	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
123
-
124
-		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
126
-			return array();
127
-		}
128
-
129
-		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
-		);
149
-
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
-
152
-		if ( is_array( $payment_form_data ) ) {
153
-
154
-			foreach ( $payment_form_data as $label => $value ) {
155
-
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
-
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
-				}
162
-
163
-			}
164
-
165
-		}
166
-
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
-	}
169
-
170
-	/**
171
-	 * Helper function to send an email.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice
174
-	 * @param GetPaid_Notification_Email $email
175
-	 * @param string $type
176
-	 * @param string|array $recipients
177
-	 * @param array $extra_args Extra template args.
178
-	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
-
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
-
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
-			return;
185
-		}
186
-
187
-		$mailer     = new GetPaid_Notification_Email_Sender();
188
-		$merge_tags = $email->get_merge_tags();
189
-
190
-		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
194
-			$email->get_attachments()
195
-		);
196
-
197
-		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
199
-			$mailer->send(
200
-				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
203
-				$email->get_attachments()
204
-			);
205
-		}
206
-
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
-		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
-		}
212
-
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214
-
215
-		return $result;
216
-	}
217
-
218
-	/**
219
-	 * Also send emails to any cc users.
220
-	 *
221
-	 * @param array $recipients
222
-	 * @param GetPaid_Notification_Email $email
223
-	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
225
-
226
-		if ( ! $email->is_admin_email() ) {
227
-			$cc = $email->object->get_email_cc();
228
-
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
-			}
15
+    /**
16
+     * The array of invoice email actions.
17
+     *
18
+     * @param array
19
+     */
20
+    public $invoice_actions;
21
+
22
+    /**
23
+     * Class constructor
24
+     *
25
+     */
26
+    public function __construct() {
27
+
28
+        $this->invoice_actions = apply_filters(
29
+            'getpaid_notification_email_invoice_triggers',
30
+            array(
31
+                'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
32
+                'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33
+                'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34
+                'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
35
+                'getpaid_invoice_status_wpi-processing' => 'processing_invoice',
36
+                'getpaid_invoice_status_publish'        => 'completed_invoice',
37
+                'getpaid_invoice_status_wpi-renewal'    => 'completed_invoice',
38
+                'getpaid_invoice_status_wpi-refunded'   => 'refunded_invoice',
39
+                'getpaid_new_customer_note'             => 'user_note',
40
+                'getpaid_daily_maintenance'             => 'overdue',
41
+            )
42
+        );
43
+
44
+        $this->init_hooks();
45
+
46
+    }
47
+
48
+    /**
49
+     * Registers email hooks.
50
+     */
51
+    public function init_hooks() {
52
+
53
+        add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
+        add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
55
+
56
+        foreach ( $this->invoice_actions as $hook => $email_type ) {
57
+            $this->init_email_type_hook( $hook, $email_type );
58
+        }
59
+    }
60
+
61
+    /**
62
+     * Registers an email hook for an invoice action.
63
+     * 
64
+     * @param string $hook
65
+     * @param string|array $email_type
66
+     */
67
+    public function init_email_type_hook( $hook, $email_type ) {
68
+
69
+        $email_type = wpinv_parse_list( $email_type );
70
+
71
+        foreach ( $email_type as $type ) {
72
+
73
+            $email = new GetPaid_Notification_Email( $type );
74
+
75
+            // Abort if it is not active.
76
+            if ( ! $email->is_active() ) {
77
+                continue;
78
+            }
79
+
80
+            if ( method_exists( $this, $type ) ) {
81
+                add_action( $hook, array( $this, $type ), 100, 2 );
82
+                continue;
83
+            }
84
+
85
+            do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
86
+        }
87
+
88
+    }
89
+
90
+    /**
91
+     * Filters invoice merge tags.
92
+     *
93
+     * @param array $merge_tags
94
+     * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95
+     */
96
+    public function invoice_merge_tags( $merge_tags, $object ) {
97
+
98
+        if ( is_a( $object, 'WPInv_Invoice' ) ) {
99
+            return array_merge(
100
+                $merge_tags,
101
+                $this->get_invoice_merge_tags( $object )
102
+            );
103
+        }
104
+
105
+        if ( is_a( $object, 'WPInv_Subscription' ) ) {
106
+            return array_merge(
107
+                $merge_tags,
108
+                $this->get_invoice_merge_tags( $object->get_parent_payment() )
109
+            );
110
+        }
111
+
112
+        return $merge_tags;
113
+
114
+    }
115
+
116
+    /**
117
+     * Generates invoice merge tags.
118
+     *
119
+     * @param WPInv_Invoice $invoice
120
+     * @return array
121
+     */
122
+    public function get_invoice_merge_tags( $invoice ) {
123
+
124
+        // Abort if it does not exist.
125
+        if ( ! $invoice->get_id() ) {
126
+            return array();
127
+        }
128
+
129
+        $merge_tags = array(
130
+            '{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
+            '{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
+            '{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
+            '{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
+            '{email}'               => sanitize_email( $invoice->get_email() ),
135
+            '{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
+            '{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
+            '{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
+            '{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
+            '{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
+            '{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
+            '{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
+            '{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
+            '{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
+            '{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
+            '{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
+            '{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
+            '{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
148
+        );
149
+
150
+        $payment_form_data = $invoice->get_meta( 'payment_form_data', true );
151
+
152
+        if ( is_array( $payment_form_data ) ) {
153
+
154
+            foreach ( $payment_form_data as $label => $value ) {
155
+
156
+                $label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
+                $value = is_array( $value ) ? implode( ', ', $value ) : $value;
158
+
159
+                if ( is_scalar ( $value ) ) {
160
+                    $merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
161
+                }
162
+
163
+            }
164
+
165
+        }
166
+
167
+        return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
168
+    }
169
+
170
+    /**
171
+     * Helper function to send an email.
172
+     *
173
+     * @param WPInv_Invoice $invoice
174
+     * @param GetPaid_Notification_Email $email
175
+     * @param string $type
176
+     * @param string|array $recipients
177
+     * @param array $extra_args Extra template args.
178
+     */
179
+    public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
180
+
181
+        do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
182
+
183
+        if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
184
+            return;
185
+        }
186
+
187
+        $mailer     = new GetPaid_Notification_Email_Sender();
188
+        $merge_tags = $email->get_merge_tags();
189
+
190
+        $result = $mailer->send(
191
+            apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
+            $email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
+            $email->get_content( $merge_tags, $extra_args ),
194
+            $email->get_attachments()
195
+        );
196
+
197
+        // Maybe send a copy to the admin.
198
+        if ( $email->include_admin_bcc() ) {
199
+            $mailer->send(
200
+                wpinv_get_admin_email(),
201
+                $email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
+                $email->get_content( $merge_tags ),
203
+                $email->get_attachments()
204
+            );
205
+        }
206
+
207
+        if ( $result ) {
208
+            $invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
209
+        } else {
210
+            $invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
211
+        }
212
+
213
+        do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
214
+
215
+        return $result;
216
+    }
217
+
218
+    /**
219
+     * Also send emails to any cc users.
220
+     *
221
+     * @param array $recipients
222
+     * @param GetPaid_Notification_Email $email
223
+     */
224
+    public function filter_email_recipients( $recipients, $email ) {
225
+
226
+        if ( ! $email->is_admin_email() ) {
227
+            $cc = $email->object->get_email_cc();
228
+
229
+            if ( ! empty( $cc ) ) {
230
+                $cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
+                $recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
232
+            }
233 233
 
234
-		}
234
+        }
235 235
 
236
-		return $recipients;
236
+        return $recipients;
237 237
 
238
-	}
238
+    }
239 239
 
240
-	/**
241
-	 * Sends a new invoice notification.
242
-	 *
243
-	 * @param WPInv_Invoice $invoice
244
-	 */
245
-	public function new_invoice( $invoice ) {
240
+    /**
241
+     * Sends a new invoice notification.
242
+     *
243
+     * @param WPInv_Invoice $invoice
244
+     */
245
+    public function new_invoice( $invoice ) {
246 246
 
247
-		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
-			return;
250
-		}
247
+        // Only send this email for invoices created via the admin page.
248
+        if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
249
+            return;
250
+        }
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
-		$recipient = wpinv_get_admin_email();
252
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
253
+        $recipient = wpinv_get_admin_email();
254 254
 
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
255
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
256 256
 
257
-	}
257
+    }
258 258
 
259
-	/**
260
-	 * Sends a cancelled invoice notification.
261
-	 *
262
-	 * @param WPInv_Invoice $invoice
263
-	 */
264
-	public function cancelled_invoice( $invoice ) {
259
+    /**
260
+     * Sends a cancelled invoice notification.
261
+     *
262
+     * @param WPInv_Invoice $invoice
263
+     */
264
+    public function cancelled_invoice( $invoice ) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
-		$recipient = wpinv_get_admin_email();
266
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
267
+        $recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
270 270
 
271
-	}
271
+    }
272 272
 
273
-	/**
274
-	 * Sends a failed invoice notification.
275
-	 *
276
-	 * @param WPInv_Invoice $invoice
277
-	 */
278
-	public function failed_invoice( $invoice ) {
273
+    /**
274
+     * Sends a failed invoice notification.
275
+     *
276
+     * @param WPInv_Invoice $invoice
277
+     */
278
+    public function failed_invoice( $invoice ) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
-		$recipient = wpinv_get_admin_email();
280
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
281
+        $recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
284 284
 
285
-	}
285
+    }
286 286
 
287
-	/**
288
-	 * Sends a notification whenever an invoice is put on hold.
289
-	 *
290
-	 * @param WPInv_Invoice $invoice
291
-	 */
292
-	public function onhold_invoice( $invoice ) {
287
+    /**
288
+     * Sends a notification whenever an invoice is put on hold.
289
+     *
290
+     * @param WPInv_Invoice $invoice
291
+     */
292
+    public function onhold_invoice( $invoice ) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
-		$recipient = $invoice->get_email();
294
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
295
+        $recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
298 298
 
299
-	}
299
+    }
300 300
 
301
-	/**
302
-	 * Sends a notification whenever an invoice is marked as processing payment.
303
-	 *
304
-	 * @param WPInv_Invoice $invoice
305
-	 */
306
-	public function processing_invoice( $invoice ) {
301
+    /**
302
+     * Sends a notification whenever an invoice is marked as processing payment.
303
+     *
304
+     * @param WPInv_Invoice $invoice
305
+     */
306
+    public function processing_invoice( $invoice ) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
-		$recipient = $invoice->get_email();
308
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
309
+        $recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
312 312
 
313
-	}
313
+    }
314 314
 
315
-	/**
316
-	 * Sends a notification whenever an invoice is paid.
317
-	 *
318
-	 * @param WPInv_Invoice $invoice
319
-	 */
320
-	public function completed_invoice( $invoice ) {
315
+    /**
316
+     * Sends a notification whenever an invoice is paid.
317
+     *
318
+     * @param WPInv_Invoice $invoice
319
+     */
320
+    public function completed_invoice( $invoice ) {
321 321
 
322
-		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
-			return;
325
-		}
322
+        // (Maybe) abort if it is a renewal invoice.
323
+        if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
324
+            return;
325
+        }
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
-		$recipient = $invoice->get_email();
327
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
328
+        $recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
331 331
 
332
-	}
332
+    }
333 333
 
334
-	/**
335
-	 * Sends a notification whenever an invoice is refunded.
336
-	 *
337
-	 * @param WPInv_Invoice $invoice
338
-	 */
339
-	public function refunded_invoice( $invoice ) {
334
+    /**
335
+     * Sends a notification whenever an invoice is refunded.
336
+     *
337
+     * @param WPInv_Invoice $invoice
338
+     */
339
+    public function refunded_invoice( $invoice ) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
-		$recipient = $invoice->get_email();
341
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
342
+        $recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
345 345
 
346
-	}
346
+    }
347 347
 
348
-	/**
349
-	 * Notifies a user about new invoices
350
-	 *
351
-	 * @param WPInv_Invoice $invoice
352
-	 * @param bool $force
353
-	 */
354
-	public function user_invoice( $invoice, $force = false ) {
348
+    /**
349
+     * Notifies a user about new invoices
350
+     *
351
+     * @param WPInv_Invoice $invoice
352
+     * @param bool $force
353
+     */
354
+    public function user_invoice( $invoice, $force = false ) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
-			return;
358
-		}
359
-
360
-		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
-			return;
363
-		}
356
+        if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
357
+            return;
358
+        }
359
+
360
+        // Only send this email for invoices created via the admin page.
361
+        if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
362
+            return;
363
+        }
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
-		$recipient = $invoice->get_email();
365
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
366
+        $recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
369 369
 
370
-	}
371
-
372
-	/**
373
-	 * Checks if an invoice is a payment form invoice.
374
-	 *
375
-	 * @param int $invoice
376
-	 * @return bool
377
-	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
381
-	}
370
+    }
371
+
372
+    /**
373
+     * Checks if an invoice is a payment form invoice.
374
+     *
375
+     * @param int $invoice
376
+     * @return bool
377
+     */
378
+    public function is_payment_form_invoice( $invoice ) {
379
+        $is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
+        return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
381
+    }
382 382
 
383
-	/**
384
-	 * Notifies admin about new invoice notes
385
-	 *
386
-	 * @param WPInv_Invoice $invoice
387
-	 * @param string $note
388
-	 */
389
-	public function user_note( $invoice, $note ) {
390
-
391
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
392
-		$recipient = $invoice->get_email();
383
+    /**
384
+     * Notifies admin about new invoice notes
385
+     *
386
+     * @param WPInv_Invoice $invoice
387
+     * @param string $note
388
+     */
389
+    public function user_note( $invoice, $note ) {
390
+
391
+        $email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
392
+        $recipient = $invoice->get_email();
393 393
 
394
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
395
-
396
-	}
397
-
398
-	/**
399
-	 * (Force) Sends overdue notices.
400
-	 *
401
-	 * @param WPInv_Invoice $invoice
402
-	 */
403
-	public function force_send_overdue_notice( $invoice ) {
404
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
405
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
406
-	}
407
-
408
-	/**
409
-	 * Sends overdue notices.
410
-	 *
411
-	 * @TODO: Create an invoices query class.
412
-	 */
413
-	public function overdue() {
414
-		global $wpdb;
415
-
416
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
417
-
418
-		// Fetch reminder days.
419
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
420
-
421
-		// Abort if non is set.
422
-		if ( empty( $reminder_days ) ) {
423
-			return;
424
-		}
425
-
426
-		// Retrieve date query.
427
-		$date_query = $this->get_date_query( $reminder_days );
428
-
429
-		// Invoices table.
430
-		$table = $wpdb->prefix . 'getpaid_invoices';
431
-
432
-		// Fetch invoices.
433
-		$invoices  = $wpdb->get_col(
434
-			"SELECT posts.ID FROM $wpdb->posts as posts
394
+        return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
395
+
396
+    }
397
+
398
+    /**
399
+     * (Force) Sends overdue notices.
400
+     *
401
+     * @param WPInv_Invoice $invoice
402
+     */
403
+    public function force_send_overdue_notice( $invoice ) {
404
+        $email = new GetPaid_Notification_Email( 'overdue', $invoice );
405
+        return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
406
+    }
407
+
408
+    /**
409
+     * Sends overdue notices.
410
+     *
411
+     * @TODO: Create an invoices query class.
412
+     */
413
+    public function overdue() {
414
+        global $wpdb;
415
+
416
+        $email = new GetPaid_Notification_Email( __FUNCTION__ );
417
+
418
+        // Fetch reminder days.
419
+        $reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
420
+
421
+        // Abort if non is set.
422
+        if ( empty( $reminder_days ) ) {
423
+            return;
424
+        }
425
+
426
+        // Retrieve date query.
427
+        $date_query = $this->get_date_query( $reminder_days );
428
+
429
+        // Invoices table.
430
+        $table = $wpdb->prefix . 'getpaid_invoices';
431
+
432
+        // Fetch invoices.
433
+        $invoices  = $wpdb->get_col(
434
+            "SELECT posts.ID FROM $wpdb->posts as posts
435 435
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
436 436
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
437 437
 
438
-		foreach ( $invoices as $invoice ) {
438
+        foreach ( $invoices as $invoice ) {
439 439
 
440
-			// Only send this email for invoices created via the admin page.
441
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
442
-				$invoice       = new WPInv_Invoice( $invoice );
443
-				$email->object = $invoice;
440
+            // Only send this email for invoices created via the admin page.
441
+            if ( ! $this->is_payment_form_invoice( $invoice ) ) {
442
+                $invoice       = new WPInv_Invoice( $invoice );
443
+                $email->object = $invoice;
444 444
 
445
-				if ( $invoice->needs_payment() ) {
446
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
447
-				}
445
+                if ( $invoice->needs_payment() ) {
446
+                    $this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
447
+                }
448 448
 
449
-			}
449
+            }
450 450
 
451
-		}
451
+        }
452 452
 
453
-	}
453
+    }
454 454
 
455
-	/**
456
-	 * Calculates the date query for an invoices query
457
-	 *
458
-	 * @param array $reminder_days
459
-	 * @return string
460
-	 */
461
-	public function get_date_query( $reminder_days ) {
455
+    /**
456
+     * Calculates the date query for an invoices query
457
+     *
458
+     * @param array $reminder_days
459
+     * @return string
460
+     */
461
+    public function get_date_query( $reminder_days ) {
462 462
 
463
-		$date_query = array(
464
-			'relation'  => 'OR'
465
-		);
463
+        $date_query = array(
464
+            'relation'  => 'OR'
465
+        );
466 466
 
467
-		foreach ( $reminder_days as $days ) {
468
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
467
+        foreach ( $reminder_days as $days ) {
468
+            $date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
469 469
 
470
-			$date_query[] = array(
471
-				'year'  => $date['year'],
472
-				'month' => $date['month'],
473
-				'day'   => $date['day'],
474
-			);
470
+            $date_query[] = array(
471
+                'year'  => $date['year'],
472
+                'month' => $date['month'],
473
+                'day'   => $date['day'],
474
+            );
475 475
 
476
-		}
476
+        }
477 477
 
478
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
478
+        $date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
479 479
 
480
-		return $date_query->get_sql();
480
+        return $date_query->get_sql();
481 481
 
482
-	}
482
+    }
483 483
 
484 484
 }
Please login to merge, or discard this patch.
Spacing   +116 added lines, -116 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This class handles invoice notificaiton emails.
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 		$this->invoice_actions = apply_filters(
29 29
 			'getpaid_notification_email_invoice_triggers',
30 30
 			array(
31
-				'getpaid_new_invoice'                   => array( 'new_invoice', 'user_invoice' ),
31
+				'getpaid_new_invoice'                   => array('new_invoice', 'user_invoice'),
32 32
 				'getpaid_invoice_status_wpi-cancelled'  => 'cancelled_invoice',
33 33
 				'getpaid_invoice_status_wpi-failed'     => 'failed_invoice',
34 34
 				'getpaid_invoice_status_wpi-onhold'     => 'onhold_invoice',
@@ -50,11 +50,11 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function init_hooks() {
52 52
 
53
-		add_filter( 'getpaid_get_email_merge_tags', array( $this, 'invoice_merge_tags' ), 10, 2 );
54
-		add_filter( 'getpaid_invoice_email_recipients', array( $this, 'filter_email_recipients' ), 10, 2 );
53
+		add_filter('getpaid_get_email_merge_tags', array($this, 'invoice_merge_tags'), 10, 2);
54
+		add_filter('getpaid_invoice_email_recipients', array($this, 'filter_email_recipients'), 10, 2);
55 55
 
56
-		foreach ( $this->invoice_actions as $hook => $email_type ) {
57
-			$this->init_email_type_hook( $hook, $email_type );
56
+		foreach ($this->invoice_actions as $hook => $email_type) {
57
+			$this->init_email_type_hook($hook, $email_type);
58 58
 		}
59 59
 	}
60 60
 
@@ -64,25 +64,25 @@  discard block
 block discarded – undo
64 64
 	 * @param string $hook
65 65
 	 * @param string|array $email_type
66 66
 	 */
67
-	public function init_email_type_hook( $hook, $email_type ) {
67
+	public function init_email_type_hook($hook, $email_type) {
68 68
 
69
-		$email_type = wpinv_parse_list( $email_type );
69
+		$email_type = wpinv_parse_list($email_type);
70 70
 
71
-		foreach ( $email_type as $type ) {
71
+		foreach ($email_type as $type) {
72 72
 
73
-			$email = new GetPaid_Notification_Email( $type );
73
+			$email = new GetPaid_Notification_Email($type);
74 74
 
75 75
 			// Abort if it is not active.
76
-			if ( ! $email->is_active() ) {
76
+			if (!$email->is_active()) {
77 77
 				continue;
78 78
 			}
79 79
 
80
-			if ( method_exists( $this, $type ) ) {
81
-				add_action( $hook, array( $this, $type ), 100, 2 );
80
+			if (method_exists($this, $type)) {
81
+				add_action($hook, array($this, $type), 100, 2);
82 82
 				continue;
83 83
 			}
84 84
 
85
-			do_action( 'getpaid_invoice_init_email_type_hook', $type, $hook );
85
+			do_action('getpaid_invoice_init_email_type_hook', $type, $hook);
86 86
 		}
87 87
 
88 88
 	}
@@ -93,19 +93,19 @@  discard block
 block discarded – undo
93 93
 	 * @param array $merge_tags
94 94
 	 * @param mixed|WPInv_Invoice|WPInv_Subscription $object
95 95
 	 */
96
-	public function invoice_merge_tags( $merge_tags, $object ) {
96
+	public function invoice_merge_tags($merge_tags, $object) {
97 97
 
98
-		if ( is_a( $object, 'WPInv_Invoice' ) ) {
98
+		if (is_a($object, 'WPInv_Invoice')) {
99 99
 			return array_merge(
100 100
 				$merge_tags,
101
-				$this->get_invoice_merge_tags( $object )
101
+				$this->get_invoice_merge_tags($object)
102 102
 			);
103 103
 		}
104 104
 
105
-		if ( is_a( $object, 'WPInv_Subscription' ) ) {
105
+		if (is_a($object, 'WPInv_Subscription')) {
106 106
 			return array_merge(
107 107
 				$merge_tags,
108
-				$this->get_invoice_merge_tags( $object->get_parent_payment() )
108
+				$this->get_invoice_merge_tags($object->get_parent_payment())
109 109
 			);
110 110
 		}
111 111
 
@@ -119,52 +119,52 @@  discard block
 block discarded – undo
119 119
 	 * @param WPInv_Invoice $invoice
120 120
 	 * @return array
121 121
 	 */
122
-	public function get_invoice_merge_tags( $invoice ) {
122
+	public function get_invoice_merge_tags($invoice) {
123 123
 
124 124
 		// Abort if it does not exist.
125
-		if ( ! $invoice->get_id() ) {
125
+		if (!$invoice->get_id()) {
126 126
 			return array();
127 127
 		}
128 128
 
129 129
 		$merge_tags = array(
130
-			'{name}'                => sanitize_text_field( $invoice->get_user_full_name() ),
131
-			'{full_name}'           => sanitize_text_field( $invoice->get_user_full_name() ),
132
-			'{first_name}'          => sanitize_text_field( $invoice->get_first_name() ),
133
-			'{last_name}'           => sanitize_text_field( $invoice->get_last_name() ),
134
-			'{email}'               => sanitize_email( $invoice->get_email() ),
135
-			'{invoice_number}'      => sanitize_text_field( $invoice->get_number() ),
136
-			'{invoice_currency}'    => sanitize_text_field( $invoice->get_currency() ),
137
-			'{invoice_total}'       => sanitize_text_field( wpinv_price( $invoice->get_total(), $invoice->get_currency() ) ),
138
-			'{invoice_link}'        => esc_url( $invoice->get_view_url() ),
139
-			'{invoice_pay_link}'    => esc_url( $invoice->get_checkout_payment_url() ),
140
-			'{invoice_receipt_link}'=> esc_url( $invoice->get_receipt_url() ),
141
-			'{invoice_date}'        => getpaid_format_date_value( $invoice->get_date_created() ),
142
-			'{invoice_due_date}'    => getpaid_format_date_value( $invoice->get_due_date(), __( 'on receipt', 'invoicing' ) ),
143
-			'{invoice_quote}'       => sanitize_text_field( strtolower( $invoice->get_label() ) ),
144
-			'{invoice_label}'       => sanitize_text_field( ucfirst( $invoice->get_label() ) ),
145
-			'{invoice_description}' => wp_kses_post( $invoice->get_description() ),
146
-			'{subscription_name}'   => wp_kses_post( $invoice->get_subscription_name() ),
147
-			'{is_was}'              => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
130
+			'{name}'                => sanitize_text_field($invoice->get_user_full_name()),
131
+			'{full_name}'           => sanitize_text_field($invoice->get_user_full_name()),
132
+			'{first_name}'          => sanitize_text_field($invoice->get_first_name()),
133
+			'{last_name}'           => sanitize_text_field($invoice->get_last_name()),
134
+			'{email}'               => sanitize_email($invoice->get_email()),
135
+			'{invoice_number}'      => sanitize_text_field($invoice->get_number()),
136
+			'{invoice_currency}'    => sanitize_text_field($invoice->get_currency()),
137
+			'{invoice_total}'       => sanitize_text_field(wpinv_price($invoice->get_total(), $invoice->get_currency())),
138
+			'{invoice_link}'        => esc_url($invoice->get_view_url()),
139
+			'{invoice_pay_link}'    => esc_url($invoice->get_checkout_payment_url()),
140
+			'{invoice_receipt_link}'=> esc_url($invoice->get_receipt_url()),
141
+			'{invoice_date}'        => getpaid_format_date_value($invoice->get_date_created()),
142
+			'{invoice_due_date}'    => getpaid_format_date_value($invoice->get_due_date(), __('on receipt', 'invoicing')),
143
+			'{invoice_quote}'       => sanitize_text_field(strtolower($invoice->get_label())),
144
+			'{invoice_label}'       => sanitize_text_field(ucfirst($invoice->get_label())),
145
+			'{invoice_description}' => wp_kses_post($invoice->get_description()),
146
+			'{subscription_name}'   => wp_kses_post($invoice->get_subscription_name()),
147
+			'{is_was}'              => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
148 148
 		);
149 149
 
150
-		$payment_form_data = $invoice->get_meta( 'payment_form_data', true );
150
+		$payment_form_data = $invoice->get_meta('payment_form_data', true);
151 151
 
152
-		if ( is_array( $payment_form_data ) ) {
152
+		if (is_array($payment_form_data)) {
153 153
 
154
-			foreach ( $payment_form_data as $label => $value ) {
154
+			foreach ($payment_form_data as $label => $value) {
155 155
 
156
-				$label = preg_replace( '/[^a-z0-9]+/', '_', strtolower( $label ) );
157
-				$value = is_array( $value ) ? implode( ', ', $value ) : $value;
156
+				$label = preg_replace('/[^a-z0-9]+/', '_', strtolower($label));
157
+				$value = is_array($value) ? implode(', ', $value) : $value;
158 158
 
159
-				if ( is_scalar ( $value ) ) {
160
-					$merge_tags[ "{{$label}}" ] = wp_kses_post( $value );
159
+				if (is_scalar($value)) {
160
+					$merge_tags["{{$label}}"] = wp_kses_post($value);
161 161
 				}
162 162
 
163 163
 			}
164 164
 
165 165
 		}
166 166
 
167
-		return apply_filters( 'getpaid_invoice_email_merge_tags', $merge_tags, $invoice );
167
+		return apply_filters('getpaid_invoice_email_merge_tags', $merge_tags, $invoice);
168 168
 	}
169 169
 
170 170
 	/**
@@ -176,11 +176,11 @@  discard block
 block discarded – undo
176 176
 	 * @param string|array $recipients
177 177
 	 * @param array $extra_args Extra template args.
178 178
 	 */
179
-	public function send_email( $invoice, $email, $type, $recipients, $extra_args = array() ) {
179
+	public function send_email($invoice, $email, $type, $recipients, $extra_args = array()) {
180 180
 
181
-		do_action( 'getpaid_before_send_invoice_notification', $type, $invoice, $email );
181
+		do_action('getpaid_before_send_invoice_notification', $type, $invoice, $email);
182 182
 
183
-		if ( apply_filters( 'getpaid_skip_invoice_email', false, $type, $invoice ) ) {
183
+		if (apply_filters('getpaid_skip_invoice_email', false, $type, $invoice)) {
184 184
 			return;
185 185
 		}
186 186
 
@@ -188,29 +188,29 @@  discard block
 block discarded – undo
188 188
 		$merge_tags = $email->get_merge_tags();
189 189
 
190 190
 		$result = $mailer->send(
191
-			apply_filters( 'getpaid_invoice_email_recipients', wpinv_parse_list( $recipients ), $email ),
192
-			$email->add_merge_tags( $email->get_subject(), $merge_tags ),
193
-			$email->get_content( $merge_tags, $extra_args ),
191
+			apply_filters('getpaid_invoice_email_recipients', wpinv_parse_list($recipients), $email),
192
+			$email->add_merge_tags($email->get_subject(), $merge_tags),
193
+			$email->get_content($merge_tags, $extra_args),
194 194
 			$email->get_attachments()
195 195
 		);
196 196
 
197 197
 		// Maybe send a copy to the admin.
198
-		if ( $email->include_admin_bcc() ) {
198
+		if ($email->include_admin_bcc()) {
199 199
 			$mailer->send(
200 200
 				wpinv_get_admin_email(),
201
-				$email->add_merge_tags( $email->get_subject() . __( ' - ADMIN BCC COPY', 'invoicing' ), $merge_tags ),
202
-				$email->get_content( $merge_tags ),
201
+				$email->add_merge_tags($email->get_subject() . __(' - ADMIN BCC COPY', 'invoicing'), $merge_tags),
202
+				$email->get_content($merge_tags),
203 203
 				$email->get_attachments()
204 204
 			);
205 205
 		}
206 206
 
207
-		if ( $result ) {
208
-			$invoice->add_note( sprintf( __( 'Successfully sent %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );
207
+		if ($result) {
208
+			$invoice->add_note(sprintf(__('Successfully sent %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);
209 209
 		} else {
210
-			$invoice->add_note( sprintf( __( 'Failed sending %s notification email.', 'invoicing' ), sanitize_key( $type ) ), false, false, true );	
210
+			$invoice->add_note(sprintf(__('Failed sending %s notification email.', 'invoicing'), sanitize_key($type)), false, false, true);	
211 211
 		}
212 212
 
213
-		do_action( 'getpaid_after_send_invoice_notification', $type, $invoice, $email );
213
+		do_action('getpaid_after_send_invoice_notification', $type, $invoice, $email);
214 214
 
215 215
 		return $result;
216 216
 	}
@@ -221,14 +221,14 @@  discard block
 block discarded – undo
221 221
 	 * @param array $recipients
222 222
 	 * @param GetPaid_Notification_Email $email
223 223
 	 */
224
-	public function filter_email_recipients( $recipients, $email ) {
224
+	public function filter_email_recipients($recipients, $email) {
225 225
 
226
-		if ( ! $email->is_admin_email() ) {
226
+		if (!$email->is_admin_email()) {
227 227
 			$cc = $email->object->get_email_cc();
228 228
 
229
-			if ( ! empty( $cc ) ) {
230
-				$cc = array_map( 'sanitize_email', wpinv_parse_list( $cc ) );
231
-				$recipients = array_filter( array_unique( array_merge( $recipients, $cc ) ) );
229
+			if (!empty($cc)) {
230
+				$cc = array_map('sanitize_email', wpinv_parse_list($cc));
231
+				$recipients = array_filter(array_unique(array_merge($recipients, $cc)));
232 232
 			}
233 233
 
234 234
 		}
@@ -242,17 +242,17 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @param WPInv_Invoice $invoice
244 244
 	 */
245
-	public function new_invoice( $invoice ) {
245
+	public function new_invoice($invoice) {
246 246
 
247 247
 		// Only send this email for invoices created via the admin page.
248
-		if ( ! $invoice->is_type( 'invoice' ) || $this->is_payment_form_invoice( $invoice->get_id() ) ) {
248
+		if (!$invoice->is_type('invoice') || $this->is_payment_form_invoice($invoice->get_id())) {
249 249
 			return;
250 250
 		}
251 251
 
252
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
252
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
253 253
 		$recipient = wpinv_get_admin_email();
254 254
 
255
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
255
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
256 256
 
257 257
 	}
258 258
 
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
 	 *
262 262
 	 * @param WPInv_Invoice $invoice
263 263
 	 */
264
-	public function cancelled_invoice( $invoice ) {
264
+	public function cancelled_invoice($invoice) {
265 265
 
266
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
266
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
267 267
 		$recipient = wpinv_get_admin_email();
268 268
 
269
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
269
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
270 270
 
271 271
 	}
272 272
 
@@ -275,12 +275,12 @@  discard block
 block discarded – undo
275 275
 	 *
276 276
 	 * @param WPInv_Invoice $invoice
277 277
 	 */
278
-	public function failed_invoice( $invoice ) {
278
+	public function failed_invoice($invoice) {
279 279
 
280
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
280
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
281 281
 		$recipient = wpinv_get_admin_email();
282 282
 
283
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
283
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
284 284
 
285 285
 	}
286 286
 
@@ -289,12 +289,12 @@  discard block
 block discarded – undo
289 289
 	 *
290 290
 	 * @param WPInv_Invoice $invoice
291 291
 	 */
292
-	public function onhold_invoice( $invoice ) {
292
+	public function onhold_invoice($invoice) {
293 293
 
294
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
294
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
295 295
 		$recipient = $invoice->get_email();
296 296
 
297
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
297
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
298 298
 
299 299
 	}
300 300
 
@@ -303,12 +303,12 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param WPInv_Invoice $invoice
305 305
 	 */
306
-	public function processing_invoice( $invoice ) {
306
+	public function processing_invoice($invoice) {
307 307
 
308
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
308
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
309 309
 		$recipient = $invoice->get_email();
310 310
 
311
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
311
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
312 312
 
313 313
 	}
314 314
 
@@ -317,17 +317,17 @@  discard block
 block discarded – undo
317 317
 	 *
318 318
 	 * @param WPInv_Invoice $invoice
319 319
 	 */
320
-	public function completed_invoice( $invoice ) {
320
+	public function completed_invoice($invoice) {
321 321
 
322 322
 		// (Maybe) abort if it is a renewal invoice.
323
-		if ( $invoice->is_renewal() && ! wpinv_get_option( 'email_completed_invoice_renewal_active', false ) ) {
323
+		if ($invoice->is_renewal() && !wpinv_get_option('email_completed_invoice_renewal_active', false)) {
324 324
 			return;
325 325
 		}
326 326
 
327
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
327
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
328 328
 		$recipient = $invoice->get_email();
329 329
 
330
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
330
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
331 331
 
332 332
 	}
333 333
 
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
 	 *
337 337
 	 * @param WPInv_Invoice $invoice
338 338
 	 */
339
-	public function refunded_invoice( $invoice ) {
339
+	public function refunded_invoice($invoice) {
340 340
 
341
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
341
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
342 342
 		$recipient = $invoice->get_email();
343 343
 
344
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
344
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
345 345
 
346 346
 	}
347 347
 
@@ -351,21 +351,21 @@  discard block
 block discarded – undo
351 351
 	 * @param WPInv_Invoice $invoice
352 352
 	 * @param bool $force
353 353
 	 */
354
-	public function user_invoice( $invoice, $force = false ) {
354
+	public function user_invoice($invoice, $force = false) {
355 355
 
356
-		if ( ! empty( $GLOBALS['wpinv_skip_invoice_notification'] ) ) {
356
+		if (!empty($GLOBALS['wpinv_skip_invoice_notification'])) {
357 357
 			return;
358 358
 		}
359 359
 
360 360
 		// Only send this email for invoices created via the admin page.
361
-		if ( ! $invoice->is_type( 'invoice' ) || ( empty( $force ) && $this->is_payment_form_invoice( $invoice->get_id() ) ) ) {
361
+		if (!$invoice->is_type('invoice') || (empty($force) && $this->is_payment_form_invoice($invoice->get_id()))) {
362 362
 			return;
363 363
 		}
364 364
 
365
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
365
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
366 366
 		$recipient = $invoice->get_email();
367 367
 
368
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient );
368
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient);
369 369
 
370 370
 	}
371 371
 
@@ -375,9 +375,9 @@  discard block
 block discarded – undo
375 375
 	 * @param int $invoice
376 376
 	 * @return bool
377 377
 	 */
378
-	public function is_payment_form_invoice( $invoice ) {
379
-		$is_payment_form_invoice = empty( $_GET['getpaid-admin-action'] ) && ( 'payment_form' == get_post_meta( $invoice, 'wpinv_created_via', true ) || 'geodirectory' == get_post_meta( $invoice, 'wpinv_created_via', true ) );
380
-		return apply_filters( 'getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice );
378
+	public function is_payment_form_invoice($invoice) {
379
+		$is_payment_form_invoice = empty($_GET['getpaid-admin-action']) && ('payment_form' == get_post_meta($invoice, 'wpinv_created_via', true) || 'geodirectory' == get_post_meta($invoice, 'wpinv_created_via', true));
380
+		return apply_filters('getpaid_invoice_notifications_is_payment_form_invoice', $is_payment_form_invoice, $invoice);
381 381
 	}
382 382
 
383 383
 	/**
@@ -386,12 +386,12 @@  discard block
 block discarded – undo
386 386
 	 * @param WPInv_Invoice $invoice
387 387
 	 * @param string $note
388 388
 	 */
389
-	public function user_note( $invoice, $note ) {
389
+	public function user_note($invoice, $note) {
390 390
 
391
-		$email     = new GetPaid_Notification_Email( __FUNCTION__, $invoice );
391
+		$email     = new GetPaid_Notification_Email(__FUNCTION__, $invoice);
392 392
 		$recipient = $invoice->get_email();
393 393
 
394
-		return $this->send_email( $invoice, $email, __FUNCTION__, $recipient, array( 'customer_note' => $note ) );
394
+		return $this->send_email($invoice, $email, __FUNCTION__, $recipient, array('customer_note' => $note));
395 395
 
396 396
 	}
397 397
 
@@ -400,9 +400,9 @@  discard block
 block discarded – undo
400 400
 	 *
401 401
 	 * @param WPInv_Invoice $invoice
402 402
 	 */
403
-	public function force_send_overdue_notice( $invoice ) {
404
-		$email = new GetPaid_Notification_Email( 'overdue', $invoice );
405
-		return $this->send_email( $invoice, $email, 'overdue', $invoice->get_email() );
403
+	public function force_send_overdue_notice($invoice) {
404
+		$email = new GetPaid_Notification_Email('overdue', $invoice);
405
+		return $this->send_email($invoice, $email, 'overdue', $invoice->get_email());
406 406
 	}
407 407
 
408 408
 	/**
@@ -413,37 +413,37 @@  discard block
 block discarded – undo
413 413
 	public function overdue() {
414 414
 		global $wpdb;
415 415
 
416
-		$email = new GetPaid_Notification_Email( __FUNCTION__ );
416
+		$email = new GetPaid_Notification_Email(__FUNCTION__);
417 417
 
418 418
 		// Fetch reminder days.
419
-		$reminder_days = array_unique( wp_parse_id_list( $email->get_option( 'days' ) ) );
419
+		$reminder_days = array_unique(wp_parse_id_list($email->get_option('days')));
420 420
 
421 421
 		// Abort if non is set.
422
-		if ( empty( $reminder_days ) ) {
422
+		if (empty($reminder_days)) {
423 423
 			return;
424 424
 		}
425 425
 
426 426
 		// Retrieve date query.
427
-		$date_query = $this->get_date_query( $reminder_days );
427
+		$date_query = $this->get_date_query($reminder_days);
428 428
 
429 429
 		// Invoices table.
430 430
 		$table = $wpdb->prefix . 'getpaid_invoices';
431 431
 
432 432
 		// Fetch invoices.
433
-		$invoices  = $wpdb->get_col(
433
+		$invoices = $wpdb->get_col(
434 434
 			"SELECT posts.ID FROM $wpdb->posts as posts
435 435
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
436 436
 			WHERE posts.post_type = 'wpi_invoice' AND posts.post_status = 'wpi-pending' $date_query");
437 437
 
438
-		foreach ( $invoices as $invoice ) {
438
+		foreach ($invoices as $invoice) {
439 439
 
440 440
 			// Only send this email for invoices created via the admin page.
441
-			if ( ! $this->is_payment_form_invoice( $invoice ) ) {
442
-				$invoice       = new WPInv_Invoice( $invoice );
441
+			if (!$this->is_payment_form_invoice($invoice)) {
442
+				$invoice       = new WPInv_Invoice($invoice);
443 443
 				$email->object = $invoice;
444 444
 
445
-				if ( $invoice->needs_payment() ) {
446
-					$this->send_email( $invoice, $email, __FUNCTION__, $invoice->get_email() );
445
+				if ($invoice->needs_payment()) {
446
+					$this->send_email($invoice, $email, __FUNCTION__, $invoice->get_email());
447 447
 				}
448 448
 
449 449
 			}
@@ -458,14 +458,14 @@  discard block
 block discarded – undo
458 458
 	 * @param array $reminder_days
459 459
 	 * @return string
460 460
 	 */
461
-	public function get_date_query( $reminder_days ) {
461
+	public function get_date_query($reminder_days) {
462 462
 
463 463
 		$date_query = array(
464 464
 			'relation'  => 'OR'
465 465
 		);
466 466
 
467
-		foreach ( $reminder_days as $days ) {
468
-			$date = date_parse( date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) ) );
467
+		foreach ($reminder_days as $days) {
468
+			$date = date_parse(date('Y-m-d', strtotime("-$days days", current_time('timestamp'))));
469 469
 
470 470
 			$date_query[] = array(
471 471
 				'year'  => $date['year'],
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 
476 476
 		}
477 477
 
478
-		$date_query = new WP_Date_Query( $date_query, 'invoices.due_date' );
478
+		$date_query = new WP_Date_Query($date_query, 'invoices.due_date');
479 479
 
480 480
 		return $date_query->get_sql();
481 481
 
Please login to merge, or discard this patch.
includes/class-getpaid-notification-email-sender.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Notification_Email_Sender {
14 14
 
15 15
     /**
16
-	 * Whether or not we should inline CSS into the email.
17
-	 */
18
-	public $inline_css = true;
16
+     * Whether or not we should inline CSS into the email.
17
+     */
18
+    public $inline_css = true;
19 19
 
20 20
     /**
21
-	 * The wp_mail() data.
22
-	 */
21
+     * The wp_mail() data.
22
+     */
23 23
     public $wp_mail_data = null;
24 24
 
25 25
     /**
26
-	 * Sends a new email.
26
+     * Sends a new email.
27 27
      * 
28 28
      * @param string|array $to The recipients email or an array of recipient emails.
29 29
      * @param string $subject The email's subject.
@@ -31,49 +31,49 @@  discard block
 block discarded – undo
31 31
      * @param array $attachments The email attachments.
32 32
      * 
33 33
      * @return bool
34
-	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
34
+     */
35
+    public function send( $to, $subject, $email, $attachments = array() ) {
36 36
 
37
-		/*
37
+        /*
38 38
 		 * Allow to filter data on per-email basis.
39 39
 		 */
40
-		$data = apply_filters(
41
-			'getpaid_email_data',
42
-			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
-				'headers'     => $this->get_headers(),
47
-				'attachments' => $attachments,
48
-			),
49
-			$this
50
-		);
40
+        $data = apply_filters(
41
+            'getpaid_email_data',
42
+            array(
43
+                'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
+                'subject'     => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ),
45
+                'email'       => apply_filters( 'wpinv_mail_content', $email ),
46
+                'headers'     => $this->get_headers(),
47
+                'attachments' => $attachments,
48
+            ),
49
+            $this
50
+        );
51 51
 
52 52
         // Remove slashes.
53 53
         $data               = (array) wp_unslash( $data );
54 54
 
55 55
         // Cache it.
56
-		$this->wp_mail_data = $data;
56
+        $this->wp_mail_data = $data;
57 57
 
58
-		// Attach our own hooks.
59
-		$this->before_sending();
58
+        // Attach our own hooks.
59
+        $this->before_sending();
60 60
 
61 61
         $result = false;
62 62
 
63 63
         foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
64
+            $result = $this->_send( $to, $data );
65 65
         }
66 66
 
67
-		// Remove our hooks.
68
-		$this->after_sending();		
67
+        // Remove our hooks.
68
+        $this->after_sending();		
69 69
 
70
-		$this->wp_mail_data = null;
70
+        $this->wp_mail_data = null;
71 71
 
72
-		return $result;
73
-	}
72
+        return $result;
73
+    }
74 74
 
75
-	/**
76
-	 * Does the actual sending.
75
+    /**
76
+     * Does the actual sending.
77 77
      * 
78 78
      * @param string $to The recipient's email.
79 79
      * @param array $data The email's data.
@@ -81,81 +81,81 @@  discard block
 block discarded – undo
81 81
      * @param array $attachments The email attachments.
82 82
      * 
83 83
      * @return bool
84
-	 */
85
-	protected function _send( $to, $data ) {
86
-
87
-		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
-
90
-		// Send the actual email.
91
-		$result = call_user_func(
92
-			$sending_function,
93
-			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
-			$data['email'],
96
-			$data['headers'],
97
-			$data['attachments']
98
-		);
99
-
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
-		}
104
-
105
-		return $result;
106
-	}
84
+     */
85
+    protected function _send( $to, $data ) {
86
+
87
+        // Prepare the sending function.
88
+        $sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
89
+
90
+        // Send the actual email.
91
+        $result = call_user_func(
92
+            $sending_function,
93
+            $to,
94
+            html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
95
+            $data['email'],
96
+            $data['headers'],
97
+            $data['attachments']
98
+        );
99
+
100
+        if ( ! $result ) {
101
+            $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
+            wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
103
+        }
104
+
105
+        return $result;
106
+    }
107 107
     
108 108
     /**
109
-	 * Retrieves email headers.
110
-	 */
111
-	public function get_headers() {
109
+     * Retrieves email headers.
110
+     */
111
+    public function get_headers() {
112 112
 
113
-		$name       = $this->get_from_name();
114
-		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
113
+        $name       = $this->get_from_name();
114
+        $reply_to   = $this->get_reply_to();
115
+        $headers    = array( "Reply-To:$name <$reply_to>" );
116 116
 
117
-		return apply_filters( 'getpaid_email_headers',  $headers, $this );
117
+        return apply_filters( 'getpaid_email_headers',  $headers, $this );
118 118
 
119
-	}
119
+    }
120 120
 
121 121
     /**
122
-	 * Fires before an email is sent
123
-	 *
124
-	 * @since 1.0.0
125
-	 */
126
-	public function before_sending() {
122
+     * Fires before an email is sent
123
+     *
124
+     * @since 1.0.0
125
+     */
126
+    public function before_sending() {
127 127
 
128 128
         do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
129
+        add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
+        add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
+        add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
+        add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
133 133
 
134
-	}
134
+    }
135 135
 
136 136
     /**
137
-	 * Returns the from name.
138
-	 */
139
-	public function get_from_name() {
137
+     * Returns the from name.
138
+     */
139
+    public function get_from_name() {
140 140
 
141 141
         $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name =  get_bloginfo( 'name' );
143
+        if ( empty( $from_name ) ) {
144
+            $from_name =  get_bloginfo( 'name' );
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+        return wp_specialchars_decode( $from_name, ENT_QUOTES );
148 148
     }
149 149
 
150 150
     /**
151
-	 * Returns the from email.
152
-	 */
153
-	public function get_from_address() {
151
+     * Returns the from email.
152
+     */
153
+    public function get_from_address() {
154 154
 
155 155
         $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address =  $this->default_from_address();
157
+        if ( ! is_email( $from_address ) ) {
158
+            $from_address =  $this->default_from_address();
159 159
         }
160 160
         
161 161
         return $from_address;
@@ -163,75 +163,75 @@  discard block
 block discarded – undo
163 163
     }
164 164
 
165 165
     /**
166
-	 * The default emails from address.
167
-	 * 
168
-	 * Defaults to wordpress@$sitename
169
-	 * Some hosts will block outgoing mail from this address if it doesn't exist,
170
-	 * but there's no easy alternative. Defaulting to admin_email might appear to be
171
-	 * another option, but some hosts may refuse to relay mail from an unknown domain.
172
-	 *
173
-	 */
174
-	public function default_from_address() {
175
-
176
-		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
180
-		}
181
-
182
-		$from_email = 'wordpress@' . $sitename;
183
-
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
166
+     * The default emails from address.
167
+     * 
168
+     * Defaults to wordpress@$sitename
169
+     * Some hosts will block outgoing mail from this address if it doesn't exist,
170
+     * but there's no easy alternative. Defaulting to admin_email might appear to be
171
+     * another option, but some hosts may refuse to relay mail from an unknown domain.
172
+     *
173
+     */
174
+    public function default_from_address() {
175
+
176
+        // Get the site domain and get rid of www.
177
+        $sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
+        if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
+            $sitename = substr( $sitename, 4 );
180
+        }
181
+
182
+        $from_email = 'wordpress@' . $sitename;
183
+
184
+        return apply_filters( 'getpaid_default_from_address', $from_email );
185 185
 
186 186
     }
187 187
     
188 188
     /**
189
-	 * Get the email reply-to.
190
-	 *
191
-	 *
192
-	 * @return string The email reply-to address.
193
-	 */
194
-	public function get_reply_to() {
189
+     * Get the email reply-to.
190
+     *
191
+     *
192
+     * @return string The email reply-to address.
193
+     */
194
+    public function get_reply_to() {
195 195
 
196
-		$reply_to = wpinv_get_admin_email();
196
+        $reply_to = wpinv_get_admin_email();
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to =  get_option( 'admin_email' );
200
-		}
198
+        if ( ! is_email( $reply_to ) ) {
199
+            $reply_to =  get_option( 'admin_email' );
200
+        }
201 201
 
202
-		return $reply_to;
202
+        return $reply_to;
203 203
     }
204 204
     
205 205
     /**
206
-	 * Get the email content type.
207
-	 *
208
-	 */
209
-	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
206
+     * Get the email content type.
207
+     *
208
+     */
209
+    public function get_content_type() {
210
+        return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
211 211
     }
212 212
     
213 213
     /**
214
-	 * Ensures that our email messages are not messed up by template plugins.
215
-	 *
216
-	 * @return array wp_mail_data.
217
-	 */
218
-	public function ensure_email_content( $args ) {
219
-		$args['message'] = $this->wp_mail_data['email'];
220
-		return $args;
214
+     * Ensures that our email messages are not messed up by template plugins.
215
+     *
216
+     * @return array wp_mail_data.
217
+     */
218
+    public function ensure_email_content( $args ) {
219
+        $args['message'] = $this->wp_mail_data['email'];
220
+        return $args;
221 221
     }
222 222
     
223 223
     /**
224
-	 * A little house keeping after an email is sent.
225
-	 *
226
- 	 */
227
-	public function after_sending() {
224
+     * A little house keeping after an email is sent.
225
+     *
226
+     */
227
+    public function after_sending() {
228 228
 
229 229
         do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
230
+        remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
+        remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
+        remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
+        remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
234 234
 
235
-	}
235
+    }
236 236
 
237 237
 }
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * This function is responsible for sending emails.
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      * 
33 33
      * @return bool
34 34
 	 */
35
-	public function send( $to, $subject, $email, $attachments = array() ) {
35
+	public function send($to, $subject, $email, $attachments = array()) {
36 36
 
37 37
 		/*
38 38
 		 * Allow to filter data on per-email basis.
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 		$data = apply_filters(
41 41
 			'getpaid_email_data',
42 42
 			array(
43
-				'to'          => array_filter( array_unique( wpinv_parse_list( $to ) ) ),
44
-				'subject'     => htmlspecialchars_decode( strip_tags( $subject ), ENT_QUOTES ),
45
-				'email'       => apply_filters( 'wpinv_mail_content', $email ),
43
+				'to'          => array_filter(array_unique(wpinv_parse_list($to))),
44
+				'subject'     => htmlspecialchars_decode(strip_tags($subject), ENT_QUOTES),
45
+				'email'       => apply_filters('wpinv_mail_content', $email),
46 46
 				'headers'     => $this->get_headers(),
47 47
 				'attachments' => $attachments,
48 48
 			),
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 		);
51 51
 
52 52
         // Remove slashes.
53
-        $data               = (array) wp_unslash( $data );
53
+        $data = (array) wp_unslash($data);
54 54
 
55 55
         // Cache it.
56 56
 		$this->wp_mail_data = $data;
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 
61 61
         $result = false;
62 62
 
63
-        foreach ( $this->wp_mail_data['to'] as $to ) {
64
-			$result = $this->_send( $to, $data );
63
+        foreach ($this->wp_mail_data['to'] as $to) {
64
+			$result = $this->_send($to, $data);
65 65
         }
66 66
 
67 67
 		// Remove our hooks.
@@ -82,24 +82,24 @@  discard block
 block discarded – undo
82 82
      * 
83 83
      * @return bool
84 84
 	 */
85
-	protected function _send( $to, $data ) {
85
+	protected function _send($to, $data) {
86 86
 
87 87
 		// Prepare the sending function.
88
-		$sending_function = apply_filters( 'getpaid_email_email_sending_function', 'wp_mail' );
88
+		$sending_function = apply_filters('getpaid_email_email_sending_function', 'wp_mail');
89 89
 
90 90
 		// Send the actual email.
91 91
 		$result = call_user_func(
92 92
 			$sending_function,
93 93
 			$to,
94
-			html_entity_decode( $data['subject'], ENT_QUOTES, get_bloginfo( 'charset' ) ),
94
+			html_entity_decode($data['subject'], ENT_QUOTES, get_bloginfo('charset')),
95 95
 			$data['email'],
96 96
 			$data['headers'],
97 97
 			$data['attachments']
98 98
 		);
99 99
 
100
-		if ( ! $result ) {
101
-			$log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), $to, $data['subject'] );
102
-			wpinv_error_log( $log_message, __( 'Email from Invoicing plugin failed to send', 'invoicing' ), __FILE__, __LINE__ );
100
+		if (!$result) {
101
+			$log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), $to, $data['subject']);
102
+			wpinv_error_log($log_message, __('Email from Invoicing plugin failed to send', 'invoicing'), __FILE__, __LINE__);
103 103
 		}
104 104
 
105 105
 		return $result;
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 
113 113
 		$name       = $this->get_from_name();
114 114
 		$reply_to   = $this->get_reply_to();
115
-		$headers    = array( "Reply-To:$name <$reply_to>" );
115
+		$headers    = array("Reply-To:$name <$reply_to>");
116 116
 
117
-		return apply_filters( 'getpaid_email_headers',  $headers, $this );
117
+		return apply_filters('getpaid_email_headers', $headers, $this);
118 118
 
119 119
 	}
120 120
 
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function before_sending() {
127 127
 
128
-        do_action( 'getpaid_before_send_email', $this );
129
-		add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
130
-		add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
131
-		add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
132
-		add_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
128
+        do_action('getpaid_before_send_email', $this);
129
+		add_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
130
+		add_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
131
+		add_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
132
+		add_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
133 133
 
134 134
 	}
135 135
 
@@ -138,13 +138,13 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function get_from_name() {
140 140
 
141
-        $from_name = wpinv_get_option( 'email_from_name', get_bloginfo( 'name' ) );
141
+        $from_name = wpinv_get_option('email_from_name', get_bloginfo('name'));
142 142
 
143
-		if ( empty( $from_name ) ) {
144
-			$from_name =  get_bloginfo( 'name' );
143
+		if (empty($from_name)) {
144
+			$from_name = get_bloginfo('name');
145 145
         }
146 146
 
147
-		return wp_specialchars_decode( $from_name, ENT_QUOTES );
147
+		return wp_specialchars_decode($from_name, ENT_QUOTES);
148 148
     }
149 149
 
150 150
     /**
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function get_from_address() {
154 154
 
155
-        $from_address = wpinv_get_option( 'email_from', $this->default_from_address() );
155
+        $from_address = wpinv_get_option('email_from', $this->default_from_address());
156 156
 
157
-		if ( ! is_email( $from_address ) ) {
158
-			$from_address =  $this->default_from_address();
157
+		if (!is_email($from_address)) {
158
+			$from_address = $this->default_from_address();
159 159
         }
160 160
         
161 161
         return $from_address;
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	public function default_from_address() {
175 175
 
176 176
 		// Get the site domain and get rid of www.
177
-		$sitename = strtolower( $_SERVER['SERVER_NAME'] );
178
-		if ( substr( $sitename, 0, 4 ) == 'www.' ) {
179
-			$sitename = substr( $sitename, 4 );
177
+		$sitename = strtolower($_SERVER['SERVER_NAME']);
178
+		if (substr($sitename, 0, 4) == 'www.') {
179
+			$sitename = substr($sitename, 4);
180 180
 		}
181 181
 
182 182
 		$from_email = 'wordpress@' . $sitename;
183 183
 
184
-		return apply_filters( 'getpaid_default_from_address', $from_email );
184
+		return apply_filters('getpaid_default_from_address', $from_email);
185 185
 
186 186
     }
187 187
     
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 
196 196
 		$reply_to = wpinv_get_admin_email();
197 197
 
198
-		if ( ! is_email( $reply_to ) ) {
199
-			$reply_to =  get_option( 'admin_email' );
198
+		if (!is_email($reply_to)) {
199
+			$reply_to = get_option('admin_email');
200 200
 		}
201 201
 
202 202
 		return $reply_to;
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
 	 *
208 208
 	 */
209 209
 	public function get_content_type() {
210
-		return apply_filters( 'getpaid_email_content_type', 'text/html', $this );
210
+		return apply_filters('getpaid_email_content_type', 'text/html', $this);
211 211
     }
212 212
     
213 213
     /**
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
215 215
 	 *
216 216
 	 * @return array wp_mail_data.
217 217
 	 */
218
-	public function ensure_email_content( $args ) {
218
+	public function ensure_email_content($args) {
219 219
 		$args['message'] = $this->wp_mail_data['email'];
220 220
 		return $args;
221 221
     }
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
  	 */
227 227
 	public function after_sending() {
228 228
 
229
-        do_action( 'getpaid_after_send_email', $this->wp_mail_data );
230
-		remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 1000 );
231
-		remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 1000 );
232
-		remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 1000 );
233
-		remove_filter( 'wp_mail', array( $this, 'ensure_email_content' ), 1000 );
229
+        do_action('getpaid_after_send_email', $this->wp_mail_data);
230
+		remove_filter('wp_mail_from', array($this, 'get_from_address'), 1000);
231
+		remove_filter('wp_mail_from_name', array($this, 'get_from_name'), 1000);
232
+		remove_filter('wp_mail_content_type', array($this, 'get_content_type'), 1000);
233
+		remove_filter('wp_mail', array($this, 'ensure_email_content'), 1000);
234 234
 
235 235
 	}
236 236
 
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 2 patches
Indentation   +429 added lines, -429 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
  */
15 15
 function wpinv_subscriptions_page() {
16 16
 
17
-	?>
17
+    ?>
18 18
 
19 19
 	<div class="wrap">
20 20
 		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
@@ -22,27 +22,27 @@  discard block
 block discarded – undo
22 22
 
23 23
 			<?php
24 24
 
25
-				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
25
+                // Verify user permissions.
26
+                if ( ! wpinv_current_user_can_manage_invoicing() ) {
27 27
 
28
-					echo aui()->alert(
29
-						array(
30
-							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
-						)
33
-					);
28
+                    echo aui()->alert(
29
+                        array(
30
+                            'type'    => 'danger',
31
+                            'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
32
+                        )
33
+                    );
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+                } else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
36 36
 
37
-					// Display a single subscription.
38
-					wpinv_recurring_subscription_details();
39
-				} else {
37
+                    // Display a single subscription.
38
+                    wpinv_recurring_subscription_details();
39
+                } else {
40 40
 
41
-					// Display a list of available subscriptions.
42
-					getpaid_print_subscriptions_list();
43
-				}
41
+                    // Display a list of available subscriptions.
42
+                    getpaid_print_subscriptions_list();
43
+                }
44 44
 
45
-			?>
45
+            ?>
46 46
 
47 47
 		</div>
48 48
 	</div>
@@ -59,10 +59,10 @@  discard block
 block discarded – undo
59 59
  */
60 60
 function getpaid_print_subscriptions_list() {
61 61
 
62
-	$subscribers_table = new WPInv_Subscriptions_List_Table();
63
-	$subscribers_table->prepare_items();
62
+    $subscribers_table = new WPInv_Subscriptions_List_Table();
63
+    $subscribers_table->prepare_items();
64 64
 
65
-	?>
65
+    ?>
66 66
 	<form id="subscribers-filter" class="bsui" method="get">
67 67
 		<input type="hidden" name="page" value="wpinv-subscriptions" />
68 68
 		<?php $subscribers_table->views(); ?>
@@ -80,41 +80,41 @@  discard block
 block discarded – undo
80 80
  */
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83
-	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->exists() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->exists() ) {
86 86
 
87
-		echo aui()->alert(
88
-			array(
89
-				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
91
-			)
92
-		);
87
+        echo aui()->alert(
88
+            array(
89
+                'type'    => 'danger',
90
+                'content' => __( 'Subscription not found.', 'invoicing' ),
91
+            )
92
+        );
93 93
 
94
-		return;
95
-	}
94
+        return;
95
+    }
96 96
 
97
-	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
97
+    // Use metaboxes to display the subscription details.
98
+    add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100 100
 
101
-	$subscription_id     = $sub->get_id();
102
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
101
+    $subscription_id     = $sub->get_id();
102
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
+    $subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
104 104
 
105
-	if ( 1 < count( $subscription_groups ) ) {
106
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
107
-	}
105
+    if ( 1 < count( $subscription_groups ) ) {
106
+        add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
107
+    }
108 108
 
109
-	if ( ! empty( $subscription_group ) ) {
110
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
111
-	}
109
+    if ( ! empty( $subscription_group ) ) {
110
+        add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
111
+    }
112 112
 
113
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
113
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
114 114
 
115
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
115
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
116 116
 
117
-	?>
117
+    ?>
118 118
 
119 119
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
120 120
 
@@ -154,45 +154,45 @@  discard block
 block discarded – undo
154 154
  */
155 155
 function getpaid_admin_subscription_details_metabox( $sub ) {
156 156
 
157
-	// Subscription items.
158
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
159
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
160
-
161
-	// Prepare subscription detail columns.
162
-	$fields = apply_filters(
163
-		'getpaid_subscription_admin_page_fields',
164
-		array(
165
-			'subscription'   => __( 'Subscription', 'invoicing' ),
166
-			'customer'       => __( 'Customer', 'invoicing' ),
167
-			'amount'         => __( 'Amount', 'invoicing' ),
168
-			'start_date'     => __( 'Start Date', 'invoicing' ),
169
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
170
-			'renewals'       => __( 'Payments', 'invoicing' ),
171
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
172
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
173
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
174
-			'status'         => __( 'Status', 'invoicing' ),
175
-		)
176
-	);
177
-
178
-	if ( ! $sub->is_active() ) {
179
-
180
-		if ( isset( $fields['renews_on'] ) ) {
181
-			unset( $fields['renews_on'] );
182
-		}
183
-
184
-		if ( isset( $fields['gateway'] ) ) {
185
-			unset( $fields['gateway'] );
186
-		}
187
-
188
-	}
189
-
190
-	$profile_id = $sub->get_profile_id();
191
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
192
-		unset( $fields['profile_id'] );
193
-	}
194
-
195
-	?>
157
+    // Subscription items.
158
+    $subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
159
+    $items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
160
+
161
+    // Prepare subscription detail columns.
162
+    $fields = apply_filters(
163
+        'getpaid_subscription_admin_page_fields',
164
+        array(
165
+            'subscription'   => __( 'Subscription', 'invoicing' ),
166
+            'customer'       => __( 'Customer', 'invoicing' ),
167
+            'amount'         => __( 'Amount', 'invoicing' ),
168
+            'start_date'     => __( 'Start Date', 'invoicing' ),
169
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
170
+            'renewals'       => __( 'Payments', 'invoicing' ),
171
+            'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
172
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
173
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
174
+            'status'         => __( 'Status', 'invoicing' ),
175
+        )
176
+    );
177
+
178
+    if ( ! $sub->is_active() ) {
179
+
180
+        if ( isset( $fields['renews_on'] ) ) {
181
+            unset( $fields['renews_on'] );
182
+        }
183
+
184
+        if ( isset( $fields['gateway'] ) ) {
185
+            unset( $fields['gateway'] );
186
+        }
187
+
188
+    }
189
+
190
+    $profile_id = $sub->get_profile_id();
191
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
192
+        unset( $fields['profile_id'] );
193
+    }
194
+
195
+    ?>
196 196
 
197 197
 		<table class="table table-borderless" style="font-size: 14px;">
198 198
 			<tbody>
@@ -226,20 +226,20 @@  discard block
 block discarded – undo
226 226
  */
227 227
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
228 228
 
229
-	$username = __( '(Missing User)', 'invoicing' );
229
+    $username = __( '(Missing User)', 'invoicing' );
230 230
 
231
-	$user = get_userdata( $subscription->get_customer_id() );
232
-	if ( $user ) {
231
+    $user = get_userdata( $subscription->get_customer_id() );
232
+    if ( $user ) {
233 233
 
234
-		$username = sprintf(
235
-			'<a href="user-edit.php?user_id=%s">%s</a>',
236
-			absint( $user->ID ),
237
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
238
-		);
234
+        $username = sprintf(
235
+            '<a href="user-edit.php?user_id=%s">%s</a>',
236
+            absint( $user->ID ),
237
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
238
+        );
239 239
 
240
-	}
240
+    }
241 241
 
242
-	echo  $username;
242
+    echo  $username;
243 243
 }
244 244
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
245 245
 
@@ -249,8 +249,8 @@  discard block
 block discarded – undo
249 249
  * @param WPInv_Subscription $subscription
250 250
  */
251 251
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
252
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
253
-	echo "<span>$amount</span>";
252
+    $amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
253
+    echo "<span>$amount</span>";
254 254
 }
255 255
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
256 256
 
@@ -260,7 +260,7 @@  discard block
 block discarded – undo
260 260
  * @param WPInv_Subscription $subscription
261 261
  */
262 262
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
263
-	echo  '#' . absint( $subscription->get_id() );
263
+    echo  '#' . absint( $subscription->get_id() );
264 264
 }
265 265
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
266 266
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
  * @param WPInv_Subscription $subscription
271 271
  */
272 272
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
273
-	echo getpaid_format_date_value( $subscription->get_date_created() );
273
+    echo getpaid_format_date_value( $subscription->get_date_created() );
274 274
 }
275 275
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
276 276
 
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
  * @param WPInv_Subscription $subscription
281 281
  */
282 282
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
283
-	echo getpaid_format_date_value( $subscription->get_expiration() );
283
+    echo getpaid_format_date_value( $subscription->get_expiration() );
284 284
 }
285 285
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
286 286
 
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
  * @param WPInv_Subscription $subscription
291 291
  */
292 292
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
293
-	$max_bills = $subscription->get_bill_times();
294
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
293
+    $max_bills = $subscription->get_bill_times();
294
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
295 295
 }
296 296
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
297 297
 /**
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
  */
303 303
 function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
304 304
 
305
-	if ( empty( $subscription_group ) ) {
306
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
307
-		return;
308
-	}
305
+    if ( empty( $subscription_group ) ) {
306
+        echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
307
+        return;
308
+    }
309 309
 
310
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
311
-	echo implode( ' | ', $markup );
310
+    $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
311
+    echo implode( ' | ', $markup );
312 312
 
313 313
 }
314 314
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
@@ -320,13 +320,13 @@  discard block
 block discarded – undo
320 320
  */
321 321
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
322 322
 
323
-	$gateway = $subscription->get_gateway();
323
+    $gateway = $subscription->get_gateway();
324 324
 
325
-	if ( ! empty( $gateway ) ) {
326
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
327
-	} else {
328
-		echo "&mdash;";
329
-	}
325
+    if ( ! empty( $gateway ) ) {
326
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
327
+    } else {
328
+        echo "&mdash;";
329
+    }
330 330
 
331 331
 }
332 332
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
  * @param WPInv_Subscription $subscription
338 338
  */
339 339
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
340
-	echo $subscription->get_status_label_html();
340
+    echo $subscription->get_status_label_html();
341 341
 }
342 342
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
343 343
 
@@ -348,29 +348,29 @@  discard block
 block discarded – undo
348 348
  */
349 349
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
350 350
 
351
-	$profile_id = $subscription->get_profile_id();
352
-
353
-	$input = aui()->input(
354
-		array(
355
-			'type'        => 'text',
356
-			'id'          => 'wpinv_subscription_profile_id',
357
-			'name'        => 'wpinv_subscription_profile_id',
358
-			'label'       => __( 'Profile Id', 'invoicing' ),
359
-			'label_type'  => 'hidden',
360
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
361
-			'value'       => sanitize_text_field( $profile_id ),
362
-			'input_group_right' => '',
363
-			'no_wrap'     => true,
364
-		)
365
-	);
366
-
367
-	echo str_ireplace( 'form-control', 'regular-text', $input );
368
-
369
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
370
-	if ( ! empty( $url ) ) {
371
-		$url = esc_url_raw( $url );
372
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
373
-	}
351
+    $profile_id = $subscription->get_profile_id();
352
+
353
+    $input = aui()->input(
354
+        array(
355
+            'type'        => 'text',
356
+            'id'          => 'wpinv_subscription_profile_id',
357
+            'name'        => 'wpinv_subscription_profile_id',
358
+            'label'       => __( 'Profile Id', 'invoicing' ),
359
+            'label_type'  => 'hidden',
360
+            'placeholder' => __( 'Profile Id', 'invoicing' ),
361
+            'value'       => sanitize_text_field( $profile_id ),
362
+            'input_group_right' => '',
363
+            'no_wrap'     => true,
364
+        )
365
+    );
366
+
367
+    echo str_ireplace( 'form-control', 'regular-text', $input );
368
+
369
+    $url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
370
+    if ( ! empty( $url ) ) {
371
+        $url = esc_url_raw( $url );
372
+        echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
373
+    }
374 374
 
375 375
 }
376 376
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -382,39 +382,39 @@  discard block
 block discarded – undo
382 382
  */
383 383
 function getpaid_admin_subscription_update_metabox( $subscription ) {
384 384
 
385
-	?>
385
+    ?>
386 386
 	<div class="mt-3">
387 387
 
388 388
 		<?php
389
-			echo aui()->select(
390
-				array(
391
-					'options'          => getpaid_get_subscription_statuses(),
392
-					'name'             => 'subscription_status',
393
-					'id'               => 'subscription_status_update_select',
394
-					'required'         => true,
395
-					'no_wrap'          => false,
396
-					'label'            => __( 'Subscription Status', 'invoicing' ),
397
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
398
-					'select2'          => true,
399
-					'value'            => $subscription->get_status( 'edit' ),
400
-				)
401
-			);
402
-		?>
389
+            echo aui()->select(
390
+                array(
391
+                    'options'          => getpaid_get_subscription_statuses(),
392
+                    'name'             => 'subscription_status',
393
+                    'id'               => 'subscription_status_update_select',
394
+                    'required'         => true,
395
+                    'no_wrap'          => false,
396
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
397
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
398
+                    'select2'          => true,
399
+                    'value'            => $subscription->get_status( 'edit' ),
400
+                )
401
+            );
402
+        ?>
403 403
 
404 404
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
405 405
 
406 406
 		<?php
407
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
407
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
408 408
 
409
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
410
-			$anchor = __( 'Renew Subscription', 'invoicing' );
411
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
409
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
410
+            $anchor = __( 'Renew Subscription', 'invoicing' );
411
+            $title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
412 412
 
413
-			if ( $subscription->is_active() ) {
414
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
415
-			}
413
+            if ( $subscription->is_active() ) {
414
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
415
+            }
416 416
 
417
-	echo '</div></div>';
417
+    echo '</div></div>';
418 418
 }
419 419
 
420 420
 /**
@@ -425,33 +425,33 @@  discard block
 block discarded – undo
425 425
  */
426 426
 function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
427 427
 
428
-	$columns = apply_filters(
429
-		'getpaid_subscription_related_invoices_columns',
430
-		array(
431
-			'invoice'      => __( 'Invoice', 'invoicing' ),
432
-			'relationship' => __( 'Relationship', 'invoicing' ),
433
-			'date'         => __( 'Date', 'invoicing' ),
434
-			'status'       => __( 'Status', 'invoicing' ),
435
-			'total'        => __( 'Total', 'invoicing' ),
436
-		),
437
-		$subscription
438
-	);
439
-
440
-	// Prepare the invoices.
441
-	$payments = $subscription->get_child_payments( ! is_admin() );
442
-	$parent   = $subscription->get_parent_invoice();
443
-
444
-	if ( $parent->exists() ) {
445
-		$payments = array_merge( array( $parent ), $payments );
446
-	}
447
-
448
-	$table_class = 'w-100 bg-white';
449
-
450
-	if ( ! is_admin() ) {
451
-		$table_class = 'table table-bordered';
452
-	}
453
-
454
-	?>
428
+    $columns = apply_filters(
429
+        'getpaid_subscription_related_invoices_columns',
430
+        array(
431
+            'invoice'      => __( 'Invoice', 'invoicing' ),
432
+            'relationship' => __( 'Relationship', 'invoicing' ),
433
+            'date'         => __( 'Date', 'invoicing' ),
434
+            'status'       => __( 'Status', 'invoicing' ),
435
+            'total'        => __( 'Total', 'invoicing' ),
436
+        ),
437
+        $subscription
438
+    );
439
+
440
+    // Prepare the invoices.
441
+    $payments = $subscription->get_child_payments( ! is_admin() );
442
+    $parent   = $subscription->get_parent_invoice();
443
+
444
+    if ( $parent->exists() ) {
445
+        $payments = array_merge( array( $parent ), $payments );
446
+    }
447
+
448
+    $table_class = 'w-100 bg-white';
449
+
450
+    if ( ! is_admin() ) {
451
+        $table_class = 'table table-bordered';
452
+    }
453
+
454
+    ?>
455 455
 		<div class="m-0" style="overflow: auto;">
456 456
 
457 457
 			<table class="<?php echo $table_class; ?>">
@@ -459,14 +459,14 @@  discard block
 block discarded – undo
459 459
 				<thead>
460 460
 					<tr>
461 461
 						<?php
462
-							foreach ( $columns as $key => $label ) {
463
-								$key   = esc_attr( $key );
464
-								$label = sanitize_text_field( $label );
465
-								$class = 'text-left';
466
-
467
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
468
-							}
469
-						?>
462
+                            foreach ( $columns as $key => $label ) {
463
+                                $key   = esc_attr( $key );
464
+                                $label = sanitize_text_field( $label );
465
+                                $class = 'text-left';
466
+
467
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
468
+                            }
469
+                        ?>
470 470
 					</tr>
471 471
 				</thead>
472 472
 
@@ -482,73 +482,73 @@  discard block
 block discarded – undo
482 482
 
483 483
 					<?php
484 484
 
485
-						foreach( $payments as $payment ) :
485
+                        foreach( $payments as $payment ) :
486 486
 
487
-							// Ensure that we have an invoice.
488
-							$payment = new WPInv_Invoice( $payment );
487
+                            // Ensure that we have an invoice.
488
+                            $payment = new WPInv_Invoice( $payment );
489 489
 
490
-							// Abort if the invoice is invalid...
491
-							if ( ! $payment->exists() ) {
492
-								continue;
493
-							}
490
+                            // Abort if the invoice is invalid...
491
+                            if ( ! $payment->exists() ) {
492
+                                continue;
493
+                            }
494 494
 
495
-							// ... or belongs to a different subscription.
496
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
497
-								continue;
498
-							}
495
+                            // ... or belongs to a different subscription.
496
+                            if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
497
+                                continue;
498
+                            }
499 499
 
500
-							echo '<tr>';
500
+                            echo '<tr>';
501 501
 
502
-								foreach ( array_keys( $columns ) as $key ) {
502
+                                foreach ( array_keys( $columns ) as $key ) {
503 503
 
504
-									$class = 'text-left';
504
+                                    $class = 'text-left';
505 505
 
506
-									echo "<td class='p-2 $class'>";
506
+                                    echo "<td class='p-2 $class'>";
507 507
 
508
-										switch( $key ) {
508
+                                        switch( $key ) {
509 509
 
510
-											case 'total':
511
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
512
-												break;
510
+                                            case 'total':
511
+                                                echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
512
+                                                break;
513 513
 
514
-											case 'relationship':
515
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
516
-												break;
514
+                                            case 'relationship':
515
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
516
+                                                break;
517 517
 
518
-											case 'date':
519
-												echo getpaid_format_date_value( $payment->get_date_created() );
520
-												break;
518
+                                            case 'date':
519
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
520
+                                                break;
521 521
 
522
-											case 'status':
522
+                                            case 'status':
523 523
 
524
-												$status = $payment->get_status_nicename();
525
-												if ( is_admin() ) {
526
-													$status = $payment->get_status_label_html();
527
-												}
524
+                                                $status = $payment->get_status_nicename();
525
+                                                if ( is_admin() ) {
526
+                                                    $status = $payment->get_status_label_html();
527
+                                                }
528 528
 
529
-												echo $status;
530
-												break;
529
+                                                echo $status;
530
+                                                break;
531 531
 
532
-											case 'invoice':
533
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
532
+                                            case 'invoice':
533
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
534 534
 
535
-												if ( ! is_admin() ) {
536
-													$link = esc_url( $payment->get_view_url() );
537
-												}
535
+                                                if ( ! is_admin() ) {
536
+                                                    $link = esc_url( $payment->get_view_url() );
537
+                                                }
538 538
 
539
-												$invoice = sanitize_text_field( $payment->get_number() );
540
-												echo "<a href='$link'>$invoice</a>";
541
-												break;
542
-										}
539
+                                                $invoice = sanitize_text_field( $payment->get_number() );
540
+                                                echo "<a href='$link'>$invoice</a>";
541
+                                                break;
542
+                                        }
543 543
 
544
-									echo '</td>';
544
+                                    echo '</td>';
545 545
 
546
-								}
546
+                                }
547 547
 
548
-							echo '</tr>';
548
+                            echo '</tr>';
549 549
 
550
-						endforeach;
551
-					?>
550
+                        endforeach;
551
+                    ?>
552 552
 
553 553
 				</tbody>
554 554
 
@@ -566,42 +566,42 @@  discard block
 block discarded – undo
566 566
  */
567 567
 function getpaid_admin_subscription_item_details_metabox( $subscription ) {
568 568
 
569
-	// Fetch the subscription group.
570
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
569
+    // Fetch the subscription group.
570
+    $subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
571 571
 
572
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
573
-		return;
574
-	}
572
+    if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
573
+        return;
574
+    }
575 575
 
576
-	// Prepare table columns.
577
-	$columns = apply_filters(
578
-		'getpaid_subscription_item_details_columns',
579
-		array(
580
-			'item_name'    => __( 'Item', 'invoicing' ),
581
-			'price'        => __( 'Price', 'invoicing' ),
582
-			'tax'          => __( 'Tax', 'invoicing' ),
583
-			'discount'     => __( 'Discount', 'invoicing' ),
584
-			//'initial'      => __( 'Initial Amount', 'invoicing' ),
585
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
586
-		),
587
-		$subscription
588
-	);
576
+    // Prepare table columns.
577
+    $columns = apply_filters(
578
+        'getpaid_subscription_item_details_columns',
579
+        array(
580
+            'item_name'    => __( 'Item', 'invoicing' ),
581
+            'price'        => __( 'Price', 'invoicing' ),
582
+            'tax'          => __( 'Tax', 'invoicing' ),
583
+            'discount'     => __( 'Discount', 'invoicing' ),
584
+            //'initial'      => __( 'Initial Amount', 'invoicing' ),
585
+            'recurring'    => __( 'Subtotal', 'invoicing' ),
586
+        ),
587
+        $subscription
588
+    );
589 589
 
590
-	// Prepare the invoices.
590
+    // Prepare the invoices.
591 591
 
592
-	$invoice = $subscription->get_parent_invoice();
592
+    $invoice = $subscription->get_parent_invoice();
593 593
 
594
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
595
-		unset( $columns['tax'] );
596
-	}
594
+    if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
595
+        unset( $columns['tax'] );
596
+    }
597 597
 
598
-	$table_class = 'w-100 bg-white';
598
+    $table_class = 'w-100 bg-white';
599 599
 
600
-	if ( ! is_admin() ) {
601
-		$table_class = 'table table-bordered';
602
-	}
600
+    if ( ! is_admin() ) {
601
+        $table_class = 'table table-bordered';
602
+    }
603 603
 
604
-	?>
604
+    ?>
605 605
 		<div class="m-0" style="overflow: auto;">
606 606
 
607 607
 			<table class="<?php echo $table_class; ?>">
@@ -610,14 +610,14 @@  discard block
 block discarded – undo
610 610
 					<tr>
611 611
 						<?php
612 612
 
613
-							foreach ( $columns as $key => $label ) {
614
-								$key   = esc_attr( $key );
615
-								$label = sanitize_text_field( $label );
616
-								$class = 'text-left';
613
+                            foreach ( $columns as $key => $label ) {
614
+                                $key   = esc_attr( $key );
615
+                                $label = sanitize_text_field( $label );
616
+                                $class = 'text-left';
617 617
 
618
-								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
619
-							}
620
-						?>
618
+                                echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
619
+                            }
620
+                        ?>
621 621
 					</tr>
622 622
 				</thead>
623 623
 
@@ -625,106 +625,106 @@  discard block
 block discarded – undo
625 625
 
626 626
 					<?php
627 627
 
628
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
628
+                        foreach( $subscription_group['items'] as $subscription_group_item ) :
629 629
 
630
-							echo '<tr>';
630
+                            echo '<tr>';
631 631
 
632
-								foreach ( array_keys( $columns ) as $key ) {
632
+                                foreach ( array_keys( $columns ) as $key ) {
633 633
 
634
-									$class = 'text-left';
634
+                                    $class = 'text-left';
635 635
 
636
-									echo "<td class='p-2 $class'>";
636
+                                    echo "<td class='p-2 $class'>";
637 637
 
638
-										switch( $key ) {
638
+                                        switch( $key ) {
639 639
 
640
-											case 'item_name':
641
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
642
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
640
+                                            case 'item_name':
641
+                                                $item_name = get_the_title( $subscription_group_item['item_id'] );
642
+                                                $item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
643 643
 
644
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
645
-													echo sanitize_text_field( $item_name );
646
-												} else {
647
-													printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] );
648
-												}
644
+                                                if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
645
+                                                    echo sanitize_text_field( $item_name );
646
+                                                } else {
647
+                                                    printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] );
648
+                                                }
649 649
 
650
-												break;
650
+                                                break;
651 651
 
652
-											case 'price':
653
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
654
-												break;
652
+                                            case 'price':
653
+                                                echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
654
+                                                break;
655 655
 
656
-											case 'tax':
657
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
658
-												break;
656
+                                            case 'tax':
657
+                                                echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
658
+                                                break;
659 659
 
660
-											case 'discount':
661
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
662
-												break;
660
+                                            case 'discount':
661
+                                                echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
662
+                                                break;
663 663
 
664
-											case 'initial':
665
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
666
-												break;
664
+                                            case 'initial':
665
+                                                echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
666
+                                                break;
667 667
 
668
-											case 'recurring':
669
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
670
-												break;
668
+                                            case 'recurring':
669
+                                                echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
670
+                                                break;
671 671
 
672
-										}
672
+                                        }
673 673
 
674
-									echo '</td>';
674
+                                    echo '</td>';
675 675
 
676
-								}
676
+                                }
677 677
 
678
-							echo '</tr>';
678
+                            echo '</tr>';
679 679
 
680
-						endforeach;
680
+                        endforeach;
681 681
 
682
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
682
+                        foreach( $subscription_group['fees'] as $subscription_group_fee ) :
683 683
 
684
-							echo '<tr>';
684
+                            echo '<tr>';
685 685
 
686
-								foreach ( array_keys( $columns ) as $key ) {
686
+                                foreach ( array_keys( $columns ) as $key ) {
687 687
 
688
-									$class = 'text-left';
688
+                                    $class = 'text-left';
689 689
 
690
-									echo "<td class='p-2 $class'>";
690
+                                    echo "<td class='p-2 $class'>";
691 691
 
692
-										switch( $key ) {
692
+                                        switch( $key ) {
693 693
 
694
-											case 'item_name':
695
-												echo sanitize_text_field( $subscription_group_fee['name'] );
696
-												break;
694
+                                            case 'item_name':
695
+                                                echo sanitize_text_field( $subscription_group_fee['name'] );
696
+                                                break;
697 697
 
698
-											case 'price':
699
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
700
-												break;
698
+                                            case 'price':
699
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
700
+                                                break;
701 701
 
702
-											case 'tax':
703
-												echo "&mdash;";
704
-												break;
702
+                                            case 'tax':
703
+                                                echo "&mdash;";
704
+                                                break;
705 705
 
706
-											case 'discount':
707
-												echo "&mdash;";
708
-												break;
706
+                                            case 'discount':
707
+                                                echo "&mdash;";
708
+                                                break;
709 709
 
710
-											case 'initial':
711
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
712
-												break;
710
+                                            case 'initial':
711
+                                                echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
712
+                                                break;
713 713
 
714
-											case 'recurring':
715
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
716
-												break;
714
+                                            case 'recurring':
715
+                                                echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
716
+                                                break;
717 717
 
718
-										}
718
+                                        }
719 719
 
720
-									echo '</td>';
720
+                                    echo '</td>';
721 721
 
722
-								}
722
+                                }
723 723
 
724
-							echo '</tr>';
724
+                            echo '</tr>';
725 725
 
726
-						endforeach;
727
-					?>
726
+                        endforeach;
727
+                    ?>
728 728
 
729 729
 				</tbody>
730 730
 
@@ -743,38 +743,38 @@  discard block
 block discarded – undo
743 743
  */
744 744
 function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
745 745
 
746
-	// Fetch the subscription groups.
747
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
748
-
749
-	if ( empty( $subscription_groups ) ) {
750
-		return;
751
-	}
752
-
753
-	// Prepare table columns.
754
-	$columns = apply_filters(
755
-		'getpaid_subscription_related_subscriptions_columns',
756
-		array(
757
-			'subscription'      => __( 'Subscription', 'invoicing' ),
758
-			'start_date'        => __( 'Start Date', 'invoicing' ),
759
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
760
-			'renewals'          => __( 'Payments', 'invoicing' ),
761
-			'item'              => __( 'Items', 'invoicing' ),
762
-			'status'            => __( 'Status', 'invoicing' ),
763
-		),
764
-		$subscription
765
-	);
766
-
767
-	if ( $subscription->get_status() == 'pending' ) {
768
-		unset( $columns['start_date'], $columns['renewal_date'] );
769
-	}
770
-
771
-	$table_class = 'w-100 bg-white';
772
-
773
-	if ( ! is_admin() ) {
774
-		$table_class = 'table table-bordered';
775
-	}
776
-
777
-	?>
746
+    // Fetch the subscription groups.
747
+    $subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
748
+
749
+    if ( empty( $subscription_groups ) ) {
750
+        return;
751
+    }
752
+
753
+    // Prepare table columns.
754
+    $columns = apply_filters(
755
+        'getpaid_subscription_related_subscriptions_columns',
756
+        array(
757
+            'subscription'      => __( 'Subscription', 'invoicing' ),
758
+            'start_date'        => __( 'Start Date', 'invoicing' ),
759
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
760
+            'renewals'          => __( 'Payments', 'invoicing' ),
761
+            'item'              => __( 'Items', 'invoicing' ),
762
+            'status'            => __( 'Status', 'invoicing' ),
763
+        ),
764
+        $subscription
765
+    );
766
+
767
+    if ( $subscription->get_status() == 'pending' ) {
768
+        unset( $columns['start_date'], $columns['renewal_date'] );
769
+    }
770
+
771
+    $table_class = 'w-100 bg-white';
772
+
773
+    if ( ! is_admin() ) {
774
+        $table_class = 'table table-bordered';
775
+    }
776
+
777
+    ?>
778 778
 		<div class="m-0" style="overflow: auto;">
779 779
 
780 780
 			<table class="<?php echo $table_class; ?>">
@@ -783,14 +783,14 @@  discard block
 block discarded – undo
783 783
 					<tr>
784 784
 						<?php
785 785
 
786
-							foreach ( $columns as $key => $label ) {
787
-								$key   = esc_attr( $key );
788
-								$label = sanitize_text_field( $label );
789
-								$class = 'text-left';
786
+                            foreach ( $columns as $key => $label ) {
787
+                                $key   = esc_attr( $key );
788
+                                $label = sanitize_text_field( $label );
789
+                                $class = 'text-left';
790 790
 
791
-								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
792
-							}
793
-						?>
791
+                                echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
792
+                            }
793
+                        ?>
794 794
 					</tr>
795 795
 				</thead>
796 796
 
@@ -798,74 +798,74 @@  discard block
 block discarded – undo
798 798
 
799 799
 					<?php
800 800
 
801
-						foreach( $subscription_groups as $subscription_group ) :
801
+                        foreach( $subscription_groups as $subscription_group ) :
802 802
 
803
-							// Do not list current subscription.
804
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
805
-								continue;
806
-							}
803
+                            // Do not list current subscription.
804
+                            if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
805
+                                continue;
806
+                            }
807 807
 
808
-							// Ensure the subscription exists.
809
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
808
+                            // Ensure the subscription exists.
809
+                            $_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
810 810
 
811
-							if ( ! $_suscription->exists() ) {
812
-								continue;
813
-							}
811
+                            if ( ! $_suscription->exists() ) {
812
+                                continue;
813
+                            }
814 814
 
815
-							echo '<tr>';
815
+                            echo '<tr>';
816 816
 
817
-								foreach ( array_keys( $columns ) as $key ) {
817
+                                foreach ( array_keys( $columns ) as $key ) {
818 818
 
819
-									$class = 'text-left';
819
+                                    $class = 'text-left';
820 820
 
821
-									echo "<td class='p-2 $class'>";
821
+                                    echo "<td class='p-2 $class'>";
822 822
 
823
-										switch( $key ) {
823
+                                        switch( $key ) {
824 824
 
825
-											case 'status':
826
-												echo $_suscription->get_status_label_html();
827
-												break;
825
+                                            case 'status':
826
+                                                echo $_suscription->get_status_label_html();
827
+                                                break;
828 828
 
829
-											case 'item':
830
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
831
-												echo implode( ' | ', $markup );
832
-												break;
829
+                                            case 'item':
830
+                                                $markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
831
+                                                echo implode( ' | ', $markup );
832
+                                                break;
833 833
 
834
-											case 'renewals':
835
-												$max_bills = $_suscription->get_bill_times();
836
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
837
-												break;
834
+                                            case 'renewals':
835
+                                                $max_bills = $_suscription->get_bill_times();
836
+                                                echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
837
+                                                break;
838 838
 
839
-											case 'renewal_date':
840
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
841
-												break;
839
+                                            case 'renewal_date':
840
+                                                echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
841
+                                                break;
842 842
 
843
-											case 'start_date':
844
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
845
-												break;
843
+                                            case 'start_date':
844
+                                                echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
845
+                                                break;
846 846
 
847
-											case 'subscription':
848
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
849
-												printf(
850
-													'%1$s#%2$s%3$s',
851
-													'<a href="' . esc_url( $url ) . '">',
852
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
853
-													'</a>'
854
-												);
847
+                                            case 'subscription':
848
+                                                $url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
849
+                                                printf(
850
+                                                    '%1$s#%2$s%3$s',
851
+                                                    '<a href="' . esc_url( $url ) . '">',
852
+                                                    '<strong>' . intval( $_suscription->get_id() ) . '</strong>',
853
+                                                    '</a>'
854
+                                                );
855 855
 
856
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
857
-												break;
856
+                                                echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
857
+                                                break;
858 858
 
859
-										}
859
+                                        }
860 860
 
861
-									echo '</td>';
861
+                                    echo '</td>';
862 862
 
863
-								}
863
+                                }
864 864
 
865
-							echo '</tr>';
865
+                            echo '</tr>';
866 866
 
867
-						endforeach;
868
-					?>
867
+                        endforeach;
868
+                    ?>
869 869
 
870 870
 				</tbody>
871 871
 
Please login to merge, or discard this patch.
Spacing   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains functions that display the subscriptions admin page.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Render the Subscriptions page
@@ -17,22 +17,22 @@  discard block
 block discarded – undo
17 17
 	?>
18 18
 
19 19
 	<div class="wrap">
20
-		<h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
20
+		<h1><?php echo esc_html(get_admin_page_title()); ?></h1>
21 21
 		<div class="bsui">
22 22
 
23 23
 			<?php
24 24
 
25 25
 				// Verify user permissions.
26
-				if ( ! wpinv_current_user_can_manage_invoicing() ) {
26
+				if (!wpinv_current_user_can_manage_invoicing()) {
27 27
 
28 28
 					echo aui()->alert(
29 29
 						array(
30 30
 							'type'    => 'danger',
31
-							'content' => __( 'You are not permitted to view this page.', 'invoicing' ),
31
+							'content' => __('You are not permitted to view this page.', 'invoicing'),
32 32
 						)
33 33
 					);
34 34
 
35
-				} else if ( ! empty( $_GET['id'] ) && is_numeric( $_GET['id'] ) ) {
35
+				} else if (!empty($_GET['id']) && is_numeric($_GET['id'])) {
36 36
 
37 37
 					// Display a single subscription.
38 38
 					wpinv_recurring_subscription_details();
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 function wpinv_recurring_subscription_details() {
82 82
 
83 83
 	// Fetch the subscription.
84
-	$sub = new WPInv_Subscription( (int) $_GET['id'] );
85
-	if ( ! $sub->exists() ) {
84
+	$sub = new WPInv_Subscription((int) $_GET['id']);
85
+	if (!$sub->exists()) {
86 86
 
87 87
 		echo aui()->alert(
88 88
 			array(
89 89
 				'type'    => 'danger',
90
-				'content' => __( 'Subscription not found.', 'invoicing' ),
90
+				'content' => __('Subscription not found.', 'invoicing'),
91 91
 			)
92 92
 		);
93 93
 
@@ -95,45 +95,45 @@  discard block
 block discarded – undo
95 95
 	}
96 96
 
97 97
 	// Use metaboxes to display the subscription details.
98
-	add_meta_box( 'getpaid_admin_subscription_details_metabox', __( 'Subscription Details', 'invoicing' ), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
98
+	add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal', 'high');
99
+	add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side');
100 100
 
101 101
 	$subscription_id     = $sub->get_id();
102
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $sub->get_parent_invoice_id() );
103
-	$subscription_group  = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
102
+	$subscription_groups = getpaid_get_invoice_subscription_groups($sub->get_parent_invoice_id());
103
+	$subscription_group  = wp_list_filter($subscription_groups, compact('subscription_id'));
104 104
 
105
-	if ( 1 < count( $subscription_groups ) ) {
106
-		add_meta_box( 'getpaid_admin_subscription_related_subscriptions_metabox', __( 'Related Subscriptions', 'invoicing' ), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced' );
105
+	if (1 < count($subscription_groups)) {
106
+		add_meta_box('getpaid_admin_subscription_related_subscriptions_metabox', __('Related Subscriptions', 'invoicing'), 'getpaid_admin_subscription_related_subscriptions_metabox', get_current_screen(), 'advanced');
107 107
 	}
108 108
 
109
-	if ( ! empty( $subscription_group ) ) {
110
-		add_meta_box( 'getpaid_admin_subscription_item_details_metabox', __( 'Subscription Items', 'invoicing' ), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low' );
109
+	if (!empty($subscription_group)) {
110
+		add_meta_box('getpaid_admin_subscription_item_details_metabox', __('Subscription Items', 'invoicing'), 'getpaid_admin_subscription_item_details_metabox', get_current_screen(), 'normal', 'low');
111 111
 	}
112 112
 
113
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Related Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
113
+	add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Related Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced');
114 114
 
115
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
115
+	do_action('getpaid_admin_single_subscription_register_metabox', $sub);
116 116
 
117 117
 	?>
118 118
 
119
-		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
119
+		<form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>">
120 120
 
121
-			<?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?>
122
-			<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
123
-			<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
121
+			<?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?>
122
+			<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
123
+			<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
124 124
 			<input type="hidden" name="getpaid-admin-action" value="update_single_subscription" />
125
-			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" />
125
+			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" />
126 126
 
127 127
 			<div id="poststuff">
128 128
 				<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
129 129
 
130 130
 					<div id="postbox-container-1" class="postbox-container">
131
-						<?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?>
131
+						<?php do_meta_boxes(get_current_screen(), 'side', $sub); ?>
132 132
 					</div>
133 133
 
134 134
 					<div id="postbox-container-2" class="postbox-container">
135
-						<?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?>
136
-						<?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?>
135
+						<?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?>
136
+						<?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?>
137 137
 					</div>
138 138
 
139 139
 				</div>
@@ -152,44 +152,44 @@  discard block
 block discarded – undo
152 152
  *
153 153
  * @param WPInv_Subscription $sub
154 154
  */
155
-function getpaid_admin_subscription_details_metabox( $sub ) {
155
+function getpaid_admin_subscription_details_metabox($sub) {
156 156
 
157 157
 	// Subscription items.
158
-	$subscription_group = getpaid_get_invoice_subscription_group( $sub->get_parent_invoice_id(), $sub->get_id() );
159
-	$items_count        = empty( $subscription_group ) ? 1 : count( $subscription_group['items'] );
158
+	$subscription_group = getpaid_get_invoice_subscription_group($sub->get_parent_invoice_id(), $sub->get_id());
159
+	$items_count        = empty($subscription_group) ? 1 : count($subscription_group['items']);
160 160
 
161 161
 	// Prepare subscription detail columns.
162 162
 	$fields = apply_filters(
163 163
 		'getpaid_subscription_admin_page_fields',
164 164
 		array(
165
-			'subscription'   => __( 'Subscription', 'invoicing' ),
166
-			'customer'       => __( 'Customer', 'invoicing' ),
167
-			'amount'         => __( 'Amount', 'invoicing' ),
168
-			'start_date'     => __( 'Start Date', 'invoicing' ),
169
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
170
-			'renewals'       => __( 'Payments', 'invoicing' ),
171
-			'item'           => _n( 'Item', 'Items', $items_count,  'invoicing' ),
172
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
173
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
174
-			'status'         => __( 'Status', 'invoicing' ),
165
+			'subscription'   => __('Subscription', 'invoicing'),
166
+			'customer'       => __('Customer', 'invoicing'),
167
+			'amount'         => __('Amount', 'invoicing'),
168
+			'start_date'     => __('Start Date', 'invoicing'),
169
+			'renews_on'      => __('Next Payment', 'invoicing'),
170
+			'renewals'       => __('Payments', 'invoicing'),
171
+			'item'           => _n('Item', 'Items', $items_count, 'invoicing'),
172
+			'gateway'        => __('Payment Method', 'invoicing'),
173
+			'profile_id'     => __('Profile ID', 'invoicing'),
174
+			'status'         => __('Status', 'invoicing'),
175 175
 		)
176 176
 	);
177 177
 
178
-	if ( ! $sub->is_active() ) {
178
+	if (!$sub->is_active()) {
179 179
 
180
-		if ( isset( $fields['renews_on'] ) ) {
181
-			unset( $fields['renews_on'] );
180
+		if (isset($fields['renews_on'])) {
181
+			unset($fields['renews_on']);
182 182
 		}
183 183
 
184
-		if ( isset( $fields['gateway'] ) ) {
185
-			unset( $fields['gateway'] );
184
+		if (isset($fields['gateway'])) {
185
+			unset($fields['gateway']);
186 186
 		}
187 187
 
188 188
 	}
189 189
 
190 190
 	$profile_id = $sub->get_profile_id();
191
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
192
-		unset( $fields['profile_id'] );
191
+	if (empty($profile_id) && isset($fields['profile_id'])) {
192
+		unset($fields['profile_id']);
193 193
 	}
194 194
 
195 195
 	?>
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
 		<table class="table table-borderless" style="font-size: 14px;">
198 198
 			<tbody>
199 199
 
200
-				<?php foreach ( $fields as $key => $label ) : ?>
200
+				<?php foreach ($fields as $key => $label) : ?>
201 201
 
202
-					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>">
202
+					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>">
203 203
 
204 204
 						<th class="w-25" style="font-weight: 500;">
205
-							<?php echo sanitize_text_field( $label ); ?>
205
+							<?php echo sanitize_text_field($label); ?>
206 206
 						</th>
207 207
 
208 208
 						<td class="w-75 text-muted">
209
-							<?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub, $subscription_group ); ?>
209
+							<?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub, $subscription_group); ?>
210 210
 						</td>
211 211
 
212 212
 					</tr>
@@ -224,129 +224,129 @@  discard block
 block discarded – undo
224 224
  *
225 225
  * @param WPInv_Subscription $subscription
226 226
  */
227
-function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
227
+function getpaid_admin_subscription_metabox_display_customer($subscription) {
228 228
 
229
-	$username = __( '(Missing User)', 'invoicing' );
229
+	$username = __('(Missing User)', 'invoicing');
230 230
 
231
-	$user = get_userdata( $subscription->get_customer_id() );
232
-	if ( $user ) {
231
+	$user = get_userdata($subscription->get_customer_id());
232
+	if ($user) {
233 233
 
234 234
 		$username = sprintf(
235 235
 			'<a href="user-edit.php?user_id=%s">%s</a>',
236
-			absint( $user->ID ),
237
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
236
+			absint($user->ID),
237
+			!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
238 238
 		);
239 239
 
240 240
 	}
241 241
 
242 242
 	echo  $username;
243 243
 }
244
-add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
244
+add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer');
245 245
 
246 246
 /**
247 247
  * Displays the subscription amount.
248 248
  *
249 249
  * @param WPInv_Subscription $subscription
250 250
  */
251
-function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
252
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
251
+function getpaid_admin_subscription_metabox_display_amount($subscription) {
252
+	$amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription));
253 253
 	echo "<span>$amount</span>";
254 254
 }
255
-add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
255
+add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount');
256 256
 
257 257
 /**
258 258
  * Displays the subscription id.
259 259
  *
260 260
  * @param WPInv_Subscription $subscription
261 261
  */
262
-function getpaid_admin_subscription_metabox_display_id( $subscription ) {
263
-	echo  '#' . absint( $subscription->get_id() );
262
+function getpaid_admin_subscription_metabox_display_id($subscription) {
263
+	echo  '#' . absint($subscription->get_id());
264 264
 }
265
-add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
265
+add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id');
266 266
 
267 267
 /**
268 268
  * Displays the subscription renewal date.
269 269
  *
270 270
  * @param WPInv_Subscription $subscription
271 271
  */
272
-function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
273
-	echo getpaid_format_date_value( $subscription->get_date_created() );
272
+function getpaid_admin_subscription_metabox_display_start_date($subscription) {
273
+	echo getpaid_format_date_value($subscription->get_date_created());
274 274
 }
275
-add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
275
+add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date');
276 276
 
277 277
 /**
278 278
  * Displays the subscription renewal date.
279 279
  *
280 280
  * @param WPInv_Subscription $subscription
281 281
  */
282
-function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
283
-	echo getpaid_format_date_value( $subscription->get_expiration() );
282
+function getpaid_admin_subscription_metabox_display_renews_on($subscription) {
283
+	echo getpaid_format_date_value($subscription->get_expiration());
284 284
 }
285
-add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
285
+add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on');
286 286
 
287 287
 /**
288 288
  * Displays the subscription renewal count.
289 289
  *
290 290
  * @param WPInv_Subscription $subscription
291 291
  */
292
-function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
292
+function getpaid_admin_subscription_metabox_display_renewals($subscription) {
293 293
 	$max_bills = $subscription->get_bill_times();
294
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
294
+	echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
295 295
 }
296
-add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
296
+add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals');
297 297
 /**
298 298
  * Displays the subscription item.
299 299
  *
300 300
  * @param WPInv_Subscription $subscription
301 301
  * @param false|array $subscription_group
302 302
  */
303
-function getpaid_admin_subscription_metabox_display_item( $subscription, $subscription_group = false ) {
303
+function getpaid_admin_subscription_metabox_display_item($subscription, $subscription_group = false) {
304 304
 
305
-	if ( empty( $subscription_group ) ) {
306
-		echo WPInv_Subscriptions_List_Table::generate_item_markup( $subscription->get_product_id() );
305
+	if (empty($subscription_group)) {
306
+		echo WPInv_Subscriptions_List_Table::generate_item_markup($subscription->get_product_id());
307 307
 		return;
308 308
 	}
309 309
 
310
-	$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
311
-	echo implode( ' | ', $markup );
310
+	$markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items']));
311
+	echo implode(' | ', $markup);
312 312
 
313 313
 }
314
-add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2 );
314
+add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item', 10, 2);
315 315
 
316 316
 /**
317 317
  * Displays the subscription gateway.
318 318
  *
319 319
  * @param WPInv_Subscription $subscription
320 320
  */
321
-function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
321
+function getpaid_admin_subscription_metabox_display_gateway($subscription) {
322 322
 
323 323
 	$gateway = $subscription->get_gateway();
324 324
 
325
-	if ( ! empty( $gateway ) ) {
326
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
325
+	if (!empty($gateway)) {
326
+		echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway));
327 327
 	} else {
328 328
 		echo "&mdash;";
329 329
 	}
330 330
 
331 331
 }
332
-add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
332
+add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway');
333 333
 
334 334
 /**
335 335
  * Displays the subscription status.
336 336
  *
337 337
  * @param WPInv_Subscription $subscription
338 338
  */
339
-function getpaid_admin_subscription_metabox_display_status( $subscription ) {
339
+function getpaid_admin_subscription_metabox_display_status($subscription) {
340 340
 	echo $subscription->get_status_label_html();
341 341
 }
342
-add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
342
+add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status');
343 343
 
344 344
 /**
345 345
  * Displays the subscription profile id.
346 346
  *
347 347
  * @param WPInv_Subscription $subscription
348 348
  */
349
-function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
349
+function getpaid_admin_subscription_metabox_display_profile_id($subscription) {
350 350
 
351 351
 	$profile_id = $subscription->get_profile_id();
352 352
 
@@ -355,32 +355,32 @@  discard block
 block discarded – undo
355 355
 			'type'        => 'text',
356 356
 			'id'          => 'wpinv_subscription_profile_id',
357 357
 			'name'        => 'wpinv_subscription_profile_id',
358
-			'label'       => __( 'Profile Id', 'invoicing' ),
358
+			'label'       => __('Profile Id', 'invoicing'),
359 359
 			'label_type'  => 'hidden',
360
-			'placeholder' => __( 'Profile Id', 'invoicing' ),
361
-			'value'       => sanitize_text_field( $profile_id ),
360
+			'placeholder' => __('Profile Id', 'invoicing'),
361
+			'value'       => sanitize_text_field($profile_id),
362 362
 			'input_group_right' => '',
363 363
 			'no_wrap'     => true,
364 364
 		)
365 365
 	);
366 366
 
367
-	echo str_ireplace( 'form-control', 'regular-text', $input );
367
+	echo str_ireplace('form-control', 'regular-text', $input);
368 368
 
369
-	$url = apply_filters( 'getpaid_remote_subscription_profile_url', '', $subscription );
370
-	if ( ! empty( $url ) ) {
371
-		$url = esc_url_raw( $url );
372
-		echo '&nbsp;<a href="' . $url . '" title="' . __( 'View in Gateway', 'invoicing' ) . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
369
+	$url = apply_filters('getpaid_remote_subscription_profile_url', '', $subscription);
370
+	if (!empty($url)) {
371
+		$url = esc_url_raw($url);
372
+		echo '&nbsp;<a href="' . $url . '" title="' . __('View in Gateway', 'invoicing') . '" target="_blank"><i class="fas fa-external-link-alt fa-xs fa-fw align-top"></i></a>';
373 373
 	}
374 374
 
375 375
 }
376
-add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
376
+add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id');
377 377
 
378 378
 /**
379 379
  * Displays the subscriptions update metabox.
380 380
  *
381 381
  * @param WPInv_Subscription $subscription
382 382
  */
383
-function getpaid_admin_subscription_update_metabox( $subscription ) {
383
+function getpaid_admin_subscription_update_metabox($subscription) {
384 384
 
385 385
 	?>
386 386
 	<div class="mt-3">
@@ -393,10 +393,10 @@  discard block
 block discarded – undo
393 393
 					'id'               => 'subscription_status_update_select',
394 394
 					'required'         => true,
395 395
 					'no_wrap'          => false,
396
-					'label'            => __( 'Subscription Status', 'invoicing' ),
397
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
396
+					'label'            => __('Subscription Status', 'invoicing'),
397
+					'help_text'        => __('Updating the status will trigger related actions and hooks', 'invoicing'),
398 398
 					'select2'          => true,
399
-					'value'            => $subscription->get_status( 'edit' ),
399
+					'value'            => $subscription->get_status('edit'),
400 400
 				)
401 401
 			);
402 402
 		?>
@@ -404,13 +404,13 @@  discard block
 block discarded – undo
404 404
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
405 405
 
406 406
 		<?php
407
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
407
+			submit_button(__('Update', 'invoicing'), 'primary', 'submit', false);
408 408
 
409
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
410
-			$anchor = __( 'Renew Subscription', 'invoicing' );
411
-			$title  = esc_attr__( 'Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing' );
409
+			$url    = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce'));
410
+			$anchor = __('Renew Subscription', 'invoicing');
411
+			$title  = esc_attr__('Are you sure you want to extend the subscription and generate a new invoice that will be automatically marked as paid?', 'invoicing');
412 412
 
413
-			if ( $subscription->is_active() ) {
413
+			if ($subscription->is_active()) {
414 414
 				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
415 415
 			}
416 416
 
@@ -423,31 +423,31 @@  discard block
 block discarded – undo
423 423
  * @param WPInv_Subscription $subscription
424 424
  * @param bool $strict Whether or not to skip invoices of sibling subscriptions
425 425
  */
426
-function getpaid_admin_subscription_invoice_details_metabox( $subscription, $strict = true ) {
426
+function getpaid_admin_subscription_invoice_details_metabox($subscription, $strict = true) {
427 427
 
428 428
 	$columns = apply_filters(
429 429
 		'getpaid_subscription_related_invoices_columns',
430 430
 		array(
431
-			'invoice'      => __( 'Invoice', 'invoicing' ),
432
-			'relationship' => __( 'Relationship', 'invoicing' ),
433
-			'date'         => __( 'Date', 'invoicing' ),
434
-			'status'       => __( 'Status', 'invoicing' ),
435
-			'total'        => __( 'Total', 'invoicing' ),
431
+			'invoice'      => __('Invoice', 'invoicing'),
432
+			'relationship' => __('Relationship', 'invoicing'),
433
+			'date'         => __('Date', 'invoicing'),
434
+			'status'       => __('Status', 'invoicing'),
435
+			'total'        => __('Total', 'invoicing'),
436 436
 		),
437 437
 		$subscription
438 438
 	);
439 439
 
440 440
 	// Prepare the invoices.
441
-	$payments = $subscription->get_child_payments( ! is_admin() );
441
+	$payments = $subscription->get_child_payments(!is_admin());
442 442
 	$parent   = $subscription->get_parent_invoice();
443 443
 
444
-	if ( $parent->exists() ) {
445
-		$payments = array_merge( array( $parent ), $payments );
444
+	if ($parent->exists()) {
445
+		$payments = array_merge(array($parent), $payments);
446 446
 	}
447 447
 
448 448
 	$table_class = 'w-100 bg-white';
449 449
 
450
-	if ( ! is_admin() ) {
450
+	if (!is_admin()) {
451 451
 		$table_class = 'table table-bordered';
452 452
 	}
453 453
 
@@ -459,9 +459,9 @@  discard block
 block discarded – undo
459 459
 				<thead>
460 460
 					<tr>
461 461
 						<?php
462
-							foreach ( $columns as $key => $label ) {
463
-								$key   = esc_attr( $key );
464
-								$label = sanitize_text_field( $label );
462
+							foreach ($columns as $key => $label) {
463
+								$key   = esc_attr($key);
464
+								$label = sanitize_text_field($label);
465 465
 								$class = 'text-left';
466 466
 
467 467
 								echo "<th class='subscription-invoice-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -472,57 +472,57 @@  discard block
 block discarded – undo
472 472
 
473 473
 				<tbody>
474 474
 
475
-					<?php if ( empty( $payments ) ) : ?>
475
+					<?php if (empty($payments)) : ?>
476 476
 						<tr>
477 477
 							<td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted">
478
-								<?php _e( 'This subscription has no invoices.', 'invoicing' ); ?>
478
+								<?php _e('This subscription has no invoices.', 'invoicing'); ?>
479 479
 							</td>
480 480
 						</tr>
481 481
 					<?php endif; ?>
482 482
 
483 483
 					<?php
484 484
 
485
-						foreach( $payments as $payment ) :
485
+						foreach ($payments as $payment) :
486 486
 
487 487
 							// Ensure that we have an invoice.
488
-							$payment = new WPInv_Invoice( $payment );
488
+							$payment = new WPInv_Invoice($payment);
489 489
 
490 490
 							// Abort if the invoice is invalid...
491
-							if ( ! $payment->exists() ) {
491
+							if (!$payment->exists()) {
492 492
 								continue;
493 493
 							}
494 494
 
495 495
 							// ... or belongs to a different subscription.
496
-							if ( $strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id() ) {
496
+							if ($strict && $payment->is_renewal() && $payment->get_subscription_id() && $payment->get_subscription_id() != $subscription->get_id()) {
497 497
 								continue;
498 498
 							}
499 499
 
500 500
 							echo '<tr>';
501 501
 
502
-								foreach ( array_keys( $columns ) as $key ) {
502
+								foreach (array_keys($columns) as $key) {
503 503
 
504 504
 									$class = 'text-left';
505 505
 
506 506
 									echo "<td class='p-2 $class'>";
507 507
 
508
-										switch( $key ) {
508
+										switch ($key) {
509 509
 
510 510
 											case 'total':
511
-												echo '<strong>' . wpinv_price( $payment->get_total(), $payment->get_currency() ) . '</strong>';
511
+												echo '<strong>' . wpinv_price($payment->get_total(), $payment->get_currency()) . '</strong>';
512 512
 												break;
513 513
 
514 514
 											case 'relationship':
515
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
515
+												echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing');
516 516
 												break;
517 517
 
518 518
 											case 'date':
519
-												echo getpaid_format_date_value( $payment->get_date_created() );
519
+												echo getpaid_format_date_value($payment->get_date_created());
520 520
 												break;
521 521
 
522 522
 											case 'status':
523 523
 
524 524
 												$status = $payment->get_status_nicename();
525
-												if ( is_admin() ) {
525
+												if (is_admin()) {
526 526
 													$status = $payment->get_status_label_html();
527 527
 												}
528 528
 
@@ -530,13 +530,13 @@  discard block
 block discarded – undo
530 530
 												break;
531 531
 
532 532
 											case 'invoice':
533
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
533
+												$link = esc_url(get_edit_post_link($payment->get_id()));
534 534
 
535
-												if ( ! is_admin() ) {
536
-													$link = esc_url( $payment->get_view_url() );
535
+												if (!is_admin()) {
536
+													$link = esc_url($payment->get_view_url());
537 537
 												}
538 538
 
539
-												$invoice = sanitize_text_field( $payment->get_number() );
539
+												$invoice = sanitize_text_field($payment->get_number());
540 540
 												echo "<a href='$link'>$invoice</a>";
541 541
 												break;
542 542
 										}
@@ -564,12 +564,12 @@  discard block
 block discarded – undo
564 564
  *
565 565
  * @param WPInv_Subscription $subscription
566 566
  */
567
-function getpaid_admin_subscription_item_details_metabox( $subscription ) {
567
+function getpaid_admin_subscription_item_details_metabox($subscription) {
568 568
 
569 569
 	// Fetch the subscription group.
570
-	$subscription_group = getpaid_get_invoice_subscription_group( $subscription->get_parent_payment_id(), $subscription->get_id() );
570
+	$subscription_group = getpaid_get_invoice_subscription_group($subscription->get_parent_payment_id(), $subscription->get_id());
571 571
 
572
-	if ( empty( $subscription_group ) || empty( $subscription_group['items'] ) ) {
572
+	if (empty($subscription_group) || empty($subscription_group['items'])) {
573 573
 		return;
574 574
 	}
575 575
 
@@ -577,12 +577,12 @@  discard block
 block discarded – undo
577 577
 	$columns = apply_filters(
578 578
 		'getpaid_subscription_item_details_columns',
579 579
 		array(
580
-			'item_name'    => __( 'Item', 'invoicing' ),
581
-			'price'        => __( 'Price', 'invoicing' ),
582
-			'tax'          => __( 'Tax', 'invoicing' ),
583
-			'discount'     => __( 'Discount', 'invoicing' ),
580
+			'item_name'    => __('Item', 'invoicing'),
581
+			'price'        => __('Price', 'invoicing'),
582
+			'tax'          => __('Tax', 'invoicing'),
583
+			'discount'     => __('Discount', 'invoicing'),
584 584
 			//'initial'      => __( 'Initial Amount', 'invoicing' ),
585
-			'recurring'    => __( 'Subtotal', 'invoicing' ),
585
+			'recurring'    => __('Subtotal', 'invoicing'),
586 586
 		),
587 587
 		$subscription
588 588
 	);
@@ -591,13 +591,13 @@  discard block
 block discarded – undo
591 591
 
592 592
 	$invoice = $subscription->get_parent_invoice();
593 593
 
594
-	if ( ( ! wpinv_use_taxes() || ! $invoice->is_taxable() ) && isset( $columns['tax'] ) ) {
595
-		unset( $columns['tax'] );
594
+	if ((!wpinv_use_taxes() || !$invoice->is_taxable()) && isset($columns['tax'])) {
595
+		unset($columns['tax']);
596 596
 	}
597 597
 
598 598
 	$table_class = 'w-100 bg-white';
599 599
 
600
-	if ( ! is_admin() ) {
600
+	if (!is_admin()) {
601 601
 		$table_class = 'table table-bordered';
602 602
 	}
603 603
 
@@ -610,9 +610,9 @@  discard block
 block discarded – undo
610 610
 					<tr>
611 611
 						<?php
612 612
 
613
-							foreach ( $columns as $key => $label ) {
614
-								$key   = esc_attr( $key );
615
-								$label = sanitize_text_field( $label );
613
+							foreach ($columns as $key => $label) {
614
+								$key   = esc_attr($key);
615
+								$label = sanitize_text_field($label);
616 616
 								$class = 'text-left';
617 617
 
618 618
 								echo "<th class='subscription-item-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -625,48 +625,48 @@  discard block
 block discarded – undo
625 625
 
626 626
 					<?php
627 627
 
628
-						foreach( $subscription_group['items'] as $subscription_group_item ) :
628
+						foreach ($subscription_group['items'] as $subscription_group_item) :
629 629
 
630 630
 							echo '<tr>';
631 631
 
632
-								foreach ( array_keys( $columns ) as $key ) {
632
+								foreach (array_keys($columns) as $key) {
633 633
 
634 634
 									$class = 'text-left';
635 635
 
636 636
 									echo "<td class='p-2 $class'>";
637 637
 
638
-										switch( $key ) {
638
+										switch ($key) {
639 639
 
640 640
 											case 'item_name':
641
-												$item_name = get_the_title( $subscription_group_item['item_id'] );
642
-												$item_name = empty( $item_name ) ? $subscription_group_item['item_name'] : $item_name;
641
+												$item_name = get_the_title($subscription_group_item['item_id']);
642
+												$item_name = empty($item_name) ? $subscription_group_item['item_name'] : $item_name;
643 643
 
644
-												if ( $invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity'] ) {
645
-													echo sanitize_text_field( $item_name );
644
+												if ($invoice->get_template() == 'amount' || 1 == (float) $subscription_group_item['quantity']) {
645
+													echo sanitize_text_field($item_name);
646 646
 												} else {
647
-													printf( '%1$s x %2$d', sanitize_text_field( $item_name ), (float) $subscription_group_item['quantity'] );
647
+													printf('%1$s x %2$d', sanitize_text_field($item_name), (float) $subscription_group_item['quantity']);
648 648
 												}
649 649
 
650 650
 												break;
651 651
 
652 652
 											case 'price':
653
-												echo wpinv_price( $subscription_group_item['item_price'], $invoice->get_currency() );
653
+												echo wpinv_price($subscription_group_item['item_price'], $invoice->get_currency());
654 654
 												break;
655 655
 
656 656
 											case 'tax':
657
-												echo wpinv_price( $subscription_group_item['tax'], $invoice->get_currency() );
657
+												echo wpinv_price($subscription_group_item['tax'], $invoice->get_currency());
658 658
 												break;
659 659
 
660 660
 											case 'discount':
661
-												echo wpinv_price( $subscription_group_item['discount'], $invoice->get_currency() );
661
+												echo wpinv_price($subscription_group_item['discount'], $invoice->get_currency());
662 662
 												break;
663 663
 
664 664
 											case 'initial':
665
-												echo wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() );
665
+												echo wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency());
666 666
 												break;
667 667
 
668 668
 											case 'recurring':
669
-												echo '<strong>' . wpinv_price( $subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency() ) . '</strong>';
669
+												echo '<strong>' . wpinv_price($subscription_group_item['price'] * $subscription_group_item['quantity'], $invoice->get_currency()) . '</strong>';
670 670
 												break;
671 671
 
672 672
 										}
@@ -679,24 +679,24 @@  discard block
 block discarded – undo
679 679
 
680 680
 						endforeach;
681 681
 
682
-						foreach( $subscription_group['fees'] as $subscription_group_fee ) :
682
+						foreach ($subscription_group['fees'] as $subscription_group_fee) :
683 683
 
684 684
 							echo '<tr>';
685 685
 
686
-								foreach ( array_keys( $columns ) as $key ) {
686
+								foreach (array_keys($columns) as $key) {
687 687
 
688 688
 									$class = 'text-left';
689 689
 
690 690
 									echo "<td class='p-2 $class'>";
691 691
 
692
-										switch( $key ) {
692
+										switch ($key) {
693 693
 
694 694
 											case 'item_name':
695
-												echo sanitize_text_field( $subscription_group_fee['name'] );
695
+												echo sanitize_text_field($subscription_group_fee['name']);
696 696
 												break;
697 697
 
698 698
 											case 'price':
699
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
699
+												echo wpinv_price($subscription_group_fee['initial_fee'], $invoice->get_currency());
700 700
 												break;
701 701
 
702 702
 											case 'tax':
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
 												break;
709 709
 
710 710
 											case 'initial':
711
-												echo wpinv_price( $subscription_group_fee['initial_fee'], $invoice->get_currency() );
711
+												echo wpinv_price($subscription_group_fee['initial_fee'], $invoice->get_currency());
712 712
 												break;
713 713
 
714 714
 											case 'recurring':
715
-												echo '<strong>' . wpinv_price( $subscription_group_fee['recurring_fee'], $invoice->get_currency() ) . '</strong>';
715
+												echo '<strong>' . wpinv_price($subscription_group_fee['recurring_fee'], $invoice->get_currency()) . '</strong>';
716 716
 												break;
717 717
 
718 718
 										}
@@ -741,12 +741,12 @@  discard block
 block discarded – undo
741 741
  * @param WPInv_Subscription $subscription
742 742
  * @param bool $skip_current
743 743
  */
744
-function getpaid_admin_subscription_related_subscriptions_metabox( $subscription, $skip_current = true ) {
744
+function getpaid_admin_subscription_related_subscriptions_metabox($subscription, $skip_current = true) {
745 745
 
746 746
 	// Fetch the subscription groups.
747
-	$subscription_groups = getpaid_get_invoice_subscription_groups( $subscription->get_parent_payment_id() );
747
+	$subscription_groups = getpaid_get_invoice_subscription_groups($subscription->get_parent_payment_id());
748 748
 
749
-	if ( empty( $subscription_groups ) ) {
749
+	if (empty($subscription_groups)) {
750 750
 		return;
751 751
 	}
752 752
 
@@ -754,23 +754,23 @@  discard block
 block discarded – undo
754 754
 	$columns = apply_filters(
755 755
 		'getpaid_subscription_related_subscriptions_columns',
756 756
 		array(
757
-			'subscription'      => __( 'Subscription', 'invoicing' ),
758
-			'start_date'        => __( 'Start Date', 'invoicing' ),
759
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
760
-			'renewals'          => __( 'Payments', 'invoicing' ),
761
-			'item'              => __( 'Items', 'invoicing' ),
762
-			'status'            => __( 'Status', 'invoicing' ),
757
+			'subscription'      => __('Subscription', 'invoicing'),
758
+			'start_date'        => __('Start Date', 'invoicing'),
759
+			'renewal_date'      => __('Next Payment', 'invoicing'),
760
+			'renewals'          => __('Payments', 'invoicing'),
761
+			'item'              => __('Items', 'invoicing'),
762
+			'status'            => __('Status', 'invoicing'),
763 763
 		),
764 764
 		$subscription
765 765
 	);
766 766
 
767
-	if ( $subscription->get_status() == 'pending' ) {
768
-		unset( $columns['start_date'], $columns['renewal_date'] );
767
+	if ($subscription->get_status() == 'pending') {
768
+		unset($columns['start_date'], $columns['renewal_date']);
769 769
 	}
770 770
 
771 771
 	$table_class = 'w-100 bg-white';
772 772
 
773
-	if ( ! is_admin() ) {
773
+	if (!is_admin()) {
774 774
 		$table_class = 'table table-bordered';
775 775
 	}
776 776
 
@@ -783,9 +783,9 @@  discard block
 block discarded – undo
783 783
 					<tr>
784 784
 						<?php
785 785
 
786
-							foreach ( $columns as $key => $label ) {
787
-								$key   = esc_attr( $key );
788
-								$label = sanitize_text_field( $label );
786
+							foreach ($columns as $key => $label) {
787
+								$key   = esc_attr($key);
788
+								$label = sanitize_text_field($label);
789 789
 								$class = 'text-left';
790 790
 
791 791
 								echo "<th class='related-subscription-field-$key bg-light p-2 $class color-dark font-weight-bold'>$label</th>";
@@ -798,62 +798,62 @@  discard block
 block discarded – undo
798 798
 
799 799
 					<?php
800 800
 
801
-						foreach( $subscription_groups as $subscription_group ) :
801
+						foreach ($subscription_groups as $subscription_group) :
802 802
 
803 803
 							// Do not list current subscription.
804
-							if ( $skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id() ) {
804
+							if ($skip_current && (int) $subscription_group['subscription_id'] === $subscription->get_id()) {
805 805
 								continue;
806 806
 							}
807 807
 
808 808
 							// Ensure the subscription exists.
809
-							$_suscription = new WPInv_Subscription( $subscription_group['subscription_id'] );
809
+							$_suscription = new WPInv_Subscription($subscription_group['subscription_id']);
810 810
 
811
-							if ( ! $_suscription->exists() ) {
811
+							if (!$_suscription->exists()) {
812 812
 								continue;
813 813
 							}
814 814
 
815 815
 							echo '<tr>';
816 816
 
817
-								foreach ( array_keys( $columns ) as $key ) {
817
+								foreach (array_keys($columns) as $key) {
818 818
 
819 819
 									$class = 'text-left';
820 820
 
821 821
 									echo "<td class='p-2 $class'>";
822 822
 
823
-										switch( $key ) {
823
+										switch ($key) {
824 824
 
825 825
 											case 'status':
826 826
 												echo $_suscription->get_status_label_html();
827 827
 												break;
828 828
 
829 829
 											case 'item':
830
-												$markup = array_map( array( 'WPInv_Subscriptions_List_Table', 'generate_item_markup' ), array_keys( $subscription_group['items'] ) );
831
-												echo implode( ' | ', $markup );
830
+												$markup = array_map(array('WPInv_Subscriptions_List_Table', 'generate_item_markup'), array_keys($subscription_group['items']));
831
+												echo implode(' | ', $markup);
832 832
 												break;
833 833
 
834 834
 											case 'renewals':
835 835
 												$max_bills = $_suscription->get_bill_times();
836
-												echo $_suscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
836
+												echo $_suscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
837 837
 												break;
838 838
 
839 839
 											case 'renewal_date':
840
-												echo $_suscription->is_active() ? getpaid_format_date_value( $_suscription->get_expiration() ) : "&mdash;";
840
+												echo $_suscription->is_active() ? getpaid_format_date_value($_suscription->get_expiration()) : "&mdash;";
841 841
 												break;
842 842
 
843 843
 											case 'start_date':
844
-												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value( $_suscription->get_date_created() );
844
+												echo 'pending' == $_suscription->get_status() ? "&mdash;" : getpaid_format_date_value($_suscription->get_date_created());
845 845
 												break;
846 846
 
847 847
 											case 'subscription':
848
-												$url = is_admin() ? admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $_suscription->get_id() ) ) : $_suscription->get_view_url();
848
+												$url = is_admin() ? admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($_suscription->get_id())) : $_suscription->get_view_url();
849 849
 												printf(
850 850
 													'%1$s#%2$s%3$s',
851
-													'<a href="' . esc_url( $url ) . '">',
852
-													'<strong>' . intval( $_suscription->get_id() ) . '</strong>',
851
+													'<a href="' . esc_url($url) . '">',
852
+													'<strong>' . intval($_suscription->get_id()) . '</strong>',
853 853
 													'</a>'
854 854
 												);
855 855
 
856
-												echo WPInv_Subscriptions_List_Table::column_amount( $_suscription );
856
+												echo WPInv_Subscriptions_List_Table::column_amount($_suscription);
857 857
 												break;
858 858
 
859 859
 										}
Please login to merge, or discard this patch.
includes/subscription-functions.php 2 patches
Indentation   +307 added lines, -307 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
  */
51 51
 function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52 52
     $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
53
+    $matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54 54
     return reset( $matching_group );
55 55
 }
56 56
 
@@ -63,11 +63,11 @@  discard block
 block discarded – undo
63 63
  */
64 64
 function getpaid_get_subscription( $subscription ) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
68
-	}
66
+    if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
+        $subscription = new WPInv_Subscription( $subscription );
68
+    }
69 69
 
70
-	return $subscription->exists() ? $subscription : false;
70
+    return $subscription->exists() ? $subscription : false;
71 71
 }
72 72
 
73 73
 /**
@@ -81,28 +81,28 @@  discard block
 block discarded – undo
81 81
  */
82 82
 function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
83 83
 
84
-	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
86
-		$args['fields'] = 'id';
87
-		$args['number'] = 1;
88
-	}
84
+    // Do not retrieve all fields if we just want the count.
85
+    if ( 'count' == $return ) {
86
+        $args['fields'] = 'id';
87
+        $args['number'] = 1;
88
+    }
89 89
 
90
-	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
92
-		$args['count_total'] = false;
93
-	}
90
+    // Do not count all matches if we just want the results.
91
+    if ( 'results' == $return ) {
92
+        $args['count_total'] = false;
93
+    }
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+    $query = new GetPaid_Subscriptions_Query( $args );
96 96
 
97
-	if ( 'results' == $return ) {
98
-		return $query->get_results();
99
-	}
97
+    if ( 'results' == $return ) {
98
+        return $query->get_results();
99
+    }
100 100
 
101
-	if ( 'count' == $return ) {
102
-		return $query->get_total();
103
-	}
101
+    if ( 'count' == $return ) {
102
+        return $query->get_total();
103
+    }
104 104
 
105
-	return $query;
105
+    return $query;
106 106
 }
107 107
 
108 108
 /**
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
  */
113 113
 function getpaid_get_subscription_statuses() {
114 114
 
115
-	return apply_filters(
116
-		'getpaid_get_subscription_statuses',
117
-		array(
118
-			'pending'    => __( 'Pending', 'invoicing' ),
119
-			'trialling'  => __( 'Trialing', 'invoicing' ),
120
-			'active'     => __( 'Active', 'invoicing' ),
121
-			'failing'    => __( 'Failing', 'invoicing' ),
122
-			'expired'    => __( 'Expired', 'invoicing' ),
123
-			'completed'  => __( 'Complete', 'invoicing' ),
124
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
125
-		)
126
-	);
115
+    return apply_filters(
116
+        'getpaid_get_subscription_statuses',
117
+        array(
118
+            'pending'    => __( 'Pending', 'invoicing' ),
119
+            'trialling'  => __( 'Trialing', 'invoicing' ),
120
+            'active'     => __( 'Active', 'invoicing' ),
121
+            'failing'    => __( 'Failing', 'invoicing' ),
122
+            'expired'    => __( 'Expired', 'invoicing' ),
123
+            'completed'  => __( 'Complete', 'invoicing' ),
124
+            'cancelled'  => __( 'Cancelled', 'invoicing' ),
125
+        )
126
+    );
127 127
 
128 128
 }
129 129
 
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
  * @return string
134 134
  */
135 135
 function getpaid_get_subscription_status_label( $status ) {
136
-	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
136
+    $statuses = getpaid_get_subscription_statuses();
137
+    return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
138 138
 }
139 139
 
140 140
 /**
@@ -144,18 +144,18 @@  discard block
 block discarded – undo
144 144
  */
145 145
 function getpaid_get_subscription_status_classes() {
146 146
 
147
-	return apply_filters(
148
-		'getpaid_get_subscription_status_classes',
149
-		array(
150
-			'pending'    => 'badge-dark',
151
-			'trialling'  => 'badge-info',
152
-			'active'     => 'badge-success',
153
-			'failing'    => 'badge-warning',
154
-			'expired'    => 'badge-danger',
155
-			'completed'  => 'badge-primary',
156
-			'cancelled'  => 'badge-secondary',
157
-		)
158
-	);
147
+    return apply_filters(
148
+        'getpaid_get_subscription_status_classes',
149
+        array(
150
+            'pending'    => 'badge-dark',
151
+            'trialling'  => 'badge-info',
152
+            'active'     => 'badge-success',
153
+            'failing'    => 'badge-warning',
154
+            'expired'    => 'badge-danger',
155
+            'completed'  => 'badge-primary',
156
+            'cancelled'  => 'badge-secondary',
157
+        )
158
+    );
159 159
 
160 160
 }
161 161
 
@@ -166,15 +166,15 @@  discard block
 block discarded – undo
166 166
  */
167 167
 function getpaid_get_subscription_status_counts( $args = array() ) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
170
-	$counts   = array();
169
+    $statuses = array_keys( getpaid_get_subscription_statuses() );
170
+    $counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
-	}
172
+    foreach ( $statuses as $status ) {
173
+        $_args             = wp_parse_args( "status=$status", $args );
174
+        $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
175
+    }
176 176
 
177
-	return $counts;
177
+    return $counts;
178 178
 
179 179
 }
180 180
 
@@ -185,32 +185,32 @@  discard block
 block discarded – undo
185 185
  */
186 186
 function getpaid_get_subscription_periods() {
187 187
 
188
-	return apply_filters(
189
-		'getpaid_get_subscription_periods',
190
-		array(
188
+    return apply_filters(
189
+        'getpaid_get_subscription_periods',
190
+        array(
191 191
 
192
-			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
195
-			),
192
+            'day'   => array(
193
+                'singular' => __( '%s day', 'invoicing' ),
194
+                'plural'   => __( '%d days', 'invoicing' ),
195
+            ),
196 196
 
197
-			'week'   => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
200
-			),
197
+            'week'   => array(
198
+                'singular' => __( '%s week', 'invoicing' ),
199
+                'plural'   => __( '%d weeks', 'invoicing' ),
200
+            ),
201 201
 
202
-			'month'   => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
205
-			),
202
+            'month'   => array(
203
+                'singular' => __( '%s month', 'invoicing' ),
204
+                'plural'   => __( '%d months', 'invoicing' ),
205
+            ),
206 206
 
207
-			'year'   => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
210
-			),
207
+            'year'   => array(
208
+                'singular' => __( '%s year', 'invoicing' ),
209
+                'plural'   => __( '%d years', 'invoicing' ),
210
+            ),
211 211
 
212
-		)
213
-	);
212
+        )
213
+    );
214 214
 
215 215
 }
216 216
 
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
  * @return int
222 222
  */
223 223
 function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
224
+    return (int) preg_replace( '/[^0-9]/', '', $trial_period );
225 225
 }
226 226
 
227 227
 /**
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
  * @return string
232 232
  */
233 233
 function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
234
+    return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
235 235
 }
236 236
 
237 237
 /**
@@ -242,8 +242,8 @@  discard block
 block discarded – undo
242 242
  * @return string
243 243
  */
244 244
 function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
245
+    $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
+    return strtolower( sanitize_text_field( $label ) );
247 247
 }
248 248
 
249 249
 /**
@@ -254,22 +254,22 @@  discard block
 block discarded – undo
254 254
  */
255 255
 function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
256 256
 
257
-	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
257
+    $periods = getpaid_get_subscription_periods();
258
+    $period  = strtolower( $period );
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
-	}
260
+    if ( isset( $periods[ $period ] ) ) {
261
+        return sprintf( $periods[ $period ]['singular'], $singular_prefix );
262
+    }
263 263
 
264
-	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
268
-		}
269
-	}
264
+    // Backwards compatibility.
265
+    foreach ( $periods as $key => $data ) {
266
+        if ( strpos( $key, $period ) === 0 ) {
267
+            return sprintf( $data['singular'], $singular_prefix );
268
+        }
269
+    }
270 270
 
271
-	// Invalid string.
272
-	return '';
271
+    // Invalid string.
272
+    return '';
273 273
 }
274 274
 
275 275
 /**
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
  */
282 282
 function getpaid_get_plural_subscription_period_label( $period, $interval ) {
283 283
 
284
-	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
284
+    $periods = getpaid_get_subscription_periods();
285
+    $period  = strtolower( $period );
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
289
-	}
287
+    if ( isset( $periods[ $period ] ) ) {
288
+        return sprintf( $periods[ $period ]['plural'], $interval );
289
+    }
290 290
 
291
-	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
295
-		}
296
-	}
291
+    // Backwards compatibility.
292
+    foreach ( $periods as $key => $data ) {
293
+        if ( strpos( $key, $period ) === 0 ) {
294
+            return sprintf( $data['plural'], $interval );
295
+        }
296
+    }
297 297
 
298
-	// Invalid string.
299
-	return '';
298
+    // Invalid string.
299
+    return '';
300 300
 }
301 301
 
302 302
 /**
@@ -307,101 +307,101 @@  discard block
 block discarded – undo
307 307
  */
308 308
 function getpaid_get_formatted_subscription_amount( $subscription ) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
-	$bill_times = $subscription->get_bill_times();
310
+    $initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
+    $recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
+    $period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
313
+    $bill_times = $subscription->get_bill_times();
314 314
 
315
-	if ( ! empty( $bill_times ) ) {
316
-		$bill_times = $subscription->get_frequency() * $bill_times;
317
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
-	}
315
+    if ( ! empty( $bill_times ) ) {
316
+        $bill_times = $subscription->get_frequency() * $bill_times;
317
+        $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
318
+    }
319 319
 
320
-	// Trial periods.
321
-	if ( $subscription->has_trial_period() ) {
320
+    // Trial periods.
321
+    if ( $subscription->has_trial_period() ) {
322 322
 
323
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
323
+        $trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
+        $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
325 325
 
326
-		if ( empty( $bill_times ) ) {
326
+        if ( empty( $bill_times ) ) {
327 327
 
328
-			return sprintf(
328
+            return sprintf(
329 329
 
330
-				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
332
-				$initial,
333
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
-				$recurring,
335
-				$period
330
+                // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
+                _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
332
+                $initial,
333
+                getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
334
+                $recurring,
335
+                $period
336 336
 	
337
-			);
337
+            );
338 338
 
339
-		}
339
+        }
340 340
 
341
-		return sprintf(
341
+        return sprintf(
342 342
 
343
-			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
344
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
345
-			$initial,
346
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
347
-			$recurring,
348
-			$period,
349
-			$bill_times
350
-		);
343
+            // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
344
+            _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
345
+            $initial,
346
+            getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
347
+            $recurring,
348
+            $period,
349
+            $bill_times
350
+        );
351 351
 
352
-	}
352
+    }
353 353
 
354
-	if ( $initial != $recurring ) {
354
+    if ( $initial != $recurring ) {
355 355
 
356
-		if ( empty( $bill_times ) ) {
356
+        if ( empty( $bill_times ) ) {
357 357
 
358
-			return sprintf(
358
+            return sprintf(
359 359
 
360
-				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
362
-				$initial,
363
-				$recurring,
364
-				$period
360
+                // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
+                _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
362
+                $initial,
363
+                $recurring,
364
+                $period
365 365
 	
366
-			);
366
+            );
367 367
 
368
-		}
368
+        }
369 369
 
370
-		return sprintf(
370
+        return sprintf(
371 371
 
372
-			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
374
-			$initial,
375
-			$recurring,
376
-			$period,
377
-			$bill_times
372
+            // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
+            _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
374
+            $initial,
375
+            $recurring,
376
+            $period,
377
+            $bill_times
378 378
 
379
-		);
379
+        );
380 380
 
381
-	}
381
+    }
382 382
 
383
-	if ( empty( $bill_times ) ) {
383
+    if ( empty( $bill_times ) ) {
384 384
 
385
-		return sprintf(
385
+        return sprintf(
386 386
 
387
-			// translators: $1: is the recurring amount, $2: is the recurring period
388
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
389
-			$initial,
390
-			$period
387
+            // translators: $1: is the recurring amount, $2: is the recurring period
388
+            _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
389
+            $initial,
390
+            $period
391 391
 	
392
-		);
392
+        );
393 393
 
394
-	}
394
+    }
395 395
 
396
-	return sprintf(
396
+    return sprintf(
397 397
 
398
-		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
400
-		$bill_times,
401
-		$initial,
402
-		$period
398
+        // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
+        _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
400
+        $bill_times,
401
+        $initial,
402
+        $period
403 403
 
404
-	);
404
+    );
405 405
 
406 406
 }
407 407
 
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
  * @return WPInv_Subscription|false
413 413
  */
414 414
 function getpaid_get_invoice_subscription( $invoice ) {
415
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
415
+    return getpaid_subscriptions()->get_invoice_subscription( $invoice );
416 416
 }
417 417
 
418 418
 /**
@@ -421,10 +421,10 @@  discard block
 block discarded – undo
421 421
  * @param WPInv_Invoice $invoice
422 422
  */
423 423
 function getpaid_activate_invoice_subscription( $invoice ) {
424
-	$subscription = getpaid_get_invoice_subscription( $invoice );
425
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
426
-		$subscription->activate();
427
-	}
424
+    $subscription = getpaid_get_invoice_subscription( $invoice );
425
+    if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
426
+        $subscription->activate();
427
+    }
428 428
 }
429 429
 
430 430
 /**
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return WPInv_Subscriptions
434 434
  */
435 435
 function getpaid_subscriptions() {
436
-	return getpaid()->get( 'subscriptions' );
436
+    return getpaid()->get( 'subscriptions' );
437 437
 }
438 438
 
439 439
 /**
@@ -452,15 +452,15 @@  discard block
 block discarded – undo
452 452
         return false;
453 453
     }
454 454
 
455
-	// Fetch the invoice subscription.
456
-	$subscription = getpaid_get_subscriptions(
457
-		array(
458
-			'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
459
-			'number'     => 1,
460
-		)
461
-	);
455
+    // Fetch the invoice subscription.
456
+    $subscription = getpaid_get_subscriptions(
457
+        array(
458
+            'invoice_in' => $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id(),
459
+            'number'     => 1,
460
+        )
461
+    );
462 462
 
463
-	return empty( $subscription ) ? false : $subscription[0];
463
+    return empty( $subscription ) ? false : $subscription[0];
464 464
 
465 465
 }
466 466
 
@@ -477,48 +477,48 @@  discard block
 block discarded – undo
477 477
  */
478 478
 function getpaid_get_recurring_item_key( $cart_item ) {
479 479
 
480
-	$cart_key     = 'renews_';
481
-	$interval     = $cart_item->get_recurring_interval();
482
-	$period       = $cart_item->get_recurring_period( true );
483
-	$length       = $cart_item->get_recurring_limit() * $interval;
484
-	$trial_period = $cart_item->get_trial_period( true );
485
-	$trial_length = $cart_item->get_trial_interval();
486
-
487
-	// First start with the billing interval and period
488
-	switch ( $interval ) {
489
-		case 1 :
490
-			if ( 'day' == $period ) {
491
-				$cart_key .= 'daily';
492
-			} else {
493
-				$cart_key .= sprintf( '%sly', $period );
494
-			}
495
-			break;
496
-		case 2 :
497
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
498
-			break;
499
-		case 3 :
500
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
501
-		break;
502
-		default:
503
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
504
-			break;
505
-	}
506
-
507
-	// Maybe add the optional maximum billing periods...
508
-	if ( $length > 0 ) {
509
-		$cart_key .= '_for_';
510
-		$cart_key .= sprintf( '%d_%s', $length, $period );
511
-		if ( $length > 1 ) {
512
-			$cart_key .= 's';
513
-		}
514
-	}
515
-
516
-	// And an optional free trial.
517
-	if ( $cart_item->has_free_trial() ) {
518
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
519
-	}
520
-
521
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
480
+    $cart_key     = 'renews_';
481
+    $interval     = $cart_item->get_recurring_interval();
482
+    $period       = $cart_item->get_recurring_period( true );
483
+    $length       = $cart_item->get_recurring_limit() * $interval;
484
+    $trial_period = $cart_item->get_trial_period( true );
485
+    $trial_length = $cart_item->get_trial_interval();
486
+
487
+    // First start with the billing interval and period
488
+    switch ( $interval ) {
489
+        case 1 :
490
+            if ( 'day' == $period ) {
491
+                $cart_key .= 'daily';
492
+            } else {
493
+                $cart_key .= sprintf( '%sly', $period );
494
+            }
495
+            break;
496
+        case 2 :
497
+            $cart_key .= sprintf( 'every_2nd_%s', $period );
498
+            break;
499
+        case 3 :
500
+            $cart_key .= sprintf( 'every_3rd_%s', $period );
501
+        break;
502
+        default:
503
+            $cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
504
+            break;
505
+    }
506
+
507
+    // Maybe add the optional maximum billing periods...
508
+    if ( $length > 0 ) {
509
+        $cart_key .= '_for_';
510
+        $cart_key .= sprintf( '%d_%s', $length, $period );
511
+        if ( $length > 1 ) {
512
+            $cart_key .= 's';
513
+        }
514
+    }
515
+
516
+    // And an optional free trial.
517
+    if ( $cart_item->has_free_trial() ) {
518
+        $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
519
+    }
520
+
521
+    return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
522 522
 }
523 523
 
524 524
 /**
@@ -529,17 +529,17 @@  discard block
 block discarded – undo
529 529
  */
530 530
 function getpaid_get_subscription_groups( $invoice ) {
531 531
 
532
-	// Generate subscription groups.
533
-	$subscription_groups = array();
534
-	foreach ( $invoice->get_items() as $item ) {
532
+    // Generate subscription groups.
533
+    $subscription_groups = array();
534
+    foreach ( $invoice->get_items() as $item ) {
535 535
 
536
-		if ( $item->is_recurring() ) {
537
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
538
-		}
536
+        if ( $item->is_recurring() ) {
537
+            $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
538
+        }
539 539
 
540
-	}
540
+    }
541 541
 
542
-	return $subscription_groups;
542
+    return $subscription_groups;
543 543
 }
544 544
 
545 545
 /**
@@ -553,57 +553,57 @@  discard block
 block discarded – undo
553 553
  */
554 554
 function getpaid_calculate_subscription_totals( $invoice ) {
555 555
 
556
-	// Generate subscription groups.
557
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
556
+    // Generate subscription groups.
557
+    $subscription_groups = getpaid_get_subscription_groups( $invoice );
558 558
 
559
-	// Now let's calculate the totals for each group of subscriptions
560
-	$subscription_totals = array();
559
+    // Now let's calculate the totals for each group of subscriptions
560
+    $subscription_totals = array();
561 561
 
562
-	foreach ( $subscription_groups as $subscription_key => $items ) {
562
+    foreach ( $subscription_groups as $subscription_key => $items ) {
563 563
 
564
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
564
+        if ( empty( $subscription_totals[ $subscription_key ] ) ) {
565 565
 
566
-			$subscription_totals[ $subscription_key ] = array(
567
-				'initial_total'   => 0,
568
-				'recurring_total' => 0,
569
-				'items'           => array(),
570
-				'trialling'       => false,
571
-			);
566
+            $subscription_totals[ $subscription_key ] = array(
567
+                'initial_total'   => 0,
568
+                'recurring_total' => 0,
569
+                'items'           => array(),
570
+                'trialling'       => false,
571
+            );
572 572
 
573
-		}
573
+        }
574 574
 
575
-		/**
576
-		 * Get the totals of the group.
577
-		 * @var GetPaid_Form_Item $item
578
-		 */
579
-		foreach ( $items as $item ) {
575
+        /**
576
+         * Get the totals of the group.
577
+         * @var GetPaid_Form_Item $item
578
+         */
579
+        foreach ( $items as $item ) {
580 580
 
581
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
581
+            $subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
+            $subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
+            $subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
+            $subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
+            $subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
+            $subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
+            $subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
588 588
 
589
-			// Calculate the next renewal date.
590
-			$period       = $item->get_recurring_period( true );
591
-			$interval     = $item->get_recurring_interval();
589
+            // Calculate the next renewal date.
590
+            $period       = $item->get_recurring_period( true );
591
+            $interval     = $item->get_recurring_interval();
592 592
 
593
-			// If the subscription item has a trial period...
594
-			if ( $item->has_free_trial() ) {
595
-				$period   = $item->get_trial_period( true );
596
-				$interval = $item->get_trial_interval();
597
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
598
-			}
593
+            // If the subscription item has a trial period...
594
+            if ( $item->has_free_trial() ) {
595
+                $period   = $item->get_trial_period( true );
596
+                $interval = $item->get_trial_interval();
597
+                $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
598
+            }
599 599
 
600
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
600
+            $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
601 601
 
602
-		}
602
+        }
603 603
 
604
-	}
604
+    }
605 605
 
606
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
606
+    return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
607 607
 }
608 608
 
609 609
 /**
@@ -614,17 +614,17 @@  discard block
 block discarded – undo
614 614
  */
615 615
 function getpaid_should_group_subscriptions( $invoice ) {
616 616
 
617
-	$recurring_items = 0;
617
+    $recurring_items = 0;
618 618
 
619
-	foreach ( $invoice->get_items() as $item ) {
619
+    foreach ( $invoice->get_items() as $item ) {
620 620
 
621
-		if ( $item->is_recurring() ) {
622
-			$recurring_items ++;
623
-		}
621
+        if ( $item->is_recurring() ) {
622
+            $recurring_items ++;
623
+        }
624 624
 
625
-	}
625
+    }
626 626
 
627
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
627
+    return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
628 628
 }
629 629
 
630 630
 /**
@@ -635,40 +635,40 @@  discard block
 block discarded – undo
635 635
  * @return int
636 636
  */
637 637
 function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
638
-	global $wpdb;
638
+    global $wpdb;
639 639
 
640
-	$parent_invoice_id = (int) $parent_invoice_id;
640
+    $parent_invoice_id = (int) $parent_invoice_id;
641 641
 
642
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
642
+    if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
643 643
 
644
-		return (int) $wpdb->get_var(
645
-			$wpdb->prepare(
646
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
647
-				$parent_invoice_id,
648
-				$parent_invoice_id
649
-			)
650
-		);
644
+        return (int) $wpdb->get_var(
645
+            $wpdb->prepare(
646
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
647
+                $parent_invoice_id,
648
+                $parent_invoice_id
649
+            )
650
+        );
651 651
 
652
-	}
652
+    }
653 653
 	
654
-	$invoice_ids = $wpdb->get_col(
655
-		$wpdb->prepare(
656
-			"SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
657
-			$parent_invoice_id,
658
-			$parent_invoice_id
659
-		)
660
-	);
654
+    $invoice_ids = $wpdb->get_col(
655
+        $wpdb->prepare(
656
+            "SELECT ID FROM $wpdb->posts WHERE ( post_parent=%d OR ID=%d ) AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
657
+            $parent_invoice_id,
658
+            $parent_invoice_id
659
+        )
660
+    );
661 661
 
662
-	$count = 0;
662
+    $count = 0;
663 663
 
664
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
664
+    foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
665 665
 
666
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
-			$count ++;
668
-			continue;
669
-		}
666
+        if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
+            $count ++;
668
+            continue;
669
+        }
670 670
 
671
-	}
671
+    }
672 672
 
673
-	return $count;
673
+    return $count;
674 674
 }
Please login to merge, or discard this patch.
Spacing   +143 added lines, -143 removed lines patch added patch discarded remove patch
@@ -13,18 +13,18 @@  discard block
 block discarded – undo
13 13
  * @return      WPInv_Subscription[]|WPInv_Subscription|false
14 14
  * @since       2.3.0
15 15
  */
16
-function getpaid_get_invoice_subscriptions( $invoice ) {
16
+function getpaid_get_invoice_subscriptions($invoice) {
17 17
 
18 18
     // Retrieve subscription groups.
19
-    $subscription_ids = wp_list_pluck( getpaid_get_invoice_subscription_groups( $invoice->get_id() ), 'subscription_id' );
19
+    $subscription_ids = wp_list_pluck(getpaid_get_invoice_subscription_groups($invoice->get_id()), 'subscription_id');
20 20
 
21 21
     // No subscription groups, normal subscription.
22
-    if ( empty( $subscription_ids ) ) {
23
-        return getpaid_subscriptions()->get_invoice_subscription( $invoice );
22
+    if (empty($subscription_ids)) {
23
+        return getpaid_subscriptions()->get_invoice_subscription($invoice);
24 24
     }
25 25
 
26 26
     // Subscription groups.
27
-    return array_filter( array_map( 'getpaid_get_subscription', $subscription_ids ) );
27
+    return array_filter(array_map('getpaid_get_subscription', $subscription_ids));
28 28
 
29 29
 }
30 30
 
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
  * @return      array
36 36
  * @since       2.3.0
37 37
  */
38
-function getpaid_get_invoice_subscription_groups( $invoice_id ) {
39
-    $subscription_groups = get_post_meta( $invoice_id, 'getpaid_subscription_groups', true );
40
-    return empty( $subscription_groups ) ? array() : $subscription_groups;
38
+function getpaid_get_invoice_subscription_groups($invoice_id) {
39
+    $subscription_groups = get_post_meta($invoice_id, 'getpaid_subscription_groups', true);
40
+    return empty($subscription_groups) ? array() : $subscription_groups;
41 41
 }
42 42
 
43 43
 /**
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
  * @return      array|false
49 49
  * @since       2.3.0
50 50
  */
51
-function getpaid_get_invoice_subscription_group( $invoice_id, $subscription_id ) {
52
-    $subscription_groups = getpaid_get_invoice_subscription_groups( $invoice_id );
53
-	$matching_group      = wp_list_filter( $subscription_groups, compact( 'subscription_id' ) );
54
-    return reset( $matching_group );
51
+function getpaid_get_invoice_subscription_group($invoice_id, $subscription_id) {
52
+    $subscription_groups = getpaid_get_invoice_subscription_groups($invoice_id);
53
+	$matching_group = wp_list_filter($subscription_groups, compact('subscription_id'));
54
+    return reset($matching_group);
55 55
 }
56 56
 
57 57
 /**
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
  * @since       2.3.0
62 62
  * @return WPInv_Subscription|false
63 63
  */
64
-function getpaid_get_subscription( $subscription ) {
64
+function getpaid_get_subscription($subscription) {
65 65
 
66
-	if ( ! is_a( $subscription, 'WPInv_Subscription' ) ) {
67
-		$subscription = new WPInv_Subscription( $subscription );
66
+	if (!is_a($subscription, 'WPInv_Subscription')) {
67
+		$subscription = new WPInv_Subscription($subscription);
68 68
 	}
69 69
 
70 70
 	return $subscription->exists() ? $subscription : false;
@@ -79,26 +79,26 @@  discard block
 block discarded – undo
79 79
  *
80 80
  * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query
81 81
  */
82
-function getpaid_get_subscriptions( $args = array(), $return = 'results' ) {
82
+function getpaid_get_subscriptions($args = array(), $return = 'results') {
83 83
 
84 84
 	// Do not retrieve all fields if we just want the count.
85
-	if ( 'count' == $return ) {
85
+	if ('count' == $return) {
86 86
 		$args['fields'] = 'id';
87 87
 		$args['number'] = 1;
88 88
 	}
89 89
 
90 90
 	// Do not count all matches if we just want the results.
91
-	if ( 'results' == $return ) {
91
+	if ('results' == $return) {
92 92
 		$args['count_total'] = false;
93 93
 	}
94 94
 
95
-	$query = new GetPaid_Subscriptions_Query( $args );
95
+	$query = new GetPaid_Subscriptions_Query($args);
96 96
 
97
-	if ( 'results' == $return ) {
97
+	if ('results' == $return) {
98 98
 		return $query->get_results();
99 99
 	}
100 100
 
101
-	if ( 'count' == $return ) {
101
+	if ('count' == $return) {
102 102
 		return $query->get_total();
103 103
 	}
104 104
 
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	return apply_filters(
116 116
 		'getpaid_get_subscription_statuses',
117 117
 		array(
118
-			'pending'    => __( 'Pending', 'invoicing' ),
119
-			'trialling'  => __( 'Trialing', 'invoicing' ),
120
-			'active'     => __( 'Active', 'invoicing' ),
121
-			'failing'    => __( 'Failing', 'invoicing' ),
122
-			'expired'    => __( 'Expired', 'invoicing' ),
123
-			'completed'  => __( 'Complete', 'invoicing' ),
124
-			'cancelled'  => __( 'Cancelled', 'invoicing' ),
118
+			'pending'    => __('Pending', 'invoicing'),
119
+			'trialling'  => __('Trialing', 'invoicing'),
120
+			'active'     => __('Active', 'invoicing'),
121
+			'failing'    => __('Failing', 'invoicing'),
122
+			'expired'    => __('Expired', 'invoicing'),
123
+			'completed'  => __('Complete', 'invoicing'),
124
+			'cancelled'  => __('Cancelled', 'invoicing'),
125 125
 		)
126 126
 	);
127 127
 
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
  *
133 133
  * @return string
134 134
  */
135
-function getpaid_get_subscription_status_label( $status ) {
135
+function getpaid_get_subscription_status_label($status) {
136 136
 	$statuses = getpaid_get_subscription_statuses();
137
-	return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) );
137
+	return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status));
138 138
 }
139 139
 
140 140
 /**
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
  *
165 165
  * @return array
166 166
  */
167
-function getpaid_get_subscription_status_counts( $args = array() ) {
167
+function getpaid_get_subscription_status_counts($args = array()) {
168 168
 
169
-	$statuses = array_keys( getpaid_get_subscription_statuses() );
169
+	$statuses = array_keys(getpaid_get_subscription_statuses());
170 170
 	$counts   = array();
171 171
 
172
-	foreach ( $statuses as $status ) {
173
-		$_args             = wp_parse_args( "status=$status", $args );
174
-		$counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' );
172
+	foreach ($statuses as $status) {
173
+		$_args             = wp_parse_args("status=$status", $args);
174
+		$counts[$status] = getpaid_get_subscriptions($_args, 'count');
175 175
 	}
176 176
 
177 177
 	return $counts;
@@ -190,23 +190,23 @@  discard block
 block discarded – undo
190 190
 		array(
191 191
 
192 192
 			'day'   => array(
193
-				'singular' => __( '%s day', 'invoicing' ),
194
-				'plural'   => __( '%d days', 'invoicing' ),
193
+				'singular' => __('%s day', 'invoicing'),
194
+				'plural'   => __('%d days', 'invoicing'),
195 195
 			),
196 196
 
197 197
 			'week'   => array(
198
-				'singular' => __( '%s week', 'invoicing' ),
199
-				'plural'   => __( '%d weeks', 'invoicing' ),
198
+				'singular' => __('%s week', 'invoicing'),
199
+				'plural'   => __('%d weeks', 'invoicing'),
200 200
 			),
201 201
 
202 202
 			'month'   => array(
203
-				'singular' => __( '%s month', 'invoicing' ),
204
-				'plural'   => __( '%d months', 'invoicing' ),
203
+				'singular' => __('%s month', 'invoicing'),
204
+				'plural'   => __('%d months', 'invoicing'),
205 205
 			),
206 206
 
207 207
 			'year'   => array(
208
-				'singular' => __( '%s year', 'invoicing' ),
209
-				'plural'   => __( '%d years', 'invoicing' ),
208
+				'singular' => __('%s year', 'invoicing'),
209
+				'plural'   => __('%d years', 'invoicing'),
210 210
 			),
211 211
 
212 212
 		)
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
  * @param string $trial_period
221 221
  * @return int
222 222
  */
223
-function getpaid_get_subscription_trial_period_interval( $trial_period ) {
224
-	return (int) preg_replace( '/[^0-9]/', '', $trial_period );
223
+function getpaid_get_subscription_trial_period_interval($trial_period) {
224
+	return (int) preg_replace('/[^0-9]/', '', $trial_period);
225 225
 }
226 226
 
227 227
 /**
@@ -230,8 +230,8 @@  discard block
 block discarded – undo
230 230
  * @param string $trial_period
231 231
  * @return string
232 232
  */
233
-function getpaid_get_subscription_trial_period_period( $trial_period ) {
234
-	return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) );
233
+function getpaid_get_subscription_trial_period_period($trial_period) {
234
+	return preg_replace('/[^a-z]/', '', strtolower($trial_period));
235 235
 }
236 236
 
237 237
 /**
@@ -241,9 +241,9 @@  discard block
 block discarded – undo
241 241
  * @param int $interval
242 242
  * @return string
243 243
  */
244
-function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) {
245
-	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label(  $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix );
246
-	return strtolower( sanitize_text_field( $label ) );
244
+function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') {
245
+	$label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix);
246
+	return strtolower(sanitize_text_field($label));
247 247
 }
248 248
 
249 249
 /**
@@ -252,19 +252,19 @@  discard block
 block discarded – undo
252 252
  * @param string $period
253 253
  * @return string
254 254
  */
255
-function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) {
255
+function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') {
256 256
 
257 257
 	$periods = getpaid_get_subscription_periods();
258
-	$period  = strtolower( $period );
258
+	$period  = strtolower($period);
259 259
 
260
-	if ( isset( $periods[ $period ] ) ) {
261
-		return sprintf( $periods[ $period ]['singular'], $singular_prefix );
260
+	if (isset($periods[$period])) {
261
+		return sprintf($periods[$period]['singular'], $singular_prefix);
262 262
 	}
263 263
 
264 264
 	// Backwards compatibility.
265
-	foreach ( $periods as $key => $data ) {
266
-		if ( strpos( $key, $period ) === 0 ) {
267
-			return sprintf( $data['singular'], $singular_prefix );
265
+	foreach ($periods as $key => $data) {
266
+		if (strpos($key, $period) === 0) {
267
+			return sprintf($data['singular'], $singular_prefix);
268 268
 		}
269 269
 	}
270 270
 
@@ -279,19 +279,19 @@  discard block
 block discarded – undo
279 279
  * @param int $interval
280 280
  * @return string
281 281
  */
282
-function getpaid_get_plural_subscription_period_label( $period, $interval ) {
282
+function getpaid_get_plural_subscription_period_label($period, $interval) {
283 283
 
284 284
 	$periods = getpaid_get_subscription_periods();
285
-	$period  = strtolower( $period );
285
+	$period  = strtolower($period);
286 286
 
287
-	if ( isset( $periods[ $period ] ) ) {
288
-		return sprintf( $periods[ $period ]['plural'], $interval );
287
+	if (isset($periods[$period])) {
288
+		return sprintf($periods[$period]['plural'], $interval);
289 289
 	}
290 290
 
291 291
 	// Backwards compatibility.
292
-	foreach ( $periods as $key => $data ) {
293
-		if ( strpos( $key, $period ) === 0 ) {
294
-			return sprintf( $data['plural'], $interval );
292
+	foreach ($periods as $key => $data) {
293
+		if (strpos($key, $period) === 0) {
294
+			return sprintf($data['plural'], $interval);
295 295
 		}
296 296
 	}
297 297
 
@@ -305,32 +305,32 @@  discard block
 block discarded – undo
305 305
  * @param WPInv_Subscription $subscription
306 306
  * @return string
307 307
  */
308
-function getpaid_get_formatted_subscription_amount( $subscription ) {
308
+function getpaid_get_formatted_subscription_amount($subscription) {
309 309
 
310
-	$initial    = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() );
311
-	$recurring  = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() );
312
-	$period     = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' );
310
+	$initial    = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency());
311
+	$recurring  = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency());
312
+	$period     = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), '');
313 313
 	$bill_times = $subscription->get_bill_times();
314 314
 
315
-	if ( ! empty( $bill_times ) ) {
315
+	if (!empty($bill_times)) {
316 316
 		$bill_times = $subscription->get_frequency() * $bill_times;
317
-		$bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times );
317
+		$bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times);
318 318
 	}
319 319
 
320 320
 	// Trial periods.
321
-	if ( $subscription->has_trial_period() ) {
321
+	if ($subscription->has_trial_period()) {
322 322
 
323
-		$trial_period   = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() );
324
-		$trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() );
323
+		$trial_period   = getpaid_get_subscription_trial_period_period($subscription->get_trial_period());
324
+		$trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period());
325 325
 
326
-		if ( empty( $bill_times ) ) {
326
+		if (empty($bill_times)) {
327 327
 
328 328
 			return sprintf(
329 329
 
330 330
 				// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period
331
-				_x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ),
331
+				_x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'),
332 332
 				$initial,
333
-				getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
333
+				getpaid_get_subscription_period_label($trial_period, $trial_interval),
334 334
 				$recurring,
335 335
 				$period
336 336
 	
@@ -341,9 +341,9 @@  discard block
 block discarded – undo
341 341
 		return sprintf(
342 342
 
343 343
 			// translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times
344
-			_x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ),
344
+			_x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'),
345 345
 			$initial,
346
-			getpaid_get_subscription_period_label( $trial_period, $trial_interval ),
346
+			getpaid_get_subscription_period_label($trial_period, $trial_interval),
347 347
 			$recurring,
348 348
 			$period,
349 349
 			$bill_times
@@ -351,14 +351,14 @@  discard block
 block discarded – undo
351 351
 
352 352
 	}
353 353
 
354
-	if ( $initial != $recurring ) {
354
+	if ($initial != $recurring) {
355 355
 
356
-		if ( empty( $bill_times ) ) {
356
+		if (empty($bill_times)) {
357 357
 
358 358
 			return sprintf(
359 359
 
360 360
 				// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period
361
-				_x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ),
361
+				_x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'),
362 362
 				$initial,
363 363
 				$recurring,
364 364
 				$period
@@ -370,7 +370,7 @@  discard block
 block discarded – undo
370 370
 		return sprintf(
371 371
 
372 372
 			// translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times
373
-			_x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ),
373
+			_x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'),
374 374
 			$initial,
375 375
 			$recurring,
376 376
 			$period,
@@ -380,12 +380,12 @@  discard block
 block discarded – undo
380 380
 
381 381
 	}
382 382
 
383
-	if ( empty( $bill_times ) ) {
383
+	if (empty($bill_times)) {
384 384
 
385 385
 		return sprintf(
386 386
 
387 387
 			// translators: $1: is the recurring amount, $2: is the recurring period
388
-			_x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ),
388
+			_x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'),
389 389
 			$initial,
390 390
 			$period
391 391
 	
@@ -396,7 +396,7 @@  discard block
 block discarded – undo
396 396
 	return sprintf(
397 397
 
398 398
 		// translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period
399
-		_x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ),
399
+		_x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'),
400 400
 		$bill_times,
401 401
 		$initial,
402 402
 		$period
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  * @param WPInv_Invoice $invoice
412 412
  * @return WPInv_Subscription|false
413 413
  */
414
-function getpaid_get_invoice_subscription( $invoice ) {
415
-	return getpaid_subscriptions()->get_invoice_subscription( $invoice );
414
+function getpaid_get_invoice_subscription($invoice) {
415
+	return getpaid_subscriptions()->get_invoice_subscription($invoice);
416 416
 }
417 417
 
418 418
 /**
@@ -420,9 +420,9 @@  discard block
 block discarded – undo
420 420
  *
421 421
  * @param WPInv_Invoice $invoice
422 422
  */
423
-function getpaid_activate_invoice_subscription( $invoice ) {
424
-	$subscription = getpaid_get_invoice_subscription( $invoice );
425
-	if ( is_a( $subscription, 'WPInv_Subscription' ) ) {
423
+function getpaid_activate_invoice_subscription($invoice) {
424
+	$subscription = getpaid_get_invoice_subscription($invoice);
425
+	if (is_a($subscription, 'WPInv_Subscription')) {
426 426
 		$subscription->activate();
427 427
 	}
428 428
 }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return WPInv_Subscriptions
434 434
  */
435 435
 function getpaid_subscriptions() {
436
-	return getpaid()->get( 'subscriptions' );
436
+	return getpaid()->get('subscriptions');
437 437
 }
438 438
 
439 439
 /**
@@ -442,13 +442,13 @@  discard block
 block discarded – undo
442 442
  * @since 2.3.0
443 443
  * @return WPInv_Subscription|bool
444 444
  */
445
-function wpinv_get_invoice_subscription( $invoice ) {
445
+function wpinv_get_invoice_subscription($invoice) {
446 446
 
447 447
     // Retrieve the invoice.
448
-    $invoice = new WPInv_Invoice( $invoice );
448
+    $invoice = new WPInv_Invoice($invoice);
449 449
 
450 450
     // Ensure it is a recurring invoice.
451
-    if ( ! $invoice->is_recurring() ) {
451
+    if (!$invoice->is_recurring()) {
452 452
         return false;
453 453
     }
454 454
 
@@ -460,7 +460,7 @@  discard block
 block discarded – undo
460 460
 		)
461 461
 	);
462 462
 
463
-	return empty( $subscription ) ? false : $subscription[0];
463
+	return empty($subscription) ? false : $subscription[0];
464 464
 
465 465
 }
466 466
 
@@ -475,50 +475,50 @@  discard block
 block discarded – undo
475 475
  * @param GetPaid_Form_Item|WPInv_Item $cart_item
476 476
  * @return string
477 477
  */
478
-function getpaid_get_recurring_item_key( $cart_item ) {
478
+function getpaid_get_recurring_item_key($cart_item) {
479 479
 
480 480
 	$cart_key     = 'renews_';
481 481
 	$interval     = $cart_item->get_recurring_interval();
482
-	$period       = $cart_item->get_recurring_period( true );
482
+	$period       = $cart_item->get_recurring_period(true);
483 483
 	$length       = $cart_item->get_recurring_limit() * $interval;
484
-	$trial_period = $cart_item->get_trial_period( true );
484
+	$trial_period = $cart_item->get_trial_period(true);
485 485
 	$trial_length = $cart_item->get_trial_interval();
486 486
 
487 487
 	// First start with the billing interval and period
488
-	switch ( $interval ) {
488
+	switch ($interval) {
489 489
 		case 1 :
490
-			if ( 'day' == $period ) {
490
+			if ('day' == $period) {
491 491
 				$cart_key .= 'daily';
492 492
 			} else {
493
-				$cart_key .= sprintf( '%sly', $period );
493
+				$cart_key .= sprintf('%sly', $period);
494 494
 			}
495 495
 			break;
496 496
 		case 2 :
497
-			$cart_key .= sprintf( 'every_2nd_%s', $period );
497
+			$cart_key .= sprintf('every_2nd_%s', $period);
498 498
 			break;
499 499
 		case 3 :
500
-			$cart_key .= sprintf( 'every_3rd_%s', $period );
500
+			$cart_key .= sprintf('every_3rd_%s', $period);
501 501
 		break;
502 502
 		default:
503
-			$cart_key .= sprintf( 'every_%dth_%s', $interval, $period );
503
+			$cart_key .= sprintf('every_%dth_%s', $interval, $period);
504 504
 			break;
505 505
 	}
506 506
 
507 507
 	// Maybe add the optional maximum billing periods...
508
-	if ( $length > 0 ) {
508
+	if ($length > 0) {
509 509
 		$cart_key .= '_for_';
510
-		$cart_key .= sprintf( '%d_%s', $length, $period );
511
-		if ( $length > 1 ) {
510
+		$cart_key .= sprintf('%d_%s', $length, $period);
511
+		if ($length > 1) {
512 512
 			$cart_key .= 's';
513 513
 		}
514 514
 	}
515 515
 
516 516
 	// And an optional free trial.
517
-	if ( $cart_item->has_free_trial() ) {
518
-		$cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period );
517
+	if ($cart_item->has_free_trial()) {
518
+		$cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period);
519 519
 	}
520 520
 
521
-	return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item );
521
+	return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item);
522 522
 }
523 523
 
524 524
 /**
@@ -527,14 +527,14 @@  discard block
 block discarded – undo
527 527
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
528 528
  * @return array
529 529
  */
530
-function getpaid_get_subscription_groups( $invoice ) {
530
+function getpaid_get_subscription_groups($invoice) {
531 531
 
532 532
 	// Generate subscription groups.
533 533
 	$subscription_groups = array();
534
-	foreach ( $invoice->get_items() as $item ) {
534
+	foreach ($invoice->get_items() as $item) {
535 535
 
536
-		if ( $item->is_recurring() ) {
537
-			$subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item;
536
+		if ($item->is_recurring()) {
537
+			$subscription_groups[getpaid_get_recurring_item_key($item)][] = $item;
538 538
 		}
539 539
 
540 540
 	}
@@ -551,19 +551,19 @@  discard block
 block discarded – undo
551 551
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
552 552
  * @return array
553 553
  */
554
-function getpaid_calculate_subscription_totals( $invoice ) {
554
+function getpaid_calculate_subscription_totals($invoice) {
555 555
 
556 556
 	// Generate subscription groups.
557
-	$subscription_groups = getpaid_get_subscription_groups( $invoice );
557
+	$subscription_groups = getpaid_get_subscription_groups($invoice);
558 558
 
559 559
 	// Now let's calculate the totals for each group of subscriptions
560 560
 	$subscription_totals = array();
561 561
 
562
-	foreach ( $subscription_groups as $subscription_key => $items ) {
562
+	foreach ($subscription_groups as $subscription_key => $items) {
563 563
 
564
-		if ( empty( $subscription_totals[ $subscription_key ] ) ) {
564
+		if (empty($subscription_totals[$subscription_key])) {
565 565
 
566
-			$subscription_totals[ $subscription_key ] = array(
566
+			$subscription_totals[$subscription_key] = array(
567 567
 				'initial_total'   => 0,
568 568
 				'recurring_total' => 0,
569 569
 				'items'           => array(),
@@ -576,34 +576,34 @@  discard block
 block discarded – undo
576 576
 		 * Get the totals of the group.
577 577
 		 * @var GetPaid_Form_Item $item
578 578
 		 */
579
-		foreach ( $items as $item ) {
579
+		foreach ($items as $item) {
580 580
 
581
-			$subscription_totals[ $subscription_key ]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
-			$subscription_totals[ $subscription_key ]['item_id']                 = $item->get_id();
583
-			$subscription_totals[ $subscription_key ]['period']                  = $item->get_recurring_period( true );
584
-			$subscription_totals[ $subscription_key ]['interval']                = $item->get_recurring_interval();
585
-			$subscription_totals[ $subscription_key ]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
-			$subscription_totals[ $subscription_key ]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
-			$subscription_totals[ $subscription_key ]['recurring_limit']         = $item->get_recurring_limit();
581
+			$subscription_totals[$subscription_key]['items'][$item->get_id()]  = $item->prepare_data_for_saving();
582
+			$subscription_totals[$subscription_key]['item_id']                 = $item->get_id();
583
+			$subscription_totals[$subscription_key]['period']                  = $item->get_recurring_period(true);
584
+			$subscription_totals[$subscription_key]['interval']                = $item->get_recurring_interval();
585
+			$subscription_totals[$subscription_key]['initial_total']          += $item->get_sub_total() + $item->item_tax - $item->item_discount;
586
+			$subscription_totals[$subscription_key]['recurring_total']        += $item->get_recurring_sub_total() + $item->item_tax - $item->recurring_item_discount;
587
+			$subscription_totals[$subscription_key]['recurring_limit']         = $item->get_recurring_limit();
588 588
 
589 589
 			// Calculate the next renewal date.
590
-			$period       = $item->get_recurring_period( true );
590
+			$period       = $item->get_recurring_period(true);
591 591
 			$interval     = $item->get_recurring_interval();
592 592
 
593 593
 			// If the subscription item has a trial period...
594
-			if ( $item->has_free_trial() ) {
595
-				$period   = $item->get_trial_period( true );
594
+			if ($item->has_free_trial()) {
595
+				$period   = $item->get_trial_period(true);
596 596
 				$interval = $item->get_trial_interval();
597
-				$subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period;
597
+				$subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period;
598 598
 			}
599 599
 
600
-			$subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) );
600
+			$subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp')));
601 601
 
602 602
 		}
603 603
 
604 604
 	}
605 605
 
606
-	return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice );
606
+	return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice);
607 607
 }
608 608
 
609 609
 /**
@@ -612,19 +612,19 @@  discard block
 block discarded – undo
612 612
  * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice
613 613
  * @return array
614 614
  */
615
-function getpaid_should_group_subscriptions( $invoice ) {
615
+function getpaid_should_group_subscriptions($invoice) {
616 616
 
617 617
 	$recurring_items = 0;
618 618
 
619
-	foreach ( $invoice->get_items() as $item ) {
619
+	foreach ($invoice->get_items() as $item) {
620 620
 
621
-		if ( $item->is_recurring() ) {
622
-			$recurring_items ++;
621
+		if ($item->is_recurring()) {
622
+			$recurring_items++;
623 623
 		}
624 624
 
625 625
 	}
626 626
 
627
-	return apply_filters( 'getpaid_should_group_subscriptions', $recurring_items > 1, $invoice );
627
+	return apply_filters('getpaid_should_group_subscriptions', $recurring_items > 1, $invoice);
628 628
 }
629 629
 
630 630
 /**
@@ -634,12 +634,12 @@  discard block
 block discarded – undo
634 634
  * @param int|false $subscription_id
635 635
  * @return int
636 636
  */
637
-function getpaid_count_subscription_invoices( $parent_invoice_id, $subscription_id = false ) {
637
+function getpaid_count_subscription_invoices($parent_invoice_id, $subscription_id = false) {
638 638
 	global $wpdb;
639 639
 
640 640
 	$parent_invoice_id = (int) $parent_invoice_id;
641 641
 
642
-	if ( false === $subscription_id || ! (bool) get_post_meta( $parent_invoice_id, '_wpinv_subscription_id', true ) ) {
642
+	if (false === $subscription_id || !(bool) get_post_meta($parent_invoice_id, '_wpinv_subscription_id', true)) {
643 643
 
644 644
 		return (int) $wpdb->get_var(
645 645
 			$wpdb->prepare(
@@ -661,10 +661,10 @@  discard block
 block discarded – undo
661 661
 
662 662
 	$count = 0;
663 663
 
664
-	foreach ( wp_parse_id_list( $invoice_ids ) as $invoice_id ) {
664
+	foreach (wp_parse_id_list($invoice_ids) as $invoice_id) {
665 665
 
666
-		if ( $invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta( $invoice_id, '_wpinv_subscription_id', true ) ) {
667
-			$count ++;
666
+		if ($invoice_id == $parent_invoice_id || $subscription_id == (int) get_post_meta($invoice_id, '_wpinv_subscription_id', true)) {
667
+			$count++;
668 668
 			continue;
669 669
 		}
670 670
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -12,230 +12,230 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26 26
 
27 27
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
-
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
74
-				continue;
75
-			}
76
-
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
-
80
-		}
81
-
82
-	}
83
-
84
-	/**
85
-	 * Checks if the submission has a digital item.
86
-	 *
87
-	 * @param GetPaid_Payment_Form_Submission $submission
88
-	 * @since 1.0.19
89
-	 * @return bool
90
-	 */
91
-	public function has_digital_item( $submission ) {
92
-
93
-		foreach ( $submission->get_items() as $item ) {
94
-
95
-			if ( 'digital' == $item->get_vat_rule() ) {
96
-				return true;
97
-			}
98
-
99
-		}
100
-
101
-		return false;
102
-	}
103
-
104
-	/**
105
-	 * Checks if this is an eu store.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @return bool
109
-	 */
110
-	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
112
-	}
113
-
114
-	/**
115
-	 * Checks if this is an eu country.
116
-	 *
117
-	 * @param string $country
118
-	 * @since 1.0.19
119
-	 * @return bool
120
-	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
123
-	}
124
-
125
-	/**
126
-	 * Checks if this is an eu purchase.
127
-	 *
128
-	 * @param string $customer_country
129
-	 * @since 1.0.19
130
-	 * @return bool
131
-	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
-	}
135
-
136
-	/**
137
-	 * Retrieves the vat number.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 * @since 1.0.19
141
-	 * @return string
142
-	 */
143
-	public function get_vat_number( $submission ) {
144
-
145
-		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
149
-		}
150
-
151
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
-	}
153
-
154
-	/**
155
-	 * Retrieves the company.
156
-	 *
157
-	 * @param GetPaid_Payment_Form_Submission $submission
158
-	 * @since 1.0.19
159
-	 * @return string
160
-	 */
161
-	public function get_company( $submission ) {
162
-
163
-		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
167
-		}
168
-
169
-		// Retrieve from the invoice.
170
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
-	}
172
-
173
-	/**
174
-	 * Checks if we require a VAT number.
175
-	 *
176
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
177
-	 * @param bool $country_in_eu Whether the customer country is from the EU
178
-	 * @since 1.0.19
179
-	 * @return string
180
-	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
-
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
185
-		$is_eu       = $ip_in_eu || $country_in_eu;
186
-
187
-		return $prevent_b2c && $is_eu;
188
-	}
189
-
190
-	/**
191
-	 * Validate VAT data.
192
-	 *
193
-	 * @param GetPaid_Payment_Form_Submission $submission
194
-	 * @since 1.0.19
195
-	 */
196
-	public function validate_vat( $submission ) {
197
-
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
199
-
200
-		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
202 38
             return;
203
-		}
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            $item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
71
+
72
+            if ( ! isset( $this->taxes[ $name ] ) ) {
73
+                $this->taxes[ $name ] = $tax;
74
+                continue;
75
+            }
76
+
77
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
79
+
80
+        }
81
+
82
+    }
83
+
84
+    /**
85
+     * Checks if the submission has a digital item.
86
+     *
87
+     * @param GetPaid_Payment_Form_Submission $submission
88
+     * @since 1.0.19
89
+     * @return bool
90
+     */
91
+    public function has_digital_item( $submission ) {
92
+
93
+        foreach ( $submission->get_items() as $item ) {
94
+
95
+            if ( 'digital' == $item->get_vat_rule() ) {
96
+                return true;
97
+            }
98
+
99
+        }
204 100
 
205
-		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
207
-		$ip_country  = getpaid_get_ip_country();
101
+        return false;
102
+    }
103
+
104
+    /**
105
+     * Checks if this is an eu store.
106
+     *
107
+     * @since 1.0.19
108
+     * @return bool
109
+     */
110
+    public static function is_eu_store() {
111
+        return self::is_eu_country( wpinv_get_default_country() );
112
+    }
113
+
114
+    /**
115
+     * Checks if this is an eu country.
116
+     *
117
+     * @param string $country
118
+     * @since 1.0.19
119
+     * @return bool
120
+     */
121
+    public static function is_eu_country( $country ) {
122
+        return getpaid_is_eu_state( $country );
123
+    }
124
+
125
+    /**
126
+     * Checks if this is an eu purchase.
127
+     *
128
+     * @param string $customer_country
129
+     * @since 1.0.19
130
+     * @return bool
131
+     */
132
+    public static function is_eu_transaction( $customer_country ) {
133
+        return self::is_eu_country( $customer_country ) && self::is_eu_store();
134
+    }
135
+
136
+    /**
137
+     * Retrieves the vat number.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     * @since 1.0.19
141
+     * @return string
142
+     */
143
+    public function get_vat_number( $submission ) {
144
+
145
+        // Retrieve from the posted number.
146
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
+        if ( ! is_null( $vat_number ) ) {
148
+            return wpinv_clean( $vat_number );
149
+        }
150
+
151
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
152
+    }
153
+
154
+    /**
155
+     * Retrieves the company.
156
+     *
157
+     * @param GetPaid_Payment_Form_Submission $submission
158
+     * @since 1.0.19
159
+     * @return string
160
+     */
161
+    public function get_company( $submission ) {
162
+
163
+        // Retrieve from the posted data.
164
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
165
+        if ( ! empty( $company ) ) {
166
+            return wpinv_clean( $company );
167
+        }
168
+
169
+        // Retrieve from the invoice.
170
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
171
+    }
172
+
173
+    /**
174
+     * Checks if we require a VAT number.
175
+     *
176
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
177
+     * @param bool $country_in_eu Whether the customer country is from the EU
178
+     * @since 1.0.19
179
+     * @return string
180
+     */
181
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
182
+
183
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
+        $prevent_b2c = ! empty( $prevent_b2c );
185
+        $is_eu       = $ip_in_eu || $country_in_eu;
186
+
187
+        return $prevent_b2c && $is_eu;
188
+    }
189
+
190
+    /**
191
+     * Validate VAT data.
192
+     *
193
+     * @param GetPaid_Payment_Form_Submission $submission
194
+     * @since 1.0.19
195
+     */
196
+    public function validate_vat( $submission ) {
197
+
198
+        $in_eu = $this->is_eu_transaction( $submission->country );
199
+
200
+        // Abort if we are not validating vat numbers.
201
+        if ( ! $in_eu ) {
202
+            return;
203
+        }
204
+
205
+        // Prepare variables.
206
+        $vat_number  = $this->get_vat_number( $submission );
207
+        $ip_country  = getpaid_get_ip_country();
208 208
         $is_eu       = $this->is_eu_country( $submission->country );
209 209
         $is_ip_eu    = $this->is_eu_country( $ip_country );
210 210
 
211
-		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
-			return;
214
-		}
211
+        // Maybe abort early for initial fetches.
212
+        if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
213
+            return;
214
+        }
215 215
 
216
-		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases,
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
222
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
222
+            );
223 223
 
224
-		}
224
+        }
225 225
 
226
-		if ( empty( $vat_number ) ) {
227
-			return;
228
-		}
226
+        if ( empty( $vat_number ) ) {
227
+            return;
228
+        }
229 229
 
230
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
232
-		}
230
+        if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
+            throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
232
+        }
233 233
 
234
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
235
-			return;
236
-		}
234
+        if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
235
+            return;
236
+        }
237 237
 
238
-		$this->skip_taxes = true;
239
-	}
238
+        $this->skip_taxes = true;
239
+    }
240 240
 
241 241
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission taxes class
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 
34 34
 		// Validate VAT number.
35
-		$this->validate_vat( $submission );
35
+		$this->validate_vat($submission);
36 36
 
37
-		if ( $this->skip_taxes ) {
37
+		if ($this->skip_taxes) {
38 38
 			return;
39 39
 		}
40 40
 
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
41
+		foreach ($submission->get_items() as $item) {
42
+			$this->process_item_tax($item, $submission);
43 43
 		}
44 44
 
45 45
 		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
46
+		if ($submission->has_invoice()) {
47
+			$this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes);
48 48
 		}
49 49
 
50 50
 	}
@@ -56,26 +56,26 @@  discard block
 block discarded – undo
56 56
 	 * @param GetPaid_Form_Item $item
57 57
 	 * @param GetPaid_Payment_Form_Submission $submission
58 58
 	 */
59
-	public function process_item_tax( $item, $submission ) {
59
+	public function process_item_tax($item, $submission) {
60 60
 
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item, true ), $rates );
61
+		$rates    = getpaid_get_item_tax_rates($item, $submission->country, $submission->state);
62
+		$rates    = getpaid_filter_item_tax_rates($item, $rates);
63
+		$taxes    = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, false), $rates);
64
+		$r_taxes  = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item, true), $rates);
65 65
 
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
66
+		foreach ($taxes as $name => $amount) {
67
+			$recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0;
68
+			$tax       = getpaid_prepare_item_tax($item, $name, $amount, $recurring);
69 69
 
70
-			$item->item_tax += wpinv_sanitize_amount( $tax['initial_tax'] );
70
+			$item->item_tax += wpinv_sanitize_amount($tax['initial_tax']);
71 71
 
72
-			if ( ! isset( $this->taxes[ $name ] ) ) {
73
-				$this->taxes[ $name ] = $tax;
72
+			if (!isset($this->taxes[$name])) {
73
+				$this->taxes[$name] = $tax;
74 74
 				continue;
75 75
 			}
76 76
 
77
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
78
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+			$this->taxes[$name]['initial_tax']   += $tax['initial_tax'];
78
+			$this->taxes[$name]['recurring_tax'] += $tax['recurring_tax'];
79 79
 
80 80
 		}
81 81
 
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
 	 * @since 1.0.19
89 89
 	 * @return bool
90 90
 	 */
91
-	public function has_digital_item( $submission ) {
91
+	public function has_digital_item($submission) {
92 92
 
93
-		foreach ( $submission->get_items() as $item ) {
93
+		foreach ($submission->get_items() as $item) {
94 94
 
95
-			if ( 'digital' == $item->get_vat_rule() ) {
95
+			if ('digital' == $item->get_vat_rule()) {
96 96
 				return true;
97 97
 			}
98 98
 
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 	 * @return bool
109 109
 	 */
110 110
 	public static function is_eu_store() {
111
-		return self::is_eu_country( wpinv_get_default_country() );
111
+		return self::is_eu_country(wpinv_get_default_country());
112 112
 	}
113 113
 
114 114
 	/**
@@ -118,8 +118,8 @@  discard block
 block discarded – undo
118 118
 	 * @since 1.0.19
119 119
 	 * @return bool
120 120
 	 */
121
-	public static function is_eu_country( $country ) {
122
-		return getpaid_is_eu_state( $country );
121
+	public static function is_eu_country($country) {
122
+		return getpaid_is_eu_state($country);
123 123
 	}
124 124
 
125 125
 	/**
@@ -129,8 +129,8 @@  discard block
 block discarded – undo
129 129
 	 * @since 1.0.19
130 130
 	 * @return bool
131 131
 	 */
132
-	public static function is_eu_transaction( $customer_country ) {
133
-		return self::is_eu_country( $customer_country ) && self::is_eu_store();
132
+	public static function is_eu_transaction($customer_country) {
133
+		return self::is_eu_country($customer_country) && self::is_eu_store();
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,12 +140,12 @@  discard block
 block discarded – undo
140 140
 	 * @since 1.0.19
141 141
 	 * @return string
142 142
 	 */
143
-	public function get_vat_number( $submission ) {
143
+	public function get_vat_number($submission) {
144 144
 
145 145
 		// Retrieve from the posted number.
146
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
147
-		if ( ! is_null( $vat_number ) ) {
148
-			return wpinv_clean( $vat_number );
146
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
147
+		if (!is_null($vat_number)) {
148
+			return wpinv_clean($vat_number);
149 149
 		}
150 150
 
151 151
 		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
@@ -158,12 +158,12 @@  discard block
 block discarded – undo
158 158
 	 * @since 1.0.19
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_company( $submission ) {
161
+	public function get_company($submission) {
162 162
 
163 163
 		// Retrieve from the posted data.
164
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
165
-		if ( ! empty( $company ) ) {
166
-			return wpinv_clean( $company );
164
+		$company = $submission->get_field('wpinv_company', 'billing');
165
+		if (!empty($company)) {
166
+			return wpinv_clean($company);
167 167
 		}
168 168
 
169 169
 		// Retrieve from the invoice.
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
 	 * @since 1.0.19
179 179
 	 * @return string
180 180
 	 */
181
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
+	public function requires_vat($ip_in_eu, $country_in_eu) {
182 182
 
183
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
184
-		$prevent_b2c = ! empty( $prevent_b2c );
183
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
184
+		$prevent_b2c = !empty($prevent_b2c);
185 185
 		$is_eu       = $ip_in_eu || $country_in_eu;
186 186
 
187 187
 		return $prevent_b2c && $is_eu;
@@ -193,45 +193,45 @@  discard block
 block discarded – undo
193 193
 	 * @param GetPaid_Payment_Form_Submission $submission
194 194
 	 * @since 1.0.19
195 195
 	 */
196
-	public function validate_vat( $submission ) {
196
+	public function validate_vat($submission) {
197 197
 
198
-		$in_eu = $this->is_eu_transaction( $submission->country );
198
+		$in_eu = $this->is_eu_transaction($submission->country);
199 199
 
200 200
 		// Abort if we are not validating vat numbers.
201
-		if ( ! $in_eu ) {
201
+		if (!$in_eu) {
202 202
             return;
203 203
 		}
204 204
 
205 205
 		// Prepare variables.
206
-		$vat_number  = $this->get_vat_number( $submission );
206
+		$vat_number  = $this->get_vat_number($submission);
207 207
 		$ip_country  = getpaid_get_ip_country();
208
-        $is_eu       = $this->is_eu_country( $submission->country );
209
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
208
+        $is_eu       = $this->is_eu_country($submission->country);
209
+        $is_ip_eu    = $this->is_eu_country($ip_country);
210 210
 
211 211
 		// Maybe abort early for initial fetches.
212
-		if ( $submission->is_initial_fetch() && empty( $vat_number ) ) {
212
+		if ($submission->is_initial_fetch() && empty($vat_number)) {
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		// If we're preventing business to consumer purchases,
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220 220
 			throw new Exception(
221
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
221
+				__('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')
222 222
 			);
223 223
 
224 224
 		}
225 225
 
226
-		if ( empty( $vat_number ) ) {
226
+		if (empty($vat_number)) {
227 227
 			return;
228 228
 		}
229 229
 
230
-		if ( wpinv_should_validate_vat_number() && ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
231
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
230
+		if (wpinv_should_validate_vat_number() && !wpinv_validate_vat_number($vat_number, $submission->country)) {
231
+			throw new Exception(__('Your VAT number is invalid', 'invoicing'));
232 232
 		}
233 233
 
234
-		if (  wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option( 'vat_same_country_rule', 'vat_too' ) ) {
234
+		if (wpinv_default_billing_country() == $submission->country && 'vat_too' == wpinv_get_option('vat_same_country_rule', 'vat_too')) {
235 235
 			return;
236 236
 		}
237 237
 
Please login to merge, or discard this patch.