Passed
Pull Request — master (#377)
by Brian
05:01
created
includes/class-wpinv-item.php 1 patch
Indentation   +604 added lines, -604 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,33 +74,33 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( is_numeric( $item ) && $item > 0 ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} else {
91
-			$this->set_object_read( true );
92
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( is_numeric( $item ) && $item > 0 ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } else {
91
+            $this->set_object_read( true );
92
+        }
93 93
 
94 94
         // Load the datastore.
95
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
95
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
96 96
 
97
-		if ( $this->get_id() > 0 ) {
97
+        if ( $this->get_id() > 0 ) {
98 98
             $this->post = get_post( $this->get_id() );
99 99
             $this->ID   = $this->get_id();
100
-			$this->data_store->read( $this );
100
+            $this->data_store->read( $this );
101 101
         }
102 102
 
103
-	}
103
+    }
104 104
 
105 105
     /*
106 106
 	|--------------------------------------------------------------------------
@@ -118,194 +118,194 @@  discard block
 block discarded – undo
118 118
     */
119 119
 
120 120
     /**
121
-	 * Get parent item ID.
122
-	 *
123
-	 * @since 1.0.19
124
-	 * @param  string $context View or edit context.
125
-	 * @return int
126
-	 */
127
-	public function get_parent_id( $context = 'view' ) {
128
-		return (int) $this->get_prop( 'parent_id', $context );
121
+     * Get parent item ID.
122
+     *
123
+     * @since 1.0.19
124
+     * @param  string $context View or edit context.
125
+     * @return int
126
+     */
127
+    public function get_parent_id( $context = 'view' ) {
128
+        return (int) $this->get_prop( 'parent_id', $context );
129 129
     }
130 130
 
131 131
     /**
132
-	 * Get item status.
133
-	 *
134
-	 * @since 1.0.19
135
-	 * @param  string $context View or edit context.
136
-	 * @return string
137
-	 */
138
-	public function get_status( $context = 'view' ) {
139
-		return $this->get_prop( 'status', $context );
132
+     * Get item status.
133
+     *
134
+     * @since 1.0.19
135
+     * @param  string $context View or edit context.
136
+     * @return string
137
+     */
138
+    public function get_status( $context = 'view' ) {
139
+        return $this->get_prop( 'status', $context );
140 140
     }
141 141
 
142 142
     /**
143
-	 * Get plugin version when the item was created.
144
-	 *
145
-	 * @since 1.0.19
146
-	 * @param  string $context View or edit context.
147
-	 * @return string
148
-	 */
149
-	public function get_version( $context = 'view' ) {
150
-		return $this->get_prop( 'version', $context );
143
+     * Get plugin version when the item was created.
144
+     *
145
+     * @since 1.0.19
146
+     * @param  string $context View or edit context.
147
+     * @return string
148
+     */
149
+    public function get_version( $context = 'view' ) {
150
+        return $this->get_prop( 'version', $context );
151 151
     }
152 152
 
153 153
     /**
154
-	 * Get date when the item was created.
155
-	 *
156
-	 * @since 1.0.19
157
-	 * @param  string $context View or edit context.
158
-	 * @return string
159
-	 */
160
-	public function get_date_created( $context = 'view' ) {
161
-		return $this->get_prop( 'date_created', $context );
154
+     * Get date when the item was created.
155
+     *
156
+     * @since 1.0.19
157
+     * @param  string $context View or edit context.
158
+     * @return string
159
+     */
160
+    public function get_date_created( $context = 'view' ) {
161
+        return $this->get_prop( 'date_created', $context );
162 162
     }
163 163
 
164 164
     /**
165
-	 * Get GMT date when the item was created.
166
-	 *
167
-	 * @since 1.0.19
168
-	 * @param  string $context View or edit context.
169
-	 * @return string
170
-	 */
171
-	public function get_date_created_gmt( $context = 'view' ) {
165
+     * Get GMT date when the item was created.
166
+     *
167
+     * @since 1.0.19
168
+     * @param  string $context View or edit context.
169
+     * @return string
170
+     */
171
+    public function get_date_created_gmt( $context = 'view' ) {
172 172
         $date = $this->get_date_created( $context );
173 173
 
174 174
         if ( $date ) {
175 175
             $date = get_gmt_from_date( $date );
176 176
         }
177
-		return $date;
177
+        return $date;
178 178
     }
179 179
 
180 180
     /**
181
-	 * Get date when the item was last modified.
182
-	 *
183
-	 * @since 1.0.19
184
-	 * @param  string $context View or edit context.
185
-	 * @return string
186
-	 */
187
-	public function get_date_modified( $context = 'view' ) {
188
-		return $this->get_prop( 'date_modified', $context );
181
+     * Get date when the item was last modified.
182
+     *
183
+     * @since 1.0.19
184
+     * @param  string $context View or edit context.
185
+     * @return string
186
+     */
187
+    public function get_date_modified( $context = 'view' ) {
188
+        return $this->get_prop( 'date_modified', $context );
189 189
     }
190 190
 
191 191
     /**
192
-	 * Get GMT date when the item was last modified.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return string
197
-	 */
198
-	public function get_date_modified_gmt( $context = 'view' ) {
192
+     * Get GMT date when the item was last modified.
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return string
197
+     */
198
+    public function get_date_modified_gmt( $context = 'view' ) {
199 199
         $date = $this->get_date_modified( $context );
200 200
 
201 201
         if ( $date ) {
202 202
             $date = get_gmt_from_date( $date );
203 203
         }
204
-		return $date;
204
+        return $date;
205 205
     }
206 206
 
207 207
     /**
208
-	 * Get the item name.
209
-	 *
210
-	 * @since 1.0.19
211
-	 * @param  string $context View or edit context.
212
-	 * @return string
213
-	 */
214
-	public function get_name( $context = 'view' ) {
215
-		return $this->get_prop( 'name', $context );
208
+     * Get the item name.
209
+     *
210
+     * @since 1.0.19
211
+     * @param  string $context View or edit context.
212
+     * @return string
213
+     */
214
+    public function get_name( $context = 'view' ) {
215
+        return $this->get_prop( 'name', $context );
216 216
     }
217 217
 
218 218
     /**
219
-	 * Alias of self::get_name().
220
-	 *
221
-	 * @since 1.0.19
222
-	 * @param  string $context View or edit context.
223
-	 * @return string
224
-	 */
225
-	public function get_title( $context = 'view' ) {
226
-		return $this->get_name( $context );
219
+     * Alias of self::get_name().
220
+     *
221
+     * @since 1.0.19
222
+     * @param  string $context View or edit context.
223
+     * @return string
224
+     */
225
+    public function get_title( $context = 'view' ) {
226
+        return $this->get_name( $context );
227 227
     }
228 228
 
229 229
     /**
230
-	 * Get the item description.
231
-	 *
232
-	 * @since 1.0.19
233
-	 * @param  string $context View or edit context.
234
-	 * @return string
235
-	 */
236
-	public function get_description( $context = 'view' ) {
237
-		return $this->get_prop( 'description', $context );
230
+     * Get the item description.
231
+     *
232
+     * @since 1.0.19
233
+     * @param  string $context View or edit context.
234
+     * @return string
235
+     */
236
+    public function get_description( $context = 'view' ) {
237
+        return $this->get_prop( 'description', $context );
238 238
     }
239 239
 
240 240
     /**
241
-	 * Alias of self::get_description().
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return string
246
-	 */
247
-	public function get_excerpt( $context = 'view' ) {
248
-		return $this->get_description( $context );
241
+     * Alias of self::get_description().
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return string
246
+     */
247
+    public function get_excerpt( $context = 'view' ) {
248
+        return $this->get_description( $context );
249 249
     }
250 250
 
251 251
     /**
252
-	 * Alias of self::get_description().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return string
257
-	 */
258
-	public function get_summary( $context = 'view' ) {
259
-		return $this->get_description( $context );
252
+     * Alias of self::get_description().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return string
257
+     */
258
+    public function get_summary( $context = 'view' ) {
259
+        return $this->get_description( $context );
260 260
     }
261 261
 
262 262
     /**
263
-	 * Get the owner of the item.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return string
268
-	 */
269
-	public function get_author( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'author', $context );
263
+     * Get the owner of the item.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return string
268
+     */
269
+    public function get_author( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'author', $context );
271 271
     }
272 272
 
273 273
     /**
274
-	 * Get the price of the item.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return float
279
-	 */
280
-	public function get_price( $context = 'view' ) {
274
+     * Get the price of the item.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return float
279
+     */
280
+    public function get_price( $context = 'view' ) {
281 281
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
282
-	}
282
+    }
283 283
 	
284
-	/**
285
-	 * Get the inital price of the item.
286
-	 *
287
-	 * @since 1.0.19
288
-	 * @param  string $context View or edit context.
289
-	 * @return float
290
-	 */
291
-	public function get_initial_price( $context = 'view' ) {
284
+    /**
285
+     * Get the inital price of the item.
286
+     *
287
+     * @since 1.0.19
288
+     * @param  string $context View or edit context.
289
+     * @return float
290
+     */
291
+    public function get_initial_price( $context = 'view' ) {
292 292
 
293
-		$price = $this->get_price( $context );
293
+        $price = $this->get_price( $context );
294 294
 
295
-		if ( $this->has_free_trial() ) {
296
-			$price = wpinv_sanitize_amount( 0 );
297
-		}
295
+        if ( $this->has_free_trial() ) {
296
+            $price = wpinv_sanitize_amount( 0 );
297
+        }
298 298
 
299 299
         return apply_filters( 'wpinv_get_initial_item_price', $price, $this );
300 300
     }
301 301
 
302 302
     /**
303
-	 * Returns a formated price.
304
-	 *
305
-	 * @since 1.0.19
306
-	 * @param  string $context View or edit context.
307
-	 * @return string
308
-	 */
303
+     * Returns a formated price.
304
+     *
305
+     * @since 1.0.19
306
+     * @param  string $context View or edit context.
307
+     * @return string
308
+     */
309 309
     public function get_the_price() {
310 310
         $item_price = wpinv_price( $this->get_price() );
311 311
 
@@ -313,175 +313,175 @@  discard block
 block discarded – undo
313 313
     }
314 314
 
315 315
     /**
316
-	 * Get the VAT rule of the item.
317
-	 *
318
-	 * @since 1.0.19
319
-	 * @param  string $context View or edit context.
320
-	 * @return string
321
-	 */
322
-	public function get_vat_rule( $context = 'view' ) {
316
+     * Get the VAT rule of the item.
317
+     *
318
+     * @since 1.0.19
319
+     * @param  string $context View or edit context.
320
+     * @return string
321
+     */
322
+    public function get_vat_rule( $context = 'view' ) {
323 323
         return $this->get_prop( 'vat_rule', $context );
324 324
     }
325 325
 
326 326
     /**
327
-	 * Get the VAT class of the item.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  string $context View or edit context.
331
-	 * @return string
332
-	 */
333
-	public function get_vat_class( $context = 'view' ) {
327
+     * Get the VAT class of the item.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  string $context View or edit context.
331
+     * @return string
332
+     */
333
+    public function get_vat_class( $context = 'view' ) {
334 334
         return $this->get_prop( 'vat_class', $context );
335 335
     }
336 336
 
337 337
     /**
338
-	 * Get the type of the item.
339
-	 *
340
-	 * @since 1.0.19
341
-	 * @param  string $context View or edit context.
342
-	 * @return string
343
-	 */
344
-	public function get_type( $context = 'view' ) {
338
+     * Get the type of the item.
339
+     *
340
+     * @since 1.0.19
341
+     * @param  string $context View or edit context.
342
+     * @return string
343
+     */
344
+    public function get_type( $context = 'view' ) {
345 345
         return $this->get_prop( 'type', $context );
346 346
     }
347 347
 
348 348
     /**
349
-	 * Get the custom id of the item.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @param  string $context View or edit context.
353
-	 * @return string
354
-	 */
355
-	public function get_custom_id( $context = 'view' ) {
349
+     * Get the custom id of the item.
350
+     *
351
+     * @since 1.0.19
352
+     * @param  string $context View or edit context.
353
+     * @return string
354
+     */
355
+    public function get_custom_id( $context = 'view' ) {
356 356
         return $this->get_prop( 'custom_id', $context );
357 357
     }
358 358
 
359 359
     /**
360
-	 * Get the custom name of the item.
361
-	 *
362
-	 * @since 1.0.19
363
-	 * @param  string $context View or edit context.
364
-	 * @return string
365
-	 */
366
-	public function get_custom_name( $context = 'view' ) {
360
+     * Get the custom name of the item.
361
+     *
362
+     * @since 1.0.19
363
+     * @param  string $context View or edit context.
364
+     * @return string
365
+     */
366
+    public function get_custom_name( $context = 'view' ) {
367 367
         return $this->get_prop( 'custom_name', $context );
368 368
     }
369 369
 
370 370
     /**
371
-	 * Get the custom singular name of the item.
372
-	 *
373
-	 * @since 1.0.19
374
-	 * @param  string $context View or edit context.
375
-	 * @return string
376
-	 */
377
-	public function get_custom_singular_name( $context = 'view' ) {
371
+     * Get the custom singular name of the item.
372
+     *
373
+     * @since 1.0.19
374
+     * @param  string $context View or edit context.
375
+     * @return string
376
+     */
377
+    public function get_custom_singular_name( $context = 'view' ) {
378 378
         return $this->get_prop( 'custom_singular_name', $context );
379 379
     }
380 380
 
381 381
     /**
382
-	 * Checks if an item is editable..
383
-	 *
384
-	 * @since 1.0.19
385
-	 * @param  string $context View or edit context.
386
-	 * @return int
387
-	 */
388
-	public function get_is_editable( $context = 'view' ) {
382
+     * Checks if an item is editable..
383
+     *
384
+     * @since 1.0.19
385
+     * @param  string $context View or edit context.
386
+     * @return int
387
+     */
388
+    public function get_is_editable( $context = 'view' ) {
389 389
         return (int) $this->get_prop( 'is_editable', $context );
390 390
     }
391 391
 
392 392
     /**
393
-	 * Alias of self::get_is_editable().
394
-	 *
395
-	 * @since 1.0.19
396
-	 * @param  string $context View or edit context.
397
-	 * @return int
398
-	 */
399
-	public function get_editable( $context = 'view' ) {
400
-		return $this->get_is_editable( $context );
393
+     * Alias of self::get_is_editable().
394
+     *
395
+     * @since 1.0.19
396
+     * @param  string $context View or edit context.
397
+     * @return int
398
+     */
399
+    public function get_editable( $context = 'view' ) {
400
+        return $this->get_is_editable( $context );
401 401
     }
402 402
 
403 403
     /**
404
-	 * Checks if dynamic pricing is enabled.
405
-	 *
406
-	 * @since 1.0.19
407
-	 * @param  string $context View or edit context.
408
-	 * @return int
409
-	 */
410
-	public function get_is_dynamic_pricing( $context = 'view' ) {
404
+     * Checks if dynamic pricing is enabled.
405
+     *
406
+     * @since 1.0.19
407
+     * @param  string $context View or edit context.
408
+     * @return int
409
+     */
410
+    public function get_is_dynamic_pricing( $context = 'view' ) {
411 411
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
412 412
     }
413 413
 
414 414
     /**
415
-	 * Returns the minimum price if dynamic pricing is enabled.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return float
420
-	 */
421
-	public function get_minimum_price( $context = 'view' ) {
415
+     * Returns the minimum price if dynamic pricing is enabled.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return float
420
+     */
421
+    public function get_minimum_price( $context = 'view' ) {
422 422
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
423 423
     }
424 424
 
425 425
     /**
426
-	 * Checks if this is a recurring item.
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return int
431
-	 */
432
-	public function get_is_recurring( $context = 'view' ) {
426
+     * Checks if this is a recurring item.
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return int
431
+     */
432
+    public function get_is_recurring( $context = 'view' ) {
433 433
         return (int) $this->get_prop( 'is_recurring', $context );
434
-	}
434
+    }
435 435
 	
436
-	/**
437
-	 * Get the recurring price of the item.
438
-	 *
439
-	 * @since 1.0.19
440
-	 * @param  string $context View or edit context.
441
-	 * @return float
442
-	 */
443
-	public function get_recurring_price( $context = 'view' ) {
444
-		$price = $this->get_price( $context );
436
+    /**
437
+     * Get the recurring price of the item.
438
+     *
439
+     * @since 1.0.19
440
+     * @param  string $context View or edit context.
441
+     * @return float
442
+     */
443
+    public function get_recurring_price( $context = 'view' ) {
444
+        $price = $this->get_price( $context );
445 445
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
446
-	}
447
-
448
-	/**
449
-	 * Get the first renewal date (in timestamps) of the item.
450
-	 *
451
-	 * @since 1.0.19
452
-	 * @return int
453
-	 */
454
-	public function get_first_renewal_date() {
455
-
456
-		$periods = array(
457
-			'D' => 'days',
458
-			'W' => 'weeks',
459
-			'M' => 'months',
460
-			'Y' => 'years',
461
-		);
462
-
463
-		$period   = $this->get_recurring_period();
464
-		$interval = $this->get_recurring_interval();
465
-
466
-		if ( $this->has_free_trial() ) {
467
-			$period   = $this->get_trial_period();
468
-			$interval = $this->get_trial_interval();
469
-		}
470
-
471
-		$period       = $periods[ $period ];
472
-		$interval     = empty( $interval ) ? 1 : $interval;
473
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
446
+    }
447
+
448
+    /**
449
+     * Get the first renewal date (in timestamps) of the item.
450
+     *
451
+     * @since 1.0.19
452
+     * @return int
453
+     */
454
+    public function get_first_renewal_date() {
455
+
456
+        $periods = array(
457
+            'D' => 'days',
458
+            'W' => 'weeks',
459
+            'M' => 'months',
460
+            'Y' => 'years',
461
+        );
462
+
463
+        $period   = $this->get_recurring_period();
464
+        $interval = $this->get_recurring_interval();
465
+
466
+        if ( $this->has_free_trial() ) {
467
+            $period   = $this->get_trial_period();
468
+            $interval = $this->get_trial_interval();
469
+        }
470
+
471
+        $period       = $periods[ $period ];
472
+        $interval     = empty( $interval ) ? 1 : $interval;
473
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
474 474
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
475 475
     }
476 476
 
477 477
     /**
478
-	 * Get the recurring period.
479
-	 *
480
-	 * @since 1.0.19
481
-	 * @param  bool $full Return abbreviation or in full.
482
-	 * @return string
483
-	 */
484
-	public function get_recurring_period( $full = false ) {
478
+     * Get the recurring period.
479
+     *
480
+     * @since 1.0.19
481
+     * @param  bool $full Return abbreviation or in full.
482
+     * @return string
483
+     */
484
+    public function get_recurring_period( $full = false ) {
485 485
         $period = $this->get_prop( 'recurring_period', 'view' );
486 486
 
487 487
         if ( $full && ! is_bool( $full ) ) {
@@ -492,63 +492,63 @@  discard block
 block discarded – undo
492 492
     }
493 493
 
494 494
     /**
495
-	 * Get the recurring interval.
496
-	 *
497
-	 * @since 1.0.19
498
-	 * @param  string $context View or edit context.
499
-	 * @return int
500
-	 */
501
-	public function get_recurring_interval( $context = 'view' ) {
502
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
495
+     * Get the recurring interval.
496
+     *
497
+     * @since 1.0.19
498
+     * @param  string $context View or edit context.
499
+     * @return int
500
+     */
501
+    public function get_recurring_interval( $context = 'view' ) {
502
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
503 503
 
504
-		if ( $interval < 1 ) {
505
-			$interval = 1;
506
-		}
504
+        if ( $interval < 1 ) {
505
+            $interval = 1;
506
+        }
507 507
 
508 508
         return $interval;
509 509
     }
510 510
 
511 511
     /**
512
-	 * Get the recurring limit.
513
-	 *
514
-	 * @since 1.0.19
515
-	 * @param  string $context View or edit context.
516
-	 * @return int
517
-	 */
518
-	public function get_recurring_limit( $context = 'view' ) {
512
+     * Get the recurring limit.
513
+     *
514
+     * @since 1.0.19
515
+     * @param  string $context View or edit context.
516
+     * @return int
517
+     */
518
+    public function get_recurring_limit( $context = 'view' ) {
519 519
         return (int) $this->get_prop( 'recurring_limit', $context );
520 520
     }
521 521
 
522 522
     /**
523
-	 * Checks if we have a free trial.
524
-	 *
525
-	 * @since 1.0.19
526
-	 * @param  string $context View or edit context.
527
-	 * @return int
528
-	 */
529
-	public function get_is_free_trial( $context = 'view' ) {
523
+     * Checks if we have a free trial.
524
+     *
525
+     * @since 1.0.19
526
+     * @param  string $context View or edit context.
527
+     * @return int
528
+     */
529
+    public function get_is_free_trial( $context = 'view' ) {
530 530
         return (int) $this->get_prop( 'is_free_trial', $context );
531 531
     }
532 532
 
533 533
     /**
534
-	 * Alias for self::get_is_free_trial().
535
-	 *
536
-	 * @since 1.0.19
537
-	 * @param  string $context View or edit context.
538
-	 * @return int
539
-	 */
540
-	public function get_free_trial( $context = 'view' ) {
534
+     * Alias for self::get_is_free_trial().
535
+     *
536
+     * @since 1.0.19
537
+     * @param  string $context View or edit context.
538
+     * @return int
539
+     */
540
+    public function get_free_trial( $context = 'view' ) {
541 541
         return $this->get_is_free_trial( $context );
542 542
     }
543 543
 
544 544
     /**
545
-	 * Get the trial period.
546
-	 *
547
-	 * @since 1.0.19
548
-	 * @param  bool $full Return abbreviation or in full.
549
-	 * @return string
550
-	 */
551
-	public function get_trial_period( $full = false ) {
545
+     * Get the trial period.
546
+     *
547
+     * @since 1.0.19
548
+     * @param  bool $full Return abbreviation or in full.
549
+     * @return string
550
+     */
551
+    public function get_trial_period( $full = false ) {
552 552
         $period = $this->get_prop( 'trial_period', 'view' );
553 553
 
554 554
         if ( $full && ! is_bool( $full ) ) {
@@ -559,13 +559,13 @@  discard block
 block discarded – undo
559 559
     }
560 560
 
561 561
     /**
562
-	 * Get the trial interval.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param  string $context View or edit context.
566
-	 * @return int
567
-	 */
568
-	public function get_trial_interval( $context = 'view' ) {
562
+     * Get the trial interval.
563
+     *
564
+     * @since 1.0.19
565
+     * @param  string $context View or edit context.
566
+     * @return int
567
+     */
568
+    public function get_trial_interval( $context = 'view' ) {
569 569
         return (int) $this->get_prop( 'trial_interval', $context );
570 570
     }
571 571
 
@@ -599,52 +599,52 @@  discard block
 block discarded – undo
599 599
     */
600 600
 
601 601
     /**
602
-	 * Set parent order ID.
603
-	 *
604
-	 * @since 1.0.19
605
-	 */
606
-	public function set_parent_id( $value ) {
607
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
608
-			return;
609
-		}
610
-		$this->set_prop( 'parent_id', absint( $value ) );
611
-	}
612
-
613
-    /**
614
-	 * Sets item status.
615
-	 *
616
-	 * @since 1.0.19
617
-	 * @param  string $status New status.
618
-	 * @return array details of change.
619
-	 */
620
-	public function set_status( $status ) {
602
+     * Set parent order ID.
603
+     *
604
+     * @since 1.0.19
605
+     */
606
+    public function set_parent_id( $value ) {
607
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
608
+            return;
609
+        }
610
+        $this->set_prop( 'parent_id', absint( $value ) );
611
+    }
612
+
613
+    /**
614
+     * Sets item status.
615
+     *
616
+     * @since 1.0.19
617
+     * @param  string $status New status.
618
+     * @return array details of change.
619
+     */
620
+    public function set_status( $status ) {
621 621
         $old_status = $this->get_status();
622 622
 
623 623
         $this->set_prop( 'status', $status );
624 624
 
625
-		return array(
626
-			'from' => $old_status,
627
-			'to'   => $status,
628
-		);
625
+        return array(
626
+            'from' => $old_status,
627
+            'to'   => $status,
628
+        );
629 629
     }
630 630
 
631 631
     /**
632
-	 * Set plugin version when the item was created.
633
-	 *
634
-	 * @since 1.0.19
635
-	 */
636
-	public function set_version( $value ) {
637
-		$this->set_prop( 'version', $value );
632
+     * Set plugin version when the item was created.
633
+     *
634
+     * @since 1.0.19
635
+     */
636
+    public function set_version( $value ) {
637
+        $this->set_prop( 'version', $value );
638 638
     }
639 639
 
640 640
     /**
641
-	 * Set date when the item was created.
642
-	 *
643
-	 * @since 1.0.19
644
-	 * @param string $value Value to set.
641
+     * Set date when the item was created.
642
+     *
643
+     * @since 1.0.19
644
+     * @param string $value Value to set.
645 645
      * @return bool Whether or not the date was set.
646
-	 */
647
-	public function set_date_created( $value ) {
646
+     */
647
+    public function set_date_created( $value ) {
648 648
         $date = strtotime( $value );
649 649
 
650 650
         if ( $date ) {
@@ -657,13 +657,13 @@  discard block
 block discarded – undo
657 657
     }
658 658
 
659 659
     /**
660
-	 * Set date when the item was last modified.
661
-	 *
662
-	 * @since 1.0.19
663
-	 * @param string $value Value to set.
660
+     * Set date when the item was last modified.
661
+     *
662
+     * @since 1.0.19
663
+     * @param string $value Value to set.
664 664
      * @return bool Whether or not the date was set.
665
-	 */
666
-	public function set_date_modified( $value ) {
665
+     */
666
+    public function set_date_modified( $value ) {
667 667
         $date = strtotime( $value );
668 668
 
669 669
         if ( $date ) {
@@ -676,105 +676,105 @@  discard block
 block discarded – undo
676 676
     }
677 677
 
678 678
     /**
679
-	 * Set the item name.
680
-	 *
681
-	 * @since 1.0.19
682
-	 * @param  string $value New name.
683
-	 */
684
-	public function set_name( $value ) {
679
+     * Set the item name.
680
+     *
681
+     * @since 1.0.19
682
+     * @param  string $value New name.
683
+     */
684
+    public function set_name( $value ) {
685 685
         $name = sanitize_text_field( $value );
686
-		$this->set_prop( 'name', $name );
686
+        $this->set_prop( 'name', $name );
687 687
     }
688 688
 
689 689
     /**
690
-	 * Alias of self::set_name().
691
-	 *
692
-	 * @since 1.0.19
693
-	 * @param  string $value New name.
694
-	 */
695
-	public function set_title( $value ) {
696
-		$this->set_name( $value );
690
+     * Alias of self::set_name().
691
+     *
692
+     * @since 1.0.19
693
+     * @param  string $value New name.
694
+     */
695
+    public function set_title( $value ) {
696
+        $this->set_name( $value );
697 697
     }
698 698
 
699 699
     /**
700
-	 * Set the item description.
701
-	 *
702
-	 * @since 1.0.19
703
-	 * @param  string $value New description.
704
-	 */
705
-	public function set_description( $value ) {
700
+     * Set the item description.
701
+     *
702
+     * @since 1.0.19
703
+     * @param  string $value New description.
704
+     */
705
+    public function set_description( $value ) {
706 706
         $description = wp_kses_post( $value );
707
-		return $this->set_prop( 'description', $description );
707
+        return $this->set_prop( 'description', $description );
708 708
     }
709 709
 
710 710
     /**
711
-	 * Alias of self::set_description().
712
-	 *
713
-	 * @since 1.0.19
714
-	 * @param  string $value New description.
715
-	 */
716
-	public function set_excerpt( $value ) {
717
-		$this->set_description( $value );
711
+     * Alias of self::set_description().
712
+     *
713
+     * @since 1.0.19
714
+     * @param  string $value New description.
715
+     */
716
+    public function set_excerpt( $value ) {
717
+        $this->set_description( $value );
718 718
     }
719 719
 
720 720
     /**
721
-	 * Alias of self::set_description().
722
-	 *
723
-	 * @since 1.0.19
724
-	 * @param  string $value New description.
725
-	 */
726
-	public function set_summary( $value ) {
727
-		$this->set_description( $value );
721
+     * Alias of self::set_description().
722
+     *
723
+     * @since 1.0.19
724
+     * @param  string $value New description.
725
+     */
726
+    public function set_summary( $value ) {
727
+        $this->set_description( $value );
728 728
     }
729 729
 
730 730
     /**
731
-	 * Set the owner of the item.
732
-	 *
733
-	 * @since 1.0.19
734
-	 * @param  int $value New author.
735
-	 */
736
-	public function set_author( $value ) {
737
-		$this->set_prop( 'author', (int) $value );
731
+     * Set the owner of the item.
732
+     *
733
+     * @since 1.0.19
734
+     * @param  int $value New author.
735
+     */
736
+    public function set_author( $value ) {
737
+        $this->set_prop( 'author', (int) $value );
738 738
     }
739 739
 
740 740
     /**
741
-	 * Set the price of the item.
742
-	 *
743
-	 * @since 1.0.19
744
-	 * @param  float $value New price.
745
-	 */
746
-	public function set_price( $value ) {
741
+     * Set the price of the item.
742
+     *
743
+     * @since 1.0.19
744
+     * @param  float $value New price.
745
+     */
746
+    public function set_price( $value ) {
747 747
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
748 748
     }
749 749
 
750 750
     /**
751
-	 * Set the VAT rule of the item.
752
-	 *
753
-	 * @since 1.0.19
754
-	 * @param  string $value new rule.
755
-	 */
756
-	public function set_vat_rule( $value ) {
751
+     * Set the VAT rule of the item.
752
+     *
753
+     * @since 1.0.19
754
+     * @param  string $value new rule.
755
+     */
756
+    public function set_vat_rule( $value ) {
757 757
         $this->set_prop( 'vat_rule', $value );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Set the VAT class of the item.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param  string $value new class.
765
-	 */
766
-	public function set_vat_class( $value ) {
761
+     * Set the VAT class of the item.
762
+     *
763
+     * @since 1.0.19
764
+     * @param  string $value new class.
765
+     */
766
+    public function set_vat_class( $value ) {
767 767
         $this->set_prop( 'vat_class', $value );
768 768
     }
769 769
 
770 770
     /**
771
-	 * Set the type of the item.
772
-	 *
773
-	 * @since 1.0.19
774
-	 * @param  string $value new item type.
775
-	 * @return string
776
-	 */
777
-	public function set_type( $value ) {
771
+     * Set the type of the item.
772
+     *
773
+     * @since 1.0.19
774
+     * @param  string $value new item type.
775
+     * @return string
776
+     */
777
+    public function set_type( $value ) {
778 778
 
779 779
         if ( empty( $value ) ) {
780 780
             $value = 'custom';
@@ -784,134 +784,134 @@  discard block
 block discarded – undo
784 784
     }
785 785
 
786 786
     /**
787
-	 * Set the custom id of the item.
788
-	 *
789
-	 * @since 1.0.19
790
-	 * @param  string $value new custom id.
791
-	 */
792
-	public function set_custom_id( $value ) {
787
+     * Set the custom id of the item.
788
+     *
789
+     * @since 1.0.19
790
+     * @param  string $value new custom id.
791
+     */
792
+    public function set_custom_id( $value ) {
793 793
         $this->set_prop( 'custom_id', $value );
794 794
     }
795 795
 
796 796
     /**
797
-	 * Set the custom name of the item.
798
-	 *
799
-	 * @since 1.0.19
800
-	 * @param  string $value new custom name.
801
-	 */
802
-	public function set_custom_name( $value ) {
797
+     * Set the custom name of the item.
798
+     *
799
+     * @since 1.0.19
800
+     * @param  string $value new custom name.
801
+     */
802
+    public function set_custom_name( $value ) {
803 803
         $this->set_prop( 'custom_name', $value );
804 804
     }
805 805
 
806 806
     /**
807
-	 * Set the custom singular name of the item.
808
-	 *
809
-	 * @since 1.0.19
810
-	 * @param  string $value new custom singular name.
811
-	 */
812
-	public function set_custom_singular_name( $value ) {
807
+     * Set the custom singular name of the item.
808
+     *
809
+     * @since 1.0.19
810
+     * @param  string $value new custom singular name.
811
+     */
812
+    public function set_custom_singular_name( $value ) {
813 813
         $this->set_prop( 'custom_singular_name', $value );
814 814
     }
815 815
 
816 816
     /**
817
-	 * Sets if an item is editable..
818
-	 *
819
-	 * @since 1.0.19
820
-	 * @param  int|bool $value whether or not the item is editable.
821
-	 */
822
-	public function set_is_editable( $value ) {
823
-		if ( is_numeric( $value ) ) {
824
-			$this->set_prop( 'is_editable', (int) $value );
825
-		}
817
+     * Sets if an item is editable..
818
+     *
819
+     * @since 1.0.19
820
+     * @param  int|bool $value whether or not the item is editable.
821
+     */
822
+    public function set_is_editable( $value ) {
823
+        if ( is_numeric( $value ) ) {
824
+            $this->set_prop( 'is_editable', (int) $value );
825
+        }
826 826
     }
827 827
 
828 828
     /**
829
-	 * Sets if dynamic pricing is enabled.
830
-	 *
831
-	 * @since 1.0.19
832
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
833
-	 */
834
-	public function set_is_dynamic_pricing( $value ) {
829
+     * Sets if dynamic pricing is enabled.
830
+     *
831
+     * @since 1.0.19
832
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
833
+     */
834
+    public function set_is_dynamic_pricing( $value ) {
835 835
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
836 836
     }
837 837
 
838 838
     /**
839
-	 * Sets the minimum price if dynamic pricing is enabled.
840
-	 *
841
-	 * @since 1.0.19
842
-	 * @param  float $value minimum price.
843
-	 */
844
-	public function set_minimum_price( $value ) {
839
+     * Sets the minimum price if dynamic pricing is enabled.
840
+     *
841
+     * @since 1.0.19
842
+     * @param  float $value minimum price.
843
+     */
844
+    public function set_minimum_price( $value ) {
845 845
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
846 846
     }
847 847
 
848 848
     /**
849
-	 * Sets if this is a recurring item.
850
-	 *
851
-	 * @since 1.0.19
852
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
853
-	 */
854
-	public function set_is_recurring( $value ) {
849
+     * Sets if this is a recurring item.
850
+     *
851
+     * @since 1.0.19
852
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
853
+     */
854
+    public function set_is_recurring( $value ) {
855 855
         $this->set_prop( 'is_recurring', (int) $value );
856 856
     }
857 857
 
858 858
     /**
859
-	 * Set the recurring period.
860
-	 *
861
-	 * @since 1.0.19
862
-	 * @param  string $value new period.
863
-	 */
864
-	public function set_recurring_period( $value ) {
859
+     * Set the recurring period.
860
+     *
861
+     * @since 1.0.19
862
+     * @param  string $value new period.
863
+     */
864
+    public function set_recurring_period( $value ) {
865 865
         $this->set_prop( 'recurring_period', $value );
866 866
     }
867 867
 
868 868
     /**
869
-	 * Set the recurring interval.
870
-	 *
871
-	 * @since 1.0.19
872
-	 * @param  int $value recurring interval.
873
-	 */
874
-	public function set_recurring_interval( $value ) {
869
+     * Set the recurring interval.
870
+     *
871
+     * @since 1.0.19
872
+     * @param  int $value recurring interval.
873
+     */
874
+    public function set_recurring_interval( $value ) {
875 875
         return $this->set_prop( 'recurring_interval', (int) $value );
876 876
     }
877 877
 
878 878
     /**
879
-	 * Get the recurring limit.
880
-	 * @since 1.0.19
881
-	 * @param  int $value The recurring limit.
882
-	 * @return int
883
-	 */
884
-	public function set_recurring_limit( $value ) {
879
+     * Get the recurring limit.
880
+     * @since 1.0.19
881
+     * @param  int $value The recurring limit.
882
+     * @return int
883
+     */
884
+    public function set_recurring_limit( $value ) {
885 885
         $this->set_prop( 'recurring_limit', (int) $value );
886 886
     }
887 887
 
888 888
     /**
889
-	 * Checks if we have a free trial.
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @param  int|bool $value whether or not it has a free trial.
893
-	 */
894
-	public function set_is_free_trial( $value ) {
889
+     * Checks if we have a free trial.
890
+     *
891
+     * @since 1.0.19
892
+     * @param  int|bool $value whether or not it has a free trial.
893
+     */
894
+    public function set_is_free_trial( $value ) {
895 895
         $this->set_prop( 'is_free_trial', (int) $value );
896 896
     }
897 897
 
898 898
     /**
899
-	 * Set the trial period.
900
-	 *
901
-	 * @since 1.0.19
902
-	 * @param  string $value trial period.
903
-	 */
904
-	public function set_trial_period( $value ) {
899
+     * Set the trial period.
900
+     *
901
+     * @since 1.0.19
902
+     * @param  string $value trial period.
903
+     */
904
+    public function set_trial_period( $value ) {
905 905
         $this->set_prop( 'trial_period', $value );
906 906
     }
907 907
 
908 908
     /**
909
-	 * Set the trial interval.
910
-	 *
911
-	 * @since 1.0.19
912
-	 * @param  int $value trial interval.
913
-	 */
914
-	public function set_trial_interval( $value ) {
909
+     * Set the trial interval.
910
+     *
911
+     * @since 1.0.19
912
+     * @param  int $value trial interval.
913
+     */
914
+    public function set_trial_interval( $value ) {
915 915
         $this->set_prop( 'trial_interval', $value );
916 916
     }
917 917
 
@@ -919,17 +919,17 @@  discard block
 block discarded – undo
919 919
      * Create an item. For backwards compatibilty.
920 920
      * 
921 921
      * @deprecated
922
-	 * @return int item id
922
+     * @return int item id
923 923
      */
924 924
     public function create( $data = array() ) {
925 925
 
926
-		// Set the properties.
927
-		if ( is_array( $data ) ) {
928
-			$this->set_props( $data );
929
-		}
926
+        // Set the properties.
927
+        if ( is_array( $data ) ) {
928
+            $this->set_props( $data );
929
+        }
930 930
 
931
-		// Save the item.
932
-		return $this->save();
931
+        // Save the item.
932
+        return $this->save();
933 933
 
934 934
     }
935 935
 
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
      * Updates an item. For backwards compatibilty.
938 938
      * 
939 939
      * @deprecated
940
-	 * @return int item id
940
+     * @return int item id
941 941
      */
942 942
     public function update( $data = array() ) {
943 943
         return $this->create( $data );
@@ -953,84 +953,84 @@  discard block
 block discarded – undo
953 953
 	*/
954 954
 
955 955
     /**
956
-	 * Checks whether the item has enabled dynamic pricing.
957
-	 *
958
-	 * @since 1.0.19
959
-	 * @return bool
960
-	 */
961
-	public function user_can_set_their_price() {
956
+     * Checks whether the item has enabled dynamic pricing.
957
+     *
958
+     * @since 1.0.19
959
+     * @return bool
960
+     */
961
+    public function user_can_set_their_price() {
962 962
         return (bool) $this->get_is_dynamic_pricing();
963
-	}
963
+    }
964 964
 	
965
-	/**
966
-	 * Checks whether the item is recurring.
967
-	 *
968
-	 * @since 1.0.19
969
-	 * @return bool
970
-	 */
971
-	public function is_recurring() {
965
+    /**
966
+     * Checks whether the item is recurring.
967
+     *
968
+     * @since 1.0.19
969
+     * @return bool
970
+     */
971
+    public function is_recurring() {
972 972
         return (bool) $this->get_is_recurring();
973 973
     }
974 974
 
975 975
     /**
976
-	 * Checks whether the item has a free trial.
977
-	 *
978
-	 * @since 1.0.19
979
-	 * @return bool
980
-	 */
976
+     * Checks whether the item has a free trial.
977
+     *
978
+     * @since 1.0.19
979
+     * @return bool
980
+     */
981 981
     public function has_free_trial() {
982 982
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
983 983
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
984 984
     }
985 985
 
986 986
     /**
987
-	 * Checks whether the item is free.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @return bool
991
-	 */
987
+     * Checks whether the item is free.
988
+     *
989
+     * @since 1.0.19
990
+     * @return bool
991
+     */
992 992
     public function is_free() {
993 993
         $is_free   = $this->get_price() == 0;
994 994
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
995 995
     }
996 996
 
997 997
     /**
998
-	 * Checks the item status against a passed in status.
999
-	 *
1000
-	 * @param array|string $status Status to check.
1001
-	 * @return bool
1002
-	 */
1003
-	public function has_status( $status ) {
1004
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1005
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
998
+     * Checks the item status against a passed in status.
999
+     *
1000
+     * @param array|string $status Status to check.
1001
+     * @return bool
1002
+     */
1003
+    public function has_status( $status ) {
1004
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1005
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1006 1006
     }
1007 1007
 
1008 1008
     /**
1009
-	 * Checks the item type against a passed in types.
1010
-	 *
1011
-	 * @param array|string $type Type to check.
1012
-	 * @return bool
1013
-	 */
1014
-	public function is_type( $type ) {
1015
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1016
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1017
-	}
1009
+     * Checks the item type against a passed in types.
1010
+     *
1011
+     * @param array|string $type Type to check.
1012
+     * @return bool
1013
+     */
1014
+    public function is_type( $type ) {
1015
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1016
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1017
+    }
1018 1018
 
1019 1019
     /**
1020
-	 * Checks whether the item is editable.
1021
-	 *
1022
-	 * @since 1.0.19
1023
-	 * @return bool
1024
-	 */
1020
+     * Checks whether the item is editable.
1021
+     *
1022
+     * @since 1.0.19
1023
+     * @return bool
1024
+     */
1025 1025
     public function is_editable() {
1026 1026
         $is_editable = $this->get_is_editable();
1027 1027
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1028
-	}
1028
+    }
1029 1029
 
1030
-	/**
1031
-	 * Returns an array of cart fees.
1032
-	 */
1033
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1030
+    /**
1031
+     * Returns an array of cart fees.
1032
+     */
1033
+    public function get_fees( $type = 'fee', $item_id = 0 ) {
1034 1034
         global $wpi_session;
1035 1035
         
1036 1036
         $fees = $wpi_session->get( 'wpi_cart_fees' );
@@ -1074,11 +1074,11 @@  discard block
 block discarded – undo
1074 1074
     }
1075 1075
 
1076 1076
     /**
1077
-	 * Checks whether the item is purchasable.
1078
-	 *
1079
-	 * @since 1.0.19
1080
-	 * @return bool
1081
-	 */
1077
+     * Checks whether the item is purchasable.
1078
+     *
1079
+     * @since 1.0.19
1080
+     * @return bool
1081
+     */
1082 1082
     public function can_purchase() {
1083 1083
         $can_purchase = null !== $this->get_id();
1084 1084
 
@@ -1090,11 +1090,11 @@  discard block
 block discarded – undo
1090 1090
     }
1091 1091
 
1092 1092
     /**
1093
-	 * Checks whether the item supports dynamic pricing.
1094
-	 *
1095
-	 * @since 1.0.19
1096
-	 * @return bool
1097
-	 */
1093
+     * Checks whether the item supports dynamic pricing.
1094
+     *
1095
+     * @since 1.0.19
1096
+     * @return bool
1097
+     */
1098 1098
     public function supports_dynamic_pricing() {
1099 1099
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1100 1100
     }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +911 added lines, -911 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		try {
141
-			$this->__construct( absint( $this->id ) );
142
-		} catch ( Exception $e ) {
143
-			$this->set_id( 0 );
144
-			$this->set_object_read( true );
145
-		}
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        try {
141
+            $this->__construct( absint( $this->id ) );
142
+        } catch ( Exception $e ) {
143
+            $this->set_id( 0 );
144
+            $this->set_object_read( true );
145
+        }
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			/* translators: %s: $key Key to set */
382
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
381
+            /* translators: %s: $key Key to set */
382
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
383 383
 
384 384
             return call_user_func( array( $this, 'get_' . $key ) );
385 385
         }
@@ -389,564 +389,564 @@  discard block
 block discarded – undo
389 389
             return $this->post->$key;
390 390
         }
391 391
 
392
-		return $this->get_prop( $key );
393
-
394
-    }
395
-
396
-	/**
397
-	 * Get Meta Data by Key.
398
-	 *
399
-	 * @since  1.0.19
400
-	 * @param  string $key Meta Key.
401
-	 * @param  bool   $single return first found meta with key, or all with $key.
402
-	 * @param  string $context What the value is for. Valid values are view and edit.
403
-	 * @return mixed
404
-	 */
405
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
406
-
407
-		// Check if this is an internal meta key.
408
-		if ( $this->is_internal_meta_key( $key ) ) {
409
-			$function = 'get_' . $key;
410
-
411
-			if ( is_callable( array( $this, $function ) ) ) {
412
-				return $this->{$function}();
413
-			}
414
-		}
415
-
416
-		// Read the meta data if not yet read.
417
-		$this->maybe_read_meta_data();
418
-		$meta_data  = $this->get_meta_data();
419
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
420
-		$value      = $single ? '' : array();
421
-
422
-		if ( ! empty( $array_keys ) ) {
423
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
424
-			if ( $single ) {
425
-				$value = $meta_data[ current( $array_keys ) ]->value;
426
-			} else {
427
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
428
-			}
429
-		}
430
-
431
-		if ( 'view' === $context ) {
432
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
433
-		}
434
-
435
-		return $value;
436
-	}
437
-
438
-	/**
439
-	 * See if meta data exists, since get_meta always returns a '' or array().
440
-	 *
441
-	 * @since  1.0.19
442
-	 * @param  string $key Meta Key.
443
-	 * @return boolean
444
-	 */
445
-	public function meta_exists( $key = '' ) {
446
-		$this->maybe_read_meta_data();
447
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
448
-		return in_array( $key, $array_keys, true );
449
-	}
450
-
451
-	/**
452
-	 * Set all meta data from array.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param array $data Key/Value pairs.
456
-	 */
457
-	public function set_meta_data( $data ) {
458
-		if ( ! empty( $data ) && is_array( $data ) ) {
459
-			$this->maybe_read_meta_data();
460
-			foreach ( $data as $meta ) {
461
-				$meta = (array) $meta;
462
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
463
-					$this->meta_data[] = new GetPaid_Meta_Data(
464
-						array(
465
-							'id'    => $meta['id'],
466
-							'key'   => $meta['key'],
467
-							'value' => $meta['value'],
468
-						)
469
-					);
470
-				}
471
-			}
472
-		}
473
-	}
474
-
475
-	/**
476
-	 * Add meta data.
477
-	 *
478
-	 * @since 1.0.19
479
-	 *
480
-	 * @param string       $key Meta key.
481
-	 * @param string|array $value Meta value.
482
-	 * @param bool         $unique Should this be a unique key?.
483
-	 */
484
-	public function add_meta_data( $key, $value, $unique = false ) {
485
-		if ( $this->is_internal_meta_key( $key ) ) {
486
-			$function = 'set_' . $key;
487
-
488
-			if ( is_callable( array( $this, $function ) ) ) {
489
-				return $this->{$function}( $value );
490
-			}
491
-		}
492
-
493
-		$this->maybe_read_meta_data();
494
-		if ( $unique ) {
495
-			$this->delete_meta_data( $key );
496
-		}
497
-		$this->meta_data[] = new GetPaid_Meta_Data(
498
-			array(
499
-				'key'   => $key,
500
-				'value' => $value,
501
-			)
502
-		);
503
-	}
504
-
505
-	/**
506
-	 * Update meta data by key or ID, if provided.
507
-	 *
508
-	 * @since  1.0.19
509
-	 *
510
-	 * @param  string       $key Meta key.
511
-	 * @param  string|array $value Meta value.
512
-	 * @param  int          $meta_id Meta ID.
513
-	 */
514
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
515
-		if ( $this->is_internal_meta_key( $key ) ) {
516
-			$function = 'set_' . $key;
517
-
518
-			if ( is_callable( array( $this, $function ) ) ) {
519
-				return $this->{$function}( $value );
520
-			}
521
-		}
522
-
523
-		$this->maybe_read_meta_data();
524
-
525
-		$array_key = false;
526
-
527
-		if ( $meta_id ) {
528
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
529
-			$array_key  = $array_keys ? current( $array_keys ) : false;
530
-		} else {
531
-			// Find matches by key.
532
-			$matches = array();
533
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
534
-				if ( $meta->key === $key ) {
535
-					$matches[] = $meta_data_array_key;
536
-				}
537
-			}
538
-
539
-			if ( ! empty( $matches ) ) {
540
-				// Set matches to null so only one key gets the new value.
541
-				foreach ( $matches as $meta_data_array_key ) {
542
-					$this->meta_data[ $meta_data_array_key ]->value = null;
543
-				}
544
-				$array_key = current( $matches );
545
-			}
546
-		}
547
-
548
-		if ( false !== $array_key ) {
549
-			$meta        = $this->meta_data[ $array_key ];
550
-			$meta->key   = $key;
551
-			$meta->value = $value;
552
-		} else {
553
-			$this->add_meta_data( $key, $value, true );
554
-		}
555
-	}
556
-
557
-	/**
558
-	 * Delete meta data.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @param string $key Meta key.
562
-	 */
563
-	public function delete_meta_data( $key ) {
564
-		$this->maybe_read_meta_data();
565
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
566
-
567
-		if ( $array_keys ) {
568
-			foreach ( $array_keys as $array_key ) {
569
-				$this->meta_data[ $array_key ]->value = null;
570
-			}
571
-		}
572
-	}
573
-
574
-	/**
575
-	 * Delete meta data.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param int $mid Meta ID.
579
-	 */
580
-	public function delete_meta_data_by_mid( $mid ) {
581
-		$this->maybe_read_meta_data();
582
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
583
-
584
-		if ( $array_keys ) {
585
-			foreach ( $array_keys as $array_key ) {
586
-				$this->meta_data[ $array_key ]->value = null;
587
-			}
588
-		}
589
-	}
590
-
591
-	/**
592
-	 * Read meta data if null.
593
-	 *
594
-	 * @since 1.0.19
595
-	 */
596
-	protected function maybe_read_meta_data() {
597
-		if ( is_null( $this->meta_data ) ) {
598
-			$this->read_meta_data();
599
-		}
600
-	}
601
-
602
-	/**
603
-	 * Read Meta Data from the database. Ignore any internal properties.
604
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param bool $force_read True to force a new DB read (and update cache).
608
-	 */
609
-	public function read_meta_data( $force_read = false ) {
610
-		$this->meta_data = array();
611
-		$cache_loaded    = false;
612
-
613
-		if ( ! $this->get_id() ) {
614
-			return;
615
-		}
616
-
617
-		if ( ! $this->data_store ) {
618
-			return;
619
-		}
620
-
621
-		if ( ! empty( $this->cache_group ) ) {
622
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
623
-		}
624
-
625
-		if ( ! $force_read ) {
626
-			if ( ! empty( $this->cache_group ) ) {
627
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
628
-				$cache_loaded = ! empty( $cached_meta );
629
-			}
630
-		}
631
-
632
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
633
-		if ( $raw_meta_data ) {
634
-			foreach ( $raw_meta_data as $meta ) {
635
-				$this->meta_data[] = new GetPaid_Meta_Data(
636
-					array(
637
-						'id'    => (int) $meta->meta_id,
638
-						'key'   => $meta->meta_key,
639
-						'value' => maybe_unserialize( $meta->meta_value ),
640
-					)
641
-				);
642
-			}
643
-
644
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
645
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
646
-			}
647
-		}
648
-	}
649
-
650
-	/**
651
-	 * Update Meta Data in the database.
652
-	 *
653
-	 * @since 1.0.19
654
-	 */
655
-	public function save_meta_data() {
656
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
657
-			return;
658
-		}
659
-		foreach ( $this->meta_data as $array_key => $meta ) {
660
-			if ( is_null( $meta->value ) ) {
661
-				if ( ! empty( $meta->id ) ) {
662
-					$this->data_store->delete_meta( $this, $meta );
663
-					unset( $this->meta_data[ $array_key ] );
664
-				}
665
-			} elseif ( empty( $meta->id ) ) {
666
-				$meta->id = $this->data_store->add_meta( $this, $meta );
667
-				$meta->apply_changes();
668
-			} else {
669
-				if ( $meta->get_changes() ) {
670
-					$this->data_store->update_meta( $this, $meta );
671
-					$meta->apply_changes();
672
-				}
673
-			}
674
-		}
675
-		if ( ! empty( $this->cache_group ) ) {
676
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
677
-			wp_cache_delete( $cache_key, $this->cache_group );
678
-		}
679
-	}
680
-
681
-	/**
682
-	 * Set ID.
683
-	 *
684
-	 * @since 1.0.19
685
-	 * @param int $id ID.
686
-	 */
687
-	public function set_id( $id ) {
688
-		$this->id = absint( $id );
689
-	}
690
-
691
-	/**
692
-	 * Sets item status.
693
-	 *
694
-	 * @since 1.0.19
695
-	 * @param string $status New status.
696
-	 * @return array details of change.
697
-	 */
698
-	public function set_status( $status ) {
392
+        return $this->get_prop( $key );
393
+
394
+    }
395
+
396
+    /**
397
+     * Get Meta Data by Key.
398
+     *
399
+     * @since  1.0.19
400
+     * @param  string $key Meta Key.
401
+     * @param  bool   $single return first found meta with key, or all with $key.
402
+     * @param  string $context What the value is for. Valid values are view and edit.
403
+     * @return mixed
404
+     */
405
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
406
+
407
+        // Check if this is an internal meta key.
408
+        if ( $this->is_internal_meta_key( $key ) ) {
409
+            $function = 'get_' . $key;
410
+
411
+            if ( is_callable( array( $this, $function ) ) ) {
412
+                return $this->{$function}();
413
+            }
414
+        }
415
+
416
+        // Read the meta data if not yet read.
417
+        $this->maybe_read_meta_data();
418
+        $meta_data  = $this->get_meta_data();
419
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
420
+        $value      = $single ? '' : array();
421
+
422
+        if ( ! empty( $array_keys ) ) {
423
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
424
+            if ( $single ) {
425
+                $value = $meta_data[ current( $array_keys ) ]->value;
426
+            } else {
427
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
428
+            }
429
+        }
430
+
431
+        if ( 'view' === $context ) {
432
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
433
+        }
434
+
435
+        return $value;
436
+    }
437
+
438
+    /**
439
+     * See if meta data exists, since get_meta always returns a '' or array().
440
+     *
441
+     * @since  1.0.19
442
+     * @param  string $key Meta Key.
443
+     * @return boolean
444
+     */
445
+    public function meta_exists( $key = '' ) {
446
+        $this->maybe_read_meta_data();
447
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
448
+        return in_array( $key, $array_keys, true );
449
+    }
450
+
451
+    /**
452
+     * Set all meta data from array.
453
+     *
454
+     * @since 1.0.19
455
+     * @param array $data Key/Value pairs.
456
+     */
457
+    public function set_meta_data( $data ) {
458
+        if ( ! empty( $data ) && is_array( $data ) ) {
459
+            $this->maybe_read_meta_data();
460
+            foreach ( $data as $meta ) {
461
+                $meta = (array) $meta;
462
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
463
+                    $this->meta_data[] = new GetPaid_Meta_Data(
464
+                        array(
465
+                            'id'    => $meta['id'],
466
+                            'key'   => $meta['key'],
467
+                            'value' => $meta['value'],
468
+                        )
469
+                    );
470
+                }
471
+            }
472
+        }
473
+    }
474
+
475
+    /**
476
+     * Add meta data.
477
+     *
478
+     * @since 1.0.19
479
+     *
480
+     * @param string       $key Meta key.
481
+     * @param string|array $value Meta value.
482
+     * @param bool         $unique Should this be a unique key?.
483
+     */
484
+    public function add_meta_data( $key, $value, $unique = false ) {
485
+        if ( $this->is_internal_meta_key( $key ) ) {
486
+            $function = 'set_' . $key;
487
+
488
+            if ( is_callable( array( $this, $function ) ) ) {
489
+                return $this->{$function}( $value );
490
+            }
491
+        }
492
+
493
+        $this->maybe_read_meta_data();
494
+        if ( $unique ) {
495
+            $this->delete_meta_data( $key );
496
+        }
497
+        $this->meta_data[] = new GetPaid_Meta_Data(
498
+            array(
499
+                'key'   => $key,
500
+                'value' => $value,
501
+            )
502
+        );
503
+    }
504
+
505
+    /**
506
+     * Update meta data by key or ID, if provided.
507
+     *
508
+     * @since  1.0.19
509
+     *
510
+     * @param  string       $key Meta key.
511
+     * @param  string|array $value Meta value.
512
+     * @param  int          $meta_id Meta ID.
513
+     */
514
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
515
+        if ( $this->is_internal_meta_key( $key ) ) {
516
+            $function = 'set_' . $key;
517
+
518
+            if ( is_callable( array( $this, $function ) ) ) {
519
+                return $this->{$function}( $value );
520
+            }
521
+        }
522
+
523
+        $this->maybe_read_meta_data();
524
+
525
+        $array_key = false;
526
+
527
+        if ( $meta_id ) {
528
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
529
+            $array_key  = $array_keys ? current( $array_keys ) : false;
530
+        } else {
531
+            // Find matches by key.
532
+            $matches = array();
533
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
534
+                if ( $meta->key === $key ) {
535
+                    $matches[] = $meta_data_array_key;
536
+                }
537
+            }
538
+
539
+            if ( ! empty( $matches ) ) {
540
+                // Set matches to null so only one key gets the new value.
541
+                foreach ( $matches as $meta_data_array_key ) {
542
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
543
+                }
544
+                $array_key = current( $matches );
545
+            }
546
+        }
547
+
548
+        if ( false !== $array_key ) {
549
+            $meta        = $this->meta_data[ $array_key ];
550
+            $meta->key   = $key;
551
+            $meta->value = $value;
552
+        } else {
553
+            $this->add_meta_data( $key, $value, true );
554
+        }
555
+    }
556
+
557
+    /**
558
+     * Delete meta data.
559
+     *
560
+     * @since 1.0.19
561
+     * @param string $key Meta key.
562
+     */
563
+    public function delete_meta_data( $key ) {
564
+        $this->maybe_read_meta_data();
565
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
566
+
567
+        if ( $array_keys ) {
568
+            foreach ( $array_keys as $array_key ) {
569
+                $this->meta_data[ $array_key ]->value = null;
570
+            }
571
+        }
572
+    }
573
+
574
+    /**
575
+     * Delete meta data.
576
+     *
577
+     * @since 1.0.19
578
+     * @param int $mid Meta ID.
579
+     */
580
+    public function delete_meta_data_by_mid( $mid ) {
581
+        $this->maybe_read_meta_data();
582
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
583
+
584
+        if ( $array_keys ) {
585
+            foreach ( $array_keys as $array_key ) {
586
+                $this->meta_data[ $array_key ]->value = null;
587
+            }
588
+        }
589
+    }
590
+
591
+    /**
592
+     * Read meta data if null.
593
+     *
594
+     * @since 1.0.19
595
+     */
596
+    protected function maybe_read_meta_data() {
597
+        if ( is_null( $this->meta_data ) ) {
598
+            $this->read_meta_data();
599
+        }
600
+    }
601
+
602
+    /**
603
+     * Read Meta Data from the database. Ignore any internal properties.
604
+     * Uses it's own caches because get_metadata does not provide meta_ids.
605
+     *
606
+     * @since 1.0.19
607
+     * @param bool $force_read True to force a new DB read (and update cache).
608
+     */
609
+    public function read_meta_data( $force_read = false ) {
610
+        $this->meta_data = array();
611
+        $cache_loaded    = false;
612
+
613
+        if ( ! $this->get_id() ) {
614
+            return;
615
+        }
616
+
617
+        if ( ! $this->data_store ) {
618
+            return;
619
+        }
620
+
621
+        if ( ! empty( $this->cache_group ) ) {
622
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
623
+        }
624
+
625
+        if ( ! $force_read ) {
626
+            if ( ! empty( $this->cache_group ) ) {
627
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
628
+                $cache_loaded = ! empty( $cached_meta );
629
+            }
630
+        }
631
+
632
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
633
+        if ( $raw_meta_data ) {
634
+            foreach ( $raw_meta_data as $meta ) {
635
+                $this->meta_data[] = new GetPaid_Meta_Data(
636
+                    array(
637
+                        'id'    => (int) $meta->meta_id,
638
+                        'key'   => $meta->meta_key,
639
+                        'value' => maybe_unserialize( $meta->meta_value ),
640
+                    )
641
+                );
642
+            }
643
+
644
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
645
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
646
+            }
647
+        }
648
+    }
649
+
650
+    /**
651
+     * Update Meta Data in the database.
652
+     *
653
+     * @since 1.0.19
654
+     */
655
+    public function save_meta_data() {
656
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
657
+            return;
658
+        }
659
+        foreach ( $this->meta_data as $array_key => $meta ) {
660
+            if ( is_null( $meta->value ) ) {
661
+                if ( ! empty( $meta->id ) ) {
662
+                    $this->data_store->delete_meta( $this, $meta );
663
+                    unset( $this->meta_data[ $array_key ] );
664
+                }
665
+            } elseif ( empty( $meta->id ) ) {
666
+                $meta->id = $this->data_store->add_meta( $this, $meta );
667
+                $meta->apply_changes();
668
+            } else {
669
+                if ( $meta->get_changes() ) {
670
+                    $this->data_store->update_meta( $this, $meta );
671
+                    $meta->apply_changes();
672
+                }
673
+            }
674
+        }
675
+        if ( ! empty( $this->cache_group ) ) {
676
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
677
+            wp_cache_delete( $cache_key, $this->cache_group );
678
+        }
679
+    }
680
+
681
+    /**
682
+     * Set ID.
683
+     *
684
+     * @since 1.0.19
685
+     * @param int $id ID.
686
+     */
687
+    public function set_id( $id ) {
688
+        $this->id = absint( $id );
689
+    }
690
+
691
+    /**
692
+     * Sets item status.
693
+     *
694
+     * @since 1.0.19
695
+     * @param string $status New status.
696
+     * @return array details of change.
697
+     */
698
+    public function set_status( $status ) {
699 699
         $old_status = $this->get_status();
700 700
 
701
-		$this->set_prop( 'status', $status );
702
-
703
-		return array(
704
-			'from' => $old_status,
705
-			'to'   => $status,
706
-		);
707
-    }
708
-
709
-	/**
710
-	 * Set all props to default values.
711
-	 *
712
-	 * @since 1.0.19
713
-	 */
714
-	public function set_defaults() {
715
-		$this->data    = $this->default_data;
716
-		$this->changes = array();
717
-		$this->set_object_read( false );
718
-	}
719
-
720
-	/**
721
-	 * Set object read property.
722
-	 *
723
-	 * @since 1.0.19
724
-	 * @param boolean $read Should read?.
725
-	 */
726
-	public function set_object_read( $read = true ) {
727
-		$this->object_read = (bool) $read;
728
-	}
729
-
730
-	/**
731
-	 * Get object read property.
732
-	 *
733
-	 * @since  1.0.19
734
-	 * @return boolean
735
-	 */
736
-	public function get_object_read() {
737
-		return (bool) $this->object_read;
738
-	}
739
-
740
-	/**
741
-	 * Set a collection of props in one go, collect any errors, and return the result.
742
-	 * Only sets using public methods.
743
-	 *
744
-	 * @since  1.0.19
745
-	 *
746
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
747
-	 * @param string $context In what context to run this.
748
-	 *
749
-	 * @return bool|WP_Error
750
-	 */
751
-	public function set_props( $props, $context = 'set' ) {
752
-		$errors = false;
753
-
754
-		foreach ( $props as $prop => $value ) {
755
-			try {
756
-				/**
757
-				 * Checks if the prop being set is allowed, and the value is not null.
758
-				 */
759
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
760
-					continue;
761
-				}
762
-				$setter = "set_$prop";
763
-
764
-				if ( is_callable( array( $this, $setter ) ) ) {
765
-					$this->{$setter}( $value );
766
-				}
767
-			} catch ( Exception $e ) {
768
-				if ( ! $errors ) {
769
-					$errors = new WP_Error();
770
-				}
771
-				$errors->add( $e->getCode(), $e->getMessage() );
772
-				$this->last_error = $e->getMessage();
773
-			}
774
-		}
775
-
776
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
777
-	}
778
-
779
-	/**
780
-	 * Sets a prop for a setter method.
781
-	 *
782
-	 * This stores changes in a special array so we can track what needs saving
783
-	 * the the DB later.
784
-	 *
785
-	 * @since 1.0.19
786
-	 * @param string $prop Name of prop to set.
787
-	 * @param mixed  $value Value of the prop.
788
-	 */
789
-	protected function set_prop( $prop, $value ) {
790
-		if ( array_key_exists( $prop, $this->data ) ) {
791
-			if ( true === $this->object_read ) {
792
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
793
-					$this->changes[ $prop ] = $value;
794
-				}
795
-			} else {
796
-				$this->data[ $prop ] = $value;
797
-			}
798
-		}
799
-	}
800
-
801
-	/**
802
-	 * Return data changes only.
803
-	 *
804
-	 * @since 1.0.19
805
-	 * @return array
806
-	 */
807
-	public function get_changes() {
808
-		return $this->changes;
809
-	}
810
-
811
-	/**
812
-	 * Merge changes with data and clear.
813
-	 *
814
-	 * @since 1.0.19
815
-	 */
816
-	public function apply_changes() {
817
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
818
-		$this->changes = array();
819
-	}
820
-
821
-	/**
822
-	 * Prefix for action and filter hooks on data.
823
-	 *
824
-	 * @since  1.0.19
825
-	 * @return string
826
-	 */
827
-	protected function get_hook_prefix() {
828
-		return 'wpinv_get_' . $this->object_type . '_';
829
-	}
830
-
831
-	/**
832
-	 * Gets a prop for a getter method.
833
-	 *
834
-	 * Gets the value from either current pending changes, or the data itself.
835
-	 * Context controls what happens to the value before it's returned.
836
-	 *
837
-	 * @since  1.0.19
838
-	 * @param  string $prop Name of prop to get.
839
-	 * @param  string $context What the value is for. Valid values are view and edit.
840
-	 * @return mixed
841
-	 */
842
-	protected function get_prop( $prop, $context = 'view' ) {
843
-		$value = null;
844
-
845
-		if ( array_key_exists( $prop, $this->data ) ) {
846
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
847
-
848
-			if ( 'view' === $context ) {
849
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
850
-			}
851
-		}
852
-
853
-		return $value;
854
-	}
855
-
856
-	/**
857
-	 * Sets a date prop whilst handling formatting and datetime objects.
858
-	 *
859
-	 * @since 1.0.19
860
-	 * @param string         $prop Name of prop to set.
861
-	 * @param string|integer $value Value of the prop.
862
-	 */
863
-	protected function set_date_prop( $prop, $value ) {
864
-
865
-		if ( empty( $value ) ) {
866
-			$this->set_prop( $prop, null );
867
-			return;
868
-		}
869
-		$this->set_prop( $prop, $value );
870
-
871
-	}
872
-
873
-	/**
874
-	 * When invalid data is found, throw an exception unless reading from the DB.
875
-	 *
876
-	 * @throws Exception Data Exception.
877
-	 * @since 1.0.19
878
-	 * @param string $code             Error code.
879
-	 * @param string $message          Error message.
880
-	 */
881
-	protected function error( $code, $message ) {
882
-		throw new Exception( $message, $code );
883
-	}
884
-
885
-	/**
886
-	 * Handle the status transition.
887
-	 */
888
-	protected function status_transition() {
889
-		$status_transition = $this->status_transition;
890
-
891
-		// Reset status transition variable.
892
-		$this->status_transition = false;
893
-
894
-		if ( $status_transition ) {
895
-			try {
896
-
897
-				$object = $this->object_type;
898
-
899
-				if ( 'invoice' == $object ) {
900
-					$this->get_type();
901
-				}
902
-
903
-				do_action( "wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this );
904
-
905
-				if ( ! empty( $status_transition['from'] ) ) {
906
-					/* translators: 1: old status 2: new status */
907
-					$transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
908
-
909
-					// Note the transition occurred.
910
-					$this->add_status_transition_note( $transition_note, $status_transition );
911
-
912
-					do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
913
-					do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
914
-
915
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
916
-					if (
917
-						in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
918
-						&& in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
919
-					) {
920
-						/**
921
-						 * Fires when the order progresses from a pending payment status to a paid one.
922
-						 *
923
-						 * @since 3.9.0
924
-						 * @param int Order ID
925
-						 * @param WC_Order Order object
926
-						 */
927
-						do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
928
-					}
929
-				} else {
930
-					/* translators: %s: new order status */
931
-					$transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
932
-
933
-					// Note the transition occurred.
934
-					$this->add_status_transition_note( $transition_note, $status_transition );
935
-				}
936
-			} catch ( Exception $e ) {
937
-				$logger = wc_get_logger();
938
-				$logger->error(
939
-					sprintf(
940
-						'Status transition of order #%d errored!',
941
-						$this->get_id()
942
-					),
943
-					array(
944
-						'order' => $this,
945
-						'error' => $e,
946
-					)
947
-				);
948
-				$this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
949
-			}
950
-		}
951
-	}
701
+        $this->set_prop( 'status', $status );
702
+
703
+        return array(
704
+            'from' => $old_status,
705
+            'to'   => $status,
706
+        );
707
+    }
708
+
709
+    /**
710
+     * Set all props to default values.
711
+     *
712
+     * @since 1.0.19
713
+     */
714
+    public function set_defaults() {
715
+        $this->data    = $this->default_data;
716
+        $this->changes = array();
717
+        $this->set_object_read( false );
718
+    }
719
+
720
+    /**
721
+     * Set object read property.
722
+     *
723
+     * @since 1.0.19
724
+     * @param boolean $read Should read?.
725
+     */
726
+    public function set_object_read( $read = true ) {
727
+        $this->object_read = (bool) $read;
728
+    }
729
+
730
+    /**
731
+     * Get object read property.
732
+     *
733
+     * @since  1.0.19
734
+     * @return boolean
735
+     */
736
+    public function get_object_read() {
737
+        return (bool) $this->object_read;
738
+    }
739
+
740
+    /**
741
+     * Set a collection of props in one go, collect any errors, and return the result.
742
+     * Only sets using public methods.
743
+     *
744
+     * @since  1.0.19
745
+     *
746
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
747
+     * @param string $context In what context to run this.
748
+     *
749
+     * @return bool|WP_Error
750
+     */
751
+    public function set_props( $props, $context = 'set' ) {
752
+        $errors = false;
753
+
754
+        foreach ( $props as $prop => $value ) {
755
+            try {
756
+                /**
757
+                 * Checks if the prop being set is allowed, and the value is not null.
758
+                 */
759
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
760
+                    continue;
761
+                }
762
+                $setter = "set_$prop";
763
+
764
+                if ( is_callable( array( $this, $setter ) ) ) {
765
+                    $this->{$setter}( $value );
766
+                }
767
+            } catch ( Exception $e ) {
768
+                if ( ! $errors ) {
769
+                    $errors = new WP_Error();
770
+                }
771
+                $errors->add( $e->getCode(), $e->getMessage() );
772
+                $this->last_error = $e->getMessage();
773
+            }
774
+        }
775
+
776
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
777
+    }
778
+
779
+    /**
780
+     * Sets a prop for a setter method.
781
+     *
782
+     * This stores changes in a special array so we can track what needs saving
783
+     * the the DB later.
784
+     *
785
+     * @since 1.0.19
786
+     * @param string $prop Name of prop to set.
787
+     * @param mixed  $value Value of the prop.
788
+     */
789
+    protected function set_prop( $prop, $value ) {
790
+        if ( array_key_exists( $prop, $this->data ) ) {
791
+            if ( true === $this->object_read ) {
792
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
793
+                    $this->changes[ $prop ] = $value;
794
+                }
795
+            } else {
796
+                $this->data[ $prop ] = $value;
797
+            }
798
+        }
799
+    }
800
+
801
+    /**
802
+     * Return data changes only.
803
+     *
804
+     * @since 1.0.19
805
+     * @return array
806
+     */
807
+    public function get_changes() {
808
+        return $this->changes;
809
+    }
810
+
811
+    /**
812
+     * Merge changes with data and clear.
813
+     *
814
+     * @since 1.0.19
815
+     */
816
+    public function apply_changes() {
817
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
818
+        $this->changes = array();
819
+    }
820
+
821
+    /**
822
+     * Prefix for action and filter hooks on data.
823
+     *
824
+     * @since  1.0.19
825
+     * @return string
826
+     */
827
+    protected function get_hook_prefix() {
828
+        return 'wpinv_get_' . $this->object_type . '_';
829
+    }
830
+
831
+    /**
832
+     * Gets a prop for a getter method.
833
+     *
834
+     * Gets the value from either current pending changes, or the data itself.
835
+     * Context controls what happens to the value before it's returned.
836
+     *
837
+     * @since  1.0.19
838
+     * @param  string $prop Name of prop to get.
839
+     * @param  string $context What the value is for. Valid values are view and edit.
840
+     * @return mixed
841
+     */
842
+    protected function get_prop( $prop, $context = 'view' ) {
843
+        $value = null;
844
+
845
+        if ( array_key_exists( $prop, $this->data ) ) {
846
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
847
+
848
+            if ( 'view' === $context ) {
849
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
850
+            }
851
+        }
852
+
853
+        return $value;
854
+    }
855
+
856
+    /**
857
+     * Sets a date prop whilst handling formatting and datetime objects.
858
+     *
859
+     * @since 1.0.19
860
+     * @param string         $prop Name of prop to set.
861
+     * @param string|integer $value Value of the prop.
862
+     */
863
+    protected function set_date_prop( $prop, $value ) {
864
+
865
+        if ( empty( $value ) ) {
866
+            $this->set_prop( $prop, null );
867
+            return;
868
+        }
869
+        $this->set_prop( $prop, $value );
870
+
871
+    }
872
+
873
+    /**
874
+     * When invalid data is found, throw an exception unless reading from the DB.
875
+     *
876
+     * @throws Exception Data Exception.
877
+     * @since 1.0.19
878
+     * @param string $code             Error code.
879
+     * @param string $message          Error message.
880
+     */
881
+    protected function error( $code, $message ) {
882
+        throw new Exception( $message, $code );
883
+    }
884
+
885
+    /**
886
+     * Handle the status transition.
887
+     */
888
+    protected function status_transition() {
889
+        $status_transition = $this->status_transition;
890
+
891
+        // Reset status transition variable.
892
+        $this->status_transition = false;
893
+
894
+        if ( $status_transition ) {
895
+            try {
896
+
897
+                $object = $this->object_type;
898
+
899
+                if ( 'invoice' == $object ) {
900
+                    $this->get_type();
901
+                }
902
+
903
+                do_action( "wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this );
904
+
905
+                if ( ! empty( $status_transition['from'] ) ) {
906
+                    /* translators: 1: old status 2: new status */
907
+                    $transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
908
+
909
+                    // Note the transition occurred.
910
+                    $this->add_status_transition_note( $transition_note, $status_transition );
911
+
912
+                    do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
913
+                    do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
914
+
915
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
916
+                    if (
917
+                        in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
918
+                        && in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
919
+                    ) {
920
+                        /**
921
+                         * Fires when the order progresses from a pending payment status to a paid one.
922
+                         *
923
+                         * @since 3.9.0
924
+                         * @param int Order ID
925
+                         * @param WC_Order Order object
926
+                         */
927
+                        do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
928
+                    }
929
+                } else {
930
+                    /* translators: %s: new order status */
931
+                    $transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
932
+
933
+                    // Note the transition occurred.
934
+                    $this->add_status_transition_note( $transition_note, $status_transition );
935
+                }
936
+            } catch ( Exception $e ) {
937
+                $logger = wc_get_logger();
938
+                $logger->error(
939
+                    sprintf(
940
+                        'Status transition of order #%d errored!',
941
+                        $this->get_id()
942
+                    ),
943
+                    array(
944
+                        'order' => $this,
945
+                        'error' => $e,
946
+                    )
947
+                );
948
+                $this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
949
+            }
950
+        }
951
+    }
952 952
 }
Please login to merge, or discard this patch.
Spacing   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -138,10 +138,10 @@  discard block
 block discarded – undo
138 138
 	 */
139 139
 	public function __wakeup() {
140 140
 		try {
141
-			$this->__construct( absint( $this->id ) );
142
-		} catch ( Exception $e ) {
143
-			$this->set_id( 0 );
144
-			$this->set_object_read( true );
141
+			$this->__construct(absint($this->id));
142
+		} catch (Exception $e) {
143
+			$this->set_id(0);
144
+			$this->set_object_read(true);
145 145
 		}
146 146
 	}
147 147
 
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 154
 		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
155
+		if (!empty($this->meta_data)) {
156
+			foreach ($this->meta_data as $array_key => $meta) {
157
+				$this->meta_data[$array_key] = clone $meta;
158
+				if (!empty($meta->id)) {
159
+					$this->meta_data[$array_key]->id = null;
160 160
 				}
161 161
 			}
162 162
 		}
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
202
+	public function get_status($context = 'view') {
203
+		return $this->get_prop('status', $context);
204 204
     }
205 205
 
206 206
 	/**
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 	 * @param  bool $force_delete Should the data be deleted permanently.
211 211
 	 * @return bool result
212 212
 	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
213
+	public function delete($force_delete = false) {
214
+		if ($this->data_store) {
215
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
216
+			$this->set_id(0);
217 217
 			return true;
218 218
 		}
219 219
 		return false;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @return int
227 227
 	 */
228 228
 	public function save() {
229
-		if ( ! $this->data_store ) {
229
+		if (!$this->data_store) {
230 230
 			return $this->get_id();
231 231
 		}
232 232
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 		 * @param GetPaid_Data          $this The object being saved.
237 237
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238 238
 		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
239
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
240 240
 
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
241
+		if ($this->get_id()) {
242
+			$this->data_store->update($this);
243 243
 		} else {
244
-			$this->data_store->create( $this );
244
+			$this->data_store->create($this);
245 245
 		}
246 246
 
247 247
 		/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param GetPaid_Data          $this The object being saved.
251 251
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252 252
 		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
253
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
254 254
 
255 255
 		return $this->get_id();
256 256
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return string Data in JSON format.
263 263
 	 */
264 264
 	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
265
+		return wp_json_encode($this->get_data());
266 266
 	}
267 267
 
268 268
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return array
273 273
 	 */
274 274
 	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
275
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @return array
283 283
 	 */
284 284
 	public function get_data_keys() {
285
-		return array_keys( $this->data );
285
+		return array_keys($this->data);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 */
294 294
 	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
295
+		return array_keys($this->extra_data);
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $meta Meta value to check.
303 303
 	 * @return bool
304 304
 	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
305
+	protected function filter_null_meta($meta) {
306
+		return !is_null($meta->value);
307 307
 	}
308 308
 
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 */
315 315
 	public function get_meta_data() {
316 316
 		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
317
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
318 318
 	}
319 319
 
320 320
 	/**
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 	 * @param  string $key Key to check.
325 325
 	 * @return bool   true if it's an internal key, false otherwise
326 326
 	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
327
+	protected function is_internal_meta_key($key) {
328
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
329 329
 
330
-		if ( ! $internal_meta_key ) {
330
+		if (!$internal_meta_key) {
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
334
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
335 335
 
336
-		if ( ! $has_setter_or_getter ) {
336
+		if (!$has_setter_or_getter) {
337 337
 			return false;
338 338
 		}
339 339
 
340 340
 		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
341
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
342 342
 
343 343
 		return true;
344 344
 	}
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 *
354 354
 	 */
355
-	public function __set( $key, $value ) {
355
+	public function __set($key, $value) {
356 356
 
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
357
+		if ('id' == strtolower($key)) {
358
+			return $this->set_id($value);
359 359
 		}
360 360
 
361
-		if ( method_exists( $this, "set_$key") ) {
361
+		if (method_exists($this, "set_$key")) {
362 362
 
363 363
 			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
364
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
365 365
 
366
-			call_user_func( array( $this, "set_$key" ), $value );
366
+			call_user_func(array($this, "set_$key"), $value);
367 367
 		} else {
368
-			$this->set_prop( $key, $value );
368
+			$this->set_prop($key, $value);
369 369
 		}
370 370
 
371 371
 	}
@@ -373,23 +373,23 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
      * Margic method for retrieving a property.
375 375
      */
376
-    public function __get( $key ) {
376
+    public function __get($key) {
377 377
 
378 378
         // Check if we have a helper method for that.
379
-        if ( method_exists( $this, 'get_' . $key ) ) {
379
+        if (method_exists($this, 'get_' . $key)) {
380 380
 
381 381
 			/* translators: %s: $key Key to set */
382
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
382
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
383 383
 
384
-            return call_user_func( array( $this, 'get_' . $key ) );
384
+            return call_user_func(array($this, 'get_' . $key));
385 385
         }
386 386
 
387 387
         // Check if the key is in the associated $post object.
388
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
388
+        if (!empty($this->post) && isset($this->post->$key)) {
389 389
             return $this->post->$key;
390 390
         }
391 391
 
392
-		return $this->get_prop( $key );
392
+		return $this->get_prop($key);
393 393
 
394 394
     }
395 395
 
@@ -402,13 +402,13 @@  discard block
 block discarded – undo
402 402
 	 * @param  string $context What the value is for. Valid values are view and edit.
403 403
 	 * @return mixed
404 404
 	 */
405
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
405
+	public function get_meta($key = '', $single = true, $context = 'view') {
406 406
 
407 407
 		// Check if this is an internal meta key.
408
-		if ( $this->is_internal_meta_key( $key ) ) {
408
+		if ($this->is_internal_meta_key($key)) {
409 409
 			$function = 'get_' . $key;
410 410
 
411
-			if ( is_callable( array( $this, $function ) ) ) {
411
+			if (is_callable(array($this, $function))) {
412 412
 				return $this->{$function}();
413 413
 			}
414 414
 		}
@@ -416,20 +416,20 @@  discard block
 block discarded – undo
416 416
 		// Read the meta data if not yet read.
417 417
 		$this->maybe_read_meta_data();
418 418
 		$meta_data  = $this->get_meta_data();
419
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
419
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
420 420
 		$value      = $single ? '' : array();
421 421
 
422
-		if ( ! empty( $array_keys ) ) {
422
+		if (!empty($array_keys)) {
423 423
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
424
-			if ( $single ) {
425
-				$value = $meta_data[ current( $array_keys ) ]->value;
424
+			if ($single) {
425
+				$value = $meta_data[current($array_keys)]->value;
426 426
 			} else {
427
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
427
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
428 428
 			}
429 429
 		}
430 430
 
431
-		if ( 'view' === $context ) {
432
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
431
+		if ('view' === $context) {
432
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
433 433
 		}
434 434
 
435 435
 		return $value;
@@ -442,10 +442,10 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $key Meta Key.
443 443
 	 * @return boolean
444 444
 	 */
445
-	public function meta_exists( $key = '' ) {
445
+	public function meta_exists($key = '') {
446 446
 		$this->maybe_read_meta_data();
447
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
448
-		return in_array( $key, $array_keys, true );
447
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
448
+		return in_array($key, $array_keys, true);
449 449
 	}
450 450
 
451 451
 	/**
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
 	 * @since 1.0.19
455 455
 	 * @param array $data Key/Value pairs.
456 456
 	 */
457
-	public function set_meta_data( $data ) {
458
-		if ( ! empty( $data ) && is_array( $data ) ) {
457
+	public function set_meta_data($data) {
458
+		if (!empty($data) && is_array($data)) {
459 459
 			$this->maybe_read_meta_data();
460
-			foreach ( $data as $meta ) {
460
+			foreach ($data as $meta) {
461 461
 				$meta = (array) $meta;
462
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
462
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
463 463
 					$this->meta_data[] = new GetPaid_Meta_Data(
464 464
 						array(
465 465
 							'id'    => $meta['id'],
@@ -481,18 +481,18 @@  discard block
 block discarded – undo
481 481
 	 * @param string|array $value Meta value.
482 482
 	 * @param bool         $unique Should this be a unique key?.
483 483
 	 */
484
-	public function add_meta_data( $key, $value, $unique = false ) {
485
-		if ( $this->is_internal_meta_key( $key ) ) {
484
+	public function add_meta_data($key, $value, $unique = false) {
485
+		if ($this->is_internal_meta_key($key)) {
486 486
 			$function = 'set_' . $key;
487 487
 
488
-			if ( is_callable( array( $this, $function ) ) ) {
489
-				return $this->{$function}( $value );
488
+			if (is_callable(array($this, $function))) {
489
+				return $this->{$function}($value);
490 490
 			}
491 491
 		}
492 492
 
493 493
 		$this->maybe_read_meta_data();
494
-		if ( $unique ) {
495
-			$this->delete_meta_data( $key );
494
+		if ($unique) {
495
+			$this->delete_meta_data($key);
496 496
 		}
497 497
 		$this->meta_data[] = new GetPaid_Meta_Data(
498 498
 			array(
@@ -511,12 +511,12 @@  discard block
 block discarded – undo
511 511
 	 * @param  string|array $value Meta value.
512 512
 	 * @param  int          $meta_id Meta ID.
513 513
 	 */
514
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
515
-		if ( $this->is_internal_meta_key( $key ) ) {
514
+	public function update_meta_data($key, $value, $meta_id = 0) {
515
+		if ($this->is_internal_meta_key($key)) {
516 516
 			$function = 'set_' . $key;
517 517
 
518
-			if ( is_callable( array( $this, $function ) ) ) {
519
-				return $this->{$function}( $value );
518
+			if (is_callable(array($this, $function))) {
519
+				return $this->{$function}($value);
520 520
 			}
521 521
 		}
522 522
 
@@ -524,33 +524,33 @@  discard block
 block discarded – undo
524 524
 
525 525
 		$array_key = false;
526 526
 
527
-		if ( $meta_id ) {
528
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
529
-			$array_key  = $array_keys ? current( $array_keys ) : false;
527
+		if ($meta_id) {
528
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
529
+			$array_key  = $array_keys ? current($array_keys) : false;
530 530
 		} else {
531 531
 			// Find matches by key.
532 532
 			$matches = array();
533
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
534
-				if ( $meta->key === $key ) {
533
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
534
+				if ($meta->key === $key) {
535 535
 					$matches[] = $meta_data_array_key;
536 536
 				}
537 537
 			}
538 538
 
539
-			if ( ! empty( $matches ) ) {
539
+			if (!empty($matches)) {
540 540
 				// Set matches to null so only one key gets the new value.
541
-				foreach ( $matches as $meta_data_array_key ) {
542
-					$this->meta_data[ $meta_data_array_key ]->value = null;
541
+				foreach ($matches as $meta_data_array_key) {
542
+					$this->meta_data[$meta_data_array_key]->value = null;
543 543
 				}
544
-				$array_key = current( $matches );
544
+				$array_key = current($matches);
545 545
 			}
546 546
 		}
547 547
 
548
-		if ( false !== $array_key ) {
549
-			$meta        = $this->meta_data[ $array_key ];
548
+		if (false !== $array_key) {
549
+			$meta        = $this->meta_data[$array_key];
550 550
 			$meta->key   = $key;
551 551
 			$meta->value = $value;
552 552
 		} else {
553
-			$this->add_meta_data( $key, $value, true );
553
+			$this->add_meta_data($key, $value, true);
554 554
 		}
555 555
 	}
556 556
 
@@ -560,13 +560,13 @@  discard block
 block discarded – undo
560 560
 	 * @since 1.0.19
561 561
 	 * @param string $key Meta key.
562 562
 	 */
563
-	public function delete_meta_data( $key ) {
563
+	public function delete_meta_data($key) {
564 564
 		$this->maybe_read_meta_data();
565
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
565
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
566 566
 
567
-		if ( $array_keys ) {
568
-			foreach ( $array_keys as $array_key ) {
569
-				$this->meta_data[ $array_key ]->value = null;
567
+		if ($array_keys) {
568
+			foreach ($array_keys as $array_key) {
569
+				$this->meta_data[$array_key]->value = null;
570 570
 			}
571 571
 		}
572 572
 	}
@@ -577,13 +577,13 @@  discard block
 block discarded – undo
577 577
 	 * @since 1.0.19
578 578
 	 * @param int $mid Meta ID.
579 579
 	 */
580
-	public function delete_meta_data_by_mid( $mid ) {
580
+	public function delete_meta_data_by_mid($mid) {
581 581
 		$this->maybe_read_meta_data();
582
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
582
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
583 583
 
584
-		if ( $array_keys ) {
585
-			foreach ( $array_keys as $array_key ) {
586
-				$this->meta_data[ $array_key ]->value = null;
584
+		if ($array_keys) {
585
+			foreach ($array_keys as $array_key) {
586
+				$this->meta_data[$array_key]->value = null;
587 587
 			}
588 588
 		}
589 589
 	}
@@ -594,7 +594,7 @@  discard block
 block discarded – undo
594 594
 	 * @since 1.0.19
595 595
 	 */
596 596
 	protected function maybe_read_meta_data() {
597
-		if ( is_null( $this->meta_data ) ) {
597
+		if (is_null($this->meta_data)) {
598 598
 			$this->read_meta_data();
599 599
 		}
600 600
 	}
@@ -606,43 +606,43 @@  discard block
 block discarded – undo
606 606
 	 * @since 1.0.19
607 607
 	 * @param bool $force_read True to force a new DB read (and update cache).
608 608
 	 */
609
-	public function read_meta_data( $force_read = false ) {
609
+	public function read_meta_data($force_read = false) {
610 610
 		$this->meta_data = array();
611 611
 		$cache_loaded    = false;
612 612
 
613
-		if ( ! $this->get_id() ) {
613
+		if (!$this->get_id()) {
614 614
 			return;
615 615
 		}
616 616
 
617
-		if ( ! $this->data_store ) {
617
+		if (!$this->data_store) {
618 618
 			return;
619 619
 		}
620 620
 
621
-		if ( ! empty( $this->cache_group ) ) {
622
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
621
+		if (!empty($this->cache_group)) {
622
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
623 623
 		}
624 624
 
625
-		if ( ! $force_read ) {
626
-			if ( ! empty( $this->cache_group ) ) {
627
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
628
-				$cache_loaded = ! empty( $cached_meta );
625
+		if (!$force_read) {
626
+			if (!empty($this->cache_group)) {
627
+				$cached_meta  = wp_cache_get($cache_key, $this->cache_group);
628
+				$cache_loaded = !empty($cached_meta);
629 629
 			}
630 630
 		}
631 631
 
632
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
633
-		if ( $raw_meta_data ) {
634
-			foreach ( $raw_meta_data as $meta ) {
632
+		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this);
633
+		if ($raw_meta_data) {
634
+			foreach ($raw_meta_data as $meta) {
635 635
 				$this->meta_data[] = new GetPaid_Meta_Data(
636 636
 					array(
637 637
 						'id'    => (int) $meta->meta_id,
638 638
 						'key'   => $meta->meta_key,
639
-						'value' => maybe_unserialize( $meta->meta_value ),
639
+						'value' => maybe_unserialize($meta->meta_value),
640 640
 					)
641 641
 				);
642 642
 			}
643 643
 
644
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
645
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
644
+			if (!$cache_loaded && !empty($this->cache_group)) {
645
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
646 646
 			}
647 647
 		}
648 648
 	}
@@ -653,28 +653,28 @@  discard block
 block discarded – undo
653 653
 	 * @since 1.0.19
654 654
 	 */
655 655
 	public function save_meta_data() {
656
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
656
+		if (!$this->data_store || is_null($this->meta_data)) {
657 657
 			return;
658 658
 		}
659
-		foreach ( $this->meta_data as $array_key => $meta ) {
660
-			if ( is_null( $meta->value ) ) {
661
-				if ( ! empty( $meta->id ) ) {
662
-					$this->data_store->delete_meta( $this, $meta );
663
-					unset( $this->meta_data[ $array_key ] );
659
+		foreach ($this->meta_data as $array_key => $meta) {
660
+			if (is_null($meta->value)) {
661
+				if (!empty($meta->id)) {
662
+					$this->data_store->delete_meta($this, $meta);
663
+					unset($this->meta_data[$array_key]);
664 664
 				}
665
-			} elseif ( empty( $meta->id ) ) {
666
-				$meta->id = $this->data_store->add_meta( $this, $meta );
665
+			} elseif (empty($meta->id)) {
666
+				$meta->id = $this->data_store->add_meta($this, $meta);
667 667
 				$meta->apply_changes();
668 668
 			} else {
669
-				if ( $meta->get_changes() ) {
670
-					$this->data_store->update_meta( $this, $meta );
669
+				if ($meta->get_changes()) {
670
+					$this->data_store->update_meta($this, $meta);
671 671
 					$meta->apply_changes();
672 672
 				}
673 673
 			}
674 674
 		}
675
-		if ( ! empty( $this->cache_group ) ) {
676
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
677
-			wp_cache_delete( $cache_key, $this->cache_group );
675
+		if (!empty($this->cache_group)) {
676
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
677
+			wp_cache_delete($cache_key, $this->cache_group);
678 678
 		}
679 679
 	}
680 680
 
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
 	 * @since 1.0.19
685 685
 	 * @param int $id ID.
686 686
 	 */
687
-	public function set_id( $id ) {
688
-		$this->id = absint( $id );
687
+	public function set_id($id) {
688
+		$this->id = absint($id);
689 689
 	}
690 690
 
691 691
 	/**
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
 	 * @param string $status New status.
696 696
 	 * @return array details of change.
697 697
 	 */
698
-	public function set_status( $status ) {
698
+	public function set_status($status) {
699 699
         $old_status = $this->get_status();
700 700
 
701
-		$this->set_prop( 'status', $status );
701
+		$this->set_prop('status', $status);
702 702
 
703 703
 		return array(
704 704
 			'from' => $old_status,
@@ -714,7 +714,7 @@  discard block
 block discarded – undo
714 714
 	public function set_defaults() {
715 715
 		$this->data    = $this->default_data;
716 716
 		$this->changes = array();
717
-		$this->set_object_read( false );
717
+		$this->set_object_read(false);
718 718
 	}
719 719
 
720 720
 	/**
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 	 * @since 1.0.19
724 724
 	 * @param boolean $read Should read?.
725 725
 	 */
726
-	public function set_object_read( $read = true ) {
726
+	public function set_object_read($read = true) {
727 727
 		$this->object_read = (bool) $read;
728 728
 	}
729 729
 
@@ -748,32 +748,32 @@  discard block
 block discarded – undo
748 748
 	 *
749 749
 	 * @return bool|WP_Error
750 750
 	 */
751
-	public function set_props( $props, $context = 'set' ) {
751
+	public function set_props($props, $context = 'set') {
752 752
 		$errors = false;
753 753
 
754
-		foreach ( $props as $prop => $value ) {
754
+		foreach ($props as $prop => $value) {
755 755
 			try {
756 756
 				/**
757 757
 				 * Checks if the prop being set is allowed, and the value is not null.
758 758
 				 */
759
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
759
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
760 760
 					continue;
761 761
 				}
762 762
 				$setter = "set_$prop";
763 763
 
764
-				if ( is_callable( array( $this, $setter ) ) ) {
765
-					$this->{$setter}( $value );
764
+				if (is_callable(array($this, $setter))) {
765
+					$this->{$setter}($value);
766 766
 				}
767
-			} catch ( Exception $e ) {
768
-				if ( ! $errors ) {
767
+			} catch (Exception $e) {
768
+				if (!$errors) {
769 769
 					$errors = new WP_Error();
770 770
 				}
771
-				$errors->add( $e->getCode(), $e->getMessage() );
771
+				$errors->add($e->getCode(), $e->getMessage());
772 772
 				$this->last_error = $e->getMessage();
773 773
 			}
774 774
 		}
775 775
 
776
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
776
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
777 777
 	}
778 778
 
779 779
 	/**
@@ -786,14 +786,14 @@  discard block
 block discarded – undo
786 786
 	 * @param string $prop Name of prop to set.
787 787
 	 * @param mixed  $value Value of the prop.
788 788
 	 */
789
-	protected function set_prop( $prop, $value ) {
790
-		if ( array_key_exists( $prop, $this->data ) ) {
791
-			if ( true === $this->object_read ) {
792
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
793
-					$this->changes[ $prop ] = $value;
789
+	protected function set_prop($prop, $value) {
790
+		if (array_key_exists($prop, $this->data)) {
791
+			if (true === $this->object_read) {
792
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
793
+					$this->changes[$prop] = $value;
794 794
 				}
795 795
 			} else {
796
-				$this->data[ $prop ] = $value;
796
+				$this->data[$prop] = $value;
797 797
 			}
798 798
 		}
799 799
 	}
@@ -814,7 +814,7 @@  discard block
 block discarded – undo
814 814
 	 * @since 1.0.19
815 815
 	 */
816 816
 	public function apply_changes() {
817
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
817
+		$this->data    = array_replace_recursive($this->data, $this->changes);
818 818
 		$this->changes = array();
819 819
 	}
820 820
 
@@ -839,14 +839,14 @@  discard block
 block discarded – undo
839 839
 	 * @param  string $context What the value is for. Valid values are view and edit.
840 840
 	 * @return mixed
841 841
 	 */
842
-	protected function get_prop( $prop, $context = 'view' ) {
842
+	protected function get_prop($prop, $context = 'view') {
843 843
 		$value = null;
844 844
 
845
-		if ( array_key_exists( $prop, $this->data ) ) {
846
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
845
+		if (array_key_exists($prop, $this->data)) {
846
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
847 847
 
848
-			if ( 'view' === $context ) {
849
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
848
+			if ('view' === $context) {
849
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
850 850
 			}
851 851
 		}
852 852
 
@@ -860,13 +860,13 @@  discard block
 block discarded – undo
860 860
 	 * @param string         $prop Name of prop to set.
861 861
 	 * @param string|integer $value Value of the prop.
862 862
 	 */
863
-	protected function set_date_prop( $prop, $value ) {
863
+	protected function set_date_prop($prop, $value) {
864 864
 
865
-		if ( empty( $value ) ) {
866
-			$this->set_prop( $prop, null );
865
+		if (empty($value)) {
866
+			$this->set_prop($prop, null);
867 867
 			return;
868 868
 		}
869
-		$this->set_prop( $prop, $value );
869
+		$this->set_prop($prop, $value);
870 870
 
871 871
 	}
872 872
 
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 	 * @param string $code             Error code.
879 879
 	 * @param string $message          Error message.
880 880
 	 */
881
-	protected function error( $code, $message ) {
882
-		throw new Exception( $message, $code );
881
+	protected function error($code, $message) {
882
+		throw new Exception($message, $code);
883 883
 	}
884 884
 
885 885
 	/**
@@ -891,31 +891,31 @@  discard block
 block discarded – undo
891 891
 		// Reset status transition variable.
892 892
 		$this->status_transition = false;
893 893
 
894
-		if ( $status_transition ) {
894
+		if ($status_transition) {
895 895
 			try {
896 896
 
897 897
 				$object = $this->object_type;
898 898
 
899
-				if ( 'invoice' == $object ) {
899
+				if ('invoice' == $object) {
900 900
 					$this->get_type();
901 901
 				}
902 902
 
903
-				do_action( "wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this );
903
+				do_action("wpinv_{$object}_status_" . $status_transition['to'], $this->get_id(), $this);
904 904
 
905
-				if ( ! empty( $status_transition['from'] ) ) {
905
+				if (!empty($status_transition['from'])) {
906 906
 					/* translators: 1: old status 2: new status */
907
-					$transition_note = sprintf( __( 'Order status changed from %1$s to %2$s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['from'] ), wc_get_order_status_name( $status_transition['to'] ) );
907
+					$transition_note = sprintf(__('Order status changed from %1$s to %2$s.', 'woocommerce'), wc_get_order_status_name($status_transition['from']), wc_get_order_status_name($status_transition['to']));
908 908
 
909 909
 					// Note the transition occurred.
910
-					$this->add_status_transition_note( $transition_note, $status_transition );
910
+					$this->add_status_transition_note($transition_note, $status_transition);
911 911
 
912
-					do_action( 'woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
913
-					do_action( 'woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
912
+					do_action('woocommerce_order_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
913
+					do_action('woocommerce_order_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this);
914 914
 
915 915
 					// Work out if this was for a payment, and trigger a payment_status hook instead.
916 916
 					if (
917
-						in_array( $status_transition['from'], apply_filters( 'woocommerce_valid_order_statuses_for_payment', array( 'pending', 'failed' ), $this ), true )
918
-						&& in_array( $status_transition['to'], wc_get_is_paid_statuses(), true )
917
+						in_array($status_transition['from'], apply_filters('woocommerce_valid_order_statuses_for_payment', array('pending', 'failed'), $this), true)
918
+						&& in_array($status_transition['to'], wc_get_is_paid_statuses(), true)
919 919
 					) {
920 920
 						/**
921 921
 						 * Fires when the order progresses from a pending payment status to a paid one.
@@ -924,16 +924,16 @@  discard block
 block discarded – undo
924 924
 						 * @param int Order ID
925 925
 						 * @param WC_Order Order object
926 926
 						 */
927
-						do_action( 'woocommerce_order_payment_status_changed', $this->get_id(), $this );
927
+						do_action('woocommerce_order_payment_status_changed', $this->get_id(), $this);
928 928
 					}
929 929
 				} else {
930 930
 					/* translators: %s: new order status */
931
-					$transition_note = sprintf( __( 'Order status set to %s.', 'woocommerce' ), wc_get_order_status_name( $status_transition['to'] ) );
931
+					$transition_note = sprintf(__('Order status set to %s.', 'woocommerce'), wc_get_order_status_name($status_transition['to']));
932 932
 
933 933
 					// Note the transition occurred.
934
-					$this->add_status_transition_note( $transition_note, $status_transition );
934
+					$this->add_status_transition_note($transition_note, $status_transition);
935 935
 				}
936
-			} catch ( Exception $e ) {
936
+			} catch (Exception $e) {
937 937
 				$logger = wc_get_logger();
938 938
 				$logger->error(
939 939
 					sprintf(
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 						'error' => $e,
946 946
 					)
947 947
 				);
948
-				$this->add_order_note( __( 'Error during status transition.', 'woocommerce' ) . ' ' . $e->getMessage() );
948
+				$this->add_order_note(__('Error during status transition.', 'woocommerce') . ' ' . $e->getMessage());
949 949
 			}
950 950
 		}
951 951
 	}
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-payment-form-data-store.php 2 patches
Indentation   +168 added lines, -168 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,178 +14,178 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Payment_Form_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for a form.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'wpinv_form_elements',
25
-		'wpinv_form_items',
26
-		'wpinv_form_earned',
27
-		'wpinv_form_refunded',
28
-		'wpinv_form_cancelled',
29
-		'wpinv_form_failed'
30
-	);
31
-
32
-	/**
33
-	 * A map of meta keys to data props.
34
-	 *
35
-	 * @since 1.0.19
36
-	 *
37
-	 * @var array
38
-	 */
39
-	protected $meta_key_to_props = array(
40
-		'wpinv_form_elements'  => 'elements',
41
-		'wpinv_form_items'     => 'items',
42
-		'wpinv_form_earned'    => 'earned',
43
-		'wpinv_form_refunded'  => 'refunded',
44
-		'wpinv_form_cancelled' => 'cancelled',
45
-		'wpinv_form_failed'    => 'failed',
46
-	);
47
-
48
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for a form.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        'wpinv_form_elements',
25
+        'wpinv_form_items',
26
+        'wpinv_form_earned',
27
+        'wpinv_form_refunded',
28
+        'wpinv_form_cancelled',
29
+        'wpinv_form_failed'
30
+    );
31
+
32
+    /**
33
+     * A map of meta keys to data props.
34
+     *
35
+     * @since 1.0.19
36
+     *
37
+     * @var array
38
+     */
39
+    protected $meta_key_to_props = array(
40
+        'wpinv_form_elements'  => 'elements',
41
+        'wpinv_form_items'     => 'items',
42
+        'wpinv_form_earned'    => 'earned',
43
+        'wpinv_form_refunded'  => 'refunded',
44
+        'wpinv_form_cancelled' => 'cancelled',
45
+        'wpinv_form_failed'    => 'failed',
46
+    );
47
+
48
+    /*
49 49
 	|--------------------------------------------------------------------------
50 50
 	| CRUD Methods
51 51
 	|--------------------------------------------------------------------------
52 52
 	*/
53 53
 
54
-	/**
55
-	 * Method to create a new form in the database.
56
-	 *
57
-	 * @param GetPaid_Payment_Form $form Form object.
58
-	 */
59
-	public function create( &$form ) {
60
-		$form->set_version( WPINV_VERSION );
61
-		$form->set_date_created( current_time('mysql') );
62
-
63
-		// Create a new post.
64
-		$id = wp_insert_post(
65
-			apply_filters(
66
-				'getpaid_new_payment_form_data',
67
-				array(
68
-					'post_date'     => $form->get_date_created( 'edit' ),
69
-					'post_type'     => 'wpi_payment_form',
70
-					'post_status'   => $this->get_post_status( $form ),
71
-					'ping_status'   => 'closed',
72
-					'post_author'   => $form->get_author( 'edit' ),
73
-					'post_title'    => $form->get_name( 'edit' ),
74
-				)
75
-			),
76
-			true
77
-		);
78
-
79
-		if ( $id && ! is_wp_error( $id ) ) {
80
-			$form->set_id( $id );
81
-			$this->update_post_meta( $form );
82
-			$form->save_meta_data();
83
-			$form->apply_changes();
84
-			$this->clear_caches( $form );
85
-			do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
86
-			return true;
87
-		}
88
-
89
-		if ( is_wp_error( $id ) ) {
90
-			$form->last_error = $id->get_error_message();
91
-		}
92
-
93
-		return false;
94
-	}
95
-
96
-	/**
97
-	 * Method to read a form from the database.
98
-	 *
99
-	 * @param GetPaid_Payment_Form $form Form object.
100
-	 *
101
-	 */
102
-	public function read( &$form ) {
103
-
104
-		$form->set_defaults();
105
-		$form_object = get_post( $form->get_id() );
106
-
107
-		if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
-			$form->last_error = __( 'Invalid form.', 'invoicing' );
109
-			return false;
110
-		}
111
-
112
-		$form->set_props(
113
-			array(
114
-				'date_created'  => 0 < $form_object->post_date ? $form_object->post_date : null,
115
-				'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null,
116
-				'status'        => $form_object->post_status,
117
-				'name'          => $form_object->post_title,
118
-				'author'        => $form_object->post_author,
119
-			)
120
-		);
121
-
122
-		$this->read_object_data( $form, $form_object );
123
-		$form->read_meta_data();
124
-		$form->set_object_read( true );
125
-		do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
126
-
127
-	}
128
-
129
-	/**
130
-	 * Method to update a form in the database.
131
-	 *
132
-	 * @param GetPaid_Payment_Form $form Form object.
133
-	 */
134
-	public function update( &$form ) {
135
-		$form->save_meta_data();
136
-		$form->set_version( WPINV_VERSION );
137
-
138
-		if ( null === $form->get_date_created( 'edit' ) ) {
139
-			$form->set_date_created(  current_time('mysql') );
140
-		}
141
-
142
-		// Grab the current status so we can compare.
143
-		$previous_status = get_post_status( $form->get_id() );
144
-
145
-		$changes = $form->get_changes();
146
-
147
-		// Only update the post when the post data changes.
148
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
149
-			$post_data = array(
150
-				'post_date'         => $form->get_date_created( 'edit' ),
151
-				'post_status'       => $form->get_status( 'edit' ),
152
-				'post_title'        => $form->get_name( 'edit' ),
153
-				'post_author'       => $form->get_author( 'edit' ),
154
-				'post_modified'     => $form->get_date_modified( 'edit' ),
155
-			);
156
-
157
-			/**
158
-			 * When updating this object, to prevent infinite loops, use $wpdb
159
-			 * to update data, since wp_update_post spawns more calls to the
160
-			 * save_post action.
161
-			 *
162
-			 * This ensures hooks are fired by either WP itself (admin screen save),
163
-			 * or an update purely from CRUD.
164
-			 */
165
-			if ( doing_action( 'save_post' ) ) {
166
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
167
-				clean_post_cache( $form->get_id() );
168
-			} else {
169
-				wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
170
-			}
171
-			$form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
172
-		}
173
-		$this->update_post_meta( $form );
174
-		$form->apply_changes();
175
-		$this->clear_caches( $form );
176
-
177
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
178
-		$new_status = $form->get_status( 'edit' );
179
-
180
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
181
-			do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
182
-		} else {
183
-			do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
184
-		}
185
-
186
-	}
187
-
188
-	/*
54
+    /**
55
+     * Method to create a new form in the database.
56
+     *
57
+     * @param GetPaid_Payment_Form $form Form object.
58
+     */
59
+    public function create( &$form ) {
60
+        $form->set_version( WPINV_VERSION );
61
+        $form->set_date_created( current_time('mysql') );
62
+
63
+        // Create a new post.
64
+        $id = wp_insert_post(
65
+            apply_filters(
66
+                'getpaid_new_payment_form_data',
67
+                array(
68
+                    'post_date'     => $form->get_date_created( 'edit' ),
69
+                    'post_type'     => 'wpi_payment_form',
70
+                    'post_status'   => $this->get_post_status( $form ),
71
+                    'ping_status'   => 'closed',
72
+                    'post_author'   => $form->get_author( 'edit' ),
73
+                    'post_title'    => $form->get_name( 'edit' ),
74
+                )
75
+            ),
76
+            true
77
+        );
78
+
79
+        if ( $id && ! is_wp_error( $id ) ) {
80
+            $form->set_id( $id );
81
+            $this->update_post_meta( $form );
82
+            $form->save_meta_data();
83
+            $form->apply_changes();
84
+            $this->clear_caches( $form );
85
+            do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
86
+            return true;
87
+        }
88
+
89
+        if ( is_wp_error( $id ) ) {
90
+            $form->last_error = $id->get_error_message();
91
+        }
92
+
93
+        return false;
94
+    }
95
+
96
+    /**
97
+     * Method to read a form from the database.
98
+     *
99
+     * @param GetPaid_Payment_Form $form Form object.
100
+     *
101
+     */
102
+    public function read( &$form ) {
103
+
104
+        $form->set_defaults();
105
+        $form_object = get_post( $form->get_id() );
106
+
107
+        if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
+            $form->last_error = __( 'Invalid form.', 'invoicing' );
109
+            return false;
110
+        }
111
+
112
+        $form->set_props(
113
+            array(
114
+                'date_created'  => 0 < $form_object->post_date ? $form_object->post_date : null,
115
+                'date_modified' => 0 < $form_object->post_modified ? $form_object->post_modified : null,
116
+                'status'        => $form_object->post_status,
117
+                'name'          => $form_object->post_title,
118
+                'author'        => $form_object->post_author,
119
+            )
120
+        );
121
+
122
+        $this->read_object_data( $form, $form_object );
123
+        $form->read_meta_data();
124
+        $form->set_object_read( true );
125
+        do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
126
+
127
+    }
128
+
129
+    /**
130
+     * Method to update a form in the database.
131
+     *
132
+     * @param GetPaid_Payment_Form $form Form object.
133
+     */
134
+    public function update( &$form ) {
135
+        $form->save_meta_data();
136
+        $form->set_version( WPINV_VERSION );
137
+
138
+        if ( null === $form->get_date_created( 'edit' ) ) {
139
+            $form->set_date_created(  current_time('mysql') );
140
+        }
141
+
142
+        // Grab the current status so we can compare.
143
+        $previous_status = get_post_status( $form->get_id() );
144
+
145
+        $changes = $form->get_changes();
146
+
147
+        // Only update the post when the post data changes.
148
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
149
+            $post_data = array(
150
+                'post_date'         => $form->get_date_created( 'edit' ),
151
+                'post_status'       => $form->get_status( 'edit' ),
152
+                'post_title'        => $form->get_name( 'edit' ),
153
+                'post_author'       => $form->get_author( 'edit' ),
154
+                'post_modified'     => $form->get_date_modified( 'edit' ),
155
+            );
156
+
157
+            /**
158
+             * When updating this object, to prevent infinite loops, use $wpdb
159
+             * to update data, since wp_update_post spawns more calls to the
160
+             * save_post action.
161
+             *
162
+             * This ensures hooks are fired by either WP itself (admin screen save),
163
+             * or an update purely from CRUD.
164
+             */
165
+            if ( doing_action( 'save_post' ) ) {
166
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
167
+                clean_post_cache( $form->get_id() );
168
+            } else {
169
+                wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
170
+            }
171
+            $form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
172
+        }
173
+        $this->update_post_meta( $form );
174
+        $form->apply_changes();
175
+        $this->clear_caches( $form );
176
+
177
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
178
+        $new_status = $form->get_status( 'edit' );
179
+
180
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
181
+            do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
182
+        } else {
183
+            do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
184
+        }
185
+
186
+    }
187
+
188
+    /*
189 189
 	|--------------------------------------------------------------------------
190 190
 	| Additional Methods
191 191
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Payment_Form_Data_Store class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -56,37 +56,37 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @param GetPaid_Payment_Form $form Form object.
58 58
 	 */
59
-	public function create( &$form ) {
60
-		$form->set_version( WPINV_VERSION );
61
-		$form->set_date_created( current_time('mysql') );
59
+	public function create(&$form) {
60
+		$form->set_version(WPINV_VERSION);
61
+		$form->set_date_created(current_time('mysql'));
62 62
 
63 63
 		// Create a new post.
64 64
 		$id = wp_insert_post(
65 65
 			apply_filters(
66 66
 				'getpaid_new_payment_form_data',
67 67
 				array(
68
-					'post_date'     => $form->get_date_created( 'edit' ),
68
+					'post_date'     => $form->get_date_created('edit'),
69 69
 					'post_type'     => 'wpi_payment_form',
70
-					'post_status'   => $this->get_post_status( $form ),
70
+					'post_status'   => $this->get_post_status($form),
71 71
 					'ping_status'   => 'closed',
72
-					'post_author'   => $form->get_author( 'edit' ),
73
-					'post_title'    => $form->get_name( 'edit' ),
72
+					'post_author'   => $form->get_author('edit'),
73
+					'post_title'    => $form->get_name('edit'),
74 74
 				)
75 75
 			),
76 76
 			true
77 77
 		);
78 78
 
79
-		if ( $id && ! is_wp_error( $id ) ) {
80
-			$form->set_id( $id );
81
-			$this->update_post_meta( $form );
79
+		if ($id && !is_wp_error($id)) {
80
+			$form->set_id($id);
81
+			$this->update_post_meta($form);
82 82
 			$form->save_meta_data();
83 83
 			$form->apply_changes();
84
-			$this->clear_caches( $form );
85
-			do_action( 'getpaid_create_payment_form', $form->get_id(), $form );
84
+			$this->clear_caches($form);
85
+			do_action('getpaid_create_payment_form', $form->get_id(), $form);
86 86
 			return true;
87 87
 		}
88 88
 
89
-		if ( is_wp_error( $id ) ) {
89
+		if (is_wp_error($id)) {
90 90
 			$form->last_error = $id->get_error_message();
91 91
 		}
92 92
 
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
 	 * @param GetPaid_Payment_Form $form Form object.
100 100
 	 *
101 101
 	 */
102
-	public function read( &$form ) {
102
+	public function read(&$form) {
103 103
 
104 104
 		$form->set_defaults();
105
-		$form_object = get_post( $form->get_id() );
105
+		$form_object = get_post($form->get_id());
106 106
 
107
-		if ( ! $form->get_id() || ! $form_object || $form_object->post_type != 'wpi_payment_form' ) {
108
-			$form->last_error = __( 'Invalid form.', 'invoicing' );
107
+		if (!$form->get_id() || !$form_object || $form_object->post_type != 'wpi_payment_form') {
108
+			$form->last_error = __('Invalid form.', 'invoicing');
109 109
 			return false;
110 110
 		}
111 111
 
@@ -119,10 +119,10 @@  discard block
 block discarded – undo
119 119
 			)
120 120
 		);
121 121
 
122
-		$this->read_object_data( $form, $form_object );
122
+		$this->read_object_data($form, $form_object);
123 123
 		$form->read_meta_data();
124
-		$form->set_object_read( true );
125
-		do_action( 'getpaid_read_payment_form', $form->get_id(), $form );
124
+		$form->set_object_read(true);
125
+		do_action('getpaid_read_payment_form', $form->get_id(), $form);
126 126
 
127 127
 	}
128 128
 
@@ -131,27 +131,27 @@  discard block
 block discarded – undo
131 131
 	 *
132 132
 	 * @param GetPaid_Payment_Form $form Form object.
133 133
 	 */
134
-	public function update( &$form ) {
134
+	public function update(&$form) {
135 135
 		$form->save_meta_data();
136
-		$form->set_version( WPINV_VERSION );
136
+		$form->set_version(WPINV_VERSION);
137 137
 
138
-		if ( null === $form->get_date_created( 'edit' ) ) {
139
-			$form->set_date_created(  current_time('mysql') );
138
+		if (null === $form->get_date_created('edit')) {
139
+			$form->set_date_created(current_time('mysql'));
140 140
 		}
141 141
 
142 142
 		// Grab the current status so we can compare.
143
-		$previous_status = get_post_status( $form->get_id() );
143
+		$previous_status = get_post_status($form->get_id());
144 144
 
145 145
 		$changes = $form->get_changes();
146 146
 
147 147
 		// Only update the post when the post data changes.
148
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author' ), array_keys( $changes ) ) ) {
148
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author'), array_keys($changes))) {
149 149
 			$post_data = array(
150
-				'post_date'         => $form->get_date_created( 'edit' ),
151
-				'post_status'       => $form->get_status( 'edit' ),
152
-				'post_title'        => $form->get_name( 'edit' ),
153
-				'post_author'       => $form->get_author( 'edit' ),
154
-				'post_modified'     => $form->get_date_modified( 'edit' ),
150
+				'post_date'         => $form->get_date_created('edit'),
151
+				'post_status'       => $form->get_status('edit'),
152
+				'post_title'        => $form->get_name('edit'),
153
+				'post_author'       => $form->get_author('edit'),
154
+				'post_modified'     => $form->get_date_modified('edit'),
155 155
 			);
156 156
 
157 157
 			/**
@@ -162,25 +162,25 @@  discard block
 block discarded – undo
162 162
 			 * This ensures hooks are fired by either WP itself (admin screen save),
163 163
 			 * or an update purely from CRUD.
164 164
 			 */
165
-			if ( doing_action( 'save_post' ) ) {
166
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $form->get_id() ) );
167
-				clean_post_cache( $form->get_id() );
165
+			if (doing_action('save_post')) {
166
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $form->get_id()));
167
+				clean_post_cache($form->get_id());
168 168
 			} else {
169
-				wp_update_post( array_merge( array( 'ID' => $form->get_id() ), $post_data ) );
169
+				wp_update_post(array_merge(array('ID' => $form->get_id()), $post_data));
170 170
 			}
171
-			$form->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
171
+			$form->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
172 172
 		}
173
-		$this->update_post_meta( $form );
173
+		$this->update_post_meta($form);
174 174
 		$form->apply_changes();
175
-		$this->clear_caches( $form );
175
+		$this->clear_caches($form);
176 176
 
177 177
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
178
-		$new_status = $form->get_status( 'edit' );
178
+		$new_status = $form->get_status('edit');
179 179
 
180
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
181
-			do_action( 'getpaid_new_payment_form', $form->get_id(), $form );
180
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
181
+			do_action('getpaid_new_payment_form', $form->get_id(), $form);
182 182
 		} else {
183
-			do_action( 'getpaid_update_payment_form', $form->get_id(), $form );
183
+			do_action('getpaid_update_payment_form', $form->get_id(), $form);
184 184
 		}
185 185
 
186 186
 	}
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-item-data-store.php 2 patches
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,227 +14,227 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Item_Data_Store extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Data stored in meta keys, but not considered "meta" for an item.
19
-	 *
20
-	 * @since 1.0.19
21
-	 * @var array
22
-	 */
23
-	protected $internal_meta_keys = array(
24
-		'_wpinv_price',
25
-		'_wpinv_vat_rule',
26
-		'_wpinv_vat_class',
27
-		'_wpinv_type',
28
-		'_wpinv_custom_id',
29
-		'_wpinv_custom_name',
30
-		'_wpinv_custom_singular_name',
31
-		'_wpinv_editable',
32
-		'_wpinv_dynamic_pricing',
33
-		'_minimum_price',
34
-		'_wpinv_is_recurring',
35
-		'_wpinv_recurring_period',
36
-		'_wpinv_recurring_interval',
37
-		'_wpinv_recurring_limit',
38
-		'_wpinv_free_trial',
39
-		'_wpinv_trial_period',
40
-		'_wpinv_trial_interval'
41
-	);
42
-
43
-	/**
44
-	 * A map of meta keys to data props.
45
-	 *
46
-	 * @since 1.0.19
47
-	 *
48
-	 * @var array
49
-	 */
50
-	protected $meta_key_to_props = array(
51
-		'_wpinv_price'                => 'price',
52
-		'_wpinv_vat_rule'             => 'vat_rule',
53
-		'_wpinv_vat_class'            => 'vat_class',
54
-		'_wpinv_type'                 => 'type',
55
-		'_wpinv_custom_id'            => 'custom_id',
56
-		'_wpinv_custom_name'          => 'custom_name',
57
-		'_wpinv_custom_singular_name' => 'custom_singular_name',
58
-		'_wpinv_editable'             => 'is_editable',
59
-		'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
-		'_minimum_price'              => 'minimum_price',
61
-		'_wpinv_custom_name'          => 'custom_name',
62
-		'_wpinv_is_recurring'         => 'is_recurring',
63
-		'_wpinv_recurring_period'     => 'recurring_period',
64
-		'_wpinv_recurring_interval'   => 'recurring_interval',
65
-		'_wpinv_recurring_limit'      => 'recurring_limit',
66
-		'_wpinv_free_trial'           => 'is_free_trial',
67
-		'_wpinv_trial_period'         => 'trial_period',
68
-		'_wpinv_trial_interval'       => 'trial_interval',
69
-		'_wpinv_version'              => 'version',
70
-	);
71
-
72
-	/*
17
+    /**
18
+     * Data stored in meta keys, but not considered "meta" for an item.
19
+     *
20
+     * @since 1.0.19
21
+     * @var array
22
+     */
23
+    protected $internal_meta_keys = array(
24
+        '_wpinv_price',
25
+        '_wpinv_vat_rule',
26
+        '_wpinv_vat_class',
27
+        '_wpinv_type',
28
+        '_wpinv_custom_id',
29
+        '_wpinv_custom_name',
30
+        '_wpinv_custom_singular_name',
31
+        '_wpinv_editable',
32
+        '_wpinv_dynamic_pricing',
33
+        '_minimum_price',
34
+        '_wpinv_is_recurring',
35
+        '_wpinv_recurring_period',
36
+        '_wpinv_recurring_interval',
37
+        '_wpinv_recurring_limit',
38
+        '_wpinv_free_trial',
39
+        '_wpinv_trial_period',
40
+        '_wpinv_trial_interval'
41
+    );
42
+
43
+    /**
44
+     * A map of meta keys to data props.
45
+     *
46
+     * @since 1.0.19
47
+     *
48
+     * @var array
49
+     */
50
+    protected $meta_key_to_props = array(
51
+        '_wpinv_price'                => 'price',
52
+        '_wpinv_vat_rule'             => 'vat_rule',
53
+        '_wpinv_vat_class'            => 'vat_class',
54
+        '_wpinv_type'                 => 'type',
55
+        '_wpinv_custom_id'            => 'custom_id',
56
+        '_wpinv_custom_name'          => 'custom_name',
57
+        '_wpinv_custom_singular_name' => 'custom_singular_name',
58
+        '_wpinv_editable'             => 'is_editable',
59
+        '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
60
+        '_minimum_price'              => 'minimum_price',
61
+        '_wpinv_custom_name'          => 'custom_name',
62
+        '_wpinv_is_recurring'         => 'is_recurring',
63
+        '_wpinv_recurring_period'     => 'recurring_period',
64
+        '_wpinv_recurring_interval'   => 'recurring_interval',
65
+        '_wpinv_recurring_limit'      => 'recurring_limit',
66
+        '_wpinv_free_trial'           => 'is_free_trial',
67
+        '_wpinv_trial_period'         => 'trial_period',
68
+        '_wpinv_trial_interval'       => 'trial_interval',
69
+        '_wpinv_version'              => 'version',
70
+    );
71
+
72
+    /*
73 73
 	|--------------------------------------------------------------------------
74 74
 	| CRUD Methods
75 75
 	|--------------------------------------------------------------------------
76 76
 	*/
77 77
 
78
-	/**
79
-	 * Method to create a new item in the database.
80
-	 *
81
-	 * @param WPInv_Item $item Item object.
82
-	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time('mysql') );
86
-
87
-		// Create a new post.
88
-		$id = wp_insert_post(
89
-			apply_filters(
90
-				'getpaid_new_item_data',
91
-				array(
92
-					'post_date'     => $item->get_date_created( 'edit' ),
93
-					'post_type'     => 'wpi_item',
94
-					'post_status'   => $this->get_post_status( $item ),
95
-					'ping_status'   => 'closed',
96
-					'post_author'   => $item->get_author( 'edit' ),
97
-					'post_title'    => $item->get_name( 'edit' ),
98
-					'post_parent'   => 0,
99
-					'post_excerpt'  => $item->get_description( 'edit' ),
100
-				)
101
-			),
102
-			true
103
-		);
104
-
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
108
-			$item->save_meta_data();
109
-			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
112
-			return true;
113
-		}
114
-
115
-		if ( is_wp_error( $id ) ) {
116
-			$item->last_error = $id->get_error_message();
117
-		}
78
+    /**
79
+     * Method to create a new item in the database.
80
+     *
81
+     * @param WPInv_Item $item Item object.
82
+     */
83
+    public function create( &$item ) {
84
+        $item->set_version( WPINV_VERSION );
85
+        $item->set_date_created( current_time('mysql') );
86
+
87
+        // Create a new post.
88
+        $id = wp_insert_post(
89
+            apply_filters(
90
+                'getpaid_new_item_data',
91
+                array(
92
+                    'post_date'     => $item->get_date_created( 'edit' ),
93
+                    'post_type'     => 'wpi_item',
94
+                    'post_status'   => $this->get_post_status( $item ),
95
+                    'ping_status'   => 'closed',
96
+                    'post_author'   => $item->get_author( 'edit' ),
97
+                    'post_title'    => $item->get_name( 'edit' ),
98
+                    'post_parent'   => 0,
99
+                    'post_excerpt'  => $item->get_description( 'edit' ),
100
+                )
101
+            ),
102
+            true
103
+        );
104
+
105
+        if ( $id && ! is_wp_error( $id ) ) {
106
+            $item->set_id( $id );
107
+            $this->update_post_meta( $item );
108
+            $item->save_meta_data();
109
+            $item->apply_changes();
110
+            $this->clear_caches( $item );
111
+            do_action( 'getpaid_new_item', $item->get_id(), $item );
112
+            return true;
113
+        }
114
+
115
+        if ( is_wp_error( $id ) ) {
116
+            $item->last_error = $id->get_error_message();
117
+        }
118 118
 		
119
-		return false;
120
-	}
121
-
122
-	/**
123
-	 * Method to read an item from the database.
124
-	 *
125
-	 * @param WPInv_Item $item Item object.
126
-	 *
127
-	 */
128
-	public function read( &$item ) {
129
-
130
-		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
132
-
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
135
-			return false;
136
-		}
137
-
138
-		$item->set_props(
139
-			array(
140
-				'parent_id'     => $item_object->post_parent,
141
-				'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
142
-				'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
143
-				'status'        => $item_object->post_status,
144
-				'name'          => $item_object->post_title,
145
-				'description'   => $item_object->post_excerpt,
146
-				'author'        => $item_object->post_author,
147
-			)
148
-		);
149
-
150
-		$this->read_object_data( $item, $item_object );
151
-		$item->read_meta_data();
152
-		$item->set_object_read( true );
153
-		do_action( 'getpaid_read_item', $item->get_id(), $item );
154
-
155
-	}
156
-
157
-	/**
158
-	 * Method to update an item in the database.
159
-	 *
160
-	 * @param WPInv_Item $item Item object.
161
-	 */
162
-	public function update( &$item ) {
163
-		$item->save_meta_data();
164
-		$item->set_version( WPINV_VERSION );
165
-
166
-		if ( null === $item->get_date_created( 'edit' ) ) {
167
-			$item->set_date_created(  current_time('mysql') );
168
-		}
169
-
170
-		// Grab the current status so we can compare.
171
-		$previous_status = get_post_status( $item->get_id() );
172
-
173
-		$changes = $item->get_changes();
174
-
175
-		// Only update the post when the post data changes.
176
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
177
-			$post_data = array(
178
-				'post_date'         => $item->get_date_created( 'edit' ),
179
-				'post_status'       => $item->get_status( 'edit' ),
180
-				'post_parent'       => $item->get_parent_id( 'edit' ),
181
-				'post_excerpt'      => $item->get_description( 'edit' ),
182
-				'post_modified'     => $item->get_date_modified( 'edit' ),
183
-				'post_title'        => $item->get_name( 'edit' ),
184
-				'post_author'       => $item->get_author( 'edit' ),
185
-			);
186
-
187
-			/**
188
-			 * When updating this object, to prevent infinite loops, use $wpdb
189
-			 * to update data, since wp_update_post spawns more calls to the
190
-			 * save_post action.
191
-			 *
192
-			 * This ensures hooks are fired by either WP itself (admin screen save),
193
-			 * or an update purely from CRUD.
194
-			 */
195
-			if ( doing_action( 'save_post' ) ) {
196
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
197
-				clean_post_cache( $item->get_id() );
198
-			} else {
199
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
200
-			}
201
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202
-		}
203
-		$this->update_post_meta( $item );
204
-		$item->apply_changes();
205
-		$this->clear_caches( $item );
206
-
207
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
208
-		$new_status = $item->get_status( 'edit' );
209
-
210
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
211
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
212
-		} else {
213
-			do_action( 'getpaid_update_item', $item->get_id(), $item );
214
-		}
215
-
216
-	}
217
-
218
-	/*
119
+        return false;
120
+    }
121
+
122
+    /**
123
+     * Method to read an item from the database.
124
+     *
125
+     * @param WPInv_Item $item Item object.
126
+     *
127
+     */
128
+    public function read( &$item ) {
129
+
130
+        $item->set_defaults();
131
+        $item_object = get_post( $item->get_id() );
132
+
133
+        if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
+            $item->last_error = __( 'Invalid item.', 'invoicing' );
135
+            return false;
136
+        }
137
+
138
+        $item->set_props(
139
+            array(
140
+                'parent_id'     => $item_object->post_parent,
141
+                'date_created'  => 0 < $item_object->post_date ? $item_object->post_date : null,
142
+                'date_modified' => 0 < $item_object->post_modified ? $item_object->post_modified : null,
143
+                'status'        => $item_object->post_status,
144
+                'name'          => $item_object->post_title,
145
+                'description'   => $item_object->post_excerpt,
146
+                'author'        => $item_object->post_author,
147
+            )
148
+        );
149
+
150
+        $this->read_object_data( $item, $item_object );
151
+        $item->read_meta_data();
152
+        $item->set_object_read( true );
153
+        do_action( 'getpaid_read_item', $item->get_id(), $item );
154
+
155
+    }
156
+
157
+    /**
158
+     * Method to update an item in the database.
159
+     *
160
+     * @param WPInv_Item $item Item object.
161
+     */
162
+    public function update( &$item ) {
163
+        $item->save_meta_data();
164
+        $item->set_version( WPINV_VERSION );
165
+
166
+        if ( null === $item->get_date_created( 'edit' ) ) {
167
+            $item->set_date_created(  current_time('mysql') );
168
+        }
169
+
170
+        // Grab the current status so we can compare.
171
+        $previous_status = get_post_status( $item->get_id() );
172
+
173
+        $changes = $item->get_changes();
174
+
175
+        // Only update the post when the post data changes.
176
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
177
+            $post_data = array(
178
+                'post_date'         => $item->get_date_created( 'edit' ),
179
+                'post_status'       => $item->get_status( 'edit' ),
180
+                'post_parent'       => $item->get_parent_id( 'edit' ),
181
+                'post_excerpt'      => $item->get_description( 'edit' ),
182
+                'post_modified'     => $item->get_date_modified( 'edit' ),
183
+                'post_title'        => $item->get_name( 'edit' ),
184
+                'post_author'       => $item->get_author( 'edit' ),
185
+            );
186
+
187
+            /**
188
+             * When updating this object, to prevent infinite loops, use $wpdb
189
+             * to update data, since wp_update_post spawns more calls to the
190
+             * save_post action.
191
+             *
192
+             * This ensures hooks are fired by either WP itself (admin screen save),
193
+             * or an update purely from CRUD.
194
+             */
195
+            if ( doing_action( 'save_post' ) ) {
196
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
197
+                clean_post_cache( $item->get_id() );
198
+            } else {
199
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
200
+            }
201
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202
+        }
203
+        $this->update_post_meta( $item );
204
+        $item->apply_changes();
205
+        $this->clear_caches( $item );
206
+
207
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
208
+        $new_status = $item->get_status( 'edit' );
209
+
210
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
211
+            do_action( 'getpaid_new_item', $item->get_id(), $item );
212
+        } else {
213
+            do_action( 'getpaid_update_item', $item->get_id(), $item );
214
+        }
215
+
216
+    }
217
+
218
+    /*
219 219
 	|--------------------------------------------------------------------------
220 220
 	| Additional Methods
221 221
 	|--------------------------------------------------------------------------
222 222
 	*/
223 223
 
224
-	/**
225
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
226
-	 *
227
-	 * @param WPInv_Item $item WPInv_Item object.
228
-	 * @since 1.0.19
229
-	 */
230
-	protected function update_post_meta( &$item ) {
224
+    /**
225
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
226
+     *
227
+     * @param WPInv_Item $item WPInv_Item object.
228
+     * @since 1.0.19
229
+     */
230
+    protected function update_post_meta( &$item ) {
231 231
 
232
-		// Ensure that we have a custom id.
232
+        // Ensure that we have a custom id.
233 233
         if ( ! $item->get_custom_id() ) {
234 234
             $item->set_custom_id( $item->get_id() );
235
-		}
235
+        }
236 236
 
237
-		parent::update_post_meta( $item );
238
-	}
237
+        parent::update_post_meta( $item );
238
+    }
239 239
 
240 240
 }
Please login to merge, or discard this patch.
Spacing   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Item_Data_Store class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -80,39 +80,39 @@  discard block
 block discarded – undo
80 80
 	 *
81 81
 	 * @param WPInv_Item $item Item object.
82 82
 	 */
83
-	public function create( &$item ) {
84
-		$item->set_version( WPINV_VERSION );
85
-		$item->set_date_created( current_time('mysql') );
83
+	public function create(&$item) {
84
+		$item->set_version(WPINV_VERSION);
85
+		$item->set_date_created(current_time('mysql'));
86 86
 
87 87
 		// Create a new post.
88 88
 		$id = wp_insert_post(
89 89
 			apply_filters(
90 90
 				'getpaid_new_item_data',
91 91
 				array(
92
-					'post_date'     => $item->get_date_created( 'edit' ),
92
+					'post_date'     => $item->get_date_created('edit'),
93 93
 					'post_type'     => 'wpi_item',
94
-					'post_status'   => $this->get_post_status( $item ),
94
+					'post_status'   => $this->get_post_status($item),
95 95
 					'ping_status'   => 'closed',
96
-					'post_author'   => $item->get_author( 'edit' ),
97
-					'post_title'    => $item->get_name( 'edit' ),
96
+					'post_author'   => $item->get_author('edit'),
97
+					'post_title'    => $item->get_name('edit'),
98 98
 					'post_parent'   => 0,
99
-					'post_excerpt'  => $item->get_description( 'edit' ),
99
+					'post_excerpt'  => $item->get_description('edit'),
100 100
 				)
101 101
 			),
102 102
 			true
103 103
 		);
104 104
 
105
-		if ( $id && ! is_wp_error( $id ) ) {
106
-			$item->set_id( $id );
107
-			$this->update_post_meta( $item );
105
+		if ($id && !is_wp_error($id)) {
106
+			$item->set_id($id);
107
+			$this->update_post_meta($item);
108 108
 			$item->save_meta_data();
109 109
 			$item->apply_changes();
110
-			$this->clear_caches( $item );
111
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
110
+			$this->clear_caches($item);
111
+			do_action('getpaid_new_item', $item->get_id(), $item);
112 112
 			return true;
113 113
 		}
114 114
 
115
-		if ( is_wp_error( $id ) ) {
115
+		if (is_wp_error($id)) {
116 116
 			$item->last_error = $id->get_error_message();
117 117
 		}
118 118
 		
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 * @param WPInv_Item $item Item object.
126 126
 	 *
127 127
 	 */
128
-	public function read( &$item ) {
128
+	public function read(&$item) {
129 129
 
130 130
 		$item->set_defaults();
131
-		$item_object = get_post( $item->get_id() );
131
+		$item_object = get_post($item->get_id());
132 132
 
133
-		if ( ! $item->get_id() || ! $item_object || $item_object->post_type != 'wpi_item' ) {
134
-			$item->last_error = __( 'Invalid item.', 'invoicing' );
133
+		if (!$item->get_id() || !$item_object || $item_object->post_type != 'wpi_item') {
134
+			$item->last_error = __('Invalid item.', 'invoicing');
135 135
 			return false;
136 136
 		}
137 137
 
@@ -147,10 +147,10 @@  discard block
 block discarded – undo
147 147
 			)
148 148
 		);
149 149
 
150
-		$this->read_object_data( $item, $item_object );
150
+		$this->read_object_data($item, $item_object);
151 151
 		$item->read_meta_data();
152
-		$item->set_object_read( true );
153
-		do_action( 'getpaid_read_item', $item->get_id(), $item );
152
+		$item->set_object_read(true);
153
+		do_action('getpaid_read_item', $item->get_id(), $item);
154 154
 
155 155
 	}
156 156
 
@@ -159,29 +159,29 @@  discard block
 block discarded – undo
159 159
 	 *
160 160
 	 * @param WPInv_Item $item Item object.
161 161
 	 */
162
-	public function update( &$item ) {
162
+	public function update(&$item) {
163 163
 		$item->save_meta_data();
164
-		$item->set_version( WPINV_VERSION );
164
+		$item->set_version(WPINV_VERSION);
165 165
 
166
-		if ( null === $item->get_date_created( 'edit' ) ) {
167
-			$item->set_date_created(  current_time('mysql') );
166
+		if (null === $item->get_date_created('edit')) {
167
+			$item->set_date_created(current_time('mysql'));
168 168
 		}
169 169
 
170 170
 		// Grab the current status so we can compare.
171
-		$previous_status = get_post_status( $item->get_id() );
171
+		$previous_status = get_post_status($item->get_id());
172 172
 
173 173
 		$changes = $item->get_changes();
174 174
 
175 175
 		// Only update the post when the post data changes.
176
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author' ), array_keys( $changes ) ) ) {
176
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt', 'name', 'author'), array_keys($changes))) {
177 177
 			$post_data = array(
178
-				'post_date'         => $item->get_date_created( 'edit' ),
179
-				'post_status'       => $item->get_status( 'edit' ),
180
-				'post_parent'       => $item->get_parent_id( 'edit' ),
181
-				'post_excerpt'      => $item->get_description( 'edit' ),
182
-				'post_modified'     => $item->get_date_modified( 'edit' ),
183
-				'post_title'        => $item->get_name( 'edit' ),
184
-				'post_author'       => $item->get_author( 'edit' ),
178
+				'post_date'         => $item->get_date_created('edit'),
179
+				'post_status'       => $item->get_status('edit'),
180
+				'post_parent'       => $item->get_parent_id('edit'),
181
+				'post_excerpt'      => $item->get_description('edit'),
182
+				'post_modified'     => $item->get_date_modified('edit'),
183
+				'post_title'        => $item->get_name('edit'),
184
+				'post_author'       => $item->get_author('edit'),
185 185
 			);
186 186
 
187 187
 			/**
@@ -192,25 +192,25 @@  discard block
 block discarded – undo
192 192
 			 * This ensures hooks are fired by either WP itself (admin screen save),
193 193
 			 * or an update purely from CRUD.
194 194
 			 */
195
-			if ( doing_action( 'save_post' ) ) {
196
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
197
-				clean_post_cache( $item->get_id() );
195
+			if (doing_action('save_post')) {
196
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id()));
197
+				clean_post_cache($item->get_id());
198 198
 			} else {
199
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
199
+				wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data));
200 200
 			}
201
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
201
+			$item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
202 202
 		}
203
-		$this->update_post_meta( $item );
203
+		$this->update_post_meta($item);
204 204
 		$item->apply_changes();
205
-		$this->clear_caches( $item );
205
+		$this->clear_caches($item);
206 206
 
207 207
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
208
-		$new_status = $item->get_status( 'edit' );
208
+		$new_status = $item->get_status('edit');
209 209
 
210
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
211
-			do_action( 'getpaid_new_item', $item->get_id(), $item );
210
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
211
+			do_action('getpaid_new_item', $item->get_id(), $item);
212 212
 		} else {
213
-			do_action( 'getpaid_update_item', $item->get_id(), $item );
213
+			do_action('getpaid_update_item', $item->get_id(), $item);
214 214
 		}
215 215
 
216 216
 	}
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 	 * @param WPInv_Item $item WPInv_Item object.
228 228
 	 * @since 1.0.19
229 229
 	 */
230
-	protected function update_post_meta( &$item ) {
230
+	protected function update_post_meta(&$item) {
231 231
 
232 232
 		// Ensure that we have a custom id.
233
-        if ( ! $item->get_custom_id() ) {
234
-            $item->set_custom_id( $item->get_id() );
233
+        if (!$item->get_custom_id()) {
234
+            $item->set_custom_id($item->get_id());
235 235
 		}
236 236
 
237
-		parent::update_post_meta( $item );
237
+		parent::update_post_meta($item);
238 238
 	}
239 239
 
240 240
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store-wp.php 2 patches
Indentation   +338 added lines, -338 removed lines patch added patch discarded remove patch
@@ -14,346 +14,346 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Meta type. This should match up with
19
-	 * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
20
-	 * WP defines 'post', 'user', 'comment', and 'term'.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $meta_type = 'post';
25
-
26
-	/**
27
-	 * This only needs set if you are using a custom metadata type.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	protected $object_id_field_for_meta = '';
32
-
33
-	/**
34
-	 * Data stored in meta keys, but not considered "meta" for an object.
35
-	 *
36
-	 * @since 1.0.19
37
-	 *
38
-	 * @var array
39
-	 */
40
-	protected $internal_meta_keys = array();
41
-
42
-	/**
43
-	 * Meta data which should exist in the DB, even if empty.
44
-	 *
45
-	 * @since 1.0.19
46
-	 *
47
-	 * @var array
48
-	 */
49
-	protected $must_exist_meta_keys = array();
50
-
51
-	/**
52
-	 * A map of meta keys to data props.
53
-	 *
54
-	 * @since 1.0.19
55
-	 *
56
-	 * @var array
57
-	 */
58
-	protected $meta_key_to_props = array();
59
-
60
-	/**
61
-	 * Returns an array of meta for an object.
62
-	 *
63
-	 * @since  1.0.19
64
-	 * @param  GetPaid_Data $object GetPaid_Data object.
65
-	 * @return array
66
-	 */
67
-	public function read_meta( &$object ) {
68
-		global $wpdb;
69
-		$db_info       = $this->get_db_info();
70
-		$raw_meta_data = $wpdb->get_results(
71
-			$wpdb->prepare(
72
-				"SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
17
+    /**
18
+     * Meta type. This should match up with
19
+     * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
20
+     * WP defines 'post', 'user', 'comment', and 'term'.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $meta_type = 'post';
25
+
26
+    /**
27
+     * This only needs set if you are using a custom metadata type.
28
+     *
29
+     * @var string
30
+     */
31
+    protected $object_id_field_for_meta = '';
32
+
33
+    /**
34
+     * Data stored in meta keys, but not considered "meta" for an object.
35
+     *
36
+     * @since 1.0.19
37
+     *
38
+     * @var array
39
+     */
40
+    protected $internal_meta_keys = array();
41
+
42
+    /**
43
+     * Meta data which should exist in the DB, even if empty.
44
+     *
45
+     * @since 1.0.19
46
+     *
47
+     * @var array
48
+     */
49
+    protected $must_exist_meta_keys = array();
50
+
51
+    /**
52
+     * A map of meta keys to data props.
53
+     *
54
+     * @since 1.0.19
55
+     *
56
+     * @var array
57
+     */
58
+    protected $meta_key_to_props = array();
59
+
60
+    /**
61
+     * Returns an array of meta for an object.
62
+     *
63
+     * @since  1.0.19
64
+     * @param  GetPaid_Data $object GetPaid_Data object.
65
+     * @return array
66
+     */
67
+    public function read_meta( &$object ) {
68
+        global $wpdb;
69
+        $db_info       = $this->get_db_info();
70
+        $raw_meta_data = $wpdb->get_results(
71
+            $wpdb->prepare(
72
+                "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
73 73
 				FROM {$db_info['table']}
74 74
 				WHERE {$db_info['object_id_field']} = %d
75 75
 				ORDER BY {$db_info['meta_id_field']}",
76
-				$object->get_id()
77
-			)
78
-		);
79
-
80
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
83
-	}
84
-
85
-	/**
86
-	 * Deletes meta based on meta ID.
87
-	 *
88
-	 * @since  1.0.19
89
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
90
-	 * @param  stdClass $meta (containing at least ->id).
91
-	 */
92
-	public function delete_meta( &$object, $meta ) {
93
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
94
-	}
95
-
96
-	/**
97
-	 * Add new piece of meta.
98
-	 *
99
-	 * @since  1.0.19
100
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
101
-	 * @param  stdClass $meta (containing ->key and ->value).
102
-	 * @return int meta ID
103
-	 */
104
-	public function add_meta( &$object, $meta ) {
105
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
106
-	}
107
-
108
-	/**
109
-	 * Update meta.
110
-	 *
111
-	 * @since  1.0.19
112
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
113
-	 * @param  stdClass $meta (containing ->id, ->key and ->value).
114
-	 */
115
-	public function update_meta( &$object, $meta ) {
116
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
117
-	}
118
-
119
-	/**
120
-	 * Table structure is slightly different between meta types, this function will return what we need to know.
121
-	 *
122
-	 * @since  1.0.19
123
-	 * @return array Array elements: table, object_id_field, meta_id_field
124
-	 */
125
-	protected function get_db_info() {
126
-		global $wpdb;
127
-
128
-		$meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well.
129
-		$table         = $wpdb->prefix;
130
-
131
-		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
133
-			$table .= 'getpaid_';
134
-		}
135
-
136
-		$table          .= $this->meta_type . 'meta';
137
-		$object_id_field = $this->meta_type . '_id';
138
-
139
-		// Figure out our field names.
140
-		if ( 'user' === $this->meta_type ) {
141
-			$meta_id_field = 'umeta_id';
142
-			$table         = $wpdb->usermeta;
143
-		}
144
-
145
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
146
-			$object_id_field = $this->object_id_field_for_meta;
147
-		}
148
-
149
-		return array(
150
-			'table'           => $table,
151
-			'object_id_field' => $object_id_field,
152
-			'meta_id_field'   => $meta_id_field,
153
-		);
154
-	}
155
-
156
-	/**
157
-	 * Internal meta keys we don't want exposed as part of meta_data. This is in
158
-	 * addition to all data props with _ prefix.
159
-	 *
160
-	 * @since 1.0.19
161
-	 *
162
-	 * @param string $key Prefix to be added to meta keys.
163
-	 * @return string
164
-	 */
165
-	protected function prefix_key( $key ) {
166
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
167
-	}
168
-
169
-	/**
170
-	 * Callback to remove unwanted meta data.
171
-	 *
172
-	 * @param object $meta Meta object to check if it should be excluded or not.
173
-	 * @return bool
174
-	 */
175
-	protected function exclude_internal_meta_keys( $meta ) {
176
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
177
-	}
178
-
179
-	/**
180
-	 * Gets a list of props and meta keys that need updated based on change state
181
-	 * or if they are present in the database or not.
182
-	 *
183
-	 * @param  GetPaid_Data $object         The GetPaid_Data object.
184
-	 * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
185
-	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186
-	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187
-	 */
188
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
189
-		$props_to_update = array();
190
-		$changed_props   = $object->get_changes();
191
-
192
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
193
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
-				$props_to_update[ $meta_key ] = $prop;
196
-			}
197
-		}
198
-
199
-		return $props_to_update;
200
-	}
201
-
202
-	/**
203
-	 * Read object data.
204
-	 *
205
-	 * @param GetPaid_Data $object GetPaid_Data object.
206
-	 * @param WP_Post   $post_object Post object.
207
-	 * @since 1.0.19
208
-	 */
209
-	protected function read_object_data( &$object, $post_object ) {
210
-		$id    = $object->get_id();
211
-		$props = array();
212
-
213
-		foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
-			$props[ $prop ] = get_post_meta( $id, $meta_key, true );
215
-		}
216
-
217
-		// Set object properties.
218
-		$object->set_props( $props );
219
-
220
-		// Gets extra data associated with the object if needed.
221
-		foreach ( $object->get_extra_data_keys() as $key ) {
222
-			$function = 'set_' . $key;
223
-			if ( is_callable( array( $object, $function ) ) ) {
224
-				$object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
225
-			}
226
-		}
227
-	}
228
-
229
-	/**
230
-	 * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class.
231
-	 *
232
-	 * @param GetPaid_Data $object GetPaid_Data object.
233
-	 * @since 1.0.19
234
-	 */
235
-	protected function update_post_meta( &$object ) {
236
-
237
-		$updated_props   = array();
238
-		$props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
239
-		$object_type     = $object->get_object_type();
240
-
241
-		foreach ( $props_to_update as $meta_key => $prop ) {
242
-			$value = $object->{"get_$prop"}( 'edit' );
243
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
244
-
245
-			$updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
246
-
247
-			if ( $updated ) {
248
-				$updated_props[] = $prop;
249
-			}
250
-		}
251
-
252
-		do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
253
-	}
254
-
255
-	/**
256
-	 * Update meta data in, or delete it from, the database.
257
-	 *
258
-	 * Avoids storing meta when it's either an empty string or empty array or null.
259
-	 * Other empty values such as numeric 0 should still be stored.
260
-	 * Data-stores can force meta to exist using `must_exist_meta_keys`.
261
-	 *
262
-	 * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
263
-	 *
264
-	 * @param GetPaid_Data $object The GetPaid_Data object.
265
-	 * @param string  $meta_key Meta key to update.
266
-	 * @param mixed   $meta_value Value to save.
267
-	 *
268
-	 * @since 1.0.19 Added to prevent empty meta being stored unless required.
269
-	 *
270
-	 * @return bool True if updated/deleted.
271
-	 */
272
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
275
-		} else {
276
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
277
-		}
278
-
279
-		return (bool) $updated;
280
-	}
281
-
282
-	/**
283
-	 * Return list of internal meta keys.
284
-	 *
285
-	 * @since 1.0.19
286
-	 * @return array
287
-	 */
288
-	public function get_internal_meta_keys() {
289
-		return $this->internal_meta_keys;
290
-	}
291
-
292
-	/**
293
-	 * Clear any caches.
294
-	 *
295
-	 * @param GetPaid_Data $object GetPaid_Data object.
296
-	 * @since 1.0.19
297
-	 */
298
-	protected function clear_caches( &$object ) {
299
-		clean_post_cache( $object->get_id() );
300
-	}
301
-
302
-	/**
303
-	 * Method to delete a data object from the database.
304
-	 *
305
-	 * @param GetPaid_Data $object GetPaid_Data object.
306
-	 * @param array    $args Array of args to pass to the delete method.
307
-	 *
308
-	 * @return void
309
-	 */
310
-	public function delete( &$object, $args = array() ) {
311
-		$id          = $object->get_id();
312
-		$object_type = $object->get_object_type();
313
-
314
-		if ( 'invoice' == $object_type ) {
315
-			$object_type = $object->get_type();
316
-		}
317
-
318
-		$args        = wp_parse_args(
319
-			$args,
320
-			array(
321
-				'force_delete' => false,
322
-			)
323
-		);
324
-
325
-		if ( ! $id ) {
326
-			return;
327
-		}
328
-
329
-		if ( $args['force_delete'] ) {
330
-			wp_delete_post( $id, true );
331
-			$object->set_id( 0 );
332
-			do_action( "getpaid_delete_$object_type", $id );
333
-		} else {
334
-			wp_trash_post( $id );
335
-			$object->set_status( 'trash' );
336
-			do_action( "getpaid_trash_$object_type", $id );
337
-		}
338
-	}
339
-
340
-	/**
341
-	 * Get the status to save to the post object.
342
-	 *
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  GetPaid_Data $object GetPaid_Data object.
346
-	 * @return string
347
-	 */
348
-	protected function get_post_status( $object ) {
349
-		$object_status = $object->get_status( 'edit' );
350
-		$object_type   = $object->get_object_type();
351
-
352
-		if ( ! $object_status ) {
353
-			$object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
354
-		}
355
-
356
-		return $object_status;
357
-	}
76
+                $object->get_id()
77
+            )
78
+        );
79
+
80
+        $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
+        $meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
+        return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
83
+    }
84
+
85
+    /**
86
+     * Deletes meta based on meta ID.
87
+     *
88
+     * @since  1.0.19
89
+     * @param  GetPaid_Data  $object GetPaid_Data object.
90
+     * @param  stdClass $meta (containing at least ->id).
91
+     */
92
+    public function delete_meta( &$object, $meta ) {
93
+        delete_metadata_by_mid( $this->meta_type, $meta->id );
94
+    }
95
+
96
+    /**
97
+     * Add new piece of meta.
98
+     *
99
+     * @since  1.0.19
100
+     * @param  GetPaid_Data  $object GetPaid_Data object.
101
+     * @param  stdClass $meta (containing ->key and ->value).
102
+     * @return int meta ID
103
+     */
104
+    public function add_meta( &$object, $meta ) {
105
+        return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
106
+    }
107
+
108
+    /**
109
+     * Update meta.
110
+     *
111
+     * @since  1.0.19
112
+     * @param  GetPaid_Data  $object GetPaid_Data object.
113
+     * @param  stdClass $meta (containing ->id, ->key and ->value).
114
+     */
115
+    public function update_meta( &$object, $meta ) {
116
+        update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
117
+    }
118
+
119
+    /**
120
+     * Table structure is slightly different between meta types, this function will return what we need to know.
121
+     *
122
+     * @since  1.0.19
123
+     * @return array Array elements: table, object_id_field, meta_id_field
124
+     */
125
+    protected function get_db_info() {
126
+        global $wpdb;
127
+
128
+        $meta_id_field = 'meta_id'; // users table calls this umeta_id so we need to track this as well.
129
+        $table         = $wpdb->prefix;
130
+
131
+        // If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
+        if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
133
+            $table .= 'getpaid_';
134
+        }
135
+
136
+        $table          .= $this->meta_type . 'meta';
137
+        $object_id_field = $this->meta_type . '_id';
138
+
139
+        // Figure out our field names.
140
+        if ( 'user' === $this->meta_type ) {
141
+            $meta_id_field = 'umeta_id';
142
+            $table         = $wpdb->usermeta;
143
+        }
144
+
145
+        if ( ! empty( $this->object_id_field_for_meta ) ) {
146
+            $object_id_field = $this->object_id_field_for_meta;
147
+        }
148
+
149
+        return array(
150
+            'table'           => $table,
151
+            'object_id_field' => $object_id_field,
152
+            'meta_id_field'   => $meta_id_field,
153
+        );
154
+    }
155
+
156
+    /**
157
+     * Internal meta keys we don't want exposed as part of meta_data. This is in
158
+     * addition to all data props with _ prefix.
159
+     *
160
+     * @since 1.0.19
161
+     *
162
+     * @param string $key Prefix to be added to meta keys.
163
+     * @return string
164
+     */
165
+    protected function prefix_key( $key ) {
166
+        return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
167
+    }
168
+
169
+    /**
170
+     * Callback to remove unwanted meta data.
171
+     *
172
+     * @param object $meta Meta object to check if it should be excluded or not.
173
+     * @return bool
174
+     */
175
+    protected function exclude_internal_meta_keys( $meta ) {
176
+        return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
177
+    }
178
+
179
+    /**
180
+     * Gets a list of props and meta keys that need updated based on change state
181
+     * or if they are present in the database or not.
182
+     *
183
+     * @param  GetPaid_Data $object         The GetPaid_Data object.
184
+     * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
185
+     * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186
+     * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187
+     */
188
+    protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
189
+        $props_to_update = array();
190
+        $changed_props   = $object->get_changes();
191
+
192
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
193
+        foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
+            if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
+                $props_to_update[ $meta_key ] = $prop;
196
+            }
197
+        }
198
+
199
+        return $props_to_update;
200
+    }
201
+
202
+    /**
203
+     * Read object data.
204
+     *
205
+     * @param GetPaid_Data $object GetPaid_Data object.
206
+     * @param WP_Post   $post_object Post object.
207
+     * @since 1.0.19
208
+     */
209
+    protected function read_object_data( &$object, $post_object ) {
210
+        $id    = $object->get_id();
211
+        $props = array();
212
+
213
+        foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
+            $props[ $prop ] = get_post_meta( $id, $meta_key, true );
215
+        }
216
+
217
+        // Set object properties.
218
+        $object->set_props( $props );
219
+
220
+        // Gets extra data associated with the object if needed.
221
+        foreach ( $object->get_extra_data_keys() as $key ) {
222
+            $function = 'set_' . $key;
223
+            if ( is_callable( array( $object, $function ) ) ) {
224
+                $object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
225
+            }
226
+        }
227
+    }
228
+
229
+    /**
230
+     * Helper method that updates all the post meta for an object based on it's settings in the GetPaid_Data class.
231
+     *
232
+     * @param GetPaid_Data $object GetPaid_Data object.
233
+     * @since 1.0.19
234
+     */
235
+    protected function update_post_meta( &$object ) {
236
+
237
+        $updated_props   = array();
238
+        $props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
239
+        $object_type     = $object->get_object_type();
240
+
241
+        foreach ( $props_to_update as $meta_key => $prop ) {
242
+            $value = $object->{"get_$prop"}( 'edit' );
243
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
244
+
245
+            $updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
246
+
247
+            if ( $updated ) {
248
+                $updated_props[] = $prop;
249
+            }
250
+        }
251
+
252
+        do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
253
+    }
254
+
255
+    /**
256
+     * Update meta data in, or delete it from, the database.
257
+     *
258
+     * Avoids storing meta when it's either an empty string or empty array or null.
259
+     * Other empty values such as numeric 0 should still be stored.
260
+     * Data-stores can force meta to exist using `must_exist_meta_keys`.
261
+     *
262
+     * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
263
+     *
264
+     * @param GetPaid_Data $object The GetPaid_Data object.
265
+     * @param string  $meta_key Meta key to update.
266
+     * @param mixed   $meta_value Value to save.
267
+     *
268
+     * @since 1.0.19 Added to prevent empty meta being stored unless required.
269
+     *
270
+     * @return bool True if updated/deleted.
271
+     */
272
+    protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
+        if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
+            $updated = delete_post_meta( $object->get_id(), $meta_key );
275
+        } else {
276
+            $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
277
+        }
278
+
279
+        return (bool) $updated;
280
+    }
281
+
282
+    /**
283
+     * Return list of internal meta keys.
284
+     *
285
+     * @since 1.0.19
286
+     * @return array
287
+     */
288
+    public function get_internal_meta_keys() {
289
+        return $this->internal_meta_keys;
290
+    }
291
+
292
+    /**
293
+     * Clear any caches.
294
+     *
295
+     * @param GetPaid_Data $object GetPaid_Data object.
296
+     * @since 1.0.19
297
+     */
298
+    protected function clear_caches( &$object ) {
299
+        clean_post_cache( $object->get_id() );
300
+    }
301
+
302
+    /**
303
+     * Method to delete a data object from the database.
304
+     *
305
+     * @param GetPaid_Data $object GetPaid_Data object.
306
+     * @param array    $args Array of args to pass to the delete method.
307
+     *
308
+     * @return void
309
+     */
310
+    public function delete( &$object, $args = array() ) {
311
+        $id          = $object->get_id();
312
+        $object_type = $object->get_object_type();
313
+
314
+        if ( 'invoice' == $object_type ) {
315
+            $object_type = $object->get_type();
316
+        }
317
+
318
+        $args        = wp_parse_args(
319
+            $args,
320
+            array(
321
+                'force_delete' => false,
322
+            )
323
+        );
324
+
325
+        if ( ! $id ) {
326
+            return;
327
+        }
328
+
329
+        if ( $args['force_delete'] ) {
330
+            wp_delete_post( $id, true );
331
+            $object->set_id( 0 );
332
+            do_action( "getpaid_delete_$object_type", $id );
333
+        } else {
334
+            wp_trash_post( $id );
335
+            $object->set_status( 'trash' );
336
+            do_action( "getpaid_trash_$object_type", $id );
337
+        }
338
+    }
339
+
340
+    /**
341
+     * Get the status to save to the post object.
342
+     *
343
+     *
344
+     * @since 1.0.19
345
+     * @param  GetPaid_Data $object GetPaid_Data object.
346
+     * @return string
347
+     */
348
+    protected function get_post_status( $object ) {
349
+        $object_status = $object->get_status( 'edit' );
350
+        $object_type   = $object->get_object_type();
351
+
352
+        if ( ! $object_status ) {
353
+            $object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
354
+        }
355
+
356
+        return $object_status;
357
+    }
358 358
 
359 359
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -58 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.19
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Data_Store_WP class.
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @param  GetPaid_Data $object GetPaid_Data object.
65 65
 	 * @return array
66 66
 	 */
67
-	public function read_meta( &$object ) {
67
+	public function read_meta(&$object) {
68 68
 		global $wpdb;
69 69
 		$db_info       = $this->get_db_info();
70 70
 		$raw_meta_data = $wpdb->get_results(
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
 			)
78 78
 		);
79 79
 
80
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
81
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
82
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
80
+		$this->internal_meta_keys = array_merge(array_map(array($this, 'prefix_key'), $object->get_data_keys()), $this->internal_meta_keys);
81
+		$meta_data                = array_filter($raw_meta_data, array($this, 'exclude_internal_meta_keys'));
82
+		return apply_filters("getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this);
83 83
 	}
84 84
 
85 85
 	/**
@@ -89,8 +89,8 @@  discard block
 block discarded – undo
89 89
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
90 90
 	 * @param  stdClass $meta (containing at least ->id).
91 91
 	 */
92
-	public function delete_meta( &$object, $meta ) {
93
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
92
+	public function delete_meta(&$object, $meta) {
93
+		delete_metadata_by_mid($this->meta_type, $meta->id);
94 94
 	}
95 95
 
96 96
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @param  stdClass $meta (containing ->key and ->value).
102 102
 	 * @return int meta ID
103 103
 	 */
104
-	public function add_meta( &$object, $meta ) {
105
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
104
+	public function add_meta(&$object, $meta) {
105
+		return add_metadata($this->meta_type, $object->get_id(), $meta->key, is_string($meta->value) ? wp_slash($meta->value) : $meta->value, false);
106 106
 	}
107 107
 
108 108
 	/**
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
113 113
 	 * @param  stdClass $meta (containing ->id, ->key and ->value).
114 114
 	 */
115
-	public function update_meta( &$object, $meta ) {
116
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
115
+	public function update_meta(&$object, $meta) {
116
+		update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key);
117 117
 	}
118 118
 
119 119
 	/**
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
 		$table         = $wpdb->prefix;
130 130
 
131 131
 		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
132
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
132
+		if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) {
133 133
 			$table .= 'getpaid_';
134 134
 		}
135 135
 
@@ -137,12 +137,12 @@  discard block
 block discarded – undo
137 137
 		$object_id_field = $this->meta_type . '_id';
138 138
 
139 139
 		// Figure out our field names.
140
-		if ( 'user' === $this->meta_type ) {
140
+		if ('user' === $this->meta_type) {
141 141
 			$meta_id_field = 'umeta_id';
142 142
 			$table         = $wpdb->usermeta;
143 143
 		}
144 144
 
145
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
145
+		if (!empty($this->object_id_field_for_meta)) {
146 146
 			$object_id_field = $this->object_id_field_for_meta;
147 147
 		}
148 148
 
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
 	 * @param string $key Prefix to be added to meta keys.
163 163
 	 * @return string
164 164
 	 */
165
-	protected function prefix_key( $key ) {
166
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
165
+	protected function prefix_key($key) {
166
+		return '_' === substr($key, 0, 1) ? $key : '_' . $key;
167 167
 	}
168 168
 
169 169
 	/**
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	 * @param object $meta Meta object to check if it should be excluded or not.
173 173
 	 * @return bool
174 174
 	 */
175
-	protected function exclude_internal_meta_keys( $meta ) {
176
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
175
+	protected function exclude_internal_meta_keys($meta) {
176
+		return !in_array($meta->meta_key, $this->internal_meta_keys, true) && 0 !== stripos($meta->meta_key, 'wp_');
177 177
 	}
178 178
 
179 179
 	/**
@@ -185,14 +185,14 @@  discard block
 block discarded – undo
185 185
 	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
186 186
 	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
187 187
 	 */
188
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
188
+	protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') {
189 189
 		$props_to_update = array();
190 190
 		$changed_props   = $object->get_changes();
191 191
 
192 192
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
193
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
194
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
195
-				$props_to_update[ $meta_key ] = $prop;
193
+		foreach ($meta_key_to_props as $meta_key => $prop) {
194
+			if (array_key_exists($prop, $changed_props) || !metadata_exists($meta_type, $object->get_id(), $meta_key)) {
195
+				$props_to_update[$meta_key] = $prop;
196 196
 			}
197 197
 		}
198 198
 
@@ -206,22 +206,22 @@  discard block
 block discarded – undo
206 206
 	 * @param WP_Post   $post_object Post object.
207 207
 	 * @since 1.0.19
208 208
 	 */
209
-	protected function read_object_data( &$object, $post_object ) {
209
+	protected function read_object_data(&$object, $post_object) {
210 210
 		$id    = $object->get_id();
211 211
 		$props = array();
212 212
 
213
-		foreach ( $this->meta_key_to_props as $meta_key => $prop ) {
214
-			$props[ $prop ] = get_post_meta( $id, $meta_key, true );
213
+		foreach ($this->meta_key_to_props as $meta_key => $prop) {
214
+			$props[$prop] = get_post_meta($id, $meta_key, true);
215 215
 		}
216 216
 
217 217
 		// Set object properties.
218
-		$object->set_props( $props );
218
+		$object->set_props($props);
219 219
 
220 220
 		// Gets extra data associated with the object if needed.
221
-		foreach ( $object->get_extra_data_keys() as $key ) {
221
+		foreach ($object->get_extra_data_keys() as $key) {
222 222
 			$function = 'set_' . $key;
223
-			if ( is_callable( array( $object, $function ) ) ) {
224
-				$object->{$function}( get_post_meta( $object->get_id(), $key, true ) );
223
+			if (is_callable(array($object, $function))) {
224
+				$object->{$function}(get_post_meta($object->get_id(), $key, true));
225 225
 			}
226 226
 		}
227 227
 	}
@@ -232,24 +232,24 @@  discard block
 block discarded – undo
232 232
 	 * @param GetPaid_Data $object GetPaid_Data object.
233 233
 	 * @since 1.0.19
234 234
 	 */
235
-	protected function update_post_meta( &$object ) {
235
+	protected function update_post_meta(&$object) {
236 236
 
237 237
 		$updated_props   = array();
238
-		$props_to_update = $this->get_props_to_update( $object, $this->meta_key_to_props );
238
+		$props_to_update = $this->get_props_to_update($object, $this->meta_key_to_props);
239 239
 		$object_type     = $object->get_object_type();
240 240
 
241
-		foreach ( $props_to_update as $meta_key => $prop ) {
242
-			$value = $object->{"get_$prop"}( 'edit' );
243
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
241
+		foreach ($props_to_update as $meta_key => $prop) {
242
+			$value = $object->{"get_$prop"}('edit');
243
+			$value = is_string($value) ? wp_slash($value) : $value;
244 244
 
245
-			$updated = $this->update_or_delete_post_meta( $object, $meta_key, $value );
245
+			$updated = $this->update_or_delete_post_meta($object, $meta_key, $value);
246 246
 
247
-			if ( $updated ) {
247
+			if ($updated) {
248 248
 				$updated_props[] = $prop;
249 249
 			}
250 250
 		}
251 251
 
252
-		do_action( "getpaid_{$object_type}_object_updated_props", $object, $updated_props );
252
+		do_action("getpaid_{$object_type}_object_updated_props", $object, $updated_props);
253 253
 	}
254 254
 
255 255
 	/**
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 	 *
270 270
 	 * @return bool True if updated/deleted.
271 271
 	 */
272
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
273
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
274
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
272
+	protected function update_or_delete_post_meta($object, $meta_key, $meta_value) {
273
+		if (in_array($meta_value, array(array(), '', null), true) && !in_array($meta_key, $this->must_exist_meta_keys, true)) {
274
+			$updated = delete_post_meta($object->get_id(), $meta_key);
275 275
 		} else {
276
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
276
+			$updated = update_post_meta($object->get_id(), $meta_key, $meta_value);
277 277
 		}
278 278
 
279 279
 		return (bool) $updated;
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param GetPaid_Data $object GetPaid_Data object.
296 296
 	 * @since 1.0.19
297 297
 	 */
298
-	protected function clear_caches( &$object ) {
299
-		clean_post_cache( $object->get_id() );
298
+	protected function clear_caches(&$object) {
299
+		clean_post_cache($object->get_id());
300 300
 	}
301 301
 
302 302
 	/**
@@ -307,33 +307,33 @@  discard block
 block discarded – undo
307 307
 	 *
308 308
 	 * @return void
309 309
 	 */
310
-	public function delete( &$object, $args = array() ) {
310
+	public function delete(&$object, $args = array()) {
311 311
 		$id          = $object->get_id();
312 312
 		$object_type = $object->get_object_type();
313 313
 
314
-		if ( 'invoice' == $object_type ) {
314
+		if ('invoice' == $object_type) {
315 315
 			$object_type = $object->get_type();
316 316
 		}
317 317
 
318
-		$args        = wp_parse_args(
318
+		$args = wp_parse_args(
319 319
 			$args,
320 320
 			array(
321 321
 				'force_delete' => false,
322 322
 			)
323 323
 		);
324 324
 
325
-		if ( ! $id ) {
325
+		if (!$id) {
326 326
 			return;
327 327
 		}
328 328
 
329
-		if ( $args['force_delete'] ) {
330
-			wp_delete_post( $id, true );
331
-			$object->set_id( 0 );
332
-			do_action( "getpaid_delete_$object_type", $id );
329
+		if ($args['force_delete']) {
330
+			wp_delete_post($id, true);
331
+			$object->set_id(0);
332
+			do_action("getpaid_delete_$object_type", $id);
333 333
 		} else {
334
-			wp_trash_post( $id );
335
-			$object->set_status( 'trash' );
336
-			do_action( "getpaid_trash_$object_type", $id );
334
+			wp_trash_post($id);
335
+			$object->set_status('trash');
336
+			do_action("getpaid_trash_$object_type", $id);
337 337
 		}
338 338
 	}
339 339
 
@@ -345,12 +345,12 @@  discard block
 block discarded – undo
345 345
 	 * @param  GetPaid_Data $object GetPaid_Data object.
346 346
 	 * @return string
347 347
 	 */
348
-	protected function get_post_status( $object ) {
349
-		$object_status = $object->get_status( 'edit' );
348
+	protected function get_post_status($object) {
349
+		$object_status = $object->get_status('edit');
350 350
 		$object_type   = $object->get_object_type();
351 351
 
352
-		if ( ! $object_status ) {
353
-			$object_status = apply_filters( "getpaid_default_{$object_type}_status", 'draft' );
352
+		if (!$object_status) {
353
+			$object_status = apply_filters("getpaid_default_{$object_type}_status", 'draft');
354 354
 		}
355 355
 
356 356
 		return $object_status;
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-invoice-data-store.php 2 patches
Indentation   +301 added lines, -301 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,251 +15,251 @@  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_taxes',
27
-		'_wpinv_fees',
28
-		'_wpinv_discounts',
29
-		'_wpinv_submission_id',
30
-		'_wpinv_payment_form',
31
-	);
32
-
33
-	/**
34
-	 * A map of meta keys to data props.
35
-	 *
36
-	 * @since 1.0.19
37
-	 *
38
-	 * @var array
39
-	 */
40
-	protected $meta_key_to_props = array(
41
-		'_wpinv_subscr_profile_id' => 'subscription_id',
42
-		'_wpinv_taxes'             => 'taxes',
43
-		'_wpinv_fees'              => 'fees',
44
-		'_wpinv_discounts'         => 'discounts',
45
-		'_wpinv_submission_id'     => 'submission_id',
46
-		'_wpinv_payment_form'      => 'payment_form',
47
-	);
48
-
49
-	/*
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_taxes',
27
+        '_wpinv_fees',
28
+        '_wpinv_discounts',
29
+        '_wpinv_submission_id',
30
+        '_wpinv_payment_form',
31
+    );
32
+
33
+    /**
34
+     * A map of meta keys to data props.
35
+     *
36
+     * @since 1.0.19
37
+     *
38
+     * @var array
39
+     */
40
+    protected $meta_key_to_props = array(
41
+        '_wpinv_subscr_profile_id' => 'subscription_id',
42
+        '_wpinv_taxes'             => 'taxes',
43
+        '_wpinv_fees'              => 'fees',
44
+        '_wpinv_discounts'         => 'discounts',
45
+        '_wpinv_submission_id'     => 'submission_id',
46
+        '_wpinv_payment_form'      => 'payment_form',
47
+    );
48
+
49
+    /*
50 50
 	|--------------------------------------------------------------------------
51 51
 	| CRUD Methods
52 52
 	|--------------------------------------------------------------------------
53 53
 	*/
54
-	/**
55
-	 * Method to create a new invoice in the database.
56
-	 *
57
-	 * @param WPInv_Invoice $invoice Invoice object.
58
-	 */
59
-	public function create( &$invoice ) {
60
-		$invoice->set_version( WPINV_VERSION );
61
-		$invoice->set_date_created( current_time('mysql') );
62
-
63
-		// Create a new post.
64
-		$id = wp_insert_post(
65
-			apply_filters(
66
-				'getpaid_new_invoice_data',
67
-				array(
68
-					'post_date'     => $invoice->get_date_created( 'edit' ),
69
-					'post_type'     => $invoice->get_post_type( 'edit' ),
70
-					'post_status'   => $this->get_post_status( $invoice ),
71
-					'ping_status'   => 'closed',
72
-					'post_author'   => $invoice->get_user_id( 'edit' ),
73
-					'post_title'    => $invoice->get_number( 'edit' ),
74
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
75
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
76
-					'post_name'     => $invoice->get_path( 'edit' ),
77
-				)
78
-			),
79
-			true
80
-		);
81
-
82
-		if ( $id && ! is_wp_error( $id ) ) {
83
-			$invoice->set_id( $id );
84
-			$this->save_special_fields( $invoice );
85
-			$this->update_post_meta( $invoice );
86
-			$invoice->save_meta_data();
87
-			$invoice->apply_changes();
88
-			$this->clear_caches( $invoice );
89
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
90
-			return true;
91
-		}
92
-
93
-		if ( is_wp_error( $id ) ) {
94
-			$invoice->last_error = $id->get_error_message();
95
-		}
96
-
97
-		return false;
98
-	}
99
-
100
-	/**
101
-	 * Method to read an invoice from the database.
102
-	 *
103
-	 * @param WPInv_Invoice $invoice Invoice object.
104
-	 *
105
-	 */
106
-	public function read( &$invoice ) {
107
-
108
-		$invoice->set_defaults();
109
-		$invoice_object = get_post( $invoice->get_id() );
110
-
111
-		if ( ! $invoice->get_id() || ! $invoice_object || getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
112
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
113
-			return false;
114
-		}
115
-
116
-		$invoice->set_props(
117
-			array(
118
-				'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
119
-				'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
120
-				'status'        => $invoice_object->post_status,
121
-				'author'        => $invoice_object->post_author,
122
-				'description'   => $invoice_object->post_excerpt,
123
-				'parent_id'     => $invoice_object->post_parent,
124
-				'name'          => $invoice_object->post_title,
125
-				'path'          => $invoice_object->post_name,
126
-				'post_type'     => $invoice_object->post_type,
127
-			)
128
-		);
129
-
130
-		$this->read_object_data( $invoice, $invoice_object );
131
-		$this->add_special_fields( $invoice );
132
-		$invoice->read_meta_data();
133
-		$invoice->set_object_read( true );
134
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
135
-
136
-	}
137
-
138
-	/**
139
-	 * Method to update an invoice in the database.
140
-	 *
141
-	 * @param WPInv_Invoice $invoice Invoice object.
142
-	 */
143
-	public function update( &$invoice ) {
144
-		$invoice->save_meta_data();
145
-		$invoice->set_version( WPINV_VERSION );
146
-
147
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
148
-			$invoice->set_date_created(  current_time('mysql') );
149
-		}
150
-
151
-		// Grab the current status so we can compare.
152
-		$previous_status = get_post_status( $invoice->get_id() );
153
-
154
-		$changes = $invoice->get_changes();
155
-
156
-		// Only update the post when the post data changes.
157
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
158
-			$post_data = array(
159
-				'post_date'         => $invoice->get_date_created( 'edit' ),
160
-				'post_status'       => $invoice->get_status( 'edit' ),
161
-				'post_title'        => $invoice->get_name( 'edit' ),
162
-				'post_author'       => $invoice->get_user_id( 'edit' ),
163
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
164
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
165
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
166
-				'post_name'         => $invoice->get_path( 'edit' ),
167
-				'post_type'         => $invoice->get_post_type( 'edit' ),
168
-			);
169
-
170
-			/**
171
-			 * When updating this object, to prevent infinite loops, use $wpdb
172
-			 * to update data, since wp_update_post spawns more calls to the
173
-			 * save_post action.
174
-			 *
175
-			 * This ensures hooks are fired by either WP itself (admin screen save),
176
-			 * or an update purely from CRUD.
177
-			 */
178
-			if ( doing_action( 'save_post' ) ) {
179
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
180
-				clean_post_cache( $invoice->get_id() );
181
-			} else {
182
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
183
-			}
184
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
185
-		}
186
-		$this->update_post_meta( $invoice );
187
-		$this->save_special_fields( $invoice );
188
-		$invoice->apply_changes();
189
-		$this->clear_caches( $invoice );
190
-
191
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
192
-		$new_status = $invoice->get_status( 'edit' );
193
-
194
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
195
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
196
-		} else {
197
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
198
-		}
199
-
200
-	}
201
-
202
-	/*
54
+    /**
55
+     * Method to create a new invoice in the database.
56
+     *
57
+     * @param WPInv_Invoice $invoice Invoice object.
58
+     */
59
+    public function create( &$invoice ) {
60
+        $invoice->set_version( WPINV_VERSION );
61
+        $invoice->set_date_created( current_time('mysql') );
62
+
63
+        // Create a new post.
64
+        $id = wp_insert_post(
65
+            apply_filters(
66
+                'getpaid_new_invoice_data',
67
+                array(
68
+                    'post_date'     => $invoice->get_date_created( 'edit' ),
69
+                    'post_type'     => $invoice->get_post_type( 'edit' ),
70
+                    'post_status'   => $this->get_post_status( $invoice ),
71
+                    'ping_status'   => 'closed',
72
+                    'post_author'   => $invoice->get_user_id( 'edit' ),
73
+                    'post_title'    => $invoice->get_number( 'edit' ),
74
+                    'post_excerpt'  => $invoice->get_description( 'edit' ),
75
+                    'post_parent'   => $invoice->get_parent_id( 'edit' ),
76
+                    'post_name'     => $invoice->get_path( 'edit' ),
77
+                )
78
+            ),
79
+            true
80
+        );
81
+
82
+        if ( $id && ! is_wp_error( $id ) ) {
83
+            $invoice->set_id( $id );
84
+            $this->save_special_fields( $invoice );
85
+            $this->update_post_meta( $invoice );
86
+            $invoice->save_meta_data();
87
+            $invoice->apply_changes();
88
+            $this->clear_caches( $invoice );
89
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
90
+            return true;
91
+        }
92
+
93
+        if ( is_wp_error( $id ) ) {
94
+            $invoice->last_error = $id->get_error_message();
95
+        }
96
+
97
+        return false;
98
+    }
99
+
100
+    /**
101
+     * Method to read an invoice from the database.
102
+     *
103
+     * @param WPInv_Invoice $invoice Invoice object.
104
+     *
105
+     */
106
+    public function read( &$invoice ) {
107
+
108
+        $invoice->set_defaults();
109
+        $invoice_object = get_post( $invoice->get_id() );
110
+
111
+        if ( ! $invoice->get_id() || ! $invoice_object || getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
112
+            $invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
113
+            return false;
114
+        }
115
+
116
+        $invoice->set_props(
117
+            array(
118
+                'date_created'  => 0 < $invoice_object->post_date ? $invoice_object->post_date : null,
119
+                'date_modified' => 0 < $invoice_object->post_modified ? $invoice_object->post_modified : null,
120
+                'status'        => $invoice_object->post_status,
121
+                'author'        => $invoice_object->post_author,
122
+                'description'   => $invoice_object->post_excerpt,
123
+                'parent_id'     => $invoice_object->post_parent,
124
+                'name'          => $invoice_object->post_title,
125
+                'path'          => $invoice_object->post_name,
126
+                'post_type'     => $invoice_object->post_type,
127
+            )
128
+        );
129
+
130
+        $this->read_object_data( $invoice, $invoice_object );
131
+        $this->add_special_fields( $invoice );
132
+        $invoice->read_meta_data();
133
+        $invoice->set_object_read( true );
134
+        do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
135
+
136
+    }
137
+
138
+    /**
139
+     * Method to update an invoice in the database.
140
+     *
141
+     * @param WPInv_Invoice $invoice Invoice object.
142
+     */
143
+    public function update( &$invoice ) {
144
+        $invoice->save_meta_data();
145
+        $invoice->set_version( WPINV_VERSION );
146
+
147
+        if ( null === $invoice->get_date_created( 'edit' ) ) {
148
+            $invoice->set_date_created(  current_time('mysql') );
149
+        }
150
+
151
+        // Grab the current status so we can compare.
152
+        $previous_status = get_post_status( $invoice->get_id() );
153
+
154
+        $changes = $invoice->get_changes();
155
+
156
+        // Only update the post when the post data changes.
157
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
158
+            $post_data = array(
159
+                'post_date'         => $invoice->get_date_created( 'edit' ),
160
+                'post_status'       => $invoice->get_status( 'edit' ),
161
+                'post_title'        => $invoice->get_name( 'edit' ),
162
+                'post_author'       => $invoice->get_user_id( 'edit' ),
163
+                'post_modified'     => $invoice->get_date_modified( 'edit' ),
164
+                'post_excerpt'      => $invoice->get_description( 'edit' ),
165
+                'post_parent'       => $invoice->get_parent_id( 'edit' ),
166
+                'post_name'         => $invoice->get_path( 'edit' ),
167
+                'post_type'         => $invoice->get_post_type( 'edit' ),
168
+            );
169
+
170
+            /**
171
+             * When updating this object, to prevent infinite loops, use $wpdb
172
+             * to update data, since wp_update_post spawns more calls to the
173
+             * save_post action.
174
+             *
175
+             * This ensures hooks are fired by either WP itself (admin screen save),
176
+             * or an update purely from CRUD.
177
+             */
178
+            if ( doing_action( 'save_post' ) ) {
179
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
180
+                clean_post_cache( $invoice->get_id() );
181
+            } else {
182
+                wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
183
+            }
184
+            $invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
185
+        }
186
+        $this->update_post_meta( $invoice );
187
+        $this->save_special_fields( $invoice );
188
+        $invoice->apply_changes();
189
+        $this->clear_caches( $invoice );
190
+
191
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
192
+        $new_status = $invoice->get_status( 'edit' );
193
+
194
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
195
+            do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
196
+        } else {
197
+            do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
198
+        }
199
+
200
+    }
201
+
202
+    /*
203 203
 	|--------------------------------------------------------------------------
204 204
 	| Additional Methods
205 205
 	|--------------------------------------------------------------------------
206 206
 	*/
207 207
 
208
-	/**
208
+    /**
209 209
      * Retrieves special fields and adds to the invoice.
210
-	 *
211
-	 * @param WPInv_Invoice $invoice Invoice object.
210
+     *
211
+     * @param WPInv_Invoice $invoice Invoice object.
212 212
      */
213 213
     public function add_special_fields( &$invoice ) {
214
-		global $wpdb;
214
+        global $wpdb;
215 215
 
216
-		$table =  $wpdb->prefix . 'getpaid_invoices';
216
+        $table =  $wpdb->prefix . 'getpaid_invoices';
217 217
         $data  = $wpdb->get_row(
218
-			$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $this->ID ),
219
-			ARRAY_A
220
-		);
221
-
222
-		// Abort if the data does not exist.
223
-		if ( empty( $data ) ) {
224
-			return;
225
-		}
226
-
227
-		$invoice->set_props( $data );
228
-
229
-	}
230
-
231
-	/**
232
-	 * Gets a list of special fields that need updated based on change state
233
-	 * or if they are present in the database or not.
234
-	 *
235
-	 * @param  WPInv_Invoice $invoice       The Invoice object.
236
-	 * @param  array   $meta_key_to_props   A mapping of prop => value.
237
-	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
238
-	 */
239
-	protected function get_special_fields_to_update( $invoice, $special_fields ) {
240
-		$props_to_update = array();
241
-		$changed_props   = $invoice->get_changes();
242
-
243
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
244
-		foreach ( $special_fields as $prop => $value ) {
245
-			if ( array_key_exists( $prop, $changed_props ) ) {
246
-				$props_to_update[ $prop ] = $value;
247
-			}
248
-		}
249
-
250
-		return $props_to_update;
251
-	}
252
-
253
-	/**
218
+            $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $this->ID ),
219
+            ARRAY_A
220
+        );
221
+
222
+        // Abort if the data does not exist.
223
+        if ( empty( $data ) ) {
224
+            return;
225
+        }
226
+
227
+        $invoice->set_props( $data );
228
+
229
+    }
230
+
231
+    /**
232
+     * Gets a list of special fields that need updated based on change state
233
+     * or if they are present in the database or not.
234
+     *
235
+     * @param  WPInv_Invoice $invoice       The Invoice object.
236
+     * @param  array   $meta_key_to_props   A mapping of prop => value.
237
+     * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
238
+     */
239
+    protected function get_special_fields_to_update( $invoice, $special_fields ) {
240
+        $props_to_update = array();
241
+        $changed_props   = $invoice->get_changes();
242
+
243
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
244
+        foreach ( $special_fields as $prop => $value ) {
245
+            if ( array_key_exists( $prop, $changed_props ) ) {
246
+                $props_to_update[ $prop ] = $value;
247
+            }
248
+        }
249
+
250
+        return $props_to_update;
251
+    }
252
+
253
+    /**
254 254
      * Saves all special fields.
255
-	 *
256
-	 * @param WPInv_Invoice $invoice Invoice object.
255
+     *
256
+     * @param WPInv_Invoice $invoice Invoice object.
257 257
      */
258 258
     public function save_special_fields( $invoice ) {
259
-		global $wpdb;
259
+        global $wpdb;
260 260
 
261
-		// Fields to update.
262
-		$fields = array (
261
+        // Fields to update.
262
+        $fields = array (
263 263
             'post_id'        => $invoice->get_id(),
264 264
             'number'         => $invoice->get_number( 'edit' ),
265 265
             'key'            => $invoice->get_key( 'edit' ),
@@ -288,118 +288,118 @@  discard block
 block discarded – undo
288 288
             'company'        => $invoice->get_company( 'edit' ),
289 289
             'vat_number'     => $invoice->get_vat_number( 'edit' ),
290 290
             'vat_rate'       => $invoice->get_vat_rate( 'edit' ),
291
-		);
292
-
293
-		// The invoices table.
294
-		$table = $wpdb->prefix . 'getpaid_invoices';
295
-		$id    = (int) $invoice->get_id();
296
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
297
-
298
-			$to_update = $this->get_special_fields_to_update( $invoice, $fields );
299
-
300
-			if ( empty( $to_update ) ) {
301
-				return;
302
-			}
303
-
304
-			$changes = array(
305
-				'tax'                => 'total_tax',
306
-				'fees_total'         => 'total_fees',
307
-				'discount'           => 'total_discount',
308
-				'adddress_confirmed' => 'address_confirmed',
309
-			);
310
-
311
-			foreach ( $changes as $to => $from ) {
312
-				if ( isset( $changes[ $from ] ) ) {
313
-					$changes[ $to ] = $changes[ $from ];
314
-					unset( $changes[ $from ] );
315
-				}
316
-			}
317
-
318
-			$changes['total'] = $invoice->get_total( 'edit' );
291
+        );
292
+
293
+        // The invoices table.
294
+        $table = $wpdb->prefix . 'getpaid_invoices';
295
+        $id    = (int) $invoice->get_id();
296
+        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
297
+
298
+            $to_update = $this->get_special_fields_to_update( $invoice, $fields );
299
+
300
+            if ( empty( $to_update ) ) {
301
+                return;
302
+            }
303
+
304
+            $changes = array(
305
+                'tax'                => 'total_tax',
306
+                'fees_total'         => 'total_fees',
307
+                'discount'           => 'total_discount',
308
+                'adddress_confirmed' => 'address_confirmed',
309
+            );
310
+
311
+            foreach ( $changes as $to => $from ) {
312
+                if ( isset( $changes[ $from ] ) ) {
313
+                    $changes[ $to ] = $changes[ $from ];
314
+                    unset( $changes[ $from ] );
315
+                }
316
+            }
317
+
318
+            $changes['total'] = $invoice->get_total( 'edit' );
319 319
             $wpdb->update( $table, $fields, array( 'post_id' => $id ) );
320 320
 
321 321
         } else {
322 322
 
323
-			$fields['tax'] = $fields['total_tax'];
324
-			unset( $fields['total_tax'] );
323
+            $fields['tax'] = $fields['total_tax'];
324
+            unset( $fields['total_tax'] );
325 325
 
326
-			$fields['fees_total'] = $fields['total_fees'];
327
-			unset( $fields['total_fees'] );
326
+            $fields['fees_total'] = $fields['total_fees'];
327
+            unset( $fields['total_fees'] );
328 328
 
329
-			$fields['discount'] = $fields['total_discount'];
330
-			unset( $fields['total_discount'] );
329
+            $fields['discount'] = $fields['total_discount'];
330
+            unset( $fields['total_discount'] );
331 331
 
332
-			$fields['adddress_confirmed'] = $fields['address_confirmed'];
333
-			unset( $fields['address_confirmed'] );
332
+            $fields['adddress_confirmed'] = $fields['address_confirmed'];
333
+            unset( $fields['address_confirmed'] );
334 334
 			
335
-			$fields['total']   = $invoice->get_total( 'edit' );
336
-			$fields['post_id'] = $id;
335
+            $fields['total']   = $invoice->get_total( 'edit' );
336
+            $fields['post_id'] = $id;
337 337
             $wpdb->insert( $table, $fields );
338 338
 
339
-		}
339
+        }
340 340
 
341
-	}
341
+    }
342 342
 
343
-	/**
343
+    /**
344 344
      * Set's up cart details.
345
-	 *
346
-	 * @param WPInv_Invoice $invoice Invoice object.
345
+     *
346
+     * @param WPInv_Invoice $invoice Invoice object.
347 347
      */
348 348
     public function add_items( &$invoice ) {
349
-		global $wpdb;
349
+        global $wpdb;
350 350
 
351
-		$table =  $wpdb->prefix . 'getpaid_invoice_items';
351
+        $table =  $wpdb->prefix . 'getpaid_invoice_items';
352 352
         $items = $wpdb->get_results(
353 353
             $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $this->ID )
354 354
         );
355 355
 
356 356
         if ( empty( $items ) ) {
357 357
             return;
358
-		}
358
+        }
359 359
 
360
-		foreach ( $items as $item_data ) {
361
-			$item = new GetPaid_Form_Item( $item_data->item_id );
360
+        foreach ( $items as $item_data ) {
361
+            $item = new GetPaid_Form_Item( $item_data->item_id );
362 362
 
363
-			// Set item data.
364
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
365
-			$item->item_discount = wpinv_sanitize_amount( $item_data->tax );
366
-			$item->set_name( $item_data->item_name );
367
-			$item->set_description( $item_data->item_description );
368
-			$item->set_price( $item_data->item_price );
369
-			$item->set_quantity( $item_data->quantity );
363
+            // Set item data.
364
+            $item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
365
+            $item->item_discount = wpinv_sanitize_amount( $item_data->tax );
366
+            $item->set_name( $item_data->item_name );
367
+            $item->set_description( $item_data->item_description );
368
+            $item->set_price( $item_data->item_price );
369
+            $item->set_quantity( $item_data->quantity );
370 370
 
371
-			$invoice->add_item( $item );
372
-		}
371
+            $invoice->add_item( $item );
372
+        }
373 373
 
374
-	}
374
+    }
375 375
 
376
-	/**
376
+    /**
377 377
      * Saves cart details.
378
-	 *
379
-	 * @param WPInv_Invoice $invoice Invoice object.
378
+     *
379
+     * @param WPInv_Invoice $invoice Invoice object.
380 380
      */
381 381
     public function save_items( $invoice ) {
382 382
 
383
-		// Delete previously existing items.
384
-		$this->delete_items( $invoice );
383
+        // Delete previously existing items.
384
+        $this->delete_items( $invoice );
385 385
 
386
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
386
+        $table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
387 387
         $to_save = $invoice->get_cart_details();
388 388
 
389
-		foreach ( $to_save as $item_data ) {
390
-			$GLOBALS['wpdb']->insert( $table, $item_data );
391
-		}
389
+        foreach ( $to_save as $item_data ) {
390
+            $GLOBALS['wpdb']->insert( $table, $item_data );
391
+        }
392 392
 
393
-	}
393
+    }
394 394
 
395
-	/**
395
+    /**
396 396
      * Deletes an invoice's cart details from the database.
397
-	 *
398
-	 * @param WPInv_Invoice $invoice Invoice object.
397
+     *
398
+     * @param WPInv_Invoice $invoice Invoice object.
399 399
      */
400 400
     public function delete_items( $invoice ) {
401
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
402
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->ID ) );
401
+        $table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
402
+        return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->ID ) );
403 403
     }
404 404
 
405 405
 }
Please login to merge, or discard this patch.
Spacing   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Invoice_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -56,41 +56,41 @@  discard block
 block discarded – undo
56 56
 	 *
57 57
 	 * @param WPInv_Invoice $invoice Invoice object.
58 58
 	 */
59
-	public function create( &$invoice ) {
60
-		$invoice->set_version( WPINV_VERSION );
61
-		$invoice->set_date_created( current_time('mysql') );
59
+	public function create(&$invoice) {
60
+		$invoice->set_version(WPINV_VERSION);
61
+		$invoice->set_date_created(current_time('mysql'));
62 62
 
63 63
 		// Create a new post.
64 64
 		$id = wp_insert_post(
65 65
 			apply_filters(
66 66
 				'getpaid_new_invoice_data',
67 67
 				array(
68
-					'post_date'     => $invoice->get_date_created( 'edit' ),
69
-					'post_type'     => $invoice->get_post_type( 'edit' ),
70
-					'post_status'   => $this->get_post_status( $invoice ),
68
+					'post_date'     => $invoice->get_date_created('edit'),
69
+					'post_type'     => $invoice->get_post_type('edit'),
70
+					'post_status'   => $this->get_post_status($invoice),
71 71
 					'ping_status'   => 'closed',
72
-					'post_author'   => $invoice->get_user_id( 'edit' ),
73
-					'post_title'    => $invoice->get_number( 'edit' ),
74
-					'post_excerpt'  => $invoice->get_description( 'edit' ),
75
-					'post_parent'   => $invoice->get_parent_id( 'edit' ),
76
-					'post_name'     => $invoice->get_path( 'edit' ),
72
+					'post_author'   => $invoice->get_user_id('edit'),
73
+					'post_title'    => $invoice->get_number('edit'),
74
+					'post_excerpt'  => $invoice->get_description('edit'),
75
+					'post_parent'   => $invoice->get_parent_id('edit'),
76
+					'post_name'     => $invoice->get_path('edit'),
77 77
 				)
78 78
 			),
79 79
 			true
80 80
 		);
81 81
 
82
-		if ( $id && ! is_wp_error( $id ) ) {
83
-			$invoice->set_id( $id );
84
-			$this->save_special_fields( $invoice );
85
-			$this->update_post_meta( $invoice );
82
+		if ($id && !is_wp_error($id)) {
83
+			$invoice->set_id($id);
84
+			$this->save_special_fields($invoice);
85
+			$this->update_post_meta($invoice);
86 86
 			$invoice->save_meta_data();
87 87
 			$invoice->apply_changes();
88
-			$this->clear_caches( $invoice );
89
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
88
+			$this->clear_caches($invoice);
89
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice);
90 90
 			return true;
91 91
 		}
92 92
 
93
-		if ( is_wp_error( $id ) ) {
93
+		if (is_wp_error($id)) {
94 94
 			$invoice->last_error = $id->get_error_message();
95 95
 		}
96 96
 
@@ -103,13 +103,13 @@  discard block
 block discarded – undo
103 103
 	 * @param WPInv_Invoice $invoice Invoice object.
104 104
 	 *
105 105
 	 */
106
-	public function read( &$invoice ) {
106
+	public function read(&$invoice) {
107 107
 
108 108
 		$invoice->set_defaults();
109
-		$invoice_object = get_post( $invoice->get_id() );
109
+		$invoice_object = get_post($invoice->get_id());
110 110
 
111
-		if ( ! $invoice->get_id() || ! $invoice_object || getpaid_is_invoice_post_type( $invoice_object->post_type ) ) {
112
-			$invoice->last_error = __( 'Invalid invoice.', 'invoicing' );
111
+		if (!$invoice->get_id() || !$invoice_object || getpaid_is_invoice_post_type($invoice_object->post_type)) {
112
+			$invoice->last_error = __('Invalid invoice.', 'invoicing');
113 113
 			return false;
114 114
 		}
115 115
 
@@ -127,11 +127,11 @@  discard block
 block discarded – undo
127 127
 			)
128 128
 		);
129 129
 
130
-		$this->read_object_data( $invoice, $invoice_object );
131
-		$this->add_special_fields( $invoice );
130
+		$this->read_object_data($invoice, $invoice_object);
131
+		$this->add_special_fields($invoice);
132 132
 		$invoice->read_meta_data();
133
-		$invoice->set_object_read( true );
134
-		do_action( 'getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice );
133
+		$invoice->set_object_read(true);
134
+		do_action('getpaid_read_' . $invoice->get_type(), $invoice->get_id(), $invoice);
135 135
 
136 136
 	}
137 137
 
@@ -140,31 +140,31 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @param WPInv_Invoice $invoice Invoice object.
142 142
 	 */
143
-	public function update( &$invoice ) {
143
+	public function update(&$invoice) {
144 144
 		$invoice->save_meta_data();
145
-		$invoice->set_version( WPINV_VERSION );
145
+		$invoice->set_version(WPINV_VERSION);
146 146
 
147
-		if ( null === $invoice->get_date_created( 'edit' ) ) {
148
-			$invoice->set_date_created(  current_time('mysql') );
147
+		if (null === $invoice->get_date_created('edit')) {
148
+			$invoice->set_date_created(current_time('mysql'));
149 149
 		}
150 150
 
151 151
 		// Grab the current status so we can compare.
152
-		$previous_status = get_post_status( $invoice->get_id() );
152
+		$previous_status = get_post_status($invoice->get_id());
153 153
 
154 154
 		$changes = $invoice->get_changes();
155 155
 
156 156
 		// Only update the post when the post data changes.
157
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path' ), array_keys( $changes ) ) ) {
157
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'description', 'parent_id', 'post_excerpt', 'path'), array_keys($changes))) {
158 158
 			$post_data = array(
159
-				'post_date'         => $invoice->get_date_created( 'edit' ),
160
-				'post_status'       => $invoice->get_status( 'edit' ),
161
-				'post_title'        => $invoice->get_name( 'edit' ),
162
-				'post_author'       => $invoice->get_user_id( 'edit' ),
163
-				'post_modified'     => $invoice->get_date_modified( 'edit' ),
164
-				'post_excerpt'      => $invoice->get_description( 'edit' ),
165
-				'post_parent'       => $invoice->get_parent_id( 'edit' ),
166
-				'post_name'         => $invoice->get_path( 'edit' ),
167
-				'post_type'         => $invoice->get_post_type( 'edit' ),
159
+				'post_date'         => $invoice->get_date_created('edit'),
160
+				'post_status'       => $invoice->get_status('edit'),
161
+				'post_title'        => $invoice->get_name('edit'),
162
+				'post_author'       => $invoice->get_user_id('edit'),
163
+				'post_modified'     => $invoice->get_date_modified('edit'),
164
+				'post_excerpt'      => $invoice->get_description('edit'),
165
+				'post_parent'       => $invoice->get_parent_id('edit'),
166
+				'post_name'         => $invoice->get_path('edit'),
167
+				'post_type'         => $invoice->get_post_type('edit'),
168 168
 			);
169 169
 
170 170
 			/**
@@ -175,26 +175,26 @@  discard block
 block discarded – undo
175 175
 			 * This ensures hooks are fired by either WP itself (admin screen save),
176 176
 			 * or an update purely from CRUD.
177 177
 			 */
178
-			if ( doing_action( 'save_post' ) ) {
179
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $invoice->get_id() ) );
180
-				clean_post_cache( $invoice->get_id() );
178
+			if (doing_action('save_post')) {
179
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $invoice->get_id()));
180
+				clean_post_cache($invoice->get_id());
181 181
 			} else {
182
-				wp_update_post( array_merge( array( 'ID' => $invoice->get_id() ), $post_data ) );
182
+				wp_update_post(array_merge(array('ID' => $invoice->get_id()), $post_data));
183 183
 			}
184
-			$invoice->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
184
+			$invoice->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
185 185
 		}
186
-		$this->update_post_meta( $invoice );
187
-		$this->save_special_fields( $invoice );
186
+		$this->update_post_meta($invoice);
187
+		$this->save_special_fields($invoice);
188 188
 		$invoice->apply_changes();
189
-		$this->clear_caches( $invoice );
189
+		$this->clear_caches($invoice);
190 190
 
191 191
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
192
-		$new_status = $invoice->get_status( 'edit' );
192
+		$new_status = $invoice->get_status('edit');
193 193
 
194
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
195
-			do_action( 'getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice );
194
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
195
+			do_action('getpaid_new_' . $invoice->get_type(), $invoice->get_id(), $invoice);
196 196
 		} else {
197
-			do_action( 'getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice );
197
+			do_action('getpaid_update_' . $invoice->get_type(), $invoice->get_id(), $invoice);
198 198
 		}
199 199
 
200 200
 	}
@@ -210,21 +210,21 @@  discard block
 block discarded – undo
210 210
 	 *
211 211
 	 * @param WPInv_Invoice $invoice Invoice object.
212 212
      */
213
-    public function add_special_fields( &$invoice ) {
213
+    public function add_special_fields(&$invoice) {
214 214
 		global $wpdb;
215 215
 
216
-		$table =  $wpdb->prefix . 'getpaid_invoices';
217
-        $data  = $wpdb->get_row(
218
-			$wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $this->ID ),
216
+		$table = $wpdb->prefix . 'getpaid_invoices';
217
+        $data = $wpdb->get_row(
218
+			$wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d LIMIT 1", $this->ID),
219 219
 			ARRAY_A
220 220
 		);
221 221
 
222 222
 		// Abort if the data does not exist.
223
-		if ( empty( $data ) ) {
223
+		if (empty($data)) {
224 224
 			return;
225 225
 		}
226 226
 
227
-		$invoice->set_props( $data );
227
+		$invoice->set_props($data);
228 228
 
229 229
 	}
230 230
 
@@ -236,14 +236,14 @@  discard block
 block discarded – undo
236 236
 	 * @param  array   $meta_key_to_props   A mapping of prop => value.
237 237
 	 * @return array                        A mapping of field keys => prop names, filtered by ones that should be updated.
238 238
 	 */
239
-	protected function get_special_fields_to_update( $invoice, $special_fields ) {
239
+	protected function get_special_fields_to_update($invoice, $special_fields) {
240 240
 		$props_to_update = array();
241 241
 		$changed_props   = $invoice->get_changes();
242 242
 
243 243
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
244
-		foreach ( $special_fields as $prop => $value ) {
245
-			if ( array_key_exists( $prop, $changed_props ) ) {
246
-				$props_to_update[ $prop ] = $value;
244
+		foreach ($special_fields as $prop => $value) {
245
+			if (array_key_exists($prop, $changed_props)) {
246
+				$props_to_update[$prop] = $value;
247 247
 			}
248 248
 		}
249 249
 
@@ -255,49 +255,49 @@  discard block
 block discarded – undo
255 255
 	 *
256 256
 	 * @param WPInv_Invoice $invoice Invoice object.
257 257
      */
258
-    public function save_special_fields( $invoice ) {
258
+    public function save_special_fields($invoice) {
259 259
 		global $wpdb;
260 260
 
261 261
 		// Fields to update.
262
-		$fields = array (
262
+		$fields = array(
263 263
             'post_id'        => $invoice->get_id(),
264
-            'number'         => $invoice->get_number( 'edit' ),
265
-            'key'            => $invoice->get_key( 'edit' ),
266
-            'type'           => $invoice->get_type( 'edit' ),
267
-            'mode'           => $invoice->get_mode( 'edit' ),
268
-            'user_ip'        => $invoice->get_user_ip( 'edit' ),
269
-            'first_name'     => $invoice->get_first_name( 'edit' ),
270
-            'last_name'      => $invoice->get_last_name( 'edit' ),
271
-            'address'        => $invoice->get_address( 'edit' ),
272
-            'city'           => $invoice->get_city( 'edit' ),
273
-            'state'          => $invoice->get_state( 'edit' ),
274
-            'country'        => $invoice->get_country( 'edit' ),
275
-            'zip'            => $invoice->get_zip( 'edit' ),
276
-            'address_confirmed' => (int) $invoice->get_address_confirmed( 'edit' ),
277
-            'gateway'        => $invoice->get_gateway( 'edit' ),
278
-            'transaction_id' => $invoice->get_transaction_id( 'edit' ),
279
-            'currency'       => $invoice->get_currency( 'edit' ),
280
-            'subtotal'       => $invoice->get_subtotal( 'edit' ),
281
-            'total_tax'      => $invoice->get_total_tax( 'edit' ),
282
-            'total_fees'     => $invoice->get_total_fees( 'edit' ),
283
-            'total_discount' => $invoice->get_total_discount( 'edit' ),
284
-            'discount_code'  => $invoice->get_discount_code( 'edit' ),
285
-            'disable_taxes'  => (int) $invoice->get_disable_taxes( 'edit' ),
286
-            'due_date'       => $invoice->get_due_date( 'edit' ),
287
-            'completed_date' => $invoice->get_completed_date( 'edit' ),
288
-            'company'        => $invoice->get_company( 'edit' ),
289
-            'vat_number'     => $invoice->get_vat_number( 'edit' ),
290
-            'vat_rate'       => $invoice->get_vat_rate( 'edit' ),
264
+            'number'         => $invoice->get_number('edit'),
265
+            'key'            => $invoice->get_key('edit'),
266
+            'type'           => $invoice->get_type('edit'),
267
+            'mode'           => $invoice->get_mode('edit'),
268
+            'user_ip'        => $invoice->get_user_ip('edit'),
269
+            'first_name'     => $invoice->get_first_name('edit'),
270
+            'last_name'      => $invoice->get_last_name('edit'),
271
+            'address'        => $invoice->get_address('edit'),
272
+            'city'           => $invoice->get_city('edit'),
273
+            'state'          => $invoice->get_state('edit'),
274
+            'country'        => $invoice->get_country('edit'),
275
+            'zip'            => $invoice->get_zip('edit'),
276
+            'address_confirmed' => (int) $invoice->get_address_confirmed('edit'),
277
+            'gateway'        => $invoice->get_gateway('edit'),
278
+            'transaction_id' => $invoice->get_transaction_id('edit'),
279
+            'currency'       => $invoice->get_currency('edit'),
280
+            'subtotal'       => $invoice->get_subtotal('edit'),
281
+            'total_tax'      => $invoice->get_total_tax('edit'),
282
+            'total_fees'     => $invoice->get_total_fees('edit'),
283
+            'total_discount' => $invoice->get_total_discount('edit'),
284
+            'discount_code'  => $invoice->get_discount_code('edit'),
285
+            'disable_taxes'  => (int) $invoice->get_disable_taxes('edit'),
286
+            'due_date'       => $invoice->get_due_date('edit'),
287
+            'completed_date' => $invoice->get_completed_date('edit'),
288
+            'company'        => $invoice->get_company('edit'),
289
+            'vat_number'     => $invoice->get_vat_number('edit'),
290
+            'vat_rate'       => $invoice->get_vat_rate('edit'),
291 291
 		);
292 292
 
293 293
 		// The invoices table.
294 294
 		$table = $wpdb->prefix . 'getpaid_invoices';
295 295
 		$id    = (int) $invoice->get_id();
296
-		if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`= $id" ) ) {
296
+		if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`= $id")) {
297 297
 
298
-			$to_update = $this->get_special_fields_to_update( $invoice, $fields );
298
+			$to_update = $this->get_special_fields_to_update($invoice, $fields);
299 299
 
300
-			if ( empty( $to_update ) ) {
300
+			if (empty($to_update)) {
301 301
 				return;
302 302
 			}
303 303
 
@@ -308,33 +308,33 @@  discard block
 block discarded – undo
308 308
 				'adddress_confirmed' => 'address_confirmed',
309 309
 			);
310 310
 
311
-			foreach ( $changes as $to => $from ) {
312
-				if ( isset( $changes[ $from ] ) ) {
313
-					$changes[ $to ] = $changes[ $from ];
314
-					unset( $changes[ $from ] );
311
+			foreach ($changes as $to => $from) {
312
+				if (isset($changes[$from])) {
313
+					$changes[$to] = $changes[$from];
314
+					unset($changes[$from]);
315 315
 				}
316 316
 			}
317 317
 
318
-			$changes['total'] = $invoice->get_total( 'edit' );
319
-            $wpdb->update( $table, $fields, array( 'post_id' => $id ) );
318
+			$changes['total'] = $invoice->get_total('edit');
319
+            $wpdb->update($table, $fields, array('post_id' => $id));
320 320
 
321 321
         } else {
322 322
 
323 323
 			$fields['tax'] = $fields['total_tax'];
324
-			unset( $fields['total_tax'] );
324
+			unset($fields['total_tax']);
325 325
 
326 326
 			$fields['fees_total'] = $fields['total_fees'];
327
-			unset( $fields['total_fees'] );
327
+			unset($fields['total_fees']);
328 328
 
329 329
 			$fields['discount'] = $fields['total_discount'];
330
-			unset( $fields['total_discount'] );
330
+			unset($fields['total_discount']);
331 331
 
332 332
 			$fields['adddress_confirmed'] = $fields['address_confirmed'];
333
-			unset( $fields['address_confirmed'] );
333
+			unset($fields['address_confirmed']);
334 334
 			
335
-			$fields['total']   = $invoice->get_total( 'edit' );
335
+			$fields['total']   = $invoice->get_total('edit');
336 336
 			$fields['post_id'] = $id;
337
-            $wpdb->insert( $table, $fields );
337
+            $wpdb->insert($table, $fields);
338 338
 
339 339
 		}
340 340
 
@@ -345,30 +345,30 @@  discard block
 block discarded – undo
345 345
 	 *
346 346
 	 * @param WPInv_Invoice $invoice Invoice object.
347 347
      */
348
-    public function add_items( &$invoice ) {
348
+    public function add_items(&$invoice) {
349 349
 		global $wpdb;
350 350
 
351
-		$table =  $wpdb->prefix . 'getpaid_invoice_items';
351
+		$table = $wpdb->prefix . 'getpaid_invoice_items';
352 352
         $items = $wpdb->get_results(
353
-            $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $this->ID )
353
+            $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $this->ID)
354 354
         );
355 355
 
356
-        if ( empty( $items ) ) {
356
+        if (empty($items)) {
357 357
             return;
358 358
 		}
359 359
 
360
-		foreach ( $items as $item_data ) {
361
-			$item = new GetPaid_Form_Item( $item_data->item_id );
360
+		foreach ($items as $item_data) {
361
+			$item = new GetPaid_Form_Item($item_data->item_id);
362 362
 
363 363
 			// Set item data.
364
-			$item->item_tax      = wpinv_sanitize_amount( $item_data->tax );
365
-			$item->item_discount = wpinv_sanitize_amount( $item_data->tax );
366
-			$item->set_name( $item_data->item_name );
367
-			$item->set_description( $item_data->item_description );
368
-			$item->set_price( $item_data->item_price );
369
-			$item->set_quantity( $item_data->quantity );
370
-
371
-			$invoice->add_item( $item );
364
+			$item->item_tax      = wpinv_sanitize_amount($item_data->tax);
365
+			$item->item_discount = wpinv_sanitize_amount($item_data->tax);
366
+			$item->set_name($item_data->item_name);
367
+			$item->set_description($item_data->item_description);
368
+			$item->set_price($item_data->item_price);
369
+			$item->set_quantity($item_data->quantity);
370
+
371
+			$invoice->add_item($item);
372 372
 		}
373 373
 
374 374
 	}
@@ -378,16 +378,16 @@  discard block
 block discarded – undo
378 378
 	 *
379 379
 	 * @param WPInv_Invoice $invoice Invoice object.
380 380
      */
381
-    public function save_items( $invoice ) {
381
+    public function save_items($invoice) {
382 382
 
383 383
 		// Delete previously existing items.
384
-		$this->delete_items( $invoice );
384
+		$this->delete_items($invoice);
385 385
 
386
-		$table   =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
386
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
387 387
         $to_save = $invoice->get_cart_details();
388 388
 
389
-		foreach ( $to_save as $item_data ) {
390
-			$GLOBALS['wpdb']->insert( $table, $item_data );
389
+		foreach ($to_save as $item_data) {
390
+			$GLOBALS['wpdb']->insert($table, $item_data);
391 391
 		}
392 392
 
393 393
 	}
@@ -397,9 +397,9 @@  discard block
 block discarded – undo
397 397
 	 *
398 398
 	 * @param WPInv_Invoice $invoice Invoice object.
399 399
      */
400
-    public function delete_items( $invoice ) {
401
-		$table =  $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
402
-		return $GLOBALS['wpdb']->delete( $table, array( 'post_id' => $invoice->ID ) );
400
+    public function delete_items($invoice) {
401
+		$table = $GLOBALS['wpdb']->prefix . 'getpaid_invoice_items';
402
+		return $GLOBALS['wpdb']->delete($table, array('post_id' => $invoice->ID));
403 403
     }
404 404
 
405 405
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-discount-data-store.php 2 patches
Indentation   +185 added lines, -185 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,195 +15,195 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Discount_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
-		'_wpi_discount_code',
26
-		'_wpi_discount_amount',
27
-		'_wpi_discount_start',
28
-		'_wpi_discount_expiration',
29
-		'_wpi_discount_type',
30
-		'_wpi_discount_uses',
31
-		'_wpi_discount_is_single_use',
32
-		'_wpi_discount_items',
33
-		'_wpi_discount_excluded_items',
34
-		'_wpi_discount_max_uses',
35
-		'_wpi_discount_is_recurring',
36
-		'_wpi_discount_min_total',
37
-		'_wpi_discount_max_total',
38
-	);
39
-
40
-	/**
41
-	 * A map of meta keys to data props.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $meta_key_to_props = array(
48
-		'_wpi_discount_code'           => 'code',
49
-		'_wpi_discount_amount'         => 'amount',
50
-		'_wpi_discount_start'          => 'start',
51
-		'_wpi_discount_expiration'     => 'expiration',
52
-		'_wpi_discount_type'           => 'type',
53
-		'_wpi_discount_uses'           => 'uses',
54
-		'_wpi_discount_is_single_use'  => 'is_single_use',
55
-		'_wpi_discount_items'          => 'items',
56
-		'_wpi_discount_excluded_items' => 'excluded_items',
57
-		'_wpi_discount_max_uses'       => 'max_uses',
58
-		'_wpi_discount_is_recurring'   => 'is_recurring',
59
-		'_wpi_discount_min_total'      => 'min_total',
60
-		'_wpi_discount_max_total'      => 'max_total',
61
-	);
62
-
63
-	/*
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
+        '_wpi_discount_code',
26
+        '_wpi_discount_amount',
27
+        '_wpi_discount_start',
28
+        '_wpi_discount_expiration',
29
+        '_wpi_discount_type',
30
+        '_wpi_discount_uses',
31
+        '_wpi_discount_is_single_use',
32
+        '_wpi_discount_items',
33
+        '_wpi_discount_excluded_items',
34
+        '_wpi_discount_max_uses',
35
+        '_wpi_discount_is_recurring',
36
+        '_wpi_discount_min_total',
37
+        '_wpi_discount_max_total',
38
+    );
39
+
40
+    /**
41
+     * A map of meta keys to data props.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $meta_key_to_props = array(
48
+        '_wpi_discount_code'           => 'code',
49
+        '_wpi_discount_amount'         => 'amount',
50
+        '_wpi_discount_start'          => 'start',
51
+        '_wpi_discount_expiration'     => 'expiration',
52
+        '_wpi_discount_type'           => 'type',
53
+        '_wpi_discount_uses'           => 'uses',
54
+        '_wpi_discount_is_single_use'  => 'is_single_use',
55
+        '_wpi_discount_items'          => 'items',
56
+        '_wpi_discount_excluded_items' => 'excluded_items',
57
+        '_wpi_discount_max_uses'       => 'max_uses',
58
+        '_wpi_discount_is_recurring'   => 'is_recurring',
59
+        '_wpi_discount_min_total'      => 'min_total',
60
+        '_wpi_discount_max_total'      => 'max_total',
61
+    );
62
+
63
+    /*
64 64
 	|--------------------------------------------------------------------------
65 65
 	| CRUD Methods
66 66
 	|--------------------------------------------------------------------------
67 67
 	*/
68 68
 
69
-	/**
70
-	 * Method to create a new discount in the database.
71
-	 *
72
-	 * @param WPInv_Discount $discount Discount object.
73
-	 */
74
-	public function create( &$discount ) {
75
-		$discount->set_version( WPINV_VERSION );
76
-		$discount->set_date_created( current_time('mysql') );
77
-
78
-		// Create a new post.
79
-		$id = wp_insert_post(
80
-			apply_filters(
81
-				'getpaid_new_discount_data',
82
-				array(
83
-					'post_date'     => $discount->get_date_created( 'edit' ),
84
-					'post_type'     => 'wpi_discount',
85
-					'post_status'   => $this->get_post_status( $discount ),
86
-					'ping_status'   => 'closed',
87
-					'post_author'   => $discount->get_author( 'edit' ),
88
-					'post_title'    => $discount->get_name( 'edit' ),
89
-					'post_excerpt'  => $discount->get_description( 'edit' ),
90
-				)
91
-			),
92
-			true
93
-		);
94
-
95
-		if ( $id && ! is_wp_error( $id ) ) {
96
-			$discount->set_id( $id );
97
-			$this->update_post_meta( $discount );
98
-			$discount->save_meta_data();
99
-			$discount->apply_changes();
100
-			$this->clear_caches( $discount );
101
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
102
-			return true;
103
-		}
104
-
105
-		if ( is_wp_error( $id ) ) {
106
-			$discount->last_error = $id->get_error_message();
107
-		}
108
-
109
-		return false;
110
-	}
111
-
112
-	/**
113
-	 * Method to read a discount from the database.
114
-	 *
115
-	 * @param WPInv_Discount $discount Discount object.
116
-	 *
117
-	 */
118
-	public function read( &$discount ) {
119
-
120
-		$discount->set_defaults();
121
-		$discount_object = get_post( $discount->get_id() );
122
-
123
-		if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
-			$discount->last_error = __( 'Invalid discount.', 'invoicing' );
125
-			return false;
126
-		}
127
-
128
-		$discount->set_props(
129
-			array(
130
-				'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
131
-				'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
132
-				'status'        => $discount_object->post_status,
133
-				'name'          => $discount_object->post_title,
134
-				'author'        => $discount_object->post_author,
135
-				'description'   => $discount_object->post_excerpt,
136
-			)
137
-		);
138
-
139
-		$this->read_object_data( $discount, $discount_object );
140
-		$discount->read_meta_data();
141
-		$discount->set_object_read( true );
142
-		do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
143
-
144
-	}
145
-
146
-	/**
147
-	 * Method to update a discount in the database.
148
-	 *
149
-	 * @param WPInv_Discount $discount Discount object.
150
-	 */
151
-	public function update( &$discount ) {
152
-		$discount->save_meta_data();
153
-		$discount->set_version( WPINV_VERSION );
154
-
155
-		if ( null === $discount->get_date_created( 'edit' ) ) {
156
-			$discount->set_date_created(  current_time('mysql') );
157
-		}
158
-
159
-		// Grab the current status so we can compare.
160
-		$previous_status = get_post_status( $discount->get_id() );
161
-
162
-		$changes = $discount->get_changes();
163
-
164
-		// Only update the post when the post data changes.
165
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
166
-			$post_data = array(
167
-				'post_date'         => $discount->get_date_created( 'edit' ),
168
-				'post_status'       => $discount->get_status( 'edit' ),
169
-				'post_title'        => $discount->get_name( 'edit' ),
170
-				'post_author'       => $discount->get_author( 'edit' ),
171
-				'post_modified'     => $discount->get_date_modified( 'edit' ),
172
-				'post_excerpt'      => $discount->get_description( 'edit' ),
173
-			);
174
-
175
-			/**
176
-			 * When updating this object, to prevent infinite loops, use $wpdb
177
-			 * to update data, since wp_update_post spawns more calls to the
178
-			 * save_post action.
179
-			 *
180
-			 * This ensures hooks are fired by either WP itself (admin screen save),
181
-			 * or an update purely from CRUD.
182
-			 */
183
-			if ( doing_action( 'save_post' ) ) {
184
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
185
-				clean_post_cache( $discount->get_id() );
186
-			} else {
187
-				wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
188
-			}
189
-			$discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
190
-		}
191
-		$this->update_post_meta( $discount );
192
-		$discount->apply_changes();
193
-		$this->clear_caches( $discount );
194
-
195
-		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
-		$new_status = $discount->get_status( 'edit' );
197
-
198
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
200
-		} else {
201
-			do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
202
-		}
203
-
204
-	}
205
-
206
-	/*
69
+    /**
70
+     * Method to create a new discount in the database.
71
+     *
72
+     * @param WPInv_Discount $discount Discount object.
73
+     */
74
+    public function create( &$discount ) {
75
+        $discount->set_version( WPINV_VERSION );
76
+        $discount->set_date_created( current_time('mysql') );
77
+
78
+        // Create a new post.
79
+        $id = wp_insert_post(
80
+            apply_filters(
81
+                'getpaid_new_discount_data',
82
+                array(
83
+                    'post_date'     => $discount->get_date_created( 'edit' ),
84
+                    'post_type'     => 'wpi_discount',
85
+                    'post_status'   => $this->get_post_status( $discount ),
86
+                    'ping_status'   => 'closed',
87
+                    'post_author'   => $discount->get_author( 'edit' ),
88
+                    'post_title'    => $discount->get_name( 'edit' ),
89
+                    'post_excerpt'  => $discount->get_description( 'edit' ),
90
+                )
91
+            ),
92
+            true
93
+        );
94
+
95
+        if ( $id && ! is_wp_error( $id ) ) {
96
+            $discount->set_id( $id );
97
+            $this->update_post_meta( $discount );
98
+            $discount->save_meta_data();
99
+            $discount->apply_changes();
100
+            $this->clear_caches( $discount );
101
+            do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
102
+            return true;
103
+        }
104
+
105
+        if ( is_wp_error( $id ) ) {
106
+            $discount->last_error = $id->get_error_message();
107
+        }
108
+
109
+        return false;
110
+    }
111
+
112
+    /**
113
+     * Method to read a discount from the database.
114
+     *
115
+     * @param WPInv_Discount $discount Discount object.
116
+     *
117
+     */
118
+    public function read( &$discount ) {
119
+
120
+        $discount->set_defaults();
121
+        $discount_object = get_post( $discount->get_id() );
122
+
123
+        if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
+            $discount->last_error = __( 'Invalid discount.', 'invoicing' );
125
+            return false;
126
+        }
127
+
128
+        $discount->set_props(
129
+            array(
130
+                'date_created'  => 0 < $discount_object->post_date ? $discount_object->post_date : null,
131
+                'date_modified' => 0 < $discount_object->post_modified ? $discount_object->post_modified : null,
132
+                'status'        => $discount_object->post_status,
133
+                'name'          => $discount_object->post_title,
134
+                'author'        => $discount_object->post_author,
135
+                'description'   => $discount_object->post_excerpt,
136
+            )
137
+        );
138
+
139
+        $this->read_object_data( $discount, $discount_object );
140
+        $discount->read_meta_data();
141
+        $discount->set_object_read( true );
142
+        do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
143
+
144
+    }
145
+
146
+    /**
147
+     * Method to update a discount in the database.
148
+     *
149
+     * @param WPInv_Discount $discount Discount object.
150
+     */
151
+    public function update( &$discount ) {
152
+        $discount->save_meta_data();
153
+        $discount->set_version( WPINV_VERSION );
154
+
155
+        if ( null === $discount->get_date_created( 'edit' ) ) {
156
+            $discount->set_date_created(  current_time('mysql') );
157
+        }
158
+
159
+        // Grab the current status so we can compare.
160
+        $previous_status = get_post_status( $discount->get_id() );
161
+
162
+        $changes = $discount->get_changes();
163
+
164
+        // Only update the post when the post data changes.
165
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
166
+            $post_data = array(
167
+                'post_date'         => $discount->get_date_created( 'edit' ),
168
+                'post_status'       => $discount->get_status( 'edit' ),
169
+                'post_title'        => $discount->get_name( 'edit' ),
170
+                'post_author'       => $discount->get_author( 'edit' ),
171
+                'post_modified'     => $discount->get_date_modified( 'edit' ),
172
+                'post_excerpt'      => $discount->get_description( 'edit' ),
173
+            );
174
+
175
+            /**
176
+             * When updating this object, to prevent infinite loops, use $wpdb
177
+             * to update data, since wp_update_post spawns more calls to the
178
+             * save_post action.
179
+             *
180
+             * This ensures hooks are fired by either WP itself (admin screen save),
181
+             * or an update purely from CRUD.
182
+             */
183
+            if ( doing_action( 'save_post' ) ) {
184
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
185
+                clean_post_cache( $discount->get_id() );
186
+            } else {
187
+                wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
188
+            }
189
+            $discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
190
+        }
191
+        $this->update_post_meta( $discount );
192
+        $discount->apply_changes();
193
+        $this->clear_caches( $discount );
194
+
195
+        // Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
+        $new_status = $discount->get_status( 'edit' );
197
+
198
+        if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
+            do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
200
+        } else {
201
+            do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
202
+        }
203
+
204
+    }
205
+
206
+    /*
207 207
 	|--------------------------------------------------------------------------
208 208
 	| Additional Methods
209 209
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
Spacing   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  * GetPaid_Discount_Data_Store class file.
5 5
  *
6 6
  */
7
-if ( ! defined( 'ABSPATH' ) ) {
7
+if (!defined('ABSPATH')) {
8 8
 	exit;
9 9
 }
10 10
 
@@ -71,38 +71,38 @@  discard block
 block discarded – undo
71 71
 	 *
72 72
 	 * @param WPInv_Discount $discount Discount object.
73 73
 	 */
74
-	public function create( &$discount ) {
75
-		$discount->set_version( WPINV_VERSION );
76
-		$discount->set_date_created( current_time('mysql') );
74
+	public function create(&$discount) {
75
+		$discount->set_version(WPINV_VERSION);
76
+		$discount->set_date_created(current_time('mysql'));
77 77
 
78 78
 		// Create a new post.
79 79
 		$id = wp_insert_post(
80 80
 			apply_filters(
81 81
 				'getpaid_new_discount_data',
82 82
 				array(
83
-					'post_date'     => $discount->get_date_created( 'edit' ),
83
+					'post_date'     => $discount->get_date_created('edit'),
84 84
 					'post_type'     => 'wpi_discount',
85
-					'post_status'   => $this->get_post_status( $discount ),
85
+					'post_status'   => $this->get_post_status($discount),
86 86
 					'ping_status'   => 'closed',
87
-					'post_author'   => $discount->get_author( 'edit' ),
88
-					'post_title'    => $discount->get_name( 'edit' ),
89
-					'post_excerpt'  => $discount->get_description( 'edit' ),
87
+					'post_author'   => $discount->get_author('edit'),
88
+					'post_title'    => $discount->get_name('edit'),
89
+					'post_excerpt'  => $discount->get_description('edit'),
90 90
 				)
91 91
 			),
92 92
 			true
93 93
 		);
94 94
 
95
-		if ( $id && ! is_wp_error( $id ) ) {
96
-			$discount->set_id( $id );
97
-			$this->update_post_meta( $discount );
95
+		if ($id && !is_wp_error($id)) {
96
+			$discount->set_id($id);
97
+			$this->update_post_meta($discount);
98 98
 			$discount->save_meta_data();
99 99
 			$discount->apply_changes();
100
-			$this->clear_caches( $discount );
101
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
100
+			$this->clear_caches($discount);
101
+			do_action('getpaid_new_discount', $discount->get_id(), $discount);
102 102
 			return true;
103 103
 		}
104 104
 
105
-		if ( is_wp_error( $id ) ) {
105
+		if (is_wp_error($id)) {
106 106
 			$discount->last_error = $id->get_error_message();
107 107
 		}
108 108
 
@@ -115,13 +115,13 @@  discard block
 block discarded – undo
115 115
 	 * @param WPInv_Discount $discount Discount object.
116 116
 	 *
117 117
 	 */
118
-	public function read( &$discount ) {
118
+	public function read(&$discount) {
119 119
 
120 120
 		$discount->set_defaults();
121
-		$discount_object = get_post( $discount->get_id() );
121
+		$discount_object = get_post($discount->get_id());
122 122
 
123
-		if ( ! $discount->get_id() || ! $discount_object || $discount_object->post_type != 'wpi_discount' ) {
124
-			$discount->last_error = __( 'Invalid discount.', 'invoicing' );
123
+		if (!$discount->get_id() || !$discount_object || $discount_object->post_type != 'wpi_discount') {
124
+			$discount->last_error = __('Invalid discount.', 'invoicing');
125 125
 			return false;
126 126
 		}
127 127
 
@@ -136,10 +136,10 @@  discard block
 block discarded – undo
136 136
 			)
137 137
 		);
138 138
 
139
-		$this->read_object_data( $discount, $discount_object );
139
+		$this->read_object_data($discount, $discount_object);
140 140
 		$discount->read_meta_data();
141
-		$discount->set_object_read( true );
142
-		do_action( 'getpaid_read_discount', $discount->get_id(), $discount );
141
+		$discount->set_object_read(true);
142
+		do_action('getpaid_read_discount', $discount->get_id(), $discount);
143 143
 
144 144
 	}
145 145
 
@@ -148,28 +148,28 @@  discard block
 block discarded – undo
148 148
 	 *
149 149
 	 * @param WPInv_Discount $discount Discount object.
150 150
 	 */
151
-	public function update( &$discount ) {
151
+	public function update(&$discount) {
152 152
 		$discount->save_meta_data();
153
-		$discount->set_version( WPINV_VERSION );
153
+		$discount->set_version(WPINV_VERSION);
154 154
 
155
-		if ( null === $discount->get_date_created( 'edit' ) ) {
156
-			$discount->set_date_created(  current_time('mysql') );
155
+		if (null === $discount->get_date_created('edit')) {
156
+			$discount->set_date_created(current_time('mysql'));
157 157
 		}
158 158
 
159 159
 		// Grab the current status so we can compare.
160
-		$previous_status = get_post_status( $discount->get_id() );
160
+		$previous_status = get_post_status($discount->get_id());
161 161
 
162 162
 		$changes = $discount->get_changes();
163 163
 
164 164
 		// Only update the post when the post data changes.
165
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt' ), array_keys( $changes ) ) ) {
165
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'name', 'author', 'post_excerpt'), array_keys($changes))) {
166 166
 			$post_data = array(
167
-				'post_date'         => $discount->get_date_created( 'edit' ),
168
-				'post_status'       => $discount->get_status( 'edit' ),
169
-				'post_title'        => $discount->get_name( 'edit' ),
170
-				'post_author'       => $discount->get_author( 'edit' ),
171
-				'post_modified'     => $discount->get_date_modified( 'edit' ),
172
-				'post_excerpt'      => $discount->get_description( 'edit' ),
167
+				'post_date'         => $discount->get_date_created('edit'),
168
+				'post_status'       => $discount->get_status('edit'),
169
+				'post_title'        => $discount->get_name('edit'),
170
+				'post_author'       => $discount->get_author('edit'),
171
+				'post_modified'     => $discount->get_date_modified('edit'),
172
+				'post_excerpt'      => $discount->get_description('edit'),
173 173
 			);
174 174
 
175 175
 			/**
@@ -180,25 +180,25 @@  discard block
 block discarded – undo
180 180
 			 * This ensures hooks are fired by either WP itself (admin screen save),
181 181
 			 * or an update purely from CRUD.
182 182
 			 */
183
-			if ( doing_action( 'save_post' ) ) {
184
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $discount->get_id() ) );
185
-				clean_post_cache( $discount->get_id() );
183
+			if (doing_action('save_post')) {
184
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $discount->get_id()));
185
+				clean_post_cache($discount->get_id());
186 186
 			} else {
187
-				wp_update_post( array_merge( array( 'ID' => $discount->get_id() ), $post_data ) );
187
+				wp_update_post(array_merge(array('ID' => $discount->get_id()), $post_data));
188 188
 			}
189
-			$discount->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
189
+			$discount->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
190 190
 		}
191
-		$this->update_post_meta( $discount );
191
+		$this->update_post_meta($discount);
192 192
 		$discount->apply_changes();
193
-		$this->clear_caches( $discount );
193
+		$this->clear_caches($discount);
194 194
 
195 195
 		// Fire a hook depending on the status - this should be considered a creation if it was previously draft status.
196
-		$new_status = $discount->get_status( 'edit' );
196
+		$new_status = $discount->get_status('edit');
197 197
 
198
-		if ( $new_status !== $previous_status && in_array( $previous_status, array( 'new', 'auto-draft', 'draft' ), true ) ) {
199
-			do_action( 'getpaid_new_discount', $discount->get_id(), $discount );
198
+		if ($new_status !== $previous_status && in_array($previous_status, array('new', 'auto-draft', 'draft'), true)) {
199
+			do_action('getpaid_new_discount', $discount->get_id(), $discount);
200 200
 		} else {
201
-			do_action( 'getpaid_update_discount', $discount->get_id(), $discount );
201
+			do_action('getpaid_update_discount', $discount->get_id(), $discount);
202 202
 		}
203 203
 
204 204
 	}
Please login to merge, or discard this patch.
includes/class-getpaid-form-item.php 2 patches
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,53 +10,53 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item  extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = '';
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var int
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Is this item required?
28
-	 *
29
-	 * @var int
30
-	 */
31
-	protected $is_required = true;
32
-
33
-	/**
34
-	 * Are quantities allowed?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $allow_quantities = false;
39
-
40
-	/**
41
-	 * Associated invoice.
42
-	 *
43
-	 * @var int
44
-	 */
45
-	public $invoice_id = 0;
46
-
47
-	/**
48
-	 * Item discount.
49
-	 *
50
-	 * @var float
51
-	 */
52
-	public $item_discount = 0;
53
-
54
-	/**
55
-	 * Item tax.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_tax = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = '';
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var int
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Is this item required?
28
+     *
29
+     * @var int
30
+     */
31
+    protected $is_required = true;
32
+
33
+    /**
34
+     * Are quantities allowed?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $allow_quantities = false;
39
+
40
+    /**
41
+     * Associated invoice.
42
+     *
43
+     * @var int
44
+     */
45
+    public $invoice_id = 0;
46
+
47
+    /**
48
+     * Item discount.
49
+     *
50
+     * @var float
51
+     */
52
+    public $item_discount = 0;
53
+
54
+    /**
55
+     * Item tax.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_tax = 0;
60 60
 
61 61
     /*
62 62
 	|--------------------------------------------------------------------------
@@ -74,160 +74,160 @@  discard block
 block discarded – undo
74 74
     */
75 75
 
76 76
     /**
77
-	 * Get the item name.
78
-	 *
79
-	 * @since 1.0.19
80
-	 * @param  string $context View or edit context.
81
-	 * @return string
82
-	 */
83
-	public function get_name( $context = 'view' ) {
84
-		$name = parent::get_name( $context );
85
-		return $name . wpinv_get_item_suffix( $this );
86
-	}
87
-
88
-	/**
89
-	 * Get the item description.
90
-	 *
91
-	 * @since 1.0.19
92
-	 * @param  string $context View or edit context.
93
-	 * @return string
94
-	 */
95
-	public function get_description( $context = 'view' ) {
96
-
97
-		if ( ! empty( $this->custom_description ) ) {
98
-			return $this->custom_description;
99
-		}
100
-
101
-		return parent::get_description( $context );
102
-	}
103
-
104
-	/**
105
-	 * Returns the sub total.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @param  string $context View or edit context.
109
-	 * @return int
110
-	 */
111
-	public function get_sub_total( $context = 'view' ) {
112
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
113
-	}
114
-
115
-	/**
116
-	 * Returns the recurring sub total.
117
-	 *
118
-	 * @since 1.0.19
119
-	 * @param  string $context View or edit context.
120
-	 * @return int
121
-	 */
122
-	public function get_recurring_sub_total( $context = 'view' ) {
123
-		return $this->get_quantity( $context ) * $this->get_price( $context );
124
-	}
125
-
126
-	/**
127
-	 * @deprecated
128
-	 */
129
-	public function get_qantity( $context = 'view' ) {
130
-		return $this->get_quantity( $context );
131
-	}
132
-
133
-	/**
134
-	 * Get the item quantity.
135
-	 *
136
-	 * @since 1.0.19
137
-	 * @param  string $context View or edit context.
138
-	 * @return int
139
-	 */
140
-	public function get_quantity( $context = 'view' ) {
141
-		$quantity = (int) $this->quantity;
142
-
143
-		if ( empty( $quantity ) || 1 > $quantity ) {
144
-			$quantity = 1;
145
-		}
146
-
147
-		if ( 'view' == $context ) {
148
-			return apply_filters( 'getpaid_payment_form_item_quanity', $quantity, $this );
149
-		}
150
-
151
-		return $quantity;
152
-
153
-	}
154
-
155
-	/**
156
-	 * Returns whether or not customers can update the item quantity.
157
-	 *
158
-	 * @since 1.0.19
159
-	 * @param  string $context View or edit context.
160
-	 * @return bool
161
-	 */
162
-	public function get_allow_quantities( $context = 'view' ) {
163
-		$allow_quantities = (bool) $this->allow_quantities;
164
-
165
-		if ( 'view' == $context ) {
166
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
167
-		}
168
-
169
-		return $allow_quantities;
170
-
171
-	}
172
-
173
-	/**
174
-	 * Returns whether or not the item is required.
175
-	 *
176
-	 * @since 1.0.19
177
-	 * @param  string $context View or edit context.
178
-	 * @return bool
179
-	 */
180
-	public function get_is_required( $context = 'view' ) {
181
-		$is_required = (bool) $this->is_required;
182
-
183
-		if ( 'view' == $context ) {
184
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
185
-		}
186
-
187
-		return $is_required;
188
-
189
-	}
190
-
191
-	/**
192
-	 * Prepares form data for use.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @return array
196
-	 */
197
-	public function prepare_data_for_use() {
198
-
199
-		return array(
200
-			'title'            => sanitize_text_field( $this->get_name() ),
201
-			'id'               => $this->get_id(),
202
-			'price'            => $this->get_price(),
203
-			'recurring'        => $this->is_recurring(),
204
-			'description'      => $this->get_description(),
205
-			'allow_quantities' => $this->allows_quantities(),
206
-			'required'         => $this->is_required(),
77
+     * Get the item name.
78
+     *
79
+     * @since 1.0.19
80
+     * @param  string $context View or edit context.
81
+     * @return string
82
+     */
83
+    public function get_name( $context = 'view' ) {
84
+        $name = parent::get_name( $context );
85
+        return $name . wpinv_get_item_suffix( $this );
86
+    }
87
+
88
+    /**
89
+     * Get the item description.
90
+     *
91
+     * @since 1.0.19
92
+     * @param  string $context View or edit context.
93
+     * @return string
94
+     */
95
+    public function get_description( $context = 'view' ) {
96
+
97
+        if ( ! empty( $this->custom_description ) ) {
98
+            return $this->custom_description;
99
+        }
100
+
101
+        return parent::get_description( $context );
102
+    }
103
+
104
+    /**
105
+     * Returns the sub total.
106
+     *
107
+     * @since 1.0.19
108
+     * @param  string $context View or edit context.
109
+     * @return int
110
+     */
111
+    public function get_sub_total( $context = 'view' ) {
112
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context );
113
+    }
114
+
115
+    /**
116
+     * Returns the recurring sub total.
117
+     *
118
+     * @since 1.0.19
119
+     * @param  string $context View or edit context.
120
+     * @return int
121
+     */
122
+    public function get_recurring_sub_total( $context = 'view' ) {
123
+        return $this->get_quantity( $context ) * $this->get_price( $context );
124
+    }
125
+
126
+    /**
127
+     * @deprecated
128
+     */
129
+    public function get_qantity( $context = 'view' ) {
130
+        return $this->get_quantity( $context );
131
+    }
132
+
133
+    /**
134
+     * Get the item quantity.
135
+     *
136
+     * @since 1.0.19
137
+     * @param  string $context View or edit context.
138
+     * @return int
139
+     */
140
+    public function get_quantity( $context = 'view' ) {
141
+        $quantity = (int) $this->quantity;
142
+
143
+        if ( empty( $quantity ) || 1 > $quantity ) {
144
+            $quantity = 1;
145
+        }
146
+
147
+        if ( 'view' == $context ) {
148
+            return apply_filters( 'getpaid_payment_form_item_quanity', $quantity, $this );
149
+        }
150
+
151
+        return $quantity;
152
+
153
+    }
154
+
155
+    /**
156
+     * Returns whether or not customers can update the item quantity.
157
+     *
158
+     * @since 1.0.19
159
+     * @param  string $context View or edit context.
160
+     * @return bool
161
+     */
162
+    public function get_allow_quantities( $context = 'view' ) {
163
+        $allow_quantities = (bool) $this->allow_quantities;
164
+
165
+        if ( 'view' == $context ) {
166
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
167
+        }
168
+
169
+        return $allow_quantities;
170
+
171
+    }
172
+
173
+    /**
174
+     * Returns whether or not the item is required.
175
+     *
176
+     * @since 1.0.19
177
+     * @param  string $context View or edit context.
178
+     * @return bool
179
+     */
180
+    public function get_is_required( $context = 'view' ) {
181
+        $is_required = (bool) $this->is_required;
182
+
183
+        if ( 'view' == $context ) {
184
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
185
+        }
186
+
187
+        return $is_required;
188
+
189
+    }
190
+
191
+    /**
192
+     * Prepares form data for use.
193
+     *
194
+     * @since 1.0.19
195
+     * @return array
196
+     */
197
+    public function prepare_data_for_use() {
198
+
199
+        return array(
200
+            'title'            => sanitize_text_field( $this->get_name() ),
201
+            'id'               => $this->get_id(),
202
+            'price'            => $this->get_price(),
203
+            'recurring'        => $this->is_recurring(),
204
+            'description'      => $this->get_description(),
205
+            'allow_quantities' => $this->allows_quantities(),
206
+            'required'         => $this->is_required(),
207 207
         );
208
-	}
209
-
210
-	/**
211
-	 * Prepares form data for saving (cart_details).
212
-	 *
213
-	 * @since 1.0.19
214
-	 * @return array
215
-	 */
216
-	public function prepare_data_for_saving() {
217
-
218
-		return array(
219
-			'post_id'           => $this->invoice_id,
220
-			'item_id'           => $this->get_id(),
221
-			'item_name'         => sanitize_text_field( $this->get_name() ),
222
-			'item_description'  => $this->get_description(),
223
-			'tax'               => $this->item_tax,
224
-			'item_price'        => $this->get_price(),
225
-			'quantity'          => (int) $this->get_quantity(),
226
-			'discount'          => $this->item_discount,
227
-			'subtotal'          => $this->get_sub_total(),
228
-			'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount
208
+    }
209
+
210
+    /**
211
+     * Prepares form data for saving (cart_details).
212
+     *
213
+     * @since 1.0.19
214
+     * @return array
215
+     */
216
+    public function prepare_data_for_saving() {
217
+
218
+        return array(
219
+            'post_id'           => $this->invoice_id,
220
+            'item_id'           => $this->get_id(),
221
+            'item_name'         => sanitize_text_field( $this->get_name() ),
222
+            'item_description'  => $this->get_description(),
223
+            'tax'               => $this->item_tax,
224
+            'item_price'        => $this->get_price(),
225
+            'quantity'          => (int) $this->get_quantity(),
226
+            'discount'          => $this->item_discount,
227
+            'subtotal'          => $this->get_sub_total(),
228
+            'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount
229 229
         );
230
-	}
230
+    }
231 231
 
232 232
     /*
233 233
 	|--------------------------------------------------------------------------
@@ -239,60 +239,60 @@  discard block
 block discarded – undo
239 239
 	| object.
240 240
     */
241 241
 
242
-	/**
243
-	 * Set the item qantity.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  int $quantity The item quantity.
247
-	 */
248
-	public function set_quantity( $quantity ) {
249
-
250
-		if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
251
-			$quantity = 1;
252
-		}
253
-
254
-		$this->quantity = $quantity;
255
-
256
-	}
257
-
258
-	/**
259
-	 * Set whether or not the quantities are allowed.
260
-	 *
261
-	 * @since 1.0.19
262
-	 * @param  bool $allow_quantities
263
-	 */
264
-	public function set_allow_quantities( $allow_quantities ) {
265
-		$this->allow_quantities = (bool) $allow_quantities;
266
-	}
267
-
268
-	/**
269
-	 * Set whether or not the item is required.
270
-	 *
271
-	 * @since 1.0.19
272
-	 * @param  bool $is_required
273
-	 */
274
-	public function set_is_required( $is_required ) {
275
-		$this->is_required = (bool) $is_required;
276
-	}
277
-
278
-	/**
279
-	 * Sets the custom item description.
280
-	 *
281
-	 * @since 1.0.19
282
-	 * @param  string $description
283
-	 */
284
-	public function set_custom_description( $description ) {
285
-		$this->custom_description = $description;
286
-	}
242
+    /**
243
+     * Set the item qantity.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  int $quantity The item quantity.
247
+     */
248
+    public function set_quantity( $quantity ) {
249
+
250
+        if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
251
+            $quantity = 1;
252
+        }
253
+
254
+        $this->quantity = $quantity;
255
+
256
+    }
257
+
258
+    /**
259
+     * Set whether or not the quantities are allowed.
260
+     *
261
+     * @since 1.0.19
262
+     * @param  bool $allow_quantities
263
+     */
264
+    public function set_allow_quantities( $allow_quantities ) {
265
+        $this->allow_quantities = (bool) $allow_quantities;
266
+    }
267
+
268
+    /**
269
+     * Set whether or not the item is required.
270
+     *
271
+     * @since 1.0.19
272
+     * @param  bool $is_required
273
+     */
274
+    public function set_is_required( $is_required ) {
275
+        $this->is_required = (bool) $is_required;
276
+    }
277
+
278
+    /**
279
+     * Sets the custom item description.
280
+     *
281
+     * @since 1.0.19
282
+     * @param  string $description
283
+     */
284
+    public function set_custom_description( $description ) {
285
+        $this->custom_description = $description;
286
+    }
287 287
 
288 288
     /**
289 289
      * We do not want to save items to the database.
290 290
      * 
291
-	 * @return int item id
291
+     * @return int item id
292 292
      */
293 293
     public function save( $data = array() ) {
294 294
         return $this->get_id();
295
-	}
295
+    }
296 296
 
297 297
     /*
298 298
 	|--------------------------------------------------------------------------
@@ -304,23 +304,23 @@  discard block
 block discarded – undo
304 304
 	*/
305 305
 
306 306
     /**
307
-	 * Checks whether the item has enabled dynamic pricing.
308
-	 *
309
-	 * @since 1.0.19
310
-	 * @return bool
311
-	 */
312
-	public function is_required() {
307
+     * Checks whether the item has enabled dynamic pricing.
308
+     *
309
+     * @since 1.0.19
310
+     * @return bool
311
+     */
312
+    public function is_required() {
313 313
         return (bool) $this->get_is_required();
314
-	}
315
-
316
-	/**
317
-	 * Checks whether users can edit the quantities.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @return bool
321
-	 */
322
-	public function allows_quantities() {
314
+    }
315
+
316
+    /**
317
+     * Checks whether users can edit the quantities.
318
+     *
319
+     * @since 1.0.19
320
+     * @return bool
321
+     */
322
+    public function allows_quantities() {
323 323
         return (bool) $this->get_allow_quantities();
324
-	}
324
+    }
325 325
 
326 326
 }
Please login to merge, or discard this patch.
Spacing   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -80,9 +80,9 @@  discard block
 block discarded – undo
80 80
 	 * @param  string $context View or edit context.
81 81
 	 * @return string
82 82
 	 */
83
-	public function get_name( $context = 'view' ) {
84
-		$name = parent::get_name( $context );
85
-		return $name . wpinv_get_item_suffix( $this );
83
+	public function get_name($context = 'view') {
84
+		$name = parent::get_name($context);
85
+		return $name . wpinv_get_item_suffix($this);
86 86
 	}
87 87
 
88 88
 	/**
@@ -92,13 +92,13 @@  discard block
 block discarded – undo
92 92
 	 * @param  string $context View or edit context.
93 93
 	 * @return string
94 94
 	 */
95
-	public function get_description( $context = 'view' ) {
95
+	public function get_description($context = 'view') {
96 96
 
97
-		if ( ! empty( $this->custom_description ) ) {
97
+		if (!empty($this->custom_description)) {
98 98
 			return $this->custom_description;
99 99
 		}
100 100
 
101
-		return parent::get_description( $context );
101
+		return parent::get_description($context);
102 102
 	}
103 103
 
104 104
 	/**
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	 * @param  string $context View or edit context.
109 109
 	 * @return int
110 110
 	 */
111
-	public function get_sub_total( $context = 'view' ) {
112
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
111
+	public function get_sub_total($context = 'view') {
112
+		return $this->get_quantity($context) * $this->get_initial_price($context);
113 113
 	}
114 114
 
115 115
 	/**
@@ -119,15 +119,15 @@  discard block
 block discarded – undo
119 119
 	 * @param  string $context View or edit context.
120 120
 	 * @return int
121 121
 	 */
122
-	public function get_recurring_sub_total( $context = 'view' ) {
123
-		return $this->get_quantity( $context ) * $this->get_price( $context );
122
+	public function get_recurring_sub_total($context = 'view') {
123
+		return $this->get_quantity($context) * $this->get_price($context);
124 124
 	}
125 125
 
126 126
 	/**
127 127
 	 * @deprecated
128 128
 	 */
129
-	public function get_qantity( $context = 'view' ) {
130
-		return $this->get_quantity( $context );
129
+	public function get_qantity($context = 'view') {
130
+		return $this->get_quantity($context);
131 131
 	}
132 132
 
133 133
 	/**
@@ -137,15 +137,15 @@  discard block
 block discarded – undo
137 137
 	 * @param  string $context View or edit context.
138 138
 	 * @return int
139 139
 	 */
140
-	public function get_quantity( $context = 'view' ) {
140
+	public function get_quantity($context = 'view') {
141 141
 		$quantity = (int) $this->quantity;
142 142
 
143
-		if ( empty( $quantity ) || 1 > $quantity ) {
143
+		if (empty($quantity) || 1 > $quantity) {
144 144
 			$quantity = 1;
145 145
 		}
146 146
 
147
-		if ( 'view' == $context ) {
148
-			return apply_filters( 'getpaid_payment_form_item_quanity', $quantity, $this );
147
+		if ('view' == $context) {
148
+			return apply_filters('getpaid_payment_form_item_quanity', $quantity, $this);
149 149
 		}
150 150
 
151 151
 		return $quantity;
@@ -159,11 +159,11 @@  discard block
 block discarded – undo
159 159
 	 * @param  string $context View or edit context.
160 160
 	 * @return bool
161 161
 	 */
162
-	public function get_allow_quantities( $context = 'view' ) {
162
+	public function get_allow_quantities($context = 'view') {
163 163
 		$allow_quantities = (bool) $this->allow_quantities;
164 164
 
165
-		if ( 'view' == $context ) {
166
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
165
+		if ('view' == $context) {
166
+			return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this);
167 167
 		}
168 168
 
169 169
 		return $allow_quantities;
@@ -177,11 +177,11 @@  discard block
 block discarded – undo
177 177
 	 * @param  string $context View or edit context.
178 178
 	 * @return bool
179 179
 	 */
180
-	public function get_is_required( $context = 'view' ) {
180
+	public function get_is_required($context = 'view') {
181 181
 		$is_required = (bool) $this->is_required;
182 182
 
183
-		if ( 'view' == $context ) {
184
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
183
+		if ('view' == $context) {
184
+			return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this);
185 185
 		}
186 186
 
187 187
 		return $is_required;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	public function prepare_data_for_use() {
198 198
 
199 199
 		return array(
200
-			'title'            => sanitize_text_field( $this->get_name() ),
200
+			'title'            => sanitize_text_field($this->get_name()),
201 201
 			'id'               => $this->get_id(),
202 202
 			'price'            => $this->get_price(),
203 203
 			'recurring'        => $this->is_recurring(),
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
 		return array(
219 219
 			'post_id'           => $this->invoice_id,
220 220
 			'item_id'           => $this->get_id(),
221
-			'item_name'         => sanitize_text_field( $this->get_name() ),
221
+			'item_name'         => sanitize_text_field($this->get_name()),
222 222
 			'item_description'  => $this->get_description(),
223 223
 			'tax'               => $this->item_tax,
224 224
 			'item_price'        => $this->get_price(),
@@ -245,9 +245,9 @@  discard block
 block discarded – undo
245 245
 	 * @since 1.0.19
246 246
 	 * @param  int $quantity The item quantity.
247 247
 	 */
248
-	public function set_quantity( $quantity ) {
248
+	public function set_quantity($quantity) {
249 249
 
250
-		if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
250
+		if (empty($quantity) || !is_numeric($quantity)) {
251 251
 			$quantity = 1;
252 252
 		}
253 253
 
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
 	 * @since 1.0.19
262 262
 	 * @param  bool $allow_quantities
263 263
 	 */
264
-	public function set_allow_quantities( $allow_quantities ) {
264
+	public function set_allow_quantities($allow_quantities) {
265 265
 		$this->allow_quantities = (bool) $allow_quantities;
266 266
 	}
267 267
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 	 * @since 1.0.19
272 272
 	 * @param  bool $is_required
273 273
 	 */
274
-	public function set_is_required( $is_required ) {
274
+	public function set_is_required($is_required) {
275 275
 		$this->is_required = (bool) $is_required;
276 276
 	}
277 277
 
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
 	 * @since 1.0.19
282 282
 	 * @param  string $description
283 283
 	 */
284
-	public function set_custom_description( $description ) {
284
+	public function set_custom_description($description) {
285 285
 		$this->custom_description = $description;
286 286
 	}
287 287
 
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      * 
291 291
 	 * @return int item id
292 292
      */
293
-    public function save( $data = array() ) {
293
+    public function save($data = array()) {
294 294
         return $this->get_id();
295 295
 	}
296 296
 
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +807 added lines, -807 removed lines patch added patch discarded remove patch
@@ -7,8 +7,8 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 /**
@@ -16,24 +16,24 @@  discard block
 block discarded – undo
16 16
  */
17 17
 function getpaid_get_invoice_post_types() {
18 18
     $post_types = array(
19
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
20
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
19
+        'wpi_quote'   => __('Quote', 'invoicing'),
20
+        'wpi_invoice' => __('Invoice', 'invoicing'),
21 21
     );
22 22
     
23
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
23
+    return apply_filters('getpaid_invoice_post_types', $post_types);
24 24
 }
25 25
 
26 26
 /**
27 27
  * Checks if this is an invocing post type.
28 28
  */
29
-function getpaid_is_invoice_post_type( $post_type ) {
30
-    return array_key_exists( $post_type, getpaid_get_invoice_post_types() );
29
+function getpaid_is_invoice_post_type($post_type) {
30
+    return array_key_exists($post_type, getpaid_get_invoice_post_types());
31 31
 }
32 32
 
33 33
 function wpinv_get_invoice_cart_id() {
34 34
     $wpinv_checkout = wpinv_get_checkout_session();
35 35
     
36
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
36
+    if (!empty($wpinv_checkout['invoice_id'])) {
37 37
         return $wpinv_checkout['invoice_id'];
38 38
     }
39 39
     
@@ -47,48 +47,48 @@  discard block
 block discarded – undo
47 47
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
48 48
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
49 49
  */
50
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
51
-    if ( empty( $invoice_data ) ) {
50
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
51
+    if (empty($invoice_data)) {
52 52
         return false;
53 53
     }
54 54
     
55
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
56
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
55
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
56
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
57 57
     }
58 58
     
59 59
     // If no user id is provided, default to the current user id
60
-    if ( empty( $invoice_data['user_id'] ) ) {
60
+    if (empty($invoice_data['user_id'])) {
61 61
         $invoice_data['user_id'] = get_current_user_id();
62 62
     }
63 63
     
64
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
64
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
65 65
     
66
-    if ( empty( $invoice_data['status'] ) ) {
66
+    if (empty($invoice_data['status'])) {
67 67
         $invoice_data['status'] = 'wpi-pending';
68 68
     }
69 69
 
70
-    if ( empty( $invoice_data['post_type'] ) ) {
70
+    if (empty($invoice_data['post_type'])) {
71 71
         $invoice_data['post_type'] = 'wpi_invoice';
72 72
     }
73 73
     
74
-    if ( empty( $invoice_data['ip'] ) ) {
74
+    if (empty($invoice_data['ip'])) {
75 75
         $invoice_data['ip'] = wpinv_get_ip();
76 76
     }
77 77
 
78 78
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
79 79
     $default_args = array(
80
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
81
-        'user_id'       => (int)$invoice_data['user_id'],
80
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
81
+        'user_id'       => (int) $invoice_data['user_id'],
82 82
         'status'        => $invoice_data['status'],
83 83
         'post_type'     => $invoice_data['post_type'],
84 84
     );
85 85
 
86
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
87
-    if ( is_wp_error( $invoice ) ) {
86
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
87
+    if (is_wp_error($invoice)) {
88 88
         return $wp_error ? $invoice : 0;
89 89
     }
90 90
     
91
-    if ( empty( $invoice_data['invoice_id'] ) ) {
91
+    if (empty($invoice_data['invoice_id'])) {
92 92
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
93 93
     }
94 94
     
@@ -111,24 +111,24 @@  discard block
 block discarded – undo
111 111
         'discount'              => array(),
112 112
     );
113 113
 
114
-    if ( $user_id = (int)$invoice->get_user_id() ) {
115
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
116
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
114
+    if ($user_id = (int) $invoice->get_user_id()) {
115
+        if ($user_address = wpinv_get_user_address($user_id)) {
116
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
117 117
         }
118 118
     }
119 119
     
120
-    if ( empty( $invoice_data['user_info'] ) ) {
120
+    if (empty($invoice_data['user_info'])) {
121 121
         $invoice_data['user_info'] = array();
122 122
     }
123 123
     
124
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
124
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
125 125
     
126
-    if ( empty( $user_info['first_name'] ) ) {
126
+    if (empty($user_info['first_name'])) {
127 127
         $user_info['first_name'] = $default_user_info['first_name'];
128 128
         $user_info['last_name'] = $default_user_info['last_name'];
129 129
     }
130 130
     
131
-    if ( empty( $user_info['country'] ) ) {
131
+    if (empty($user_info['country'])) {
132 132
         $user_info['country'] = $default_user_info['country'];
133 133
         $user_info['state'] = $default_user_info['state'];
134 134
         $user_info['city'] = $default_user_info['city'];
@@ -137,13 +137,13 @@  discard block
 block discarded – undo
137 137
         $user_info['phone'] = $default_user_info['phone'];
138 138
     }
139 139
     
140
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
141
-        $user_info['discount'] = (array)$user_info['discount'];
140
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
141
+        $user_info['discount'] = (array) $user_info['discount'];
142 142
     }
143 143
 
144 144
     // Payment details
145 145
     $payment_details = array();
146
-    if ( !empty( $invoice_data['payment_details'] ) ) {
146
+    if (!empty($invoice_data['payment_details'])) {
147 147
         $default_payment_details = array(
148 148
             'gateway'           => 'manual',
149 149
             'gateway_title'     => '',
@@ -151,56 +151,56 @@  discard block
 block discarded – undo
151 151
             'transaction_id'    => '',
152 152
         );
153 153
         
154
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
154
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
155 155
         
156
-        if ( empty( $payment_details['gateway'] ) ) {
156
+        if (empty($payment_details['gateway'])) {
157 157
             $payment_details['gateway'] = 'manual';
158 158
         }
159 159
         
160
-        if ( empty( $payment_details['currency'] ) ) {
160
+        if (empty($payment_details['currency'])) {
161 161
             $payment_details['currency'] = wpinv_get_default_country();
162 162
         }
163 163
         
164
-        if ( empty( $payment_details['gateway_title'] ) ) {
165
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
164
+        if (empty($payment_details['gateway_title'])) {
165
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
166 166
         }
167 167
     }
168 168
     
169
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
170
-    
171
-    if ( !empty( $payment_details ) ) {
172
-        $invoice->set( 'currency', $payment_details['currency'] );
173
-        $invoice->set( 'gateway', $payment_details['gateway'] );
174
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
175
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
176
-    }
177
-    
178
-    $invoice->set( 'user_info', $user_info );
179
-    $invoice->set( 'first_name', $user_info['first_name'] );
180
-    $invoice->set( 'last_name', $user_info['last_name'] );
181
-    $invoice->set( 'address', $user_info['address'] );
182
-    $invoice->set( 'company', $user_info['company'] );
183
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
184
-    $invoice->set( 'phone', $user_info['phone'] );
185
-    $invoice->set( 'city', $user_info['city'] );
186
-    $invoice->set( 'country', $user_info['country'] );
187
-    $invoice->set( 'state', $user_info['state'] );
188
-    $invoice->set( 'zip', $user_info['zip'] );
189
-    $invoice->set( 'discounts', $user_info['discount'] );
190
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
191
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
192
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
193
-    
194
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
195
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
196
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
197
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
198
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
199
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
169
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
170
+    
171
+    if (!empty($payment_details)) {
172
+        $invoice->set('currency', $payment_details['currency']);
173
+        $invoice->set('gateway', $payment_details['gateway']);
174
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
175
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
176
+    }
177
+    
178
+    $invoice->set('user_info', $user_info);
179
+    $invoice->set('first_name', $user_info['first_name']);
180
+    $invoice->set('last_name', $user_info['last_name']);
181
+    $invoice->set('address', $user_info['address']);
182
+    $invoice->set('company', $user_info['company']);
183
+    $invoice->set('vat_number', $user_info['vat_number']);
184
+    $invoice->set('phone', $user_info['phone']);
185
+    $invoice->set('city', $user_info['city']);
186
+    $invoice->set('country', $user_info['country']);
187
+    $invoice->set('state', $user_info['state']);
188
+    $invoice->set('zip', $user_info['zip']);
189
+    $invoice->set('discounts', $user_info['discount']);
190
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
191
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
192
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
193
+    
194
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
195
+        foreach ($invoice_data['cart_details'] as $key => $item) {
196
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
197
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
198
+            $name           = !empty($item['name']) ? $item['name'] : '';
199
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
200 200
             
201
-            $post_item  = new WPInv_Item( $item_id );
202
-            if ( !empty( $post_item ) ) {
203
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
201
+            $post_item = new WPInv_Item($item_id);
202
+            if (!empty($post_item)) {
203
+                $name       = !empty($name) ? $name : $post_item->get_name();
204 204
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
205 205
             } else {
206 206
                 continue;
@@ -210,266 +210,266 @@  discard block
 block discarded – undo
210 210
                 'name'          => $name,
211 211
                 'quantity'      => $quantity,
212 212
                 'item_price'    => $item_price,
213
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
214
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
215
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
216
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
217
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
213
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
214
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
215
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
216
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
217
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
218 218
             );
219 219
 
220
-            $invoice->add_item( $item_id, $args );
220
+            $invoice->add_item($item_id, $args);
221 221
         }
222 222
     }
223 223
 
224
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
224
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
225 225
 
226
-    if ( isset( $invoice_data['post_date'] ) ) {
227
-        $invoice->set( 'date', $invoice_data['post_date'] );
226
+    if (isset($invoice_data['post_date'])) {
227
+        $invoice->set('date', $invoice_data['post_date']);
228 228
     }
229 229
     
230 230
     // Invoice due date
231
-    if ( isset( $invoice_data['due_date'] ) ) {
232
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
231
+    if (isset($invoice_data['due_date'])) {
232
+        $invoice->set('due_date', $invoice_data['due_date']);
233 233
     }
234 234
     
235 235
     $invoice->save();
236 236
     
237 237
     // Add notes
238
-    if ( !empty( $invoice_data['private_note'] ) ) {
239
-        $invoice->add_note( $invoice_data['private_note'] );
238
+    if (!empty($invoice_data['private_note'])) {
239
+        $invoice->add_note($invoice_data['private_note']);
240 240
     }
241
-    if ( !empty( $invoice_data['user_note'] ) ) {
242
-        $invoice->add_note( $invoice_data['user_note'], true );
241
+    if (!empty($invoice_data['user_note'])) {
242
+        $invoice->add_note($invoice_data['user_note'], true);
243 243
     }
244 244
     
245
-    if ( $invoice->is_quote() ) {
245
+    if ($invoice->is_quote()) {
246 246
 
247
-        if ( isset( $invoice_data['valid_until'] ) ) {
248
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
247
+        if (isset($invoice_data['valid_until'])) {
248
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
249 249
         }
250 250
         return $invoice;
251 251
 
252 252
     }
253 253
 
254
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
254
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
255 255
 
256
-    if ( ! empty( $invoice->ID ) ) {
256
+    if (!empty($invoice->ID)) {
257 257
         global $wpi_userID, $wpinv_ip_address_country;
258 258
         
259
-        if ( isset( $invoice_data['created_via'] ) ) {
260
-            update_post_meta( $invoice->ID, 'wpinv_created_via', $invoice_data['created_via'] );
259
+        if (isset($invoice_data['created_via'])) {
260
+            update_post_meta($invoice->ID, 'wpinv_created_via', $invoice_data['created_via']);
261 261
         }
262 262
 
263 263
         $checkout_session = wpinv_get_checkout_session();
264 264
         
265 265
         $data_session                   = array();
266 266
         $data_session['invoice_id']     = $invoice->ID;
267
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
267
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
268 268
         
269
-        wpinv_set_checkout_session( $data_session );
269
+        wpinv_set_checkout_session($data_session);
270 270
         
271
-        $wpi_userID         = (int)$invoice->get_user_id();
271
+        $wpi_userID         = (int) $invoice->get_user_id();
272 272
         
273
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
273
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
274 274
         $_POST['state']     = $invoice->state;
275 275
 
276
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
277
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
276
+        $invoice->set('country', sanitize_text_field($_POST['country']));
277
+        $invoice->set('state', sanitize_text_field($_POST['state']));
278 278
         
279 279
         $wpinv_ip_address_country = $invoice->country;
280 280
 
281
-        $invoice = $invoice->recalculate_totals( true );
281
+        $invoice = $invoice->recalculate_totals(true);
282 282
 
283
-        wpinv_set_checkout_session( $checkout_session );
283
+        wpinv_set_checkout_session($checkout_session);
284 284
 
285 285
         return $invoice;
286 286
     }
287 287
     
288
-    if ( $wp_error ) {
289
-        if ( is_wp_error( $invoice ) ) {
288
+    if ($wp_error) {
289
+        if (is_wp_error($invoice)) {
290 290
             return $invoice;
291 291
         } else {
292
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
292
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
293 293
         }
294 294
     } else {
295 295
         return 0;
296 296
     }
297 297
 }
298 298
 
299
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
300
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
299
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
300
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
301 301
 
302
-    if ( !$invoice_ID ) {
303
-        if ( $wp_error ) {
304
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
302
+    if (!$invoice_ID) {
303
+        if ($wp_error) {
304
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
305 305
         }
306 306
         return 0;
307 307
     }
308 308
 
309
-    $invoice = wpinv_get_invoice( $invoice_ID );
309
+    $invoice = wpinv_get_invoice($invoice_ID);
310 310
 
311
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
311
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
312 312
 
313
-    if ( empty( $invoice->ID ) ) {
314
-        if ( $wp_error ) {
315
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
313
+    if (empty($invoice->ID)) {
314
+        if ($wp_error) {
315
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
316 316
         }
317 317
         return 0;
318 318
     }
319 319
 
320
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
321
-        if ( $wp_error ) {
322
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
320
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
321
+        if ($wp_error) {
322
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
323 323
         }
324 324
         return 0;
325 325
     }
326 326
 
327 327
     // Invoice status
328
-    if ( !empty( $invoice_data['status'] ) ) {
329
-        $invoice->set( 'status', $invoice_data['status'] );
328
+    if (!empty($invoice_data['status'])) {
329
+        $invoice->set('status', $invoice_data['status']);
330 330
     }
331 331
 
332 332
     // Invoice date
333
-    if ( !empty( $invoice_data['post_date'] ) ) {
334
-        $invoice->set( 'date', $invoice_data['post_date'] );
333
+    if (!empty($invoice_data['post_date'])) {
334
+        $invoice->set('date', $invoice_data['post_date']);
335 335
     }
336 336
 
337 337
     // Invoice due date
338
-    if ( isset( $invoice_data['due_date'] ) ) {
339
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
338
+    if (isset($invoice_data['due_date'])) {
339
+        $invoice->set('due_date', $invoice_data['due_date']);
340 340
     }
341 341
 
342 342
     // Invoice IP address
343
-    if ( !empty( $invoice_data['ip'] ) ) {
344
-        $invoice->set( 'ip', $invoice_data['ip'] );
343
+    if (!empty($invoice_data['ip'])) {
344
+        $invoice->set('ip', $invoice_data['ip']);
345 345
     }
346 346
     
347 347
     // User info
348
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
349
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
348
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
349
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
350 350
 
351
-        if ( $discounts = $invoice->get_discounts() ) {
351
+        if ($discounts = $invoice->get_discounts()) {
352 352
             $set_discount = $discounts;
353 353
         } else {
354 354
             $set_discount = '';
355 355
         }
356 356
 
357 357
         // Manage discount
358
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
358
+        if (!empty($invoice_data['user_info']['discount'])) {
359 359
             // Remove discount
360
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
360
+            if ($invoice_data['user_info']['discount'] == 'none') {
361 361
                 $set_discount = '';
362 362
             } else {
363 363
                 $set_discount = $invoice_data['user_info']['discount'];
364 364
             }
365 365
 
366
-            $invoice->set( 'discounts', $set_discount );
366
+            $invoice->set('discounts', $set_discount);
367 367
         }
368 368
 
369 369
         $user_info['discount'] = $set_discount;
370 370
 
371
-        $invoice->set( 'user_info', $user_info );
371
+        $invoice->set('user_info', $user_info);
372 372
     }
373 373
 
374
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
375
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
374
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
375
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
376 376
 
377
-        if ( !empty( $remove_items[0]['id'] ) ) {
378
-            foreach ( $remove_items as $item ) {
379
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
380
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
381
-                if ( empty( $item_id ) ) {
377
+        if (!empty($remove_items[0]['id'])) {
378
+            foreach ($remove_items as $item) {
379
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
380
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
381
+                if (empty($item_id)) {
382 382
                     continue;
383 383
                 }
384 384
 
385
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
386
-                    if ( $item_id == $cart_item['id'] ) {
385
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
386
+                    if ($item_id == $cart_item['id']) {
387 387
                         $args = array(
388 388
                             'id'         => $item_id,
389 389
                             'quantity'   => $quantity,
390 390
                             'cart_index' => $cart_index
391 391
                         );
392 392
 
393
-                        $invoice->remove_item( $item_id, $args );
393
+                        $invoice->remove_item($item_id, $args);
394 394
                         break;
395 395
                     }
396 396
                 }
397 397
             }
398 398
         }
399 399
 
400
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
400
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
401 401
 
402
-        if ( !empty( $add_items[0]['id'] ) ) {
403
-            foreach ( $add_items as $item ) {
404
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
405
-                $post_item      = new WPInv_Item( $item_id );
406
-                if ( empty( $post_item ) ) {
402
+        if (!empty($add_items[0]['id'])) {
403
+            foreach ($add_items as $item) {
404
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
405
+                $post_item      = new WPInv_Item($item_id);
406
+                if (empty($post_item)) {
407 407
                     continue;
408 408
                 }
409 409
 
410 410
                 $valid_item = true;
411
-                if ( !empty( $recurring_item ) ) {
412
-                    if ( $recurring_item->ID != $item_id ) {
411
+                if (!empty($recurring_item)) {
412
+                    if ($recurring_item->ID != $item_id) {
413 413
                         $valid_item = false;
414 414
                     }
415
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
415
+                } else if (wpinv_is_recurring_item($item_id)) {
416 416
                     $valid_item = false;
417 417
                 }
418 418
                 
419
-                if ( !$valid_item ) {
420
-                    if ( $wp_error ) {
421
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
419
+                if (!$valid_item) {
420
+                    if ($wp_error) {
421
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
422 422
                     }
423 423
                     return 0;
424 424
                 }
425 425
 
426
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
427
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
428
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
426
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
427
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
428
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
429 429
 
430 430
                 $args = array(
431 431
                     'name'          => $name,
432 432
                     'quantity'      => $quantity,
433 433
                     'item_price'    => $item_price,
434
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
435
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
436
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
437
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
438
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
434
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
435
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
436
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
437
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
438
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
439 439
                 );
440 440
 
441
-                $invoice->add_item( $item_id, $args );
441
+                $invoice->add_item($item_id, $args);
442 442
             }
443 443
         }
444 444
     }
445 445
     
446 446
     // Payment details
447
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
448
-        if ( !empty( $payment_details['gateway'] ) ) {
449
-            $invoice->set( 'gateway', $payment_details['gateway'] );
447
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
448
+        if (!empty($payment_details['gateway'])) {
449
+            $invoice->set('gateway', $payment_details['gateway']);
450 450
         }
451 451
 
452
-        if ( !empty( $payment_details['transaction_id'] ) ) {
453
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
452
+        if (!empty($payment_details['transaction_id'])) {
453
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
454 454
         }
455 455
     }
456 456
 
457
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
457
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
458 458
 
459 459
     // Parent invoice
460
-    if ( !empty( $invoice_data['parent'] ) ) {
461
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
460
+    if (!empty($invoice_data['parent'])) {
461
+        $invoice->set('parent_invoice', $invoice_data['parent']);
462 462
     }
463 463
 
464 464
     // Save invoice data.
465 465
     $invoice->save();
466 466
     
467
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
468
-        if ( $wp_error ) {
469
-            if ( is_wp_error( $invoice ) ) {
467
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
468
+        if ($wp_error) {
469
+            if (is_wp_error($invoice)) {
470 470
                 return $invoice;
471 471
             } else {
472
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
472
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
473 473
             }
474 474
         } else {
475 475
             return 0;
@@ -477,19 +477,19 @@  discard block
 block discarded – undo
477 477
     }
478 478
 
479 479
     // Add private note
480
-    if ( !empty( $invoice_data['private_note'] ) ) {
481
-        $invoice->add_note( $invoice_data['private_note'] );
480
+    if (!empty($invoice_data['private_note'])) {
481
+        $invoice->add_note($invoice_data['private_note']);
482 482
     }
483 483
 
484 484
     // Add user note
485
-    if ( !empty( $invoice_data['user_note'] ) ) {
486
-        $invoice->add_note( $invoice_data['user_note'], true );
485
+    if (!empty($invoice_data['user_note'])) {
486
+        $invoice->add_note($invoice_data['user_note'], true);
487 487
     }
488 488
 
489
-    if ( $invoice->is_quote() ) {
489
+    if ($invoice->is_quote()) {
490 490
 
491
-        if ( isset( $invoice_data['valid_until'] ) ) {
492
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
491
+        if (isset($invoice_data['valid_until'])) {
492
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
493 493
         }
494 494
         return $invoice;
495 495
 
@@ -501,466 +501,466 @@  discard block
 block discarded – undo
501 501
 
502 502
     $data_session                   = array();
503 503
     $data_session['invoice_id']     = $invoice->ID;
504
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
504
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
505 505
 
506
-    wpinv_set_checkout_session( $data_session );
506
+    wpinv_set_checkout_session($data_session);
507 507
 
508
-    $wpi_userID         = (int)$invoice->get_user_id();
508
+    $wpi_userID         = (int) $invoice->get_user_id();
509 509
 
510
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
510
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
511 511
     $_POST['state']     = $invoice->state;
512 512
 
513
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
514
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
513
+    $invoice->set('country', sanitize_text_field($_POST['country']));
514
+    $invoice->set('state', sanitize_text_field($_POST['state']));
515 515
 
516 516
     $wpinv_ip_address_country = $invoice->country;
517 517
 
518
-    $invoice = $invoice->recalculate_totals( true );
518
+    $invoice = $invoice->recalculate_totals(true);
519 519
 
520
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
520
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
521 521
 
522
-    wpinv_set_checkout_session( $checkout_session );
522
+    wpinv_set_checkout_session($checkout_session);
523 523
 
524 524
     return $invoice;
525 525
 }
526 526
 
527
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
528
-    if ( $cart && empty( $invoice_id ) ) {
529
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
527
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
528
+    if ($cart && empty($invoice_id)) {
529
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
530 530
     }
531 531
 
532
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+    $invoice = new WPInv_Invoice($invoice_id);
533 533
 
534
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
534
+    if (!empty($invoice) && !empty($invoice->ID)) {
535 535
         return $invoice;
536 536
     }
537 537
 
538 538
     return NULL;
539 539
 }
540 540
 
541
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
542
-    return wpinv_get_invoice( $invoice_id, true );
541
+function wpinv_get_invoice_cart($invoice_id = 0) {
542
+    return wpinv_get_invoice($invoice_id, true);
543 543
 }
544 544
 
545
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
546
-    $invoice = new WPInv_Invoice( $invoice_id );
545
+function wpinv_get_invoice_description($invoice_id = 0) {
546
+    $invoice = new WPInv_Invoice($invoice_id);
547 547
     return $invoice->get_description();
548 548
 }
549 549
 
550
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
551
-    $invoice = new WPInv_Invoice( $invoice_id );
550
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
551
+    $invoice = new WPInv_Invoice($invoice_id);
552 552
     return $invoice->get_currency();
553 553
 }
554 554
 
555
-function wpinv_get_payment_user_email( $invoice_id ) {
556
-    $invoice = new WPInv_Invoice( $invoice_id );
555
+function wpinv_get_payment_user_email($invoice_id) {
556
+    $invoice = new WPInv_Invoice($invoice_id);
557 557
     return $invoice->get_email();
558 558
 }
559 559
 
560
-function wpinv_get_user_id( $invoice_id ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_get_user_id($invoice_id) {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     return $invoice->get_user_id();
563 563
 }
564 564
 
565
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
566
-    $invoice = new WPInv_Invoice( $invoice_id );
565
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
566
+    $invoice = new WPInv_Invoice($invoice_id);
567 567
     
568
-    return $invoice->get_status( $return_label );
568
+    return $invoice->get_status($return_label);
569 569
 }
570 570
 
571
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
572
-    $invoice = new WPInv_Invoice( $invoice_id );
571
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
572
+    $invoice = new WPInv_Invoice($invoice_id);
573 573
     
574
-    return $invoice->get_gateway( $return_label );
574
+    return $invoice->get_gateway($return_label);
575 575
 }
576 576
 
577
-function wpinv_get_payment_gateway_name( $invoice_id ) {
578
-    $invoice = new WPInv_Invoice( $invoice_id );
577
+function wpinv_get_payment_gateway_name($invoice_id) {
578
+    $invoice = new WPInv_Invoice($invoice_id);
579 579
     
580 580
     return $invoice->get_gateway_title();
581 581
 }
582 582
 
583
-function wpinv_get_payment_transaction_id( $invoice_id ) {
584
-    $invoice = new WPInv_Invoice( $invoice_id );
583
+function wpinv_get_payment_transaction_id($invoice_id) {
584
+    $invoice = new WPInv_Invoice($invoice_id);
585 585
     
586 586
     return $invoice->get_transaction_id();
587 587
 }
588 588
 
589
-function wpinv_get_id_by_transaction_id( $key ) {
589
+function wpinv_get_id_by_transaction_id($key) {
590 590
     global $wpdb;
591 591
 
592
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
592
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
593 593
 
594
-    if ( $invoice_id != NULL )
594
+    if ($invoice_id != NULL)
595 595
         return $invoice_id;
596 596
 
597 597
     return 0;
598 598
 }
599 599
 
600
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
601
-    $invoice = new WPInv_Invoice( $invoice_id );
600
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603
-    return $invoice->get_meta( $meta_key, $single );
603
+    return $invoice->get_meta($meta_key, $single);
604 604
 }
605 605
 
606
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
607
-    $invoice = new WPInv_Invoice( $invoice_id );
606
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
607
+    $invoice = new WPInv_Invoice($invoice_id);
608 608
     
609
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
609
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
610 610
 }
611 611
 
612
-function wpinv_get_items( $invoice_id = 0 ) {
613
-    $invoice            = wpinv_get_invoice( $invoice_id );
612
+function wpinv_get_items($invoice_id = 0) {
613
+    $invoice            = wpinv_get_invoice($invoice_id);
614 614
     
615 615
     $items              = $invoice->get_items();
616 616
     $invoice_currency   = $invoice->get_currency();
617 617
 
618
-    if ( !empty( $items ) && is_array( $items ) ) {
619
-        foreach ( $items as $key => $item ) {
618
+    if (!empty($items) && is_array($items)) {
619
+        foreach ($items as $key => $item) {
620 620
             $items[$key]['currency'] = $invoice_currency;
621 621
 
622
-            if ( !isset( $item['subtotal'] ) ) {
622
+            if (!isset($item['subtotal'])) {
623 623
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
624 624
             }
625 625
         }
626 626
     }
627 627
 
628
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
628
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
629 629
 }
630 630
 
631
-function wpinv_get_fees( $invoice_id = 0 ) {
632
-    $invoice           = wpinv_get_invoice( $invoice_id );
631
+function wpinv_get_fees($invoice_id = 0) {
632
+    $invoice           = wpinv_get_invoice($invoice_id);
633 633
     $fees              = $invoice->get_fees();
634 634
 
635
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
635
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
636 636
 }
637 637
 
638
-function wpinv_get_invoice_ip( $invoice_id ) {
639
-    $invoice = new WPInv_Invoice( $invoice_id );
638
+function wpinv_get_invoice_ip($invoice_id) {
639
+    $invoice = new WPInv_Invoice($invoice_id);
640 640
     return $invoice->get_ip();
641 641
 }
642 642
 
643
-function wpinv_get_invoice_user_info( $invoice_id ) {
644
-    $invoice = new WPInv_Invoice( $invoice_id );
643
+function wpinv_get_invoice_user_info($invoice_id) {
644
+    $invoice = new WPInv_Invoice($invoice_id);
645 645
     return $invoice->get_user_info();
646 646
 }
647 647
 
648
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
649
-    $invoice = new WPInv_Invoice( $invoice_id );
648
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
649
+    $invoice = new WPInv_Invoice($invoice_id);
650 650
 
651
-    return $invoice->get_subtotal( $currency );
651
+    return $invoice->get_subtotal($currency);
652 652
 }
653 653
 
654
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
655
-    $invoice = new WPInv_Invoice( $invoice_id );
654
+function wpinv_tax($invoice_id = 0, $currency = false) {
655
+    $invoice = new WPInv_Invoice($invoice_id);
656 656
 
657
-    return $invoice->get_tax( $currency );
657
+    return $invoice->get_tax($currency);
658 658
 }
659 659
 
660
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
661
-    $invoice = wpinv_get_invoice( $invoice_id );
660
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
661
+    $invoice = wpinv_get_invoice($invoice_id);
662 662
 
663
-    return $invoice->get_discount( $currency, $dash );
663
+    return $invoice->get_discount($currency, $dash);
664 664
 }
665 665
 
666
-function wpinv_discount_code( $invoice_id = 0 ) {
667
-    $invoice = new WPInv_Invoice( $invoice_id );
666
+function wpinv_discount_code($invoice_id = 0) {
667
+    $invoice = new WPInv_Invoice($invoice_id);
668 668
 
669 669
     return $invoice->get_discount_code();
670 670
 }
671 671
 
672
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
673
-    $invoice = new WPInv_Invoice( $invoice_id );
672
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
673
+    $invoice = new WPInv_Invoice($invoice_id);
674 674
 
675
-    return $invoice->get_total( $currency );
675
+    return $invoice->get_total($currency);
676 676
 }
677 677
 
678
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
679
-    $invoice = new WPInv_Invoice( $invoice_id );
678
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
679
+    $invoice = new WPInv_Invoice($invoice_id);
680 680
 
681
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
681
+    $format         = !empty($format) ? $format : get_option('date_format');
682 682
     $date_created   = $invoice->get_created_date();
683
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
683
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
684 684
 
685 685
     return $date_created;
686 686
 }
687 687
 
688
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
689
-    $invoice = new WPInv_Invoice( $invoice_id );
688
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
689
+    $invoice = new WPInv_Invoice($invoice_id);
690 690
     
691
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
691
+    $format         = !empty($format) ? $format : get_option('date_format');
692 692
     $date_completed = $invoice->get_completed_date();
693
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
694
-    if ( $invoice_date == '' && $default ) {
695
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
693
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
694
+    if ($invoice_date == '' && $default) {
695
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
696 696
     }
697 697
 
698 698
     return $invoice_date;
699 699
 }
700 700
 
701
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
702
-    $invoice = new WPInv_Invoice( $invoice_id );
701
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
702
+    $invoice = new WPInv_Invoice($invoice_id);
703 703
     
704 704
     return $invoice->vat_number;
705 705
 }
706 706
 
707
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
708
-    $invoice = new WPInv_Invoice( $invoice_id );
707
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
708
+    $invoice = new WPInv_Invoice($invoice_id);
709 709
 
710
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
710
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
711 711
 }
712 712
 
713
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
713
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
714 714
     global $invoicing;
715 715
     
716
-    if ( empty( $invoice_id ) ) {
716
+    if (empty($invoice_id)) {
717 717
         return NULL;
718 718
     }
719 719
     
720
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
720
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
721 721
     
722
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
722
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
723 723
 }
724 724
 
725
-function wpinv_get_payment_key( $invoice_id = 0 ) {
726
-	$invoice = new WPInv_Invoice( $invoice_id );
725
+function wpinv_get_payment_key($invoice_id = 0) {
726
+	$invoice = new WPInv_Invoice($invoice_id);
727 727
     return $invoice->get_key();
728 728
 }
729 729
 
730
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
731
-    $invoice = new WPInv_Invoice( $invoice_id );
730
+function wpinv_get_invoice_number($invoice_id = 0) {
731
+    $invoice = new WPInv_Invoice($invoice_id);
732 732
     return $invoice->get_number();
733 733
 }
734 734
 
735
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
735
+function wpinv_get_cart_discountable_subtotal($code_id) {
736 736
     $cart_items = wpinv_get_cart_content_details();
737 737
     $items      = array();
738 738
 
739
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
739
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
740 740
 
741
-    if( $cart_items ) {
741
+    if ($cart_items) {
742 742
 
743
-        foreach( $cart_items as $item ) {
743
+        foreach ($cart_items as $item) {
744 744
 
745
-            if( ! in_array( $item['id'], $excluded_items ) ) {
746
-                $items[] =  $item;
745
+            if (!in_array($item['id'], $excluded_items)) {
746
+                $items[] = $item;
747 747
             }
748 748
         }
749 749
     }
750 750
 
751
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
751
+    $subtotal = wpinv_get_cart_items_subtotal($items);
752 752
 
753
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
753
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
754 754
 }
755 755
 
756
-function wpinv_get_cart_items_subtotal( $items ) {
756
+function wpinv_get_cart_items_subtotal($items) {
757 757
     $subtotal = 0.00;
758 758
 
759
-    if ( is_array( $items ) && ! empty( $items ) ) {
760
-        $prices = wp_list_pluck( $items, 'subtotal' );
759
+    if (is_array($items) && !empty($items)) {
760
+        $prices = wp_list_pluck($items, 'subtotal');
761 761
 
762
-        if( is_array( $prices ) ) {
763
-            $subtotal = array_sum( $prices );
762
+        if (is_array($prices)) {
763
+            $subtotal = array_sum($prices);
764 764
         } else {
765 765
             $subtotal = 0.00;
766 766
         }
767 767
 
768
-        if( $subtotal < 0 ) {
768
+        if ($subtotal < 0) {
769 769
             $subtotal = 0.00;
770 770
         }
771 771
     }
772 772
 
773
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
773
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
774 774
 }
775 775
 
776
-function wpinv_get_cart_subtotal( $items = array() ) {
777
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
778
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
776
+function wpinv_get_cart_subtotal($items = array()) {
777
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
778
+    $subtotal = wpinv_get_cart_items_subtotal($items);
779 779
 
780
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
780
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
781 781
 }
782 782
 
783
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
783
+function wpinv_cart_subtotal($items = array(), $currency = '') {
784 784
 
785
-    if( empty( $currency ) ) {
785
+    if (empty($currency)) {
786 786
         $currency = wpinv_get_currency();
787 787
     }
788 788
 
789
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
789
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
790 790
 
791 791
     return $price;
792 792
 }
793 793
 
794
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
795
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
796
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
797
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
798
-    $fees      = (float)wpinv_get_cart_fee_total();
799
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
794
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
795
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
796
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
797
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
798
+    $fees      = (float) wpinv_get_cart_fee_total();
799
+    if (!empty($invoice) && $invoice->is_free_trial()) {
800 800
         $total = 0;
801 801
     } else {
802
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
802
+        $total = $subtotal - $discounts + $cart_tax + $fees;
803 803
     }
804 804
 
805
-    if ( $total < 0 ) {
805
+    if ($total < 0) {
806 806
         $total = 0.00;
807 807
     }
808 808
     
809
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
809
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
810 810
 
811
-    return wpinv_sanitize_amount( $total );
811
+    return wpinv_sanitize_amount($total);
812 812
 }
813 813
 
814
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
814
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
815 815
     global $cart_total;
816
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
817
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
816
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
817
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
818 818
     
819 819
     $cart_total = $total;
820 820
 
821
-    if ( !$echo ) {
821
+    if (!$echo) {
822 822
         return $total;
823 823
     }
824 824
 
825 825
     echo $total;
826 826
 }
827 827
 
828
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
828
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
829 829
 
830
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
830
+    if (!empty($invoice) && !$invoice->is_taxable()) {
831 831
         return 0;
832 832
     }
833 833
 
834 834
     $cart_tax = 0;
835
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
835
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
836 836
 
837
-    if ( $items ) {
838
-        $taxes = wp_list_pluck( $items, 'tax' );
837
+    if ($items) {
838
+        $taxes = wp_list_pluck($items, 'tax');
839 839
 
840
-        if( is_array( $taxes ) ) {
841
-            $cart_tax = array_sum( $taxes );
840
+        if (is_array($taxes)) {
841
+            $cart_tax = array_sum($taxes);
842 842
         }
843 843
     }
844 844
 
845 845
     $cart_tax += wpinv_get_cart_fee_tax();
846 846
 
847
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
847
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
848 848
 }
849 849
 
850
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
850
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
851 851
 
852
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
853
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
852
+    if (!empty($invoice && !$invoice->is_taxable())) {
853
+        echo wpinv_price(wpinv_format_amount(0), $currency);
854 854
         return;
855 855
     }
856 856
 
857
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
858
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
857
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
858
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
859 859
 
860
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
860
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
861 861
 
862
-    if ( !$echo ) {
862
+    if (!$echo) {
863 863
         return $tax;
864 864
     }
865 865
 
866 866
     echo $tax;
867 867
 }
868 868
 
869
-function wpinv_get_cart_discount_code( $items = array() ) {
869
+function wpinv_get_cart_discount_code($items = array()) {
870 870
     $invoice = wpinv_get_invoice_cart();
871
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
871
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
872 872
     
873
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
873
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
874 874
 }
875 875
 
876
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
877
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
876
+function wpinv_cart_discount_code($items = array(), $echo = false) {
877
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
878 878
 
879
-    if ( $cart_discount_code != '' ) {
879
+    if ($cart_discount_code != '') {
880 880
         $cart_discount_code = ' (' . $cart_discount_code . ')';
881 881
     }
882 882
     
883
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
883
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
884 884
 
885
-    if ( !$echo ) {
885
+    if (!$echo) {
886 886
         return $discount_code;
887 887
     }
888 888
 
889 889
     echo $discount_code;
890 890
 }
891 891
 
892
-function wpinv_get_cart_discount( $items = array() ) {
892
+function wpinv_get_cart_discount($items = array()) {
893 893
     $invoice = wpinv_get_invoice_cart();
894
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
894
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
895 895
     
896
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
896
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
897 897
 }
898 898
 
899
-function wpinv_cart_discount( $items = array(), $echo = false ) {
900
-    $cart_discount = wpinv_get_cart_discount( $items );
901
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
899
+function wpinv_cart_discount($items = array(), $echo = false) {
900
+    $cart_discount = wpinv_get_cart_discount($items);
901
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
902 902
 
903
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
903
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
904 904
 
905
-    if ( !$echo ) {
905
+    if (!$echo) {
906 906
         return $discount;
907 907
     }
908 908
 
909 909
     echo $discount;
910 910
 }
911 911
 
912
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
913
-    $item = new WPInv_Item( $item_id );
912
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
913
+    $item = new WPInv_Item($item_id);
914 914
     
915
-    return $item->get_fees( $type, $item_id );
915
+    return $item->get_fees($type, $item_id);
916 916
 }
917 917
 
918 918
 function wpinv_get_cart_fee_total() {
919
-    $total  = 0;
919
+    $total = 0;
920 920
     $fees = wpinv_get_cart_fees();
921 921
     
922
-    if ( $fees ) {
923
-        foreach ( $fees as $fee_id => $fee ) {
922
+    if ($fees) {
923
+        foreach ($fees as $fee_id => $fee) {
924 924
             $total += $fee['amount'];
925 925
         }
926 926
     }
927 927
 
928
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
928
+    return apply_filters('wpinv_get_cart_fee_total', $total);
929 929
 }
930 930
 
931 931
 function wpinv_get_cart_fee_tax() {
932 932
     $tax  = 0;
933 933
     $fees = wpinv_get_cart_fees();
934 934
 
935
-    if ( $fees ) {
936
-        foreach ( $fees as $fee_id => $fee ) {
937
-            if( ! empty( $fee['no_tax'] ) ) {
935
+    if ($fees) {
936
+        foreach ($fees as $fee_id => $fee) {
937
+            if (!empty($fee['no_tax'])) {
938 938
                 continue;
939 939
             }
940 940
 
941
-            $tax += wpinv_calculate_tax( $fee['amount'] );
941
+            $tax += wpinv_calculate_tax($fee['amount']);
942 942
         }
943 943
     }
944 944
 
945
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
945
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
946 946
 }
947 947
 
948 948
 function wpinv_cart_has_recurring_item() {
949 949
     $cart_items = wpinv_get_cart_contents();
950 950
     
951
-    if ( empty( $cart_items ) ) {
951
+    if (empty($cart_items)) {
952 952
         return false;
953 953
     }
954 954
     
955 955
     $has_subscription = false;
956
-    foreach( $cart_items as $cart_item ) {
957
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
956
+    foreach ($cart_items as $cart_item) {
957
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
958 958
             $has_subscription = true;
959 959
             break;
960 960
         }
961 961
     }
962 962
     
963
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
963
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
964 964
 }
965 965
 
966 966
 function wpinv_cart_has_free_trial() {
@@ -968,100 +968,100 @@  discard block
 block discarded – undo
968 968
     
969 969
     $free_trial = false;
970 970
     
971
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
971
+    if (!empty($invoice) && $invoice->is_free_trial()) {
972 972
         $free_trial = true;
973 973
     }
974 974
     
975
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
975
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
976 976
 }
977 977
 
978 978
 function wpinv_get_cart_contents() {
979 979
     $cart_details = wpinv_get_cart_details();
980 980
     
981
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
981
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
982 982
 }
983 983
 
984 984
 function wpinv_get_cart_content_details() {
985 985
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
986 986
     $cart_items = wpinv_get_cart_contents();
987 987
     
988
-    if ( empty( $cart_items ) ) {
988
+    if (empty($cart_items)) {
989 989
         return false;
990 990
     }
991 991
     $invoice = wpinv_get_invoice_cart();
992
-	if ( empty( $invoice ) ) {
992
+	if (empty($invoice)) {
993 993
         return false;
994 994
     }
995 995
 
996 996
     $details = array();
997
-    $length  = count( $cart_items ) - 1;
997
+    $length  = count($cart_items) - 1;
998 998
     
999
-    if ( empty( $_POST['country'] ) ) {
999
+    if (empty($_POST['country'])) {
1000 1000
         $_POST['country'] = $invoice->country;
1001 1001
     }
1002
-    if ( !isset( $_POST['state'] ) ) {
1002
+    if (!isset($_POST['state'])) {
1003 1003
         $_POST['state'] = $invoice->state;
1004 1004
     }
1005 1005
 
1006
-    foreach( $cart_items as $key => $item ) {
1007
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
1008
-        if ( empty( $item_id ) ) {
1006
+    foreach ($cart_items as $key => $item) {
1007
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
1008
+        if (empty($item_id)) {
1009 1009
             continue;
1010 1010
         }
1011 1011
         
1012 1012
         $wpi_current_id         = $invoice->ID;
1013 1013
         $wpi_item_id            = $item_id;
1014 1014
         
1015
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
1015
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
1016 1016
             $item_price = $item['custom_price'];
1017 1017
         } else {
1018
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
1018
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
1019 1019
                 $item_price = $item['item_price'];
1020 1020
             } else {
1021
-                $item_price = wpinv_get_item_price( $item_id );
1021
+                $item_price = wpinv_get_item_price($item_id);
1022 1022
             }
1023 1023
         }
1024
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1025
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1026
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1027
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1024
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1025
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1026
+        $quantity           = wpinv_get_cart_item_quantity($item);
1027
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1028 1028
         
1029 1029
         $subtotal           = $item_price * $quantity;
1030
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1031
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1032
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1030
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1031
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1032
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1033 1033
         
1034
-        if ( ! $invoice->is_taxable() ) {
1034
+        if (!$invoice->is_taxable()) {
1035 1035
             $tax = 0;
1036 1036
         }
1037
-        if ( wpinv_prices_include_tax() ) {
1038
-            $subtotal -= wpinv_round_amount( $tax );
1037
+        if (wpinv_prices_include_tax()) {
1038
+            $subtotal -= wpinv_round_amount($tax);
1039 1039
         }
1040 1040
         
1041
-        $total              = $subtotal - $discount + $tax;
1041
+        $total = $subtotal - $discount + $tax;
1042 1042
         
1043 1043
         // Do not allow totals to go negatve
1044
-        if( $total < 0 ) {
1044
+        if ($total < 0) {
1045 1045
             $total = 0;
1046 1046
         }
1047 1047
         
1048
-        $details[ $key ]  = array(
1048
+        $details[$key] = array(
1049 1049
             'id'                => $item_id,
1050
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1051
-            'item_price'        => wpinv_round_amount( $item_price ),
1052
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1050
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1051
+            'item_price'        => wpinv_round_amount($item_price),
1052
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1053 1053
             'quantity'          => $quantity,
1054
-            'discount'          => wpinv_round_amount( $discount ),
1055
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1056
-            'tax'               => wpinv_round_amount( $tax ),
1057
-            'price'             => wpinv_round_amount( $total ),
1054
+            'discount'          => wpinv_round_amount($discount),
1055
+            'subtotal'          => wpinv_round_amount($subtotal),
1056
+            'tax'               => wpinv_round_amount($tax),
1057
+            'price'             => wpinv_round_amount($total),
1058 1058
             'vat_rates_class'   => $tax_class,
1059 1059
             'vat_rate'          => $tax_rate,
1060
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1060
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1061 1061
             'fees'              => $fees,
1062 1062
         );
1063 1063
         
1064
-        if ( $wpinv_is_last_cart_item ) {
1064
+        if ($wpinv_is_last_cart_item) {
1065 1065
             $wpinv_is_last_cart_item   = false;
1066 1066
             $wpinv_flat_discount_total = 0.00;
1067 1067
         }
@@ -1070,74 +1070,74 @@  discard block
 block discarded – undo
1070 1070
     return $details;
1071 1071
 }
1072 1072
 
1073
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1073
+function wpinv_get_cart_details($invoice_id = 0) {
1074 1074
     global $ajax_cart_details;
1075 1075
 
1076
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1076
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1077 1077
     $cart_details = $ajax_cart_details;
1078
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1078
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1079 1079
         $cart_details = $invoice->cart_details;
1080 1080
     }
1081 1081
 
1082
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1083
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1082
+    if (!empty($cart_details) && is_array($cart_details)) {
1083
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1084 1084
 
1085
-        foreach ( $cart_details as $key => $cart_item ) {
1086
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1085
+        foreach ($cart_details as $key => $cart_item) {
1086
+            $cart_details[$key]['currency'] = $invoice_currency;
1087 1087
 
1088
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1089
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1088
+            if (!isset($cart_item['subtotal'])) {
1089
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1090 1090
             }
1091 1091
         }
1092 1092
     }
1093 1093
 
1094
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1094
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1095 1095
 }
1096 1096
 
1097
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1098
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1097
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1098
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1099 1099
         return;
1100 1100
     }
1101 1101
 
1102
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1102
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1103 1103
         return;
1104 1104
     }
1105 1105
 
1106
-    $invoice    = wpinv_get_invoice( $invoice_id );
1106
+    $invoice = wpinv_get_invoice($invoice_id);
1107 1107
 
1108
-    if ( wpinv_use_taxes() && $new_status == 'publish' ) {
1108
+    if (wpinv_use_taxes() && $new_status == 'publish') {
1109 1109
         
1110
-        if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->country ) ) {
1111
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
1110
+        if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->country)) {
1111
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
1112 1112
         }
1113 1113
     }
1114 1114
 
1115
-    $old_status = wpinv_status_nicename( $old_status );
1116
-    $new_status = wpinv_status_nicename( $new_status );
1115
+    $old_status = wpinv_status_nicename($old_status);
1116
+    $new_status = wpinv_status_nicename($new_status);
1117 1117
 
1118
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1118
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1119 1119
 
1120 1120
     // Add note
1121
-    return $invoice->add_note( $status_change, false, false, true );
1121
+    return $invoice->add_note($status_change, false, false, true);
1122 1122
 }
1123
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1123
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1124 1124
 
1125
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1125
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1126 1126
     global $wpi_has_free_trial;
1127 1127
     
1128 1128
     $wpi_has_free_trial = false;
1129 1129
     
1130
-    if ( $old_status == 'publish' ) {
1130
+    if ($old_status == 'publish') {
1131 1131
         return; // Make sure that payments are only paid once
1132 1132
     }
1133 1133
 
1134 1134
     // Make sure the payment completion is only processed when new status is paid
1135
-    if ( $new_status != 'publish' ) {
1135
+    if ($new_status != 'publish') {
1136 1136
         return;
1137 1137
     }
1138 1138
 
1139
-    $invoice = new WPInv_Invoice( $invoice_id );
1140
-    if ( empty( $invoice ) ) {
1139
+    $invoice = new WPInv_Invoice($invoice_id);
1140
+    if (empty($invoice)) {
1141 1141
         return;
1142 1142
     }
1143 1143
 
@@ -1145,58 +1145,58 @@  discard block
 block discarded – undo
1145 1145
     $completed_date = $invoice->completed_date;
1146 1146
     $cart_details   = $invoice->cart_details;
1147 1147
 
1148
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1148
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1149 1149
 
1150
-    if ( is_array( $cart_details ) ) {
1150
+    if (is_array($cart_details)) {
1151 1151
         // Increase purchase count and earnings
1152
-        foreach ( $cart_details as $cart_index => $item ) {
1152
+        foreach ($cart_details as $cart_index => $item) {
1153 1153
             // Ensure these actions only run once, ever
1154
-            if ( empty( $completed_date ) ) {
1155
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1154
+            if (empty($completed_date)) {
1155
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1156 1156
             }
1157 1157
         }
1158 1158
     }
1159 1159
     
1160 1160
     // Check for discount codes and increment their use counts
1161
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1162
-        if( ! empty( $discounts ) ) {
1163
-            foreach( $discounts as $code ) {
1164
-                wpinv_increase_discount_usage( $code );
1161
+    if ($discounts = $invoice->get_discounts(true)) {
1162
+        if (!empty($discounts)) {
1163
+            foreach ($discounts as $code) {
1164
+                wpinv_increase_discount_usage($code);
1165 1165
             }
1166 1166
         }
1167 1167
     }
1168 1168
     
1169 1169
     // Ensure this action only runs once ever
1170
-    if( empty( $completed_date ) ) {
1170
+    if (empty($completed_date)) {
1171 1171
         // Save the completed date
1172
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1172
+        $invoice->set('completed_date', current_time('mysql', 0));
1173 1173
         $invoice->save();
1174 1174
 
1175
-        do_action( 'wpinv_complete_payment', $invoice_id );
1175
+        do_action('wpinv_complete_payment', $invoice_id);
1176 1176
     }
1177 1177
 
1178 1178
     // Empty the shopping cart
1179 1179
     wpinv_empty_cart();
1180 1180
 }
1181
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1181
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1182 1182
 
1183
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1184
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1183
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1184
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1185 1185
 
1186
-    if ( empty( $invoice ) ) {
1186
+    if (empty($invoice)) {
1187 1187
         return false;
1188 1188
     }
1189 1189
 
1190
-    return $invoice->update_status( $new_status );
1190
+    return $invoice->update_status($new_status);
1191 1191
 }
1192 1192
 
1193
-function wpinv_cart_has_fees( $type = 'all' ) {
1193
+function wpinv_cart_has_fees($type = 'all') {
1194 1194
     return false;
1195 1195
 }
1196 1196
 
1197 1197
 function wpinv_validate_checkout_fields() {
1198 1198
     // Check if there is $_POST
1199
-    if ( empty( $_POST ) ) {
1199
+    if (empty($_POST)) {
1200 1200
         return false;
1201 1201
     }
1202 1202
 
@@ -1219,28 +1219,28 @@  discard block
 block discarded – undo
1219 1219
     
1220 1220
     $invoice = wpinv_get_invoice_cart();
1221 1221
     $has_subscription = $invoice->is_recurring();
1222
-    if ( empty( $invoice ) ) {
1223
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1222
+    if (empty($invoice)) {
1223
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1224 1224
         return $gateway;
1225 1225
     }
1226 1226
 
1227 1227
     // Check if a gateway value is present
1228
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1229
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1228
+    if (!empty($_REQUEST['wpi-gateway'])) {
1229
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1230 1230
 
1231
-        if ( $invoice->is_free() ) {
1231
+        if ($invoice->is_free()) {
1232 1232
             $gateway = 'manual';
1233
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1234
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1235
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1236
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1237
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1233
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1234
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1235
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1236
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1237
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1238 1238
             }
1239 1239
         }
1240 1240
     }
1241 1241
 
1242
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1243
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1242
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1243
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1244 1244
     }
1245 1245
 
1246 1246
     return $gateway;
@@ -1252,41 +1252,41 @@  discard block
 block discarded – undo
1252 1252
     // Retrieve the discount stored in cookies
1253 1253
     $discounts = wpinv_get_cart_discounts();
1254 1254
 
1255
-    if ( ! is_array( $discounts ) ) {
1255
+    if (!is_array($discounts)) {
1256 1256
         return NULL;
1257 1257
     }
1258 1258
 
1259
-    $discounts = array_filter( $discounts );
1260
-    $error    = false;
1259
+    $discounts = array_filter($discounts);
1260
+    $error = false;
1261 1261
 
1262
-    if ( empty( $discounts ) ) {
1262
+    if (empty($discounts)) {
1263 1263
         return NULL;
1264 1264
     }
1265 1265
 
1266 1266
     // If we have discounts, loop through them
1267
-    foreach ( $discounts as $discount ) {
1267
+    foreach ($discounts as $discount) {
1268 1268
         // Check if valid
1269
-        if (  ! wpinv_is_discount_valid( $discount, (int) $wpi_cart->get_user_id() ) ) {
1269
+        if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1270 1270
             // Discount is not valid
1271 1271
             $error = true;
1272 1272
         }
1273 1273
 
1274 1274
     }
1275 1275
 
1276
-    if ( $error && ! wpinv_get_errors() ) {
1277
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1276
+    if ($error && !wpinv_get_errors()) {
1277
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1278 1278
     }
1279 1279
 
1280
-    return implode( ',', $discounts );
1280
+    return implode(',', $discounts);
1281 1281
 }
1282 1282
 
1283 1283
 function wpinv_checkout_validate_cc() {
1284 1284
     $card_data = wpinv_checkout_get_cc_info();
1285 1285
 
1286 1286
     // Validate the card zip
1287
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1288
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1289
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1287
+    if (!empty($card_data['wpinv_zip'])) {
1288
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1289
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1290 1290
         }
1291 1291
     }
1292 1292
 
@@ -1296,28 +1296,28 @@  discard block
 block discarded – undo
1296 1296
 
1297 1297
 function wpinv_checkout_get_cc_info() {
1298 1298
 	$cc_info = array();
1299
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1300
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1301
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1302
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1303
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1304
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1305
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1306
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1307
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1308
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1299
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1300
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1301
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1302
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1303
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1304
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1305
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1306
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1307
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1308
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1309 1309
 
1310 1310
 	// Return cc info
1311 1311
 	return $cc_info;
1312 1312
 }
1313 1313
 
1314
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1314
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1315 1315
     $ret = false;
1316 1316
 
1317
-    if ( empty( $zip ) || empty( $country_code ) )
1317
+    if (empty($zip) || empty($country_code))
1318 1318
         return $ret;
1319 1319
 
1320
-    $country_code = strtoupper( $country_code );
1320
+    $country_code = strtoupper($country_code);
1321 1321
 
1322 1322
     $zip_regex = array(
1323 1323
         "AD" => "AD\d{3}",
@@ -1477,72 +1477,72 @@  discard block
 block discarded – undo
1477 1477
         "ZM" => "\d{5}"
1478 1478
     );
1479 1479
 
1480
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1480
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1481 1481
         $ret = true;
1482 1482
 
1483
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1483
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1484 1484
 }
1485 1485
 
1486 1486
 function wpinv_checkout_validate_agree_to_terms() {
1487 1487
     // Validate agree to terms
1488
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1488
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1489 1489
         // User did not agree
1490
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1490
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1491 1491
     }
1492 1492
 }
1493 1493
 
1494 1494
 function wpinv_checkout_validate_invoice_user() {
1495 1495
     global $wpi_cart, $user_ID;
1496 1496
 
1497
-    if(empty($wpi_cart)){
1497
+    if (empty($wpi_cart)) {
1498 1498
         $wpi_cart = wpinv_get_invoice_cart();
1499 1499
     }
1500 1500
 
1501
-    $invoice_user = (int)$wpi_cart->get_user_id();
1501
+    $invoice_user = (int) $wpi_cart->get_user_id();
1502 1502
     $valid_user_data = array(
1503 1503
         'user_id' => $invoice_user
1504 1504
     );
1505 1505
 
1506 1506
     // If guest checkout allowed
1507
-    if ( !wpinv_require_login_to_checkout() ) {
1507
+    if (!wpinv_require_login_to_checkout()) {
1508 1508
         return $valid_user_data;
1509 1509
     }
1510 1510
     
1511 1511
     // Verify there is a user_ID
1512
-    if ( $user_ID == $invoice_user ) {
1512
+    if ($user_ID == $invoice_user) {
1513 1513
         // Get the logged in user data
1514
-        $user_data = get_userdata( $user_ID );
1515
-        $required_fields  = wpinv_checkout_required_fields();
1514
+        $user_data = get_userdata($user_ID);
1515
+        $required_fields = wpinv_checkout_required_fields();
1516 1516
 
1517 1517
         // Loop through required fields and show error messages
1518
-         if ( !empty( $required_fields ) ) {
1519
-            foreach ( $required_fields as $field_name => $value ) {
1520
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1521
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1518
+         if (!empty($required_fields)) {
1519
+            foreach ($required_fields as $field_name => $value) {
1520
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1521
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1522 1522
                 }
1523 1523
             }
1524 1524
         }
1525 1525
 
1526 1526
         // Verify data
1527
-        if ( $user_data ) {
1527
+        if ($user_data) {
1528 1528
             // Collected logged in user data
1529 1529
             $valid_user_data = array(
1530 1530
                 'user_id'     => $user_ID,
1531
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1532
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1533
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1531
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1532
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1533
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1534 1534
             );
1535 1535
 
1536
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1537
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1536
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1537
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1538 1538
             }
1539 1539
         } else {
1540 1540
             // Set invalid user error
1541
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1541
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1542 1542
         }
1543 1543
     } else {
1544 1544
         // Set invalid user error
1545
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1545
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1546 1546
     }
1547 1547
 
1548 1548
     // Return user data
@@ -1554,27 +1554,27 @@  discard block
 block discarded – undo
1554 1554
 
1555 1555
     $data = array();
1556 1556
     
1557
-    if ( is_user_logged_in() ) {
1558
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1559
-            $data['user_id'] = (int)get_current_user_id();
1557
+    if (is_user_logged_in()) {
1558
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1559
+            $data['user_id'] = (int) get_current_user_id();
1560 1560
         } else {
1561
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1561
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1562 1562
         }
1563 1563
     } else {
1564 1564
         // If guest checkout allowed
1565
-        if ( !wpinv_require_login_to_checkout() ) {
1565
+        if (!wpinv_require_login_to_checkout()) {
1566 1566
             $data['user_id'] = 0;
1567 1567
         } else {
1568
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1568
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1569 1569
         }
1570 1570
     }
1571 1571
 
1572 1572
     return $data;
1573 1573
 }
1574 1574
 
1575
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1575
+function wpinv_checkout_form_get_user($valid_data = array()) {
1576 1576
 
1577
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1577
+    if (!empty($valid_data['current_user']['user_id'])) {
1578 1578
         $user = $valid_data['current_user'];
1579 1579
     } else {
1580 1580
         // Set the valid invoice user
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
     }
1583 1583
 
1584 1584
     // Verify invoice have an user
1585
-    if ( false === $user || empty( $user ) ) {
1585
+    if (false === $user || empty($user)) {
1586 1586
         return false;
1587 1587
     }
1588 1588
 
@@ -1599,11 +1599,11 @@  discard block
 block discarded – undo
1599 1599
         'zip',
1600 1600
     );
1601 1601
     
1602
-    foreach ( $address_fields as $field ) {
1603
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1602
+    foreach ($address_fields as $field) {
1603
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1604 1604
         
1605
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1606
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1605
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1606
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1607 1607
         }
1608 1608
     }
1609 1609
 
@@ -1611,26 +1611,26 @@  discard block
 block discarded – undo
1611 1611
     return $user;
1612 1612
 }
1613 1613
 
1614
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1614
+function wpinv_set_checkout_session($invoice_data = array()) {
1615 1615
     global $wpi_session;
1616
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1616
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1617 1617
 }
1618 1618
 
1619 1619
 function wpinv_get_checkout_session() {
1620 1620
 	global $wpi_session;
1621
-    return $wpi_session->get( 'wpinv_checkout' );
1621
+    return $wpi_session->get('wpinv_checkout');
1622 1622
 }
1623 1623
 
1624 1624
 function wpinv_empty_cart() {
1625 1625
     global $wpi_session;
1626 1626
 
1627 1627
     // Remove cart contents
1628
-    $wpi_session->set( 'wpinv_checkout', NULL );
1628
+    $wpi_session->set('wpinv_checkout', NULL);
1629 1629
 
1630 1630
     // Remove all cart fees
1631
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1631
+    $wpi_session->set('wpi_cart_fees', NULL);
1632 1632
 
1633
-    do_action( 'wpinv_empty_cart' );
1633
+    do_action('wpinv_empty_cart');
1634 1634
 }
1635 1635
 
1636 1636
 function wpinv_process_checkout() {
@@ -1639,7 +1639,7 @@  discard block
 block discarded – undo
1639 1639
     wpinv_clear_errors();
1640 1640
 
1641 1641
     $invoice = wpinv_get_invoice_cart();
1642
-    if ( empty( $invoice ) ) {
1642
+    if (empty($invoice)) {
1643 1643
         return false;
1644 1644
     }
1645 1645
 
@@ -1647,42 +1647,42 @@  discard block
 block discarded – undo
1647 1647
 
1648 1648
     $wpi_checkout_id = $invoice->ID;
1649 1649
 
1650
-    do_action( 'wpinv_pre_process_checkout' );
1650
+    do_action('wpinv_pre_process_checkout');
1651 1651
     
1652
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1652
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1653 1653
         $valid_data = false;
1654
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1654
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1655 1655
     } else {
1656 1656
         // Validate the form $_POST data
1657 1657
         $valid_data = wpinv_validate_checkout_fields();
1658 1658
         
1659 1659
         // Allow themes and plugins to hook to errors
1660
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1660
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1661 1661
     }
1662 1662
     
1663
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1663
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1664 1664
     
1665 1665
     // Validate the user
1666
-    $user = wpinv_checkout_form_get_user( $valid_data );
1666
+    $user = wpinv_checkout_form_get_user($valid_data);
1667 1667
 
1668 1668
     // Let extensions validate fields after user is logged in if user has used login/registration form
1669
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1669
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1670 1670
     
1671
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1672
-        if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1673
-            do_action( 'wpinv_ajax_checkout_errors' );
1671
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1672
+        if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1673
+            do_action('wpinv_ajax_checkout_errors');
1674 1674
             die();
1675 1675
         } else {
1676 1676
             return false;
1677 1677
         }
1678 1678
     }
1679 1679
 
1680
-    if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1680
+    if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1681 1681
         // Save address fields.
1682
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1683
-        foreach ( $address_fields as $field ) {
1684
-            if ( isset( $user[$field] ) ) {
1685
-                $invoice->set( $field, $user[$field] );
1682
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1683
+        foreach ($address_fields as $field) {
1684
+            if (isset($user[$field])) {
1685
+                $invoice->set($field, $user[$field]);
1686 1686
             }
1687 1687
 
1688 1688
             $invoice->save();
@@ -1690,16 +1690,16 @@  discard block
 block discarded – undo
1690 1690
 
1691 1691
         $response['success']            = true;
1692 1692
         $response['data']['subtotal']   = $invoice->get_subtotal();
1693
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1693
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1694 1694
         $response['data']['discount']   = $invoice->get_discount();
1695
-        $response['data']['discountf']  = $invoice->get_discount( true );
1695
+        $response['data']['discountf']  = $invoice->get_discount(true);
1696 1696
         $response['data']['tax']        = $invoice->get_tax();
1697
-        $response['data']['taxf']       = $invoice->get_tax( true );
1697
+        $response['data']['taxf']       = $invoice->get_tax(true);
1698 1698
         $response['data']['total']      = $invoice->get_total();
1699
-        $response['data']['totalf']     = $invoice->get_total( true );
1700
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1699
+        $response['data']['totalf']     = $invoice->get_total(true);
1700
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1701 1701
 
1702
-        wp_send_json( $response );
1702
+        wp_send_json($response);
1703 1703
     }
1704 1704
     
1705 1705
     $user_info = array(
@@ -1721,42 +1721,42 @@  discard block
 block discarded – undo
1721 1721
     
1722 1722
     // Setup invoice information
1723 1723
     $invoice_data = array(
1724
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1724
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1725 1725
         'items'             => $cart_items,
1726 1726
         'cart_discounts'    => $discounts,
1727
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1728
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1729
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1730
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1731
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1727
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1728
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1729
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1730
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1731
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1732 1732
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1733 1733
         'user_email'        => $invoice->get_email(),
1734
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1735
-        'user_info'         => stripslashes_deep( $user_info ),
1734
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1735
+        'user_info'         => stripslashes_deep($user_info),
1736 1736
         'post_data'         => $_POST,
1737 1737
         'cart_details'      => $cart_items,
1738 1738
         'gateway'           => $valid_data['gateway'],
1739 1739
         'card_info'         => $valid_data['cc_info']
1740 1740
     );
1741 1741
     
1742
-    $vat_info   = $wpinv_euvat->current_vat_data();
1743
-    if ( is_array( $vat_info ) ) {
1742
+    $vat_info = $wpinv_euvat->current_vat_data();
1743
+    if (is_array($vat_info)) {
1744 1744
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1745 1745
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1746
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1746
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1747 1747
 
1748 1748
         // Add the VAT rate to each item in the cart
1749
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1749
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1750 1750
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1751
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1751
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1752 1752
         }
1753 1753
     }
1754 1754
     
1755 1755
     // Save vat fields.
1756
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1757
-    foreach ( $address_fields as $field ) {
1758
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1759
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1756
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1757
+    foreach ($address_fields as $field) {
1758
+        if (isset($invoice_data['user_info'][$field])) {
1759
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1760 1760
         }
1761 1761
     }
1762 1762
     $invoice->save();
@@ -1765,54 +1765,54 @@  discard block
 block discarded – undo
1765 1765
     $valid_data['user'] = $user;
1766 1766
     
1767 1767
     // Allow themes and plugins to hook before the gateway
1768
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1768
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1769 1769
 
1770 1770
      // If it is free, abort.
1771
-     if ( $invoice->is_free() && ( ! $invoice->is_recurring() || 0 ==  $invoice->get_recurring_details( 'total' ) ) ) {
1771
+     if ($invoice->is_free() && (!$invoice->is_recurring() || 0 == $invoice->get_recurring_details('total'))) {
1772 1772
         $invoice_data['gateway'] = 'manual';
1773 1773
         $_POST['wpi-gateway'] = 'manual';
1774 1774
     }
1775 1775
 
1776 1776
     // Allow the invoice data to be modified before it is sent to the gateway
1777
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1777
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1778 1778
     
1779
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1779
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1780 1780
         $mode = 'test';
1781 1781
     } else {
1782
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1782
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1783 1783
     }
1784 1784
 
1785 1785
     // Setup the data we're storing in the purchase session
1786 1786
     $session_data = $invoice_data;
1787 1787
     // Make sure credit card numbers are never stored in sessions
1788
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1789
-        unset( $session_data['card_info']['card_number'] );
1788
+    if (!empty($session_data['card_info']['card_number'])) {
1789
+        unset($session_data['card_info']['card_number']);
1790 1790
     }
1791 1791
     
1792 1792
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1793
-    wpinv_set_checkout_session( $invoice_data );
1793
+    wpinv_set_checkout_session($invoice_data);
1794 1794
     
1795 1795
     // Set gateway
1796
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1797
-    $invoice->update_meta( '_wpinv_mode', $mode );
1798
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1796
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1797
+    $invoice->update_meta('_wpinv_mode', $mode);
1798
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1799 1799
     
1800
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1800
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1801 1801
 
1802 1802
     // Send info to the gateway for payment processing
1803
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1803
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1804 1804
     die();
1805 1805
 }
1806
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1806
+add_action('wpinv_payment', 'wpinv_process_checkout');
1807 1807
 
1808
-function wpinv_get_invoices( $args ) {
1809
-    $args = wp_parse_args( $args, array(
1810
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1808
+function wpinv_get_invoices($args) {
1809
+    $args = wp_parse_args($args, array(
1810
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1811 1811
         'type'     => 'wpi_invoice',
1812 1812
         'parent'   => null,
1813 1813
         'user'     => null,
1814 1814
         'email'    => '',
1815
-        'limit'    => get_option( 'posts_per_page' ),
1815
+        'limit'    => get_option('posts_per_page'),
1816 1816
         'offset'   => null,
1817 1817
         'page'     => 1,
1818 1818
         'exclude'  => array(),
@@ -1820,7 +1820,7 @@  discard block
 block discarded – undo
1820 1820
         'order'    => 'DESC',
1821 1821
         'return'   => 'objects',
1822 1822
         'paginate' => false,
1823
-    ) );
1823
+    ));
1824 1824
     
1825 1825
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1826 1826
     $map_legacy = array(
@@ -1833,18 +1833,18 @@  discard block
 block discarded – undo
1833 1833
         'paged'          => 'page',
1834 1834
     );
1835 1835
 
1836
-    foreach ( $map_legacy as $from => $to ) {
1837
-        if ( isset( $args[ $from ] ) ) {
1838
-            $args[ $to ] = $args[ $from ];
1836
+    foreach ($map_legacy as $from => $to) {
1837
+        if (isset($args[$from])) {
1838
+            $args[$to] = $args[$from];
1839 1839
         }
1840 1840
     }
1841 1841
 
1842
-    if ( get_query_var( 'paged' ) )
1842
+    if (get_query_var('paged'))
1843 1843
         $args['page'] = get_query_var('paged');
1844
-    else if ( get_query_var( 'page' ) )
1845
-        $args['page'] = get_query_var( 'page' );
1846
-    else if ( !empty( $args[ 'page' ] ) )
1847
-        $args['page'] = $args[ 'page' ];
1844
+    else if (get_query_var('page'))
1845
+        $args['page'] = get_query_var('page');
1846
+    else if (!empty($args['page']))
1847
+        $args['page'] = $args['page'];
1848 1848
     else
1849 1849
         $args['page'] = 1;
1850 1850
 
@@ -1857,48 +1857,48 @@  discard block
 block discarded – undo
1857 1857
         'post_status'    => $args['status'],
1858 1858
         'posts_per_page' => $args['limit'],
1859 1859
         'meta_query'     => array(),
1860
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1860
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1861 1861
         'fields'         => 'ids',
1862 1862
         'orderby'        => $args['orderby'],
1863 1863
         'order'          => $args['order'],
1864 1864
     );
1865 1865
     
1866
-    if ( !empty( $args['user'] ) ) {
1867
-        $wp_query_args['author'] = absint( $args['user'] );
1866
+    if (!empty($args['user'])) {
1867
+        $wp_query_args['author'] = absint($args['user']);
1868 1868
     }
1869 1869
 
1870
-    if ( ! is_null( $args['parent'] ) ) {
1871
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1870
+    if (!is_null($args['parent'])) {
1871
+        $wp_query_args['post_parent'] = absint($args['parent']);
1872 1872
     }
1873 1873
 
1874
-    if ( ! is_null( $args['offset'] ) ) {
1875
-        $wp_query_args['offset'] = absint( $args['offset'] );
1874
+    if (!is_null($args['offset'])) {
1875
+        $wp_query_args['offset'] = absint($args['offset']);
1876 1876
     } else {
1877
-        $wp_query_args['paged'] = absint( $args['page'] );
1877
+        $wp_query_args['paged'] = absint($args['page']);
1878 1878
     }
1879 1879
 
1880
-    if ( ! empty( $args['exclude'] ) ) {
1881
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1880
+    if (!empty($args['exclude'])) {
1881
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1882 1882
     }
1883 1883
 
1884
-    if ( ! $args['paginate' ] ) {
1884
+    if (!$args['paginate']) {
1885 1885
         $wp_query_args['no_found_rows'] = true;
1886 1886
     }
1887 1887
 
1888 1888
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1889 1889
 
1890 1890
     // Get results.
1891
-    $invoices = new WP_Query( $wp_query_args );
1891
+    $invoices = new WP_Query($wp_query_args);
1892 1892
 
1893
-    if ( 'objects' === $args['return'] ) {
1894
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1895
-    } elseif ( 'self' === $args['return'] ) {
1893
+    if ('objects' === $args['return']) {
1894
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1895
+    } elseif ('self' === $args['return']) {
1896 1896
         return $invoices;
1897 1897
     } else {
1898 1898
         $return = $invoices->posts;
1899 1899
     }
1900 1900
 
1901
-    if ( $args['paginate' ] ) {
1901
+    if ($args['paginate']) {
1902 1902
         return (object) array(
1903 1903
             'invoices'      => $return,
1904 1904
             'total'         => $invoices->found_posts,
@@ -1911,22 +1911,22 @@  discard block
 block discarded – undo
1911 1911
 
1912 1912
 function wpinv_get_user_invoices_columns() {
1913 1913
     $columns = array(
1914
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1915
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1916
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1917
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1918
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1919
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1914
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1915
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1916
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1917
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1918
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1919
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1920 1920
         );
1921 1921
 
1922
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1922
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1923 1923
 }
1924 1924
 
1925
-function wpinv_payment_receipt( $atts, $content = null ) {
1925
+function wpinv_payment_receipt($atts, $content = null) {
1926 1926
     global $wpinv_receipt_args;
1927 1927
 
1928
-    $wpinv_receipt_args = shortcode_atts( array(
1929
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1928
+    $wpinv_receipt_args = shortcode_atts(array(
1929
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1930 1930
         'price'           => true,
1931 1931
         'discount'        => true,
1932 1932
         'items'           => true,
@@ -1935,45 +1935,45 @@  discard block
 block discarded – undo
1935 1935
         'invoice_key'     => false,
1936 1936
         'payment_method'  => true,
1937 1937
         'invoice_id'      => true
1938
-    ), $atts, 'wpinv_receipt' );
1938
+    ), $atts, 'wpinv_receipt');
1939 1939
 
1940 1940
     // Find the invoice.
1941 1941
     $session = wpinv_get_checkout_session();
1942 1942
 
1943
-    if ( isset( $_GET['invoice_key'] ) ) {
1944
-        $invoice_id = wpinv_get_invoice_id_by_key( urldecode( $_GET['invoice_key'] ) );
1945
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1943
+    if (isset($_GET['invoice_key'])) {
1944
+        $invoice_id = wpinv_get_invoice_id_by_key(urldecode($_GET['invoice_key']));
1945
+    } else if (isset($_GET['invoice-id'])) {
1946 1946
         $invoice_id = (int) $_GET['invoice-id'];
1947
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1948
-        $invoice_id = wpinv_get_invoice_id_by_key( $session['invoice_key'] );
1949
-    } else if ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1950
-        $invoice_id = wpinv_get_invoice_id_by_key( $wpinv_receipt_args['invoice_key'] );
1947
+    } else if ($session && isset($session['invoice_key'])) {
1948
+        $invoice_id = wpinv_get_invoice_id_by_key($session['invoice_key']);
1949
+    } else if (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1950
+        $invoice_id = wpinv_get_invoice_id_by_key($wpinv_receipt_args['invoice_key']);
1951 1951
     }
1952 1952
 
1953 1953
     // Did we find the invoice?
1954
-    if ( empty( $invoice_id ) || ! $invoice = wpinv_get_invoice( $invoice_id ) ) {
1955
-        return '<p class="alert alert-error">' . __( 'We could not find your invoice.', 'invoicing' ) . '</p>';
1954
+    if (empty($invoice_id) || !$invoice = wpinv_get_invoice($invoice_id)) {
1955
+        return '<p class="alert alert-error">' . __('We could not find your invoice.', 'invoicing') . '</p>';
1956 1956
     }
1957 1957
 
1958 1958
     $invoice_key   = $invoice->get_key();
1959
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1960
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1961
-        $user_can_view  = $_GET['invoice-id'] == $invoice->ID;
1959
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1960
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1961
+        $user_can_view = $_GET['invoice-id'] == $invoice->ID;
1962 1962
     }
1963 1963
 
1964 1964
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1965
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1965
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1966 1966
         // login redirect
1967
-        return '<p class="alert alert-error">' . __( 'You must be logged in to view this receipt', 'invoicing' ) . '</p>';
1967
+        return '<p class="alert alert-error">' . __('You must be logged in to view this receipt', 'invoicing') . '</p>';
1968 1968
     }
1969 1969
 
1970
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1970
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1971 1971
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1972 1972
     }
1973 1973
 
1974 1974
     ob_start();
1975 1975
 
1976
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1976
+    wpinv_get_template_part('wpinv-invoice-receipt');
1977 1977
 
1978 1978
     $display = ob_get_clean();
1979 1979
 
@@ -1983,148 +1983,148 @@  discard block
 block discarded – undo
1983 1983
 /**
1984 1984
  * Given an invoice key, this function returns the id.
1985 1985
  */
1986
-function wpinv_get_invoice_id_by_key( $key ) {
1986
+function wpinv_get_invoice_id_by_key($key) {
1987 1987
 	global $wpdb;
1988
-    $table      = $wpdb->prefix . 'getpaid_invoices';
1989
-	return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1988
+    $table = $wpdb->prefix . 'getpaid_invoices';
1989
+	return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key));
1990 1990
 }
1991 1991
 
1992
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1993
-	$return = current_user_can( 'manage_options' );
1992
+function wpinv_can_view_receipt($invoice_key = '') {
1993
+	$return = current_user_can('manage_options');
1994 1994
 
1995
-	if ( empty( $invoice_key ) ) {
1995
+	if (empty($invoice_key)) {
1996 1996
 		return false;
1997 1997
 	}
1998 1998
 
1999 1999
 	global $wpinv_receipt_args;
2000 2000
 
2001
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
2002
-	if ( isset( $_GET['invoice-id'] ) ) {
2003
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
2001
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
2002
+	if (isset($_GET['invoice-id'])) {
2003
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
2004 2004
 	}
2005 2005
 
2006
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
2006
+	if (empty($wpinv_receipt_args['id'])) {
2007 2007
 		return $return;
2008 2008
 	}
2009 2009
 
2010
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
2011
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
2010
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
2011
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
2012 2012
 		return $return;
2013 2013
 	}
2014 2014
 
2015
-	if ( is_user_logged_in() ) {
2016
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
2015
+	if (is_user_logged_in()) {
2016
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
2017 2017
 			$return = true;
2018 2018
 		}
2019 2019
 	}
2020 2020
 
2021 2021
 	$session = wpinv_get_checkout_session();
2022
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
2023
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
2022
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
2023
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
2024 2024
 
2025
-		if ( wpinv_require_login_to_checkout() ) {
2025
+		if (wpinv_require_login_to_checkout()) {
2026 2026
 			$return = $return && $check_key == $invoice_key;
2027 2027
 		} else {
2028 2028
 			$return = $check_key == $invoice_key;
2029 2029
 		}
2030 2030
 	}
2031 2031
 
2032
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2032
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2033 2033
 }
2034 2034
 
2035 2035
 function wpinv_pay_for_invoice() {
2036 2036
     global $wpinv_euvat;
2037 2037
     
2038
-    if ( isset( $_GET['invoice_key'] ) ) {
2038
+    if (isset($_GET['invoice_key'])) {
2039 2039
         $checkout_uri   = wpinv_get_checkout_uri();
2040
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2040
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2041 2041
         
2042
-        if ( empty( $invoice_key ) ) {
2043
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2044
-            wp_redirect( $checkout_uri );
2042
+        if (empty($invoice_key)) {
2043
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2044
+            wp_redirect($checkout_uri);
2045 2045
             exit();
2046 2046
         }
2047 2047
         
2048
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2048
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2049 2049
 
2050
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2051
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2052
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2053
-            $invoice_id     = (int)$_GET['invoice-id'];
2054
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2050
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2051
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2052
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2053
+            $invoice_id     = (int) $_GET['invoice-id'];
2054
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2055 2055
         }
2056 2056
         
2057
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2058
-            if ( $invoice->needs_payment() ) {
2057
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2058
+            if ($invoice->needs_payment()) {
2059 2059
                 $data                   = array();
2060 2060
                 $data['invoice_id']     = $invoice_id;
2061
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2061
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2062 2062
                 
2063
-                wpinv_set_checkout_session( $data );
2063
+                wpinv_set_checkout_session($data);
2064 2064
                 
2065
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2065
+                if (wpinv_get_option('vat_ip_country_default')) {
2066 2066
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2067 2067
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2068 2068
                     
2069
-                    wpinv_recalculate_tax( true );
2069
+                    wpinv_recalculate_tax(true);
2070 2070
                 }
2071 2071
                 
2072 2072
             } else {
2073 2073
                 $checkout_uri = $invoice->get_view_url();
2074 2074
             }
2075 2075
         } else {
2076
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2076
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2077 2077
             
2078
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2078
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2079 2079
         }
2080 2080
         
2081
-        if(wp_redirect( $checkout_uri )){
2081
+        if (wp_redirect($checkout_uri)) {
2082 2082
             exit;
2083 2083
         };
2084 2084
         wpinv_die();
2085 2085
     }
2086 2086
 }
2087
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2087
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2088 2088
 
2089
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2090
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2091
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2089
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2090
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2091
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2092 2092
             $user_id = $invoice->get_user_id();
2093
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2093
+            $secret = sanitize_text_field($_GET['_wpipay']);
2094 2094
             
2095
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2096
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2095
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2096
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2097 2097
                 
2098
-                wpinv_guest_redirect( $redirect_to, $user_id );
2098
+                wpinv_guest_redirect($redirect_to, $user_id);
2099 2099
                 exit();
2100 2100
             }
2101 2101
         }
2102 2102
     }
2103 2103
 }
2104
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2104
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2105 2105
 
2106
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2107
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2106
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2107
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2108 2108
     
2109
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2109
+    if (empty($invoice_id) && $invoice_id > 0) {
2110 2110
         return false;
2111 2111
     }
2112 2112
     
2113
-    if ( empty( $transaction_id ) ) {
2113
+    if (empty($transaction_id)) {
2114 2114
         $transaction_id = $invoice_id;
2115 2115
     }
2116 2116
 
2117
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2117
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2118 2118
     
2119
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2119
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2120 2120
 }
2121 2121
 
2122
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2123
-    if ( empty( $status_display ) ) {
2124
-        $status_display = wpinv_status_nicename( $status );
2122
+function wpinv_invoice_status_label($status, $status_display = '') {
2123
+    if (empty($status_display)) {
2124
+        $status_display = wpinv_status_nicename($status);
2125 2125
     }
2126 2126
     
2127
-    switch ( $status ) {
2127
+    switch ($status) {
2128 2128
         case 'publish' :
2129 2129
         case 'wpi-renewal' :
2130 2130
             $class = 'label-success';
@@ -2149,201 +2149,201 @@  discard block
 block discarded – undo
2149 2149
     
2150 2150
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2151 2151
     
2152
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2152
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2153 2153
 }
2154 2154
 
2155
-function wpinv_format_invoice_number( $number, $type = '' ) {
2156
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2157
-    if ( null !== $check ) {
2155
+function wpinv_format_invoice_number($number, $type = '') {
2156
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2157
+    if (null !== $check) {
2158 2158
         return $check;
2159 2159
     }
2160 2160
 
2161
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2161
+    if (!empty($number) && !is_numeric($number)) {
2162 2162
         return $number;
2163 2163
     }
2164 2164
 
2165
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2166
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2167
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2165
+    $padd = wpinv_get_option('invoice_number_padd');
2166
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2167
+    $postfix = wpinv_get_option('invoice_number_postfix');
2168 2168
     
2169
-    $padd = absint( $padd );
2170
-    $formatted_number = absint( $number );
2169
+    $padd = absint($padd);
2170
+    $formatted_number = absint($number);
2171 2171
     
2172
-    if ( $padd > 0 ) {
2173
-        $formatted_number = zeroise( $formatted_number, $padd );
2172
+    if ($padd > 0) {
2173
+        $formatted_number = zeroise($formatted_number, $padd);
2174 2174
     }    
2175 2175
 
2176 2176
     $formatted_number = $prefix . $formatted_number . $postfix;
2177 2177
 
2178
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2178
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2179 2179
 }
2180 2180
 
2181
-function wpinv_get_next_invoice_number( $type = '' ) {
2182
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2183
-    if ( null !== $check ) {
2181
+function wpinv_get_next_invoice_number($type = '') {
2182
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2183
+    if (null !== $check) {
2184 2184
         return $check;
2185 2185
     }
2186 2186
     
2187
-    if ( !wpinv_sequential_number_active() ) {
2187
+    if (!wpinv_sequential_number_active()) {
2188 2188
         return false;
2189 2189
     }
2190 2190
 
2191
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2192
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2193
-    if ( !absint( $start ) > 0 ) {
2191
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2192
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2193
+    if (!absint($start) > 0) {
2194 2194
         $start = 1;
2195 2195
     }
2196 2196
     $increment_number = true;
2197 2197
     $save_number = false;
2198 2198
 
2199
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2200
-        $number = wpinv_clean_invoice_number( $number );
2199
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2200
+        $number = wpinv_clean_invoice_number($number);
2201 2201
     }
2202 2202
 
2203
-    if ( empty( $number ) ) {
2204
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2205
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2203
+    if (empty($number)) {
2204
+        if (!($last_number === 0 || $last_number === '0')) {
2205
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2206 2206
 
2207
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2208
-                if ( is_numeric( $invoice_number ) ) {
2207
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2208
+                if (is_numeric($invoice_number)) {
2209 2209
                     $number = $invoice_number;
2210 2210
                 } else {
2211
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2211
+                    $number = wpinv_clean_invoice_number($invoice_number);
2212 2212
                 }
2213 2213
             }
2214 2214
 
2215
-            if ( empty( $number ) ) {
2215
+            if (empty($number)) {
2216 2216
                 $increment_number = false;
2217 2217
                 $number = $start;
2218
-                $save_number = ( $number - 1 );
2218
+                $save_number = ($number - 1);
2219 2219
             } else {
2220 2220
                 $save_number = $number;
2221 2221
             }
2222 2222
         }
2223 2223
     }
2224 2224
 
2225
-    if ( $start > $number ) {
2225
+    if ($start > $number) {
2226 2226
         $increment_number = false;
2227 2227
         $number = $start;
2228
-        $save_number = ( $number - 1 );
2228
+        $save_number = ($number - 1);
2229 2229
     }
2230 2230
 
2231
-    if ( $save_number !== false ) {
2232
-        update_option( 'wpinv_last_invoice_number', $save_number );
2231
+    if ($save_number !== false) {
2232
+        update_option('wpinv_last_invoice_number', $save_number);
2233 2233
     }
2234 2234
     
2235
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2235
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2236 2236
 
2237
-    if ( $increment_number ) {
2237
+    if ($increment_number) {
2238 2238
         $number++;
2239 2239
     }
2240 2240
 
2241
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2241
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2242 2242
 }
2243 2243
 
2244
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2245
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2246
-    if ( null !== $check ) {
2244
+function wpinv_clean_invoice_number($number, $type = '') {
2245
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2246
+    if (null !== $check) {
2247 2247
         return $check;
2248 2248
     }
2249 2249
     
2250
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2251
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2250
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2251
+    $postfix = wpinv_get_option('invoice_number_postfix');
2252 2252
 
2253
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2253
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2254 2254
 
2255
-    $length      = strlen( $number );
2256
-    $postfix_pos = strrpos( $number, $postfix );
2255
+    $length      = strlen($number);
2256
+    $postfix_pos = strrpos($number, $postfix);
2257 2257
     
2258
-    if ( false !== $postfix_pos ) {
2259
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2258
+    if (false !== $postfix_pos) {
2259
+        $number = substr_replace($number, '', $postfix_pos, $length);
2260 2260
     }
2261 2261
 
2262
-    $number = intval( $number );
2262
+    $number = intval($number);
2263 2263
 
2264
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2264
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2265 2265
 }
2266 2266
 
2267
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2267
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2268 2268
     global $wpdb;
2269 2269
 
2270
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2271
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2270
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2271
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2272 2272
     }
2273 2273
 
2274
-    if ( !$update ) {
2275
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2276
-        clean_post_cache( $post_ID );
2274
+    if (!$update) {
2275
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2276
+        clean_post_cache($post_ID);
2277 2277
     }
2278 2278
 }
2279
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2279
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2280 2280
 
2281
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2282
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2283
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2281
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2282
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2283
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2284 2284
     }
2285 2285
 }
2286
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2286
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2287 2287
 
2288
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2288
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2289 2289
     global $wpdb;
2290 2290
     
2291
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2292
-    if ( null !== $check ) {
2291
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2292
+    if (null !== $check) {
2293 2293
         return $check;
2294 2294
     }
2295 2295
 
2296
-    if ( wpinv_sequential_number_active() ) {
2296
+    if (wpinv_sequential_number_active()) {
2297 2297
         $number = wpinv_get_next_invoice_number();
2298 2298
 
2299
-        if ( $save_sequential ) {
2300
-            update_option( 'wpinv_last_invoice_number', $number );
2299
+        if ($save_sequential) {
2300
+            update_option('wpinv_last_invoice_number', $number);
2301 2301
         }
2302 2302
     } else {
2303 2303
         $number = $post_ID;
2304 2304
     }
2305 2305
 
2306
-    $number = wpinv_format_invoice_number( $number );
2306
+    $number = wpinv_format_invoice_number($number);
2307 2307
 
2308
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2308
+    update_post_meta($post_ID, '_wpinv_number', $number);
2309 2309
 
2310
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2310
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2311 2311
 
2312
-    clean_post_cache( $post_ID );
2312
+    clean_post_cache($post_ID);
2313 2313
 
2314 2314
     return $number;
2315 2315
 }
2316 2316
 
2317
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2318
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2317
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2318
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2319 2319
 }
2320 2320
 
2321
-function wpinv_generate_post_name( $post_ID ) {
2322
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2323
-    $post_name = sanitize_title( $prefix . $post_ID );
2321
+function wpinv_generate_post_name($post_ID) {
2322
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2323
+    $post_name = sanitize_title($prefix . $post_ID);
2324 2324
 
2325
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2325
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2326 2326
 }
2327 2327
 
2328
-function wpinv_is_invoice_viewed( $invoice_id ) {
2329
-    if ( empty( $invoice_id ) ) {
2328
+function wpinv_is_invoice_viewed($invoice_id) {
2329
+    if (empty($invoice_id)) {
2330 2330
         return false;
2331 2331
     }
2332 2332
 
2333
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2333
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2334 2334
 
2335
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2335
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2336 2336
 }
2337 2337
 
2338 2338
 function wpinv_mark_invoice_viewed() {
2339 2339
 
2340
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2341
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2340
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2341
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2342 2342
 	    global $post;
2343 2343
 
2344
-        if(!empty($invoice_key)){
2344
+        if (!empty($invoice_key)) {
2345 2345
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2346
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2346
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2347 2347
 			$invoice_id = $post->ID;
2348 2348
         } else {
2349 2349
         	return;
@@ -2351,63 +2351,63 @@  discard block
 block discarded – undo
2351 2351
 
2352 2352
         $invoice = new WPInv_Invoice($invoice_id);
2353 2353
 
2354
-        if(!$invoice_id){
2354
+        if (!$invoice_id) {
2355 2355
             return;
2356 2356
         }
2357 2357
 
2358
-	    if ( is_user_logged_in() ) {
2359
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2360
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2361
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2362
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2358
+	    if (is_user_logged_in()) {
2359
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2360
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2361
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2362
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2363 2363
 		    }
2364 2364
 	    } else {
2365
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2366
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2365
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2366
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2367 2367
 		    }
2368 2368
 	    }
2369 2369
     }
2370 2370
 
2371 2371
 }
2372
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2372
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2373 2373
 
2374 2374
 /**
2375 2375
  * @return WPInv_Subscription
2376 2376
  */
2377
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2378
-    if ( empty( $invoice ) ) {
2377
+function wpinv_get_subscription($invoice, $by_parent = false) {
2378
+    if (empty($invoice)) {
2379 2379
         return false;
2380 2380
     }
2381 2381
     
2382
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2383
-        $invoice = wpinv_get_invoice( $invoice );
2382
+    if (!is_object($invoice) && is_scalar($invoice)) {
2383
+        $invoice = wpinv_get_invoice($invoice);
2384 2384
     }
2385 2385
     
2386
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2386
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2387 2387
         return false;
2388 2388
     }
2389 2389
     
2390
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2390
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2391 2391
     
2392 2392
     $subs_db    = new WPInv_Subscriptions_DB;
2393
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2393
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2394 2394
     
2395
-    if ( ! empty( $subs ) ) {
2396
-        return reset( $subs );
2395
+    if (!empty($subs)) {
2396
+        return reset($subs);
2397 2397
     }
2398 2398
     
2399 2399
     return false;
2400 2400
 }
2401 2401
 
2402
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2402
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2403 2403
     global $wpdb;
2404 2404
 
2405
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2406
-        if ( !empty( $clauses['join'] ) ) {
2405
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2406
+        if (!empty($clauses['join'])) {
2407 2407
             $clauses['join'] .= " ";
2408 2408
         }
2409 2409
 
2410
-        if ( !empty( $clauses['fields'] ) ) {
2410
+        if (!empty($clauses['fields'])) {
2411 2411
             $clauses['fields'] .= ", ";
2412 2412
         }
2413 2413
 
@@ -2418,7 +2418,7 @@  discard block
 block discarded – undo
2418 2418
 
2419 2419
     return $clauses;
2420 2420
 }
2421
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2421
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2422 2422
 
2423 2423
 /**
2424 2424
  * Processes an invoice refund.
@@ -2428,27 +2428,27 @@  discard block
 block discarded – undo
2428 2428
  * @param array $status_transition
2429 2429
  * @todo: descrease customer/store earnings
2430 2430
  */
2431
-function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) {
2431
+function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) {
2432 2432
 
2433
-    if ( empty( $status_transition['from'] ) || ! $invoice->has_status( 'wpi-refunded' ) || in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
2433
+    if (empty($status_transition['from']) || !$invoice->has_status('wpi-refunded') || in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
2434 2434
         return;
2435 2435
     }
2436 2436
 
2437 2437
     $discount_code = $invoice->get_discount_code();
2438
-    if ( ! empty( $discount_code ) ) {
2439
-        $discount = wpinv_get_discount_obj( $discount_code );
2438
+    if (!empty($discount_code)) {
2439
+        $discount = wpinv_get_discount_obj($discount_code);
2440 2440
 
2441
-        if ( $discount->exists() ) {
2441
+        if ($discount->exists()) {
2442 2442
             $discount->increase_usage( -1 );
2443 2443
         }
2444 2444
     
2445 2445
     }
2446 2446
 
2447
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id );
2448
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice_id );
2449
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id );
2447
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id);
2448
+    do_action('wpinv_refund_invoice', $invoice, $invoice_id);
2449
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice_id);
2450 2450
 }
2451
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 );
2451
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3);
2452 2452
 
2453 2453
 /**
2454 2454
  * Fires when a payment fails.
@@ -2456,22 +2456,22 @@  discard block
 block discarded – undo
2456 2456
  * @param int $invoice_id
2457 2457
  * @param WPInv_Invoice $invoice
2458 2458
  */
2459
-function getpaid_maybe_process_failure( $invoice_id, $invoice ) {
2459
+function getpaid_maybe_process_failure($invoice_id, $invoice) {
2460 2460
 
2461
-    if ( ! $invoice->has_status( 'wpi-failed' ) ) {
2461
+    if (!$invoice->has_status('wpi-failed')) {
2462 2462
         return;
2463 2463
     }
2464 2464
 
2465 2465
     $discount_code = $invoice->get_discount_code();
2466
-    if ( ! empty( $discount_code ) ) {
2467
-        $discount = wpinv_get_discount_obj( $discount_code );
2466
+    if (!empty($discount_code)) {
2467
+        $discount = wpinv_get_discount_obj($discount_code);
2468 2468
 
2469
-        if ( $discount->exists() ) {
2469
+        if ($discount->exists()) {
2470 2470
             $discount->increase_usage( -1 );
2471 2471
         }
2472 2472
 
2473 2473
     }
2474 2474
 
2475
-    do_action( 'wpinv_invoice_payment_failed', $invoice, $invoice_id );
2475
+    do_action('wpinv_invoice_payment_failed', $invoice, $invoice_id);
2476 2476
 }
2477
-add_action( 'getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2 );
2478 2477
\ No newline at end of file
2478
+add_action('getpaid_invoice_status_wpi-failed', 'getpaid_maybe_process_failure', 10, 2);
2479 2479
\ No newline at end of file
Please login to merge, or discard this patch.