Passed
Push — master ( c0eaca...2632ed )
by Brian
04:50
created
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +862 added lines, -862 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|string $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
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
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 && $this->exists() ) {
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.', 'invoicing' ), $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.', 'invoicing' ), $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|string $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
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
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 && $this->exists() ) {
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.', 'invoicing' ), $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.', 'invoicing' ), $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,10 +378,10 @@  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
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,514 +391,514 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// 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()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-
508
-		$this->save();
509
-	}
510
-
511
-	/**
512
-	 * Update meta data by key or ID, if provided.
513
-	 *
514
-	 * @since  1.0.19
515
-	 *
516
-	 * @param  string       $key Meta key.
517
-	 * @param  string|array $value Meta value.
518
-	 * @param  int          $meta_id Meta ID.
519
-	 */
520
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
-		if ( $this->is_internal_meta_key( $key ) ) {
522
-			$function = 'set_' . $key;
523
-
524
-			if ( is_callable( array( $this, $function ) ) ) {
525
-				return $this->{$function}( $value );
526
-			}
527
-		}
528
-
529
-		$this->maybe_read_meta_data();
530
-
531
-		$array_key = false;
532
-
533
-		if ( $meta_id ) {
534
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
-			$array_key  = $array_keys ? current( $array_keys ) : false;
536
-		} else {
537
-			// Find matches by key.
538
-			$matches = array();
539
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
-				if ( $meta->key === $key ) {
541
-					$matches[] = $meta_data_array_key;
542
-				}
543
-			}
544
-
545
-			if ( ! empty( $matches ) ) {
546
-				// Set matches to null so only one key gets the new value.
547
-				foreach ( $matches as $meta_data_array_key ) {
548
-					$this->meta_data[ $meta_data_array_key ]->value = null;
549
-				}
550
-				$array_key = current( $matches );
551
-			}
552
-		}
553
-
554
-		if ( false !== $array_key ) {
555
-			$meta        = $this->meta_data[ $array_key ];
556
-			$meta->key   = $key;
557
-			$meta->value = $value;
558
-		} else {
559
-			$this->add_meta_data( $key, $value, true );
560
-		}
561
-	}
562
-
563
-	/**
564
-	 * Delete meta data.
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param string $key Meta key.
568
-	 */
569
-	public function delete_meta_data( $key ) {
570
-		$this->maybe_read_meta_data();
571
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
572
-
573
-		if ( $array_keys ) {
574
-			foreach ( $array_keys as $array_key ) {
575
-				$this->meta_data[ $array_key ]->value = null;
576
-			}
577
-		}
578
-	}
579
-
580
-	/**
581
-	 * Delete meta data.
582
-	 *
583
-	 * @since 1.0.19
584
-	 * @param int $mid Meta ID.
585
-	 */
586
-	public function delete_meta_data_by_mid( $mid ) {
587
-		$this->maybe_read_meta_data();
588
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
589
-
590
-		if ( $array_keys ) {
591
-			foreach ( $array_keys as $array_key ) {
592
-				$this->meta_data[ $array_key ]->value = null;
593
-			}
594
-		}
595
-	}
596
-
597
-	/**
598
-	 * Read meta data if null.
599
-	 *
600
-	 * @since 1.0.19
601
-	 */
602
-	protected function maybe_read_meta_data() {
603
-		if ( is_null( $this->meta_data ) ) {
604
-			$this->read_meta_data();
605
-		}
606
-	}
607
-
608
-	/**
609
-	 * Read Meta Data from the database. Ignore any internal properties.
610
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param bool $force_read True to force a new DB read (and update cache).
614
-	 */
615
-	public function read_meta_data( $force_read = false ) {
616
-
617
-		// Reset meta data.
618
-		$this->meta_data = array();
619
-
620
-		// Maybe abort early.
621
-		if ( ! $this->get_id() || ! $this->data_store ) {
622
-			return;
623
-		}
624
-
625
-		// Only read from cache if the cache key is set.
626
-		$cache_key = null;
627
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
-			$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();
629
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
630
-		}
631
-
632
-		// Should we force read?
633
-		if ( empty( $raw_meta_data ) ) {
634
-			$raw_meta_data = $this->data_store->read_meta( $this );
635
-
636
-			if ( ! empty( $cache_key ) ) {
637
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
638
-			}
639
-
640
-		}
641
-
642
-		// Set meta data.
643
-		if ( is_array( $raw_meta_data ) ) {
644
-
645
-			foreach ( $raw_meta_data as $meta ) {
646
-				$this->meta_data[] = new GetPaid_Meta_Data(
647
-					array(
648
-						'id'    => (int) $meta->meta_id,
649
-						'key'   => $meta->meta_key,
650
-						'value' => maybe_unserialize( $meta->meta_value ),
651
-					)
652
-				);
653
-			}
654
-
655
-		}
656
-
657
-	}
658
-
659
-	/**
660
-	 * Update Meta Data in the database.
661
-	 *
662
-	 * @since 1.0.19
663
-	 */
664
-	public function save_meta_data() {
665
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
666
-			return;
667
-		}
668
-		foreach ( $this->meta_data as $array_key => $meta ) {
669
-			if ( is_null( $meta->value ) ) {
670
-				if ( ! empty( $meta->id ) ) {
671
-					$this->data_store->delete_meta( $this, $meta );
672
-					unset( $this->meta_data[ $array_key ] );
673
-				}
674
-			} elseif ( empty( $meta->id ) ) {
675
-				$meta->id = $this->data_store->add_meta( $this, $meta );
676
-				$meta->apply_changes();
677
-			} else {
678
-				if ( $meta->get_changes() ) {
679
-					$this->data_store->update_meta( $this, $meta );
680
-					$meta->apply_changes();
681
-				}
682
-			}
683
-		}
684
-		if ( ! empty( $this->cache_group ) ) {
685
-			$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();
686
-			wp_cache_delete( $cache_key, $this->cache_group );
687
-		}
688
-	}
689
-
690
-	/**
691
-	 * Set ID.
692
-	 *
693
-	 * @since 1.0.19
694
-	 * @param int $id ID.
695
-	 */
696
-	public function set_id( $id ) {
697
-		$this->id = absint( $id );
698
-	}
699
-
700
-	/**
701
-	 * Sets item status.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @param string $status New status.
705
-	 * @return array details of change.
706
-	 */
707
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // 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()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+
508
+        $this->save();
509
+    }
510
+
511
+    /**
512
+     * Update meta data by key or ID, if provided.
513
+     *
514
+     * @since  1.0.19
515
+     *
516
+     * @param  string       $key Meta key.
517
+     * @param  string|array $value Meta value.
518
+     * @param  int          $meta_id Meta ID.
519
+     */
520
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
+        if ( $this->is_internal_meta_key( $key ) ) {
522
+            $function = 'set_' . $key;
523
+
524
+            if ( is_callable( array( $this, $function ) ) ) {
525
+                return $this->{$function}( $value );
526
+            }
527
+        }
528
+
529
+        $this->maybe_read_meta_data();
530
+
531
+        $array_key = false;
532
+
533
+        if ( $meta_id ) {
534
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
+            $array_key  = $array_keys ? current( $array_keys ) : false;
536
+        } else {
537
+            // Find matches by key.
538
+            $matches = array();
539
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
+                if ( $meta->key === $key ) {
541
+                    $matches[] = $meta_data_array_key;
542
+                }
543
+            }
544
+
545
+            if ( ! empty( $matches ) ) {
546
+                // Set matches to null so only one key gets the new value.
547
+                foreach ( $matches as $meta_data_array_key ) {
548
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
549
+                }
550
+                $array_key = current( $matches );
551
+            }
552
+        }
553
+
554
+        if ( false !== $array_key ) {
555
+            $meta        = $this->meta_data[ $array_key ];
556
+            $meta->key   = $key;
557
+            $meta->value = $value;
558
+        } else {
559
+            $this->add_meta_data( $key, $value, true );
560
+        }
561
+    }
562
+
563
+    /**
564
+     * Delete meta data.
565
+     *
566
+     * @since 1.0.19
567
+     * @param string $key Meta key.
568
+     */
569
+    public function delete_meta_data( $key ) {
570
+        $this->maybe_read_meta_data();
571
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
572
+
573
+        if ( $array_keys ) {
574
+            foreach ( $array_keys as $array_key ) {
575
+                $this->meta_data[ $array_key ]->value = null;
576
+            }
577
+        }
578
+    }
579
+
580
+    /**
581
+     * Delete meta data.
582
+     *
583
+     * @since 1.0.19
584
+     * @param int $mid Meta ID.
585
+     */
586
+    public function delete_meta_data_by_mid( $mid ) {
587
+        $this->maybe_read_meta_data();
588
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
589
+
590
+        if ( $array_keys ) {
591
+            foreach ( $array_keys as $array_key ) {
592
+                $this->meta_data[ $array_key ]->value = null;
593
+            }
594
+        }
595
+    }
596
+
597
+    /**
598
+     * Read meta data if null.
599
+     *
600
+     * @since 1.0.19
601
+     */
602
+    protected function maybe_read_meta_data() {
603
+        if ( is_null( $this->meta_data ) ) {
604
+            $this->read_meta_data();
605
+        }
606
+    }
607
+
608
+    /**
609
+     * Read Meta Data from the database. Ignore any internal properties.
610
+     * Uses it's own caches because get_metadata does not provide meta_ids.
611
+     *
612
+     * @since 1.0.19
613
+     * @param bool $force_read True to force a new DB read (and update cache).
614
+     */
615
+    public function read_meta_data( $force_read = false ) {
616
+
617
+        // Reset meta data.
618
+        $this->meta_data = array();
619
+
620
+        // Maybe abort early.
621
+        if ( ! $this->get_id() || ! $this->data_store ) {
622
+            return;
623
+        }
624
+
625
+        // Only read from cache if the cache key is set.
626
+        $cache_key = null;
627
+        if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
+            $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();
629
+            $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
630
+        }
631
+
632
+        // Should we force read?
633
+        if ( empty( $raw_meta_data ) ) {
634
+            $raw_meta_data = $this->data_store->read_meta( $this );
635
+
636
+            if ( ! empty( $cache_key ) ) {
637
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
638
+            }
639
+
640
+        }
641
+
642
+        // Set meta data.
643
+        if ( is_array( $raw_meta_data ) ) {
644
+
645
+            foreach ( $raw_meta_data as $meta ) {
646
+                $this->meta_data[] = new GetPaid_Meta_Data(
647
+                    array(
648
+                        'id'    => (int) $meta->meta_id,
649
+                        'key'   => $meta->meta_key,
650
+                        'value' => maybe_unserialize( $meta->meta_value ),
651
+                    )
652
+                );
653
+            }
654
+
655
+        }
656
+
657
+    }
658
+
659
+    /**
660
+     * Update Meta Data in the database.
661
+     *
662
+     * @since 1.0.19
663
+     */
664
+    public function save_meta_data() {
665
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
666
+            return;
667
+        }
668
+        foreach ( $this->meta_data as $array_key => $meta ) {
669
+            if ( is_null( $meta->value ) ) {
670
+                if ( ! empty( $meta->id ) ) {
671
+                    $this->data_store->delete_meta( $this, $meta );
672
+                    unset( $this->meta_data[ $array_key ] );
673
+                }
674
+            } elseif ( empty( $meta->id ) ) {
675
+                $meta->id = $this->data_store->add_meta( $this, $meta );
676
+                $meta->apply_changes();
677
+            } else {
678
+                if ( $meta->get_changes() ) {
679
+                    $this->data_store->update_meta( $this, $meta );
680
+                    $meta->apply_changes();
681
+                }
682
+            }
683
+        }
684
+        if ( ! empty( $this->cache_group ) ) {
685
+            $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();
686
+            wp_cache_delete( $cache_key, $this->cache_group );
687
+        }
688
+    }
689
+
690
+    /**
691
+     * Set ID.
692
+     *
693
+     * @since 1.0.19
694
+     * @param int $id ID.
695
+     */
696
+    public function set_id( $id ) {
697
+        $this->id = absint( $id );
698
+    }
699
+
700
+    /**
701
+     * Sets item status.
702
+     *
703
+     * @since 1.0.19
704
+     * @param string $status New status.
705
+     * @return array details of change.
706
+     */
707
+    public function set_status( $status ) {
708 708
         $old_status = $this->get_status();
709 709
 
710
-		$this->set_prop( 'status', $status );
711
-
712
-		return array(
713
-			'from' => $old_status,
714
-			'to'   => $status,
715
-		);
716
-    }
717
-
718
-	/**
719
-	 * Set all props to default values.
720
-	 *
721
-	 * @since 1.0.19
722
-	 */
723
-	public function set_defaults() {
724
-		$this->data    = $this->default_data;
725
-		$this->changes = array();
726
-		$this->set_object_read( false );
727
-	}
728
-
729
-	/**
730
-	 * Set object read property.
731
-	 *
732
-	 * @since 1.0.19
733
-	 * @param boolean $read Should read?.
734
-	 */
735
-	public function set_object_read( $read = true ) {
736
-		$this->object_read = (bool) $read;
737
-	}
738
-
739
-	/**
740
-	 * Get object read property.
741
-	 *
742
-	 * @since  1.0.19
743
-	 * @return boolean
744
-	 */
745
-	public function get_object_read() {
746
-		return (bool) $this->object_read;
747
-	}
748
-
749
-	/**
750
-	 * Set a collection of props in one go, collect any errors, and return the result.
751
-	 * Only sets using public methods.
752
-	 *
753
-	 * @since  1.0.19
754
-	 *
755
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
756
-	 * @param string $context In what context to run this.
757
-	 *
758
-	 * @return bool|WP_Error
759
-	 */
760
-	public function set_props( $props, $context = 'set' ) {
761
-		$errors = false;
762
-
763
-		foreach ( $props as $prop => $value ) {
764
-			try {
765
-				/**
766
-				 * Checks if the prop being set is allowed, and the value is not null.
767
-				 */
768
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
769
-					continue;
770
-				}
771
-				$setter = "set_$prop";
772
-
773
-				if ( is_callable( array( $this, $setter ) ) ) {
774
-					$this->{$setter}( $value );
775
-				}
776
-			} catch ( Exception $e ) {
777
-				if ( ! $errors ) {
778
-					$errors = new WP_Error();
779
-				}
780
-				$errors->add( $e->getCode(), $e->getMessage() );
781
-				$this->last_error = $e->getMessage();
782
-			}
783
-		}
784
-
785
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
786
-	}
787
-
788
-	/**
789
-	 * Sets a prop for a setter method.
790
-	 *
791
-	 * This stores changes in a special array so we can track what needs saving
792
-	 * the the DB later.
793
-	 *
794
-	 * @since 1.0.19
795
-	 * @param string $prop Name of prop to set.
796
-	 * @param mixed  $value Value of the prop.
797
-	 */
798
-	protected function set_prop( $prop, $value ) {
799
-		if ( array_key_exists( $prop, $this->data ) ) {
800
-			if ( true === $this->object_read ) {
801
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
802
-					$this->changes[ $prop ] = $value;
803
-				}
804
-			} else {
805
-				$this->data[ $prop ] = $value;
806
-			}
807
-		}
808
-	}
809
-
810
-	/**
811
-	 * Return data changes only.
812
-	 *
813
-	 * @since 1.0.19
814
-	 * @return array
815
-	 */
816
-	public function get_changes() {
817
-		return $this->changes;
818
-	}
819
-
820
-	/**
821
-	 * Merge changes with data and clear.
822
-	 *
823
-	 * @since 1.0.19
824
-	 */
825
-	public function apply_changes() {
826
-		$this->data    = array_replace( $this->data, $this->changes );
827
-		$this->changes = array();
828
-	}
829
-
830
-	/**
831
-	 * Prefix for action and filter hooks on data.
832
-	 *
833
-	 * @since  1.0.19
834
-	 * @return string
835
-	 */
836
-	protected function get_hook_prefix() {
837
-		return 'wpinv_get_' . $this->object_type . '_';
838
-	}
839
-
840
-	/**
841
-	 * Gets a prop for a getter method.
842
-	 *
843
-	 * Gets the value from either current pending changes, or the data itself.
844
-	 * Context controls what happens to the value before it's returned.
845
-	 *
846
-	 * @since  1.0.19
847
-	 * @param  string $prop Name of prop to get.
848
-	 * @param  string $context What the value is for. Valid values are view and edit.
849
-	 * @return mixed
850
-	 */
851
-	protected function get_prop( $prop, $context = 'view' ) {
852
-		$value = null;
853
-
854
-		if ( array_key_exists( $prop, $this->data ) ) {
855
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
856
-
857
-			if ( 'view' === $context ) {
858
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
859
-			}
860
-		}
861
-
862
-		return $value;
863
-	}
864
-
865
-	/**
866
-	 * Sets a date prop whilst handling formatting and datetime objects.
867
-	 *
868
-	 * @since 1.0.19
869
-	 * @param string         $prop Name of prop to set.
870
-	 * @param string|integer $value Value of the prop.
871
-	 */
872
-	protected function set_date_prop( $prop, $value ) {
873
-
874
-		if ( empty( $value ) ) {
875
-			$this->set_prop( $prop, null );
876
-			return;
877
-		}
878
-		$this->set_prop( $prop, $value );
879
-
880
-	}
881
-
882
-	/**
883
-	 * When invalid data is found, throw an exception unless reading from the DB.
884
-	 *
885
-	 * @since 1.0.19
886
-	 * @param string $code             Error code.
887
-	 * @param string $message          Error message.
888
-	 */
889
-	protected function error( $code, $message ) {
890
-		$this->last_error = $message;
891
-	}
892
-
893
-	/**
894
-	 * Checks if the object is saved in the database
895
-	 *
896
-	 * @since 1.0.19
897
-	 * @return bool
898
-	 */
899
-	public function exists() {
900
-		$id = $this->get_id();
901
-		return ! empty( $id );
902
-	}
710
+        $this->set_prop( 'status', $status );
711
+
712
+        return array(
713
+            'from' => $old_status,
714
+            'to'   => $status,
715
+        );
716
+    }
717
+
718
+    /**
719
+     * Set all props to default values.
720
+     *
721
+     * @since 1.0.19
722
+     */
723
+    public function set_defaults() {
724
+        $this->data    = $this->default_data;
725
+        $this->changes = array();
726
+        $this->set_object_read( false );
727
+    }
728
+
729
+    /**
730
+     * Set object read property.
731
+     *
732
+     * @since 1.0.19
733
+     * @param boolean $read Should read?.
734
+     */
735
+    public function set_object_read( $read = true ) {
736
+        $this->object_read = (bool) $read;
737
+    }
738
+
739
+    /**
740
+     * Get object read property.
741
+     *
742
+     * @since  1.0.19
743
+     * @return boolean
744
+     */
745
+    public function get_object_read() {
746
+        return (bool) $this->object_read;
747
+    }
748
+
749
+    /**
750
+     * Set a collection of props in one go, collect any errors, and return the result.
751
+     * Only sets using public methods.
752
+     *
753
+     * @since  1.0.19
754
+     *
755
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
756
+     * @param string $context In what context to run this.
757
+     *
758
+     * @return bool|WP_Error
759
+     */
760
+    public function set_props( $props, $context = 'set' ) {
761
+        $errors = false;
762
+
763
+        foreach ( $props as $prop => $value ) {
764
+            try {
765
+                /**
766
+                 * Checks if the prop being set is allowed, and the value is not null.
767
+                 */
768
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
769
+                    continue;
770
+                }
771
+                $setter = "set_$prop";
772
+
773
+                if ( is_callable( array( $this, $setter ) ) ) {
774
+                    $this->{$setter}( $value );
775
+                }
776
+            } catch ( Exception $e ) {
777
+                if ( ! $errors ) {
778
+                    $errors = new WP_Error();
779
+                }
780
+                $errors->add( $e->getCode(), $e->getMessage() );
781
+                $this->last_error = $e->getMessage();
782
+            }
783
+        }
784
+
785
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
786
+    }
787
+
788
+    /**
789
+     * Sets a prop for a setter method.
790
+     *
791
+     * This stores changes in a special array so we can track what needs saving
792
+     * the the DB later.
793
+     *
794
+     * @since 1.0.19
795
+     * @param string $prop Name of prop to set.
796
+     * @param mixed  $value Value of the prop.
797
+     */
798
+    protected function set_prop( $prop, $value ) {
799
+        if ( array_key_exists( $prop, $this->data ) ) {
800
+            if ( true === $this->object_read ) {
801
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
802
+                    $this->changes[ $prop ] = $value;
803
+                }
804
+            } else {
805
+                $this->data[ $prop ] = $value;
806
+            }
807
+        }
808
+    }
809
+
810
+    /**
811
+     * Return data changes only.
812
+     *
813
+     * @since 1.0.19
814
+     * @return array
815
+     */
816
+    public function get_changes() {
817
+        return $this->changes;
818
+    }
819
+
820
+    /**
821
+     * Merge changes with data and clear.
822
+     *
823
+     * @since 1.0.19
824
+     */
825
+    public function apply_changes() {
826
+        $this->data    = array_replace( $this->data, $this->changes );
827
+        $this->changes = array();
828
+    }
829
+
830
+    /**
831
+     * Prefix for action and filter hooks on data.
832
+     *
833
+     * @since  1.0.19
834
+     * @return string
835
+     */
836
+    protected function get_hook_prefix() {
837
+        return 'wpinv_get_' . $this->object_type . '_';
838
+    }
839
+
840
+    /**
841
+     * Gets a prop for a getter method.
842
+     *
843
+     * Gets the value from either current pending changes, or the data itself.
844
+     * Context controls what happens to the value before it's returned.
845
+     *
846
+     * @since  1.0.19
847
+     * @param  string $prop Name of prop to get.
848
+     * @param  string $context What the value is for. Valid values are view and edit.
849
+     * @return mixed
850
+     */
851
+    protected function get_prop( $prop, $context = 'view' ) {
852
+        $value = null;
853
+
854
+        if ( array_key_exists( $prop, $this->data ) ) {
855
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
856
+
857
+            if ( 'view' === $context ) {
858
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
859
+            }
860
+        }
861
+
862
+        return $value;
863
+    }
864
+
865
+    /**
866
+     * Sets a date prop whilst handling formatting and datetime objects.
867
+     *
868
+     * @since 1.0.19
869
+     * @param string         $prop Name of prop to set.
870
+     * @param string|integer $value Value of the prop.
871
+     */
872
+    protected function set_date_prop( $prop, $value ) {
873
+
874
+        if ( empty( $value ) ) {
875
+            $this->set_prop( $prop, null );
876
+            return;
877
+        }
878
+        $this->set_prop( $prop, $value );
879
+
880
+    }
881
+
882
+    /**
883
+     * When invalid data is found, throw an exception unless reading from the DB.
884
+     *
885
+     * @since 1.0.19
886
+     * @param string $code             Error code.
887
+     * @param string $message          Error message.
888
+     */
889
+    protected function error( $code, $message ) {
890
+        $this->last_error = $message;
891
+    }
892
+
893
+    /**
894
+     * Checks if the object is saved in the database
895
+     *
896
+     * @since 1.0.19
897
+     * @return bool
898
+     */
899
+    public function exists() {
900
+        $id = $this->get_id();
901
+        return ! empty( $id );
902
+    }
903 903
 
