Passed
Pull Request — master (#442)
by Brian
04:21
created
includes/wpinv-helper-functions.php 1 patch
Spacing   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Are we supporting item quantities?
@@ -20,35 +20,35 @@  discard block
 block discarded – undo
20 20
  */
21 21
 function wpinv_get_ip() {
22 22
 
23
-    if ( isset( $_SERVER['HTTP_X_REAL_IP'] ) ) {
24
-        return sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_REAL_IP'] ) );
23
+    if (isset($_SERVER['HTTP_X_REAL_IP'])) {
24
+        return sanitize_text_field(wp_unslash($_SERVER['HTTP_X_REAL_IP']));
25 25
     }
26 26
 
27
-    if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
27
+    if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
28 28
         // Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
29 29
         // Make sure we always only send through the first IP in the list which should always be the client IP.
30
-        return (string) rest_is_ip_address( trim( current( preg_split( '/,/', sanitize_text_field( wp_unslash( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) ) ) ) );
30
+        return (string) rest_is_ip_address(trim(current(preg_split('/,/', sanitize_text_field(wp_unslash($_SERVER['HTTP_X_FORWARDED_FOR']))))));
31 31
     }
32 32
 
33
-    if ( isset( $_SERVER['HTTP_CLIENT_IP'] ) ) {
34
-        return sanitize_text_field( wp_unslash( $_SERVER['HTTP_CLIENT_IP'] ) );
33
+    if (isset($_SERVER['HTTP_CLIENT_IP'])) {
34
+        return sanitize_text_field(wp_unslash($_SERVER['HTTP_CLIENT_IP']));
35 35
     }
36 36
 
37
-    if ( isset( $_SERVER['REMOTE_ADDR'] ) ) {
38
-        return sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
37
+    if (isset($_SERVER['REMOTE_ADDR'])) {
38
+        return sanitize_text_field(wp_unslash($_SERVER['REMOTE_ADDR']));
39 39
     }
40 40
 
41 41
     return '';
42 42
 }
43 43
 
44 44
 function wpinv_get_user_agent() {
45
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
46
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
45
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
46
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
47 47
     } else {
48 48
         $user_agent = '';
49 49
     }
50 50
 
51
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
51
+    return apply_filters('wpinv_get_user_agent', $user_agent);
52 52
 }
53 53
 
54 54
 /**
@@ -56,27 +56,27 @@  discard block
 block discarded – undo
56 56
  * 
57 57
  * @param string $amount The amount to sanitize.
58 58
  */
59
-function wpinv_sanitize_amount( $amount ) {
59
+function wpinv_sanitize_amount($amount) {
60 60
 
61 61
     // Format decimals.
62
-    $amount = str_replace( wpinv_decimal_separator(), '.', $amount );
62
+    $amount = str_replace(wpinv_decimal_separator(), '.', $amount);
63 63
 
64 64
     // Remove thousands.
65
-    $amount = str_replace( wpinv_thousands_separator(), '', $amount );
65
+    $amount = str_replace(wpinv_thousands_separator(), '', $amount);
66 66
 
67 67
     // Cast the remaining to a float.
68
-    return (float) preg_replace( '/[^0-9\.\-]/', '', $amount );
68
+    return (float) preg_replace('/[^0-9\.\-]/', '', $amount);
69 69
 
70 70
 }
71 71
 
72
-function wpinv_round_amount( $amount, $decimals = NULL ) {
73
-    if ( $decimals === NULL ) {
72
+function wpinv_round_amount($amount, $decimals = NULL) {
73
+    if ($decimals === NULL) {
74 74
         $decimals = wpinv_decimals();
75 75
     }
76 76
     
77
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
77
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
78 78
 
79
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
79
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
80 80
 }
81 81
 
82 82
 /**
@@ -88,32 +88,32 @@  discard block
 block discarded – undo
88 88
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
89 89
  * @return array
90 90
  */
91
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
91
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
92 92
 
93 93
 	$invoice_statuses = array(
94
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
95
-        'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
96
-        'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
97
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
98
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
99
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
100
-        'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
101
-        'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
94
+		'wpi-pending'    => _x('Pending payment', 'Invoice status', 'invoicing'),
95
+        'publish'        => _x('Paid', 'Invoice status', 'invoicing'),
96
+        'wpi-processing' => _x('Processing', 'Invoice status', 'invoicing'),
97
+		'wpi-onhold'     => _x('On hold', 'Invoice status', 'invoicing'),
98
+		'wpi-cancelled'  => _x('Cancelled', 'Invoice status', 'invoicing'),
99
+		'wpi-refunded'   => _x('Refunded', 'Invoice status', 'invoicing'),
100
+        'wpi-failed'     => _x('Failed', 'Invoice status', 'invoicing'),
101
+        'wpi-renewal'    => _x('Renewal Payment', 'Invoice status', 'invoicing'),
102 102
     );
103 103
 
104
-    if ( $draft ) {
105
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
104
+    if ($draft) {
105
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
106 106
     }
107 107
 
108
-    if ( $trashed ) {
109
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
108
+    if ($trashed) {
109
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
110 110
     }
111 111
 
112
-    if ( $invoice instanceof WPInv_Invoice ) {
112
+    if ($invoice instanceof WPInv_Invoice) {
113 113
         $invoice = $invoice->get_post_type();
114 114
     }
115 115
 
116
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
116
+	return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
117 117
 }
118 118
 
119 119
 /**
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
  * @param string $status The raw status
123 123
  * @param string|WPInv_Invoice $invoice The invoice object|post type|type
124 124
  */
125
-function wpinv_status_nicename( $status, $invoice = false ) {
126
-    $statuses = wpinv_get_invoice_statuses( true, true, $invoice );
127
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : $status;
125
+function wpinv_status_nicename($status, $invoice = false) {
126
+    $statuses = wpinv_get_invoice_statuses(true, true, $invoice);
127
+    $status   = isset($statuses[$status]) ? $statuses[$status] : $status;
128 128
 
129
-    return sanitize_text_field( $status );
129
+    return sanitize_text_field($status);
130 130
 }
131 131
 
132 132
 /**
@@ -134,13 +134,13 @@  discard block
 block discarded – undo
134 134
  * 
135 135
  * @param string $current
136 136
  */
137
-function wpinv_get_currency( $current = '' ) {
137
+function wpinv_get_currency($current = '') {
138 138
 
139
-    if ( empty( $current ) ) {
140
-        $current = apply_filters( 'wpinv_currency', wpinv_get_option( 'currency', 'USD' ) );
139
+    if (empty($current)) {
140
+        $current = apply_filters('wpinv_currency', wpinv_get_option('currency', 'USD'));
141 141
     }
142 142
 
143
-    return trim( strtoupper( $current ) );
143
+    return trim(strtoupper($current));
144 144
 }
145 145
 
146 146
 /**
@@ -148,25 +148,25 @@  discard block
 block discarded – undo
148 148
  * 
149 149
  * @param string|null $currency The currency code. Defaults to the default currency.
150 150
  */
151
-function wpinv_currency_symbol( $currency = null ) {
151
+function wpinv_currency_symbol($currency = null) {
152 152
 
153 153
     // Prepare the currency.
154
-    $currency = empty( $currency ) ? wpinv_get_currency() : wpinv_clean( $currency );
154
+    $currency = empty($currency) ? wpinv_get_currency() : wpinv_clean($currency);
155 155
 
156 156
     // Fetch all symbols.
157 157
     $symbols = wpinv_get_currency_symbols();
158 158
 
159 159
     // Fetch this currencies symbol.
160
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
160
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
161 161
 
162 162
     // Filter the symbol.
163
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
163
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
164 164
 }
165 165
 
166 166
 function wpinv_currency_position() {
167
-    $position = wpinv_get_option( 'currency_position', 'left' );
167
+    $position = wpinv_get_option('currency_position', 'left');
168 168
     
169
-    return apply_filters( 'wpinv_currency_position', $position );
169
+    return apply_filters('wpinv_currency_position', $position);
170 170
 }
171 171
 
172 172
 /**
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
  * 
175 175
  * @param $string|null $current
176 176
  */
177
-function wpinv_thousands_separator( $current = null ) {
177
+function wpinv_thousands_separator($current = null) {
178 178
 
179
-    if ( null == $current ) {
180
-        $current = wpinv_get_option( 'thousands_separator', '.' );
179
+    if (null == $current) {
180
+        $current = wpinv_get_option('thousands_separator', '.');
181 181
     }
182 182
 
183
-    return trim( $current );
183
+    return trim($current);
184 184
 }
185 185
 
186 186
 /**
@@ -188,13 +188,13 @@  discard block
 block discarded – undo
188 188
  * 
189 189
  * @param $string|null $current
190 190
  */
191
-function wpinv_decimal_separator( $current = null ) {
191
+function wpinv_decimal_separator($current = null) {
192 192
 
193
-    if ( null == $current ) {
194
-        $current = wpinv_get_option( 'decimal_separator', '.' );
193
+    if (null == $current) {
194
+        $current = wpinv_get_option('decimal_separator', '.');
195 195
     }
196 196
     
197
-    return trim( $current );
197
+    return trim($current);
198 198
 }
199 199
 
200 200
 /**
@@ -202,27 +202,27 @@  discard block
 block discarded – undo
202 202
  * 
203 203
  * @param $string|null $current
204 204
  */
205
-function wpinv_decimals( $current = null ) {
205
+function wpinv_decimals($current = null) {
206 206
 
207
-    if ( null == $current ) {
208
-        $current = wpinv_get_option( 'decimals', 2 );
207
+    if (null == $current) {
208
+        $current = wpinv_get_option('decimals', 2);
209 209
     }
210 210
     
211
-    return absint( $current );
211
+    return absint($current);
212 212
 }
213 213
 
214 214
 /**
215 215
  * Retrieves a list of all supported currencies.
216 216
  */
217 217
 function wpinv_get_currencies() {
218
-    return apply_filters( 'wpinv_currencies', wpinv_get_data( 'currencies' ) );
218
+    return apply_filters('wpinv_currencies', wpinv_get_data('currencies'));
219 219
 }
220 220
 
221 221
 /**
222 222
  * Retrieves a list of all currency symbols.
223 223
  */
224 224
 function wpinv_get_currency_symbols() {
225
-    return apply_filters( 'wpinv_currency_symbols', wpinv_get_data( 'currency-symbols' ) );
225
+    return apply_filters('wpinv_currency_symbols', wpinv_get_data('currency-symbols'));
226 226
 }
227 227
 
228 228
 /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 	$currency_pos = wpinv_currency_position();
235 235
 	$format       = '%1$s%2$s';
236 236
 
237
-	switch ( $currency_pos ) {
237
+	switch ($currency_pos) {
238 238
 		case 'left':
239 239
 			$format = '%1$s%2$s';
240 240
 			break;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
 			break;
250 250
 	}
251 251
 
252
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
252
+	return apply_filters('getpaid_price_format', $format, $currency_pos);
253 253
 }
254 254
 
255 255
 /**
@@ -259,25 +259,25 @@  discard block
 block discarded – undo
259 259
  * @param  string $currency Currency.
260 260
  * @return string
261 261
  */
262
-function wpinv_price( $amount = 0, $currency = '' ) {
262
+function wpinv_price($amount = 0, $currency = '') {
263 263
 
264 264
     // Backwards compatibility.
265
-    $amount             = floatval( wpinv_sanitize_amount( $amount ) );
265
+    $amount             = floatval(wpinv_sanitize_amount($amount));
266 266
 
267 267
     // Prepare variables.
268
-    $currency           = wpinv_get_currency( $currency );
268
+    $currency           = wpinv_get_currency($currency);
269 269
     $amount             = (float) $amount;
270 270
     $unformatted_amount = $amount;
271 271
     $negative           = $amount < 0;
272
-    $amount             = apply_filters( 'getpaid_raw_amount', floatval( $negative ? $amount * -1 : $amount ) );
273
-    $amount             = wpinv_format_amount( $amount );
272
+    $amount             = apply_filters('getpaid_raw_amount', floatval($negative ? $amount * -1 : $amount));
273
+    $amount             = wpinv_format_amount($amount);
274 274
 
275 275
     // Format the amount.
276 276
     $format             = getpaid_get_price_format();
277
-    $formatted_amount   = ( $negative ? '-' : '' ) . sprintf( $format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol( $currency ) . '</span>', $amount );
277
+    $formatted_amount   = ($negative ? '-' : '') . sprintf($format, '<span class="getpaid-currency__symbol">' . wpinv_currency_symbol($currency) . '</span>', $amount);
278 278
 
279 279
     // Filter the formatting.
280
-    return apply_filters( 'wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount );
280
+    return apply_filters('wpinv_price', $formatted_amount, $amount, $currency, $unformatted_amount);
281 281
 }
282 282
 
283 283
 /**
@@ -288,33 +288,33 @@  discard block
 block discarded – undo
288 288
  * @param  bool     $calculate Whether or not to apply separators.
289 289
  * @return string
290 290
  */
291
-function wpinv_format_amount( $amount, $decimals = null, $calculate = false ) {
291
+function wpinv_format_amount($amount, $decimals = null, $calculate = false) {
292 292
     $thousands_sep = wpinv_thousands_separator();
293 293
     $decimal_sep   = wpinv_decimal_separator();
294
-    $decimals      = wpinv_decimals( $decimals );
294
+    $decimals      = wpinv_decimals($decimals);
295 295
 
296 296
     // Format decimals.
297
-    $amount = str_replace( $decimal_sep, '.', $amount );
297
+    $amount = str_replace($decimal_sep, '.', $amount);
298 298
 
299 299
     // Remove thousands.
300
-    $amount = str_replace( $thousands_sep, '', $amount );
300
+    $amount = str_replace($thousands_sep, '', $amount);
301 301
 
302 302
     // Cast the remaining to a float.
303
-    $amount = floatval( $amount );
303
+    $amount = floatval($amount);
304 304
 
305
-    if ( $calculate ) {
305
+    if ($calculate) {
306 306
         return $amount;
307 307
     }
308 308
 
309 309
     // Fomart the amount.
310
-    return number_format( $amount, $decimals, $decimal_sep, $thousands_sep );
310
+    return number_format($amount, $decimals, $decimal_sep, $thousands_sep);
311 311
 }
312 312
 
313
-function wpinv_sanitize_key( $key ) {
313
+function wpinv_sanitize_key($key) {
314 314
     $raw_key = $key;
315
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
315
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
316 316
 
317
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
317
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
318 318
 }
319 319
 
320 320
 /**
@@ -322,8 +322,8 @@  discard block
 block discarded – undo
322 322
  * 
323 323
  * @param $str the file whose extension should be retrieved.
324 324
  */
325
-function wpinv_get_file_extension( $str ) {
326
-    $filetype = wp_check_filetype( $str );
325
+function wpinv_get_file_extension($str) {
326
+    $filetype = wp_check_filetype($str);
327 327
     return $filetype['ext'];
328 328
 }
329 329
 
@@ -332,16 +332,16 @@  discard block
 block discarded – undo
332 332
  * 
333 333
  * @param string $string
334 334
  */
335
-function wpinv_string_is_image_url( $string ) {
336
-    $extension = strtolower( wpinv_get_file_extension( $string ) );
337
-    return in_array( $extension, array( 'jpeg', 'jpg', 'png', 'gif', 'ico' ), true );
335
+function wpinv_string_is_image_url($string) {
336
+    $extension = strtolower(wpinv_get_file_extension($string));
337
+    return in_array($extension, array('jpeg', 'jpg', 'png', 'gif', 'ico'), true);
338 338
 }
339 339
 
340 340
 /**
341 341
  * Returns the current URL.
342 342
  */
343 343
 function wpinv_get_current_page_url() {
344
-    return ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
344
+    return (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
345 345
 }
346 346
 
347 347
 /**
@@ -351,46 +351,46 @@  discard block
 block discarded – undo
351 351
  * @param string $name  Constant name.
352 352
  * @param mixed  $value Value.
353 353
  */
354
-function getpaid_maybe_define_constant( $name, $value ) {
355
-	if ( ! defined( $name ) ) {
356
-		define( $name, $value );
354
+function getpaid_maybe_define_constant($name, $value) {
355
+	if (!defined($name)) {
356
+		define($name, $value);
357 357
 	}
358 358
 }
359 359
 
360 360
 function wpinv_get_php_arg_separator_output() {
361
-	return ini_get( 'arg_separator.output' );
361
+	return ini_get('arg_separator.output');
362 362
 }
363 363
 
364
-function wpinv_rgb_from_hex( $color ) {
365
-    $color = str_replace( '#', '', $color );
364
+function wpinv_rgb_from_hex($color) {
365
+    $color = str_replace('#', '', $color);
366 366
 
367 367
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
368
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
369
-    if ( empty( $color ) ) {
368
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
369
+    if (empty($color)) {
370 370
         return NULL;
371 371
     }
372 372
 
373
-    $color = str_split( $color );
373
+    $color = str_split($color);
374 374
 
375 375
     $rgb      = array();
376
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
377
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
378
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
376
+    $rgb['R'] = hexdec($color[0] . $color[1]);
377
+    $rgb['G'] = hexdec($color[2] . $color[3]);
378
+    $rgb['B'] = hexdec($color[4] . $color[5]);
379 379
 
380 380
     return $rgb;
381 381
 }
382 382
 
383
-function wpinv_hex_darker( $color, $factor = 30 ) {
384
-    $base  = wpinv_rgb_from_hex( $color );
383
+function wpinv_hex_darker($color, $factor = 30) {
384
+    $base  = wpinv_rgb_from_hex($color);
385 385
     $color = '#';
386 386
 
387
-    foreach ( $base as $k => $v ) {
387
+    foreach ($base as $k => $v) {
388 388
         $amount      = $v / 100;
389
-        $amount      = round( $amount * $factor );
389
+        $amount      = round($amount * $factor);
390 390
         $new_decimal = $v - $amount;
391 391
 
392
-        $new_hex_component = dechex( $new_decimal );
393
-        if ( strlen( $new_hex_component ) < 2 ) {
392
+        $new_hex_component = dechex($new_decimal);
393
+        if (strlen($new_hex_component) < 2) {
394 394
             $new_hex_component = "0" . $new_hex_component;
395 395
         }
396 396
         $color .= $new_hex_component;
@@ -399,18 +399,18 @@  discard block
 block discarded – undo
399 399
     return $color;
400 400
 }
401 401
 
402
-function wpinv_hex_lighter( $color, $factor = 30 ) {
403
-    $base  = wpinv_rgb_from_hex( $color );
402
+function wpinv_hex_lighter($color, $factor = 30) {
403
+    $base  = wpinv_rgb_from_hex($color);
404 404
     $color = '#';
405 405
 
406
-    foreach ( $base as $k => $v ) {
406
+    foreach ($base as $k => $v) {
407 407
         $amount      = 255 - $v;
408 408
         $amount      = $amount / 100;
409
-        $amount      = round( $amount * $factor );
409
+        $amount      = round($amount * $factor);
410 410
         $new_decimal = $v + $amount;
411 411
 
412
-        $new_hex_component = dechex( $new_decimal );
413
-        if ( strlen( $new_hex_component ) < 2 ) {
412
+        $new_hex_component = dechex($new_decimal);
413
+        if (strlen($new_hex_component) < 2) {
414 414
             $new_hex_component = "0" . $new_hex_component;
415 415
         }
416 416
         $color .= $new_hex_component;
@@ -419,22 +419,22 @@  discard block
 block discarded – undo
419 419
     return $color;
420 420
 }
421 421
 
422
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
423
-    $hex = str_replace( '#', '', $color );
422
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
423
+    $hex = str_replace('#', '', $color);
424 424
 
425
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
426
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
427
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
425
+    $c_r = hexdec(substr($hex, 0, 2));
426
+    $c_g = hexdec(substr($hex, 2, 2));
427
+    $c_b = hexdec(substr($hex, 4, 2));
428 428
 
429
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
429
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
430 430
 
431 431
     return $brightness > 155 ? $dark : $light;
432 432
 }
433 433
 
434
-function wpinv_format_hex( $hex ) {
435
-    $hex = trim( str_replace( '#', '', $hex ) );
434
+function wpinv_format_hex($hex) {
435
+    $hex = trim(str_replace('#', '', $hex));
436 436
 
437
-    if ( strlen( $hex ) == 3 ) {
437
+    if (strlen($hex) == 3) {
438 438
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
439 439
     }
440 440
 
@@ -454,12 +454,12 @@  discard block
 block discarded – undo
454 454
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
455 455
  * @return string
456 456
  */
457
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
458
-    if ( function_exists( 'mb_strimwidth' ) ) {
459
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
457
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
458
+    if (function_exists('mb_strimwidth')) {
459
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
460 460
     }
461 461
     
462
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
462
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
463 463
 }
464 464
 
465 465
 /**
@@ -471,28 +471,28 @@  discard block
 block discarded – undo
471 471
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
472 472
  * @return int Returns the number of characters in string.
473 473
  */
474
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
475
-    if ( function_exists( 'mb_strlen' ) ) {
476
-        return mb_strlen( $str, $encoding );
474
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
475
+    if (function_exists('mb_strlen')) {
476
+        return mb_strlen($str, $encoding);
477 477
     }
478 478
         
479
-    return strlen( $str );
479
+    return strlen($str);
480 480
 }
481 481
 
482
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
483
-    if ( function_exists( 'mb_strtolower' ) ) {
484
-        return mb_strtolower( $str, $encoding );
482
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
483
+    if (function_exists('mb_strtolower')) {
484
+        return mb_strtolower($str, $encoding);
485 485
     }
486 486
     
487
-    return strtolower( $str );
487
+    return strtolower($str);
488 488
 }
489 489
 
490
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
491
-    if ( function_exists( 'mb_strtoupper' ) ) {
492
-        return mb_strtoupper( $str, $encoding );
490
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
491
+    if (function_exists('mb_strtoupper')) {
492
+        return mb_strtoupper($str, $encoding);
493 493
     }
494 494
     
495
-    return strtoupper( $str );
495
+    return strtoupper($str);
496 496
 }
497 497
 
498 498
 /**
@@ -506,12 +506,12 @@  discard block
 block discarded – undo
506 506
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
507 507
  * @return int Returns the position of the first occurrence of search in the string.
508 508
  */
509
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
510
-    if ( function_exists( 'mb_strpos' ) ) {
511
-        return mb_strpos( $str, $find, $offset, $encoding );
509
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
510
+    if (function_exists('mb_strpos')) {
511
+        return mb_strpos($str, $find, $offset, $encoding);
512 512
     }
513 513
         
514
-    return strpos( $str, $find, $offset );
514
+    return strpos($str, $find, $offset);
515 515
 }
516 516
 
517 517
 /**
@@ -525,12 +525,12 @@  discard block
 block discarded – undo
525 525
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
526 526
  * @return int Returns the position of the last occurrence of search.
527 527
  */
528
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
529
-    if ( function_exists( 'mb_strrpos' ) ) {
530
-        return mb_strrpos( $str, $find, $offset, $encoding );
528
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
529
+    if (function_exists('mb_strrpos')) {
530
+        return mb_strrpos($str, $find, $offset, $encoding);
531 531
     }
532 532
         
533
-    return strrpos( $str, $find, $offset );
533
+    return strrpos($str, $find, $offset);
534 534
 }
535 535
 
536 536
 /**
@@ -545,16 +545,16 @@  discard block
 block discarded – undo
545 545
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
546 546
  * @return string
547 547
  */
548
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
549
-    if ( function_exists( 'mb_substr' ) ) {
550
-        if ( $length === null ) {
551
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
548
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
549
+    if (function_exists('mb_substr')) {
550
+        if ($length === null) {
551
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
552 552
         } else {
553
-            return mb_substr( $str, $start, $length, $encoding );
553
+            return mb_substr($str, $start, $length, $encoding);
554 554
         }
555 555
     }
556 556
         
557
-    return substr( $str, $start, $length );
557
+    return substr($str, $start, $length);
558 558
 }
559 559
 
560 560
 /**
@@ -566,48 +566,48 @@  discard block
 block discarded – undo
566 566
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
567 567
  * @return string The width of string.
568 568
  */
569
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
570
-    if ( function_exists( 'mb_strwidth' ) ) {
571
-        return mb_strwidth( $str, $encoding );
569
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
570
+    if (function_exists('mb_strwidth')) {
571
+        return mb_strwidth($str, $encoding);
572 572
     }
573 573
     
574
-    return wpinv_utf8_strlen( $str, $encoding );
574
+    return wpinv_utf8_strlen($str, $encoding);
575 575
 }
576 576
 
577
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
578
-    if ( function_exists( 'mb_strlen' ) ) {
579
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
577
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
578
+    if (function_exists('mb_strlen')) {
579
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
580 580
         $str_end = "";
581 581
         
582
-        if ( $lower_str_end ) {
583
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
582
+        if ($lower_str_end) {
583
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
584 584
         } else {
585
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
585
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
586 586
         }
587 587
 
588 588
         return $first_letter . $str_end;
589 589
     }
590 590
     
591
-    return ucfirst( $str );
591
+    return ucfirst($str);
592 592
 }
593 593
 
594
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
595
-    if ( function_exists( 'mb_convert_case' ) ) {
596
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
594
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
595
+    if (function_exists('mb_convert_case')) {
596
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
597 597
     }
598 598
     
599
-    return ucwords( $str );
599
+    return ucwords($str);
600 600
 }
601 601
 
602
-function wpinv_period_in_days( $period, $unit ) {
603
-    $period = absint( $period );
602
+function wpinv_period_in_days($period, $unit) {
603
+    $period = absint($period);
604 604
     
605
-    if ( $period > 0 ) {
606
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
605
+    if ($period > 0) {
606
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
607 607
             $period = $period * 7;
608
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
608
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
609 609
             $period = $period * 30;
610
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
610
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
611 611
             $period = $period * 365;
612 612
         }
613 613
     }
@@ -615,14 +615,14 @@  discard block
 block discarded – undo
615 615
     return $period;
616 616
 }
617 617
 
618
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
619
-    if ( function_exists( 'cal_days_in_month' ) ) {
620
-        return cal_days_in_month( $calendar, $month, $year );
618
+function wpinv_cal_days_in_month($calendar, $month, $year) {
619
+    if (function_exists('cal_days_in_month')) {
620
+        return cal_days_in_month($calendar, $month, $year);
621 621
     }
622 622
 
623 623
     // Fallback in case the calendar extension is not loaded in PHP
624 624
     // Only supports Gregorian calendar
625
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
625
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
626 626
 }
627 627
 
628 628
 /**
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
  *
634 634
  * @return string
635 635
  */
636
-function wpi_help_tip( $tip, $allow_html = false ) {
636
+function wpi_help_tip($tip, $allow_html = false) {
637 637
 
638
-    if ( $allow_html ) {
639
-        $tip = wpi_sanitize_tooltip( $tip );
638
+    if ($allow_html) {
639
+        $tip = wpi_sanitize_tooltip($tip);
640 640
     } else {
641
-        $tip = esc_attr( $tip );
641
+        $tip = esc_attr($tip);
642 642
     }
643 643
 
644 644
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -652,8 +652,8 @@  discard block
 block discarded – undo
652 652
  * @param string $var
653 653
  * @return string
654 654
  */
655
-function wpi_sanitize_tooltip( $var ) {
656
-    return wp_kses( html_entity_decode( $var ), array(
655
+function wpi_sanitize_tooltip($var) {
656
+    return wp_kses(html_entity_decode($var), array(
657 657
         'br'     => array(),
658 658
         'em'     => array(),
659 659
         'strong' => array(),
@@ -664,7 +664,7 @@  discard block
 block discarded – undo
664 664
         'li'     => array(),
665 665
         'ol'     => array(),
666 666
         'p'      => array(),
667
-    ) );
667
+    ));
668 668
 }
669 669
 
670 670
 /**
@@ -674,7 +674,7 @@  discard block
 block discarded – undo
674 674
  */
675 675
 function wpinv_get_screen_ids() {
676 676
 
677
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
677
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
678 678
 
679 679
     $screen_ids = array(
680 680
         'toplevel_page_' . $screen_id,
@@ -692,7 +692,7 @@  discard block
 block discarded – undo
692 692
         'invoicing_page_wpi-addons',
693 693
     );
694 694
 
695
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
695
+    return apply_filters('wpinv_screen_ids', $screen_ids);
696 696
 }
697 697
 
698 698
 /**
@@ -703,14 +703,14 @@  discard block
 block discarded – undo
703 703
  * @param array|string $list List of values.
704 704
  * @return array Sanitized array of values.
705 705
  */
706
-function wpinv_parse_list( $list ) {
706
+function wpinv_parse_list($list) {
707 707
 
708
-    if ( empty( $list ) ) {
708
+    if (empty($list)) {
709 709
         $list = array();
710 710
     }
711 711
 
712
-	if ( ! is_array( $list ) ) {
713
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
712
+	if (!is_array($list)) {
713
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
714 714
 	}
715 715
 
716 716
 	return $list;
@@ -724,16 +724,16 @@  discard block
 block discarded – undo
724 724
  * @param string $key Type of data to fetch.
725 725
  * @return mixed Fetched data.
726 726
  */
727
-function wpinv_get_data( $key ) {
727
+function wpinv_get_data($key) {
728 728
 
729 729
     // Try fetching it from the cache.
730
-    $data = wp_cache_get( "wpinv-data-$key", 'wpinv' );
731
-    if( $data ) {
730
+    $data = wp_cache_get("wpinv-data-$key", 'wpinv');
731
+    if ($data) {
732 732
         return $data;
733 733
     }
734 734
 
735
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
736
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
735
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
736
+	wp_cache_set("wpinv-data-$key", $data, 'wpinv');
737 737
 
738 738
 	return $data;
739 739
 }
@@ -747,10 +747,10 @@  discard block
 block discarded – undo
747 747
  * @param bool $first_empty Whether or not the first item in the list should be empty
748 748
  * @return mixed Fetched data.
749 749
  */
750
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
750
+function wpinv_maybe_add_empty_option($options, $first_empty) {
751 751
 
752
-    if ( ! empty( $options ) && $first_empty ) {
753
-        return array_merge( array( '' => '' ), $options );
752
+    if (!empty($options) && $first_empty) {
753
+        return array_merge(array('' => ''), $options);
754 754
     }
755 755
     return $options;
756 756
 
@@ -762,21 +762,21 @@  discard block
 block discarded – undo
762 762
  * @param mixed $var Data to sanitize.
763 763
  * @return string|array
764 764
  */
765
-function wpinv_clean( $var ) {
765
+function wpinv_clean($var) {
766 766
 
767
-	if ( is_array( $var ) ) {
768
-		return array_map( 'wpinv_clean', $var );
767
+	if (is_array($var)) {
768
+		return array_map('wpinv_clean', $var);
769 769
     }
770 770
 
771
-    if ( is_object( $var ) ) {
772
-		$object_vars = get_object_vars( $var );
773
-		foreach ( $object_vars as $property_name => $property_value ) {
774
-			$var->$property_name = wpinv_clean( $property_value );
771
+    if (is_object($var)) {
772
+		$object_vars = get_object_vars($var);
773
+		foreach ($object_vars as $property_name => $property_value) {
774
+			$var->$property_name = wpinv_clean($property_value);
775 775
         }
776 776
         return $var;
777 777
 	}
778 778
     
779
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
779
+    return is_string($var) ? sanitize_text_field($var) : $var;
780 780
 }
781 781
 
782 782
 /**
@@ -785,43 +785,43 @@  discard block
 block discarded – undo
785 785
  * @param string $str Data to convert.
786 786
  * @return string|array
787 787
  */
788
-function getpaid_convert_price_string_to_options( $str ) {
788
+function getpaid_convert_price_string_to_options($str) {
789 789
 
790
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
791
-    $options     = array();
790
+	$raw_options = array_map('trim', explode(',', $str));
791
+    $options = array();
792 792
 
793
-    foreach ( $raw_options as $option ) {
793
+    foreach ($raw_options as $option) {
794 794
 
795
-        if ( '' == $option ) {
795
+        if ('' == $option) {
796 796
             continue;
797 797
         }
798 798
 
799
-        $option = array_map( 'trim', explode( '|', $option ) );
799
+        $option = array_map('trim', explode('|', $option));
800 800
 
801 801
         $price = null;
802 802
         $label = null;
803 803
 
804
-        if ( isset( $option[0] ) && '' !=  $option[0] ) {
805
-            $label  = $option[0];
804
+        if (isset($option[0]) && '' != $option[0]) {
805
+            $label = $option[0];
806 806
         }
807 807
 
808
-        if ( isset( $option[1] ) && '' !=  $option[1] ) {
808
+        if (isset($option[1]) && '' != $option[1]) {
809 809
             $price = $option[1];
810 810
         }
811 811
 
812
-        if ( ! isset( $price ) ) {
812
+        if (!isset($price)) {
813 813
             $price = $label;
814 814
         }
815 815
 
816
-        if ( ! isset( $price ) || ! is_numeric( $price ) ) {
816
+        if (!isset($price) || !is_numeric($price)) {
817 817
             continue;
818 818
         }
819 819
 
820
-        if ( ! isset( $label ) ) {
820
+        if (!isset($label)) {
821 821
             $label = $price;
822 822
         }
823 823
 
824
-        $options[ $price ] = $label;
824
+        $options[$price] = $label;
825 825
     }
826 826
 
827 827
     return $options;
@@ -830,22 +830,22 @@  discard block
 block discarded – undo
830 830
 /**
831 831
  * Returns the help tip.
832 832
  */
833
-function getpaid_get_help_tip( $tip, $additional_classes = '' ) {
834
-    $additional_classes = sanitize_html_class( $additional_classes );
835
-    $tip                = esc_attr__( $tip );
833
+function getpaid_get_help_tip($tip, $additional_classes = '') {
834
+    $additional_classes = sanitize_html_class($additional_classes);
835
+    $tip                = esc_attr__($tip);
836 836
     return "<span class='wpi-help-tip dashicons dashicons-editor-help $additional_classes' title='$tip'></span>";
837 837
 }
838 838
 
839 839
 /**
840 840
  * Formats a date
841 841
  */
842
-function getpaid_format_date( $date ) {
842
+function getpaid_format_date($date) {
843 843
 
844
-    if ( empty( $date ) || $date == '0000-00-00 00:00:00' ) {
844
+    if (empty($date) || $date == '0000-00-00 00:00:00') {
845 845
         return '';
846 846
     }
847 847
 
848
-    return date_i18n( getpaid_date_format(), strtotime( $date ) );
848
+    return date_i18n(getpaid_date_format(), strtotime($date));
849 849
 
850 850
 }
851 851
 
@@ -854,9 +854,9 @@  discard block
 block discarded – undo
854 854
  *
855 855
  * @return string
856 856
  */
857
-function getpaid_format_date_value( $date, $default = "&mdash;" ) {
858
-    $date = getpaid_format_date( $date );
859
-    return empty( $date ) ? $default : $date;
857
+function getpaid_format_date_value($date, $default = "&mdash;") {
858
+    $date = getpaid_format_date($date);
859
+    return empty($date) ? $default : $date;
860 860
 }
861 861
 
862 862
 /**
@@ -865,7 +865,7 @@  discard block
 block discarded – undo
865 865
  * @return string
866 866
  */
867 867
 function getpaid_date_format() {
868
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
868
+	return apply_filters('getpaid_date_format', get_option('date_format'));
869 869
 }
870 870
 
871 871
 /**
@@ -874,7 +874,7 @@  discard block
 block discarded – undo
874 874
  * @return string
875 875
  */
876 876
 function getpaid_time_format() {
877
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
877
+	return apply_filters('getpaid_time_format', get_option('time_format'));
878 878
 }
879 879
 
880 880
 /**
@@ -884,16 +884,16 @@  discard block
 block discarded – undo
884 884
  * @param  integer $limit Limit size in characters.
885 885
  * @return string
886 886
  */
887
-function getpaid_limit_length( $string, $limit ) {
887
+function getpaid_limit_length($string, $limit) {
888 888
     $str_limit = $limit - 3;
889 889
 
890
-	if ( function_exists( 'mb_strimwidth' ) ) {
891
-		if ( mb_strlen( $string ) > $limit ) {
892
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
890
+	if (function_exists('mb_strimwidth')) {
891
+		if (mb_strlen($string) > $limit) {
892
+			$string = mb_strimwidth($string, 0, $str_limit) . '...';
893 893
 		}
894 894
 	} else {
895
-		if ( strlen( $string ) > $limit ) {
896
-			$string = substr( $string, 0, $str_limit ) . '...';
895
+		if (strlen($string) > $limit) {
896
+			$string = substr($string, 0, $str_limit) . '...';
897 897
 		}
898 898
 	}
899 899
     return $string;
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
  * @since 1.0.19
908 908
  */
909 909
 function getpaid_api() {
910
-    return getpaid()->get( 'api' );
910
+    return getpaid()->get('api');
911 911
 }
912 912
 
913 913
 /**
@@ -917,7 +917,7 @@  discard block
 block discarded – undo
917 917
  * @since 1.0.19
918 918
  */
919 919
 function getpaid_post_types() {
920
-    return getpaid()->get( 'post_types' );
920
+    return getpaid()->get('post_types');
921 921
 }
922 922
 
923 923
 /**
@@ -927,7 +927,7 @@  discard block
 block discarded – undo
927 927
  * @since 1.0.19
928 928
  */
929 929
 function getpaid_session() {
930
-    return getpaid()->get( 'session' );
930
+    return getpaid()->get('session');
931 931
 }
932 932
 
933 933
 /**
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
  * @since 1.0.19
938 938
  */
939 939
 function getpaid_notes() {
940
-    return getpaid()->get( 'notes' );
940
+    return getpaid()->get('notes');
941 941
 }
942 942
 
943 943
 /**
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
  * @return GetPaid_Admin
947 947
  */
948 948
 function getpaid_admin() {
949
-    return getpaid()->get( 'admin' );
949
+    return getpaid()->get('admin');
950 950
 }
951 951
 
952 952
 /**
@@ -956,8 +956,8 @@  discard block
 block discarded – undo
956 956
  * @param string $base the base url
957 957
  * @return string
958 958
  */
959
-function getpaid_get_authenticated_action_url( $action, $base = false ) {
960
-    return wp_nonce_url( add_query_arg( 'getpaid-action', $action, $base ), 'getpaid-nonce', 'getpaid-nonce' );
959
+function getpaid_get_authenticated_action_url($action, $base = false) {
960
+    return wp_nonce_url(add_query_arg('getpaid-action', $action, $base), 'getpaid-nonce', 'getpaid-nonce');
961 961
 }
962 962
 
963 963
 /**
@@ -965,11 +965,11 @@  discard block
 block discarded – undo
965 965
  *
966 966
  * @return string
967 967
  */
968
-function getpaid_get_post_type_label( $post_type, $plural = true ) {
968
+function getpaid_get_post_type_label($post_type, $plural = true) {
969 969
 
970
-    $post_type = get_post_type_object( $post_type );
970
+    $post_type = get_post_type_object($post_type);
971 971
 
972
-    if ( ! is_object( $post_type ) ) {
972
+    if (!is_object($post_type)) {
973 973
         return null;
974 974
     }
975 975
 
@@ -982,18 +982,18 @@  discard block
 block discarded – undo
982 982
  *
983 983
  * @return mixed|null
984 984
  */
985
-function getpaid_get_array_field( $array, $key, $secondary_key = null ) {
985
+function getpaid_get_array_field($array, $key, $secondary_key = null) {
986 986
 
987
-    if ( ! is_array( $array ) ) {
987
+    if (!is_array($array)) {
988 988
         return null;
989 989
     }
990 990
 
991
-    if ( ! empty( $secondary_key ) ) {
992
-        $array = isset( $array[ $secondary_key ] ) ? $array[ $secondary_key ] : array();
993
-        return getpaid_get_array_field( $array, $key );
991
+    if (!empty($secondary_key)) {
992
+        $array = isset($array[$secondary_key]) ? $array[$secondary_key] : array();
993
+        return getpaid_get_array_field($array, $key);
994 994
     }
995 995
 
996
-    return isset( $array[ $key ] ) ? $array[ $key ] : null;
996
+    return isset($array[$key]) ? $array[$key] : null;
997 997
 
998 998
 }
999 999
 
@@ -1002,12 +1002,12 @@  discard block
 block discarded – undo
1002 1002
  *
1003 1003
  * @return array
1004 1004
  */
1005
-function getpaid_array_merge_if_empty( $args, $defaults ) {
1005
+function getpaid_array_merge_if_empty($args, $defaults) {
1006 1006
 
1007
-    foreach ( $defaults as $key => $value ) {
1007
+    foreach ($defaults as $key => $value) {
1008 1008
 
1009
-        if ( array_key_exists( $key, $args ) && empty( $args[ $key ] ) ) {
1010
-            $args[ $key ] = $value;
1009
+        if (array_key_exists($key, $args) && empty($args[$key])) {
1010
+            $args[$key] = $value;
1011 1011
         }
1012 1012
 
1013 1013
     }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -101,36 +101,36 @@  discard block
 block discarded – undo
101 101
             'payment_form_refresh_prices' => true,
102 102
         );
103 103
 
104
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
105
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
106
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
104
+        foreach ($ajax_events as $ajax_event => $nopriv) {
105
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
106
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
107 107
 
108
-            if ( $nopriv ) {
109
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
+            if ($nopriv) {
109
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
110
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
             }
113 113
         }
114 114
     }
115 115
     
116 116
     public static function add_note() {
117
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
117
+        check_ajax_referer('add-invoice-note', '_nonce');
118 118
 
119
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
119
+        if (!wpinv_current_user_can_manage_invoicing()) {
120 120
             die(-1);
121 121
         }
122 122
 
123
-        $post_id   = absint( $_POST['post_id'] );
124
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
125
-        $note_type = sanitize_text_field( $_POST['note_type'] );
123
+        $post_id   = absint($_POST['post_id']);
124
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
125
+        $note_type = sanitize_text_field($_POST['note_type']);
126 126
 
127 127
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
128 128
 
129
-        if ( $post_id > 0 ) {
130
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
129
+        if ($post_id > 0) {
130
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
131 131
 
132
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
133
-                wpinv_get_invoice_note_line_item( $note_id );
132
+            if ($note_id > 0 && !is_wp_error($note_id)) {
133
+                wpinv_get_invoice_note_line_item($note_id);
134 134
             }
135 135
         }
136 136
 
@@ -138,16 +138,16 @@  discard block
 block discarded – undo
138 138
     }
139 139
 
140 140
     public static function delete_note() {
141
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
141
+        check_ajax_referer('delete-invoice-note', '_nonce');
142 142
 
143
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
143
+        if (!wpinv_current_user_can_manage_invoicing()) {
144 144
             die(-1);
145 145
         }
146 146
 
147
-        $note_id = (int)$_POST['note_id'];
147
+        $note_id = (int) $_POST['note_id'];
148 148
 
149
-        if ( $note_id > 0 ) {
150
-            wp_delete_comment( $note_id, true );
149
+        if ($note_id > 0) {
150
+            wp_delete_comment($note_id, true);
151 151
         }
152 152
 
153 153
         die();
@@ -165,34 +165,34 @@  discard block
 block discarded – undo
165 165
     public static function get_billing_details() {
166 166
 
167 167
         // Verify nonce.
168
-        check_ajax_referer( 'wpinv-nonce' );
168
+        check_ajax_referer('wpinv-nonce');
169 169
 
170 170
         // Can the user manage the plugin?
171
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
171
+        if (!wpinv_current_user_can_manage_invoicing()) {
172 172
             die(-1);
173 173
         }
174 174
 
175 175
         // Do we have a user id?
176 176
         $user_id = $_GET['user_id'];
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die(-1);
180 180
         }
181 181
 
182 182
         // Fetch the billing details.
183
-        $billing_details    = wpinv_get_user_address( $user_id );
184
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
183
+        $billing_details    = wpinv_get_user_address($user_id);
184
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
185 185
 
186 186
         // unset the user id and email.
187
-        $to_ignore = array( 'user_id', 'email' );
187
+        $to_ignore = array('user_id', 'email');
188 188
 
189
-        foreach ( $to_ignore as $key ) {
190
-            if ( isset( $billing_details[ $key ] ) ) {
191
-                unset( $billing_details[ $key ] );
189
+        foreach ($to_ignore as $key) {
190
+            if (isset($billing_details[$key])) {
191
+                unset($billing_details[$key]);
192 192
             }
193 193
         }
194 194
 
195
-        wp_send_json_success( $billing_details );
195
+        wp_send_json_success($billing_details);
196 196
 
197 197
     }
198 198
 
@@ -202,47 +202,47 @@  discard block
 block discarded – undo
202 202
     public static function check_new_user_email() {
203 203
 
204 204
         // Verify nonce.
205
-        check_ajax_referer( 'wpinv-nonce' );
205
+        check_ajax_referer('wpinv-nonce');
206 206
 
207 207
         // Can the user manage the plugin?
208
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
208
+        if (!wpinv_current_user_can_manage_invoicing()) {
209 209
             die(-1);
210 210
         }
211 211
 
212 212
         // We need an email address.
213
-        if ( empty( $_GET['email'] ) ) {
214
-            _e( "Provide the new user's email address", 'invoicing' );
213
+        if (empty($_GET['email'])) {
214
+            _e("Provide the new user's email address", 'invoicing');
215 215
             exit;
216 216
         }
217 217
 
218 218
         // Ensure the email is valid.
219
-        $email = sanitize_text_field( $_GET['email'] );
220
-        if ( ! is_email( $email ) ) {
221
-            _e( 'Invalid email address', 'invoicing' );
219
+        $email = sanitize_text_field($_GET['email']);
220
+        if (!is_email($email)) {
221
+            _e('Invalid email address', 'invoicing');
222 222
             exit;
223 223
         }
224 224
 
225 225
         // And it does not exist.
226
-        if ( email_exists( $email ) ) {
227
-            _e( 'A user with this email address already exists', 'invoicing' );
226
+        if (email_exists($email)) {
227
+            _e('A user with this email address already exists', 'invoicing');
228 228
             exit;
229 229
         }
230 230
 
231
-        wp_send_json_success( true );
231
+        wp_send_json_success(true);
232 232
     }
233 233
     
234 234
     public static function run_tool() {
235
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
236
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
235
+        check_ajax_referer('wpinv-nonce', '_nonce');
236
+        if (!wpinv_current_user_can_manage_invoicing()) {
237 237
             die(-1);
238 238
         }
239 239
         
240
-        $tool = sanitize_text_field( $_POST['tool'] );
240
+        $tool = sanitize_text_field($_POST['tool']);
241 241
         
242
-        do_action( 'wpinv_run_tool' );
242
+        do_action('wpinv_run_tool');
243 243
         
244
-        if ( !empty( $tool ) ) {
245
-            do_action( 'wpinv_tool_' . $tool );
244
+        if (!empty($tool)) {
245
+            do_action('wpinv_tool_' . $tool);
246 246
         }
247 247
     }
248 248
 
@@ -252,27 +252,27 @@  discard block
 block discarded – undo
252 252
     public static function get_payment_form() {
253 253
 
254 254
         // Check nonce.
255
-        check_ajax_referer( 'getpaid_form_nonce' );
255
+        check_ajax_referer('getpaid_form_nonce');
256 256
 
257 257
         // Is the request set up correctly?
258
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
258
+		if (empty($_GET['form']) && empty($_GET['item'])) {
259 259
 			echo aui()->alert(
260 260
 				array(
261 261
 					'type'    => 'warning',
262
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
262
+					'content' => __('No payment form or item provided', 'invoicing'),
263 263
 				)
264 264
             );
265 265
             exit;
266 266
         }
267 267
 
268 268
         // Payment form or button?
269
-		if ( ! empty( $_GET['form'] ) ) {
270
-            getpaid_display_payment_form( $_GET['form'] );
271
-		} else if( ! empty( $_GET['invoice'] ) ) {
272
-		    getpaid_display_invoice_payment_form( $_GET['invoice'] );
269
+		if (!empty($_GET['form'])) {
270
+            getpaid_display_payment_form($_GET['form']);
271
+		} else if (!empty($_GET['invoice'])) {
272
+		    getpaid_display_invoice_payment_form($_GET['invoice']);
273 273
         } else {
274
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
275
-		    getpaid_display_item_payment_form( $items );
274
+			$items = getpaid_convert_items_to_array($_GET['item']);
275
+		    getpaid_display_item_payment_form($items);
276 276
         }
277 277
 
278 278
         exit;
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
     public static function payment_form() {
288 288
 
289 289
         // Check nonce.
290
-        check_ajax_referer( 'getpaid_form_nonce' );
290
+        check_ajax_referer('getpaid_form_nonce');
291 291
 
292 292
         // ... form fields...
293
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
294
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
293
+        if (empty($_POST['getpaid_payment_form_submission'])) {
294
+            _e('Error: Reload the page and try again.', 'invoicing');
295 295
             exit;
296 296
         }
297 297
 
298 298
         // Process the payment form.
299
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
300
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
299
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
300
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
301 301
         $checkout->process_checkout();
302 302
 
303 303
         exit;
@@ -310,55 +310,55 @@  discard block
 block discarded – undo
310 310
      */
311 311
     public static function get_payment_form_states_field() {
312 312
 
313
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
313
+        if (empty($_GET['country']) || empty($_GET['form'])) {
314 314
             exit;
315 315
         }
316 316
 
317
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
317
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
318 318
 
319
-        if ( empty( $elements ) ) {
319
+        if (empty($elements)) {
320 320
             exit;
321 321
         }
322 322
 
323 323
         $address_fields = array();
324
-        foreach ( $elements as $element ) {
325
-            if ( 'address' === $element['type'] ) {
324
+        foreach ($elements as $element) {
325
+            if ('address' === $element['type']) {
326 326
                 $address_fields = $element;
327 327
                 break;
328 328
             }
329 329
         }
330 330
 
331
-        if ( empty( $address_fields ) ) {
331
+        if (empty($address_fields)) {
332 332
             exit;
333 333
         }
334 334
 
335
-        foreach ( $address_fields['fields'] as $address_field ) {
335
+        foreach ($address_fields['fields'] as $address_field) {
336 336
 
337
-            if ( 'wpinv_state' == $address_field['name'] ) {
337
+            if ('wpinv_state' == $address_field['name']) {
338 338
 
339
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
340
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
341
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
342
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
343
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
344
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
339
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
340
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
341
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
342
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
343
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
344
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
345 345
 
346
-                if ( ! empty( $address_field['required'] ) ) {
346
+                if (!empty($address_field['required'])) {
347 347
                     $label .= "<span class='text-danger'> *</span>";
348 348
                 }
349 349
 
350
-                $html = getpaid_get_states_select_markup (
351
-                    sanitize_text_field( $_GET['country'] ),
350
+                $html = getpaid_get_states_select_markup(
351
+                    sanitize_text_field($_GET['country']),
352 352
                     $value,
353 353
                     $placeholder,
354 354
                     $label,
355 355
                     $description,
356
-                    ! empty( $address_field['required'] ),
356
+                    !empty($address_field['required']),
357 357
                     $wrap_class,
358
-                    wpinv_clean( $_GET['name'] )
358
+                    wpinv_clean($_GET['name'])
359 359
                 );
360 360
 
361
-                wp_send_json_success( $html );
361
+                wp_send_json_success($html);
362 362
                 exit;
363 363
 
364 364
             }
@@ -374,56 +374,56 @@  discard block
 block discarded – undo
374 374
     public static function recalculate_invoice_totals() {
375 375
 
376 376
         // Verify nonce.
377
-        check_ajax_referer( 'wpinv-nonce' );
377
+        check_ajax_referer('wpinv-nonce');
378 378
 
379
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
379
+        if (!wpinv_current_user_can_manage_invoicing()) {
380 380
             exit;
381 381
         }
382 382
 
383 383
         // We need an invoice.
384
-        if ( empty( $_POST['post_id'] ) ) {
384
+        if (empty($_POST['post_id'])) {
385 385
             exit;
386 386
         }
387 387
 
388 388
         // Fetch the invoice.
389
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
389
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
390 390
 
391 391
         // Ensure it exists.
392
-        if ( ! $invoice->get_id() ) {
392
+        if (!$invoice->get_id()) {
393 393
             exit;
394 394
         }
395 395
 
396 396
         // Maybe set the country, state, currency.
397
-        foreach ( array( 'country', 'state', 'currency' ) as $key ) {
398
-            if ( isset( $_POST[ $key ] ) ) {
397
+        foreach (array('country', 'state', 'currency') as $key) {
398
+            if (isset($_POST[$key])) {
399 399
                 $method = "set_$key";
400
-                $invoice->$method( $_POST[ $key ] );
400
+                $invoice->$method($_POST[$key]);
401 401
             }
402 402
         }
403 403
 
404 404
         // Maybe disable taxes.
405
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
405
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
406 406
 
407 407
         // Recalculate totals.
408 408
         $invoice->recalculate_total();
409 409
 
410
-        $total = wpinv_price( wpinv_format_amount( $invoice->get_total() ), $invoice->get_currency() );
410
+        $total = wpinv_price(wpinv_format_amount($invoice->get_total()), $invoice->get_currency());
411 411
 
412
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
413
-            $recurring_total = wpinv_price( wpinv_format_amount( $invoice->get_recurring_total() ), $invoice->get_currency() );
414
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
412
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
413
+            $recurring_total = wpinv_price(wpinv_format_amount($invoice->get_recurring_total()), $invoice->get_currency());
414
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
415 415
         }
416 416
 
417 417
         $totals = array(
418
-            'subtotal' => wpinv_price( wpinv_format_amount( $invoice->get_subtotal() ), $invoice->get_currency() ),
419
-            'discount' => wpinv_price( wpinv_format_amount( $invoice->get_total_discount() ), $invoice->get_currency() ),
420
-            'tax'      => wpinv_price( wpinv_format_amount( $invoice->get_total_tax() ), $invoice->get_currency() ),
418
+            'subtotal' => wpinv_price(wpinv_format_amount($invoice->get_subtotal()), $invoice->get_currency()),
419
+            'discount' => wpinv_price(wpinv_format_amount($invoice->get_total_discount()), $invoice->get_currency()),
420
+            'tax'      => wpinv_price(wpinv_format_amount($invoice->get_total_tax()), $invoice->get_currency()),
421 421
             'total'    => $total,
422 422
         );
423 423
 
424
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
424
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
425 425
 
426
-        wp_send_json_success( compact( 'totals' ) );
426
+        wp_send_json_success(compact('totals'));
427 427
     }
428 428
 
429 429
     /**
@@ -432,33 +432,33 @@  discard block
 block discarded – undo
432 432
     public static function get_invoice_items() {
433 433
 
434 434
         // Verify nonce.
435
-        check_ajax_referer( 'wpinv-nonce' );
435
+        check_ajax_referer('wpinv-nonce');
436 436
 
437
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
437
+        if (!wpinv_current_user_can_manage_invoicing()) {
438 438
             exit;
439 439
         }
440 440
 
441 441
         // We need an invoice and items.
442
-        if ( empty( $_POST['post_id'] ) ) {
442
+        if (empty($_POST['post_id'])) {
443 443
             exit;
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
447
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Return an array of invoice items.
455 455
         $items = array();
456 456
 
457
-        foreach ( $invoice->get_items() as $item_id => $item ) {
458
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
457
+        foreach ($invoice->get_items() as $item_id => $item) {
458
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
459 459
         }
460 460
 
461
-        wp_send_json_success( compact( 'items' ) );
461
+        wp_send_json_success(compact('items'));
462 462
     }
463 463
 
464 464
     /**
@@ -467,50 +467,50 @@  discard block
 block discarded – undo
467 467
     public static function edit_invoice_item() {
468 468
 
469 469
         // Verify nonce.
470
-        check_ajax_referer( 'wpinv-nonce' );
470
+        check_ajax_referer('wpinv-nonce');
471 471
 
472
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
472
+        if (!wpinv_current_user_can_manage_invoicing()) {
473 473
             exit;
474 474
         }
475 475
 
476 476
         // We need an invoice and item details.
477
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
477
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
478 478
             exit;
479 479
         }
480 480
 
481 481
         // Fetch the invoice.
482
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
482
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
483 483
 
484 484
         // Ensure it exists and its not been paid for.
485
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
485
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
486 486
             exit;
487 487
         }
488 488
 
489 489
         // Format the data.
490
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
490
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
491 491
 
492 492
         // Ensure that we have an item id.
493
-        if ( empty( $data['id'] ) ) {
493
+        if (empty($data['id'])) {
494 494
             exit;
495 495
         }
496 496
 
497 497
         // Abort if the invoice does not have the specified item.
498
-        $item = $invoice->get_item( (int) $data['id'] );
498
+        $item = $invoice->get_item((int) $data['id']);
499 499
 
500
-        if ( empty( $item ) ) {
500
+        if (empty($item)) {
501 501
             exit;
502 502
         }
503 503
 
504 504
         // Update the item.
505
-        $item->set_price( $data['price'] );
506
-        $item->set_name( $data['name'] );
507
-        $item->set_description( $data['description'] );
508
-        $item->set_quantity( $data['quantity'] );
505
+        $item->set_price($data['price']);
506
+        $item->set_name($data['name']);
507
+        $item->set_description($data['description']);
508
+        $item->set_quantity($data['quantity']);
509 509
 
510 510
         // Add it to the invoice.
511
-        $error = $invoice->add_item( $item );
511
+        $error = $invoice->add_item($item);
512 512
         $alert = false;
513
-        if ( is_wp_error( $error ) ) {
513
+        if (is_wp_error($error)) {
514 514
             $alert = $error->get_error_message();
515 515
         }
516 516
 
@@ -523,11 +523,11 @@  discard block
 block discarded – undo
523 523
         // Return an array of invoice items.
524 524
         $items = array();
525 525
 
526
-        foreach ( $invoice->get_items() as $item_id => $item ) {
527
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
526
+        foreach ($invoice->get_items() as $item_id => $item) {
527
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
528 528
         }
529 529
 
530
-        wp_send_json_success( compact( 'items', 'alert' ) );
530
+        wp_send_json_success(compact('items', 'alert'));
531 531
     }
532 532
 
533 533
     /**
@@ -536,33 +536,33 @@  discard block
 block discarded – undo
536 536
     public static function remove_invoice_item() {
537 537
 
538 538
         // Verify nonce.
539
-        check_ajax_referer( 'wpinv-nonce' );
539
+        check_ajax_referer('wpinv-nonce');
540 540
 
541
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
541
+        if (!wpinv_current_user_can_manage_invoicing()) {
542 542
             exit;
543 543
         }
544 544
 
545 545
         // We need an invoice and an item.
546
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
546
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
547 547
             exit;
548 548
         }
549 549
 
550 550
         // Fetch the invoice.
551
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
551
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
552 552
 
553 553
         // Ensure it exists and its not been paid for.
554
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
554
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
555 555
             exit;
556 556
         }
557 557
 
558 558
         // Abort if the invoice does not have the specified item.
559
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
559
+        $item = $invoice->get_item((int) $_POST['item_id']);
560 560
 
561
-        if ( empty( $item ) ) {
561
+        if (empty($item)) {
562 562
             exit;
563 563
         }
564 564
 
565
-        $invoice->remove_item( (int) $_POST['item_id'] );
565
+        $invoice->remove_item((int) $_POST['item_id']);
566 566
 
567 567
         // Update totals.
568 568
         $invoice->recalculate_total();
@@ -573,11 +573,11 @@  discard block
 block discarded – undo
573 573
         // Return an array of invoice items.
574 574
         $items = array();
575 575
 
576
-        foreach ( $invoice->get_items() as $item_id => $item ) {
577
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
576
+        foreach ($invoice->get_items() as $item_id => $item) {
577
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
578 578
         }
579 579
 
580
-        wp_send_json_success( compact( 'items' ) );
580
+        wp_send_json_success(compact('items'));
581 581
     }
582 582
 
583 583
     /**
@@ -586,39 +586,39 @@  discard block
 block discarded – undo
586 586
     public static function add_invoice_items() {
587 587
 
588 588
         // Verify nonce.
589
-        check_ajax_referer( 'wpinv-nonce' );
589
+        check_ajax_referer('wpinv-nonce');
590 590
 
591
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
591
+        if (!wpinv_current_user_can_manage_invoicing()) {
592 592
             exit;
593 593
         }
594 594
 
595 595
         // We need an invoice and items.
596
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
596
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
597 597
             exit;
598 598
         }
599 599
 
600 600
         // Fetch the invoice.
601
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
601
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
602 602
         $alert   = false;
603 603
 
604 604
         // Ensure it exists and its not been paid for.
605
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
605
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
606 606
             exit;
607 607
         }
608 608
 
609 609
         // Add the items.
610
-        foreach ( $_POST['items'] as $data ) {
610
+        foreach ($_POST['items'] as $data) {
611 611
 
612
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
612
+            $item = new GetPaid_Form_Item($data['id']);
613 613
 
614
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
615
-                $item->set_quantity( $data[ 'qty' ] );
614
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
615
+                $item->set_quantity($data['qty']);
616 616
             }
617 617
 
618
-            if ( $item->get_id() > 0 ) {
619
-                $error = $invoice->add_item( $item );
618
+            if ($item->get_id() > 0) {
619
+                $error = $invoice->add_item($item);
620 620
 
621
-                if ( is_wp_error( $error ) ) {
621
+                if (is_wp_error($error)) {
622 622
                     $alert = $error->get_error_message();
623 623
                 }
624 624
 
@@ -633,11 +633,11 @@  discard block
 block discarded – undo
633 633
         // Return an array of invoice items.
634 634
         $items = array();
635 635
 
636
-        foreach ( $invoice->get_items() as $item_id => $item ) {
637
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
636
+        foreach ($invoice->get_items() as $item_id => $item) {
637
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
638 638
         }
639 639
 
640
-        wp_send_json_success( compact( 'items', 'alert' ) );
640
+        wp_send_json_success(compact('items', 'alert'));
641 641
     }
642 642
 
643 643
     /**
@@ -646,15 +646,15 @@  discard block
 block discarded – undo
646 646
     public static function get_invoicing_items() {
647 647
 
648 648
         // Verify nonce.
649
-        check_ajax_referer( 'wpinv-nonce' );
649
+        check_ajax_referer('wpinv-nonce');
650 650
 
651
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
651
+        if (!wpinv_current_user_can_manage_invoicing()) {
652 652
             exit;
653 653
         }
654 654
 
655 655
         // We need a search term.
656
-        if ( empty( $_GET['search'] ) ) {
657
-            wp_send_json_success( array() );
656
+        if (empty($_GET['search'])) {
657
+            wp_send_json_success(array());
658 658
         }
659 659
 
660 660
         // Retrieve items.
@@ -663,8 +663,8 @@  discard block
 block discarded – undo
663 663
             'orderby'        => 'title',
664 664
             'order'          => 'ASC',
665 665
             'posts_per_page' => -1,
666
-            'post_status'    => array( 'publish' ),
667
-            's'              => trim( $_GET['search'] ),
666
+            'post_status'    => array('publish'),
667
+            's'              => trim($_GET['search']),
668 668
             'meta_query'     => array(
669 669
                 array(
670 670
                     'key'       => '_wpinv_type',
@@ -674,22 +674,22 @@  discard block
 block discarded – undo
674 674
             )
675 675
         );
676 676
 
677
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
677
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
678 678
         $data  = array();
679 679
 
680 680
 
681
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
681
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
682 682
 
683
-        foreach ( $items as $item ) {
684
-            $item      = new GetPaid_Form_Item( $item );
683
+        foreach ($items as $item) {
684
+            $item = new GetPaid_Form_Item($item);
685 685
             $data[] = array(
686 686
                 'id'        => (int) $item->get_id(),
687
-                'text'      => strip_tags( $item->get_name() ),
688
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
687
+                'text'      => strip_tags($item->get_name()),
688
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
689 689
             );
690 690
         }
691 691
 
692
-        wp_send_json_success( $data );
692
+        wp_send_json_success($data);
693 693
 
694 694
     }
695 695
 
@@ -699,24 +699,24 @@  discard block
 block discarded – undo
699 699
     public static function get_aui_states_field() {
700 700
 
701 701
         // Verify nonce.
702
-        check_ajax_referer( 'wpinv-nonce' );
702
+        check_ajax_referer('wpinv-nonce');
703 703
 
704 704
         // We need a country.
705
-        if ( empty( $_GET['country'] ) ) {
705
+        if (empty($_GET['country'])) {
706 706
             exit;
707 707
         }
708 708
 
709
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
710
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
709
+        $states = wpinv_get_country_states(trim($_GET['country']));
710
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
711 711
 
712
-        if ( empty( $states ) ) {
712
+        if (empty($states)) {
713 713
 
714 714
             $html = aui()->input(
715 715
                 array(
716 716
                     'type'        => 'text',
717 717
                     'id'          => 'wpinv_state',
718 718
                     'name'        => 'wpinv_state',
719
-                    'label'       => __( 'State', 'invoicing' ),
719
+                    'label'       => __('State', 'invoicing'),
720 720
                     'label_type'  => 'vertical',
721 721
                     'placeholder' => 'Liège',
722 722
                     'class'       => 'form-control-sm',
@@ -730,9 +730,9 @@  discard block
 block discarded – undo
730 730
                 array(
731 731
                     'id'          => 'wpinv_state',
732 732
                     'name'        => 'wpinv_state',
733
-                    'label'       => __( 'State', 'invoicing' ),
733
+                    'label'       => __('State', 'invoicing'),
734 734
                     'label_type'  => 'vertical',
735
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
735
+                    'placeholder' => __('Select a state', 'invoicing'),
736 736
                     'class'       => 'form-control-sm',
737 737
                     'value'       => $state,
738 738
                     'options'     => $states,
@@ -746,7 +746,7 @@  discard block
 block discarded – undo
746 746
         wp_send_json_success(
747 747
             array(
748 748
                 'html'   => $html,
749
-                'select' => ! empty ( $states )
749
+                'select' => !empty ($states)
750 750
             )
751 751
         );
752 752
 
@@ -760,11 +760,11 @@  discard block
 block discarded – undo
760 760
     public static function payment_form_refresh_prices() {
761 761
 
762 762
         // Check nonce.
763
-        check_ajax_referer( 'getpaid_form_nonce' );
763
+        check_ajax_referer('getpaid_form_nonce');
764 764
 
765 765
         // ... form fields...
766
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
767
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
766
+        if (empty($_POST['getpaid_payment_form_submission'])) {
767
+            _e('Error: Reload the page and try again.', 'invoicing');
768 768
             exit;
769 769
         }
770 770
 
@@ -772,18 +772,18 @@  discard block
 block discarded – undo
772 772
         $submission = new GetPaid_Payment_Form_Submission();
773 773
 
774 774
         // Do we have an error?
775
-        if ( ! empty( $submission->last_error ) ) {
775
+        if (!empty($submission->last_error)) {
776 776
             echo $submission->last_error;
777 777
             exit;
778 778
         }
779 779
 
780 780
         // Prepare the response.
781
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
781
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
782 782
         
783 783
         // Filter the response.
784
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
784
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
785 785
 
786
-        wp_send_json_success( $response );
786
+        wp_send_json_success($response);
787 787
     }
788 788
 
789 789
 }
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 1 patch
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return string
25 25
  */
26
-function getpaid_get_ip_country( $ip_address = '' ) {
27
-    $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true );
26
+function getpaid_get_ip_country($ip_address = '') {
27
+    $country = GetPaid_Geolocation::geolocate_ip($ip_address, true);
28 28
     return $country['country'];
29 29
 }
30 30
 
@@ -34,59 +34,59 @@  discard block
 block discarded – undo
34 34
  * @param string $country The country code to sanitize
35 35
  * @return array
36 36
  */
37
-function wpinv_sanitize_country( $country ) {
37
+function wpinv_sanitize_country($country) {
38 38
 
39 39
 	// Enure the country is specified
40
-    if ( empty( $country ) ) {
40
+    if (empty($country)) {
41 41
         $country = wpinv_get_default_country();
42 42
     }
43
-    return trim( wpinv_utf8_strtoupper( $country ) );
43
+    return trim(wpinv_utf8_strtoupper($country));
44 44
 
45 45
 }
46 46
 
47
-function wpinv_is_base_country( $country ) {
47
+function wpinv_is_base_country($country) {
48 48
     $base_country = wpinv_get_default_country();
49 49
     
50
-    if ( $base_country === 'UK' ) {
50
+    if ($base_country === 'UK') {
51 51
         $base_country = 'GB';
52 52
     }
53
-    if ( $country == 'UK' ) {
53
+    if ($country == 'UK') {
54 54
         $country = 'GB';
55 55
     }
56 56
 
57
-    return ( $country && $country === $base_country ) ? true : false;
57
+    return ($country && $country === $base_country) ? true : false;
58 58
 }
59 59
 
60
-function wpinv_country_name( $country_code = '' ) { 
60
+function wpinv_country_name($country_code = '') { 
61 61
     $countries = wpinv_get_country_list();
62 62
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
63
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
63
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
64 64
 
65
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
65
+    return apply_filters('wpinv_country_name', $country, $country_code);
66 66
 }
67 67
 
68 68
 function wpinv_get_default_state() {
69
-	$state = wpinv_get_option( 'default_state', '' );
69
+	$state = wpinv_get_option('default_state', '');
70 70
 
71
-	return apply_filters( 'wpinv_default_state', $state );
71
+	return apply_filters('wpinv_default_state', $state);
72 72
 }
73 73
 
74
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
74
+function wpinv_state_name($state_code = '', $country_code = '') {
75 75
     $state = $state_code;
76 76
     
77
-    if ( !empty( $country_code ) ) {
78
-        $states = wpinv_get_country_states( $country_code );
77
+    if (!empty($country_code)) {
78
+        $states = wpinv_get_country_states($country_code);
79 79
         
80
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
80
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
81 81
     }
82 82
 
83
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
83
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
84 84
 }
85 85
 
86 86
 function wpinv_store_address() {
87
-    $address = wpinv_get_option( 'store_address', '' );
87
+    $address = wpinv_get_option('store_address', '');
88 88
 
89
-    return apply_filters( 'wpinv_store_address', $address );
89
+    return apply_filters('wpinv_store_address', $address);
90 90
 }
91 91
 
92 92
 /**
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  *
95 95
  * @param WPInv_Invoice $invoice
96 96
  */
97
-function getpaid_maybe_add_default_address( &$invoice ) {
97
+function getpaid_maybe_add_default_address(&$invoice) {
98 98
 
99 99
     $user_id = $invoice->get_user_id();
100 100
 
101 101
     // Abort if the invoice belongs to no one.
102
-    if ( empty( $user_id ) ) {
102
+    if (empty($user_id)) {
103 103
         return;
104 104
     }
105 105
 
106 106
     // Fill in defaults whenever necessary.
107
-    foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) {
107
+    foreach (wpinv_get_user_address($user_id) as $key => $value) {
108 108
 
109
-        if ( is_callable( $invoice, "get_$key" ) ) {
110
-            $current = call_user_func( array( $invoice, "get_$key" ) );
109
+        if (is_callable($invoice, "get_$key")) {
110
+            $current = call_user_func(array($invoice, "get_$key"));
111 111
 
112
-            if ( empty( $current ) ) {
112
+            if (empty($current)) {
113 113
                 $method = "set_$key";
114
-                $invoice->$method( $value );
114
+                $invoice->$method($value);
115 115
             }
116 116
 
117 117
         }
@@ -130,16 +130,16 @@  discard block
 block discarded – undo
130 130
     return apply_filters(
131 131
         'getpaid_user_address_fields',
132 132
         array(
133
-            'first_name' => __( 'First Name', 'invoicing' ),
134
-            'last_name'  => __( 'Last Name', 'invoicing' ),
135
-            'country'    => __( 'Country', 'invoicing' ),
136
-            'state'      => __( 'State', 'invoicing' ),
137
-            'city'       => __( 'City', 'invoicing' ),
138
-            'zip'        => __( 'Zip/Postal Code', 'invoicing' ),
139
-            'address'    => __( 'Address', 'invoicing' ),
140
-            'phone'      => __( 'Phone Number', 'invoicing' ),
141
-            'company'    => __( 'Company', 'invoicing' ),
142
-            'vat_number' => __( 'VAT Number', 'invoicing' ),
133
+            'first_name' => __('First Name', 'invoicing'),
134
+            'last_name'  => __('Last Name', 'invoicing'),
135
+            'country'    => __('Country', 'invoicing'),
136
+            'state'      => __('State', 'invoicing'),
137
+            'city'       => __('City', 'invoicing'),
138
+            'zip'        => __('Zip/Postal Code', 'invoicing'),
139
+            'address'    => __('Address', 'invoicing'),
140
+            'phone'      => __('Phone Number', 'invoicing'),
141
+            'company'    => __('Company', 'invoicing'),
142
+            'vat_number' => __('VAT Number', 'invoicing'),
143 143
         )
144 144
     );
145 145
 
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
  * 
151 151
  * @return bool
152 152
  */
153
-function getpaid_is_address_field_whitelisted( $key ) {
154
-    return array_key_exists( $key, getpaid_user_address_fields() );
153
+function getpaid_is_address_field_whitelisted($key) {
154
+    return array_key_exists($key, getpaid_user_address_fields());
155 155
 }
156 156
 
157 157
 /**
@@ -161,24 +161,24 @@  discard block
 block discarded – undo
161 161
  *
162 162
  * @param WPInv_Invoice $invoice
163 163
  */
164
-function getpaid_save_invoice_user_address( $invoice ) {
164
+function getpaid_save_invoice_user_address($invoice) {
165 165
 
166 166
     // Retrieve the invoice.
167
-    $invoice = wpinv_get_invoice( $invoice );
167
+    $invoice = wpinv_get_invoice($invoice);
168 168
 
169 169
     // Abort if it does not exist.
170
-    if ( empty( $invoice ) ) {
170
+    if (empty($invoice)) {
171 171
         return;
172 172
     }
173 173
 
174
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
174
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
175 175
 
176
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
177
-            $value = call_user_func( array( $invoice, "get_$field" ) );
176
+        if (is_callable(array($invoice, "get_$field"))) {
177
+            $value = call_user_func(array($invoice, "get_$field"));
178 178
 
179 179
             // Only save if it is not empty.
180
-            if ( ! empty( $value ) ) {
181
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
180
+            if (!empty($value)) {
181
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
182 182
             }
183 183
 
184 184
         }
@@ -186,8 +186,8 @@  discard block
 block discarded – undo
186 186
     }
187 187
 
188 188
 }
189
-add_action( 'getpaid_new_invoice', 'getpaid_save_invoice_user_address' );
190
-add_action( 'getpaid_update_invoice', 'getpaid_save_invoice_user_address' );
189
+add_action('getpaid_new_invoice', 'getpaid_save_invoice_user_address');
190
+add_action('getpaid_update_invoice', 'getpaid_save_invoice_user_address');
191 191
 
192 192
 /**
193 193
  * Retrieves a saved user address.
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
  * @param bool $with_default Whether or not we should use the default country and state.
197 197
  * @return array
198 198
  */
199
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
199
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
200 200
 
201 201
     // Prepare the user id.
202
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
203
-    $user_info = get_userdata( $user_id );
202
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
203
+    $user_info = get_userdata($user_id);
204 204
 
205 205
     // Abort if non exists.
206
-    if ( empty( $user_info ) ) {
206
+    if (empty($user_info)) {
207 207
         return array();
208 208
     }
209 209
 
@@ -213,11 +213,11 @@  discard block
 block discarded – undo
213 213
         'email'   => $user_info->user_email,
214 214
     );
215 215
 
216
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
217
-        $address[$field] = getpaid_get_user_address_field( $user_id, $field );
216
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
217
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
218 218
     }
219 219
 
220
-    if ( ! $with_default ) {
220
+    if (!$with_default) {
221 221
         return $address;
222 222
     }
223 223
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
         'state'      => wpinv_get_default_country(),
229 229
     );
230 230
 
231
-    return getpaid_array_merge_if_empty( $address, $defaults );
231
+    return getpaid_array_merge_if_empty($address, $defaults);
232 232
 
233 233
 }
234 234
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
  * @param string $field The field to use.
240 240
  * @return string|null
241 241
  */
242
-function getpaid_get_user_address_field( $user_id, $field ) {
242
+function getpaid_get_user_address_field($user_id, $field) {
243 243
 
244 244
     $prefixes = array(
245 245
         '_wpinv_',
@@ -247,15 +247,15 @@  discard block
 block discarded – undo
247 247
         ''
248 248
     );
249 249
 
250
-    foreach ( $prefixes as $prefix ) {
250
+    foreach ($prefixes as $prefix) {
251 251
 
252 252
         // Meta table.
253
-        $value = get_user_meta( $user_id, $prefix . $field, true );
253
+        $value = get_user_meta($user_id, $prefix . $field, true);
254 254
         
255 255
         // UWP table.
256
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
256
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
257 257
 
258
-        if ( ! empty( $value ) ) {
258
+        if (!empty($value)) {
259 259
             return $value;
260 260
         }
261 261
 
@@ -272,16 +272,16 @@  discard block
 block discarded – undo
272 272
  * @param string $return What to return.
273 273
  * @return array
274 274
  */
275
-function wpinv_get_continents( $return = 'all' ) {
275
+function wpinv_get_continents($return = 'all') {
276 276
 
277
-    $continents = wpinv_get_data( 'continents' );
277
+    $continents = wpinv_get_data('continents');
278 278
 
279
-    switch( $return ) {
279
+    switch ($return) {
280 280
         case 'name' :
281
-            return wp_list_pluck( $continents, 'name' );
281
+            return wp_list_pluck($continents, 'name');
282 282
             break;
283 283
         case 'countries' :
284
-            return wp_list_pluck( $continents, 'countries' );
284
+            return wp_list_pluck($continents, 'countries');
285 285
             break;
286 286
         default :
287 287
             return $continents;
@@ -297,12 +297,12 @@  discard block
 block discarded – undo
297 297
  * @param string $country Country code. If no code is specified, defaults to the default country.
298 298
  * @return string
299 299
  */
300
-function wpinv_get_continent_code_for_country( $country = false ) {
300
+function wpinv_get_continent_code_for_country($country = false) {
301 301
 
302
-    $country = wpinv_sanitize_country( $country );
302
+    $country = wpinv_sanitize_country($country);
303 303
     
304
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
305
-		if ( false !== array_search( $country, $countries, true ) ) {
304
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
305
+		if (false !== array_search($country, $countries, true)) {
306 306
 			return $continent_code;
307 307
 		}
308 308
 	}
@@ -318,13 +318,13 @@  discard block
 block discarded – undo
318 318
  * @param string $country Country code. If no code is specified, defaults to the default country.
319 319
  * @return array
320 320
  */
321
-function wpinv_get_country_calling_code( $country = null) {
321
+function wpinv_get_country_calling_code($country = null) {
322 322
 
323
-    $country = wpinv_sanitize_country( $country );
324
-    $codes   = wpinv_get_data( 'phone-codes' );
325
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
323
+    $country = wpinv_sanitize_country($country);
324
+    $codes   = wpinv_get_data('phone-codes');
325
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
326 326
 
327
-    if ( is_array( $code ) ) {
327
+    if (is_array($code)) {
328 328
         return $code[0];
329 329
     }
330 330
     return $code;
@@ -337,8 +337,8 @@  discard block
 block discarded – undo
337 337
  * @param bool $first_empty Whether or not the first item in the list should be empty
338 338
  * @return array
339 339
  */
340
-function wpinv_get_country_list( $first_empty = false ) {
341
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
340
+function wpinv_get_country_list($first_empty = false) {
341
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
342 342
 }
343 343
 
344 344
 /**
@@ -348,22 +348,22 @@  discard block
 block discarded – undo
348 348
  * @param bool $first_empty Whether or not the first item in the list should be empty
349 349
  * @return array
350 350
  */
351
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
351
+function wpinv_get_country_states($country = null, $first_empty = false) {
352 352
     
353 353
     // Prepare the country.
354
-    $country = wpinv_sanitize_country( $country );
354
+    $country = wpinv_sanitize_country($country);
355 355
 
356 356
     // Fetch all states.
357
-    $all_states = wpinv_get_data( 'states' );
357
+    $all_states = wpinv_get_data('states');
358 358
 
359 359
     // Fetch the specified country's states.
360
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
361
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
362
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
360
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
361
+    $states     = apply_filters("wpinv_{$country}_states", $states);
362
+    $states     = apply_filters('wpinv_country_states', $states, $country);
363 363
 
364
-    asort( $states );
364
+    asort($states);
365 365
      
366
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
366
+    return wpinv_maybe_add_empty_option($states, $first_empty);
367 367
 }
368 368
 
369 369
 /**
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
  * @return array
374 374
  */
375 375
 function wpinv_get_us_states_list() {
376
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
376
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
377 377
 }
378 378
 
379 379
 /**
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
  * @return array
384 384
  */
385 385
 function wpinv_get_canada_states_list() {
386
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
386
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
387 387
 }
388 388
 
389 389
 /**
@@ -393,7 +393,7 @@  discard block
 block discarded – undo
393 393
  * @return array
394 394
  */
395 395
 function wpinv_get_australia_states_list() {
396
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
396
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
397 397
 }
398 398
 
399 399
 /**
@@ -403,7 +403,7 @@  discard block
 block discarded – undo
403 403
  * @return array
404 404
  */
405 405
 function wpinv_get_bangladesh_states_list() {
406
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
406
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
407 407
 }
408 408
 
409 409
 /**
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
  * @return array
414 414
  */
415 415
 function wpinv_get_brazil_states_list() {
416
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
416
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
417 417
 }
418 418
 
419 419
 /**
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
  * @return array
424 424
  */
425 425
 function wpinv_get_bulgaria_states_list() {
426
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
426
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
427 427
 }
428 428
 
429 429
 /**
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
  * @return array
434 434
  */
435 435
 function wpinv_get_hong_kong_states_list() {
436
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
436
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
437 437
 }
438 438
 
439 439
 /**
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
  * @return array
444 444
  */
445 445
 function wpinv_get_hungary_states_list() {
446
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
446
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
447 447
 }
448 448
 
449 449
 /**
@@ -453,7 +453,7 @@  discard block
 block discarded – undo
453 453
  * @return array
454 454
  */
455 455
 function wpinv_get_japan_states_list() {
456
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
456
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
457 457
 }
458 458
 
459 459
 /**
@@ -463,7 +463,7 @@  discard block
 block discarded – undo
463 463
  * @return array
464 464
  */
465 465
 function wpinv_get_china_states_list() {
466
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
466
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
467 467
 }
468 468
 
469 469
 /**
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
  * @return array
474 474
  */
475 475
 function wpinv_get_new_zealand_states_list() {
476
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
476
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
477 477
 }
478 478
 
479 479
 /**
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
  * @return array
484 484
  */
485 485
 function wpinv_get_peru_states_list() {
486
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
486
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
487 487
 }
488 488
 
489 489
 /**
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
  * @return array
494 494
  */
495 495
 function wpinv_get_indonesia_states_list() {
496
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
496
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
497 497
 }
498 498
 
499 499
 /**
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
  * @return array
504 504
  */
505 505
 function wpinv_get_india_states_list() {
506
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
506
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
507 507
 }
508 508
 
509 509
 /**
@@ -513,7 +513,7 @@  discard block
 block discarded – undo
513 513
  * @return array
514 514
  */
515 515
 function wpinv_get_iran_states_list() {
516
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
516
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
517 517
 }
518 518
 
519 519
 /**
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
  * @return array
524 524
  */
525 525
 function wpinv_get_italy_states_list() {
526
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
526
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
527 527
 }
528 528
 
529 529
 /**
@@ -533,7 +533,7 @@  discard block
 block discarded – undo
533 533
  * @return array
534 534
  */
535 535
 function wpinv_get_malaysia_states_list() {
536
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
536
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
537 537
 }
538 538
 
539 539
 /**
@@ -543,7 +543,7 @@  discard block
 block discarded – undo
543 543
  * @return array
544 544
  */
545 545
 function wpinv_get_mexico_states_list() {
546
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
546
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
547 547
 }
548 548
 
549 549
 /**
@@ -553,7 +553,7 @@  discard block
 block discarded – undo
553 553
  * @return array
554 554
  */
555 555
 function wpinv_get_nepal_states_list() {
556
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
556
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
557 557
 }
558 558
 
559 559
 /**
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
  * @return array
564 564
  */
565 565
 function wpinv_get_south_africa_states_list() {
566
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
566
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
567 567
 }
568 568
 
569 569
 /**
@@ -573,7 +573,7 @@  discard block
 block discarded – undo
573 573
  * @return array
574 574
  */
575 575
 function wpinv_get_thailand_states_list() {
576
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
576
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
577 577
 }
578 578
 
579 579
 /**
@@ -583,7 +583,7 @@  discard block
 block discarded – undo
583 583
  * @return array
584 584
  */
585 585
 function wpinv_get_turkey_states_list() {
586
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
586
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
587 587
 }
588 588
 
589 589
 /**
@@ -593,28 +593,28 @@  discard block
 block discarded – undo
593 593
  * @return array
594 594
  */
595 595
 function wpinv_get_spain_states_list() {
596
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
596
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
597 597
 }
598 598
 
599 599
 function wpinv_get_states_field() {
600
-	if( empty( $_POST['country'] ) ) {
600
+	if (empty($_POST['country'])) {
601 601
 		$_POST['country'] = wpinv_get_default_country();
602 602
 	}
603
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
603
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
604 604
 
605
-	if( !empty( $states ) ) {
606
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
605
+	if (!empty($states)) {
606
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
607 607
         
608 608
         $args = array(
609 609
 			'name'    => $sanitized_field_name,
610 610
 			'id'      => $sanitized_field_name,
611 611
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
612
-			'options' => array_merge( array( '' => '' ), $states ),
612
+			'options' => array_merge(array('' => ''), $states),
613 613
 			'show_option_all'  => false,
614 614
 			'show_option_none' => false
615 615
 		);
616 616
 
617
-		$response = wpinv_html_select( $args );
617
+		$response = wpinv_html_select($args);
618 618
 
619 619
 	} else {
620 620
 		$response = 'nostates';
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
 	return $response;
624 624
 }
625 625
 
626
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
627
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
626
+function wpinv_default_billing_country($country = '', $user_id = 0) {
627
+    $country = !empty($country) ? $country : wpinv_get_default_country();
628 628
     
629
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
629
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
630 630
 }
631 631
 
632 632
 /**
@@ -638,7 +638,7 @@  discard block
 block discarded – undo
638 638
  */
639 639
 function wpinv_get_address_formats() {
640 640
 
641
-		return apply_filters( 'wpinv_localisation_address_formats',
641
+		return apply_filters('wpinv_localisation_address_formats',
642 642
 			array(
643 643
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
644 644
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -687,9 +687,9 @@  discard block
 block discarded – undo
687 687
  * @see `wpinv_get_invoice_address_replacements`
688 688
  * @return string
689 689
  */
690
-function wpinv_get_full_address_format( $country = false) {
690
+function wpinv_get_full_address_format($country = false) {
691 691
 
692
-    if( empty( $country ) ) {
692
+    if (empty($country)) {
693 693
         $country = wpinv_get_default_country();
694 694
     }
695 695
 
@@ -697,7 +697,7 @@  discard block
 block discarded – undo
697 697
 	$formats = wpinv_get_address_formats();
698 698
 
699 699
 	// Get format for the specified country.
700
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
700
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
701 701
     
702 702
     /**
703 703
 	 * Filters the address format to use on Invoices.
@@ -709,7 +709,7 @@  discard block
 block discarded – undo
709 709
 	 * @param string $format  The address format to use.
710 710
      * @param string $country The country who's address format is being retrieved.
711 711
 	 */
712
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
712
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
713 713
 }
714 714
 
715 715
 /**
@@ -720,7 +720,7 @@  discard block
 block discarded – undo
720 720
  * @param array $billing_details customer's billing details
721 721
  * @return array
722 722
  */
723
-function wpinv_get_invoice_address_replacements( $billing_details ) {
723
+function wpinv_get_invoice_address_replacements($billing_details) {
724 724
 
725 725
     $default_args = array(
726 726
         'address'           => '',
@@ -733,22 +733,22 @@  discard block
 block discarded – undo
733 733
 		'company'           => '',
734 734
     );
735 735
 
736
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
736
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
737 737
     $state   = $args['state'];
738 738
     $country = $args['country'];
739 739
 
740 740
     // Handle full country name.
741
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
741
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
742 742
 
743 743
     // Handle full state name.
744
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
744
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
745 745
 
746 746
     $args['postcode']    = $args['zip'];
747 747
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
748 748
     $args['state']       = $full_state;
749 749
     $args['state_code']  = $state;
750 750
     $args['country']     = $full_country;
751
-    $args['country_code']= $country;
751
+    $args['country_code'] = $country;
752 752
 
753 753
     /**
754 754
 	 * Filters the address format replacements to use on Invoices.
@@ -759,14 +759,14 @@  discard block
 block discarded – undo
759 759
 	 * @param array $replacements  The address replacements to use.
760 760
      * @param array $billing_details  The billing details to use.
761 761
 	 */
762
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
762
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
763 763
 
764 764
     $return = array();
765 765
 
766
-    foreach( $replacements as $key => $value ) {
767
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
766
+    foreach ($replacements as $key => $value) {
767
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
768 768
         $return['{{' . $key . '}}'] = $value;
769
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
769
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
770 770
     }
771 771
 
772 772
     return $return;
@@ -780,6 +780,6 @@  discard block
 block discarded – undo
780 780
  * @since 1.0.14
781 781
  * @return string
782 782
  */
783
-function wpinv_trim_formatted_address_line( $line ) {
784
-	return trim( $line, ', ' );
783
+function wpinv_trim_formatted_address_line($line) {
784
+	return trim($line, ', ');
785 785
 }
786 786
\ No newline at end of file
Please login to merge, or discard this patch.
admin/meta-boxes/class-getpaid-meta-box-invoice-shipping-address.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -15,22 +15,22 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Meta_Box_Invoice_Shipping_Address {
17 17
 
18
-	/**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
23
-	public static function output( $post ) {
18
+    /**
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23
+    public static function output( $post ) {
24 24
 
25
-		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
25
+        // Retrieve shipping address.
26
+        $shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
27 27
 
28
-		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
30
-			return;
31
-		}
28
+        // Abort if it is invalid.
29
+        if ( ! is_array( $shipping_address ) ) {
30
+            return;
31
+        }
32 32
 
33
-		?>
33
+        ?>
34 34
 
35 35
 		<div class="bsui">
36 36
 
@@ -55,31 +55,31 @@  discard block
 block discarded – undo
55 55
 
56 56
 		<?php
57 57
 
58
-	}
58
+    }
59 59
 
60
-	/**
61
-	 * Prepares a value.
62
-	 *
63
-	 * @param array $address
64
-	 * @param string $key
65
-	 * @return string
66
-	 */
67
-	public static function prepare_for_display( $address, $key ) {
60
+    /**
61
+     * Prepares a value.
62
+     *
63
+     * @param array $address
64
+     * @param string $key
65
+     * @return string
66
+     */
67
+    public static function prepare_for_display( $address, $key ) {
68 68
 
69
-		// Prepare the value.
70
-		$value = $address[ $key ];
69
+        // Prepare the value.
70
+        $value = $address[ $key ];
71 71
 
72
-		if ( $key == 'country' ) {
73
-			$value = wpinv_country_name( $value );
74
-		}
72
+        if ( $key == 'country' ) {
73
+            $value = wpinv_country_name( $value );
74
+        }
75 75
 
76
-		if ( $key == 'state' ) {
77
-			$country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
-			$value = wpinv_state_name( $value, $country );
79
-		}
76
+        if ( $key == 'state' ) {
77
+            $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
+            $value = wpinv_state_name( $value, $country );
79
+        }
80 80
 
81
-		return sanitize_text_field( $value );
81
+        return sanitize_text_field( $value );
82 82
 
83
-	}
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit; // Exit if accessed directly
11 11
 }
12 12
 
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param WP_Post $post
22 22
 	 */
23
-	public static function output( $post ) {
23
+	public static function output($post) {
24 24
 
25 25
 		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
26
+		$shipping_address = get_post_meta($post->ID, 'shipping_address', true);
27 27
 
28 28
 		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
29
+		if (!is_array($shipping_address)) {
30 30
 			return;
31 31
 		}
32 32
 
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
 
35 35
 		<div class="bsui">
36 36
 
37
-			<?php foreach ( getpaid_user_address_fields() as $key => $label ) : ?>
37
+			<?php foreach (getpaid_user_address_fields() as $key => $label) : ?>
38 38
 
39
-					<?php if ( ! empty( $shipping_address[ $key ] ) ) : ?>
39
+					<?php if (!empty($shipping_address[$key])) : ?>
40 40
 
41 41
 						<div class="form-group form-row">
42 42
 							<div class="col">
43
-								<span style="font-weight: 600"><?php echo sanitize_text_field( $label ); ?>:</span>
43
+								<span style="font-weight: 600"><?php echo sanitize_text_field($label); ?>:</span>
44 44
 							</div>
45 45
 							<div class="col">
46
-								<?php echo self::prepare_for_display( $shipping_address, $key ); ?>
46
+								<?php echo self::prepare_for_display($shipping_address, $key); ?>
47 47
 							</div>
48 48
 						</div>
49 49
 
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
 	 * @param string $key
65 65
 	 * @return string
66 66
 	 */
67
-	public static function prepare_for_display( $address, $key ) {
67
+	public static function prepare_for_display($address, $key) {
68 68
 
69 69
 		// Prepare the value.
70
-		$value = $address[ $key ];
70
+		$value = $address[$key];
71 71
 
72
-		if ( $key == 'country' ) {
73
-			$value = wpinv_country_name( $value );
72
+		if ($key == 'country') {
73
+			$value = wpinv_country_name($value);
74 74
 		}
75 75
 
76
-		if ( $key == 'state' ) {
77
-			$country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
-			$value = wpinv_state_name( $value, $country );
76
+		if ($key == 'state') {
77
+			$country = isset($address['country']) ? $address['country'] : wpinv_get_default_country();
78
+			$value = wpinv_state_name($value, $country);
79 79
 		}
80 80
 
81
-		return sanitize_text_field( $value );
81
+		return sanitize_text_field($value);
82 82
 
83 83
 	}
84 84
 
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +224 added lines, -224 removed lines patch added patch discarded remove patch
@@ -12,240 +12,240 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
15
+    /**
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
21 21
 
22 22
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
44
-		global $wpinv_euvat;
45
-
46
-		// For invoices...
47
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
-			$invoice = new WPInv_Invoice( $post );
49
-
50
-			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
-
53
-				add_meta_box(
54
-					'wpinv-mb-resend-invoice',
55
-					sprintf(
56
-						__( 'Resend %s', 'invoicing' ),
57
-						ucfirst( $invoice->get_type() )
58
-					),
59
-					'GetPaid_Meta_Box_Resend_Invoice::output',
60
-					$post_type,
61
-					'side',
62
-					'low'
63
-				);
64
-
65
-			}
66
-
67
-			// Subscriptions.
68
-			$subscription = getpaid_get_invoice_subscription( $invoice );
69
-			if ( ! empty( $subscription ) ) {
70
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
72
-			}
73
-
74
-			// Invoice details.
75
-			add_meta_box(
76
-				'wpinv-details',
77
-				sprintf(
78
-					__( '%s Details', 'invoicing' ),
79
-					ucfirst( $invoice->get_type() )
80
-				),
81
-				'GetPaid_Meta_Box_Invoice_Details::output',
82
-				$post_type,
83
-				'side'
84
-			);
85
-
86
-			// Payment details.
87
-			if ( ! $invoice->is_draft() ) {
88
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
89
-			}
90
-
91
-			// Billing details.
92
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
26
+
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
+
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
+
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
+
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
39
+
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
44
+        global $wpinv_euvat;
45
+
46
+        // For invoices...
47
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
+            $invoice = new WPInv_Invoice( $post );
49
+
50
+            // Resend invoice.
51
+            if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
52
+
53
+                add_meta_box(
54
+                    'wpinv-mb-resend-invoice',
55
+                    sprintf(
56
+                        __( 'Resend %s', 'invoicing' ),
57
+                        ucfirst( $invoice->get_type() )
58
+                    ),
59
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
60
+                    $post_type,
61
+                    'side',
62
+                    'low'
63
+                );
64
+
65
+            }
66
+
67
+            // Subscriptions.
68
+            $subscription = getpaid_get_invoice_subscription( $invoice );
69
+            if ( ! empty( $subscription ) ) {
70
+                add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
+                add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
72
+            }
73
+
74
+            // Invoice details.
75
+            add_meta_box(
76
+                'wpinv-details',
77
+                sprintf(
78
+                    __( '%s Details', 'invoicing' ),
79
+                    ucfirst( $invoice->get_type() )
80
+                ),
81
+                'GetPaid_Meta_Box_Invoice_Details::output',
82
+                $post_type,
83
+                'side'
84
+            );
85
+
86
+            // Payment details.
87
+            if ( ! $invoice->is_draft() ) {
88
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
89
+            }
90
+
91
+            // Billing details.
92
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
93 93
 			
94
-			// Invoice items.
95
-			add_meta_box(
96
-				'wpinv-items',
97
-				sprintf(
98
-					__( '%s Items', 'invoicing' ),
99
-					ucfirst( $invoice->get_type() )
100
-				),
101
-				'GetPaid_Meta_Box_Invoice_Items::output',
102
-				$post_type,
103
-				'normal',
104
-				'high'
105
-			);
94
+            // Invoice items.
95
+            add_meta_box(
96
+                'wpinv-items',
97
+                sprintf(
98
+                    __( '%s Items', 'invoicing' ),
99
+                    ucfirst( $invoice->get_type() )
100
+                ),
101
+                'GetPaid_Meta_Box_Invoice_Items::output',
102
+                $post_type,
103
+                'normal',
104
+                'high'
105
+            );
106 106
 			
107
-			// Invoice notes.
108
-			add_meta_box(
109
-				'wpinv-notes',
110
-				sprintf(
111
-					__( '%s Notes', 'invoicing' ),
112
-					ucfirst( $invoice->get_type() )
113
-				),
114
-				'WPInv_Meta_Box_Notes::output',
115
-				$post_type,
116
-				'side',
117
-				'low'
118
-			);
119
-
120
-			// Shipping Address.
121
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'shipping_address', true ) ) {
122
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
123
-			}
124
-
125
-			// Payment form information.
126
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
127
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
128
-			}
129
-
130
-		}
131
-
132
-		// For payment forms.
133
-		if ( $post_type == 'wpi_payment_form' ) {
134
-
135
-			// Design payment form.
136
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
137
-
138
-			// Payment form information.
139
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
140
-
141
-		}
142
-
143
-		// For invoice items.
144
-		if ( $post_type == 'wpi_item' ) {
145
-
146
-			// Item details.
147
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
148
-
149
-			// If taxes are enabled, register the tax metabox.
150
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
151
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
152
-			}
153
-
154
-			// Item info.
155
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
156
-
157
-		}
158
-
159
-		// For invoice discounts.
160
-		if ( $post_type == 'wpi_discount' ) {
161
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
162
-		}
107
+            // Invoice notes.
108
+            add_meta_box(
109
+                'wpinv-notes',
110
+                sprintf(
111
+                    __( '%s Notes', 'invoicing' ),
112
+                    ucfirst( $invoice->get_type() )
113
+                ),
114
+                'WPInv_Meta_Box_Notes::output',
115
+                $post_type,
116
+                'side',
117
+                'low'
118
+            );
119
+
120
+            // Shipping Address.
121
+            if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'shipping_address', true ) ) {
122
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
123
+            }
124
+
125
+            // Payment form information.
126
+            if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
127
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
128
+            }
129
+
130
+        }
131
+
132
+        // For payment forms.
133
+        if ( $post_type == 'wpi_payment_form' ) {
134
+
135
+            // Design payment form.
136
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
137
+
138
+            // Payment form information.
139
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
140
+
141
+        }
142
+
143
+        // For invoice items.
144
+        if ( $post_type == 'wpi_item' ) {
145
+
146
+            // Item details.
147
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
148
+
149
+            // If taxes are enabled, register the tax metabox.
150
+            if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
151
+                add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
152
+            }
153
+
154
+            // Item info.
155
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
156
+
157
+        }
158
+
159
+        // For invoice discounts.
160
+        if ( $post_type == 'wpi_discount' ) {
161
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
162
+        }
163 163
 		
164 164
 
165
-	}
165
+    }
166 166
 
167
-	/**
168
-	 * Remove some metaboxes.
169
-	 */
170
-	public static function remove_meta_boxes() {
171
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
172
-	}
167
+    /**
168
+     * Remove some metaboxes.
169
+     */
170
+    public static function remove_meta_boxes() {
171
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
172
+    }
173 173
 
174
-	/**
175
-	 * Rename other metaboxes.
176
-	 */
177
-	public static function rename_meta_boxes() {
174
+    /**
175
+     * Rename other metaboxes.
176
+     */
177
+    public static function rename_meta_boxes() {
178 178
 		
179
-	}
180
-
181
-	/**
182
-	 * Check if we're saving, then trigger an action based on the post type.
183
-	 *
184
-	 * @param  int    $post_id Post ID.
185
-	 * @param  object $post Post object.
186
-	 */
187
-	public static function save_meta_boxes( $post_id, $post ) {
188
-		$post_id = absint( $post_id );
189
-		$data    = wp_unslash( $_POST );
190
-
191
-		// Do not save for ajax requests.
192
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
193
-			return;
194
-		}
195
-
196
-		// $post_id and $post are required
197
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
198
-			return;
199
-		}
200
-
201
-		// Dont' save meta boxes for revisions or autosaves.
202
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
203
-			return;
204
-		}
205
-
206
-		// Check the nonce.
207
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
208
-			return;
209
-		}
210
-
211
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
212
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
213
-			return;
214
-		}
215
-
216
-		// Check user has permission to edit.
217
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
218
-			return;
219
-		}
220
-
221
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
222
-
223
-			// We need this save event to run once to avoid potential endless loops.
224
-			self::$saved_meta_boxes = true;
225
-
226
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
227
-
228
-		}
229
-
230
-		// Ensure this is our post type.
231
-		$post_types_map = array(
232
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
233
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
234
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
235
-		);
236
-
237
-		// Is this our post type?
238
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
239
-			return;
240
-		}
241
-
242
-		// We need this save event to run once to avoid potential endless loops.
243
-		self::$saved_meta_boxes = true;
179
+    }
180
+
181
+    /**
182
+     * Check if we're saving, then trigger an action based on the post type.
183
+     *
184
+     * @param  int    $post_id Post ID.
185
+     * @param  object $post Post object.
186
+     */
187
+    public static function save_meta_boxes( $post_id, $post ) {
188
+        $post_id = absint( $post_id );
189
+        $data    = wp_unslash( $_POST );
190
+
191
+        // Do not save for ajax requests.
192
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
193
+            return;
194
+        }
195
+
196
+        // $post_id and $post are required
197
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
198
+            return;
199
+        }
200
+
201
+        // Dont' save meta boxes for revisions or autosaves.
202
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
203
+            return;
204
+        }
205
+
206
+        // Check the nonce.
207
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
208
+            return;
209
+        }
210
+
211
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
212
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
213
+            return;
214
+        }
215
+
216
+        // Check user has permission to edit.
217
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
218
+            return;
219
+        }
220
+
221
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
222
+
223
+            // We need this save event to run once to avoid potential endless loops.
224
+            self::$saved_meta_boxes = true;
225
+
226
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
227
+
228
+        }
229
+
230
+        // Ensure this is our post type.
231
+        $post_types_map = array(
232
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
233
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
234
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
235
+        );
236
+
237
+        // Is this our post type?
238
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
239
+            return;
240
+        }
241
+
242
+        // We need this save event to run once to avoid potential endless loops.
243
+        self::$saved_meta_boxes = true;
244 244
 		
245
-		// Save the post.
246
-		$class = $post_types_map[ $post->post_type ];
247
-		$class::save( $post_id, $_POST, $post );
245
+        // Save the post.
246
+        $class = $post_types_map[ $post->post_type ];
247
+        $class::save( $post_id, $_POST, $post );
248 248
 
249
-	}
249
+    }
250 250
 
251 251
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Metaboxes Admin Class
@@ -25,36 +25,36 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 		global $wpinv_euvat;
45 45
 
46 46
 		// For invoices...
47
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
48
-			$invoice = new WPInv_Invoice( $post );
47
+		if (getpaid_is_invoice_post_type($post_type)) {
48
+			$invoice = new WPInv_Invoice($post);
49 49
 
50 50
 			// Resend invoice.
51
-			if ( ! $invoice->is_draft() && ! $invoice->is_paid() ) {
51
+			if (!$invoice->is_draft() && !$invoice->is_paid()) {
52 52
 
53 53
 				add_meta_box(
54 54
 					'wpinv-mb-resend-invoice',
55 55
 					sprintf(
56
-						__( 'Resend %s', 'invoicing' ),
57
-						ucfirst( $invoice->get_type() )
56
+						__('Resend %s', 'invoicing'),
57
+						ucfirst($invoice->get_type())
58 58
 					),
59 59
 					'GetPaid_Meta_Box_Resend_Invoice::output',
60 60
 					$post_type,
@@ -65,18 +65,18 @@  discard block
 block discarded – undo
65 65
 			}
66 66
 
67 67
 			// Subscriptions.
68
-			$subscription = getpaid_get_invoice_subscription( $invoice );
69
-			if ( ! empty( $subscription ) ) {
70
-				add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
71
-				add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
68
+			$subscription = getpaid_get_invoice_subscription($invoice);
69
+			if (!empty($subscription)) {
70
+				add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
71
+				add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
72 72
 			}
73 73
 
74 74
 			// Invoice details.
75 75
 			add_meta_box(
76 76
 				'wpinv-details',
77 77
 				sprintf(
78
-					__( '%s Details', 'invoicing' ),
79
-					ucfirst( $invoice->get_type() )
78
+					__('%s Details', 'invoicing'),
79
+					ucfirst($invoice->get_type())
80 80
 				),
81 81
 				'GetPaid_Meta_Box_Invoice_Details::output',
82 82
 				$post_type,
@@ -84,19 +84,19 @@  discard block
 block discarded – undo
84 84
 			);
85 85
 
86 86
 			// Payment details.
87
-			if ( ! $invoice->is_draft() ) {
88
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
87
+			if (!$invoice->is_draft()) {
88
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
89 89
 			}
90 90
 
91 91
 			// Billing details.
92
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
92
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
93 93
 			
94 94
 			// Invoice items.
95 95
 			add_meta_box(
96 96
 				'wpinv-items',
97 97
 				sprintf(
98
-					__( '%s Items', 'invoicing' ),
99
-					ucfirst( $invoice->get_type() )
98
+					__('%s Items', 'invoicing'),
99
+					ucfirst($invoice->get_type())
100 100
 				),
101 101
 				'GetPaid_Meta_Box_Invoice_Items::output',
102 102
 				$post_type,
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 			add_meta_box(
109 109
 				'wpinv-notes',
110 110
 				sprintf(
111
-					__( '%s Notes', 'invoicing' ),
112
-					ucfirst( $invoice->get_type() )
111
+					__('%s Notes', 'invoicing'),
112
+					ucfirst($invoice->get_type())
113 113
 				),
114 114
 				'WPInv_Meta_Box_Notes::output',
115 115
 				$post_type,
@@ -118,47 +118,47 @@  discard block
 block discarded – undo
118 118
 			);
119 119
 
120 120
 			// Shipping Address.
121
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'shipping_address', true ) ) {
122
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
121
+			if (!empty($post->ID) && get_post_meta($post->ID, 'shipping_address', true)) {
122
+				add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high');
123 123
 			}
124 124
 
125 125
 			// Payment form information.
126
-			if ( ! empty( $post->ID ) && get_post_meta( $post->ID, 'payment_form_data', true ) ) {
127
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
126
+			if (!empty($post->ID) && get_post_meta($post->ID, 'payment_form_data', true)) {
127
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
128 128
 			}
129 129
 
130 130
 		}
131 131
 
132 132
 		// For payment forms.
133
-		if ( $post_type == 'wpi_payment_form' ) {
133
+		if ($post_type == 'wpi_payment_form') {
134 134
 
135 135
 			// Design payment form.
136
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
136
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
137 137
 
138 138
 			// Payment form information.
139
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
139
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
140 140
 
141 141
 		}
142 142
 
143 143
 		// For invoice items.
144
-		if ( $post_type == 'wpi_item' ) {
144
+		if ($post_type == 'wpi_item') {
145 145
 
146 146
 			// Item details.
147
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
147
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
148 148
 
149 149
 			// If taxes are enabled, register the tax metabox.
150
-			if ( $wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes() ) {
151
-				add_meta_box( 'wpinv_item_vat', __( 'VAT / Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
150
+			if ($wpinv_euvat->allow_vat_rules() || $wpinv_euvat->allow_vat_classes()) {
151
+				add_meta_box('wpinv_item_vat', __('VAT / Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
152 152
 			}
153 153
 
154 154
 			// Item info.
155
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
155
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
156 156
 
157 157
 		}
158 158
 
159 159
 		// For invoice discounts.
160
-		if ( $post_type == 'wpi_discount' ) {
161
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
160
+		if ($post_type == 'wpi_discount') {
161
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
162 162
 		}
163 163
 		
164 164
 
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * Remove some metaboxes.
169 169
 	 */
170 170
 	public static function remove_meta_boxes() {
171
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
171
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
172 172
 	}
173 173
 
174 174
 	/**
@@ -184,46 +184,46 @@  discard block
 block discarded – undo
184 184
 	 * @param  int    $post_id Post ID.
185 185
 	 * @param  object $post Post object.
186 186
 	 */
187
-	public static function save_meta_boxes( $post_id, $post ) {
188
-		$post_id = absint( $post_id );
189
-		$data    = wp_unslash( $_POST );
187
+	public static function save_meta_boxes($post_id, $post) {
188
+		$post_id = absint($post_id);
189
+		$data    = wp_unslash($_POST);
190 190
 
191 191
 		// Do not save for ajax requests.
192
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
192
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
193 193
 			return;
194 194
 		}
195 195
 
196 196
 		// $post_id and $post are required
197
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
197
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
198 198
 			return;
199 199
 		}
200 200
 
201 201
 		// Dont' save meta boxes for revisions or autosaves.
202
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
202
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
203 203
 			return;
204 204
 		}
205 205
 
206 206
 		// Check the nonce.
207
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
207
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
208 208
 			return;
209 209
 		}
210 210
 
211 211
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
212
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
212
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
213 213
 			return;
214 214
 		}
215 215
 
216 216
 		// Check user has permission to edit.
217
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
217
+		if (!current_user_can('edit_post', $post_id)) {
218 218
 			return;
219 219
 		}
220 220
 
221
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
221
+		if (getpaid_is_invoice_post_type($post->post_type)) {
222 222
 
223 223
 			// We need this save event to run once to avoid potential endless loops.
224 224
 			self::$saved_meta_boxes = true;
225 225
 
226
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
226
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
227 227
 
228 228
 		}
229 229
 
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 		);
236 236
 
237 237
 		// Is this our post type?
238
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
238
+		if (!isset($post_types_map[$post->post_type])) {
239 239
 			return;
240 240
 		}
241 241
 
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
 		self::$saved_meta_boxes = true;
244 244
 		
245 245
 		// Save the post.
246
-		$class = $post_types_map[ $post->post_type ];
247
-		$class::save( $post_id, $_POST, $post );
246
+		$class = $post_types_map[$post->post_type];
247
+		$class::save($post_id, $_POST, $post);
248 248
 
249 249
 	}
250 250
 
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +473 added lines, -473 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, watermark, 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
-    return 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
+    return 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,30 +572,30 @@  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
 }
581 581
 
582
-function wpinv_html_text( $args = array() ) {
582
+function wpinv_html_text($args = array()) {
583 583
     // Backwards compatibility
584
-    if ( func_num_args() > 1 ) {
584
+    if (func_num_args() > 1) {
585 585
         $args = func_get_args();
586 586
 
587 587
         $name  = $args[0];
588
-        $value = isset( $args[1] ) ? $args[1] : '';
589
-        $label = isset( $args[2] ) ? $args[2] : '';
590
-        $desc  = isset( $args[3] ) ? $args[3] : '';
588
+        $value = isset($args[1]) ? $args[1] : '';
589
+        $label = isset($args[2]) ? $args[2] : '';
590
+        $desc  = isset($args[3]) ? $args[3] : '';
591 591
     }
592 592
 
593 593
     $defaults = array(
594 594
         'id'           => '',
595
-        'name'         => isset( $name )  ? $name  : 'text',
596
-        'value'        => isset( $value ) ? $value : null,
597
-        'label'        => isset( $label ) ? $label : null,
598
-        'desc'         => isset( $desc )  ? $desc  : null,
595
+        'name'         => isset($name) ? $name : 'text',
596
+        'value'        => isset($value) ? $value : null,
597
+        'label'        => isset($label) ? $label : null,
598
+        'desc'         => isset($desc) ? $desc : null,
599 599
         'placeholder'  => '',
600 600
         'class'        => 'regular-text',
601 601
         'disabled'     => false,
@@ -605,51 +605,51 @@  discard block
 block discarded – undo
605 605
         'data'         => false
606 606
     );
607 607
 
608
-    $args = wp_parse_args( $args, $defaults );
608
+    $args = wp_parse_args($args, $defaults);
609 609
 
610
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
610
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
611 611
     $options = '';
612
-    if( $args['required'] ) {
612
+    if ($args['required']) {
613 613
         $options .= ' required="required"';
614 614
     }
615
-    if( $args['readonly'] ) {
615
+    if ($args['readonly']) {
616 616
         $options .= ' readonly';
617 617
     }
618
-    if( $args['readonly'] ) {
618
+    if ($args['readonly']) {
619 619
         $options .= ' readonly';
620 620
     }
621 621
 
622 622
     $data = '';
623
-    if ( !empty( $args['data'] ) ) {
624
-        foreach ( $args['data'] as $key => $value ) {
625
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
623
+    if (!empty($args['data'])) {
624
+        foreach ($args['data'] as $key => $value) {
625
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
626 626
         }
627 627
     }
628 628
 
629
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
630
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
631
-    if ( ! empty( $args['desc'] ) ) {
632
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
629
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
630
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
631
+    if (!empty($args['desc'])) {
632
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
633 633
     }
634 634
 
635
-    $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 ) . '/>';
635
+    $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) . '/>';
636 636
 
637 637
     $output .= '</span>';
638 638
 
639 639
     return $output;
640 640
 }
641 641
 
642
-function wpinv_html_date_field( $args = array() ) {
643
-    if( empty( $args['class'] ) ) {
642
+function wpinv_html_date_field($args = array()) {
643
+    if (empty($args['class'])) {
644 644
         $args['class'] = 'wpiDatepicker';
645
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
645
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
646 646
         $args['class'] .= ' wpiDatepicker';
647 647
     }
648 648
 
649
-    return wpinv_html_text( $args );
649
+    return wpinv_html_text($args);
650 650
 }
651 651
 
652
-function wpinv_html_textarea( $args = array() ) {
652
+function wpinv_html_textarea($args = array()) {
653 653
     $defaults = array(
654 654
         'name'        => 'textarea',
655 655
         'value'       => null,
@@ -660,31 +660,31 @@  discard block
 block discarded – undo
660 660
         'placeholder' => '',
661 661
     );
662 662
 
663
-    $args = wp_parse_args( $args, $defaults );
663
+    $args = wp_parse_args($args, $defaults);
664 664
 
665
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
665
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
666 666
     $disabled = '';
667
-    if( $args['disabled'] ) {
667
+    if ($args['disabled']) {
668 668
         $disabled = ' disabled="disabled"';
669 669
     }
670 670
 
671
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
672
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
673
-    $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>';
671
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
672
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
673
+    $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>';
674 674
 
675
-    if ( ! empty( $args['desc'] ) ) {
676
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
675
+    if (!empty($args['desc'])) {
676
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
677 677
     }
678 678
     $output .= '</span>';
679 679
 
680 680
     return $output;
681 681
 }
682 682
 
683
-function wpinv_html_ajax_user_search( $args = array() ) {
683
+function wpinv_html_ajax_user_search($args = array()) {
684 684
     $defaults = array(
685 685
         'name'        => 'user_id',
686 686
         'value'       => null,
687
-        'placeholder' => __( 'Enter username', 'invoicing' ),
687
+        'placeholder' => __('Enter username', 'invoicing'),
688 688
         'label'       => null,
689 689
         'desc'        => null,
690 690
         'class'       => '',
@@ -693,13 +693,13 @@  discard block
 block discarded – undo
693 693
         'data'        => false
694 694
     );
695 695
 
696
-    $args = wp_parse_args( $args, $defaults );
696
+    $args = wp_parse_args($args, $defaults);
697 697
 
698 698
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
699 699
 
700 700
     $output  = '<span class="wpinv_user_search_wrap">';
701
-        $output .= wpinv_html_text( $args );
702
-        $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>';
701
+        $output .= wpinv_html_text($args);
702
+        $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>';
703 703
     $output .= '</span>';
704 704
 
705 705
     return $output;
@@ -710,20 +710,20 @@  discard block
 block discarded – undo
710 710
  * 
711 711
  * @param string $template the template that is currently being used.
712 712
  */
713
-function wpinv_template( $template ) {
713
+function wpinv_template($template) {
714 714
     global $post;
715 715
 
716
-    if ( ! is_admin() && ( is_single() || is_404() ) && ! empty( $post->ID ) && getpaid_is_invoice_post_type( get_post_type( $post->ID ) ) ) {
716
+    if (!is_admin() && (is_single() || is_404()) && !empty($post->ID) && getpaid_is_invoice_post_type(get_post_type($post->ID))) {
717 717
 
718 718
         // If the user can view this invoice, display it.
719
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
719
+        if (wpinv_user_can_view_invoice($post->ID)) {
720 720
 
721
-            return wpinv_get_template_part( 'wpinv-invoice-print', false, false );
721
+            return wpinv_get_template_part('wpinv-invoice-print', false, false);
722 722
 
723 723
         // Else display an error message.
724 724
         } else {
725 725
 
726
-            return wpinv_get_template_part( 'wpinv-invalid-access', false, false );
726
+            return wpinv_get_template_part('wpinv-invalid-access', false, false);
727 727
 
728 728
         }
729 729
 
@@ -731,46 +731,46 @@  discard block
 block discarded – undo
731 731
 
732 732
     return $template;
733 733
 }
734
-add_filter( 'template_include', 'wpinv_template', 10, 1 );
734
+add_filter('template_include', 'wpinv_template', 10, 1);
735 735
 
736 736
 function wpinv_get_business_address() {
737 737
     $business_address   = wpinv_store_address();
738
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
738
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
739 739
     
740 740
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
741 741
     
742
-    return apply_filters( 'wpinv_get_business_address', $business_address );
742
+    return apply_filters('wpinv_get_business_address', $business_address);
743 743
 }
744 744
 
745 745
 /**
746 746
  * Displays the company address.
747 747
  */
748 748
 function wpinv_display_from_address() {
749
-    wpinv_get_template( 'invoice/company-address.php' );
749
+    wpinv_get_template('invoice/company-address.php');
750 750
 }
751
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_from_address', 10 );
751
+add_action('getpaid_invoice_details_left', 'wpinv_display_from_address', 10);
752 752
 
753
-function wpinv_watermark( $id = 0 ) {
754
-    $output = wpinv_get_watermark( $id );
755
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
753
+function wpinv_watermark($id = 0) {
754
+    $output = wpinv_get_watermark($id);
755
+    return apply_filters('wpinv_get_watermark', $output, $id);
756 756
 }
757 757
 
758
-function wpinv_get_watermark( $id ) {
759
-    if ( !$id > 0 ) {
758
+function wpinv_get_watermark($id) {
759
+    if (!$id > 0) {
760 760
         return NULL;
761 761
     }
762 762
 
763
-    $invoice = wpinv_get_invoice( $id );
763
+    $invoice = wpinv_get_invoice($id);
764 764
     
765
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
766
-        if ( $invoice->is_paid() ) {
767
-            return __( 'Paid', 'invoicing' );
765
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
766
+        if ($invoice->is_paid()) {
767
+            return __('Paid', 'invoicing');
768 768
         }
769
-        if ( $invoice->is_refunded() ) {
770
-            return __( 'Refunded', 'invoicing' );
769
+        if ($invoice->is_refunded()) {
770
+            return __('Refunded', 'invoicing');
771 771
         }
772
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
773
-            return __( 'Cancelled', 'invoicing' );
772
+        if ($invoice->has_status(array('wpi-cancelled'))) {
773
+            return __('Cancelled', 'invoicing');
774 774
         }
775 775
     }
776 776
     
@@ -780,30 +780,30 @@  discard block
 block discarded – undo
780 780
 /**
781 781
  * @deprecated
782 782
  */
783
-function wpinv_display_invoice_details( $invoice ) {
784
-    return getpaid_invoice_meta( $invoice );
783
+function wpinv_display_invoice_details($invoice) {
784
+    return getpaid_invoice_meta($invoice);
785 785
 }
786 786
 
787 787
 /**
788 788
  * Displays invoice meta.
789 789
  */
790
-function getpaid_invoice_meta( $invoice ) {
790
+function getpaid_invoice_meta($invoice) {
791 791
 
792
-    $invoice = new WPInv_Invoice( $invoice );
792
+    $invoice = new WPInv_Invoice($invoice);
793 793
 
794 794
     // Ensure that we have an invoice.
795
-    if ( 0 == $invoice->get_id() ) {
795
+    if (0 == $invoice->get_id()) {
796 796
         return;
797 797
     }
798 798
 
799 799
     // Get the invoice meta.
800
-    $meta = getpaid_get_invoice_meta( $invoice );
800
+    $meta = getpaid_get_invoice_meta($invoice);
801 801
 
802 802
     // Display the meta.
803
-    wpinv_get_template( 'invoice/invoice-meta.php', compact( 'invoice', 'meta' ) );
803
+    wpinv_get_template('invoice/invoice-meta.php', compact('invoice', 'meta'));
804 804
 
805 805
 }
806
-add_action( 'getpaid_invoice_details_right', 'getpaid_invoice_meta', 10 );
806
+add_action('getpaid_invoice_details_right', 'getpaid_invoice_meta', 10);
807 807
 
808 808
 /**
809 809
  * Retrieves the address markup to use on Invoices.
@@ -815,29 +815,29 @@  discard block
 block discarded – undo
815 815
  * @param  string $separator How to separate address lines.
816 816
  * @return string
817 817
  */
818
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
818
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
819 819
 
820 820
     // Retrieve the address markup...
821
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
822
-    $format = wpinv_get_full_address_format( $country );
821
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
822
+    $format = wpinv_get_full_address_format($country);
823 823
 
824 824
     // ... and the replacements.
825
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
825
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
826 826
 
827
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
827
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
828 828
     
829 829
 	// Remove unavailable tags.
830
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
830
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
831 831
 
832 832
     // Clean up white space.
833
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
834
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
833
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
834
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
835 835
     
836 836
     // Break newlines apart and remove empty lines/trim commas and white space.
837
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
837
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
838 838
 
839 839
     // Add html breaks.
840
-	$formatted_address = implode( $separator, $formatted_address );
840
+	$formatted_address = implode($separator, $formatted_address);
841 841
 
842 842
 	// We're done!
843 843
 	return $formatted_address;
@@ -849,88 +849,88 @@  discard block
 block discarded – undo
849 849
  * 
850 850
  * @param WPInv_Invoice $invoice
851 851
  */
852
-function wpinv_display_to_address( $invoice = 0 ) {
853
-    if ( ! empty( $invoice ) ) {
854
-        wpinv_get_template( 'invoice/billing-address.php', compact( 'invoice' ) );
852
+function wpinv_display_to_address($invoice = 0) {
853
+    if (!empty($invoice)) {
854
+        wpinv_get_template('invoice/billing-address.php', compact('invoice'));
855 855
     }
856 856
 }
857
-add_action( 'getpaid_invoice_details_left', 'wpinv_display_to_address', 40 );
857
+add_action('getpaid_invoice_details_left', 'wpinv_display_to_address', 40);
858 858
 
859 859
 
860 860
 /**
861 861
  * Displays invoice line items.
862 862
  */
863
-function wpinv_display_line_items( $invoice_id = 0 ) {
863
+function wpinv_display_line_items($invoice_id = 0) {
864 864
 
865 865
     // Prepare the invoice.
866
-    $invoice = new WPInv_Invoice( $invoice_id );
866
+    $invoice = new WPInv_Invoice($invoice_id);
867 867
 
868 868
     // Abort if there is no invoice.
869
-    if ( 0 == $invoice->get_id() ) {
869
+    if (0 == $invoice->get_id()) {
870 870
         return;
871 871
     }
872 872
 
873 873
     // Line item columns.
874
-    $columns = getpaid_invoice_item_columns( $invoice );
875
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
874
+    $columns = getpaid_invoice_item_columns($invoice);
875
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
876 876
 
877
-    wpinv_get_template( 'invoice/line-items.php', compact( 'invoice', 'columns' ) );
877
+    wpinv_get_template('invoice/line-items.php', compact('invoice', 'columns'));
878 878
 }
879
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_line_items', 10 );
879
+add_action('getpaid_invoice_line_items', 'wpinv_display_line_items', 10);
880 880
 
881 881
 /**
882 882
  * Displays invoice notices on invoices.
883 883
  */
884 884
 function wpinv_display_invoice_notice() {
885 885
 
886
-    $label  = wpinv_get_option( 'vat_invoice_notice_label' );
887
-    $notice = wpinv_get_option( 'vat_invoice_notice' );
886
+    $label  = wpinv_get_option('vat_invoice_notice_label');
887
+    $notice = wpinv_get_option('vat_invoice_notice');
888 888
 
889
-    if ( empty( $label ) && empty( $notice ) ) {
889
+    if (empty($label) && empty($notice)) {
890 890
         return;
891 891
     }
892 892
 
893 893
     echo '<div class="mt-4 mb-4 wpinv-vat-notice">';
894 894
 
895
-    if ( ! empty( $label ) ) {
896
-        $label = sanitize_text_field( $label );
895
+    if (!empty($label)) {
896
+        $label = sanitize_text_field($label);
897 897
         echo "<h5>$label</h5>";
898 898
     }
899 899
 
900
-    if ( ! empty( $notice ) ) {
901
-        echo '<small class="form-text text-muted">' . wpautop( wptexturize( $notice ) ) . '</small>';
900
+    if (!empty($notice)) {
901
+        echo '<small class="form-text text-muted">' . wpautop(wptexturize($notice)) . '</small>';
902 902
     }
903 903
 
904 904
     echo '</div>';
905 905
 }
906
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100 );
906
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notice', 100);
907 907
 
908 908
 /**
909 909
  * @param WPInv_Invoice $invoice
910 910
  */
911
-function wpinv_display_invoice_notes( $invoice ) {
911
+function wpinv_display_invoice_notes($invoice) {
912 912
 
913 913
     // Retrieve the notes.
914
-    $notes = wpinv_get_invoice_notes( $invoice->get_id(), 'customer' );
914
+    $notes = wpinv_get_invoice_notes($invoice->get_id(), 'customer');
915 915
 
916 916
     // Abort if we have non.
917
-    if ( empty( $notes ) ) {
917
+    if (empty($notes)) {
918 918
         return;
919 919
     }
920 920
 
921 921
     // Echo the note.
922 922
     echo '<div class="getpaid-invoice-notes-wrapper border position-relative w-100 mb-4 p-0">';
923
-    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __( 'Notes', 'invoicing' ) .'</h3>';
923
+    echo '<h3 class="getpaid-invoice-notes-title text-dark bg-light border-bottom m-0 d-block">' . __('Notes', 'invoicing') . '</h3>';
924 924
     echo '<ul class="getpaid-invoice-notes mt-4 p-0">';
925 925
 
926
-    foreach( $notes as $note ) {
927
-        wpinv_get_invoice_note_line_item( $note );
926
+    foreach ($notes as $note) {
927
+        wpinv_get_invoice_note_line_item($note);
928 928
     }
929 929
 
930 930
     echo '</ul>';
931 931
     echo '</div>';
932 932
 }
933
-add_action( 'getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60 );
933
+add_action('getpaid_invoice_line_items', 'wpinv_display_invoice_notes', 60);
934 934
 
935 935
 /**
936 936
  * Loads scripts on our invoice templates.
@@ -938,32 +938,32 @@  discard block
 block discarded – undo
938 938
 function wpinv_display_style() {
939 939
 
940 940
     // Make sure that all scripts have been loaded.
941
-    if ( ! did_action( 'wp_enqueue_scripts' ) ) {
942
-        do_action( 'wp_enqueue_scripts' );
941
+    if (!did_action('wp_enqueue_scripts')) {
942
+        do_action('wp_enqueue_scripts');
943 943
     }
944 944
 
945 945
     // Register the invoices style.
946
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice.css' ) );
946
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice.css'));
947 947
 
948 948
     // Load required styles
949
-    wp_print_styles( 'open-sans' );
950
-    wp_print_styles( 'wpinv-single-style' );
951
-    wp_print_styles( 'ayecode-ui' );
949
+    wp_print_styles('open-sans');
950
+    wp_print_styles('wpinv-single-style');
951
+    wp_print_styles('ayecode-ui');
952 952
 
953 953
     // Maybe load custom css.
954
-    $custom_css = wpinv_get_option( 'template_custom_css' );
954
+    $custom_css = wpinv_get_option('template_custom_css');
955 955
 
956
-    if ( isset( $custom_css ) && ! empty( $custom_css ) ) {
957
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
958
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
956
+    if (isset($custom_css) && !empty($custom_css)) {
957
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
958
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
959 959
         echo '<style type="text/css">';
960 960
         echo $custom_css;
961 961
         echo '</style>';
962 962
     }
963 963
 
964 964
 }
965
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
966
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
965
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
966
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
967 967
 
968 968
 
969 969
 /**
@@ -975,41 +975,41 @@  discard block
 block discarded – undo
975 975
     // Retrieve the current invoice.
976 976
     $invoice_id = getpaid_get_current_invoice_id();
977 977
 
978
-    if ( empty( $invoice_id ) ) {
978
+    if (empty($invoice_id)) {
979 979
 
980 980
         return aui()->alert(
981 981
             array(
982 982
                 'type'    => 'warning',
983
-                'content' => __( 'Invalid invoice', 'invoicing' ),
983
+                'content' => __('Invalid invoice', 'invoicing'),
984 984
             )
985 985
         );
986 986
 
987 987
     }
988 988
 
989 989
     // Can the user view this invoice?
990
-    if ( ! wpinv_user_can_view_invoice( $invoice_id ) ) {
990
+    if (!wpinv_user_can_view_invoice($invoice_id)) {
991 991
 
992 992
         return aui()->alert(
993 993
             array(
994 994
                 'type'    => 'warning',
995
-                'content' => __( 'You are not allowed to view this invoice', 'invoicing' ),
995
+                'content' => __('You are not allowed to view this invoice', 'invoicing'),
996 996
             )
997 997
         );
998 998
 
999 999
     }
1000 1000
 
1001 1001
     // Ensure that it is not yet paid for.
1002
-    $invoice = new WPInv_Invoice( $invoice_id );
1002
+    $invoice = new WPInv_Invoice($invoice_id);
1003 1003
 
1004 1004
     // Maybe mark it as viewed.
1005
-    getpaid_maybe_mark_invoice_as_viewed( $invoice );
1005
+    getpaid_maybe_mark_invoice_as_viewed($invoice);
1006 1006
 
1007
-    if ( $invoice->is_paid() ) {
1007
+    if ($invoice->is_paid()) {
1008 1008
 
1009 1009
         return aui()->alert(
1010 1010
             array(
1011 1011
                 'type'    => 'success',
1012
-                'content' => __( 'This invoice has already been paid.', 'invoicing' ),
1012
+                'content' => __('This invoice has already been paid.', 'invoicing'),
1013 1013
             )
1014 1014
         );
1015 1015
 
@@ -1019,14 +1019,14 @@  discard block
 block discarded – undo
1019 1019
     $wpi_checkout_id = $invoice_id;
1020 1020
 
1021 1021
     // We'll display this invoice via the default form.
1022
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1022
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1023 1023
 
1024
-    if ( 0 == $form->get_id() ) {
1024
+    if (0 == $form->get_id()) {
1025 1025
 
1026 1026
         return aui()->alert(
1027 1027
             array(
1028 1028
                 'type'    => 'warning',
1029
-                'content' => __( 'Error loading the payment form', 'invoicing' ),
1029
+                'content' => __('Error loading the payment form', 'invoicing'),
1030 1030
             )
1031 1031
         );
1032 1032
 
@@ -1034,7 +1034,7 @@  discard block
 block discarded – undo
1034 1034
 
1035 1035
     // Set the invoice.
1036 1036
     $form->invoice = $invoice;
1037
-    $form->set_items( $invoice->get_items() );
1037
+    $form->set_items($invoice->get_items());
1038 1038
 
1039 1039
     // Generate the html.
1040 1040
     return $form->get_html();
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
 }
1043 1043
 
1044 1044
 function wpinv_empty_cart_message() {
1045
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1045
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1046 1046
 }
1047 1047
 
1048 1048
 /**
@@ -1059,38 +1059,38 @@  discard block
 block discarded – undo
1059 1059
         )
1060 1060
     );
1061 1061
 }
1062
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1062
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1063 1063
 
1064
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1065
-    $invoice = wpinv_get_invoice( $invoice_id );
1064
+function wpinv_receipt_billing_address($invoice_id = 0) {
1065
+    $invoice = wpinv_get_invoice($invoice_id);
1066 1066
 
1067
-    if ( empty( $invoice ) ) {
1067
+    if (empty($invoice)) {
1068 1068
         return NULL;
1069 1069
     }
1070 1070
 
1071 1071
     $billing_details = $invoice->get_user_info();
1072
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1072
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1073 1073
 
1074 1074
     ob_start();
1075 1075
     ?>
1076 1076
     <table class="table table-bordered table-sm wpi-billing-details">
1077 1077
         <tbody>
1078 1078
             <tr class="wpi-receipt-name">
1079
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1080
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1079
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1080
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1081 1081
             </tr>
1082 1082
             <tr class="wpi-receipt-email">
1083
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1084
-                <td><?php echo $billing_details['email'] ;?></td>
1083
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1084
+                <td><?php echo $billing_details['email']; ?></td>
1085 1085
             </tr>
1086 1086
             <tr class="wpi-receipt-address">
1087
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1088
-                <td><?php echo $address_row ;?></td>
1087
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1088
+                <td><?php echo $address_row; ?></td>
1089 1089
             </tr>
1090
-            <?php if ( $billing_details['phone'] ) { ?>
1090
+            <?php if ($billing_details['phone']) { ?>
1091 1091
             <tr class="wpi-receipt-phone">
1092
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1093
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1092
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1093
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1094 1094
             </tr>
1095 1095
             <?php } ?>
1096 1096
         </tbody>
@@ -1098,7 +1098,7 @@  discard block
 block discarded – undo
1098 1098
     <?php
1099 1099
     $output = ob_get_clean();
1100 1100
     
1101
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1101
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1102 1102
 
1103 1103
     echo $output;
1104 1104
 }
@@ -1106,66 +1106,66 @@  discard block
 block discarded – undo
1106 1106
 /**
1107 1107
  * Filters the receipt page.
1108 1108
  */
1109
-function wpinv_filter_success_page_content( $content ) {
1109
+function wpinv_filter_success_page_content($content) {
1110 1110
 
1111 1111
     // Ensure this is our page.
1112
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1112
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1113 1113
 
1114
-        $gateway = sanitize_text_field( $_GET['payment-confirm'] );
1115
-        return apply_filters( "wpinv_payment_confirm_$gateway", $content );
1114
+        $gateway = sanitize_text_field($_GET['payment-confirm']);
1115
+        return apply_filters("wpinv_payment_confirm_$gateway", $content);
1116 1116
 
1117 1117
     }
1118 1118
 
1119 1119
     return $content;
1120 1120
 }
1121
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1121
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1122 1122
 
1123
-function wpinv_invoice_link( $invoice_id ) {
1124
-    $invoice = wpinv_get_invoice( $invoice_id );
1123
+function wpinv_invoice_link($invoice_id) {
1124
+    $invoice = wpinv_get_invoice($invoice_id);
1125 1125
 
1126
-    if ( empty( $invoice ) ) {
1126
+    if (empty($invoice)) {
1127 1127
         return NULL;
1128 1128
     }
1129 1129
 
1130
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1130
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1131 1131
 
1132
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1132
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1133 1133
 }
1134 1134
 
1135
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
1136
-    if ( empty( $note ) ) {
1135
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
1136
+    if (empty($note)) {
1137 1137
         return NULL;
1138 1138
     }
1139 1139
 
1140
-    if ( is_int( $note ) ) {
1141
-        $note = get_comment( $note );
1140
+    if (is_int($note)) {
1141
+        $note = get_comment($note);
1142 1142
     }
1143 1143
 
1144
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
1144
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
1145 1145
         return NULL;
1146 1146
     }
1147 1147
 
1148
-    $note_classes   = array( 'note' );
1149
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
1148
+    $note_classes   = array('note');
1149
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
1150 1150
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
1151
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
1152
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
1151
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
1152
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
1153 1153
 
1154 1154
     ob_start();
1155 1155
     ?>
1156
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?> mt-4 pl-3 pr-3">
1156
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?> mt-4 pl-3 pr-3">
1157 1157
         <div class="note_content bg-light border position-relative p-4">
1158 1158
 
1159
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
1159
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
1160 1160
 
1161
-            <?php if ( ! is_admin() ) : ?>
1161
+            <?php if (!is_admin()) : ?>
1162 1162
                 <em class="meta position-absolute form-text">
1163 1163
                     <?php
1164 1164
                         printf(
1165
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1165
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1166 1166
                             $note->comment_author,
1167
-                            getpaid_format_date_value( $note->comment_date ),
1168
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1167
+                            getpaid_format_date_value($note->comment_date),
1168
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1169 1169
                         );
1170 1170
                     ?>
1171 1171
                 </em>
@@ -1173,21 +1173,21 @@  discard block
 block discarded – undo
1173 1173
 
1174 1174
         </div>
1175 1175
 
1176
-        <?php if ( is_admin() ) : ?>
1176
+        <?php if (is_admin()) : ?>
1177 1177
 
1178 1178
             <p class="meta px-4 py-2">
1179
-                <abbr class="exact-date" title="<?php echo esc_attr( $note->comment_date ); ?>">
1179
+                <abbr class="exact-date" title="<?php echo esc_attr($note->comment_date); ?>">
1180 1180
                     <?php
1181 1181
                         printf(
1182
-                            __( '%1$s - %2$s at %3$s', 'invoicing' ),
1182
+                            __('%1$s - %2$s at %3$s', 'invoicing'),
1183 1183
                             $note->comment_author,
1184
-                            getpaid_format_date_value( $note->comment_date ),
1185
-                            date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) )
1184
+                            getpaid_format_date_value($note->comment_date),
1185
+                            date_i18n(get_option('time_format'), strtotime($note->comment_date))
1186 1186
                         );
1187 1187
                     ?>
1188 1188
                 </abbr>&nbsp;&nbsp;
1189
-                <?php if ( $note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing() ) { ?>
1190
-                    <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
1189
+                <?php if ($note->comment_author !== 'System' && wpinv_current_user_can_manage_invoicing()) { ?>
1190
+                    <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
1191 1191
                 <?php } ?>
1192 1192
             </p>
1193 1193
 
@@ -1196,9 +1196,9 @@  discard block
 block discarded – undo
1196 1196
     </li>
1197 1197
     <?php
1198 1198
     $note_content = ob_get_clean();
1199
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
1199
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
1200 1200
 
1201
-    if ( $echo ) {
1201
+    if ($echo) {
1202 1202
         echo $note_content;
1203 1203
     } else {
1204 1204
         return $note_content;
@@ -1208,36 +1208,36 @@  discard block
 block discarded – undo
1208 1208
 function wpinv_invalid_invoice_content() {
1209 1209
     global $post;
1210 1210
 
1211
-    $invoice = wpinv_get_invoice( $post->ID );
1211
+    $invoice = wpinv_get_invoice($post->ID);
1212 1212
 
1213
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
1214
-    if ( !empty( $invoice->get_id() ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
1215
-        if ( is_user_logged_in() ) {
1216
-            if ( wpinv_require_login_to_checkout() ) {
1217
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1218
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
1213
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
1214
+    if (!empty($invoice->get_id()) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
1215
+        if (is_user_logged_in()) {
1216
+            if (wpinv_require_login_to_checkout()) {
1217
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1218
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
1219 1219
                 }
1220 1220
             }
1221 1221
         } else {
1222
-            if ( wpinv_require_login_to_checkout() ) {
1223
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
1224
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
1222
+            if (wpinv_require_login_to_checkout()) {
1223
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
1224
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
1225 1225
                 }
1226 1226
             }
1227 1227
         }
1228 1228
     } else {
1229
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
1229
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
1230 1230
     }
1231 1231
     ?>
1232 1232
     <div class="row wpinv-row-invalid">
1233 1233
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
1234
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
1234
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
1235 1235
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
1236 1236
         </div>
1237 1237
     </div>
1238 1238
     <?php
1239 1239
 }
1240
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
1240
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
1241 1241
 
1242 1242
 /**
1243 1243
  * Function to get privacy policy text.
@@ -1246,21 +1246,21 @@  discard block
 block discarded – undo
1246 1246
  * @return string
1247 1247
  */
1248 1248
 function wpinv_get_policy_text() {
1249
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
1249
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
1250 1250
 
1251
-    $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]' ));
1251
+    $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]'));
1252 1252
 
1253
-    if(!$privacy_page_id){
1254
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
1253
+    if (!$privacy_page_id) {
1254
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
1255 1255
     }
1256 1256
 
1257
-    $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' );
1257
+    $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');
1258 1258
 
1259 1259
     $find_replace = array(
1260 1260
         '[wpinv_privacy_policy]' => $privacy_link,
1261 1261
     );
1262 1262
 
1263
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
1263
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
1264 1264
 
1265 1265
     return wp_kses_post(wpautop($privacy_text));
1266 1266
 }
@@ -1268,21 +1268,21 @@  discard block
 block discarded – undo
1268 1268
 function wpinv_oxygen_fix_conflict() {
1269 1269
     global $ct_ignore_post_types;
1270 1270
 
1271
-    if ( ! is_array( $ct_ignore_post_types ) ) {
1271
+    if (!is_array($ct_ignore_post_types)) {
1272 1272
         $ct_ignore_post_types = array();
1273 1273
     }
1274 1274
 
1275
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
1275
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
1276 1276
 
1277
-    foreach ( $post_types as $post_type ) {
1277
+    foreach ($post_types as $post_type) {
1278 1278
         $ct_ignore_post_types[] = $post_type;
1279 1279
 
1280 1280
         // Ignore post type
1281
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
1281
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
1282 1282
     }
1283 1283
 
1284
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
1285
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
1284
+    remove_filter('template_include', 'wpinv_template', 10, 1);
1285
+    add_filter('template_include', 'wpinv_template', 999, 1);
1286 1286
 }
1287 1287
 
1288 1288
 /**
@@ -1290,10 +1290,10 @@  discard block
 block discarded – undo
1290 1290
  * 
1291 1291
  * @param GetPaid_Payment_Form $form
1292 1292
  */
1293
-function getpaid_display_payment_form( $form ) {
1293
+function getpaid_display_payment_form($form) {
1294 1294
 
1295
-    if ( is_numeric( $form ) ) {
1296
-        $form = new GetPaid_Payment_Form( $form );
1295
+    if (is_numeric($form)) {
1296
+        $form = new GetPaid_Payment_Form($form);
1297 1297
     }
1298 1298
 
1299 1299
     $form->display();
@@ -1303,55 +1303,55 @@  discard block
 block discarded – undo
1303 1303
 /**
1304 1304
  * Helper function to display a item payment form on the frontend.
1305 1305
  */
1306
-function getpaid_display_item_payment_form( $items ) {
1306
+function getpaid_display_item_payment_form($items) {
1307 1307
 
1308
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1309
-    $form->set_items( $items );
1308
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1309
+    $form->set_items($items);
1310 1310
 
1311
-    if ( 0 == count( $form->get_items() ) ) {
1311
+    if (0 == count($form->get_items())) {
1312 1312
         echo aui()->alert(
1313 1313
 			array(
1314 1314
 				'type'    => 'warning',
1315
-				'content' => __( 'No published items found', 'invoicing' ),
1315
+				'content' => __('No published items found', 'invoicing'),
1316 1316
 			)
1317 1317
         );
1318 1318
         return;
1319 1319
     }
1320 1320
 
1321
-    $form_items = esc_attr( getpaid_convert_items_to_string( $items ) );
1321
+    $form_items = esc_attr(getpaid_convert_items_to_string($items));
1322 1322
     $form_items = "<input type='hidden' name='getpaid-form-items' value='$form_items' />";
1323
-    $form->display( $form_items );
1323
+    $form->display($form_items);
1324 1324
 }
1325 1325
 
1326 1326
 /**
1327 1327
  * Helper function to display an invoice payment form on the frontend.
1328 1328
  */
1329
-function getpaid_display_invoice_payment_form( $invoice_id ) {
1329
+function getpaid_display_invoice_payment_form($invoice_id) {
1330 1330
 
1331
-    $invoice = wpinv_get_invoice( $invoice_id );
1331
+    $invoice = wpinv_get_invoice($invoice_id);
1332 1332
 
1333
-    if ( empty( $invoice ) ) {
1333
+    if (empty($invoice)) {
1334 1334
 		echo aui()->alert(
1335 1335
 			array(
1336 1336
 				'type'    => 'warning',
1337
-				'content' => __( 'Invoice not found', 'invoicing' ),
1337
+				'content' => __('Invoice not found', 'invoicing'),
1338 1338
 			)
1339 1339
         );
1340 1340
         return;
1341 1341
     }
1342 1342
 
1343
-    if ( $invoice->is_paid() ) {
1343
+    if ($invoice->is_paid()) {
1344 1344
 		echo aui()->alert(
1345 1345
 			array(
1346 1346
 				'type'    => 'warning',
1347
-				'content' => __( 'Invoice has already been paid', 'invoicing' ),
1347
+				'content' => __('Invoice has already been paid', 'invoicing'),
1348 1348
 			)
1349 1349
         );
1350 1350
         return;
1351 1351
     }
1352 1352
 
1353
-    $form = new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
1354
-    $form->set_items( $invoice->get_items() );
1353
+    $form = new GetPaid_Payment_Form(wpinv_get_default_payment_form());
1354
+    $form->set_items($invoice->get_items());
1355 1355
 
1356 1356
     $form->display();
1357 1357
 }
@@ -1359,23 +1359,23 @@  discard block
 block discarded – undo
1359 1359
 /**
1360 1360
  * Helper function to convert item string to array.
1361 1361
  */
1362
-function getpaid_convert_items_to_array( $items ) {
1363
-    $items    = array_filter( array_map( 'trim', explode( ',', $items ) ) );
1362
+function getpaid_convert_items_to_array($items) {
1363
+    $items    = array_filter(array_map('trim', explode(',', $items)));
1364 1364
     $prepared = array();
1365 1365
 
1366
-    foreach ( $items as $item ) {
1367
-        $data = array_map( 'trim', explode( '|', $item ) );
1366
+    foreach ($items as $item) {
1367
+        $data = array_map('trim', explode('|', $item));
1368 1368
 
1369
-        if ( empty( $data[0] ) || ! is_numeric( $data[0] ) ) {
1369
+        if (empty($data[0]) || !is_numeric($data[0])) {
1370 1370
             continue;
1371 1371
         }
1372 1372
 
1373 1373
         $quantity = 1;
1374
-        if ( isset( $data[1] ) && is_numeric( $data[1] ) ) {
1374
+        if (isset($data[1]) && is_numeric($data[1])) {
1375 1375
             $quantity = (int) $data[1];
1376 1376
         }
1377 1377
 
1378
-        $prepared[ $data[0] ] = $quantity;
1378
+        $prepared[$data[0]] = $quantity;
1379 1379
 
1380 1380
     }
1381 1381
 
@@ -1385,13 +1385,13 @@  discard block
 block discarded – undo
1385 1385
 /**
1386 1386
  * Helper function to convert item array to string.
1387 1387
  */
1388
-function getpaid_convert_items_to_string( $items ) {
1388
+function getpaid_convert_items_to_string($items) {
1389 1389
     $prepared = array();
1390 1390
 
1391
-    foreach ( $items as $item => $quantity ) {
1391
+    foreach ($items as $item => $quantity) {
1392 1392
         $prepared[] = "$item|$quantity";
1393 1393
     }
1394
-    return implode( ',', $prepared );
1394
+    return implode(',', $prepared);
1395 1395
 }
1396 1396
 
1397 1397
 /**
@@ -1399,21 +1399,21 @@  discard block
 block discarded – undo
1399 1399
  * 
1400 1400
  * Provide a label and one of $form, $items or $invoice.
1401 1401
  */
1402
-function getpaid_get_payment_button( $label, $form = null, $items = null, $invoice = null ) {
1403
-    $label = sanitize_text_field( $label );
1402
+function getpaid_get_payment_button($label, $form = null, $items = null, $invoice = null) {
1403
+    $label = sanitize_text_field($label);
1404 1404
 
1405
-    if ( ! empty( $form ) ) {
1406
-        $form  = esc_attr( $form );
1405
+    if (!empty($form)) {
1406
+        $form = esc_attr($form);
1407 1407
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-form='$form'>$label</button>"; 
1408 1408
     }
1409 1409
 	
1410
-	if ( ! empty( $items ) ) {
1411
-        $items  = esc_attr( $items );
1410
+	if (!empty($items)) {
1411
+        $items = esc_attr($items);
1412 1412
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-item='$items'>$label</button>"; 
1413 1413
     }
1414 1414
     
1415
-    if ( ! empty( $invoice ) ) {
1416
-        $invoice  = esc_attr( $invoice );
1415
+    if (!empty($invoice)) {
1416
+        $invoice = esc_attr($invoice);
1417 1417
         return "<button class='btn btn-primary getpaid-payment-button' type='button' data-invoice='$invoice'>$label</button>"; 
1418 1418
     }
1419 1419
 
@@ -1424,17 +1424,17 @@  discard block
 block discarded – undo
1424 1424
  *
1425 1425
  * @param WPInv_Invoice $invoice
1426 1426
  */
1427
-function getpaid_the_invoice_description( $invoice ) {
1427
+function getpaid_the_invoice_description($invoice) {
1428 1428
     $description = $invoice->get_description();
1429 1429
 
1430
-    if ( empty( $description ) ) {
1430
+    if (empty($description)) {
1431 1431
         return;
1432 1432
     }
1433 1433
 
1434
-    $description = wp_kses_post( $description );
1434
+    $description = wp_kses_post($description);
1435 1435
     echo "<small class='getpaid-invoice-description text-dark p-2 form-text'><em>$description</em></small>";
1436 1436
 }
1437
-add_action( 'getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100 );
1437
+add_action('getpaid_invoice_line_items', 'getpaid_the_invoice_description', 100);
1438 1438
 
1439 1439
 /**
1440 1440
  * Render element on a form.
@@ -1442,60 +1442,60 @@  discard block
 block discarded – undo
1442 1442
  * @param array $element
1443 1443
  * @param GetPaid_Payment_Form $form
1444 1444
  */
1445
-function getpaid_payment_form_element( $element, $form ) {
1445
+function getpaid_payment_form_element($element, $form) {
1446 1446
 
1447 1447
     // Set up the args.
1448
-    $element_type    = trim( $element['type'] );
1448
+    $element_type    = trim($element['type']);
1449 1449
     $element['form'] = $form;
1450
-    extract( $element );
1450
+    extract($element);
1451 1451
 
1452 1452
     // Try to locate the appropriate template.
1453
-    $located = wpinv_locate_template( "payment-forms/elements/$element_type.php" );
1453
+    $located = wpinv_locate_template("payment-forms/elements/$element_type.php");
1454 1454
     
1455 1455
     // Abort if this is not our element.
1456
-    if ( empty( $located ) || ! file_exists( $located ) ) {
1456
+    if (empty($located) || !file_exists($located)) {
1457 1457
         return;
1458 1458
     }
1459 1459
 
1460 1460
     // Generate the class and id of the element.
1461
-    $wrapper_class = 'getpaid-payment-form-element-' . trim( esc_attr( $element_type ) );
1462
-    $id            = isset( $id ) ? $id : uniqid( 'gp' );
1461
+    $wrapper_class = 'getpaid-payment-form-element-' . trim(esc_attr($element_type));
1462
+    $id            = isset($id) ? $id : uniqid('gp');
1463 1463
 
1464 1464
     // Echo the opening wrapper.
1465 1465
     echo "<div class='getpaid-payment-form-element $wrapper_class'>";
1466 1466
 
1467 1467
     // Fires before displaying a given element type's content.
1468
-    do_action( "getpaid_before_payment_form_{$element_type}_element", $element, $form );
1468
+    do_action("getpaid_before_payment_form_{$element_type}_element", $element, $form);
1469 1469
 
1470 1470
     // Include the template for the element.
1471 1471
     include $located;
1472 1472
 
1473 1473
     // Fires after displaying a given element type's content.
1474
-    do_action( "getpaid_payment_form_{$element_type}_element", $element, $form );
1474
+    do_action("getpaid_payment_form_{$element_type}_element", $element, $form);
1475 1475
 
1476 1476
     // Echo the closing wrapper.
1477 1477
     echo '</div>';
1478 1478
 }
1479
-add_action( 'getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2 );
1479
+add_action('getpaid_payment_form_element', 'getpaid_payment_form_element', 10, 2);
1480 1480
 
1481 1481
 /**
1482 1482
  * Render an element's edit page.
1483 1483
  *
1484 1484
  * @param WP_Post $post
1485 1485
  */
1486
-function getpaid_payment_form_edit_element_template( $post ) {
1486
+function getpaid_payment_form_edit_element_template($post) {
1487 1487
 
1488 1488
     // Retrieve all elements.
1489
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1489
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1490 1490
 
1491
-    foreach ( $all_elements as $element ) {
1491
+    foreach ($all_elements as $element) {
1492 1492
 
1493 1493
         // Try to locate the appropriate template.
1494
-        $element = sanitize_key( $element );
1495
-        $located = wpinv_locate_template( "payment-forms-admin/edit/$element.php" );
1494
+        $element = sanitize_key($element);
1495
+        $located = wpinv_locate_template("payment-forms-admin/edit/$element.php");
1496 1496
 
1497 1497
         // Continue if this is not our element.
1498
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1498
+        if (empty($located) || !file_exists($located)) {
1499 1499
             continue;
1500 1500
         }
1501 1501
 
@@ -1506,7 +1506,7 @@  discard block
 block discarded – undo
1506 1506
     }
1507 1507
 
1508 1508
 }
1509
-add_action( 'getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template' );
1509
+add_action('getpaid_payment_form_edit_element_template', 'getpaid_payment_form_edit_element_template');
1510 1510
 
1511 1511
 /**
1512 1512
  * Render an element's preview.
@@ -1515,16 +1515,16 @@  discard block
 block discarded – undo
1515 1515
 function getpaid_payment_form_render_element_preview_template() {
1516 1516
 
1517 1517
     // Retrieve all elements.
1518
-    $all_elements = wp_list_pluck( wpinv_get_data( 'payment-form-elements' ), 'type' );
1518
+    $all_elements = wp_list_pluck(wpinv_get_data('payment-form-elements'), 'type');
1519 1519
 
1520
-    foreach ( $all_elements as $element ) {
1520
+    foreach ($all_elements as $element) {
1521 1521
 
1522 1522
         // Try to locate the appropriate template.
1523
-        $element = sanitize_key( $element );
1524
-        $located = wpinv_locate_template( "payment-forms-admin/previews/$element.php" );
1523
+        $element = sanitize_key($element);
1524
+        $located = wpinv_locate_template("payment-forms-admin/previews/$element.php");
1525 1525
 
1526 1526
         // Continue if this is not our element.
1527
-        if ( empty( $located ) || ! file_exists( $located ) ) {
1527
+        if (empty($located) || !file_exists($located)) {
1528 1528
             continue;
1529 1529
         }
1530 1530
 
@@ -1535,7 +1535,7 @@  discard block
 block discarded – undo
1535 1535
     }
1536 1536
 
1537 1537
 }
1538
-add_action( 'wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template' );
1538
+add_action('wpinv_payment_form_render_element_template', 'getpaid_payment_form_render_element_preview_template');
1539 1539
 
1540 1540
 /**
1541 1541
  * Shows a list of gateways that support recurring payments.
@@ -1543,17 +1543,17 @@  discard block
 block discarded – undo
1543 1543
 function wpinv_get_recurring_gateways_text() {
1544 1544
     $gateways = array();
1545 1545
 
1546
-    foreach ( wpinv_get_payment_gateways() as $key => $gateway ) {
1547
-        if ( wpinv_gateway_support_subscription( $key ) ) {
1548
-            $gateways[] = sanitize_text_field( $gateway['admin_label'] );
1546
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
1547
+        if (wpinv_gateway_support_subscription($key)) {
1548
+            $gateways[] = sanitize_text_field($gateway['admin_label']);
1549 1549
         }
1550 1550
     }
1551 1551
 
1552
-    if ( empty( $gateways ) ) {
1553
-        return "<span class='form-text text-danger'>" . __( 'No active gateways support subscription payments.', 'invoicing' ) ."</span>";
1552
+    if (empty($gateways)) {
1553
+        return "<span class='form-text text-danger'>" . __('No active gateways support subscription payments.', 'invoicing') . "</span>";
1554 1554
     }
1555 1555
 
1556
-    return "<span class='form-text text-muted'>" . wp_sprintf( __( 'Subscription payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ) ."</span>";
1556
+    return "<span class='form-text text-muted'>" . wp_sprintf(__('Subscription payments only supported by: %s', 'invoicing'), implode(', ', $gateways)) . "</span>";
1557 1557
 
1558 1558
 }
1559 1559
 
@@ -1563,7 +1563,7 @@  discard block
 block discarded – undo
1563 1563
  * @return GetPaid_Template
1564 1564
  */
1565 1565
 function getpaid_template() {
1566
-    return getpaid()->get( 'template' );
1566
+    return getpaid()->get('template');
1567 1567
 }
1568 1568
 
1569 1569
 /**
@@ -1572,23 +1572,23 @@  discard block
 block discarded – undo
1572 1572
  * @param array args
1573 1573
  * @return string
1574 1574
  */
1575
-function getpaid_paginate_links( $args ) {
1575
+function getpaid_paginate_links($args) {
1576 1576
 
1577 1577
     $args['type']     = 'array';
1578 1578
     $args['mid_size'] = 1;
1579
-    $pages        = paginate_links( $args );
1579
+    $pages = paginate_links($args);
1580 1580
 
1581
-    if ( ! is_array( $pages ) ) {
1581
+    if (!is_array($pages)) {
1582 1582
         return '';
1583 1583
     }
1584 1584
 
1585 1585
     $_pages = array();
1586
-    foreach ( $pages as $page ) {
1587
-        $_pages[] = str_replace( 'page-numbers', 'page-link text-decoration-none', $page );
1586
+    foreach ($pages as $page) {
1587
+        $_pages[] = str_replace('page-numbers', 'page-link text-decoration-none', $page);
1588 1588
     }
1589 1589
 
1590 1590
     $links  = "<nav>\n\t<ul class='pagination justify-content-end m-0'>\n\t\t<li class='page-item'>";
1591
-    $links .= join( "</li>\n\t\t<li class='page-item'>", $_pages );
1591
+    $links .= join("</li>\n\t\t<li class='page-item'>", $_pages);
1592 1592
     $links .= "</li>\n\t</ul>\n</nav>\n";
1593 1593
 
1594 1594
     return $links;
@@ -1601,21 +1601,21 @@  discard block
 block discarded – undo
1601 1601
  * @param string state
1602 1602
  * @return string
1603 1603
  */
1604
-function getpaid_get_states_select_markup( $country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state' ) {
1604
+function getpaid_get_states_select_markup($country, $state, $placeholder, $label, $help_text, $required = false, $wrapper_class = 'col-12', $field_name = 'wpinv_state') {
1605 1605
 
1606
-    $states = wpinv_get_country_states( $country );
1607
-    $uniqid = uniqid( '_' );
1606
+    $states = wpinv_get_country_states($country);
1607
+    $uniqid = uniqid('_');
1608 1608
 
1609
-    if ( ! empty( $states ) ) {
1609
+    if (!empty($states)) {
1610 1610
 
1611
-        return aui()->select( array(
1611
+        return aui()->select(array(
1612 1612
             'options'          => $states,
1613
-            'name'             => esc_attr( $field_name ),
1614
-            'id'               => sanitize_html_class( $field_name ) . $uniqid,
1615
-            'value'            => sanitize_text_field( $state ),
1613
+            'name'             => esc_attr($field_name),
1614
+            'id'               => sanitize_html_class($field_name) . $uniqid,
1615
+            'value'            => sanitize_text_field($state),
1616 1616
             'placeholder'      => $placeholder,
1617 1617
             'required'         => $required,
1618
-            'label'            => wp_kses_post( $label ),
1618
+            'label'            => wp_kses_post($label),
1619 1619
             'label_type'       => 'vertical',
1620 1620
             'help_text'        => $help_text,
1621 1621
             'class'            => 'getpaid-address-field wpinv_state',
@@ -1627,14 +1627,14 @@  discard block
 block discarded – undo
1627 1627
 
1628 1628
     return aui()->input(
1629 1629
         array(
1630
-            'name'        => esc_attr( $field_name ),
1631
-            'id'          => sanitize_html_class( $field_name ) . $uniqid,
1630
+            'name'        => esc_attr($field_name),
1631
+            'id'          => sanitize_html_class($field_name) . $uniqid,
1632 1632
             'placeholder' => $placeholder,
1633 1633
             'required'    => $required,
1634
-            'label'       => wp_kses_post( $label ),
1634
+            'label'       => wp_kses_post($label),
1635 1635
             'label_type'  => 'vertical',
1636 1636
             'help_text'   => $help_text,
1637
-            'value'       => sanitize_text_field( $state ),
1637
+            'value'       => sanitize_text_field($state),
1638 1638
             'class'       => 'getpaid-address-field wpinv_state',
1639 1639
             'wrap_class'  => "$wrapper_class getpaid-address-field-wrapper__state",
1640 1640
             'label_class' => 'getpaid-address-field-label getpaid-address-field-label__state',
@@ -1649,16 +1649,16 @@  discard block
 block discarded – undo
1649 1649
  * @param array $element
1650 1650
  * @return string
1651 1651
  */
1652
-function getpaid_get_form_element_grid_class( $element ) {
1652
+function getpaid_get_form_element_grid_class($element) {
1653 1653
 
1654 1654
     $class = "col-12";
1655
-    $width = empty( $element['grid_width'] ) ? 'full' : $element['grid_width'];
1655
+    $width = empty($element['grid_width']) ? 'full' : $element['grid_width'];
1656 1656
 
1657
-    if ( $width == 'half' ) {
1657
+    if ($width == 'half') {
1658 1658
         $class = "col-12 col-md-6";
1659 1659
     }
1660 1660
 
1661
-    if ( $width == 'third' ) {
1661
+    if ($width == 'third') {
1662 1662
         $class = "col-12 col-md-4";
1663 1663
     }
1664 1664
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +212 added lines, -212 removed lines patch added patch discarded remove patch
@@ -12,231 +12,231 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Initial tax.
23
-	 * @var float
24
-	 */
25
-	protected $initial_tax = 0;
26
-
27
-	/**
28
-	 * Recurring tax.
29
-	 * @var float
30
-	 */
31
-	protected $recurring_tax = 0;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Initial tax.
23
+     * @var float
24
+     */
25
+    protected $initial_tax = 0;
26
+
27
+    /**
28
+     * Recurring tax.
29
+     * @var float
30
+     */
31
+    protected $recurring_tax = 0;
32
+
33
+    /**
34
+     * Class constructor
35
+     *
36
+     * @param GetPaid_Payment_Form_Submission $submission
37
+     */
38
+    public function __construct( $submission ) {
39
+
40
+        // Validate VAT number.
41
+        $this->validate_vat( $submission );
42
+
43
+        foreach ( $submission->get_items() as $item ) {
44
+            $this->process_item_tax( $item, $submission );
45
+        }
46
+
47
+        // Process any existing invoice taxes.
48
+        if ( $submission->has_invoice() ) {
49
+            $this->taxes = $submission->get_invoice()->get_taxes();
50
+        }
51
+
52
+        // Add VAT.
53
+        $this->taxes['vat'] = array(
54
+            'name'          => 'vat',
55
+            'initial_tax'   => $this->initial_tax,
56
+            'recurring_tax' => $this->recurring_tax,
57
+        );
58
+
59
+    }
60
+
61
+    /**
62
+     * Maybe process tax.
63
+     *
64
+     * @since 1.0.19
65
+     * @param GetPaid_Form_Item $item
66
+     * @param GetPaid_Payment_Form_Submission $submission
67
+     */
68
+    public function process_item_tax( $item, $submission ) {
69
+
70
+        $rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
+        $price    = $item->get_sub_total();
72
+        $item_tax = $price * $rate * 0.01;
73
+
74
+        if ( wpinv_prices_include_tax() ) {
75
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
76
+        }
77
+
78
+        $this->initial_tax += $item_tax;
79
+
80
+        if ( $item->is_recurring() ) {
81
+            $this->recurring_tax += $item_tax;
82
+        }
83
+
84
+    }
85
+
86
+    /**
87
+     * Checks if the submission has a digital item.
88
+     *
89
+     * @param GetPaid_Payment_Form_Submission $submission
90
+     * @since 1.0.19
91
+     * @return bool
92
+     */
93
+    public function has_digital_item( $submission ) {
94
+
95
+        foreach ( $submission->get_items() as $item ) {
96
+
97
+            if ( 'digital' == $item->get_vat_rule() ) {
98
+                return true;
99
+            }
100
+
101
+        }
102
+
103
+        return false;
104
+    }
105
+
106
+    /**
107
+     * Checks if this is an eu store.
108
+     *
109
+     * @since 1.0.19
110
+     * @return bool
111
+     */
112
+    public function is_eu_store() {
113
+        return $this->is_eu_country( wpinv_get_default_country() );
114
+    }
115
+
116
+    /**
117
+     * Checks if this is an eu country.
118
+     *
119
+     * @param string $country
120
+     * @since 1.0.19
121
+     * @return bool
122
+     */
123
+    public function is_eu_country( $country ) {
124
+        return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
+    }
126
+
127
+    /**
128
+     * Checks if this is an eu purchase.
129
+     *
130
+     * @param string $customer_country
131
+     * @since 1.0.19
132
+     * @return bool
133
+     */
134
+    public function is_eu_transaction( $customer_country ) {
135
+        return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
+    }
137
+
138
+    /**
139
+     * Retrieves the vat number.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     * @since 1.0.19
143
+     * @return string
144
+     */
145
+    public function get_vat_number( $submission ) {
146
+
147
+        // Retrieve from the posted number.
148
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
149
+        if ( ! empty( $vat_number ) ) {
150
+            return wpinv_clean( $vat_number );
151
+        }
152
+
153
+        // Retrieve from the invoice.
154
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
+    }
156
+
157
+    /**
158
+     * Retrieves the company.
159
+     *
160
+     * @param GetPaid_Payment_Form_Submission $submission
161
+     * @since 1.0.19
162
+     * @return string
163
+     */
164
+    public function get_company( $submission ) {
165
+
166
+        // Retrieve from the posted data.
167
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
168
+        if ( ! empty( $company ) ) {
169
+            return wpinv_clean( $company );
170
+        }
171
+
172
+        // Retrieve from the invoice.
173
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
+    }
175
+
176
+    /**
177
+     * Checks if we requires a VAT number.
178
+     *
179
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
180
+     * @param bool $country_in_eu Whether the customer country is from the EU
181
+     * @since 1.0.19
182
+     * @return string
183
+     */
184
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
+
186
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
+        $prevent_b2c = ! empty( $prevent_b2c );
188
+        $is_eu       = $ip_in_eu || $country_in_eu;
189
+
190
+        return $prevent_b2c && $is_eu;
191
+    }
32 192
 
33 193
     /**
34
-	 * Class constructor
35
-	 *
36
-	 * @param GetPaid_Payment_Form_Submission $submission
37
-	 */
38
-	public function __construct( $submission ) {
39
-
40
-		// Validate VAT number.
41
-		$this->validate_vat( $submission );
42
-
43
-		foreach ( $submission->get_items() as $item ) {
44
-			$this->process_item_tax( $item, $submission );
45
-		}
46
-
47
-		// Process any existing invoice taxes.
48
-		if ( $submission->has_invoice() ) {
49
-			$this->taxes = $submission->get_invoice()->get_taxes();
50
-		}
51
-
52
-		// Add VAT.
53
-		$this->taxes['vat'] = array(
54
-			'name'          => 'vat',
55
-			'initial_tax'   => $this->initial_tax,
56
-			'recurring_tax' => $this->recurring_tax,
57
-		);
58
-
59
-	}
60
-
61
-	/**
62
-	 * Maybe process tax.
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @param GetPaid_Form_Item $item
66
-	 * @param GetPaid_Payment_Form_Submission $submission
67
-	 */
68
-	public function process_item_tax( $item, $submission ) {
69
-
70
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
71
-		$price    = $item->get_sub_total();
72
-		$item_tax = $price * $rate * 0.01;
73
-
74
-		if ( wpinv_prices_include_tax() ) {
75
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
76
-		}
77
-
78
-		$this->initial_tax += $item_tax;
79
-
80
-		if ( $item->is_recurring() ) {
81
-			$this->recurring_tax += $item_tax;
82
-		}
83
-
84
-	}
85
-
86
-	/**
87
-	 * Checks if the submission has a digital item.
88
-	 *
89
-	 * @param GetPaid_Payment_Form_Submission $submission
90
-	 * @since 1.0.19
91
-	 * @return bool
92
-	 */
93
-	public function has_digital_item( $submission ) {
94
-
95
-		foreach ( $submission->get_items() as $item ) {
96
-
97
-			if ( 'digital' == $item->get_vat_rule() ) {
98
-				return true;
99
-			}
100
-
101
-		}
102
-
103
-		return false;
104
-	}
105
-
106
-	/**
107
-	 * Checks if this is an eu store.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @return bool
111
-	 */
112
-	public function is_eu_store() {
113
-		return $this->is_eu_country( wpinv_get_default_country() );
114
-	}
115
-
116
-	/**
117
-	 * Checks if this is an eu country.
118
-	 *
119
-	 * @param string $country
120
-	 * @since 1.0.19
121
-	 * @return bool
122
-	 */
123
-	public function is_eu_country( $country ) {
124
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
125
-	}
126
-
127
-	/**
128
-	 * Checks if this is an eu purchase.
129
-	 *
130
-	 * @param string $customer_country
131
-	 * @since 1.0.19
132
-	 * @return bool
133
-	 */
134
-	public function is_eu_transaction( $customer_country ) {
135
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
136
-	}
137
-
138
-	/**
139
-	 * Retrieves the vat number.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 * @since 1.0.19
143
-	 * @return string
144
-	 */
145
-	public function get_vat_number( $submission ) {
146
-
147
-		// Retrieve from the posted number.
148
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
149
-		if ( ! empty( $vat_number ) ) {
150
-			return wpinv_clean( $vat_number );
151
-		}
152
-
153
-		// Retrieve from the invoice.
154
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
155
-	}
156
-
157
-	/**
158
-	 * Retrieves the company.
159
-	 *
160
-	 * @param GetPaid_Payment_Form_Submission $submission
161
-	 * @since 1.0.19
162
-	 * @return string
163
-	 */
164
-	public function get_company( $submission ) {
165
-
166
-		// Retrieve from the posted data.
167
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
168
-		if ( ! empty( $company ) ) {
169
-			return wpinv_clean( $company );
170
-		}
171
-
172
-		// Retrieve from the invoice.
173
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
174
-	}
175
-
176
-	/**
177
-	 * Checks if we requires a VAT number.
178
-	 *
179
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
180
-	 * @param bool $country_in_eu Whether the customer country is from the EU
181
-	 * @since 1.0.19
182
-	 * @return string
183
-	 */
184
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
185
-
186
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
-		$prevent_b2c = ! empty( $prevent_b2c );
188
-		$is_eu       = $ip_in_eu || $country_in_eu;
189
-
190
-		return $prevent_b2c && $is_eu;
191
-	}
192
-
193
-	/**
194
-	 * Validate VAT data.
195
-	 *
196
-	 * @param GetPaid_Payment_Form_Submission $submission
197
-	 * @since 1.0.19
198
-	 */
199
-	public function validate_vat( $submission ) {
200
-
201
-		$has_digital = $this->has_digital_item( $submission );
202
-		$in_eu       = $this->is_eu_transaction( $submission->country );
203
-
204
-		// Abort if we are not validating vat numbers.
205
-		if ( ! $has_digital && ! $in_eu ) {
194
+     * Validate VAT data.
195
+     *
196
+     * @param GetPaid_Payment_Form_Submission $submission
197
+     * @since 1.0.19
198
+     */
199
+    public function validate_vat( $submission ) {
200
+
201
+        $has_digital = $this->has_digital_item( $submission );
202
+        $in_eu       = $this->is_eu_transaction( $submission->country );
203
+
204
+        // Abort if we are not validating vat numbers.
205
+        if ( ! $has_digital && ! $in_eu ) {
206 206
             return;
207
-		}
207
+        }
208 208
 
209
-		// Prepare variables.
210
-		$vat_number  = $this->get_vat_number( $submission );
211
-		$company     = $this->get_company( $submission );
212
-		$ip_country  = getpaid_get_ip_country();
209
+        // Prepare variables.
210
+        $vat_number  = $this->get_vat_number( $submission );
211
+        $company     = $this->get_company( $submission );
212
+        $ip_country  = getpaid_get_ip_country();
213 213
         $is_eu       = $this->is_eu_country( $submission->country );
214 214
         $is_ip_eu    = $this->is_eu_country( $ip_country );
215 215
 
216
-		// If we're preventing business to consumer purchases, ensure
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
216
+        // If we're preventing business to consumer purchases, ensure
217
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
218 218
 
219
-			// Ensure that a vat number has been specified.
220
-			throw new Exception(
221
-				wp_sprintf(
222
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
-					getpaid_vat_name()
224
-				)
225
-			);
219
+            // Ensure that a vat number has been specified.
220
+            throw new Exception(
221
+                wp_sprintf(
222
+                    __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
223
+                    getpaid_vat_name()
224
+                )
225
+            );
226 226
 
227
-		}
227
+        }
228 228
 
229
-		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
229
+        // Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
+        if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
231 231
             return;
232
-		}
232
+        }
233 233
 
234
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
234
+        $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
235 235
 
236
-		if ( is_string( $is_valid ) ) {
237
-			throw new Exception( $is_valid );
238
-		}
236
+        if ( is_string( $is_valid ) ) {
237
+            throw new Exception( $is_valid );
238
+        }
239 239
 
240
-	}
240
+    }
241 241
 
242 242
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission taxes class
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 	 *
36 36
 	 * @param GetPaid_Payment_Form_Submission $submission
37 37
 	 */
38
-	public function __construct( $submission ) {
38
+	public function __construct($submission) {
39 39
 
40 40
 		// Validate VAT number.
41
-		$this->validate_vat( $submission );
41
+		$this->validate_vat($submission);
42 42
 
43
-		foreach ( $submission->get_items() as $item ) {
44
-			$this->process_item_tax( $item, $submission );
43
+		foreach ($submission->get_items() as $item) {
44
+			$this->process_item_tax($item, $submission);
45 45
 		}
46 46
 
47 47
 		// Process any existing invoice taxes.
48
-		if ( $submission->has_invoice() ) {
48
+		if ($submission->has_invoice()) {
49 49
 			$this->taxes = $submission->get_invoice()->get_taxes();
50 50
 		}
51 51
 
@@ -65,19 +65,19 @@  discard block
 block discarded – undo
65 65
 	 * @param GetPaid_Form_Item $item
66 66
 	 * @param GetPaid_Payment_Form_Submission $submission
67 67
 	 */
68
-	public function process_item_tax( $item, $submission ) {
68
+	public function process_item_tax($item, $submission) {
69 69
 
70
-		$rate     = wpinv_get_tax_rate( $submission->country, $submission->state, $item->get_id() );
70
+		$rate     = wpinv_get_tax_rate($submission->country, $submission->state, $item->get_id());
71 71
 		$price    = $item->get_sub_total();
72 72
 		$item_tax = $price * $rate * 0.01;
73 73
 
74
-		if ( wpinv_prices_include_tax() ) {
75
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
74
+		if (wpinv_prices_include_tax()) {
75
+			$item_tax = $price - ($price - $price * $rate * 0.01);
76 76
 		}
77 77
 
78 78
 		$this->initial_tax += $item_tax;
79 79
 
80
-		if ( $item->is_recurring() ) {
80
+		if ($item->is_recurring()) {
81 81
 			$this->recurring_tax += $item_tax;
82 82
 		}
83 83
 
@@ -90,11 +90,11 @@  discard block
 block discarded – undo
90 90
 	 * @since 1.0.19
91 91
 	 * @return bool
92 92
 	 */
93
-	public function has_digital_item( $submission ) {
93
+	public function has_digital_item($submission) {
94 94
 
95
-		foreach ( $submission->get_items() as $item ) {
95
+		foreach ($submission->get_items() as $item) {
96 96
 
97
-			if ( 'digital' == $item->get_vat_rule() ) {
97
+			if ('digital' == $item->get_vat_rule()) {
98 98
 				return true;
99 99
 			}
100 100
 
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @return bool
111 111
 	 */
112 112
 	public function is_eu_store() {
113
-		return $this->is_eu_country( wpinv_get_default_country() );
113
+		return $this->is_eu_country(wpinv_get_default_country());
114 114
 	}
115 115
 
116 116
 	/**
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @since 1.0.19
121 121
 	 * @return bool
122 122
 	 */
123
-	public function is_eu_country( $country ) {
124
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
123
+	public function is_eu_country($country) {
124
+		return getpaid_is_eu_state($country) || getpaid_is_gst_country($country);
125 125
 	}
126 126
 
127 127
 	/**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @since 1.0.19
132 132
 	 * @return bool
133 133
 	 */
134
-	public function is_eu_transaction( $customer_country ) {
135
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
134
+	public function is_eu_transaction($customer_country) {
135
+		return $this->is_eu_country($customer_country) && $this->is_eu_store();
136 136
 	}
137 137
 
138 138
 	/**
@@ -142,12 +142,12 @@  discard block
 block discarded – undo
142 142
 	 * @since 1.0.19
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_vat_number( $submission ) {
145
+	public function get_vat_number($submission) {
146 146
 
147 147
 		// Retrieve from the posted number.
148
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
149
-		if ( ! empty( $vat_number ) ) {
150
-			return wpinv_clean( $vat_number );
148
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
149
+		if (!empty($vat_number)) {
150
+			return wpinv_clean($vat_number);
151 151
 		}
152 152
 
153 153
 		// Retrieve from the invoice.
@@ -161,12 +161,12 @@  discard block
 block discarded – undo
161 161
 	 * @since 1.0.19
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_company( $submission ) {
164
+	public function get_company($submission) {
165 165
 
166 166
 		// Retrieve from the posted data.
167
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
168
-		if ( ! empty( $company ) ) {
169
-			return wpinv_clean( $company );
167
+		$company = $submission->get_field('wpinv_company', 'billing');
168
+		if (!empty($company)) {
169
+			return wpinv_clean($company);
170 170
 		}
171 171
 
172 172
 		// Retrieve from the invoice.
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
 	 * @since 1.0.19
182 182
 	 * @return string
183 183
 	 */
184
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
184
+	public function requires_vat($ip_in_eu, $country_in_eu) {
185 185
 
186
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
187
-		$prevent_b2c = ! empty( $prevent_b2c );
186
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
187
+		$prevent_b2c = !empty($prevent_b2c);
188 188
 		$is_eu       = $ip_in_eu || $country_in_eu;
189 189
 
190 190
 		return $prevent_b2c && $is_eu;
@@ -196,30 +196,30 @@  discard block
 block discarded – undo
196 196
 	 * @param GetPaid_Payment_Form_Submission $submission
197 197
 	 * @since 1.0.19
198 198
 	 */
199
-	public function validate_vat( $submission ) {
199
+	public function validate_vat($submission) {
200 200
 
201
-		$has_digital = $this->has_digital_item( $submission );
202
-		$in_eu       = $this->is_eu_transaction( $submission->country );
201
+		$has_digital = $this->has_digital_item($submission);
202
+		$in_eu       = $this->is_eu_transaction($submission->country);
203 203
 
204 204
 		// Abort if we are not validating vat numbers.
205
-		if ( ! $has_digital && ! $in_eu ) {
205
+		if (!$has_digital && !$in_eu) {
206 206
             return;
207 207
 		}
208 208
 
209 209
 		// Prepare variables.
210
-		$vat_number  = $this->get_vat_number( $submission );
211
-		$company     = $this->get_company( $submission );
210
+		$vat_number  = $this->get_vat_number($submission);
211
+		$company     = $this->get_company($submission);
212 212
 		$ip_country  = getpaid_get_ip_country();
213
-        $is_eu       = $this->is_eu_country( $submission->country );
214
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
213
+        $is_eu       = $this->is_eu_country($submission->country);
214
+        $is_ip_eu    = $this->is_eu_country($ip_country);
215 215
 
216 216
 		// If we're preventing business to consumer purchases, ensure
217
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
217
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
218 218
 
219 219
 			// Ensure that a vat number has been specified.
220 220
 			throw new Exception(
221 221
 				wp_sprintf(
222
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
222
+					__('Please enter your %s number to verify your purchase is by an EU business.', 'invoicing'),
223 223
 					getpaid_vat_name()
224 224
 				)
225 225
 			);
@@ -227,14 +227,14 @@  discard block
 block discarded – undo
227 227
 		}
228 228
 
229 229
 		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
230
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
230
+		if (!$is_eu || !$in_eu || empty($vat_number)) {
231 231
             return;
232 232
 		}
233 233
 
234
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
234
+		$is_valid = WPInv_EUVat::validate_vat_number($vat_number, $company, $submission->country);
235 235
 
236
-		if ( is_string( $is_valid ) ) {
237
-			throw new Exception( $is_valid );
236
+		if (is_string($is_valid)) {
237
+			throw new Exception($is_valid);
238 238
 		}
239 239
 
240 240
 	}
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +738 added lines, -738 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_taxes' ),
175
-					array( $this, 'process_discount' ),
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_taxes' ),
175
+                    array( $this, 'process_discount' ),
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,61 +240,61 @@  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
-		}
262
-
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
-		}
266
-
267
-		$this->payment_form->set_items( $invoice->get_items() );
268
-		$this->payment_form->invoice = $invoice;
269
-
270
-		$this->country = $invoice->get_country();
271
-		$this->state   = $invoice->get_state();
272
-		$this->invoice = $invoice;
273
-
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
-	}
276
-
277
-	/**
278
-	 * Returns the associated invoice.
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @return WPInv_Invoice
282
-	 */
283
-	public function get_invoice() {
284
-		return $this->invoice;
285
-	}
286
-
287
-	/**
288
-	 * Checks whether there is an invoice associated with this submission.
289
-	 *
290
-	 * @since 1.0.19
291
-	 * @return bool
292
-	 */
293
-	public function has_invoice() {
294
-		return ! empty( $this->invoice );
295
-	}
296
-
297
-	/*
260
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
+        }
262
+
263
+        if ( $invoice->is_paid() ) {
264
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
+        }
266
+
267
+        $this->payment_form->set_items( $invoice->get_items() );
268
+        $this->payment_form->invoice = $invoice;
269
+
270
+        $this->country = $invoice->get_country();
271
+        $this->state   = $invoice->get_state();
272
+        $this->invoice = $invoice;
273
+
274
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
+    }
276
+
277
+    /**
278
+     * Returns the associated invoice.
279
+     *
280
+     * @since 1.0.19
281
+     * @return WPInv_Invoice
282
+     */
283
+    public function get_invoice() {
284
+        return $this->invoice;
285
+    }
286
+
287
+    /**
288
+     * Checks whether there is an invoice associated with this submission.
289
+     *
290
+     * @since 1.0.19
291
+     * @return bool
292
+     */
293
+    public function has_invoice() {
294
+        return ! empty( $this->invoice );
295
+    }
296
+
297
+    /*
298 298
 	|--------------------------------------------------------------------------
299 299
 	| Items.
300 300
 	|--------------------------------------------------------------------------
@@ -303,105 +303,105 @@  discard block
 block discarded – undo
303 303
 	| recurring item. But can have an unlimited number of non-recurring items.
304 304
 	*/
305 305
 
306
-	/**
307
-	 * Prepares the submission's items.
308
-	 *
309
-	 * @since 1.0.19
310
-	 */
311
-	public function process_items() {
312
-
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
-
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
317
-		}
318
-
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
-	}
321
-
322
-	/**
323
-	 * Adds an item to the submission.
324
-	 *
325
-	 * @since 1.0.19
326
-	 * @param GetPaid_Form_Item $item
327
-	 */
328
-	public function add_item( $item ) {
329
-
330
-		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() ) {
332
-			return;
333
-		}
334
-
335
-		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
337
-
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
-			}
341
-
342
-			$this->has_recurring = $item->get_id();
343
-
344
-		}
345
-
346
-		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
348
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
-
351
-	}
352
-
353
-	/**
354
-	 * Removes a specific item.
355
-	 * 
356
-	 * You should not call this method after the discounts and taxes
357
-	 * have been calculated.
358
-	 *
359
-	 * @since 1.0.19
360
-	 */
361
-	public function remove_item( $item_id ) {
362
-
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
-
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
368
-				$this->has_recurring = 0;
369
-			}
370
-
371
-			unset( $this->items[ $item_id ] );
372
-		}
306
+    /**
307
+     * Prepares the submission's items.
308
+     *
309
+     * @since 1.0.19
310
+     */
311
+    public function process_items() {
312
+
313
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
+
315
+        foreach ( $processor->items as $item ) {
316
+            $this->add_item( $item );
317
+        }
318
+
319
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
+    }
321
+
322
+    /**
323
+     * Adds an item to the submission.
324
+     *
325
+     * @since 1.0.19
326
+     * @param GetPaid_Form_Item $item
327
+     */
328
+    public function add_item( $item ) {
329
+
330
+        // Make sure that it is available for purchase.
331
+        if ( ! $item->can_purchase() ) {
332
+            return;
333
+        }
334
+
335
+        // Each submission can only contain one recurring item.
336
+        if ( $item->is_recurring() ) {
337
+
338
+            if ( $this->has_recurring != 0 ) {
339
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
+            }
341
+
342
+            $this->has_recurring = $item->get_id();
343
+
344
+        }
345
+
346
+        // Update the items and totals.
347
+        $this->items[ $item->get_id() ]         = $item;
348
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
349
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
+
351
+    }
352
+
353
+    /**
354
+     * Removes a specific item.
355
+     * 
356
+     * You should not call this method after the discounts and taxes
357
+     * have been calculated.
358
+     *
359
+     * @since 1.0.19
360
+     */
361
+    public function remove_item( $item_id ) {
362
+
363
+        if ( isset( $this->items[ $item_id ] ) ) {
364
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
+
367
+            if ( $this->items[ $item_id ]->is_recurring() ) {
368
+                $this->has_recurring = 0;
369
+            }
370
+
371
+            unset( $this->items[ $item_id ] );
372
+        }
373 373
 		
374
-	}
375
-
376
-	/**
377
-	 * Returns the subtotal.
378
-	 *
379
-	 * @since 1.0.19
380
-	 */
381
-	public function get_subtotal() {
382
-		return $this->totals['subtotal']['initial'];
383
-	}
384
-
385
-	/**
386
-	 * Returns the recurring subtotal.
387
-	 *
388
-	 * @since 1.0.19
389
-	 */
390
-	public function get_recurring_subtotal() {
391
-		return $this->totals['subtotal']['recurring'];
392
-	}
393
-
394
-	/**
395
-	 * Returns all items.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @return GetPaid_Form_Item[]
399
-	 */
400
-	public function get_items() {
401
-		return $this->items;
402
-	}
403
-
404
-	/*
374
+    }
375
+
376
+    /**
377
+     * Returns the subtotal.
378
+     *
379
+     * @since 1.0.19
380
+     */
381
+    public function get_subtotal() {
382
+        return $this->totals['subtotal']['initial'];
383
+    }
384
+
385
+    /**
386
+     * Returns the recurring subtotal.
387
+     *
388
+     * @since 1.0.19
389
+     */
390
+    public function get_recurring_subtotal() {
391
+        return $this->totals['subtotal']['recurring'];
392
+    }
393
+
394
+    /**
395
+     * Returns all items.
396
+     *
397
+     * @since 1.0.19
398
+     * @return GetPaid_Form_Item[]
399
+     */
400
+    public function get_items() {
401
+        return $this->items;
402
+    }
403
+
404
+    /*
405 405
 	|--------------------------------------------------------------------------
406 406
 	| Taxes
407 407
 	|--------------------------------------------------------------------------
@@ -410,110 +410,110 @@  discard block
 block discarded – undo
410 410
 	| or only one-time.
411 411
     */
412 412
 
413
-	/**
414
-	 * Prepares the submission's taxes.
415
-	 *
416
-	 * @since 1.0.19
417
-	 */
418
-	public function process_taxes() {
419
-
420
-		// Abort if we're not using taxes.
421
-		if ( ! $this->use_taxes() ) {
422
-			return;
423
-		}
424
-
425
-		// If a custom country && state has been passed in, use it to calculate taxes.
426
-		$country = $this->get_field( 'wpinv_country', 'billing' );
427
-		if ( ! empty( $country ) ) {
428
-			$this->country = $country;
429
-		}
430
-
431
-		$state = $this->get_field( 'wpinv_state', 'billing' );
432
-		if ( ! empty( $state ) ) {
433
-			$this->state = $state;
434
-		}
435
-
436
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
437
-
438
-		foreach ( $processor->taxes as $tax ) {
439
-			$this->add_tax( $tax );
440
-		}
441
-
442
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
443
-	}
444
-
445
-	/**
446
-	 * Adds a tax to the submission.
447
-	 *
448
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
449
-	 * @since 1.0.19
450
-	 */
451
-	public function add_tax( $tax ) {
452
-		$this->taxes[ $tax['name'] ]         = $tax;
453
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
454
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
455
-	}
456
-
457
-	/**
458
-	 * Removes a specific tax.
459
-	 *
460
-	 * @since 1.0.19
461
-	 */
462
-	public function remove_tax( $tax_name ) {
463
-
464
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
465
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
466
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
467
-			unset( $this->taxes[ $tax_name ] );
468
-		}
469
-
470
-	}
471
-
472
-	/**
473
-	 * Whether or not we'll use taxes for the submission.
474
-	 *
475
-	 * @since 1.0.19
476
-	 */
477
-	public function use_taxes() {
478
-
479
-		$use_taxes = wpinv_use_taxes();
480
-
481
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
482
-			$use_taxes = false;
483
-		}
484
-
485
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
486
-
487
-	}
488
-
489
-	/**
490
-	 * Returns the tax.
491
-	 *
492
-	 * @since 1.0.19
493
-	 */
494
-	public function get_tax() {
495
-		return $this->totals['taxes']['initial'];
496
-	}
497
-
498
-	/**
499
-	 * Returns the recurring tax.
500
-	 *
501
-	 * @since 1.0.19
502
-	 */
503
-	public function get_recurring_tax() {
504
-		return $this->totals['taxes']['recurring'];
505
-	}
506
-
507
-	/**
508
-	 * Returns all taxes.
509
-	 *
510
-	 * @since 1.0.19
511
-	 */
512
-	public function get_taxes() {
513
-		return $this->taxes;
514
-	}
515
-
516
-	/*
413
+    /**
414
+     * Prepares the submission's taxes.
415
+     *
416
+     * @since 1.0.19
417
+     */
418
+    public function process_taxes() {
419
+
420
+        // Abort if we're not using taxes.
421
+        if ( ! $this->use_taxes() ) {
422
+            return;
423
+        }
424
+
425
+        // If a custom country && state has been passed in, use it to calculate taxes.
426
+        $country = $this->get_field( 'wpinv_country', 'billing' );
427
+        if ( ! empty( $country ) ) {
428
+            $this->country = $country;
429
+        }
430
+
431
+        $state = $this->get_field( 'wpinv_state', 'billing' );
432
+        if ( ! empty( $state ) ) {
433
+            $this->state = $state;
434
+        }
435
+
436
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
437
+
438
+        foreach ( $processor->taxes as $tax ) {
439
+            $this->add_tax( $tax );
440
+        }
441
+
442
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
443
+    }
444
+
445
+    /**
446
+     * Adds a tax to the submission.
447
+     *
448
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
449
+     * @since 1.0.19
450
+     */
451
+    public function add_tax( $tax ) {
452
+        $this->taxes[ $tax['name'] ]         = $tax;
453
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
454
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
455
+    }
456
+
457
+    /**
458
+     * Removes a specific tax.
459
+     *
460
+     * @since 1.0.19
461
+     */
462
+    public function remove_tax( $tax_name ) {
463
+
464
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
465
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
466
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
467
+            unset( $this->taxes[ $tax_name ] );
468
+        }
469
+
470
+    }
471
+
472
+    /**
473
+     * Whether or not we'll use taxes for the submission.
474
+     *
475
+     * @since 1.0.19
476
+     */
477
+    public function use_taxes() {
478
+
479
+        $use_taxes = wpinv_use_taxes();
480
+
481
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
482
+            $use_taxes = false;
483
+        }
484
+
485
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
486
+
487
+    }
488
+
489
+    /**
490
+     * Returns the tax.
491
+     *
492
+     * @since 1.0.19
493
+     */
494
+    public function get_tax() {
495
+        return $this->totals['taxes']['initial'];
496
+    }
497
+
498
+    /**
499
+     * Returns the recurring tax.
500
+     *
501
+     * @since 1.0.19
502
+     */
503
+    public function get_recurring_tax() {
504
+        return $this->totals['taxes']['recurring'];
505
+    }
506
+
507
+    /**
508
+     * Returns all taxes.
509
+     *
510
+     * @since 1.0.19
511
+     */
512
+    public function get_taxes() {
513
+        return $this->taxes;
514
+    }
515
+
516
+    /*
517 517
 	|--------------------------------------------------------------------------
518 518
 	| Discounts
519 519
 	|--------------------------------------------------------------------------
@@ -522,99 +522,99 @@  discard block
 block discarded – undo
522 522
 	| or only one-time. They also do not have to come from a discount code.
523 523
     */
524 524
 
525
-	/**
526
-	 * Prepares the submission's discount.
527
-	 *
528
-	 * @since 1.0.19
529
-	 */
530
-	public function process_discount() {
531
-
532
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
533
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
534
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
535
-
536
-		foreach ( $processor->discounts as $discount ) {
537
-			$this->add_discount( $discount );
538
-		}
539
-
540
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
541
-	}
542
-
543
-	/**
544
-	 * Adds a discount to the submission.
545
-	 *
546
-	 * @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.
547
-	 * @since 1.0.19
548
-	 */
549
-	public function add_discount( $discount ) {
550
-		$this->discounts[ $discount['name'] ]   = $discount;
551
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
552
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
553
-	}
554
-
555
-	/**
556
-	 * Removes a discount from the submission.
557
-	 *
558
-	 * @since 1.0.19
559
-	 */
560
-	public function remove_discount( $name ) {
561
-
562
-		if ( isset( $this->discounts[ $name ] ) ) {
563
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
564
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
565
-			unset( $this->discounts[ $name ] );
566
-		}
567
-
568
-	}
569
-
570
-	/**
571
-	 * Checks whether there is a discount code associated with this submission.
572
-	 *
573
-	 * @since 1.0.19
574
-	 * @return bool
575
-	 */
576
-	public function has_discount_code() {
577
-		return ! empty( $this->discounts['discount_code'] );
578
-	}
579
-
580
-	/**
581
-	 * Returns the discount code.
582
-	 *
583
-	 * @since 1.0.19
584
-	 * @return string
585
-	 */
586
-	public function get_discount_code() {
587
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
588
-	}
589
-
590
-	/**
591
-	 * Returns the discount.
592
-	 *
593
-	 * @since 1.0.19
594
-	 */
595
-	public function get_discount() {
596
-		return $this->totals['discount']['initial'];
597
-	}
598
-
599
-	/**
600
-	 * Returns the recurring discount.
601
-	 *
602
-	 * @since 1.0.19
603
-	 */
604
-	public function get_recurring_discount() {
605
-		return $this->totals['discount']['recurring'];
606
-	}
607
-
608
-	/**
609
-	 * Returns all discounts.
610
-	 *
611
-	 * @since 1.0.19
612
-	 */
613
-	public function get_discounts() {
614
-		return $this->discounts;
615
-	}
616
-
617
-	/*
525
+    /**
526
+     * Prepares the submission's discount.
527
+     *
528
+     * @since 1.0.19
529
+     */
530
+    public function process_discount() {
531
+
532
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
533
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
534
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
535
+
536
+        foreach ( $processor->discounts as $discount ) {
537
+            $this->add_discount( $discount );
538
+        }
539
+
540
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
541
+    }
542
+
543
+    /**
544
+     * Adds a discount to the submission.
545
+     *
546
+     * @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.
547
+     * @since 1.0.19
548
+     */
549
+    public function add_discount( $discount ) {
550
+        $this->discounts[ $discount['name'] ]   = $discount;
551
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
552
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
553
+    }
554
+
555
+    /**
556
+     * Removes a discount from the submission.
557
+     *
558
+     * @since 1.0.19
559
+     */
560
+    public function remove_discount( $name ) {
561
+
562
+        if ( isset( $this->discounts[ $name ] ) ) {
563
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
564
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
565
+            unset( $this->discounts[ $name ] );
566
+        }
567
+
568
+    }
569
+
570
+    /**
571
+     * Checks whether there is a discount code associated with this submission.
572
+     *
573
+     * @since 1.0.19
574
+     * @return bool
575
+     */
576
+    public function has_discount_code() {
577
+        return ! empty( $this->discounts['discount_code'] );
578
+    }
579
+
580
+    /**
581
+     * Returns the discount code.
582
+     *
583
+     * @since 1.0.19
584
+     * @return string
585
+     */
586
+    public function get_discount_code() {
587
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
588
+    }
589
+
590
+    /**
591
+     * Returns the discount.
592
+     *
593
+     * @since 1.0.19
594
+     */
595
+    public function get_discount() {
596
+        return $this->totals['discount']['initial'];
597
+    }
598
+
599
+    /**
600
+     * Returns the recurring discount.
601
+     *
602
+     * @since 1.0.19
603
+     */
604
+    public function get_recurring_discount() {
605
+        return $this->totals['discount']['recurring'];
606
+    }
607
+
608
+    /**
609
+     * Returns all discounts.
610
+     *
611
+     * @since 1.0.19
612
+     */
613
+    public function get_discounts() {
614
+        return $this->discounts;
615
+    }
616
+
617
+    /*
618 618
 	|--------------------------------------------------------------------------
619 619
 	| Fees
620 620
 	|--------------------------------------------------------------------------
@@ -624,89 +624,89 @@  discard block
 block discarded – undo
624 624
 	| fees.
625 625
     */
626 626
 
627
-	/**
628
-	 * Prepares the submission's fees.
629
-	 *
630
-	 * @since 1.0.19
631
-	 */
632
-	public function process_fees() {
633
-
634
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
635
-
636
-		foreach ( $fees_processor->fees as $fee ) {
637
-			$this->add_fee( $fee );
638
-		}
639
-
640
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
641
-	}
642
-
643
-	/**
644
-	 * Adds a fee to the submission.
645
-	 *
646
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
647
-	 * @since 1.0.19
648
-	 */
649
-	public function add_fee( $fee ) {
650
-
651
-		$this->fees[ $fee['name'] ]         = $fee;
652
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
653
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
654
-
655
-	}
656
-
657
-	/**
658
-	 * Removes a fee from the submission.
659
-	 *
660
-	 * @since 1.0.19
661
-	 */
662
-	public function remove_fee( $name ) {
663
-
664
-		if ( isset( $this->fees[ $name ] ) ) {
665
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
666
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
667
-			unset( $this->fees[ $name ] );
668
-		}
669
-
670
-	}
671
-
672
-	/**
673
-	 * Returns the fees.
674
-	 *
675
-	 * @since 1.0.19
676
-	 */
677
-	public function get_fee() {
678
-		return $this->totals['fees']['initial'];
679
-	}
680
-
681
-	/**
682
-	 * Returns the recurring fees.
683
-	 *
684
-	 * @since 1.0.19
685
-	 */
686
-	public function get_recurring_fee() {
687
-		return $this->totals['fees']['recurring'];
688
-	}
689
-
690
-	/**
691
-	 * Returns all fees.
692
-	 *
693
-	 * @since 1.0.19
694
-	 */
695
-	public function get_fees() {
696
-		return $this->fees;
697
-	}
698
-
699
-	/**
700
-	 * Checks if there are any fees for the form.
701
-	 *
702
-	 * @return bool
703
-	 * @since 1.0.19
704
-	 */
705
-	public function has_fees() {
706
-		return count( $this->fees ) !== 0;
707
-	}
708
-
709
-	/*
627
+    /**
628
+     * Prepares the submission's fees.
629
+     *
630
+     * @since 1.0.19
631
+     */
632
+    public function process_fees() {
633
+
634
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
635
+
636
+        foreach ( $fees_processor->fees as $fee ) {
637
+            $this->add_fee( $fee );
638
+        }
639
+
640
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
641
+    }
642
+
643
+    /**
644
+     * Adds a fee to the submission.
645
+     *
646
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
647
+     * @since 1.0.19
648
+     */
649
+    public function add_fee( $fee ) {
650
+
651
+        $this->fees[ $fee['name'] ]         = $fee;
652
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
653
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
654
+
655
+    }
656
+
657
+    /**
658
+     * Removes a fee from the submission.
659
+     *
660
+     * @since 1.0.19
661
+     */
662
+    public function remove_fee( $name ) {
663
+
664
+        if ( isset( $this->fees[ $name ] ) ) {
665
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
666
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
667
+            unset( $this->fees[ $name ] );
668
+        }
669
+
670
+    }
671
+
672
+    /**
673
+     * Returns the fees.
674
+     *
675
+     * @since 1.0.19
676
+     */
677
+    public function get_fee() {
678
+        return $this->totals['fees']['initial'];
679
+    }
680
+
681
+    /**
682
+     * Returns the recurring fees.
683
+     *
684
+     * @since 1.0.19
685
+     */
686
+    public function get_recurring_fee() {
687
+        return $this->totals['fees']['recurring'];
688
+    }
689
+
690
+    /**
691
+     * Returns all fees.
692
+     *
693
+     * @since 1.0.19
694
+     */
695
+    public function get_fees() {
696
+        return $this->fees;
697
+    }
698
+
699
+    /**
700
+     * Checks if there are any fees for the form.
701
+     *
702
+     * @return bool
703
+     * @since 1.0.19
704
+     */
705
+    public function has_fees() {
706
+        return count( $this->fees ) !== 0;
707
+    }
708
+
709
+    /*
710 710
 	|--------------------------------------------------------------------------
711 711
 	| MISC
712 712
 	|--------------------------------------------------------------------------
@@ -714,109 +714,109 @@  discard block
 block discarded – undo
714 714
 	| Extra submission functions.
715 715
     */
716 716
 
717
-	/**
718
-	 * Returns the total amount to collect for this submission.
719
-	 *
720
-	 * @since 1.0.19
721
-	 */
722
-	public function get_total() {
723
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
724
-		return max( $total, 0 );
725
-	}
726
-
727
-	/**
728
-	 * Returns the recurring total amount to collect for this submission.
729
-	 *
730
-	 * @since 1.0.19
731
-	 */
732
-	public function get_recurring_total() {
733
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
734
-		return max( $total, 0 );
735
-	}
736
-
737
-	/**
738
-	 * Whether payment details should be collected for this submission.
739
-	 *
740
-	 * @since 1.0.19
741
-	 */
742
-	public function should_collect_payment_details() {
743
-		$initial   = $this->get_total();
744
-		$recurring = $this->get_recurring_total();
745
-
746
-		if ( $this->has_recurring == 0 ) {
747
-			$recurring = 0;
748
-		}
749
-
750
-		$collect = $initial > 0 || $recurring > 0;
751
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
752
-	}
753
-
754
-	/**
755
-	 * Returns the billing email of the user.
756
-	 *
757
-	 * @since 1.0.19
758
-	 */
759
-	public function get_billing_email() {
760
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
761
-	}
762
-
763
-	/**
764
-	 * Checks if the submitter has a billing email.
765
-	 *
766
-	 * @since 1.0.19
767
-	 */
768
-	public function has_billing_email() {
769
-		$billing_email = $this->get_billing_email();
770
-		return ! empty( $billing_email ) && is_email( $billing_email );
771
-	}
772
-
773
-	/**
774
-	 * Returns the appropriate currency for the submission.
775
-	 *
776
-	 * @since 1.0.19
777
-	 * @return string
778
-	 */
779
-	public function get_currency() {
780
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
781
-    }
782
-
783
-    /**
784
-	 * Returns the raw submission data.
785
-	 *
786
-	 * @since 1.0.19
787
-	 * @return array
788
-	 */
789
-	public function get_data() {
790
-		return $this->data;
791
-	}
792
-
793
-	/**
794
-	 * Returns a field from the submission data
795
-	 *
796
-	 * @param string $field
797
-	 * @since 1.0.19
798
-	 * @return mixed|null
799
-	 */
800
-	public function get_field( $field, $sub_array_key = null ) {
801
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
802
-	}
803
-
804
-	/**
805
-	 * Checks if a required field is set.
806
-	 *
807
-	 * @since 1.0.19
808
-	 */
809
-	public function is_required_field_set( $field ) {
810
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
811
-	}
812
-
813
-	/**
814
-	 * Formats an amount
815
-	 *
816
-	 * @since 1.0.19
817
-	 */
818
-	public function format_amount( $amount ) {
819
-		return wpinv_price( $amount, $this->get_currency() );
820
-	}
717
+    /**
718
+     * Returns the total amount to collect for this submission.
719
+     *
720
+     * @since 1.0.19
721
+     */
722
+    public function get_total() {
723
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
724
+        return max( $total, 0 );
725
+    }
726
+
727
+    /**
728
+     * Returns the recurring total amount to collect for this submission.
729
+     *
730
+     * @since 1.0.19
731
+     */
732
+    public function get_recurring_total() {
733
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
734
+        return max( $total, 0 );
735
+    }
736
+
737
+    /**
738
+     * Whether payment details should be collected for this submission.
739
+     *
740
+     * @since 1.0.19
741
+     */
742
+    public function should_collect_payment_details() {
743
+        $initial   = $this->get_total();
744
+        $recurring = $this->get_recurring_total();
745
+
746
+        if ( $this->has_recurring == 0 ) {
747
+            $recurring = 0;
748
+        }
749
+
750
+        $collect = $initial > 0 || $recurring > 0;
751
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
752
+    }
753
+
754
+    /**
755
+     * Returns the billing email of the user.
756
+     *
757
+     * @since 1.0.19
758
+     */
759
+    public function get_billing_email() {
760
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
761
+    }
762
+
763
+    /**
764
+     * Checks if the submitter has a billing email.
765
+     *
766
+     * @since 1.0.19
767
+     */
768
+    public function has_billing_email() {
769
+        $billing_email = $this->get_billing_email();
770
+        return ! empty( $billing_email ) && is_email( $billing_email );
771
+    }
772
+
773
+    /**
774
+     * Returns the appropriate currency for the submission.
775
+     *
776
+     * @since 1.0.19
777
+     * @return string
778
+     */
779
+    public function get_currency() {
780
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
781
+    }
782
+
783
+    /**
784
+     * Returns the raw submission data.
785
+     *
786
+     * @since 1.0.19
787
+     * @return array
788
+     */
789
+    public function get_data() {
790
+        return $this->data;
791
+    }
792
+
793
+    /**
794
+     * Returns a field from the submission data
795
+     *
796
+     * @param string $field
797
+     * @since 1.0.19
798
+     * @return mixed|null
799
+     */
800
+    public function get_field( $field, $sub_array_key = null ) {
801
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
802
+    }
803
+
804
+    /**
805
+     * Checks if a required field is set.
806
+     *
807
+     * @since 1.0.19
808
+     */
809
+    public function is_required_field_set( $field ) {
810
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
811
+    }
812
+
813
+    /**
814
+     * Formats an amount
815
+     *
816
+     * @since 1.0.19
817
+     */
818
+    public function format_amount( $amount ) {
819
+        return wpinv_price( $amount, $this->get_currency() );
820
+    }
821 821
 
822 822
 }
Please login to merge, or discard this patch.
Spacing   +108 added lines, -108 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_taxes' ),
175
-					array( $this, 'process_discount' ),
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_taxes'),
175
+					array($this, 'process_discount'),
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,30 +248,30 @@  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
-		$this->payment_form->set_items( $invoice->get_items() );
267
+		$this->payment_form->set_items($invoice->get_items());
268 268
 		$this->payment_form->invoice = $invoice;
269 269
 
270 270
 		$this->country = $invoice->get_country();
271 271
 		$this->state   = $invoice->get_state();
272 272
 		$this->invoice = $invoice;
273 273
 
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
274
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
275 275
 	}
276 276
 
277 277
 	/**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 */
293 293
 	public function has_invoice() {
294
-		return ! empty( $this->invoice );
294
+		return !empty($this->invoice);
295 295
 	}
296 296
 
297 297
 	/*
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 	 */
311 311
 	public function process_items() {
312 312
 
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
313
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
314 314
 
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
315
+		foreach ($processor->items as $item) {
316
+			$this->add_item($item);
317 317
 		}
318 318
 
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
319
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
320 320
 	}
321 321
 
322 322
 	/**
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
 	 * @since 1.0.19
326 326
 	 * @param GetPaid_Form_Item $item
327 327
 	 */
328
-	public function add_item( $item ) {
328
+	public function add_item($item) {
329 329
 
330 330
 		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() ) {
331
+		if (!$item->can_purchase()) {
332 332
 			return;
333 333
 		}
334 334
 
335 335
 		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
336
+		if ($item->is_recurring()) {
337 337
 
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
338
+			if ($this->has_recurring != 0) {
339
+				throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing'));
340 340
 			}
341 341
 
342 342
 			$this->has_recurring = $item->get_id();
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		}
345 345
 
346 346
 		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
347
+		$this->items[$item->get_id()]         = $item;
348 348
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349 349
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350 350
 
@@ -358,17 +358,17 @@  discard block
 block discarded – undo
358 358
 	 *
359 359
 	 * @since 1.0.19
360 360
 	 */
361
-	public function remove_item( $item_id ) {
361
+	public function remove_item($item_id) {
362 362
 
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
363
+		if (isset($this->items[$item_id])) {
364
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
365
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
366 366
 
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
367
+			if ($this->items[$item_id]->is_recurring()) {
368 368
 				$this->has_recurring = 0;
369 369
 			}
370 370
 
371
-			unset( $this->items[ $item_id ] );
371
+			unset($this->items[$item_id]);
372 372
 		}
373 373
 		
374 374
 	}
@@ -418,28 +418,28 @@  discard block
 block discarded – undo
418 418
 	public function process_taxes() {
419 419
 
420 420
 		// Abort if we're not using taxes.
421
-		if ( ! $this->use_taxes() ) {
421
+		if (!$this->use_taxes()) {
422 422
 			return;
423 423
 		}
424 424
 
425 425
 		// If a custom country && state has been passed in, use it to calculate taxes.
426
-		$country = $this->get_field( 'wpinv_country', 'billing' );
427
-		if ( ! empty( $country ) ) {
426
+		$country = $this->get_field('wpinv_country', 'billing');
427
+		if (!empty($country)) {
428 428
 			$this->country = $country;
429 429
 		}
430 430
 
431
-		$state = $this->get_field( 'wpinv_state', 'billing' );
432
-		if ( ! empty( $state ) ) {
431
+		$state = $this->get_field('wpinv_state', 'billing');
432
+		if (!empty($state)) {
433 433
 			$this->state = $state;
434 434
 		}
435 435
 
436
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
436
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
437 437
 
438
-		foreach ( $processor->taxes as $tax ) {
439
-			$this->add_tax( $tax );
438
+		foreach ($processor->taxes as $tax) {
439
+			$this->add_tax($tax);
440 440
 		}
441 441
 
442
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
442
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
443 443
 	}
444 444
 
445 445
 	/**
@@ -448,10 +448,10 @@  discard block
 block discarded – undo
448 448
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
449 449
 	 * @since 1.0.19
450 450
 	 */
451
-	public function add_tax( $tax ) {
452
-		$this->taxes[ $tax['name'] ]         = $tax;
453
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
454
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
451
+	public function add_tax($tax) {
452
+		$this->taxes[$tax['name']]         = $tax;
453
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
454
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
455 455
 	}
456 456
 
457 457
 	/**
@@ -459,12 +459,12 @@  discard block
 block discarded – undo
459 459
 	 *
460 460
 	 * @since 1.0.19
461 461
 	 */
462
-	public function remove_tax( $tax_name ) {
462
+	public function remove_tax($tax_name) {
463 463
 
464
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
465
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
466
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
467
-			unset( $this->taxes[ $tax_name ] );
464
+		if (isset($this->taxes[$tax_name])) {
465
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
466
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
467
+			unset($this->taxes[$tax_name]);
468 468
 		}
469 469
 
470 470
 	}
@@ -478,11 +478,11 @@  discard block
 block discarded – undo
478 478
 
479 479
 		$use_taxes = wpinv_use_taxes();
480 480
 
481
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
481
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
482 482
 			$use_taxes = false;
483 483
 		}
484 484
 
485
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
485
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
486 486
 
487 487
 	}
488 488
 
@@ -531,13 +531,13 @@  discard block
 block discarded – undo
531 531
 
532 532
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
533 533
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
534
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
534
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
535 535
 
536
-		foreach ( $processor->discounts as $discount ) {
537
-			$this->add_discount( $discount );
536
+		foreach ($processor->discounts as $discount) {
537
+			$this->add_discount($discount);
538 538
 		}
539 539
 
540
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
540
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
541 541
 	}
542 542
 
543 543
 	/**
@@ -546,10 +546,10 @@  discard block
 block discarded – undo
546 546
 	 * @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.
547 547
 	 * @since 1.0.19
548 548
 	 */
549
-	public function add_discount( $discount ) {
550
-		$this->discounts[ $discount['name'] ]   = $discount;
551
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
552
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
549
+	public function add_discount($discount) {
550
+		$this->discounts[$discount['name']]   = $discount;
551
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
552
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
553 553
 	}
554 554
 
555 555
 	/**
@@ -557,12 +557,12 @@  discard block
 block discarded – undo
557 557
 	 *
558 558
 	 * @since 1.0.19
559 559
 	 */
560
-	public function remove_discount( $name ) {
560
+	public function remove_discount($name) {
561 561
 
562
-		if ( isset( $this->discounts[ $name ] ) ) {
563
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
564
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
565
-			unset( $this->discounts[ $name ] );
562
+		if (isset($this->discounts[$name])) {
563
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
564
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
565
+			unset($this->discounts[$name]);
566 566
 		}
567 567
 
568 568
 	}
@@ -574,7 +574,7 @@  discard block
 block discarded – undo
574 574
 	 * @return bool
575 575
 	 */
576 576
 	public function has_discount_code() {
577
-		return ! empty( $this->discounts['discount_code'] );
577
+		return !empty($this->discounts['discount_code']);
578 578
 	}
579 579
 
580 580
 	/**
@@ -631,13 +631,13 @@  discard block
 block discarded – undo
631 631
 	 */
632 632
 	public function process_fees() {
633 633
 
634
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
634
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
635 635
 
636
-		foreach ( $fees_processor->fees as $fee ) {
637
-			$this->add_fee( $fee );
636
+		foreach ($fees_processor->fees as $fee) {
637
+			$this->add_fee($fee);
638 638
 		}
639 639
 
640
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
640
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
641 641
 	}
642 642
 
643 643
 	/**
@@ -646,11 +646,11 @@  discard block
 block discarded – undo
646 646
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
647 647
 	 * @since 1.0.19
648 648
 	 */
649
-	public function add_fee( $fee ) {
649
+	public function add_fee($fee) {
650 650
 
651
-		$this->fees[ $fee['name'] ]         = $fee;
652
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
653
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
651
+		$this->fees[$fee['name']]         = $fee;
652
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
653
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
654 654
 
655 655
 	}
656 656
 
@@ -659,12 +659,12 @@  discard block
 block discarded – undo
659 659
 	 *
660 660
 	 * @since 1.0.19
661 661
 	 */
662
-	public function remove_fee( $name ) {
662
+	public function remove_fee($name) {
663 663
 
664
-		if ( isset( $this->fees[ $name ] ) ) {
665
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
666
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
667
-			unset( $this->fees[ $name ] );
664
+		if (isset($this->fees[$name])) {
665
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
666
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
667
+			unset($this->fees[$name]);
668 668
 		}
669 669
 
670 670
 	}
@@ -703,7 +703,7 @@  discard block
 block discarded – undo
703 703
 	 * @since 1.0.19
704 704
 	 */
705 705
 	public function has_fees() {
706
-		return count( $this->fees ) !== 0;
706
+		return count($this->fees) !== 0;
707 707
 	}
708 708
 
709 709
 	/*
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
 	 */
722 722
 	public function get_total() {
723 723
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
724
-		return max( $total, 0 );
724
+		return max($total, 0);
725 725
 	}
726 726
 
727 727
 	/**
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 	 */
732 732
 	public function get_recurring_total() {
733 733
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
734
-		return max( $total, 0 );
734
+		return max($total, 0);
735 735
 	}
736 736
 
737 737
 	/**
@@ -743,12 +743,12 @@  discard block
 block discarded – undo
743 743
 		$initial   = $this->get_total();
744 744
 		$recurring = $this->get_recurring_total();
745 745
 
746
-		if ( $this->has_recurring == 0 ) {
746
+		if ($this->has_recurring == 0) {
747 747
 			$recurring = 0;
748 748
 		}
749 749
 
750 750
 		$collect = $initial > 0 || $recurring > 0;
751
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
751
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
752 752
 	}
753 753
 
754 754
 	/**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 * @since 1.0.19
758 758
 	 */
759 759
 	public function get_billing_email() {
760
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
760
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
761 761
 	}
762 762
 
763 763
 	/**
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
 	 */
768 768
 	public function has_billing_email() {
769 769
 		$billing_email = $this->get_billing_email();
770
-		return ! empty( $billing_email ) && is_email( $billing_email );
770
+		return !empty($billing_email) && is_email($billing_email);
771 771
 	}
772 772
 
773 773
 	/**
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
 	 * @since 1.0.19
798 798
 	 * @return mixed|null
799 799
 	 */
800
-	public function get_field( $field, $sub_array_key = null ) {
801
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
800
+	public function get_field($field, $sub_array_key = null) {
801
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
802 802
 	}
803 803
 
804 804
 	/**
@@ -806,8 +806,8 @@  discard block
 block discarded – undo
806 806
 	 *
807 807
 	 * @since 1.0.19
808 808
 	 */
809
-	public function is_required_field_set( $field ) {
810
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
809
+	public function is_required_field_set($field) {
810
+		return empty($field['required']) || !empty($this->data[$field['id']]);
811 811
 	}
812 812
 
813 813
 	/**
@@ -815,8 +815,8 @@  discard block
 block discarded – undo
815 815
 	 *
816 816
 	 * @since 1.0.19
817 817
 	 */
818
-	public function format_amount( $amount ) {
819
-		return wpinv_price( $amount, $this->get_currency() );
818
+	public function format_amount($amount) {
819
+		return wpinv_price($amount, $this->get_currency());
820 820
 	}
821 821
 
822 822
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -12,174 +12,174 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 * 
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     * 
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->recalculate_total();
50 50
         $invoice->save();
51 51
 
52
-		// Send to the gateway.
53
-		$this->post_process_submission( $invoice, $prepared, $shipping );
54
-	}
52
+        // Send to the gateway.
53
+        $this->post_process_submission( $invoice, $prepared, $shipping );
54
+    }
55 55
 
56
-	/**
57
-	 * Validates the submission.
58
-	 *
59
-	 */
60
-	protected function validate_submission() {
56
+    /**
57
+     * Validates the submission.
58
+     *
59
+     */
60
+    protected function validate_submission() {
61 61
 
62
-		$submission = $this->payment_form_submission;
63
-		$data       = $submission->get_data();
62
+        $submission = $this->payment_form_submission;
63
+        $data       = $submission->get_data();
64 64
 
65
-		// Do we have an error?
65
+        // Do we have an error?
66 66
         if ( ! empty( $submission->last_error ) ) {
67
-			wp_send_json_error( $submission->last_error );
67
+            wp_send_json_error( $submission->last_error );
68 68
         }
69 69
 
70
-		// We need a billing email.
70
+        // We need a billing email.
71 71
         if ( ! $submission->has_billing_email() ) {
72 72
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
73
-		}
73
+        }
74 74
 
75
-		// Non-recurring gateways should not be allowed to process recurring invoices.
76
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
77
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
78
-		}
75
+        // Non-recurring gateways should not be allowed to process recurring invoices.
76
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
77
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
78
+        }
79 79
 
80
-		// Ensure the gateway is active.
81
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
82
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
83
-		}
80
+        // Ensure the gateway is active.
81
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
82
+            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
83
+        }
84 84
 
85
-		// Clear any existing errors.
86
-		wpinv_clear_errors();
85
+        // Clear any existing errors.
86
+        wpinv_clear_errors();
87 87
 
88
-		// Allow themes and plugins to hook to errors
89
-		do_action( 'getpaid_checkout_error_checks', $submission );
88
+        // Allow themes and plugins to hook to errors
89
+        do_action( 'getpaid_checkout_error_checks', $submission );
90 90
 
91
-		// Do we have any errors?
91
+        // Do we have any errors?
92 92
         if ( wpinv_get_errors() ) {
93 93
             wp_send_json_error( getpaid_get_errors_html() );
94
-		}
94
+        }
95 95
 
96
-	}
96
+    }
97 97
 
98
-	/**
99
-	 * Retrieves submission items.
100
-	 *
101
-	 * @return GetPaid_Form_Item[]
102
-	 */
103
-	protected function get_submission_items() {
98
+    /**
99
+     * Retrieves submission items.
100
+     *
101
+     * @return GetPaid_Form_Item[]
102
+     */
103
+    protected function get_submission_items() {
104 104
 
105
-		$items = $this->payment_form_submission->get_items();
105
+        $items = $this->payment_form_submission->get_items();
106 106
 
107 107
         // Ensure that we have items.
108 108
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
109 109
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
110
-		}
111
-
112
-		return $items;
113
-	}
114
-
115
-	/**
116
-	 * Retrieves submission invoice.
117
-	 *
118
-	 * @return WPInv_Invoice
119
-	 */
120
-	protected function get_submission_invoice() {
121
-		$submission = $this->payment_form_submission;
122
-
123
-		if ( ! $submission->has_invoice() ) {
124
-			$invoice = new WPInv_Invoice();
125
-			$invoice->created_via( 'payment_form' );
126
-			return $invoice;
127 110
         }
128 111
 
129
-		$invoice = $submission->get_invoice();
112
+        return $items;
113
+    }
130 114
 
131
-		// Make sure that it is neither paid or refunded.
132
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
133
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
134
-		}
115
+    /**
116
+     * Retrieves submission invoice.
117
+     *
118
+     * @return WPInv_Invoice
119
+     */
120
+    protected function get_submission_invoice() {
121
+        $submission = $this->payment_form_submission;
135 122
 
136
-		return $invoice;
137
-	}
123
+        if ( ! $submission->has_invoice() ) {
124
+            $invoice = new WPInv_Invoice();
125
+            $invoice->created_via( 'payment_form' );
126
+            return $invoice;
127
+        }
138 128
 
139
-	/**
140
-	 * Processes the submission invoice.
141
-	 *
142
-	 * @param WPInv_Invoice $invoice
143
-	 * @param GetPaid_Form_Item[] $items
144
-	 * @return WPInv_Invoice
145
-	 */
146
-	protected function process_submission_invoice( $invoice, $items ) {
129
+        $invoice = $submission->get_invoice();
147 130
 
148
-		$submission = $this->payment_form_submission;
149
-		$data       = $submission->get_data();
131
+        // Make sure that it is neither paid or refunded.
132
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
133
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
134
+        }
150 135
 
151
-		// Set-up the invoice details.
152
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
153
-		$invoice->set_user_id( $this->get_submission_customer() );
154
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
136
+        return $invoice;
137
+    }
138
+
139
+    /**
140
+     * Processes the submission invoice.
141
+     *
142
+     * @param WPInv_Invoice $invoice
143
+     * @param GetPaid_Form_Item[] $items
144
+     * @return WPInv_Invoice
145
+     */
146
+    protected function process_submission_invoice( $invoice, $items ) {
147
+
148
+        $submission = $this->payment_form_submission;
149
+        $data       = $submission->get_data();
150
+
151
+        // Set-up the invoice details.
152
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
153
+        $invoice->set_user_id( $this->get_submission_customer() );
154
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
155 155
         $invoice->set_items( $items );
156 156
         $invoice->set_fees( $submission->get_fees() );
157 157
         $invoice->set_taxes( $submission->get_taxes() );
158
-		$invoice->set_discounts( $submission->get_discounts() );
159
-		$invoice->set_gateway( $data['wpi-gateway'] );
158
+        $invoice->set_discounts( $submission->get_discounts() );
159
+        $invoice->set_gateway( $data['wpi-gateway'] );
160 160
 
161
-		if ( $submission->has_discount_code() ) {
161
+        if ( $submission->has_discount_code() ) {
162 162
             $invoice->set_discount_code( $submission->get_discount_code() );
163
-		}
164
-
165
-		getpaid_maybe_add_default_address( $invoice );
166
-		return $invoice;
167
-	}
168
-
169
-	/**
170
-	 * Retrieves the submission's customer.
171
-	 *
172
-	 * @return int The customer id.
173
-	 */
174
-	protected function get_submission_customer() {
175
-		$submission = $this->payment_form_submission;
176
-
177
-		// If this is an existing invoice...
178
-		if ( $submission->has_invoice() ) {
179
-			return $submission->get_invoice()->get_user_id();
180
-		}
181
-
182
-		// (Maybe) create the user.
163
+        }
164
+
165
+        getpaid_maybe_add_default_address( $invoice );
166
+        return $invoice;
167
+    }
168
+
169
+    /**
170
+     * Retrieves the submission's customer.
171
+     *
172
+     * @return int The customer id.
173
+     */
174
+    protected function get_submission_customer() {
175
+        $submission = $this->payment_form_submission;
176
+
177
+        // If this is an existing invoice...
178
+        if ( $submission->has_invoice() ) {
179
+            return $submission->get_invoice()->get_user_id();
180
+        }
181
+
182
+        // (Maybe) create the user.
183 183
         $user = get_current_user_id();
184 184
 
185 185
         if ( empty( $user ) ) {
@@ -196,31 +196,31 @@  discard block
 block discarded – undo
196 196
 
197 197
         if ( is_numeric( $user ) ) {
198 198
             return $user;
199
-		}
199
+        }
200 200
 
201
-		return $user->ID;
201
+        return $user->ID;
202 202
 
203
-	}
203
+    }
204 204
 
205
-	/**
205
+    /**
206 206
      * Prepares submission data for saving to the database.
207 207
      *
208
-	 * @return array
208
+     * @return array
209 209
      */
210 210
     public function prepare_submission_data_for_saving() {
211 211
 
212
-		$submission = $this->payment_form_submission;
212
+        $submission = $this->payment_form_submission;
213 213
 
214
-		// Prepared submission details.
214
+        // Prepared submission details.
215 215
         $prepared = array();
216 216
 
217 217
         // Raw submission details.
218
-		$data     = $submission->get_data();
218
+        $data     = $submission->get_data();
219 219
 
220
-		// Loop through the submitted details.
220
+        // Loop through the submitted details.
221 221
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
222 222
 
223
-			// Skip premade fields.
223
+            // Skip premade fields.
224 224
             if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
225 225
                 continue;
226 226
             }
@@ -238,93 +238,93 @@  discard block
 block discarded – undo
238 238
                     $label = $field['label'];
239 239
                 }
240 240
 
241
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
241
+                $prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
242 242
 
243 243
             }
244 244
 
245
-		}
245
+        }
246 246
 
247
-		return $prepared;
247
+        return $prepared;
248 248
 
249
-	}
249
+    }
250 250
 
251
-	/**
251
+    /**
252 252
      * Retrieves address details.
253 253
      *
254
-	 * @return array
255
-	 * @param WPInv_Invoice $invoice
256
-	 * @param string $type
254
+     * @return array
255
+     * @param WPInv_Invoice $invoice
256
+     * @param string $type
257 257
      */
258 258
     public function prepare_address_details( $invoice, $type = 'billing' ) {
259 259
 
260
-		$data     = $this->payment_form_submission->get_data();
261
-		$type     = sanitize_key( $type );
262
-		$address  = array();
263
-		$prepared = array();
260
+        $data     = $this->payment_form_submission->get_data();
261
+        $type     = sanitize_key( $type );
262
+        $address  = array();
263
+        $prepared = array();
264 264
 
265
-		if ( ! empty( $data[ $type ] ) ) {
266
-			$address = $data[ $type ];
267
-		}
265
+        if ( ! empty( $data[ $type ] ) ) {
266
+            $address = $data[ $type ];
267
+        }
268 268
 
269
-		// Clean address details.
270
-		foreach ( $address as $key => $value ) {
271
-			$key             = sanitize_key( $key );
272
-			$key             = str_replace( 'wpinv_', '', $key );
273
-			$value           = wpinv_clean( $value );
274
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
275
-		}
269
+        // Clean address details.
270
+        foreach ( $address as $key => $value ) {
271
+            $key             = sanitize_key( $key );
272
+            $key             = str_replace( 'wpinv_', '', $key );
273
+            $value           = wpinv_clean( $value );
274
+            $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
275
+        }
276 276
 
277
-		// Filter address details.
278
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
277
+        // Filter address details.
278
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
279 279
 
280
-		// Remove non-whitelisted values.
281
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
280
+        // Remove non-whitelisted values.
281
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
282 282
 
283
-	}
283
+    }
284 284
 
285
-	/**
285
+    /**
286 286
      * Prepares the billing details.
287 287
      *
288
-	 * @return array
289
-	 * @param WPInv_Invoice $invoice
288
+     * @return array
289
+     * @param WPInv_Invoice $invoice
290 290
      */
291 291
     protected function prepare_billing_info( &$invoice ) {
292 292
 
293
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
293
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
294 294
 
295
-		// Update the invoice with the billing details.
296
-		$invoice->set_props( $billing_address );
295
+        // Update the invoice with the billing details.
296
+        $invoice->set_props( $billing_address );
297 297
 
298
-	}
298
+    }
299 299
 
300
-	/**
300
+    /**
301 301
      * Prepares the shipping details.
302 302
      *
303
-	 * @return array
304
-	 * @param WPInv_Invoice $invoice
303
+     * @return array
304
+     * @param WPInv_Invoice $invoice
305 305
      */
306 306
     protected function prepare_shipping_info( $invoice ) {
307 307
 
308
-		$data = $this->payment_form_submission->get_data();
308
+        $data = $this->payment_form_submission->get_data();
309 309
 
310
-		if ( empty( $data['same-shipping-address'] ) ) {
311
-			return $this->prepare_address_details( $invoice, 'shipping' );
312
-		}
310
+        if ( empty( $data['same-shipping-address'] ) ) {
311
+            return $this->prepare_address_details( $invoice, 'shipping' );
312
+        }
313 313
 
314
-		return $this->prepare_address_details( $invoice, 'billing' );
314
+        return $this->prepare_address_details( $invoice, 'billing' );
315 315
 
316
-	}
316
+    }
317 317
 
318
-	/**
319
-	 * Confirms the submission is valid and send users to the gateway.
320
-	 *
321
-	 * @param WPInv_Invoice $invoice
322
-	 * @param array $prepared_payment_form_data
323
-	 * @param array $shipping
324
-	 */
325
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
318
+    /**
319
+     * Confirms the submission is valid and send users to the gateway.
320
+     *
321
+     * @param WPInv_Invoice $invoice
322
+     * @param array $prepared_payment_form_data
323
+     * @param array $shipping
324
+     */
325
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
326 326
 
327
-		// Ensure the invoice exists.
327
+        // Ensure the invoice exists.
328 328
         if ( ! $invoice->exists() ) {
329 329
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
330 330
         }
@@ -332,81 +332,81 @@  discard block
 block discarded – undo
332 332
         // Save payment form data.
333 333
         if ( ! empty( $prepared_payment_form_data ) ) {
334 334
             update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
335
-		}
335
+        }
336 336
 
337
-		// Save payment form data.
337
+        // Save payment form data.
338 338
         if ( ! empty( $shipping ) ) {
339 339
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
340
-		}
340
+        }
341 341
 
342
-		// Backwards compatibility.
342
+        // Backwards compatibility.
343 343
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
344 344
 
345
-		$this->process_payment( $invoice );
345
+        $this->process_payment( $invoice );
346 346
 
347 347
         // If we are here, there was an error.
348
-		wpinv_send_back_to_checkout();
348
+        wpinv_send_back_to_checkout();
349 349
 
350
-	}
350
+    }
351 351
 
352
-	/**
353
-	 * Processes the actual payment.
354
-	 *
355
-	 * @param WPInv_Invoice $invoice
356
-	 */
357
-	protected function process_payment( $invoice ) {
352
+    /**
353
+     * Processes the actual payment.
354
+     *
355
+     * @param WPInv_Invoice $invoice
356
+     */
357
+    protected function process_payment( $invoice ) {
358 358
 
359
-		// Clear any checkout errors.
360
-		wpinv_clear_errors();
359
+        // Clear any checkout errors.
360
+        wpinv_clear_errors();
361 361
 
362
-		// No need to send free invoices to the gateway.
363
-		if ( $invoice->is_free() ) {
364
-			$this->process_free_payment( $invoice );
365
-		}
362
+        // No need to send free invoices to the gateway.
363
+        if ( $invoice->is_free() ) {
364
+            $this->process_free_payment( $invoice );
365
+        }
366 366
 
367
-		$submission = $this->payment_form_submission;
367
+        $submission = $this->payment_form_submission;
368 368
 
369
-		// Fires before sending to the gateway.
370
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
369
+        // Fires before sending to the gateway.
370
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
371 371
 
372
-		// Allow the sumission data to be modified before it is sent to the gateway.
373
-		$submission_data    = $submission->get_data();
374
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
375
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
372
+        // Allow the sumission data to be modified before it is sent to the gateway.
373
+        $submission_data    = $submission->get_data();
374
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
375
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
376 376
 
377
-		// Validate the currency.
378
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
379
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
380
-		}
377
+        // Validate the currency.
378
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
379
+            wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
380
+        }
381 381
 
382
-		// Check to see if we have any errors.
383
-		if ( wpinv_get_errors() ) {
384
-			wpinv_send_back_to_checkout();
385
-		}
382
+        // Check to see if we have any errors.
383
+        if ( wpinv_get_errors() ) {
384
+            wpinv_send_back_to_checkout();
385
+        }
386 386
 
387
-		// Send info to the gateway for payment processing
388
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
387
+        // Send info to the gateway for payment processing
388
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
389 389
 
390
-		// Backwards compatibility.
391
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
390
+        // Backwards compatibility.
391
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
392 392
 
393
-	}
393
+    }
394 394
 
395
-	/**
396
-	 * Marks the invoice as paid in case the checkout is free.
397
-	 *
398
-	 * @param WPInv_Invoice $invoice
399
-	 */
400
-	protected function process_free_payment( $invoice ) {
395
+    /**
396
+     * Marks the invoice as paid in case the checkout is free.
397
+     *
398
+     * @param WPInv_Invoice $invoice
399
+     */
400
+    protected function process_free_payment( $invoice ) {
401 401
 
402
-		$invoice->set_gateway( 'none' );
403
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
404
-		$invoice->mark_paid();
405
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
402
+        $invoice->set_gateway( 'none' );
403
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
404
+        $invoice->mark_paid();
405
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
406 406
 
407
-	}
407
+    }
408 408
 
409
-	/**
409
+    /**
410 410
      * Sends a redrect response to payment details.
411 411
      *
412 412
      */
Please login to merge, or discard this patch.
Spacing   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 * 
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,19 +38,19 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49 49
 		$invoice->recalculate_total();
50 50
         $invoice->save();
51 51
 
52 52
 		// Send to the gateway.
53
-		$this->post_process_submission( $invoice, $prepared, $shipping );
53
+		$this->post_process_submission($invoice, $prepared, $shipping);
54 54
 	}
55 55
 
56 56
 	/**
@@ -63,34 +63,34 @@  discard block
 block discarded – undo
63 63
 		$data       = $submission->get_data();
64 64
 
65 65
 		// Do we have an error?
66
-        if ( ! empty( $submission->last_error ) ) {
67
-			wp_send_json_error( $submission->last_error );
66
+        if (!empty($submission->last_error)) {
67
+			wp_send_json_error($submission->last_error);
68 68
         }
69 69
 
70 70
 		// We need a billing email.
71
-        if ( ! $submission->has_billing_email() ) {
72
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
71
+        if (!$submission->has_billing_email()) {
72
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
73 73
 		}
74 74
 
75 75
 		// Non-recurring gateways should not be allowed to process recurring invoices.
76
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
77
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
76
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
77
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
78 78
 		}
79 79
 
80 80
 		// Ensure the gateway is active.
81
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
82
-			wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not active', 'invoicing' ) );
81
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
82
+			wpinv_set_error('invalid_gateway', __('The selected payment gateway is not active', 'invoicing'));
83 83
 		}
84 84
 
85 85
 		// Clear any existing errors.
86 86
 		wpinv_clear_errors();
87 87
 
88 88
 		// Allow themes and plugins to hook to errors
89
-		do_action( 'getpaid_checkout_error_checks', $submission );
89
+		do_action('getpaid_checkout_error_checks', $submission);
90 90
 
91 91
 		// Do we have any errors?
92
-        if ( wpinv_get_errors() ) {
93
-            wp_send_json_error( getpaid_get_errors_html() );
92
+        if (wpinv_get_errors()) {
93
+            wp_send_json_error(getpaid_get_errors_html());
94 94
 		}
95 95
 
96 96
 	}
@@ -105,8 +105,8 @@  discard block
 block discarded – undo
105 105
 		$items = $this->payment_form_submission->get_items();
106 106
 
107 107
         // Ensure that we have items.
108
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
109
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
108
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
109
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
110 110
 		}
111 111
 
112 112
 		return $items;
@@ -120,17 +120,17 @@  discard block
 block discarded – undo
120 120
 	protected function get_submission_invoice() {
121 121
 		$submission = $this->payment_form_submission;
122 122
 
123
-		if ( ! $submission->has_invoice() ) {
123
+		if (!$submission->has_invoice()) {
124 124
 			$invoice = new WPInv_Invoice();
125
-			$invoice->created_via( 'payment_form' );
125
+			$invoice->created_via('payment_form');
126 126
 			return $invoice;
127 127
         }
128 128
 
129 129
 		$invoice = $submission->get_invoice();
130 130
 
131 131
 		// Make sure that it is neither paid or refunded.
132
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
133
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
132
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
133
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
134 134
 		}
135 135
 
136 136
 		return $invoice;
@@ -143,26 +143,26 @@  discard block
 block discarded – undo
143 143
 	 * @param GetPaid_Form_Item[] $items
144 144
 	 * @return WPInv_Invoice
145 145
 	 */
146
-	protected function process_submission_invoice( $invoice, $items ) {
146
+	protected function process_submission_invoice($invoice, $items) {
147 147
 
148 148
 		$submission = $this->payment_form_submission;
149 149
 		$data       = $submission->get_data();
150 150
 
151 151
 		// Set-up the invoice details.
152
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
153
-		$invoice->set_user_id( $this->get_submission_customer() );
154
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
155
-        $invoice->set_items( $items );
156
-        $invoice->set_fees( $submission->get_fees() );
157
-        $invoice->set_taxes( $submission->get_taxes() );
158
-		$invoice->set_discounts( $submission->get_discounts() );
159
-		$invoice->set_gateway( $data['wpi-gateway'] );
160
-
161
-		if ( $submission->has_discount_code() ) {
162
-            $invoice->set_discount_code( $submission->get_discount_code() );
152
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
153
+		$invoice->set_user_id($this->get_submission_customer());
154
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
155
+        $invoice->set_items($items);
156
+        $invoice->set_fees($submission->get_fees());
157
+        $invoice->set_taxes($submission->get_taxes());
158
+		$invoice->set_discounts($submission->get_discounts());
159
+		$invoice->set_gateway($data['wpi-gateway']);
160
+
161
+		if ($submission->has_discount_code()) {
162
+            $invoice->set_discount_code($submission->get_discount_code());
163 163
 		}
164 164
 
165
-		getpaid_maybe_add_default_address( $invoice );
165
+		getpaid_maybe_add_default_address($invoice);
166 166
 		return $invoice;
167 167
 	}
168 168
 
@@ -175,26 +175,26 @@  discard block
 block discarded – undo
175 175
 		$submission = $this->payment_form_submission;
176 176
 
177 177
 		// If this is an existing invoice...
178
-		if ( $submission->has_invoice() ) {
178
+		if ($submission->has_invoice()) {
179 179
 			return $submission->get_invoice()->get_user_id();
180 180
 		}
181 181
 
182 182
 		// (Maybe) create the user.
183 183
         $user = get_current_user_id();
184 184
 
185
-        if ( empty( $user ) ) {
186
-            $user = get_user_by( 'email', $submission->get_billing_email() );
185
+        if (empty($user)) {
186
+            $user = get_user_by('email', $submission->get_billing_email());
187 187
         }
188 188
 
189
-        if ( empty( $user ) ) {
190
-            $user = wpinv_create_user( $submission->get_billing_email() );
189
+        if (empty($user)) {
190
+            $user = wpinv_create_user($submission->get_billing_email());
191 191
         }
192 192
 
193
-        if ( is_wp_error( $user ) ) {
194
-            wp_send_json_error( $user->get_error_message() );
193
+        if (is_wp_error($user)) {
194
+            wp_send_json_error($user->get_error_message());
195 195
         }
196 196
 
197
-        if ( is_numeric( $user ) ) {
197
+        if (is_numeric($user)) {
198 198
             return $user;
199 199
 		}
200 200
 
@@ -215,30 +215,30 @@  discard block
 block discarded – undo
215 215
         $prepared = array();
216 216
 
217 217
         // Raw submission details.
218
-		$data     = $submission->get_data();
218
+		$data = $submission->get_data();
219 219
 
220 220
 		// Loop through the submitted details.
221
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
221
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
222 222
 
223 223
 			// Skip premade fields.
224
-            if ( ! empty( $field['premade'] ) || $field['type'] == 'address' ) {
224
+            if (!empty($field['premade']) || $field['type'] == 'address') {
225 225
                 continue;
226 226
             }
227 227
 
228 228
             // If it is required and not set, abort.
229
-            if ( ! $submission->is_required_field_set( $field ) ) {
230
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
229
+            if (!$submission->is_required_field_set($field)) {
230
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
231 231
             }
232 232
 
233 233
             // Handle misc fields.
234
-            if ( isset( $data[ $field['id'] ] ) ) {
234
+            if (isset($data[$field['id']])) {
235 235
                 $label = $field['id'];
236 236
 
237
-                if ( isset( $field['label'] ) ) {
237
+                if (isset($field['label'])) {
238 238
                     $label = $field['label'];
239 239
                 }
240 240
 
241
-				$prepared[ wpinv_clean( $label ) ] = wp_kses_post( $data[ $field['id'] ] );
241
+				$prepared[wpinv_clean($label)] = wp_kses_post($data[$field['id']]);
242 242
 
243 243
             }
244 244
 
@@ -255,30 +255,30 @@  discard block
 block discarded – undo
255 255
 	 * @param WPInv_Invoice $invoice
256 256
 	 * @param string $type
257 257
      */
258
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
258
+    public function prepare_address_details($invoice, $type = 'billing') {
259 259
 
260 260
 		$data     = $this->payment_form_submission->get_data();
261
-		$type     = sanitize_key( $type );
261
+		$type     = sanitize_key($type);
262 262
 		$address  = array();
263 263
 		$prepared = array();
264 264
 
265
-		if ( ! empty( $data[ $type ] ) ) {
266
-			$address = $data[ $type ];
265
+		if (!empty($data[$type])) {
266
+			$address = $data[$type];
267 267
 		}
268 268
 
269 269
 		// Clean address details.
270
-		foreach ( $address as $key => $value ) {
271
-			$key             = sanitize_key( $key );
272
-			$key             = str_replace( 'wpinv_', '', $key );
273
-			$value           = wpinv_clean( $value );
274
-			$prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
270
+		foreach ($address as $key => $value) {
271
+			$key             = sanitize_key($key);
272
+			$key             = str_replace('wpinv_', '', $key);
273
+			$value           = wpinv_clean($value);
274
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
275 275
 		}
276 276
 
277 277
 		// Filter address details.
278
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
278
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
279 279
 
280 280
 		// Remove non-whitelisted values.
281
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
281
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
282 282
 
283 283
 	}
284 284
 
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
 	 * @return array
289 289
 	 * @param WPInv_Invoice $invoice
290 290
      */
291
-    protected function prepare_billing_info( &$invoice ) {
291
+    protected function prepare_billing_info(&$invoice) {
292 292
 
293
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
293
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
294 294
 
295 295
 		// Update the invoice with the billing details.
296
-		$invoice->set_props( $billing_address );
296
+		$invoice->set_props($billing_address);
297 297
 
298 298
 	}
299 299
 
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @return array
304 304
 	 * @param WPInv_Invoice $invoice
305 305
      */
306
-    protected function prepare_shipping_info( $invoice ) {
306
+    protected function prepare_shipping_info($invoice) {
307 307
 
308 308
 		$data = $this->payment_form_submission->get_data();
309 309
 
310
-		if ( empty( $data['same-shipping-address'] ) ) {
311
-			return $this->prepare_address_details( $invoice, 'shipping' );
310
+		if (empty($data['same-shipping-address'])) {
311
+			return $this->prepare_address_details($invoice, 'shipping');
312 312
 		}
313 313
 
314
-		return $this->prepare_address_details( $invoice, 'billing' );
314
+		return $this->prepare_address_details($invoice, 'billing');
315 315
 
316 316
 	}
317 317
 
@@ -322,27 +322,27 @@  discard block
 block discarded – undo
322 322
 	 * @param array $prepared_payment_form_data
323 323
 	 * @param array $shipping
324 324
 	 */
325
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
325
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
326 326
 
327 327
 		// Ensure the invoice exists.
328
-        if ( ! $invoice->exists() ) {
329
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
328
+        if (!$invoice->exists()) {
329
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
330 330
         }
331 331
 
332 332
         // Save payment form data.
333
-        if ( ! empty( $prepared_payment_form_data ) ) {
334
-            update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data );
333
+        if (!empty($prepared_payment_form_data)) {
334
+            update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data);
335 335
 		}
336 336
 
337 337
 		// Save payment form data.
338
-        if ( ! empty( $shipping ) ) {
339
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
338
+        if (!empty($shipping)) {
339
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
340 340
 		}
341 341
 
342 342
 		// Backwards compatibility.
343
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
343
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
344 344
 
345
-		$this->process_payment( $invoice );
345
+		$this->process_payment($invoice);
346 346
 
347 347
         // If we are here, there was an error.
348 348
 		wpinv_send_back_to_checkout();
@@ -354,41 +354,41 @@  discard block
 block discarded – undo
354 354
 	 *
355 355
 	 * @param WPInv_Invoice $invoice
356 356
 	 */
357
-	protected function process_payment( $invoice ) {
357
+	protected function process_payment($invoice) {
358 358
 
359 359
 		// Clear any checkout errors.
360 360
 		wpinv_clear_errors();
361 361
 
362 362
 		// No need to send free invoices to the gateway.
363
-		if ( $invoice->is_free() ) {
364
-			$this->process_free_payment( $invoice );
363
+		if ($invoice->is_free()) {
364
+			$this->process_free_payment($invoice);
365 365
 		}
366 366
 
367 367
 		$submission = $this->payment_form_submission;
368 368
 
369 369
 		// Fires before sending to the gateway.
370
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
370
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
371 371
 
372 372
 		// Allow the sumission data to be modified before it is sent to the gateway.
373 373
 		$submission_data    = $submission->get_data();
374
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
375
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
374
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
375
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
376 376
 
377 377
 		// Validate the currency.
378
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
379
-			wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) );
378
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
379
+			wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing'));
380 380
 		}
381 381
 
382 382
 		// Check to see if we have any errors.
383
-		if ( wpinv_get_errors() ) {
383
+		if (wpinv_get_errors()) {
384 384
 			wpinv_send_back_to_checkout();
385 385
 		}
386 386
 
387 387
 		// Send info to the gateway for payment processing
388
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
388
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
389 389
 
390 390
 		// Backwards compatibility.
391
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
391
+		wpinv_send_to_gateway($submission_gateway, $invoice);
392 392
 
393 393
 	}
394 394
 
@@ -397,12 +397,12 @@  discard block
 block discarded – undo
397 397
 	 *
398 398
 	 * @param WPInv_Invoice $invoice
399 399
 	 */
400
-	protected function process_free_payment( $invoice ) {
400
+	protected function process_free_payment($invoice) {
401 401
 
402
-		$invoice->set_gateway( 'none' );
403
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
402
+		$invoice->set_gateway('none');
403
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
404 404
 		$invoice->mark_paid();
405
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
405
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
406 406
 
407 407
 	}
408 408
 
@@ -410,9 +410,9 @@  discard block
 block discarded – undo
410 410
      * Sends a redrect response to payment details.
411 411
      *
412 412
      */
413
-    public function send_redirect_response( $url ) {
414
-        $url = urlencode( $url );
415
-        wp_send_json_success( $url );
413
+    public function send_redirect_response($url) {
414
+        $url = urlencode($url);
415
+        wp_send_json_success($url);
416 416
     }
417 417
 
418 418
 }
Please login to merge, or discard this patch.