Completed
Push — master ( 4b2794...9fddb7 )
by Brian
18s queued 15s
created
includes/wpinv-general-functions.php 1 patch
Spacing   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -7,202 +7,202 @@  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 65
 function wpinv_is_subscriptions_history_page() {
66
-    $ret = wpinv_get_option( 'invoice_subscription_page', false );
67
-    $ret = $ret ? is_page( $ret ) : false;
68
-    return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );
66
+    $ret = wpinv_get_option('invoice_subscription_page', false);
67
+    $ret = $ret ? is_page($ret) : false;
68
+    return apply_filters('wpinv_is_subscriptions_history_page', $ret);
69 69
 }
70 70
 
71
-function wpinv_send_to_success_page( $args = null ) {
71
+function wpinv_send_to_success_page($args = null) {
72 72
 	$redirect = wpinv_get_success_page_uri();
73 73
     
74
-    if ( !empty( $args ) ) {
74
+    if (!empty($args)) {
75 75
         // Check for backward compatibility
76
-        if ( is_string( $args ) )
77
-            $args = str_replace( '?', '', $args );
76
+        if (is_string($args))
77
+            $args = str_replace('?', '', $args);
78 78
 
79
-        $args = wp_parse_args( $args );
79
+        $args = wp_parse_args($args);
80 80
 
81
-        $redirect = add_query_arg( $args, $redirect );
81
+        $redirect = add_query_arg($args, $redirect);
82 82
     }
83 83
 
84
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
84
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
85 85
     
86
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
87
-    wp_redirect( $redirect );
86
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
87
+    wp_redirect($redirect);
88 88
     exit;
89 89
 }
90 90
 
91
-function wpinv_send_to_failed_page( $args = null ) {
91
+function wpinv_send_to_failed_page($args = null) {
92 92
 	$redirect = wpinv_get_failed_transaction_uri();
93 93
     
94
-    if ( !empty( $args ) ) {
94
+    if (!empty($args)) {
95 95
         // Check for backward compatibility
96
-        if ( is_string( $args ) )
97
-            $args = str_replace( '?', '', $args );
96
+        if (is_string($args))
97
+            $args = str_replace('?', '', $args);
98 98
 
99
-        $args = wp_parse_args( $args );
99
+        $args = wp_parse_args($args);
100 100
 
101
-        $redirect = add_query_arg( $args, $redirect );
101
+        $redirect = add_query_arg($args, $redirect);
102 102
     }
103 103
 
104
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
104
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
105 105
     
106
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
107
-    wp_redirect( $redirect );
106
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
107
+    wp_redirect($redirect);
108 108
     exit;
109 109
 }
110 110
 
111
-function wpinv_get_checkout_uri( $args = array() ) {
112
-	$uri = wpinv_get_option( 'checkout_page', false );
113
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
111
+function wpinv_get_checkout_uri($args = array()) {
112
+	$uri = wpinv_get_option('checkout_page', false);
113
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
114 114
 
115
-	if ( !empty( $args ) ) {
115
+	if (!empty($args)) {
116 116
 		// Check for backward compatibility
117
-		if ( is_string( $args ) )
118
-			$args = str_replace( '?', '', $args );
117
+		if (is_string($args))
118
+			$args = str_replace('?', '', $args);
119 119
 
120
-		$args = wp_parse_args( $args );
120
+		$args = wp_parse_args($args);
121 121
 
122
-		$uri = add_query_arg( $args, $uri );
122
+		$uri = add_query_arg($args, $uri);
123 123
 	}
124 124
 
125
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
125
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
126 126
 
127
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
127
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
128 128
 
129
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
129
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
130
+		$uri = preg_replace('/^http:/', 'https:', $uri);
131 131
 	}
132 132
 
133
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
133
+	return apply_filters('wpinv_get_checkout_uri', $uri);
134 134
 }
135 135
 
136
-function wpinv_send_back_to_checkout( $args = array() ) {
136
+function wpinv_send_back_to_checkout($args = array()) {
137 137
 	$redirect = wpinv_get_checkout_uri();
138 138
 
139
-	if ( ! empty( $args ) ) {
139
+	if (!empty($args)) {
140 140
 		// Check for backward compatibility
141
-		if ( is_string( $args ) )
142
-			$args = str_replace( '?', '', $args );
141
+		if (is_string($args))
142
+			$args = str_replace('?', '', $args);
143 143
 
144
-		$args = wp_parse_args( $args );
144
+		$args = wp_parse_args($args);
145 145
 
146
-		$redirect = add_query_arg( $args, $redirect );
146
+		$redirect = add_query_arg($args, $redirect);
147 147
 	}
148 148
 
149
-    do_action( 'wpinv_pre_send_back_to_checkout', $args );
150
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
149
+    do_action('wpinv_pre_send_back_to_checkout', $args);
150
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
151 151
 	exit;
152 152
 }
153 153
 
154
-function wpinv_get_success_page_url( $query_string = null ) {
155
-	$success_page = wpinv_get_option( 'success_page', 0 );
156
-	$success_page = get_permalink( $success_page );
154
+function wpinv_get_success_page_url($query_string = null) {
155
+	$success_page = wpinv_get_option('success_page', 0);
156
+	$success_page = get_permalink($success_page);
157 157
 
158
-	if ( $query_string )
158
+	if ($query_string)
159 159
 		$success_page .= $query_string;
160 160
 
161
-	return apply_filters( 'wpinv_success_page_url', $success_page );
161
+	return apply_filters('wpinv_success_page_url', $success_page);
162 162
 }
163 163
 
164
-function wpinv_get_failed_transaction_uri( $extras = false ) {
165
-	$uri = wpinv_get_option( 'failure_page', '' );
166
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
164
+function wpinv_get_failed_transaction_uri($extras = false) {
165
+	$uri = wpinv_get_option('failure_page', '');
166
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
167 167
 
168
-	if ( $extras )
168
+	if ($extras)
169 169
 		$uri .= $extras;
170 170
 
171
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
171
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
172 172
 }
173 173
 
174 174
 function wpinv_is_failed_transaction_page() {
175
-	$ret = wpinv_get_option( 'failure_page', false );
176
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
175
+	$ret = wpinv_get_option('failure_page', false);
176
+	$ret = isset($ret) ? is_page($ret) : false;
177 177
 
178
-	return apply_filters( 'wpinv_is_failure_page', $ret );
178
+	return apply_filters('wpinv_is_failure_page', $ret);
179 179
 }
180 180
 
181
-function wpinv_transaction_query( $type = 'start' ) {
181
+function wpinv_transaction_query($type = 'start') {
182 182
     global $wpdb;
183 183
 
184 184
     $wpdb->hide_errors();
185 185
 
186
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
187
-        define( 'WPINV_USE_TRANSACTIONS', true );
186
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
187
+        define('WPINV_USE_TRANSACTIONS', true);
188 188
     }
189 189
 
190
-    if ( WPINV_USE_TRANSACTIONS ) {
191
-        switch ( $type ) {
190
+    if (WPINV_USE_TRANSACTIONS) {
191
+        switch ($type) {
192 192
             case 'commit' :
193
-                $wpdb->query( 'COMMIT' );
193
+                $wpdb->query('COMMIT');
194 194
                 break;
195 195
             case 'rollback' :
196
-                $wpdb->query( 'ROLLBACK' );
196
+                $wpdb->query('ROLLBACK');
197 197
                 break;
198 198
             default :
199
-                $wpdb->query( 'START TRANSACTION' );
199
+                $wpdb->query('START TRANSACTION');
200 200
             break;
201 201
         }
202 202
     }
203 203
 }
204 204
 
205
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
205
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
206 206
     $default_args = array(
207 207
         'status'        => '',
208 208
         'user_id'       => null,
@@ -213,66 +213,66 @@  discard block
 block discarded – undo
213 213
         'post_type'     => 'wpi_invoice'
214 214
     );
215 215
 
216
-    $args           = wp_parse_args( $args, $default_args );
216
+    $args           = wp_parse_args($args, $default_args);
217 217
     $invoice_data   = array();
218 218
 
219
-    if ( $args['invoice_id'] > 0 ) {
220
-        $updating           = true;
219
+    if ($args['invoice_id'] > 0) {
220
+        $updating = true;
221 221
         $invoice_data['post_type']  = $args['post_type'];
222 222
         $invoice_data['ID']         = $args['invoice_id'];
223 223
     } else {
224 224
         $updating                       = false;
225 225
         $invoice_data['post_type']      = $args['post_type'];
226
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' );
226
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'wpi-pending');
227 227
         $invoice_data['ping_status']    = 'closed';
228
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
229
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
230
-        $invoice_data['post_parent']    = absint( $args['parent'] );
231
-        if ( !empty( $args['created_date'] ) ) {
228
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
229
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
230
+        $invoice_data['post_parent']    = absint($args['parent']);
231
+        if (!empty($args['created_date'])) {
232 232
             $invoice_data['post_date']      = $args['created_date'];
233
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
233
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
234 234
         }
235 235
     }
236 236
 
237
-    if ( $args['status'] ) {
238
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) && 'wpi_invoice' === $invoice_data['post_type'] ) {
239
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
237
+    if ($args['status']) {
238
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses())) && 'wpi_invoice' === $invoice_data['post_type']) {
239
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
240 240
         }
241
-        $invoice_data['post_status']    = $args['status'];
241
+        $invoice_data['post_status'] = $args['status'];
242 242
     }
243 243
 
244
-    if ( ! is_null( $args['user_note'] ) ) {
245
-        $invoice_data['post_excerpt']   = $args['user_note'];
244
+    if (!is_null($args['user_note'])) {
245
+        $invoice_data['post_excerpt'] = $args['user_note'];
246 246
     }
247 247
 
248
-    if ( $updating ) {
249
-        $invoice_id = wp_update_post( $invoice_data, true );
248
+    if ($updating) {
249
+        $invoice_id = wp_update_post($invoice_data, true);
250 250
     } else {
251
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
251
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
252 252
     }
253 253
 
254
-    if ( is_wp_error( $invoice_id ) ) {
254
+    if (is_wp_error($invoice_id)) {
255 255
         return $wp_error ? $invoice_id : 0;
256 256
     }
257 257
     
258
-    $invoice = wpinv_get_invoice( $invoice_id );
259
-
260
-    if ( !$updating ) {
261
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
262
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
263
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
264
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
265
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
266
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
258
+    $invoice = wpinv_get_invoice($invoice_id);
259
+
260
+    if (!$updating) {
261
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
262
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
263
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
264
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
265
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
266
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
267 267
         
268 268
         // Add invoice note
269
-        if ( ! $invoice->is_quote() ) {
270
-            $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
269
+        if (!$invoice->is_quote()) {
270
+            $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
271 271
         }
272 272
         
273 273
     }
274 274
 
275
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
275
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
276 276
 
277 277
     return $invoice;
278 278
 }
@@ -280,184 +280,184 @@  discard block
 block discarded – undo
280 280
 function wpinv_get_prefix() {
281 281
     $invoice_prefix = 'INV-';
282 282
     
283
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
283
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
284 284
 }
285 285
 
286 286
 function wpinv_get_business_logo() {
287
-    $business_logo = wpinv_get_option( 'logo' );
288
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
287
+    $business_logo = wpinv_get_option('logo');
288
+    return apply_filters('wpinv_get_business_logo', $business_logo);
289 289
 }
290 290
 
291 291
 function wpinv_get_business_name() {
292 292
     $business_name = wpinv_get_option('store_name');
293
-    return apply_filters( 'wpinv_get_business_name', $business_name );
293
+    return apply_filters('wpinv_get_business_name', $business_name);
294 294
 }
295 295
 
296 296
 function wpinv_get_blogname() {
297
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
297
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
298 298
 }
299 299
 
300 300
 function wpinv_get_admin_email() {
301
-    $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) );
302
-    return apply_filters( 'wpinv_admin_email', $admin_email );
301
+    $admin_email = wpinv_get_option('admin_email', get_option('admin_email'));
302
+    return apply_filters('wpinv_admin_email', $admin_email);
303 303
 }
304 304
 
305 305
 function wpinv_get_business_website() {
306
-    $business_website = home_url( '/' );
307
-    return apply_filters( 'wpinv_get_business_website', $business_website );
306
+    $business_website = home_url('/');
307
+    return apply_filters('wpinv_get_business_website', $business_website);
308 308
 }
309 309
 
310
-function wpinv_get_terms_text( $invoice_id = 0 ) {
310
+function wpinv_get_terms_text($invoice_id = 0) {
311 311
     $terms_text = '';
312
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
312
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
313 313
 }
314 314
 
315 315
 function wpinv_get_business_footer() {
316
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
317
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
318
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
316
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
317
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
318
+    return apply_filters('wpinv_get_business_footer', $business_footer);
319 319
 }
320 320
 
321 321
 function wpinv_checkout_required_fields() {
322 322
     $required_fields = array();
323 323
     
324 324
     // Let payment gateways and other extensions determine if address fields should be required
325
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
325
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
326 326
     
327
-    if ( $require_billing_details ) {
328
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
327
+    if ($require_billing_details) {
328
+		if ((bool) wpinv_get_option('fname_mandatory')) {
329 329
 			$required_fields['first_name'] = array(
330 330
 				'error_id' => 'invalid_first_name',
331
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
331
+				'error_message' => __('Please enter your first name', 'invoicing')
332 332
 			);
333 333
 		}
334
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
334
+		if ((bool) wpinv_get_option('address_mandatory')) {
335 335
 			$required_fields['address'] = array(
336 336
 				'error_id' => 'invalid_address',
337
-				'error_message' => __( 'Please enter your address', 'invoicing' )
337
+				'error_message' => __('Please enter your address', 'invoicing')
338 338
 			);
339 339
 		}
340
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
340
+		if ((bool) wpinv_get_option('city_mandatory')) {
341 341
 			$required_fields['city'] = array(
342 342
 				'error_id' => 'invalid_city',
343
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
343
+				'error_message' => __('Please enter your billing city', 'invoicing')
344 344
 			);
345 345
 		}
346
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
346
+		if ((bool) wpinv_get_option('state_mandatory')) {
347 347
 			$required_fields['state'] = array(
348 348
 				'error_id' => 'invalid_state',
349
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
349
+				'error_message' => __('Please enter billing state / province', 'invoicing')
350 350
 			);
351 351
 		}
352
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
352
+		if ((bool) wpinv_get_option('country_mandatory')) {
353 353
 			$required_fields['country'] = array(
354 354
 				'error_id' => 'invalid_country',
355
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
355
+				'error_message' => __('Please select your billing country', 'invoicing')
356 356
 			);
357 357
 		}
358 358
     }
359 359
 
360
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
360
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
361 361
 }
362 362
 
363 363
 function wpinv_is_ssl_enforced() {
364
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
365
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
364
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
365
+    return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
366 366
 }
367 367
 
368
-function wpinv_user_can_view_invoice( $post ) {
368
+function wpinv_user_can_view_invoice($post) {
369 369
     $allow = false;
370 370
 
371
-    $post = get_post( $post );
371
+    $post = get_post($post);
372 372
 
373
-    if ( empty( $post->ID ) ) {
373
+    if (empty($post->ID)) {
374 374
         return $allow;
375 375
     }
376 376
 
377
-    $invoice = wpinv_get_invoice( $post->ID );
378
-    if ( empty( $invoice->ID ) ) {
377
+    $invoice = wpinv_get_invoice($post->ID);
378
+    if (empty($invoice->ID)) {
379 379
         return $allow;
380 380
     }
381 381
 
382 382
     // Don't allow trash, draft status
383
-    if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
384
-        if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->ID ) ) { // Admin user
383
+    if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
384
+        if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->ID)) { // Admin user
385 385
             $allow = true;
386 386
         } else {
387
-            if ( is_user_logged_in() ) {
388
-                if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) {
387
+            if (is_user_logged_in()) {
388
+                if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
389 389
                     $allow = true;
390
-                } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
390
+                } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
391 391
                     $allow = true;
392 392
                 }
393 393
             } else {
394
-                if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
394
+                if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
395 395
                     $allow = true;
396 396
                 }
397 397
             }
398 398
         }
399 399
     }
400 400
     
401
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice );
401
+    return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice);
402 402
 }
403 403
 
404 404
 function wpinv_schedule_events() {
405 405
     // hourly, daily and twicedaily
406
-    if ( !wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' ) ) {
407
-        wp_schedule_event( current_time( 'timestamp' ), 'twicedaily', 'wpinv_register_schedule_event_twicedaily' );
406
+    if (!wp_next_scheduled('wpinv_register_schedule_event_twicedaily')) {
407
+        wp_schedule_event(current_time('timestamp'), 'twicedaily', 'wpinv_register_schedule_event_twicedaily');
408 408
     }
409 409
 }
410
-add_action( 'wp', 'wpinv_schedule_events' );
410
+add_action('wp', 'wpinv_schedule_events');
411 411
 
412 412
 function wpinv_schedule_event_twicedaily() {
413 413
     wpinv_email_payment_reminders();
414 414
 }
415
-add_action( 'wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily' );
415
+add_action('wpinv_register_schedule_event_twicedaily', 'wpinv_schedule_event_twicedaily');
416 416
 
417 417
 function wpinv_require_login_to_checkout() {
418
-    $return = wpinv_get_option( 'login_to_checkout', false );
419
-    return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );
418
+    $return = wpinv_get_option('login_to_checkout', false);
419
+    return (bool) apply_filters('wpinv_require_login_to_checkout', $return);
420 420
 }
421 421
 
422
-function wpinv_sequential_number_active( $type = '' ) {
423
-    $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );
424
-    if ( null !== $check ) {
422
+function wpinv_sequential_number_active($type = '') {
423
+    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type);
424
+    if (null !== $check) {
425 425
         return $check;
426 426
     }
427 427
     
428
-    return wpinv_get_option( 'sequential_invoice_number' );
428
+    return wpinv_get_option('sequential_invoice_number');
429 429
 }
430 430
 
431
-function wpinv_switch_to_locale( $locale = NULL ) {
431
+function wpinv_switch_to_locale($locale = NULL) {
432 432
     global $invoicing, $wpi_switch_locale;
433 433
 
434
-    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) {
435
-        $locale = empty( $locale ) ? get_locale() : $locale;
434
+    if (!empty($invoicing) && function_exists('switch_to_locale')) {
435
+        $locale = empty($locale) ? get_locale() : $locale;
436 436
 
437
-        switch_to_locale( $locale );
437
+        switch_to_locale($locale);
438 438
 
439 439
         $wpi_switch_locale = $locale;
440 440
 
441
-        add_filter( 'plugin_locale', 'get_locale' );
441
+        add_filter('plugin_locale', 'get_locale');
442 442
 
443 443
         $invoicing->load_textdomain();
444 444
 
445
-        do_action( 'wpinv_switch_to_locale', $locale );
445
+        do_action('wpinv_switch_to_locale', $locale);
446 446
     }
447 447
 }
448 448
 
449 449
 function wpinv_restore_locale() {
450 450
     global $invoicing, $wpi_switch_locale;
451 451
     
452
-    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) {
452
+    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) {
453 453
         restore_previous_locale();
454 454
 
455 455
         $wpi_switch_locale = NULL;
456 456
 
457
-        remove_filter( 'plugin_locale', 'get_locale' );
457
+        remove_filter('plugin_locale', 'get_locale');
458 458
 
459 459
         $invoicing->load_textdomain();
460 460
 
461
-        do_action( 'wpinv_restore_locale' );
461
+        do_action('wpinv_restore_locale');
462 462
     }
463 463
 }
464 464
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-template-functions.php 1 patch
Spacing   +743 added lines, -743 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array) $template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,159 +208,159 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
245
-	$classes = (array)$class;
244
+function wpinv_add_body_classes($class) {
245
+	$classes = (array) $class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
 
334 334
     $options = array(
335
-        '1'  => __( 'January', 'invoicing' ),
336
-        '2'  => __( 'February', 'invoicing' ),
337
-        '3'  => __( 'March', 'invoicing' ),
338
-        '4'  => __( 'April', 'invoicing' ),
339
-        '5'  => __( 'May', 'invoicing' ),
340
-        '6'  => __( 'June', 'invoicing' ),
341
-        '7'  => __( 'July', 'invoicing' ),
342
-        '8'  => __( 'August', 'invoicing' ),
343
-        '9'  => __( 'September', 'invoicing' ),
344
-        '10' => __( 'October', 'invoicing' ),
345
-        '11' => __( 'November', 'invoicing' ),
346
-        '12' => __( 'December', 'invoicing' ),
335
+        '1'  => __('January', 'invoicing'),
336
+        '2'  => __('February', 'invoicing'),
337
+        '3'  => __('March', 'invoicing'),
338
+        '4'  => __('April', 'invoicing'),
339
+        '5'  => __('May', 'invoicing'),
340
+        '6'  => __('June', 'invoicing'),
341
+        '7'  => __('July', 'invoicing'),
342
+        '8'  => __('August', 'invoicing'),
343
+        '9'  => __('September', 'invoicing'),
344
+        '10' => __('October', 'invoicing'),
345
+        '11' => __('November', 'invoicing'),
346
+        '12' => __('December', 'invoicing'),
347 347
     );
348 348
 
349 349
     // If no month is selected, default to the current month
350
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
350
+    $selected = empty($selected) ? date('n') : $selected;
351 351
 
352
-    $output = wpinv_html_select( array(
352
+    $output = wpinv_html_select(array(
353 353
         'name'             => $name,
354 354
         'selected'         => $selected,
355 355
         'options'          => $options,
356 356
         'show_option_all'  => false,
357 357
         'show_option_none' => false
358
-    ) );
358
+    ));
359 359
 
360 360
     return $output;
361 361
 }
362 362
 
363
-function wpinv_html_select( $args = array() ) {
363
+function wpinv_html_select($args = array()) {
364 364
     $defaults = array(
365 365
         'options'          => array(),
366 366
         'name'             => null,
@@ -369,8 +369,8 @@  discard block
 block discarded – undo
369 369
         'selected'         => 0,
370 370
         'placeholder'      => null,
371 371
         'multiple'         => false,
372
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
373
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
372
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
373
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
374 374
         'data'             => array(),
375 375
         'onchange'         => null,
376 376
         'required'         => false,
@@ -378,74 +378,74 @@  discard block
 block discarded – undo
378 378
         'readonly'         => false,
379 379
     );
380 380
 
381
-    $args = wp_parse_args( $args, $defaults );
381
+    $args = wp_parse_args($args, $defaults);
382 382
 
383 383
     $data_elements = '';
384
-    foreach ( $args['data'] as $key => $value ) {
385
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
384
+    foreach ($args['data'] as $key => $value) {
385
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
386 386
     }
387 387
 
388
-    if( $args['multiple'] ) {
388
+    if ($args['multiple']) {
389 389
         $multiple = ' MULTIPLE';
390 390
     } else {
391 391
         $multiple = '';
392 392
     }
393 393
 
394
-    if( $args['placeholder'] ) {
394
+    if ($args['placeholder']) {
395 395
         $placeholder = $args['placeholder'];
396 396
     } else {
397 397
         $placeholder = '';
398 398
     }
399 399
     
400 400
     $options = '';
401
-    if( !empty( $args['onchange'] ) ) {
402
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
401
+    if (!empty($args['onchange'])) {
402
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
403 403
     }
404 404
     
405
-    if( !empty( $args['required'] ) ) {
405
+    if (!empty($args['required'])) {
406 406
         $options .= ' required="required"';
407 407
     }
408 408
     
409
-    if( !empty( $args['disabled'] ) ) {
409
+    if (!empty($args['disabled'])) {
410 410
         $options .= ' disabled';
411 411
     }
412 412
     
413
-    if( !empty( $args['readonly'] ) ) {
413
+    if (!empty($args['readonly'])) {
414 414
         $options .= ' readonly';
415 415
     }
416 416
 
417
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
418
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
417
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
418
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
419 419
 
420
-    if ( $args['show_option_all'] ) {
421
-        if( $args['multiple'] ) {
422
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
420
+    if ($args['show_option_all']) {
421
+        if ($args['multiple']) {
422
+            $selected = selected(true, in_array(0, $args['selected']), false);
423 423
         } else {
424
-            $selected = selected( $args['selected'], 0, false );
424
+            $selected = selected($args['selected'], 0, false);
425 425
         }
426
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
426
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
427 427
     }
428 428
 
429
-    if ( !empty( $args['options'] ) ) {
429
+    if (!empty($args['options'])) {
430 430
 
431
-        if ( $args['show_option_none'] ) {
432
-            if( $args['multiple'] ) {
433
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
431
+        if ($args['show_option_none']) {
432
+            if ($args['multiple']) {
433
+                $selected = selected(true, in_array("", $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'] === "", true, false );
435
+                $selected = selected($args['selected'] === "", true, false);
436 436
             }
437
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
437
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
438 438
         }
439 439
 
440
-        foreach( $args['options'] as $key => $option ) {
440
+        foreach ($args['options'] as $key => $option) {
441 441
 
442
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
443
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
442
+            if ($args['multiple'] && is_array($args['selected'])) {
443
+                $selected = selected(true, (bool) in_array($key, $args['selected']), false);
444 444
             } else {
445
-                $selected = selected( $args['selected'], $key, false );
445
+                $selected = selected($args['selected'], $key, false);
446 446
             }
447 447
 
448
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
448
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
449 449
         }
450 450
     }
451 451
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
     return $output;
455 455
 }
456 456
 
457
-function wpinv_item_dropdown( $args = array() ) {
457
+function wpinv_item_dropdown($args = array()) {
458 458
     $defaults = array(
459 459
         'name'              => 'wpi_item',
460 460
         'id'                => 'wpi_item',
@@ -462,14 +462,14 @@  discard block
 block discarded – undo
462 462
         'multiple'          => false,
463 463
         'selected'          => 0,
464 464
         'number'            => 100,
465
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
466
-        'data'              => array( 'search-type' => 'item' ),
465
+        'placeholder'       => __('Choose a item', 'invoicing'),
466
+        'data'              => array('search-type' => 'item'),
467 467
         'show_option_all'   => false,
468 468
         'show_option_none'  => false,
469 469
         'show_recurring'    => false,
470 470
     );
471 471
 
472
-    $args = wp_parse_args( $args, $defaults );
472
+    $args = wp_parse_args($args, $defaults);
473 473
 
474 474
     $item_args = array(
475 475
         'post_type'      => 'wpi_item',
@@ -478,44 +478,44 @@  discard block
 block discarded – undo
478 478
         'posts_per_page' => $args['number']
479 479
     );
480 480
     
481
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
481
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
482 482
 
483
-    $items      = get_posts( $item_args );
483
+    $items      = get_posts($item_args);
484 484
     $options    = array();
485
-    if ( $items ) {
486
-        foreach ( $items as $item ) {
487
-            $title = esc_html( $item->post_title );
485
+    if ($items) {
486
+        foreach ($items as $item) {
487
+            $title = esc_html($item->post_title);
488 488
             
489
-            if ( !empty( $args['show_recurring'] ) ) {
490
-                $title .= wpinv_get_item_suffix( $item->ID, false );
489
+            if (!empty($args['show_recurring'])) {
490
+                $title .= wpinv_get_item_suffix($item->ID, false);
491 491
             }
492 492
             
493
-            $options[ absint( $item->ID ) ] = $title;
493
+            $options[absint($item->ID)] = $title;
494 494
         }
495 495
     }
496 496
 
497 497
     // This ensures that any selected items are included in the drop down
498
-    if( is_array( $args['selected'] ) ) {
499
-        foreach( $args['selected'] as $item ) {
500
-            if( ! in_array( $item, $options ) ) {
501
-                $title = get_the_title( $item );
502
-                if ( !empty( $args['show_recurring'] ) ) {
503
-                    $title .= wpinv_get_item_suffix( $item, false );
498
+    if (is_array($args['selected'])) {
499
+        foreach ($args['selected'] as $item) {
500
+            if (!in_array($item, $options)) {
501
+                $title = get_the_title($item);
502
+                if (!empty($args['show_recurring'])) {
503
+                    $title .= wpinv_get_item_suffix($item, false);
504 504
                 }
505 505
                 $options[$item] = $title;
506 506
             }
507 507
         }
508
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
509
-        if ( ! in_array( $args['selected'], $options ) ) {
510
-            $title = get_the_title( $args['selected'] );
511
-            if ( !empty( $args['show_recurring'] ) ) {
512
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
508
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
509
+        if (!in_array($args['selected'], $options)) {
510
+            $title = get_the_title($args['selected']);
511
+            if (!empty($args['show_recurring'])) {
512
+                $title .= wpinv_get_item_suffix($args['selected'], false);
513 513
             }
514
-            $options[$args['selected']] = get_the_title( $args['selected'] );
514
+            $options[$args['selected']] = get_the_title($args['selected']);
515 515
         }
516 516
     }
517 517
 
518
-    $output = wpinv_html_select( array(
518
+    $output = wpinv_html_select(array(
519 519
         'name'             => $args['name'],
520 520
         'selected'         => $args['selected'],
521 521
         'id'               => $args['id'],
@@ -526,12 +526,12 @@  discard block
 block discarded – undo
526 526
         'show_option_all'  => $args['show_option_all'],
527 527
         'show_option_none' => $args['show_option_none'],
528 528
         'data'             => $args['data'],
529
-    ) );
529
+    ));
530 530
 
531 531
     return $output;
532 532
 }
533 533
 
534
-function wpinv_html_checkbox( $args = array() ) {
534
+function wpinv_html_checkbox($args = array()) {
535 535
     $defaults = array(
536 536
         'name'     => null,
537 537
         'current'  => null,
@@ -542,38 +542,38 @@  discard block
 block discarded – undo
542 542
         )
543 543
     );
544 544
 
545
-    $args = wp_parse_args( $args, $defaults );
545
+    $args = wp_parse_args($args, $defaults);
546 546
 
547
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
547
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
548 548
     $options = '';
549
-    if ( ! empty( $args['options']['disabled'] ) ) {
549
+    if (!empty($args['options']['disabled'])) {
550 550
         $options .= ' disabled="disabled"';
551
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
551
+    } elseif (!empty($args['options']['readonly'])) {
552 552
         $options .= ' readonly';
553 553
     }
554 554
 
555
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
555
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
556 556
 
557 557
     return $output;
558 558
 }
559 559
 
560
-function wpinv_html_text( $args = array() ) {
560
+function wpinv_html_text($args = array()) {
561 561
     // Backwards compatibility
562
-    if ( func_num_args() > 1 ) {
562
+    if (func_num_args() > 1) {
563 563
         $args = func_get_args();
564 564
 
565 565
         $name  = $args[0];
566
-        $value = isset( $args[1] ) ? $args[1] : '';
567
-        $label = isset( $args[2] ) ? $args[2] : '';
568
-        $desc  = isset( $args[3] ) ? $args[3] : '';
566
+        $value = isset($args[1]) ? $args[1] : '';
567
+        $label = isset($args[2]) ? $args[2] : '';
568
+        $desc  = isset($args[3]) ? $args[3] : '';
569 569
     }
570 570
 
571 571
     $defaults = array(
572 572
         'id'           => '',
573
-        'name'         => isset( $name )  ? $name  : 'text',
574
-        'value'        => isset( $value ) ? $value : null,
575
-        'label'        => isset( $label ) ? $label : null,
576
-        'desc'         => isset( $desc )  ? $desc  : null,
573
+        'name'         => isset($name) ? $name : 'text',
574
+        'value'        => isset($value) ? $value : null,
575
+        'label'        => isset($label) ? $label : null,
576
+        'desc'         => isset($desc) ? $desc : null,
577 577
         'placeholder'  => '',
578 578
         'class'        => 'regular-text',
579 579
         'disabled'     => false,
@@ -583,51 +583,51 @@  discard block
 block discarded – undo
583 583
         'data'         => false
584 584
     );
585 585
 
586
-    $args = wp_parse_args( $args, $defaults );
586
+    $args = wp_parse_args($args, $defaults);
587 587
 
588
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
588
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
589 589
     $options = '';
590
-    if( $args['required'] ) {
590
+    if ($args['required']) {
591 591
         $options .= ' required="required"';
592 592
     }
593
-    if( $args['readonly'] ) {
593
+    if ($args['readonly']) {
594 594
         $options .= ' readonly';
595 595
     }
596
-    if( $args['readonly'] ) {
596
+    if ($args['readonly']) {
597 597
         $options .= ' readonly';
598 598
     }
599 599
 
600 600
     $data = '';
601
-    if ( !empty( $args['data'] ) ) {
602
-        foreach ( $args['data'] as $key => $value ) {
603
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
601
+    if (!empty($args['data'])) {
602
+        foreach ($args['data'] as $key => $value) {
603
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
604 604
         }
605 605
     }
606 606
 
607
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
608
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
609
-    if ( ! empty( $args['desc'] ) ) {
610
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
607
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
608
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
609
+    if (!empty($args['desc'])) {
610
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
611 611
     }
612 612
 
613
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
613
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
614 614
 
615 615
     $output .= '</span>';
616 616
 
617 617
     return $output;
618 618
 }
619 619
 
620
-function wpinv_html_date_field( $args = array() ) {
621
-    if( empty( $args['class'] ) ) {
620
+function wpinv_html_date_field($args = array()) {
621
+    if (empty($args['class'])) {
622 622
         $args['class'] = 'wpiDatepicker';
623
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
623
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
624 624
         $args['class'] .= ' wpiDatepicker';
625 625
     }
626 626
 
627
-    return wpinv_html_text( $args );
627
+    return wpinv_html_text($args);
628 628
 }
629 629
 
630
-function wpinv_html_textarea( $args = array() ) {
630
+function wpinv_html_textarea($args = array()) {
631 631
     $defaults = array(
632 632
         'name'        => 'textarea',
633 633
         'value'       => null,
@@ -638,31 +638,31 @@  discard block
 block discarded – undo
638 638
         'placeholder' => '',
639 639
     );
640 640
 
641
-    $args = wp_parse_args( $args, $defaults );
641
+    $args = wp_parse_args($args, $defaults);
642 642
 
643
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
643
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
644 644
     $disabled = '';
645
-    if( $args['disabled'] ) {
645
+    if ($args['disabled']) {
646 646
         $disabled = ' disabled="disabled"';
647 647
     }
648 648
 
649
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
650
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
651
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
649
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
650
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
651
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" placeholder="' . esc_attr($args['placeholder']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
652 652
 
653
-    if ( ! empty( $args['desc'] ) ) {
654
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
653
+    if (!empty($args['desc'])) {
654
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
655 655
     }
656 656
     $output .= '</span>';
657 657
 
658 658
     return $output;
659 659
 }
660 660
 
661
-function wpinv_html_ajax_user_search( $args = array() ) {
661
+function wpinv_html_ajax_user_search($args = array()) {
662 662
     $defaults = array(
663 663
         'name'        => 'user_id',
664 664
         'value'       => null,
665
-        'placeholder' => __( 'Enter username', 'invoicing' ),
665
+        'placeholder' => __('Enter username', 'invoicing'),
666 666
         'label'       => null,
667 667
         'desc'        => null,
668 668
         'class'       => '',
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
         'data'        => false
672 672
     );
673 673
 
674
-    $args = wp_parse_args( $args, $defaults );
674
+    $args = wp_parse_args($args, $defaults);
675 675
 
676 676
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
677 677
 
678 678
     $output  = '<span class="wpinv_user_search_wrap">';
679
-        $output .= wpinv_html_text( $args );
680
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
679
+        $output .= wpinv_html_text($args);
680
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
681 681
     $output .= '</span>';
682 682
 
683 683
     return $output;
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 function wpinv_ip_geolocation() {
687 687
     global $wpinv_euvat;
688 688
     
689
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
689
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
690 690
     $content    = '';
691 691
     $iso        = '';
692 692
     $country    = '';
@@ -697,69 +697,69 @@  discard block
 block discarded – undo
697 697
     $credit     = '';
698 698
     $address    = '';
699 699
     
700
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
700
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
701 701
         try {
702 702
             $iso        = $geoip2_city->country->isoCode;
703 703
             $country    = $geoip2_city->country->name;
704
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
704
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
705 705
             $city       = $geoip2_city->city->name;
706 706
             $longitude  = $geoip2_city->location->longitude;
707 707
             $latitude   = $geoip2_city->location->latitude;
708
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
709
-        } catch( Exception $e ) { }
708
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
709
+        } catch (Exception $e) { }
710 710
     }
711 711
     
712
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
712
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
713 713
         try {
714
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
714
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
715 715
             
716
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
716
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
717 717
                 $iso        = $load_xml->geoplugin_countryCode;
718 718
                 $country    = $load_xml->geoplugin_countryName;
719
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
720
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
719
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
720
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
721 721
                 $longitude  = $load_xml->geoplugin_longitude;
722 722
                 $latitude   = $load_xml->geoplugin_latitude;
723 723
                 $credit     = $load_xml->geoplugin_credit;
724
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
724
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
725 725
             }
726
-        } catch( Exception $e ) { }
726
+        } catch (Exception $e) { }
727 727
     }
728 728
     
729
-    if ( $iso && $longitude && $latitude ) {
730
-        if ( $city ) {
729
+    if ($iso && $longitude && $latitude) {
730
+        if ($city) {
731 731
             $address .= $city . ', ';
732 732
         }
733 733
         
734
-        if ( $region ) {
734
+        if ($region) {
735 735
             $address .= $region . ', ';
736 736
         }
737 737
         
738 738
         $address .= $country . ' (' . $iso . ')';
739
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
740
-        $content .= '<p>'. $credit . '</p>';
739
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
740
+        $content .= '<p>' . $credit . '</p>';
741 741
     } else {
742
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
742
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
743 743
     }
744 744
     ?>
745 745
 <!DOCTYPE html>
746
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
746
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
747 747
 <body>
748
-    <?php if ( $latitude && $latitude ) { ?>
748
+    <?php if ($latitude && $latitude) { ?>
749 749
     <div id="map"></div>
750 750
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
751 751
         <script type="text/javascript">
752 752
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
753 753
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
754 754
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
755
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
755
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
756 756
 
757 757
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
758 758
 
759 759
         var marker = new L.Marker(latlng);
760 760
         map.addLayer(marker);
761 761
 
762
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
762
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
763 763
     </script>
764 764
     <?php } ?>
765 765
     <div style="height:100px"><?php echo $content; ?></div>
@@ -767,18 +767,18 @@  discard block
 block discarded – undo
767 767
 <?php
768 768
     exit;
769 769
 }
770
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
771
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
770
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
771
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
772 772
 
773 773
 // Set up the template for the invoice.
774
-function wpinv_template( $template ) {
774
+function wpinv_template($template) {
775 775
     global $post, $wp_query;
776 776
     
777
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
778
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
779
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
777
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
778
+        if (wpinv_user_can_view_invoice($post->ID)) {
779
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
780 780
         } else {
781
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
781
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
782 782
         }
783 783
     }
784 784
 
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 
788 788
 function wpinv_get_business_address() {
789 789
     $business_address   = wpinv_store_address();
790
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
790
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
791 791
     
792 792
     /*
793 793
     $default_country    = wpinv_get_default_country();
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
     
812 812
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
813 813
     
814
-    return apply_filters( 'wpinv_get_business_address', $business_address );
814
+    return apply_filters('wpinv_get_business_address', $business_address);
815 815
 }
816 816
 
817 817
 function wpinv_display_from_address() {
@@ -821,107 +821,107 @@  discard block
 block discarded – undo
821 821
     if (empty($from_name)) {
822 822
         $from_name = wpinv_get_business_name();
823 823
     }
824
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
824
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
825 825
     <div class="wrapper col-xs-10">
826
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
827
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
828
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
826
+        <div class="name"><?php echo esc_html($from_name); ?></div>
827
+        <?php if ($address = wpinv_get_business_address()) { ?>
828
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
829 829
         <?php } ?>
830
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
831
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
830
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
831
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
832 832
         <?php } ?>
833 833
     </div>
834 834
     <?php
835 835
 }
836 836
 
837
-function wpinv_watermark( $id = 0 ) {
838
-    $output = wpinv_get_watermark( $id );
837
+function wpinv_watermark($id = 0) {
838
+    $output = wpinv_get_watermark($id);
839 839
     
840
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
840
+    return apply_filters('wpinv_get_watermark', $output, $id);
841 841
 }
842 842
 
843
-function wpinv_get_watermark( $id ) {
844
-    if ( !$id > 0 ) {
843
+function wpinv_get_watermark($id) {
844
+    if (!$id > 0) {
845 845
         return NULL;
846 846
     }
847
-    $invoice = wpinv_get_invoice( $id );
847
+    $invoice = wpinv_get_invoice($id);
848 848
     
849
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
850
-        if ( $invoice->is_paid() ) {
851
-            return __( 'Paid', 'invoicing' );
849
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
850
+        if ($invoice->is_paid()) {
851
+            return __('Paid', 'invoicing');
852 852
         }
853
-        if ( $invoice->is_refunded() ) {
854
-            return __( 'Refunded', 'invoicing' );
853
+        if ($invoice->is_refunded()) {
854
+            return __('Refunded', 'invoicing');
855 855
         }
856
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
857
-            return __( 'Cancelled', 'invoicing' );
856
+        if ($invoice->has_status(array('wpi-cancelled'))) {
857
+            return __('Cancelled', 'invoicing');
858 858
         }
859 859
     }
860 860
     
861 861
     return NULL;
862 862
 }
863 863
 
864
-function wpinv_display_invoice_details( $invoice ) {
864
+function wpinv_display_invoice_details($invoice) {
865 865
     global $wpinv_euvat;
866 866
     
867 867
     $invoice_id = $invoice->ID;
868 868
     $vat_name   = $wpinv_euvat->get_vat_name();
869 869
     $use_taxes  = wpinv_use_taxes();
870 870
     
871
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
871
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
872 872
     ?>
873 873
     <table class="table table-bordered table-sm">
874
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
874
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
875 875
             <tr class="wpi-row-number">
876
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
877
-                <td><?php echo esc_html( $invoice_number ); ?></td>
876
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
877
+                <td><?php echo esc_html($invoice_number); ?></td>
878 878
             </tr>
879 879
         <?php } ?>
880 880
         <tr class="wpi-row-status">
881
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
882
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
881
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
882
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
883 883
         </tr>
884
-        <?php if ( $invoice->is_renewal() ) { ?>
884
+        <?php if ($invoice->is_renewal()) { ?>
885 885
         <tr class="wpi-row-parent">
886
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
887
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
886
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
887
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
888 888
         </tr>
889 889
         <?php } ?>
890
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
890
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
891 891
             <tr class="wpi-row-gateway">
892
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
892
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
893 893
                 <td><?php echo $gateway_name; ?></td>
894 894
             </tr>
895 895
         <?php } ?>
896
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
896
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
897 897
             <tr class="wpi-row-date">
898
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
898
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
899 899
                 <td><?php echo $invoice_date; ?></td>
900 900
             </tr>
901 901
         <?php } ?>
902
-        <?php do_action( 'wpinv_display_details_before_due_date', $invoice_id ); ?>
903
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
902
+        <?php do_action('wpinv_display_details_before_due_date', $invoice_id); ?>
903
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
904 904
             <tr class="wpi-row-date">
905
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
905
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
906 906
                 <td><?php echo $due_date; ?></td>
907 907
             </tr>
908 908
         <?php } ?>
909
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
910
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
909
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
910
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
911 911
             <tr class="wpi-row-ovatno">
912
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
912
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
913 913
                 <td><?php echo $owner_vat_number; ?></td>
914 914
             </tr>
915 915
         <?php } ?>
916
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
916
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
917 917
             <tr class="wpi-row-uvatno">
918
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
918
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
919 919
                 <td><?php echo $user_vat_number; ?></td>
920 920
             </tr>
921 921
         <?php } ?>
922 922
         <tr class="table-active tr-total wpi-row-total">
923
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
924
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
923
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
924
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
925 925
         </tr>
926 926
     </table>
927 927
 <?php
@@ -937,84 +937,84 @@  discard block
 block discarded – undo
937 937
  * @param  string $separator How to separate address lines.
938 938
  * @return string
939 939
  */
940
-function wpinv_get_invoice_address_markup( $billing_details, $separator = '<br/>' ) {
940
+function wpinv_get_invoice_address_markup($billing_details, $separator = '<br/>') {
941 941
 
942 942
     // Retrieve the address markup...
943
-    $country= empty( $billing_details['country'] ) ? '' : $billing_details['country'];
944
-    $format = wpinv_get_full_address_format( $country );
943
+    $country = empty($billing_details['country']) ? '' : $billing_details['country'];
944
+    $format = wpinv_get_full_address_format($country);
945 945
 
946 946
     // ... and the replacements.
947
-    $replacements = wpinv_get_invoice_address_replacements( $billing_details );
947
+    $replacements = wpinv_get_invoice_address_replacements($billing_details);
948 948
 
949
-    $formatted_address = str_ireplace( array_keys( $replacements ), $replacements, $format );
949
+    $formatted_address = str_ireplace(array_keys($replacements), $replacements, $format);
950 950
     
951 951
 	// Remove unavailable tags.
952
-    $formatted_address = preg_replace( "/\{\{\w+\}\}/", '', $formatted_address );
952
+    $formatted_address = preg_replace("/\{\{\w+\}\}/", '', $formatted_address);
953 953
 
954 954
     // Clean up white space.
955
-	$formatted_address = preg_replace( '/  +/', ' ', trim( $formatted_address ) );
956
-    $formatted_address = preg_replace( '/\n\n+/', "\n", $formatted_address );
955
+	$formatted_address = preg_replace('/  +/', ' ', trim($formatted_address));
956
+    $formatted_address = preg_replace('/\n\n+/', "\n", $formatted_address);
957 957
     
958 958
     // Break newlines apart and remove empty lines/trim commas and white space.
959
-	$formatted_address = array_filter( array_map( 'wpinv_trim_formatted_address_line', explode( "\n", $formatted_address ) ) );
959
+	$formatted_address = array_filter(array_map('wpinv_trim_formatted_address_line', explode("\n", $formatted_address)));
960 960
 
961 961
     // Add html breaks.
962
-	$formatted_address = implode( $separator, $formatted_address );
962
+	$formatted_address = implode($separator, $formatted_address);
963 963
 
964 964
 	// We're done!
965 965
 	return $formatted_address;
966 966
     
967 967
 }
968 968
 
969
-function wpinv_display_to_address( $invoice_id = 0 ) {
970
-    $invoice = wpinv_get_invoice( $invoice_id );
969
+function wpinv_display_to_address($invoice_id = 0) {
970
+    $invoice = wpinv_get_invoice($invoice_id);
971 971
     
972
-    if ( empty( $invoice ) ) {
972
+    if (empty($invoice)) {
973 973
         return NULL;
974 974
     }
975 975
     
976 976
     $billing_details = $invoice->get_user_info();
977
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
977
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
978 978
     $output .= '<div class="wrapper col-xs-10">';
979 979
     
980 980
     ob_start();
981
-    do_action( 'wpinv_display_to_address_top', $invoice );
981
+    do_action('wpinv_display_to_address_top', $invoice);
982 982
     $output .= ob_get_clean();
983 983
     
984
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
984
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
985 985
 
986
-    if ( $address_row ) {
986
+    if ($address_row) {
987 987
         $output .= '<div class="address">' . $address_row . '</div>';
988 988
     }
989 989
 
990
-    if ( $phone = $invoice->get_phone() ) {
991
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
990
+    if ($phone = $invoice->get_phone()) {
991
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
992 992
     }
993
-    if ( $email = $invoice->get_email() ) {
994
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
993
+    if ($email = $invoice->get_email()) {
994
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
995 995
     }
996 996
 
997 997
     ob_start();
998
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
998
+    do_action('wpinv_display_to_address_bottom', $invoice);
999 999
     $output .= ob_get_clean();
1000 1000
     
1001 1001
     $output .= '</div>';
1002
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
1002
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
1003 1003
 
1004 1004
     echo $output;
1005 1005
 }
1006 1006
 
1007
-function wpinv_display_line_items( $invoice_id = 0 ) {
1007
+function wpinv_display_line_items($invoice_id = 0) {
1008 1008
     global $wpinv_euvat, $ajax_cart_details;
1009
-    $invoice            = wpinv_get_invoice( $invoice_id );
1009
+    $invoice            = wpinv_get_invoice($invoice_id);
1010 1010
     $quantities_enabled = wpinv_item_quantities_enabled();
1011 1011
     $use_taxes          = wpinv_use_taxes();
1012
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
1012
+    if (!$use_taxes && (float) $invoice->get_tax() > 0) {
1013 1013
         $use_taxes = true;
1014 1014
     }
1015
-    $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
1016
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
1017
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
1015
+    $zero_tax           = !(float) $invoice->get_tax() > 0 ? true : false;
1016
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
1017
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
1018 1018
 
1019 1019
     $cart_details       = $invoice->get_cart_details();
1020 1020
     $ajax_cart_details  = $cart_details;
@@ -1023,67 +1023,67 @@  discard block
 block discarded – undo
1023 1023
     <table class="table table-sm table-bordered">
1024 1024
         <thead>
1025 1025
             <tr>
1026
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1027
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1026
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1027
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1028 1028
                 <?php if ($quantities_enabled) { ?>
1029
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1029
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1030 1030
                 <?php } ?>
1031 1031
                 <?php if ($use_taxes && !$zero_tax) { ?>
1032 1032
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1033 1033
                 <?php } ?>
1034
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1034
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1035 1035
             </tr>
1036 1036
         </thead>
1037 1037
         <tbody>
1038 1038
         <?php 
1039
-            if ( !empty( $cart_details ) ) {
1040
-                do_action( 'wpinv_display_line_items_start', $invoice );
1039
+            if (!empty($cart_details)) {
1040
+                do_action('wpinv_display_line_items_start', $invoice);
1041 1041
 
1042 1042
                 $count = 0;
1043 1043
                 $cols  = 3;
1044
-                foreach ( $cart_details as $key => $cart_item ) {
1045
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1046
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1047
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1048
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1044
+                foreach ($cart_details as $key => $cart_item) {
1045
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1046
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1047
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1048
+                    $quantity   = !empty($cart_item['quantity']) && (int) $cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1049 1049
 
1050
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1050
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1051 1051
                     $summary    = '';
1052
-	                $item_name    = '';
1052
+	                $item_name = '';
1053 1053
                     $cols       = 3;
1054
-                    if ( !empty($item) ) {
1054
+                    if (!empty($item)) {
1055 1055
                         $item_name  = $item->get_name();
1056 1056
                         $summary    = $item->get_summary();
1057 1057
                     }
1058
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1058
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1059 1059
 
1060
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1060
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1061 1061
 
1062 1062
                     $item_tax       = '';
1063 1063
                     $tax_rate       = '';
1064
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1065
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1066
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1067
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1064
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1065
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1066
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1067
+                        $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1068 1068
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1069 1069
                     }
1070 1070
 
1071 1071
                     $line_item_tax = $item_tax . $tax_rate;
1072 1072
 
1073
-                    if ( $line_item_tax === '' ) {
1073
+                    if ($line_item_tax === '') {
1074 1074
                         $line_item_tax = 0; // Zero tax
1075 1075
                     }
1076 1076
 
1077
-                    $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols );
1077
+                    $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols);
1078 1078
 
1079
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1080
-                        $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1081
-                        if ( $summary !== '' ) {
1082
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1079
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1080
+                        $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1081
+                        if ($summary !== '') {
1082
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1083 1083
                         }
1084 1084
                         $line_item .= '</td>';
1085 1085
 
1086
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1086
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1087 1087
                         if ($quantities_enabled) {
1088 1088
                             $cols++;
1089 1089
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1092,55 +1092,55 @@  discard block
 block discarded – undo
1092 1092
                             $cols++;
1093 1093
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1094 1094
                         }
1095
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1095
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1096 1096
                     $line_item .= '</tr>';
1097 1097
 
1098
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1098
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1099 1099
 
1100 1100
                     $count++;
1101 1101
                 }
1102 1102
 
1103
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1103
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1104 1104
                 ?>
1105 1105
                 <tr class="row-sub-total row_odd">
1106
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1107
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1106
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1107
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1108 1108
                 </tr>
1109 1109
                 <?php
1110
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1110
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1111 1111
                 
1112
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1113
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1112
+                if (wpinv_discount($invoice_id, false) > 0) {
1113
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1114 1114
                     ?>
1115 1115
                         <tr class="row-discount">
1116
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1117
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1116
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1117
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1118 1118
                         </tr>
1119 1119
                     <?php
1120
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1120
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1121 1121
                 }
1122 1122
 
1123
-                if ( $use_taxes ) {
1124
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1123
+                if ($use_taxes) {
1124
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1125 1125
                     ?>
1126 1126
                     <tr class="row-tax">
1127
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1128
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1127
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1128
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1129 1129
                     </tr>
1130 1130
                     <?php
1131
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1131
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1132 1132
                 }
1133 1133
 
1134
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1134
+                do_action('wpinv_display_before_total', $invoice, $cols);
1135 1135
                 ?>
1136 1136
                 <tr class="table-active row-total">
1137
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1138
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1137
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1138
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1139 1139
                 </tr>
1140 1140
                 <?php
1141
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1141
+                do_action('wpinv_display_after_total', $invoice, $cols);
1142 1142
 
1143
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1143
+                do_action('wpinv_display_line_end', $invoice, $cols);
1144 1144
             }
1145 1145
         ?>
1146 1146
         </tbody>
@@ -1152,56 +1152,56 @@  discard block
 block discarded – undo
1152 1152
 /**
1153 1153
  * @param WPInv_Invoice $invoice
1154 1154
  */
1155
-function wpinv_display_invoice_notes( $invoice ) {
1155
+function wpinv_display_invoice_notes($invoice) {
1156 1156
 
1157
-    $notes = wpinv_get_invoice_notes( $invoice->ID, 'customer' );
1157
+    $notes = wpinv_get_invoice_notes($invoice->ID, 'customer');
1158 1158
 
1159
-    if ( empty( $notes ) ) {
1159
+    if (empty($notes)) {
1160 1160
         return;
1161 1161
     }
1162 1162
 
1163 1163
     echo '<div class="wpi_invoice_notes_container">';
1164
-    echo '<h2>' . __( 'Invoice Notes', 'invoicing' ) .'</h2>';
1164
+    echo '<h2>' . __('Invoice Notes', 'invoicing') . '</h2>';
1165 1165
     echo '<ul class="wpi_invoice_notes">';
1166 1166
 
1167
-    foreach( $notes as $note ) {
1168
-        wpinv_get_invoice_note_line_item( $note );
1167
+    foreach ($notes as $note) {
1168
+        wpinv_get_invoice_note_line_item($note);
1169 1169
     }
1170 1170
 
1171 1171
     echo '</ul>';
1172 1172
     echo '</div>';
1173 1173
 }
1174
-add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes' );
1174
+add_action('wpinv_invoice_print_after_line_items', 'wpinv_display_invoice_notes');
1175 1175
 
1176
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1176
+function wpinv_display_invoice_totals($invoice_id = 0) {
1177 1177
     $use_taxes = wpinv_use_taxes();
1178 1178
 
1179
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1179
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1180 1180
     ?>
1181 1181
     <table class="table table-sm table-bordered table-responsive">
1182 1182
         <tbody>
1183
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1183
+            <?php do_action('wpinv_before_display_totals'); ?>
1184 1184
             <tr class="row-sub-total">
1185
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1186
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1185
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1186
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1187 1187
             </tr>
1188
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1189
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1188
+            <?php do_action('wpinv_after_display_totals'); ?>
1189
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1190 1190
                 <tr class="row-discount">
1191
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1192
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1191
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1192
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1193 1193
                 </tr>
1194
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1194
+            <?php do_action('wpinv_after_display_discount'); ?>
1195 1195
             <?php } ?>
1196
-            <?php if ( $use_taxes ) { ?>
1196
+            <?php if ($use_taxes) { ?>
1197 1197
             <tr class="row-tax">
1198
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1199
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1198
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1199
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1200 1200
             </tr>
1201
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1201
+            <?php do_action('wpinv_after_display_tax'); ?>
1202 1202
             <?php } ?>
1203
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1204
-                <?php foreach ( $fees as $fee ) { ?>
1203
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1204
+                <?php foreach ($fees as $fee) { ?>
1205 1205
                     <tr class="row-fee">
1206 1206
                         <td class="rate"><?php echo $fee['label']; ?></td>
1207 1207
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1209,82 +1209,82 @@  discard block
 block discarded – undo
1209 1209
                 <?php } ?>
1210 1210
             <?php } ?>
1211 1211
             <tr class="table-active row-total">
1212
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1213
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1212
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1213
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1214 1214
             </tr>
1215
-            <?php do_action( 'wpinv_after_totals' ); ?>
1215
+            <?php do_action('wpinv_after_totals'); ?>
1216 1216
         </tbody>
1217 1217
 
1218 1218
     </table>
1219 1219
 
1220
-    <?php do_action( 'wpinv_after_totals_table' );
1220
+    <?php do_action('wpinv_after_totals_table');
1221 1221
 }
1222 1222
 
1223
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1224
-    $invoice = wpinv_get_invoice( $invoice_id );
1223
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1224
+    $invoice = wpinv_get_invoice($invoice_id);
1225 1225
 
1226 1226
     ob_start();
1227
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1228
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1227
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1228
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1229 1229
         ?>
1230 1230
         <div class="wpi-payment-info">
1231
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1232
-            <?php if ( $gateway_title ) { ?>
1233
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1231
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1232
+            <?php if ($gateway_title) { ?>
1233
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1234 1234
             <?php } ?>
1235 1235
         </div>
1236 1236
         <?php
1237 1237
     }
1238
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1238
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1239 1239
     $outout = ob_get_clean();
1240 1240
 
1241
-    if ( $echo ) {
1241
+    if ($echo) {
1242 1242
         echo $outout;
1243 1243
     } else {
1244 1244
         return $outout;
1245 1245
     }
1246 1246
 }
1247 1247
 
1248
-function wpinv_display_style( $invoice ) {
1249
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1248
+function wpinv_display_style($invoice) {
1249
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1250 1250
 
1251
-    wp_print_styles( 'open-sans' );
1252
-    wp_print_styles( 'wpinv-single-style' );
1251
+    wp_print_styles('open-sans');
1252
+    wp_print_styles('wpinv-single-style');
1253 1253
 
1254 1254
     $custom_css = wpinv_get_option('template_custom_css');
1255
-    if(isset($custom_css) && !empty($custom_css)){
1256
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1257
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1255
+    if (isset($custom_css) && !empty($custom_css)) {
1256
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1257
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1258 1258
         echo '<style type="text/css">';
1259 1259
         echo $custom_css;
1260 1260
         echo '</style>';
1261 1261
     }
1262 1262
 }
1263
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1264
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1263
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1264
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1265 1265
 
1266 1266
 function wpinv_checkout_billing_details() {
1267
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
1267
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
1268 1268
     if (empty($invoice_id)) {
1269
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1269
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1270 1270
         return null;
1271 1271
     }
1272 1272
 
1273
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1273
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1274 1274
     if (empty($invoice)) {
1275
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1275
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1276 1276
         return null;
1277 1277
     }
1278 1278
     $user_id        = $invoice->get_user_id();
1279 1279
     $user_info      = $invoice->get_user_info();
1280
-    $address_info   = wpinv_get_user_address( $user_id );
1280
+    $address_info   = wpinv_get_user_address($user_id);
1281 1281
 
1282
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1282
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1283 1283
         $user_info['first_name'] = $user_info['first_name'];
1284 1284
         $user_info['last_name'] = $user_info['last_name'];
1285 1285
     }
1286 1286
 
1287
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1287
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1288 1288
         $user_info['country']   = $address_info['country'];
1289 1289
         $user_info['state']     = $address_info['state'];
1290 1290
         $user_info['city']      = $address_info['city'];
@@ -1300,99 +1300,99 @@  discard block
 block discarded – undo
1300 1300
         'address'
1301 1301
     );
1302 1302
 
1303
-    foreach ( $address_fields as $field ) {
1304
-        if ( empty( $user_info[$field] ) ) {
1303
+    foreach ($address_fields as $field) {
1304
+        if (empty($user_info[$field])) {
1305 1305
             $user_info[$field] = $address_info[$field];
1306 1306
         }
1307 1307
     }
1308 1308
 
1309
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1309
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1310 1310
 }
1311 1311
 
1312 1312
 function wpinv_admin_get_line_items($invoice = array()) {
1313 1313
     $item_quantities    = wpinv_item_quantities_enabled();
1314 1314
     $use_taxes          = wpinv_use_taxes();
1315 1315
 
1316
-    if ( empty( $invoice ) ) {
1316
+    if (empty($invoice)) {
1317 1317
         return NULL;
1318 1318
     }
1319 1319
 
1320 1320
     $cart_items = $invoice->get_cart_details();
1321
-    if ( empty( $cart_items ) ) {
1321
+    if (empty($cart_items)) {
1322 1322
         return NULL;
1323 1323
     }
1324 1324
 
1325 1325
     ob_start();
1326 1326
 
1327
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1327
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1328 1328
 
1329 1329
     $count = 0;
1330
-    foreach ( $cart_items as $key => $cart_item ) {
1330
+    foreach ($cart_items as $key => $cart_item) {
1331 1331
         $item_id    = $cart_item['id'];
1332
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1332
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1333 1333
 
1334 1334
         if (empty($wpi_item)) {
1335 1335
             continue;
1336 1336
         }
1337 1337
 
1338
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1339
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1338
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1339
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1340
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1341 1341
         $can_remove     = true;
1342 1342
 
1343
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1343
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1344 1344
 
1345 1345
         $item_tax       = '';
1346 1346
         $tax_rate       = '';
1347
-        if ( $invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1348
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1349
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1350
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1347
+        if ($invoice->is_taxable() && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1348
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1349
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1350
+            $tax_rate = $tax_rate > 0 ? (float) wpinv_round_amount($tax_rate, 4) : '';
1351 1351
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1352 1352
         }
1353 1353
         $line_item_tax = $item_tax . $tax_rate;
1354 1354
 
1355
-        if ( $line_item_tax === '' ) {
1355
+        if ($line_item_tax === '') {
1356 1356
             $line_item_tax = 0; // Zero tax
1357 1357
         }
1358 1358
 
1359
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1359
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1360 1360
             $line_item .= '<td class="id">' . $item_id . '</td>';
1361
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1362
-            if ( $summary !== '' ) {
1363
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1361
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1362
+            if ($summary !== '') {
1363
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1364 1364
             }
1365 1365
             $line_item .= '</td>';
1366 1366
             $line_item .= '<td class="price">' . $item_price . '</td>';
1367 1367
             
1368
-            if ( $item_quantities ) {
1369
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1368
+            if ($item_quantities) {
1369
+                if (count($cart_items) == 1 && $quantity <= 1) {
1370 1370
                     $can_remove = false;
1371 1371
                 }
1372 1372
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1373 1373
             } else {
1374
-                if ( count( $cart_items ) == 1 ) {
1374
+                if (count($cart_items) == 1) {
1375 1375
                     $can_remove = false;
1376 1376
                 }
1377 1377
             }
1378 1378
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1379 1379
             
1380
-            if ( $use_taxes ) {
1380
+            if ($use_taxes) {
1381 1381
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1382 1382
             }
1383 1383
             $line_item .= '<td class="action">';
1384
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() ) {
1384
+            if (!$invoice->is_paid() && !$invoice->is_refunded()) {
1385 1385
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1386 1386
             }
1387 1387
             $line_item .= '</td>';
1388 1388
         $line_item .= '</tr>';
1389 1389
 
1390
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1390
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1391 1391
 
1392 1392
         $count++;
1393 1393
     } 
1394 1394
 
1395
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1395
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1396 1396
 
1397 1397
     return ob_get_clean();
1398 1398
 }
@@ -1404,32 +1404,32 @@  discard block
 block discarded – undo
1404 1404
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1405 1405
 
1406 1406
     //Maybe update the prices
1407
-    if(! empty( $_GET['wpi_dynamic_item'] ) && ! empty( $_GET['wpi_dynamic_price'] ) ) {
1407
+    if (!empty($_GET['wpi_dynamic_item']) && !empty($_GET['wpi_dynamic_price'])) {
1408 1408
 
1409 1409
         //If the invoice exists, update it with new pricing details
1410
-        if (! empty( $wpi_checkout_id ) ) {
1410
+        if (!empty($wpi_checkout_id)) {
1411 1411
 
1412 1412
             $_invoice       = wpinv_get_invoice_cart();
1413 1413
             $_cart_details  = $_invoice->get_cart_details();
1414
-            $_dynamic_item  = sanitize_text_field( $_GET['wpi_dynamic_item'] );
1414
+            $_dynamic_item  = sanitize_text_field($_GET['wpi_dynamic_item']);
1415 1415
 
1416 1416
             //First, fetch the item
1417
-            $item    = new WPInv_Item( $_dynamic_item );
1417
+            $item = new WPInv_Item($_dynamic_item);
1418 1418
     
1419 1419
             //Next, ensure it supports dynamic pricing...
1420
-            if( $item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing() ) {
1420
+            if ($item->supports_dynamic_pricing() && $item->get_is_dynamic_pricing()) {
1421 1421
                 
1422 1422
                 //... and that the new price is not lower than the minimum price
1423
-                $_dynamic_price = (float) wpinv_sanitize_amount( sanitize_text_field( $_GET['wpi_dynamic_price'] ) );
1424
-                if( $_dynamic_price < $item->get_minimum_price() ) {
1423
+                $_dynamic_price = (float) wpinv_sanitize_amount(sanitize_text_field($_GET['wpi_dynamic_price']));
1424
+                if ($_dynamic_price < $item->get_minimum_price()) {
1425 1425
                     $_dynamic_price = $item->get_minimum_price();
1426 1426
                 }
1427 1427
 
1428 1428
                 //Finally, update our invoice with the new price
1429
-                if ( !empty( $_cart_details ) ) {
1429
+                if (!empty($_cart_details)) {
1430 1430
 
1431
-                    foreach ( $_cart_details as $key => $item ) {
1432
-                        if ( !empty( $item['id'] ) && $_dynamic_item == $item['id'] ) {
1431
+                    foreach ($_cart_details as $key => $item) {
1432
+                        if (!empty($item['id']) && $_dynamic_item == $item['id']) {
1433 1433
                             $_cart_details[$key]['custom_price'] = $_dynamic_price;
1434 1434
                             $_cart_details[$key]['item_price']   = $_dynamic_price;
1435 1435
                         }
@@ -1437,8 +1437,8 @@  discard block
 block discarded – undo
1437 1437
 
1438 1438
                     $_meta = $_invoice->get_meta();
1439 1439
                     $_meta['cart_details'] = $_cart_details;
1440
-                    $_invoice->set( 'payment_meta', $_meta );
1441
-                    $_invoice->set( 'cart_details', $_cart_details );
1440
+                    $_invoice->set('payment_meta', $_meta);
1441
+                    $_invoice->set('cart_details', $_cart_details);
1442 1442
                     $_invoice->recalculate_totals();
1443 1443
 
1444 1444
                 }
@@ -1449,60 +1449,60 @@  discard block
 block discarded – undo
1449 1449
 
1450 1450
     }
1451 1451
 
1452
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1452
+    $form_action = esc_url(wpinv_get_checkout_uri());
1453 1453
 
1454 1454
     ob_start();
1455
-	    do_action( 'wpinv_checkout_content_before' );
1455
+	    do_action('wpinv_checkout_content_before');
1456 1456
         echo '<div id="wpinv_checkout_wrap">';
1457 1457
 
1458
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1458
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1459 1459
             ?>
1460 1460
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1461
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1461
+                <?php do_action('wpinv_before_checkout_form'); ?>
1462 1462
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1463 1463
                     <?php
1464
-                    do_action( 'wpinv_checkout_form_top' );
1465
-                    do_action( 'wpinv_checkout_billing_info' );
1466
-                    do_action( 'wpinv_checkout_cart' );
1467
-                    do_action( 'wpinv_payment_mode_select'  );
1468
-                    do_action( 'wpinv_checkout_form_bottom' )
1464
+                    do_action('wpinv_checkout_form_top');
1465
+                    do_action('wpinv_checkout_billing_info');
1466
+                    do_action('wpinv_checkout_cart');
1467
+                    do_action('wpinv_payment_mode_select');
1468
+                    do_action('wpinv_checkout_form_bottom')
1469 1469
                     ?>
1470 1470
                 </form>
1471
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1471
+                <?php do_action('wpinv_after_purchase_form'); ?>
1472 1472
             </div><!--end #wpinv_checkout_form_wrap-->
1473 1473
         <?php
1474 1474
         } else {
1475
-            do_action( 'wpinv_cart_empty' );
1475
+            do_action('wpinv_cart_empty');
1476 1476
         }
1477 1477
         echo '</div><!--end #wpinv_checkout_wrap-->';
1478
-	    do_action( 'wpinv_checkout_content_after' );
1478
+	    do_action('wpinv_checkout_content_after');
1479 1479
     return ob_get_clean();
1480 1480
 }
1481 1481
 
1482
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1482
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1483 1483
     global $ajax_cart_details;
1484 1484
     $ajax_cart_details = $cart_details;
1485 1485
 
1486 1486
     ob_start();
1487
-    do_action( 'wpinv_before_checkout_cart' );
1487
+    do_action('wpinv_before_checkout_cart');
1488 1488
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1489 1489
         echo '<div id="wpinv_checkout_cart_wrap">';
1490
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1490
+            wpinv_get_template_part('wpinv-checkout-cart');
1491 1491
         echo '</div>';
1492 1492
     echo '</div>';
1493
-    do_action( 'wpinv_after_checkout_cart' );
1493
+    do_action('wpinv_after_checkout_cart');
1494 1494
     $content = ob_get_clean();
1495 1495
 
1496
-    if ( $echo ) {
1496
+    if ($echo) {
1497 1497
         echo $content;
1498 1498
     } else {
1499 1499
         return $content;
1500 1500
     }
1501 1501
 }
1502
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1502
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1503 1503
 
1504 1504
 function wpinv_empty_cart_message() {
1505
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1505
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1506 1506
 }
1507 1507
 
1508 1508
 /**
@@ -1514,83 +1514,83 @@  discard block
 block discarded – undo
1514 1514
 function wpinv_empty_checkout_cart() {
1515 1515
 	echo wpinv_empty_cart_message();
1516 1516
 }
1517
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1517
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1518 1518
 
1519 1519
 function wpinv_update_cart_button() {
1520
-    if ( !wpinv_item_quantities_enabled() )
1520
+    if (!wpinv_item_quantities_enabled())
1521 1521
         return;
1522 1522
 ?>
1523
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1523
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1524 1524
     <input type="hidden" name="wpi_action" value="update_cart"/>
1525 1525
 <?php
1526 1526
 }
1527 1527
 
1528 1528
 function wpinv_checkout_cart_columns() {
1529 1529
     $default = 3;
1530
-    if ( wpinv_item_quantities_enabled() ) {
1530
+    if (wpinv_item_quantities_enabled()) {
1531 1531
         $default++;
1532 1532
     }
1533 1533
     
1534
-    if ( wpinv_use_taxes() ) {
1534
+    if (wpinv_use_taxes()) {
1535 1535
         $default++;
1536 1536
     }
1537 1537
 
1538
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1538
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_display_cart_messages() {
1542 1542
     global $wpi_session;
1543 1543
 
1544
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1544
+    $messages = $wpi_session->get('wpinv_cart_messages');
1545 1545
 
1546
-    if ( $messages ) {
1547
-        foreach ( $messages as $message_id => $message ) {
1546
+    if ($messages) {
1547
+        foreach ($messages as $message_id => $message) {
1548 1548
             // Try and detect what type of message this is
1549
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1549
+            if (strpos(strtolower($message), 'error')) {
1550 1550
                 $type = 'error';
1551
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1551
+            } elseif (strpos(strtolower($message), 'success')) {
1552 1552
                 $type = 'success';
1553 1553
             } else {
1554 1554
                 $type = 'info';
1555 1555
             }
1556 1556
 
1557
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1557
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1558 1558
 
1559
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1559
+            echo '<div class="' . implode(' ', $classes) . '">';
1560 1560
                 // Loop message codes and display messages
1561 1561
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1562 1562
             echo '</div>';
1563 1563
         }
1564 1564
 
1565 1565
         // Remove all of the cart saving messages
1566
-        $wpi_session->set( 'wpinv_cart_messages', null );
1566
+        $wpi_session->set('wpinv_cart_messages', null);
1567 1567
     }
1568 1568
 }
1569
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1569
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1570 1570
 
1571 1571
 function wpinv_discount_field() {
1572
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1572
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1573 1573
         return; // Only show before a payment method has been selected if ajax is disabled
1574 1574
     }
1575 1575
 
1576
-    if ( !wpinv_is_checkout() ) {
1576
+    if (!wpinv_is_checkout()) {
1577 1577
         return;
1578 1578
     }
1579 1579
 
1580
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1580
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1581 1581
     ?>
1582 1582
     <div id="wpinv-discount-field" class="panel panel-default">
1583 1583
         <div class="panel-body">
1584 1584
             <p>
1585
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1586
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1585
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1586
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1587 1587
             </p>
1588 1588
             <div class="form-group row">
1589 1589
                 <div class="col-sm-4">
1590
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1590
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1591 1591
                 </div>
1592 1592
                 <div class="col-sm-3">
1593
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1593
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1594 1594
                 </div>
1595 1595
                 <div style="clear:both"></div>
1596 1596
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1603,10 +1603,10 @@  discard block
 block discarded – undo
1603 1603
 <?php
1604 1604
     }
1605 1605
 }
1606
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1606
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1607 1607
 
1608 1608
 function wpinv_agree_to_terms_js() {
1609
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1609
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1610 1610
 ?>
1611 1611
 <script type="text/javascript">
1612 1612
     jQuery(document).ready(function($){
@@ -1621,125 +1621,125 @@  discard block
 block discarded – undo
1621 1621
 <?php
1622 1622
     }
1623 1623
 }
1624
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1624
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1625 1625
 
1626 1626
 function wpinv_payment_mode_select() {
1627
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1628
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1629
-    $invoice = wpinv_get_invoice( 0, true );
1627
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1628
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1629
+    $invoice = wpinv_get_invoice(0, true);
1630 1630
 
1631 1631
     do_action('wpinv_payment_mode_top');
1632
-    $invoice_id = $invoice ? (int)$invoice->ID : 0;
1633
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1632
+    $invoice_id = $invoice ? (int) $invoice->ID : 0;
1633
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1634 1634
     ?>
1635
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( ( $invoice && $invoice->is_free() ) ? 'style="display:none;" data-free="1"' : '' ); ?>>
1636
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1635
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo (($invoice && $invoice->is_free()) ? 'style="display:none;" data-free="1"' : ''); ?>>
1636
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1637 1637
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1638
-                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1638
+                <div class="panel-heading wpi-payment_methods_title"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1639 1639
                 <div class="panel-body list-group wpi-payment_methods">
1640 1640
                     <?php
1641
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1642
-
1643
-                    if ( !empty( $gateways ) ) {
1644
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1645
-                            $checked       = checked( $gateway_id, $chosen_gateway, false );
1646
-                            $button_label  = wpinv_get_gateway_button_label( $gateway_id );
1647
-                            $gateway_label = wpinv_get_gateway_checkout_label( $gateway_id );
1648
-                            $description   = wpinv_get_gateway_description( $gateway_id );
1641
+                    do_action('wpinv_payment_mode_before_gateways');
1642
+
1643
+                    if (!empty($gateways)) {
1644
+                        foreach ($gateways as $gateway_id => $gateway) {
1645
+                            $checked       = checked($gateway_id, $chosen_gateway, false);
1646
+                            $button_label  = wpinv_get_gateway_button_label($gateway_id);
1647
+                            $gateway_label = wpinv_get_gateway_checkout_label($gateway_id);
1648
+                            $description   = wpinv_get_gateway_description($gateway_id);
1649 1649
                             ?>
1650 1650
                             <div class="list-group-item">
1651 1651
                                 <div class="radio">
1652
-                                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway_label ); ?></label>
1652
+                                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway_label); ?></label>
1653 1653
                                 </div>
1654
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1655
-                                    <?php if ( !empty( $description ) ) { ?>
1656
-                                        <div class="wpi-gateway-desc alert alert-info"><?php _e( $description, 'invoicing' ); ?></div>
1654
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1655
+                                    <?php if (!empty($description)) { ?>
1656
+                                        <div class="wpi-gateway-desc alert alert-info"><?php _e($description, 'invoicing'); ?></div>
1657 1657
                                     <?php } ?>
1658
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1658
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1659 1659
                                 </div>
1660 1660
                             </div>
1661 1661
                             <?php
1662 1662
                         }
1663 1663
                     } else {
1664
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1664
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1665 1665
                     }
1666 1666
 
1667
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1667
+                    do_action('wpinv_payment_mode_after_gateways');
1668 1668
                     ?>
1669 1669
                 </div>
1670 1670
             </div>
1671
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1671
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1672 1672
     </div>
1673 1673
     <?php
1674 1674
     do_action('wpinv_payment_mode_bottom');
1675 1675
 }
1676
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1676
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1677 1677
 
1678 1678
 function wpinv_checkout_billing_info() {
1679
-    if ( wpinv_is_checkout() ) {
1679
+    if (wpinv_is_checkout()) {
1680 1680
         $billing_details    = wpinv_checkout_billing_details();
1681
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1681
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1682 1682
         ?>
1683 1683
         <div id="wpinv-fields" class="clearfix">
1684 1684
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1685
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1685
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1686 1686
                 <div id="wpinv-fields-box" class="panel-body">
1687
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1687
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1688 1688
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1689
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1689
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1690 1690
                         <?php
1691
-                        echo wpinv_html_text( array(
1691
+                        echo wpinv_html_text(array(
1692 1692
                                 'id'            => 'wpinv_first_name',
1693 1693
                                 'name'          => 'wpinv_first_name',
1694 1694
                                 'value'         => $billing_details['first_name'],
1695 1695
                                 'class'         => 'wpi-input form-control',
1696
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1697
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1698
-                            ) );
1696
+                                'placeholder'   => __('First name', 'invoicing'),
1697
+                                'required'      => (bool) wpinv_get_option('fname_mandatory'),
1698
+                            ));
1699 1699
                         ?>
1700 1700
                     </p>
1701 1701
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1702
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1702
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1703 1703
                         <?php
1704
-                        echo wpinv_html_text( array(
1704
+                        echo wpinv_html_text(array(
1705 1705
                                 'id'            => 'wpinv_last_name',
1706 1706
                                 'name'          => 'wpinv_last_name',
1707 1707
                                 'value'         => $billing_details['last_name'],
1708 1708
                                 'class'         => 'wpi-input form-control',
1709
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1710
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1711
-                            ) );
1709
+                                'placeholder'   => __('Last name', 'invoicing'),
1710
+                                'required'      => (bool) wpinv_get_option('lname_mandatory'),
1711
+                            ));
1712 1712
                         ?>
1713 1713
                     </p>
1714 1714
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1715
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1715
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1716 1716
                         <?php
1717
-                        echo wpinv_html_text( array(
1717
+                        echo wpinv_html_text(array(
1718 1718
                                 'id'            => 'wpinv_address',
1719 1719
                                 'name'          => 'wpinv_address',
1720 1720
                                 'value'         => $billing_details['address'],
1721 1721
                                 'class'         => 'wpi-input form-control',
1722
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1723
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1724
-                            ) );
1722
+                                'placeholder'   => __('Address', 'invoicing'),
1723
+                                'required'      => (bool) wpinv_get_option('address_mandatory'),
1724
+                            ));
1725 1725
                         ?>
1726 1726
                     </p>
1727 1727
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1728
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1728
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1729 1729
                         <?php
1730
-                        echo wpinv_html_text( array(
1730
+                        echo wpinv_html_text(array(
1731 1731
                                 'id'            => 'wpinv_city',
1732 1732
                                 'name'          => 'wpinv_city',
1733 1733
                                 'value'         => $billing_details['city'],
1734 1734
                                 'class'         => 'wpi-input form-control',
1735
-                                'placeholder'   => __( 'City', 'invoicing' ),
1736
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1737
-                            ) );
1735
+                                'placeholder'   => __('City', 'invoicing'),
1736
+                                'required'      => (bool) wpinv_get_option('city_mandatory'),
1737
+                            ));
1738 1738
                         ?>
1739 1739
                     </p>
1740 1740
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1741
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
-                        <?php echo wpinv_html_select( array(
1741
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1742
+                        <?php echo wpinv_html_select(array(
1743 1743
                             'options'          => wpinv_get_country_list(),
1744 1744
                             'name'             => 'wpinv_country',
1745 1745
                             'id'               => 'wpinv_country',
@@ -1747,16 +1747,16 @@  discard block
 block discarded – undo
1747 1747
                             'show_option_all'  => false,
1748 1748
                             'show_option_none' => false,
1749 1749
                             'class'            => 'wpi-input form-control wpi_select2',
1750
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1751
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1752
-                        ) ); ?>
1750
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1751
+                            'required'         => (bool) wpinv_get_option('country_mandatory'),
1752
+                        )); ?>
1753 1753
                     </p>
1754 1754
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1755
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1755
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1756 1756
                         <?php
1757
-                        $states = wpinv_get_country_states( $selected_country );
1758
-                        if( !empty( $states ) ) {
1759
-                            echo wpinv_html_select( array(
1757
+                        $states = wpinv_get_country_states($selected_country);
1758
+                        if (!empty($states)) {
1759
+                            echo wpinv_html_select(array(
1760 1760
                                 'options'          => $states,
1761 1761
                                 'name'             => 'wpinv_state',
1762 1762
                                 'id'               => 'wpinv_state',
@@ -1764,61 +1764,61 @@  discard block
 block discarded – undo
1764 1764
                                 'show_option_all'  => false,
1765 1765
                                 'show_option_none' => false,
1766 1766
                                 'class'            => 'wpi-input form-control wpi_select2',
1767
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1768
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1769
-                            ) );
1767
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1768
+                                'required'         => (bool) wpinv_get_option('state_mandatory'),
1769
+                            ));
1770 1770
                         } else {
1771
-                            echo wpinv_html_text( array(
1771
+                            echo wpinv_html_text(array(
1772 1772
                                 'name'          => 'wpinv_state',
1773 1773
                                 'value'         => $billing_details['state'],
1774 1774
                                 'id'            => 'wpinv_state',
1775 1775
                                 'class'         => 'wpi-input form-control',
1776
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1777
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1778
-                            ) );
1776
+                                'placeholder'   => __('State / Province', 'invoicing'),
1777
+                                'required'      => (bool) wpinv_get_option('state_mandatory'),
1778
+                            ));
1779 1779
                         }
1780 1780
                         ?>
1781 1781
                     </p>
1782 1782
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1783
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1783
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1784 1784
                         <?php
1785
-                        echo wpinv_html_text( array(
1785
+                        echo wpinv_html_text(array(
1786 1786
                                 'name'          => 'wpinv_zip',
1787 1787
                                 'value'         => $billing_details['zip'],
1788 1788
                                 'id'            => 'wpinv_zip',
1789 1789
                                 'class'         => 'wpi-input form-control',
1790
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1791
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1792
-                            ) );
1790
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1791
+                                'required'      => (bool) wpinv_get_option('zip_mandatory'),
1792
+                            ));
1793 1793
                         ?>
1794 1794
                     </p>
1795 1795
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1796
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1796
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1797 1797
                         <?php
1798
-                        echo wpinv_html_text( array(
1798
+                        echo wpinv_html_text(array(
1799 1799
                                 'id'            => 'wpinv_phone',
1800 1800
                                 'name'          => 'wpinv_phone',
1801 1801
                                 'value'         => $billing_details['phone'],
1802 1802
                                 'class'         => 'wpi-input form-control',
1803
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1804
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1805
-                            ) );
1803
+                                'placeholder'   => __('Phone', 'invoicing'),
1804
+                                'required'      => (bool) wpinv_get_option('phone_mandatory'),
1805
+                            ));
1806 1806
                         ?>
1807 1807
                     </p>
1808
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1808
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1809 1809
                     <div class="clearfix"></div>
1810 1810
                 </div>
1811 1811
             </div>
1812
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1812
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1813 1813
         </div>
1814 1814
         <?php
1815 1815
     }
1816 1816
 }
1817
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1817
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1818 1818
 
1819 1819
 function wpinv_checkout_hidden_fields() {
1820 1820
 ?>
1821
-    <?php if ( is_user_logged_in() ) { ?>
1821
+    <?php if (is_user_logged_in()) { ?>
1822 1822
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1823 1823
     <?php } ?>
1824 1824
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1828,9 +1828,9 @@  discard block
 block discarded – undo
1828 1828
 function wpinv_checkout_button_purchase() {
1829 1829
     ob_start();
1830 1830
 ?>
1831
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1831
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1832 1832
 <?php
1833
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1833
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1834 1834
 }
1835 1835
 
1836 1836
 function wpinv_checkout_total() {
@@ -1839,84 +1839,84 @@  discard block
 block discarded – undo
1839 1839
 <div id="wpinv_checkout_total" class="panel panel-info">
1840 1840
     <div class="panel-body">
1841 1841
     <?php
1842
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1842
+    do_action('wpinv_purchase_form_before_checkout_total');
1843 1843
     ?>
1844
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1844
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1845 1845
     <?php
1846
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1846
+    do_action('wpinv_purchase_form_after_checkout_total');
1847 1847
     ?>
1848 1848
     </div>
1849 1849
 </div>
1850 1850
 <?php
1851 1851
 }
1852
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1852
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1853 1853
 
1854 1854
 function wpinv_checkout_accept_tandc() {
1855
-    $page = wpinv_get_option( 'tandc_page' );
1855
+    $page = wpinv_get_option('tandc_page');
1856 1856
     ?>
1857 1857
     <div id="wpinv_checkout_tandc" class="panel panel-success">
1858 1858
         <div class="panel-body">
1859 1859
             <?php echo wpinv_get_policy_text(); ?>
1860 1860
             <?php
1861
-            if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1862
-                $terms_link = esc_url( get_permalink( $page ) );
1861
+            if (isset($page) && (int) $page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1862
+                $terms_link = esc_url(get_permalink($page));
1863 1863
                 ?>
1864 1864
                 <label class="">
1865
-                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked( apply_filters( 'wpinv_terms_is_checked_default', isset( $_POST['wpi_terms'] ) ), true ); ?>> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing' ), $terms_link ); ?></span> <span class="wpi-required">*</span>
1865
+                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked(apply_filters('wpinv_terms_is_checked_default', isset($_POST['wpi_terms'])), true); ?>> <span><?php printf(__('I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing'), $terms_link); ?></span> <span class="wpi-required">*</span>
1866 1866
                 </label>
1867 1867
             <?php } ?>
1868 1868
         </div>
1869 1869
     </div>
1870 1870
     <?php
1871 1871
 }
1872
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995 );
1872
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995);
1873 1873
 
1874 1874
 function wpinv_checkout_submit() {
1875 1875
 ?>
1876 1876
 <div id="wpinv_purchase_submit" class="panel panel-success">
1877 1877
     <div class="panel-body text-center">
1878 1878
     <?php
1879
-    do_action( 'wpinv_purchase_form_before_submit' );
1879
+    do_action('wpinv_purchase_form_before_submit');
1880 1880
     wpinv_checkout_hidden_fields();
1881 1881
     echo wpinv_checkout_button_purchase();
1882
-    do_action( 'wpinv_purchase_form_after_submit' );
1882
+    do_action('wpinv_purchase_form_after_submit');
1883 1883
     ?>
1884 1884
     </div>
1885 1885
 </div>
1886 1886
 <?php
1887 1887
 }
1888
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1888
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1889 1889
 
1890
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1891
-    $invoice = wpinv_get_invoice( $invoice_id );
1890
+function wpinv_receipt_billing_address($invoice_id = 0) {
1891
+    $invoice = wpinv_get_invoice($invoice_id);
1892 1892
 
1893
-    if ( empty( $invoice ) ) {
1893
+    if (empty($invoice)) {
1894 1894
         return NULL;
1895 1895
     }
1896 1896
 
1897 1897
     $billing_details = $invoice->get_user_info();
1898
-    $address_row = wpinv_get_invoice_address_markup( $billing_details );
1898
+    $address_row = wpinv_get_invoice_address_markup($billing_details);
1899 1899
 
1900 1900
     ob_start();
1901 1901
     ?>
1902 1902
     <table class="table table-bordered table-sm wpi-billing-details">
1903 1903
         <tbody>
1904 1904
             <tr class="wpi-receipt-name">
1905
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1906
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1905
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1906
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1907 1907
             </tr>
1908 1908
             <tr class="wpi-receipt-email">
1909
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1910
-                <td><?php echo $billing_details['email'] ;?></td>
1909
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1910
+                <td><?php echo $billing_details['email']; ?></td>
1911 1911
             </tr>
1912 1912
             <tr class="wpi-receipt-address">
1913
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1914
-                <td><?php echo $address_row ;?></td>
1913
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1914
+                <td><?php echo $address_row; ?></td>
1915 1915
             </tr>
1916
-            <?php if ( $billing_details['phone'] ) { ?>
1916
+            <?php if ($billing_details['phone']) { ?>
1917 1917
             <tr class="wpi-receipt-phone">
1918
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1919
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1918
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1919
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1920 1920
             </tr>
1921 1921
             <?php } ?>
1922 1922
         </tbody>
@@ -1924,74 +1924,74 @@  discard block
 block discarded – undo
1924 1924
     <?php
1925 1925
     $output = ob_get_clean();
1926 1926
     
1927
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1927
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1928 1928
 
1929 1929
     echo $output;
1930 1930
 }
1931 1931
 
1932
-function wpinv_filter_success_page_content( $content ) {
1933
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1934
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1935
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1932
+function wpinv_filter_success_page_content($content) {
1933
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1934
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1935
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1936 1936
         }
1937 1937
     }
1938 1938
 
1939 1939
     return $content;
1940 1940
 }
1941
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1941
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1942 1942
 
1943
-function wpinv_receipt_actions( $invoice ) {
1944
-    if ( !empty( $invoice ) ) {
1943
+function wpinv_receipt_actions($invoice) {
1944
+    if (!empty($invoice)) {
1945 1945
         $actions = array();
1946 1946
 
1947
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1948
-            $actions['print']   = array(
1949
-                'url'  => $invoice->get_view_url( true ),
1950
-                'name' => __( 'Print Invoice', 'invoicing' ),
1947
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1948
+            $actions['print'] = array(
1949
+                'url'  => $invoice->get_view_url(true),
1950
+                'name' => __('Print Invoice', 'invoicing'),
1951 1951
                 'class' => 'btn-primary',
1952 1952
             );
1953 1953
         }
1954 1954
 
1955
-        if ( is_user_logged_in() ) {
1955
+        if (is_user_logged_in()) {
1956 1956
             $actions['history'] = array(
1957 1957
                 'url'  => wpinv_get_history_page_uri(),
1958
-                'name' => __( 'Invoice History', 'invoicing' ),
1958
+                'name' => __('Invoice History', 'invoicing'),
1959 1959
                 'class' => 'btn-warning',
1960 1960
             );
1961 1961
         }
1962 1962
 
1963
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1963
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1964 1964
 
1965
-        if ( !empty( $actions ) ) {
1965
+        if (!empty($actions)) {
1966 1966
         ?>
1967 1967
         <div class="wpinv-receipt-actions text-right">
1968
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1969
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1968
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1969
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1970 1970
             <?php } ?>
1971 1971
         </div>
1972 1972
         <?php
1973 1973
         }
1974 1974
     }
1975 1975
 }
1976
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1976
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1977 1977
 
1978
-function wpinv_invoice_link( $invoice_id ) {
1979
-    $invoice = wpinv_get_invoice( $invoice_id );
1978
+function wpinv_invoice_link($invoice_id) {
1979
+    $invoice = wpinv_get_invoice($invoice_id);
1980 1980
 
1981
-    if ( empty( $invoice ) ) {
1981
+    if (empty($invoice)) {
1982 1982
         return NULL;
1983 1983
     }
1984 1984
 
1985
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1985
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1986 1986
 
1987
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1987
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1988 1988
 }
1989 1989
 
1990
-function wpinv_invoice_subscription_details( $invoice ) {
1991
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1992
-        $subscription = wpinv_get_subscription( $invoice, true );
1990
+function wpinv_invoice_subscription_details($invoice) {
1991
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1992
+        $subscription = wpinv_get_subscription($invoice, true);
1993 1993
 
1994
-        if ( empty( $subscription ) ) {
1994
+        if (empty($subscription)) {
1995 1995
             return;
1996 1996
         }
1997 1997
 
@@ -2002,15 +2002,15 @@  discard block
 block discarded – undo
2002 2002
         $payments = $subscription->get_child_payments();
2003 2003
         ?>
2004 2004
         <div class="wpinv-subscriptions-details">
2005
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
2005
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
2006 2006
             <table class="table">
2007 2007
                 <thead>
2008 2008
                     <tr>
2009
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
2010
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
2011
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
2012
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
2013
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
2009
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
2010
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
2011
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
2012
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
2013
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
2014 2014
                     </tr>
2015 2015
                 </thead>
2016 2016
                 <tbody>
@@ -2024,29 +2024,29 @@  discard block
 block discarded – undo
2024 2024
                 </tbody>
2025 2025
             </table>
2026 2026
         </div>
2027
-        <?php if ( !empty( $payments ) ) { ?>
2027
+        <?php if (!empty($payments)) { ?>
2028 2028
         <div class="wpinv-renewal-payments">
2029
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
2029
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
2030 2030
             <table class="table">
2031 2031
                 <thead>
2032 2032
                     <tr>
2033 2033
                         <th>#</th>
2034
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
2035
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
2036
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
2034
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
2035
+                        <th><?php _e('Date', 'invoicing'); ?></th>
2036
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
2037 2037
                     </tr>
2038 2038
                 </thead>
2039 2039
                 <tbody>
2040 2040
                     <?php
2041 2041
                         $i = 1;
2042
-                        foreach ( $payments as $payment ) {
2042
+                        foreach ($payments as $payment) {
2043 2043
                             $invoice_id = $payment->ID;
2044 2044
                     ?>
2045 2045
                     <tr>
2046
-                        <th scope="row"><?php echo $i;?></th>
2047
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2048
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2049
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2046
+                        <th scope="row"><?php echo $i; ?></th>
2047
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2048
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2049
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2050 2050
                     </tr>
2051 2051
                     <?php $i++; } ?>
2052 2052
                 </tbody>
@@ -2057,52 +2057,52 @@  discard block
 block discarded – undo
2057 2057
     }
2058 2058
 }
2059 2059
 
2060
-function wpinv_cart_total_label( $label, $invoice ) {
2061
-    if ( empty( $invoice ) ) {
2060
+function wpinv_cart_total_label($label, $invoice) {
2061
+    if (empty($invoice)) {
2062 2062
         return $label;
2063 2063
     }
2064 2064
 
2065 2065
     $prefix_label = '';
2066
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
2067
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2068
-    } else if ( $invoice->is_renewal() ) {
2069
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2066
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
2067
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2068
+    } else if ($invoice->is_renewal()) {
2069
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2070 2070
     }
2071 2071
 
2072
-    if ( $prefix_label != '' ) {
2073
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2072
+    if ($prefix_label != '') {
2073
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2074 2074
     }
2075 2075
 
2076 2076
     return $label;
2077 2077
 }
2078
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2079
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2080
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2078
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2079
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2080
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2081 2081
 
2082
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2082
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2083 2083
 
2084
-function wpinv_invoice_print_description( $invoice ) {
2085
-    if ( empty( $invoice ) ) {
2084
+function wpinv_invoice_print_description($invoice) {
2085
+    if (empty($invoice)) {
2086 2086
         return NULL;
2087 2087
     }
2088
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2088
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2089 2089
         ?>
2090 2090
         <div class="row wpinv-lower">
2091 2091
             <div class="col-sm-12 wpinv-description">
2092
-                <?php echo wpautop( $description ); ?>
2092
+                <?php echo wpautop($description); ?>
2093 2093
             </div>
2094 2094
         </div>
2095 2095
         <?php
2096 2096
     }
2097 2097
 }
2098
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2098
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2099 2099
 
2100
-function wpinv_invoice_print_payment_info( $invoice ) {
2101
-    if ( empty( $invoice ) ) {
2100
+function wpinv_invoice_print_payment_info($invoice) {
2101
+    if (empty($invoice)) {
2102 2102
         return NULL;
2103 2103
     }
2104 2104
 
2105
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2105
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2106 2106
         ?>
2107 2107
         <div class="row wpinv-payments">
2108 2108
             <div class="col-sm-12">
@@ -2114,43 +2114,43 @@  discard block
 block discarded – undo
2114 2114
 }
2115 2115
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2116 2116
 
2117
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2118
-    if ( empty( $note ) ) {
2117
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2118
+    if (empty($note)) {
2119 2119
         return NULL;
2120 2120
     }
2121 2121
 
2122
-    if ( is_int( $note ) ) {
2123
-        $note = get_comment( $note );
2122
+    if (is_int($note)) {
2123
+        $note = get_comment($note);
2124 2124
     }
2125 2125
 
2126
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2126
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2127 2127
         return NULL;
2128 2128
     }
2129 2129
 
2130
-    $note_classes   = array( 'note' );
2131
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2130
+    $note_classes   = array('note');
2131
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2132 2132
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2133
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2134
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2133
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2134
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2135 2135
 
2136 2136
     ob_start();
2137 2137
     ?>
2138
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2138
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2139 2139
         <div class="note_content">
2140
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2140
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2141 2141
         </div>
2142 2142
         <p class="meta">
2143
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2144
-            <?php if ( is_admin() && ( $note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing() ) ) { ?>
2145
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2143
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2144
+            <?php if (is_admin() && ($note->comment_author !== 'System' || wpinv_current_user_can_manage_invoicing())) { ?>
2145
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2146 2146
             <?php } ?>
2147 2147
         </p>
2148 2148
     </li>
2149 2149
     <?php
2150 2150
     $note_content = ob_get_clean();
2151
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2151
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2152 2152
 
2153
-    if ( $echo ) {
2153
+    if ($echo) {
2154 2154
         echo $note_content;
2155 2155
     } else {
2156 2156
         return $note_content;
@@ -2160,43 +2160,43 @@  discard block
 block discarded – undo
2160 2160
 function wpinv_invalid_invoice_content() {
2161 2161
     global $post;
2162 2162
 
2163
-    $invoice = wpinv_get_invoice( $post->ID );
2163
+    $invoice = wpinv_get_invoice($post->ID);
2164 2164
 
2165
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing' );
2166
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2167
-        if ( is_user_logged_in() ) {
2168
-            if ( wpinv_require_login_to_checkout() ) {
2169
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2170
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2165
+    $error = __('This invoice is only viewable by clicking on the invoice link that was sent to you via email.', 'invoicing');
2166
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2167
+        if (is_user_logged_in()) {
2168
+            if (wpinv_require_login_to_checkout()) {
2169
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2170
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2171 2171
                 }
2172 2172
             }
2173 2173
         } else {
2174
-            if ( wpinv_require_login_to_checkout() ) {
2175
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2176
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2174
+            if (wpinv_require_login_to_checkout()) {
2175
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2176
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2177 2177
                 }
2178 2178
             }
2179 2179
         }
2180 2180
     } else {
2181
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2181
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2182 2182
     }
2183 2183
     ?>
2184 2184
     <div class="row wpinv-row-invalid">
2185 2185
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2186
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2186
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2187 2187
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2188 2188
         </div>
2189 2189
     </div>
2190 2190
     <?php
2191 2191
 }
2192
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2192
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2193 2193
 
2194
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
-function wpinv_force_company_name_field(){
2194
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2195
+function wpinv_force_company_name_field() {
2196 2196
     $invoice = wpinv_get_invoice_cart();
2197
-    $user_id = wpinv_get_user_id( $invoice->ID );
2198
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2199
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2197
+    $user_id = wpinv_get_user_id($invoice->ID);
2198
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2199
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2200 2200
         ?>
2201 2201
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2202 2202
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2222,21 +2222,21 @@  discard block
 block discarded – undo
2222 2222
  * @return string
2223 2223
  */
2224 2224
 function wpinv_get_policy_text() {
2225
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2225
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2226 2226
 
2227
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
2227
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
2228 2228
 
2229
-    if(!$privacy_page_id){
2230
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2229
+    if (!$privacy_page_id) {
2230
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2231 2231
     }
2232 2232
 
2233
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
2233
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
2234 2234
 
2235 2235
     $find_replace = array(
2236 2236
         '[wpinv_privacy_policy]' => $privacy_link,
2237 2237
     );
2238 2238
 
2239
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2239
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2240 2240
 
2241 2241
     return wp_kses_post(wpautop($privacy_text));
2242 2242
 }
@@ -2245,25 +2245,25 @@  discard block
 block discarded – undo
2245 2245
 /**
2246 2246
  * Allows the user to set their own price for an invoice item
2247 2247
  */
2248
-function wpinv_checkout_cart_item_name_your_price( $cart_item, $key ) {
2248
+function wpinv_checkout_cart_item_name_your_price($cart_item, $key) {
2249 2249
     
2250 2250
     //Ensure we have an item id
2251
-    if(! is_array( $cart_item ) || empty( $cart_item['id'] ) ) {
2251
+    if (!is_array($cart_item) || empty($cart_item['id'])) {
2252 2252
         return;
2253 2253
     }
2254 2254
 
2255 2255
     //Fetch the item
2256 2256
     $item_id = $cart_item['id'];
2257
-    $item    = new WPInv_Item( $item_id );
2257
+    $item    = new WPInv_Item($item_id);
2258 2258
     
2259
-    if(! $item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing() ) {
2259
+    if (!$item->supports_dynamic_pricing() || !$item->get_is_dynamic_pricing()) {
2260 2260
         return;
2261 2261
     }
2262 2262
 
2263 2263
     //Fetch the dynamic pricing "strings"
2264
-    $suggested_price_text = esc_html( wpinv_get_option( 'suggested_price_text', __( 'Suggested Price:', 'invoicing' ) ) );
2265
-    $minimum_price_text   = esc_html( wpinv_get_option( 'minimum_price_text', __( 'Minimum Price:', 'invoicing' ) ) );
2266
-    $name_your_price_text = esc_html( wpinv_get_option( 'name_your_price_text', __( 'Name Your Price', 'invoicing' ) ) );
2264
+    $suggested_price_text = esc_html(wpinv_get_option('suggested_price_text', __('Suggested Price:', 'invoicing')));
2265
+    $minimum_price_text   = esc_html(wpinv_get_option('minimum_price_text', __('Minimum Price:', 'invoicing')));
2266
+    $name_your_price_text = esc_html(wpinv_get_option('name_your_price_text', __('Name Your Price', 'invoicing')));
2267 2267
 
2268 2268
     //Display a "name_your_price" button
2269 2269
     echo " &mdash; <a href='#' class='wpinv-name-your-price-frontend small'>$name_your_price_text</a></div>";
@@ -2272,7 +2272,7 @@  discard block
 block discarded – undo
2272 2272
     echo '<div class="name-your-price-miniform">';
2273 2273
     
2274 2274
     //Maybe display the recommended price
2275
-    if( $item->get_price() > 0 && !empty( $suggested_price_text ) ) {
2275
+    if ($item->get_price() > 0 && !empty($suggested_price_text)) {
2276 2276
         $suggested_price = $item->get_the_price();
2277 2277
         echo "<div>$suggested_price_text &mdash; $suggested_price</div>";
2278 2278
     }
@@ -2280,50 +2280,50 @@  discard block
 block discarded – undo
2280 2280
     //Display the update price form
2281 2281
     $symbol         = wpinv_currency_symbol();
2282 2282
     $position       = wpinv_currency_position();
2283
-    $minimum        = esc_attr( $item->get_minimum_price() );
2284
-    $price          = esc_attr( $cart_item['item_price'] );
2285
-    $update         = esc_attr__( "Update", 'invoicing' );
2283
+    $minimum        = esc_attr($item->get_minimum_price());
2284
+    $price          = esc_attr($cart_item['item_price']);
2285
+    $update         = esc_attr__("Update", 'invoicing');
2286 2286
 
2287 2287
     //Ensure it supports dynamic prici
2288
-    if( $price < $minimum ) {
2288
+    if ($price < $minimum) {
2289 2289
         $price = $minimum;
2290 2290
     }
2291 2291
 
2292 2292
     echo '<label>';
2293 2293
     echo $position != 'right' ? $symbol . '&nbsp;' : '';
2294 2294
     echo "<input type='number' min='$minimum' placeholder='$price' value='$price' class='wpi-field-price' />";
2295
-    echo $position == 'right' ? '&nbsp;' . $symbol : '' ;
2295
+    echo $position == 'right' ? '&nbsp;' . $symbol : '';
2296 2296
     echo "</label>";
2297 2297
     echo "<input type='hidden' value='$item_id' class='wpi-field-item' />";
2298 2298
     echo "<a class='btn btn-success wpinv-submit wpinv-update-dynamic-price-frontend'>$update</a>";
2299 2299
 
2300 2300
     //Maybe display the minimum price
2301
-    if( $item->get_minimum_price() > 0 && !empty( $minimum_price_text ) ) {
2302
-        $minimum_price = wpinv_price( wpinv_format_amount( $item->get_minimum_price() ) );
2301
+    if ($item->get_minimum_price() > 0 && !empty($minimum_price_text)) {
2302
+        $minimum_price = wpinv_price(wpinv_format_amount($item->get_minimum_price()));
2303 2303
         echo "<div>$minimum_price_text &mdash; $minimum_price</div>";
2304 2304
     }
2305 2305
 
2306 2306
     echo "</div>";
2307 2307
 
2308 2308
 }
2309
-add_action( 'wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2 );
2309
+add_action('wpinv_checkout_cart_item_price_after', 'wpinv_checkout_cart_item_name_your_price', 10, 2);
2310 2310
 
2311 2311
 function wpinv_oxygen_fix_conflict() {
2312 2312
     global $ct_ignore_post_types;
2313 2313
 
2314
-    if ( ! is_array( $ct_ignore_post_types ) ) {
2314
+    if (!is_array($ct_ignore_post_types)) {
2315 2315
         $ct_ignore_post_types = array();
2316 2316
     }
2317 2317
 
2318
-    $post_types = array( 'wpi_discount', 'wpi_invoice', 'wpi_item' );
2318
+    $post_types = array('wpi_discount', 'wpi_invoice', 'wpi_item');
2319 2319
 
2320
-    foreach ( $post_types as $post_type ) {
2320
+    foreach ($post_types as $post_type) {
2321 2321
         $ct_ignore_post_types[] = $post_type;
2322 2322
 
2323 2323
         // Ignore post type
2324
-        add_filter( 'pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999 );
2324
+        add_filter('pre_option_oxygen_vsb_ignore_post_type_' . $post_type, '__return_true', 999);
2325 2325
     }
2326 2326
 
2327
-    remove_filter( 'template_include', 'wpinv_template', 10, 1 );
2328
-    add_filter( 'template_include', 'wpinv_template', 999, 1 );
2327
+    remove_filter('template_include', 'wpinv_template', 10, 1);
2328
+    add_filter('template_include', 'wpinv_template', 999, 1);
2329 2329
 }
Please login to merge, or discard this patch.
widgets/payment-form.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
     exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 				'orderby'        => 'title',
23 23
 				'order'          => 'ASC',
24 24
 				'posts_per_page' => -1,
25
-				'post_status'    => array( 'publish' ),
25
+				'post_status'    => array('publish'),
26 26
 			)
27 27
 		);
28 28
 
29 29
 		$options = array(
30
-			'' => __('Select a Form','invoicing')
30
+			'' => __('Select a Form', 'invoicing')
31 31
 		);
32 32
 
33
-		foreach( $forms as $form ) {
34
-			$options[ $form->ID ] = $form->post_title;
33
+		foreach ($forms as $form) {
34
+			$options[$form->ID] = $form->post_title;
35 35
 		}
36 36
 
37 37
         $options = array(
@@ -41,15 +41,15 @@  discard block
 block discarded – undo
41 41
             'block-keywords'=> "['invoicing','buy', 'buy item', 'pay', 'payment form']",
42 42
             'class_name'     => __CLASS__,
43 43
             'base_id'       => 'wpinv_payment_form',
44
-            'name'          => __('Invoicing > Payment Form','invoicing'),
44
+            'name'          => __('Invoicing > Payment Form', 'invoicing'),
45 45
             'widget_ops'    => array(
46 46
                 'classname'   => 'wpinv-payment-form-class bsui',
47
-                'description' => esc_html__('Displays a payment form.','invoicing'),
47
+                'description' => esc_html__('Displays a payment form.', 'invoicing'),
48 48
             ),
49 49
             'arguments'           => array(
50 50
                 'form'            => array(
51
-                    'title'       => __( 'Payment Form', 'invoicing' ),
52
-                    'desc'        => __( 'Select your payment form.', 'invoicing' ),
51
+                    'title'       => __('Payment Form', 'invoicing'),
52
+                    'desc'        => __('Select your payment form.', 'invoicing'),
53 53
 					'type'        => 'select',
54 54
 					'options'     =>  $options,
55 55
                     'desc_tip'    => true,
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
         );
62 62
 
63 63
 
64
-        parent::__construct( $options );
64
+        parent::__construct($options);
65 65
     }
66 66
 
67 67
 	/**
@@ -73,43 +73,43 @@  discard block
 block discarded – undo
73 73
 	 *
74 74
 	 * @return string
75 75
 	 */
76
-    public function output( $args = array(), $widget_args = array(), $content = '' ) {
76
+    public function output($args = array(), $widget_args = array(), $content = '') {
77 77
 		global $invoicing;
78 78
 
79 79
 		// Do we have a payment form?
80
-		if ( empty( $args['form'] ) ) {
80
+		if (empty($args['form'])) {
81 81
 			return aui()->alert(
82 82
 				array(
83 83
 					'type'    => 'warning',
84
-					'content' => __( 'No payment form selected', 'invoicing' ),
84
+					'content' => __('No payment form selected', 'invoicing'),
85 85
 				)
86 86
 			);
87 87
 
88 88
 		}
89 89
 
90 90
 		// If yes, ensure that it is published.
91
-		if ( 'publish' != get_post_status( $args['form'] ) ) {
91
+		if ('publish' != get_post_status($args['form'])) {
92 92
 			return aui()->alert(
93 93
 				array(
94 94
 					'type'    => 'warning',
95
-					'content' => __( 'This payment form is no longer active', 'invoicing' ),
95
+					'content' => __('This payment form is no longer active', 'invoicing'),
96 96
 				)
97 97
 			);
98 98
 		}
99 99
 
100 100
 		// Get the form elements and items.
101
-		$elements = $invoicing->form_elements->get_form_elements( $args['form'] );
102
-		$items    = $invoicing->form_elements->get_form_items( $args['form'] );
101
+		$elements = $invoicing->form_elements->get_form_elements($args['form']);
102
+		$items    = $invoicing->form_elements->get_form_items($args['form']);
103 103
 
104 104
 		ob_start();
105 105
 		echo "<form class='wpinv_payment_form'>";
106 106
 		echo "<input type='hidden' name='form_id' value='{$args['form']}'/>";
107
-		wp_nonce_field( 'wpinv_payment_form', 'wpinv_payment_form' );
108
-		wp_nonce_field( 'vat_validation', '_wpi_nonce' );
107
+		wp_nonce_field('wpinv_payment_form', 'wpinv_payment_form');
108
+		wp_nonce_field('vat_validation', '_wpi_nonce');
109 109
 
110
-		foreach ( $elements as $element ) {
111
-			do_action( 'wpinv_frontend_render_payment_form_element', $element, $items, $args['form'] );
112
-			do_action( "wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form'] );
110
+		foreach ($elements as $element) {
111
+			do_action('wpinv_frontend_render_payment_form_element', $element, $items, $args['form']);
112
+			do_action("wpinv_frontend_render_payment_form_{$element['type']}", $element, $items, $args['form']);
113 113
 		}
114 114
 
115 115
 		echo "<div class='wpinv_payment_form_errors alert alert-danger d-none'></div>";
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 
118 118
 		$content = ob_get_clean();
119 119
 		
120
-		return str_replace( 'sr-only', '', $content );
120
+		return str_replace('sr-only', '', $content);
121 121
 
122 122
     }
123 123
 
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +725 added lines, -725 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,137 +17,137 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
90
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
91 91
             self::load_vat_scripts();
92 92
         }
93 93
     }
94 94
 
95
-    public static function load_vat_scripts(){
96
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95
+    public static function load_vat_scripts() {
96
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
97 97
 
98
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
99
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
98
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
99
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
100 100
 
101
-        $vat_name   = self::get_vat_name();
101
+        $vat_name = self::get_vat_name();
102 102
 
103 103
         $vars = array();
104 104
         $vars['UseTaxes'] = wpinv_use_taxes();
105 105
         $vars['EUStates'] = self::get_eu_states();
106
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
107
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
108
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
109
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
110
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
111
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
112
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
113
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
106
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
107
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
108
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
109
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
110
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
111
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
112
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
113
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
114 114
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
115 115
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
116
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
117
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
118
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
119
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
120
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
121
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
122
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
123
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
124
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
125
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
126
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
127
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
128
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
116
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
117
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
118
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
119
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
120
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
121
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
122
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
123
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
124
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
125
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
126
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
127
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
128
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
129 129
         $vars['isFront'] = is_admin() ? false : true;
130 130
         $vars['baseCountry'] = wpinv_get_default_country();
131
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
132
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
131
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
132
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
133 133
 
134
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
135
-        wp_enqueue_script( 'wpinv-vat-script' );
136
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
134
+        wp_enqueue_script('wpinv-vat-validation-script');
135
+        wp_enqueue_script('wpinv-vat-script');
136
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
137 137
     }
138 138
 
139 139
     public static function enqueue_admin_scripts() {
140
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
140
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
141 141
             self::load_vat_scripts();
142 142
         }
143 143
     }
144 144
     
145
-    public static function section_vat_settings( $sections ) {
146
-        if ( !empty( $sections ) ) {
147
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
145
+    public static function section_vat_settings($sections) {
146
+        if (!empty($sections)) {
147
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
148 148
             
149
-            if ( self::allow_vat_classes() ) {
150
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
149
+            if (self::allow_vat_classes()) {
150
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
151 151
             }
152 152
         }
153 153
         return $sections;
@@ -156,52 +156,52 @@  discard block
 block discarded – undo
156 156
     public static function vat_rates_settings() {
157 157
         $vat_classes = self::get_rate_classes();
158 158
         $vat_rates = array();
159
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
160
-        $current_url = remove_query_arg( 'wpi_sub' );
159
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
160
+        $current_url = remove_query_arg('wpi_sub');
161 161
         
162 162
         $vat_rates['vat_rates_header'] = array(
163 163
             'id' => 'vat_rates_header',
164
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
164
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
165 165
             'desc' => '',
166 166
             'type' => 'header',
167 167
             'size' => 'regular'
168 168
         );
169 169
         $vat_rates['vat_rates_class'] = array(
170 170
             'id'          => 'vat_rates_class',
171
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
172
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
171
+            'name'        => __('Edit VAT Rates', 'invoicing'),
172
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
173 173
             'type'        => 'select',
174
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
175
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
174
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
175
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
176 176
             'selected'    => $vat_class,
177 177
             'class'       => 'wpi_select2',
178 178
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
179 179
         );
180 180
         
181
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
181
+        if ($vat_class != '_standard' && $vat_class != '_new') {
182 182
             $vat_rates['vat_rate_delete'] = array(
183 183
                 'id'   => 'vat_rate_delete',
184 184
                 'type' => 'vat_rate_delete',
185 185
             );
186 186
         }
187 187
                     
188
-        if ( $vat_class == '_new' ) {
188
+        if ($vat_class == '_new') {
189 189
             $vat_rates['vat_rates_settings'] = array(
190 190
                 'id' => 'vat_rates_settings',
191
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
191
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
192 192
                 'type' => 'header',
193 193
             );
194 194
             $vat_rates['vat_rate_name'] = array(
195 195
                 'id'   => 'vat_rate_name',
196
-                'name' => __( 'Name', 'invoicing' ),
197
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
196
+                'name' => __('Name', 'invoicing'),
197
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
198 198
                 'type' => 'text',
199 199
                 'size' => 'regular',
200 200
             );
201 201
             $vat_rates['vat_rate_desc'] = array(
202 202
                 'id'   => 'vat_rate_desc',
203
-                'name' => __( 'Description', 'invoicing' ),
204
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
203
+                'name' => __('Description', 'invoicing'),
204
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
205 205
                 'type' => 'text',
206 206
                 'size' => 'regular',
207 207
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             $vat_rates['vat_rates'] = array(
214 214
                 'id'   => 'vat_rates',
215 215
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
216
-                'desc' => self::get_class_desc( $vat_class ),
216
+                'desc' => self::get_class_desc($vat_class),
217 217
                 'type' => 'vat_rates',
218 218
             );
219 219
         }
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
         return $vat_rates;
222 222
     }
223 223
     
224
-    public static function vat_settings( $settings ) {
225
-        if ( !empty( $settings ) ) {    
224
+    public static function vat_settings($settings) {
225
+        if (!empty($settings)) {    
226 226
             $vat_settings = array();
227 227
             $vat_settings['vat_company_title'] = array(
228 228
                 'id' => 'vat_company_title',
229
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
229
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
230 230
                 'desc' => '',
231 231
                 'type' => 'header',
232 232
                 'size' => 'regular'
@@ -234,22 +234,22 @@  discard block
 block discarded – undo
234 234
             
235 235
             $vat_settings['vat_company_name'] = array(
236 236
                 'id' => 'vat_company_name',
237
-                'name' => __( 'Your Company Name', 'invoicing' ),
238
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
237
+                'name' => __('Your Company Name', 'invoicing'),
238
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
239 239
                 'type' => 'text',
240 240
                 'size' => 'regular',
241 241
             );
242 242
             
243 243
             $vat_settings['vat_number'] = array(
244 244
                 'id'   => 'vat_number',
245
-                'name' => __( 'Your VAT Number', 'invoicing' ),
245
+                'name' => __('Your VAT Number', 'invoicing'),
246 246
                 'type' => 'vat_number',
247 247
                 'size' => 'regular',
248 248
             );
249 249
 
250 250
             $vat_settings['vat_settings_title'] = array(
251 251
                 'id' => 'vat_settings_title',
252
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
252
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
253 253
                 'desc' => '',
254 254
                 'type' => 'header',
255 255
                 'size' => 'regular'
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 
258 258
             $vat_settings['apply_vat_rules'] = array(
259 259
                 'id' => 'apply_vat_rules',
260
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
261
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
260
+                'name' => __('Enable VAT Rules', 'invoicing'),
261
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
262 262
                 'type' => 'checkbox',
263 263
                 'std' => '1'
264 264
             );
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 
275 275
             $vat_settings['vat_prevent_b2c_purchase'] = array(
276 276
                 'id' => 'vat_prevent_b2c_purchase',
277
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
278
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
277
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
278
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
279 279
                 'type' => 'checkbox'
280 280
             );
281 281
 
@@ -283,22 +283,22 @@  discard block
 block discarded – undo
283 283
 
284 284
             $vat_settings['vat_same_country_rule'] = array(
285 285
                 'id'          => 'vat_same_country_rule',
286
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
287
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
286
+                'name'        => __('Same Country Rule', 'invoicing'),
287
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
288 288
                 'type'        => 'select',
289 289
                 'options'     => array(
290
-                    ''          => __( 'Normal', 'invoicing' ),
291
-                    'no'        => __( 'No VAT', 'invoicing' ),
292
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
290
+                    ''          => __('Normal', 'invoicing'),
291
+                    'no'        => __('No VAT', 'invoicing'),
292
+                    'always'    => __('Always apply VAT', 'invoicing'),
293 293
                 ),
294
-                'placeholder' => __( 'Select an option', 'invoicing' ),
294
+                'placeholder' => __('Select an option', 'invoicing'),
295 295
                 'std'         => '',
296 296
                 'class'   => 'wpi_select2',
297 297
             );
298 298
 
299 299
             $vat_settings['vat_checkout_title'] = array(
300 300
                 'id' => 'vat_checkout_title',
301
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
301
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
302 302
                 'desc' => '',
303 303
                 'type' => 'header',
304 304
                 'size' => 'regular'
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 
307 307
             $vat_settings['vat_disable_fields'] = array(
308 308
                 'id' => 'vat_disable_fields',
309
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
310
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
309
+                'name' => __('Disable VAT Fields', 'invoicing'),
310
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
311 311
                 'type' => 'checkbox'
312 312
             );
313 313
 
314 314
             $vat_settings['vat_ip_lookup'] = array(
315 315
                 'id'   => 'vat_ip_lookup',
316
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
316
+                'name' => __('IP Country Look-up', 'invoicing'),
317 317
                 'type' => 'vat_ip_lookup',
318 318
                 'size' => 'regular',
319 319
                 'std' => 'default',
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 
323 323
             $vat_settings['hide_ip_address'] = array(
324 324
                 'id' => 'hide_ip_address',
325
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
326
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
325
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
326
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vat_ip_country_default'] = array(
331 331
                 'id' => 'vat_ip_country_default',
332
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
333
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
332
+                'name' => __('Enable IP Country as Default', 'invoicing'),
333
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
334 334
                 'type' => 'checkbox'
335 335
             );
336 336
 
337 337
             $vat_settings['vies_validation_title'] = array(
338 338
                 'id' => 'vies_validation_title',
339
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
339
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
340 340
                 'desc' => '',
341 341
                 'type' => 'header',
342 342
                 'size' => 'regular'
@@ -344,37 +344,37 @@  discard block
 block discarded – undo
344 344
 
345 345
             $vat_settings['vat_vies_check'] = array(
346 346
                 'id' => 'vat_vies_check',
347
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
348
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
347
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
348
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_disable_company_name_check'] = array(
353 353
                 'id' => 'vat_disable_company_name_check',
354
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
355
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
354
+                'name' => __('Disable VIES Name Check', 'invoicing'),
355
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
 
359 359
             $vat_settings['vat_offline_check'] = array(
360 360
                 'id' => 'vat_offline_check',
361
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
362
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
361
+                'name' => __('Disable Basic Checks', 'invoicing'),
362
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
363 363
                 'type' => 'checkbox'
364 364
             );
365 365
             
366 366
 
367 367
             $settings['vat'] = $vat_settings;
368 368
             
369
-            if ( self::allow_vat_classes() ) {
369
+            if (self::allow_vat_classes()) {
370 370
                 $settings['vat_rates'] = self::vat_rates_settings();
371 371
             }
372 372
             
373 373
             $eu_fallback_rate = array(
374 374
                 'id'   => 'eu_fallback_rate',
375
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
375
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
376 376
                 'type' => 'eu_fallback_rate',
377
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
377
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
378 378
                 'std'  => '20',
379 379
                 'size' => 'small'
380 380
             );
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
391 391
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
392 392
         
393
-        if ( !is_dir( $destination_dir ) ) { 
394
-            mkdir( $destination_dir );
393
+        if (!is_dir($destination_dir)) { 
394
+            mkdir($destination_dir);
395 395
         }
396 396
         
397
-        $database_files     = array(
397
+        $database_files = array(
398 398
             'country'   => array(
399 399
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
400 400
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -405,57 +405,57 @@  discard block
 block discarded – undo
405 405
             )
406 406
         );
407 407
 
408
-        foreach( $database_files as $database => $files ) {
409
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
408
+        foreach ($database_files as $database => $files) {
409
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
410 410
             
411
-            if ( empty( $result['success'] ) ) {
411
+            if (empty($result['success'])) {
412 412
                 echo $result['message'];
413 413
                 exit;
414 414
             }
415 415
             
416
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
417
-            echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
416
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
417
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
418 418
         }
419 419
         
420 420
         exit;
421 421
     }
422 422
     
423
-    public static function geoip2_download_file( $source_url, $destination_file ) {
423
+    public static function geoip2_download_file($source_url, $destination_file) {
424 424
         $success    = false;
425 425
         $message    = '';
426 426
         
427
-        if ( !function_exists( 'download_url' ) ) {
428
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
427
+        if (!function_exists('download_url')) {
428
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
429 429
         }
430 430
 
431
-        $temp_file  = download_url( $source_url );
431
+        $temp_file = download_url($source_url);
432 432
         
433
-        if ( is_wp_error( $temp_file ) ) {
434
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
433
+        if (is_wp_error($temp_file)) {
434
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
435 435
         } else {
436
-            $handle = gzopen( $temp_file, 'rb' );
436
+            $handle = gzopen($temp_file, 'rb');
437 437
             
438
-            if ( $handle ) {
439
-                $fopen  = fopen( $destination_file, 'wb' );
440
-                if ( $fopen ) {
441
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
442
-                        fwrite( $fopen, $data );
438
+            if ($handle) {
439
+                $fopen = fopen($destination_file, 'wb');
440
+                if ($fopen) {
441
+                    while (($data = gzread($handle, 4096)) != false) {
442
+                        fwrite($fopen, $data);
443 443
                     }
444 444
 
445
-                    gzclose( $handle );
446
-                    fclose( $fopen );
445
+                    gzclose($handle);
446
+                    fclose($fopen);
447 447
                         
448 448
                     $success = true;
449 449
                 } else {
450
-                    gzclose( $handle );
451
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
450
+                    gzclose($handle);
451
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
452 452
                 }
453 453
             } else {
454
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
454
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
455 455
             }
456 456
             
457
-            if ( file_exists( $temp_file ) ) {
458
-                unlink( $temp_file );
457
+            if (file_exists($temp_file)) {
458
+                unlink($temp_file);
459 459
             }
460 460
         }
461 461
         
@@ -467,11 +467,11 @@  discard block
 block discarded – undo
467 467
     }
468 468
     
469 469
     public static function load_geoip2() {
470
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
470
+        if (defined('WPINV_GEOIP2_LODDED')) {
471 471
             return;
472 472
         }
473 473
         
474
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
474
+        if (!class_exists('\MaxMind\Db\Reader')) {
475 475
             $maxmind_db_files = array(
476 476
                 'Reader/Decoder.php',
477 477
                 'Reader/InvalidDatabaseException.php',
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
                 'Reader.php',
481 481
             );
482 482
             
483
-            foreach ( $maxmind_db_files as $key => $file ) {
484
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
483
+            foreach ($maxmind_db_files as $key => $file) {
484
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
485 485
             }
486 486
         }
487 487
         
488
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
488
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
489 489
             $geoip2_files = array(
490 490
                 'ProviderInterface.php',
491 491
                 'Compat/JsonSerializable.php',
@@ -519,23 +519,23 @@  discard block
 block discarded – undo
519 519
                 'WebService/Client.php',
520 520
             );
521 521
             
522
-            foreach ( $geoip2_files as $key => $file ) {
523
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
522
+            foreach ($geoip2_files as $key => $file) {
523
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
524 524
             }
525 525
         }
526 526
 
527
-        define( 'WPINV_GEOIP2_LODDED', true );
527
+        define('WPINV_GEOIP2_LODDED', true);
528 528
     }
529 529
 
530 530
     public static function geoip2_country_dbfile() {
531 531
         $upload_dir = wp_upload_dir();
532 532
 
533
-        if ( !isset( $upload_dir['basedir'] ) ) {
533
+        if (!isset($upload_dir['basedir'])) {
534 534
             return false;
535 535
         }
536 536
 
537 537
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
538
-        if ( !file_exists( $filename ) ) {
538
+        if (!file_exists($filename)) {
539 539
             return false;
540 540
         }
541 541
         
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
     public static function geoip2_city_dbfile() {
546 546
         $upload_dir = wp_upload_dir();
547 547
 
548
-        if ( !isset( $upload_dir['basedir'] ) ) {
548
+        if (!isset($upload_dir['basedir'])) {
549 549
             return false;
550 550
         }
551 551
 
552 552
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
553
-        if ( !file_exists( $filename ) ) {
553
+        if (!file_exists($filename)) {
554 554
             return false;
555 555
         }
556 556
         
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
         try {
562 562
             self::load_geoip2();
563 563
 
564
-            if ( $filename = self::geoip2_country_dbfile() ) {
565
-                return new \GeoIp2\Database\Reader( $filename );
564
+            if ($filename = self::geoip2_country_dbfile()) {
565
+                return new \GeoIp2\Database\Reader($filename);
566 566
             }
567
-        } catch( Exception $e ) {
567
+        } catch (Exception $e) {
568 568
             return false;
569 569
         }
570 570
         
@@ -575,183 +575,183 @@  discard block
 block discarded – undo
575 575
         try {
576 576
             self::load_geoip2();
577 577
 
578
-            if ( $filename = self::geoip2_city_dbfile() ) {
579
-                return new \GeoIp2\Database\Reader( $filename );
578
+            if ($filename = self::geoip2_city_dbfile()) {
579
+                return new \GeoIp2\Database\Reader($filename);
580 580
             }
581
-        } catch( Exception $e ) {
581
+        } catch (Exception $e) {
582 582
             return false;
583 583
         }
584 584
         
585 585
         return false;
586 586
     }
587 587
 
588
-    public static function geoip2_country_record( $ip_address ) {
588
+    public static function geoip2_country_record($ip_address) {
589 589
         try {
590 590
             $reader = self::geoip2_country_reader();
591 591
 
592
-            if ( $reader ) {
593
-                $record = $reader->country( $ip_address );
592
+            if ($reader) {
593
+                $record = $reader->country($ip_address);
594 594
                 
595
-                if ( !empty( $record->country->isoCode ) ) {
595
+                if (!empty($record->country->isoCode)) {
596 596
                     return $record;
597 597
                 }
598 598
             }
599
-        } catch(\InvalidArgumentException $e) {
600
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
599
+        } catch (\InvalidArgumentException $e) {
600
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
601 601
             
602 602
             return false;
603
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
604
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
603
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
604
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
605 605
             
606 606
             return false;
607
-        } catch( Exception $e ) {
607
+        } catch (Exception $e) {
608 608
             return false;
609 609
         }
610 610
         
611 611
         return false;
612 612
     }
613 613
 
614
-    public static function geoip2_city_record( $ip_address ) {
614
+    public static function geoip2_city_record($ip_address) {
615 615
         try {
616 616
             $reader = self::geoip2_city_reader();
617 617
 
618
-            if ( $reader ) {
619
-                $record = $reader->city( $ip_address );
618
+            if ($reader) {
619
+                $record = $reader->city($ip_address);
620 620
                 
621
-                if ( !empty( $record->country->isoCode ) ) {
621
+                if (!empty($record->country->isoCode)) {
622 622
                     return $record;
623 623
                 }
624 624
             }
625
-        } catch(\InvalidArgumentException $e) {
626
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
625
+        } catch (\InvalidArgumentException $e) {
626
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
627 627
             
628 628
             return false;
629
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
630
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
629
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
630
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
631 631
             
632 632
             return false;
633
-        } catch( Exception $e ) {
633
+        } catch (Exception $e) {
634 634
             return false;
635 635
         }
636 636
         
637 637
         return false;
638 638
     }
639 639
 
640
-    public static function geoip2_country_code( $ip_address ) {
641
-        $record = self::geoip2_country_record( $ip_address );
642
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
640
+    public static function geoip2_country_code($ip_address) {
641
+        $record = self::geoip2_country_record($ip_address);
642
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
643 643
     }
644 644
 
645 645
     // Find country by IP address.
646
-    public static function get_country_by_ip( $ip = '' ) {
646
+    public static function get_country_by_ip($ip = '') {
647 647
         global $wpinv_ip_address_country;
648 648
         return '';
649
-        if ( !empty( $wpinv_ip_address_country ) ) {
649
+        if (!empty($wpinv_ip_address_country)) {
650 650
             return $wpinv_ip_address_country;
651 651
         }
652 652
         
653
-        if ( empty( $ip ) ) {
653
+        if (empty($ip)) {
654 654
             $ip = wpinv_get_ip();
655 655
         }
656 656
 
657
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
658
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
657
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
658
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
659 659
 
660
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
661
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
660
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
661
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
662 662
                 try {
663
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
664
-                } catch( Exception $e ) {
665
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
663
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
664
+                } catch (Exception $e) {
665
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
666 666
                 }
667
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
668
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
669
-            } else if ( function_exists( 'simplexml_load_file' ) && ini_get('allow_url_fopen') && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
670
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
667
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
668
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
669
+            } else if (function_exists('simplexml_load_file') && ini_get('allow_url_fopen') && ($ip_country_service === 'geoplugin' || $is_default)) {
670
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
671 671
                 
672
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
673
-                    $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
672
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
673
+                    $wpinv_ip_address_country = (string) $load_xml->geoplugin_countryCode;
674 674
                 }
675
-            }elseif(!empty( $ip )){
675
+            }elseif (!empty($ip)) {
676 676
                 $url = 'http://ip-api.com/json/' . $ip;
677 677
                 $response = wp_remote_get($url);
678 678
 
679
-                if ( is_array( $response ) && wp_remote_retrieve_response_code( $response ) == '200' ) {
680
-                    $data = json_decode(wp_remote_retrieve_body( $response ),true);
681
-                    if(!empty($data['countryCode'])){
682
-                        $wpinv_ip_address_country = (string)$data['countryCode'];
679
+                if (is_array($response) && wp_remote_retrieve_response_code($response) == '200') {
680
+                    $data = json_decode(wp_remote_retrieve_body($response), true);
681
+                    if (!empty($data['countryCode'])) {
682
+                        $wpinv_ip_address_country = (string) $data['countryCode'];
683 683
                     }
684 684
                 }
685 685
             }
686 686
         }
687 687
 
688
-        if ( empty( $wpinv_ip_address_country ) ) {
688
+        if (empty($wpinv_ip_address_country)) {
689 689
             $wpinv_ip_address_country = wpinv_get_default_country();
690 690
         }
691 691
 
692 692
         return $wpinv_ip_address_country;
693 693
     }
694 694
     
695
-    public static function sanitize_vat_settings( $input ) {
695
+    public static function sanitize_vat_settings($input) {
696 696
         global $wpinv_options;
697 697
         
698 698
         $valid      = false;
699 699
         $message    = '';
700 700
         
701
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
702
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
703
-                $valid = self::offline_check( $input['vat_number'] );
701
+        if (!empty($wpinv_options['vat_vies_check'])) {
702
+            if (empty($wpinv_options['vat_offline_check'])) {
703
+                $valid = self::offline_check($input['vat_number']);
704 704
             } else {
705 705
                 $valid = true;
706 706
             }
707 707
             
708
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
708
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
709 709
         } else {
710
-            $result = self::check_vat( $input['vat_number'] );
710
+            $result = self::check_vat($input['vat_number']);
711 711
             
712
-            if ( empty( $result['valid'] ) ) {
712
+            if (empty($result['valid'])) {
713 713
                 $valid      = false;
714 714
                 $message    = $result['message'];
715 715
             } else {
716
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
717
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
716
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
717
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
718 718
             }
719 719
         }
720 720
 
721
-        if ( $message && self::is_vat_validated() != $valid ) {
722
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
721
+        if ($message && self::is_vat_validated() != $valid) {
722
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
723 723
         }
724 724
 
725 725
         $input['vat_valid'] = $valid;
726 726
         return $input;
727 727
     }
728 728
     
729
-    public static function sanitize_vat_rates( $input ) {
730
-        if( !wpinv_current_user_can_manage_invoicing() ) {
731
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
729
+    public static function sanitize_vat_rates($input) {
730
+        if (!wpinv_current_user_can_manage_invoicing()) {
731
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
732 732
             return $input;
733 733
         }
734 734
         
735 735
         $vat_classes = self::get_rate_classes();
736
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
736
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
737 737
         
738
-        if ( empty( $vat_class ) ) {
739
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
738
+        if (empty($vat_class)) {
739
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
740 740
             
741 741
             return $input;
742 742
         }
743 743
 
744
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
744
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
745 745
 
746
-        if ( $vat_class === '_standard' ) {
746
+        if ($vat_class === '_standard') {
747 747
             // Save the active rates in the invoice settings
748
-            update_option( 'wpinv_tax_rates', $new_rates );
748
+            update_option('wpinv_tax_rates', $new_rates);
749 749
         } else {
750 750
             // Get the existing set of rates
751 751
             $rates = self::get_non_standard_rates();
752 752
             $rates[$vat_class] = $new_rates;
753 753
 
754
-            update_option( 'wpinv_vat_rates', $rates );
754
+            update_option('wpinv_vat_rates', $rates);
755 755
         }
756 756
         
757 757
         return $input;
@@ -761,71 +761,71 @@  discard block
 block discarded – undo
761 761
         $response = array();
762 762
         $response['success'] = false;
763 763
         
764
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
765
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
766
-            wp_send_json( $response );
764
+        if (!wpinv_current_user_can_manage_invoicing()) {
765
+            $response['error'] = __('Invalid access!', 'invoicing');
766
+            wp_send_json($response);
767 767
         }
768 768
         
769
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
770
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
769
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
770
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
771 771
         
772
-        if ( empty( $vat_class_name ) ) {
773
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
774
-            wp_send_json( $response );
772
+        if (empty($vat_class_name)) {
773
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
774
+            wp_send_json($response);
775 775
         }
776 776
         
777
-        $vat_classes = (array)self::get_rate_classes();
777
+        $vat_classes = (array) self::get_rate_classes();
778 778
 
779
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
780
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
781
-            wp_send_json( $response );
779
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
780
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
781
+            wp_send_json($response);
782 782
         }
783 783
         
784
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
785
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
784
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
785
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
786 786
         
787
-        $vat_classes = (array)self::get_rate_classes( true );
788
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
787
+        $vat_classes = (array) self::get_rate_classes(true);
788
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
789 789
         
790
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
790
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
791 791
         
792 792
         $response['success'] = true;
793
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
793
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
794 794
         
795
-        wp_send_json( $response );
795
+        wp_send_json($response);
796 796
     }
797 797
     
798 798
     public static function delete_class() {
799 799
         $response = array();
800 800
         $response['success'] = false;
801 801
         
802
-        if ( !wpinv_current_user_can_manage_invoicing() || !isset( $_POST['class'] ) ) {
803
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
804
-            wp_send_json( $response );
802
+        if (!wpinv_current_user_can_manage_invoicing() || !isset($_POST['class'])) {
803
+            $response['error'] = __('Invalid access!', 'invoicing');
804
+            wp_send_json($response);
805 805
         }
806 806
         
807
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
808
-        $vat_classes = (array)self::get_rate_classes();
807
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
808
+        $vat_classes = (array) self::get_rate_classes();
809 809
 
810
-        if ( !isset( $vat_classes[$vat_class] ) ) {
811
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
812
-            wp_send_json( $response );
810
+        if (!isset($vat_classes[$vat_class])) {
811
+            $response['error'] = __('Requested class does not exists', 'invoicing');
812
+            wp_send_json($response);
813 813
         }
814 814
         
815
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
816
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
817
-            wp_send_json( $response );
815
+        if ($vat_class == '_new' || $vat_class == '_standard') {
816
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
817
+            wp_send_json($response);
818 818
         }
819 819
             
820
-        $vat_classes = (array)self::get_rate_classes( true );
821
-        unset( $vat_classes[$vat_class] );
820
+        $vat_classes = (array) self::get_rate_classes(true);
821
+        unset($vat_classes[$vat_class]);
822 822
         
823
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
823
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
824 824
         
825 825
         $response['success'] = true;
826
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
826
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
827 827
         
828
-        wp_send_json( $response );
828
+        wp_send_json($response);
829 829
     }
830 830
     
831 831
     public static function update_eu_rates() {        
@@ -834,72 +834,72 @@  discard block
 block discarded – undo
834 834
         $response['error']      = null;
835 835
         $response['data']       = null;
836 836
         
837
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
838
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
839
-            wp_send_json( $response );
837
+        if (!wpinv_current_user_can_manage_invoicing()) {
838
+            $response['error'] = __('Invalid access!', 'invoicing');
839
+            wp_send_json($response);
840 840
         }
841 841
         
842
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
843
-        $euvatrates = self::request_euvatrates( $group );
842
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
843
+        $euvatrates = self::request_euvatrates($group);
844 844
         
845
-        if ( !empty( $euvatrates ) ) {
846
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
845
+        if (!empty($euvatrates)) {
846
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
847 847
                 $response['success']        = true;
848 848
                 $response['data']['rates']  = $euvatrates['rates'];
849
-            } else if ( !empty( $euvatrates['error'] ) ) {
849
+            } else if (!empty($euvatrates['error'])) {
850 850
                 $response['error']          = $euvatrates['error'];
851 851
             }
852 852
         }
853 853
             
854
-        wp_send_json( $response );
854
+        wp_send_json($response);
855 855
     }
856 856
     
857 857
     public static function hide_vat_fields() {
858
-        $hide = wpinv_get_option( 'vat_disable_fields' );
858
+        $hide = wpinv_get_option('vat_disable_fields');
859 859
         
860
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
860
+        return apply_filters('wpinv_hide_vat_fields', $hide);
861 861
     }
862 862
     
863 863
     public static function same_country_rule() {
864
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
864
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
865 865
         
866
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
866
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
867 867
     }
868 868
     
869 869
     public static function get_vat_name() {
870
-        $vat_name   = wpinv_get_option( 'vat_name' );
871
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
870
+        $vat_name   = wpinv_get_option('vat_name');
871
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
872 872
         
873
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
873
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
874 874
     }
875 875
     
876 876
     public static function get_company_name() {
877
-        $company_name = wpinv_get_option( 'vat_company_name' );
877
+        $company_name = wpinv_get_option('vat_company_name');
878 878
         
879
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
879
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
880 880
     }
881 881
     
882 882
     public static function get_vat_number() {
883
-        $vat_number = wpinv_get_option( 'vat_number' );
883
+        $vat_number = wpinv_get_option('vat_number');
884 884
         
885
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
885
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
886 886
     }
887 887
     
888 888
     public static function is_vat_validated() {
889
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
889
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
890 890
         
891
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
891
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
892 892
     }
893 893
     
894
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
895
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
894
+    public static function sanitize_vat($vat_number, $country_code = '') {        
895
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
896 896
         
897
-        if ( empty( $country_code ) ) {
898
-            $country_code = substr( $vat_number, 0, 2 );
897
+        if (empty($country_code)) {
898
+            $country_code = substr($vat_number, 0, 2);
899 899
         }
900 900
         
901
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
902
-            $vat = str_replace( $country_code, '', $vat_number );
901
+        if (strpos($vat_number, $country_code) === 0) {
902
+            $vat = str_replace($country_code, '', $vat_number);
903 903
         } else {
904 904
             $vat = $country_code . $vat_number;
905 905
         }
@@ -912,140 +912,140 @@  discard block
 block discarded – undo
912 912
         return $return;
913 913
     }
914 914
     
915
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
916
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
915
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
916
+        $vat            = self::sanitize_vat($vat_number, $country_code);
917 917
         $vat_number     = $vat['vat_number'];
918 918
         $country_code   = $vat['iso'];
919 919
         $regex          = array();
920 920
         
921
-        switch ( $country_code ) {
921
+        switch ($country_code) {
922 922
             case 'AT':
923
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
923
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
924 924
                 break;
925 925
             case 'BE':
926
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
926
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
927 927
                 break;
928 928
             case 'BG':
929
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
929
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
930 930
                 break;
931 931
             case 'CH':
932 932
             case 'CHE':
933
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
933
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
934 934
                 break;
935 935
             case 'CY':
936
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
936
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
937 937
                 break;
938 938
             case 'CZ':
939
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
939
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
940 940
                 break;
941 941
             case 'DE':
942
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
942
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
943 943
                 break;
944 944
             case 'DK':
945
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
945
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
946 946
                 break;
947 947
             case 'EE':
948
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
948
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
949 949
                 break;
950 950
             case 'EL':
951
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
951
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
952 952
                 break;
953 953
             case 'ES':
954
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
955
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
956
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
957
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
954
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
955
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
956
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
957
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
958 958
                 break;
959 959
             case 'EU':
960
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
960
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
961 961
                 break;
962 962
             case 'FI':
963
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
963
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
964 964
                 break;
965 965
             case 'FR':
966
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
967
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
968
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
969
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
966
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
967
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
968
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
969
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
970 970
                 break;
971 971
             case 'GB':
972
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
973
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
974
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
975
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
972
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
973
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
974
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
975
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
976 976
                 break;
977 977
             case 'GR':
978
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
978
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
979 979
                 break;
980 980
             case 'HR':
981
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
981
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
982 982
                 break;
983 983
             case 'HU':
984
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
984
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
985 985
                 break;
986 986
             case 'IE':
987
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
988
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
989
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
987
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
988
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
989
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
990 990
                 break;
991 991
             case 'IT':
992
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
992
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
993 993
                 break;
994 994
             case 'LV':
995
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
995
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
996 996
                 break;
997 997
             case 'LT':
998
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
998
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
999 999
                 break;
1000 1000
             case 'LU':
1001
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
1001
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
1002 1002
                 break;
1003 1003
             case 'MT':
1004
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
1004
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
1005 1005
                 break;
1006 1006
             case 'NL':
1007
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
1007
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
1008 1008
                 break;
1009 1009
             case 'NO':
1010
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
1010
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
1011 1011
                 break;
1012 1012
             case 'PL':
1013
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1013
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1014 1014
                 break;
1015 1015
             case 'PT':
1016
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1016
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1017 1017
                 break;
1018 1018
             case 'RO':
1019
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1019
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1020 1020
                 break;
1021 1021
             case 'RS':
1022
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1022
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1023 1023
                 break;
1024 1024
             case 'SI':
1025
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1025
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1026 1026
                 break;
1027 1027
             case 'SK':
1028
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1028
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1029 1029
                 break;
1030 1030
             case 'SE':
1031
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1031
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1032 1032
                 break;
1033 1033
             default:
1034 1034
                 $regex = array();
1035 1035
             break;
1036 1036
         }
1037 1037
         
1038
-        if ( empty( $regex ) ) {
1038
+        if (empty($regex)) {
1039 1039
             return false;
1040 1040
         }
1041 1041
         
1042
-        foreach ( $regex as $pattern ) {
1042
+        foreach ($regex as $pattern) {
1043 1043
             $matches = null;
1044
-            preg_match_all( $pattern, $vat_number, $matches );
1044
+            preg_match_all($pattern, $vat_number, $matches);
1045 1045
             
1046
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1047
-                if ( $formatted ) {
1048
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1046
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1047
+                if ($formatted) {
1048
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1049 1049
                 } else {
1050 1050
                     return true;
1051 1051
                 }
@@ -1055,75 +1055,75 @@  discard block
 block discarded – undo
1055 1055
         return false;
1056 1056
     }
1057 1057
     
1058
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1059
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1058
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1059
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1060 1060
         $vat_number     = $vat['vat'];
1061 1061
         $iso            = $vat['iso'];
1062 1062
         
1063
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1063
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1064 1064
         
1065
-        if ( ini_get( 'allow_url_fopen' ) ) {
1066
-            $response = file_get_contents( $url );
1067
-        } else if ( function_exists( 'curl_init' ) ) {
1065
+        if (ini_get('allow_url_fopen')) {
1066
+            $response = file_get_contents($url);
1067
+        } else if (function_exists('curl_init')) {
1068 1068
             $ch = curl_init();
1069 1069
             
1070
-            curl_setopt( $ch, CURLOPT_URL, $url );
1071
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1072
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1073
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1074
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1070
+            curl_setopt($ch, CURLOPT_URL, $url);
1071
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1072
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1073
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1074
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1075 1075
             
1076
-            $response = curl_exec( $ch );
1076
+            $response = curl_exec($ch);
1077 1077
             
1078
-            if ( curl_errno( $ch ) ) {
1079
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1078
+            if (curl_errno($ch)) {
1079
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1080 1080
                 $response = '';
1081 1081
             }
1082 1082
             
1083
-            curl_close( $ch );
1083
+            curl_close($ch);
1084 1084
         } else {
1085
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1085
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1086 1086
         }
1087 1087
         
1088
-        if ( empty( $response ) ) {
1088
+        if (empty($response)) {
1089 1089
             return $result;
1090 1090
         }
1091 1091
 
1092
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1092
+        if (preg_match('/invalid VAT number/i', $response)) {
1093 1093
             return false;
1094
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1095
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1094
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1095
+            $content = explode("valid VAT number", htmlentities($response));
1096 1096
             
1097
-            if ( !empty( $content[1] ) ) {
1098
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1097
+            if (!empty($content[1])) {
1098
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1099 1099
                 
1100
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1100
+                if (!empty($matches[2]) && $matches[3]) {
1101 1101
                     $return = array();
1102 1102
                     
1103
-                    foreach ( $matches[2] as $key => $label ) {
1104
-                        $label = trim( $label );
1103
+                    foreach ($matches[2] as $key => $label) {
1104
+                        $label = trim($label);
1105 1105
                         
1106
-                        switch ( strtolower( $label ) ) {
1106
+                        switch (strtolower($label)) {
1107 1107
                             case 'member state':
1108
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1108
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1109 1109
                             break;
1110 1110
                             case 'vat number':
1111
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1111
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1112 1112
                             break;
1113 1113
                             case 'name':
1114
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1114
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1115 1115
                             break;
1116 1116
                             case 'address':
1117
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1118
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1117
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1118
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1119 1119
                             break;
1120 1120
                             case 'consultation number':
1121
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1121
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1122 1122
                             break;
1123 1123
                         }
1124 1124
                     }
1125 1125
                     
1126
-                    if ( !empty( $return ) ) {
1126
+                    if (!empty($return)) {
1127 1127
                         return $return;
1128 1128
                     }
1129 1129
                 }
@@ -1135,62 +1135,62 @@  discard block
 block discarded – undo
1135 1135
         }
1136 1136
     }
1137 1137
     
1138
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1138
+    public static function check_vat($vat_number, $country_code = '') {        
1139 1139
         $vat_name           = self::get_vat_name();
1140 1140
         
1141 1141
         $return             = array();
1142 1142
         $return['valid']    = false;
1143
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1143
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1144 1144
                 
1145
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1145
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1146 1146
             return $return;
1147 1147
         }
1148 1148
             
1149
-        $response = self::vies_check( $vat_number, $country_code );
1149
+        $response = self::vies_check($vat_number, $country_code);
1150 1150
         
1151
-        if ( $response ) {
1152
-            $return['valid']    = true;
1151
+        if ($response) {
1152
+            $return['valid'] = true;
1153 1153
             
1154
-            if ( is_array( $response ) ) {
1155
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1156
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1154
+            if (is_array($response)) {
1155
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1156
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1157 1157
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1158 1158
             }
1159 1159
         } else {
1160 1160
             $return['valid']    = false;
1161
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1161
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1162 1162
         }
1163 1163
         
1164 1164
         return $return;
1165 1165
     }
1166 1166
 
1167
-    public static function request_euvatrates( $group ) {
1167
+    public static function request_euvatrates($group) {
1168 1168
         $response               = array();
1169 1169
         $response['success']    = false;
1170 1170
         $response['error']      = null;
1171 1171
         $response['eurates']    = null;
1172 1172
         
1173 1173
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1174
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1175
-        $api_response   = wp_remote_get( $euvatrates_url );
1174
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1175
+        $api_response   = wp_remote_get($euvatrates_url);
1176 1176
 
1177 1177
         try {
1178
-            if ( is_wp_error( $api_response ) ) {
1179
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1178
+            if (is_wp_error($api_response)) {
1179
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1180 1180
             } else {
1181
-                $body = json_decode( $api_response['body'] );
1182
-                if ( isset( $body->rates ) ) {
1181
+                $body = json_decode($api_response['body']);
1182
+                if (isset($body->rates)) {
1183 1183
                     $rates = array();
1184 1184
                     
1185
-                    foreach ( $body->rates as $country_code => $rate ) {
1185
+                    foreach ($body->rates as $country_code => $rate) {
1186 1186
                         $vat_rate = array();
1187 1187
                         $vat_rate['country']        = $rate->country;
1188
-                        $vat_rate['standard']       = (float)$rate->standard_rate;
1189
-                        $vat_rate['reduced']        = (float)$rate->reduced_rate;
1190
-                        $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1191
-                        $vat_rate['parking']        = (float)$rate->parking_rate;
1188
+                        $vat_rate['standard']       = (float) $rate->standard_rate;
1189
+                        $vat_rate['reduced']        = (float) $rate->reduced_rate;
1190
+                        $vat_rate['superreduced']   = (float) $rate->super_reduced_rate;
1191
+                        $vat_rate['parking']        = (float) $rate->parking_rate;
1192 1192
                         
1193
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1193
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1194 1194
                             $vat_rate_group = array();
1195 1195
                             $vat_rate_group['country'] = $rate->country;
1196 1196
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1202,79 +1202,79 @@  discard block
 block discarded – undo
1202 1202
                     }
1203 1203
                     
1204 1204
                     $response['success']    = true;                                
1205
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1205
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1206 1206
                 } else {
1207
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1207
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1208 1208
                 }
1209 1209
             }
1210
-        } catch ( Exception $e ) {
1211
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1210
+        } catch (Exception $e) {
1211
+            $response['error'] = __($e->getMessage(), 'invoicing');
1212 1212
         }
1213 1213
         
1214
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1214
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1215 1215
     }    
1216 1216
     
1217
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1217
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1218 1218
         global $wpi_item_id, $wpi_country;
1219 1219
         
1220
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1221
-            $country_code = trim( $_POST['wpinv_country'] );
1222
-        } else if ( !empty( $_POST['country'] ) ) {
1223
-            $country_code = trim( $_POST['country'] );
1224
-        } else if ( !empty( $wpi_country ) ) {
1220
+        if (!empty($_POST['wpinv_country'])) {
1221
+            $country_code = trim($_POST['wpinv_country']);
1222
+        } else if (!empty($_POST['country'])) {
1223
+            $country_code = trim($_POST['country']);
1224
+        } else if (!empty($wpi_country)) {
1225 1225
             $country_code = $wpi_country;
1226 1226
         } else {
1227
-            $country_code = self::get_user_country( '', $user_id );
1227
+            $country_code = self::get_user_country('', $user_id);
1228 1228
         }
1229 1229
         
1230
-        if ( $is_digital === null && $wpi_item_id ) {
1231
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1230
+        if ($is_digital === null && $wpi_item_id) {
1231
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1232 1232
         }
1233 1233
         
1234
-        if ( !empty( $country_code ) ) {
1235
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1234
+        if (!empty($country_code)) {
1235
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1236 1236
         }
1237 1237
         
1238
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1238
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1239 1239
     }
1240 1240
     
1241
-    public static function tax_label( $label = '' ) {
1241
+    public static function tax_label($label = '') {
1242 1242
         global $wpi_requires_vat;
1243 1243
         
1244
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1245
-            $wpi_requires_vat = self::requires_vat( 0, false );
1244
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1245
+            $wpi_requires_vat = self::requires_vat(0, false);
1246 1246
         }
1247 1247
         
1248
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1248
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1249 1249
     }
1250 1250
     
1251 1251
     public static function standard_rates_label() {
1252
-        return __( 'Standard Rates', 'invoicing' );
1252
+        return __('Standard Rates', 'invoicing');
1253 1253
     }
1254 1254
     
1255
-    public static function get_rate_classes( $with_desc = false ) {        
1256
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1257
-        $classes = maybe_unserialize( $rate_classes_option );
1255
+    public static function get_rate_classes($with_desc = false) {        
1256
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1257
+        $classes = maybe_unserialize($rate_classes_option);
1258 1258
 
1259
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1259
+        if (empty($classes) || !is_array($classes)) {
1260 1260
             $classes = array();
1261 1261
         }
1262 1262
 
1263 1263
         $rate_classes = array();
1264
-        if ( !array_key_exists( '_standard', $classes ) ) {
1265
-            if ( $with_desc ) {
1266
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1264
+        if (!array_key_exists('_standard', $classes)) {
1265
+            if ($with_desc) {
1266
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1267 1267
             } else {
1268 1268
                 $rate_classes['_standard'] = self::standard_rates_label();
1269 1269
             }
1270 1270
         }
1271 1271
         
1272
-        foreach ( $classes as $key => $class ) {
1273
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1274
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1272
+        foreach ($classes as $key => $class) {
1273
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1274
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1275 1275
             
1276
-            if ( $with_desc ) {
1277
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1276
+            if ($with_desc) {
1277
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1278 1278
             } else {
1279 1279
                 $rate_classes[$key] = $name;
1280 1280
             }
@@ -1285,15 +1285,15 @@  discard block
 block discarded – undo
1285 1285
     
1286 1286
     public static function get_all_classes() {        
1287 1287
         $classes            = self::get_rate_classes();
1288
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1288
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1289 1289
         
1290
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1290
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1291 1291
     }
1292 1292
     
1293
-    public static function get_class_desc( $rate_class ) {        
1294
-        $rate_classes = self::get_rate_classes( true );
1293
+    public static function get_class_desc($rate_class) {        
1294
+        $rate_classes = self::get_rate_classes(true);
1295 1295
 
1296
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1296
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1297 1297
             return $rate_classes[$rate_class]['desc'];
1298 1298
         }
1299 1299
         
@@ -1309,107 +1309,107 @@  discard block
 block discarded – undo
1309 1309
             'increased'     => 'Increased'
1310 1310
         );
1311 1311
         
1312
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1312
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1313 1313
     }
1314 1314
 
1315 1315
     public static function get_rules() {
1316 1316
         $vat_rules = array(
1317
-            'digital' => __( 'Digital Product', 'invoicing' ),
1318
-            'physical' => __( 'Physical Product', 'invoicing' ),    
1319
-            '_exempt' => __( 'Tax-Free Product', 'invoicing' ),
1317
+            'digital' => __('Digital Product', 'invoicing'),
1318
+            'physical' => __('Physical Product', 'invoicing'),    
1319
+            '_exempt' => __('Tax-Free Product', 'invoicing'),
1320 1320
         );
1321
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1321
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1322 1322
     }
1323 1323
 
1324
-    public static function get_vat_rates( $class ) {
1325
-        if ( $class === '_standard' ) {
1324
+    public static function get_vat_rates($class) {
1325
+        if ($class === '_standard') {
1326 1326
             return wpinv_get_tax_rates();
1327 1327
         }
1328 1328
 
1329 1329
         $rates = self::get_non_standard_rates();
1330 1330
 
1331
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1331
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1332 1332
     }
1333 1333
 
1334 1334
     public static function get_non_standard_rates() {
1335
-        $option = get_option( 'wpinv_vat_rates', array());
1336
-        return is_array( $option ) ? $option : array();
1335
+        $option = get_option('wpinv_vat_rates', array());
1336
+        return is_array($option) ? $option : array();
1337 1337
     }
1338 1338
     
1339 1339
     public static function allow_vat_rules() {
1340
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1340
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1341 1341
     }
1342 1342
     
1343 1343
     public static function allow_vat_classes() {
1344 1344
         return false; // TODO
1345
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1345
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1346 1346
     }
1347 1347
     
1348
-    public static function get_item_class( $postID ) {
1349
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1348
+    public static function get_item_class($postID) {
1349
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1350 1350
 
1351
-        if ( empty( $class ) ) {
1351
+        if (empty($class)) {
1352 1352
             $class = '_standard';
1353 1353
         }
1354 1354
         
1355
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1355
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1356 1356
     }
1357 1357
     
1358
-    public static function item_class_label( $postID ) {        
1358
+    public static function item_class_label($postID) {        
1359 1359
         $vat_classes = self::get_all_classes();
1360 1360
         
1361
-        $class = self::get_item_class( $postID );
1362
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1361
+        $class = self::get_item_class($postID);
1362
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1363 1363
         
1364
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1364
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1365 1365
     }
1366 1366
     
1367
-    public static function get_item_rule( $postID ) {        
1368
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1367
+    public static function get_item_rule($postID) {        
1368
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1369 1369
 
1370
-        if ( empty( $rule_type ) ) {        
1370
+        if (empty($rule_type)) {        
1371 1371
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1372 1372
         }
1373 1373
         
1374
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1374
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1375 1375
     }
1376 1376
     
1377
-    public static function item_rule_label( $postID ) {
1377
+    public static function item_rule_label($postID) {
1378 1378
         $vat_rules  = self::get_rules();
1379
-        $vat_rule   = self::get_item_rule( $postID );
1380
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1379
+        $vat_rule   = self::get_item_rule($postID);
1380
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1381 1381
         
1382
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1382
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1383 1383
     }
1384 1384
     
1385
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1386
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1385
+    public static function item_has_digital_rule($item_id = 0) {        
1386
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1387 1387
     }
1388 1388
 
1389
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1390
-        if ( !self::allow_vat_rules() ) {
1389
+    public static function invoice_has_digital_rule($invoice = 0) {        
1390
+        if (!self::allow_vat_rules()) {
1391 1391
             return false;
1392 1392
         }
1393 1393
         
1394
-        if ( empty( $invoice ) ) {
1394
+        if (empty($invoice)) {
1395 1395
             return true;
1396 1396
         }
1397 1397
         
1398
-        if ( is_int( $invoice ) ) {
1399
-            $invoice = new WPInv_Invoice( $invoice );
1398
+        if (is_int($invoice)) {
1399
+            $invoice = new WPInv_Invoice($invoice);
1400 1400
         }
1401 1401
         
1402
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1402
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1403 1403
             return true;
1404 1404
         }
1405 1405
         
1406
-        $cart_items  = $invoice->get_cart_details();
1406
+        $cart_items = $invoice->get_cart_details();
1407 1407
         
1408
-        if ( !empty( $cart_items ) ) {
1408
+        if (!empty($cart_items)) {
1409 1409
             $has_digital_rule = false;
1410 1410
             
1411
-            foreach ( $cart_items as $key => $item ) {
1412
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1411
+            foreach ($cart_items as $key => $item) {
1412
+                if (self::item_has_digital_rule($item['id'])) {
1413 1413
                     $has_digital_rule = true;
1414 1414
                     break;
1415 1415
                 }
@@ -1421,71 +1421,71 @@  discard block
 block discarded – undo
1421 1421
         return $has_digital_rule;
1422 1422
     }
1423 1423
     
1424
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1425
-        if ( !wpinv_use_taxes() ) {
1424
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1425
+        if (!wpinv_use_taxes()) {
1426 1426
             return false;
1427 1427
         }
1428 1428
 
1429 1429
         $is_taxable = true;
1430 1430
 
1431
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1431
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1432 1432
             $is_taxable = false;
1433 1433
         }
1434 1434
 
1435
-        if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) {
1435
+        if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') {
1436 1436
             $is_taxable = false;
1437 1437
         }
1438 1438
 
1439
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1439
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1440 1440
     }
1441 1441
     
1442
-    public static function find_rate( $country, $state, $rate, $class ) {
1442
+    public static function find_rate($country, $state, $rate, $class) {
1443 1443
         global $wpi_zero_tax;
1444 1444
 
1445
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1445
+        if ($class === '_exempt' || $wpi_zero_tax) {
1446 1446
             return 0;
1447 1447
         }
1448 1448
 
1449
-        $tax_rates   = wpinv_get_tax_rates();
1449
+        $tax_rates = wpinv_get_tax_rates();
1450 1450
         
1451
-        if ( $class !== '_standard' ) {
1452
-            $class_rates = self::get_vat_rates( $class );
1451
+        if ($class !== '_standard') {
1452
+            $class_rates = self::get_vat_rates($class);
1453 1453
             
1454
-            if ( is_array( $class_rates ) ) {
1454
+            if (is_array($class_rates)) {
1455 1455
                 $indexed_class_rates = array();
1456 1456
                 
1457
-                foreach ( $class_rates as $key => $cr ) {
1457
+                foreach ($class_rates as $key => $cr) {
1458 1458
                     $indexed_class_rates[$cr['country']] = $cr;
1459 1459
                 }
1460 1460
 
1461
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1461
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1462 1462
                     $tr_country = $tr['country'];
1463
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1463
+                    if (!isset($indexed_class_rates[$tr_country])) {
1464 1464
                         return $tr;
1465 1465
                     }
1466 1466
                     $icr = $indexed_class_rates[$tr_country];
1467
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1467
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1468 1468
 
1469
-                }, $tax_rates, $class_rates );
1469
+                }, $tax_rates, $class_rates);
1470 1470
             }
1471 1471
         }
1472 1472
 
1473
-        if ( !empty( $tax_rates ) ) {
1474
-            foreach ( $tax_rates as $key => $tax_rate ) {
1475
-                if ( $country != $tax_rate['country'] )
1473
+        if (!empty($tax_rates)) {
1474
+            foreach ($tax_rates as $key => $tax_rate) {
1475
+                if ($country != $tax_rate['country'])
1476 1476
                     continue;
1477 1477
 
1478
-                if ( !empty( $tax_rate['global'] ) ) {
1479
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1480
-                        $rate = number_format( $tax_rate['rate'], 4 );
1478
+                if (!empty($tax_rate['global'])) {
1479
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1480
+                        $rate = number_format($tax_rate['rate'], 4);
1481 1481
                     }
1482 1482
                 } else {
1483
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1483
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1484 1484
                         continue;
1485 1485
 
1486 1486
                     $state_rate = $tax_rate['rate'];
1487
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1488
-                        $rate = number_format( $state_rate, 4 );
1487
+                    if (0 !== $state_rate || !empty($state_rate)) {
1488
+                        $rate = number_format($state_rate, 4);
1489 1489
                     }
1490 1490
                 }
1491 1491
             }
@@ -1494,84 +1494,84 @@  discard block
 block discarded – undo
1494 1494
         return $rate;
1495 1495
     }
1496 1496
     
1497
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1497
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1498 1498
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1499 1499
         
1500 1500
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1501 1501
         $allow_vat_classes = self::allow_vat_classes();
1502
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1502
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1503 1503
 
1504
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1504
+        if ($class === '_exempt' || $wpi_zero_tax) {
1505 1505
             return 0;
1506
-        } else if ( !$allow_vat_classes ) {
1506
+        } else if (!$allow_vat_classes) {
1507 1507
             $class = '_standard';
1508 1508
         }
1509 1509
 
1510
-        if( !empty( $_POST['wpinv_country'] ) ) {
1510
+        if (!empty($_POST['wpinv_country'])) {
1511 1511
             $post_country = $_POST['wpinv_country'];
1512
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1512
+        } elseif (!empty($_POST['wpinv_country'])) {
1513 1513
             $post_country = $_POST['wpinv_country'];
1514
-        } elseif( !empty( $_POST['country'] ) ) {
1514
+        } elseif (!empty($_POST['country'])) {
1515 1515
             $post_country = $_POST['country'];
1516 1516
         } else {
1517 1517
             $post_country = '';
1518 1518
         }
1519 1519
 
1520
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1521
-        $base_country   = wpinv_is_base_country( $country );
1520
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1521
+        $base_country   = wpinv_is_base_country($country);
1522 1522
         
1523
-        $requires_vat   = self::requires_vat( 0, false );
1524
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1525
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1523
+        $requires_vat   = self::requires_vat(0, false);
1524
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1525
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1526 1526
           
1527
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1527
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1528 1528
             $rate = 0;
1529
-        } else if ( $requires_vat ) {
1530
-            $vat_number = self::get_user_vat_number( '', 0, true );
1529
+        } else if ($requires_vat) {
1530
+            $vat_number = self::get_user_vat_number('', 0, true);
1531 1531
             $vat_info   = self::current_vat_data();
1532 1532
             
1533
-            if ( is_array( $vat_info ) ) {
1534
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1533
+            if (is_array($vat_info)) {
1534
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1535 1535
             }
1536 1536
             
1537
-            if ( $country == 'UK' ) {
1537
+            if ($country == 'UK') {
1538 1538
                 $country = 'GB';
1539 1539
             }
1540 1540
 
1541
-            if ( !empty( $vat_number ) ) {
1541
+            if (!empty($vat_number)) {
1542 1542
                 $rate = 0;
1543 1543
             } else {
1544
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1544
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1545 1545
             }
1546 1546
 
1547
-            if ( empty( $vat_number ) && !$is_digital ) {
1548
-                if ( $base_country ) {
1549
-                    $rate = self::find_rate( $country, null, $rate, $class );
1547
+            if (empty($vat_number) && !$is_digital) {
1548
+                if ($base_country) {
1549
+                    $rate = self::find_rate($country, null, $rate, $class);
1550 1550
                 } else {
1551
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1551
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1552 1552
                         $rate = $wpinv_options['eu_fallback_rate'];
1553
-                    } else if( !empty( $country ) ) {
1554
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1553
+                    } else if (!empty($country)) {
1554
+                        $rate = self::find_rate($country, $state, $rate, $class);
1555 1555
                     }
1556 1556
                 }
1557
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1558
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1557
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1558
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1559 1559
                     $rate = $wpinv_options['eu_fallback_rate'];
1560
-                } else if( !empty( $country ) ) {
1561
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1560
+                } else if (!empty($country)) {
1561
+                    $rate = self::find_rate($country, $state, $rate, $class);
1562 1562
                 }
1563 1563
             }
1564 1564
         } else {
1565
-            if ( $is_digital ) {
1565
+            if ($is_digital) {
1566 1566
                 $ip_country_code = self::get_country_by_ip();
1567 1567
                 
1568
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1569
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1568
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1569
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1570 1570
                 } else {
1571
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1571
+                    $rate = self::find_rate($country, $state, $rate, $class);
1572 1572
                 }
1573 1573
             } else {
1574
-                $rate = self::find_rate( $country, $state, $rate, $class );
1574
+                $rate = self::find_rate($country, $state, $rate, $class);
1575 1575
             }
1576 1576
         }
1577 1577
 
@@ -1581,48 +1581,48 @@  discard block
 block discarded – undo
1581 1581
     public static function current_vat_data() {
1582 1582
         global $wpi_session;
1583 1583
         
1584
-        return $wpi_session->get( 'user_vat_data' );
1584
+        return $wpi_session->get('user_vat_data');
1585 1585
     }
1586 1586
     
1587
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1588
-        $user_address = wpinv_get_user_address( $user_id, false );
1587
+    public static function get_user_country($country = '', $user_id = 0) {
1588
+        $user_address = wpinv_get_user_address($user_id, false);
1589 1589
         
1590
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1590
+        if (wpinv_get_option('vat_ip_country_default')) {
1591 1591
             $country = '';
1592 1592
         }
1593 1593
         
1594
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1595
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1594
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1595
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1596 1596
 
1597
-        if ( empty( $result ) ) {
1597
+        if (empty($result)) {
1598 1598
             $result = self::get_country_by_ip();
1599 1599
         }
1600 1600
 
1601 1601
         return $result;
1602 1602
     }
1603 1603
     
1604
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1604
+    public static function set_user_country($country = '', $user_id = 0) {
1605 1605
         global $wpi_userID;
1606 1606
         
1607
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1607
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1608 1608
             $country = wpinv_get_default_country();
1609 1609
         }
1610 1610
         
1611 1611
         return $country;
1612 1612
     }
1613 1613
     
1614
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1614
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1615 1615
         global $wpi_current_id, $wpi_userID;
1616 1616
         
1617
-        if ( !empty( $_POST['new_user'] ) ) {
1617
+        if (!empty($_POST['new_user'])) {
1618 1618
             return '';
1619 1619
         }
1620 1620
         
1621
-        if ( empty( $user_id ) ) {
1622
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1621
+        if (empty($user_id)) {
1622
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1623 1623
         }
1624 1624
 
1625
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1625
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1626 1626
         
1627 1627
         /* TODO
1628 1628
         if ( $is_valid && $vat_number ) {
@@ -1633,38 +1633,38 @@  discard block
 block discarded – undo
1633 1633
         }
1634 1634
         */
1635 1635
 
1636
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1636
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1637 1637
     }
1638 1638
     
1639
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1639
+    public static function get_user_company($company = '', $user_id = 0) {
1640 1640
         global $wpi_current_id, $wpi_userID;
1641 1641
         
1642
-        if ( empty( $user_id ) ) {
1643
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1642
+        if (empty($user_id)) {
1643
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1644 1644
         }
1645 1645
 
1646
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1646
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1647 1647
 
1648
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1648
+        return apply_filters('wpinv_user_company', $company, $user_id);
1649 1649
     }
1650 1650
     
1651
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1652
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1651
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1652
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1653 1653
 
1654
-        if ( is_user_logged_in() && $save ) {
1654
+        if (is_user_logged_in() && $save) {
1655 1655
             $user_id = get_current_user_id();
1656 1656
 
1657
-            if ( !empty( $vat_number ) ) {
1658
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1657
+            if (!empty($vat_number)) {
1658
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1659 1659
             } else {
1660
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1660
+                delete_user_meta($user_id, '_wpinv_vat_number');
1661 1661
             }
1662 1662
 
1663
-            if ( !empty( $company ) ) {
1664
-                update_user_meta( $user_id, '_wpinv_company', $company );
1663
+            if (!empty($company)) {
1664
+                update_user_meta($user_id, '_wpinv_company', $company);
1665 1665
             } else {
1666
-                delete_user_meta( $user_id, '_wpinv_company');
1667
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1666
+                delete_user_meta($user_id, '_wpinv_company');
1667
+                delete_user_meta($user_id, '_wpinv_vat_number');
1668 1668
             }
1669 1669
         }
1670 1670
 
@@ -1674,113 +1674,113 @@  discard block
 block discarded – undo
1674 1674
     public static function ajax_vat_validate() {
1675 1675
         global $wpinv_options, $wpi_session;
1676 1676
         
1677
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1677
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1678 1678
         $response               = array();
1679 1679
         $response['success']    = false;
1680 1680
         
1681
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1682
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1683
-            wp_send_json( $response );
1681
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1682
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1683
+            wp_send_json($response);
1684 1684
         }
1685 1685
         
1686
-        $vat_name   = self::get_vat_name();
1686
+        $vat_name = self::get_vat_name();
1687 1687
         
1688
-        if ( $is_checkout ) {
1688
+        if ($is_checkout) {
1689 1689
             $invoice = wpinv_get_invoice_cart();
1690 1690
             
1691
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1691
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1692 1692
                 $vat_info = array();
1693
-                $wpi_session->set( 'user_vat_data', $vat_info );
1693
+                $wpi_session->set('user_vat_data', $vat_info);
1694 1694
 
1695 1695
                 self::save_user_vat_details();
1696 1696
                 
1697 1697
                 $response['success'] = true;
1698
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1699
-                wp_send_json( $response );
1698
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1699
+                wp_send_json($response);
1700 1700
             }
1701 1701
         }
1702 1702
         
1703
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1704
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1703
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1704
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1705 1705
         
1706
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1707
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1708
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1706
+        $vat_info = $wpi_session->get('user_vat_data');
1707
+        if (!is_array($vat_info) || empty($vat_info)) {
1708
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1709 1709
         }
1710 1710
         
1711
-        if ( empty( $vat_number ) ) {
1712
-            if ( $is_checkout ) {
1711
+        if (empty($vat_number)) {
1712
+            if ($is_checkout) {
1713 1713
                 $response['success'] = true;
1714
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1714
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1715 1715
                 
1716
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1716
+                $vat_info = $wpi_session->get('user_vat_data');
1717 1717
                 $vat_info['number'] = "";
1718 1718
                 $vat_info['valid'] = true;
1719 1719
                 
1720
-                self::save_user_vat_details( $company );
1720
+                self::save_user_vat_details($company);
1721 1721
             } else {
1722
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1722
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1723 1723
                 
1724 1724
                 $vat_info['valid'] = false;
1725 1725
             }
1726 1726
 
1727
-            $wpi_session->set( 'user_vat_data', $vat_info );
1728
-            wp_send_json( $response );
1727
+            $wpi_session->set('user_vat_data', $vat_info);
1728
+            wp_send_json($response);
1729 1729
         }
1730 1730
         
1731
-        if ( empty( $company ) ) {
1731
+        if (empty($company)) {
1732 1732
             $vat_info['valid'] = false;
1733
-            $wpi_session->set( 'user_vat_data', $vat_info );
1733
+            $wpi_session->set('user_vat_data', $vat_info);
1734 1734
             
1735
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1736
-            wp_send_json( $response );
1735
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1736
+            wp_send_json($response);
1737 1737
         }
1738 1738
         
1739
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1740
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1739
+        if (!empty($wpinv_options['vat_vies_check'])) {
1740
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1741 1741
                 $vat_info['valid'] = false;
1742
-                $wpi_session->set( 'user_vat_data', $vat_info );
1742
+                $wpi_session->set('user_vat_data', $vat_info);
1743 1743
                 
1744
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1745
-                wp_send_json( $response );
1744
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1745
+                wp_send_json($response);
1746 1746
             }
1747 1747
             
1748 1748
             $response['success'] = true;
1749
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1749
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1750 1750
         } else {
1751
-            $result = self::check_vat( $vat_number );
1751
+            $result = self::check_vat($vat_number);
1752 1752
             
1753
-            if ( empty( $result['valid'] ) ) {
1753
+            if (empty($result['valid'])) {
1754 1754
                 $response['error'] = $result['message'];
1755
-                wp_send_json( $response );
1755
+                wp_send_json($response);
1756 1756
             }
1757 1757
             
1758
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1759
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1758
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1759
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1760 1760
             
1761
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1761
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1762 1762
 
1763
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1763
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1764 1764
                 $response['success'] = true;
1765
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1765
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1766 1766
             } else {           
1767 1767
                 $vat_info['valid'] = false;
1768
-                $wpi_session->set( 'user_vat_data', $vat_info );
1768
+                $wpi_session->set('user_vat_data', $vat_info);
1769 1769
                 
1770 1770
                 $response['success'] = false;
1771
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1772
-                wp_send_json( $response );
1771
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1772
+                wp_send_json($response);
1773 1773
             }
1774 1774
         }
1775 1775
         
1776
-        if ( $is_checkout ) {
1777
-            self::save_user_vat_details( $company, $vat_number );
1776
+        if ($is_checkout) {
1777
+            self::save_user_vat_details($company, $vat_number);
1778 1778
 
1779
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1780
-            $wpi_session->set( 'user_vat_data', $vat_info );
1779
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1780
+            $wpi_session->set('user_vat_data', $vat_info);
1781 1781
         }
1782 1782
 
1783
-        wp_send_json( $response );
1783
+        wp_send_json($response);
1784 1784
     }
1785 1785
     
1786 1786
     public static function ajax_vat_reset() {
@@ -1789,161 +1789,161 @@  discard block
 block discarded – undo
1789 1789
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1790 1790
         $vat_number = self::get_user_vat_number();
1791 1791
         
1792
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1793
-        $wpi_session->set( 'user_vat_data', $vat_info );
1792
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1793
+        $wpi_session->set('user_vat_data', $vat_info);
1794 1794
         
1795 1795
         $response                       = array();
1796 1796
         $response['success']            = true;
1797 1797
         $response['data']['company']    = $company;
1798 1798
         $response['data']['number']     = $vat_number;
1799 1799
         
1800
-        wp_send_json( $response );
1800
+        wp_send_json($response);
1801 1801
     }
1802 1802
     
1803
-    public static function checkout_vat_validate( $valid_data, $post ) {
1803
+    public static function checkout_vat_validate($valid_data, $post) {
1804 1804
         global $wpinv_options, $wpi_session;
1805 1805
 
1806
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1806
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1807 1807
 
1808
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1809
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1808
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1809
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1810 1810
             return;
1811 1811
         }
1812 1812
 
1813
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1814
-        $wpi_session->set( 'user_vat_data', null );
1813
+        $vat_saved = $wpi_session->get('user_vat_data');
1814
+        $wpi_session->set('user_vat_data', null);
1815 1815
         
1816 1816
         $invoice        = wpinv_get_invoice_cart();
1817 1817
         $amount         = $invoice->get_total();
1818
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1819
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1818
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1819
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1820 1820
         
1821
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1822
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1823
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1824
-        if ( empty( $country ) ) {
1821
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1822
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1823
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1824
+        if (empty($country)) {
1825 1825
             $country = wpinv_default_billing_country();
1826 1826
         }
1827 1827
         
1828
-        if ( !$is_digital && $no_vat ) {
1828
+        if (!$is_digital && $no_vat) {
1829 1829
             return;
1830 1830
         }
1831 1831
             
1832
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1832
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1833 1833
         
1834 1834
         $ip_country_code    = self::get_country_by_ip();
1835
-        $is_eu_state        = self::is_eu_state( $country );
1836
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1835
+        $is_eu_state        = self::is_eu_state($country);
1836
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1837 1837
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1838 1838
 
1839
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1839
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1840 1840
             $vat_data['adddress_confirmed'] = false;
1841 1841
             
1842
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1843
-                if ( $ip_country_code != $country ) {
1844
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1842
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1843
+                if ($ip_country_code != $country) {
1844
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1845 1845
                 }
1846 1846
             } else {
1847 1847
                 $vat_data['adddress_confirmed'] = true;
1848 1848
             }
1849 1849
         }
1850 1850
 
1851
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1852
-            if ( $is_eu_state ) {
1853
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1854
-            } else if ( $is_digital && $is_eu_state_ip ) {
1855
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1851
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1852
+            if ($is_eu_state) {
1853
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1854
+            } else if ($is_digital && $is_eu_state_ip) {
1855
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1856 1856
             }
1857 1857
         }
1858 1858
 
1859
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1859
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1860 1860
             return;
1861 1861
         }
1862 1862
 
1863
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1864
-            $vat_data['valid']  = $vat_saved['valid'];
1863
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1864
+            $vat_data['valid'] = $vat_saved['valid'];
1865 1865
         }
1866 1866
             
1867
-        if ( $company !== null ) {
1867
+        if ($company !== null) {
1868 1868
             $vat_data['company'] = $company;
1869 1869
         }
1870 1870
 
1871 1871
         $message = '';
1872
-        if ( $vat_number !== null ) {
1872
+        if ($vat_number !== null) {
1873 1873
             $vat_data['number'] = $vat_number;
1874 1874
             
1875
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1876
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1877
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1875
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1876
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1877
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1878 1878
                         $vat_data['valid'] = false;
1879 1879
                     }
1880 1880
                 } else {
1881
-                    $result = self::check_vat( $vat_number );
1881
+                    $result = self::check_vat($vat_number);
1882 1882
                     
1883
-                    if ( !empty( $result['valid'] ) ) {                
1883
+                    if (!empty($result['valid'])) {                
1884 1884
                         $vat_data['valid'] = true;
1885
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1886
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1885
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1886
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1887 1887
                     
1888
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1888
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1889 1889
 
1890
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1890
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1891 1891
                             $vat_data['valid'] = false;
1892 1892
                             
1893
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1893
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1894 1894
                         }
1895 1895
                     } else {
1896
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1896
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1897 1897
                     }
1898 1898
                 }
1899 1899
                 
1900
-                if ( !$vat_data['valid'] ) {
1901
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1902
-                    wpinv_set_error( 'vat_validation', $error );
1900
+                if (!$vat_data['valid']) {
1901
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1902
+                    wpinv_set_error('vat_validation', $error);
1903 1903
                 }
1904 1904
             }
1905 1905
         }
1906 1906
 
1907
-        $wpi_session->set( 'user_vat_data', $vat_data );
1907
+        $wpi_session->set('user_vat_data', $vat_data);
1908 1908
     }
1909 1909
     
1910
-    public static function checkout_vat_fields( $billing_details ) {
1910
+    public static function checkout_vat_fields($billing_details) {
1911 1911
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1912 1912
         
1913 1913
         $ip_address         = wpinv_get_ip();
1914 1914
         $ip_country_code    = self::get_country_by_ip();
1915 1915
         
1916
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1916
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1917 1917
         $invoice            = wpinv_get_invoice_cart();
1918
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1918
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1919 1919
         $wpi_country        = $invoice->country;
1920 1920
         
1921
-        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital );
1921
+        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital);
1922 1922
         $wpi_requires_vat   = $requires_vat;
1923 1923
         
1924 1924
         $company            = self::get_user_company();
1925 1925
         $vat_number         = self::get_user_vat_number();
1926 1926
         
1927
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1928
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1927
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1928
+        $vat_info           = $wpi_session->get('user_vat_data');
1929 1929
 
1930
-        if ( is_array( $vat_info ) ) {
1931
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1932
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1933
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1930
+        if (is_array($vat_info)) {
1931
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1932
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1933
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1934 1934
         }
1935 1935
         
1936 1936
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1937 1937
 
1938
-        if ( $ip_country_code == 'UK' ) {
1938
+        if ($ip_country_code == 'UK') {
1939 1939
             $ip_country_code = 'GB';
1940 1940
         }
1941 1941
         
1942
-        if ( $selected_country == 'UK' ) {
1942
+        if ($selected_country == 'UK') {
1943 1943
             $selected_country = 'GB';
1944 1944
         }
1945 1945
         
1946
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1946
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1947 1947
             $requires_vat = false;
1948 1948
         }
1949 1949
 
@@ -1951,52 +1951,52 @@  discard block
 block discarded – undo
1951 1951
         $display_validate_btn   = 'none';
1952 1952
         $display_reset_btn      = 'none';
1953 1953
         
1954
-        if ( !empty( $vat_number ) && $validated ) {
1955
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1954
+        if (!empty($vat_number) && $validated) {
1955
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1956 1956
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1957 1957
             $display_reset_btn      = 'block';
1958 1958
         } else {
1959
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1960
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1959
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1960
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1961 1961
             $display_validate_btn   = 'block';
1962 1962
         }
1963 1963
         
1964
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1964
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1965 1965
         ?>
1966 1966
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1967 1967
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1968
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1968
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1969 1969
                 <div id="wpinv-fields-box" class="panel-body">
1970 1970
                     <p id="wpi_show_vat_note">
1971
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1971
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1972 1972
                     </p>
1973 1973
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1974 1974
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1975
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1975
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1976 1976
                             <?php
1977
-                            echo wpinv_html_text( array(
1977
+                            echo wpinv_html_text(array(
1978 1978
                                     'id'            => 'wpinv_company',
1979 1979
                                     'name'          => 'wpinv_company',
1980 1980
                                     'value'         => $company,
1981 1981
                                     'class'         => 'wpi-input form-control',
1982
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1983
-                                ) );
1982
+                                    'placeholder'   => __('Company name', 'invoicing'),
1983
+                                ));
1984 1984
                             ?>
1985 1985
                         </p>
1986 1986
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1987
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1987
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1988 1988
                             <span id="wpinv_vat_number-wrap">
1989 1989
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1990
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1991
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1990
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1991
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1992 1992
                             </span>
1993 1993
                         </p>
1994 1994
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1995
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1996
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1995
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1996
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1997 1997
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1998 1998
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1999
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1999
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
2000 2000
                         </p>
2001 2001
                     </div>
2002 2002
                 </div>
@@ -2010,32 +2010,32 @@  discard block
 block discarded – undo
2010 2010
                 </span>
2011 2011
             </div>
2012 2012
         </div>
2013
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
2014
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
2013
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
2014
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
2015 2015
         ?>
2016 2016
         <div class="wpi-ip-info clearfix panel panel-info">
2017 2017
             <div id="wpinv-fields-box" class="panel-body">
2018
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
2018
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
2019 2019
             </div>
2020 2020
         </div>
2021 2021
         <?php }
2022 2022
     }
2023 2023
     
2024
-    public static function show_vat_notice( $invoice ) {
2025
-        if ( empty( $invoice ) ) {
2024
+    public static function show_vat_notice($invoice) {
2025
+        if (empty($invoice)) {
2026 2026
             return NULL;
2027 2027
         }
2028 2028
         
2029
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2030
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2031
-        if ( $label || $notice ) {
2029
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2030
+        $notice     = wpinv_get_option('vat_invoice_notice');
2031
+        if ($label || $notice) {
2032 2032
         ?>
2033 2033
         <div class="row wpinv-vat-notice">
2034 2034
             <div class="col-sm-12">
2035
-                <?php if ( $label ) { ?>
2036
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2037
-                <?php } if ( $notice ) { ?>
2038
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2035
+                <?php if ($label) { ?>
2036
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2037
+                <?php } if ($notice) { ?>
2038
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2039 2039
                 <?php } ?>
2040 2040
             </div>
2041 2041
         </div>
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +364 added lines, -364 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -80,39 +80,39 @@  discard block
 block discarded – undo
80 80
             'buy_items' => true,
81 81
         );
82 82
 
83
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
84
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
83
+        foreach ($ajax_events as $ajax_event => $nopriv) {
84
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
85 85
             
86
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
87
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
86
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
87
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
88 88
             }
89 89
 
90
-            if ( $nopriv ) {
91
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
90
+            if ($nopriv) {
91
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
92 92
 
93
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
93
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
94 94
             }
95 95
         }
96 96
     }
97 97
     
98 98
     public static function add_note() {
99
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
99
+        check_ajax_referer('add-invoice-note', '_nonce');
100 100
 
101
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
101
+        if (!wpinv_current_user_can_manage_invoicing()) {
102 102
             die(-1);
103 103
         }
104 104
 
105
-        $post_id   = absint( $_POST['post_id'] );
106
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
107
-        $note_type = sanitize_text_field( $_POST['note_type'] );
105
+        $post_id   = absint($_POST['post_id']);
106
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
107
+        $note_type = sanitize_text_field($_POST['note_type']);
108 108
 
109 109
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
110 110
 
111
-        if ( $post_id > 0 ) {
112
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
111
+        if ($post_id > 0) {
112
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
113 113
 
114
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
115
-                wpinv_get_invoice_note_line_item( $note_id );
114
+            if ($note_id > 0 && !is_wp_error($note_id)) {
115
+                wpinv_get_invoice_note_line_item($note_id);
116 116
             }
117 117
         }
118 118
 
@@ -120,16 +120,16 @@  discard block
 block discarded – undo
120 120
     }
121 121
 
122 122
     public static function delete_note() {
123
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
123
+        check_ajax_referer('delete-invoice-note', '_nonce');
124 124
 
125
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
125
+        if (!wpinv_current_user_can_manage_invoicing()) {
126 126
             die(-1);
127 127
         }
128 128
 
129
-        $note_id = (int)$_POST['note_id'];
129
+        $note_id = (int) $_POST['note_id'];
130 130
 
131
-        if ( $note_id > 0 ) {
132
-            wp_delete_comment( $note_id, true );
131
+        if ($note_id > 0) {
132
+            wp_delete_comment($note_id, true);
133 133
         }
134 134
 
135 135
         die();
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
     }
143 143
     
144 144
     public static function checkout() {
145
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
146
-            define( 'WPINV_CHECKOUT', true );
145
+        if (!defined('WPINV_CHECKOUT')) {
146
+            define('WPINV_CHECKOUT', true);
147 147
         }
148 148
 
149 149
         wpinv_process_checkout();
@@ -152,53 +152,53 @@  discard block
 block discarded – undo
152 152
     
153 153
     public static function add_invoice_item() {
154 154
         global $wpi_userID, $wpinv_ip_address_country;
155
-        check_ajax_referer( 'invoice-item', '_nonce' );
156
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
155
+        check_ajax_referer('invoice-item', '_nonce');
156
+        if (!wpinv_current_user_can_manage_invoicing()) {
157 157
             die(-1);
158 158
         }
159 159
         
160
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
161
-        $invoice_id = absint( $_POST['invoice_id'] );
160
+        $item_id    = sanitize_text_field($_POST['item_id']);
161
+        $invoice_id = absint($_POST['invoice_id']);
162 162
         
163
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
163
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
164 164
             die();
165 165
         }
166 166
         
167
-        $invoice    = wpinv_get_invoice( $invoice_id );
168
-        if ( empty( $invoice ) ) {
167
+        $invoice = wpinv_get_invoice($invoice_id);
168
+        if (empty($invoice)) {
169 169
             die();
170 170
         }
171 171
         
172
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
172
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
173 173
             die(); // Don't allow modify items for paid invoice.
174 174
         }
175 175
         
176
-        if ( !empty( $_POST['user_id'] ) ) {
177
-            $wpi_userID = absint( $_POST['user_id'] ); 
176
+        if (!empty($_POST['user_id'])) {
177
+            $wpi_userID = absint($_POST['user_id']); 
178 178
         }
179 179
 
180
-        $item = new WPInv_Item( $item_id );
181
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
180
+        $item = new WPInv_Item($item_id);
181
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
182 182
             die();
183 183
         }
184 184
         
185 185
         // Validate item before adding to invoice because recurring item must be paid individually.
186
-        if ( !empty( $invoice->cart_details ) ) {
186
+        if (!empty($invoice->cart_details)) {
187 187
             $valid = true;
188 188
             
189
-            if ( $recurring_item = $invoice->get_recurring() ) {
190
-                if ( $recurring_item != $item_id ) {
189
+            if ($recurring_item = $invoice->get_recurring()) {
190
+                if ($recurring_item != $item_id) {
191 191
                     $valid = false;
192 192
                 }
193
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
193
+            } else if (wpinv_is_recurring_item($item_id)) {
194 194
                 $valid = false;
195 195
             }
196 196
             
197
-            if ( !$valid ) {
197
+            if (!$valid) {
198 198
                 $response               = array();
199 199
                 $response['success']    = false;
200
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
201
-                wp_send_json( $response );
200
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
201
+                wp_send_json($response);
202 202
             }
203 203
         }
204 204
         
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
         
207 207
         $data                   = array();
208 208
         $data['invoice_id']     = $invoice_id;
209
-        $data['cart_discounts'] = $invoice->get_discounts( true );
209
+        $data['cart_discounts'] = $invoice->get_discounts(true);
210 210
         
211
-        wpinv_set_checkout_session( $data );
211
+        wpinv_set_checkout_session($data);
212 212
         
213
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
213
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
214 214
 
215 215
         $args = array(
216 216
             'id'            => $item_id,
@@ -223,21 +223,21 @@  discard block
 block discarded – undo
223 223
             'fees'          => array()
224 224
         );
225 225
 
226
-        $invoice->add_item( $item_id, $args );
226
+        $invoice->add_item($item_id, $args);
227 227
         $invoice->save();
228 228
         
229
-        if ( empty( $_POST['country'] ) ) {
229
+        if (empty($_POST['country'])) {
230 230
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
231 231
         }
232
-        if ( empty( $_POST['state'] ) ) {
232
+        if (empty($_POST['state'])) {
233 233
             $_POST['state'] = $invoice->state;
234 234
         }
235 235
          
236
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
237
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
236
+        $invoice->country   = sanitize_text_field($_POST['country']);
237
+        $invoice->state     = sanitize_text_field($_POST['state']);
238 238
         
239
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
239
+        $invoice->set('country', sanitize_text_field($_POST['country']));
240
+        $invoice->set('state', sanitize_text_field($_POST['state']));
241 241
         
242 242
         $wpinv_ip_address_country = $invoice->country;
243 243
 
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         
246 246
         $response                       = array();
247 247
         $response['success']            = true;
248
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
248
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
249 249
         $response['data']['subtotal']   = $invoice->get_subtotal();
250 250
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
251 251
         $response['data']['tax']        = $invoice->get_tax();
@@ -257,41 +257,41 @@  discard block
 block discarded – undo
257 257
         
258 258
         wpinv_set_checkout_session($checkout_session);
259 259
         
260
-        wp_send_json( $response );
260
+        wp_send_json($response);
261 261
     }
262 262
 
263 263
 
264 264
     public static function remove_invoice_item() {
265 265
         global $wpi_userID, $wpinv_ip_address_country;
266 266
         
267
-        check_ajax_referer( 'invoice-item', '_nonce' );
268
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
267
+        check_ajax_referer('invoice-item', '_nonce');
268
+        if (!wpinv_current_user_can_manage_invoicing()) {
269 269
             die(-1);
270 270
         }
271 271
         
272
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
273
-        $invoice_id = absint( $_POST['invoice_id'] );
274
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
272
+        $item_id    = sanitize_text_field($_POST['item_id']);
273
+        $invoice_id = absint($_POST['invoice_id']);
274
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
275 275
         
276
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
276
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
277 277
             die();
278 278
         }
279 279
 
280
-        $invoice    = wpinv_get_invoice( $invoice_id );
281
-        if ( empty( $invoice ) ) {
280
+        $invoice = wpinv_get_invoice($invoice_id);
281
+        if (empty($invoice)) {
282 282
             die();
283 283
         }
284 284
         
285
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
285
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
286 286
             die(); // Don't allow modify items for paid invoice.
287 287
         }
288 288
         
289
-        if ( !empty( $_POST['user_id'] ) ) {
290
-            $wpi_userID = absint( $_POST['user_id'] ); 
289
+        if (!empty($_POST['user_id'])) {
290
+            $wpi_userID = absint($_POST['user_id']); 
291 291
         }
292 292
 
293
-        $item       = new WPInv_Item( $item_id );
294
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
293
+        $item = new WPInv_Item($item_id);
294
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
295 295
             die();
296 296
         }
297 297
         
@@ -299,9 +299,9 @@  discard block
 block discarded – undo
299 299
         
300 300
         $data                   = array();
301 301
         $data['invoice_id']     = $invoice_id;
302
-        $data['cart_discounts'] = $invoice->get_discounts( true );
302
+        $data['cart_discounts'] = $invoice->get_discounts(true);
303 303
         
304
-        wpinv_set_checkout_session( $data );
304
+        wpinv_set_checkout_session($data);
305 305
 
306 306
         $args = array(
307 307
             'id'         => $item_id,
@@ -309,21 +309,21 @@  discard block
 block discarded – undo
309 309
             'cart_index' => $cart_index
310 310
         );
311 311
 
312
-        $invoice->remove_item( $item_id, $args );
312
+        $invoice->remove_item($item_id, $args);
313 313
         $invoice->save();
314 314
         
315
-        if ( empty( $_POST['country'] ) ) {
315
+        if (empty($_POST['country'])) {
316 316
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
317 317
         }
318
-        if ( empty( $_POST['state'] ) ) {
318
+        if (empty($_POST['state'])) {
319 319
             $_POST['state'] = $invoice->state;
320 320
         }
321 321
          
322
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
323
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
322
+        $invoice->country   = sanitize_text_field($_POST['country']);
323
+        $invoice->state     = sanitize_text_field($_POST['state']);
324 324
         
325
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
326
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
325
+        $invoice->set('country', sanitize_text_field($_POST['country']));
326
+        $invoice->set('state', sanitize_text_field($_POST['state']));
327 327
         
328 328
         $wpinv_ip_address_country = $invoice->country;
329 329
         
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
         
332 332
         $response                       = array();
333 333
         $response['success']            = true;
334
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
334
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
335 335
         $response['data']['subtotal']   = $invoice->get_subtotal();
336 336
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
337 337
         $response['data']['tax']        = $invoice->get_tax();
@@ -343,55 +343,55 @@  discard block
 block discarded – undo
343 343
         
344 344
         wpinv_set_checkout_session($checkout_session);
345 345
         
346
-        wp_send_json( $response );
346
+        wp_send_json($response);
347 347
     }
348 348
     
349 349
     public static function create_invoice_item() {
350
-        check_ajax_referer( 'invoice-item', '_nonce' );
351
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
350
+        check_ajax_referer('invoice-item', '_nonce');
351
+        if (!wpinv_current_user_can_manage_invoicing()) {
352 352
             die(-1);
353 353
         }
354 354
         
355
-        $invoice_id = absint( $_POST['invoice_id'] );
355
+        $invoice_id = absint($_POST['invoice_id']);
356 356
 
357 357
         // Find the item
358
-        if ( !is_numeric( $invoice_id ) ) {
358
+        if (!is_numeric($invoice_id)) {
359 359
             die();
360 360
         }        
361 361
         
362
-        $invoice     = wpinv_get_invoice( $invoice_id );
363
-        if ( empty( $invoice ) ) {
362
+        $invoice = wpinv_get_invoice($invoice_id);
363
+        if (empty($invoice)) {
364 364
             die();
365 365
         }
366 366
         
367 367
         // Validate item before adding to invoice because recurring item must be paid individually.
368
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
368
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
369 369
             $response               = array();
370 370
             $response['success']    = false;
371
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
372
-            wp_send_json( $response );
371
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
372
+            wp_send_json($response);
373 373
         }        
374 374
         
375
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
375
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
376 376
         
377 377
         $meta               = array();
378 378
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
379
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
379
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
380 380
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
381 381
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
382 382
         
383 383
         $data                   = array();
384 384
         $data['post_title']     = sanitize_text_field($save_item['name']);
385 385
         $data['post_status']    = 'publish';
386
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
386
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
387 387
         $data['meta']           = $meta;
388 388
         
389 389
         $item = new WPInv_Item();
390
-        $item->create( $data );
390
+        $item->create($data);
391 391
         
392
-        if ( !empty( $item ) ) {
392
+        if (!empty($item)) {
393 393
             $_POST['item_id']   = $item->ID;
394
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
394
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
395 395
             
396 396
             self::add_invoice_item();
397 397
         }
@@ -399,15 +399,15 @@  discard block
 block discarded – undo
399 399
     }
400 400
     
401 401
     public static function get_billing_details() {
402
-        check_ajax_referer( 'get-billing-details', '_nonce' );
402
+        check_ajax_referer('get-billing-details', '_nonce');
403 403
         
404
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
404
+        if (!wpinv_current_user_can_manage_invoicing()) {
405 405
             die(-1);
406 406
         }
407 407
 
408
-        $user_id            = (int)$_POST['user_id'];
408
+        $user_id            = (int) $_POST['user_id'];
409 409
         $billing_details    = wpinv_get_user_address($user_id);
410
-        $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
410
+        $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
411 411
         
412 412
         if (isset($billing_details['user_id'])) {
413 413
             unset($billing_details['user_id']);
@@ -421,20 +421,20 @@  discard block
 block discarded – undo
421 421
         $response['success']                    = true;
422 422
         $response['data']['billing_details']    = $billing_details;
423 423
         
424
-        wp_send_json( $response );
424
+        wp_send_json($response);
425 425
     }
426 426
     
427 427
     public static function admin_recalculate_totals() {
428 428
         global $wpi_userID, $wpinv_ip_address_country;
429 429
         
430
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
431
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
430
+        check_ajax_referer('wpinv-nonce', '_nonce');
431
+        if (!wpinv_current_user_can_manage_invoicing()) {
432 432
             die(-1);
433 433
         }
434 434
         
435
-        $invoice_id = absint( $_POST['invoice_id'] );        
436
-        $invoice    = wpinv_get_invoice( $invoice_id );
437
-        if ( empty( $invoice ) ) {
435
+        $invoice_id = absint($_POST['invoice_id']);        
436
+        $invoice    = wpinv_get_invoice($invoice_id);
437
+        if (empty($invoice)) {
438 438
             die();
439 439
         }
440 440
 
@@ -442,29 +442,29 @@  discard block
 block discarded – undo
442 442
 
443 443
         $data                   = array();
444 444
         $data['invoice_id']     = $invoice_id;
445
-        $data['cart_discounts'] = $invoice->get_discounts( true );
445
+        $data['cart_discounts'] = $invoice->get_discounts(true);
446 446
 
447
-        wpinv_set_checkout_session( $data );
447
+        wpinv_set_checkout_session($data);
448 448
         
449
-        if ( !empty( $_POST['user_id'] ) ) {
450
-            $wpi_userID = absint( $_POST['user_id'] ); 
449
+        if (!empty($_POST['user_id'])) {
450
+            $wpi_userID = absint($_POST['user_id']); 
451 451
         }
452 452
         
453
-        if ( empty( $_POST['country'] ) ) {
453
+        if (empty($_POST['country'])) {
454 454
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
455 455
         }
456 456
 
457 457
         $disable_taxes = 0;
458
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
458
+        if (!empty($_POST['disable_taxes'])) {
459 459
             $disable_taxes = 1;
460 460
         }
461
-        $invoice->set( 'disable_taxes', $disable_taxes );
461
+        $invoice->set('disable_taxes', $disable_taxes);
462 462
 
463
-        $invoice->country = sanitize_text_field( $_POST['country'] );
464
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
465
-        if ( isset( $_POST['state'] ) ) {
466
-            $invoice->state = sanitize_text_field( $_POST['state'] );
467
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
463
+        $invoice->country = sanitize_text_field($_POST['country']);
464
+        $invoice->set('country', sanitize_text_field($_POST['country']));
465
+        if (isset($_POST['state'])) {
466
+            $invoice->state = sanitize_text_field($_POST['state']);
467
+            $invoice->set('state', sanitize_text_field($_POST['state']));
468 468
         }
469 469
         
470 470
         $wpinv_ip_address_country = $invoice->country;
@@ -473,7 +473,7 @@  discard block
 block discarded – undo
473 473
         
474 474
         $response                       = array();
475 475
         $response['success']            = true;
476
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
476
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
477 477
         $response['data']['subtotal']   = $invoice->get_subtotal();
478 478
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
479 479
         $response['data']['tax']        = $invoice->get_tax();
@@ -485,25 +485,25 @@  discard block
 block discarded – undo
485 485
         
486 486
         wpinv_set_checkout_session($checkout_session);
487 487
 
488
-        wp_send_json( $response );
488
+        wp_send_json($response);
489 489
     }
490 490
     
491 491
     public static function admin_apply_discount() {
492 492
         global $wpi_userID;
493 493
         
494
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
495
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
494
+        check_ajax_referer('wpinv-nonce', '_nonce');
495
+        if (!wpinv_current_user_can_manage_invoicing()) {
496 496
             die(-1);
497 497
         }
498 498
         
499
-        $invoice_id = absint( $_POST['invoice_id'] );
500
-        $discount_code = sanitize_text_field( $_POST['code'] );
501
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
499
+        $invoice_id = absint($_POST['invoice_id']);
500
+        $discount_code = sanitize_text_field($_POST['code']);
501
+        if (empty($invoice_id) || empty($discount_code)) {
502 502
             die();
503 503
         }
504 504
         
505
-        $invoice = wpinv_get_invoice( $invoice_id );
506
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
505
+        $invoice = wpinv_get_invoice($invoice_id);
506
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
507 507
             die();
508 508
         }
509 509
         
@@ -511,49 +511,49 @@  discard block
 block discarded – undo
511 511
         
512 512
         $data                   = array();
513 513
         $data['invoice_id']     = $invoice_id;
514
-        $data['cart_discounts'] = $invoice->get_discounts( true );
514
+        $data['cart_discounts'] = $invoice->get_discounts(true);
515 515
         
516
-        wpinv_set_checkout_session( $data );
516
+        wpinv_set_checkout_session($data);
517 517
         
518 518
         $response               = array();
519 519
         $response['success']    = false;
520
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
520
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
521 521
         $response['data']['code'] = $discount_code;
522 522
         
523
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
524
-            $discounts = wpinv_set_cart_discount( $discount_code );
523
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
524
+            $discounts = wpinv_set_cart_discount($discount_code);
525 525
             
526 526
             $response['success'] = true;
527
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
528
-        }  else {
527
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
528
+        } else {
529 529
             $errors = wpinv_get_errors();
530
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
530
+            if (!empty($errors['wpinv-discount-error'])) {
531 531
                 $response['msg'] = $errors['wpinv-discount-error'];
532 532
             }
533
-            wpinv_unset_error( 'wpinv-discount-error' );
533
+            wpinv_unset_error('wpinv-discount-error');
534 534
         }
535 535
         
536 536
         wpinv_set_checkout_session($checkout_session);
537 537
         
538
-        wp_send_json( $response );
538
+        wp_send_json($response);
539 539
     }
540 540
     
541 541
     public static function admin_remove_discount() {
542 542
         global $wpi_userID;
543 543
         
544
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
545
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
544
+        check_ajax_referer('wpinv-nonce', '_nonce');
545
+        if (!wpinv_current_user_can_manage_invoicing()) {
546 546
             die(-1);
547 547
         }
548 548
         
549
-        $invoice_id = absint( $_POST['invoice_id'] );
550
-        $discount_code = sanitize_text_field( $_POST['code'] );
551
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
549
+        $invoice_id = absint($_POST['invoice_id']);
550
+        $discount_code = sanitize_text_field($_POST['code']);
551
+        if (empty($invoice_id) || empty($discount_code)) {
552 552
             die();
553 553
         }
554 554
         
555
-        $invoice = wpinv_get_invoice( $invoice_id );
556
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
555
+        $invoice = wpinv_get_invoice($invoice_id);
556
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
557 557
             die();
558 558
         }
559 559
         
@@ -561,38 +561,38 @@  discard block
 block discarded – undo
561 561
         
562 562
         $data                   = array();
563 563
         $data['invoice_id']     = $invoice_id;
564
-        $data['cart_discounts'] = $invoice->get_discounts( true );
564
+        $data['cart_discounts'] = $invoice->get_discounts(true);
565 565
         
566
-        wpinv_set_checkout_session( $data );
566
+        wpinv_set_checkout_session($data);
567 567
         
568 568
         $response               = array();
569 569
         $response['success']    = false;
570 570
         $response['msg']        = NULL;
571 571
         
572
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
572
+        $discounts = wpinv_unset_cart_discount($discount_code);
573 573
         $response['success'] = true;
574
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
574
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
575 575
         
576 576
         wpinv_set_checkout_session($checkout_session);
577 577
         
578
-        wp_send_json( $response );
578
+        wp_send_json($response);
579 579
     }
580 580
     
581 581
     public static function check_email() {
582
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
583
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
582
+        check_ajax_referer('wpinv-nonce', '_nonce');
583
+        if (!wpinv_current_user_can_manage_invoicing()) {
584 584
             die(-1);
585 585
         }
586 586
         
587
-        $email = sanitize_text_field( $_POST['email'] );
587
+        $email = sanitize_text_field($_POST['email']);
588 588
         
589 589
         $response = array();
590
-        if ( is_email( $email ) && email_exists( $email ) && $user_data = get_user_by( 'email', $email ) ) {
590
+        if (is_email($email) && email_exists($email) && $user_data = get_user_by('email', $email)) {
591 591
             $user_id            = $user_data->ID;
592 592
             $user_login         = $user_data->user_login;
593 593
             $display_name       = $user_data->display_name ? $user_data->display_name : $user_login;
594 594
             $billing_details    = wpinv_get_user_address($user_id);
595
-            $billing_details    = apply_filters( 'wpinv_fill_billing_details', $billing_details, $user_id );
595
+            $billing_details    = apply_filters('wpinv_fill_billing_details', $billing_details, $user_id);
596 596
             
597 597
             if (isset($billing_details['user_id'])) {
598 598
                 unset($billing_details['user_id']);
@@ -608,54 +608,54 @@  discard block
 block discarded – undo
608 608
             $response['data']['billing_details']    = $billing_details;
609 609
         }
610 610
         
611
-        wp_send_json( $response );
611
+        wp_send_json($response);
612 612
     }
613 613
     
614 614
     public static function run_tool() {
615
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
616
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
615
+        check_ajax_referer('wpinv-nonce', '_nonce');
616
+        if (!wpinv_current_user_can_manage_invoicing()) {
617 617
             die(-1);
618 618
         }
619 619
         
620
-        $tool = sanitize_text_field( $_POST['tool'] );
620
+        $tool = sanitize_text_field($_POST['tool']);
621 621
         
622
-        do_action( 'wpinv_run_tool' );
622
+        do_action('wpinv_run_tool');
623 623
         
624
-        if ( !empty( $tool ) ) {
625
-            do_action( 'wpinv_tool_' . $tool );
624
+        if (!empty($tool)) {
625
+            do_action('wpinv_tool_' . $tool);
626 626
         }
627 627
     }
628 628
     
629 629
     public static function apply_discount() {
630 630
         global $wpi_userID;
631 631
         
632
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
632
+        check_ajax_referer('wpinv-nonce', '_nonce');
633 633
         
634 634
         $response = array();
635 635
         
636
-        if ( isset( $_POST['code'] ) ) {
637
-            $discount_code = sanitize_text_field( $_POST['code'] );
636
+        if (isset($_POST['code'])) {
637
+            $discount_code = sanitize_text_field($_POST['code']);
638 638
 
639 639
             $response['success']        = false;
640 640
             $response['msg']            = '';
641 641
             $response['data']['code']   = $discount_code;
642 642
             
643 643
             $invoice = wpinv_get_invoice_cart();
644
-            if ( empty( $invoice->ID ) ) {
645
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
646
-                wp_send_json( $response );
644
+            if (empty($invoice->ID)) {
645
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
646
+                wp_send_json($response);
647 647
             }
648 648
 
649 649
             $wpi_userID = $invoice->get_user_id();
650 650
 
651
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
652
-                $discount       = wpinv_get_discount_by_code( $discount_code );
653
-                $discounts      = wpinv_set_cart_discount( $discount_code );
654
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
655
-                $total          = wpinv_get_cart_total( null, $discounts );
656
-                $cart_totals    = wpinv_recalculate_tax( true );
651
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
652
+                $discount       = wpinv_get_discount_by_code($discount_code);
653
+                $discounts      = wpinv_set_cart_discount($discount_code);
654
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
655
+                $total          = wpinv_get_cart_total(null, $discounts);
656
+                $cart_totals    = wpinv_recalculate_tax(true);
657 657
             
658
-                if ( !empty( $cart_totals ) ) {
658
+                if (!empty($cart_totals)) {
659 659
                     $response['success']        = true;
660 660
                     $response['data']           = $cart_totals;
661 661
                     $response['data']['code']   = $discount_code;
@@ -664,29 +664,29 @@  discard block
 block discarded – undo
664 664
                 }
665 665
             } else {
666 666
                 $errors = wpinv_get_errors();
667
-                $response['msg']  = $errors['wpinv-discount-error'];
668
-                wpinv_unset_error( 'wpinv-discount-error' );
667
+                $response['msg'] = $errors['wpinv-discount-error'];
668
+                wpinv_unset_error('wpinv-discount-error');
669 669
             }
670 670
 
671 671
             // Allow for custom discount code handling
672
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
672
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
673 673
         }
674 674
         
675
-        wp_send_json( $response );
675
+        wp_send_json($response);
676 676
     }
677 677
     
678 678
     public static function remove_discount() {
679
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
679
+        check_ajax_referer('wpinv-nonce', '_nonce');
680 680
         
681 681
         $response = array();
682 682
         
683
-        if ( isset( $_POST['code'] ) ) {
684
-            $discount_code  = sanitize_text_field( $_POST['code'] );
685
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
686
-            $total          = wpinv_get_cart_total( null, $discounts );
687
-            $cart_totals    = wpinv_recalculate_tax( true );
683
+        if (isset($_POST['code'])) {
684
+            $discount_code  = sanitize_text_field($_POST['code']);
685
+            $discounts      = wpinv_unset_cart_discount($discount_code);
686
+            $total          = wpinv_get_cart_total(null, $discounts);
687
+            $cart_totals    = wpinv_recalculate_tax(true);
688 688
             
689
-            if ( !empty( $cart_totals ) ) {
689
+            if (!empty($cart_totals)) {
690 690
                 $response['success']        = true;
691 691
                 $response['data']           = $cart_totals;
692 692
                 $response['data']['code']   = $discount_code;
@@ -695,10 +695,10 @@  discard block
 block discarded – undo
695 695
             }
696 696
             
697 697
             // Allow for custom discount code handling
698
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
698
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
699 699
         }
700 700
         
701
-        wp_send_json( $response );
701
+        wp_send_json($response);
702 702
     }
703 703
 
704 704
     /**
@@ -710,75 +710,75 @@  discard block
 block discarded – undo
710 710
         global $invoicing, $wpi_checkout_id, $cart_total;
711 711
 
712 712
         // Check nonce.
713
-        if ( ! isset( $_POST['wpinv_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_payment_form'], 'wpinv_payment_form' ) ) {
714
-            wp_send_json_error( __( 'Security checks failed.', 'invoicing' ) );
713
+        if (!isset($_POST['wpinv_payment_form']) || !wp_verify_nonce($_POST['wpinv_payment_form'], 'wpinv_payment_form')) {
714
+            wp_send_json_error(__('Security checks failed.', 'invoicing'));
715 715
         }
716 716
 
717 717
         // Prepare submitted data...
718
-        $data = wp_unslash( $_POST );
718
+        $data = wp_unslash($_POST);
719 719
 
720 720
         // ... form fields...
721
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
722
-            wp_send_json_error( __( 'This payment form is no longer active.', 'invoicing' ) );
721
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
722
+            wp_send_json_error(__('This payment form is no longer active.', 'invoicing'));
723 723
         }
724 724
 
725
-        if ( empty( $data['billing_email'] ) || ! is_email( $data['billing_email'] ) ) {
726
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
725
+        if (empty($data['billing_email']) || !is_email($data['billing_email'])) {
726
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
727 727
         }
728 728
 
729 729
         $prepared = array(
730
-            'billing_email'                    => sanitize_email( $data['billing_email'] ),
731
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $data['billing_email'] ),
732
-            __( 'Form Id', 'invoicing' )       => absint( $data['form_id'] ),
730
+            'billing_email'                    => sanitize_email($data['billing_email']),
731
+            __('Billing Email', 'invoicing') => sanitize_email($data['billing_email']),
732
+            __('Form Id', 'invoicing')       => absint($data['form_id']),
733 733
         );
734 734
 
735
-        $prepared['billing_email'] = sanitize_email( $data['billing_email'] );
735
+        $prepared['billing_email'] = sanitize_email($data['billing_email']);
736 736
 
737
-        $fields = $invoicing->form_elements->get_form_elements( $data['form_id'] );
737
+        $fields = $invoicing->form_elements->get_form_elements($data['form_id']);
738 738
 
739 739
         // ... and form items.
740
-        $items          = $invoicing->form_elements->get_form_items( $data['form_id'] );
740
+        $items          = $invoicing->form_elements->get_form_items($data['form_id']);
741 741
         $prepared_items = array();
742 742
         $address_fields = array();
743 743
 
744
-        if ( ! empty( $data['wpinv-items'] ) ) {
744
+        if (!empty($data['wpinv-items'])) {
745 745
 
746
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
746
+            $selected_items = wpinv_clean($data['wpinv-items']);
747 747
 
748
-            foreach ( $items as $item ) {
748
+            foreach ($items as $item) {
749 749
 
750
-                if ( ! empty( $item['required'] ) && ! isset( $selected_items[ $item['id'] ] ) ) {
751
-                    wp_send_json_error( __( 'A required item is missing.', 'invoicing' ) );
750
+                if (!empty($item['required']) && !isset($selected_items[$item['id']])) {
751
+                    wp_send_json_error(__('A required item is missing.', 'invoicing'));
752 752
                 }
753 753
 
754
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
754
+                if (!isset($selected_items[$item['id']])) {
755 755
                     continue;
756 756
                 }
757 757
 
758 758
                 $quantity = 1;
759 759
 
760
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
760
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
761 761
 
762
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
762
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
763 763
 
764
-                    if ( empty( $quantity ) ) {
764
+                    if (empty($quantity)) {
765 765
                         $quantity = 1;
766 766
                     }
767 767
                 }
768 768
 
769 769
                 // Custom pricing.
770
-                if ( ! empty( $item['custom_price'] ) ) {
770
+                if (!empty($item['custom_price'])) {
771 771
 
772
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
773
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
772
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
773
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
774 774
 
775
-                    if ( $set_price < $minimum_price ) {
776
-                        wp_send_json_error( __( 'The provided amount is less than the minimum allowed value.', 'invoicing' ) );
775
+                    if ($set_price < $minimum_price) {
776
+                        wp_send_json_error(__('The provided amount is less than the minimum allowed value.', 'invoicing'));
777 777
                     }
778 778
 
779 779
                     $prepared_items[] = array(
780 780
                         'id'           =>$item['id'],
781
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
781
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
782 782
                         'custom_price' => $set_price,
783 783
                         'name'         => $item['title'],
784 784
                         'quantity'     => $quantity,
@@ -788,8 +788,8 @@  discard block
 block discarded – undo
788 788
 
789 789
                     $prepared_items[] = array(
790 790
                         'id'           => $item['id'],
791
-                        'item_price'   => wpinv_sanitize_amount( $item['price'] ),
792
-                        'custom_price' => wpinv_sanitize_amount( $item['price'] ),
791
+                        'item_price'   => wpinv_sanitize_amount($item['price']),
792
+                        'custom_price' => wpinv_sanitize_amount($item['price']),
793 793
                         'name'         => $item['title'],
794 794
                         'quantity'     => $quantity,
795 795
                     );
@@ -800,64 +800,64 @@  discard block
 block discarded – undo
800 800
 
801 801
         } else {
802 802
 
803
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
803
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
804 804
 
805 805
         }
806 806
 
807 807
         // Are all required fields provided?
808
-        foreach ( $fields as $field ) {
808
+        foreach ($fields as $field) {
809 809
 
810
-            if ( ! empty( $field['premade'] ) ) {
810
+            if (!empty($field['premade'])) {
811 811
                 continue;
812 812
             }
813 813
 
814
-            if ( ! empty( $field['required'] ) && empty( $data[ $field['id'] ] ) ) {
815
-                wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
814
+            if (!empty($field['required']) && empty($data[$field['id']])) {
815
+                wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
816 816
             }
817 817
 
818
-            if ( $field['type'] == 'address' ) {
818
+            if ($field['type'] == 'address') {
819 819
 
820
-                foreach ( $field['fields'] as $address_field ) {
820
+                foreach ($field['fields'] as $address_field) {
821 821
 
822
-                    if ( empty( $address_field['visible'] ) ) {
822
+                    if (empty($address_field['visible'])) {
823 823
                         continue;
824 824
                     }
825 825
 
826
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
827
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
826
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
827
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
828 828
                     }
829 829
 
830
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
831
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
832
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
830
+                    if (isset($data[$address_field['name']])) {
831
+                        $label = str_replace('wpinv_', '', $address_field['name']);
832
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
833 833
                     }
834 834
 
835 835
                 }
836 836
 
837
-            } else if ( isset( $data[ $field['id'] ] ) ) {
837
+            } else if (isset($data[$field['id']])) {
838 838
                 $label = $field['id'];
839 839
 
840
-                if ( isset( $field['label'] ) ) {
840
+                if (isset($field['label'])) {
841 841
                     $label = $field['label'];
842 842
                 }
843 843
 
844
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
844
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
845 845
             }
846 846
 
847 847
         }
848 848
 
849
-        $user = get_user_by( 'email', $prepared['billing_email'] );
849
+        $user = get_user_by('email', $prepared['billing_email']);
850 850
 
851
-        if ( empty( $user ) ) {
852
-            $user = wpinv_create_user( $prepared['billing_email'] );
851
+        if (empty($user)) {
852
+            $user = wpinv_create_user($prepared['billing_email']);
853 853
         }
854 854
 
855
-        if ( is_wp_error( $user ) ) {
856
-            wp_send_json_error( $user->get_error_message() );
855
+        if (is_wp_error($user)) {
856
+            wp_send_json_error($user->get_error_message());
857 857
         }
858 858
 
859
-        if ( is_numeric( $user ) ) {
860
-            $user = get_user_by( 'id', $user );
859
+        if (is_numeric($user)) {
860
+            $user = get_user_by('id', $user);
861 861
         }
862 862
 
863 863
         // Create the invoice.
@@ -872,34 +872,34 @@  discard block
 block discarded – undo
872 872
             true
873 873
         );
874 874
 
875
-        if ( is_wp_error( $created ) ) {
876
-            wp_send_json_error( $created->get_error_message() );
875
+        if (is_wp_error($created)) {
876
+            wp_send_json_error($created->get_error_message());
877 877
         }
878 878
 
879
-        if ( empty( $created ) ) {
880
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
879
+        if (empty($created)) {
880
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
881 881
         }
882 882
 
883
-        unset( $prepared['billing_email'] );
884
-        update_post_meta( $created->ID, 'payment_form_data', $prepared );
883
+        unset($prepared['billing_email']);
884
+        update_post_meta($created->ID, 'payment_form_data', $prepared);
885 885
 
886 886
         $wpi_checkout_id = $created->ID;
887 887
         $cart_total = wpinv_price(
888 888
             wpinv_format_amount(
889
-                wpinv_get_cart_total( $created->get_cart_details(), NULL, $created ) ),
889
+                wpinv_get_cart_total($created->get_cart_details(), NULL, $created) ),
890 890
                 $created->get_currency()
891 891
         );
892 892
 
893 893
         $data                   = array();
894 894
         $data['invoice_id']     = $created->ID;
895
-        $data['cart_discounts'] = $created->get_discounts( true );
895
+        $data['cart_discounts'] = $created->get_discounts(true);
896 896
 
897
-        wpinv_set_checkout_session( $data );
898
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
899
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
897
+        wpinv_set_checkout_session($data);
898
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
899
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
900 900
         
901
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
902
-            define( 'WPINV_CHECKOUT', true );
901
+        if (!defined('WPINV_CHECKOUT')) {
902
+            define('WPINV_CHECKOUT', true);
903 903
         }
904 904
 
905 905
         wpinv_process_checkout();
@@ -917,51 +917,51 @@  discard block
 block discarded – undo
917 917
     public static function get_payment_form_states_field() {
918 918
         global $invoicing;
919 919
 
920
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
920
+        if (empty($_GET['country']) || empty($_GET['form'])) {
921 921
             exit;
922 922
         }
923 923
 
924
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
924
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
925 925
 
926
-        if ( empty( $elements ) ) {
926
+        if (empty($elements)) {
927 927
             exit;
928 928
         }
929 929
 
930 930
         $address_fields = array();
931
-        foreach ( $elements as $element ) {
932
-            if ( 'address' === $element['type'] ) {
931
+        foreach ($elements as $element) {
932
+            if ('address' === $element['type']) {
933 933
                 $address_fields = $element;
934 934
                 break;
935 935
             }
936 936
         }
937 937
 
938
-        if ( empty( $address_fields ) ) {
938
+        if (empty($address_fields)) {
939 939
             exit;
940 940
         }
941 941
 
942
-        foreach( $address_fields['fields'] as $address_field ) {
942
+        foreach ($address_fields['fields'] as $address_field) {
943 943
 
944
-            if ( 'wpinv_state' == $address_field['name'] ) {
944
+            if ('wpinv_state' == $address_field['name']) {
945 945
 
946 946
                 $label = $address_field['label'];
947 947
 
948
-                if ( ! empty( $address_field['required'] ) ) {
948
+                if (!empty($address_field['required'])) {
949 949
                     $label .= "<span class='text-danger'> *</span>";
950 950
                 }
951 951
 
952
-                $states = wpinv_get_country_states( $_GET['country'] );
952
+                $states = wpinv_get_country_states($_GET['country']);
953 953
 
954
-                if ( ! empty( $states ) ) {
954
+                if (!empty($states)) {
955 955
 
956 956
                     $html = aui()->select(
957 957
                             array(
958 958
                                 'options'          => $states,
959
-                                'name'             => esc_attr( $address_field['name'] ),
960
-                                'id'               => esc_attr( $address_field['name'] ),
961
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
959
+                                'name'             => esc_attr($address_field['name']),
960
+                                'id'               => esc_attr($address_field['name']),
961
+                                'placeholder'      => esc_attr($address_field['placeholder']),
962 962
                                 'required'         => (bool) $address_field['required'],
963 963
                                 'no_wrap'          => true,
964
-                                'label'            => wp_kses_post( $label ),
964
+                                'label'            => wp_kses_post($label),
965 965
                                 'select2'          => false,
966 966
                             )
967 967
                         );
@@ -970,10 +970,10 @@  discard block
 block discarded – undo
970 970
 
971 971
                     $html = aui()->input(
972 972
                             array(
973
-                                'name'       => esc_attr( $address_field['name'] ),
974
-                                'id'         => esc_attr( $address_field['name'] ),
973
+                                'name'       => esc_attr($address_field['name']),
974
+                                'id'         => esc_attr($address_field['name']),
975 975
                                 'required'   => (bool) $address_field['required'],
976
-                                'label'      => wp_kses_post( $label ),
976
+                                'label'      => wp_kses_post($label),
977 977
                                 'no_wrap'    => true,
978 978
                                 'type'       => 'text',
979 979
                             )
@@ -981,7 +981,7 @@  discard block
 block discarded – undo
981 981
 
982 982
                 }
983 983
 
984
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
984
+                wp_send_json_success(str_replace('sr-only', '', $html));
985 985
                 exit;
986 986
 
987 987
             }
@@ -1000,77 +1000,77 @@  discard block
 block discarded – undo
1000 1000
         global $invoicing;
1001 1001
 
1002 1002
         // Check nonce.
1003
-        check_ajax_referer( 'wpinv_payment_form', 'wpinv_payment_form' );
1003
+        check_ajax_referer('wpinv_payment_form', 'wpinv_payment_form');
1004 1004
 
1005 1005
         // Prepare submitted data...
1006
-        $data = wp_unslash( $_POST );
1006
+        $data = wp_unslash($_POST);
1007 1007
 
1008 1008
         // ... form fields...
1009
-        if ( empty( $data['form_id'] ) || 'publish' != get_post_status( $data['form_id'] ) ) {
1009
+        if (empty($data['form_id']) || 'publish' != get_post_status($data['form_id'])) {
1010 1010
             exit;
1011 1011
         }
1012 1012
 
1013 1013
         // ... and form items.
1014
-        $items     = $invoicing->form_elements->get_form_items( $data['form_id'] );
1014
+        $items     = $invoicing->form_elements->get_form_items($data['form_id']);
1015 1015
         $total     = 0;
1016 1016
         $tax       = 0;
1017 1017
         $sub_total = 0;
1018 1018
         $country   = wpinv_default_billing_country();
1019 1019
         $state     = false;
1020 1020
 
1021
-        if ( ! empty( $_POST['wpinv_country'] ) ) {
1021
+        if (!empty($_POST['wpinv_country'])) {
1022 1022
             $country = $_POST['wpinv_country'];
1023 1023
         }
1024 1024
 
1025
-        if ( ! empty( $_POST['wpinv_state'] ) ) {
1025
+        if (!empty($_POST['wpinv_state'])) {
1026 1026
             $state = $_POST['wpinv_state'];
1027 1027
         }
1028 1028
 
1029
-        if ( ! empty( $data['wpinv-items'] ) ) {
1029
+        if (!empty($data['wpinv-items'])) {
1030 1030
 
1031
-            $selected_items = wpinv_clean( $data['wpinv-items'] );
1031
+            $selected_items = wpinv_clean($data['wpinv-items']);
1032 1032
 
1033
-            foreach ( $items as $item ) {
1033
+            foreach ($items as $item) {
1034 1034
 
1035
-                if ( ! isset( $selected_items[ $item['id'] ] ) ) {
1035
+                if (!isset($selected_items[$item['id']])) {
1036 1036
                     continue;
1037 1037
                 }
1038 1038
 
1039 1039
                 $quantity = 1;
1040 1040
 
1041
-                if ( ! empty( $item['allow_quantities'] ) && ! empty( $data["wpinv-item-{$item['id']}-quantity"] ) ) {
1041
+                if (!empty($item['allow_quantities']) && !empty($data["wpinv-item-{$item['id']}-quantity"])) {
1042 1042
 
1043
-                    $quantity = intval( $data["wpinv-item-{$item['id']}-quantity"] );
1043
+                    $quantity = intval($data["wpinv-item-{$item['id']}-quantity"]);
1044 1044
 
1045
-                    if ( 1 > $quantity ) {
1045
+                    if (1 > $quantity) {
1046 1046
                         $quantity = 1;
1047 1047
                     }
1048 1048
 
1049 1049
                 }
1050 1050
 
1051 1051
                 // Custom pricing.
1052
-                $price = wpinv_sanitize_amount( $item['price'] );
1053
-                if ( ! empty( $item['custom_price'] ) ) {
1052
+                $price = wpinv_sanitize_amount($item['price']);
1053
+                if (!empty($item['custom_price'])) {
1054 1054
 
1055
-                    $minimum_price = wpinv_sanitize_amount( $item['minimum_price'] );
1056
-                    $set_price     = wpinv_sanitize_amount( $selected_items[ $item['id'] ] );
1055
+                    $minimum_price = wpinv_sanitize_amount($item['minimum_price']);
1056
+                    $set_price     = wpinv_sanitize_amount($selected_items[$item['id']]);
1057 1057
 
1058
-                    if ( $set_price < $minimum_price ) {
1058
+                    if ($set_price < $minimum_price) {
1059 1059
                         $set_price = $minimum_price;
1060 1060
                     }
1061 1061
 
1062
-                    $price = wpinv_sanitize_amount( $set_price );
1062
+                    $price = wpinv_sanitize_amount($set_price);
1063 1063
 
1064 1064
                 }
1065 1065
 
1066
-                $price  = $quantity * floatval( $price );
1066
+                $price = $quantity * floatval($price);
1067 1067
 
1068
-                if ( wpinv_use_taxes() ) {
1068
+                if (wpinv_use_taxes()) {
1069 1069
 
1070
-                    $rate = wpinv_get_tax_rate( $country, $state, (int) $item['id'] );
1070
+                    $rate = wpinv_get_tax_rate($country, $state, (int) $item['id']);
1071 1071
 
1072
-                    if ( wpinv_prices_include_tax() ) {
1073
-                        $pre_tax  = ( $price - $price * $rate * 0.01 );
1072
+                    if (wpinv_prices_include_tax()) {
1073
+                        $pre_tax  = ($price - $price * $rate * 0.01);
1074 1074
                         $item_tax = $price - $pre_tax;
1075 1075
                     } else {
1076 1076
                         $pre_tax  = $price;
@@ -1082,17 +1082,17 @@  discard block
 block discarded – undo
1082 1082
                     $total     = $sub_total + $tax;
1083 1083
 
1084 1084
                 } else {
1085
-                    $total  = $total + $price;
1085
+                    $total = $total + $price;
1086 1086
                 }
1087 1087
 
1088 1088
             }
1089 1089
 
1090 1090
         }
1091 1091
 
1092
-        wp_send_json_success( array(
1093
-            'total'     => wpinv_price( wpinv_format_amount( $total ) ),
1094
-            'tax'       => wpinv_price( wpinv_format_amount( $tax ) ),
1095
-            'sub_total' => wpinv_price( wpinv_format_amount( $sub_total ) ),
1092
+        wp_send_json_success(array(
1093
+            'total'     => wpinv_price(wpinv_format_amount($total)),
1094
+            'tax'       => wpinv_price(wpinv_format_amount($tax)),
1095
+            'sub_total' => wpinv_price(wpinv_format_amount($sub_total)),
1096 1096
         ));
1097 1097
         exit;
1098 1098
     }
@@ -1105,53 +1105,53 @@  discard block
 block discarded – undo
1105 1105
     public static function buy_items() {
1106 1106
         $user_id = get_current_user_id();
1107 1107
 
1108
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
1109
-            wp_send_json( array(
1110
-                'success' => wp_login_url( wp_get_referer() )
1111
-            ) );
1108
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
1109
+            wp_send_json(array(
1110
+                'success' => wp_login_url(wp_get_referer())
1111
+            ));
1112 1112
         } else {
1113 1113
             // Only check nonce if logged in as it could be cached when logged out.
1114
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
1115
-                wp_send_json( array(
1116
-                    'error' => __( 'Security checks failed.', 'invoicing' )
1117
-                ) );
1114
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
1115
+                wp_send_json(array(
1116
+                    'error' => __('Security checks failed.', 'invoicing')
1117
+                ));
1118 1118
                 wp_die();
1119 1119
             }
1120 1120
 
1121 1121
             // allow to set a custom price through post_id
1122 1122
             $items = $_POST['items'];
1123
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
1124
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
1123
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
1124
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
1125 1125
 
1126 1126
             $cart_items = array();
1127
-            if ( $items ) {
1128
-                $items = explode( ',', $items );
1127
+            if ($items) {
1128
+                $items = explode(',', $items);
1129 1129
 
1130
-                foreach( $items as $item ) {
1130
+                foreach ($items as $item) {
1131 1131
                     $item_id = $item;
1132 1132
                     $quantity = 1;
1133 1133
 
1134
-                    if ( strpos( $item, '|' ) !== false ) {
1135
-                        $item_parts = explode( '|', $item );
1134
+                    if (strpos($item, '|') !== false) {
1135
+                        $item_parts = explode('|', $item);
1136 1136
                         $item_id = $item_parts[0];
1137 1137
                         $quantity = $item_parts[1];
1138 1138
                     }
1139 1139
 
1140
-                    if ( $item_id && $quantity ) {
1140
+                    if ($item_id && $quantity) {
1141 1141
                         $cart_items_arr = array(
1142
-                            'id'            => (int)$item_id,
1143
-                            'quantity'      => (int)$quantity
1142
+                            'id'            => (int) $item_id,
1143
+                            'quantity'      => (int) $quantity
1144 1144
                         );
1145 1145
 
1146 1146
                         // If there is a related post id then add it to meta
1147
-                        if ( $related_post_id ) {
1147
+                        if ($related_post_id) {
1148 1148
                             $cart_items_arr['meta'] = array(
1149 1149
                                 'post_id'   => $related_post_id
1150 1150
                             );
1151 1151
                         }
1152 1152
 
1153 1153
                         // If there is a custom price then set it.
1154
-                        if ( $custom_item_price ) {
1154
+                        if ($custom_item_price) {
1155 1155
                             $cart_items_arr['custom_price'] = $custom_item_price;
1156 1156
                         }
1157 1157
 
@@ -1167,37 +1167,37 @@  discard block
 block discarded – undo
1167 1167
              * @param int $related_post_id The related post id if any.
1168 1168
              * @since 1.0.0
1169 1169
              */
1170
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1170
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1171 1171
 
1172 1172
             // Make sure its not in the cart already, if it is then redirect to checkout.
1173 1173
             $cart_invoice = wpinv_get_invoice_cart();
1174 1174
 
1175
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1176
-                wp_send_json( array(
1175
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1176
+                wp_send_json(array(
1177 1177
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1178
-                ) );
1178
+                ));
1179 1179
                 wp_die();
1180 1180
             }
1181 1181
 
1182 1182
             // Check if user has invoice with same items waiting to be paid.
1183
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1184
-            if ( !empty( $user_invoices ) ) {
1185
-                foreach( $user_invoices as $user_invoice ) {
1183
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1184
+            if (!empty($user_invoices)) {
1185
+                foreach ($user_invoices as $user_invoice) {
1186 1186
                     $user_cart_details = array();
1187
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1187
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1188 1188
                     $cart_details = $invoice->get_cart_details();
1189 1189
 
1190
-                    if ( !empty( $cart_details ) ) {
1191
-                        foreach ( $cart_details as $invoice_item ) {
1190
+                    if (!empty($cart_details)) {
1191
+                        foreach ($cart_details as $invoice_item) {
1192 1192
                             $ii_arr = array();
1193
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1194
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1193
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1194
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1195 1195
 
1196
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1196
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1197 1197
                                 $ii_arr['meta'] = $invoice_item['meta'];
1198 1198
                             }
1199 1199
 
1200
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1200
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1201 1201
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1202 1202
                             }
1203 1203
 
@@ -1205,17 +1205,17 @@  discard block
 block discarded – undo
1205 1205
                         }
1206 1206
                     }
1207 1207
 
1208
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1209
-                        wp_send_json( array(
1208
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1209
+                        wp_send_json(array(
1210 1210
                             'success' =>  $invoice->get_checkout_payment_url()
1211
-                        ) );
1211
+                        ));
1212 1212
                         wp_die();
1213 1213
                     }
1214 1214
                 }
1215 1215
             }
1216 1216
 
1217 1217
             // Create invoice and send user to checkout
1218
-            if ( !empty( $cart_items ) ) {
1218
+            if (!empty($cart_items)) {
1219 1219
                 $invoice_data = array(
1220 1220
                     'status'        =>  'wpi-pending',
1221 1221
                     'created_via'   =>  'wpi',
@@ -1223,21 +1223,21 @@  discard block
 block discarded – undo
1223 1223
                     'cart_details'  =>  $cart_items,
1224 1224
                 );
1225 1225
 
1226
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1226
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1227 1227
 
1228
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1229
-                    wp_send_json( array(
1228
+                if (!empty($invoice) && isset($invoice->ID)) {
1229
+                    wp_send_json(array(
1230 1230
                         'success' =>  $invoice->get_checkout_payment_url()
1231
-                    ) );
1231
+                    ));
1232 1232
                 } else {
1233
-                    wp_send_json( array(
1234
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1235
-                    ) );
1233
+                    wp_send_json(array(
1234
+                        'error' => __('Invoice failed to create', 'invoicing')
1235
+                    ));
1236 1236
                 }
1237 1237
             } else {
1238
-                wp_send_json( array(
1239
-                    'error' => __( 'Items not valid.', 'invoicing' )
1240
-                ) );
1238
+                wp_send_json(array(
1239
+                    'error' => __('Items not valid.', 'invoicing')
1240
+                ));
1241 1241
             }
1242 1242
         }
1243 1243
 
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +246 added lines, -246 removed lines patch added patch discarded remove patch
@@ -7,245 +7,245 @@  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
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
82
+            $date_format = get_option('date_format');
83 83
             
84 84
             $m_time = $post->post_date;
85
-            $h_time = mysql2date( $date_format, $m_time );
85
+            $h_time = mysql2date($date_format, $m_time);
86 86
             
87
-            $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
87
+            $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
88 88
             break;
89 89
         case 'payment_date' :
90
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
91
-                $date_format = get_option( 'date_format' );
90
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
91
+                $date_format = get_option('date_format');
92 92
                 
93 93
                 $m_time = $date_completed;
94
-                $h_time = mysql2date( $date_format, $m_time );
94
+                $h_time = mysql2date($date_format, $m_time);
95 95
                 
96
-                $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
96
+                $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
97 97
             } else {
98 98
                 $value = '-';
99 99
             }
100 100
             break;
101 101
         case 'status' :
102
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
103
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
104
-	        $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() );
102
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
103
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
104
+	        $gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway());
105 105
 	        $offline_gateways = apply_filters('wpinv_offline_payments', array('bank_transfer', 'cheque', 'cod'));
106 106
 	        $is_offline_payment = in_array($wpi_invoice->get_gateway(), $offline_gateways) ? true : false;
107 107
 
108
-            if ( 1 == $is_viewed ) {
109
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
108
+            if (1 == $is_viewed) {
109
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
110 110
             }
111
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment ) && ( isset( $gateway_title ) ) ) {
112
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
111
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded() || $is_offline_payment) && (isset($gateway_title))) {
112
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
113 113
             }
114 114
             break;
115 115
         case 'number' :
116
-            $edit_link = get_edit_post_link( $post->ID );
117
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
116
+            $edit_link = get_edit_post_link($post->ID);
117
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
118 118
             break;
119 119
         case 'wpi_actions' :
120 120
             $value = '';
121
-            if ( !empty( $post->post_name ) ) {
122
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121
+            if (!empty($post->post_name)) {
122
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123 123
             }
124 124
             
125
-            if ( $email = $wpi_invoice->get_email() ) {
126
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125
+            if ($email = $wpi_invoice->get_email()) {
126
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127 127
             }
128 128
             
129 129
             break;
130 130
         default:
131
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
131
+            $value = isset($post->$column_name) ? $post->$column_name : '';
132 132
             break;
133 133
 
134 134
     }
135
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
135
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
136 136
     
137
-    if ( $value !== NULL ) {
137
+    if ($value !== NULL) {
138 138
         echo $value;
139 139
     }
140 140
 }
141 141
 
142
-function wpinv_admin_post_id( $id = 0 ) {
142
+function wpinv_admin_post_id($id = 0) {
143 143
     global $post;
144 144
 
145
-    if ( isset( $id ) && ! empty( $id ) ) {
146
-        return (int)$id;
147
-    } else if ( get_the_ID() ) {
145
+    if (isset($id) && !empty($id)) {
146
+        return (int) $id;
147
+    } else if (get_the_ID()) {
148 148
         return (int) get_the_ID();
149
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
149
+    } else if (isset($post->ID) && !empty($post->ID)) {
150 150
         return (int) $post->ID;
151
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
151
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
152 152
         return (int) $_GET['post'];
153
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
153
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
154 154
         return (int) $_GET['id'];
155
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
155
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
156 156
         return (int) $_POST['id'];
157 157
     } 
158 158
 
159 159
     return null;
160 160
 }
161 161
     
162
-function wpinv_admin_post_type( $id = 0 ) {
163
-    if ( !$id ) {
162
+function wpinv_admin_post_type($id = 0) {
163
+    if (!$id) {
164 164
         $id = wpinv_admin_post_id();
165 165
     }
166 166
     
167
-    $type = get_post_type( $id );
167
+    $type = get_post_type($id);
168 168
     
169
-    if ( !$type ) {
170
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
169
+    if (!$type) {
170
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
171 171
     }
172 172
     
173
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
173
+    return apply_filters('wpinv_admin_post_type', $type, $id);
174 174
 }
175 175
 
176 176
 function wpinv_admin_messages() {
177 177
 	global $wpinv_options, $pagenow, $post;
178 178
 
179
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
180
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
179
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
180
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
181 181
 	}
182 182
 
183
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
184
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
183
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
184
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
185 185
 	}
186 186
 
187
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
188
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
187
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
188
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
189 189
 	}
190 190
 
191
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
192
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
191
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
192
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
193 193
 	}
194 194
 
195
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
196
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
195
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
196
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
197 197
 	}
198 198
 
199
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
200
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
199
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
200
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
201 201
 	}
202 202
 
203
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
204
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
203
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
204
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
205 205
 	}
206 206
 
207
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
208
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
207
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
208
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
209 209
     }
210 210
     
211
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
212
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
211
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
212
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
213 213
     }
214 214
 
215
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
216
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
215
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
216
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
217 217
     }
218 218
 
219
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
220
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
219
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
220
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
221 221
 	}
222 222
 
223
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
224
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
223
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
224
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
225 225
 	}
226 226
 
227
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing() ) {
228
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
227
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && wpinv_current_user_can_manage_invoicing()) {
228
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
229 229
 	}
230 230
     
231
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
232
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
231
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
232
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
233 233
 
234
-		if ( !empty( $message ) ) {
235
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
234
+		if (!empty($message)) {
235
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
236 236
 		}
237 237
 	}
238 238
 
239
-	settings_errors( 'wpinv-notices' );
239
+	settings_errors('wpinv-notices');
240 240
 }
241
-add_action( 'admin_notices', 'wpinv_admin_messages' );
241
+add_action('admin_notices', 'wpinv_admin_messages');
242 242
 
243
-add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' );
244
-function wpinv_show_test_payment_gateway_notice(){
245
-    add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' );
243
+add_action('admin_init', 'wpinv_show_test_payment_gateway_notice');
244
+function wpinv_show_test_payment_gateway_notice() {
245
+    add_action('admin_notices', 'wpinv_test_payment_gateway_messages');
246 246
 }
247 247
 
248
-function wpinv_test_payment_gateway_messages(){
248
+function wpinv_test_payment_gateway_messages() {
249 249
     $gateways = wpinv_get_enabled_payment_gateways();
250 250
     $name = array(); $test_gateways = '';
251 251
     if ($gateways) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         }
257 257
         $test_gateways = implode(', ', $name);
258 258
     }
259
-    if(isset($test_gateways) && !empty($test_gateways)){
259
+    if (isset($test_gateways) && !empty($test_gateways)) {
260 260
         $link = admin_url('admin.php?page=wpinv-settings&tab=gateways');
261
-        $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link );
261
+        $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link);
262 262
         ?>
263 263
         <div class="notice notice-warning is-dismissible">
264 264
             <p><?php echo $notice; ?></p>
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
     }
268 268
 }
269 269
 
270
-function wpinv_items_columns( $existing_columns ) {
270
+function wpinv_items_columns($existing_columns) {
271 271
     global $wpinv_euvat;
272 272
     
273 273
     $columns                = array();
274 274
     $columns['cb']          = $existing_columns['cb'];
275
-    $columns['title']       = __( 'Title', 'invoicing' );
276
-    $columns['price']       = __( 'Price', 'invoicing' );
277
-    if ( $wpinv_euvat->allow_vat_rules() ) {
278
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
275
+    $columns['title']       = __('Title', 'invoicing');
276
+    $columns['price']       = __('Price', 'invoicing');
277
+    if ($wpinv_euvat->allow_vat_rules()) {
278
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
279 279
     }
280
-    if ( $wpinv_euvat->allow_vat_classes() ) {
281
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
280
+    if ($wpinv_euvat->allow_vat_classes()) {
281
+        $columns['vat_class']   = __('VAT class', 'invoicing');
282 282
     }
283
-    $columns['type']        = __( 'Type', 'invoicing' );
284
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
285
-    $columns['date']        = __( 'Date', 'invoicing' );
286
-    $columns['id']          = __( 'ID', 'invoicing' );
283
+    $columns['type']        = __('Type', 'invoicing');
284
+    $columns['recurring']   = __('Recurring', 'invoicing');
285
+    $columns['date']        = __('Date', 'invoicing');
286
+    $columns['id']          = __('ID', 'invoicing');
287 287
 
288
-    return apply_filters( 'wpinv_items_columns', $columns );
288
+    return apply_filters('wpinv_items_columns', $columns);
289 289
 }
290
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
290
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
291 291
 
292
-function wpinv_items_sortable_columns( $columns ) {
292
+function wpinv_items_sortable_columns($columns) {
293 293
     $columns['price']       = 'price';
294 294
     $columns['vat_rule']    = 'vat_rule';
295 295
     $columns['vat_class']   = 'vat_class';
@@ -299,175 +299,175 @@  discard block
 block discarded – undo
299 299
 
300 300
     return $columns;
301 301
 }
302
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
302
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
303 303
 
304
-function wpinv_items_table_custom_column( $column ) {
304
+function wpinv_items_table_custom_column($column) {
305 305
     global $wpinv_euvat, $post, $wpi_item;
306 306
     
307
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
308
-        $wpi_item = new WPInv_Item( $post->ID );
307
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
308
+        $wpi_item = new WPInv_Item($post->ID);
309 309
     }
310 310
 
311
-    switch ( $column ) {
311
+    switch ($column) {
312 312
         case 'price' :
313
-            echo wpinv_item_price( $post->ID );
313
+            echo wpinv_item_price($post->ID);
314 314
         break;
315 315
         case 'vat_rule' :
316
-            echo $wpinv_euvat->item_rule_label( $post->ID );
316
+            echo $wpinv_euvat->item_rule_label($post->ID);
317 317
         break;
318 318
         case 'vat_class' :
319
-            echo $wpinv_euvat->item_class_label( $post->ID );
319
+            echo $wpinv_euvat->item_class_label($post->ID);
320 320
         break;
321 321
         case 'type' :
322
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
322
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
323 323
         break;
324 324
         case 'recurring' :
325
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
325
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
326 326
         break;
327 327
         case 'id' :
328 328
            echo $post->ID;
329 329
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
330
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
331
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
332
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
330
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
331
+                    if ($wpinv_euvat->allow_vat_rules()) {
332
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
333 333
                     }
334
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
335
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
334
+                    if ($wpinv_euvat->allow_vat_classes()) {
335
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
336 336
                     }
337
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
337
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
338 338
                 </div>';
339 339
         break;
340 340
     }
341 341
     
342
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
342
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
343 343
 }
344
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
344
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
345 345
 
346 346
 function wpinv_add_items_filters() {
347 347
     global $wpinv_euvat, $typenow;
348 348
 
349 349
     // Checks if the current post type is 'item'
350
-    if ( $typenow == 'wpi_item') {
351
-        if ( $wpinv_euvat->allow_vat_rules() ) {
350
+    if ($typenow == 'wpi_item') {
351
+        if ($wpinv_euvat->allow_vat_rules()) {
352 352
 
353 353
             // Sanitize selected vat rule.
354
-            $vat_rule   = '';
355
-            if( isset( $_GET['vat_rule'] ) && array_key_exists(  $_GET['type'], $wpinv_euvat->get_rules() ) ) {
356
-                $class   =  $_GET['type'];
354
+            $vat_rule = '';
355
+            if (isset($_GET['vat_rule']) && array_key_exists($_GET['type'], $wpinv_euvat->get_rules())) {
356
+                $class = $_GET['type'];
357 357
             }
358 358
 
359
-            echo wpinv_html_select( array(
360
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
359
+            echo wpinv_html_select(array(
360
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
361 361
                     'name'             => 'vat_rule',
362 362
                     'id'               => 'vat_rule',
363
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
363
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
364 364
                     'show_option_all'  => false,
365 365
                     'show_option_none' => false,
366 366
                     'class'            => 'gdmbx2-text-medium wpi_select2',
367
-                    'placeholder'      => __( 'Select VAT rule', 'invoicing' ),
368
-                ) );
367
+                    'placeholder'      => __('Select VAT rule', 'invoicing'),
368
+                ));
369 369
         }
370 370
 
371
-        if ( $wpinv_euvat->allow_vat_classes() ) {
371
+        if ($wpinv_euvat->allow_vat_classes()) {
372 372
 
373 373
             $classes = $wpinv_euvat->get_all_classes();
374 374
 
375 375
             // Sanitize selected vat class.
376 376
             $class   = '';
377
-            if( isset( $_GET['vat_class'] ) && array_key_exists(  $_GET['vat_class'], $classes ) ) {
378
-                $class   =  $_GET['vat_class'];
377
+            if (isset($_GET['vat_class']) && array_key_exists($_GET['vat_class'], $classes)) {
378
+                $class = $_GET['vat_class'];
379 379
             }
380 380
 
381
-            echo wpinv_html_select( array(
382
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $classes ),
381
+            echo wpinv_html_select(array(
382
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $classes),
383 383
                     'name'             => 'vat_class',
384 384
                     'id'               => 'vat_class',
385 385
                     'selected'         => $class,
386 386
                     'show_option_all'  => false,
387 387
                     'show_option_none' => false,
388 388
                     'class'            => 'gdmbx2-text-medium wpi_select2',
389
-                    'placeholder'      => __( 'Select VAT class', 'invoicing' ),
390
-                ) );
389
+                    'placeholder'      => __('Select VAT class', 'invoicing'),
390
+                ));
391 391
         }
392 392
         
393 393
         // Sanitize selected item type.
394
-        $type   = '';
395
-        if( isset( $_GET['type'] ) && array_key_exists(  $_GET['type'], wpinv_get_item_types() ) ) {
396
-            $class   =  $_GET['type'];
394
+        $type = '';
395
+        if (isset($_GET['type']) && array_key_exists($_GET['type'], wpinv_get_item_types())) {
396
+            $class = $_GET['type'];
397 397
         }
398 398
 
399
-        echo wpinv_html_select( array(
400
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
399
+        echo wpinv_html_select(array(
400
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
401 401
                 'name'             => 'type',
402 402
                 'id'               => 'type',
403 403
                 'selected'         => $type,
404 404
                 'show_option_all'  => false,
405 405
                 'show_option_none' => false,
406 406
                 'class'            => 'gdmbx2-text-medium',
407
-            ) );
407
+            ));
408 408
 
409
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
409
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
410 410
             echo '<input type="hidden" name="all_posts" value="1" />';
411 411
         }
412 412
     }
413 413
 }
414
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
414
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
415 415
 
416
-function wpinv_send_invoice_after_save( $invoice ) {
417
-    if ( empty( $_POST['wpi_save_send'] ) ) {
416
+function wpinv_send_invoice_after_save($invoice) {
417
+    if (empty($_POST['wpi_save_send'])) {
418 418
         return;
419 419
     }
420 420
     
421
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
422
-        wpinv_user_invoice_notification( $invoice->ID );
421
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
422
+        wpinv_user_invoice_notification($invoice->ID);
423 423
     }
424 424
 }
425
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
425
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
426 426
 
427
-function wpinv_send_register_new_user( $data, $postarr ) {
428
-    if ( wpinv_current_user_can_manage_invoicing() && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
429
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
430
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
427
+function wpinv_send_register_new_user($data, $postarr) {
428
+    if (wpinv_current_user_can_manage_invoicing() && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
429
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
430
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
431 431
         
432
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
433
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
434
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
435
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
436
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
437
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
432
+        if ($is_new_user && $email && !email_exists($email)) {
433
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
434
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
435
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
436
+            $user_nicename = $display_name ? trim($display_name) : $email;
437
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
438 438
             
439
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
440
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
439
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
440
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
441 441
                 $new_user_login = strstr($email, '@', true);
442
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
443
-                    $user_login = sanitize_user($new_user_login, true );
442
+                if (validate_username($user_login) && username_exists($user_login)) {
443
+                    $user_login = sanitize_user($new_user_login, true);
444 444
                 }
445
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
446
-                    $user_append_text = rand(10,1000);
447
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
445
+                if (validate_username($user_login) && username_exists($user_login)) {
446
+                    $user_append_text = rand(10, 1000);
447
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
448 448
                 }
449 449
                 
450
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
450
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
451 451
                     $user_login = $email;
452 452
                 }
453 453
             }
454 454
             
455 455
             $userdata = array(
456 456
                 'user_login' => $user_login,
457
-                'user_pass' => wp_generate_password( 12, false ),
458
-                'user_email' => sanitize_text_field( $email ),
457
+                'user_pass' => wp_generate_password(12, false),
458
+                'user_email' => sanitize_text_field($email),
459 459
                 'first_name' => $first_name,
460 460
                 'last_name' => $last_name,
461
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
461
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
462 462
                 'nickname' => $display_name,
463 463
                 'display_name' => $display_name,
464 464
             );
465 465
 
466
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
466
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
467 467
             
468
-            $new_user_id = wp_insert_user( $userdata );
468
+            $new_user_id = wp_insert_user($userdata);
469 469
             
470
-            if ( !is_wp_error( $new_user_id ) ) {
470
+            if (!is_wp_error($new_user_id)) {
471 471
                 $data['post_author'] = $new_user_id;
472 472
                 $_POST['post_author'] = $new_user_id;
473 473
                 $_POST['post_author_override'] = $new_user_id;
@@ -488,86 +488,86 @@  discard block
 block discarded – undo
488 488
                 
489 489
                 $meta = array();
490 490
                 ///$meta['_wpinv_user_id'] = $new_user_id;
491
-                foreach ( $meta_fields as $field ) {
492
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
491
+                foreach ($meta_fields as $field) {
492
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
493 493
                 }
494 494
                 
495
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
495
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
496 496
 
497 497
                 // Update user meta.
498
-                foreach ( $meta as $key => $value ) {
499
-                    update_user_meta( $new_user_id, $key, $value );
498
+                foreach ($meta as $key => $value) {
499
+                    update_user_meta($new_user_id, $key, $value);
500 500
                 }
501 501
                 
502
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
502
+                if (function_exists('wp_send_new_user_notifications')) {
503 503
                     // Send email notifications related to the creation of new user.
504
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
504
+                    wp_send_new_user_notifications($new_user_id, 'user');
505 505
                 }
506 506
             } else {
507
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
507
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
508 508
             }
509 509
         }
510 510
     }
511 511
     
512 512
     return $data;
513 513
 }
514
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
514
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
515 515
 
516
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
516
+function wpinv_show_recurring_supported_gateways($item_ID) {
517 517
     $all_gateways = wpinv_get_payment_gateways();
518 518
 
519
-    if ( !empty( $all_gateways ) ) {
519
+    if (!empty($all_gateways)) {
520 520
         $gateways = array();
521 521
 
522
-        foreach ( $all_gateways as $key => $gateway ) {
523
-            if ( wpinv_gateway_support_subscription( $key ) ) {
522
+        foreach ($all_gateways as $key => $gateway) {
523
+            if (wpinv_gateway_support_subscription($key)) {
524 524
                 $gateways[] = $gateway['admin_label'];
525 525
             }
526 526
         }
527 527
 
528
-        if ( !empty( $gateways ) ) {
528
+        if (!empty($gateways)) {
529 529
             ?>
530
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
530
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
531 531
             <?php
532 532
         }
533 533
     }
534 534
 }
535
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
535
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
536 536
 
537
-function wpinv_post_updated_messages( $messages ) {
537
+function wpinv_post_updated_messages($messages) {
538 538
     global $post, $post_ID;
539 539
 
540 540
     $messages['wpi_discount'] = array(
541 541
         0   => '',
542
-        1   => __( 'Discount updated.', 'invoicing' ),
543
-        2   => __( 'Custom field updated.', 'invoicing' ),
544
-        3   => __( 'Custom field deleted.', 'invoicing' ),
545
-        4   => __( 'Discount updated.', 'invoicing' ),
546
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
547
-        6   => __( 'Discount updated.', 'invoicing' ),
548
-        7   => __( 'Discount saved.', 'invoicing' ),
549
-        8   => __( 'Discount submitted.', 'invoicing' ),
550
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
551
-        10  => __( 'Discount draft updated.', 'invoicing' ),
542
+        1   => __('Discount updated.', 'invoicing'),
543
+        2   => __('Custom field updated.', 'invoicing'),
544
+        3   => __('Custom field deleted.', 'invoicing'),
545
+        4   => __('Discount updated.', 'invoicing'),
546
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
547
+        6   => __('Discount updated.', 'invoicing'),
548
+        7   => __('Discount saved.', 'invoicing'),
549
+        8   => __('Discount submitted.', 'invoicing'),
550
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
551
+        10  => __('Discount draft updated.', 'invoicing'),
552 552
     );
553 553
 
554 554
     $messages['wpi_payment_form'] = array(
555 555
         0   => '',
556
-        1   => __( 'Payment Form updated.', 'invoicing' ),
557
-        2   => __( 'Custom field updated.', 'invoicing' ),
558
-        3   => __( 'Custom field deleted.', 'invoicing' ),
559
-        4   => __( 'Payment Form updated.', 'invoicing' ),
560
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Payment Form restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
561
-        6   => __( 'Payment Form updated.', 'invoicing' ),
562
-        7   => __( 'Payment Form saved.', 'invoicing' ),
563
-        8   => __( 'Payment Form submitted.', 'invoicing' ),
564
-        9   => wp_sprintf( __( 'Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
565
-        10  => __( 'Payment Form draft updated.', 'invoicing' ),
556
+        1   => __('Payment Form updated.', 'invoicing'),
557
+        2   => __('Custom field updated.', 'invoicing'),
558
+        3   => __('Custom field deleted.', 'invoicing'),
559
+        4   => __('Payment Form updated.', 'invoicing'),
560
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Payment Form restored to revision from %s', 'invoicing'), wp_post_revision_title((int) $_GET['revision'], false)) : false,
561
+        6   => __('Payment Form updated.', 'invoicing'),
562
+        7   => __('Payment Form saved.', 'invoicing'),
563
+        8   => __('Payment Form submitted.', 'invoicing'),
564
+        9   => wp_sprintf(__('Payment Form scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
565
+        10  => __('Payment Form draft updated.', 'invoicing'),
566 566
     );
567 567
 
568 568
     return $messages;
569 569
 }
570
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
570
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
571 571
 
572 572
 add_action('admin_init', 'admin_init_example_type');
573 573
 
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 function admin_init_example_type() {
578 578
     global $typenow;
579 579
 
580
-    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) {
580
+    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') {
581 581
         add_filter('posts_search', 'posts_search_example_type', 10, 2);
582 582
     }
583 583
 }
@@ -592,9 +592,9 @@  discard block
 block discarded – undo
592 592
     global $wpdb;
593 593
 
594 594
     if ($query->is_main_query() && !empty($query->query['s'])) {
595
-        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )";
596
-        if ( ! empty( $search ) ) {
597
-            $search = preg_replace( '/^ AND /', '', $search );
595
+        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )";
596
+        if (!empty($search)) {
597
+            $search = preg_replace('/^ AND /', '', $search);
598 598
             $search = " AND ( {$search} OR ( {$conditions_str} ) )";
599 599
         } else {
600 600
             $search = " AND ( {$conditions_str} )";
@@ -604,9 +604,9 @@  discard block
 block discarded – undo
604 604
     return $search;
605 605
 }
606 606
 
607
-add_action( 'admin_init', 'wpinv_reset_invoice_count' );
608
-function wpinv_reset_invoice_count(){
609
-    if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
607
+add_action('admin_init', 'wpinv_reset_invoice_count');
608
+function wpinv_reset_invoice_count() {
609
+    if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
610 610
         wpinv_update_option('invoice_sequence_start', 1);
611 611
         delete_option('wpinv_last_invoice_number');
612 612
         $url = add_query_arg(array('reset_invoice_done' => 1));
@@ -617,8 +617,8 @@  discard block
 block discarded – undo
617 617
 }
618 618
 
619 619
 add_action('admin_notices', 'wpinv_invoice_count_reset_message');
620
-function wpinv_invoice_count_reset_message(){
621
-    if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
620
+function wpinv_invoice_count_reset_message() {
621
+    if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
622 622
         $notice = __('Invoice number sequence reset successfully.', 'invoicing');
623 623
         ?>
624 624
         <div class="notice notice-success is-dismissible">
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-payment-form.php 1 patch
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Payment_Form {
@@ -11,23 +11,23 @@  discard block
 block discarded – undo
11 11
      *
12 12
      * @param WP_Post $post
13 13
      */
14
-    public static function output_details( $post ) {
15
-        $details = get_post_meta( $post->ID, 'payment_form_data', true );
14
+    public static function output_details($post) {
15
+        $details = get_post_meta($post->ID, 'payment_form_data', true);
16 16
 
17
-        if ( ! is_array( $details ) ) {
17
+        if (!is_array($details)) {
18 18
             return;
19 19
         }
20 20
 
21 21
         echo '<div class="gdmbx2-wrap form-table"> <div class="gdmbx2-metabox gdmbx-field-list">';
22 22
 
23
-        foreach ( $details as $key => $value ) {
24
-            $key = sanitize_text_field( $key );
23
+        foreach ($details as $key => $value) {
24
+            $key = sanitize_text_field($key);
25 25
 
26
-            if ( is_array( $value ) ) {
27
-                $value = implode( ',', $value );
26
+            if (is_array($value)) {
27
+                $value = implode(',', $value);
28 28
             }
29 29
 
30
-            $value = esc_html( $value );
30
+            $value = esc_html($value);
31 31
 
32 32
             echo "<div class='gdmbx-row gdmbx-type-select'>";
33 33
             echo "<div class='gdmbx-th'><label>$key:</label></div>";
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
      *
44 44
      * @param WP_Post $post
45 45
      */
46
-    public static function output_shortcode( $post ) {
46
+    public static function output_shortcode($post) {
47 47
 
48
-        if ( ! is_numeric( $post ) ) {
48
+        if (!is_numeric($post)) {
49 49
             $post = $post->ID;
50 50
         }
51 51
 
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
      *
58 58
      * @param WP_Post $post
59 59
      */
60
-    public static function output ( $post ) {
61
-        $success_page        = get_post_meta( $post->ID, 'wpinv_success_page', true );
62
-        $success_page        = empty( $success_page ) ? wpinv_get_success_page_uri() : $success_page
60
+    public static function output($post) {
61
+        $success_page        = get_post_meta($post->ID, 'wpinv_success_page', true);
62
+        $success_page        = empty($success_page) ? wpinv_get_success_page_uri() : $success_page
63 63
         ?>
64 64
 
65 65
         <div id="wpinv-form-builder" style="display: flex; flex-flow: wrap;">
@@ -67,20 +67,20 @@  discard block
 block discarded – undo
67 67
             <div class="wpinv-form-builder-left bsui" style="flex: 0 0 320px;">
68 68
                 <ul class="wpinv-form-builder-tabs  nav nav-tabs">
69 69
                     <li class='nav-item' v-if="active_tab!='new_item'">
70
-                        <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e( 'Add new element', 'invoicing' ); ?></a>
70
+                        <a @click.prevent="active_tab='new_item'" class="nav-link p-3" :class="{ 'active': active_tab=='new_item' }" href="#"><?php _e('Add new element', 'invoicing'); ?></a>
71 71
                     </li>
72 72
                     <li class='nav-item' v-if='false'>
73
-                        <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e( 'Edit element', 'invoicing' ); ?></a>
73
+                        <a @click.prevent="active_tab='edit_item'" class="nav-link p-3" :class="{ 'active': active_tab=='edit_item' }" href="#"><?php _e('Edit element', 'invoicing'); ?></a>
74 74
                     </li>
75 75
                     <li class='nav-item' v-if='false'>
76
-                        <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e( 'Settings', 'invoicing' ); ?></a>
76
+                        <a @click.prevent="active_tab='settings'" class="nav-link p-3" :class="{ 'active': active_tab=='settings' }" href="#"><?php _e('Settings', 'invoicing'); ?></a>
77 77
                     </li>
78 78
                 </ul>
79 79
 
80 80
                 <div class="wpinv-form-builder-tab-content bsui" style="margin-top: 16px;">
81 81
                     <div class="wpinv-form-builder-tab-pane" v-if="active_tab=='new_item'">
82 82
                         <div class="wpinv-form-builder-add-field-types">
83
-                            <small class='form-text text-muted'><?php _e( 'Add an element by dragging it to the payment form.', 'invoicing' ); ?></small>
83
+                            <small class='form-text text-muted'><?php _e('Add an element by dragging it to the payment form.', 'invoicing'); ?></small>
84 84
                             <draggable class="section mt-2" style="display: flex; flex-flow: wrap; justify-content: space-between;" v-model="elements" :group="{ name: 'fields', pull: 'clone', put: false }" :sort="false" :clone="addDraggedField" tag="ul" filter=".wpinv-undraggable">
85 85
                                 <li v-for="element in elements" class= "wpinv-payment-form-left-fields-field" @click.prevent="addField(element)" :class="{ 'd-none': element.defaults.premade }">
86 86
                                     <button class="button btn">
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 
96 96
                     <div class="wpinv-form-builder-tab-pane bsui" v-if="active_tab=='edit_item'" style="font-size: 16px;">
97 97
                         <div class="wpinv-form-builder-edit-field-wrapper">
98
-                            <?php do_action( 'wpinv_payment_form_edit_element_template', 'active_form_element', $post ); ?>
98
+                            <?php do_action('wpinv_payment_form_edit_element_template', 'active_form_element', $post); ?>
99 99
                             <div>
100
-                                <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e( 'Delete Field', 'invoicing' ); ?></button>
100
+                                <button type="button" class="button button-link button-link-delete" @click.prevent="removeField(active_form_element)" v-show="! active_form_element.premade"><?php _e('Delete Field', 'invoicing'); ?></button>
101 101
                             </div>
102 102
                         </div>
103 103
                     </div>
@@ -106,9 +106,9 @@  discard block
 block discarded – undo
106 106
                         <div class="wpinv-form-builder-settings-wrapper">
107 107
                         
108 108
                             <div class='form-group'>
109
-                                <label for="wpi-success-page"><?php _e( 'Success Page', 'invoicing' ); ?></label>
110
-                                <input  placeholder="https://" id='wpi-success-page' value="<?php echo esc_url( $success_page ); ?>" class='form-control' type='text'>
111
-                                <small class='form-text text-muted'><?php _e( 'Where should we redirect users after successfuly completing their payment?', 'invoicing' ); ?></small>
109
+                                <label for="wpi-success-page"><?php _e('Success Page', 'invoicing'); ?></label>
110
+                                <input  placeholder="https://" id='wpi-success-page' value="<?php echo esc_url($success_page); ?>" class='form-control' type='text'>
111
+                                <small class='form-text text-muted'><?php _e('Where should we redirect users after successfuly completing their payment?', 'invoicing'); ?></small>
112 112
                             </div>
113 113
 
114 114
                         </div>
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 
120 120
             <div class="wpinv-form-builder-right" style="flex: 1; padding-top: 40px;border-left: 1px solid #ddd;padding-left: 20px;min-height: 520px;margin-left: 10px;">
121 121
 
122
-                <small class='form-text text-muted' v-if='form_elements.length'><?php _e( 'Click on any element to edit or delete it.', 'invoicing' ); ?></small>
123
-                <p class='form-text text-muted' v-if='! form_elements.length'><?php _e( 'This form is empty. Add new elements by dragging them from the right.', 'invoicing' ); ?></p>
122
+                <small class='form-text text-muted' v-if='form_elements.length'><?php _e('Click on any element to edit or delete it.', 'invoicing'); ?></small>
123
+                <p class='form-text text-muted' v-if='! form_elements.length'><?php _e('This form is empty. Add new elements by dragging them from the right.', 'invoicing'); ?></p>
124 124
 
125 125
                 <draggable class="section bsui" v-model="form_elements" @add="highlightLastDroppedField" group="fields" tag="div" style="min-height: 100%; font-size: 16px;">
126 126
                     <div v-for="form_element in form_elements" class="wpinv-form-builder-element-preview" :class="{ active: active_form_element==form_element &&  active_tab=='edit_item' }" @click="active_tab = 'edit_item'; active_form_element = form_element">
127
-                        <?php do_action( 'wpinv_payment_form_render_element_template', 'form_element', $post ); ?>
127
+                        <?php do_action('wpinv_payment_form_render_element_template', 'form_element', $post); ?>
128 128
                     </div>
129 129
                 </draggable>
130 130
             </div>
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
             <textarea style="display:none;" name="wpinv_form_items" v-model="itemString"></textarea>
134 134
         </div>
135 135
         
136
-        <?php wp_nonce_field( 'wpinv_save_payment_form', 'wpinv_save_payment_form' ) ;?>
136
+        <?php wp_nonce_field('wpinv_save_payment_form', 'wpinv_save_payment_form'); ?>
137 137
 
138 138
         <?php
139 139
     }
@@ -141,83 +141,83 @@  discard block
 block discarded – undo
141 141
     /**
142 142
      * Saves our payment forms.
143 143
      */
144
-    public static function save( $post_id, $post ) {
144
+    public static function save($post_id, $post) {
145 145
 
146
-        remove_action( 'save_post', 'WPInv_Meta_Box_Payment_Form::save' );
146
+        remove_action('save_post', 'WPInv_Meta_Box_Payment_Form::save');
147 147
 
148 148
         // $post_id and $post are required.
149
-        if ( empty( $post_id ) || empty( $post ) ) {
149
+        if (empty($post_id) || empty($post)) {
150 150
             return;
151 151
         }
152 152
         
153 153
         // Ensure that this user can edit the post.
154
-        if ( ! current_user_can( 'edit_post', $post_id ) ) {
154
+        if (!current_user_can('edit_post', $post_id)) {
155 155
             return;
156 156
         }
157 157
 
158 158
         // Dont' save meta boxes for revisions or autosaves
159
-        if ( defined( 'DOING_AUTOSAVE' ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
159
+        if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
160 160
             return;
161 161
         }
162 162
 
163 163
         // Do not save for ajax requests.
164
-        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
164
+        if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
165 165
             return;
166 166
         }
167 167
 
168 168
         // Confirm the security nonce.
169
-        if ( empty( $_POST['wpinv_save_payment_form'] ) || ! wp_verify_nonce( $_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form' ) ) {
169
+        if (empty($_POST['wpinv_save_payment_form']) || !wp_verify_nonce($_POST['wpinv_save_payment_form'], 'wpinv_save_payment_form')) {
170 170
             return;
171 171
         }
172 172
 
173 173
         // Save form items.
174
-        $form_items = json_decode( wp_unslash( $_POST['wpinv_form_items'] ), true );
174
+        $form_items = json_decode(wp_unslash($_POST['wpinv_form_items']), true);
175 175
 
176
-        if ( empty( $form_items ) ) {
176
+        if (empty($form_items)) {
177 177
             $form_items = array();
178 178
         }
179 179
 
180
-        update_post_meta( $post_id, 'wpinv_form_items', self::maybe_save_items( $form_items ) );
180
+        update_post_meta($post_id, 'wpinv_form_items', self::maybe_save_items($form_items));
181 181
 
182 182
         // Save form elements.
183
-        $wpinv_form_elements = json_decode( wp_unslash( $_POST['wpinv_form_elements'] ), true );
184
-        if ( empty( $wpinv_form_elements ) ) {
183
+        $wpinv_form_elements = json_decode(wp_unslash($_POST['wpinv_form_elements']), true);
184
+        if (empty($wpinv_form_elements)) {
185 185
             $wpinv_form_elements = array();
186 186
         }
187 187
 
188
-        update_post_meta( $post_id, 'wpinv_form_elements', $wpinv_form_elements );
188
+        update_post_meta($post_id, 'wpinv_form_elements', $wpinv_form_elements);
189 189
     }
190 190
 
191 191
     /**
192 192
      * Saves unsaved form items.
193 193
      */
194
-    public static function maybe_save_items( $items ) {
194
+    public static function maybe_save_items($items) {
195 195
 
196 196
         $saved = array();
197 197
 
198
-        foreach( $items as $item ) {
198
+        foreach ($items as $item) {
199 199
 
200
-            if ( is_numeric( $item['id'] ) ) {
200
+            if (is_numeric($item['id'])) {
201 201
                 $saved[] = $item;
202 202
                 continue;
203 203
             }
204 204
 
205 205
             $data = array(
206
-                'post_title'   => sanitize_text_field( $item['title'] ),
207
-                'post_excerpt' => wp_kses_post( $item['description'] ),
206
+                'post_title'   => sanitize_text_field($item['title']),
207
+                'post_excerpt' => wp_kses_post($item['description']),
208 208
                 'post_status'  => 'publish',
209 209
                 'meta'         => array(
210 210
                     'type'      => 'custom',
211
-                    'price'     => wpinv_sanitize_amount( $item['price'] ),
211
+                    'price'     => wpinv_sanitize_amount($item['price']),
212 212
                     'vat_rule'  => 'digital',
213 213
                     'vat_class' => '_standard',
214 214
                 )
215 215
             );
216 216
             
217
-            $new_item  = new WPInv_Item();
218
-            $new_item->create( $data );
217
+            $new_item = new WPInv_Item();
218
+            $new_item->create($data);
219 219
     
220
-            if ( ! empty( $new_item ) ) {
220
+            if (!empty($new_item)) {
221 221
                 $item['id'] = $new_item->ID;
222 222
                 $saved[] = $item;
223 223
             }
@@ -230,5 +230,5 @@  discard block
 block discarded – undo
230 230
 
231 231
 }
232 232
 
233
-add_action( 'save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2 );
233
+add_action('save_post_wpi_payment_form', 'WPInv_Meta_Box_Payment_Form::save', 10, 2);
234 234
 
Please login to merge, or discard this patch.
includes/class-wpinv-payment-form-elements.php 1 patch
Spacing   +579 added lines, -579 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3
-if ( ! defined( 'ABSPATH' ) ) {
3
+if (!defined('ABSPATH')) {
4 4
     exit; // Exit if accessed directly
5 5
 }
6 6
 
@@ -13,19 +13,19 @@  discard block
 block discarded – undo
13 13
 
14 14
     public function __construct() {
15 15
 
16
-        foreach( $this->get_elements() as $element ) {
16
+        foreach ($this->get_elements() as $element) {
17 17
             $element = $element['type'];
18 18
 
19
-            if ( method_exists( $this, "render_{$element}_template" ) ) {
20
-                add_action( 'wpinv_payment_form_render_element_template', array( $this, "render_{$element}_template" ), 10, 2 );
19
+            if (method_exists($this, "render_{$element}_template")) {
20
+                add_action('wpinv_payment_form_render_element_template', array($this, "render_{$element}_template"), 10, 2);
21 21
             }
22 22
 
23
-            if ( method_exists( $this, "edit_{$element}_template" ) ) {
24
-                add_action( 'wpinv_payment_form_edit_element_template', array( $this, "edit_{$element}_template" ), 10, 2 );
23
+            if (method_exists($this, "edit_{$element}_template")) {
24
+                add_action('wpinv_payment_form_edit_element_template', array($this, "edit_{$element}_template"), 10, 2);
25 25
             }
26 26
 
27
-            if ( method_exists( $this, "frontend_render_{$element}_template" ) ) {
28
-                add_action( "wpinv_frontend_render_payment_form_$element", array( $this, "frontend_render_{$element}_template" ), 10, 3 );
27
+            if (method_exists($this, "frontend_render_{$element}_template")) {
28
+                add_action("wpinv_frontend_render_payment_form_$element", array($this, "frontend_render_{$element}_template"), 10, 3);
29 29
             }
30 30
 
31 31
         }
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function get_elements() {
39 39
 
40
-        if ( ! empty( $this->elements ) ) {
40
+        if (!empty($this->elements)) {
41 41
             return $this->elements;
42 42
         }
43 43
 
@@ -45,28 +45,28 @@  discard block
 block discarded – undo
45 45
 
46 46
             array(
47 47
                 'type'     => 'heading',
48
-                'name'     => __( 'Heading', 'invoicing' ),
48
+                'name'     => __('Heading', 'invoicing'),
49 49
                 'defaults' => array(
50 50
                     'level' => 'h2',
51
-                    'text'  => __( 'Heading', 'invoicing' ),
51
+                    'text'  => __('Heading', 'invoicing'),
52 52
                 )
53 53
             ),
54 54
 
55 55
             array(
56 56
                 'type' => 'paragraph',
57
-                'name' => __( 'Paragraph', 'invoicing' ),
57
+                'name' => __('Paragraph', 'invoicing'),
58 58
                 'defaults'  => array(
59
-                    'text'  => __( 'Paragraph text', 'invoicing' ),
59
+                    'text'  => __('Paragraph text', 'invoicing'),
60 60
                 )
61 61
             ),
62 62
 
63 63
             array( 
64 64
                 'type' => 'alert',
65
-                'name' => __( 'Alert', 'invoicing' ),
65
+                'name' => __('Alert', 'invoicing'),
66 66
                 'defaults'  => array(
67 67
                     'value'        => '',
68 68
                     'class'        => 'alert-warning',
69
-                    'text'         => __( 'Alert', 'invoicing' ),
69
+                    'text'         => __('Alert', 'invoicing'),
70 70
                     'dismissible'  => false,
71 71
                 )
72 72
             ),
@@ -82,11 +82,11 @@  discard block
 block discarded – undo
82 82
 
83 83
             array(
84 84
                 'type' => 'text',
85
-                'name' => __( 'Text Input', 'invoicing' ),
85
+                'name' => __('Text Input', 'invoicing'),
86 86
                 'defaults'  => array(
87
-                    'placeholder'  => __( 'Enter some text', 'invoicing' ),
87
+                    'placeholder'  => __('Enter some text', 'invoicing'),
88 88
                     'value'        => '',
89
-                    'label'        => __( 'Field Label', 'invoicing' ),
89
+                    'label'        => __('Field Label', 'invoicing'),
90 90
                     'description'  => '',
91 91
                     'required'     => false,
92 92
                 )
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
 
95 95
             array(
96 96
                 'type' => 'textarea',
97
-                'name' => __( 'Textarea', 'invoicing' ),
97
+                'name' => __('Textarea', 'invoicing'),
98 98
                 'defaults'         => array(
99
-                    'placeholder'  => __( 'Enter your text hear', 'invoicing' ),
99
+                    'placeholder'  => __('Enter your text hear', 'invoicing'),
100 100
                     'value'        => '',
101
-                    'label'        => __( 'Textarea Label', 'invoicing' ),
101
+                    'label'        => __('Textarea Label', 'invoicing'),
102 102
                     'description'  => '',
103 103
                     'required'     => false,
104 104
                 )
@@ -106,27 +106,27 @@  discard block
 block discarded – undo
106 106
 
107 107
             array(
108 108
                 'type' => 'select',
109
-                'name' => __( 'Dropdown', 'invoicing' ),
109
+                'name' => __('Dropdown', 'invoicing'),
110 110
                 'defaults'         => array(
111
-                    'placeholder'  => __( 'Select a value', 'invoicing' ),
111
+                    'placeholder'  => __('Select a value', 'invoicing'),
112 112
                     'value'        => '',
113
-                    'label'        => __( 'Dropdown Label', 'invoicing' ),
113
+                    'label'        => __('Dropdown Label', 'invoicing'),
114 114
                     'description'  => '',
115 115
                     'required'     => false,
116 116
                     'options'      => array(
117
-                        esc_attr__( 'Option One', 'invoicing' ),
118
-                        esc_attr__( 'Option Two', 'invoicing' ),
119
-                        esc_attr__( 'Option Three', 'invoicing' )
117
+                        esc_attr__('Option One', 'invoicing'),
118
+                        esc_attr__('Option Two', 'invoicing'),
119
+                        esc_attr__('Option Three', 'invoicing')
120 120
                     ),
121 121
                 )
122 122
             ),
123 123
 
124 124
             array(
125 125
                 'type' => 'checkbox',
126
-                'name' => __( 'Checkbox', 'invoicing' ),
126
+                'name' => __('Checkbox', 'invoicing'),
127 127
                 'defaults'         => array(
128 128
                     'value'        => '',
129
-                    'label'        => __( 'Checkbox Label', 'invoicing' ),
129
+                    'label'        => __('Checkbox Label', 'invoicing'),
130 130
                     'description'  => '',
131 131
                     'required'     => false,
132 132
                 )
@@ -134,23 +134,23 @@  discard block
 block discarded – undo
134 134
 
135 135
             array( 
136 136
                 'type' => 'radio',
137
-                'name' => __( 'Multiple Choice', 'invoicing' ),
137
+                'name' => __('Multiple Choice', 'invoicing'),
138 138
                 'defaults'     => array(
139
-                    'label'    => __( 'Select one choice', 'invoicing' ),
139
+                    'label'    => __('Select one choice', 'invoicing'),
140 140
                     'options'  => array(
141
-                        esc_attr__( 'Choice One', 'invoicing' ),
142
-                        esc_attr__( 'Choice Two', 'invoicing' ),
143
-                        esc_attr__( 'Choice Three', 'invoicing' )
141
+                        esc_attr__('Choice One', 'invoicing'),
142
+                        esc_attr__('Choice Two', 'invoicing'),
143
+                        esc_attr__('Choice Three', 'invoicing')
144 144
                     ),
145 145
                 )
146 146
             ),
147 147
 
148 148
             array( 
149 149
                 'type' => 'date',
150
-                'name' => __( 'Date', 'invoicing' ),
150
+                'name' => __('Date', 'invoicing'),
151 151
                 'defaults' => array(
152 152
                     'value'        => '',
153
-                    'label'        => __( 'Date', 'invoicing' ),
153
+                    'label'        => __('Date', 'invoicing'),
154 154
                     'description'  => '',
155 155
                     'required'     => false,
156 156
                 )
@@ -158,10 +158,10 @@  discard block
 block discarded – undo
158 158
 
159 159
             array( 
160 160
                 'type' => 'time',
161
-                'name' => __( 'Time', 'invoicing' ),
161
+                'name' => __('Time', 'invoicing'),
162 162
                 'defaults' => array(
163 163
                     'value'        => '',
164
-                    'label'        => __( 'Time', 'invoicing' ),
164
+                    'label'        => __('Time', 'invoicing'),
165 165
                     'description'  => '',
166 166
                     'required'     => false,
167 167
                 )
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 
170 170
             array( 
171 171
                 'type' => 'number',
172
-                'name' => __( 'Number', 'invoicing' ),
172
+                'name' => __('Number', 'invoicing'),
173 173
                 'defaults' => array(
174 174
                     'placeholder'  => '',
175 175
                     'value'        => '',
176
-                    'label'        => __( 'Number', 'invoicing' ),
176
+                    'label'        => __('Number', 'invoicing'),
177 177
                     'description'  => '',
178 178
                     'required'     => false,
179 179
                 )
@@ -181,11 +181,11 @@  discard block
 block discarded – undo
181 181
 
182 182
             array( 
183 183
                 'type' => 'website',
184
-                'name' => __( 'Website', 'invoicing' ),
184
+                'name' => __('Website', 'invoicing'),
185 185
                 'defaults' => array(
186 186
                     'placeholder'  => 'http://example.com',
187 187
                     'value'        => '',
188
-                    'label'        => __( 'Website', 'invoicing' ),
188
+                    'label'        => __('Website', 'invoicing'),
189 189
                     'description'  => '',
190 190
                     'required'     => false,
191 191
                 )
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 
194 194
             array( 
195 195
                 'type' => 'email',
196
-                'name' => __( 'Email', 'invoicing' ),
196
+                'name' => __('Email', 'invoicing'),
197 197
                 'defaults'  => array(
198 198
                     'placeholder'  => '[email protected]',
199 199
                     'value'        => '',
200
-                    'label'        => __( 'Email Address', 'invoicing' ),
200
+                    'label'        => __('Email Address', 'invoicing'),
201 201
                     'description'  => '',
202 202
                     'required'     => false,
203 203
                 )
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 
206 206
             array( 
207 207
                 'type' => 'address',
208
-                'name' => __( 'Address', 'invoicing' ),
208
+                'name' => __('Address', 'invoicing'),
209 209
                 'defaults'  => array(
210 210
 
211 211
                     'fields' => array(
212 212
                         array(
213 213
                             'placeholder'  => 'Jon',
214 214
                             'value'        => '',
215
-                            'label'        => __( 'First Name', 'invoicing' ),
215
+                            'label'        => __('First Name', 'invoicing'),
216 216
                             'description'  => '',
217 217
                             'required'     => false,
218 218
                             'visible'      => true,
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                         array(
223 223
                             'placeholder'  => 'Snow',
224 224
                             'value'        => '',
225
-                            'label'        => __( 'Last Name', 'invoicing' ),
225
+                            'label'        => __('Last Name', 'invoicing'),
226 226
                             'description'  => '',
227 227
                             'required'     => false,
228 228
                             'visible'      => true,
@@ -232,7 +232,7 @@  discard block
 block discarded – undo
232 232
                         array(
233 233
                             'placeholder'  => '',
234 234
                             'value'        => '',
235
-                            'label'        => __( 'Address', 'invoicing' ),
235
+                            'label'        => __('Address', 'invoicing'),
236 236
                             'description'  => '',
237 237
                             'required'     => false,
238 238
                             'visible'      => true,
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
                         array(
243 243
                             'placeholder'  => '',
244 244
                             'value'        => '',
245
-                            'label'        => __( 'City', 'invoicing' ),
245
+                            'label'        => __('City', 'invoicing'),
246 246
                             'description'  => '',
247 247
                             'required'     => false,
248 248
                             'visible'      => true,
@@ -250,9 +250,9 @@  discard block
 block discarded – undo
250 250
                         ),
251 251
 
252 252
                         array(
253
-                            'placeholder'  => __( 'Select your country' ),
253
+                            'placeholder'  => __('Select your country'),
254 254
                             'value'        => '',
255
-                            'label'        => __( 'Country', 'invoicing' ),
255
+                            'label'        => __('Country', 'invoicing'),
256 256
                             'description'  => '',
257 257
                             'required'     => false,
258 258
                             'visible'      => true,
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
                         ),
261 261
 
262 262
                         array(
263
-                            'placeholder'  => __( 'Choose a state', 'invoicing' ),
263
+                            'placeholder'  => __('Choose a state', 'invoicing'),
264 264
                             'value'        => '',
265
-                            'label'        => __( 'State / Province', 'invoicing' ),
265
+                            'label'        => __('State / Province', 'invoicing'),
266 266
                             'description'  => '',
267 267
                             'required'     => false,
268 268
                             'visible'      => true,
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
                         array(
273 273
                             'placeholder'  => '',
274 274
                             'value'        => '',
275
-                            'label'        => __( 'ZIP / Postcode', 'invoicing' ),
275
+                            'label'        => __('ZIP / Postcode', 'invoicing'),
276 276
                             'description'  => '',
277 277
                             'required'     => false,
278 278
                             'visible'      => true,
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
                         array(
283 283
                             'placeholder'  => '',
284 284
                             'value'        => '',
285
-                            'label'        => __( 'Phone', 'invoicing' ),
285
+                            'label'        => __('Phone', 'invoicing'),
286 286
                             'description'  => '',
287 287
                             'required'     => false,
288 288
                             'visible'      => true,
@@ -294,11 +294,11 @@  discard block
 block discarded – undo
294 294
 
295 295
             array( 
296 296
                 'type' => 'billing_email',
297
-                'name' => __( 'Billing Email', 'invoicing' ),
297
+                'name' => __('Billing Email', 'invoicing'),
298 298
                 'defaults'  => array(
299 299
                     'placeholder'  => '[email protected]',
300 300
                     'value'        => '',
301
-                    'label'        => __( 'Billing Email', 'invoicing' ),
301
+                    'label'        => __('Billing Email', 'invoicing'),
302 302
                     'description'  => '',
303 303
                     'premade'      => true,
304 304
                 )
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 
318 318
             array( 
319 319
                 'type' => 'items',
320
-                'name' => __( 'Items', 'invoicing' ),
320
+                'name' => __('Items', 'invoicing'),
321 321
                 'defaults'  => array(
322 322
                     'value'        => '',
323 323
                     'items_type'   => 'total',
@@ -328,25 +328,25 @@  discard block
 block discarded – undo
328 328
 
329 329
             array( 
330 330
                 'type'       => 'pay_button',
331
-                'name'       => __( 'Payment Button', 'invoicing' ),
331
+                'name'       => __('Payment Button', 'invoicing'),
332 332
                 'defaults'   => array(
333 333
                     'value'        => '',
334 334
                     'class'        => 'btn-primary',
335
-                    'label'        => __( 'Pay Now »', 'invoicing' ),
336
-                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
335
+                    'label'        => __('Pay Now »', 'invoicing'),
336
+                    'description'  => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'),
337 337
                     'premade'      => true,
338 338
                 )
339 339
             )
340 340
         );
341 341
 
342
-        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
342
+        $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements);
343 343
         return $this->elements;
344 344
     }
345 345
 
346 346
     /**
347 347
      * Returns the restrict markup.
348 348
      */
349
-    public function get_restrict_markup( $field, $field_type ) {
349
+    public function get_restrict_markup($field, $field_type) {
350 350
         $restrict = "$field.type=='$field_type'";
351 351
         return "v-if=\"$restrict\"";
352 352
     }
@@ -354,15 +354,15 @@  discard block
 block discarded – undo
354 354
     /**
355 355
      * Renders the title element template.
356 356
      */
357
-    public function render_heading_template( $field ) {
358
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
357
+    public function render_heading_template($field) {
358
+        $restrict = $this->get_restrict_markup($field, 'heading');
359 359
         echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
360 360
     }
361 361
 
362 362
     /**
363 363
      * Renders the title element on the frontend.
364 364
      */
365
-    public function frontend_render_heading_template( $field ) {
365
+    public function frontend_render_heading_template($field) {
366 366
         $tag = $field['level'];
367 367
         echo "<$tag>{$field['text']}</$tag>";
368 368
     }
@@ -370,10 +370,10 @@  discard block
 block discarded – undo
370 370
     /**
371 371
      * Renders the edit title element template.
372 372
      */
373
-    public function edit_heading_template( $field ) {
374
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
375
-        $label    = __( 'Heading', 'invoicing' );
376
-        $label2   = __( 'Select Heading Level', 'invoicing' );
373
+    public function edit_heading_template($field) {
374
+        $restrict = $this->get_restrict_markup($field, 'heading');
375
+        $label    = __('Heading', 'invoicing');
376
+        $label2   = __('Select Heading Level', 'invoicing');
377 377
         $id       = $field . '.id + "_edit"';
378 378
         $id2      = $field . '.id + "_edit2"';
379 379
 
@@ -405,8 +405,8 @@  discard block
 block discarded – undo
405 405
     /**
406 406
      * Renders a paragraph element template.
407 407
      */
408
-    public function render_paragraph_template( $field ) {
409
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
408
+    public function render_paragraph_template($field) {
409
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
410 410
         $label    = "$field.text";
411 411
         echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
412 412
     }
@@ -414,16 +414,16 @@  discard block
 block discarded – undo
414 414
     /**
415 415
      * Renders the paragraph element on the frontend.
416 416
      */
417
-    public function frontend_render_paragraph_template( $field ) {
417
+    public function frontend_render_paragraph_template($field) {
418 418
         echo "<p>{$field['text']}</p>";
419 419
     }
420 420
 
421 421
     /**
422 422
      * Renders the edit paragraph element template.
423 423
      */
424
-    public function edit_paragraph_template( $field ) {
425
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
426
-        $label    = __( 'Enter your text', 'invoicing' );
424
+    public function edit_paragraph_template($field) {
425
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
426
+        $label    = __('Enter your text', 'invoicing');
427 427
         $id       = $field . '.id + "_edit"';
428 428
         echo "
429 429
             <div $restrict>
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
     /**
440 440
      * Renders the text element template.
441 441
      */
442
-    public function render_text_template( $field ) {
443
-        $restrict = $this->get_restrict_markup( $field, 'text' );
442
+    public function render_text_template($field) {
443
+        $restrict = $this->get_restrict_markup($field, 'text');
444 444
         $label    = "$field.label";
445 445
         echo "
446 446
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -455,23 +455,23 @@  discard block
 block discarded – undo
455 455
     /**
456 456
      * Renders the text element on the frontend.
457 457
      */
458
-    public function frontend_render_text_template( $field ) {
458
+    public function frontend_render_text_template($field) {
459 459
         
460 460
         echo "<div class='form-group'>";
461 461
 
462 462
         echo aui()->input(
463 463
             array(
464
-                'name'       => esc_attr( $field['id'] ),
465
-                'id'         => esc_attr( $field['id'] ),
466
-                'placeholder'=> esc_attr( $field['placeholder'] ),
464
+                'name'       => esc_attr($field['id']),
465
+                'id'         => esc_attr($field['id']),
466
+                'placeholder'=> esc_attr($field['placeholder']),
467 467
                 'required'   => (bool) $field['required'],
468
-                'label'      => wp_kses_post( $field['label'] ),
468
+                'label'      => wp_kses_post($field['label']),
469 469
                 'no_wrap'    => true,
470 470
             )
471 471
         );
472 472
 
473
-        if ( ! empty( $field['description'] ) ) {
474
-            $description = wp_kses_post( $field['description'] );
473
+        if (!empty($field['description'])) {
474
+            $description = wp_kses_post($field['description']);
475 475
             echo "<small class='form-text text-muted'>$description</small>";
476 476
         }
477 477
 
@@ -482,16 +482,16 @@  discard block
 block discarded – undo
482 482
     /**
483 483
      * Renders the edit text element template.
484 484
      */
485
-    public function edit_text_template( $field ) {
486
-        $restrict = $this->get_restrict_markup( $field, 'text' );
487
-        $label    = __( 'Field Label', 'invoicing' );
485
+    public function edit_text_template($field) {
486
+        $restrict = $this->get_restrict_markup($field, 'text');
487
+        $label    = __('Field Label', 'invoicing');
488 488
         $id       = $field . '.id + "_edit"';
489
-        $label2   = __( 'Placeholder text', 'invoicing' );
489
+        $label2   = __('Placeholder text', 'invoicing');
490 490
         $id2      = $field . '.id + "_edit2"';
491
-        $label3   = __( 'Help text', 'invoicing' );
492
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
491
+        $label3   = __('Help text', 'invoicing');
492
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
493 493
         $id3      = $field . '.id + "_edit3"';
494
-        $label5   = __( 'Is this field required?', 'invoicing' );
494
+        $label5   = __('Is this field required?', 'invoicing');
495 495
         $id4      = $field . '.id + "_edit4"';
496 496
         echo "
497 497
             <div $restrict>
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
     /**
520 520
      * Renders the textarea element template.
521 521
      */
522
-    public function render_textarea_template( $field ) {
523
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
522
+    public function render_textarea_template($field) {
523
+        $restrict = $this->get_restrict_markup($field, 'textarea');
524 524
         $label    = "$field.label";
525 525
         echo "
526 526
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -535,24 +535,24 @@  discard block
 block discarded – undo
535 535
     /**
536 536
      * Renders the textarea element on the frontend.
537 537
      */
538
-    public function frontend_render_textarea_template( $field ) {
538
+    public function frontend_render_textarea_template($field) {
539 539
         
540 540
         echo "<div class='form-group'>";
541 541
 
542 542
         echo aui()->textarea(
543 543
             array(
544
-                'name'       => esc_attr( $field['id'] ),
545
-                'id'         => esc_attr( $field['id'] ),
546
-                'placeholder'=> esc_attr( $field['placeholder'] ),
544
+                'name'       => esc_attr($field['id']),
545
+                'id'         => esc_attr($field['id']),
546
+                'placeholder'=> esc_attr($field['placeholder']),
547 547
                 'required'   => (bool) $field['required'],
548
-                'label'      => wp_kses_post( $field['label'] ),
548
+                'label'      => wp_kses_post($field['label']),
549 549
                 'no_wrap'    => true,
550 550
                 'rows'       => 3,
551 551
             )
552 552
         );
553 553
 
554
-        if ( ! empty( $field['description'] ) ) {
555
-            $description = wp_kses_post( $field['description'] );
554
+        if (!empty($field['description'])) {
555
+            $description = wp_kses_post($field['description']);
556 556
             echo "<small class='form-text text-muted'>$description</small>";
557 557
         }
558 558
 
@@ -563,16 +563,16 @@  discard block
 block discarded – undo
563 563
     /**
564 564
      * Renders the edit textarea element template.
565 565
      */
566
-    public function edit_textarea_template( $field ) {
567
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
568
-        $label    = __( 'Field Label', 'invoicing' );
566
+    public function edit_textarea_template($field) {
567
+        $restrict = $this->get_restrict_markup($field, 'textarea');
568
+        $label    = __('Field Label', 'invoicing');
569 569
         $id       = $field . '.id + "_edit"';
570
-        $label2   = __( 'Placeholder text', 'invoicing' );
570
+        $label2   = __('Placeholder text', 'invoicing');
571 571
         $id2      = $field . '.id + "_edit2"';
572
-        $label3   = __( 'Help text', 'invoicing' );
573
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
572
+        $label3   = __('Help text', 'invoicing');
573
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
574 574
         $id3      = $field . '.id + "_edit3"';
575
-        $label5   = __( 'Is this field required?', 'invoicing' );
575
+        $label5   = __('Is this field required?', 'invoicing');
576 576
         $id4      = $field . '.id + "_edit4"';
577 577
         echo "
578 578
             <div $restrict>
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
     /**
601 601
      * Renders the select element template.
602 602
      */
603
-    public function render_select_template( $field ) {
604
-        $restrict    = $this->get_restrict_markup( $field, 'select' );
603
+    public function render_select_template($field) {
604
+        $restrict    = $this->get_restrict_markup($field, 'select');
605 605
         $label       = "$field.label";
606 606
         $placeholder = "$field.placeholder";
607 607
         $id          = $field . '.id';
@@ -621,24 +621,24 @@  discard block
 block discarded – undo
621 621
     /**
622 622
      * Renders the select element on the frontend.
623 623
      */
624
-    public function frontend_render_select_template( $field ) {
624
+    public function frontend_render_select_template($field) {
625 625
         
626 626
         echo "<div class='form-group'>";
627 627
 
628 628
         echo aui()->select(
629 629
             array(
630
-                'name'       => esc_attr( $field['id'] ),
631
-                'id'         => esc_attr( $field['id'] ),
632
-                'placeholder'=> esc_attr( $field['placeholder'] ),
630
+                'name'       => esc_attr($field['id']),
631
+                'id'         => esc_attr($field['id']),
632
+                'placeholder'=> esc_attr($field['placeholder']),
633 633
                 'required'   => (bool) $field['required'],
634
-                'label'      => wp_kses_post( $field['label'] ),
634
+                'label'      => wp_kses_post($field['label']),
635 635
                 'no_wrap'    => true,
636
-                'options'    => array_combine( $field['options'], $field['options'] ),
636
+                'options'    => array_combine($field['options'], $field['options']),
637 637
             )
638 638
         );
639 639
 
640
-        if ( ! empty( $field['description'] ) ) {
641
-            $description = wp_kses_post( $field['description'] );
640
+        if (!empty($field['description'])) {
641
+            $description = wp_kses_post($field['description']);
642 642
             echo "<small class='form-text text-muted'>$description</small>";
643 643
         }
644 644
 
@@ -649,18 +649,18 @@  discard block
 block discarded – undo
649 649
     /**
650 650
      * Renders the edit select element template.
651 651
      */
652
-    public function edit_select_template( $field ) {
653
-        $restrict = $this->get_restrict_markup( $field, 'select' );
654
-        $label    = __( 'Field Label', 'invoicing' );
652
+    public function edit_select_template($field) {
653
+        $restrict = $this->get_restrict_markup($field, 'select');
654
+        $label    = __('Field Label', 'invoicing');
655 655
         $id       = $field . '.id + "_edit"';
656
-        $label2   = __( 'Placeholder text', 'invoicing' );
656
+        $label2   = __('Placeholder text', 'invoicing');
657 657
         $id2      = $field . '.id + "_edit2"';
658
-        $label3   = __( 'Help text', 'invoicing' );
659
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
658
+        $label3   = __('Help text', 'invoicing');
659
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
660 660
         $id3      = $field . '.id + "_edit3"';
661
-        $label5   = __( 'Is this field required?', 'invoicing' );
661
+        $label5   = __('Is this field required?', 'invoicing');
662 662
         $id4      = $field . '.id + "_edit4"';
663
-        $label6   = __( 'Available Options', 'invoicing' );
663
+        $label6   = __('Available Options', 'invoicing');
664 664
         echo "
665 665
             <div $restrict>
666 666
                 <div class='form-group'>
@@ -698,8 +698,8 @@  discard block
 block discarded – undo
698 698
     /**
699 699
      * Renders the checkbox element template.
700 700
      */
701
-    public function render_checkbox_template( $field ) {
702
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
701
+    public function render_checkbox_template($field) {
702
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
703 703
         $label    = "$field.label";
704 704
         echo "
705 705
             <div class='form-check' $restrict>
@@ -714,24 +714,24 @@  discard block
 block discarded – undo
714 714
     /**
715 715
      * Renders the checkbox element on the frontend.
716 716
      */
717
-    public function frontend_render_checkbox_template( $field ) {
717
+    public function frontend_render_checkbox_template($field) {
718 718
         
719 719
         echo "<div class='form-group'>";
720 720
 
721 721
         echo aui()->input(
722 722
             array(
723
-                'name'       => esc_attr( $field['id'] ),
724
-                'id'         => esc_attr( $field['id'] ),
723
+                'name'       => esc_attr($field['id']),
724
+                'id'         => esc_attr($field['id']),
725 725
                 'required'   => (bool) $field['required'],
726
-                'label'      => wp_kses_post( $field['label'] ),
726
+                'label'      => wp_kses_post($field['label']),
727 727
                 'no_wrap'    => true,
728
-                'value'      => esc_attr__( 'Yes', 'invoicing' ),
728
+                'value'      => esc_attr__('Yes', 'invoicing'),
729 729
                 'type'       => 'checkbox',
730 730
             )
731 731
         );
732 732
 
733
-        if ( ! empty( $field['description'] ) ) {
734
-            $description = wp_kses_post( $field['description'] );
733
+        if (!empty($field['description'])) {
734
+            $description = wp_kses_post($field['description']);
735 735
             echo "<small class='form-text text-muted'>$description</small>";
736 736
         }
737 737
 
@@ -742,14 +742,14 @@  discard block
 block discarded – undo
742 742
     /**
743 743
      * Renders the edit checkbox element template.
744 744
      */
745
-    public function edit_checkbox_template( $field ) {
746
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
747
-        $label    = __( 'Field Label', 'invoicing' );
745
+    public function edit_checkbox_template($field) {
746
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
747
+        $label    = __('Field Label', 'invoicing');
748 748
         $id       = $field . '.id + "_edit"';
749
-        $label2   = __( 'Help text', 'invoicing' );
750
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
749
+        $label2   = __('Help text', 'invoicing');
750
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
751 751
         $id2      = $field . '.id + "_edit2"';
752
-        $label4   = __( 'Is this field required?', 'invoicing' );
752
+        $label4   = __('Is this field required?', 'invoicing');
753 753
         $id3      = $field . '.id + "_edit3"';
754 754
         echo "
755 755
             <div $restrict>
@@ -773,8 +773,8 @@  discard block
 block discarded – undo
773 773
     /**
774 774
      * Renders the radio element template.
775 775
      */
776
-    public function render_radio_template( $field ) {
777
-        $restrict    = $this->get_restrict_markup( $field, 'radio' );
776
+    public function render_radio_template($field) {
777
+        $restrict    = $this->get_restrict_markup($field, 'radio');
778 778
         $label       = "$field.label";
779 779
         $id          = $field . '.id';
780 780
         echo "
@@ -793,20 +793,20 @@  discard block
 block discarded – undo
793 793
     /**
794 794
      * Renders the radio element on the frontend.
795 795
      */
796
-    public function frontend_render_radio_template( $field ) {
796
+    public function frontend_render_radio_template($field) {
797 797
         
798 798
         echo "<div class='form-group'>";
799 799
 
800
-        if ( ! empty( $field['label'] ) ) {
801
-            $label = wp_kses_post( $field['label'] );
800
+        if (!empty($field['label'])) {
801
+            $label = wp_kses_post($field['label']);
802 802
             echo "<legend class='col-form-label'>$label</legend>";
803 803
         }
804 804
 
805
-        foreach( $field['options'] as $index => $option ) {
805
+        foreach ($field['options'] as $index => $option) {
806 806
             $id    = $field['id'] . $index;
807 807
             $name  = $field['id'];
808
-            $value = esc_attr( $option );
809
-            $label = wp_kses_post( $option );
808
+            $value = esc_attr($option);
809
+            $label = wp_kses_post($option);
810 810
 
811 811
             echo "
812 812
                 <div class='form-check'>
@@ -816,8 +816,8 @@  discard block
 block discarded – undo
816 816
             ";
817 817
         }
818 818
 
819
-        if ( ! empty( $field['description'] ) ) {
820
-            $description = wp_kses_post( $field['description'] );
819
+        if (!empty($field['description'])) {
820
+            $description = wp_kses_post($field['description']);
821 821
             echo "<small class='form-text text-muted'>$description</small>";
822 822
         }
823 823
 
@@ -828,16 +828,16 @@  discard block
 block discarded – undo
828 828
     /**
829 829
      * Renders the edit radio element template.
830 830
      */
831
-    public function edit_radio_template( $field ) {
832
-        $restrict = $this->get_restrict_markup( $field, 'radio' );
833
-        $label    = __( 'Field Label', 'invoicing' );
831
+    public function edit_radio_template($field) {
832
+        $restrict = $this->get_restrict_markup($field, 'radio');
833
+        $label    = __('Field Label', 'invoicing');
834 834
         $id       = $field . '.id + "_edit"';
835
-        $label2   = __( 'Help text', 'invoicing' );
836
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
835
+        $label2   = __('Help text', 'invoicing');
836
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
837 837
         $id2      = $field . '.id + "_edit3"';
838
-        $label4   = __( 'Is this field required?', 'invoicing' );
838
+        $label4   = __('Is this field required?', 'invoicing');
839 839
         $id3      = $field . '.id + "_edit4"';
840
-        $label5   = __( 'Available Options', 'invoicing' );
840
+        $label5   = __('Available Options', 'invoicing');
841 841
         echo "
842 842
             <div $restrict>
843 843
                 <div class='form-group'>
@@ -871,8 +871,8 @@  discard block
 block discarded – undo
871 871
     /**
872 872
      * Renders the address element template.
873 873
      */
874
-    public function render_address_template( $field ) {
875
-        $restrict    = $this->get_restrict_markup( $field, 'address' );
874
+    public function render_address_template($field) {
875
+        $restrict = $this->get_restrict_markup($field, 'address');
876 876
 
877 877
         echo "
878 878
             <div class='wpinv-address-wrapper' $restrict>
@@ -894,55 +894,55 @@  discard block
 block discarded – undo
894 894
     /**
895 895
      * Renders the address element on the frontend.
896 896
      */
897
-    public function frontend_render_address_template( $field ) {
897
+    public function frontend_render_address_template($field) {
898 898
         
899 899
         echo "<div class='wpinv-address-fields'>";
900 900
 
901
-        foreach( $field['fields'] as $address_field ) {
901
+        foreach ($field['fields'] as $address_field) {
902 902
 
903
-            if ( empty( $address_field['visible'] ) ) {
903
+            if (empty($address_field['visible'])) {
904 904
                 continue;
905 905
             }
906 906
 
907
-            $class = esc_attr( $address_field['name'] );
907
+            $class = esc_attr($address_field['name']);
908 908
             echo "<div class='form-group $class'>";
909 909
 
910 910
             $label = $address_field['label'];
911 911
 
912
-            if ( ! empty( $address_field['required'] ) ) {
912
+            if (!empty($address_field['required'])) {
913 913
                 $label .= "<span class='text-danger'> *</span>";
914 914
             }
915 915
 
916
-            if ( 'wpinv_country' == $address_field['name'] ) {
916
+            if ('wpinv_country' == $address_field['name']) {
917 917
 
918
-                echo aui()->select( array(
918
+                echo aui()->select(array(
919 919
                     'options'          => wpinv_get_country_list(),
920
-                    'name'             => esc_attr( $address_field['name'] ),
921
-                    'id'               => esc_attr( $address_field['name'] ),
920
+                    'name'             => esc_attr($address_field['name']),
921
+                    'id'               => esc_attr($address_field['name']),
922 922
                     'value'            => wpinv_get_default_country(),
923
-                    'placeholder'      => esc_attr( $address_field['placeholder'] ),
923
+                    'placeholder'      => esc_attr($address_field['placeholder']),
924 924
                     'required'         => (bool) $address_field['required'],
925 925
                     'no_wrap'          => true,
926
-                    'label'            => wp_kses_post( $label ),
926
+                    'label'            => wp_kses_post($label),
927 927
                     'select2'          => false,
928 928
                 ));
929 929
     
930
-            } else if ( 'wpinv_state' == $address_field['name'] ) {
930
+            } else if ('wpinv_state' == $address_field['name']) {
931 931
 
932
-                $states = wpinv_get_country_states( wpinv_get_default_country() );
932
+                $states = wpinv_get_country_states(wpinv_get_default_country());
933 933
                 $state  = wpinv_get_default_state();
934 934
 
935
-                if ( ! empty( $states ) ) {
935
+                if (!empty($states)) {
936 936
 
937
-                    echo aui()->select( array(
937
+                    echo aui()->select(array(
938 938
                         'options'          => $states,
939
-                        'name'             => esc_attr( $address_field['name'] ),
940
-                        'id'               => esc_attr( $address_field['name'] ),
939
+                        'name'             => esc_attr($address_field['name']),
940
+                        'id'               => esc_attr($address_field['name']),
941 941
                         'value'            => $state,
942
-                        'placeholder'      => esc_attr( $address_field['placeholder'] ),
942
+                        'placeholder'      => esc_attr($address_field['placeholder']),
943 943
                         'required'         => (bool) $address_field['required'],
944 944
                         'no_wrap'          => true,
945
-                        'label'            => wp_kses_post( $label ),
945
+                        'label'            => wp_kses_post($label),
946 946
                         'select2'          => false,
947 947
                     ));
948 948
 
@@ -950,10 +950,10 @@  discard block
 block discarded – undo
950 950
 
951 951
                     echo aui()->input(
952 952
                         array(
953
-                            'name'       => esc_attr( $address_field['name'] ),
954
-                            'id'         => esc_attr( $address_field['name'] ),
953
+                            'name'       => esc_attr($address_field['name']),
954
+                            'id'         => esc_attr($address_field['name']),
955 955
                             'required'   => (bool) $address_field['required'],
956
-                            'label'      => wp_kses_post( $label ),
956
+                            'label'      => wp_kses_post($label),
957 957
                             'no_wrap'    => true,
958 958
                             'type'       => 'text',
959 959
                         )
@@ -965,12 +965,12 @@  discard block
 block discarded – undo
965 965
 
966 966
                 echo aui()->input(
967 967
                     array(
968
-                        'name'       => esc_attr( $address_field['name'] ),
969
-                        'id'         => esc_attr( $address_field['name'] ),
968
+                        'name'       => esc_attr($address_field['name']),
969
+                        'id'         => esc_attr($address_field['name']),
970 970
                         'required'   => (bool) $address_field['required'],
971
-                        'label'      => wp_kses_post( $label ),
971
+                        'label'      => wp_kses_post($label),
972 972
                         'no_wrap'    => true,
973
-                        'placeholder' => esc_attr( $address_field['placeholder'] ),
973
+                        'placeholder' => esc_attr($address_field['placeholder']),
974 974
                         'type'       => 'text',
975 975
                     )
976 976
                 );
@@ -978,8 +978,8 @@  discard block
 block discarded – undo
978 978
             }
979 979
             
980 980
 
981
-            if ( ! empty( $address_field['description'] ) ) {
982
-                $description = wp_kses_post( $address_field['description'] );
981
+            if (!empty($address_field['description'])) {
982
+                $description = wp_kses_post($address_field['description']);
983 983
                 echo "<small class='form-text text-muted'>$description</small>";
984 984
             }
985 985
     
@@ -994,13 +994,13 @@  discard block
 block discarded – undo
994 994
     /**
995 995
      * Renders the edit address element template.
996 996
      */
997
-    public function edit_address_template( $field ) {
998
-        $restrict  = $this->get_restrict_markup( $field, 'address' );
999
-        $label     = __( 'Field Label', 'invoicing' );
1000
-        $label2    = __( 'Placeholder', 'invoicing' );
1001
-        $label3    = __( 'Description', 'invoicing' );
1002
-        $label4    = __( 'Is required', 'invoicing' );
1003
-        $label5    = __( 'Is visible', 'invoicing' );
997
+    public function edit_address_template($field) {
998
+        $restrict  = $this->get_restrict_markup($field, 'address');
999
+        $label     = __('Field Label', 'invoicing');
1000
+        $label2    = __('Placeholder', 'invoicing');
1001
+        $label3    = __('Description', 'invoicing');
1002
+        $label4    = __('Is required', 'invoicing');
1003
+        $label5    = __('Is visible', 'invoicing');
1004 1004
         $id        = $field . '.id + "_edit_label"';
1005 1005
         $id2       = $field . '.id + "_edit_placeholder"';
1006 1006
         $id3       = $field . '.id + "_edit_description"';
@@ -1068,8 +1068,8 @@  discard block
 block discarded – undo
1068 1068
     /**
1069 1069
      * Renders the email element template.
1070 1070
      */
1071
-    public function render_email_template( $field ) {
1072
-        $restrict = $this->get_restrict_markup( $field, 'email' );
1071
+    public function render_email_template($field) {
1072
+        $restrict = $this->get_restrict_markup($field, 'email');
1073 1073
         $label    = "$field.label";
1074 1074
         echo "
1075 1075
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1084,8 +1084,8 @@  discard block
 block discarded – undo
1084 1084
     /**
1085 1085
      * Renders the billing_email element template.
1086 1086
      */
1087
-    public function render_billing_email_template( $field ) {
1088
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1087
+    public function render_billing_email_template($field) {
1088
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
1089 1089
         $label    = "$field.label";
1090 1090
         echo "
1091 1091
             <div $restrict>
@@ -1099,24 +1099,24 @@  discard block
 block discarded – undo
1099 1099
     /**
1100 1100
      * Renders the email element on the frontend.
1101 1101
      */
1102
-    public function frontend_render_email_template( $field ) {
1102
+    public function frontend_render_email_template($field) {
1103 1103
         
1104 1104
         echo "<div class='form-group'>";
1105 1105
 
1106 1106
         echo aui()->input(
1107 1107
             array(
1108
-                'name'       => esc_attr( $field['id'] ),
1109
-                'id'         => esc_attr( $field['id'] ),
1108
+                'name'       => esc_attr($field['id']),
1109
+                'id'         => esc_attr($field['id']),
1110 1110
                 'required'   => (bool) $field['required'],
1111
-                'label'      => wp_kses_post( $field['label'] ),
1111
+                'label'      => wp_kses_post($field['label']),
1112 1112
                 'no_wrap'    => true,
1113
-                'placeholder' => esc_attr( $field['placeholder'] ),
1113
+                'placeholder' => esc_attr($field['placeholder']),
1114 1114
                 'type'       => 'email',
1115 1115
             )
1116 1116
         );
1117 1117
 
1118
-        if ( ! empty( $field['description'] ) ) {
1119
-            $description = wp_kses_post( $field['description'] );
1118
+        if (!empty($field['description'])) {
1119
+            $description = wp_kses_post($field['description']);
1120 1120
             echo "<small class='form-text text-muted'>$description</small>";
1121 1121
         }
1122 1122
 
@@ -1127,30 +1127,30 @@  discard block
 block discarded – undo
1127 1127
     /**
1128 1128
      * Renders the billing email element on the frontend.
1129 1129
      */
1130
-    public function frontend_render_billing_email_template( $field ) {
1130
+    public function frontend_render_billing_email_template($field) {
1131 1131
         
1132 1132
         echo "<div class='form-group'>";
1133 1133
         $value = '';
1134 1134
 
1135
-        if ( is_user_logged_in() ) {
1135
+        if (is_user_logged_in()) {
1136 1136
             $user  = wp_get_current_user();
1137
-            $value = sanitize_email( $user->user_email );
1137
+            $value = sanitize_email($user->user_email);
1138 1138
         }
1139 1139
         echo aui()->input(
1140 1140
             array(
1141 1141
                 'name'       => 'billing_email',
1142 1142
                 'value'      => $value,
1143
-                'id'         => esc_attr( $field['id'] ),
1143
+                'id'         => esc_attr($field['id']),
1144 1144
                 'required'   => true,
1145
-                'label'      => wp_kses_post( $field['label'] ),
1145
+                'label'      => wp_kses_post($field['label']),
1146 1146
                 'no_wrap'    => true,
1147
-                'placeholder' => esc_attr( $field['placeholder'] ),
1147
+                'placeholder' => esc_attr($field['placeholder']),
1148 1148
                 'type'       => 'email',
1149 1149
             )
1150 1150
         );
1151 1151
 
1152
-        if ( ! empty( $field['description'] ) ) {
1153
-            $description = wp_kses_post( $field['description'] );
1152
+        if (!empty($field['description'])) {
1153
+            $description = wp_kses_post($field['description']);
1154 1154
             echo "<small class='form-text text-muted'>$description</small>";
1155 1155
         }
1156 1156
 
@@ -1161,16 +1161,16 @@  discard block
 block discarded – undo
1161 1161
     /**
1162 1162
      * Renders the edit email element template.
1163 1163
      */
1164
-    public function edit_email_template( $field ) {
1165
-        $restrict = $this->get_restrict_markup( $field, 'email' );
1166
-        $label    = __( 'Field Label', 'invoicing' );
1164
+    public function edit_email_template($field) {
1165
+        $restrict = $this->get_restrict_markup($field, 'email');
1166
+        $label    = __('Field Label', 'invoicing');
1167 1167
         $id       = $field . '.id + "_edit"';
1168
-        $label2   = __( 'Placeholder text', 'invoicing' );
1168
+        $label2   = __('Placeholder text', 'invoicing');
1169 1169
         $id2      = $field . '.id + "_edit2"';
1170
-        $label3   = __( 'Help text', 'invoicing' );
1171
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1170
+        $label3   = __('Help text', 'invoicing');
1171
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1172 1172
         $id3      = $field . '.id + "_edit3"';
1173
-        $label5   = __( 'Is this field required?', 'invoicing' );
1173
+        $label5   = __('Is this field required?', 'invoicing');
1174 1174
         $id4      = $field . '.id + "_edit4"';
1175 1175
         echo "
1176 1176
             <div $restrict>
@@ -1198,16 +1198,16 @@  discard block
 block discarded – undo
1198 1198
     /**
1199 1199
      * Renders the edit billing_email element template.
1200 1200
      */
1201
-    public function edit_billing_email_template( $field ) {
1202
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1203
-        $label    = __( 'Field Label', 'invoicing' );
1201
+    public function edit_billing_email_template($field) {
1202
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
1203
+        $label    = __('Field Label', 'invoicing');
1204 1204
         $id       = $field . '.id + "_edit"';
1205
-        $label2   = __( 'Placeholder text', 'invoicing' );
1205
+        $label2   = __('Placeholder text', 'invoicing');
1206 1206
         $id2      = $field . '.id + "_edit2"';
1207
-        $label3   = __( 'Help text', 'invoicing' );
1208
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1207
+        $label3   = __('Help text', 'invoicing');
1208
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1209 1209
         $id3      = $field . '.id + "_edit3"';
1210
-        $label5   = __( 'Is this field required?', 'invoicing' );
1210
+        $label5   = __('Is this field required?', 'invoicing');
1211 1211
         $id4      = $field . '.id + "_edit4"';
1212 1212
         echo "
1213 1213
             <div $restrict>
@@ -1231,8 +1231,8 @@  discard block
 block discarded – undo
1231 1231
     /**
1232 1232
      * Renders the website element template.
1233 1233
      */
1234
-    public function render_website_template( $field ) {
1235
-        $restrict = $this->get_restrict_markup( $field, 'website' );
1234
+    public function render_website_template($field) {
1235
+        $restrict = $this->get_restrict_markup($field, 'website');
1236 1236
         $label    = "$field.label";
1237 1237
         echo "
1238 1238
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1247,24 +1247,24 @@  discard block
 block discarded – undo
1247 1247
     /**
1248 1248
      * Renders the website element on the frontend.
1249 1249
      */
1250
-    public function frontend_render_website_template( $field ) {
1250
+    public function frontend_render_website_template($field) {
1251 1251
         
1252 1252
         echo "<div class='form-group'>";
1253 1253
 
1254 1254
         echo aui()->input(
1255 1255
             array(
1256
-                'name'       => esc_attr( $field['id'] ),
1257
-                'id'         => esc_attr( $field['id'] ),
1256
+                'name'       => esc_attr($field['id']),
1257
+                'id'         => esc_attr($field['id']),
1258 1258
                 'required'   => (bool) $field['required'],
1259
-                'label'      => wp_kses_post( $field['label'] ),
1259
+                'label'      => wp_kses_post($field['label']),
1260 1260
                 'no_wrap'    => true,
1261
-                'placeholder' => esc_attr( $field['placeholder'] ),
1261
+                'placeholder' => esc_attr($field['placeholder']),
1262 1262
                 'type'       => 'url',
1263 1263
             )
1264 1264
         );
1265 1265
 
1266
-        if ( ! empty( $field['description'] ) ) {
1267
-            $description = wp_kses_post( $field['description'] );
1266
+        if (!empty($field['description'])) {
1267
+            $description = wp_kses_post($field['description']);
1268 1268
             echo "<small class='form-text text-muted'>$description</small>";
1269 1269
         }
1270 1270
 
@@ -1275,16 +1275,16 @@  discard block
 block discarded – undo
1275 1275
     /**
1276 1276
      * Renders the edit website element template.
1277 1277
      */
1278
-    public function edit_website_template( $field ) {
1279
-        $restrict = $this->get_restrict_markup( $field, 'website' );
1280
-        $label    = __( 'Field Label', 'invoicing' );
1278
+    public function edit_website_template($field) {
1279
+        $restrict = $this->get_restrict_markup($field, 'website');
1280
+        $label    = __('Field Label', 'invoicing');
1281 1281
         $id       = $field . '.id + "_edit"';
1282
-        $label2   = __( 'Placeholder text', 'invoicing' );
1282
+        $label2   = __('Placeholder text', 'invoicing');
1283 1283
         $id2      = $field . '.id + "_edit2"';
1284
-        $label3   = __( 'Help text', 'invoicing' );
1285
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1284
+        $label3   = __('Help text', 'invoicing');
1285
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1286 1286
         $id3      = $field . '.id + "_edit3"';
1287
-        $label5   = __( 'Is this field required?', 'invoicing' );
1287
+        $label5   = __('Is this field required?', 'invoicing');
1288 1288
         $id4      = $field . '.id + "_edit4"';
1289 1289
         echo "
1290 1290
             <div $restrict>
@@ -1312,8 +1312,8 @@  discard block
 block discarded – undo
1312 1312
     /**
1313 1313
      * Renders the date element template.
1314 1314
      */
1315
-    public function render_date_template( $field ) {
1316
-        $restrict = $this->get_restrict_markup( $field, 'date' );
1315
+    public function render_date_template($field) {
1316
+        $restrict = $this->get_restrict_markup($field, 'date');
1317 1317
         $label    = "$field.label";
1318 1318
         echo "
1319 1319
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1328,23 +1328,23 @@  discard block
 block discarded – undo
1328 1328
     /**
1329 1329
      * Renders the date element on the frontend.
1330 1330
      */
1331
-    public function frontend_render_date_template( $field ) {
1331
+    public function frontend_render_date_template($field) {
1332 1332
         
1333 1333
         echo "<div class='form-group'>";
1334 1334
 
1335 1335
         echo aui()->input(
1336 1336
             array(
1337
-                'name'       => esc_attr( $field['id'] ),
1338
-                'id'         => esc_attr( $field['id'] ),
1337
+                'name'       => esc_attr($field['id']),
1338
+                'id'         => esc_attr($field['id']),
1339 1339
                 'required'   => (bool) $field['required'],
1340
-                'label'      => wp_kses_post( $field['label'] ),
1340
+                'label'      => wp_kses_post($field['label']),
1341 1341
                 'no_wrap'    => true,
1342 1342
                 'type'       => 'date',
1343 1343
             )
1344 1344
         );
1345 1345
 
1346
-        if ( ! empty( $field['description'] ) ) {
1347
-            $description = wp_kses_post( $field['description'] );
1346
+        if (!empty($field['description'])) {
1347
+            $description = wp_kses_post($field['description']);
1348 1348
             echo "<small class='form-text text-muted'>$description</small>";
1349 1349
         }
1350 1350
 
@@ -1355,14 +1355,14 @@  discard block
 block discarded – undo
1355 1355
     /**
1356 1356
      * Renders the edit date element template.
1357 1357
      */
1358
-    public function edit_date_template( $field ) {
1359
-        $restrict = $this->get_restrict_markup( $field, 'date' );
1360
-        $label    = __( 'Field Label', 'invoicing' );
1358
+    public function edit_date_template($field) {
1359
+        $restrict = $this->get_restrict_markup($field, 'date');
1360
+        $label    = __('Field Label', 'invoicing');
1361 1361
         $id       = $field . '.id + "_edit"';
1362
-        $label3   = __( 'Help text', 'invoicing' );
1363
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1362
+        $label3   = __('Help text', 'invoicing');
1363
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1364 1364
         $id3      = $field . '.id + "_edit3"';
1365
-        $label5   = __( 'Is this field required?', 'invoicing' );
1365
+        $label5   = __('Is this field required?', 'invoicing');
1366 1366
         $id4      = $field . '.id + "_edit4"';
1367 1367
         echo "
1368 1368
             <div $restrict>
@@ -1386,8 +1386,8 @@  discard block
 block discarded – undo
1386 1386
     /**
1387 1387
      * Renders the time element template.
1388 1388
      */
1389
-    public function render_time_template( $field ) {
1390
-        $restrict = $this->get_restrict_markup( $field, 'time' );
1389
+    public function render_time_template($field) {
1390
+        $restrict = $this->get_restrict_markup($field, 'time');
1391 1391
         $label    = "$field.label";
1392 1392
         echo "
1393 1393
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1402,23 +1402,23 @@  discard block
 block discarded – undo
1402 1402
     /**
1403 1403
      * Renders the time element on the frontend.
1404 1404
      */
1405
-    public function frontend_render_time_template( $field ) {
1405
+    public function frontend_render_time_template($field) {
1406 1406
         
1407 1407
         echo "<div class='form-group'>";
1408 1408
 
1409 1409
         echo aui()->input(
1410 1410
             array(
1411
-                'name'       => esc_attr( $field['id'] ),
1412
-                'id'         => esc_attr( $field['id'] ),
1411
+                'name'       => esc_attr($field['id']),
1412
+                'id'         => esc_attr($field['id']),
1413 1413
                 'required'   => (bool) $field['required'],
1414
-                'label'      => wp_kses_post( $field['label'] ),
1414
+                'label'      => wp_kses_post($field['label']),
1415 1415
                 'no_wrap'    => true,
1416 1416
                 'type'       => 'time',
1417 1417
             )
1418 1418
         );
1419 1419
 
1420
-        if ( ! empty( $field['description'] ) ) {
1421
-            $description = wp_kses_post( $field['description'] );
1420
+        if (!empty($field['description'])) {
1421
+            $description = wp_kses_post($field['description']);
1422 1422
             echo "<small class='form-text text-muted'>$description</small>";
1423 1423
         }
1424 1424
 
@@ -1429,14 +1429,14 @@  discard block
 block discarded – undo
1429 1429
     /**
1430 1430
      * Renders the edit time element template.
1431 1431
      */
1432
-    public function edit_time_template( $field ) {
1433
-        $restrict = $this->get_restrict_markup( $field, 'time' );
1434
-        $label    = __( 'Field Label', 'invoicing' );
1432
+    public function edit_time_template($field) {
1433
+        $restrict = $this->get_restrict_markup($field, 'time');
1434
+        $label    = __('Field Label', 'invoicing');
1435 1435
         $id       = $field . '.id + "_edit"';
1436
-        $label3   = __( 'Help text', 'invoicing' );
1437
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1436
+        $label3   = __('Help text', 'invoicing');
1437
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1438 1438
         $id3      = $field . '.id + "_edit3"';
1439
-        $label5   = __( 'Is this field required?', 'invoicing' );
1439
+        $label5   = __('Is this field required?', 'invoicing');
1440 1440
         $id4      = $field . '.id + "_edit4"';
1441 1441
         echo "
1442 1442
             <div $restrict>
@@ -1460,8 +1460,8 @@  discard block
 block discarded – undo
1460 1460
     /**
1461 1461
      * Renders the number element template.
1462 1462
      */
1463
-    public function render_number_template( $field ) {
1464
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1463
+    public function render_number_template($field) {
1464
+        $restrict = $this->get_restrict_markup($field, 'number');
1465 1465
         $label    = "$field.label";
1466 1466
         echo "
1467 1467
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1476,24 +1476,24 @@  discard block
 block discarded – undo
1476 1476
     /**
1477 1477
      * Renders the number element on the frontend.
1478 1478
      */
1479
-    public function frontend_render_number_template( $field ) {
1479
+    public function frontend_render_number_template($field) {
1480 1480
         
1481 1481
         echo "<div class='form-group'>";
1482 1482
 
1483 1483
         echo aui()->input(
1484 1484
             array(
1485
-                'name'       => esc_attr( $field['id'] ),
1486
-                'id'         => esc_attr( $field['id'] ),
1485
+                'name'       => esc_attr($field['id']),
1486
+                'id'         => esc_attr($field['id']),
1487 1487
                 'required'   => (bool) $field['required'],
1488
-                'label'      => wp_kses_post( $field['label'] ),
1489
-                'placeholder' => esc_attr( $field['placeholder'] ),
1488
+                'label'      => wp_kses_post($field['label']),
1489
+                'placeholder' => esc_attr($field['placeholder']),
1490 1490
                 'no_wrap'    => true,
1491 1491
                 'type'       => 'number',
1492 1492
             )
1493 1493
         );
1494 1494
 
1495
-        if ( ! empty( $field['description'] ) ) {
1496
-            $description = wp_kses_post( $field['description'] );
1495
+        if (!empty($field['description'])) {
1496
+            $description = wp_kses_post($field['description']);
1497 1497
             echo "<small class='form-text text-muted'>$description</small>";
1498 1498
         }
1499 1499
 
@@ -1504,16 +1504,16 @@  discard block
 block discarded – undo
1504 1504
     /**
1505 1505
      * Renders the edit number element template.
1506 1506
      */
1507
-    public function edit_number_template( $field ) {
1508
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1509
-        $label    = __( 'Field Label', 'invoicing' );
1507
+    public function edit_number_template($field) {
1508
+        $restrict = $this->get_restrict_markup($field, 'number');
1509
+        $label    = __('Field Label', 'invoicing');
1510 1510
         $id       = $field . '.id + "_edit"';
1511
-        $label2   = __( 'Placeholder text', 'invoicing' );
1511
+        $label2   = __('Placeholder text', 'invoicing');
1512 1512
         $id2      = $field . '.id + "_edit2"';
1513
-        $label3   = __( 'Help text', 'invoicing' );
1514
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1513
+        $label3   = __('Help text', 'invoicing');
1514
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1515 1515
         $id3      = $field . '.id + "_edit3"';
1516
-        $label5   = __( 'Is this field required?', 'invoicing' );
1516
+        $label5   = __('Is this field required?', 'invoicing');
1517 1517
         $id4      = $field . '.id + "_edit4"';
1518 1518
         echo "
1519 1519
             <div $restrict>
@@ -1541,23 +1541,23 @@  discard block
 block discarded – undo
1541 1541
     /**
1542 1542
      * Renders the separator element template.
1543 1543
      */
1544
-    public function render_separator_template( $field ) {
1545
-        $restrict = $this->get_restrict_markup( $field, 'separator' );
1544
+    public function render_separator_template($field) {
1545
+        $restrict = $this->get_restrict_markup($field, 'separator');
1546 1546
         echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1547 1547
     }
1548 1548
 
1549 1549
     /**
1550 1550
      * Renders the separator element on the frontend.
1551 1551
      */
1552
-    public function frontend_render_separator_template( $field ) {
1552
+    public function frontend_render_separator_template($field) {
1553 1553
         echo '<hr class="featurette-divider mt-0 mb-2" />';
1554 1554
     }
1555 1555
 
1556 1556
     /**
1557 1557
      * Renders the pay button element template.
1558 1558
      */
1559
-    public function render_pay_button_template( $field ) {
1560
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1559
+    public function render_pay_button_template($field) {
1560
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1561 1561
         $label    = "$field.label";
1562 1562
         echo "
1563 1563
             <div $restrict>
@@ -1570,28 +1570,28 @@  discard block
 block discarded – undo
1570 1570
     /**
1571 1571
      * Renders the pay_button element on the frontend.
1572 1572
      */
1573
-    public function frontend_render_pay_button_template( $field ) {
1573
+    public function frontend_render_pay_button_template($field) {
1574 1574
 
1575 1575
         echo "<div class='mt-4 mb-4'>";
1576
-            do_action( 'wpinv_payment_mode_select' );
1576
+            do_action('wpinv_payment_mode_select');
1577 1577
         echo "</div>";
1578 1578
 
1579 1579
         echo "<div class='form-group'>";
1580 1580
 
1581
-        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1581
+        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class($field['class']);
1582 1582
         echo aui()->input(
1583 1583
             array(
1584
-                'name'       => esc_attr( $field['id'] ),
1585
-                'id'         => esc_attr( $field['id'] ),
1586
-                'value'      => esc_attr( $field['label'] ),
1584
+                'name'       => esc_attr($field['id']),
1585
+                'id'         => esc_attr($field['id']),
1586
+                'value'      => esc_attr($field['label']),
1587 1587
                 'no_wrap'    => true,
1588 1588
                 'type'       => 'submit',
1589 1589
                 'class'      => $class,
1590 1590
             )
1591 1591
         );
1592 1592
 
1593
-        if ( ! empty( $field['description'] ) ) {
1594
-            $description = wp_kses_post( $field['description'] );
1593
+        if (!empty($field['description'])) {
1594
+            $description = wp_kses_post($field['description']);
1595 1595
             echo "<small class='form-text text-muted'>$description</small>";
1596 1596
         }
1597 1597
 
@@ -1602,14 +1602,14 @@  discard block
 block discarded – undo
1602 1602
     /**
1603 1603
      * Renders the pay button element template.
1604 1604
      */
1605
-    public function edit_pay_button_template( $field ) {
1606
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1607
-        $label    = __( 'Button Text', 'invoicing' );
1605
+    public function edit_pay_button_template($field) {
1606
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1607
+        $label    = __('Button Text', 'invoicing');
1608 1608
         $id       = $field . '.id + "_edit"';
1609
-        $label2   = __( 'Help text', 'invoicing' );
1610
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1609
+        $label2   = __('Help text', 'invoicing');
1610
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1611 1611
         $id2      = $field . '.id + "_edit2"';
1612
-        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1612
+        $label4   = esc_attr__('Button Type', 'invoicing');
1613 1613
         $id3      = $field . '.id + "_edit3"';
1614 1614
         echo "
1615 1615
             <div $restrict>
@@ -1625,15 +1625,15 @@  discard block
 block discarded – undo
1625 1625
                     <label :for='$id3'>$label4</label>
1626 1626
 
1627 1627
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1628
-                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1629
-                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1630
-                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1631
-                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1632
-                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1633
-                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1634
-                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1635
-                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1636
-                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1628
+                        <option value='btn-primary'>" . __('Primary', 'invoicing') . "</option>
1629
+                        <option value='btn-secondary'>" . __('Secondary', 'invoicing') . "</option>
1630
+                        <option value='btn-success'>"   . __('Success', 'invoicing') . "</option>
1631
+                        <option value='btn-danger'>"    . __('Danger', 'invoicing') . "</option>
1632
+                        <option value='btn-warning'>"   . __('Warning', 'invoicing') . "</option>
1633
+                        <option value='btn-info'>"      . __('Info', 'invoicing') . "</option>
1634
+                        <option value='btn-light'>"     . __('Light', 'invoicing') . "</option>
1635
+                        <option value='btn-dark'>"      . __('Dark', 'invoicing') . "</option>
1636
+                        <option value='btn-link'>"      . __('Link', 'invoicing') . "</option>
1637 1637
                     </select>
1638 1638
                 </div>
1639 1639
             </div>
@@ -1644,8 +1644,8 @@  discard block
 block discarded – undo
1644 1644
     /**
1645 1645
      * Renders the alert element template.
1646 1646
      */
1647
-    public function render_alert_template( $field ) {
1648
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1647
+    public function render_alert_template($field) {
1648
+        $restrict = $this->get_restrict_markup($field, 'alert');
1649 1649
         $text     = "$field.text";
1650 1650
         echo "
1651 1651
             <div $restrict class='alert' :class='$field.class' role='alert'>
@@ -1660,15 +1660,15 @@  discard block
 block discarded – undo
1660 1660
     /**
1661 1661
      * Renders the alert element on the frontend.
1662 1662
      */
1663
-    public function frontend_render_alert_template( $field ) {
1663
+    public function frontend_render_alert_template($field) {
1664 1664
         
1665 1665
         echo "<div class='form-group'>";
1666 1666
 
1667 1667
         echo aui()->alert(
1668 1668
             array(
1669
-                'content'     => wp_kses_post( $field['text'] ),
1669
+                'content'     => wp_kses_post($field['text']),
1670 1670
                 'dismissible' => $field['dismissible'],
1671
-                'type'        => str_replace( 'alert-', '', $field['class'] ),
1671
+                'type'        => str_replace('alert-', '', $field['class']),
1672 1672
             )
1673 1673
         );
1674 1674
 
@@ -1679,14 +1679,14 @@  discard block
 block discarded – undo
1679 1679
     /**
1680 1680
      * Renders the alert element template.
1681 1681
      */
1682
-    public function edit_alert_template( $field ) {
1683
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1684
-        $label    = __( 'Alert Text', 'invoicing' );
1685
-        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1682
+    public function edit_alert_template($field) {
1683
+        $restrict = $this->get_restrict_markup($field, 'alert');
1684
+        $label    = __('Alert Text', 'invoicing');
1685
+        $label2   = esc_attr__('Enter your alert text here', 'invoicing');
1686 1686
         $id       = $field . '.id + "_edit"';
1687
-        $label3   = __( 'Is Dismissible?', 'invoicing' );
1687
+        $label3   = __('Is Dismissible?', 'invoicing');
1688 1688
         $id2      = $field . '.id + "_edit2"';
1689
-        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1689
+        $label4   = esc_attr__('Alert Type', 'invoicing');
1690 1690
         $id3      = $field . '.id + "_edit3"';
1691 1691
         echo "
1692 1692
             <div $restrict>
@@ -1702,14 +1702,14 @@  discard block
 block discarded – undo
1702 1702
                     <label :for='$id3'>$label4</label>
1703 1703
 
1704 1704
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1705
-                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1706
-                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1707
-                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1708
-                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1709
-                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1710
-                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1711
-                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1712
-                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1705
+                        <option value='alert-primary'>" . __('Primary', 'invoicing') . "</option>
1706
+                        <option value='alert-secondary'>" . __('Secondary', 'invoicing') . "</option>
1707
+                        <option value='alert-success'>"   . __('Success', 'invoicing') . "</option>
1708
+                        <option value='alert-danger'>"    . __('Danger', 'invoicing') . "</option>
1709
+                        <option value='alert-warning'>"   . __('Warning', 'invoicing') . "</option>
1710
+                        <option value='alert-info'>"      . __('Info', 'invoicing') . "</option>
1711
+                        <option value='alert-light'>"     . __('Light', 'invoicing') . "</option>
1712
+                        <option value='alert-dark'>"      . __('Dark', 'invoicing') . "</option>
1713 1713
                     </select>
1714 1714
                 </div>
1715 1715
             </div>
@@ -1720,8 +1720,8 @@  discard block
 block discarded – undo
1720 1720
     /**
1721 1721
      * Renders the discount element template.
1722 1722
      */
1723
-    public function render_discount_template( $field ) {
1724
-        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1723
+    public function render_discount_template($field) {
1724
+        $restrict = $this->get_restrict_markup($field, 'discount');
1725 1725
         ?>
1726 1726
 
1727 1727
             <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
@@ -1738,13 +1738,13 @@  discard block
 block discarded – undo
1738 1738
     /**
1739 1739
      * Renders the discount element on the frontend.
1740 1740
      */
1741
-    public function frontend_render_discount_template( $field ) {
1741
+    public function frontend_render_discount_template($field) {
1742 1742
         
1743
-        $placeholder = esc_attr( $field['input_label'] );
1744
-        $label       = sanitize_text_field( $field['button_label'] );
1743
+        $placeholder = esc_attr($field['input_label']);
1744
+        $label       = sanitize_text_field($field['button_label']);
1745 1745
         $description = '';
1746 1746
 
1747
-        if ( ! empty( $field['description'] ) ) {
1747
+        if (!empty($field['description'])) {
1748 1748
             $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1749 1749
         }
1750 1750
 ?>
@@ -1765,12 +1765,12 @@  discard block
 block discarded – undo
1765 1765
     /**
1766 1766
      * Renders the discount element template.
1767 1767
      */
1768
-    public function edit_discount_template( $field ) {
1769
-        $restrict = $this->get_restrict_markup( $field, 'discount' );
1770
-        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1771
-        $label2   = __( 'Help Text', 'invoicing' );
1772
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1773
-        $label4   = __( 'Button Text', 'invoicing' );
1768
+    public function edit_discount_template($field) {
1769
+        $restrict = $this->get_restrict_markup($field, 'discount');
1770
+        $label    = __('Discount Input Placeholder', 'invoicing');
1771
+        $label2   = __('Help Text', 'invoicing');
1772
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1773
+        $label4   = __('Button Text', 'invoicing');
1774 1774
         $id       = $field . '.id + "_edit"';
1775 1775
         $id2      = $field . '.id + "_edit2"';
1776 1776
         $id3      = $field . '.id + "_edit3"';
@@ -1799,11 +1799,11 @@  discard block
 block discarded – undo
1799 1799
     /**
1800 1800
      * Renders the items element template.
1801 1801
      */
1802
-    public function render_items_template( $field ) {
1803
-        $restrict  = $this->get_restrict_markup( $field, 'items' );
1804
-        $label     = __( 'Item totals will appear here. Click to set items.', 'invoicing' );
1805
-        $label2    = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' );
1806
-        $label2   .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' );
1802
+    public function render_items_template($field) {
1803
+        $restrict  = $this->get_restrict_markup($field, 'items');
1804
+        $label     = __('Item totals will appear here. Click to set items.', 'invoicing');
1805
+        $label2    = __('Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing');
1806
+        $label2   .= ' ' . __('To prevent this, limit customers to selecting a single item.', 'invoicing');
1807 1807
         echo "
1808 1808
             <div $restrict class='item_totals text-center'>
1809 1809
                 <div v-if='canCheckoutSeveralSubscriptions($field)' class='p-4 bg-danger text-light'>$label2</div>
@@ -1815,12 +1815,12 @@  discard block
 block discarded – undo
1815 1815
     /**
1816 1816
      * Renders the items element on the frontend.
1817 1817
      */
1818
-    public function frontend_render_items_template( $field, $items ) {
1818
+    public function frontend_render_items_template($field, $items) {
1819 1819
         
1820 1820
         echo "<div class='form-group item_totals'>";
1821 1821
         
1822
-        $id = esc_attr( $field['id'] );
1823
-        if ( 'total' == $field[ 'items_type' ] ) {
1822
+        $id = esc_attr($field['id']);
1823
+        if ('total' == $field['items_type']) {
1824 1824
             $total     = 0;
1825 1825
             $tax       = 0;
1826 1826
             $sub_total = 0;
@@ -1829,16 +1829,16 @@  discard block
 block discarded – undo
1829 1829
             <div class="border item_totals_type_total">
1830 1830
 
1831 1831
                 <?php
1832
-                    foreach( $items as $item ) {
1832
+                    foreach ($items as $item) {
1833 1833
 
1834
-                        $amount = floatval( $item['price'] );
1834
+                        $amount = floatval($item['price']);
1835 1835
 
1836
-                        if ( wpinv_use_taxes() ) {
1836
+                        if (wpinv_use_taxes()) {
1837 1837
 
1838
-                            $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1838
+                            $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
1839 1839
 
1840
-                            if ( wpinv_prices_include_tax() ) {
1841
-                                $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1840
+                            if (wpinv_prices_include_tax()) {
1841
+                                $pre_tax  = ($amount - $amount * $rate * 0.01);
1842 1842
                                 $item_tax = $amount - $pre_tax;
1843 1843
                             } else {
1844 1844
                                 $pre_tax  = $amount;
@@ -1850,27 +1850,27 @@  discard block
 block discarded – undo
1850 1850
                             $total     = $sub_total + $tax;
1851 1851
 
1852 1852
                         } else {
1853
-                            $total  = $total + $amount;
1853
+                            $total = $total + $amount;
1854 1854
                         }
1855 1855
 
1856 1856
                         $class  = 'col-8';
1857 1857
                         $class2 = '';
1858 1858
 
1859
-                        if ( ! empty( $item['allow_quantities'] ) ) {
1859
+                        if (!empty($item['allow_quantities'])) {
1860 1860
                             $class = 'col-6 pt-2';
1861 1861
                             $class2 = 'pt-2';
1862 1862
                         }
1863 1863
 
1864
-                        if ( ! empty( $item['custom_price'] ) ) {
1864
+                        if (!empty($item['custom_price'])) {
1865 1865
                             $class .= ' pt-2';
1866 1866
                         }
1867 1867
             
1868 1868
                 ?>
1869 1869
                     <div  class="item_totals_item">
1870 1870
                         <div class='row pl-2 pr-2 pt-2'>
1871
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
1871
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
1872 1872
 
1873
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
1873
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
1874 1874
 
1875 1875
                                 <div class='col-2'>
1876 1876
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -1878,11 +1878,11 @@  discard block
 block discarded – undo
1878 1878
 
1879 1879
                             <?php } else { ?>
1880 1880
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
1881
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
1881
+                            <?php } if (empty($item['custom_price'])) { ?>
1882 1882
 
1883 1883
                                 <div class='col-4 <?php echo $class2; ?>'>
1884
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
1885
-                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
1884
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
1885
+                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
1886 1886
                                 </div>
1887 1887
 
1888 1888
                             <?php } else {?>
@@ -1890,15 +1890,15 @@  discard block
 block discarded – undo
1890 1890
                                 <div class='col-4'>
1891 1891
                                     <div class='input-group'>
1892 1892
 
1893
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
1893
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
1894 1894
                                             <div class='input-group-prepend'>
1895 1895
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1896 1896
                                             </div>
1897 1897
                                         <?php } ?>
1898 1898
 
1899
-                                        <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
1899
+                                        <input type='number' name='wpinv-items[<?php echo (int) $item['id']; ?>]' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
1900 1900
                                     
1901
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
1901
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
1902 1902
                                             <div class='input-group-append'>
1903 1903
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
1904 1904
                                             </div>
@@ -1909,28 +1909,28 @@  discard block
 block discarded – undo
1909 1909
                             <?php } ?>
1910 1910
 
1911 1911
                         </div>
1912
-                        <?php if ( ! empty( $item['description'] )) { ?>
1913
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1912
+                        <?php if (!empty($item['description'])) { ?>
1913
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
1914 1914
                         <?php } ?>
1915 1915
                     </div>
1916 1916
                 <?php } ?>
1917 1917
 
1918 1918
                 <div class='mt-4 border-top item_totals_total p-2'>
1919 1919
 
1920
-                    <?php if ( wpinv_use_taxes() ) { ?>
1920
+                    <?php if (wpinv_use_taxes()) { ?>
1921 1921
                         <div class='row'>
1922
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
1923
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
1922
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
1923
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
1924 1924
                         </div>
1925 1925
                         <div class='row'>
1926
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
1927
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
1926
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
1927
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
1928 1928
                         </div>
1929 1929
                     <?php } ?>
1930 1930
 
1931 1931
                     <div class='row'>
1932
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
1933
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
1932
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
1933
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
1934 1934
                     </div>
1935 1935
 
1936 1936
                 </div>
@@ -1938,22 +1938,22 @@  discard block
 block discarded – undo
1938 1938
             </div>
1939 1939
         <?php } ?>
1940 1940
 
1941
-        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
1941
+        <?php if ('radio' == $field['items_type']) { ?>
1942 1942
             <div class="item_totals_type_radio">
1943 1943
 
1944 1944
                 <?php
1945
-                    foreach( $items as $index => $item ) {
1945
+                    foreach ($items as $index => $item) {
1946 1946
 
1947
-                        if ( ! empty( $item['required'] ) ) {
1947
+                        if (!empty($item['required'])) {
1948 1948
                             continue;
1949 1949
                         }
1950 1950
                 ?>
1951 1951
                     <div  class="form-check">
1952
-                        <input class='form-check-input wpinv-items-selector' <?php checked( ! isset( $selected_radio_item ) ); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
1953
-                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field( $item['title'] ); ?>&nbsp;<strong><?php echo wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) ); ?></strong></label>
1952
+                        <input class='form-check-input wpinv-items-selector' <?php checked(!isset($selected_radio_item)); $selected_radio_item = 1; ?> type='radio' value='<?php echo $item['id']; ?>' id='<?php echo $id . $index; ?>' name='wpinv-payment-form-selected-item'>
1953
+                        <label class='form-check-label' for='<?php echo $id . $index; ?>'><?php echo sanitize_text_field($item['title']); ?>&nbsp;<strong><?php echo wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price']))); ?></strong></label>
1954 1954
                     </div>
1955
-                    <?php if ( ! empty( $item['description'] )) { ?>
1956
-                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
1955
+                    <?php if (!empty($item['description'])) { ?>
1956
+                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
1957 1957
                     <?php } ?>
1958 1958
                 <?php } ?>
1959 1959
 
@@ -1965,32 +1965,32 @@  discard block
 block discarded – undo
1965 1965
                         $tax       = 0;
1966 1966
                         $sub_total = 0;
1967 1967
 
1968
-                        foreach ( $items as $item ) {
1968
+                        foreach ($items as $item) {
1969 1969
 
1970 1970
                             $class  = 'col-8';
1971 1971
                             $class2 = '';
1972 1972
 
1973
-                            if ( ! empty( $item['allow_quantities'] ) ) {
1973
+                            if (!empty($item['allow_quantities'])) {
1974 1974
                                 $class = 'col-6 pt-2';
1975 1975
                                 $class2 = 'pt-2';
1976 1976
                             }
1977 1977
 
1978
-                            if ( ! empty( $item['custom_price'] ) ) {
1978
+                            if (!empty($item['custom_price'])) {
1979 1979
                                 $class .= ' pt-2';
1980 1980
                             }
1981 1981
 
1982 1982
                             $class3 = 'd-none';
1983 1983
                             $name   = '';
1984
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
1984
+                            if (!empty($item['required']) || !isset($totals_selected_radio_item)) {
1985 1985
 
1986
-                                $amount = floatval( $item['price'] );
1986
+                                $amount = floatval($item['price']);
1987 1987
 
1988
-                                if ( wpinv_use_taxes() ) {
1988
+                                if (wpinv_use_taxes()) {
1989 1989
 
1990
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1990
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
1991 1991
 
1992
-                                    if ( wpinv_prices_include_tax() ) {
1993
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1992
+                                    if (wpinv_prices_include_tax()) {
1993
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
1994 1994
                                         $item_tax = $amount - $pre_tax;
1995 1995
                                     } else {
1996 1996
                                         $pre_tax  = $amount;
@@ -2002,13 +2002,13 @@  discard block
 block discarded – undo
2002 2002
                                     $total     = $sub_total + $tax;
2003 2003
 
2004 2004
                                 } else {
2005
-                                    $total  = $total + $amount;
2005
+                                    $total = $total + $amount;
2006 2006
                                 }
2007 2007
 
2008 2008
                                 $class3 = '';
2009 2009
                                 $name   = "wpinv-items[{$item['id']}]";
2010 2010
 
2011
-                                if ( empty( $item['required'] ) ) {
2011
+                                if (empty($item['required'])) {
2012 2012
                                     $totals_selected_radio_item = 1;
2013 2013
                                 }
2014 2014
 
@@ -2020,9 +2020,9 @@  discard block
 block discarded – undo
2020 2020
 
2021 2021
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2022 2022
                         <div class='row pl-2 pr-2 pt-2'>
2023
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2023
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2024 2024
 
2025
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2025
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2026 2026
 
2027 2027
                                 <div class='col-2'>
2028 2028
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2030,11 +2030,11 @@  discard block
 block discarded – undo
2030 2030
 
2031 2031
                             <?php } else { ?>
2032 2032
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2033
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2033
+                            <?php } if (empty($item['custom_price'])) { ?>
2034 2034
 
2035 2035
                                 <div class='col-4 <?php echo $class2; ?>'>
2036
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2037
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2036
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2037
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2038 2038
                                 </div>
2039 2039
 
2040 2040
                             <?php } else {?>
@@ -2042,15 +2042,15 @@  discard block
 block discarded – undo
2042 2042
                                 <div class='col-4'>
2043 2043
                                     <div class='input-group'>
2044 2044
 
2045
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2045
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2046 2046
                                             <div class='input-group-prepend'>
2047 2047
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2048 2048
                                             </div>
2049 2049
                                         <?php } ?>
2050 2050
 
2051
-                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2051
+                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2052 2052
                                     
2053
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2053
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2054 2054
                                             <div class='input-group-append'>
2055 2055
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2056 2056
                                             </div>
@@ -2061,27 +2061,27 @@  discard block
 block discarded – undo
2061 2061
                             <?php } ?>
2062 2062
 
2063 2063
                         </div>
2064
-                        <?php if ( ! empty( $item['description'] )) { ?>
2065
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2064
+                        <?php if (!empty($item['description'])) { ?>
2065
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2066 2066
                         <?php } ?>
2067 2067
                     </div>
2068 2068
                 <?php } ?>
2069 2069
 
2070 2070
                 <div class='mt-4 border-top item_totals_total p-2'>
2071
-                    <?php if ( wpinv_use_taxes() ) { ?>
2071
+                    <?php if (wpinv_use_taxes()) { ?>
2072 2072
                         <div class='row'>
2073
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2074
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2073
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2074
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2075 2075
                         </div>
2076 2076
                         <div class='row'>
2077
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2078
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2077
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2078
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2079 2079
                         </div>
2080 2080
                     <?php } ?>
2081 2081
 
2082 2082
                     <div class='row'>
2083
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2084
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2083
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2084
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2085 2085
                     </div>
2086 2086
                 </div>
2087 2087
 
@@ -2089,22 +2089,22 @@  discard block
 block discarded – undo
2089 2089
             </div>
2090 2090
         <?php } ?>
2091 2091
 
2092
-        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
2092
+        <?php if ('checkbox' == $field['items_type']) { ?>
2093 2093
 
2094 2094
             <div class="item_totals_type_checkbox">
2095 2095
 
2096 2096
                 <?php
2097
-                    foreach ( $items as $index => $item ) {
2097
+                    foreach ($items as $index => $item) {
2098 2098
 
2099
-                        if ( ! empty( $item['required'] ) ) {
2099
+                        if (!empty($item['required'])) {
2100 2100
                             continue;
2101 2101
                         }
2102 2102
 
2103
-                        $title = sanitize_text_field(  $item['title'] );
2104
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2105
-                        $item_id    = esc_attr( $id . "_$index" );
2106
-                        $value = esc_attr( $item['id'] );
2107
-                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
2103
+                        $title = sanitize_text_field($item['title']);
2104
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2105
+                        $item_id = esc_attr($id . "_$index");
2106
+                        $value = esc_attr($item['id']);
2107
+                        $checked = checked(!isset($selected_checkbox_item), true, false);
2108 2108
                         $selected_checkbox_item = 1;
2109 2109
 
2110 2110
                         echo "
@@ -2113,7 +2113,7 @@  discard block
 block discarded – undo
2113 2113
                                 <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
2114 2114
                             </div>";
2115 2115
 
2116
-                        if ( ! empty( $item['description'] ) ) {
2116
+                        if (!empty($item['description'])) {
2117 2117
                             echo "<small class='form-text text-muted'>{$item['description']}</small>";
2118 2118
                         }
2119 2119
                     }
@@ -2127,31 +2127,31 @@  discard block
 block discarded – undo
2127 2127
                         $tax       = 0;
2128 2128
                         $sub_total = 0;
2129 2129
 
2130
-                        foreach ( $items as $item ) {
2130
+                        foreach ($items as $item) {
2131 2131
 
2132 2132
                             $class  = 'col-8';
2133 2133
                             $class2 = '';
2134 2134
 
2135
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2135
+                            if (!empty($item['allow_quantities'])) {
2136 2136
                                 $class = 'col-6 pt-2';
2137 2137
                                 $class2 = 'pt-2';
2138 2138
                             }
2139 2139
 
2140
-                            if ( ! empty( $item['custom_price'] ) ) {
2140
+                            if (!empty($item['custom_price'])) {
2141 2141
                                 $class .= ' pt-2';
2142 2142
                             }
2143 2143
 
2144 2144
                             $class3 = 'd-none';
2145
-                            $name  = '';
2146
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2145
+                            $name = '';
2146
+                            if (!empty($item['required']) || !isset($totals_selected_checkbox_item)) {
2147 2147
 
2148
-                                $amount = floatval( $item['price'] );
2149
-                                if ( wpinv_use_taxes() ) {
2148
+                                $amount = floatval($item['price']);
2149
+                                if (wpinv_use_taxes()) {
2150 2150
 
2151
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2151
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2152 2152
 
2153
-                                    if ( wpinv_prices_include_tax() ) {
2154
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2153
+                                    if (wpinv_prices_include_tax()) {
2154
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2155 2155
                                         $item_tax = $amount - $pre_tax;
2156 2156
                                     } else {
2157 2157
                                         $pre_tax  = $amount;
@@ -2163,13 +2163,13 @@  discard block
 block discarded – undo
2163 2163
                                     $total     = $sub_total + $tax;
2164 2164
 
2165 2165
                                 } else {
2166
-                                    $total  = $total + $amount;
2166
+                                    $total = $total + $amount;
2167 2167
                                 }
2168 2168
 
2169 2169
                                 $class3 = '';
2170
-                                $name  = "wpinv-items[{$item['id']}]";
2170
+                                $name = "wpinv-items[{$item['id']}]";
2171 2171
 
2172
-                                if ( empty( $item['required'] ) ) {
2172
+                                if (empty($item['required'])) {
2173 2173
                                     $totals_selected_checkbox_item = 1;
2174 2174
                                 }
2175 2175
 
@@ -2181,9 +2181,9 @@  discard block
 block discarded – undo
2181 2181
 
2182 2182
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2183 2183
                         <div class='row pl-2 pr-2 pt-2'>
2184
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2184
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2185 2185
 
2186
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2186
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2187 2187
 
2188 2188
                                 <div class='col-2'>
2189 2189
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2191,11 +2191,11 @@  discard block
 block discarded – undo
2191 2191
 
2192 2192
                             <?php } else { ?>
2193 2193
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2194
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2194
+                            <?php } if (empty($item['custom_price'])) { ?>
2195 2195
 
2196 2196
                                 <div class='col-4 <?php echo $class2; ?>'>
2197
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2198
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2197
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2198
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2199 2199
                                 </div>
2200 2200
 
2201 2201
                             <?php } else {?>
@@ -2203,15 +2203,15 @@  discard block
 block discarded – undo
2203 2203
                                 <div class='col-4'>
2204 2204
                                     <div class='input-group'>
2205 2205
 
2206
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2206
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2207 2207
                                             <div class='input-group-prepend'>
2208 2208
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2209 2209
                                             </div>
2210 2210
                                         <?php } ?>
2211 2211
 
2212
-                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2212
+                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2213 2213
                                     
2214
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2214
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2215 2215
                                             <div class='input-group-append'>
2216 2216
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2217 2217
                                             </div>
@@ -2222,35 +2222,35 @@  discard block
 block discarded – undo
2222 2222
                             <?php } ?>
2223 2223
 
2224 2224
                         </div>
2225
-                        <?php if ( ! empty( $item['description'] )) { ?>
2226
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2225
+                        <?php if (!empty($item['description'])) { ?>
2226
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2227 2227
                         <?php } ?>
2228 2228
                     </div>
2229 2229
                 <?php } ?>
2230 2230
 
2231 2231
                 <div class='mt-4 border-top item_totals_total p-2'>
2232 2232
 
2233
-                    <?php if ( wpinv_use_taxes() ) { ?>
2233
+                    <?php if (wpinv_use_taxes()) { ?>
2234 2234
                         <div class='row'>
2235
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2236
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2235
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2236
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2237 2237
                         </div>
2238 2238
                         <div class='row'>
2239
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2240
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2239
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2240
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2241 2241
                         </div>
2242 2242
                     <?php } ?>
2243 2243
 
2244 2244
                     <div class='row'>
2245
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2246
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2245
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2246
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2247 2247
                     </div>
2248 2248
                 </div>
2249 2249
             </div>
2250 2250
             </div>
2251 2251
         <?php } ?>
2252 2252
 
2253
-        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2253
+        <?php if ('select' == $field['items_type']) { ?>
2254 2254
 
2255 2255
             <div class="item_totals_type_select">
2256 2256
 
@@ -2258,17 +2258,17 @@  discard block
 block discarded – undo
2258 2258
 
2259 2259
                     $options  = array();
2260 2260
                     $selected = '';
2261
-                    foreach ( $items as $index => $item ) {
2261
+                    foreach ($items as $index => $item) {
2262 2262
 
2263
-                        if ( ! empty( $item['required'] ) ) {
2263
+                        if (!empty($item['required'])) {
2264 2264
                             continue;
2265 2265
                         }
2266 2266
 
2267
-                        $title = sanitize_text_field(  $item['title'] );
2268
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2269
-                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2267
+                        $title = sanitize_text_field($item['title']);
2268
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2269
+                        $options[$item['id']] = "$title &nbsp; ($price)";
2270 2270
 
2271
-                        if ( ! isset( $selected_item ) ) {
2271
+                        if (!isset($selected_item)) {
2272 2272
                             $selected = $item['id'];
2273 2273
                             $selected_item = 1;
2274 2274
                         }
@@ -2279,7 +2279,7 @@  discard block
 block discarded – undo
2279 2279
                         array(
2280 2280
                                 'name'        => 'payment-form-items',
2281 2281
                                 'id'          => $id,
2282
-                                'placeholder' => __( 'Select an item', 'invoicing' ),
2282
+                                'placeholder' => __('Select an item', 'invoicing'),
2283 2283
                                 'no_wrap'     => true,
2284 2284
                                 'options'     => $options,
2285 2285
                                 'class'       => 'wpi_select2 wpinv-items-select-selector',
@@ -2296,31 +2296,31 @@  discard block
 block discarded – undo
2296 2296
                         $tax       = 0;
2297 2297
                         $sub_total = 0;
2298 2298
 
2299
-                        foreach ( $items as $item ) {
2299
+                        foreach ($items as $item) {
2300 2300
 
2301 2301
                             $class  = 'col-8';
2302 2302
                             $class2 = '';
2303 2303
 
2304
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2304
+                            if (!empty($item['allow_quantities'])) {
2305 2305
                                 $class = 'col-6 pt-2';
2306 2306
                                 $class2 = 'pt-2';
2307 2307
                             }
2308 2308
 
2309
-                            if ( ! empty( $item['custom_price'] ) ) {
2309
+                            if (!empty($item['custom_price'])) {
2310 2310
                                 $class .= ' pt-2';
2311 2311
                             }
2312 2312
 
2313 2313
                             $class3 = 'd-none';
2314
-                            $name  = '';
2315
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2314
+                            $name = '';
2315
+                            if (!empty($item['required']) || !isset($totals_selected_select_item)) {
2316 2316
 
2317
-                                $amount = floatval( $item['price'] );
2318
-                                if ( wpinv_use_taxes() ) {
2317
+                                $amount = floatval($item['price']);
2318
+                                if (wpinv_use_taxes()) {
2319 2319
 
2320
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2320
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2321 2321
 
2322
-                                    if ( wpinv_prices_include_tax() ) {
2323
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2322
+                                    if (wpinv_prices_include_tax()) {
2323
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2324 2324
                                         $item_tax = $amount - $pre_tax;
2325 2325
                                     } else {
2326 2326
                                         $pre_tax  = $amount;
@@ -2332,13 +2332,13 @@  discard block
 block discarded – undo
2332 2332
                                     $total     = $sub_total + $tax;
2333 2333
 
2334 2334
                                 } else {
2335
-                                    $total  = $total + $amount;
2335
+                                    $total = $total + $amount;
2336 2336
                                 }
2337 2337
 
2338 2338
                                 $class3 = '';
2339
-                                $name  = "wpinv-items[{$item['id']}]";
2339
+                                $name = "wpinv-items[{$item['id']}]";
2340 2340
 
2341
-                                if ( empty( $item['required'] ) ) {
2341
+                                if (empty($item['required'])) {
2342 2342
                                     $totals_selected_select_item = 1;
2343 2343
                                 }
2344 2344
 
@@ -2350,9 +2350,9 @@  discard block
 block discarded – undo
2350 2350
 
2351 2351
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2352 2352
                         <div class='row pl-2 pr-2 pt-2'>
2353
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2353
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2354 2354
 
2355
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2355
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2356 2356
 
2357 2357
                                 <div class='col-2'>
2358 2358
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2360,11 +2360,11 @@  discard block
 block discarded – undo
2360 2360
 
2361 2361
                             <?php } else { ?>
2362 2362
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2363
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2363
+                            <?php } if (empty($item['custom_price'])) { ?>
2364 2364
 
2365 2365
                                 <div class='col-4 <?php echo $class2; ?>'>
2366
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2367
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2366
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2367
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2368 2368
                                 </div>
2369 2369
 
2370 2370
                             <?php } else {?>
@@ -2372,15 +2372,15 @@  discard block
 block discarded – undo
2372 2372
                                 <div class='col-4'>
2373 2373
                                     <div class='input-group'>
2374 2374
 
2375
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2375
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2376 2376
                                             <div class='input-group-prepend'>
2377 2377
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2378 2378
                                             </div>
2379 2379
                                         <?php } ?>
2380 2380
 
2381
-                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2381
+                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2382 2382
                                     
2383
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2383
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2384 2384
                                             <div class='input-group-append'>
2385 2385
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2386 2386
                                             </div>
@@ -2391,34 +2391,34 @@  discard block
 block discarded – undo
2391 2391
                             <?php } ?>
2392 2392
 
2393 2393
                         </div>
2394
-                        <?php if ( ! empty( $item['description'] )) { ?>
2395
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2394
+                        <?php if (!empty($item['description'])) { ?>
2395
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2396 2396
                         <?php } ?>
2397 2397
                     </div>
2398 2398
                 <?php } ?>
2399 2399
 
2400 2400
                 <div class='mt-4 border-top item_totals_total p-2'>
2401 2401
 
2402
-                    <?php if ( wpinv_use_taxes() ) { ?>
2402
+                    <?php if (wpinv_use_taxes()) { ?>
2403 2403
                         <div class='row'>
2404
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2405
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2404
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2405
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2406 2406
                         </div>
2407 2407
                         <div class='row'>
2408
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2409
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2408
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2409
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2410 2410
                         </div>
2411 2411
                     <?php } ?>
2412 2412
                     <div class='row'>
2413
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2414
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2413
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2414
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2415 2415
                     </div>
2416 2416
                 </div>
2417 2417
 
2418 2418
             </div>
2419 2419
         <?php } ?>
2420 2420
 
2421
-        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2421
+        <?php if ('multi_select' == $field['items_type']) { ?>
2422 2422
 
2423 2423
             <div class="item_totals_type_multi_select">
2424 2424
 
@@ -2427,18 +2427,18 @@  discard block
 block discarded – undo
2427 2427
                     $options  = array();
2428 2428
                     $selected = array();
2429 2429
 
2430
-                    foreach ( $items as $index => $item ) {
2430
+                    foreach ($items as $index => $item) {
2431 2431
 
2432
-                        if ( ! empty( $item['required'] ) ) {
2432
+                        if (!empty($item['required'])) {
2433 2433
                             continue;
2434 2434
                         }
2435 2435
 
2436
-                        $title = sanitize_text_field(  $item['title'] );
2437
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2438
-                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2436
+                        $title = sanitize_text_field($item['title']);
2437
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2438
+                        $options[$item['id']] = "$title &nbsp; ($price)";
2439 2439
 
2440
-                        if ( ! isset( $selected_item ) ) {
2441
-                            $selected = array( $item['id'] );
2440
+                        if (!isset($selected_item)) {
2441
+                            $selected = array($item['id']);
2442 2442
                             $selected_item = 1;
2443 2443
                         }
2444 2444
 
@@ -2465,31 +2465,31 @@  discard block
 block discarded – undo
2465 2465
                         $tax       = 0;
2466 2466
                         $sub_total = 0;
2467 2467
 
2468
-                        foreach ( $items as $item ) {
2468
+                        foreach ($items as $item) {
2469 2469
 
2470 2470
                             $class  = 'col-8';
2471 2471
                             $class2 = '';
2472 2472
 
2473
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2473
+                            if (!empty($item['allow_quantities'])) {
2474 2474
                                 $class = 'col-6 pt-2';
2475 2475
                                 $class2 = 'pt-2';
2476 2476
                             }
2477 2477
 
2478
-                            if ( ! empty( $item['custom_price'] ) ) {
2478
+                            if (!empty($item['custom_price'])) {
2479 2479
                                 $class .= ' pt-2';
2480 2480
                             }
2481 2481
 
2482 2482
                             $class3 = 'd-none';
2483
-                            $name  = '';
2484
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2483
+                            $name = '';
2484
+                            if (!empty($item['required']) || !isset($totals_selected_select_item)) {
2485 2485
 
2486
-                                $amount = floatval( $item['price'] );
2487
-                                if ( wpinv_use_taxes() ) {
2486
+                                $amount = floatval($item['price']);
2487
+                                if (wpinv_use_taxes()) {
2488 2488
 
2489
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2489
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2490 2490
 
2491
-                                    if ( wpinv_prices_include_tax() ) {
2492
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2491
+                                    if (wpinv_prices_include_tax()) {
2492
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2493 2493
                                         $item_tax = $amount - $pre_tax;
2494 2494
                                     } else {
2495 2495
                                         $pre_tax  = $amount;
@@ -2501,13 +2501,13 @@  discard block
 block discarded – undo
2501 2501
                                     $total     = $sub_total + $tax;
2502 2502
 
2503 2503
                                 } else {
2504
-                                    $total  = $total + $amount;
2504
+                                    $total = $total + $amount;
2505 2505
                                 }
2506 2506
 
2507 2507
                                 $class3 = '';
2508
-                                $name  = "wpinv-items[{$item['id']}]";
2508
+                                $name = "wpinv-items[{$item['id']}]";
2509 2509
 
2510
-                                if ( empty( $item['required'] ) ) {
2510
+                                if (empty($item['required'])) {
2511 2511
                                     $totals_selected_select_item = 1;
2512 2512
                                 }
2513 2513
 
@@ -2519,9 +2519,9 @@  discard block
 block discarded – undo
2519 2519
 
2520 2520
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2521 2521
                         <div class='row pl-2 pr-2 pt-2'>
2522
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2522
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2523 2523
 
2524
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2524
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2525 2525
 
2526 2526
                                 <div class='col-2'>
2527 2527
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='1' min='1' required>
@@ -2529,11 +2529,11 @@  discard block
 block discarded – undo
2529 2529
 
2530 2530
                             <?php } else { ?>
2531 2531
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2532
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2532
+                            <?php } if (empty($item['custom_price'])) { ?>
2533 2533
 
2534 2534
                                 <div class='col-4 <?php echo $class2; ?>'>
2535
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2536
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2535
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2536
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2537 2537
                                 </div>
2538 2538
 
2539 2539
                             <?php } else {?>
@@ -2541,15 +2541,15 @@  discard block
 block discarded – undo
2541 2541
                                 <div class='col-4'>
2542 2542
                                     <div class='input-group'>
2543 2543
 
2544
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2544
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2545 2545
                                             <div class='input-group-prepend'>
2546 2546
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2547 2547
                                             </div>
2548 2548
                                         <?php } ?>
2549 2549
 
2550
-                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval( $item['price'] ); ?>' value='<?php echo floatval( $item['price'] ); ?>' min='<?php echo intval( $item['minimum_price'] ); ?>'>
2550
+                                        <input type='number' name='<?php echo $name; ?>' class='form-control wpinv-item-price-input' placeholder='<?php echo floatval($item['price']); ?>' value='<?php echo floatval($item['price']); ?>' min='<?php echo intval($item['minimum_price']); ?>'>
2551 2551
                                     
2552
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2552
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2553 2553
                                             <div class='input-group-append'>
2554 2554
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2555 2555
                                             </div>
@@ -2560,35 +2560,35 @@  discard block
 block discarded – undo
2560 2560
                             <?php } ?>
2561 2561
 
2562 2562
                         </div>
2563
-                        <?php if ( ! empty( $item['description'] )) { ?>
2564
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2563
+                        <?php if (!empty($item['description'])) { ?>
2564
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2565 2565
                         <?php } ?>
2566 2566
                     </div>
2567 2567
                 <?php } ?>
2568 2568
 
2569 2569
                 <div class='mt-4 border-top item_totals_total p-2'>
2570 2570
 
2571
-                    <?php if ( wpinv_use_taxes() ) { ?>
2571
+                    <?php if (wpinv_use_taxes()) { ?>
2572 2572
                         <div class='row'>
2573
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2574
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2573
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2574
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2575 2575
                         </div>
2576 2576
                         <div class='row'>
2577
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2578
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2577
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2578
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2579 2579
                         </div>
2580 2580
                     <?php } ?>
2581 2581
 
2582 2582
                     <div class='row'>
2583
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2584
-                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price( wpinv_format_amount( $total ) ) ?></strong></div>
2583
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2584
+                        <div class='col-4'><strong class='wpinv-items-total' data-currency='<?php echo wpinv_currency_symbol(); ?>' data-currency-position='<?php echo wpinv_currency_position(); ?>'><?php echo wpinv_price(wpinv_format_amount($total)) ?></strong></div>
2585 2585
                     </div>
2586 2586
                 </div>
2587 2587
 
2588 2588
             </div>
2589 2589
         <?php } ?>
2590
-        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2591
-            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2590
+        <?php if (!empty($field['description'])) { ?>
2591
+            <small class='form-text text-muted'><?php echo wp_kses_post($field['description']); ?></small>
2592 2592
         <?php } ?>
2593 2593
         </div>
2594 2594
         <?php
@@ -2597,20 +2597,20 @@  discard block
 block discarded – undo
2597 2597
     /**
2598 2598
      * Renders the items element template.
2599 2599
      */
2600
-    public function edit_items_template( $field ) {
2601
-        $restrict = $this->get_restrict_markup( $field, 'items' );
2602
-        $label    = __( 'Let customers...', 'invoicing' );
2603
-        $label2   = __( 'Available Items', 'invoicing' );
2604
-        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2600
+    public function edit_items_template($field) {
2601
+        $restrict = $this->get_restrict_markup($field, 'items');
2602
+        $label    = __('Let customers...', 'invoicing');
2603
+        $label2   = __('Available Items', 'invoicing');
2604
+        $label3   = esc_attr__('Add some help text for this element', 'invoicing');
2605 2605
         $id       = $field . '.id + "_edit"';
2606 2606
         $id2      = $field . '.id + "_edit2"';
2607 2607
         $id3      = $field . '.id + "_edit3"';
2608 2608
         $id4      = $field . '.id + "_edit4"';
2609
-        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2610
-        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2611
-        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2612
-        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2613
-        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2609
+        $label4   = esc_attr__('This will be shown to the customer as the recommended price', 'invoicing');
2610
+        $label5   = esc_attr__('Allow users to pay what they want', 'invoicing');
2611
+        $label6   = esc_attr__('Enter the minimum price that a user can pay', 'invoicing');
2612
+        $label7   = esc_attr__('Allow users to buy several quantities', 'invoicing');
2613
+        $label8   = esc_attr__('This item is required', 'invoicing');
2614 2614
         echo "<div $restrict>
2615 2615
 
2616 2616
                 <label>$label2</label>
@@ -2680,7 +2680,7 @@  discard block
 block discarded – undo
2680 2680
                 <div class='form-group mt-2'>
2681 2681
 
2682 2682
                     <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'>
2683
-                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2683
+                        <option value=''>" . __('Add an existing item to the form', 'invoicing') . "</option>
2684 2684
                         <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2685 2685
                     </select>
2686 2686
 
@@ -2695,11 +2695,11 @@  discard block
 block discarded – undo
2695 2695
                     <label :for='$id2'>$label</label>
2696 2696
 
2697 2697
                     <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2698
-                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2699
-                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2700
-                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2701
-                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2702
-                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2698
+                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Buy all items on the list', 'invoicing') . "</option>
2699
+                        <option value='radio'>"        . __('Select a single item from the list', 'invoicing') . "</option>
2700
+                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select one or more items on the list', 'invoicing') . "</option>
2701
+                        <option value='select'>"       . __('Select a single item from a dropdown', 'invoicing') . "</option>
2702
+                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select a one or more items from a dropdown', 'invoicing') . "</option>
2703 2703
                     </select>
2704 2704
 
2705 2705
                 </div>
@@ -2724,7 +2724,7 @@  discard block
 block discarded – undo
2724 2724
             'orderby'        => 'title',
2725 2725
             'order'          => 'ASC',
2726 2726
             'posts_per_page' => -1,
2727
-            'post_status'    => array( 'publish' ),
2727
+            'post_status'    => array('publish'),
2728 2728
             'meta_query'     => array(
2729 2729
                 array(
2730 2730
                     'key'       => '_wpinv_type',
@@ -2734,24 +2734,24 @@  discard block
 block discarded – undo
2734 2734
             )
2735 2735
         );
2736 2736
     
2737
-        $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) );
2737
+        $items = get_posts(apply_filters('wpinv_payment_form_item_dropdown_query_args', $item_args));
2738 2738
 
2739
-        if ( empty( $items ) ) {
2739
+        if (empty($items)) {
2740 2740
             return array();
2741 2741
         }
2742 2742
 
2743
-        $options    = array();
2744
-        foreach ( $items as $item ) {
2745
-            $title            = esc_html( $item->post_title );
2746
-            $title           .= wpinv_get_item_suffix( $item->ID, false );
2747
-            $id               = absint( $item->ID );
2748
-            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
2749
-            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
2743
+        $options = array();
2744
+        foreach ($items as $item) {
2745
+            $title            = esc_html($item->post_title);
2746
+            $title           .= wpinv_get_item_suffix($item->ID, false);
2747
+            $id               = absint($item->ID);
2748
+            $price            = wpinv_sanitize_amount(get_post_meta($id, '_wpinv_price', true));
2749
+            $recurring        = (bool) get_post_meta($id, '_wpinv_is_recurring', true);
2750 2750
             $description      = $item->post_excerpt;
2751
-            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
2752
-            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
2751
+            $custom_price     = (bool) get_post_meta($id, '_wpinv_dynamic_pricing', true);
2752
+            $minimum_price    = (float) get_post_meta($id, '_minimum_price', true);
2753 2753
             $allow_quantities = false;
2754
-            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
2754
+            $options[]        = compact('title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities');
2755 2755
 
2756 2756
         }
2757 2757
         return $options;
@@ -2761,47 +2761,47 @@  discard block
 block discarded – undo
2761 2761
     /**
2762 2762
      * Returns an array of items for the currently being edited form.
2763 2763
      */
2764
-    public function get_form_items( $id = false ) {
2764
+    public function get_form_items($id = false) {
2765 2765
         
2766
-        if ( empty( $id ) ) {
2767
-            return wpinv_get_data( 'sample-payment-form-items' );
2766
+        if (empty($id)) {
2767
+            return wpinv_get_data('sample-payment-form-items');
2768 2768
         }
2769 2769
         
2770
-        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
2770
+        $form_elements = get_post_meta($id, 'wpinv_form_items', true);
2771 2771
 
2772
-        if ( is_array( $form_elements ) ) {
2772
+        if (is_array($form_elements)) {
2773 2773
             return $form_elements;
2774 2774
         }
2775 2775
 
2776
-        return wpinv_get_data( 'sample-payment-form-items' );
2776
+        return wpinv_get_data('sample-payment-form-items');
2777 2777
 
2778 2778
     }
2779 2779
 
2780 2780
     /**
2781 2781
      * Returns an array of elements for the currently being edited form.
2782 2782
      */
2783
-    public function get_form_elements( $id = false ) {
2783
+    public function get_form_elements($id = false) {
2784 2784
 
2785
-        if ( empty( $id ) ) {
2786
-            return wpinv_get_data( 'sample-payment-form' );
2785
+        if (empty($id)) {
2786
+            return wpinv_get_data('sample-payment-form');
2787 2787
         }
2788 2788
         
2789
-        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
2789
+        $form_elements = get_post_meta($id, 'wpinv_form_elements', true);
2790 2790
 
2791
-        if ( is_array( $form_elements ) ) {
2791
+        if (is_array($form_elements)) {
2792 2792
             return $form_elements;
2793 2793
         }
2794 2794
 
2795
-        return wpinv_get_data( 'sample-payment-form' );
2795
+        return wpinv_get_data('sample-payment-form');
2796 2796
     }
2797 2797
 
2798 2798
     /**
2799 2799
      * Sends a redrect response to payment details.
2800 2800
      *
2801 2801
      */
2802
-    public function send_redirect_response( $url ) {
2803
-        $url = urlencode( $url );
2804
-        wp_send_json_success( $url );
2802
+    public function send_redirect_response($url) {
2803
+        $url = urlencode($url);
2804
+        wp_send_json_success($url);
2805 2805
     }
2806 2806
 
2807 2807
     /**
@@ -2812,12 +2812,12 @@  discard block
 block discarded – undo
2812 2812
 
2813 2813
         $errors = wpinv_get_errors();
2814 2814
 
2815
-        if ( ! empty( $errors ) ) {
2815
+        if (!empty($errors)) {
2816 2816
             wpinv_print_errors();
2817 2817
             exit;
2818 2818
         }
2819 2819
 
2820
-        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
2820
+        wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing'));
2821 2821
         exit;
2822 2822
 
2823 2823
     }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-mb-invoice-details.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -1,32 +1,32 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 class WPInv_Meta_Box_Details {
8
-    public static function output( $post ) {
8
+    public static function output($post) {
9 9
         global $wpinv_euvat;
10 10
 
11 11
         $currency_symbol    = wpinv_currency_symbol();
12
-        $statuses           = wpinv_get_invoice_statuses( true );
12
+        $statuses           = wpinv_get_invoice_statuses(true);
13 13
 
14
-        $post_id            = !empty( $post->ID ) ? $post->ID : 0;
15
-        $invoice            = new WPInv_Invoice( $post_id );
16
-        $status             = $invoice->get_status( false ); // Current status    
14
+        $post_id            = !empty($post->ID) ? $post->ID : 0;
15
+        $invoice            = new WPInv_Invoice($post_id);
16
+        $status             = $invoice->get_status(false); // Current status    
17 17
         $discount           = $invoice->get_discount();
18 18
         $discount_code      = $discount > 0 ? $invoice->get_discount_code() : '';
19 19
         $invoice_number     = $invoice->get_number();
20 20
         $taxable            = $invoice->is_taxable();
21 21
 
22 22
         $date_created       = $invoice->get_created_date();
23
-        $datetime_created   = strtotime( $date_created );
24
-        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $datetime_created ) : '';
23
+        $datetime_created   = strtotime($date_created);
24
+        $date_created       = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $datetime_created) : '';
25 25
         $date_completed     = $invoice->get_completed_date();
26
-        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), strtotime( $date_completed ) ) : 'n/a';
27
-        $title['status'] = __( 'Invoice Status:', 'invoicing' );
28
-        $title['number'] = __( 'Invoice Number:', 'invoicing' );
29
-        $mail_notice = esc_attr__( 'After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing' );
26
+        $date_completed     = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format') . ' ' . get_option('time_format'), strtotime($date_completed)) : 'n/a';
27
+        $title['status'] = __('Invoice Status:', 'invoicing');
28
+        $title['number'] = __('Invoice Number:', 'invoicing');
29
+        $mail_notice = esc_attr__('After saving invoice, this will send a copy of the invoice to the user&#8217;s email address.', 'invoicing');
30 30
 
31 31
         $title = apply_filters('wpinv_details_metabox_titles', $title, $invoice);
32 32
         $statuses = apply_filters('wpinv_invoice_statuses', $statuses, $invoice);
@@ -37,39 +37,39 @@  discard block
 block discarded – undo
37 37
     <div class="gdmbx2-metabox gdmbx-field-list" id="gdmbx2-metabox-wpinv_details">
38 38
 
39 39
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-date-created table-layout">
40
-            <div class="gdmbx-th"><label for="wpinv_date_created"><?php _e( 'Date Created:', 'invoicing' );?></label></div>
40
+            <div class="gdmbx-th"><label for="wpinv_date_created"><?php _e('Date Created:', 'invoicing'); ?></label></div>
41 41
             <div class="gdmbx-td">
42
-                <input type="datetime-local" value="<?php echo esc_attr( date( 'Y-m-d\TH:i:s', $datetime_created ) );?>" id="wpinv_date_created" name="date_created" class="regular-text">
42
+                <input type="datetime-local" value="<?php echo esc_attr(date('Y-m-d\TH:i:s', $datetime_created)); ?>" id="wpinv_date_created" name="date_created" class="regular-text">
43 43
             </div>
44 44
         </div>
45 45
 
46
-        <?php if ( $invoice->post_type == 'wpi_invoice' && wpinv_get_option( 'overdue_active' ) && ( $invoice->needs_payment() || $invoice->has_status( array( 'auto-draft', 'draft' ) ) ) ) { ?>
46
+        <?php if ($invoice->post_type == 'wpi_invoice' && wpinv_get_option('overdue_active') && ($invoice->needs_payment() || $invoice->has_status(array('auto-draft', 'draft')))) { ?>
47 47
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-overdue">
48
-            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e( 'Due Date:', 'invoicing' );?></label></div>
48
+            <div class="gdmbx-th"><label for="wpinv_due_date"><?php _e('Due Date:', 'invoicing'); ?></label></div>
49 49
             <div class="gdmbx-td">
50
-                <input type="text" placeholder="<?php esc_attr_e( 'Y-m-d', 'invoicing' );?>" value="<?php echo esc_attr( $invoice->get_due_date() );?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr( date_i18n( 'Y-m-d', $datetime_created ) );?>" data-dateFormat="yy-mm-dd">
51
-                <p class="wpi-meta-row wpi-meta-desc"><?php _e( 'Leave blank to disable sending auto reminder for this invoice.', 'invoicing' );?></p>
50
+                <input type="text" placeholder="<?php esc_attr_e('Y-m-d', 'invoicing'); ?>" value="<?php echo esc_attr($invoice->get_due_date()); ?>" id="wpinv_due_date" name="wpinv_due_date" class="regular-text wpiDatepicker" data-minDate="<?php echo esc_attr(date_i18n('Y-m-d', $datetime_created)); ?>" data-dateFormat="yy-mm-dd">
51
+                <p class="wpi-meta-row wpi-meta-desc"><?php _e('Leave blank to disable sending auto reminder for this invoice.', 'invoicing'); ?></p>
52 52
             </div>
53 53
         </div>
54 54
         <?php } ?>
55
-        <?php do_action( 'wpinv_meta_box_details_after_due_date', $post_id ); ?>
56
-        <?php if ( $date_completed && $date_completed != 'n/a' ) { ?>
55
+        <?php do_action('wpinv_meta_box_details_after_due_date', $post_id); ?>
56
+        <?php if ($date_completed && $date_completed != 'n/a') { ?>
57 57
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-date-completed">
58
-            <div class="gdmbx-th"><label><?php _e( 'Payment Date:', 'invoicing' );?></label></div>
59
-            <div class="gdmbx-td"><?php echo $date_completed;?></div>
58
+            <div class="gdmbx-th"><label><?php _e('Payment Date:', 'invoicing'); ?></label></div>
59
+            <div class="gdmbx-td"><?php echo $date_completed; ?></div>
60 60
         </div>
61 61
         <?php } ?>
62
-        <?php $is_viewed = wpinv_is_invoice_viewed( $post_id ); ?>
62
+        <?php $is_viewed = wpinv_is_invoice_viewed($post_id); ?>
63 63
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-customer-viewed">
64
-            <div class="gdmbx-th"><label><?php _e( 'Viewed by Customer:', 'invoicing' );?></label></div>
65
-            <div class="gdmbx-td"><?php ( 1 == $is_viewed ) ? _e( 'Yes', 'invoicing' ) : _e( 'No', 'invoicing' ); ?></div>
64
+            <div class="gdmbx-th"><label><?php _e('Viewed by Customer:', 'invoicing'); ?></label></div>
65
+            <div class="gdmbx-td"><?php (1 == $is_viewed) ? _e('Yes', 'invoicing') : _e('No', 'invoicing'); ?></div>
66 66
         </div>
67 67
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-status">
68 68
             <div class="gdmbx-th"><label for="wpinv_status"><?php echo $title['status']; ?></label></div>
69 69
             <div class="gdmbx-td">
70 70
                 <select required="required" id="wpinv_status" name="wpinv_status" class="gdmbx2_select wpi_select2">
71
-                    <?php foreach ( $statuses as $value => $label ) { ?>
72
-                    <option value="<?php echo $value;?>" <?php selected( $status, $value );?>><?php echo $label;?></option>
71
+                    <?php foreach ($statuses as $value => $label) { ?>
72
+                    <option value="<?php echo $value; ?>" <?php selected($status, $value); ?>><?php echo $label; ?></option>
73 73
                     <?php } ?>
74 74
                 </select>
75 75
             </div>
@@ -78,129 +78,129 @@  discard block
 block discarded – undo
78 78
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-number table-layout">
79 79
             <div class="gdmbx-th"><label for="wpinv_number"><?php echo $title['number']; ?></label></div>
80 80
             <div class="gdmbx-td">
81
-                <input type="text" value="<?php echo esc_attr( $invoice_number );?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
81
+                <input type="text" value="<?php echo esc_attr($invoice_number); ?>" id="wpinv_number" name="wpinv_number" class="regular-text" readonly>
82 82
             </div>
83 83
         </div>
84
-        <?php do_action( 'wpinv_meta_box_details_inner', $post_id );
84
+        <?php do_action('wpinv_meta_box_details_inner', $post_id);
85 85
         $disable_discount = apply_filters('wpinv_disable_apply_discount', false, $invoice, $post_id);
86 86
         ?>
87 87
 
88
-        <?php if ( $wpinv_euvat->allow_vat_rules() && ! ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
88
+        <?php if ($wpinv_euvat->allow_vat_rules() && !($invoice->is_paid() || $invoice->is_refunded())) { ?>
89 89
         <div class="gdmbx-row gdmbx-type-select gdmbx2-id-wpinv-taxable">
90 90
             <div class="gdmbx-th">
91 91
                 <label for="wpinv_taxable">
92
-                    <input type="checkbox" name="disable_taxes" value="1" <?php checked( $taxable, false ); ?> id="wpinv_taxable">
93
-                    <?php _e( 'Disable taxes', 'invoicing' ); ?>
92
+                    <input type="checkbox" name="disable_taxes" value="1" <?php checked($taxable, false); ?> id="wpinv_taxable">
93
+                    <?php _e('Disable taxes', 'invoicing'); ?>
94 94
                 </label>
95 95
             </div>
96 96
         </div>
97 97
         <?php } ?>
98 98
 
99
-        <?php if ( !( $is_paid = ( $invoice->is_paid() || $invoice->is_refunded() ) ) && !$disable_discount || $discount_code ) { ?>
99
+        <?php if (!($is_paid = ($invoice->is_paid() || $invoice->is_refunded())) && !$disable_discount || $discount_code) { ?>
100 100
         <div class="gdmbx-row gdmbx-type-text gdmbx2-id-wpinv-discount-code table-layout">
101
-            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e( 'Discount Code:', 'invoicing' );?></label></div>
101
+            <div class="gdmbx-th"><label for="wpinv_discount_code"><?php _e('Discount Code:', 'invoicing'); ?></label></div>
102 102
             <div class="gdmbx-td">
103
-                <input type="text" value="<?php echo esc_attr( $discount_code ); ?>" id="wpinv_discount" class="medium-text" <?php echo ( $discount_code ? 'readonly' : '' ); ?> /><?php if ( !$is_paid && !$disable_discount ) { ?><input value="<?php echo esc_attr_e( 'Apply', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-hide' : 'wpi-inlineb' ); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e( 'Remove', 'invoicing' ); ?>" class="button button-small button-primary <?php echo ( $discount_code ? 'wpi-inlineb' : 'wpi-hide' ); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
103
+                <input type="text" value="<?php echo esc_attr($discount_code); ?>" id="wpinv_discount" class="medium-text" <?php echo ($discount_code ? 'readonly' : ''); ?> /><?php if (!$is_paid && !$disable_discount) { ?><input value="<?php echo esc_attr_e('Apply', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-hide' : 'wpi-inlineb'); ?>" id="wpinv-apply-code" type="button" /><input value="<?php echo esc_attr_e('Remove', 'invoicing'); ?>" class="button button-small button-primary <?php echo ($discount_code ? 'wpi-inlineb' : 'wpi-hide'); ?>" id="wpinv-remove-code" type="button" /><?php } ?>
104 104
             </div>
105 105
         </div>
106 106
         <?php } ?>
107 107
     </div>
108 108
 </div>
109 109
 <div class="gdmbx-row gdmbx-type-text gdmbx-wpinv-save-send table-layout">
110
-    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__( 'Send %s:', 'invoicing' ),$post_obj->labels->singular_name) ; ?></label>
110
+    <p class="wpi-meta-row wpi-save-send"><label for="wpi_save_send"><?php echo sprintf(__('Send %s:', 'invoicing'), $post_obj->labels->singular_name); ?></label>
111 111
         <select id="wpi_save_send" name="wpi_save_send" class="wpi_select2">
112
-            <option value="1"><?php _e( 'Yes', 'invoicing' ); ?></option>
113
-            <option value="" selected="selected"><?php _e( 'No', 'invoicing' ); ?></option>
112
+            <option value="1"><?php _e('Yes', 'invoicing'); ?></option>
113
+            <option value="" selected="selected"><?php _e('No', 'invoicing'); ?></option>
114 114
         </select>
115 115
     </p>
116 116
     <p class="wpi-meta-row wpi-send-info"><?php echo $mail_notice; ?></p>
117 117
 </div>
118
-<?php wp_nonce_field( 'wpinv_details', 'wpinv_details_nonce' ) ;?>
118
+<?php wp_nonce_field('wpinv_details', 'wpinv_details_nonce'); ?>
119 119
         <?php
120 120
     }
121 121
     
122
-    public static function resend_invoice( $post ) {
122
+    public static function resend_invoice($post) {
123 123
         global $wpi_mb_invoice;
124 124
         
125
-        if ( empty( $wpi_mb_invoice ) ) {
125
+        if (empty($wpi_mb_invoice)) {
126 126
             return;
127 127
         }
128 128
         
129 129
         $text = array(
130
-            'message'       => esc_attr__( 'This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing' ),
131
-            'button_text'   =>  __( 'Resend Invoice', 'invoicing' ),
130
+            'message'       => esc_attr__('This will send a copy of the invoice to the customer&#8217;s email address.', 'invoicing'),
131
+            'button_text'   =>  __('Resend Invoice', 'invoicing'),
132 132
         );
133 133
             
134 134
         $text = apply_filters('wpinv_resend_invoice_metabox_text', $text);
135
-        do_action( 'wpinv_metabox_resend_invoice_before', $wpi_mb_invoice );
135
+        do_action('wpinv_metabox_resend_invoice_before', $wpi_mb_invoice);
136 136
         
137
-        if ( $email = $wpi_mb_invoice->get_email() ) {
137
+        if ($email = $wpi_mb_invoice->get_email()) {
138 138
             $email_actions = array();
139
-            $email_actions['email_url']      = remove_query_arg( 'wpinv-message', add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) );
140
-            $email_actions['reminder_url']   = add_query_arg( array( 'wpi_action' => 'send_reminder', 'invoice_id' => $post->ID ) );
139
+            $email_actions['email_url']      = remove_query_arg('wpinv-message', add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID)));
140
+            $email_actions['reminder_url']   = add_query_arg(array('wpi_action' => 'send_reminder', 'invoice_id' => $post->ID));
141 141
             
142
-            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions );
142
+            $email_actions = apply_filters('wpinv_resend_invoice_email_actions', $email_actions);
143 143
         ?>
144 144
         <p class="wpi-meta-row wpi-resend-info"><?php echo $text['message']; ?></p>
145
-        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url( $email_actions['email_url'] ); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
146
-        <?php if ( wpinv_get_option( 'overdue_active' ) && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ( $due_date = $wpi_mb_invoice->get_due_date() ) ) { ?>
147
-        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e( 'Send overdue reminder notification to customer', 'invoicing' ); ?>" href="<?php echo esc_url( $email_actions['reminder_url'] ); ?>" class="button button-secondary"><?php esc_attr_e( 'Send Reminder', 'invoicing' ); ?></a></p>
145
+        <p class="wpi-meta-row wpi-resend-email"><a href="<?php echo esc_url($email_actions['email_url']); ?>" class="button button-secondary"><?php echo $text['button_text']; ?></a></p>
146
+        <?php if (wpinv_get_option('overdue_active') && "wpi_invoice" === $wpi_mb_invoice->post_type && $wpi_mb_invoice->needs_payment() && ($due_date = $wpi_mb_invoice->get_due_date())) { ?>
147
+        <p class="wpi-meta-row wpi-send-reminder"><a title="<?php esc_attr_e('Send overdue reminder notification to customer', 'invoicing'); ?>" href="<?php echo esc_url($email_actions['reminder_url']); ?>" class="button button-secondary"><?php esc_attr_e('Send Reminder', 'invoicing'); ?></a></p>
148 148
         <?php } ?>
149 149
         <?php
150 150
         }
151 151
         
152
-        do_action( 'wpinv_metabox_resend_invoice_after', $wpi_mb_invoice );
152
+        do_action('wpinv_metabox_resend_invoice_after', $wpi_mb_invoice);
153 153
     }
154 154
     
155
-    public static function subscriptions( $post ) {
156
-        $invoice = wpinv_get_invoice( $post->ID );
155
+    public static function subscriptions($post) {
156
+        $invoice = wpinv_get_invoice($post->ID);
157 157
 
158
-        if ( ! empty( $invoice ) && $invoice->is_recurring() && $invoice->is_parent() ) {
159
-            $subscription = wpinv_get_subscription( $invoice );
158
+        if (!empty($invoice) && $invoice->is_recurring() && $invoice->is_parent()) {
159
+            $subscription = wpinv_get_subscription($invoice);
160 160
 
161
-            if ( empty( $subscription ) ) {
161
+            if (empty($subscription)) {
162 162
                 ?>
163
-                <p class="wpi-meta-row"><?php echo wp_sprintf( __( 'New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing' ), '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">', '</a>' ); ?></p>
163
+                <p class="wpi-meta-row"><?php echo wp_sprintf(__('New Subscription will be created when customer will checkout and pay the invoice. Go to: %sSubscriptions%s', 'invoicing'), '<a href="' . admin_url('admin.php?page=wpinv-subscriptions') . '">', '</a>'); ?></p>
164 164
                 <?php
165 165
                 return;
166 166
             }
167
-            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency );
168
-            $billing = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency;
169
-            $initial = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) );
167
+            $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency($subscription->period, $subscription->frequency);
168
+            $billing = wpinv_price(wpinv_format_amount($subscription->recurring_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id)) . ' / ' . $frequency;
169
+            $initial = wpinv_price(wpinv_format_amount($subscription->initial_amount), wpinv_get_invoice_currency_code($subscription->parent_payment_id));
170 170
             $payments = $subscription->get_child_payments();
171 171
             ?>
172 172
             <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . $subscription->status; ?>"><?php _e('Recurring Payment', 'invoicing'); ?></p>
173
-            <?php if ( ! empty( $subscription ) && ! empty( $subscription->id ) ) { ?>
173
+            <?php if (!empty($subscription) && !empty($subscription->id)) { ?>
174 174
                 <p class="wpi-meta-row wpi-sub-id">
175
-                    <label><?php _e( 'Subscription ID:', 'invoicing' ); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
175
+                    <label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p>
176 176
             <?php } ?>
177 177
             <p class="wpi-meta-row wpi-bill-cycle">
178
-                <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label><?php printf( _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ), $initial, $billing ); ?>
178
+                <label><?php _e('Billing Cycle:', 'invoicing'); ?> </label><?php printf(_x('%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing'), $initial, $billing); ?>
179 179
             </p>
180 180
             <p class="wpi-meta-row wpi-billed-times">
181
-                <label><?php _e( 'Times Billed:', 'invoicing' ); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?>
181
+                <label><?php _e('Times Billed:', 'invoicing'); ?> </label><?php echo $subscription->get_times_billed() . ' / ' . (($subscription->bill_times == 0) ? 'Until Cancelled' : $subscription->bill_times); ?>
182 182
             </p>
183 183
             <p class="wpi-meta-row wpi-start-date">
184
-                <label><?php _e( 'Start Date:', 'invoicing' ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?>
184
+                <label><?php _e('Start Date:', 'invoicing'); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->created, current_time('timestamp'))); ?>
185 185
             </p>
186 186
             <p class="wpi-meta-row wpi-end-date">
187
-                <label><?php echo ( 'trialling' == $subscription->status ? __( 'Trialling Until:', 'invoicing' ) : __( 'Expiration Date:', 'invoicing' ) ); ?> </label><?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?>
187
+                <label><?php echo ('trialling' == $subscription->status ? __('Trialling Until:', 'invoicing') : __('Expiration Date:', 'invoicing')); ?> </label><?php echo date_i18n(get_option('date_format'), strtotime($subscription->expiration, current_time('timestamp'))); ?>
188 188
             </p>
189
-            <?php if ( $subscription->status ) { ?>
189
+            <?php if ($subscription->status) { ?>
190 190
                 <p class="wpi-meta-row wpi-sub-status">
191
-                    <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
191
+                    <label><?php _e('Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
192 192
                 </p>
193 193
             <?php } ?>
194
-            <?php if ( !empty( $payments ) ) { ?>
195
-                <p><strong><?php _e( 'Renewal Payments:', 'invoicing' ); ?></strong></p>
194
+            <?php if (!empty($payments)) { ?>
195
+                <p><strong><?php _e('Renewal Payments:', 'invoicing'); ?></strong></p>
196 196
                 <ul id="wpi-sub-payments">
197
-                <?php foreach ( $payments as $payment ) {
197
+                <?php foreach ($payments as $payment) {
198 198
                     $invoice_id = $payment->ID;
199 199
                     ?>
200 200
                     <li>
201
-                        <a href="<?php echo esc_url( get_edit_post_link( $invoice_id ) ); ?>"><?php echo wpinv_get_invoice_number( $invoice_id ); ?></a>&nbsp;&ndash;&nbsp;
202
-                        <span><?php echo wpinv_get_invoice_date( $invoice_id ); ?>&nbsp;&ndash;&nbsp;</span>
203
-                        <span><?php echo wpinv_payment_total( $invoice_id, true ); ?></span>
201
+                        <a href="<?php echo esc_url(get_edit_post_link($invoice_id)); ?>"><?php echo wpinv_get_invoice_number($invoice_id); ?></a>&nbsp;&ndash;&nbsp;
202
+                        <span><?php echo wpinv_get_invoice_date($invoice_id); ?>&nbsp;&ndash;&nbsp;</span>
203
+                        <span><?php echo wpinv_payment_total($invoice_id, true); ?></span>
204 204
                     </li>
205 205
                 <?php } ?>
206 206
                 </ul>
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
         }
209 209
     }
210 210
     
211
-    public static function renewals( $post ) {
212
-        $invoice = wpinv_get_invoice( $post->ID );
211
+    public static function renewals($post) {
212
+        $invoice = wpinv_get_invoice($post->ID);
213 213
         
214
-        if ( wpinv_is_subscription_payment( $invoice ) ) {
215
-            $parent_url = get_edit_post_link( $invoice->parent_invoice );
216
-            $parent_id  = wpinv_get_invoice_number( $invoice->parent_invoice );
217
-            $subscription = wpinv_get_subscription( $invoice );
214
+        if (wpinv_is_subscription_payment($invoice)) {
215
+            $parent_url = get_edit_post_link($invoice->parent_invoice);
216
+            $parent_id  = wpinv_get_invoice_number($invoice->parent_invoice);
217
+            $subscription = wpinv_get_subscription($invoice);
218 218
         ?>
219
-        <?php if ( ! empty( $subscription ) ) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
220
-        <p class="wpi-meta-row wpi-parent-id"><label><?php _e( 'Parent Invoice:', 'invoicing' );?> </label><a href="<?php echo esc_url( $parent_url ); ?>"><?php echo $parent_id; ?></a></p>
219
+        <?php if (!empty($subscription)) { ?><p class="wpi-meta-row wpi-sub-id"><label><?php _e('Subscription ID:', 'invoicing'); ?> </label><a href="<?php echo esc_url(admin_url('admin.php?page=wpinv-subscriptions&id=' . $subscription->id)); ?>" title="<?php esc_attr_e('View or edit subscription', 'invoicing'); ?>" target="_blank"><?php echo $subscription->id; ?></a></p><?php } ?>
220
+        <p class="wpi-meta-row wpi-parent-id"><label><?php _e('Parent Invoice:', 'invoicing'); ?> </label><a href="<?php echo esc_url($parent_url); ?>"><?php echo $parent_id; ?></a></p>
221 221
         <?php
222 222
         }
223 223
     }
@@ -225,47 +225,47 @@  discard block
 block discarded – undo
225 225
     /**
226 226
      * Renders a metabox to edit a payment form.
227 227
      */
228
-    public static function payment_form( $post ) {
229
-        WPInv_Meta_Box_Form_Items::output_options( $post );
228
+    public static function payment_form($post) {
229
+        WPInv_Meta_Box_Form_Items::output_options($post);
230 230
     }
231 231
 
232 232
     /**
233 233
      * Renders a metabox to select items.
234 234
      */
235
-    public static function payment_form_items( $post ) {
236
-        WPInv_Meta_Box_Form_Items::output( $post );
235
+    public static function payment_form_items($post) {
236
+        WPInv_Meta_Box_Form_Items::output($post);
237 237
     }
238 238
     
239
-    public static function payment_meta( $post ) {
239
+    public static function payment_meta($post) {
240 240
         global $wpi_mb_invoice;
241 241
 
242
-        $set_dateway = empty( $wpi_mb_invoice->gateway ) ? true : false;
243
-        if ( !$set_dateway && !$wpi_mb_invoice->get_meta( '_wpinv_checkout', true ) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded() ) {
242
+        $set_dateway = empty($wpi_mb_invoice->gateway) ? true : false;
243
+        if (!$set_dateway && !$wpi_mb_invoice->get_meta('_wpinv_checkout', true) && !$wpi_mb_invoice->is_paid() && !$wpi_mb_invoice->is_refunded()) {
244 244
             $set_dateway = true;
245 245
         }
246 246
         
247 247
         ?>
248 248
         <p class="wpi-meta-row">
249
-        <?php if ( $set_dateway ) { $gateways = wpinv_get_enabled_payment_gateways( true ); ?>
250
-            <label for="wpinv_gateway"><?php _e( 'Gateway:', 'invoicing' ) ; ?></label>
249
+        <?php if ($set_dateway) { $gateways = wpinv_get_enabled_payment_gateways(true); ?>
250
+            <label for="wpinv_gateway"><?php _e('Gateway:', 'invoicing'); ?></label>
251 251
             <select required="required" id="wpinv_gateway" class="wpi_select2" name="wpinv_gateway">
252
-                <?php foreach ( $gateways as $name => $gateway ) {
253
-                    if ( $wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription( $name ) ) {
252
+                <?php foreach ($gateways as $name => $gateway) {
253
+                    if ($wpi_mb_invoice->is_recurring() && !wpinv_gateway_support_subscription($name)) {
254 254
                         continue;
255 255
                     }
256 256
                     ?>
257
-                <option value="<?php echo $name;?>" <?php selected( $wpi_mb_invoice->gateway, $name );?>><?php echo !empty( $gateway['admin_label'] ) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
257
+                <option value="<?php echo $name; ?>" <?php selected($wpi_mb_invoice->gateway, $name); ?>><?php echo !empty($gateway['admin_label']) ? $gateway['admin_label'] : $gateway['checkout_label']; ?></option>
258 258
                 <?php } ?>
259 259
             </select>
260 260
         <?php } else { 
261
-            echo wp_sprintf( __( '<label>Gateway:</label> %s', 'invoicing' ), wpinv_get_gateway_admin_label( $wpi_mb_invoice->gateway ) );
261
+            echo wp_sprintf(__('<label>Gateway:</label> %s', 'invoicing'), wpinv_get_gateway_admin_label($wpi_mb_invoice->gateway));
262 262
         } ?>
263 263
         </p>
264
-        <?php if ( $key = $wpi_mb_invoice->get_key() ) { ?>
265
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Key:</label> %s', 'invoicing' ), $key ); ?></p>
264
+        <?php if ($key = $wpi_mb_invoice->get_key()) { ?>
265
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Key:</label> %s', 'invoicing'), $key); ?></p>
266 266
         <?php } ?>
267
-        <?php if ( $wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded() ) { ?>
268
-        <p class="wpi-meta-row"><?php echo wp_sprintf( __( '<label>Transaction ID:</label> %s', 'invoicing' ), wpinv_payment_link_transaction_id( $wpi_mb_invoice ) ); ?></p>
267
+        <?php if ($wpi_mb_invoice->is_paid() || $wpi_mb_invoice->is_refunded()) { ?>
268
+        <p class="wpi-meta-row"><?php echo wp_sprintf(__('<label>Transaction ID:</label> %s', 'invoicing'), wpinv_payment_link_transaction_id($wpi_mb_invoice)); ?></p>
269 269
         <?php } ?>
270 270
         <?php
271 271
     }
Please login to merge, or discard this patch.