904 904
 }
Please login to merge, or discard this patch.
Spacing   +161 added lines, -161 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|string $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
 	/**
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * If the object no longer exists, remove the ID.
138 138
 	 */
139 139
 	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
140
+		$this->__construct(absint($this->id));
141 141
 
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
142
+		if (!empty($this->last_error)) {
143
+			$this->set_id(0);
144 144
 		}
145 145
 
146 146
 	}
@@ -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 && $this->exists() ) {
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 && $this->exists()) {
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.', 'invoicing' ), $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.', 'invoicing'), $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.', 'invoicing' ), $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.', 'invoicing'), $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,25 +373,25 @@  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
-			if ( 'post_type' != $key ) {
381
+			if ('post_type' != $key) {
382 382
 				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing' ), $key ), '1.0.19' );
383
+				getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'invoicing'), $key), '1.0.19');
384 384
 			}
385 385
 
386
-            return call_user_func( array( $this, 'get_' . $key ) );
386
+            return call_user_func(array($this, 'get_' . $key));
387 387
         }
388 388
 
389 389
         // Check if the key is in the associated $post object.
390
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
390
+        if (!empty($this->post) && isset($this->post->$key)) {
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
394
+		return $this->get_prop($key);
395 395
 
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context What the value is for. Valid values are view and edit.
405 405
 	 * @return mixed
406 406
 	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
407
+	public function get_meta($key = '', $single = true, $context = 'view') {
408 408
 
409 409
 		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $key ) ) {
410
+		$_key = str_replace('_wpinv', '', $key);
411
+		$_key = str_replace('wpinv', '', $_key);
412
+		if ($this->is_internal_meta_key($key)) {
413 413
 			$function = 'get_' . $_key;
414 414
 
415
-			if ( is_callable( array( $this, $function ) ) ) {
415
+			if (is_callable(array($this, $function))) {
416 416
 				return $this->{$function}();
417 417
 			}
418 418
 		}
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 		// Read the meta data if not yet read.
421 421
 		$this->maybe_read_meta_data();
422 422
 		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
423
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
424 424
 		$value      = $single ? '' : array();
425 425
 
426
-		if ( ! empty( $array_keys ) ) {
426
+		if (!empty($array_keys)) {
427 427
 			// 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()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
428
+			if ($single) {
429
+				$value = $meta_data[current($array_keys)]->value;
430 430
 			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
431
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
+		if ('view' === $context) {
436
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
437 437
 		}
438 438
 
439 439
 		return $value;
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $key Meta Key.
447 447
 	 * @return boolean
448 448
 	 */
449
-	public function meta_exists( $key = '' ) {
449
+	public function meta_exists($key = '') {
450 450
 		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
451
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
452
+		return in_array($key, $array_keys, true);
453 453
 	}
454 454
 
455 455
 	/**
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
 	 * @since 1.0.19
459 459
 	 * @param array $data Key/Value pairs.
460 460
 	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
461
+	public function set_meta_data($data) {
462
+		if (!empty($data) && is_array($data)) {
463 463
 			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
464
+			foreach ($data as $meta) {
465 465
 				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
466
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
467 467
 					$this->meta_data[] = new GetPaid_Meta_Data(
468 468
 						array(
469 469
 							'id'    => $meta['id'],
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
 	 * @param string|array $value Meta value.
486 486
 	 * @param bool         $unique Should this be a unique key?.
487 487
 	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
488
+	public function add_meta_data($key, $value, $unique = false) {
489
+		if ($this->is_internal_meta_key($key)) {
490 490
 			$function = 'set_' . $key;
491 491
 
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
492
+			if (is_callable(array($this, $function))) {
493
+				return $this->{$function}($value);
494 494
 			}
495 495
 		}
496 496
 
497 497
 		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
498
+		if ($unique) {
499
+			$this->delete_meta_data($key);
500 500
 		}
501 501
 		$this->meta_data[] = new GetPaid_Meta_Data(
502 502
 			array(
@@ -517,12 +517,12 @@  discard block
 block discarded – undo
517 517
 	 * @param  string|array $value Meta value.
518 518
 	 * @param  int          $meta_id Meta ID.
519 519
 	 */
520
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
521
-		if ( $this->is_internal_meta_key( $key ) ) {
520
+	public function update_meta_data($key, $value, $meta_id = 0) {
521
+		if ($this->is_internal_meta_key($key)) {
522 522
 			$function = 'set_' . $key;
523 523
 
524
-			if ( is_callable( array( $this, $function ) ) ) {
525
-				return $this->{$function}( $value );
524
+			if (is_callable(array($this, $function))) {
525
+				return $this->{$function}($value);
526 526
 			}
527 527
 		}
528 528
 
@@ -530,33 +530,33 @@  discard block
 block discarded – undo
530 530
 
531 531
 		$array_key = false;
532 532
 
533
-		if ( $meta_id ) {
534
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
535
-			$array_key  = $array_keys ? current( $array_keys ) : false;
533
+		if ($meta_id) {
534
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
535
+			$array_key  = $array_keys ? current($array_keys) : false;
536 536
 		} else {
537 537
 			// Find matches by key.
538 538
 			$matches = array();
539
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
540
-				if ( $meta->key === $key ) {
539
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
540
+				if ($meta->key === $key) {
541 541
 					$matches[] = $meta_data_array_key;
542 542
 				}
543 543
 			}
544 544
 
545
-			if ( ! empty( $matches ) ) {
545
+			if (!empty($matches)) {
546 546
 				// Set matches to null so only one key gets the new value.
547
-				foreach ( $matches as $meta_data_array_key ) {
548
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
+				foreach ($matches as $meta_data_array_key) {
548
+					$this->meta_data[$meta_data_array_key]->value = null;
549 549
 				}
550
-				$array_key = current( $matches );
550
+				$array_key = current($matches);
551 551
 			}
552 552
 		}
553 553
 
554
-		if ( false !== $array_key ) {
555
-			$meta        = $this->meta_data[ $array_key ];
554
+		if (false !== $array_key) {
555
+			$meta        = $this->meta_data[$array_key];
556 556
 			$meta->key   = $key;
557 557
 			$meta->value = $value;
558 558
 		} else {
559
-			$this->add_meta_data( $key, $value, true );
559
+			$this->add_meta_data($key, $value, true);
560 560
 		}
561 561
 	}
562 562
 
@@ -566,13 +566,13 @@  discard block
 block discarded – undo
566 566
 	 * @since 1.0.19
567 567
 	 * @param string $key Meta key.
568 568
 	 */
569
-	public function delete_meta_data( $key ) {
569
+	public function delete_meta_data($key) {
570 570
 		$this->maybe_read_meta_data();
571
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
571
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
572 572
 
573
-		if ( $array_keys ) {
574
-			foreach ( $array_keys as $array_key ) {
575
-				$this->meta_data[ $array_key ]->value = null;
573
+		if ($array_keys) {
574
+			foreach ($array_keys as $array_key) {
575
+				$this->meta_data[$array_key]->value = null;
576 576
 			}
577 577
 		}
578 578
 	}
@@ -583,13 +583,13 @@  discard block
 block discarded – undo
583 583
 	 * @since 1.0.19
584 584
 	 * @param int $mid Meta ID.
585 585
 	 */
586
-	public function delete_meta_data_by_mid( $mid ) {
586
+	public function delete_meta_data_by_mid($mid) {
587 587
 		$this->maybe_read_meta_data();
588
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
588
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
589 589
 
590
-		if ( $array_keys ) {
591
-			foreach ( $array_keys as $array_key ) {
592
-				$this->meta_data[ $array_key ]->value = null;
590
+		if ($array_keys) {
591
+			foreach ($array_keys as $array_key) {
592
+				$this->meta_data[$array_key]->value = null;
593 593
 			}
594 594
 		}
595 595
 	}
@@ -600,7 +600,7 @@  discard block
 block discarded – undo
600 600
 	 * @since 1.0.19
601 601
 	 */
602 602
 	protected function maybe_read_meta_data() {
603
-		if ( is_null( $this->meta_data ) ) {
603
+		if (is_null($this->meta_data)) {
604 604
 			$this->read_meta_data();
605 605
 		}
606 606
 	}
@@ -612,42 +612,42 @@  discard block
 block discarded – undo
612 612
 	 * @since 1.0.19
613 613
 	 * @param bool $force_read True to force a new DB read (and update cache).
614 614
 	 */
615
-	public function read_meta_data( $force_read = false ) {
615
+	public function read_meta_data($force_read = false) {
616 616
 
617 617
 		// Reset meta data.
618 618
 		$this->meta_data = array();
619 619
 
620 620
 		// Maybe abort early.
621
-		if ( ! $this->get_id() || ! $this->data_store ) {
621
+		if (!$this->get_id() || !$this->data_store) {
622 622
 			return;
623 623
 		}
624 624
 
625 625
 		// Only read from cache if the cache key is set.
626 626
 		$cache_key = null;
627
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
628
-			$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();
629
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
627
+		if (!$force_read && !empty($this->cache_group)) {
628
+			$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();
629
+			$raw_meta_data = wp_cache_get($cache_key, $this->cache_group);
630 630
 		}
631 631
 
632 632
 		// Should we force read?
633
-		if ( empty( $raw_meta_data ) ) {
634
-			$raw_meta_data = $this->data_store->read_meta( $this );
633
+		if (empty($raw_meta_data)) {
634
+			$raw_meta_data = $this->data_store->read_meta($this);
635 635
 
636
-			if ( ! empty( $cache_key ) ) {
637
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
636
+			if (!empty($cache_key)) {
637
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
638 638
 			}
639 639
 
640 640
 		}
641 641
 
642 642
 		// Set meta data.
643
-		if ( is_array( $raw_meta_data ) ) {
643
+		if (is_array($raw_meta_data)) {
644 644
 
645
-			foreach ( $raw_meta_data as $meta ) {
645
+			foreach ($raw_meta_data as $meta) {
646 646
 				$this->meta_data[] = new GetPaid_Meta_Data(
647 647
 					array(
648 648
 						'id'    => (int) $meta->meta_id,
649 649
 						'key'   => $meta->meta_key,
650
-						'value' => maybe_unserialize( $meta->meta_value ),
650
+						'value' => maybe_unserialize($meta->meta_value),
651 651
 					)
652 652
 				);
653 653
 			}
@@ -662,28 +662,28 @@  discard block
 block discarded – undo
662 662
 	 * @since 1.0.19
663 663
 	 */
664 664
 	public function save_meta_data() {
665
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
665
+		if (!$this->data_store || is_null($this->meta_data)) {
666 666
 			return;
667 667
 		}
668
-		foreach ( $this->meta_data as $array_key => $meta ) {
669
-			if ( is_null( $meta->value ) ) {
670
-				if ( ! empty( $meta->id ) ) {
671
-					$this->data_store->delete_meta( $this, $meta );
672
-					unset( $this->meta_data[ $array_key ] );
668
+		foreach ($this->meta_data as $array_key => $meta) {
669
+			if (is_null($meta->value)) {
670
+				if (!empty($meta->id)) {
671
+					$this->data_store->delete_meta($this, $meta);
672
+					unset($this->meta_data[$array_key]);
673 673
 				}
674
-			} elseif ( empty( $meta->id ) ) {
675
-				$meta->id = $this->data_store->add_meta( $this, $meta );
674
+			} elseif (empty($meta->id)) {
675
+				$meta->id = $this->data_store->add_meta($this, $meta);
676 676
 				$meta->apply_changes();
677 677
 			} else {
678
-				if ( $meta->get_changes() ) {
679
-					$this->data_store->update_meta( $this, $meta );
678
+				if ($meta->get_changes()) {
679
+					$this->data_store->update_meta($this, $meta);
680 680
 					$meta->apply_changes();
681 681
 				}
682 682
 			}
683 683
 		}
684
-		if ( ! empty( $this->cache_group ) ) {
685
-			$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();
686
-			wp_cache_delete( $cache_key, $this->cache_group );
684
+		if (!empty($this->cache_group)) {
685
+			$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();
686
+			wp_cache_delete($cache_key, $this->cache_group);
687 687
 		}
688 688
 	}
689 689
 
@@ -693,8 +693,8 @@  discard block
 block discarded – undo
693 693
 	 * @since 1.0.19
694 694
 	 * @param int $id ID.
695 695
 	 */
696
-	public function set_id( $id ) {
697
-		$this->id = absint( $id );
696
+	public function set_id($id) {
697
+		$this->id = absint($id);
698 698
 	}
699 699
 
700 700
 	/**
@@ -704,10 +704,10 @@  discard block
 block discarded – undo
704 704
 	 * @param string $status New status.
705 705
 	 * @return array details of change.
706 706
 	 */
707
-	public function set_status( $status ) {
707
+	public function set_status($status) {
708 708
         $old_status = $this->get_status();
709 709
 
710
-		$this->set_prop( 'status', $status );
710
+		$this->set_prop('status', $status);
711 711
 
712 712
 		return array(
713 713
 			'from' => $old_status,
@@ -723,7 +723,7 @@  discard block
 block discarded – undo
723 723
 	public function set_defaults() {
724 724
 		$this->data    = $this->default_data;
725 725
 		$this->changes = array();
726
-		$this->set_object_read( false );
726
+		$this->set_object_read(false);
727 727
 	}
728 728
 
729 729
 	/**
@@ -732,7 +732,7 @@  discard block
 block discarded – undo
732 732
 	 * @since 1.0.19
733 733
 	 * @param boolean $read Should read?.
734 734
 	 */
735
-	public function set_object_read( $read = true ) {
735
+	public function set_object_read($read = true) {
736 736
 		$this->object_read = (bool) $read;
737 737
 	}
738 738
 
@@ -757,32 +757,32 @@  discard block
 block discarded – undo
757 757
 	 *
758 758
 	 * @return bool|WP_Error
759 759
 	 */
760
-	public function set_props( $props, $context = 'set' ) {
760
+	public function set_props($props, $context = 'set') {
761 761
 		$errors = false;
762 762
 
763
-		foreach ( $props as $prop => $value ) {
763
+		foreach ($props as $prop => $value) {
764 764
 			try {
765 765
 				/**
766 766
 				 * Checks if the prop being set is allowed, and the value is not null.
767 767
 				 */
768
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
768
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
769 769
 					continue;
770 770
 				}
771 771
 				$setter = "set_$prop";
772 772
 
773
-				if ( is_callable( array( $this, $setter ) ) ) {
774
-					$this->{$setter}( $value );
773
+				if (is_callable(array($this, $setter))) {
774
+					$this->{$setter}($value);
775 775
 				}
776
-			} catch ( Exception $e ) {
777
-				if ( ! $errors ) {
776
+			} catch (Exception $e) {
777
+				if (!$errors) {
778 778
 					$errors = new WP_Error();
779 779
 				}
780
-				$errors->add( $e->getCode(), $e->getMessage() );
780
+				$errors->add($e->getCode(), $e->getMessage());
781 781
 				$this->last_error = $e->getMessage();
782 782
 			}
783 783
 		}
784 784
 
785
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
785
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
786 786
 	}
787 787
 
788 788
 	/**
@@ -795,14 +795,14 @@  discard block
 block discarded – undo
795 795
 	 * @param string $prop Name of prop to set.
796 796
 	 * @param mixed  $value Value of the prop.
797 797
 	 */
798
-	protected function set_prop( $prop, $value ) {
799
-		if ( array_key_exists( $prop, $this->data ) ) {
800
-			if ( true === $this->object_read ) {
801
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
802
-					$this->changes[ $prop ] = $value;
798
+	protected function set_prop($prop, $value) {
799
+		if (array_key_exists($prop, $this->data)) {
800
+			if (true === $this->object_read) {
801
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
802
+					$this->changes[$prop] = $value;
803 803
 				}
804 804
 			} else {
805
-				$this->data[ $prop ] = $value;
805
+				$this->data[$prop] = $value;
806 806
 			}
807 807
 		}
808 808
 	}
@@ -823,7 +823,7 @@  discard block
 block discarded – undo
823 823
 	 * @since 1.0.19
824 824
 	 */
825 825
 	public function apply_changes() {
826
-		$this->data    = array_replace( $this->data, $this->changes );
826
+		$this->data    = array_replace($this->data, $this->changes);
827 827
 		$this->changes = array();
828 828
 	}
829 829
 
@@ -848,14 +848,14 @@  discard block
 block discarded – undo
848 848
 	 * @param  string $context What the value is for. Valid values are view and edit.
849 849
 	 * @return mixed
850 850
 	 */
851
-	protected function get_prop( $prop, $context = 'view' ) {
851
+	protected function get_prop($prop, $context = 'view') {
852 852
 		$value = null;
853 853
 
854
-		if ( array_key_exists( $prop, $this->data ) ) {
855
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
854
+		if (array_key_exists($prop, $this->data)) {
855
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
856 856
 
857
-			if ( 'view' === $context ) {
858
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
857
+			if ('view' === $context) {
858
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
859 859
 			}
860 860
 		}
861 861
 
@@ -869,13 +869,13 @@  discard block
 block discarded – undo
869 869
 	 * @param string         $prop Name of prop to set.
870 870
 	 * @param string|integer $value Value of the prop.
871 871
 	 */
872
-	protected function set_date_prop( $prop, $value ) {
872
+	protected function set_date_prop($prop, $value) {
873 873
 
874
-		if ( empty( $value ) ) {
875
-			$this->set_prop( $prop, null );
874
+		if (empty($value)) {
875
+			$this->set_prop($prop, null);
876 876
 			return;
877 877
 		}
878
-		$this->set_prop( $prop, $value );
878
+		$this->set_prop($prop, $value);
879 879
 
880 880
 	}
881 881
 
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 	 * @param string $code             Error code.
887 887
 	 * @param string $message          Error message.
888 888
 	 */
889
-	protected function error( $code, $message ) {
889
+	protected function error($code, $message) {
890 890
 		$this->last_error = $message;
891 891
 	}
892 892
 
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
 	 */
899 899
 	public function exists() {
900 900
 		$id = $this->get_id();
901
-		return ! empty( $id );
901
+		return !empty($id);
902 902
 	}
903 903
 
904 904
 }
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -4,99 +4,99 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Displays an invoice.
11 11
  * 
12 12
  * @param WPInv_Invoice $invoice.
13 13
  */
14
-function getpaid_invoice( $invoice ) {
15
-    if ( ! empty( $invoice ) ) {
16
-        wpinv_get_template( 'invoice/invoice.php', compact( 'invoice' ) );
14
+function getpaid_invoice($invoice) {
15
+    if (!empty($invoice)) {
16
+        wpinv_get_template('invoice/invoice.php', compact('invoice'));
17 17
     }
18 18
 }
19
-add_action( 'getpaid_invoice', 'getpaid_invoice', 10 );
19
+add_action('getpaid_invoice', 'getpaid_invoice', 10);
20 20
 
21 21
 /**
22 22
  * Displays the invoice footer.
23 23
  */
24
-function getpaid_invoice_footer( $invoice ) {
25
-    if ( ! empty( $invoice ) ) {
26
-        wpinv_get_template( 'invoice/footer.php', compact( 'invoice' ) );
24
+function getpaid_invoice_footer($invoice) {
25
+    if (!empty($invoice)) {
26
+        wpinv_get_template('invoice/footer.php', compact('invoice'));
27 27
     }
28 28
 }
29
-add_action( 'getpaid_invoice_footer', 'getpaid_invoice_footer', 10 );
29
+add_action('getpaid_invoice_footer', 'getpaid_invoice_footer', 10);
30 30
 
31 31
 /**
32 32
  * Displays the invoice top bar.
33 33
  */
34
-function getpaid_invoice_header( $invoice ) {
35
-    if ( ! empty( $invoice ) ) {
36
-        wpinv_get_template( 'invoice/header.php', compact( 'invoice' ) );
34
+function getpaid_invoice_header($invoice) {
35
+    if (!empty($invoice)) {
36
+        wpinv_get_template('invoice/header.php', compact('invoice'));
37 37
     }
38 38
 }
39
-add_action( 'getpaid_invoice_header', 'getpaid_invoice_header', 10 );
39
+add_action('getpaid_invoice_header', 'getpaid_invoice_header', 10);
40 40
 
41 41
 /**
42 42
  * Displays actions on the left side of the header.
43 43
  */
44
-function getpaid_invoice_header_left_actions( $invoice ) {
45
-    if ( ! empty( $invoice ) ) {
46
-        wpinv_get_template( 'invoice/header-left-actions.php', compact( 'invoice' ) );
44
+function getpaid_invoice_header_left_actions($invoice) {
45
+    if (!empty($invoice)) {
46
+        wpinv_get_template('invoice/header-left-actions.php', compact('invoice'));
47 47
     }
48 48
 }
49
-add_action( 'getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10 );
49
+add_action('getpaid_invoice_header_left', 'getpaid_invoice_header_left_actions', 10);
50 50
 
51 51
 /**
52 52
  * Displays actions on the right side of the invoice top bar.
53 53
  */
54
-function getpaid_invoice_header_right_actions( $invoice ) {
55
-    if ( ! empty( $invoice ) ) {
56
-        wpinv_get_template( 'invoice/header-right-actions.php', compact( 'invoice' ) );
54
+function getpaid_invoice_header_right_actions($invoice) {
55
+    if (!empty($invoice)) {
56
+        wpinv_get_template('invoice/header-right-actions.php', compact('invoice'));
57 57
     }
58 58
 }
59
-add_action( 'getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10 );
59
+add_action('getpaid_invoice_header_right', 'getpaid_invoice_header_right_actions', 10);
60 60
 
61 61
 /**
62 62
  * Displays the invoice title, logo etc.
63 63
  */
64
-function getpaid_invoice_details_top( $invoice ) {
65
-    if ( ! empty( $invoice ) ) {
66
-        wpinv_get_template( 'invoice/details-top.php', compact( 'invoice' ) );
64
+function getpaid_invoice_details_top($invoice) {
65
+    if (!empty($invoice)) {
66
+        wpinv_get_template('invoice/details-top.php', compact('invoice'));
67 67
     }
68 68
 }
69
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_top', 10 );
69
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_top', 10);
70 70
 
71 71
 /**
72 72
  * Displays the company logo.
73 73
  */
74
-function getpaid_invoice_logo( $invoice ) {
75
-    if ( ! empty( $invoice ) ) {
76
-        wpinv_get_template( 'invoice/invoice-logo.php', compact( 'invoice' ) );
74
+function getpaid_invoice_logo($invoice) {
75
+    if (!empty($invoice)) {
76
+        wpinv_get_template('invoice/invoice-logo.php', compact('invoice'));
77 77
     }
78 78
 }
79
-add_action( 'getpaid_invoice_details_top_left', 'getpaid_invoice_logo' );
79
+add_action('getpaid_invoice_details_top_left', 'getpaid_invoice_logo');
80 80
 
81 81
 /**
82 82
  * Displays the type of invoice.
83 83
  */
84
-function getpaid_invoice_type( $invoice ) {
85
-    if ( ! empty( $invoice ) ) {
86
-        wpinv_get_template( 'invoice/invoice-type.php', compact( 'invoice' ) );
84
+function getpaid_invoice_type($invoice) {
85
+    if (!empty($invoice)) {
86
+        wpinv_get_template('invoice/invoice-type.php', compact('invoice'));
87 87
     }
88 88
 }
89
-add_action( 'getpaid_invoice_details_top_right', 'getpaid_invoice_type' );
89
+add_action('getpaid_invoice_details_top_right', 'getpaid_invoice_type');
90 90
 
91 91
 /**
92 92
  * Displays the invoice details.
93 93
  */
94
-function getpaid_invoice_details_main( $invoice ) {
95
-    if ( ! empty( $invoice ) ) {
96
-        wpinv_get_template( 'invoice/details.php', compact( 'invoice' ) );
94
+function getpaid_invoice_details_main($invoice) {
95
+    if (!empty($invoice)) {
96
+        wpinv_get_template('invoice/details.php', compact('invoice'));
97 97
     }
98 98
 }
99
-add_action( 'getpaid_invoice_details', 'getpaid_invoice_details_main', 50 );
99
+add_action('getpaid_invoice_details', 'getpaid_invoice_details_main', 50);
100 100
 
101 101
 /**
102 102
  * Returns a path to the templates directory.
@@ -125,8 +125,8 @@  discard block
 block discarded – undo
125 125
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
126 126
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
127 127
  */
128
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
129
-    getpaid_template()->display_template( $template_name, $args, $template_path, $default_path );
128
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
129
+    getpaid_template()->display_template($template_name, $args, $template_path, $default_path);
130 130
 }
131 131
 
132 132
 /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
  * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
140 140
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
141 141
  */
142
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
143
-	return getpaid_template()->get_template( $template_name, $args, $template_path, $default_path );
142
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
143
+	return getpaid_template()->get_template($template_name, $args, $template_path, $default_path);
144 144
 }
145 145
 
146 146
 /**
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
  * @return string
150 150
  */
151 151
 function wpinv_template_path() {
152
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
152
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
153 153
 }
154 154
 
155 155
 /**
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
  * @return string
159 159
  */
160 160
 function wpinv_get_theme_template_dir_name() {
161
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
161
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
162 162
 }
163 163
 
164 164
 /**
@@ -170,56 +170,56 @@  discard block
 block discarded – undo
170 170
  * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
171 171
  * @param string $default_path The root path to the default template. Defaults to invoicing/templates
172 172
  */
173
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
174
-    return getpaid_template()->locate_template( $template_name, $template_path, $default_path );
173
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
174
+    return getpaid_template()->locate_template($template_name, $template_path, $default_path);
175 175
 }
176 176
 
177
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
178
-	do_action( 'get_template_part_' . $slug, $slug, $name );
177
+function wpinv_get_template_part($slug, $name = null, $load = true) {
178
+	do_action('get_template_part_' . $slug, $slug, $name);
179 179
 
180 180
 	// Setup possible parts
181 181
 	$templates = array();
182
-	if ( isset( $name ) )
182
+	if (isset($name))
183 183
 		$templates[] = $slug . '-' . $name . '.php';
184 184
 	$templates[] = $slug . '.php';
185 185
 
186 186
 	// Allow template parts to be filtered
187
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
187
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
188 188
 
189 189
 	// Return the part that is found
190
-	return wpinv_locate_tmpl( $templates, $load, false );
190
+	return wpinv_locate_tmpl($templates, $load, false);
191 191
 }
192 192
 
193
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
193
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
194 194
 	// No file found yet
195 195
 	$located = false;
196 196
 
197 197
 	// Try to find a template file
198
-	foreach ( (array)$template_names as $template_name ) {
198
+	foreach ((array) $template_names as $template_name) {
199 199
 
200 200
 		// Continue if template is empty
201
-		if ( empty( $template_name ) )
201
+		if (empty($template_name))
202 202
 			continue;
203 203
 
204 204
 		// Trim off any slashes from the template name
205
-		$template_name = ltrim( $template_name, '/' );
205
+		$template_name = ltrim($template_name, '/');
206 206
 
207 207
 		// try locating this template file by looping through the template paths
208
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
208
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
209 209
 
210
-			if( file_exists( $template_path . $template_name ) ) {
210
+			if (file_exists($template_path . $template_name)) {
211 211
 				$located = $template_path . $template_name;
212 212
 				break;
213 213
 			}
214 214
 		}
215 215
 
216
-		if( !empty( $located ) ) {
216
+		if (!empty($located)) {
217 217
 			break;
218 218
 		}
219 219
 	}
220 220
 
221
-	if ( ( true == $load ) && ! empty( $located ) )
222
-		load_template( $located, $require_once );
221
+	if ((true == $load) && !empty($located))
222
+		load_template($located, $require_once);
223 223
 
224 224
 	return $located;
225 225
 }
@@ -228,127 +228,127 @@  discard block
 block discarded – undo
228 228
 	$template_dir = wpinv_get_theme_template_dir_name();
229 229
 
230 230
 	$file_paths = array(
231
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
232
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
231
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
232
+		10 => trailingslashit(get_template_directory()) . $template_dir,
233 233
 		100 => wpinv_get_templates_dir()
234 234
 	);
235 235
 
236
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
236
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
237 237
 
238 238
 	// sort the file paths based on priority
239
-	ksort( $file_paths, SORT_NUMERIC );
239
+	ksort($file_paths, SORT_NUMERIC);
240 240
 
241
-	return array_map( 'trailingslashit', $file_paths );
241
+	return array_map('trailingslashit', $file_paths);
242 242
 }
243 243
 
244 244
 function wpinv_checkout_meta_tags() {
245 245
 
246 246
 	$pages   = array();
247
-	$pages[] = wpinv_get_option( 'success_page' );
248
-	$pages[] = wpinv_get_option( 'failure_page' );
249
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
250
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
247
+	$pages[] = wpinv_get_option('success_page');
248
+	$pages[] = wpinv_get_option('failure_page');
249
+	$pages[] = wpinv_get_option('invoice_history_page');
250
+	$pages[] = wpinv_get_option('invoice_subscription_page');
251 251
 
252
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
252
+	if (!wpinv_is_checkout() && !is_page($pages)) {
253 253
 		return;
254 254
 	}
255 255
 
256 256
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
257 257
 }
258
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
258
+add_action('wp_head', 'wpinv_checkout_meta_tags');
259 259
 
260
-function wpinv_add_body_classes( $class ) {
261
-	$classes = (array)$class;
260
+function wpinv_add_body_classes($class) {
261
+	$classes = (array) $class;
262 262
 
263
-	if( wpinv_is_checkout() ) {
263
+	if (wpinv_is_checkout()) {
264 264
 		$classes[] = 'wpinv-checkout';
265 265
 		$classes[] = 'wpinv-page';
266 266
 	}
267 267
 
268
-	if( wpinv_is_success_page() ) {
268
+	if (wpinv_is_success_page()) {
269 269
 		$classes[] = 'wpinv-success';
270 270
 		$classes[] = 'wpinv-page';
271 271
 	}
272 272
 
273
-	if( wpinv_is_failed_transaction_page() ) {
273
+	if (wpinv_is_failed_transaction_page()) {
274 274
 		$classes[] = 'wpinv-failed-transaction';
275 275
 		$classes[] = 'wpinv-page';
276 276
 	}
277 277
 
278
-	if( wpinv_is_invoice_history_page() ) {
278
+	if (wpinv_is_invoice_history_page()) {
279 279
 		$classes[] = 'wpinv-history';
280 280
 		$classes[] = 'wpinv-page';
281 281
 	}
282 282
 
283
-	if( wpinv_is_subscriptions_history_page() ) {
283
+	if (wpinv_is_subscriptions_history_page()) {
284 284
 		$classes[] = 'wpinv-subscription';
285 285
 		$classes[] = 'wpinv-page';
286 286
 	}
287 287
 
288
-	if( wpinv_is_test_mode() ) {
288
+	if (wpinv_is_test_mode()) {
289 289
 		$classes[] = 'wpinv-test-mode';
290 290
 		$classes[] = 'wpinv-page';
291 291
 	}
292 292
 
293
-	return array_unique( $classes );
293
+	return array_unique($classes);
294 294
 }
295
-add_filter( 'body_class', 'wpinv_add_body_classes' );
295
+add_filter('body_class', 'wpinv_add_body_classes');
296 296
 
297
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
298
-    $current     = date( 'Y' );
299
-    $start_year  = $current - absint( $years_before );
300
-    $end_year    = $current + absint( $years_after );
301
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
297
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
298
+    $current     = date('Y');
299
+    $start_year  = $current - absint($years_before);
300
+    $end_year    = $current + absint($years_after);
301
+    $selected    = empty($selected) ? date('Y') : $selected;
302 302
     $options     = array();
303 303
 
304
-    while ( $start_year <= $end_year ) {
305
-        $options[ absint( $start_year ) ] = $start_year;
304
+    while ($start_year <= $end_year) {
305
+        $options[absint($start_year)] = $start_year;
306 306
         $start_year++;
307 307
     }
308 308
 
309
-    $output = wpinv_html_select( array(
309
+    $output = wpinv_html_select(array(
310 310
         'name'             => $name,
311 311
         'selected'         => $selected,
312 312
         'options'          => $options,
313 313
         'show_option_all'  => false,
314 314
         'show_option_none' => false
315
-    ) );
315
+    ));
316 316
 
317 317
     return $output;
318 318
 }
319 319
 
320
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
320
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
321 321
 
322 322
     $options = array(
323
-        '1'  => __( 'January', 'invoicing' ),
324
-        '2'  => __( 'February', 'invoicing' ),
325
-        '3'  => __( 'March', 'invoicing' ),
326
-        '4'  => __( 'April', 'invoicing' ),
327
-        '5'  => __( 'May', 'invoicing' ),
328
-        '6'  => __( 'June', 'invoicing' ),
329
-        '7'  => __( 'July', 'invoicing' ),
330
-        '8'  => __( 'August', 'invoicing' ),
331
-        '9'  => __( 'September', 'invoicing' ),
332
-        '10' => __( 'October', 'invoicing' ),
333
-        '11' => __( 'November', 'invoicing' ),
334
-        '12' => __( 'December', 'invoicing' ),
323
+        '1'  => __('January', 'invoicing'),
324
+        '2'  => __('February', 'invoicing'),
325
+        '3'  => __('March', 'invoicing'),
326
+        '4'  => __('April', 'invoicing'),
327
+        '5'  => __('May', 'invoicing'),
328
+        '6'  => __('June', 'invoicing'),
329
+        '7'  => __('July', 'invoicing'),
330
+        '8'  => __('August', 'invoicing'),
331
+        '9'  => __('September', 'invoicing'),
332
+        '10' => __('October', 'invoicing'),
333
+        '11' => __('November', 'invoicing'),
334
+        '12' => __('December', 'invoicing'),
335 335
     );
336 336
 
337 337
     // If no month is selected, default to the current month
338
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
338
+    $selected = empty($selected) ? date('n') : $selected;
339 339
 
340
-    $output = wpinv_html_select( array(
340
+    $output = wpinv_html_select(array(
341 341
         'name'             => $name,
342 342
         'selected'         => $selected,
343 343
         'options'          => $options,
344 344
         'show_option_all'  => false,
345 345
         'show_option_none' => false
346
-    ) );
346
+    ));
347 347
 
348 348
     return $output;
349 349
 }
350 350
 
351
-function wpinv_html_select( $args = array() ) {
351
+function wpinv_html_select($args = array()) {
352 352
     $defaults = array(
353 353
         'options'          => array(),
354 354
         'name'             => null,
@@ -357,8 +357,8 @@  discard block
 block discarded – undo
357 357
         'selected'         => 0,
358 358
         'placeholder'      => null,
359 359
         'multiple'         => false,
360
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
361
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
360
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
361
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
362 362
         'data'             => array(),
363 363
         'onchange'         => null,
364 364
         'required'         => false,
@@ -366,74 +366,74 @@  discard block
 block discarded – undo
366 366
         'readonly'         => false,
367 367
     );
368 368
 
369
-    $args = wp_parse_args( $args, $defaults );
369
+    $args = wp_parse_args($args, $defaults);
370 370
 
371 371
     $data_elements = '';
372
-    foreach ( $args['data'] as $key => $value ) {
373
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
372
+    foreach ($args['data'] as $key => $value) {
373
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
374 374
     }
375 375
 
376
-    if( $args['multiple'] ) {
376
+    if ($args['multiple']) {
377 377
         $multiple = ' MULTIPLE';
378 378
     } else {
379 379
         $multiple = '';
380 380
     }
381 381
 
382
-    if( $args['placeholder'] ) {
382
+    if ($args['placeholder']) {
383 383
         $placeholder = $args['placeholder'];
384 384
     } else {
385 385
         $placeholder = '';
386 386
     }
387 387
     
388 388
     $options = '';
389
-    if( !empty( $args['onchange'] ) ) {
390
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
389
+    if (!empty($args['onchange'])) {
390
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
391 391
     }
392 392
     
393
-    if( !empty( $args['required'] ) ) {
393
+    if (!empty($args['required'])) {
394 394
         $options .= ' required="required"';
395 395
     }
396 396
     
397
-    if( !empty( $args['disabled'] ) ) {
397
+    if (!empty($args['disabled'])) {
398 398
         $options .= ' disabled';
399 399
     }
400 400
     
401
-    if( !empty( $args['readonly'] ) ) {
401
+    if (!empty($args['readonly'])) {
402 402
         $options .= ' readonly';
403 403
     }
404 404
 
405
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
406
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
405
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
406
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
407 407
 
408
-    if ( $args['show_option_all'] ) {
409
-        if( $args['multiple'] ) {
410
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
408
+    if ($args['show_option_all']) {
409
+        if ($args['multiple']) {
410
+            $selected = selected(true, in_array(0, $args['selected']), false);
411 411
         } else {
412
-            $selected = selected( $args['selected'], 0, false );
412
+            $selected = selected($args['selected'], 0, false);
413 413
         }
414
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
414
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
415 415
     }
416 416
 
417
-    if ( !empty( $args['options'] ) ) {
417
+    if (!empty($args['options'])) {
418 418
 
419
-        if ( $args['show_option_none'] ) {
420
-            if( $args['multiple'] ) {
421
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
419
+        if ($args['show_option_none']) {
420
+            if ($args['multiple']) {
421
+                $selected = selected(true, in_array("", $args['selected']), false);
422 422
             } else {
423
-                $selected = selected( $args['selected'] === "", true, false );
423
+                $selected = selected($args['selected'] === "", true, false);
424 424
             }
425
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
425
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
426 426
         }
427 427
 
428
-        foreach( $args['options'] as $key => $option ) {
428
+        foreach ($args['options'] as $key => $option) {
429 429
 
430
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
431
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
430
+            if ($args['multiple'] && is_array($args['selected'])) {
431
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
432 432
             } else {
433
-                $selected = selected( $args['selected'], $key, false );
433
+                $selected = selected($args['selected'], $key, false);
434 434
             }
435 435
 
436
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
436
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
437 437
         }
438 438
     }
439 439
 
@@ -442,7 +442,7 @@  discard block
 block discarded – undo
442 442
     return $output;
443 443
 }
444 444
 
445
-function wpinv_item_dropdown( $args = array() ) {
445
+function wpinv_item_dropdown($args = array()) {
446 446
     $defaults = array(
447 447
         'name'              => 'wpi_item',
448 448
         'id'                => 'wpi_item',
@@ -450,14 +450,14 @@  discard block
 block discarded – undo
450 450
         'multiple'          => false,
451 451
         'selected'          => 0,
452 452
         'number'            => 100,
453
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
454
-        'data'              => array( 'search-type' => 'item' ),
453
+        'placeholder'       => __('Choose a item', 'invoicing'),
454
+        'data'              => array('search-type' => 'item'),
455 455
         'show_option_all'   => false,
456 456
         'show_option_none'  => false,
457 457
         'show_recurring'    => false,
458 458
     );
459 459
 
460
-    $args = wp_parse_args( $args, $defaults );
460
+    $args = wp_parse_args($args, $defaults);
461 461
 
462 462
     $item_args = array(
463 463
         'post_type'      => 'wpi_item',
@@ -466,44 +466,44 @@  discard block
 block discarded – undo
466 466
         'posts_per_page' => $args['number']
467 467
     );
468 468
 
469
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
469
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
470 470
 
471
-    $items      = get_posts( $item_args );
471
+    $items      = get_posts($item_args);
472 472
     $options    = array();
473
-    if ( $items ) {
474
-        foreach ( $items as $item ) {
475
-            $title = esc_html( $item->post_title );
473
+    if ($items) {
474
+        foreach ($items as $item) {
475
+            $title = esc_html($item->post_title);
476 476
             
477
-            if ( !empty( $args['show_recurring'] ) ) {
478
-                $title .= wpinv_get_item_suffix( $item->ID, false );
477
+            if (!empty($args['show_recurring'])) {
478
+                $title .= wpinv_get_item_suffix($item->ID, false);
479 479
             }
480 480
             
481
-            $options[ absint( $item->ID ) ] = $title;
481
+            $options[absint($item->ID)] = $title;
482 482
         }
483 483
     }
484 484
 
485 485
     // This ensures that any selected items are included in the drop down
486
-    if( is_array( $args['selected'] ) ) {
487
-        foreach( $args['selected'] as $item ) {
488
-            if( ! in_array( $item, $options ) ) {
489
-                $title = get_the_title( $item );
490
-                if ( !empty( $args['show_recurring'] ) ) {
491
-                    $title .= wpinv_get_item_suffix( $item, false );
486
+    if (is_array($args['selected'])) {
487
+        foreach ($args['selected'] as $item) {
488
+            if (!in_array($item, $options)) {
489
+                $title = get_the_title($item);
490
+                if (!empty($args['show_recurring'])) {
491
+                    $title .= wpinv_get_item_suffix($item, false);
492 492
                 }
493 493
                 $options[$item] = $title;
494 494
             }
495 495
         }
496
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
497
-        if ( ! in_array( $args['selected'], $options ) ) {
498
-            $title = get_the_title( $args['selected'] );
499
-            if ( !empty( $args['show_recurring'] ) ) {
500
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
496
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
497
+        if (!in_array($args['selected'], $options)) {
498
+            $title = get_the_title($args['selected']);
499
+            if (!empty($args['show_recurring'])) {
500
+                $title .= wpinv_get_item_suffix($args['selected'], false);
501 501
             }
502
-            $options[$args['selected']] = get_the_title( $args['selected'] );
502
+            $options[$args['selected']] = get_the_title($args['selected']);
503 503
         }
504 504
     }
505 505
 
506
-    $output = wpinv_html_select( array(
506
+    $output = wpinv_html_select(array(
507 507
         'name'             => $args['name'],
508 508
         'selected'         => $args['selected'],
509 509
         'id'               => $args['id'],
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
         'show_option_all'  => $args['show_option_all'],
515 515
         'show_option_none' => $args['show_option_none'],
516 516
         'data'             => $args['data'],
517
-    ) );
517
+    ));
518 518
 
519 519
     return $output;
520 520
 }
@@ -534,16 +534,16 @@  discard block
 block discarded – undo
534 534
     );
535 535
 
536 536
     $options = array();
537
-    if ( $items ) {
538
-        foreach ( $items as $item ) {
539
-            $options[ $item->ID ] = esc_html( $item->post_title ) . wpinv_get_item_suffix( $item->ID, false );
537
+    if ($items) {
538
+        foreach ($items as $item) {
539
+            $options[$item->ID] = esc_html($item->post_title) . wpinv_get_item_suffix($item->ID, false);
540 540
         }
541 541
     }
542 542
 
543 543
     return $options;
544 544
 }
545 545
 
546
-function wpinv_html_checkbox( $args = array() ) {
546
+function wpinv_html_checkbox($args = array()) {
547 547
     $defaults = array(
548 548
         'name'     => null,
549 549
         'current'  => null,
@@ -554,17 +554,17 @@  discard block
 block discarded – undo
554 554
         )
555 555
     );
556 556
 
557
-    $args = wp_parse_args( $args, $defaults );
557
+    $args = wp_parse_args($args, $defaults);
558 558
 
559
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
559
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
560 560
     $options = '';
561
-    if ( ! empty( $args['options']['disabled'] ) ) {
561
+    if (!empty($args['options']['disabled'])) {
562 562
         $options .= ' disabled="disabled"';
563
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
563
+    } elseif (!empty($args['options']['readonly'])) {
564 564
         $options .= ' readonly';
565 565
     }
566 566
 
567
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
567
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
568 568
 
569 569
     return $output;
570 570
 }
@@ -572,9 +572,9 @@  discard block
 block discarded – undo
572 572
 /**
573 573
  * Displays a hidden field.
574 574
  */
575
-function getpaid_hidden_field( $name, $value ) {
576
-    $name  = sanitize_text_field( $name );
577
-    $value = esc_attr( $value );
575
+function getpaid_hidden_field($name, $value) {
576
+    $name  = sanitize_text_field($name);
577
+    $value = esc_attr($value);
578 578
 
579 579
     echo "<input type='hidden' name='$name' value='$value' />";
580 580
 }
@@ -582,31 +582,31 @@  discard block
 block discarded – undo
582 582
 /**
583 583
  * Displays a submit field.
584 584
  */
585
-function getpaid_submit_field( $value, $name = 'submit', $class = 'btn-primary' ) {
586
-    $name  = sanitize_text_field( $name );
587
-    $value = esc_attr( $value );
588
-    $class = esc_attr( $class );
585
+function getpaid_submit_field($value, $name = 'submit', $class = 'btn-primary') {
586
+    $name  = sanitize_text_field($name);
587
+    $value = esc_attr($value);
588
+    $class = esc_attr($class);
589 589
 
590 590
     echo "<input type='submit' name='$name' value='$value' class='btn $class' />";
591 591
 }
592 592
 
593
-function wpinv_html_text( $args = array() ) {
593
+function wpinv_html_text($args = array()) {
594 594
     // Backwards compatibility
595
-    if ( func_num_args() > 1 ) {
595
+    if (func_num_args() > 1) {
596 596
         $args = func_get_args();
597 597
 
598 598
         $name  = $args[0];
599
-        $value = isset( $args[1] ) ? $args[1] : '';
600
-        $label = isset( $args[2] ) ? $args[2] : '';
601
-        $desc  = isset( $args[3] ) ? $args[3] : '';
599
+        $value = isset($args[1]) ? $args[1] : '';
600
+        $label = isset($args[2]) ? $args[2] : '';
601
+        $desc  = isset($args[3]) ? $args[3] : '';
602 602
     }
603 603
 
604 604
     $defaults = array(
605 605
         'id'           => '',
606
-        'name'         => isset( $name )  ? $name  : 'text',
607
-        'value'        => isset( $value ) ? $value : null,
608
-        'label'        => isset( $label ) ? $label : null,
609
-        'desc'         => isset( $desc )  ? $desc  : null,
606
+        'name'         => isset($name) ? $name : 'text',
607
+        'value'        => isset($value) ? $value : null,
608
+        'label'        => isset($label) ? $label : null,
609
+        'desc'         => isset($desc) ? $desc : null,
610 610
         'placeholder'  => '',
611 611
         'class'        => 'regular-text',
612 612
         'disabled'     => false,
@@ -616,41 +616,41 @@  discard block
 block discarded – undo
616 616
         'data'         => false
617 617
     );
618 618
 
619
-    $args = wp_parse_args( $args, $defaults );
619
+    $args = wp_parse_args($args, $defaults);
620 620
 
621
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
621
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
622 622
     $options = '';
623
-    if( $args['required'] ) {
623
+    if ($args['required']) {
624 624
         $options .= ' required="required"';
625 625
     }
626
-    if( $args['readonly'] ) {
626
+    if ($args['readonly']) {
627 627
         $options .= ' readonly';
628 628
     }
629
-    if( $args['readonly'] ) {
629
+    if ($args['readonly']) {
630 630
         $options .= ' readonly';
631 631
     }
632 632
 
633 633
     $data = '';
634
-    if ( !empty( $args['data'] ) ) {
635
-        foreach ( $args['data'] as $key => $value ) {
636
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
634
+    if (!empty($args['data'])) {
635
+        foreach ($args['data'] as $key => $value) {
636
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
637 637
         }
638 638
     }
639 639
 
640
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
641
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
642
-    if ( ! empty( $args['desc'] ) ) {
643
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
640
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
641
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
642
+    if (!empty($args['desc'])) {
643
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
644 644
     }
645 645
 
646
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
646
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
647 647
 
648 648
     $output .= '</span>';
649 649
 
650 650
     return $output;
651 651
 }
652 652
 
653
-function wpinv_html_textarea( $args = array() ) {
653
+function wpinv_html_textarea($args = array()) {
654 654
     $defaults = array(
655 655
         'name'        => 'textarea',
656 656
         'value'       => null,
@@ -661,31 +661,31 @@  discard block
 block discarded – undo
661 661
         'placeholder' => '',
662 662
     );
663 663
 
664
-    $args = wp_parse_args( $args, $defaults );
664
+    $args = wp_parse_args($args, $defaults);
665 665
 
666
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
666
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
667 667
     $disabled = '';
668
-    if( $args['disabled'] ) {
668
+    if ($args['disabled']) {
669 669
         $disabled = ' disabled="disabled"';
670 670
     }
671 671
 
672
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
673
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
674
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
672
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
673
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
674
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
675 675
 
676
-    if ( ! empty( $args['desc'] ) ) {
677
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
676
+    if (!empty($args['desc'])) {
677
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
678 678
     }
679 679
     $output .= '</span>';
680 680
 
681 681
     return $output;
682 682
 }
683 683
 
684
-function wpinv_html_ajax_user_search( $args = array() ) {
684
+function wpinv_html_ajax_user_search($args = array()) {
685 685
     $defaults = array(
686 686
         'name'        => 'user_id',
687 687
         'value'       => null,
688
-        'placeholder' => __( 'Enter username', 'invoicing' ),
688
+        'placeholder' => __('Enter username', 'invoicing'),
689 689
         'label'       => null,
690 690
         'desc'        => null,
691 691
         'class'       => '',
@@ -694,13 +694,13 @@  discard block
 block discarded – undo
694 694
         'data'        => false
695 695
     );
696 696
 
697
-    $args = wp_parse_args( $args, $defaults );
697
+    $args = wp_parse_args($args, $defaults);
698 698
 
699 699
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
700 700
 
701 701
     $output  = '<span class="wpinv_user_search_wrap">';
702
-        $output .= wpinv_html_text( $args );
703
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
702
+        $output .= wpinv_html_text($args);
703
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
704 704
     $output .= '</span>';
705 705
 
706 706
     return $output;
@@ -711,20 +711,20 @@  discard block
 block discarded – undo
711 711
  * 
712 712
  * @param string $template the template that is currently being used.
713 713
  */
714
-function wpinv_template( $template ) {
714
+function wpinv_template($template) {
715 715
     global $post;
716 716
 
717
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
717
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
718 718
 
719 719
         // If the user can view this invoice, display it.
720
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
720
+        if (wpinv_user_can_view_invoice($post->ID)) {
721 721
 
722
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
722
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
723 723
 
724 724
         // Else display an error message.
725 725
         } else {
726 726
 
727
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
727
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
728 728
 
729 729
         }
730 730
 
@@ -732,24 +732,24 @@  discard block
 block discarded – undo
732 732
 
733 733
     return $template;
734 734
 }
735
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
735
+add_filter('template_include', 'wpinv_template', 10, 1);
736 736
 
737 737
 function wpinv_get_business_address() {
738 738
     $business_address   = wpinv_store_address();
739
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
739
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
740 740
     
741 741
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
742 742
     
743
-    return apply_filters( 'wpinv_get_business_address', $business_address );
743
+    return apply_filters('wpinv_get_business_address', $business_address);
744 744
 }
745 745
 
746 746
 /**
747 747
  * Displays the company address.
748 748
  */
749 749
 function wpinv_display_from_address() {
750
-    wpinv_get_template( 'invoice/company-address.php' );
750
+    wpinv_get_template('invoice/company-address.php');
751 751
 }
752
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
752
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
753 753
 
754 754
 /**
755 755
  * Generates a watermark text for an invoice.
@@ -757,9 +757,9 @@  discard block
 block discarded – undo
757 757
  * @param WPInv_Invoice $invoice
758 758
  * @return string
759 759
  */
760
-function wpinv_watermark( $invoice ) {
761
-    $watermark = wpinv_get_watermark( $invoice );
762
-    return apply_filters( 'wpinv_get_watermark', $watermark, $invoice );
760
+function wpinv_watermark($invoice) {
761
+    $watermark = wpinv_get_watermark($invoice);
762
+    return apply_filters('wpinv_get_watermark', $watermark, $invoice);
763 763
 }
764 764
 
765 765
 /**
@@ -768,37 +768,37 @@  discard block
 block discarded – undo
768 768
  * @param WPInv_Invoice $invoice
769 769
  * @return string
770 770
  */
771
-function wpinv_get_watermark( $invoice ) {
771
+function wpinv_get_watermark($invoice) {
772 772
     return $invoice->get_status_nicename();
773 773
 }
774 774
 
775 775
 /**
776 776
  * @deprecated
777 777
  */
778
-function wpinv_display_invoice_details( $invoice ) {
779
-    return getpaid_invoice_meta( $invoice );
778
+function wpinv_display_invoice_details($invoice) {
779
+    return getpaid_invoice_meta($invoice);
780 780
 }
781 781
 
782 782
 /**
783 783
  * Displays invoice meta.
784 784
  */
785
-function getpaid_invoice_meta( $invoice ) {
785
+function getpaid_invoice_meta($invoice) {
786 786
 
787
-    $invoice = new WPInv_Invoice( $invoice );
787
+    $invoice = new WPInv_Invoice($invoice);
788 788
 
789 789
     // Ensure that we have an invoice.
790
-    if ( 0 == $invoice->get_id() ) {
790
+    if (0 == $invoice->get_id()) {
791 791
         return;
792 792
     }
793 793
 
794 794
     // Get the invoice meta.
795
-    $meta = getpaid_get_invoice_meta( $invoice );
795
+    $meta = getpaid_get_invoice_meta($invoice);
796 796
 
797 797
     // Display the meta.
798
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
798
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
799 799
 
800 800
 }
801
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
801
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
802 802
 
803 803
 /**
804 804
  * Retrieves the address markup to use on Invoices.
@@ -810,29 +810,29 @@  discard block
 block discarded – undo
810 810
  * @param  string $separator How to separate address lines.
811 811
  * @return string
812 812
  */
813
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
813
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
814 814
 
815 815
     // Retrieve the address markup...
816
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
817
-    $format = wpinv_get_full_address_format( $country );
816
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
817
+    $format = wpinv_get_full_address_format($country);
818 818
 
819 819
     // ... and the replacements.
820
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
820
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
821 821
 
822
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
822
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
823 823
     
824 824
 	// Remove unavailable tags.
825
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
825
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
826 826
 
827 827
     // Clean up white space.
828
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
829
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
828
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
829
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
830 830
     
831 831
     // Break newlines apart and remove empty lines/trim commas and white space.
832
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
832
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
833 833
 
834 834
     // Add html breaks.
835
-	$formatted_address = implode( $separator, $formatted_address );
835
+	$formatted_address = implode($separator, $formatted_address);
836 836
 
837 837
 	// We're done!
838 838
 	return $formatted_address;
@@ -844,88 +844,88 @@  discard block
 block discarded – undo
844 844
  * 
845 845
  * @param WPInv_Invoice $invoice
846 846
  */
847
-function wpinv_display_to_address( $invoice = 0 ) {
848
-    if ( ! empty( $invoice ) ) {
849
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
847
+function wpinv_display_to_address($invoice = 0) {
848
+    if (!empty($invoice)) {
849
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
850 850
     }
851 851
 }
852
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
852
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
853 853
 
854 854
 
855 855
 /**
856 856
  * Displays invoice line items.
857 857
  */
858
-function wpinv_display_line_items( $invoice_id = 0 ) {
858
+function wpinv_display_line_items($invoice_id = 0) {
859 859
 
860 860
     // Prepare the invoice.
861
-    $invoice = new WPInv_Invoice( $invoice_id );
861
+    $invoice = new WPInv_Invoice($invoice_id);
862 862
 
863 863
     // Abort if there is no invoice.
864
-    if ( 0 == $invoice->get_id() ) {
864
+    if (0 == $invoice->get_id()) {
865 865
         return;
866 866
     }
867 867
 
868 868
     // Line item columns.
869
-    $columns = getpaid_invoice_item_columns( $invoice );
870
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
869
+    $columns = getpaid_invoice_item_columns($invoice);
870
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
871 871
 
872
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
872
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
873 873
 }
874
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
874
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
875 875
 
876 876
 /**
877 877
  * Displays invoice notices on invoices.
878 878
  */
879 879
 function wpinv_display_invoice_notice() {
880 880
 
881
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
882
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
881
+    $label  = wpinv_get_option('vat_invoice_notice_label');
882
+    $notice = wpinv_get_option('vat_invoice_notice');
883 883
 
884
-    if ( empty( $label ) && empty( $notice ) ) {
884
+    if (empty($label) && empty($notice)) {
885 885
         return;
886 886
     }
887 887
 
888 888
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
889 889
 
890
-    if ( ! empty( $label ) ) {
891
-        $label = sanitize_text_field( $label );
890
+    if (!empty($label)) {
891
+        $label = sanitize_text_field($label);
892 892
         echo "<h5>$label</h5>";
893 893
     }
894 894
 
895
-    if ( ! empty( $notice ) ) {
896
-        echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>';
895
+    if (!empty($notice)) {
896
+        echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>';
897 897
     }
898 898
 
899 899
     echo '</div>';
900 900
 }
901
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
901
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
902 902
 
903 903
 /**
904 904
  * @param WPInv_Invoice $invoice
905 905
  */
906
-function wpinv_display_invoice_notes( $invoice ) {
906
+function wpinv_display_invoice_notes($invoice) {
907 907
 
908 908
     // Retrieve the notes.
909
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
909
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
910 910
 
911 911
     // Abort if we have non.
912
-    if ( empty( $notes ) ) {
912
+    if (empty($notes)) {
913 913
         return;
914 914
     }
915 915
 
916 916
     // Echo the note.
917 917
     echo '<div class="getpaid-invoice-notes-wrapper position-relative my-4">';
918
-    echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __( 'Notes', 'invoicing' ) .'</h2>';
918
+    echo '<h2 class="getpaid-invoice-notes-title mb-1 p-0 h4">' . __('Notes', 'invoicing') . '</h2>';
919 919
     echo '<ul class="getpaid-invoice-notes text-break overflow-auto list-unstyled p-0 m-0">';
920 920
 
921
-    foreach( $notes as $note ) {
922
-        wpinv_get_invoice_note_line_item( $note );
921
+    foreach ($notes as $note) {
922
+        wpinv_get_invoice_note_line_item($note);
923 923
     }
924 924
 
925 925
     echo '</ul>';
926 926
     echo '</div>';
927 927
 }
928
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
928
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
929 929
 
930 930
 /**
931 931
  * Loads scripts on our invoice templates.
@@ -933,31 +933,31 @@  discard block
 block discarded – undo
933 933
 function wpinv_display_style() {
934 934
 
935 935
     // Make sure that all scripts have been loaded.
936
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
937
-        do_action( 'wp_enqueue_scripts' );
936
+    if (!did_action('wp_enqueue_scripts')) {
937
+        do_action('wp_enqueue_scripts');
938 938
     }
939 939
 
940 940
     // Register the invoices style.
941
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
941
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
942 942
 
943 943
     // Load required styles
944
-    wp_print_styles( 'wpinv-single-style' );
945
-    wp_print_styles( 'ayecode-ui' );
944
+    wp_print_styles('wpinv-single-style');
945
+    wp_print_styles('ayecode-ui');
946 946
 
947 947
     // Maybe load custom css.
948
-    $custom_css = wpinv_get_option( 'template_custom_css' );
948
+    $custom_css = wpinv_get_option('template_custom_css');
949 949
 
950
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
951
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
952
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
950
+    if (isset($custom_css) && !empty($custom_css)) {
951
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
952
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
953 953
         echo '<style type="text/css">';
954 954
         echo $custom_css;
955 955
         echo '</style>';
956 956
     }
957 957
 
958 958
 }
959
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
960
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
959
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
960
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
961 961
 
962 962
 
963 963
 /**
@@ -969,41 +969,41 @@  discard block
 block discarded – undo
969 969
     // Retrieve the current invoice.
970 970
     $invoice_id = getpaid_get_current_invoice_id();
971 971
 
972
-    if ( empty( $invoice_id ) ) {
972
+    if (empty($invoice_id)) {
973 973
 
974 974
         return aui()->alert(
975 975
             array(
976 976
                 'type'    => 'warning',
977
-                'content' => __( 'Invalid invoice', 'invoicing' ),
977
+                'content' => __('Invalid invoice', 'invoicing'),
978 978
             )
979 979
         );
980 980
 
981 981
     }
982 982
 
983 983
     // Can the user view this invoice?
984
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
984
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
985 985
 
986 986
         return aui()->alert(
987 987
             array(
988 988
                 'type'    => 'warning',
989
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
989
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
990 990
             )
991 991
         );
992 992
 
993 993
     }
994 994
 
995 995
     // Ensure that it is not yet paid for.
996
-    $invoice = new WPInv_Invoice( $invoice_id );
996
+    $invoice = new WPInv_Invoice($invoice_id);
997 997
 
998 998
     // Maybe mark it as viewed.
999
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
999
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1000 1000
 
1001
-    if ( $invoice->is_paid() ) {
1001
+    if ($invoice->is_paid()) {
1002 1002
 
1003 1003
         return aui()->alert(
1004 1004
             array(
1005 1005
                 'type'    => 'success',
1006
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1006
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1007 1007
             )
1008 1008
         );
1009 1009
 
@@ -1013,15 +1013,15 @@  discard block
 block discarded – undo
1013 1013
     $wpi_checkout_id = $invoice_id;
1014 1014
 
1015 1015
     // Retrieve appropriate payment form.
1016
-    $payment_form = new GetPaid_Payment_Form( $invoice->get_meta( 'force_payment_form' ) );
1017
-    $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1016
+    $payment_form = new GetPaid_Payment_Form($invoice->get_meta('force_payment_form'));
1017
+    $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1018 1018
 
1019
-    if ( ! $payment_form->exists() ) {
1019
+    if (!$payment_form->exists()) {
1020 1020
 
1021 1021
         return aui()->alert(
1022 1022
             array(
1023 1023
                 'type'    => 'warning',
1024
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1024
+                'content' => __('Error loading the payment form', 'invoicing'),
1025 1025
             )
1026 1026
         );
1027 1027
 
@@ -1030,29 +1030,29 @@  discard block
 block discarded – undo
1030 1030
     // Set the invoice.
1031 1031
     $payment_form->invoice = $invoice;
1032 1032
 
1033
-    if ( ! $payment_form->is_default() ) {
1033
+    if (!$payment_form->is_default()) {
1034 1034
 
1035 1035
         $items    = array();
1036 1036
         $item_ids = array();
1037 1037
 
1038
-        foreach ( $invoice->get_items() as $item ) {
1039
-            if ( ! in_array( $item->get_id(), $item_ids ) ) {
1038
+        foreach ($invoice->get_items() as $item) {
1039
+            if (!in_array($item->get_id(), $item_ids)) {
1040 1040
                 $item_ids[] = $item->get_id();
1041 1041
                 $items[]    = $item;
1042 1042
             }
1043 1043
         }
1044 1044
 
1045
-        foreach ( $payment_form->get_items() as $item ) {
1046
-            if ( ! in_array( $item->get_id(), $item_ids ) ) {
1045
+        foreach ($payment_form->get_items() as $item) {
1046
+            if (!in_array($item->get_id(), $item_ids)) {
1047 1047
                 $item_ids[] = $item->get_id();
1048 1048
                 $items[]    = $item;
1049 1049
             }
1050 1050
         }
1051 1051
 
1052
-        $payment_form->set_items( $items );
1052
+        $payment_form->set_items($items);
1053 1053
 
1054 1054
     } else {
1055
-        $payment_form->set_items( $invoice->get_items() );
1055
+        $payment_form->set_items($invoice->get_items());
1056 1056
     }
1057 1057
 
1058 1058
     // Generate the html.
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
 }
1062 1062
 
1063 1063
 function wpinv_empty_cart_message() {
1064
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1064
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1065 1065
 }
1066 1066
 
1067 1067
 /**
@@ -1078,71 +1078,71 @@  discard block
 block discarded – undo
1078 1078
         )
1079 1079
     );
1080 1080
 }
1081
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1081
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1082 1082
 
1083 1083
 /**
1084 1084
  * Filters the receipt page.
1085 1085
  */
1086
-function wpinv_filter_success_page_content( $content ) {
1086
+function wpinv_filter_success_page_content($content) {
1087 1087
 
1088 1088
     // Ensure this is our page.
1089
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1089
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1090 1090
 
1091
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1092
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1091
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1092
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1093 1093
 
1094 1094
     }
1095 1095
 
1096 1096
     return $content;
1097 1097
 }
1098
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1098
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1099 1099
 
1100
-function wpinv_invoice_link( $invoice_id ) {
1101
-    $invoice = wpinv_get_invoice( $invoice_id );
1100
+function wpinv_invoice_link($invoice_id) {
1101
+    $invoice = wpinv_get_invoice($invoice_id);
1102 1102
 
1103
-    if ( empty( $invoice ) ) {
1103
+    if (empty($invoice)) {
1104 1104
         return NULL;
1105 1105
     }
1106 1106
 
1107
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1107
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1108 1108
 
1109
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1109
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1110 1110
 }
1111 1111
 
1112
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1113
-    if ( empty( $note ) ) {
1112
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1113
+    if (empty($note)) {
1114 1114
         return NULL;
1115 1115
     }
1116 1116
 
1117
-    if ( is_int( $note ) ) {
1118
-        $note = get_comment( $note );
1117
+    if (is_int($note)) {
1118
+        $note = get_comment($note);
1119 1119
     }
1120 1120
 
1121
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1121
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1122 1122
         return NULL;
1123 1123
     }
1124 1124
 
1125
-    $note_classes   = array( 'note' );
1126
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1125
+    $note_classes   = array('note');
1126
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1127 1127
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1128
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1129
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1128
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1129
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1130 1130
 
1131 1131
     ob_start();
1132 1132
     ?>
1133
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mb-2">
1133
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mb-2">
1134 1134
         <div class="note_content">
1135 1135
 
1136
-            <?php echo wptexturize( wp_kses_post( $note->comment_content ) ); ?>
1136
+            <?php echo wptexturize(wp_kses_post($note->comment_content)); ?>
1137 1137
 
1138
-            <?php if ( ! is_admin() ) : ?>
1138
+            <?php if (!is_admin()) : ?>
1139 1139
                 <em class="small form-text text-muted mt-0">
1140 1140
                     <?php
1141 1141
                         printf(
1142
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1142
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1143 1143
                             $note->comment_author,
1144
-                            getpaid_format_date_value( $note->comment_date ),
1145
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1144
+                            getpaid_format_date_value($note->comment_date),
1145
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1146 1146
                         );
1147 1147
                     ?>
1148 1148
                 </em>
@@ -1150,21 +1150,21 @@  discard block
 block discarded – undo
1150 1150
 
1151 1151
         </div>
1152 1152
 
1153
-        <?php if ( is_admin() ) : ?>
1153
+        <?php if (is_admin()) : ?>
1154 1154
 
1155 1155
             <p class="meta px-4 py-2">
1156
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>">
1156
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>">
1157 1157
                     <?php
1158 1158
                         printf(
1159
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1159
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1160 1160
                             $note->comment_author,
1161
-                            getpaid_format_date_value( $note->comment_date ),
1162
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1161
+                            getpaid_format_date_value($note->comment_date),
1162
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1163 1163
                         );
1164 1164
                     ?>
1165 1165
                 </abbr>&nbsp;&nbsp;
1166
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1167
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1166
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1167
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1168 1168
                 <?php } ?>
1169 1169
             </p>
1170 1170
 
@@ -1173,9 +1173,9 @@  discard block
 block discarded – undo
1173 1173
     </li>
1174 1174
     <?php
1175 1175
     $note_content = ob_get_clean();
1176
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1176
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1177 1177
 
1178
-    if ( $echo ) {
1178
+    if ($echo) {
1179 1179
         echo $note_content;
1180 1180
     } else {
1181 1181
         return $note_content;
@@ -1189,21 +1189,21 @@  discard block
 block discarded – undo
1189 1189
  * @return string
1190 1190
  */
1191 1191
 function wpinv_get_policy_text() {
1192
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1192
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1193 1193
 
1194
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
1194
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
1195 1195
 
1196
-    if(!$privacy_page_id){
1197
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1196
+    if (!$privacy_page_id) {
1197
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1198 1198
     }
1199 1199
 
1200
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
1200
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
1201 1201
 
1202 1202
     $find_replace = array(
1203 1203
         '[wpinv_privacy_policy]' => $privacy_link,
1204 1204
     );
1205 1205
 
1206
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1206
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1207 1207
 
1208 1208
     return wp_kses_post(wpautop($privacy_text));
1209 1209
 }
@@ -1211,21 +1211,21 @@  discard block
 block discarded – undo
1211 1211
 function wpinv_oxygen_fix_conflict() {
1212 1212
     global $ct_ignore_post_types;
1213 1213
 
1214
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1214
+    if (!is_array($ct_ignore_post_types)) {
1215 1215
         $ct_ignore_post_types = array();
1216 1216
     }
1217 1217
 
1218
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form' );
1218
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item', 'wpi_payment_form');
1219 1219
 
1220
-    foreach ( $post_types as $post_type ) {
1220
+    foreach ($post_types as $post_type) {
1221 1221
         $ct_ignore_post_types[] = $post_type;
1222 1222
 
1223 1223
         // Ignore post type
1224
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1224
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1225 1225
     }
1226 1226
 
1227
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1228
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1227
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1228
+    add_filter('template_include', 'wpinv_template', 999, 1);
1229 1229
 }
1230 1230
 
1231 1231
 /**
@@ -1233,10 +1233,10 @@  discard block
 block discarded – undo
1233 1233
  * 
1234 1234
  * @param GetPaid_Payment_Form $form
1235 1235
  */
1236
-function getpaid_display_payment_form( $form ) {
1236
+function getpaid_display_payment_form($form) {
1237 1237
 
1238
-    if ( is_numeric( $form ) ) {
1239
-        $form = new GetPaid_Payment_Form( $form );
1238
+    if (is_numeric($form)) {
1239
+        $form = new GetPaid_Payment_Form($form);
1240 1240
     }
1241 1241
 
1242 1242
     $form->display();
@@ -1246,55 +1246,55 @@  discard block
 block discarded – undo
1246 1246
 /**
1247 1247
  * Helper function to display a item payment form on the frontend.
1248 1248
  */
1249
-function getpaid_display_item_payment_form( $items ) {
1249
+function getpaid_display_item_payment_form($items) {
1250 1250
 
1251
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1252
-    $form->set_items( $items );
1251
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1252
+    $form->set_items($items);
1253 1253
 
1254
-    if ( 0 == count( $form->get_items() ) ) {
1254
+    if (0 == count($form->get_items())) {
1255 1255
         echo aui()->alert(
1256 1256
 			array(
1257 1257
 				'type'    => 'warning',
1258
-				'content' => __( 'No published items found', 'invoicing' ),
1258
+				'content' => __('No published items found', 'invoicing'),
1259 1259
 			)
1260 1260
         );
1261 1261
         return;
1262 1262
     }
1263 1263
 
1264
-    $form_items = esc_attr( getpaid_convert_items_to_string( $items ) );
1264
+    $form_items = esc_attr(getpaid_convert_items_to_string($items));
1265 1265
     $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />";
1266
-    $form->display( $form_items );
1266
+    $form->display($form_items);
1267 1267
 }
1268 1268
 
1269 1269
 /**
1270 1270
  * Helper function to display an invoice payment form on the frontend.
1271 1271
  */
1272
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1272
+function getpaid_display_invoice_payment_form($invoice_id) {
1273 1273
 
1274
-    $invoice = wpinv_get_invoice( $invoice_id );
1274
+    $invoice = wpinv_get_invoice($invoice_id);
1275 1275
 
1276
-    if ( empty( $invoice ) ) {
1276
+    if (empty($invoice)) {
1277 1277
 		echo aui()->alert(
1278 1278
 			array(
1279 1279
 				'type'    => 'warning',
1280
-				'content' => __( 'Invoice not found', 'invoicing' ),
1280
+				'content' => __('Invoice not found', 'invoicing'),
1281 1281
 			)
1282 1282
         );
1283 1283
         return;
1284 1284
     }
1285 1285
 
1286
-    if ( $invoice->is_paid() ) {
1286
+    if ($invoice->is_paid()) {
1287 1287
 		echo aui()->alert(
1288 1288
 			array(
1289 1289
 				'type'    => 'warning',
1290
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1290
+				'content' => __('Invoice has already been paid', 'invoicing'),
1291 1291
 			)
1292 1292
         );
1293 1293
         return;
1294 1294
     }
1295 1295
 
1296
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1297
-    $form->set_items( $invoice->get_items() );
1296
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1297
+    $form->set_items($invoice->get_items());
1298 1298
 
1299 1299
     $form->display();
1300 1300
 }
@@ -1302,23 +1302,23 @@  discard block
 block discarded – undo
1302 1302
 /**
1303 1303
  * Helper function to convert item string to array.
1304 1304
  */
1305
-function getpaid_convert_items_to_array( $items ) {
1306
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1305
+function getpaid_convert_items_to_array($items) {
1306
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1307 1307
     $prepared = array();
1308 1308
 
1309
-    foreach ( $items as $item ) {
1310
-        $data = array_map( 'trim', explode( '|', $item ) );
1309
+    foreach ($items as $item) {
1310
+        $data = array_map('trim', explode('|', $item));
1311 1311
 
1312
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1312
+        if (empty($data[0]) || !is_numeric($data[0])) {
1313 1313
             continue;
1314 1314
         }
1315 1315
 
1316 1316
         $quantity = 1;
1317
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1317
+        if (isset($data[1]) && is_numeric($data[1])) {
1318 1318
             $quantity = (float) $data[1];
1319 1319
         }
1320 1320
 
1321
-        $prepared[ $data[0] ] = $quantity;
1321
+        $prepared[$data[0]] = $quantity;
1322 1322
 
1323 1323
     }
1324 1324
 
@@ -1328,13 +1328,13 @@  discard block
 block discarded – undo
1328 1328
 /**
1329 1329
  * Helper function to convert item array to string.
1330 1330
  */
1331
-function getpaid_convert_items_to_string( $items ) {
1331
+function getpaid_convert_items_to_string($items) {
1332 1332
     $prepared = array();
1333 1333
 
1334
-    foreach ( $items as $item => $quantity ) {
1334
+    foreach ($items as $item => $quantity) {
1335 1335
         $prepared[] = "$item|$quantity";
1336 1336
     }
1337
-    return implode( ',', $prepared );
1337
+    return implode(',', $prepared);
1338 1338
 }
1339 1339
 
1340 1340
 /**
@@ -1342,21 +1342,21 @@  discard block
 block discarded – undo
1342 1342
  * 
1343 1343
  * Provide a label and one of $form, $items or $invoice.
1344 1344
  */
1345
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1346
-    $label = sanitize_text_field( $label );
1345
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1346
+    $label = sanitize_text_field($label);
1347 1347
 
1348
-    if ( ! empty( $form ) ) {
1349
-        $form  = esc_attr( $form );
1348
+    if (!empty($form)) {
1349
+        $form = esc_attr($form);
1350 1350
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; 
1351 1351
     }
1352 1352
 	
1353
-	if ( ! empty( $items ) ) {
1354
-        $items  = esc_attr( $items );
1353
+	if (!empty($items)) {
1354
+        $items = esc_attr($items);
1355 1355
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; 
1356 1356
     }
1357 1357
     
1358
-    if ( ! empty( $invoice ) ) {
1359
-        $invoice  = esc_attr( $invoice );
1358
+    if (!empty($invoice)) {
1359
+        $invoice = esc_attr($invoice);
1360 1360
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; 
1361 1361
     }
1362 1362
 
@@ -1367,17 +1367,17 @@  discard block
 block discarded – undo
1367 1367
  *
1368 1368
  * @param WPInv_Invoice $invoice
1369 1369
  */
1370
-function getpaid_the_invoice_description( $invoice ) {
1370
+function getpaid_the_invoice_description($invoice) {
1371 1371
     $description = $invoice->get_description();
1372 1372
 
1373
-    if ( empty( $description ) ) {
1373
+    if (empty($description)) {
1374 1374
         return;
1375 1375
     }
1376 1376
 
1377
-    $description = wp_kses_post( $description );
1377
+    $description = wp_kses_post($description);
1378 1378
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text' style='margin-bottom: 20px; border-left: 2px solid #2196F3;'><em>$description</em></small>";
1379 1379
 }
1380
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1380
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1381 1381
 
1382 1382
 /**
1383 1383
  * Render element on a form.
@@ -1385,60 +1385,60 @@  discard block
 block discarded – undo
1385 1385
  * @param array $element
1386 1386
  * @param GetPaid_Payment_Form $form
1387 1387
  */
1388
-function getpaid_payment_form_element( $element, $form ) {
1388
+function getpaid_payment_form_element($element, $form) {
1389 1389
 
1390 1390
     // Set up the args.
1391
-    $element_type    = trim( $element['type'] );
1391
+    $element_type    = trim($element['type']);
1392 1392
     $element['form'] = $form;
1393
-    extract( $element );
1393
+    extract($element);
1394 1394
 
1395 1395
     // Try to locate the appropriate template.
1396
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1396
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1397 1397
     
1398 1398
     // Abort if this is not our element.
1399
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1399
+    if (empty($located) || !file_exists($located)) {
1400 1400
         return;
1401 1401
     }
1402 1402
 
1403 1403
     // Generate the class and id of the element.
1404
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1405
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1404
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1405
+    $id            = isset($id) ? $id : uniqid('gp');
1406 1406
 
1407 1407
     // Echo the opening wrapper.
1408 1408
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1409 1409
 
1410 1410
     // Fires before displaying a given element type's content.
1411
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1411
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1412 1412
 
1413 1413
     // Include the template for the element.
1414 1414
     include $located;
1415 1415
 
1416 1416
     // Fires after displaying a given element type's content.
1417
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1417
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1418 1418
 
1419 1419
     // Echo the closing wrapper.
1420 1420
     echo '</div>';
1421 1421
 }
1422
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1422
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1423 1423
 
1424 1424
 /**
1425 1425
  * Render an element's edit page.
1426 1426
  *
1427 1427
  * @param WP_Post $post
1428 1428
  */
1429
-function getpaid_payment_form_edit_element_template( $post ) {
1429
+function getpaid_payment_form_edit_element_template($post) {
1430 1430
 
1431 1431
     // Retrieve all elements.
1432
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1432
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1433 1433
 
1434
-    foreach ( $all_elements as $element ) {
1434
+    foreach ($all_elements as $element) {
1435 1435
 
1436 1436
         // Try to locate the appropriate template.
1437
-        $element = sanitize_key( $element );
1438
-        $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" );
1437
+        $element = sanitize_key($element);
1438
+        $located = wpinv_locate_template("payment-forms-admin/edit/$element.php");
1439 1439
 
1440 1440
         // Continue if this is not our element.
1441
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1441
+        if (empty($located) || !file_exists($located)) {
1442 1442
             continue;
1443 1443
         }
1444 1444
 
@@ -1449,7 +1449,7 @@  discard block
 block discarded – undo
1449 1449
     }
1450 1450
 
1451 1451
 }
1452
-add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' );
1452
+add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template');
1453 1453
 
1454 1454
 /**
1455 1455
  * Render an element's preview.
@@ -1458,16 +1458,16 @@  discard block
 block discarded – undo
1458 1458
 function getpaid_payment_form_render_element_preview_template() {
1459 1459
 
1460 1460
     // Retrieve all elements.
1461
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1461
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1462 1462
 
1463
-    foreach ( $all_elements as $element ) {
1463
+    foreach ($all_elements as $element) {
1464 1464
 
1465 1465
         // Try to locate the appropriate template.
1466
-        $element = sanitize_key( $element );
1467
-        $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" );
1466
+        $element = sanitize_key($element);
1467
+        $located = wpinv_locate_template("payment-forms-admin/previews/$element.php");
1468 1468
 
1469 1469
         // Continue if this is not our element.
1470
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1470
+        if (empty($located) || !file_exists($located)) {
1471 1471
             continue;
1472 1472
         }
1473 1473
 
@@ -1478,7 +1478,7 @@  discard block
 block discarded – undo
1478 1478
     }
1479 1479
 
1480 1480
 }
1481
-add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' );
1481
+add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template');
1482 1482
 
1483 1483
 /**
1484 1484
  * Shows a list of gateways that support recurring payments.
@@ -1486,17 +1486,17 @@  discard block
 block discarded – undo
1486 1486
 function wpinv_get_recurring_gateways_text() {
1487 1487
     $gateways = array();
1488 1488
 
1489
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1490
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1491
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1489
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1490
+        if (wpinv_gateway_support_subscription($key)) {
1491
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1492 1492
         }
1493 1493
     }
1494 1494
 
1495
-    if ( empty( $gateways ) ) {
1496
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
1495
+    if (empty($gateways)) {
1496
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
1497 1497
     }
1498 1498
 
1499
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
1499
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
1500 1500
 
1501 1501
 }
1502 1502
 
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
  * @return GetPaid_Template
1507 1507
  */
1508 1508
 function getpaid_template() {
1509
-    return getpaid()->get( 'template' );
1509
+    return getpaid()->get('template');
1510 1510
 }
1511 1511
 
1512 1512
 /**
@@ -1515,8 +1515,8 @@  discard block
 block discarded – undo
1515 1515
  * @param array args
1516 1516
  * @return string
1517 1517
  */
1518
-function getpaid_paginate_links( $args ) {
1519
-    return str_replace( 'page-link dots', 'page-link text-dark', aui()->pagination( $args ) );
1518
+function getpaid_paginate_links($args) {
1519
+    return str_replace('page-link dots', 'page-link text-dark', aui()->pagination($args));
1520 1520
 }
1521 1521
 
1522 1522
 /**
@@ -1526,21 +1526,21 @@  discard block
 block discarded – undo
1526 1526
  * @param string state
1527 1527
  * @return string
1528 1528
  */
1529
-function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) {
1529
+function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') {
1530 1530
 
1531
-    $states = wpinv_get_country_states( $country );
1532
-    $uniqid = uniqid( '_' );
1531
+    $states = wpinv_get_country_states($country);
1532
+    $uniqid = uniqid('_');
1533 1533
 
1534
-    if ( ! empty( $states ) ) {
1534
+    if (!empty($states)) {
1535 1535
 
1536
-        return aui()->select( array(
1536
+        return aui()->select(array(
1537 1537
             'options'          => $states,
1538
-            'name'             => esc_attr( $field_name ),
1539
-            'id'               => sanitize_html_class( $field_name ) . $uniqid,
1540
-            'value'            => sanitize_text_field( $state ),
1538
+            'name'             => esc_attr($field_name),
1539
+            'id'               => sanitize_html_class($field_name) . $uniqid,
1540
+            'value'            => sanitize_text_field($state),
1541 1541
             'placeholder'      => $placeholder,
1542 1542
             'required'         => $required,
1543
-            'label'            => wp_kses_post( $label ),
1543
+            'label'            => wp_kses_post($label),
1544 1544
             'label_type'       => 'vertical',
1545 1545
             'help_text'        => $help_text,
1546 1546
             'class'            => 'getpaid-address-field wpinv_state',
@@ -1555,14 +1555,14 @@  discard block
 block discarded – undo
1555 1555
 
1556 1556
     return aui()->input(
1557 1557
         array(
1558
-            'name'        => esc_attr( $field_name ),
1559
-            'id'          => sanitize_html_class( $field_name ) . $uniqid,
1558
+            'name'        => esc_attr($field_name),
1559
+            'id'          => sanitize_html_class($field_name) . $uniqid,
1560 1560
             'placeholder' => $placeholder,
1561 1561
             'required'    => $required,
1562
-            'label'       => wp_kses_post( $label ),
1562
+            'label'       => wp_kses_post($label),
1563 1563
             'label_type'  => 'vertical',
1564 1564
             'help_text'   => $help_text,
1565
-            'value'       => sanitize_text_field( $state ),
1565
+            'value'       => sanitize_text_field($state),
1566 1566
             'class'       => 'getpaid-address-field wpinv_state',
1567 1567
             'wrap_class'  => "$wrapper_class getpaid-address-field-wrapper__state",
1568 1568
             'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state',
@@ -1580,16 +1580,16 @@  discard block
 block discarded – undo
1580 1580
  * @param array $element
1581 1581
  * @return string
1582 1582
  */
1583
-function getpaid_get_form_element_grid_class( $element ) {
1583
+function getpaid_get_form_element_grid_class($element) {
1584 1584
 
1585 1585
     $class = "col-12";
1586
-    $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width'];
1586
+    $width = empty($element['grid_width']) ? 'full' : $element['grid_width'];
1587 1587
 
1588
-    if ( $width == 'half' ) {
1588
+    if ($width == 'half') {
1589 1589
         $class = "col-12 col-md-6";
1590 1590
     }
1591 1591
 
1592
-    if ( $width == 'third' ) {
1592
+    if ($width == 'third') {
1593 1593
         $class = "col-12 col-md-4";
1594 1594
     }
1595 1595
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +793 added lines, -793 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,187 +10,187 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-    /**
127
-	 * Class constructor.
128
-	 *
129
-	 */
130
-	public function __construct() {
131
-
132
-		// Set the state and country to the default state and country.
133
-		$this->country = wpinv_default_billing_country();
134
-		$this->state   = wpinv_get_default_state();
135
-
136
-		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
139
-		}
140
-
141
-	}
142
-
143
-	/**
144
-	 * Loads submission data.
145
-	 *
146
-	 * @param array $data
147
-	 */
148
-	public function load_data( $data ) {
149
-
150
-		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
152
-
153
-		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
-
156
-		// Cache it...
157
-		$this->data = $data;
158
-
159
-		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
161
-
162
-		// Finally, process the submission.
163
-		try {
164
-
165
-			// Each process is passed an instance of the class (with reference)
166
-			// and should throw an Exception whenever it encounters one.
167
-			$processors = apply_filters(
168
-				'getpaid_payment_form_submission_processors',
169
-				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_discount' ),
175
-					array( $this, 'process_taxes' ),
176
-				),
177
-				$this		
178
-			);
179
-
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
182
-			}
183
-
184
-		} catch ( Exception $e ) {
185
-			$this->last_error = $e->getMessage();
186
-		}
187
-
188
-		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
-
191
-	}
192
-
193
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * An array of fees for the submission.
93
+     *
94
+     * @var array
95
+     */
96
+    protected $fees = array();
97
+
98
+    /**
99
+     * An array of discounts for the submission.
100
+     *
101
+     * @var array
102
+     */
103
+    protected $discounts = array();
104
+
105
+    /**
106
+     * An array of taxes for the submission.
107
+     *
108
+     * @var array
109
+     */
110
+    protected $taxes = array();
111
+
112
+    /**
113
+     * An array of items for the submission.
114
+     *
115
+     * @var GetPaid_Form_Item[]
116
+     */
117
+    protected $items = array();
118
+
119
+    /**
120
+     * The last error.
121
+     *
122
+     * @var string
123
+     */
124
+    public $last_error = null;
125
+
126
+    /**
127
+     * Class constructor.
128
+     *
129
+     */
130
+    public function __construct() {
131
+
132
+        // Set the state and country to the default state and country.
133
+        $this->country = wpinv_default_billing_country();
134
+        $this->state   = wpinv_get_default_state();
135
+
136
+        // Do we have an actual submission?
137
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
+            $this->load_data( $_POST );
139
+        }
140
+
141
+    }
142
+
143
+    /**
144
+     * Loads submission data.
145
+     *
146
+     * @param array $data
147
+     */
148
+    public function load_data( $data ) {
149
+
150
+        // Remove slashes from the submitted data...
151
+        $data       = wp_unslash( $data );
152
+
153
+        // Allow plugins to filter the data.
154
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
+
156
+        // Cache it...
157
+        $this->data = $data;
158
+
159
+        // Then generate a unique id from the data.
160
+        $this->id   = md5( wp_json_encode( $data ) );
161
+
162
+        // Finally, process the submission.
163
+        try {
164
+
165
+            // Each process is passed an instance of the class (with reference)
166
+            // and should throw an Exception whenever it encounters one.
167
+            $processors = apply_filters(
168
+                'getpaid_payment_form_submission_processors',
169
+                array(
170
+                    array( $this, 'process_payment_form' ),
171
+                    array( $this, 'process_invoice' ),
172
+                    array( $this, 'process_fees' ),
173
+                    array( $this, 'process_items' ),
174
+                    array( $this, 'process_discount' ),
175
+                    array( $this, 'process_taxes' ),
176
+                ),
177
+                $this		
178
+            );
179
+
180
+            foreach ( $processors as $processor ) {
181
+                call_user_func_array( $processor, array( &$this ) );
182
+            }
183
+
184
+        } catch ( Exception $e ) {
185
+            $this->last_error = $e->getMessage();
186
+        }
187
+
188
+        // Fired when we are done processing a submission.
189
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
+
191
+    }
192
+
193
+    /*
194 194
 	|--------------------------------------------------------------------------
195 195
 	| Payment Forms.
196 196
 	|--------------------------------------------------------------------------
@@ -199,39 +199,39 @@  discard block
 block discarded – undo
199 199
 	| submission has an active payment form etc.
200 200
     */
201 201
 
202
-	/**
203
-	 * Prepares the submission's payment form.
204
-	 *
205
-	 * @since 1.0.19
206
-	 */
207
-	public function process_payment_form() {
202
+    /**
203
+     * Prepares the submission's payment form.
204
+     *
205
+     * @since 1.0.19
206
+     */
207
+    public function process_payment_form() {
208 208
 
209
-		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
-		}
209
+        // Every submission needs an active payment form.
210
+        if ( empty( $this->data['form_id'] ) ) {
211
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
+        }
213 213
 
214
-		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
214
+        // Fetch the payment form.
215
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
-		}
217
+        if ( ! $this->payment_form->is_active() ) {
218
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
+        }
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
-	}
221
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
+    }
223 223
 
224 224
     /**
225
-	 * Returns the payment form.
226
-	 *
227
-	 * @since 1.0.19
228
-	 * @return GetPaid_Payment_Form
229
-	 */
230
-	public function get_payment_form() {
231
-		return $this->payment_form;
232
-	}
225
+     * Returns the payment form.
226
+     *
227
+     * @since 1.0.19
228
+     * @return GetPaid_Payment_Form
229
+     */
230
+    public function get_payment_form() {
231
+        return $this->payment_form;
232
+    }
233 233
 
234
-	/*
234
+    /*
235 235
 	|--------------------------------------------------------------------------
236 236
 	| Invoices.
237 237
 	|--------------------------------------------------------------------------
@@ -240,84 +240,84 @@  discard block
 block discarded – undo
240 240
 	| might be for an existing invoice.
241 241
 	*/
242 242
 
243
-	/**
244
-	 * Prepares the submission's invoice.
245
-	 *
246
-	 * @since 1.0.19
247
-	 */
248
-	public function process_invoice() {
243
+    /**
244
+     * Prepares the submission's invoice.
245
+     *
246
+     * @since 1.0.19
247
+     */
248
+    public function process_invoice() {
249 249
 
250
-		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
252
-			return;
253
-		}
250
+        // Abort if there is no invoice.
251
+        if ( empty( $this->data['invoice_id'] ) ) {
252
+            return;
253
+        }
254 254
 
255
-		// If the submission is for an existing invoice, ensure that it exists
256
-		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
255
+        // If the submission is for an existing invoice, ensure that it exists
256
+        // and that it is not paid for.
257
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
258 258
 
259 259
         if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
-		}
260
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
+        }
262 262
 
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
-		}
263
+        if ( $invoice->is_paid() ) {
264
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
+        }
266 266
 
267
-		$this->payment_form->invoice = $invoice;
268
-		if ( ! $this->payment_form->is_default() ) {
267
+        $this->payment_form->invoice = $invoice;
268
+        if ( ! $this->payment_form->is_default() ) {
269 269
 
270
-			$items    = array();
271
-			$item_ids = array();
270
+            $items    = array();
271
+            $item_ids = array();
272 272
 	
273
-			foreach ( $invoice->get_items() as $item ) {
274
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
275
-					$item_ids[] = $item->get_id();
276
-					$items[]    = $item;
277
-				}
278
-			}
273
+            foreach ( $invoice->get_items() as $item ) {
274
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
275
+                    $item_ids[] = $item->get_id();
276
+                    $items[]    = $item;
277
+                }
278
+            }
279 279
 	
280
-			foreach ( $this->payment_form->get_items() as $item ) {
281
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
282
-					$item_ids[] = $item->get_id();
283
-					$items[]    = $item;
284
-				}
285
-			}
280
+            foreach ( $this->payment_form->get_items() as $item ) {
281
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
282
+                    $item_ids[] = $item->get_id();
283
+                    $items[]    = $item;
284
+                }
285
+            }
286 286
 	
287
-			$this->payment_form->set_items( $items );
287
+            $this->payment_form->set_items( $items );
288 288
 	
289
-		} else {
290
-			$this->payment_form->set_items( $invoice->get_items() );
291
-		}
292
-
293
-		$this->country = $invoice->get_country();
294
-		$this->state   = $invoice->get_state();
295
-		$this->invoice = $invoice;
296
-
297
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
298
-	}
299
-
300
-	/**
301
-	 * Returns the associated invoice.
302
-	 *
303
-	 * @since 1.0.19
304
-	 * @return WPInv_Invoice
305
-	 */
306
-	public function get_invoice() {
307
-		return $this->invoice;
308
-	}
309
-
310
-	/**
311
-	 * Checks whether there is an invoice associated with this submission.
312
-	 *
313
-	 * @since 1.0.19
314
-	 * @return bool
315
-	 */
316
-	public function has_invoice() {
317
-		return ! empty( $this->invoice );
318
-	}
319
-
320
-	/*
289
+        } else {
290
+            $this->payment_form->set_items( $invoice->get_items() );
291
+        }
292
+
293
+        $this->country = $invoice->get_country();
294
+        $this->state   = $invoice->get_state();
295
+        $this->invoice = $invoice;
296
+
297
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
298
+    }
299
+
300
+    /**
301
+     * Returns the associated invoice.
302
+     *
303
+     * @since 1.0.19
304
+     * @return WPInv_Invoice
305
+     */
306
+    public function get_invoice() {
307
+        return $this->invoice;
308
+    }
309
+
310
+    /**
311
+     * Checks whether there is an invoice associated with this submission.
312
+     *
313
+     * @since 1.0.19
314
+     * @return bool
315
+     */
316
+    public function has_invoice() {
317
+        return ! empty( $this->invoice );
318
+    }
319
+
320
+    /*
321 321
 	|--------------------------------------------------------------------------
322 322
 	| Items.
323 323
 	|--------------------------------------------------------------------------
@@ -326,115 +326,115 @@  discard block
 block discarded – undo
326 326
 	| recurring item. But can have an unlimited number of non-recurring items.
327 327
 	*/
328 328
 
329
-	/**
330
-	 * Prepares the submission's items.
331
-	 *
332
-	 * @since 1.0.19
333
-	 */
334
-	public function process_items() {
335
-
336
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
337
-
338
-		foreach ( $processor->items as $item ) {
339
-			$this->add_item( $item );
340
-		}
341
-
342
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
343
-	}
344
-
345
-	/**
346
-	 * Adds an item to the submission.
347
-	 *
348
-	 * @since 1.0.19
349
-	 * @param GetPaid_Form_Item $item
350
-	 */
351
-	public function add_item( $item ) {
352
-
353
-		// Make sure that it is available for purchase.
354
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
355
-			return;
356
-		}
357
-
358
-		// Each submission can only contain one recurring item.
359
-		if ( $item->is_recurring() ) {
360
-
361
-			if ( $this->has_recurring != 0 ) {
362
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
363
-			}
364
-
365
-			$this->has_recurring = $item->get_id();
366
-
367
-		}
368
-
369
-		// Update the items and totals.
370
-		$this->items[ $item->get_id() ]         = $item;
371
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
372
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
373
-
374
-	}
375
-
376
-	/**
377
-	 * Removes a specific item.
378
-	 * 
379
-	 * You should not call this method after the discounts and taxes
380
-	 * have been calculated.
381
-	 *
382
-	 * @since 1.0.19
383
-	 */
384
-	public function remove_item( $item_id ) {
385
-
386
-		if ( isset( $this->items[ $item_id ] ) ) {
387
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
388
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
389
-
390
-			if ( $this->items[ $item_id ]->is_recurring() ) {
391
-				$this->has_recurring = 0;
392
-			}
393
-
394
-			unset( $this->items[ $item_id ] );
395
-		}
396
-
397
-	}
398
-
399
-	/**
400
-	 * Returns the subtotal.
401
-	 *
402
-	 * @since 1.0.19
403
-	 */
404
-	public function get_subtotal() {
405
-
406
-		if ( wpinv_prices_include_tax() ) {
407
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
408
-		}
409
-
410
-		return $this->totals['subtotal']['initial'];
411
-	}
412
-
413
-	/**
414
-	 * Returns the recurring subtotal.
415
-	 *
416
-	 * @since 1.0.19
417
-	 */
418
-	public function get_recurring_subtotal() {
419
-
420
-		if ( wpinv_prices_include_tax() ) {
421
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
422
-		}
423
-
424
-		return $this->totals['subtotal']['recurring'];
425
-	}
426
-
427
-	/**
428
-	 * Returns all items.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @return GetPaid_Form_Item[]
432
-	 */
433
-	public function get_items() {
434
-		return $this->items;
435
-	}
436
-
437
-	/*
329
+    /**
330
+     * Prepares the submission's items.
331
+     *
332
+     * @since 1.0.19
333
+     */
334
+    public function process_items() {
335
+
336
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
337
+
338
+        foreach ( $processor->items as $item ) {
339
+            $this->add_item( $item );
340
+        }
341
+
342
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
343
+    }
344
+
345
+    /**
346
+     * Adds an item to the submission.
347
+     *
348
+     * @since 1.0.19
349
+     * @param GetPaid_Form_Item $item
350
+     */
351
+    public function add_item( $item ) {
352
+
353
+        // Make sure that it is available for purchase.
354
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
355
+            return;
356
+        }
357
+
358
+        // Each submission can only contain one recurring item.
359
+        if ( $item->is_recurring() ) {
360
+
361
+            if ( $this->has_recurring != 0 ) {
362
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
363
+            }
364
+
365
+            $this->has_recurring = $item->get_id();
366
+
367
+        }
368
+
369
+        // Update the items and totals.
370
+        $this->items[ $item->get_id() ]         = $item;
371
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
372
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
373
+
374
+    }
375
+
376
+    /**
377
+     * Removes a specific item.
378
+     * 
379
+     * You should not call this method after the discounts and taxes
380
+     * have been calculated.
381
+     *
382
+     * @since 1.0.19
383
+     */
384
+    public function remove_item( $item_id ) {
385
+
386
+        if ( isset( $this->items[ $item_id ] ) ) {
387
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
388
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
389
+
390
+            if ( $this->items[ $item_id ]->is_recurring() ) {
391
+                $this->has_recurring = 0;
392
+            }
393
+
394
+            unset( $this->items[ $item_id ] );
395
+        }
396
+
397
+    }
398
+
399
+    /**
400
+     * Returns the subtotal.
401
+     *
402
+     * @since 1.0.19
403
+     */
404
+    public function get_subtotal() {
405
+
406
+        if ( wpinv_prices_include_tax() ) {
407
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
408
+        }
409
+
410
+        return $this->totals['subtotal']['initial'];
411
+    }
412
+
413
+    /**
414
+     * Returns the recurring subtotal.
415
+     *
416
+     * @since 1.0.19
417
+     */
418
+    public function get_recurring_subtotal() {
419
+
420
+        if ( wpinv_prices_include_tax() ) {
421
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
422
+        }
423
+
424
+        return $this->totals['subtotal']['recurring'];
425
+    }
426
+
427
+    /**
428
+     * Returns all items.
429
+     *
430
+     * @since 1.0.19
431
+     * @return GetPaid_Form_Item[]
432
+     */
433
+    public function get_items() {
434
+        return $this->items;
435
+    }
436
+
437
+    /*
438 438
 	|--------------------------------------------------------------------------
439 439
 	| Taxes
440 440
 	|--------------------------------------------------------------------------
@@ -443,128 +443,128 @@  discard block
 block discarded – undo
443 443
 	| or only one-time.
444 444
     */
445 445
 
446
-	/**
447
-	 * Prepares the submission's taxes.
448
-	 *
449
-	 * @since 1.0.19
450
-	 */
451
-	public function process_taxes() {
452
-
453
-		// Abort if we're not using taxes.
454
-		if ( ! $this->use_taxes() ) {
455
-			return;
456
-		}
457
-
458
-		// If a custom country && state has been passed in, use it to calculate taxes.
459
-		$country = $this->get_field( 'wpinv_country', 'billing' );
460
-		if ( ! empty( $country ) ) {
461
-			$this->country = $country;
462
-		}
463
-
464
-		$state = $this->get_field( 'wpinv_state', 'billing' );
465
-		if ( ! empty( $state ) ) {
466
-			$this->state = $state;
467
-		}
468
-
469
-		// Confirm if the provided country and the ip country are similar.
470
-		$address_confirmed = $this->get_field( 'confirm-address' );
471
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
472
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
473
-		}
474
-
475
-		// Abort if the country is not taxable.
476
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
477
-			return;
478
-		}
479
-
480
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
481
-
482
-		foreach ( $processor->taxes as $tax ) {
483
-			$this->add_tax( $tax );
484
-		}
485
-
486
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
487
-	}
488
-
489
-	/**
490
-	 * Adds a tax to the submission.
491
-	 *
492
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
493
-	 * @since 1.0.19
494
-	 */
495
-	public function add_tax( $tax ) {
496
-
497
-		if ( wpinv_round_tax_per_tax_rate() ) {
498
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
499
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
500
-		}
501
-
502
-		$this->taxes[ $tax['name'] ]         = $tax;
503
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
504
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
505
-
506
-	}
507
-
508
-	/**
509
-	 * Removes a specific tax.
510
-	 *
511
-	 * @since 1.0.19
512
-	 */
513
-	public function remove_tax( $tax_name ) {
514
-
515
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
516
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
517
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
518
-			unset( $this->taxes[ $tax_name ] );
519
-		}
520
-
521
-	}
522
-
523
-	/**
524
-	 * Whether or not we'll use taxes for the submission.
525
-	 *
526
-	 * @since 1.0.19
527
-	 */
528
-	public function use_taxes() {
529
-
530
-		$use_taxes = wpinv_use_taxes();
531
-
532
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
533
-			$use_taxes = false;
534
-		}
535
-
536
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
537
-
538
-	}
539
-
540
-	/**
541
-	 * Returns the tax.
542
-	 *
543
-	 * @since 1.0.19
544
-	 */
545
-	public function get_tax() {
546
-		return $this->totals['taxes']['initial'];
547
-	}
548
-
549
-	/**
550
-	 * Returns the recurring tax.
551
-	 *
552
-	 * @since 1.0.19
553
-	 */
554
-	public function get_recurring_tax() {
555
-		return $this->totals['taxes']['recurring'];
556
-	}
557
-
558
-	/**
559
-	 * Returns all taxes.
560
-	 *
561
-	 * @since 1.0.19
562
-	 */
563
-	public function get_taxes() {
564
-		return $this->taxes;
565
-	}
566
-
567
-	/*
446
+    /**
447
+     * Prepares the submission's taxes.
448
+     *
449
+     * @since 1.0.19
450
+     */
451
+    public function process_taxes() {
452
+
453
+        // Abort if we're not using taxes.
454
+        if ( ! $this->use_taxes() ) {
455
+            return;
456
+        }
457
+
458
+        // If a custom country && state has been passed in, use it to calculate taxes.
459
+        $country = $this->get_field( 'wpinv_country', 'billing' );
460
+        if ( ! empty( $country ) ) {
461
+            $this->country = $country;
462
+        }
463
+
464
+        $state = $this->get_field( 'wpinv_state', 'billing' );
465
+        if ( ! empty( $state ) ) {
466
+            $this->state = $state;
467
+        }
468
+
469
+        // Confirm if the provided country and the ip country are similar.
470
+        $address_confirmed = $this->get_field( 'confirm-address' );
471
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
472
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
473
+        }
474
+
475
+        // Abort if the country is not taxable.
476
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
477
+            return;
478
+        }
479
+
480
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
481
+
482
+        foreach ( $processor->taxes as $tax ) {
483
+            $this->add_tax( $tax );
484
+        }
485
+
486
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
487
+    }
488
+
489
+    /**
490
+     * Adds a tax to the submission.
491
+     *
492
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
493
+     * @since 1.0.19
494
+     */
495
+    public function add_tax( $tax ) {
496
+
497
+        if ( wpinv_round_tax_per_tax_rate() ) {
498
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
499
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
500
+        }
501
+
502
+        $this->taxes[ $tax['name'] ]         = $tax;
503
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
504
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
505
+
506
+    }
507
+
508
+    /**
509
+     * Removes a specific tax.
510
+     *
511
+     * @since 1.0.19
512
+     */
513
+    public function remove_tax( $tax_name ) {
514
+
515
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
516
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
517
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
518
+            unset( $this->taxes[ $tax_name ] );
519
+        }
520
+
521
+    }
522
+
523
+    /**
524
+     * Whether or not we'll use taxes for the submission.
525
+     *
526
+     * @since 1.0.19
527
+     */
528
+    public function use_taxes() {
529
+
530
+        $use_taxes = wpinv_use_taxes();
531
+
532
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
533
+            $use_taxes = false;
534
+        }
535
+
536
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
537
+
538
+    }
539
+
540
+    /**
541
+     * Returns the tax.
542
+     *
543
+     * @since 1.0.19
544
+     */
545
+    public function get_tax() {
546
+        return $this->totals['taxes']['initial'];
547
+    }
548
+
549
+    /**
550
+     * Returns the recurring tax.
551
+     *
552
+     * @since 1.0.19
553
+     */
554
+    public function get_recurring_tax() {
555
+        return $this->totals['taxes']['recurring'];
556
+    }
557
+
558
+    /**
559
+     * Returns all taxes.
560
+     *
561
+     * @since 1.0.19
562
+     */
563
+    public function get_taxes() {
564
+        return $this->taxes;
565
+    }
566
+
567
+    /*
568 568
 	|--------------------------------------------------------------------------
569 569
 	| Discounts
570 570
 	|--------------------------------------------------------------------------
@@ -573,99 +573,99 @@  discard block
 block discarded – undo
573 573
 	| or only one-time. They also do not have to come from a discount code.
574 574
     */
575 575
 
576
-	/**
577
-	 * Prepares the submission's discount.
578
-	 *
579
-	 * @since 1.0.19
580
-	 */
581
-	public function process_discount() {
582
-
583
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
584
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
585
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
586
-
587
-		foreach ( $processor->discounts as $discount ) {
588
-			$this->add_discount( $discount );
589
-		}
590
-
591
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
592
-	}
593
-
594
-	/**
595
-	 * Adds a discount to the submission.
596
-	 *
597
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
598
-	 * @since 1.0.19
599
-	 */
600
-	public function add_discount( $discount ) {
601
-		$this->discounts[ $discount['name'] ]   = $discount;
602
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
603
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
604
-	}
605
-
606
-	/**
607
-	 * Removes a discount from the submission.
608
-	 *
609
-	 * @since 1.0.19
610
-	 */
611
-	public function remove_discount( $name ) {
612
-
613
-		if ( isset( $this->discounts[ $name ] ) ) {
614
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
615
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
616
-			unset( $this->discounts[ $name ] );
617
-		}
618
-
619
-	}
620
-
621
-	/**
622
-	 * Checks whether there is a discount code associated with this submission.
623
-	 *
624
-	 * @since 1.0.19
625
-	 * @return bool
626
-	 */
627
-	public function has_discount_code() {
628
-		return ! empty( $this->discounts['discount_code'] );
629
-	}
630
-
631
-	/**
632
-	 * Returns the discount code.
633
-	 *
634
-	 * @since 1.0.19
635
-	 * @return string
636
-	 */
637
-	public function get_discount_code() {
638
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
639
-	}
640
-
641
-	/**
642
-	 * Returns the discount.
643
-	 *
644
-	 * @since 1.0.19
645
-	 */
646
-	public function get_discount() {
647
-		return $this->totals['discount']['initial'];
648
-	}
649
-
650
-	/**
651
-	 * Returns the recurring discount.
652
-	 *
653
-	 * @since 1.0.19
654
-	 */
655
-	public function get_recurring_discount() {
656
-		return $this->totals['discount']['recurring'];
657
-	}
658
-
659
-	/**
660
-	 * Returns all discounts.
661
-	 *
662
-	 * @since 1.0.19
663
-	 */
664
-	public function get_discounts() {
665
-		return $this->discounts;
666
-	}
667
-
668
-	/*
576
+    /**
577
+     * Prepares the submission's discount.
578
+     *
579
+     * @since 1.0.19
580
+     */
581
+    public function process_discount() {
582
+
583
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
584
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
585
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
586
+
587
+        foreach ( $processor->discounts as $discount ) {
588
+            $this->add_discount( $discount );
589
+        }
590
+
591
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
592
+    }
593
+
594
+    /**
595
+     * Adds a discount to the submission.
596
+     *
597
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
598
+     * @since 1.0.19
599
+     */
600
+    public function add_discount( $discount ) {
601
+        $this->discounts[ $discount['name'] ]   = $discount;
602
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
603
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
604
+    }
605
+
606
+    /**
607
+     * Removes a discount from the submission.
608
+     *
609
+     * @since 1.0.19
610
+     */
611
+    public function remove_discount( $name ) {
612
+
613
+        if ( isset( $this->discounts[ $name ] ) ) {
614
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
615
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
616
+            unset( $this->discounts[ $name ] );
617
+        }
618
+
619
+    }
620
+
621
+    /**
622
+     * Checks whether there is a discount code associated with this submission.
623
+     *
624
+     * @since 1.0.19
625
+     * @return bool
626
+     */
627
+    public function has_discount_code() {
628
+        return ! empty( $this->discounts['discount_code'] );
629
+    }
630
+
631
+    /**
632
+     * Returns the discount code.
633
+     *
634
+     * @since 1.0.19
635
+     * @return string
636
+     */
637
+    public function get_discount_code() {
638
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
639
+    }
640
+
641
+    /**
642
+     * Returns the discount.
643
+     *
644
+     * @since 1.0.19
645
+     */
646
+    public function get_discount() {
647
+        return $this->totals['discount']['initial'];
648
+    }
649
+
650
+    /**
651
+     * Returns the recurring discount.
652
+     *
653
+     * @since 1.0.19
654
+     */
655
+    public function get_recurring_discount() {
656
+        return $this->totals['discount']['recurring'];
657
+    }
658
+
659
+    /**
660
+     * Returns all discounts.
661
+     *
662
+     * @since 1.0.19
663
+     */
664
+    public function get_discounts() {
665
+        return $this->discounts;
666
+    }
667
+
668
+    /*
669 669
 	|--------------------------------------------------------------------------
670 670
 	| Fees
671 671
 	|--------------------------------------------------------------------------
@@ -675,89 +675,89 @@  discard block
 block discarded – undo
675 675
 	| fees.
676 676
     */
677 677
 
678
-	/**
679
-	 * Prepares the submission's fees.
680
-	 *
681
-	 * @since 1.0.19
682
-	 */
683
-	public function process_fees() {
684
-
685
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
686
-
687
-		foreach ( $fees_processor->fees as $fee ) {
688
-			$this->add_fee( $fee );
689
-		}
690
-
691
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
692
-	}
693
-
694
-	/**
695
-	 * Adds a fee to the submission.
696
-	 *
697
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
698
-	 * @since 1.0.19
699
-	 */
700
-	public function add_fee( $fee ) {
701
-
702
-		$this->fees[ $fee['name'] ]         = $fee;
703
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
704
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
705
-
706
-	}
707
-
708
-	/**
709
-	 * Removes a fee from the submission.
710
-	 *
711
-	 * @since 1.0.19
712
-	 */
713
-	public function remove_fee( $name ) {
714
-
715
-		if ( isset( $this->fees[ $name ] ) ) {
716
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
717
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
718
-			unset( $this->fees[ $name ] );
719
-		}
720
-
721
-	}
722
-
723
-	/**
724
-	 * Returns the fees.
725
-	 *
726
-	 * @since 1.0.19
727
-	 */
728
-	public function get_fee() {
729
-		return $this->totals['fees']['initial'];
730
-	}
731
-
732
-	/**
733
-	 * Returns the recurring fees.
734
-	 *
735
-	 * @since 1.0.19
736
-	 */
737
-	public function get_recurring_fee() {
738
-		return $this->totals['fees']['recurring'];
739
-	}
740
-
741
-	/**
742
-	 * Returns all fees.
743
-	 *
744
-	 * @since 1.0.19
745
-	 */
746
-	public function get_fees() {
747
-		return $this->fees;
748
-	}
749
-
750
-	/**
751
-	 * Checks if there are any fees for the form.
752
-	 *
753
-	 * @return bool
754
-	 * @since 1.0.19
755
-	 */
756
-	public function has_fees() {
757
-		return count( $this->fees ) !== 0;
758
-	}
759
-
760
-	/*
678
+    /**
679
+     * Prepares the submission's fees.
680
+     *
681
+     * @since 1.0.19
682
+     */
683
+    public function process_fees() {
684
+
685
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
686
+
687
+        foreach ( $fees_processor->fees as $fee ) {
688
+            $this->add_fee( $fee );
689
+        }
690
+
691
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
692
+    }
693
+
694
+    /**
695
+     * Adds a fee to the submission.
696
+     *
697
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
698
+     * @since 1.0.19
699
+     */
700
+    public function add_fee( $fee ) {
701
+
702
+        $this->fees[ $fee['name'] ]         = $fee;
703
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
704
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
705
+
706
+    }
707
+
708
+    /**
709
+     * Removes a fee from the submission.
710
+     *
711
+     * @since 1.0.19
712
+     */
713
+    public function remove_fee( $name ) {
714
+
715
+        if ( isset( $this->fees[ $name ] ) ) {
716
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
717
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
718
+            unset( $this->fees[ $name ] );
719
+        }
720
+
721
+    }
722
+
723
+    /**
724
+     * Returns the fees.
725
+     *
726
+     * @since 1.0.19
727
+     */
728
+    public function get_fee() {
729
+        return $this->totals['fees']['initial'];
730
+    }
731
+
732
+    /**
733
+     * Returns the recurring fees.
734
+     *
735
+     * @since 1.0.19
736
+     */
737
+    public function get_recurring_fee() {
738
+        return $this->totals['fees']['recurring'];
739
+    }
740
+
741
+    /**
742
+     * Returns all fees.
743
+     *
744
+     * @since 1.0.19
745
+     */
746
+    public function get_fees() {
747
+        return $this->fees;
748
+    }
749
+
750
+    /**
751
+     * Checks if there are any fees for the form.
752
+     *
753
+     * @return bool
754
+     * @since 1.0.19
755
+     */
756
+    public function has_fees() {
757
+        return count( $this->fees ) !== 0;
758
+    }
759
+
760
+    /*
761 761
 	|--------------------------------------------------------------------------
762 762
 	| MISC
763 763
 	|--------------------------------------------------------------------------
@@ -765,119 +765,119 @@  discard block
 block discarded – undo
765 765
 	| Extra submission functions.
766 766
     */
767 767
 
768
-	/**
769
-	 * Checks if this is the initial fetch.
770
-	 *
771
-	 * @return bool
772
-	 * @since 1.0.19
773
-	 */
774
-	public function is_initial_fetch() {
775
-		return empty( $this->data['initial_state'] );
776
-	}
777
-
778
-	/**
779
-	 * Returns the total amount to collect for this submission.
780
-	 *
781
-	 * @since 1.0.19
782
-	 */
783
-	public function get_total() {
784
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
785
-		return max( $total, 0 );
786
-	}
787
-
788
-	/**
789
-	 * Returns the recurring total amount to collect for this submission.
790
-	 *
791
-	 * @since 1.0.19
792
-	 */
793
-	public function get_recurring_total() {
794
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
795
-		return max( $total, 0 );
796
-	}
797
-
798
-	/**
799
-	 * Whether payment details should be collected for this submission.
800
-	 *
801
-	 * @since 1.0.19
802
-	 */
803
-	public function should_collect_payment_details() {
804
-		$initial   = $this->get_total();
805
-		$recurring = $this->get_recurring_total();
806
-
807
-		if ( $this->has_recurring == 0 ) {
808
-			$recurring = 0;
809
-		}
810
-
811
-		$collect = $initial > 0 || $recurring > 0;
812
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
813
-	}
814
-
815
-	/**
816
-	 * Returns the billing email of the user.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function get_billing_email() {
821
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
822
-	}
823
-
824
-	/**
825
-	 * Checks if the submitter has a billing email.
826
-	 *
827
-	 * @since 1.0.19
828
-	 */
829
-	public function has_billing_email() {
830
-		$billing_email = $this->get_billing_email();
831
-		return ! empty( $billing_email ) && is_email( $billing_email );
832
-	}
833
-
834
-	/**
835
-	 * Returns the appropriate currency for the submission.
836
-	 *
837
-	 * @since 1.0.19
838
-	 * @return string
839
-	 */
840
-	public function get_currency() {
841
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
842
-    }
843
-
844
-    /**
845
-	 * Returns the raw submission data.
846
-	 *
847
-	 * @since 1.0.19
848
-	 * @return array
849
-	 */
850
-	public function get_data() {
851
-		return $this->data;
852
-	}
853
-
854
-	/**
855
-	 * Returns a field from the submission data
856
-	 *
857
-	 * @param string $field
858
-	 * @since 1.0.19
859
-	 * @return mixed|null
860
-	 */
861
-	public function get_field( $field, $sub_array_key = null ) {
862
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
863
-	}
864
-
865
-	/**
866
-	 * Checks if a required field is set.
867
-	 *
868
-	 * @since 1.0.19
869
-	 */
870
-	public function is_required_field_set( $field ) {
871
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
872
-	}
873
-
874
-	/**
875
-	 * Formats an amount
876
-	 *
877
-	 * @since 1.0.19
878
-	 */
879
-	public function format_amount( $amount ) {
880
-		return wpinv_price( $amount, $this->get_currency() );
881
-	}
768
+    /**
769
+     * Checks if this is the initial fetch.
770
+     *
771
+     * @return bool
772
+     * @since 1.0.19
773
+     */
774
+    public function is_initial_fetch() {
775
+        return empty( $this->data['initial_state'] );
776
+    }
777
+
778
+    /**
779
+     * Returns the total amount to collect for this submission.
780
+     *
781
+     * @since 1.0.19
782
+     */
783
+    public function get_total() {
784
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
785
+        return max( $total, 0 );
786
+    }
787
+
788
+    /**
789
+     * Returns the recurring total amount to collect for this submission.
790
+     *
791
+     * @since 1.0.19
792
+     */
793
+    public function get_recurring_total() {
794
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
795
+        return max( $total, 0 );
796
+    }
797
+
798
+    /**
799
+     * Whether payment details should be collected for this submission.
800
+     *
801
+     * @since 1.0.19
802
+     */
803
+    public function should_collect_payment_details() {
804
+        $initial   = $this->get_total();
805
+        $recurring = $this->get_recurring_total();
806
+
807
+        if ( $this->has_recurring == 0 ) {
808
+            $recurring = 0;
809
+        }
810
+
811
+        $collect = $initial > 0 || $recurring > 0;
812
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
813
+    }
814
+
815
+    /**
816
+     * Returns the billing email of the user.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function get_billing_email() {
821
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
822
+    }
823
+
824
+    /**
825
+     * Checks if the submitter has a billing email.
826
+     *
827
+     * @since 1.0.19
828
+     */
829
+    public function has_billing_email() {
830
+        $billing_email = $this->get_billing_email();
831
+        return ! empty( $billing_email ) && is_email( $billing_email );
832
+    }
833
+
834
+    /**
835
+     * Returns the appropriate currency for the submission.
836
+     *
837
+     * @since 1.0.19
838
+     * @return string
839
+     */
840
+    public function get_currency() {
841
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
842
+    }
843
+
844
+    /**
845
+     * Returns the raw submission data.
846
+     *
847
+     * @since 1.0.19
848
+     * @return array
849
+     */
850
+    public function get_data() {
851
+        return $this->data;
852
+    }
853
+
854
+    /**
855
+     * Returns a field from the submission data
856
+     *
857
+     * @param string $field
858
+     * @since 1.0.19
859
+     * @return mixed|null
860
+     */
861
+    public function get_field( $field, $sub_array_key = null ) {
862
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
863
+    }
864
+
865
+    /**
866
+     * Checks if a required field is set.
867
+     *
868
+     * @since 1.0.19
869
+     */
870
+    public function is_required_field_set( $field ) {
871
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
872
+    }
873
+
874
+    /**
875
+     * Formats an amount
876
+     *
877
+     * @since 1.0.19
878
+     */
879
+    public function format_amount( $amount ) {
880
+        return wpinv_price( $amount, $this->get_currency() );
881
+    }
882 882
 
883 883
 }
Please login to merge, or discard this patch.
Spacing   +124 added lines, -124 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
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 		$this->state   = wpinv_get_default_state();
135 135
 
136 136
 		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
137
+		if (isset($_POST['getpaid_payment_form_submission'])) {
138
+			$this->load_data($_POST);
139 139
 		}
140 140
 
141 141
 	}
@@ -145,19 +145,19 @@  discard block
 block discarded – undo
145 145
 	 *
146 146
 	 * @param array $data
147 147
 	 */
148
-	public function load_data( $data ) {
148
+	public function load_data($data) {
149 149
 
150 150
 		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
151
+		$data       = wp_unslash($data);
152 152
 
153 153
 		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
154
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
155 155
 
156 156
 		// Cache it...
157 157
 		$this->data = $data;
158 158
 
159 159
 		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
160
+		$this->id   = md5(wp_json_encode($data));
161 161
 
162 162
 		// Finally, process the submission.
163 163
 		try {
@@ -167,26 +167,26 @@  discard block
 block discarded – undo
167 167
 			$processors = apply_filters(
168 168
 				'getpaid_payment_form_submission_processors',
169 169
 				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_discount' ),
175
-					array( $this, 'process_taxes' ),
170
+					array($this, 'process_payment_form'),
171
+					array($this, 'process_invoice'),
172
+					array($this, 'process_fees'),
173
+					array($this, 'process_items'),
174
+					array($this, 'process_discount'),
175
+					array($this, 'process_taxes'),
176 176
 				),
177 177
 				$this		
178 178
 			);
179 179
 
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
180
+			foreach ($processors as $processor) {
181
+				call_user_func_array($processor, array(&$this));
182 182
 			}
183 183
 
184
-		} catch ( Exception $e ) {
184
+		} catch (Exception $e) {
185 185
 			$this->last_error = $e->getMessage();
186 186
 		}
187 187
 
188 188
 		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
189
+		do_action_ref_array('getpaid_process_submission', array(&$this));
190 190
 
191 191
 	}
192 192
 
@@ -207,18 +207,18 @@  discard block
 block discarded – undo
207 207
 	public function process_payment_form() {
208 208
 
209 209
 		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
210
+		if (empty($this->data['form_id'])) {
211
+			throw new Exception(__('Missing payment form', 'invoicing'));
212 212
 		}
213 213
 
214 214
 		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
215
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
217
+		if (!$this->payment_form->is_active()) {
218
+			throw new Exception(__('Payment form not active', 'invoicing'));
219 219
 		}
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
221
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
222 222
 	}
223 223
 
224 224
     /**
@@ -248,53 +248,53 @@  discard block
 block discarded – undo
248 248
 	public function process_invoice() {
249 249
 
250 250
 		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
251
+		if (empty($this->data['invoice_id'])) {
252 252
 			return;
253 253
 		}
254 254
 
255 255
 		// If the submission is for an existing invoice, ensure that it exists
256 256
 		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
257
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
258 258
 
259
-        if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
259
+        if (empty($invoice)) {
260
+			throw new Exception(__('Invalid invoice', 'invoicing'));
261 261
 		}
262 262
 
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
263
+		if ($invoice->is_paid()) {
264
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
265 265
 		}
266 266
 
267 267
 		$this->payment_form->invoice = $invoice;
268
-		if ( ! $this->payment_form->is_default() ) {
268
+		if (!$this->payment_form->is_default()) {
269 269
 
270 270
 			$items    = array();
271 271
 			$item_ids = array();
272 272
 	
273
-			foreach ( $invoice->get_items() as $item ) {
274
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
273
+			foreach ($invoice->get_items() as $item) {
274
+				if (!in_array($item->get_id(), $item_ids)) {
275 275
 					$item_ids[] = $item->get_id();
276 276
 					$items[]    = $item;
277 277
 				}
278 278
 			}
279 279
 	
280
-			foreach ( $this->payment_form->get_items() as $item ) {
281
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
280
+			foreach ($this->payment_form->get_items() as $item) {
281
+				if (!in_array($item->get_id(), $item_ids)) {
282 282
 					$item_ids[] = $item->get_id();
283 283
 					$items[]    = $item;
284 284
 				}
285 285
 			}
286 286
 	
287
-			$this->payment_form->set_items( $items );
287
+			$this->payment_form->set_items($items);
288 288
 	
289 289
 		} else {
290
-			$this->payment_form->set_items( $invoice->get_items() );
290
+			$this->payment_form->set_items($invoice->get_items());
291 291
 		}
292 292
 
293 293
 		$this->country = $invoice->get_country();
294 294
 		$this->state   = $invoice->get_state();
295 295
 		$this->invoice = $invoice;
296 296
 
297
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
297
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
298 298
 	}
299 299
 
300 300
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 * @return bool
315 315
 	 */
316 316
 	public function has_invoice() {
317
-		return ! empty( $this->invoice );
317
+		return !empty($this->invoice);
318 318
 	}
319 319
 
320 320
 	/*
@@ -333,13 +333,13 @@  discard block
 block discarded – undo
333 333
 	 */
334 334
 	public function process_items() {
335 335
 
336
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
336
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
337 337
 
338
-		foreach ( $processor->items as $item ) {
339
-			$this->add_item( $item );
338
+		foreach ($processor->items as $item) {
339
+			$this->add_item($item);
340 340
 		}
341 341
 
342
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
342
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
343 343
 	}
344 344
 
345 345
 	/**
@@ -348,18 +348,18 @@  discard block
 block discarded – undo
348 348
 	 * @since 1.0.19
349 349
 	 * @param GetPaid_Form_Item $item
350 350
 	 */
351
-	public function add_item( $item ) {
351
+	public function add_item($item) {
352 352
 
353 353
 		// Make sure that it is available for purchase.
354
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
354
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
355 355
 			return;
356 356
 		}
357 357
 
358 358
 		// Each submission can only contain one recurring item.
359
-		if ( $item->is_recurring() ) {
359
+		if ($item->is_recurring()) {
360 360
 
361
-			if ( $this->has_recurring != 0 ) {
362
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
361
+			if ($this->has_recurring != 0) {
362
+				throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing'));
363 363
 			}
364 364
 
365 365
 			$this->has_recurring = $item->get_id();
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
 		}
368 368
 
369 369
 		// Update the items and totals.
370
-		$this->items[ $item->get_id() ]         = $item;
370
+		$this->items[$item->get_id()]         = $item;
371 371
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
372 372
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
373 373
 
@@ -381,17 +381,17 @@  discard block
 block discarded – undo
381 381
 	 *
382 382
 	 * @since 1.0.19
383 383
 	 */
384
-	public function remove_item( $item_id ) {
384
+	public function remove_item($item_id) {
385 385
 
386
-		if ( isset( $this->items[ $item_id ] ) ) {
387
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
388
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
386
+		if (isset($this->items[$item_id])) {
387
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
388
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
389 389
 
390
-			if ( $this->items[ $item_id ]->is_recurring() ) {
390
+			if ($this->items[$item_id]->is_recurring()) {
391 391
 				$this->has_recurring = 0;
392 392
 			}
393 393
 
394
-			unset( $this->items[ $item_id ] );
394
+			unset($this->items[$item_id]);
395 395
 		}
396 396
 
397 397
 	}
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
 	 */
404 404
 	public function get_subtotal() {
405 405
 
406
-		if ( wpinv_prices_include_tax() ) {
406
+		if (wpinv_prices_include_tax()) {
407 407
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
408 408
 		}
409 409
 
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 	 */
418 418
 	public function get_recurring_subtotal() {
419 419
 
420
-		if ( wpinv_prices_include_tax() ) {
420
+		if (wpinv_prices_include_tax()) {
421 421
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
422 422
 		}
423 423
 
@@ -451,39 +451,39 @@  discard block
 block discarded – undo
451 451
 	public function process_taxes() {
452 452
 
453 453
 		// Abort if we're not using taxes.
454
-		if ( ! $this->use_taxes() ) {
454
+		if (!$this->use_taxes()) {
455 455
 			return;
456 456
 		}
457 457
 
458 458
 		// If a custom country && state has been passed in, use it to calculate taxes.
459
-		$country = $this->get_field( 'wpinv_country', 'billing' );
460
-		if ( ! empty( $country ) ) {
459
+		$country = $this->get_field('wpinv_country', 'billing');
460
+		if (!empty($country)) {
461 461
 			$this->country = $country;
462 462
 		}
463 463
 
464
-		$state = $this->get_field( 'wpinv_state', 'billing' );
465
-		if ( ! empty( $state ) ) {
464
+		$state = $this->get_field('wpinv_state', 'billing');
465
+		if (!empty($state)) {
466 466
 			$this->state = $state;
467 467
 		}
468 468
 
469 469
 		// Confirm if the provided country and the ip country are similar.
470
-		$address_confirmed = $this->get_field( 'confirm-address' );
471
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
472
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
470
+		$address_confirmed = $this->get_field('confirm-address');
471
+		if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
472
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
473 473
 		}
474 474
 
475 475
 		// Abort if the country is not taxable.
476
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
476
+		if (!wpinv_is_country_taxable($this->country)) {
477 477
 			return;
478 478
 		}
479 479
 
480
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
480
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
481 481
 
482
-		foreach ( $processor->taxes as $tax ) {
483
-			$this->add_tax( $tax );
482
+		foreach ($processor->taxes as $tax) {
483
+			$this->add_tax($tax);
484 484
 		}
485 485
 
486
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
486
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
487 487
 	}
488 488
 
489 489
 	/**
@@ -492,16 +492,16 @@  discard block
 block discarded – undo
492 492
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
493 493
 	 * @since 1.0.19
494 494
 	 */
495
-	public function add_tax( $tax ) {
495
+	public function add_tax($tax) {
496 496
 
497
-		if ( wpinv_round_tax_per_tax_rate() ) {
498
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
499
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
497
+		if (wpinv_round_tax_per_tax_rate()) {
498
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
499
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
500 500
 		}
501 501
 
502
-		$this->taxes[ $tax['name'] ]         = $tax;
503
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
504
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
502
+		$this->taxes[$tax['name']]         = $tax;
503
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
504
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
505 505
 
506 506
 	}
507 507
 
@@ -510,12 +510,12 @@  discard block
 block discarded – undo
510 510
 	 *
511 511
 	 * @since 1.0.19
512 512
 	 */
513
-	public function remove_tax( $tax_name ) {
513
+	public function remove_tax($tax_name) {
514 514
 
515
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
516
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
517
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
518
-			unset( $this->taxes[ $tax_name ] );
515
+		if (isset($this->taxes[$tax_name])) {
516
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
517
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
518
+			unset($this->taxes[$tax_name]);
519 519
 		}
520 520
 
521 521
 	}
@@ -529,11 +529,11 @@  discard block
 block discarded – undo
529 529
 
530 530
 		$use_taxes = wpinv_use_taxes();
531 531
 
532
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
532
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
533 533
 			$use_taxes = false;
534 534
 		}
535 535
 
536
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
536
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
537 537
 
538 538
 	}
539 539
 
@@ -582,13 +582,13 @@  discard block
 block discarded – undo
582 582
 
583 583
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
584 584
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
585
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
585
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
586 586
 
587
-		foreach ( $processor->discounts as $discount ) {
588
-			$this->add_discount( $discount );
587
+		foreach ($processor->discounts as $discount) {
588
+			$this->add_discount($discount);
589 589
 		}
590 590
 
591
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
591
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
592 592
 	}
593 593
 
594 594
 	/**
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
598 598
 	 * @since 1.0.19
599 599
 	 */
600
-	public function add_discount( $discount ) {
601
-		$this->discounts[ $discount['name'] ]   = $discount;
602
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
603
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
600
+	public function add_discount($discount) {
601
+		$this->discounts[$discount['name']]   = $discount;
602
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
603
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
604 604
 	}
605 605
 
606 606
 	/**
@@ -608,12 +608,12 @@  discard block
 block discarded – undo
608 608
 	 *
609 609
 	 * @since 1.0.19
610 610
 	 */
611
-	public function remove_discount( $name ) {
611
+	public function remove_discount($name) {
612 612
 
613
-		if ( isset( $this->discounts[ $name ] ) ) {
614
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
615
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
616
-			unset( $this->discounts[ $name ] );
613
+		if (isset($this->discounts[$name])) {
614
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
615
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
616
+			unset($this->discounts[$name]);
617 617
 		}
618 618
 
619 619
 	}
@@ -625,7 +625,7 @@  discard block
 block discarded – undo
625 625
 	 * @return bool
626 626
 	 */
627 627
 	public function has_discount_code() {
628
-		return ! empty( $this->discounts['discount_code'] );
628
+		return !empty($this->discounts['discount_code']);
629 629
 	}
630 630
 
631 631
 	/**
@@ -682,13 +682,13 @@  discard block
 block discarded – undo
682 682
 	 */
683 683
 	public function process_fees() {
684 684
 
685
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
685
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
686 686
 
687
-		foreach ( $fees_processor->fees as $fee ) {
688
-			$this->add_fee( $fee );
687
+		foreach ($fees_processor->fees as $fee) {
688
+			$this->add_fee($fee);
689 689
 		}
690 690
 
691
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
691
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
692 692
 	}
693 693
 
694 694
 	/**
@@ -697,11 +697,11 @@  discard block
 block discarded – undo
697 697
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
698 698
 	 * @since 1.0.19
699 699
 	 */
700
-	public function add_fee( $fee ) {
700
+	public function add_fee($fee) {
701 701
 
702
-		$this->fees[ $fee['name'] ]         = $fee;
703
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
704
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
702
+		$this->fees[$fee['name']]         = $fee;
703
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
704
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
705 705
 
706 706
 	}
707 707
 
@@ -710,12 +710,12 @@  discard block
 block discarded – undo
710 710
 	 *
711 711
 	 * @since 1.0.19
712 712
 	 */
713
-	public function remove_fee( $name ) {
713
+	public function remove_fee($name) {
714 714
 
715
-		if ( isset( $this->fees[ $name ] ) ) {
716
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
717
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
718
-			unset( $this->fees[ $name ] );
715
+		if (isset($this->fees[$name])) {
716
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
717
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
718
+			unset($this->fees[$name]);
719 719
 		}
720 720
 
721 721
 	}
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 	 * @since 1.0.19
755 755
 	 */
756 756
 	public function has_fees() {
757
-		return count( $this->fees ) !== 0;
757
+		return count($this->fees) !== 0;
758 758
 	}
759 759
 
760 760
 	/*
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 	 * @since 1.0.19
773 773
 	 */
774 774
 	public function is_initial_fetch() {
775
-		return empty( $this->data['initial_state'] );
775
+		return empty($this->data['initial_state']);
776 776
 	}
777 777
 
778 778
 	/**
@@ -782,7 +782,7 @@  discard block
 block discarded – undo
782 782
 	 */
783 783
 	public function get_total() {
784 784
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
785
-		return max( $total, 0 );
785
+		return max($total, 0);
786 786
 	}
787 787
 
788 788
 	/**
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	 */
793 793
 	public function get_recurring_total() {
794 794
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
795
-		return max( $total, 0 );
795
+		return max($total, 0);
796 796
 	}
797 797
 
798 798
 	/**
@@ -804,12 +804,12 @@  discard block
 block discarded – undo
804 804
 		$initial   = $this->get_total();
805 805
 		$recurring = $this->get_recurring_total();
806 806
 
807
-		if ( $this->has_recurring == 0 ) {
807
+		if ($this->has_recurring == 0) {
808 808
 			$recurring = 0;
809 809
 		}
810 810
 
811 811
 		$collect = $initial > 0 || $recurring > 0;
812
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
812
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
813 813
 	}
814 814
 
815 815
 	/**
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	 * @since 1.0.19
819 819
 	 */
820 820
 	public function get_billing_email() {
821
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
821
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
822 822
 	}
823 823
 
824 824
 	/**
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 	 */
829 829
 	public function has_billing_email() {
830 830
 		$billing_email = $this->get_billing_email();
831
-		return ! empty( $billing_email ) && is_email( $billing_email );
831
+		return !empty($billing_email) && is_email($billing_email);
832 832
 	}
833 833
 
834 834
 	/**
@@ -858,8 +858,8 @@  discard block
 block discarded – undo
858 858
 	 * @since 1.0.19
859 859
 	 * @return mixed|null
860 860
 	 */
861
-	public function get_field( $field, $sub_array_key = null ) {
862
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
861
+	public function get_field($field, $sub_array_key = null) {
862
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
863 863
 	}
864 864
 
865 865
 	/**
@@ -867,8 +867,8 @@  discard block
 block discarded – undo
867 867
 	 *
868 868
 	 * @since 1.0.19
869 869
 	 */
870
-	public function is_required_field_set( $field ) {
871
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
870
+	public function is_required_field_set($field) {
871
+		return empty($field['required']) || !empty($this->data[$field['id']]);
872 872
 	}
873 873
 
874 874
 	/**
@@ -876,8 +876,8 @@  discard block
 block discarded – undo
876 876
 	 *
877 877
 	 * @since 1.0.19
878 878
 	 */
879
-	public function format_amount( $amount ) {
880
-		return wpinv_price( $amount, $this->get_currency() );
879
+	public function format_amount($amount) {
880
+		return wpinv_price($amount, $this->get_currency());
881 881
 	}
882 882
 
883 883
 }
Please login to merge, or discard this patch.