Passed
Push — master ( 578d12...5023d9 )
by Brian
04:33
created
includes/wpinv-subscription.php 2 patches
Indentation   +1006 added lines, -1006 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 ( ! empty( $subscription->id ) ) {
80
-			$this->set_id( $subscription->id );
81
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_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 ( ! empty( $subscription->id ) ) {
80
+            $this->set_id( $subscription->id );
81
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_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
-	/*
180
+    /*
181 181
 	|--------------------------------------------------------------------------
182 182
 	| Getters
183 183
 	|--------------------------------------------------------------------------
184 184
 	*/
185 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
-	 */
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 226
     public function get_parent_payment_id( $context = 'view' ) {
227 227
         return $this->get_parent_invoice_id( $context );
228
-	}
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
+    }
229 606
 
230
-	/**
231
-     * Alias for self::get_parent_invoice_id().
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
232 609
      *
233
-     * @since  1.0.0
234
-     * @return int
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
235 612
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
238 615
     }
239 616
 
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 );
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 );
405 625
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $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
+            return;
408 629
         }
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 630
 
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
-	*/
631
+        $this->set_prop( 'created', '' );
505 632
 
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
-	}
633
+    }
535 634
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
635
+    /**
636
+     * Alias for self::set_created().
538 637
      *
539 638
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
639
+     * @param string $value strtotime compliant date.
541 640
      */
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 ) {
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
643
+    }
644
+
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 ) {
624 652
         $date = strtotime( $value );
625 653
 
626 654
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
628 656
             return;
629 657
         }
630 658
 
631
-		$this->set_prop( 'created', '' );
659
+        $this->set_prop( 'expiration', '' );
660
+
661
+    }
632 662
 
633
-	}
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
+    }
634 672
 
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 );
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 );
643 681
     }
644 682
 
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 );
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 ) {
653 690
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
656 693
             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
-	/*
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
+    /*
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,15 +811,15 @@  discard block
 block discarded – undo
811 811
      */
812 812
     public function get_child_payments() {
813 813
         return get_posts(
814
-			array(
815
-            	'post_parent'    => $this->get_parent_payment_id(),
816
-            	'numberposts'    => -1,
817
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
818
-            	'orderby'        => 'ID',
819
-            	'order'          => 'DESC',
820
-            	'post_type'      => 'wpi_invoice'
821
-			)
822
-		);
814
+            array(
815
+                'post_parent'    => $this->get_parent_payment_id(),
816
+                'numberposts'    => -1,
817
+                'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
818
+                'orderby'        => 'ID',
819
+                'order'          => 'DESC',
820
+                'post_type'      => 'wpi_invoice'
821
+            )
822
+        );
823 823
     }
824 824
 
825 825
     /**
@@ -829,16 +829,16 @@  discard block
 block discarded – undo
829 829
      * @return int
830 830
      */
831 831
     public function get_total_payments() {
832
-		global $wpdb;
832
+        global $wpdb;
833 833
 
834
-		$count = (int) $wpdb->get_var(
835
-			$wpdb->prepare(
836
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
837
-				$this->get_parent_invoice_id()
838
-			)
839
-		);
834
+        $count = (int) $wpdb->get_var(
835
+            $wpdb->prepare(
836
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
837
+                $this->get_parent_invoice_id()
838
+            )
839
+        );
840 840
 
841
-		// Maybe include parent invoice.
841
+        // Maybe include parent invoice.
842 842
         if ( $this->get_parent_payment()->is_paid() ) {
843 843
             $count++;
844 844
         }
@@ -867,57 +867,57 @@  discard block
 block discarded – undo
867 867
      *
868 868
      * @since  2.4
869 869
      * @param  array $args Array of values for the payment, including amount and transaction ID
870
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
870
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873 873
     public function add_payment( $args = array(), $invoice = false ) {
874 874
 
875
-		// Process each payment once.
875
+        // Process each payment once.
876 876
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
877 877
             return false;
878 878
         }
879 879
 
880
-		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
882
-			$invoice = $this->create_payment();
880
+        // Are we creating a new invoice?
881
+        if ( empty( $invoice ) ) {
882
+            $invoice = $this->create_payment();
883 883
 
884
-			if ( empty( $invoice ) ) {
885
-				return false;
886
-			}
884
+            if ( empty( $invoice ) ) {
885
+                return false;
886
+            }
887 887
 
888
-			$invoice->set_status( 'wpi-renewal' );
888
+            $invoice->set_status( 'wpi-renewal' );
889 889
 
890
-		}
890
+        }
891 891
 
892
-		// Maybe set a transaction id.
893
-		if ( ! empty( $args['transaction_id'] ) ) {
894
-			$invoice->set_transaction_id( $args['transaction_id'] );
895
-		}
892
+        // Maybe set a transaction id.
893
+        if ( ! empty( $args['transaction_id'] ) ) {
894
+            $invoice->set_transaction_id( $args['transaction_id'] );
895
+        }
896 896
 
897
-		// Set the completed date.
898
-		$invoice->set_completed_date( current_time( 'mysql' ) );
897
+        // Set the completed date.
898
+        $invoice->set_completed_date( current_time( 'mysql' ) );
899 899
 
900
-		// And the gateway.
901
-		if ( ! empty( $args['gateway'] ) ) {
902
-			$invoice->set_gateway( $args['gateway'] );
903
-		}
900
+        // And the gateway.
901
+        if ( ! empty( $args['gateway'] ) ) {
902
+            $invoice->set_gateway( $args['gateway'] );
903
+        }
904 904
 
905
-		$invoice->save();
905
+        $invoice->save();
906 906
 
907
-		if ( ! $invoice->get_id() ) {
908
-			return 0;
909
-		}
907
+        if ( ! $invoice->get_id() ) {
908
+            return 0;
909
+        }
910 910
 
911
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
912
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
911
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
912
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
913 913
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
914 914
 
915 915
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
916 916
 
917 917
         return $invoice->get_id();
918
-	}
918
+    }
919 919
 
920
-	/**
920
+    /**
921 921
      * Creates a new invoice and returns it.
922 922
      *
923 923
      * @since  1.0.19
@@ -925,104 +925,104 @@  discard block
 block discarded – undo
925 925
      */
926 926
     public function create_payment() {
927 927
 
928
-		$parent_invoice = $this->get_parent_payment();
929
-
930
-		if ( ! $parent_invoice->get_id() ) {
931
-			return false;
932
-		}
933
-
934
-		// Duplicate the parent invoice.
935
-		$invoice = new WPInv_Invoice();
936
-		$invoice->set_props( $parent_invoice->get_data() );
937
-		$invoice->set_id( 0 );
938
-		$invoice->set_items( $parent_invoice->get_items() );
939
-		$invoice->set_parent_id( $parent_invoice->get_id() );
940
-		$invoice->set_transaction_id( '' );
941
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
942
-		$invoice->set_number( '' );
943
-		$invoice->set_completed_date( '' );
944
-		$invoice->set_status( 'wpi-pending' );
945
-		$invoice->recalculate_total();
946
-		$invoice->save();
947
-
948
-		return $invoice->get_id() ? $invoice : false;
949
-    }
950
-
951
-	/**
952
-	 * Renews or completes a subscription
953
-	 *
954
-	 * @since  1.0.0
955
-	 * @return int The subscription's id
956
-	 */
957
-	public function renew() {
958
-
959
-		// Complete subscription if applicable
960
-		if ( $this->is_last_renewal() ) {
961
-			return $this->complete();
962
-		}
963
-
964
-		// Calculate new expiration
965
-		$frequency      = $this->get_frequency();
966
-		$period         = $this->get_period();
967
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
968
-
969
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
970
-		$this->set_status( 'active' );
971
-		return $this->save();
972
-
973
-		do_action( 'getpaid_subscription_renewed', $this );
974
-
975
-	}
976
-
977
-	/**
978
-	 * Marks a subscription as completed
979
-	 *
980
-	 * Subscription is completed when the number of payments matches the billing_times field
981
-	 *
982
-	 * @since  1.0.0
983
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
984
-	 */
985
-	public function complete() {
986
-
987
-		// Only mark a subscription as complete if it's not already cancelled.
988
-		if ( $this->has_status( 'cancelled' ) ) {
989
-			return false;
990
-		}
991
-
992
-		$this->set_status( 'completed' );
993
-		return $this->save();
994
-
995
-	}
996
-
997
-	/**
998
-	 * Marks a subscription as expired
999
-	 *
1000
-	 * @since  1.0.0
1001
-	 * @param  bool $check_expiration
1002
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1003
-	 */
1004
-	public function expire( $check_expiration = false ) {
1005
-
1006
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1007
-			// Do not mark as expired since real expiration date is in the future
1008
-			return false;
1009
-		}
1010
-
1011
-		$this->set_status( 'expired' );
1012
-		return $this->save();
1013
-
1014
-	}
1015
-
1016
-	/**
1017
-	 * Marks a subscription as failing
1018
-	 *
1019
-	 * @since  2.4.2
1020
-	 * @return int Subscription id.
1021
-	 */
1022
-	public function failing() {
1023
-		$this->set_status( 'failing' );
1024
-		return $this->save();
1025
-	}
928
+        $parent_invoice = $this->get_parent_payment();
929
+
930
+        if ( ! $parent_invoice->get_id() ) {
931
+            return false;
932
+        }
933
+
934
+        // Duplicate the parent invoice.
935
+        $invoice = new WPInv_Invoice();
936
+        $invoice->set_props( $parent_invoice->get_data() );
937
+        $invoice->set_id( 0 );
938
+        $invoice->set_items( $parent_invoice->get_items() );
939
+        $invoice->set_parent_id( $parent_invoice->get_id() );
940
+        $invoice->set_transaction_id( '' );
941
+        $invoice->set_key( $invoice->generate_key( 'renewal_' ) );
942
+        $invoice->set_number( '' );
943
+        $invoice->set_completed_date( '' );
944
+        $invoice->set_status( 'wpi-pending' );
945
+        $invoice->recalculate_total();
946
+        $invoice->save();
947
+
948
+        return $invoice->get_id() ? $invoice : false;
949
+    }
950
+
951
+    /**
952
+     * Renews or completes a subscription
953
+     *
954
+     * @since  1.0.0
955
+     * @return int The subscription's id
956
+     */
957
+    public function renew() {
958
+
959
+        // Complete subscription if applicable
960
+        if ( $this->is_last_renewal() ) {
961
+            return $this->complete();
962
+        }
963
+
964
+        // Calculate new expiration
965
+        $frequency      = $this->get_frequency();
966
+        $period         = $this->get_period();
967
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
968
+
969
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
970
+        $this->set_status( 'active' );
971
+        return $this->save();
972
+
973
+        do_action( 'getpaid_subscription_renewed', $this );
974
+
975
+    }
976
+
977
+    /**
978
+     * Marks a subscription as completed
979
+     *
980
+     * Subscription is completed when the number of payments matches the billing_times field
981
+     *
982
+     * @since  1.0.0
983
+     * @return int|bool Subscription id or false if the subscription is cancelled.
984
+     */
985
+    public function complete() {
986
+
987
+        // Only mark a subscription as complete if it's not already cancelled.
988
+        if ( $this->has_status( 'cancelled' ) ) {
989
+            return false;
990
+        }
991
+
992
+        $this->set_status( 'completed' );
993
+        return $this->save();
994
+
995
+    }
996
+
997
+    /**
998
+     * Marks a subscription as expired
999
+     *
1000
+     * @since  1.0.0
1001
+     * @param  bool $check_expiration
1002
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1003
+     */
1004
+    public function expire( $check_expiration = false ) {
1005
+
1006
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1007
+            // Do not mark as expired since real expiration date is in the future
1008
+            return false;
1009
+        }
1010
+
1011
+        $this->set_status( 'expired' );
1012
+        return $this->save();
1013
+
1014
+    }
1015
+
1016
+    /**
1017
+     * Marks a subscription as failing
1018
+     *
1019
+     * @since  2.4.2
1020
+     * @return int Subscription id.
1021
+     */
1022
+    public function failing() {
1023
+        $this->set_status( 'failing' );
1024
+        return $this->save();
1025
+    }
1026 1026
 
1027 1027
     /**
1028 1028
      * Marks a subscription as cancelled
@@ -1031,19 +1031,19 @@  discard block
 block discarded – undo
1031 1031
      * @return int Subscription id.
1032 1032
      */
1033 1033
     public function cancel() {
1034
-		$this->set_status( 'cancelled' );
1035
-		return $this->save();
1034
+        $this->set_status( 'cancelled' );
1035
+        return $this->save();
1036 1036
     }
1037 1037
 
1038
-	/**
1039
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1040
-	 *
1041
-	 * @since  1.0.0
1042
-	 * @return bool
1043
-	 */
1044
-	public function can_cancel() {
1045
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1046
-	}
1038
+    /**
1039
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1040
+     *
1041
+     * @since  1.0.0
1042
+     * @return bool
1043
+     */
1044
+    public function can_cancel() {
1045
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1046
+    }
1047 1047
 
1048 1048
     /**
1049 1049
      * Returns an array of subscription statuses that can be cancelled
@@ -1056,93 +1056,93 @@  discard block
 block discarded – undo
1056 1056
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1057 1057
     }
1058 1058
 
1059
-	/**
1060
-	 * Retrieves the URL to cancel subscription
1061
-	 *
1062
-	 * @since  1.0.0
1063
-	 * @return string
1064
-	 */
1065
-	public function get_cancel_url() {
1066
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1067
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1068
-	}
1069
-
1070
-	/**
1071
-	 * Retrieves the URL to view a subscription
1072
-	 *
1073
-	 * @since  1.0.19
1074
-	 * @return string
1075
-	 */
1076
-	public function get_view_url() {
1077
-		$url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1078
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1079
-	}
1080
-
1081
-	/**
1082
-	 * Determines if subscription can be manually renewed
1083
-	 *
1084
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1085
-	 * that can be renewed manually
1086
-	 *
1087
-	 * @since  2.5
1088
-	 * @return bool
1089
-	 */
1090
-	public function can_renew() {
1091
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1092
-	}
1093
-
1094
-	/**
1095
-	 * Retrieves the URL to renew a subscription
1096
-	 *
1097
-	 * @since  2.5
1098
-	 * @return string
1099
-	 */
1100
-	public function get_renew_url() {
1101
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1102
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1103
-	}
1104
-
1105
-	/**
1106
-	 * Determines if subscription can have their payment method updated
1107
-	 *
1108
-	 * @since  1.0.0
1109
-	 * @return bool
1110
-	 */
1111
-	public function can_update() {
1112
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1113
-	}
1114
-
1115
-	/**
1116
-	 * Retrieves the URL to update subscription
1117
-	 *
1118
-	 * @since  1.0.0
1119
-	 * @return string
1120
-	 */
1121
-	public function get_update_url() {
1122
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1123
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1124
-	}
1125
-
1126
-	/**
1127
-	 * Retrieves the subscription status label
1128
-	 *
1129
-	 * @since  1.0.0
1130
-	 * @return string
1131
-	 */
1132
-	public function get_status_label() {
1133
-		return getpaid_get_subscription_status_label( $this->get_status() );
1134
-	}
1135
-
1136
-	/**
1137
-	 * Retrieves the subscription status class
1138
-	 *
1139
-	 * @since  1.0.19
1140
-	 * @return string
1141
-	 */
1142
-	public function get_status_class() {
1143
-		$statuses = getpaid_get_subscription_status_classes();
1144
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1145
-	}
1059
+    /**
1060
+     * Retrieves the URL to cancel subscription
1061
+     *
1062
+     * @since  1.0.0
1063
+     * @return string
1064
+     */
1065
+    public function get_cancel_url() {
1066
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1067
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1068
+    }
1069
+
1070
+    /**
1071
+     * Retrieves the URL to view a subscription
1072
+     *
1073
+     * @since  1.0.19
1074
+     * @return string
1075
+     */
1076
+    public function get_view_url() {
1077
+        $url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1078
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1079
+    }
1080
+
1081
+    /**
1082
+     * Determines if subscription can be manually renewed
1083
+     *
1084
+     * This method is filtered by payment gateways in order to return true on subscriptions
1085
+     * that can be renewed manually
1086
+     *
1087
+     * @since  2.5
1088
+     * @return bool
1089
+     */
1090
+    public function can_renew() {
1091
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1092
+    }
1093
+
1094
+    /**
1095
+     * Retrieves the URL to renew a subscription
1096
+     *
1097
+     * @since  2.5
1098
+     * @return string
1099
+     */
1100
+    public function get_renew_url() {
1101
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1102
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1103
+    }
1104
+
1105
+    /**
1106
+     * Determines if subscription can have their payment method updated
1107
+     *
1108
+     * @since  1.0.0
1109
+     * @return bool
1110
+     */
1111
+    public function can_update() {
1112
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1113
+    }
1114
+
1115
+    /**
1116
+     * Retrieves the URL to update subscription
1117
+     *
1118
+     * @since  1.0.0
1119
+     * @return string
1120
+     */
1121
+    public function get_update_url() {
1122
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1123
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1124
+    }
1125
+
1126
+    /**
1127
+     * Retrieves the subscription status label
1128
+     *
1129
+     * @since  1.0.0
1130
+     * @return string
1131
+     */
1132
+    public function get_status_label() {
1133
+        return getpaid_get_subscription_status_label( $this->get_status() );
1134
+    }
1135
+
1136
+    /**
1137
+     * Retrieves the subscription status class
1138
+     *
1139
+     * @since  1.0.19
1140
+     * @return string
1141
+     */
1142
+    public function get_status_class() {
1143
+        $statuses = getpaid_get_subscription_status_classes();
1144
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1145
+    }
1146 1146
 
1147 1147
     /**
1148 1148
      * Retrieves the subscription status label
@@ -1152,11 +1152,11 @@  discard block
 block discarded – undo
1152 1152
      */
1153 1153
     public function get_status_label_html() {
1154 1154
 
1155
-		$status_label = sanitize_text_field( $this->get_status_label() );
1156
-		$class        = esc_attr( $this->get_status_class() );
1157
-		$status       = sanitize_html_class( $this->get_status_label() );
1155
+        $status_label = sanitize_text_field( $this->get_status_label() );
1156
+        $class        = esc_attr( $this->get_status_class() );
1157
+        $status       = sanitize_html_class( $this->get_status_label() );
1158 1158
 
1159
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1159
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1160 1160
     }
1161 1161
 
1162 1162
     /**
@@ -1167,75 +1167,75 @@  discard block
 block discarded – undo
1167 1167
      * @return bool
1168 1168
      */
1169 1169
     public function payment_exists( $txn_id = '' ) {
1170
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1170
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1171 1171
         return ! empty( $invoice_id );
1172
-	}
1173
-
1174
-	/**
1175
-	 * Handle the status transition.
1176
-	 */
1177
-	protected function status_transition() {
1178
-		$status_transition = $this->status_transition;
1179
-
1180
-		// Reset status transition variable.
1181
-		$this->status_transition = false;
1182
-
1183
-		if ( $status_transition ) {
1184
-			try {
1185
-
1186
-				// Fire a hook for the status change.
1187
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1188
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1189
-
1190
-				if ( ! empty( $status_transition['from'] ) ) {
1191
-
1192
-					/* translators: 1: old subscription status 2: new subscription status */
1193
-					$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'] ) );
1194
-
1195
-					// Note the transition occurred.
1196
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1197
-
1198
-					// Fire another hook.
1199
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1200
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1201
-
1202
-				} else {
1203
-					/* translators: %s: new invoice status */
1204
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1205
-
1206
-					// Note the transition occurred.
1207
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1208
-
1209
-				}
1210
-			} catch ( Exception $e ) {
1211
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1212
-			}
1213
-		}
1214
-
1215
-	}
1216
-
1217
-	/**
1218
-	 * Save data to the database.
1219
-	 *
1220
-	 * @since 1.0.19
1221
-	 * @return int subscription ID
1222
-	 */
1223
-	public function save() {
1224
-		parent::save();
1225
-		$this->status_transition();
1226
-		return $this->get_id();
1227
-	}
1228
-
1229
-	/**
1230
-	 * Activates a subscription.
1231
-	 *
1232
-	 * @since 1.0.19
1233
-	 * @return int subscription ID
1234
-	 */
1235
-	public function activate() {
1236
-		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1237
-		$this->set_status( $status );
1238
-		return $this->save();
1239
-	}
1172
+    }
1173
+
1174
+    /**
1175
+     * Handle the status transition.
1176
+     */
1177
+    protected function status_transition() {
1178
+        $status_transition = $this->status_transition;
1179
+
1180
+        // Reset status transition variable.
1181
+        $this->status_transition = false;
1182
+
1183
+        if ( $status_transition ) {
1184
+            try {
1185
+
1186
+                // Fire a hook for the status change.
1187
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1188
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1189
+
1190
+                if ( ! empty( $status_transition['from'] ) ) {
1191
+
1192
+                    /* translators: 1: old subscription status 2: new subscription status */
1193
+                    $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'] ) );
1194
+
1195
+                    // Note the transition occurred.
1196
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1197
+
1198
+                    // Fire another hook.
1199
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1200
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1201
+
1202
+                } else {
1203
+                    /* translators: %s: new invoice status */
1204
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1205
+
1206
+                    // Note the transition occurred.
1207
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1208
+
1209
+                }
1210
+            } catch ( Exception $e ) {
1211
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1212
+            }
1213
+        }
1214
+
1215
+    }
1216
+
1217
+    /**
1218
+     * Save data to the database.
1219
+     *
1220
+     * @since 1.0.19
1221
+     * @return int subscription ID
1222
+     */
1223
+    public function save() {
1224
+        parent::save();
1225
+        $this->status_transition();
1226
+        return $this->get_id();
1227
+    }
1228
+
1229
+    /**
1230
+     * Activates a subscription.
1231
+     *
1232
+     * @since 1.0.19
1233
+     * @return int subscription ID
1234
+     */
1235
+    public function activate() {
1236
+        $status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1237
+        $this->set_status( $status );
1238
+        return $this->save();
1239
+    }
1240 1240
 
1241 1241
 }
Please login to merge, or discard this patch.
Spacing   +220 added lines, -220 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 ( ! empty( $subscription->id ) ) {
80
-			$this->set_id( $subscription->id );
81
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_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 (!empty($subscription->id)) {
80
+			$this->set_id($subscription->id);
81
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_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
     /**
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
 			array(
815 815
             	'post_parent'    => $this->get_parent_payment_id(),
816 816
             	'numberposts'    => -1,
817
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
817
+            	'post_status'    => array('publish', 'wpi-processing', 'wpi-renewal'),
818 818
             	'orderby'        => 'ID',
819 819
             	'order'          => 'DESC',
820 820
             	'post_type'      => 'wpi_invoice'
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 		);
840 840
 
841 841
 		// Maybe include parent invoice.
842
-        if ( $this->get_parent_payment()->is_paid() ) {
842
+        if ($this->get_parent_payment()->is_paid()) {
843 843
             $count++;
844 844
         }
845 845
 
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
     public function get_times_billed() {
856 856
         $times_billed = $this->get_total_payments();
857 857
 
858
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
858
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
859 859
             $times_billed--;
860 860
         }
861 861
 
@@ -870,49 +870,49 @@  discard block
 block discarded – undo
870 870
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873
-    public function add_payment( $args = array(), $invoice = false ) {
873
+    public function add_payment($args = array(), $invoice = false) {
874 874
 
875 875
 		// Process each payment once.
876
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
876
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
877 877
             return false;
878 878
         }
879 879
 
880 880
 		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
881
+		if (empty($invoice)) {
882 882
 			$invoice = $this->create_payment();
883 883
 
884
-			if ( empty( $invoice ) ) {
884
+			if (empty($invoice)) {
885 885
 				return false;
886 886
 			}
887 887
 
888
-			$invoice->set_status( 'wpi-renewal' );
888
+			$invoice->set_status('wpi-renewal');
889 889
 
890 890
 		}
891 891
 
892 892
 		// Maybe set a transaction id.
893
-		if ( ! empty( $args['transaction_id'] ) ) {
894
-			$invoice->set_transaction_id( $args['transaction_id'] );
893
+		if (!empty($args['transaction_id'])) {
894
+			$invoice->set_transaction_id($args['transaction_id']);
895 895
 		}
896 896
 
897 897
 		// Set the completed date.
898
-		$invoice->set_completed_date( current_time( 'mysql' ) );
898
+		$invoice->set_completed_date(current_time('mysql'));
899 899
 
900 900
 		// And the gateway.
901
-		if ( ! empty( $args['gateway'] ) ) {
902
-			$invoice->set_gateway( $args['gateway'] );
901
+		if (!empty($args['gateway'])) {
902
+			$invoice->set_gateway($args['gateway']);
903 903
 		}
904 904
 
905 905
 		$invoice->save();
906 906
 
907
-		if ( ! $invoice->get_id() ) {
907
+		if (!$invoice->get_id()) {
908 908
 			return 0;
909 909
 		}
910 910
 
911
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
912
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
913
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
911
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
912
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
913
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
914 914
 
915
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
915
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
916 916
 
917 917
         return $invoice->get_id();
918 918
 	}
@@ -927,21 +927,21 @@  discard block
 block discarded – undo
927 927
 
928 928
 		$parent_invoice = $this->get_parent_payment();
929 929
 
930
-		if ( ! $parent_invoice->get_id() ) {
930
+		if (!$parent_invoice->get_id()) {
931 931
 			return false;
932 932
 		}
933 933
 
934 934
 		// Duplicate the parent invoice.
935 935
 		$invoice = new WPInv_Invoice();
936
-		$invoice->set_props( $parent_invoice->get_data() );
937
-		$invoice->set_id( 0 );
938
-		$invoice->set_items( $parent_invoice->get_items() );
939
-		$invoice->set_parent_id( $parent_invoice->get_id() );
940
-		$invoice->set_transaction_id( '' );
941
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
942
-		$invoice->set_number( '' );
943
-		$invoice->set_completed_date( '' );
944
-		$invoice->set_status( 'wpi-pending' );
936
+		$invoice->set_props($parent_invoice->get_data());
937
+		$invoice->set_id(0);
938
+		$invoice->set_items($parent_invoice->get_items());
939
+		$invoice->set_parent_id($parent_invoice->get_id());
940
+		$invoice->set_transaction_id('');
941
+		$invoice->set_key($invoice->generate_key('renewal_'));
942
+		$invoice->set_number('');
943
+		$invoice->set_completed_date('');
944
+		$invoice->set_status('wpi-pending');
945 945
 		$invoice->recalculate_total();
946 946
 		$invoice->save();
947 947
 
@@ -957,20 +957,20 @@  discard block
 block discarded – undo
957 957
 	public function renew() {
958 958
 
959 959
 		// Complete subscription if applicable
960
-		if ( $this->is_last_renewal() ) {
960
+		if ($this->is_last_renewal()) {
961 961
 			return $this->complete();
962 962
 		}
963 963
 
964 964
 		// Calculate new expiration
965 965
 		$frequency      = $this->get_frequency();
966 966
 		$period         = $this->get_period();
967
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
967
+		$new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time());
968 968
 
969
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
970
-		$this->set_status( 'active' );
969
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
970
+		$this->set_status('active');
971 971
 		return $this->save();
972 972
 
973
-		do_action( 'getpaid_subscription_renewed', $this );
973
+		do_action('getpaid_subscription_renewed', $this);
974 974
 
975 975
 	}
976 976
 
@@ -985,11 +985,11 @@  discard block
 block discarded – undo
985 985
 	public function complete() {
986 986
 
987 987
 		// Only mark a subscription as complete if it's not already cancelled.
988
-		if ( $this->has_status( 'cancelled' ) ) {
988
+		if ($this->has_status('cancelled')) {
989 989
 			return false;
990 990
 		}
991 991
 
992
-		$this->set_status( 'completed' );
992
+		$this->set_status('completed');
993 993
 		return $this->save();
994 994
 
995 995
 	}
@@ -1001,14 +1001,14 @@  discard block
 block discarded – undo
1001 1001
 	 * @param  bool $check_expiration
1002 1002
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1003 1003
 	 */
1004
-	public function expire( $check_expiration = false ) {
1004
+	public function expire($check_expiration = false) {
1005 1005
 
1006
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1006
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1007 1007
 			// Do not mark as expired since real expiration date is in the future
1008 1008
 			return false;
1009 1009
 		}
1010 1010
 
1011
-		$this->set_status( 'expired' );
1011
+		$this->set_status('expired');
1012 1012
 		return $this->save();
1013 1013
 
1014 1014
 	}
@@ -1020,7 +1020,7 @@  discard block
 block discarded – undo
1020 1020
 	 * @return int Subscription id.
1021 1021
 	 */
1022 1022
 	public function failing() {
1023
-		$this->set_status( 'failing' );
1023
+		$this->set_status('failing');
1024 1024
 		return $this->save();
1025 1025
 	}
1026 1026
 
@@ -1031,7 +1031,7 @@  discard block
 block discarded – undo
1031 1031
      * @return int Subscription id.
1032 1032
      */
1033 1033
     public function cancel() {
1034
-		$this->set_status( 'cancelled' );
1034
+		$this->set_status('cancelled');
1035 1035
 		return $this->save();
1036 1036
     }
1037 1037
 
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
 	 * @return bool
1043 1043
 	 */
1044 1044
 	public function can_cancel() {
1045
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1045
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1046 1046
 	}
1047 1047
 
1048 1048
     /**
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
      * @return      array
1054 1054
      */
1055 1055
     public function get_cancellable_statuses() {
1056
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1056
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1057 1057
     }
1058 1058
 
1059 1059
 	/**
@@ -1063,8 +1063,8 @@  discard block
 block discarded – undo
1063 1063
 	 * @return string
1064 1064
 	 */
1065 1065
 	public function get_cancel_url() {
1066
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1067
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1066
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1067
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1068 1068
 	}
1069 1069
 
1070 1070
 	/**
@@ -1074,8 +1074,8 @@  discard block
 block discarded – undo
1074 1074
 	 * @return string
1075 1075
 	 */
1076 1076
 	public function get_view_url() {
1077
-		$url = add_query_arg( 'subscription', $this->get_id(), get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1078
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1077
+		$url = add_query_arg('subscription', $this->get_id(), get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1078
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1079 1079
 	}
1080 1080
 
1081 1081
 	/**
@@ -1088,7 +1088,7 @@  discard block
 block discarded – undo
1088 1088
 	 * @return bool
1089 1089
 	 */
1090 1090
 	public function can_renew() {
1091
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1091
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1092 1092
 	}
1093 1093
 
1094 1094
 	/**
@@ -1098,8 +1098,8 @@  discard block
 block discarded – undo
1098 1098
 	 * @return string
1099 1099
 	 */
1100 1100
 	public function get_renew_url() {
1101
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1102
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1101
+		$url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce');
1102
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1103 1103
 	}
1104 1104
 
1105 1105
 	/**
@@ -1109,7 +1109,7 @@  discard block
 block discarded – undo
1109 1109
 	 * @return bool
1110 1110
 	 */
1111 1111
 	public function can_update() {
1112
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1112
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1113 1113
 	}
1114 1114
 
1115 1115
 	/**
@@ -1119,8 +1119,8 @@  discard block
 block discarded – undo
1119 1119
 	 * @return string
1120 1120
 	 */
1121 1121
 	public function get_update_url() {
1122
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1123
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1122
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id()));
1123
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1124 1124
 	}
1125 1125
 
1126 1126
 	/**
@@ -1130,7 +1130,7 @@  discard block
 block discarded – undo
1130 1130
 	 * @return string
1131 1131
 	 */
1132 1132
 	public function get_status_label() {
1133
-		return getpaid_get_subscription_status_label( $this->get_status() );
1133
+		return getpaid_get_subscription_status_label($this->get_status());
1134 1134
 	}
1135 1135
 
1136 1136
 	/**
@@ -1141,7 +1141,7 @@  discard block
 block discarded – undo
1141 1141
 	 */
1142 1142
 	public function get_status_class() {
1143 1143
 		$statuses = getpaid_get_subscription_status_classes();
1144
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1144
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'text-white bg-secondary';
1145 1145
 	}
1146 1146
 
1147 1147
     /**
@@ -1152,9 +1152,9 @@  discard block
 block discarded – undo
1152 1152
      */
1153 1153
     public function get_status_label_html() {
1154 1154
 
1155
-		$status_label = sanitize_text_field( $this->get_status_label() );
1156
-		$class        = esc_attr( $this->get_status_class() );
1157
-		$status       = sanitize_html_class( $this->get_status_label() );
1155
+		$status_label = sanitize_text_field($this->get_status_label());
1156
+		$class        = esc_attr($this->get_status_class());
1157
+		$status       = sanitize_html_class($this->get_status_label());
1158 1158
 
1159 1159
 		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded $class $status'>$status_label</span></span>";
1160 1160
     }
@@ -1166,9 +1166,9 @@  discard block
 block discarded – undo
1166 1166
      * @param  string $txn_id The transaction ID from the merchant processor
1167 1167
      * @return bool
1168 1168
      */
1169
-    public function payment_exists( $txn_id = '' ) {
1170
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1171
-        return ! empty( $invoice_id );
1169
+    public function payment_exists($txn_id = '') {
1170
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1171
+        return !empty($invoice_id);
1172 1172
 	}
1173 1173
 
1174 1174
 	/**
@@ -1180,35 +1180,35 @@  discard block
 block discarded – undo
1180 1180
 		// Reset status transition variable.
1181 1181
 		$this->status_transition = false;
1182 1182
 
1183
-		if ( $status_transition ) {
1183
+		if ($status_transition) {
1184 1184
 			try {
1185 1185
 
1186 1186
 				// Fire a hook for the status change.
1187
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1188
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1187
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1188
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1189 1189
 
1190
-				if ( ! empty( $status_transition['from'] ) ) {
1190
+				if (!empty($status_transition['from'])) {
1191 1191
 
1192 1192
 					/* translators: 1: old subscription status 2: new subscription status */
1193
-					$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'] ) );
1193
+					$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']));
1194 1194
 
1195 1195
 					// Note the transition occurred.
1196
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1196
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1197 1197
 
1198 1198
 					// Fire another hook.
1199
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1200
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1199
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1200
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1201 1201
 
1202 1202
 				} else {
1203 1203
 					/* translators: %s: new invoice status */
1204
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1204
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1205 1205
 
1206 1206
 					// Note the transition occurred.
1207
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1207
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1208 1208
 
1209 1209
 				}
1210
-			} catch ( Exception $e ) {
1211
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1210
+			} catch (Exception $e) {
1211
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1212 1212
 			}
1213 1213
 		}
1214 1214
 
@@ -1234,7 +1234,7 @@  discard block
 block discarded – undo
1234 1234
 	 */
1235 1235
 	public function activate() {
1236 1236
 		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1237
-		$this->set_status( $status );
1237
+		$this->set_status($status);
1238 1238
 		return $this->save();
1239 1239
 	}
1240 1240
 
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 2 patches
Indentation   +2332 added lines, -2332 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 class WPInv_Invoice extends GetPaid_Data {
15 15
 
16 16
     /**
17
-	 * Which data store to load.
18
-	 *
19
-	 * @var string
20
-	 */
17
+     * Which data store to load.
18
+     *
19
+     * @var string
20
+     */
21 21
     protected $data_store_name = 'invoice';
22 22
 
23 23
     /**
24
-	 * This is the name of this object type.
25
-	 *
26
-	 * @var string
27
-	 */
24
+     * This is the name of this object type.
25
+     *
26
+     * @var string
27
+     */
28 28
     protected $object_type = 'invoice';
29 29
 
30 30
     /**
31
-	 * Item Data array. This is the core item data exposed in APIs.
32
-	 *
33
-	 * @since 1.0.19
34
-	 * @var array
35
-	 */
36
-	protected $data = array(
37
-		'parent_id'            => 0,
38
-		'status'               => 'wpi-pending',
39
-		'version'              => '',
40
-		'date_created'         => null,
31
+     * Item Data array. This is the core item data exposed in APIs.
32
+     *
33
+     * @since 1.0.19
34
+     * @var array
35
+     */
36
+    protected $data = array(
37
+        'parent_id'            => 0,
38
+        'status'               => 'wpi-pending',
39
+        'version'              => '',
40
+        'date_created'         => null,
41 41
         'date_modified'        => null,
42 42
         'due_date'             => null,
43 43
         'completed_date'       => null,
@@ -79,22 +79,22 @@  discard block
 block discarded – undo
79 79
         'transaction_id'       => '',
80 80
         'currency'             => '',
81 81
         'disable_taxes'        => false,
82
-		'subscription_id'      => null,
83
-		'remote_subscription_id' => null,
84
-		'is_viewed'            => false,
85
-		'email_cc'             => '',
86
-		'template'             => 'quantity', // hours, amount only
87
-		'created_via'          => null,
82
+        'subscription_id'      => null,
83
+        'remote_subscription_id' => null,
84
+        'is_viewed'            => false,
85
+        'email_cc'             => '',
86
+        'template'             => 'quantity', // hours, amount only
87
+        'created_via'          => null,
88 88
     );
89 89
 
90 90
     /**
91
-	 * Stores meta in cache for future reads.
92
-	 *
93
-	 * A group must be set to to enable caching.
94
-	 *
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = 'getpaid_invoices';
91
+     * Stores meta in cache for future reads.
92
+     *
93
+     * A group must be set to to enable caching.
94
+     *
95
+     * @var string
96
+     */
97
+    protected $cache_group = 'getpaid_invoices';
98 98
 
99 99
     /**
100 100
      * Stores a reference to the original WP_Post object
@@ -108,104 +108,104 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @var int
110 110
      */
111
-	protected $recurring_item = null;
111
+    protected $recurring_item = null;
112 112
 
113
-	/**
113
+    /**
114 114
      * Stores an array of item totals.
115
-	 *
116
-	 * e.g $totals['discount'] = array(
117
-	 * 		'initial'   => 10,
118
-	 * 		'recurring' => 10,
119
-	 * )
115
+     *
116
+     * e.g $totals['discount'] = array(
117
+     * 		'initial'   => 10,
118
+     * 		'recurring' => 10,
119
+     * )
120 120
      *
121 121
      * @var array
122 122
      */
123
-	protected $totals = array();
123
+    protected $totals = array();
124 124
 
125
-	/**
126
-	 * Stores the status transition information.
127
-	 *
128
-	 * @since 1.0.19
129
-	 * @var bool
130
-	 */
131
-	protected $status_transition = false;
125
+    /**
126
+     * Stores the status transition information.
127
+     *
128
+     * @since 1.0.19
129
+     * @var bool
130
+     */
131
+    protected $status_transition = false;
132 132
 
133 133
     /**
134
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
135
-	 *
136
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
137
-	 */
134
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
135
+     *
136
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
137
+     */
138 138
     public function __construct( $invoice = false ) {
139 139
 
140 140
         parent::__construct( $invoice );
141 141
 
142
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
143
-			$this->set_id( $invoice );
144
-		} elseif ( $invoice instanceof self ) {
145
-			$this->set_id( $invoice->get_id() );
146
-		} elseif ( ! empty( $invoice->ID ) ) {
147
-			$this->set_id( $invoice->ID );
148
-		} elseif ( is_array( $invoice ) ) {
149
-			$this->set_props( $invoice );
150
-
151
-			if ( isset( $invoice['ID'] ) ) {
152
-				$this->set_id( $invoice['ID'] );
153
-			}
154
-
155
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
156
-			$this->set_id( $invoice_id );
157
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
158
-			$this->set_id( $invoice_id );
159
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
160
-			$this->set_id( $invoice_id );
161
-		}else {
162
-			$this->set_object_read( true );
163
-		}
142
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
143
+            $this->set_id( $invoice );
144
+        } elseif ( $invoice instanceof self ) {
145
+            $this->set_id( $invoice->get_id() );
146
+        } elseif ( ! empty( $invoice->ID ) ) {
147
+            $this->set_id( $invoice->ID );
148
+        } elseif ( is_array( $invoice ) ) {
149
+            $this->set_props( $invoice );
150
+
151
+            if ( isset( $invoice['ID'] ) ) {
152
+                $this->set_id( $invoice['ID'] );
153
+            }
154
+
155
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
156
+            $this->set_id( $invoice_id );
157
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
158
+            $this->set_id( $invoice_id );
159
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
160
+            $this->set_id( $invoice_id );
161
+        }else {
162
+            $this->set_object_read( true );
163
+        }
164 164
 
165 165
         // Load the datastore.
166
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
166
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
167 167
 
168
-		if ( $this->get_id() > 0 ) {
168
+        if ( $this->get_id() > 0 ) {
169 169
             $this->post = get_post( $this->get_id() );
170 170
             $this->ID   = $this->get_id();
171
-			$this->data_store->read( $this );
171
+            $this->data_store->read( $this );
172 172
         }
173 173
 
174 174
     }
175 175
 
176 176
     /**
177
-	 * Given an invoice key/number, it returns its id.
178
-	 *
179
-	 *
180
-	 * @static
181
-	 * @param string $value The invoice key or number
182
-	 * @param string $field Either key, transaction_id or number.
183
-	 * @since 1.0.15
184
-	 * @return int
185
-	 */
186
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
177
+     * Given an invoice key/number, it returns its id.
178
+     *
179
+     *
180
+     * @static
181
+     * @param string $value The invoice key or number
182
+     * @param string $field Either key, transaction_id or number.
183
+     * @since 1.0.15
184
+     * @return int
185
+     */
186
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
187 187
         global $wpdb;
188 188
 
189
-		// Trim the value.
190
-		$value = trim( $value );
189
+        // Trim the value.
190
+        $value = trim( $value );
191 191
 
192
-		if ( empty( $value ) ) {
193
-			return 0;
194
-		}
192
+        if ( empty( $value ) ) {
193
+            return 0;
194
+        }
195 195
 
196 196
         // Valid fields.
197 197
         $fields = array( 'key', 'number', 'transaction_id' );
198 198
 
199
-		// Ensure a field has been passed.
200
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
201
-			return 0;
202
-		}
199
+        // Ensure a field has been passed.
200
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
201
+            return 0;
202
+        }
203 203
 
204
-		// Maybe retrieve from the cache.
205
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
206
-		if ( false !== $invoice_id ) {
207
-			return $invoice_id;
208
-		}
204
+        // Maybe retrieve from the cache.
205
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
206
+        if ( false !== $invoice_id ) {
207
+            return $invoice_id;
208
+        }
209 209
 
210 210
         // Fetch from the db.
211 211
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
214 214
         );
215 215
 
216
-		// Update the cache with our data
217
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
216
+        // Update the cache with our data
217
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
218 218
 
219
-		return $invoice_id;
219
+        return $invoice_id;
220 220
     }
221 221
 
222 222
     /**
@@ -242,80 +242,80 @@  discard block
 block discarded – undo
242 242
     */
243 243
 
244 244
     /**
245
-	 * Get parent invoice ID.
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return int
250
-	 */
251
-	public function get_parent_id( $context = 'view' ) {
252
-		return (int) $this->get_prop( 'parent_id', $context );
245
+     * Get parent invoice ID.
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return int
250
+     */
251
+    public function get_parent_id( $context = 'view' ) {
252
+        return (int) $this->get_prop( 'parent_id', $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Get parent invoice.
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @return WPInv_Invoice
260
-	 */
256
+     * Get parent invoice.
257
+     *
258
+     * @since 1.0.19
259
+     * @return WPInv_Invoice
260
+     */
261 261
     public function get_parent_payment() {
262 262
         return new WPInv_Invoice( $this->get_parent_id() );
263 263
     }
264 264
 
265 265
     /**
266
-	 * Alias for self::get_parent_payment().
267
-	 *
268
-	 * @since 1.0.19
269
-	 * @return WPInv_Invoice
270
-	 */
266
+     * Alias for self::get_parent_payment().
267
+     *
268
+     * @since 1.0.19
269
+     * @return WPInv_Invoice
270
+     */
271 271
     public function get_parent() {
272 272
         return $this->get_parent_payment();
273 273
     }
274 274
 
275 275
     /**
276
-	 * Get invoice status.
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @param  string $context View or edit context.
280
-	 * @return string
281
-	 */
282
-	public function get_status( $context = 'view' ) {
283
-		return $this->get_prop( 'status', $context );
284
-	}
276
+     * Get invoice status.
277
+     *
278
+     * @since 1.0.19
279
+     * @param  string $context View or edit context.
280
+     * @return string
281
+     */
282
+    public function get_status( $context = 'view' ) {
283
+        return $this->get_prop( 'status', $context );
284
+    }
285 285
 	
286
-	/**
287
-	 * Retrieves an array of possible invoice statuses.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @return array
291
-	 */
292
-	public function get_all_statuses() {
293
-
294
-		$statuses = wpinv_get_invoice_statuses( true, true, $this );
295
-
296
-		// For backwards compatibility.
297
-		if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
286
+    /**
287
+     * Retrieves an array of possible invoice statuses.
288
+     *
289
+     * @since 1.0.19
290
+     * @return array
291
+     */
292
+    public function get_all_statuses() {
293
+
294
+        $statuses = wpinv_get_invoice_statuses( true, true, $this );
295
+
296
+        // For backwards compatibility.
297
+        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
298 298
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
299
-		}
299
+        }
300 300
 
301
-		return $statuses;
301
+        return $statuses;
302 302
     }
303 303
 
304 304
     /**
305
-	 * Get invoice status nice name.
306
-	 *
307
-	 * @since 1.0.19
308
-	 * @return string
309
-	 */
305
+     * Get invoice status nice name.
306
+     *
307
+     * @since 1.0.19
308
+     * @return string
309
+     */
310 310
     public function get_status_nicename() {
311
-		$statuses = $this->get_all_statuses();
311
+        $statuses = $this->get_all_statuses();
312 312
 
313 313
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
314 314
 
315 315
         return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
316 316
     }
317 317
 
318
-	/**
318
+    /**
319 319
      * Retrieves the invoice status label html
320 320
      *
321 321
      * @since  1.0.0
@@ -323,262 +323,262 @@  discard block
 block discarded – undo
323 323
      */
324 324
     public function get_status_label_html() {
325 325
 
326
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
327
-		$status       = sanitize_html_class( $this->get_status() );
326
+        $status_label = sanitize_text_field( $this->get_status_nicename() );
327
+        $status       = sanitize_html_class( $this->get_status() );
328 328
 
329
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
330
-	}
329
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
330
+    }
331 331
 
332 332
     /**
333
-	 * Get plugin version when the invoice was created.
334
-	 *
335
-	 * @since 1.0.19
336
-	 * @param  string $context View or edit context.
337
-	 * @return string
338
-	 */
339
-	public function get_version( $context = 'view' ) {
340
-		return $this->get_prop( 'version', $context );
341
-	}
333
+     * Get plugin version when the invoice was created.
334
+     *
335
+     * @since 1.0.19
336
+     * @param  string $context View or edit context.
337
+     * @return string
338
+     */
339
+    public function get_version( $context = 'view' ) {
340
+        return $this->get_prop( 'version', $context );
341
+    }
342 342
 
343
-	/**
344
-	 * @deprecated
345
-	 */
346
-	public function get_invoice_date( $format = true ) {
347
-		$date      = getpaid_format_date( $this->get_date_completed() );
348
-		$date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
349
-		$formatted = getpaid_format_date( $date );
343
+    /**
344
+     * @deprecated
345
+     */
346
+    public function get_invoice_date( $format = true ) {
347
+        $date      = getpaid_format_date( $this->get_date_completed() );
348
+        $date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
349
+        $formatted = getpaid_format_date( $date );
350 350
 
351
-		if ( $format ) {
352
-			return $formatted;
353
-		}
351
+        if ( $format ) {
352
+            return $formatted;
353
+        }
354 354
 
355
-		return empty( $formatted ) ? '' : $date;
355
+        return empty( $formatted ) ? '' : $date;
356 356
 
357 357
     }
358 358
 
359 359
     /**
360
-	 * Get date when the invoice was created.
361
-	 *
362
-	 * @since 1.0.19
363
-	 * @param  string $context View or edit context.
364
-	 * @return string
365
-	 */
366
-	public function get_date_created( $context = 'view' ) {
367
-		return $this->get_prop( 'date_created', $context );
368
-	}
360
+     * Get date when the invoice was created.
361
+     *
362
+     * @since 1.0.19
363
+     * @param  string $context View or edit context.
364
+     * @return string
365
+     */
366
+    public function get_date_created( $context = 'view' ) {
367
+        return $this->get_prop( 'date_created', $context );
368
+    }
369 369
 	
370
-	/**
371
-	 * Alias for self::get_date_created().
372
-	 *
373
-	 * @since 1.0.19
374
-	 * @param  string $context View or edit context.
375
-	 * @return string
376
-	 */
377
-	public function get_created_date( $context = 'view' ) {
378
-		return $this->get_date_created( $context );
379
-    }
380
-
381
-    /**
382
-	 * Get GMT date when the invoice was created.
383
-	 *
384
-	 * @since 1.0.19
385
-	 * @param  string $context View or edit context.
386
-	 * @return string
387
-	 */
388
-	public function get_date_created_gmt( $context = 'view' ) {
370
+    /**
371
+     * Alias for self::get_date_created().
372
+     *
373
+     * @since 1.0.19
374
+     * @param  string $context View or edit context.
375
+     * @return string
376
+     */
377
+    public function get_created_date( $context = 'view' ) {
378
+        return $this->get_date_created( $context );
379
+    }
380
+
381
+    /**
382
+     * Get GMT date when the invoice was created.
383
+     *
384
+     * @since 1.0.19
385
+     * @param  string $context View or edit context.
386
+     * @return string
387
+     */
388
+    public function get_date_created_gmt( $context = 'view' ) {
389 389
         $date = $this->get_date_created( $context );
390 390
 
391 391
         if ( $date ) {
392 392
             $date = get_gmt_from_date( $date );
393 393
         }
394
-		return $date;
394
+        return $date;
395 395
     }
396 396
 
397 397
     /**
398
-	 * Get date when the invoice was last modified.
399
-	 *
400
-	 * @since 1.0.19
401
-	 * @param  string $context View or edit context.
402
-	 * @return string
403
-	 */
404
-	public function get_date_modified( $context = 'view' ) {
405
-		return $this->get_prop( 'date_modified', $context );
406
-	}
398
+     * Get date when the invoice was last modified.
399
+     *
400
+     * @since 1.0.19
401
+     * @param  string $context View or edit context.
402
+     * @return string
403
+     */
404
+    public function get_date_modified( $context = 'view' ) {
405
+        return $this->get_prop( 'date_modified', $context );
406
+    }
407 407
 
408
-	/**
409
-	 * Alias for self::get_date_modified().
410
-	 *
411
-	 * @since 1.0.19
412
-	 * @param  string $context View or edit context.
413
-	 * @return string
414
-	 */
415
-	public function get_modified_date( $context = 'view' ) {
416
-		return $this->get_date_modified( $context );
408
+    /**
409
+     * Alias for self::get_date_modified().
410
+     *
411
+     * @since 1.0.19
412
+     * @param  string $context View or edit context.
413
+     * @return string
414
+     */
415
+    public function get_modified_date( $context = 'view' ) {
416
+        return $this->get_date_modified( $context );
417 417
     }
418 418
 
419 419
     /**
420
-	 * Get GMT date when the invoice was last modified.
421
-	 *
422
-	 * @since 1.0.19
423
-	 * @param  string $context View or edit context.
424
-	 * @return string
425
-	 */
426
-	public function get_date_modified_gmt( $context = 'view' ) {
420
+     * Get GMT date when the invoice was last modified.
421
+     *
422
+     * @since 1.0.19
423
+     * @param  string $context View or edit context.
424
+     * @return string
425
+     */
426
+    public function get_date_modified_gmt( $context = 'view' ) {
427 427
         $date = $this->get_date_modified( $context );
428 428
 
429 429
         if ( $date ) {
430 430
             $date = get_gmt_from_date( $date );
431 431
         }
432
-		return $date;
432
+        return $date;
433 433
     }
434 434
 
435 435
     /**
436
-	 * Get the invoice due date.
437
-	 *
438
-	 * @since 1.0.19
439
-	 * @param  string $context View or edit context.
440
-	 * @return string
441
-	 */
442
-	public function get_due_date( $context = 'view' ) {
443
-		return $this->get_prop( 'due_date', $context );
436
+     * Get the invoice due date.
437
+     *
438
+     * @since 1.0.19
439
+     * @param  string $context View or edit context.
440
+     * @return string
441
+     */
442
+    public function get_due_date( $context = 'view' ) {
443
+        return $this->get_prop( 'due_date', $context );
444 444
     }
445 445
 
446 446
     /**
447
-	 * Alias for self::get_due_date().
448
-	 *
449
-	 * @since 1.0.19
450
-	 * @param  string $context View or edit context.
451
-	 * @return string
452
-	 */
453
-	public function get_date_due( $context = 'view' ) {
454
-		return $this->get_due_date( $context );
447
+     * Alias for self::get_due_date().
448
+     *
449
+     * @since 1.0.19
450
+     * @param  string $context View or edit context.
451
+     * @return string
452
+     */
453
+    public function get_date_due( $context = 'view' ) {
454
+        return $this->get_due_date( $context );
455 455
     }
456 456
 
457 457
     /**
458
-	 * Get the invoice GMT due date.
459
-	 *
460
-	 * @since 1.0.19
461
-	 * @param  string $context View or edit context.
462
-	 * @return string
463
-	 */
464
-	public function get_due_date_gmt( $context = 'view' ) {
458
+     * Get the invoice GMT due date.
459
+     *
460
+     * @since 1.0.19
461
+     * @param  string $context View or edit context.
462
+     * @return string
463
+     */
464
+    public function get_due_date_gmt( $context = 'view' ) {
465 465
         $date = $this->get_due_date( $context );
466 466
 
467 467
         if ( $date ) {
468 468
             $date = get_gmt_from_date( $date );
469 469
         }
470
-		return $date;
470
+        return $date;
471 471
     }
472 472
 
473 473
     /**
474
-	 * Alias for self::get_due_date_gmt().
475
-	 *
476
-	 * @since 1.0.19
477
-	 * @param  string $context View or edit context.
478
-	 * @return string
479
-	 */
480
-	public function get_gmt_date_due( $context = 'view' ) {
481
-		return $this->get_due_date_gmt( $context );
474
+     * Alias for self::get_due_date_gmt().
475
+     *
476
+     * @since 1.0.19
477
+     * @param  string $context View or edit context.
478
+     * @return string
479
+     */
480
+    public function get_gmt_date_due( $context = 'view' ) {
481
+        return $this->get_due_date_gmt( $context );
482 482
     }
483 483
 
484 484
     /**
485
-	 * Get date when the invoice was completed.
486
-	 *
487
-	 * @since 1.0.19
488
-	 * @param  string $context View or edit context.
489
-	 * @return string
490
-	 */
491
-	public function get_completed_date( $context = 'view' ) {
492
-		return $this->get_prop( 'completed_date', $context );
485
+     * Get date when the invoice was completed.
486
+     *
487
+     * @since 1.0.19
488
+     * @param  string $context View or edit context.
489
+     * @return string
490
+     */
491
+    public function get_completed_date( $context = 'view' ) {
492
+        return $this->get_prop( 'completed_date', $context );
493 493
     }
494 494
 
495 495
     /**
496
-	 * Alias for self::get_completed_date().
497
-	 *
498
-	 * @since 1.0.19
499
-	 * @param  string $context View or edit context.
500
-	 * @return string
501
-	 */
502
-	public function get_date_completed( $context = 'view' ) {
503
-		return $this->get_completed_date( $context );
496
+     * Alias for self::get_completed_date().
497
+     *
498
+     * @since 1.0.19
499
+     * @param  string $context View or edit context.
500
+     * @return string
501
+     */
502
+    public function get_date_completed( $context = 'view' ) {
503
+        return $this->get_completed_date( $context );
504 504
     }
505 505
 
506 506
     /**
507
-	 * Get GMT date when the invoice was was completed.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  string $context View or edit context.
511
-	 * @return string
512
-	 */
513
-	public function get_completed_date_gmt( $context = 'view' ) {
507
+     * Get GMT date when the invoice was was completed.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  string $context View or edit context.
511
+     * @return string
512
+     */
513
+    public function get_completed_date_gmt( $context = 'view' ) {
514 514
         $date = $this->get_completed_date( $context );
515 515
 
516 516
         if ( $date ) {
517 517
             $date = get_gmt_from_date( $date );
518 518
         }
519
-		return $date;
519
+        return $date;
520 520
     }
521 521
 
522 522
     /**
523
-	 * Alias for self::get_completed_date_gmt().
524
-	 *
525
-	 * @since 1.0.19
526
-	 * @param  string $context View or edit context.
527
-	 * @return string
528
-	 */
529
-	public function get_gmt_completed_date( $context = 'view' ) {
530
-		return $this->get_completed_date_gmt( $context );
523
+     * Alias for self::get_completed_date_gmt().
524
+     *
525
+     * @since 1.0.19
526
+     * @param  string $context View or edit context.
527
+     * @return string
528
+     */
529
+    public function get_gmt_completed_date( $context = 'view' ) {
530
+        return $this->get_completed_date_gmt( $context );
531 531
     }
532 532
 
533 533
     /**
534
-	 * Get the invoice number.
535
-	 *
536
-	 * @since 1.0.19
537
-	 * @param  string $context View or edit context.
538
-	 * @return string
539
-	 */
540
-	public function get_number( $context = 'view' ) {
541
-		$number = $this->get_prop( 'number', $context );
534
+     * Get the invoice number.
535
+     *
536
+     * @since 1.0.19
537
+     * @param  string $context View or edit context.
538
+     * @return string
539
+     */
540
+    public function get_number( $context = 'view' ) {
541
+        $number = $this->get_prop( 'number', $context );
542 542
 
543
-		if ( empty( $number ) ) {
544
-			$number = $this->generate_number();
545
-			$this->set_number( $this->generate_number() );
546
-		}
543
+        if ( empty( $number ) ) {
544
+            $number = $this->generate_number();
545
+            $this->set_number( $this->generate_number() );
546
+        }
547 547
 
548
-		return $number;
548
+        return $number;
549 549
     }
550 550
 
551
-	/**
552
-	 * Set the invoice number.
553
-	 *
554
-	 * @since 1.0.19
555
-	 */
556
-	public function maybe_set_number() {
551
+    /**
552
+     * Set the invoice number.
553
+     *
554
+     * @since 1.0.19
555
+     */
556
+    public function maybe_set_number() {
557 557
         $number = $this->get_number();
558 558
 
559 559
         if ( empty( $number ) || $this->get_id() == $number ) {
560
-			$this->set_number( $this->generate_number() );
560
+            $this->set_number( $this->generate_number() );
561 561
         }
562 562
 
563
-	}
563
+    }
564 564
 
565 565
     /**
566
-	 * Get the invoice key.
567
-	 *
568
-	 * @since 1.0.19
569
-	 * @param  string $context View or edit context.
570
-	 * @return string
571
-	 */
572
-	public function get_key( $context = 'view' ) {
566
+     * Get the invoice key.
567
+     *
568
+     * @since 1.0.19
569
+     * @param  string $context View or edit context.
570
+     * @return string
571
+     */
572
+    public function get_key( $context = 'view' ) {
573 573
         return $this->get_prop( 'key', $context );
574
-	}
575
-
576
-	/**
577
-	 * Set the invoice key.
578
-	 *
579
-	 * @since 1.0.19
580
-	 */
581
-	public function maybe_set_key() {
574
+    }
575
+
576
+    /**
577
+     * Set the invoice key.
578
+     *
579
+     * @since 1.0.19
580
+     */
581
+    public function maybe_set_key() {
582 582
         $key = $this->get_key();
583 583
 
584 584
         if ( empty( $key ) ) {
@@ -589,126 +589,126 @@  discard block
 block discarded – undo
589 589
     }
590 590
 
591 591
     /**
592
-	 * Get the invoice type.
593
-	 *
594
-	 * @since 1.0.19
595
-	 * @param  string $context View or edit context.
596
-	 * @return string
597
-	 */
598
-	public function get_type( $context = 'view' ) {
592
+     * Get the invoice type.
593
+     *
594
+     * @since 1.0.19
595
+     * @param  string $context View or edit context.
596
+     * @return string
597
+     */
598
+    public function get_type( $context = 'view' ) {
599 599
         return $this->get_prop( 'type', $context );
600
-	}
600
+    }
601 601
 
602
-	/**
603
-	 * @deprecated
604
-	 */
605
-	public function get_invoice_quote_type() {
602
+    /**
603
+     * @deprecated
604
+     */
605
+    public function get_invoice_quote_type() {
606 606
         ucfirst( $this->get_type() );
607 607
     }
608 608
 
609 609
     /**
610
-	 * Get the invoice post type.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param  string $context View or edit context.
614
-	 * @return string
615
-	 */
616
-	public function get_post_type( $context = 'view' ) {
610
+     * Get the invoice post type.
611
+     *
612
+     * @since 1.0.19
613
+     * @param  string $context View or edit context.
614
+     * @return string
615
+     */
616
+    public function get_post_type( $context = 'view' ) {
617 617
         return $this->get_prop( 'post_type', $context );
618 618
     }
619 619
 
620 620
     /**
621
-	 * Get the invoice mode.
622
-	 *
623
-	 * @since 1.0.19
624
-	 * @param  string $context View or edit context.
625
-	 * @return string
626
-	 */
627
-	public function get_mode( $context = 'view' ) {
621
+     * Get the invoice mode.
622
+     *
623
+     * @since 1.0.19
624
+     * @param  string $context View or edit context.
625
+     * @return string
626
+     */
627
+    public function get_mode( $context = 'view' ) {
628 628
         return $this->get_prop( 'mode', $context );
629 629
     }
630 630
 
631 631
     /**
632
-	 * Get the invoice path.
633
-	 *
634
-	 * @since 1.0.19
635
-	 * @param  string $context View or edit context.
636
-	 * @return string
637
-	 */
638
-	public function get_path( $context = 'view' ) {
632
+     * Get the invoice path.
633
+     *
634
+     * @since 1.0.19
635
+     * @param  string $context View or edit context.
636
+     * @return string
637
+     */
638
+    public function get_path( $context = 'view' ) {
639 639
         $path   = $this->get_prop( 'path', $context );
640
-		$prefix = wpinv_post_name_prefix( $this->get_post_type() );
640
+        $prefix = wpinv_post_name_prefix( $this->get_post_type() );
641 641
 
642
-		if ( 0 !== strpos( $path, $prefix ) ) {
643
-			$path = sanitize_title(  $prefix . $this->get_id()  );
644
-			$this->set_path( $path );
645
-		}
642
+        if ( 0 !== strpos( $path, $prefix ) ) {
643
+            $path = sanitize_title(  $prefix . $this->get_id()  );
644
+            $this->set_path( $path );
645
+        }
646 646
 
647
-		return $path;
647
+        return $path;
648 648
     }
649 649
 
650 650
     /**
651
-	 * Get the invoice name/title.
652
-	 *
653
-	 * @since 1.0.19
654
-	 * @param  string $context View or edit context.
655
-	 * @return string
656
-	 */
657
-	public function get_name( $context = 'view' ) {
651
+     * Get the invoice name/title.
652
+     *
653
+     * @since 1.0.19
654
+     * @param  string $context View or edit context.
655
+     * @return string
656
+     */
657
+    public function get_name( $context = 'view' ) {
658 658
         return $this->get_prop( 'title', $context );
659 659
     }
660 660
 
661 661
     /**
662
-	 * Alias of self::get_name().
663
-	 *
664
-	 * @since 1.0.19
665
-	 * @param  string $context View or edit context.
666
-	 * @return string
667
-	 */
668
-	public function get_title( $context = 'view' ) {
669
-		return $this->get_name( $context );
662
+     * Alias of self::get_name().
663
+     *
664
+     * @since 1.0.19
665
+     * @param  string $context View or edit context.
666
+     * @return string
667
+     */
668
+    public function get_title( $context = 'view' ) {
669
+        return $this->get_name( $context );
670 670
     }
671 671
 
672 672
     /**
673
-	 * Get the invoice description.
674
-	 *
675
-	 * @since 1.0.19
676
-	 * @param  string $context View or edit context.
677
-	 * @return string
678
-	 */
679
-	public function get_description( $context = 'view' ) {
680
-		return $this->get_prop( 'description', $context );
673
+     * Get the invoice description.
674
+     *
675
+     * @since 1.0.19
676
+     * @param  string $context View or edit context.
677
+     * @return string
678
+     */
679
+    public function get_description( $context = 'view' ) {
680
+        return $this->get_prop( 'description', $context );
681 681
     }
682 682
 
683 683
     /**
684
-	 * Alias of self::get_description().
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param  string $context View or edit context.
688
-	 * @return string
689
-	 */
690
-	public function get_excerpt( $context = 'view' ) {
691
-		return $this->get_description( $context );
684
+     * Alias of self::get_description().
685
+     *
686
+     * @since 1.0.19
687
+     * @param  string $context View or edit context.
688
+     * @return string
689
+     */
690
+    public function get_excerpt( $context = 'view' ) {
691
+        return $this->get_description( $context );
692 692
     }
693 693
 
694 694
     /**
695
-	 * Alias of self::get_description().
696
-	 *
697
-	 * @since 1.0.19
698
-	 * @param  string $context View or edit context.
699
-	 * @return string
700
-	 */
701
-	public function get_summary( $context = 'view' ) {
702
-		return $this->get_description( $context );
695
+     * Alias of self::get_description().
696
+     *
697
+     * @since 1.0.19
698
+     * @param  string $context View or edit context.
699
+     * @return string
700
+     */
701
+    public function get_summary( $context = 'view' ) {
702
+        return $this->get_description( $context );
703 703
     }
704 704
 
705 705
     /**
706
-	 * Returns the user info.
707
-	 *
708
-	 * @since 1.0.19
706
+     * Returns the user info.
707
+     *
708
+     * @since 1.0.19
709 709
      * @param  string $context View or edit context.
710
-	 * @return array
711
-	 */
710
+     * @return array
711
+     */
712 712
     public function get_user_info( $context = 'view' ) {
713 713
 
714 714
         $user_info = array(
@@ -725,616 +725,616 @@  discard block
 block discarded – undo
725 725
             'company'    => $this->get_company( $context ),
726 726
             'vat_number' => $this->get_vat_number( $context ),
727 727
             'discount'   => $this->get_discount_code( $context ),
728
-		);
728
+        );
729
+
730
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
731
+
732
+    }
733
+
734
+    /**
735
+     * Get the customer id.
736
+     *
737
+     * @since 1.0.19
738
+     * @param  string $context View or edit context.
739
+     * @return int
740
+     */
741
+    public function get_author( $context = 'view' ) {
742
+        return (int) $this->get_prop( 'author', $context );
743
+    }
744
+
745
+    /**
746
+     * Alias of self::get_author().
747
+     *
748
+     * @since 1.0.19
749
+     * @param  string $context View or edit context.
750
+     * @return int
751
+     */
752
+    public function get_user_id( $context = 'view' ) {
753
+        return $this->get_author( $context );
754
+    }
755
+
756
+        /**
757
+         * Alias of self::get_author().
758
+         *
759
+         * @since 1.0.19
760
+         * @param  string $context View or edit context.
761
+         * @return int
762
+         */
763
+    public function get_customer_id( $context = 'view' ) {
764
+        return $this->get_author( $context );
765
+    }
729 766
 
730
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
767
+    /**
768
+     * Get the customer's ip.
769
+     *
770
+     * @since 1.0.19
771
+     * @param  string $context View or edit context.
772
+     * @return string
773
+     */
774
+    public function get_ip( $context = 'view' ) {
775
+        return $this->get_prop( 'user_ip', $context );
776
+    }
731 777
 
778
+    /**
779
+     * Alias of self::get_ip().
780
+     *
781
+     * @since 1.0.19
782
+     * @param  string $context View or edit context.
783
+     * @return string
784
+     */
785
+    public function get_user_ip( $context = 'view' ) {
786
+        return $this->get_ip( $context );
787
+    }
788
+
789
+        /**
790
+         * Alias of self::get_ip().
791
+         *
792
+         * @since 1.0.19
793
+         * @param  string $context View or edit context.
794
+         * @return string
795
+         */
796
+    public function get_customer_ip( $context = 'view' ) {
797
+        return $this->get_ip( $context );
732 798
     }
733 799
 
734 800
     /**
735
-	 * Get the customer id.
736
-	 *
737
-	 * @since 1.0.19
738
-	 * @param  string $context View or edit context.
739
-	 * @return int
740
-	 */
741
-	public function get_author( $context = 'view' ) {
742
-		return (int) $this->get_prop( 'author', $context );
801
+     * Get the customer's first name.
802
+     *
803
+     * @since 1.0.19
804
+     * @param  string $context View or edit context.
805
+     * @return string
806
+     */
807
+    public function get_first_name( $context = 'view' ) {
808
+        return $this->get_prop( 'first_name', $context );
743 809
     }
744 810
 
745 811
     /**
746
-	 * Alias of self::get_author().
747
-	 *
748
-	 * @since 1.0.19
749
-	 * @param  string $context View or edit context.
750
-	 * @return int
751
-	 */
752
-	public function get_user_id( $context = 'view' ) {
753
-		return $this->get_author( $context );
812
+     * Alias of self::get_first_name().
813
+     *
814
+     * @since 1.0.19
815
+     * @param  string $context View or edit context.
816
+     * @return int
817
+     */
818
+    public function get_user_first_name( $context = 'view' ) {
819
+        return $this->get_first_name( $context );
754 820
     }
755 821
 
756
-     /**
757
-	 * Alias of self::get_author().
758
-	 *
759
-	 * @since 1.0.19
760
-	 * @param  string $context View or edit context.
761
-	 * @return int
762
-	 */
763
-	public function get_customer_id( $context = 'view' ) {
764
-		return $this->get_author( $context );
822
+        /**
823
+         * Alias of self::get_first_name().
824
+         *
825
+         * @since 1.0.19
826
+         * @param  string $context View or edit context.
827
+         * @return int
828
+         */
829
+    public function get_customer_first_name( $context = 'view' ) {
830
+        return $this->get_first_name( $context );
765 831
     }
766 832
 
767 833
     /**
768
-	 * Get the customer's ip.
769
-	 *
770
-	 * @since 1.0.19
771
-	 * @param  string $context View or edit context.
772
-	 * @return string
773
-	 */
774
-	public function get_ip( $context = 'view' ) {
775
-		return $this->get_prop( 'user_ip', $context );
834
+     * Get the customer's last name.
835
+     *
836
+     * @since 1.0.19
837
+     * @param  string $context View or edit context.
838
+     * @return string
839
+     */
840
+    public function get_last_name( $context = 'view' ) {
841
+        return $this->get_prop( 'last_name', $context );
776 842
     }
777 843
 
778 844
     /**
779
-	 * Alias of self::get_ip().
780
-	 *
781
-	 * @since 1.0.19
782
-	 * @param  string $context View or edit context.
783
-	 * @return string
784
-	 */
785
-	public function get_user_ip( $context = 'view' ) {
786
-		return $this->get_ip( $context );
845
+     * Alias of self::get_last_name().
846
+     *
847
+     * @since 1.0.19
848
+     * @param  string $context View or edit context.
849
+     * @return int
850
+     */
851
+    public function get_user_last_name( $context = 'view' ) {
852
+        return $this->get_last_name( $context );
787 853
     }
788 854
 
789
-     /**
790
-	 * Alias of self::get_ip().
791
-	 *
792
-	 * @since 1.0.19
793
-	 * @param  string $context View or edit context.
794
-	 * @return string
795
-	 */
796
-	public function get_customer_ip( $context = 'view' ) {
797
-		return $this->get_ip( $context );
855
+    /**
856
+     * Alias of self::get_last_name().
857
+     *
858
+     * @since 1.0.19
859
+     * @param  string $context View or edit context.
860
+     * @return int
861
+     */
862
+    public function get_customer_last_name( $context = 'view' ) {
863
+        return $this->get_last_name( $context );
798 864
     }
799 865
 
800 866
     /**
801
-	 * Get the customer's first name.
802
-	 *
803
-	 * @since 1.0.19
804
-	 * @param  string $context View or edit context.
805
-	 * @return string
806
-	 */
807
-	public function get_first_name( $context = 'view' ) {
808
-		return $this->get_prop( 'first_name', $context );
867
+     * Get the customer's full name.
868
+     *
869
+     * @since 1.0.19
870
+     * @param  string $context View or edit context.
871
+     * @return string
872
+     */
873
+    public function get_full_name( $context = 'view' ) {
874
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
809 875
     }
810 876
 
811 877
     /**
812
-	 * Alias of self::get_first_name().
813
-	 *
814
-	 * @since 1.0.19
815
-	 * @param  string $context View or edit context.
816
-	 * @return int
817
-	 */
818
-	public function get_user_first_name( $context = 'view' ) {
819
-		return $this->get_first_name( $context );
878
+     * Alias of self::get_full_name().
879
+     *
880
+     * @since 1.0.19
881
+     * @param  string $context View or edit context.
882
+     * @return int
883
+     */
884
+    public function get_user_full_name( $context = 'view' ) {
885
+        return $this->get_full_name( $context );
820 886
     }
821 887
 
822
-     /**
823
-	 * Alias of self::get_first_name().
824
-	 *
825
-	 * @since 1.0.19
826
-	 * @param  string $context View or edit context.
827
-	 * @return int
828
-	 */
829
-	public function get_customer_first_name( $context = 'view' ) {
830
-		return $this->get_first_name( $context );
888
+    /**
889
+     * Alias of self::get_full_name().
890
+     *
891
+     * @since 1.0.19
892
+     * @param  string $context View or edit context.
893
+     * @return int
894
+     */
895
+    public function get_customer_full_name( $context = 'view' ) {
896
+        return $this->get_full_name( $context );
831 897
     }
832 898
 
833 899
     /**
834
-	 * Get the customer's last name.
835
-	 *
836
-	 * @since 1.0.19
837
-	 * @param  string $context View or edit context.
838
-	 * @return string
839
-	 */
840
-	public function get_last_name( $context = 'view' ) {
841
-		return $this->get_prop( 'last_name', $context );
900
+     * Get the customer's phone number.
901
+     *
902
+     * @since 1.0.19
903
+     * @param  string $context View or edit context.
904
+     * @return string
905
+     */
906
+    public function get_phone( $context = 'view' ) {
907
+        return $this->get_prop( 'phone', $context );
842 908
     }
843 909
 
844 910
     /**
845
-	 * Alias of self::get_last_name().
846
-	 *
847
-	 * @since 1.0.19
848
-	 * @param  string $context View or edit context.
849
-	 * @return int
850
-	 */
851
-	public function get_user_last_name( $context = 'view' ) {
852
-		return $this->get_last_name( $context );
911
+     * Alias of self::get_phone().
912
+     *
913
+     * @since 1.0.19
914
+     * @param  string $context View or edit context.
915
+     * @return int
916
+     */
917
+    public function get_phone_number( $context = 'view' ) {
918
+        return $this->get_phone( $context );
853 919
     }
854 920
 
855 921
     /**
856
-	 * Alias of self::get_last_name().
857
-	 *
858
-	 * @since 1.0.19
859
-	 * @param  string $context View or edit context.
860
-	 * @return int
861
-	 */
862
-	public function get_customer_last_name( $context = 'view' ) {
863
-		return $this->get_last_name( $context );
922
+     * Alias of self::get_phone().
923
+     *
924
+     * @since 1.0.19
925
+     * @param  string $context View or edit context.
926
+     * @return int
927
+     */
928
+    public function get_user_phone( $context = 'view' ) {
929
+        return $this->get_phone( $context );
864 930
     }
865 931
 
866 932
     /**
867
-	 * Get the customer's full name.
868
-	 *
869
-	 * @since 1.0.19
870
-	 * @param  string $context View or edit context.
871
-	 * @return string
872
-	 */
873
-	public function get_full_name( $context = 'view' ) {
874
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
933
+     * Alias of self::get_phone().
934
+     *
935
+     * @since 1.0.19
936
+     * @param  string $context View or edit context.
937
+     * @return int
938
+     */
939
+    public function get_customer_phone( $context = 'view' ) {
940
+        return $this->get_phone( $context );
941
+    }
942
+
943
+    /**
944
+     * Get the customer's email address.
945
+     *
946
+     * @since 1.0.19
947
+     * @param  string $context View or edit context.
948
+     * @return string
949
+     */
950
+    public function get_email( $context = 'view' ) {
951
+        return $this->get_prop( 'email', $context );
952
+    }
953
+
954
+    /**
955
+     * Alias of self::get_email().
956
+     *
957
+     * @since 1.0.19
958
+     * @param  string $context View or edit context.
959
+     * @return string
960
+     */
961
+    public function get_email_address( $context = 'view' ) {
962
+        return $this->get_email( $context );
963
+    }
964
+
965
+    /**
966
+     * Alias of self::get_email().
967
+     *
968
+     * @since 1.0.19
969
+     * @param  string $context View or edit context.
970
+     * @return int
971
+     */
972
+    public function get_user_email( $context = 'view' ) {
973
+        return $this->get_email( $context );
974
+    }
975
+
976
+    /**
977
+     * Alias of self::get_email().
978
+     *
979
+     * @since 1.0.19
980
+     * @param  string $context View or edit context.
981
+     * @return int
982
+     */
983
+    public function get_customer_email( $context = 'view' ) {
984
+        return $this->get_email( $context );
985
+    }
986
+
987
+    /**
988
+     * Get the customer's country.
989
+     *
990
+     * @since 1.0.19
991
+     * @param  string $context View or edit context.
992
+     * @return string
993
+     */
994
+    public function get_country( $context = 'view' ) {
995
+        $country = $this->get_prop( 'country', $context );
996
+        return empty( $country ) ? wpinv_get_default_country() : $country;
997
+    }
998
+
999
+    /**
1000
+     * Alias of self::get_country().
1001
+     *
1002
+     * @since 1.0.19
1003
+     * @param  string $context View or edit context.
1004
+     * @return int
1005
+     */
1006
+    public function get_user_country( $context = 'view' ) {
1007
+        return $this->get_country( $context );
1008
+    }
1009
+
1010
+    /**
1011
+     * Alias of self::get_country().
1012
+     *
1013
+     * @since 1.0.19
1014
+     * @param  string $context View or edit context.
1015
+     * @return int
1016
+     */
1017
+    public function get_customer_country( $context = 'view' ) {
1018
+        return $this->get_country( $context );
875 1019
     }
876 1020
 
877 1021
     /**
878
-	 * Alias of self::get_full_name().
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param  string $context View or edit context.
882
-	 * @return int
883
-	 */
884
-	public function get_user_full_name( $context = 'view' ) {
885
-		return $this->get_full_name( $context );
1022
+     * Get the customer's state.
1023
+     *
1024
+     * @since 1.0.19
1025
+     * @param  string $context View or edit context.
1026
+     * @return string
1027
+     */
1028
+    public function get_state( $context = 'view' ) {
1029
+        $state = $this->get_prop( 'state', $context );
1030
+        return empty( $state ) ? wpinv_get_default_state() : $state;
886 1031
     }
887 1032
 
888 1033
     /**
889
-	 * Alias of self::get_full_name().
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @param  string $context View or edit context.
893
-	 * @return int
894
-	 */
895
-	public function get_customer_full_name( $context = 'view' ) {
896
-		return $this->get_full_name( $context );
1034
+     * Alias of self::get_state().
1035
+     *
1036
+     * @since 1.0.19
1037
+     * @param  string $context View or edit context.
1038
+     * @return int
1039
+     */
1040
+    public function get_user_state( $context = 'view' ) {
1041
+        return $this->get_state( $context );
897 1042
     }
898 1043
 
899 1044
     /**
900
-	 * Get the customer's phone number.
901
-	 *
902
-	 * @since 1.0.19
903
-	 * @param  string $context View or edit context.
904
-	 * @return string
905
-	 */
906
-	public function get_phone( $context = 'view' ) {
907
-		return $this->get_prop( 'phone', $context );
1045
+     * Alias of self::get_state().
1046
+     *
1047
+     * @since 1.0.19
1048
+     * @param  string $context View or edit context.
1049
+     * @return int
1050
+     */
1051
+    public function get_customer_state( $context = 'view' ) {
1052
+        return $this->get_state( $context );
908 1053
     }
909 1054
 
910 1055
     /**
911
-	 * Alias of self::get_phone().
912
-	 *
913
-	 * @since 1.0.19
914
-	 * @param  string $context View or edit context.
915
-	 * @return int
916
-	 */
917
-	public function get_phone_number( $context = 'view' ) {
918
-		return $this->get_phone( $context );
1056
+     * Get the customer's city.
1057
+     *
1058
+     * @since 1.0.19
1059
+     * @param  string $context View or edit context.
1060
+     * @return string
1061
+     */
1062
+    public function get_city( $context = 'view' ) {
1063
+        return $this->get_prop( 'city', $context );
919 1064
     }
920 1065
 
921 1066
     /**
922
-	 * Alias of self::get_phone().
923
-	 *
924
-	 * @since 1.0.19
925
-	 * @param  string $context View or edit context.
926
-	 * @return int
927
-	 */
928
-	public function get_user_phone( $context = 'view' ) {
929
-		return $this->get_phone( $context );
1067
+     * Alias of self::get_city().
1068
+     *
1069
+     * @since 1.0.19
1070
+     * @param  string $context View or edit context.
1071
+     * @return string
1072
+     */
1073
+    public function get_user_city( $context = 'view' ) {
1074
+        return $this->get_city( $context );
930 1075
     }
931 1076
 
932 1077
     /**
933
-	 * Alias of self::get_phone().
934
-	 *
935
-	 * @since 1.0.19
936
-	 * @param  string $context View or edit context.
937
-	 * @return int
938
-	 */
939
-	public function get_customer_phone( $context = 'view' ) {
940
-		return $this->get_phone( $context );
1078
+     * Alias of self::get_city().
1079
+     *
1080
+     * @since 1.0.19
1081
+     * @param  string $context View or edit context.
1082
+     * @return string
1083
+     */
1084
+    public function get_customer_city( $context = 'view' ) {
1085
+        return $this->get_city( $context );
941 1086
     }
942 1087
 
943 1088
     /**
944
-	 * Get the customer's email address.
945
-	 *
946
-	 * @since 1.0.19
947
-	 * @param  string $context View or edit context.
948
-	 * @return string
949
-	 */
950
-	public function get_email( $context = 'view' ) {
951
-		return $this->get_prop( 'email', $context );
1089
+     * Get the customer's zip.
1090
+     *
1091
+     * @since 1.0.19
1092
+     * @param  string $context View or edit context.
1093
+     * @return string
1094
+     */
1095
+    public function get_zip( $context = 'view' ) {
1096
+        return $this->get_prop( 'zip', $context );
952 1097
     }
953 1098
 
954 1099
     /**
955
-	 * Alias of self::get_email().
956
-	 *
957
-	 * @since 1.0.19
958
-	 * @param  string $context View or edit context.
959
-	 * @return string
960
-	 */
961
-	public function get_email_address( $context = 'view' ) {
962
-		return $this->get_email( $context );
1100
+     * Alias of self::get_zip().
1101
+     *
1102
+     * @since 1.0.19
1103
+     * @param  string $context View or edit context.
1104
+     * @return string
1105
+     */
1106
+    public function get_user_zip( $context = 'view' ) {
1107
+        return $this->get_zip( $context );
963 1108
     }
964 1109
 
965 1110
     /**
966
-	 * Alias of self::get_email().
967
-	 *
968
-	 * @since 1.0.19
969
-	 * @param  string $context View or edit context.
970
-	 * @return int
971
-	 */
972
-	public function get_user_email( $context = 'view' ) {
973
-		return $this->get_email( $context );
1111
+     * Alias of self::get_zip().
1112
+     *
1113
+     * @since 1.0.19
1114
+     * @param  string $context View or edit context.
1115
+     * @return string
1116
+     */
1117
+    public function get_customer_zip( $context = 'view' ) {
1118
+        return $this->get_zip( $context );
974 1119
     }
975 1120
 
976 1121
     /**
977
-	 * Alias of self::get_email().
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param  string $context View or edit context.
981
-	 * @return int
982
-	 */
983
-	public function get_customer_email( $context = 'view' ) {
984
-		return $this->get_email( $context );
1122
+     * Get the customer's company.
1123
+     *
1124
+     * @since 1.0.19
1125
+     * @param  string $context View or edit context.
1126
+     * @return string
1127
+     */
1128
+    public function get_company( $context = 'view' ) {
1129
+        return $this->get_prop( 'company', $context );
985 1130
     }
986 1131
 
987 1132
     /**
988
-	 * Get the customer's country.
989
-	 *
990
-	 * @since 1.0.19
991
-	 * @param  string $context View or edit context.
992
-	 * @return string
993
-	 */
994
-	public function get_country( $context = 'view' ) {
995
-		$country = $this->get_prop( 'country', $context );
996
-		return empty( $country ) ? wpinv_get_default_country() : $country;
1133
+     * Alias of self::get_company().
1134
+     *
1135
+     * @since 1.0.19
1136
+     * @param  string $context View or edit context.
1137
+     * @return string
1138
+     */
1139
+    public function get_user_company( $context = 'view' ) {
1140
+        return $this->get_company( $context );
997 1141
     }
998 1142
 
999 1143
     /**
1000
-	 * Alias of self::get_country().
1001
-	 *
1002
-	 * @since 1.0.19
1003
-	 * @param  string $context View or edit context.
1004
-	 * @return int
1005
-	 */
1006
-	public function get_user_country( $context = 'view' ) {
1007
-		return $this->get_country( $context );
1144
+     * Alias of self::get_company().
1145
+     *
1146
+     * @since 1.0.19
1147
+     * @param  string $context View or edit context.
1148
+     * @return string
1149
+     */
1150
+    public function get_customer_company( $context = 'view' ) {
1151
+        return $this->get_company( $context );
1008 1152
     }
1009 1153
 
1010 1154
     /**
1011
-	 * Alias of self::get_country().
1012
-	 *
1013
-	 * @since 1.0.19
1014
-	 * @param  string $context View or edit context.
1015
-	 * @return int
1016
-	 */
1017
-	public function get_customer_country( $context = 'view' ) {
1018
-		return $this->get_country( $context );
1155
+     * Get the customer's vat number.
1156
+     *
1157
+     * @since 1.0.19
1158
+     * @param  string $context View or edit context.
1159
+     * @return string
1160
+     */
1161
+    public function get_vat_number( $context = 'view' ) {
1162
+        return $this->get_prop( 'vat_number', $context );
1019 1163
     }
1020 1164
 
1021 1165
     /**
1022
-	 * Get the customer's state.
1023
-	 *
1024
-	 * @since 1.0.19
1025
-	 * @param  string $context View or edit context.
1026
-	 * @return string
1027
-	 */
1028
-	public function get_state( $context = 'view' ) {
1029
-		$state = $this->get_prop( 'state', $context );
1030
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1166
+     * Alias of self::get_vat_number().
1167
+     *
1168
+     * @since 1.0.19
1169
+     * @param  string $context View or edit context.
1170
+     * @return string
1171
+     */
1172
+    public function get_user_vat_number( $context = 'view' ) {
1173
+        return $this->get_vat_number( $context );
1031 1174
     }
1032 1175
 
1033 1176
     /**
1034
-	 * Alias of self::get_state().
1035
-	 *
1036
-	 * @since 1.0.19
1037
-	 * @param  string $context View or edit context.
1038
-	 * @return int
1039
-	 */
1040
-	public function get_user_state( $context = 'view' ) {
1041
-		return $this->get_state( $context );
1177
+     * Alias of self::get_vat_number().
1178
+     *
1179
+     * @since 1.0.19
1180
+     * @param  string $context View or edit context.
1181
+     * @return string
1182
+     */
1183
+    public function get_customer_vat_number( $context = 'view' ) {
1184
+        return $this->get_vat_number( $context );
1042 1185
     }
1043 1186
 
1044 1187
     /**
1045
-	 * Alias of self::get_state().
1046
-	 *
1047
-	 * @since 1.0.19
1048
-	 * @param  string $context View or edit context.
1049
-	 * @return int
1050
-	 */
1051
-	public function get_customer_state( $context = 'view' ) {
1052
-		return $this->get_state( $context );
1188
+     * Get the customer's vat rate.
1189
+     *
1190
+     * @since 1.0.19
1191
+     * @param  string $context View or edit context.
1192
+     * @return string
1193
+     */
1194
+    public function get_vat_rate( $context = 'view' ) {
1195
+        return $this->get_prop( 'vat_rate', $context );
1053 1196
     }
1054 1197
 
1055 1198
     /**
1056
-	 * Get the customer's city.
1057
-	 *
1058
-	 * @since 1.0.19
1059
-	 * @param  string $context View or edit context.
1060
-	 * @return string
1061
-	 */
1062
-	public function get_city( $context = 'view' ) {
1063
-		return $this->get_prop( 'city', $context );
1199
+     * Alias of self::get_vat_rate().
1200
+     *
1201
+     * @since 1.0.19
1202
+     * @param  string $context View or edit context.
1203
+     * @return string
1204
+     */
1205
+    public function get_user_vat_rate( $context = 'view' ) {
1206
+        return $this->get_vat_rate( $context );
1064 1207
     }
1065 1208
 
1066 1209
     /**
1067
-	 * Alias of self::get_city().
1068
-	 *
1069
-	 * @since 1.0.19
1070
-	 * @param  string $context View or edit context.
1071
-	 * @return string
1072
-	 */
1073
-	public function get_user_city( $context = 'view' ) {
1074
-		return $this->get_city( $context );
1210
+     * Alias of self::get_vat_rate().
1211
+     *
1212
+     * @since 1.0.19
1213
+     * @param  string $context View or edit context.
1214
+     * @return string
1215
+     */
1216
+    public function get_customer_vat_rate( $context = 'view' ) {
1217
+        return $this->get_vat_rate( $context );
1075 1218
     }
1076 1219
 
1077 1220
     /**
1078
-	 * Alias of self::get_city().
1079
-	 *
1080
-	 * @since 1.0.19
1081
-	 * @param  string $context View or edit context.
1082
-	 * @return string
1083
-	 */
1084
-	public function get_customer_city( $context = 'view' ) {
1085
-		return $this->get_city( $context );
1221
+     * Get the customer's address.
1222
+     *
1223
+     * @since 1.0.19
1224
+     * @param  string $context View or edit context.
1225
+     * @return string
1226
+     */
1227
+    public function get_address( $context = 'view' ) {
1228
+        return $this->get_prop( 'address', $context );
1086 1229
     }
1087 1230
 
1088 1231
     /**
1089
-	 * Get the customer's zip.
1090
-	 *
1091
-	 * @since 1.0.19
1092
-	 * @param  string $context View or edit context.
1093
-	 * @return string
1094
-	 */
1095
-	public function get_zip( $context = 'view' ) {
1096
-		return $this->get_prop( 'zip', $context );
1232
+     * Alias of self::get_address().
1233
+     *
1234
+     * @since 1.0.19
1235
+     * @param  string $context View or edit context.
1236
+     * @return string
1237
+     */
1238
+    public function get_user_address( $context = 'view' ) {
1239
+        return $this->get_address( $context );
1097 1240
     }
1098 1241
 
1099 1242
     /**
1100
-	 * Alias of self::get_zip().
1101
-	 *
1102
-	 * @since 1.0.19
1103
-	 * @param  string $context View or edit context.
1104
-	 * @return string
1105
-	 */
1106
-	public function get_user_zip( $context = 'view' ) {
1107
-		return $this->get_zip( $context );
1243
+     * Alias of self::get_address().
1244
+     *
1245
+     * @since 1.0.19
1246
+     * @param  string $context View or edit context.
1247
+     * @return string
1248
+     */
1249
+    public function get_customer_address( $context = 'view' ) {
1250
+        return $this->get_address( $context );
1108 1251
     }
1109 1252
 
1110 1253
     /**
1111
-	 * Alias of self::get_zip().
1112
-	 *
1113
-	 * @since 1.0.19
1114
-	 * @param  string $context View or edit context.
1115
-	 * @return string
1116
-	 */
1117
-	public function get_customer_zip( $context = 'view' ) {
1118
-		return $this->get_zip( $context );
1254
+     * Get whether the customer has viewed the invoice or not.
1255
+     *
1256
+     * @since 1.0.19
1257
+     * @param  string $context View or edit context.
1258
+     * @return bool
1259
+     */
1260
+    public function get_is_viewed( $context = 'view' ) {
1261
+        return (bool) $this->get_prop( 'is_viewed', $context );
1119 1262
     }
1120 1263
 
1121 1264
     /**
1122
-	 * Get the customer's company.
1123
-	 *
1124
-	 * @since 1.0.19
1125
-	 * @param  string $context View or edit context.
1126
-	 * @return string
1127
-	 */
1128
-	public function get_company( $context = 'view' ) {
1129
-		return $this->get_prop( 'company', $context );
1265
+     * Get other recipients for invoice communications.
1266
+     *
1267
+     * @since 1.0.19
1268
+     * @param  string $context View or edit context.
1269
+     * @return bool
1270
+     */
1271
+    public function get_email_cc( $context = 'view' ) {
1272
+        return $this->get_prop( 'email_cc', $context );
1130 1273
     }
1131 1274
 
1132 1275
     /**
1133
-	 * Alias of self::get_company().
1134
-	 *
1135
-	 * @since 1.0.19
1136
-	 * @param  string $context View or edit context.
1137
-	 * @return string
1138
-	 */
1139
-	public function get_user_company( $context = 'view' ) {
1140
-		return $this->get_company( $context );
1276
+     * Get invoice template.
1277
+     *
1278
+     * @since 1.0.19
1279
+     * @param  string $context View or edit context.
1280
+     * @return bool
1281
+     */
1282
+    public function get_template( $context = 'view' ) {
1283
+        return $this->get_prop( 'template', $context );
1141 1284
     }
1142 1285
 
1143 1286
     /**
1144
-	 * Alias of self::get_company().
1145
-	 *
1146
-	 * @since 1.0.19
1147
-	 * @param  string $context View or edit context.
1148
-	 * @return string
1149
-	 */
1150
-	public function get_customer_company( $context = 'view' ) {
1151
-		return $this->get_company( $context );
1287
+     * Get invoice source.
1288
+     *
1289
+     * @since 1.0.19
1290
+     * @param  string $context View or edit context.
1291
+     * @return bool
1292
+     */
1293
+    public function get_created_via( $context = 'view' ) {
1294
+        return $this->get_prop( 'created_via', $context );
1152 1295
     }
1153 1296
 
1154 1297
     /**
1155
-	 * Get the customer's vat number.
1156
-	 *
1157
-	 * @since 1.0.19
1158
-	 * @param  string $context View or edit context.
1159
-	 * @return string
1160
-	 */
1161
-	public function get_vat_number( $context = 'view' ) {
1162
-		return $this->get_prop( 'vat_number', $context );
1298
+     * Get whether the customer has confirmed their address.
1299
+     *
1300
+     * @since 1.0.19
1301
+     * @param  string $context View or edit context.
1302
+     * @return bool
1303
+     */
1304
+    public function get_address_confirmed( $context = 'view' ) {
1305
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1163 1306
     }
1164 1307
 
1165 1308
     /**
1166
-	 * Alias of self::get_vat_number().
1167
-	 *
1168
-	 * @since 1.0.19
1169
-	 * @param  string $context View or edit context.
1170
-	 * @return string
1171
-	 */
1172
-	public function get_user_vat_number( $context = 'view' ) {
1173
-		return $this->get_vat_number( $context );
1309
+     * Alias of self::get_address_confirmed().
1310
+     *
1311
+     * @since 1.0.19
1312
+     * @param  string $context View or edit context.
1313
+     * @return bool
1314
+     */
1315
+    public function get_user_address_confirmed( $context = 'view' ) {
1316
+        return $this->get_address_confirmed( $context );
1174 1317
     }
1175 1318
 
1176 1319
     /**
1177
-	 * Alias of self::get_vat_number().
1178
-	 *
1179
-	 * @since 1.0.19
1180
-	 * @param  string $context View or edit context.
1181
-	 * @return string
1182
-	 */
1183
-	public function get_customer_vat_number( $context = 'view' ) {
1184
-		return $this->get_vat_number( $context );
1320
+     * Alias of self::get_address().
1321
+     *
1322
+     * @since 1.0.19
1323
+     * @param  string $context View or edit context.
1324
+     * @return bool
1325
+     */
1326
+    public function get_customer_address_confirmed( $context = 'view' ) {
1327
+        return $this->get_address_confirmed( $context );
1185 1328
     }
1186 1329
 
1187 1330
     /**
1188
-	 * Get the customer's vat rate.
1189
-	 *
1190
-	 * @since 1.0.19
1191
-	 * @param  string $context View or edit context.
1192
-	 * @return string
1193
-	 */
1194
-	public function get_vat_rate( $context = 'view' ) {
1195
-		return $this->get_prop( 'vat_rate', $context );
1196
-    }
1197
-
1198
-    /**
1199
-	 * Alias of self::get_vat_rate().
1200
-	 *
1201
-	 * @since 1.0.19
1202
-	 * @param  string $context View or edit context.
1203
-	 * @return string
1204
-	 */
1205
-	public function get_user_vat_rate( $context = 'view' ) {
1206
-		return $this->get_vat_rate( $context );
1207
-    }
1208
-
1209
-    /**
1210
-	 * Alias of self::get_vat_rate().
1211
-	 *
1212
-	 * @since 1.0.19
1213
-	 * @param  string $context View or edit context.
1214
-	 * @return string
1215
-	 */
1216
-	public function get_customer_vat_rate( $context = 'view' ) {
1217
-		return $this->get_vat_rate( $context );
1218
-    }
1219
-
1220
-    /**
1221
-	 * Get the customer's address.
1222
-	 *
1223
-	 * @since 1.0.19
1224
-	 * @param  string $context View or edit context.
1225
-	 * @return string
1226
-	 */
1227
-	public function get_address( $context = 'view' ) {
1228
-		return $this->get_prop( 'address', $context );
1229
-    }
1230
-
1231
-    /**
1232
-	 * Alias of self::get_address().
1233
-	 *
1234
-	 * @since 1.0.19
1235
-	 * @param  string $context View or edit context.
1236
-	 * @return string
1237
-	 */
1238
-	public function get_user_address( $context = 'view' ) {
1239
-		return $this->get_address( $context );
1240
-    }
1241
-
1242
-    /**
1243
-	 * Alias of self::get_address().
1244
-	 *
1245
-	 * @since 1.0.19
1246
-	 * @param  string $context View or edit context.
1247
-	 * @return string
1248
-	 */
1249
-	public function get_customer_address( $context = 'view' ) {
1250
-		return $this->get_address( $context );
1251
-    }
1252
-
1253
-    /**
1254
-	 * Get whether the customer has viewed the invoice or not.
1255
-	 *
1256
-	 * @since 1.0.19
1257
-	 * @param  string $context View or edit context.
1258
-	 * @return bool
1259
-	 */
1260
-	public function get_is_viewed( $context = 'view' ) {
1261
-		return (bool) $this->get_prop( 'is_viewed', $context );
1262
-	}
1263
-
1264
-	/**
1265
-	 * Get other recipients for invoice communications.
1266
-	 *
1267
-	 * @since 1.0.19
1268
-	 * @param  string $context View or edit context.
1269
-	 * @return bool
1270
-	 */
1271
-	public function get_email_cc( $context = 'view' ) {
1272
-		return $this->get_prop( 'email_cc', $context );
1273
-	}
1274
-
1275
-	/**
1276
-	 * Get invoice template.
1277
-	 *
1278
-	 * @since 1.0.19
1279
-	 * @param  string $context View or edit context.
1280
-	 * @return bool
1281
-	 */
1282
-	public function get_template( $context = 'view' ) {
1283
-		return $this->get_prop( 'template', $context );
1284
-	}
1285
-
1286
-	/**
1287
-	 * Get invoice source.
1288
-	 *
1289
-	 * @since 1.0.19
1290
-	 * @param  string $context View or edit context.
1291
-	 * @return bool
1292
-	 */
1293
-	public function get_created_via( $context = 'view' ) {
1294
-		return $this->get_prop( 'created_via', $context );
1295
-	}
1296
-
1297
-	/**
1298
-	 * Get whether the customer has confirmed their address.
1299
-	 *
1300
-	 * @since 1.0.19
1301
-	 * @param  string $context View or edit context.
1302
-	 * @return bool
1303
-	 */
1304
-	public function get_address_confirmed( $context = 'view' ) {
1305
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1306
-    }
1307
-
1308
-    /**
1309
-	 * Alias of self::get_address_confirmed().
1310
-	 *
1311
-	 * @since 1.0.19
1312
-	 * @param  string $context View or edit context.
1313
-	 * @return bool
1314
-	 */
1315
-	public function get_user_address_confirmed( $context = 'view' ) {
1316
-		return $this->get_address_confirmed( $context );
1317
-    }
1318
-
1319
-    /**
1320
-	 * Alias of self::get_address().
1321
-	 *
1322
-	 * @since 1.0.19
1323
-	 * @param  string $context View or edit context.
1324
-	 * @return bool
1325
-	 */
1326
-	public function get_customer_address_confirmed( $context = 'view' ) {
1327
-		return $this->get_address_confirmed( $context );
1328
-    }
1329
-
1330
-    /**
1331
-	 * Get the invoice subtotal.
1332
-	 *
1333
-	 * @since 1.0.19
1334
-	 * @param  string $context View or edit context.
1335
-	 * @return float
1336
-	 */
1337
-	public function get_subtotal( $context = 'view' ) {
1331
+     * Get the invoice subtotal.
1332
+     *
1333
+     * @since 1.0.19
1334
+     * @param  string $context View or edit context.
1335
+     * @return float
1336
+     */
1337
+    public function get_subtotal( $context = 'view' ) {
1338 1338
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1339 1339
 
1340 1340
         // Backwards compatibility.
@@ -1346,165 +1346,165 @@  discard block
 block discarded – undo
1346 1346
     }
1347 1347
 
1348 1348
     /**
1349
-	 * Get the invoice discount total.
1350
-	 *
1351
-	 * @since 1.0.19
1352
-	 * @param  string $context View or edit context.
1353
-	 * @return float
1354
-	 */
1355
-	public function get_total_discount( $context = 'view' ) {
1356
-		return (float) $this->get_prop( 'total_discount', $context );
1349
+     * Get the invoice discount total.
1350
+     *
1351
+     * @since 1.0.19
1352
+     * @param  string $context View or edit context.
1353
+     * @return float
1354
+     */
1355
+    public function get_total_discount( $context = 'view' ) {
1356
+        return (float) $this->get_prop( 'total_discount', $context );
1357 1357
     }
1358 1358
 
1359 1359
     /**
1360
-	 * Get the invoice tax total.
1361
-	 *
1362
-	 * @since 1.0.19
1363
-	 * @param  string $context View or edit context.
1364
-	 * @return float
1365
-	 */
1366
-	public function get_total_tax( $context = 'view' ) {
1367
-		return (float) $this->get_prop( 'total_tax', $context );
1368
-	}
1360
+     * Get the invoice tax total.
1361
+     *
1362
+     * @since 1.0.19
1363
+     * @param  string $context View or edit context.
1364
+     * @return float
1365
+     */
1366
+    public function get_total_tax( $context = 'view' ) {
1367
+        return (float) $this->get_prop( 'total_tax', $context );
1368
+    }
1369 1369
 
1370
-	/**
1371
-	 * @deprecated
1372
-	 */
1373
-	public function get_final_tax( $currency = false ) {
1374
-		$tax = $this->get_total_tax();
1370
+    /**
1371
+     * @deprecated
1372
+     */
1373
+    public function get_final_tax( $currency = false ) {
1374
+        $tax = $this->get_total_tax();
1375 1375
 
1376 1376
         if ( $currency ) {
1377
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1377
+            return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1378 1378
         }
1379 1379
 
1380 1380
         return $tax;
1381 1381
     }
1382 1382
 
1383 1383
     /**
1384
-	 * Get the invoice fees total.
1385
-	 *
1386
-	 * @since 1.0.19
1387
-	 * @param  string $context View or edit context.
1388
-	 * @return float
1389
-	 */
1390
-	public function get_total_fees( $context = 'view' ) {
1391
-		return (float) $this->get_prop( 'total_fees', $context );
1384
+     * Get the invoice fees total.
1385
+     *
1386
+     * @since 1.0.19
1387
+     * @param  string $context View or edit context.
1388
+     * @return float
1389
+     */
1390
+    public function get_total_fees( $context = 'view' ) {
1391
+        return (float) $this->get_prop( 'total_fees', $context );
1392 1392
     }
1393 1393
 
1394 1394
     /**
1395
-	 * Alias for self::get_total_fees().
1396
-	 *
1397
-	 * @since 1.0.19
1398
-	 * @param  string $context View or edit context.
1399
-	 * @return float
1400
-	 */
1401
-	public function get_fees_total( $context = 'view' ) {
1402
-		return $this->get_total_fees( $context );
1395
+     * Alias for self::get_total_fees().
1396
+     *
1397
+     * @since 1.0.19
1398
+     * @param  string $context View or edit context.
1399
+     * @return float
1400
+     */
1401
+    public function get_fees_total( $context = 'view' ) {
1402
+        return $this->get_total_fees( $context );
1403 1403
     }
1404 1404
 
1405 1405
     /**
1406
-	 * Get the invoice total.
1407
-	 *
1408
-	 * @since 1.0.19
1406
+     * Get the invoice total.
1407
+     *
1408
+     * @since 1.0.19
1409 1409
      * @return float
1410
-	 */
1411
-	public function get_total() {
1412
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1413
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1414
-	}
1410
+     */
1411
+    public function get_total() {
1412
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1413
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1414
+    }
1415 1415
 	
1416
-	/**
1417
-	 * Get the invoice totals.
1418
-	 *
1419
-	 * @since 1.0.19
1416
+    /**
1417
+     * Get the invoice totals.
1418
+     *
1419
+     * @since 1.0.19
1420 1420
      * @return float
1421
-	 */
1422
-	public function get_totals() {
1423
-		return $this->totals;
1421
+     */
1422
+    public function get_totals() {
1423
+        return $this->totals;
1424 1424
     }
1425 1425
 
1426 1426
     /**
1427
-	 * Get the initial invoice total.
1428
-	 *
1429
-	 * @since 1.0.19
1427
+     * Get the initial invoice total.
1428
+     *
1429
+     * @since 1.0.19
1430 1430
      * @param  string $context View or edit context.
1431 1431
      * @return float
1432
-	 */
1432
+     */
1433 1433
     public function get_initial_total() {
1434 1434
 
1435
-		if ( empty( $this->totals ) ) {
1436
-			$this->recalculate_total();
1437
-		}
1435
+        if ( empty( $this->totals ) ) {
1436
+            $this->recalculate_total();
1437
+        }
1438 1438
 
1439
-		$tax      = $this->totals['tax']['initial'];
1440
-		$fee      = $this->totals['fee']['initial'];
1441
-		$discount = $this->totals['discount']['initial'];
1442
-		$subtotal = $this->totals['subtotal']['initial'];
1443
-		$total    = $tax + $fee - $discount + $subtotal;
1439
+        $tax      = $this->totals['tax']['initial'];
1440
+        $fee      = $this->totals['fee']['initial'];
1441
+        $discount = $this->totals['discount']['initial'];
1442
+        $subtotal = $this->totals['subtotal']['initial'];
1443
+        $total    = $tax + $fee - $discount + $subtotal;
1444 1444
 
1445
-		if ( 0 > $total ) {
1446
-			$total = 0;
1447
-		}
1445
+        if ( 0 > $total ) {
1446
+            $total = 0;
1447
+        }
1448 1448
 
1449 1449
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1450
-	}
1450
+    }
1451 1451
 
1452
-	/**
1453
-	 * Get the recurring invoice total.
1454
-	 *
1455
-	 * @since 1.0.19
1452
+    /**
1453
+     * Get the recurring invoice total.
1454
+     *
1455
+     * @since 1.0.19
1456 1456
      * @param  string $context View or edit context.
1457 1457
      * @return float
1458
-	 */
1458
+     */
1459 1459
     public function get_recurring_total() {
1460 1460
 
1461
-		if ( empty( $this->totals ) ) {
1462
-			$this->recalculate_total();
1463
-		}
1461
+        if ( empty( $this->totals ) ) {
1462
+            $this->recalculate_total();
1463
+        }
1464 1464
 
1465
-		$tax      = $this->totals['tax']['recurring'];
1466
-		$fee      = $this->totals['fee']['recurring'];
1467
-		$discount = $this->totals['discount']['recurring'];
1468
-		$subtotal = $this->totals['subtotal']['recurring'];
1469
-		$total    = $tax + $fee - $discount + $subtotal;
1465
+        $tax      = $this->totals['tax']['recurring'];
1466
+        $fee      = $this->totals['fee']['recurring'];
1467
+        $discount = $this->totals['discount']['recurring'];
1468
+        $subtotal = $this->totals['subtotal']['recurring'];
1469
+        $total    = $tax + $fee - $discount + $subtotal;
1470 1470
 
1471
-		if ( 0 > $total ) {
1472
-			$total = 0;
1473
-		}
1471
+        if ( 0 > $total ) {
1472
+            $total = 0;
1473
+        }
1474 1474
 
1475 1475
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1476
-	}
1476
+    }
1477 1477
 
1478
-	/**
1479
-	 * Returns recurring payment details.
1480
-	 *
1481
-	 * @since 1.0.19
1478
+    /**
1479
+     * Returns recurring payment details.
1480
+     *
1481
+     * @since 1.0.19
1482 1482
      * @param  string $field Optionally provide a field to return.
1483
-	 * @param string $currency Whether to include the currency.
1483
+     * @param string $currency Whether to include the currency.
1484 1484
      * @return float
1485
-	 */
1485
+     */
1486 1486
     public function get_recurring_details( $field = '', $currency = false ) {
1487 1487
 
1488
-		// Maybe recalculate totals.
1489
-		if ( empty( $this->totals ) ) {
1490
-			$this->recalculate_total();
1491
-		}
1488
+        // Maybe recalculate totals.
1489
+        if ( empty( $this->totals ) ) {
1490
+            $this->recalculate_total();
1491
+        }
1492 1492
 
1493
-		// Prepare recurring totals.
1493
+        // Prepare recurring totals.
1494 1494
         $data = apply_filters(
1495
-			'wpinv_get_invoice_recurring_details',
1496
-			array(
1497
-				'cart_details' => $this->get_cart_details(),
1498
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1499
-				'discount'     => $this->totals['discount']['recurring'],
1500
-				'tax'          => $this->totals['tax']['recurring'],
1501
-				'fee'          => $this->totals['fee']['recurring'],
1502
-				'total'        => $this->get_recurring_total(),
1503
-			),
1504
-			$this,
1505
-			$field,
1506
-			$currency
1507
-		);
1495
+            'wpinv_get_invoice_recurring_details',
1496
+            array(
1497
+                'cart_details' => $this->get_cart_details(),
1498
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1499
+                'discount'     => $this->totals['discount']['recurring'],
1500
+                'tax'          => $this->totals['tax']['recurring'],
1501
+                'fee'          => $this->totals['fee']['recurring'],
1502
+                'total'        => $this->get_recurring_total(),
1503
+            ),
1504
+            $this,
1505
+            $field,
1506
+            $currency
1507
+        );
1508 1508
 
1509 1509
         if ( isset( $data[$field] ) ) {
1510 1510
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1514,156 +1514,156 @@  discard block
 block discarded – undo
1514 1514
     }
1515 1515
 
1516 1516
     /**
1517
-	 * Get the invoice fees.
1518
-	 *
1519
-	 * @since 1.0.19
1520
-	 * @param  string $context View or edit context.
1521
-	 * @return array
1522
-	 */
1523
-	public function get_fees( $context = 'view' ) {
1524
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1517
+     * Get the invoice fees.
1518
+     *
1519
+     * @since 1.0.19
1520
+     * @param  string $context View or edit context.
1521
+     * @return array
1522
+     */
1523
+    public function get_fees( $context = 'view' ) {
1524
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1525 1525
     }
1526 1526
 
1527 1527
     /**
1528
-	 * Get the invoice discounts.
1529
-	 *
1530
-	 * @since 1.0.19
1531
-	 * @param  string $context View or edit context.
1532
-	 * @return array
1533
-	 */
1534
-	public function get_discounts( $context = 'view' ) {
1535
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1528
+     * Get the invoice discounts.
1529
+     *
1530
+     * @since 1.0.19
1531
+     * @param  string $context View or edit context.
1532
+     * @return array
1533
+     */
1534
+    public function get_discounts( $context = 'view' ) {
1535
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1536 1536
     }
1537 1537
 
1538 1538
     /**
1539
-	 * Get the invoice taxes.
1540
-	 *
1541
-	 * @since 1.0.19
1542
-	 * @param  string $context View or edit context.
1543
-	 * @return array
1544
-	 */
1545
-	public function get_taxes( $context = 'view' ) {
1546
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1539
+     * Get the invoice taxes.
1540
+     *
1541
+     * @since 1.0.19
1542
+     * @param  string $context View or edit context.
1543
+     * @return array
1544
+     */
1545
+    public function get_taxes( $context = 'view' ) {
1546
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1547 1547
     }
1548 1548
 
1549 1549
     /**
1550
-	 * Get the invoice items.
1551
-	 *
1552
-	 * @since 1.0.19
1553
-	 * @param  string $context View or edit context.
1554
-	 * @return GetPaid_Form_Item[]
1555
-	 */
1556
-	public function get_items( $context = 'view' ) {
1550
+     * Get the invoice items.
1551
+     *
1552
+     * @since 1.0.19
1553
+     * @param  string $context View or edit context.
1554
+     * @return GetPaid_Form_Item[]
1555
+     */
1556
+    public function get_items( $context = 'view' ) {
1557 1557
         return $this->get_prop( 'items', $context );
1558 1558
     }
1559 1559
 
1560 1560
     /**
1561
-	 * Get the invoice's payment form.
1562
-	 *
1563
-	 * @since 1.0.19
1564
-	 * @param  string $context View or edit context.
1565
-	 * @return int
1566
-	 */
1567
-	public function get_payment_form( $context = 'view' ) {
1568
-		return intval( $this->get_prop( 'payment_form', $context ) );
1561
+     * Get the invoice's payment form.
1562
+     *
1563
+     * @since 1.0.19
1564
+     * @param  string $context View or edit context.
1565
+     * @return int
1566
+     */
1567
+    public function get_payment_form( $context = 'view' ) {
1568
+        return intval( $this->get_prop( 'payment_form', $context ) );
1569 1569
     }
1570 1570
 
1571 1571
     /**
1572
-	 * Get the invoice's submission id.
1573
-	 *
1574
-	 * @since 1.0.19
1575
-	 * @param  string $context View or edit context.
1576
-	 * @return string
1577
-	 */
1578
-	public function get_submission_id( $context = 'view' ) {
1579
-		return $this->get_prop( 'submission_id', $context );
1572
+     * Get the invoice's submission id.
1573
+     *
1574
+     * @since 1.0.19
1575
+     * @param  string $context View or edit context.
1576
+     * @return string
1577
+     */
1578
+    public function get_submission_id( $context = 'view' ) {
1579
+        return $this->get_prop( 'submission_id', $context );
1580 1580
     }
1581 1581
 
1582 1582
     /**
1583
-	 * Get the invoice's discount code.
1584
-	 *
1585
-	 * @since 1.0.19
1586
-	 * @param  string $context View or edit context.
1587
-	 * @return string
1588
-	 */
1589
-	public function get_discount_code( $context = 'view' ) {
1590
-		return $this->get_prop( 'discount_code', $context );
1583
+     * Get the invoice's discount code.
1584
+     *
1585
+     * @since 1.0.19
1586
+     * @param  string $context View or edit context.
1587
+     * @return string
1588
+     */
1589
+    public function get_discount_code( $context = 'view' ) {
1590
+        return $this->get_prop( 'discount_code', $context );
1591 1591
     }
1592 1592
 
1593 1593
     /**
1594
-	 * Get the invoice's gateway.
1595
-	 *
1596
-	 * @since 1.0.19
1597
-	 * @param  string $context View or edit context.
1598
-	 * @return string
1599
-	 */
1600
-	public function get_gateway( $context = 'view' ) {
1601
-		return $this->get_prop( 'gateway', $context );
1594
+     * Get the invoice's gateway.
1595
+     *
1596
+     * @since 1.0.19
1597
+     * @param  string $context View or edit context.
1598
+     * @return string
1599
+     */
1600
+    public function get_gateway( $context = 'view' ) {
1601
+        return $this->get_prop( 'gateway', $context );
1602 1602
     }
1603 1603
 
1604 1604
     /**
1605
-	 * Get the invoice's gateway display title.
1606
-	 *
1607
-	 * @since 1.0.19
1608
-	 * @return string
1609
-	 */
1605
+     * Get the invoice's gateway display title.
1606
+     *
1607
+     * @since 1.0.19
1608
+     * @return string
1609
+     */
1610 1610
     public function get_gateway_title() {
1611 1611
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1612 1612
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1613 1613
     }
1614 1614
 
1615 1615
     /**
1616
-	 * Get the invoice's transaction id.
1617
-	 *
1618
-	 * @since 1.0.19
1619
-	 * @param  string $context View or edit context.
1620
-	 * @return string
1621
-	 */
1622
-	public function get_transaction_id( $context = 'view' ) {
1623
-		return $this->get_prop( 'transaction_id', $context );
1616
+     * Get the invoice's transaction id.
1617
+     *
1618
+     * @since 1.0.19
1619
+     * @param  string $context View or edit context.
1620
+     * @return string
1621
+     */
1622
+    public function get_transaction_id( $context = 'view' ) {
1623
+        return $this->get_prop( 'transaction_id', $context );
1624 1624
     }
1625 1625
 
1626 1626
     /**
1627
-	 * Get the invoice's currency.
1628
-	 *
1629
-	 * @since 1.0.19
1630
-	 * @param  string $context View or edit context.
1631
-	 * @return string
1632
-	 */
1633
-	public function get_currency( $context = 'view' ) {
1627
+     * Get the invoice's currency.
1628
+     *
1629
+     * @since 1.0.19
1630
+     * @param  string $context View or edit context.
1631
+     * @return string
1632
+     */
1633
+    public function get_currency( $context = 'view' ) {
1634 1634
         $currency = $this->get_prop( 'currency', $context );
1635 1635
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1636 1636
     }
1637 1637
 
1638 1638
     /**
1639
-	 * Checks if we are charging taxes for this invoice.
1640
-	 *
1641
-	 * @since 1.0.19
1642
-	 * @param  string $context View or edit context.
1643
-	 * @return bool
1644
-	 */
1645
-	public function get_disable_taxes( $context = 'view' ) {
1639
+     * Checks if we are charging taxes for this invoice.
1640
+     *
1641
+     * @since 1.0.19
1642
+     * @param  string $context View or edit context.
1643
+     * @return bool
1644
+     */
1645
+    public function get_disable_taxes( $context = 'view' ) {
1646 1646
         return (bool) $this->get_prop( 'disable_taxes', $context );
1647 1647
     }
1648 1648
 
1649 1649
     /**
1650
-	 * Retrieves the subscription id for an invoice.
1651
-	 *
1652
-	 * @since 1.0.19
1653
-	 * @param  string $context View or edit context.
1654
-	 * @return int
1655
-	 */
1650
+     * Retrieves the subscription id for an invoice.
1651
+     *
1652
+     * @since 1.0.19
1653
+     * @param  string $context View or edit context.
1654
+     * @return int
1655
+     */
1656 1656
     public function get_subscription_id( $context = 'view' ) {
1657
-		return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1658
-	}
1659
-
1660
-	/**
1661
-	 * Retrieves the remote subscription id for an invoice.
1662
-	 *
1663
-	 * @since 1.0.19
1664
-	 * @param  string $context View or edit context.
1665
-	 * @return int
1666
-	 */
1657
+        return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1658
+    }
1659
+
1660
+    /**
1661
+     * Retrieves the remote subscription id for an invoice.
1662
+     *
1663
+     * @since 1.0.19
1664
+     * @param  string $context View or edit context.
1665
+     * @return int
1666
+     */
1667 1667
     public function get_remote_subscription_id( $context = 'view' ) {
1668 1668
         $subscription_id = $this->get_prop( 'remote_subscription_id', $context );
1669 1669
 
@@ -1676,12 +1676,12 @@  discard block
 block discarded – undo
1676 1676
     }
1677 1677
 
1678 1678
     /**
1679
-	 * Retrieves the payment meta for an invoice.
1680
-	 *
1681
-	 * @since 1.0.19
1682
-	 * @param  string $context View or edit context.
1683
-	 * @return array
1684
-	 */
1679
+     * Retrieves the payment meta for an invoice.
1680
+     *
1681
+     * @since 1.0.19
1682
+     * @param  string $context View or edit context.
1683
+     * @return array
1684
+     */
1685 1685
     public function get_payment_meta( $context = 'view' ) {
1686 1686
 
1687 1687
         return array(
@@ -1701,31 +1701,31 @@  discard block
 block discarded – undo
1701 1701
     }
1702 1702
 
1703 1703
     /**
1704
-	 * Retrieves the cart details for an invoice.
1705
-	 *
1706
-	 * @since 1.0.19
1707
-	 * @return array
1708
-	 */
1704
+     * Retrieves the cart details for an invoice.
1705
+     *
1706
+     * @since 1.0.19
1707
+     * @return array
1708
+     */
1709 1709
     public function get_cart_details() {
1710 1710
         $items        = $this->get_items();
1711 1711
         $cart_details = array();
1712 1712
 
1713 1713
         foreach ( $items as $item_id => $item ) {
1714
-			$item->invoice_id = $this->get_id();
1714
+            $item->invoice_id = $this->get_id();
1715 1715
             $cart_details[]   = $item->prepare_data_for_saving();
1716 1716
         }
1717 1717
 
1718 1718
         return $cart_details;
1719
-	}
1719
+    }
1720 1720
 
1721
-	/**
1722
-	 * Retrieves the recurring item.
1723
-	 *
1724
-	 * @return null|GetPaid_Form_Item|int
1725
-	 */
1726
-	public function get_recurring( $object = false ) {
1721
+    /**
1722
+     * Retrieves the recurring item.
1723
+     *
1724
+     * @return null|GetPaid_Form_Item|int
1725
+     */
1726
+    public function get_recurring( $object = false ) {
1727 1727
 
1728
-		// Are we returning an object?
1728
+        // Are we returning an object?
1729 1729
         if ( $object ) {
1730 1730
             return $this->get_item( $this->recurring_item );
1731 1731
         }
@@ -1733,100 +1733,100 @@  discard block
 block discarded – undo
1733 1733
         return $this->recurring_item;
1734 1734
     }
1735 1735
 
1736
-	/**
1737
-	 * Retrieves the subscription name.
1738
-	 *
1739
-	 * @since 1.0.19
1740
-	 * @return string
1741
-	 */
1742
-	public function get_subscription_name() {
1736
+    /**
1737
+     * Retrieves the subscription name.
1738
+     *
1739
+     * @since 1.0.19
1740
+     * @return string
1741
+     */
1742
+    public function get_subscription_name() {
1743 1743
 
1744
-		// Retrieve the recurring name
1744
+        // Retrieve the recurring name
1745 1745
         $item = $this->get_recurring( true );
1746 1746
 
1747
-		// Abort if it does not exist.
1747
+        // Abort if it does not exist.
1748 1748
         if ( empty( $item ) ) {
1749 1749
             return '';
1750 1750
         }
1751 1751
 
1752
-		// Return the item name.
1752
+        // Return the item name.
1753 1753
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1754
-	}
1755
-
1756
-	/**
1757
-	 * Retrieves the view url.
1758
-	 *
1759
-	 * @since 1.0.19
1760
-	 * @return string
1761
-	 */
1762
-	public function get_view_url() {
1754
+    }
1755
+
1756
+    /**
1757
+     * Retrieves the view url.
1758
+     *
1759
+     * @since 1.0.19
1760
+     * @return string
1761
+     */
1762
+    public function get_view_url() {
1763 1763
         $invoice_url = get_permalink( $this->get_id() );
1764
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1764
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1765 1765
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1766
-	}
1766
+    }
1767 1767
 
1768
-	/**
1769
-	 * Retrieves the payment url.
1770
-	 *
1771
-	 * @since 1.0.19
1772
-	 * @return string
1773
-	 */
1774
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1768
+    /**
1769
+     * Retrieves the payment url.
1770
+     *
1771
+     * @since 1.0.19
1772
+     * @return string
1773
+     */
1774
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1775 1775
 
1776
-		// Retrieve the checkout url.
1776
+        // Retrieve the checkout url.
1777 1777
         $pay_url = wpinv_get_checkout_uri();
1778 1778
 
1779
-		// Maybe force ssl.
1779
+        // Maybe force ssl.
1780 1780
         if ( is_ssl() ) {
1781 1781
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1782 1782
         }
1783 1783
 
1784
-		// Add the invoice key.
1785
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1784
+        // Add the invoice key.
1785
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1786 1786
 
1787
-		// (Maybe?) add a secret
1787
+        // (Maybe?) add a secret
1788 1788
         if ( $secret ) {
1789 1789
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1790 1790
         }
1791 1791
 
1792 1792
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1793
-	}
1793
+    }
1794 1794
 	
1795
-	/**
1796
-	 * Retrieves the receipt url.
1797
-	 *
1798
-	 * @since 1.0.19
1799
-	 * @return string
1800
-	 */
1801
-	public function get_receipt_url() {
1802
-
1803
-		// Retrieve the checkout url.
1795
+    /**
1796
+     * Retrieves the receipt url.
1797
+     *
1798
+     * @since 1.0.19
1799
+     * @return string
1800
+     */
1801
+    public function get_receipt_url() {
1802
+
1803
+        // Retrieve the checkout url.
1804 1804
         $receipt_url = wpinv_get_success_page_uri();
1805 1805
 
1806
-		// Maybe force ssl.
1806
+        // Maybe force ssl.
1807 1807
         if ( is_ssl() ) {
1808 1808
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1809 1809
         }
1810 1810
 
1811
-		// Add the invoice key.
1812
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1811
+        // Add the invoice key.
1812
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1813 1813
 
1814 1814
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1815 1815
     }
1816 1816
 
1817 1817
     /**
1818
-	 * Magic method for accessing invoice properties.
1819
-	 *
1820
-	 * @since 1.0.15
1821
-	 * @access public
1822
-	 *
1823
-	 * @param string $key Discount data to retrieve
1824
-	 * @param  string $context View or edit context.
1825
-	 * @return mixed Value of the given invoice property (if set).
1826
-	 */
1827
-	public function get( $key, $context = 'view' ) {
1818
+     * Magic method for accessing invoice properties.
1819
+     *
1820
+     * @since 1.0.15
1821
+     * @access public
1822
+     *
1823
+     * @param string $key Discount data to retrieve
1824
+     * @param  string $context View or edit context.
1825
+     * @return mixed Value of the given invoice property (if set).
1826
+     */
1827
+    public function get( $key, $context = 'view' ) {
1828 1828
         return $this->get_prop( $key, $context );
1829
-	}
1829
+    }
1830 1830
 
1831 1831
     /*
1832 1832
 	|--------------------------------------------------------------------------
@@ -1839,130 +1839,130 @@  discard block
 block discarded – undo
1839 1839
     */
1840 1840
 
1841 1841
     /**
1842
-	 * Magic method for setting invoice properties.
1843
-	 *
1844
-	 * @since 1.0.19
1845
-	 * @access public
1846
-	 *
1847
-	 * @param string $key Discount data to retrieve
1848
-	 * @param  mixed $value new value.
1849
-	 * @return mixed Value of the given invoice property (if set).
1850
-	 */
1851
-	public function set( $key, $value ) {
1842
+     * Magic method for setting invoice properties.
1843
+     *
1844
+     * @since 1.0.19
1845
+     * @access public
1846
+     *
1847
+     * @param string $key Discount data to retrieve
1848
+     * @param  mixed $value new value.
1849
+     * @return mixed Value of the given invoice property (if set).
1850
+     */
1851
+    public function set( $key, $value ) {
1852 1852
 
1853 1853
         $setter = "set_$key";
1854 1854
         if ( is_callable( array( $this, $setter ) ) ) {
1855 1855
             $this->{$setter}( $value );
1856 1856
         }
1857 1857
 
1858
-	}
1858
+    }
1859 1859
 
1860
-	/**
1861
-	 * Sets item status.
1862
-	 *
1863
-	 * @since 1.0.19
1864
-	 * @param string $new_status    New status.
1865
-	 * @param string $note          Optional note to add.
1866
-	 * @param bool   $manual_update Is this a manual status change?.
1867
-	 * @return array details of change.
1868
-	 */
1869
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1870
-		$old_status = $this->get_status();
1860
+    /**
1861
+     * Sets item status.
1862
+     *
1863
+     * @since 1.0.19
1864
+     * @param string $new_status    New status.
1865
+     * @param string $note          Optional note to add.
1866
+     * @param bool   $manual_update Is this a manual status change?.
1867
+     * @return array details of change.
1868
+     */
1869
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1870
+        $old_status = $this->get_status();
1871 1871
 
1872
-		$statuses = $this->get_all_statuses();
1872
+        $statuses = $this->get_all_statuses();
1873 1873
 
1874
-		if ( isset( $statuses[ 'draft' ] ) ) {
1875
-			unset( $statuses[ 'draft' ] );
1876
-		}
1874
+        if ( isset( $statuses[ 'draft' ] ) ) {
1875
+            unset( $statuses[ 'draft' ] );
1876
+        }
1877 1877
 
1878
-		$this->set_prop( 'status', $new_status );
1878
+        $this->set_prop( 'status', $new_status );
1879 1879
 
1880
-		// If setting the status, ensure it's set to a valid status.
1881
-		if ( true === $this->object_read ) {
1880
+        // If setting the status, ensure it's set to a valid status.
1881
+        if ( true === $this->object_read ) {
1882 1882
 
1883
-			// Only allow valid new status.
1884
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1885
-				$new_status = 'wpi-pending';
1886
-			}
1883
+            // Only allow valid new status.
1884
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1885
+                $new_status = 'wpi-pending';
1886
+            }
1887 1887
 
1888
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1889
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1890
-				$old_status = 'wpi-pending';
1891
-			}
1888
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1889
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1890
+                $old_status = 'wpi-pending';
1891
+            }
1892 1892
 
1893
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1894
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1895
-				$old_status = 'wpi-pending';
1896
-			}
1893
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1894
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1895
+                $old_status = 'wpi-pending';
1896
+            }
1897 1897
 
1898
-		}
1898
+        }
1899 1899
 
1900
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1901
-			$this->status_transition = array(
1902
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1903
-				'to'     => $new_status,
1904
-				'note'   => $note,
1905
-				'manual' => (bool) $manual_update,
1906
-			);
1900
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1901
+            $this->status_transition = array(
1902
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1903
+                'to'     => $new_status,
1904
+                'note'   => $note,
1905
+                'manual' => (bool) $manual_update,
1906
+            );
1907 1907
 
1908
-			if ( $manual_update ) {
1909
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1910
-			}
1908
+            if ( $manual_update ) {
1909
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1910
+            }
1911 1911
 
1912
-			$this->maybe_set_date_paid();
1912
+            $this->maybe_set_date_paid();
1913 1913
 
1914
-		}
1914
+        }
1915 1915
 
1916
-		return array(
1917
-			'from' => $old_status,
1918
-			'to'   => $new_status,
1919
-		);
1920
-	}
1916
+        return array(
1917
+            'from' => $old_status,
1918
+            'to'   => $new_status,
1919
+        );
1920
+    }
1921 1921
 
1922
-	/**
1923
-	 * Maybe set date paid.
1924
-	 *
1925
-	 * Sets the date paid variable when transitioning to the payment complete
1926
-	 * order status.
1927
-	 *
1928
-	 * @since 1.0.19
1929
-	 */
1930
-	public function maybe_set_date_paid() {
1922
+    /**
1923
+     * Maybe set date paid.
1924
+     *
1925
+     * Sets the date paid variable when transitioning to the payment complete
1926
+     * order status.
1927
+     *
1928
+     * @since 1.0.19
1929
+     */
1930
+    public function maybe_set_date_paid() {
1931 1931
 
1932
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1933
-			$this->set_date_completed( current_time( 'mysql' ) );
1934
-		}
1935
-	}
1932
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1933
+            $this->set_date_completed( current_time( 'mysql' ) );
1934
+        }
1935
+    }
1936 1936
 
1937 1937
     /**
1938
-	 * Set parent invoice ID.
1939
-	 *
1940
-	 * @since 1.0.19
1941
-	 */
1942
-	public function set_parent_id( $value ) {
1943
-		if ( $value && ( $value === $this->get_id() ) ) {
1944
-			return;
1945
-		}
1946
-		$this->set_prop( 'parent_id', absint( $value ) );
1938
+     * Set parent invoice ID.
1939
+     *
1940
+     * @since 1.0.19
1941
+     */
1942
+    public function set_parent_id( $value ) {
1943
+        if ( $value && ( $value === $this->get_id() ) ) {
1944
+            return;
1945
+        }
1946
+        $this->set_prop( 'parent_id', absint( $value ) );
1947 1947
     }
1948 1948
 
1949 1949
     /**
1950
-	 * Set plugin version when the invoice was created.
1951
-	 *
1952
-	 * @since 1.0.19
1953
-	 */
1954
-	public function set_version( $value ) {
1955
-		$this->set_prop( 'version', $value );
1950
+     * Set plugin version when the invoice was created.
1951
+     *
1952
+     * @since 1.0.19
1953
+     */
1954
+    public function set_version( $value ) {
1955
+        $this->set_prop( 'version', $value );
1956 1956
     }
1957
-
1958
-    /**
1959
-	 * Set date when the invoice was created.
1960
-	 *
1961
-	 * @since 1.0.19
1962
-	 * @param string $value Value to set.
1957
+
1958
+    /**
1959
+     * Set date when the invoice was created.
1960
+     *
1961
+     * @since 1.0.19
1962
+     * @param string $value Value to set.
1963 1963
      * @return bool Whether or not the date was set.
1964
-	 */
1965
-	public function set_date_created( $value ) {
1964
+     */
1965
+    public function set_date_created( $value ) {
1966 1966
         $date = strtotime( $value );
1967 1967
 
1968 1968
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1975,13 +1975,13 @@  discard block
 block discarded – undo
1975 1975
     }
1976 1976
 
1977 1977
     /**
1978
-	 * Set date invoice due date.
1979
-	 *
1980
-	 * @since 1.0.19
1981
-	 * @param string $value Value to set.
1978
+     * Set date invoice due date.
1979
+     *
1980
+     * @since 1.0.19
1981
+     * @param string $value Value to set.
1982 1982
      * @return bool Whether or not the date was set.
1983
-	 */
1984
-	public function set_due_date( $value ) {
1983
+     */
1984
+    public function set_due_date( $value ) {
1985 1985
         $date = strtotime( $value );
1986 1986
 
1987 1987
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1989,29 +1989,29 @@  discard block
 block discarded – undo
1989 1989
             return true;
1990 1990
         }
1991 1991
 
1992
-		$this->set_prop( 'due_date', '' );
1992
+        $this->set_prop( 'due_date', '' );
1993 1993
         return false;
1994 1994
 
1995 1995
     }
1996 1996
 
1997 1997
     /**
1998
-	 * Alias of self::set_due_date().
1999
-	 *
2000
-	 * @since 1.0.19
2001
-	 * @param  string $value New name.
2002
-	 */
2003
-	public function set_date_due( $value ) {
2004
-		$this->set_due_date( $value );
1998
+     * Alias of self::set_due_date().
1999
+     *
2000
+     * @since 1.0.19
2001
+     * @param  string $value New name.
2002
+     */
2003
+    public function set_date_due( $value ) {
2004
+        $this->set_due_date( $value );
2005 2005
     }
2006 2006
 
2007 2007
     /**
2008
-	 * Set date invoice was completed.
2009
-	 *
2010
-	 * @since 1.0.19
2011
-	 * @param string $value Value to set.
2008
+     * Set date invoice was completed.
2009
+     *
2010
+     * @since 1.0.19
2011
+     * @param string $value Value to set.
2012 2012
      * @return bool Whether or not the date was set.
2013
-	 */
2014
-	public function set_completed_date( $value ) {
2013
+     */
2014
+    public function set_completed_date( $value ) {
2015 2015
         $date = strtotime( $value );
2016 2016
 
2017 2017
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -2019,29 +2019,29 @@  discard block
 block discarded – undo
2019 2019
             return true;
2020 2020
         }
2021 2021
 
2022
-		$this->set_prop( 'completed_date', '' );
2022
+        $this->set_prop( 'completed_date', '' );
2023 2023
         return false;
2024 2024
 
2025 2025
     }
2026 2026
 
2027 2027
     /**
2028
-	 * Alias of self::set_completed_date().
2029
-	 *
2030
-	 * @since 1.0.19
2031
-	 * @param  string $value New name.
2032
-	 */
2033
-	public function set_date_completed( $value ) {
2034
-		$this->set_completed_date( $value );
2028
+     * Alias of self::set_completed_date().
2029
+     *
2030
+     * @since 1.0.19
2031
+     * @param  string $value New name.
2032
+     */
2033
+    public function set_date_completed( $value ) {
2034
+        $this->set_completed_date( $value );
2035 2035
     }
2036 2036
 
2037 2037
     /**
2038
-	 * Set date when the invoice was last modified.
2039
-	 *
2040
-	 * @since 1.0.19
2041
-	 * @param string $value Value to set.
2038
+     * Set date when the invoice was last modified.
2039
+     *
2040
+     * @since 1.0.19
2041
+     * @param string $value Value to set.
2042 2042
      * @return bool Whether or not the date was set.
2043
-	 */
2044
-	public function set_date_modified( $value ) {
2043
+     */
2044
+    public function set_date_modified( $value ) {
2045 2045
         $date = strtotime( $value );
2046 2046
 
2047 2047
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2049,763 +2049,763 @@  discard block
 block discarded – undo
2049 2049
             return true;
2050 2050
         }
2051 2051
 
2052
-		$this->set_prop( 'date_modified', '' );
2052
+        $this->set_prop( 'date_modified', '' );
2053 2053
         return false;
2054 2054
 
2055 2055
     }
2056 2056
 
2057 2057
     /**
2058
-	 * Set the invoice number.
2059
-	 *
2060
-	 * @since 1.0.19
2061
-	 * @param  string $value New number.
2062
-	 */
2063
-	public function set_number( $value ) {
2058
+     * Set the invoice number.
2059
+     *
2060
+     * @since 1.0.19
2061
+     * @param  string $value New number.
2062
+     */
2063
+    public function set_number( $value ) {
2064 2064
         $number = sanitize_text_field( $value );
2065
-		$this->set_prop( 'number', $number );
2065
+        $this->set_prop( 'number', $number );
2066 2066
     }
2067 2067
 
2068 2068
     /**
2069
-	 * Set the invoice type.
2070
-	 *
2071
-	 * @since 1.0.19
2072
-	 * @param  string $value Type.
2073
-	 */
2074
-	public function set_type( $value ) {
2069
+     * Set the invoice type.
2070
+     *
2071
+     * @since 1.0.19
2072
+     * @param  string $value Type.
2073
+     */
2074
+    public function set_type( $value ) {
2075 2075
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2076
-		$this->set_prop( 'type', $type );
2077
-	}
2076
+        $this->set_prop( 'type', $type );
2077
+    }
2078 2078
 
2079 2079
     /**
2080
-	 * Set the invoice post type.
2081
-	 *
2082
-	 * @since 1.0.19
2083
-	 * @param  string $value Post type.
2084
-	 */
2085
-	public function set_post_type( $value ) {
2080
+     * Set the invoice post type.
2081
+     *
2082
+     * @since 1.0.19
2083
+     * @param  string $value Post type.
2084
+     */
2085
+    public function set_post_type( $value ) {
2086 2086
         if ( getpaid_is_invoice_post_type( $value ) ) {
2087
-			$this->set_type( $value );
2087
+            $this->set_type( $value );
2088 2088
             $this->set_prop( 'post_type', $value );
2089 2089
         }
2090 2090
     }
2091 2091
 
2092 2092
     /**
2093
-	 * Set the invoice key.
2094
-	 *
2095
-	 * @since 1.0.19
2096
-	 * @param  string $value New key.
2097
-	 */
2098
-	public function set_key( $value ) {
2093
+     * Set the invoice key.
2094
+     *
2095
+     * @since 1.0.19
2096
+     * @param  string $value New key.
2097
+     */
2098
+    public function set_key( $value ) {
2099 2099
         $key = sanitize_text_field( $value );
2100
-		$this->set_prop( 'key', $key );
2100
+        $this->set_prop( 'key', $key );
2101 2101
     }
2102 2102
 
2103 2103
     /**
2104
-	 * Set the invoice mode.
2105
-	 *
2106
-	 * @since 1.0.19
2107
-	 * @param  string $value mode.
2108
-	 */
2109
-	public function set_mode( $value ) {
2104
+     * Set the invoice mode.
2105
+     *
2106
+     * @since 1.0.19
2107
+     * @param  string $value mode.
2108
+     */
2109
+    public function set_mode( $value ) {
2110 2110
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2111 2111
             $this->set_prop( 'value', $value );
2112 2112
         }
2113 2113
     }
2114 2114
 
2115 2115
     /**
2116
-	 * Set the invoice path.
2117
-	 *
2118
-	 * @since 1.0.19
2119
-	 * @param  string $value path.
2120
-	 */
2121
-	public function set_path( $value ) {
2116
+     * Set the invoice path.
2117
+     *
2118
+     * @since 1.0.19
2119
+     * @param  string $value path.
2120
+     */
2121
+    public function set_path( $value ) {
2122 2122
         $this->set_prop( 'path', $value );
2123 2123
     }
2124 2124
 
2125 2125
     /**
2126
-	 * Set the invoice name.
2127
-	 *
2128
-	 * @since 1.0.19
2129
-	 * @param  string $value New name.
2130
-	 */
2131
-	public function set_name( $value ) {
2126
+     * Set the invoice name.
2127
+     *
2128
+     * @since 1.0.19
2129
+     * @param  string $value New name.
2130
+     */
2131
+    public function set_name( $value ) {
2132 2132
         $name = sanitize_text_field( $value );
2133
-		$this->set_prop( 'name', $name );
2133
+        $this->set_prop( 'name', $name );
2134 2134
     }
2135 2135
 
2136 2136
     /**
2137
-	 * Alias of self::set_name().
2138
-	 *
2139
-	 * @since 1.0.19
2140
-	 * @param  string $value New name.
2141
-	 */
2142
-	public function set_title( $value ) {
2143
-		$this->set_name( $value );
2137
+     * Alias of self::set_name().
2138
+     *
2139
+     * @since 1.0.19
2140
+     * @param  string $value New name.
2141
+     */
2142
+    public function set_title( $value ) {
2143
+        $this->set_name( $value );
2144 2144
     }
2145 2145
 
2146 2146
     /**
2147
-	 * Set the invoice description.
2148
-	 *
2149
-	 * @since 1.0.19
2150
-	 * @param  string $value New description.
2151
-	 */
2152
-	public function set_description( $value ) {
2147
+     * Set the invoice description.
2148
+     *
2149
+     * @since 1.0.19
2150
+     * @param  string $value New description.
2151
+     */
2152
+    public function set_description( $value ) {
2153 2153
         $description = wp_kses_post( $value );
2154
-		return $this->set_prop( 'description', $description );
2154
+        return $this->set_prop( 'description', $description );
2155 2155
     }
2156 2156
 
2157 2157
     /**
2158
-	 * Alias of self::set_description().
2159
-	 *
2160
-	 * @since 1.0.19
2161
-	 * @param  string $value New description.
2162
-	 */
2163
-	public function set_excerpt( $value ) {
2164
-		$this->set_description( $value );
2158
+     * Alias of self::set_description().
2159
+     *
2160
+     * @since 1.0.19
2161
+     * @param  string $value New description.
2162
+     */
2163
+    public function set_excerpt( $value ) {
2164
+        $this->set_description( $value );
2165 2165
     }
2166 2166
 
2167 2167
     /**
2168
-	 * Alias of self::set_description().
2169
-	 *
2170
-	 * @since 1.0.19
2171
-	 * @param  string $value New description.
2172
-	 */
2173
-	public function set_summary( $value ) {
2174
-		$this->set_description( $value );
2168
+     * Alias of self::set_description().
2169
+     *
2170
+     * @since 1.0.19
2171
+     * @param  string $value New description.
2172
+     */
2173
+    public function set_summary( $value ) {
2174
+        $this->set_description( $value );
2175 2175
     }
2176 2176
 
2177 2177
     /**
2178
-	 * Set the receiver of the invoice.
2179
-	 *
2180
-	 * @since 1.0.19
2181
-	 * @param  int $value New author.
2182
-	 */
2183
-	public function set_author( $value ) {
2184
-		$user = get_user_by( 'id', (int) $value );
2178
+     * Set the receiver of the invoice.
2179
+     *
2180
+     * @since 1.0.19
2181
+     * @param  int $value New author.
2182
+     */
2183
+    public function set_author( $value ) {
2184
+        $user = get_user_by( 'id', (int) $value );
2185 2185
 
2186
-		if ( $user && $user->ID ) {
2187
-			$this->set_prop( 'author', $user->ID );
2188
-			$this->set_prop( 'email', $user->user_email );
2189
-		}
2186
+        if ( $user && $user->ID ) {
2187
+            $this->set_prop( 'author', $user->ID );
2188
+            $this->set_prop( 'email', $user->user_email );
2189
+        }
2190 2190
 		
2191 2191
     }
2192 2192
 
2193 2193
     /**
2194
-	 * Alias of self::set_author().
2195
-	 *
2196
-	 * @since 1.0.19
2197
-	 * @param  int $value New user id.
2198
-	 */
2199
-	public function set_user_id( $value ) {
2200
-		$this->set_author( $value );
2194
+     * Alias of self::set_author().
2195
+     *
2196
+     * @since 1.0.19
2197
+     * @param  int $value New user id.
2198
+     */
2199
+    public function set_user_id( $value ) {
2200
+        $this->set_author( $value );
2201
+    }
2202
+
2203
+    /**
2204
+     * Alias of self::set_author().
2205
+     *
2206
+     * @since 1.0.19
2207
+     * @param  int $value New user id.
2208
+     */
2209
+    public function set_customer_id( $value ) {
2210
+        $this->set_author( $value );
2211
+    }
2212
+
2213
+    /**
2214
+     * Set the customer's ip.
2215
+     *
2216
+     * @since 1.0.19
2217
+     * @param  string $value ip address.
2218
+     */
2219
+    public function set_ip( $value ) {
2220
+        $this->set_prop( 'ip', $value );
2221
+    }
2222
+
2223
+    /**
2224
+     * Alias of self::set_ip().
2225
+     *
2226
+     * @since 1.0.19
2227
+     * @param  string $value ip address.
2228
+     */
2229
+    public function set_user_ip( $value ) {
2230
+        $this->set_ip( $value );
2231
+    }
2232
+
2233
+    /**
2234
+     * Set the customer's first name.
2235
+     *
2236
+     * @since 1.0.19
2237
+     * @param  string $value first name.
2238
+     */
2239
+    public function set_first_name( $value ) {
2240
+        $this->set_prop( 'first_name', $value );
2201 2241
     }
2202 2242
 
2203 2243
     /**
2204
-	 * Alias of self::set_author().
2205
-	 *
2206
-	 * @since 1.0.19
2207
-	 * @param  int $value New user id.
2208
-	 */
2209
-	public function set_customer_id( $value ) {
2210
-		$this->set_author( $value );
2244
+     * Alias of self::set_first_name().
2245
+     *
2246
+     * @since 1.0.19
2247
+     * @param  string $value first name.
2248
+     */
2249
+    public function set_user_first_name( $value ) {
2250
+        $this->set_first_name( $value );
2211 2251
     }
2212 2252
 
2213 2253
     /**
2214
-	 * Set the customer's ip.
2215
-	 *
2216
-	 * @since 1.0.19
2217
-	 * @param  string $value ip address.
2218
-	 */
2219
-	public function set_ip( $value ) {
2220
-		$this->set_prop( 'ip', $value );
2254
+     * Alias of self::set_first_name().
2255
+     *
2256
+     * @since 1.0.19
2257
+     * @param  string $value first name.
2258
+     */
2259
+    public function set_customer_first_name( $value ) {
2260
+        $this->set_first_name( $value );
2221 2261
     }
2222 2262
 
2223 2263
     /**
2224
-	 * Alias of self::set_ip().
2225
-	 *
2226
-	 * @since 1.0.19
2227
-	 * @param  string $value ip address.
2228
-	 */
2229
-	public function set_user_ip( $value ) {
2230
-		$this->set_ip( $value );
2264
+     * Set the customer's last name.
2265
+     *
2266
+     * @since 1.0.19
2267
+     * @param  string $value last name.
2268
+     */
2269
+    public function set_last_name( $value ) {
2270
+        $this->set_prop( 'last_name', $value );
2231 2271
     }
2232 2272
 
2233 2273
     /**
2234
-	 * Set the customer's first name.
2235
-	 *
2236
-	 * @since 1.0.19
2237
-	 * @param  string $value first name.
2238
-	 */
2239
-	public function set_first_name( $value ) {
2240
-		$this->set_prop( 'first_name', $value );
2274
+     * Alias of self::set_last_name().
2275
+     *
2276
+     * @since 1.0.19
2277
+     * @param  string $value last name.
2278
+     */
2279
+    public function set_user_last_name( $value ) {
2280
+        $this->set_last_name( $value );
2241 2281
     }
2242 2282
 
2243 2283
     /**
2244
-	 * Alias of self::set_first_name().
2245
-	 *
2246
-	 * @since 1.0.19
2247
-	 * @param  string $value first name.
2248
-	 */
2249
-	public function set_user_first_name( $value ) {
2250
-		$this->set_first_name( $value );
2284
+     * Alias of self::set_last_name().
2285
+     *
2286
+     * @since 1.0.19
2287
+     * @param  string $value last name.
2288
+     */
2289
+    public function set_customer_last_name( $value ) {
2290
+        $this->set_last_name( $value );
2251 2291
     }
2252 2292
 
2253 2293
     /**
2254
-	 * Alias of self::set_first_name().
2255
-	 *
2256
-	 * @since 1.0.19
2257
-	 * @param  string $value first name.
2258
-	 */
2259
-	public function set_customer_first_name( $value ) {
2260
-		$this->set_first_name( $value );
2294
+     * Set the customer's phone number.
2295
+     *
2296
+     * @since 1.0.19
2297
+     * @param  string $value phone.
2298
+     */
2299
+    public function set_phone( $value ) {
2300
+        $this->set_prop( 'phone', $value );
2261 2301
     }
2262 2302
 
2263 2303
     /**
2264
-	 * Set the customer's last name.
2265
-	 *
2266
-	 * @since 1.0.19
2267
-	 * @param  string $value last name.
2268
-	 */
2269
-	public function set_last_name( $value ) {
2270
-		$this->set_prop( 'last_name', $value );
2304
+     * Alias of self::set_phone().
2305
+     *
2306
+     * @since 1.0.19
2307
+     * @param  string $value phone.
2308
+     */
2309
+    public function set_user_phone( $value ) {
2310
+        $this->set_phone( $value );
2271 2311
     }
2272 2312
 
2273 2313
     /**
2274
-	 * Alias of self::set_last_name().
2275
-	 *
2276
-	 * @since 1.0.19
2277
-	 * @param  string $value last name.
2278
-	 */
2279
-	public function set_user_last_name( $value ) {
2280
-		$this->set_last_name( $value );
2314
+     * Alias of self::set_phone().
2315
+     *
2316
+     * @since 1.0.19
2317
+     * @param  string $value phone.
2318
+     */
2319
+    public function set_customer_phone( $value ) {
2320
+        $this->set_phone( $value );
2281 2321
     }
2282 2322
 
2283 2323
     /**
2284
-	 * Alias of self::set_last_name().
2285
-	 *
2286
-	 * @since 1.0.19
2287
-	 * @param  string $value last name.
2288
-	 */
2289
-	public function set_customer_last_name( $value ) {
2290
-		$this->set_last_name( $value );
2324
+     * Alias of self::set_phone().
2325
+     *
2326
+     * @since 1.0.19
2327
+     * @param  string $value phone.
2328
+     */
2329
+    public function set_phone_number( $value ) {
2330
+        $this->set_phone( $value );
2291 2331
     }
2292 2332
 
2293 2333
     /**
2294
-	 * Set the customer's phone number.
2295
-	 *
2296
-	 * @since 1.0.19
2297
-	 * @param  string $value phone.
2298
-	 */
2299
-	public function set_phone( $value ) {
2300
-		$this->set_prop( 'phone', $value );
2334
+     * Set the customer's email address.
2335
+     *
2336
+     * @since 1.0.19
2337
+     * @param  string $value email address.
2338
+     */
2339
+    public function set_email( $value ) {
2340
+        $this->set_prop( 'email', $value );
2301 2341
     }
2302 2342
 
2303 2343
     /**
2304
-	 * Alias of self::set_phone().
2305
-	 *
2306
-	 * @since 1.0.19
2307
-	 * @param  string $value phone.
2308
-	 */
2309
-	public function set_user_phone( $value ) {
2310
-		$this->set_phone( $value );
2344
+     * Alias of self::set_email().
2345
+     *
2346
+     * @since 1.0.19
2347
+     * @param  string $value email address.
2348
+     */
2349
+    public function set_user_email( $value ) {
2350
+        $this->set_email( $value );
2311 2351
     }
2312 2352
 
2313 2353
     /**
2314
-	 * Alias of self::set_phone().
2315
-	 *
2316
-	 * @since 1.0.19
2317
-	 * @param  string $value phone.
2318
-	 */
2319
-	public function set_customer_phone( $value ) {
2320
-		$this->set_phone( $value );
2354
+     * Alias of self::set_email().
2355
+     *
2356
+     * @since 1.0.19
2357
+     * @param  string $value email address.
2358
+     */
2359
+    public function set_email_address( $value ) {
2360
+        $this->set_email( $value );
2321 2361
     }
2322 2362
 
2323 2363
     /**
2324
-	 * Alias of self::set_phone().
2325
-	 *
2326
-	 * @since 1.0.19
2327
-	 * @param  string $value phone.
2328
-	 */
2329
-	public function set_phone_number( $value ) {
2330
-		$this->set_phone( $value );
2364
+     * Alias of self::set_email().
2365
+     *
2366
+     * @since 1.0.19
2367
+     * @param  string $value email address.
2368
+     */
2369
+    public function set_customer_email( $value ) {
2370
+        $this->set_email( $value );
2331 2371
     }
2332 2372
 
2333 2373
     /**
2334
-	 * Set the customer's email address.
2335
-	 *
2336
-	 * @since 1.0.19
2337
-	 * @param  string $value email address.
2338
-	 */
2339
-	public function set_email( $value ) {
2340
-		$this->set_prop( 'email', $value );
2374
+     * Set the customer's country.
2375
+     *
2376
+     * @since 1.0.19
2377
+     * @param  string $value country.
2378
+     */
2379
+    public function set_country( $value ) {
2380
+        $this->set_prop( 'country', $value );
2341 2381
     }
2342 2382
 
2343 2383
     /**
2344
-	 * Alias of self::set_email().
2345
-	 *
2346
-	 * @since 1.0.19
2347
-	 * @param  string $value email address.
2348
-	 */
2349
-	public function set_user_email( $value ) {
2350
-		$this->set_email( $value );
2384
+     * Alias of self::set_country().
2385
+     *
2386
+     * @since 1.0.19
2387
+     * @param  string $value country.
2388
+     */
2389
+    public function set_user_country( $value ) {
2390
+        $this->set_country( $value );
2351 2391
     }
2352 2392
 
2353 2393
     /**
2354
-	 * Alias of self::set_email().
2355
-	 *
2356
-	 * @since 1.0.19
2357
-	 * @param  string $value email address.
2358
-	 */
2359
-	public function set_email_address( $value ) {
2360
-		$this->set_email( $value );
2394
+     * Alias of self::set_country().
2395
+     *
2396
+     * @since 1.0.19
2397
+     * @param  string $value country.
2398
+     */
2399
+    public function set_customer_country( $value ) {
2400
+        $this->set_country( $value );
2361 2401
     }
2362 2402
 
2363 2403
     /**
2364
-	 * Alias of self::set_email().
2365
-	 *
2366
-	 * @since 1.0.19
2367
-	 * @param  string $value email address.
2368
-	 */
2369
-	public function set_customer_email( $value ) {
2370
-		$this->set_email( $value );
2404
+     * Set the customer's state.
2405
+     *
2406
+     * @since 1.0.19
2407
+     * @param  string $value state.
2408
+     */
2409
+    public function set_state( $value ) {
2410
+        $this->set_prop( 'state', $value );
2371 2411
     }
2372 2412
 
2373 2413
     /**
2374
-	 * Set the customer's country.
2375
-	 *
2376
-	 * @since 1.0.19
2377
-	 * @param  string $value country.
2378
-	 */
2379
-	public function set_country( $value ) {
2380
-		$this->set_prop( 'country', $value );
2414
+     * Alias of self::set_state().
2415
+     *
2416
+     * @since 1.0.19
2417
+     * @param  string $value state.
2418
+     */
2419
+    public function set_user_state( $value ) {
2420
+        $this->set_state( $value );
2381 2421
     }
2382 2422
 
2383 2423
     /**
2384
-	 * Alias of self::set_country().
2385
-	 *
2386
-	 * @since 1.0.19
2387
-	 * @param  string $value country.
2388
-	 */
2389
-	public function set_user_country( $value ) {
2390
-		$this->set_country( $value );
2424
+     * Alias of self::set_state().
2425
+     *
2426
+     * @since 1.0.19
2427
+     * @param  string $value state.
2428
+     */
2429
+    public function set_customer_state( $value ) {
2430
+        $this->set_state( $value );
2391 2431
     }
2392 2432
 
2393 2433
     /**
2394
-	 * Alias of self::set_country().
2395
-	 *
2396
-	 * @since 1.0.19
2397
-	 * @param  string $value country.
2398
-	 */
2399
-	public function set_customer_country( $value ) {
2400
-		$this->set_country( $value );
2434
+     * Set the customer's city.
2435
+     *
2436
+     * @since 1.0.19
2437
+     * @param  string $value city.
2438
+     */
2439
+    public function set_city( $value ) {
2440
+        $this->set_prop( 'city', $value );
2401 2441
     }
2402 2442
 
2403 2443
     /**
2404
-	 * Set the customer's state.
2405
-	 *
2406
-	 * @since 1.0.19
2407
-	 * @param  string $value state.
2408
-	 */
2409
-	public function set_state( $value ) {
2410
-		$this->set_prop( 'state', $value );
2444
+     * Alias of self::set_city().
2445
+     *
2446
+     * @since 1.0.19
2447
+     * @param  string $value city.
2448
+     */
2449
+    public function set_user_city( $value ) {
2450
+        $this->set_city( $value );
2411 2451
     }
2412 2452
 
2413 2453
     /**
2414
-	 * Alias of self::set_state().
2415
-	 *
2416
-	 * @since 1.0.19
2417
-	 * @param  string $value state.
2418
-	 */
2419
-	public function set_user_state( $value ) {
2420
-		$this->set_state( $value );
2454
+     * Alias of self::set_city().
2455
+     *
2456
+     * @since 1.0.19
2457
+     * @param  string $value city.
2458
+     */
2459
+    public function set_customer_city( $value ) {
2460
+        $this->set_city( $value );
2421 2461
     }
2422 2462
 
2423 2463
     /**
2424
-	 * Alias of self::set_state().
2425
-	 *
2426
-	 * @since 1.0.19
2427
-	 * @param  string $value state.
2428
-	 */
2429
-	public function set_customer_state( $value ) {
2430
-		$this->set_state( $value );
2464
+     * Set the customer's zip code.
2465
+     *
2466
+     * @since 1.0.19
2467
+     * @param  string $value zip.
2468
+     */
2469
+    public function set_zip( $value ) {
2470
+        $this->set_prop( 'zip', $value );
2431 2471
     }
2432 2472
 
2433 2473
     /**
2434
-	 * Set the customer's city.
2435
-	 *
2436
-	 * @since 1.0.19
2437
-	 * @param  string $value city.
2438
-	 */
2439
-	public function set_city( $value ) {
2440
-		$this->set_prop( 'city', $value );
2474
+     * Alias of self::set_zip().
2475
+     *
2476
+     * @since 1.0.19
2477
+     * @param  string $value zip.
2478
+     */
2479
+    public function set_user_zip( $value ) {
2480
+        $this->set_zip( $value );
2441 2481
     }
2442 2482
 
2443 2483
     /**
2444
-	 * Alias of self::set_city().
2445
-	 *
2446
-	 * @since 1.0.19
2447
-	 * @param  string $value city.
2448
-	 */
2449
-	public function set_user_city( $value ) {
2450
-		$this->set_city( $value );
2484
+     * Alias of self::set_zip().
2485
+     *
2486
+     * @since 1.0.19
2487
+     * @param  string $value zip.
2488
+     */
2489
+    public function set_customer_zip( $value ) {
2490
+        $this->set_zip( $value );
2451 2491
     }
2452 2492
 
2453 2493
     /**
2454
-	 * Alias of self::set_city().
2455
-	 *
2456
-	 * @since 1.0.19
2457
-	 * @param  string $value city.
2458
-	 */
2459
-	public function set_customer_city( $value ) {
2460
-		$this->set_city( $value );
2494
+     * Set the customer's company.
2495
+     *
2496
+     * @since 1.0.19
2497
+     * @param  string $value company.
2498
+     */
2499
+    public function set_company( $value ) {
2500
+        $this->set_prop( 'company', $value );
2461 2501
     }
2462 2502
 
2463 2503
     /**
2464
-	 * Set the customer's zip code.
2465
-	 *
2466
-	 * @since 1.0.19
2467
-	 * @param  string $value zip.
2468
-	 */
2469
-	public function set_zip( $value ) {
2470
-		$this->set_prop( 'zip', $value );
2504
+     * Alias of self::set_company().
2505
+     *
2506
+     * @since 1.0.19
2507
+     * @param  string $value company.
2508
+     */
2509
+    public function set_user_company( $value ) {
2510
+        $this->set_company( $value );
2471 2511
     }
2472 2512
 
2473 2513
     /**
2474
-	 * Alias of self::set_zip().
2475
-	 *
2476
-	 * @since 1.0.19
2477
-	 * @param  string $value zip.
2478
-	 */
2479
-	public function set_user_zip( $value ) {
2480
-		$this->set_zip( $value );
2514
+     * Alias of self::set_company().
2515
+     *
2516
+     * @since 1.0.19
2517
+     * @param  string $value company.
2518
+     */
2519
+    public function set_customer_company( $value ) {
2520
+        $this->set_company( $value );
2481 2521
     }
2482 2522
 
2483 2523
     /**
2484
-	 * Alias of self::set_zip().
2485
-	 *
2486
-	 * @since 1.0.19
2487
-	 * @param  string $value zip.
2488
-	 */
2489
-	public function set_customer_zip( $value ) {
2490
-		$this->set_zip( $value );
2524
+     * Set the customer's var number.
2525
+     *
2526
+     * @since 1.0.19
2527
+     * @param  string $value var number.
2528
+     */
2529
+    public function set_vat_number( $value ) {
2530
+        $this->set_prop( 'vat_number', $value );
2491 2531
     }
2492 2532
 
2493 2533
     /**
2494
-	 * Set the customer's company.
2495
-	 *
2496
-	 * @since 1.0.19
2497
-	 * @param  string $value company.
2498
-	 */
2499
-	public function set_company( $value ) {
2500
-		$this->set_prop( 'company', $value );
2534
+     * Alias of self::set_vat_number().
2535
+     *
2536
+     * @since 1.0.19
2537
+     * @param  string $value var number.
2538
+     */
2539
+    public function set_user_vat_number( $value ) {
2540
+        $this->set_vat_number( $value );
2501 2541
     }
2502 2542
 
2503 2543
     /**
2504
-	 * Alias of self::set_company().
2505
-	 *
2506
-	 * @since 1.0.19
2507
-	 * @param  string $value company.
2508
-	 */
2509
-	public function set_user_company( $value ) {
2510
-		$this->set_company( $value );
2544
+     * Alias of self::set_vat_number().
2545
+     *
2546
+     * @since 1.0.19
2547
+     * @param  string $value var number.
2548
+     */
2549
+    public function set_customer_vat_number( $value ) {
2550
+        $this->set_vat_number( $value );
2511 2551
     }
2512 2552
 
2513 2553
     /**
2514
-	 * Alias of self::set_company().
2515
-	 *
2516
-	 * @since 1.0.19
2517
-	 * @param  string $value company.
2518
-	 */
2519
-	public function set_customer_company( $value ) {
2520
-		$this->set_company( $value );
2554
+     * Set the customer's vat rate.
2555
+     *
2556
+     * @since 1.0.19
2557
+     * @param  string $value var rate.
2558
+     */
2559
+    public function set_vat_rate( $value ) {
2560
+        $this->set_prop( 'vat_rate', $value );
2521 2561
     }
2522 2562
 
2523 2563
     /**
2524
-	 * Set the customer's var number.
2525
-	 *
2526
-	 * @since 1.0.19
2527
-	 * @param  string $value var number.
2528
-	 */
2529
-	public function set_vat_number( $value ) {
2530
-		$this->set_prop( 'vat_number', $value );
2564
+     * Alias of self::set_vat_rate().
2565
+     *
2566
+     * @since 1.0.19
2567
+     * @param  string $value var number.
2568
+     */
2569
+    public function set_user_vat_rate( $value ) {
2570
+        $this->set_vat_rate( $value );
2531 2571
     }
2532 2572
 
2533 2573
     /**
2534
-	 * Alias of self::set_vat_number().
2535
-	 *
2536
-	 * @since 1.0.19
2537
-	 * @param  string $value var number.
2538
-	 */
2539
-	public function set_user_vat_number( $value ) {
2540
-		$this->set_vat_number( $value );
2574
+     * Alias of self::set_vat_rate().
2575
+     *
2576
+     * @since 1.0.19
2577
+     * @param  string $value var number.
2578
+     */
2579
+    public function set_customer_vat_rate( $value ) {
2580
+        $this->set_vat_rate( $value );
2541 2581
     }
2542 2582
 
2543 2583
     /**
2544
-	 * Alias of self::set_vat_number().
2545
-	 *
2546
-	 * @since 1.0.19
2547
-	 * @param  string $value var number.
2548
-	 */
2549
-	public function set_customer_vat_number( $value ) {
2550
-		$this->set_vat_number( $value );
2584
+     * Set the customer's address.
2585
+     *
2586
+     * @since 1.0.19
2587
+     * @param  string $value address.
2588
+     */
2589
+    public function set_address( $value ) {
2590
+        $this->set_prop( 'address', $value );
2551 2591
     }
2552 2592
 
2553 2593
     /**
2554
-	 * Set the customer's vat rate.
2555
-	 *
2556
-	 * @since 1.0.19
2557
-	 * @param  string $value var rate.
2558
-	 */
2559
-	public function set_vat_rate( $value ) {
2560
-		$this->set_prop( 'vat_rate', $value );
2594
+     * Alias of self::set_address().
2595
+     *
2596
+     * @since 1.0.19
2597
+     * @param  string $value address.
2598
+     */
2599
+    public function set_user_address( $value ) {
2600
+        $this->set_address( $value );
2561 2601
     }
2562 2602
 
2563 2603
     /**
2564
-	 * Alias of self::set_vat_rate().
2565
-	 *
2566
-	 * @since 1.0.19
2567
-	 * @param  string $value var number.
2568
-	 */
2569
-	public function set_user_vat_rate( $value ) {
2570
-		$this->set_vat_rate( $value );
2604
+     * Alias of self::set_address().
2605
+     *
2606
+     * @since 1.0.19
2607
+     * @param  string $value address.
2608
+     */
2609
+    public function set_customer_address( $value ) {
2610
+        $this->set_address( $value );
2571 2611
     }
2572 2612
 
2573 2613
     /**
2574
-	 * Alias of self::set_vat_rate().
2575
-	 *
2576
-	 * @since 1.0.19
2577
-	 * @param  string $value var number.
2578
-	 */
2579
-	public function set_customer_vat_rate( $value ) {
2580
-		$this->set_vat_rate( $value );
2614
+     * Set whether the customer has viewed the invoice or not.
2615
+     *
2616
+     * @since 1.0.19
2617
+     * @param  int|bool $value confirmed.
2618
+     */
2619
+    public function set_is_viewed( $value ) {
2620
+        $this->set_prop( 'is_viewed', $value );
2581 2621
     }
2582 2622
 
2583 2623
     /**
2584
-	 * Set the customer's address.
2585
-	 *
2586
-	 * @since 1.0.19
2587
-	 * @param  string $value address.
2588
-	 */
2589
-	public function set_address( $value ) {
2590
-		$this->set_prop( 'address', $value );
2624
+     * Set extra email recipients.
2625
+     *
2626
+     * @since 1.0.19
2627
+     * @param  string $value email recipients.
2628
+     */
2629
+    public function set_email_cc( $value ) {
2630
+        $this->set_prop( 'email_cc', $value );
2591 2631
     }
2592 2632
 
2593 2633
     /**
2594
-	 * Alias of self::set_address().
2595
-	 *
2596
-	 * @since 1.0.19
2597
-	 * @param  string $value address.
2598
-	 */
2599
-	public function set_user_address( $value ) {
2600
-		$this->set_address( $value );
2634
+     * Set the invoice template.
2635
+     *
2636
+     * @since 1.0.19
2637
+     * @param  string $value template.
2638
+     */
2639
+    public function set_template( $value ) {
2640
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2641
+            $this->set_prop( 'template', $value );
2642
+        }
2601 2643
     }
2602 2644
 
2603 2645
     /**
2604
-	 * Alias of self::set_address().
2605
-	 *
2606
-	 * @since 1.0.19
2607
-	 * @param  string $value address.
2608
-	 */
2609
-	public function set_customer_address( $value ) {
2610
-		$this->set_address( $value );
2646
+     * Set the invoice source.
2647
+     *
2648
+     * @since 1.0.19
2649
+     * @param  string $value email recipients.
2650
+     */
2651
+    public function created_via( $value ) {
2652
+        $this->set_prop( 'created_via', sanitize_text_field( $value ) );
2611 2653
     }
2612 2654
 
2613 2655
     /**
2614
-	 * Set whether the customer has viewed the invoice or not.
2615
-	 *
2616
-	 * @since 1.0.19
2617
-	 * @param  int|bool $value confirmed.
2618
-	 */
2619
-	public function set_is_viewed( $value ) {
2620
-		$this->set_prop( 'is_viewed', $value );
2621
-	}
2622
-
2623
-	/**
2624
-	 * Set extra email recipients.
2625
-	 *
2626
-	 * @since 1.0.19
2627
-	 * @param  string $value email recipients.
2628
-	 */
2629
-	public function set_email_cc( $value ) {
2630
-		$this->set_prop( 'email_cc', $value );
2631
-	}
2632
-
2633
-	/**
2634
-	 * Set the invoice template.
2635
-	 *
2636
-	 * @since 1.0.19
2637
-	 * @param  string $value template.
2638
-	 */
2639
-	public function set_template( $value ) {
2640
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2641
-			$this->set_prop( 'template', $value );
2642
-		}
2643
-	}
2644
-
2645
-	/**
2646
-	 * Set the invoice source.
2647
-	 *
2648
-	 * @since 1.0.19
2649
-	 * @param  string $value email recipients.
2650
-	 */
2651
-	public function created_via( $value ) {
2652
-		$this->set_prop( 'created_via', sanitize_text_field( $value ) );
2653
-	}
2654
-
2655
-	/**
2656
-	 * Set the customer's address confirmed status.
2657
-	 *
2658
-	 * @since 1.0.19
2659
-	 * @param  int|bool $value confirmed.
2660
-	 */
2661
-	public function set_address_confirmed( $value ) {
2662
-		$this->set_prop( 'address_confirmed', $value );
2656
+     * Set the customer's address confirmed status.
2657
+     *
2658
+     * @since 1.0.19
2659
+     * @param  int|bool $value confirmed.
2660
+     */
2661
+    public function set_address_confirmed( $value ) {
2662
+        $this->set_prop( 'address_confirmed', $value );
2663 2663
     }
2664 2664
 
2665 2665
     /**
2666
-	 * Alias of self::set_address_confirmed().
2667
-	 *
2668
-	 * @since 1.0.19
2669
-	 * @param  int|bool $value confirmed.
2670
-	 */
2671
-	public function set_user_address_confirmed( $value ) {
2672
-		$this->set_address_confirmed( $value );
2666
+     * Alias of self::set_address_confirmed().
2667
+     *
2668
+     * @since 1.0.19
2669
+     * @param  int|bool $value confirmed.
2670
+     */
2671
+    public function set_user_address_confirmed( $value ) {
2672
+        $this->set_address_confirmed( $value );
2673 2673
     }
2674 2674
 
2675 2675
     /**
2676
-	 * Alias of self::set_address_confirmed().
2677
-	 *
2678
-	 * @since 1.0.19
2679
-	 * @param  int|bool $value confirmed.
2680
-	 */
2681
-	public function set_customer_address_confirmed( $value ) {
2682
-		$this->set_address_confirmed( $value );
2676
+     * Alias of self::set_address_confirmed().
2677
+     *
2678
+     * @since 1.0.19
2679
+     * @param  int|bool $value confirmed.
2680
+     */
2681
+    public function set_customer_address_confirmed( $value ) {
2682
+        $this->set_address_confirmed( $value );
2683 2683
     }
2684 2684
 
2685 2685
     /**
2686
-	 * Set the invoice sub total.
2687
-	 *
2688
-	 * @since 1.0.19
2689
-	 * @param  float $value sub total.
2690
-	 */
2691
-	public function set_subtotal( $value ) {
2692
-		$this->set_prop( 'subtotal', $value );
2686
+     * Set the invoice sub total.
2687
+     *
2688
+     * @since 1.0.19
2689
+     * @param  float $value sub total.
2690
+     */
2691
+    public function set_subtotal( $value ) {
2692
+        $this->set_prop( 'subtotal', $value );
2693 2693
     }
2694 2694
 
2695 2695
     /**
2696
-	 * Set the invoice discount amount.
2697
-	 *
2698
-	 * @since 1.0.19
2699
-	 * @param  float $value discount total.
2700
-	 */
2701
-	public function set_total_discount( $value ) {
2702
-		$this->set_prop( 'total_discount', $value );
2696
+     * Set the invoice discount amount.
2697
+     *
2698
+     * @since 1.0.19
2699
+     * @param  float $value discount total.
2700
+     */
2701
+    public function set_total_discount( $value ) {
2702
+        $this->set_prop( 'total_discount', $value );
2703 2703
     }
2704 2704
 
2705 2705
     /**
2706
-	 * Alias of self::set_total_discount().
2707
-	 *
2708
-	 * @since 1.0.19
2709
-	 * @param  float $value discount total.
2710
-	 */
2711
-	public function set_discount( $value ) {
2712
-		$this->set_total_discount( $value );
2706
+     * Alias of self::set_total_discount().
2707
+     *
2708
+     * @since 1.0.19
2709
+     * @param  float $value discount total.
2710
+     */
2711
+    public function set_discount( $value ) {
2712
+        $this->set_total_discount( $value );
2713 2713
     }
2714 2714
 
2715 2715
     /**
2716
-	 * Set the invoice tax amount.
2717
-	 *
2718
-	 * @since 1.0.19
2719
-	 * @param  float $value tax total.
2720
-	 */
2721
-	public function set_total_tax( $value ) {
2722
-		$this->set_prop( 'total_tax', $value );
2716
+     * Set the invoice tax amount.
2717
+     *
2718
+     * @since 1.0.19
2719
+     * @param  float $value tax total.
2720
+     */
2721
+    public function set_total_tax( $value ) {
2722
+        $this->set_prop( 'total_tax', $value );
2723 2723
     }
2724 2724
 
2725 2725
     /**
2726
-	 * Alias of self::set_total_tax().
2727
-	 *
2728
-	 * @since 1.0.19
2729
-	 * @param  float $value tax total.
2730
-	 */
2731
-	public function set_tax_total( $value ) {
2732
-		$this->set_total_tax( $value );
2726
+     * Alias of self::set_total_tax().
2727
+     *
2728
+     * @since 1.0.19
2729
+     * @param  float $value tax total.
2730
+     */
2731
+    public function set_tax_total( $value ) {
2732
+        $this->set_total_tax( $value );
2733 2733
     }
2734 2734
 
2735 2735
     /**
2736
-	 * Set the invoice fees amount.
2737
-	 *
2738
-	 * @since 1.0.19
2739
-	 * @param  float $value fees total.
2740
-	 */
2741
-	public function set_total_fees( $value ) {
2742
-		$this->set_prop( 'total_fees', $value );
2736
+     * Set the invoice fees amount.
2737
+     *
2738
+     * @since 1.0.19
2739
+     * @param  float $value fees total.
2740
+     */
2741
+    public function set_total_fees( $value ) {
2742
+        $this->set_prop( 'total_fees', $value );
2743 2743
     }
2744 2744
 
2745 2745
     /**
2746
-	 * Alias of self::set_total_fees().
2747
-	 *
2748
-	 * @since 1.0.19
2749
-	 * @param  float $value fees total.
2750
-	 */
2751
-	public function set_fees_total( $value ) {
2752
-		$this->set_total_fees( $value );
2746
+     * Alias of self::set_total_fees().
2747
+     *
2748
+     * @since 1.0.19
2749
+     * @param  float $value fees total.
2750
+     */
2751
+    public function set_fees_total( $value ) {
2752
+        $this->set_total_fees( $value );
2753 2753
     }
2754 2754
 
2755 2755
     /**
2756
-	 * Set the invoice fees.
2757
-	 *
2758
-	 * @since 1.0.19
2759
-	 * @param  array $value fees.
2760
-	 */
2761
-	public function set_fees( $value ) {
2756
+     * Set the invoice fees.
2757
+     *
2758
+     * @since 1.0.19
2759
+     * @param  array $value fees.
2760
+     */
2761
+    public function set_fees( $value ) {
2762 2762
 
2763
-		if ( ! is_array( $value ) ) {
2764
-			$value = array();
2765
-		}
2763
+        if ( ! is_array( $value ) ) {
2764
+            $value = array();
2765
+        }
2766 2766
 
2767
-		$this->set_prop( 'fees', $value );
2767
+        $this->set_prop( 'fees', $value );
2768 2768
 
2769 2769
     }
2770 2770
 
2771 2771
     /**
2772
-	 * Set the invoice taxes.
2773
-	 *
2774
-	 * @since 1.0.19
2775
-	 * @param  array $value taxes.
2776
-	 */
2777
-	public function set_taxes( $value ) {
2772
+     * Set the invoice taxes.
2773
+     *
2774
+     * @since 1.0.19
2775
+     * @param  array $value taxes.
2776
+     */
2777
+    public function set_taxes( $value ) {
2778 2778
 
2779
-		if ( ! is_array( $value ) ) {
2780
-			$value = array();
2781
-		}
2779
+        if ( ! is_array( $value ) ) {
2780
+            $value = array();
2781
+        }
2782 2782
 
2783
-		$this->set_prop( 'taxes', $value );
2783
+        $this->set_prop( 'taxes', $value );
2784 2784
 
2785 2785
     }
2786 2786
 
2787 2787
     /**
2788
-	 * Set the invoice discounts.
2789
-	 *
2790
-	 * @since 1.0.19
2791
-	 * @param  array $value discounts.
2792
-	 */
2793
-	public function set_discounts( $value ) {
2788
+     * Set the invoice discounts.
2789
+     *
2790
+     * @since 1.0.19
2791
+     * @param  array $value discounts.
2792
+     */
2793
+    public function set_discounts( $value ) {
2794 2794
 
2795
-		if ( ! is_array( $value ) ) {
2796
-			$value = array();
2797
-		}
2795
+        if ( ! is_array( $value ) ) {
2796
+            $value = array();
2797
+        }
2798 2798
 
2799
-		$this->set_prop( 'discounts', $value );
2799
+        $this->set_prop( 'discounts', $value );
2800 2800
     }
2801 2801
 
2802 2802
     /**
2803
-	 * Set the invoice items.
2804
-	 *
2805
-	 * @since 1.0.19
2806
-	 * @param  GetPaid_Form_Item[] $value items.
2807
-	 */
2808
-	public function set_items( $value ) {
2803
+     * Set the invoice items.
2804
+     *
2805
+     * @since 1.0.19
2806
+     * @param  GetPaid_Form_Item[] $value items.
2807
+     */
2808
+    public function set_items( $value ) {
2809 2809
 
2810 2810
         // Remove existing items.
2811 2811
         $this->set_prop( 'items', array() );
@@ -2822,95 +2822,95 @@  discard block
 block discarded – undo
2822 2822
     }
2823 2823
 
2824 2824
     /**
2825
-	 * Set the payment form.
2826
-	 *
2827
-	 * @since 1.0.19
2828
-	 * @param  int $value payment form.
2829
-	 */
2830
-	public function set_payment_form( $value ) {
2831
-		$this->set_prop( 'payment_form', $value );
2825
+     * Set the payment form.
2826
+     *
2827
+     * @since 1.0.19
2828
+     * @param  int $value payment form.
2829
+     */
2830
+    public function set_payment_form( $value ) {
2831
+        $this->set_prop( 'payment_form', $value );
2832 2832
     }
2833 2833
 
2834 2834
     /**
2835
-	 * Set the submission id.
2836
-	 *
2837
-	 * @since 1.0.19
2838
-	 * @param  string $value submission id.
2839
-	 */
2840
-	public function set_submission_id( $value ) {
2841
-		$this->set_prop( 'submission_id', $value );
2835
+     * Set the submission id.
2836
+     *
2837
+     * @since 1.0.19
2838
+     * @param  string $value submission id.
2839
+     */
2840
+    public function set_submission_id( $value ) {
2841
+        $this->set_prop( 'submission_id', $value );
2842 2842
     }
2843 2843
 
2844 2844
     /**
2845
-	 * Set the discount code.
2846
-	 *
2847
-	 * @since 1.0.19
2848
-	 * @param  string $value discount code.
2849
-	 */
2850
-	public function set_discount_code( $value ) {
2851
-		$this->set_prop( 'discount_code', $value );
2845
+     * Set the discount code.
2846
+     *
2847
+     * @since 1.0.19
2848
+     * @param  string $value discount code.
2849
+     */
2850
+    public function set_discount_code( $value ) {
2851
+        $this->set_prop( 'discount_code', $value );
2852 2852
     }
2853 2853
 
2854 2854
     /**
2855
-	 * Set the gateway.
2856
-	 *
2857
-	 * @since 1.0.19
2858
-	 * @param  string $value gateway.
2859
-	 */
2860
-	public function set_gateway( $value ) {
2861
-		$this->set_prop( 'gateway', $value );
2855
+     * Set the gateway.
2856
+     *
2857
+     * @since 1.0.19
2858
+     * @param  string $value gateway.
2859
+     */
2860
+    public function set_gateway( $value ) {
2861
+        $this->set_prop( 'gateway', $value );
2862 2862
     }
2863 2863
 
2864 2864
     /**
2865
-	 * Set the transaction id.
2866
-	 *
2867
-	 * @since 1.0.19
2868
-	 * @param  string $value transaction id.
2869
-	 */
2870
-	public function set_transaction_id( $value ) {
2871
-		if ( ! empty( $value ) ) {
2872
-			$this->set_prop( 'transaction_id', $value );
2873
-		}
2865
+     * Set the transaction id.
2866
+     *
2867
+     * @since 1.0.19
2868
+     * @param  string $value transaction id.
2869
+     */
2870
+    public function set_transaction_id( $value ) {
2871
+        if ( ! empty( $value ) ) {
2872
+            $this->set_prop( 'transaction_id', $value );
2873
+        }
2874 2874
     }
2875 2875
 
2876 2876
     /**
2877
-	 * Set the currency id.
2878
-	 *
2879
-	 * @since 1.0.19
2880
-	 * @param  string $value currency id.
2881
-	 */
2882
-	public function set_currency( $value ) {
2883
-		$this->set_prop( 'currency', $value );
2877
+     * Set the currency id.
2878
+     *
2879
+     * @since 1.0.19
2880
+     * @param  string $value currency id.
2881
+     */
2882
+    public function set_currency( $value ) {
2883
+        $this->set_prop( 'currency', $value );
2884 2884
     }
2885 2885
 
2886
-	/**
2887
-	 * Set whether to disable taxes.
2888
-	 *
2889
-	 * @since 1.0.19
2890
-	 * @param  bool $value value.
2891
-	 */
2892
-	public function set_disable_taxes( $value ) {
2893
-		$this->set_prop( 'disable_taxes', (bool) $value );
2894
-	}
2886
+    /**
2887
+     * Set whether to disable taxes.
2888
+     *
2889
+     * @since 1.0.19
2890
+     * @param  bool $value value.
2891
+     */
2892
+    public function set_disable_taxes( $value ) {
2893
+        $this->set_prop( 'disable_taxes', (bool) $value );
2894
+    }
2895 2895
 
2896 2896
     /**
2897
-	 * Set the subscription id.
2898
-	 *
2899
-	 * @since 1.0.19
2900
-	 * @param  string $value subscription id.
2901
-	 */
2902
-	public function set_subscription_id( $value ) {
2903
-		$this->set_prop( 'subscription_id', $value );
2904
-	}
2897
+     * Set the subscription id.
2898
+     *
2899
+     * @since 1.0.19
2900
+     * @param  string $value subscription id.
2901
+     */
2902
+    public function set_subscription_id( $value ) {
2903
+        $this->set_prop( 'subscription_id', $value );
2904
+    }
2905 2905
 	
2906
-	/**
2907
-	 * Set the remote subscription id.
2908
-	 *
2909
-	 * @since 1.0.19
2910
-	 * @param  string $value subscription id.
2911
-	 */
2912
-	public function set_remote_subscription_id( $value ) {
2913
-		$this->set_prop( 'remote_subscription_id', $value );
2906
+    /**
2907
+     * Set the remote subscription id.
2908
+     *
2909
+     * @since 1.0.19
2910
+     * @param  string $value subscription id.
2911
+     */
2912
+    public function set_remote_subscription_id( $value ) {
2913
+        $this->set_prop( 'remote_subscription_id', $value );
2914 2914
     }
2915 2915
 
2916 2916
     /*
@@ -2949,12 +2949,12 @@  discard block
 block discarded – undo
2949 2949
      */
2950 2950
     public function is_taxable() {
2951 2951
         return ! $this->get_disable_taxes();
2952
-	}
2952
+    }
2953 2953
 
2954
-	/**
2955
-	 * @deprecated
2956
-	 */
2957
-	public function has_vat() {
2954
+    /**
2955
+     * @deprecated
2956
+     */
2957
+    public function has_vat() {
2958 2958
         global $wpinv_euvat, $wpi_country;
2959 2959
 
2960 2960
         $requires_vat = false;
@@ -2965,17 +2965,17 @@  discard block
 block discarded – undo
2965 2965
         }
2966 2966
 
2967 2967
         return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2968
-	}
2968
+    }
2969 2969
 
2970
-	/**
2971
-	 * Checks to see if the invoice requires payment.
2972
-	 */
2973
-	public function is_free() {
2970
+    /**
2971
+     * Checks to see if the invoice requires payment.
2972
+     */
2973
+    public function is_free() {
2974 2974
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2975 2975
 
2976
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2977
-			$is_free = false;
2978
-		}
2976
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2977
+            $is_free = false;
2978
+        }
2979 2979
 
2980 2980
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2981 2981
     }
@@ -2986,46 +2986,46 @@  discard block
 block discarded – undo
2986 2986
     public function is_paid() {
2987 2987
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2988 2988
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2989
-	}
2989
+    }
2990 2990
 
2991
-	/**
2991
+    /**
2992 2992
      * Checks if the invoice needs payment.
2993 2993
      */
2994
-	public function needs_payment() {
2995
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2994
+    public function needs_payment() {
2995
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2996 2996
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2997 2997
     }
2998 2998
   
2999
-	/**
2999
+    /**
3000 3000
      * Checks if the invoice is refunded.
3001 3001
      */
3002
-	public function is_refunded() {
3002
+    public function is_refunded() {
3003 3003
         $is_refunded = $this->has_status( 'wpi-refunded' );
3004 3004
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
3005
-	}
3005
+    }
3006 3006
 
3007
-	/**
3007
+    /**
3008 3008
      * Checks if the invoice is held.
3009 3009
      */
3010
-	public function is_held() {
3010
+    public function is_held() {
3011 3011
         $is_held = $this->has_status( 'wpi-onhold' );
3012 3012
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
3013
-	}
3013
+    }
3014 3014
 
3015
-	/**
3015
+    /**
3016 3016
      * Checks if the invoice is due.
3017 3017
      */
3018
-	public function is_due() {
3019
-		$due_date = $this->get_due_date();
3020
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3021
-	}
3018
+    public function is_due() {
3019
+        $due_date = $this->get_due_date();
3020
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3021
+    }
3022 3022
 
3023
-	/**
3023
+    /**
3024 3024
      * Checks if the invoice is draft.
3025 3025
      */
3026
-	public function is_draft() {
3026
+    public function is_draft() {
3027 3027
         return $this->has_status( 'draft, auto-draft' );
3028
-	}
3028
+    }
3029 3029
 
3030 3030
     /**
3031 3031
      * Checks if the invoice has a given status.
@@ -3033,9 +3033,9 @@  discard block
 block discarded – undo
3033 3033
     public function has_status( $status ) {
3034 3034
         $status = wpinv_parse_list( $status );
3035 3035
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
3036
-	}
3036
+    }
3037 3037
 
3038
-	/**
3038
+    /**
3039 3039
      * Checks if the invoice is of a given type.
3040 3040
      */
3041 3041
     public function is_type( $type ) {
@@ -3058,25 +3058,25 @@  discard block
 block discarded – undo
3058 3058
      */
3059 3059
     public function has_free_trial() {
3060 3060
         return $this->is_recurring() && 0 == $this->get_initial_total();
3061
-	}
3061
+    }
3062 3062
 
3063
-	/**
3063
+    /**
3064 3064
      * @deprecated
3065 3065
      */
3066 3066
     public function is_free_trial() {
3067 3067
         $this->has_free_trial();
3068 3068
     }
3069 3069
 
3070
-	/**
3070
+    /**
3071 3071
      * Check if the initial payment if 0.
3072 3072
      *
3073 3073
      */
3074
-	public function is_initial_free() {
3074
+    public function is_initial_free() {
3075 3075
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3076 3076
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3077 3077
     }
3078 3078
 	
3079
-	/**
3079
+    /**
3080 3080
      * Check if the recurring item has a free trial.
3081 3081
      *
3082 3082
      */
@@ -3089,21 +3089,21 @@  discard block
 block discarded – undo
3089 3089
 
3090 3090
         $item = $this->get_recurring( true );
3091 3091
         return $item->has_free_trial();
3092
-	}
3092
+    }
3093 3093
 
3094
-	/**
3094
+    /**
3095 3095
      * Check if the free trial is a result of a discount.
3096 3096
      */
3097 3097
     public function is_free_trial_from_discount() {
3098
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3099
-	}
3098
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3099
+    }
3100 3100
 	
3101
-	/**
3101
+    /**
3102 3102
      * @deprecated
3103 3103
      */
3104 3104
     public function discount_first_payment_only() {
3105 3105
 
3106
-		$discount_code = $this->get_discount_code();
3106
+        $discount_code = $this->get_discount_code();
3107 3107
         if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
3108 3108
             return true;
3109 3109
         }
@@ -3134,28 +3134,28 @@  discard block
 block discarded – undo
3134 3134
      */
3135 3135
     public function add_item( $item ) {
3136 3136
 
3137
-		if ( is_array( $item ) ) {
3138
-			$item = $this->process_array_item( $item );
3139
-		}
3137
+        if ( is_array( $item ) ) {
3138
+            $item = $this->process_array_item( $item );
3139
+        }
3140 3140
 
3141
-		if ( is_numeric( $item ) ) {
3142
-			$item = new GetPaid_Form_Item( $item );
3143
-		}
3141
+        if ( is_numeric( $item ) ) {
3142
+            $item = new GetPaid_Form_Item( $item );
3143
+        }
3144 3144
 
3145 3145
         // Make sure that it is available for purchase.
3146
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3147
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3146
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3147
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3148 3148
         }
3149 3149
 
3150 3150
         // Do we have a recurring item?
3151
-		if ( $item->is_recurring() ) {
3151
+        if ( $item->is_recurring() ) {
3152 3152
 
3153
-			// An invoice can only contain one recurring item.
3154
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3155
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3156
-			}
3153
+            // An invoice can only contain one recurring item.
3154
+            if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3155
+                return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3156
+            }
3157 3157
 
3158
-			$this->recurring_item = $item->get_id();
3158
+            $this->recurring_item = $item->get_id();
3159 3159
         }
3160 3160
 
3161 3161
         // Invoice id.
@@ -3166,60 +3166,60 @@  discard block
 block discarded – undo
3166 3166
         $items[ (int) $item->get_id() ] = $item;
3167 3167
 
3168 3168
         $this->set_prop( 'items', $items );
3169
-		return true;
3170
-	}
3169
+        return true;
3170
+    }
3171 3171
 
3172
-	/**
3173
-	 * Converts an array to an item.
3174
-	 *
3175
-	 * @since 1.0.19
3176
-	 * @return GetPaid_Form_Item
3177
-	 */
3178
-	protected function process_array_item( $array ) {
3172
+    /**
3173
+     * Converts an array to an item.
3174
+     *
3175
+     * @since 1.0.19
3176
+     * @return GetPaid_Form_Item
3177
+     */
3178
+    protected function process_array_item( $array ) {
3179 3179
 
3180
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3181
-		$item    = new GetPaid_Form_Item( $item_id );
3180
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3181
+        $item    = new GetPaid_Form_Item( $item_id );
3182 3182
 
3183
-		// Set item data.
3184
-		foreach ( array( 'name', 'price', 'description' ) as $key ) {
3185
-			if ( isset( $array[ "item_$key" ] ) ) {
3186
-				$method = "set_$key";
3187
-				$item->$method( $array[ "item_$key" ] );
3188
-			}
3189
-		}
3183
+        // Set item data.
3184
+        foreach ( array( 'name', 'price', 'description' ) as $key ) {
3185
+            if ( isset( $array[ "item_$key" ] ) ) {
3186
+                $method = "set_$key";
3187
+                $item->$method( $array[ "item_$key" ] );
3188
+            }
3189
+        }
3190 3190
 
3191
-		if ( isset( $array['quantity'] ) ) {
3192
-			$item->set_quantity( $array['quantity'] );
3193
-		}
3191
+        if ( isset( $array['quantity'] ) ) {
3192
+            $item->set_quantity( $array['quantity'] );
3193
+        }
3194 3194
 
3195
-		// Set item meta.
3196
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3197
-			$item->set_item_meta( $array['meta'] );
3198
-		}
3195
+        // Set item meta.
3196
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3197
+            $item->set_item_meta( $array['meta'] );
3198
+        }
3199 3199
 
3200
-		return $item;
3200
+        return $item;
3201 3201
 
3202
-	}
3202
+    }
3203 3203
 
3204 3204
     /**
3205
-	 * Retrieves a specific item.
3206
-	 *
3207
-	 * @since 1.0.19
3208
-	 */
3209
-	public function get_item( $item_id ) {
3210
-		$items   = $this->get_items();
3211
-		$item_id = (int) $item_id;
3212
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3205
+     * Retrieves a specific item.
3206
+     *
3207
+     * @since 1.0.19
3208
+     */
3209
+    public function get_item( $item_id ) {
3210
+        $items   = $this->get_items();
3211
+        $item_id = (int) $item_id;
3212
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3213 3213
     }
3214 3214
 
3215 3215
     /**
3216
-	 * Removes a specific item.
3217
-	 *
3218
-	 * @since 1.0.19
3219
-	 */
3220
-	public function remove_item( $item_id ) {
3221
-		$items   = $this->get_items();
3222
-		$item_id = (int) $item_id;
3216
+     * Removes a specific item.
3217
+     *
3218
+     * @since 1.0.19
3219
+     */
3220
+    public function remove_item( $item_id ) {
3221
+        $items   = $this->get_items();
3222
+        $item_id = (int) $item_id;
3223 3223
 
3224 3224
         if ( $item_id == $this->recurring_item ) {
3225 3225
             $this->recurring_item = null;
@@ -3232,35 +3232,35 @@  discard block
 block discarded – undo
3232 3232
     }
3233 3233
 
3234 3234
     /**
3235
-	 * Adds a fee to the invoice.
3236
-	 *
3237
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3238
-	 * @since 1.0.19
3239
-	 */
3235
+     * Adds a fee to the invoice.
3236
+     *
3237
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3238
+     * @since 1.0.19
3239
+     */
3240 3240
     public function add_fee( $fee ) {
3241 3241
 
3242
-		$fees                 = $this->get_fees();
3243
-		$fees[ $fee['name'] ] = $fee;
3244
-		$this->set_prop( 'fees', $fees );
3242
+        $fees                 = $this->get_fees();
3243
+        $fees[ $fee['name'] ] = $fee;
3244
+        $this->set_prop( 'fees', $fees );
3245 3245
 
3246 3246
     }
3247 3247
 
3248 3248
     /**
3249
-	 * Retrieves a specific fee.
3250
-	 *
3251
-	 * @since 1.0.19
3252
-	 */
3253
-	public function get_fee( $fee ) {
3249
+     * Retrieves a specific fee.
3250
+     *
3251
+     * @since 1.0.19
3252
+     */
3253
+    public function get_fee( $fee ) {
3254 3254
         $fees = $this->get_fees();
3255
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3255
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3256 3256
     }
3257 3257
 
3258 3258
     /**
3259
-	 * Removes a specific fee.
3260
-	 *
3261
-	 * @since 1.0.19
3262
-	 */
3263
-	public function remove_fee( $fee ) {
3259
+     * Removes a specific fee.
3260
+     *
3261
+     * @since 1.0.19
3262
+     */
3263
+    public function remove_fee( $fee ) {
3264 3264
         $fees = $this->get_fees();
3265 3265
         if ( isset( $fees[ $fee ] ) ) {
3266 3266
             unset( $fees[ $fee ] );
@@ -3268,43 +3268,43 @@  discard block
 block discarded – undo
3268 3268
         }
3269 3269
     }
3270 3270
 
3271
-	/**
3272
-	 * Adds a discount to the invoice.
3273
-	 *
3274
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3275
-	 * @since 1.0.19
3276
-	 */
3277
-	public function add_discount( $discount ) {
3271
+    /**
3272
+     * Adds a discount to the invoice.
3273
+     *
3274
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3275
+     * @since 1.0.19
3276
+     */
3277
+    public function add_discount( $discount ) {
3278 3278
 
3279
-		$discounts = $this->get_discounts();
3280
-		$discounts[ $discount['name'] ] = $discount;
3281
-		$this->set_prop( 'discounts', $discounts );
3279
+        $discounts = $this->get_discounts();
3280
+        $discounts[ $discount['name'] ] = $discount;
3281
+        $this->set_prop( 'discounts', $discounts );
3282 3282
 
3283
-	}
3283
+    }
3284 3284
 
3285 3285
     /**
3286
-	 * Retrieves a specific discount.
3287
-	 *
3288
-	 * @since 1.0.19
3289
-	 * @return float
3290
-	 */
3291
-	public function get_discount( $discount = false ) {
3286
+     * Retrieves a specific discount.
3287
+     *
3288
+     * @since 1.0.19
3289
+     * @return float
3290
+     */
3291
+    public function get_discount( $discount = false ) {
3292 3292
 
3293
-		// Backwards compatibilty.
3294
-		if ( empty( $discount ) ) {
3295
-			return $this->get_total_discount();
3296
-		}
3293
+        // Backwards compatibilty.
3294
+        if ( empty( $discount ) ) {
3295
+            return $this->get_total_discount();
3296
+        }
3297 3297
 
3298 3298
         $discounts = $this->get_discounts();
3299
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3299
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3300 3300
     }
3301 3301
 
3302 3302
     /**
3303
-	 * Removes a specific discount.
3304
-	 *
3305
-	 * @since 1.0.19
3306
-	 */
3307
-	public function remove_discount( $discount ) {
3303
+     * Removes a specific discount.
3304
+     *
3305
+     * @since 1.0.19
3306
+     */
3307
+    public function remove_discount( $discount ) {
3308 3308
         $discounts = $this->get_discounts();
3309 3309
         if ( isset( $discounts[ $discount ] ) ) {
3310 3310
             unset( $discounts[ $discount ] );
@@ -3321,34 +3321,34 @@  discard block
 block discarded – undo
3321 3321
         if ( $this->is_taxable() ) {
3322 3322
 
3323 3323
             $taxes                 = $this->get_taxes();
3324
-			$taxes[ $tax['name'] ] = $tax;
3325
-			$this->set_prop( 'taxes', $tax );
3324
+            $taxes[ $tax['name'] ] = $tax;
3325
+            $this->set_prop( 'taxes', $tax );
3326 3326
 
3327 3327
         }
3328 3328
     }
3329 3329
 
3330 3330
     /**
3331
-	 * Retrieves a specific tax.
3332
-	 *
3333
-	 * @since 1.0.19
3334
-	 */
3335
-	public function get_tax( $tax = null ) {
3331
+     * Retrieves a specific tax.
3332
+     *
3333
+     * @since 1.0.19
3334
+     */
3335
+    public function get_tax( $tax = null ) {
3336 3336
 
3337
-		// Backwards compatility.
3338
-		if ( empty( $tax ) ) {
3339
-			return $this->get_total_tax();
3340
-		}
3337
+        // Backwards compatility.
3338
+        if ( empty( $tax ) ) {
3339
+            return $this->get_total_tax();
3340
+        }
3341 3341
 
3342 3342
         $taxes = $this->get_taxes();
3343
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3343
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3344 3344
     }
3345 3345
 
3346 3346
     /**
3347
-	 * Removes a specific tax.
3348
-	 *
3349
-	 * @since 1.0.19
3350
-	 */
3351
-	public function remove_tax( $tax ) {
3347
+     * Removes a specific tax.
3348
+     *
3349
+     * @since 1.0.19
3350
+     */
3351
+    public function remove_tax( $tax ) {
3352 3352
         $taxes = $this->get_taxes();
3353 3353
         if ( isset( $taxes[ $tax ] ) ) {
3354 3354
             unset( $taxes[ $tax ] );
@@ -3357,134 +3357,134 @@  discard block
 block discarded – undo
3357 3357
     }
3358 3358
 
3359 3359
     /**
3360
-	 * Recalculates the invoice subtotal.
3361
-	 *
3362
-	 * @since 1.0.19
3363
-	 * @return float The recalculated subtotal
3364
-	 */
3365
-	public function recalculate_subtotal() {
3360
+     * Recalculates the invoice subtotal.
3361
+     *
3362
+     * @since 1.0.19
3363
+     * @return float The recalculated subtotal
3364
+     */
3365
+    public function recalculate_subtotal() {
3366 3366
         $items     = $this->get_items();
3367
-		$subtotal  = 0;
3368
-		$recurring = 0;
3367
+        $subtotal  = 0;
3368
+        $recurring = 0;
3369 3369
 
3370 3370
         foreach ( $items as $item ) {
3371
-			$subtotal  += $item->get_sub_total();
3372
-			$recurring += $item->get_recurring_sub_total();
3371
+            $subtotal  += $item->get_sub_total();
3372
+            $recurring += $item->get_recurring_sub_total();
3373 3373
         }
3374 3374
 
3375
-		$current = $this->is_renewal() ? $recurring : $subtotal;
3376
-		$this->set_subtotal( $current );
3375
+        $current = $this->is_renewal() ? $recurring : $subtotal;
3376
+        $this->set_subtotal( $current );
3377 3377
 
3378
-		$this->totals['subtotal'] = array(
3379
-			'initial'   => $subtotal,
3380
-			'recurring' => $recurring,
3381
-		);
3378
+        $this->totals['subtotal'] = array(
3379
+            'initial'   => $subtotal,
3380
+            'recurring' => $recurring,
3381
+        );
3382 3382
 
3383 3383
         return $current;
3384 3384
     }
3385 3385
 
3386 3386
     /**
3387
-	 * Recalculates the invoice discount total.
3388
-	 *
3389
-	 * @since 1.0.19
3390
-	 * @return float The recalculated discount
3391
-	 */
3392
-	public function recalculate_total_discount() {
3387
+     * Recalculates the invoice discount total.
3388
+     *
3389
+     * @since 1.0.19
3390
+     * @return float The recalculated discount
3391
+     */
3392
+    public function recalculate_total_discount() {
3393 3393
         $discounts = $this->get_discounts();
3394
-		$discount  = 0;
3395
-		$recurring = 0;
3394
+        $discount  = 0;
3395
+        $recurring = 0;
3396 3396
 
3397 3397
         foreach ( $discounts as $data ) {
3398
-			$discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3399
-			$recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3400
-		}
3398
+            $discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3399
+            $recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3400
+        }
3401 3401
 
3402
-		$current = $this->is_renewal() ? $recurring : $discount;
3402
+        $current = $this->is_renewal() ? $recurring : $discount;
3403 3403
 
3404
-		$this->set_total_discount( $current );
3404
+        $this->set_total_discount( $current );
3405 3405
 
3406
-		$this->totals['discount'] = array(
3407
-			'initial'   => $discount,
3408
-			'recurring' => $recurring,
3409
-		);
3406
+        $this->totals['discount'] = array(
3407
+            'initial'   => $discount,
3408
+            'recurring' => $recurring,
3409
+        );
3410 3410
 
3411
-		return $current;
3411
+        return $current;
3412 3412
 
3413 3413
     }
3414 3414
 
3415 3415
     /**
3416
-	 * Recalculates the invoice tax total.
3417
-	 *
3418
-	 * @since 1.0.19
3419
-	 * @return float The recalculated tax
3420
-	 */
3421
-	public function recalculate_total_tax() {
3416
+     * Recalculates the invoice tax total.
3417
+     *
3418
+     * @since 1.0.19
3419
+     * @return float The recalculated tax
3420
+     */
3421
+    public function recalculate_total_tax() {
3422 3422
         $taxes     = $this->get_taxes();
3423
-		$tax       = 0;
3424
-		$recurring = 0;
3423
+        $tax       = 0;
3424
+        $recurring = 0;
3425 3425
 
3426 3426
         foreach ( $taxes as $data ) {
3427
-			$tax       += wpinv_sanitize_amount( $data['initial_tax'] );
3428
-			$recurring += wpinv_sanitize_amount( $data['recurring_tax'] );
3429
-		}
3427
+            $tax       += wpinv_sanitize_amount( $data['initial_tax'] );
3428
+            $recurring += wpinv_sanitize_amount( $data['recurring_tax'] );
3429
+        }
3430 3430
 
3431
-		$current = $this->is_renewal() ? $recurring : $tax;
3432
-		$this->set_total_tax( $current );
3431
+        $current = $this->is_renewal() ? $recurring : $tax;
3432
+        $this->set_total_tax( $current );
3433 3433
 
3434
-		$this->totals['tax'] = array(
3435
-			'initial'   => $tax,
3436
-			'recurring' => $recurring,
3437
-		);
3434
+        $this->totals['tax'] = array(
3435
+            'initial'   => $tax,
3436
+            'recurring' => $recurring,
3437
+        );
3438 3438
 
3439
-		return $current;
3439
+        return $current;
3440 3440
 
3441 3441
     }
3442 3442
 
3443 3443
     /**
3444
-	 * Recalculates the invoice fees total.
3445
-	 *
3446
-	 * @since 1.0.19
3447
-	 * @return float The recalculated fee
3448
-	 */
3449
-	public function recalculate_total_fees() {
3450
-		$fees      = $this->get_fees();
3451
-		$fee       = 0;
3452
-		$recurring = 0;
3444
+     * Recalculates the invoice fees total.
3445
+     *
3446
+     * @since 1.0.19
3447
+     * @return float The recalculated fee
3448
+     */
3449
+    public function recalculate_total_fees() {
3450
+        $fees      = $this->get_fees();
3451
+        $fee       = 0;
3452
+        $recurring = 0;
3453 3453
 
3454 3454
         foreach ( $fees as $data ) {
3455
-			$fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3456
-			$recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3457
-		}
3455
+            $fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3456
+            $recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3457
+        }
3458 3458
 
3459
-		$current = $this->is_renewal() ? $recurring : $fee;
3460
-		$this->set_total_fees( $current );
3459
+        $current = $this->is_renewal() ? $recurring : $fee;
3460
+        $this->set_total_fees( $current );
3461 3461
 
3462
-		$this->totals['fee'] = array(
3463
-			'initial'   => $fee,
3464
-			'recurring' => $recurring,
3465
-		);
3462
+        $this->totals['fee'] = array(
3463
+            'initial'   => $fee,
3464
+            'recurring' => $recurring,
3465
+        );
3466 3466
 
3467 3467
         $this->set_total_fees( $fee );
3468 3468
         return $current;
3469 3469
     }
3470 3470
 
3471 3471
     /**
3472
-	 * Recalculates the invoice total.
3473
-	 *
3474
-	 * @since 1.0.19
3472
+     * Recalculates the invoice total.
3473
+     *
3474
+     * @since 1.0.19
3475 3475
      * @return float The invoice total
3476
-	 */
3477
-	public function recalculate_total() {
3476
+     */
3477
+    public function recalculate_total() {
3478 3478
         $this->recalculate_subtotal();
3479 3479
         $this->recalculate_total_fees();
3480 3480
         $this->recalculate_total_discount();
3481 3481
         $this->recalculate_total_tax();
3482
-		return $this->get_total();
3483
-	}
3482
+        return $this->get_total();
3483
+    }
3484 3484
 
3485
-	/**
3486
-	 * @deprecated
3487
-	 */
3485
+    /**
3486
+     * @deprecated
3487
+     */
3488 3488
     public function recalculate_totals( $temp = false ) {
3489 3489
         $this->update_items( $temp );
3490 3490
         $this->save( true );
@@ -3502,7 +3502,7 @@  discard block
 block discarded – undo
3502 3502
      * Adds a note to an invoice.
3503 3503
      *
3504 3504
      * @param string $note The note being added.
3505
-	 * @return int|false The new note's ID on success, false on failure.
3505
+     * @return int|false The new note's ID on success, false on failure.
3506 3506
      *
3507 3507
      */
3508 3508
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3512,21 +3512,21 @@  discard block
 block discarded – undo
3512 3512
             return false;
3513 3513
         }
3514 3514
 
3515
-		$author       = 'System';
3516
-		$author_email = '[email protected]';
3515
+        $author       = 'System';
3516
+        $author_email = '[email protected]';
3517 3517
 
3518
-		// If this is an admin comment or it has been added by the user.
3519
-		if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3520
-			$user         = get_user_by( 'id', get_current_user_id() );
3518
+        // If this is an admin comment or it has been added by the user.
3519
+        if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3520
+            $user         = get_user_by( 'id', get_current_user_id() );
3521 3521
             $author       = $user->display_name;
3522 3522
             $author_email = $user->user_email;
3523
-		}
3523
+        }
3524 3524
 
3525
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3525
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3526 3526
 
3527
-	}
3527
+    }
3528 3528
 
3529
-	/**
3529
+    /**
3530 3530
      * Generates a unique key for the invoice.
3531 3531
      */
3532 3532
     public function generate_key( $string = '' ) {
@@ -3546,113 +3546,113 @@  discard block
 block discarded – undo
3546 3546
             $number = wpinv_get_next_invoice_number( $this->get_post_type() );
3547 3547
         }
3548 3548
 
3549
-		return wpinv_format_invoice_number( $number, $this->get_post_type() );
3550
-
3551
-	}
3552
-
3553
-	/**
3554
-	 * Handle the status transition.
3555
-	 */
3556
-	protected function status_transition() {
3557
-		$status_transition = $this->status_transition;
3558
-
3559
-		// Reset status transition variable.
3560
-		$this->status_transition = false;
3561
-
3562
-		if ( $status_transition ) {
3563
-			try {
3549
+        return wpinv_format_invoice_number( $number, $this->get_post_type() );
3564 3550
 
3565
-				// Fire a hook for the status change.
3566
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3567
-
3568
-				// @deprecated this is deprecated and will be removed in the future.
3569
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3570
-
3571
-				if ( ! empty( $status_transition['from'] ) ) {
3572
-
3573
-					/* translators: 1: old invoice status 2: new invoice status */
3574
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3575
-
3576
-					// Fire another hook.
3577
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3578
-					do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3579
-
3580
-					// @deprecated this is deprecated and will be removed in the future.
3581
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3582
-
3583
-					// Note the transition occurred.
3584
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3585
-
3586
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3587
-					if (
3588
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3589
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3590
-					) {
3591
-						do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3592
-					}
3593
-
3594
-					// Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3595
-					if (
3596
-						in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3597
-						&& in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3598
-					) {
3599
-						do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3600
-					}
3601
-				} else {
3602
-					/* translators: %s: new invoice status */
3603
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3604
-
3605
-					// Note the transition occurred.
3606
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3551
+    }
3607 3552
 
3608
-				}
3609
-			} catch ( Exception $e ) {
3610
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3611
-			}
3612
-		}
3613
-	}
3553
+    /**
3554
+     * Handle the status transition.
3555
+     */
3556
+    protected function status_transition() {
3557
+        $status_transition = $this->status_transition;
3558
+
3559
+        // Reset status transition variable.
3560
+        $this->status_transition = false;
3561
+
3562
+        if ( $status_transition ) {
3563
+            try {
3564
+
3565
+                // Fire a hook for the status change.
3566
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3567
+
3568
+                // @deprecated this is deprecated and will be removed in the future.
3569
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3570
+
3571
+                if ( ! empty( $status_transition['from'] ) ) {
3572
+
3573
+                    /* translators: 1: old invoice status 2: new invoice status */
3574
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3575
+
3576
+                    // Fire another hook.
3577
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3578
+                    do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3579
+
3580
+                    // @deprecated this is deprecated and will be removed in the future.
3581
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3582
+
3583
+                    // Note the transition occurred.
3584
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3585
+
3586
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3587
+                    if (
3588
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3589
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3590
+                    ) {
3591
+                        do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3592
+                    }
3593
+
3594
+                    // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3595
+                    if (
3596
+                        in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3597
+                        && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3598
+                    ) {
3599
+                        do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3600
+                    }
3601
+                } else {
3602
+                    /* translators: %s: new invoice status */
3603
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3604
+
3605
+                    // Note the transition occurred.
3606
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3607
+
3608
+                }
3609
+            } catch ( Exception $e ) {
3610
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3611
+            }
3612
+        }
3613
+    }
3614 3614
 
3615
-	/**
3616
-	 * Updates an invoice status.
3617
-	 */
3618
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3615
+    /**
3616
+     * Updates an invoice status.
3617
+     */
3618
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3619 3619
 
3620
-		// Fires before updating a status.
3621
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3620
+        // Fires before updating a status.
3621
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3622 3622
 
3623
-		// Update the status.
3624
-		$this->set_status( $new_status, $note, $manual );
3623
+        // Update the status.
3624
+        $this->set_status( $new_status, $note, $manual );
3625 3625
 
3626
-		// Save the order.
3627
-		return $this->save();
3626
+        // Save the order.
3627
+        return $this->save();
3628 3628
 
3629
-	}
3629
+    }
3630 3630
 
3631
-	/**
3632
-	 * @deprecated
3633
-	 */
3634
-	public function refresh_item_ids() {
3631
+    /**
3632
+     * @deprecated
3633
+     */
3634
+    public function refresh_item_ids() {
3635 3635
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3636 3636
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3637
-	}
3637
+    }
3638 3638
 
3639
-	/**
3640
-	 * @deprecated
3641
-	 */
3642
-	public function update_items( $temp = false ) {
3639
+    /**
3640
+     * @deprecated
3641
+     */
3642
+    public function update_items( $temp = false ) {
3643 3643
 
3644
-		$this->set_items( $this->get_items() );
3644
+        $this->set_items( $this->get_items() );
3645 3645
 
3646
-		if ( ! $temp ) {
3647
-			$this->save();
3648
-		}
3646
+        if ( ! $temp ) {
3647
+            $this->save();
3648
+        }
3649 3649
 
3650 3650
         return $this;
3651
-	}
3651
+    }
3652 3652
 
3653
-	/**
3654
-	 * @deprecated
3655
-	 */
3653
+    /**
3654
+     * @deprecated
3655
+     */
3656 3656
     public function validate_discount() {
3657 3657
 
3658 3658
         $discount_code = $this->get_discount_code();
@@ -3668,97 +3668,97 @@  discard block
 block discarded – undo
3668 3668
 
3669 3669
     }
3670 3670
 
3671
-	/**
3672
-	 * Refunds an invoice.
3673
-	 */
3671
+    /**
3672
+     * Refunds an invoice.
3673
+     */
3674 3674
     public function refund() {
3675
-		$this->set_status( 'wpi-refunded' );
3675
+        $this->set_status( 'wpi-refunded' );
3676 3676
         $this->save();
3677
-	}
3677
+    }
3678 3678
 
3679
-	/**
3680
-	 * Marks an invoice as paid.
3681
-	 * 
3682
-	 * @param string $transaction_id
3683
-	 */
3679
+    /**
3680
+     * Marks an invoice as paid.
3681
+     * 
3682
+     * @param string $transaction_id
3683
+     */
3684 3684
     public function mark_paid( $transaction_id = null, $note = '' ) {
3685 3685
 
3686
-		// Set the transaction id.
3687
-		if ( empty( $transaction_id ) ) {
3688
-			$transaction_id = $this->generate_key('trans_');
3689
-		}
3686
+        // Set the transaction id.
3687
+        if ( empty( $transaction_id ) ) {
3688
+            $transaction_id = $this->generate_key('trans_');
3689
+        }
3690 3690
 
3691
-		if ( ! $this->get_transaction_id() ) {
3692
-			$this->set_transaction_id( $transaction_id );
3693
-		}
3691
+        if ( ! $this->get_transaction_id() ) {
3692
+            $this->set_transaction_id( $transaction_id );
3693
+        }
3694 3694
 
3695
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3696
-			return $this->save();
3697
-		}
3695
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3696
+            return $this->save();
3697
+        }
3698 3698
 
3699
-		// Set the completed date.
3700
-		$this->set_date_completed( current_time( 'mysql' ) );
3699
+        // Set the completed date.
3700
+        $this->set_date_completed( current_time( 'mysql' ) );
3701 3701
 
3702
-		// Set the new status.
3703
-		if ( $this->is_renewal() ) {
3702
+        // Set the new status.
3703
+        if ( $this->is_renewal() ) {
3704 3704
 
3705
-			$_note = sprintf(
3706
-				__( 'Renewed via %s', 'invoicing' ),
3707
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3708
-			);
3705
+            $_note = sprintf(
3706
+                __( 'Renewed via %s', 'invoicing' ),
3707
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3708
+            );
3709 3709
 
3710
-			if ( 'none' == $this->get_gateway() ) {
3711
-				$_note = $note;
3712
-			}
3710
+            if ( 'none' == $this->get_gateway() ) {
3711
+                $_note = $note;
3712
+            }
3713 3713
 
3714
-			$this->set_status( 'wpi-renewal', $_note );
3714
+            $this->set_status( 'wpi-renewal', $_note );
3715 3715
 
3716
-		} else {
3716
+        } else {
3717 3717
 
3718
-			$_note = sprintf(
3719
-				__( 'Paid via %s', 'invoicing' ),
3720
-				$this->get_gateway() . empty( $note ) ? '' : " ($note)"
3721
-			);
3718
+            $_note = sprintf(
3719
+                __( 'Paid via %s', 'invoicing' ),
3720
+                $this->get_gateway() . empty( $note ) ? '' : " ($note)"
3721
+            );
3722 3722
 
3723
-			if ( 'none' == $this->get_gateway() ) {
3724
-				$_note = $note;
3725
-			}
3723
+            if ( 'none' == $this->get_gateway() ) {
3724
+                $_note = $note;
3725
+            }
3726 3726
 
3727
-			$this->set_status( 'publish',$_note );
3727
+            $this->set_status( 'publish',$_note );
3728 3728
 
3729
-		}
3729
+        }
3730 3730
 
3731
-		// Set checkout mode.
3732
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3733
-		$this->set_mode( $mode );
3731
+        // Set checkout mode.
3732
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3733
+        $this->set_mode( $mode );
3734 3734
 
3735
-		// Save the invoice.
3735
+        // Save the invoice.
3736 3736
         $this->save();
3737
-	}
3738
-
3739
-
3740
-	/**
3741
-	 * Save data to the database.
3742
-	 *
3743
-	 * @since 1.0.19
3744
-	 * @return int invoice ID
3745
-	 */
3746
-	public function save() {
3747
-		$this->maybe_set_date_paid();
3748
-		$this->maybe_set_key();
3749
-		parent::save();
3750
-		$this->clear_cache();
3751
-		$this->status_transition();
3752
-		return $this->get_id();
3753
-	}
3754
-
3755
-	/**
3737
+    }
3738
+
3739
+
3740
+    /**
3741
+     * Save data to the database.
3742
+     *
3743
+     * @since 1.0.19
3744
+     * @return int invoice ID
3745
+     */
3746
+    public function save() {
3747
+        $this->maybe_set_date_paid();
3748
+        $this->maybe_set_key();
3749
+        parent::save();
3750
+        $this->clear_cache();
3751
+        $this->status_transition();
3752
+        return $this->get_id();
3753
+    }
3754
+
3755
+    /**
3756 3756
      * Clears the subscription's cache.
3757 3757
      */
3758 3758
     public function clear_cache() {
3759
-		wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3760
-		wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3761
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3762
-	}
3759
+        wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3760
+        wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3761
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3762
+    }
3763 3763
 
3764 3764
 }
Please login to merge, or discard this patch.
Spacing   +745 added lines, -745 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
  * Invoice class.
@@ -135,40 +135,40 @@  discard block
 block discarded – undo
135 135
 	 *
136 136
 	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
137 137
 	 */
138
-    public function __construct( $invoice = false ) {
138
+    public function __construct($invoice = false) {
139 139
 
140
-        parent::__construct( $invoice );
140
+        parent::__construct($invoice);
141 141
 
142
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
143
-			$this->set_id( $invoice );
144
-		} elseif ( $invoice instanceof self ) {
145
-			$this->set_id( $invoice->get_id() );
146
-		} elseif ( ! empty( $invoice->ID ) ) {
147
-			$this->set_id( $invoice->ID );
148
-		} elseif ( is_array( $invoice ) ) {
149
-			$this->set_props( $invoice );
142
+		if (!empty($invoice) && is_numeric($invoice) && getpaid_is_invoice_post_type(get_post_type($invoice))) {
143
+			$this->set_id($invoice);
144
+		} elseif ($invoice instanceof self) {
145
+			$this->set_id($invoice->get_id());
146
+		} elseif (!empty($invoice->ID)) {
147
+			$this->set_id($invoice->ID);
148
+		} elseif (is_array($invoice)) {
149
+			$this->set_props($invoice);
150 150
 
151
-			if ( isset( $invoice['ID'] ) ) {
152
-				$this->set_id( $invoice['ID'] );
151
+			if (isset($invoice['ID'])) {
152
+				$this->set_id($invoice['ID']);
153 153
 			}
154 154
 
155
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
156
-			$this->set_id( $invoice_id );
157
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
158
-			$this->set_id( $invoice_id );
159
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
160
-			$this->set_id( $invoice_id );
161
-		}else {
162
-			$this->set_object_read( true );
155
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'key')) {
156
+			$this->set_id($invoice_id);
157
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'number')) {
158
+			$this->set_id($invoice_id);
159
+		} elseif (is_scalar($invoice) && $invoice_id = self::get_invoice_id_by_field($invoice, 'transaction_id')) {
160
+			$this->set_id($invoice_id);
161
+		} else {
162
+			$this->set_object_read(true);
163 163
 		}
164 164
 
165 165
         // Load the datastore.
166
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
166
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
167 167
 
168
-		if ( $this->get_id() > 0 ) {
169
-            $this->post = get_post( $this->get_id() );
168
+		if ($this->get_id() > 0) {
169
+            $this->post = get_post($this->get_id());
170 170
             $this->ID   = $this->get_id();
171
-			$this->data_store->read( $this );
171
+			$this->data_store->read($this);
172 172
         }
173 173
 
174 174
     }
@@ -183,38 +183,38 @@  discard block
 block discarded – undo
183 183
 	 * @since 1.0.15
184 184
 	 * @return int
185 185
 	 */
186
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
186
+	public static function get_invoice_id_by_field($value, $field = 'key') {
187 187
         global $wpdb;
188 188
 
189 189
 		// Trim the value.
190
-		$value = trim( $value );
190
+		$value = trim($value);
191 191
 
192
-		if ( empty( $value ) ) {
192
+		if (empty($value)) {
193 193
 			return 0;
194 194
 		}
195 195
 
196 196
         // Valid fields.
197
-        $fields = array( 'key', 'number', 'transaction_id' );
197
+        $fields = array('key', 'number', 'transaction_id');
198 198
 
199 199
 		// Ensure a field has been passed.
200
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
200
+		if (empty($field) || !in_array($field, $fields)) {
201 201
 			return 0;
202 202
 		}
203 203
 
204 204
 		// Maybe retrieve from the cache.
205
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
206
-		if ( false !== $invoice_id ) {
205
+		$invoice_id = wp_cache_get($value, "getpaid_invoice_{$field}s_to_invoice_ids");
206
+		if (false !== $invoice_id) {
207 207
 			return $invoice_id;
208 208
 		}
209 209
 
210 210
         // Fetch from the db.
211 211
         $table       = $wpdb->prefix . 'getpaid_invoices';
212 212
         $invoice_id  = (int) $wpdb->get_var(
213
-            $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
213
+            $wpdb->prepare("SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
214 214
         );
215 215
 
216 216
 		// Update the cache with our data
217
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
217
+		wp_cache_set($value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids");
218 218
 
219 219
 		return $invoice_id;
220 220
     }
@@ -222,8 +222,8 @@  discard block
 block discarded – undo
222 222
     /**
223 223
      * Checks if an invoice key is set.
224 224
      */
225
-    public function _isset( $key ) {
226
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
225
+    public function _isset($key) {
226
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
227 227
     }
228 228
 
229 229
     /*
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param  string $context View or edit context.
249 249
 	 * @return int
250 250
 	 */
251
-	public function get_parent_id( $context = 'view' ) {
252
-		return (int) $this->get_prop( 'parent_id', $context );
251
+	public function get_parent_id($context = 'view') {
252
+		return (int) $this->get_prop('parent_id', $context);
253 253
     }
254 254
 
255 255
     /**
@@ -259,7 +259,7 @@  discard block
 block discarded – undo
259 259
 	 * @return WPInv_Invoice
260 260
 	 */
261 261
     public function get_parent_payment() {
262
-        return new WPInv_Invoice( $this->get_parent_id() );
262
+        return new WPInv_Invoice($this->get_parent_id());
263 263
     }
264 264
 
265 265
     /**
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 	 * @param  string $context View or edit context.
280 280
 	 * @return string
281 281
 	 */
282
-	public function get_status( $context = 'view' ) {
283
-		return $this->get_prop( 'status', $context );
282
+	public function get_status($context = 'view') {
283
+		return $this->get_prop('status', $context);
284 284
 	}
285 285
 	
286 286
 	/**
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
 	 */
292 292
 	public function get_all_statuses() {
293 293
 
294
-		$statuses = wpinv_get_invoice_statuses( true, true, $this );
294
+		$statuses = wpinv_get_invoice_statuses(true, true, $this);
295 295
 
296 296
 		// For backwards compatibility.
297
-		if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
297
+		if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
298 298
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
299 299
 		}
300 300
 
@@ -310,9 +310,9 @@  discard block
 block discarded – undo
310 310
     public function get_status_nicename() {
311 311
 		$statuses = $this->get_all_statuses();
312 312
 
313
-        $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
313
+        $status = isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : $this->get_status();
314 314
 
315
-        return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
315
+        return apply_filters('wpinv_get_invoice_status_nicename', $status, $this);
316 316
     }
317 317
 
318 318
 	/**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
      */
324 324
     public function get_status_label_html() {
325 325
 
326
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
327
-		$status       = sanitize_html_class( $this->get_status() );
326
+		$status_label = sanitize_text_field($this->get_status_nicename());
327
+		$status       = sanitize_html_class($this->get_status());
328 328
 
329 329
 		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
330 330
 	}
@@ -336,23 +336,23 @@  discard block
 block discarded – undo
336 336
 	 * @param  string $context View or edit context.
337 337
 	 * @return string
338 338
 	 */
339
-	public function get_version( $context = 'view' ) {
340
-		return $this->get_prop( 'version', $context );
339
+	public function get_version($context = 'view') {
340
+		return $this->get_prop('version', $context);
341 341
 	}
342 342
 
343 343
 	/**
344 344
 	 * @deprecated
345 345
 	 */
346
-	public function get_invoice_date( $format = true ) {
347
-		$date      = getpaid_format_date( $this->get_date_completed() );
348
-		$date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
349
-		$formatted = getpaid_format_date( $date );
346
+	public function get_invoice_date($format = true) {
347
+		$date      = getpaid_format_date($this->get_date_completed());
348
+		$date      = empty($date) ? $this->get_date_created() : $this->get_date_completed();
349
+		$formatted = getpaid_format_date($date);
350 350
 
351
-		if ( $format ) {
351
+		if ($format) {
352 352
 			return $formatted;
353 353
 		}
354 354
 
355
-		return empty( $formatted ) ? '' : $date;
355
+		return empty($formatted) ? '' : $date;
356 356
 
357 357
     }
358 358
 
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
 	 * @param  string $context View or edit context.
364 364
 	 * @return string
365 365
 	 */
366
-	public function get_date_created( $context = 'view' ) {
367
-		return $this->get_prop( 'date_created', $context );
366
+	public function get_date_created($context = 'view') {
367
+		return $this->get_prop('date_created', $context);
368 368
 	}
369 369
 	
370 370
 	/**
@@ -374,8 +374,8 @@  discard block
 block discarded – undo
374 374
 	 * @param  string $context View or edit context.
375 375
 	 * @return string
376 376
 	 */
377
-	public function get_created_date( $context = 'view' ) {
378
-		return $this->get_date_created( $context );
377
+	public function get_created_date($context = 'view') {
378
+		return $this->get_date_created($context);
379 379
     }
380 380
 
381 381
     /**
@@ -385,11 +385,11 @@  discard block
 block discarded – undo
385 385
 	 * @param  string $context View or edit context.
386 386
 	 * @return string
387 387
 	 */
388
-	public function get_date_created_gmt( $context = 'view' ) {
389
-        $date = $this->get_date_created( $context );
388
+	public function get_date_created_gmt($context = 'view') {
389
+        $date = $this->get_date_created($context);
390 390
 
391
-        if ( $date ) {
392
-            $date = get_gmt_from_date( $date );
391
+        if ($date) {
392
+            $date = get_gmt_from_date($date);
393 393
         }
394 394
 		return $date;
395 395
     }
@@ -401,8 +401,8 @@  discard block
 block discarded – undo
401 401
 	 * @param  string $context View or edit context.
402 402
 	 * @return string
403 403
 	 */
404
-	public function get_date_modified( $context = 'view' ) {
405
-		return $this->get_prop( 'date_modified', $context );
404
+	public function get_date_modified($context = 'view') {
405
+		return $this->get_prop('date_modified', $context);
406 406
 	}
407 407
 
408 408
 	/**
@@ -412,8 +412,8 @@  discard block
 block discarded – undo
412 412
 	 * @param  string $context View or edit context.
413 413
 	 * @return string
414 414
 	 */
415
-	public function get_modified_date( $context = 'view' ) {
416
-		return $this->get_date_modified( $context );
415
+	public function get_modified_date($context = 'view') {
416
+		return $this->get_date_modified($context);
417 417
     }
418 418
 
419 419
     /**
@@ -423,11 +423,11 @@  discard block
 block discarded – undo
423 423
 	 * @param  string $context View or edit context.
424 424
 	 * @return string
425 425
 	 */
426
-	public function get_date_modified_gmt( $context = 'view' ) {
427
-        $date = $this->get_date_modified( $context );
426
+	public function get_date_modified_gmt($context = 'view') {
427
+        $date = $this->get_date_modified($context);
428 428
 
429
-        if ( $date ) {
430
-            $date = get_gmt_from_date( $date );
429
+        if ($date) {
430
+            $date = get_gmt_from_date($date);
431 431
         }
432 432
 		return $date;
433 433
     }
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
 	 * @param  string $context View or edit context.
440 440
 	 * @return string
441 441
 	 */
442
-	public function get_due_date( $context = 'view' ) {
443
-		return $this->get_prop( 'due_date', $context );
442
+	public function get_due_date($context = 'view') {
443
+		return $this->get_prop('due_date', $context);
444 444
     }
445 445
 
446 446
     /**
@@ -450,8 +450,8 @@  discard block
 block discarded – undo
450 450
 	 * @param  string $context View or edit context.
451 451
 	 * @return string
452 452
 	 */
453
-	public function get_date_due( $context = 'view' ) {
454
-		return $this->get_due_date( $context );
453
+	public function get_date_due($context = 'view') {
454
+		return $this->get_due_date($context);
455 455
     }
456 456
 
457 457
     /**
@@ -461,11 +461,11 @@  discard block
 block discarded – undo
461 461
 	 * @param  string $context View or edit context.
462 462
 	 * @return string
463 463
 	 */
464
-	public function get_due_date_gmt( $context = 'view' ) {
465
-        $date = $this->get_due_date( $context );
464
+	public function get_due_date_gmt($context = 'view') {
465
+        $date = $this->get_due_date($context);
466 466
 
467
-        if ( $date ) {
468
-            $date = get_gmt_from_date( $date );
467
+        if ($date) {
468
+            $date = get_gmt_from_date($date);
469 469
         }
470 470
 		return $date;
471 471
     }
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 	 * @param  string $context View or edit context.
478 478
 	 * @return string
479 479
 	 */
480
-	public function get_gmt_date_due( $context = 'view' ) {
481
-		return $this->get_due_date_gmt( $context );
480
+	public function get_gmt_date_due($context = 'view') {
481
+		return $this->get_due_date_gmt($context);
482 482
     }
483 483
 
484 484
     /**
@@ -488,8 +488,8 @@  discard block
 block discarded – undo
488 488
 	 * @param  string $context View or edit context.
489 489
 	 * @return string
490 490
 	 */
491
-	public function get_completed_date( $context = 'view' ) {
492
-		return $this->get_prop( 'completed_date', $context );
491
+	public function get_completed_date($context = 'view') {
492
+		return $this->get_prop('completed_date', $context);
493 493
     }
494 494
 
495 495
     /**
@@ -499,8 +499,8 @@  discard block
 block discarded – undo
499 499
 	 * @param  string $context View or edit context.
500 500
 	 * @return string
501 501
 	 */
502
-	public function get_date_completed( $context = 'view' ) {
503
-		return $this->get_completed_date( $context );
502
+	public function get_date_completed($context = 'view') {
503
+		return $this->get_completed_date($context);
504 504
     }
505 505
 
506 506
     /**
@@ -510,11 +510,11 @@  discard block
 block discarded – undo
510 510
 	 * @param  string $context View or edit context.
511 511
 	 * @return string
512 512
 	 */
513
-	public function get_completed_date_gmt( $context = 'view' ) {
514
-        $date = $this->get_completed_date( $context );
513
+	public function get_completed_date_gmt($context = 'view') {
514
+        $date = $this->get_completed_date($context);
515 515
 
516
-        if ( $date ) {
517
-            $date = get_gmt_from_date( $date );
516
+        if ($date) {
517
+            $date = get_gmt_from_date($date);
518 518
         }
519 519
 		return $date;
520 520
     }
@@ -526,8 +526,8 @@  discard block
 block discarded – undo
526 526
 	 * @param  string $context View or edit context.
527 527
 	 * @return string
528 528
 	 */
529
-	public function get_gmt_completed_date( $context = 'view' ) {
530
-		return $this->get_completed_date_gmt( $context );
529
+	public function get_gmt_completed_date($context = 'view') {
530
+		return $this->get_completed_date_gmt($context);
531 531
     }
532 532
 
533 533
     /**
@@ -537,12 +537,12 @@  discard block
 block discarded – undo
537 537
 	 * @param  string $context View or edit context.
538 538
 	 * @return string
539 539
 	 */
540
-	public function get_number( $context = 'view' ) {
541
-		$number = $this->get_prop( 'number', $context );
540
+	public function get_number($context = 'view') {
541
+		$number = $this->get_prop('number', $context);
542 542
 
543
-		if ( empty( $number ) ) {
543
+		if (empty($number)) {
544 544
 			$number = $this->generate_number();
545
-			$this->set_number( $this->generate_number() );
545
+			$this->set_number($this->generate_number());
546 546
 		}
547 547
 
548 548
 		return $number;
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
 	public function maybe_set_number() {
557 557
         $number = $this->get_number();
558 558
 
559
-        if ( empty( $number ) || $this->get_id() == $number ) {
560
-			$this->set_number( $this->generate_number() );
559
+        if (empty($number) || $this->get_id() == $number) {
560
+			$this->set_number($this->generate_number());
561 561
         }
562 562
 
563 563
 	}
@@ -569,8 +569,8 @@  discard block
 block discarded – undo
569 569
 	 * @param  string $context View or edit context.
570 570
 	 * @return string
571 571
 	 */
572
-	public function get_key( $context = 'view' ) {
573
-        return $this->get_prop( 'key', $context );
572
+	public function get_key($context = 'view') {
573
+        return $this->get_prop('key', $context);
574 574
 	}
575 575
 
576 576
 	/**
@@ -581,9 +581,9 @@  discard block
 block discarded – undo
581 581
 	public function maybe_set_key() {
582 582
         $key = $this->get_key();
583 583
 
584
-        if ( empty( $key ) ) {
585
-            $key = $this->generate_key( $this->get_type() . '_' );
586
-            $this->set_key( $key );
584
+        if (empty($key)) {
585
+            $key = $this->generate_key($this->get_type() . '_');
586
+            $this->set_key($key);
587 587
         }
588 588
 
589 589
     }
@@ -595,15 +595,15 @@  discard block
 block discarded – undo
595 595
 	 * @param  string $context View or edit context.
596 596
 	 * @return string
597 597
 	 */
598
-	public function get_type( $context = 'view' ) {
599
-        return $this->get_prop( 'type', $context );
598
+	public function get_type($context = 'view') {
599
+        return $this->get_prop('type', $context);
600 600
 	}
601 601
 
602 602
 	/**
603 603
 	 * @deprecated
604 604
 	 */
605 605
 	public function get_invoice_quote_type() {
606
-        ucfirst( $this->get_type() );
606
+        ucfirst($this->get_type());
607 607
     }
608 608
 
609 609
     /**
@@ -613,8 +613,8 @@  discard block
 block discarded – undo
613 613
 	 * @param  string $context View or edit context.
614 614
 	 * @return string
615 615
 	 */
616
-	public function get_post_type( $context = 'view' ) {
617
-        return $this->get_prop( 'post_type', $context );
616
+	public function get_post_type($context = 'view') {
617
+        return $this->get_prop('post_type', $context);
618 618
     }
619 619
 
620 620
     /**
@@ -624,8 +624,8 @@  discard block
 block discarded – undo
624 624
 	 * @param  string $context View or edit context.
625 625
 	 * @return string
626 626
 	 */
627
-	public function get_mode( $context = 'view' ) {
628
-        return $this->get_prop( 'mode', $context );
627
+	public function get_mode($context = 'view') {
628
+        return $this->get_prop('mode', $context);
629 629
     }
630 630
 
631 631
     /**
@@ -635,13 +635,13 @@  discard block
 block discarded – undo
635 635
 	 * @param  string $context View or edit context.
636 636
 	 * @return string
637 637
 	 */
638
-	public function get_path( $context = 'view' ) {
639
-        $path   = $this->get_prop( 'path', $context );
640
-		$prefix = wpinv_post_name_prefix( $this->get_post_type() );
638
+	public function get_path($context = 'view') {
639
+        $path = $this->get_prop('path', $context);
640
+		$prefix = wpinv_post_name_prefix($this->get_post_type());
641 641
 
642
-		if ( 0 !== strpos( $path, $prefix ) ) {
643
-			$path = sanitize_title(  $prefix . $this->get_id()  );
644
-			$this->set_path( $path );
642
+		if (0 !== strpos($path, $prefix)) {
643
+			$path = sanitize_title($prefix . $this->get_id());
644
+			$this->set_path($path);
645 645
 		}
646 646
 
647 647
 		return $path;
@@ -654,8 +654,8 @@  discard block
 block discarded – undo
654 654
 	 * @param  string $context View or edit context.
655 655
 	 * @return string
656 656
 	 */
657
-	public function get_name( $context = 'view' ) {
658
-        return $this->get_prop( 'title', $context );
657
+	public function get_name($context = 'view') {
658
+        return $this->get_prop('title', $context);
659 659
     }
660 660
 
661 661
     /**
@@ -665,8 +665,8 @@  discard block
 block discarded – undo
665 665
 	 * @param  string $context View or edit context.
666 666
 	 * @return string
667 667
 	 */
668
-	public function get_title( $context = 'view' ) {
669
-		return $this->get_name( $context );
668
+	public function get_title($context = 'view') {
669
+		return $this->get_name($context);
670 670
     }
671 671
 
672 672
     /**
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
 	 * @param  string $context View or edit context.
677 677
 	 * @return string
678 678
 	 */
679
-	public function get_description( $context = 'view' ) {
680
-		return $this->get_prop( 'description', $context );
679
+	public function get_description($context = 'view') {
680
+		return $this->get_prop('description', $context);
681 681
     }
682 682
 
683 683
     /**
@@ -687,8 +687,8 @@  discard block
 block discarded – undo
687 687
 	 * @param  string $context View or edit context.
688 688
 	 * @return string
689 689
 	 */
690
-	public function get_excerpt( $context = 'view' ) {
691
-		return $this->get_description( $context );
690
+	public function get_excerpt($context = 'view') {
691
+		return $this->get_description($context);
692 692
     }
693 693
 
694 694
     /**
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
 	 * @param  string $context View or edit context.
699 699
 	 * @return string
700 700
 	 */
701
-	public function get_summary( $context = 'view' ) {
702
-		return $this->get_description( $context );
701
+	public function get_summary($context = 'view') {
702
+		return $this->get_description($context);
703 703
     }
704 704
 
705 705
     /**
@@ -709,25 +709,25 @@  discard block
 block discarded – undo
709 709
      * @param  string $context View or edit context.
710 710
 	 * @return array
711 711
 	 */
712
-    public function get_user_info( $context = 'view' ) {
712
+    public function get_user_info($context = 'view') {
713 713
 
714 714
         $user_info = array(
715
-            'user_id'    => $this->get_user_id( $context ),
716
-            'email'      => $this->get_email( $context ),
717
-            'first_name' => $this->get_first_name( $context ),
718
-            'last_name'  => $this->get_last_name( $context ),
719
-            'address'    => $this->get_address( $context ),
720
-            'phone'      => $this->get_phone( $context ),
721
-            'city'       => $this->get_city( $context ),
722
-            'country'    => $this->get_country( $context ),
723
-            'state'      => $this->get_state( $context ),
724
-            'zip'        => $this->get_zip( $context ),
725
-            'company'    => $this->get_company( $context ),
726
-            'vat_number' => $this->get_vat_number( $context ),
727
-            'discount'   => $this->get_discount_code( $context ),
715
+            'user_id'    => $this->get_user_id($context),
716
+            'email'      => $this->get_email($context),
717
+            'first_name' => $this->get_first_name($context),
718
+            'last_name'  => $this->get_last_name($context),
719
+            'address'    => $this->get_address($context),
720
+            'phone'      => $this->get_phone($context),
721
+            'city'       => $this->get_city($context),
722
+            'country'    => $this->get_country($context),
723
+            'state'      => $this->get_state($context),
724
+            'zip'        => $this->get_zip($context),
725
+            'company'    => $this->get_company($context),
726
+            'vat_number' => $this->get_vat_number($context),
727
+            'discount'   => $this->get_discount_code($context),
728 728
 		);
729 729
 
730
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
730
+		return apply_filters('wpinv_user_info', $user_info, $this->get_id(), $this);
731 731
 
732 732
     }
733 733
 
@@ -738,8 +738,8 @@  discard block
 block discarded – undo
738 738
 	 * @param  string $context View or edit context.
739 739
 	 * @return int
740 740
 	 */
741
-	public function get_author( $context = 'view' ) {
742
-		return (int) $this->get_prop( 'author', $context );
741
+	public function get_author($context = 'view') {
742
+		return (int) $this->get_prop('author', $context);
743 743
     }
744 744
 
745 745
     /**
@@ -749,8 +749,8 @@  discard block
 block discarded – undo
749 749
 	 * @param  string $context View or edit context.
750 750
 	 * @return int
751 751
 	 */
752
-	public function get_user_id( $context = 'view' ) {
753
-		return $this->get_author( $context );
752
+	public function get_user_id($context = 'view') {
753
+		return $this->get_author($context);
754 754
     }
755 755
 
756 756
      /**
@@ -760,8 +760,8 @@  discard block
 block discarded – undo
760 760
 	 * @param  string $context View or edit context.
761 761
 	 * @return int
762 762
 	 */
763
-	public function get_customer_id( $context = 'view' ) {
764
-		return $this->get_author( $context );
763
+	public function get_customer_id($context = 'view') {
764
+		return $this->get_author($context);
765 765
     }
766 766
 
767 767
     /**
@@ -771,8 +771,8 @@  discard block
 block discarded – undo
771 771
 	 * @param  string $context View or edit context.
772 772
 	 * @return string
773 773
 	 */
774
-	public function get_ip( $context = 'view' ) {
775
-		return $this->get_prop( 'user_ip', $context );
774
+	public function get_ip($context = 'view') {
775
+		return $this->get_prop('user_ip', $context);
776 776
     }
777 777
 
778 778
     /**
@@ -782,8 +782,8 @@  discard block
 block discarded – undo
782 782
 	 * @param  string $context View or edit context.
783 783
 	 * @return string
784 784
 	 */
785
-	public function get_user_ip( $context = 'view' ) {
786
-		return $this->get_ip( $context );
785
+	public function get_user_ip($context = 'view') {
786
+		return $this->get_ip($context);
787 787
     }
788 788
 
789 789
      /**
@@ -793,8 +793,8 @@  discard block
 block discarded – undo
793 793
 	 * @param  string $context View or edit context.
794 794
 	 * @return string
795 795
 	 */
796
-	public function get_customer_ip( $context = 'view' ) {
797
-		return $this->get_ip( $context );
796
+	public function get_customer_ip($context = 'view') {
797
+		return $this->get_ip($context);
798 798
     }
799 799
 
800 800
     /**
@@ -804,8 +804,8 @@  discard block
 block discarded – undo
804 804
 	 * @param  string $context View or edit context.
805 805
 	 * @return string
806 806
 	 */
807
-	public function get_first_name( $context = 'view' ) {
808
-		return $this->get_prop( 'first_name', $context );
807
+	public function get_first_name($context = 'view') {
808
+		return $this->get_prop('first_name', $context);
809 809
     }
810 810
 
811 811
     /**
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
 	 * @param  string $context View or edit context.
816 816
 	 * @return int
817 817
 	 */
818
-	public function get_user_first_name( $context = 'view' ) {
819
-		return $this->get_first_name( $context );
818
+	public function get_user_first_name($context = 'view') {
819
+		return $this->get_first_name($context);
820 820
     }
821 821
 
822 822
      /**
@@ -826,8 +826,8 @@  discard block
 block discarded – undo
826 826
 	 * @param  string $context View or edit context.
827 827
 	 * @return int
828 828
 	 */
829
-	public function get_customer_first_name( $context = 'view' ) {
830
-		return $this->get_first_name( $context );
829
+	public function get_customer_first_name($context = 'view') {
830
+		return $this->get_first_name($context);
831 831
     }
832 832
 
833 833
     /**
@@ -837,8 +837,8 @@  discard block
 block discarded – undo
837 837
 	 * @param  string $context View or edit context.
838 838
 	 * @return string
839 839
 	 */
840
-	public function get_last_name( $context = 'view' ) {
841
-		return $this->get_prop( 'last_name', $context );
840
+	public function get_last_name($context = 'view') {
841
+		return $this->get_prop('last_name', $context);
842 842
     }
843 843
 
844 844
     /**
@@ -848,8 +848,8 @@  discard block
 block discarded – undo
848 848
 	 * @param  string $context View or edit context.
849 849
 	 * @return int
850 850
 	 */
851
-	public function get_user_last_name( $context = 'view' ) {
852
-		return $this->get_last_name( $context );
851
+	public function get_user_last_name($context = 'view') {
852
+		return $this->get_last_name($context);
853 853
     }
854 854
 
855 855
     /**
@@ -859,8 +859,8 @@  discard block
 block discarded – undo
859 859
 	 * @param  string $context View or edit context.
860 860
 	 * @return int
861 861
 	 */
862
-	public function get_customer_last_name( $context = 'view' ) {
863
-		return $this->get_last_name( $context );
862
+	public function get_customer_last_name($context = 'view') {
863
+		return $this->get_last_name($context);
864 864
     }
865 865
 
866 866
     /**
@@ -870,8 +870,8 @@  discard block
 block discarded – undo
870 870
 	 * @param  string $context View or edit context.
871 871
 	 * @return string
872 872
 	 */
873
-	public function get_full_name( $context = 'view' ) {
874
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
873
+	public function get_full_name($context = 'view') {
874
+		return trim($this->get_first_name($context) . ' ' . $this->get_last_name($context));
875 875
     }
876 876
 
877 877
     /**
@@ -881,8 +881,8 @@  discard block
 block discarded – undo
881 881
 	 * @param  string $context View or edit context.
882 882
 	 * @return int
883 883
 	 */
884
-	public function get_user_full_name( $context = 'view' ) {
885
-		return $this->get_full_name( $context );
884
+	public function get_user_full_name($context = 'view') {
885
+		return $this->get_full_name($context);
886 886
     }
887 887
 
888 888
     /**
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
 	 * @param  string $context View or edit context.
893 893
 	 * @return int
894 894
 	 */
895
-	public function get_customer_full_name( $context = 'view' ) {
896
-		return $this->get_full_name( $context );
895
+	public function get_customer_full_name($context = 'view') {
896
+		return $this->get_full_name($context);
897 897
     }
898 898
 
899 899
     /**
@@ -903,8 +903,8 @@  discard block
 block discarded – undo
903 903
 	 * @param  string $context View or edit context.
904 904
 	 * @return string
905 905
 	 */
906
-	public function get_phone( $context = 'view' ) {
907
-		return $this->get_prop( 'phone', $context );
906
+	public function get_phone($context = 'view') {
907
+		return $this->get_prop('phone', $context);
908 908
     }
909 909
 
910 910
     /**
@@ -914,8 +914,8 @@  discard block
 block discarded – undo
914 914
 	 * @param  string $context View or edit context.
915 915
 	 * @return int
916 916
 	 */
917
-	public function get_phone_number( $context = 'view' ) {
918
-		return $this->get_phone( $context );
917
+	public function get_phone_number($context = 'view') {
918
+		return $this->get_phone($context);
919 919
     }
920 920
 
921 921
     /**
@@ -925,8 +925,8 @@  discard block
 block discarded – undo
925 925
 	 * @param  string $context View or edit context.
926 926
 	 * @return int
927 927
 	 */
928
-	public function get_user_phone( $context = 'view' ) {
929
-		return $this->get_phone( $context );
928
+	public function get_user_phone($context = 'view') {
929
+		return $this->get_phone($context);
930 930
     }
931 931
 
932 932
     /**
@@ -936,8 +936,8 @@  discard block
 block discarded – undo
936 936
 	 * @param  string $context View or edit context.
937 937
 	 * @return int
938 938
 	 */
939
-	public function get_customer_phone( $context = 'view' ) {
940
-		return $this->get_phone( $context );
939
+	public function get_customer_phone($context = 'view') {
940
+		return $this->get_phone($context);
941 941
     }
942 942
 
943 943
     /**
@@ -947,8 +947,8 @@  discard block
 block discarded – undo
947 947
 	 * @param  string $context View or edit context.
948 948
 	 * @return string
949 949
 	 */
950
-	public function get_email( $context = 'view' ) {
951
-		return $this->get_prop( 'email', $context );
950
+	public function get_email($context = 'view') {
951
+		return $this->get_prop('email', $context);
952 952
     }
953 953
 
954 954
     /**
@@ -958,8 +958,8 @@  discard block
 block discarded – undo
958 958
 	 * @param  string $context View or edit context.
959 959
 	 * @return string
960 960
 	 */
961
-	public function get_email_address( $context = 'view' ) {
962
-		return $this->get_email( $context );
961
+	public function get_email_address($context = 'view') {
962
+		return $this->get_email($context);
963 963
     }
964 964
 
965 965
     /**
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 	 * @param  string $context View or edit context.
970 970
 	 * @return int
971 971
 	 */
972
-	public function get_user_email( $context = 'view' ) {
973
-		return $this->get_email( $context );
972
+	public function get_user_email($context = 'view') {
973
+		return $this->get_email($context);
974 974
     }
975 975
 
976 976
     /**
@@ -980,8 +980,8 @@  discard block
 block discarded – undo
980 980
 	 * @param  string $context View or edit context.
981 981
 	 * @return int
982 982
 	 */
983
-	public function get_customer_email( $context = 'view' ) {
984
-		return $this->get_email( $context );
983
+	public function get_customer_email($context = 'view') {
984
+		return $this->get_email($context);
985 985
     }
986 986
 
987 987
     /**
@@ -991,9 +991,9 @@  discard block
 block discarded – undo
991 991
 	 * @param  string $context View or edit context.
992 992
 	 * @return string
993 993
 	 */
994
-	public function get_country( $context = 'view' ) {
995
-		$country = $this->get_prop( 'country', $context );
996
-		return empty( $country ) ? wpinv_get_default_country() : $country;
994
+	public function get_country($context = 'view') {
995
+		$country = $this->get_prop('country', $context);
996
+		return empty($country) ? wpinv_get_default_country() : $country;
997 997
     }
998 998
 
999 999
     /**
@@ -1003,8 +1003,8 @@  discard block
 block discarded – undo
1003 1003
 	 * @param  string $context View or edit context.
1004 1004
 	 * @return int
1005 1005
 	 */
1006
-	public function get_user_country( $context = 'view' ) {
1007
-		return $this->get_country( $context );
1006
+	public function get_user_country($context = 'view') {
1007
+		return $this->get_country($context);
1008 1008
     }
1009 1009
 
1010 1010
     /**
@@ -1014,8 +1014,8 @@  discard block
 block discarded – undo
1014 1014
 	 * @param  string $context View or edit context.
1015 1015
 	 * @return int
1016 1016
 	 */
1017
-	public function get_customer_country( $context = 'view' ) {
1018
-		return $this->get_country( $context );
1017
+	public function get_customer_country($context = 'view') {
1018
+		return $this->get_country($context);
1019 1019
     }
1020 1020
 
1021 1021
     /**
@@ -1025,9 +1025,9 @@  discard block
 block discarded – undo
1025 1025
 	 * @param  string $context View or edit context.
1026 1026
 	 * @return string
1027 1027
 	 */
1028
-	public function get_state( $context = 'view' ) {
1029
-		$state = $this->get_prop( 'state', $context );
1030
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1028
+	public function get_state($context = 'view') {
1029
+		$state = $this->get_prop('state', $context);
1030
+		return empty($state) ? wpinv_get_default_state() : $state;
1031 1031
     }
1032 1032
 
1033 1033
     /**
@@ -1037,8 +1037,8 @@  discard block
 block discarded – undo
1037 1037
 	 * @param  string $context View or edit context.
1038 1038
 	 * @return int
1039 1039
 	 */
1040
-	public function get_user_state( $context = 'view' ) {
1041
-		return $this->get_state( $context );
1040
+	public function get_user_state($context = 'view') {
1041
+		return $this->get_state($context);
1042 1042
     }
1043 1043
 
1044 1044
     /**
@@ -1048,8 +1048,8 @@  discard block
 block discarded – undo
1048 1048
 	 * @param  string $context View or edit context.
1049 1049
 	 * @return int
1050 1050
 	 */
1051
-	public function get_customer_state( $context = 'view' ) {
1052
-		return $this->get_state( $context );
1051
+	public function get_customer_state($context = 'view') {
1052
+		return $this->get_state($context);
1053 1053
     }
1054 1054
 
1055 1055
     /**
@@ -1059,8 +1059,8 @@  discard block
 block discarded – undo
1059 1059
 	 * @param  string $context View or edit context.
1060 1060
 	 * @return string
1061 1061
 	 */
1062
-	public function get_city( $context = 'view' ) {
1063
-		return $this->get_prop( 'city', $context );
1062
+	public function get_city($context = 'view') {
1063
+		return $this->get_prop('city', $context);
1064 1064
     }
1065 1065
 
1066 1066
     /**
@@ -1070,8 +1070,8 @@  discard block
 block discarded – undo
1070 1070
 	 * @param  string $context View or edit context.
1071 1071
 	 * @return string
1072 1072
 	 */
1073
-	public function get_user_city( $context = 'view' ) {
1074
-		return $this->get_city( $context );
1073
+	public function get_user_city($context = 'view') {
1074
+		return $this->get_city($context);
1075 1075
     }
1076 1076
 
1077 1077
     /**
@@ -1081,8 +1081,8 @@  discard block
 block discarded – undo
1081 1081
 	 * @param  string $context View or edit context.
1082 1082
 	 * @return string
1083 1083
 	 */
1084
-	public function get_customer_city( $context = 'view' ) {
1085
-		return $this->get_city( $context );
1084
+	public function get_customer_city($context = 'view') {
1085
+		return $this->get_city($context);
1086 1086
     }
1087 1087
 
1088 1088
     /**
@@ -1092,8 +1092,8 @@  discard block
 block discarded – undo
1092 1092
 	 * @param  string $context View or edit context.
1093 1093
 	 * @return string
1094 1094
 	 */
1095
-	public function get_zip( $context = 'view' ) {
1096
-		return $this->get_prop( 'zip', $context );
1095
+	public function get_zip($context = 'view') {
1096
+		return $this->get_prop('zip', $context);
1097 1097
     }
1098 1098
 
1099 1099
     /**
@@ -1103,8 +1103,8 @@  discard block
 block discarded – undo
1103 1103
 	 * @param  string $context View or edit context.
1104 1104
 	 * @return string
1105 1105
 	 */
1106
-	public function get_user_zip( $context = 'view' ) {
1107
-		return $this->get_zip( $context );
1106
+	public function get_user_zip($context = 'view') {
1107
+		return $this->get_zip($context);
1108 1108
     }
1109 1109
 
1110 1110
     /**
@@ -1114,8 +1114,8 @@  discard block
 block discarded – undo
1114 1114
 	 * @param  string $context View or edit context.
1115 1115
 	 * @return string
1116 1116
 	 */
1117
-	public function get_customer_zip( $context = 'view' ) {
1118
-		return $this->get_zip( $context );
1117
+	public function get_customer_zip($context = 'view') {
1118
+		return $this->get_zip($context);
1119 1119
     }
1120 1120
 
1121 1121
     /**
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
 	 * @param  string $context View or edit context.
1126 1126
 	 * @return string
1127 1127
 	 */
1128
-	public function get_company( $context = 'view' ) {
1129
-		return $this->get_prop( 'company', $context );
1128
+	public function get_company($context = 'view') {
1129
+		return $this->get_prop('company', $context);
1130 1130
     }
1131 1131
 
1132 1132
     /**
@@ -1136,8 +1136,8 @@  discard block
 block discarded – undo
1136 1136
 	 * @param  string $context View or edit context.
1137 1137
 	 * @return string
1138 1138
 	 */
1139
-	public function get_user_company( $context = 'view' ) {
1140
-		return $this->get_company( $context );
1139
+	public function get_user_company($context = 'view') {
1140
+		return $this->get_company($context);
1141 1141
     }
1142 1142
 
1143 1143
     /**
@@ -1147,8 +1147,8 @@  discard block
 block discarded – undo
1147 1147
 	 * @param  string $context View or edit context.
1148 1148
 	 * @return string
1149 1149
 	 */
1150
-	public function get_customer_company( $context = 'view' ) {
1151
-		return $this->get_company( $context );
1150
+	public function get_customer_company($context = 'view') {
1151
+		return $this->get_company($context);
1152 1152
     }
1153 1153
 
1154 1154
     /**
@@ -1158,8 +1158,8 @@  discard block
 block discarded – undo
1158 1158
 	 * @param  string $context View or edit context.
1159 1159
 	 * @return string
1160 1160
 	 */
1161
-	public function get_vat_number( $context = 'view' ) {
1162
-		return $this->get_prop( 'vat_number', $context );
1161
+	public function get_vat_number($context = 'view') {
1162
+		return $this->get_prop('vat_number', $context);
1163 1163
     }
1164 1164
 
1165 1165
     /**
@@ -1169,8 +1169,8 @@  discard block
 block discarded – undo
1169 1169
 	 * @param  string $context View or edit context.
1170 1170
 	 * @return string
1171 1171
 	 */
1172
-	public function get_user_vat_number( $context = 'view' ) {
1173
-		return $this->get_vat_number( $context );
1172
+	public function get_user_vat_number($context = 'view') {
1173
+		return $this->get_vat_number($context);
1174 1174
     }
1175 1175
 
1176 1176
     /**
@@ -1180,8 +1180,8 @@  discard block
 block discarded – undo
1180 1180
 	 * @param  string $context View or edit context.
1181 1181
 	 * @return string
1182 1182
 	 */
1183
-	public function get_customer_vat_number( $context = 'view' ) {
1184
-		return $this->get_vat_number( $context );
1183
+	public function get_customer_vat_number($context = 'view') {
1184
+		return $this->get_vat_number($context);
1185 1185
     }
1186 1186
 
1187 1187
     /**
@@ -1191,8 +1191,8 @@  discard block
 block discarded – undo
1191 1191
 	 * @param  string $context View or edit context.
1192 1192
 	 * @return string
1193 1193
 	 */
1194
-	public function get_vat_rate( $context = 'view' ) {
1195
-		return $this->get_prop( 'vat_rate', $context );
1194
+	public function get_vat_rate($context = 'view') {
1195
+		return $this->get_prop('vat_rate', $context);
1196 1196
     }
1197 1197
 
1198 1198
     /**
@@ -1202,8 +1202,8 @@  discard block
 block discarded – undo
1202 1202
 	 * @param  string $context View or edit context.
1203 1203
 	 * @return string
1204 1204
 	 */
1205
-	public function get_user_vat_rate( $context = 'view' ) {
1206
-		return $this->get_vat_rate( $context );
1205
+	public function get_user_vat_rate($context = 'view') {
1206
+		return $this->get_vat_rate($context);
1207 1207
     }
1208 1208
 
1209 1209
     /**
@@ -1213,8 +1213,8 @@  discard block
 block discarded – undo
1213 1213
 	 * @param  string $context View or edit context.
1214 1214
 	 * @return string
1215 1215
 	 */
1216
-	public function get_customer_vat_rate( $context = 'view' ) {
1217
-		return $this->get_vat_rate( $context );
1216
+	public function get_customer_vat_rate($context = 'view') {
1217
+		return $this->get_vat_rate($context);
1218 1218
     }
1219 1219
 
1220 1220
     /**
@@ -1224,8 +1224,8 @@  discard block
 block discarded – undo
1224 1224
 	 * @param  string $context View or edit context.
1225 1225
 	 * @return string
1226 1226
 	 */
1227
-	public function get_address( $context = 'view' ) {
1228
-		return $this->get_prop( 'address', $context );
1227
+	public function get_address($context = 'view') {
1228
+		return $this->get_prop('address', $context);
1229 1229
     }
1230 1230
 
1231 1231
     /**
@@ -1235,8 +1235,8 @@  discard block
 block discarded – undo
1235 1235
 	 * @param  string $context View or edit context.
1236 1236
 	 * @return string
1237 1237
 	 */
1238
-	public function get_user_address( $context = 'view' ) {
1239
-		return $this->get_address( $context );
1238
+	public function get_user_address($context = 'view') {
1239
+		return $this->get_address($context);
1240 1240
     }
1241 1241
 
1242 1242
     /**
@@ -1246,8 +1246,8 @@  discard block
 block discarded – undo
1246 1246
 	 * @param  string $context View or edit context.
1247 1247
 	 * @return string
1248 1248
 	 */
1249
-	public function get_customer_address( $context = 'view' ) {
1250
-		return $this->get_address( $context );
1249
+	public function get_customer_address($context = 'view') {
1250
+		return $this->get_address($context);
1251 1251
     }
1252 1252
 
1253 1253
     /**
@@ -1257,8 +1257,8 @@  discard block
 block discarded – undo
1257 1257
 	 * @param  string $context View or edit context.
1258 1258
 	 * @return bool
1259 1259
 	 */
1260
-	public function get_is_viewed( $context = 'view' ) {
1261
-		return (bool) $this->get_prop( 'is_viewed', $context );
1260
+	public function get_is_viewed($context = 'view') {
1261
+		return (bool) $this->get_prop('is_viewed', $context);
1262 1262
 	}
1263 1263
 
1264 1264
 	/**
@@ -1268,8 +1268,8 @@  discard block
 block discarded – undo
1268 1268
 	 * @param  string $context View or edit context.
1269 1269
 	 * @return bool
1270 1270
 	 */
1271
-	public function get_email_cc( $context = 'view' ) {
1272
-		return $this->get_prop( 'email_cc', $context );
1271
+	public function get_email_cc($context = 'view') {
1272
+		return $this->get_prop('email_cc', $context);
1273 1273
 	}
1274 1274
 
1275 1275
 	/**
@@ -1279,8 +1279,8 @@  discard block
 block discarded – undo
1279 1279
 	 * @param  string $context View or edit context.
1280 1280
 	 * @return bool
1281 1281
 	 */
1282
-	public function get_template( $context = 'view' ) {
1283
-		return $this->get_prop( 'template', $context );
1282
+	public function get_template($context = 'view') {
1283
+		return $this->get_prop('template', $context);
1284 1284
 	}
1285 1285
 
1286 1286
 	/**
@@ -1290,8 +1290,8 @@  discard block
 block discarded – undo
1290 1290
 	 * @param  string $context View or edit context.
1291 1291
 	 * @return bool
1292 1292
 	 */
1293
-	public function get_created_via( $context = 'view' ) {
1294
-		return $this->get_prop( 'created_via', $context );
1293
+	public function get_created_via($context = 'view') {
1294
+		return $this->get_prop('created_via', $context);
1295 1295
 	}
1296 1296
 
1297 1297
 	/**
@@ -1301,8 +1301,8 @@  discard block
 block discarded – undo
1301 1301
 	 * @param  string $context View or edit context.
1302 1302
 	 * @return bool
1303 1303
 	 */
1304
-	public function get_address_confirmed( $context = 'view' ) {
1305
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1304
+	public function get_address_confirmed($context = 'view') {
1305
+		return (bool) $this->get_prop('address_confirmed', $context);
1306 1306
     }
1307 1307
 
1308 1308
     /**
@@ -1312,8 +1312,8 @@  discard block
 block discarded – undo
1312 1312
 	 * @param  string $context View or edit context.
1313 1313
 	 * @return bool
1314 1314
 	 */
1315
-	public function get_user_address_confirmed( $context = 'view' ) {
1316
-		return $this->get_address_confirmed( $context );
1315
+	public function get_user_address_confirmed($context = 'view') {
1316
+		return $this->get_address_confirmed($context);
1317 1317
     }
1318 1318
 
1319 1319
     /**
@@ -1323,8 +1323,8 @@  discard block
 block discarded – undo
1323 1323
 	 * @param  string $context View or edit context.
1324 1324
 	 * @return bool
1325 1325
 	 */
1326
-	public function get_customer_address_confirmed( $context = 'view' ) {
1327
-		return $this->get_address_confirmed( $context );
1326
+	public function get_customer_address_confirmed($context = 'view') {
1327
+		return $this->get_address_confirmed($context);
1328 1328
     }
1329 1329
 
1330 1330
     /**
@@ -1334,12 +1334,12 @@  discard block
 block discarded – undo
1334 1334
 	 * @param  string $context View or edit context.
1335 1335
 	 * @return float
1336 1336
 	 */
1337
-	public function get_subtotal( $context = 'view' ) {
1338
-        $subtotal = (float) $this->get_prop( 'subtotal', $context );
1337
+	public function get_subtotal($context = 'view') {
1338
+        $subtotal = (float) $this->get_prop('subtotal', $context);
1339 1339
 
1340 1340
         // Backwards compatibility.
1341
-        if ( is_bool( $context ) && $context ) {
1342
-            return wpinv_price( wpinv_format_amount( $subtotal ), $this->get_currency() );
1341
+        if (is_bool($context) && $context) {
1342
+            return wpinv_price(wpinv_format_amount($subtotal), $this->get_currency());
1343 1343
         }
1344 1344
 
1345 1345
         return $subtotal;
@@ -1352,8 +1352,8 @@  discard block
 block discarded – undo
1352 1352
 	 * @param  string $context View or edit context.
1353 1353
 	 * @return float
1354 1354
 	 */
1355
-	public function get_total_discount( $context = 'view' ) {
1356
-		return (float) $this->get_prop( 'total_discount', $context );
1355
+	public function get_total_discount($context = 'view') {
1356
+		return (float) $this->get_prop('total_discount', $context);
1357 1357
     }
1358 1358
 
1359 1359
     /**
@@ -1363,18 +1363,18 @@  discard block
 block discarded – undo
1363 1363
 	 * @param  string $context View or edit context.
1364 1364
 	 * @return float
1365 1365
 	 */
1366
-	public function get_total_tax( $context = 'view' ) {
1367
-		return (float) $this->get_prop( 'total_tax', $context );
1366
+	public function get_total_tax($context = 'view') {
1367
+		return (float) $this->get_prop('total_tax', $context);
1368 1368
 	}
1369 1369
 
1370 1370
 	/**
1371 1371
 	 * @deprecated
1372 1372
 	 */
1373
-	public function get_final_tax( $currency = false ) {
1373
+	public function get_final_tax($currency = false) {
1374 1374
 		$tax = $this->get_total_tax();
1375 1375
 
1376
-        if ( $currency ) {
1377
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1376
+        if ($currency) {
1377
+			return wpinv_price(wpinv_format_amount($tax, NULL, false), $this->get_currency());
1378 1378
         }
1379 1379
 
1380 1380
         return $tax;
@@ -1387,8 +1387,8 @@  discard block
 block discarded – undo
1387 1387
 	 * @param  string $context View or edit context.
1388 1388
 	 * @return float
1389 1389
 	 */
1390
-	public function get_total_fees( $context = 'view' ) {
1391
-		return (float) $this->get_prop( 'total_fees', $context );
1390
+	public function get_total_fees($context = 'view') {
1391
+		return (float) $this->get_prop('total_fees', $context);
1392 1392
     }
1393 1393
 
1394 1394
     /**
@@ -1398,8 +1398,8 @@  discard block
 block discarded – undo
1398 1398
 	 * @param  string $context View or edit context.
1399 1399
 	 * @return float
1400 1400
 	 */
1401
-	public function get_fees_total( $context = 'view' ) {
1402
-		return $this->get_total_fees( $context );
1401
+	public function get_fees_total($context = 'view') {
1402
+		return $this->get_total_fees($context);
1403 1403
     }
1404 1404
 
1405 1405
     /**
@@ -1410,7 +1410,7 @@  discard block
 block discarded – undo
1410 1410
 	 */
1411 1411
 	public function get_total() {
1412 1412
 		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1413
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1413
+		return apply_filters('getpaid_get_invoice_total_amount', $total, $this);
1414 1414
 	}
1415 1415
 	
1416 1416
 	/**
@@ -1432,7 +1432,7 @@  discard block
 block discarded – undo
1432 1432
 	 */
1433 1433
     public function get_initial_total() {
1434 1434
 
1435
-		if ( empty( $this->totals ) ) {
1435
+		if (empty($this->totals)) {
1436 1436
 			$this->recalculate_total();
1437 1437
 		}
1438 1438
 
@@ -1442,11 +1442,11 @@  discard block
 block discarded – undo
1442 1442
 		$subtotal = $this->totals['subtotal']['initial'];
1443 1443
 		$total    = $tax + $fee - $discount + $subtotal;
1444 1444
 
1445
-		if ( 0 > $total ) {
1445
+		if (0 > $total) {
1446 1446
 			$total = 0;
1447 1447
 		}
1448 1448
 
1449
-        return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1449
+        return apply_filters('wpinv_get_initial_invoice_total', $total, $this);
1450 1450
 	}
1451 1451
 
1452 1452
 	/**
@@ -1458,7 +1458,7 @@  discard block
 block discarded – undo
1458 1458
 	 */
1459 1459
     public function get_recurring_total() {
1460 1460
 
1461
-		if ( empty( $this->totals ) ) {
1461
+		if (empty($this->totals)) {
1462 1462
 			$this->recalculate_total();
1463 1463
 		}
1464 1464
 
@@ -1468,11 +1468,11 @@  discard block
 block discarded – undo
1468 1468
 		$subtotal = $this->totals['subtotal']['recurring'];
1469 1469
 		$total    = $tax + $fee - $discount + $subtotal;
1470 1470
 
1471
-		if ( 0 > $total ) {
1471
+		if (0 > $total) {
1472 1472
 			$total = 0;
1473 1473
 		}
1474 1474
 
1475
-        return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1475
+        return apply_filters('wpinv_get_recurring_invoice_total', $total, $this);
1476 1476
 	}
1477 1477
 
1478 1478
 	/**
@@ -1483,10 +1483,10 @@  discard block
 block discarded – undo
1483 1483
 	 * @param string $currency Whether to include the currency.
1484 1484
      * @return float
1485 1485
 	 */
1486
-    public function get_recurring_details( $field = '', $currency = false ) {
1486
+    public function get_recurring_details($field = '', $currency = false) {
1487 1487
 
1488 1488
 		// Maybe recalculate totals.
1489
-		if ( empty( $this->totals ) ) {
1489
+		if (empty($this->totals)) {
1490 1490
 			$this->recalculate_total();
1491 1491
 		}
1492 1492
 
@@ -1506,8 +1506,8 @@  discard block
 block discarded – undo
1506 1506
 			$currency
1507 1507
 		);
1508 1508
 
1509
-        if ( isset( $data[$field] ) ) {
1510
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1509
+        if (isset($data[$field])) {
1510
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1511 1511
         }
1512 1512
 
1513 1513
         return $data;
@@ -1520,8 +1520,8 @@  discard block
 block discarded – undo
1520 1520
 	 * @param  string $context View or edit context.
1521 1521
 	 * @return array
1522 1522
 	 */
1523
-	public function get_fees( $context = 'view' ) {
1524
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1523
+	public function get_fees($context = 'view') {
1524
+		return wpinv_parse_list($this->get_prop('fees', $context));
1525 1525
     }
1526 1526
 
1527 1527
     /**
@@ -1531,8 +1531,8 @@  discard block
 block discarded – undo
1531 1531
 	 * @param  string $context View or edit context.
1532 1532
 	 * @return array
1533 1533
 	 */
1534
-	public function get_discounts( $context = 'view' ) {
1535
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1534
+	public function get_discounts($context = 'view') {
1535
+		return wpinv_parse_list($this->get_prop('discounts', $context));
1536 1536
     }
1537 1537
 
1538 1538
     /**
@@ -1542,8 +1542,8 @@  discard block
 block discarded – undo
1542 1542
 	 * @param  string $context View or edit context.
1543 1543
 	 * @return array
1544 1544
 	 */
1545
-	public function get_taxes( $context = 'view' ) {
1546
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1545
+	public function get_taxes($context = 'view') {
1546
+		return wpinv_parse_list($this->get_prop('taxes', $context));
1547 1547
     }
1548 1548
 
1549 1549
     /**
@@ -1553,8 +1553,8 @@  discard block
 block discarded – undo
1553 1553
 	 * @param  string $context View or edit context.
1554 1554
 	 * @return GetPaid_Form_Item[]
1555 1555
 	 */
1556
-	public function get_items( $context = 'view' ) {
1557
-        return $this->get_prop( 'items', $context );
1556
+	public function get_items($context = 'view') {
1557
+        return $this->get_prop('items', $context);
1558 1558
     }
1559 1559
 
1560 1560
     /**
@@ -1564,8 +1564,8 @@  discard block
 block discarded – undo
1564 1564
 	 * @param  string $context View or edit context.
1565 1565
 	 * @return int
1566 1566
 	 */
1567
-	public function get_payment_form( $context = 'view' ) {
1568
-		return intval( $this->get_prop( 'payment_form', $context ) );
1567
+	public function get_payment_form($context = 'view') {
1568
+		return intval($this->get_prop('payment_form', $context));
1569 1569
     }
1570 1570
 
1571 1571
     /**
@@ -1575,8 +1575,8 @@  discard block
 block discarded – undo
1575 1575
 	 * @param  string $context View or edit context.
1576 1576
 	 * @return string
1577 1577
 	 */
1578
-	public function get_submission_id( $context = 'view' ) {
1579
-		return $this->get_prop( 'submission_id', $context );
1578
+	public function get_submission_id($context = 'view') {
1579
+		return $this->get_prop('submission_id', $context);
1580 1580
     }
1581 1581
 
1582 1582
     /**
@@ -1586,8 +1586,8 @@  discard block
 block discarded – undo
1586 1586
 	 * @param  string $context View or edit context.
1587 1587
 	 * @return string
1588 1588
 	 */
1589
-	public function get_discount_code( $context = 'view' ) {
1590
-		return $this->get_prop( 'discount_code', $context );
1589
+	public function get_discount_code($context = 'view') {
1590
+		return $this->get_prop('discount_code', $context);
1591 1591
     }
1592 1592
 
1593 1593
     /**
@@ -1597,8 +1597,8 @@  discard block
 block discarded – undo
1597 1597
 	 * @param  string $context View or edit context.
1598 1598
 	 * @return string
1599 1599
 	 */
1600
-	public function get_gateway( $context = 'view' ) {
1601
-		return $this->get_prop( 'gateway', $context );
1600
+	public function get_gateway($context = 'view') {
1601
+		return $this->get_prop('gateway', $context);
1602 1602
     }
1603 1603
 
1604 1604
     /**
@@ -1608,8 +1608,8 @@  discard block
 block discarded – undo
1608 1608
 	 * @return string
1609 1609
 	 */
1610 1610
     public function get_gateway_title() {
1611
-        $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1612
-        return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1611
+        $title = wpinv_get_gateway_checkout_label($this->get_gateway());
1612
+        return apply_filters('wpinv_gateway_title', $title, $this->get_id(), $this);
1613 1613
     }
1614 1614
 
1615 1615
     /**
@@ -1619,8 +1619,8 @@  discard block
 block discarded – undo
1619 1619
 	 * @param  string $context View or edit context.
1620 1620
 	 * @return string
1621 1621
 	 */
1622
-	public function get_transaction_id( $context = 'view' ) {
1623
-		return $this->get_prop( 'transaction_id', $context );
1622
+	public function get_transaction_id($context = 'view') {
1623
+		return $this->get_prop('transaction_id', $context);
1624 1624
     }
1625 1625
 
1626 1626
     /**
@@ -1630,9 +1630,9 @@  discard block
 block discarded – undo
1630 1630
 	 * @param  string $context View or edit context.
1631 1631
 	 * @return string
1632 1632
 	 */
1633
-	public function get_currency( $context = 'view' ) {
1634
-        $currency = $this->get_prop( 'currency', $context );
1635
-        return empty( $currency ) ? wpinv_get_currency() : $currency;
1633
+	public function get_currency($context = 'view') {
1634
+        $currency = $this->get_prop('currency', $context);
1635
+        return empty($currency) ? wpinv_get_currency() : $currency;
1636 1636
     }
1637 1637
 
1638 1638
     /**
@@ -1642,8 +1642,8 @@  discard block
 block discarded – undo
1642 1642
 	 * @param  string $context View or edit context.
1643 1643
 	 * @return bool
1644 1644
 	 */
1645
-	public function get_disable_taxes( $context = 'view' ) {
1646
-        return (bool) $this->get_prop( 'disable_taxes', $context );
1645
+	public function get_disable_taxes($context = 'view') {
1646
+        return (bool) $this->get_prop('disable_taxes', $context);
1647 1647
     }
1648 1648
 
1649 1649
     /**
@@ -1653,8 +1653,8 @@  discard block
 block discarded – undo
1653 1653
 	 * @param  string $context View or edit context.
1654 1654
 	 * @return int
1655 1655
 	 */
1656
-    public function get_subscription_id( $context = 'view' ) {
1657
-		return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1656
+    public function get_subscription_id($context = 'view') {
1657
+		return $this->is_renewal() ? $this->get_parent()->get_subscription_id($context) : $this->get_prop('subscription_id', $context);
1658 1658
 	}
1659 1659
 
1660 1660
 	/**
@@ -1664,12 +1664,12 @@  discard block
 block discarded – undo
1664 1664
 	 * @param  string $context View or edit context.
1665 1665
 	 * @return int
1666 1666
 	 */
1667
-    public function get_remote_subscription_id( $context = 'view' ) {
1668
-        $subscription_id = $this->get_prop( 'remote_subscription_id', $context );
1667
+    public function get_remote_subscription_id($context = 'view') {
1668
+        $subscription_id = $this->get_prop('remote_subscription_id', $context);
1669 1669
 
1670
-        if ( empty( $subscription_id ) && $this->is_renewal() ) {
1670
+        if (empty($subscription_id) && $this->is_renewal()) {
1671 1671
             $parent = $this->get_parent();
1672
-            return $parent->get_subscription_id( $context );
1672
+            return $parent->get_subscription_id($context);
1673 1673
         }
1674 1674
 
1675 1675
         return $subscription_id;
@@ -1682,20 +1682,20 @@  discard block
 block discarded – undo
1682 1682
 	 * @param  string $context View or edit context.
1683 1683
 	 * @return array
1684 1684
 	 */
1685
-    public function get_payment_meta( $context = 'view' ) {
1685
+    public function get_payment_meta($context = 'view') {
1686 1686
 
1687 1687
         return array(
1688
-            'price'        => $this->get_total( $context ),
1689
-            'date'         => $this->get_date_created( $context ),
1690
-            'user_email'   => $this->get_email( $context ),
1691
-            'invoice_key'  => $this->get_key( $context ),
1692
-            'currency'     => $this->get_currency( $context ),
1693
-            'items'        => $this->get_items( $context ),
1694
-            'user_info'    => $this->get_user_info( $context ),
1688
+            'price'        => $this->get_total($context),
1689
+            'date'         => $this->get_date_created($context),
1690
+            'user_email'   => $this->get_email($context),
1691
+            'invoice_key'  => $this->get_key($context),
1692
+            'currency'     => $this->get_currency($context),
1693
+            'items'        => $this->get_items($context),
1694
+            'user_info'    => $this->get_user_info($context),
1695 1695
             'cart_details' => $this->get_cart_details(),
1696
-            'status'       => $this->get_status( $context ),
1697
-            'fees'         => $this->get_fees( $context ),
1698
-            'taxes'        => $this->get_taxes( $context ),
1696
+            'status'       => $this->get_status($context),
1697
+            'fees'         => $this->get_fees($context),
1698
+            'taxes'        => $this->get_taxes($context),
1699 1699
         );
1700 1700
 
1701 1701
     }
@@ -1710,9 +1710,9 @@  discard block
 block discarded – undo
1710 1710
         $items        = $this->get_items();
1711 1711
         $cart_details = array();
1712 1712
 
1713
-        foreach ( $items as $item_id => $item ) {
1713
+        foreach ($items as $item_id => $item) {
1714 1714
 			$item->invoice_id = $this->get_id();
1715
-            $cart_details[]   = $item->prepare_data_for_saving();
1715
+            $cart_details[] = $item->prepare_data_for_saving();
1716 1716
         }
1717 1717
 
1718 1718
         return $cart_details;
@@ -1723,11 +1723,11 @@  discard block
 block discarded – undo
1723 1723
 	 *
1724 1724
 	 * @return null|GetPaid_Form_Item|int
1725 1725
 	 */
1726
-	public function get_recurring( $object = false ) {
1726
+	public function get_recurring($object = false) {
1727 1727
 
1728 1728
 		// Are we returning an object?
1729
-        if ( $object ) {
1730
-            return $this->get_item( $this->recurring_item );
1729
+        if ($object) {
1730
+            return $this->get_item($this->recurring_item);
1731 1731
         }
1732 1732
 
1733 1733
         return $this->recurring_item;
@@ -1742,15 +1742,15 @@  discard block
 block discarded – undo
1742 1742
 	public function get_subscription_name() {
1743 1743
 
1744 1744
 		// Retrieve the recurring name
1745
-        $item = $this->get_recurring( true );
1745
+        $item = $this->get_recurring(true);
1746 1746
 
1747 1747
 		// Abort if it does not exist.
1748
-        if ( empty( $item ) ) {
1748
+        if (empty($item)) {
1749 1749
             return '';
1750 1750
         }
1751 1751
 
1752 1752
 		// Return the item name.
1753
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1753
+        return apply_filters('wpinv_invoice_get_subscription_name', $item->get_name(), $this);
1754 1754
 	}
1755 1755
 
1756 1756
 	/**
@@ -1760,9 +1760,9 @@  discard block
 block discarded – undo
1760 1760
 	 * @return string
1761 1761
 	 */
1762 1762
 	public function get_view_url() {
1763
-        $invoice_url = get_permalink( $this->get_id() );
1764
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1765
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1763
+        $invoice_url = get_permalink($this->get_id());
1764
+		$invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
1765
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this);
1766 1766
 	}
1767 1767
 
1768 1768
 	/**
@@ -1771,25 +1771,25 @@  discard block
 block discarded – undo
1771 1771
 	 * @since 1.0.19
1772 1772
 	 * @return string
1773 1773
 	 */
1774
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1774
+	public function get_checkout_payment_url($deprecated = false, $secret = false) {
1775 1775
 
1776 1776
 		// Retrieve the checkout url.
1777 1777
         $pay_url = wpinv_get_checkout_uri();
1778 1778
 
1779 1779
 		// Maybe force ssl.
1780
-        if ( is_ssl() ) {
1781
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
1780
+        if (is_ssl()) {
1781
+            $pay_url = str_replace('http:', 'https:', $pay_url);
1782 1782
         }
1783 1783
 
1784 1784
 		// Add the invoice key.
1785
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1785
+		$pay_url = add_query_arg('invoice_key', $this->get_key(), $pay_url);
1786 1786
 
1787 1787
 		// (Maybe?) add a secret
1788
-        if ( $secret ) {
1789
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1788
+        if ($secret) {
1789
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key())), $pay_url);
1790 1790
         }
1791 1791
 
1792
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1792
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret);
1793 1793
 	}
1794 1794
 	
1795 1795
 	/**
@@ -1804,14 +1804,14 @@  discard block
 block discarded – undo
1804 1804
         $receipt_url = wpinv_get_success_page_uri();
1805 1805
 
1806 1806
 		// Maybe force ssl.
1807
-        if ( is_ssl() ) {
1808
-            $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1807
+        if (is_ssl()) {
1808
+            $receipt_url = str_replace('http:', 'https:', $receipt_url);
1809 1809
         }
1810 1810
 
1811 1811
 		// Add the invoice key.
1812
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1812
+		$receipt_url = add_query_arg('invoice_key', $this->get_key(), $receipt_url);
1813 1813
 
1814
-        return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1814
+        return apply_filters('getpaid_get_invoice_receipt_url', $receipt_url, $this);
1815 1815
     }
1816 1816
 
1817 1817
     /**
@@ -1824,8 +1824,8 @@  discard block
 block discarded – undo
1824 1824
 	 * @param  string $context View or edit context.
1825 1825
 	 * @return mixed Value of the given invoice property (if set).
1826 1826
 	 */
1827
-	public function get( $key, $context = 'view' ) {
1828
-        return $this->get_prop( $key, $context );
1827
+	public function get($key, $context = 'view') {
1828
+        return $this->get_prop($key, $context);
1829 1829
 	}
1830 1830
 
1831 1831
     /*
@@ -1848,11 +1848,11 @@  discard block
 block discarded – undo
1848 1848
 	 * @param  mixed $value new value.
1849 1849
 	 * @return mixed Value of the given invoice property (if set).
1850 1850
 	 */
1851
-	public function set( $key, $value ) {
1851
+	public function set($key, $value) {
1852 1852
 
1853 1853
         $setter = "set_$key";
1854
-        if ( is_callable( array( $this, $setter ) ) ) {
1855
-            $this->{$setter}( $value );
1854
+        if (is_callable(array($this, $setter))) {
1855
+            $this->{$setter}($value);
1856 1856
         }
1857 1857
 
1858 1858
 	}
@@ -1866,47 +1866,47 @@  discard block
 block discarded – undo
1866 1866
 	 * @param bool   $manual_update Is this a manual status change?.
1867 1867
 	 * @return array details of change.
1868 1868
 	 */
1869
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1869
+	public function set_status($new_status, $note = '', $manual_update = false) {
1870 1870
 		$old_status = $this->get_status();
1871 1871
 
1872 1872
 		$statuses = $this->get_all_statuses();
1873 1873
 
1874
-		if ( isset( $statuses[ 'draft' ] ) ) {
1875
-			unset( $statuses[ 'draft' ] );
1874
+		if (isset($statuses['draft'])) {
1875
+			unset($statuses['draft']);
1876 1876
 		}
1877 1877
 
1878
-		$this->set_prop( 'status', $new_status );
1878
+		$this->set_prop('status', $new_status);
1879 1879
 
1880 1880
 		// If setting the status, ensure it's set to a valid status.
1881
-		if ( true === $this->object_read ) {
1881
+		if (true === $this->object_read) {
1882 1882
 
1883 1883
 			// Only allow valid new status.
1884
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1884
+			if (!array_key_exists($new_status, $statuses)) {
1885 1885
 				$new_status = 'wpi-pending';
1886 1886
 			}
1887 1887
 
1888 1888
 			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1889
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1889
+			if ($old_status && !array_key_exists($new_status, $statuses)) {
1890 1890
 				$old_status = 'wpi-pending';
1891 1891
 			}
1892 1892
 
1893 1893
 			// Paid - Renewal (i.e when duplicating a parent invoice )
1894
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1894
+			if ($new_status == 'wpi-pending' && $old_status == 'publish' && !$this->get_id()) {
1895 1895
 				$old_status = 'wpi-pending';
1896 1896
 			}
1897 1897
 
1898 1898
 		}
1899 1899
 
1900
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1900
+		if (true === $this->object_read && $old_status !== $new_status) {
1901 1901
 			$this->status_transition = array(
1902
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1902
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
1903 1903
 				'to'     => $new_status,
1904 1904
 				'note'   => $note,
1905 1905
 				'manual' => (bool) $manual_update,
1906 1906
 			);
1907 1907
 
1908
-			if ( $manual_update ) {
1909
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1908
+			if ($manual_update) {
1909
+				do_action('getpaid_' . $this->object_type . '_edit_status', $this->get_id(), $new_status);
1910 1910
 			}
1911 1911
 
1912 1912
 			$this->maybe_set_date_paid();
@@ -1929,8 +1929,8 @@  discard block
 block discarded – undo
1929 1929
 	 */
1930 1930
 	public function maybe_set_date_paid() {
1931 1931
 
1932
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1933
-			$this->set_date_completed( current_time( 'mysql' ) );
1932
+		if (!$this->get_date_completed('edit') && $this->is_paid()) {
1933
+			$this->set_date_completed(current_time('mysql'));
1934 1934
 		}
1935 1935
 	}
1936 1936
 
@@ -1939,11 +1939,11 @@  discard block
 block discarded – undo
1939 1939
 	 *
1940 1940
 	 * @since 1.0.19
1941 1941
 	 */
1942
-	public function set_parent_id( $value ) {
1943
-		if ( $value && ( $value === $this->get_id() ) ) {
1942
+	public function set_parent_id($value) {
1943
+		if ($value && ($value === $this->get_id())) {
1944 1944
 			return;
1945 1945
 		}
1946
-		$this->set_prop( 'parent_id', absint( $value ) );
1946
+		$this->set_prop('parent_id', absint($value));
1947 1947
     }
1948 1948
 
1949 1949
     /**
@@ -1951,8 +1951,8 @@  discard block
 block discarded – undo
1951 1951
 	 *
1952 1952
 	 * @since 1.0.19
1953 1953
 	 */
1954
-	public function set_version( $value ) {
1955
-		$this->set_prop( 'version', $value );
1954
+	public function set_version($value) {
1955
+		$this->set_prop('version', $value);
1956 1956
     }
1957 1957
 
1958 1958
     /**
@@ -1962,15 +1962,15 @@  discard block
 block discarded – undo
1962 1962
 	 * @param string $value Value to set.
1963 1963
      * @return bool Whether or not the date was set.
1964 1964
 	 */
1965
-	public function set_date_created( $value ) {
1966
-        $date = strtotime( $value );
1965
+	public function set_date_created($value) {
1966
+        $date = strtotime($value);
1967 1967
 
1968
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
1969
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
1968
+        if ($date && $value !== '0000-00-00 00:00:00') {
1969
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
1970 1970
             return true;
1971 1971
         }
1972 1972
 
1973
-        return $this->set_prop( 'date_created', '' );
1973
+        return $this->set_prop('date_created', '');
1974 1974
 
1975 1975
     }
1976 1976
 
@@ -1981,15 +1981,15 @@  discard block
 block discarded – undo
1981 1981
 	 * @param string $value Value to set.
1982 1982
      * @return bool Whether or not the date was set.
1983 1983
 	 */
1984
-	public function set_due_date( $value ) {
1985
-        $date = strtotime( $value );
1984
+	public function set_due_date($value) {
1985
+        $date = strtotime($value);
1986 1986
 
1987
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
1988
-            $this->set_prop( 'due_date', date( 'Y-m-d H:i:s', $date ) );
1987
+        if ($date && $value !== '0000-00-00 00:00:00') {
1988
+            $this->set_prop('due_date', date('Y-m-d H:i:s', $date));
1989 1989
             return true;
1990 1990
         }
1991 1991
 
1992
-		$this->set_prop( 'due_date', '' );
1992
+		$this->set_prop('due_date', '');
1993 1993
         return false;
1994 1994
 
1995 1995
     }
@@ -2000,8 +2000,8 @@  discard block
 block discarded – undo
2000 2000
 	 * @since 1.0.19
2001 2001
 	 * @param  string $value New name.
2002 2002
 	 */
2003
-	public function set_date_due( $value ) {
2004
-		$this->set_due_date( $value );
2003
+	public function set_date_due($value) {
2004
+		$this->set_due_date($value);
2005 2005
     }
2006 2006
 
2007 2007
     /**
@@ -2011,15 +2011,15 @@  discard block
 block discarded – undo
2011 2011
 	 * @param string $value Value to set.
2012 2012
      * @return bool Whether or not the date was set.
2013 2013
 	 */
2014
-	public function set_completed_date( $value ) {
2015
-        $date = strtotime( $value );
2014
+	public function set_completed_date($value) {
2015
+        $date = strtotime($value);
2016 2016
 
2017
-        if ( $date && $value !== '0000-00-00 00:00:00'  ) {
2018
-            $this->set_prop( 'completed_date', date( 'Y-m-d H:i:s', $date ) );
2017
+        if ($date && $value !== '0000-00-00 00:00:00') {
2018
+            $this->set_prop('completed_date', date('Y-m-d H:i:s', $date));
2019 2019
             return true;
2020 2020
         }
2021 2021
 
2022
-		$this->set_prop( 'completed_date', '' );
2022
+		$this->set_prop('completed_date', '');
2023 2023
         return false;
2024 2024
 
2025 2025
     }
@@ -2030,8 +2030,8 @@  discard block
 block discarded – undo
2030 2030
 	 * @since 1.0.19
2031 2031
 	 * @param  string $value New name.
2032 2032
 	 */
2033
-	public function set_date_completed( $value ) {
2034
-		$this->set_completed_date( $value );
2033
+	public function set_date_completed($value) {
2034
+		$this->set_completed_date($value);
2035 2035
     }
2036 2036
 
2037 2037
     /**
@@ -2041,15 +2041,15 @@  discard block
 block discarded – undo
2041 2041
 	 * @param string $value Value to set.
2042 2042
      * @return bool Whether or not the date was set.
2043 2043
 	 */
2044
-	public function set_date_modified( $value ) {
2045
-        $date = strtotime( $value );
2044
+	public function set_date_modified($value) {
2045
+        $date = strtotime($value);
2046 2046
 
2047
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
2048
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
2047
+        if ($date && $value !== '0000-00-00 00:00:00') {
2048
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
2049 2049
             return true;
2050 2050
         }
2051 2051
 
2052
-		$this->set_prop( 'date_modified', '' );
2052
+		$this->set_prop('date_modified', '');
2053 2053
         return false;
2054 2054
 
2055 2055
     }
@@ -2060,9 +2060,9 @@  discard block
 block discarded – undo
2060 2060
 	 * @since 1.0.19
2061 2061
 	 * @param  string $value New number.
2062 2062
 	 */
2063
-	public function set_number( $value ) {
2064
-        $number = sanitize_text_field( $value );
2065
-		$this->set_prop( 'number', $number );
2063
+	public function set_number($value) {
2064
+        $number = sanitize_text_field($value);
2065
+		$this->set_prop('number', $number);
2066 2066
     }
2067 2067
 
2068 2068
     /**
@@ -2071,9 +2071,9 @@  discard block
 block discarded – undo
2071 2071
 	 * @since 1.0.19
2072 2072
 	 * @param  string $value Type.
2073 2073
 	 */
2074
-	public function set_type( $value ) {
2075
-        $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2076
-		$this->set_prop( 'type', $type );
2074
+	public function set_type($value) {
2075
+        $type = sanitize_text_field(str_replace('wpi_', '', $value));
2076
+		$this->set_prop('type', $type);
2077 2077
 	}
2078 2078
 
2079 2079
     /**
@@ -2082,10 +2082,10 @@  discard block
 block discarded – undo
2082 2082
 	 * @since 1.0.19
2083 2083
 	 * @param  string $value Post type.
2084 2084
 	 */
2085
-	public function set_post_type( $value ) {
2086
-        if ( getpaid_is_invoice_post_type( $value ) ) {
2087
-			$this->set_type( $value );
2088
-            $this->set_prop( 'post_type', $value );
2085
+	public function set_post_type($value) {
2086
+        if (getpaid_is_invoice_post_type($value)) {
2087
+			$this->set_type($value);
2088
+            $this->set_prop('post_type', $value);
2089 2089
         }
2090 2090
     }
2091 2091
 
@@ -2095,9 +2095,9 @@  discard block
 block discarded – undo
2095 2095
 	 * @since 1.0.19
2096 2096
 	 * @param  string $value New key.
2097 2097
 	 */
2098
-	public function set_key( $value ) {
2099
-        $key = sanitize_text_field( $value );
2100
-		$this->set_prop( 'key', $key );
2098
+	public function set_key($value) {
2099
+        $key = sanitize_text_field($value);
2100
+		$this->set_prop('key', $key);
2101 2101
     }
2102 2102
 
2103 2103
     /**
@@ -2106,9 +2106,9 @@  discard block
 block discarded – undo
2106 2106
 	 * @since 1.0.19
2107 2107
 	 * @param  string $value mode.
2108 2108
 	 */
2109
-	public function set_mode( $value ) {
2110
-        if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2111
-            $this->set_prop( 'value', $value );
2109
+	public function set_mode($value) {
2110
+        if (!in_array($value, array('live', 'test'))) {
2111
+            $this->set_prop('value', $value);
2112 2112
         }
2113 2113
     }
2114 2114
 
@@ -2118,8 +2118,8 @@  discard block
 block discarded – undo
2118 2118
 	 * @since 1.0.19
2119 2119
 	 * @param  string $value path.
2120 2120
 	 */
2121
-	public function set_path( $value ) {
2122
-        $this->set_prop( 'path', $value );
2121
+	public function set_path($value) {
2122
+        $this->set_prop('path', $value);
2123 2123
     }
2124 2124
 
2125 2125
     /**
@@ -2128,9 +2128,9 @@  discard block
 block discarded – undo
2128 2128
 	 * @since 1.0.19
2129 2129
 	 * @param  string $value New name.
2130 2130
 	 */
2131
-	public function set_name( $value ) {
2132
-        $name = sanitize_text_field( $value );
2133
-		$this->set_prop( 'name', $name );
2131
+	public function set_name($value) {
2132
+        $name = sanitize_text_field($value);
2133
+		$this->set_prop('name', $name);
2134 2134
     }
2135 2135
 
2136 2136
     /**
@@ -2139,8 +2139,8 @@  discard block
 block discarded – undo
2139 2139
 	 * @since 1.0.19
2140 2140
 	 * @param  string $value New name.
2141 2141
 	 */
2142
-	public function set_title( $value ) {
2143
-		$this->set_name( $value );
2142
+	public function set_title($value) {
2143
+		$this->set_name($value);
2144 2144
     }
2145 2145
 
2146 2146
     /**
@@ -2149,9 +2149,9 @@  discard block
 block discarded – undo
2149 2149
 	 * @since 1.0.19
2150 2150
 	 * @param  string $value New description.
2151 2151
 	 */
2152
-	public function set_description( $value ) {
2153
-        $description = wp_kses_post( $value );
2154
-		return $this->set_prop( 'description', $description );
2152
+	public function set_description($value) {
2153
+        $description = wp_kses_post($value);
2154
+		return $this->set_prop('description', $description);
2155 2155
     }
2156 2156
 
2157 2157
     /**
@@ -2160,8 +2160,8 @@  discard block
 block discarded – undo
2160 2160
 	 * @since 1.0.19
2161 2161
 	 * @param  string $value New description.
2162 2162
 	 */
2163
-	public function set_excerpt( $value ) {
2164
-		$this->set_description( $value );
2163
+	public function set_excerpt($value) {
2164
+		$this->set_description($value);
2165 2165
     }
2166 2166
 
2167 2167
     /**
@@ -2170,8 +2170,8 @@  discard block
 block discarded – undo
2170 2170
 	 * @since 1.0.19
2171 2171
 	 * @param  string $value New description.
2172 2172
 	 */
2173
-	public function set_summary( $value ) {
2174
-		$this->set_description( $value );
2173
+	public function set_summary($value) {
2174
+		$this->set_description($value);
2175 2175
     }
2176 2176
 
2177 2177
     /**
@@ -2180,12 +2180,12 @@  discard block
 block discarded – undo
2180 2180
 	 * @since 1.0.19
2181 2181
 	 * @param  int $value New author.
2182 2182
 	 */
2183
-	public function set_author( $value ) {
2184
-		$user = get_user_by( 'id', (int) $value );
2183
+	public function set_author($value) {
2184
+		$user = get_user_by('id', (int) $value);
2185 2185
 
2186
-		if ( $user && $user->ID ) {
2187
-			$this->set_prop( 'author', $user->ID );
2188
-			$this->set_prop( 'email', $user->user_email );
2186
+		if ($user && $user->ID) {
2187
+			$this->set_prop('author', $user->ID);
2188
+			$this->set_prop('email', $user->user_email);
2189 2189
 		}
2190 2190
 		
2191 2191
     }
@@ -2196,8 +2196,8 @@  discard block
 block discarded – undo
2196 2196
 	 * @since 1.0.19
2197 2197
 	 * @param  int $value New user id.
2198 2198
 	 */
2199
-	public function set_user_id( $value ) {
2200
-		$this->set_author( $value );
2199
+	public function set_user_id($value) {
2200
+		$this->set_author($value);
2201 2201
     }
2202 2202
 
2203 2203
     /**
@@ -2206,8 +2206,8 @@  discard block
 block discarded – undo
2206 2206
 	 * @since 1.0.19
2207 2207
 	 * @param  int $value New user id.
2208 2208
 	 */
2209
-	public function set_customer_id( $value ) {
2210
-		$this->set_author( $value );
2209
+	public function set_customer_id($value) {
2210
+		$this->set_author($value);
2211 2211
     }
2212 2212
 
2213 2213
     /**
@@ -2216,8 +2216,8 @@  discard block
 block discarded – undo
2216 2216
 	 * @since 1.0.19
2217 2217
 	 * @param  string $value ip address.
2218 2218
 	 */
2219
-	public function set_ip( $value ) {
2220
-		$this->set_prop( 'ip', $value );
2219
+	public function set_ip($value) {
2220
+		$this->set_prop('ip', $value);
2221 2221
     }
2222 2222
 
2223 2223
     /**
@@ -2226,8 +2226,8 @@  discard block
 block discarded – undo
2226 2226
 	 * @since 1.0.19
2227 2227
 	 * @param  string $value ip address.
2228 2228
 	 */
2229
-	public function set_user_ip( $value ) {
2230
-		$this->set_ip( $value );
2229
+	public function set_user_ip($value) {
2230
+		$this->set_ip($value);
2231 2231
     }
2232 2232
 
2233 2233
     /**
@@ -2236,8 +2236,8 @@  discard block
 block discarded – undo
2236 2236
 	 * @since 1.0.19
2237 2237
 	 * @param  string $value first name.
2238 2238
 	 */
2239
-	public function set_first_name( $value ) {
2240
-		$this->set_prop( 'first_name', $value );
2239
+	public function set_first_name($value) {
2240
+		$this->set_prop('first_name', $value);
2241 2241
     }
2242 2242
 
2243 2243
     /**
@@ -2246,8 +2246,8 @@  discard block
 block discarded – undo
2246 2246
 	 * @since 1.0.19
2247 2247
 	 * @param  string $value first name.
2248 2248
 	 */
2249
-	public function set_user_first_name( $value ) {
2250
-		$this->set_first_name( $value );
2249
+	public function set_user_first_name($value) {
2250
+		$this->set_first_name($value);
2251 2251
     }
2252 2252
 
2253 2253
     /**
@@ -2256,8 +2256,8 @@  discard block
 block discarded – undo
2256 2256
 	 * @since 1.0.19
2257 2257
 	 * @param  string $value first name.
2258 2258
 	 */
2259
-	public function set_customer_first_name( $value ) {
2260
-		$this->set_first_name( $value );
2259
+	public function set_customer_first_name($value) {
2260
+		$this->set_first_name($value);
2261 2261
     }
2262 2262
 
2263 2263
     /**
@@ -2266,8 +2266,8 @@  discard block
 block discarded – undo
2266 2266
 	 * @since 1.0.19
2267 2267
 	 * @param  string $value last name.
2268 2268
 	 */
2269
-	public function set_last_name( $value ) {
2270
-		$this->set_prop( 'last_name', $value );
2269
+	public function set_last_name($value) {
2270
+		$this->set_prop('last_name', $value);
2271 2271
     }
2272 2272
 
2273 2273
     /**
@@ -2276,8 +2276,8 @@  discard block
 block discarded – undo
2276 2276
 	 * @since 1.0.19
2277 2277
 	 * @param  string $value last name.
2278 2278
 	 */
2279
-	public function set_user_last_name( $value ) {
2280
-		$this->set_last_name( $value );
2279
+	public function set_user_last_name($value) {
2280
+		$this->set_last_name($value);
2281 2281
     }
2282 2282
 
2283 2283
     /**
@@ -2286,8 +2286,8 @@  discard block
 block discarded – undo
2286 2286
 	 * @since 1.0.19
2287 2287
 	 * @param  string $value last name.
2288 2288
 	 */
2289
-	public function set_customer_last_name( $value ) {
2290
-		$this->set_last_name( $value );
2289
+	public function set_customer_last_name($value) {
2290
+		$this->set_last_name($value);
2291 2291
     }
2292 2292
 
2293 2293
     /**
@@ -2296,8 +2296,8 @@  discard block
 block discarded – undo
2296 2296
 	 * @since 1.0.19
2297 2297
 	 * @param  string $value phone.
2298 2298
 	 */
2299
-	public function set_phone( $value ) {
2300
-		$this->set_prop( 'phone', $value );
2299
+	public function set_phone($value) {
2300
+		$this->set_prop('phone', $value);
2301 2301
     }
2302 2302
 
2303 2303
     /**
@@ -2306,8 +2306,8 @@  discard block
 block discarded – undo
2306 2306
 	 * @since 1.0.19
2307 2307
 	 * @param  string $value phone.
2308 2308
 	 */
2309
-	public function set_user_phone( $value ) {
2310
-		$this->set_phone( $value );
2309
+	public function set_user_phone($value) {
2310
+		$this->set_phone($value);
2311 2311
     }
2312 2312
 
2313 2313
     /**
@@ -2316,8 +2316,8 @@  discard block
 block discarded – undo
2316 2316
 	 * @since 1.0.19
2317 2317
 	 * @param  string $value phone.
2318 2318
 	 */
2319
-	public function set_customer_phone( $value ) {
2320
-		$this->set_phone( $value );
2319
+	public function set_customer_phone($value) {
2320
+		$this->set_phone($value);
2321 2321
     }
2322 2322
 
2323 2323
     /**
@@ -2326,8 +2326,8 @@  discard block
 block discarded – undo
2326 2326
 	 * @since 1.0.19
2327 2327
 	 * @param  string $value phone.
2328 2328
 	 */
2329
-	public function set_phone_number( $value ) {
2330
-		$this->set_phone( $value );
2329
+	public function set_phone_number($value) {
2330
+		$this->set_phone($value);
2331 2331
     }
2332 2332
 
2333 2333
     /**
@@ -2336,8 +2336,8 @@  discard block
 block discarded – undo
2336 2336
 	 * @since 1.0.19
2337 2337
 	 * @param  string $value email address.
2338 2338
 	 */
2339
-	public function set_email( $value ) {
2340
-		$this->set_prop( 'email', $value );
2339
+	public function set_email($value) {
2340
+		$this->set_prop('email', $value);
2341 2341
     }
2342 2342
 
2343 2343
     /**
@@ -2346,8 +2346,8 @@  discard block
 block discarded – undo
2346 2346
 	 * @since 1.0.19
2347 2347
 	 * @param  string $value email address.
2348 2348
 	 */
2349
-	public function set_user_email( $value ) {
2350
-		$this->set_email( $value );
2349
+	public function set_user_email($value) {
2350
+		$this->set_email($value);
2351 2351
     }
2352 2352
 
2353 2353
     /**
@@ -2356,8 +2356,8 @@  discard block
 block discarded – undo
2356 2356
 	 * @since 1.0.19
2357 2357
 	 * @param  string $value email address.
2358 2358
 	 */
2359
-	public function set_email_address( $value ) {
2360
-		$this->set_email( $value );
2359
+	public function set_email_address($value) {
2360
+		$this->set_email($value);
2361 2361
     }
2362 2362
 
2363 2363
     /**
@@ -2366,8 +2366,8 @@  discard block
 block discarded – undo
2366 2366
 	 * @since 1.0.19
2367 2367
 	 * @param  string $value email address.
2368 2368
 	 */
2369
-	public function set_customer_email( $value ) {
2370
-		$this->set_email( $value );
2369
+	public function set_customer_email($value) {
2370
+		$this->set_email($value);
2371 2371
     }
2372 2372
 
2373 2373
     /**
@@ -2376,8 +2376,8 @@  discard block
 block discarded – undo
2376 2376
 	 * @since 1.0.19
2377 2377
 	 * @param  string $value country.
2378 2378
 	 */
2379
-	public function set_country( $value ) {
2380
-		$this->set_prop( 'country', $value );
2379
+	public function set_country($value) {
2380
+		$this->set_prop('country', $value);
2381 2381
     }
2382 2382
 
2383 2383
     /**
@@ -2386,8 +2386,8 @@  discard block
 block discarded – undo
2386 2386
 	 * @since 1.0.19
2387 2387
 	 * @param  string $value country.
2388 2388
 	 */
2389
-	public function set_user_country( $value ) {
2390
-		$this->set_country( $value );
2389
+	public function set_user_country($value) {
2390
+		$this->set_country($value);
2391 2391
     }
2392 2392
 
2393 2393
     /**
@@ -2396,8 +2396,8 @@  discard block
 block discarded – undo
2396 2396
 	 * @since 1.0.19
2397 2397
 	 * @param  string $value country.
2398 2398
 	 */
2399
-	public function set_customer_country( $value ) {
2400
-		$this->set_country( $value );
2399
+	public function set_customer_country($value) {
2400
+		$this->set_country($value);
2401 2401
     }
2402 2402
 
2403 2403
     /**
@@ -2406,8 +2406,8 @@  discard block
 block discarded – undo
2406 2406
 	 * @since 1.0.19
2407 2407
 	 * @param  string $value state.
2408 2408
 	 */
2409
-	public function set_state( $value ) {
2410
-		$this->set_prop( 'state', $value );
2409
+	public function set_state($value) {
2410
+		$this->set_prop('state', $value);
2411 2411
     }
2412 2412
 
2413 2413
     /**
@@ -2416,8 +2416,8 @@  discard block
 block discarded – undo
2416 2416
 	 * @since 1.0.19
2417 2417
 	 * @param  string $value state.
2418 2418
 	 */
2419
-	public function set_user_state( $value ) {
2420
-		$this->set_state( $value );
2419
+	public function set_user_state($value) {
2420
+		$this->set_state($value);
2421 2421
     }
2422 2422
 
2423 2423
     /**
@@ -2426,8 +2426,8 @@  discard block
 block discarded – undo
2426 2426
 	 * @since 1.0.19
2427 2427
 	 * @param  string $value state.
2428 2428
 	 */
2429
-	public function set_customer_state( $value ) {
2430
-		$this->set_state( $value );
2429
+	public function set_customer_state($value) {
2430
+		$this->set_state($value);
2431 2431
     }
2432 2432
 
2433 2433
     /**
@@ -2436,8 +2436,8 @@  discard block
 block discarded – undo
2436 2436
 	 * @since 1.0.19
2437 2437
 	 * @param  string $value city.
2438 2438
 	 */
2439
-	public function set_city( $value ) {
2440
-		$this->set_prop( 'city', $value );
2439
+	public function set_city($value) {
2440
+		$this->set_prop('city', $value);
2441 2441
     }
2442 2442
 
2443 2443
     /**
@@ -2446,8 +2446,8 @@  discard block
 block discarded – undo
2446 2446
 	 * @since 1.0.19
2447 2447
 	 * @param  string $value city.
2448 2448
 	 */
2449
-	public function set_user_city( $value ) {
2450
-		$this->set_city( $value );
2449
+	public function set_user_city($value) {
2450
+		$this->set_city($value);
2451 2451
     }
2452 2452
 
2453 2453
     /**
@@ -2456,8 +2456,8 @@  discard block
 block discarded – undo
2456 2456
 	 * @since 1.0.19
2457 2457
 	 * @param  string $value city.
2458 2458
 	 */
2459
-	public function set_customer_city( $value ) {
2460
-		$this->set_city( $value );
2459
+	public function set_customer_city($value) {
2460
+		$this->set_city($value);
2461 2461
     }
2462 2462
 
2463 2463
     /**
@@ -2466,8 +2466,8 @@  discard block
 block discarded – undo
2466 2466
 	 * @since 1.0.19
2467 2467
 	 * @param  string $value zip.
2468 2468
 	 */
2469
-	public function set_zip( $value ) {
2470
-		$this->set_prop( 'zip', $value );
2469
+	public function set_zip($value) {
2470
+		$this->set_prop('zip', $value);
2471 2471
     }
2472 2472
 
2473 2473
     /**
@@ -2476,8 +2476,8 @@  discard block
 block discarded – undo
2476 2476
 	 * @since 1.0.19
2477 2477
 	 * @param  string $value zip.
2478 2478
 	 */
2479
-	public function set_user_zip( $value ) {
2480
-		$this->set_zip( $value );
2479
+	public function set_user_zip($value) {
2480
+		$this->set_zip($value);
2481 2481
     }
2482 2482
 
2483 2483
     /**
@@ -2486,8 +2486,8 @@  discard block
 block discarded – undo
2486 2486
 	 * @since 1.0.19
2487 2487
 	 * @param  string $value zip.
2488 2488
 	 */
2489
-	public function set_customer_zip( $value ) {
2490
-		$this->set_zip( $value );
2489
+	public function set_customer_zip($value) {
2490
+		$this->set_zip($value);
2491 2491
     }
2492 2492
 
2493 2493
     /**
@@ -2496,8 +2496,8 @@  discard block
 block discarded – undo
2496 2496
 	 * @since 1.0.19
2497 2497
 	 * @param  string $value company.
2498 2498
 	 */
2499
-	public function set_company( $value ) {
2500
-		$this->set_prop( 'company', $value );
2499
+	public function set_company($value) {
2500
+		$this->set_prop('company', $value);
2501 2501
     }
2502 2502
 
2503 2503
     /**
@@ -2506,8 +2506,8 @@  discard block
 block discarded – undo
2506 2506
 	 * @since 1.0.19
2507 2507
 	 * @param  string $value company.
2508 2508
 	 */
2509
-	public function set_user_company( $value ) {
2510
-		$this->set_company( $value );
2509
+	public function set_user_company($value) {
2510
+		$this->set_company($value);
2511 2511
     }
2512 2512
 
2513 2513
     /**
@@ -2516,8 +2516,8 @@  discard block
 block discarded – undo
2516 2516
 	 * @since 1.0.19
2517 2517
 	 * @param  string $value company.
2518 2518
 	 */
2519
-	public function set_customer_company( $value ) {
2520
-		$this->set_company( $value );
2519
+	public function set_customer_company($value) {
2520
+		$this->set_company($value);
2521 2521
     }
2522 2522
 
2523 2523
     /**
@@ -2526,8 +2526,8 @@  discard block
 block discarded – undo
2526 2526
 	 * @since 1.0.19
2527 2527
 	 * @param  string $value var number.
2528 2528
 	 */
2529
-	public function set_vat_number( $value ) {
2530
-		$this->set_prop( 'vat_number', $value );
2529
+	public function set_vat_number($value) {
2530
+		$this->set_prop('vat_number', $value);
2531 2531
     }
2532 2532
 
2533 2533
     /**
@@ -2536,8 +2536,8 @@  discard block
 block discarded – undo
2536 2536
 	 * @since 1.0.19
2537 2537
 	 * @param  string $value var number.
2538 2538
 	 */
2539
-	public function set_user_vat_number( $value ) {
2540
-		$this->set_vat_number( $value );
2539
+	public function set_user_vat_number($value) {
2540
+		$this->set_vat_number($value);
2541 2541
     }
2542 2542
 
2543 2543
     /**
@@ -2546,8 +2546,8 @@  discard block
 block discarded – undo
2546 2546
 	 * @since 1.0.19
2547 2547
 	 * @param  string $value var number.
2548 2548
 	 */
2549
-	public function set_customer_vat_number( $value ) {
2550
-		$this->set_vat_number( $value );
2549
+	public function set_customer_vat_number($value) {
2550
+		$this->set_vat_number($value);
2551 2551
     }
2552 2552
 
2553 2553
     /**
@@ -2556,8 +2556,8 @@  discard block
 block discarded – undo
2556 2556
 	 * @since 1.0.19
2557 2557
 	 * @param  string $value var rate.
2558 2558
 	 */
2559
-	public function set_vat_rate( $value ) {
2560
-		$this->set_prop( 'vat_rate', $value );
2559
+	public function set_vat_rate($value) {
2560
+		$this->set_prop('vat_rate', $value);
2561 2561
     }
2562 2562
 
2563 2563
     /**
@@ -2566,8 +2566,8 @@  discard block
 block discarded – undo
2566 2566
 	 * @since 1.0.19
2567 2567
 	 * @param  string $value var number.
2568 2568
 	 */
2569
-	public function set_user_vat_rate( $value ) {
2570
-		$this->set_vat_rate( $value );
2569
+	public function set_user_vat_rate($value) {
2570
+		$this->set_vat_rate($value);
2571 2571
     }
2572 2572
 
2573 2573
     /**
@@ -2576,8 +2576,8 @@  discard block
 block discarded – undo
2576 2576
 	 * @since 1.0.19
2577 2577
 	 * @param  string $value var number.
2578 2578
 	 */
2579
-	public function set_customer_vat_rate( $value ) {
2580
-		$this->set_vat_rate( $value );
2579
+	public function set_customer_vat_rate($value) {
2580
+		$this->set_vat_rate($value);
2581 2581
     }
2582 2582
 
2583 2583
     /**
@@ -2586,8 +2586,8 @@  discard block
 block discarded – undo
2586 2586
 	 * @since 1.0.19
2587 2587
 	 * @param  string $value address.
2588 2588
 	 */
2589
-	public function set_address( $value ) {
2590
-		$this->set_prop( 'address', $value );
2589
+	public function set_address($value) {
2590
+		$this->set_prop('address', $value);
2591 2591
     }
2592 2592
 
2593 2593
     /**
@@ -2596,8 +2596,8 @@  discard block
 block discarded – undo
2596 2596
 	 * @since 1.0.19
2597 2597
 	 * @param  string $value address.
2598 2598
 	 */
2599
-	public function set_user_address( $value ) {
2600
-		$this->set_address( $value );
2599
+	public function set_user_address($value) {
2600
+		$this->set_address($value);
2601 2601
     }
2602 2602
 
2603 2603
     /**
@@ -2606,8 +2606,8 @@  discard block
 block discarded – undo
2606 2606
 	 * @since 1.0.19
2607 2607
 	 * @param  string $value address.
2608 2608
 	 */
2609
-	public function set_customer_address( $value ) {
2610
-		$this->set_address( $value );
2609
+	public function set_customer_address($value) {
2610
+		$this->set_address($value);
2611 2611
     }
2612 2612
 
2613 2613
     /**
@@ -2616,8 +2616,8 @@  discard block
 block discarded – undo
2616 2616
 	 * @since 1.0.19
2617 2617
 	 * @param  int|bool $value confirmed.
2618 2618
 	 */
2619
-	public function set_is_viewed( $value ) {
2620
-		$this->set_prop( 'is_viewed', $value );
2619
+	public function set_is_viewed($value) {
2620
+		$this->set_prop('is_viewed', $value);
2621 2621
 	}
2622 2622
 
2623 2623
 	/**
@@ -2626,8 +2626,8 @@  discard block
 block discarded – undo
2626 2626
 	 * @since 1.0.19
2627 2627
 	 * @param  string $value email recipients.
2628 2628
 	 */
2629
-	public function set_email_cc( $value ) {
2630
-		$this->set_prop( 'email_cc', $value );
2629
+	public function set_email_cc($value) {
2630
+		$this->set_prop('email_cc', $value);
2631 2631
 	}
2632 2632
 
2633 2633
 	/**
@@ -2636,9 +2636,9 @@  discard block
 block discarded – undo
2636 2636
 	 * @since 1.0.19
2637 2637
 	 * @param  string $value template.
2638 2638
 	 */
2639
-	public function set_template( $value ) {
2640
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2641
-			$this->set_prop( 'template', $value );
2639
+	public function set_template($value) {
2640
+		if (in_array($value, array('quantity', 'hours', 'amount'))) {
2641
+			$this->set_prop('template', $value);
2642 2642
 		}
2643 2643
 	}
2644 2644
 
@@ -2648,8 +2648,8 @@  discard block
 block discarded – undo
2648 2648
 	 * @since 1.0.19
2649 2649
 	 * @param  string $value email recipients.
2650 2650
 	 */
2651
-	public function created_via( $value ) {
2652
-		$this->set_prop( 'created_via', sanitize_text_field( $value ) );
2651
+	public function created_via($value) {
2652
+		$this->set_prop('created_via', sanitize_text_field($value));
2653 2653
 	}
2654 2654
 
2655 2655
 	/**
@@ -2658,8 +2658,8 @@  discard block
 block discarded – undo
2658 2658
 	 * @since 1.0.19
2659 2659
 	 * @param  int|bool $value confirmed.
2660 2660
 	 */
2661
-	public function set_address_confirmed( $value ) {
2662
-		$this->set_prop( 'address_confirmed', $value );
2661
+	public function set_address_confirmed($value) {
2662
+		$this->set_prop('address_confirmed', $value);
2663 2663
     }
2664 2664
 
2665 2665
     /**
@@ -2668,8 +2668,8 @@  discard block
 block discarded – undo
2668 2668
 	 * @since 1.0.19
2669 2669
 	 * @param  int|bool $value confirmed.
2670 2670
 	 */
2671
-	public function set_user_address_confirmed( $value ) {
2672
-		$this->set_address_confirmed( $value );
2671
+	public function set_user_address_confirmed($value) {
2672
+		$this->set_address_confirmed($value);
2673 2673
     }
2674 2674
 
2675 2675
     /**
@@ -2678,8 +2678,8 @@  discard block
 block discarded – undo
2678 2678
 	 * @since 1.0.19
2679 2679
 	 * @param  int|bool $value confirmed.
2680 2680
 	 */
2681
-	public function set_customer_address_confirmed( $value ) {
2682
-		$this->set_address_confirmed( $value );
2681
+	public function set_customer_address_confirmed($value) {
2682
+		$this->set_address_confirmed($value);
2683 2683
     }
2684 2684
 
2685 2685
     /**
@@ -2688,8 +2688,8 @@  discard block
 block discarded – undo
2688 2688
 	 * @since 1.0.19
2689 2689
 	 * @param  float $value sub total.
2690 2690
 	 */
2691
-	public function set_subtotal( $value ) {
2692
-		$this->set_prop( 'subtotal', $value );
2691
+	public function set_subtotal($value) {
2692
+		$this->set_prop('subtotal', $value);
2693 2693
     }
2694 2694
 
2695 2695
     /**
@@ -2698,8 +2698,8 @@  discard block
 block discarded – undo
2698 2698
 	 * @since 1.0.19
2699 2699
 	 * @param  float $value discount total.
2700 2700
 	 */
2701
-	public function set_total_discount( $value ) {
2702
-		$this->set_prop( 'total_discount', $value );
2701
+	public function set_total_discount($value) {
2702
+		$this->set_prop('total_discount', $value);
2703 2703
     }
2704 2704
 
2705 2705
     /**
@@ -2708,8 +2708,8 @@  discard block
 block discarded – undo
2708 2708
 	 * @since 1.0.19
2709 2709
 	 * @param  float $value discount total.
2710 2710
 	 */
2711
-	public function set_discount( $value ) {
2712
-		$this->set_total_discount( $value );
2711
+	public function set_discount($value) {
2712
+		$this->set_total_discount($value);
2713 2713
     }
2714 2714
 
2715 2715
     /**
@@ -2718,8 +2718,8 @@  discard block
 block discarded – undo
2718 2718
 	 * @since 1.0.19
2719 2719
 	 * @param  float $value tax total.
2720 2720
 	 */
2721
-	public function set_total_tax( $value ) {
2722
-		$this->set_prop( 'total_tax', $value );
2721
+	public function set_total_tax($value) {
2722
+		$this->set_prop('total_tax', $value);
2723 2723
     }
2724 2724
 
2725 2725
     /**
@@ -2728,8 +2728,8 @@  discard block
 block discarded – undo
2728 2728
 	 * @since 1.0.19
2729 2729
 	 * @param  float $value tax total.
2730 2730
 	 */
2731
-	public function set_tax_total( $value ) {
2732
-		$this->set_total_tax( $value );
2731
+	public function set_tax_total($value) {
2732
+		$this->set_total_tax($value);
2733 2733
     }
2734 2734
 
2735 2735
     /**
@@ -2738,8 +2738,8 @@  discard block
 block discarded – undo
2738 2738
 	 * @since 1.0.19
2739 2739
 	 * @param  float $value fees total.
2740 2740
 	 */
2741
-	public function set_total_fees( $value ) {
2742
-		$this->set_prop( 'total_fees', $value );
2741
+	public function set_total_fees($value) {
2742
+		$this->set_prop('total_fees', $value);
2743 2743
     }
2744 2744
 
2745 2745
     /**
@@ -2748,8 +2748,8 @@  discard block
 block discarded – undo
2748 2748
 	 * @since 1.0.19
2749 2749
 	 * @param  float $value fees total.
2750 2750
 	 */
2751
-	public function set_fees_total( $value ) {
2752
-		$this->set_total_fees( $value );
2751
+	public function set_fees_total($value) {
2752
+		$this->set_total_fees($value);
2753 2753
     }
2754 2754
 
2755 2755
     /**
@@ -2758,13 +2758,13 @@  discard block
 block discarded – undo
2758 2758
 	 * @since 1.0.19
2759 2759
 	 * @param  array $value fees.
2760 2760
 	 */
2761
-	public function set_fees( $value ) {
2761
+	public function set_fees($value) {
2762 2762
 
2763
-		if ( ! is_array( $value ) ) {
2763
+		if (!is_array($value)) {
2764 2764
 			$value = array();
2765 2765
 		}
2766 2766
 
2767
-		$this->set_prop( 'fees', $value );
2767
+		$this->set_prop('fees', $value);
2768 2768
 
2769 2769
     }
2770 2770
 
@@ -2774,13 +2774,13 @@  discard block
 block discarded – undo
2774 2774
 	 * @since 1.0.19
2775 2775
 	 * @param  array $value taxes.
2776 2776
 	 */
2777
-	public function set_taxes( $value ) {
2777
+	public function set_taxes($value) {
2778 2778
 
2779
-		if ( ! is_array( $value ) ) {
2779
+		if (!is_array($value)) {
2780 2780
 			$value = array();
2781 2781
 		}
2782 2782
 
2783
-		$this->set_prop( 'taxes', $value );
2783
+		$this->set_prop('taxes', $value);
2784 2784
 
2785 2785
     }
2786 2786
 
@@ -2790,13 +2790,13 @@  discard block
 block discarded – undo
2790 2790
 	 * @since 1.0.19
2791 2791
 	 * @param  array $value discounts.
2792 2792
 	 */
2793
-	public function set_discounts( $value ) {
2793
+	public function set_discounts($value) {
2794 2794
 
2795
-		if ( ! is_array( $value ) ) {
2795
+		if (!is_array($value)) {
2796 2796
 			$value = array();
2797 2797
 		}
2798 2798
 
2799
-		$this->set_prop( 'discounts', $value );
2799
+		$this->set_prop('discounts', $value);
2800 2800
     }
2801 2801
 
2802 2802
     /**
@@ -2805,18 +2805,18 @@  discard block
 block discarded – undo
2805 2805
 	 * @since 1.0.19
2806 2806
 	 * @param  GetPaid_Form_Item[] $value items.
2807 2807
 	 */
2808
-	public function set_items( $value ) {
2808
+	public function set_items($value) {
2809 2809
 
2810 2810
         // Remove existing items.
2811
-        $this->set_prop( 'items', array() );
2811
+        $this->set_prop('items', array());
2812 2812
 
2813 2813
         // Ensure that we have an array.
2814
-        if ( ! is_array( $value ) ) {
2814
+        if (!is_array($value)) {
2815 2815
             return;
2816 2816
         }
2817 2817
 
2818
-        foreach ( $value as $item ) {
2819
-            $this->add_item( $item );
2818
+        foreach ($value as $item) {
2819
+            $this->add_item($item);
2820 2820
         }
2821 2821
 
2822 2822
     }
@@ -2827,8 +2827,8 @@  discard block
 block discarded – undo
2827 2827
 	 * @since 1.0.19
2828 2828
 	 * @param  int $value payment form.
2829 2829
 	 */
2830
-	public function set_payment_form( $value ) {
2831
-		$this->set_prop( 'payment_form', $value );
2830
+	public function set_payment_form($value) {
2831
+		$this->set_prop('payment_form', $value);
2832 2832
     }
2833 2833
 
2834 2834
     /**
@@ -2837,8 +2837,8 @@  discard block
 block discarded – undo
2837 2837
 	 * @since 1.0.19
2838 2838
 	 * @param  string $value submission id.
2839 2839
 	 */
2840
-	public function set_submission_id( $value ) {
2841
-		$this->set_prop( 'submission_id', $value );
2840
+	public function set_submission_id($value) {
2841
+		$this->set_prop('submission_id', $value);
2842 2842
     }
2843 2843
 
2844 2844
     /**
@@ -2847,8 +2847,8 @@  discard block
 block discarded – undo
2847 2847
 	 * @since 1.0.19
2848 2848
 	 * @param  string $value discount code.
2849 2849
 	 */
2850
-	public function set_discount_code( $value ) {
2851
-		$this->set_prop( 'discount_code', $value );
2850
+	public function set_discount_code($value) {
2851
+		$this->set_prop('discount_code', $value);
2852 2852
     }
2853 2853
 
2854 2854
     /**
@@ -2857,8 +2857,8 @@  discard block
 block discarded – undo
2857 2857
 	 * @since 1.0.19
2858 2858
 	 * @param  string $value gateway.
2859 2859
 	 */
2860
-	public function set_gateway( $value ) {
2861
-		$this->set_prop( 'gateway', $value );
2860
+	public function set_gateway($value) {
2861
+		$this->set_prop('gateway', $value);
2862 2862
     }
2863 2863
 
2864 2864
     /**
@@ -2867,9 +2867,9 @@  discard block
 block discarded – undo
2867 2867
 	 * @since 1.0.19
2868 2868
 	 * @param  string $value transaction id.
2869 2869
 	 */
2870
-	public function set_transaction_id( $value ) {
2871
-		if ( ! empty( $value ) ) {
2872
-			$this->set_prop( 'transaction_id', $value );
2870
+	public function set_transaction_id($value) {
2871
+		if (!empty($value)) {
2872
+			$this->set_prop('transaction_id', $value);
2873 2873
 		}
2874 2874
     }
2875 2875
 
@@ -2879,8 +2879,8 @@  discard block
 block discarded – undo
2879 2879
 	 * @since 1.0.19
2880 2880
 	 * @param  string $value currency id.
2881 2881
 	 */
2882
-	public function set_currency( $value ) {
2883
-		$this->set_prop( 'currency', $value );
2882
+	public function set_currency($value) {
2883
+		$this->set_prop('currency', $value);
2884 2884
     }
2885 2885
 
2886 2886
 	/**
@@ -2889,8 +2889,8 @@  discard block
 block discarded – undo
2889 2889
 	 * @since 1.0.19
2890 2890
 	 * @param  bool $value value.
2891 2891
 	 */
2892
-	public function set_disable_taxes( $value ) {
2893
-		$this->set_prop( 'disable_taxes', (bool) $value );
2892
+	public function set_disable_taxes($value) {
2893
+		$this->set_prop('disable_taxes', (bool) $value);
2894 2894
 	}
2895 2895
 
2896 2896
     /**
@@ -2899,8 +2899,8 @@  discard block
 block discarded – undo
2899 2899
 	 * @since 1.0.19
2900 2900
 	 * @param  string $value subscription id.
2901 2901
 	 */
2902
-	public function set_subscription_id( $value ) {
2903
-		$this->set_prop( 'subscription_id', $value );
2902
+	public function set_subscription_id($value) {
2903
+		$this->set_prop('subscription_id', $value);
2904 2904
 	}
2905 2905
 	
2906 2906
 	/**
@@ -2909,8 +2909,8 @@  discard block
 block discarded – undo
2909 2909
 	 * @since 1.0.19
2910 2910
 	 * @param  string $value subscription id.
2911 2911
 	 */
2912
-	public function set_remote_subscription_id( $value ) {
2913
-		$this->set_prop( 'remote_subscription_id', $value );
2912
+	public function set_remote_subscription_id($value) {
2913
+		$this->set_prop('remote_subscription_id', $value);
2914 2914
     }
2915 2915
 
2916 2916
     /*
@@ -2927,28 +2927,28 @@  discard block
 block discarded – undo
2927 2927
      */
2928 2928
     public function is_parent() {
2929 2929
         $parent = $this->get_parent_id();
2930
-        return apply_filters( 'wpinv_invoice_is_parent', empty( $parent ), $this );
2930
+        return apply_filters('wpinv_invoice_is_parent', empty($parent), $this);
2931 2931
     }
2932 2932
 
2933 2933
     /**
2934 2934
      * Checks if this is a renewal invoice.
2935 2935
      */
2936 2936
     public function is_renewal() {
2937
-        return ! $this->is_parent();
2937
+        return !$this->is_parent();
2938 2938
     }
2939 2939
 
2940 2940
     /**
2941 2941
      * Checks if this is a recurring invoice.
2942 2942
      */
2943 2943
     public function is_recurring() {
2944
-        return $this->is_renewal() || ! empty( $this->recurring_item );
2944
+        return $this->is_renewal() || !empty($this->recurring_item);
2945 2945
     }
2946 2946
 
2947 2947
     /**
2948 2948
      * Checks if this is a taxable invoice.
2949 2949
      */
2950 2950
     public function is_taxable() {
2951
-        return ! $this->get_disable_taxes();
2951
+        return !$this->get_disable_taxes();
2952 2952
 	}
2953 2953
 
2954 2954
 	/**
@@ -2959,57 +2959,57 @@  discard block
 block discarded – undo
2959 2959
 
2960 2960
         $requires_vat = false;
2961 2961
 
2962
-        if ( $this->country ) {
2962
+        if ($this->country) {
2963 2963
             $wpi_country        = $this->country;
2964
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2964
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2965 2965
         }
2966 2966
 
2967
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2967
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2968 2968
 	}
2969 2969
 
2970 2970
 	/**
2971 2971
 	 * Checks to see if the invoice requires payment.
2972 2972
 	 */
2973 2973
 	public function is_free() {
2974
-        $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2974
+        $is_free = ((float) wpinv_round_amount($this->get_initial_total()) == 0);
2975 2975
 
2976
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2976
+		if ($this->is_recurring() && $this->get_recurring_total() > 0) {
2977 2977
 			$is_free = false;
2978 2978
 		}
2979 2979
 
2980
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2980
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2981 2981
     }
2982 2982
 
2983 2983
     /**
2984 2984
      * Checks if the invoice is paid.
2985 2985
      */
2986 2986
     public function is_paid() {
2987
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2988
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2987
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2988
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2989 2989
 	}
2990 2990
 
2991 2991
 	/**
2992 2992
      * Checks if the invoice needs payment.
2993 2993
      */
2994 2994
 	public function needs_payment() {
2995
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2996
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2995
+		$needs_payment = !$this->is_paid() && !$this->is_refunded() && !$this->is_free();
2996
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this);
2997 2997
     }
2998 2998
   
2999 2999
 	/**
3000 3000
      * Checks if the invoice is refunded.
3001 3001
      */
3002 3002
 	public function is_refunded() {
3003
-        $is_refunded = $this->has_status( 'wpi-refunded' );
3004
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
3003
+        $is_refunded = $this->has_status('wpi-refunded');
3004
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
3005 3005
 	}
3006 3006
 
3007 3007
 	/**
3008 3008
      * Checks if the invoice is held.
3009 3009
      */
3010 3010
 	public function is_held() {
3011
-        $is_held = $this->has_status( 'wpi-onhold' );
3012
-        return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
3011
+        $is_held = $this->has_status('wpi-onhold');
3012
+        return apply_filters('wpinv_invoice_is_held', $is_held, $this);
3013 3013
 	}
3014 3014
 
3015 3015
 	/**
@@ -3017,30 +3017,30 @@  discard block
 block discarded – undo
3017 3017
      */
3018 3018
 	public function is_due() {
3019 3019
 		$due_date = $this->get_due_date();
3020
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3020
+		return empty($due_date) ? false : current_time('timestamp') > strtotime($due_date);
3021 3021
 	}
3022 3022
 
3023 3023
 	/**
3024 3024
      * Checks if the invoice is draft.
3025 3025
      */
3026 3026
 	public function is_draft() {
3027
-        return $this->has_status( 'draft, auto-draft' );
3027
+        return $this->has_status('draft, auto-draft');
3028 3028
 	}
3029 3029
 
3030 3030
     /**
3031 3031
      * Checks if the invoice has a given status.
3032 3032
      */
3033
-    public function has_status( $status ) {
3034
-        $status = wpinv_parse_list( $status );
3035
-        return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
3033
+    public function has_status($status) {
3034
+        $status = wpinv_parse_list($status);
3035
+        return apply_filters('wpinv_has_status', in_array($this->get_status(), $status), $status);
3036 3036
 	}
3037 3037
 
3038 3038
 	/**
3039 3039
      * Checks if the invoice is of a given type.
3040 3040
      */
3041
-    public function is_type( $type ) {
3042
-        $type = wpinv_parse_list( $type );
3043
-        return in_array( $this->get_type(), $type );
3041
+    public function is_type($type) {
3042
+        $type = wpinv_parse_list($type);
3043
+        return in_array($this->get_type(), $type);
3044 3044
     }
3045 3045
 
3046 3046
     /**
@@ -3072,8 +3072,8 @@  discard block
 block discarded – undo
3072 3072
      *
3073 3073
      */
3074 3074
 	public function is_initial_free() {
3075
-        $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3076
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3075
+        $is_initial_free = !((float) wpinv_round_amount($this->get_initial_total()) > 0);
3076
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this);
3077 3077
     }
3078 3078
 	
3079 3079
 	/**
@@ -3083,11 +3083,11 @@  discard block
 block discarded – undo
3083 3083
     public function item_has_free_trial() {
3084 3084
 
3085 3085
         // Ensure we have a recurring item.
3086
-        if ( ! $this->is_recurring() ) {
3086
+        if (!$this->is_recurring()) {
3087 3087
             return false;
3088 3088
         }
3089 3089
 
3090
-        $item = $this->get_recurring( true );
3090
+        $item = $this->get_recurring(true);
3091 3091
         return $item->has_free_trial();
3092 3092
 	}
3093 3093
 
@@ -3095,7 +3095,7 @@  discard block
 block discarded – undo
3095 3095
      * Check if the free trial is a result of a discount.
3096 3096
      */
3097 3097
     public function is_free_trial_from_discount() {
3098
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3098
+		return $this->has_free_trial() && !$this->item_has_free_trial();
3099 3099
 	}
3100 3100
 	
3101 3101
 	/**
@@ -3104,17 +3104,17 @@  discard block
 block discarded – undo
3104 3104
     public function discount_first_payment_only() {
3105 3105
 
3106 3106
 		$discount_code = $this->get_discount_code();
3107
-        if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
3107
+        if (empty($this->discount_code) || !$this->is_recurring()) {
3108 3108
             return true;
3109 3109
         }
3110 3110
 
3111
-        $discount = wpinv_get_discount_obj( $discount_code );
3111
+        $discount = wpinv_get_discount_obj($discount_code);
3112 3112
 
3113
-        if ( ! $discount || ! $discount->exists() ) {
3113
+        if (!$discount || !$discount->exists()) {
3114 3114
             return true;
3115 3115
         }
3116 3116
 
3117
-        return ! $discount->get_is_recurring();
3117
+        return !$discount->get_is_recurring();
3118 3118
     }
3119 3119
 
3120 3120
     /*
@@ -3132,27 +3132,27 @@  discard block
 block discarded – undo
3132 3132
      * @param GetPaid_Form_Item|array $item
3133 3133
      * @return WP_Error|Bool
3134 3134
      */
3135
-    public function add_item( $item ) {
3135
+    public function add_item($item) {
3136 3136
 
3137
-		if ( is_array( $item ) ) {
3138
-			$item = $this->process_array_item( $item );
3137
+		if (is_array($item)) {
3138
+			$item = $this->process_array_item($item);
3139 3139
 		}
3140 3140
 
3141
-		if ( is_numeric( $item ) ) {
3142
-			$item = new GetPaid_Form_Item( $item );
3141
+		if (is_numeric($item)) {
3142
+			$item = new GetPaid_Form_Item($item);
3143 3143
 		}
3144 3144
 
3145 3145
         // Make sure that it is available for purchase.
3146
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3147
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3146
+		if ($item->get_id() > 0 && !$item->can_purchase()) {
3147
+			return new WP_Error('invalid_item', __('This item is not available for purchase', 'invoicing'));
3148 3148
         }
3149 3149
 
3150 3150
         // Do we have a recurring item?
3151
-		if ( $item->is_recurring() ) {
3151
+		if ($item->is_recurring()) {
3152 3152
 
3153 3153
 			// An invoice can only contain one recurring item.
3154
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3155
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3154
+			if (!empty($this->recurring_item && $this->recurring_item != (int) $item->get_id())) {
3155
+				return new WP_Error('recurring_item', __('An invoice can only contain one recurring item', 'invoicing'));
3156 3156
 			}
3157 3157
 
3158 3158
 			$this->recurring_item = $item->get_id();
@@ -3163,9 +3163,9 @@  discard block
 block discarded – undo
3163 3163
 
3164 3164
         // Retrieve all items.
3165 3165
         $items = $this->get_items();
3166
-        $items[ (int) $item->get_id() ] = $item;
3166
+        $items[(int) $item->get_id()] = $item;
3167 3167
 
3168
-        $this->set_prop( 'items', $items );
3168
+        $this->set_prop('items', $items);
3169 3169
 		return true;
3170 3170
 	}
3171 3171
 
@@ -3175,26 +3175,26 @@  discard block
 block discarded – undo
3175 3175
 	 * @since 1.0.19
3176 3176
 	 * @return GetPaid_Form_Item
3177 3177
 	 */
3178
-	protected function process_array_item( $array ) {
3178
+	protected function process_array_item($array) {
3179 3179
 
3180
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3181
-		$item    = new GetPaid_Form_Item( $item_id );
3180
+		$item_id = isset($array['item_id']) ? $array['item_id'] : 0;
3181
+		$item    = new GetPaid_Form_Item($item_id);
3182 3182
 
3183 3183
 		// Set item data.
3184
-		foreach ( array( 'name', 'price', 'description' ) as $key ) {
3185
-			if ( isset( $array[ "item_$key" ] ) ) {
3184
+		foreach (array('name', 'price', 'description') as $key) {
3185
+			if (isset($array["item_$key"])) {
3186 3186
 				$method = "set_$key";
3187
-				$item->$method( $array[ "item_$key" ] );
3187
+				$item->$method($array["item_$key"]);
3188 3188
 			}
3189 3189
 		}
3190 3190
 
3191
-		if ( isset( $array['quantity'] ) ) {
3192
-			$item->set_quantity( $array['quantity'] );
3191
+		if (isset($array['quantity'])) {
3192
+			$item->set_quantity($array['quantity']);
3193 3193
 		}
3194 3194
 
3195 3195
 		// Set item meta.
3196
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3197
-			$item->set_item_meta( $array['meta'] );
3196
+		if (isset($array['meta']) && is_array($array['meta'])) {
3197
+			$item->set_item_meta($array['meta']);
3198 3198
 		}
3199 3199
 
3200 3200
 		return $item;
@@ -3206,10 +3206,10 @@  discard block
 block discarded – undo
3206 3206
 	 *
3207 3207
 	 * @since 1.0.19
3208 3208
 	 */
3209
-	public function get_item( $item_id ) {
3209
+	public function get_item($item_id) {
3210 3210
 		$items   = $this->get_items();
3211 3211
 		$item_id = (int) $item_id;
3212
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3212
+		return (!empty($item_id) && isset($items[$item_id])) ? $items[$item_id] : null;
3213 3213
     }
3214 3214
 
3215 3215
     /**
@@ -3217,17 +3217,17 @@  discard block
 block discarded – undo
3217 3217
 	 *
3218 3218
 	 * @since 1.0.19
3219 3219
 	 */
3220
-	public function remove_item( $item_id ) {
3220
+	public function remove_item($item_id) {
3221 3221
 		$items   = $this->get_items();
3222 3222
 		$item_id = (int) $item_id;
3223 3223
 
3224
-        if ( $item_id == $this->recurring_item ) {
3224
+        if ($item_id == $this->recurring_item) {
3225 3225
             $this->recurring_item = null;
3226 3226
         }
3227 3227
 
3228
-        if ( isset( $items[ $item_id ] ) ) {
3229
-            unset( $items[ $item_id ] );
3230
-            $this->set_prop( 'items', $items );
3228
+        if (isset($items[$item_id])) {
3229
+            unset($items[$item_id]);
3230
+            $this->set_prop('items', $items);
3231 3231
         }
3232 3232
     }
3233 3233
 
@@ -3237,11 +3237,11 @@  discard block
 block discarded – undo
3237 3237
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3238 3238
 	 * @since 1.0.19
3239 3239
 	 */
3240
-    public function add_fee( $fee ) {
3240
+    public function add_fee($fee) {
3241 3241
 
3242 3242
 		$fees                 = $this->get_fees();
3243
-		$fees[ $fee['name'] ] = $fee;
3244
-		$this->set_prop( 'fees', $fees );
3243
+		$fees[$fee['name']] = $fee;
3244
+		$this->set_prop('fees', $fees);
3245 3245
 
3246 3246
     }
3247 3247
 
@@ -3250,9 +3250,9 @@  discard block
 block discarded – undo
3250 3250
 	 *
3251 3251
 	 * @since 1.0.19
3252 3252
 	 */
3253
-	public function get_fee( $fee ) {
3253
+	public function get_fee($fee) {
3254 3254
         $fees = $this->get_fees();
3255
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3255
+		return isset($fees[$fee]) ? $fees[$fee] : null;
3256 3256
     }
3257 3257
 
3258 3258
     /**
@@ -3260,11 +3260,11 @@  discard block
 block discarded – undo
3260 3260
 	 *
3261 3261
 	 * @since 1.0.19
3262 3262
 	 */
3263
-	public function remove_fee( $fee ) {
3263
+	public function remove_fee($fee) {
3264 3264
         $fees = $this->get_fees();
3265
-        if ( isset( $fees[ $fee ] ) ) {
3266
-            unset( $fees[ $fee ] );
3267
-            $this->set_prop( 'fees', $fees );
3265
+        if (isset($fees[$fee])) {
3266
+            unset($fees[$fee]);
3267
+            $this->set_prop('fees', $fees);
3268 3268
         }
3269 3269
     }
3270 3270
 
@@ -3274,11 +3274,11 @@  discard block
 block discarded – undo
3274 3274
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3275 3275
 	 * @since 1.0.19
3276 3276
 	 */
3277
-	public function add_discount( $discount ) {
3277
+	public function add_discount($discount) {
3278 3278
 
3279 3279
 		$discounts = $this->get_discounts();
3280
-		$discounts[ $discount['name'] ] = $discount;
3281
-		$this->set_prop( 'discounts', $discounts );
3280
+		$discounts[$discount['name']] = $discount;
3281
+		$this->set_prop('discounts', $discounts);
3282 3282
 
3283 3283
 	}
3284 3284
 
@@ -3288,15 +3288,15 @@  discard block
 block discarded – undo
3288 3288
 	 * @since 1.0.19
3289 3289
 	 * @return float
3290 3290
 	 */
3291
-	public function get_discount( $discount = false ) {
3291
+	public function get_discount($discount = false) {
3292 3292
 
3293 3293
 		// Backwards compatibilty.
3294
-		if ( empty( $discount ) ) {
3294
+		if (empty($discount)) {
3295 3295
 			return $this->get_total_discount();
3296 3296
 		}
3297 3297
 
3298 3298
         $discounts = $this->get_discounts();
3299
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3299
+		return isset($discounts[$discount]) ? $discounts[$discount] : null;
3300 3300
     }
3301 3301
 
3302 3302
     /**
@@ -3304,11 +3304,11 @@  discard block
 block discarded – undo
3304 3304
 	 *
3305 3305
 	 * @since 1.0.19
3306 3306
 	 */
3307
-	public function remove_discount( $discount ) {
3307
+	public function remove_discount($discount) {
3308 3308
         $discounts = $this->get_discounts();
3309
-        if ( isset( $discounts[ $discount ] ) ) {
3310
-            unset( $discounts[ $discount ] );
3311
-            $this->set_prop( 'discounts', $discounts );
3309
+        if (isset($discounts[$discount])) {
3310
+            unset($discounts[$discount]);
3311
+            $this->set_prop('discounts', $discounts);
3312 3312
         }
3313 3313
     }
3314 3314
 
@@ -3317,12 +3317,12 @@  discard block
 block discarded – undo
3317 3317
      *
3318 3318
      * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
3319 3319
      */
3320
-    public function add_tax( $tax ) {
3321
-        if ( $this->is_taxable() ) {
3320
+    public function add_tax($tax) {
3321
+        if ($this->is_taxable()) {
3322 3322
 
3323
-            $taxes                 = $this->get_taxes();
3324
-			$taxes[ $tax['name'] ] = $tax;
3325
-			$this->set_prop( 'taxes', $tax );
3323
+            $taxes = $this->get_taxes();
3324
+			$taxes[$tax['name']] = $tax;
3325
+			$this->set_prop('taxes', $tax);
3326 3326
 
3327 3327
         }
3328 3328
     }
@@ -3332,15 +3332,15 @@  discard block
 block discarded – undo
3332 3332
 	 *
3333 3333
 	 * @since 1.0.19
3334 3334
 	 */
3335
-	public function get_tax( $tax = null ) {
3335
+	public function get_tax($tax = null) {
3336 3336
 
3337 3337
 		// Backwards compatility.
3338
-		if ( empty( $tax ) ) {
3338
+		if (empty($tax)) {
3339 3339
 			return $this->get_total_tax();
3340 3340
 		}
3341 3341
 
3342 3342
         $taxes = $this->get_taxes();
3343
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3343
+		return isset($taxes[$tax]) ? $taxes[$tax] : null;
3344 3344
     }
3345 3345
 
3346 3346
     /**
@@ -3348,11 +3348,11 @@  discard block
 block discarded – undo
3348 3348
 	 *
3349 3349
 	 * @since 1.0.19
3350 3350
 	 */
3351
-	public function remove_tax( $tax ) {
3351
+	public function remove_tax($tax) {
3352 3352
         $taxes = $this->get_taxes();
3353
-        if ( isset( $taxes[ $tax ] ) ) {
3354
-            unset( $taxes[ $tax ] );
3355
-            $this->set_prop( 'taxes', $taxes );
3353
+        if (isset($taxes[$tax])) {
3354
+            unset($taxes[$tax]);
3355
+            $this->set_prop('taxes', $taxes);
3356 3356
         }
3357 3357
     }
3358 3358
 
@@ -3363,17 +3363,17 @@  discard block
 block discarded – undo
3363 3363
 	 * @return float The recalculated subtotal
3364 3364
 	 */
3365 3365
 	public function recalculate_subtotal() {
3366
-        $items     = $this->get_items();
3366
+        $items = $this->get_items();
3367 3367
 		$subtotal  = 0;
3368 3368
 		$recurring = 0;
3369 3369
 
3370
-        foreach ( $items as $item ) {
3370
+        foreach ($items as $item) {
3371 3371
 			$subtotal  += $item->get_sub_total();
3372 3372
 			$recurring += $item->get_recurring_sub_total();
3373 3373
         }
3374 3374
 
3375 3375
 		$current = $this->is_renewal() ? $recurring : $subtotal;
3376
-		$this->set_subtotal( $current );
3376
+		$this->set_subtotal($current);
3377 3377
 
3378 3378
 		$this->totals['subtotal'] = array(
3379 3379
 			'initial'   => $subtotal,
@@ -3394,14 +3394,14 @@  discard block
 block discarded – undo
3394 3394
 		$discount  = 0;
3395 3395
 		$recurring = 0;
3396 3396
 
3397
-        foreach ( $discounts as $data ) {
3398
-			$discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3399
-			$recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3397
+        foreach ($discounts as $data) {
3398
+			$discount  += wpinv_sanitize_amount($data['initial_discount']);
3399
+			$recurring += wpinv_sanitize_amount($data['recurring_discount']);
3400 3400
 		}
3401 3401
 
3402 3402
 		$current = $this->is_renewal() ? $recurring : $discount;
3403 3403
 
3404
-		$this->set_total_discount( $current );
3404
+		$this->set_total_discount($current);
3405 3405
 
3406 3406
 		$this->totals['discount'] = array(
3407 3407
 			'initial'   => $discount,
@@ -3419,17 +3419,17 @@  discard block
 block discarded – undo
3419 3419
 	 * @return float The recalculated tax
3420 3420
 	 */
3421 3421
 	public function recalculate_total_tax() {
3422
-        $taxes     = $this->get_taxes();
3422
+        $taxes = $this->get_taxes();
3423 3423
 		$tax       = 0;
3424 3424
 		$recurring = 0;
3425 3425
 
3426
-        foreach ( $taxes as $data ) {
3427
-			$tax       += wpinv_sanitize_amount( $data['initial_tax'] );
3428
-			$recurring += wpinv_sanitize_amount( $data['recurring_tax'] );
3426
+        foreach ($taxes as $data) {
3427
+			$tax       += wpinv_sanitize_amount($data['initial_tax']);
3428
+			$recurring += wpinv_sanitize_amount($data['recurring_tax']);
3429 3429
 		}
3430 3430
 
3431 3431
 		$current = $this->is_renewal() ? $recurring : $tax;
3432
-		$this->set_total_tax( $current );
3432
+		$this->set_total_tax($current);
3433 3433
 
3434 3434
 		$this->totals['tax'] = array(
3435 3435
 			'initial'   => $tax,
@@ -3451,20 +3451,20 @@  discard block
 block discarded – undo
3451 3451
 		$fee       = 0;
3452 3452
 		$recurring = 0;
3453 3453
 
3454
-        foreach ( $fees as $data ) {
3455
-			$fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3456
-			$recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3454
+        foreach ($fees as $data) {
3455
+			$fee       += wpinv_sanitize_amount($data['initial_fee']);
3456
+			$recurring += wpinv_sanitize_amount($data['recurring_fee']);
3457 3457
 		}
3458 3458
 
3459 3459
 		$current = $this->is_renewal() ? $recurring : $fee;
3460
-		$this->set_total_fees( $current );
3460
+		$this->set_total_fees($current);
3461 3461
 
3462 3462
 		$this->totals['fee'] = array(
3463 3463
 			'initial'   => $fee,
3464 3464
 			'recurring' => $recurring,
3465 3465
 		);
3466 3466
 
3467
-        $this->set_total_fees( $fee );
3467
+        $this->set_total_fees($fee);
3468 3468
         return $current;
3469 3469
     }
3470 3470
 
@@ -3485,9 +3485,9 @@  discard block
 block discarded – undo
3485 3485
 	/**
3486 3486
 	 * @deprecated
3487 3487
 	 */
3488
-    public function recalculate_totals( $temp = false ) {
3489
-        $this->update_items( $temp );
3490
-        $this->save( true );
3488
+    public function recalculate_totals($temp = false) {
3489
+        $this->update_items($temp);
3490
+        $this->save(true);
3491 3491
         return $this;
3492 3492
     }
3493 3493
 
@@ -3505,10 +3505,10 @@  discard block
 block discarded – undo
3505 3505
 	 * @return int|false The new note's ID on success, false on failure.
3506 3506
      *
3507 3507
      */
3508
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
3508
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
3509 3509
 
3510 3510
         // Bail if no note specified or this invoice is not yet saved.
3511
-        if ( ! $note || $this->get_id() == 0 || ( ! is_user_logged_in() && ! $system ) ) {
3511
+        if (!$note || $this->get_id() == 0 || (!is_user_logged_in() && !$system)) {
3512 3512
             return false;
3513 3513
         }
3514 3514
 
@@ -3516,23 +3516,23 @@  discard block
 block discarded – undo
3516 3516
 		$author_email = '[email protected]';
3517 3517
 
3518 3518
 		// If this is an admin comment or it has been added by the user.
3519
-		if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3520
-			$user         = get_user_by( 'id', get_current_user_id() );
3519
+		if (is_user_logged_in() && (!$system || $added_by_user)) {
3520
+			$user = get_user_by('id', get_current_user_id());
3521 3521
             $author       = $user->display_name;
3522 3522
             $author_email = $user->user_email;
3523 3523
 		}
3524 3524
 
3525
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3525
+		return getpaid_notes()->add_invoice_note($this, $note, $author, $author_email, $customer_type);
3526 3526
 
3527 3527
 	}
3528 3528
 
3529 3529
 	/**
3530 3530
      * Generates a unique key for the invoice.
3531 3531
      */
3532
-    public function generate_key( $string = '' ) {
3533
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
3532
+    public function generate_key($string = '') {
3533
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
3534 3534
         return strtolower(
3535
-            $string . md5( $this->get_id() . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) )
3535
+            $string . md5($this->get_id() . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))
3536 3536
         );
3537 3537
     }
3538 3538
 
@@ -3542,11 +3542,11 @@  discard block
 block discarded – undo
3542 3542
     public function generate_number() {
3543 3543
         $number = $this->get_id();
3544 3544
 
3545
-        if ( wpinv_sequential_number_active( $this->get_post_type() ) ) {
3546
-            $number = wpinv_get_next_invoice_number( $this->get_post_type() );
3545
+        if (wpinv_sequential_number_active($this->get_post_type())) {
3546
+            $number = wpinv_get_next_invoice_number($this->get_post_type());
3547 3547
         }
3548 3548
 
3549
-		return wpinv_format_invoice_number( $number, $this->get_post_type() );
3549
+		return wpinv_format_invoice_number($number, $this->get_post_type());
3550 3550
 
3551 3551
 	}
3552 3552
 
@@ -3559,55 +3559,55 @@  discard block
 block discarded – undo
3559 3559
 		// Reset status transition variable.
3560 3560
 		$this->status_transition = false;
3561 3561
 
3562
-		if ( $status_transition ) {
3562
+		if ($status_transition) {
3563 3563
 			try {
3564 3564
 
3565 3565
 				// Fire a hook for the status change.
3566
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3566
+				do_action('getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition);
3567 3567
 
3568 3568
 				// @deprecated this is deprecated and will be removed in the future.
3569
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3569
+				do_action('wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from']);
3570 3570
 
3571
-				if ( ! empty( $status_transition['from'] ) ) {
3571
+				if (!empty($status_transition['from'])) {
3572 3572
 
3573 3573
 					/* translators: 1: old invoice status 2: new invoice status */
3574
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3574
+					$transition_note = sprintf(__('Status changed from %1$s to %2$s.', 'invoicing'), wpinv_status_nicename($status_transition['from']), wpinv_status_nicename($status_transition['to']));
3575 3575
 
3576 3576
 					// Fire another hook.
3577
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3578
-					do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3577
+					do_action('getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this);
3578
+					do_action('getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to']);
3579 3579
 
3580 3580
 					// @deprecated this is deprecated and will be removed in the future.
3581
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3581
+					do_action('wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from']);
3582 3582
 
3583 3583
 					// Note the transition occurred.
3584
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3584
+					$this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']);
3585 3585
 
3586 3586
 					// Work out if this was for a payment, and trigger a payment_status hook instead.
3587 3587
 					if (
3588
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3589
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3588
+						in_array($status_transition['from'], array('wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold'), true)
3589
+						&& in_array($status_transition['to'], array('publish', 'wpi-processing', 'wpi-renewal'), true)
3590 3590
 					) {
3591
-						do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3591
+						do_action('getpaid_invoice_payment_status_changed', $this, $status_transition);
3592 3592
 					}
3593 3593
 
3594 3594
 					// Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3595 3595
 					if (
3596
-						in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3597
-						&& in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3596
+						in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'), true)
3597
+						&& in_array($status_transition['to'], array('wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold'), true)
3598 3598
 					) {
3599
-						do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3599
+						do_action('getpaid_invoice_payment_status_reversed', $this, $status_transition);
3600 3600
 					}
3601 3601
 				} else {
3602 3602
 					/* translators: %s: new invoice status */
3603
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3603
+					$transition_note = sprintf(__('Status set to %s.', 'invoicing'), wpinv_status_nicename($status_transition['to']));
3604 3604
 
3605 3605
 					// Note the transition occurred.
3606
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3606
+					$this->add_note(trim($status_transition['note'] . ' ' . $transition_note), 0, $status_transition['manual']);
3607 3607
 
3608 3608
 				}
3609
-			} catch ( Exception $e ) {
3610
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3609
+			} catch (Exception $e) {
3610
+				$this->add_note(__('Error during status transition.', 'invoicing') . ' ' . $e->getMessage());
3611 3611
 			}
3612 3612
 		}
3613 3613
 	}
@@ -3615,13 +3615,13 @@  discard block
 block discarded – undo
3615 3615
 	/**
3616 3616
 	 * Updates an invoice status.
3617 3617
 	 */
3618
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3618
+	public function update_status($new_status = false, $note = '', $manual = false) {
3619 3619
 
3620 3620
 		// Fires before updating a status.
3621
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3621
+		do_action('wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status('edit'));
3622 3622
 
3623 3623
 		// Update the status.
3624
-		$this->set_status( $new_status, $note, $manual );
3624
+		$this->set_status($new_status, $note, $manual);
3625 3625
 
3626 3626
 		// Save the order.
3627 3627
 		return $this->save();
@@ -3632,18 +3632,18 @@  discard block
 block discarded – undo
3632 3632
 	 * @deprecated
3633 3633
 	 */
3634 3634
 	public function refresh_item_ids() {
3635
-        $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3636
-        update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3635
+        $item_ids = implode(',', array_unique(array_keys($this->get_items())));
3636
+        update_post_meta($this->get_id(), '_wpinv_item_ids', $item_ids);
3637 3637
 	}
3638 3638
 
3639 3639
 	/**
3640 3640
 	 * @deprecated
3641 3641
 	 */
3642
-	public function update_items( $temp = false ) {
3642
+	public function update_items($temp = false) {
3643 3643
 
3644
-		$this->set_items( $this->get_items() );
3644
+		$this->set_items($this->get_items());
3645 3645
 
3646
-		if ( ! $temp ) {
3646
+		if (!$temp) {
3647 3647
 			$this->save();
3648 3648
 		}
3649 3649
 
@@ -3657,11 +3657,11 @@  discard block
 block discarded – undo
3657 3657
 
3658 3658
         $discount_code = $this->get_discount_code();
3659 3659
 
3660
-        if ( empty( $discount_code ) ) {
3660
+        if (empty($discount_code)) {
3661 3661
             return false;
3662 3662
         }
3663 3663
 
3664
-        $discount = wpinv_get_discount_obj( $discount_code );
3664
+        $discount = wpinv_get_discount_obj($discount_code);
3665 3665
 
3666 3666
         // Ensure it is active.
3667 3667
         return $discount->exists();
@@ -3672,7 +3672,7 @@  discard block
 block discarded – undo
3672 3672
 	 * Refunds an invoice.
3673 3673
 	 */
3674 3674
     public function refund() {
3675
-		$this->set_status( 'wpi-refunded' );
3675
+		$this->set_status('wpi-refunded');
3676 3676
         $this->save();
3677 3677
 	}
3678 3678
 
@@ -3681,56 +3681,56 @@  discard block
 block discarded – undo
3681 3681
 	 * 
3682 3682
 	 * @param string $transaction_id
3683 3683
 	 */
3684
-    public function mark_paid( $transaction_id = null, $note = '' ) {
3684
+    public function mark_paid($transaction_id = null, $note = '') {
3685 3685
 
3686 3686
 		// Set the transaction id.
3687
-		if ( empty( $transaction_id ) ) {
3687
+		if (empty($transaction_id)) {
3688 3688
 			$transaction_id = $this->generate_key('trans_');
3689 3689
 		}
3690 3690
 
3691
-		if ( ! $this->get_transaction_id() ) {
3692
-			$this->set_transaction_id( $transaction_id );
3691
+		if (!$this->get_transaction_id()) {
3692
+			$this->set_transaction_id($transaction_id);
3693 3693
 		}
3694 3694
 
3695
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3695
+		if ($this->is_paid() && 'wpi-processing' != $this->get_status()) {
3696 3696
 			return $this->save();
3697 3697
 		}
3698 3698
 
3699 3699
 		// Set the completed date.
3700
-		$this->set_date_completed( current_time( 'mysql' ) );
3700
+		$this->set_date_completed(current_time('mysql'));
3701 3701
 
3702 3702
 		// Set the new status.
3703
-		if ( $this->is_renewal() ) {
3703
+		if ($this->is_renewal()) {
3704 3704
 
3705 3705
 			$_note = sprintf(
3706
-				__( 'Renewed via %s', 'invoicing' ),
3707
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3706
+				__('Renewed via %s', 'invoicing'),
3707
+				$this->get_gateway_title() . empty($note) ? '' : " ($note)"
3708 3708
 			);
3709 3709
 
3710
-			if ( 'none' == $this->get_gateway() ) {
3710
+			if ('none' == $this->get_gateway()) {
3711 3711
 				$_note = $note;
3712 3712
 			}
3713 3713
 
3714
-			$this->set_status( 'wpi-renewal', $_note );
3714
+			$this->set_status('wpi-renewal', $_note);
3715 3715
 
3716 3716
 		} else {
3717 3717
 
3718 3718
 			$_note = sprintf(
3719
-				__( 'Paid via %s', 'invoicing' ),
3720
-				$this->get_gateway() . empty( $note ) ? '' : " ($note)"
3719
+				__('Paid via %s', 'invoicing'),
3720
+				$this->get_gateway() . empty($note) ? '' : " ($note)"
3721 3721
 			);
3722 3722
 
3723
-			if ( 'none' == $this->get_gateway() ) {
3723
+			if ('none' == $this->get_gateway()) {
3724 3724
 				$_note = $note;
3725 3725
 			}
3726 3726
 
3727
-			$this->set_status( 'publish',$_note );
3727
+			$this->set_status('publish', $_note);
3728 3728
 
3729 3729
 		}
3730 3730
 
3731 3731
 		// Set checkout mode.
3732
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3733
-		$this->set_mode( $mode );
3732
+		$mode = wpinv_is_test_mode($this->get_gateway()) ? 'test' : 'live';
3733
+		$this->set_mode($mode);
3734 3734
 
3735 3735
 		// Save the invoice.
3736 3736
         $this->save();
@@ -3756,9 +3756,9 @@  discard block
 block discarded – undo
3756 3756
      * Clears the subscription's cache.
3757 3757
      */
3758 3758
     public function clear_cache() {
3759
-		wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3760
-		wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3761
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3759
+		wp_cache_delete($this->get_key(), 'getpaid_invoice_keys_to_invoice_ids');
3760
+		wp_cache_delete($this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids');
3761
+		wp_cache_delete($this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids');
3762 3762
 	}
3763 3763
 
3764 3764
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 1 patch
Indentation   +449 added lines, -449 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,519 +15,519 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Invoice_Data_Store extends GetPaid_Data_Store_WP {
17 17
 
18
-	/**
19
-	 * Data stored in meta keys, but not considered "meta" for a discount.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $internal_meta_keys = array(
25
-		'_wpinv_subscr_profile_id',
26
-		'_wpinv_subscription_id',
27
-		'_wpinv_taxes',
28
-		'_wpinv_fees',
29
-		'_wpinv_discounts',
30
-		'_wpinv_submission_id',
31
-		'_wpinv_payment_form',
32
-		'_wpinv_is_viewed',
33
-		'wpinv_email_cc',
34
-		'wpinv_template',
35
-		'wpinv_created_via'
36
-	);
37
-
38
-	/**
39
-	 * A map of meta keys to data props.
40
-	 *
41
-	 * @since 1.0.19
42
-	 *
43
-	 * @var array
44
-	 */
45
-	protected $meta_key_to_props = array(
46
-		'_wpinv_subscr_profile_id' => 'remote_subscription_id',
47
-		'_wpinv_subscription_id'   => 'subscription_id',
48
-		'_wpinv_taxes'             => 'taxes',
49
-		'_wpinv_fees'              => 'fees',
50
-		'_wpinv_discounts'         => 'discounts',
51
-		'_wpinv_submission_id'     => 'submission_id',
52
-		'_wpinv_payment_form'      => 'payment_form',
53
-		'_wpinv_is_viewed'         => 'is_viewed',
54
-		'wpinv_email_cc'           => 'email_cc',
55
-		'wpinv_template'           => 'template',
56
-		'wpinv_created_via'        => 'created_via',
57
-	);
58
-
59
-	/**
60
-	 * A map of database fields to data props.
61
-	 *
62
-	 * @since 1.0.19
63
-	 *
64
-	 * @var array
65
-	 */
66
-	protected $database_fields_to_props = array(
67
-		'post_id'            => 'id',
68
-		'number'             => 'number',
69
-		'currency'           => 'currency',
70
-		'key'                => 'key',
71
-		'type'               => 'type',
72
-		'mode'               => 'mode',
73
-		'user_ip'            => 'user_ip',
74
-		'first_name'         => 'first_name',
75
-		'last_name'          => 'last_name',
76
-		'address'            => 'address',
77
-		'city'               => 'city',
78
-		'state'              => 'state',
79
-		'country'            => 'country',
80
-		'zip'                => 'zip',
81
-		'zip'                => 'zip',
82
-		'adddress_confirmed' => 'address_confirmed',
83
-		'gateway'            => 'gateway',
84
-		'transaction_id'     => 'transaction_id',
85
-		'currency'           => 'currency',
86
-		'subtotal'           => 'subtotal',
87
-		'tax'                => 'total_tax',
88
-		'fees_total'         => 'total_fees',
89
-		'discount'           => 'total_discount',
90
-		'total'              => 'total',
91
-		'discount_code'      => 'discount_code',
92
-		'disable_taxes'      => 'disable_taxes',
93
-		'due_date'           => 'due_date',
94
-		'completed_date'     => 'completed_date',
95
-		'company'            => 'company',
96
-		'vat_number'         => 'vat_number',
97
-		'vat_rate'           => 'vat_rate',
98
-	);
99
-
100
-	/*
18
+    /**
19
+     * Data stored in meta keys, but not considered "meta" for a discount.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $internal_meta_keys = array(
25
+        '_wpinv_subscr_profile_id',
26
+        '_wpinv_subscription_id',
27
+        '_wpinv_taxes',
28
+        '_wpinv_fees',
29
+        '_wpinv_discounts',
30
+        '_wpinv_submission_id',
31
+        '_wpinv_payment_form',
32
+        '_wpinv_is_viewed',
33
+        'wpinv_email_cc',
34
+        'wpinv_template',
35
+        'wpinv_created_via'
36
+    );
37
+
38
+    /**
39
+     * A map of meta keys to data props.
40
+     *
41
+     * @since 1.0.19
42
+     *
43
+     * @var array
44
+     */
45
+    protected $meta_key_to_props = array(
46
+        '_wpinv_subscr_profile_id' => 'remote_subscription_id',
47
+        '_wpinv_subscription_id'   => 'subscription_id',
48
+        '_wpinv_taxes'             => 'taxes',
49
+        '_wpinv_fees'              => 'fees',
50
+        '_wpinv_discounts'         => 'discounts',
51
+        '_wpinv_submission_id'     => 'submission_id',
52
+        '_wpinv_payment_form'      => 'payment_form',
53
+        '_wpinv_is_viewed'         => 'is_viewed',
54
+        'wpinv_email_cc'           => 'email_cc',
55
+        'wpinv_template'           => 'template',
56
+        'wpinv_created_via'        => 'created_via',
57
+    );
58
+
59
+    /**
60
+     * A map of database fields to data props.
61
+     *
62
+     * @since 1.0.19
63
+     *
64
+     * @var array
65
+     */
66
+    protected $database_fields_to_props = array(
67
+        'post_id'            => 'id',
68
+        'number'             => 'number',
69
+        'currency'           => 'currency',
70
+        'key'                => 'key',
71
+        'type'               => 'type',
72
+        'mode'               => 'mode',
73
+        'user_ip'            => 'user_ip',
74
+        'first_name'         => 'first_name',
75
+        'last_name'          => 'last_name',
76
+        'address'            => 'address',
77
+        'city'               => 'city',
78
+        'state'              => 'state',
79
+        'country'            => 'country',
80
+        'zip'                => 'zip',
81
+        'zip'                => 'zip',
82
+        'adddress_confirmed' => 'address_confirmed',
83
+        'gateway'            => 'gateway',
84
+        'transaction_id'     => 'transaction_id',
85
+        'currency'           => 'currency',
86
+        'subtotal'           => 'subtotal',
87
+        'tax'                => 'total_tax',
88
+        'fees_total'         => 'total_fees',
89
+        'discount'           => 'total_discount',
90
+        'total'              => 'total',
91
+        'discount_code'      => 'discount_code',
92
+        'disable_taxes'      => 'disable_taxes',
93
+        'due_date'           => 'due_date',
94
+        'completed_date'     => 'completed_date',
95
+        'company'            => 'company',
96
+        'vat_number'         => 'vat_number',
97
+        'vat_rate'           => 'vat_rate',
98
+    );
99
+
100
+    /*
101 101
 	|--------------------------------------------------------------------------
102 102
 	| CRUD Methods
103 103
 	|--------------------------------------------------------------------------
104 104
 	*/
105 105
 
106
-	/**
107
-	 * Method to create a new invoice in the database.
108
-	 *
109
-	 * @param WPInv_Invoice $invoice Invoice object.
110
-	 */
111
-	public function create( &$invoice ) {
112
-		$invoice->set_version( WPINV_VERSION );
113
-		$invoice->set_date_created( current_time('mysql') );
114
-
115
-		// Create a new post.
116
-		$id = wp_insert_post(
117
-			apply_filters(
118
-				'getpaid_new_invoice_data',
119
-				array(
120
-					'post_date'     => $invoice->get_date_created( 'edit' ),
121
-					'post_type'     => $invoice->get_post_type( 'edit' ),
122
-					'post_status'   => $this->get_post_status( $invoice ),
123
-					'ping_status'   => 'closed',
124
-					'post_author'   => $invoice->get_user_id( 'edit' ),
125
-					'post_title'    => $invoice->get_title( 'edit' ),
126
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
127
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
128
-				)
129
-			),
130
-			true
131
-		);
132
-
133
-		if ( $id && ! is_wp_error( $id ) ) {
134
-
135
-			// Update the new id and regenerate a title.
136
-			$invoice->set_id( $id );
137
-
138
-			$invoice->maybe_set_number();
139
-
140
-			wp_update_post(
141
-				array(
142
-					'ID'         => $invoice->get_id(),
143
-					'post_title' => $invoice->get_number( 'edit' ),
144
-					'post_name'  => $invoice->get_path( 'edit' )
145
-				)
146
-			);
147
-
148
-			// Save special fields and items.
149
-			$this->save_special_fields( $invoice );
150
-			$this->save_items( $invoice );
151
-
152
-			// Update meta data.
153
-			$this->update_post_meta( $invoice );
154
-			$invoice->save_meta_data();
155
-
156
-			// Apply changes.
157
-			$invoice->apply_changes();
158
-			$this->clear_caches( $invoice );
159
-
160
-			// Fires after a new invoice is created.
161
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
162
-			return true;
163
-		}
164
-
165
-		if ( is_wp_error( $id ) ) {
166
-			$invoice->last_error = $id->get_error_message();
167
-		}
168
-
169
-		return false;
170
-	}
171
-
172
-	/**
173
-	 * Method to read an invoice from the database.
174
-	 *
175
-	 * @param WPInv_Invoice $invoice Invoice object.
176
-	 *
177
-	 */
178
-	public function read( &$invoice ) {
179
-
180
-		$invoice->set_defaults();
181
-		$invoice_object = get_post( $invoice->get_id() );
182
-
183
-		if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
184
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
185
-			$invoice->set_id( 0 );
186
-			return false;
187
-		}
188
-
189
-		$invoice->set_props(
190
-			array(
191
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
192
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
193
-				'status'        => $invoice_object->post_status,
194
-				'author'        => $invoice_object->post_author,
195
-				'description'   => $invoice_object->post_excerpt,
196
-				'parent_id'     => $invoice_object->post_parent,
197
-				'name'          => $invoice_object->post_title,
198
-				'path'          => $invoice_object->post_name,
199
-				'post_type'     => $invoice_object->post_type,
200
-			)
201
-		);
202
-
203
-		$invoice->set_type( $invoice_object->post_type );
204
-
205
-		$this->read_object_data( $invoice, $invoice_object );
206
-		$this->add_special_fields( $invoice );
207
-		$this->add_items( $invoice );
208
-		$invoice->read_meta_data();
209
-		$invoice->set_object_read( true );
210
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
211
-
212
-	}
213
-
214
-	/**
215
-	 * Method to update an invoice in the database.
216
-	 *
217
-	 * @param WPInv_Invoice $invoice Invoice object.
218
-	 */
219
-	public function update( &$invoice ) {
220
-		$invoice->save_meta_data();
221
-		$invoice->set_version( WPINV_VERSION );
222
-
223
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
224
-			$invoice->set_date_created(  current_time('mysql') );
225
-		}
226
-
227
-		// Ensure both the key and number are set.
228
-		$invoice->get_path();
229
-
230
-		// Grab the current status so we can compare.
231
-		$previous_status = get_post_status( $invoice->get_id() );
232
-
233
-		$changes = $invoice->get_changes();
234
-
235
-		// Only update the post when the post data changes.
236
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
237
-			$post_data = array(
238
-				'post_date'         => $invoice->get_date_created( 'edit' ),
239
-				'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
240
-				'post_status'       => $invoice->get_status( 'edit' ),
241
-				'post_title'        => $invoice->get_name( 'edit' ),
242
-				'post_author'       => $invoice->get_user_id( 'edit' ),
243
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
244
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
245
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
246
-				'post_name'         => $invoice->get_path( 'edit' ),
247
-				'post_type'         => $invoice->get_post_type( 'edit' ),
248
-			);
249
-
250
-			/**
251
-			 * When updating this object, to prevent infinite loops, use $wpdb
252
-			 * to update data, since wp_update_post spawns more calls to the
253
-			 * save_post action.
254
-			 *
255
-			 * This ensures hooks are fired by either WP itself (admin screen save),
256
-			 * or an update purely from CRUD.
257
-			 */
258
-			if ( doing_action( 'save_post' ) ) {
259
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
260
-				clean_post_cache( $invoice->get_id() );
261
-			} else {
262
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
263
-			}
264
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
265
-		}
266
-
267
-		// Update meta data.
268
-		$this->update_post_meta( $invoice );
269
-
270
-		// Save special fields and items.
271
-		$this->save_special_fields( $invoice );
272
-		$this->save_items( $invoice );
273
-
274
-		// Apply the changes.
275
-		$invoice->apply_changes();
276
-
277
-		// Clear caches.
278
-		$this->clear_caches( $invoice );
279
-
280
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
281
-		$new_status = $invoice->get_status( 'edit' );
282
-
283
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
284
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
285
-		} else {
286
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
287
-		}
288
-
289
-	}
290
-
291
-	/*
106
+    /**
107
+     * Method to create a new invoice in the database.
108
+     *
109
+     * @param WPInv_Invoice $invoice Invoice object.
110
+     */
111
+    public function create( &$invoice ) {
112
+        $invoice->set_version( WPINV_VERSION );
113
+        $invoice->set_date_created( current_time('mysql') );
114
+
115
+        // Create a new post.
116
+        $id = wp_insert_post(
117
+            apply_filters(
118
+                'getpaid_new_invoice_data',
119
+                array(
120
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
121
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
122
+                    'post_status'   => $this->get_post_status( $invoice ),
123
+                    'ping_status'   => 'closed',
124
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
125
+                    'post_title'    => $invoice->get_title( 'edit' ),
126
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
127
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
128
+                )
129
+            ),
130
+            true
131
+        );
132
+
133
+        if ( $id && ! is_wp_error( $id ) ) {
134
+
135
+            // Update the new id and regenerate a title.
136
+            $invoice->set_id( $id );
137
+
138
+            $invoice->maybe_set_number();
139
+
140
+            wp_update_post(
141
+                array(
142
+                    'ID'         => $invoice->get_id(),
143
+                    'post_title' => $invoice->get_number( 'edit' ),
144
+                    'post_name'  => $invoice->get_path( 'edit' )
145
+                )
146
+            );
147
+
148
+            // Save special fields and items.
149
+            $this->save_special_fields( $invoice );
150
+            $this->save_items( $invoice );
151
+
152
+            // Update meta data.
153
+            $this->update_post_meta( $invoice );
154
+            $invoice->save_meta_data();
155
+
156
+            // Apply changes.
157
+            $invoice->apply_changes();
158
+            $this->clear_caches( $invoice );
159
+
160
+            // Fires after a new invoice is created.
161
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
162
+            return true;
163
+        }
164
+
165
+        if ( is_wp_error( $id ) ) {
166
+            $invoice->last_error = $id->get_error_message();
167
+        }
168
+
169
+        return false;
170
+    }
171
+
172
+    /**
173
+     * Method to read an invoice from the database.
174
+     *
175
+     * @param WPInv_Invoice $invoice Invoice object.
176
+     *
177
+     */
178
+    public function read( &$invoice ) {
179
+
180
+        $invoice->set_defaults();
181
+        $invoice_object = get_post( $invoice->get_id() );
182
+
183
+        if ( ! $invoice->get_id() || ! $invoice_object || ! getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
184
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
185
+            $invoice->set_id( 0 );
186
+            return false;
187
+        }
188
+
189
+        $invoice->set_props(
190
+            array(
191
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
192
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
193
+                'status'        => $invoice_object->post_status,
194
+                'author'        => $invoice_object->post_author,
195
+                'description'   => $invoice_object->post_excerpt,
196
+                'parent_id'     => $invoice_object->post_parent,
197
+                'name'          => $invoice_object->post_title,
198
+                'path'          => $invoice_object->post_name,
199
+                'post_type'     => $invoice_object->post_type,
200
+            )
201
+        );
202
+
203
+        $invoice->set_type( $invoice_object->post_type );
204
+
205
+        $this->read_object_data( $invoice, $invoice_object );
206
+        $this->add_special_fields( $invoice );
207
+        $this->add_items( $invoice );
208
+        $invoice->read_meta_data();
209
+        $invoice->set_object_read( true );
210
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice );
211
+
212
+    }
213
+
214
+    /**
215
+     * Method to update an invoice in the database.
216
+     *
217
+     * @param WPInv_Invoice $invoice Invoice object.
218
+     */
219
+    public function update( &$invoice ) {
220
+        $invoice->save_meta_data();
221
+        $invoice->set_version( WPINV_VERSION );
222
+
223
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
224
+            $invoice->set_date_created(  current_time('mysql') );
225
+        }
226
+
227
+        // Ensure both the key and number are set.
228
+        $invoice->get_path();
229
+
230
+        // Grab the current status so we can compare.
231
+        $previous_status = get_post_status( $invoice->get_id() );
232
+
233
+        $changes = $invoice->get_changes();
234
+
235
+        // Only update the post when the post data changes.
236
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
237
+            $post_data = array(
238
+                'post_date'         => $invoice->get_date_created( 'edit' ),
239
+                'post_date_gmt'     => $invoice->get_date_created_gmt( 'edit' ),
240
+                'post_status'       => $invoice->get_status( 'edit' ),
241
+                'post_title'        => $invoice->get_name( 'edit' ),
242
+                'post_author'       => $invoice->get_user_id( 'edit' ),
243
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
244
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
245
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
246
+                'post_name'         => $invoice->get_path( 'edit' ),
247
+                'post_type'         => $invoice->get_post_type( 'edit' ),
248
+            );
249
+
250
+            /**
251
+             * When updating this object, to prevent infinite loops, use $wpdb
252
+             * to update data, since wp_update_post spawns more calls to the
253
+             * save_post action.
254
+             *
255
+             * This ensures hooks are fired by either WP itself (admin screen save),
256
+             * or an update purely from CRUD.
257
+             */
258
+            if ( doing_action( 'save_post' ) ) {
259
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
260
+                clean_post_cache( $invoice->get_id() );
261
+            } else {
262
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
263
+            }
264
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
265
+        }
266
+
267
+        // Update meta data.
268
+        $this->update_post_meta( $invoice );
269
+
270
+        // Save special fields and items.
271
+        $this->save_special_fields( $invoice );
272
+        $this->save_items( $invoice );
273
+
274
+        // Apply the changes.
275
+        $invoice->apply_changes();
276
+
277
+        // Clear caches.
278
+        $this->clear_caches( $invoice );
279
+
280
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
281
+        $new_status = $invoice->get_status( 'edit' );
282
+
283
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
284
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice );
285
+        } else {
286
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice );
287
+        }
288
+
289
+    }
290
+
291
+    /*
292 292
 	|--------------------------------------------------------------------------
293 293
 	| Additional Methods
294 294
 	|--------------------------------------------------------------------------
295 295
 	*/
296 296
 
297
-	/**
297
+    /**
298 298
      * Retrieves special fields and adds to the invoice.
299
-	 *
300
-	 * @param WPInv_Invoice $invoice Invoice object.
299
+     *
300
+     * @param WPInv_Invoice $invoice Invoice object.
301 301
      */
302 302
     public function add_special_fields( &$invoice ) {
303
-		global $wpdb;
303
+        global $wpdb;
304 304
 
305
-		// Maybe retrieve from the cache.
306
-		$data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
305
+        // Maybe retrieve from the cache.
306
+        $data   = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_special_fields' );
307 307
 
308
-		// If not found, retrieve from the db.
309
-		if ( false === $data ) {
310
-			$table =  $wpdb->prefix . 'getpaid_invoices';
308
+        // If not found, retrieve from the db.
309
+        if ( false === $data ) {
310
+            $table =  $wpdb->prefix . 'getpaid_invoices';
311 311
 
312
-			$data  = $wpdb->get_row(
313
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
314
-				ARRAY_A
315
-			);
312
+            $data  = $wpdb->get_row(
313
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $invoice->get_id() ),
314
+                ARRAY_A
315
+            );
316 316
 
317
-			// Update the cache with our data
318
-			wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
317
+            // Update the cache with our data
318
+            wp_cache_set( $invoice->get_id(), $data, 'getpaid_invoice_special_fields' );
319 319
 
320
-		}
320
+        }
321 321
 
322
-		// Abort if the data does not exist.
323
-		if ( empty( $data ) ) {
324
-			$invoice->set_object_read( true );
325
-			$invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
326
-			return;
327
-		}
322
+        // Abort if the data does not exist.
323
+        if ( empty( $data ) ) {
324
+            $invoice->set_object_read( true );
325
+            $invoice->set_props( wpinv_get_user_address( $invoice->get_user_id() ) );
326
+            return;
327
+        }
328 328
 
329
-		$props = array();
329
+        $props = array();
330 330
 
331
-		foreach ( $this->database_fields_to_props as $db_field => $prop ) {
331
+        foreach ( $this->database_fields_to_props as $db_field => $prop ) {
332 332
 			
333
-			if ( $db_field == 'post_id' ) {
334
-				continue;
335
-			}
336
-
337
-			$props[ $prop ] = $data[ $db_field ];
338
-		}
339
-
340
-		$invoice->set_props( $props );
341
-
342
-	}
343
-
344
-	/**
345
-	 * Gets a list of special fields that need updated based on change state
346
-	 * or if they are present in the database or not.
347
-	 *
348
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
349
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
350
-	 */
351
-	protected function get_special_fields_to_update( $invoice ) {
352
-		$fields_to_update = array();
353
-		$changed_props   = $invoice->get_changes();
354
-
355
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
356
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
357
-			if ( array_key_exists( $prop, $changed_props ) ) {
358
-				$fields_to_update[ $database_field ] = $prop;
359
-			}
360
-		}
361
-
362
-		return $fields_to_update;
363
-	}
364
-
365
-	/**
366
-	 * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
367
-	 *
368
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
369
-	 * @since 1.0.19
370
-	 */
371
-	protected function update_special_fields( &$invoice ) {
372
-		global $wpdb;
373
-
374
-		$updated_props    = array();
375
-		$fields_to_update = $this->get_special_fields_to_update( $invoice );
376
-
377
-		foreach ( $fields_to_update as $database_field => $prop ) {
378
-			$value = $invoice->{"get_$prop"}( 'edit' );
379
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
380
-			$value = is_bool( $value ) ? ( int ) $value : $value;
381
-			$updated_props[ $database_field ] = maybe_serialize( $value );
382
-		}
383
-
384
-		if ( ! empty( $updated_props ) ) {
385
-
386
-			$table = $wpdb->prefix . 'getpaid_invoices';
387
-			$wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
388
-			wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
389
-			do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
390
-
391
-		}
392
-
393
-	}
394
-
395
-	/**
396
-	 * Helper method that inserts special fields to the database.
397
-	 *
398
-	 * @param WPInv_Invoice $invoice WPInv_Invoice object.
399
-	 * @since 1.0.19
400
-	 */
401
-	protected function insert_special_fields( &$invoice ) {
402
-		global $wpdb;
403
-
404
-		$updated_props   = array();
405
-
406
-		foreach ( $this->database_fields_to_props as $database_field => $prop ) {
407
-			$value = $invoice->{"get_$prop"}( 'edit' );
408
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
409
-			$value = is_bool( $value ) ? ( int ) $value : $value;
410
-			$updated_props[ $database_field ] = maybe_serialize( $value );
411
-		}
412
-
413
-		$table = $wpdb->prefix . 'getpaid_invoices';
414
-		$wpdb->insert( $table, $updated_props );
415
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
416
-		do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
417
-
418
-	}
419
-
420
-	/**
333
+            if ( $db_field == 'post_id' ) {
334
+                continue;
335
+            }
336
+
337
+            $props[ $prop ] = $data[ $db_field ];
338
+        }
339
+
340
+        $invoice->set_props( $props );
341
+
342
+    }
343
+
344
+    /**
345
+     * Gets a list of special fields that need updated based on change state
346
+     * or if they are present in the database or not.
347
+     *
348
+     * @param  WPInv_Invoice $invoice       The Invoice object.
349
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
350
+     */
351
+    protected function get_special_fields_to_update( $invoice ) {
352
+        $fields_to_update = array();
353
+        $changed_props   = $invoice->get_changes();
354
+
355
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
356
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
357
+            if ( array_key_exists( $prop, $changed_props ) ) {
358
+                $fields_to_update[ $database_field ] = $prop;
359
+            }
360
+        }
361
+
362
+        return $fields_to_update;
363
+    }
364
+
365
+    /**
366
+     * Helper method that updates all the database fields for an invoice based on it's settings in the WPInv_Invoice class.
367
+     *
368
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
369
+     * @since 1.0.19
370
+     */
371
+    protected function update_special_fields( &$invoice ) {
372
+        global $wpdb;
373
+
374
+        $updated_props    = array();
375
+        $fields_to_update = $this->get_special_fields_to_update( $invoice );
376
+
377
+        foreach ( $fields_to_update as $database_field => $prop ) {
378
+            $value = $invoice->{"get_$prop"}( 'edit' );
379
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
380
+            $value = is_bool( $value ) ? ( int ) $value : $value;
381
+            $updated_props[ $database_field ] = maybe_serialize( $value );
382
+        }
383
+
384
+        if ( ! empty( $updated_props ) ) {
385
+
386
+            $table = $wpdb->prefix . 'getpaid_invoices';
387
+            $wpdb->update( $table, $updated_props, array( 'post_id' => $invoice->get_id() ) );
388
+            wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
389
+            do_action( "getpaid_invoice_update_database_fields", $invoice, $updated_props );
390
+
391
+        }
392
+
393
+    }
394
+
395
+    /**
396
+     * Helper method that inserts special fields to the database.
397
+     *
398
+     * @param WPInv_Invoice $invoice WPInv_Invoice object.
399
+     * @since 1.0.19
400
+     */
401
+    protected function insert_special_fields( &$invoice ) {
402
+        global $wpdb;
403
+
404
+        $updated_props   = array();
405
+
406
+        foreach ( $this->database_fields_to_props as $database_field => $prop ) {
407
+            $value = $invoice->{"get_$prop"}( 'edit' );
408
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
409
+            $value = is_bool( $value ) ? ( int ) $value : $value;
410
+            $updated_props[ $database_field ] = maybe_serialize( $value );
411
+        }
412
+
413
+        $table = $wpdb->prefix . 'getpaid_invoices';
414
+        $wpdb->insert( $table, $updated_props );
415
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_special_fields' );
416
+        do_action( "getpaid_invoice_insert_database_fields", $invoice, $updated_props );
417
+
418
+    }
419
+
420
+    /**
421 421
      * Saves all special fields.
422
-	 *
423
-	 * @param WPInv_Invoice $invoice Invoice object.
422
+     *
423
+     * @param WPInv_Invoice $invoice Invoice object.
424 424
      */
425 425
     public function save_special_fields( & $invoice ) {
426
-		global $wpdb;
426
+        global $wpdb;
427 427
 
428
-		// The invoices table.
429
-		$table = $wpdb->prefix . 'getpaid_invoices';
430
-		$id    = (int) $invoice->get_id();
431
-		$invoice->maybe_set_key();
428
+        // The invoices table.
429
+        $table = $wpdb->prefix . 'getpaid_invoices';
430
+        $id    = (int) $invoice->get_id();
431
+        $invoice->maybe_set_key();
432 432
 
433
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
433
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
434 434
 
435
-			$this->update_special_fields( $invoice );
435
+            $this->update_special_fields( $invoice );
436 436
 
437
-		} else {
437
+        } else {
438 438
 
439
-			$this->insert_special_fields( $invoice );
439
+            $this->insert_special_fields( $invoice );
440 440
 
441
-		}
441
+        }
442 442
 
443
-	}
443
+    }
444 444
 
445
-	/**
445
+    /**
446 446
      * Set's up cart details.
447
-	 *
448
-	 * @param WPInv_Invoice $invoice Invoice object.
447
+     *
448
+     * @param WPInv_Invoice $invoice Invoice object.
449 449
      */
450 450
     public function add_items( &$invoice ) {
451
-		global $wpdb;
451
+        global $wpdb;
452 452
 
453
-		// Maybe retrieve from the cache.
454
-		$items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
453
+        // Maybe retrieve from the cache.
454
+        $items = wp_cache_get( $invoice->get_id(), 'getpaid_invoice_cart_details' );
455 455
 
456
-		// If not found, retrieve from the db.
457
-		if ( false === $items ) {
458
-			$table =  $wpdb->prefix . 'getpaid_invoice_items';
456
+        // If not found, retrieve from the db.
457
+        if ( false === $items ) {
458
+            $table =  $wpdb->prefix . 'getpaid_invoice_items';
459 459
 
460
-			$items = $wpdb->get_results(
461
-				$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
-			);
460
+            $items = $wpdb->get_results(
461
+                $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $invoice->get_id() )
462
+            );
463 463
 
464
-			// Update the cache with our data
465
-			wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
464
+            // Update the cache with our data
465
+            wp_cache_set( $invoice->get_id(), $items, 'getpaid_invoice_cart_details' );
466 466
 
467
-		}
467
+        }
468 468
 
469
-		// Abort if no items found.
469
+        // Abort if no items found.
470 470
         if ( empty( $items ) ) {
471 471
             return;
472
-		}
472
+        }
473 473
 
474
-		foreach ( $items as $item_data ) {
475
-			$item = new GetPaid_Form_Item( $item_data->item_id );
474
+        foreach ( $items as $item_data ) {
475
+            $item = new GetPaid_Form_Item( $item_data->item_id );
476 476
 
477
-			// Set item data.
478
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
479
-			$item->item_discount = wpinv_sanitize_amount( $item_data->discount );
480
-			$item->set_name( $item_data->item_name );
481
-			$item->set_description( $item_data->item_description );
482
-			$item->set_price( $item_data->item_price );
483
-			$item->set_quantity( $item_data->quantity );
484
-			$item->set_item_meta( $item_data->meta );
477
+            // Set item data.
478
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
479
+            $item->item_discount = wpinv_sanitize_amount( $item_data->discount );
480
+            $item->set_name( $item_data->item_name );
481
+            $item->set_description( $item_data->item_description );
482
+            $item->set_price( $item_data->item_price );
483
+            $item->set_quantity( $item_data->quantity );
484
+            $item->set_item_meta( $item_data->meta );
485 485
 
486
-			$invoice->add_item( $item );
487
-		}
486
+            $invoice->add_item( $item );
487
+        }
488 488
 
489
-	}
489
+    }
490 490
 
491
-	/**
491
+    /**
492 492
      * Saves cart details.
493
-	 *
494
-	 * @param WPInv_Invoice $invoice Invoice object.
493
+     *
494
+     * @param WPInv_Invoice $invoice Invoice object.
495 495
      */
496 496
     public function save_items( $invoice ) {
497 497
 
498
-		// Delete previously existing items.
499
-		$this->delete_items( $invoice );
498
+        // Delete previously existing items.
499
+        $this->delete_items( $invoice );
500 500
 
501
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
501
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
502 502
 
503
-		foreach ( $invoice->get_cart_details() as $item_data ) {
504
-			$item_data = array_map( 'maybe_serialize', $item_data );
505
-			$GLOBALS['wpdb']->insert( $table, $item_data );
506
-		}
503
+        foreach ( $invoice->get_cart_details() as $item_data ) {
504
+            $item_data = array_map( 'maybe_serialize', $item_data );
505
+            $GLOBALS['wpdb']->insert( $table, $item_data );
506
+        }
507 507
 
508
-		wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
509
-		do_action( "getpaid_invoice_save_items", $invoice );
508
+        wp_cache_delete( $invoice->get_id(), 'getpaid_invoice_cart_details' );
509
+        do_action( "getpaid_invoice_save_items", $invoice );
510 510
 
511
-	}
511
+    }
512 512
 
513
-	/**
513
+    /**
514 514
      * Deletes an invoice's cart details from the database.
515
-	 *
516
-	 * @param WPInv_Invoice $invoice Invoice object.
515
+     *
516
+     * @param WPInv_Invoice $invoice Invoice object.
517 517
      */
518 518
     public function delete_items( $invoice ) {
519
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
520
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
-	}
519
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
520
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
521
+    }
522 522
 
523
-	/**
523
+    /**
524 524
      * Deletes an invoice's special fields from the database.
525
-	 *
526
-	 * @param WPInv_Invoice $invoice Invoice object.
525
+     *
526
+     * @param WPInv_Invoice $invoice Invoice object.
527 527
      */
528 528
     public function delete_special_fields( $invoice ) {
529
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
530
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
529
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoices';
530
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->get_id() ) );
531 531
     }
532 532
 
533 533
 }
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +264 added lines, -264 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves an item by it's ID.
@@ -14,9 +14,9 @@  discard block
 block discarded – undo
14 14
  * @param int the item ID to retrieve.
15 15
  * @return WPInv_Item|false
16 16
  */
17
-function wpinv_get_item_by_id( $id ) {
18
-    $item = wpinv_get_item( $id );
19
-    return empty( $item ) || $id != $item->get_id() ? false : $item;
17
+function wpinv_get_item_by_id($id) {
18
+    $item = wpinv_get_item($id);
19
+    return empty($item) || $id != $item->get_id() ? false : $item;
20 20
 }
21 21
 
22 22
 /**
@@ -24,14 +24,14 @@  discard block
 block discarded – undo
24 24
  * 
25 25
  * @return WPInv_Item|false
26 26
  */
27
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
27
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
28 28
 
29
-    if ( 'id' == strtolower( $field ) ) {
30
-        return wpinv_get_item_by_id( $field );
29
+    if ('id' == strtolower($field)) {
30
+        return wpinv_get_item_by_id($field);
31 31
     }
32 32
 
33
-    $id = WPInv_Item::get_item_id_by_field( $value, strtolower( $field ), $type );
34
-    return $id ? wpinv_get_item( $id ) : false;
33
+    $id = WPInv_Item::get_item_id_by_field($value, strtolower($field), $type);
34
+    return $id ? wpinv_get_item($id) : false;
35 35
 
36 36
 }
37 37
 
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
  * @param int|WPInv_Item the item to retrieve.
42 42
  * @return WPInv_Item|false
43 43
  */
44
-function wpinv_get_item( $item = 0 ) {
44
+function wpinv_get_item($item = 0) {
45 45
     
46
-    if ( empty( $item ) ) {
46
+    if (empty($item)) {
47 47
         return false;
48 48
     }
49 49
 
50
-    $item = new WPInv_Item( $item );
50
+    $item = new WPInv_Item($item);
51 51
     return $item->get_id() ? $item : false;
52 52
 
53 53
 }
54 54
 
55
-function wpinv_get_all_items( $args = array() ) {
55
+function wpinv_get_all_items($args = array()) {
56 56
 
57
-    $args = wp_parse_args( $args, array(
58
-        'status'         => array( 'publish' ),
59
-        'limit'          => get_option( 'posts_per_page' ),
57
+    $args = wp_parse_args($args, array(
58
+        'status'         => array('publish'),
59
+        'limit'          => get_option('posts_per_page'),
60 60
         'page'           => 1,
61 61
         'exclude'        => array(),
62 62
         'orderby'        => 'date',
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         'meta_query'     => array(),
66 66
         'return'         => 'objects',
67 67
         'paginate'       => false,
68
-    ) );
68
+    ));
69 69
 
70 70
     $wp_query_args = array(
71 71
         'post_type'      => 'wpi_item',
@@ -75,26 +75,26 @@  discard block
 block discarded – undo
75 75
         'fields'         => 'ids',
76 76
         'orderby'        => $args['orderby'],
77 77
         'order'          => $args['order'],
78
-        'paged'          => absint( $args['page'] ),
78
+        'paged'          => absint($args['page']),
79 79
     );
80 80
 
81
-    if ( ! empty( $args['exclude'] ) ) {
82
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
81
+    if (!empty($args['exclude'])) {
82
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
83 83
     }
84 84
 
85
-    if ( ! $args['paginate' ] ) {
85
+    if (!$args['paginate']) {
86 86
         $wp_query_args['no_found_rows'] = true;
87 87
     }
88 88
 
89
-    if ( ! empty( $args['search'] ) ) {
89
+    if (!empty($args['search'])) {
90 90
         $wp_query_args['s'] = $args['search'];
91 91
     }
92 92
 
93
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
94
-        $types = wpinv_parse_list( $args['type'] );
93
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
94
+        $types = wpinv_parse_list($args['type']);
95 95
         $wp_query_args['meta_query'][] = array(
96 96
             'key'     => '_wpinv_type',
97
-            'value'   => implode( ',', $types ),
97
+            'value'   => implode(',', $types),
98 98
             'compare' => 'IN',
99 99
         );
100 100
     }
@@ -102,17 +102,17 @@  discard block
 block discarded – undo
102 102
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
103 103
 
104 104
     // Get results.
105
-    $items = new WP_Query( $wp_query_args );
105
+    $items = new WP_Query($wp_query_args);
106 106
 
107
-    if ( 'objects' === $args['return'] ) {
108
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
109
-    } elseif ( 'self' === $args['return'] ) {
107
+    if ('objects' === $args['return']) {
108
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
109
+    } elseif ('self' === $args['return']) {
110 110
         return $items;
111 111
     } else {
112 112
         $return = $items->posts;
113 113
     }
114 114
 
115
-    if ( $args['paginate' ] ) {
115
+    if ($args['paginate']) {
116 116
         return (object) array(
117 117
             'items'      => $return,
118 118
             'total'         => $items->found_posts,
@@ -124,12 +124,12 @@  discard block
 block discarded – undo
124 124
 
125 125
 }
126 126
 
127
-function wpinv_is_free_item( $item_id = 0 ) {
128
-    if( empty( $item_id ) ) {
127
+function wpinv_is_free_item($item_id = 0) {
128
+    if (empty($item_id)) {
129 129
         return false;
130 130
     }
131 131
 
132
-    $item = new WPInv_Item( $item_id );
132
+    $item = new WPInv_Item($item_id);
133 133
     
134 134
     return $item->is_free();
135 135
 }
@@ -139,128 +139,128 @@  discard block
 block discarded – undo
139 139
  * 
140 140
  * @param WP_Post|WPInv_Item|Int $item The item to check for.
141 141
  */
142
-function wpinv_item_is_editable( $item = 0 ) {
142
+function wpinv_item_is_editable($item = 0) {
143 143
 
144 144
     // Fetch the item.
145
-    $item = new WPInv_Item( $item );
145
+    $item = new WPInv_Item($item);
146 146
 
147 147
     // Check if it is editable.
148 148
     return $item->is_editable();
149 149
 }
150 150
 
151
-function wpinv_get_item_price( $item_id = 0 ) {
152
-    if( empty( $item_id ) ) {
151
+function wpinv_get_item_price($item_id = 0) {
152
+    if (empty($item_id)) {
153 153
         return false;
154 154
     }
155 155
 
156
-    $item = new WPInv_Item( $item_id );
156
+    $item = new WPInv_Item($item_id);
157 157
     
158 158
     return $item->get_price();
159 159
 }
160 160
 
161
-function wpinv_is_recurring_item( $item_id = 0 ) {
162
-    if( empty( $item_id ) ) {
161
+function wpinv_is_recurring_item($item_id = 0) {
162
+    if (empty($item_id)) {
163 163
         return false;
164 164
     }
165 165
 
166
-    $item = new WPInv_Item( $item_id );
166
+    $item = new WPInv_Item($item_id);
167 167
     
168 168
     return $item->is_recurring();
169 169
 }
170 170
 
171
-function wpinv_item_price( $item_id = 0 ) {
172
-    if( empty( $item_id ) ) {
171
+function wpinv_item_price($item_id = 0) {
172
+    if (empty($item_id)) {
173 173
         return false;
174 174
     }
175 175
 
176
-    $price = wpinv_get_item_price( $item_id );
177
-    $price = wpinv_price( wpinv_format_amount( $price ) );
176
+    $price = wpinv_get_item_price($item_id);
177
+    $price = wpinv_price(wpinv_format_amount($price));
178 178
     
179
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
179
+    return apply_filters('wpinv_item_price', $price, $item_id);
180 180
 }
181 181
 
182
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
183
-    if ( empty( $item_id ) ) {
182
+function wpinv_item_show_price($item_id = 0, $echo = true) {
183
+    if (empty($item_id)) {
184 184
         $item_id = get_the_ID();
185 185
     }
186 186
 
187
-    $price = wpinv_item_price( $item_id );
187
+    $price = wpinv_item_price($item_id);
188 188
 
189
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
189
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
190 190
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
191
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
191
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
192 192
 
193
-    if ( $echo ) {
193
+    if ($echo) {
194 194
         echo $formatted_price;
195 195
     } else {
196 196
         return $formatted_price;
197 197
     }
198 198
 }
199 199
 
200
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
201
-    if ( is_null( $amount_override ) ) {
202
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
200
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
201
+    if (is_null($amount_override)) {
202
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
203 203
     } else {
204 204
         $original_price = $amount_override;
205 205
     }
206 206
     
207 207
     $price = $original_price;
208 208
 
209
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
209
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
210 210
 }
211 211
 
212
-function wpinv_item_custom_singular_name( $item_id ) {
213
-    if( empty( $item_id ) ) {
212
+function wpinv_item_custom_singular_name($item_id) {
213
+    if (empty($item_id)) {
214 214
         return false;
215 215
     }
216 216
 
217
-    $item = new WPInv_Item( $item_id );
217
+    $item = new WPInv_Item($item_id);
218 218
     
219 219
     return $item->get_custom_singular_name();
220 220
 }
221 221
 
222 222
 function wpinv_get_item_types() {
223 223
     $item_types = array(
224
-            'custom'    => __( 'Standard', 'invoicing' ),
225
-            'fee'       => __( 'Fee', 'invoicing' ),
224
+            'custom'    => __('Standard', 'invoicing'),
225
+            'fee'       => __('Fee', 'invoicing'),
226 226
         );
227
-    return apply_filters( 'wpinv_get_item_types', $item_types );
227
+    return apply_filters('wpinv_get_item_types', $item_types);
228 228
 }
229 229
 
230 230
 function wpinv_item_types() {
231 231
     $item_types = wpinv_get_item_types();
232 232
     
233
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
233
+    return (!empty($item_types) ? array_keys($item_types) : array());
234 234
 }
235 235
 
236
-function wpinv_get_item_type( $item_id ) {
237
-    if( empty( $item_id ) ) {
236
+function wpinv_get_item_type($item_id) {
237
+    if (empty($item_id)) {
238 238
         return false;
239 239
     }
240 240
 
241
-    $item = new WPInv_Item( $item_id );
241
+    $item = new WPInv_Item($item_id);
242 242
     
243 243
     return $item->get_type();
244 244
 }
245 245
 
246
-function wpinv_item_type( $item_id ) {
246
+function wpinv_item_type($item_id) {
247 247
     $item_types = wpinv_get_item_types();
248 248
     
249
-    $item_type = wpinv_get_item_type( $item_id );
249
+    $item_type = wpinv_get_item_type($item_id);
250 250
     
251
-    if ( empty( $item_type ) ) {
251
+    if (empty($item_type)) {
252 252
         $item_type = '-';
253 253
     }
254 254
     
255
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
255
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
256 256
 
257
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
257
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
258 258
 }
259 259
 
260
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
260
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
@@ -269,278 +269,278 @@  discard block
 block discarded – undo
269 269
         'log_type'		=> 'wpi_item'
270 270
     );
271 271
 
272
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
272
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
273 273
 
274 274
     $log_meta = array(
275 275
         'user_info'	=> $user_info,
276 276
         'user_id'	=> $user_id,
277
-        'file_id'	=> (int)$file_id,
277
+        'file_id'	=> (int) $file_id,
278 278
         'ip'		=> $ip,
279 279
         'invoice_id'=> $invoice_id,
280 280
     );
281 281
 
282
-    $wpinv_logs->insert_log( $log_data, $log_meta );
282
+    $wpinv_logs->insert_log($log_data, $log_meta);
283 283
 }
284 284
 
285
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
286
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
285
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
286
+    if ('wpi_item' !== get_post_type($item_id))
287 287
         return;
288 288
 
289 289
     global $wpinv_logs;
290 290
     
291
-    if ( empty( $wpinv_logs ) ) {
291
+    if (empty($wpinv_logs)) {
292 292
         return false;
293 293
     }
294 294
 
295 295
     // Remove all log entries related to this item
296
-    $wpinv_logs->delete_logs( $item_id );
296
+    $wpinv_logs->delete_logs($item_id);
297 297
 }
298
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
298
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
299 299
 
300
-function wpinv_get_random_item( $post_ids = true ) {
301
-    wpinv_get_random_items( 1, $post_ids );
300
+function wpinv_get_random_item($post_ids = true) {
301
+    wpinv_get_random_items(1, $post_ids);
302 302
 }
303 303
 
304
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
305
-    if ( $post_ids ) {
306
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
304
+function wpinv_get_random_items($num = 3, $post_ids = true) {
305
+    if ($post_ids) {
306
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
307 307
     } else {
308
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
308
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
309 309
     }
310 310
     
311
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
311
+    $args = apply_filters('wpinv_get_random_items', $args);
312 312
     
313
-    return get_posts( $args );
313
+    return get_posts($args);
314 314
 }
315 315
 
316
-function wpinv_get_item_token( $url = '' ) {
316
+function wpinv_get_item_token($url = '') {
317 317
     $args    = array();
318
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
319
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
318
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
319
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
320 320
 
321
-    $parts   = parse_url( $url );
321
+    $parts   = parse_url($url);
322 322
     $options = array();
323 323
 
324
-    if ( isset( $parts['query'] ) ) {
325
-        wp_parse_str( $parts['query'], $query_args );
324
+    if (isset($parts['query'])) {
325
+        wp_parse_str($parts['query'], $query_args);
326 326
 
327
-        if ( ! empty( $query_args['o'] ) ) {
328
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
327
+        if (!empty($query_args['o'])) {
328
+            $options = explode(':', rawurldecode($query_args['o']));
329 329
 
330
-            if ( in_array( 'ip', $options ) ) {
330
+            if (in_array('ip', $options)) {
331 331
                 $args['ip'] = wpinv_get_ip();
332 332
             }
333 333
 
334
-            if ( in_array( 'ua', $options ) ) {
334
+            if (in_array('ua', $options)) {
335 335
                 $ua = wpinv_get_user_agent();
336
-                $args['user_agent'] = rawurlencode( $ua );
336
+                $args['user_agent'] = rawurlencode($ua);
337 337
             }
338 338
         }
339 339
     }
340 340
 
341
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
341
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
342 342
 
343 343
     $args['secret'] = $secret;
344 344
     $args['token']  = false;
345 345
 
346
-    $url   = add_query_arg( $args, $url );
347
-    $parts = parse_url( $url );
346
+    $url   = add_query_arg($args, $url);
347
+    $parts = parse_url($url);
348 348
 
349
-    if ( ! isset( $parts['path'] ) ) {
349
+    if (!isset($parts['path'])) {
350 350
         $parts['path'] = '';
351 351
     }
352 352
 
353
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
353
+    $token = md5($parts['path'] . '?' . $parts['query']);
354 354
 
355 355
     return $token;
356 356
 }
357 357
 
358
-function wpinv_validate_url_token( $url = '' ) {
358
+function wpinv_validate_url_token($url = '') {
359 359
     $ret   = false;
360
-    $parts = parse_url( $url );
360
+    $parts = parse_url($url);
361 361
 
362
-    if ( isset( $parts['query'] ) ) {
363
-        wp_parse_str( $parts['query'], $query_args );
362
+    if (isset($parts['query'])) {
363
+        wp_parse_str($parts['query'], $query_args);
364 364
 
365
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
365
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
366 366
             'item',
367 367
             'ttl',
368 368
             'token'
369
-        ) );
369
+        ));
370 370
 
371 371
         $remove = array();
372 372
 
373
-        foreach( $query_args as $key => $value ) {
374
-            if( false === in_array( $key, $allowed ) ) {
373
+        foreach ($query_args as $key => $value) {
374
+            if (false === in_array($key, $allowed)) {
375 375
                 $remove[] = $key;
376 376
             }
377 377
         }
378 378
 
379
-        if( ! empty( $remove ) ) {
380
-            $url = remove_query_arg( $remove, $url );
379
+        if (!empty($remove)) {
380
+            $url = remove_query_arg($remove, $url);
381 381
         }
382 382
 
383
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
384
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
383
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
384
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
385 385
         }
386 386
 
387
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
387
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
388 388
             $ret = true;
389 389
         }
390 390
 
391 391
     }
392 392
 
393
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
393
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
394 394
 }
395 395
 
396
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
396
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
397 397
     $cart_items = wpinv_get_cart_contents();
398 398
 
399 399
     $ret = false;
400 400
 
401
-    if ( is_array( $cart_items ) ) {
402
-        foreach ( $cart_items as $item ) {
403
-            if ( $item['id'] == $item_id ) {
401
+    if (is_array($cart_items)) {
402
+        foreach ($cart_items as $item) {
403
+            if ($item['id'] == $item_id) {
404 404
                 $ret = true;
405 405
                 break;
406 406
             }
407 407
         }
408 408
     }
409 409
 
410
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
410
+    return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
411 411
 }
412 412
 
413
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
413
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
414 414
     $tax = 0;
415
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
416
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
417
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
415
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
416
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
417
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
418 418
 
419
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
419
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
420 420
     }
421 421
 
422
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
422
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
423 423
 }
424 424
 
425
-function wpinv_cart_item_price( $item, $currency = '' ) {
425
+function wpinv_cart_item_price($item, $currency = '') {
426 426
 
427
-    if( empty( $currency ) ) {
427
+    if (empty($currency)) {
428 428
         $currency = wpinv_get_currency();
429 429
     }
430 430
 
431
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
432
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
433
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
431
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
432
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
433
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
434 434
     
435
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
436
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
435
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
436
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
437 437
             $price += $tax;
438 438
         }
439 439
         
440
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
440
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
441 441
             $price -= $tax;
442 442
         }        
443 443
     }
444 444
 
445
-    $price = wpinv_price( wpinv_format_amount( $price ), $currency );
445
+    $price = wpinv_price(wpinv_format_amount($price), $currency);
446 446
 
447
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
447
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
448 448
 }
449 449
 
450
-function wpinv_cart_item_subtotal( $item, $currency = '' ) {
450
+function wpinv_cart_item_subtotal($item, $currency = '') {
451 451
 
452
-    if( empty( $currency ) ) {
452
+    if (empty($currency)) {
453 453
         $currency = wpinv_get_currency();
454 454
     }
455 455
 
456
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
457
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ), $currency );
456
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
457
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal), $currency);
458 458
 
459
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
459
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
460 460
 }
461 461
 
462
-function wpinv_cart_item_tax( $item, $currency = '' ) {
462
+function wpinv_cart_item_tax($item, $currency = '') {
463 463
     $tax        = '';
464 464
     $tax_rate   = '';
465 465
 
466
-    if( empty( $currency ) ) {
466
+    if (empty($currency)) {
467 467
         $currency = wpinv_get_currency();
468 468
     }
469 469
     
470
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
471
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency );
472
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
473
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
470
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
471
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']), $currency);
472
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
473
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
474 474
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
475 475
     }
476 476
     
477
-    $tax        = $tax . $tax_rate;
477
+    $tax = $tax . $tax_rate;
478 478
     
479
-    if ( $tax === '' ) {
479
+    if ($tax === '') {
480 480
         $tax = 0; // Zero tax
481 481
     }
482 482
 
483
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
483
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
484 484
 }
485 485
 
486
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
486
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
487 487
     $price = 0;
488 488
     
489 489
     // Set custom price
490
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
490
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
491 491
         $price = $cart_item['custom_price'];
492 492
     } else {
493
-        $variable_prices = wpinv_has_variable_prices( $item_id );
493
+        $variable_prices = wpinv_has_variable_prices($item_id);
494 494
 
495
-        if ( $variable_prices ) {
496
-            $prices = wpinv_get_variable_prices( $item_id );
495
+        if ($variable_prices) {
496
+            $prices = wpinv_get_variable_prices($item_id);
497 497
 
498
-            if ( $prices ) {
499
-                if( ! empty( $options ) ) {
500
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
498
+            if ($prices) {
499
+                if (!empty($options)) {
500
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
501 501
                 } else {
502 502
                     $price = false;
503 503
                 }
504 504
             }
505 505
         }
506 506
 
507
-        if( ! $variable_prices || false === $price ) {
508
-            if($cart_item['item_price'] > 0){
507
+        if (!$variable_prices || false === $price) {
508
+            if ($cart_item['item_price'] > 0) {
509 509
                 $price = $cart_item['item_price'];
510 510
             } else {
511 511
                 // Get the standard Item price if not using variable prices
512
-                $price = wpinv_get_item_price( $item_id );
512
+                $price = wpinv_get_item_price($item_id);
513 513
             }
514 514
         }
515 515
     }
516 516
 
517
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
518
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
517
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
518
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
519 519
     }
520 520
 
521
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
521
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
522 522
 }
523 523
 
524
-function wpinv_get_cart_item_price_id( $item = array() ) {
525
-    if( isset( $item['item_number'] ) ) {
526
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
524
+function wpinv_get_cart_item_price_id($item = array()) {
525
+    if (isset($item['item_number'])) {
526
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
527 527
     } else {
528
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
528
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
529 529
     }
530 530
     return $price_id;
531 531
 }
532 532
 
533
-function wpinv_get_cart_item_price_name( $item = array() ) {
534
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
535
-    $prices   = wpinv_get_variable_prices( $item['id'] );
536
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
537
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
533
+function wpinv_get_cart_item_price_name($item = array()) {
534
+    $price_id = (int) wpinv_get_cart_item_price_id($item);
535
+    $prices   = wpinv_get_variable_prices($item['id']);
536
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
537
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
538 538
 }
539 539
 
540
-function wpinv_get_cart_item_name( $item = array() ) {
541
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
540
+function wpinv_get_cart_item_name($item = array()) {
541
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
542 542
 
543
-    if ( empty( $item_title ) ) {
543
+    if (empty($item_title)) {
544 544
         $item_title = $item['id'];
545 545
     }
546 546
 
@@ -550,23 +550,23 @@  discard block
 block discarded – undo
550 550
     }
551 551
     */
552 552
 
553
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
553
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
554 554
 }
555 555
 
556
-function wpinv_has_variable_prices( $item_id = 0 ) {
556
+function wpinv_has_variable_prices($item_id = 0) {
557 557
     return false;
558 558
 }
559 559
 
560
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
560
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
561 561
     $cart_items = wpinv_get_cart_contents();
562 562
 
563
-    if ( !is_array( $cart_items ) ) {
563
+    if (!is_array($cart_items)) {
564 564
         return false; // Empty cart
565 565
     } else {
566
-        foreach ( $cart_items as $position => $item ) {
567
-            if ( $item['id'] == $item_id ) {
568
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
569
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
566
+        foreach ($cart_items as $position => $item) {
567
+            if ($item['id'] == $item_id) {
568
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
569
+                    if ((int) $options['price_id'] == (int) $item['options']['price_id']) {
570 570
                         return $position;
571 571
                     }
572 572
                 } else {
@@ -579,80 +579,80 @@  discard block
 block discarded – undo
579 579
     return false; // Not found
580 580
 }
581 581
 
582
-function wpinv_get_cart_item_quantity( $item ) {
583
-    if ( wpinv_item_quantities_enabled() ) {
584
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
582
+function wpinv_get_cart_item_quantity($item) {
583
+    if (wpinv_item_quantities_enabled()) {
584
+        $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1;
585 585
     } else {
586 586
         $quantity = 1;
587 587
     }
588 588
     
589
-    if ( $quantity < 1 ) {
589
+    if ($quantity < 1) {
590 590
         $quantity = 1;
591 591
     }
592 592
     
593
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
593
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
594 594
 }
595 595
 
596
-function wpinv_get_item_suffix( $item, $html = true ) {
597
-    if ( empty( $item ) ) {
596
+function wpinv_get_item_suffix($item, $html = true) {
597
+    if (empty($item)) {
598 598
         return NULL;
599 599
     }
600 600
     
601
-    if ( is_int( $item ) ) {
602
-        $item = new WPInv_Item( $item );
601
+    if (is_int($item)) {
602
+        $item = new WPInv_Item($item);
603 603
     }
604 604
     
605
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
605
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
606 606
         return NULL;
607 607
     }
608 608
     
609
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
609
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
610 610
     
611
-    if ( !$html && $suffix ) {
612
-        $suffix = strip_tags( $suffix );
611
+    if (!$html && $suffix) {
612
+        $suffix = strip_tags($suffix);
613 613
     }
614 614
     
615
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
615
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
616 616
 }
617 617
 
618
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
619
-    if ( empty( $item ) ) {
618
+function wpinv_remove_item($item = 0, $force_delete = false) {
619
+    if (empty($item)) {
620 620
         return NULL;
621 621
     }
622 622
     
623
-    if ( is_int( $item ) ) {
624
-        $item = new WPInv_Item( $item );
623
+    if (is_int($item)) {
624
+        $item = new WPInv_Item($item);
625 625
     }
626 626
     
627
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
627
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
628 628
         return NULL;
629 629
     }
630 630
     
631
-    do_action( 'wpinv_pre_delete_item', $item );
631
+    do_action('wpinv_pre_delete_item', $item);
632 632
 
633
-    wp_delete_post( $item->ID, $force_delete );
633
+    wp_delete_post($item->ID, $force_delete);
634 634
 
635
-    do_action( 'wpinv_post_delete_item', $item );
635
+    do_action('wpinv_post_delete_item', $item);
636 636
 }
637 637
 
638
-function wpinv_can_delete_item( $post_id ) {
638
+function wpinv_can_delete_item($post_id) {
639 639
     $return = wpinv_current_user_can_manage_invoicing() ? true : false;
640 640
     
641
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
641
+    if ($return && wpinv_item_in_use($post_id)) {
642 642
         $return = false; // Don't delete item already use in invoices.
643 643
     }
644 644
     
645
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
645
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
646 646
 }
647 647
 
648 648
 function wpinv_admin_action_delete() {
649 649
     $screen = get_current_screen();
650 650
     
651
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
651
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
652 652
         $post_ids = array();
653 653
         
654
-        foreach ( $_REQUEST['post'] as $post_id ) {
655
-            if ( !wpinv_can_delete_item( $post_id ) ) {
654
+        foreach ($_REQUEST['post'] as $post_id) {
655
+            if (!wpinv_can_delete_item($post_id)) {
656 656
                 continue;
657 657
             }
658 658
             
@@ -662,39 +662,39 @@  discard block
 block discarded – undo
662 662
         $_REQUEST['post'] = $post_ids;
663 663
     }
664 664
 }
665
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
666
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
665
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
666
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
667 667
 
668
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
669
-    if ( $post->post_type == 'wpi_item' ) {
670
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
668
+function wpinv_check_delete_item($check, $post, $force_delete) {
669
+    if ($post->post_type == 'wpi_item') {
670
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
671 671
             return true;
672 672
         }
673 673
     }
674 674
     
675 675
     return $check;
676 676
 }
677
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
677
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
678 678
 
679
-function wpinv_item_in_use( $item_id ) {
679
+function wpinv_item_in_use($item_id) {
680 680
     global $wpdb, $wpi_items_in_use;
681 681
     
682
-    if ( !$item_id > 0 ) {
682
+    if (!$item_id > 0) {
683 683
         return false;
684 684
     }
685 685
     
686
-    if ( !empty( $wpi_items_in_use ) ) {
687
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
686
+    if (!empty($wpi_items_in_use)) {
687
+        if (isset($wpi_items_in_use[$item_id])) {
688 688
             return $wpi_items_in_use[$item_id];
689 689
         }
690 690
     } else {
691 691
         $wpi_items_in_use = array();
692 692
     }
693 693
     
694
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
694
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
695 695
     
696
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
697
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
696
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )";
697
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
698 698
     
699 699
     $wpi_items_in_use[$item_id] = $in_use;
700 700
     
@@ -737,45 +737,45 @@  discard block
 block discarded – undo
737 737
  * @param bool $wp_error whether or not to return a WP_Error on failure.
738 738
  * @return bool|WP_Error|WPInv_Item
739 739
  */
740
-function wpinv_create_item( $args = array(), $wp_error = false ) {
740
+function wpinv_create_item($args = array(), $wp_error = false) {
741 741
 
742 742
     // Prepare the item.
743
-    if ( ! empty( $args['custom_id'] ) && empty( $args['ID'] ) ) {
744
-        $type = empty( $args['type'] ) ? 'custom' : $args['type'];
745
-        $item = wpinv_get_item_by( 'custom_id', $args['custom_id'], $type );
743
+    if (!empty($args['custom_id']) && empty($args['ID'])) {
744
+        $type = empty($args['type']) ? 'custom' : $args['type'];
745
+        $item = wpinv_get_item_by('custom_id', $args['custom_id'], $type);
746 746
 
747
-        if ( ! empty( $item ) ) {
747
+        if (!empty($item)) {
748 748
             $args['ID'] = $item->get_id();
749 749
         }
750 750
 
751 751
     }
752 752
 
753 753
     // Do we have an item?
754
-    if ( ! empty( $args['ID'] ) ) {
755
-        $item = new WPInv_Item( $args['ID'] );
754
+    if (!empty($args['ID'])) {
755
+        $item = new WPInv_Item($args['ID']);
756 756
     } else {
757 757
         $item = new WPInv_Item();
758 758
     }
759 759
 
760 760
     // Do we have an error?
761
-    if ( ! empty( $item->last_error ) ) {
762
-        return $wp_error ? new WP_Error( 'invalid_item', $item->last_error ) : false;
761
+    if (!empty($item->last_error)) {
762
+        return $wp_error ? new WP_Error('invalid_item', $item->last_error) : false;
763 763
     }
764 764
 
765 765
     // Update item props.
766
-    $item->set_props( $args );
766
+    $item->set_props($args);
767 767
 
768 768
     // Save the item.
769 769
     $item->save();
770 770
 
771 771
     // Do we have an error?
772
-    if ( ! empty( $item->last_error ) ) {
773
-        return $wp_error ? new WP_Error( 'not_saved', $item->last_error ) : false;
772
+    if (!empty($item->last_error)) {
773
+        return $wp_error ? new WP_Error('not_saved', $item->last_error) : false;
774 774
     }
775 775
 
776 776
     // Was the item saved?
777
-    if ( ! $item->get_id() ) {
778
-        return $wp_error ? new WP_Error( 'not_saved', __( 'An error occured while saving the item', 'invoicing' ) ) : false;
777
+    if (!$item->get_id()) {
778
+        return $wp_error ? new WP_Error('not_saved', __('An error occured while saving the item', 'invoicing')) : false;
779 779
     }
780 780
 
781 781
     return $item;
@@ -787,14 +787,14 @@  discard block
 block discarded – undo
787 787
  * 
788 788
  * @see wpinv_create_item()
789 789
  */
790
-function wpinv_update_item( $args = array(), $wp_error = false ) {
791
-    return wpinv_create_item( $args, $wp_error );
790
+function wpinv_update_item($args = array(), $wp_error = false) {
791
+    return wpinv_create_item($args, $wp_error);
792 792
 }
793 793
 
794 794
 /**
795 795
  * Sanitizes a recurring period
796 796
  */
797
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
797
+function getpaid_sanitize_recurring_period($period, $full = false) {
798 798
 
799 799
     $periods = array(
800 800
         'D' => 'day',
@@ -803,11 +803,11 @@  discard block
 block discarded – undo
803 803
         'Y' => 'year',
804 804
     );
805 805
 
806
-    if ( ! isset( $periods[ $period ] ) ) {
806
+    if (!isset($periods[$period])) {
807 807
         $period = 'D';
808 808
     }
809 809
 
810
-    return $full ? $periods[ $period ] : $period;
810
+    return $full ? $periods[$period] : $period;
811 811
 
812 812
 }
813 813
 
@@ -816,34 +816,34 @@  discard block
 block discarded – undo
816 816
  * 
817 817
  * @param WPInv_Item|GetPaid_Form_Item $item
818 818
  */
819
-function getpaid_item_recurring_price_help_text( $item, $currency = '' ) {
819
+function getpaid_item_recurring_price_help_text($item, $currency = '') {
820 820
 
821 821
     // Abort if it is not recurring.
822
-    if ( ! $item->is_recurring() ) {
822
+    if (!$item->is_recurring()) {
823 823
         return '';
824 824
     }
825 825
 
826
-    $initial_price   = wpinv_price( $item->get_initial_price(), $currency );
827
-    $recurring_price = wpinv_price( $item->get_recurring_price(), $currency );
828
-    $period          = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' );
826
+    $initial_price   = wpinv_price($item->get_initial_price(), $currency);
827
+    $recurring_price = wpinv_price($item->get_recurring_price(), $currency);
828
+    $period          = getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '');
829 829
     $initial_class   = 'getpaid-item-initial-price';
830 830
     $recurring_class = 'getpaid-item-recurring-price';
831 831
 
832
-    if ( $item instanceof GetPaid_Form_Item ) {
833
-        $initial_price   = wpinv_price( $item->get_sub_total(), $currency );
834
-        $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency );
832
+    if ($item instanceof GetPaid_Form_Item) {
833
+        $initial_price   = wpinv_price($item->get_sub_total(), $currency);
834
+        $recurring_price = wpinv_price($item->get_recurring_sub_total(), $currency);
835 835
     }
836 836
 
837 837
     // For free trial items.
838
-    if ( $item->has_free_trial() ) {
839
-        $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() );
838
+    if ($item->has_free_trial()) {
839
+        $trial_period = getpaid_get_subscription_period_label($item->get_trial_period(), $item->get_trial_interval());
840 840
 
841
-        if ( 0 == $item->get_initial_price() ) {
841
+        if (0 == $item->get_initial_price()) {
842 842
 
843 843
             return sprintf(
844 844
 
845 845
                 // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period
846
-                _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ),
846
+                _x('Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing'),
847 847
                 $trial_period,
848 848
                 "<span class='$recurring_class'>$recurring_price</span>",
849 849
                 $period
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
         return sprintf(
856 856
 
857 857
             // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period
858
-            _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ),
858
+            _x('%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing'),
859 859
             "<span class='$initial_class'>$initial_price</span>",
860 860
             $trial_period,
861 861
             "<span class='$recurring_class'>$recurring_price</span>",
@@ -865,12 +865,12 @@  discard block
 block discarded – undo
865 865
 
866 866
     }
867 867
 
868
-    if ( $initial_price == $recurring_price ) {
868
+    if ($initial_price == $recurring_price) {
869 869
 
870 870
         return sprintf(
871 871
 
872 872
             // translators: $1: is the recurring price, $2: is the susbcription period
873
-            _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ),
873
+            _x('%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing'),
874 874
             "<span class='$recurring_class'>$recurring_price</span>",
875 875
             $period
876 876
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
     return sprintf(
882 882
 
883 883
         // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period
884
-        _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ),
884
+        _x('Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing'),
885 885
         "<span class='$initial_class'>$initial_price</span>",
886 886
         "<span class='$recurring_class'>$recurring_price</span>",
887 887
         $period
Please login to merge, or discard this patch.
includes/admin/subscriptions.php 2 patches
Indentation   +203 added lines, -203 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,27 +80,27 @@  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->get_id() ) {
83
+    // Fetch the subscription.
84
+    $sub = new WPInv_Subscription( (int) $_GET['id'] );
85
+    if ( ! $sub->get_id() ) {
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' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
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' );
99
+    add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
+    add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
+    do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
102 102
 
103
-	?>
103
+    ?>
104 104
 
105 105
 		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
106 106
 
@@ -140,41 +140,41 @@  discard block
 block discarded – undo
140 140
  */
141 141
 function getpaid_admin_subscription_details_metabox( $sub ) {
142 142
 
143
-	// Prepare subscription detail columns.
144
-	$fields = apply_filters(
145
-		'getpaid_subscription_admin_page_fields',
146
-		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Payments', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
157
-		)
158
-	);
159
-
160
-	if ( ! $sub->is_active() ) {
161
-
162
-		if ( isset( $fields['renews_on'] ) ) {
163
-			unset( $fields['renews_on'] );
164
-		}
165
-
166
-		if ( isset( $fields['gateway'] ) ) {
167
-			unset( $fields['gateway'] );
168
-		}
143
+    // Prepare subscription detail columns.
144
+    $fields = apply_filters(
145
+        'getpaid_subscription_admin_page_fields',
146
+        array(
147
+            'subscription'   => __( 'Subscription', 'invoicing' ),
148
+            'customer'       => __( 'Customer', 'invoicing' ),
149
+            'amount'         => __( 'Amount', 'invoicing' ),
150
+            'start_date'     => __( 'Start Date', 'invoicing' ),
151
+            'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
+            'renewals'       => __( 'Payments', 'invoicing' ),
153
+            'item'           => __( 'Item', 'invoicing' ),
154
+            'gateway'        => __( 'Payment Method', 'invoicing' ),
155
+            'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
+            'status'         => __( 'Status', 'invoicing' ),
157
+        )
158
+    );
159
+
160
+    if ( ! $sub->is_active() ) {
161
+
162
+        if ( isset( $fields['renews_on'] ) ) {
163
+            unset( $fields['renews_on'] );
164
+        }
165
+
166
+        if ( isset( $fields['gateway'] ) ) {
167
+            unset( $fields['gateway'] );
168
+        }
169 169
 		
170
-	}
170
+    }
171 171
 
172
-	$profile_id = $sub->get_profile_id();
173
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
-		unset( $fields['profile_id'] );
175
-	}
172
+    $profile_id = $sub->get_profile_id();
173
+    if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
+        unset( $fields['profile_id'] );
175
+    }
176 176
 
177
-	?>
177
+    ?>
178 178
 
179 179
 		<table class="table table-borderless" style="font-size: 14px;">
180 180
 			<tbody>
@@ -208,20 +208,20 @@  discard block
 block discarded – undo
208 208
  */
209 209
 function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
210 210
 
211
-	$username = __( '(Missing User)', 'invoicing' );
211
+    $username = __( '(Missing User)', 'invoicing' );
212 212
 
213
-	$user = get_userdata( $subscription->get_customer_id() );
214
-	if ( $user ) {
213
+    $user = get_userdata( $subscription->get_customer_id() );
214
+    if ( $user ) {
215 215
 
216
-		$username = sprintf(
217
-			'<a href="user-edit.php?user_id=%s">%s</a>',
218
-			absint( $user->ID ),
219
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
-		);
216
+        $username = sprintf(
217
+            '<a href="user-edit.php?user_id=%s">%s</a>',
218
+            absint( $user->ID ),
219
+            ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
220
+        );
221 221
 
222
-	}
222
+    }
223 223
 
224
-	echo  $username;
224
+    echo  $username;
225 225
 }
226 226
 add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
227 227
 
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
  * @param WPInv_Subscription $subscription
232 232
  */
233 233
 function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
234
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
235
-	echo "<span>$amount</span>";
234
+    $amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
235
+    echo "<span>$amount</span>";
236 236
 }
237 237
 add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
238 238
 
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
  * @param WPInv_Subscription $subscription
243 243
  */
244 244
 function getpaid_admin_subscription_metabox_display_id( $subscription ) {
245
-	echo  '#' . absint( $subscription->get_id() );
245
+    echo  '#' . absint( $subscription->get_id() );
246 246
 }
247 247
 add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
248 248
 
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
  * @param WPInv_Subscription $subscription
253 253
  */
254 254
 function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
255
-	echo getpaid_format_date_value( $subscription->get_date_created() );
255
+    echo getpaid_format_date_value( $subscription->get_date_created() );
256 256
 }
257 257
 add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
258 258
 
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
  * @param WPInv_Subscription $subscription
263 263
  */
264 264
 function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
265
-	echo getpaid_format_date_value( $subscription->get_expiration() );
265
+    echo getpaid_format_date_value( $subscription->get_expiration() );
266 266
 }
267 267
 add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
268 268
 
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
  * @param WPInv_Subscription $subscription
273 273
  */
274 274
 function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
275
-	$max_bills = $subscription->get_bill_times();
276
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
275
+    $max_bills = $subscription->get_bill_times();
276
+    echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
277 277
 }
278 278
 add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
279 279
 /**
@@ -283,16 +283,16 @@  discard block
 block discarded – undo
283 283
  */
284 284
 function getpaid_admin_subscription_metabox_display_item( $subscription ) {
285 285
 
286
-	$item = get_post( $subscription->get_product_id() );
286
+    $item = get_post( $subscription->get_product_id() );
287 287
 
288
-	if ( ! empty( $item ) ) {
289
-		$link = get_edit_post_link( $item );
290
-		$link = esc_url( $link );
291
-		$name = esc_html( get_the_title( $item ) );
292
-		echo "<a href='$link'>$name</a>";
293
-	} else {
294
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
295
-	}
288
+    if ( ! empty( $item ) ) {
289
+        $link = get_edit_post_link( $item );
290
+        $link = esc_url( $link );
291
+        $name = esc_html( get_the_title( $item ) );
292
+        echo "<a href='$link'>$name</a>";
293
+    } else {
294
+        echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
295
+    }
296 296
 
297 297
 }
298 298
 add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
@@ -304,13 +304,13 @@  discard block
 block discarded – undo
304 304
  */
305 305
 function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
306 306
 
307
-	$gateway = $subscription->get_gateway();
307
+    $gateway = $subscription->get_gateway();
308 308
 
309
-	if ( ! empty( $gateway ) ) {
310
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
311
-	} else {
312
-		echo "&mdash;";
313
-	}
309
+    if ( ! empty( $gateway ) ) {
310
+        echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
311
+    } else {
312
+        echo "&mdash;";
313
+    }
314 314
 
315 315
 }
316 316
 add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
  * @param WPInv_Subscription $subscription
322 322
  */
323 323
 function getpaid_admin_subscription_metabox_display_status( $subscription ) {
324
-	echo $subscription->get_status_label_html();
324
+    echo $subscription->get_status_label_html();
325 325
 }
326 326
 add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
327 327
 
@@ -332,14 +332,14 @@  discard block
 block discarded – undo
332 332
  */
333 333
 function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
334 334
 
335
-	$profile_id = $subscription->get_profile_id();
335
+    $profile_id = $subscription->get_profile_id();
336 336
 
337
-	if ( ! empty( $profile_id ) ) {
338
-		$profile_id = sanitize_text_field( $profile_id );
339
-		echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
340
-	} else {
341
-		echo "&mdash;";
342
-	}
337
+    if ( ! empty( $profile_id ) ) {
338
+        $profile_id = sanitize_text_field( $profile_id );
339
+        echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
340
+    } else {
341
+        echo "&mdash;";
342
+    }
343 343
 
344 344
 }
345 345
 add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
@@ -351,39 +351,39 @@  discard block
 block discarded – undo
351 351
  */
352 352
 function getpaid_admin_subscription_update_metabox( $subscription ) {
353 353
 
354
-	?>
354
+    ?>
355 355
 	<div class="mt-3">
356 356
 
357 357
 		<?php
358
-			echo aui()->select(
359
-				array(
360
-					'options'          => getpaid_get_subscription_statuses(),
361
-					'name'             => 'subscription_status',
362
-					'id'               => 'subscription_status_update_select',
363
-					'required'         => true,
364
-					'no_wrap'          => false,
365
-					'label'            => __( 'Subscription Status', 'invoicing' ),
366
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
367
-					'select2'          => true,
368
-					'value'            => $subscription->get_status( 'edit' ),
369
-				)
370
-			);
371
-		?>
358
+            echo aui()->select(
359
+                array(
360
+                    'options'          => getpaid_get_subscription_statuses(),
361
+                    'name'             => 'subscription_status',
362
+                    'id'               => 'subscription_status_update_select',
363
+                    'required'         => true,
364
+                    'no_wrap'          => false,
365
+                    'label'            => __( 'Subscription Status', 'invoicing' ),
366
+                    'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
367
+                    'select2'          => true,
368
+                    'value'            => $subscription->get_status( 'edit' ),
369
+                )
370
+            );
371
+        ?>
372 372
 
373 373
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
374 374
 	
375 375
 		<?php
376
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
376
+            submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
377 377
 
378
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
379
-			$anchor = __( 'Renew Subscription', 'invoicing' );
380
-			$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' );
378
+            $url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
379
+            $anchor = __( 'Renew Subscription', 'invoicing' );
380
+            $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' );
381 381
 
382
-			if ( $subscription->is_active() ) {
383
-				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
384
-			}
382
+            if ( $subscription->is_active() ) {
383
+                echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
384
+            }
385 385
 
386
-	echo '</div></div>';
386
+    echo '</div></div>';
387 387
 }
388 388
 
389 389
 /**
@@ -393,33 +393,33 @@  discard block
 block discarded – undo
393 393
  */
394 394
 function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
395 395
 
396
-	$columns = apply_filters(
397
-		'getpaid_subscription_related_invoices_columns',
398
-		array(
399
-			'invoice'      => __( 'Invoice', 'invoicing' ),
400
-			'relationship' => __( 'Relationship', 'invoicing' ),
401
-			'date'         => __( 'Date', 'invoicing' ),
402
-			'status'       => __( 'Status', 'invoicing' ),
403
-			'total'        => __( 'Total', 'invoicing' ),
404
-		),
405
-		$subscription
406
-	);
407
-
408
-	// Prepare the invoices.
409
-	$payments = $subscription->get_child_payments();
410
-	$parent   = $subscription->get_parent_invoice();
411
-
412
-	if ( $parent->get_id() ) {
413
-		$payments = array_merge( array( $parent ), $payments );
414
-	}
396
+    $columns = apply_filters(
397
+        'getpaid_subscription_related_invoices_columns',
398
+        array(
399
+            'invoice'      => __( 'Invoice', 'invoicing' ),
400
+            'relationship' => __( 'Relationship', 'invoicing' ),
401
+            'date'         => __( 'Date', 'invoicing' ),
402
+            'status'       => __( 'Status', 'invoicing' ),
403
+            'total'        => __( 'Total', 'invoicing' ),
404
+        ),
405
+        $subscription
406
+    );
407
+
408
+    // Prepare the invoices.
409
+    $payments = $subscription->get_child_payments();
410
+    $parent   = $subscription->get_parent_invoice();
411
+
412
+    if ( $parent->get_id() ) {
413
+        $payments = array_merge( array( $parent ), $payments );
414
+    }
415 415
 	
416
-	$table_class = 'w-100 bg-white';
416
+    $table_class = 'w-100 bg-white';
417 417
 
418
-	if ( ! is_admin() ) {
419
-		$table_class = 'table table-bordered table-striped';
420
-	}
418
+    if ( ! is_admin() ) {
419
+        $table_class = 'table table-bordered table-striped';
420
+    }
421 421
 
422
-	?>
422
+    ?>
423 423
 		<div class="m-0" style="overflow: auto;">
424 424
 
425 425
 			<table class="<?php echo $table_class; ?>">
@@ -427,13 +427,13 @@  discard block
 block discarded – undo
427 427
 				<thead>
428 428
 					<tr>
429 429
 						<?php
430
-							foreach ( $columns as $key => $label ) {
431
-								$key   = esc_attr( $key );
432
-								$label = sanitize_text_field( $label );
430
+                            foreach ( $columns as $key => $label ) {
431
+                                $key   = esc_attr( $key );
432
+                                $label = sanitize_text_field( $label );
433 433
 
434
-								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
435
-							}
436
-						?>
434
+                                echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
435
+                            }
436
+                        ?>
437 437
 					</tr>
438 438
 				</thead>
439 439
 
@@ -449,66 +449,66 @@  discard block
 block discarded – undo
449 449
 
450 450
 					<?php
451 451
 
452
-						foreach( $payments as $payment ) :
452
+                        foreach( $payments as $payment ) :
453 453
 
454
-							// Ensure that we have an invoice.
455
-							$payment = new WPInv_Invoice( $payment );
454
+                            // Ensure that we have an invoice.
455
+                            $payment = new WPInv_Invoice( $payment );
456 456
 
457
-							// Abort if the invoice is invalid.
458
-							if ( ! $payment->get_id() ) {
459
-								continue;
460
-							}
457
+                            // Abort if the invoice is invalid.
458
+                            if ( ! $payment->get_id() ) {
459
+                                continue;
460
+                            }
461 461
 
462
-							echo '<tr>';
462
+                            echo '<tr>';
463 463
 
464
-								foreach ( array_keys( $columns ) as $key ) {
464
+                                foreach ( array_keys( $columns ) as $key ) {
465 465
 									
466
-									echo '<td class="p-2 text-left">';
466
+                                    echo '<td class="p-2 text-left">';
467 467
 
468
-										switch( $key ) {
468
+                                        switch( $key ) {
469 469
 
470
-											case 'total':
471
-												echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
472
-												break;
470
+                                            case 'total':
471
+                                                echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
472
+                                                break;
473 473
 
474
-											case 'relationship':
475
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
476
-												break;
474
+                                            case 'relationship':
475
+                                                echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
476
+                                                break;
477 477
 
478
-											case 'date':
479
-												echo getpaid_format_date_value( $payment->get_date_created() );
480
-												break;
478
+                                            case 'date':
479
+                                                echo getpaid_format_date_value( $payment->get_date_created() );
480
+                                                break;
481 481
 
482
-											case 'status':
482
+                                            case 'status':
483 483
 
484
-												$status = $payment->get_status_nicename();
485
-												if ( is_admin() ) {
486
-													$status = $payment->get_status_label_html();
487
-												}
484
+                                                $status = $payment->get_status_nicename();
485
+                                                if ( is_admin() ) {
486
+                                                    $status = $payment->get_status_label_html();
487
+                                                }
488 488
 
489
-												echo $status;
490
-												break;
489
+                                                echo $status;
490
+                                                break;
491 491
 
492
-											case 'invoice':
493
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
492
+                                            case 'invoice':
493
+                                                $link    = esc_url( get_edit_post_link( $payment->get_id() ) );
494 494
 
495
-												if ( ! is_admin() ) {
496
-													$link = esc_url( $payment->get_view_url() );
497
-												}
495
+                                                if ( ! is_admin() ) {
496
+                                                    $link = esc_url( $payment->get_view_url() );
497
+                                                }
498 498
 
499
-												$invoice = sanitize_text_field( $payment->get_number() );
500
-												echo "<a href='$link'>$invoice</a>";
501
-												break;
502
-										}
499
+                                                $invoice = sanitize_text_field( $payment->get_number() );
500
+                                                echo "<a href='$link'>$invoice</a>";
501
+                                                break;
502
+                                        }
503 503
 
504
-									echo '</td>';
504
+                                    echo '</td>';
505 505
 
506
-								}
506
+                                }
507 507
 
508
-							echo '</tr>';
508
+                            echo '</tr>';
509 509
 
510
-						endforeach;
511
-					?>
510
+                        endforeach;
511
+                    ?>
512 512
 
513 513
 				</tbody>
514 514
 
Please login to merge, or discard this patch.
Spacing   +119 added lines, -119 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->get_id() ) {
84
+	$sub = new WPInv_Subscription((int) $_GET['id']);
85
+	if (!$sub->get_id()) {
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,31 +95,31 @@  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' );
99
-	add_meta_box( 'getpaid_admin_subscription_update_metabox', __( 'Change Status', 'invoicing' ), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side' );
100
-	add_meta_box( 'getpaid_admin_subscription_invoice_details_metabox', __( 'Invoices', 'invoicing' ), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced' );
101
-	do_action( 'getpaid_admin_single_subscription_register_metabox', $sub );
98
+	add_meta_box('getpaid_admin_subscription_details_metabox', __('Subscription Details', 'invoicing'), 'getpaid_admin_subscription_details_metabox', get_current_screen(), 'normal');
99
+	add_meta_box('getpaid_admin_subscription_update_metabox', __('Change Status', 'invoicing'), 'getpaid_admin_subscription_update_metabox', get_current_screen(), 'side');
100
+	add_meta_box('getpaid_admin_subscription_invoice_details_metabox', __('Invoices', 'invoicing'), 'getpaid_admin_subscription_invoice_details_metabox', get_current_screen(), 'advanced');
101
+	do_action('getpaid_admin_single_subscription_register_metabox', $sub);
102 102
 
103 103
 	?>
104 104
 
105
-		<form method="post" action="<?php echo admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $sub->get_id() ) ); ?>">
105
+		<form method="post" action="<?php echo admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($sub->get_id())); ?>">
106 106
 
107
-			<?php wp_nonce_field( 'getpaid-nonce', 'getpaid-nonce' ); ?>
108
-			<?php wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false ); ?>
109
-			<?php wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false ); ?>
107
+			<?php wp_nonce_field('getpaid-nonce', 'getpaid-nonce'); ?>
108
+			<?php wp_nonce_field('meta-box-order', 'meta-box-order-nonce', false); ?>
109
+			<?php wp_nonce_field('closedpostboxes', 'closedpostboxesnonce', false); ?>
110 110
 			<input type="hidden" name="getpaid-admin-action" value="update_single_subscription" />
111
-			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id() ;?>" />
111
+			<input type="hidden" name="subscription_id" value="<?php echo (int) $sub->get_id(); ?>" />
112 112
 
113 113
 			<div id="poststuff">
114 114
 				<div id="post-body" class="metabox-holder columns-<?php echo 1 == get_current_screen()->get_columns() ? '1' : '2'; ?>">
115 115
 
116 116
 					<div id="postbox-container-1" class="postbox-container">
117
-						<?php do_meta_boxes( get_current_screen(), 'side', $sub ); ?>
117
+						<?php do_meta_boxes(get_current_screen(), 'side', $sub); ?>
118 118
 					</div>
119 119
 
120 120
 					<div id="postbox-container-2" class="postbox-container">
121
-						<?php do_meta_boxes( get_current_screen(), 'normal', $sub ); ?>
122
-						<?php do_meta_boxes( get_current_screen(), 'advanced', $sub ); ?>
121
+						<?php do_meta_boxes(get_current_screen(), 'normal', $sub); ?>
122
+						<?php do_meta_boxes(get_current_screen(), 'advanced', $sub); ?>
123 123
 					</div>
124 124
 
125 125
 				</div>
@@ -138,40 +138,40 @@  discard block
 block discarded – undo
138 138
  *
139 139
  * @param WPInv_Subscription $sub
140 140
  */
141
-function getpaid_admin_subscription_details_metabox( $sub ) {
141
+function getpaid_admin_subscription_details_metabox($sub) {
142 142
 
143 143
 	// Prepare subscription detail columns.
144 144
 	$fields = apply_filters(
145 145
 		'getpaid_subscription_admin_page_fields',
146 146
 		array(
147
-			'subscription'   => __( 'Subscription', 'invoicing' ),
148
-			'customer'       => __( 'Customer', 'invoicing' ),
149
-			'amount'         => __( 'Amount', 'invoicing' ),
150
-			'start_date'     => __( 'Start Date', 'invoicing' ),
151
-			'renews_on'      => __( 'Next Payment', 'invoicing' ),
152
-			'renewals'       => __( 'Payments', 'invoicing' ),
153
-			'item'           => __( 'Item', 'invoicing' ),
154
-			'gateway'        => __( 'Payment Method', 'invoicing' ),
155
-			'profile_id'     => __( 'Profile ID', 'invoicing' ),
156
-			'status'         => __( 'Status', 'invoicing' ),
147
+			'subscription'   => __('Subscription', 'invoicing'),
148
+			'customer'       => __('Customer', 'invoicing'),
149
+			'amount'         => __('Amount', 'invoicing'),
150
+			'start_date'     => __('Start Date', 'invoicing'),
151
+			'renews_on'      => __('Next Payment', 'invoicing'),
152
+			'renewals'       => __('Payments', 'invoicing'),
153
+			'item'           => __('Item', 'invoicing'),
154
+			'gateway'        => __('Payment Method', 'invoicing'),
155
+			'profile_id'     => __('Profile ID', 'invoicing'),
156
+			'status'         => __('Status', 'invoicing'),
157 157
 		)
158 158
 	);
159 159
 
160
-	if ( ! $sub->is_active() ) {
160
+	if (!$sub->is_active()) {
161 161
 
162
-		if ( isset( $fields['renews_on'] ) ) {
163
-			unset( $fields['renews_on'] );
162
+		if (isset($fields['renews_on'])) {
163
+			unset($fields['renews_on']);
164 164
 		}
165 165
 
166
-		if ( isset( $fields['gateway'] ) ) {
167
-			unset( $fields['gateway'] );
166
+		if (isset($fields['gateway'])) {
167
+			unset($fields['gateway']);
168 168
 		}
169 169
 		
170 170
 	}
171 171
 
172 172
 	$profile_id = $sub->get_profile_id();
173
-	if ( empty( $profile_id ) && isset( $fields['profile_id'] ) ) {
174
-		unset( $fields['profile_id'] );
173
+	if (empty($profile_id) && isset($fields['profile_id'])) {
174
+		unset($fields['profile_id']);
175 175
 	}
176 176
 
177 177
 	?>
@@ -179,16 +179,16 @@  discard block
 block discarded – undo
179 179
 		<table class="table table-borderless" style="font-size: 14px;">
180 180
 			<tbody>
181 181
 
182
-				<?php foreach ( $fields as $key => $label ) : ?>
182
+				<?php foreach ($fields as $key => $label) : ?>
183 183
 
184
-					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class( $key ); ?>">
184
+					<tr class="getpaid-subscription-meta-<?php echo sanitize_html_class($key); ?>">
185 185
 
186 186
 						<th class="w-25" style="font-weight: 500;">
187
-							<?php echo sanitize_text_field( $label ); ?>
187
+							<?php echo sanitize_text_field($label); ?>
188 188
 						</th>
189 189
 
190 190
 						<td class="w-75 text-muted">
191
-							<?php do_action( 'getpaid_subscription_admin_display_' . sanitize_text_field( $key ), $sub ); ?>
191
+							<?php do_action('getpaid_subscription_admin_display_' . sanitize_text_field($key), $sub); ?>
192 192
 						</td>
193 193
 
194 194
 					</tr>
@@ -206,150 +206,150 @@  discard block
 block discarded – undo
206 206
  *
207 207
  * @param WPInv_Subscription $subscription
208 208
  */
209
-function getpaid_admin_subscription_metabox_display_customer( $subscription ) {
209
+function getpaid_admin_subscription_metabox_display_customer($subscription) {
210 210
 
211
-	$username = __( '(Missing User)', 'invoicing' );
211
+	$username = __('(Missing User)', 'invoicing');
212 212
 
213
-	$user = get_userdata( $subscription->get_customer_id() );
214
-	if ( $user ) {
213
+	$user = get_userdata($subscription->get_customer_id());
214
+	if ($user) {
215 215
 
216 216
 		$username = sprintf(
217 217
 			'<a href="user-edit.php?user_id=%s">%s</a>',
218
-			absint( $user->ID ),
219
-			! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
218
+			absint($user->ID),
219
+			!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
220 220
 		);
221 221
 
222 222
 	}
223 223
 
224 224
 	echo  $username;
225 225
 }
226
-add_action( 'getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer' );
226
+add_action('getpaid_subscription_admin_display_customer', 'getpaid_admin_subscription_metabox_display_customer');
227 227
 
228 228
 /**
229 229
  * Displays the subscription amount.
230 230
  *
231 231
  * @param WPInv_Subscription $subscription
232 232
  */
233
-function getpaid_admin_subscription_metabox_display_amount( $subscription ) {
234
-	$amount    = sanitize_text_field( getpaid_get_formatted_subscription_amount( $subscription ) );
233
+function getpaid_admin_subscription_metabox_display_amount($subscription) {
234
+	$amount = sanitize_text_field(getpaid_get_formatted_subscription_amount($subscription));
235 235
 	echo "<span>$amount</span>";
236 236
 }
237
-add_action( 'getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount' );
237
+add_action('getpaid_subscription_admin_display_amount', 'getpaid_admin_subscription_metabox_display_amount');
238 238
 
239 239
 /**
240 240
  * Displays the subscription id.
241 241
  *
242 242
  * @param WPInv_Subscription $subscription
243 243
  */
244
-function getpaid_admin_subscription_metabox_display_id( $subscription ) {
245
-	echo  '#' . absint( $subscription->get_id() );
244
+function getpaid_admin_subscription_metabox_display_id($subscription) {
245
+	echo  '#' . absint($subscription->get_id());
246 246
 }
247
-add_action( 'getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id' );
247
+add_action('getpaid_subscription_admin_display_subscription', 'getpaid_admin_subscription_metabox_display_id');
248 248
 
249 249
 /**
250 250
  * Displays the subscription renewal date.
251 251
  *
252 252
  * @param WPInv_Subscription $subscription
253 253
  */
254
-function getpaid_admin_subscription_metabox_display_start_date( $subscription ) {
255
-	echo getpaid_format_date_value( $subscription->get_date_created() );
254
+function getpaid_admin_subscription_metabox_display_start_date($subscription) {
255
+	echo getpaid_format_date_value($subscription->get_date_created());
256 256
 }
257
-add_action( 'getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date' );
257
+add_action('getpaid_subscription_admin_display_start_date', 'getpaid_admin_subscription_metabox_display_start_date');
258 258
 
259 259
 /**
260 260
  * Displays the subscription renewal date.
261 261
  *
262 262
  * @param WPInv_Subscription $subscription
263 263
  */
264
-function getpaid_admin_subscription_metabox_display_renews_on( $subscription ) {
265
-	echo getpaid_format_date_value( $subscription->get_expiration() );
264
+function getpaid_admin_subscription_metabox_display_renews_on($subscription) {
265
+	echo getpaid_format_date_value($subscription->get_expiration());
266 266
 }
267
-add_action( 'getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on' );
267
+add_action('getpaid_subscription_admin_display_renews_on', 'getpaid_admin_subscription_metabox_display_renews_on');
268 268
 
269 269
 /**
270 270
  * Displays the subscription renewal count.
271 271
  *
272 272
  * @param WPInv_Subscription $subscription
273 273
  */
274
-function getpaid_admin_subscription_metabox_display_renewals( $subscription ) {
274
+function getpaid_admin_subscription_metabox_display_renewals($subscription) {
275 275
 	$max_bills = $subscription->get_bill_times();
276
-	echo $subscription->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
276
+	echo $subscription->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
277 277
 }
278
-add_action( 'getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals' );
278
+add_action('getpaid_subscription_admin_display_renewals', 'getpaid_admin_subscription_metabox_display_renewals');
279 279
 /**
280 280
  * Displays the subscription item.
281 281
  *
282 282
  * @param WPInv_Subscription $subscription
283 283
  */
284
-function getpaid_admin_subscription_metabox_display_item( $subscription ) {
284
+function getpaid_admin_subscription_metabox_display_item($subscription) {
285 285
 
286
-	$item = get_post( $subscription->get_product_id() );
286
+	$item = get_post($subscription->get_product_id());
287 287
 
288
-	if ( ! empty( $item ) ) {
289
-		$link = get_edit_post_link( $item );
290
-		$link = esc_url( $link );
291
-		$name = esc_html( get_the_title( $item ) );
288
+	if (!empty($item)) {
289
+		$link = get_edit_post_link($item);
290
+		$link = esc_url($link);
291
+		$name = esc_html(get_the_title($item));
292 292
 		echo "<a href='$link'>$name</a>";
293 293
 	} else {
294
-		echo sprintf( __( 'Item #%s', 'invoicing' ), $subscription->get_product_id() );
294
+		echo sprintf(__('Item #%s', 'invoicing'), $subscription->get_product_id());
295 295
 	}
296 296
 
297 297
 }
298
-add_action( 'getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item' );
298
+add_action('getpaid_subscription_admin_display_item', 'getpaid_admin_subscription_metabox_display_item');
299 299
 
300 300
 /**
301 301
  * Displays the subscription gateway.
302 302
  *
303 303
  * @param WPInv_Subscription $subscription
304 304
  */
305
-function getpaid_admin_subscription_metabox_display_gateway( $subscription ) {
305
+function getpaid_admin_subscription_metabox_display_gateway($subscription) {
306 306
 
307 307
 	$gateway = $subscription->get_gateway();
308 308
 
309
-	if ( ! empty( $gateway ) ) {
310
-		echo sanitize_text_field( wpinv_get_gateway_admin_label( $gateway ) );
309
+	if (!empty($gateway)) {
310
+		echo sanitize_text_field(wpinv_get_gateway_admin_label($gateway));
311 311
 	} else {
312 312
 		echo "&mdash;";
313 313
 	}
314 314
 
315 315
 }
316
-add_action( 'getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway' );
316
+add_action('getpaid_subscription_admin_display_gateway', 'getpaid_admin_subscription_metabox_display_gateway');
317 317
 
318 318
 /**
319 319
  * Displays the subscription status.
320 320
  *
321 321
  * @param WPInv_Subscription $subscription
322 322
  */
323
-function getpaid_admin_subscription_metabox_display_status( $subscription ) {
323
+function getpaid_admin_subscription_metabox_display_status($subscription) {
324 324
 	echo $subscription->get_status_label_html();
325 325
 }
326
-add_action( 'getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status' );
326
+add_action('getpaid_subscription_admin_display_status', 'getpaid_admin_subscription_metabox_display_status');
327 327
 
328 328
 /**
329 329
  * Displays the subscription profile id.
330 330
  *
331 331
  * @param WPInv_Subscription $subscription
332 332
  */
333
-function getpaid_admin_subscription_metabox_display_profile_id( $subscription ) {
333
+function getpaid_admin_subscription_metabox_display_profile_id($subscription) {
334 334
 
335 335
 	$profile_id = $subscription->get_profile_id();
336 336
 
337
-	if ( ! empty( $profile_id ) ) {
338
-		$profile_id = sanitize_text_field( $profile_id );
339
-		echo apply_filters( 'getpaid_subscription_profile_id_display', $profile_id, $subscription );
337
+	if (!empty($profile_id)) {
338
+		$profile_id = sanitize_text_field($profile_id);
339
+		echo apply_filters('getpaid_subscription_profile_id_display', $profile_id, $subscription);
340 340
 	} else {
341 341
 		echo "&mdash;";
342 342
 	}
343 343
 
344 344
 }
345
-add_action( 'getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id' );
345
+add_action('getpaid_subscription_admin_display_profile_id', 'getpaid_admin_subscription_metabox_display_profile_id');
346 346
 
347 347
 /**
348 348
  * Displays the subscriptions update metabox.
349 349
  * 
350 350
  * @param WPInv_Subscription $subscription
351 351
  */
352
-function getpaid_admin_subscription_update_metabox( $subscription ) {
352
+function getpaid_admin_subscription_update_metabox($subscription) {
353 353
 
354 354
 	?>
355 355
 	<div class="mt-3">
@@ -362,10 +362,10 @@  discard block
 block discarded – undo
362 362
 					'id'               => 'subscription_status_update_select',
363 363
 					'required'         => true,
364 364
 					'no_wrap'          => false,
365
-					'label'            => __( 'Subscription Status', 'invoicing' ),
366
-					'help_text'        => __( 'Updating the status will trigger related actions and hooks', 'invoicing' ),
365
+					'label'            => __('Subscription Status', 'invoicing'),
366
+					'help_text'        => __('Updating the status will trigger related actions and hooks', 'invoicing'),
367 367
 					'select2'          => true,
368
-					'value'            => $subscription->get_status( 'edit' ),
368
+					'value'            => $subscription->get_status('edit'),
369 369
 				)
370 370
 			);
371 371
 		?>
@@ -373,13 +373,13 @@  discard block
 block discarded – undo
373 373
 		<div class="mt-2 px-3 py-2 bg-light border-top" style="margin: -12px;">
374 374
 	
375 375
 		<?php
376
-			submit_button( __( 'Update', 'invoicing' ), 'primary', 'submit', false );
376
+			submit_button(__('Update', 'invoicing'), 'primary', 'submit', false);
377 377
 
378
-			$url    = esc_url( wp_nonce_url( add_query_arg( 'getpaid-admin-action', 'subscription_manual_renew' ), 'getpaid-nonce', 'getpaid-nonce' ) );
379
-			$anchor = __( 'Renew Subscription', 'invoicing' );
380
-			$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' );
378
+			$url    = esc_url(wp_nonce_url(add_query_arg('getpaid-admin-action', 'subscription_manual_renew'), 'getpaid-nonce', 'getpaid-nonce'));
379
+			$anchor = __('Renew Subscription', 'invoicing');
380
+			$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');
381 381
 
382
-			if ( $subscription->is_active() ) {
382
+			if ($subscription->is_active()) {
383 383
 				echo "<a href='$url' class='float-right text-muted' onclick='return confirm(\"$title\")'>$anchor</a>";
384 384
 			}
385 385
 
@@ -391,16 +391,16 @@  discard block
 block discarded – undo
391 391
  * 
392 392
  * @param WPInv_Subscription $subscription
393 393
  */
394
-function getpaid_admin_subscription_invoice_details_metabox( $subscription ) {
394
+function getpaid_admin_subscription_invoice_details_metabox($subscription) {
395 395
 
396 396
 	$columns = apply_filters(
397 397
 		'getpaid_subscription_related_invoices_columns',
398 398
 		array(
399
-			'invoice'      => __( 'Invoice', 'invoicing' ),
400
-			'relationship' => __( 'Relationship', 'invoicing' ),
401
-			'date'         => __( 'Date', 'invoicing' ),
402
-			'status'       => __( 'Status', 'invoicing' ),
403
-			'total'        => __( 'Total', 'invoicing' ),
399
+			'invoice'      => __('Invoice', 'invoicing'),
400
+			'relationship' => __('Relationship', 'invoicing'),
401
+			'date'         => __('Date', 'invoicing'),
402
+			'status'       => __('Status', 'invoicing'),
403
+			'total'        => __('Total', 'invoicing'),
404 404
 		),
405 405
 		$subscription
406 406
 	);
@@ -409,13 +409,13 @@  discard block
 block discarded – undo
409 409
 	$payments = $subscription->get_child_payments();
410 410
 	$parent   = $subscription->get_parent_invoice();
411 411
 
412
-	if ( $parent->get_id() ) {
413
-		$payments = array_merge( array( $parent ), $payments );
412
+	if ($parent->get_id()) {
413
+		$payments = array_merge(array($parent), $payments);
414 414
 	}
415 415
 	
416 416
 	$table_class = 'w-100 bg-white';
417 417
 
418
-	if ( ! is_admin() ) {
418
+	if (!is_admin()) {
419 419
 		$table_class = 'table table-bordered table-striped';
420 420
 	}
421 421
 
@@ -427,9 +427,9 @@  discard block
 block discarded – undo
427 427
 				<thead>
428 428
 					<tr>
429 429
 						<?php
430
-							foreach ( $columns as $key => $label ) {
431
-								$key   = esc_attr( $key );
432
-								$label = sanitize_text_field( $label );
430
+							foreach ($columns as $key => $label) {
431
+								$key   = esc_attr($key);
432
+								$label = sanitize_text_field($label);
433 433
 
434 434
 								echo "<th class='subscription-invoice-field-$key bg-light p-2 text-left color-dark'>$label</th>";
435 435
 							}
@@ -439,50 +439,50 @@  discard block
 block discarded – undo
439 439
 
440 440
 				<tbody>
441 441
 
442
-					<?php if ( empty( $payments ) ) : ?>
442
+					<?php if (empty($payments)) : ?>
443 443
 						<tr>
444 444
 							<td colspan="<?php echo count($columns); ?>" class="p-2 text-left text-muted">
445
-								<?php _e( 'This subscription has no invoices.', 'invoicing' ); ?>
445
+								<?php _e('This subscription has no invoices.', 'invoicing'); ?>
446 446
 							</td>
447 447
 						</tr>
448 448
 					<?php endif; ?>
449 449
 
450 450
 					<?php
451 451
 
452
-						foreach( $payments as $payment ) :
452
+						foreach ($payments as $payment) :
453 453
 
454 454
 							// Ensure that we have an invoice.
455
-							$payment = new WPInv_Invoice( $payment );
455
+							$payment = new WPInv_Invoice($payment);
456 456
 
457 457
 							// Abort if the invoice is invalid.
458
-							if ( ! $payment->get_id() ) {
458
+							if (!$payment->get_id()) {
459 459
 								continue;
460 460
 							}
461 461
 
462 462
 							echo '<tr>';
463 463
 
464
-								foreach ( array_keys( $columns ) as $key ) {
464
+								foreach (array_keys($columns) as $key) {
465 465
 									
466 466
 									echo '<td class="p-2 text-left">';
467 467
 
468
-										switch( $key ) {
468
+										switch ($key) {
469 469
 
470 470
 											case 'total':
471
-												echo '<strong>' . wpinv_price( wpinv_format_amount( wpinv_sanitize_amount( $payment->get_total ) ), $payment->get_currency() ) . '</strong>';
471
+												echo '<strong>' . wpinv_price(wpinv_format_amount(wpinv_sanitize_amount($payment->get_total)), $payment->get_currency()) . '</strong>';
472 472
 												break;
473 473
 
474 474
 											case 'relationship':
475
-												echo $payment->is_renewal() ? __( 'Renewal Invoice', 'invoicing' ) : __( 'Initial Invoice', 'invoicing' );
475
+												echo $payment->is_renewal() ? __('Renewal Invoice', 'invoicing') : __('Initial Invoice', 'invoicing');
476 476
 												break;
477 477
 
478 478
 											case 'date':
479
-												echo getpaid_format_date_value( $payment->get_date_created() );
479
+												echo getpaid_format_date_value($payment->get_date_created());
480 480
 												break;
481 481
 
482 482
 											case 'status':
483 483
 
484 484
 												$status = $payment->get_status_nicename();
485
-												if ( is_admin() ) {
485
+												if (is_admin()) {
486 486
 													$status = $payment->get_status_label_html();
487 487
 												}
488 488
 
@@ -490,13 +490,13 @@  discard block
 block discarded – undo
490 490
 												break;
491 491
 
492 492
 											case 'invoice':
493
-												$link    = esc_url( get_edit_post_link( $payment->get_id() ) );
493
+												$link = esc_url(get_edit_post_link($payment->get_id()));
494 494
 
495
-												if ( ! is_admin() ) {
496
-													$link = esc_url( $payment->get_view_url() );
495
+												if (!is_admin()) {
496
+													$link = esc_url($payment->get_view_url());
497 497
 												}
498 498
 
499
-												$invoice = sanitize_text_field( $payment->get_number() );
499
+												$invoice = sanitize_text_field($payment->get_number());
500 500
 												echo "<a href='$link'>$invoice</a>";
501 501
 												break;
502 502
 										}
Please login to merge, or discard this patch.
includes/admin/class-wpinv-subscriptions-list-table.php 2 patches
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 if ( ! defined( 'ABSPATH' ) ) exit;
7 7
 
8 8
 if ( ! class_exists( 'WP_List_Table' ) ) {
9
-	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
9
+    include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
12 12
 /**
@@ -14,373 +14,373 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class WPInv_Subscriptions_List_Table extends WP_List_Table {
16 16
 
17
-	/**
18
-	 * URL of this page
19
-	 *
20
-	 * @var   string
21
-	 * @since 1.0.19
22
-	 */
23
-	public $base_url;
24
-
25
-	/**
26
-	 * Query
27
-	 *
28
-	 * @var   GetPaid_Subscriptions_Query
29
-	 * @since 1.0.19
30
-	 */
31
-	public $query;
32
-
33
-	/**
34
-	 * Total subscriptions
35
-	 *
36
-	 * @var   string
37
-	 * @since 1.0.0
38
-	 */
39
-	public $total_count;
40
-
41
-	/**
42
-	 * Current status subscriptions
43
-	 *
44
-	 * @var   string
45
-	 * @since 1.0.0
46
-	 */
47
-	public $current_total_count;
48
-
49
-	/**
50
-	 * Status counts
51
-	 *
52
-	 * @var   array
53
-	 * @since 1.0.19
54
-	 */
55
-	public $status_counts;
56
-
57
-	/**
58
-	 * Number of results to show per page
59
-	 *
60
-	 * @var   int
61
-	 * @since 1.0.0
62
-	 */
63
-	public $per_page = 10;
64
-
65
-	/**
66
-	 *  Constructor function.
67
-	 */
68
-	public function __construct() {
69
-
70
-		parent::__construct(
71
-			array(
72
-				'singular' => 'subscription',
73
-				'plural'   => 'subscriptions',
74
-			)
75
-		);
76
-
77
-		$this->process_bulk_action();
78
-
79
-		$this->prepare_query();
80
-
81
-		$this->base_url = remove_query_arg( 'status' );
82
-
83
-	}
84
-
85
-	/**
86
-	 *  Prepares the display query
87
-	 */
88
-	public function prepare_query() {
89
-
90
-		// Prepare query args.
91
-		$query = array(
92
-			'number'  => $this->per_page,
93
-			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
-		);
98
-
99
-		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
101
-		$this->total_count         = $this->query->get_total();
102
-		$this->current_total_count = $this->query->get_total();
103
-		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
-
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
-		}
110
-
111
-	}
112
-
113
-	/**
114
-	 * Gets the list of views available on this table.
115
-	 *
116
-	 * The format is an associative array:
117
-	 * - `'id' => 'link'`
118
-	 *
119
-	 * @since 1.0.0
120
-	 *
121
-	 * @return array
122
-	 */
123
-	public function get_views() {
124
-
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
-		$views    = array(
127
-
128
-			'all' => sprintf(
129
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
-				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
133
-				$this->total_count
134
-			)
135
-
136
-		);
137
-
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
-
140
-			$views[ $status ] = sprintf(
141
-				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
-				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
-				$count
146
-			);
147
-
148
-		}
149
-
150
-		return $views;
151
-
152
-	}
153
-
154
-	/**
155
-	 * Render most columns
156
-	 *
157
-	 * @access      private
158
-	 * @since       1.0.0
159
-	 * @return      string
160
-	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
-	}
164
-
165
-	/**
166
-	 * This is how checkbox column renders.
167
-	 *
168
-	 * @param WPInv_Subscription $item
169
-	 * @return string
170
-	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
-	}
174
-
175
-	/**
176
-	 * Status column
177
-	 *
178
-	 * @param WPInv_Subscription $item
179
-	 * @since       1.0.0
180
-	 * @return      string
181
-	 */
182
-	public function column_status( $item ) {
183
-		return $item->get_status_label_html();
184
-	}
185
-
186
-	/**
187
-	 * Subscription column
188
-	 *
189
-	 * @param WPInv_Subscription $item
190
-	 * @since       1.0.0
191
-	 * @return      string
192
-	 */
193
-	public function column_subscription( $item ) {
194
-
195
-		$username = __( '(Missing User)', 'invoicing' );
196
-
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
199
-
200
-			$username = sprintf(
201
-				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
-			);
205
-
206
-		}
207
-
208
-		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
-		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
-			$username
214
-		);
215
-
216
-		$row_actions = array();
217
-
218
-		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
-
222
-		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
224
-
225
-		if ( ! empty( $invoice ) ) {
226
-			$view_url    = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
-		}
229
-
230
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
-
232
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
-	}
234
-
235
-	/**
236
-	 * Renewal date column
237
-	 *
238
-	 * @param WPInv_Subscription $item
239
-	 * @since       1.0.0
240
-	 * @return      string
241
-	 */
242
-	public function column_renewal_date( $item ) {
243
-		return getpaid_format_date_value( $item->get_expiration() );
244
-	}
245
-
246
-	/**
247
-	 * Start date column
248
-	 *
249
-	 * @param WPInv_Subscription $item
250
-	 * @since       1.0.0
251
-	 * @return      string
252
-	 */
253
-	public function column_start_date( $item ) {
254
-		return getpaid_format_date_value( $item->get_date_created() );
255
-	}
256
-
257
-	/**
258
-	 * Amount column
259
-	 *
260
-	 * @param WPInv_Subscription $item
261
-	 * @since       1.0.19
262
-	 * @return      string
263
-	 */
264
-	public function column_amount( $item ) {
265
-		$amount = getpaid_get_formatted_subscription_amount( $item );
266
-		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
267
-	}
268
-
269
-	/**
270
-	 * Billing Times column
271
-	 *
272
-	 * @param WPInv_Subscription $item
273
-	 * @since       1.0.0
274
-	 * @return      string
275
-	 */
276
-	public function column_renewals( $item ) {
277
-		$max_bills = $item->get_bill_times();
278
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
279
-	}
280
-
281
-	/**
282
-	 * Product ID column
283
-	 *
284
-	 * @param WPInv_Subscription $item
285
-	 * @since       1.0.0
286
-	 * @return      string
287
-	 */
288
-	public function column_item( $item ) {
289
-		$_item = get_post( $item->get_product_id() );
290
-
291
-		if ( ! empty( $_item ) ) {
292
-			$link = get_edit_post_link( $_item );
293
-			$link = esc_url( $link );
294
-			$name = esc_html( get_the_title( $_item ) );
295
-			return "<a href='$link'>$name</a>";
296
-		} else {
297
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
298
-		}
299
-
300
-	}
301
-
302
-	/**
303
-	 * Retrieve the current page number
304
-	 *
305
-	 * @return      int
306
-	 */
307
-	public function get_paged() {
308
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
309
-	}
310
-
311
-	/**
312
-	 * Setup the final data for the table
313
-	 *
314
-	 */
315
-	public function prepare_items() {
316
-
317
-		$columns  = $this->get_columns();
318
-		$hidden   = array();
319
-		$sortable = $this->get_sortable_columns();
320
-
321
-		$this->_column_headers = array( $columns, $hidden, $sortable );
322
-
323
-		$this->set_pagination_args(
324
-			array(
325
-			'total_items' => $this->current_total_count,
326
-			'per_page'    => $this->per_page,
327
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
328
-			)
329
-		);
330
-	}
331
-
332
-	/**
333
-	 * Table columns
334
-	 *
335
-	 * @return array
336
-	 */
337
-	public function get_columns(){
338
-		$columns = array(
339
-			'cb'                => '<input type="checkbox" />',
340
-			'subscription'      => __( 'Subscription', 'invoicing' ),
341
-			'start_date'        => __( 'Start Date', 'invoicing' ),
342
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
343
-			'renewals'          => __( 'Payments', 'invoicing' ),
344
-			'item'              => __( 'Item', 'invoicing' ),
345
-			'status'            => __( 'Status', 'invoicing' ),
346
-		);
347
-
348
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
349
-	}
350
-
351
-	/**
352
-	 * Sortable table columns.
353
-	 *
354
-	 * @return array
355
-	 */
356
-	public function get_sortable_columns() {
357
-		$sortable = array(
358
-			'subscription' => array( 'id', true ),
359
-			'start_date'   => array( 'created', true ),
360
-			'renewal_date' => array( 'expiration', true ),
361
-			'renewals'     => array( 'bill_times', true ),
362
-			'item'         => array( 'product_id', true ),
363
-			'status'       => array( 'status', true ),
364
-		);
365
-
366
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
367
-	}
368
-
369
-	/**
370
-	 * Whether the table has items to display or not
371
-	 *
372
-	 * @return bool
373
-	 */
374
-	public function has_items() {
375
-		return ! empty( $this->current_total_count );
376
-	}
377
-
378
-	/**
379
-	 * Processes bulk actions.
380
-	 *
381
-	 */
382
-	public function process_bulk_action() {
383
-
384
-	}
17
+    /**
18
+     * URL of this page
19
+     *
20
+     * @var   string
21
+     * @since 1.0.19
22
+     */
23
+    public $base_url;
24
+
25
+    /**
26
+     * Query
27
+     *
28
+     * @var   GetPaid_Subscriptions_Query
29
+     * @since 1.0.19
30
+     */
31
+    public $query;
32
+
33
+    /**
34
+     * Total subscriptions
35
+     *
36
+     * @var   string
37
+     * @since 1.0.0
38
+     */
39
+    public $total_count;
40
+
41
+    /**
42
+     * Current status subscriptions
43
+     *
44
+     * @var   string
45
+     * @since 1.0.0
46
+     */
47
+    public $current_total_count;
48
+
49
+    /**
50
+     * Status counts
51
+     *
52
+     * @var   array
53
+     * @since 1.0.19
54
+     */
55
+    public $status_counts;
56
+
57
+    /**
58
+     * Number of results to show per page
59
+     *
60
+     * @var   int
61
+     * @since 1.0.0
62
+     */
63
+    public $per_page = 10;
64
+
65
+    /**
66
+     *  Constructor function.
67
+     */
68
+    public function __construct() {
69
+
70
+        parent::__construct(
71
+            array(
72
+                'singular' => 'subscription',
73
+                'plural'   => 'subscriptions',
74
+            )
75
+        );
76
+
77
+        $this->process_bulk_action();
78
+
79
+        $this->prepare_query();
80
+
81
+        $this->base_url = remove_query_arg( 'status' );
82
+
83
+    }
84
+
85
+    /**
86
+     *  Prepares the display query
87
+     */
88
+    public function prepare_query() {
89
+
90
+        // Prepare query args.
91
+        $query = array(
92
+            'number'  => $this->per_page,
93
+            'paged'   => $this->get_paged(),
94
+            'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
+            'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
+            'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
97
+        );
98
+
99
+        // Prepare class properties.
100
+        $this->query               = new GetPaid_Subscriptions_Query( $query );
101
+        $this->total_count         = $this->query->get_total();
102
+        $this->current_total_count = $this->query->get_total();
103
+        $this->items               = $this->query->get_results();
104
+        $this->status_counts       = getpaid_get_subscription_status_counts( $query );
105
+
106
+        if ( 'all' != $query['status'] ) {
107
+            unset( $query['status'] );
108
+            $this->total_count   = getpaid_get_subscriptions( $query, 'count' );
109
+        }
110
+
111
+    }
112
+
113
+    /**
114
+     * Gets the list of views available on this table.
115
+     *
116
+     * The format is an associative array:
117
+     * - `'id' => 'link'`
118
+     *
119
+     * @since 1.0.0
120
+     *
121
+     * @return array
122
+     */
123
+    public function get_views() {
124
+
125
+        $current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
126
+        $views    = array(
127
+
128
+            'all' => sprintf(
129
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
+                esc_url( add_query_arg( 'status', false, $this->base_url ) ),
131
+                $current === 'all' ? ' class="current"' : '',
132
+                __('All','invoicing' ),
133
+                $this->total_count
134
+            )
135
+
136
+        );
137
+
138
+        foreach ( array_filter( $this->status_counts ) as $status => $count ) {
139
+
140
+            $views[ $status ] = sprintf(
141
+                '<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
+                esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
143
+                $current === $status ? ' class="current"' : '',
144
+                sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
145
+                $count
146
+            );
147
+
148
+        }
149
+
150
+        return $views;
151
+
152
+    }
153
+
154
+    /**
155
+     * Render most columns
156
+     *
157
+     * @access      private
158
+     * @since       1.0.0
159
+     * @return      string
160
+     */
161
+    public function column_default( $item, $column_name ) {
162
+        return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
163
+    }
164
+
165
+    /**
166
+     * This is how checkbox column renders.
167
+     *
168
+     * @param WPInv_Subscription $item
169
+     * @return string
170
+     */
171
+    public function column_cb( $item ) {
172
+        return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
173
+    }
174
+
175
+    /**
176
+     * Status column
177
+     *
178
+     * @param WPInv_Subscription $item
179
+     * @since       1.0.0
180
+     * @return      string
181
+     */
182
+    public function column_status( $item ) {
183
+        return $item->get_status_label_html();
184
+    }
185
+
186
+    /**
187
+     * Subscription column
188
+     *
189
+     * @param WPInv_Subscription $item
190
+     * @since       1.0.0
191
+     * @return      string
192
+     */
193
+    public function column_subscription( $item ) {
194
+
195
+        $username = __( '(Missing User)', 'invoicing' );
196
+
197
+        $user = get_userdata( $item->get_customer_id() );
198
+        if ( $user ) {
199
+
200
+            $username = sprintf(
201
+                '<a href="user-edit.php?user_id=%s">%s</a>',
202
+                absint( $user->ID ),
203
+                ! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
204
+            );
205
+
206
+        }
207
+
208
+        // translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209
+        $column_content = sprintf(
210
+            _x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
+            '<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
+            '<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
213
+            $username
214
+        );
215
+
216
+        $row_actions = array();
217
+
218
+        // View subscription.
219
+        $view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
+        $row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
221
+
222
+        // View invoice.
223
+        $invoice = get_post( $item->get_parent_invoice_id() );
224
+
225
+        if ( ! empty( $invoice ) ) {
226
+            $view_url    = get_edit_post_link( $invoice );
227
+            $row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
228
+        }
229
+
230
+        $row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
231
+
232
+        return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
233
+    }
234
+
235
+    /**
236
+     * Renewal date column
237
+     *
238
+     * @param WPInv_Subscription $item
239
+     * @since       1.0.0
240
+     * @return      string
241
+     */
242
+    public function column_renewal_date( $item ) {
243
+        return getpaid_format_date_value( $item->get_expiration() );
244
+    }
245
+
246
+    /**
247
+     * Start date column
248
+     *
249
+     * @param WPInv_Subscription $item
250
+     * @since       1.0.0
251
+     * @return      string
252
+     */
253
+    public function column_start_date( $item ) {
254
+        return getpaid_format_date_value( $item->get_date_created() );
255
+    }
256
+
257
+    /**
258
+     * Amount column
259
+     *
260
+     * @param WPInv_Subscription $item
261
+     * @since       1.0.19
262
+     * @return      string
263
+     */
264
+    public function column_amount( $item ) {
265
+        $amount = getpaid_get_formatted_subscription_amount( $item );
266
+        return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
267
+    }
268
+
269
+    /**
270
+     * Billing Times column
271
+     *
272
+     * @param WPInv_Subscription $item
273
+     * @since       1.0.0
274
+     * @return      string
275
+     */
276
+    public function column_renewals( $item ) {
277
+        $max_bills = $item->get_bill_times();
278
+        return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
279
+    }
280
+
281
+    /**
282
+     * Product ID column
283
+     *
284
+     * @param WPInv_Subscription $item
285
+     * @since       1.0.0
286
+     * @return      string
287
+     */
288
+    public function column_item( $item ) {
289
+        $_item = get_post( $item->get_product_id() );
290
+
291
+        if ( ! empty( $_item ) ) {
292
+            $link = get_edit_post_link( $_item );
293
+            $link = esc_url( $link );
294
+            $name = esc_html( get_the_title( $_item ) );
295
+            return "<a href='$link'>$name</a>";
296
+        } else {
297
+            return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
298
+        }
299
+
300
+    }
301
+
302
+    /**
303
+     * Retrieve the current page number
304
+     *
305
+     * @return      int
306
+     */
307
+    public function get_paged() {
308
+        return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
309
+    }
310
+
311
+    /**
312
+     * Setup the final data for the table
313
+     *
314
+     */
315
+    public function prepare_items() {
316
+
317
+        $columns  = $this->get_columns();
318
+        $hidden   = array();
319
+        $sortable = $this->get_sortable_columns();
320
+
321
+        $this->_column_headers = array( $columns, $hidden, $sortable );
322
+
323
+        $this->set_pagination_args(
324
+            array(
325
+            'total_items' => $this->current_total_count,
326
+            'per_page'    => $this->per_page,
327
+            'total_pages' => ceil( $this->current_total_count / $this->per_page )
328
+            )
329
+        );
330
+    }
331
+
332
+    /**
333
+     * Table columns
334
+     *
335
+     * @return array
336
+     */
337
+    public function get_columns(){
338
+        $columns = array(
339
+            'cb'                => '<input type="checkbox" />',
340
+            'subscription'      => __( 'Subscription', 'invoicing' ),
341
+            'start_date'        => __( 'Start Date', 'invoicing' ),
342
+            'renewal_date'      => __( 'Next Payment', 'invoicing' ),
343
+            'renewals'          => __( 'Payments', 'invoicing' ),
344
+            'item'              => __( 'Item', 'invoicing' ),
345
+            'status'            => __( 'Status', 'invoicing' ),
346
+        );
347
+
348
+        return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
349
+    }
350
+
351
+    /**
352
+     * Sortable table columns.
353
+     *
354
+     * @return array
355
+     */
356
+    public function get_sortable_columns() {
357
+        $sortable = array(
358
+            'subscription' => array( 'id', true ),
359
+            'start_date'   => array( 'created', true ),
360
+            'renewal_date' => array( 'expiration', true ),
361
+            'renewals'     => array( 'bill_times', true ),
362
+            'item'         => array( 'product_id', true ),
363
+            'status'       => array( 'status', true ),
364
+        );
365
+
366
+        return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
367
+    }
368
+
369
+    /**
370
+     * Whether the table has items to display or not
371
+     *
372
+     * @return bool
373
+     */
374
+    public function has_items() {
375
+        return ! empty( $this->current_total_count );
376
+    }
377
+
378
+    /**
379
+     * Processes bulk actions.
380
+     *
381
+     */
382
+    public function process_bulk_action() {
383
+
384
+    }
385 385
 
386 386
 }
Please login to merge, or discard this patch.
Spacing   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -3,9 +3,9 @@  discard block
 block discarded – undo
3 3
  * Displays a list of all subscriptions rules
4 4
  */
5 5
 
6
-if ( ! defined( 'ABSPATH' ) ) exit;
6
+if (!defined('ABSPATH')) exit;
7 7
 
8
-if ( ! class_exists( 'WP_List_Table' ) ) {
8
+if (!class_exists('WP_List_Table')) {
9 9
 	include_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
10 10
 }
11 11
 
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 
79 79
 		$this->prepare_query();
80 80
 
81
-		$this->base_url = remove_query_arg( 'status' );
81
+		$this->base_url = remove_query_arg('status');
82 82
 
83 83
 	}
84 84
 
@@ -91,21 +91,21 @@  discard block
 block discarded – undo
91 91
 		$query = array(
92 92
 			'number'  => $this->per_page,
93 93
 			'paged'   => $this->get_paged(),
94
-			'status'  => ( isset( $_GET['status'] ) && array_key_exists( $_GET['status'], getpaid_get_subscription_statuses() ) ) ? $_GET['status'] : 'all',
95
-			'orderby' => ( isset( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id',
96
-			'order'   => ( isset( $_GET['order'] ) ) ? $_GET['order'] : 'DESC',
94
+			'status'  => (isset($_GET['status']) && array_key_exists($_GET['status'], getpaid_get_subscription_statuses())) ? $_GET['status'] : 'all',
95
+			'orderby' => (isset($_GET['orderby'])) ? $_GET['orderby'] : 'id',
96
+			'order'   => (isset($_GET['order'])) ? $_GET['order'] : 'DESC',
97 97
 		);
98 98
 
99 99
 		// Prepare class properties.
100
-		$this->query               = new GetPaid_Subscriptions_Query( $query );
100
+		$this->query               = new GetPaid_Subscriptions_Query($query);
101 101
 		$this->total_count         = $this->query->get_total();
102 102
 		$this->current_total_count = $this->query->get_total();
103 103
 		$this->items               = $this->query->get_results();
104
-		$this->status_counts       = getpaid_get_subscription_status_counts( $query );
104
+		$this->status_counts       = getpaid_get_subscription_status_counts($query);
105 105
 
106
-		if ( 'all' != $query['status'] ) {
107
-			unset( $query['status'] );
108
-			$this->total_count   = getpaid_get_subscriptions( $query, 'count' );
106
+		if ('all' != $query['status']) {
107
+			unset($query['status']);
108
+			$this->total_count = getpaid_get_subscriptions($query, 'count');
109 109
 		}
110 110
 
111 111
 	}
@@ -122,26 +122,26 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public function get_views() {
124 124
 
125
-		$current  = isset( $_GET['status'] ) ? $_GET['status'] : 'all';
125
+		$current  = isset($_GET['status']) ? $_GET['status'] : 'all';
126 126
 		$views    = array(
127 127
 
128 128
 			'all' => sprintf(
129 129
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
130
-				esc_url( add_query_arg( 'status', false, $this->base_url ) ),
130
+				esc_url(add_query_arg('status', false, $this->base_url)),
131 131
 				$current === 'all' ? ' class="current"' : '',
132
-				__('All','invoicing' ),
132
+				__('All', 'invoicing'),
133 133
 				$this->total_count
134 134
 			)
135 135
 
136 136
 		);
137 137
 
138
-		foreach ( array_filter( $this->status_counts ) as $status => $count ) {
138
+		foreach (array_filter($this->status_counts) as $status => $count) {
139 139
 
140
-			$views[ $status ] = sprintf(
140
+			$views[$status] = sprintf(
141 141
 				'<a href="%s" %s>%s&nbsp;<span class="count">(%d)</span></a>',
142
-				esc_url( add_query_arg( 'status', urlencode( $status ), $this->base_url ) ),
142
+				esc_url(add_query_arg('status', urlencode($status), $this->base_url)),
143 143
 				$current === $status ? ' class="current"' : '',
144
-				sanitize_text_field( getpaid_get_subscription_status_label( $status ) ),
144
+				sanitize_text_field(getpaid_get_subscription_status_label($status)),
145 145
 				$count
146 146
 			);
147 147
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @since       1.0.0
159 159
 	 * @return      string
160 160
 	 */
161
-	public function column_default( $item, $column_name ) {
162
-		return apply_filters( "getpaid_subscriptions_table_column_$column_name", $item->$column_name );
161
+	public function column_default($item, $column_name) {
162
+		return apply_filters("getpaid_subscriptions_table_column_$column_name", $item->$column_name);
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,8 +168,8 @@  discard block
 block discarded – undo
168 168
 	 * @param WPInv_Subscription $item
169 169
 	 * @return string
170 170
 	 */
171
-	public function column_cb( $item ) {
172
-		return sprintf( '<input type="checkbox" name="id[]" value="%s" />', esc_html( $item->get_id() ) );
171
+	public function column_cb($item) {
172
+		return sprintf('<input type="checkbox" name="id[]" value="%s" />', esc_html($item->get_id()));
173 173
 	}
174 174
 
175 175
 	/**
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
 	 * @since       1.0.0
180 180
 	 * @return      string
181 181
 	 */
182
-	public function column_status( $item ) {
182
+	public function column_status($item) {
183 183
 		return $item->get_status_label_html();
184 184
 	}
185 185
 
@@ -190,46 +190,46 @@  discard block
 block discarded – undo
190 190
 	 * @since       1.0.0
191 191
 	 * @return      string
192 192
 	 */
193
-	public function column_subscription( $item ) {
193
+	public function column_subscription($item) {
194 194
 
195
-		$username = __( '(Missing User)', 'invoicing' );
195
+		$username = __('(Missing User)', 'invoicing');
196 196
 
197
-		$user = get_userdata( $item->get_customer_id() );
198
-		if ( $user ) {
197
+		$user = get_userdata($item->get_customer_id());
198
+		if ($user) {
199 199
 
200 200
 			$username = sprintf(
201 201
 				'<a href="user-edit.php?user_id=%s">%s</a>',
202
-				absint( $user->ID ),
203
-				! empty( $user->display_name ) ? sanitize_text_field( $user->display_name ) : sanitize_email( $user->user_email )
202
+				absint($user->ID),
203
+				!empty($user->display_name) ? sanitize_text_field($user->display_name) : sanitize_email($user->user_email)
204 204
 			);
205 205
 
206 206
 		}
207 207
 
208 208
 		// translators: $1: is opening link, $2: is subscription id number, $3: is closing link tag, $4: is user's name
209 209
 		$column_content = sprintf(
210
-			_x( '%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing' ),
211
-			'<a href="' . esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . absint( $item->get_id() ) ) ) . '">',
212
-			'<strong>' . esc_attr( $item->get_id() ) . '</strong>', '</a>',
210
+			_x('%1$s#%2$s%3$s for %4$s', 'Subscription title on admin table. (e.g.: #211 for John Doe)', 'invoicing'),
211
+			'<a href="' . esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . absint($item->get_id()))) . '">',
212
+			'<strong>' . esc_attr($item->get_id()) . '</strong>', '</a>',
213 213
 			$username
214 214
 		);
215 215
 
216 216
 		$row_actions = array();
217 217
 
218 218
 		// View subscription.
219
-		$view_url    = esc_url( add_query_arg( 'id', $item->get_id(), admin_url( 'admin.php?page=wpinv-subscriptions' ) ));
220
-		$row_actions['view'] = '<a href="' . $view_url . '">' . __( 'View Subscription', 'invoicing' ) . '</a>';
219
+		$view_url    = esc_url(add_query_arg('id', $item->get_id(), admin_url('admin.php?page=wpinv-subscriptions')));
220
+		$row_actions['view'] = '<a href="' . $view_url . '">' . __('View Subscription', 'invoicing') . '</a>';
221 221
 
222 222
 		// View invoice.
223
-		$invoice = get_post( $item->get_parent_invoice_id() );
223
+		$invoice = get_post($item->get_parent_invoice_id());
224 224
 
225
-		if ( ! empty( $invoice ) ) {
226
-			$view_url    = get_edit_post_link( $invoice );
227
-			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __( 'View Invoice', 'invoicing' ) . '</a>';
225
+		if (!empty($invoice)) {
226
+			$view_url = get_edit_post_link($invoice);
227
+			$row_actions['invoice'] = '<a href="' . $view_url . '">' . __('View Invoice', 'invoicing') . '</a>';
228 228
 		}
229 229
 
230
-		$row_actions = $this->row_actions( apply_filters( 'getpaid_subscription_table_row_actions', $row_actions, $item ) );
230
+		$row_actions = $this->row_actions(apply_filters('getpaid_subscription_table_row_actions', $row_actions, $item));
231 231
 
232
-		return "<strong>$column_content</strong>" . $this->column_amount( $item ) . $row_actions;
232
+		return "<strong>$column_content</strong>" . $this->column_amount($item) . $row_actions;
233 233
 	}
234 234
 
235 235
 	/**
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 	 * @since       1.0.0
240 240
 	 * @return      string
241 241
 	 */
242
-	public function column_renewal_date( $item ) {
243
-		return getpaid_format_date_value( $item->get_expiration() );
242
+	public function column_renewal_date($item) {
243
+		return getpaid_format_date_value($item->get_expiration());
244 244
 	}
245 245
 
246 246
 	/**
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	 * @since       1.0.0
251 251
 	 * @return      string
252 252
 	 */
253
-	public function column_start_date( $item ) {
254
-		return getpaid_format_date_value( $item->get_date_created() );
253
+	public function column_start_date($item) {
254
+		return getpaid_format_date_value($item->get_date_created());
255 255
 	}
256 256
 
257 257
 	/**
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 	 * @since       1.0.19
262 262
 	 * @return      string
263 263
 	 */
264
-	public function column_amount( $item ) {
265
-		$amount = getpaid_get_formatted_subscription_amount( $item );
264
+	public function column_amount($item) {
265
+		$amount = getpaid_get_formatted_subscription_amount($item);
266 266
 		return "<span class='text-muted form-text mt-2 mb-2'>$amount</span>";
267 267
 	}
268 268
 
@@ -273,9 +273,9 @@  discard block
 block discarded – undo
273 273
 	 * @since       1.0.0
274 274
 	 * @return      string
275 275
 	 */
276
-	public function column_renewals( $item ) {
276
+	public function column_renewals($item) {
277 277
 		$max_bills = $item->get_bill_times();
278
-		return $item->get_times_billed() . ' / ' . ( empty( $max_bills ) ? "&infin;" : $max_bills );
278
+		return $item->get_times_billed() . ' / ' . (empty($max_bills) ? "&infin;" : $max_bills);
279 279
 	}
280 280
 
281 281
 	/**
@@ -285,16 +285,16 @@  discard block
 block discarded – undo
285 285
 	 * @since       1.0.0
286 286
 	 * @return      string
287 287
 	 */
288
-	public function column_item( $item ) {
289
-		$_item = get_post( $item->get_product_id() );
288
+	public function column_item($item) {
289
+		$_item = get_post($item->get_product_id());
290 290
 
291
-		if ( ! empty( $_item ) ) {
292
-			$link = get_edit_post_link( $_item );
293
-			$link = esc_url( $link );
294
-			$name = esc_html( get_the_title( $_item ) );
291
+		if (!empty($_item)) {
292
+			$link = get_edit_post_link($_item);
293
+			$link = esc_url($link);
294
+			$name = esc_html(get_the_title($_item));
295 295
 			return "<a href='$link'>$name</a>";
296 296
 		} else {
297
-			return sprintf( __( 'Item #%s', 'invoicing' ), $item->get_product_id() );
297
+			return sprintf(__('Item #%s', 'invoicing'), $item->get_product_id());
298 298
 		}
299 299
 
300 300
 	}
@@ -305,7 +305,7 @@  discard block
 block discarded – undo
305 305
 	 * @return      int
306 306
 	 */
307 307
 	public function get_paged() {
308
-		return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
308
+		return isset($_GET['paged']) ? absint($_GET['paged']) : 1;
309 309
 	}
310 310
 
311 311
 	/**
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
 		$hidden   = array();
319 319
 		$sortable = $this->get_sortable_columns();
320 320
 
321
-		$this->_column_headers = array( $columns, $hidden, $sortable );
321
+		$this->_column_headers = array($columns, $hidden, $sortable);
322 322
 
323 323
 		$this->set_pagination_args(
324 324
 			array(
325 325
 			'total_items' => $this->current_total_count,
326 326
 			'per_page'    => $this->per_page,
327
-			'total_pages' => ceil( $this->current_total_count / $this->per_page )
327
+			'total_pages' => ceil($this->current_total_count / $this->per_page)
328 328
 			)
329 329
 		);
330 330
 	}
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
 	 *
335 335
 	 * @return array
336 336
 	 */
337
-	public function get_columns(){
337
+	public function get_columns() {
338 338
 		$columns = array(
339 339
 			'cb'                => '<input type="checkbox" />',
340
-			'subscription'      => __( 'Subscription', 'invoicing' ),
341
-			'start_date'        => __( 'Start Date', 'invoicing' ),
342
-			'renewal_date'      => __( 'Next Payment', 'invoicing' ),
343
-			'renewals'          => __( 'Payments', 'invoicing' ),
344
-			'item'              => __( 'Item', 'invoicing' ),
345
-			'status'            => __( 'Status', 'invoicing' ),
340
+			'subscription'      => __('Subscription', 'invoicing'),
341
+			'start_date'        => __('Start Date', 'invoicing'),
342
+			'renewal_date'      => __('Next Payment', 'invoicing'),
343
+			'renewals'          => __('Payments', 'invoicing'),
344
+			'item'              => __('Item', 'invoicing'),
345
+			'status'            => __('Status', 'invoicing'),
346 346
 		);
347 347
 
348
-		return apply_filters( 'manage_getpaid_subscriptions_table_columns', $columns );
348
+		return apply_filters('manage_getpaid_subscriptions_table_columns', $columns);
349 349
 	}
350 350
 
351 351
 	/**
@@ -355,15 +355,15 @@  discard block
 block discarded – undo
355 355
 	 */
356 356
 	public function get_sortable_columns() {
357 357
 		$sortable = array(
358
-			'subscription' => array( 'id', true ),
359
-			'start_date'   => array( 'created', true ),
360
-			'renewal_date' => array( 'expiration', true ),
361
-			'renewals'     => array( 'bill_times', true ),
362
-			'item'         => array( 'product_id', true ),
363
-			'status'       => array( 'status', true ),
358
+			'subscription' => array('id', true),
359
+			'start_date'   => array('created', true),
360
+			'renewal_date' => array('expiration', true),
361
+			'renewals'     => array('bill_times', true),
362
+			'item'         => array('product_id', true),
363
+			'status'       => array('status', true),
364 364
 		);
365 365
 
366
-		return apply_filters( 'manage_getpaid_subscriptions_sortable_table_columns', $sortable );
366
+		return apply_filters('manage_getpaid_subscriptions_sortable_table_columns', $sortable);
367 367
 	}
368 368
 
369 369
 	/**
@@ -372,7 +372,7 @@  discard block
 block discarded – undo
372 372
 	 * @return bool
373 373
 	 */
374 374
 	public function has_items() {
375
-		return ! empty( $this->current_total_count );
375
+		return !empty($this->current_total_count);
376 376
 	}
377 377
 
378 378
 	/**
Please login to merge, or discard this patch.
includes/admin/class-getpaid-post-types-admin.php 2 patches
Indentation   +615 added lines, -615 removed lines patch added patch discarded remove patch
@@ -13,616 +13,616 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Post_Types_Admin {
14 14
 
15 15
     /**
16
-	 * Hook in methods.
17
-	 */
18
-	public static function init() {
19
-
20
-		// Init metaboxes.
21
-		GetPaid_Metaboxes::init();
22
-
23
-		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
25
-
26
-		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
28
-
29
-		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
32
-
33
-		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
40
-
41
-		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
45
-
46
-		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
48
-
49
-		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
-	}
53
-
54
-	/**
55
-	 * Post updated messages.
56
-	 */
57
-	public static function post_updated_messages( $messages ) {
58
-		global $post;
59
-
60
-		$messages['wpi_discount'] = array(
61
-			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
72
-		);
73
-
74
-		$messages['wpi_payment_form'] = array(
75
-			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
-		);
87
-
88
-		return $messages;
89
-
90
-	}
91
-
92
-	/**
93
-	 * Post row actions.
94
-	 */
95
-	public static function post_row_actions( $actions, $post ) {
96
-
97
-		$post = get_post( $post );
98
-
99
-		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
103
-		}
104
-
105
-		return $actions;
106
-	}
107
-
108
-	/**
109
-	 * Returns an array of invoice table columns.
110
-	 */
111
-	public static function invoice_columns( $columns ) {
112
-
113
-		$columns = array(
114
-			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
-		);
123
-
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
125
-	}
126
-
127
-	/**
128
-	 * Displays invoice table columns.
129
-	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
131
-
132
-		$invoice = new WPInv_Invoice( $post_id );
133
-
134
-		switch ( $column_name ) {
135
-
136
-			case 'invoice_date' :
137
-				$date_time = esc_attr( $invoice->get_created_date() );
138
-				$date      = getpaid_format_date_value( $date_time );
139
-				echo "<span title='$date_time'>$date</span>";
140
-				break;
141
-
142
-			case 'amount' :
143
-
144
-				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
-
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
-					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150
-				} else {
151
-
152
-					$discount = $invoice->get_total_discount();
153
-
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
-						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157
-					} else {
158
-						echo $formated_amount;
159
-					}
160
-
161
-				}
162
-
163
-				break;
164
-
165
-			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
-
169
-				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
16
+     * Hook in methods.
17
+     */
18
+    public static function init() {
173 19
 
174
-					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
-				} else {
176
-					echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
-				}
20
+        // Init metaboxes.
21
+        GetPaid_Metaboxes::init();
178 22
 
179
-				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
23
+        // Filter the post updated messages.
24
+        add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
181 25
 
182
-					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
-					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
-					}
26
+        // Filter post actions.
27
+        add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
188 28
 
189
-					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
191
-						$due_date = $invoice->get_due_date();
192
-						$fomatted = getpaid_format_date( $due_date );
29
+        // Invoice table columns.
30
+        add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
+        add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
193 32
 
194
-						if ( ! empty( $fomatted ) ) {
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
196
-							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197
-						}
198
-					}
33
+        // Items table columns.
34
+        add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
+        add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
+        add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
+        add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
+        add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
+        add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
199 40
 
200
-				}
41
+        // Payment forms columns.
42
+        add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
+        add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
201 45
 
202
-				break;
46
+        // Discount table columns.
47
+        add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
203 48
 
204
-			case 'recurring':
49
+        // Deleting posts.
50
+        add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
+        add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
52
+    }
205 53
 
206
-				if ( $invoice->is_recurring() ) {
207
-					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
-				} else {
209
-					echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
-				}
211
-				break;
54
+    /**
55
+     * Post updated messages.
56
+     */
57
+    public static function post_updated_messages( $messages ) {
58
+        global $post;
59
+
60
+        $messages['wpi_discount'] = array(
61
+            0   => '',
62
+            1   => __( 'Discount updated.', 'invoicing' ),
63
+            2   => __( 'Custom field updated.', 'invoicing' ),
64
+            3   => __( 'Custom field deleted.', 'invoicing' ),
65
+            4   => __( 'Discount updated.', 'invoicing' ),
66
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
+            6   => __( 'Discount updated.', 'invoicing' ),
68
+            7   => __( 'Discount saved.', 'invoicing' ),
69
+            8   => __( 'Discount submitted.', 'invoicing' ),
70
+            9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
+            10  => __( 'Discount draft updated.', 'invoicing' ),
72
+        );
73
+
74
+        $messages['wpi_payment_form'] = array(
75
+            0   => '',
76
+            1   => __( 'Payment Form updated.', 'invoicing' ),
77
+            2   => __( 'Custom field updated.', 'invoicing' ),
78
+            3   => __( 'Custom field deleted.', 'invoicing' ),
79
+            4   => __( 'Payment Form updated.', 'invoicing' ),
80
+            5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
+            6   => __( 'Payment Form updated.', 'invoicing' ),
82
+            7   => __( 'Payment Form saved.', 'invoicing' ),
83
+            8   => __( 'Payment Form submitted.', 'invoicing' ),
84
+            9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
+            10  => __( 'Payment Form draft updated.', 'invoicing' ),
86
+        );
87
+
88
+        return $messages;
89
+
90
+    }
91
+
92
+    /**
93
+     * Post row actions.
94
+     */
95
+    public static function post_row_actions( $actions, $post ) {
96
+
97
+        $post = get_post( $post );
98
+
99
+        // We do not want to edit the default payment form.
100
+        if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
+            unset( $actions['trash'] );
102
+            unset( $actions['inline hide-if-no-js'] );
103
+        }
104
+
105
+        return $actions;
106
+    }
107
+
108
+    /**
109
+     * Returns an array of invoice table columns.
110
+     */
111
+    public static function invoice_columns( $columns ) {
112
+
113
+        $columns = array(
114
+            'cb'                => $columns['cb'],
115
+            'number'            => __( 'Invoice', 'invoicing' ),
116
+            'customer'          => __( 'Customer', 'invoicing' ),
117
+            'invoice_date'      => __( 'Date', 'invoicing' ),
118
+            'amount'            => __( 'Amount', 'invoicing' ),
119
+            'recurring'         => __( 'Recurring', 'invoicing' ),
120
+            'status'            => __( 'Status', 'invoicing' ),
121
+            'wpi_actions'       => __( 'Actions', 'invoicing' ),
122
+        );
123
+
124
+        return apply_filters( 'wpi_invoice_table_columns', $columns );
125
+    }
126
+
127
+    /**
128
+     * Displays invoice table columns.
129
+     */
130
+    public static function display_invoice_columns( $column_name, $post_id ) {
131
+
132
+        $invoice = new WPInv_Invoice( $post_id );
133
+
134
+        switch ( $column_name ) {
135
+
136
+            case 'invoice_date' :
137
+                $date_time = esc_attr( $invoice->get_created_date() );
138
+                $date      = getpaid_format_date_value( $date_time );
139
+                echo "<span title='$date_time'>$date</span>";
140
+                break;
141
+
142
+            case 'amount' :
143
+
144
+                $amount = $invoice->get_total();
145
+                $formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
146
+
147
+                if ( $invoice->is_refunded() ) {
148
+                    $refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
149
+                    echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150
+                } else {
151
+
152
+                    $discount = $invoice->get_total_discount();
153
+
154
+                    if ( ! empty( $discount ) ) {
155
+                        $new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
156
+                        echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157
+                    } else {
158
+                        echo $formated_amount;
159
+                    }
160
+
161
+                }
162
+
163
+                break;
164
+
165
+            case 'status' :
166
+                $status       = sanitize_text_field( $invoice->get_status() );
167
+                $status_label = sanitize_text_field( $invoice->get_status_nicename() );
168
+
169
+                // If it is paid, show the gateway title.
170
+                if ( $invoice->is_paid() ) {
171
+                    $gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
+                    $gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
212 173
 
213
-			case 'number' :
174
+                    echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175
+                } else {
176
+                    echo "<mark class='getpaid-invoice-status $status'><span>$status_label</span></mark>";
177
+                }
214 178
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
179
+                // If it is not paid, display the overdue and view status.
180
+                if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
218 181
 
219
-				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
182
+                    // Invoice view status.
183
+                    if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
185
+                    } else {
186
+                        echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
187
+                    }
220 188
 
221
-				break;
189
+                    // Display the overview status.
190
+                    if ( wpinv_get_option( 'overdue_active' ) ) {
191
+                        $due_date = $invoice->get_due_date();
192
+                        $fomatted = getpaid_format_date( $due_date );
222 193
 
223
-			case 'customer' :
194
+                        if ( ! empty( $fomatted ) ) {
195
+                            $date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
196
+                            echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197
+                        }
198
+                    }
199
+
200
+                }
201
+
202
+                break;
203
+
204
+            case 'recurring':
205
+
206
+                if ( $invoice->is_recurring() ) {
207
+                    echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208
+                } else {
209
+                    echo '<i class="fa fa-times" style="color:#616161;"></i>';
210
+                }
211
+                break;
212
+
213
+            case 'number' :
214
+
215
+                $edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
+                $invoice_number  = sanitize_text_field( $invoice->get_number() );
217
+                $invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
218
+
219
+                echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220
+
221
+                break;
222
+
223
+            case 'customer' :
224 224
 	
225
-				$customer_name = $invoice->get_user_full_name();
225
+                $customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
228
-					$customer_name = $invoice->get_email();
229
-				}
227
+                if ( empty( $customer_name ) ) {
228
+                    $customer_name = $invoice->get_email();
229
+                }
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
-					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
-				} else {
236
-					echo '<div>&mdash;</div>';
237
-				}
231
+                if ( ! empty( $customer_name ) ) {
232
+                    $customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
+                    $view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
234
+                    echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235
+                } else {
236
+                    echo '<div>&mdash;</div>';
237
+                }
238
+
239
+                break;
240
+
241
+            case 'wpi_actions' :
242
+
243
+                if ( $invoice->is_draft() ) {
244
+                    return;
245
+                }
246
+
247
+                $url    = esc_url( $invoice->get_view_url() );
248
+                $print  = esc_attr__( 'Print invoice', 'invoicing' );
249
+                echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250
+
251
+                $url    = esc_url(
252
+                    wp_nonce_url(
253
+                        add_query_arg(
254
+                            array(
255
+                                'getpaid-admin-action' => 'send_invoice',
256
+                                'invoice_id'           => $invoice->get_id()
257
+                            )
258
+                        ),
259
+                        'getpaid-nonce',
260
+                        'getpaid-nonce'
261
+                    )
262
+                );
263
+
264
+                $send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
+                echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266
+
267
+                break;
268
+        }
238 269
 
239
-				break;
270
+    }
240 271
 
241
-			case 'wpi_actions' :
242
-
243
-				if ( $invoice->is_draft() ) {
244
-					return;
245
-				}
246
-
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
249
-				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
272
+    /**
273
+     * Returns an array of payment forms table columns.
274
+     */
275
+    public static function payment_form_columns( $columns ) {
250 276
 
251
-				$url    = esc_url(
252
-					wp_nonce_url(
253
-						add_query_arg(
254
-							array(
255
-								'getpaid-admin-action' => 'send_invoice',
256
-								'invoice_id'           => $invoice->get_id()
257
-							)
258
-						),
259
-						'getpaid-nonce',
260
-						'getpaid-nonce'
261
-					)
262
-				);
277
+        $columns = array(
278
+            'cb'                => $columns['cb'],
279
+            'title'             => __( 'Name', 'invoicing' ),
280
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
+            'earnings'          => __( 'Revenue', 'invoicing' ),
282
+            'refunds'           => __( 'Refunded', 'invoicing' ),
283
+            'items'             => __( 'Items', 'invoicing' ),
284
+            'date'              => __( 'Date', 'invoicing' ),
285
+        );
263 286
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
265
-				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
287
+        return apply_filters( 'wpi_payment_form_table_columns', $columns );
266 288
 
267
-				break;
268
-		}
289
+    }
269 290
 
270
-	}
291
+    /**
292
+     * Displays payment form table columns.
293
+     */
294
+    public static function display_payment_form_columns( $column_name, $post_id ) {
271 295
 
272
-	/**
273
-	 * Returns an array of payment forms table columns.
274
-	 */
275
-	public static function payment_form_columns( $columns ) {
296
+        // Retrieve the payment form.
297
+        $form = new GetPaid_Payment_Form( $post_id );
276 298
 
277
-		$columns = array(
278
-			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
285
-		);
299
+        switch ( $column_name ) {
286 300
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
301
+            case 'earnings' :
302
+                echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
+                break;
288 304
 
289
-	}
305
+            case 'refunds' :
306
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
+                break;
290 308
 
291
-	/**
292
-	 * Displays payment form table columns.
293
-	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
309
+            case 'refunds' :
310
+                echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
+                break;
295 312
 
296
-		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
313
+            case 'shortcode' :
298 314
 
299
-		switch ( $column_name ) {
315
+                if ( $form->is_default() ) {
316
+                    echo '&mdash;';
317
+                } else {
318
+                    echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
+                }
300 320
 
301
-			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
303
-				break;
321
+                break;
304 322
 
305
-			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
307
-				break;
323
+            case 'items' :
308 324
 
309
-			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
311
-				break;
325
+                $items = $form->get_items();
312 326
 
313
-			case 'shortcode' :
327
+                if ( $form->is_default() || empty( $items ) ) {
328
+                    echo '&mdash;';
329
+                    return;
330
+                }
314 331
 
315
-				if ( $form->is_default() ) {
316
-					echo '&mdash;';
317
-				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
319
-				}
332
+                $_items = array();
320 333
 
321
-				break;
334
+                foreach ( $items as $item ) {
335
+                    $url = $item->get_edit_url();
322 336
 
323
-			case 'items' :
337
+                    if ( empty( $url ) ) {
338
+                        $_items[] = sanitize_text_field( $item->get_name() );
339
+                    } else {
340
+                        $_items[] = sprintf(
341
+                            '<a href="%s">%s</a>',
342
+                            esc_url( $url ),
343
+                            sanitize_text_field( $item->get_name() )
344
+                        );
345
+                    }
324 346
 
325
-				$items = $form->get_items();
347
+                }
326 348
 
327
-				if ( $form->is_default() || empty( $items ) ) {
328
-					echo '&mdash;';
329
-					return;
330
-				}
349
+                echo implode( '<br>', $_items );
331 350
 
332
-				$_items = array();
351
+                break;
333 352
 
334
-				foreach ( $items as $item ) {
335
-					$url = $item->get_edit_url();
353
+        }
336 354
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
339
-					} else {
340
-						$_items[] = sprintf(
341
-							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
344
-						);
345
-					}
355
+    }
346 356
 
347
-				}
357
+    /**
358
+     * Filters post states.
359
+     */
360
+    public static function filter_payment_form_state( $post_states, $post ) {
348 361
 
349
-				echo implode( '<br>', $_items );
362
+        if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
+            $post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
+        }
365
+	
366
+        return $post_states;
350 367
 
351
-				break;
368
+    }
352 369
 
353
-		}
370
+    /**
371
+     * Returns an array of coupon table columns.
372
+     */
373
+    public static function discount_columns( $columns ) {
374
+
375
+        $columns = array(
376
+            'cb'                => $columns['cb'],
377
+            'title'             => __( 'Name', 'invoicing' ),
378
+            'code'              => __( 'Code', 'invoicing' ),
379
+            'amount'            => __( 'Amount', 'invoicing' ),
380
+            'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
+            'start_date'        => __( 'Start Date', 'invoicing' ),
382
+            'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
+        );
384
+
385
+        return apply_filters( 'wpi_discount_table_columns', $columns );
386
+    }
354 387
 
355
-	}
388
+    /**
389
+     * Filters post states.
390
+     */
391
+    public static function filter_discount_state( $post_states, $post ) {
356 392
 
357
-	/**
358
-	 * Filters post states.
359
-	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
393
+        if ( 'wpi_discount' == $post->post_type ) {
361 394
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
364
-		}
365
-	
366
-		return $post_states;
395
+            $discount = new WPInv_Discount( $post );
367 396
 
368
-	}
397
+            $status = $discount->is_expired() ? 'expired' : $discount->get_status();
369 398
 
370
-	/**
371
-	 * Returns an array of coupon table columns.
372
-	 */
373
-	public static function discount_columns( $columns ) {
399
+            if ( $status != 'publish' ) {
400
+                return array(
401
+                    'discount_status' => wpinv_discount_status( $status ),
402
+                );
403
+            }
374 404
 
375
-		$columns = array(
376
-			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
383
-		);
405
+            return array();
384 406
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
386
-	}
407
+        }
387 408
 
388
-	/**
389
-	 * Filters post states.
390
-	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
409
+        return $post_states;
392 410
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
411
+    }
394 412
 
395
-			$discount = new WPInv_Discount( $post );
413
+    /**
414
+     * Returns an array of items table columns.
415
+     */
416
+    public static function item_columns( $columns ) {
417
+        global $wpinv_euvat;
418
+
419
+        $columns = array(
420
+            'cb'                => $columns['cb'],
421
+            'title'             => __( 'Name', 'invoicing' ),
422
+            'price'             => __( 'Price', 'invoicing' ),
423
+            'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
+            'vat_class'         => __( 'VAT class', 'invoicing' ),
425
+            'type'              => __( 'Type', 'invoicing' ),
426
+            'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
+        );
428
+
429
+        if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
+            unset( $columns['vat_rule'] );
431
+        }
396 432
 
397
-			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
433
+        if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
+            unset( $columns['vat_class'] );
435
+        }
398 436
 
399
-			if ( $status != 'publish' ) {
400
-				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
402
-				);
403
-			}
437
+        return apply_filters( 'wpi_item_table_columns', $columns );
438
+    }
404 439
 
405
-			return array();
440
+    /**
441
+     * Returns an array of sortable items table columns.
442
+     */
443
+    public static function sortable_item_columns( $columns ) {
444
+
445
+        return array_merge(
446
+            $columns,
447
+            array(
448
+                'price'     => 'price',
449
+                'vat_rule'  => 'vat_rule',
450
+                'vat_class' => 'vat_class',
451
+                'type'      => 'type',
452
+            )
453
+        );
454
+
455
+    }
406 456
 
407
-		}
457
+    /**
458
+     * Displays items table columns.
459
+     */
460
+    public static function display_item_columns( $column_name, $post_id ) {
461
+        global $wpinv_euvat;
408 462
 
409
-		return $post_states;
463
+        $item = new WPInv_Item( $post_id );
410 464
 
411
-	}
465
+        switch ( $column_name ) {
412 466
 
413
-	/**
414
-	 * Returns an array of items table columns.
415
-	 */
416
-	public static function item_columns( $columns ) {
417
-		global $wpinv_euvat;
467
+            case 'price' :
418 468
 
419
-		$columns = array(
420
-			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
427
-		);
469
+                if ( ! $item->is_recurring() ) {
470
+                    echo $item->get_the_price();
471
+                    break;
472
+                }
428 473
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
431
-		}
474
+                $price = wp_sprintf(
475
+                    __( '%s / %s', 'invoicing' ),
476
+                    $item->get_the_price(),
477
+                    getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
478
+                );
432 479
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
435
-		}
480
+                if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
+                    echo $price;
482
+                    break;
483
+                }
436 484
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
438
-	}
485
+                echo $item->get_the_initial_price();
439 486
 
440
-	/**
441
-	 * Returns an array of sortable items table columns.
442
-	 */
443
-	public static function sortable_item_columns( $columns ) {
487
+                echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
+                break;
444 489
 
445
-		return array_merge(
446
-			$columns,
447
-			array(
448
-				'price'     => 'price',
449
-				'vat_rule'  => 'vat_rule',
450
-				'vat_class' => 'vat_class',
451
-				'type'      => 'type',
452
-			)
453
-		);
490
+            case 'vat_rule' :
491
+                echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
+                break;
454 493
 
455
-	}
494
+            case 'vat_class' :
495
+                echo $wpinv_euvat->item_class_label( $item->get_id() );
496
+                break;
456 497
 
457
-	/**
458
-	 * Displays items table columns.
459
-	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
461
-		global $wpinv_euvat;
498
+            case 'shortcode' :
499
+                echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
+                break;
462 501
 
463
-		$item = new WPInv_Item( $post_id );
502
+            case 'type' :
503
+                echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
+                break;
464 505
 
465
-		switch ( $column_name ) {
506
+        }
466 507
 
467
-			case 'price' :
508
+    }
468 509
 
469
-				if ( ! $item->is_recurring() ) {
470
-					echo $item->get_the_price();
471
-					break;
472
-				}
510
+    /**
511
+     * Lets users filter items using taxes.
512
+     */
513
+    public static function add_item_filters( $post_type ) {
514
+        $wpinv_euvat = getpaid_tax();
515
+
516
+        // Abort if we're not dealing with items.
517
+        if ( $post_type != 'wpi_item' ) {
518
+            return;
519
+        }
520
+
521
+        // Filter by vat rules.
522
+        if ( $wpinv_euvat->allow_vat_rules() ) {
523
+	
524
+            // Sanitize selected vat rule.
525
+            $vat_rule   = '';
526
+            $vat_rules  = $wpinv_euvat->get_rules();
527
+            if ( isset( $_GET['vat_rule'] ) ) {
528
+                $vat_rule   =  $_GET['vat_rule'];
529
+            }
530
+
531
+            // Filter by VAT rule.
532
+            echo wpinv_html_select(
533
+                array(
534
+                    'options'          => array_merge(
535
+                        array(
536
+                            '' => __( 'All VAT rules', 'invoicing' )
537
+                        ),
538
+                        $vat_rules
539
+                    ),
540
+                    'name'             => 'vat_rule',
541
+                    'id'               => 'vat_rule',
542
+                    'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
543
+                    'show_option_all'  => false,
544
+                    'show_option_none' => false,
545
+                    'class'            => 'gdmbx2-text-medium',
546
+                )
547
+            );
548
+
549
+            // Filter by VAT class.
550
+        }
473 551
 
474
-				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
476
-					$item->get_the_price(),
477
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
478
-				);
552
+        // Filter by vat class.
553
+        if ( $wpinv_euvat->allow_vat_classes() ) {
554
+	
555
+            // Sanitize selected vat rule.
556
+            $vat_class   = '';
557
+            $vat_classes = $wpinv_euvat->get_all_classes();
558
+            if ( isset( $_GET['vat_class'] ) ) {
559
+                $vat_class   =  $_GET['vat_class'];
560
+            }
561
+
562
+            echo wpinv_html_select(
563
+                array(
564
+                    'options'          => array_merge(
565
+                        array(
566
+                            '' => __( 'All VAT classes', 'invoicing' )
567
+                        ),
568
+                        $vat_classes
569
+                    ),
570
+                    'name'             => 'vat_class',
571
+                    'id'               => 'vat_class',
572
+                    'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
573
+                    'show_option_all'  => false,
574
+                    'show_option_none' => false,
575
+                    'class'            => 'gdmbx2-text-medium',
576
+                )
577
+            );
479 578
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
481
-					echo $price;
482
-					break;
483
-				}
579
+        }
484 580
 
485
-				echo $item->get_the_initial_price();
581
+        // Filter by item type.
582
+        $type   = '';
583
+        if ( isset( $_GET['type'] ) ) {
584
+            $type   =  $_GET['type'];
585
+        }
486 586
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
488
-				break;
587
+        echo wpinv_html_select(
588
+            array(
589
+                'options'          => array_merge(
590
+                    array(
591
+                        '' => __( 'All item types', 'invoicing' )
592
+                    ),
593
+                    wpinv_get_item_types()
594
+                ),
595
+                'name'             => 'type',
596
+                'id'               => 'type',
597
+                'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
598
+                'show_option_all'  => false,
599
+                'show_option_none' => false,
600
+                'class'            => 'gdmbx2-text-medium',
601
+            )
602
+        );
603
+
604
+    }
489 605
 
490
-			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
492
-				break;
606
+    /**
607
+     * Filters the item query.
608
+     */
609
+    public static function filter_item_query( $query ) {
493 610
 
494
-			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
496
-				break;
611
+        // modify the query only if it admin and main query.
612
+        if ( ! ( is_admin() && $query->is_main_query() ) ){ 
613
+            return $query;
614
+        }
497 615
 
498
-			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500
-				break;
616
+        // we want to modify the query for our items.
617
+        if ( 'wpi_item' != $query->query['post_type'] ){
618
+            return $query;
619
+        }
501 620
 
502
-			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504
-				break;
621
+        if ( empty( $query->query_vars['meta_query'] ) ) {
622
+            $query->query_vars['meta_query'] = array();
623
+        }
505 624
 
506
-		}
507
-
508
-	}
509
-
510
-	/**
511
-	 * Lets users filter items using taxes.
512
-	 */
513
-	public static function add_item_filters( $post_type ) {
514
-		$wpinv_euvat = getpaid_tax();
515
-
516
-		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
518
-			return;
519
-		}
520
-
521
-		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
523
-	
524
-			// Sanitize selected vat rule.
525
-			$vat_rule   = '';
526
-			$vat_rules  = $wpinv_euvat->get_rules();
527
-			if ( isset( $_GET['vat_rule'] ) ) {
528
-				$vat_rule   =  $_GET['vat_rule'];
529
-			}
530
-
531
-			// Filter by VAT rule.
532
-			echo wpinv_html_select(
533
-				array(
534
-					'options'          => array_merge(
535
-						array(
536
-							'' => __( 'All VAT rules', 'invoicing' )
537
-						),
538
-						$vat_rules
539
-					),
540
-					'name'             => 'vat_rule',
541
-					'id'               => 'vat_rule',
542
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
543
-					'show_option_all'  => false,
544
-					'show_option_none' => false,
545
-					'class'            => 'gdmbx2-text-medium',
546
-				)
547
-			);
548
-
549
-			// Filter by VAT class.
550
-		}
551
-
552
-		// Filter by vat class.
553
-		if ( $wpinv_euvat->allow_vat_classes() ) {
554
-	
555
-			// Sanitize selected vat rule.
556
-			$vat_class   = '';
557
-			$vat_classes = $wpinv_euvat->get_all_classes();
558
-			if ( isset( $_GET['vat_class'] ) ) {
559
-				$vat_class   =  $_GET['vat_class'];
560
-			}
561
-
562
-			echo wpinv_html_select(
563
-				array(
564
-					'options'          => array_merge(
565
-						array(
566
-							'' => __( 'All VAT classes', 'invoicing' )
567
-						),
568
-						$vat_classes
569
-					),
570
-					'name'             => 'vat_class',
571
-					'id'               => 'vat_class',
572
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
573
-					'show_option_all'  => false,
574
-					'show_option_none' => false,
575
-					'class'            => 'gdmbx2-text-medium',
576
-				)
577
-			);
578
-
579
-		}
580
-
581
-		// Filter by item type.
582
-		$type   = '';
583
-		if ( isset( $_GET['type'] ) ) {
584
-			$type   =  $_GET['type'];
585
-		}
586
-
587
-		echo wpinv_html_select(
588
-			array(
589
-				'options'          => array_merge(
590
-					array(
591
-						'' => __( 'All item types', 'invoicing' )
592
-					),
593
-					wpinv_get_item_types()
594
-				),
595
-				'name'             => 'type',
596
-				'id'               => 'type',
597
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
598
-				'show_option_all'  => false,
599
-				'show_option_none' => false,
600
-				'class'            => 'gdmbx2-text-medium',
601
-			)
602
-		);
603
-
604
-	}
605
-
606
-	/**
607
-	 * Filters the item query.
608
-	 */
609
-	public static function filter_item_query( $query ) {
610
-
611
-		// modify the query only if it admin and main query.
612
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
613
-			return $query;
614
-		}
615
-
616
-		// we want to modify the query for our items.
617
-		if ( 'wpi_item' != $query->query['post_type'] ){
618
-			return $query;
619
-		}
620
-
621
-		if ( empty( $query->query_vars['meta_query'] ) ) {
622
-			$query->query_vars['meta_query'] = array();
623
-		}
624
-
625
-		// Filter vat rule type
625
+        // Filter vat rule type
626 626
         if ( ! empty( $_GET['vat_rule'] ) ) {
627 627
             $query->query_vars['meta_query'][] = array(
628 628
                 'key'     => '_wpinv_vat_rule',
@@ -647,94 +647,94 @@  discard block
 block discarded – undo
647 647
                 'value'   => sanitize_text_field( $_GET['type'] ),
648 648
                 'compare' => '='
649 649
             );
650
-		}
651
-
652
-	}
653
-
654
-	/**
655
-	 * Reorders items.
656
-	 */
657
-	public static function reorder_items( $vars ) {
658
-		global $typenow;
659
-
660
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
661
-			return $vars;
662
-		}
663
-
664
-		// By item type.
665
-		if ( 'type' == $vars['orderby'] ) {
666
-			return array_merge(
667
-				$vars,
668
-				array(
669
-					'meta_key' => '_wpinv_type',
670
-					'orderby'  => 'meta_value'
671
-				)
672
-			);
673
-		}
674
-
675
-		// By vat class.
676
-		if ( 'vat_class' == $vars['orderby'] ) {
677
-			return array_merge(
678
-				$vars,
679
-				array(
680
-					'meta_key' => '_wpinv_vat_class',
681
-					'orderby'  => 'meta_value'
682
-				)
683
-			);
684
-		}
685
-
686
-		// By vat rule.
687
-		if ( 'vat_rule' == $vars['orderby'] ) {
688
-			return array_merge(
689
-				$vars,
690
-				array(
691
-					'meta_key' => '_wpinv_vat_rule',
692
-					'orderby'  => 'meta_value'
693
-				)
694
-			);
695
-		}
696
-
697
-		// By price.
698
-		if ( 'price' == $vars['orderby'] ) {
699
-			return array_merge(
700
-				$vars,
701
-				array(
702
-					'meta_key' => '_wpinv_price',
703
-					'orderby'  => 'meta_value_num'
704
-				)
705
-			);
706
-		}
707
-
708
-		return $vars;
709
-
710
-	}
711
-
712
-	/**
713
-	 * Fired when deleting a post.
714
-	 */
715
-	public static function delete_post( $post_id ) {
716
-
717
-		switch ( get_post_type( $post_id ) ) {
718
-
719
-			case 'wpi_item' :
720
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
721
-				break;
722
-
723
-			case 'wpi_payment_form' :
724
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
725
-				break;
726
-
727
-			case 'wpi_discount' :
728
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
729
-				break;
730
-
731
-			case 'wpi_invoice' :
732
-				$invoice = new WPInv_Invoice( $post_id );
733
-				do_action( "getpaid_before_delete_invoice", $invoice );
734
-				$invoice->get_data_store()->delete_items( $invoice );
735
-				$invoice->get_data_store()->delete_special_fields( $invoice );
736
-				break;
737
-		}
738
-	}
650
+        }
651
+
652
+    }
653
+
654
+    /**
655
+     * Reorders items.
656
+     */
657
+    public static function reorder_items( $vars ) {
658
+        global $typenow;
659
+
660
+        if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
661
+            return $vars;
662
+        }
663
+
664
+        // By item type.
665
+        if ( 'type' == $vars['orderby'] ) {
666
+            return array_merge(
667
+                $vars,
668
+                array(
669
+                    'meta_key' => '_wpinv_type',
670
+                    'orderby'  => 'meta_value'
671
+                )
672
+            );
673
+        }
674
+
675
+        // By vat class.
676
+        if ( 'vat_class' == $vars['orderby'] ) {
677
+            return array_merge(
678
+                $vars,
679
+                array(
680
+                    'meta_key' => '_wpinv_vat_class',
681
+                    'orderby'  => 'meta_value'
682
+                )
683
+            );
684
+        }
685
+
686
+        // By vat rule.
687
+        if ( 'vat_rule' == $vars['orderby'] ) {
688
+            return array_merge(
689
+                $vars,
690
+                array(
691
+                    'meta_key' => '_wpinv_vat_rule',
692
+                    'orderby'  => 'meta_value'
693
+                )
694
+            );
695
+        }
696
+
697
+        // By price.
698
+        if ( 'price' == $vars['orderby'] ) {
699
+            return array_merge(
700
+                $vars,
701
+                array(
702
+                    'meta_key' => '_wpinv_price',
703
+                    'orderby'  => 'meta_value_num'
704
+                )
705
+            );
706
+        }
707
+
708
+        return $vars;
709
+
710
+    }
711
+
712
+    /**
713
+     * Fired when deleting a post.
714
+     */
715
+    public static function delete_post( $post_id ) {
716
+
717
+        switch ( get_post_type( $post_id ) ) {
718
+
719
+            case 'wpi_item' :
720
+                do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
721
+                break;
722
+
723
+            case 'wpi_payment_form' :
724
+                do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
725
+                break;
726
+
727
+            case 'wpi_discount' :
728
+                do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
729
+                break;
730
+
731
+            case 'wpi_invoice' :
732
+                $invoice = new WPInv_Invoice( $post_id );
733
+                do_action( "getpaid_before_delete_invoice", $invoice );
734
+                $invoice->get_data_store()->delete_items( $invoice );
735
+                $invoice->get_data_store()->delete_special_fields( $invoice );
736
+                break;
737
+        }
738
+    }
739 739
 
740 740
 }
Please login to merge, or discard this patch.
Spacing   +193 added lines, -193 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
  * Post types Admin Class
@@ -21,68 +21,68 @@  discard block
 block discarded – undo
21 21
 		GetPaid_Metaboxes::init();
22 22
 
23 23
 		// Filter the post updated messages.
24
-		add_filter( 'post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages' );
24
+		add_filter('post_updated_messages', 'GetPaid_Post_Types_Admin::post_updated_messages');
25 25
 
26 26
 		// Filter post actions.
27
-		add_filter( 'post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2 );
27
+		add_filter('post_row_actions', 'GetPaid_Post_Types_Admin::post_row_actions', 10, 2);
28 28
 
29 29
 		// Invoice table columns.
30
-		add_filter( 'manage_wpi_invoice_posts_columns', array( __CLASS__, 'invoice_columns' ), 100 );
31
-		add_action( 'manage_wpi_invoice_posts_custom_column', array( __CLASS__, 'display_invoice_columns' ), 10, 2 );
30
+		add_filter('manage_wpi_invoice_posts_columns', array(__CLASS__, 'invoice_columns'), 100);
31
+		add_action('manage_wpi_invoice_posts_custom_column', array(__CLASS__, 'display_invoice_columns'), 10, 2);
32 32
 
33 33
 		// Items table columns.
34
-		add_filter( 'manage_wpi_item_posts_columns', array( __CLASS__, 'item_columns' ), 100 );
35
-		add_filter( 'manage_edit-wpi_item_sortable_columns', array( __CLASS__, 'sortable_item_columns' ), 20 );
36
-		add_action( 'manage_wpi_item_posts_custom_column', array( __CLASS__, 'display_item_columns' ), 10, 2 );
37
-		add_action( 'restrict_manage_posts', array( __CLASS__, 'add_item_filters' ), 100 );
38
-		add_action( 'parse_query', array( __CLASS__, 'filter_item_query' ), 100 );
39
-		add_action( 'request', array( __CLASS__, 'reorder_items' ), 100 );
34
+		add_filter('manage_wpi_item_posts_columns', array(__CLASS__, 'item_columns'), 100);
35
+		add_filter('manage_edit-wpi_item_sortable_columns', array(__CLASS__, 'sortable_item_columns'), 20);
36
+		add_action('manage_wpi_item_posts_custom_column', array(__CLASS__, 'display_item_columns'), 10, 2);
37
+		add_action('restrict_manage_posts', array(__CLASS__, 'add_item_filters'), 100);
38
+		add_action('parse_query', array(__CLASS__, 'filter_item_query'), 100);
39
+		add_action('request', array(__CLASS__, 'reorder_items'), 100);
40 40
 
41 41
 		// Payment forms columns.
42
-		add_filter( 'manage_wpi_payment_form_posts_columns', array( __CLASS__, 'payment_form_columns' ), 100 );
43
-		add_action( 'manage_wpi_payment_form_posts_custom_column', array( __CLASS__, 'display_payment_form_columns' ), 10, 2 );
44
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_payment_form_state' ), 10, 2 );
42
+		add_filter('manage_wpi_payment_form_posts_columns', array(__CLASS__, 'payment_form_columns'), 100);
43
+		add_action('manage_wpi_payment_form_posts_custom_column', array(__CLASS__, 'display_payment_form_columns'), 10, 2);
44
+		add_filter('display_post_states', array(__CLASS__, 'filter_payment_form_state'), 10, 2);
45 45
 
46 46
 		// Discount table columns.
47
-		add_filter( 'manage_wpi_discount_posts_columns', array( __CLASS__, 'discount_columns' ), 100 );
47
+		add_filter('manage_wpi_discount_posts_columns', array(__CLASS__, 'discount_columns'), 100);
48 48
 
49 49
 		// Deleting posts.
50
-		add_action( 'delete_post', array( __CLASS__, 'delete_post' ) );
51
-		add_filter( 'display_post_states', array( __CLASS__, 'filter_discount_state' ), 10, 2 );
50
+		add_action('delete_post', array(__CLASS__, 'delete_post'));
51
+		add_filter('display_post_states', array(__CLASS__, 'filter_discount_state'), 10, 2);
52 52
 	}
53 53
 
54 54
 	/**
55 55
 	 * Post updated messages.
56 56
 	 */
57
-	public static function post_updated_messages( $messages ) {
57
+	public static function post_updated_messages($messages) {
58 58
 		global $post;
59 59
 
60 60
 		$messages['wpi_discount'] = array(
61 61
 			0   => '',
62
-			1   => __( 'Discount updated.', 'invoicing' ),
63
-			2   => __( 'Custom field updated.', 'invoicing' ),
64
-			3   => __( 'Custom field deleted.', 'invoicing' ),
65
-			4   => __( 'Discount updated.', 'invoicing' ),
66
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
67
-			6   => __( 'Discount updated.', 'invoicing' ),
68
-			7   => __( 'Discount saved.', 'invoicing' ),
69
-			8   => __( 'Discount submitted.', 'invoicing' ),
70
-			9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
71
-			10  => __( 'Discount draft updated.', 'invoicing' ),
62
+			1   => __('Discount updated.', 'invoicing'),
63
+			2   => __('Custom field updated.', 'invoicing'),
64
+			3   => __('Custom field deleted.', 'invoicing'),
65
+			4   => __('Discount updated.', 'invoicing'),
66
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
67
+			6   => __('Discount updated.', 'invoicing'),
68
+			7   => __('Discount saved.', 'invoicing'),
69
+			8   => __('Discount submitted.', 'invoicing'),
70
+			9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
71
+			10  => __('Discount draft updated.', 'invoicing'),
72 72
 		);
73 73
 
74 74
 		$messages['wpi_payment_form'] = array(
75 75
 			0   => '',
76
-			1   => __( 'Payment Form updated.', 'invoicing' ),
77
-			2   => __( 'Custom field updated.', 'invoicing' ),
78
-			3   => __( 'Custom field deleted.', 'invoicing' ),
79
-			4   => __( 'Payment Form updated.', 'invoicing' ),
80
-			5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
81
-			6   => __( 'Payment Form updated.', 'invoicing' ),
82
-			7   => __( 'Payment Form saved.', 'invoicing' ),
83
-			8   => __( 'Payment Form submitted.', 'invoicing' ),
84
-			9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
85
-			10  => __( 'Payment Form draft updated.', 'invoicing' ),
76
+			1   => __('Payment Form updated.', 'invoicing'),
77
+			2   => __('Custom field updated.', 'invoicing'),
78
+			3   => __('Custom field deleted.', 'invoicing'),
79
+			4   => __('Payment Form updated.', 'invoicing'),
80
+			5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
81
+			6   => __('Payment Form updated.', 'invoicing'),
82
+			7   => __('Payment Form saved.', 'invoicing'),
83
+			8   => __('Payment Form submitted.', 'invoicing'),
84
+			9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
85
+			10  => __('Payment Form draft updated.', 'invoicing'),
86 86
 		);
87 87
 
88 88
 		return $messages;
@@ -92,14 +92,14 @@  discard block
 block discarded – undo
92 92
 	/**
93 93
 	 * Post row actions.
94 94
 	 */
95
-	public static function post_row_actions( $actions, $post ) {
95
+	public static function post_row_actions($actions, $post) {
96 96
 
97
-		$post = get_post( $post );
97
+		$post = get_post($post);
98 98
 
99 99
 		// We do not want to edit the default payment form.
100
-		if ( 'wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form() ) {
101
-			unset( $actions['trash'] );
102
-			unset( $actions['inline hide-if-no-js'] );
100
+		if ('wpi_payment_form' == $post->post_type && $post->ID == wpinv_get_default_payment_form()) {
101
+			unset($actions['trash']);
102
+			unset($actions['inline hide-if-no-js']);
103 103
 		}
104 104
 
105 105
 		return $actions;
@@ -108,51 +108,51 @@  discard block
 block discarded – undo
108 108
 	/**
109 109
 	 * Returns an array of invoice table columns.
110 110
 	 */
111
-	public static function invoice_columns( $columns ) {
111
+	public static function invoice_columns($columns) {
112 112
 
113 113
 		$columns = array(
114 114
 			'cb'                => $columns['cb'],
115
-			'number'            => __( 'Invoice', 'invoicing' ),
116
-			'customer'          => __( 'Customer', 'invoicing' ),
117
-			'invoice_date'      => __( 'Date', 'invoicing' ),
118
-			'amount'            => __( 'Amount', 'invoicing' ),
119
-			'recurring'         => __( 'Recurring', 'invoicing' ),
120
-			'status'            => __( 'Status', 'invoicing' ),
121
-			'wpi_actions'       => __( 'Actions', 'invoicing' ),
115
+			'number'            => __('Invoice', 'invoicing'),
116
+			'customer'          => __('Customer', 'invoicing'),
117
+			'invoice_date'      => __('Date', 'invoicing'),
118
+			'amount'            => __('Amount', 'invoicing'),
119
+			'recurring'         => __('Recurring', 'invoicing'),
120
+			'status'            => __('Status', 'invoicing'),
121
+			'wpi_actions'       => __('Actions', 'invoicing'),
122 122
 		);
123 123
 
124
-		return apply_filters( 'wpi_invoice_table_columns', $columns );
124
+		return apply_filters('wpi_invoice_table_columns', $columns);
125 125
 	}
126 126
 
127 127
 	/**
128 128
 	 * Displays invoice table columns.
129 129
 	 */
130
-	public static function display_invoice_columns( $column_name, $post_id ) {
130
+	public static function display_invoice_columns($column_name, $post_id) {
131 131
 
132
-		$invoice = new WPInv_Invoice( $post_id );
132
+		$invoice = new WPInv_Invoice($post_id);
133 133
 
134
-		switch ( $column_name ) {
134
+		switch ($column_name) {
135 135
 
136 136
 			case 'invoice_date' :
137
-				$date_time = esc_attr( $invoice->get_created_date() );
138
-				$date      = getpaid_format_date_value( $date_time );
137
+				$date_time = esc_attr($invoice->get_created_date());
138
+				$date      = getpaid_format_date_value($date_time);
139 139
 				echo "<span title='$date_time'>$date</span>";
140 140
 				break;
141 141
 
142 142
 			case 'amount' :
143 143
 
144 144
 				$amount = $invoice->get_total();
145
-				$formated_amount = wpinv_price( wpinv_format_amount( $amount ), $invoice->get_currency() );
145
+				$formated_amount = wpinv_price(wpinv_format_amount($amount), $invoice->get_currency());
146 146
 
147
-				if ( $invoice->is_refunded() ) {
148
-					$refunded_amount = wpinv_price( wpinv_format_amount( 0 ), $invoice->get_currency() );
147
+				if ($invoice->is_refunded()) {
148
+					$refunded_amount = wpinv_price(wpinv_format_amount(0), $invoice->get_currency());
149 149
 					echo "<del>$formated_amount</del>&nbsp;<ins>$refunded_amount</ins>";
150 150
 				} else {
151 151
 
152 152
 					$discount = $invoice->get_total_discount();
153 153
 
154
-					if ( ! empty( $discount ) ) {
155
-						$new_amount = wpinv_price( wpinv_format_amount( $amount + $discount ), $invoice->get_currency() );
154
+					if (!empty($discount)) {
155
+						$new_amount = wpinv_price(wpinv_format_amount($amount + $discount), $invoice->get_currency());
156 156
 						echo "<del>$new_amount</del>&nbsp;<ins>$formated_amount</ins>";
157 157
 					} else {
158 158
 						echo $formated_amount;
@@ -163,13 +163,13 @@  discard block
 block discarded – undo
163 163
 				break;
164 164
 
165 165
 			case 'status' :
166
-				$status       = sanitize_text_field( $invoice->get_status() );
167
-				$status_label = sanitize_text_field( $invoice->get_status_nicename() );
166
+				$status       = sanitize_text_field($invoice->get_status());
167
+				$status_label = sanitize_text_field($invoice->get_status_nicename());
168 168
 
169 169
 				// If it is paid, show the gateway title.
170
-				if ( $invoice->is_paid() ) {
171
-					$gateway = sanitize_text_field( $invoice->get_gateway_title() );
172
-					$gateway = wp_sprintf( esc_attr__( 'Paid via %s', 'invoicing' ), $gateway );
170
+				if ($invoice->is_paid()) {
171
+					$gateway = sanitize_text_field($invoice->get_gateway_title());
172
+					$gateway = wp_sprintf(esc_attr__('Paid via %s', 'invoicing'), $gateway);
173 173
 
174 174
 					echo "<mark class='wpi-help-tip getpaid-invoice-status $status' title='$gateway'><span>$status_label</span></mark>";
175 175
 				} else {
@@ -177,22 +177,22 @@  discard block
 block discarded – undo
177 177
 				}
178 178
 
179 179
 				// If it is not paid, display the overdue and view status.
180
-				if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
180
+				if (!$invoice->is_paid() && !$invoice->is_refunded()) {
181 181
 
182 182
 					// Invoice view status.
183
-					if ( wpinv_is_invoice_viewed( $invoice->get_id() ) ) {
184
-						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="'. esc_attr__( 'Viewed by Customer', 'invoicing' ).'"></i>';
183
+					if (wpinv_is_invoice_viewed($invoice->get_id())) {
184
+						echo '&nbsp;&nbsp;<i class="fa fa-eye wpi-help-tip" title="' . esc_attr__('Viewed by Customer', 'invoicing') . '"></i>';
185 185
 					} else {
186
-						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="'. esc_attr__( 'Not Viewed by Customer', 'invoicing' ).'"></i>';
186
+						echo '&nbsp;&nbsp;<i class="fa fa-eye-slash wpi-help-tip" title="' . esc_attr__('Not Viewed by Customer', 'invoicing') . '"></i>';
187 187
 					}
188 188
 
189 189
 					// Display the overview status.
190
-					if ( wpinv_get_option( 'overdue_active' ) ) {
190
+					if (wpinv_get_option('overdue_active')) {
191 191
 						$due_date = $invoice->get_due_date();
192
-						$fomatted = getpaid_format_date( $due_date );
192
+						$fomatted = getpaid_format_date($due_date);
193 193
 
194
-						if ( ! empty( $fomatted ) ) {
195
-							$date = wp_sprintf( __( 'Due %s', 'invoicing' ), $fomatted );
194
+						if (!empty($fomatted)) {
195
+							$date = wp_sprintf(__('Due %s', 'invoicing'), $fomatted);
196 196
 							echo "<p class='description' style='color: #888;' title='$due_date'>$fomatted</p>";
197 197
 						}
198 198
 					}
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 			case 'recurring':
205 205
 
206
-				if ( $invoice->is_recurring() ) {
206
+				if ($invoice->is_recurring()) {
207 207
 					echo '<i class="fa fa-check" style="color:#43850a;"></i>';
208 208
 				} else {
209 209
 					echo '<i class="fa fa-times" style="color:#616161;"></i>';
@@ -212,9 +212,9 @@  discard block
 block discarded – undo
212 212
 
213 213
 			case 'number' :
214 214
 
215
-				$edit_link       = esc_url( get_edit_post_link( $invoice->get_id() ) );
216
-				$invoice_number  = sanitize_text_field( $invoice->get_number() );
217
-				$invoice_details = esc_attr__( 'View Invoice Details', 'invoicing' );
215
+				$edit_link       = esc_url(get_edit_post_link($invoice->get_id()));
216
+				$invoice_number  = sanitize_text_field($invoice->get_number());
217
+				$invoice_details = esc_attr__('View Invoice Details', 'invoicing');
218 218
 
219 219
 				echo "<a href='$edit_link' title='$invoice_details'><strong>$invoice_number</strong></a>";
220 220
 
@@ -224,13 +224,13 @@  discard block
 block discarded – undo
224 224
 	
225 225
 				$customer_name = $invoice->get_user_full_name();
226 226
 	
227
-				if ( empty( $customer_name ) ) {
227
+				if (empty($customer_name)) {
228 228
 					$customer_name = $invoice->get_email();
229 229
 				}
230 230
 	
231
-				if ( ! empty( $customer_name ) ) {
232
-					$customer_details = esc_attr__( 'View Customer Details', 'invoicing' );
233
-					$view_link        = esc_url( add_query_arg( 'user_id', $invoice->get_user_id(), admin_url( 'user-edit.php' ) ) );
231
+				if (!empty($customer_name)) {
232
+					$customer_details = esc_attr__('View Customer Details', 'invoicing');
233
+					$view_link        = esc_url(add_query_arg('user_id', $invoice->get_user_id(), admin_url('user-edit.php')));
234 234
 					echo "<a href='$view_link' title='$customer_details'><span>$customer_name</span></a>";
235 235
 				} else {
236 236
 					echo '<div>&mdash;</div>';
@@ -240,12 +240,12 @@  discard block
 block discarded – undo
240 240
 
241 241
 			case 'wpi_actions' :
242 242
 
243
-				if ( $invoice->is_draft() ) {
243
+				if ($invoice->is_draft()) {
244 244
 					return;
245 245
 				}
246 246
 
247
-				$url    = esc_url( $invoice->get_view_url() );
248
-				$print  = esc_attr__( 'Print invoice', 'invoicing' );
247
+				$url    = esc_url($invoice->get_view_url());
248
+				$print  = esc_attr__('Print invoice', 'invoicing');
249 249
 				echo "&nbsp;<a href='$url' title='$print' target='_blank' style='color:#757575'><i class='fa fa-print' style='font-size: 1.4em;'></i></a>";
250 250
 
251 251
 				$url    = esc_url(
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 					)
262 262
 				);
263 263
 
264
-				$send   = esc_attr__( 'Send invoice to customer', 'invoicing' );
264
+				$send = esc_attr__('Send invoice to customer', 'invoicing');
265 265
 				echo "&nbsp;&nbsp;<a href='$url' title='$send' style='color:#757575'><i class='fa fa-envelope' style='font-size: 1.4em;'></i></a>";
266 266
 
267 267
 				break;
@@ -272,50 +272,50 @@  discard block
 block discarded – undo
272 272
 	/**
273 273
 	 * Returns an array of payment forms table columns.
274 274
 	 */
275
-	public static function payment_form_columns( $columns ) {
275
+	public static function payment_form_columns($columns) {
276 276
 
277 277
 		$columns = array(
278 278
 			'cb'                => $columns['cb'],
279
-			'title'             => __( 'Name', 'invoicing' ),
280
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
281
-			'earnings'          => __( 'Revenue', 'invoicing' ),
282
-			'refunds'           => __( 'Refunded', 'invoicing' ),
283
-			'items'             => __( 'Items', 'invoicing' ),
284
-			'date'              => __( 'Date', 'invoicing' ),
279
+			'title'             => __('Name', 'invoicing'),
280
+			'shortcode'         => __('Shortcode', 'invoicing'),
281
+			'earnings'          => __('Revenue', 'invoicing'),
282
+			'refunds'           => __('Refunded', 'invoicing'),
283
+			'items'             => __('Items', 'invoicing'),
284
+			'date'              => __('Date', 'invoicing'),
285 285
 		);
286 286
 
287
-		return apply_filters( 'wpi_payment_form_table_columns', $columns );
287
+		return apply_filters('wpi_payment_form_table_columns', $columns);
288 288
 
289 289
 	}
290 290
 
291 291
 	/**
292 292
 	 * Displays payment form table columns.
293 293
 	 */
294
-	public static function display_payment_form_columns( $column_name, $post_id ) {
294
+	public static function display_payment_form_columns($column_name, $post_id) {
295 295
 
296 296
 		// Retrieve the payment form.
297
-		$form = new GetPaid_Payment_Form( $post_id );
297
+		$form = new GetPaid_Payment_Form($post_id);
298 298
 
299
-		switch ( $column_name ) {
299
+		switch ($column_name) {
300 300
 
301 301
 			case 'earnings' :
302
-				echo wpinv_price( wpinv_format_amount( $form->get_earned() ) );
302
+				echo wpinv_price(wpinv_format_amount($form->get_earned()));
303 303
 				break;
304 304
 
305 305
 			case 'refunds' :
306
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
306
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
307 307
 				break;
308 308
 
309 309
 			case 'refunds' :
310
-				echo wpinv_price( wpinv_format_amount( $form->get_refunded() ) );
310
+				echo wpinv_price(wpinv_format_amount($form->get_refunded()));
311 311
 				break;
312 312
 
313 313
 			case 'shortcode' :
314 314
 
315
-				if ( $form->is_default() ) {
315
+				if ($form->is_default()) {
316 316
 					echo '&mdash;';
317 317
 				} else {
318
-					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr( $form->get_id() ) . ']" style="width: 100%;" readonly/>';
318
+					echo '<input onClick="this.select()" type="text" value="[getpaid form=' . esc_attr($form->get_id()) . ']" style="width: 100%;" readonly/>';
319 319
 				}
320 320
 
321 321
 				break;
@@ -324,29 +324,29 @@  discard block
 block discarded – undo
324 324
 
325 325
 				$items = $form->get_items();
326 326
 
327
-				if ( $form->is_default() || empty( $items ) ) {
327
+				if ($form->is_default() || empty($items)) {
328 328
 					echo '&mdash;';
329 329
 					return;
330 330
 				}
331 331
 
332 332
 				$_items = array();
333 333
 
334
-				foreach ( $items as $item ) {
334
+				foreach ($items as $item) {
335 335
 					$url = $item->get_edit_url();
336 336
 
337
-					if ( empty( $url ) ) {
338
-						$_items[] = sanitize_text_field( $item->get_name() );
337
+					if (empty($url)) {
338
+						$_items[] = sanitize_text_field($item->get_name());
339 339
 					} else {
340 340
 						$_items[] = sprintf(
341 341
 							'<a href="%s">%s</a>',
342
-							esc_url( $url ),
343
-							sanitize_text_field( $item->get_name() )
342
+							esc_url($url),
343
+							sanitize_text_field($item->get_name())
344 344
 						);
345 345
 					}
346 346
 
347 347
 				}
348 348
 
349
-				echo implode( '<br>', $_items );
349
+				echo implode('<br>', $_items);
350 350
 
351 351
 				break;
352 352
 
@@ -357,10 +357,10 @@  discard block
 block discarded – undo
357 357
 	/**
358 358
 	 * Filters post states.
359 359
 	 */
360
-	public static function filter_payment_form_state( $post_states, $post ) {
360
+	public static function filter_payment_form_state($post_states, $post) {
361 361
 
362
-		if ( 'wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID ) {
363
-			$post_states[ 'default_form' ] = __( 'Default Payment Form', 'invoicing' );
362
+		if ('wpi_payment_form' == $post->post_type && wpinv_get_default_payment_form() == $post->ID) {
363
+			$post_states['default_form'] = __('Default Payment Form', 'invoicing');
364 364
 		}
365 365
 	
366 366
 		return $post_states;
@@ -370,35 +370,35 @@  discard block
 block discarded – undo
370 370
 	/**
371 371
 	 * Returns an array of coupon table columns.
372 372
 	 */
373
-	public static function discount_columns( $columns ) {
373
+	public static function discount_columns($columns) {
374 374
 
375 375
 		$columns = array(
376 376
 			'cb'                => $columns['cb'],
377
-			'title'             => __( 'Name', 'invoicing' ),
378
-			'code'              => __( 'Code', 'invoicing' ),
379
-			'amount'            => __( 'Amount', 'invoicing' ),
380
-			'usage'             => __( 'Usage / Limit', 'invoicing' ),
381
-			'start_date'        => __( 'Start Date', 'invoicing' ),
382
-			'expiry_date'       => __( 'Expiry Date', 'invoicing' ),
377
+			'title'             => __('Name', 'invoicing'),
378
+			'code'              => __('Code', 'invoicing'),
379
+			'amount'            => __('Amount', 'invoicing'),
380
+			'usage'             => __('Usage / Limit', 'invoicing'),
381
+			'start_date'        => __('Start Date', 'invoicing'),
382
+			'expiry_date'       => __('Expiry Date', 'invoicing'),
383 383
 		);
384 384
 
385
-		return apply_filters( 'wpi_discount_table_columns', $columns );
385
+		return apply_filters('wpi_discount_table_columns', $columns);
386 386
 	}
387 387
 
388 388
 	/**
389 389
 	 * Filters post states.
390 390
 	 */
391
-	public static function filter_discount_state( $post_states, $post ) {
391
+	public static function filter_discount_state($post_states, $post) {
392 392
 
393
-		if ( 'wpi_discount' == $post->post_type ) {
393
+		if ('wpi_discount' == $post->post_type) {
394 394
 
395
-			$discount = new WPInv_Discount( $post );
395
+			$discount = new WPInv_Discount($post);
396 396
 
397 397
 			$status = $discount->is_expired() ? 'expired' : $discount->get_status();
398 398
 
399
-			if ( $status != 'publish' ) {
399
+			if ($status != 'publish') {
400 400
 				return array(
401
-					'discount_status' => wpinv_discount_status( $status ),
401
+					'discount_status' => wpinv_discount_status($status),
402 402
 				);
403 403
 			}
404 404
 
@@ -413,34 +413,34 @@  discard block
 block discarded – undo
413 413
 	/**
414 414
 	 * Returns an array of items table columns.
415 415
 	 */
416
-	public static function item_columns( $columns ) {
416
+	public static function item_columns($columns) {
417 417
 		global $wpinv_euvat;
418 418
 
419 419
 		$columns = array(
420 420
 			'cb'                => $columns['cb'],
421
-			'title'             => __( 'Name', 'invoicing' ),
422
-			'price'             => __( 'Price', 'invoicing' ),
423
-			'vat_rule'          => __( 'VAT rule', 'invoicing' ),
424
-			'vat_class'         => __( 'VAT class', 'invoicing' ),
425
-			'type'              => __( 'Type', 'invoicing' ),
426
-			'shortcode'         => __( 'Shortcode', 'invoicing' ),
421
+			'title'             => __('Name', 'invoicing'),
422
+			'price'             => __('Price', 'invoicing'),
423
+			'vat_rule'          => __('VAT rule', 'invoicing'),
424
+			'vat_class'         => __('VAT class', 'invoicing'),
425
+			'type'              => __('Type', 'invoicing'),
426
+			'shortcode'         => __('Shortcode', 'invoicing'),
427 427
 		);
428 428
 
429
-		if ( ! $wpinv_euvat->allow_vat_rules() ) {
430
-			unset( $columns['vat_rule'] );
429
+		if (!$wpinv_euvat->allow_vat_rules()) {
430
+			unset($columns['vat_rule']);
431 431
 		}
432 432
 
433
-		if ( ! $wpinv_euvat->allow_vat_classes() ) {
434
-			unset( $columns['vat_class'] );
433
+		if (!$wpinv_euvat->allow_vat_classes()) {
434
+			unset($columns['vat_class']);
435 435
 		}
436 436
 
437
-		return apply_filters( 'wpi_item_table_columns', $columns );
437
+		return apply_filters('wpi_item_table_columns', $columns);
438 438
 	}
439 439
 
440 440
 	/**
441 441
 	 * Returns an array of sortable items table columns.
442 442
 	 */
443
-	public static function sortable_item_columns( $columns ) {
443
+	public static function sortable_item_columns($columns) {
444 444
 
445 445
 		return array_merge(
446 446
 			$columns,
@@ -457,50 +457,50 @@  discard block
 block discarded – undo
457 457
 	/**
458 458
 	 * Displays items table columns.
459 459
 	 */
460
-	public static function display_item_columns( $column_name, $post_id ) {
460
+	public static function display_item_columns($column_name, $post_id) {
461 461
 		global $wpinv_euvat;
462 462
 
463
-		$item = new WPInv_Item( $post_id );
463
+		$item = new WPInv_Item($post_id);
464 464
 
465
-		switch ( $column_name ) {
465
+		switch ($column_name) {
466 466
 
467 467
 			case 'price' :
468 468
 
469
-				if ( ! $item->is_recurring() ) {
469
+				if (!$item->is_recurring()) {
470 470
 					echo $item->get_the_price();
471 471
 					break;
472 472
 				}
473 473
 
474 474
 				$price = wp_sprintf(
475
-					__( '%s / %s', 'invoicing' ),
475
+					__('%s / %s', 'invoicing'),
476 476
 					$item->get_the_price(),
477
-					getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' )
477
+					getpaid_get_subscription_period_label($item->get_recurring_period(), $item->get_recurring_interval(), '')
478 478
 				);
479 479
 
480
-				if ( $item->get_the_price() == $item->get_the_initial_price() ) {
480
+				if ($item->get_the_price() == $item->get_the_initial_price()) {
481 481
 					echo $price;
482 482
 					break;
483 483
 				}
484 484
 
485 485
 				echo $item->get_the_initial_price();
486 486
 
487
-				echo '<span class="meta">' . wp_sprintf( __( 'then %s', 'invoicing' ), $price )  .'</span>';
487
+				echo '<span class="meta">' . wp_sprintf(__('then %s', 'invoicing'), $price) . '</span>';
488 488
 				break;
489 489
 
490 490
 			case 'vat_rule' :
491
-				echo $wpinv_euvat->item_rule_label( $item->get_id() );
491
+				echo $wpinv_euvat->item_rule_label($item->get_id());
492 492
 				break;
493 493
 
494 494
 			case 'vat_class' :
495
-				echo $wpinv_euvat->item_class_label( $item->get_id() );
495
+				echo $wpinv_euvat->item_class_label($item->get_id());
496 496
 				break;
497 497
 
498 498
 			case 'shortcode' :
499
-				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr( $item->get_id() ) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
499
+				echo '<input onClick="this.select()" type="text" value="[getpaid item=' . esc_attr($item->get_id()) . ' button=\'Buy Now\']" style="width: 100%;" readonly/>';
500 500
 				break;
501 501
 
502 502
 			case 'type' :
503
-				echo wpinv_item_type( $item->get_id() ) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
503
+				echo wpinv_item_type($item->get_id()) . '<span class="meta">' . $item->get_custom_singular_name() . '</span>';
504 504
 				break;
505 505
 
506 506
 		}
@@ -510,22 +510,22 @@  discard block
 block discarded – undo
510 510
 	/**
511 511
 	 * Lets users filter items using taxes.
512 512
 	 */
513
-	public static function add_item_filters( $post_type ) {
513
+	public static function add_item_filters($post_type) {
514 514
 		$wpinv_euvat = getpaid_tax();
515 515
 
516 516
 		// Abort if we're not dealing with items.
517
-		if ( $post_type != 'wpi_item' ) {
517
+		if ($post_type != 'wpi_item') {
518 518
 			return;
519 519
 		}
520 520
 
521 521
 		// Filter by vat rules.
522
-		if ( $wpinv_euvat->allow_vat_rules() ) {
522
+		if ($wpinv_euvat->allow_vat_rules()) {
523 523
 	
524 524
 			// Sanitize selected vat rule.
525 525
 			$vat_rule   = '';
526 526
 			$vat_rules  = $wpinv_euvat->get_rules();
527
-			if ( isset( $_GET['vat_rule'] ) ) {
528
-				$vat_rule   =  $_GET['vat_rule'];
527
+			if (isset($_GET['vat_rule'])) {
528
+				$vat_rule = $_GET['vat_rule'];
529 529
 			}
530 530
 
531 531
 			// Filter by VAT rule.
@@ -533,13 +533,13 @@  discard block
 block discarded – undo
533 533
 				array(
534 534
 					'options'          => array_merge(
535 535
 						array(
536
-							'' => __( 'All VAT rules', 'invoicing' )
536
+							'' => __('All VAT rules', 'invoicing')
537 537
 						),
538 538
 						$vat_rules
539 539
 					),
540 540
 					'name'             => 'vat_rule',
541 541
 					'id'               => 'vat_rule',
542
-					'selected'         => in_array( $vat_rule, array_keys( $vat_rules ) ) ? $vat_rule : '',
542
+					'selected'         => in_array($vat_rule, array_keys($vat_rules)) ? $vat_rule : '',
543 543
 					'show_option_all'  => false,
544 544
 					'show_option_none' => false,
545 545
 					'class'            => 'gdmbx2-text-medium',
@@ -550,26 +550,26 @@  discard block
 block discarded – undo
550 550
 		}
551 551
 
552 552
 		// Filter by vat class.
553
-		if ( $wpinv_euvat->allow_vat_classes() ) {
553
+		if ($wpinv_euvat->allow_vat_classes()) {
554 554
 	
555 555
 			// Sanitize selected vat rule.
556 556
 			$vat_class   = '';
557 557
 			$vat_classes = $wpinv_euvat->get_all_classes();
558
-			if ( isset( $_GET['vat_class'] ) ) {
559
-				$vat_class   =  $_GET['vat_class'];
558
+			if (isset($_GET['vat_class'])) {
559
+				$vat_class = $_GET['vat_class'];
560 560
 			}
561 561
 
562 562
 			echo wpinv_html_select(
563 563
 				array(
564 564
 					'options'          => array_merge(
565 565
 						array(
566
-							'' => __( 'All VAT classes', 'invoicing' )
566
+							'' => __('All VAT classes', 'invoicing')
567 567
 						),
568 568
 						$vat_classes
569 569
 					),
570 570
 					'name'             => 'vat_class',
571 571
 					'id'               => 'vat_class',
572
-					'selected'         => in_array( $vat_class, array_keys( $vat_classes ) ) ? $vat_class : '',
572
+					'selected'         => in_array($vat_class, array_keys($vat_classes)) ? $vat_class : '',
573 573
 					'show_option_all'  => false,
574 574
 					'show_option_none' => false,
575 575
 					'class'            => 'gdmbx2-text-medium',
@@ -579,22 +579,22 @@  discard block
 block discarded – undo
579 579
 		}
580 580
 
581 581
 		// Filter by item type.
582
-		$type   = '';
583
-		if ( isset( $_GET['type'] ) ) {
584
-			$type   =  $_GET['type'];
582
+		$type = '';
583
+		if (isset($_GET['type'])) {
584
+			$type = $_GET['type'];
585 585
 		}
586 586
 
587 587
 		echo wpinv_html_select(
588 588
 			array(
589 589
 				'options'          => array_merge(
590 590
 					array(
591
-						'' => __( 'All item types', 'invoicing' )
591
+						'' => __('All item types', 'invoicing')
592 592
 					),
593 593
 					wpinv_get_item_types()
594 594
 				),
595 595
 				'name'             => 'type',
596 596
 				'id'               => 'type',
597
-				'selected'         => in_array( $type, wpinv_item_types() ) ? $type : '',
597
+				'selected'         => in_array($type, wpinv_item_types()) ? $type : '',
598 598
 				'show_option_all'  => false,
599 599
 				'show_option_none' => false,
600 600
 				'class'            => 'gdmbx2-text-medium',
@@ -606,45 +606,45 @@  discard block
 block discarded – undo
606 606
 	/**
607 607
 	 * Filters the item query.
608 608
 	 */
609
-	public static function filter_item_query( $query ) {
609
+	public static function filter_item_query($query) {
610 610
 
611 611
 		// modify the query only if it admin and main query.
612
-		if ( ! ( is_admin() && $query->is_main_query() ) ){ 
612
+		if (!(is_admin() && $query->is_main_query())) { 
613 613
 			return $query;
614 614
 		}
615 615
 
616 616
 		// we want to modify the query for our items.
617
-		if ( 'wpi_item' != $query->query['post_type'] ){
617
+		if ('wpi_item' != $query->query['post_type']) {
618 618
 			return $query;
619 619
 		}
620 620
 
621
-		if ( empty( $query->query_vars['meta_query'] ) ) {
621
+		if (empty($query->query_vars['meta_query'])) {
622 622
 			$query->query_vars['meta_query'] = array();
623 623
 		}
624 624
 
625 625
 		// Filter vat rule type
626
-        if ( ! empty( $_GET['vat_rule'] ) ) {
626
+        if (!empty($_GET['vat_rule'])) {
627 627
             $query->query_vars['meta_query'][] = array(
628 628
                 'key'     => '_wpinv_vat_rule',
629
-                'value'   => sanitize_text_field( $_GET['vat_rule'] ),
629
+                'value'   => sanitize_text_field($_GET['vat_rule']),
630 630
                 'compare' => '='
631 631
             );
632 632
         }
633 633
 
634 634
         // Filter vat class
635
-        if ( ! empty( $_GET['vat_class'] ) ) {
635
+        if (!empty($_GET['vat_class'])) {
636 636
             $query->query_vars['meta_query'][] = array(
637 637
                 'key'     => '_wpinv_vat_class',
638
-                'value'   => sanitize_text_field( $_GET['vat_class'] ),
638
+                'value'   => sanitize_text_field($_GET['vat_class']),
639 639
                 'compare' => '='
640 640
             );
641 641
         }
642 642
 
643 643
         // Filter item type
644
-        if ( ! empty( $_GET['type'] ) ) {
644
+        if (!empty($_GET['type'])) {
645 645
             $query->query_vars['meta_query'][] = array(
646 646
                 'key'     => '_wpinv_type',
647
-                'value'   => sanitize_text_field( $_GET['type'] ),
647
+                'value'   => sanitize_text_field($_GET['type']),
648 648
                 'compare' => '='
649 649
             );
650 650
 		}
@@ -654,15 +654,15 @@  discard block
 block discarded – undo
654 654
 	/**
655 655
 	 * Reorders items.
656 656
 	 */
657
-	public static function reorder_items( $vars ) {
657
+	public static function reorder_items($vars) {
658 658
 		global $typenow;
659 659
 
660
-		if ( 'wpi_item' !== $typenow || empty( $vars['orderby'] ) ) {
660
+		if ('wpi_item' !== $typenow || empty($vars['orderby'])) {
661 661
 			return $vars;
662 662
 		}
663 663
 
664 664
 		// By item type.
665
-		if ( 'type' == $vars['orderby'] ) {
665
+		if ('type' == $vars['orderby']) {
666 666
 			return array_merge(
667 667
 				$vars,
668 668
 				array(
@@ -673,7 +673,7 @@  discard block
 block discarded – undo
673 673
 		}
674 674
 
675 675
 		// By vat class.
676
-		if ( 'vat_class' == $vars['orderby'] ) {
676
+		if ('vat_class' == $vars['orderby']) {
677 677
 			return array_merge(
678 678
 				$vars,
679 679
 				array(
@@ -684,7 +684,7 @@  discard block
 block discarded – undo
684 684
 		}
685 685
 
686 686
 		// By vat rule.
687
-		if ( 'vat_rule' == $vars['orderby'] ) {
687
+		if ('vat_rule' == $vars['orderby']) {
688 688
 			return array_merge(
689 689
 				$vars,
690 690
 				array(
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
 		}
696 696
 
697 697
 		// By price.
698
-		if ( 'price' == $vars['orderby'] ) {
698
+		if ('price' == $vars['orderby']) {
699 699
 			return array_merge(
700 700
 				$vars,
701 701
 				array(
@@ -712,27 +712,27 @@  discard block
 block discarded – undo
712 712
 	/**
713 713
 	 * Fired when deleting a post.
714 714
 	 */
715
-	public static function delete_post( $post_id ) {
715
+	public static function delete_post($post_id) {
716 716
 
717
-		switch ( get_post_type( $post_id ) ) {
717
+		switch (get_post_type($post_id)) {
718 718
 
719 719
 			case 'wpi_item' :
720
-				do_action( "getpaid_before_delete_item", new WPInv_Item( $post_id ) );
720
+				do_action("getpaid_before_delete_item", new WPInv_Item($post_id));
721 721
 				break;
722 722
 
723 723
 			case 'wpi_payment_form' :
724
-				do_action( "getpaid_before_delete_payment_form", new GetPaid_Payment_Form( $post_id ) );
724
+				do_action("getpaid_before_delete_payment_form", new GetPaid_Payment_Form($post_id));
725 725
 				break;
726 726
 
727 727
 			case 'wpi_discount' :
728
-				do_action( "getpaid_before_delete_discount", new WPInv_Discount( $post_id ) );
728
+				do_action("getpaid_before_delete_discount", new WPInv_Discount($post_id));
729 729
 				break;
730 730
 
731 731
 			case 'wpi_invoice' :
732
-				$invoice = new WPInv_Invoice( $post_id );
733
-				do_action( "getpaid_before_delete_invoice", $invoice );
734
-				$invoice->get_data_store()->delete_items( $invoice );
735
-				$invoice->get_data_store()->delete_special_fields( $invoice );
732
+				$invoice = new WPInv_Invoice($post_id);
733
+				do_action("getpaid_before_delete_invoice", $invoice);
734
+				$invoice->get_data_store()->delete_items($invoice);
735
+				$invoice->get_data_store()->delete_special_fields($invoice);
736 736
 				break;
737 737
 		}
738 738
 	}
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Spacing   +235 added lines, -235 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
  * Are we supporting item quantities?
@@ -21,25 +21,25 @@  discard block
 block discarded – undo
21 21
 function wpinv_get_ip() {
22 22
     $ip = $_SERVER['REMOTE_ADDR'];
23 23
 
24
-    if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
25 25
         //Check ip from share internet.
26 26
         $ip = $_SERVER['HTTP_CLIENT_IP'];
27
-    } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
28 28
         //Check ip is pass from proxy.
29 29
         $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
30 30
     }
31 31
 
32
-    return apply_filters( 'wpinv_get_ip', $ip );
32
+    return apply_filters('wpinv_get_ip', $ip);
33 33
 }
34 34
 
35 35
 function wpinv_get_user_agent() {
36
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
37
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
36
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
37
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
38 38
     } else {
39 39
         $user_agent = '';
40 40
     }
41 41
 
42
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
42
+    return apply_filters('wpinv_get_user_agent', $user_agent);
43 43
 }
44 44
 
45 45
 /**
@@ -47,27 +47,27 @@  discard block
 block discarded – undo
47 47
  * 
48 48
  * @param string $amount The amount to sanitize.
49 49
  */
50
-function wpinv_sanitize_amount( $amount ) {
50
+function wpinv_sanitize_amount($amount) {
51 51
 
52 52
     // Format decimals.
53
-    $amount = str_replace( wpinv_decimal_separator(), '.', $amount );
53
+    $amount = str_replace(wpinv_decimal_separator(), '.', $amount);
54 54
 
55 55
     // Remove thousands.
56
-    $amount = str_replace( wpinv_thousands_separator(), '', $amount );
56
+    $amount = str_replace(wpinv_thousands_separator(), '', $amount);
57 57
 
58 58
     // Cast the remaining to a float.
59
-    return (float) preg_replace( '/[^0-9\.\-]/', '', $amount );
59
+    return (float) preg_replace('/[^0-9\.\-]/', '', $amount);
60 60
 
61 61
 }
62 62
 
63
-function wpinv_round_amount( $amount, $decimals = NULL ) {
64
-    if ( $decimals === NULL ) {
63
+function wpinv_round_amount($amount, $decimals = NULL) {
64
+    if ($decimals === NULL) {
65 65
         $decimals = wpinv_decimals();
66 66
     }
67 67
     
68
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
68
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
69 69
 
70
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
70
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
71 71
 }
72 72
 
73 73
 /**
@@ -76,32 +76,32 @@  discard block
 block discarded – undo
76 76
  * @since 1.0.19
77 77
  * @return array
78 78
  */
79
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
79
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
80 80
 	$invoice_statuses = array(
81
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
82
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
83
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
84
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
85
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
86
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
87
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
88
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
81
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
82
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
83
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
84
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
85
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
86
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
87
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
88
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
89 89
     );
90 90
 
91
-    if ( $draft ) {
92
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
91
+    if ($draft) {
92
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
93 93
     }
94 94
 
95
-    if ( $trashed ) {
96
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
95
+    if ($trashed) {
96
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
97 97
     }
98 98
 
99
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
99
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
100 100
 }
101 101
 
102
-function wpinv_status_nicename( $status ) {
103
-    $statuses = wpinv_get_invoice_statuses( true, true );
104
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
102
+function wpinv_status_nicename($status) {
103
+    $statuses = wpinv_get_invoice_statuses(true, true);
104
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
105 105
 
106 106
     return $status;
107 107
 }
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
  * 
112 112
  * @param string $current
113 113
  */
114
-function wpinv_get_currency( $current = '' ) {
114
+function wpinv_get_currency($current = '') {
115 115
 
116
-    if ( empty( $current ) ) {
117
-        $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
116
+    if (empty($current)) {
117
+        $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
118 118
     }
119 119
 
120
-    return trim( strtoupper( $current ) );
120
+    return trim(strtoupper($current));
121 121
 }
122 122
 
123 123
 /**
@@ -125,25 +125,25 @@  discard block
 block discarded – undo
125 125
  * 
126 126
  * @param string|null $currency The currency code. Defaults to the default currency.
127 127
  */
128
-function wpinv_currency_symbol( $currency = null ) {
128
+function wpinv_currency_symbol($currency = null) {
129 129
 
130 130
     // Prepare the currency.
131
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
131
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
132 132
 
133 133
     // Fetch all symbols.
134 134
     $symbols = wpinv_get_currency_symbols();
135 135
 
136 136
     // Fetch this currencies symbol.
137
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
137
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
138 138
 
139 139
     // Filter the symbol.
140
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
140
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
141 141
 }
142 142
 
143 143
 function wpinv_currency_position() {
144
-    $position = wpinv_get_option( 'currency_position', 'left' );
144
+    $position = wpinv_get_option('currency_position', 'left');
145 145
     
146
-    return apply_filters( 'wpinv_currency_position', $position );
146
+    return apply_filters('wpinv_currency_position', $position);
147 147
 }
148 148
 
149 149
 /**
@@ -151,13 +151,13 @@  discard block
 block discarded – undo
151 151
  * 
152 152
  * @param $string|null $current
153 153
  */
154
-function wpinv_thousands_separator( $current = null ) {
154
+function wpinv_thousands_separator($current = null) {
155 155
 
156
-    if ( null == $current ) {
157
-        $current = wpinv_get_option( 'thousands_separator', '.' );
156
+    if (null == $current) {
157
+        $current = wpinv_get_option('thousands_separator', '.');
158 158
     }
159 159
 
160
-    return trim( $current );
160
+    return trim($current);
161 161
 }
162 162
 
163 163
 /**
@@ -165,13 +165,13 @@  discard block
 block discarded – undo
165 165
  * 
166 166
  * @param $string|null $current
167 167
  */
168
-function wpinv_decimal_separator( $current = null ) {
168
+function wpinv_decimal_separator($current = null) {
169 169
 
170
-    if ( null == $current ) {
171
-        $current = wpinv_get_option( 'decimal_separator', '.' );
170
+    if (null == $current) {
171
+        $current = wpinv_get_option('decimal_separator', '.');
172 172
     }
173 173
     
174
-    return trim( $current );
174
+    return trim($current);
175 175
 }
176 176
 
177 177
 /**
@@ -179,27 +179,27 @@  discard block
 block discarded – undo
179 179
  * 
180 180
  * @param $string|null $current
181 181
  */
182
-function wpinv_decimals( $current = null ) {
182
+function wpinv_decimals($current = null) {
183 183
 
184
-    if ( null == $current ) {
185
-        $current = wpinv_get_option( 'decimals', 2 );
184
+    if (null == $current) {
185
+        $current = wpinv_get_option('decimals', 2);
186 186
     }
187 187
     
188
-    return absint( $current );
188
+    return absint($current);
189 189
 }
190 190
 
191 191
 /**
192 192
  * Retrieves a list of all supported currencies.
193 193
  */
194 194
 function wpinv_get_currencies() {
195
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
195
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
196 196
 }
197 197
 
198 198
 /**
199 199
  * Retrieves a list of all currency symbols.
200 200
  */
201 201
 function wpinv_get_currency_symbols() {
202
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
202
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
203 203
 }
204 204
 
205 205
 /**
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
 	$currency_pos = wpinv_currency_position();
212 212
 	$format       = '%1$s%2$s';
213 213
 
214
-	switch ( $currency_pos ) {
214
+	switch ($currency_pos) {
215 215
 		case 'left':
216 216
 			$format = '%1$s%2$s';
217 217
 			break;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 			break;
227 227
 	}
228 228
 
229
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
229
+	return apply_filters('getpaid_price_format', $format, $currency_pos);
230 230
 }
231 231
 
232 232
 /**
@@ -236,25 +236,25 @@  discard block
 block discarded – undo
236 236
  * @param  string $currency Currency.
237 237
  * @return string
238 238
  */
239
-function wpinv_price( $amount = 0, $currency = '' ) {
239
+function wpinv_price($amount = 0, $currency = '') {
240 240
 
241 241
     // Backwards compatibility.
242
-    $amount             = floatval( wpinv_sanitize_amount( $amount ) );
242
+    $amount             = floatval(wpinv_sanitize_amount($amount));
243 243
 
244 244
     // Prepare variables.
245
-    $currency           = wpinv_get_currency( $currency );
245
+    $currency           = wpinv_get_currency($currency);
246 246
     $amount             = (float) $amount;
247 247
     $unformatted_amount = $amount;
248 248
     $negative           = $amount < 0;
249
-    $amount             = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) );
250
-    $amount             = wpinv_format_amount( $amount );
249
+    $amount             = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount));
250
+    $amount             = wpinv_format_amount($amount);
251 251
 
252 252
     // Format the amount.
253 253
     $format             = getpaid_get_price_format();
254
-    $formatted_amount   = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount );
254
+    $formatted_amount   = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount);
255 255
 
256 256
     // Filter the formatting.
257
-    return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount );
257
+    return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount);
258 258
 }
259 259
 
260 260
 /**
@@ -265,33 +265,33 @@  discard block
 block discarded – undo
265 265
  * @param  bool     $calculate Whether or not to apply separators.
266 266
  * @return string
267 267
  */
268
-function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) {
268
+function wpinv_format_amount($amount, $decimals = null, $calculate = false) {
269 269
     $thousands_sep = wpinv_thousands_separator();
270 270
     $decimal_sep   = wpinv_decimal_separator();
271
-    $decimals      = wpinv_decimals( $decimals );
271
+    $decimals      = wpinv_decimals($decimals);
272 272
 
273 273
     // Format decimals.
274
-    $amount = str_replace( $decimal_sep, '.', $amount );
274
+    $amount = str_replace($decimal_sep, '.', $amount);
275 275
 
276 276
     // Remove thousands.
277
-    $amount = str_replace( $thousands_sep, '', $amount );
277
+    $amount = str_replace($thousands_sep, '', $amount);
278 278
 
279 279
     // Cast the remaining to a float.
280
-    $amount = floatval( $amount );
280
+    $amount = floatval($amount);
281 281
 
282
-    if ( $calculate ) {
282
+    if ($calculate) {
283 283
         return $amount;
284 284
     }
285 285
 
286 286
     // Fomart the amount.
287
-    return number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
287
+    return number_format($amount, $decimals, $decimal_sep, $thousands_sep);
288 288
 }
289 289
 
290
-function wpinv_sanitize_key( $key ) {
290
+function wpinv_sanitize_key($key) {
291 291
     $raw_key = $key;
292
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
292
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
293 293
 
294
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
294
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
295 295
 }
296 296
 
297 297
 /**
@@ -299,8 +299,8 @@  discard block
 block discarded – undo
299 299
  * 
300 300
  * @param $str the file whose extension should be retrieved.
301 301
  */
302
-function wpinv_get_file_extension( $str ) {
303
-    $filetype = wp_check_filetype( $str );
302
+function wpinv_get_file_extension($str) {
303
+    $filetype = wp_check_filetype($str);
304 304
     return $filetype['ext'];
305 305
 }
306 306
 
@@ -309,16 +309,16 @@  discard block
 block discarded – undo
309 309
  * 
310 310
  * @param string $string
311 311
  */
312
-function wpinv_string_is_image_url( $string ) {
313
-    $extension = strtolower( wpinv_get_file_extension( $string ) );
314
-    return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true );
312
+function wpinv_string_is_image_url($string) {
313
+    $extension = strtolower(wpinv_get_file_extension($string));
314
+    return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true);
315 315
 }
316 316
 
317 317
 /**
318 318
  * Returns the current URL.
319 319
  */
320 320
 function wpinv_get_current_page_url() {
321
-    return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
321
+    return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
322 322
 }
323 323
 
324 324
 /**
@@ -328,46 +328,46 @@  discard block
 block discarded – undo
328 328
  * @param string $name  Constant name.
329 329
  * @param mixed  $value Value.
330 330
  */
331
-function getpaid_maybe_define_constant( $name, $value ) {
332
-	if ( ! defined( $name ) ) {
333
-		define( $name, $value );
331
+function getpaid_maybe_define_constant($name, $value) {
332
+	if (!defined($name)) {
333
+		define($name, $value);
334 334
 	}
335 335
 }
336 336
 
337 337
 function wpinv_get_php_arg_separator_output() {
338
-	return ini_get( 'arg_separator.output' );
338
+	return ini_get('arg_separator.output');
339 339
 }
340 340
 
341
-function wpinv_rgb_from_hex( $color ) {
342
-    $color = str_replace( '#', '', $color );
341
+function wpinv_rgb_from_hex($color) {
342
+    $color = str_replace('#', '', $color);
343 343
 
344 344
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
345
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
346
-    if ( empty( $color ) ) {
345
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
346
+    if (empty($color)) {
347 347
         return NULL;
348 348
     }
349 349
 
350
-    $color = str_split( $color );
350
+    $color = str_split($color);
351 351
 
352 352
     $rgb      = array();
353
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
354
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
355
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
353
+    $rgb['R'] = hexdec($color[0] . $color[1]);
354
+    $rgb['G'] = hexdec($color[2] . $color[3]);
355
+    $rgb['B'] = hexdec($color[4] . $color[5]);
356 356
 
357 357
     return $rgb;
358 358
 }
359 359
 
360
-function wpinv_hex_darker( $color, $factor = 30 ) {
361
-    $base  = wpinv_rgb_from_hex( $color );
360
+function wpinv_hex_darker($color, $factor = 30) {
361
+    $base  = wpinv_rgb_from_hex($color);
362 362
     $color = '#';
363 363
 
364
-    foreach ( $base as $k => $v ) {
364
+    foreach ($base as $k => $v) {
365 365
         $amount      = $v / 100;
366
-        $amount      = round( $amount * $factor );
366
+        $amount      = round($amount * $factor);
367 367
         $new_decimal = $v - $amount;
368 368
 
369
-        $new_hex_component = dechex( $new_decimal );
370
-        if ( strlen( $new_hex_component ) < 2 ) {
369
+        $new_hex_component = dechex($new_decimal);
370
+        if (strlen($new_hex_component) < 2) {
371 371
             $new_hex_component = "0" . $new_hex_component;
372 372
         }
373 373
         $color .= $new_hex_component;
@@ -376,18 +376,18 @@  discard block
 block discarded – undo
376 376
     return $color;
377 377
 }
378 378
 
379
-function wpinv_hex_lighter( $color, $factor = 30 ) {
380
-    $base  = wpinv_rgb_from_hex( $color );
379
+function wpinv_hex_lighter($color, $factor = 30) {
380
+    $base  = wpinv_rgb_from_hex($color);
381 381
     $color = '#';
382 382
 
383
-    foreach ( $base as $k => $v ) {
383
+    foreach ($base as $k => $v) {
384 384
         $amount      = 255 - $v;
385 385
         $amount      = $amount / 100;
386
-        $amount      = round( $amount * $factor );
386
+        $amount      = round($amount * $factor);
387 387
         $new_decimal = $v + $amount;
388 388
 
389
-        $new_hex_component = dechex( $new_decimal );
390
-        if ( strlen( $new_hex_component ) < 2 ) {
389
+        $new_hex_component = dechex($new_decimal);
390
+        if (strlen($new_hex_component) < 2) {
391 391
             $new_hex_component = "0" . $new_hex_component;
392 392
         }
393 393
         $color .= $new_hex_component;
@@ -396,22 +396,22 @@  discard block
 block discarded – undo
396 396
     return $color;
397 397
 }
398 398
 
399
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
400
-    $hex = str_replace( '#', '', $color );
399
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
400
+    $hex = str_replace('#', '', $color);
401 401
 
402
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
403
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
404
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
402
+    $c_r = hexdec(substr($hex, 0, 2));
403
+    $c_g = hexdec(substr($hex, 2, 2));
404
+    $c_b = hexdec(substr($hex, 4, 2));
405 405
 
406
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
406
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
407 407
 
408 408
     return $brightness > 155 ? $dark : $light;
409 409
 }
410 410
 
411
-function wpinv_format_hex( $hex ) {
412
-    $hex = trim( str_replace( '#', '', $hex ) );
411
+function wpinv_format_hex($hex) {
412
+    $hex = trim(str_replace('#', '', $hex));
413 413
 
414
-    if ( strlen( $hex ) == 3 ) {
414
+    if (strlen($hex) == 3) {
415 415
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
416 416
     }
417 417
 
@@ -431,12 +431,12 @@  discard block
 block discarded – undo
431 431
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
432 432
  * @return string
433 433
  */
434
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
435
-    if ( function_exists( 'mb_strimwidth' ) ) {
436
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
434
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
435
+    if (function_exists('mb_strimwidth')) {
436
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
437 437
     }
438 438
     
439
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
439
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
440 440
 }
441 441
 
442 442
 /**
@@ -448,28 +448,28 @@  discard block
 block discarded – undo
448 448
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
449 449
  * @return int Returns the number of characters in string.
450 450
  */
451
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
452
-    if ( function_exists( 'mb_strlen' ) ) {
453
-        return mb_strlen( $str, $encoding );
451
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
452
+    if (function_exists('mb_strlen')) {
453
+        return mb_strlen($str, $encoding);
454 454
     }
455 455
         
456
-    return strlen( $str );
456
+    return strlen($str);
457 457
 }
458 458
 
459
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
460
-    if ( function_exists( 'mb_strtolower' ) ) {
461
-        return mb_strtolower( $str, $encoding );
459
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
460
+    if (function_exists('mb_strtolower')) {
461
+        return mb_strtolower($str, $encoding);
462 462
     }
463 463
     
464
-    return strtolower( $str );
464
+    return strtolower($str);
465 465
 }
466 466
 
467
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
468
-    if ( function_exists( 'mb_strtoupper' ) ) {
469
-        return mb_strtoupper( $str, $encoding );
467
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
468
+    if (function_exists('mb_strtoupper')) {
469
+        return mb_strtoupper($str, $encoding);
470 470
     }
471 471
     
472
-    return strtoupper( $str );
472
+    return strtoupper($str);
473 473
 }
474 474
 
475 475
 /**
@@ -483,12 +483,12 @@  discard block
 block discarded – undo
483 483
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
484 484
  * @return int Returns the position of the first occurrence of search in the string.
485 485
  */
486
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
487
-    if ( function_exists( 'mb_strpos' ) ) {
488
-        return mb_strpos( $str, $find, $offset, $encoding );
486
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
487
+    if (function_exists('mb_strpos')) {
488
+        return mb_strpos($str, $find, $offset, $encoding);
489 489
     }
490 490
         
491
-    return strpos( $str, $find, $offset );
491
+    return strpos($str, $find, $offset);
492 492
 }
493 493
 
494 494
 /**
@@ -502,12 +502,12 @@  discard block
 block discarded – undo
502 502
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
503 503
  * @return int Returns the position of the last occurrence of search.
504 504
  */
505
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
506
-    if ( function_exists( 'mb_strrpos' ) ) {
507
-        return mb_strrpos( $str, $find, $offset, $encoding );
505
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
506
+    if (function_exists('mb_strrpos')) {
507
+        return mb_strrpos($str, $find, $offset, $encoding);
508 508
     }
509 509
         
510
-    return strrpos( $str, $find, $offset );
510
+    return strrpos($str, $find, $offset);
511 511
 }
512 512
 
513 513
 /**
@@ -522,16 +522,16 @@  discard block
 block discarded – undo
522 522
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
523 523
  * @return string
524 524
  */
525
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
526
-    if ( function_exists( 'mb_substr' ) ) {
527
-        if ( $length === null ) {
528
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
525
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
526
+    if (function_exists('mb_substr')) {
527
+        if ($length === null) {
528
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
529 529
         } else {
530
-            return mb_substr( $str, $start, $length, $encoding );
530
+            return mb_substr($str, $start, $length, $encoding);
531 531
         }
532 532
     }
533 533
         
534
-    return substr( $str, $start, $length );
534
+    return substr($str, $start, $length);
535 535
 }
536 536
 
537 537
 /**
@@ -543,48 +543,48 @@  discard block
 block discarded – undo
543 543
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
544 544
  * @return string The width of string.
545 545
  */
546
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
547
-    if ( function_exists( 'mb_strwidth' ) ) {
548
-        return mb_strwidth( $str, $encoding );
546
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
547
+    if (function_exists('mb_strwidth')) {
548
+        return mb_strwidth($str, $encoding);
549 549
     }
550 550
     
551
-    return wpinv_utf8_strlen( $str, $encoding );
551
+    return wpinv_utf8_strlen($str, $encoding);
552 552
 }
553 553
 
554
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
555
-    if ( function_exists( 'mb_strlen' ) ) {
556
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
554
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
555
+    if (function_exists('mb_strlen')) {
556
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
557 557
         $str_end = "";
558 558
         
559
-        if ( $lower_str_end ) {
560
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
559
+        if ($lower_str_end) {
560
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
561 561
         } else {
562
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
562
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
563 563
         }
564 564
 
565 565
         return $first_letter . $str_end;
566 566
     }
567 567
     
568
-    return ucfirst( $str );
568
+    return ucfirst($str);
569 569
 }
570 570
 
571
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
572
-    if ( function_exists( 'mb_convert_case' ) ) {
573
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
571
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
572
+    if (function_exists('mb_convert_case')) {
573
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
574 574
     }
575 575
     
576
-    return ucwords( $str );
576
+    return ucwords($str);
577 577
 }
578 578
 
579
-function wpinv_period_in_days( $period, $unit ) {
580
-    $period = absint( $period );
579
+function wpinv_period_in_days($period, $unit) {
580
+    $period = absint($period);
581 581
     
582
-    if ( $period > 0 ) {
583
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
582
+    if ($period > 0) {
583
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
584 584
             $period = $period * 7;
585
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
585
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
586 586
             $period = $period * 30;
587
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
587
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
588 588
             $period = $period * 365;
589 589
         }
590 590
     }
@@ -592,14 +592,14 @@  discard block
 block discarded – undo
592 592
     return $period;
593 593
 }
594 594
 
595
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
596
-    if ( function_exists( 'cal_days_in_month' ) ) {
597
-        return cal_days_in_month( $calendar, $month, $year );
595
+function wpinv_cal_days_in_month($calendar, $month, $year) {
596
+    if (function_exists('cal_days_in_month')) {
597
+        return cal_days_in_month($calendar, $month, $year);
598 598
     }
599 599
 
600 600
     // Fallback in case the calendar extension is not loaded in PHP
601 601
     // Only supports Gregorian calendar
602
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
602
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
603 603
 }
604 604
 
605 605
 /**
@@ -610,11 +610,11 @@  discard block
 block discarded – undo
610 610
  *
611 611
  * @return string
612 612
  */
613
-function wpi_help_tip( $tip, $allow_html = false ) {
614
-    if ( $allow_html ) {
615
-        $tip = wpi_sanitize_tooltip( $tip );
613
+function wpi_help_tip($tip, $allow_html = false) {
614
+    if ($allow_html) {
615
+        $tip = wpi_sanitize_tooltip($tip);
616 616
     } else {
617
-        $tip = esc_attr( $tip );
617
+        $tip = esc_attr($tip);
618 618
     }
619 619
 
620 620
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
  * @param string $var
629 629
  * @return string
630 630
  */
631
-function wpi_sanitize_tooltip( $var ) {
632
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
631
+function wpi_sanitize_tooltip($var) {
632
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
633 633
         'br'     => array(),
634 634
         'em'     => array(),
635 635
         'strong' => array(),
@@ -639,7 +639,7 @@  discard block
 block discarded – undo
639 639
         'li'     => array(),
640 640
         'ol'     => array(),
641 641
         'p'      => array(),
642
-    ) ) );
642
+    )));
643 643
 }
644 644
 
645 645
 /**
@@ -649,7 +649,7 @@  discard block
 block discarded – undo
649 649
  */
650 650
 function wpinv_get_screen_ids() {
651 651
 
652
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
652
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
653 653
 
654 654
     $screen_ids = array(
655 655
         'toplevel_page_' . $screen_id,
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
         'invoicing_page_wpi-addons',
668 668
     );
669 669
 
670
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
670
+    return apply_filters('wpinv_screen_ids', $screen_ids);
671 671
 }
672 672
 
673 673
 /**
@@ -678,14 +678,14 @@  discard block
 block discarded – undo
678 678
  * @param array|string $list List of values.
679 679
  * @return array Sanitized array of values.
680 680
  */
681
-function wpinv_parse_list( $list ) {
681
+function wpinv_parse_list($list) {
682 682
 
683
-    if ( empty( $list ) ) {
683
+    if (empty($list)) {
684 684
         $list = array();
685 685
     }
686 686
 
687
-	if ( ! is_array( $list ) ) {
688
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
687
+	if (!is_array($list)) {
688
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
689 689
 	}
690 690
 
691 691
 	return $list;
@@ -699,16 +699,16 @@  discard block
 block discarded – undo
699 699
  * @param string $key Type of data to fetch.
700 700
  * @return mixed Fetched data.
701 701
  */
702
-function wpinv_get_data( $key ) {
702
+function wpinv_get_data($key) {
703 703
 
704 704
     // Try fetching it from the cache.
705
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
706
-    if( $data ) {
705
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
706
+    if ($data) {
707 707
         return $data;
708 708
     }
709 709
 
710
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
711
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
710
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
711
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
712 712
 
713 713
 	return $data;
714 714
 }
@@ -722,10 +722,10 @@  discard block
 block discarded – undo
722 722
  * @param bool $first_empty Whether or not the first item in the list should be empty
723 723
  * @return mixed Fetched data.
724 724
  */
725
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
725
+function wpinv_maybe_add_empty_option($options, $first_empty) {
726 726
 
727
-    if ( ! empty( $options ) && $first_empty ) {
728
-        return array_merge( array( '' => '' ), $options );
727
+    if (!empty($options) && $first_empty) {
728
+        return array_merge(array('' => ''), $options);
729 729
     }
730 730
     return $options;
731 731
 
@@ -737,21 +737,21 @@  discard block
 block discarded – undo
737 737
  * @param mixed $var Data to sanitize.
738 738
  * @return string|array
739 739
  */
740
-function wpinv_clean( $var ) {
740
+function wpinv_clean($var) {
741 741
 
742
-	if ( is_array( $var ) ) {
743
-		return array_map( 'wpinv_clean', $var );
742
+	if (is_array($var)) {
743
+		return array_map('wpinv_clean', $var);
744 744
     }
745 745
 
746
-    if ( is_object( $var ) ) {
747
-		$object_vars = get_object_vars( $var );
748
-		foreach ( $object_vars as $property_name => $property_value ) {
749
-			$var->$property_name = wpinv_clean( $property_value );
746
+    if (is_object($var)) {
747
+		$object_vars = get_object_vars($var);
748
+		foreach ($object_vars as $property_name => $property_value) {
749
+			$var->$property_name = wpinv_clean($property_value);
750 750
         }
751 751
         return $var;
752 752
 	}
753 753
     
754
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
754
+    return is_string($var) ? sanitize_text_field($var) : $var;
755 755
 }
756 756
 
757 757
 /**
@@ -760,43 +760,43 @@  discard block
 block discarded – undo
760 760
  * @param string $str Data to convert.
761 761
  * @return string|array
762 762
  */
763
-function getpaid_convert_price_string_to_options( $str ) {
763
+function getpaid_convert_price_string_to_options($str) {
764 764
 
765
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
766
-    $options     = array();
765
+	$raw_options = array_map('trim', explode(',', $str));
766
+    $options = array();
767 767
 
768
-    foreach ( $raw_options as $option ) {
768
+    foreach ($raw_options as $option) {
769 769
 
770
-        if ( '' == $option ) {
770
+        if ('' == $option) {
771 771
             continue;
772 772
         }
773 773
 
774
-        $option = array_map( 'trim', explode( '|', $option ) );
774
+        $option = array_map('trim', explode('|', $option));
775 775
 
776 776
         $price = null;
777 777
         $label = null;
778 778
 
779
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
780
-            $label  = $option[0];
779
+        if (isset($option[0]) && '' != $option[0]) {
780
+            $label = $option[0];
781 781
         }
782 782
 
783
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
783
+        if (isset($option[1]) && '' != $option[1]) {
784 784
             $price = $option[1];
785 785
         }
786 786
 
787
-        if ( ! isset( $price ) ) {
787
+        if (!isset($price)) {
788 788
             $price = $label;
789 789
         }
790 790
 
791
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
791
+        if (!isset($price) || !is_numeric($price)) {
792 792
             continue;
793 793
         }
794 794
 
795
-        if ( ! isset( $label ) ) {
795
+        if (!isset($label)) {
796 796
             $label = $price;
797 797
         }
798 798
 
799
-        $options[ $price ] = $label;
799
+        $options[$price] = $label;
800 800
     }
801 801
 
802 802
     return $options;
@@ -805,22 +805,22 @@  discard block
 block discarded – undo
805 805
 /**
806 806
  * Returns the help tip.
807 807
  */
808
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
809
-    $additional_classes = sanitize_html_class( $additional_classes );
810
-    $tip                = esc_attr__( $tip );
808
+function getpaid_get_help_tip($tip, $additional_classes = '') {
809
+    $additional_classes = sanitize_html_class($additional_classes);
810
+    $tip                = esc_attr__($tip);
811 811
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
812 812
 }
813 813
 
814 814
 /**
815 815
  * Formats a date
816 816
  */
817
-function getpaid_format_date( $date ) {
817
+function getpaid_format_date($date) {
818 818
 
819
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
819
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
820 820
         return '';
821 821
     }
822 822
 
823
-    return date_i18n( getpaid_date_format(), strtotime( $date ) );
823
+    return date_i18n(getpaid_date_format(), strtotime($date));
824 824
 
825 825
 }
826 826
 
@@ -829,9 +829,9 @@  discard block
 block discarded – undo
829 829
  *
830 830
  * @return string
831 831
  */
832
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
833
-    $date = getpaid_format_date( $date );
834
-    return empty( $date ) ? $default : $date;
832
+function getpaid_format_date_value($date, $default = "&mdash;") {
833
+    $date = getpaid_format_date($date);
834
+    return empty($date) ? $default : $date;
835 835
 }
836 836
 
837 837
 /**
@@ -840,7 +840,7 @@  discard block
 block discarded – undo
840 840
  * @return string
841 841
  */
842 842
 function getpaid_date_format() {
843
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
843
+	return apply_filters('getpaid_date_format', get_option('date_format'));
844 844
 }
845 845
 
846 846
 /**
@@ -849,7 +849,7 @@  discard block
 block discarded – undo
849 849
  * @return string
850 850
  */
851 851
 function getpaid_time_format() {
852
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
852
+	return apply_filters('getpaid_time_format', get_option('time_format'));
853 853
 }
854 854
 
855 855
 /**
@@ -859,16 +859,16 @@  discard block
 block discarded – undo
859 859
  * @param  integer $limit Limit size in characters.
860 860
  * @return string
861 861
  */
862
-function getpaid_limit_length( $string, $limit ) {
862
+function getpaid_limit_length($string, $limit) {
863 863
     $str_limit = $limit - 3;
864 864
 
865
-	if ( function_exists( 'mb_strimwidth' ) ) {
866
-		if ( mb_strlen( $string ) > $limit ) {
867
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
865
+	if (function_exists('mb_strimwidth')) {
866
+		if (mb_strlen($string) > $limit) {
867
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
868 868
 		}
869 869
 	} else {
870
-		if ( strlen( $string ) > $limit ) {
871
-			$string = substr( $string, 0, $str_limit ) . '...';
870
+		if (strlen($string) > $limit) {
871
+			$string = substr($string, 0, $str_limit) . '...';
872 872
 		}
873 873
 	}
874 874
     return $string;
@@ -882,7 +882,7 @@  discard block
 block discarded – undo
882 882
  * @since 1.0.19
883 883
  */
884 884
 function getpaid_api() {
885
-    return getpaid()->get( 'api' );
885
+    return getpaid()->get('api');
886 886
 }
887 887
 
888 888
 /**
@@ -892,7 +892,7 @@  discard block
 block discarded – undo
892 892
  * @since 1.0.19
893 893
  */
894 894
 function getpaid_post_types() {
895
-    return getpaid()->get( 'post_types' );
895
+    return getpaid()->get('post_types');
896 896
 }
897 897
 
898 898
 /**
@@ -902,7 +902,7 @@  discard block
 block discarded – undo
902 902
  * @since 1.0.19
903 903
  */
904 904
 function getpaid_session() {
905
-    return getpaid()->get( 'session' );
905
+    return getpaid()->get('session');
906 906
 }
907 907
 
908 908
 /**
@@ -912,7 +912,7 @@  discard block
 block discarded – undo
912 912
  * @since 1.0.19
913 913
  */
914 914
 function getpaid_notes() {
915
-    return getpaid()->get( 'notes' );
915
+    return getpaid()->get('notes');
916 916
 }
917 917
 
918 918
 /**
@@ -921,7 +921,7 @@  discard block
 block discarded – undo
921 921
  * @return GetPaid_Admin
922 922
  */
923 923
 function getpaid_admin() {
924
-    return getpaid()->get( 'admin' );
924
+    return getpaid()->get('admin');
925 925
 }
926 926
 
927 927
 /**
@@ -931,6 +931,6 @@  discard block
 block discarded – undo
931 931
  * @param string $base the base url
932 932
  * @return string
933 933
  */
934
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
935
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
934
+function getpaid_get_authenticated_action_url($action, $base = false) {
935
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
936 936
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -12,185 +12,185 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-
41
-	}
42
-
43
-	/**
44
-	 * Adds totals to a response for submission refresh prices.
45
-	 *
46
-	 * @param GetPaid_Payment_Form_Submission $submission
47
-	 */
48
-	public function add_totals( $submission ) {
49
-
50
-		$this->response = array_merge(
51
-			$this->response,
52
-			array(
53
-
54
-				'totals'        => array(
55
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
57
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
58
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
59
-					'total'     => $submission->format_amount( $submission->get_total() ),
60
-				),
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+
41
+    }
42
+
43
+    /**
44
+     * Adds totals to a response for submission refresh prices.
45
+     *
46
+     * @param GetPaid_Payment_Form_Submission $submission
47
+     */
48
+    public function add_totals( $submission ) {
49
+
50
+        $this->response = array_merge(
51
+            $this->response,
52
+            array(
53
+
54
+                'totals'        => array(
55
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
57
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
58
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
59
+                    'total'     => $submission->format_amount( $submission->get_total() ),
60
+                ),
61 61
 	
62
-				'recurring'     => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
-				),
62
+                'recurring'     => array(
63
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
68
+                ),
69 69
 
70
-			)
71
-		);
70
+            )
71
+        );
72 72
 
73
-	}
73
+    }
74 74
 
75
-	/**
76
-	 * Adds texts to a response for submission refresh prices.
77
-	 *
78
-	 * @param GetPaid_Payment_Form_Submission $submission
79
-	 */
80
-	public function add_texts( $submission ) {
75
+    /**
76
+     * Adds texts to a response for submission refresh prices.
77
+     *
78
+     * @param GetPaid_Payment_Form_Submission $submission
79
+     */
80
+    public function add_texts( $submission ) {
81 81
 
82
-		$payable = $submission->format_amount( $submission->get_total() );
82
+        $payable = $submission->format_amount( $submission->get_total() );
83 83
 
84
-		if ( $submission->has_recurring != 0 ) {
84
+        if ( $submission->has_recurring != 0 ) {
85 85
 
86
-			$recurring = new WPInv_Item( $submission->has_recurring );
87
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
86
+            $recurring = new WPInv_Item( $submission->has_recurring );
87
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
88 88
 
89
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
-				$payable = "$payable / $period";
91
-			} else {
92
-				$payable = sprintf(
93
-					__( '%1$s (renews at %2$s / %3$s)'),
94
-					$submission->format_amount( $submission->get_total() ),
95
-					$submission->format_amount( $submission->get_recurring_total() ),
96
-					$period
97
-				);
98
-			}
89
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
90
+                $payable = "$payable / $period";
91
+            } else {
92
+                $payable = sprintf(
93
+                    __( '%1$s (renews at %2$s / %3$s)'),
94
+                    $submission->format_amount( $submission->get_total() ),
95
+                    $submission->format_amount( $submission->get_recurring_total() ),
96
+                    $period
97
+                );
98
+            }
99 99
 
100
-		}
100
+        }
101 101
 
102
-		$texts = array(
103
-			'.getpaid-checkout-total-payable' => $payable,
104
-		);
102
+        $texts = array(
103
+            '.getpaid-checkout-total-payable' => $payable,
104
+        );
105 105
 
106
-		foreach ( $submission->get_items() as $item_id => $item ) {
107
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
109
-		}
106
+        foreach ( $submission->get_items() as $item_id => $item ) {
107
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
109
+        }
110 110
 
111
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
111
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
112 112
 
113
-	}
113
+    }
114 114
 
115
-	/**
116
-	 * Adds items to a response for submission refresh prices.
117
-	 *
118
-	 * @param GetPaid_Payment_Form_Submission $submission
119
-	 */
120
-	public function add_items( $submission ) {
115
+    /**
116
+     * Adds items to a response for submission refresh prices.
117
+     *
118
+     * @param GetPaid_Payment_Form_Submission $submission
119
+     */
120
+    public function add_items( $submission ) {
121 121
 
122
-		// Add items.
123
-		$items = array();
122
+        // Add items.
123
+        $items = array();
124 124
 
125 125
         foreach ( $submission->get_items() as $item_id => $item ) {
126
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
127
-		}
126
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
127
+        }
128 128
 
129
-		$this->response = array_merge(
130
-			$this->response,
131
-			array( 'items' => $items )
132
-		);
129
+        $this->response = array_merge(
130
+            $this->response,
131
+            array( 'items' => $items )
132
+        );
133 133
 
134
-	}
134
+    }
135 135
 
136
-	/**
137
-	 * Adds fees to a response for submission refresh prices.
138
-	 *
139
-	 * @param GetPaid_Payment_Form_Submission $submission
140
-	 */
141
-	public function add_fees( $submission ) {
136
+    /**
137
+     * Adds fees to a response for submission refresh prices.
138
+     *
139
+     * @param GetPaid_Payment_Form_Submission $submission
140
+     */
141
+    public function add_fees( $submission ) {
142 142
 
143
-		$fees = array();
143
+        $fees = array();
144 144
 
145 145
         foreach ( $submission->get_fees() as $name => $data ) {
146
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
147
-		}
146
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
147
+        }
148 148
 
149
-		$this->response = array_merge(
150
-			$this->response,
151
-			array( 'fees' => $fees )
152
-		);
149
+        $this->response = array_merge(
150
+            $this->response,
151
+            array( 'fees' => $fees )
152
+        );
153 153
 
154
-	}
154
+    }
155 155
 
156
-	/**
157
-	 * Adds discounts to a response for submission refresh prices.
158
-	 *
159
-	 * @param GetPaid_Payment_Form_Submission $submission
160
-	 */
161
-	public function add_discounts( $submission ) {
156
+    /**
157
+     * Adds discounts to a response for submission refresh prices.
158
+     *
159
+     * @param GetPaid_Payment_Form_Submission $submission
160
+     */
161
+    public function add_discounts( $submission ) {
162 162
 
163
-		$discounts = array();
163
+        $discounts = array();
164 164
 
165 165
         foreach ( $submission->get_discounts() as $name => $data ) {
166
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
167
-		}
166
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
167
+        }
168 168
 
169
-		$this->response = array_merge(
170
-			$this->response,
171
-			array( 'discounts' => $discounts )
172
-		);
169
+        $this->response = array_merge(
170
+            $this->response,
171
+            array( 'discounts' => $discounts )
172
+        );
173 173
 
174
-	}
174
+    }
175 175
 
176
-	/**
177
-	 * Adds taxes to a response for submission refresh prices.
178
-	 *
179
-	 * @param GetPaid_Payment_Form_Submission $submission
180
-	 */
181
-	public function add_taxes( $submission ) {
176
+    /**
177
+     * Adds taxes to a response for submission refresh prices.
178
+     *
179
+     * @param GetPaid_Payment_Form_Submission $submission
180
+     */
181
+    public function add_taxes( $submission ) {
182 182
 
183
-		$taxes = array();
183
+        $taxes = array();
184 184
 
185 185
         foreach ( $submission->get_taxes() as $name => $data ) {
186
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
187
-		}
186
+            $taxes[$name] = $submission->format_amount( $data['initial_tax'] );
187
+        }
188 188
 
189
-		$this->response = array_merge(
190
-			$this->response,
191
-			array( 'taxes' => $taxes )
192
-		);
189
+        $this->response = array_merge(
190
+            $this->response,
191
+            array( 'taxes' => $taxes )
192
+        );
193 193
 
194
-	}
194
+    }
195 195
 
196 196
 }
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 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 refresh prices class
@@ -23,20 +23,20 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31
-            'is_free'       => ! $submission->should_collect_payment_details(),
31
+            'is_free'       => !$submission->should_collect_payment_details(),
32 32
 		);
33 33
 
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
34
+		$this->add_totals($submission);
35
+		$this->add_texts($submission);
36
+		$this->add_items($submission);
37
+		$this->add_fees($submission);
38
+		$this->add_discounts($submission);
39
+		$this->add_taxes($submission);
40 40
 
41 41
 	}
42 42
 
@@ -45,26 +45,26 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @param GetPaid_Payment_Form_Submission $submission
47 47
 	 */
48
-	public function add_totals( $submission ) {
48
+	public function add_totals($submission) {
49 49
 
50 50
 		$this->response = array_merge(
51 51
 			$this->response,
52 52
 			array(
53 53
 
54 54
 				'totals'        => array(
55
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
56
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
57
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
58
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
59
-					'total'     => $submission->format_amount( $submission->get_total() ),
55
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
56
+					'discount'  => $submission->format_amount($submission->get_discount()),
57
+					'fees'      => $submission->format_amount($submission->get_fee()),
58
+					'tax'       => $submission->format_amount($submission->get_tax()),
59
+					'total'     => $submission->format_amount($submission->get_total()),
60 60
 				),
61 61
 	
62 62
 				'recurring'     => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
63
+					'subtotal'  => $submission->format_amount($submission->get_recurring_subtotal()),
64
+					'discount'  => $submission->format_amount($submission->get_recurring_discount()),
65
+					'fees'      => $submission->format_amount($submission->get_recurring_fee()),
66
+					'tax'       => $submission->format_amount($submission->get_recurring_tax()),
67
+					'total'     => $submission->format_amount($submission->get_recurring_total()),
68 68
 				),
69 69
 
70 70
 			)
@@ -77,22 +77,22 @@  discard block
 block discarded – undo
77 77
 	 *
78 78
 	 * @param GetPaid_Payment_Form_Submission $submission
79 79
 	 */
80
-	public function add_texts( $submission ) {
80
+	public function add_texts($submission) {
81 81
 
82
-		$payable = $submission->format_amount( $submission->get_total() );
82
+		$payable = $submission->format_amount($submission->get_total());
83 83
 
84
-		if ( $submission->has_recurring != 0 ) {
84
+		if ($submission->has_recurring != 0) {
85 85
 
86
-			$recurring = new WPInv_Item( $submission->has_recurring );
87
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
86
+			$recurring = new WPInv_Item($submission->has_recurring);
87
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
88 88
 
89
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
89
+			if ($submission->get_total() == $submission->get_recurring_total()) {
90 90
 				$payable = "$payable / $period";
91 91
 			} else {
92 92
 				$payable = sprintf(
93
-					__( '%1$s (renews at %2$s / %3$s)'),
94
-					$submission->format_amount( $submission->get_total() ),
95
-					$submission->format_amount( $submission->get_recurring_total() ),
93
+					__('%1$s (renews at %2$s / %3$s)'),
94
+					$submission->format_amount($submission->get_total()),
95
+					$submission->format_amount($submission->get_recurring_total()),
96 96
 					$period
97 97
 				);
98 98
 			}
@@ -103,12 +103,12 @@  discard block
 block discarded – undo
103 103
 			'.getpaid-checkout-total-payable' => $payable,
104 104
 		);
105 105
 
106
-		foreach ( $submission->get_items() as $item_id => $item ) {
107
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
108
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
106
+		foreach ($submission->get_items() as $item_id => $item) {
107
+			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount($item->get_sub_total());
108
+			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount($item->get_recurring_sub_total());
109 109
 		}
110 110
 
111
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
111
+		$this->response = array_merge($this->response, array('texts' => $texts));
112 112
 
113 113
 	}
114 114
 
@@ -117,18 +117,18 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param GetPaid_Payment_Form_Submission $submission
119 119
 	 */
120
-	public function add_items( $submission ) {
120
+	public function add_items($submission) {
121 121
 
122 122
 		// Add items.
123 123
 		$items = array();
124 124
 
125
-        foreach ( $submission->get_items() as $item_id => $item ) {
126
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
125
+        foreach ($submission->get_items() as $item_id => $item) {
126
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
127 127
 		}
128 128
 
129 129
 		$this->response = array_merge(
130 130
 			$this->response,
131
-			array( 'items' => $items )
131
+			array('items' => $items)
132 132
 		);
133 133
 
134 134
 	}
@@ -138,17 +138,17 @@  discard block
 block discarded – undo
138 138
 	 *
139 139
 	 * @param GetPaid_Payment_Form_Submission $submission
140 140
 	 */
141
-	public function add_fees( $submission ) {
141
+	public function add_fees($submission) {
142 142
 
143 143
 		$fees = array();
144 144
 
145
-        foreach ( $submission->get_fees() as $name => $data ) {
146
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
145
+        foreach ($submission->get_fees() as $name => $data) {
146
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
147 147
 		}
148 148
 
149 149
 		$this->response = array_merge(
150 150
 			$this->response,
151
-			array( 'fees' => $fees )
151
+			array('fees' => $fees)
152 152
 		);
153 153
 
154 154
 	}
@@ -158,17 +158,17 @@  discard block
 block discarded – undo
158 158
 	 *
159 159
 	 * @param GetPaid_Payment_Form_Submission $submission
160 160
 	 */
161
-	public function add_discounts( $submission ) {
161
+	public function add_discounts($submission) {
162 162
 
163 163
 		$discounts = array();
164 164
 
165
-        foreach ( $submission->get_discounts() as $name => $data ) {
166
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
165
+        foreach ($submission->get_discounts() as $name => $data) {
166
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
167 167
 		}
168 168
 
169 169
 		$this->response = array_merge(
170 170
 			$this->response,
171
-			array( 'discounts' => $discounts )
171
+			array('discounts' => $discounts)
172 172
 		);
173 173
 
174 174
 	}
@@ -178,17 +178,17 @@  discard block
 block discarded – undo
178 178
 	 *
179 179
 	 * @param GetPaid_Payment_Form_Submission $submission
180 180
 	 */
181
-	public function add_taxes( $submission ) {
181
+	public function add_taxes($submission) {
182 182
 
183 183
 		$taxes = array();
184 184
 
185
-        foreach ( $submission->get_taxes() as $name => $data ) {
186
-			$taxes[$name] = $submission->format_amount( $data['initial_tax'] );
185
+        foreach ($submission->get_taxes() as $name => $data) {
186
+			$taxes[$name] = $submission->format_amount($data['initial_tax']);
187 187
 		}
188 188
 
189 189
 		$this->response = array_merge(
190 190
 			$this->response,
191
-			array( 'taxes' => $taxes )
191
+			array('taxes' => $taxes)
192 192
 		);
193 193
 
194 194
 	}
Please login to merge, or discard this patch.