Completed
Push — master ( 71be48...b0d50b )
by Stiofan
12s
created
includes/wpinv-general-functions.php 1 patch
Spacing   +148 added lines, -148 removed lines patch added patch discarded remove patch
@@ -7,195 +7,195 @@  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_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool)apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65
-function wpinv_send_to_success_page( $args = null ) {
65
+function wpinv_send_to_success_page($args = null) {
66 66
 	$redirect = wpinv_get_success_page_uri();
67 67
     
68
-    if ( !empty( $args ) ) {
68
+    if (!empty($args)) {
69 69
         // Check for backward compatibility
70
-        if ( is_string( $args ) )
71
-            $args = str_replace( '?', '', $args );
70
+        if (is_string($args))
71
+            $args = str_replace('?', '', $args);
72 72
 
73
-        $args = wp_parse_args( $args );
73
+        $args = wp_parse_args($args);
74 74
 
75
-        $redirect = add_query_arg( $args, $redirect );
75
+        $redirect = add_query_arg($args, $redirect);
76 76
     }
77 77
 
78
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
78
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
79 79
     
80
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
81
-    wp_redirect( $redirect );
80
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
81
+    wp_redirect($redirect);
82 82
     exit;
83 83
 }
84 84
 
85
-function wpinv_send_to_failed_page( $args = null ) {
85
+function wpinv_send_to_failed_page($args = null) {
86 86
 	$redirect = wpinv_get_failed_transaction_uri();
87 87
     
88
-    if ( !empty( $args ) ) {
88
+    if (!empty($args)) {
89 89
         // Check for backward compatibility
90
-        if ( is_string( $args ) )
91
-            $args = str_replace( '?', '', $args );
90
+        if (is_string($args))
91
+            $args = str_replace('?', '', $args);
92 92
 
93
-        $args = wp_parse_args( $args );
93
+        $args = wp_parse_args($args);
94 94
 
95
-        $redirect = add_query_arg( $args, $redirect );
95
+        $redirect = add_query_arg($args, $redirect);
96 96
     }
97 97
 
98
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
98
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
99 99
     
100
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
101
-    wp_redirect( $redirect );
100
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
101
+    wp_redirect($redirect);
102 102
     exit;
103 103
 }
104 104
 
105
-function wpinv_get_checkout_uri( $args = array() ) {
106
-	$uri = wpinv_get_option( 'checkout_page', false );
107
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
105
+function wpinv_get_checkout_uri($args = array()) {
106
+	$uri = wpinv_get_option('checkout_page', false);
107
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
108 108
 
109
-	if ( !empty( $args ) ) {
109
+	if (!empty($args)) {
110 110
 		// Check for backward compatibility
111
-		if ( is_string( $args ) )
112
-			$args = str_replace( '?', '', $args );
111
+		if (is_string($args))
112
+			$args = str_replace('?', '', $args);
113 113
 
114
-		$args = wp_parse_args( $args );
114
+		$args = wp_parse_args($args);
115 115
 
116
-		$uri = add_query_arg( $args, $uri );
116
+		$uri = add_query_arg($args, $uri);
117 117
 	}
118 118
 
119
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
119
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
120 120
 
121
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
121
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
122 122
 
123
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
124
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
123
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
124
+		$uri = preg_replace('/^http:/', 'https:', $uri);
125 125
 	}
126 126
 
127
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
127
+	return apply_filters('wpinv_get_checkout_uri', $uri);
128 128
 }
129 129
 
130
-function wpinv_send_back_to_checkout( $args = array() ) {
130
+function wpinv_send_back_to_checkout($args = array()) {
131 131
 	$redirect = wpinv_get_checkout_uri();
132 132
 
133
-	if ( ! empty( $args ) ) {
133
+	if (!empty($args)) {
134 134
 		// Check for backward compatibility
135
-		if ( is_string( $args ) )
136
-			$args = str_replace( '?', '', $args );
135
+		if (is_string($args))
136
+			$args = str_replace('?', '', $args);
137 137
 
138
-		$args = wp_parse_args( $args );
138
+		$args = wp_parse_args($args);
139 139
 
140
-		$redirect = add_query_arg( $args, $redirect );
140
+		$redirect = add_query_arg($args, $redirect);
141 141
 	}
142 142
 
143
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
143
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
144 144
 	exit;
145 145
 }
146 146
 
147
-function wpinv_get_success_page_url( $query_string = null ) {
148
-	$success_page = wpinv_get_option( 'success_page', 0 );
149
-	$success_page = get_permalink( $success_page );
147
+function wpinv_get_success_page_url($query_string = null) {
148
+	$success_page = wpinv_get_option('success_page', 0);
149
+	$success_page = get_permalink($success_page);
150 150
 
151
-	if ( $query_string )
151
+	if ($query_string)
152 152
 		$success_page .= $query_string;
153 153
 
154
-	return apply_filters( 'wpinv_success_page_url', $success_page );
154
+	return apply_filters('wpinv_success_page_url', $success_page);
155 155
 }
156 156
 
157
-function wpinv_get_failed_transaction_uri( $extras = false ) {
158
-	$uri = wpinv_get_option( 'failure_page', '' );
159
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
157
+function wpinv_get_failed_transaction_uri($extras = false) {
158
+	$uri = wpinv_get_option('failure_page', '');
159
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
160 160
 
161
-	if ( $extras )
161
+	if ($extras)
162 162
 		$uri .= $extras;
163 163
 
164
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
164
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
165 165
 }
166 166
 
167 167
 function wpinv_is_failed_transaction_page() {
168
-	$ret = wpinv_get_option( 'failure_page', false );
169
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
168
+	$ret = wpinv_get_option('failure_page', false);
169
+	$ret = isset($ret) ? is_page($ret) : false;
170 170
 
171
-	return apply_filters( 'wpinv_is_failure_page', $ret );
171
+	return apply_filters('wpinv_is_failure_page', $ret);
172 172
 }
173 173
 
174
-function wpinv_transaction_query( $type = 'start' ) {
174
+function wpinv_transaction_query($type = 'start') {
175 175
     global $wpdb;
176 176
 
177 177
     $wpdb->hide_errors();
178 178
 
179
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
180
-        define( 'WPINV_USE_TRANSACTIONS', true );
179
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
180
+        define('WPINV_USE_TRANSACTIONS', true);
181 181
     }
182 182
 
183
-    if ( WPINV_USE_TRANSACTIONS ) {
184
-        switch ( $type ) {
183
+    if (WPINV_USE_TRANSACTIONS) {
184
+        switch ($type) {
185 185
             case 'commit' :
186
-                $wpdb->query( 'COMMIT' );
186
+                $wpdb->query('COMMIT');
187 187
                 break;
188 188
             case 'rollback' :
189
-                $wpdb->query( 'ROLLBACK' );
189
+                $wpdb->query('ROLLBACK');
190 190
                 break;
191 191
             default :
192
-                $wpdb->query( 'START TRANSACTION' );
192
+                $wpdb->query('START TRANSACTION');
193 193
             break;
194 194
         }
195 195
     }
196 196
 }
197 197
 
198
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
198
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
199 199
     $default_args = array(
200 200
         'status'        => '',
201 201
         'user_id'       => null,
@@ -205,63 +205,63 @@  discard block
 block discarded – undo
205 205
         'parent'        => 0
206 206
     );
207 207
 
208
-    $args           = wp_parse_args( $args, $default_args );
208
+    $args           = wp_parse_args($args, $default_args);
209 209
     $invoice_data   = array();
210 210
 
211
-    if ( $args['invoice_id'] > 0 ) {
212
-        $updating           = true;
211
+    if ($args['invoice_id'] > 0) {
212
+        $updating = true;
213 213
         $invoice_data['post_type']  = 'wpi_invoice';
214 214
         $invoice_data['ID']         = $args['invoice_id'];
215 215
     } else {
216 216
         $updating                       = false;
217 217
         $invoice_data['post_type']      = 'wpi_invoice';
218
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'pending' );
218
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'pending');
219 219
         $invoice_data['ping_status']    = 'closed';
220
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
221
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
222
-        $invoice_data['post_parent']    = absint( $args['parent'] );
223
-        if ( !empty( $args['created_date'] ) ) {
220
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
221
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
222
+        $invoice_data['post_parent']    = absint($args['parent']);
223
+        if (!empty($args['created_date'])) {
224 224
             $invoice_data['post_date']      = $args['created_date'];
225
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
225
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
226 226
         }
227 227
     }
228 228
 
229
-    if ( $args['status'] ) {
230
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) ) {
231
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
229
+    if ($args['status']) {
230
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses()))) {
231
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
232 232
         }
233
-        $invoice_data['post_status']    = $args['status'];
233
+        $invoice_data['post_status'] = $args['status'];
234 234
     }
235 235
 
236
-    if ( ! is_null( $args['user_note'] ) ) {
237
-        $invoice_data['post_excerpt']   = $args['user_note'];
236
+    if (!is_null($args['user_note'])) {
237
+        $invoice_data['post_excerpt'] = $args['user_note'];
238 238
     }
239 239
 
240
-    if ( $updating ) {
241
-        $invoice_id = wp_update_post( $invoice_data, true );
240
+    if ($updating) {
241
+        $invoice_id = wp_update_post($invoice_data, true);
242 242
     } else {
243
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
243
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
244 244
     }
245 245
 
246
-    if ( is_wp_error( $invoice_id ) ) {
246
+    if (is_wp_error($invoice_id)) {
247 247
         return $wp_error ? $invoice_id : 0;
248 248
     }
249 249
     
250
-    $invoice = wpinv_get_invoice( $invoice_id );
251
-
252
-    if ( !$updating ) {
253
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
254
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
255
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
256
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
257
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
258
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
250
+    $invoice = wpinv_get_invoice($invoice_id);
251
+
252
+    if (!$updating) {
253
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
254
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
255
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
256
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
257
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
258
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
259 259
         
260 260
         // Add invoice note
261
-        $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
261
+        $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
262 262
     }
263 263
 
264
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
264
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
265 265
 
266 266
     return $invoice;
267 267
 }
@@ -269,118 +269,118 @@  discard block
 block discarded – undo
269 269
 function wpinv_get_prefix() {
270 270
     $invoice_prefix = 'INV-';
271 271
     
272
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
272
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
273 273
 }
274 274
 
275 275
 function wpinv_get_business_logo() {
276
-    $business_logo = wpinv_get_option( 'logo' );
277
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
276
+    $business_logo = wpinv_get_option('logo');
277
+    return apply_filters('wpinv_get_business_logo', $business_logo);
278 278
 }
279 279
 
280 280
 function wpinv_get_business_name() {
281 281
     $business_name = wpinv_get_option('store_name');
282
-    return apply_filters( 'wpinv_get_business_name', $business_name );
282
+    return apply_filters('wpinv_get_business_name', $business_name);
283 283
 }
284 284
 
285 285
 function wpinv_get_blogname() {
286
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
286
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
287 287
 }
288 288
 
289 289
 function wpinv_get_admin_email() {
290
-    $admin_email = get_option( 'admin_email' );
291
-    return apply_filters( 'wpinv_admin_email', $admin_email );
290
+    $admin_email = get_option('admin_email');
291
+    return apply_filters('wpinv_admin_email', $admin_email);
292 292
 }
293 293
 
294 294
 function wpinv_get_business_website() {
295
-    $business_website = home_url( '/' );
296
-    return apply_filters( 'wpinv_get_business_website', $business_website );
295
+    $business_website = home_url('/');
296
+    return apply_filters('wpinv_get_business_website', $business_website);
297 297
 }
298 298
 
299
-function wpinv_get_terms_text( $invoice_id = 0 ) {
299
+function wpinv_get_terms_text($invoice_id = 0) {
300 300
     $terms_text = '';
301
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
301
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
302 302
 }
303 303
 
304 304
 function wpinv_get_business_footer() {
305
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
306
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
307
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
305
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
306
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
307
+    return apply_filters('wpinv_get_business_footer', $business_footer);
308 308
 }
309 309
 
310 310
 function wpinv_checkout_required_fields() {
311 311
     $required_fields = array();
312 312
     
313 313
     // Let payment gateways and other extensions determine if address fields should be required
314
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
314
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
315 315
     
316
-    if ( $require_billing_details ) {
316
+    if ($require_billing_details) {
317 317
         ///$required_fields['email'] = array(
318 318
                 ///'error_id' => 'invalid_email',
319 319
                 ///'error_message' => __( 'Please enter a valid email address', 'invoicing' )
320 320
             ///);
321 321
         $required_fields['first_name'] = array(
322 322
                 'error_id' => 'invalid_first_name',
323
-                'error_message' => __( 'Please enter your first name', 'invoicing' )
323
+                'error_message' => __('Please enter your first name', 'invoicing')
324 324
             );
325 325
         $required_fields['address'] = array(
326 326
                 'error_id' => 'invalid_address',
327
-                'error_message' => __( 'Please enter your address', 'invoicing' )
327
+                'error_message' => __('Please enter your address', 'invoicing')
328 328
             );
329 329
         $required_fields['city'] = array(
330 330
                 'error_id' => 'invalid_city',
331
-                'error_message' => __( 'Please enter your billing city', 'invoicing' )
331
+                'error_message' => __('Please enter your billing city', 'invoicing')
332 332
             );
333 333
         $required_fields['state'] = array(
334 334
                 'error_id' => 'invalid_state',
335
-                'error_message' => __( 'Please enter billing state / province', 'invoicing' )
335
+                'error_message' => __('Please enter billing state / province', 'invoicing')
336 336
             );
337 337
         $required_fields['country'] = array(
338 338
                 'error_id' => 'invalid_country',
339
-                'error_message' => __( 'Please select your billing country', 'invoicing' )
339
+                'error_message' => __('Please select your billing country', 'invoicing')
340 340
             );
341 341
     }
342 342
 
343
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
343
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
344 344
 }
345 345
 
346 346
 function wpinv_is_ssl_enforced() {
347
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
348
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
347
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
348
+    return (bool)apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
349 349
 }
350 350
 
351
-function wpinv_user_can_print_invoice( $post ) {
351
+function wpinv_user_can_print_invoice($post) {
352 352
     $allow = false;
353 353
     
354
-    if ( !( $user_id = get_current_user_id() ) ) {
354
+    if (!($user_id = get_current_user_id())) {
355 355
         return $allow;
356 356
     }
357 357
     
358
-    if ( is_int( $post ) ) {
359
-        $post = get_post( $post );
358
+    if (is_int($post)) {
359
+        $post = get_post($post);
360 360
     }
361 361
     
362 362
     // Allow to owner.
363
-    if ( is_object( $post ) && !empty( $post->post_author ) && $post->post_author == $user_id ) {
363
+    if (is_object($post) && !empty($post->post_author) && $post->post_author == $user_id) {
364 364
         $allow = true;
365 365
     }
366 366
     
367 367
     // Allow to admin user.
368
-    if ( current_user_can( 'manage_options' ) ) {
368
+    if (current_user_can('manage_options')) {
369 369
         $allow = true;
370 370
     }
371 371
     
372
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post );
372
+    return apply_filters('wpinv_can_print_invoice', $allow, $post);
373 373
 }
374 374
 
375 375
 function wpinv_schedule_events() {
376 376
     // hourly, daily and twicedaily
377
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
378
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
377
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
378
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
379 379
     }
380 380
 }
381
-add_action( 'wp', 'wpinv_schedule_events' );
381
+add_action('wp', 'wpinv_schedule_events');
382 382
 
383 383
 function wpinv_schedule_event_twicedaily() {
384 384
     wpinv_email_payment_reminders();
385 385
 }
386
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
387 386
\ No newline at end of file
387
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
388 388
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +605 added lines, -605 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  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_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
25
-    if ( empty( $invoice_data ) ) {
24
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
25
+    if (empty($invoice_data)) {
26 26
         return false;
27 27
     }
28 28
     
29
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
30
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0;
29
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
30
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0;
31 31
     }
32 32
     
33
-    if ( empty( $invoice_data['user_id'] ) ) {
33
+    if (empty($invoice_data['user_id'])) {
34 34
         $invoice_data['user_id'] = get_current_user_id();
35 35
     }
36 36
     
37
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
37
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0;
38 38
     
39
-    if ( empty( $invoice_data['status'] ) ) {
39
+    if (empty($invoice_data['status'])) {
40 40
         $invoice_data['status'] = 'pending';
41 41
     }
42 42
     
43
-    if ( empty( $invoice_data['ip'] ) ) {
43
+    if (empty($invoice_data['ip'])) {
44 44
         $invoice_data['ip'] = wpinv_get_ip();
45 45
     }
46 46
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
         'status'        => $invoice_data['status'],
52 52
     );
53 53
 
54
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
55
-    if ( is_wp_error( $invoice ) ) {
54
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
55
+    if (is_wp_error($invoice)) {
56 56
         return $wp_error ? $invoice : 0;
57 57
     }
58 58
     
59
-    if ( empty( $invoice_data['invoice_id'] ) ) {
59
+    if (empty($invoice_data['invoice_id'])) {
60 60
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
61 61
     }
62 62
     
@@ -79,24 +79,24 @@  discard block
 block discarded – undo
79 79
         'discount'              => array(),
80 80
     );
81 81
 
82
-    if ( $user_id = (int)$invoice->get_user_id() ) {
83
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
84
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
82
+    if ($user_id = (int)$invoice->get_user_id()) {
83
+        if ($user_address = wpinv_get_user_address($user_id)) {
84
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
85 85
         }
86 86
     }
87 87
     
88
-    if ( empty( $invoice_data['user_info'] ) ) {
88
+    if (empty($invoice_data['user_info'])) {
89 89
         $invoice_data['user_info'] = array();
90 90
     }
91 91
     
92
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
92
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
93 93
     
94
-    if ( empty( $user_info['first_name'] ) ) {
94
+    if (empty($user_info['first_name'])) {
95 95
         $user_info['first_name'] = $default_user_info['first_name'];
96 96
         $user_info['last_name'] = $default_user_info['last_name'];
97 97
     }
98 98
     
99
-    if ( empty( $user_info['country'] ) ) {
99
+    if (empty($user_info['country'])) {
100 100
         $user_info['country'] = $default_user_info['country'];
101 101
         $user_info['state'] = $default_user_info['state'];
102 102
         $user_info['city'] = $default_user_info['city'];
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
         $user_info['phone'] = $default_user_info['phone'];
106 106
     }
107 107
     
108
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
108
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
109 109
         $user_info['discount'] = (array)$user_info['discount'];
110 110
     }
111 111
 
112 112
     // Payment details
113 113
     $payment_details = array();
114
-    if ( !empty( $invoice_data['payment_details'] ) ) {
114
+    if (!empty($invoice_data['payment_details'])) {
115 115
         $default_payment_details = array(
116 116
             'gateway'           => 'manual',
117 117
             'gateway_title'     => '',
@@ -119,59 +119,59 @@  discard block
 block discarded – undo
119 119
             'transaction_id'    => '',
120 120
         );
121 121
         
122
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
122
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
123 123
         
124
-        if ( empty( $payment_details['gateway'] ) ) {
124
+        if (empty($payment_details['gateway'])) {
125 125
             $payment_details['gateway'] = 'manual';
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['currency'] ) ) {
128
+        if (empty($payment_details['currency'])) {
129 129
             $payment_details['currency'] = geodir_get_currency_type();
130 130
         }
131 131
         
132
-        if ( empty( $payment_details['gateway_title'] ) ) {
133
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
132
+        if (empty($payment_details['gateway_title'])) {
133
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
134 134
         }
135 135
     }
136 136
     
137
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'pending' ) );
138
-    
139
-    if ( !empty( $payment_details ) ) {
140
-        $invoice->set( 'currency', $payment_details['currency'] );
141
-        $invoice->set( 'gateway', $payment_details['gateway'] );
142
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
143
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
144
-    }
145
-    
146
-    $invoice->set( 'user_info', $user_info );
147
-    $invoice->set( 'first_name', $user_info['first_name'] );
148
-    $invoice->set( 'last_name', $user_info['last_name'] );
149
-    $invoice->set( 'address', $user_info['address'] );
150
-    $invoice->set( 'company', $user_info['company'] );
151
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
152
-    $invoice->set( 'phone', $user_info['phone'] );
153
-    $invoice->set( 'city', $user_info['city'] );
154
-    $invoice->set( 'country', $user_info['country'] );
155
-    $invoice->set( 'state', $user_info['state'] );
156
-    $invoice->set( 'zip', $user_info['zip'] );
157
-    $invoice->set( 'discounts', $user_info['discount'] );
158
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
159
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
160
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
161
-    }
162
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
163
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
164
-    
165
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
166
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
167
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
168
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
169
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
170
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
137
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'pending'));
138
+    
139
+    if (!empty($payment_details)) {
140
+        $invoice->set('currency', $payment_details['currency']);
141
+        $invoice->set('gateway', $payment_details['gateway']);
142
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
143
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
144
+    }
145
+    
146
+    $invoice->set('user_info', $user_info);
147
+    $invoice->set('first_name', $user_info['first_name']);
148
+    $invoice->set('last_name', $user_info['last_name']);
149
+    $invoice->set('address', $user_info['address']);
150
+    $invoice->set('company', $user_info['company']);
151
+    $invoice->set('vat_number', $user_info['vat_number']);
152
+    $invoice->set('phone', $user_info['phone']);
153
+    $invoice->set('city', $user_info['city']);
154
+    $invoice->set('country', $user_info['country']);
155
+    $invoice->set('state', $user_info['state']);
156
+    $invoice->set('zip', $user_info['zip']);
157
+    $invoice->set('discounts', $user_info['discount']);
158
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
159
+    if (!empty($invoice_data['invoice_key'])) {
160
+        $invoice->set('key', $invoice_data['invoice_key']);
161
+    }
162
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
163
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
164
+    
165
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
166
+        foreach ($invoice_data['cart_details'] as $key => $item) {
167
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
168
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
169
+            $name           = !empty($item['name']) ? $item['name'] : '';
170
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
171 171
             
172
-            $post_item  = new WPInv_Item( $item_id );
173
-            if ( !empty( $post_item ) ) {
174
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
172
+            $post_item = new WPInv_Item($item_id);
173
+            if (!empty($post_item)) {
174
+                $name       = !empty($name) ? $name : $post_item->get_name();
175 175
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
176 176
             } else {
177 177
                 continue;
@@ -181,495 +181,495 @@  discard block
 block discarded – undo
181 181
                 'name'          => $name,
182 182
                 'quantity'      => $quantity,
183 183
                 'item_price'    => $item_price,
184
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
185
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
186
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
187
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
188
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
184
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
185
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
186
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
187
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
188
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
189 189
             );
190 190
 
191
-            $invoice->add_item( $item_id, $args );
191
+            $invoice->add_item($item_id, $args);
192 192
         }
193 193
     }
194 194
 
195
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
195
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
196 196
 
197
-    if ( isset( $invoice_data['post_date'] ) ) {
198
-        $invoice->set( 'date', $invoice_data['post_date'] );
197
+    if (isset($invoice_data['post_date'])) {
198
+        $invoice->set('date', $invoice_data['post_date']);
199 199
     }
200 200
     
201 201
     // Invoice due date
202
-    if ( isset( $invoice_data['due_date'] ) ) {
203
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
202
+    if (isset($invoice_data['due_date'])) {
203
+        $invoice->set('due_date', $invoice_data['due_date']);
204 204
     }
205 205
     
206 206
     $invoice->save();
207 207
     
208 208
     // Add notes
209
-    if ( !empty( $invoice_data['private_note'] ) ) {
210
-        $invoice->add_note( $invoice_data['private_note'] );
209
+    if (!empty($invoice_data['private_note'])) {
210
+        $invoice->add_note($invoice_data['private_note']);
211 211
     }
212
-    if ( !empty( $invoice_data['user_note'] ) ) {
213
-        $invoice->add_note( $invoice_data['user_note'], true );
212
+    if (!empty($invoice_data['user_note'])) {
213
+        $invoice->add_note($invoice_data['user_note'], true);
214 214
     }
215 215
     
216
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
216
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
217 217
 
218
-    if ( ! empty( $invoice->ID ) ) {
218
+    if (!empty($invoice->ID)) {
219 219
         global $wpi_userID, $wpinv_ip_address_country;
220 220
         
221 221
         $checkout_session = wpinv_get_checkout_session();
222 222
         
223 223
         $data_session                   = array();
224 224
         $data_session['invoice_id']     = $invoice->ID;
225
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
225
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
226 226
         
227
-        wpinv_set_checkout_session( $data_session );
227
+        wpinv_set_checkout_session($data_session);
228 228
         
229 229
         $wpi_userID         = (int)$invoice->get_user_id();
230 230
         
231
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
231
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
232 232
         $_POST['state']     = $invoice->state;
233 233
 
234
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
235
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
234
+        $invoice->set('country', sanitize_text_field($_POST['country']));
235
+        $invoice->set('state', sanitize_text_field($_POST['state']));
236 236
         
237 237
         $wpinv_ip_address_country = $invoice->country;
238 238
         
239
-        $invoice = $invoice->recalculate_totals( true );
239
+        $invoice = $invoice->recalculate_totals(true);
240 240
         
241
-        wpinv_set_checkout_session( $checkout_session );
241
+        wpinv_set_checkout_session($checkout_session);
242 242
                     
243 243
         return $invoice;
244 244
     }
245 245
     
246
-    if ( $wp_error ) {
247
-        if ( is_wp_error( $invoice ) ) {
246
+    if ($wp_error) {
247
+        if (is_wp_error($invoice)) {
248 248
             return $invoice;
249 249
         } else {
250
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
250
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
251 251
         }
252 252
     } else {
253 253
         return 0;
254 254
     }
255 255
 }
256 256
 
257
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
258
-    if ( $cart && empty( $invoice_id ) ) {
257
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
258
+    if ($cart && empty($invoice_id)) {
259 259
         $invoice_id = (int)wpinv_get_invoice_cart_id();
260 260
     }
261 261
 
262
-    $invoice = new WPInv_Invoice( $invoice_id );
262
+    $invoice = new WPInv_Invoice($invoice_id);
263 263
     return $invoice;
264 264
 }
265 265
 
266
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
267
-    return wpinv_get_invoice( $invoice_id, true );
266
+function wpinv_get_invoice_cart($invoice_id = 0) {
267
+    return wpinv_get_invoice($invoice_id, true);
268 268
 }
269 269
 
270
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
271
-    $invoice = new WPInv_Invoice( $invoice_id );
270
+function wpinv_get_invoice_description($invoice_id = 0) {
271
+    $invoice = new WPInv_Invoice($invoice_id);
272 272
     return $invoice->get_description();
273 273
 }
274 274
 
275
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
276
-    $invoice = new WPInv_Invoice( $invoice_id );
275
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
276
+    $invoice = new WPInv_Invoice($invoice_id);
277 277
     return $invoice->get_currency();
278 278
 }
279 279
 
280
-function wpinv_get_payment_user_email( $invoice_id ) {
281
-    $invoice = new WPInv_Invoice( $invoice_id );
280
+function wpinv_get_payment_user_email($invoice_id) {
281
+    $invoice = new WPInv_Invoice($invoice_id);
282 282
     return $invoice->get_email();
283 283
 }
284 284
 
285
-function wpinv_get_user_id( $invoice_id ) {
286
-    $invoice = new WPInv_Invoice( $invoice_id );
285
+function wpinv_get_user_id($invoice_id) {
286
+    $invoice = new WPInv_Invoice($invoice_id);
287 287
     return $invoice->get_user_id();
288 288
 }
289 289
 
290
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
291
-    $invoice = new WPInv_Invoice( $invoice_id );
290
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
291
+    $invoice = new WPInv_Invoice($invoice_id);
292 292
     
293
-    return $invoice->get_status( $return_label );
293
+    return $invoice->get_status($return_label);
294 294
 }
295 295
 
296
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
297
-    $invoice = new WPInv_Invoice( $invoice_id );
296
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
297
+    $invoice = new WPInv_Invoice($invoice_id);
298 298
     
299
-    return $invoice->get_gateway( $return_label );
299
+    return $invoice->get_gateway($return_label);
300 300
 }
301 301
 
302
-function wpinv_get_payment_gateway_name( $invoice_id ) {
303
-    $invoice = new WPInv_Invoice( $invoice_id );
302
+function wpinv_get_payment_gateway_name($invoice_id) {
303
+    $invoice = new WPInv_Invoice($invoice_id);
304 304
     
305 305
     return $invoice->get_gateway_title();
306 306
 }
307 307
 
308
-function wpinv_get_payment_transaction_id( $invoice_id ) {
309
-    $invoice = new WPInv_Invoice( $invoice_id );
308
+function wpinv_get_payment_transaction_id($invoice_id) {
309
+    $invoice = new WPInv_Invoice($invoice_id);
310 310
     
311 311
     return $invoice->get_transaction_id();
312 312
 }
313 313
 
314
-function wpinv_get_id_by_transaction_id( $key ) {
314
+function wpinv_get_id_by_transaction_id($key) {
315 315
     global $wpdb;
316 316
 
317
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
317
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
318 318
 
319
-    if ( $invoice_id != NULL )
319
+    if ($invoice_id != NULL)
320 320
         return $invoice_id;
321 321
 
322 322
     return 0;
323 323
 }
324 324
 
325
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
326
-    $invoice = new WPInv_Invoice( $invoice_id );
325
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
326
+    $invoice = new WPInv_Invoice($invoice_id);
327 327
 
328
-    return $invoice->get_meta( $meta_key, $single );
328
+    return $invoice->get_meta($meta_key, $single);
329 329
 }
330 330
 
331
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
332
-    $invoice = new WPInv_Invoice( $invoice_id );
331
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
332
+    $invoice = new WPInv_Invoice($invoice_id);
333 333
     
334
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
334
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
335 335
 }
336 336
 
337
-function wpinv_get_items( $invoice_id = 0 ) {
338
-    $invoice            = wpinv_get_invoice( $invoice_id );
337
+function wpinv_get_items($invoice_id = 0) {
338
+    $invoice            = wpinv_get_invoice($invoice_id);
339 339
     
340 340
     $items              = $invoice->get_items();
341 341
     $invoice_currency   = $invoice->get_currency();
342 342
 
343
-    if ( !empty( $items ) && is_array( $items ) ) {
344
-        foreach ( $items as $key => $item ) {
343
+    if (!empty($items) && is_array($items)) {
344
+        foreach ($items as $key => $item) {
345 345
             $items[$key]['currency'] = $invoice_currency;
346 346
 
347
-            if ( !isset( $cart_item['subtotal'] ) ) {
347
+            if (!isset($cart_item['subtotal'])) {
348 348
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
349 349
             }
350 350
         }
351 351
     }
352 352
 
353
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
353
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
354 354
 }
355 355
 
356
-function wpinv_get_fees( $invoice_id = 0 ) {
357
-    $invoice           = wpinv_get_invoice( $invoice_id );
356
+function wpinv_get_fees($invoice_id = 0) {
357
+    $invoice           = wpinv_get_invoice($invoice_id);
358 358
     $fees              = $invoice->get_fees();
359 359
 
360
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
360
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
361 361
 }
362 362
 
363
-function wpinv_get_invoice_ip( $invoice_id ) {
364
-    $invoice = new WPInv_Invoice( $invoice_id );
363
+function wpinv_get_invoice_ip($invoice_id) {
364
+    $invoice = new WPInv_Invoice($invoice_id);
365 365
     return $invoice->get_ip();
366 366
 }
367 367
 
368
-function wpinv_get_invoice_user_info( $invoice_id ) {
369
-    $invoice = new WPInv_Invoice( $invoice_id );
368
+function wpinv_get_invoice_user_info($invoice_id) {
369
+    $invoice = new WPInv_Invoice($invoice_id);
370 370
     return $invoice->get_user_info();
371 371
 }
372 372
 
373
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
374
-    $invoice = new WPInv_Invoice( $invoice_id );
373
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
374
+    $invoice = new WPInv_Invoice($invoice_id);
375 375
 
376
-    return $invoice->get_subtotal( $currency );
376
+    return $invoice->get_subtotal($currency);
377 377
 }
378 378
 
379
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
380
-    $invoice = new WPInv_Invoice( $invoice_id );
379
+function wpinv_tax($invoice_id = 0, $currency = false) {
380
+    $invoice = new WPInv_Invoice($invoice_id);
381 381
 
382
-    return $invoice->get_tax( $currency );
382
+    return $invoice->get_tax($currency);
383 383
 }
384 384
 
385
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
386
-    $invoice = wpinv_get_invoice( $invoice_id );
385
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
386
+    $invoice = wpinv_get_invoice($invoice_id);
387 387
 
388
-    return $invoice->get_discount( $currency, $dash );
388
+    return $invoice->get_discount($currency, $dash);
389 389
 }
390 390
 
391
-function wpinv_discount_code( $invoice_id = 0 ) {
392
-    $invoice = new WPInv_Invoice( $invoice_id );
391
+function wpinv_discount_code($invoice_id = 0) {
392
+    $invoice = new WPInv_Invoice($invoice_id);
393 393
 
394 394
     return $invoice->get_discount_code();
395 395
 }
396 396
 
397
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
398
-    $invoice = new WPInv_Invoice( $invoice_id );
397
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
398
+    $invoice = new WPInv_Invoice($invoice_id);
399 399
 
400
-    return $invoice->get_total( $currency );
400
+    return $invoice->get_total($currency);
401 401
 }
402 402
 
403
-function wpinv_get_date_created( $invoice_id = 0 ) {
404
-    $invoice = new WPInv_Invoice( $invoice_id );
403
+function wpinv_get_date_created($invoice_id = 0) {
404
+    $invoice = new WPInv_Invoice($invoice_id);
405 405
     
406 406
     $date_created   = $invoice->get_created_date();
407
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
407
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
408 408
 
409 409
     return $date_created;
410 410
 }
411 411
 
412
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
413
-    $invoice = new WPInv_Invoice( $invoice_id );
412
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
413
+    $invoice = new WPInv_Invoice($invoice_id);
414 414
     
415
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
415
+    $format         = !empty($format) ? $format : get_option('date_format');
416 416
     $date_completed = $invoice->get_completed_date();
417
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
418
-    if ( $invoice_date == '' ) {
417
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
418
+    if ($invoice_date == '') {
419 419
         $date_created   = $invoice->get_created_date();
420
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
420
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
421 421
     }
422 422
 
423 423
     return $invoice_date;
424 424
 }
425 425
 
426
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
427
-    $invoice = new WPInv_Invoice( $invoice_id );
426
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
427
+    $invoice = new WPInv_Invoice($invoice_id);
428 428
     
429 429
     return $invoice->vat_number;
430 430
 }
431 431
 
432
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
433
-    $invoice = new WPInv_Invoice( $invoice_id );
432
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
433
+    $invoice = new WPInv_Invoice($invoice_id);
434 434
 
435
-    return $invoice->add_note( $note, $user_type, $added_by_user );
435
+    return $invoice->add_note($note, $user_type, $added_by_user);
436 436
 }
437 437
 
438
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
438
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
439 439
     global $invoicing;
440 440
     
441
-    if ( empty( $invoice_id ) ) {
441
+    if (empty($invoice_id)) {
442 442
         return NULL;
443 443
     }
444 444
     
445
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
445
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
446 446
     
447
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
447
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
448 448
 }
449 449
 
450
-function wpinv_get_payment_key( $invoice_id = 0 ) {
451
-	$invoice = new WPInv_Invoice( $invoice_id );
450
+function wpinv_get_payment_key($invoice_id = 0) {
451
+	$invoice = new WPInv_Invoice($invoice_id);
452 452
     return $invoice->get_key();
453 453
 }
454 454
 
455
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
456
-    $invoice = new WPInv_Invoice( $invoice_id );
455
+function wpinv_get_invoice_number($invoice_id = 0) {
456
+    $invoice = new WPInv_Invoice($invoice_id);
457 457
     return $invoice->get_number();
458 458
 }
459 459
 
460
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
460
+function wpinv_get_cart_discountable_subtotal($code_id) {
461 461
     $cart_items = wpinv_get_cart_content_details();
462 462
     $items      = array();
463 463
 
464
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
464
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
465 465
 
466
-    if( $cart_items ) {
466
+    if ($cart_items) {
467 467
 
468
-        foreach( $cart_items as $item ) {
468
+        foreach ($cart_items as $item) {
469 469
 
470
-            if( ! in_array( $item['id'], $excluded_items ) ) {
471
-                $items[] =  $item;
470
+            if (!in_array($item['id'], $excluded_items)) {
471
+                $items[] = $item;
472 472
             }
473 473
         }
474 474
     }
475 475
 
476
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
476
+    $subtotal = wpinv_get_cart_items_subtotal($items);
477 477
 
478
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
478
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
479 479
 }
480 480
 
481
-function wpinv_get_cart_items_subtotal( $items ) {
481
+function wpinv_get_cart_items_subtotal($items) {
482 482
     $subtotal = 0.00;
483 483
 
484
-    if ( is_array( $items ) && ! empty( $items ) ) {
485
-        $prices = wp_list_pluck( $items, 'subtotal' );
484
+    if (is_array($items) && !empty($items)) {
485
+        $prices = wp_list_pluck($items, 'subtotal');
486 486
 
487
-        if( is_array( $prices ) ) {
488
-            $subtotal = array_sum( $prices );
487
+        if (is_array($prices)) {
488
+            $subtotal = array_sum($prices);
489 489
         } else {
490 490
             $subtotal = 0.00;
491 491
         }
492 492
 
493
-        if( $subtotal < 0 ) {
493
+        if ($subtotal < 0) {
494 494
             $subtotal = 0.00;
495 495
         }
496 496
     }
497 497
 
498
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
498
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
499 499
 }
500 500
 
501
-function wpinv_get_cart_subtotal( $items = array() ) {
502
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
503
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
501
+function wpinv_get_cart_subtotal($items = array()) {
502
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
503
+    $subtotal = wpinv_get_cart_items_subtotal($items);
504 504
 
505
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
505
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
506 506
 }
507 507
 
508
-function wpinv_cart_subtotal( $items = array() ) {
509
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
508
+function wpinv_cart_subtotal($items = array()) {
509
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
510 510
 
511 511
     return $price;
512 512
 }
513 513
 
514
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
515
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
516
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
517
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
514
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
515
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
516
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
517
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
518 518
     $fees      = (float)wpinv_get_cart_fee_total();
519
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
519
+    if (!empty($invoice) && $invoice->is_free_trial()) {
520 520
         $total = 0;
521 521
     } else {
522
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
522
+        $total = $subtotal - $discounts + $cart_tax + $fees;
523 523
     }
524 524
 
525
-    if ( $total < 0 ) {
525
+    if ($total < 0) {
526 526
         $total = 0.00;
527 527
     }
528 528
     
529
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
529
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
530 530
 
531
-    return wpinv_sanitize_amount( $total );
531
+    return wpinv_sanitize_amount($total);
532 532
 }
533 533
 
534
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
534
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
535 535
     global $cart_total;
536
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
537
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
536
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
537
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
538 538
     
539 539
     $cart_total = $total;
540 540
 
541
-    if ( !$echo ) {
541
+    if (!$echo) {
542 542
         return $total;
543 543
     }
544 544
 
545 545
     echo $total;
546 546
 }
547 547
 
548
-function wpinv_get_cart_tax( $items = array() ) {
548
+function wpinv_get_cart_tax($items = array()) {
549 549
     $cart_tax = 0;
550
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
550
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
551 551
 
552
-    if ( $items ) {
553
-        $taxes = wp_list_pluck( $items, 'tax' );
552
+    if ($items) {
553
+        $taxes = wp_list_pluck($items, 'tax');
554 554
 
555
-        if( is_array( $taxes ) ) {
556
-            $cart_tax = array_sum( $taxes );
555
+        if (is_array($taxes)) {
556
+            $cart_tax = array_sum($taxes);
557 557
         }
558 558
     }
559 559
 
560 560
     $cart_tax += wpinv_get_cart_fee_tax();
561 561
 
562
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
562
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
563 563
 }
564 564
 
565
-function wpinv_cart_tax( $items = array(), $echo = false ) {
566
-    $cart_tax = wpinv_get_cart_tax( $items );
567
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
565
+function wpinv_cart_tax($items = array(), $echo = false) {
566
+    $cart_tax = wpinv_get_cart_tax($items);
567
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
568 568
 
569
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
569
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
570 570
 
571
-    if ( !$echo ) {
571
+    if (!$echo) {
572 572
         return $tax;
573 573
     }
574 574
 
575 575
     echo $tax;
576 576
 }
577 577
 
578
-function wpinv_get_cart_discount_code( $items = array() ) {
578
+function wpinv_get_cart_discount_code($items = array()) {
579 579
     $invoice = wpinv_get_invoice_cart();
580
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
580
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
581 581
     
582
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
582
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
583 583
 }
584 584
 
585
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
586
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
585
+function wpinv_cart_discount_code($items = array(), $echo = false) {
586
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
587 587
 
588
-    if ( $cart_discount_code != '' ) {
588
+    if ($cart_discount_code != '') {
589 589
         $cart_discount_code = ' (' . $cart_discount_code . ')';
590 590
     }
591 591
     
592
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
592
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
593 593
 
594
-    if ( !$echo ) {
594
+    if (!$echo) {
595 595
         return $discount_code;
596 596
     }
597 597
 
598 598
     echo $discount_code;
599 599
 }
600 600
 
601
-function wpinv_get_cart_discount( $items = array() ) {
601
+function wpinv_get_cart_discount($items = array()) {
602 602
     $invoice = wpinv_get_invoice_cart();
603
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
603
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
604 604
     
605
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
605
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
606 606
 }
607 607
 
608
-function wpinv_cart_discount( $items = array(), $echo = false ) {
609
-    $cart_discount = wpinv_get_cart_discount( $items );
610
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
608
+function wpinv_cart_discount($items = array(), $echo = false) {
609
+    $cart_discount = wpinv_get_cart_discount($items);
610
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
611 611
 
612
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
612
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
613 613
 
614
-    if ( !$echo ) {
614
+    if (!$echo) {
615 615
         return $discount;
616 616
     }
617 617
 
618 618
     echo $discount;
619 619
 }
620 620
 
621
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
622
-    $item = new WPInv_Item( $item_id );
621
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
622
+    $item = new WPInv_Item($item_id);
623 623
     
624
-    return $item->get_fees( $type, $item_id );
624
+    return $item->get_fees($type, $item_id);
625 625
 }
626 626
 
627 627
 function wpinv_get_cart_fee_total() {
628
-    $total  = 0;
628
+    $total = 0;
629 629
     $fees = wpinv_get_cart_fees();
630 630
     
631
-    if ( $fees ) {
632
-        foreach ( $fees as $fee_id => $fee ) {
631
+    if ($fees) {
632
+        foreach ($fees as $fee_id => $fee) {
633 633
             $total += $fee['amount'];
634 634
         }
635 635
     }
636 636
 
637
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
637
+    return apply_filters('wpinv_get_cart_fee_total', $total);
638 638
 }
639 639
 
640 640
 function wpinv_get_cart_fee_tax() {
641 641
     $tax  = 0;
642 642
     $fees = wpinv_get_cart_fees();
643 643
 
644
-    if ( $fees ) {
645
-        foreach ( $fees as $fee_id => $fee ) {
646
-            if( ! empty( $fee['no_tax'] ) ) {
644
+    if ($fees) {
645
+        foreach ($fees as $fee_id => $fee) {
646
+            if (!empty($fee['no_tax'])) {
647 647
                 continue;
648 648
             }
649 649
 
650
-            $tax += wpinv_calculate_tax( $fee['amount'] );
650
+            $tax += wpinv_calculate_tax($fee['amount']);
651 651
         }
652 652
     }
653 653
 
654
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
654
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
655 655
 }
656 656
 
657 657
 function wpinv_cart_has_recurring_item() {
658 658
     $cart_items = wpinv_get_cart_contents();
659 659
     
660
-    if ( empty( $cart_items ) ) {
660
+    if (empty($cart_items)) {
661 661
         return false;
662 662
     }
663 663
     
664 664
     $has_subscription = false;
665
-    foreach( $cart_items as $cart_item ) {
666
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
665
+    foreach ($cart_items as $cart_item) {
666
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
667 667
             $has_subscription = true;
668 668
             break;
669 669
         }
670 670
     }
671 671
     
672
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
672
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
673 673
 }
674 674
 
675 675
 function wpinv_cart_has_free_trial() {
@@ -677,94 +677,94 @@  discard block
 block discarded – undo
677 677
     
678 678
     $free_trial = false;
679 679
     
680
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
680
+    if (!empty($invoice) && $invoice->is_free_trial()) {
681 681
         $free_trial = true;
682 682
     }
683 683
     
684
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
684
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
685 685
 }
686 686
 
687 687
 function wpinv_get_cart_contents() {
688 688
     $cart_details = wpinv_get_cart_details();
689 689
     
690
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
690
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
691 691
 }
692 692
 
693 693
 function wpinv_get_cart_content_details() {
694 694
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
695 695
     $cart_items = wpinv_get_cart_contents();
696 696
     
697
-    if ( empty( $cart_items ) ) {
697
+    if (empty($cart_items)) {
698 698
         return false;
699 699
     }
700 700
     $invoice = wpinv_get_invoice_cart();
701 701
 
702 702
     $details = array();
703
-    $length  = count( $cart_items ) - 1;
703
+    $length  = count($cart_items) - 1;
704 704
     
705
-    if ( empty( $_POST['country'] ) ) {
705
+    if (empty($_POST['country'])) {
706 706
         $_POST['country'] = $invoice->country;
707 707
     }
708
-    if ( !isset( $_POST['state'] ) ) {
708
+    if (!isset($_POST['state'])) {
709 709
         $_POST['state'] = $invoice->state;
710 710
     }
711 711
 
712
-    foreach( $cart_items as $key => $item ) {
713
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
714
-        if ( empty( $item_id ) ) {
712
+    foreach ($cart_items as $key => $item) {
713
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
714
+        if (empty($item_id)) {
715 715
             continue;
716 716
         }
717 717
         
718 718
         $wpi_current_id         = $invoice->ID;
719 719
         $wpi_item_id            = $item_id;
720 720
         
721
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
721
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
722 722
             $item_price = $item['custom_price'];
723 723
         } else {
724
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
724
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
725 725
                 $item_price = $item['item_price'];
726 726
             } else {
727
-                $item_price = wpinv_get_item_price( $item_id );
727
+                $item_price = wpinv_get_item_price($item_id);
728 728
             }
729 729
         }
730
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
731
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
732
-        $quantity           = wpinv_get_cart_item_quantity( $item );
733
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
730
+        $discount           = wpinv_get_cart_item_discount_amount($item);
731
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
732
+        $quantity           = wpinv_get_cart_item_quantity($item);
733
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
734 734
         
735 735
         $subtotal           = $item_price * $quantity;
736
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
737
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
738
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
736
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
737
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
738
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
739 739
         
740
-        if ( wpinv_prices_include_tax() ) {
741
-            $subtotal -= wpinv_round_amount( $tax );
740
+        if (wpinv_prices_include_tax()) {
741
+            $subtotal -= wpinv_round_amount($tax);
742 742
         }
743 743
         
744
-        $total              = $subtotal - $discount + $tax;
744
+        $total = $subtotal - $discount + $tax;
745 745
         
746 746
         // Do not allow totals to go negatve
747
-        if( $total < 0 ) {
747
+        if ($total < 0) {
748 748
             $total = 0;
749 749
         }
750 750
         
751
-        $details[ $key ]  = array(
751
+        $details[$key] = array(
752 752
             'id'                => $item_id,
753
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
754
-            'item_price'        => wpinv_round_amount( $item_price ),
755
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
753
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
754
+            'item_price'        => wpinv_round_amount($item_price),
755
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
756 756
             'quantity'          => $quantity,
757
-            'discount'          => wpinv_round_amount( $discount ),
758
-            'subtotal'          => wpinv_round_amount( $subtotal ),
759
-            'tax'               => wpinv_round_amount( $tax ),
760
-            'price'             => wpinv_round_amount( $total ),
757
+            'discount'          => wpinv_round_amount($discount),
758
+            'subtotal'          => wpinv_round_amount($subtotal),
759
+            'tax'               => wpinv_round_amount($tax),
760
+            'price'             => wpinv_round_amount($total),
761 761
             'vat_rates_class'   => $tax_class,
762 762
             'vat_rate'          => $tax_rate,
763
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
763
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
764 764
             'fees'              => $fees,
765 765
         );
766 766
         
767
-        if ( $wpinv_is_last_cart_item ) {
767
+        if ($wpinv_is_last_cart_item) {
768 768
             $wpinv_is_last_cart_item   = false;
769 769
             $wpinv_flat_discount_total = 0.00;
770 770
         }
@@ -773,60 +773,60 @@  discard block
 block discarded – undo
773 773
     return $details;
774 774
 }
775 775
 
776
-function wpinv_get_cart_details( $invoice_id = 0 ) {
776
+function wpinv_get_cart_details($invoice_id = 0) {
777 777
     global $ajax_cart_details;
778 778
 
779
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
780
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
779
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
780
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
781 781
 
782 782
     $invoice_currency = $invoice->currency;
783 783
 
784
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
785
-        foreach ( $cart_details as $key => $cart_item ) {
786
-            $cart_details[ $key ]['currency'] = $invoice_currency;
784
+    if (!empty($cart_details) && is_array($cart_details)) {
785
+        foreach ($cart_details as $key => $cart_item) {
786
+            $cart_details[$key]['currency'] = $invoice_currency;
787 787
 
788
-            if ( ! isset( $cart_item['subtotal'] ) ) {
789
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
788
+            if (!isset($cart_item['subtotal'])) {
789
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
790 790
             }
791 791
         }
792 792
     }
793 793
 
794
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
794
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
795 795
 }
796 796
 
797
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
798
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
797
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
798
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
799 799
         return;
800 800
     }
801 801
 
802
-    $invoice    = wpinv_get_invoice( $invoice_id );
802
+    $invoice    = wpinv_get_invoice($invoice_id);
803 803
     
804
-    $old_status = wpinv_status_nicename( $old_status );
805
-    $new_status = wpinv_status_nicename( $new_status );
804
+    $old_status = wpinv_status_nicename($old_status);
805
+    $new_status = wpinv_status_nicename($new_status);
806 806
 
807
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
807
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
808 808
     
809 809
     // Add note
810
-    return $invoice->add_note( $status_change, false, false, true );
810
+    return $invoice->add_note($status_change, false, false, true);
811 811
 }
812
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
812
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
813 813
 
814
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
814
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
815 815
     global $wpi_has_free_trial;
816 816
     
817 817
     $wpi_has_free_trial = false;
818 818
     
819
-    if ( $old_status == 'publish' ) {
819
+    if ($old_status == 'publish') {
820 820
         return; // Make sure that payments are only paid once
821 821
     }
822 822
 
823 823
     // Make sure the payment completion is only processed when new status is paid
824
-    if ( $new_status != 'publish' ) {
824
+    if ($new_status != 'publish') {
825 825
         return;
826 826
     }
827 827
 
828
-    $invoice = new WPInv_Invoice( $invoice_id );
829
-    if ( empty( $invoice ) ) {
828
+    $invoice = new WPInv_Invoice($invoice_id);
829
+    if (empty($invoice)) {
830 830
         return;
831 831
     }
832 832
 
@@ -834,58 +834,58 @@  discard block
 block discarded – undo
834 834
     $completed_date = $invoice->completed_date;
835 835
     $cart_details   = $invoice->cart_details;
836 836
 
837
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
837
+    do_action('wpinv_pre_complete_payment', $invoice_id);
838 838
 
839
-    if ( is_array( $cart_details ) ) {
839
+    if (is_array($cart_details)) {
840 840
         // Increase purchase count and earnings
841
-        foreach ( $cart_details as $cart_index => $item ) {
841
+        foreach ($cart_details as $cart_index => $item) {
842 842
             // Ensure these actions only run once, ever
843
-            if ( empty( $completed_date ) ) {
844
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
843
+            if (empty($completed_date)) {
844
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
845 845
             }
846 846
         }
847 847
     }
848 848
     
849 849
     // Check for discount codes and increment their use counts
850
-    if ( $discounts = $invoice->get_discounts( true ) ) {
851
-        if( ! empty( $discounts ) ) {
852
-            foreach( $discounts as $code ) {
853
-                wpinv_increase_discount_usage( $code );
850
+    if ($discounts = $invoice->get_discounts(true)) {
851
+        if (!empty($discounts)) {
852
+            foreach ($discounts as $code) {
853
+                wpinv_increase_discount_usage($code);
854 854
             }
855 855
         }
856 856
     }
857 857
     
858 858
     // Ensure this action only runs once ever
859
-    if( empty( $completed_date ) ) {
859
+    if (empty($completed_date)) {
860 860
         // Save the completed date
861
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
861
+        $invoice->set('completed_date', current_time('mysql', 0));
862 862
         $invoice->save();
863 863
 
864
-        do_action( 'wpinv_complete_payment', $invoice_id );
864
+        do_action('wpinv_complete_payment', $invoice_id);
865 865
     }
866 866
 
867 867
     // Empty the shopping cart
868 868
     wpinv_empty_cart();
869 869
 }
870
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
870
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
871 871
 
872
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
873
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
872
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
873
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
874 874
     
875
-    if ( empty( $invoice ) ) {
875
+    if (empty($invoice)) {
876 876
         return false;
877 877
     }
878 878
     
879
-    return $invoice->update_status( $new_status );
879
+    return $invoice->update_status($new_status);
880 880
 }
881 881
 
882
-function wpinv_cart_has_fees( $type = 'all' ) {
882
+function wpinv_cart_has_fees($type = 'all') {
883 883
     return false;
884 884
 }
885 885
 
886 886
 function wpinv_validate_checkout_fields() {    
887 887
     // Check if there is $_POST
888
-    if ( empty( $_POST ) ) {
888
+    if (empty($_POST)) {
889 889
         return false;
890 890
     }
891 891
     
@@ -897,11 +897,11 @@  discard block
 block discarded – undo
897 897
     );
898 898
     
899 899
     // Validate agree to terms
900
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
900
+    if (wpinv_get_option('show_agree_to_terms', false)) {
901 901
         wpinv_checkout_validate_agree_to_terms();
902 902
     }
903 903
     
904
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
904
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
905 905
     
906 906
     // Return collected data
907 907
     return $valid_data;
@@ -912,26 +912,26 @@  discard block
 block discarded – undo
912 912
     
913 913
     $invoice = wpinv_get_invoice_cart();
914 914
     $has_subscription = $invoice->is_recurring();
915
-    if ( empty( $invoice ) ) {
916
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
915
+    if (empty($invoice)) {
916
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
917 917
         return $gateway;
918 918
     }
919 919
 
920 920
     // Check if a gateway value is present
921
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
922
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
921
+    if (!empty($_REQUEST['wpi-gateway'])) {
922
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
923 923
 
924
-        if ( $invoice->is_free() ) {
924
+        if ($invoice->is_free()) {
925 925
             $gateway = 'manual';
926
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
927
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
928
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
929
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
926
+        } elseif (!wpinv_is_gateway_active($gateway)) {
927
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
928
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
929
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
930 930
         }
931 931
     }
932 932
 
933
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
934
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
933
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
934
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
935 935
     }
936 936
 
937 937
     return $gateway;
@@ -943,10 +943,10 @@  discard block
 block discarded – undo
943 943
     
944 944
     $error = false;
945 945
     // If we have discounts, loop through them
946
-    if ( ! empty( $discounts ) ) {
947
-        foreach ( $discounts as $discount ) {
946
+    if (!empty($discounts)) {
947
+        foreach ($discounts as $discount) {
948 948
             // Check if valid
949
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
949
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
950 950
                 // Discount is not valid
951 951
                 $error = true;
952 952
             }
@@ -956,20 +956,20 @@  discard block
 block discarded – undo
956 956
         return NULL;
957 957
     }
958 958
 
959
-    if ( $error && !wpinv_get_errors() ) {
960
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
959
+    if ($error && !wpinv_get_errors()) {
960
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
961 961
     }
962 962
 
963
-    return implode( ',', $discounts );
963
+    return implode(',', $discounts);
964 964
 }
965 965
 
966 966
 function wpinv_checkout_validate_cc() {
967 967
     $card_data = wpinv_checkout_get_cc_info();
968 968
 
969 969
     // Validate the card zip
970
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
971
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
972
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
970
+    if (!empty($card_data['wpinv_zip'])) {
971
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
972
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
973 973
         }
974 974
     }
975 975
 
@@ -979,28 +979,28 @@  discard block
 block discarded – undo
979 979
 
980 980
 function wpinv_checkout_get_cc_info() {
981 981
 	$cc_info = array();
982
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
983
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
984
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
985
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
986
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
987
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
988
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
989
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
990
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
991
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
982
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
983
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
984
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
985
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
986
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
987
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
988
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
989
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
990
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
991
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
992 992
 
993 993
 	// Return cc info
994 994
 	return $cc_info;
995 995
 }
996 996
 
997
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
997
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
998 998
     $ret = false;
999 999
 
1000
-    if ( empty( $zip ) || empty( $country_code ) )
1000
+    if (empty($zip) || empty($country_code))
1001 1001
         return $ret;
1002 1002
 
1003
-    $country_code = strtoupper( $country_code );
1003
+    $country_code = strtoupper($country_code);
1004 1004
 
1005 1005
     $zip_regex = array(
1006 1006
         "AD" => "AD\d{3}",
@@ -1160,17 +1160,17 @@  discard block
 block discarded – undo
1160 1160
         "ZM" => "\d{5}"
1161 1161
     );
1162 1162
 
1163
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1163
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1164 1164
         $ret = true;
1165 1165
 
1166
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1166
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1167 1167
 }
1168 1168
 
1169 1169
 function wpinv_checkout_validate_agree_to_terms() {
1170 1170
     // Validate agree to terms
1171
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1171
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1172 1172
         // User did not agree
1173
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1173
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1174 1174
     }
1175 1175
 }
1176 1176
 
@@ -1183,36 +1183,36 @@  discard block
 block discarded – undo
1183 1183
     );
1184 1184
     
1185 1185
     // Verify there is a user_ID
1186
-    if ( $user_ID > 0 ) {
1186
+    if ($user_ID > 0) {
1187 1187
         // Get the logged in user data
1188
-        $user_data = get_userdata( $user_ID );
1189
-        $required_fields  = wpinv_checkout_required_fields();
1188
+        $user_data = get_userdata($user_ID);
1189
+        $required_fields = wpinv_checkout_required_fields();
1190 1190
 
1191 1191
         // Loop through required fields and show error messages
1192
-         if ( !empty( $required_fields ) ) {
1193
-            foreach ( $required_fields as $field_name => $value ) {
1194
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1195
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1192
+         if (!empty($required_fields)) {
1193
+            foreach ($required_fields as $field_name => $value) {
1194
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1195
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1196 1196
                 }
1197 1197
             }
1198 1198
         }
1199 1199
 
1200 1200
         // Verify data
1201
-        if ( $user_data ) {
1201
+        if ($user_data) {
1202 1202
             // Collected logged in user data
1203 1203
             $valid_user_data = array(
1204 1204
                 'user_id'     => $user_ID,
1205
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1206
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1207
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1205
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1206
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1207
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1208 1208
             );
1209 1209
 
1210
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1211
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1210
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1211
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1212 1212
             }
1213 1213
         } else {
1214 1214
             // Set invalid user error
1215
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1215
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1216 1216
         }
1217 1217
     }
1218 1218
 
@@ -1220,21 +1220,21 @@  discard block
 block discarded – undo
1220 1220
     return $valid_user_data;
1221 1221
 }
1222 1222
 
1223
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1223
+function wpinv_checkout_form_get_user($valid_data = array()) {
1224 1224
     // Initialize user
1225 1225
     $user    = false;
1226
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1226
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1227 1227
 
1228 1228
     /*if ( $is_ajax ) {
1229 1229
         // Do not create or login the user during the ajax submission (check for errors only)
1230 1230
         return true;
1231
-    } else */if ( is_user_logged_in() ) {
1231
+    } else */if (is_user_logged_in()) {
1232 1232
         // Set the valid user as the logged in collected data
1233 1233
         $user = $valid_data['logged_in_user'];
1234 1234
     }
1235 1235
 
1236 1236
     // Verify we have an user
1237
-    if ( false === $user || empty( $user ) ) {
1237
+    if (false === $user || empty($user)) {
1238 1238
         // Return false
1239 1239
         return false;
1240 1240
     }
@@ -1253,11 +1253,11 @@  discard block
 block discarded – undo
1253 1253
         'zip',
1254 1254
     );
1255 1255
     
1256
-    foreach ( $address_fields as $field ) {
1257
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1256
+    foreach ($address_fields as $field) {
1257
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1258 1258
         
1259
-        if ( !empty( $user['user_id'] ) ) {
1260
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1259
+        if (!empty($user['user_id'])) {
1260
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1261 1261
         }
1262 1262
     }
1263 1263
 
@@ -1265,28 +1265,28 @@  discard block
 block discarded – undo
1265 1265
     return $user;
1266 1266
 }
1267 1267
 
1268
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1268
+function wpinv_set_checkout_session($invoice_data = array()) {
1269 1269
     global $wpi_session;
1270 1270
     
1271
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1271
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1272 1272
 }
1273 1273
 
1274 1274
 function wpinv_get_checkout_session() {
1275 1275
 	global $wpi_session;
1276 1276
     
1277
-    return $wpi_session->get( 'wpinv_checkout' );
1277
+    return $wpi_session->get('wpinv_checkout');
1278 1278
 }
1279 1279
 
1280 1280
 function wpinv_empty_cart() {
1281 1281
     global $wpi_session;
1282 1282
 
1283 1283
     // Remove cart contents
1284
-    $wpi_session->set( 'wpinv_checkout', NULL );
1284
+    $wpi_session->set('wpinv_checkout', NULL);
1285 1285
 
1286 1286
     // Remove all cart fees
1287
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1287
+    $wpi_session->set('wpi_cart_fees', NULL);
1288 1288
 
1289
-    do_action( 'wpinv_empty_cart' );
1289
+    do_action('wpinv_empty_cart');
1290 1290
 }
1291 1291
 
1292 1292
 function wpinv_process_checkout() {
@@ -1298,42 +1298,42 @@  discard block
 block discarded – undo
1298 1298
     
1299 1299
     $wpi_checkout_id = $invoice->ID;
1300 1300
     
1301
-    do_action( 'wpinv_pre_process_checkout' );
1301
+    do_action('wpinv_pre_process_checkout');
1302 1302
     
1303
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1303
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1304 1304
         $valid_data = false;
1305
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1305
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1306 1306
     } else {
1307 1307
         // Validate the form $_POST data
1308 1308
         $valid_data = wpinv_validate_checkout_fields();
1309 1309
         
1310 1310
         // Allow themes and plugins to hook to errors
1311
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1311
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1312 1312
     }
1313 1313
     
1314
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1314
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1315 1315
     
1316 1316
     // Validate the user
1317
-    $user = wpinv_checkout_form_get_user( $valid_data );
1317
+    $user = wpinv_checkout_form_get_user($valid_data);
1318 1318
 
1319 1319
     // Let extensions validate fields after user is logged in if user has used login/registration form
1320
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1320
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1321 1321
     
1322
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1323
-        if ( $is_ajax ) {
1324
-            do_action( 'wpinv_ajax_checkout_errors' );
1322
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1323
+        if ($is_ajax) {
1324
+            do_action('wpinv_ajax_checkout_errors');
1325 1325
             die();
1326 1326
         } else {
1327 1327
             return false;
1328 1328
         }
1329 1329
     }
1330 1330
 
1331
-    if ( $is_ajax ) {
1331
+    if ($is_ajax) {
1332 1332
         // Save address fields.
1333
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1334
-        foreach ( $address_fields as $field ) {
1335
-            if ( isset( $user[$field] ) ) {
1336
-                $invoice->set( $field, $user[$field] );
1333
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1334
+        foreach ($address_fields as $field) {
1335
+            if (isset($user[$field])) {
1336
+                $invoice->set($field, $user[$field]);
1337 1337
             }
1338 1338
             
1339 1339
             $invoice->save();
@@ -1341,15 +1341,15 @@  discard block
 block discarded – undo
1341 1341
 
1342 1342
         $response['success']            = true;
1343 1343
         $response['data']['subtotal']   = $invoice->get_subtotal();
1344
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1344
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1345 1345
         $response['data']['discount']   = $invoice->get_discount();
1346
-        $response['data']['discountf']  = $invoice->get_discount( true );
1346
+        $response['data']['discountf']  = $invoice->get_discount(true);
1347 1347
         $response['data']['tax']        = $invoice->get_tax();
1348
-        $response['data']['taxf']       = $invoice->get_tax( true );
1348
+        $response['data']['taxf']       = $invoice->get_tax(true);
1349 1349
         $response['data']['total']      = $invoice->get_total();
1350
-        $response['data']['totalf']     = $invoice->get_total( true );
1350
+        $response['data']['totalf']     = $invoice->get_total(true);
1351 1351
         
1352
-        wp_send_json( $response );
1352
+        wp_send_json($response);
1353 1353
     }
1354 1354
     
1355 1355
     $user_info = array(
@@ -1371,42 +1371,42 @@  discard block
 block discarded – undo
1371 1371
     
1372 1372
     // Setup invoice information
1373 1373
     $invoice_data = array(
1374
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1374
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1375 1375
         'items'             => $cart_items,
1376 1376
         'cart_discounts'    => $discounts,
1377
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1378
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1379
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1380
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1381
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1377
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1378
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1379
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1380
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1381
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1382 1382
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1383 1383
         'user_email'        => $user['email'],
1384
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1385
-        'user_info'         => stripslashes_deep( $user_info ),
1384
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1385
+        'user_info'         => stripslashes_deep($user_info),
1386 1386
         'post_data'         => $_POST,
1387 1387
         'cart_details'      => $cart_items,
1388 1388
         'gateway'           => $valid_data['gateway'],
1389 1389
         'card_info'         => $valid_data['cc_info']
1390 1390
     );
1391 1391
     
1392
-    $vat_info   = $wpinv_euvat->current_vat_data();
1393
-    if ( is_array( $vat_info ) ) {
1392
+    $vat_info = $wpinv_euvat->current_vat_data();
1393
+    if (is_array($vat_info)) {
1394 1394
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1395 1395
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1396
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1396
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1397 1397
 
1398 1398
         // Add the VAT rate to each item in the cart
1399
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1399
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1400 1400
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1401
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1401
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1402 1402
         }
1403 1403
     }
1404 1404
     
1405 1405
     // Save vat fields.
1406
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1407
-    foreach ( $address_fields as $field ) {
1408
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1409
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1406
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1407
+    foreach ($address_fields as $field) {
1408
+        if (isset($invoice_data['user_info'][$field])) {
1409
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1410 1410
         }
1411 1411
         
1412 1412
         $invoice->save();
@@ -1416,49 +1416,49 @@  discard block
 block discarded – undo
1416 1416
     $valid_data['user'] = $user;
1417 1417
     
1418 1418
     // Allow themes and plugins to hook before the gateway
1419
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1419
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1420 1420
     
1421 1421
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1422
-    if ( !$invoice_data['price'] ) {
1422
+    if (!$invoice_data['price']) {
1423 1423
         // Revert to manual
1424 1424
         $invoice_data['gateway'] = 'manual';
1425 1425
         $_POST['wpi-gateway'] = 'manual';
1426 1426
     }
1427 1427
     
1428 1428
     // Allow the invoice data to be modified before it is sent to the gateway
1429
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1429
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1430 1430
     
1431 1431
     // Setup the data we're storing in the purchase session
1432 1432
     $session_data = $invoice_data;
1433 1433
     // Make sure credit card numbers are never stored in sessions
1434
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1435
-        unset( $session_data['card_info']['card_number'] );
1434
+    if (!empty($session_data['card_info']['card_number'])) {
1435
+        unset($session_data['card_info']['card_number']);
1436 1436
     }
1437 1437
     
1438 1438
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1439
-    wpinv_set_checkout_session( $invoice_data );
1439
+    wpinv_set_checkout_session($invoice_data);
1440 1440
     
1441 1441
     // Set gateway
1442
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1443
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1444
-    $invoice->update_meta( '_wpinv_checkout', true );
1442
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1443
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1444
+    $invoice->update_meta('_wpinv_checkout', true);
1445 1445
     
1446
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1446
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1447 1447
 
1448 1448
     // Send info to the gateway for payment processing
1449
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1449
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1450 1450
     die();
1451 1451
 }
1452
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1452
+add_action('wpinv_payment', 'wpinv_process_checkout');
1453 1453
 
1454
-function wpinv_get_invoices( $args ) {
1455
-    $args = wp_parse_args( $args, array(
1456
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1454
+function wpinv_get_invoices($args) {
1455
+    $args = wp_parse_args($args, array(
1456
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1457 1457
         'type'     => 'wpi_invoice',
1458 1458
         'parent'   => null,
1459 1459
         'user'     => null,
1460 1460
         'email'    => '',
1461
-        'limit'    => get_option( 'posts_per_page' ),
1461
+        'limit'    => get_option('posts_per_page'),
1462 1462
         'offset'   => null,
1463 1463
         'page'     => 1,
1464 1464
         'exclude'  => array(),
@@ -1466,7 +1466,7 @@  discard block
 block discarded – undo
1466 1466
         'order'    => 'DESC',
1467 1467
         'return'   => 'objects',
1468 1468
         'paginate' => false,
1469
-    ) );
1469
+    ));
1470 1470
     
1471 1471
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1472 1472
     $map_legacy = array(
@@ -1479,20 +1479,20 @@  discard block
 block discarded – undo
1479 1479
         'paged'          => 'page',
1480 1480
     );
1481 1481
 
1482
-    foreach ( $map_legacy as $from => $to ) {
1483
-        if ( isset( $args[ $from ] ) ) {
1484
-            $args[ $to ] = $args[ $from ];
1482
+    foreach ($map_legacy as $from => $to) {
1483
+        if (isset($args[$from])) {
1484
+            $args[$to] = $args[$from];
1485 1485
         }
1486 1486
     }
1487 1487
 
1488
-    $wpinv_cpt = isset( $_REQUEST[ 'wpinv-cpt' ] ) ? $_REQUEST[ 'wpinv-cpt' ] : '';
1488
+    $wpinv_cpt = isset($_REQUEST['wpinv-cpt']) ? $_REQUEST['wpinv-cpt'] : '';
1489 1489
 
1490
-    if ( get_query_var( 'paged' ) && 'wpi_invoice' == $wpinv_cpt )
1490
+    if (get_query_var('paged') && 'wpi_invoice' == $wpinv_cpt)
1491 1491
         $args['page'] = get_query_var('paged');
1492
-    else if ( get_query_var( 'page' )  && 'wpi_invoice' == $wpinv_cpt )
1493
-        $args['page'] = get_query_var( 'page' );
1494
-    else if ( !empty( $args[ 'page' ] ) )
1495
-        $args['page'] = $args[ 'page' ];
1492
+    else if (get_query_var('page') && 'wpi_invoice' == $wpinv_cpt)
1493
+        $args['page'] = get_query_var('page');
1494
+    else if (!empty($args['page']))
1495
+        $args['page'] = $args['page'];
1496 1496
     else
1497 1497
         $args['page'] = 1;
1498 1498
 
@@ -1505,47 +1505,47 @@  discard block
 block discarded – undo
1505 1505
         'post_status'    => $args['status'],
1506 1506
         'posts_per_page' => $args['limit'],
1507 1507
         'meta_query'     => array(),
1508
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1508
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1509 1509
         'fields'         => 'ids',
1510 1510
         'orderby'        => $args['orderby'],
1511 1511
         'order'          => $args['order'],
1512 1512
     );
1513 1513
     
1514
-    if ( !empty( $args['user'] ) ) {
1515
-        $wp_query_args['author'] = absint( $args['user'] );
1514
+    if (!empty($args['user'])) {
1515
+        $wp_query_args['author'] = absint($args['user']);
1516 1516
     }
1517 1517
 
1518
-    if ( ! is_null( $args['parent'] ) ) {
1519
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1518
+    if (!is_null($args['parent'])) {
1519
+        $wp_query_args['post_parent'] = absint($args['parent']);
1520 1520
     }
1521 1521
 
1522
-    if ( ! is_null( $args['offset'] ) ) {
1523
-        $wp_query_args['offset'] = absint( $args['offset'] );
1522
+    if (!is_null($args['offset'])) {
1523
+        $wp_query_args['offset'] = absint($args['offset']);
1524 1524
     } else {
1525
-        $wp_query_args['paged'] = absint( $args['page'] );
1525
+        $wp_query_args['paged'] = absint($args['page']);
1526 1526
     }
1527 1527
 
1528
-    if ( ! empty( $args['exclude'] ) ) {
1529
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1528
+    if (!empty($args['exclude'])) {
1529
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1530 1530
     }
1531 1531
 
1532
-    if ( ! $args['paginate' ] ) {
1532
+    if (!$args['paginate']) {
1533 1533
         $wp_query_args['no_found_rows'] = true;
1534 1534
     }
1535 1535
 
1536 1536
     // Get results.
1537
-    $invoices = new WP_Query( $wp_query_args );
1537
+    $invoices = new WP_Query($wp_query_args);
1538 1538
 
1539
-    if ( 'objects' === $args['return'] ) {
1540
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1541
-    } elseif ( 'self' === $args['return'] ) {
1539
+    if ('objects' === $args['return']) {
1540
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1541
+    } elseif ('self' === $args['return']) {
1542 1542
         return $invoices;
1543 1543
     } else {
1544 1544
         $return = $invoices->posts;
1545 1545
     }
1546 1546
 
1547
-    if ( $args['paginate' ] ) {
1548
-        return (object) array(
1547
+    if ($args['paginate']) {
1548
+        return (object)array(
1549 1549
             'invoices'      => $return,
1550 1550
             'total'         => $invoices->found_posts,
1551 1551
             'max_num_pages' => $invoices->max_num_pages,
@@ -1557,21 +1557,21 @@  discard block
 block discarded – undo
1557 1557
 
1558 1558
 function wpinv_get_user_invoices_columns() {
1559 1559
     $columns = array(
1560
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1561
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1562
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1563
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1564
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1560
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1561
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1562
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1563
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1564
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1565 1565
         );
1566 1566
 
1567
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1567
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1568 1568
 }
1569 1569
 
1570
-function wpinv_payment_receipt( $atts, $content = null ) {
1570
+function wpinv_payment_receipt($atts, $content = null) {
1571 1571
     global $wpinv_receipt_args;
1572 1572
 
1573
-    $wpinv_receipt_args = shortcode_atts( array(
1574
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1573
+    $wpinv_receipt_args = shortcode_atts(array(
1574
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1575 1575
         'price'           => true,
1576 1576
         'discount'        => true,
1577 1577
         'items'           => true,
@@ -1580,185 +1580,185 @@  discard block
 block discarded – undo
1580 1580
         'invoice_key'     => false,
1581 1581
         'payment_method'  => true,
1582 1582
         'invoice_id'      => true
1583
-    ), $atts, 'wpinv_receipt' );
1583
+    ), $atts, 'wpinv_receipt');
1584 1584
 
1585 1585
     $session = wpinv_get_checkout_session();
1586
-    if ( isset( $_GET['invoice_key'] ) ) {
1587
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1588
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1586
+    if (isset($_GET['invoice_key'])) {
1587
+        $invoice_key = urldecode($_GET['invoice_key']);
1588
+    } else if ($session && isset($session['invoice_key'])) {
1589 1589
         $invoice_key = $session['invoice_key'];
1590
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1590
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1591 1591
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1592
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1593
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1592
+    } else if (isset($_GET['invoice-id'])) {
1593
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1594 1594
     }
1595 1595
 
1596 1596
     // No key found
1597
-    if ( ! isset( $invoice_key ) ) {
1597
+    if (!isset($invoice_key)) {
1598 1598
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1599 1599
     }
1600 1600
 
1601
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1602
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1603
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1601
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1602
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1603
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1604 1604
         $invoice_id     = (int)$_GET['invoice-id'];
1605
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1605
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1606 1606
     }
1607 1607
 
1608 1608
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1609
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1609
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1610 1610
         // login redirect
1611
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1611
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1612 1612
     }
1613 1613
 
1614
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1614
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1615 1615
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1616 1616
     }
1617 1617
 
1618 1618
     ob_start();
1619 1619
 
1620
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1620
+    wpinv_get_template_part('wpinv-invoice-receipt');
1621 1621
 
1622 1622
     $display = ob_get_clean();
1623 1623
 
1624 1624
     return $display;
1625 1625
 }
1626 1626
 
1627
-function wpinv_get_invoice_id_by_key( $key ) {
1627
+function wpinv_get_invoice_id_by_key($key) {
1628 1628
 	global $wpdb;
1629 1629
 
1630
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1630
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1631 1631
 
1632
-	if ( $invoice_id != NULL )
1632
+	if ($invoice_id != NULL)
1633 1633
 		return $invoice_id;
1634 1634
 
1635 1635
 	return 0;
1636 1636
 }
1637 1637
 
1638
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1638
+function wpinv_can_view_receipt($invoice_key = '') {
1639 1639
 	$return = false;
1640 1640
 
1641
-	if ( empty( $invoice_key ) ) {
1641
+	if (empty($invoice_key)) {
1642 1642
 		return $return;
1643 1643
 	}
1644 1644
 
1645 1645
 	global $wpinv_receipt_args;
1646 1646
 
1647
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1648
-	if ( isset( $_GET['invoice-id'] ) ) {
1649
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1647
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1648
+	if (isset($_GET['invoice-id'])) {
1649
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1650 1650
 	}
1651 1651
 
1652
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1653
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1652
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1653
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1654 1654
 
1655
-	if ( is_user_logged_in() ) {
1656
-		if ( $user_id === (int) get_current_user_id() ) {
1655
+	if (is_user_logged_in()) {
1656
+		if ($user_id === (int)get_current_user_id()) {
1657 1657
 			$return = true;
1658 1658
 		}
1659 1659
 	}
1660 1660
 
1661 1661
 	$session = wpinv_get_checkout_session();
1662
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1663
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1662
+	if (!empty($session) && !is_user_logged_in()) {
1663
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1664 1664
 			$return = true;
1665 1665
 		}
1666 1666
 	}
1667 1667
 
1668
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1668
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1669 1669
 }
1670 1670
 
1671 1671
 function wpinv_pay_for_invoice() {
1672 1672
     global $wpinv_euvat;
1673 1673
     
1674
-    if ( isset( $_GET['invoice_key'] ) ) {
1674
+    if (isset($_GET['invoice_key'])) {
1675 1675
         $checkout_uri   = wpinv_get_checkout_uri();
1676
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1676
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1677 1677
         
1678
-        if ( empty( $invoice_key ) ) {
1679
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1680
-            wp_redirect( $checkout_uri );
1678
+        if (empty($invoice_key)) {
1679
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1680
+            wp_redirect($checkout_uri);
1681 1681
             wpinv_die();
1682 1682
         }
1683 1683
         
1684
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1684
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1685 1685
 
1686
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1687
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1688
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1686
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1687
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1688
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1689 1689
             $invoice_id     = (int)$_GET['invoice-id'];
1690
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1690
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1691 1691
         }
1692 1692
         
1693
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1694
-            if ( $invoice->needs_payment() ) {
1693
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1694
+            if ($invoice->needs_payment()) {
1695 1695
                 $data                   = array();
1696 1696
                 $data['invoice_id']     = $invoice_id;
1697
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1697
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1698 1698
                 
1699
-                wpinv_set_checkout_session( $data );
1699
+                wpinv_set_checkout_session($data);
1700 1700
                 
1701
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1701
+                if (wpinv_get_option('vat_ip_country_default')) {
1702 1702
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1703 1703
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1704 1704
                     
1705
-                    wpinv_recalculate_tax( true );
1705
+                    wpinv_recalculate_tax(true);
1706 1706
                 }
1707 1707
                 
1708 1708
             } else {
1709 1709
                 $checkout_uri = $invoice->get_view_url();
1710 1710
             }
1711 1711
         } else {
1712
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1712
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1713 1713
             
1714
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1714
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1715 1715
         }
1716 1716
         
1717
-        wp_redirect( $checkout_uri );
1717
+        wp_redirect($checkout_uri);
1718 1718
         wpinv_die();
1719 1719
     }
1720 1720
 }
1721
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1721
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1722 1722
 
1723
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1724
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1725
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1723
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1724
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1725
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1726 1726
             $user_id = $invoice->get_user_id();
1727
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1727
+            $secret = sanitize_text_field($_GET['_wpipay']);
1728 1728
             
1729
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1730
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1729
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1730
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1731 1731
                 
1732
-                wpinv_guest_redirect( $redirect_to, $user_id );
1732
+                wpinv_guest_redirect($redirect_to, $user_id);
1733 1733
                 wpinv_die();
1734 1734
             }
1735 1735
         }
1736 1736
     }
1737 1737
 }
1738
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1738
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1739 1739
 
1740
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1741
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1740
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1741
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1742 1742
     
1743
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1743
+    if (empty($invoice_id) && $invoice_id > 0) {
1744 1744
         return false;
1745 1745
     }
1746 1746
     
1747
-    if ( empty( $transaction_id ) ) {
1747
+    if (empty($transaction_id)) {
1748 1748
         $transaction_id = $invoice_id;
1749 1749
     }
1750 1750
 
1751
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1751
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1752 1752
     
1753
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1753
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1754 1754
 }
1755 1755
 
1756
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1757
-    if ( empty( $status_display ) ) {
1758
-        $status_display = wpinv_status_nicename( $status );
1756
+function wpinv_invoice_status_label($status, $status_display = '') {
1757
+    if (empty($status_display)) {
1758
+        $status_display = wpinv_status_nicename($status);
1759 1759
     }
1760 1760
     
1761
-    switch ( $status ) {
1761
+    switch ($status) {
1762 1762
         case 'publish' :
1763 1763
         case 'wpi-renewal' :
1764 1764
             $class = 'label-success';
@@ -1783,129 +1783,129 @@  discard block
 block discarded – undo
1783 1783
     
1784 1784
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
1785 1785
     
1786
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
1786
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
1787 1787
 }
1788 1788
 
1789
-function wpinv_format_invoice_number( $number ) {
1790
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
1789
+function wpinv_format_invoice_number($number) {
1790
+    $padd = wpinv_get_option('invoice_number_padd');
1791 1791
     
1792 1792
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
1793
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
1794
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
1793
+    if ($padd === '' || $padd === false || $padd === NULL) {
1794
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
1795 1795
     }
1796 1796
     
1797
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1798
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1797
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1798
+    $postfix = wpinv_get_option('invoice_number_postfix');
1799 1799
     
1800
-    $padd = absint( $padd );
1801
-    $formatted_number = absint( $number );
1800
+    $padd = absint($padd);
1801
+    $formatted_number = absint($number);
1802 1802
     
1803
-    if ( $padd > 0 ) {
1804
-        $formatted_number = zeroise( $formatted_number, $padd );
1803
+    if ($padd > 0) {
1804
+        $formatted_number = zeroise($formatted_number, $padd);
1805 1805
     }    
1806 1806
 
1807 1807
     $formatted_number = $prefix . $formatted_number . $postfix;
1808 1808
 
1809
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
1809
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
1810 1810
 }
1811 1811
 
1812 1812
 function wpinv_get_next_invoice_number() {
1813
-    if ( ! wpinv_get_option( 'sequential_invoice_number' ) ) {
1813
+    if (!wpinv_get_option('sequential_invoice_number')) {
1814 1814
         return false;
1815 1815
     }
1816 1816
 
1817
-    $number           = get_option( 'wpinv_last_invoice_number' );
1818
-    $start            = wpinv_get_option( 'invoice_sequence_start', 1 );
1817
+    $number           = get_option('wpinv_last_invoice_number');
1818
+    $start            = wpinv_get_option('invoice_sequence_start', 1);
1819 1819
     $increment_number = true;
1820 1820
 
1821
-    if ( false !== $number ) {
1822
-        if ( empty( $number ) ) {
1821
+    if (false !== $number) {
1822
+        if (empty($number)) {
1823 1823
             $number = $start;
1824 1824
             $increment_number = false;
1825 1825
         }
1826 1826
     } else {
1827
-        $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => 'any' ) );
1827
+        $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => 'any'));
1828 1828
 
1829
-        if ( ! empty( $last_invoice[0] ) ) {
1830
-            $number = wpinv_get_invoice_number( $last_invoice[0] );
1829
+        if (!empty($last_invoice[0])) {
1830
+            $number = wpinv_get_invoice_number($last_invoice[0]);
1831 1831
         }
1832 1832
 
1833
-        if ( ! empty( $number ) && ! empty( $last_invoice[0] ) && $number !== (int) $last_invoice[0] ) {
1834
-            $number = wpinv_clean_invoice_number( $number );
1833
+        if (!empty($number) && !empty($last_invoice[0]) && $number !== (int)$last_invoice[0]) {
1834
+            $number = wpinv_clean_invoice_number($number);
1835 1835
         } else {
1836 1836
             $number = $start;
1837 1837
             $increment_number = false;
1838 1838
         }
1839 1839
     }
1840 1840
 
1841
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
1841
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
1842 1842
 
1843
-    if ( $increment_number ) {
1843
+    if ($increment_number) {
1844 1844
         $number++;
1845 1845
     }
1846 1846
 
1847
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
1847
+    return apply_filters('wpinv_get_next_invoice_number', $number);
1848 1848
 }
1849 1849
 
1850
-function wpinv_clean_invoice_number( $number ) {
1851
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
1852
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
1850
+function wpinv_clean_invoice_number($number) {
1851
+    $prefix  = wpinv_get_option('invoice_number_prefix');
1852
+    $postfix = wpinv_get_option('invoice_number_postfix');
1853 1853
 
1854
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
1854
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
1855 1855
 
1856
-    $length      = strlen( $number );
1857
-    $postfix_pos = strrpos( $number, $postfix );
1856
+    $length      = strlen($number);
1857
+    $postfix_pos = strrpos($number, $postfix);
1858 1858
     
1859
-    if ( false !== $postfix_pos ) {
1860
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
1859
+    if (false !== $postfix_pos) {
1860
+        $number = substr_replace($number, '', $postfix_pos, $length);
1861 1861
     }
1862 1862
 
1863
-    $number = intval( $number );
1863
+    $number = intval($number);
1864 1864
 
1865
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
1865
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
1866 1866
 }
1867 1867
 
1868
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
1868
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
1869 1869
     global $wpdb;
1870 1870
 
1871
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
1872
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft' );
1871
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
1872
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft');
1873 1873
     }
1874 1874
 
1875
-    if ( !$update ) {
1876
-        $wpdb->update( $wpdb->posts, array( 'post_name' => 'inv-' . $post_ID ), array( 'ID' => $post_ID ) );
1877
-        clean_post_cache( $post_ID );
1875
+    if (!$update) {
1876
+        $wpdb->update($wpdb->posts, array('post_name' => 'inv-' . $post_ID), array('ID' => $post_ID));
1877
+        clean_post_cache($post_ID);
1878 1878
     }
1879 1879
 }
1880
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
1880
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
1881 1881
 
1882
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
1883
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
1884
-        wpinv_update_invoice_number( $post_ID, true );
1882
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
1883
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
1884
+        wpinv_update_invoice_number($post_ID, true);
1885 1885
     }
1886 1886
 }
1887
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
1887
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
1888 1888
 
1889
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false ) {
1889
+function wpinv_update_invoice_number($post_ID, $save_sequential = false) {
1890 1890
     global $wpdb;
1891 1891
 
1892
-    if ( wpinv_get_option( 'sequential_invoice_number' ) ) {
1892
+    if (wpinv_get_option('sequential_invoice_number')) {
1893 1893
         $number = wpinv_get_next_invoice_number();
1894 1894
 
1895
-        if ( $save_sequential ) {
1896
-            update_option( 'wpinv_last_invoice_number', $number );
1895
+        if ($save_sequential) {
1896
+            update_option('wpinv_last_invoice_number', $number);
1897 1897
         }
1898 1898
     } else {
1899 1899
         $number = $post_ID;
1900 1900
     }
1901 1901
 
1902
-    $number = wpinv_format_invoice_number( $number );
1902
+    $number = wpinv_format_invoice_number($number);
1903 1903
 
1904
-    update_post_meta( $post_ID, '_wpinv_number', $number );
1904
+    update_post_meta($post_ID, '_wpinv_number', $number);
1905 1905
 
1906
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
1906
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
1907 1907
 
1908
-    clean_post_cache( $post_ID );
1908
+    clean_post_cache($post_ID);
1909 1909
 
1910 1910
     return $number;
1911 1911
 }
1912 1912
\ No newline at end of file
Please login to merge, or discard this patch.