Passed
Push — master ( cb75a2...6929e7 )
by Brian
05:54 queued 11s
created
templates/payment-forms/cart.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -7,29 +7,29 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Cart table columns.
13 13
 $columns = array(
14
-    'name'     => __( 'Item', 'invoicing' ),
15
-    'price'    => __( 'Price', 'invoicing' ),
16
-    'quantity' => __( 'Quantity', 'invoicing' ),
17
-    'subtotal' => __( 'Subtotal', 'invoicing' ),
14
+    'name'     => __('Item', 'invoicing'),
15
+    'price'    => __('Price', 'invoicing'),
16
+    'quantity' => __('Quantity', 'invoicing'),
17
+    'subtotal' => __('Subtotal', 'invoicing'),
18 18
 );
19 19
 
20
-if ( ! empty( $form->invoice ) ) {
21
-    $columns = getpaid_invoice_item_columns( $form->invoice );
20
+if (!empty($form->invoice)) {
21
+    $columns = getpaid_invoice_item_columns($form->invoice);
22 22
 }
23 23
 
24
-$columns = apply_filters( 'getpaid_payment_form_cart_table_columns', $columns, $form );
24
+$columns = apply_filters('getpaid_payment_form_cart_table_columns', $columns, $form);
25 25
 
26 26
 ?>
27 27
     <div class="getpaid-payment-form-items-cart border">
28 28
         <div class="getpaid-payment-form-items-cart-header">
29 29
             <div class="form-row">
30
-            <?php foreach ( $columns as $key => $label ) : ?>
31
-                <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-form-cart-item-<?php echo esc_attr( $key ); ?>">
32
-                    <?php echo sanitize_text_field( $label ); ?>
30
+            <?php foreach ($columns as $key => $label) : ?>
31
+                <div class="<?php echo 'name' == $key ? 'col-12 col-sm-6' : 'col-12 col-sm' ?> getpaid-form-cart-item-<?php echo esc_attr($key); ?>">
32
+                    <?php echo sanitize_text_field($label); ?>
33 33
                 </div>
34 34
             <?php endforeach; ?>
35 35
             </div>
@@ -37,12 +37,12 @@  discard block
 block discarded – undo
37 37
         <?php
38 38
 
39 39
             // Display the item totals.
40
-            foreach ( $form->get_items() as $item ) {
41
-                wpinv_get_template( 'payment-forms/cart-item.php', compact( 'form', 'item', 'columns' ) );
40
+            foreach ($form->get_items() as $item) {
41
+                wpinv_get_template('payment-forms/cart-item.php', compact('form', 'item', 'columns'));
42 42
             }
43 43
 
44 44
             // Display the cart totals.
45
-            wpinv_get_template( 'payment-forms/cart-totals.php', compact( 'form' ) );
45
+            wpinv_get_template('payment-forms/cart-totals.php', compact('form'));
46 46
 
47 47
         ?>
48 48
     </div>
Please login to merge, or discard this patch.
templates/payment-forms/cart-totals.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -7,25 +7,25 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Totals rows.
13 13
 $totals = apply_filters(
14 14
     'getpaid_payment_form_cart_table_totals',
15 15
     array(
16
-        'subtotal' => __( 'Subtotal', 'invoicing' ),
17
-        'tax'      => __( 'Tax', 'invoicing' ),
18
-        'discount' => __( 'Discount', 'invoicing' ),
19
-        'total'    => __( 'Total', 'invoicing' ),
16
+        'subtotal' => __('Subtotal', 'invoicing'),
17
+        'tax'      => __('Tax', 'invoicing'),
18
+        'discount' => __('Discount', 'invoicing'),
19
+        'total'    => __('Total', 'invoicing'),
20 20
     ),
21 21
     $form
22 22
 );
23 23
 
24
-if ( ! wpinv_use_taxes() && isset( $totals['tax'] ) ) {
25
-    unset( $totals['tax'] );
24
+if (!wpinv_use_taxes() && isset($totals['tax'])) {
25
+    unset($totals['tax']);
26 26
 }
27 27
 
28
-do_action( 'getpaid_before_payment_form_cart_totals', $form, $totals );
28
+do_action('getpaid_before_payment_form_cart_totals', $form, $totals);
29 29
 
30 30
 $tax       = 0;
31 31
 $sub_total = 0;
@@ -33,15 +33,15 @@  discard block
 block discarded – undo
33 33
 $discount  = 0;
34 34
 
35 35
 // Calculate totals.
36
-foreach ( $form->get_items() as $item ) {
36
+foreach ($form->get_items() as $item) {
37 37
     $amount = $item->get_price();
38 38
 
39 39
     // Include the tax.
40
-    if ( wpinv_use_taxes() ) {
41
-        $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, $item->get_id() );
40
+    if (wpinv_use_taxes()) {
41
+        $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, $item->get_id());
42 42
 
43
-        if ( wpinv_prices_include_tax() ) {
44
-            $pre_tax  = ( $amount - $amount * $rate * 0.01 );
43
+        if (wpinv_prices_include_tax()) {
44
+            $pre_tax  = ($amount - $amount * $rate * 0.01);
45 45
             $item_tax = $amount - $pre_tax;
46 46
         } else {
47 47
             $pre_tax  = $amount;
@@ -53,41 +53,41 @@  discard block
 block discarded – undo
53 53
         $total     = $sub_total + $tax;
54 54
 
55 55
     } else {
56
-        $total  = $total + $amount;
56
+        $total = $total + $amount;
57 57
     }
58 58
 
59 59
 }
60 60
 
61 61
 ?>
62 62
 <div class='border-top getpaid-payment-form-items-cart-totals'>
63
-    <?php foreach ( $totals as $key => $label ) : ?>
64
-        <div class="getpaid-form-cart-totals-col getpaid-form-cart-totals-<?php echo esc_attr( $key ); ?>">
63
+    <?php foreach ($totals as $key => $label) : ?>
64
+        <div class="getpaid-form-cart-totals-col getpaid-form-cart-totals-<?php echo esc_attr($key); ?>">
65 65
             <div class="row">
66 66
                 <div class="col-12 offset-sm-6 col-sm-4">
67
-                    <?php echo sanitize_text_field( $label ); ?>
67
+                    <?php echo sanitize_text_field($label); ?>
68 68
                 </div>
69
-                <div class="col-12 col-sm-2 getpaid-form-cart-totals-total-<?php echo esc_attr( $key ); ?>">
69
+                <div class="col-12 col-sm-2 getpaid-form-cart-totals-total-<?php echo esc_attr($key); ?>">
70 70
                     <?php
71
-                        do_action( "getpaid_payment_form_cart_totals_$key", $form );
71
+                        do_action("getpaid_payment_form_cart_totals_$key", $form);
72 72
 
73 73
                         // Total tax.
74
-                        if ( 'tax' == $key ) {
75
-                            echo wpinv_price( wpinv_format_amount( $tax ) );
74
+                        if ('tax' == $key) {
75
+                            echo wpinv_price(wpinv_format_amount($tax));
76 76
                         }
77 77
 
78 78
                         // Total discount.
79
-                        if ( 'discount' == $key ) {
80
-                            echo wpinv_price( wpinv_format_amount( $discount ) );
79
+                        if ('discount' == $key) {
80
+                            echo wpinv_price(wpinv_format_amount($discount));
81 81
                         }
82 82
 
83 83
                         // Sub total.
84
-                        if ( 'subtotal' == $key ) {
85
-                            echo wpinv_price( wpinv_format_amount( $sub_total ) );
84
+                        if ('subtotal' == $key) {
85
+                            echo wpinv_price(wpinv_format_amount($sub_total));
86 86
                         }
87 87
 
88 88
                         // Total.
89
-                        if ( 'total' == $key ) {
90
-                            echo wpinv_price( wpinv_format_amount( $total ) );
89
+                        if ('total' == $key) {
90
+                            echo wpinv_price(wpinv_format_amount($total));
91 91
                         }
92 92
                     ?>
93 93
                 </div>
@@ -97,4 +97,4 @@  discard block
 block discarded – undo
97 97
 </div>
98 98
 
99 99
 <?php
100
-do_action(  'getpaid_payment_form_cart_totals', $form, $totals );
100
+do_action('getpaid_payment_form_cart_totals', $form, $totals);
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 1 patch
Spacing   +112 added lines, -112 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -24,59 +24,59 @@  discard block
 block discarded – undo
24 24
  * @param string $country The country code to sanitize
25 25
  * @return array
26 26
  */
27
-function wpinv_sanitize_country( $country ) {
27
+function wpinv_sanitize_country($country) {
28 28
 
29 29
 	// Enure the country is specified
30
-    if ( empty( $country ) ) {
30
+    if (empty($country)) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
33
-    return trim( wpinv_utf8_strtoupper( $country ) );
33
+    return trim(wpinv_utf8_strtoupper($country));
34 34
 
35 35
 }
36 36
 
37
-function wpinv_is_base_country( $country ) {
37
+function wpinv_is_base_country($country) {
38 38
     $base_country = wpinv_get_default_country();
39 39
     
40
-    if ( $base_country === 'UK' ) {
40
+    if ($base_country === 'UK') {
41 41
         $base_country = 'GB';
42 42
     }
43
-    if ( $country == 'UK' ) {
43
+    if ($country == 'UK') {
44 44
         $country = 'GB';
45 45
     }
46 46
 
47
-    return ( $country && $country === $base_country ) ? true : false;
47
+    return ($country && $country === $base_country) ? true : false;
48 48
 }
49 49
 
50
-function wpinv_country_name( $country_code = '' ) { 
50
+function wpinv_country_name($country_code = '') { 
51 51
     $countries = wpinv_get_country_list();
52 52
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
53
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
53
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
54 54
 
55
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
55
+    return apply_filters('wpinv_country_name', $country, $country_code);
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', false );
59
+	$state = wpinv_get_option('default_state', false);
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+	return apply_filters('wpinv_default_state', $state);
62 62
 }
63 63
 
64
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
64
+function wpinv_state_name($state_code = '', $country_code = '') {
65 65
     $state = $state_code;
66 66
     
67
-    if ( !empty( $country_code ) ) {
68
-        $states = wpinv_get_country_states( $country_code );
67
+    if (!empty($country_code)) {
68
+        $states = wpinv_get_country_states($country_code);
69 69
         
70
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
70
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
71 71
     }
72 72
 
73
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
73
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
74 74
 }
75 75
 
76 76
 function wpinv_store_address() {
77
-    $address = wpinv_get_option( 'store_address', '' );
77
+    $address = wpinv_get_option('store_address', '');
78 78
 
79
-    return apply_filters( 'wpinv_store_address', $address );
79
+    return apply_filters('wpinv_store_address', $address);
80 80
 }
81 81
 
82 82
 /**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
  * 
85 85
  * @param WPInv_Invoice $invoice
86 86
  */
87
-function getpaid_save_invoice_user_address( $invoice ) {
87
+function getpaid_save_invoice_user_address($invoice) {
88 88
 
89 89
     $address_fields = array(
90 90
         'first_name',
@@ -99,23 +99,23 @@  discard block
 block discarded – undo
99 99
         'zip'
100 100
     );
101 101
 
102
-    foreach ( $address_fields as $field ) {
102
+    foreach ($address_fields as $field) {
103 103
         $method = "get_{$field}";
104 104
         $value = $invoice->$method();
105 105
 
106 106
         // Only save if it is not empty.
107
-        if ( ! empty( $value ) ) {
108
-            update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
107
+        if (!empty($value)) {
108
+            update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
109 109
         }
110 110
     }
111 111
 
112 112
 }
113 113
 
114
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
114
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
115 115
     global $wpi_userID;
116 116
     
117
-    if( empty( $user_id ) ) {
118
-        $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id();
117
+    if (empty($user_id)) {
118
+        $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id();
119 119
     }
120 120
     
121 121
     $address_fields = array(
@@ -132,29 +132,29 @@  discard block
 block discarded – undo
132 132
         'phone',
133 133
     );
134 134
 
135
-    $user_info = get_userdata( $user_id );
135
+    $user_info = get_userdata($user_id);
136 136
 
137 137
     $address = array();
138 138
     $address['user_id'] = $user_id;
139
-    $address['email'] = !empty( $user_info ) ? $user_info->user_email : '';
140
-    foreach ( $address_fields as $field ) {
141
-        $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true );
139
+    $address['email'] = !empty($user_info) ? $user_info->user_email : '';
140
+    foreach ($address_fields as $field) {
141
+        $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true);
142 142
     }
143 143
 
144
-    if ( !empty( $user_info ) ) {
145
-        if( empty( $address['first_name'] ) )
144
+    if (!empty($user_info)) {
145
+        if (empty($address['first_name']))
146 146
             $address['first_name'] = $user_info->first_name;
147 147
         
148
-        if( empty( $address['last_name'] ) )
148
+        if (empty($address['last_name']))
149 149
             $address['last_name'] = $user_info->last_name;
150 150
     }
151 151
     
152
-    $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
152
+    $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ",");
153 153
     
154
-    if( empty( $address['state'] ) && $with_default )
154
+    if (empty($address['state']) && $with_default)
155 155
         $address['state'] = wpinv_get_default_state();
156 156
 
157
-    if( empty( $address['country'] ) && $with_default )
157
+    if (empty($address['country']) && $with_default)
158 158
         $address['country'] = wpinv_get_default_country();
159 159
 
160 160
 
@@ -168,16 +168,16 @@  discard block
 block discarded – undo
168 168
  * @param string $return What to return.
169 169
  * @return array
170 170
  */
171
-function wpinv_get_continents( $return = 'all' ) {
171
+function wpinv_get_continents($return = 'all') {
172 172
 
173
-    $continents = wpinv_get_data( 'continents' );
173
+    $continents = wpinv_get_data('continents');
174 174
 
175
-    switch( $return ) {
175
+    switch ($return) {
176 176
         case 'name' :
177
-            return wp_list_pluck( $continents, 'name' );
177
+            return wp_list_pluck($continents, 'name');
178 178
             break;
179 179
         case 'countries' :
180
-            return wp_list_pluck( $continents, 'countries' );
180
+            return wp_list_pluck($continents, 'countries');
181 181
             break;
182 182
         default :
183 183
             return $continents;
@@ -193,12 +193,12 @@  discard block
 block discarded – undo
193 193
  * @param string $country Country code. If no code is specified, defaults to the default country.
194 194
  * @return string
195 195
  */
196
-function wpinv_get_continent_code_for_country( $country = false ) {
196
+function wpinv_get_continent_code_for_country($country = false) {
197 197
 
198
-    $country = wpinv_sanitize_country( $country );
198
+    $country = wpinv_sanitize_country($country);
199 199
     
200
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
201
-		if ( false !== array_search( $country, $countries, true ) ) {
200
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
201
+		if (false !== array_search($country, $countries, true)) {
202 202
 			return $continent_code;
203 203
 		}
204 204
 	}
@@ -214,13 +214,13 @@  discard block
 block discarded – undo
214 214
  * @param string $country Country code. If no code is specified, defaults to the default country.
215 215
  * @return array
216 216
  */
217
-function wpinv_get_country_calling_code( $country = null) {
217
+function wpinv_get_country_calling_code($country = null) {
218 218
 
219
-    $country = wpinv_sanitize_country( $country );
220
-    $codes   = wpinv_get_data( 'phone-codes' );
221
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
219
+    $country = wpinv_sanitize_country($country);
220
+    $codes   = wpinv_get_data('phone-codes');
221
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
222 222
 
223
-    if ( is_array( $code ) ) {
223
+    if (is_array($code)) {
224 224
         return $code[0];
225 225
     }
226 226
     return $code;
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
  * @param bool $first_empty Whether or not the first item in the list should be empty
234 234
  * @return array
235 235
  */
236
-function wpinv_get_country_list( $first_empty = false ) {
237
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
236
+function wpinv_get_country_list($first_empty = false) {
237
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
238 238
 }
239 239
 
240 240
 /**
@@ -244,22 +244,22 @@  discard block
 block discarded – undo
244 244
  * @param bool $first_empty Whether or not the first item in the list should be empty
245 245
  * @return array
246 246
  */
247
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
247
+function wpinv_get_country_states($country = null, $first_empty = false) {
248 248
     
249 249
     // Prepare the country.
250
-    $country = wpinv_sanitize_country( $country );
250
+    $country = wpinv_sanitize_country($country);
251 251
 
252 252
     // Fetch all states.
253
-    $all_states = wpinv_get_data( 'states' );
253
+    $all_states = wpinv_get_data('states');
254 254
 
255 255
     // Fetch the specified country's states.
256
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ;
257
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
258
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
256
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
257
+    $states     = apply_filters("wpinv_{$country}_states", $states);
258
+    $states     = apply_filters('wpinv_country_states', $states, $country);
259 259
 
260
-    asort( $states );
260
+    asort($states);
261 261
      
262
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
262
+    return wpinv_maybe_add_empty_option($states, $first_empty);
263 263
 }
264 264
 
265 265
 /**
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
  * @return array
270 270
  */
271 271
 function wpinv_get_us_states_list() {
272
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
272
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
273 273
 }
274 274
 
275 275
 /**
@@ -279,7 +279,7 @@  discard block
 block discarded – undo
279 279
  * @return array
280 280
  */
281 281
 function wpinv_get_canada_states_list() {
282
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
282
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
283 283
 }
284 284
 
285 285
 /**
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
  * @return array
290 290
  */
291 291
 function wpinv_get_australia_states_list() {
292
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
292
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
293 293
 }
294 294
 
295 295
 /**
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
  * @return array
300 300
  */
301 301
 function wpinv_get_bangladesh_states_list() {
302
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
302
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
303 303
 }
304 304
 
305 305
 /**
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
  * @return array
310 310
  */
311 311
 function wpinv_get_brazil_states_list() {
312
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
312
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
313 313
 }
314 314
 
315 315
 /**
@@ -319,7 +319,7 @@  discard block
 block discarded – undo
319 319
  * @return array
320 320
  */
321 321
 function wpinv_get_bulgaria_states_list() {
322
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
322
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
323 323
 }
324 324
 
325 325
 /**
@@ -329,7 +329,7 @@  discard block
 block discarded – undo
329 329
  * @return array
330 330
  */
331 331
 function wpinv_get_hong_kong_states_list() {
332
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
332
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
333 333
 }
334 334
 
335 335
 /**
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
  * @return array
340 340
  */
341 341
 function wpinv_get_hungary_states_list() {
342
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
342
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
343 343
 }
344 344
 
345 345
 /**
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
  * @return array
350 350
  */
351 351
 function wpinv_get_japan_states_list() {
352
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
352
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
353 353
 }
354 354
 
355 355
 /**
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
  * @return array
360 360
  */
361 361
 function wpinv_get_china_states_list() {
362
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
362
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
363 363
 }
364 364
 
365 365
 /**
@@ -369,7 +369,7 @@  discard block
 block discarded – undo
369 369
  * @return array
370 370
  */
371 371
 function wpinv_get_new_zealand_states_list() {
372
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
372
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
373 373
 }
374 374
 
375 375
 /**
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
  * @return array
380 380
  */
381 381
 function wpinv_get_peru_states_list() {
382
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
382
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
383 383
 }
384 384
 
385 385
 /**
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
  * @return array
390 390
  */
391 391
 function wpinv_get_indonesia_states_list() {
392
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
392
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
393 393
 }
394 394
 
395 395
 /**
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
  * @return array
400 400
  */
401 401
 function wpinv_get_india_states_list() {
402
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
402
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
403 403
 }
404 404
 
405 405
 /**
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
  * @return array
410 410
  */
411 411
 function wpinv_get_iran_states_list() {
412
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
412
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
413 413
 }
414 414
 
415 415
 /**
@@ -419,7 +419,7 @@  discard block
 block discarded – undo
419 419
  * @return array
420 420
  */
421 421
 function wpinv_get_italy_states_list() {
422
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
422
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
423 423
 }
424 424
 
425 425
 /**
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
  * @return array
430 430
  */
431 431
 function wpinv_get_malaysia_states_list() {
432
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
432
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
433 433
 }
434 434
 
435 435
 /**
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
  * @return array
440 440
  */
441 441
 function wpinv_get_mexico_states_list() {
442
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
442
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
443 443
 }
444 444
 
445 445
 /**
@@ -449,7 +449,7 @@  discard block
 block discarded – undo
449 449
  * @return array
450 450
  */
451 451
 function wpinv_get_nepal_states_list() {
452
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
452
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
453 453
 }
454 454
 
455 455
 /**
@@ -459,7 +459,7 @@  discard block
 block discarded – undo
459 459
  * @return array
460 460
  */
461 461
 function wpinv_get_south_africa_states_list() {
462
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
462
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
463 463
 }
464 464
 
465 465
 /**
@@ -469,7 +469,7 @@  discard block
 block discarded – undo
469 469
  * @return array
470 470
  */
471 471
 function wpinv_get_thailand_states_list() {
472
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
472
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
473 473
 }
474 474
 
475 475
 /**
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
  * @return array
480 480
  */
481 481
 function wpinv_get_turkey_states_list() {
482
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
482
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
483 483
 }
484 484
 
485 485
 /**
@@ -489,28 +489,28 @@  discard block
 block discarded – undo
489 489
  * @return array
490 490
  */
491 491
 function wpinv_get_spain_states_list() {
492
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
492
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
493 493
 }
494 494
 
495 495
 function wpinv_get_states_field() {
496
-	if( empty( $_POST['country'] ) ) {
496
+	if (empty($_POST['country'])) {
497 497
 		$_POST['country'] = wpinv_get_default_country();
498 498
 	}
499
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
499
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
500 500
 
501
-	if( !empty( $states ) ) {
502
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
501
+	if (!empty($states)) {
502
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
503 503
         
504 504
         $args = array(
505 505
 			'name'    => $sanitized_field_name,
506 506
 			'id'      => $sanitized_field_name,
507 507
 			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
508
-			'options' => array_merge( array( '' => '' ), $states ),
508
+			'options' => array_merge(array('' => ''), $states),
509 509
 			'show_option_all'  => false,
510 510
 			'show_option_none' => false
511 511
 		);
512 512
 
513
-		$response = wpinv_html_select( $args );
513
+		$response = wpinv_html_select($args);
514 514
 
515 515
 	} else {
516 516
 		$response = 'nostates';
@@ -519,10 +519,10 @@  discard block
 block discarded – undo
519 519
 	return $response;
520 520
 }
521 521
 
522
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
523
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
522
+function wpinv_default_billing_country($country = '', $user_id = 0) {
523
+    $country = !empty($country) ? $country : wpinv_get_default_country();
524 524
     
525
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
525
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
526 526
 }
527 527
 
528 528
 /**
@@ -534,7 +534,7 @@  discard block
 block discarded – undo
534 534
  */
535 535
 function wpinv_get_address_formats() {
536 536
 
537
-		return apply_filters( 'wpinv_localisation_address_formats',
537
+		return apply_filters('wpinv_localisation_address_formats',
538 538
 			array(
539 539
 				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
540 540
 				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
@@ -583,9 +583,9 @@  discard block
 block discarded – undo
583 583
  * @see `wpinv_get_invoice_address_replacements`
584 584
  * @return string
585 585
  */
586
-function wpinv_get_full_address_format( $country = false) {
586
+function wpinv_get_full_address_format($country = false) {
587 587
 
588
-    if( empty( $country ) ) {
588
+    if (empty($country)) {
589 589
         $country = wpinv_get_default_country();
590 590
     }
591 591
 
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 	$formats = wpinv_get_address_formats();
594 594
 
595 595
 	// Get format for the specified country.
596
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
596
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
597 597
     
598 598
     /**
599 599
 	 * Filters the address format to use on Invoices.
@@ -605,7 +605,7 @@  discard block
 block discarded – undo
605 605
 	 * @param string $format  The address format to use.
606 606
      * @param string $country The country who's address format is being retrieved.
607 607
 	 */
608
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
608
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
609 609
 }
610 610
 
611 611
 /**
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
  * @param array $billing_details customer's billing details
617 617
  * @return array
618 618
  */
619
-function wpinv_get_invoice_address_replacements( $billing_details ) {
619
+function wpinv_get_invoice_address_replacements($billing_details) {
620 620
 
621 621
     $default_args = array(
622 622
         'address'           => '',
@@ -629,22 +629,22 @@  discard block
 block discarded – undo
629 629
 		'company'           => '',
630 630
     );
631 631
 
632
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
632
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
633 633
     $state   = $args['state'];
634 634
     $country = $args['country'];
635 635
 
636 636
     // Handle full country name.
637
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
637
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
638 638
 
639 639
     // Handle full state name.
640
-    $full_state   = ( $country && $state ) ?  wpinv_state_name( $state, $country ) : $state;
640
+    $full_state   = ($country && $state) ?  wpinv_state_name($state, $country) : $state;
641 641
 
642 642
     $args['postcode']    = $args['zip'];
643 643
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
644 644
     $args['state']       = $full_state;
645 645
     $args['state_code']  = $state;
646 646
     $args['country']     = $full_country;
647
-    $args['country_code']= $country;
647
+    $args['country_code'] = $country;
648 648
 
649 649
     /**
650 650
 	 * Filters the address format replacements to use on Invoices.
@@ -655,14 +655,14 @@  discard block
 block discarded – undo
655 655
 	 * @param array $replacements  The address replacements to use.
656 656
      * @param array $billing_details  The billing details to use.
657 657
 	 */
658
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
658
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
659 659
 
660 660
     $return = array();
661 661
 
662
-    foreach( $replacements as $key => $value ) {
663
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
662
+    foreach ($replacements as $key => $value) {
663
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
664 664
         $return['{{' . $key . '}}'] = $value;
665
-        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value );
665
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
666 666
     }
667 667
 
668 668
     return $return;
@@ -676,6 +676,6 @@  discard block
 block discarded – undo
676 676
  * @since 1.0.14
677 677
  * @return string
678 678
  */
679
-function wpinv_trim_formatted_address_line( $line ) {
680
-	return trim( $line, ', ' );
679
+function wpinv_trim_formatted_address_line($line) {
680
+	return trim($line, ', ');
681 681
 }
682 682
\ No newline at end of file
Please login to merge, or discard this patch.
includes/deprecated-functions.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
  * @deprecated
247 247
  */
248 248
 function wpinv_get_payment_key( $invoice = 0 ) {
249
-	$invoice = new WPInv_Invoice( $invoice );
249
+    $invoice = new WPInv_Invoice( $invoice );
250 250
     return $invoice->get_key();
251 251
 }
252 252
 
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
  * @deprecated
425 425
  */
426 426
 function wpinv_get_checkout_session() {
427
-	return false;
427
+    return false;
428 428
 }
429 429
 
430 430
 /**
Please login to merge, or discard this patch.
Spacing   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * @deprecated
@@ -19,48 +19,48 @@  discard block
 block discarded – undo
19 19
  * @deprecated
20 20
  */
21 21
 function wpinv_get_invoice_cart() {
22
-    return wpinv_get_invoice( getpaid_get_current_invoice_id() );
22
+    return wpinv_get_invoice(getpaid_get_current_invoice_id());
23 23
 }
24 24
 
25 25
 /**
26 26
  * @deprecated
27 27
  */
28
-function wpinv_get_invoice_description( $invoice ) {
29
-    $invoice = new WPInv_Invoice( $invoice );
28
+function wpinv_get_invoice_description($invoice) {
29
+    $invoice = new WPInv_Invoice($invoice);
30 30
     return $invoice->get_description();
31 31
 }
32 32
 
33 33
 /**
34 34
  * @deprecated
35 35
  */
36
-function wpinv_get_invoice_currency_code( $invoice ) {
37
-    $invoice = new WPInv_Invoice( $invoice );
36
+function wpinv_get_invoice_currency_code($invoice) {
37
+    $invoice = new WPInv_Invoice($invoice);
38 38
     return $invoice->get_currency();
39 39
 }
40 40
 
41 41
 /**
42 42
  * @deprecated
43 43
  */
44
-function wpinv_get_payment_user_email( $invoice ) {
45
-    $invoice = new WPInv_Invoice( $invoice );
44
+function wpinv_get_payment_user_email($invoice) {
45
+    $invoice = new WPInv_Invoice($invoice);
46 46
     return $invoice->get_email();
47 47
 }
48 48
 
49 49
 /**
50 50
  * @deprecated
51 51
  */
52
-function wpinv_get_user_id( $invoice ) {
53
-    $invoice = new WPInv_Invoice( $invoice );
52
+function wpinv_get_user_id($invoice) {
53
+    $invoice = new WPInv_Invoice($invoice);
54 54
     return $invoice->get_user_id();
55 55
 }
56 56
 
57 57
 /**
58 58
  * @deprecated
59 59
  */
60
-function wpinv_get_invoice_status( $invoice, $return_label = false ) {
61
-    $invoice = new WPInv_Invoice( $invoice );
60
+function wpinv_get_invoice_status($invoice, $return_label = false) {
61
+    $invoice = new WPInv_Invoice($invoice);
62 62
     
63
-    if ( $return_label ) {
63
+    if ($return_label) {
64 64
         return $invoice->get_status_nicename();
65 65
     }
66 66
 
@@ -70,10 +70,10 @@  discard block
 block discarded – undo
70 70
 /**
71 71
  * @deprecated
72 72
  */
73
-function wpinv_get_payment_gateway( $invoice, $return_label = false ) {
74
-    $invoice = new WPInv_Invoice( $invoice );
73
+function wpinv_get_payment_gateway($invoice, $return_label = false) {
74
+    $invoice = new WPInv_Invoice($invoice);
75 75
 
76
-    if ( $return_label ) {
76
+    if ($return_label) {
77 77
         return $invoice->get_gateway_title();
78 78
     }
79 79
 
@@ -83,75 +83,75 @@  discard block
 block discarded – undo
83 83
 /**
84 84
  * @deprecated
85 85
  */
86
-function wpinv_get_payment_gateway_name( $invoice ) {
87
-    return wpinv_get_payment_gateway( $invoice, true );
86
+function wpinv_get_payment_gateway_name($invoice) {
87
+    return wpinv_get_payment_gateway($invoice, true);
88 88
 }
89 89
 
90 90
 /**
91 91
  * @deprecated
92 92
  */
93
-function wpinv_get_payment_transaction_id( $invoice ) {
94
-    $invoice = new WPInv_Invoice( $invoice );
93
+function wpinv_get_payment_transaction_id($invoice) {
94
+    $invoice = new WPInv_Invoice($invoice);
95 95
     return $invoice->get_transaction_id();
96 96
 }
97 97
 
98 98
 /**
99 99
  * @deprecated
100 100
  */
101
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
102
-    $invoice = new WPInv_Invoice( $invoice_id );
103
-    return $invoice->get_meta( $meta_key, $single );
101
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
102
+    $invoice = new WPInv_Invoice($invoice_id);
103
+    return $invoice->get_meta($meta_key, $single);
104 104
 }
105 105
 
106 106
 /**
107 107
  * @deprecated
108 108
  */
109
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '' ) {
110
-    $invoice = new WPInv_Invoice( $invoice_id );
111
-    return $invoice->update_meta_data( $meta_key, $meta_value );
109
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '') {
110
+    $invoice = new WPInv_Invoice($invoice_id);
111
+    return $invoice->update_meta_data($meta_key, $meta_value);
112 112
 }
113 113
 
114 114
 /**
115 115
  * @deprecated
116 116
  */
117
-function wpinv_get_items( $invoice = 0 ) {
118
-    $invoice = new WPInv_Invoice( $invoice );
117
+function wpinv_get_items($invoice = 0) {
118
+    $invoice = new WPInv_Invoice($invoice);
119 119
     return $invoice->get_items();
120 120
 }
121 121
 
122 122
 /**
123 123
  * @deprecated
124 124
  */
125
-function wpinv_get_fees( $invoice = 0 ) {
126
-    $invoice = new WPInv_Invoice( $invoice );
125
+function wpinv_get_fees($invoice = 0) {
126
+    $invoice = new WPInv_Invoice($invoice);
127 127
     return $invoice->get_fees();
128 128
 }
129 129
 
130 130
 /**
131 131
  * @deprecated
132 132
  */
133
-function wpinv_get_invoice_ip( $invoice ) {
134
-    $invoice = new WPInv_Invoice( $invoice );
133
+function wpinv_get_invoice_ip($invoice) {
134
+    $invoice = new WPInv_Invoice($invoice);
135 135
     return $invoice->get_ip();
136 136
 }
137 137
 
138 138
 /**
139 139
  * @deprecated
140 140
  */
141
-function wpinv_get_invoice_user_info( $invoice ) {
142
-    $invoice = new WPInv_Invoice( $invoice );
141
+function wpinv_get_invoice_user_info($invoice) {
142
+    $invoice = new WPInv_Invoice($invoice);
143 143
     return $invoice->get_user_info();
144 144
 }
145 145
 
146 146
 /**
147 147
  * @deprecated
148 148
  */
149
-function wpinv_subtotal( $invoice = 0, $currency = false ) {
150
-    $invoice  = new WPInv_Invoice( $invoice );
149
+function wpinv_subtotal($invoice = 0, $currency = false) {
150
+    $invoice  = new WPInv_Invoice($invoice);
151 151
     $subtotal = $invoice->get_subtotal();
152 152
 
153
-    if ( $currency ) {
154
-        return wpinv_price( wpinv_format_amount( $subtotal ), $invoice->get_currency() );
153
+    if ($currency) {
154
+        return wpinv_price(wpinv_format_amount($subtotal), $invoice->get_currency());
155 155
     }
156 156
 
157 157
     return $subtotal;
@@ -160,12 +160,12 @@  discard block
 block discarded – undo
160 160
 /**
161 161
  * @deprecated
162 162
  */
163
-function wpinv_tax( $invoice = 0, $currency = false ) {
164
-    $invoice  = new WPInv_Invoice( $invoice );
163
+function wpinv_tax($invoice = 0, $currency = false) {
164
+    $invoice  = new WPInv_Invoice($invoice);
165 165
     $tax      = $invoice->get_total_tax();
166 166
 
167
-    if ( $currency ) {
168
-        return wpinv_price( wpinv_format_amount( $tax ), $invoice->get_currency() );
167
+    if ($currency) {
168
+        return wpinv_price(wpinv_format_amount($tax), $invoice->get_currency());
169 169
     }
170 170
 
171 171
     return $tax;
@@ -174,12 +174,12 @@  discard block
 block discarded – undo
174 174
 /**
175 175
  * @deprecated
176 176
  */
177
-function wpinv_discount( $invoice = 0, $currency = false, $deprecated ) {
178
-    $invoice  = new WPInv_Invoice( $invoice );
177
+function wpinv_discount($invoice = 0, $currency = false, $deprecated) {
178
+    $invoice  = new WPInv_Invoice($invoice);
179 179
     $discount = $invoice->get_total_discount();
180 180
 
181
-    if ( $currency ) {
182
-        return wpinv_price( wpinv_format_amount( $discount ), $invoice->get_currency() );
181
+    if ($currency) {
182
+        return wpinv_price(wpinv_format_amount($discount), $invoice->get_currency());
183 183
     }
184 184
 
185 185
     return $discount;
@@ -188,20 +188,20 @@  discard block
 block discarded – undo
188 188
 /**
189 189
  * @deprecated
190 190
  */
191
-function wpinv_discount_code( $invoice = 0 ) {
192
-    $invoice = new WPInv_Invoice( $invoice );
191
+function wpinv_discount_code($invoice = 0) {
192
+    $invoice = new WPInv_Invoice($invoice);
193 193
     return $invoice->get_discount_code();
194 194
 }
195 195
 
196 196
 /**
197 197
  * @deprecated
198 198
  */
199
-function wpinv_payment_total( $invoice = 0, $currency = false ) {
200
-    $invoice  = new WPInv_Invoice( $invoice );
199
+function wpinv_payment_total($invoice = 0, $currency = false) {
200
+    $invoice = new WPInv_Invoice($invoice);
201 201
     $total = $invoice->get_total();
202 202
 
203
-    if ( $currency ) {
204
-        return wpinv_price( wpinv_format_amount( $total ), $invoice->get_currency() );
203
+    if ($currency) {
204
+        return wpinv_price(wpinv_format_amount($total), $invoice->get_currency());
205 205
     }
206 206
 
207 207
     return $total;
@@ -210,51 +210,51 @@  discard block
 block discarded – undo
210 210
 /**
211 211
  * @deprecated
212 212
  */
213
-function wpinv_get_date_created( $invoice = 0, $format = '' ) {
214
-    $invoice = new WPInv_Invoice( $invoice );
213
+function wpinv_get_date_created($invoice = 0, $format = '') {
214
+    $invoice = new WPInv_Invoice($invoice);
215 215
 
216
-    $format         = ! empty( $format ) ? $format : get_option( 'date_format' );
216
+    $format         = !empty($format) ? $format : get_option('date_format');
217 217
     $date_created   = $invoice->get_created_date();
218 218
 
219
-    return empty( $date_created ) ? date_i18n( $format, strtotime( $date_created ) ) : '';
219
+    return empty($date_created) ? date_i18n($format, strtotime($date_created)) : '';
220 220
 }
221 221
 
222 222
 /**
223 223
  * @deprecated
224 224
  */
225
-function wpinv_get_invoice_date( $invoice = 0, $format = '' ) {
226
-    wpinv_get_date_created( $invoice, $format );
225
+function wpinv_get_invoice_date($invoice = 0, $format = '') {
226
+    wpinv_get_date_created($invoice, $format);
227 227
 }
228 228
 
229 229
 /**
230 230
  * @deprecated
231 231
  */
232
-function wpinv_get_invoice_vat_number( $invoice = 0 ) {
233
-    $invoice = new WPInv_Invoice( $invoice );
232
+function wpinv_get_invoice_vat_number($invoice = 0) {
233
+    $invoice = new WPInv_Invoice($invoice);
234 234
     return $invoice->get_vat_number();
235 235
 }
236 236
 
237 237
 /**
238 238
  * @deprecated
239 239
  */
240
-function wpinv_insert_payment_note( $invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
241
-    $invoice = new WPInv_Invoice( $invoice );
242
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
240
+function wpinv_insert_payment_note($invoice = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
241
+    $invoice = new WPInv_Invoice($invoice);
242
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
243 243
 }
244 244
 
245 245
 /**
246 246
  * @deprecated
247 247
  */
248
-function wpinv_get_payment_key( $invoice = 0 ) {
249
-	$invoice = new WPInv_Invoice( $invoice );
248
+function wpinv_get_payment_key($invoice = 0) {
249
+	$invoice = new WPInv_Invoice($invoice);
250 250
     return $invoice->get_key();
251 251
 }
252 252
 
253 253
 /**
254 254
  * @deprecated
255 255
  */
256
-function wpinv_get_invoice_number( $invoice = 0 ) {
257
-    $invoice = new WPInv_Invoice( $invoice );
256
+function wpinv_get_invoice_number($invoice = 0) {
257
+    $invoice = new WPInv_Invoice($invoice);
258 258
     return $invoice->get_number();
259 259
 }
260 260
 
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 /**
402 402
  * @deprecated
403 403
  */
404
-function wpinv_update_payment_status( $invoice, $new_status = 'publish' ) {    
405
-    $invoice = new WPInv_Invoice( $invoice );
406
-    return $invoice->update_status( $new_status );
404
+function wpinv_update_payment_status($invoice, $new_status = 'publish') {    
405
+    $invoice = new WPInv_Invoice($invoice);
406
+    return $invoice->update_status($new_status);
407 407
 }
408 408
 
409 409
 /**
@@ -456,22 +456,22 @@  discard block
 block discarded – undo
456 456
 /**
457 457
  * @deprecated
458 458
  */
459
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
459
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
460 460
 
461 461
     // Fetch the invoice.
462
-    $invoice = new WPInv_Invoice( $invoice_id );
462
+    $invoice = new WPInv_Invoice($invoice_id);
463 463
 
464
-    if ( 0 ==  $invoice->get_id() ) {
464
+    if (0 == $invoice->get_id()) {
465 465
         return false;
466 466
     }
467 467
 
468 468
     // Prepare the transaction id.
469
-    if ( empty( $transaction_id ) ) {
469
+    if (empty($transaction_id)) {
470 470
         $transaction_id = $invoice_id;
471 471
     }
472 472
 
473 473
     // Set the transaction id;
474
-    $invoice->set_transaction_id( apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice ) );
474
+    $invoice->set_transaction_id(apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice));
475 475
 
476 476
     // Save the invoice.
477 477
     return $invoice->save();
Please login to merge, or discard this patch.
includes/gateways/paypal.php 1 patch
Spacing   +280 added lines, -280 removed lines patch added patch discarded remove patch
@@ -1,15 +1,15 @@  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
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8 8
 
9
-function wpinv_paypal_gateway_description_sandbox_notice( $description, $gateway ) {
10
-    if ( 'paypal' == $gateway && wpinv_is_test_mode( 'paypal' ) ) {
9
+function wpinv_paypal_gateway_description_sandbox_notice($description, $gateway) {
10
+    if ('paypal' == $gateway && wpinv_is_test_mode('paypal')) {
11 11
         $description .= '<br>' . sprintf(
12
-            __( 'SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing' ),
12
+            __('SANDBOX ENABLED. You can use sandbox testing accounts only. See the %sPayPal Sandbox Testing Guide%s for more details.', 'invoicing'),
13 13
             '<a href="https://developer.paypal.com/docs/classic/lifecycle/ug_sandbox/">',
14 14
             '</a>'
15 15
         );
@@ -17,11 +17,11 @@  discard block
 block discarded – undo
17 17
     return $description;
18 18
 
19 19
 }
20
-add_filter( 'wpinv_gateway_description', 'wpinv_paypal_gateway_description_sandbox_notice', 10, 2 );
20
+add_filter('wpinv_gateway_description', 'wpinv_paypal_gateway_description_sandbox_notice', 10, 2);
21 21
 
22
-function wpinv_process_paypal_payment( $purchase_data ) {
23
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
24
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
22
+function wpinv_process_paypal_payment($purchase_data) {
23
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
24
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
25 25
     }
26 26
 
27 27
     // Collect payment data
@@ -39,24 +39,24 @@  discard block
 block discarded – undo
39 39
     );
40 40
 
41 41
     // Record the pending payment
42
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
42
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
43 43
 
44 44
     // Check payment
45
-    if ( ! $invoice ) {
45
+    if (!$invoice) {
46 46
         // Record the error
47
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
47
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
48 48
         // Problems? send back
49
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
49
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
50 50
     } else {
51 51
         // Only send to PayPal if the pending payment is created successfully
52
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
52
+        $listener_url = wpinv_get_ipn_url('paypal');
53 53
 
54 54
         // Get the success url
55
-        $return_url = add_query_arg( array(
55
+        $return_url = add_query_arg(array(
56 56
                 'payment-confirm' => 'paypal',
57 57
                 'invoice-id'      => $invoice->ID,
58 58
                 'utm_nooverride'  => 1
59
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
59
+            ), get_permalink(wpinv_get_option('success_page', false)));
60 60
 
61 61
         // Get the PayPal redirect uri
62 62
         $paypal_redirect = wpinv_get_paypal_redirect();
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
         $paypal_args = array(
66 66
             'cmd'           => '_cart',
67 67
             'upload'        => '1',
68
-            'business'      => wpinv_get_option( 'paypal_email', false ),
68
+            'business'      => wpinv_get_option('paypal_email', false),
69 69
             'email'         => $invoice->get_email(),
70 70
             'first_name'    => $invoice->get_first_name(),
71 71
             'last_name'     => $invoice->get_last_name(),
@@ -74,88 +74,88 @@  discard block
 block discarded – undo
74 74
             'shipping'      => '0',
75 75
             'no_note'       => '1',
76 76
             'currency_code' => $invoice->get_currency(),
77
-            'charset'       => get_bloginfo( 'charset' ),
77
+            'charset'       => get_bloginfo('charset'),
78 78
             'custom'        => $invoice->ID,
79 79
             'rm'            => is_ssl() ? 2 : 1,
80
-            'return'        => esc_url_raw( $return_url ),
80
+            'return'        => esc_url_raw($return_url),
81 81
             'cancel_return' => $invoice->get_checkout_payment_url(),
82 82
             'notify_url'    => $listener_url,
83
-            'cbt'           => get_bloginfo( 'name' ),
83
+            'cbt'           => get_bloginfo('name'),
84 84
             'bn'            => 'WPInvoicing_SP',
85 85
         );
86 86
 
87 87
         // Add cart items
88 88
         $i = 1;
89
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
90
-            foreach ( $purchase_data['cart_details'] as $item ) {
89
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
90
+            foreach ($purchase_data['cart_details'] as $item) {
91 91
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
92
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
92
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
93 93
 
94
-                if ( $item_amount <= 0 ) {
94
+                if ($item_amount <= 0) {
95 95
                     $item_amount = 0;
96 96
                 }
97 97
 
98
-                $paypal_args['item_number_' . $i ]      = $item['id'];
99
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
100
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
101
-                $paypal_args['amount_' . $i ]           = $item_amount;
102
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
98
+                $paypal_args['item_number_' . $i]      = $item['id'];
99
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
100
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
101
+                $paypal_args['amount_' . $i]           = $item_amount;
102
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
103 103
 
104 104
                 $i++;
105 105
             }
106 106
         }
107 107
 
108 108
         // Add taxes to the cart
109
-        if ( wpinv_use_taxes() && $invoice->is_taxable() ) {
110
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float) $invoice->get_tax(), 2 );
109
+        if (wpinv_use_taxes() && $invoice->is_taxable()) {
110
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float) $invoice->get_tax(), 2);
111 111
         }
112 112
 
113
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
113
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
114 114
 
115 115
         // Build query
116
-        $paypal_redirect .= http_build_query( $paypal_args );
116
+        $paypal_redirect .= http_build_query($paypal_args);
117 117
 
118 118
         // Fix for some sites that encode the entities
119
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
119
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
120 120
 
121 121
         // Get rid of cart contents
122 122
         wpinv_empty_cart();
123 123
         
124 124
         // Redirect to PayPal
125
-        wp_redirect( $paypal_redirect );
125
+        wp_redirect($paypal_redirect);
126 126
         exit;
127 127
     }
128 128
 }
129
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
129
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
130 130
 
131
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
132
-    if ( $invoice->is_recurring() && $subscription = wpinv_get_subscription( $invoice->ID ) ) {
131
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
132
+    if ($invoice->is_recurring() && $subscription = wpinv_get_subscription($invoice->ID)) {
133 133
 
134
-        $period             = strtoupper( substr( $subscription->period, 0, 1) );
134
+        $period             = strtoupper(substr($subscription->period, 0, 1));
135 135
         $interval           = $subscription->frequency;
136 136
         $bill_times         = (int) $subscription->bill_times;
137 137
         
138
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
139
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
138
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
139
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
140 140
         
141 141
         $paypal_args['cmd'] = '_xclick-subscriptions';
142 142
         $paypal_args['sra'] = '1';
143 143
         $paypal_args['src'] = '1';
144 144
         
145 145
         // Set item description
146
-        $item_name                  = wpinv_get_cart_item_name( array( 'id' => $subscription->product_id ) );
147
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) );
146
+        $item_name                  = wpinv_get_cart_item_name(array('id' => $subscription->product_id));
147
+        $paypal_args['item_name']   = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8'));
148 148
         $paypal_args['item_number'] = $subscription->product_id;
149
-        $item   = new WPInv_Item( $subscription->period );
149
+        $item = new WPInv_Item($subscription->period);
150 150
 
151
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
151
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
152 152
             $paypal_args['a1']  = $initial_amount;
153 153
             $paypal_args['p1']  = $item->get_trial_interval();
154 154
             $paypal_args['t1']  = $item->get_trial_period();
155 155
             
156 156
             // Set the recurring amount
157 157
             $paypal_args['a3']  = $recurring_amount;
158
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
158
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
159 159
             $paypal_args['a1']  = $initial_amount;
160 160
             $paypal_args['p1']  = $interval;
161 161
             $paypal_args['t1']  = $period;
@@ -163,63 +163,63 @@  discard block
 block discarded – undo
163 163
             // Set the recurring amount
164 164
             $paypal_args['a3']  = $recurring_amount;
165 165
             
166
-            if ( $bill_times > 1 ) {
166
+            if ($bill_times > 1) {
167 167
                 $bill_times--;
168 168
             }
169 169
         } else {
170
-            $paypal_args['a3']  = $initial_amount;
170
+            $paypal_args['a3'] = $initial_amount;
171 171
         }
172 172
         
173 173
         $paypal_args['p3']  = $interval;
174 174
         $paypal_args['t3']  = $period;
175 175
         
176
-        if ( $bill_times > 1 ) {
176
+        if ($bill_times > 1) {
177 177
             // Make sure it's not over the max of 52
178
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
178
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
179 179
         }
180 180
                 
181 181
         // Remove cart items
182 182
         $i = 1;
183
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
184
-            foreach ( $purchase_data['cart_details'] as $item ) {                
185
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
186
-                    unset( $paypal_args['item_number_' . $i] );
183
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
184
+            foreach ($purchase_data['cart_details'] as $item) {                
185
+                if (isset($paypal_args['item_number_' . $i])) {
186
+                    unset($paypal_args['item_number_' . $i]);
187 187
                 }
188
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
189
-                    unset( $paypal_args['item_name_' . $i] );
188
+                if (isset($paypal_args['item_name_' . $i])) {
189
+                    unset($paypal_args['item_name_' . $i]);
190 190
                 }
191
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
192
-                    unset( $paypal_args['quantity_' . $i] );
191
+                if (isset($paypal_args['quantity_' . $i])) {
192
+                    unset($paypal_args['quantity_' . $i]);
193 193
                 }
194
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
195
-                    unset( $paypal_args['amount_' . $i] );
194
+                if (isset($paypal_args['amount_' . $i])) {
195
+                    unset($paypal_args['amount_' . $i]);
196 196
                 }
197
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
198
-                    unset( $paypal_args['discount_amount_' . $i] );
197
+                if (isset($paypal_args['discount_amount_' . $i])) {
198
+                    unset($paypal_args['discount_amount_' . $i]);
199 199
                 }
200 200
 
201 201
                 $i++;
202 202
             }
203 203
         }
204 204
         
205
-        if ( isset( $paypal_args['tax_cart'] ) ) {
206
-            unset( $paypal_args['tax_cart'] );
205
+        if (isset($paypal_args['tax_cart'])) {
206
+            unset($paypal_args['tax_cart']);
207 207
         }
208 208
                 
209
-        if ( isset( $paypal_args['upload'] ) ) {
210
-            unset( $paypal_args['upload'] );
209
+        if (isset($paypal_args['upload'])) {
210
+            unset($paypal_args['upload']);
211 211
         }
212 212
         
213
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
213
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
214 214
     }
215 215
     
216 216
     return $paypal_args;
217 217
 }
218
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
218
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221 221
 	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
222
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
223 223
 		return;
224 224
 	}
225 225
 
@@ -227,11 +227,11 @@  discard block
 block discarded – undo
227 227
 	$post_data = '';
228 228
 
229 229
 	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
230
+	if (ini_get('allow_url_fopen')) {
231
+		$post_data = file_get_contents('php://input');
232 232
 	} else {
233 233
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
234
+		ini_set('post_max_size', '12M');
235 235
 	}
236 236
 	// Start the encoded data collection with notification command
237 237
 	$encoded_data = 'cmd=_notify-validate';
@@ -240,43 +240,43 @@  discard block
 block discarded – undo
240 240
 	$arg_separator = wpinv_get_php_arg_separator_output();
241 241
 
242 242
 	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
243
+	if ($post_data || strlen($post_data) > 0) {
244 244
 		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
245
+		$encoded_data .= $arg_separator . $post_data;
246 246
 	} else {
247 247
 		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
248
+		if (empty($_POST)) {
249 249
 			// Nothing to do
250 250
 			return;
251 251
 		} else {
252 252
 			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
253
+			foreach ($_POST as $key => $value) {
254 254
 				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
255
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
256 256
 			}
257 257
 		}
258 258
 	}
259 259
 
260 260
 	// Convert collected post data to an array
261
-	wp_parse_str( $encoded_data, $encoded_data_array );
261
+	wp_parse_str($encoded_data, $encoded_data_array);
262 262
 
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
263
+	foreach ($encoded_data_array as $key => $value) {
264
+		if (false !== strpos($key, 'amp;')) {
265
+			$new_key = str_replace('&amp;', '&', $key);
266
+			$new_key = str_replace('amp;', '&', $new_key);
267 267
 
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
268
+			unset($encoded_data_array[$key]);
269
+			$encoded_data_array[$new_key] = $value;
270 270
 		}
271 271
 	}
272 272
 
273 273
 	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
274
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
275 275
 
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
276
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
277 277
 		// Validate the IPN
278 278
 
279
-		$remote_post_vars      = array(
279
+		$remote_post_vars = array(
280 280
 			'method'           => 'POST',
281 281
 			'timeout'          => 45,
282 282
 			'redirection'      => 5,
@@ -294,21 +294,21 @@  discard block
 block discarded – undo
294 294
 		);
295 295
 
296 296
 		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
297
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
298 298
 
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
299
+		if (is_wp_error($api_response)) {
300
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
301 301
 			return; // Something went wrong
302 302
 		}
303 303
 
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
304
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
305
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
306 306
 			return; // Response not okay
307 307
 		}
308 308
 	}
309 309
 
310 310
 	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
311
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
312 312
 		return;
313 313
 
314 314
 	$defaults = array(
@@ -316,265 +316,265 @@  discard block
 block discarded – undo
316 316
 		'payment_status' => ''
317 317
 	);
318 318
 
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
319
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
320 320
 
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
321
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
323
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
324
+	wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__);
325 325
 
326
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
326
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
327 327
 		// Allow PayPal IPN types to be processed separately
328
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
328
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
329 329
 	} else {
330 330
 		// Fallback to web accept just in case the txn_type isn't present
331
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
331
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
332 332
 	}
333 333
 	exit;
334 334
 }
335
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
335
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
336 336
 
337
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
338
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
337
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
338
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
339 339
 		return;
340 340
 	}
341 341
 
342
-	if( empty( $invoice_id ) ) {
342
+	if (empty($invoice_id)) {
343 343
 		return;
344 344
 	}
345 345
 
346 346
 	// Collect payment details
347
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
347
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
348 348
 	$paypal_amount  = $data['mc_gross'];
349
-	$payment_status = strtolower( $data['payment_status'] );
350
-	$currency_code  = strtolower( $data['mc_currency'] );
351
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
349
+	$payment_status = strtolower($data['payment_status']);
350
+	$currency_code  = strtolower($data['mc_currency']);
351
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
352
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
353 353
 
354
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
354
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
355 355
 		return; // this isn't a PayPal standard IPN
356 356
 	}
357 357
 
358 358
 	// Verify payment recipient
359
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
359
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
360
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
361
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
362
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true);
363 363
 		return;
364 364
 	}
365 365
 
366 366
 	// Verify payment currency
367
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
367
+	if ($currency_code != strtolower($payment_meta['currency'])) {
368
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
369
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
370
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true);
371 371
 		return;
372 372
 	}
373 373
 
374
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
374
+	if (!wpinv_get_payment_user_email($invoice_id)) {
375 375
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376 376
 		// No email associated with purchase, so store from PayPal
377
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
377
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
378 378
 
379 379
 		// Setup and store the customer's details
380 380
 		$user_info = array(
381 381
 			'user_id'    => '-1',
382
-			'email'      => sanitize_text_field( $data['payer_email'] ),
383
-			'first_name' => sanitize_text_field( $data['first_name'] ),
384
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
382
+			'email'      => sanitize_text_field($data['payer_email']),
383
+			'first_name' => sanitize_text_field($data['first_name']),
384
+			'last_name'  => sanitize_text_field($data['last_name']),
385 385
 			'discount'   => '',
386 386
 		);
387
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
387
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
388
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
389
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
390
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
391
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
392 392
 
393 393
 		$payment_meta['user_info'] = $user_info;
394
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
394
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
395 395
 	}
396 396
 
397
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
397
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
398 398
 		// Process a refund
399
-		wpinv_process_paypal_refund( $data, $invoice_id );
399
+		wpinv_process_paypal_refund($data, $invoice_id);
400 400
 	} else {
401
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
401
+		if (get_post_status($invoice_id) == 'publish') {
402 402
 			return; // Only paid payments once
403 403
 		}
404 404
 
405 405
 		// Retrieve the total purchase amount (before PayPal)
406
-		$payment_amount = wpinv_payment_total( $invoice_id );
406
+		$payment_amount = wpinv_payment_total($invoice_id);
407 407
 
408
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
408
+		if (number_format((float) $paypal_amount, 2) < number_format((float) $payment_amount, 2)) {
409 409
 			// The prices don't match
410
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
410
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
411
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
412
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true);
413 413
 			return;
414 414
 		}
415
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
415
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
416 416
 			// Purchase keys don't match
417
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
417
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
418
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
419
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true);
420 420
 			return;
421 421
 		}
422 422
 
423
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
-			wpinv_update_payment_status( $invoice_id, 'publish' );
427
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
423
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
424
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
425
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
426
+			wpinv_update_payment_status($invoice_id, 'publish');
427
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
428 428
 			// Look for possible pending reasons, such as an echeck
429 429
 			$note = '';
430 430
 
431
-			switch( strtolower( $data['pending_reason'] ) ) {
431
+			switch (strtolower($data['pending_reason'])) {
432 432
 				case 'echeck' :
433
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
433
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
434 434
 					break;
435 435
 				
436 436
                 case 'address' :
437
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
437
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
438 438
 					break;
439 439
 				
440 440
                 case 'intl' :
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
441
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
442 442
 					break;
443 443
 				
444 444
                 case 'multi-currency' :
445
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
445
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
446 446
 					break;
447 447
 				
448 448
                 case 'paymentreview' :
449 449
                 case 'regulatory_review' :
450
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
450
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
451 451
 					break;
452 452
 				
453 453
                 case 'unilateral' :
454
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
454
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
455 455
 					break;
456 456
 				
457 457
                 case 'upgrade' :
458
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
458
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
459 459
 					break;
460 460
 				
461 461
                 case 'verify' :
462
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
462
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
463 463
 					break;
464 464
 
465 465
 				case 'other' :
466
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
466
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
467 467
 					break;
468 468
 			}
469 469
 
470
-			if ( ! empty( $note ) ) {
471
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
470
+			if (!empty($note)) {
471
+				wpinv_insert_payment_note($invoice_id, $note, '', '', true);
472 472
 			}
473 473
 		} else {
474
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
474
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true);
475 475
 		}
476 476
 	}
477 477
 }
478
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
478
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
479 479
 
480 480
 // Process PayPal subscription sign ups
481
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
481
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
482 482
 
483 483
 // Process PayPal subscription payments
484
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
484
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
485 485
 
486 486
 // Process PayPal subscription cancellations
487
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
487
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
488 488
 
489 489
 // Process PayPal subscription end of term notices
490
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
490
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
491 491
 
492 492
 // Process PayPal payment failed
493
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
493
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
494 494
 
495 495
 
496 496
 /**
497 497
  * Process the subscription started IPN.
498 498
  */
499
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
500
-    $parent_invoice_id = absint( $ipn_data['custom'] );
501
-    if( empty( $parent_invoice_id ) ) {
499
+function wpinv_process_paypal_subscr_signup($ipn_data) {
500
+    $parent_invoice_id = absint($ipn_data['custom']);
501
+    if (empty($parent_invoice_id)) {
502 502
         return;
503 503
     }
504 504
 
505
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
506
-    if ( empty( $invoice ) ) {
505
+    $invoice = wpinv_get_invoice($parent_invoice_id);
506
+    if (empty($invoice)) {
507 507
         return;
508 508
     }
509 509
 
510
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
511
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true);
512
-        if ( !empty( $ipn_data['txn_id'] ) ) {
513
-            wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
510
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
511
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true);
512
+        if (!empty($ipn_data['txn_id'])) {
513
+            wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
514 514
         }
515 515
     }
516 516
 
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
     
522
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
522
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
523 523
     sleep(1);
524
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
525
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
524
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
525
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
526 526
 
527 527
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
528
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
529
-    $created    = date_i18n( 'Y-m-d H:i:s' );
530
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
528
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
529
+    $created    = date_i18n('Y-m-d H:i:s');
530
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
531 531
 
532 532
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
533
-    $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
533
+    $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration));
534 534
 }
535 535
 
536 536
 /**
537 537
  * Process the subscription payment received IPN.
538 538
  */
539
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
540
-    $parent_invoice_id = absint( $ipn_data['custom'] );
539
+function wpinv_process_paypal_subscr_payment($ipn_data) {
540
+    $parent_invoice_id = absint($ipn_data['custom']);
541 541
 
542
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
543
-    if ( empty( $parent_invoice ) ) {
542
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
543
+    if (empty($parent_invoice)) {
544 544
         return;
545 545
     }
546 546
 
547
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
548
-    if ( false === $subscription ) {
547
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
548
+    if (false === $subscription) {
549 549
         return;
550 550
     }
551 551
 
552
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
552
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
553 553
     $times_billed   = $subscription->get_times_billed();
554
-    $signup_date    = strtotime( $subscription->created );
555
-    $today          = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) );
554
+    $signup_date    = strtotime($subscription->created);
555
+    $today          = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date']));
556 556
 
557 557
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
558
-    if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
559
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
558
+    if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
559
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
560 560
         sleep(1);
561 561
         
562 562
         // This is the very first payment
563
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
564
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
563
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
564
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
565 565
         return;
566 566
     }
567 567
 
568
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
568
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
569 569
         return; // Payment already recorded
570 570
     }
571 571
 
572
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
572
+    $currency_code = strtolower($ipn_data['mc_currency']);
573 573
 
574 574
     // verify details
575
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
575
+    if ($currency_code != strtolower(wpinv_get_currency())) {
576 576
         // the currency code is invalid
577
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
577
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
578 578
         return;
579 579
     }
580 580
 
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
         'gateway'        => 'paypal'
585 585
     );
586 586
     
587
-    $invoice_id = $subscription->add_payment( $args );
587
+    $invoice_id = $subscription->add_payment($args);
588 588
 
589
-    if ( $invoice_id > 0 ) {
590
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
591
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
589
+    if ($invoice_id > 0) {
590
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
591
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
592 592
 
593 593
         $subscription->renew();
594 594
     }
@@ -597,10 +597,10 @@  discard block
 block discarded – undo
597 597
 /**
598 598
  * Process the subscription canceled IPN.
599 599
  */
600
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
601
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
600
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
601
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
602 602
 
603
-    if( false === $subscription ) {
603
+    if (false === $subscription) {
604 604
         return;
605 605
     }
606 606
 
@@ -610,10 +610,10 @@  discard block
 block discarded – undo
610 610
 /**
611 611
  * Process the subscription expired IPN.
612 612
  */
613
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
614
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
613
+function wpinv_process_paypal_subscr_eot($ipn_data) {
614
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
615 615
 
616
-    if( false === $subscription ) {
616
+    if (false === $subscription) {
617 617
         return;
618 618
     }
619 619
 
@@ -623,40 +623,40 @@  discard block
 block discarded – undo
623 623
 /**
624 624
  * Process the subscription payment failed IPN.
625 625
  */
626
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
627
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
626
+function wpinv_process_paypal_subscr_failed($ipn_data) {
627
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
628 628
 
629
-    if( false === $subscription ) {
629
+    if (false === $subscription) {
630 630
         return;
631 631
     }
632 632
 
633 633
     $subscription->failing();
634 634
 
635
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
635
+    do_action('wpinv_recurring_payment_failed', $subscription);
636 636
 }
637 637
 
638 638
 /**
639 639
  * Retrieve the subscription this IPN notice is for.
640 640
  */
641
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
642
-    $parent_invoice_id = absint( $ipn_data['custom'] );
641
+function wpinv_get_paypal_subscription($ipn_data = array()) {
642
+    $parent_invoice_id = absint($ipn_data['custom']);
643 643
 
644
-    if( empty( $parent_invoice_id ) ) {
644
+    if (empty($parent_invoice_id)) {
645 645
         return false;
646 646
     }
647 647
 
648
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
649
-    if ( empty( $invoice ) ) {
648
+    $invoice = wpinv_get_invoice($parent_invoice_id);
649
+    if (empty($invoice)) {
650 650
         return false;
651 651
     }
652 652
 
653
-    $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true );
653
+    $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true);
654 654
 
655
-    if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) {
656
-        $subscription = wpinv_get_subscription( $parent_invoice_id );
655
+    if (!(!empty($subscription) && $subscription->id > 0)) {
656
+        $subscription = wpinv_get_subscription($parent_invoice_id);
657 657
 
658
-        if ( ! empty( $subscription ) && $subscription->id > 0 ) {
659
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
658
+        if (!empty($subscription) && $subscription->id > 0) {
659
+            $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
660 660
         } else {
661 661
             return false;
662 662
         }
@@ -666,39 +666,39 @@  discard block
 block discarded – undo
666 666
 
667 667
 }
668 668
 
669
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
669
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
670 670
 	// Collect payment details
671 671
 
672
-	if( empty( $invoice_id ) ) {
672
+	if (empty($invoice_id)) {
673 673
 		return;
674 674
 	}
675 675
 
676
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
676
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
677 677
 		return; // Only refund payments once
678 678
 	}
679 679
 
680
-	$payment_amount = wpinv_payment_total( $invoice_id );
680
+	$payment_amount = wpinv_payment_total($invoice_id);
681 681
 	$refund_amount  = $data['mc_gross'] * -1;
682 682
 
683
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
683
+	do_action('wpinv_paypal_refund_request', $data, $invoice_id);
684 684
 
685
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
686
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
685
+	if (number_format((float) $refund_amount, 2) < number_format((float) $payment_amount, 2)) {
686
+		wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float) $refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true);
687 687
 
688
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
688
+		do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount);
689 689
 
690 690
 		return; // This is a partial refund
691 691
 	}
692 692
 
693
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
694
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
695
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
693
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true);
694
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
695
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
696 696
 
697
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
697
+	do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id);
698 698
 }
699 699
 
700
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
701
-    return apply_filters( 'wpinv_paypal_uri', wpinv_is_test_mode( 'paypal' ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?' );
700
+function wpinv_get_paypal_redirect($ssl_check = false) {
701
+    return apply_filters('wpinv_paypal_uri', wpinv_is_test_mode('paypal') ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?');
702 702
 }
703 703
 
704 704
 /**
@@ -706,111 +706,111 @@  discard block
 block discarded – undo
706 706
  * 
707 707
  * @param string $content Success page content.
708 708
  */
709
-function wpinv_paypal_success_page_content( $content ) {
709
+function wpinv_paypal_success_page_content($content) {
710 710
 
711 711
     // Retrieve the invoice.
712 712
     $invoice_id = getpaid_get_current_invoice_id();
713
-    $invoice    = wpinv_get_invoice( $invoice_id );
713
+    $invoice    = wpinv_get_invoice($invoice_id);
714 714
 
715 715
     // Ensure that it exists and that it is pending payment.
716
-    if ( empty( $invoice_id ) || ! $invoice->has_status( 'wpi-pending' ) ) {
716
+    if (empty($invoice_id) || !$invoice->has_status('wpi-pending')) {
717 717
         return $content;
718 718
     }
719 719
 
720 720
     // Can the user view this invoice??
721
-    if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
721
+    if (!wpinv_user_can_view_invoice($invoice)) {
722 722
         return $content;
723 723
     }
724 724
 
725 725
     // Show payment processing indicator.
726
-    return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
726
+    return wpinv_get_template_html('wpinv-payment-processing.php', compact('invoice'));
727 727
 
728 728
 }
729
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
729
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
730 730
 
731
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
731
+function wpinv_paypal_get_transaction_id($invoice_id) {
732 732
     $transaction_id = '';
733
-    $notes = wpinv_get_invoice_notes( $invoice_id );
733
+    $notes = wpinv_get_invoice_notes($invoice_id);
734 734
 
735
-    foreach ( $notes as $note ) {
736
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
735
+    foreach ($notes as $note) {
736
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
737 737
             $transaction_id = $match[1];
738 738
             continue;
739 739
         }
740 740
     }
741 741
 
742
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
742
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
743 743
 }
744
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
744
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
745 745
 
746
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
747
-    if ( $transaction_id == $invoice_id ) {
746
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
747
+    if ($transaction_id == $invoice_id) {
748 748
         $transaction_link = $transaction_id;
749 749
     } else {
750
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
750
+        if (!empty($invoice) && !empty($invoice->mode)) {
751 751
             $mode = $invoice->mode;
752 752
         } else {
753
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
753
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
754 754
         }
755 755
 
756 756
         $sandbox = $mode == 'test' ? '.sandbox' : '';
757 757
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id;
758 758
 
759
-        $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
759
+        $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
760 760
     }
761 761
 
762
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice );
762
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice);
763 763
 }
764
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
764
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
765 765
 
766
-function wpinv_paypal_profile_id_link( $profile_id, $subscription ) {
766
+function wpinv_paypal_profile_id_link($profile_id, $subscription) {
767 767
     $link = $profile_id;
768 768
 
769
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
770
-        $invoice = wpinv_get_invoice( $invoice_id );
769
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
770
+        $invoice = wpinv_get_invoice($invoice_id);
771 771
 
772
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
772
+        if (!empty($invoice) && !empty($invoice->mode)) {
773 773
             $mode = $invoice->mode;
774 774
         } else {
775
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
775
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
776 776
         }
777 777
 
778 778
         $sandbox = $mode == 'test' ? '.sandbox' : '';
779 779
         $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id;
780 780
 
781
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
781
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
782 782
     }
783 783
     
784
-    return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription );
784
+    return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription);
785 785
 }
786
-add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 );
786
+add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2);
787 787
 
788
-function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) {
789
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
790
-        $invoice = wpinv_get_invoice( $invoice_id );
788
+function wpinv_paypal_transaction_id_link($transaction_id, $subscription) {
789
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
790
+        $invoice = wpinv_get_invoice($invoice_id);
791 791
 
792
-        if ( ! empty( $invoice ) ) {
793
-            return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice );
792
+        if (!empty($invoice)) {
793
+            return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice);
794 794
         }        
795 795
     }
796 796
     
797 797
     return $transaction_id;
798 798
 }
799
-add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 );
799
+add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2);
800 800
 
801 801
 function wpinv_is_paypal_valid_for_use() {
802
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) );
802
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR')));
803 803
 }
804 804
 
805
-function wpinv_check_paypal_currency_support( $gateway_list ) {
806
-    if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) {
807
-        unset( $gateway_list['paypal'] );
805
+function wpinv_check_paypal_currency_support($gateway_list) {
806
+    if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) {
807
+        unset($gateway_list['paypal']);
808 808
     }
809 809
     return $gateway_list;
810 810
 }
811
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 );
811
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1);
812 812
 
813
-function wpinv_gateway_paypal_button_label( $label ) {
814
-    return __( 'Proceed to PayPal', 'invoicing' );
813
+function wpinv_gateway_paypal_button_label($label) {
814
+    return __('Proceed to PayPal', 'invoicing');
815 815
 }
816
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
817 816
\ No newline at end of file
817
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
818 818
\ No newline at end of file
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 2 patches
Indentation   +857 added lines, -857 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,509 +391,509 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-	}
508
-
509
-	/**
510
-	 * Update meta data by key or ID, if provided.
511
-	 *
512
-	 * @since  1.0.19
513
-	 *
514
-	 * @param  string       $key Meta key.
515
-	 * @param  string|array $value Meta value.
516
-	 * @param  int          $meta_id Meta ID.
517
-	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
520
-			$function = 'set_' . $key;
521
-
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
524
-			}
525
-		}
526
-
527
-		$this->maybe_read_meta_data();
528
-
529
-		$array_key = false;
530
-
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
534
-		} else {
535
-			// Find matches by key.
536
-			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
539
-					$matches[] = $meta_data_array_key;
540
-				}
541
-			}
542
-
543
-			if ( ! empty( $matches ) ) {
544
-				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
-				}
548
-				$array_key = current( $matches );
549
-			}
550
-		}
551
-
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
554
-			$meta->key   = $key;
555
-			$meta->value = $value;
556
-		} else {
557
-			$this->add_meta_data( $key, $value, true );
558
-		}
559
-	}
560
-
561
-	/**
562
-	 * Delete meta data.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string $key Meta key.
566
-	 */
567
-	public function delete_meta_data( $key ) {
568
-		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
-
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
574
-			}
575
-		}
576
-	}
577
-
578
-	/**
579
-	 * Delete meta data.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @param int $mid Meta ID.
583
-	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
585
-		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
-
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
591
-			}
592
-		}
593
-	}
594
-
595
-	/**
596
-	 * Read meta data if null.
597
-	 *
598
-	 * @since 1.0.19
599
-	 */
600
-	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
602
-			$this->read_meta_data();
603
-		}
604
-	}
605
-
606
-	/**
607
-	 * Read Meta Data from the database. Ignore any internal properties.
608
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param bool $force_read True to force a new DB read (and update cache).
612
-	 */
613
-	public function read_meta_data( $force_read = false ) {
614
-		$this->meta_data = array();
615
-		$cache_loaded    = false;
616
-
617
-		if ( ! $this->get_id() ) {
618
-			return;
619
-		}
620
-
621
-		if ( ! $this->data_store ) {
622
-			return;
623
-		}
624
-
625
-		if ( ! empty( $this->cache_group ) ) {
626
-			$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();
627
-		}
628
-
629
-		if ( ! $force_read ) {
630
-			if ( ! empty( $this->cache_group ) ) {
631
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
-				$cache_loaded = ! empty( $cached_meta );
633
-			}
634
-		}
635
-
636
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
-		if ( $raw_meta_data ) {
638
-			foreach ( $raw_meta_data as $meta ) {
639
-				$this->meta_data[] = new GetPaid_Meta_Data(
640
-					array(
641
-						'id'    => (int) $meta->meta_id,
642
-						'key'   => $meta->meta_key,
643
-						'value' => maybe_unserialize( $meta->meta_value ),
644
-					)
645
-				);
646
-			}
647
-
648
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
650
-			}
651
-		}
652
-	}
653
-
654
-	/**
655
-	 * Update Meta Data in the database.
656
-	 *
657
-	 * @since 1.0.19
658
-	 */
659
-	public function save_meta_data() {
660
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
661
-			return;
662
-		}
663
-		foreach ( $this->meta_data as $array_key => $meta ) {
664
-			if ( is_null( $meta->value ) ) {
665
-				if ( ! empty( $meta->id ) ) {
666
-					$this->data_store->delete_meta( $this, $meta );
667
-					unset( $this->meta_data[ $array_key ] );
668
-				}
669
-			} elseif ( empty( $meta->id ) ) {
670
-				$meta->id = $this->data_store->add_meta( $this, $meta );
671
-				$meta->apply_changes();
672
-			} else {
673
-				if ( $meta->get_changes() ) {
674
-					$this->data_store->update_meta( $this, $meta );
675
-					$meta->apply_changes();
676
-				}
677
-			}
678
-		}
679
-		if ( ! empty( $this->cache_group ) ) {
680
-			$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();
681
-			wp_cache_delete( $cache_key, $this->cache_group );
682
-		}
683
-	}
684
-
685
-	/**
686
-	 * Set ID.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param int $id ID.
690
-	 */
691
-	public function set_id( $id ) {
692
-		$this->id = absint( $id );
693
-	}
694
-
695
-	/**
696
-	 * Sets item status.
697
-	 *
698
-	 * @since 1.0.19
699
-	 * @param string $status New status.
700
-	 * @return array details of change.
701
-	 */
702
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $_key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+    }
508
+
509
+    /**
510
+     * Update meta data by key or ID, if provided.
511
+     *
512
+     * @since  1.0.19
513
+     *
514
+     * @param  string       $key Meta key.
515
+     * @param  string|array $value Meta value.
516
+     * @param  int          $meta_id Meta ID.
517
+     */
518
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
+        if ( $this->is_internal_meta_key( $key ) ) {
520
+            $function = 'set_' . $key;
521
+
522
+            if ( is_callable( array( $this, $function ) ) ) {
523
+                return $this->{$function}( $value );
524
+            }
525
+        }
526
+
527
+        $this->maybe_read_meta_data();
528
+
529
+        $array_key = false;
530
+
531
+        if ( $meta_id ) {
532
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
+            $array_key  = $array_keys ? current( $array_keys ) : false;
534
+        } else {
535
+            // Find matches by key.
536
+            $matches = array();
537
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
+                if ( $meta->key === $key ) {
539
+                    $matches[] = $meta_data_array_key;
540
+                }
541
+            }
542
+
543
+            if ( ! empty( $matches ) ) {
544
+                // Set matches to null so only one key gets the new value.
545
+                foreach ( $matches as $meta_data_array_key ) {
546
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
547
+                }
548
+                $array_key = current( $matches );
549
+            }
550
+        }
551
+
552
+        if ( false !== $array_key ) {
553
+            $meta        = $this->meta_data[ $array_key ];
554
+            $meta->key   = $key;
555
+            $meta->value = $value;
556
+        } else {
557
+            $this->add_meta_data( $key, $value, true );
558
+        }
559
+    }
560
+
561
+    /**
562
+     * Delete meta data.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string $key Meta key.
566
+     */
567
+    public function delete_meta_data( $key ) {
568
+        $this->maybe_read_meta_data();
569
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
+
571
+        if ( $array_keys ) {
572
+            foreach ( $array_keys as $array_key ) {
573
+                $this->meta_data[ $array_key ]->value = null;
574
+            }
575
+        }
576
+    }
577
+
578
+    /**
579
+     * Delete meta data.
580
+     *
581
+     * @since 1.0.19
582
+     * @param int $mid Meta ID.
583
+     */
584
+    public function delete_meta_data_by_mid( $mid ) {
585
+        $this->maybe_read_meta_data();
586
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
+
588
+        if ( $array_keys ) {
589
+            foreach ( $array_keys as $array_key ) {
590
+                $this->meta_data[ $array_key ]->value = null;
591
+            }
592
+        }
593
+    }
594
+
595
+    /**
596
+     * Read meta data if null.
597
+     *
598
+     * @since 1.0.19
599
+     */
600
+    protected function maybe_read_meta_data() {
601
+        if ( is_null( $this->meta_data ) ) {
602
+            $this->read_meta_data();
603
+        }
604
+    }
605
+
606
+    /**
607
+     * Read Meta Data from the database. Ignore any internal properties.
608
+     * Uses it's own caches because get_metadata does not provide meta_ids.
609
+     *
610
+     * @since 1.0.19
611
+     * @param bool $force_read True to force a new DB read (and update cache).
612
+     */
613
+    public function read_meta_data( $force_read = false ) {
614
+        $this->meta_data = array();
615
+        $cache_loaded    = false;
616
+
617
+        if ( ! $this->get_id() ) {
618
+            return;
619
+        }
620
+
621
+        if ( ! $this->data_store ) {
622
+            return;
623
+        }
624
+
625
+        if ( ! empty( $this->cache_group ) ) {
626
+            $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();
627
+        }
628
+
629
+        if ( ! $force_read ) {
630
+            if ( ! empty( $this->cache_group ) ) {
631
+                $cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
+                $cache_loaded = ! empty( $cached_meta );
633
+            }
634
+        }
635
+
636
+        $raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
+        if ( $raw_meta_data ) {
638
+            foreach ( $raw_meta_data as $meta ) {
639
+                $this->meta_data[] = new GetPaid_Meta_Data(
640
+                    array(
641
+                        'id'    => (int) $meta->meta_id,
642
+                        'key'   => $meta->meta_key,
643
+                        'value' => maybe_unserialize( $meta->meta_value ),
644
+                    )
645
+                );
646
+            }
647
+
648
+            if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
650
+            }
651
+        }
652
+    }
653
+
654
+    /**
655
+     * Update Meta Data in the database.
656
+     *
657
+     * @since 1.0.19
658
+     */
659
+    public function save_meta_data() {
660
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
661
+            return;
662
+        }
663
+        foreach ( $this->meta_data as $array_key => $meta ) {
664
+            if ( is_null( $meta->value ) ) {
665
+                if ( ! empty( $meta->id ) ) {
666
+                    $this->data_store->delete_meta( $this, $meta );
667
+                    unset( $this->meta_data[ $array_key ] );
668
+                }
669
+            } elseif ( empty( $meta->id ) ) {
670
+                $meta->id = $this->data_store->add_meta( $this, $meta );
671
+                $meta->apply_changes();
672
+            } else {
673
+                if ( $meta->get_changes() ) {
674
+                    $this->data_store->update_meta( $this, $meta );
675
+                    $meta->apply_changes();
676
+                }
677
+            }
678
+        }
679
+        if ( ! empty( $this->cache_group ) ) {
680
+            $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();
681
+            wp_cache_delete( $cache_key, $this->cache_group );
682
+        }
683
+    }
684
+
685
+    /**
686
+     * Set ID.
687
+     *
688
+     * @since 1.0.19
689
+     * @param int $id ID.
690
+     */
691
+    public function set_id( $id ) {
692
+        $this->id = absint( $id );
693
+    }
694
+
695
+    /**
696
+     * Sets item status.
697
+     *
698
+     * @since 1.0.19
699
+     * @param string $status New status.
700
+     * @return array details of change.
701
+     */
702
+    public function set_status( $status ) {
703 703
         $old_status = $this->get_status();
704 704
 
705
-		$this->set_prop( 'status', $status );
706
-
707
-		return array(
708
-			'from' => $old_status,
709
-			'to'   => $status,
710
-		);
711
-    }
712
-
713
-	/**
714
-	 * Set all props to default values.
715
-	 *
716
-	 * @since 1.0.19
717
-	 */
718
-	public function set_defaults() {
719
-		$this->data    = $this->default_data;
720
-		$this->changes = array();
721
-		$this->set_object_read( false );
722
-	}
723
-
724
-	/**
725
-	 * Set object read property.
726
-	 *
727
-	 * @since 1.0.19
728
-	 * @param boolean $read Should read?.
729
-	 */
730
-	public function set_object_read( $read = true ) {
731
-		$this->object_read = (bool) $read;
732
-	}
733
-
734
-	/**
735
-	 * Get object read property.
736
-	 *
737
-	 * @since  1.0.19
738
-	 * @return boolean
739
-	 */
740
-	public function get_object_read() {
741
-		return (bool) $this->object_read;
742
-	}
743
-
744
-	/**
745
-	 * Set a collection of props in one go, collect any errors, and return the result.
746
-	 * Only sets using public methods.
747
-	 *
748
-	 * @since  1.0.19
749
-	 *
750
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
751
-	 * @param string $context In what context to run this.
752
-	 *
753
-	 * @return bool|WP_Error
754
-	 */
755
-	public function set_props( $props, $context = 'set' ) {
756
-		$errors = false;
757
-
758
-		foreach ( $props as $prop => $value ) {
759
-			try {
760
-				/**
761
-				 * Checks if the prop being set is allowed, and the value is not null.
762
-				 */
763
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
764
-					continue;
765
-				}
766
-				$setter = "set_$prop";
767
-
768
-				if ( is_callable( array( $this, $setter ) ) ) {
769
-					$this->{$setter}( $value );
770
-				}
771
-			} catch ( Exception $e ) {
772
-				if ( ! $errors ) {
773
-					$errors = new WP_Error();
774
-				}
775
-				$errors->add( $e->getCode(), $e->getMessage() );
776
-				$this->last_error = $e->getMessage();
777
-			}
778
-		}
779
-
780
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
781
-	}
782
-
783
-	/**
784
-	 * Sets a prop for a setter method.
785
-	 *
786
-	 * This stores changes in a special array so we can track what needs saving
787
-	 * the the DB later.
788
-	 *
789
-	 * @since 1.0.19
790
-	 * @param string $prop Name of prop to set.
791
-	 * @param mixed  $value Value of the prop.
792
-	 */
793
-	protected function set_prop( $prop, $value ) {
794
-		if ( array_key_exists( $prop, $this->data ) ) {
795
-			if ( true === $this->object_read ) {
796
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
-					$this->changes[ $prop ] = maybe_unserialize( $value );
798
-				}
799
-			} else {
800
-				$this->data[ $prop ] = maybe_unserialize( $value );
801
-			}
802
-		}
803
-	}
804
-
805
-	/**
806
-	 * Return data changes only.
807
-	 *
808
-	 * @since 1.0.19
809
-	 * @return array
810
-	 */
811
-	public function get_changes() {
812
-		return $this->changes;
813
-	}
814
-
815
-	/**
816
-	 * Merge changes with data and clear.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function apply_changes() {
821
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
822
-		$this->changes = array();
823
-	}
824
-
825
-	/**
826
-	 * Prefix for action and filter hooks on data.
827
-	 *
828
-	 * @since  1.0.19
829
-	 * @return string
830
-	 */
831
-	protected function get_hook_prefix() {
832
-		return 'wpinv_get_' . $this->object_type . '_';
833
-	}
834
-
835
-	/**
836
-	 * Gets a prop for a getter method.
837
-	 *
838
-	 * Gets the value from either current pending changes, or the data itself.
839
-	 * Context controls what happens to the value before it's returned.
840
-	 *
841
-	 * @since  1.0.19
842
-	 * @param  string $prop Name of prop to get.
843
-	 * @param  string $context What the value is for. Valid values are view and edit.
844
-	 * @return mixed
845
-	 */
846
-	protected function get_prop( $prop, $context = 'view' ) {
847
-		$value = null;
848
-
849
-		if ( array_key_exists( $prop, $this->data ) ) {
850
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
851
-
852
-			if ( 'view' === $context ) {
853
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
854
-			}
855
-		}
856
-
857
-		return $value;
858
-	}
859
-
860
-	/**
861
-	 * Sets a date prop whilst handling formatting and datetime objects.
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param string         $prop Name of prop to set.
865
-	 * @param string|integer $value Value of the prop.
866
-	 */
867
-	protected function set_date_prop( $prop, $value ) {
868
-
869
-		if ( empty( $value ) ) {
870
-			$this->set_prop( $prop, null );
871
-			return;
872
-		}
873
-		$this->set_prop( $prop, $value );
874
-
875
-	}
876
-
877
-	/**
878
-	 * When invalid data is found, throw an exception unless reading from the DB.
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param string $code             Error code.
882
-	 * @param string $message          Error message.
883
-	 */
884
-	protected function error( $code, $message ) {
885
-		$this->last_error = $message;
886
-	}
887
-
888
-	/**
889
-	 * Checks if the object is saved in the database
890
-	 *
891
-	 * @since 1.0.19
892
-	 * @return bool
893
-	 */
894
-	public function exists() {
895
-		$id = $this->get_id();
896
-		return ! empty( $id );
897
-	}
705
+        $this->set_prop( 'status', $status );
706
+
707
+        return array(
708
+            'from' => $old_status,
709
+            'to'   => $status,
710
+        );
711
+    }
712
+
713
+    /**
714
+     * Set all props to default values.
715
+     *
716
+     * @since 1.0.19
717
+     */
718
+    public function set_defaults() {
719
+        $this->data    = $this->default_data;
720
+        $this->changes = array();
721
+        $this->set_object_read( false );
722
+    }
723
+
724
+    /**
725
+     * Set object read property.
726
+     *
727
+     * @since 1.0.19
728
+     * @param boolean $read Should read?.
729
+     */
730
+    public function set_object_read( $read = true ) {
731
+        $this->object_read = (bool) $read;
732
+    }
733
+
734
+    /**
735
+     * Get object read property.
736
+     *
737
+     * @since  1.0.19
738
+     * @return boolean
739
+     */
740
+    public function get_object_read() {
741
+        return (bool) $this->object_read;
742
+    }
743
+
744
+    /**
745
+     * Set a collection of props in one go, collect any errors, and return the result.
746
+     * Only sets using public methods.
747
+     *
748
+     * @since  1.0.19
749
+     *
750
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
751
+     * @param string $context In what context to run this.
752
+     *
753
+     * @return bool|WP_Error
754
+     */
755
+    public function set_props( $props, $context = 'set' ) {
756
+        $errors = false;
757
+
758
+        foreach ( $props as $prop => $value ) {
759
+            try {
760
+                /**
761
+                 * Checks if the prop being set is allowed, and the value is not null.
762
+                 */
763
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
764
+                    continue;
765
+                }
766
+                $setter = "set_$prop";
767
+
768
+                if ( is_callable( array( $this, $setter ) ) ) {
769
+                    $this->{$setter}( $value );
770
+                }
771
+            } catch ( Exception $e ) {
772
+                if ( ! $errors ) {
773
+                    $errors = new WP_Error();
774
+                }
775
+                $errors->add( $e->getCode(), $e->getMessage() );
776
+                $this->last_error = $e->getMessage();
777
+            }
778
+        }
779
+
780
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
781
+    }
782
+
783
+    /**
784
+     * Sets a prop for a setter method.
785
+     *
786
+     * This stores changes in a special array so we can track what needs saving
787
+     * the the DB later.
788
+     *
789
+     * @since 1.0.19
790
+     * @param string $prop Name of prop to set.
791
+     * @param mixed  $value Value of the prop.
792
+     */
793
+    protected function set_prop( $prop, $value ) {
794
+        if ( array_key_exists( $prop, $this->data ) ) {
795
+            if ( true === $this->object_read ) {
796
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
+                    $this->changes[ $prop ] = maybe_unserialize( $value );
798
+                }
799
+            } else {
800
+                $this->data[ $prop ] = maybe_unserialize( $value );
801
+            }
802
+        }
803
+    }
804
+
805
+    /**
806
+     * Return data changes only.
807
+     *
808
+     * @since 1.0.19
809
+     * @return array
810
+     */
811
+    public function get_changes() {
812
+        return $this->changes;
813
+    }
814
+
815
+    /**
816
+     * Merge changes with data and clear.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function apply_changes() {
821
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
822
+        $this->changes = array();
823
+    }
824
+
825
+    /**
826
+     * Prefix for action and filter hooks on data.
827
+     *
828
+     * @since  1.0.19
829
+     * @return string
830
+     */
831
+    protected function get_hook_prefix() {
832
+        return 'wpinv_get_' . $this->object_type . '_';
833
+    }
834
+
835
+    /**
836
+     * Gets a prop for a getter method.
837
+     *
838
+     * Gets the value from either current pending changes, or the data itself.
839
+     * Context controls what happens to the value before it's returned.
840
+     *
841
+     * @since  1.0.19
842
+     * @param  string $prop Name of prop to get.
843
+     * @param  string $context What the value is for. Valid values are view and edit.
844
+     * @return mixed
845
+     */
846
+    protected function get_prop( $prop, $context = 'view' ) {
847
+        $value = null;
848
+
849
+        if ( array_key_exists( $prop, $this->data ) ) {
850
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
851
+
852
+            if ( 'view' === $context ) {
853
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
854
+            }
855
+        }
856
+
857
+        return $value;
858
+    }
859
+
860
+    /**
861
+     * Sets a date prop whilst handling formatting and datetime objects.
862
+     *
863
+     * @since 1.0.19
864
+     * @param string         $prop Name of prop to set.
865
+     * @param string|integer $value Value of the prop.
866
+     */
867
+    protected function set_date_prop( $prop, $value ) {
868
+
869
+        if ( empty( $value ) ) {
870
+            $this->set_prop( $prop, null );
871
+            return;
872
+        }
873
+        $this->set_prop( $prop, $value );
874
+
875
+    }
876
+
877
+    /**
878
+     * When invalid data is found, throw an exception unless reading from the DB.
879
+     *
880
+     * @since 1.0.19
881
+     * @param string $code             Error code.
882
+     * @param string $message          Error message.
883
+     */
884
+    protected function error( $code, $message ) {
885
+        $this->last_error = $message;
886
+    }
887
+
888
+    /**
889
+     * Checks if the object is saved in the database
890
+     *
891
+     * @since 1.0.19
892
+     * @return bool
893
+     */
894
+    public function exists() {
895
+        $id = $this->get_id();
896
+        return ! empty( $id );
897
+    }
898 898
 
899 899
 }
Please login to merge, or discard this patch.
Spacing   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  *
9 9
  */
10 10
 
11
-if ( ! defined( 'ABSPATH' ) ) {
11
+if (!defined('ABSPATH')) {
12 12
 	exit;
13 13
 }
14 14
 
@@ -117,8 +117,8 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @param int|object|array $read ID to load from the DB (optional) or already queried data.
119 119
 	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
120
+	public function __construct($read = 0) {
121
+		$this->data         = array_merge($this->data, $this->extra_data);
122 122
 		$this->default_data = $this->data;
123 123
 	}
124 124
 
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
 	 * @return array
129 129
 	 */
130 130
 	public function __sleep() {
131
-		return array( 'id' );
131
+		return array('id');
132 132
 	}
133 133
 
134 134
 	/**
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * If the object no longer exists, remove the ID.
138 138
 	 */
139 139
 	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
140
+		$this->__construct(absint($this->id));
141 141
 
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
142
+		if (!empty($this->last_error)) {
143
+			$this->set_id(0);
144 144
 		}
145 145
 
146 146
 	}
@@ -152,11 +152,11 @@  discard block
 block discarded – undo
152 152
 	 */
153 153
 	public function __clone() {
154 154
 		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
155
+		if (!empty($this->meta_data)) {
156
+			foreach ($this->meta_data as $array_key => $meta) {
157
+				$this->meta_data[$array_key] = clone $meta;
158
+				if (!empty($meta->id)) {
159
+					$this->meta_data[$array_key]->id = null;
160 160
 				}
161 161
 			}
162 162
 		}
@@ -199,8 +199,8 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
202
+	public function get_status($context = 'view') {
203
+		return $this->get_prop('status', $context);
204 204
     }
205 205
 
206 206
 	/**
@@ -210,10 +210,10 @@  discard block
 block discarded – undo
210 210
 	 * @param  bool $force_delete Should the data be deleted permanently.
211 211
 	 * @return bool result
212 212
 	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
213
+	public function delete($force_delete = false) {
214
+		if ($this->data_store) {
215
+			$this->data_store->delete($this, array('force_delete' => $force_delete));
216
+			$this->set_id(0);
217 217
 			return true;
218 218
 		}
219 219
 		return false;
@@ -226,7 +226,7 @@  discard block
 block discarded – undo
226 226
 	 * @return int
227 227
 	 */
228 228
 	public function save() {
229
-		if ( ! $this->data_store ) {
229
+		if (!$this->data_store) {
230 230
 			return $this->get_id();
231 231
 		}
232 232
 
@@ -236,12 +236,12 @@  discard block
 block discarded – undo
236 236
 		 * @param GetPaid_Data          $this The object being saved.
237 237
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238 238
 		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
239
+		do_action('getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store);
240 240
 
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
241
+		if ($this->get_id()) {
242
+			$this->data_store->update($this);
243 243
 		} else {
244
-			$this->data_store->create( $this );
244
+			$this->data_store->create($this);
245 245
 		}
246 246
 
247 247
 		/**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 		 * @param GetPaid_Data          $this The object being saved.
251 251
 		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252 252
 		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
253
+		do_action('getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store);
254 254
 
255 255
 		return $this->get_id();
256 256
 	}
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
 	 * @return string Data in JSON format.
263 263
 	 */
264 264
 	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
265
+		return wp_json_encode($this->get_data());
266 266
 	}
267 267
 
268 268
 	/**
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
 	 * @return array
273 273
 	 */
274 274
 	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
275
+		return array_merge(array('id' => $this->get_id()), $this->data, array('meta_data' => $this->get_meta_data()));
276 276
 	}
277 277
 
278 278
 	/**
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 	 * @return array
283 283
 	 */
284 284
 	public function get_data_keys() {
285
-		return array_keys( $this->data );
285
+		return array_keys($this->data);
286 286
 	}
287 287
 
288 288
 	/**
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
 	 * @return array
293 293
 	 */
294 294
 	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
295
+		return array_keys($this->extra_data);
296 296
 	}
297 297
 
298 298
 	/**
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
 	 * @param mixed $meta Meta value to check.
303 303
 	 * @return bool
304 304
 	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
305
+	protected function filter_null_meta($meta) {
306
+		return !is_null($meta->value);
307 307
 	}
308 308
 
309 309
 	/**
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
 	 */
315 315
 	public function get_meta_data() {
316 316
 		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
317
+		return array_values(array_filter($this->meta_data, array($this, 'filter_null_meta')));
318 318
 	}
319 319
 
320 320
 	/**
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 	 * @param  string $key Key to check.
325 325
 	 * @return bool   true if it's an internal key, false otherwise
326 326
 	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
327
+	protected function is_internal_meta_key($key) {
328
+		$internal_meta_key = !empty($key) && $this->data_store && in_array($key, $this->data_store->get_internal_meta_keys(), true);
329 329
 
330
-		if ( ! $internal_meta_key ) {
330
+		if (!$internal_meta_key) {
331 331
 			return false;
332 332
 		}
333 333
 
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
334
+		$has_setter_or_getter = is_callable(array($this, 'set_' . $key)) || is_callable(array($this, 'get_' . $key));
335 335
 
336
-		if ( ! $has_setter_or_getter ) {
336
+		if (!$has_setter_or_getter) {
337 337
 			return false;
338 338
 		}
339 339
 
340 340
 		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
341
+		getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid'), $key), '1.0.19');
342 342
 
343 343
 		return true;
344 344
 	}
@@ -352,20 +352,20 @@  discard block
 block discarded – undo
352 352
 	 * @access public
353 353
 	 *
354 354
 	 */
355
-	public function __set( $key, $value ) {
355
+	public function __set($key, $value) {
356 356
 
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
357
+		if ('id' == strtolower($key)) {
358
+			return $this->set_id($value);
359 359
 		}
360 360
 
361
-		if ( method_exists( $this, "set_$key") ) {
361
+		if (method_exists($this, "set_$key")) {
362 362
 
363 363
 			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
364
+			getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
365 365
 
366
-			call_user_func( array( $this, "set_$key" ), $value );
366
+			call_user_func(array($this, "set_$key"), $value);
367 367
 		} else {
368
-			$this->set_prop( $key, $value );
368
+			$this->set_prop($key, $value);
369 369
 		}
370 370
 
371 371
 	}
@@ -373,25 +373,25 @@  discard block
 block discarded – undo
373 373
 	/**
374 374
      * Margic method for retrieving a property.
375 375
      */
376
-    public function __get( $key ) {
376
+    public function __get($key) {
377 377
 
378 378
         // Check if we have a helper method for that.
379
-        if ( method_exists( $this, 'get_' . $key ) ) {
379
+        if (method_exists($this, 'get_' . $key)) {
380 380
 
381
-			if ( 'post_type' != $key ) {
381
+			if ('post_type' != $key) {
382 382
 				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
383
+				getpaid_doing_it_wrong(__FUNCTION__, sprintf(__('Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid'), $key), '1.0.19');
384 384
 			}
385 385
 
386
-            return call_user_func( array( $this, 'get_' . $key ) );
386
+            return call_user_func(array($this, 'get_' . $key));
387 387
         }
388 388
 
389 389
         // Check if the key is in the associated $post object.
390
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
390
+        if (!empty($this->post) && isset($this->post->$key)) {
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
394
+		return $this->get_prop($key);
395 395
 
396 396
     }
397 397
 
@@ -404,15 +404,15 @@  discard block
 block discarded – undo
404 404
 	 * @param  string $context What the value is for. Valid values are view and edit.
405 405
 	 * @return mixed
406 406
 	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
407
+	public function get_meta($key = '', $single = true, $context = 'view') {
408 408
 
409 409
 		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
410
+		$_key = str_replace('_wpinv', '', $key);
411
+		$_key = str_replace('wpinv', '', $_key);
412
+		if ($this->is_internal_meta_key($_key)) {
413 413
 			$function = 'get_' . $_key;
414 414
 
415
-			if ( is_callable( array( $this, $function ) ) ) {
415
+			if (is_callable(array($this, $function))) {
416 416
 				return $this->{$function}();
417 417
 			}
418 418
 		}
@@ -420,20 +420,20 @@  discard block
 block discarded – undo
420 420
 		// Read the meta data if not yet read.
421 421
 		$this->maybe_read_meta_data();
422 422
 		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
423
+		$array_keys = array_keys(wp_list_pluck($meta_data, 'key'), $key, true);
424 424
 		$value      = $single ? '' : array();
425 425
 
426
-		if ( ! empty( $array_keys ) ) {
426
+		if (!empty($array_keys)) {
427 427
 			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
428
+			if ($single) {
429
+				$value = $meta_data[current($array_keys)]->value;
430 430
 			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
431
+				$value = array_intersect_key($meta_data, array_flip($array_keys));
432 432
 			}
433 433
 		}
434 434
 
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
435
+		if ('view' === $context) {
436
+			$value = apply_filters($this->get_hook_prefix() . $key, $value, $this);
437 437
 		}
438 438
 
439 439
 		return $value;
@@ -446,10 +446,10 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $key Meta Key.
447 447
 	 * @return boolean
448 448
 	 */
449
-	public function meta_exists( $key = '' ) {
449
+	public function meta_exists($key = '') {
450 450
 		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
451
+		$array_keys = wp_list_pluck($this->get_meta_data(), 'key');
452
+		return in_array($key, $array_keys, true);
453 453
 	}
454 454
 
455 455
 	/**
@@ -458,12 +458,12 @@  discard block
 block discarded – undo
458 458
 	 * @since 1.0.19
459 459
 	 * @param array $data Key/Value pairs.
460 460
 	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
461
+	public function set_meta_data($data) {
462
+		if (!empty($data) && is_array($data)) {
463 463
 			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
464
+			foreach ($data as $meta) {
465 465
 				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
466
+				if (isset($meta['key'], $meta['value'], $meta['id'])) {
467 467
 					$this->meta_data[] = new GetPaid_Meta_Data(
468 468
 						array(
469 469
 							'id'    => $meta['id'],
@@ -485,18 +485,18 @@  discard block
 block discarded – undo
485 485
 	 * @param string|array $value Meta value.
486 486
 	 * @param bool         $unique Should this be a unique key?.
487 487
 	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
488
+	public function add_meta_data($key, $value, $unique = false) {
489
+		if ($this->is_internal_meta_key($key)) {
490 490
 			$function = 'set_' . $key;
491 491
 
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
492
+			if (is_callable(array($this, $function))) {
493
+				return $this->{$function}($value);
494 494
 			}
495 495
 		}
496 496
 
497 497
 		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
498
+		if ($unique) {
499
+			$this->delete_meta_data($key);
500 500
 		}
501 501
 		$this->meta_data[] = new GetPaid_Meta_Data(
502 502
 			array(
@@ -515,12 +515,12 @@  discard block
 block discarded – undo
515 515
 	 * @param  string|array $value Meta value.
516 516
 	 * @param  int          $meta_id Meta ID.
517 517
 	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
518
+	public function update_meta_data($key, $value, $meta_id = 0) {
519
+		if ($this->is_internal_meta_key($key)) {
520 520
 			$function = 'set_' . $key;
521 521
 
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
522
+			if (is_callable(array($this, $function))) {
523
+				return $this->{$function}($value);
524 524
 			}
525 525
 		}
526 526
 
@@ -528,33 +528,33 @@  discard block
 block discarded – undo
528 528
 
529 529
 		$array_key = false;
530 530
 
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
531
+		if ($meta_id) {
532
+			$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), $meta_id, true);
533
+			$array_key  = $array_keys ? current($array_keys) : false;
534 534
 		} else {
535 535
 			// Find matches by key.
536 536
 			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
537
+			foreach ($this->meta_data as $meta_data_array_key => $meta) {
538
+				if ($meta->key === $key) {
539 539
 					$matches[] = $meta_data_array_key;
540 540
 				}
541 541
 			}
542 542
 
543
-			if ( ! empty( $matches ) ) {
543
+			if (!empty($matches)) {
544 544
 				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
545
+				foreach ($matches as $meta_data_array_key) {
546
+					$this->meta_data[$meta_data_array_key]->value = null;
547 547
 				}
548
-				$array_key = current( $matches );
548
+				$array_key = current($matches);
549 549
 			}
550 550
 		}
551 551
 
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
552
+		if (false !== $array_key) {
553
+			$meta        = $this->meta_data[$array_key];
554 554
 			$meta->key   = $key;
555 555
 			$meta->value = $value;
556 556
 		} else {
557
-			$this->add_meta_data( $key, $value, true );
557
+			$this->add_meta_data($key, $value, true);
558 558
 		}
559 559
 	}
560 560
 
@@ -564,13 +564,13 @@  discard block
 block discarded – undo
564 564
 	 * @since 1.0.19
565 565
 	 * @param string $key Meta key.
566 566
 	 */
567
-	public function delete_meta_data( $key ) {
567
+	public function delete_meta_data($key) {
568 568
 		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
569
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'key'), $key, true);
570 570
 
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
571
+		if ($array_keys) {
572
+			foreach ($array_keys as $array_key) {
573
+				$this->meta_data[$array_key]->value = null;
574 574
 			}
575 575
 		}
576 576
 	}
@@ -581,13 +581,13 @@  discard block
 block discarded – undo
581 581
 	 * @since 1.0.19
582 582
 	 * @param int $mid Meta ID.
583 583
 	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
584
+	public function delete_meta_data_by_mid($mid) {
585 585
 		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
586
+		$array_keys = array_keys(wp_list_pluck($this->meta_data, 'id'), (int) $mid, true);
587 587
 
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
588
+		if ($array_keys) {
589
+			foreach ($array_keys as $array_key) {
590
+				$this->meta_data[$array_key]->value = null;
591 591
 			}
592 592
 		}
593 593
 	}
@@ -598,7 +598,7 @@  discard block
 block discarded – undo
598 598
 	 * @since 1.0.19
599 599
 	 */
600 600
 	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
601
+		if (is_null($this->meta_data)) {
602 602
 			$this->read_meta_data();
603 603
 		}
604 604
 	}
@@ -610,43 +610,43 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param bool $force_read True to force a new DB read (and update cache).
612 612
 	 */
613
-	public function read_meta_data( $force_read = false ) {
613
+	public function read_meta_data($force_read = false) {
614 614
 		$this->meta_data = array();
615 615
 		$cache_loaded    = false;
616 616
 
617
-		if ( ! $this->get_id() ) {
617
+		if (!$this->get_id()) {
618 618
 			return;
619 619
 		}
620 620
 
621
-		if ( ! $this->data_store ) {
621
+		if (!$this->data_store) {
622 622
 			return;
623 623
 		}
624 624
 
625
-		if ( ! empty( $this->cache_group ) ) {
626
-			$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();
625
+		if (!empty($this->cache_group)) {
626
+			$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();
627 627
 		}
628 628
 
629
-		if ( ! $force_read ) {
630
-			if ( ! empty( $this->cache_group ) ) {
631
-				$cached_meta  = wp_cache_get( $cache_key, $this->cache_group );
632
-				$cache_loaded = ! empty( $cached_meta );
629
+		if (!$force_read) {
630
+			if (!empty($this->cache_group)) {
631
+				$cached_meta  = wp_cache_get($cache_key, $this->cache_group);
632
+				$cache_loaded = !empty($cached_meta);
633 633
 			}
634 634
 		}
635 635
 
636
-		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta( $this );
637
-		if ( $raw_meta_data ) {
638
-			foreach ( $raw_meta_data as $meta ) {
636
+		$raw_meta_data = $cache_loaded ? $cached_meta : $this->data_store->read_meta($this);
637
+		if ($raw_meta_data) {
638
+			foreach ($raw_meta_data as $meta) {
639 639
 				$this->meta_data[] = new GetPaid_Meta_Data(
640 640
 					array(
641 641
 						'id'    => (int) $meta->meta_id,
642 642
 						'key'   => $meta->meta_key,
643
-						'value' => maybe_unserialize( $meta->meta_value ),
643
+						'value' => maybe_unserialize($meta->meta_value),
644 644
 					)
645 645
 				);
646 646
 			}
647 647
 
648
-			if ( ! $cache_loaded && ! empty( $this->cache_group ) ) {
649
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
648
+			if (!$cache_loaded && !empty($this->cache_group)) {
649
+				wp_cache_set($cache_key, $raw_meta_data, $this->cache_group);
650 650
 			}
651 651
 		}
652 652
 	}
@@ -657,28 +657,28 @@  discard block
 block discarded – undo
657 657
 	 * @since 1.0.19
658 658
 	 */
659 659
 	public function save_meta_data() {
660
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
660
+		if (!$this->data_store || is_null($this->meta_data)) {
661 661
 			return;
662 662
 		}
663
-		foreach ( $this->meta_data as $array_key => $meta ) {
664
-			if ( is_null( $meta->value ) ) {
665
-				if ( ! empty( $meta->id ) ) {
666
-					$this->data_store->delete_meta( $this, $meta );
667
-					unset( $this->meta_data[ $array_key ] );
663
+		foreach ($this->meta_data as $array_key => $meta) {
664
+			if (is_null($meta->value)) {
665
+				if (!empty($meta->id)) {
666
+					$this->data_store->delete_meta($this, $meta);
667
+					unset($this->meta_data[$array_key]);
668 668
 				}
669
-			} elseif ( empty( $meta->id ) ) {
670
-				$meta->id = $this->data_store->add_meta( $this, $meta );
669
+			} elseif (empty($meta->id)) {
670
+				$meta->id = $this->data_store->add_meta($this, $meta);
671 671
 				$meta->apply_changes();
672 672
 			} else {
673
-				if ( $meta->get_changes() ) {
674
-					$this->data_store->update_meta( $this, $meta );
673
+				if ($meta->get_changes()) {
674
+					$this->data_store->update_meta($this, $meta);
675 675
 					$meta->apply_changes();
676 676
 				}
677 677
 			}
678 678
 		}
679
-		if ( ! empty( $this->cache_group ) ) {
680
-			$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();
681
-			wp_cache_delete( $cache_key, $this->cache_group );
679
+		if (!empty($this->cache_group)) {
680
+			$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();
681
+			wp_cache_delete($cache_key, $this->cache_group);
682 682
 		}
683 683
 	}
684 684
 
@@ -688,8 +688,8 @@  discard block
 block discarded – undo
688 688
 	 * @since 1.0.19
689 689
 	 * @param int $id ID.
690 690
 	 */
691
-	public function set_id( $id ) {
692
-		$this->id = absint( $id );
691
+	public function set_id($id) {
692
+		$this->id = absint($id);
693 693
 	}
694 694
 
695 695
 	/**
@@ -699,10 +699,10 @@  discard block
 block discarded – undo
699 699
 	 * @param string $status New status.
700 700
 	 * @return array details of change.
701 701
 	 */
702
-	public function set_status( $status ) {
702
+	public function set_status($status) {
703 703
         $old_status = $this->get_status();
704 704
 
705
-		$this->set_prop( 'status', $status );
705
+		$this->set_prop('status', $status);
706 706
 
707 707
 		return array(
708 708
 			'from' => $old_status,
@@ -718,7 +718,7 @@  discard block
 block discarded – undo
718 718
 	public function set_defaults() {
719 719
 		$this->data    = $this->default_data;
720 720
 		$this->changes = array();
721
-		$this->set_object_read( false );
721
+		$this->set_object_read(false);
722 722
 	}
723 723
 
724 724
 	/**
@@ -727,7 +727,7 @@  discard block
 block discarded – undo
727 727
 	 * @since 1.0.19
728 728
 	 * @param boolean $read Should read?.
729 729
 	 */
730
-	public function set_object_read( $read = true ) {
730
+	public function set_object_read($read = true) {
731 731
 		$this->object_read = (bool) $read;
732 732
 	}
733 733
 
@@ -752,32 +752,32 @@  discard block
 block discarded – undo
752 752
 	 *
753 753
 	 * @return bool|WP_Error
754 754
 	 */
755
-	public function set_props( $props, $context = 'set' ) {
755
+	public function set_props($props, $context = 'set') {
756 756
 		$errors = false;
757 757
 
758
-		foreach ( $props as $prop => $value ) {
758
+		foreach ($props as $prop => $value) {
759 759
 			try {
760 760
 				/**
761 761
 				 * Checks if the prop being set is allowed, and the value is not null.
762 762
 				 */
763
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
763
+				if (is_null($value) || in_array($prop, array('prop', 'date_prop', 'meta_data'), true)) {
764 764
 					continue;
765 765
 				}
766 766
 				$setter = "set_$prop";
767 767
 
768
-				if ( is_callable( array( $this, $setter ) ) ) {
769
-					$this->{$setter}( $value );
768
+				if (is_callable(array($this, $setter))) {
769
+					$this->{$setter}($value);
770 770
 				}
771
-			} catch ( Exception $e ) {
772
-				if ( ! $errors ) {
771
+			} catch (Exception $e) {
772
+				if (!$errors) {
773 773
 					$errors = new WP_Error();
774 774
 				}
775
-				$errors->add( $e->getCode(), $e->getMessage() );
775
+				$errors->add($e->getCode(), $e->getMessage());
776 776
 				$this->last_error = $e->getMessage();
777 777
 			}
778 778
 		}
779 779
 
780
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
780
+		return $errors && count($errors->get_error_codes()) ? $errors : true;
781 781
 	}
782 782
 
783 783
 	/**
@@ -790,14 +790,14 @@  discard block
 block discarded – undo
790 790
 	 * @param string $prop Name of prop to set.
791 791
 	 * @param mixed  $value Value of the prop.
792 792
 	 */
793
-	protected function set_prop( $prop, $value ) {
794
-		if ( array_key_exists( $prop, $this->data ) ) {
795
-			if ( true === $this->object_read ) {
796
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
797
-					$this->changes[ $prop ] = maybe_unserialize( $value );
793
+	protected function set_prop($prop, $value) {
794
+		if (array_key_exists($prop, $this->data)) {
795
+			if (true === $this->object_read) {
796
+				if ($value !== $this->data[$prop] || array_key_exists($prop, $this->changes)) {
797
+					$this->changes[$prop] = maybe_unserialize($value);
798 798
 				}
799 799
 			} else {
800
-				$this->data[ $prop ] = maybe_unserialize( $value );
800
+				$this->data[$prop] = maybe_unserialize($value);
801 801
 			}
802 802
 		}
803 803
 	}
@@ -818,7 +818,7 @@  discard block
 block discarded – undo
818 818
 	 * @since 1.0.19
819 819
 	 */
820 820
 	public function apply_changes() {
821
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
821
+		$this->data    = array_replace_recursive($this->data, $this->changes);
822 822
 		$this->changes = array();
823 823
 	}
824 824
 
@@ -843,14 +843,14 @@  discard block
 block discarded – undo
843 843
 	 * @param  string $context What the value is for. Valid values are view and edit.
844 844
 	 * @return mixed
845 845
 	 */
846
-	protected function get_prop( $prop, $context = 'view' ) {
846
+	protected function get_prop($prop, $context = 'view') {
847 847
 		$value = null;
848 848
 
849
-		if ( array_key_exists( $prop, $this->data ) ) {
850
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
849
+		if (array_key_exists($prop, $this->data)) {
850
+			$value = array_key_exists($prop, $this->changes) ? $this->changes[$prop] : $this->data[$prop];
851 851
 
852
-			if ( 'view' === $context ) {
853
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
852
+			if ('view' === $context) {
853
+				$value = apply_filters($this->get_hook_prefix() . $prop, $value, $this);
854 854
 			}
855 855
 		}
856 856
 
@@ -864,13 +864,13 @@  discard block
 block discarded – undo
864 864
 	 * @param string         $prop Name of prop to set.
865 865
 	 * @param string|integer $value Value of the prop.
866 866
 	 */
867
-	protected function set_date_prop( $prop, $value ) {
867
+	protected function set_date_prop($prop, $value) {
868 868
 
869
-		if ( empty( $value ) ) {
870
-			$this->set_prop( $prop, null );
869
+		if (empty($value)) {
870
+			$this->set_prop($prop, null);
871 871
 			return;
872 872
 		}
873
-		$this->set_prop( $prop, $value );
873
+		$this->set_prop($prop, $value);
874 874
 
875 875
 	}
876 876
 
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
 	 * @param string $code             Error code.
882 882
 	 * @param string $message          Error message.
883 883
 	 */
884
-	protected function error( $code, $message ) {
884
+	protected function error($code, $message) {
885 885
 		$this->last_error = $message;
886 886
 	}
887 887
 
@@ -893,7 +893,7 @@  discard block
 block discarded – undo
893 893
 	 */
894 894
 	public function exists() {
895 895
 		$id = $this->get_id();
896
-		return ! empty( $id );
896
+		return !empty($id);
897 897
 	}
898 898
 
899 899
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +271 added lines, -271 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -33,35 +33,35 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
 
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array(&$this, 'wpinv_actions'));
48 48
         
49
-        if ( class_exists( 'BuddyPress' ) ) {
50
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
49
+        if (class_exists('BuddyPress')) {
50
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
51 51
         }
52 52
 
53
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
-        add_action( 'wp_footer', array( &$this, 'wp_footer' ) );
55
-        add_action( 'widgets_init', array( &$this, 'register_widgets' ) );
56
-        add_filter( 'wpseo_exclude_from_sitemap_by_post_ids', array( $this, 'wpseo_exclude_from_sitemap_by_post_ids' ) );
53
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
54
+        add_action('wp_footer', array(&$this, 'wp_footer'));
55
+        add_action('widgets_init', array(&$this, 'register_widgets'));
56
+        add_filter('wpseo_exclude_from_sitemap_by_post_ids', array($this, 'wpseo_exclude_from_sitemap_by_post_ids'));
57 57
 
58
-        if ( is_admin() ) {
59
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
60
-            add_filter( 'admin_body_class', array( &$this, 'admin_body_class' ) );
61
-            add_action( 'admin_init', array( &$this, 'init_ayecode_connect_helper' ) );
58
+        if (is_admin()) {
59
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
60
+            add_filter('admin_body_class', array(&$this, 'admin_body_class'));
61
+            add_action('admin_init', array(&$this, 'init_ayecode_connect_helper'));
62 62
 
63 63
         } else {
64
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
64
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
65 65
         }
66 66
         
67 67
         /**
@@ -71,28 +71,28 @@  discard block
 block discarded – undo
71 71
          *
72 72
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
73 73
          */
74
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
74
+        do_action_ref_array('wpinv_actions', array(&$this));
75 75
 
76
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
76
+        add_action('admin_init', array(&$this, 'activation_redirect'));
77 77
     }
78 78
 
79 79
     /**
80 80
      * Maybe show the AyeCode Connect Notice.
81 81
      */
82
-    public function init_ayecode_connect_helper(){
82
+    public function init_ayecode_connect_helper() {
83 83
         // AyeCode Connect notice
84
-        if ( is_admin() ){
84
+        if (is_admin()) {
85 85
             // set the strings so they can be translated
86 86
             $strings = array(
87
-                'connect_title' => __("WP Invoicing - an AyeCode product!","invoicing"),
88
-                'connect_external'  => __( "Please confirm you wish to connect your site?","invoicing" ),
89
-                'connect'           => sprintf( __( "<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s","invoicing" ),"<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>","</a>" ),
90
-                'connect_button'    => __("Connect Site","invoicing"),
91
-                'connecting_button'    => __("Connecting...","invoicing"),
92
-                'error_localhost'   => __( "This service will only work with a live domain, not a localhost.","invoicing" ),
93
-                'error'             => __( "Something went wrong, please refresh and try again.","invoicing" ),
87
+                'connect_title' => __("WP Invoicing - an AyeCode product!", "invoicing"),
88
+                'connect_external'  => __("Please confirm you wish to connect your site?", "invoicing"),
89
+                'connect'           => sprintf(__("<strong>Have a license?</strong> Forget about entering license keys or downloading zip files, connect your site for instant access. %slearn more%s", "invoicing"), "<a href='https://ayecode.io/introducing-ayecode-connect/' target='_blank'>", "</a>"),
90
+                'connect_button'    => __("Connect Site", "invoicing"),
91
+                'connecting_button'    => __("Connecting...", "invoicing"),
92
+                'error_localhost'   => __("This service will only work with a live domain, not a localhost.", "invoicing"),
93
+                'error'             => __("Something went wrong, please refresh and try again.", "invoicing"),
94 94
             );
95
-            new AyeCode_Connect_Helper($strings,array('wpi-addons'));
95
+            new AyeCode_Connect_Helper($strings, array('wpi-addons'));
96 96
         }
97 97
     }
98 98
     
@@ -100,10 +100,10 @@  discard block
 block discarded – undo
100 100
         /* Internationalize the text strings used. */
101 101
         $this->load_textdomain();
102 102
 
103
-        do_action( 'wpinv_loaded' );
103
+        do_action('wpinv_loaded');
104 104
 
105 105
         // Fix oxygen page builder conflict
106
-        if ( function_exists( 'ct_css_output' ) ) {
106
+        if (function_exists('ct_css_output')) {
107 107
             wpinv_oxygen_fix_conflict();
108 108
         }
109 109
     }
@@ -113,144 +113,144 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @since 1.0
115 115
      */
116
-    public function load_textdomain( $locale = NULL ) {
117
-        if ( empty( $locale ) ) {
118
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
116
+    public function load_textdomain($locale = NULL) {
117
+        if (empty($locale)) {
118
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
119 119
         }
120 120
 
121
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
121
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
122 122
         
123
-        unload_textdomain( 'invoicing' );
124
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
125
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
123
+        unload_textdomain('invoicing');
124
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
125
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
126 126
         
127 127
         /**
128 128
          * Define language constants.
129 129
          */
130
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
130
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
131 131
     }
132 132
 
133 133
     public function includes() {
134 134
         global $wpinv_options;
135 135
 
136
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
136
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
137 137
         $wpinv_options = wpinv_get_settings();
138 138
 
139 139
         // Load composer packages.
140
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
140
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
141 141
 
142 142
         // load AUI
143
-        require_once( WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php' );
143
+        require_once(WPINV_PLUGIN_DIR . 'vendor/ayecode/wp-ayecode-ui/ayecode-ui-loader.php');
144 144
 
145 145
         // Load the action scheduler.
146
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php' );
146
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/action-scheduler/action-scheduler.php');
147 147
 
148 148
         // Load functions.
149
-        require_once( WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php' );
150
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
151
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
152
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
153
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
154
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
155
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
156
-        require_once( WPINV_PLUGIN_DIR . 'includes/invoice-functions.php' );
157
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
158
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
160
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
161
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
162
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
149
+        require_once(WPINV_PLUGIN_DIR . 'includes/deprecated-functions.php');
150
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
151
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
152
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
153
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
154
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
155
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
156
+        require_once(WPINV_PLUGIN_DIR . 'includes/invoice-functions.php');
157
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
158
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
160
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
161
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
162
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
163 163
 
164 164
         // Register autoloader.
165 165
 		try {
166
-			spl_autoload_register( array( $this, 'autoload' ), true );
167
-		} catch ( Exception $e ) {
168
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
169
-        }
170
-
171
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php' );
172
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
173
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
174
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php' );
175
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
176
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
177
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php' );
178
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php' );
179
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
180
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
181
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
182
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
183
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
184
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
185
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
186
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
187
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
188
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
189
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php' );
190
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
191
-        require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
192
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
193
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
194
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
195
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
196
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
197
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
198
-        require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
199
-        require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
200
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
201
-
202
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
203
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
166
+			spl_autoload_register(array($this, 'autoload'), true);
167
+		} catch (Exception $e) {
168
+			wpinv_error_log($e->getMessage(), '', __FILE__, 149, true);
169
+        }
170
+
171
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php');
172
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
173
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
174
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-discount.php');
175
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
176
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
177
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-session.php');
178
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session-handler.php');
179
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
180
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
181
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
182
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
183
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
184
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
185
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
186
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
187
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
188
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
189
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstracts/abstract-wpinv-privacy.php');
190
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
191
+        require_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php');
192
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php');
193
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/checkout.php');
194
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-history.php');
195
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php');
196
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php');
197
+	    require_once(WPINV_PLUGIN_DIR . 'widgets/subscriptions.php');
198
+        require_once(WPINV_PLUGIN_DIR . 'widgets/buy-item.php');
199
+        require_once(WPINV_PLUGIN_DIR . 'widgets/getpaid.php');
200
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php');
201
+
202
+        if (!class_exists('WPInv_EUVat')) {
203
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
204 204
         }
205 205
         
206
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
207
-        if ( !empty( $gateways ) ) {
208
-            foreach ( $gateways as $gateway ) {
209
-                if ( $gateway == 'manual' ) {
206
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
207
+        if (!empty($gateways)) {
208
+            foreach ($gateways as $gateway) {
209
+                if ($gateway == 'manual') {
210 210
                     continue;
211 211
                 }
212 212
                 
213 213
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
214 214
                 
215
-                if ( file_exists( $gateway_file ) ) {
216
-                    require_once( $gateway_file );
215
+                if (file_exists($gateway_file)) {
216
+                    require_once($gateway_file);
217 217
                 }
218 218
             }
219 219
         }
220
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
220
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
221 221
         
222
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
222
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
223 223
             GetPaid_Post_Types_Admin::init();
224 224
 
225
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
226
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
225
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
226
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
227 227
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
228
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php' );
229
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
230
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
231
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
232
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
233
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php' );
228
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-payment-form.php');
229
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
230
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
231
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
232
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
233
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-getpaid-admin-profile.php');
234 234
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
235 235
             // load the user class only on the users.php page
236 236
             global $pagenow;
237
-            if($pagenow=='users.php'){
237
+            if ($pagenow == 'users.php') {
238 238
                 new WPInv_Admin_Users();
239 239
             }
240 240
         }
241 241
 
242 242
         // Register cli commands
243
-        if ( defined( 'WP_CLI' ) && WP_CLI ) {
244
-            require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php' );
245
-            WP_CLI::add_command( 'invoicing', 'WPInv_CLI' );
243
+        if (defined('WP_CLI') && WP_CLI) {
244
+            require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cli.php');
245
+            WP_CLI::add_command('invoicing', 'WPInv_CLI');
246 246
         }
247 247
         
248 248
         // include css inliner
249
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
250
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
249
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
250
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
251 251
         }
252 252
         
253
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
253
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
254 254
     }
255 255
 
256 256
     /**
@@ -261,18 +261,18 @@  discard block
 block discarded – undo
261 261
 	 * @since       1.0.19
262 262
 	 * @return      void
263 263
 	 */
264
-	public function autoload( $class_name ) {
264
+	public function autoload($class_name) {
265 265
 
266 266
 		// Normalize the class name...
267
-		$class_name  = strtolower( $class_name );
267
+		$class_name = strtolower($class_name);
268 268
 
269 269
 		// ... and make sure it is our class.
270
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
270
+		if (false === strpos($class_name, 'getpaid_') && false === strpos($class_name, 'wpinv_')) {
271 271
 			return;
272 272
 		}
273 273
 
274 274
 		// Next, prepare the file name from the class.
275
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
275
+		$file_name = 'class-' . str_replace('_', '-', $class_name) . '.php';
276 276
 
277 277
 		// And an array of possible locations in order of importance.
278 278
 		$locations = array(
@@ -283,11 +283,11 @@  discard block
 block discarded – undo
283 283
 		);
284 284
 
285 285
 		// Base path of the classes.
286
-		$plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
286
+		$plugin_path = untrailingslashit(WPINV_PLUGIN_DIR);
287 287
 
288
-		foreach ( $locations as $location ) {
288
+		foreach ($locations as $location) {
289 289
 
290
-			if ( file_exists( "$plugin_path/$location/$file_name" ) ) {
290
+			if (file_exists("$plugin_path/$location/$file_name")) {
291 291
 				include "$plugin_path/$location/$file_name";
292 292
 				break;
293 293
 			}
@@ -301,117 +301,117 @@  discard block
 block discarded – undo
301 301
     
302 302
     public function admin_init() {
303 303
         self::$instance->default_payment_form = wpinv_get_default_payment_form();
304
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
304
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
305 305
     }
306 306
 
307 307
     public function activation_redirect() {
308 308
         // Bail if no activation redirect
309
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
309
+        if (!get_transient('_wpinv_activation_redirect')) {
310 310
             return;
311 311
         }
312 312
 
313 313
         // Delete the redirect transient
314
-        delete_transient( '_wpinv_activation_redirect' );
314
+        delete_transient('_wpinv_activation_redirect');
315 315
 
316 316
         // Bail if activating from network, or bulk
317
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
317
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
318 318
             return;
319 319
         }
320 320
 
321
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
321
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
322 322
         exit;
323 323
     }
324 324
     
325 325
     public function enqueue_scripts() {
326
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
326
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
327 327
         
328
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css' );
329
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version );
330
-        wp_enqueue_style( 'wpinv_front_style' );
328
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/invoice-front.css');
329
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), $version);
330
+        wp_enqueue_style('wpinv_front_style');
331 331
                
332 332
         // Register scripts
333
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
334
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  filemtime( WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js' ) );
333
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
334
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), filemtime(WPINV_PLUGIN_DIR . 'assets/js/invoice-front.js'));
335 335
 
336 336
         $localize                         = array();
337
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
338
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
337
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
338
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
339 339
         $localize['currency_symbol']      = wpinv_currency_symbol();
340 340
         $localize['currency_pos']         = wpinv_currency_position();
341 341
         $localize['thousand_sep']         = wpinv_thousands_separator();
342 342
         $localize['decimal_sep']          = wpinv_decimal_separator();
343 343
         $localize['decimals']             = wpinv_decimals();
344
-        $localize['txtComplete']          = __( 'Continue', 'invoicing' );
344
+        $localize['txtComplete']          = __('Continue', 'invoicing');
345 345
         $localize['UseTaxes']             = wpinv_use_taxes();
346
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
347
-        $localize['formNonce']            = wp_create_nonce( 'getpaid_form_nonce' );
348
-        $localize['connectionError']      = __( 'Could not establish a connection to the server.', 'invoicing' );
346
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
347
+        $localize['formNonce']            = wp_create_nonce('getpaid_form_nonce');
348
+        $localize['connectionError']      = __('Could not establish a connection to the server.', 'invoicing');
349 349
 
350
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
350
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
351 351
         
352
-        wp_enqueue_script( 'jquery-blockui' );
352
+        wp_enqueue_script('jquery-blockui');
353 353
         $autofill_api = wpinv_get_option('address_autofill_api');
354 354
         $autofill_active = wpinv_get_option('address_autofill_active');
355
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
356
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
357
-                wp_dequeue_script( 'google-maps-api' );
355
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
356
+            if (wp_script_is('google-maps-api', 'enqueued')) {
357
+                wp_dequeue_script('google-maps-api');
358 358
             }
359
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
360
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
359
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
360
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
361 361
         }
362 362
 
363
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
364
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
363
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
364
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
365 365
 
366
-        wp_enqueue_script( 'wpinv-front-script' );
367
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
366
+        wp_enqueue_script('wpinv-front-script');
367
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
368 368
 
369
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js' );
370
-        wp_enqueue_script( 'wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array( 'wpinv-front-script', 'wp-hooks' ),  $version, true );
369
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/payment-forms.js');
370
+        wp_enqueue_script('wpinv-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/payment-forms.js', array('wpinv-front-script', 'wp-hooks'), $version, true);
371 371
     }
372 372
 
373
-    public function admin_enqueue_scripts( $hook ) {
373
+    public function admin_enqueue_scripts($hook) {
374 374
         global $post, $pagenow;
375 375
         
376 376
         $post_type  = wpinv_admin_post_type();
377
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
378
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
377
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
378
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
379 379
 
380 380
         $jquery_ui_css = false;
381
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
381
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
382 382
             $jquery_ui_css = true;
383
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
383
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
384 384
             $jquery_ui_css = true;
385 385
         }
386
-        if ( $jquery_ui_css ) {
387
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
388
-            wp_enqueue_style( 'jquery-ui-css' );
389
-            wp_deregister_style( 'yoast-seo-select2' );
390
-	        wp_deregister_style( 'yoast-seo-monorepo' );
386
+        if ($jquery_ui_css) {
387
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
388
+            wp_enqueue_style('jquery-ui-css');
389
+            wp_deregister_style('yoast-seo-select2');
390
+	        wp_deregister_style('yoast-seo-monorepo');
391 391
         }
392 392
 
393
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
394
-        wp_enqueue_style( 'wpinv_meta_box_style' );
393
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
394
+        wp_enqueue_style('wpinv_meta_box_style');
395 395
         
396
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/css/admin.css' );
397
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version );
398
-        wp_enqueue_style( 'wpinv_admin_style' );
396
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/css/admin.css');
397
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), $version);
398
+        wp_enqueue_style('wpinv_admin_style');
399 399
 
400
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
401
-        if ( $page == 'wpinv-subscriptions' ) {
402
-            wp_enqueue_script( 'jquery-ui-datepicker' );
403
-            wp_deregister_style( 'yoast-seo-select2' );
404
-	        wp_deregister_style( 'yoast-seo-monorepo' );
400
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
401
+        if ($page == 'wpinv-subscriptions') {
402
+            wp_enqueue_script('jquery-ui-datepicker');
403
+            wp_deregister_style('yoast-seo-select2');
404
+	        wp_deregister_style('yoast-seo-monorepo');
405 405
         }
406 406
         
407
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
408
-            wp_enqueue_script( 'jquery-ui-datepicker' );
407
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
408
+            wp_enqueue_script('jquery-ui-datepicker');
409 409
         }
410 410
 
411
-        wp_enqueue_style( 'wp-color-picker' );
412
-        wp_enqueue_script( 'wp-color-picker' );
411
+        wp_enqueue_style('wp-color-picker');
412
+        wp_enqueue_script('wp-color-picker');
413 413
         
414
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
414
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
415 415
 
416 416
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
417 417
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -422,21 +422,21 @@  discard block
 block discarded – undo
422 422
             }
423 423
         }
424 424
 
425
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
426
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
425
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
426
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
427 427
 
428
-        $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin.js' );
429
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  $version );
430
-        wp_enqueue_script( 'wpinv-admin-script' );
428
+        $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin.js');
429
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), $version);
430
+        wp_enqueue_script('wpinv-admin-script');
431 431
         
432 432
         $localize                               = array();
433
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
434
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
435
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
436
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
437
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
438
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
439
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
433
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
434
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
435
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
436
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
437
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
438
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
439
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
440 440
         $localize['tax']                        = wpinv_tax_amount();
441 441
         $localize['discount']                   = wpinv_discount_amount();
442 442
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -444,104 +444,104 @@  discard block
 block discarded – undo
444 444
         $localize['thousand_sep']               = wpinv_thousands_separator();
445 445
         $localize['decimal_sep']                = wpinv_decimal_separator();
446 446
         $localize['decimals']                   = wpinv_decimals();
447
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
448
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
449
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
450
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
451
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
452
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
453
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
454
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
455
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
456
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
457
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
458
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
459
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
460
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
461
-        $localize['item_description']           = __( 'Item Description', 'invoicing' );
462
-        $localize['discount_description']       = __( 'Discount Description', 'invoicing' );
463
-        $localize['invoice_description']        = __( 'Invoice Description', 'invoicing' );
464
-        $localize['searching']                  = __( 'Searching', 'invoicing' );
465
-
466
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
467
-
468
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
447
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
448
+        $localize['status_publish']             = wpinv_status_nicename('publish');
449
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
450
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
451
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
452
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
453
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
454
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
455
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
456
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
457
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
458
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
459
+        $localize['action_edit']                = __('Edit', 'invoicing');
460
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
461
+        $localize['item_description']           = __('Item Description', 'invoicing');
462
+        $localize['discount_description']       = __('Discount Description', 'invoicing');
463
+        $localize['invoice_description']        = __('Invoice Description', 'invoicing');
464
+        $localize['searching']                  = __('Searching', 'invoicing');
465
+
466
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
467
+
468
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
469 469
 
470 470
         // Load payment form scripts on our admin pages only.
471
-        if ( ( $hook == 'post-new.php' || $hook == 'post.php' ) && 'wpi_payment_form' === $post->post_type ) {
471
+        if (($hook == 'post-new.php' || $hook == 'post.php') && 'wpi_payment_form' === $post->post_type) {
472 472
 
473
-            wp_enqueue_script( 'vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION );
474
-            wp_enqueue_script( 'sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION );
475
-            wp_enqueue_script( 'vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array( 'sortable', 'vue' ), WPINV_VERSION );
473
+            wp_enqueue_script('vue', WPINV_PLUGIN_URL . 'assets/js/vue/vue.js', array(), WPINV_VERSION);
474
+            wp_enqueue_script('sortable', WPINV_PLUGIN_URL . 'assets/js/sortable.min.js', array(), WPINV_VERSION);
475
+            wp_enqueue_script('vue_draggable', WPINV_PLUGIN_URL . 'assets/js/vue/vuedraggable.min.js', array('sortable', 'vue'), WPINV_VERSION);
476 476
 
477
-            $version = filemtime( WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js' );
478
-            wp_register_script( 'wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array( 'wpinv-admin-script', 'vue_draggable' ),  $version );
477
+            $version = filemtime(WPINV_PLUGIN_DIR . 'assets/js/admin-payment-forms.js');
478
+            wp_register_script('wpinv-admin-payment-form-script', WPINV_PLUGIN_URL . 'assets/js/admin-payment-forms.js', array('wpinv-admin-script', 'vue_draggable'), $version);
479 479
         
480
-            wp_localize_script( 'wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
480
+            wp_localize_script('wpinv-admin-payment-form-script', 'wpinvPaymentFormAdmin', array(
481 481
                 'elements'      => $this->form_elements->get_elements(),
482
-                'form_elements' => $this->form_elements->get_form_elements( $post->ID ),
482
+                'form_elements' => $this->form_elements->get_form_elements($post->ID),
483 483
                 'all_items'     => $this->form_elements->get_published_items(),
484 484
                 'currency'      => wpinv_currency_symbol(),
485 485
                 'position'      => wpinv_currency_position(),
486 486
                 'decimals'      => (int) wpinv_decimals(),
487 487
                 'thousands_sep' => wpinv_thousands_separator(),
488 488
                 'decimals_sep'  => wpinv_decimal_separator(),
489
-                'form_items'    => $this->form_elements->get_form_items( $post->ID ),
489
+                'form_items'    => $this->form_elements->get_form_items($post->ID),
490 490
                 'is_default'    => $post->ID == $this->default_payment_form,
491
-            ) );
491
+            ));
492 492
 
493
-            wp_enqueue_script( 'wpinv-admin-payment-form-script' );
493
+            wp_enqueue_script('wpinv-admin-payment-form-script');
494 494
         }
495 495
 
496
-        if ( $page == 'wpinv-subscriptions' ) {
497
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
498
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
496
+        if ($page == 'wpinv-subscriptions') {
497
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
498
+            wp_enqueue_script('wpinv-sub-admin-script');
499 499
         }
500 500
 
501
-        if ( $page == 'wpinv-reports' ) {
502
-            wp_enqueue_script( 'jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array( 'jquery' ), '0.7' );
501
+        if ($page == 'wpinv-reports') {
502
+            wp_enqueue_script('jquery-flot', WPINV_PLUGIN_URL . 'assets/js/jquery.flot.min.js', array('jquery'), '0.7');
503 503
         }
504 504
 
505 505
     }
506 506
 
507
-    public function admin_body_class( $classes ) {
507
+    public function admin_body_class($classes) {
508 508
         global $pagenow, $post, $current_screen;
509 509
         
510
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote' ) ) {
510
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_payment_form' || $current_screen->post_type == 'wpi_quote')) {
511 511
             $classes .= ' wpinv-cpt';
512 512
         }
513 513
         
514
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
514
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
515 515
 
516
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
517
-        if ( $add_class ) {
518
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
516
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
517
+        if ($add_class) {
518
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
519 519
         }
520 520
         
521 521
         $settings_class = array();
522
-        if ( $page == 'wpinv-settings' ) {
523
-            if ( !empty( $_REQUEST['tab'] ) ) {
524
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
522
+        if ($page == 'wpinv-settings') {
523
+            if (!empty($_REQUEST['tab'])) {
524
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
525 525
             }
526 526
             
527
-            if ( !empty( $_REQUEST['section'] ) ) {
528
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
527
+            if (!empty($_REQUEST['section'])) {
528
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
529 529
             }
530 530
             
531
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
531
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
532 532
         }
533 533
         
534
-        if ( !empty( $settings_class ) ) {
535
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
534
+        if (!empty($settings_class)) {
535
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
536 536
         }
537 537
         
538 538
         $post_type = wpinv_admin_post_type();
539 539
 
540
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
540
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
541 541
             return $classes .= ' wpinv';
542 542
         }
543 543
         
544
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
544
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
545 545
             $classes .= ' wpi-editable-n';
546 546
         }
547 547
 
@@ -553,21 +553,21 @@  discard block
 block discarded – undo
553 553
     }
554 554
     
555 555
     public function wpinv_actions() {
556
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
557
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
556
+        if (isset($_REQUEST['wpi_action'])) {
557
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
558 558
         }
559 559
     }
560 560
     
561
-    public function pre_get_posts( $wp_query ) {
562
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
563
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
561
+    public function pre_get_posts($wp_query) {
562
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
563
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
564 564
         }
565 565
         
566 566
         return $wp_query;
567 567
     }
568 568
     
569 569
     public function bp_invoicing_init() {
570
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
570
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
571 571
     }
572 572
 
573 573
 	/**
@@ -575,13 +575,13 @@  discard block
 block discarded – undo
575 575
 	 *
576 576
 	 */
577 577
 	public function register_widgets() {
578
-		register_widget( "WPInv_Checkout_Widget" );
579
-		register_widget( "WPInv_History_Widget" );
580
-		register_widget( "WPInv_Receipt_Widget" );
581
-		register_widget( "WPInv_Subscriptions_Widget" );
582
-		register_widget( "WPInv_Buy_Item_Widget" );
583
-        register_widget( "WPInv_Messages_Widget" );
584
-        register_widget( 'WPInv_GetPaid_Widget' );
578
+		register_widget("WPInv_Checkout_Widget");
579
+		register_widget("WPInv_History_Widget");
580
+		register_widget("WPInv_Receipt_Widget");
581
+		register_widget("WPInv_Subscriptions_Widget");
582
+		register_widget("WPInv_Buy_Item_Widget");
583
+        register_widget("WPInv_Messages_Widget");
584
+        register_widget('WPInv_GetPaid_Widget');
585 585
 	}
586 586
     
587 587
     /**
@@ -590,10 +590,10 @@  discard block
 block discarded – undo
590 590
      * @since 1.0.19
591 591
      * @param int[] $excluded_posts_ids
592 592
      */
593
-    public function wpseo_exclude_from_sitemap_by_post_ids( $excluded_posts_ids ){
593
+    public function wpseo_exclude_from_sitemap_by_post_ids($excluded_posts_ids) {
594 594
 
595 595
         // Ensure that we have an array.
596
-        if ( ! is_array( $excluded_posts_ids ) ) {
596
+        if (!is_array($excluded_posts_ids)) {
597 597
             $excluded_posts_ids = array();
598 598
         }
599 599
 
@@ -601,24 +601,24 @@  discard block
 block discarded – undo
601 601
         $our_pages = array();
602 602
     
603 603
         // Checkout page.
604
-        $our_pages[] = wpinv_get_option( 'checkout_page', false );
604
+        $our_pages[] = wpinv_get_option('checkout_page', false);
605 605
 
606 606
         // Success page.
607
-        $our_pages[] = wpinv_get_option( 'success_page', false );
607
+        $our_pages[] = wpinv_get_option('success_page', false);
608 608
 
609 609
         // Failure page.
610
-        $our_pages[] = wpinv_get_option( 'failure_page', false );
610
+        $our_pages[] = wpinv_get_option('failure_page', false);
611 611
 
612 612
         // History page.
613
-        $our_pages[] = wpinv_get_option( 'invoice_history_page', false );
613
+        $our_pages[] = wpinv_get_option('invoice_history_page', false);
614 614
 
615 615
         // Subscriptions page.
616
-        $our_pages[] = wpinv_get_option( 'invoice_subscription_page', false );
616
+        $our_pages[] = wpinv_get_option('invoice_subscription_page', false);
617 617
 
618
-        $our_pages   = array_map( 'intval', array_filter( $our_pages ) );
618
+        $our_pages   = array_map('intval', array_filter($our_pages));
619 619
 
620 620
         $excluded_posts_ids = $excluded_posts_ids + $our_pages;
621
-        return array_unique( $excluded_posts_ids );
621
+        return array_unique($excluded_posts_ids);
622 622
 
623 623
     }
624 624
 
Please login to merge, or discard this patch.
includes/invoice-functions.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69 69
 function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
70
+    return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
71 71
 }
72 72
 
73 73
 /**
Please login to merge, or discard this patch.
Spacing   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves the current invoice.
@@ -14,15 +14,15 @@  discard block
 block discarded – undo
14 14
 function getpaid_get_current_invoice_id() {
15 15
 
16 16
     // Ensure that we have an invoice key.
17
-    if ( empty( $_GET['invoice_key'] ) ) {
17
+    if (empty($_GET['invoice_key'])) {
18 18
         return 0;
19 19
     }
20 20
 
21 21
     // Retrieve an invoice using the key.
22
-    $invoice = new WPInv_Invoice( $_GET['invoice_key'] );
22
+    $invoice = new WPInv_Invoice($_GET['invoice_key']);
23 23
 
24 24
     // Compare the invoice key and the parsed key.
25
-    if ( $invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key'] ) {
25
+    if ($invoice->get_id() != 0 && $invoice->get_key() == $_GET['invoice_key']) {
26 26
         return $invoice->get_id();
27 27
     }
28 28
 
@@ -32,42 +32,42 @@  discard block
 block discarded – undo
32 32
 /**
33 33
  * Checks if the current user cna view an invoice.
34 34
  */
35
-function wpinv_user_can_view_invoice( $invoice ) {
36
-    $invoice = new WPInv_Invoice( $invoice );
35
+function wpinv_user_can_view_invoice($invoice) {
36
+    $invoice = new WPInv_Invoice($invoice);
37 37
 
38 38
     // Abort if the invoice does not exist.
39
-    if ( 0 == $invoice->get_id() ) {
39
+    if (0 == $invoice->get_id()) {
40 40
         return false;
41 41
     }
42 42
 
43 43
     // Don't allow trash, draft status
44
-    if ( $invoice->is_draft() ) {
44
+    if ($invoice->is_draft()) {
45 45
         return false;
46 46
     }
47 47
 
48 48
     // If users are not required to login to check out, compare the invoice keys.
49
-    if ( ! wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && trim( $_GET['invoice_key'] ) == $invoice->get_key() ) {
49
+    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && trim($_GET['invoice_key']) == $invoice->get_key()) {
50 50
         return true;
51 51
     }
52 52
 
53 53
     // Always enable for admins..
54
-    if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->get_id() ) ) { // Admin user
54
+    if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->get_id())) { // Admin user
55 55
         return true;
56 56
     }
57 57
 
58 58
     // Else, ensure that this is their invoice.
59
-    if ( is_user_logged_in() && $invoice->get_user_id() == get_current_user_id() ) {
59
+    if (is_user_logged_in() && $invoice->get_user_id() == get_current_user_id()) {
60 60
         return true;
61 61
     }
62 62
 
63
-    return apply_filters( 'wpinv_current_user_can_view_invoice', false, $invoice );
63
+    return apply_filters('wpinv_current_user_can_view_invoice', false, $invoice);
64 64
 }
65 65
 
66 66
 /**
67 67
  * Checks if the current user cna view an invoice receipt.
68 68
  */
69
-function wpinv_can_view_receipt( $invoice ) {
70
-	return (bool) apply_filters( 'wpinv_can_view_receipt', wpinv_user_can_view_invoice( $invoice ), $invoice );
69
+function wpinv_can_view_receipt($invoice) {
70
+	return (bool) apply_filters('wpinv_can_view_receipt', wpinv_user_can_view_invoice($invoice), $invoice);
71 71
 }
72 72
 
73 73
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function getpaid_get_invoice_post_types() {
79 79
     $post_types = array(
80
-        'wpi_quote'   => __( 'Quote', 'invoicing' ),
81
-        'wpi_invoice' => __( 'Invoice', 'invoicing' ),
80
+        'wpi_quote'   => __('Quote', 'invoicing'),
81
+        'wpi_invoice' => __('Invoice', 'invoicing'),
82 82
     );
83 83
 
84
-    return apply_filters( 'getpaid_invoice_post_types', $post_types );
84
+    return apply_filters('getpaid_invoice_post_types', $post_types);
85 85
 }
86 86
 
87 87
 /**
@@ -90,8 +90,8 @@  discard block
 block discarded – undo
90 90
  * 
91 91
  * @param string $post_type The post type to check for.
92 92
  */
93
-function getpaid_is_invoice_post_type( $post_type ) {
94
-    return ! empty( $post_type ) && array_key_exists( $post_type, getpaid_get_invoice_post_types() );
93
+function getpaid_is_invoice_post_type($post_type) {
94
+    return !empty($post_type) && array_key_exists($post_type, getpaid_get_invoice_post_types());
95 95
 }
96 96
 
97 97
 /**
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
102 102
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
103 103
  */
104
-function wpinv_create_invoice( $data = array(), $deprecated = null, $wp_error = false ) {
105
-    $data[ 'invoice_id' ] = 0;
106
-    return wpinv_insert_invoice( $data, $wp_error );
104
+function wpinv_create_invoice($data = array(), $deprecated = null, $wp_error = false) {
105
+    $data['invoice_id'] = 0;
106
+    return wpinv_insert_invoice($data, $wp_error);
107 107
 }
108 108
 
109 109
 /**
@@ -113,36 +113,36 @@  discard block
 block discarded – undo
113 113
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
114 114
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
115 115
  */
116
-function wpinv_update_invoice( $data = array(), $wp_error = false ) {
116
+function wpinv_update_invoice($data = array(), $wp_error = false) {
117 117
 
118 118
     // Backwards compatibility.
119
-    if ( ! empty( $data['ID'] ) ) {
119
+    if (!empty($data['ID'])) {
120 120
         $data['invoice_id'] = $data['ID'];
121 121
     }
122 122
 
123 123
     // Do we have an invoice id?
124
-    if ( empty( $data['invoice_id'] ) ) {
125
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) ) : 0;
124
+    if (empty($data['invoice_id'])) {
125
+        return $wp_error ? new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing')) : 0;
126 126
     }
127 127
 
128 128
     // Retrieve the invoice.
129
-    $invoice = wpinv_get_invoice( $data['invoice_id'] );
129
+    $invoice = wpinv_get_invoice($data['invoice_id']);
130 130
 
131 131
     // And abort if it does not exist.
132
-    if ( empty( $invoice ) ) {
133
-        return $wp_error ? new WP_Error( 'missing_invoice', __( 'Invoice not found.', 'invoicing' ) ) : 0;
132
+    if (empty($invoice)) {
133
+        return $wp_error ? new WP_Error('missing_invoice', __('Invoice not found.', 'invoicing')) : 0;
134 134
     }
135 135
 
136 136
     // Do not update totals for paid / refunded invoices.
137
-    if ( $invoice->is_paid() || $invoice->is_refunded() ) {
137
+    if ($invoice->is_paid() || $invoice->is_refunded()) {
138 138
 
139
-        if ( ! empty( $data['items'] ) || ! empty( $data['cart_details'] ) ) {
140
-            return $wp_error ? new WP_Error( 'paid_invoice', __( 'You can not update cart items for invoices that have already been paid for.', 'invoicing' ) ) : 0;
139
+        if (!empty($data['items']) || !empty($data['cart_details'])) {
140
+            return $wp_error ? new WP_Error('paid_invoice', __('You can not update cart items for invoices that have already been paid for.', 'invoicing')) : 0;
141 141
         }
142 142
 
143 143
     }
144 144
 
145
-    return wpinv_insert_invoice( $data, $wp_error );
145
+    return wpinv_insert_invoice($data, $wp_error);
146 146
 
147 147
 }
148 148
 
@@ -153,34 +153,34 @@  discard block
 block discarded – undo
153 153
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
154 154
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
155 155
  */
156
-function wpinv_insert_invoice( $data = array(), $wp_error = false ) {
156
+function wpinv_insert_invoice($data = array(), $wp_error = false) {
157 157
 
158 158
     // Ensure that we have invoice data.
159
-    if ( empty( $data ) ) {
159
+    if (empty($data)) {
160 160
         return false;
161 161
     }
162 162
 
163 163
     // The invoice id will be provided when updating an invoice.
164
-    $data['invoice_id'] = ! empty( $data['invoice_id'] ) ? (int) $data['invoice_id'] : false;
164
+    $data['invoice_id'] = !empty($data['invoice_id']) ? (int) $data['invoice_id'] : false;
165 165
 
166 166
     // Retrieve the invoice.
167
-    $invoice = new WPInv_Invoice( $data['invoice_id'] );
167
+    $invoice = new WPInv_Invoice($data['invoice_id']);
168 168
 
169 169
     // Do we have an error?
170
-    if ( ! empty( $invoice->last_error ) ) {
171
-        return $wp_error ? new WP_Error( 'invalid_invoice_id', $invoice->last_error ) : 0;
170
+    if (!empty($invoice->last_error)) {
171
+        return $wp_error ? new WP_Error('invalid_invoice_id', $invoice->last_error) : 0;
172 172
     }
173 173
 
174 174
     // Backwards compatibility (billing address).
175
-    if ( ! empty( $data['user_info'] ) ) {
175
+    if (!empty($data['user_info'])) {
176 176
 
177
-        foreach ( $data['user_info'] as $key => $value ) {
177
+        foreach ($data['user_info'] as $key => $value) {
178 178
 
179
-            if ( $key == 'discounts' ) {
179
+            if ($key == 'discounts') {
180 180
                 $value = (array) $value;
181
-                $data[ 'discount_code' ] = empty( $value ) ? null : $value[0];
181
+                $data['discount_code'] = empty($value) ? null : $value[0];
182 182
             } else {
183
-                $data[ $key ] = $value;
183
+                $data[$key] = $value;
184 184
             }
185 185
 
186 186
         }
@@ -188,30 +188,30 @@  discard block
 block discarded – undo
188 188
     }
189 189
 
190 190
     // Backwards compatibility.
191
-    if ( ! empty( $data['payment_details'] ) ) {
191
+    if (!empty($data['payment_details'])) {
192 192
 
193
-        foreach ( $data['payment_details'] as $key => $value ) {
194
-            $data[ $key ] = $value;
193
+        foreach ($data['payment_details'] as $key => $value) {
194
+            $data[$key] = $value;
195 195
         }
196 196
 
197 197
     }
198 198
 
199 199
     // Set up the owner of the invoice.
200
-    $user_id = ! empty( $data['user_id'] ) ? wpinv_clean( $data['user_id'] ) : get_current_user_id();
200
+    $user_id = !empty($data['user_id']) ? wpinv_clean($data['user_id']) : get_current_user_id();
201 201
 
202 202
     // Make sure the user exists.
203
-    if ( ! get_userdata( $user_id ) ) {
204
-        return $wp_error ? new WP_Error( 'wpinv_invalid_user', __( 'There is no user with that ID.', 'invoicing' ) ) : 0;
203
+    if (!get_userdata($user_id)) {
204
+        return $wp_error ? new WP_Error('wpinv_invalid_user', __('There is no user with that ID.', 'invoicing')) : 0;
205 205
     }
206 206
 
207
-    $address = wpinv_get_user_address( $user_id );
207
+    $address = wpinv_get_user_address($user_id);
208 208
 
209
-    foreach ( $address as $key => $value ) {
209
+    foreach ($address as $key => $value) {
210 210
 
211
-        if ( $value == '' ) {
212
-            $address[ $key ] = null;
211
+        if ($value == '') {
212
+            $address[$key] = null;
213 213
         } else {
214
-            $address[ $key ] = wpinv_clean( $value );
214
+            $address[$key] = wpinv_clean($value);
215 215
         }
216 216
 
217 217
     }
@@ -222,103 +222,103 @@  discard block
 block discarded – undo
222 222
         array(
223 223
 
224 224
             // Basic info.
225
-            'template'             => isset( $data['template'] ) ? wpinv_clean( $data['template'] ) : null,
226
-            'email_cc'             => isset( $data['email_cc'] ) ? wpinv_clean( $data['email_cc'] ) : null,
227
-            'date_created'         => isset( $data['created_date'] ) ? wpinv_clean( $data['created_date'] ) : null,
228
-            'due_date'             => isset( $data['due_date'] ) ? wpinv_clean( $data['due_date'] ) : null,
229
-            'date_completed'       => isset( $data['date_completed'] ) ? wpinv_clean( $data['date_completed'] ) : null,
230
-            'number'               => isset( $data['number'] ) ? wpinv_clean( $data['number'] ) : null,
231
-            'key'                  => isset( $data['key'] ) ? wpinv_clean( $data['key'] ) : null,
232
-            'status'               => isset( $data['status'] ) ? wpinv_clean( $data['status'] ) : null,
233
-            'post_type'            => isset( $data['post_type'] ) ? wpinv_clean( $data['post_type'] ) : null,
234
-            'user_ip'              => isset( $data['ip'] ) ? wpinv_clean( $data['ip'] ) : wpinv_get_ip(),
235
-            'parent_id'            => isset( $data['parent'] ) ? intval( $data['parent'] ) : null,
236
-            'mode'                 => isset( $data['mode'] ) ? wpinv_clean( $data['mode'] ) : null,
237
-            'description'          => isset( $data['description'] ) ? wp_kses_post( $data['description'] ) : null,
225
+            'template'             => isset($data['template']) ? wpinv_clean($data['template']) : null,
226
+            'email_cc'             => isset($data['email_cc']) ? wpinv_clean($data['email_cc']) : null,
227
+            'date_created'         => isset($data['created_date']) ? wpinv_clean($data['created_date']) : null,
228
+            'due_date'             => isset($data['due_date']) ? wpinv_clean($data['due_date']) : null,
229
+            'date_completed'       => isset($data['date_completed']) ? wpinv_clean($data['date_completed']) : null,
230
+            'number'               => isset($data['number']) ? wpinv_clean($data['number']) : null,
231
+            'key'                  => isset($data['key']) ? wpinv_clean($data['key']) : null,
232
+            'status'               => isset($data['status']) ? wpinv_clean($data['status']) : null,
233
+            'post_type'            => isset($data['post_type']) ? wpinv_clean($data['post_type']) : null,
234
+            'user_ip'              => isset($data['ip']) ? wpinv_clean($data['ip']) : wpinv_get_ip(),
235
+            'parent_id'            => isset($data['parent']) ? intval($data['parent']) : null,
236
+            'mode'                 => isset($data['mode']) ? wpinv_clean($data['mode']) : null,
237
+            'description'          => isset($data['description']) ? wp_kses_post($data['description']) : null,
238 238
 
239 239
             // Payment info.
240
-            'disable_taxes'        => ! empty( $data['disable_taxes'] ),
241
-            'currency'             => isset( $data['currency'] ) ? wpinv_clean( $data['currency'] ) : wpinv_get_currency(),
242
-            'gateway'              => isset( $data['gateway'] ) ? wpinv_clean( $data['gateway'] ) : null,
243
-            'transaction_id'       => isset( $data['transaction_id'] ) ? wpinv_clean( $data['transaction_id'] ) : null,
244
-            'discount_code'        => isset( $data['discount_code'] ) ? wpinv_clean( $data['discount_code'] ) : null,
245
-            'payment_form'         => isset( $data['payment_form'] ) ? intval( $data['payment_form'] ) : null,
246
-            'submission_id'        => isset( $data['submission_id'] ) ? wpinv_clean( $data['submission_id'] ) : null,
247
-            'subscription_id'      => isset( $data['subscription_id'] ) ? wpinv_clean( $data['subscription_id'] ) : null,
248
-            'is_viewed'            => isset( $data['is_viewed'] ) ? wpinv_clean( $data['is_viewed'] ) : null,
249
-            'fees'                 => isset( $data['fees'] ) ? wpinv_clean( $data['fees'] ) : null,
250
-            'discounts'            => isset( $data['discounts'] ) ? wpinv_clean( $data['discounts'] ) : null,
251
-            'taxes'                => isset( $data['taxes'] ) ? wpinv_clean( $data['taxes'] ) : null,
240
+            'disable_taxes'        => !empty($data['disable_taxes']),
241
+            'currency'             => isset($data['currency']) ? wpinv_clean($data['currency']) : wpinv_get_currency(),
242
+            'gateway'              => isset($data['gateway']) ? wpinv_clean($data['gateway']) : null,
243
+            'transaction_id'       => isset($data['transaction_id']) ? wpinv_clean($data['transaction_id']) : null,
244
+            'discount_code'        => isset($data['discount_code']) ? wpinv_clean($data['discount_code']) : null,
245
+            'payment_form'         => isset($data['payment_form']) ? intval($data['payment_form']) : null,
246
+            'submission_id'        => isset($data['submission_id']) ? wpinv_clean($data['submission_id']) : null,
247
+            'subscription_id'      => isset($data['subscription_id']) ? wpinv_clean($data['subscription_id']) : null,
248
+            'is_viewed'            => isset($data['is_viewed']) ? wpinv_clean($data['is_viewed']) : null,
249
+            'fees'                 => isset($data['fees']) ? wpinv_clean($data['fees']) : null,
250
+            'discounts'            => isset($data['discounts']) ? wpinv_clean($data['discounts']) : null,
251
+            'taxes'                => isset($data['taxes']) ? wpinv_clean($data['taxes']) : null,
252 252
             
253 253
 
254 254
             // Billing details.
255 255
             'user_id'              => $data['user_id'],
256
-            'first_name'           => isset( $data['first_name'] ) ? wpinv_clean( $data['first_name'] ) : $address['first_name'],
257
-            'last_name'            => isset( $data['last_name'] ) ? wpinv_clean( $data['last_name'] ) : $address['last_name'],
258
-            'address'              => isset( $data['address'] ) ? wpinv_clean( $data['address'] ) : $address['address'] ,
259
-            'vat_number'           => isset( $data['vat_number'] ) ? wpinv_clean( $data['vat_number'] ) : $address['vat_number'],
260
-            'company'              => isset( $data['company'] ) ? wpinv_clean( $data['company'] ) : $address['company'],
261
-            'zip'                  => isset( $data['zip'] ) ? wpinv_clean( $data['zip'] ) : $address['zip'],
262
-            'state'                => isset( $data['state'] ) ? wpinv_clean( $data['state'] ) : $address['state'],
263
-            'city'                 => isset( $data['city'] ) ? wpinv_clean( $data['city'] ) : $address['city'],
264
-            'country'              => isset( $data['country'] ) ? wpinv_clean( $data['country'] ) : $address['country'],
265
-            'phone'                => isset( $data['phone'] ) ? wpinv_clean( $data['phone'] ) : $address['phone'],
266
-            'address_confirmed'    => ! empty( $data['address_confirmed'] ),
256
+            'first_name'           => isset($data['first_name']) ? wpinv_clean($data['first_name']) : $address['first_name'],
257
+            'last_name'            => isset($data['last_name']) ? wpinv_clean($data['last_name']) : $address['last_name'],
258
+            'address'              => isset($data['address']) ? wpinv_clean($data['address']) : $address['address'],
259
+            'vat_number'           => isset($data['vat_number']) ? wpinv_clean($data['vat_number']) : $address['vat_number'],
260
+            'company'              => isset($data['company']) ? wpinv_clean($data['company']) : $address['company'],
261
+            'zip'                  => isset($data['zip']) ? wpinv_clean($data['zip']) : $address['zip'],
262
+            'state'                => isset($data['state']) ? wpinv_clean($data['state']) : $address['state'],
263
+            'city'                 => isset($data['city']) ? wpinv_clean($data['city']) : $address['city'],
264
+            'country'              => isset($data['country']) ? wpinv_clean($data['country']) : $address['country'],
265
+            'phone'                => isset($data['phone']) ? wpinv_clean($data['phone']) : $address['phone'],
266
+            'address_confirmed'    => !empty($data['address_confirmed']),
267 267
 
268 268
         )
269 269
 
270 270
     );
271 271
 
272 272
     // Backwards compatibililty.
273
-    if ( ! empty( $data['cart_details'] ) && is_array( $data['cart_details'] ) ) {
273
+    if (!empty($data['cart_details']) && is_array($data['cart_details'])) {
274 274
         $data['items'] = array();
275 275
 
276
-        foreach( $data['cart_details'] as $_item ) {
276
+        foreach ($data['cart_details'] as $_item) {
277 277
 
278 278
             // Ensure that we have an item id.
279
-            if ( empty(  $_item['id']  ) ) {
279
+            if (empty($_item['id'])) {
280 280
                 continue;
281 281
             }
282 282
 
283 283
             // Retrieve the item.
284
-            $item = new GetPaid_Form_Item(  $_item['id']  );
284
+            $item = new GetPaid_Form_Item($_item['id']);
285 285
 
286 286
             // Ensure that it is purchasable.
287
-            if ( ! $item->can_purchase() ) {
287
+            if (!$item->can_purchase()) {
288 288
                 continue;
289 289
             }
290 290
 
291 291
             // Set quantity.
292
-            if ( ! empty( $_item['quantity'] ) && is_numeric( $_item['quantity'] ) ) {
293
-                $item->set_quantity( $_item['quantity'] );
292
+            if (!empty($_item['quantity']) && is_numeric($_item['quantity'])) {
293
+                $item->set_quantity($_item['quantity']);
294 294
             }
295 295
 
296 296
             // Set price.
297
-            if ( isset( $_item['item_price'] ) ) {
298
-                $item->set_price( $_item['item_price'] );
297
+            if (isset($_item['item_price'])) {
298
+                $item->set_price($_item['item_price']);
299 299
             }
300 300
 
301
-            if ( isset( $_item['custom_price'] ) ) {
302
-                $item->set_price( $_item['custom_price'] );
301
+            if (isset($_item['custom_price'])) {
302
+                $item->set_price($_item['custom_price']);
303 303
             }
304 304
 
305 305
             // Set name.
306
-            if ( ! empty( $_item['name'] ) ) {
307
-                $item->set_name( $_item['name'] );
306
+            if (!empty($_item['name'])) {
307
+                $item->set_name($_item['name']);
308 308
             }
309 309
 
310 310
             // Set description.
311
-            if ( isset( $_item['description'] ) ) {
312
-                $item->set_custom_description( $_item['description'] );
311
+            if (isset($_item['description'])) {
312
+                $item->set_custom_description($_item['description']);
313 313
             }
314 314
 
315 315
             // Set meta.
316
-            if ( isset( $_item['meta'] ) && is_array( $_item['meta'] ) ) {
316
+            if (isset($_item['meta']) && is_array($_item['meta'])) {
317 317
 
318
-                $item->set_item_meta( $_item['meta'] );
318
+                $item->set_item_meta($_item['meta']);
319 319
 
320
-                if ( isset( $_item['meta']['description'] ) ) {
321
-                    $item->set_custom_description( $_item['meta']['description'] );
320
+                if (isset($_item['meta']['description'])) {
321
+                    $item->set_custom_description($_item['meta']['description']);
322 322
                 }
323 323
 
324 324
             }
@@ -329,14 +329,14 @@  discard block
 block discarded – undo
329 329
     }
330 330
 
331 331
     // Add invoice items.
332
-    if ( ! empty( $data['items'] ) && is_array( $data['items'] ) ) {
332
+    if (!empty($data['items']) && is_array($data['items'])) {
333 333
 
334
-        $invoice->set_items( array() );
334
+        $invoice->set_items(array());
335 335
 
336
-        foreach ( $data['items'] as $item ) {
336
+        foreach ($data['items'] as $item) {
337 337
 
338
-            if ( is_object( $item ) && is_a( $item, 'GetPaid_Form_Item' ) && $item->can_purchase() ) {
339
-                $invoice->add_item( $item );
338
+            if (is_object($item) && is_a($item, 'GetPaid_Form_Item') && $item->can_purchase()) {
339
+                $invoice->add_item($item);
340 340
             }
341 341
 
342 342
         }
@@ -346,30 +346,30 @@  discard block
 block discarded – undo
346 346
     // Save the invoice.
347 347
     $invoice->save();
348 348
 
349
-    if ( ! $invoice->get_id() ) {
350
-        return $wp_error ? new WP_Error( 'wpinv_insert_invoice_error', __( 'An error occured when saving your invoice.', 'invoicing' ) ) : 0;
349
+    if (!$invoice->get_id()) {
350
+        return $wp_error ? new WP_Error('wpinv_insert_invoice_error', __('An error occured when saving your invoice.', 'invoicing')) : 0;
351 351
     }
352 352
 
353 353
     // Add private note.
354
-    if ( ! empty( $data['private_note'] ) ) {
355
-        $invoice->add_note( $data['private_note'] );
354
+    if (!empty($data['private_note'])) {
355
+        $invoice->add_note($data['private_note']);
356 356
     }
357 357
 
358 358
     // User notes.
359
-    if ( !empty( $data['user_note'] ) ) {
360
-        $invoice->add_note( $data['user_note'], true );
359
+    if (!empty($data['user_note'])) {
360
+        $invoice->add_note($data['user_note'], true);
361 361
     }
362 362
 
363 363
     // Created via.
364
-    if ( isset( $data['created_via'] ) ) {
365
-        update_post_meta( $invoice->get_id(), 'wpinv_created_via', $data['created_via'] );
364
+    if (isset($data['created_via'])) {
365
+        update_post_meta($invoice->get_id(), 'wpinv_created_via', $data['created_via']);
366 366
     }
367 367
 
368 368
     // Backwards compatiblity.
369
-    if ( $invoice->is_quote() ) {
369
+    if ($invoice->is_quote()) {
370 370
 
371
-        if ( isset( $data['valid_until'] ) ) {
372
-            update_post_meta( $invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until'] );
371
+        if (isset($data['valid_until'])) {
372
+            update_post_meta($invoice->get_id(), 'wpinv_quote_valid_until', $data['valid_until']);
373 373
         }
374 374
         return $invoice;
375 375
 
@@ -384,18 +384,18 @@  discard block
 block discarded – undo
384 384
  * @param $bool $deprecated
385 385
  * @return WPInv_Invoice|null
386 386
  */
387
-function wpinv_get_invoice( $invoice = 0, $deprecated = false ) {
387
+function wpinv_get_invoice($invoice = 0, $deprecated = false) {
388 388
 
389 389
     // If we are retrieving the invoice from the cart...
390
-    if ( $deprecated && empty( $invoice ) ) {
390
+    if ($deprecated && empty($invoice)) {
391 391
         $invoice = (int) getpaid_get_current_invoice_id();
392 392
     }
393 393
 
394 394
     // Retrieve the invoice.
395
-    $invoice = new WPInv_Invoice( $invoice );
395
+    $invoice = new WPInv_Invoice($invoice);
396 396
 
397 397
     // Check if it exists.
398
-    if ( $invoice->get_id() != 0 ) {
398
+    if ($invoice->get_id() != 0) {
399 399
         return $invoice;
400 400
     }
401 401
 
@@ -408,15 +408,15 @@  discard block
 block discarded – undo
408 408
  * @param array $args Args to search for.
409 409
  * @return WPInv_Invoice[]|int[]|object
410 410
  */
411
-function wpinv_get_invoices( $args ) {
411
+function wpinv_get_invoices($args) {
412 412
 
413 413
     // Prepare args.
414 414
     $args = wp_parse_args(
415 415
         $args,
416 416
         array(
417
-            'status'   => array_keys( wpinv_get_invoice_statuses() ),
417
+            'status'   => array_keys(wpinv_get_invoice_statuses()),
418 418
             'type'     => 'wpi_invoice',
419
-            'limit'    => get_option( 'posts_per_page' ),
419
+            'limit'    => get_option('posts_per_page'),
420 420
             'return'   => 'objects',
421 421
         )
422 422
     );
@@ -434,24 +434,24 @@  discard block
 block discarded – undo
434 434
         'post__in'       => 'include',
435 435
     );
436 436
 
437
-    foreach ( $map_legacy as $to => $from ) {
438
-        if ( isset( $args[ $from ] ) ) {
439
-            $args[ $to ] = $args[ $from ];
440
-            unset( $args[ $from ] );
437
+    foreach ($map_legacy as $to => $from) {
438
+        if (isset($args[$from])) {
439
+            $args[$to] = $args[$from];
440
+            unset($args[$from]);
441 441
         }
442 442
     }
443 443
 
444 444
     // Backwards compatibility.
445
-    if ( ! empty( $args['email'] ) && empty( $args['user'] ) ) {
445
+    if (!empty($args['email']) && empty($args['user'])) {
446 446
         $args['user'] = $args['email'];
447
-        unset( $args['email'] );
447
+        unset($args['email']);
448 448
     }
449 449
 
450 450
     // Handle cases where the user is set as an email.
451
-    if ( ! empty( $args['author'] ) && is_email( $args['author'] ) ) {
452
-        $user = get_user_by( 'email', $args['user'] );
451
+    if (!empty($args['author']) && is_email($args['author'])) {
452
+        $user = get_user_by('email', $args['user']);
453 453
 
454
-        if ( $user ) {
454
+        if ($user) {
455 455
             $args['author'] = $user->user_email;
456 456
         }
457 457
 
@@ -462,31 +462,31 @@  discard block
 block discarded – undo
462 462
 
463 463
     // Show all posts.
464 464
     $paginate = true;
465
-    if ( isset( $args['paginate'] ) ) {
465
+    if (isset($args['paginate'])) {
466 466
         
467 467
         $paginate = $args['paginate'];
468
-        $args['no_found_rows'] = empty( $args['paginate'] );
469
-        unset( $args['paginate'] );
468
+        $args['no_found_rows'] = empty($args['paginate']);
469
+        unset($args['paginate']);
470 470
 
471 471
     }
472 472
 
473 473
     // Whether to return objects or fields.
474 474
     $return = $args['return'];
475
-    unset( $args['return'] );
475
+    unset($args['return']);
476 476
 
477 477
     // Get invoices.
478
-    $invoices = new WP_Query( apply_filters( 'wpinv_get_invoices_args', $args ) );
478
+    $invoices = new WP_Query(apply_filters('wpinv_get_invoices_args', $args));
479 479
 
480 480
     // Prepare the results.
481
-    if ( 'objects' === $return ) {
482
-        $results = array_map( 'wpinv_get_invoice', $invoices->posts );
483
-    } elseif ( 'self' === $return ) {
481
+    if ('objects' === $return) {
482
+        $results = array_map('wpinv_get_invoice', $invoices->posts);
483
+    } elseif ('self' === $return) {
484 484
         return $invoices;
485 485
     } else {
486 486
         $results = $invoices->posts;
487 487
     }
488 488
 
489
-    if ( $paginate ) {
489
+    if ($paginate) {
490 490
         return (object) array(
491 491
             'invoices'      => $results,
492 492
             'total'         => $invoices->found_posts,
@@ -504,8 +504,8 @@  discard block
 block discarded – undo
504 504
  * @param string $transaction_id The transaction id to check.
505 505
  * @return int Invoice id on success or 0 on failure
506 506
  */
507
-function wpinv_get_id_by_transaction_id( $transaction_id ) {
508
-    return WPInv_Invoice::get_invoice_id_by_field( $transaction_id, 'transaction_id' );
507
+function wpinv_get_id_by_transaction_id($transaction_id) {
508
+    return WPInv_Invoice::get_invoice_id_by_field($transaction_id, 'transaction_id');
509 509
 }
510 510
 
511 511
 /**
@@ -514,8 +514,8 @@  discard block
 block discarded – undo
514 514
  * @param string $invoice_number The invoice number to check.
515 515
  * @return int Invoice id on success or 0 on failure
516 516
  */
517
-function wpinv_get_id_by_invoice_number( $invoice_number ) {
518
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_number, 'number' );
517
+function wpinv_get_id_by_invoice_number($invoice_number) {
518
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_number, 'number');
519 519
 }
520 520
 
521 521
 /**
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
  * @param string $invoice_key The invoice key to check.
525 525
  * @return int Invoice id on success or 0 on failure
526 526
  */
527
-function wpinv_get_invoice_id_by_key( $invoice_key ) {
528
-    return WPInv_Invoice::get_invoice_id_by_field( $invoice_key, 'key' );
527
+function wpinv_get_invoice_id_by_key($invoice_key) {
528
+    return WPInv_Invoice::get_invoice_id_by_field($invoice_key, 'key');
529 529
 }
530 530
 
531 531
 /**
@@ -535,20 +535,20 @@  discard block
 block discarded – undo
535 535
  * @param string $type Optionally filter by type i.e customer|system
536 536
  * @return WPInv_Invoice|null
537 537
  */
538
-function wpinv_get_invoice_notes( $invoice = 0, $type = '' ) {
538
+function wpinv_get_invoice_notes($invoice = 0, $type = '') {
539 539
     global $invoicing;
540 540
 
541 541
     // Prepare the invoice.
542
-    $invoice = new WPInv_Invoice( $invoice );
543
-    if ( ! $invoice->exists() ) {
542
+    $invoice = new WPInv_Invoice($invoice);
543
+    if (!$invoice->exists()) {
544 544
         return NULL;
545 545
     }
546 546
 
547 547
     // Fetch notes.
548
-    $notes = $invoicing->notes->get_invoice_notes( $invoice->get_id(), $type );
548
+    $notes = $invoicing->notes->get_invoice_notes($invoice->get_id(), $type);
549 549
 
550 550
     // Filter the notes.
551
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice->get_id(), $type );
551
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice->get_id(), $type);
552 552
 }
553 553
 
554 554
 /**
@@ -558,27 +558,27 @@  discard block
 block discarded – undo
558 558
     $columns = array(
559 559
 
560 560
             'invoice-number'  => array(
561
-                'title' => __( 'Invoice', 'invoicing' ),
561
+                'title' => __('Invoice', 'invoicing'),
562 562
                 'class' => 'text-left'
563 563
             ),
564 564
 
565 565
             'created-date'    => array(
566
-                'title' => __( 'Created Date', 'invoicing' ),
566
+                'title' => __('Created Date', 'invoicing'),
567 567
                 'class' => 'text-left'
568 568
             ),
569 569
 
570 570
             'payment-date'    => array(
571
-                'title' => __( 'Payment Date', 'invoicing' ),
571
+                'title' => __('Payment Date', 'invoicing'),
572 572
                 'class' => 'text-left'
573 573
             ),
574 574
 
575 575
             'invoice-status'  => array(
576
-                'title' => __( 'Status', 'invoicing' ),
576
+                'title' => __('Status', 'invoicing'),
577 577
                 'class' => 'text-center'
578 578
             ),
579 579
 
580 580
             'invoice-total'   => array(
581
-                'title' => __( 'Total', 'invoicing' ),
581
+                'title' => __('Total', 'invoicing'),
582 582
                 'class' => 'text-right'
583 583
             ),
584 584
 
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 
590 590
         );
591 591
 
592
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
592
+    return apply_filters('wpinv_user_invoices_columns', $columns);
593 593
 }
594 594
 
595 595
 /**
@@ -599,54 +599,54 @@  discard block
 block discarded – undo
599 599
 
600 600
     // Find the invoice.
601 601
     $invoice_id = getpaid_get_current_invoice_id();
602
-    $invoice = new WPInv_Invoice( $invoice_id );
602
+    $invoice = new WPInv_Invoice($invoice_id);
603 603
 
604 604
     // Abort if non was found.
605
-    if ( empty( $invoice_id ) || $invoice->is_draft() ) {
605
+    if (empty($invoice_id) || $invoice->is_draft()) {
606 606
 
607 607
         return aui()->alert(
608 608
             array(
609 609
                 'type'    => 'warning',
610
-                'content' => __( 'We could not find your invoice', 'invoicing' ),
610
+                'content' => __('We could not find your invoice', 'invoicing'),
611 611
             )
612 612
         );
613 613
 
614 614
     }
615 615
 
616 616
     // Can the user view this invoice?
617
-    if ( ! wpinv_can_view_receipt( $invoice_id ) ) {
617
+    if (!wpinv_can_view_receipt($invoice_id)) {
618 618
 
619 619
         return aui()->alert(
620 620
             array(
621 621
                 'type'    => 'warning',
622
-                'content' => __( 'You are not allowed to view this receipt', 'invoicing' ),
622
+                'content' => __('You are not allowed to view this receipt', 'invoicing'),
623 623
             )
624 624
         );
625 625
 
626 626
     }
627 627
 
628 628
     // Load the template.
629
-    return wpinv_get_template_html( 'invoice-receipt.php', compact( 'invoice' ) );
629
+    return wpinv_get_template_html('invoice-receipt.php', compact('invoice'));
630 630
 
631 631
 }
632 632
 
633 633
 /**
634 634
  * Displays the invoice history.
635 635
  */
636
-function getpaid_invoice_history( $user_id = 0 ) {
636
+function getpaid_invoice_history($user_id = 0) {
637 637
 
638 638
     // Ensure that we have a user id.
639
-    if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
639
+    if (empty($user_id) || !is_numeric($user_id)) {
640 640
         $user_id = get_current_user_id();
641 641
     }
642 642
 
643 643
     // View user id.
644
-    if ( empty( $user_id ) ) {
644
+    if (empty($user_id)) {
645 645
 
646 646
         return aui()->alert(
647 647
             array(
648 648
                 'type'    => 'warning',
649
-                'content' => __( 'You must be logged in to view your invoice history.', 'invoicing' ),
649
+                'content' => __('You must be logged in to view your invoice history.', 'invoicing'),
650 650
             )
651 651
         );
652 652
 
@@ -656,89 +656,89 @@  discard block
 block discarded – undo
656 656
     $invoices = wpinv_get_invoices(
657 657
 
658 658
         array(
659
-            'page'     => ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1,
659
+            'page'     => (get_query_var('paged')) ? absint(get_query_var('paged')) : 1,
660 660
             'user'     => $user_id,
661 661
             'paginate' => true,
662 662
         )
663 663
 
664 664
     );
665 665
 
666
-    if ( empty( $invoices->total ) ) {
666
+    if (empty($invoices->total)) {
667 667
 
668 668
         return aui()->alert(
669 669
             array(
670 670
                 'type'    => 'info',
671
-                'content' => __( 'No invoices found.', 'invoicing' ),
671
+                'content' => __('No invoices found.', 'invoicing'),
672 672
             )
673 673
         );
674 674
 
675 675
     }
676 676
 
677 677
     // Load the template.
678
-    return wpinv_get_template_html( 'invoice-history.php', compact( 'invoices' ) );
678
+    return wpinv_get_template_html('invoice-history.php', compact('invoices'));
679 679
 
680 680
 }
681 681
 
682 682
 function wpinv_pay_for_invoice() {
683 683
     global $wpinv_euvat;
684 684
     
685
-    if ( isset( $_GET['invoice_key'] ) ) {
685
+    if (isset($_GET['invoice_key'])) {
686 686
         $checkout_uri   = wpinv_get_checkout_uri();
687
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
687
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
688 688
         
689
-        if ( empty( $invoice_key ) ) {
690
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
691
-            wp_redirect( $checkout_uri );
689
+        if (empty($invoice_key)) {
690
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
691
+            wp_redirect($checkout_uri);
692 692
             exit();
693 693
         }
694 694
         
695
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
695
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
696 696
 
697
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
698
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
699
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
700
-            $invoice_id     = (int)$_GET['invoice-id'];
701
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
697
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
698
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
699
+        if ($user_can_view && isset($_GET['invoice-id'])) {
700
+            $invoice_id     = (int) $_GET['invoice-id'];
701
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
702 702
         }
703 703
         
704
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
705
-            if ( $invoice->needs_payment() ) {
704
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
705
+            if ($invoice->needs_payment()) {
706 706
                 $data                   = array();
707 707
                 $data['invoice_id']     = $invoice_id;
708
-                $data['cart_discounts'] = $invoice->get_discounts( true );
708
+                $data['cart_discounts'] = $invoice->get_discounts(true);
709 709
                 
710
-                wpinv_set_checkout_session( $data );
710
+                wpinv_set_checkout_session($data);
711 711
                 
712
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
712
+                if (wpinv_get_option('vat_ip_country_default')) {
713 713
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
714 714
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
715 715
                     
716
-                    wpinv_recalculate_tax( true );
716
+                    wpinv_recalculate_tax(true);
717 717
                 }
718 718
                 
719 719
             } else {
720 720
                 $checkout_uri = $invoice->get_view_url();
721 721
             }
722 722
         } else {
723
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
723
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
724 724
             
725
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
725
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
726 726
         }
727 727
         
728
-        if(wp_redirect( $checkout_uri )){
728
+        if (wp_redirect($checkout_uri)) {
729 729
             exit;
730 730
         };
731 731
         wpinv_die();
732 732
     }
733 733
 }
734
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
734
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
735 735
 
736
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
737
-    if ( empty( $status_display ) ) {
738
-        $status_display = wpinv_status_nicename( $status );
736
+function wpinv_invoice_status_label($status, $status_display = '') {
737
+    if (empty($status_display)) {
738
+        $status_display = wpinv_status_nicename($status);
739 739
     }
740 740
     
741
-    switch ( $status ) {
741
+    switch ($status) {
742 742
         case 'publish' :
743 743
         case 'wpi-renewal' :
744 744
             $class = 'label-success';
@@ -763,159 +763,159 @@  discard block
 block discarded – undo
763 763
 
764 764
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
765 765
 
766
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
766
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
767 767
 }
768 768
 
769
-function wpinv_format_invoice_number( $number, $type = '' ) {
770
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
771
-    if ( null !== $check ) {
769
+function wpinv_format_invoice_number($number, $type = '') {
770
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
771
+    if (null !== $check) {
772 772
         return $check;
773 773
     }
774 774
 
775
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
775
+    if (!empty($number) && !is_numeric($number)) {
776 776
         return $number;
777 777
     }
778 778
 
779
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
780
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
781
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
779
+    $padd = wpinv_get_option('invoice_number_padd');
780
+    $prefix  = wpinv_get_option('invoice_number_prefix');
781
+    $postfix = wpinv_get_option('invoice_number_postfix');
782 782
     
783
-    $padd = absint( $padd );
784
-    $formatted_number = absint( $number );
783
+    $padd = absint($padd);
784
+    $formatted_number = absint($number);
785 785
     
786
-    if ( $padd > 0 ) {
787
-        $formatted_number = zeroise( $formatted_number, $padd );
786
+    if ($padd > 0) {
787
+        $formatted_number = zeroise($formatted_number, $padd);
788 788
     }    
789 789
 
790 790
     $formatted_number = $prefix . $formatted_number . $postfix;
791 791
 
792
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
792
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
793 793
 }
794 794
 
795
-function wpinv_get_next_invoice_number( $type = '' ) {
796
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
797
-    if ( null !== $check ) {
795
+function wpinv_get_next_invoice_number($type = '') {
796
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
797
+    if (null !== $check) {
798 798
         return $check;
799 799
     }
800 800
     
801
-    if ( !wpinv_sequential_number_active() ) {
801
+    if (!wpinv_sequential_number_active()) {
802 802
         return false;
803 803
     }
804 804
 
805
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
806
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
807
-    if ( !absint( $start ) > 0 ) {
805
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
806
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
807
+    if (!absint($start) > 0) {
808 808
         $start = 1;
809 809
     }
810 810
     $increment_number = true;
811 811
     $save_number = false;
812 812
 
813
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
814
-        $number = wpinv_clean_invoice_number( $number );
813
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
814
+        $number = wpinv_clean_invoice_number($number);
815 815
     }
816 816
 
817
-    if ( empty( $number ) ) {
818
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
819
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
817
+    if (empty($number)) {
818
+        if (!($last_number === 0 || $last_number === '0')) {
819
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
820 820
 
821
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
822
-                if ( is_numeric( $invoice_number ) ) {
821
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
822
+                if (is_numeric($invoice_number)) {
823 823
                     $number = $invoice_number;
824 824
                 } else {
825
-                    $number = wpinv_clean_invoice_number( $invoice_number );
825
+                    $number = wpinv_clean_invoice_number($invoice_number);
826 826
                 }
827 827
             }
828 828
 
829
-            if ( empty( $number ) ) {
829
+            if (empty($number)) {
830 830
                 $increment_number = false;
831 831
                 $number = $start;
832
-                $save_number = ( $number - 1 );
832
+                $save_number = ($number - 1);
833 833
             } else {
834 834
                 $save_number = $number;
835 835
             }
836 836
         }
837 837
     }
838 838
 
839
-    if ( $start > $number ) {
839
+    if ($start > $number) {
840 840
         $increment_number = false;
841 841
         $number = $start;
842
-        $save_number = ( $number - 1 );
842
+        $save_number = ($number - 1);
843 843
     }
844 844
 
845
-    if ( $save_number !== false ) {
846
-        update_option( 'wpinv_last_invoice_number', $save_number );
845
+    if ($save_number !== false) {
846
+        update_option('wpinv_last_invoice_number', $save_number);
847 847
     }
848 848
     
849
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
849
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
850 850
 
851
-    if ( $increment_number ) {
851
+    if ($increment_number) {
852 852
         $number++;
853 853
     }
854 854
 
855
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
855
+    return apply_filters('wpinv_get_next_invoice_number', $number);
856 856
 }
857 857
 
858
-function wpinv_clean_invoice_number( $number, $type = '' ) {
859
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
860
-    if ( null !== $check ) {
858
+function wpinv_clean_invoice_number($number, $type = '') {
859
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
860
+    if (null !== $check) {
861 861
         return $check;
862 862
     }
863 863
     
864
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
865
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
864
+    $prefix  = wpinv_get_option('invoice_number_prefix');
865
+    $postfix = wpinv_get_option('invoice_number_postfix');
866 866
 
867
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
867
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
868 868
 
869
-    $length      = strlen( $number );
870
-    $postfix_pos = strrpos( $number, $postfix );
869
+    $length      = strlen($number);
870
+    $postfix_pos = strrpos($number, $postfix);
871 871
     
872
-    if ( false !== $postfix_pos ) {
873
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
872
+    if (false !== $postfix_pos) {
873
+        $number = substr_replace($number, '', $postfix_pos, $length);
874 874
     }
875 875
 
876
-    $number = intval( $number );
876
+    $number = intval($number);
877 877
 
878
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
878
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
879 879
 }
880 880
 
881
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
881
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
882 882
     global $wpdb;
883 883
 
884
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
885
-    if ( null !== $check ) {
884
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
885
+    if (null !== $check) {
886 886
         return $check;
887 887
     }
888 888
 
889
-    if ( wpinv_sequential_number_active() ) {
889
+    if (wpinv_sequential_number_active()) {
890 890
         $number = wpinv_get_next_invoice_number();
891 891
 
892
-        if ( $save_sequential ) {
893
-            update_option( 'wpinv_last_invoice_number', $number );
892
+        if ($save_sequential) {
893
+            update_option('wpinv_last_invoice_number', $number);
894 894
         }
895 895
     } else {
896 896
         $number = $post_ID;
897 897
     }
898 898
 
899
-    $number = wpinv_format_invoice_number( $number );
899
+    $number = wpinv_format_invoice_number($number);
900 900
 
901
-    update_post_meta( $post_ID, '_wpinv_number', $number );
901
+    update_post_meta($post_ID, '_wpinv_number', $number);
902 902
 
903
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
903
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
904 904
 
905
-    clean_post_cache( $post_ID );
905
+    clean_post_cache($post_ID);
906 906
 
907 907
     return $number;
908 908
 }
909 909
 
910
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
911
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
910
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
911
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
912 912
 }
913 913
 
914
-function wpinv_generate_post_name( $post_ID ) {
915
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
916
-    $post_name = sanitize_title( $prefix . $post_ID );
914
+function wpinv_generate_post_name($post_ID) {
915
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
916
+    $post_name = sanitize_title($prefix . $post_ID);
917 917
 
918
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
918
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
919 919
 }
920 920
 
921 921
 /**
@@ -923,8 +923,8 @@  discard block
 block discarded – undo
923 923
  * 
924 924
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
925 925
  */
926
-function wpinv_is_invoice_viewed( $invoice ) {
927
-    $invoice = new WPInv_Invoice( $invoice );
926
+function wpinv_is_invoice_viewed($invoice) {
927
+    $invoice = new WPInv_Invoice($invoice);
928 928
     return (bool) $invoice->get_is_viewed();
929 929
 }
930 930
 
@@ -933,51 +933,51 @@  discard block
 block discarded – undo
933 933
  * 
934 934
  * @param int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object.
935 935
  */
936
-function getpaid_maybe_mark_invoice_as_viewed( $invoice ) {
937
-    $invoice = new WPInv_Invoice( $invoice );
936
+function getpaid_maybe_mark_invoice_as_viewed($invoice) {
937
+    $invoice = new WPInv_Invoice($invoice);
938 938
 
939
-    if ( get_current_user_id() == $invoice->get_user_id() && ! $invoice->get_is_viewed() ) {
940
-        $invoice->set_is_viewed( true );
939
+    if (get_current_user_id() == $invoice->get_user_id() && !$invoice->get_is_viewed()) {
940
+        $invoice->set_is_viewed(true);
941 941
         $invoice->save();
942 942
     }
943 943
 
944 944
 }
945
-add_action( 'wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed' );
946
-add_action( 'wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed' );
945
+add_action('wpinv_invoice_print_before_display', 'getpaid_maybe_mark_invoice_as_viewed');
946
+add_action('wpinv_before_receipt', 'getpaid_maybe_mark_invoice_as_viewed');
947 947
 
948 948
 /**
949 949
  * Fetch a subscription given an invoice.
950 950
  *
951 951
  * @return WPInv_Subscription|bool
952 952
  */
953
-function wpinv_get_subscription( $invoice ) {
953
+function wpinv_get_subscription($invoice) {
954 954
 
955 955
     // Abort if we do not have an invoice.
956
-    if ( empty( $invoice ) ) {
956
+    if (empty($invoice)) {
957 957
         return false;
958 958
     }
959 959
 
960 960
     // Retrieve the invoice.
961
-    $invoice = new WPInv_Invoice( $invoice );
961
+    $invoice = new WPInv_Invoice($invoice);
962 962
 
963 963
     // Ensure it is a recurring invoice.
964
-    if ( ! $invoice->is_recurring() ) {
964
+    if (!$invoice->is_recurring()) {
965 965
         return false;
966 966
     }
967 967
 
968 968
     // Fetch the subscription handler.
969
-    $subs_db    = new WPInv_Subscriptions_DB();
969
+    $subs_db = new WPInv_Subscriptions_DB();
970 970
 
971 971
     // Fetch the parent in case it is a renewal.
972
-    if ( $invoice->is_renewal() ) {
973
-        $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_parent_id(), 'number' => 1 ) );
972
+    if ($invoice->is_renewal()) {
973
+        $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_parent_id(), 'number' => 1));
974 974
     } else {
975
-        $subs = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice->get_id(), 'number' => 1 ) );
975
+        $subs = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice->get_id(), 'number' => 1));
976 976
     }
977 977
 
978 978
     // Return the subscription if it exists.
979
-    if ( ! empty( $subs ) ) {
980
-        return reset( $subs );
979
+    if (!empty($subs)) {
980
+        return reset($subs);
981 981
     }
982 982
 
983 983
     return false;
@@ -991,27 +991,27 @@  discard block
 block discarded – undo
991 991
  * @param array $status_transition
992 992
  * @todo: descrease customer/store earnings
993 993
  */
994
-function getpaid_maybe_process_refund( $invoice_id, $invoice, $status_transition ) {
994
+function getpaid_maybe_process_refund($invoice_id, $invoice, $status_transition) {
995 995
 
996
-    if ( empty( $status_transition['from'] ) || ! in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ) ) ) {
996
+    if (empty($status_transition['from']) || !in_array($status_transition['from'], array('publish', 'wpi-processing', 'wpi-renewal'))) {
997 997
         return;
998 998
     }
999 999
 
1000 1000
     $discount_code = $invoice->get_discount_code();
1001
-    if ( ! empty( $discount_code ) ) {
1002
-        $discount = wpinv_get_discount_obj( $discount_code );
1001
+    if (!empty($discount_code)) {
1002
+        $discount = wpinv_get_discount_obj($discount_code);
1003 1003
 
1004
-        if ( $discount->exists() ) {
1004
+        if ($discount->exists()) {
1005 1005
             $discount->increase_usage( -1 );
1006 1006
         }
1007 1007
 
1008 1008
     }
1009 1009
 
1010
-    do_action( 'wpinv_pre_refund_invoice', $invoice, $invoice_id );
1011
-    do_action( 'wpinv_refund_invoice', $invoice, $invoice_id );
1012
-    do_action( 'wpinv_post_refund_invoice', $invoice, $invoice_id );
1010
+    do_action('wpinv_pre_refund_invoice', $invoice, $invoice_id);
1011
+    do_action('wpinv_refund_invoice', $invoice, $invoice_id);
1012
+    do_action('wpinv_post_refund_invoice', $invoice, $invoice_id);
1013 1013
 }
1014
-add_action( 'getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3 );
1014
+add_action('getpaid_invoice_status_wpi-refunded', 'getpaid_maybe_process_refund', 10, 3);
1015 1015
 
1016 1016
 
1017 1017
 /**
@@ -1019,48 +1019,48 @@  discard block
 block discarded – undo
1019 1019
  *
1020 1020
  * @param int $invoice_id
1021 1021
  */
1022
-function getpaid_process_invoice_payment( $invoice_id ) {
1022
+function getpaid_process_invoice_payment($invoice_id) {
1023 1023
 
1024 1024
     // Fetch the invoice.
1025
-    $invoice = new WPInv_Invoice( $invoice_id );
1025
+    $invoice = new WPInv_Invoice($invoice_id);
1026 1026
 
1027 1027
     // We only want to do this once.
1028
-    if ( 1 ==  get_post_meta( $invoice_id, 'wpinv_processed_payment', true ) ) {
1028
+    if (1 == get_post_meta($invoice_id, 'wpinv_processed_payment', true)) {
1029 1029
         return;
1030 1030
     }
1031 1031
 
1032
-    update_post_meta( $invoice_id, 'wpinv_processed_payment', 1 );
1032
+    update_post_meta($invoice_id, 'wpinv_processed_payment', 1);
1033 1033
 
1034 1034
     // Fires when processing a payment.
1035
-    do_action( 'getpaid_process_payment', $invoice );
1035
+    do_action('getpaid_process_payment', $invoice);
1036 1036
 
1037 1037
     // Fire an action for each invoice item.
1038
-    foreach( $invoice->get_items() as $item ) {
1039
-        do_action( 'getpaid_process_item_payment', $item, $invoice );
1038
+    foreach ($invoice->get_items() as $item) {
1039
+        do_action('getpaid_process_item_payment', $item, $invoice);
1040 1040
     }
1041 1041
 
1042 1042
     // Increase discount usage.
1043 1043
     $discount_code = $invoice->get_discount_code();
1044
-    if ( ! empty( $discount_code ) ) {
1045
-        $discount = wpinv_get_discount_obj( $discount_code );
1044
+    if (!empty($discount_code)) {
1045
+        $discount = wpinv_get_discount_obj($discount_code);
1046 1046
 
1047
-        if ( $discount->exists() ) {
1047
+        if ($discount->exists()) {
1048 1048
             $discount->increase_usage();
1049 1049
         }
1050 1050
 
1051 1051
     }
1052 1052
 
1053 1053
     // Record reverse vat.
1054
-    if ( 'invoice' == $invoice->get_type() && wpinv_use_taxes() && ! $invoice->get_disable_taxes() ) {
1054
+    if ('invoice' == $invoice->get_type() && wpinv_use_taxes() && !$invoice->get_disable_taxes()) {
1055 1055
 
1056
-        if ( WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country( $invoice->get_country() ) ) {
1057
-            $invoice->add_note( __( 'VAT was reverse charged', 'invoicing' ), false, false, true );
1056
+        if (WPInv_EUVat::same_country_rule() == 'no' && wpinv_is_base_country($invoice->get_country())) {
1057
+            $invoice->add_note(__('VAT was reverse charged', 'invoicing'), false, false, true);
1058 1058
         }
1059 1059
 
1060 1060
     }
1061 1061
 
1062 1062
 }
1063
-add_action( 'getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment' );
1063
+add_action('getpaid_invoice_payment_status_changed', 'getpaid_process_invoice_payment');
1064 1064
 
1065 1065
 /**
1066 1066
  * Returns an array of invoice item columns
@@ -1068,13 +1068,13 @@  discard block
 block discarded – undo
1068 1068
  * @param int|WPInv_Invoice $invoice
1069 1069
  * @return array
1070 1070
  */
1071
-function getpaid_invoice_item_columns( $invoice ) {
1071
+function getpaid_invoice_item_columns($invoice) {
1072 1072
 
1073 1073
     // Prepare the invoice.
1074
-    $invoice = new WPInv_Invoice( $invoice );
1074
+    $invoice = new WPInv_Invoice($invoice);
1075 1075
 
1076 1076
     // Abort if there is no invoice.
1077
-    if ( 0 == $invoice->get_id() ) {
1077
+    if (0 == $invoice->get_id()) {
1078 1078
         return array();
1079 1079
     }
1080 1080
 
@@ -1082,47 +1082,47 @@  discard block
 block discarded – undo
1082 1082
     $columns = apply_filters(
1083 1083
         'getpaid_invoice_item_columns',
1084 1084
         array(
1085
-            'name'     => __( 'Item', 'invoicing' ),
1086
-            'price'    => __( 'Price', 'invoicing' ),
1087
-            'quantity' => __( 'Quantity', 'invoicing' ),
1088
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
1085
+            'name'     => __('Item', 'invoicing'),
1086
+            'price'    => __('Price', 'invoicing'),
1087
+            'quantity' => __('Quantity', 'invoicing'),
1088
+            'subtotal' => __('Subtotal', 'invoicing'),
1089 1089
         ),
1090 1090
         $invoice
1091 1091
     );
1092 1092
 
1093 1093
     // Quantities.
1094
-    if ( isset( $columns[ 'quantity' ] ) ) {
1094
+    if (isset($columns['quantity'])) {
1095 1095
 
1096
-        if ( 'hours' == $invoice->get_template() ) {
1097
-            $columns[ 'quantity' ] = __( 'Hours', 'invoicing' );
1096
+        if ('hours' == $invoice->get_template()) {
1097
+            $columns['quantity'] = __('Hours', 'invoicing');
1098 1098
         }
1099 1099
 
1100
-        if ( ! wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template() ) {
1101
-            unset( $columns[ 'quantity' ] );
1100
+        if (!wpinv_item_quantities_enabled() || 'amount' == $invoice->get_template()) {
1101
+            unset($columns['quantity']);
1102 1102
         }
1103 1103
 
1104 1104
     }
1105 1105
 
1106 1106
 
1107 1107
     // Price.
1108
-    if ( isset( $columns[ 'price' ] ) ) {
1108
+    if (isset($columns['price'])) {
1109 1109
 
1110
-        if ( 'amount' == $invoice->get_template() ) {
1111
-            $columns[ 'price' ] = __( 'Amount', 'invoicing' );
1110
+        if ('amount' == $invoice->get_template()) {
1111
+            $columns['price'] = __('Amount', 'invoicing');
1112 1112
         }
1113 1113
 
1114
-        if ( 'hours' == $invoice->get_template() ) {
1115
-            $columns[ 'price' ] = __( 'Rate', 'invoicing' );
1114
+        if ('hours' == $invoice->get_template()) {
1115
+            $columns['price'] = __('Rate', 'invoicing');
1116 1116
         }
1117 1117
 
1118 1118
     }
1119 1119
 
1120 1120
 
1121 1121
     // Sub total.
1122
-    if ( isset( $columns[ 'subtotal' ] ) ) {
1122
+    if (isset($columns['subtotal'])) {
1123 1123
 
1124
-        if ( 'amount' == $invoice->get_template() ) {
1125
-            unset( $columns[ 'subtotal' ] );
1124
+        if ('amount' == $invoice->get_template()) {
1125
+            unset($columns['subtotal']);
1126 1126
         }
1127 1127
 
1128 1128
     }
@@ -1136,29 +1136,29 @@  discard block
 block discarded – undo
1136 1136
  * @param int|WPInv_Invoice $invoice
1137 1137
  * @return array
1138 1138
  */
1139
-function getpaid_invoice_totals_rows( $invoice ) {
1139
+function getpaid_invoice_totals_rows($invoice) {
1140 1140
 
1141 1141
     // Prepare the invoice.
1142
-    $invoice = new WPInv_Invoice( $invoice );
1142
+    $invoice = new WPInv_Invoice($invoice);
1143 1143
 
1144 1144
     // Abort if there is no invoice.
1145
-    if ( 0 == $invoice->get_id() ) {
1145
+    if (0 == $invoice->get_id()) {
1146 1146
         return array();
1147 1147
     }
1148 1148
 
1149 1149
     $totals = apply_filters(
1150 1150
         'getpaid_invoice_totals_rows',
1151 1151
         array(
1152
-            'subtotal' => __( 'Subtotal', 'invoicing' ),
1153
-            'tax'      => __( 'Tax', 'invoicing' ),
1154
-            'discount' => __( 'Discount', 'invoicing' ),
1155
-            'total'    => __( 'Total', 'invoicing' ),
1152
+            'subtotal' => __('Subtotal', 'invoicing'),
1153
+            'tax'      => __('Tax', 'invoicing'),
1154
+            'discount' => __('Discount', 'invoicing'),
1155
+            'total'    => __('Total', 'invoicing'),
1156 1156
         ),
1157 1157
         $invoice
1158 1158
     );
1159 1159
 
1160
-    if ( ( $invoice->get_disable_taxes() || ! wpinv_use_taxes() ) && isset( $totals['tax'] ) ) {
1161
-        unset( $totals['tax'] );
1160
+    if (($invoice->get_disable_taxes() || !wpinv_use_taxes()) && isset($totals['tax'])) {
1161
+        unset($totals['tax']);
1162 1162
     }
1163 1163
 
1164 1164
     return $totals;
@@ -1170,18 +1170,18 @@  discard block
 block discarded – undo
1170 1170
  * @param int $invoice_id
1171 1171
  * @param WPInv_Invoice $invoice
1172 1172
  */
1173
-function getpaid_new_invoice( $invoice_id, $invoice ) {
1173
+function getpaid_new_invoice($invoice_id, $invoice) {
1174 1174
 
1175 1175
     // Add an invoice created note.
1176 1176
     $invoice->add_note(
1177 1177
         wp_sprintf(
1178
-            __( 'Invoice created with the status "%s".', 'invoicing' ),
1179
-            wpinv_status_nicename( $invoice->get_status() )
1178
+            __('Invoice created with the status "%s".', 'invoicing'),
1179
+            wpinv_status_nicename($invoice->get_status())
1180 1180
         )
1181 1181
     );
1182 1182
 
1183 1183
 }
1184
-add_action( 'getpaid_new_invoice', 'getpaid_new_invoice', 10, 2 );
1184
+add_action('getpaid_new_invoice', 'getpaid_new_invoice', 10, 2);
1185 1185
 
1186 1186
 /**
1187 1187
  * This function updates invoice caches.
@@ -1189,21 +1189,21 @@  discard block
 block discarded – undo
1189 1189
  * @param int $invoice_id
1190 1190
  * @param WPInv_Invoice $invoice
1191 1191
  */
1192
-function getpaid_update_invoice_caches( $invoice_id, $invoice ) {
1192
+function getpaid_update_invoice_caches($invoice_id, $invoice) {
1193 1193
 
1194 1194
     // Cache invoice number.
1195
-    wp_cache_set( $invoice->get_number(), $invoice_id, "getpaid_invoice_numbers_to_invoice_ids" );
1195
+    wp_cache_set($invoice->get_number(), $invoice_id, "getpaid_invoice_numbers_to_invoice_ids");
1196 1196
 
1197 1197
     // Cache invoice key.
1198
-    wp_cache_set( $invoice->get_key(), $invoice_id, "getpaid_invoice_keys_to_invoice_ids" );
1198
+    wp_cache_set($invoice->get_key(), $invoice_id, "getpaid_invoice_keys_to_invoice_ids");
1199 1199
 
1200 1200
     // (Maybe) cache transaction id.
1201 1201
     $transaction_id = $invoice->get_transaction_id();
1202 1202
 
1203
-    if ( ! empty( $transaction_id ) ) {
1204
-        wp_cache_set( $transaction_id, $invoice_id, "getpaid_invoice_transaction_ids_to_invoice_ids" );
1203
+    if (!empty($transaction_id)) {
1204
+        wp_cache_set($transaction_id, $invoice_id, "getpaid_invoice_transaction_ids_to_invoice_ids");
1205 1205
     }
1206 1206
 
1207 1207
 }
1208
-add_action( 'getpaid_new_invoice', 'getpaid_update_invoice_caches', 5, 2 );
1209
-add_action( 'getpaid_update_invoice', 'getpaid_update_invoice_caches', 5, 2 );
1208
+add_action('getpaid_new_invoice', 'getpaid_update_invoice_caches', 5, 2);
1209
+add_action('getpaid_update_invoice', 'getpaid_update_invoice_caches', 5, 2);
Please login to merge, or discard this patch.
includes/wpinv-email-functions.php 1 patch
Spacing   +670 added lines, -670 removed lines patch added patch discarded remove patch
@@ -7,12 +7,12 @@  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_init_transactional_emails() {
15
-    $email_actions = apply_filters( 'wpinv_email_actions', array(
15
+    $email_actions = apply_filters('wpinv_email_actions', array(
16 16
         'wpinv_status_wpi-pending_to_wpi-processing',
17 17
         'wpinv_status_wpi-pending_to_publish',
18 18
         'wpinv_status_wpi-pending_to_wpi-cancelled',
@@ -30,385 +30,385 @@  discard block
 block discarded – undo
30 30
         'wpinv_fully_refunded',
31 31
         'wpinv_partially_refunded',
32 32
         'wpinv_new_invoice_note'
33
-    ) );
33
+    ));
34 34
 
35
-    foreach ( $email_actions as $action ) {
36
-        add_action( $action, 'wpinv_send_transactional_email', 10, 10 );
35
+    foreach ($email_actions as $action) {
36
+        add_action($action, 'wpinv_send_transactional_email', 10, 10);
37 37
     }
38 38
 }
39
-add_action( 'init', 'wpinv_init_transactional_emails' );
39
+add_action('init', 'wpinv_init_transactional_emails');
40 40
 
41 41
 // New invoice email
42
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
43
-add_action( 'wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification' );
44
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
45
-add_action( 'wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification' );
46
-add_action( 'wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification' );
47
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification' );
42
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
43
+add_action('wpinv_status_wpi-pending_to_publish_notification', 'wpinv_new_invoice_notification');
44
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
45
+add_action('wpinv_status_wpi-failed_to_wpi-processing_notification', 'wpinv_new_invoice_notification');
46
+add_action('wpinv_status_wpi-failed_to_publish_notification', 'wpinv_new_invoice_notification');
47
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_new_invoice_notification');
48 48
 
49 49
 // Cancelled invoice email
50
-add_action( 'wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
51
-add_action( 'wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification' );
50
+add_action('wpinv_status_wpi-pending_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
51
+add_action('wpinv_status_wpi-onhold_to_wpi-cancelled_notification', 'wpinv_cancelled_invoice_notification');
52 52
 
53 53
 // Failed invoice email
54
-add_action( 'wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
55
-add_action( 'wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification' );
54
+add_action('wpinv_status_wpi-pending_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
55
+add_action('wpinv_status_wpi-onhold_to_wpi-failed_notification', 'wpinv_failed_invoice_notification');
56 56
 
57 57
 // On hold invoice email
58
-add_action( 'wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
59
-add_action( 'wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification' );
58
+add_action('wpinv_status_wpi-pending_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
59
+add_action('wpinv_status_wpi-failed_to_wpi-onhold_notification', 'wpinv_onhold_invoice_notification');
60 60
 
61 61
 // Processing invoice email
62
-add_action( 'wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification' );
62
+add_action('wpinv_status_wpi-pending_to_wpi-processing_notification', 'wpinv_processing_invoice_notification');
63 63
 
64 64
 // Paid invoice email
65
-add_action( 'wpinv_status_publish_notification', 'wpinv_completed_invoice_notification' );
65
+add_action('wpinv_status_publish_notification', 'wpinv_completed_invoice_notification');
66 66
 
67 67
 // Refunded invoice email
68
-add_action( 'wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification' );
69
-add_action( 'wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification' );
70
-add_action( 'wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
71
-add_action( 'wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification' );
68
+add_action('wpinv_fully_refunded_notification', 'wpinv_fully_refunded_notification');
69
+add_action('wpinv_partially_refunded_notification', 'wpinv_partially_refunded_notification');
70
+add_action('wpinv_status_publish_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
71
+add_action('wpinv_status_wpi-processing_to_wpi-refunded_notification', 'wpinv_fully_refunded_notification');
72 72
 
73 73
 // Invoice note
74
-add_action( 'wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification' );
74
+add_action('wpinv_new_invoice_note_notification', 'wpinv_new_invoice_note_notification');
75 75
 
76
-add_action( 'wpinv_email_header', 'wpinv_email_header' );
77
-add_action( 'wpinv_email_footer', 'wpinv_email_footer' );
78
-add_action( 'wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3 );
79
-add_action( 'wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3 );
80
-add_action( 'wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3 );
76
+add_action('wpinv_email_header', 'wpinv_email_header');
77
+add_action('wpinv_email_footer', 'wpinv_email_footer');
78
+add_action('wpinv_email_invoice_details', 'wpinv_email_invoice_details', 10, 3);
79
+add_action('wpinv_email_invoice_items', 'wpinv_email_invoice_items', 10, 3);
80
+add_action('wpinv_email_billing_details', 'wpinv_email_billing_details', 10, 3);
81 81
 
82 82
 function wpinv_send_transactional_email() {
83 83
     $args       = func_get_args();
84 84
     $function   = current_filter() . '_notification';
85
-    do_action_ref_array( $function, $args );
85
+    do_action_ref_array($function, $args);
86 86
 }
87 87
 
88
-function wpinv_new_invoice_notification( $invoice_id, $new_status = '' ) {
88
+function wpinv_new_invoice_notification($invoice_id, $new_status = '') {
89 89
     $email_type = 'new_invoice';
90
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
90
+    if (!wpinv_email_is_enabled($email_type)) {
91 91
         return false;
92 92
     }
93 93
 
94
-    $invoice = wpinv_get_invoice( $invoice_id );
95
-    if ( empty( $invoice ) ) {
94
+    $invoice = wpinv_get_invoice($invoice_id);
95
+    if (empty($invoice)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
99
+    if (!("wpi_invoice" === $invoice->post_type)) {
100 100
         return false;
101 101
     }
102 102
 
103
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
104
-    if ( !is_email( $recipient ) ) {
103
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
104
+    if (!is_email($recipient)) {
105 105
         return false;
106 106
     }
107 107
 
108
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
108
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
109 109
 
110
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
111
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
112
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
113
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
114
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
110
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
111
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
112
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
113
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
114
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
115 115
 
116
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
116
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
117 117
             'invoice'       => $invoice,
118 118
             'email_type'    => $email_type,
119 119
             'email_heading' => $email_heading,
120 120
             'sent_to_admin' => true,
121 121
             'plain_text'    => false,
122 122
             'message_body'  => $message_body,
123
-        ) );
123
+        ));
124 124
 
125
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
125
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
126 126
 
127
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
127
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
128 128
 
129 129
     return $sent;
130 130
 }
131 131
 
132
-function wpinv_cancelled_invoice_notification( $invoice_id, $new_status = '' ) {
132
+function wpinv_cancelled_invoice_notification($invoice_id, $new_status = '') {
133 133
     $email_type = 'cancelled_invoice';
134
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
134
+    if (!wpinv_email_is_enabled($email_type)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $invoice = wpinv_get_invoice( $invoice_id );
139
-    if ( empty( $invoice ) ) {
138
+    $invoice = wpinv_get_invoice($invoice_id);
139
+    if (empty($invoice)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
143
+    if (!("wpi_invoice" === $invoice->post_type)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
148
-    if ( !is_email( $recipient ) ) {
147
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
148
+    if (!is_email($recipient)) {
149 149
         return false;
150 150
     }
151 151
 
152
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
152
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
153 153
 
154
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
155
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
156
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
157
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
158
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
154
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
155
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
156
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
157
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
158
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
159 159
 
160
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
160
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
161 161
             'invoice'       => $invoice,
162 162
             'email_type'    => $email_type,
163 163
             'email_heading' => $email_heading,
164 164
             'sent_to_admin' => true,
165 165
             'plain_text'    => false,
166 166
             'message_body'  => $message_body,
167
-        ) );
167
+        ));
168 168
 
169
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
169
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
170 170
 
171
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
171
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
172 172
 
173 173
     return $sent;
174 174
 }
175 175
 
176
-function wpinv_failed_invoice_notification( $invoice_id, $new_status = '' ) {
176
+function wpinv_failed_invoice_notification($invoice_id, $new_status = '') {
177 177
     $email_type = 'failed_invoice';
178
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
178
+    if (!wpinv_email_is_enabled($email_type)) {
179 179
         return false;
180 180
     }
181 181
     
182
-    $invoice = wpinv_get_invoice( $invoice_id );
183
-    if ( empty( $invoice ) ) {
182
+    $invoice = wpinv_get_invoice($invoice_id);
183
+    if (empty($invoice)) {
184 184
         return false;
185 185
     }
186 186
 
187
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
187
+    if (!("wpi_invoice" === $invoice->post_type)) {
188 188
         return false;
189 189
     }
190 190
 
191
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
192
-    if ( !is_email( $recipient ) ) {
191
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
192
+    if (!is_email($recipient)) {
193 193
         return false;
194 194
     }
195 195
 
196
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type, true );
196
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type, true);
197 197
 
198
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
199
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
200
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
201
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
202
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
198
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
199
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
200
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
201
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
202
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
203 203
     
204
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
204
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
205 205
             'invoice'       => $invoice,
206 206
             'email_type'    => $email_type,
207 207
             'email_heading' => $email_heading,
208 208
             'sent_to_admin' => true,
209 209
             'plain_text'    => false,
210 210
             'message_body'  => $message_body,
211
-        ) );
211
+        ));
212 212
 
213
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
213
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
214 214
 
215
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type, true );
215
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type, true);
216 216
 
217 217
     return $sent;
218 218
 }
219 219
 
220
-function wpinv_onhold_invoice_notification( $invoice_id, $new_status = '' ) {
220
+function wpinv_onhold_invoice_notification($invoice_id, $new_status = '') {
221 221
     $email_type = 'onhold_invoice';
222
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
222
+    if (!wpinv_email_is_enabled($email_type)) {
223 223
         return false;
224 224
     }
225 225
 
226
-    $invoice = wpinv_get_invoice( $invoice_id );
227
-    if ( empty( $invoice ) ) {
226
+    $invoice = wpinv_get_invoice($invoice_id);
227
+    if (empty($invoice)) {
228 228
         return false;
229 229
     }
230 230
 
231
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
231
+    if (!("wpi_invoice" === $invoice->post_type)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
236
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
237
-    if ( !is_email( $recipient ) ) {
235
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
236
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
237
+    if (!is_email($recipient)) {
238 238
         return false;
239 239
     }
240 240
 
241
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
241
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
242 242
 
243
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
244
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
245
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
246
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
247
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
243
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
244
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
245
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
246
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
247
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
248 248
     
249
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
249
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
250 250
             'invoice'       => $invoice,
251 251
             'email_type'    => $email_type,
252 252
             'email_heading' => $email_heading,
253 253
             'sent_to_admin' => false,
254 254
             'plain_text'    => false,
255 255
             'message_body'  => $message_body,
256
-        ) );
256
+        ));
257 257
     
258
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
258
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
259 259
     
260
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
261
-        $recipient  = wpinv_get_admin_email();
262
-        $subject    .= ' - ADMIN BCC COPY';
263
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
260
+    if (wpinv_mail_admin_bcc_active($email_type)) {
261
+        $recipient = wpinv_get_admin_email();
262
+        $subject .= ' - ADMIN BCC COPY';
263
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
264 264
     }
265 265
 
266
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
266
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
267 267
 
268 268
     return $sent;
269 269
 }
270 270
 
271
-function wpinv_processing_invoice_notification( $invoice_id, $new_status = '' ) {
271
+function wpinv_processing_invoice_notification($invoice_id, $new_status = '') {
272 272
     $email_type = 'processing_invoice';
273
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
273
+    if (!wpinv_email_is_enabled($email_type)) {
274 274
         return false;
275 275
     }
276 276
 
277
-    $invoice = wpinv_get_invoice( $invoice_id );
278
-    if ( empty( $invoice ) ) {
277
+    $invoice = wpinv_get_invoice($invoice_id);
278
+    if (empty($invoice)) {
279 279
         return false;
280 280
     }
281 281
 
282
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
282
+    if (!("wpi_invoice" === $invoice->post_type)) {
283 283
         return false;
284 284
     }
285 285
 
286
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
287
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
288
-    if ( !is_email( $recipient ) ) {
286
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
287
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
288
+    if (!is_email($recipient)) {
289 289
         return false;
290 290
     }
291 291
 
292
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
292
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
293 293
 
294 294
     $search                     = array();
295 295
     $search['invoice_number']   = '{invoice_number}';
296 296
     $search['invoice_date']     = '{invoice_date}';
297 297
     $search['name']             = '{name}';
298 298
 
299
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
300
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
301
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
302
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
303
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
299
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
300
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
301
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
302
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
303
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
304 304
     
305
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
305
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
306 306
             'invoice'       => $invoice,
307 307
             'email_type'    => $email_type,
308 308
             'email_heading' => $email_heading,
309 309
             'sent_to_admin' => false,
310 310
             'plain_text'    => false,
311 311
             'message_body'  => $message_body,
312
-        ) );
312
+        ));
313 313
 
314
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
314
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
315 315
 
316
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
317
-        $recipient  = wpinv_get_admin_email();
318
-        $subject    .= ' - ADMIN BCC COPY';
319
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
316
+    if (wpinv_mail_admin_bcc_active($email_type)) {
317
+        $recipient = wpinv_get_admin_email();
318
+        $subject .= ' - ADMIN BCC COPY';
319
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
320 320
     }
321 321
 
322
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
322
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
323 323
 
324 324
     return $sent;
325 325
 }
326 326
 
327
-function wpinv_completed_invoice_notification( $invoice_id, $new_status = '' ) {
327
+function wpinv_completed_invoice_notification($invoice_id, $new_status = '') {
328 328
     $email_type = 'completed_invoice';
329
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
329
+    if (!wpinv_email_is_enabled($email_type)) {
330 330
         return false;
331 331
     }
332 332
 
333
-    $invoice = wpinv_get_invoice( $invoice_id );
334
-    if ( empty( $invoice ) ) {
333
+    $invoice = wpinv_get_invoice($invoice_id);
334
+    if (empty($invoice)) {
335 335
         return false;
336 336
     }
337 337
 
338
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
338
+    if (!("wpi_invoice" === $invoice->post_type)) {
339 339
         return false;
340 340
     }
341 341
 
342
-    if($invoice->is_renewal() && wpinv_email_is_enabled( 'completed_invoice_renewal' )){
342
+    if ($invoice->is_renewal() && wpinv_email_is_enabled('completed_invoice_renewal')) {
343 343
         return false;
344 344
     }
345 345
 
346
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
347
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
348
-    if ( !is_email( $recipient ) ) {
346
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
347
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
348
+    if (!is_email($recipient)) {
349 349
         return false;
350 350
     }
351 351
 
352
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
352
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
353 353
 
354
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
355
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
356
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
357
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
358
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
354
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
355
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
356
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
357
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
358
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
359 359
 
360
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
360
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
361 361
             'invoice'       => $invoice,
362 362
             'email_type'    => $email_type,
363 363
             'email_heading' => $email_heading,
364 364
             'sent_to_admin' => false,
365 365
             'plain_text'    => false,
366 366
             'message_body'  => $message_body,
367
-        ) );
367
+        ));
368 368
 
369
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
369
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
370 370
 
371
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
372
-        $recipient  = wpinv_get_admin_email();
373
-        $subject    .= ' - ADMIN BCC COPY';
374
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
371
+    if (wpinv_mail_admin_bcc_active($email_type)) {
372
+        $recipient = wpinv_get_admin_email();
373
+        $subject .= ' - ADMIN BCC COPY';
374
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
375 375
     }
376 376
 
377
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
377
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
378 378
 
379 379
     return $sent;
380 380
 }
381 381
 
382
-function wpinv_fully_refunded_notification( $invoice_id, $new_status = '' ) {
382
+function wpinv_fully_refunded_notification($invoice_id, $new_status = '') {
383 383
     $email_type = 'refunded_invoice';
384
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
384
+    if (!wpinv_email_is_enabled($email_type)) {
385 385
         return false;
386 386
     }
387 387
 
388
-    $invoice = wpinv_get_invoice( $invoice_id );
389
-    if ( empty( $invoice ) ) {
388
+    $invoice = wpinv_get_invoice($invoice_id);
389
+    if (empty($invoice)) {
390 390
         return false;
391 391
     }
392 392
 
393
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
393
+    if (!("wpi_invoice" === $invoice->post_type)) {
394 394
         return false;
395 395
     }
396 396
 
397
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
398
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
399
-    if ( !is_email( $recipient ) ) {
397
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
398
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
399
+    if (!is_email($recipient)) {
400 400
         return false;
401 401
     }
402 402
 
403
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
403
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
404 404
 
405
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
406
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
407
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
408
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
409
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
405
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
406
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
407
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
408
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
409
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
410 410
 
411
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
411
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
412 412
             'invoice'           => $invoice,
413 413
             'email_type'        => $email_type,
414 414
             'email_heading'     => $email_heading,
@@ -416,51 +416,51 @@  discard block
 block discarded – undo
416 416
             'plain_text'        => false,
417 417
             'partial_refund'    => false,
418 418
             'message_body'      => $message_body,
419
-        ) );
419
+        ));
420 420
 
421
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
421
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
422 422
 
423
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
424
-        $recipient  = wpinv_get_admin_email();
425
-        $subject    .= ' - ADMIN BCC COPY';
426
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
423
+    if (wpinv_mail_admin_bcc_active($email_type)) {
424
+        $recipient = wpinv_get_admin_email();
425
+        $subject .= ' - ADMIN BCC COPY';
426
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
427 427
     }
428 428
 
429
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
429
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
430 430
 
431 431
     return $sent;
432 432
 }
433 433
 
434
-function wpinv_partially_refunded_notification( $invoice_id, $new_status = '' ) {
434
+function wpinv_partially_refunded_notification($invoice_id, $new_status = '') {
435 435
     $email_type = 'refunded_invoice';
436
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
436
+    if (!wpinv_email_is_enabled($email_type)) {
437 437
         return false;
438 438
     }
439 439
 
440
-    $invoice = wpinv_get_invoice( $invoice_id );
441
-    if ( empty( $invoice ) ) {
440
+    $invoice = wpinv_get_invoice($invoice_id);
441
+    if (empty($invoice)) {
442 442
         return false;
443 443
     }
444 444
 
445
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
445
+    if (!("wpi_invoice" === $invoice->post_type)) {
446 446
         return false;
447 447
     }
448 448
 
449
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
450
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
451
-    if ( !is_email( $recipient ) ) {
449
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
450
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
451
+    if (!is_email($recipient)) {
452 452
         return false;
453 453
     }
454 454
 
455
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
455
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
456 456
 
457
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
458
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
459
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
460
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
461
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
457
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
458
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
459
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
460
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
461
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
462 462
 
463
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
463
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
464 464
             'invoice'           => $invoice,
465 465
             'email_type'        => $email_type,
466 466
             'email_heading'     => $email_heading,
@@ -468,97 +468,97 @@  discard block
 block discarded – undo
468 468
             'plain_text'        => false,
469 469
             'partial_refund'    => true,
470 470
             'message_body'      => $message_body,
471
-        ) );
471
+        ));
472 472
 
473
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
473
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
474 474
 
475
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
476
-        $recipient  = wpinv_get_admin_email();
477
-        $subject    .= ' - ADMIN BCC COPY';
478
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
475
+    if (wpinv_mail_admin_bcc_active($email_type)) {
476
+        $recipient = wpinv_get_admin_email();
477
+        $subject .= ' - ADMIN BCC COPY';
478
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
479 479
     }
480 480
 
481
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
481
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
482 482
 
483 483
     return $sent;
484 484
 }
485 485
 
486
-function wpinv_new_invoice_note_notification( $invoice_id, $new_status = '' ) {
486
+function wpinv_new_invoice_note_notification($invoice_id, $new_status = '') {
487 487
 }
488 488
 
489
-function wpinv_user_invoice_notification( $invoice_id ) {
489
+function wpinv_user_invoice_notification($invoice_id) {
490 490
     $email_type = 'user_invoice';
491
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
491
+    if (!wpinv_email_is_enabled($email_type)) {
492 492
         return -1;
493 493
     }
494 494
 
495
-    $invoice = wpinv_get_invoice( $invoice_id );
496
-    if ( empty( $invoice ) ) {
495
+    $invoice = wpinv_get_invoice($invoice_id);
496
+    if (empty($invoice)) {
497 497
         return false;
498 498
     }
499 499
 
500
-    if ( !("wpi_invoice" === $invoice->post_type) ) {
500
+    if (!("wpi_invoice" === $invoice->post_type)) {
501 501
         return false;
502 502
     }
503 503
 
504
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
505
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
506
-    if ( !is_email( $recipient ) ) {
504
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
505
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
506
+    if (!is_email($recipient)) {
507 507
         return false;
508 508
     }
509 509
 
510
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
510
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
511 511
 
512
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
513
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
514
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
515
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
516
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
512
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
513
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
514
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
515
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
516
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
517 517
     
518
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
518
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
519 519
             'invoice'       => $invoice,
520 520
             'email_type'    => $email_type,
521 521
             'email_heading' => $email_heading,
522 522
             'sent_to_admin' => false,
523 523
             'plain_text'    => false,
524 524
             'message_body'  => $message_body,
525
-        ) );
525
+        ));
526 526
 
527
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
527
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
528 528
 
529
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
530
-        $recipient  = wpinv_get_admin_email();
531
-        $subject    .= ' - ADMIN BCC COPY';
532
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
529
+    if (wpinv_mail_admin_bcc_active($email_type)) {
530
+        $recipient = wpinv_get_admin_email();
531
+        $subject .= ' - ADMIN BCC COPY';
532
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
533 533
     }
534 534
 
535
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
535
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
536 536
 
537
-    if ( $sent ) {
538
-        $note = __( 'Invoice has been emailed to the user.', 'invoicing' );
537
+    if ($sent) {
538
+        $note = __('Invoice has been emailed to the user.', 'invoicing');
539 539
     } else {
540
-        $note = __( 'Fail to send invoice to the user!', 'invoicing' );
540
+        $note = __('Fail to send invoice to the user!', 'invoicing');
541 541
     }
542 542
 
543
-    $invoice->add_note( $note, '', '', true ); // Add system note.
543
+    $invoice->add_note($note, '', '', true); // Add system note.
544 544
 
545 545
     return $sent;
546 546
 }
547 547
 
548
-function wpinv_user_note_notification( $invoice_id, $args = array() ) {
548
+function wpinv_user_note_notification($invoice_id, $args = array()) {
549 549
     $email_type = 'user_note';
550
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
550
+    if (!wpinv_email_is_enabled($email_type)) {
551 551
         return false;
552 552
     }
553 553
 
554
-    $invoice = wpinv_get_invoice( $invoice_id );
555
-    if ( empty( $invoice ) ) {
554
+    $invoice = wpinv_get_invoice($invoice_id);
555
+    if (empty($invoice)) {
556 556
         return false;
557 557
     }
558 558
 
559
-    $recipient      = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
560
-    $extra          = wpinv_email_get_cc_recipients( $email_type, $invoice_id, $invoice );
561
-    if ( !is_email( $recipient ) ) {
559
+    $recipient      = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
560
+    $extra          = wpinv_email_get_cc_recipients($email_type, $invoice_id, $invoice);
561
+    if (!is_email($recipient)) {
562 562
         return false;
563 563
     }
564 564
 
@@ -566,19 +566,19 @@  discard block
 block discarded – undo
566 566
         'user_note' => ''
567 567
     );
568 568
 
569
-    $args = wp_parse_args( $args, $defaults );
569
+    $args = wp_parse_args($args, $defaults);
570 570
 
571
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
571
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
572 572
 
573
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
574
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
575
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
576
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
577
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
573
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
574
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
575
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
576
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
577
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
578 578
 
579
-    $message_body   = str_replace( '{customer_note}', $args['user_note'], $message_body );
579
+    $message_body   = str_replace('{customer_note}', $args['user_note'], $message_body);
580 580
 
581
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
581
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
582 582
             'invoice'       => $invoice,
583 583
             'email_type'    => $email_type,
584 584
             'email_heading' => $email_heading,
@@ -586,36 +586,36 @@  discard block
 block discarded – undo
586 586
             'plain_text'    => false,
587 587
             'message_body'  => $message_body,
588 588
             'customer_note' => $args['user_note']
589
-        ) );
589
+        ));
590 590
 
591
-    $content        = wpinv_email_format_text( $content, $invoice );
591
+    $content = wpinv_email_format_text($content, $invoice);
592 592
 
593
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments, $extra );
593
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments, $extra);
594 594
 
595
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
595
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
596 596
 
597 597
     return $sent;
598 598
 }
599 599
 
600 600
 function wpinv_mail_get_from_address() {
601
-    $from_address = apply_filters( 'wpinv_mail_from_address', wpinv_get_option( 'email_from' ) );
602
-    return sanitize_email( $from_address );
601
+    $from_address = apply_filters('wpinv_mail_from_address', wpinv_get_option('email_from'));
602
+    return sanitize_email($from_address);
603 603
 }
604 604
 
605 605
 function wpinv_mail_get_from_name() {
606
-    $from_name = apply_filters( 'wpinv_mail_from_name', wpinv_get_option( 'email_from_name' ) );
607
-    return wp_specialchars_decode( esc_html( $from_name ), ENT_QUOTES );
606
+    $from_name = apply_filters('wpinv_mail_from_name', wpinv_get_option('email_from_name'));
607
+    return wp_specialchars_decode(esc_html($from_name), ENT_QUOTES);
608 608
 }
609 609
 
610
-function wpinv_mail_admin_bcc_active( $mail_type = '' ) {
611
-    $active = apply_filters( 'wpinv_mail_admin_bcc_active', wpinv_get_option( 'email_' . $mail_type . '_admin_bcc' ) );
612
-    return ( $active ? true : false );
610
+function wpinv_mail_admin_bcc_active($mail_type = '') {
611
+    $active = apply_filters('wpinv_mail_admin_bcc_active', wpinv_get_option('email_' . $mail_type . '_admin_bcc'));
612
+    return ($active ? true : false);
613 613
 }
614 614
     
615
-function wpinv_mail_get_content_type(  $content_type = 'text/html', $email_type = 'html' ) {
616
-    $email_type = apply_filters( 'wpinv_mail_content_type', $email_type );
615
+function wpinv_mail_get_content_type($content_type = 'text/html', $email_type = 'html') {
616
+    $email_type = apply_filters('wpinv_mail_content_type', $email_type);
617 617
 
618
-    switch ( $email_type ) {
618
+    switch ($email_type) {
619 619
         case 'html' :
620 620
             $content_type = 'text/html';
621 621
             break;
@@ -630,43 +630,43 @@  discard block
 block discarded – undo
630 630
     return $content_type;
631 631
 }
632 632
     
633
-function wpinv_mail_send( $to, $subject, $message, $headers, $attachments, $cc = array() ) {
634
-    add_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
635
-    add_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
636
-    add_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
633
+function wpinv_mail_send($to, $subject, $message, $headers, $attachments, $cc = array()) {
634
+    add_filter('wp_mail_from', 'wpinv_mail_get_from_address');
635
+    add_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
636
+    add_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
637 637
 
638
-    $message = wpinv_email_style_body( $message );
639
-    $message = apply_filters( 'wpinv_mail_content', $message );
638
+    $message = wpinv_email_style_body($message);
639
+    $message = apply_filters('wpinv_mail_content', $message);
640 640
 
641
-    if ( ! empty( $cc ) && is_array( $cc ) ) {
642
-        if ( ! is_array( $to ) ) {
643
-            $to = array( $to );
641
+    if (!empty($cc) && is_array($cc)) {
642
+        if (!is_array($to)) {
643
+            $to = array($to);
644 644
         }
645 645
 
646
-        $to = array_unique( array_merge( $to, $cc ) );
646
+        $to = array_unique(array_merge($to, $cc));
647 647
     }
648 648
 
649
-    $sent  = wp_mail( $to, $subject, $message, $headers, $attachments );
649
+    $sent = wp_mail($to, $subject, $message, $headers, $attachments);
650 650
 
651
-    if ( !$sent ) {
652
-        $log_message = wp_sprintf( __( "\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing' ), date_i18n( 'F j Y H:i:s', current_time( 'timestamp' ) ), ( is_array( $to ) ? implode( ', ', $to ) : $to ), $subject );
653
-        wpinv_error_log( $log_message, __( "Email from Invoicing plugin failed to send", 'invoicing' ), __FILE__, __LINE__ );
651
+    if (!$sent) {
652
+        $log_message = wp_sprintf(__("\nTime: %s\nTo: %s\nSubject: %s\n", 'invoicing'), date_i18n('F j Y H:i:s', current_time('timestamp')), (is_array($to) ? implode(', ', $to) : $to), $subject);
653
+        wpinv_error_log($log_message, __("Email from Invoicing plugin failed to send", 'invoicing'), __FILE__, __LINE__);
654 654
     }
655 655
 
656
-    remove_filter( 'wp_mail_from', 'wpinv_mail_get_from_address' );
657
-    remove_filter( 'wp_mail_from_name', 'wpinv_mail_get_from_name' );
658
-    remove_filter( 'wp_mail_content_type', 'wpinv_mail_get_content_type' );
656
+    remove_filter('wp_mail_from', 'wpinv_mail_get_from_address');
657
+    remove_filter('wp_mail_from_name', 'wpinv_mail_get_from_name');
658
+    remove_filter('wp_mail_content_type', 'wpinv_mail_get_content_type');
659 659
 
660 660
     return $sent;
661 661
 }
662 662
     
663 663
 function wpinv_get_emails() {
664 664
     $overdue_days_options       = array();
665
-    $overdue_days_options[0]    = __( 'On the Due Date', 'invoicing' );
666
-    $overdue_days_options[1]    = __( '1 day after Due Date', 'invoicing' );
665
+    $overdue_days_options[0]    = __('On the Due Date', 'invoicing');
666
+    $overdue_days_options[1]    = __('1 day after Due Date', 'invoicing');
667 667
 
668
-    for ( $i = 2; $i <= 10; $i++ ) {
669
-        $overdue_days_options[$i]   = wp_sprintf( __( '%d days after Due Date', 'invoicing' ), $i );
668
+    for ($i = 2; $i <= 10; $i++) {
669
+        $overdue_days_options[$i] = wp_sprintf(__('%d days after Due Date', 'invoicing'), $i);
670 670
     }
671 671
 
672 672
     // Default, built-in gateways
@@ -674,39 +674,39 @@  discard block
 block discarded – undo
674 674
             'new_invoice' => array(
675 675
             'email_new_invoice_header' => array(
676 676
                 'id'   => 'email_new_invoice_header',
677
-                'name' => '<h3>' . __( 'New Invoice', 'invoicing' ) . '</h3>',
678
-                'desc' => __( 'New invoice emails are sent to admin when a new invoice is received.', 'invoicing' ),
677
+                'name' => '<h3>' . __('New Invoice', 'invoicing') . '</h3>',
678
+                'desc' => __('New invoice emails are sent to admin when a new invoice is received.', 'invoicing'),
679 679
                 'type' => 'header',
680 680
             ),
681 681
             'email_new_invoice_active' => array(
682 682
                 'id'   => 'email_new_invoice_active',
683
-                'name' => __( 'Enable/Disable', 'invoicing' ),
684
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
683
+                'name' => __('Enable/Disable', 'invoicing'),
684
+                'desc' => __('Enable this email notification', 'invoicing'),
685 685
                 'type' => 'checkbox',
686 686
                 'std'  => 1
687 687
             ),
688 688
             'email_new_invoice_subject' => array(
689 689
                 'id'   => 'email_new_invoice_subject',
690
-                'name' => __( 'Subject', 'invoicing' ),
691
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
690
+                'name' => __('Subject', 'invoicing'),
691
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
692 692
                 'type' => 'text',
693
-                'std'  => __( '[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing' ),
693
+                'std'  => __('[{site_title}] New payment invoice ({invoice_number}) - {invoice_date}', 'invoicing'),
694 694
                 'size' => 'large'
695 695
             ),
696 696
             'email_new_invoice_heading' => array(
697 697
                 'id'   => 'email_new_invoice_heading',
698
-                'name' => __( 'Email Heading', 'invoicing' ),
699
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
698
+                'name' => __('Email Heading', 'invoicing'),
699
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
700 700
                 'type' => 'text',
701
-                'std'  => __( 'New payment invoice', 'invoicing' ),
701
+                'std'  => __('New payment invoice', 'invoicing'),
702 702
                 'size' => 'large'
703 703
             ),
704 704
             'email_new_invoice_body' => array(
705 705
                 'id'   => 'email_new_invoice_body',
706
-                'name' => __( 'Email Content', 'invoicing' ),
707
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
706
+                'name' => __('Email Content', 'invoicing'),
707
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
708 708
                 'type' => 'rich_editor',
709
-                'std'  => __( '<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing' ),
709
+                'std'  => __('<p>Hi Admin,</p><p>You have received payment invoice from {name}.</p>', 'invoicing'),
710 710
                 'class' => 'large',
711 711
                 'size' => '10'
712 712
             ),
@@ -714,39 +714,39 @@  discard block
 block discarded – undo
714 714
         'cancelled_invoice' => array(
715 715
             'email_cancelled_invoice_header' => array(
716 716
                 'id'   => 'email_cancelled_invoice_header',
717
-                'name' => '<h3>' . __( 'Cancelled Invoice', 'invoicing' ) . '</h3>',
718
-                'desc' => __( 'Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing' ),
717
+                'name' => '<h3>' . __('Cancelled Invoice', 'invoicing') . '</h3>',
718
+                'desc' => __('Cancelled invoice emails are sent to admin when invoices have been marked cancelled.', 'invoicing'),
719 719
                 'type' => 'header',
720 720
             ),
721 721
             'email_cancelled_invoice_active' => array(
722 722
                 'id'   => 'email_cancelled_invoice_active',
723
-                'name' => __( 'Enable/Disable', 'invoicing' ),
724
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
723
+                'name' => __('Enable/Disable', 'invoicing'),
724
+                'desc' => __('Enable this email notification', 'invoicing'),
725 725
                 'type' => 'checkbox',
726 726
                 'std'  => 1
727 727
             ),
728 728
             'email_cancelled_invoice_subject' => array(
729 729
                 'id'   => 'email_cancelled_invoice_subject',
730
-                'name' => __( 'Subject', 'invoicing' ),
731
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
730
+                'name' => __('Subject', 'invoicing'),
731
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
732 732
                 'type' => 'text',
733
-                'std'  => __( '[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing' ),
733
+                'std'  => __('[{site_title}] Cancelled invoice ({invoice_number})', 'invoicing'),
734 734
                 'size' => 'large'
735 735
             ),
736 736
             'email_cancelled_invoice_heading' => array(
737 737
                 'id'   => 'email_cancelled_invoice_heading',
738
-                'name' => __( 'Email Heading', 'invoicing' ),
739
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
738
+                'name' => __('Email Heading', 'invoicing'),
739
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
740 740
                 'type' => 'text',
741
-                'std'  => __( 'Cancelled invoice', 'invoicing' ),
741
+                'std'  => __('Cancelled invoice', 'invoicing'),
742 742
                 'size' => 'large'
743 743
             ),
744 744
             'email_cancelled_invoice_body' => array(
745 745
                 'id'   => 'email_cancelled_invoice_body',
746
-                'name' => __( 'Email Content', 'invoicing' ),
747
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
746
+                'name' => __('Email Content', 'invoicing'),
747
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
748 748
                 'type' => 'rich_editor',
749
-                'std'  => __( '<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing' ),
749
+                'std'  => __('<p>Hi Admin,</p><p>The invoice #{invoice_number} from {site_title} has been cancelled.</p>', 'invoicing'),
750 750
                 'class' => 'large',
751 751
                 'size' => '10'
752 752
             ),
@@ -754,39 +754,39 @@  discard block
 block discarded – undo
754 754
         'failed_invoice' => array(
755 755
             'email_failed_invoice_header' => array(
756 756
                 'id'   => 'email_failed_invoice_header',
757
-                'name' => '<h3>' . __( 'Failed Invoice', 'invoicing' ) . '</h3>',
758
-                'desc' => __( 'Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing' ),
757
+                'name' => '<h3>' . __('Failed Invoice', 'invoicing') . '</h3>',
758
+                'desc' => __('Failed invoice emails are sent to admin when invoices have been marked failed (if they were previously processing or on-hold).', 'invoicing'),
759 759
                 'type' => 'header',
760 760
             ),
761 761
             'email_failed_invoice_active' => array(
762 762
                 'id'   => 'email_failed_invoice_active',
763
-                'name' => __( 'Enable/Disable', 'invoicing' ),
764
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
763
+                'name' => __('Enable/Disable', 'invoicing'),
764
+                'desc' => __('Enable this email notification', 'invoicing'),
765 765
                 'type' => 'checkbox',
766 766
                 'std'  => 1
767 767
             ),
768 768
             'email_failed_invoice_subject' => array(
769 769
                 'id'   => 'email_failed_invoice_subject',
770
-                'name' => __( 'Subject', 'invoicing' ),
771
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
770
+                'name' => __('Subject', 'invoicing'),
771
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
772 772
                 'type' => 'text',
773
-                'std'  => __( '[{site_title}] Failed invoice ({invoice_number})', 'invoicing' ),
773
+                'std'  => __('[{site_title}] Failed invoice ({invoice_number})', 'invoicing'),
774 774
                 'size' => 'large'
775 775
             ),
776 776
             'email_failed_invoice_heading' => array(
777 777
                 'id'   => 'email_failed_invoice_heading',
778
-                'name' => __( 'Email Heading', 'invoicing' ),
779
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
778
+                'name' => __('Email Heading', 'invoicing'),
779
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
780 780
                 'type' => 'text',
781
-                'std'  => __( 'Failed invoice', 'invoicing' ),
781
+                'std'  => __('Failed invoice', 'invoicing'),
782 782
                 'size' => 'large'
783 783
             ),
784 784
             'email_failed_invoice_body' => array(
785 785
                 'id'   => 'email_failed_invoice_body',
786
-                'name' => __( 'Email Content', 'invoicing' ),
787
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
786
+                'name' => __('Email Content', 'invoicing'),
787
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
788 788
                 'type' => 'rich_editor',
789
-                'std'  => __( '<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing' ),
789
+                'std'  => __('<p>Hi Admin,</p><p>Payment for invoice #{invoice_number} from {site_title} has been failed.</p>', 'invoicing'),
790 790
                 'class' => 'large',
791 791
                 'size' => '10'
792 792
             ),
@@ -794,46 +794,46 @@  discard block
 block discarded – undo
794 794
         'onhold_invoice' => array(
795 795
             'email_onhold_invoice_header' => array(
796 796
                 'id'   => 'email_onhold_invoice_header',
797
-                'name' => '<h3>' . __( 'On Hold Invoice', 'invoicing' ) . '</h3>',
798
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing' ),
797
+                'name' => '<h3>' . __('On Hold Invoice', 'invoicing') . '</h3>',
798
+                'desc' => __('This is an invoice notification sent to users containing invoice details after an invoice is placed on-hold.', 'invoicing'),
799 799
                 'type' => 'header',
800 800
             ),
801 801
             'email_onhold_invoice_active' => array(
802 802
                 'id'   => 'email_onhold_invoice_active',
803
-                'name' => __( 'Enable/Disable', 'invoicing' ),
804
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
803
+                'name' => __('Enable/Disable', 'invoicing'),
804
+                'desc' => __('Enable this email notification', 'invoicing'),
805 805
                 'type' => 'checkbox',
806 806
                 'std'  => 1
807 807
             ),
808 808
             'email_onhold_invoice_subject' => array(
809 809
                 'id'   => 'email_onhold_invoice_subject',
810
-                'name' => __( 'Subject', 'invoicing' ),
811
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
810
+                'name' => __('Subject', 'invoicing'),
811
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
812 812
                 'type' => 'text',
813
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
813
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
814 814
                 'size' => 'large'
815 815
             ),
816 816
             'email_onhold_invoice_heading' => array(
817 817
                 'id'   => 'email_onhold_invoice_heading',
818
-                'name' => __( 'Email Heading', 'invoicing' ),
819
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
818
+                'name' => __('Email Heading', 'invoicing'),
819
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
820 820
                 'type' => 'text',
821
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
821
+                'std'  => __('Thank you for your invoice', 'invoicing'),
822 822
                 'size' => 'large'
823 823
             ),
824 824
             'email_onhold_invoice_admin_bcc' => array(
825 825
                 'id'   => 'email_onhold_invoice_admin_bcc',
826
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
827
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
826
+                'name' => __('Enable Admin BCC', 'invoicing'),
827
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
828 828
                 'type' => 'checkbox',
829 829
                 'std'  => 1
830 830
             ),
831 831
             'email_onhold_invoice_body' => array(
832 832
                 'id'   => 'email_onhold_invoice_body',
833
-                'name' => __( 'Email Content', 'invoicing' ),
834
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
833
+                'name' => __('Email Content', 'invoicing'),
834
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
835 835
                 'type' => 'rich_editor',
836
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing' ),
836
+                'std'  => __('<p>Hi {name},</p><p>Your invoice is on-hold until we confirm your payment has been received.</p>', 'invoicing'),
837 837
                 'class' => 'large',
838 838
                 'size' => '10'
839 839
             ),
@@ -841,46 +841,46 @@  discard block
 block discarded – undo
841 841
         'processing_invoice' => array(
842 842
             'email_processing_invoice_header' => array(
843 843
                 'id'   => 'email_processing_invoice_header',
844
-                'name' => '<h3>' . __( 'Processing Invoice', 'invoicing' ) . '</h3>',
845
-                'desc' => __( 'This is an invoice notification sent to users containing invoice details after payment.', 'invoicing' ),
844
+                'name' => '<h3>' . __('Processing Invoice', 'invoicing') . '</h3>',
845
+                'desc' => __('This is an invoice notification sent to users containing invoice details after payment.', 'invoicing'),
846 846
                 'type' => 'header',
847 847
             ),
848 848
             'email_processing_invoice_active' => array(
849 849
                 'id'   => 'email_processing_invoice_active',
850
-                'name' => __( 'Enable/Disable', 'invoicing' ),
851
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
850
+                'name' => __('Enable/Disable', 'invoicing'),
851
+                'desc' => __('Enable this email notification', 'invoicing'),
852 852
                 'type' => 'checkbox',
853 853
                 'std'  => 1
854 854
             ),
855 855
             'email_processing_invoice_subject' => array(
856 856
                 'id'   => 'email_processing_invoice_subject',
857
-                'name' => __( 'Subject', 'invoicing' ),
858
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
857
+                'name' => __('Subject', 'invoicing'),
858
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
859 859
                 'type' => 'text',
860
-                'std'  => __( '[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing' ),
860
+                'std'  => __('[{site_title}] Your invoice receipt from {invoice_date}', 'invoicing'),
861 861
                 'size' => 'large'
862 862
             ),
863 863
             'email_processing_invoice_heading' => array(
864 864
                 'id'   => 'email_processing_invoice_heading',
865
-                'name' => __( 'Email Heading', 'invoicing' ),
866
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
865
+                'name' => __('Email Heading', 'invoicing'),
866
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
867 867
                 'type' => 'text',
868
-                'std'  => __( 'Thank you for your invoice', 'invoicing' ),
868
+                'std'  => __('Thank you for your invoice', 'invoicing'),
869 869
                 'size' => 'large'
870 870
             ),
871 871
             'email_processing_invoice_admin_bcc' => array(
872 872
                 'id'   => 'email_processing_invoice_admin_bcc',
873
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
874
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
873
+                'name' => __('Enable Admin BCC', 'invoicing'),
874
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
875 875
                 'type' => 'checkbox',
876 876
                 'std'  => 1
877 877
             ),
878 878
             'email_processing_invoice_body' => array(
879 879
                 'id'   => 'email_processing_invoice_body',
880
-                'name' => __( 'Email Content', 'invoicing' ),
881
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
880
+                'name' => __('Email Content', 'invoicing'),
881
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
882 882
                 'type' => 'rich_editor',
883
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing' ),
883
+                'std'  => __('<p>Hi {name},</p><p>Your invoice has been received at {site_title} and is now being processed.</p>', 'invoicing'),
884 884
                 'class' => 'large',
885 885
                 'size' => '10'
886 886
             ),
@@ -888,52 +888,52 @@  discard block
 block discarded – undo
888 888
         'completed_invoice' => array(
889 889
             'email_completed_invoice_header' => array(
890 890
                 'id'   => 'email_completed_invoice_header',
891
-                'name' => '<h3>' . __( 'Paid Invoice', 'invoicing' ) . '</h3>',
892
-                'desc' => __( 'Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing' ),
891
+                'name' => '<h3>' . __('Paid Invoice', 'invoicing') . '</h3>',
892
+                'desc' => __('Invoice paid emails are sent to users when their invoices are marked paid and usually indicate that their payment has been done.', 'invoicing'),
893 893
                 'type' => 'header',
894 894
             ),
895 895
             'email_completed_invoice_active' => array(
896 896
                 'id'   => 'email_completed_invoice_active',
897
-                'name' => __( 'Enable/Disable', 'invoicing' ),
898
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
897
+                'name' => __('Enable/Disable', 'invoicing'),
898
+                'desc' => __('Enable this email notification', 'invoicing'),
899 899
                 'type' => 'checkbox',
900 900
                 'std'  => 1
901 901
             ),
902 902
             'email_completed_invoice_renewal_active' => array(
903 903
                 'id'   => 'email_completed_invoice_renewal_active',
904
-                'name' => __( 'Enable renewal notification', 'invoicing' ),
905
-                'desc' => __( 'Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing' ),
904
+                'name' => __('Enable renewal notification', 'invoicing'),
905
+                'desc' => __('Enable renewal invoice email notification. This notification will be sent on renewal.', 'invoicing'),
906 906
                 'type' => 'checkbox',
907 907
                 'std'  => 0
908 908
             ),
909 909
             'email_completed_invoice_subject' => array(
910 910
                 'id'   => 'email_completed_invoice_subject',
911
-                'name' => __( 'Subject', 'invoicing' ),
912
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
911
+                'name' => __('Subject', 'invoicing'),
912
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
913 913
                 'type' => 'text',
914
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing' ),
914
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been paid', 'invoicing'),
915 915
                 'size' => 'large'
916 916
             ),
917 917
             'email_completed_invoice_heading' => array(
918 918
                 'id'   => 'email_completed_invoice_heading',
919
-                'name' => __( 'Email Heading', 'invoicing' ),
920
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
919
+                'name' => __('Email Heading', 'invoicing'),
920
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
921 921
                 'type' => 'text',
922
-                'std'  => __( 'Your invoice has been paid', 'invoicing' ),
922
+                'std'  => __('Your invoice has been paid', 'invoicing'),
923 923
                 'size' => 'large'
924 924
             ),
925 925
             'email_completed_invoice_admin_bcc' => array(
926 926
                 'id'   => 'email_completed_invoice_admin_bcc',
927
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
928
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
927
+                'name' => __('Enable Admin BCC', 'invoicing'),
928
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
929 929
                 'type' => 'checkbox',
930 930
             ),
931 931
             'email_completed_invoice_body' => array(
932 932
                 'id'   => 'email_completed_invoice_body',
933
-                'name' => __( 'Email Content', 'invoicing' ),
934
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
933
+                'name' => __('Email Content', 'invoicing'),
934
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
935 935
                 'type' => 'rich_editor',
936
-                'std'  => __( '<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing' ),
936
+                'std'  => __('<p>Hi {name},</p><p>Your recent invoice on {site_title} has been paid.</p>', 'invoicing'),
937 937
                 'class' => 'large',
938 938
                 'size' => '10'
939 939
             ),
@@ -942,46 +942,46 @@  discard block
 block discarded – undo
942 942
         'refunded_invoice' => array(
943 943
             'email_refunded_invoice_header' => array(
944 944
                 'id'   => 'email_refunded_invoice_header',
945
-                'name' => '<h3>' . __( 'Refunded Invoice', 'invoicing' ) . '</h3>',
946
-                'desc' => __( 'Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing' ),
945
+                'name' => '<h3>' . __('Refunded Invoice', 'invoicing') . '</h3>',
946
+                'desc' => __('Invoice refunded emails are sent to users when their invoices are marked refunded.', 'invoicing'),
947 947
                 'type' => 'header',
948 948
             ),
949 949
             'email_refunded_invoice_active' => array(
950 950
                 'id'   => 'email_refunded_invoice_active',
951
-                'name' => __( 'Enable/Disable', 'invoicing' ),
952
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
951
+                'name' => __('Enable/Disable', 'invoicing'),
952
+                'desc' => __('Enable this email notification', 'invoicing'),
953 953
                 'type' => 'checkbox',
954 954
                 'std'  => 1
955 955
             ),
956 956
             'email_refunded_invoice_subject' => array(
957 957
                 'id'   => 'email_refunded_invoice_subject',
958
-                'name' => __( 'Subject', 'invoicing' ),
959
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
958
+                'name' => __('Subject', 'invoicing'),
959
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
960 960
                 'type' => 'text',
961
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing' ),
961
+                'std'  => __('[{site_title}] Your invoice from {invoice_date} has been refunded', 'invoicing'),
962 962
                 'size' => 'large'
963 963
             ),
964 964
             'email_refunded_invoice_heading' => array(
965 965
                 'id'   => 'email_refunded_invoice_heading',
966
-                'name' => __( 'Email Heading', 'invoicing' ),
967
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
966
+                'name' => __('Email Heading', 'invoicing'),
967
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
968 968
                 'type' => 'text',
969
-                'std'  => __( 'Your invoice has been refunded', 'invoicing' ),
969
+                'std'  => __('Your invoice has been refunded', 'invoicing'),
970 970
                 'size' => 'large'
971 971
             ),
972 972
             'email_refunded_invoice_admin_bcc' => array(
973 973
                 'id'   => 'email_refunded_invoice_admin_bcc',
974
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
975
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
974
+                'name' => __('Enable Admin BCC', 'invoicing'),
975
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
976 976
                 'type' => 'checkbox',
977 977
                 'std'  => 1
978 978
             ),
979 979
             'email_refunded_invoice_body' => array(
980 980
                 'id'   => 'email_refunded_invoice_body',
981
-                'name' => __( 'Email Content', 'invoicing' ),
982
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
981
+                'name' => __('Email Content', 'invoicing'),
982
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
983 983
                 'type' => 'rich_editor',
984
-                'std'  => __( '<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing' ),
984
+                'std'  => __('<p>Hi {name},</p><p>Your invoice on {site_title} has been refunded.</p>', 'invoicing'),
985 985
                 'class' => 'large',
986 986
                 'size' => '10'
987 987
             ),
@@ -989,46 +989,46 @@  discard block
 block discarded – undo
989 989
         'user_invoice' => array(
990 990
             'email_user_invoice_header' => array(
991 991
                 'id'   => 'email_user_invoice_header',
992
-                'name' => '<h3>' . __( 'Customer Invoice', 'invoicing' ) . '</h3>',
993
-                'desc' => __( 'Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing' ),
992
+                'name' => '<h3>' . __('Customer Invoice', 'invoicing') . '</h3>',
993
+                'desc' => __('Customer invoice emails can be sent to customers containing their invoice information and payment links.', 'invoicing'),
994 994
                 'type' => 'header',
995 995
             ),
996 996
             'email_user_invoice_active' => array(
997 997
                 'id'   => 'email_user_invoice_active',
998
-                'name' => __( 'Enable/Disable', 'invoicing' ),
999
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
998
+                'name' => __('Enable/Disable', 'invoicing'),
999
+                'desc' => __('Enable this email notification', 'invoicing'),
1000 1000
                 'type' => 'checkbox',
1001 1001
                 'std'  => 1
1002 1002
             ),
1003 1003
             'email_user_invoice_subject' => array(
1004 1004
                 'id'   => 'email_user_invoice_subject',
1005
-                'name' => __( 'Subject', 'invoicing' ),
1006
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1005
+                'name' => __('Subject', 'invoicing'),
1006
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1007 1007
                 'type' => 'text',
1008
-                'std'  => __( '[{site_title}] Your invoice from {invoice_date}', 'invoicing' ),
1008
+                'std'  => __('[{site_title}] Your invoice from {invoice_date}', 'invoicing'),
1009 1009
                 'size' => 'large'
1010 1010
             ),
1011 1011
             'email_user_invoice_heading' => array(
1012 1012
                 'id'   => 'email_user_invoice_heading',
1013
-                'name' => __( 'Email Heading', 'invoicing' ),
1014
-                'desc' => __( 'Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing' ),
1013
+                'name' => __('Email Heading', 'invoicing'),
1014
+                'desc' => __('Enter the main heading contained within the email notification for the invoice receipt email.', 'invoicing'),
1015 1015
                 'type' => 'text',
1016
-                'std'  => __( 'Your invoice {invoice_number} details', 'invoicing' ),
1016
+                'std'  => __('Your invoice {invoice_number} details', 'invoicing'),
1017 1017
                 'size' => 'large'
1018 1018
             ),
1019 1019
             'email_user_invoice_admin_bcc' => array(
1020 1020
                 'id'   => 'email_user_invoice_admin_bcc',
1021
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1022
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1021
+                'name' => __('Enable Admin BCC', 'invoicing'),
1022
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1023 1023
                 'type' => 'checkbox',
1024 1024
                 'std'  => 1
1025 1025
             ),
1026 1026
             'email_user_invoice_body' => array(
1027 1027
                 'id'   => 'email_user_invoice_body',
1028
-                'name' => __( 'Email Content', 'invoicing' ),
1029
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1028
+                'name' => __('Email Content', 'invoicing'),
1029
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1030 1030
                 'type' => 'rich_editor',
1031
-                'std'  => __( '<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1031
+                'std'  => __('<p>Hi {name},</p><p>An invoice has been created for you on {site_title}. To view / pay for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1032 1032
                 'class' => 'large',
1033 1033
                 'size' => '10'
1034 1034
             ),
@@ -1036,39 +1036,39 @@  discard block
 block discarded – undo
1036 1036
         'user_note' => array(
1037 1037
             'email_user_note_header' => array(
1038 1038
                 'id'   => 'email_user_note_header',
1039
-                'name' => '<h3>' . __( 'Customer Note', 'invoicing' ) . '</h3>',
1040
-                'desc' => __( 'Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing' ),
1039
+                'name' => '<h3>' . __('Customer Note', 'invoicing') . '</h3>',
1040
+                'desc' => __('Customer note emails are sent when you add a note to an invoice/quote.', 'invoicing'),
1041 1041
                 'type' => 'header',
1042 1042
             ),
1043 1043
             'email_user_note_active' => array(
1044 1044
                 'id'   => 'email_user_note_active',
1045
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1046
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1045
+                'name' => __('Enable/Disable', 'invoicing'),
1046
+                'desc' => __('Enable this email notification', 'invoicing'),
1047 1047
                 'type' => 'checkbox',
1048 1048
                 'std'  => 1
1049 1049
             ),
1050 1050
             'email_user_note_subject' => array(
1051 1051
                 'id'   => 'email_user_note_subject',
1052
-                'name' => __( 'Subject', 'invoicing' ),
1053
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1052
+                'name' => __('Subject', 'invoicing'),
1053
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1054 1054
                 'type' => 'text',
1055
-                'std'  => __( '[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing' ),
1055
+                'std'  => __('[{site_title}] Note added to your {invoice_label} #{invoice_number} from {invoice_date}', 'invoicing'),
1056 1056
                 'size' => 'large'
1057 1057
             ),
1058 1058
             'email_user_note_heading' => array(
1059 1059
                 'id'   => 'email_user_note_heading',
1060
-                'name' => __( 'Email Heading', 'invoicing' ),
1061
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1060
+                'name' => __('Email Heading', 'invoicing'),
1061
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1062 1062
                 'type' => 'text',
1063
-                'std'  => __( 'A note has been added to your {invoice_label}', 'invoicing' ),
1063
+                'std'  => __('A note has been added to your {invoice_label}', 'invoicing'),
1064 1064
                 'size' => 'large'
1065 1065
             ),
1066 1066
             'email_user_note_body' => array(
1067 1067
                 'id'   => 'email_user_note_body',
1068
-                'name' => __( 'Email Content', 'invoicing' ),
1069
-                'desc' => __( 'The content of the email (wildcards and HTML are allowed).', 'invoicing' ),
1068
+                'name' => __('Email Content', 'invoicing'),
1069
+                'desc' => __('The content of the email (wildcards and HTML are allowed).', 'invoicing'),
1070 1070
                 'type' => 'rich_editor',
1071
-                'std'  => __( '<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing' ),
1071
+                'std'  => __('<p>Hi {name},</p><p>Following note has been added to your {invoice_label}:</p><blockquote class="wpinv-note">{customer_note}</blockquote>', 'invoicing'),
1072 1072
                 'class' => 'large',
1073 1073
                 'size' => '10'
1074 1074
             ),
@@ -1077,54 +1077,54 @@  discard block
 block discarded – undo
1077 1077
         'pre_payment' => array(
1078 1078
             'email_pre_payment_header' => array(
1079 1079
                 'id'   => 'email_pre_payment_header',
1080
-                'name' => '<h3>' . __( 'Renewal Reminder', 'invoicing' ) . '</h3>',
1081
-                'desc' => __( 'Renewal reminder emails are sent to user automatically.', 'invoicing' ),
1080
+                'name' => '<h3>' . __('Renewal Reminder', 'invoicing') . '</h3>',
1081
+                'desc' => __('Renewal reminder emails are sent to user automatically.', 'invoicing'),
1082 1082
                 'type' => 'header',
1083 1083
             ),
1084 1084
             'email_pre_payment_active' => array(
1085 1085
                 'id'   => 'email_pre_payment_active',
1086
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1087
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1086
+                'name' => __('Enable/Disable', 'invoicing'),
1087
+                'desc' => __('Enable this email notification', 'invoicing'),
1088 1088
                 'type' => 'checkbox',
1089 1089
                 'std'  => 1
1090 1090
             ),
1091 1091
             'email_pre_payment_reminder_days' => array(
1092 1092
                 'id'            => 'email_pre_payment_reminder_days',
1093
-                'name'          => __( 'When to Send', 'invoicing' ),
1094
-                'desc'          => __( 'Enter a comma separated list of days before renewal when this email should be sent.', 'invoicing' ),
1093
+                'name'          => __('When to Send', 'invoicing'),
1094
+                'desc'          => __('Enter a comma separated list of days before renewal when this email should be sent.', 'invoicing'),
1095 1095
                 'default'       => '',
1096 1096
                 'type'          => 'text',
1097 1097
                 'std'           => '1,5,10',
1098 1098
             ),
1099 1099
             'email_pre_payment_subject' => array(
1100 1100
                 'id'   => 'email_pre_payment_subject',
1101
-                'name' => __( 'Subject', 'invoicing' ),
1102
-                'desc' => __( 'Enter the subject line for the email.', 'invoicing' ),
1101
+                'name' => __('Subject', 'invoicing'),
1102
+                'desc' => __('Enter the subject line for the email.', 'invoicing'),
1103 1103
                 'type' => 'text',
1104
-                'std'  => __( '[{site_title}] Renewal Reminder', 'invoicing' ),
1104
+                'std'  => __('[{site_title}] Renewal Reminder', 'invoicing'),
1105 1105
                 'size' => 'large'
1106 1106
             ),
1107 1107
             'email_pre_payment_heading' => array(
1108 1108
                 'id'   => 'email_pre_payment_heading',
1109
-                'name' => __( 'Email Heading', 'invoicing' ),
1110
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1109
+                'name' => __('Email Heading', 'invoicing'),
1110
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1111 1111
                 'type' => 'text',
1112
-                'std'  => __( 'Upcoming renewal reminder', 'invoicing' ),
1112
+                'std'  => __('Upcoming renewal reminder', 'invoicing'),
1113 1113
                 'size' => 'large'
1114 1114
             ),
1115 1115
             'email_pre_payment_admin_bcc' => array(
1116 1116
                 'id'   => 'email_pre_payment_admin_bcc',
1117
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1118
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1117
+                'name' => __('Enable Admin BCC', 'invoicing'),
1118
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1119 1119
                 'type' => 'checkbox',
1120 1120
                 'std'  => 1
1121 1121
             ),
1122 1122
             'email_pre_payment_body' => array(
1123 1123
                 'id'   => 'email_pre_payment_body',
1124
-                'name' => __( 'Email Content', 'invoicing' ),
1125
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1124
+                'name' => __('Email Content', 'invoicing'),
1125
+                'desc' => __('The content of the email.', 'invoicing'),
1126 1126
                 'type' => 'rich_editor',
1127
-                'std'  => __( '<p>Hi {full_name},</p><p>Your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date}.</p>', 'invoicing' ),
1127
+                'std'  => __('<p>Hi {full_name},</p><p>Your subscription for invoice <a href="{invoice_link}">#{invoice_number}</a> will renew on {subscription_renewal_date}.</p>', 'invoicing'),
1128 1128
                 'class' => 'large',
1129 1129
                 'size'  => 10,
1130 1130
             ),
@@ -1133,264 +1133,264 @@  discard block
 block discarded – undo
1133 1133
         'overdue' => array(
1134 1134
             'email_overdue_header' => array(
1135 1135
                 'id'   => 'email_overdue_header',
1136
-                'name' => '<h3>' . __( 'Payment Reminder', 'invoicing' ) . '</h3>',
1137
-                'desc' => __( 'Payment reminder emails are sent to user automatically.', 'invoicing' ),
1136
+                'name' => '<h3>' . __('Payment Reminder', 'invoicing') . '</h3>',
1137
+                'desc' => __('Payment reminder emails are sent to user automatically.', 'invoicing'),
1138 1138
                 'type' => 'header',
1139 1139
             ),
1140 1140
             'email_overdue_active' => array(
1141 1141
                 'id'   => 'email_overdue_active',
1142
-                'name' => __( 'Enable/Disable', 'invoicing' ),
1143
-                'desc' => __( 'Enable this email notification', 'invoicing' ),
1142
+                'name' => __('Enable/Disable', 'invoicing'),
1143
+                'desc' => __('Enable this email notification', 'invoicing'),
1144 1144
                 'type' => 'checkbox',
1145 1145
                 'std'  => 1
1146 1146
             ),
1147 1147
             'email_due_reminder_days' => array(
1148 1148
                 'id'        => 'email_due_reminder_days',
1149
-                'name'      => __( 'When to Send', 'invoicing' ),
1150
-                'desc'      => __( 'Check when you would like payment reminders sent out.', 'invoicing' ),
1149
+                'name'      => __('When to Send', 'invoicing'),
1150
+                'desc'      => __('Check when you would like payment reminders sent out.', 'invoicing'),
1151 1151
                 'default'   => '',
1152 1152
                 'type'      => 'multicheck',
1153 1153
                 'options'   => $overdue_days_options,
1154 1154
             ),
1155 1155
             'email_overdue_subject' => array(
1156 1156
                 'id'   => 'email_overdue_subject',
1157
-                'name' => __( 'Subject', 'invoicing' ),
1158
-                'desc' => __( 'Enter the subject line for the invoice receipt email.', 'invoicing' ),
1157
+                'name' => __('Subject', 'invoicing'),
1158
+                'desc' => __('Enter the subject line for the invoice receipt email.', 'invoicing'),
1159 1159
                 'type' => 'text',
1160
-                'std'  => __( '[{site_title}] Payment Reminder', 'invoicing' ),
1160
+                'std'  => __('[{site_title}] Payment Reminder', 'invoicing'),
1161 1161
                 'size' => 'large'
1162 1162
             ),
1163 1163
             'email_overdue_heading' => array(
1164 1164
                 'id'   => 'email_overdue_heading',
1165
-                'name' => __( 'Email Heading', 'invoicing' ),
1166
-                'desc' => __( 'Enter the main heading contained within the email notification.', 'invoicing' ),
1165
+                'name' => __('Email Heading', 'invoicing'),
1166
+                'desc' => __('Enter the main heading contained within the email notification.', 'invoicing'),
1167 1167
                 'type' => 'text',
1168
-                'std'  => __( 'Payment reminder for your invoice', 'invoicing' ),
1168
+                'std'  => __('Payment reminder for your invoice', 'invoicing'),
1169 1169
                 'size' => 'large'
1170 1170
             ),
1171 1171
             'email_overdue_admin_bcc' => array(
1172 1172
                 'id'   => 'email_overdue_admin_bcc',
1173
-                'name' => __( 'Enable Admin BCC', 'invoicing' ),
1174
-                'desc' => __( 'Check if you want to send this notification email to site Admin.', 'invoicing' ),
1173
+                'name' => __('Enable Admin BCC', 'invoicing'),
1174
+                'desc' => __('Check if you want to send this notification email to site Admin.', 'invoicing'),
1175 1175
                 'type' => 'checkbox',
1176 1176
                 'std'  => 1
1177 1177
             ),
1178 1178
             'email_overdue_body' => array(
1179 1179
                 'id'   => 'email_overdue_body',
1180
-                'name' => __( 'Email Content', 'invoicing' ),
1181
-                'desc' => __( 'The content of the email.', 'invoicing' ),
1180
+                'name' => __('Email Content', 'invoicing'),
1181
+                'desc' => __('The content of the email.', 'invoicing'),
1182 1182
                 'type' => 'rich_editor',
1183
-                'std'  => __( '<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing' ),
1183
+                'std'  => __('<p>Hi {full_name},</p><p>This is just a friendly reminder that your invoice <a href="{invoice_link}">#{invoice_number}</a> {is_was} due on {invoice_due_date}.</p><p>The total of this invoice is {invoice_total}</p><p>To view / pay now for this invoice please use the following link: <a class="btn btn-success" href="{invoice_link}">View / Pay</a></p>', 'invoicing'),
1184 1184
                 'class' => 'large',
1185 1185
                 'size'  => 10,
1186 1186
             ),
1187 1187
         ),
1188 1188
     );
1189 1189
 
1190
-    return apply_filters( 'wpinv_get_emails', $emails );
1190
+    return apply_filters('wpinv_get_emails', $emails);
1191 1191
 }
1192 1192
 
1193
-function wpinv_settings_emails( $settings = array() ) {
1193
+function wpinv_settings_emails($settings = array()) {
1194 1194
     $emails = wpinv_get_emails();
1195 1195
 
1196
-    if ( !empty( $emails ) ) {
1197
-        foreach ( $emails as $key => $email ) {
1196
+    if (!empty($emails)) {
1197
+        foreach ($emails as $key => $email) {
1198 1198
             $settings[$key] = $email;
1199 1199
         }
1200 1200
     }
1201 1201
 
1202
-    return apply_filters( 'wpinv_settings_get_emails', $settings );
1202
+    return apply_filters('wpinv_settings_get_emails', $settings);
1203 1203
 }
1204
-add_filter( 'wpinv_settings_emails', 'wpinv_settings_emails', 10, 1 );
1204
+add_filter('wpinv_settings_emails', 'wpinv_settings_emails', 10, 1);
1205 1205
 
1206
-function wpinv_settings_sections_emails( $settings ) {
1206
+function wpinv_settings_sections_emails($settings) {
1207 1207
     $emails = wpinv_get_emails();
1208 1208
 
1209 1209
     if (!empty($emails)) {
1210
-        foreach  ($emails as $key => $email) {
1211
-            $settings[$key] = !empty( $email['email_' . $key . '_header']['name'] ) ? strip_tags( $email['email_' . $key . '_header']['name'] ) : $key;
1210
+        foreach ($emails as $key => $email) {
1211
+            $settings[$key] = !empty($email['email_' . $key . '_header']['name']) ? strip_tags($email['email_' . $key . '_header']['name']) : $key;
1212 1212
         }
1213 1213
     }
1214 1214
 
1215 1215
     return $settings;    
1216 1216
 }
1217
-add_filter( 'wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1 );
1217
+add_filter('wpinv_settings_sections_emails', 'wpinv_settings_sections_emails', 10, 1);
1218 1218
 
1219
-function wpinv_email_is_enabled( $email_type ) {
1219
+function wpinv_email_is_enabled($email_type) {
1220 1220
     $emails = wpinv_get_emails();
1221
-    $enabled = isset( $emails[$email_type] ) && wpinv_get_option( 'email_'. $email_type . '_active', 0 ) ? true : false;
1221
+    $enabled = isset($emails[$email_type]) && wpinv_get_option('email_' . $email_type . '_active', 0) ? true : false;
1222 1222
 
1223
-    return apply_filters( 'wpinv_email_is_enabled', $enabled, $email_type );
1223
+    return apply_filters('wpinv_email_is_enabled', $enabled, $email_type);
1224 1224
 }
1225 1225
 
1226
-function wpinv_email_get_recipient( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1227
-    switch ( $email_type ) {
1226
+function wpinv_email_get_recipient($email_type = '', $invoice_id = 0, $invoice = array()) {
1227
+    switch ($email_type) {
1228 1228
         case 'new_invoice':
1229 1229
         case 'cancelled_invoice':
1230 1230
         case 'failed_invoice':
1231 1231
             $recipient  = wpinv_get_admin_email();
1232 1232
         break;
1233 1233
         default:
1234
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1235
-            $recipient  = !empty( $invoice ) ? $invoice->get_email() : '';
1234
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1235
+            $recipient  = !empty($invoice) ? $invoice->get_email() : '';
1236 1236
         break;
1237 1237
     }
1238 1238
 
1239
-    return apply_filters( 'wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice );
1239
+    return apply_filters('wpinv_email_recipient', $recipient, $email_type, $invoice_id, $invoice);
1240 1240
 }
1241 1241
 
1242 1242
 /**
1243 1243
  * Returns invoice CC recipients
1244 1244
  */
1245
-function wpinv_email_get_cc_recipients( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1246
-    switch ( $email_type ) {
1245
+function wpinv_email_get_cc_recipients($email_type = '', $invoice_id = 0, $invoice = array()) {
1246
+    switch ($email_type) {
1247 1247
         case 'new_invoice':
1248 1248
         case 'cancelled_invoice':
1249 1249
         case 'failed_invoice':
1250 1250
             return array();
1251 1251
         break;
1252 1252
         default:
1253
-            $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1254
-            $recipient  = empty( $invoice ) ? '' : get_post_meta( $invoice->ID, 'wpinv_email_cc', true );
1255
-            if ( empty( $recipient ) ) {
1253
+            $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1254
+            $recipient  = empty($invoice) ? '' : get_post_meta($invoice->ID, 'wpinv_email_cc', true);
1255
+            if (empty($recipient)) {
1256 1256
                 return array();
1257 1257
             }
1258
-            return  array_filter( array_map( 'trim', explode( ',', $recipient ) ) );
1258
+            return  array_filter(array_map('trim', explode(',', $recipient)));
1259 1259
         break;
1260 1260
     }
1261 1261
 
1262 1262
 }
1263 1263
 
1264
-function wpinv_email_get_subject( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1265
-    $subject    = wpinv_get_option( 'email_' . $email_type . '_subject' );
1266
-    $subject    = __( $subject, 'invoicing' );
1264
+function wpinv_email_get_subject($email_type = '', $invoice_id = 0, $invoice = array()) {
1265
+    $subject    = wpinv_get_option('email_' . $email_type . '_subject');
1266
+    $subject    = __($subject, 'invoicing');
1267 1267
 
1268
-    $subject    = wpinv_email_format_text( $subject, $invoice );
1268
+    $subject    = wpinv_email_format_text($subject, $invoice);
1269 1269
 
1270
-    return apply_filters( 'wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice );
1270
+    return apply_filters('wpinv_email_subject', $subject, $email_type, $invoice_id, $invoice);
1271 1271
 }
1272 1272
 
1273
-function wpinv_email_get_heading( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1274
-    $email_heading = wpinv_get_option( 'email_' . $email_type . '_heading' );
1275
-    $email_heading = __( $email_heading, 'invoicing' );
1273
+function wpinv_email_get_heading($email_type = '', $invoice_id = 0, $invoice = array()) {
1274
+    $email_heading = wpinv_get_option('email_' . $email_type . '_heading');
1275
+    $email_heading = __($email_heading, 'invoicing');
1276 1276
 
1277
-    $email_heading = wpinv_email_format_text( $email_heading, $invoice );
1277
+    $email_heading = wpinv_email_format_text($email_heading, $invoice);
1278 1278
 
1279
-    return apply_filters( 'wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice );
1279
+    return apply_filters('wpinv_email_heading', $email_heading, $email_type, $invoice_id, $invoice);
1280 1280
 }
1281 1281
 
1282
-function wpinv_email_get_content( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1283
-    $content    = wpinv_get_option( 'email_' . $email_type . '_body' );
1284
-    $content    = __( $content, 'invoicing' );
1282
+function wpinv_email_get_content($email_type = '', $invoice_id = 0, $invoice = array()) {
1283
+    $content    = wpinv_get_option('email_' . $email_type . '_body');
1284
+    $content    = __($content, 'invoicing');
1285 1285
 
1286
-    $content    = wpinv_email_format_text( $content, $invoice );
1286
+    $content    = wpinv_email_format_text($content, $invoice);
1287 1287
 
1288
-    return apply_filters( 'wpinv_email_content', $content, $email_type, $invoice_id, $invoice );
1288
+    return apply_filters('wpinv_email_content', $content, $email_type, $invoice_id, $invoice);
1289 1289
 }
1290 1290
 
1291
-function wpinv_email_get_headers( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1291
+function wpinv_email_get_headers($email_type = '', $invoice_id = 0, $invoice = array()) {
1292 1292
     $from_name = wpinv_mail_get_from_address();
1293 1293
     $from_email = wpinv_mail_get_from_address();
1294 1294
     
1295
-    $invoice    = !empty( $invoice ) && is_object( $invoice ) ? $invoice : ( $invoice_id > 0 ? wpinv_get_invoice( $invoice_id ) : NULL );
1295
+    $invoice    = !empty($invoice) && is_object($invoice) ? $invoice : ($invoice_id > 0 ? wpinv_get_invoice($invoice_id) : NULL);
1296 1296
     
1297
-    $headers    = "From: " . stripslashes_deep( html_entity_decode( $from_name, ENT_COMPAT, 'UTF-8' ) ) . " <$from_email>\r\n";
1298
-    $headers    .= "Reply-To: ". $from_email . "\r\n";
1297
+    $headers    = "From: " . stripslashes_deep(html_entity_decode($from_name, ENT_COMPAT, 'UTF-8')) . " <$from_email>\r\n";
1298
+    $headers    .= "Reply-To: " . $from_email . "\r\n";
1299 1299
     $headers    .= "Content-Type: " . wpinv_mail_get_content_type() . "\r\n";
1300 1300
     
1301
-    return apply_filters( 'wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice );
1301
+    return apply_filters('wpinv_email_headers', $headers, $email_type, $invoice_id, $invoice);
1302 1302
 }
1303 1303
 
1304
-function wpinv_email_get_attachments( $email_type = '', $invoice_id = 0, $invoice = array() ) {
1304
+function wpinv_email_get_attachments($email_type = '', $invoice_id = 0, $invoice = array()) {
1305 1305
     $attachments = array();
1306 1306
     
1307
-    return apply_filters( 'wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice );
1307
+    return apply_filters('wpinv_email_attachments', $attachments, $email_type, $invoice_id, $invoice);
1308 1308
 }
1309 1309
 
1310 1310
 /**
1311 1311
  * Searches for and replaces certain placeholders in an email.
1312 1312
  */
1313
-function wpinv_email_format_text( $content, $invoice ) {
1313
+function wpinv_email_format_text($content, $invoice) {
1314 1314
 
1315 1315
     $replace_array = array(
1316 1316
         '{site_title}'      => wpinv_get_blogname(),
1317
-        '{date}'            => date_i18n( get_option( 'date_format' ), (int) current_time( 'timestamp' ) ),
1317
+        '{date}'            => date_i18n(get_option('date_format'), (int) current_time('timestamp')),
1318 1318
     );
1319 1319
 
1320
-    $invoice = new WPInv_Invoice( $invoice );
1320
+    $invoice = new WPInv_Invoice($invoice);
1321 1321
 
1322
-    if ( $invoice->get_id() ) {
1322
+    if ($invoice->get_id()) {
1323 1323
 
1324 1324
         $replace_array = array_merge(
1325 1325
             $replace_array, 
1326 1326
             array(
1327
-                '{name}'            => sanitize_text_field( $invoice->get_user_full_name() ),
1328
-                '{full_name}'       => sanitize_text_field( $invoice->get_user_full_name() ),
1329
-                '{first_name}'      => sanitize_text_field( $invoice->get_first_name() ),
1330
-                '{last_name}'       => sanitize_text_field( $invoice->get_last_name() ),
1331
-                '{email}'           => sanitize_email( $invoice->get_email() ),
1332
-                '{invoice_number}'  => sanitize_text_field( $invoice->get_number() ),
1333
-                '{invoice_total}'   => wpinv_price( wpinv_format_amount( $invoice->get_total( true ) ) ),
1334
-                '{invoice_link}'    => esc_url( $invoice->get_view_url() ),
1335
-                '{invoice_pay_link}'=> esc_url( $invoice->get_checkout_payment_url() ),
1336
-                '{invoice_date}'    => date( get_option( 'date_format' ), strtotime( $invoice->get_date_created(), current_time( 'timestamp' ) ) ),
1337
-                '{invoice_due_date}'=> date( get_option( 'date_format' ), strtotime( $invoice->get_due_date(), current_time( 'timestamp' ) ) ),
1338
-                '{invoice_quote}'   => sanitize_text_field( $invoice->get_type() ),
1339
-                '{invoice_label}'   => sanitize_text_field( ucfirst( $invoice->get_type() ) ),
1340
-                '{is_was}'          => strtotime( $invoice->get_due_date() ) < current_time( 'timestamp' ) ? __( 'was', 'invoicing' ) : __( 'is', 'invoicing' ),
1327
+                '{name}'            => sanitize_text_field($invoice->get_user_full_name()),
1328
+                '{full_name}'       => sanitize_text_field($invoice->get_user_full_name()),
1329
+                '{first_name}'      => sanitize_text_field($invoice->get_first_name()),
1330
+                '{last_name}'       => sanitize_text_field($invoice->get_last_name()),
1331
+                '{email}'           => sanitize_email($invoice->get_email()),
1332
+                '{invoice_number}'  => sanitize_text_field($invoice->get_number()),
1333
+                '{invoice_total}'   => wpinv_price(wpinv_format_amount($invoice->get_total(true))),
1334
+                '{invoice_link}'    => esc_url($invoice->get_view_url()),
1335
+                '{invoice_pay_link}'=> esc_url($invoice->get_checkout_payment_url()),
1336
+                '{invoice_date}'    => date(get_option('date_format'), strtotime($invoice->get_date_created(), current_time('timestamp'))),
1337
+                '{invoice_due_date}'=> date(get_option('date_format'), strtotime($invoice->get_due_date(), current_time('timestamp'))),
1338
+                '{invoice_quote}'   => sanitize_text_field($invoice->get_type()),
1339
+                '{invoice_label}'   => sanitize_text_field(ucfirst($invoice->get_type())),
1340
+                '{is_was}'          => strtotime($invoice->get_due_date()) < current_time('timestamp') ? __('was', 'invoicing') : __('is', 'invoicing'),
1341 1341
             )
1342 1342
         );
1343 1343
 
1344 1344
     }
1345 1345
 
1346 1346
     // Let third party plugins filter the arra.
1347
-    $replace_array = apply_filters( 'wpinv_email_format_text', $replace_array, $content, $invoice );
1347
+    $replace_array = apply_filters('wpinv_email_format_text', $replace_array, $content, $invoice);
1348 1348
 
1349
-    foreach ( $replace_array as $key => $value ) {
1350
-        $content = str_replace( $key, $value, $content );
1349
+    foreach ($replace_array as $key => $value) {
1350
+        $content = str_replace($key, $value, $content);
1351 1351
     }
1352 1352
 
1353
-    return apply_filters( 'wpinv_email_content_replace', $content );
1353
+    return apply_filters('wpinv_email_content_replace', $content);
1354 1354
 }
1355 1355
 
1356
-function wpinv_email_style_body( $content ) {
1356
+function wpinv_email_style_body($content) {
1357 1357
     // make sure we only inline CSS for html emails
1358
-    if ( in_array( wpinv_mail_get_content_type(), array( 'text/html', 'multipart/alternative' ) ) && class_exists( 'DOMDocument' ) ) {
1358
+    if (in_array(wpinv_mail_get_content_type(), array('text/html', 'multipart/alternative')) && class_exists('DOMDocument')) {
1359 1359
         ob_start();
1360
-        wpinv_get_template( 'emails/wpinv-email-styles.php' );
1361
-        $css = apply_filters( 'wpinv_email_styles', ob_get_clean() );
1360
+        wpinv_get_template('emails/wpinv-email-styles.php');
1361
+        $css = apply_filters('wpinv_email_styles', ob_get_clean());
1362 1362
 
1363 1363
         // apply CSS styles inline for picky email clients
1364 1364
         try {
1365
-            $emogrifier = new Emogrifier( $content, $css );
1365
+            $emogrifier = new Emogrifier($content, $css);
1366 1366
             $content    = $emogrifier->emogrify();
1367
-        } catch ( Exception $e ) {
1368
-            wpinv_error_log( $e->getMessage(), 'emogrifier' );
1367
+        } catch (Exception $e) {
1368
+            wpinv_error_log($e->getMessage(), 'emogrifier');
1369 1369
         }
1370 1370
     }
1371 1371
     return $content;
1372 1372
 }
1373 1373
 
1374
-function wpinv_email_header( $email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1375
-    wpinv_get_template( 'emails/wpinv-email-header.php', array( 'email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1374
+function wpinv_email_header($email_heading = '', $invoice = array(), $email_type = '', $sent_to_admin = false) {
1375
+    wpinv_get_template('emails/wpinv-email-header.php', array('email_heading' => $email_heading, 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1376 1376
 }
1377 1377
 
1378 1378
 /**
1379 1379
  * Get the email footer.
1380 1380
  */
1381
-function wpinv_email_footer( $invoice = array(), $email_type = '', $sent_to_admin = false ) {
1382
-    wpinv_get_template( 'emails/wpinv-email-footer.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1381
+function wpinv_email_footer($invoice = array(), $email_type = '', $sent_to_admin = false) {
1382
+    wpinv_get_template('emails/wpinv-email-footer.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1383 1383
 }
1384 1384
 
1385
-function wpinv_email_wrap_message( $message ) {
1385
+function wpinv_email_wrap_message($message) {
1386 1386
     // Buffer
1387 1387
     ob_start();
1388 1388
 
1389
-    do_action( 'wpinv_email_header' );
1389
+    do_action('wpinv_email_header');
1390 1390
 
1391
-    echo wpautop( wptexturize( $message ) );
1391
+    echo wpautop(wptexturize($message));
1392 1392
 
1393
-    do_action( 'wpinv_email_footer' );
1393
+    do_action('wpinv_email_footer');
1394 1394
 
1395 1395
     // Get contents
1396 1396
     $message = ob_get_clean();
@@ -1398,8 +1398,8 @@  discard block
 block discarded – undo
1398 1398
     return $message;
1399 1399
 }
1400 1400
 
1401
-function wpinv_email_invoice_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1402
-    wpinv_get_template( 'emails/wpinv-email-invoice-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1401
+function wpinv_email_invoice_details($invoice, $email_type = '', $sent_to_admin = false) {
1402
+    wpinv_get_template('emails/wpinv-email-invoice-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1403 1403
 }
1404 1404
 
1405 1405
 /**
@@ -1409,102 +1409,102 @@  discard block
 block discarded – undo
1409 1409
  * @param string $email_type
1410 1410
  * @param bool $sent_to_admin
1411 1411
  */
1412
-function wpinv_email_invoice_items( $invoice, $email_type = '', $sent_to_admin = false ) {
1412
+function wpinv_email_invoice_items($invoice, $email_type = '', $sent_to_admin = false) {
1413 1413
 
1414 1414
     // Prepare the invoice.
1415
-    $invoice = new WPInv_Invoice( $invoice );
1415
+    $invoice = new WPInv_Invoice($invoice);
1416 1416
 
1417 1417
     // Abort if there is no invoice.
1418
-    if ( 0 == $invoice->get_id() ) {
1418
+    if (0 == $invoice->get_id()) {
1419 1419
         return;
1420 1420
     }
1421 1421
 
1422 1422
     // Prepare line items.
1423
-    $columns = getpaid_invoice_item_columns( $invoice );
1424
-    $columns = apply_filters( 'getpaid_invoice_line_items_table_columns', $columns, $invoice );
1423
+    $columns = getpaid_invoice_item_columns($invoice);
1424
+    $columns = apply_filters('getpaid_invoice_line_items_table_columns', $columns, $invoice);
1425 1425
 
1426 1426
     // Load the template.
1427
-    wpinv_get_template( 'emails/wpinv-email-invoice-items.php', compact( 'invoice', 'columns', 'email_type', 'sent_to_admin' ) );
1427
+    wpinv_get_template('emails/wpinv-email-invoice-items.php', compact('invoice', 'columns', 'email_type', 'sent_to_admin'));
1428 1428
 }
1429 1429
 
1430
-function wpinv_email_billing_details( $invoice, $email_type = '', $sent_to_admin = false ) {
1431
-    wpinv_get_template( 'emails/wpinv-email-billing-details.php', array( 'invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin ) );
1430
+function wpinv_email_billing_details($invoice, $email_type = '', $sent_to_admin = false) {
1431
+    wpinv_get_template('emails/wpinv-email-billing-details.php', array('invoice' => $invoice, 'email_type' => $email_type, 'sent_to_admin' => $sent_to_admin));
1432 1432
 }
1433 1433
 
1434
-function wpinv_send_customer_invoice( $data = array() ) {
1435
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1434
+function wpinv_send_customer_invoice($data = array()) {
1435
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1436 1436
 
1437
-    if ( empty( $invoice_id ) ) {
1437
+    if (empty($invoice_id)) {
1438 1438
         return;
1439 1439
     }
1440 1440
 
1441
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1442
-        wp_die( __( 'You do not have permission to send invoice notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1441
+    if (!wpinv_current_user_can_manage_invoicing()) {
1442
+        wp_die(__('You do not have permission to send invoice notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1443 1443
     }
1444 1444
     
1445
-    $sent = wpinv_user_invoice_notification( $invoice_id );
1445
+    $sent = wpinv_user_invoice_notification($invoice_id);
1446 1446
 
1447 1447
     if ( -1 === $sent ) {
1448 1448
         $status = 'email_disabled';
1449
-    } elseif ( $sent ) {
1449
+    } elseif ($sent) {
1450 1450
         $status = 'email_sent';
1451 1451
     } else {
1452 1452
         $status = 'email_fail';
1453 1453
     }
1454 1454
 
1455
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1456
-    wp_redirect( $redirect );
1455
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1456
+    wp_redirect($redirect);
1457 1457
     exit;
1458 1458
 }
1459
-add_action( 'wpinv_send_invoice', 'wpinv_send_customer_invoice' );
1459
+add_action('wpinv_send_invoice', 'wpinv_send_customer_invoice');
1460 1460
 
1461
-function wpinv_send_overdue_reminder( $data = array() ) {
1462
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1461
+function wpinv_send_overdue_reminder($data = array()) {
1462
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1463 1463
 
1464
-    if ( empty( $invoice_id ) ) {
1464
+    if (empty($invoice_id)) {
1465 1465
         return;
1466 1466
     }
1467 1467
 
1468
-    if ( !wpinv_current_user_can_manage_invoicing() ) {
1469
-        wp_die( __( 'You do not have permission to send reminder notification', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
1468
+    if (!wpinv_current_user_can_manage_invoicing()) {
1469
+        wp_die(__('You do not have permission to send reminder notification', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
1470 1470
     }
1471 1471
 
1472
-    $sent = wpinv_send_payment_reminder_notification( $invoice_id );
1472
+    $sent = wpinv_send_payment_reminder_notification($invoice_id);
1473 1473
     
1474 1474
     $status = $sent ? 'email_sent' : 'email_fail';
1475 1475
 
1476
-    $redirect = add_query_arg( array( 'wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false ) );
1477
-    wp_redirect( $redirect );
1476
+    $redirect = add_query_arg(array('wpinv-message' => $status, 'wpi_action' => false, 'invoice_id' => false));
1477
+    wp_redirect($redirect);
1478 1478
     exit;
1479 1479
 }
1480
-add_action( 'wpinv_send_reminder', 'wpinv_send_overdue_reminder' );
1480
+add_action('wpinv_send_reminder', 'wpinv_send_overdue_reminder');
1481 1481
 
1482
-function wpinv_send_customer_note_email( $data ) {
1483
-    $invoice_id = !empty( $data['invoice_id'] ) ? absint( $data['invoice_id'] ) : NULL;
1482
+function wpinv_send_customer_note_email($data) {
1483
+    $invoice_id = !empty($data['invoice_id']) ? absint($data['invoice_id']) : NULL;
1484 1484
 
1485
-    if ( empty( $invoice_id ) ) {
1485
+    if (empty($invoice_id)) {
1486 1486
         return;
1487 1487
     }
1488 1488
 
1489
-    $sent = wpinv_user_note_notification( $invoice_id, $data );
1489
+    $sent = wpinv_user_note_notification($invoice_id, $data);
1490 1490
 }
1491
-add_action( 'wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1 );
1491
+add_action('wpinv_new_customer_note', 'wpinv_send_customer_note_email', 10, 1);
1492 1492
 
1493
-function wpinv_add_notes_to_invoice_email( $invoice, $email_type, $sent_to_admin ) {
1494
-    if ( !empty( $invoice ) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes( $invoice->ID, true ) ) {
1495
-        $date_format = get_option( 'date_format' );
1496
-        $time_format = get_option( 'time_format' );
1493
+function wpinv_add_notes_to_invoice_email($invoice, $email_type, $sent_to_admin) {
1494
+    if (!empty($invoice) && $email_type == 'user_invoice' && $invoice_notes = wpinv_get_invoice_notes($invoice->ID, true)) {
1495
+        $date_format = get_option('date_format');
1496
+        $time_format = get_option('time_format');
1497 1497
         ?>
1498 1498
         <div id="wpinv-email-notes">
1499
-            <h3 class="wpinv-notes-t"><?php echo apply_filters( 'wpinv_email_invoice_notes_title', __( 'Invoice Notes', 'invoicing' ) ); ?></h3>
1499
+            <h3 class="wpinv-notes-t"><?php echo apply_filters('wpinv_email_invoice_notes_title', __('Invoice Notes', 'invoicing')); ?></h3>
1500 1500
             <ol class="wpinv-notes-lists">
1501 1501
         <?php
1502
-        foreach ( $invoice_notes as $note ) {
1503
-            $note_time = strtotime( $note->comment_date );
1502
+        foreach ($invoice_notes as $note) {
1503
+            $note_time = strtotime($note->comment_date);
1504 1504
             ?>
1505 1505
             <li class="comment wpinv-note">
1506
-            <p class="wpinv-note-date meta"><?php printf( __( '%2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( $date_format, $note_time ), date_i18n( $time_format, $note_time ), $note_time ); ?></p>
1507
-            <div class="wpinv-note-desc description"><?php echo wpautop( wptexturize( $note->comment_content ) ); ?></div>
1506
+            <p class="wpinv-note-date meta"><?php printf(__('%2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n($date_format, $note_time), date_i18n($time_format, $note_time), $note_time); ?></p>
1507
+            <div class="wpinv-note-desc description"><?php echo wpautop(wptexturize($note->comment_content)); ?></div>
1508 1508
             </li>
1509 1509
             <?php
1510 1510
         }
@@ -1513,7 +1513,7 @@  discard block
 block discarded – undo
1513 1513
         <?php
1514 1514
     }
1515 1515
 }
1516
-add_action( 'wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3 );
1516
+add_action('wpinv_email_billing_details', 'wpinv_add_notes_to_invoice_email', 10, 3);
1517 1517
 
1518 1518
 /**
1519 1519
  * Sends renewal reminders.
@@ -1521,35 +1521,35 @@  discard block
 block discarded – undo
1521 1521
 function wpinv_email_renewal_reminders() {
1522 1522
     global $wpdb;
1523 1523
 
1524
-    if ( ! wpinv_get_option( 'email_pre_payment_active' ) ) {
1524
+    if (!wpinv_get_option('email_pre_payment_active')) {
1525 1525
         return;
1526 1526
     }
1527 1527
 
1528
-    $reminder_days = wpinv_get_option( 'email_pre_payment_reminder_days' );
1528
+    $reminder_days = wpinv_get_option('email_pre_payment_reminder_days');
1529 1529
 
1530
-    if ( empty( $reminder_days ) ) {
1530
+    if (empty($reminder_days)) {
1531 1531
         return;
1532 1532
     }
1533 1533
 
1534 1534
     // How many days before renewal should we send this email?
1535
-    $reminder_days = array_unique( array_map( 'absint', array_filter( wpinv_parse_list( $reminder_days ) ) ) );
1536
-    if ( empty( $reminder_days ) ) {
1535
+    $reminder_days = array_unique(array_map('absint', array_filter(wpinv_parse_list($reminder_days))));
1536
+    if (empty($reminder_days)) {
1537 1537
         return;
1538 1538
     }
1539 1539
 
1540
-    if ( 1 == count( $reminder_days ) ) {
1540
+    if (1 == count($reminder_days)) {
1541 1541
         $days  = $reminder_days[0];
1542
-        $date  = date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) );
1543
-        $where = $wpdb->prepare( "DATE(expiration)=%s", $date );
1542
+        $date  = date('Y-m-d', strtotime("+$days days", current_time('timestamp')));
1543
+        $where = $wpdb->prepare("DATE(expiration)=%s", $date);
1544 1544
     } else {
1545 1545
         $in    = array();
1546 1546
 
1547
-        foreach ( $reminder_days as $days ) {
1548
-            $date  = date( 'Y-m-d', strtotime( "+$days days", current_time( 'timestamp' ) ) );
1549
-            $in[]  = $wpdb->prepare( "%s", $date );
1547
+        foreach ($reminder_days as $days) {
1548
+            $date  = date('Y-m-d', strtotime("+$days days", current_time('timestamp')));
1549
+            $in[]  = $wpdb->prepare("%s", $date);
1550 1550
         }
1551 1551
 
1552
-        $in    = implode( ',', $in );
1552
+        $in    = implode(',', $in);
1553 1553
         $where = "DATE(expiration) IN ($in)";
1554 1554
     }
1555 1555
 
@@ -1557,20 +1557,20 @@  discard block
 block discarded – undo
1557 1557
     $table = $wpdb->prefix . 'wpinv_subscriptions';
1558 1558
 
1559 1559
     // Fetch invoices.
1560
-	$subscriptions  = $wpdb->get_results(
1560
+	$subscriptions = $wpdb->get_results(
1561 1561
 		"SELECT parent_payment_id, product_id, expiration FROM $table
1562 1562
 		WHERE
1563 1563
             $where
1564 1564
             AND status IN ( 'trialling', 'active' )");
1565 1565
 
1566
-    foreach ( $subscriptions as $subscription ) {
1566
+    foreach ($subscriptions as $subscription) {
1567 1567
 
1568 1568
         // Skip packages.
1569
-        if ( get_post_meta( $subscription->product_id, '_wpinv_type', true ) == 'package' ) {
1569
+        if (get_post_meta($subscription->product_id, '_wpinv_type', true) == 'package') {
1570 1570
             continue;
1571 1571
         }
1572 1572
 
1573
-        wpinv_send_pre_payment_reminder_notification( $subscription->parent_payment_id, $subscription->expiration );
1573
+        wpinv_send_pre_payment_reminder_notification($subscription->parent_payment_id, $subscription->expiration);
1574 1574
     }
1575 1575
 
1576 1576
 }
@@ -1578,44 +1578,44 @@  discard block
 block discarded – undo
1578 1578
 function wpinv_email_payment_reminders() {
1579 1579
     global $wpi_auto_reminder, $wpdb;
1580 1580
 
1581
-    if ( ! wpinv_get_option( 'email_overdue_active' ) ) {
1581
+    if (!wpinv_get_option('email_overdue_active')) {
1582 1582
         return;
1583 1583
     }
1584 1584
 
1585
-    if ( $reminder_days = wpinv_get_option( 'email_due_reminder_days' ) ) {
1585
+    if ($reminder_days = wpinv_get_option('email_due_reminder_days')) {
1586 1586
 
1587 1587
         // Get a list of all reminder dates.
1588
-        $reminder_days  = is_array( $reminder_days ) ? array_values( $reminder_days ) : array();
1588
+        $reminder_days  = is_array($reminder_days) ? array_values($reminder_days) : array();
1589 1589
 
1590 1590
         // Ensure we have integers.
1591
-        $reminder_days  = array_unique( array_map( 'absint', $reminder_days ) );
1591
+        $reminder_days  = array_unique(array_map('absint', $reminder_days));
1592 1592
 
1593 1593
         // Abort if non is selected.
1594
-        if ( empty( $reminder_days ) ) {
1594
+        if (empty($reminder_days)) {
1595 1595
             return;
1596 1596
         }
1597 1597
 
1598 1598
         // Fetch the max reminder day.
1599
-        $max_date = max( $reminder_days );
1599
+        $max_date = max($reminder_days);
1600 1600
 
1601 1601
         // Todays date.
1602
-        $today = date( 'Y-m-d', current_time( 'timestamp' ) );
1602
+        $today = date('Y-m-d', current_time('timestamp'));
1603 1603
 
1604
-        if ( empty( $max_date ) ) {
1605
-            $where = $wpdb->prepare( "DATE(invoices.due_date)=%s", $today );
1606
-        } else if ( 1 == count( $reminder_days ) ) {
1604
+        if (empty($max_date)) {
1605
+            $where = $wpdb->prepare("DATE(invoices.due_date)=%s", $today);
1606
+        } else if (1 == count($reminder_days)) {
1607 1607
             $days  = $reminder_days[0];
1608
-            $date  = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) );
1609
-            $where = $wpdb->prepare( "DATE(invoices.due_date)=%s", $date );
1608
+            $date  = date('Y-m-d', strtotime("-$days days", current_time('timestamp')));
1609
+            $where = $wpdb->prepare("DATE(invoices.due_date)=%s", $date);
1610 1610
         } else {
1611 1611
             $in    = array();
1612 1612
 
1613
-            foreach ( $reminder_days as $days ) {
1614
-                $date  = date( 'Y-m-d', strtotime( "-$days days", current_time( 'timestamp' ) ) );
1615
-                $in[]  = $wpdb->prepare( "%s", $date );
1613
+            foreach ($reminder_days as $days) {
1614
+                $date  = date('Y-m-d', strtotime("-$days days", current_time('timestamp')));
1615
+                $in[]  = $wpdb->prepare("%s", $date);
1616 1616
             }
1617 1617
 
1618
-            $in    = implode( ',', $in );
1618
+            $in    = implode(',', $in);
1619 1619
             $where = "DATE(invoices.due_date) IN ($in)";
1620 1620
         }
1621 1621
 
@@ -1623,7 +1623,7 @@  discard block
 block discarded – undo
1623 1623
         $table = $wpdb->prefix . 'getpaid_invoices';
1624 1624
 
1625 1625
         // Fetch invoices.
1626
-		$invoices  = $wpdb->get_col(
1626
+		$invoices = $wpdb->get_col(
1627 1627
 			"SELECT posts.ID FROM $wpdb->posts as posts
1628 1628
 			LEFT JOIN $table as invoices ON invoices.post_id = posts.ID
1629 1629
 			WHERE
@@ -1631,174 +1631,174 @@  discard block
 block discarded – undo
1631 1631
 				AND posts.post_type = 'wpi_invoice'
1632 1632
                 AND posts.post_status = 'wpi-pending'");
1633 1633
 
1634
-        $wpi_auto_reminder  = true;
1634
+        $wpi_auto_reminder = true;
1635 1635
 
1636
-        foreach ( $invoices as $invoice ) {
1636
+        foreach ($invoices as $invoice) {
1637 1637
 
1638
-            if ( 'payment_form' != get_post_meta( $invoice, 'wpinv_created_via', true ) ) {
1639
-                do_action( 'wpinv_send_payment_reminder_notification', $invoice );
1638
+            if ('payment_form' != get_post_meta($invoice, 'wpinv_created_via', true)) {
1639
+                do_action('wpinv_send_payment_reminder_notification', $invoice);
1640 1640
             }
1641 1641
 
1642 1642
         }
1643 1643
 
1644
-        $wpi_auto_reminder  = false;
1644
+        $wpi_auto_reminder = false;
1645 1645
     }
1646 1646
 }
1647 1647
 
1648 1648
 /**
1649 1649
  * Sends an upcoming renewal notification.
1650 1650
  */
1651
-function wpinv_send_pre_payment_reminder_notification( $invoice_id, $renewal_date ) {
1651
+function wpinv_send_pre_payment_reminder_notification($invoice_id, $renewal_date) {
1652 1652
 
1653 1653
     $email_type = 'pre_payment';
1654
-    if ( ! wpinv_email_is_enabled( $email_type ) ) {
1654
+    if (!wpinv_email_is_enabled($email_type)) {
1655 1655
         return false;
1656 1656
     }
1657 1657
 
1658
-    $invoice    = wpinv_get_invoice( $invoice_id );
1659
-    if ( empty( $invoice ) ) {
1658
+    $invoice = wpinv_get_invoice($invoice_id);
1659
+    if (empty($invoice)) {
1660 1660
         return false;
1661 1661
     }
1662 1662
 
1663
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1664
-    if ( ! is_email( $recipient ) ) {
1663
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1664
+    if (!is_email($recipient)) {
1665 1665
         return false;
1666 1666
     }
1667 1667
 
1668
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1669
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1670
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1671
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1672
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1668
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1669
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1670
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1671
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1672
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1673 1673
 
1674
-    $renewal_date = date_i18n( 'Y-m-d', strtotime( $renewal_date ) );
1675
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1674
+    $renewal_date = date_i18n('Y-m-d', strtotime($renewal_date));
1675
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1676 1676
             'invoice'       => $invoice,
1677 1677
             'email_type'    => $email_type,
1678
-            'email_heading' => str_replace( '{subscription_renewal_date}', $renewal_date, $email_heading ),
1678
+            'email_heading' => str_replace('{subscription_renewal_date}', $renewal_date, $email_heading),
1679 1679
             'sent_to_admin' => false,
1680 1680
             'plain_text'    => false,
1681
-            'message_body'  => str_replace( '{subscription_renewal_date}', $renewal_date, $message_body )
1682
-        ) );
1681
+            'message_body'  => str_replace('{subscription_renewal_date}', $renewal_date, $message_body)
1682
+        ));
1683 1683
 
1684
-    $content        = wpinv_email_format_text( $content, $invoice );
1684
+    $content = wpinv_email_format_text($content, $invoice);
1685 1685
 
1686
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1686
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1687 1687
 
1688
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
1689
-        $recipient  = wpinv_get_admin_email();
1690
-        $subject    .= ' - ADMIN BCC COPY';
1691
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1688
+    if (wpinv_mail_admin_bcc_active($email_type)) {
1689
+        $recipient = wpinv_get_admin_email();
1690
+        $subject .= ' - ADMIN BCC COPY';
1691
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1692 1692
     }
1693 1693
 
1694 1694
     return $sent;
1695 1695
 
1696 1696
 }
1697 1697
 
1698
-function wpinv_send_payment_reminder_notification( $invoice_id ) {
1698
+function wpinv_send_payment_reminder_notification($invoice_id) {
1699 1699
     $email_type = 'overdue';
1700
-    if ( !wpinv_email_is_enabled( $email_type ) ) {
1700
+    if (!wpinv_email_is_enabled($email_type)) {
1701 1701
         return false;
1702 1702
     }
1703 1703
 
1704
-    $invoice    = wpinv_get_invoice( $invoice_id );
1705
-    if ( empty( $invoice ) ) {
1704
+    $invoice = wpinv_get_invoice($invoice_id);
1705
+    if (empty($invoice)) {
1706 1706
         return false;
1707 1707
     }
1708 1708
 
1709
-    if ( !$invoice->needs_payment() ) {
1709
+    if (!$invoice->needs_payment()) {
1710 1710
         return false;
1711 1711
     }
1712 1712
 
1713
-    $recipient  = wpinv_email_get_recipient( $email_type, $invoice_id, $invoice );
1714
-    if ( !is_email( $recipient ) ) {
1713
+    $recipient = wpinv_email_get_recipient($email_type, $invoice_id, $invoice);
1714
+    if (!is_email($recipient)) {
1715 1715
         return false;
1716 1716
     }
1717 1717
 
1718
-    do_action( 'wpinv_pre_send_invoice_notification', $invoice, $email_type );
1718
+    do_action('wpinv_pre_send_invoice_notification', $invoice, $email_type);
1719 1719
 
1720
-    $subject        = wpinv_email_get_subject( $email_type, $invoice_id, $invoice );
1721
-    $email_heading  = wpinv_email_get_heading( $email_type, $invoice_id, $invoice );
1722
-    $headers        = wpinv_email_get_headers( $email_type, $invoice_id, $invoice );
1723
-    $message_body   = wpinv_email_get_content( $email_type, $invoice_id, $invoice );
1724
-    $attachments    = wpinv_email_get_attachments( $email_type, $invoice_id, $invoice );
1720
+    $subject        = wpinv_email_get_subject($email_type, $invoice_id, $invoice);
1721
+    $email_heading  = wpinv_email_get_heading($email_type, $invoice_id, $invoice);
1722
+    $headers        = wpinv_email_get_headers($email_type, $invoice_id, $invoice);
1723
+    $message_body   = wpinv_email_get_content($email_type, $invoice_id, $invoice);
1724
+    $attachments    = wpinv_email_get_attachments($email_type, $invoice_id, $invoice);
1725 1725
 
1726
-    $content        = wpinv_get_template_html( 'emails/wpinv-email-' . $email_type . '.php', array(
1726
+    $content        = wpinv_get_template_html('emails/wpinv-email-' . $email_type . '.php', array(
1727 1727
             'invoice'       => $invoice,
1728 1728
             'email_type'    => $email_type,
1729 1729
             'email_heading' => $email_heading,
1730 1730
             'sent_to_admin' => false,
1731 1731
             'plain_text'    => false,
1732 1732
             'message_body'  => $message_body
1733
-        ) );
1733
+        ));
1734 1734
 
1735
-    $content        = wpinv_email_format_text( $content, $invoice );
1735
+    $content = wpinv_email_format_text($content, $invoice);
1736 1736
 
1737
-    $sent = wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1738
-    if ( $sent ) {
1739
-        do_action( 'wpinv_payment_reminder_sent', $invoice_id, $invoice );
1737
+    $sent = wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1738
+    if ($sent) {
1739
+        do_action('wpinv_payment_reminder_sent', $invoice_id, $invoice);
1740 1740
     }
1741 1741
 
1742
-    if ( wpinv_mail_admin_bcc_active( $email_type ) ) {
1743
-        $recipient  = wpinv_get_admin_email();
1744
-        $subject    .= ' - ADMIN BCC COPY';
1745
-        wpinv_mail_send( $recipient, $subject, $content, $headers, $attachments );
1742
+    if (wpinv_mail_admin_bcc_active($email_type)) {
1743
+        $recipient = wpinv_get_admin_email();
1744
+        $subject .= ' - ADMIN BCC COPY';
1745
+        wpinv_mail_send($recipient, $subject, $content, $headers, $attachments);
1746 1746
     }
1747 1747
 
1748
-    do_action( 'wpinv_post_send_invoice_notification', $invoice, $email_type );
1748
+    do_action('wpinv_post_send_invoice_notification', $invoice, $email_type);
1749 1749
 
1750 1750
     return $sent;
1751 1751
 }
1752
-add_action( 'wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1 );
1752
+add_action('wpinv_send_payment_reminder_notification', 'wpinv_send_payment_reminder_notification', 10, 1);
1753 1753
 
1754
-function wpinv_payment_reminder_sent( $invoice_id, $invoice ) {
1754
+function wpinv_payment_reminder_sent($invoice_id, $invoice) {
1755 1755
     global $wpi_auto_reminder;
1756 1756
 
1757
-    $sent = get_post_meta( $invoice_id, '_wpinv_reminder_sent', true );
1757
+    $sent = get_post_meta($invoice_id, '_wpinv_reminder_sent', true);
1758 1758
 
1759
-    if ( empty( $sent ) ) {
1759
+    if (empty($sent)) {
1760 1760
         $sent = array();
1761 1761
     }
1762
-    $sent[] = date_i18n( 'Y-m-d' );
1762
+    $sent[] = date_i18n('Y-m-d');
1763 1763
 
1764
-    update_post_meta( $invoice_id, '_wpinv_reminder_sent', $sent );
1764
+    update_post_meta($invoice_id, '_wpinv_reminder_sent', $sent);
1765 1765
 
1766
-    if ( $wpi_auto_reminder ) { // Auto reminder note.
1767
-        $note = __( 'Automated reminder sent to the user.', 'invoicing' );
1768
-        $invoice->add_note( $note, false, false, true );
1766
+    if ($wpi_auto_reminder) { // Auto reminder note.
1767
+        $note = __('Automated reminder sent to the user.', 'invoicing');
1768
+        $invoice->add_note($note, false, false, true);
1769 1769
     } else { // Menual reminder note.
1770
-        $note = __( 'Manual reminder sent to the user.', 'invoicing' );
1771
-        $invoice->add_note( $note );
1770
+        $note = __('Manual reminder sent to the user.', 'invoicing');
1771
+        $invoice->add_note($note);
1772 1772
     }
1773 1773
 }
1774
-add_action( 'wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2 );
1774
+add_action('wpinv_payment_reminder_sent', 'wpinv_payment_reminder_sent', 10, 2);
1775 1775
 
1776
-function wpinv_invoice_notification_set_locale( $invoice, $email_type, $site = false ) {
1777
-    if ( empty( $invoice ) ) {
1776
+function wpinv_invoice_notification_set_locale($invoice, $email_type, $site = false) {
1777
+    if (empty($invoice)) {
1778 1778
         return;
1779 1779
     }
1780 1780
 
1781
-    if ( is_int( $invoice ) ) {
1782
-        $invoice = wpinv_get_invoice( $invoice );
1781
+    if (is_int($invoice)) {
1782
+        $invoice = wpinv_get_invoice($invoice);
1783 1783
     }
1784 1784
 
1785
-    if ( ! empty( $invoice ) && is_object( $invoice ) ) {
1786
-        if ( ! $site && function_exists( 'get_user_locale' ) ) {
1787
-            $locale = get_user_locale( $invoice->get_user_id() );
1785
+    if (!empty($invoice) && is_object($invoice)) {
1786
+        if (!$site && function_exists('get_user_locale')) {
1787
+            $locale = get_user_locale($invoice->get_user_id());
1788 1788
         } else {
1789 1789
             $locale = get_locale();
1790 1790
         }
1791 1791
 
1792
-        wpinv_switch_to_locale( $locale );
1792
+        wpinv_switch_to_locale($locale);
1793 1793
     }
1794 1794
 }
1795
-add_action( 'wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3 );
1795
+add_action('wpinv_pre_send_invoice_notification', 'wpinv_invoice_notification_set_locale', 10, 3);
1796 1796
 
1797
-function wpinv_invoice_notification_restore_locale( $invoice, $email_type, $site = false ) {
1798
-    if ( empty( $invoice ) ) {
1797
+function wpinv_invoice_notification_restore_locale($invoice, $email_type, $site = false) {
1798
+    if (empty($invoice)) {
1799 1799
         return;
1800 1800
     }
1801 1801
 
1802 1802
     wpinv_restore_locale();
1803 1803
 }
1804
-add_action( 'wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3 );
1804
+add_action('wpinv_post_send_invoice_notification', 'wpinv_invoice_notification_restore_locale', 10, 3);
Please login to merge, or discard this patch.