Passed
Pull Request — master (#371)
by Brian
88:26
created
includes/wpinv-helper-functions.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
  * @param mixed  $value Value.
709 709
  */
710 710
 function getpaid_maybe_define_constant( $name, $value ) {
711
-	if ( ! defined( $name ) ) {
712
-		define( $name, $value );
713
-	}
711
+    if ( ! defined( $name ) ) {
712
+        define( $name, $value );
713
+    }
714 714
 }
715 715
 
716 716
 function wpinv_get_php_arg_separator_output() {
717
-	return ini_get( 'arg_separator.output' );
717
+    return ini_get( 'arg_separator.output' );
718 718
 }
719 719
 
720 720
 function wpinv_rgb_from_hex( $color ) {
@@ -1058,11 +1058,11 @@  discard block
 block discarded – undo
1058 1058
  * @return array Sanitized array of values.
1059 1059
  */
1060 1060
 function wpinv_parse_list( $list ) {
1061
-	if ( ! is_array( $list ) ) {
1062
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1063
-	}
1061
+    if ( ! is_array( $list ) ) {
1062
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1063
+    }
1064 1064
 
1065
-	return $list;
1065
+    return $list;
1066 1066
 }
1067 1067
 
1068 1068
 /**
@@ -1082,9 +1082,9 @@  discard block
 block discarded – undo
1082 1082
     }
1083 1083
 
1084 1084
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1085
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1085
+    wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1086 1086
 
1087
-	return $data;
1087
+    return $data;
1088 1088
 }
1089 1089
 
1090 1090
 /**
@@ -1113,17 +1113,17 @@  discard block
 block discarded – undo
1113 1113
  */
1114 1114
 function wpinv_clean( $var ) {
1115 1115
 
1116
-	if ( is_array( $var ) ) {
1117
-		return array_map( 'wpinv_clean', $var );
1116
+    if ( is_array( $var ) ) {
1117
+        return array_map( 'wpinv_clean', $var );
1118 1118
     }
1119 1119
 
1120 1120
     if ( is_object( $var ) ) {
1121
-		$object_vars = get_object_vars( $var );
1122
-		foreach ( $object_vars as $property_name => $property_value ) {
1123
-			$var->$property_name = wpinv_clean( $property_value );
1121
+        $object_vars = get_object_vars( $var );
1122
+        foreach ( $object_vars as $property_name => $property_value ) {
1123
+            $var->$property_name = wpinv_clean( $property_value );
1124 1124
         }
1125 1125
         return $var;
1126
-	}
1126
+    }
1127 1127
     
1128 1128
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1129 1129
 }
1130 1130
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +414 added lines, -414 removed lines patch added patch discarded remove patch
@@ -7,132 +7,132 @@  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
 function wpinv_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
 
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool) apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
 
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
 
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double) $amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double) $amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
92
+function wpinv_get_invoice_statuses($draft = false, $trashed = false, $invoice = false) {
93 93
     global $post;
94 94
 
95 95
     $invoice_statuses = array(
96
-        'wpi-pending' => __( 'Pending Payment', 'invoicing' ),
97
-        'publish' => __( 'Paid', 'invoicing'),
98
-        'wpi-processing' => __( 'Processing', 'invoicing' ),
99
-        'wpi-onhold' => __( 'On Hold', 'invoicing' ),
100
-        'wpi-refunded' => __( 'Refunded', 'invoicing' ),
101
-        'wpi-cancelled' => __( 'Cancelled', 'invoicing' ),
102
-        'wpi-failed' => __( 'Failed', 'invoicing' ),
103
-        'wpi-renewal' => __( 'Renewal Payment', 'invoicing' )
96
+        'wpi-pending' => __('Pending Payment', 'invoicing'),
97
+        'publish' => __('Paid', 'invoicing'),
98
+        'wpi-processing' => __('Processing', 'invoicing'),
99
+        'wpi-onhold' => __('On Hold', 'invoicing'),
100
+        'wpi-refunded' => __('Refunded', 'invoicing'),
101
+        'wpi-cancelled' => __('Cancelled', 'invoicing'),
102
+        'wpi-failed' => __('Failed', 'invoicing'),
103
+        'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
 
106
-    if ( $draft ) {
107
-        $invoice_statuses['draft'] = __( 'Draft', 'invoicing' );
106
+    if ($draft) {
107
+        $invoice_statuses['draft'] = __('Draft', 'invoicing');
108 108
     }
109 109
 
110
-    if ( $trashed ) {
111
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
110
+    if ($trashed) {
111
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
112 112
     }
113 113
 
114
-    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
114
+    return apply_filters('wpinv_statuses', $invoice_statuses, $invoice);
115 115
 }
116 116
 
117
-function wpinv_status_nicename( $status ) {
118
-    $statuses = wpinv_get_invoice_statuses( true, true );
119
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
117
+function wpinv_status_nicename($status) {
118
+    $statuses = wpinv_get_invoice_statuses(true, true);
119
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
120 120
 
121 121
     return $status;
122 122
 }
123 123
 
124 124
 function wpinv_get_currency() {
125
-    $currency = wpinv_get_option( 'currency', 'USD' );
125
+    $currency = wpinv_get_option('currency', 'USD');
126 126
     
127
-    return apply_filters( 'wpinv_currency', $currency );
127
+    return apply_filters('wpinv_currency', $currency);
128 128
 }
129 129
 
130
-function wpinv_currency_symbol( $currency = '' ) {
131
-    if ( empty( $currency ) ) {
130
+function wpinv_currency_symbol($currency = '') {
131
+    if (empty($currency)) {
132 132
         $currency = wpinv_get_currency();
133 133
     }
134 134
     
135
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
135
+    $symbols = apply_filters('wpinv_currency_symbols', array(
136 136
         'AED' => '&#x62f;.&#x625;',
137 137
         'AFN' => '&#x60b;',
138 138
         'ALL' => 'L',
@@ -295,209 +295,209 @@  discard block
 block discarded – undo
295 295
         'YER' => '&#xfdfc;',
296 296
         'ZAR' => '&#82;',
297 297
         'ZMW' => 'ZK',
298
-    ) );
298
+    ));
299 299
 
300
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : $currency;
300
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : $currency;
301 301
 
302
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
302
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
303 303
 }
304 304
 
305 305
 function wpinv_currency_position() {
306
-    $position = wpinv_get_option( 'currency_position', 'left' );
306
+    $position = wpinv_get_option('currency_position', 'left');
307 307
     
308
-    return apply_filters( 'wpinv_currency_position', $position );
308
+    return apply_filters('wpinv_currency_position', $position);
309 309
 }
310 310
 
311 311
 function wpinv_thousands_separator() {
312
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
312
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
313 313
     
314
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
314
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
315 315
 }
316 316
 
317 317
 function wpinv_decimal_separator() {
318
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
318
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
319 319
     
320
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
320
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
321 321
 }
322 322
 
323 323
 function wpinv_decimals() {
324
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
324
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
325 325
     
326
-    return absint( $decimals );
326
+    return absint($decimals);
327 327
 }
328 328
 
329 329
 function wpinv_get_currencies() {
330 330
     $currencies = array(
331
-        'USD' => __( 'US Dollar', 'invoicing' ),
332
-        'EUR' => __( 'Euro', 'invoicing' ),
333
-        'GBP' => __( 'Pound Sterling', 'invoicing' ),
334
-        'AED' => __( 'United Arab Emirates', 'invoicing' ),
335
-        'AFN' => __( 'Afghan Afghani', 'invoicing' ),
336
-        'ALL' => __( 'Albanian Lek', 'invoicing' ),
337
-        'AMD' => __( 'Armenian Dram', 'invoicing' ),
338
-        'ANG' => __( 'Netherlands Antillean Guilder', 'invoicing' ),
339
-        'AOA' => __( 'Angolan Kwanza', 'invoicing' ),
340
-        'ARS' => __( 'Argentine Peso', 'invoicing' ),
341
-        'AUD' => __( 'Australian Dollar', 'invoicing' ),
342
-        'AWG' => __( 'Aruban Florin', 'invoicing' ),
343
-        'AZN' => __( 'Azerbaijani Manat', 'invoicing' ),
344
-        'BAM' => __( 'Bosnia and Herzegovina Convertible Marka', 'invoicing' ),
345
-        'BBD' => __( 'Barbadian Dollar', 'invoicing' ),
346
-        'BDT' => __( 'Bangladeshi Taka', 'invoicing' ),
347
-        'BGN' => __( 'Bulgarian Lev', 'invoicing' ),
348
-        'BHD' => __( 'Bahraini Dinar', 'invoicing' ),
349
-        'BIF' => __( 'Burundian Franc', 'invoicing' ),
350
-        'BMD' => __( 'Bermudian Dollar', 'invoicing' ),
351
-        'BND' => __( 'Brunei Dollar', 'invoicing' ),
352
-        'BOB' => __( 'Bolivian Boliviano', 'invoicing' ),
353
-        'BRL' => __( 'Brazilian Real', 'invoicing' ),
354
-        'BSD' => __( 'Bahamian Dollar', 'invoicing' ),
355
-        'BTC' => __( 'Bitcoin', 'invoicing' ),
356
-        'BTN' => __( 'Bhutanese Ngultrum', 'invoicing' ),
357
-        'BWP' => __( 'Botswana Pula', 'invoicing' ),
358
-        'BYN' => __( 'Belarusian Ruble', 'invoicing' ),
359
-        'BZD' => __( 'Belize Dollar', 'invoicing' ),
360
-        'CAD' => __( 'Canadian Dollar', 'invoicing' ),
361
-        'CDF' => __( 'Congolese Franc', 'invoicing' ),
362
-        'CHF' => __( 'Swiss Franc', 'invoicing' ),
363
-        'CLP' => __( 'Chilean Peso', 'invoicing' ),
364
-        'CNY' => __( 'Chinese Yuan', 'invoicing' ),
365
-        'COP' => __( 'Colombian Peso', 'invoicing' ),
366
-        'CRC' => __( 'Costa Rican Colon', 'invoicing' ),
367
-        'CUC' => __( 'Cuban Convertible Peso', 'invoicing' ),
368
-        'CUP' => __( 'Cuban Peso', 'invoicing' ),
369
-        'CVE' => __( 'Cape Verdean escudo', 'invoicing' ),
370
-        'CZK' => __( 'Czech Koruna', 'invoicing' ),
371
-        'DJF' => __( 'Djiboutian Franc', 'invoicing' ),
372
-        'DKK' => __( 'Danish Krone', 'invoicing' ),
373
-        'DOP' => __( 'Dominican Peso', 'invoicing' ),
374
-        'DZD' => __( 'Algerian Dinar', 'invoicing' ),
375
-        'EGP' => __( 'Egyptian Pound', 'invoicing' ),
376
-        'ERN' => __( 'Eritrean Nakfa', 'invoicing' ),
377
-        'ETB' => __( 'Ethiopian Irr', 'invoicing' ),
378
-        'FJD' => __( 'Fijian Dollar', 'invoicing' ),
379
-        'FKP' => __( 'Falkland Islands Pound', 'invoicing' ),
380
-        'GEL' => __( 'Georgian Lari', 'invoicing' ),
381
-        'GGP' => __( 'Guernsey Pound', 'invoicing' ),
382
-        'GHS' => __( 'Ghana Cedi', 'invoicing' ),
383
-        'GIP' => __( 'Gibraltar Pound', 'invoicing' ),
384
-        'GMD' => __( 'Gambian Dalasi', 'invoicing' ),
385
-        'GNF' => __( 'Guinean Franc', 'invoicing' ),
386
-        'GTQ' => __( 'Guatemalan Quetzal', 'invoicing' ),
387
-        'GYD' => __( 'Guyanese Dollar', 'invoicing' ),
388
-        'HKD' => __( 'Hong Kong Dollar', 'invoicing' ),
389
-        'HNL' => __( 'Honduran Lempira', 'invoicing' ),
390
-        'HRK' => __( 'Croatian Kuna', 'invoicing' ),
391
-        'HTG' => __( 'Haitian Gourde', 'invoicing' ),
392
-        'HUF' => __( 'Hungarian Forint', 'invoicing' ),
393
-        'IDR' => __( 'Indonesian Rupiah', 'invoicing' ),
394
-        'ILS' => __( 'Israeli New Shekel', 'invoicing' ),
395
-        'IMP' => __( 'Manx Pound', 'invoicing' ),
396
-        'INR' => __( 'Indian Rupee', 'invoicing' ),
397
-        'IQD' => __( 'Iraqi Dinar', 'invoicing' ),
398
-        'IRR' => __( 'Iranian Rial', 'invoicing' ),
399
-        'IRT' => __( 'Iranian Toman', 'invoicing' ),
400
-        'ISK' => __( 'Icelandic Krona', 'invoicing' ),
401
-        'JEP' => __( 'Jersey Pound', 'invoicing' ),
402
-        'JMD' => __( 'Jamaican Dollar', 'invoicing' ),
403
-        'JOD' => __( 'Jordanian Dinar', 'invoicing' ),
404
-        'JPY' => __( 'Japanese Yen', 'invoicing' ),
405
-        'KES' => __( 'Kenyan Shilling', 'invoicing' ),
406
-        'KGS' => __( 'Kyrgyzstani Som', 'invoicing' ),
407
-        'KHR' => __( 'Cambodian Riel', 'invoicing' ),
408
-        'KMF' => __( 'Comorian Franc', 'invoicing' ),
409
-        'KPW' => __( 'North Korean Won', 'invoicing' ),
410
-        'KRW' => __( 'South Korean Won', 'invoicing' ),
411
-        'KWD' => __( 'Kuwaiti Dinar', 'invoicing' ),
412
-        'KYD' => __( 'Cayman Islands Dollar', 'invoicing' ),
413
-        'KZT' => __( 'Kazakhstani Tenge', 'invoicing' ),
414
-        'LAK' => __( 'Lao Kip', 'invoicing' ),
415
-        'LBP' => __( 'Lebanese Pound', 'invoicing' ),
416
-        'LKR' => __( 'Sri Lankan Rupee', 'invoicing' ),
417
-        'LRD' => __( 'Liberian Dollar', 'invoicing' ),
418
-        'LSL' => __( 'Lesotho Loti', 'invoicing' ),
419
-        'LYD' => __( 'Libyan Dinar', 'invoicing' ),
420
-        'MAD' => __( 'Moroccan Dirham', 'invoicing' ),
421
-        'MDL' => __( 'Moldovan Leu', 'invoicing' ),
422
-        'MGA' => __( 'Malagasy Ariary', 'invoicing' ),
423
-        'MKD' => __( 'Macedonian Denar', 'invoicing' ),
424
-        'MMK' => __( 'Burmese Kyat', 'invoicing' ),
425
-        'MNT' => __( 'Mongolian Tughrik', 'invoicing' ),
426
-        'MOP' => __( 'Macanese Pataca', 'invoicing' ),
427
-        'MRO' => __( 'Mauritanian Ouguiya', 'invoicing' ),
428
-        'MUR' => __( 'Mauritian Rupee', 'invoicing' ),
429
-        'MVR' => __( 'Maldivian Rufiyaa', 'invoicing' ),
430
-        'MWK' => __( 'Malawian Kwacha', 'invoicing' ),
431
-        'MXN' => __( 'Mexican Peso', 'invoicing' ),
432
-        'MYR' => __( 'Malaysian Ringgit', 'invoicing' ),
433
-        'MZN' => __( 'Mozambican Metical', 'invoicing' ),
434
-        'NAD' => __( 'Namibian Dollar', 'invoicing' ),
435
-        'NGN' => __( 'Nigerian Naira', 'invoicing' ),
436
-        'NIO' => __( 'Nicaraguan Cordoba', 'invoicing' ),
437
-        'NOK' => __( 'Norwegian Krone', 'invoicing' ),
438
-        'NPR' => __( 'Nepalese Rupee', 'invoicing' ),
439
-        'NZD' => __( 'New Zealand Dollar', 'invoicing' ),
440
-        'OMR' => __( 'Omani Rial', 'invoicing' ),
441
-        'PAB' => __( 'Panamanian Balboa', 'invoicing' ),
442
-        'PEN' => __( 'Peruvian Nuevo Sol', 'invoicing' ),
443
-        'PGK' => __( 'Papua New Guinean Kina', 'invoicing' ),
444
-        'PHP' => __( 'Philippine Peso', 'invoicing' ),
445
-        'PKR' => __( 'Pakistani Rupee', 'invoicing' ),
446
-        'PLN' => __( 'Polish Zloty', 'invoicing' ),
447
-        'PRB' => __( 'Transnistrian Ruble', 'invoicing' ),
448
-        'PYG' => __( 'Paraguayan Guarani', 'invoicing' ),
449
-        'QAR' => __( 'Qatari Riyal', 'invoicing' ),
450
-        'RON' => __( 'Romanian Leu', 'invoicing' ),
451
-        'RSD' => __( 'Serbian Dinar', 'invoicing' ),
452
-        'RUB' => __( 'Russian Ruble', 'invoicing' ),
453
-        'RWF' => __( 'Rwandan Franc', 'invoicing' ),
454
-        'SAR' => __( 'Saudi Riyal', 'invoicing' ),
455
-        'SBD' => __( 'Solomon Islands Dollar', 'invoicing' ),
456
-        'SCR' => __( 'Seychellois Rupee', 'invoicing' ),
457
-        'SDG' => __( 'Sudanese Pound', 'invoicing' ),
458
-        'SEK' => __( 'Swedish Krona', 'invoicing' ),
459
-        'SGD' => __( 'Singapore Dollar', 'invoicing' ),
460
-        'SHP' => __( 'Saint Helena Pound', 'invoicing' ),
461
-        'SLL' => __( 'Sierra Leonean Leone', 'invoicing' ),
462
-        'SOS' => __( 'Somali Shilling', 'invoicing' ),
463
-        'SRD' => __( 'Surinamese Dollar', 'invoicing' ),
464
-        'SSP' => __( 'South Sudanese Pound', 'invoicing' ),
465
-        'STD' => __( 'Sao Tomean Dobra', 'invoicing' ),
466
-        'SYP' => __( 'Syrian Pound', 'invoicing' ),
467
-        'SZL' => __( 'Swazi Lilangeni', 'invoicing' ),
468
-        'THB' => __( 'Thai Baht', 'invoicing' ),
469
-        'TJS' => __( 'Tajikistani Somoni', 'invoicing' ),
470
-        'TMT' => __( 'Turkmenistan Manat', 'invoicing' ),
471
-        'TND' => __( 'Tunisian Dinar', 'invoicing' ),
472
-        'TOP' => __( 'Tongan Pa&#x2bb;anga', 'invoicing' ),
473
-        'TRY' => __( 'Turkish Lira', 'invoicing' ),
474
-        'TTD' => __( 'Trinidad and Tobago Dollar', 'invoicing' ),
475
-        'TWD' => __( 'New Taiwan Dollar', 'invoicing' ),
476
-        'TZS' => __( 'Tanzanian Shilling', 'invoicing' ),
477
-        'UAH' => __( 'Ukrainian Hryvnia', 'invoicing' ),
478
-        'UGX' => __( 'Ugandan Shilling', 'invoicing' ),
479
-        'UYU' => __( 'Uruguayan Peso', 'invoicing' ),
480
-        'UZS' => __( 'Uzbekistani Som', 'invoicing' ),
481
-        'VEF' => __( 'Venezuelan Bol&iacute;var', 'invoicing' ),
482
-        'VND' => __( 'Vietnamese Dong', 'invoicing' ),
483
-        'VUV' => __( 'Vanuatu Vatu', 'invoicing' ),
484
-        'WST' => __( 'Samoan Tala', 'invoicing' ),
485
-        'XAF' => __( 'Central African CFA Franc', 'invoicing' ),
486
-        'XCD' => __( 'East Caribbean Dollar', 'invoicing' ),
487
-        'XOF' => __( 'West African CFA Franc', 'invoicing' ),
488
-        'XPF' => __( 'CFP Franc', 'invoicing' ),
489
-        'YER' => __( 'Yemeni Rial', 'invoicing' ),
490
-        'ZAR' => __( 'South African Rand', 'invoicing' ),
491
-        'ZMW' => __( 'Zambian Kwacha', 'invoicing' ),
331
+        'USD' => __('US Dollar', 'invoicing'),
332
+        'EUR' => __('Euro', 'invoicing'),
333
+        'GBP' => __('Pound Sterling', 'invoicing'),
334
+        'AED' => __('United Arab Emirates', 'invoicing'),
335
+        'AFN' => __('Afghan Afghani', 'invoicing'),
336
+        'ALL' => __('Albanian Lek', 'invoicing'),
337
+        'AMD' => __('Armenian Dram', 'invoicing'),
338
+        'ANG' => __('Netherlands Antillean Guilder', 'invoicing'),
339
+        'AOA' => __('Angolan Kwanza', 'invoicing'),
340
+        'ARS' => __('Argentine Peso', 'invoicing'),
341
+        'AUD' => __('Australian Dollar', 'invoicing'),
342
+        'AWG' => __('Aruban Florin', 'invoicing'),
343
+        'AZN' => __('Azerbaijani Manat', 'invoicing'),
344
+        'BAM' => __('Bosnia and Herzegovina Convertible Marka', 'invoicing'),
345
+        'BBD' => __('Barbadian Dollar', 'invoicing'),
346
+        'BDT' => __('Bangladeshi Taka', 'invoicing'),
347
+        'BGN' => __('Bulgarian Lev', 'invoicing'),
348
+        'BHD' => __('Bahraini Dinar', 'invoicing'),
349
+        'BIF' => __('Burundian Franc', 'invoicing'),
350
+        'BMD' => __('Bermudian Dollar', 'invoicing'),
351
+        'BND' => __('Brunei Dollar', 'invoicing'),
352
+        'BOB' => __('Bolivian Boliviano', 'invoicing'),
353
+        'BRL' => __('Brazilian Real', 'invoicing'),
354
+        'BSD' => __('Bahamian Dollar', 'invoicing'),
355
+        'BTC' => __('Bitcoin', 'invoicing'),
356
+        'BTN' => __('Bhutanese Ngultrum', 'invoicing'),
357
+        'BWP' => __('Botswana Pula', 'invoicing'),
358
+        'BYN' => __('Belarusian Ruble', 'invoicing'),
359
+        'BZD' => __('Belize Dollar', 'invoicing'),
360
+        'CAD' => __('Canadian Dollar', 'invoicing'),
361
+        'CDF' => __('Congolese Franc', 'invoicing'),
362
+        'CHF' => __('Swiss Franc', 'invoicing'),
363
+        'CLP' => __('Chilean Peso', 'invoicing'),
364
+        'CNY' => __('Chinese Yuan', 'invoicing'),
365
+        'COP' => __('Colombian Peso', 'invoicing'),
366
+        'CRC' => __('Costa Rican Colon', 'invoicing'),
367
+        'CUC' => __('Cuban Convertible Peso', 'invoicing'),
368
+        'CUP' => __('Cuban Peso', 'invoicing'),
369
+        'CVE' => __('Cape Verdean escudo', 'invoicing'),
370
+        'CZK' => __('Czech Koruna', 'invoicing'),
371
+        'DJF' => __('Djiboutian Franc', 'invoicing'),
372
+        'DKK' => __('Danish Krone', 'invoicing'),
373
+        'DOP' => __('Dominican Peso', 'invoicing'),
374
+        'DZD' => __('Algerian Dinar', 'invoicing'),
375
+        'EGP' => __('Egyptian Pound', 'invoicing'),
376
+        'ERN' => __('Eritrean Nakfa', 'invoicing'),
377
+        'ETB' => __('Ethiopian Irr', 'invoicing'),
378
+        'FJD' => __('Fijian Dollar', 'invoicing'),
379
+        'FKP' => __('Falkland Islands Pound', 'invoicing'),
380
+        'GEL' => __('Georgian Lari', 'invoicing'),
381
+        'GGP' => __('Guernsey Pound', 'invoicing'),
382
+        'GHS' => __('Ghana Cedi', 'invoicing'),
383
+        'GIP' => __('Gibraltar Pound', 'invoicing'),
384
+        'GMD' => __('Gambian Dalasi', 'invoicing'),
385
+        'GNF' => __('Guinean Franc', 'invoicing'),
386
+        'GTQ' => __('Guatemalan Quetzal', 'invoicing'),
387
+        'GYD' => __('Guyanese Dollar', 'invoicing'),
388
+        'HKD' => __('Hong Kong Dollar', 'invoicing'),
389
+        'HNL' => __('Honduran Lempira', 'invoicing'),
390
+        'HRK' => __('Croatian Kuna', 'invoicing'),
391
+        'HTG' => __('Haitian Gourde', 'invoicing'),
392
+        'HUF' => __('Hungarian Forint', 'invoicing'),
393
+        'IDR' => __('Indonesian Rupiah', 'invoicing'),
394
+        'ILS' => __('Israeli New Shekel', 'invoicing'),
395
+        'IMP' => __('Manx Pound', 'invoicing'),
396
+        'INR' => __('Indian Rupee', 'invoicing'),
397
+        'IQD' => __('Iraqi Dinar', 'invoicing'),
398
+        'IRR' => __('Iranian Rial', 'invoicing'),
399
+        'IRT' => __('Iranian Toman', 'invoicing'),
400
+        'ISK' => __('Icelandic Krona', 'invoicing'),
401
+        'JEP' => __('Jersey Pound', 'invoicing'),
402
+        'JMD' => __('Jamaican Dollar', 'invoicing'),
403
+        'JOD' => __('Jordanian Dinar', 'invoicing'),
404
+        'JPY' => __('Japanese Yen', 'invoicing'),
405
+        'KES' => __('Kenyan Shilling', 'invoicing'),
406
+        'KGS' => __('Kyrgyzstani Som', 'invoicing'),
407
+        'KHR' => __('Cambodian Riel', 'invoicing'),
408
+        'KMF' => __('Comorian Franc', 'invoicing'),
409
+        'KPW' => __('North Korean Won', 'invoicing'),
410
+        'KRW' => __('South Korean Won', 'invoicing'),
411
+        'KWD' => __('Kuwaiti Dinar', 'invoicing'),
412
+        'KYD' => __('Cayman Islands Dollar', 'invoicing'),
413
+        'KZT' => __('Kazakhstani Tenge', 'invoicing'),
414
+        'LAK' => __('Lao Kip', 'invoicing'),
415
+        'LBP' => __('Lebanese Pound', 'invoicing'),
416
+        'LKR' => __('Sri Lankan Rupee', 'invoicing'),
417
+        'LRD' => __('Liberian Dollar', 'invoicing'),
418
+        'LSL' => __('Lesotho Loti', 'invoicing'),
419
+        'LYD' => __('Libyan Dinar', 'invoicing'),
420
+        'MAD' => __('Moroccan Dirham', 'invoicing'),
421
+        'MDL' => __('Moldovan Leu', 'invoicing'),
422
+        'MGA' => __('Malagasy Ariary', 'invoicing'),
423
+        'MKD' => __('Macedonian Denar', 'invoicing'),
424
+        'MMK' => __('Burmese Kyat', 'invoicing'),
425
+        'MNT' => __('Mongolian Tughrik', 'invoicing'),
426
+        'MOP' => __('Macanese Pataca', 'invoicing'),
427
+        'MRO' => __('Mauritanian Ouguiya', 'invoicing'),
428
+        'MUR' => __('Mauritian Rupee', 'invoicing'),
429
+        'MVR' => __('Maldivian Rufiyaa', 'invoicing'),
430
+        'MWK' => __('Malawian Kwacha', 'invoicing'),
431
+        'MXN' => __('Mexican Peso', 'invoicing'),
432
+        'MYR' => __('Malaysian Ringgit', 'invoicing'),
433
+        'MZN' => __('Mozambican Metical', 'invoicing'),
434
+        'NAD' => __('Namibian Dollar', 'invoicing'),
435
+        'NGN' => __('Nigerian Naira', 'invoicing'),
436
+        'NIO' => __('Nicaraguan Cordoba', 'invoicing'),
437
+        'NOK' => __('Norwegian Krone', 'invoicing'),
438
+        'NPR' => __('Nepalese Rupee', 'invoicing'),
439
+        'NZD' => __('New Zealand Dollar', 'invoicing'),
440
+        'OMR' => __('Omani Rial', 'invoicing'),
441
+        'PAB' => __('Panamanian Balboa', 'invoicing'),
442
+        'PEN' => __('Peruvian Nuevo Sol', 'invoicing'),
443
+        'PGK' => __('Papua New Guinean Kina', 'invoicing'),
444
+        'PHP' => __('Philippine Peso', 'invoicing'),
445
+        'PKR' => __('Pakistani Rupee', 'invoicing'),
446
+        'PLN' => __('Polish Zloty', 'invoicing'),
447
+        'PRB' => __('Transnistrian Ruble', 'invoicing'),
448
+        'PYG' => __('Paraguayan Guarani', 'invoicing'),
449
+        'QAR' => __('Qatari Riyal', 'invoicing'),
450
+        'RON' => __('Romanian Leu', 'invoicing'),
451
+        'RSD' => __('Serbian Dinar', 'invoicing'),
452
+        'RUB' => __('Russian Ruble', 'invoicing'),
453
+        'RWF' => __('Rwandan Franc', 'invoicing'),
454
+        'SAR' => __('Saudi Riyal', 'invoicing'),
455
+        'SBD' => __('Solomon Islands Dollar', 'invoicing'),
456
+        'SCR' => __('Seychellois Rupee', 'invoicing'),
457
+        'SDG' => __('Sudanese Pound', 'invoicing'),
458
+        'SEK' => __('Swedish Krona', 'invoicing'),
459
+        'SGD' => __('Singapore Dollar', 'invoicing'),
460
+        'SHP' => __('Saint Helena Pound', 'invoicing'),
461
+        'SLL' => __('Sierra Leonean Leone', 'invoicing'),
462
+        'SOS' => __('Somali Shilling', 'invoicing'),
463
+        'SRD' => __('Surinamese Dollar', 'invoicing'),
464
+        'SSP' => __('South Sudanese Pound', 'invoicing'),
465
+        'STD' => __('Sao Tomean Dobra', 'invoicing'),
466
+        'SYP' => __('Syrian Pound', 'invoicing'),
467
+        'SZL' => __('Swazi Lilangeni', 'invoicing'),
468
+        'THB' => __('Thai Baht', 'invoicing'),
469
+        'TJS' => __('Tajikistani Somoni', 'invoicing'),
470
+        'TMT' => __('Turkmenistan Manat', 'invoicing'),
471
+        'TND' => __('Tunisian Dinar', 'invoicing'),
472
+        'TOP' => __('Tongan Pa&#x2bb;anga', 'invoicing'),
473
+        'TRY' => __('Turkish Lira', 'invoicing'),
474
+        'TTD' => __('Trinidad and Tobago Dollar', 'invoicing'),
475
+        'TWD' => __('New Taiwan Dollar', 'invoicing'),
476
+        'TZS' => __('Tanzanian Shilling', 'invoicing'),
477
+        'UAH' => __('Ukrainian Hryvnia', 'invoicing'),
478
+        'UGX' => __('Ugandan Shilling', 'invoicing'),
479
+        'UYU' => __('Uruguayan Peso', 'invoicing'),
480
+        'UZS' => __('Uzbekistani Som', 'invoicing'),
481
+        'VEF' => __('Venezuelan Bol&iacute;var', 'invoicing'),
482
+        'VND' => __('Vietnamese Dong', 'invoicing'),
483
+        'VUV' => __('Vanuatu Vatu', 'invoicing'),
484
+        'WST' => __('Samoan Tala', 'invoicing'),
485
+        'XAF' => __('Central African CFA Franc', 'invoicing'),
486
+        'XCD' => __('East Caribbean Dollar', 'invoicing'),
487
+        'XOF' => __('West African CFA Franc', 'invoicing'),
488
+        'XPF' => __('CFP Franc', 'invoicing'),
489
+        'YER' => __('Yemeni Rial', 'invoicing'),
490
+        'ZAR' => __('South African Rand', 'invoicing'),
491
+        'ZMW' => __('Zambian Kwacha', 'invoicing'),
492 492
     );
493 493
     
494 494
     //asort( $currencies ); // this
495 495
 
496
-    return apply_filters( 'wpinv_currencies', $currencies );
496
+    return apply_filters('wpinv_currencies', $currencies);
497 497
 }
498 498
 
499
-function wpinv_price( $amount = '', $currency = '' ) {
500
-    if( empty( $currency ) ) {
499
+function wpinv_price($amount = '', $currency = '') {
500
+    if (empty($currency)) {
501 501
         $currency = wpinv_get_currency();
502 502
     }
503 503
 
@@ -505,14 +505,14 @@  discard block
 block discarded – undo
505 505
 
506 506
     $negative = $amount < 0;
507 507
 
508
-    if ( $negative ) {
509
-        $amount = substr( $amount, 1 );
508
+    if ($negative) {
509
+        $amount = substr($amount, 1);
510 510
     }
511 511
 
512
-    $symbol = wpinv_currency_symbol( $currency );
512
+    $symbol = wpinv_currency_symbol($currency);
513 513
 
514
-    if ( $position == 'left' || $position == 'left_space' ) {
515
-        switch ( $currency ) {
514
+    if ($position == 'left' || $position == 'left_space') {
515
+        switch ($currency) {
516 516
             case "GBP" :
517 517
             case "BRL" :
518 518
             case "EUR" :
@@ -524,15 +524,15 @@  discard block
 block discarded – undo
524 524
             case "NZD" :
525 525
             case "SGD" :
526 526
             case "JPY" :
527
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
527
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
528 528
                 break;
529 529
             default :
530 530
                 //$price = $currency . ' ' . $amount;
531
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
531
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
532 532
                 break;
533 533
         }
534 534
     } else {
535
-        switch ( $currency ) {
535
+        switch ($currency) {
536 536
             case "GBP" :
537 537
             case "BRL" :
538 538
             case "EUR" :
@@ -543,83 +543,83 @@  discard block
 block discarded – undo
543 543
             case "MXN" :
544 544
             case "SGD" :
545 545
             case "JPY" :
546
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
546
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
547 547
                 break;
548 548
             default :
549 549
                 //$price = $amount . ' ' . $currency;
550
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
550
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
551 551
                 break;
552 552
         }
553 553
     }
554 554
     
555
-    if ( $negative ) {
555
+    if ($negative) {
556 556
         $price = '-' . $price;
557 557
     }
558 558
     
559
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
559
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
560 560
 
561 561
     return $price;
562 562
 }
563 563
 
564
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
564
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
565 565
     $thousands_sep = wpinv_thousands_separator();
566 566
     $decimal_sep   = wpinv_decimal_separator();
567 567
 
568
-    if ( $decimals === NULL ) {
568
+    if ($decimals === NULL) {
569 569
         $decimals = wpinv_decimals();
570 570
     }
571 571
 
572
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
573
-        $whole = substr( $amount, 0, $sep_found );
574
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
572
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
573
+        $whole = substr($amount, 0, $sep_found);
574
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
575 575
         $amount = $whole . '.' . $part;
576 576
     }
577 577
 
578
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
579
-        $amount = str_replace( ',', '', $amount );
578
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
579
+        $amount = str_replace(',', '', $amount);
580 580
     }
581 581
 
582
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
583
-        $amount = str_replace( ' ', '', $amount );
582
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
583
+        $amount = str_replace(' ', '', $amount);
584 584
     }
585 585
 
586
-    if ( empty( $amount ) ) {
586
+    if (empty($amount)) {
587 587
         $amount = 0;
588 588
     }
589 589
     
590
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
591
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
590
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
591
+    $formatted = number_format((float) $amount, $decimals, $decimal_sep, $thousands_sep);
592 592
     
593
-    if ( $calculate ) {
594
-        if ( $thousands_sep === "," ) {
595
-            $formatted = str_replace( ",", "", $formatted );
593
+    if ($calculate) {
594
+        if ($thousands_sep === ",") {
595
+            $formatted = str_replace(",", "", $formatted);
596 596
         }
597 597
         
598
-        if ( $decimal_sep === "," ) {
599
-            $formatted = str_replace( ",", ".", $formatted );
598
+        if ($decimal_sep === ",") {
599
+            $formatted = str_replace(",", ".", $formatted);
600 600
         }
601 601
     }
602 602
 
603
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
603
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
604 604
 }
605
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
605
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
606 606
 
607
-function wpinv_sanitize_key( $key ) {
607
+function wpinv_sanitize_key($key) {
608 608
     $raw_key = $key;
609
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
609
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
610 610
 
611
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
611
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
612 612
 }
613 613
 
614
-function wpinv_get_file_extension( $str ) {
615
-    $parts = explode( '.', $str );
616
-    return end( $parts );
614
+function wpinv_get_file_extension($str) {
615
+    $parts = explode('.', $str);
616
+    return end($parts);
617 617
 }
618 618
 
619
-function wpinv_string_is_image_url( $str ) {
620
-    $ext = wpinv_get_file_extension( $str );
619
+function wpinv_string_is_image_url($str) {
620
+    $ext = wpinv_get_file_extension($str);
621 621
 
622
-    switch ( strtolower( $ext ) ) {
622
+    switch (strtolower($ext)) {
623 623
         case 'jpeg';
624 624
         case 'jpg';
625 625
             $return = true;
@@ -635,33 +635,33 @@  discard block
 block discarded – undo
635 635
             break;
636 636
     }
637 637
 
638
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
638
+    return (bool) apply_filters('wpinv_string_is_image', $return, $str);
639 639
 }
640 640
 
641
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
642
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
641
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
642
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
643 643
     
644
-    if ( true === $should_log ) {
644
+    if (true === $should_log) {
645 645
         $label = '';
646
-        if ( $file && $file !== '' ) {
647
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
646
+        if ($file && $file !== '') {
647
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
648 648
         }
649 649
         
650
-        if ( $title && $title !== '' ) {
650
+        if ($title && $title !== '') {
651 651
             $label = $label !== '' ? $label . ' ' : '';
652 652
             $label .= $title . ' ';
653 653
         }
654 654
         
655
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
655
+        $label = $label !== '' ? trim($label) . ' : ' : '';
656 656
         
657
-        if ( is_array( $log ) || is_object( $log ) ) {
658
-            error_log( $label . print_r( $log, true ) );
657
+        if (is_array($log) || is_object($log)) {
658
+            error_log($label . print_r($log, true));
659 659
         } else {
660
-            error_log( $label . $log );
660
+            error_log($label . $log);
661 661
         }
662 662
 
663
-        error_log( wp_debug_backtrace_summary() );
664
-        if ( $exit ) {
663
+        error_log(wp_debug_backtrace_summary());
664
+        if ($exit) {
665 665
             exit;
666 666
         }
667 667
     }
@@ -669,32 +669,32 @@  discard block
 block discarded – undo
669 669
 
670 670
 function wpinv_is_ajax_disabled() {
671 671
     $retval = false;
672
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
672
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
673 673
 }
674 674
 
675
-function wpinv_get_current_page_url( $nocache = false ) {
675
+function wpinv_get_current_page_url($nocache = false) {
676 676
     global $wp;
677 677
 
678
-    if ( get_option( 'permalink_structure' ) ) {
679
-        $base = trailingslashit( home_url( $wp->request ) );
678
+    if (get_option('permalink_structure')) {
679
+        $base = trailingslashit(home_url($wp->request));
680 680
     } else {
681
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
682
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
681
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
682
+        $base = remove_query_arg(array('post_type', 'name'), $base);
683 683
     }
684 684
 
685 685
     $scheme = is_ssl() ? 'https' : 'http';
686
-    $uri    = set_url_scheme( $base, $scheme );
686
+    $uri    = set_url_scheme($base, $scheme);
687 687
 
688
-    if ( is_front_page() ) {
689
-        $uri = home_url( '/' );
690
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
688
+    if (is_front_page()) {
689
+        $uri = home_url('/');
690
+    } elseif (wpinv_is_checkout(array(), false)) {
691 691
         $uri = wpinv_get_checkout_uri();
692 692
     }
693 693
 
694
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
694
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
695 695
 
696
-    if ( $nocache ) {
697
-        $uri = wpinv_add_cache_busting( $uri );
696
+    if ($nocache) {
697
+        $uri = wpinv_add_cache_busting($uri);
698 698
     }
699 699
 
700 700
     return $uri;
@@ -707,46 +707,46 @@  discard block
 block discarded – undo
707 707
  * @param string $name  Constant name.
708 708
  * @param mixed  $value Value.
709 709
  */
710
-function getpaid_maybe_define_constant( $name, $value ) {
711
-	if ( ! defined( $name ) ) {
712
-		define( $name, $value );
710
+function getpaid_maybe_define_constant($name, $value) {
711
+	if (!defined($name)) {
712
+		define($name, $value);
713 713
 	}
714 714
 }
715 715
 
716 716
 function wpinv_get_php_arg_separator_output() {
717
-	return ini_get( 'arg_separator.output' );
717
+	return ini_get('arg_separator.output');
718 718
 }
719 719
 
720
-function wpinv_rgb_from_hex( $color ) {
721
-    $color = str_replace( '#', '', $color );
720
+function wpinv_rgb_from_hex($color) {
721
+    $color = str_replace('#', '', $color);
722 722
 
723 723
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
724
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
725
-    if ( empty( $color ) ) {
724
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
725
+    if (empty($color)) {
726 726
         return NULL;
727 727
     }
728 728
 
729
-    $color = str_split( $color );
729
+    $color = str_split($color);
730 730
 
731 731
     $rgb      = array();
732
-    $rgb['R'] = hexdec( $color[0] . $color[1] );
733
-    $rgb['G'] = hexdec( $color[2] . $color[3] );
734
-    $rgb['B'] = hexdec( $color[4] . $color[5] );
732
+    $rgb['R'] = hexdec($color[0] . $color[1]);
733
+    $rgb['G'] = hexdec($color[2] . $color[3]);
734
+    $rgb['B'] = hexdec($color[4] . $color[5]);
735 735
 
736 736
     return $rgb;
737 737
 }
738 738
 
739
-function wpinv_hex_darker( $color, $factor = 30 ) {
740
-    $base  = wpinv_rgb_from_hex( $color );
739
+function wpinv_hex_darker($color, $factor = 30) {
740
+    $base  = wpinv_rgb_from_hex($color);
741 741
     $color = '#';
742 742
 
743
-    foreach ( $base as $k => $v ) {
743
+    foreach ($base as $k => $v) {
744 744
         $amount      = $v / 100;
745
-        $amount      = round( $amount * $factor );
745
+        $amount      = round($amount * $factor);
746 746
         $new_decimal = $v - $amount;
747 747
 
748
-        $new_hex_component = dechex( $new_decimal );
749
-        if ( strlen( $new_hex_component ) < 2 ) {
748
+        $new_hex_component = dechex($new_decimal);
749
+        if (strlen($new_hex_component) < 2) {
750 750
             $new_hex_component = "0" . $new_hex_component;
751 751
         }
752 752
         $color .= $new_hex_component;
@@ -755,18 +755,18 @@  discard block
 block discarded – undo
755 755
     return $color;
756 756
 }
757 757
 
758
-function wpinv_hex_lighter( $color, $factor = 30 ) {
759
-    $base  = wpinv_rgb_from_hex( $color );
758
+function wpinv_hex_lighter($color, $factor = 30) {
759
+    $base  = wpinv_rgb_from_hex($color);
760 760
     $color = '#';
761 761
 
762
-    foreach ( $base as $k => $v ) {
762
+    foreach ($base as $k => $v) {
763 763
         $amount      = 255 - $v;
764 764
         $amount      = $amount / 100;
765
-        $amount      = round( $amount * $factor );
765
+        $amount      = round($amount * $factor);
766 766
         $new_decimal = $v + $amount;
767 767
 
768
-        $new_hex_component = dechex( $new_decimal );
769
-        if ( strlen( $new_hex_component ) < 2 ) {
768
+        $new_hex_component = dechex($new_decimal);
769
+        if (strlen($new_hex_component) < 2) {
770 770
             $new_hex_component = "0" . $new_hex_component;
771 771
         }
772 772
         $color .= $new_hex_component;
@@ -775,22 +775,22 @@  discard block
 block discarded – undo
775 775
     return $color;
776 776
 }
777 777
 
778
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
779
-    $hex = str_replace( '#', '', $color );
778
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
779
+    $hex = str_replace('#', '', $color);
780 780
 
781
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
782
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
783
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
781
+    $c_r = hexdec(substr($hex, 0, 2));
782
+    $c_g = hexdec(substr($hex, 2, 2));
783
+    $c_b = hexdec(substr($hex, 4, 2));
784 784
 
785
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
785
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
786 786
 
787 787
     return $brightness > 155 ? $dark : $light;
788 788
 }
789 789
 
790
-function wpinv_format_hex( $hex ) {
791
-    $hex = trim( str_replace( '#', '', $hex ) );
790
+function wpinv_format_hex($hex) {
791
+    $hex = trim(str_replace('#', '', $hex));
792 792
 
793
-    if ( strlen( $hex ) == 3 ) {
793
+    if (strlen($hex) == 3) {
794 794
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
795 795
     }
796 796
 
@@ -810,12 +810,12 @@  discard block
 block discarded – undo
810 810
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
811 811
  * @return string
812 812
  */
813
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
814
-    if ( function_exists( 'mb_strimwidth' ) ) {
815
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
813
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
814
+    if (function_exists('mb_strimwidth')) {
815
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
816 816
     }
817 817
     
818
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
818
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
819 819
 }
820 820
 
821 821
 /**
@@ -827,28 +827,28 @@  discard block
 block discarded – undo
827 827
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
828 828
  * @return int Returns the number of characters in string.
829 829
  */
830
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
831
-    if ( function_exists( 'mb_strlen' ) ) {
832
-        return mb_strlen( $str, $encoding );
830
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
831
+    if (function_exists('mb_strlen')) {
832
+        return mb_strlen($str, $encoding);
833 833
     }
834 834
         
835
-    return strlen( $str );
835
+    return strlen($str);
836 836
 }
837 837
 
838
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
839
-    if ( function_exists( 'mb_strtolower' ) ) {
840
-        return mb_strtolower( $str, $encoding );
838
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
839
+    if (function_exists('mb_strtolower')) {
840
+        return mb_strtolower($str, $encoding);
841 841
     }
842 842
     
843
-    return strtolower( $str );
843
+    return strtolower($str);
844 844
 }
845 845
 
846
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
847
-    if ( function_exists( 'mb_strtoupper' ) ) {
848
-        return mb_strtoupper( $str, $encoding );
846
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
847
+    if (function_exists('mb_strtoupper')) {
848
+        return mb_strtoupper($str, $encoding);
849 849
     }
850 850
     
851
-    return strtoupper( $str );
851
+    return strtoupper($str);
852 852
 }
853 853
 
854 854
 /**
@@ -862,12 +862,12 @@  discard block
 block discarded – undo
862 862
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
863 863
  * @return int Returns the position of the first occurrence of search in the string.
864 864
  */
865
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
866
-    if ( function_exists( 'mb_strpos' ) ) {
867
-        return mb_strpos( $str, $find, $offset, $encoding );
865
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
866
+    if (function_exists('mb_strpos')) {
867
+        return mb_strpos($str, $find, $offset, $encoding);
868 868
     }
869 869
         
870
-    return strpos( $str, $find, $offset );
870
+    return strpos($str, $find, $offset);
871 871
 }
872 872
 
873 873
 /**
@@ -881,12 +881,12 @@  discard block
 block discarded – undo
881 881
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
882 882
  * @return int Returns the position of the last occurrence of search.
883 883
  */
884
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
885
-    if ( function_exists( 'mb_strrpos' ) ) {
886
-        return mb_strrpos( $str, $find, $offset, $encoding );
884
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
885
+    if (function_exists('mb_strrpos')) {
886
+        return mb_strrpos($str, $find, $offset, $encoding);
887 887
     }
888 888
         
889
-    return strrpos( $str, $find, $offset );
889
+    return strrpos($str, $find, $offset);
890 890
 }
891 891
 
892 892
 /**
@@ -901,16 +901,16 @@  discard block
 block discarded – undo
901 901
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
902 902
  * @return string
903 903
  */
904
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
905
-    if ( function_exists( 'mb_substr' ) ) {
906
-        if ( $length === null ) {
907
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
904
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
905
+    if (function_exists('mb_substr')) {
906
+        if ($length === null) {
907
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
908 908
         } else {
909
-            return mb_substr( $str, $start, $length, $encoding );
909
+            return mb_substr($str, $start, $length, $encoding);
910 910
         }
911 911
     }
912 912
         
913
-    return substr( $str, $start, $length );
913
+    return substr($str, $start, $length);
914 914
 }
915 915
 
916 916
 /**
@@ -922,48 +922,48 @@  discard block
 block discarded – undo
922 922
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
923 923
  * @return string The width of string.
924 924
  */
925
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
926
-    if ( function_exists( 'mb_strwidth' ) ) {
927
-        return mb_strwidth( $str, $encoding );
925
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
926
+    if (function_exists('mb_strwidth')) {
927
+        return mb_strwidth($str, $encoding);
928 928
     }
929 929
     
930
-    return wpinv_utf8_strlen( $str, $encoding );
930
+    return wpinv_utf8_strlen($str, $encoding);
931 931
 }
932 932
 
933
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
934
-    if ( function_exists( 'mb_strlen' ) ) {
935
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
933
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
934
+    if (function_exists('mb_strlen')) {
935
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
936 936
         $str_end = "";
937 937
         
938
-        if ( $lower_str_end ) {
939
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
938
+        if ($lower_str_end) {
939
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
940 940
         } else {
941
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
941
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
942 942
         }
943 943
 
944 944
         return $first_letter . $str_end;
945 945
     }
946 946
     
947
-    return ucfirst( $str );
947
+    return ucfirst($str);
948 948
 }
949 949
 
950
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
951
-    if ( function_exists( 'mb_convert_case' ) ) {
952
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
950
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
951
+    if (function_exists('mb_convert_case')) {
952
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
953 953
     }
954 954
     
955
-    return ucwords( $str );
955
+    return ucwords($str);
956 956
 }
957 957
 
958
-function wpinv_period_in_days( $period, $unit ) {
959
-    $period = absint( $period );
958
+function wpinv_period_in_days($period, $unit) {
959
+    $period = absint($period);
960 960
     
961
-    if ( $period > 0 ) {
962
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
961
+    if ($period > 0) {
962
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
963 963
             $period = $period * 7;
964
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
964
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
965 965
             $period = $period * 30;
966
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
966
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
967 967
             $period = $period * 365;
968 968
         }
969 969
     }
@@ -971,14 +971,14 @@  discard block
 block discarded – undo
971 971
     return $period;
972 972
 }
973 973
 
974
-function wpinv_cal_days_in_month( $calendar, $month, $year ) {
975
-    if ( function_exists( 'cal_days_in_month' ) ) {
976
-        return cal_days_in_month( $calendar, $month, $year );
974
+function wpinv_cal_days_in_month($calendar, $month, $year) {
975
+    if (function_exists('cal_days_in_month')) {
976
+        return cal_days_in_month($calendar, $month, $year);
977 977
     }
978 978
 
979 979
     // Fallback in case the calendar extension is not loaded in PHP
980 980
     // Only supports Gregorian calendar
981
-    return date( 't', mktime( 0, 0, 0, $month, 1, $year ) );
981
+    return date('t', mktime(0, 0, 0, $month, 1, $year));
982 982
 }
983 983
 
984 984
 /**
@@ -989,11 +989,11 @@  discard block
 block discarded – undo
989 989
  *
990 990
  * @return string
991 991
  */
992
-function wpi_help_tip( $tip, $allow_html = false ) {
993
-    if ( $allow_html ) {
994
-        $tip = wpi_sanitize_tooltip( $tip );
992
+function wpi_help_tip($tip, $allow_html = false) {
993
+    if ($allow_html) {
994
+        $tip = wpi_sanitize_tooltip($tip);
995 995
     } else {
996
-        $tip = esc_attr( $tip );
996
+        $tip = esc_attr($tip);
997 997
     }
998 998
 
999 999
     return '<span class="wpi-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -1007,8 +1007,8 @@  discard block
 block discarded – undo
1007 1007
  * @param string $var
1008 1008
  * @return string
1009 1009
  */
1010
-function wpi_sanitize_tooltip( $var ) {
1011
-    return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1010
+function wpi_sanitize_tooltip($var) {
1011
+    return htmlspecialchars(wp_kses(html_entity_decode($var), array(
1012 1012
         'br'     => array(),
1013 1013
         'em'     => array(),
1014 1014
         'strong' => array(),
@@ -1018,7 +1018,7 @@  discard block
 block discarded – undo
1018 1018
         'li'     => array(),
1019 1019
         'ol'     => array(),
1020 1020
         'p'      => array(),
1021
-    ) ) );
1021
+    )));
1022 1022
 }
1023 1023
 
1024 1024
 /**
@@ -1028,7 +1028,7 @@  discard block
 block discarded – undo
1028 1028
  */
1029 1029
 function wpinv_get_screen_ids() {
1030 1030
 
1031
-    $screen_id = sanitize_title( __( 'Invoicing', 'invoicing' ) );
1031
+    $screen_id = sanitize_title(__('Invoicing', 'invoicing'));
1032 1032
 
1033 1033
     $screen_ids = array(
1034 1034
         'toplevel_page_' . $screen_id,
@@ -1046,7 +1046,7 @@  discard block
 block discarded – undo
1046 1046
         'invoicing_page_wpi-addons',
1047 1047
     );
1048 1048
 
1049
-    return apply_filters( 'wpinv_screen_ids', $screen_ids );
1049
+    return apply_filters('wpinv_screen_ids', $screen_ids);
1050 1050
 }
1051 1051
 
1052 1052
 /**
@@ -1057,9 +1057,9 @@  discard block
 block discarded – undo
1057 1057
  * @param array|string $list List of values.
1058 1058
  * @return array Sanitized array of values.
1059 1059
  */
1060
-function wpinv_parse_list( $list ) {
1061
-	if ( ! is_array( $list ) ) {
1062
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1060
+function wpinv_parse_list($list) {
1061
+	if (!is_array($list)) {
1062
+		return preg_split('/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY);
1063 1063
 	}
1064 1064
 
1065 1065
 	return $list;
@@ -1073,16 +1073,16 @@  discard block
 block discarded – undo
1073 1073
  * @param string $key Type of data to fetch.
1074 1074
  * @return mixed Fetched data.
1075 1075
  */
1076
-function wpinv_get_data( $key ) {
1076
+function wpinv_get_data($key) {
1077 1077
     
1078 1078
     // Try fetching it from the cache.
1079
-    $data = wp_cache_get( "wpinv-$key", 'wpinv' );
1080
-    if( $data ) {
1079
+    $data = wp_cache_get("wpinv-$key", 'wpinv');
1080
+    if ($data) {
1081 1081
         return $data;
1082 1082
     }
1083 1083
 
1084
-    $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1085
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1084
+    $data = apply_filters("wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php");
1085
+	wp_cache_set("wpinv-$key", $data, 'wpinv');
1086 1086
 
1087 1087
 	return $data;
1088 1088
 }
@@ -1096,10 +1096,10 @@  discard block
 block discarded – undo
1096 1096
  * @param bool $first_empty Whether or not the first item in the list should be empty
1097 1097
  * @return mixed Fetched data.
1098 1098
  */
1099
-function wpinv_maybe_add_empty_option( $options, $first_empty ) {
1099
+function wpinv_maybe_add_empty_option($options, $first_empty) {
1100 1100
 
1101
-    if ( ! empty( $options ) && $first_empty ) {
1102
-        return array_merge( array( '' => '' ), $options );
1101
+    if (!empty($options) && $first_empty) {
1102
+        return array_merge(array('' => ''), $options);
1103 1103
     }
1104 1104
     return $options;
1105 1105
 
@@ -1111,19 +1111,19 @@  discard block
 block discarded – undo
1111 1111
  * @param mixed $var Data to sanitize.
1112 1112
  * @return string|array
1113 1113
  */
1114
-function wpinv_clean( $var ) {
1114
+function wpinv_clean($var) {
1115 1115
 
1116
-	if ( is_array( $var ) ) {
1117
-		return array_map( 'wpinv_clean', $var );
1116
+	if (is_array($var)) {
1117
+		return array_map('wpinv_clean', $var);
1118 1118
     }
1119 1119
 
1120
-    if ( is_object( $var ) ) {
1121
-		$object_vars = get_object_vars( $var );
1122
-		foreach ( $object_vars as $property_name => $property_value ) {
1123
-			$var->$property_name = wpinv_clean( $property_value );
1120
+    if (is_object($var)) {
1121
+		$object_vars = get_object_vars($var);
1122
+		foreach ($object_vars as $property_name => $property_value) {
1123
+			$var->$property_name = wpinv_clean($property_value);
1124 1124
         }
1125 1125
         return $var;
1126 1126
 	}
1127 1127
     
1128
-    return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1128
+    return is_string($var) ? sanitize_text_field($var) : $var;
1129 1129
 }
1130 1130
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -1,23 +1,23 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by_id( $id ) {
6
-    return wpinv_get_item_by( 'id', $id );
5
+function wpinv_get_item_by_id($id) {
6
+    return wpinv_get_item_by('id', $id);
7 7
 }
8 8
 
9
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
10
-    if( empty( $field ) || empty( $value ) ) {
9
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
10
+    if (empty($field) || empty($value)) {
11 11
         return false;
12 12
     }
13 13
     
14 14
     $posts = array();
15 15
 
16
-    switch( strtolower( $field ) ) {
16
+    switch (strtolower($field)) {
17 17
         case 'id':
18
-            $item = new WPInv_Item( $value );
18
+            $item = new WPInv_Item($value);
19 19
 
20
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
20
+            if (!empty($item) && $item->post_type == 'wpi_item') {
21 21
                 return $item;
22 22
             }
23 23
             return false;
@@ -26,16 +26,16 @@  discard block
 block discarded – undo
26 26
 
27 27
         case 'slug':
28 28
         case 'name':
29
-            $posts = get_posts( array(
29
+            $posts = get_posts(array(
30 30
                 'post_type'      => 'wpi_item',
31 31
                 'name'           => $value,
32 32
                 'posts_per_page' => 1,
33 33
                 'post_status'    => 'any'
34
-            ) );
34
+            ));
35 35
 
36 36
             break;
37 37
         case 'custom_id':
38
-            if ( empty( $value ) || empty( $type ) ) {
38
+            if (empty($value) || empty($type)) {
39 39
                 return false;
40 40
             }
41 41
             
@@ -55,10 +55,10 @@  discard block
 block discarded – undo
55 55
                 'post_status'    => 'any',
56 56
                 'orderby'        => 'ID',
57 57
                 'order'          => 'ASC',
58
-                'meta_query'     => array( $meta_query )
58
+                'meta_query'     => array($meta_query)
59 59
             );
60 60
             
61
-            $posts = get_posts( $args );
61
+            $posts = get_posts($args);
62 62
 
63 63
             break;
64 64
 
@@ -66,10 +66,10 @@  discard block
 block discarded – undo
66 66
             return false;
67 67
     }
68 68
     
69
-    if ( !empty( $posts[0] ) ) {
70
-        $item = new WPInv_Item( $posts[0]->ID );
69
+    if (!empty($posts[0])) {
70
+        $item = new WPInv_Item($posts[0]->ID);
71 71
 
72
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
72
+        if (!empty($item) && $item->post_type == 'wpi_item') {
73 73
             return $item;
74 74
         }
75 75
     }
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
     return false;
78 78
 }
79 79
 
80
-function wpinv_get_item( $item = 0 ) {
81
-    if ( is_numeric( $item ) ) {
82
-        $item = get_post( $item );
83
-        if ( ! $item || 'wpi_item' !== $item->post_type )
80
+function wpinv_get_item($item = 0) {
81
+    if (is_numeric($item)) {
82
+        $item = get_post($item);
83
+        if (!$item || 'wpi_item' !== $item->post_type)
84 84
             return null;
85 85
         return $item;
86 86
     }
@@ -93,18 +93,18 @@  discard block
 block discarded – undo
93 93
 
94 94
     $item = get_posts($args);
95 95
 
96
-    if ( $item ) {
96
+    if ($item) {
97 97
         return $item[0];
98 98
     }
99 99
 
100 100
     return null;
101 101
 }
102 102
 
103
-function wpinv_get_all_items( $args = array() ) {
103
+function wpinv_get_all_items($args = array()) {
104 104
 
105
-    $args = wp_parse_args( $args, array(
106
-        'status'         => array( 'publish' ),
107
-        'limit'          => get_option( 'posts_per_page' ),
105
+    $args = wp_parse_args($args, array(
106
+        'status'         => array('publish'),
107
+        'limit'          => get_option('posts_per_page'),
108 108
         'page'           => 1,
109 109
         'exclude'        => array(),
110 110
         'orderby'        => 'date',
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         'meta_query'     => array(),
114 114
         'return'         => 'objects',
115 115
         'paginate'       => false,
116
-    ) );
116
+    ));
117 117
 
118 118
     $wp_query_args = array(
119 119
         'post_type'      => 'wpi_item',
@@ -123,26 +123,26 @@  discard block
 block discarded – undo
123 123
         'fields'         => 'ids',
124 124
         'orderby'        => $args['orderby'],
125 125
         'order'          => $args['order'],
126
-        'paged'          => absint( $args['page'] ),
126
+        'paged'          => absint($args['page']),
127 127
     );
128 128
 
129
-    if ( ! empty( $args['exclude'] ) ) {
130
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
129
+    if (!empty($args['exclude'])) {
130
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
131 131
     }
132 132
 
133
-    if ( ! $args['paginate' ] ) {
133
+    if (!$args['paginate']) {
134 134
         $wp_query_args['no_found_rows'] = true;
135 135
     }
136 136
 
137
-    if ( ! empty( $args['search'] ) ) {
137
+    if (!empty($args['search'])) {
138 138
         $wp_query_args['s'] = $args['search'];
139 139
     }
140 140
 
141
-    if ( ! empty( $args['type'] ) && $args['type'] !== wpinv_item_types() ) {
142
-        $types = wpinv_parse_list( $args['type'] );
141
+    if (!empty($args['type']) && $args['type'] !== wpinv_item_types()) {
142
+        $types = wpinv_parse_list($args['type']);
143 143
         $wp_query_args['meta_query'][] = array(
144 144
             'key'     => '_wpinv_type',
145
-            'value'   => implode( ',', $types ),
145
+            'value'   => implode(',', $types),
146 146
             'compare' => 'IN',
147 147
         );
148 148
     }
@@ -150,17 +150,17 @@  discard block
 block discarded – undo
150 150
     $wp_query_args = apply_filters('wpinv_get_items_args', $wp_query_args, $args);
151 151
 
152 152
     // Get results.
153
-    $items = new WP_Query( $wp_query_args );
153
+    $items = new WP_Query($wp_query_args);
154 154
 
155
-    if ( 'objects' === $args['return'] ) {
156
-        $return = array_map( 'wpinv_get_item_by_id', $items->posts );
157
-    } elseif ( 'self' === $args['return'] ) {
155
+    if ('objects' === $args['return']) {
156
+        $return = array_map('wpinv_get_item_by_id', $items->posts);
157
+    } elseif ('self' === $args['return']) {
158 158
         return $items;
159 159
     } else {
160 160
         $return = $items->posts;
161 161
     }
162 162
 
163
-    if ( $args['paginate' ] ) {
163
+    if ($args['paginate']) {
164 164
         return (object) array(
165 165
             'items'      => $return,
166 166
             'total'         => $items->found_posts,
@@ -172,143 +172,143 @@  discard block
 block discarded – undo
172 172
 
173 173
 }
174 174
 
175
-function wpinv_is_free_item( $item_id = 0 ) {
176
-    if( empty( $item_id ) ) {
175
+function wpinv_is_free_item($item_id = 0) {
176
+    if (empty($item_id)) {
177 177
         return false;
178 178
     }
179 179
 
180
-    $item = new WPInv_Item( $item_id );
180
+    $item = new WPInv_Item($item_id);
181 181
     
182 182
     return $item->is_free();
183 183
 }
184 184
 
185
-function wpinv_item_is_editable( $item = 0 ) {
186
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
185
+function wpinv_item_is_editable($item = 0) {
186
+    if (!empty($item) && is_a($item, 'WP_Post')) {
187 187
         $item = $item->ID;
188 188
     }
189 189
         
190
-    if ( empty( $item ) ) {
190
+    if (empty($item)) {
191 191
         return true;
192 192
     }
193 193
 
194
-    $item = new WPInv_Item( $item );
194
+    $item = new WPInv_Item($item);
195 195
     
196 196
     return (bool) $item->is_editable();
197 197
 }
198 198
 
199
-function wpinv_get_item_price( $item_id = 0 ) {
200
-    if( empty( $item_id ) ) {
199
+function wpinv_get_item_price($item_id = 0) {
200
+    if (empty($item_id)) {
201 201
         return false;
202 202
     }
203 203
 
204
-    $item = new WPInv_Item( $item_id );
204
+    $item = new WPInv_Item($item_id);
205 205
     
206 206
     return $item->get_price();
207 207
 }
208 208
 
209
-function wpinv_is_recurring_item( $item_id = 0 ) {
210
-    if( empty( $item_id ) ) {
209
+function wpinv_is_recurring_item($item_id = 0) {
210
+    if (empty($item_id)) {
211 211
         return false;
212 212
     }
213 213
 
214
-    $item = new WPInv_Item( $item_id );
214
+    $item = new WPInv_Item($item_id);
215 215
     
216 216
     return $item->is_recurring();
217 217
 }
218 218
 
219
-function wpinv_item_price( $item_id = 0 ) {
220
-    if( empty( $item_id ) ) {
219
+function wpinv_item_price($item_id = 0) {
220
+    if (empty($item_id)) {
221 221
         return false;
222 222
     }
223 223
 
224
-    $price = wpinv_get_item_price( $item_id );
225
-    $price = wpinv_price( wpinv_format_amount( $price ) );
224
+    $price = wpinv_get_item_price($item_id);
225
+    $price = wpinv_price(wpinv_format_amount($price));
226 226
     
227
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
227
+    return apply_filters('wpinv_item_price', $price, $item_id);
228 228
 }
229 229
 
230
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
231
-    if ( empty( $item_id ) ) {
230
+function wpinv_item_show_price($item_id = 0, $echo = true) {
231
+    if (empty($item_id)) {
232 232
         $item_id = get_the_ID();
233 233
     }
234 234
 
235
-    $price = wpinv_item_price( $item_id );
235
+    $price = wpinv_item_price($item_id);
236 236
 
237
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
237
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
238 238
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
239
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
239
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
240 240
 
241
-    if ( $echo ) {
241
+    if ($echo) {
242 242
         echo $formatted_price;
243 243
     } else {
244 244
         return $formatted_price;
245 245
     }
246 246
 }
247 247
 
248
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
249
-    if ( is_null( $amount_override ) ) {
250
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
248
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
249
+    if (is_null($amount_override)) {
250
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
251 251
     } else {
252 252
         $original_price = $amount_override;
253 253
     }
254 254
     
255 255
     $price = $original_price;
256 256
 
257
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
257
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
258 258
 }
259 259
 
260
-function wpinv_item_custom_singular_name( $item_id ) {
261
-    if( empty( $item_id ) ) {
260
+function wpinv_item_custom_singular_name($item_id) {
261
+    if (empty($item_id)) {
262 262
         return false;
263 263
     }
264 264
 
265
-    $item = new WPInv_Item( $item_id );
265
+    $item = new WPInv_Item($item_id);
266 266
     
267 267
     return $item->get_custom_singular_name();
268 268
 }
269 269
 
270 270
 function wpinv_get_item_types() {
271 271
     $item_types = array(
272
-            'custom'    => __( 'Standard', 'invoicing' ),
273
-            'fee'       => __( 'Fee', 'invoicing' ),
272
+            'custom'    => __('Standard', 'invoicing'),
273
+            'fee'       => __('Fee', 'invoicing'),
274 274
         );
275
-    return apply_filters( 'wpinv_get_item_types', $item_types );
275
+    return apply_filters('wpinv_get_item_types', $item_types);
276 276
 }
277 277
 
278 278
 function wpinv_item_types() {
279 279
     $item_types = wpinv_get_item_types();
280 280
     
281
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
281
+    return (!empty($item_types) ? array_keys($item_types) : array());
282 282
 }
283 283
 
284
-function wpinv_get_item_type( $item_id ) {
285
-    if( empty( $item_id ) ) {
284
+function wpinv_get_item_type($item_id) {
285
+    if (empty($item_id)) {
286 286
         return false;
287 287
     }
288 288
 
289
-    $item = new WPInv_Item( $item_id );
289
+    $item = new WPInv_Item($item_id);
290 290
     
291 291
     return $item->get_type();
292 292
 }
293 293
 
294
-function wpinv_item_type( $item_id ) {
294
+function wpinv_item_type($item_id) {
295 295
     $item_types = wpinv_get_item_types();
296 296
     
297
-    $item_type = wpinv_get_item_type( $item_id );
297
+    $item_type = wpinv_get_item_type($item_id);
298 298
     
299
-    if ( empty( $item_type ) ) {
299
+    if (empty($item_type)) {
300 300
         $item_type = '-';
301 301
     }
302 302
     
303
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
303
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
304 304
 
305
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
305
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
306 306
 }
307 307
 
308
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
308
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
309 309
     global $wpinv_logs;
310 310
     
311
-    if ( empty( $wpinv_logs ) ) {
311
+    if (empty($wpinv_logs)) {
312 312
         return false;
313 313
     }
314 314
 
@@ -317,278 +317,278 @@  discard block
 block discarded – undo
317 317
         'log_type'		=> 'wpi_item'
318 318
     );
319 319
 
320
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
320
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
321 321
 
322 322
     $log_meta = array(
323 323
         'user_info'	=> $user_info,
324 324
         'user_id'	=> $user_id,
325
-        'file_id'	=> (int)$file_id,
325
+        'file_id'	=> (int) $file_id,
326 326
         'ip'		=> $ip,
327 327
         'invoice_id'=> $invoice_id,
328 328
     );
329 329
 
330
-    $wpinv_logs->insert_log( $log_data, $log_meta );
330
+    $wpinv_logs->insert_log($log_data, $log_meta);
331 331
 }
332 332
 
333
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
334
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
333
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
334
+    if ('wpi_item' !== get_post_type($item_id))
335 335
         return;
336 336
 
337 337
     global $wpinv_logs;
338 338
     
339
-    if ( empty( $wpinv_logs ) ) {
339
+    if (empty($wpinv_logs)) {
340 340
         return false;
341 341
     }
342 342
 
343 343
     // Remove all log entries related to this item
344
-    $wpinv_logs->delete_logs( $item_id );
344
+    $wpinv_logs->delete_logs($item_id);
345 345
 }
346
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
346
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
347 347
 
348
-function wpinv_get_random_item( $post_ids = true ) {
349
-    wpinv_get_random_items( 1, $post_ids );
348
+function wpinv_get_random_item($post_ids = true) {
349
+    wpinv_get_random_items(1, $post_ids);
350 350
 }
351 351
 
352
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
353
-    if ( $post_ids ) {
354
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
352
+function wpinv_get_random_items($num = 3, $post_ids = true) {
353
+    if ($post_ids) {
354
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
355 355
     } else {
356
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
356
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
357 357
     }
358 358
     
359
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
359
+    $args = apply_filters('wpinv_get_random_items', $args);
360 360
     
361
-    return get_posts( $args );
361
+    return get_posts($args);
362 362
 }
363 363
 
364
-function wpinv_get_item_token( $url = '' ) {
364
+function wpinv_get_item_token($url = '') {
365 365
     $args    = array();
366
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
367
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
366
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
367
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
368 368
 
369
-    $parts   = parse_url( $url );
369
+    $parts   = parse_url($url);
370 370
     $options = array();
371 371
 
372
-    if ( isset( $parts['query'] ) ) {
373
-        wp_parse_str( $parts['query'], $query_args );
372
+    if (isset($parts['query'])) {
373
+        wp_parse_str($parts['query'], $query_args);
374 374
 
375
-        if ( ! empty( $query_args['o'] ) ) {
376
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
375
+        if (!empty($query_args['o'])) {
376
+            $options = explode(':', rawurldecode($query_args['o']));
377 377
 
378
-            if ( in_array( 'ip', $options ) ) {
378
+            if (in_array('ip', $options)) {
379 379
                 $args['ip'] = wpinv_get_ip();
380 380
             }
381 381
 
382
-            if ( in_array( 'ua', $options ) ) {
382
+            if (in_array('ua', $options)) {
383 383
                 $ua = wpinv_get_user_agent();
384
-                $args['user_agent'] = rawurlencode( $ua );
384
+                $args['user_agent'] = rawurlencode($ua);
385 385
             }
386 386
         }
387 387
     }
388 388
 
389
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
389
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
390 390
 
391 391
     $args['secret'] = $secret;
392 392
     $args['token']  = false;
393 393
 
394
-    $url   = add_query_arg( $args, $url );
395
-    $parts = parse_url( $url );
394
+    $url   = add_query_arg($args, $url);
395
+    $parts = parse_url($url);
396 396
 
397
-    if ( ! isset( $parts['path'] ) ) {
397
+    if (!isset($parts['path'])) {
398 398
         $parts['path'] = '';
399 399
     }
400 400
 
401
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
401
+    $token = md5($parts['path'] . '?' . $parts['query']);
402 402
 
403 403
     return $token;
404 404
 }
405 405
 
406
-function wpinv_validate_url_token( $url = '' ) {
406
+function wpinv_validate_url_token($url = '') {
407 407
     $ret   = false;
408
-    $parts = parse_url( $url );
408
+    $parts = parse_url($url);
409 409
 
410
-    if ( isset( $parts['query'] ) ) {
411
-        wp_parse_str( $parts['query'], $query_args );
410
+    if (isset($parts['query'])) {
411
+        wp_parse_str($parts['query'], $query_args);
412 412
 
413
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
413
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
414 414
             'item',
415 415
             'ttl',
416 416
             'token'
417
-        ) );
417
+        ));
418 418
 
419 419
         $remove = array();
420 420
 
421
-        foreach( $query_args as $key => $value ) {
422
-            if( false === in_array( $key, $allowed ) ) {
421
+        foreach ($query_args as $key => $value) {
422
+            if (false === in_array($key, $allowed)) {
423 423
                 $remove[] = $key;
424 424
             }
425 425
         }
426 426
 
427
-        if( ! empty( $remove ) ) {
428
-            $url = remove_query_arg( $remove, $url );
427
+        if (!empty($remove)) {
428
+            $url = remove_query_arg($remove, $url);
429 429
         }
430 430
 
431
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
432
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
431
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
432
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
433 433
         }
434 434
 
435
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
435
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
436 436
             $ret = true;
437 437
         }
438 438
 
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
441
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
442 442
 }
443 443
 
444
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
444
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
445 445
     $cart_items = wpinv_get_cart_contents();
446 446
 
447 447
     $ret = false;
448 448
 
449
-    if ( is_array( $cart_items ) ) {
450
-        foreach ( $cart_items as $item ) {
451
-            if ( $item['id'] == $item_id ) {
449
+    if (is_array($cart_items)) {
450
+        foreach ($cart_items as $item) {
451
+            if ($item['id'] == $item_id) {
452 452
                 $ret = true;
453 453
                 break;
454 454
             }
455 455
         }
456 456
     }
457 457
 
458
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
458
+    return (bool) apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
459 459
 }
460 460
 
461
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
461
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
462 462
     $tax = 0;
463
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
464
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
465
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
463
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
464
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
465
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
466 466
 
467
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
467
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
468 468
     }
469 469
 
470
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
470
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
471 471
 }
472 472
 
473
-function wpinv_cart_item_price( $item, $currency = '' ) {
473
+function wpinv_cart_item_price($item, $currency = '') {
474 474
 
475
-    if( empty( $currency ) ) {
475
+    if (empty($currency)) {
476 476
         $currency = wpinv_get_currency();
477 477
     }
478 478
 
479
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
480
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
481
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
479
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
480
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
481
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
482 482
     
483
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
484
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
483
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
484
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
485 485
             $price += $tax;
486 486
         }
487 487
         
488
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
488
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
489 489
             $price -= $tax;
490 490
         }        
491 491
     }
492 492
 
493
-    $price = wpinv_price( wpinv_format_amount( $price ), $currency );
493
+    $price = wpinv_price(wpinv_format_amount($price), $currency);
494 494
 
495
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
495
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
496 496
 }
497 497
 
498
-function wpinv_cart_item_subtotal( $item, $currency = '' ) {
498
+function wpinv_cart_item_subtotal($item, $currency = '') {
499 499
 
500
-    if( empty( $currency ) ) {
500
+    if (empty($currency)) {
501 501
         $currency = wpinv_get_currency();
502 502
     }
503 503
 
504
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
505
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ), $currency );
504
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
505
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal), $currency);
506 506
 
507
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
507
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
508 508
 }
509 509
 
510
-function wpinv_cart_item_tax( $item, $currency = '' ) {
510
+function wpinv_cart_item_tax($item, $currency = '') {
511 511
     $tax        = '';
512 512
     $tax_rate   = '';
513 513
 
514
-    if( empty( $currency ) ) {
514
+    if (empty($currency)) {
515 515
         $currency = wpinv_get_currency();
516 516
     }
517 517
     
518
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
519
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ), $currency );
520
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
521
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
518
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
519
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']), $currency);
520
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
521
+        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
522 522
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
523 523
     }
524 524
     
525
-    $tax        = $tax . $tax_rate;
525
+    $tax = $tax . $tax_rate;
526 526
     
527
-    if ( $tax === '' ) {
527
+    if ($tax === '') {
528 528
         $tax = 0; // Zero tax
529 529
     }
530 530
 
531
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
531
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
532 532
 }
533 533
 
534
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
534
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
535 535
     $price = 0;
536 536
     
537 537
     // Set custom price
538
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
538
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
539 539
         $price = $cart_item['custom_price'];
540 540
     } else {
541
-        $variable_prices = wpinv_has_variable_prices( $item_id );
541
+        $variable_prices = wpinv_has_variable_prices($item_id);
542 542
 
543
-        if ( $variable_prices ) {
544
-            $prices = wpinv_get_variable_prices( $item_id );
543
+        if ($variable_prices) {
544
+            $prices = wpinv_get_variable_prices($item_id);
545 545
 
546
-            if ( $prices ) {
547
-                if( ! empty( $options ) ) {
548
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
546
+            if ($prices) {
547
+                if (!empty($options)) {
548
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
549 549
                 } else {
550 550
                     $price = false;
551 551
                 }
552 552
             }
553 553
         }
554 554
 
555
-        if( ! $variable_prices || false === $price ) {
556
-            if($cart_item['item_price'] > 0){
555
+        if (!$variable_prices || false === $price) {
556
+            if ($cart_item['item_price'] > 0) {
557 557
                 $price = $cart_item['item_price'];
558 558
             } else {
559 559
                 // Get the standard Item price if not using variable prices
560
-                $price = wpinv_get_item_price( $item_id );
560
+                $price = wpinv_get_item_price($item_id);
561 561
             }
562 562
         }
563 563
     }
564 564
 
565
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
566
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
565
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
566
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
567 567
     }
568 568
 
569
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
569
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
570 570
 }
571 571
 
572
-function wpinv_get_cart_item_price_id( $item = array() ) {
573
-    if( isset( $item['item_number'] ) ) {
574
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
572
+function wpinv_get_cart_item_price_id($item = array()) {
573
+    if (isset($item['item_number'])) {
574
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
575 575
     } else {
576
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
576
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
577 577
     }
578 578
     return $price_id;
579 579
 }
580 580
 
581
-function wpinv_get_cart_item_price_name( $item = array() ) {
582
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
583
-    $prices   = wpinv_get_variable_prices( $item['id'] );
584
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
585
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
581
+function wpinv_get_cart_item_price_name($item = array()) {
582
+    $price_id = (int) wpinv_get_cart_item_price_id($item);
583
+    $prices   = wpinv_get_variable_prices($item['id']);
584
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
585
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
586 586
 }
587 587
 
588
-function wpinv_get_cart_item_name( $item = array() ) {
589
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
588
+function wpinv_get_cart_item_name($item = array()) {
589
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
590 590
 
591
-    if ( empty( $item_title ) ) {
591
+    if (empty($item_title)) {
592 592
         $item_title = $item['id'];
593 593
     }
594 594
 
@@ -598,23 +598,23 @@  discard block
 block discarded – undo
598 598
     }
599 599
     */
600 600
 
601
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
601
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
602 602
 }
603 603
 
604
-function wpinv_has_variable_prices( $item_id = 0 ) {
604
+function wpinv_has_variable_prices($item_id = 0) {
605 605
     return false;
606 606
 }
607 607
 
608
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
608
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
609 609
     $cart_items = wpinv_get_cart_contents();
610 610
 
611
-    if ( !is_array( $cart_items ) ) {
611
+    if (!is_array($cart_items)) {
612 612
         return false; // Empty cart
613 613
     } else {
614
-        foreach ( $cart_items as $position => $item ) {
615
-            if ( $item['id'] == $item_id ) {
616
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
617
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
614
+        foreach ($cart_items as $position => $item) {
615
+            if ($item['id'] == $item_id) {
616
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
617
+                    if ((int) $options['price_id'] == (int) $item['options']['price_id']) {
618 618
                         return $position;
619 619
                     }
620 620
                 } else {
@@ -627,80 +627,80 @@  discard block
 block discarded – undo
627 627
     return false; // Not found
628 628
 }
629 629
 
630
-function wpinv_get_cart_item_quantity( $item ) {
631
-    if ( wpinv_item_quantities_enabled() ) {
632
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
630
+function wpinv_get_cart_item_quantity($item) {
631
+    if (wpinv_item_quantities_enabled()) {
632
+        $quantity = !empty($item['quantity']) && (int) $item['quantity'] > 0 ? absint($item['quantity']) : 1;
633 633
     } else {
634 634
         $quantity = 1;
635 635
     }
636 636
     
637
-    if ( $quantity < 1 ) {
637
+    if ($quantity < 1) {
638 638
         $quantity = 1;
639 639
     }
640 640
     
641
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
641
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
642 642
 }
643 643
 
644
-function wpinv_get_item_suffix( $item, $html = true ) {
645
-    if ( empty( $item ) ) {
644
+function wpinv_get_item_suffix($item, $html = true) {
645
+    if (empty($item)) {
646 646
         return NULL;
647 647
     }
648 648
     
649
-    if ( is_int( $item ) ) {
650
-        $item = new WPInv_Item( $item );
649
+    if (is_int($item)) {
650
+        $item = new WPInv_Item($item);
651 651
     }
652 652
     
653
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
653
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
654 654
         return NULL;
655 655
     }
656 656
     
657
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
657
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
658 658
     
659
-    if ( !$html && $suffix ) {
660
-        $suffix = strip_tags( $suffix );
659
+    if (!$html && $suffix) {
660
+        $suffix = strip_tags($suffix);
661 661
     }
662 662
     
663
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
663
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
664 664
 }
665 665
 
666
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
667
-    if ( empty( $item ) ) {
666
+function wpinv_remove_item($item = 0, $force_delete = false) {
667
+    if (empty($item)) {
668 668
         return NULL;
669 669
     }
670 670
     
671
-    if ( is_int( $item ) ) {
672
-        $item = new WPInv_Item( $item );
671
+    if (is_int($item)) {
672
+        $item = new WPInv_Item($item);
673 673
     }
674 674
     
675
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
675
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
676 676
         return NULL;
677 677
     }
678 678
     
679
-    do_action( 'wpinv_pre_delete_item', $item );
679
+    do_action('wpinv_pre_delete_item', $item);
680 680
 
681
-    wp_delete_post( $item->ID, $force_delete );
681
+    wp_delete_post($item->ID, $force_delete);
682 682
 
683
-    do_action( 'wpinv_post_delete_item', $item );
683
+    do_action('wpinv_post_delete_item', $item);
684 684
 }
685 685
 
686
-function wpinv_can_delete_item( $post_id ) {
686
+function wpinv_can_delete_item($post_id) {
687 687
     $return = wpinv_current_user_can_manage_invoicing() ? true : false;
688 688
     
689
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
689
+    if ($return && wpinv_item_in_use($post_id)) {
690 690
         $return = false; // Don't delete item already use in invoices.
691 691
     }
692 692
     
693
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
693
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
694 694
 }
695 695
 
696 696
 function wpinv_admin_action_delete() {
697 697
     $screen = get_current_screen();
698 698
     
699
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
699
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
700 700
         $post_ids = array();
701 701
         
702
-        foreach ( $_REQUEST['post'] as $post_id ) {
703
-            if ( !wpinv_can_delete_item( $post_id ) ) {
702
+        foreach ($_REQUEST['post'] as $post_id) {
703
+            if (!wpinv_can_delete_item($post_id)) {
704 704
                 continue;
705 705
             }
706 706
             
@@ -710,88 +710,88 @@  discard block
 block discarded – undo
710 710
         $_REQUEST['post'] = $post_ids;
711 711
     }
712 712
 }
713
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
714
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
713
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
714
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
715 715
 
716
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
717
-    if ( $post->post_type == 'wpi_item' ) {
718
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
716
+function wpinv_check_delete_item($check, $post, $force_delete) {
717
+    if ($post->post_type == 'wpi_item') {
718
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
719 719
             return true;
720 720
         }
721 721
     }
722 722
     
723 723
     return $check;
724 724
 }
725
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
725
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
726 726
 
727
-function wpinv_item_in_use( $item_id ) {
727
+function wpinv_item_in_use($item_id) {
728 728
     global $wpdb, $wpi_items_in_use;
729 729
     
730
-    if ( !$item_id > 0 ) {
730
+    if (!$item_id > 0) {
731 731
         return false;
732 732
     }
733 733
     
734
-    if ( !empty( $wpi_items_in_use ) ) {
735
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
734
+    if (!empty($wpi_items_in_use)) {
735
+        if (isset($wpi_items_in_use[$item_id])) {
736 736
             return $wpi_items_in_use[$item_id];
737 737
         }
738 738
     } else {
739 739
         $wpi_items_in_use = array();
740 740
     }
741 741
     
742
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
742
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
743 743
     
744
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
745
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
744
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int) $item_id . "', pm.meta_value )";
745
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
746 746
     
747 747
     $wpi_items_in_use[$item_id] = $in_use;
748 748
     
749 749
     return $in_use;
750 750
 }
751 751
 
752
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
752
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
753 753
     // Set some defaults
754 754
     $defaults = array(
755
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
756
-        'title'                => '',                                                      // Required. Item title.
757
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
758
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
759
-        'status'               => 'pending',                                               // Optional. pending, publish
760
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
761
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
762
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
763
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
764
-        'excerpt'              => '',                                                      // Optional. Item short description
755
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
756
+        'title'                => '', // Required. Item title.
757
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
758
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
759
+        'status'               => 'pending', // Optional. pending, publish
760
+        'custom_name'          => '', // Optional. Plural sub title for item.
761
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
762
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
763
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
764
+        'excerpt'              => '', // Optional. Item short description
765 765
         /* Recurring item fields */
766
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
767
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
768
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
769
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
770
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
771
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
772
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
773
-        'minimum_price'        => '0.00',                                                  // Optional. Minimum allowed prices for items with dynamic pricing.
774
-        'dynamic_pricing'      => 0,                                                       // Optional. Whether or not the item supports dynamic prices.
766
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
767
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
768
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
769
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
770
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
771
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
772
+        'trial_interval'       => 0, // Optional. Any integer number.
773
+        'minimum_price'        => '0.00', // Optional. Minimum allowed prices for items with dynamic pricing.
774
+        'dynamic_pricing'      => 0, // Optional. Whether or not the item supports dynamic prices.
775 775
     );
776 776
 
777
-    $data = wp_parse_args( $args, $defaults );
777
+    $data = wp_parse_args($args, $defaults);
778 778
 
779
-    if ( empty( $data['type'] ) ) {
779
+    if (empty($data['type'])) {
780 780
         $data['type'] = 'custom';
781 781
     }
782 782
 
783
-    if ( !empty( $data['custom_id'] ) ) {
784
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
783
+    if (!empty($data['custom_id'])) {
784
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
785 785
     } else {
786 786
         $item = NULL;
787 787
     }
788 788
 
789
-    if ( !empty( $item ) ) {
790
-        if ( $force_update ) {
791
-            if ( empty( $args['ID'] ) ) {
789
+    if (!empty($item)) {
790
+        if ($force_update) {
791
+            if (empty($args['ID'])) {
792 792
                 $args['ID'] = $item->ID;
793 793
             }
794
-            return wpinv_update_item( $args, $wp_error );
794
+            return wpinv_update_item($args, $wp_error);
795 795
         }
796 796
 
797 797
         return $item;
@@ -802,21 +802,21 @@  discard block
 block discarded – undo
802 802
     $meta['custom_id']              = $data['custom_id'];
803 803
     $meta['custom_singular_name']   = $data['custom_singular_name'];
804 804
     $meta['custom_name']            = $data['custom_name'];
805
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
806
-    $meta['editable']               = (int)$data['editable'];
805
+    $meta['price']                  = wpinv_round_amount($data['price']);
806
+    $meta['editable']               = (int) $data['editable'];
807 807
     $meta['vat_rule']               = $data['vat_rule'];
808 808
     $meta['vat_class']              = '_standard';
809 809
     $meta['dynamic_pricing']        = (int) $data['dynamic_pricing'];
810
-    $meta['minimum_price']          = wpinv_round_amount( $data['minimum_price'] );
810
+    $meta['minimum_price']          = wpinv_round_amount($data['minimum_price']);
811 811
     
812
-    if ( !empty( $data['is_recurring'] ) ) {
812
+    if (!empty($data['is_recurring'])) {
813 813
         $meta['is_recurring']       = $data['is_recurring'];
814 814
         $meta['recurring_period']   = $data['recurring_period'];
815
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
816
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
815
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
816
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
817 817
         $meta['free_trial']         = $data['free_trial'];
818 818
         $meta['trial_period']       = $data['trial_period'];
819
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
819
+        $meta['trial_interval']     = absint($data['trial_interval']);
820 820
     } else {
821 821
         $meta['is_recurring']       = 0;
822 822
         $meta['recurring_period']   = '';
@@ -827,7 +827,7 @@  discard block
 block discarded – undo
827 827
         $meta['trial_interval']     = '';
828 828
     }
829 829
     
830
-    $post_data  = array( 
830
+    $post_data = array( 
831 831
         'post_title'    => $data['title'],
832 832
         'post_excerpt'  => $data['excerpt'],
833 833
         'post_status'   => $data['status'],
@@ -835,34 +835,34 @@  discard block
 block discarded – undo
835 835
     );
836 836
 
837 837
     $item = new WPInv_Item();
838
-    $return = $item->create( $post_data, $wp_error );
838
+    $return = $item->create($post_data, $wp_error);
839 839
 
840
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
840
+    if ($return && !empty($item) && !is_wp_error($return)) {
841 841
         return $item;
842 842
     }
843 843
 
844
-    if ( $wp_error && is_wp_error( $return ) ) {
844
+    if ($wp_error && is_wp_error($return)) {
845 845
         return $return;
846 846
     }
847 847
     return 0;
848 848
 }
849 849
 
850
-function wpinv_update_item( $args = array(), $wp_error = false ) {
851
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
850
+function wpinv_update_item($args = array(), $wp_error = false) {
851
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
852 852
 
853
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
854
-        if ( $wp_error ) {
855
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
853
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
854
+        if ($wp_error) {
855
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
856 856
         }
857 857
         return 0;
858 858
     }
859 859
     
860
-    if ( !empty( $args['custom_id'] ) ) {
861
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
860
+    if (!empty($args['custom_id'])) {
861
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
862 862
         
863
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
864
-            if ( $wp_error ) {
865
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
863
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
864
+            if ($wp_error) {
865
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
866 866
             }
867 867
             return 0;
868 868
         }
@@ -889,54 +889,54 @@  discard block
 block discarded – undo
889 889
     );
890 890
 
891 891
     $post_data = array();
892
-    if ( isset( $args['title'] ) ) { 
892
+    if (isset($args['title'])) { 
893 893
         $post_data['post_title'] = $args['title'];
894 894
     }
895
-    if ( isset( $args['excerpt'] ) ) { 
895
+    if (isset($args['excerpt'])) { 
896 896
         $post_data['post_excerpt'] = $args['excerpt'];
897 897
     }
898
-    if ( isset( $args['status'] ) ) { 
898
+    if (isset($args['status'])) { 
899 899
         $post_data['post_status'] = $args['status'];
900 900
     }
901 901
     
902
-    foreach ( $meta_fields as $meta_field ) {
903
-        if ( isset( $args[ $meta_field ] ) ) { 
904
-            $value = $args[ $meta_field ];
902
+    foreach ($meta_fields as $meta_field) {
903
+        if (isset($args[$meta_field])) { 
904
+            $value = $args[$meta_field];
905 905
 
906
-            switch ( $meta_field ) {
906
+            switch ($meta_field) {
907 907
                 case 'price':
908 908
                 case 'minimum_price':
909
-                    $value = wpinv_round_amount( $value );
909
+                    $value = wpinv_round_amount($value);
910 910
                 break;
911 911
                 case 'recurring_interval':
912 912
                 case 'recurring_limit':
913 913
                 case 'trial_interval':
914
-                    $value = absint( $value );
914
+                    $value = absint($value);
915 915
                 break;
916 916
 				case 'editable':
917 917
                     $value = (int) $value;
918 918
                 break;
919 919
             }
920 920
 
921
-            $post_data['meta'][ $meta_field ] = $value;
921
+            $post_data['meta'][$meta_field] = $value;
922 922
         };
923 923
     }
924 924
 
925
-    if ( empty( $post_data ) ) {
926
-        if ( $wp_error ) {
927
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
925
+    if (empty($post_data)) {
926
+        if ($wp_error) {
927
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
928 928
         }
929 929
         return 0;
930 930
     }
931 931
     $post_data['ID'] = $args['ID'];
932 932
 
933
-    $return = $item->update( $post_data, $wp_error );
933
+    $return = $item->update($post_data, $wp_error);
934 934
 
935
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
935
+    if ($return && !empty($item) && !is_wp_error($return)) {
936 936
         return $item;
937 937
     }
938 938
 
939
-    if ( $wp_error && is_wp_error( $return ) ) {
939
+    if ($wp_error && is_wp_error($return)) {
940 940
         return $return;
941 941
     }
942 942
     return 0;
@@ -945,7 +945,7 @@  discard block
 block discarded – undo
945 945
 /**
946 946
  * Sanitizes a recurring period
947 947
  */
948
-function getpaid_sanitize_recurring_period( $period, $full = false ) {
948
+function getpaid_sanitize_recurring_period($period, $full = false) {
949 949
 
950 950
     $periods = array(
951 951
         'D' => 'day',
@@ -954,10 +954,10 @@  discard block
 block discarded – undo
954 954
         'Y' => 'year',
955 955
     );
956 956
 
957
-    if ( ! isset( $periods[ $period ] ) ) {
957
+    if (!isset($periods[$period])) {
958 958
         $period = 'D';
959 959
     }
960 960
     
961
-    return $full ? $periods[ $period ] : $period;
961
+    return $full ? $periods[$period] : $period;
962 962
 
963 963
 }
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
Indentation   +552 added lines, -552 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
 /**
@@ -17,30 +17,30 @@  discard block
 block discarded – undo
17 17
     public $ID = 0;
18 18
 
19 19
     /**
20
-	 * Which data store to load.
21
-	 *
22
-	 * @var string
23
-	 */
20
+     * Which data store to load.
21
+     *
22
+     * @var string
23
+     */
24 24
     protected $data_store_name = 'item';
25 25
 
26 26
     /**
27
-	 * This is the name of this object type.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	protected $object_type = 'item';
27
+     * This is the name of this object type.
28
+     *
29
+     * @var string
30
+     */
31
+    protected $object_type = 'item';
32 32
 
33 33
     /**
34
-	 * Item Data array. This is the core item data exposed in APIs.
35
-	 *
36
-	 * @since 1.0.19
37
-	 * @var array
38
-	 */
39
-	protected $data = array(
40
-		'parent_id'            => 0,
41
-		'status'               => 'draft',
42
-		'version'              => '',
43
-		'date_created'         => null,
34
+     * Item Data array. This is the core item data exposed in APIs.
35
+     *
36
+     * @since 1.0.19
37
+     * @var array
38
+     */
39
+    protected $data = array(
40
+        'parent_id'            => 0,
41
+        'status'               => 'draft',
42
+        'version'              => '',
43
+        'date_created'         => null,
44 44
         'date_modified'        => null,
45 45
         'name'                 => '',
46 46
         'description'          => '',
@@ -66,13 +66,13 @@  discard block
 block discarded – undo
66 66
     );
67 67
 
68 68
     /**
69
-	 * Stores meta in cache for future reads.
70
-	 *
71
-	 * A group must be set to to enable caching.
72
-	 *
73
-	 * @var string
74
-	 */
75
-	protected $cache_group = 'getpaid_items';
69
+     * Stores meta in cache for future reads.
70
+     *
71
+     * A group must be set to to enable caching.
72
+     *
73
+     * @var string
74
+     */
75
+    protected $cache_group = 'getpaid_items';
76 76
 
77 77
     /**
78 78
      * Stores a reference to the original WP_Post object
@@ -82,31 +82,31 @@  discard block
 block discarded – undo
82 82
     protected $post = null; 
83 83
 
84 84
     /**
85
-	 * Get the item if ID is passed, otherwise the item is new and empty.
86
-	 *
87
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
88
-	 */
89
-	public function __construct( $item = 0 ) {
90
-		parent::__construct( $item );
91
-
92
-		if ( is_numeric( $item ) && $item > 0 ) {
93
-			$this->set_id( $item );
94
-		} elseif ( $item instanceof self ) {
95
-			$this->set_id( $item->get_id() );
96
-		} elseif ( ! empty( $item->ID ) ) {
97
-			$this->set_id( $item->ID );
98
-		} else {
99
-			$this->set_object_read( true );
100
-		}
85
+     * Get the item if ID is passed, otherwise the item is new and empty.
86
+     *
87
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
88
+     */
89
+    public function __construct( $item = 0 ) {
90
+        parent::__construct( $item );
91
+
92
+        if ( is_numeric( $item ) && $item > 0 ) {
93
+            $this->set_id( $item );
94
+        } elseif ( $item instanceof self ) {
95
+            $this->set_id( $item->get_id() );
96
+        } elseif ( ! empty( $item->ID ) ) {
97
+            $this->set_id( $item->ID );
98
+        } else {
99
+            $this->set_object_read( true );
100
+        }
101 101
 
102 102
         // Load the datastore.
103
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
103
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
104 104
 
105
-		if ( $this->get_id() > 0 ) {
105
+        if ( $this->get_id() > 0 ) {
106 106
             $this->post = get_post( $this->get_id() );
107
-			$this->data_store->read( $this );
108
-		}
109
-	}
107
+            $this->data_store->read( $this );
108
+        }
109
+    }
110 110
 
111 111
     /*
112 112
 	|--------------------------------------------------------------------------
@@ -124,176 +124,176 @@  discard block
 block discarded – undo
124 124
     */
125 125
 
126 126
     /**
127
-	 * Get parent item ID.
128
-	 *
129
-	 * @since 1.0.19
130
-	 * @param  string $context View or edit context.
131
-	 * @return int
132
-	 */
133
-	public function get_parent_id( $context = 'view' ) {
134
-		return (int) $this->get_prop( 'parent_id', $context );
127
+     * Get parent item ID.
128
+     *
129
+     * @since 1.0.19
130
+     * @param  string $context View or edit context.
131
+     * @return int
132
+     */
133
+    public function get_parent_id( $context = 'view' ) {
134
+        return (int) $this->get_prop( 'parent_id', $context );
135 135
     }
136 136
 
137 137
     /**
138
-	 * Get item status.
139
-	 *
140
-	 * @since 1.0.19
141
-	 * @param  string $context View or edit context.
142
-	 * @return string
143
-	 */
144
-	public function get_status( $context = 'view' ) {
145
-		return $this->get_prop( 'status', $context );
138
+     * Get item status.
139
+     *
140
+     * @since 1.0.19
141
+     * @param  string $context View or edit context.
142
+     * @return string
143
+     */
144
+    public function get_status( $context = 'view' ) {
145
+        return $this->get_prop( 'status', $context );
146 146
     }
147 147
 
148 148
     /**
149
-	 * Get plugin version when the item was created.
150
-	 *
151
-	 * @since 1.0.19
152
-	 * @param  string $context View or edit context.
153
-	 * @return string
154
-	 */
155
-	public function get_version( $context = 'view' ) {
156
-		return $this->get_prop( 'version', $context );
149
+     * Get plugin version when the item was created.
150
+     *
151
+     * @since 1.0.19
152
+     * @param  string $context View or edit context.
153
+     * @return string
154
+     */
155
+    public function get_version( $context = 'view' ) {
156
+        return $this->get_prop( 'version', $context );
157 157
     }
158 158
 
159 159
     /**
160
-	 * Get date when the item was created.
161
-	 *
162
-	 * @since 1.0.19
163
-	 * @param  string $context View or edit context.
164
-	 * @return string
165
-	 */
166
-	public function get_date_created( $context = 'view' ) {
167
-		return $this->get_prop( 'date_created', $context );
160
+     * Get date when the item was created.
161
+     *
162
+     * @since 1.0.19
163
+     * @param  string $context View or edit context.
164
+     * @return string
165
+     */
166
+    public function get_date_created( $context = 'view' ) {
167
+        return $this->get_prop( 'date_created', $context );
168 168
     }
169 169
 
170 170
     /**
171
-	 * Get GMT date when the item was created.
172
-	 *
173
-	 * @since 1.0.19
174
-	 * @param  string $context View or edit context.
175
-	 * @return string
176
-	 */
177
-	public function get_date_created_gmt( $context = 'view' ) {
171
+     * Get GMT date when the item was created.
172
+     *
173
+     * @since 1.0.19
174
+     * @param  string $context View or edit context.
175
+     * @return string
176
+     */
177
+    public function get_date_created_gmt( $context = 'view' ) {
178 178
         $date = $this->get_date_created( $context );
179 179
 
180 180
         if ( $date ) {
181 181
             $date = get_gmt_from_date( $date );
182 182
         }
183
-		return $date;
183
+        return $date;
184 184
     }
185 185
 
186 186
     /**
187
-	 * Get date when the item was last modified.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return string
192
-	 */
193
-	public function get_date_modified( $context = 'view' ) {
194
-		return $this->get_prop( 'date_modified', $context );
187
+     * Get date when the item was last modified.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return string
192
+     */
193
+    public function get_date_modified( $context = 'view' ) {
194
+        return $this->get_prop( 'date_modified', $context );
195 195
     }
196 196
 
197 197
     /**
198
-	 * Get GMT date when the item was last modified.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return string
203
-	 */
204
-	public function get_date_modified_gmt( $context = 'view' ) {
198
+     * Get GMT date when the item was last modified.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return string
203
+     */
204
+    public function get_date_modified_gmt( $context = 'view' ) {
205 205
         $date = $this->get_date_modified( $context );
206 206
 
207 207
         if ( $date ) {
208 208
             $date = get_gmt_from_date( $date );
209 209
         }
210
-		return $date;
210
+        return $date;
211 211
     }
212 212
 
213 213
     /**
214
-	 * Get the item name.
215
-	 *
216
-	 * @since 1.0.19
217
-	 * @param  string $context View or edit context.
218
-	 * @return string
219
-	 */
220
-	public function get_name( $context = 'view' ) {
221
-		return $this->get_prop( 'name', $context );
214
+     * Get the item name.
215
+     *
216
+     * @since 1.0.19
217
+     * @param  string $context View or edit context.
218
+     * @return string
219
+     */
220
+    public function get_name( $context = 'view' ) {
221
+        return $this->get_prop( 'name', $context );
222 222
     }
223 223
 
224 224
     /**
225
-	 * Alias of self::get_name().
226
-	 *
227
-	 * @since 1.0.19
228
-	 * @param  string $context View or edit context.
229
-	 * @return string
230
-	 */
231
-	public function get_title( $context = 'view' ) {
232
-		return $this->get_name( $context );
225
+     * Alias of self::get_name().
226
+     *
227
+     * @since 1.0.19
228
+     * @param  string $context View or edit context.
229
+     * @return string
230
+     */
231
+    public function get_title( $context = 'view' ) {
232
+        return $this->get_name( $context );
233 233
     }
234 234
 
235 235
     /**
236
-	 * Get the item description.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @param  string $context View or edit context.
240
-	 * @return string
241
-	 */
242
-	public function get_description( $context = 'view' ) {
243
-		return $this->get_prop( 'description', $context );
236
+     * Get the item description.
237
+     *
238
+     * @since 1.0.19
239
+     * @param  string $context View or edit context.
240
+     * @return string
241
+     */
242
+    public function get_description( $context = 'view' ) {
243
+        return $this->get_prop( 'description', $context );
244 244
     }
245 245
 
246 246
     /**
247
-	 * Alias of self::get_description().
248
-	 *
249
-	 * @since 1.0.19
250
-	 * @param  string $context View or edit context.
251
-	 * @return string
252
-	 */
253
-	public function get_excerpt( $context = 'view' ) {
254
-		return $this->get_description( $context );
247
+     * Alias of self::get_description().
248
+     *
249
+     * @since 1.0.19
250
+     * @param  string $context View or edit context.
251
+     * @return string
252
+     */
253
+    public function get_excerpt( $context = 'view' ) {
254
+        return $this->get_description( $context );
255 255
     }
256 256
 
257 257
     /**
258
-	 * Alias of self::get_description().
259
-	 *
260
-	 * @since 1.0.19
261
-	 * @param  string $context View or edit context.
262
-	 * @return string
263
-	 */
264
-	public function get_summary( $context = 'view' ) {
265
-		return $this->get_description( $context );
258
+     * Alias of self::get_description().
259
+     *
260
+     * @since 1.0.19
261
+     * @param  string $context View or edit context.
262
+     * @return string
263
+     */
264
+    public function get_summary( $context = 'view' ) {
265
+        return $this->get_description( $context );
266 266
     }
267 267
 
268 268
     /**
269
-	 * Get the owner of the item.
270
-	 *
271
-	 * @since 1.0.19
272
-	 * @param  string $context View or edit context.
273
-	 * @return string
274
-	 */
275
-	public function get_author( $context = 'view' ) {
276
-		return (int) $this->get_prop( 'author', $context );
269
+     * Get the owner of the item.
270
+     *
271
+     * @since 1.0.19
272
+     * @param  string $context View or edit context.
273
+     * @return string
274
+     */
275
+    public function get_author( $context = 'view' ) {
276
+        return (int) $this->get_prop( 'author', $context );
277 277
     }
278 278
 
279 279
     /**
280
-	 * Get the price of the item.
281
-	 *
282
-	 * @since 1.0.19
283
-	 * @param  string $context View or edit context.
284
-	 * @return string
285
-	 */
286
-	public function get_price( $context = 'view' ) {
280
+     * Get the price of the item.
281
+     *
282
+     * @since 1.0.19
283
+     * @param  string $context View or edit context.
284
+     * @return string
285
+     */
286
+    public function get_price( $context = 'view' ) {
287 287
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
288 288
     }
289 289
 
290 290
     /**
291
-	 * Returns a formated price.
292
-	 *
293
-	 * @since 1.0.19
294
-	 * @param  string $context View or edit context.
295
-	 * @return string
296
-	 */
291
+     * Returns a formated price.
292
+     *
293
+     * @since 1.0.19
294
+     * @param  string $context View or edit context.
295
+     * @return string
296
+     */
297 297
     public function get_the_price() {
298 298
         $item_price = wpinv_price( wpinv_format_amount( $this->get_price() ) );
299 299
 
@@ -301,134 +301,134 @@  discard block
 block discarded – undo
301 301
     }
302 302
 
303 303
     /**
304
-	 * Get the VAT rule of the item.
305
-	 *
306
-	 * @since 1.0.19
307
-	 * @param  string $context View or edit context.
308
-	 * @return string
309
-	 */
310
-	public function get_vat_rule( $context = 'view' ) {
304
+     * Get the VAT rule of the item.
305
+     *
306
+     * @since 1.0.19
307
+     * @param  string $context View or edit context.
308
+     * @return string
309
+     */
310
+    public function get_vat_rule( $context = 'view' ) {
311 311
         return $this->get_prop( 'vat_rule', $context );
312 312
     }
313 313
 
314 314
     /**
315
-	 * Get the VAT class of the item.
316
-	 *
317
-	 * @since 1.0.19
318
-	 * @param  string $context View or edit context.
319
-	 * @return string
320
-	 */
321
-	public function get_vat_class( $context = 'view' ) {
315
+     * Get the VAT class of the item.
316
+     *
317
+     * @since 1.0.19
318
+     * @param  string $context View or edit context.
319
+     * @return string
320
+     */
321
+    public function get_vat_class( $context = 'view' ) {
322 322
         return $this->get_prop( 'vat_class', $context );
323 323
     }
324 324
 
325 325
     /**
326
-	 * Get the type of the item.
327
-	 *
328
-	 * @since 1.0.19
329
-	 * @param  string $context View or edit context.
330
-	 * @return string
331
-	 */
332
-	public function get_type( $context = 'view' ) {
326
+     * Get the type of the item.
327
+     *
328
+     * @since 1.0.19
329
+     * @param  string $context View or edit context.
330
+     * @return string
331
+     */
332
+    public function get_type( $context = 'view' ) {
333 333
         return $this->get_prop( 'type', $context );
334 334
     }
335 335
 
336 336
     /**
337
-	 * Get the custom id of the item.
338
-	 *
339
-	 * @since 1.0.19
340
-	 * @param  string $context View or edit context.
341
-	 * @return string
342
-	 */
343
-	public function get_custom_id( $context = 'view' ) {
337
+     * Get the custom id of the item.
338
+     *
339
+     * @since 1.0.19
340
+     * @param  string $context View or edit context.
341
+     * @return string
342
+     */
343
+    public function get_custom_id( $context = 'view' ) {
344 344
         return $this->get_prop( 'custom_id', $context );
345 345
     }
346 346
 
347 347
     /**
348
-	 * Get the custom name of the item.
349
-	 *
350
-	 * @since 1.0.19
351
-	 * @param  string $context View or edit context.
352
-	 * @return string
353
-	 */
354
-	public function get_custom_name( $context = 'view' ) {
348
+     * Get the custom name of the item.
349
+     *
350
+     * @since 1.0.19
351
+     * @param  string $context View or edit context.
352
+     * @return string
353
+     */
354
+    public function get_custom_name( $context = 'view' ) {
355 355
         return $this->get_prop( 'custom_name', $context );
356 356
     }
357 357
 
358 358
     /**
359
-	 * Get the custom singular name of the item.
360
-	 *
361
-	 * @since 1.0.19
362
-	 * @param  string $context View or edit context.
363
-	 * @return string
364
-	 */
365
-	public function get_custom_singular_name( $context = 'view' ) {
359
+     * Get the custom singular name of the item.
360
+     *
361
+     * @since 1.0.19
362
+     * @param  string $context View or edit context.
363
+     * @return string
364
+     */
365
+    public function get_custom_singular_name( $context = 'view' ) {
366 366
         return $this->get_prop( 'custom_singular_name', $context );
367 367
     }
368 368
 
369 369
     /**
370
-	 * Checks if an item is editable..
371
-	 *
372
-	 * @since 1.0.19
373
-	 * @param  string $context View or edit context.
374
-	 * @return string
375
-	 */
376
-	public function get_is_editable( $context = 'view' ) {
370
+     * Checks if an item is editable..
371
+     *
372
+     * @since 1.0.19
373
+     * @param  string $context View or edit context.
374
+     * @return string
375
+     */
376
+    public function get_is_editable( $context = 'view' ) {
377 377
         return $this->get_prop( 'is_editable', $context );
378 378
     }
379 379
 
380 380
     /**
381
-	 * Alias of self::get_is_editable().
382
-	 *
383
-	 * @since 1.0.19
384
-	 * @param  string $context View or edit context.
385
-	 * @return string
386
-	 */
387
-	public function get_editable( $context = 'view' ) {
388
-		return $this->get_is_editable( $context );
381
+     * Alias of self::get_is_editable().
382
+     *
383
+     * @since 1.0.19
384
+     * @param  string $context View or edit context.
385
+     * @return string
386
+     */
387
+    public function get_editable( $context = 'view' ) {
388
+        return $this->get_is_editable( $context );
389 389
     }
390 390
 
391 391
     /**
392
-	 * Checks if dynamic pricing is enabled.
393
-	 *
394
-	 * @since 1.0.19
395
-	 * @param  string $context View or edit context.
396
-	 * @return string
397
-	 */
398
-	public function get_is_dynamic_pricing( $context = 'view' ) {
392
+     * Checks if dynamic pricing is enabled.
393
+     *
394
+     * @since 1.0.19
395
+     * @param  string $context View or edit context.
396
+     * @return string
397
+     */
398
+    public function get_is_dynamic_pricing( $context = 'view' ) {
399 399
         return $this->get_prop( 'is_dynamic_pricing', $context );
400 400
     }
401 401
 
402 402
     /**
403
-	 * Returns the minimum price if dynamic pricing is enabled.
404
-	 *
405
-	 * @since 1.0.19
406
-	 * @param  string $context View or edit context.
407
-	 * @return string
408
-	 */
409
-	public function get_minimum_price( $context = 'view' ) {
403
+     * Returns the minimum price if dynamic pricing is enabled.
404
+     *
405
+     * @since 1.0.19
406
+     * @param  string $context View or edit context.
407
+     * @return string
408
+     */
409
+    public function get_minimum_price( $context = 'view' ) {
410 410
         return $this->get_prop( 'minimum_price', $context );
411 411
     }
412 412
 
413 413
     /**
414
-	 * Checks if this is a recurring item.
415
-	 *
416
-	 * @since 1.0.19
417
-	 * @param  string $context View or edit context.
418
-	 * @return string
419
-	 */
420
-	public function get_is_recurring( $context = 'view' ) {
414
+     * Checks if this is a recurring item.
415
+     *
416
+     * @since 1.0.19
417
+     * @param  string $context View or edit context.
418
+     * @return string
419
+     */
420
+    public function get_is_recurring( $context = 'view' ) {
421 421
         return $this->get_prop( 'is_recurring', $context );
422 422
     }
423 423
 
424 424
     /**
425
-	 * Get the recurring period.
426
-	 *
427
-	 * @since 1.0.19
428
-	 * @param  bool $full Return abbreviation or in full.
429
-	 * @return string
430
-	 */
431
-	public function get_recurring_period( $full = false ) {
425
+     * Get the recurring period.
426
+     *
427
+     * @since 1.0.19
428
+     * @param  bool $full Return abbreviation or in full.
429
+     * @return string
430
+     */
431
+    public function get_recurring_period( $full = false ) {
432 432
         $period = $this->get_prop( 'recurring_period', 'view' );
433 433
 
434 434
         if ( $full && ! is_bool( $full ) ) {
@@ -439,57 +439,57 @@  discard block
 block discarded – undo
439 439
     }
440 440
 
441 441
     /**
442
-	 * Get the recurring interval.
443
-	 *
444
-	 * @since 1.0.19
445
-	 * @param  string $context View or edit context.
446
-	 * @return int
447
-	 */
448
-	public function get_recurring_interval( $context = 'view' ) {
442
+     * Get the recurring interval.
443
+     *
444
+     * @since 1.0.19
445
+     * @param  string $context View or edit context.
446
+     * @return int
447
+     */
448
+    public function get_recurring_interval( $context = 'view' ) {
449 449
         return (int) $this->get_prop( 'recurring_interval', $context );
450 450
     }
451 451
 
452 452
     /**
453
-	 * Get the recurring limit.
454
-	 *
455
-	 * @since 1.0.19
456
-	 * @param  string $context View or edit context.
457
-	 * @return int
458
-	 */
459
-	public function get_recurring_limit( $context = 'view' ) {
453
+     * Get the recurring limit.
454
+     *
455
+     * @since 1.0.19
456
+     * @param  string $context View or edit context.
457
+     * @return int
458
+     */
459
+    public function get_recurring_limit( $context = 'view' ) {
460 460
         return (int) $this->get_prop( 'recurring_limit', $context );
461 461
     }
462 462
 
463 463
     /**
464
-	 * Checks if we have a free trial.
465
-	 *
466
-	 * @since 1.0.19
467
-	 * @param  string $context View or edit context.
468
-	 * @return string
469
-	 */
470
-	public function get_is_free_trial( $context = 'view' ) {
464
+     * Checks if we have a free trial.
465
+     *
466
+     * @since 1.0.19
467
+     * @param  string $context View or edit context.
468
+     * @return string
469
+     */
470
+    public function get_is_free_trial( $context = 'view' ) {
471 471
         return $this->get_prop( 'is_free_trial', $context );
472 472
     }
473 473
 
474 474
     /**
475
-	 * Alias for self::get_is_free_trial().
476
-	 *
477
-	 * @since 1.0.19
478
-	 * @param  string $context View or edit context.
479
-	 * @return string
480
-	 */
481
-	public function get_free_trial( $context = 'view' ) {
475
+     * Alias for self::get_is_free_trial().
476
+     *
477
+     * @since 1.0.19
478
+     * @param  string $context View or edit context.
479
+     * @return string
480
+     */
481
+    public function get_free_trial( $context = 'view' ) {
482 482
         return $this->get_is_free_trial( $context );
483 483
     }
484 484
 
485 485
     /**
486
-	 * Get the trial period.
487
-	 *
488
-	 * @since 1.0.19
489
-	 * @param  bool $full Return abbreviation or in full.
490
-	 * @return string
491
-	 */
492
-	public function get_trial_period( $full = false ) {
486
+     * Get the trial period.
487
+     *
488
+     * @since 1.0.19
489
+     * @param  bool $full Return abbreviation or in full.
490
+     * @return string
491
+     */
492
+    public function get_trial_period( $full = false ) {
493 493
         $period = $this->get_prop( 'trial_period', 'view' );
494 494
 
495 495
         if ( $full && ! is_bool( $full ) ) {
@@ -500,24 +500,24 @@  discard block
 block discarded – undo
500 500
     }
501 501
 
502 502
     /**
503
-	 * Get the trial interval.
504
-	 *
505
-	 * @since 1.0.19
506
-	 * @param  string $context View or edit context.
507
-	 * @return string
508
-	 */
509
-	public function get_trial_interval( $context = 'view' ) {
503
+     * Get the trial interval.
504
+     *
505
+     * @since 1.0.19
506
+     * @param  string $context View or edit context.
507
+     * @return string
508
+     */
509
+    public function get_trial_interval( $context = 'view' ) {
510 510
         return (int) $this->get_prop( 'trial_interval', $context );
511 511
     }
512 512
 
513 513
     /**
514
-	 * Get the sign up fee.
515
-	 *
516
-	 * @since 1.0.19
517
-	 * @param  string $context View or edit context.
518
-	 * @return float
519
-	 */
520
-	public function get_signup_fee( $context = 'view' ) {
514
+     * Get the sign up fee.
515
+     *
516
+     * @since 1.0.19
517
+     * @param  string $context View or edit context.
518
+     * @return float
519
+     */
520
+    public function get_signup_fee( $context = 'view' ) {
521 521
         return $this->get_prop( 'signup_fee', $context );
522 522
     }
523 523
 
@@ -551,168 +551,168 @@  discard block
 block discarded – undo
551 551
     */
552 552
     
553 553
     /**
554
-	 * Set parent order ID.
555
-	 *
556
-	 * @since 1.0.19
557
-	 */
558
-	public function set_parent_id( $value ) {
559
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
560
-			return;
561
-		}
562
-		$this->set_prop( 'parent_id', absint( $value ) );
563
-	}
564
-
565
-    /**
566
-	 * Sets item status.
567
-	 *
568
-	 * @since 1.0.19
569
-	 * @param  string $status New status.
570
-	 * @return array details of change.
571
-	 */
572
-	public function set_status( $status ) {
554
+     * Set parent order ID.
555
+     *
556
+     * @since 1.0.19
557
+     */
558
+    public function set_parent_id( $value ) {
559
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
560
+            return;
561
+        }
562
+        $this->set_prop( 'parent_id', absint( $value ) );
563
+    }
564
+
565
+    /**
566
+     * Sets item status.
567
+     *
568
+     * @since 1.0.19
569
+     * @param  string $status New status.
570
+     * @return array details of change.
571
+     */
572
+    public function set_status( $status ) {
573 573
         $old_status = $this->get_status();
574 574
         
575 575
         $this->set_prop( 'status', $status );
576 576
 
577
-		return array(
578
-			'from' => $old_status,
579
-			'to'   => $status,
580
-		);
577
+        return array(
578
+            'from' => $old_status,
579
+            'to'   => $status,
580
+        );
581 581
     }
582 582
 
583 583
     /**
584
-	 * Set plugin version when the item was created.
585
-	 *
586
-	 * @since 1.0.19
587
-	 * @param string $value Value to set.
588
-	 */
589
-	public function set_version( $value ) {
590
-		return $this->set_prop( 'version', $value );
584
+     * Set plugin version when the item was created.
585
+     *
586
+     * @since 1.0.19
587
+     * @param string $value Value to set.
588
+     */
589
+    public function set_version( $value ) {
590
+        return $this->set_prop( 'version', $value );
591 591
     }
592 592
 
593 593
     /**
594
-	 * Set date when the item was created.
595
-	 *
596
-	 * @since 1.0.19
597
-	 * @param string $value Value to set.
598
-	 */
599
-	public function set_date_created( $value ) {
600
-		return $this->set_prop( 'date_created', $value );
594
+     * Set date when the item was created.
595
+     *
596
+     * @since 1.0.19
597
+     * @param string $value Value to set.
598
+     */
599
+    public function set_date_created( $value ) {
600
+        return $this->set_prop( 'date_created', $value );
601 601
     }
602 602
 
603 603
     /**
604
-	 * Set date when the item was last modified.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param string $value Value to set.
608
-	 */
609
-	public function set_date_modified( $value ) {
610
-		return $this->set_prop( 'date_modified', $value );
604
+     * Set date when the item was last modified.
605
+     *
606
+     * @since 1.0.19
607
+     * @param string $value Value to set.
608
+     */
609
+    public function set_date_modified( $value ) {
610
+        return $this->set_prop( 'date_modified', $value );
611 611
     }
612 612
 
613 613
     /**
614
-	 * Set the item name.
615
-	 *
616
-	 * @since 1.0.19
617
-	 * @param  string $value New name.
618
-	 * @return string
619
-	 */
620
-	public function set_name( $value ) {
621
-		return $this->set_prop( 'name', $value );
614
+     * Set the item name.
615
+     *
616
+     * @since 1.0.19
617
+     * @param  string $value New name.
618
+     * @return string
619
+     */
620
+    public function set_name( $value ) {
621
+        return $this->set_prop( 'name', $value );
622 622
     }
623 623
 
624 624
     /**
625
-	 * Alias of self::set_name().
626
-	 *
627
-	 * @since 1.0.19
628
-	 * @param  string $value New name.
629
-	 * @return string
630
-	 */
631
-	public function set_title( $value ) {
632
-		return $this->set_name( $value );
625
+     * Alias of self::set_name().
626
+     *
627
+     * @since 1.0.19
628
+     * @param  string $value New name.
629
+     * @return string
630
+     */
631
+    public function set_title( $value ) {
632
+        return $this->set_name( $value );
633 633
     }
634 634
 
635 635
     /**
636
-	 * Set the item description.
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param  string $value New description.
640
-	 * @return string
641
-	 */
642
-	public function set_description( $value ) {
643
-		return $this->set_prop( 'description', $value );
636
+     * Set the item description.
637
+     *
638
+     * @since 1.0.19
639
+     * @param  string $value New description.
640
+     * @return string
641
+     */
642
+    public function set_description( $value ) {
643
+        return $this->set_prop( 'description', $value );
644 644
     }
645 645
 
646 646
     /**
647
-	 * Alias of self::set_description().
648
-	 *
649
-	 * @since 1.0.19
650
-	 * @param  string $value New description.
651
-	 * @return string
652
-	 */
653
-	public function set_excerpt( $value ) {
654
-		return $this->set_description( $value );
647
+     * Alias of self::set_description().
648
+     *
649
+     * @since 1.0.19
650
+     * @param  string $value New description.
651
+     * @return string
652
+     */
653
+    public function set_excerpt( $value ) {
654
+        return $this->set_description( $value );
655 655
     }
656 656
 
657 657
     /**
658
-	 * Alias of self::get_description().
659
-	 *
660
-	 * @since 1.0.19
661
-	 * @param  string $value New description.
662
-	 */
663
-	public function set_summary( $value ) {
664
-		return $this->set_description( $value );
658
+     * Alias of self::get_description().
659
+     *
660
+     * @since 1.0.19
661
+     * @param  string $value New description.
662
+     */
663
+    public function set_summary( $value ) {
664
+        return $this->set_description( $value );
665 665
     }
666 666
 
667 667
     /**
668
-	 * Set the owner of the item.
669
-	 *
670
-	 * @since 1.0.19
671
-	 * @param  int $value New author.
672
-	 */
673
-	public function set_author( $value ) {
674
-		$this->set_prop( 'author', (int) $value );
668
+     * Set the owner of the item.
669
+     *
670
+     * @since 1.0.19
671
+     * @param  int $value New author.
672
+     */
673
+    public function set_author( $value ) {
674
+        $this->set_prop( 'author', (int) $value );
675 675
     }
676 676
 
677 677
     /**
678
-	 * Set the price of the item.
679
-	 *
680
-	 * @since 1.0.19
681
-	 * @param  float $value New price.
682
-	 * @return string
683
-	 */
684
-	public function set_price( $value ) {
678
+     * Set the price of the item.
679
+     *
680
+     * @since 1.0.19
681
+     * @param  float $value New price.
682
+     * @return string
683
+     */
684
+    public function set_price( $value ) {
685 685
         $this->set_prop( 'price', wpinv_sanitize_amount( $value ) );
686 686
     }
687 687
 
688 688
     /**
689
-	 * Set the VAT rule of the item.
690
-	 *
691
-	 * @since 1.0.19
692
-	 * @param  string $value new rule.
693
-	 */
694
-	public function set_vat_rule( $value ) {
689
+     * Set the VAT rule of the item.
690
+     *
691
+     * @since 1.0.19
692
+     * @param  string $value new rule.
693
+     */
694
+    public function set_vat_rule( $value ) {
695 695
         $this->set_prop( 'price', $value );
696 696
     }
697 697
 
698 698
     /**
699
-	 * Set the VAT class of the item.
700
-	 *
701
-	 * @since 1.0.19
702
-	 * @param  string $value new class.
703
-	 */
704
-	public function set_vat_class( $value ) {
699
+     * Set the VAT class of the item.
700
+     *
701
+     * @since 1.0.19
702
+     * @param  string $value new class.
703
+     */
704
+    public function set_vat_class( $value ) {
705 705
         $this->set_prop( 'vat_class', $value );
706 706
     }
707 707
 
708 708
     /**
709
-	 * Set the type of the item.
710
-	 *
711
-	 * @since 1.0.19
712
-	 * @param  string $value new item type.
713
-	 * @return string
714
-	 */
715
-	public function set_type( $value ) {
709
+     * Set the type of the item.
710
+     *
711
+     * @since 1.0.19
712
+     * @param  string $value new item type.
713
+     * @return string
714
+     */
715
+    public function set_type( $value ) {
716 716
 
717 717
         if ( empty( $value ) ) {
718 718
             $value = 'custom';
@@ -722,142 +722,142 @@  discard block
 block discarded – undo
722 722
     }
723 723
 
724 724
     /**
725
-	 * Set the custom id of the item.
726
-	 *
727
-	 * @since 1.0.19
728
-	 * @param  string $value new custom id.
729
-	 */
730
-	public function set_custom_id( $value ) {
725
+     * Set the custom id of the item.
726
+     *
727
+     * @since 1.0.19
728
+     * @param  string $value new custom id.
729
+     */
730
+    public function set_custom_id( $value ) {
731 731
         $this->set_prop( 'custom_id', $value );
732 732
     }
733 733
 
734 734
     /**
735
-	 * Set the custom name of the item.
736
-	 *
737
-	 * @since 1.0.19
738
-	 * @param  string $value new custom id.
739
-	 */
740
-	public function set_custom_name( $value ) {
735
+     * Set the custom name of the item.
736
+     *
737
+     * @since 1.0.19
738
+     * @param  string $value new custom id.
739
+     */
740
+    public function set_custom_name( $value ) {
741 741
         $this->set_prop( 'custom_name', $value );
742 742
     }
743 743
 
744 744
     /**
745
-	 * Set the custom singular name of the item.
746
-	 *
747
-	 * @since 1.0.19
748
-	 * @param  string $value new custom id.
749
-	 */
750
-	public function set_custom_singular_name( $value ) {
745
+     * Set the custom singular name of the item.
746
+     *
747
+     * @since 1.0.19
748
+     * @param  string $value new custom id.
749
+     */
750
+    public function set_custom_singular_name( $value ) {
751 751
         $this->set_prop( 'custom_singular_name', $value );
752 752
     }
753 753
 
754 754
     /**
755
-	 * Sets if an item is editable..
756
-	 *
757
-	 * @since 1.0.19
758
-	 * @param  bool $value whether or not the item is editable.
759
-	 */
760
-	public function set_is_editable( $value ) {
755
+     * Sets if an item is editable..
756
+     *
757
+     * @since 1.0.19
758
+     * @param  bool $value whether or not the item is editable.
759
+     */
760
+    public function set_is_editable( $value ) {
761 761
         $this->set_prop( 'is_editable', (int) $value );
762 762
     }
763 763
 
764 764
     /**
765
-	 * Sets if dynamic pricing is enabled.
766
-	 *
767
-	 * @since 1.0.19
768
-	 * @param  bool $value whether or not dynamic pricing is allowed.
769
-	 */
770
-	public function set_is_dynamic_pricing( $value ) {
765
+     * Sets if dynamic pricing is enabled.
766
+     *
767
+     * @since 1.0.19
768
+     * @param  bool $value whether or not dynamic pricing is allowed.
769
+     */
770
+    public function set_is_dynamic_pricing( $value ) {
771 771
         $this->get_prop( 'is_dynamic_pricing', (int) $value );
772 772
     }
773 773
 
774 774
     /**
775
-	 * Sets the minimum price if dynamic pricing is enabled.
776
-	 *
777
-	 * @since 1.0.19
778
-	 * @param  float $value minimum price.
779
-	 */
780
-	public function set_minimum_price( $value ) {
775
+     * Sets the minimum price if dynamic pricing is enabled.
776
+     *
777
+     * @since 1.0.19
778
+     * @param  float $value minimum price.
779
+     */
780
+    public function set_minimum_price( $value ) {
781 781
         $this->set_prop( 'minimum_price',  wpinv_sanitize_amount( $value ) );
782 782
     }
783 783
 
784 784
     /**
785
-	 * Sets if this is a recurring item.
786
-	 *
787
-	 * @since 1.0.19
788
-	 * @param  bool $value whether or not dynamic pricing is allowed.
789
-	 */
790
-	public function set_is_recurring( $value ) {
785
+     * Sets if this is a recurring item.
786
+     *
787
+     * @since 1.0.19
788
+     * @param  bool $value whether or not dynamic pricing is allowed.
789
+     */
790
+    public function set_is_recurring( $value ) {
791 791
         $this->set_prop( 'is_recurring', (int) $value );
792 792
     }
793 793
 
794 794
     /**
795
-	 * Set the recurring period.
796
-	 *
797
-	 * @since 1.0.19
798
-	 * @param  string $value new period.
799
-	 */
800
-	public function set_recurring_period( $value ) {
795
+     * Set the recurring period.
796
+     *
797
+     * @since 1.0.19
798
+     * @param  string $value new period.
799
+     */
800
+    public function set_recurring_period( $value ) {
801 801
         $this->set_prop( 'recurring_period', $value );
802 802
     }
803 803
 
804 804
     /**
805
-	 * Set the recurring interval.
806
-	 *
807
-	 * @since 1.0.19
808
-	 * @param  int $value recurring interval.
809
-	 */
810
-	public function set_recurring_interval( $value ) {
805
+     * Set the recurring interval.
806
+     *
807
+     * @since 1.0.19
808
+     * @param  int $value recurring interval.
809
+     */
810
+    public function set_recurring_interval( $value ) {
811 811
         return $this->set_prop( 'recurring_interval', (int) $value );
812 812
     }
813 813
 
814 814
     /**
815
-	 * Get the recurring limit.
816
-	 * @since 1.0.19
817
-	 * @param  int $value The recurring limit.
818
-	 * @return int
819
-	 */
820
-	public function set_recurring_limit( $value ) {
815
+     * Get the recurring limit.
816
+     * @since 1.0.19
817
+     * @param  int $value The recurring limit.
818
+     * @return int
819
+     */
820
+    public function set_recurring_limit( $value ) {
821 821
         $this->get_prop( 'recurring_limit', (int) $value );
822 822
     }
823 823
 
824 824
     /**
825
-	 * Checks if we have a free trial.
826
-	 *
827
-	 * @since 1.0.19
828
-	 * @param  bool $value whether or not it has a free trial.
829
-	 */
830
-	public function set_is_free_trial( $value ) {
825
+     * Checks if we have a free trial.
826
+     *
827
+     * @since 1.0.19
828
+     * @param  bool $value whether or not it has a free trial.
829
+     */
830
+    public function set_is_free_trial( $value ) {
831 831
         $this->set_prop( 'is_free_trial', (int) $value );
832 832
     }
833 833
 
834 834
     /**
835
-	 * Set the trial period.
836
-	 *
837
-	 * @since 1.0.19
838
-	 * @param  string $value trial period.
839
-	 */
840
-	public function set_trial_period( $value ) {
835
+     * Set the trial period.
836
+     *
837
+     * @since 1.0.19
838
+     * @param  string $value trial period.
839
+     */
840
+    public function set_trial_period( $value ) {
841 841
         $this->set_prop( 'trial_period', $value );
842 842
     }
843 843
 
844 844
     /**
845
-	 * Set the trial interval.
846
-	 *
847
-	 * @since 1.0.19
848
-	 * @param  int $value trial interval.
849
-	 */
850
-	public function Set_trial_interval( $value ) {
845
+     * Set the trial interval.
846
+     *
847
+     * @since 1.0.19
848
+     * @param  int $value trial interval.
849
+     */
850
+    public function Set_trial_interval( $value ) {
851 851
         $this->set_prop( 'trial_interval', $value );
852 852
     }
853 853
 
854 854
     /**
855
-	 * Set the sign up fee.
856
-	 *
857
-	 * @since 1.0.19
858
-	 * @param  float $value The signup fee.
859
-	 */
860
-	public function set_signup_fee( $value ) {
855
+     * Set the sign up fee.
856
+     *
857
+     * @since 1.0.19
858
+     * @param  float $value The signup fee.
859
+     */
860
+    public function set_signup_fee( $value ) {
861 861
         $this->set_prop( 'signup_fee', $value );
862 862
     }
863 863
 
@@ -889,21 +889,21 @@  discard block
 block discarded – undo
889 889
 	*/
890 890
 
891 891
     /**
892
-	 * Checks whether the item is recurring.
893
-	 *
894
-	 * @since 1.0.19
895
-	 * @return bool
896
-	 */
897
-	public function is_recurring() {
892
+     * Checks whether the item is recurring.
893
+     *
894
+     * @since 1.0.19
895
+     * @return bool
896
+     */
897
+    public function is_recurring() {
898 898
         (bool) $this->get_is_recurring();
899 899
     }
900 900
 
901 901
     /**
902
-	 * Checks whether the item has a free trial.
903
-	 *
904
-	 * @since 1.0.19
905
-	 * @return bool
906
-	 */
902
+     * Checks whether the item has a free trial.
903
+     *
904
+     * @since 1.0.19
905
+     * @return bool
906
+     */
907 907
     public function has_free_trial() {
908 908
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
909 909
 
@@ -911,11 +911,11 @@  discard block
 block discarded – undo
911 911
     }
912 912
 
913 913
     /**
914
-	 * Checks whether the item has a sign up fee.
915
-	 *
916
-	 * @since 1.0.19
917
-	 * @return bool
918
-	 */
914
+     * Checks whether the item has a sign up fee.
915
+     *
916
+     * @since 1.0.19
917
+     * @return bool
918
+     */
919 919
     public function has_signup_fee() {
920 920
         $has_signup_fee = $this->is_recurring() && $this->get_signup_fee() > 0 ? true : false;
921 921
 
@@ -923,11 +923,11 @@  discard block
 block discarded – undo
923 923
     }
924 924
 
925 925
     /**
926
-	 * Checks whether the item is free.
927
-	 *
928
-	 * @since 1.0.19
929
-	 * @return bool
930
-	 */
926
+     * Checks whether the item is free.
927
+     *
928
+     * @since 1.0.19
929
+     * @return bool
930
+     */
931 931
     public function is_free() {
932 932
         $price   = (float) $this->get_price();
933 933
         $is_free = $price == 0;
@@ -937,31 +937,31 @@  discard block
 block discarded – undo
937 937
     }
938 938
 
939 939
     /**
940
-	 * Checks the item status against a passed in status.
941
-	 *
942
-	 * @param array|string $status Status to check.
943
-	 * @return bool
944
-	 */
945
-	public function has_status( $status ) {
946
-		return apply_filters( 'getpaid_item_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status, $this, $status );
940
+     * Checks the item status against a passed in status.
941
+     *
942
+     * @param array|string $status Status to check.
943
+     * @return bool
944
+     */
945
+    public function has_status( $status ) {
946
+        return apply_filters( 'getpaid_item_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status, $this, $status );
947 947
     }
948 948
     
949 949
     /**
950
-	 * Checks the item type against a passed in types.
951
-	 *
952
-	 * @param array|string $type Type to check.
953
-	 * @return bool
954
-	 */
955
-	public function is_type( $type ) {
956
-		return apply_filters( 'getpaid_item_is_type', ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type, $this, $type );
957
-	}
958
-
959
-    /**
960
-	 * Checks whether the item is editable.
961
-	 *
962
-	 * @since 1.0.19
963
-	 * @return bool
964
-	 */
950
+     * Checks the item type against a passed in types.
951
+     *
952
+     * @param array|string $type Type to check.
953
+     * @return bool
954
+     */
955
+    public function is_type( $type ) {
956
+        return apply_filters( 'getpaid_item_is_type', ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type, $this, $type );
957
+    }
958
+
959
+    /**
960
+     * Checks whether the item is editable.
961
+     *
962
+     * @since 1.0.19
963
+     * @return bool
964
+     */
965 965
     public function is_editable() {
966 966
         $is_editable = (int) $this->get_is_editable();
967 967
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
@@ -969,11 +969,11 @@  discard block
 block discarded – undo
969 969
 
970 970
 
971 971
     /**
972
-	 * Checks whether the item is purchasable.
973
-	 *
974
-	 * @since 1.0.19
975
-	 * @return bool
976
-	 */
972
+     * Checks whether the item is purchasable.
973
+     *
974
+     * @since 1.0.19
975
+     * @return bool
976
+     */
977 977
     public function can_purchase() {
978 978
         $can_purchase = null != $this->get_id();
979 979
 
@@ -985,11 +985,11 @@  discard block
 block discarded – undo
985 985
     }
986 986
 
987 987
     /**
988
-	 * Checks whether the item supports dynamic pricing.
989
-	 *
990
-	 * @since 1.0.19
991
-	 * @return bool
992
-	 */
988
+     * Checks whether the item supports dynamic pricing.
989
+     *
990
+     * @since 1.0.19
991
+     * @return bool
992
+     */
993 993
     public function supports_dynamic_pricing() {
994 994
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
995 995
     }
Please login to merge, or discard this patch.
Spacing   +168 added lines, -168 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
 
@@ -86,25 +86,25 @@  discard block
 block discarded – undo
86 86
 	 *
87 87
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
88 88
 	 */
89
-	public function __construct( $item = 0 ) {
90
-		parent::__construct( $item );
89
+	public function __construct($item = 0) {
90
+		parent::__construct($item);
91 91
 
92
-		if ( is_numeric( $item ) && $item > 0 ) {
93
-			$this->set_id( $item );
94
-		} elseif ( $item instanceof self ) {
95
-			$this->set_id( $item->get_id() );
96
-		} elseif ( ! empty( $item->ID ) ) {
97
-			$this->set_id( $item->ID );
92
+		if (is_numeric($item) && $item > 0) {
93
+			$this->set_id($item);
94
+		} elseif ($item instanceof self) {
95
+			$this->set_id($item->get_id());
96
+		} elseif (!empty($item->ID)) {
97
+			$this->set_id($item->ID);
98 98
 		} else {
99
-			$this->set_object_read( true );
99
+			$this->set_object_read(true);
100 100
 		}
101 101
 
102 102
         // Load the datastore.
103
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
103
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
104 104
 
105
-		if ( $this->get_id() > 0 ) {
106
-            $this->post = get_post( $this->get_id() );
107
-			$this->data_store->read( $this );
105
+		if ($this->get_id() > 0) {
106
+            $this->post = get_post($this->get_id());
107
+			$this->data_store->read($this);
108 108
 		}
109 109
 	}
110 110
 
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 * @param  string $context View or edit context.
131 131
 	 * @return int
132 132
 	 */
133
-	public function get_parent_id( $context = 'view' ) {
134
-		return (int) $this->get_prop( 'parent_id', $context );
133
+	public function get_parent_id($context = 'view') {
134
+		return (int) $this->get_prop('parent_id', $context);
135 135
     }
136 136
 
137 137
     /**
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 	 * @param  string $context View or edit context.
142 142
 	 * @return string
143 143
 	 */
144
-	public function get_status( $context = 'view' ) {
145
-		return $this->get_prop( 'status', $context );
144
+	public function get_status($context = 'view') {
145
+		return $this->get_prop('status', $context);
146 146
     }
147 147
 
148 148
     /**
@@ -152,8 +152,8 @@  discard block
 block discarded – undo
152 152
 	 * @param  string $context View or edit context.
153 153
 	 * @return string
154 154
 	 */
155
-	public function get_version( $context = 'view' ) {
156
-		return $this->get_prop( 'version', $context );
155
+	public function get_version($context = 'view') {
156
+		return $this->get_prop('version', $context);
157 157
     }
158 158
 
159 159
     /**
@@ -163,8 +163,8 @@  discard block
 block discarded – undo
163 163
 	 * @param  string $context View or edit context.
164 164
 	 * @return string
165 165
 	 */
166
-	public function get_date_created( $context = 'view' ) {
167
-		return $this->get_prop( 'date_created', $context );
166
+	public function get_date_created($context = 'view') {
167
+		return $this->get_prop('date_created', $context);
168 168
     }
169 169
 
170 170
     /**
@@ -174,11 +174,11 @@  discard block
 block discarded – undo
174 174
 	 * @param  string $context View or edit context.
175 175
 	 * @return string
176 176
 	 */
177
-	public function get_date_created_gmt( $context = 'view' ) {
178
-        $date = $this->get_date_created( $context );
177
+	public function get_date_created_gmt($context = 'view') {
178
+        $date = $this->get_date_created($context);
179 179
 
180
-        if ( $date ) {
181
-            $date = get_gmt_from_date( $date );
180
+        if ($date) {
181
+            $date = get_gmt_from_date($date);
182 182
         }
183 183
 		return $date;
184 184
     }
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	 * @param  string $context View or edit context.
191 191
 	 * @return string
192 192
 	 */
193
-	public function get_date_modified( $context = 'view' ) {
194
-		return $this->get_prop( 'date_modified', $context );
193
+	public function get_date_modified($context = 'view') {
194
+		return $this->get_prop('date_modified', $context);
195 195
     }
196 196
 
197 197
     /**
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 	 * @param  string $context View or edit context.
202 202
 	 * @return string
203 203
 	 */
204
-	public function get_date_modified_gmt( $context = 'view' ) {
205
-        $date = $this->get_date_modified( $context );
204
+	public function get_date_modified_gmt($context = 'view') {
205
+        $date = $this->get_date_modified($context);
206 206
 
207
-        if ( $date ) {
208
-            $date = get_gmt_from_date( $date );
207
+        if ($date) {
208
+            $date = get_gmt_from_date($date);
209 209
         }
210 210
 		return $date;
211 211
     }
@@ -217,8 +217,8 @@  discard block
 block discarded – undo
217 217
 	 * @param  string $context View or edit context.
218 218
 	 * @return string
219 219
 	 */
220
-	public function get_name( $context = 'view' ) {
221
-		return $this->get_prop( 'name', $context );
220
+	public function get_name($context = 'view') {
221
+		return $this->get_prop('name', $context);
222 222
     }
223 223
 
224 224
     /**
@@ -228,8 +228,8 @@  discard block
 block discarded – undo
228 228
 	 * @param  string $context View or edit context.
229 229
 	 * @return string
230 230
 	 */
231
-	public function get_title( $context = 'view' ) {
232
-		return $this->get_name( $context );
231
+	public function get_title($context = 'view') {
232
+		return $this->get_name($context);
233 233
     }
234 234
 
235 235
     /**
@@ -239,8 +239,8 @@  discard block
 block discarded – undo
239 239
 	 * @param  string $context View or edit context.
240 240
 	 * @return string
241 241
 	 */
242
-	public function get_description( $context = 'view' ) {
243
-		return $this->get_prop( 'description', $context );
242
+	public function get_description($context = 'view') {
243
+		return $this->get_prop('description', $context);
244 244
     }
245 245
 
246 246
     /**
@@ -250,8 +250,8 @@  discard block
 block discarded – undo
250 250
 	 * @param  string $context View or edit context.
251 251
 	 * @return string
252 252
 	 */
253
-	public function get_excerpt( $context = 'view' ) {
254
-		return $this->get_description( $context );
253
+	public function get_excerpt($context = 'view') {
254
+		return $this->get_description($context);
255 255
     }
256 256
 
257 257
     /**
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
 	 * @param  string $context View or edit context.
262 262
 	 * @return string
263 263
 	 */
264
-	public function get_summary( $context = 'view' ) {
265
-		return $this->get_description( $context );
264
+	public function get_summary($context = 'view') {
265
+		return $this->get_description($context);
266 266
     }
267 267
 
268 268
     /**
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
 	 * @param  string $context View or edit context.
273 273
 	 * @return string
274 274
 	 */
275
-	public function get_author( $context = 'view' ) {
276
-		return (int) $this->get_prop( 'author', $context );
275
+	public function get_author($context = 'view') {
276
+		return (int) $this->get_prop('author', $context);
277 277
     }
278 278
 
279 279
     /**
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 	 * @param  string $context View or edit context.
284 284
 	 * @return string
285 285
 	 */
286
-	public function get_price( $context = 'view' ) {
287
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
286
+	public function get_price($context = 'view') {
287
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
288 288
     }
289 289
 
290 290
     /**
@@ -295,9 +295,9 @@  discard block
 block discarded – undo
295 295
 	 * @return string
296 296
 	 */
297 297
     public function get_the_price() {
298
-        $item_price = wpinv_price( wpinv_format_amount( $this->get_price() ) );
298
+        $item_price = wpinv_price(wpinv_format_amount($this->get_price()));
299 299
 
300
-        return apply_filters( 'wpinv_get_the_item_price', $item_price, $this->ID );
300
+        return apply_filters('wpinv_get_the_item_price', $item_price, $this->ID);
301 301
     }
302 302
 
303 303
     /**
@@ -307,8 +307,8 @@  discard block
 block discarded – undo
307 307
 	 * @param  string $context View or edit context.
308 308
 	 * @return string
309 309
 	 */
310
-	public function get_vat_rule( $context = 'view' ) {
311
-        return $this->get_prop( 'vat_rule', $context );
310
+	public function get_vat_rule($context = 'view') {
311
+        return $this->get_prop('vat_rule', $context);
312 312
     }
313 313
 
314 314
     /**
@@ -318,8 +318,8 @@  discard block
 block discarded – undo
318 318
 	 * @param  string $context View or edit context.
319 319
 	 * @return string
320 320
 	 */
321
-	public function get_vat_class( $context = 'view' ) {
322
-        return $this->get_prop( 'vat_class', $context );
321
+	public function get_vat_class($context = 'view') {
322
+        return $this->get_prop('vat_class', $context);
323 323
     }
324 324
 
325 325
     /**
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
 	 * @param  string $context View or edit context.
330 330
 	 * @return string
331 331
 	 */
332
-	public function get_type( $context = 'view' ) {
333
-        return $this->get_prop( 'type', $context );
332
+	public function get_type($context = 'view') {
333
+        return $this->get_prop('type', $context);
334 334
     }
335 335
 
336 336
     /**
@@ -340,8 +340,8 @@  discard block
 block discarded – undo
340 340
 	 * @param  string $context View or edit context.
341 341
 	 * @return string
342 342
 	 */
343
-	public function get_custom_id( $context = 'view' ) {
344
-        return $this->get_prop( 'custom_id', $context );
343
+	public function get_custom_id($context = 'view') {
344
+        return $this->get_prop('custom_id', $context);
345 345
     }
346 346
 
347 347
     /**
@@ -351,8 +351,8 @@  discard block
 block discarded – undo
351 351
 	 * @param  string $context View or edit context.
352 352
 	 * @return string
353 353
 	 */
354
-	public function get_custom_name( $context = 'view' ) {
355
-        return $this->get_prop( 'custom_name', $context );
354
+	public function get_custom_name($context = 'view') {
355
+        return $this->get_prop('custom_name', $context);
356 356
     }
357 357
 
358 358
     /**
@@ -362,8 +362,8 @@  discard block
 block discarded – undo
362 362
 	 * @param  string $context View or edit context.
363 363
 	 * @return string
364 364
 	 */
365
-	public function get_custom_singular_name( $context = 'view' ) {
366
-        return $this->get_prop( 'custom_singular_name', $context );
365
+	public function get_custom_singular_name($context = 'view') {
366
+        return $this->get_prop('custom_singular_name', $context);
367 367
     }
368 368
 
369 369
     /**
@@ -373,8 +373,8 @@  discard block
 block discarded – undo
373 373
 	 * @param  string $context View or edit context.
374 374
 	 * @return string
375 375
 	 */
376
-	public function get_is_editable( $context = 'view' ) {
377
-        return $this->get_prop( 'is_editable', $context );
376
+	public function get_is_editable($context = 'view') {
377
+        return $this->get_prop('is_editable', $context);
378 378
     }
379 379
 
380 380
     /**
@@ -384,8 +384,8 @@  discard block
 block discarded – undo
384 384
 	 * @param  string $context View or edit context.
385 385
 	 * @return string
386 386
 	 */
387
-	public function get_editable( $context = 'view' ) {
388
-		return $this->get_is_editable( $context );
387
+	public function get_editable($context = 'view') {
388
+		return $this->get_is_editable($context);
389 389
     }
390 390
 
391 391
     /**
@@ -395,8 +395,8 @@  discard block
 block discarded – undo
395 395
 	 * @param  string $context View or edit context.
396 396
 	 * @return string
397 397
 	 */
398
-	public function get_is_dynamic_pricing( $context = 'view' ) {
399
-        return $this->get_prop( 'is_dynamic_pricing', $context );
398
+	public function get_is_dynamic_pricing($context = 'view') {
399
+        return $this->get_prop('is_dynamic_pricing', $context);
400 400
     }
401 401
 
402 402
     /**
@@ -406,8 +406,8 @@  discard block
 block discarded – undo
406 406
 	 * @param  string $context View or edit context.
407 407
 	 * @return string
408 408
 	 */
409
-	public function get_minimum_price( $context = 'view' ) {
410
-        return $this->get_prop( 'minimum_price', $context );
409
+	public function get_minimum_price($context = 'view') {
410
+        return $this->get_prop('minimum_price', $context);
411 411
     }
412 412
 
413 413
     /**
@@ -417,8 +417,8 @@  discard block
 block discarded – undo
417 417
 	 * @param  string $context View or edit context.
418 418
 	 * @return string
419 419
 	 */
420
-	public function get_is_recurring( $context = 'view' ) {
421
-        return $this->get_prop( 'is_recurring', $context );
420
+	public function get_is_recurring($context = 'view') {
421
+        return $this->get_prop('is_recurring', $context);
422 422
     }
423 423
 
424 424
     /**
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
 	 * @param  bool $full Return abbreviation or in full.
429 429
 	 * @return string
430 430
 	 */
431
-	public function get_recurring_period( $full = false ) {
432
-        $period = $this->get_prop( 'recurring_period', 'view' );
431
+	public function get_recurring_period($full = false) {
432
+        $period = $this->get_prop('recurring_period', 'view');
433 433
 
434
-        if ( $full && ! is_bool( $full ) ) {
434
+        if ($full && !is_bool($full)) {
435 435
             $full = false;
436 436
         }
437 437
 
438
-        return getpaid_sanitize_recurring_period( $period, $full );
438
+        return getpaid_sanitize_recurring_period($period, $full);
439 439
     }
440 440
 
441 441
     /**
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
 	 * @param  string $context View or edit context.
446 446
 	 * @return int
447 447
 	 */
448
-	public function get_recurring_interval( $context = 'view' ) {
449
-        return (int) $this->get_prop( 'recurring_interval', $context );
448
+	public function get_recurring_interval($context = 'view') {
449
+        return (int) $this->get_prop('recurring_interval', $context);
450 450
     }
451 451
 
452 452
     /**
@@ -456,8 +456,8 @@  discard block
 block discarded – undo
456 456
 	 * @param  string $context View or edit context.
457 457
 	 * @return int
458 458
 	 */
459
-	public function get_recurring_limit( $context = 'view' ) {
460
-        return (int) $this->get_prop( 'recurring_limit', $context );
459
+	public function get_recurring_limit($context = 'view') {
460
+        return (int) $this->get_prop('recurring_limit', $context);
461 461
     }
462 462
 
463 463
     /**
@@ -467,8 +467,8 @@  discard block
 block discarded – undo
467 467
 	 * @param  string $context View or edit context.
468 468
 	 * @return string
469 469
 	 */
470
-	public function get_is_free_trial( $context = 'view' ) {
471
-        return $this->get_prop( 'is_free_trial', $context );
470
+	public function get_is_free_trial($context = 'view') {
471
+        return $this->get_prop('is_free_trial', $context);
472 472
     }
473 473
 
474 474
     /**
@@ -478,8 +478,8 @@  discard block
 block discarded – undo
478 478
 	 * @param  string $context View or edit context.
479 479
 	 * @return string
480 480
 	 */
481
-	public function get_free_trial( $context = 'view' ) {
482
-        return $this->get_is_free_trial( $context );
481
+	public function get_free_trial($context = 'view') {
482
+        return $this->get_is_free_trial($context);
483 483
     }
484 484
 
485 485
     /**
@@ -489,14 +489,14 @@  discard block
 block discarded – undo
489 489
 	 * @param  bool $full Return abbreviation or in full.
490 490
 	 * @return string
491 491
 	 */
492
-	public function get_trial_period( $full = false ) {
493
-        $period = $this->get_prop( 'trial_period', 'view' );
492
+	public function get_trial_period($full = false) {
493
+        $period = $this->get_prop('trial_period', 'view');
494 494
 
495
-        if ( $full && ! is_bool( $full ) ) {
495
+        if ($full && !is_bool($full)) {
496 496
             $full = false;
497 497
         }
498 498
 
499
-        return getpaid_sanitize_recurring_period( $period, $full );
499
+        return getpaid_sanitize_recurring_period($period, $full);
500 500
     }
501 501
 
502 502
     /**
@@ -506,8 +506,8 @@  discard block
 block discarded – undo
506 506
 	 * @param  string $context View or edit context.
507 507
 	 * @return string
508 508
 	 */
509
-	public function get_trial_interval( $context = 'view' ) {
510
-        return (int) $this->get_prop( 'trial_interval', $context );
509
+	public function get_trial_interval($context = 'view') {
510
+        return (int) $this->get_prop('trial_interval', $context);
511 511
     }
512 512
 
513 513
     /**
@@ -517,26 +517,26 @@  discard block
 block discarded – undo
517 517
 	 * @param  string $context View or edit context.
518 518
 	 * @return float
519 519
 	 */
520
-	public function get_signup_fee( $context = 'view' ) {
521
-        return $this->get_prop( 'signup_fee', $context );
520
+	public function get_signup_fee($context = 'view') {
521
+        return $this->get_prop('signup_fee', $context);
522 522
     }
523 523
 
524 524
     /**
525 525
      * Margic method for retrieving a property.
526 526
      */
527
-    public function __get( $key ) {
527
+    public function __get($key) {
528 528
 
529 529
         // Check if we have a helper method for that.
530
-        if ( method_exists( $this, 'get_' . $key ) ) {
531
-            return call_user_func( array( $this, 'get_' . $key ) );
530
+        if (method_exists($this, 'get_' . $key)) {
531
+            return call_user_func(array($this, 'get_' . $key));
532 532
         }
533 533
         
534 534
         // Check if the key is in the associated $post object.
535
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
535
+        if (!empty($this->post) && isset($this->post->$key)) {
536 536
             return $this->post->$key;
537 537
         }
538 538
 
539
-        return $this->get_prop( $key );
539
+        return $this->get_prop($key);
540 540
 
541 541
     }
542 542
 
@@ -555,11 +555,11 @@  discard block
 block discarded – undo
555 555
 	 *
556 556
 	 * @since 1.0.19
557 557
 	 */
558
-	public function set_parent_id( $value ) {
559
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
558
+	public function set_parent_id($value) {
559
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
560 560
 			return;
561 561
 		}
562
-		$this->set_prop( 'parent_id', absint( $value ) );
562
+		$this->set_prop('parent_id', absint($value));
563 563
 	}
564 564
 
565 565
     /**
@@ -569,10 +569,10 @@  discard block
 block discarded – undo
569 569
 	 * @param  string $status New status.
570 570
 	 * @return array details of change.
571 571
 	 */
572
-	public function set_status( $status ) {
572
+	public function set_status($status) {
573 573
         $old_status = $this->get_status();
574 574
         
575
-        $this->set_prop( 'status', $status );
575
+        $this->set_prop('status', $status);
576 576
 
577 577
 		return array(
578 578
 			'from' => $old_status,
@@ -586,8 +586,8 @@  discard block
 block discarded – undo
586 586
 	 * @since 1.0.19
587 587
 	 * @param string $value Value to set.
588 588
 	 */
589
-	public function set_version( $value ) {
590
-		return $this->set_prop( 'version', $value );
589
+	public function set_version($value) {
590
+		return $this->set_prop('version', $value);
591 591
     }
592 592
 
593 593
     /**
@@ -596,8 +596,8 @@  discard block
 block discarded – undo
596 596
 	 * @since 1.0.19
597 597
 	 * @param string $value Value to set.
598 598
 	 */
599
-	public function set_date_created( $value ) {
600
-		return $this->set_prop( 'date_created', $value );
599
+	public function set_date_created($value) {
600
+		return $this->set_prop('date_created', $value);
601 601
     }
602 602
 
603 603
     /**
@@ -606,8 +606,8 @@  discard block
 block discarded – undo
606 606
 	 * @since 1.0.19
607 607
 	 * @param string $value Value to set.
608 608
 	 */
609
-	public function set_date_modified( $value ) {
610
-		return $this->set_prop( 'date_modified', $value );
609
+	public function set_date_modified($value) {
610
+		return $this->set_prop('date_modified', $value);
611 611
     }
612 612
 
613 613
     /**
@@ -617,8 +617,8 @@  discard block
 block discarded – undo
617 617
 	 * @param  string $value New name.
618 618
 	 * @return string
619 619
 	 */
620
-	public function set_name( $value ) {
621
-		return $this->set_prop( 'name', $value );
620
+	public function set_name($value) {
621
+		return $this->set_prop('name', $value);
622 622
     }
623 623
 
624 624
     /**
@@ -628,8 +628,8 @@  discard block
 block discarded – undo
628 628
 	 * @param  string $value New name.
629 629
 	 * @return string
630 630
 	 */
631
-	public function set_title( $value ) {
632
-		return $this->set_name( $value );
631
+	public function set_title($value) {
632
+		return $this->set_name($value);
633 633
     }
634 634
 
635 635
     /**
@@ -639,8 +639,8 @@  discard block
 block discarded – undo
639 639
 	 * @param  string $value New description.
640 640
 	 * @return string
641 641
 	 */
642
-	public function set_description( $value ) {
643
-		return $this->set_prop( 'description', $value );
642
+	public function set_description($value) {
643
+		return $this->set_prop('description', $value);
644 644
     }
645 645
 
646 646
     /**
@@ -650,8 +650,8 @@  discard block
 block discarded – undo
650 650
 	 * @param  string $value New description.
651 651
 	 * @return string
652 652
 	 */
653
-	public function set_excerpt( $value ) {
654
-		return $this->set_description( $value );
653
+	public function set_excerpt($value) {
654
+		return $this->set_description($value);
655 655
     }
656 656
 
657 657
     /**
@@ -660,8 +660,8 @@  discard block
 block discarded – undo
660 660
 	 * @since 1.0.19
661 661
 	 * @param  string $value New description.
662 662
 	 */
663
-	public function set_summary( $value ) {
664
-		return $this->set_description( $value );
663
+	public function set_summary($value) {
664
+		return $this->set_description($value);
665 665
     }
666 666
 
667 667
     /**
@@ -670,8 +670,8 @@  discard block
 block discarded – undo
670 670
 	 * @since 1.0.19
671 671
 	 * @param  int $value New author.
672 672
 	 */
673
-	public function set_author( $value ) {
674
-		$this->set_prop( 'author', (int) $value );
673
+	public function set_author($value) {
674
+		$this->set_prop('author', (int) $value);
675 675
     }
676 676
 
677 677
     /**
@@ -681,8 +681,8 @@  discard block
 block discarded – undo
681 681
 	 * @param  float $value New price.
682 682
 	 * @return string
683 683
 	 */
684
-	public function set_price( $value ) {
685
-        $this->set_prop( 'price', wpinv_sanitize_amount( $value ) );
684
+	public function set_price($value) {
685
+        $this->set_prop('price', wpinv_sanitize_amount($value));
686 686
     }
687 687
 
688 688
     /**
@@ -691,8 +691,8 @@  discard block
 block discarded – undo
691 691
 	 * @since 1.0.19
692 692
 	 * @param  string $value new rule.
693 693
 	 */
694
-	public function set_vat_rule( $value ) {
695
-        $this->set_prop( 'price', $value );
694
+	public function set_vat_rule($value) {
695
+        $this->set_prop('price', $value);
696 696
     }
697 697
 
698 698
     /**
@@ -701,8 +701,8 @@  discard block
 block discarded – undo
701 701
 	 * @since 1.0.19
702 702
 	 * @param  string $value new class.
703 703
 	 */
704
-	public function set_vat_class( $value ) {
705
-        $this->set_prop( 'vat_class', $value );
704
+	public function set_vat_class($value) {
705
+        $this->set_prop('vat_class', $value);
706 706
     }
707 707
 
708 708
     /**
@@ -712,13 +712,13 @@  discard block
 block discarded – undo
712 712
 	 * @param  string $value new item type.
713 713
 	 * @return string
714 714
 	 */
715
-	public function set_type( $value ) {
715
+	public function set_type($value) {
716 716
 
717
-        if ( empty( $value ) ) {
717
+        if (empty($value)) {
718 718
             $value = 'custom';
719 719
         }
720 720
 
721
-        $this->set_prop( 'type', $value );
721
+        $this->set_prop('type', $value);
722 722
     }
723 723
 
724 724
     /**
@@ -727,8 +727,8 @@  discard block
 block discarded – undo
727 727
 	 * @since 1.0.19
728 728
 	 * @param  string $value new custom id.
729 729
 	 */
730
-	public function set_custom_id( $value ) {
731
-        $this->set_prop( 'custom_id', $value );
730
+	public function set_custom_id($value) {
731
+        $this->set_prop('custom_id', $value);
732 732
     }
733 733
 
734 734
     /**
@@ -737,8 +737,8 @@  discard block
 block discarded – undo
737 737
 	 * @since 1.0.19
738 738
 	 * @param  string $value new custom id.
739 739
 	 */
740
-	public function set_custom_name( $value ) {
741
-        $this->set_prop( 'custom_name', $value );
740
+	public function set_custom_name($value) {
741
+        $this->set_prop('custom_name', $value);
742 742
     }
743 743
 
744 744
     /**
@@ -747,8 +747,8 @@  discard block
 block discarded – undo
747 747
 	 * @since 1.0.19
748 748
 	 * @param  string $value new custom id.
749 749
 	 */
750
-	public function set_custom_singular_name( $value ) {
751
-        $this->set_prop( 'custom_singular_name', $value );
750
+	public function set_custom_singular_name($value) {
751
+        $this->set_prop('custom_singular_name', $value);
752 752
     }
753 753
 
754 754
     /**
@@ -757,8 +757,8 @@  discard block
 block discarded – undo
757 757
 	 * @since 1.0.19
758 758
 	 * @param  bool $value whether or not the item is editable.
759 759
 	 */
760
-	public function set_is_editable( $value ) {
761
-        $this->set_prop( 'is_editable', (int) $value );
760
+	public function set_is_editable($value) {
761
+        $this->set_prop('is_editable', (int) $value);
762 762
     }
763 763
 
764 764
     /**
@@ -767,8 +767,8 @@  discard block
 block discarded – undo
767 767
 	 * @since 1.0.19
768 768
 	 * @param  bool $value whether or not dynamic pricing is allowed.
769 769
 	 */
770
-	public function set_is_dynamic_pricing( $value ) {
771
-        $this->get_prop( 'is_dynamic_pricing', (int) $value );
770
+	public function set_is_dynamic_pricing($value) {
771
+        $this->get_prop('is_dynamic_pricing', (int) $value);
772 772
     }
773 773
 
774 774
     /**
@@ -777,8 +777,8 @@  discard block
 block discarded – undo
777 777
 	 * @since 1.0.19
778 778
 	 * @param  float $value minimum price.
779 779
 	 */
780
-	public function set_minimum_price( $value ) {
781
-        $this->set_prop( 'minimum_price',  wpinv_sanitize_amount( $value ) );
780
+	public function set_minimum_price($value) {
781
+        $this->set_prop('minimum_price', wpinv_sanitize_amount($value));
782 782
     }
783 783
 
784 784
     /**
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
 	 * @since 1.0.19
788 788
 	 * @param  bool $value whether or not dynamic pricing is allowed.
789 789
 	 */
790
-	public function set_is_recurring( $value ) {
791
-        $this->set_prop( 'is_recurring', (int) $value );
790
+	public function set_is_recurring($value) {
791
+        $this->set_prop('is_recurring', (int) $value);
792 792
     }
793 793
 
794 794
     /**
@@ -797,8 +797,8 @@  discard block
 block discarded – undo
797 797
 	 * @since 1.0.19
798 798
 	 * @param  string $value new period.
799 799
 	 */
800
-	public function set_recurring_period( $value ) {
801
-        $this->set_prop( 'recurring_period', $value );
800
+	public function set_recurring_period($value) {
801
+        $this->set_prop('recurring_period', $value);
802 802
     }
803 803
 
804 804
     /**
@@ -807,8 +807,8 @@  discard block
 block discarded – undo
807 807
 	 * @since 1.0.19
808 808
 	 * @param  int $value recurring interval.
809 809
 	 */
810
-	public function set_recurring_interval( $value ) {
811
-        return $this->set_prop( 'recurring_interval', (int) $value );
810
+	public function set_recurring_interval($value) {
811
+        return $this->set_prop('recurring_interval', (int) $value);
812 812
     }
813 813
 
814 814
     /**
@@ -817,8 +817,8 @@  discard block
 block discarded – undo
817 817
 	 * @param  int $value The recurring limit.
818 818
 	 * @return int
819 819
 	 */
820
-	public function set_recurring_limit( $value ) {
821
-        $this->get_prop( 'recurring_limit', (int) $value );
820
+	public function set_recurring_limit($value) {
821
+        $this->get_prop('recurring_limit', (int) $value);
822 822
     }
823 823
 
824 824
     /**
@@ -827,8 +827,8 @@  discard block
 block discarded – undo
827 827
 	 * @since 1.0.19
828 828
 	 * @param  bool $value whether or not it has a free trial.
829 829
 	 */
830
-	public function set_is_free_trial( $value ) {
831
-        $this->set_prop( 'is_free_trial', (int) $value );
830
+	public function set_is_free_trial($value) {
831
+        $this->set_prop('is_free_trial', (int) $value);
832 832
     }
833 833
 
834 834
     /**
@@ -837,8 +837,8 @@  discard block
 block discarded – undo
837 837
 	 * @since 1.0.19
838 838
 	 * @param  string $value trial period.
839 839
 	 */
840
-	public function set_trial_period( $value ) {
841
-        $this->set_prop( 'trial_period', $value );
840
+	public function set_trial_period($value) {
841
+        $this->set_prop('trial_period', $value);
842 842
     }
843 843
 
844 844
     /**
@@ -847,8 +847,8 @@  discard block
 block discarded – undo
847 847
 	 * @since 1.0.19
848 848
 	 * @param  int $value trial interval.
849 849
 	 */
850
-	public function Set_trial_interval( $value ) {
851
-        $this->set_prop( 'trial_interval', $value );
850
+	public function Set_trial_interval($value) {
851
+        $this->set_prop('trial_interval', $value);
852 852
     }
853 853
 
854 854
     /**
@@ -857,8 +857,8 @@  discard block
 block discarded – undo
857 857
 	 * @since 1.0.19
858 858
 	 * @param  float $value The signup fee.
859 859
 	 */
860
-	public function set_signup_fee( $value ) {
861
-        $this->set_prop( 'signup_fee', $value );
860
+	public function set_signup_fee($value) {
861
+        $this->set_prop('signup_fee', $value);
862 862
     }
863 863
 
864 864
     /**
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
      * 
867 867
      * @deprecated
868 868
      */
869
-    public function create( $data = array(), $wp_error = false ) {
869
+    public function create($data = array(), $wp_error = false) {
870 870
         $this->save();
871 871
     }
872 872
 
@@ -875,7 +875,7 @@  discard block
 block discarded – undo
875 875
      * 
876 876
      * @deprecated
877 877
      */
878
-    public function update( $data = array(), $wp_error = false ) {
878
+    public function update($data = array(), $wp_error = false) {
879 879
         $this->save();
880 880
     }
881 881
 
@@ -907,7 +907,7 @@  discard block
 block discarded – undo
907 907
     public function has_free_trial() {
908 908
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
909 909
 
910
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
910
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
911 911
     }
912 912
 
913 913
     /**
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
     public function has_signup_fee() {
920 920
         $has_signup_fee = $this->is_recurring() && $this->get_signup_fee() > 0 ? true : false;
921 921
 
922
-        return (bool) apply_filters( 'wpinv_item_has_signup_fee', $has_signup_fee, $this->ID, $this );
922
+        return (bool) apply_filters('wpinv_item_has_signup_fee', $has_signup_fee, $this->ID, $this);
923 923
     }
924 924
 
925 925
     /**
@@ -932,7 +932,7 @@  discard block
 block discarded – undo
932 932
         $price   = (float) $this->get_price();
933 933
         $is_free = $price == 0;
934 934
 
935
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID );
935
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID);
936 936
 
937 937
     }
938 938
 
@@ -942,8 +942,8 @@  discard block
 block discarded – undo
942 942
 	 * @param array|string $status Status to check.
943 943
 	 * @return bool
944 944
 	 */
945
-	public function has_status( $status ) {
946
-		return apply_filters( 'getpaid_item_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status, $this, $status );
945
+	public function has_status($status) {
946
+		return apply_filters('getpaid_item_has_status', (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status, $this, $status);
947 947
     }
948 948
     
949 949
     /**
@@ -952,8 +952,8 @@  discard block
 block discarded – undo
952 952
 	 * @param array|string $type Type to check.
953 953
 	 * @return bool
954 954
 	 */
955
-	public function is_type( $type ) {
956
-		return apply_filters( 'getpaid_item_is_type', ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type, $this, $type );
955
+	public function is_type($type) {
956
+		return apply_filters('getpaid_item_is_type', (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type, $this, $type);
957 957
 	}
958 958
 
959 959
     /**
@@ -964,7 +964,7 @@  discard block
 block discarded – undo
964 964
 	 */
965 965
     public function is_editable() {
966 966
         $is_editable = (int) $this->get_is_editable();
967
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID );
967
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID);
968 968
     }
969 969
 
970 970
 
@@ -977,11 +977,11 @@  discard block
 block discarded – undo
977 977
     public function can_purchase() {
978 978
         $can_purchase = null != $this->get_id();
979 979
 
980
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
980
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
981 981
             $can_purchase = false;
982 982
         }
983 983
 
984
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
984
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
985 985
     }
986 986
 
987 987
     /**
@@ -991,6 +991,6 @@  discard block
 block discarded – undo
991 991
 	 * @return bool
992 992
 	 */
993 993
     public function supports_dynamic_pricing() {
994
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
994
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
995 995
     }
996 996
 }
Please login to merge, or discard this patch.
includes/wpinv-error-functions.php 2 patches
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
         ) );
14 14
         echo '<div class="' . implode( ' ', $classes ) . '">';
15 15
             // Loop error codes and display errors
16
-           foreach ( $errors as $error_id => $error ) {
16
+            foreach ( $errors as $error_id => $error ) {
17 17
                 echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>';
18
-           }
18
+            }
19 19
         echo '</div>';
20 20
         wpinv_clear_errors();
21 21
     }
@@ -79,13 +79,13 @@  discard block
 block discarded – undo
79 79
  */
80 80
 function getpaid_doing_it_wrong( $function, $message, $version ) {
81 81
 
82
-	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
82
+    $message .= ' Backtrace: ' . wp_debug_backtrace_summary();
83 83
 
84
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
85
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
86
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
87
-	} else {
88
-		_doing_it_wrong( $function, $message, $version );
89
-	}
84
+    if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
85
+        do_action( 'doing_it_wrong_run', $function, $message, $version );
86
+        error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
87
+    } else {
88
+        _doing_it_wrong( $function, $message, $version );
89
+    }
90 90
 
91 91
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,61 +1,61 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_print_errors() {
8 8
     $errors = wpinv_get_errors();
9 9
 
10
-    if ( $errors ) {
11
-        $classes = apply_filters( 'wpinv_error_class', array(
10
+    if ($errors) {
11
+        $classes = apply_filters('wpinv_error_class', array(
12 12
             'wpinv_errors', 'wpinv-alert', 'wpinv-alert-error'
13
-        ) );
14
-        echo '<div class="' . implode( ' ', $classes ) . '">';
13
+        ));
14
+        echo '<div class="' . implode(' ', $classes) . '">';
15 15
             // Loop error codes and display errors
16
-           foreach ( $errors as $error_id => $error ) {
17
-                echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __( 'Error', 'invoicing' ) . '</strong>: ' . $error . '</p>';
16
+           foreach ($errors as $error_id => $error) {
17
+                echo '<p class="wpinv_error" id="wpinv_error_' . $error_id . '"><strong>' . __('Error', 'invoicing') . '</strong>: ' . $error . '</p>';
18 18
            }
19 19
         echo '</div>';
20 20
         wpinv_clear_errors();
21 21
     }
22 22
 }
23
-add_action( 'wpinv_purchase_form_before_submit', 'wpinv_print_errors' );
24
-add_action( 'wpinv_ajax_checkout_errors', 'wpinv_print_errors' );
23
+add_action('wpinv_purchase_form_before_submit', 'wpinv_print_errors');
24
+add_action('wpinv_ajax_checkout_errors', 'wpinv_print_errors');
25 25
 
26 26
 function wpinv_get_errors() {
27 27
     global $wpi_session;
28 28
     
29
-    return $wpi_session->get( 'wpinv_errors' );
29
+    return $wpi_session->get('wpinv_errors');
30 30
 }
31 31
 
32
-function wpinv_set_error( $error_id, $error_message ) {
32
+function wpinv_set_error($error_id, $error_message) {
33 33
     global $wpi_session;
34 34
     
35 35
     $errors = wpinv_get_errors();
36 36
 
37
-    if ( ! $errors ) {
37
+    if (!$errors) {
38 38
         $errors = array();
39 39
     }
40 40
 
41
-    $errors[ $error_id ] = $error_message;
42
-    $wpi_session->set( 'wpinv_errors', $errors );
41
+    $errors[$error_id] = $error_message;
42
+    $wpi_session->set('wpinv_errors', $errors);
43 43
 }
44 44
 
45 45
 function wpinv_clear_errors() {
46 46
     global $wpi_session;
47 47
     
48
-    $wpi_session->set( 'wpinv_errors', null );
48
+    $wpi_session->set('wpinv_errors', null);
49 49
 }
50 50
 
51
-function wpinv_unset_error( $error_id ) {
51
+function wpinv_unset_error($error_id) {
52 52
     global $wpi_session;
53 53
     
54 54
     $errors = wpinv_get_errors();
55 55
 
56
-    if ( $errors ) {
57
-        unset( $errors[ $error_id ] );
58
-        $wpi_session->set( 'wpinv_errors', $errors );
56
+    if ($errors) {
57
+        unset($errors[$error_id]);
58
+        $wpi_session->set('wpinv_errors', $errors);
59 59
     }
60 60
 }
61 61
 
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
     die();
64 64
 }
65 65
 
66
-function wpinv_die( $message = '', $title = '', $status = 400 ) {
67
-    add_filter( 'wp_die_ajax_handler', 'wpinv_die_handler', 10, 3 );
68
-    add_filter( 'wp_die_handler', 'wpinv_die_handler', 10, 3 );
69
-    wp_die( $message, $title, array( 'response' => $status ));
66
+function wpinv_die($message = '', $title = '', $status = 400) {
67
+    add_filter('wp_die_ajax_handler', 'wpinv_die_handler', 10, 3);
68
+    add_filter('wp_die_handler', 'wpinv_die_handler', 10, 3);
69
+    wp_die($message, $title, array('response' => $status));
70 70
 }
71 71
 
72 72
 /**
@@ -77,15 +77,15 @@  discard block
 block discarded – undo
77 77
  * @param string $message Message to log.
78 78
  * @param string $version Version the message was added in.
79 79
  */
80
-function getpaid_doing_it_wrong( $function, $message, $version ) {
80
+function getpaid_doing_it_wrong($function, $message, $version) {
81 81
 
82 82
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
83 83
 
84
-	if ( is_ajax() || defined( 'REST_REQUEST' ) ) {
85
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
86
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
84
+	if (is_ajax() || defined('REST_REQUEST')) {
85
+		do_action('doing_it_wrong_run', $function, $message, $version);
86
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
87 87
 	} else {
88
-		_doing_it_wrong( $function, $message, $version );
88
+		_doing_it_wrong($function, $message, $version);
89 89
 	}
90 90
 
91 91
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-item-data-store-cpt.php 2 patches
Indentation   +300 added lines, -300 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 if ( ! defined( 'ABSPATH' ) ) {
7
-	exit;
7
+    exit;
8 8
 }
9 9
 
10 10
 /**
@@ -14,314 +14,314 @@  discard block
 block discarded – undo
14 14
  */
15 15
 abstract class GetPaid_Item_Data_Store_CPT extends GetPaid_Data_Store_WP {
16 16
 
17
-	/**
18
-	 * Internal meta type used to store order data.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $meta_type = 'post';
23
-
24
-	/**
25
-	 * Data stored in meta keys, but not considered "meta" for an item.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var array
29
-	 */
30
-	protected $internal_meta_keys = array(
31
-		'_wpinv_price',
32
-		'_wpinv_vat_rule',
33
-		'_wpinv_vat_class',
34
-		'_wpinv_type',
35
-		'_wpinv_custom_id',
36
-		'_wpinv_custom_name',
37
-		'_wpinv_custom_singular_name',
38
-		'_wpinv_editable',
39
-		'_wpinv_dynamic_pricing',
40
-		'_minimum_price',
41
-		'_wpinv_is_recurring',
42
-		'_wpinv_recurring_period',
43
-		'_wpinv_recurring_interval',
44
-		'_wpinv_recurring_limit',
45
-		'_wpinv_free_trial',
46
-		'_wpinv_trial_period',
47
-		'_wpinv_signup_fee',
48
-		'_wpinv_trial_interval'
49
-	);
50
-
51
-	/*
17
+    /**
18
+     * Internal meta type used to store order data.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $meta_type = 'post';
23
+
24
+    /**
25
+     * Data stored in meta keys, but not considered "meta" for an item.
26
+     *
27
+     * @since 1.0.19
28
+     * @var array
29
+     */
30
+    protected $internal_meta_keys = array(
31
+        '_wpinv_price',
32
+        '_wpinv_vat_rule',
33
+        '_wpinv_vat_class',
34
+        '_wpinv_type',
35
+        '_wpinv_custom_id',
36
+        '_wpinv_custom_name',
37
+        '_wpinv_custom_singular_name',
38
+        '_wpinv_editable',
39
+        '_wpinv_dynamic_pricing',
40
+        '_minimum_price',
41
+        '_wpinv_is_recurring',
42
+        '_wpinv_recurring_period',
43
+        '_wpinv_recurring_interval',
44
+        '_wpinv_recurring_limit',
45
+        '_wpinv_free_trial',
46
+        '_wpinv_trial_period',
47
+        '_wpinv_signup_fee',
48
+        '_wpinv_trial_interval'
49
+    );
50
+
51
+    /*
52 52
 	|--------------------------------------------------------------------------
53 53
 	| CRUD Methods
54 54
 	|--------------------------------------------------------------------------
55 55
 	*/
56 56
 
57
-	/**
58
-	 * Method to create a new item in the database.
59
-	 *
60
-	 * @param WPInv_Item $item Item object.
61
-	 */
62
-	public function create( &$item ) {
63
-		$item->set_version( WPINV_VERSION );
64
-		$item->set_date_created( current_time('mysql') );
65
-
66
-		$id = wp_insert_post(
67
-			apply_filters(
68
-				'getpaid_new_item_data',
69
-				array(
70
-					'post_date'     => $item->get_date_created( 'edit' ),
71
-					'post_type'     => 'wpi_item',
72
-					'post_status'   => $this->get_post_status( $item ),
73
-					'ping_status'   => 'closed',
74
-					'post_author'   => $item->get_author( 'edit' ),
75
-					'post_title'    => $item->get_title( 'edit' ),
76
-					'post_parent'   => 0,
77
-					'post_excerpt'  => $item->get_description( 'edit' ),
78
-				)
79
-			),
80
-			true
81
-		);
82
-
83
-		if ( $id && ! is_wp_error( $id ) ) {
84
-			$item->set_id( $id );
85
-			$this->update_post_meta( $item );
86
-			$item->save_meta_data();
87
-			$item->apply_changes();
88
-			$this->clear_caches( $item );
89
-		}
90
-	}
91
-
92
-	/**
93
-	 * Method to read an order from the database.
94
-	 *
95
-	 * @param WPInv_Item $item Item object.
96
-	 *
97
-	 * @throws Exception If passed item is invalid.
98
-	 */
99
-	public function read( &$item ) {
100
-		$item->set_defaults();
101
-		$item_object = get_post( $item->get_id() );
102
-
103
-		if ( ! $item->get_id() || ! $item_object || ! $item_object->post_type != 'wpi_item' ) {
104
-			throw new Exception( __( 'Invalid item.', 'invoicing' ) );
105
-		}
106
-
107
-		$item->set_props(
108
-			array(
109
-				'parent_id'     => $item_object->post_parent,
110
-				'date_created'  => 0 < $item_object->post_date_gmt ? $item_object->post_date_gmt : null,
111
-				'date_modified' => 0 < $item_object->post_modified_gmt ? $item_object->post_modified_gmt : null,
112
-				'status'        => $item_object->post_status,
113
-				'name'          => $item_object->post_title,
114
-				'description'   => $item_object->post_excerpt,
115
-				'author'        => $item_object->post_author,
116
-			)
117
-		);
118
-
119
-		$this->read_item_data( $item, $item_object );
120
-		$item->read_meta_data();
121
-		$item->set_object_read( true );
122
-
123
-	}
124
-
125
-	/**
126
-	 * Method to update an item in the database.
127
-	 *
128
-	 * @param WPInv_Item $item Order object.
129
-	 */
130
-	public function update( &$item ) {
131
-		$item->save_meta_data();
132
-		$item->set_version( WPINV_VERSION );
133
-
134
-		if ( null === $item->get_date_created( 'edit' ) ) {
135
-			$item->set_date_created(  current_time('mysql') );
136
-		}
137
-
138
-		$changes = $item->get_changes();
139
-
140
-		// Only update the post when the post data changes.
141
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
142
-			$post_data = array(
143
-				'post_date'         => $item->get_date_created( 'edit' ),
144
-				'post_status'       => $item->get_status( $item ),
145
-				'post_parent'       => $item->get_parent_id(),
146
-				'post_excerpt'      => $item->get_description(),
147
-				'post_modified'     => $item->get_date_modified( 'edit' ),
148
-			);
149
-
150
-			/**
151
-			 * When updating this object, to prevent infinite loops, use $wpdb
152
-			 * to update data, since wp_update_post spawns more calls to the
153
-			 * save_post action.
154
-			 *
155
-			 * This ensures hooks are fired by either WP itself (admin screen save),
156
-			 * or an update purely from CRUD.
157
-			 */
158
-			if ( doing_action( 'save_post' ) ) {
159
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
160
-				clean_post_cache( $item->get_id() );
161
-			} else {
162
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
163
-			}
164
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
165
-		}
166
-		$this->update_post_meta( $item );
167
-		$item->apply_changes();
168
-		$this->clear_caches( $item );
169
-	}
170
-
171
-	/**
172
-	 * Method to delete an item from the database.
173
-	 *
174
-	 * @param WPInv_Item $item Item object.
175
-	 * @param array    $args Array of args to pass to the delete method.
176
-	 *
177
-	 * @return void
178
-	 */
179
-	public function delete( &$item, $args = array() ) {
180
-		$id   = $item->get_id();
181
-		$args = wp_parse_args(
182
-			$args,
183
-			array(
184
-				'force_delete' => false,
185
-			)
186
-		);
187
-
188
-		if ( ! $id ) {
189
-			return;
190
-		}
191
-
192
-		if ( $args['force_delete'] ) {
193
-			wp_delete_post( $id );
194
-			$item->set_id( 0 );
195
-			do_action( 'getpaid_delete_item', $id );
196
-		} else {
197
-			wp_trash_post( $id );
198
-			$item->set_status( 'trash' );
199
-			do_action( 'getpaid_trash_item', $id );
200
-		}
201
-	}
202
-
203
-	/*
57
+    /**
58
+     * Method to create a new item in the database.
59
+     *
60
+     * @param WPInv_Item $item Item object.
61
+     */
62
+    public function create( &$item ) {
63
+        $item->set_version( WPINV_VERSION );
64
+        $item->set_date_created( current_time('mysql') );
65
+
66
+        $id = wp_insert_post(
67
+            apply_filters(
68
+                'getpaid_new_item_data',
69
+                array(
70
+                    'post_date'     => $item->get_date_created( 'edit' ),
71
+                    'post_type'     => 'wpi_item',
72
+                    'post_status'   => $this->get_post_status( $item ),
73
+                    'ping_status'   => 'closed',
74
+                    'post_author'   => $item->get_author( 'edit' ),
75
+                    'post_title'    => $item->get_title( 'edit' ),
76
+                    'post_parent'   => 0,
77
+                    'post_excerpt'  => $item->get_description( 'edit' ),
78
+                )
79
+            ),
80
+            true
81
+        );
82
+
83
+        if ( $id && ! is_wp_error( $id ) ) {
84
+            $item->set_id( $id );
85
+            $this->update_post_meta( $item );
86
+            $item->save_meta_data();
87
+            $item->apply_changes();
88
+            $this->clear_caches( $item );
89
+        }
90
+    }
91
+
92
+    /**
93
+     * Method to read an order from the database.
94
+     *
95
+     * @param WPInv_Item $item Item object.
96
+     *
97
+     * @throws Exception If passed item is invalid.
98
+     */
99
+    public function read( &$item ) {
100
+        $item->set_defaults();
101
+        $item_object = get_post( $item->get_id() );
102
+
103
+        if ( ! $item->get_id() || ! $item_object || ! $item_object->post_type != 'wpi_item' ) {
104
+            throw new Exception( __( 'Invalid item.', 'invoicing' ) );
105
+        }
106
+
107
+        $item->set_props(
108
+            array(
109
+                'parent_id'     => $item_object->post_parent,
110
+                'date_created'  => 0 < $item_object->post_date_gmt ? $item_object->post_date_gmt : null,
111
+                'date_modified' => 0 < $item_object->post_modified_gmt ? $item_object->post_modified_gmt : null,
112
+                'status'        => $item_object->post_status,
113
+                'name'          => $item_object->post_title,
114
+                'description'   => $item_object->post_excerpt,
115
+                'author'        => $item_object->post_author,
116
+            )
117
+        );
118
+
119
+        $this->read_item_data( $item, $item_object );
120
+        $item->read_meta_data();
121
+        $item->set_object_read( true );
122
+
123
+    }
124
+
125
+    /**
126
+     * Method to update an item in the database.
127
+     *
128
+     * @param WPInv_Item $item Order object.
129
+     */
130
+    public function update( &$item ) {
131
+        $item->save_meta_data();
132
+        $item->set_version( WPINV_VERSION );
133
+
134
+        if ( null === $item->get_date_created( 'edit' ) ) {
135
+            $item->set_date_created(  current_time('mysql') );
136
+        }
137
+
138
+        $changes = $item->get_changes();
139
+
140
+        // Only update the post when the post data changes.
141
+        if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
142
+            $post_data = array(
143
+                'post_date'         => $item->get_date_created( 'edit' ),
144
+                'post_status'       => $item->get_status( $item ),
145
+                'post_parent'       => $item->get_parent_id(),
146
+                'post_excerpt'      => $item->get_description(),
147
+                'post_modified'     => $item->get_date_modified( 'edit' ),
148
+            );
149
+
150
+            /**
151
+             * When updating this object, to prevent infinite loops, use $wpdb
152
+             * to update data, since wp_update_post spawns more calls to the
153
+             * save_post action.
154
+             *
155
+             * This ensures hooks are fired by either WP itself (admin screen save),
156
+             * or an update purely from CRUD.
157
+             */
158
+            if ( doing_action( 'save_post' ) ) {
159
+                $GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
160
+                clean_post_cache( $item->get_id() );
161
+            } else {
162
+                wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
163
+            }
164
+            $item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
165
+        }
166
+        $this->update_post_meta( $item );
167
+        $item->apply_changes();
168
+        $this->clear_caches( $item );
169
+    }
170
+
171
+    /**
172
+     * Method to delete an item from the database.
173
+     *
174
+     * @param WPInv_Item $item Item object.
175
+     * @param array    $args Array of args to pass to the delete method.
176
+     *
177
+     * @return void
178
+     */
179
+    public function delete( &$item, $args = array() ) {
180
+        $id   = $item->get_id();
181
+        $args = wp_parse_args(
182
+            $args,
183
+            array(
184
+                'force_delete' => false,
185
+            )
186
+        );
187
+
188
+        if ( ! $id ) {
189
+            return;
190
+        }
191
+
192
+        if ( $args['force_delete'] ) {
193
+            wp_delete_post( $id );
194
+            $item->set_id( 0 );
195
+            do_action( 'getpaid_delete_item', $id );
196
+        } else {
197
+            wp_trash_post( $id );
198
+            $item->set_status( 'trash' );
199
+            do_action( 'getpaid_trash_item', $id );
200
+        }
201
+    }
202
+
203
+    /*
204 204
 	|--------------------------------------------------------------------------
205 205
 	| Additional Methods
206 206
 	|--------------------------------------------------------------------------
207 207
 	*/
208 208
 
209
-	/**
210
-	 * Get the status to save to the post object.
211
-	 *
212
-	 *
213
-	 * @since 1.0.19
214
-	 * @param  WPInv_item $item Item object.
215
-	 * @return string
216
-	 */
217
-	protected function get_post_status( $item ) {
218
-		$item_status = $item->get_status( 'edit' );
219
-
220
-		if ( ! $item_status ) {
221
-			$item_status = apply_filters( 'getpaid_default_item_status', 'draft' );
222
-		}
223
-
224
-		return $item_status;
225
-	}
226
-
227
-	/**
228
-	 * Read item data.
229
-	 *
230
-	 * @param WPInv_Item $item Item object.
231
-	 * @param object   $post_object Post object.
232
-	 * @since 1.0.19
233
-	 */
234
-	protected function read_order_data( &$item, $post_object ) {
235
-		$id = $item->get_id();
236
-
237
-		// Set item properties.
238
-		$item->set_props(
239
-			array(
240
-				'price'                => get_post_meta( $id, '_wpinv_price', true ),
241
-				'vat_rule'             => get_post_meta( $id, '_wpinv_vat_rule', true ),
242
-				'vat_class'            => get_post_meta( $id, '_wpinv_vat_class', true ),
243
-				'type'                 => get_post_meta( $id, '_wpinv_type', true ),
244
-				'custom_id'            => get_post_meta( $id, '_wpinv_custom_id', true ),
245
-				'custom_name'          => get_post_meta( $id, '_wpinv_custom_name', true ),
246
-				'custom_singular_name' => get_post_meta( $id, '_wpinv_custom_singular_name', true ),
247
-				'is_editable'          => get_post_meta( $id, '_wpinv_editable', true ),
248
-				'is_dynamic_pricing'   => get_post_meta( $id, '_wpinv_dynamic_pricing', true ),
249
-				'minimum_price'        => get_post_meta( $id, '_minimum_price', true ),
250
-				'is_recurring'         => get_post_meta( $id, '_wpinv_is_recurring', true ),
251
-				'recurring_period'     => get_post_meta( $id, '_wpinv_recurring_period', true ),
252
-				'recurring_interval'   => get_post_meta( $id, '_wpinv_recurring_interval', true ),
253
-				'recurring_limit'      => get_post_meta( $id, '_wpinv_recurring_limit', true ),
254
-				'is_free_trial'        => get_post_meta( $id, '_wpinv_free_trial', true ),
255
-				'trial_period'         => get_post_meta( $id, '_wpinv_trial_period', true ),
256
-				'signup_fee'           => get_post_meta( $id, '_wpinv_signup_fee', true ),
257
-				'trial_interval'       => get_post_meta( $id, '_wpinv_trial_interval', true ),
258
-			)
259
-		);
260
-
261
-		// Gets extra data associated with the item if needed.
262
-		foreach ( $item->get_extra_data_keys() as $key ) {
263
-			$function = 'set_' . $key;
264
-			if ( is_callable( array( $item, $function ) ) ) {
265
-				$item->{$function}( get_post_meta( $item->get_id(), '_' . $key, true ) );
266
-			}
267
-		}
268
-	}
269
-
270
-	/**
271
-	 * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
272
-	 *
273
-	 * @param WPInv_Item $item Item object.
274
-	 * @since 1.0.19
275
-	 */
276
-	protected function update_post_meta( &$item ) {
277
-		$updated_props     = array();
278
-
279
-		$meta_key_to_props = array(
280
-			'_wpinv_price'                => 'price',
281
-			'_wpinv_vat_rule'             => 'vat_rule',
282
-			'_wpinv_vat_class'            => 'vat_class',
283
-			'_wpinv_type'                 => 'type',
284
-			'_wpinv_custom_id'            => 'custom_id',
285
-			'_wpinv_custom_name'          => 'custom_name',
286
-			'_wpinv_custom_singular_name' => 'custom_singular_name',
287
-			'_wpinv_editable'             => 'is_editable',
288
-			'_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
289
-			'_minimum_price'              => 'minimum_price',
290
-			'_wpinv_custom_name'          => 'custom_name',
291
-			'_wpinv_is_recurring'         => 'is_recurring',
292
-			'_wpinv_recurring_period'     => 'recurring_period',
293
-			'_wpinv_recurring_interval'   => 'recurring_interval',
294
-			'_wpinv_recurring_limit'      => 'recurring_limit',
295
-			'_wpinv_free_trial'           => 'is_free_trial',
296
-			'_wpinv_trial_period'         => 'trial_period',
297
-			'_wpinv_signup_fee'           => 'signup_fee',
298
-			'_wpinv_trial_interval'       => 'trial_interval',
299
-		);
300
-
301
-		$props_to_update = $this->get_props_to_update( $item, $meta_key_to_props );
302
-
303
-		foreach ( $props_to_update as $meta_key => $prop ) {
304
-			$value = $item->{"get_$prop"}( 'edit' );
305
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
306
-
307
-			$updated = $this->update_or_delete_post_meta( $item, $meta_key, $value );
308
-
309
-			if ( $updated ) {
310
-				$updated_props[] = $prop;
311
-			}
312
-		}
313
-
314
-		do_action( 'getpaid_item_object_updated_props', $item, $updated_props );
315
-	}
316
-
317
-	/**
318
-	 * Clear any caches.
319
-	 *
320
-	 * @param WPInv_Item $item Item object.
321
-	 * @since 1.0.19
322
-	 */
323
-	protected function clear_caches( &$item ) {
324
-		clean_post_cache( $item->get_id() );
325
-	}
209
+    /**
210
+     * Get the status to save to the post object.
211
+     *
212
+     *
213
+     * @since 1.0.19
214
+     * @param  WPInv_item $item Item object.
215
+     * @return string
216
+     */
217
+    protected function get_post_status( $item ) {
218
+        $item_status = $item->get_status( 'edit' );
219
+
220
+        if ( ! $item_status ) {
221
+            $item_status = apply_filters( 'getpaid_default_item_status', 'draft' );
222
+        }
223
+
224
+        return $item_status;
225
+    }
226
+
227
+    /**
228
+     * Read item data.
229
+     *
230
+     * @param WPInv_Item $item Item object.
231
+     * @param object   $post_object Post object.
232
+     * @since 1.0.19
233
+     */
234
+    protected function read_order_data( &$item, $post_object ) {
235
+        $id = $item->get_id();
236
+
237
+        // Set item properties.
238
+        $item->set_props(
239
+            array(
240
+                'price'                => get_post_meta( $id, '_wpinv_price', true ),
241
+                'vat_rule'             => get_post_meta( $id, '_wpinv_vat_rule', true ),
242
+                'vat_class'            => get_post_meta( $id, '_wpinv_vat_class', true ),
243
+                'type'                 => get_post_meta( $id, '_wpinv_type', true ),
244
+                'custom_id'            => get_post_meta( $id, '_wpinv_custom_id', true ),
245
+                'custom_name'          => get_post_meta( $id, '_wpinv_custom_name', true ),
246
+                'custom_singular_name' => get_post_meta( $id, '_wpinv_custom_singular_name', true ),
247
+                'is_editable'          => get_post_meta( $id, '_wpinv_editable', true ),
248
+                'is_dynamic_pricing'   => get_post_meta( $id, '_wpinv_dynamic_pricing', true ),
249
+                'minimum_price'        => get_post_meta( $id, '_minimum_price', true ),
250
+                'is_recurring'         => get_post_meta( $id, '_wpinv_is_recurring', true ),
251
+                'recurring_period'     => get_post_meta( $id, '_wpinv_recurring_period', true ),
252
+                'recurring_interval'   => get_post_meta( $id, '_wpinv_recurring_interval', true ),
253
+                'recurring_limit'      => get_post_meta( $id, '_wpinv_recurring_limit', true ),
254
+                'is_free_trial'        => get_post_meta( $id, '_wpinv_free_trial', true ),
255
+                'trial_period'         => get_post_meta( $id, '_wpinv_trial_period', true ),
256
+                'signup_fee'           => get_post_meta( $id, '_wpinv_signup_fee', true ),
257
+                'trial_interval'       => get_post_meta( $id, '_wpinv_trial_interval', true ),
258
+            )
259
+        );
260
+
261
+        // Gets extra data associated with the item if needed.
262
+        foreach ( $item->get_extra_data_keys() as $key ) {
263
+            $function = 'set_' . $key;
264
+            if ( is_callable( array( $item, $function ) ) ) {
265
+                $item->{$function}( get_post_meta( $item->get_id(), '_' . $key, true ) );
266
+            }
267
+        }
268
+    }
269
+
270
+    /**
271
+     * Helper method that updates all the post meta for an item based on it's settings in the WPInv_Item class.
272
+     *
273
+     * @param WPInv_Item $item Item object.
274
+     * @since 1.0.19
275
+     */
276
+    protected function update_post_meta( &$item ) {
277
+        $updated_props     = array();
278
+
279
+        $meta_key_to_props = array(
280
+            '_wpinv_price'                => 'price',
281
+            '_wpinv_vat_rule'             => 'vat_rule',
282
+            '_wpinv_vat_class'            => 'vat_class',
283
+            '_wpinv_type'                 => 'type',
284
+            '_wpinv_custom_id'            => 'custom_id',
285
+            '_wpinv_custom_name'          => 'custom_name',
286
+            '_wpinv_custom_singular_name' => 'custom_singular_name',
287
+            '_wpinv_editable'             => 'is_editable',
288
+            '_wpinv_dynamic_pricing'      => 'is_dynamic_pricing',
289
+            '_minimum_price'              => 'minimum_price',
290
+            '_wpinv_custom_name'          => 'custom_name',
291
+            '_wpinv_is_recurring'         => 'is_recurring',
292
+            '_wpinv_recurring_period'     => 'recurring_period',
293
+            '_wpinv_recurring_interval'   => 'recurring_interval',
294
+            '_wpinv_recurring_limit'      => 'recurring_limit',
295
+            '_wpinv_free_trial'           => 'is_free_trial',
296
+            '_wpinv_trial_period'         => 'trial_period',
297
+            '_wpinv_signup_fee'           => 'signup_fee',
298
+            '_wpinv_trial_interval'       => 'trial_interval',
299
+        );
300
+
301
+        $props_to_update = $this->get_props_to_update( $item, $meta_key_to_props );
302
+
303
+        foreach ( $props_to_update as $meta_key => $prop ) {
304
+            $value = $item->{"get_$prop"}( 'edit' );
305
+            $value = is_string( $value ) ? wp_slash( $value ) : $value;
306
+
307
+            $updated = $this->update_or_delete_post_meta( $item, $meta_key, $value );
308
+
309
+            if ( $updated ) {
310
+                $updated_props[] = $prop;
311
+            }
312
+        }
313
+
314
+        do_action( 'getpaid_item_object_updated_props', $item, $updated_props );
315
+    }
316
+
317
+    /**
318
+     * Clear any caches.
319
+     *
320
+     * @param WPInv_Item $item Item object.
321
+     * @since 1.0.19
322
+     */
323
+    protected function clear_caches( &$item ) {
324
+        clean_post_cache( $item->get_id() );
325
+    }
326 326
 
327 327
 }
Please login to merge, or discard this patch.
Spacing   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * GetPaid_Order_Data_Store_CPT class file.
4 4
  *
5 5
  */
6
-if ( ! defined( 'ABSPATH' ) ) {
6
+if (!defined('ABSPATH')) {
7 7
 	exit;
8 8
 }
9 9
 
@@ -59,33 +59,33 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @param WPInv_Item $item Item object.
61 61
 	 */
62
-	public function create( &$item ) {
63
-		$item->set_version( WPINV_VERSION );
64
-		$item->set_date_created( current_time('mysql') );
62
+	public function create(&$item) {
63
+		$item->set_version(WPINV_VERSION);
64
+		$item->set_date_created(current_time('mysql'));
65 65
 
66 66
 		$id = wp_insert_post(
67 67
 			apply_filters(
68 68
 				'getpaid_new_item_data',
69 69
 				array(
70
-					'post_date'     => $item->get_date_created( 'edit' ),
70
+					'post_date'     => $item->get_date_created('edit'),
71 71
 					'post_type'     => 'wpi_item',
72
-					'post_status'   => $this->get_post_status( $item ),
72
+					'post_status'   => $this->get_post_status($item),
73 73
 					'ping_status'   => 'closed',
74
-					'post_author'   => $item->get_author( 'edit' ),
75
-					'post_title'    => $item->get_title( 'edit' ),
74
+					'post_author'   => $item->get_author('edit'),
75
+					'post_title'    => $item->get_title('edit'),
76 76
 					'post_parent'   => 0,
77
-					'post_excerpt'  => $item->get_description( 'edit' ),
77
+					'post_excerpt'  => $item->get_description('edit'),
78 78
 				)
79 79
 			),
80 80
 			true
81 81
 		);
82 82
 
83
-		if ( $id && ! is_wp_error( $id ) ) {
84
-			$item->set_id( $id );
85
-			$this->update_post_meta( $item );
83
+		if ($id && !is_wp_error($id)) {
84
+			$item->set_id($id);
85
+			$this->update_post_meta($item);
86 86
 			$item->save_meta_data();
87 87
 			$item->apply_changes();
88
-			$this->clear_caches( $item );
88
+			$this->clear_caches($item);
89 89
 		}
90 90
 	}
91 91
 
@@ -96,12 +96,12 @@  discard block
 block discarded – undo
96 96
 	 *
97 97
 	 * @throws Exception If passed item is invalid.
98 98
 	 */
99
-	public function read( &$item ) {
99
+	public function read(&$item) {
100 100
 		$item->set_defaults();
101
-		$item_object = get_post( $item->get_id() );
101
+		$item_object = get_post($item->get_id());
102 102
 
103
-		if ( ! $item->get_id() || ! $item_object || ! $item_object->post_type != 'wpi_item' ) {
104
-			throw new Exception( __( 'Invalid item.', 'invoicing' ) );
103
+		if (!$item->get_id() || !$item_object || !$item_object->post_type != 'wpi_item') {
104
+			throw new Exception(__('Invalid item.', 'invoicing'));
105 105
 		}
106 106
 
107 107
 		$item->set_props(
@@ -116,9 +116,9 @@  discard block
 block discarded – undo
116 116
 			)
117 117
 		);
118 118
 
119
-		$this->read_item_data( $item, $item_object );
119
+		$this->read_item_data($item, $item_object);
120 120
 		$item->read_meta_data();
121
-		$item->set_object_read( true );
121
+		$item->set_object_read(true);
122 122
 
123 123
 	}
124 124
 
@@ -127,24 +127,24 @@  discard block
 block discarded – undo
127 127
 	 *
128 128
 	 * @param WPInv_Item $item Order object.
129 129
 	 */
130
-	public function update( &$item ) {
130
+	public function update(&$item) {
131 131
 		$item->save_meta_data();
132
-		$item->set_version( WPINV_VERSION );
132
+		$item->set_version(WPINV_VERSION);
133 133
 
134
-		if ( null === $item->get_date_created( 'edit' ) ) {
135
-			$item->set_date_created(  current_time('mysql') );
134
+		if (null === $item->get_date_created('edit')) {
135
+			$item->set_date_created(current_time('mysql'));
136 136
 		}
137 137
 
138 138
 		$changes = $item->get_changes();
139 139
 
140 140
 		// Only update the post when the post data changes.
141
-		if ( array_intersect( array( 'date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt' ), array_keys( $changes ) ) ) {
141
+		if (array_intersect(array('date_created', 'date_modified', 'status', 'parent_id', 'post_excerpt'), array_keys($changes))) {
142 142
 			$post_data = array(
143
-				'post_date'         => $item->get_date_created( 'edit' ),
144
-				'post_status'       => $item->get_status( $item ),
143
+				'post_date'         => $item->get_date_created('edit'),
144
+				'post_status'       => $item->get_status($item),
145 145
 				'post_parent'       => $item->get_parent_id(),
146 146
 				'post_excerpt'      => $item->get_description(),
147
-				'post_modified'     => $item->get_date_modified( 'edit' ),
147
+				'post_modified'     => $item->get_date_modified('edit'),
148 148
 			);
149 149
 
150 150
 			/**
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
 			 * This ensures hooks are fired by either WP itself (admin screen save),
156 156
 			 * or an update purely from CRUD.
157 157
 			 */
158
-			if ( doing_action( 'save_post' ) ) {
159
-				$GLOBALS['wpdb']->update( $GLOBALS['wpdb']->posts, $post_data, array( 'ID' => $item->get_id() ) );
160
-				clean_post_cache( $item->get_id() );
158
+			if (doing_action('save_post')) {
159
+				$GLOBALS['wpdb']->update($GLOBALS['wpdb']->posts, $post_data, array('ID' => $item->get_id()));
160
+				clean_post_cache($item->get_id());
161 161
 			} else {
162
-				wp_update_post( array_merge( array( 'ID' => $item->get_id() ), $post_data ) );
162
+				wp_update_post(array_merge(array('ID' => $item->get_id()), $post_data));
163 163
 			}
164
-			$item->read_meta_data( true ); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
164
+			$item->read_meta_data(true); // Refresh internal meta data, in case things were hooked into `save_post` or another WP hook.
165 165
 		}
166
-		$this->update_post_meta( $item );
166
+		$this->update_post_meta($item);
167 167
 		$item->apply_changes();
168
-		$this->clear_caches( $item );
168
+		$this->clear_caches($item);
169 169
 	}
170 170
 
171 171
 	/**
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 *
177 177
 	 * @return void
178 178
 	 */
179
-	public function delete( &$item, $args = array() ) {
179
+	public function delete(&$item, $args = array()) {
180 180
 		$id   = $item->get_id();
181 181
 		$args = wp_parse_args(
182 182
 			$args,
@@ -185,18 +185,18 @@  discard block
 block discarded – undo
185 185
 			)
186 186
 		);
187 187
 
188
-		if ( ! $id ) {
188
+		if (!$id) {
189 189
 			return;
190 190
 		}
191 191
 
192
-		if ( $args['force_delete'] ) {
193
-			wp_delete_post( $id );
194
-			$item->set_id( 0 );
195
-			do_action( 'getpaid_delete_item', $id );
192
+		if ($args['force_delete']) {
193
+			wp_delete_post($id);
194
+			$item->set_id(0);
195
+			do_action('getpaid_delete_item', $id);
196 196
 		} else {
197
-			wp_trash_post( $id );
198
-			$item->set_status( 'trash' );
199
-			do_action( 'getpaid_trash_item', $id );
197
+			wp_trash_post($id);
198
+			$item->set_status('trash');
199
+			do_action('getpaid_trash_item', $id);
200 200
 		}
201 201
 	}
202 202
 
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
 	 * @param  WPInv_item $item Item object.
215 215
 	 * @return string
216 216
 	 */
217
-	protected function get_post_status( $item ) {
218
-		$item_status = $item->get_status( 'edit' );
217
+	protected function get_post_status($item) {
218
+		$item_status = $item->get_status('edit');
219 219
 
220
-		if ( ! $item_status ) {
221
-			$item_status = apply_filters( 'getpaid_default_item_status', 'draft' );
220
+		if (!$item_status) {
221
+			$item_status = apply_filters('getpaid_default_item_status', 'draft');
222 222
 		}
223 223
 
224 224
 		return $item_status;
@@ -231,38 +231,38 @@  discard block
 block discarded – undo
231 231
 	 * @param object   $post_object Post object.
232 232
 	 * @since 1.0.19
233 233
 	 */
234
-	protected function read_order_data( &$item, $post_object ) {
234
+	protected function read_order_data(&$item, $post_object) {
235 235
 		$id = $item->get_id();
236 236
 
237 237
 		// Set item properties.
238 238
 		$item->set_props(
239 239
 			array(
240
-				'price'                => get_post_meta( $id, '_wpinv_price', true ),
241
-				'vat_rule'             => get_post_meta( $id, '_wpinv_vat_rule', true ),
242
-				'vat_class'            => get_post_meta( $id, '_wpinv_vat_class', true ),
243
-				'type'                 => get_post_meta( $id, '_wpinv_type', true ),
244
-				'custom_id'            => get_post_meta( $id, '_wpinv_custom_id', true ),
245
-				'custom_name'          => get_post_meta( $id, '_wpinv_custom_name', true ),
246
-				'custom_singular_name' => get_post_meta( $id, '_wpinv_custom_singular_name', true ),
247
-				'is_editable'          => get_post_meta( $id, '_wpinv_editable', true ),
248
-				'is_dynamic_pricing'   => get_post_meta( $id, '_wpinv_dynamic_pricing', true ),
249
-				'minimum_price'        => get_post_meta( $id, '_minimum_price', true ),
250
-				'is_recurring'         => get_post_meta( $id, '_wpinv_is_recurring', true ),
251
-				'recurring_period'     => get_post_meta( $id, '_wpinv_recurring_period', true ),
252
-				'recurring_interval'   => get_post_meta( $id, '_wpinv_recurring_interval', true ),
253
-				'recurring_limit'      => get_post_meta( $id, '_wpinv_recurring_limit', true ),
254
-				'is_free_trial'        => get_post_meta( $id, '_wpinv_free_trial', true ),
255
-				'trial_period'         => get_post_meta( $id, '_wpinv_trial_period', true ),
256
-				'signup_fee'           => get_post_meta( $id, '_wpinv_signup_fee', true ),
257
-				'trial_interval'       => get_post_meta( $id, '_wpinv_trial_interval', true ),
240
+				'price'                => get_post_meta($id, '_wpinv_price', true),
241
+				'vat_rule'             => get_post_meta($id, '_wpinv_vat_rule', true),
242
+				'vat_class'            => get_post_meta($id, '_wpinv_vat_class', true),
243
+				'type'                 => get_post_meta($id, '_wpinv_type', true),
244
+				'custom_id'            => get_post_meta($id, '_wpinv_custom_id', true),
245
+				'custom_name'          => get_post_meta($id, '_wpinv_custom_name', true),
246
+				'custom_singular_name' => get_post_meta($id, '_wpinv_custom_singular_name', true),
247
+				'is_editable'          => get_post_meta($id, '_wpinv_editable', true),
248
+				'is_dynamic_pricing'   => get_post_meta($id, '_wpinv_dynamic_pricing', true),
249
+				'minimum_price'        => get_post_meta($id, '_minimum_price', true),
250
+				'is_recurring'         => get_post_meta($id, '_wpinv_is_recurring', true),
251
+				'recurring_period'     => get_post_meta($id, '_wpinv_recurring_period', true),
252
+				'recurring_interval'   => get_post_meta($id, '_wpinv_recurring_interval', true),
253
+				'recurring_limit'      => get_post_meta($id, '_wpinv_recurring_limit', true),
254
+				'is_free_trial'        => get_post_meta($id, '_wpinv_free_trial', true),
255
+				'trial_period'         => get_post_meta($id, '_wpinv_trial_period', true),
256
+				'signup_fee'           => get_post_meta($id, '_wpinv_signup_fee', true),
257
+				'trial_interval'       => get_post_meta($id, '_wpinv_trial_interval', true),
258 258
 			)
259 259
 		);
260 260
 
261 261
 		// Gets extra data associated with the item if needed.
262
-		foreach ( $item->get_extra_data_keys() as $key ) {
262
+		foreach ($item->get_extra_data_keys() as $key) {
263 263
 			$function = 'set_' . $key;
264
-			if ( is_callable( array( $item, $function ) ) ) {
265
-				$item->{$function}( get_post_meta( $item->get_id(), '_' . $key, true ) );
264
+			if (is_callable(array($item, $function))) {
265
+				$item->{$function}(get_post_meta($item->get_id(), '_' . $key, true));
266 266
 			}
267 267
 		}
268 268
 	}
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 * @param WPInv_Item $item Item object.
274 274
 	 * @since 1.0.19
275 275
 	 */
276
-	protected function update_post_meta( &$item ) {
276
+	protected function update_post_meta(&$item) {
277 277
 		$updated_props     = array();
278 278
 
279 279
 		$meta_key_to_props = array(
@@ -298,20 +298,20 @@  discard block
 block discarded – undo
298 298
 			'_wpinv_trial_interval'       => 'trial_interval',
299 299
 		);
300 300
 
301
-		$props_to_update = $this->get_props_to_update( $item, $meta_key_to_props );
301
+		$props_to_update = $this->get_props_to_update($item, $meta_key_to_props);
302 302
 
303
-		foreach ( $props_to_update as $meta_key => $prop ) {
304
-			$value = $item->{"get_$prop"}( 'edit' );
305
-			$value = is_string( $value ) ? wp_slash( $value ) : $value;
303
+		foreach ($props_to_update as $meta_key => $prop) {
304
+			$value = $item->{"get_$prop"}('edit');
305
+			$value = is_string($value) ? wp_slash($value) : $value;
306 306
 
307
-			$updated = $this->update_or_delete_post_meta( $item, $meta_key, $value );
307
+			$updated = $this->update_or_delete_post_meta($item, $meta_key, $value);
308 308
 
309
-			if ( $updated ) {
309
+			if ($updated) {
310 310
 				$updated_props[] = $prop;
311 311
 			}
312 312
 		}
313 313
 
314
-		do_action( 'getpaid_item_object_updated_props', $item, $updated_props );
314
+		do_action('getpaid_item_object_updated_props', $item, $updated_props);
315 315
 	}
316 316
 
317 317
 	/**
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
 	 * @param WPInv_Item $item Item object.
321 321
 	 * @since 1.0.19
322 322
 	 */
323
-	protected function clear_caches( &$item ) {
324
-		clean_post_cache( $item->get_id() );
323
+	protected function clear_caches(&$item) {
324
+		clean_post_cache($item->get_id());
325 325
 	}
326 326
 
327 327
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store.php 2 patches
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -11,171 +11,171 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Data_Store {
13 13
 
14
-	/**
15
-	 * Contains an instance of the data store class that we are working with.
16
-	 *
17
-	 * @var GetPaid_Data_Store
18
-	 */
19
-	private $instance = null;
20
-
21
-	/**
22
-	 * Contains an array of default GetPaid supported data stores.
23
-	 * Format of object name => class name.
24
-	 * Example: 'item' => 'GetPaid_Item_Data_Store_CPT'
25
-	 * You can also pass something like item-<type> for item stores and
26
-	 * that type will be used first when available, if a store is requested like
27
-	 * this and doesn't exist, then the store would fall back to 'item'.
28
-	 * Ran through `getpaid_data_stores`.
29
-	 *
30
-	 * @var array
31
-	 */
32
-	private $stores = array(
33
-		'item' => 'GetPaid_Item_Data_Store_CPT',
34
-	);
35
-
36
-	/**
37
-	 * Contains the name of the current data store's class name.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	private $current_class_name = '';
42
-
43
-	/**
44
-	 * The object type this store works with.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	private $object_type = '';
49
-
50
-	/**
51
-	 * Tells GetPaid_Data_Store which object
52
-	 * store we want to work with.
53
-	 *
54
-	 * @param string $object_type Name of object.
55
-	 */
56
-	public function __construct( $object_type ) {
57
-		$this->object_type = $object_type;
58
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
59
-
60
-		// If this object type can't be found, check to see if we can load one
61
-		// level up (so if item-type isn't found, we try item).
62
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
63
-			$pieces      = explode( '-', $object_type );
64
-			$object_type = $pieces[0];
65
-		}
66
-
67
-		if ( array_key_exists( $object_type, $this->stores ) ) {
68
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
69
-			if ( is_object( $store ) ) {
70
-				$this->current_class_name = get_class( $store );
71
-				$this->instance           = $store;
72
-			} else {
73
-				if ( ! class_exists( $store ) ) {
74
-					throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
75
-				}
76
-				$this->current_class_name = $store;
77
-				$this->instance           = new $store();
78
-			}
79
-		} else {
80
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
81
-		}
82
-	}
83
-
84
-	/**
85
-	 * Only store the object type to avoid serializing the data store instance.
86
-	 *
87
-	 * @return array
88
-	 */
89
-	public function __sleep() {
90
-		return array( 'object_type' );
91
-	}
92
-
93
-	/**
94
-	 * Re-run the constructor with the object type.
95
-	 *
96
-	 * @throws Exception When validation fails.
97
-	 */
98
-	public function __wakeup() {
99
-		$this->__construct( $this->object_type );
100
-	}
101
-
102
-	/**
103
-	 * Loads a data store.
104
-	 *
105
-	 * @param string $object_type Name of object.
106
-	 *
107
-	 * @since 1.0.19
108
-	 * @throws Exception When validation fails.
109
-	 * @return GetPaid_Data_Store
110
-	 */
111
-	public static function load( $object_type ) {
112
-		return new GetPaid_Data_Store( $object_type );
113
-	}
114
-
115
-	/**
116
-	 * Returns the class name of the current data store.
117
-	 *
118
-	 * @since 1.0.19
119
-	 * @return string
120
-	 */
121
-	public function get_current_class_name() {
122
-		return $this->current_class_name;
123
-	}
124
-
125
-	/**
126
-	 * Reads an object from the data store.
127
-	 *
128
-	 * @since 1.0.19
129
-	 * @param GetPaid_Data $data GetPaid data instance.
130
-	 */
131
-	public function read( &$data ) {
132
-		$this->instance->read( $data );
133
-	}
134
-
135
-	/**
136
-	 * Create an object in the data store.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param GetPaid_Data $data GetPaid data instance.
140
-	 */
141
-	public function create( &$data ) {
142
-		$this->instance->create( $data );
143
-	}
144
-
145
-	/**
146
-	 * Update an object in the data store.
147
-	 *
148
-	 * @since 1.0.19
149
-	 * @param GetPaid_Data $data GetPaid data instance.
150
-	 */
151
-	public function update( &$data ) {
152
-		$this->instance->update( $data );
153
-	}
154
-
155
-	/**
156
-	 * Delete an object from the data store.
157
-	 *
158
-	 * @since 1.0.19
159
-	 * @param GetPaid_Data $data GetPaid data instance.
160
-	 * @param array   $args Array of args to pass to the delete method.
161
-	 */
162
-	public function delete( &$data, $args = array() ) {
163
-		$this->instance->delete( $data, $args );
164
-	}
165
-
166
-	/**
167
-	 * Data stores can define additional function. This passes
168
-	 * through to the instance if that function exists.
169
-	 *
170
-	 * @since 1.0.19
171
-	 * @param string $method     Method.
172
-	 * @return mixed
173
-	 */
174
-	public function __call( $method, $parameters ) {
175
-		if ( is_callable( array( $this->instance, $method ) ) ) {
176
-			$object     = array_shift( $parameters );
177
-			$parameters = array_merge( array( &$object ), $parameters );
178
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
179
-		}
180
-	}
14
+    /**
15
+     * Contains an instance of the data store class that we are working with.
16
+     *
17
+     * @var GetPaid_Data_Store
18
+     */
19
+    private $instance = null;
20
+
21
+    /**
22
+     * Contains an array of default GetPaid supported data stores.
23
+     * Format of object name => class name.
24
+     * Example: 'item' => 'GetPaid_Item_Data_Store_CPT'
25
+     * You can also pass something like item-<type> for item stores and
26
+     * that type will be used first when available, if a store is requested like
27
+     * this and doesn't exist, then the store would fall back to 'item'.
28
+     * Ran through `getpaid_data_stores`.
29
+     *
30
+     * @var array
31
+     */
32
+    private $stores = array(
33
+        'item' => 'GetPaid_Item_Data_Store_CPT',
34
+    );
35
+
36
+    /**
37
+     * Contains the name of the current data store's class name.
38
+     *
39
+     * @var string
40
+     */
41
+    private $current_class_name = '';
42
+
43
+    /**
44
+     * The object type this store works with.
45
+     *
46
+     * @var string
47
+     */
48
+    private $object_type = '';
49
+
50
+    /**
51
+     * Tells GetPaid_Data_Store which object
52
+     * store we want to work with.
53
+     *
54
+     * @param string $object_type Name of object.
55
+     */
56
+    public function __construct( $object_type ) {
57
+        $this->object_type = $object_type;
58
+        $this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
59
+
60
+        // If this object type can't be found, check to see if we can load one
61
+        // level up (so if item-type isn't found, we try item).
62
+        if ( ! array_key_exists( $object_type, $this->stores ) ) {
63
+            $pieces      = explode( '-', $object_type );
64
+            $object_type = $pieces[0];
65
+        }
66
+
67
+        if ( array_key_exists( $object_type, $this->stores ) ) {
68
+            $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
69
+            if ( is_object( $store ) ) {
70
+                $this->current_class_name = get_class( $store );
71
+                $this->instance           = $store;
72
+            } else {
73
+                if ( ! class_exists( $store ) ) {
74
+                    throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
75
+                }
76
+                $this->current_class_name = $store;
77
+                $this->instance           = new $store();
78
+            }
79
+        } else {
80
+            throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
81
+        }
82
+    }
83
+
84
+    /**
85
+     * Only store the object type to avoid serializing the data store instance.
86
+     *
87
+     * @return array
88
+     */
89
+    public function __sleep() {
90
+        return array( 'object_type' );
91
+    }
92
+
93
+    /**
94
+     * Re-run the constructor with the object type.
95
+     *
96
+     * @throws Exception When validation fails.
97
+     */
98
+    public function __wakeup() {
99
+        $this->__construct( $this->object_type );
100
+    }
101
+
102
+    /**
103
+     * Loads a data store.
104
+     *
105
+     * @param string $object_type Name of object.
106
+     *
107
+     * @since 1.0.19
108
+     * @throws Exception When validation fails.
109
+     * @return GetPaid_Data_Store
110
+     */
111
+    public static function load( $object_type ) {
112
+        return new GetPaid_Data_Store( $object_type );
113
+    }
114
+
115
+    /**
116
+     * Returns the class name of the current data store.
117
+     *
118
+     * @since 1.0.19
119
+     * @return string
120
+     */
121
+    public function get_current_class_name() {
122
+        return $this->current_class_name;
123
+    }
124
+
125
+    /**
126
+     * Reads an object from the data store.
127
+     *
128
+     * @since 1.0.19
129
+     * @param GetPaid_Data $data GetPaid data instance.
130
+     */
131
+    public function read( &$data ) {
132
+        $this->instance->read( $data );
133
+    }
134
+
135
+    /**
136
+     * Create an object in the data store.
137
+     *
138
+     * @since 1.0.19
139
+     * @param GetPaid_Data $data GetPaid data instance.
140
+     */
141
+    public function create( &$data ) {
142
+        $this->instance->create( $data );
143
+    }
144
+
145
+    /**
146
+     * Update an object in the data store.
147
+     *
148
+     * @since 1.0.19
149
+     * @param GetPaid_Data $data GetPaid data instance.
150
+     */
151
+    public function update( &$data ) {
152
+        $this->instance->update( $data );
153
+    }
154
+
155
+    /**
156
+     * Delete an object from the data store.
157
+     *
158
+     * @since 1.0.19
159
+     * @param GetPaid_Data $data GetPaid data instance.
160
+     * @param array   $args Array of args to pass to the delete method.
161
+     */
162
+    public function delete( &$data, $args = array() ) {
163
+        $this->instance->delete( $data, $args );
164
+    }
165
+
166
+    /**
167
+     * Data stores can define additional function. This passes
168
+     * through to the instance if that function exists.
169
+     *
170
+     * @since 1.0.19
171
+     * @param string $method     Method.
172
+     * @return mixed
173
+     */
174
+    public function __call( $method, $parameters ) {
175
+        if ( is_callable( array( $this->instance, $method ) ) ) {
176
+            $object     = array_shift( $parameters );
177
+            $parameters = array_merge( array( &$object ), $parameters );
178
+            return call_user_func_array( array( $this->instance, $method ), $parameters );
179
+        }
180
+    }
181 181
 }
Please login to merge, or discard this patch.
Spacing   +29 added lines, -29 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
  * Data store class.
@@ -53,31 +53,31 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param string $object_type Name of object.
55 55
 	 */
56
-	public function __construct( $object_type ) {
56
+	public function __construct($object_type) {
57 57
 		$this->object_type = $object_type;
58
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
58
+		$this->stores      = apply_filters('getpaid_data_stores', $this->stores);
59 59
 
60 60
 		// If this object type can't be found, check to see if we can load one
61 61
 		// level up (so if item-type isn't found, we try item).
62
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
63
-			$pieces      = explode( '-', $object_type );
62
+		if (!array_key_exists($object_type, $this->stores)) {
63
+			$pieces      = explode('-', $object_type);
64 64
 			$object_type = $pieces[0];
65 65
 		}
66 66
 
67
-		if ( array_key_exists( $object_type, $this->stores ) ) {
68
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
69
-			if ( is_object( $store ) ) {
70
-				$this->current_class_name = get_class( $store );
67
+		if (array_key_exists($object_type, $this->stores)) {
68
+			$store = apply_filters('getpaid_' . $object_type . '_data_store', $this->stores[$object_type]);
69
+			if (is_object($store)) {
70
+				$this->current_class_name = get_class($store);
71 71
 				$this->instance           = $store;
72 72
 			} else {
73
-				if ( ! class_exists( $store ) ) {
74
-					throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
73
+				if (!class_exists($store)) {
74
+					throw new Exception(__('Invalid data store.', 'invoicing'));
75 75
 				}
76 76
 				$this->current_class_name = $store;
77 77
 				$this->instance           = new $store();
78 78
 			}
79 79
 		} else {
80
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
80
+			throw new Exception(__('Invalid data store.', 'invoicing'));
81 81
 		}
82 82
 	}
83 83
 
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @return array
88 88
 	 */
89 89
 	public function __sleep() {
90
-		return array( 'object_type' );
90
+		return array('object_type');
91 91
 	}
92 92
 
93 93
 	/**
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @throws Exception When validation fails.
97 97
 	 */
98 98
 	public function __wakeup() {
99
-		$this->__construct( $this->object_type );
99
+		$this->__construct($this->object_type);
100 100
 	}
101 101
 
102 102
 	/**
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 	 * @throws Exception When validation fails.
109 109
 	 * @return GetPaid_Data_Store
110 110
 	 */
111
-	public static function load( $object_type ) {
112
-		return new GetPaid_Data_Store( $object_type );
111
+	public static function load($object_type) {
112
+		return new GetPaid_Data_Store($object_type);
113 113
 	}
114 114
 
115 115
 	/**
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @since 1.0.19
129 129
 	 * @param GetPaid_Data $data GetPaid data instance.
130 130
 	 */
131
-	public function read( &$data ) {
132
-		$this->instance->read( $data );
131
+	public function read(&$data) {
132
+		$this->instance->read($data);
133 133
 	}
134 134
 
135 135
 	/**
@@ -138,8 +138,8 @@  discard block
 block discarded – undo
138 138
 	 * @since 1.0.19
139 139
 	 * @param GetPaid_Data $data GetPaid data instance.
140 140
 	 */
141
-	public function create( &$data ) {
142
-		$this->instance->create( $data );
141
+	public function create(&$data) {
142
+		$this->instance->create($data);
143 143
 	}
144 144
 
145 145
 	/**
@@ -148,8 +148,8 @@  discard block
 block discarded – undo
148 148
 	 * @since 1.0.19
149 149
 	 * @param GetPaid_Data $data GetPaid data instance.
150 150
 	 */
151
-	public function update( &$data ) {
152
-		$this->instance->update( $data );
151
+	public function update(&$data) {
152
+		$this->instance->update($data);
153 153
 	}
154 154
 
155 155
 	/**
@@ -159,8 +159,8 @@  discard block
 block discarded – undo
159 159
 	 * @param GetPaid_Data $data GetPaid data instance.
160 160
 	 * @param array   $args Array of args to pass to the delete method.
161 161
 	 */
162
-	public function delete( &$data, $args = array() ) {
163
-		$this->instance->delete( $data, $args );
162
+	public function delete(&$data, $args = array()) {
163
+		$this->instance->delete($data, $args);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,11 +171,11 @@  discard block
 block discarded – undo
171 171
 	 * @param string $method     Method.
172 172
 	 * @return mixed
173 173
 	 */
174
-	public function __call( $method, $parameters ) {
175
-		if ( is_callable( array( $this->instance, $method ) ) ) {
176
-			$object     = array_shift( $parameters );
177
-			$parameters = array_merge( array( &$object ), $parameters );
178
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
174
+	public function __call($method, $parameters) {
175
+		if (is_callable(array($this->instance, $method))) {
176
+			$object     = array_shift($parameters);
177
+			$parameters = array_merge(array(&$object), $parameters);
178
+			return call_user_func_array(array($this->instance, $method), $parameters);
179 179
 		}
180 180
 	}
181 181
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-cache-helper.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -11,121 +11,121 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Cache_Helper {
13 13
 
14
-	/**
15
-	 * Transients to delete on shutdown.
16
-	 *
17
-	 * @var array Array of transient keys.
18
-	 */
19
-	private static $delete_transients = array();
20
-
21
-	/**
22
-	 * Hook in methods.
23
-	 */
24
-	public static function init() {
25
-		add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
26
-		add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
27
-	}
28
-
29
-	/**
30
-	 * Add a transient to delete on shutdown.
31
-	 *
32
-	 * @since 1.0.19
33
-	 * @param string|array $keys Transient key or keys.
34
-	 */
35
-	public static function queue_delete_transient( $keys ) {
36
-		self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
37
-	}
38
-
39
-	/**
40
-	 * Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.
41
-	 *
42
-	 * @since 1.0.19
43
-	 */
44
-	public static function delete_transients_on_shutdown() {
45
-		if ( self::$delete_transients ) {
46
-			foreach ( self::$delete_transients as $key ) {
47
-				delete_transient( $key );
48
-			}
49
-			self::$delete_transients = array();
50
-		}
51
-	}
52
-
53
-	/**
54
-	 * Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
55
-	 *
56
-	 * @param  string $group Group of cache to get.
57
-	 * @return string
58
-	 */
59
-	public static function get_cache_prefix( $group ) {
60
-		// Get cache key.
61
-		$prefix = wp_cache_get( 'getpaid_' . $group . '_cache_prefix', $group );
62
-
63
-		if ( false === $prefix ) {
64
-			$prefix = microtime();
65
-			wp_cache_set( 'getpaid_' . $group . '_cache_prefix', $prefix, $group );
66
-		}
67
-
68
-		return 'getpaid_cache_' . $prefix . '_';
69
-	}
70
-
71
-	/**
72
-	 * Invalidate cache group.
73
-	 *
74
-	 * @param string $group Group of cache to clear.
75
-	 * @since 1.0.19
76
-	 */
77
-	public static function invalidate_cache_group( $group ) {
78
-		wp_cache_set( 'getpaid_' . $group . '_cache_prefix', microtime(), $group );
79
-	}
80
-
81
-	/**
82
-	 * Prevent caching on certain pages
83
-	 */
84
-	public static function prevent_caching() {
85
-		if ( ! is_blog_installed() ) {
86
-			return;
87
-		}
88
-
89
-		if ( wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page() ) {
90
-			self::set_nocache_constants();
91
-			nocache_headers();
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Get transient version.
98
-	 *
99
-	 *
100
-	 * @param  string  $group   Name for the group of transients we need to invalidate.
101
-	 * @param  boolean $refresh true to force a new version.
102
-	 * @return string transient version based on time(), 10 digits.
103
-	 */
104
-	public static function get_transient_version( $group, $refresh = false ) {
105
-		$transient_name  = $group . '-transient-version';
106
-		$transient_value = get_transient( $transient_name );
107
-
108
-		if ( false === $transient_value || true === $refresh ) {
109
-			$transient_value = (string) time();
110
-
111
-			set_transient( $transient_name, $transient_value );
112
-		}
113
-
114
-		return $transient_value;
115
-	}
116
-
117
-	/**
118
-	 * Set constants to prevent caching by some plugins.
119
-	 *
120
-	 * @param  mixed $return Value to return. Previously hooked into a filter.
121
-	 * @return mixed
122
-	 */
123
-	public static function set_nocache_constants( $return = true ) {
124
-		getpaid_maybe_define_constant( 'DONOTCACHEPAGE', true );
125
-		getpaid_maybe_define_constant( 'DONOTCACHEOBJECT', true );
126
-		getpaid_maybe_define_constant( 'DONOTCACHEDB', true );
127
-		return $return;
128
-	}
14
+    /**
15
+     * Transients to delete on shutdown.
16
+     *
17
+     * @var array Array of transient keys.
18
+     */
19
+    private static $delete_transients = array();
20
+
21
+    /**
22
+     * Hook in methods.
23
+     */
24
+    public static function init() {
25
+        add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
26
+        add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
27
+    }
28
+
29
+    /**
30
+     * Add a transient to delete on shutdown.
31
+     *
32
+     * @since 1.0.19
33
+     * @param string|array $keys Transient key or keys.
34
+     */
35
+    public static function queue_delete_transient( $keys ) {
36
+        self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
37
+    }
38
+
39
+    /**
40
+     * Transients that don't need to be cleaned right away can be deleted on shutdown to avoid repetition.
41
+     *
42
+     * @since 1.0.19
43
+     */
44
+    public static function delete_transients_on_shutdown() {
45
+        if ( self::$delete_transients ) {
46
+            foreach ( self::$delete_transients as $key ) {
47
+                delete_transient( $key );
48
+            }
49
+            self::$delete_transients = array();
50
+        }
51
+    }
52
+
53
+    /**
54
+     * Get prefix for use with wp_cache_set. Allows all cache in a group to be invalidated at once.
55
+     *
56
+     * @param  string $group Group of cache to get.
57
+     * @return string
58
+     */
59
+    public static function get_cache_prefix( $group ) {
60
+        // Get cache key.
61
+        $prefix = wp_cache_get( 'getpaid_' . $group . '_cache_prefix', $group );
62
+
63
+        if ( false === $prefix ) {
64
+            $prefix = microtime();
65
+            wp_cache_set( 'getpaid_' . $group . '_cache_prefix', $prefix, $group );
66
+        }
67
+
68
+        return 'getpaid_cache_' . $prefix . '_';
69
+    }
70
+
71
+    /**
72
+     * Invalidate cache group.
73
+     *
74
+     * @param string $group Group of cache to clear.
75
+     * @since 1.0.19
76
+     */
77
+    public static function invalidate_cache_group( $group ) {
78
+        wp_cache_set( 'getpaid_' . $group . '_cache_prefix', microtime(), $group );
79
+    }
80
+
81
+    /**
82
+     * Prevent caching on certain pages
83
+     */
84
+    public static function prevent_caching() {
85
+        if ( ! is_blog_installed() ) {
86
+            return;
87
+        }
88
+
89
+        if ( wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page() ) {
90
+            self::set_nocache_constants();
91
+            nocache_headers();
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Get transient version.
98
+     *
99
+     *
100
+     * @param  string  $group   Name for the group of transients we need to invalidate.
101
+     * @param  boolean $refresh true to force a new version.
102
+     * @return string transient version based on time(), 10 digits.
103
+     */
104
+    public static function get_transient_version( $group, $refresh = false ) {
105
+        $transient_name  = $group . '-transient-version';
106
+        $transient_value = get_transient( $transient_name );
107
+
108
+        if ( false === $transient_value || true === $refresh ) {
109
+            $transient_value = (string) time();
110
+
111
+            set_transient( $transient_name, $transient_value );
112
+        }
113
+
114
+        return $transient_value;
115
+    }
116
+
117
+    /**
118
+     * Set constants to prevent caching by some plugins.
119
+     *
120
+     * @param  mixed $return Value to return. Previously hooked into a filter.
121
+     * @return mixed
122
+     */
123
+    public static function set_nocache_constants( $return = true ) {
124
+        getpaid_maybe_define_constant( 'DONOTCACHEPAGE', true );
125
+        getpaid_maybe_define_constant( 'DONOTCACHEOBJECT', true );
126
+        getpaid_maybe_define_constant( 'DONOTCACHEDB', true );
127
+        return $return;
128
+    }
129 129
 
130 130
 }
131 131
 
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 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
  * GetPaid_Cache_Helper.
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
 	 * Hook in methods.
23 23
 	 */
24 24
 	public static function init() {
25
-		add_action( 'shutdown', array( __CLASS__, 'delete_transients_on_shutdown' ), 10 );
26
-		add_action( 'wp', array( __CLASS__, 'prevent_caching' ) );
25
+		add_action('shutdown', array(__CLASS__, 'delete_transients_on_shutdown'), 10);
26
+		add_action('wp', array(__CLASS__, 'prevent_caching'));
27 27
 	}
28 28
 
29 29
 	/**
@@ -32,8 +32,8 @@  discard block
 block discarded – undo
32 32
 	 * @since 1.0.19
33 33
 	 * @param string|array $keys Transient key or keys.
34 34
 	 */
35
-	public static function queue_delete_transient( $keys ) {
36
-		self::$delete_transients = array_unique( array_merge( is_array( $keys ) ? $keys : array( $keys ), self::$delete_transients ) );
35
+	public static function queue_delete_transient($keys) {
36
+		self::$delete_transients = array_unique(array_merge(is_array($keys) ? $keys : array($keys), self::$delete_transients));
37 37
 	}
38 38
 
39 39
 	/**
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	 * @since 1.0.19
43 43
 	 */
44 44
 	public static function delete_transients_on_shutdown() {
45
-		if ( self::$delete_transients ) {
46
-			foreach ( self::$delete_transients as $key ) {
47
-				delete_transient( $key );
45
+		if (self::$delete_transients) {
46
+			foreach (self::$delete_transients as $key) {
47
+				delete_transient($key);
48 48
 			}
49 49
 			self::$delete_transients = array();
50 50
 		}
@@ -56,13 +56,13 @@  discard block
 block discarded – undo
56 56
 	 * @param  string $group Group of cache to get.
57 57
 	 * @return string
58 58
 	 */
59
-	public static function get_cache_prefix( $group ) {
59
+	public static function get_cache_prefix($group) {
60 60
 		// Get cache key.
61
-		$prefix = wp_cache_get( 'getpaid_' . $group . '_cache_prefix', $group );
61
+		$prefix = wp_cache_get('getpaid_' . $group . '_cache_prefix', $group);
62 62
 
63
-		if ( false === $prefix ) {
63
+		if (false === $prefix) {
64 64
 			$prefix = microtime();
65
-			wp_cache_set( 'getpaid_' . $group . '_cache_prefix', $prefix, $group );
65
+			wp_cache_set('getpaid_' . $group . '_cache_prefix', $prefix, $group);
66 66
 		}
67 67
 
68 68
 		return 'getpaid_cache_' . $prefix . '_';
@@ -74,19 +74,19 @@  discard block
 block discarded – undo
74 74
 	 * @param string $group Group of cache to clear.
75 75
 	 * @since 1.0.19
76 76
 	 */
77
-	public static function invalidate_cache_group( $group ) {
78
-		wp_cache_set( 'getpaid_' . $group . '_cache_prefix', microtime(), $group );
77
+	public static function invalidate_cache_group($group) {
78
+		wp_cache_set('getpaid_' . $group . '_cache_prefix', microtime(), $group);
79 79
 	}
80 80
 
81 81
 	/**
82 82
 	 * Prevent caching on certain pages
83 83
 	 */
84 84
 	public static function prevent_caching() {
85
-		if ( ! is_blog_installed() ) {
85
+		if (!is_blog_installed()) {
86 86
 			return;
87 87
 		}
88 88
 
89
-		if ( wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page() ) {
89
+		if (wpinv_is_checkout() || wpinv_is_success_page() || wpinv_is_invoice_history_page() || wpinv_is_subscriptions_history_page()) {
90 90
 			self::set_nocache_constants();
91 91
 			nocache_headers();
92 92
 		}
@@ -101,14 +101,14 @@  discard block
 block discarded – undo
101 101
 	 * @param  boolean $refresh true to force a new version.
102 102
 	 * @return string transient version based on time(), 10 digits.
103 103
 	 */
104
-	public static function get_transient_version( $group, $refresh = false ) {
104
+	public static function get_transient_version($group, $refresh = false) {
105 105
 		$transient_name  = $group . '-transient-version';
106
-		$transient_value = get_transient( $transient_name );
106
+		$transient_value = get_transient($transient_name);
107 107
 
108
-		if ( false === $transient_value || true === $refresh ) {
108
+		if (false === $transient_value || true === $refresh) {
109 109
 			$transient_value = (string) time();
110 110
 
111
-			set_transient( $transient_name, $transient_value );
111
+			set_transient($transient_name, $transient_value);
112 112
 		}
113 113
 
114 114
 		return $transient_value;
@@ -120,10 +120,10 @@  discard block
 block discarded – undo
120 120
 	 * @param  mixed $return Value to return. Previously hooked into a filter.
121 121
 	 * @return mixed
122 122
 	 */
123
-	public static function set_nocache_constants( $return = true ) {
124
-		getpaid_maybe_define_constant( 'DONOTCACHEPAGE', true );
125
-		getpaid_maybe_define_constant( 'DONOTCACHEOBJECT', true );
126
-		getpaid_maybe_define_constant( 'DONOTCACHEDB', true );
123
+	public static function set_nocache_constants($return = true) {
124
+		getpaid_maybe_define_constant('DONOTCACHEPAGE', true);
125
+		getpaid_maybe_define_constant('DONOTCACHEOBJECT', true);
126
+		getpaid_maybe_define_constant('DONOTCACHEDB', true);
127 127
 		return $return;
128 128
 	}
129 129
 
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store-wp.php 2 patches
Indentation   +209 added lines, -209 removed lines patch added patch discarded remove patch
@@ -12,217 +12,217 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Data_Store_WP {
14 14
 
15
-	/**
16
-	 * Meta type. This should match up with
17
-	 * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
18
-	 * WP defines 'post', 'user', 'comment', and 'term'.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $meta_type = 'post';
23
-
24
-	/**
25
-	 * This only needs set if you are using a custom metadata type (for example payment tokens.
26
-	 *
27
-	 * @var string
28
-	 */
29
-	protected $object_id_field_for_meta = '';
30
-
31
-	/**
32
-	 * Data stored in meta keys, but not considered "meta" for an object.
33
-	 *
34
-	 * @since 1.0.19
35
-	 *
36
-	 * @var array
37
-	 */
38
-	protected $internal_meta_keys = array();
39
-
40
-	/**
41
-	 * Meta data which should exist in the DB, even if empty.
42
-	 *
43
-	 * @since 1.0.19
44
-	 *
45
-	 * @var array
46
-	 */
47
-	protected $must_exist_meta_keys = array();
48
-
49
-	/**
50
-	 * Returns an array of meta for an object.
51
-	 *
52
-	 * @since  1.0.19
53
-	 * @param  GetPaid_Data $object GetPaid_Data object.
54
-	 * @return array
55
-	 */
56
-	public function read_meta( &$object ) {
57
-		global $wpdb;
58
-		$db_info       = $this->get_db_info();
59
-		$raw_meta_data = $wpdb->get_results(
60
-			$wpdb->prepare(
61
-				"SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
15
+    /**
16
+     * Meta type. This should match up with
17
+     * the types available at https://developer.wordpress.org/reference/functions/add_metadata/.
18
+     * WP defines 'post', 'user', 'comment', and 'term'.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $meta_type = 'post';
23
+
24
+    /**
25
+     * This only needs set if you are using a custom metadata type (for example payment tokens.
26
+     *
27
+     * @var string
28
+     */
29
+    protected $object_id_field_for_meta = '';
30
+
31
+    /**
32
+     * Data stored in meta keys, but not considered "meta" for an object.
33
+     *
34
+     * @since 1.0.19
35
+     *
36
+     * @var array
37
+     */
38
+    protected $internal_meta_keys = array();
39
+
40
+    /**
41
+     * Meta data which should exist in the DB, even if empty.
42
+     *
43
+     * @since 1.0.19
44
+     *
45
+     * @var array
46
+     */
47
+    protected $must_exist_meta_keys = array();
48
+
49
+    /**
50
+     * Returns an array of meta for an object.
51
+     *
52
+     * @since  1.0.19
53
+     * @param  GetPaid_Data $object GetPaid_Data object.
54
+     * @return array
55
+     */
56
+    public function read_meta( &$object ) {
57
+        global $wpdb;
58
+        $db_info       = $this->get_db_info();
59
+        $raw_meta_data = $wpdb->get_results(
60
+            $wpdb->prepare(
61
+                "SELECT {$db_info['meta_id_field']} as meta_id, meta_key, meta_value
62 62
 				FROM {$db_info['table']}
63 63
 				WHERE {$db_info['object_id_field']} = %d
64 64
 				ORDER BY {$db_info['meta_id_field']}",
65
-				$object->get_id()
66
-			)
67
-		);
68
-
69
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
70
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
71
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
72
-	}
73
-
74
-	/**
75
-	 * Deletes meta based on meta ID.
76
-	 *
77
-	 * @since  1.0.19
78
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
79
-	 * @param  stdClass $meta (containing at least ->id).
80
-	 */
81
-	public function delete_meta( &$object, $meta ) {
82
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
83
-	}
84
-
85
-	/**
86
-	 * Add new piece of meta.
87
-	 *
88
-	 * @since  1.0.19
89
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
90
-	 * @param  stdClass $meta (containing ->key and ->value).
91
-	 * @return int meta ID
92
-	 */
93
-	public function add_meta( &$object, $meta ) {
94
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
95
-	}
96
-
97
-	/**
98
-	 * Update meta.
99
-	 *
100
-	 * @since  1.0.19
101
-	 * @param  GetPaid_Data  $object GetPaid_Data object.
102
-	 * @param  stdClass $meta (containing ->id, ->key and ->value).
103
-	 */
104
-	public function update_meta( &$object, $meta ) {
105
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
106
-	}
107
-
108
-	/**
109
-	 * Table structure is slightly different between meta types, this function will return what we need to know.
110
-	 *
111
-	 * @since  1.0.19
112
-	 * @return array Array elements: table, object_id_field, meta_id_field
113
-	 */
114
-	protected function get_db_info() {
115
-		global $wpdb;
116
-
117
-		$meta_id_field = 'meta_id'; // for some reason users calls this umeta_id so we need to track this as well.
118
-		$table         = $wpdb->prefix;
119
-
120
-		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
121
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
122
-			$table .= 'getpaid_';
123
-		}
124
-
125
-		$table          .= $this->meta_type . 'meta';
126
-		$object_id_field = $this->meta_type . '_id';
127
-
128
-		// Figure out our field names.
129
-		if ( 'user' === $this->meta_type ) {
130
-			$meta_id_field = 'umeta_id';
131
-			$table         = $wpdb->usermeta;
132
-		}
133
-
134
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
135
-			$object_id_field = $this->object_id_field_for_meta;
136
-		}
137
-
138
-		return array(
139
-			'table'           => $table,
140
-			'object_id_field' => $object_id_field,
141
-			'meta_id_field'   => $meta_id_field,
142
-		);
143
-	}
144
-
145
-	/**
146
-	 * Internal meta keys we don't want exposed as part of meta_data. This is in
147
-	 * addition to all data props with _ prefix.
148
-	 *
149
-	 * @since 1.0.19
150
-	 *
151
-	 * @param string $key Prefix to be added to meta keys.
152
-	 * @return string
153
-	 */
154
-	protected function prefix_key( $key ) {
155
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
156
-	}
157
-
158
-	/**
159
-	 * Callback to remove unwanted meta data.
160
-	 *
161
-	 * @param object $meta Meta object to check if it should be excluded or not.
162
-	 * @return bool
163
-	 */
164
-	protected function exclude_internal_meta_keys( $meta ) {
165
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
166
-	}
167
-
168
-	/**
169
-	 * Gets a list of props and meta keys that need updated based on change state
170
-	 * or if they are present in the database or not.
171
-	 *
172
-	 * @param  GetPaid_Data $object         The GetPaid_Data object.
173
-	 * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
174
-	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
175
-	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
176
-	 */
177
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
178
-		$props_to_update = array();
179
-		$changed_props   = $object->get_changes();
180
-
181
-		// Props should be updated if they are a part of the $changed array or don't exist yet.
182
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
183
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
184
-				$props_to_update[ $meta_key ] = $prop;
185
-			}
186
-		}
187
-
188
-		return $props_to_update;
189
-	}
190
-
191
-	/**
192
-	 * Update meta data in, or delete it from, the database.
193
-	 *
194
-	 * Avoids storing meta when it's either an empty string or empty array or null.
195
-	 * Other empty values such as numeric 0 should still be stored.
196
-	 * Data-stores can force meta to exist using `must_exist_meta_keys`.
197
-	 *
198
-	 * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
199
-	 *
200
-	 * @param GetPaid_Data $object The GetPaid_Data object.
201
-	 * @param string  $meta_key Meta key to update.
202
-	 * @param mixed   $meta_value Value to save.
203
-	 *
204
-	 * @since 1.0.19 Added to prevent empty meta being stored unless required.
205
-	 *
206
-	 * @return bool True if updated/deleted.
207
-	 */
208
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
209
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
210
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
211
-		} else {
212
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
213
-		}
214
-
215
-		return (bool) $updated;
216
-	}
217
-
218
-	/**
219
-	 * Return list of internal meta keys.
220
-	 *
221
-	 * @since 1.0.19
222
-	 * @return array
223
-	 */
224
-	public function get_internal_meta_keys() {
225
-		return $this->internal_meta_keys;
226
-	}
65
+                $object->get_id()
66
+            )
67
+        );
68
+
69
+        $this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
70
+        $meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
71
+        return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
72
+    }
73
+
74
+    /**
75
+     * Deletes meta based on meta ID.
76
+     *
77
+     * @since  1.0.19
78
+     * @param  GetPaid_Data  $object GetPaid_Data object.
79
+     * @param  stdClass $meta (containing at least ->id).
80
+     */
81
+    public function delete_meta( &$object, $meta ) {
82
+        delete_metadata_by_mid( $this->meta_type, $meta->id );
83
+    }
84
+
85
+    /**
86
+     * Add new piece of meta.
87
+     *
88
+     * @since  1.0.19
89
+     * @param  GetPaid_Data  $object GetPaid_Data object.
90
+     * @param  stdClass $meta (containing ->key and ->value).
91
+     * @return int meta ID
92
+     */
93
+    public function add_meta( &$object, $meta ) {
94
+        return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
95
+    }
96
+
97
+    /**
98
+     * Update meta.
99
+     *
100
+     * @since  1.0.19
101
+     * @param  GetPaid_Data  $object GetPaid_Data object.
102
+     * @param  stdClass $meta (containing ->id, ->key and ->value).
103
+     */
104
+    public function update_meta( &$object, $meta ) {
105
+        update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
106
+    }
107
+
108
+    /**
109
+     * Table structure is slightly different between meta types, this function will return what we need to know.
110
+     *
111
+     * @since  1.0.19
112
+     * @return array Array elements: table, object_id_field, meta_id_field
113
+     */
114
+    protected function get_db_info() {
115
+        global $wpdb;
116
+
117
+        $meta_id_field = 'meta_id'; // for some reason users calls this umeta_id so we need to track this as well.
118
+        $table         = $wpdb->prefix;
119
+
120
+        // If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
121
+        if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
122
+            $table .= 'getpaid_';
123
+        }
124
+
125
+        $table          .= $this->meta_type . 'meta';
126
+        $object_id_field = $this->meta_type . '_id';
127
+
128
+        // Figure out our field names.
129
+        if ( 'user' === $this->meta_type ) {
130
+            $meta_id_field = 'umeta_id';
131
+            $table         = $wpdb->usermeta;
132
+        }
133
+
134
+        if ( ! empty( $this->object_id_field_for_meta ) ) {
135
+            $object_id_field = $this->object_id_field_for_meta;
136
+        }
137
+
138
+        return array(
139
+            'table'           => $table,
140
+            'object_id_field' => $object_id_field,
141
+            'meta_id_field'   => $meta_id_field,
142
+        );
143
+    }
144
+
145
+    /**
146
+     * Internal meta keys we don't want exposed as part of meta_data. This is in
147
+     * addition to all data props with _ prefix.
148
+     *
149
+     * @since 1.0.19
150
+     *
151
+     * @param string $key Prefix to be added to meta keys.
152
+     * @return string
153
+     */
154
+    protected function prefix_key( $key ) {
155
+        return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
156
+    }
157
+
158
+    /**
159
+     * Callback to remove unwanted meta data.
160
+     *
161
+     * @param object $meta Meta object to check if it should be excluded or not.
162
+     * @return bool
163
+     */
164
+    protected function exclude_internal_meta_keys( $meta ) {
165
+        return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
166
+    }
167
+
168
+    /**
169
+     * Gets a list of props and meta keys that need updated based on change state
170
+     * or if they are present in the database or not.
171
+     *
172
+     * @param  GetPaid_Data $object         The GetPaid_Data object.
173
+     * @param  array   $meta_key_to_props   A mapping of meta keys => prop names.
174
+     * @param  string  $meta_type           The internal WP meta type (post, user, etc).
175
+     * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
176
+     */
177
+    protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
178
+        $props_to_update = array();
179
+        $changed_props   = $object->get_changes();
180
+
181
+        // Props should be updated if they are a part of the $changed array or don't exist yet.
182
+        foreach ( $meta_key_to_props as $meta_key => $prop ) {
183
+            if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
184
+                $props_to_update[ $meta_key ] = $prop;
185
+            }
186
+        }
187
+
188
+        return $props_to_update;
189
+    }
190
+
191
+    /**
192
+     * Update meta data in, or delete it from, the database.
193
+     *
194
+     * Avoids storing meta when it's either an empty string or empty array or null.
195
+     * Other empty values such as numeric 0 should still be stored.
196
+     * Data-stores can force meta to exist using `must_exist_meta_keys`.
197
+     *
198
+     * Note: WordPress `get_metadata` function returns an empty string when meta data does not exist.
199
+     *
200
+     * @param GetPaid_Data $object The GetPaid_Data object.
201
+     * @param string  $meta_key Meta key to update.
202
+     * @param mixed   $meta_value Value to save.
203
+     *
204
+     * @since 1.0.19 Added to prevent empty meta being stored unless required.
205
+     *
206
+     * @return bool True if updated/deleted.
207
+     */
208
+    protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
209
+        if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
210
+            $updated = delete_post_meta( $object->get_id(), $meta_key );
211
+        } else {
212
+            $updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
213
+        }
214
+
215
+        return (bool) $updated;
216
+    }
217
+
218
+    /**
219
+     * Return list of internal meta keys.
220
+     *
221
+     * @since 1.0.19
222
+     * @return array
223
+     */
224
+    public function get_internal_meta_keys() {
225
+        return $this->internal_meta_keys;
226
+    }
227 227
 
228 228
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.19
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * GetPaid_Data_Store_WP class.
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 * @param  GetPaid_Data $object GetPaid_Data object.
54 54
 	 * @return array
55 55
 	 */
56
-	public function read_meta( &$object ) {
56
+	public function read_meta(&$object) {
57 57
 		global $wpdb;
58 58
 		$db_info       = $this->get_db_info();
59 59
 		$raw_meta_data = $wpdb->get_results(
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
 			)
67 67
 		);
68 68
 
69
-		$this->internal_meta_keys = array_merge( array_map( array( $this, 'prefix_key' ), $object->get_data_keys() ), $this->internal_meta_keys );
70
-		$meta_data                = array_filter( $raw_meta_data, array( $this, 'exclude_internal_meta_keys' ) );
71
-		return apply_filters( "getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this );
69
+		$this->internal_meta_keys = array_merge(array_map(array($this, 'prefix_key'), $object->get_data_keys()), $this->internal_meta_keys);
70
+		$meta_data                = array_filter($raw_meta_data, array($this, 'exclude_internal_meta_keys'));
71
+		return apply_filters("getpaid_data_store_wp_{$this->meta_type}_read_meta", $meta_data, $object, $this);
72 72
 	}
73 73
 
74 74
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
79 79
 	 * @param  stdClass $meta (containing at least ->id).
80 80
 	 */
81
-	public function delete_meta( &$object, $meta ) {
82
-		delete_metadata_by_mid( $this->meta_type, $meta->id );
81
+	public function delete_meta(&$object, $meta) {
82
+		delete_metadata_by_mid($this->meta_type, $meta->id);
83 83
 	}
84 84
 
85 85
 	/**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
 	 * @param  stdClass $meta (containing ->key and ->value).
91 91
 	 * @return int meta ID
92 92
 	 */
93
-	public function add_meta( &$object, $meta ) {
94
-		return add_metadata( $this->meta_type, $object->get_id(), $meta->key, is_string( $meta->value ) ? wp_slash( $meta->value ) : $meta->value, false );
93
+	public function add_meta(&$object, $meta) {
94
+		return add_metadata($this->meta_type, $object->get_id(), $meta->key, is_string($meta->value) ? wp_slash($meta->value) : $meta->value, false);
95 95
 	}
96 96
 
97 97
 	/**
@@ -101,8 +101,8 @@  discard block
 block discarded – undo
101 101
 	 * @param  GetPaid_Data  $object GetPaid_Data object.
102 102
 	 * @param  stdClass $meta (containing ->id, ->key and ->value).
103 103
 	 */
104
-	public function update_meta( &$object, $meta ) {
105
-		update_metadata_by_mid( $this->meta_type, $meta->id, $meta->value, $meta->key );
104
+	public function update_meta(&$object, $meta) {
105
+		update_metadata_by_mid($this->meta_type, $meta->id, $meta->value, $meta->key);
106 106
 	}
107 107
 
108 108
 	/**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		$table         = $wpdb->prefix;
119 119
 
120 120
 		// If we are dealing with a type of metadata that is not a core type, the table should be prefixed.
121
-		if ( ! in_array( $this->meta_type, array( 'post', 'user', 'comment', 'term' ), true ) ) {
121
+		if (!in_array($this->meta_type, array('post', 'user', 'comment', 'term'), true)) {
122 122
 			$table .= 'getpaid_';
123 123
 		}
124 124
 
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 		$object_id_field = $this->meta_type . '_id';
127 127
 
128 128
 		// Figure out our field names.
129
-		if ( 'user' === $this->meta_type ) {
129
+		if ('user' === $this->meta_type) {
130 130
 			$meta_id_field = 'umeta_id';
131 131
 			$table         = $wpdb->usermeta;
132 132
 		}
133 133
 
134
-		if ( ! empty( $this->object_id_field_for_meta ) ) {
134
+		if (!empty($this->object_id_field_for_meta)) {
135 135
 			$object_id_field = $this->object_id_field_for_meta;
136 136
 		}
137 137
 
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	 * @param string $key Prefix to be added to meta keys.
152 152
 	 * @return string
153 153
 	 */
154
-	protected function prefix_key( $key ) {
155
-		return '_' === substr( $key, 0, 1 ) ? $key : '_' . $key;
154
+	protected function prefix_key($key) {
155
+		return '_' === substr($key, 0, 1) ? $key : '_' . $key;
156 156
 	}
157 157
 
158 158
 	/**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param object $meta Meta object to check if it should be excluded or not.
162 162
 	 * @return bool
163 163
 	 */
164
-	protected function exclude_internal_meta_keys( $meta ) {
165
-		return ! in_array( $meta->meta_key, $this->internal_meta_keys, true ) && 0 !== stripos( $meta->meta_key, 'wp_' );
164
+	protected function exclude_internal_meta_keys($meta) {
165
+		return !in_array($meta->meta_key, $this->internal_meta_keys, true) && 0 !== stripos($meta->meta_key, 'wp_');
166 166
 	}
167 167
 
168 168
 	/**
@@ -174,14 +174,14 @@  discard block
 block discarded – undo
174 174
 	 * @param  string  $meta_type           The internal WP meta type (post, user, etc).
175 175
 	 * @return array                        A mapping of meta keys => prop names, filtered by ones that should be updated.
176 176
 	 */
177
-	protected function get_props_to_update( $object, $meta_key_to_props, $meta_type = 'post' ) {
177
+	protected function get_props_to_update($object, $meta_key_to_props, $meta_type = 'post') {
178 178
 		$props_to_update = array();
179 179
 		$changed_props   = $object->get_changes();
180 180
 
181 181
 		// Props should be updated if they are a part of the $changed array or don't exist yet.
182
-		foreach ( $meta_key_to_props as $meta_key => $prop ) {
183
-			if ( array_key_exists( $prop, $changed_props ) || ! metadata_exists( $meta_type, $object->get_id(), $meta_key ) ) {
184
-				$props_to_update[ $meta_key ] = $prop;
182
+		foreach ($meta_key_to_props as $meta_key => $prop) {
183
+			if (array_key_exists($prop, $changed_props) || !metadata_exists($meta_type, $object->get_id(), $meta_key)) {
184
+				$props_to_update[$meta_key] = $prop;
185 185
 			}
186 186
 		}
187 187
 
@@ -205,11 +205,11 @@  discard block
 block discarded – undo
205 205
 	 *
206 206
 	 * @return bool True if updated/deleted.
207 207
 	 */
208
-	protected function update_or_delete_post_meta( $object, $meta_key, $meta_value ) {
209
-		if ( in_array( $meta_value, array( array(), '', null ), true ) && ! in_array( $meta_key, $this->must_exist_meta_keys, true ) ) {
210
-			$updated = delete_post_meta( $object->get_id(), $meta_key );
208
+	protected function update_or_delete_post_meta($object, $meta_key, $meta_value) {
209
+		if (in_array($meta_value, array(array(), '', null), true) && !in_array($meta_key, $this->must_exist_meta_keys, true)) {
210
+			$updated = delete_post_meta($object->get_id(), $meta_key);
211 211
 		} else {
212
-			$updated = update_post_meta( $object->get_id(), $meta_key, $meta_value );
212
+			$updated = update_post_meta($object->get_id(), $meta_key, $meta_value);
213 213
 		}
214 214
 
215 215
 		return (bool) $updated;
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +764 added lines, -764 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,767 +21,767 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var object
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores additional meta data.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var array
104
-	 */
105
-	protected $meta_data = null;
106
-
107
-	/**
108
-	 * Default constructor.
109
-	 *
110
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
111
-	 */
112
-	public function __construct( $read = 0 ) {
113
-		$this->data         = array_merge( $this->data, $this->extra_data );
114
-		$this->default_data = $this->data;
115
-	}
116
-
117
-	/**
118
-	 * Only store the object ID to avoid serializing the data object instance.
119
-	 *
120
-	 * @return array
121
-	 */
122
-	public function __sleep() {
123
-		return array( 'id' );
124
-	}
125
-
126
-	/**
127
-	 * Re-run the constructor with the object ID.
128
-	 *
129
-	 * If the object no longer exists, remove the ID.
130
-	 */
131
-	public function __wakeup() {
132
-		try {
133
-			$this->__construct( absint( $this->id ) );
134
-		} catch ( Exception $e ) {
135
-			$this->set_id( 0 );
136
-			$this->set_object_read( true );
137
-		}
138
-	}
139
-
140
-	/**
141
-	 * When the object is cloned, make sure meta is duplicated correctly.
142
-	 *
143
-	 * @since 1.0.19
144
-	 */
145
-	public function __clone() {
146
-		$this->maybe_read_meta_data();
147
-		if ( ! empty( $this->meta_data ) ) {
148
-			foreach ( $this->meta_data as $array_key => $meta ) {
149
-				$this->meta_data[ $array_key ] = clone $meta;
150
-				if ( ! empty( $meta->id ) ) {
151
-					$this->meta_data[ $array_key ]->id = null;
152
-				}
153
-			}
154
-		}
155
-	}
156
-
157
-	/**
158
-	 * Get the data store.
159
-	 *
160
-	 * @since  1.0.19
161
-	 * @return object
162
-	 */
163
-	public function get_data_store() {
164
-		return $this->data_store;
165
-	}
166
-
167
-	/**
168
-	 * Returns the unique ID for this object.
169
-	 *
170
-	 * @since  1.0.19
171
-	 * @return int
172
-	 */
173
-	public function get_id() {
174
-		return $this->id;
175
-	}
176
-
177
-	/**
178
-	 * Delete an object, set the ID to 0, and return result.
179
-	 *
180
-	 * @since  1.0.19
181
-	 * @param  bool $force_delete Should the data be deleted permanently.
182
-	 * @return bool result
183
-	 */
184
-	public function delete( $force_delete = false ) {
185
-		if ( $this->data_store ) {
186
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
187
-			$this->set_id( 0 );
188
-			return true;
189
-		}
190
-		return false;
191
-	}
192
-
193
-	/**
194
-	 * Save should create or update based on object existence.
195
-	 *
196
-	 * @since  1.0.19
197
-	 * @return int
198
-	 */
199
-	public function save() {
200
-		if ( ! $this->data_store ) {
201
-			return $this->get_id();
202
-		}
203
-
204
-		/**
205
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
206
-		 *
207
-		 * @param GetPaid_Data          $this The object being saved.
208
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
209
-		 */
210
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
211
-
212
-		if ( $this->get_id() ) {
213
-			$this->data_store->update( $this );
214
-		} else {
215
-			$this->data_store->create( $this );
216
-		}
217
-
218
-		/**
219
-		 * Trigger action after saving to the DB.
220
-		 *
221
-		 * @param GetPaid_Data          $this The object being saved.
222
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
223
-		 */
224
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
225
-
226
-		return $this->get_id();
227
-	}
228
-
229
-	/**
230
-	 * Change data to JSON format.
231
-	 *
232
-	 * @since  1.0.19
233
-	 * @return string Data in JSON format.
234
-	 */
235
-	public function __toString() {
236
-		return wp_json_encode( $this->get_data() );
237
-	}
238
-
239
-	/**
240
-	 * Returns all data for this object.
241
-	 *
242
-	 * @since  1.0.19
243
-	 * @return array
244
-	 */
245
-	public function get_data() {
246
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
247
-	}
248
-
249
-	/**
250
-	 * Returns array of expected data keys for this object.
251
-	 *
252
-	 * @since   1.0.19
253
-	 * @return array
254
-	 */
255
-	public function get_data_keys() {
256
-		return array_keys( $this->data );
257
-	}
258
-
259
-	/**
260
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
261
-	 *
262
-	 * @since  1.0.19
263
-	 * @return array
264
-	 */
265
-	public function get_extra_data_keys() {
266
-		return array_keys( $this->extra_data );
267
-	}
268
-
269
-	/**
270
-	 * Filter null meta values from array.
271
-	 *
272
-	 * @since  1.0.19
273
-	 * @param mixed $meta Meta value to check.
274
-	 * @return bool
275
-	 */
276
-	protected function filter_null_meta( $meta ) {
277
-		return ! is_null( $meta->value );
278
-	}
279
-
280
-	/**
281
-	 * Get All Meta Data.
282
-	 *
283
-	 * @since 1.0.19
284
-	 * @return array of objects.
285
-	 */
286
-	public function get_meta_data() {
287
-		$this->maybe_read_meta_data();
288
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
289
-	}
290
-
291
-	/**
292
-	 * Check if the key is an internal one.
293
-	 *
294
-	 * @since  1.0.19
295
-	 * @param  string $key Key to check.
296
-	 * @return bool   true if it's an internal key, false otherwise
297
-	 */
298
-	protected function is_internal_meta_key( $key ) {
299
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
300
-
301
-		if ( ! $internal_meta_key ) {
302
-			return false;
303
-		}
304
-
305
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
306
-
307
-		if ( ! $has_setter_or_getter ) {
308
-			return false;
309
-		}
310
-
311
-		/* translators: %s: $key Key to check */
312
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
313
-
314
-		return true;
315
-	}
316
-
317
-	/**
318
-	 * Get Meta Data by Key.
319
-	 *
320
-	 * @since  1.0.19
321
-	 * @param  string $key Meta Key.
322
-	 * @param  bool   $single return first found meta with key, or all with $key.
323
-	 * @param  string $context What the value is for. Valid values are view and edit.
324
-	 * @return mixed
325
-	 */
326
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
327
-
328
-		// Check if this is an internal meta key.
329
-		if ( $this->is_internal_meta_key( $key ) ) {
330
-			$function = 'get_' . $key;
331
-
332
-			if ( is_callable( array( $this, $function ) ) ) {
333
-				return $this->{$function}();
334
-			}
335
-		}
336
-
337
-		// Read the meta data if not yet read.
338
-		$this->maybe_read_meta_data();
339
-		$meta_data  = $this->get_meta_data();
340
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
341
-		$value      = $single ? '' : array();
342
-
343
-		if ( ! empty( $array_keys ) ) {
344
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
345
-			if ( $single ) {
346
-				$value = $meta_data[ current( $array_keys ) ]->value;
347
-			} else {
348
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
349
-			}
350
-		}
351
-
352
-		if ( 'view' === $context ) {
353
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
354
-		}
355
-
356
-		return $value;
357
-	}
358
-
359
-	/**
360
-	 * See if meta data exists, since get_meta always returns a '' or array().
361
-	 *
362
-	 * @since  1.0.19
363
-	 * @param  string $key Meta Key.
364
-	 * @return boolean
365
-	 */
366
-	public function meta_exists( $key = '' ) {
367
-		$this->maybe_read_meta_data();
368
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
369
-		return in_array( $key, $array_keys, true );
370
-	}
371
-
372
-	/**
373
-	 * Set all meta data from array.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param array $data Key/Value pairs.
377
-	 */
378
-	public function set_meta_data( $data ) {
379
-		if ( ! empty( $data ) && is_array( $data ) ) {
380
-			$this->maybe_read_meta_data();
381
-			foreach ( $data as $meta ) {
382
-				$meta = (array) $meta;
383
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
384
-					$this->meta_data[] = new GetPaid_Meta_Data(
385
-						array(
386
-							'id'    => $meta['id'],
387
-							'key'   => $meta['key'],
388
-							'value' => $meta['value'],
389
-						)
390
-					);
391
-				}
392
-			}
393
-		}
394
-	}
395
-
396
-	/**
397
-	 * Add meta data.
398
-	 *
399
-	 * @since 1.0.19
400
-	 *
401
-	 * @param string       $key Meta key.
402
-	 * @param string|array $value Meta value.
403
-	 * @param bool         $unique Should this be a unique key?.
404
-	 */
405
-	public function add_meta_data( $key, $value, $unique = false ) {
406
-		if ( $this->is_internal_meta_key( $key ) ) {
407
-			$function = 'set_' . $key;
408
-
409
-			if ( is_callable( array( $this, $function ) ) ) {
410
-				return $this->{$function}( $value );
411
-			}
412
-		}
413
-
414
-		$this->maybe_read_meta_data();
415
-		if ( $unique ) {
416
-			$this->delete_meta_data( $key );
417
-		}
418
-		$this->meta_data[] = new GetPaid_Meta_Data(
419
-			array(
420
-				'key'   => $key,
421
-				'value' => $value,
422
-			)
423
-		);
424
-	}
425
-
426
-	/**
427
-	 * Update meta data by key or ID, if provided.
428
-	 *
429
-	 * @since  1.0.19
430
-	 *
431
-	 * @param  string       $key Meta key.
432
-	 * @param  string|array $value Meta value.
433
-	 * @param  int          $meta_id Meta ID.
434
-	 */
435
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
436
-		if ( $this->is_internal_meta_key( $key ) ) {
437
-			$function = 'set_' . $key;
438
-
439
-			if ( is_callable( array( $this, $function ) ) ) {
440
-				return $this->{$function}( $value );
441
-			}
442
-		}
443
-
444
-		$this->maybe_read_meta_data();
445
-
446
-		$array_key = false;
447
-
448
-		if ( $meta_id ) {
449
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
450
-			$array_key  = $array_keys ? current( $array_keys ) : false;
451
-		} else {
452
-			// Find matches by key.
453
-			$matches = array();
454
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
455
-				if ( $meta->key === $key ) {
456
-					$matches[] = $meta_data_array_key;
457
-				}
458
-			}
459
-
460
-			if ( ! empty( $matches ) ) {
461
-				// Set matches to null so only one key gets the new value.
462
-				foreach ( $matches as $meta_data_array_key ) {
463
-					$this->meta_data[ $meta_data_array_key ]->value = null;
464
-				}
465
-				$array_key = current( $matches );
466
-			}
467
-		}
468
-
469
-		if ( false !== $array_key ) {
470
-			$meta        = $this->meta_data[ $array_key ];
471
-			$meta->key   = $key;
472
-			$meta->value = $value;
473
-		} else {
474
-			$this->add_meta_data( $key, $value, true );
475
-		}
476
-	}
477
-
478
-	/**
479
-	 * Delete meta data.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param string $key Meta key.
483
-	 */
484
-	public function delete_meta_data( $key ) {
485
-		$this->maybe_read_meta_data();
486
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
487
-
488
-		if ( $array_keys ) {
489
-			foreach ( $array_keys as $array_key ) {
490
-				$this->meta_data[ $array_key ]->value = null;
491
-			}
492
-		}
493
-	}
494
-
495
-	/**
496
-	 * Delete meta data.
497
-	 *
498
-	 * @since 1.0.19
499
-	 * @param int $mid Meta ID.
500
-	 */
501
-	public function delete_meta_data_by_mid( $mid ) {
502
-		$this->maybe_read_meta_data();
503
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
504
-
505
-		if ( $array_keys ) {
506
-			foreach ( $array_keys as $array_key ) {
507
-				$this->meta_data[ $array_key ]->value = null;
508
-			}
509
-		}
510
-	}
511
-
512
-	/**
513
-	 * Read meta data if null.
514
-	 *
515
-	 * @since 1.0.19
516
-	 */
517
-	protected function maybe_read_meta_data() {
518
-		if ( is_null( $this->meta_data ) ) {
519
-			$this->read_meta_data();
520
-		}
521
-	}
522
-
523
-	/**
524
-	 * Read Meta Data from the database. Ignore any internal properties.
525
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param bool $force_read True to force a new DB read (and update cache).
529
-	 */
530
-	public function read_meta_data( $force_read = false ) {
531
-		$this->meta_data = array();
532
-		$cache_loaded    = false;
533
-
534
-		if ( ! $this->get_id() ) {
535
-			return;
536
-		}
537
-
538
-		if ( ! $this->data_store ) {
539
-			return;
540
-		}
541
-
542
-		if ( ! empty( $this->cache_group ) ) {
543
-			// Prefix by group allows invalidation by group until https://core.trac.wordpress.org/ticket/4476 is implemented.
544
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
545
-		}
546
-
547
-		if ( ! $force_read ) {
548
-			if ( ! empty( $this->cache_group ) ) {
549
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
550
-				$cache_loaded = ! empty( $cached_meta );
551
-			}
552
-		}
553
-
554
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
555
-		if ( $raw_meta_data ) {
556
-			foreach ( $raw_meta_data as $meta ) {
557
-				$this->meta_data[] = new GetPaid_Meta_Data(
558
-					array(
559
-						'id'    => (int) $meta->meta_id,
560
-						'key'   => $meta->meta_key,
561
-						'value' => maybe_unserialize( $meta->meta_value ),
562
-					)
563
-				);
564
-			}
565
-
566
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
567
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
568
-			}
569
-		}
570
-	}
571
-
572
-	/**
573
-	 * Update Meta Data in the database.
574
-	 *
575
-	 * @since 1.0.19
576
-	 */
577
-	public function save_meta_data() {
578
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
579
-			return;
580
-		}
581
-		foreach ( $this->meta_data as $array_key => $meta ) {
582
-			if ( is_null( $meta->value ) ) {
583
-				if ( ! empty( $meta->id ) ) {
584
-					$this->data_store->delete_meta( $this, $meta );
585
-					unset( $this->meta_data[ $array_key ] );
586
-				}
587
-			} elseif ( empty( $meta->id ) ) {
588
-				$meta->id = $this->data_store->add_meta( $this, $meta );
589
-				$meta->apply_changes();
590
-			} else {
591
-				if ( $meta->get_changes() ) {
592
-					$this->data_store->update_meta( $this, $meta );
593
-					$meta->apply_changes();
594
-				}
595
-			}
596
-		}
597
-		if ( ! empty( $this->cache_group ) ) {
598
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
599
-			wp_cache_delete( $cache_key, $this->cache_group );
600
-		}
601
-	}
602
-
603
-	/**
604
-	 * Set ID.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param int $id ID.
608
-	 */
609
-	public function set_id( $id ) {
610
-		$this->id = absint( $id );
611
-	}
612
-
613
-	/**
614
-	 * Set all props to default values.
615
-	 *
616
-	 * @since 1.0.19
617
-	 */
618
-	public function set_defaults() {
619
-		$this->data    = $this->default_data;
620
-		$this->changes = array();
621
-		$this->set_object_read( false );
622
-	}
623
-
624
-	/**
625
-	 * Set object read property.
626
-	 *
627
-	 * @since 1.0.19
628
-	 * @param boolean $read Should read?.
629
-	 */
630
-	public function set_object_read( $read = true ) {
631
-		$this->object_read = (bool) $read;
632
-	}
633
-
634
-	/**
635
-	 * Get object read property.
636
-	 *
637
-	 * @since  1.0.19
638
-	 * @return boolean
639
-	 */
640
-	public function get_object_read() {
641
-		return (bool) $this->object_read;
642
-	}
643
-
644
-	/**
645
-	 * Set a collection of props in one go, collect any errors, and return the result.
646
-	 * Only sets using public methods.
647
-	 *
648
-	 * @since  1.0.19
649
-	 *
650
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
651
-	 * @param string $context In what context to run this.
652
-	 *
653
-	 * @return bool|WP_Error
654
-	 */
655
-	public function set_props( $props, $context = 'set' ) {
656
-		$errors = false;
657
-
658
-		foreach ( $props as $prop => $value ) {
659
-			try {
660
-				/**
661
-				 * Checks if the prop being set is allowed, and the value is not null.
662
-				 */
663
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
664
-					continue;
665
-				}
666
-				$setter = "set_$prop";
667
-
668
-				if ( is_callable( array( $this, $setter ) ) ) {
669
-					$this->{$setter}( $value );
670
-				}
671
-			} catch ( Exception $e ) {
672
-				if ( ! $errors ) {
673
-					$errors = new WP_Error();
674
-				}
675
-				$errors->add( $e->getCode(), $e->getMessage() );
676
-			}
677
-		}
678
-
679
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
680
-	}
681
-
682
-	/**
683
-	 * Sets a prop for a setter method.
684
-	 *
685
-	 * This stores changes in a special array so we can track what needs saving
686
-	 * the the DB later.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param string $prop Name of prop to set.
690
-	 * @param mixed  $value Value of the prop.
691
-	 */
692
-	protected function set_prop( $prop, $value ) {
693
-		if ( array_key_exists( $prop, $this->data ) ) {
694
-			if ( true === $this->object_read ) {
695
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
696
-					$this->changes[ $prop ] = $value;
697
-				}
698
-			} else {
699
-				$this->data[ $prop ] = $value;
700
-			}
701
-		}
702
-	}
703
-
704
-	/**
705
-	 * Return data changes only.
706
-	 *
707
-	 * @since 1.0.19
708
-	 * @return array
709
-	 */
710
-	public function get_changes() {
711
-		return $this->changes;
712
-	}
713
-
714
-	/**
715
-	 * Merge changes with data and clear.
716
-	 *
717
-	 * @since 1.0.19
718
-	 */
719
-	public function apply_changes() {
720
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
721
-		$this->changes = array();
722
-	}
723
-
724
-	/**
725
-	 * Prefix for action and filter hooks on data.
726
-	 *
727
-	 * @since  1.0.19
728
-	 * @return string
729
-	 */
730
-	protected function get_hook_prefix() {
731
-		return 'wpinv_get_' . $this->object_type . '_';
732
-	}
733
-
734
-	/**
735
-	 * Gets a prop for a getter method.
736
-	 *
737
-	 * Gets the value from either current pending changes, or the data itself.
738
-	 * Context controls what happens to the value before it's returned.
739
-	 *
740
-	 * @since  1.0.19
741
-	 * @param  string $prop Name of prop to get.
742
-	 * @param  string $context What the value is for. Valid values are view and edit.
743
-	 * @return mixed
744
-	 */
745
-	protected function get_prop( $prop, $context = 'view' ) {
746
-		$value = null;
747
-
748
-		if ( array_key_exists( $prop, $this->data ) ) {
749
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
750
-
751
-			if ( 'view' === $context ) {
752
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
753
-			}
754
-		}
755
-
756
-		return $value;
757
-	}
758
-
759
-	/**
760
-	 * Sets a date prop whilst handling formatting and datetime objects.
761
-	 *
762
-	 * @since 1.0.19
763
-	 * @param string         $prop Name of prop to set.
764
-	 * @param string|integer $value Value of the prop.
765
-	 */
766
-	protected function set_date_prop( $prop, $value ) {
767
-
768
-		if ( empty( $value ) ) {
769
-			$this->set_prop( $prop, null );
770
-			return;
771
-		}
772
-		$this->set_prop( $prop, $value );
773
-
774
-	}
775
-
776
-	/**
777
-	 * When invalid data is found, throw an exception unless reading from the DB.
778
-	 *
779
-	 * @throws Exception Data Exception.
780
-	 * @since 1.0.19
781
-	 * @param string $code             Error code.
782
-	 * @param string $message          Error message.
783
-	 */
784
-	protected function error( $code, $message ) {
785
-		throw new Exception( $message, $code );
786
-	}
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var object
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores additional meta data.
101
+     *
102
+     * @since 1.0.19
103
+     * @var array
104
+     */
105
+    protected $meta_data = null;
106
+
107
+    /**
108
+     * Default constructor.
109
+     *
110
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
111
+     */
112
+    public function __construct( $read = 0 ) {
113
+        $this->data         = array_merge( $this->data, $this->extra_data );
114
+        $this->default_data = $this->data;
115
+    }
116
+
117
+    /**
118
+     * Only store the object ID to avoid serializing the data object instance.
119
+     *
120
+     * @return array
121
+     */
122
+    public function __sleep() {
123
+        return array( 'id' );
124
+    }
125
+
126
+    /**
127
+     * Re-run the constructor with the object ID.
128
+     *
129
+     * If the object no longer exists, remove the ID.
130
+     */
131
+    public function __wakeup() {
132
+        try {
133
+            $this->__construct( absint( $this->id ) );
134
+        } catch ( Exception $e ) {
135
+            $this->set_id( 0 );
136
+            $this->set_object_read( true );
137
+        }
138
+    }
139
+
140
+    /**
141
+     * When the object is cloned, make sure meta is duplicated correctly.
142
+     *
143
+     * @since 1.0.19
144
+     */
145
+    public function __clone() {
146
+        $this->maybe_read_meta_data();
147
+        if ( ! empty( $this->meta_data ) ) {
148
+            foreach ( $this->meta_data as $array_key => $meta ) {
149
+                $this->meta_data[ $array_key ] = clone $meta;
150
+                if ( ! empty( $meta->id ) ) {
151
+                    $this->meta_data[ $array_key ]->id = null;
152
+                }
153
+            }
154
+        }
155
+    }
156
+
157
+    /**
158
+     * Get the data store.
159
+     *
160
+     * @since  1.0.19
161
+     * @return object
162
+     */
163
+    public function get_data_store() {
164
+        return $this->data_store;
165
+    }
166
+
167
+    /**
168
+     * Returns the unique ID for this object.
169
+     *
170
+     * @since  1.0.19
171
+     * @return int
172
+     */
173
+    public function get_id() {
174
+        return $this->id;
175
+    }
176
+
177
+    /**
178
+     * Delete an object, set the ID to 0, and return result.
179
+     *
180
+     * @since  1.0.19
181
+     * @param  bool $force_delete Should the data be deleted permanently.
182
+     * @return bool result
183
+     */
184
+    public function delete( $force_delete = false ) {
185
+        if ( $this->data_store ) {
186
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
187
+            $this->set_id( 0 );
188
+            return true;
189
+        }
190
+        return false;
191
+    }
192
+
193
+    /**
194
+     * Save should create or update based on object existence.
195
+     *
196
+     * @since  1.0.19
197
+     * @return int
198
+     */
199
+    public function save() {
200
+        if ( ! $this->data_store ) {
201
+            return $this->get_id();
202
+        }
203
+
204
+        /**
205
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
206
+         *
207
+         * @param GetPaid_Data          $this The object being saved.
208
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
209
+         */
210
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
211
+
212
+        if ( $this->get_id() ) {
213
+            $this->data_store->update( $this );
214
+        } else {
215
+            $this->data_store->create( $this );
216
+        }
217
+
218
+        /**
219
+         * Trigger action after saving to the DB.
220
+         *
221
+         * @param GetPaid_Data          $this The object being saved.
222
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
223
+         */
224
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
225
+
226
+        return $this->get_id();
227
+    }
228
+
229
+    /**
230
+     * Change data to JSON format.
231
+     *
232
+     * @since  1.0.19
233
+     * @return string Data in JSON format.
234
+     */
235
+    public function __toString() {
236
+        return wp_json_encode( $this->get_data() );
237
+    }
238
+
239
+    /**
240
+     * Returns all data for this object.
241
+     *
242
+     * @since  1.0.19
243
+     * @return array
244
+     */
245
+    public function get_data() {
246
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
247
+    }
248
+
249
+    /**
250
+     * Returns array of expected data keys for this object.
251
+     *
252
+     * @since   1.0.19
253
+     * @return array
254
+     */
255
+    public function get_data_keys() {
256
+        return array_keys( $this->data );
257
+    }
258
+
259
+    /**
260
+     * Returns all "extra" data keys for an object (for sub objects like item types).
261
+     *
262
+     * @since  1.0.19
263
+     * @return array
264
+     */
265
+    public function get_extra_data_keys() {
266
+        return array_keys( $this->extra_data );
267
+    }
268
+
269
+    /**
270
+     * Filter null meta values from array.
271
+     *
272
+     * @since  1.0.19
273
+     * @param mixed $meta Meta value to check.
274
+     * @return bool
275
+     */
276
+    protected function filter_null_meta( $meta ) {
277
+        return ! is_null( $meta->value );
278
+    }
279
+
280
+    /**
281
+     * Get All Meta Data.
282
+     *
283
+     * @since 1.0.19
284
+     * @return array of objects.
285
+     */
286
+    public function get_meta_data() {
287
+        $this->maybe_read_meta_data();
288
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
289
+    }
290
+
291
+    /**
292
+     * Check if the key is an internal one.
293
+     *
294
+     * @since  1.0.19
295
+     * @param  string $key Key to check.
296
+     * @return bool   true if it's an internal key, false otherwise
297
+     */
298
+    protected function is_internal_meta_key( $key ) {
299
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
300
+
301
+        if ( ! $internal_meta_key ) {
302
+            return false;
303
+        }
304
+
305
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
306
+
307
+        if ( ! $has_setter_or_getter ) {
308
+            return false;
309
+        }
310
+
311
+        /* translators: %s: $key Key to check */
312
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
313
+
314
+        return true;
315
+    }
316
+
317
+    /**
318
+     * Get Meta Data by Key.
319
+     *
320
+     * @since  1.0.19
321
+     * @param  string $key Meta Key.
322
+     * @param  bool   $single return first found meta with key, or all with $key.
323
+     * @param  string $context What the value is for. Valid values are view and edit.
324
+     * @return mixed
325
+     */
326
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
327
+
328
+        // Check if this is an internal meta key.
329
+        if ( $this->is_internal_meta_key( $key ) ) {
330
+            $function = 'get_' . $key;
331
+
332
+            if ( is_callable( array( $this, $function ) ) ) {
333
+                return $this->{$function}();
334
+            }
335
+        }
336
+
337
+        // Read the meta data if not yet read.
338
+        $this->maybe_read_meta_data();
339
+        $meta_data  = $this->get_meta_data();
340
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
341
+        $value      = $single ? '' : array();
342
+
343
+        if ( ! empty( $array_keys ) ) {
344
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
345
+            if ( $single ) {
346
+                $value = $meta_data[ current( $array_keys ) ]->value;
347
+            } else {
348
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
349
+            }
350
+        }
351
+
352
+        if ( 'view' === $context ) {
353
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
354
+        }
355
+
356
+        return $value;
357
+    }
358
+
359
+    /**
360
+     * See if meta data exists, since get_meta always returns a '' or array().
361
+     *
362
+     * @since  1.0.19
363
+     * @param  string $key Meta Key.
364
+     * @return boolean
365
+     */
366
+    public function meta_exists( $key = '' ) {
367
+        $this->maybe_read_meta_data();
368
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
369
+        return in_array( $key, $array_keys, true );
370
+    }
371
+
372
+    /**
373
+     * Set all meta data from array.
374
+     *
375
+     * @since 1.0.19
376
+     * @param array $data Key/Value pairs.
377
+     */
378
+    public function set_meta_data( $data ) {
379
+        if ( ! empty( $data ) && is_array( $data ) ) {
380
+            $this->maybe_read_meta_data();
381
+            foreach ( $data as $meta ) {
382
+                $meta = (array) $meta;
383
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
384
+                    $this->meta_data[] = new GetPaid_Meta_Data(
385
+                        array(
386
+                            'id'    => $meta['id'],
387
+                            'key'   => $meta['key'],
388
+                            'value' => $meta['value'],
389
+                        )
390
+                    );
391
+                }
392
+            }
393
+        }
394
+    }
395
+
396
+    /**
397
+     * Add meta data.
398
+     *
399
+     * @since 1.0.19
400
+     *
401
+     * @param string       $key Meta key.
402
+     * @param string|array $value Meta value.
403
+     * @param bool         $unique Should this be a unique key?.
404
+     */
405
+    public function add_meta_data( $key, $value, $unique = false ) {
406
+        if ( $this->is_internal_meta_key( $key ) ) {
407
+            $function = 'set_' . $key;
408
+
409
+            if ( is_callable( array( $this, $function ) ) ) {
410
+                return $this->{$function}( $value );
411
+            }
412
+        }
413
+
414
+        $this->maybe_read_meta_data();
415
+        if ( $unique ) {
416
+            $this->delete_meta_data( $key );
417
+        }
418
+        $this->meta_data[] = new GetPaid_Meta_Data(
419
+            array(
420
+                'key'   => $key,
421
+                'value' => $value,
422
+            )
423
+        );
424
+    }
425
+
426
+    /**
427
+     * Update meta data by key or ID, if provided.
428
+     *
429
+     * @since  1.0.19
430
+     *
431
+     * @param  string       $key Meta key.
432
+     * @param  string|array $value Meta value.
433
+     * @param  int          $meta_id Meta ID.
434
+     */
435
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
436
+        if ( $this->is_internal_meta_key( $key ) ) {
437
+            $function = 'set_' . $key;
438
+
439
+            if ( is_callable( array( $this, $function ) ) ) {
440
+                return $this->{$function}( $value );
441
+            }
442
+        }
443
+
444
+        $this->maybe_read_meta_data();
445
+
446
+        $array_key = false;
447
+
448
+        if ( $meta_id ) {
449
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
450
+            $array_key  = $array_keys ? current( $array_keys ) : false;
451
+        } else {
452
+            // Find matches by key.
453
+            $matches = array();
454
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
455
+                if ( $meta->key === $key ) {
456
+                    $matches[] = $meta_data_array_key;
457
+                }
458
+            }
459
+
460
+            if ( ! empty( $matches ) ) {
461
+                // Set matches to null so only one key gets the new value.
462
+                foreach ( $matches as $meta_data_array_key ) {
463
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
464
+                }
465
+                $array_key = current( $matches );
466
+            }
467
+        }
468
+
469
+        if ( false !== $array_key ) {
470
+            $meta        = $this->meta_data[ $array_key ];
471
+            $meta->key   = $key;
472
+            $meta->value = $value;
473
+        } else {
474
+            $this->add_meta_data( $key, $value, true );
475
+        }
476
+    }
477
+
478
+    /**
479
+     * Delete meta data.
480
+     *
481
+     * @since 1.0.19
482
+     * @param string $key Meta key.
483
+     */
484
+    public function delete_meta_data( $key ) {
485
+        $this->maybe_read_meta_data();
486
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
487
+
488
+        if ( $array_keys ) {
489
+            foreach ( $array_keys as $array_key ) {
490
+                $this->meta_data[ $array_key ]->value = null;
491
+            }
492
+        }
493
+    }
494
+
495
+    /**
496
+     * Delete meta data.
497
+     *
498
+     * @since 1.0.19
499
+     * @param int $mid Meta ID.
500
+     */
501
+    public function delete_meta_data_by_mid( $mid ) {
502
+        $this->maybe_read_meta_data();
503
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
504
+
505
+        if ( $array_keys ) {
506
+            foreach ( $array_keys as $array_key ) {
507
+                $this->meta_data[ $array_key ]->value = null;
508
+            }
509
+        }
510
+    }
511
+
512
+    /**
513
+     * Read meta data if null.
514
+     *
515
+     * @since 1.0.19
516
+     */
517
+    protected function maybe_read_meta_data() {
518
+        if ( is_null( $this->meta_data ) ) {
519
+            $this->read_meta_data();
520
+        }
521
+    }
522
+
523
+    /**
524
+     * Read Meta Data from the database. Ignore any internal properties.
525
+     * Uses it's own caches because get_metadata does not provide meta_ids.
526
+     *
527
+     * @since 1.0.19
528
+     * @param bool $force_read True to force a new DB read (and update cache).
529
+     */
530
+    public function read_meta_data( $force_read = false ) {
531
+        $this->meta_data = array();
532
+        $cache_loaded    = false;
533
+
534
+        if ( ! $this->get_id() ) {
535
+            return;
536
+        }
537
+
538
+        if ( ! $this->data_store ) {
539
+            return;
540
+        }
541
+
542
+        if ( ! empty( $this->cache_group ) ) {
543
+            // Prefix by group allows invalidation by group until https://core.trac.wordpress.org/ticket/4476 is implemented.
544
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
545
+        }
546
+
547
+        if ( ! $force_read ) {
548
+            if ( ! empty( $this->cache_group ) ) {
549
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
550
+                $cache_loaded = ! empty( $cached_meta );
551
+            }
552
+        }
553
+
554
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
555
+        if ( $raw_meta_data ) {
556
+            foreach ( $raw_meta_data as $meta ) {
557
+                $this->meta_data[] = new GetPaid_Meta_Data(
558
+                    array(
559
+                        'id'    => (int) $meta->meta_id,
560
+                        'key'   => $meta->meta_key,
561
+                        'value' => maybe_unserialize( $meta->meta_value ),
562
+                    )
563
+                );
564
+            }
565
+
566
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
567
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
568
+            }
569
+        }
570
+    }
571
+
572
+    /**
573
+     * Update Meta Data in the database.
574
+     *
575
+     * @since 1.0.19
576
+     */
577
+    public function save_meta_data() {
578
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
579
+            return;
580
+        }
581
+        foreach ( $this->meta_data as $array_key => $meta ) {
582
+            if ( is_null( $meta->value ) ) {
583
+                if ( ! empty( $meta->id ) ) {
584
+                    $this->data_store->delete_meta( $this, $meta );
585
+                    unset( $this->meta_data[ $array_key ] );
586
+                }
587
+            } elseif ( empty( $meta->id ) ) {
588
+                $meta->id = $this->data_store->add_meta( $this, $meta );
589
+                $meta->apply_changes();
590
+            } else {
591
+                if ( $meta->get_changes() ) {
592
+                    $this->data_store->update_meta( $this, $meta );
593
+                    $meta->apply_changes();
594
+                }
595
+            }
596
+        }
597
+        if ( ! empty( $this->cache_group ) ) {
598
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
599
+            wp_cache_delete( $cache_key, $this->cache_group );
600
+        }
601
+    }
602
+
603
+    /**
604
+     * Set ID.
605
+     *
606
+     * @since 1.0.19
607
+     * @param int $id ID.
608
+     */
609
+    public function set_id( $id ) {
610
+        $this->id = absint( $id );
611
+    }
612
+
613
+    /**
614
+     * Set all props to default values.
615
+     *
616
+     * @since 1.0.19
617
+     */
618
+    public function set_defaults() {
619
+        $this->data    = $this->default_data;
620
+        $this->changes = array();
621
+        $this->set_object_read( false );
622
+    }
623
+
624
+    /**
625
+     * Set object read property.
626
+     *
627
+     * @since 1.0.19
628
+     * @param boolean $read Should read?.
629
+     */
630
+    public function set_object_read( $read = true ) {
631
+        $this->object_read = (bool) $read;
632
+    }
633
+
634
+    /**
635
+     * Get object read property.
636
+     *
637
+     * @since  1.0.19
638
+     * @return boolean
639
+     */
640
+    public function get_object_read() {
641
+        return (bool) $this->object_read;
642
+    }
643
+
644
+    /**
645
+     * Set a collection of props in one go, collect any errors, and return the result.
646
+     * Only sets using public methods.
647
+     *
648
+     * @since  1.0.19
649
+     *
650
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
651
+     * @param string $context In what context to run this.
652
+     *
653
+     * @return bool|WP_Error
654
+     */
655
+    public function set_props( $props, $context = 'set' ) {
656
+        $errors = false;
657
+
658
+        foreach ( $props as $prop => $value ) {
659
+            try {
660
+                /**
661
+                 * Checks if the prop being set is allowed, and the value is not null.
662
+                 */
663
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
664
+                    continue;
665
+                }
666
+                $setter = "set_$prop";
667
+
668
+                if ( is_callable( array( $this, $setter ) ) ) {
669
+                    $this->{$setter}( $value );
670
+                }
671
+            } catch ( Exception $e ) {
672
+                if ( ! $errors ) {
673
+                    $errors = new WP_Error();
674
+                }
675
+                $errors->add( $e->getCode(), $e->getMessage() );
676
+            }
677
+        }
678
+
679
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
680
+    }
681
+
682
+    /**
683
+     * Sets a prop for a setter method.
684
+     *
685
+     * This stores changes in a special array so we can track what needs saving
686
+     * the the DB later.
687
+     *
688
+     * @since 1.0.19
689
+     * @param string $prop Name of prop to set.
690
+     * @param mixed  $value Value of the prop.
691
+     */
692
+    protected function set_prop( $prop, $value ) {
693
+        if ( array_key_exists( $prop, $this->data ) ) {
694
+            if ( true === $this->object_read ) {
695
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
696
+                    $this->changes[ $prop ] = $value;
697
+                }
698
+            } else {
699
+                $this->data[ $prop ] = $value;
700
+            }
701
+        }
702
+    }
703
+
704
+    /**
705
+     * Return data changes only.
706
+     *
707
+     * @since 1.0.19
708
+     * @return array
709
+     */
710
+    public function get_changes() {
711
+        return $this->changes;
712
+    }
713
+
714
+    /**
715
+     * Merge changes with data and clear.
716
+     *
717
+     * @since 1.0.19
718
+     */
719
+    public function apply_changes() {
720
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
721
+        $this->changes = array();
722
+    }
723
+
724
+    /**
725
+     * Prefix for action and filter hooks on data.
726
+     *
727
+     * @since  1.0.19
728
+     * @return string
729
+     */
730
+    protected function get_hook_prefix() {
731
+        return 'wpinv_get_' . $this->object_type . '_';
732
+    }
733
+
734
+    /**
735
+     * Gets a prop for a getter method.
736
+     *
737
+     * Gets the value from either current pending changes, or the data itself.
738
+     * Context controls what happens to the value before it's returned.
739
+     *
740
+     * @since  1.0.19
741
+     * @param  string $prop Name of prop to get.
742
+     * @param  string $context What the value is for. Valid values are view and edit.
743
+     * @return mixed
744
+     */
745
+    protected function get_prop( $prop, $context = 'view' ) {
746
+        $value = null;
747
+
748
+        if ( array_key_exists( $prop, $this->data ) ) {
749
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
750
+
751
+            if ( 'view' === $context ) {
752
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
753
+            }
754
+        }
755
+
756
+        return $value;
757
+    }
758
+
759
+    /**
760
+     * Sets a date prop whilst handling formatting and datetime objects.
761
+     *
762
+     * @since 1.0.19
763
+     * @param string         $prop Name of prop to set.
764
+     * @param string|integer $value Value of the prop.
765
+     */
766
+    protected function set_date_prop( $prop, $value ) {
767
+
768
+        if ( empty( $value ) ) {
769
+            $this->set_prop( $prop, null );
770
+            return;
771
+        }
772
+        $this->set_prop( $prop, $value );
773
+
774
+    }
775
+
776
+    /**
777
+     * When invalid data is found, throw an exception unless reading from the DB.
778
+     *
779
+     * @throws Exception Data Exception.
780
+     * @since 1.0.19
781
+     * @param string $code             Error code.
782
+     * @param string $message          Error message.
783
+     */
784
+    protected function error( $code, $message ) {
785
+        throw new Exception( $message, $code );
786
+    }
787 787
 }
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
 	 *
110 110
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
111 111
 	 */
112
-	public function __construct( $read = 0 ) {
113
-		$this->data         = array_merge( $this->data, $this->extra_data );
112
+	public function __construct($read = 0) {
113
+		$this->data         = array_merge($this->data, $this->extra_data);
114 114
 		$this->default_data = $this->data;
115 115
 	}
116 116
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 	 * @return array
121 121
 	 */
122 122
 	public function __sleep() {
123
-		return array( 'id' );
123
+		return array('id');
124 124
 	}
125 125
 
126 126
 	/**
@@ -130,10 +130,10 @@  discard block
 block discarded – undo
130 130
 	 */
131 131
 	public function __wakeup() {
132 132
 		try {
133
-			$this->__construct( absint( $this->id ) );
134
-		} catch ( Exception $e ) {
135
-			$this->set_id( 0 );
136
-			$this->set_object_read( true );
133
+			$this->__construct(absint($this->id));
134
+		} catch (Exception $e) {
135
+			$this->set_id(0);
136
+			$this->set_object_read(true);
137 137
 		}
138 138
 	}
139 139
 
@@ -144,11 +144,11 @@  discard block
 block discarded – undo
144 144
 	 */
145 145
 	public function __clone() {
146 146
 		$this->maybe_read_meta_data();
147
-		if ( ! empty( $this->meta_data ) ) {
148
-			foreach ( $this->meta_data as $array_key => $meta ) {
149
-				$this->meta_data[ $array_key ] = clone $meta;
150
-				if ( ! empty( $meta->id ) ) {
151
-					$this->meta_data[ $array_key ]->id = null;
147
+		if (!empty($this->meta_data)) {
148
+			foreach ($this->meta_data as $array_key => $meta) {
149
+				$this->meta_data[$array_key] = clone $meta;
150
+				if (!empty($meta->id)) {
151
+					$this->meta_data[$array_key]->id = null;
152 152
 				}
153 153
 			}
154 154
 		}
@@ -181,10 +181,10 @@  discard block
 block discarded – undo
181 181
 	 * @param  bool $force_delete Should the data be deleted permanently.
182 182
 	 * @return bool result
183 183
 	 */
184
-	public function delete( $force_delete = false ) {
185
-		if ( $this->data_store ) {
186
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
187
-			$this->set_id( 0 );
184
+	public function delete($force_delete = false) {
185
+		if ($this->data_store) {
186
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
187
+			$this->set_id(0);
188 188
 			return true;
189 189
 		}
190 190
 		return false;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
 	 * @return int
198 198
 	 */
199 199
 	public function save() {
200
-		if ( ! $this->data_store ) {
200
+		if (!$this->data_store) {
201 201
 			return $this->get_id();
202 202
 		}
203 203
 
@@ -207,12 +207,12 @@  discard block
 block discarded – undo
207 207
 		 * @param GetPaid_Data          $this The object being saved.
208 208
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
209 209
 		 */
210
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
210
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
211 211
 
212
-		if ( $this->get_id() ) {
213
-			$this->data_store->update( $this );
212
+		if ($this->get_id()) {
213
+			$this->data_store->update($this);
214 214
 		} else {
215
-			$this->data_store->create( $this );
215
+			$this->data_store->create($this);
216 216
 		}
217 217
 
218 218
 		/**
@@ -221,7 +221,7 @@  discard block
 block discarded – undo
221 221
 		 * @param GetPaid_Data          $this The object being saved.
222 222
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
223 223
 		 */
224
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
224
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
225 225
 
226 226
 		return $this->get_id();
227 227
 	}
@@ -233,7 +233,7 @@  discard block
 block discarded – undo
233 233
 	 * @return string Data in JSON format.
234 234
 	 */
235 235
 	public function __toString() {
236
-		return wp_json_encode( $this->get_data() );
236
+		return wp_json_encode($this->get_data());
237 237
 	}
238 238
 
239 239
 	/**
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
 	 * @return array
244 244
 	 */
245 245
 	public function get_data() {
246
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
246
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
247 247
 	}
248 248
 
249 249
 	/**
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
 	 * @return array
254 254
 	 */
255 255
 	public function get_data_keys() {
256
-		return array_keys( $this->data );
256
+		return array_keys($this->data);
257 257
 	}
258 258
 
259 259
 	/**
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 	 * @return array
264 264
 	 */
265 265
 	public function get_extra_data_keys() {
266
-		return array_keys( $this->extra_data );
266
+		return array_keys($this->extra_data);
267 267
 	}
268 268
 
269 269
 	/**
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @param mixed $meta Meta value to check.
274 274
 	 * @return bool
275 275
 	 */
276
-	protected function filter_null_meta( $meta ) {
277
-		return ! is_null( $meta->value );
276
+	protected function filter_null_meta($meta) {
277
+		return !is_null($meta->value);
278 278
 	}
279 279
 
280 280
 	/**
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 	 */
286 286
 	public function get_meta_data() {
287 287
 		$this->maybe_read_meta_data();
288
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
288
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
289 289
 	}
290 290
 
291 291
 	/**
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
 	 * @param  string $key Key to check.
296 296
 	 * @return bool   true if it's an internal key, false otherwise
297 297
 	 */
298
-	protected function is_internal_meta_key( $key ) {
299
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
298
+	protected function is_internal_meta_key($key) {
299
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
300 300
 
301
-		if ( ! $internal_meta_key ) {
301
+		if (!$internal_meta_key) {
302 302
 			return false;
303 303
 		}
304 304
 
305
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
305
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
306 306
 
307
-		if ( ! $has_setter_or_getter ) {
307
+		if (!$has_setter_or_getter) {
308 308
 			return false;
309 309
 		}
310 310
 
311 311
 		/* translators: %s: $key Key to check */
312
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
312
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
313 313
 
314 314
 		return true;
315 315
 	}
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context What the value is for. Valid values are view and edit.
324 324
 	 * @return mixed
325 325
 	 */
326
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
326
+	public function get_meta($key = '', $single = true, $context = 'view') {
327 327
 
328 328
 		// Check if this is an internal meta key.
329
-		if ( $this->is_internal_meta_key( $key ) ) {
329
+		if ($this->is_internal_meta_key($key)) {
330 330
 			$function = 'get_' . $key;
331 331
 
332
-			if ( is_callable( array( $this, $function ) ) ) {
332
+			if (is_callable(array($this, $function))) {
333 333
 				return $this->{$function}();
334 334
 			}
335 335
 		}
@@ -337,20 +337,20 @@  discard block
 block discarded – undo
337 337
 		// Read the meta data if not yet read.
338 338
 		$this->maybe_read_meta_data();
339 339
 		$meta_data  = $this->get_meta_data();
340
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
340
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
341 341
 		$value      = $single ? '' : array();
342 342
 
343
-		if ( ! empty( $array_keys ) ) {
343
+		if (!empty($array_keys)) {
344 344
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
345
-			if ( $single ) {
346
-				$value = $meta_data[ current( $array_keys ) ]->value;
345
+			if ($single) {
346
+				$value = $meta_data[current($array_keys)]->value;
347 347
 			} else {
348
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
348
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
349 349
 			}
350 350
 		}
351 351
 
352
-		if ( 'view' === $context ) {
353
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
352
+		if ('view' === $context) {
353
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
354 354
 		}
355 355
 
356 356
 		return $value;
@@ -363,10 +363,10 @@  discard block
 block discarded – undo
363 363
 	 * @param  string $key Meta Key.
364 364
 	 * @return boolean
365 365
 	 */
366
-	public function meta_exists( $key = '' ) {
366
+	public function meta_exists($key = '') {
367 367
 		$this->maybe_read_meta_data();
368
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
369
-		return in_array( $key, $array_keys, true );
368
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
369
+		return in_array($key, $array_keys, true);
370 370
 	}
371 371
 
372 372
 	/**
@@ -375,12 +375,12 @@  discard block
 block discarded – undo
375 375
 	 * @since 1.0.19
376 376
 	 * @param array $data Key/Value pairs.
377 377
 	 */
378
-	public function set_meta_data( $data ) {
379
-		if ( ! empty( $data ) && is_array( $data ) ) {
378
+	public function set_meta_data($data) {
379
+		if (!empty($data) && is_array($data)) {
380 380
 			$this->maybe_read_meta_data();
381
-			foreach ( $data as $meta ) {
381
+			foreach ($data as $meta) {
382 382
 				$meta = (array) $meta;
383
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
383
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
384 384
 					$this->meta_data[] = new GetPaid_Meta_Data(
385 385
 						array(
386 386
 							'id'    => $meta['id'],
@@ -402,18 +402,18 @@  discard block
 block discarded – undo
402 402
 	 * @param string|array $value Meta value.
403 403
 	 * @param bool         $unique Should this be a unique key?.
404 404
 	 */
405
-	public function add_meta_data( $key, $value, $unique = false ) {
406
-		if ( $this->is_internal_meta_key( $key ) ) {
405
+	public function add_meta_data($key, $value, $unique = false) {
406
+		if ($this->is_internal_meta_key($key)) {
407 407
 			$function = 'set_' . $key;
408 408
 
409
-			if ( is_callable( array( $this, $function ) ) ) {
410
-				return $this->{$function}( $value );
409
+			if (is_callable(array($this, $function))) {
410
+				return $this->{$function}($value);
411 411
 			}
412 412
 		}
413 413
 
414 414
 		$this->maybe_read_meta_data();
415
-		if ( $unique ) {
416
-			$this->delete_meta_data( $key );
415
+		if ($unique) {
416
+			$this->delete_meta_data($key);
417 417
 		}
418 418
 		$this->meta_data[] = new GetPaid_Meta_Data(
419 419
 			array(
@@ -432,12 +432,12 @@  discard block
 block discarded – undo
432 432
 	 * @param  string|array $value Meta value.
433 433
 	 * @param  int          $meta_id Meta ID.
434 434
 	 */
435
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
436
-		if ( $this->is_internal_meta_key( $key ) ) {
435
+	public function update_meta_data($key, $value, $meta_id = 0) {
436
+		if ($this->is_internal_meta_key($key)) {
437 437
 			$function = 'set_' . $key;
438 438
 
439
-			if ( is_callable( array( $this, $function ) ) ) {
440
-				return $this->{$function}( $value );
439
+			if (is_callable(array($this, $function))) {
440
+				return $this->{$function}($value);
441 441
 			}
442 442
 		}
443 443
 
@@ -445,33 +445,33 @@  discard block
 block discarded – undo
445 445
 
446 446
 		$array_key = false;
447 447
 
448
-		if ( $meta_id ) {
449
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
450
-			$array_key  = $array_keys ? current( $array_keys ) : false;
448
+		if ($meta_id) {
449
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
450
+			$array_key  = $array_keys ? current($array_keys) : false;
451 451
 		} else {
452 452
 			// Find matches by key.
453 453
 			$matches = array();
454
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
455
-				if ( $meta->key === $key ) {
454
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
455
+				if ($meta->key === $key) {
456 456
 					$matches[] = $meta_data_array_key;
457 457
 				}
458 458
 			}
459 459
 
460
-			if ( ! empty( $matches ) ) {
460
+			if (!empty($matches)) {
461 461
 				// Set matches to null so only one key gets the new value.
462
-				foreach ( $matches as $meta_data_array_key ) {
463
-					$this->meta_data[ $meta_data_array_key ]->value = null;
462
+				foreach ($matches as $meta_data_array_key) {
463
+					$this->meta_data[$meta_data_array_key]->value = null;
464 464
 				}
465
-				$array_key = current( $matches );
465
+				$array_key = current($matches);
466 466
 			}
467 467
 		}
468 468
 
469
-		if ( false !== $array_key ) {
470
-			$meta        = $this->meta_data[ $array_key ];
469
+		if (false !== $array_key) {
470
+			$meta        = $this->meta_data[$array_key];
471 471
 			$meta->key   = $key;
472 472
 			$meta->value = $value;
473 473
 		} else {
474
-			$this->add_meta_data( $key, $value, true );
474
+			$this->add_meta_data($key, $value, true);
475 475
 		}
476 476
 	}
477 477
 
@@ -481,13 +481,13 @@  discard block
 block discarded – undo
481 481
 	 * @since 1.0.19
482 482
 	 * @param string $key Meta key.
483 483
 	 */
484
-	public function delete_meta_data( $key ) {
484
+	public function delete_meta_data($key) {
485 485
 		$this->maybe_read_meta_data();
486
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
486
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
487 487
 
488
-		if ( $array_keys ) {
489
-			foreach ( $array_keys as $array_key ) {
490
-				$this->meta_data[ $array_key ]->value = null;
488
+		if ($array_keys) {
489
+			foreach ($array_keys as $array_key) {
490
+				$this->meta_data[$array_key]->value = null;
491 491
 			}
492 492
 		}
493 493
 	}
@@ -498,13 +498,13 @@  discard block
 block discarded – undo
498 498
 	 * @since 1.0.19
499 499
 	 * @param int $mid Meta ID.
500 500
 	 */
501
-	public function delete_meta_data_by_mid( $mid ) {
501
+	public function delete_meta_data_by_mid($mid) {
502 502
 		$this->maybe_read_meta_data();
503
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
503
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
504 504
 
505
-		if ( $array_keys ) {
506
-			foreach ( $array_keys as $array_key ) {
507
-				$this->meta_data[ $array_key ]->value = null;
505
+		if ($array_keys) {
506
+			foreach ($array_keys as $array_key) {
507
+				$this->meta_data[$array_key]->value = null;
508 508
 			}
509 509
 		}
510 510
 	}
@@ -515,7 +515,7 @@  discard block
 block discarded – undo
515 515
 	 * @since 1.0.19
516 516
 	 */
517 517
 	protected function maybe_read_meta_data() {
518
-		if ( is_null( $this->meta_data ) ) {
518
+		if (is_null($this->meta_data)) {
519 519
 			$this->read_meta_data();
520 520
 		}
521 521
 	}
@@ -527,44 +527,44 @@  discard block
 block discarded – undo
527 527
 	 * @since 1.0.19
528 528
 	 * @param bool $force_read True to force a new DB read (and update cache).
529 529
 	 */
530
-	public function read_meta_data( $force_read = false ) {
530
+	public function read_meta_data($force_read = false) {
531 531
 		$this->meta_data = array();
532 532
 		$cache_loaded    = false;
533 533
 
534
-		if ( ! $this->get_id() ) {
534
+		if (!$this->get_id()) {
535 535
 			return;
536 536
 		}
537 537
 
538
-		if ( ! $this->data_store ) {
538
+		if (!$this->data_store) {
539 539
 			return;
540 540
 		}
541 541
 
542
-		if ( ! empty( $this->cache_group ) ) {
542
+		if (!empty($this->cache_group)) {
543 543
 			// Prefix by group allows invalidation by group until https://core.trac.wordpress.org/ticket/4476 is implemented.
544
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
544
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
545 545
 		}
546 546
 
547
-		if ( ! $force_read ) {
548
-			if ( ! empty( $this->cache_group ) ) {
549
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
550
-				$cache_loaded = ! empty( $cached_meta );
547
+		if (!$force_read) {
548
+			if (!empty($this->cache_group)) {
549
+				$cached_meta  = wp_cache_get($cache_key, $this->cache_group);
550
+				$cache_loaded = !empty($cached_meta);
551 551
 			}
552 552
 		}
553 553
 
554
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
555
-		if ( $raw_meta_data ) {
556
-			foreach ( $raw_meta_data as $meta ) {
554
+		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this);
555
+		if ($raw_meta_data) {
556
+			foreach ($raw_meta_data as $meta) {
557 557
 				$this->meta_data[] = new GetPaid_Meta_Data(
558 558
 					array(
559 559
 						'id'    => (int) $meta->meta_id,
560 560
 						'key'   => $meta->meta_key,
561
-						'value' => maybe_unserialize( $meta->meta_value ),
561
+						'value' => maybe_unserialize($meta->meta_value),
562 562
 					)
563 563
 				);
564 564
 			}
565 565
 
566
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
567
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
566
+			if (!$cache_loaded && !empty($this->cache_group)) {
567
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
568 568
 			}
569 569
 		}
570 570
 	}
@@ -575,28 +575,28 @@  discard block
 block discarded – undo
575 575
 	 * @since 1.0.19
576 576
 	 */
577 577
 	public function save_meta_data() {
578
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
578
+		if (!$this->data_store || is_null($this->meta_data)) {
579 579
 			return;
580 580
 		}
581
-		foreach ( $this->meta_data as $array_key => $meta ) {
582
-			if ( is_null( $meta->value ) ) {
583
-				if ( ! empty( $meta->id ) ) {
584
-					$this->data_store->delete_meta( $this, $meta );
585
-					unset( $this->meta_data[ $array_key ] );
581
+		foreach ($this->meta_data as $array_key => $meta) {
582
+			if (is_null($meta->value)) {
583
+				if (!empty($meta->id)) {
584
+					$this->data_store->delete_meta($this, $meta);
585
+					unset($this->meta_data[$array_key]);
586 586
 				}
587
-			} elseif ( empty( $meta->id ) ) {
588
-				$meta->id = $this->data_store->add_meta( $this, $meta );
587
+			} elseif (empty($meta->id)) {
588
+				$meta->id = $this->data_store->add_meta($this, $meta);
589 589
 				$meta->apply_changes();
590 590
 			} else {
591
-				if ( $meta->get_changes() ) {
592
-					$this->data_store->update_meta( $this, $meta );
591
+				if ($meta->get_changes()) {
592
+					$this->data_store->update_meta($this, $meta);
593 593
 					$meta->apply_changes();
594 594
 				}
595 595
 			}
596 596
 		}
597
-		if ( ! empty( $this->cache_group ) ) {
598
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
599
-			wp_cache_delete( $cache_key, $this->cache_group );
597
+		if (!empty($this->cache_group)) {
598
+			$cache_key = GetPaid_Cache_Helper::get_cache_prefix($this->cache_group) . GetPaid_Cache_Helper::get_cache_prefix('object_' . $this->get_id()) . 'object_meta_' . $this->get_id();
599
+			wp_cache_delete($cache_key, $this->cache_group);
600 600
 		}
601 601
 	}
602 602
 
@@ -606,8 +606,8 @@  discard block
 block discarded – undo
606 606
 	 * @since 1.0.19
607 607
 	 * @param int $id ID.
608 608
 	 */
609
-	public function set_id( $id ) {
610
-		$this->id = absint( $id );
609
+	public function set_id($id) {
610
+		$this->id = absint($id);
611 611
 	}
612 612
 
613 613
 	/**
@@ -618,7 +618,7 @@  discard block
 block discarded – undo
618 618
 	public function set_defaults() {
619 619
 		$this->data    = $this->default_data;
620 620
 		$this->changes = array();
621
-		$this->set_object_read( false );
621
+		$this->set_object_read(false);
622 622
 	}
623 623
 
624 624
 	/**
@@ -627,7 +627,7 @@  discard block
 block discarded – undo
627 627
 	 * @since 1.0.19
628 628
 	 * @param boolean $read Should read?.
629 629
 	 */
630
-	public function set_object_read( $read = true ) {
630
+	public function set_object_read($read = true) {
631 631
 		$this->object_read = (bool) $read;
632 632
 	}
633 633
 
@@ -652,31 +652,31 @@  discard block
 block discarded – undo
652 652
 	 *
653 653
 	 * @return bool|WP_Error
654 654
 	 */
655
-	public function set_props( $props, $context = 'set' ) {
655
+	public function set_props($props, $context = 'set') {
656 656
 		$errors = false;
657 657
 
658
-		foreach ( $props as $prop => $value ) {
658
+		foreach ($props as $prop => $value) {
659 659
 			try {
660 660
 				/**
661 661
 				 * Checks if the prop being set is allowed, and the value is not null.
662 662
 				 */
663
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
663
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
664 664
 					continue;
665 665
 				}
666 666
 				$setter = "set_$prop";
667 667
 
668
-				if ( is_callable( array( $this, $setter ) ) ) {
669
-					$this->{$setter}( $value );
668
+				if (is_callable(array($this, $setter))) {
669
+					$this->{$setter}($value);
670 670
 				}
671
-			} catch ( Exception $e ) {
672
-				if ( ! $errors ) {
671
+			} catch (Exception $e) {
672
+				if (!$errors) {
673 673
 					$errors = new WP_Error();
674 674
 				}
675
-				$errors->add( $e->getCode(), $e->getMessage() );
675
+				$errors->add($e->getCode(), $e->getMessage());
676 676
 			}
677 677
 		}
678 678
 
679
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
679
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
680 680
 	}
681 681
 
682 682
 	/**
@@ -689,14 +689,14 @@  discard block
 block discarded – undo
689 689
 	 * @param string $prop Name of prop to set.
690 690
 	 * @param mixed  $value Value of the prop.
691 691
 	 */
692
-	protected function set_prop( $prop, $value ) {
693
-		if ( array_key_exists( $prop, $this->data ) ) {
694
-			if ( true === $this->object_read ) {
695
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
696
-					$this->changes[ $prop ] = $value;
692
+	protected function set_prop($prop, $value) {
693
+		if (array_key_exists($prop, $this->data)) {
694
+			if (true === $this->object_read) {
695
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
696
+					$this->changes[$prop] = $value;
697 697
 				}
698 698
 			} else {
699
-				$this->data[ $prop ] = $value;
699
+				$this->data[$prop] = $value;
700 700
 			}
701 701
 		}
702 702
 	}
@@ -717,7 +717,7 @@  discard block
 block discarded – undo
717 717
 	 * @since 1.0.19
718 718
 	 */
719 719
 	public function apply_changes() {
720
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
720
+		$this->data    = array_replace_recursive($this->data, $this->changes);
721 721
 		$this->changes = array();
722 722
 	}
723 723
 
@@ -742,14 +742,14 @@  discard block
 block discarded – undo
742 742
 	 * @param  string $context What the value is for. Valid values are view and edit.
743 743
 	 * @return mixed
744 744
 	 */
745
-	protected function get_prop( $prop, $context = 'view' ) {
745
+	protected function get_prop($prop, $context = 'view') {
746 746
 		$value = null;
747 747
 
748
-		if ( array_key_exists( $prop, $this->data ) ) {
749
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
748
+		if (array_key_exists($prop, $this->data)) {
749
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
750 750
 
751
-			if ( 'view' === $context ) {
752
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
751
+			if ('view' === $context) {
752
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
753 753
 			}
754 754
 		}
755 755
 
@@ -763,13 +763,13 @@  discard block
 block discarded – undo
763 763
 	 * @param string         $prop Name of prop to set.
764 764
 	 * @param string|integer $value Value of the prop.
765 765
 	 */
766
-	protected function set_date_prop( $prop, $value ) {
766
+	protected function set_date_prop($prop, $value) {
767 767
 
768
-		if ( empty( $value ) ) {
769
-			$this->set_prop( $prop, null );
768
+		if (empty($value)) {
769
+			$this->set_prop($prop, null);
770 770
 			return;
771 771
 		}
772
-		$this->set_prop( $prop, $value );
772
+		$this->set_prop($prop, $value);
773 773
 
774 774
 	}
775 775
 
@@ -781,7 +781,7 @@  discard block
 block discarded – undo
781 781
 	 * @param string $code             Error code.
782 782
 	 * @param string $message          Error message.
783 783
 	 */
784
-	protected function error( $code, $message ) {
785
-		throw new Exception( $message, $code );
784
+	protected function error($code, $message) {
785
+		throw new Exception($message, $code);
786 786
 	}
787 787
 }
Please login to merge, or discard this patch.