Passed
Push — master ( f921d8...35bd8d )
by Brian
17:00 queued 11:33
created
uninstall.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,13 +68,13 @@
 block discarded – undo
68 68
     // Delete invoices table.
69 69
     $table = $wpdb->prefix . 'getpaid_invoices';
70 70
     if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table ) {
71
-	    $wpdb->query( $wpdb->prepare( 'DROP TABLE %s', $table ) );
71
+        $wpdb->query( $wpdb->prepare( 'DROP TABLE %s', $table ) );
72 72
     }
73 73
 
74 74
     // Delete invoice items table.
75 75
     $table = $wpdb->prefix . 'getpaid_invoice_items';
76 76
     if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table ) {
77
-	    $wpdb->query( $wpdb->prepare( 'DROP TABLE %s', $table ) );
77
+        $wpdb->query( $wpdb->prepare( 'DROP TABLE %s', $table ) );
78 78
     }
79 79
 
80 80
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -9,72 +9,72 @@
 block discarded – undo
9 9
  */
10 10
 
11 11
 // If uninstall not called from WordPress, then exit.
12
-if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
12
+if (!defined('WP_UNINSTALL_PLUGIN')) {
13 13
     exit;
14 14
 }
15 15
 
16 16
 global $wpdb, $wp_version;
17 17
 
18
-$remove_data = get_option( 'wpinv_remove_data_on_invoice_unistall' );
18
+$remove_data = get_option('wpinv_remove_data_on_invoice_unistall');
19 19
 
20 20
 /*
21 21
  * Only remove ALL product and page data if WPINV_REMOVE_ALL_DATA constant is set to true in user's
22 22
  * wp-config.php. This is to prevent data loss when deleting the plugin from the backend
23 23
  * and to ensure only the site owner can perform this action.
24 24
  */
25
-if ( defined( 'WPINV_REMOVE_ALL_DATA' ) ) {
25
+if (defined('WPINV_REMOVE_ALL_DATA')) {
26 26
     $remove_data = true === WPINV_REMOVE_ALL_DATA ? true : false;
27 27
 }
28 28
 
29
-if ( $remove_data ) {
29
+if ($remove_data) {
30 30
     // Load Invoicing file.
31
-    include_once( 'invoicing.php' );
31
+    include_once('invoicing.php');
32 32
 
33 33
     // Roles + caps.
34
-    include_once( dirname( __FILE__ ) . '/includes/admin/install.php' );
34
+    include_once(dirname(__FILE__) . '/includes/admin/install.php');
35 35
     wpinv_remove_admin_caps();
36 36
     
37
-    $settings = get_option( 'wpinv_settings' );
37
+    $settings = get_option('wpinv_settings');
38 38
     
39 39
     // Delete pages.
40
-    $wpi_pages = array( 'checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page', 'invoice_subscription_page' );
41
-    foreach ( $wpi_pages as $page ) {
42
-        if ( !empty( $page ) && !empty( $settings[ $page ] ) ) {
43
-            wp_delete_post( $settings[ $page ], true );
40
+    $wpi_pages = array('checkout_page', 'success_page', 'failure_page', 'invoice_history_page', 'quote_history_page', 'invoice_subscription_page');
41
+    foreach ($wpi_pages as $page) {
42
+        if (!empty($page) && !empty($settings[$page])) {
43
+            wp_delete_post($settings[$page], true);
44 44
         }
45 45
     }
46 46
     
47 47
     // Delete posts + data.
48
-    $wpdb->query( "DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );" );
49
-    $wpdb->query( "DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;" );
48
+    $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type IN ( 'wpi_invoice', 'wpi_item', 'wpi_discount', 'wpi_quote' );");
49
+    $wpdb->query("DELETE meta FROM {$wpdb->postmeta} meta LEFT JOIN {$wpdb->posts} posts ON posts.ID = meta.post_id WHERE posts.ID IS NULL;");
50 50
     
51 51
     // Delete comments.
52
-    $wpdb->query( "DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';" );
53
-    $wpdb->query( "DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;" );
52
+    $wpdb->query("DELETE FROM {$wpdb->comments} WHERE comment_type LIKE 'wpinv_note';");
53
+    $wpdb->query("DELETE meta FROM {$wpdb->commentmeta} meta LEFT JOIN {$wpdb->comments} comments ON comments.comment_ID = meta.comment_id WHERE comments.comment_ID IS NULL;");
54 54
     
55 55
     // Delete user meta.
56
-    $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';" );
56
+    $wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '%_wpinv_%' OR meta_key LIKE '%_wpi_invoice%' OR meta_key LIKE '%_wpi_item%' OR meta_key LIKE '%_wpi_discount%' OR meta_key LIKE '_wpi_stripe%' OR meta_key LIKE '%_wpi_quote%';");
57 57
     
58 58
     // Cleanup Cron Schedule
59
-    wp_clear_scheduled_hook( 'wp_session_garbage_collection' );
60
-    wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
59
+    wp_clear_scheduled_hook('wp_session_garbage_collection');
60
+    wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
61 61
     
62 62
     // Delete options.
63
-    $wpdb->query( "DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';" );
63
+    $wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name LIKE 'wpinv_%' OR option_name LIKE '_wpinv_%' OR option_name LIKE '\_transient\_wpinv\_%';");
64 64
     
65 65
     // Clear any cached data that has been removed
66 66
     wp_cache_flush();
67 67
 
68 68
     // Delete invoices table.
69 69
     $table = $wpdb->prefix . 'getpaid_invoices';
70
-    if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table ) {
71
-	    $wpdb->query( $wpdb->prepare( 'DROP TABLE %s', $table ) );
70
+    if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)) === $table) {
71
+	    $wpdb->query($wpdb->prepare('DROP TABLE %s', $table));
72 72
     }
73 73
 
74 74
     // Delete invoice items table.
75 75
     $table = $wpdb->prefix . 'getpaid_invoice_items';
76
-    if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) === $table ) {
77
-	    $wpdb->query( $wpdb->prepare( 'DROP TABLE %s', $table ) );
76
+    if ($wpdb->get_var($wpdb->prepare('SHOW TABLES LIKE %s', $table)) === $table) {
77
+	    $wpdb->query($wpdb->prepare('DROP TABLE %s', $table));
78 78
     }
79 79
 
80 80
 }
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 3 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
 }
701 701
 
702 702
 function wpinv_get_payment_key( $invoice_id = 0 ) {
703
-	$invoice = new WPInv_Invoice( $invoice_id );
703
+    $invoice = new WPInv_Invoice( $invoice_id );
704 704
     return $invoice->get_key();
705 705
 }
706 706
 
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
         return false;
967 967
     }
968 968
     $invoice = wpinv_get_invoice_cart();
969
-	if ( empty( $invoice ) ) {
969
+    if ( empty( $invoice ) ) {
970 970
         return false;
971 971
     }
972 972
 
@@ -1259,20 +1259,20 @@  discard block
 block discarded – undo
1259 1259
 }
1260 1260
 
1261 1261
 function wpinv_checkout_get_cc_info() {
1262
-	$cc_info = array();
1263
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1264
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1265
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1266
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1267
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1268
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1269
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1270
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1271
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1272
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1273
-
1274
-	// Return cc info
1275
-	return $cc_info;
1262
+    $cc_info = array();
1263
+    $cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1264
+    $cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1265
+    $cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1266
+    $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1267
+    $cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1268
+    $cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1269
+    $cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1270
+    $cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1271
+    $cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1272
+    $cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1273
+
1274
+    // Return cc info
1275
+    return $cc_info;
1276 1276
 }
1277 1277
 
1278 1278
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
@@ -1479,7 +1479,7 @@  discard block
 block discarded – undo
1479 1479
         $required_fields  = wpinv_checkout_required_fields();
1480 1480
 
1481 1481
         // Loop through required fields and show error messages
1482
-         if ( !empty( $required_fields ) ) {
1482
+            if ( !empty( $required_fields ) ) {
1483 1483
             foreach ( $required_fields as $field_name => $value ) {
1484 1484
                 if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1485 1485
                     wpinv_set_error( $value['error_id'], $value['error_message'] );
@@ -1582,7 +1582,7 @@  discard block
 block discarded – undo
1582 1582
 }
1583 1583
 
1584 1584
 function wpinv_get_checkout_session() {
1585
-	global $wpi_session;
1585
+    global $wpi_session;
1586 1586
 
1587 1587
     return $wpi_session->get( 'wpinv_checkout' );
1588 1588
 }
@@ -1663,7 +1663,7 @@  discard block
 block discarded – undo
1663 1663
         $response['data']['taxf']       = $invoice->get_tax( true );
1664 1664
         $response['data']['total']      = $invoice->get_total();
1665 1665
         $response['data']['totalf']     = $invoice->get_total( true );
1666
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1666
+        $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1667 1667
 
1668 1668
         wp_send_json( $response );
1669 1669
     }
@@ -1951,52 +1951,52 @@  discard block
 block discarded – undo
1951 1951
  * Given an invoice key, this function returns the id.
1952 1952
  */
1953 1953
 function wpinv_get_invoice_id_by_key( $key ) {
1954
-	global $wpdb;
1954
+    global $wpdb;
1955 1955
     $table      = $wpdb->prefix . 'getpaid_invoices';
1956
-	return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1956
+    return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1957 1957
 }
1958 1958
 
1959 1959
 function wpinv_can_view_receipt( $invoice_key = '' ) {
1960
-	$return = false;
1960
+    $return = false;
1961 1961
 
1962
-	if ( empty( $invoice_key ) ) {
1963
-		return $return;
1964
-	}
1962
+    if ( empty( $invoice_key ) ) {
1963
+        return $return;
1964
+    }
1965 1965
 
1966
-	global $wpinv_receipt_args;
1966
+    global $wpinv_receipt_args;
1967 1967
 
1968
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1969
-	if ( isset( $_GET['invoice-id'] ) ) {
1970
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1971
-	}
1968
+    $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1969
+    if ( isset( $_GET['invoice-id'] ) ) {
1970
+        $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1971
+    }
1972 1972
 
1973
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1974
-		return $return;
1975
-	}
1973
+    if ( empty( $wpinv_receipt_args['id'] ) ) {
1974
+        return $return;
1975
+    }
1976 1976
 
1977
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1978
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1979
-		return $return;
1980
-	}
1977
+    $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1978
+    if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1979
+        return $return;
1980
+    }
1981 1981
 
1982
-	if ( is_user_logged_in() ) {
1983
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1984
-			$return = true;
1985
-		}
1986
-	}
1982
+    if ( is_user_logged_in() ) {
1983
+        if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1984
+            $return = true;
1985
+        }
1986
+    }
1987 1987
 
1988
-	$session = wpinv_get_checkout_session();
1989
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1990
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1988
+    $session = wpinv_get_checkout_session();
1989
+    if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1990
+        $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1991 1991
 
1992
-		if ( wpinv_require_login_to_checkout() ) {
1993
-			$return = $return && $check_key === $invoice_key;
1994
-		} else {
1995
-			$return = $check_key === $invoice_key;
1996
-		}
1997
-	}
1992
+        if ( wpinv_require_login_to_checkout() ) {
1993
+            $return = $return && $check_key === $invoice_key;
1994
+        } else {
1995
+            $return = $check_key === $invoice_key;
1996
+        }
1997
+    }
1998 1998
 
1999
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1999
+    return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
2000 2000
 }
2001 2001
 
2002 2002
 function wpinv_pay_for_invoice() {
@@ -2306,14 +2306,14 @@  discard block
 block discarded – undo
2306 2306
 
2307 2307
     if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2308 2308
         $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2309
-	    global $post;
2309
+        global $post;
2310 2310
 
2311 2311
         if(!empty($invoice_key)){
2312
-	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2312
+            $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2313 2313
         } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2314
-			$invoice_id = $post->ID;
2314
+            $invoice_id = $post->ID;
2315 2315
         } else {
2316
-        	return;
2316
+            return;
2317 2317
         }
2318 2318
 
2319 2319
         $invoice = new WPInv_Invoice($invoice_id);
@@ -2322,17 +2322,17 @@  discard block
 block discarded – undo
2322 2322
             return;
2323 2323
         }
2324 2324
 
2325
-	    if ( is_user_logged_in() ) {
2326
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2327
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2328
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2329
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2330
-		    }
2331
-	    } else {
2332
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2333
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2334
-		    }
2335
-	    }
2325
+        if ( is_user_logged_in() ) {
2326
+            if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2327
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2328
+            } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2329
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2330
+            }
2331
+        } else {
2332
+            if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2333
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2334
+            }
2335
+        }
2336 2336
     }
2337 2337
 
2338 2338
 }
Please login to merge, or discard this patch.
Spacing   +777 added lines, -777 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
@@ -28,48 +28,48 @@  discard block
 block discarded – undo
28 28
  * @param  bool  $wp_error       Whether to return false or WP_Error on failure.
29 29
  * @return int|WP_Error|WPInv_Invoice The value 0 or WP_Error on failure. The WPInv_Invoice object on success.
30 30
  */
31
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
32
-    if ( empty( $invoice_data ) ) {
31
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
32
+    if (empty($invoice_data)) {
33 33
         return false;
34 34
     }
35 35
     
36
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
37
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast one item.', 'invoicing' ) ) : 0;
36
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
37
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast one item.', 'invoicing')) : 0;
38 38
     }
39 39
     
40 40
     // If no user id is provided, default to the current user id
41
-    if ( empty( $invoice_data['user_id'] ) ) {
41
+    if (empty($invoice_data['user_id'])) {
42 42
         $invoice_data['user_id'] = get_current_user_id();
43 43
     }
44 44
     
45
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
45
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int) $invoice_data['invoice_id'] : 0;
46 46
     
47
-    if ( empty( $invoice_data['status'] ) ) {
47
+    if (empty($invoice_data['status'])) {
48 48
         $invoice_data['status'] = 'wpi-pending';
49 49
     }
50 50
 
51
-    if ( empty( $invoice_data['post_type'] ) ) {
51
+    if (empty($invoice_data['post_type'])) {
52 52
         $invoice_data['post_type'] = 'wpi_invoice';
53 53
     }
54 54
     
55
-    if ( empty( $invoice_data['ip'] ) ) {
55
+    if (empty($invoice_data['ip'])) {
56 56
         $invoice_data['ip'] = wpinv_get_ip();
57 57
     }
58 58
 
59 59
     // default invoice args, note that status is checked for validity in wpinv_create_invoice()
60 60
     $default_args = array(
61
-        'invoice_id'    => (int)$invoice_data['invoice_id'],
62
-        'user_id'       => (int)$invoice_data['user_id'],
61
+        'invoice_id'    => (int) $invoice_data['invoice_id'],
62
+        'user_id'       => (int) $invoice_data['user_id'],
63 63
         'status'        => $invoice_data['status'],
64 64
         'post_type'     => $invoice_data['post_type'],
65 65
     );
66 66
 
67
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
68
-    if ( is_wp_error( $invoice ) ) {
67
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
68
+    if (is_wp_error($invoice)) {
69 69
         return $wp_error ? $invoice : 0;
70 70
     }
71 71
     
72
-    if ( empty( $invoice_data['invoice_id'] ) ) {
72
+    if (empty($invoice_data['invoice_id'])) {
73 73
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
74 74
     }
75 75
     
@@ -92,24 +92,24 @@  discard block
 block discarded – undo
92 92
         'discount'              => array(),
93 93
     );
94 94
 
95
-    if ( $user_id = (int)$invoice->get_user_id() ) {
96
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
97
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
95
+    if ($user_id = (int) $invoice->get_user_id()) {
96
+        if ($user_address = wpinv_get_user_address($user_id)) {
97
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
98 98
         }
99 99
     }
100 100
     
101
-    if ( empty( $invoice_data['user_info'] ) ) {
101
+    if (empty($invoice_data['user_info'])) {
102 102
         $invoice_data['user_info'] = array();
103 103
     }
104 104
     
105
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
105
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
106 106
     
107
-    if ( empty( $user_info['first_name'] ) ) {
107
+    if (empty($user_info['first_name'])) {
108 108
         $user_info['first_name'] = $default_user_info['first_name'];
109 109
         $user_info['last_name'] = $default_user_info['last_name'];
110 110
     }
111 111
     
112
-    if ( empty( $user_info['country'] ) ) {
112
+    if (empty($user_info['country'])) {
113 113
         $user_info['country'] = $default_user_info['country'];
114 114
         $user_info['state'] = $default_user_info['state'];
115 115
         $user_info['city'] = $default_user_info['city'];
@@ -118,13 +118,13 @@  discard block
 block discarded – undo
118 118
         $user_info['phone'] = $default_user_info['phone'];
119 119
     }
120 120
     
121
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
122
-        $user_info['discount'] = (array)$user_info['discount'];
121
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
122
+        $user_info['discount'] = (array) $user_info['discount'];
123 123
     }
124 124
 
125 125
     // Payment details
126 126
     $payment_details = array();
127
-    if ( !empty( $invoice_data['payment_details'] ) ) {
127
+    if (!empty($invoice_data['payment_details'])) {
128 128
         $default_payment_details = array(
129 129
             'gateway'           => 'manual',
130 130
             'gateway_title'     => '',
@@ -132,56 +132,56 @@  discard block
 block discarded – undo
132 132
             'transaction_id'    => '',
133 133
         );
134 134
         
135
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
135
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
136 136
         
137
-        if ( empty( $payment_details['gateway'] ) ) {
137
+        if (empty($payment_details['gateway'])) {
138 138
             $payment_details['gateway'] = 'manual';
139 139
         }
140 140
         
141
-        if ( empty( $payment_details['currency'] ) ) {
141
+        if (empty($payment_details['currency'])) {
142 142
             $payment_details['currency'] = wpinv_get_default_country();
143 143
         }
144 144
         
145
-        if ( empty( $payment_details['gateway_title'] ) ) {
146
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
145
+        if (empty($payment_details['gateway_title'])) {
146
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
147 147
         }
148 148
     }
149 149
     
150
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
151
-    
152
-    if ( !empty( $payment_details ) ) {
153
-        $invoice->set( 'currency', $payment_details['currency'] );
154
-        $invoice->set( 'gateway', $payment_details['gateway'] );
155
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
156
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
157
-    }
158
-    
159
-    $invoice->set( 'user_info', $user_info );
160
-    $invoice->set( 'first_name', $user_info['first_name'] );
161
-    $invoice->set( 'last_name', $user_info['last_name'] );
162
-    $invoice->set( 'address', $user_info['address'] );
163
-    $invoice->set( 'company', $user_info['company'] );
164
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
165
-    $invoice->set( 'phone', $user_info['phone'] );
166
-    $invoice->set( 'city', $user_info['city'] );
167
-    $invoice->set( 'country', $user_info['country'] );
168
-    $invoice->set( 'state', $user_info['state'] );
169
-    $invoice->set( 'zip', $user_info['zip'] );
170
-    $invoice->set( 'discounts', $user_info['discount'] );
171
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
172
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
173
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
174
-    
175
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
176
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
177
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
178
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
179
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
180
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
150
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
151
+    
152
+    if (!empty($payment_details)) {
153
+        $invoice->set('currency', $payment_details['currency']);
154
+        $invoice->set('gateway', $payment_details['gateway']);
155
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
156
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
157
+    }
158
+    
159
+    $invoice->set('user_info', $user_info);
160
+    $invoice->set('first_name', $user_info['first_name']);
161
+    $invoice->set('last_name', $user_info['last_name']);
162
+    $invoice->set('address', $user_info['address']);
163
+    $invoice->set('company', $user_info['company']);
164
+    $invoice->set('vat_number', $user_info['vat_number']);
165
+    $invoice->set('phone', $user_info['phone']);
166
+    $invoice->set('city', $user_info['city']);
167
+    $invoice->set('country', $user_info['country']);
168
+    $invoice->set('state', $user_info['state']);
169
+    $invoice->set('zip', $user_info['zip']);
170
+    $invoice->set('discounts', $user_info['discount']);
171
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
172
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
173
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
174
+    
175
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
176
+        foreach ($invoice_data['cart_details'] as $key => $item) {
177
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
178
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
179
+            $name           = !empty($item['name']) ? $item['name'] : '';
180
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
181 181
             
182
-            $post_item  = new WPInv_Item( $item_id );
183
-            if ( !empty( $post_item ) ) {
184
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
182
+            $post_item = new WPInv_Item($item_id);
183
+            if (!empty($post_item)) {
184
+                $name       = !empty($name) ? $name : $post_item->get_name();
185 185
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
186 186
             } else {
187 187
                 continue;
@@ -191,262 +191,262 @@  discard block
 block discarded – undo
191 191
                 'name'          => $name,
192 192
                 'quantity'      => $quantity,
193 193
                 'item_price'    => $item_price,
194
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
195
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
196
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
197
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
198
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
194
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
195
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
196
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
197
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
198
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
199 199
             );
200 200
 
201
-            $invoice->add_item( $item_id, $args );
201
+            $invoice->add_item($item_id, $args);
202 202
         }
203 203
     }
204 204
 
205
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
205
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
206 206
 
207
-    if ( isset( $invoice_data['post_date'] ) ) {
208
-        $invoice->set( 'date', $invoice_data['post_date'] );
207
+    if (isset($invoice_data['post_date'])) {
208
+        $invoice->set('date', $invoice_data['post_date']);
209 209
     }
210 210
     
211 211
     // Invoice due date
212
-    if ( isset( $invoice_data['due_date'] ) ) {
213
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
212
+    if (isset($invoice_data['due_date'])) {
213
+        $invoice->set('due_date', $invoice_data['due_date']);
214 214
     }
215 215
     
216 216
     $invoice->save();
217 217
     
218 218
     // Add notes
219
-    if ( !empty( $invoice_data['private_note'] ) ) {
220
-        $invoice->add_note( $invoice_data['private_note'] );
219
+    if (!empty($invoice_data['private_note'])) {
220
+        $invoice->add_note($invoice_data['private_note']);
221 221
     }
222
-    if ( !empty( $invoice_data['user_note'] ) ) {
223
-        $invoice->add_note( $invoice_data['user_note'], true );
222
+    if (!empty($invoice_data['user_note'])) {
223
+        $invoice->add_note($invoice_data['user_note'], true);
224 224
     }
225 225
     
226
-    if ( $invoice->is_quote() ) {
226
+    if ($invoice->is_quote()) {
227 227
 
228
-        if ( isset( $invoice_data['valid_until'] ) ) {
229
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
228
+        if (isset($invoice_data['valid_until'])) {
229
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
230 230
         }
231 231
         return $invoice;
232 232
 
233 233
     }
234 234
 
235
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
235
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
236 236
 
237
-    if ( ! empty( $invoice->ID ) ) {
237
+    if (!empty($invoice->ID)) {
238 238
         global $wpi_userID, $wpinv_ip_address_country;
239 239
         
240 240
         $checkout_session = wpinv_get_checkout_session();
241 241
         
242 242
         $data_session                   = array();
243 243
         $data_session['invoice_id']     = $invoice->ID;
244
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
244
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
245 245
         
246
-        wpinv_set_checkout_session( $data_session );
246
+        wpinv_set_checkout_session($data_session);
247 247
         
248
-        $wpi_userID         = (int)$invoice->get_user_id();
248
+        $wpi_userID         = (int) $invoice->get_user_id();
249 249
         
250
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
250
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
251 251
         $_POST['state']     = $invoice->state;
252 252
 
253
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
254
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
253
+        $invoice->set('country', sanitize_text_field($_POST['country']));
254
+        $invoice->set('state', sanitize_text_field($_POST['state']));
255 255
         
256 256
         $wpinv_ip_address_country = $invoice->country;
257 257
 
258
-        $invoice = $invoice->recalculate_totals( true );
258
+        $invoice = $invoice->recalculate_totals(true);
259 259
 
260
-        wpinv_set_checkout_session( $checkout_session );
260
+        wpinv_set_checkout_session($checkout_session);
261 261
 
262 262
         return $invoice;
263 263
     }
264 264
     
265
-    if ( $wp_error ) {
266
-        if ( is_wp_error( $invoice ) ) {
265
+    if ($wp_error) {
266
+        if (is_wp_error($invoice)) {
267 267
             return $invoice;
268 268
         } else {
269
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
269
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
270 270
         }
271 271
     } else {
272 272
         return 0;
273 273
     }
274 274
 }
275 275
 
276
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
277
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
276
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
277
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
278 278
 
279
-    if ( !$invoice_ID ) {
280
-        if ( $wp_error ) {
281
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
279
+    if (!$invoice_ID) {
280
+        if ($wp_error) {
281
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
282 282
         }
283 283
         return 0;
284 284
     }
285 285
 
286
-    $invoice = wpinv_get_invoice( $invoice_ID );
286
+    $invoice = wpinv_get_invoice($invoice_ID);
287 287
 
288
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
288
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
289 289
 
290
-    if ( empty( $invoice->ID ) ) {
291
-        if ( $wp_error ) {
292
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
290
+    if (empty($invoice->ID)) {
291
+        if ($wp_error) {
292
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
293 293
         }
294 294
         return 0;
295 295
     }
296 296
 
297
-    if ( ! $invoice->has_status( array( 'wpi-pending' ) ) && ! $invoice->is_quote()  ) {
298
-        if ( $wp_error ) {
299
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
297
+    if (!$invoice->has_status(array('wpi-pending')) && !$invoice->is_quote()) {
298
+        if ($wp_error) {
299
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
300 300
         }
301 301
         return 0;
302 302
     }
303 303
 
304 304
     // Invoice status
305
-    if ( !empty( $invoice_data['status'] ) ) {
306
-        $invoice->set( 'status', $invoice_data['status'] );
305
+    if (!empty($invoice_data['status'])) {
306
+        $invoice->set('status', $invoice_data['status']);
307 307
     }
308 308
 
309 309
     // Invoice date
310
-    if ( !empty( $invoice_data['post_date'] ) ) {
311
-        $invoice->set( 'date', $invoice_data['post_date'] );
310
+    if (!empty($invoice_data['post_date'])) {
311
+        $invoice->set('date', $invoice_data['post_date']);
312 312
     }
313 313
 
314 314
     // Invoice due date
315
-    if ( isset( $invoice_data['due_date'] ) ) {
316
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
315
+    if (isset($invoice_data['due_date'])) {
316
+        $invoice->set('due_date', $invoice_data['due_date']);
317 317
     }
318 318
 
319 319
     // Invoice IP address
320
-    if ( !empty( $invoice_data['ip'] ) ) {
321
-        $invoice->set( 'ip', $invoice_data['ip'] );
320
+    if (!empty($invoice_data['ip'])) {
321
+        $invoice->set('ip', $invoice_data['ip']);
322 322
     }
323 323
     
324 324
     // User info
325
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
326
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
325
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
326
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
327 327
 
328
-        if ( $discounts = $invoice->get_discounts() ) {
328
+        if ($discounts = $invoice->get_discounts()) {
329 329
             $set_discount = $discounts;
330 330
         } else {
331 331
             $set_discount = '';
332 332
         }
333 333
 
334 334
         // Manage discount
335
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
335
+        if (!empty($invoice_data['user_info']['discount'])) {
336 336
             // Remove discount
337
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
337
+            if ($invoice_data['user_info']['discount'] == 'none') {
338 338
                 $set_discount = '';
339 339
             } else {
340 340
                 $set_discount = $invoice_data['user_info']['discount'];
341 341
             }
342 342
 
343
-            $invoice->set( 'discounts', $set_discount );
343
+            $invoice->set('discounts', $set_discount);
344 344
         }
345 345
 
346 346
         $user_info['discount'] = $set_discount;
347 347
 
348
-        $invoice->set( 'user_info', $user_info );
348
+        $invoice->set('user_info', $user_info);
349 349
     }
350 350
 
351
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
352
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
351
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
352
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
353 353
 
354
-        if ( !empty( $remove_items[0]['id'] ) ) {
355
-            foreach ( $remove_items as $item ) {
356
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
357
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
358
-                if ( empty( $item_id ) ) {
354
+        if (!empty($remove_items[0]['id'])) {
355
+            foreach ($remove_items as $item) {
356
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
357
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
358
+                if (empty($item_id)) {
359 359
                     continue;
360 360
                 }
361 361
 
362
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
363
-                    if ( $item_id == $cart_item['id'] ) {
362
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
363
+                    if ($item_id == $cart_item['id']) {
364 364
                         $args = array(
365 365
                             'id'         => $item_id,
366 366
                             'quantity'   => $quantity,
367 367
                             'cart_index' => $cart_index
368 368
                         );
369 369
 
370
-                        $invoice->remove_item( $item_id, $args );
370
+                        $invoice->remove_item($item_id, $args);
371 371
                         break;
372 372
                     }
373 373
                 }
374 374
             }
375 375
         }
376 376
 
377
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
377
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
378 378
 
379
-        if ( !empty( $add_items[0]['id'] ) ) {
380
-            foreach ( $add_items as $item ) {
381
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
382
-                $post_item      = new WPInv_Item( $item_id );
383
-                if ( empty( $post_item ) ) {
379
+        if (!empty($add_items[0]['id'])) {
380
+            foreach ($add_items as $item) {
381
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
382
+                $post_item      = new WPInv_Item($item_id);
383
+                if (empty($post_item)) {
384 384
                     continue;
385 385
                 }
386 386
 
387 387
                 $valid_item = true;
388
-                if ( !empty( $recurring_item ) ) {
389
-                    if ( $recurring_item->ID != $item_id ) {
388
+                if (!empty($recurring_item)) {
389
+                    if ($recurring_item->ID != $item_id) {
390 390
                         $valid_item = false;
391 391
                     }
392
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
392
+                } else if (wpinv_is_recurring_item($item_id)) {
393 393
                     $valid_item = false;
394 394
                 }
395 395
                 
396
-                if ( !$valid_item ) {
397
-                    if ( $wp_error ) {
398
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
396
+                if (!$valid_item) {
397
+                    if ($wp_error) {
398
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
399 399
                     }
400 400
                     return 0;
401 401
                 }
402 402
 
403
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
404
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
405
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
403
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
404
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
405
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
406 406
 
407 407
                 $args = array(
408 408
                     'name'          => $name,
409 409
                     'quantity'      => $quantity,
410 410
                     'item_price'    => $item_price,
411
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
412
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
413
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
414
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
415
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
411
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
412
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
413
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
414
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
415
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
416 416
                 );
417 417
 
418
-                $invoice->add_item( $item_id, $args );
418
+                $invoice->add_item($item_id, $args);
419 419
             }
420 420
         }
421 421
     }
422 422
     
423 423
     // Payment details
424
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
425
-        if ( !empty( $payment_details['gateway'] ) ) {
426
-            $invoice->set( 'gateway', $payment_details['gateway'] );
424
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
425
+        if (!empty($payment_details['gateway'])) {
426
+            $invoice->set('gateway', $payment_details['gateway']);
427 427
         }
428 428
 
429
-        if ( !empty( $payment_details['transaction_id'] ) ) {
430
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
429
+        if (!empty($payment_details['transaction_id'])) {
430
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
431 431
         }
432 432
     }
433 433
 
434
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
434
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
435 435
 
436 436
     // Parent invoice
437
-    if ( !empty( $invoice_data['parent'] ) ) {
438
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
437
+    if (!empty($invoice_data['parent'])) {
438
+        $invoice->set('parent_invoice', $invoice_data['parent']);
439 439
     }
440 440
 
441 441
     // Save invoice data.
442 442
     $invoice->save();
443 443
     
444
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
445
-        if ( $wp_error ) {
446
-            if ( is_wp_error( $invoice ) ) {
444
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
445
+        if ($wp_error) {
446
+            if (is_wp_error($invoice)) {
447 447
                 return $invoice;
448 448
             } else {
449
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
449
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
450 450
             }
451 451
         } else {
452 452
             return 0;
@@ -454,19 +454,19 @@  discard block
 block discarded – undo
454 454
     }
455 455
 
456 456
     // Add private note
457
-    if ( !empty( $invoice_data['private_note'] ) ) {
458
-        $invoice->add_note( $invoice_data['private_note'] );
457
+    if (!empty($invoice_data['private_note'])) {
458
+        $invoice->add_note($invoice_data['private_note']);
459 459
     }
460 460
 
461 461
     // Add user note
462
-    if ( !empty( $invoice_data['user_note'] ) ) {
463
-        $invoice->add_note( $invoice_data['user_note'], true );
462
+    if (!empty($invoice_data['user_note'])) {
463
+        $invoice->add_note($invoice_data['user_note'], true);
464 464
     }
465 465
 
466
-    if ( $invoice->is_quote() ) {
466
+    if ($invoice->is_quote()) {
467 467
 
468
-        if ( isset( $invoice_data['valid_until'] ) ) {
469
-            update_post_meta( $invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until'] );
468
+        if (isset($invoice_data['valid_until'])) {
469
+            update_post_meta($invoice->ID, 'wpinv_quote_valid_until', $invoice_data['valid_until']);
470 470
         }
471 471
         return $invoice;
472 472
 
@@ -478,466 +478,466 @@  discard block
 block discarded – undo
478 478
 
479 479
     $data_session                   = array();
480 480
     $data_session['invoice_id']     = $invoice->ID;
481
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
481
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
482 482
 
483
-    wpinv_set_checkout_session( $data_session );
483
+    wpinv_set_checkout_session($data_session);
484 484
 
485
-    $wpi_userID         = (int)$invoice->get_user_id();
485
+    $wpi_userID         = (int) $invoice->get_user_id();
486 486
 
487
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
487
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
488 488
     $_POST['state']     = $invoice->state;
489 489
 
490
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
491
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
490
+    $invoice->set('country', sanitize_text_field($_POST['country']));
491
+    $invoice->set('state', sanitize_text_field($_POST['state']));
492 492
 
493 493
     $wpinv_ip_address_country = $invoice->country;
494 494
 
495
-    $invoice = $invoice->recalculate_totals( true );
495
+    $invoice = $invoice->recalculate_totals(true);
496 496
 
497
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
497
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
498 498
 
499
-    wpinv_set_checkout_session( $checkout_session );
499
+    wpinv_set_checkout_session($checkout_session);
500 500
 
501 501
     return $invoice;
502 502
 }
503 503
 
504
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
505
-    if ( $cart && empty( $invoice_id ) ) {
506
-        $invoice_id = (int)wpinv_get_invoice_cart_id();
504
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
505
+    if ($cart && empty($invoice_id)) {
506
+        $invoice_id = (int) wpinv_get_invoice_cart_id();
507 507
     }
508 508
 
509
-    $invoice = new WPInv_Invoice( $invoice_id );
509
+    $invoice = new WPInv_Invoice($invoice_id);
510 510
 
511
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
511
+    if (!empty($invoice) && !empty($invoice->ID)) {
512 512
         return $invoice;
513 513
     }
514 514
 
515 515
     return NULL;
516 516
 }
517 517
 
518
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
519
-    return wpinv_get_invoice( $invoice_id, true );
518
+function wpinv_get_invoice_cart($invoice_id = 0) {
519
+    return wpinv_get_invoice($invoice_id, true);
520 520
 }
521 521
 
522
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
523
-    $invoice = new WPInv_Invoice( $invoice_id );
522
+function wpinv_get_invoice_description($invoice_id = 0) {
523
+    $invoice = new WPInv_Invoice($invoice_id);
524 524
     return $invoice->get_description();
525 525
 }
526 526
 
527
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
528
-    $invoice = new WPInv_Invoice( $invoice_id );
527
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
528
+    $invoice = new WPInv_Invoice($invoice_id);
529 529
     return $invoice->get_currency();
530 530
 }
531 531
 
532
-function wpinv_get_payment_user_email( $invoice_id ) {
533
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+function wpinv_get_payment_user_email($invoice_id) {
533
+    $invoice = new WPInv_Invoice($invoice_id);
534 534
     return $invoice->get_email();
535 535
 }
536 536
 
537
-function wpinv_get_user_id( $invoice_id ) {
538
-    $invoice = new WPInv_Invoice( $invoice_id );
537
+function wpinv_get_user_id($invoice_id) {
538
+    $invoice = new WPInv_Invoice($invoice_id);
539 539
     return $invoice->get_user_id();
540 540
 }
541 541
 
542
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
543
-    $invoice = new WPInv_Invoice( $invoice_id );
542
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
543
+    $invoice = new WPInv_Invoice($invoice_id);
544 544
     
545
-    return $invoice->get_status( $return_label );
545
+    return $invoice->get_status($return_label);
546 546
 }
547 547
 
548
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
549
-    $invoice = new WPInv_Invoice( $invoice_id );
548
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
549
+    $invoice = new WPInv_Invoice($invoice_id);
550 550
     
551
-    return $invoice->get_gateway( $return_label );
551
+    return $invoice->get_gateway($return_label);
552 552
 }
553 553
 
554
-function wpinv_get_payment_gateway_name( $invoice_id ) {
555
-    $invoice = new WPInv_Invoice( $invoice_id );
554
+function wpinv_get_payment_gateway_name($invoice_id) {
555
+    $invoice = new WPInv_Invoice($invoice_id);
556 556
     
557 557
     return $invoice->get_gateway_title();
558 558
 }
559 559
 
560
-function wpinv_get_payment_transaction_id( $invoice_id ) {
561
-    $invoice = new WPInv_Invoice( $invoice_id );
560
+function wpinv_get_payment_transaction_id($invoice_id) {
561
+    $invoice = new WPInv_Invoice($invoice_id);
562 562
     
563 563
     return $invoice->get_transaction_id();
564 564
 }
565 565
 
566
-function wpinv_get_id_by_transaction_id( $key ) {
566
+function wpinv_get_id_by_transaction_id($key) {
567 567
     global $wpdb;
568 568
 
569
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
569
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
570 570
 
571
-    if ( $invoice_id != NULL )
571
+    if ($invoice_id != NULL)
572 572
         return $invoice_id;
573 573
 
574 574
     return 0;
575 575
 }
576 576
 
577
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
578
-    $invoice = new WPInv_Invoice( $invoice_id );
577
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
578
+    $invoice = new WPInv_Invoice($invoice_id);
579 579
 
580
-    return $invoice->get_meta( $meta_key, $single );
580
+    return $invoice->get_meta($meta_key, $single);
581 581
 }
582 582
 
583
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
584
-    $invoice = new WPInv_Invoice( $invoice_id );
583
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
584
+    $invoice = new WPInv_Invoice($invoice_id);
585 585
     
586
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
586
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
587 587
 }
588 588
 
589
-function wpinv_get_items( $invoice_id = 0 ) {
590
-    $invoice            = wpinv_get_invoice( $invoice_id );
589
+function wpinv_get_items($invoice_id = 0) {
590
+    $invoice            = wpinv_get_invoice($invoice_id);
591 591
     
592 592
     $items              = $invoice->get_items();
593 593
     $invoice_currency   = $invoice->get_currency();
594 594
 
595
-    if ( !empty( $items ) && is_array( $items ) ) {
596
-        foreach ( $items as $key => $item ) {
595
+    if (!empty($items) && is_array($items)) {
596
+        foreach ($items as $key => $item) {
597 597
             $items[$key]['currency'] = $invoice_currency;
598 598
 
599
-            if ( !isset( $item['subtotal'] ) ) {
599
+            if (!isset($item['subtotal'])) {
600 600
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
601 601
             }
602 602
         }
603 603
     }
604 604
 
605
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
605
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
606 606
 }
607 607
 
608
-function wpinv_get_fees( $invoice_id = 0 ) {
609
-    $invoice           = wpinv_get_invoice( $invoice_id );
608
+function wpinv_get_fees($invoice_id = 0) {
609
+    $invoice           = wpinv_get_invoice($invoice_id);
610 610
     $fees              = $invoice->get_fees();
611 611
 
612
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
612
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
613 613
 }
614 614
 
615
-function wpinv_get_invoice_ip( $invoice_id ) {
616
-    $invoice = new WPInv_Invoice( $invoice_id );
615
+function wpinv_get_invoice_ip($invoice_id) {
616
+    $invoice = new WPInv_Invoice($invoice_id);
617 617
     return $invoice->get_ip();
618 618
 }
619 619
 
620
-function wpinv_get_invoice_user_info( $invoice_id ) {
621
-    $invoice = new WPInv_Invoice( $invoice_id );
620
+function wpinv_get_invoice_user_info($invoice_id) {
621
+    $invoice = new WPInv_Invoice($invoice_id);
622 622
     return $invoice->get_user_info();
623 623
 }
624 624
 
625
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
626
-    $invoice = new WPInv_Invoice( $invoice_id );
625
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
626
+    $invoice = new WPInv_Invoice($invoice_id);
627 627
 
628
-    return $invoice->get_subtotal( $currency );
628
+    return $invoice->get_subtotal($currency);
629 629
 }
630 630
 
631
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
632
-    $invoice = new WPInv_Invoice( $invoice_id );
631
+function wpinv_tax($invoice_id = 0, $currency = false) {
632
+    $invoice = new WPInv_Invoice($invoice_id);
633 633
 
634
-    return $invoice->get_tax( $currency );
634
+    return $invoice->get_tax($currency);
635 635
 }
636 636
 
637
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
638
-    $invoice = wpinv_get_invoice( $invoice_id );
637
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
638
+    $invoice = wpinv_get_invoice($invoice_id);
639 639
 
640
-    return $invoice->get_discount( $currency, $dash );
640
+    return $invoice->get_discount($currency, $dash);
641 641
 }
642 642
 
643
-function wpinv_discount_code( $invoice_id = 0 ) {
644
-    $invoice = new WPInv_Invoice( $invoice_id );
643
+function wpinv_discount_code($invoice_id = 0) {
644
+    $invoice = new WPInv_Invoice($invoice_id);
645 645
 
646 646
     return $invoice->get_discount_code();
647 647
 }
648 648
 
649
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
650
-    $invoice = new WPInv_Invoice( $invoice_id );
649
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
650
+    $invoice = new WPInv_Invoice($invoice_id);
651 651
 
652
-    return $invoice->get_total( $currency );
652
+    return $invoice->get_total($currency);
653 653
 }
654 654
 
655
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
656
-    $invoice = new WPInv_Invoice( $invoice_id );
655
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
656
+    $invoice = new WPInv_Invoice($invoice_id);
657 657
 
658
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
658
+    $format         = !empty($format) ? $format : get_option('date_format');
659 659
     $date_created   = $invoice->get_created_date();
660
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
660
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
661 661
 
662 662
     return $date_created;
663 663
 }
664 664
 
665
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
666
-    $invoice = new WPInv_Invoice( $invoice_id );
665
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
666
+    $invoice = new WPInv_Invoice($invoice_id);
667 667
     
668
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
668
+    $format         = !empty($format) ? $format : get_option('date_format');
669 669
     $date_completed = $invoice->get_completed_date();
670
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
671
-    if ( $invoice_date == '' && $default ) {
672
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
670
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
671
+    if ($invoice_date == '' && $default) {
672
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
673 673
     }
674 674
 
675 675
     return $invoice_date;
676 676
 }
677 677
 
678
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
679
-    $invoice = new WPInv_Invoice( $invoice_id );
678
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
679
+    $invoice = new WPInv_Invoice($invoice_id);
680 680
     
681 681
     return $invoice->vat_number;
682 682
 }
683 683
 
684
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
685
-    $invoice = new WPInv_Invoice( $invoice_id );
684
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
685
+    $invoice = new WPInv_Invoice($invoice_id);
686 686
 
687
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
687
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
688 688
 }
689 689
 
690
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
690
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
691 691
     global $invoicing;
692 692
     
693
-    if ( empty( $invoice_id ) ) {
693
+    if (empty($invoice_id)) {
694 694
         return NULL;
695 695
     }
696 696
     
697
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
697
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
698 698
     
699
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
699
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
700 700
 }
701 701
 
702
-function wpinv_get_payment_key( $invoice_id = 0 ) {
703
-	$invoice = new WPInv_Invoice( $invoice_id );
702
+function wpinv_get_payment_key($invoice_id = 0) {
703
+	$invoice = new WPInv_Invoice($invoice_id);
704 704
     return $invoice->get_key();
705 705
 }
706 706
 
707
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
708
-    $invoice = new WPInv_Invoice( $invoice_id );
707
+function wpinv_get_invoice_number($invoice_id = 0) {
708
+    $invoice = new WPInv_Invoice($invoice_id);
709 709
     return $invoice->get_number();
710 710
 }
711 711
 
712
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
712
+function wpinv_get_cart_discountable_subtotal($code_id) {
713 713
     $cart_items = wpinv_get_cart_content_details();
714 714
     $items      = array();
715 715
 
716
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
716
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
717 717
 
718
-    if( $cart_items ) {
718
+    if ($cart_items) {
719 719
 
720
-        foreach( $cart_items as $item ) {
720
+        foreach ($cart_items as $item) {
721 721
 
722
-            if( ! in_array( $item['id'], $excluded_items ) ) {
723
-                $items[] =  $item;
722
+            if (!in_array($item['id'], $excluded_items)) {
723
+                $items[] = $item;
724 724
             }
725 725
         }
726 726
     }
727 727
 
728
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
728
+    $subtotal = wpinv_get_cart_items_subtotal($items);
729 729
 
730
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
730
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
731 731
 }
732 732
 
733
-function wpinv_get_cart_items_subtotal( $items ) {
733
+function wpinv_get_cart_items_subtotal($items) {
734 734
     $subtotal = 0.00;
735 735
 
736
-    if ( is_array( $items ) && ! empty( $items ) ) {
737
-        $prices = wp_list_pluck( $items, 'subtotal' );
736
+    if (is_array($items) && !empty($items)) {
737
+        $prices = wp_list_pluck($items, 'subtotal');
738 738
 
739
-        if( is_array( $prices ) ) {
740
-            $subtotal = array_sum( $prices );
739
+        if (is_array($prices)) {
740
+            $subtotal = array_sum($prices);
741 741
         } else {
742 742
             $subtotal = 0.00;
743 743
         }
744 744
 
745
-        if( $subtotal < 0 ) {
745
+        if ($subtotal < 0) {
746 746
             $subtotal = 0.00;
747 747
         }
748 748
     }
749 749
 
750
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
750
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
751 751
 }
752 752
 
753
-function wpinv_get_cart_subtotal( $items = array() ) {
754
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
755
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
753
+function wpinv_get_cart_subtotal($items = array()) {
754
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
755
+    $subtotal = wpinv_get_cart_items_subtotal($items);
756 756
 
757
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
757
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
758 758
 }
759 759
 
760
-function wpinv_cart_subtotal( $items = array(), $currency = '' ) {
760
+function wpinv_cart_subtotal($items = array(), $currency = '') {
761 761
 
762
-    if( empty( $currency ) ) {
762
+    if (empty($currency)) {
763 763
         $currency = wpinv_get_currency();
764 764
     }
765 765
 
766
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ), $currency );
766
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)), $currency);
767 767
 
768 768
     return $price;
769 769
 }
770 770
 
771
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
772
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
773
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
774
-    $cart_tax  = (float)wpinv_get_cart_tax( $items, $invoice );
775
-    $fees      = (float)wpinv_get_cart_fee_total();
776
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
771
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
772
+    $subtotal  = (float) wpinv_get_cart_subtotal($items);
773
+    $discounts = (float) wpinv_get_cart_discounted_amount($items);
774
+    $cart_tax  = (float) wpinv_get_cart_tax($items, $invoice);
775
+    $fees      = (float) wpinv_get_cart_fee_total();
776
+    if (!empty($invoice) && $invoice->is_free_trial()) {
777 777
         $total = 0;
778 778
     } else {
779
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
779
+        $total = $subtotal - $discounts + $cart_tax + $fees;
780 780
     }
781 781
 
782
-    if ( $total < 0 ) {
782
+    if ($total < 0) {
783 783
         $total = 0.00;
784 784
     }
785 785
     
786
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
786
+    $total = (float) apply_filters('wpinv_get_cart_total', $total, $items);
787 787
 
788
-    return wpinv_sanitize_amount( $total );
788
+    return wpinv_sanitize_amount($total);
789 789
 }
790 790
 
791
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
791
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
792 792
     global $cart_total;
793
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ), $invoice->get_currency() );
794
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
793
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)), $invoice->get_currency());
794
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
795 795
     
796 796
     $cart_total = $total;
797 797
 
798
-    if ( !$echo ) {
798
+    if (!$echo) {
799 799
         return $total;
800 800
     }
801 801
 
802 802
     echo $total;
803 803
 }
804 804
 
805
-function wpinv_get_cart_tax( $items = array(), $invoice = 0 ) {
805
+function wpinv_get_cart_tax($items = array(), $invoice = 0) {
806 806
 
807
-    if ( ! empty( $invoice ) && ! $invoice->is_taxable() ) {
807
+    if (!empty($invoice) && !$invoice->is_taxable()) {
808 808
         return 0;
809 809
     }
810 810
 
811 811
     $cart_tax = 0;
812
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
812
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
813 813
 
814
-    if ( $items ) {
815
-        $taxes = wp_list_pluck( $items, 'tax' );
814
+    if ($items) {
815
+        $taxes = wp_list_pluck($items, 'tax');
816 816
 
817
-        if( is_array( $taxes ) ) {
818
-            $cart_tax = array_sum( $taxes );
817
+        if (is_array($taxes)) {
818
+            $cart_tax = array_sum($taxes);
819 819
         }
820 820
     }
821 821
 
822 822
     $cart_tax += wpinv_get_cart_fee_tax();
823 823
 
824
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
824
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
825 825
 }
826 826
 
827
-function wpinv_cart_tax( $items = array(), $echo = false, $currency = '', $invoice = 0 ) {
827
+function wpinv_cart_tax($items = array(), $echo = false, $currency = '', $invoice = 0) {
828 828
 
829
-    if ( ! empty( $invoice && ! $invoice->is_taxable() ) ) {
830
-        echo wpinv_price( wpinv_format_amount( 0 ), $currency );
829
+    if (!empty($invoice && !$invoice->is_taxable())) {
830
+        echo wpinv_price(wpinv_format_amount(0), $currency);
831 831
         return;
832 832
     }
833 833
 
834
-    $cart_tax = wpinv_get_cart_tax( $items, $invoice );
835
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ), $currency );
834
+    $cart_tax = wpinv_get_cart_tax($items, $invoice);
835
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax), $currency);
836 836
 
837
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
837
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
838 838
 
839
-    if ( !$echo ) {
839
+    if (!$echo) {
840 840
         return $tax;
841 841
     }
842 842
 
843 843
     echo $tax;
844 844
 }
845 845
 
846
-function wpinv_get_cart_discount_code( $items = array() ) {
846
+function wpinv_get_cart_discount_code($items = array()) {
847 847
     $invoice = wpinv_get_invoice_cart();
848
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
848
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
849 849
     
850
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
850
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
851 851
 }
852 852
 
853
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
854
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
853
+function wpinv_cart_discount_code($items = array(), $echo = false) {
854
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
855 855
 
856
-    if ( $cart_discount_code != '' ) {
856
+    if ($cart_discount_code != '') {
857 857
         $cart_discount_code = ' (' . $cart_discount_code . ')';
858 858
     }
859 859
     
860
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
860
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
861 861
 
862
-    if ( !$echo ) {
862
+    if (!$echo) {
863 863
         return $discount_code;
864 864
     }
865 865
 
866 866
     echo $discount_code;
867 867
 }
868 868
 
869
-function wpinv_get_cart_discount( $items = array() ) {
869
+function wpinv_get_cart_discount($items = array()) {
870 870
     $invoice = wpinv_get_invoice_cart();
871
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
871
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
872 872
     
873
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
873
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
874 874
 }
875 875
 
876
-function wpinv_cart_discount( $items = array(), $echo = false ) {
877
-    $cart_discount = wpinv_get_cart_discount( $items );
878
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
876
+function wpinv_cart_discount($items = array(), $echo = false) {
877
+    $cart_discount = wpinv_get_cart_discount($items);
878
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
879 879
 
880
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
880
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
881 881
 
882
-    if ( !$echo ) {
882
+    if (!$echo) {
883 883
         return $discount;
884 884
     }
885 885
 
886 886
     echo $discount;
887 887
 }
888 888
 
889
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
890
-    $item = new WPInv_Item( $item_id );
889
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
890
+    $item = new WPInv_Item($item_id);
891 891
     
892
-    return $item->get_fees( $type, $item_id );
892
+    return $item->get_fees($type, $item_id);
893 893
 }
894 894
 
895 895
 function wpinv_get_cart_fee_total() {
896
-    $total  = 0;
896
+    $total = 0;
897 897
     $fees = wpinv_get_cart_fees();
898 898
     
899
-    if ( $fees ) {
900
-        foreach ( $fees as $fee_id => $fee ) {
899
+    if ($fees) {
900
+        foreach ($fees as $fee_id => $fee) {
901 901
             $total += $fee['amount'];
902 902
         }
903 903
     }
904 904
 
905
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
905
+    return apply_filters('wpinv_get_cart_fee_total', $total);
906 906
 }
907 907
 
908 908
 function wpinv_get_cart_fee_tax() {
909 909
     $tax  = 0;
910 910
     $fees = wpinv_get_cart_fees();
911 911
 
912
-    if ( $fees ) {
913
-        foreach ( $fees as $fee_id => $fee ) {
914
-            if( ! empty( $fee['no_tax'] ) ) {
912
+    if ($fees) {
913
+        foreach ($fees as $fee_id => $fee) {
914
+            if (!empty($fee['no_tax'])) {
915 915
                 continue;
916 916
             }
917 917
 
918
-            $tax += wpinv_calculate_tax( $fee['amount'] );
918
+            $tax += wpinv_calculate_tax($fee['amount']);
919 919
         }
920 920
     }
921 921
 
922
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
922
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
923 923
 }
924 924
 
925 925
 function wpinv_cart_has_recurring_item() {
926 926
     $cart_items = wpinv_get_cart_contents();
927 927
     
928
-    if ( empty( $cart_items ) ) {
928
+    if (empty($cart_items)) {
929 929
         return false;
930 930
     }
931 931
     
932 932
     $has_subscription = false;
933
-    foreach( $cart_items as $cart_item ) {
934
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
933
+    foreach ($cart_items as $cart_item) {
934
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
935 935
             $has_subscription = true;
936 936
             break;
937 937
         }
938 938
     }
939 939
     
940
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
940
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
941 941
 }
942 942
 
943 943
 function wpinv_cart_has_free_trial() {
@@ -945,100 +945,100 @@  discard block
 block discarded – undo
945 945
     
946 946
     $free_trial = false;
947 947
     
948
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
948
+    if (!empty($invoice) && $invoice->is_free_trial()) {
949 949
         $free_trial = true;
950 950
     }
951 951
     
952
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
952
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
953 953
 }
954 954
 
955 955
 function wpinv_get_cart_contents() {
956 956
     $cart_details = wpinv_get_cart_details();
957 957
     
958
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
958
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
959 959
 }
960 960
 
961 961
 function wpinv_get_cart_content_details() {
962 962
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
963 963
     $cart_items = wpinv_get_cart_contents();
964 964
     
965
-    if ( empty( $cart_items ) ) {
965
+    if (empty($cart_items)) {
966 966
         return false;
967 967
     }
968 968
     $invoice = wpinv_get_invoice_cart();
969
-	if ( empty( $invoice ) ) {
969
+	if (empty($invoice)) {
970 970
         return false;
971 971
     }
972 972
 
973 973
     $details = array();
974
-    $length  = count( $cart_items ) - 1;
974
+    $length  = count($cart_items) - 1;
975 975
     
976
-    if ( empty( $_POST['country'] ) ) {
976
+    if (empty($_POST['country'])) {
977 977
         $_POST['country'] = $invoice->country;
978 978
     }
979
-    if ( !isset( $_POST['state'] ) ) {
979
+    if (!isset($_POST['state'])) {
980 980
         $_POST['state'] = $invoice->state;
981 981
     }
982 982
 
983
-    foreach( $cart_items as $key => $item ) {
984
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
985
-        if ( empty( $item_id ) ) {
983
+    foreach ($cart_items as $key => $item) {
984
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
985
+        if (empty($item_id)) {
986 986
             continue;
987 987
         }
988 988
         
989 989
         $wpi_current_id         = $invoice->ID;
990 990
         $wpi_item_id            = $item_id;
991 991
         
992
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
992
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
993 993
             $item_price = $item['custom_price'];
994 994
         } else {
995
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
995
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
996 996
                 $item_price = $item['item_price'];
997 997
             } else {
998
-                $item_price = wpinv_get_item_price( $item_id );
998
+                $item_price = wpinv_get_item_price($item_id);
999 999
             }
1000 1000
         }
1001
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
1002
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
1003
-        $quantity           = wpinv_get_cart_item_quantity( $item );
1004
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
1001
+        $discount           = wpinv_get_cart_item_discount_amount($item);
1002
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
1003
+        $quantity           = wpinv_get_cart_item_quantity($item);
1004
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
1005 1005
         
1006 1006
         $subtotal           = $item_price * $quantity;
1007
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
1008
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
1009
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
1007
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
1008
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
1009
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
1010 1010
         
1011
-        if ( ! $invoice->is_taxable() ) {
1011
+        if (!$invoice->is_taxable()) {
1012 1012
             $tax = 0;
1013 1013
         }
1014
-        if ( wpinv_prices_include_tax() ) {
1015
-            $subtotal -= wpinv_round_amount( $tax );
1014
+        if (wpinv_prices_include_tax()) {
1015
+            $subtotal -= wpinv_round_amount($tax);
1016 1016
         }
1017 1017
         
1018
-        $total              = $subtotal - $discount + $tax;
1018
+        $total = $subtotal - $discount + $tax;
1019 1019
         
1020 1020
         // Do not allow totals to go negatve
1021
-        if( $total < 0 ) {
1021
+        if ($total < 0) {
1022 1022
             $total = 0;
1023 1023
         }
1024 1024
         
1025
-        $details[ $key ]  = array(
1025
+        $details[$key] = array(
1026 1026
             'id'                => $item_id,
1027
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
1028
-            'item_price'        => wpinv_round_amount( $item_price ),
1029
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
1027
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
1028
+            'item_price'        => wpinv_round_amount($item_price),
1029
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
1030 1030
             'quantity'          => $quantity,
1031
-            'discount'          => wpinv_round_amount( $discount ),
1032
-            'subtotal'          => wpinv_round_amount( $subtotal ),
1033
-            'tax'               => wpinv_round_amount( $tax ),
1034
-            'price'             => wpinv_round_amount( $total ),
1031
+            'discount'          => wpinv_round_amount($discount),
1032
+            'subtotal'          => wpinv_round_amount($subtotal),
1033
+            'tax'               => wpinv_round_amount($tax),
1034
+            'price'             => wpinv_round_amount($total),
1035 1035
             'vat_rates_class'   => $tax_class,
1036 1036
             'vat_rate'          => $tax_rate,
1037
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
1037
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
1038 1038
             'fees'              => $fees,
1039 1039
         );
1040 1040
         
1041
-        if ( $wpinv_is_last_cart_item ) {
1041
+        if ($wpinv_is_last_cart_item) {
1042 1042
             $wpinv_is_last_cart_item   = false;
1043 1043
             $wpinv_flat_discount_total = 0.00;
1044 1044
         }
@@ -1047,67 +1047,67 @@  discard block
 block discarded – undo
1047 1047
     return $details;
1048 1048
 }
1049 1049
 
1050
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1050
+function wpinv_get_cart_details($invoice_id = 0) {
1051 1051
     global $ajax_cart_details;
1052 1052
 
1053
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1053
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1054 1054
     $cart_details = $ajax_cart_details;
1055
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1055
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1056 1056
         $cart_details = $invoice->cart_details;
1057 1057
     }
1058 1058
 
1059
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1060
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1059
+    if (!empty($cart_details) && is_array($cart_details)) {
1060
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1061 1061
 
1062
-        foreach ( $cart_details as $key => $cart_item ) {
1063
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1062
+        foreach ($cart_details as $key => $cart_item) {
1063
+            $cart_details[$key]['currency'] = $invoice_currency;
1064 1064
 
1065
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1066
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1065
+            if (!isset($cart_item['subtotal'])) {
1066
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1067 1067
             }
1068 1068
         }
1069 1069
     }
1070 1070
 
1071
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1071
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1072 1072
 }
1073 1073
 
1074
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1075
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1074
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1075
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1076 1076
         return;
1077 1077
     }
1078 1078
 
1079
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1079
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1080 1080
         return;
1081 1081
     }
1082 1082
 
1083
-    $invoice    = wpinv_get_invoice( $invoice_id );
1083
+    $invoice    = wpinv_get_invoice($invoice_id);
1084 1084
     
1085
-    $old_status = wpinv_status_nicename( $old_status );
1086
-    $new_status = wpinv_status_nicename( $new_status );
1085
+    $old_status = wpinv_status_nicename($old_status);
1086
+    $new_status = wpinv_status_nicename($new_status);
1087 1087
 
1088
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1088
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1089 1089
     
1090 1090
     // Add note
1091
-    return $invoice->add_note( $status_change, false, false, true );
1091
+    return $invoice->add_note($status_change, false, false, true);
1092 1092
 }
1093
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1093
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1094 1094
 
1095
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1095
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1096 1096
     global $wpi_has_free_trial;
1097 1097
     
1098 1098
     $wpi_has_free_trial = false;
1099 1099
     
1100
-    if ( $old_status == 'publish' ) {
1100
+    if ($old_status == 'publish') {
1101 1101
         return; // Make sure that payments are only paid once
1102 1102
     }
1103 1103
 
1104 1104
     // Make sure the payment completion is only processed when new status is paid
1105
-    if ( $new_status != 'publish' ) {
1105
+    if ($new_status != 'publish') {
1106 1106
         return;
1107 1107
     }
1108 1108
 
1109
-    $invoice = new WPInv_Invoice( $invoice_id );
1110
-    if ( empty( $invoice ) ) {
1109
+    $invoice = new WPInv_Invoice($invoice_id);
1110
+    if (empty($invoice)) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
@@ -1115,58 +1115,58 @@  discard block
 block discarded – undo
1115 1115
     $completed_date = $invoice->completed_date;
1116 1116
     $cart_details   = $invoice->cart_details;
1117 1117
 
1118
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1118
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1119 1119
 
1120
-    if ( is_array( $cart_details ) ) {
1120
+    if (is_array($cart_details)) {
1121 1121
         // Increase purchase count and earnings
1122
-        foreach ( $cart_details as $cart_index => $item ) {
1122
+        foreach ($cart_details as $cart_index => $item) {
1123 1123
             // Ensure these actions only run once, ever
1124
-            if ( empty( $completed_date ) ) {
1125
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1124
+            if (empty($completed_date)) {
1125
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1126 1126
             }
1127 1127
         }
1128 1128
     }
1129 1129
     
1130 1130
     // Check for discount codes and increment their use counts
1131
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1132
-        if( ! empty( $discounts ) ) {
1133
-            foreach( $discounts as $code ) {
1134
-                wpinv_increase_discount_usage( $code );
1131
+    if ($discounts = $invoice->get_discounts(true)) {
1132
+        if (!empty($discounts)) {
1133
+            foreach ($discounts as $code) {
1134
+                wpinv_increase_discount_usage($code);
1135 1135
             }
1136 1136
         }
1137 1137
     }
1138 1138
     
1139 1139
     // Ensure this action only runs once ever
1140
-    if( empty( $completed_date ) ) {
1140
+    if (empty($completed_date)) {
1141 1141
         // Save the completed date
1142
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1142
+        $invoice->set('completed_date', current_time('mysql', 0));
1143 1143
         $invoice->save();
1144 1144
 
1145
-        do_action( 'wpinv_complete_payment', $invoice_id );
1145
+        do_action('wpinv_complete_payment', $invoice_id);
1146 1146
     }
1147 1147
 
1148 1148
     // Empty the shopping cart
1149 1149
     wpinv_empty_cart();
1150 1150
 }
1151
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1151
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1152 1152
 
1153
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1154
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1153
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1154
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int) $invoice_id);
1155 1155
 
1156
-    if ( empty( $invoice ) ) {
1156
+    if (empty($invoice)) {
1157 1157
         return false;
1158 1158
     }
1159 1159
 
1160
-    return $invoice->update_status( $new_status );
1160
+    return $invoice->update_status($new_status);
1161 1161
 }
1162 1162
 
1163
-function wpinv_cart_has_fees( $type = 'all' ) {
1163
+function wpinv_cart_has_fees($type = 'all') {
1164 1164
     return false;
1165 1165
 }
1166 1166
 
1167 1167
 function wpinv_validate_checkout_fields() {    
1168 1168
     // Check if there is $_POST
1169
-    if ( empty( $_POST ) ) {
1169
+    if (empty($_POST)) {
1170 1170
         return false;
1171 1171
     }
1172 1172
 
@@ -1189,28 +1189,28 @@  discard block
 block discarded – undo
1189 1189
     
1190 1190
     $invoice = wpinv_get_invoice_cart();
1191 1191
     $has_subscription = $invoice->is_recurring();
1192
-    if ( empty( $invoice ) ) {
1193
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1192
+    if (empty($invoice)) {
1193
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1194 1194
         return $gateway;
1195 1195
     }
1196 1196
 
1197 1197
     // Check if a gateway value is present
1198
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1199
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1198
+    if (!empty($_REQUEST['wpi-gateway'])) {
1199
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1200 1200
 
1201
-        if ( $invoice->is_free() ) {
1201
+        if ($invoice->is_free()) {
1202 1202
             $gateway = 'manual';
1203
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1204
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1205
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1206
-            if ( apply_filters( 'wpinv_reject_non_recurring_gateway', true ) ) {
1207
-                wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway does not support subscription payment', 'invoicing' ) );
1203
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1204
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1205
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1206
+            if (apply_filters('wpinv_reject_non_recurring_gateway', true)) {
1207
+                wpinv_set_error('invalid_gateway', __('The selected payment gateway does not support subscription payment', 'invoicing'));
1208 1208
             }
1209 1209
         }
1210 1210
     }
1211 1211
 
1212
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1213
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1212
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1213
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1214 1214
     }
1215 1215
 
1216 1216
     return $gateway;
@@ -1224,10 +1224,10 @@  discard block
 block discarded – undo
1224 1224
     
1225 1225
     $error = false;
1226 1226
     // If we have discounts, loop through them
1227
-    if ( ! empty( $discounts ) ) {
1228
-        foreach ( $discounts as $discount ) {
1227
+    if (!empty($discounts)) {
1228
+        foreach ($discounts as $discount) {
1229 1229
             // Check if valid
1230
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1230
+            if (!wpinv_is_discount_valid($discount, (int) $wpi_cart->get_user_id())) {
1231 1231
                 // Discount is not valid
1232 1232
                 $error = true;
1233 1233
             }
@@ -1237,20 +1237,20 @@  discard block
 block discarded – undo
1237 1237
         return NULL;
1238 1238
     }
1239 1239
 
1240
-    if ( $error && !wpinv_get_errors() ) {
1241
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1240
+    if ($error && !wpinv_get_errors()) {
1241
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1242 1242
     }
1243 1243
 
1244
-    return implode( ',', $discounts );
1244
+    return implode(',', $discounts);
1245 1245
 }
1246 1246
 
1247 1247
 function wpinv_checkout_validate_cc() {
1248 1248
     $card_data = wpinv_checkout_get_cc_info();
1249 1249
 
1250 1250
     // Validate the card zip
1251
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1252
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1253
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1251
+    if (!empty($card_data['wpinv_zip'])) {
1252
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1253
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1254 1254
         }
1255 1255
     }
1256 1256
 
@@ -1260,28 +1260,28 @@  discard block
 block discarded – undo
1260 1260
 
1261 1261
 function wpinv_checkout_get_cc_info() {
1262 1262
 	$cc_info = array();
1263
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1264
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1265
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1266
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1267
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1268
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1269
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1270
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1271
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1272
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1263
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1264
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1265
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1266
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1267
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1268
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1269
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1270
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1271
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1272
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1273 1273
 
1274 1274
 	// Return cc info
1275 1275
 	return $cc_info;
1276 1276
 }
1277 1277
 
1278
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1278
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1279 1279
     $ret = false;
1280 1280
 
1281
-    if ( empty( $zip ) || empty( $country_code ) )
1281
+    if (empty($zip) || empty($country_code))
1282 1282
         return $ret;
1283 1283
 
1284
-    $country_code = strtoupper( $country_code );
1284
+    $country_code = strtoupper($country_code);
1285 1285
 
1286 1286
     $zip_regex = array(
1287 1287
         "AD" => "AD\d{3}",
@@ -1441,72 +1441,72 @@  discard block
 block discarded – undo
1441 1441
         "ZM" => "\d{5}"
1442 1442
     );
1443 1443
 
1444
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1444
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1445 1445
         $ret = true;
1446 1446
 
1447
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1447
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1448 1448
 }
1449 1449
 
1450 1450
 function wpinv_checkout_validate_agree_to_terms() {
1451 1451
     // Validate agree to terms
1452
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1452
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1453 1453
         // User did not agree
1454
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1454
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1455 1455
     }
1456 1456
 }
1457 1457
 
1458 1458
 function wpinv_checkout_validate_invoice_user() {
1459 1459
     global $wpi_cart, $user_ID;
1460 1460
 
1461
-    if(empty($wpi_cart)){
1461
+    if (empty($wpi_cart)) {
1462 1462
         $wpi_cart = wpinv_get_invoice_cart();
1463 1463
     }
1464 1464
 
1465
-    $invoice_user = (int)$wpi_cart->get_user_id();
1465
+    $invoice_user = (int) $wpi_cart->get_user_id();
1466 1466
     $valid_user_data = array(
1467 1467
         'user_id' => $invoice_user
1468 1468
     );
1469 1469
 
1470 1470
     // If guest checkout allowed
1471
-    if ( !wpinv_require_login_to_checkout() ) {
1471
+    if (!wpinv_require_login_to_checkout()) {
1472 1472
         return $valid_user_data;
1473 1473
     }
1474 1474
     
1475 1475
     // Verify there is a user_ID
1476
-    if ( $user_ID == $invoice_user ) {
1476
+    if ($user_ID == $invoice_user) {
1477 1477
         // Get the logged in user data
1478
-        $user_data = get_userdata( $user_ID );
1479
-        $required_fields  = wpinv_checkout_required_fields();
1478
+        $user_data = get_userdata($user_ID);
1479
+        $required_fields = wpinv_checkout_required_fields();
1480 1480
 
1481 1481
         // Loop through required fields and show error messages
1482
-         if ( !empty( $required_fields ) ) {
1483
-            foreach ( $required_fields as $field_name => $value ) {
1484
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1485
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1482
+         if (!empty($required_fields)) {
1483
+            foreach ($required_fields as $field_name => $value) {
1484
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1485
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1486 1486
                 }
1487 1487
             }
1488 1488
         }
1489 1489
 
1490 1490
         // Verify data
1491
-        if ( $user_data ) {
1491
+        if ($user_data) {
1492 1492
             // Collected logged in user data
1493 1493
             $valid_user_data = array(
1494 1494
                 'user_id'     => $user_ID,
1495
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1496
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1497
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1495
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1496
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1497
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1498 1498
             );
1499 1499
 
1500
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1501
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1500
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1501
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1502 1502
             }
1503 1503
         } else {
1504 1504
             // Set invalid user error
1505
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1505
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1506 1506
         }
1507 1507
     } else {
1508 1508
         // Set invalid user error
1509
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1509
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1510 1510
     }
1511 1511
 
1512 1512
     // Return user data
@@ -1518,27 +1518,27 @@  discard block
 block discarded – undo
1518 1518
 
1519 1519
     $data = array();
1520 1520
     
1521
-    if ( is_user_logged_in() ) {
1522
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1523
-            $data['user_id'] = (int)get_current_user_id();
1521
+    if (is_user_logged_in()) {
1522
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int) $wpi_cart->get_user_id() === (int) get_current_user_id())) {
1523
+            $data['user_id'] = (int) get_current_user_id();
1524 1524
         } else {
1525
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1525
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1526 1526
         }
1527 1527
     } else {
1528 1528
         // If guest checkout allowed
1529
-        if ( !wpinv_require_login_to_checkout() ) {
1529
+        if (!wpinv_require_login_to_checkout()) {
1530 1530
             $data['user_id'] = 0;
1531 1531
         } else {
1532
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1532
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1533 1533
         }
1534 1534
     }
1535 1535
 
1536 1536
     return $data;
1537 1537
 }
1538 1538
 
1539
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1539
+function wpinv_checkout_form_get_user($valid_data = array()) {
1540 1540
 
1541
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1541
+    if (!empty($valid_data['current_user']['user_id'])) {
1542 1542
         $user = $valid_data['current_user'];
1543 1543
     } else {
1544 1544
         // Set the valid invoice user
@@ -1546,7 +1546,7 @@  discard block
 block discarded – undo
1546 1546
     }
1547 1547
 
1548 1548
     // Verify invoice have an user
1549
-    if ( false === $user || empty( $user ) ) {
1549
+    if (false === $user || empty($user)) {
1550 1550
         return false;
1551 1551
     }
1552 1552
 
@@ -1563,11 +1563,11 @@  discard block
 block discarded – undo
1563 1563
         'zip',
1564 1564
     );
1565 1565
     
1566
-    foreach ( $address_fields as $field ) {
1567
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1566
+    foreach ($address_fields as $field) {
1567
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1568 1568
         
1569
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1570
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1569
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1570
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1571 1571
         }
1572 1572
     }
1573 1573
 
@@ -1575,28 +1575,28 @@  discard block
 block discarded – undo
1575 1575
     return $user;
1576 1576
 }
1577 1577
 
1578
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1578
+function wpinv_set_checkout_session($invoice_data = array()) {
1579 1579
     global $wpi_session;
1580 1580
     
1581
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1581
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1582 1582
 }
1583 1583
 
1584 1584
 function wpinv_get_checkout_session() {
1585 1585
 	global $wpi_session;
1586 1586
 
1587
-    return $wpi_session->get( 'wpinv_checkout' );
1587
+    return $wpi_session->get('wpinv_checkout');
1588 1588
 }
1589 1589
 
1590 1590
 function wpinv_empty_cart() {
1591 1591
     global $wpi_session;
1592 1592
 
1593 1593
     // Remove cart contents
1594
-    $wpi_session->set( 'wpinv_checkout', NULL );
1594
+    $wpi_session->set('wpinv_checkout', NULL);
1595 1595
 
1596 1596
     // Remove all cart fees
1597
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1597
+    $wpi_session->set('wpi_cart_fees', NULL);
1598 1598
 
1599
-    do_action( 'wpinv_empty_cart' );
1599
+    do_action('wpinv_empty_cart');
1600 1600
 }
1601 1601
 
1602 1602
 function wpinv_process_checkout() {
@@ -1605,7 +1605,7 @@  discard block
 block discarded – undo
1605 1605
     wpinv_clear_errors();
1606 1606
 
1607 1607
     $invoice = wpinv_get_invoice_cart();
1608
-    if ( empty( $invoice ) ) {
1608
+    if (empty($invoice)) {
1609 1609
         return false;
1610 1610
     }
1611 1611
 
@@ -1613,42 +1613,42 @@  discard block
 block discarded – undo
1613 1613
 
1614 1614
     $wpi_checkout_id = $invoice->ID;
1615 1615
 
1616
-    do_action( 'wpinv_pre_process_checkout' );
1616
+    do_action('wpinv_pre_process_checkout');
1617 1617
     
1618
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1618
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1619 1619
         $valid_data = false;
1620
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1620
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1621 1621
     } else {
1622 1622
         // Validate the form $_POST data
1623 1623
         $valid_data = wpinv_validate_checkout_fields();
1624 1624
         
1625 1625
         // Allow themes and plugins to hook to errors
1626
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1626
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1627 1627
     }
1628 1628
     
1629
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1629
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1630 1630
     
1631 1631
     // Validate the user
1632
-    $user = wpinv_checkout_form_get_user( $valid_data );
1632
+    $user = wpinv_checkout_form_get_user($valid_data);
1633 1633
 
1634 1634
     // Let extensions validate fields after user is logged in if user has used login/registration form
1635
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1635
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1636 1636
     
1637
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1638
-        if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1639
-            do_action( 'wpinv_ajax_checkout_errors' );
1637
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1638
+        if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1639
+            do_action('wpinv_ajax_checkout_errors');
1640 1640
             die();
1641 1641
         } else {
1642 1642
             return false;
1643 1643
         }
1644 1644
     }
1645 1645
 
1646
-    if ( $is_ajax && 'wpinv_payment_form' != $_REQUEST['action'] ) {
1646
+    if ($is_ajax && 'wpinv_payment_form' != $_REQUEST['action']) {
1647 1647
         // Save address fields.
1648
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1649
-        foreach ( $address_fields as $field ) {
1650
-            if ( isset( $user[$field] ) ) {
1651
-                $invoice->set( $field, $user[$field] );
1648
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1649
+        foreach ($address_fields as $field) {
1650
+            if (isset($user[$field])) {
1651
+                $invoice->set($field, $user[$field]);
1652 1652
             }
1653 1653
 
1654 1654
             $invoice->save();
@@ -1656,16 +1656,16 @@  discard block
 block discarded – undo
1656 1656
 
1657 1657
         $response['success']            = true;
1658 1658
         $response['data']['subtotal']   = $invoice->get_subtotal();
1659
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1659
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1660 1660
         $response['data']['discount']   = $invoice->get_discount();
1661
-        $response['data']['discountf']  = $invoice->get_discount( true );
1661
+        $response['data']['discountf']  = $invoice->get_discount(true);
1662 1662
         $response['data']['tax']        = $invoice->get_tax();
1663
-        $response['data']['taxf']       = $invoice->get_tax( true );
1663
+        $response['data']['taxf']       = $invoice->get_tax(true);
1664 1664
         $response['data']['total']      = $invoice->get_total();
1665
-        $response['data']['totalf']     = $invoice->get_total( true );
1666
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1665
+        $response['data']['totalf']     = $invoice->get_total(true);
1666
+	    $response['data']['free'] = $invoice->is_free() && (!((float) $response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1667 1667
 
1668
-        wp_send_json( $response );
1668
+        wp_send_json($response);
1669 1669
     }
1670 1670
     
1671 1671
     $user_info = array(
@@ -1687,42 +1687,42 @@  discard block
 block discarded – undo
1687 1687
     
1688 1688
     // Setup invoice information
1689 1689
     $invoice_data = array(
1690
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1690
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1691 1691
         'items'             => $cart_items,
1692 1692
         'cart_discounts'    => $discounts,
1693
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1694
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1695
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1696
-        'tax'               => wpinv_get_cart_tax( $cart_items, $invoice ),               // Taxed amount
1697
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1693
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1694
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1695
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1696
+        'tax'               => wpinv_get_cart_tax($cart_items, $invoice), // Taxed amount
1697
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1698 1698
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1699 1699
         'user_email'        => $invoice->get_email(),
1700
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1701
-        'user_info'         => stripslashes_deep( $user_info ),
1700
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1701
+        'user_info'         => stripslashes_deep($user_info),
1702 1702
         'post_data'         => $_POST,
1703 1703
         'cart_details'      => $cart_items,
1704 1704
         'gateway'           => $valid_data['gateway'],
1705 1705
         'card_info'         => $valid_data['cc_info']
1706 1706
     );
1707 1707
     
1708
-    $vat_info   = $wpinv_euvat->current_vat_data();
1709
-    if ( is_array( $vat_info ) ) {
1708
+    $vat_info = $wpinv_euvat->current_vat_data();
1709
+    if (is_array($vat_info)) {
1710 1710
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1711 1711
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1712
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1712
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1713 1713
 
1714 1714
         // Add the VAT rate to each item in the cart
1715
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1715
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1716 1716
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1717
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1717
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1718 1718
         }
1719 1719
     }
1720 1720
     
1721 1721
     // Save vat fields.
1722
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1723
-    foreach ( $address_fields as $field ) {
1724
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1725
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1722
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1723
+    foreach ($address_fields as $field) {
1724
+        if (isset($invoice_data['user_info'][$field])) {
1725
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1726 1726
         }
1727 1727
 
1728 1728
         $invoice->save();
@@ -1732,55 +1732,55 @@  discard block
 block discarded – undo
1732 1732
     $valid_data['user'] = $user;
1733 1733
     
1734 1734
     // Allow themes and plugins to hook before the gateway
1735
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1735
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1736 1736
     
1737 1737
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1738
-    if ( !$invoice_data['price'] ) {
1738
+    if (!$invoice_data['price']) {
1739 1739
         // Revert to manual
1740 1740
         $invoice_data['gateway'] = 'manual';
1741 1741
         $_POST['wpi-gateway'] = 'manual';
1742 1742
     }
1743 1743
     
1744 1744
     // Allow the invoice data to be modified before it is sent to the gateway
1745
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1745
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1746 1746
     
1747
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1747
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1748 1748
         $mode = 'test';
1749 1749
     } else {
1750
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1750
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1751 1751
     }
1752 1752
     
1753 1753
     // Setup the data we're storing in the purchase session
1754 1754
     $session_data = $invoice_data;
1755 1755
     // Make sure credit card numbers are never stored in sessions
1756
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1757
-        unset( $session_data['card_info']['card_number'] );
1756
+    if (!empty($session_data['card_info']['card_number'])) {
1757
+        unset($session_data['card_info']['card_number']);
1758 1758
     }
1759 1759
     
1760 1760
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1761
-    wpinv_set_checkout_session( $invoice_data );
1761
+    wpinv_set_checkout_session($invoice_data);
1762 1762
     
1763 1763
     // Set gateway
1764
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1765
-    $invoice->update_meta( '_wpinv_mode', $mode );
1766
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1764
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1765
+    $invoice->update_meta('_wpinv_mode', $mode);
1766
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1767 1767
     
1768
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1768
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1769 1769
 
1770 1770
     // Send info to the gateway for payment processing
1771
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1771
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1772 1772
     die();
1773 1773
 }
1774
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1774
+add_action('wpinv_payment', 'wpinv_process_checkout');
1775 1775
 
1776
-function wpinv_get_invoices( $args ) {
1777
-    $args = wp_parse_args( $args, array(
1778
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1776
+function wpinv_get_invoices($args) {
1777
+    $args = wp_parse_args($args, array(
1778
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1779 1779
         'type'     => 'wpi_invoice',
1780 1780
         'parent'   => null,
1781 1781
         'user'     => null,
1782 1782
         'email'    => '',
1783
-        'limit'    => get_option( 'posts_per_page' ),
1783
+        'limit'    => get_option('posts_per_page'),
1784 1784
         'offset'   => null,
1785 1785
         'page'     => 1,
1786 1786
         'exclude'  => array(),
@@ -1788,7 +1788,7 @@  discard block
 block discarded – undo
1788 1788
         'order'    => 'DESC',
1789 1789
         'return'   => 'objects',
1790 1790
         'paginate' => false,
1791
-    ) );
1791
+    ));
1792 1792
     
1793 1793
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1794 1794
     $map_legacy = array(
@@ -1801,18 +1801,18 @@  discard block
 block discarded – undo
1801 1801
         'paged'          => 'page',
1802 1802
     );
1803 1803
 
1804
-    foreach ( $map_legacy as $from => $to ) {
1805
-        if ( isset( $args[ $from ] ) ) {
1806
-            $args[ $to ] = $args[ $from ];
1804
+    foreach ($map_legacy as $from => $to) {
1805
+        if (isset($args[$from])) {
1806
+            $args[$to] = $args[$from];
1807 1807
         }
1808 1808
     }
1809 1809
 
1810
-    if ( get_query_var( 'paged' ) )
1810
+    if (get_query_var('paged'))
1811 1811
         $args['page'] = get_query_var('paged');
1812
-    else if ( get_query_var( 'page' ) )
1813
-        $args['page'] = get_query_var( 'page' );
1814
-    else if ( !empty( $args[ 'page' ] ) )
1815
-        $args['page'] = $args[ 'page' ];
1812
+    else if (get_query_var('page'))
1813
+        $args['page'] = get_query_var('page');
1814
+    else if (!empty($args['page']))
1815
+        $args['page'] = $args['page'];
1816 1816
     else
1817 1817
         $args['page'] = 1;
1818 1818
 
@@ -1825,48 +1825,48 @@  discard block
 block discarded – undo
1825 1825
         'post_status'    => $args['status'],
1826 1826
         'posts_per_page' => $args['limit'],
1827 1827
         'meta_query'     => array(),
1828
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1828
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1829 1829
         'fields'         => 'ids',
1830 1830
         'orderby'        => $args['orderby'],
1831 1831
         'order'          => $args['order'],
1832 1832
     );
1833 1833
     
1834
-    if ( !empty( $args['user'] ) ) {
1835
-        $wp_query_args['author'] = absint( $args['user'] );
1834
+    if (!empty($args['user'])) {
1835
+        $wp_query_args['author'] = absint($args['user']);
1836 1836
     }
1837 1837
 
1838
-    if ( ! is_null( $args['parent'] ) ) {
1839
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1838
+    if (!is_null($args['parent'])) {
1839
+        $wp_query_args['post_parent'] = absint($args['parent']);
1840 1840
     }
1841 1841
 
1842
-    if ( ! is_null( $args['offset'] ) ) {
1843
-        $wp_query_args['offset'] = absint( $args['offset'] );
1842
+    if (!is_null($args['offset'])) {
1843
+        $wp_query_args['offset'] = absint($args['offset']);
1844 1844
     } else {
1845
-        $wp_query_args['paged'] = absint( $args['page'] );
1845
+        $wp_query_args['paged'] = absint($args['page']);
1846 1846
     }
1847 1847
 
1848
-    if ( ! empty( $args['exclude'] ) ) {
1849
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1848
+    if (!empty($args['exclude'])) {
1849
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1850 1850
     }
1851 1851
 
1852
-    if ( ! $args['paginate' ] ) {
1852
+    if (!$args['paginate']) {
1853 1853
         $wp_query_args['no_found_rows'] = true;
1854 1854
     }
1855 1855
 
1856 1856
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1857 1857
 
1858 1858
     // Get results.
1859
-    $invoices = new WP_Query( $wp_query_args );
1859
+    $invoices = new WP_Query($wp_query_args);
1860 1860
 
1861
-    if ( 'objects' === $args['return'] ) {
1862
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1863
-    } elseif ( 'self' === $args['return'] ) {
1861
+    if ('objects' === $args['return']) {
1862
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1863
+    } elseif ('self' === $args['return']) {
1864 1864
         return $invoices;
1865 1865
     } else {
1866 1866
         $return = $invoices->posts;
1867 1867
     }
1868 1868
 
1869
-    if ( $args['paginate' ] ) {
1869
+    if ($args['paginate']) {
1870 1870
         return (object) array(
1871 1871
             'invoices'      => $return,
1872 1872
             'total'         => $invoices->found_posts,
@@ -1879,22 +1879,22 @@  discard block
 block discarded – undo
1879 1879
 
1880 1880
 function wpinv_get_user_invoices_columns() {
1881 1881
     $columns = array(
1882
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1883
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1884
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1885
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1886
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1887
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1882
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1883
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1884
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1885
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1886
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1887
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1888 1888
         );
1889 1889
 
1890
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1890
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1891 1891
 }
1892 1892
 
1893
-function wpinv_payment_receipt( $atts, $content = null ) {
1893
+function wpinv_payment_receipt($atts, $content = null) {
1894 1894
     global $wpinv_receipt_args;
1895 1895
 
1896
-    $wpinv_receipt_args = shortcode_atts( array(
1897
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1896
+    $wpinv_receipt_args = shortcode_atts(array(
1897
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1898 1898
         'price'           => true,
1899 1899
         'discount'        => true,
1900 1900
         'items'           => true,
@@ -1903,44 +1903,44 @@  discard block
 block discarded – undo
1903 1903
         'invoice_key'     => false,
1904 1904
         'payment_method'  => true,
1905 1905
         'invoice_id'      => true
1906
-    ), $atts, 'wpinv_receipt' );
1906
+    ), $atts, 'wpinv_receipt');
1907 1907
 
1908 1908
     $session = wpinv_get_checkout_session();
1909
-    if ( isset( $_GET['invoice_key'] ) ) {
1910
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1911
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1909
+    if (isset($_GET['invoice_key'])) {
1910
+        $invoice_key = urldecode($_GET['invoice_key']);
1911
+    } else if ($session && isset($session['invoice_key'])) {
1912 1912
         $invoice_key = $session['invoice_key'];
1913
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1913
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1914 1914
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1915
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1916
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1915
+    } else if (isset($_GET['invoice-id'])) {
1916
+        $invoice_key = wpinv_get_payment_key((int) $_GET['invoice-id']);
1917 1917
     }
1918 1918
 
1919 1919
     // No key found
1920
-    if ( ! isset( $invoice_key ) ) {
1920
+    if (!isset($invoice_key)) {
1921 1921
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1922 1922
     }
1923 1923
 
1924
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1925
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1926
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1927
-        $invoice_id     = (int)$_GET['invoice-id'];
1928
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1924
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1925
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1926
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1927
+        $invoice_id     = (int) $_GET['invoice-id'];
1928
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
1929 1929
     }
1930 1930
 
1931 1931
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1932
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1932
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1933 1933
         // login redirect
1934
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1934
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1935 1935
     }
1936 1936
 
1937
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1937
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1938 1938
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1939 1939
     }
1940 1940
 
1941 1941
     ob_start();
1942 1942
 
1943
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1943
+    wpinv_get_template_part('wpinv-invoice-receipt');
1944 1944
 
1945 1945
     $display = ob_get_clean();
1946 1946
 
@@ -1950,148 +1950,148 @@  discard block
 block discarded – undo
1950 1950
 /**
1951 1951
  * Given an invoice key, this function returns the id.
1952 1952
  */
1953
-function wpinv_get_invoice_id_by_key( $key ) {
1953
+function wpinv_get_invoice_id_by_key($key) {
1954 1954
 	global $wpdb;
1955
-    $table      = $wpdb->prefix . 'getpaid_invoices';
1956
-	return (int) $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key ) );
1955
+    $table = $wpdb->prefix . 'getpaid_invoices';
1956
+	return (int) $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $table WHERE`key` = %s LIMIT 1", $key));
1957 1957
 }
1958 1958
 
1959
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1959
+function wpinv_can_view_receipt($invoice_key = '') {
1960 1960
 	$return = false;
1961 1961
 
1962
-	if ( empty( $invoice_key ) ) {
1962
+	if (empty($invoice_key)) {
1963 1963
 		return $return;
1964 1964
 	}
1965 1965
 
1966 1966
 	global $wpinv_receipt_args;
1967 1967
 
1968
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1969
-	if ( isset( $_GET['invoice-id'] ) ) {
1970
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1968
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1969
+	if (isset($_GET['invoice-id'])) {
1970
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? (int) $_GET['invoice-id'] : 0;
1971 1971
 	}
1972 1972
 
1973
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1973
+	if (empty($wpinv_receipt_args['id'])) {
1974 1974
 		return $return;
1975 1975
 	}
1976 1976
 
1977
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1978
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1977
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1978
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1979 1979
 		return $return;
1980 1980
 	}
1981 1981
 
1982
-	if ( is_user_logged_in() ) {
1983
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1982
+	if (is_user_logged_in()) {
1983
+		if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
1984 1984
 			$return = true;
1985 1985
 		}
1986 1986
 	}
1987 1987
 
1988 1988
 	$session = wpinv_get_checkout_session();
1989
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1990
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1989
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1990
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1991 1991
 
1992
-		if ( wpinv_require_login_to_checkout() ) {
1992
+		if (wpinv_require_login_to_checkout()) {
1993 1993
 			$return = $return && $check_key === $invoice_key;
1994 1994
 		} else {
1995 1995
 			$return = $check_key === $invoice_key;
1996 1996
 		}
1997 1997
 	}
1998 1998
 
1999
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1999
+	return (bool) apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
2000 2000
 }
2001 2001
 
2002 2002
 function wpinv_pay_for_invoice() {
2003 2003
     global $wpinv_euvat;
2004 2004
     
2005
-    if ( isset( $_GET['invoice_key'] ) ) {
2005
+    if (isset($_GET['invoice_key'])) {
2006 2006
         $checkout_uri   = wpinv_get_checkout_uri();
2007
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
2007
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
2008 2008
         
2009
-        if ( empty( $invoice_key ) ) {
2010
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
2011
-            wp_redirect( $checkout_uri );
2009
+        if (empty($invoice_key)) {
2010
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
2011
+            wp_redirect($checkout_uri);
2012 2012
             exit();
2013 2013
         }
2014 2014
         
2015
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
2015
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
2016 2016
 
2017
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
2018
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
2019
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
2020
-            $invoice_id     = (int)$_GET['invoice-id'];
2021
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
2017
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
2018
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
2019
+        if ($user_can_view && isset($_GET['invoice-id'])) {
2020
+            $invoice_id     = (int) $_GET['invoice-id'];
2021
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int) $_GET['invoice-id']) ? true : false;
2022 2022
         }
2023 2023
         
2024
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
2025
-            if ( $invoice->needs_payment() ) {
2024
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
2025
+            if ($invoice->needs_payment()) {
2026 2026
                 $data                   = array();
2027 2027
                 $data['invoice_id']     = $invoice_id;
2028
-                $data['cart_discounts'] = $invoice->get_discounts( true );
2028
+                $data['cart_discounts'] = $invoice->get_discounts(true);
2029 2029
                 
2030
-                wpinv_set_checkout_session( $data );
2030
+                wpinv_set_checkout_session($data);
2031 2031
                 
2032
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
2032
+                if (wpinv_get_option('vat_ip_country_default')) {
2033 2033
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
2034 2034
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
2035 2035
                     
2036
-                    wpinv_recalculate_tax( true );
2036
+                    wpinv_recalculate_tax(true);
2037 2037
                 }
2038 2038
                 
2039 2039
             } else {
2040 2040
                 $checkout_uri = $invoice->get_view_url();
2041 2041
             }
2042 2042
         } else {
2043
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2043
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2044 2044
             
2045
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2045
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2046 2046
         }
2047 2047
         
2048
-        if(wp_redirect( $checkout_uri )){
2048
+        if (wp_redirect($checkout_uri)) {
2049 2049
             exit;
2050 2050
         };
2051 2051
         wpinv_die();
2052 2052
     }
2053 2053
 }
2054
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2054
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2055 2055
 
2056
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2057
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2058
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2056
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2057
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2058
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2059 2059
             $user_id = $invoice->get_user_id();
2060
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2060
+            $secret = sanitize_text_field($_GET['_wpipay']);
2061 2061
             
2062
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2063
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2062
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2063
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2064 2064
                 
2065
-                wpinv_guest_redirect( $redirect_to, $user_id );
2065
+                wpinv_guest_redirect($redirect_to, $user_id);
2066 2066
                 exit();
2067 2067
             }
2068 2068
         }
2069 2069
     }
2070 2070
 }
2071
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2071
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2072 2072
 
2073
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2074
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2073
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2074
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2075 2075
     
2076
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2076
+    if (empty($invoice_id) && $invoice_id > 0) {
2077 2077
         return false;
2078 2078
     }
2079 2079
     
2080
-    if ( empty( $transaction_id ) ) {
2080
+    if (empty($transaction_id)) {
2081 2081
         $transaction_id = $invoice_id;
2082 2082
     }
2083 2083
 
2084
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2084
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2085 2085
     
2086
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2086
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2087 2087
 }
2088 2088
 
2089
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2090
-    if ( empty( $status_display ) ) {
2091
-        $status_display = wpinv_status_nicename( $status );
2089
+function wpinv_invoice_status_label($status, $status_display = '') {
2090
+    if (empty($status_display)) {
2091
+        $status_display = wpinv_status_nicename($status);
2092 2092
     }
2093 2093
     
2094
-    switch ( $status ) {
2094
+    switch ($status) {
2095 2095
         case 'publish' :
2096 2096
         case 'wpi-renewal' :
2097 2097
             $class = 'label-success';
@@ -2116,201 +2116,201 @@  discard block
 block discarded – undo
2116 2116
     
2117 2117
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2118 2118
     
2119
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2119
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2120 2120
 }
2121 2121
 
2122
-function wpinv_format_invoice_number( $number, $type = '' ) {
2123
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2124
-    if ( null !== $check ) {
2122
+function wpinv_format_invoice_number($number, $type = '') {
2123
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2124
+    if (null !== $check) {
2125 2125
         return $check;
2126 2126
     }
2127 2127
 
2128
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2128
+    if (!empty($number) && !is_numeric($number)) {
2129 2129
         return $number;
2130 2130
     }
2131 2131
 
2132
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2133
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2134
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2132
+    $padd = wpinv_get_option('invoice_number_padd');
2133
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2134
+    $postfix = wpinv_get_option('invoice_number_postfix');
2135 2135
     
2136
-    $padd = absint( $padd );
2137
-    $formatted_number = absint( $number );
2136
+    $padd = absint($padd);
2137
+    $formatted_number = absint($number);
2138 2138
     
2139
-    if ( $padd > 0 ) {
2140
-        $formatted_number = zeroise( $formatted_number, $padd );
2139
+    if ($padd > 0) {
2140
+        $formatted_number = zeroise($formatted_number, $padd);
2141 2141
     }    
2142 2142
 
2143 2143
     $formatted_number = $prefix . $formatted_number . $postfix;
2144 2144
 
2145
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2145
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2146 2146
 }
2147 2147
 
2148
-function wpinv_get_next_invoice_number( $type = '' ) {
2149
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2150
-    if ( null !== $check ) {
2148
+function wpinv_get_next_invoice_number($type = '') {
2149
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2150
+    if (null !== $check) {
2151 2151
         return $check;
2152 2152
     }
2153 2153
     
2154
-    if ( !wpinv_sequential_number_active() ) {
2154
+    if (!wpinv_sequential_number_active()) {
2155 2155
         return false;
2156 2156
     }
2157 2157
 
2158
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2159
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2160
-    if ( !absint( $start ) > 0 ) {
2158
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2159
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2160
+    if (!absint($start) > 0) {
2161 2161
         $start = 1;
2162 2162
     }
2163 2163
     $increment_number = true;
2164 2164
     $save_number = false;
2165 2165
 
2166
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2167
-        $number = wpinv_clean_invoice_number( $number );
2166
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2167
+        $number = wpinv_clean_invoice_number($number);
2168 2168
     }
2169 2169
 
2170
-    if ( empty( $number ) ) {
2171
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2172
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2170
+    if (empty($number)) {
2171
+        if (!($last_number === 0 || $last_number === '0')) {
2172
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2173 2173
 
2174
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2175
-                if ( is_numeric( $invoice_number ) ) {
2174
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2175
+                if (is_numeric($invoice_number)) {
2176 2176
                     $number = $invoice_number;
2177 2177
                 } else {
2178
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2178
+                    $number = wpinv_clean_invoice_number($invoice_number);
2179 2179
                 }
2180 2180
             }
2181 2181
 
2182
-            if ( empty( $number ) ) {
2182
+            if (empty($number)) {
2183 2183
                 $increment_number = false;
2184 2184
                 $number = $start;
2185
-                $save_number = ( $number - 1 );
2185
+                $save_number = ($number - 1);
2186 2186
             } else {
2187 2187
                 $save_number = $number;
2188 2188
             }
2189 2189
         }
2190 2190
     }
2191 2191
 
2192
-    if ( $start > $number ) {
2192
+    if ($start > $number) {
2193 2193
         $increment_number = false;
2194 2194
         $number = $start;
2195
-        $save_number = ( $number - 1 );
2195
+        $save_number = ($number - 1);
2196 2196
     }
2197 2197
 
2198
-    if ( $save_number !== false ) {
2199
-        update_option( 'wpinv_last_invoice_number', $save_number );
2198
+    if ($save_number !== false) {
2199
+        update_option('wpinv_last_invoice_number', $save_number);
2200 2200
     }
2201 2201
     
2202
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2202
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2203 2203
 
2204
-    if ( $increment_number ) {
2204
+    if ($increment_number) {
2205 2205
         $number++;
2206 2206
     }
2207 2207
 
2208
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2208
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2209 2209
 }
2210 2210
 
2211
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2212
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2213
-    if ( null !== $check ) {
2211
+function wpinv_clean_invoice_number($number, $type = '') {
2212
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2213
+    if (null !== $check) {
2214 2214
         return $check;
2215 2215
     }
2216 2216
     
2217
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2218
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2217
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2218
+    $postfix = wpinv_get_option('invoice_number_postfix');
2219 2219
 
2220
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2220
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2221 2221
 
2222
-    $length      = strlen( $number );
2223
-    $postfix_pos = strrpos( $number, $postfix );
2222
+    $length      = strlen($number);
2223
+    $postfix_pos = strrpos($number, $postfix);
2224 2224
     
2225
-    if ( false !== $postfix_pos ) {
2226
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2225
+    if (false !== $postfix_pos) {
2226
+        $number = substr_replace($number, '', $postfix_pos, $length);
2227 2227
     }
2228 2228
 
2229
-    $number = intval( $number );
2229
+    $number = intval($number);
2230 2230
 
2231
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2231
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2232 2232
 }
2233 2233
 
2234
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2234
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2235 2235
     global $wpdb;
2236 2236
 
2237
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2238
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2237
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2238
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2239 2239
     }
2240 2240
 
2241
-    if ( !$update ) {
2242
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2243
-        clean_post_cache( $post_ID );
2241
+    if (!$update) {
2242
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2243
+        clean_post_cache($post_ID);
2244 2244
     }
2245 2245
 }
2246
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2246
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2247 2247
 
2248
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2249
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2250
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2248
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2249
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2250
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2251 2251
     }
2252 2252
 }
2253
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2253
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2254 2254
 
2255
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2255
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2256 2256
     global $wpdb;
2257 2257
     
2258
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2259
-    if ( null !== $check ) {
2258
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2259
+    if (null !== $check) {
2260 2260
         return $check;
2261 2261
     }
2262 2262
 
2263
-    if ( wpinv_sequential_number_active() ) {
2263
+    if (wpinv_sequential_number_active()) {
2264 2264
         $number = wpinv_get_next_invoice_number();
2265 2265
 
2266
-        if ( $save_sequential ) {
2267
-            update_option( 'wpinv_last_invoice_number', $number );
2266
+        if ($save_sequential) {
2267
+            update_option('wpinv_last_invoice_number', $number);
2268 2268
         }
2269 2269
     } else {
2270 2270
         $number = $post_ID;
2271 2271
     }
2272 2272
 
2273
-    $number = wpinv_format_invoice_number( $number );
2273
+    $number = wpinv_format_invoice_number($number);
2274 2274
 
2275
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2275
+    update_post_meta($post_ID, '_wpinv_number', $number);
2276 2276
 
2277
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2277
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2278 2278
 
2279
-    clean_post_cache( $post_ID );
2279
+    clean_post_cache($post_ID);
2280 2280
 
2281 2281
     return $number;
2282 2282
 }
2283 2283
 
2284
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2285
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2284
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2285
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2286 2286
 }
2287 2287
 
2288
-function wpinv_generate_post_name( $post_ID ) {
2289
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2290
-    $post_name = sanitize_title( $prefix . $post_ID );
2288
+function wpinv_generate_post_name($post_ID) {
2289
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2290
+    $post_name = sanitize_title($prefix . $post_ID);
2291 2291
 
2292
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2292
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2293 2293
 }
2294 2294
 
2295
-function wpinv_is_invoice_viewed( $invoice_id ) {
2296
-    if ( empty( $invoice_id ) ) {
2295
+function wpinv_is_invoice_viewed($invoice_id) {
2296
+    if (empty($invoice_id)) {
2297 2297
         return false;
2298 2298
     }
2299 2299
 
2300
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2300
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2301 2301
 
2302
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2302
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int) $viewed_meta, $invoice_id);
2303 2303
 }
2304 2304
 
2305 2305
 function wpinv_mark_invoice_viewed() {
2306 2306
 
2307
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2308
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2307
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2308
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2309 2309
 	    global $post;
2310 2310
 
2311
-        if(!empty($invoice_key)){
2311
+        if (!empty($invoice_key)) {
2312 2312
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2313
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2313
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2314 2314
 			$invoice_id = $post->ID;
2315 2315
         } else {
2316 2316
         	return;
@@ -2318,60 +2318,60 @@  discard block
 block discarded – undo
2318 2318
 
2319 2319
         $invoice = new WPInv_Invoice($invoice_id);
2320 2320
 
2321
-        if(!$invoice_id){
2321
+        if (!$invoice_id) {
2322 2322
             return;
2323 2323
         }
2324 2324
 
2325
-	    if ( is_user_logged_in() ) {
2326
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2327
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2328
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2329
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2325
+	    if (is_user_logged_in()) {
2326
+		    if ((int) $invoice->get_user_id() === get_current_user_id()) {
2327
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2328
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2329
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2330 2330
 		    }
2331 2331
 	    } else {
2332
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2333
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2332
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2333
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2334 2334
 		    }
2335 2335
 	    }
2336 2336
     }
2337 2337
 
2338 2338
 }
2339
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2339
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2340 2340
 
2341
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2342
-    if ( empty( $invoice ) ) {
2341
+function wpinv_get_subscription($invoice, $by_parent = false) {
2342
+    if (empty($invoice)) {
2343 2343
         return false;
2344 2344
     }
2345 2345
     
2346
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2347
-        $invoice = wpinv_get_invoice( $invoice );
2346
+    if (!is_object($invoice) && is_scalar($invoice)) {
2347
+        $invoice = wpinv_get_invoice($invoice);
2348 2348
     }
2349 2349
     
2350
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2350
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2351 2351
         return false;
2352 2352
     }
2353 2353
     
2354
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2354
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2355 2355
     
2356 2356
     $subs_db    = new WPInv_Subscriptions_DB;
2357
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2357
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2358 2358
     
2359
-    if ( ! empty( $subs ) ) {
2360
-        return reset( $subs );
2359
+    if (!empty($subs)) {
2360
+        return reset($subs);
2361 2361
     }
2362 2362
     
2363 2363
     return false;
2364 2364
 }
2365 2365
 
2366
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2366
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2367 2367
     global $wpdb;
2368 2368
 
2369
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2370
-        if ( !empty( $clauses['join'] ) ) {
2369
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2370
+        if (!empty($clauses['join'])) {
2371 2371
             $clauses['join'] .= " ";
2372 2372
         }
2373 2373
 
2374
-        if ( !empty( $clauses['fields'] ) ) {
2374
+        if (!empty($clauses['fields'])) {
2375 2375
             $clauses['fields'] .= ", ";
2376 2376
         }
2377 2377
 
@@ -2382,4 +2382,4 @@  discard block
 block discarded – undo
2382 2382
 
2383 2383
     return $clauses;
2384 2384
 }
2385
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2386 2385
\ No newline at end of file
2386
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2387 2387
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +18 added lines, -14 removed lines patch added patch discarded remove patch
@@ -568,8 +568,9 @@  discard block
 block discarded – undo
568 568
 
569 569
     $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
570 570
 
571
-    if ( $invoice_id != NULL )
572
-        return $invoice_id;
571
+    if ( $invoice_id != NULL ) {
572
+            return $invoice_id;
573
+    }
573 574
 
574 575
     return 0;
575 576
 }
@@ -1278,8 +1279,9 @@  discard block
 block discarded – undo
1278 1279
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1279 1280
     $ret = false;
1280 1281
 
1281
-    if ( empty( $zip ) || empty( $country_code ) )
1282
-        return $ret;
1282
+    if ( empty( $zip ) || empty( $country_code ) ) {
1283
+            return $ret;
1284
+    }
1283 1285
 
1284 1286
     $country_code = strtoupper( $country_code );
1285 1287
 
@@ -1441,8 +1443,9 @@  discard block
 block discarded – undo
1441 1443
         "ZM" => "\d{5}"
1442 1444
     );
1443 1445
 
1444
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1445
-        $ret = true;
1446
+    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) {
1447
+            $ret = true;
1448
+    }
1446 1449
 
1447 1450
     return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1448 1451
 }
@@ -1807,14 +1810,15 @@  discard block
 block discarded – undo
1807 1810
         }
1808 1811
     }
1809 1812
 
1810
-    if ( get_query_var( 'paged' ) )
1811
-        $args['page'] = get_query_var('paged');
1812
-    else if ( get_query_var( 'page' ) )
1813
-        $args['page'] = get_query_var( 'page' );
1814
-    else if ( !empty( $args[ 'page' ] ) )
1815
-        $args['page'] = $args[ 'page' ];
1816
-    else
1817
-        $args['page'] = 1;
1813
+    if ( get_query_var( 'paged' ) ) {
1814
+            $args['page'] = get_query_var('paged');
1815
+    } else if ( get_query_var( 'page' ) ) {
1816
+            $args['page'] = get_query_var( 'page' );
1817
+    } else if ( !empty( $args[ 'page' ] ) ) {
1818
+            $args['page'] = $args[ 'page' ];
1819
+    } else {
1820
+            $args['page'] = 1;
1821
+    }
1818 1822
 
1819 1823
     /**
1820 1824
      * Generate WP_Query args. This logic will change if orders are moved to
Please login to merge, or discard this patch.
includes/class-wpinv-payment-form-elements.php 1 patch
Spacing   +638 added lines, -638 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,
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
                         array(
293 293
                             'placeholder'  => '',
294 294
                             'value'        => '',
295
-                            'label'        => __( 'Company', 'invoicing' ),
295
+                            'label'        => __('Company', 'invoicing'),
296 296
                             'description'  => '',
297 297
                             'required'     => false,
298 298
                             'visible'      => false,
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
                         array(
303 303
                             'placeholder'  => '',
304 304
                             'value'        => '',
305
-                            'label'        => __( 'VAT Number', 'invoicing' ),
305
+                            'label'        => __('VAT Number', 'invoicing'),
306 306
                             'description'  => '',
307 307
                             'required'     => false,
308 308
                             'visible'      => false,
@@ -314,11 +314,11 @@  discard block
 block discarded – undo
314 314
 
315 315
             array( 
316 316
                 'type' => 'billing_email',
317
-                'name' => __( 'Billing Email', 'invoicing' ),
317
+                'name' => __('Billing Email', 'invoicing'),
318 318
                 'defaults'  => array(
319 319
                     'placeholder'  => '[email protected]',
320 320
                     'value'        => '',
321
-                    'label'        => __( 'Billing Email', 'invoicing' ),
321
+                    'label'        => __('Billing Email', 'invoicing'),
322 322
                     'description'  => '',
323 323
                     'premade'      => true,
324 324
                 )
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 
338 338
             array( 
339 339
                 'type' => 'items',
340
-                'name' => __( 'Items', 'invoicing' ),
340
+                'name' => __('Items', 'invoicing'),
341 341
                 'defaults'  => array(
342 342
                     'value'        => '',
343 343
                     'items_type'   => 'total',
@@ -348,10 +348,10 @@  discard block
 block discarded – undo
348 348
 
349 349
             array(
350 350
                 'type' => 'terms',
351
-                'name' => __( 'Terms', 'invoicing' ),
351
+                'name' => __('Terms', 'invoicing'),
352 352
                 'defaults'         => array(
353 353
                     'value'        => '',
354
-                    'text'         => __( 'I\'ve read and accept the <a href="" target="_blank">terms &amp; conditions</a>', 'invoicing' ),
354
+                    'text'         => __('I\'ve read and accept the <a href="" target="_blank">terms &amp; conditions</a>', 'invoicing'),
355 355
                     'description'  => '',
356 356
                     'required'     => true,
357 357
                 )
@@ -359,34 +359,34 @@  discard block
 block discarded – undo
359 359
 
360 360
             array(
361 361
                 'type' => 'privacy',
362
-                'name' => __( 'Privacy', 'invoicing' ),
362
+                'name' => __('Privacy', 'invoicing'),
363 363
                 'defaults'         => array(
364 364
                     'value'        => '',
365
-                    'text'         => __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing' ),
365
+                    'text'         => __('Your personal data will be used to process your invoice, payment and for other purposes described in our privacy policy.', 'invoicing'),
366 366
                 )
367 367
             ),
368 368
 
369 369
             array( 
370 370
                 'type'       => 'pay_button',
371
-                'name'       => __( 'Payment Button', 'invoicing' ),
371
+                'name'       => __('Payment Button', 'invoicing'),
372 372
                 'defaults'   => array(
373 373
                     'value'        => '',
374 374
                     'class'        => 'btn-primary',
375
-                    'label'        => __( 'Pay Now »', 'invoicing' ),
376
-                    'description'  => __( 'By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing' ),
375
+                    'label'        => __('Pay Now »', 'invoicing'),
376
+                    'description'  => __('By continuing with our payment, you are agreeing to our privacy policy and terms of service.', 'invoicing'),
377 377
                     'premade'      => true,
378 378
                 )
379 379
             )
380 380
         );
381 381
 
382
-        $this->elements = apply_filters( 'wpinv_filter_core_payment_form_elements', $this->elements );
382
+        $this->elements = apply_filters('wpinv_filter_core_payment_form_elements', $this->elements);
383 383
         return $this->elements;
384 384
     }
385 385
 
386 386
     /**
387 387
      * Returns the restrict markup.
388 388
      */
389
-    public function get_restrict_markup( $field, $field_type ) {
389
+    public function get_restrict_markup($field, $field_type) {
390 390
         $restrict = "$field.type=='$field_type'";
391 391
         return "v-if=\"$restrict\"";
392 392
     }
@@ -394,15 +394,15 @@  discard block
 block discarded – undo
394 394
     /**
395 395
      * Renders the title element template.
396 396
      */
397
-    public function render_heading_template( $field ) {
398
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
397
+    public function render_heading_template($field) {
398
+        $restrict = $this->get_restrict_markup($field, 'heading');
399 399
         echo "<component :is='$field.level' $restrict v-html='$field.text'></component>";
400 400
     }
401 401
 
402 402
     /**
403 403
      * Renders the title element on the frontend.
404 404
      */
405
-    public function frontend_render_heading_template( $field ) {
405
+    public function frontend_render_heading_template($field) {
406 406
         $tag = $field['level'];
407 407
         echo "<$tag>{$field['text']}</$tag>";
408 408
     }
@@ -410,10 +410,10 @@  discard block
 block discarded – undo
410 410
     /**
411 411
      * Renders the edit title element template.
412 412
      */
413
-    public function edit_heading_template( $field ) {
414
-        $restrict = $this->get_restrict_markup( $field, 'heading' );
415
-        $label    = __( 'Heading', 'invoicing' );
416
-        $label2   = __( 'Select Heading Level', 'invoicing' );
413
+    public function edit_heading_template($field) {
414
+        $restrict = $this->get_restrict_markup($field, 'heading');
415
+        $label    = __('Heading', 'invoicing');
416
+        $label2   = __('Select Heading Level', 'invoicing');
417 417
         $id       = $field . '.id + "_edit"';
418 418
         $id2      = $field . '.id + "_edit2"';
419 419
 
@@ -445,8 +445,8 @@  discard block
 block discarded – undo
445 445
     /**
446 446
      * Renders a paragraph element template.
447 447
      */
448
-    public function render_paragraph_template( $field ) {
449
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
448
+    public function render_paragraph_template($field) {
449
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
450 450
         $label    = "$field.text";
451 451
         echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
452 452
     }
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
     /**
455 455
      * Renders a privacy element template.
456 456
      */
457
-    public function render_privacy_template( $field ) {
458
-        $restrict = $this->get_restrict_markup( $field, 'privacy' );
457
+    public function render_privacy_template($field) {
458
+        $restrict = $this->get_restrict_markup($field, 'privacy');
459 459
         $label    = "$field.text";
460 460
         echo "<p $restrict v-html='$label' style='font-size: 16px;'></p>";
461 461
     }
@@ -463,23 +463,23 @@  discard block
 block discarded – undo
463 463
     /**
464 464
      * Renders the paragraph element on the frontend.
465 465
      */
466
-    public function frontend_render_paragraph_template( $field ) {
466
+    public function frontend_render_paragraph_template($field) {
467 467
         echo "<p>{$field['text']}</p>";
468 468
     }
469 469
 
470 470
     /**
471 471
      * Renders the privacy element on the frontend.
472 472
      */
473
-    public function frontend_render_privacy_template( $field ) {
473
+    public function frontend_render_privacy_template($field) {
474 474
         echo "<p>{$field['text']}</p>";
475 475
     }
476 476
 
477 477
     /**
478 478
      * Renders the edit paragraph element template.
479 479
      */
480
-    public function edit_paragraph_template( $field ) {
481
-        $restrict = $this->get_restrict_markup( $field, 'paragraph' );
482
-        $label    = __( 'Enter your text', 'invoicing' );
480
+    public function edit_paragraph_template($field) {
481
+        $restrict = $this->get_restrict_markup($field, 'paragraph');
482
+        $label    = __('Enter your text', 'invoicing');
483 483
         $id       = $field . '.id + "_edit"';
484 484
         echo "
485 485
             <div $restrict>
@@ -495,9 +495,9 @@  discard block
 block discarded – undo
495 495
     /**
496 496
      * Renders the edit privacy element template.
497 497
      */
498
-    public function edit_privacy_template( $field ) {
499
-        $restrict = $this->get_restrict_markup( $field, 'privacy' );
500
-        $label    = __( 'Privacy Text', 'invoicing' );
498
+    public function edit_privacy_template($field) {
499
+        $restrict = $this->get_restrict_markup($field, 'privacy');
500
+        $label    = __('Privacy Text', 'invoicing');
501 501
         $id       = $field . '.id + "_edit"';
502 502
         echo "
503 503
             <div $restrict>
@@ -513,8 +513,8 @@  discard block
 block discarded – undo
513 513
     /**
514 514
      * Renders the text element template.
515 515
      */
516
-    public function render_text_template( $field ) {
517
-        $restrict = $this->get_restrict_markup( $field, 'text' );
516
+    public function render_text_template($field) {
517
+        $restrict = $this->get_restrict_markup($field, 'text');
518 518
         $label    = "$field.label";
519 519
         echo "
520 520
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -529,23 +529,23 @@  discard block
 block discarded – undo
529 529
     /**
530 530
      * Renders the text element on the frontend.
531 531
      */
532
-    public function frontend_render_text_template( $field ) {
532
+    public function frontend_render_text_template($field) {
533 533
         
534 534
         echo "<div class='form-group'>";
535 535
 
536 536
         echo aui()->input(
537 537
             array(
538
-                'name'       => esc_attr( $field['id'] ),
539
-                'id'         => esc_attr( $field['id'] ),
540
-                'placeholder'=> esc_attr( $field['placeholder'] ),
538
+                'name'       => esc_attr($field['id']),
539
+                'id'         => esc_attr($field['id']),
540
+                'placeholder'=> esc_attr($field['placeholder']),
541 541
                 'required'   => (bool) $field['required'],
542
-                'label'      => wp_kses_post( $field['label'] ),
542
+                'label'      => wp_kses_post($field['label']),
543 543
                 'no_wrap'    => true,
544 544
             )
545 545
         );
546 546
 
547
-        if ( ! empty( $field['description'] ) ) {
548
-            $description = wp_kses_post( $field['description'] );
547
+        if (!empty($field['description'])) {
548
+            $description = wp_kses_post($field['description']);
549 549
             echo "<small class='form-text text-muted'>$description</small>";
550 550
         }
551 551
 
@@ -556,16 +556,16 @@  discard block
 block discarded – undo
556 556
     /**
557 557
      * Renders the edit text element template.
558 558
      */
559
-    public function edit_text_template( $field ) {
560
-        $restrict = $this->get_restrict_markup( $field, 'text' );
561
-        $label    = __( 'Field Label', 'invoicing' );
559
+    public function edit_text_template($field) {
560
+        $restrict = $this->get_restrict_markup($field, 'text');
561
+        $label    = __('Field Label', 'invoicing');
562 562
         $id       = $field . '.id + "_edit"';
563
-        $label2   = __( 'Placeholder text', 'invoicing' );
563
+        $label2   = __('Placeholder text', 'invoicing');
564 564
         $id2      = $field . '.id + "_edit2"';
565
-        $label3   = __( 'Help text', 'invoicing' );
566
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
565
+        $label3   = __('Help text', 'invoicing');
566
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
567 567
         $id3      = $field . '.id + "_edit3"';
568
-        $label5   = __( 'Is this field required?', 'invoicing' );
568
+        $label5   = __('Is this field required?', 'invoicing');
569 569
         $id4      = $field . '.id + "_edit4"';
570 570
         echo "
571 571
             <div $restrict>
@@ -593,8 +593,8 @@  discard block
 block discarded – undo
593 593
     /**
594 594
      * Renders the textarea element template.
595 595
      */
596
-    public function render_textarea_template( $field ) {
597
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
596
+    public function render_textarea_template($field) {
597
+        $restrict = $this->get_restrict_markup($field, 'textarea');
598 598
         $label    = "$field.label";
599 599
         echo "
600 600
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -609,24 +609,24 @@  discard block
 block discarded – undo
609 609
     /**
610 610
      * Renders the textarea element on the frontend.
611 611
      */
612
-    public function frontend_render_textarea_template( $field ) {
612
+    public function frontend_render_textarea_template($field) {
613 613
         
614 614
         echo "<div class='form-group'>";
615 615
 
616 616
         echo aui()->textarea(
617 617
             array(
618
-                'name'       => esc_attr( $field['id'] ),
619
-                'id'         => esc_attr( $field['id'] ),
620
-                'placeholder'=> esc_attr( $field['placeholder'] ),
618
+                'name'       => esc_attr($field['id']),
619
+                'id'         => esc_attr($field['id']),
620
+                'placeholder'=> esc_attr($field['placeholder']),
621 621
                 'required'   => (bool) $field['required'],
622
-                'label'      => wp_kses_post( $field['label'] ),
622
+                'label'      => wp_kses_post($field['label']),
623 623
                 'no_wrap'    => true,
624 624
                 'rows'       => 3,
625 625
             )
626 626
         );
627 627
 
628
-        if ( ! empty( $field['description'] ) ) {
629
-            $description = wp_kses_post( $field['description'] );
628
+        if (!empty($field['description'])) {
629
+            $description = wp_kses_post($field['description']);
630 630
             echo "<small class='form-text text-muted'>$description</small>";
631 631
         }
632 632
 
@@ -637,16 +637,16 @@  discard block
 block discarded – undo
637 637
     /**
638 638
      * Renders the edit textarea element template.
639 639
      */
640
-    public function edit_textarea_template( $field ) {
641
-        $restrict = $this->get_restrict_markup( $field, 'textarea' );
642
-        $label    = __( 'Field Label', 'invoicing' );
640
+    public function edit_textarea_template($field) {
641
+        $restrict = $this->get_restrict_markup($field, 'textarea');
642
+        $label    = __('Field Label', 'invoicing');
643 643
         $id       = $field . '.id + "_edit"';
644
-        $label2   = __( 'Placeholder text', 'invoicing' );
644
+        $label2   = __('Placeholder text', 'invoicing');
645 645
         $id2      = $field . '.id + "_edit2"';
646
-        $label3   = __( 'Help text', 'invoicing' );
647
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
646
+        $label3   = __('Help text', 'invoicing');
647
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
648 648
         $id3      = $field . '.id + "_edit3"';
649
-        $label5   = __( 'Is this field required?', 'invoicing' );
649
+        $label5   = __('Is this field required?', 'invoicing');
650 650
         $id4      = $field . '.id + "_edit4"';
651 651
         echo "
652 652
             <div $restrict>
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
     /**
675 675
      * Renders the select element template.
676 676
      */
677
-    public function render_select_template( $field ) {
678
-        $restrict    = $this->get_restrict_markup( $field, 'select' );
677
+    public function render_select_template($field) {
678
+        $restrict    = $this->get_restrict_markup($field, 'select');
679 679
         $label       = "$field.label";
680 680
         $placeholder = "$field.placeholder";
681 681
         $id          = $field . '.id';
@@ -695,24 +695,24 @@  discard block
 block discarded – undo
695 695
     /**
696 696
      * Renders the select element on the frontend.
697 697
      */
698
-    public function frontend_render_select_template( $field ) {
698
+    public function frontend_render_select_template($field) {
699 699
         
700 700
         echo "<div class='form-group'>";
701 701
 
702 702
         echo aui()->select(
703 703
             array(
704
-                'name'       => esc_attr( $field['id'] ),
705
-                'id'         => esc_attr( $field['id'] ),
706
-                'placeholder'=> esc_attr( $field['placeholder'] ),
704
+                'name'       => esc_attr($field['id']),
705
+                'id'         => esc_attr($field['id']),
706
+                'placeholder'=> esc_attr($field['placeholder']),
707 707
                 'required'   => (bool) $field['required'],
708
-                'label'      => wp_kses_post( $field['label'] ),
708
+                'label'      => wp_kses_post($field['label']),
709 709
                 'no_wrap'    => true,
710
-                'options'    => array_combine( $field['options'], $field['options'] ),
710
+                'options'    => array_combine($field['options'], $field['options']),
711 711
             )
712 712
         );
713 713
 
714
-        if ( ! empty( $field['description'] ) ) {
715
-            $description = wp_kses_post( $field['description'] );
714
+        if (!empty($field['description'])) {
715
+            $description = wp_kses_post($field['description']);
716 716
             echo "<small class='form-text text-muted'>$description</small>";
717 717
         }
718 718
 
@@ -723,18 +723,18 @@  discard block
 block discarded – undo
723 723
     /**
724 724
      * Renders the edit select element template.
725 725
      */
726
-    public function edit_select_template( $field ) {
727
-        $restrict = $this->get_restrict_markup( $field, 'select' );
728
-        $label    = __( 'Field Label', 'invoicing' );
726
+    public function edit_select_template($field) {
727
+        $restrict = $this->get_restrict_markup($field, 'select');
728
+        $label    = __('Field Label', 'invoicing');
729 729
         $id       = $field . '.id + "_edit"';
730
-        $label2   = __( 'Placeholder text', 'invoicing' );
730
+        $label2   = __('Placeholder text', 'invoicing');
731 731
         $id2      = $field . '.id + "_edit2"';
732
-        $label3   = __( 'Help text', 'invoicing' );
733
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
732
+        $label3   = __('Help text', 'invoicing');
733
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
734 734
         $id3      = $field . '.id + "_edit3"';
735
-        $label5   = __( 'Is this field required?', 'invoicing' );
735
+        $label5   = __('Is this field required?', 'invoicing');
736 736
         $id4      = $field . '.id + "_edit4"';
737
-        $label6   = __( 'Available Options', 'invoicing' );
737
+        $label6   = __('Available Options', 'invoicing');
738 738
         echo "
739 739
             <div $restrict>
740 740
                 <div class='form-group'>
@@ -772,8 +772,8 @@  discard block
 block discarded – undo
772 772
     /**
773 773
      * Renders the checkbox element template.
774 774
      */
775
-    public function render_checkbox_template( $field ) {
776
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
775
+    public function render_checkbox_template($field) {
776
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
777 777
         echo "
778 778
             <div class='form-check' $restrict>
779 779
                 <div class='wpinv-payment-form-field-preview-overlay'></div>
@@ -787,8 +787,8 @@  discard block
 block discarded – undo
787 787
     /**
788 788
      * Renders the terms element template.
789 789
      */
790
-    public function render_terms_template( $field ) {
791
-        $restrict = $this->get_restrict_markup( $field, 'terms' );
790
+    public function render_terms_template($field) {
791
+        $restrict = $this->get_restrict_markup($field, 'terms');
792 792
         echo "
793 793
             <div class='form-check' $restrict>
794 794
                 <div class='wpinv-payment-form-field-preview-overlay'></div>
@@ -802,24 +802,24 @@  discard block
 block discarded – undo
802 802
     /**
803 803
      * Renders the checkbox element on the frontend.
804 804
      */
805
-    public function frontend_render_checkbox_template( $field ) {
805
+    public function frontend_render_checkbox_template($field) {
806 806
         
807 807
         echo "<div class='form-group'>";
808 808
 
809 809
         echo aui()->input(
810 810
             array(
811
-                'name'       => esc_attr( $field['id'] ),
812
-                'id'         => esc_attr( $field['id'] ),
811
+                'name'       => esc_attr($field['id']),
812
+                'id'         => esc_attr($field['id']),
813 813
                 'required'   => (bool) $field['required'],
814
-                'label'      => wp_kses_post( $field['label'] ),
814
+                'label'      => wp_kses_post($field['label']),
815 815
                 'no_wrap'    => true,
816
-                'value'      => esc_attr__( 'Yes', 'invoicing' ),
816
+                'value'      => esc_attr__('Yes', 'invoicing'),
817 817
                 'type'       => 'checkbox',
818 818
             )
819 819
         );
820 820
 
821
-        if ( ! empty( $field['description'] ) ) {
822
-            $description = wp_kses_post( $field['description'] );
821
+        if (!empty($field['description'])) {
822
+            $description = wp_kses_post($field['description']);
823 823
             echo "<small class='form-text text-muted'>$description</small>";
824 824
         }
825 825
 
@@ -830,24 +830,24 @@  discard block
 block discarded – undo
830 830
         /**
831 831
      * Renders the terms element on the frontend.
832 832
      */
833
-    public function frontend_render_terms_template( $field ) {
833
+    public function frontend_render_terms_template($field) {
834 834
         
835 835
         echo "<div class='form-group'>";
836 836
 
837 837
         echo aui()->input(
838 838
             array(
839
-                'name'       => esc_attr( $field['id'] ),
840
-                'id'         => esc_attr( $field['id'] ),
839
+                'name'       => esc_attr($field['id']),
840
+                'id'         => esc_attr($field['id']),
841 841
                 'required'   => (bool) $field['required'],
842
-                'label'      => wp_kses_post( $field['text'] ),
842
+                'label'      => wp_kses_post($field['text']),
843 843
                 'no_wrap'    => true,
844
-                'value'      => esc_attr__( 'Yes', 'invoicing' ),
844
+                'value'      => esc_attr__('Yes', 'invoicing'),
845 845
                 'type'       => 'checkbox',
846 846
             )
847 847
         );
848 848
 
849
-        if ( ! empty( $field['description'] ) ) {
850
-            $description = wp_kses_post( $field['description'] );
849
+        if (!empty($field['description'])) {
850
+            $description = wp_kses_post($field['description']);
851 851
             echo "<small class='form-text text-muted'>$description</small>";
852 852
         }
853 853
 
@@ -858,14 +858,14 @@  discard block
 block discarded – undo
858 858
     /**
859 859
      * Renders the edit checkbox element template.
860 860
      */
861
-    public function edit_checkbox_template( $field ) {
862
-        $restrict = $this->get_restrict_markup( $field, 'checkbox' );
863
-        $label    = __( 'Field Label', 'invoicing' );
861
+    public function edit_checkbox_template($field) {
862
+        $restrict = $this->get_restrict_markup($field, 'checkbox');
863
+        $label    = __('Field Label', 'invoicing');
864 864
         $id       = $field . '.id + "_edit"';
865
-        $label2   = __( 'Help text', 'invoicing' );
866
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
865
+        $label2   = __('Help text', 'invoicing');
866
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
867 867
         $id2      = $field . '.id + "_edit2"';
868
-        $label4   = __( 'Is this field required?', 'invoicing' );
868
+        $label4   = __('Is this field required?', 'invoicing');
869 869
         $id3      = $field . '.id + "_edit3"';
870 870
         echo "
871 871
             <div $restrict>
@@ -889,14 +889,14 @@  discard block
 block discarded – undo
889 889
     /**
890 890
      * Renders the edit terms element template.
891 891
      */
892
-    public function edit_terms_template( $field ) {
893
-        $restrict = $this->get_restrict_markup( $field, 'terms' );
894
-        $label    = __( 'Field Label', 'invoicing' );
892
+    public function edit_terms_template($field) {
893
+        $restrict = $this->get_restrict_markup($field, 'terms');
894
+        $label    = __('Field Label', 'invoicing');
895 895
         $id       = $field . '.id + "_edit"';
896
-        $label2   = __( 'Help text', 'invoicing' );
897
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
896
+        $label2   = __('Help text', 'invoicing');
897
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
898 898
         $id2      = $field . '.id + "_edit2"';
899
-        $label4   = __( 'Is this field required?', 'invoicing' );
899
+        $label4   = __('Is this field required?', 'invoicing');
900 900
         $id3      = $field . '.id + "_edit3"';
901 901
         echo "
902 902
             <div $restrict>
@@ -920,8 +920,8 @@  discard block
 block discarded – undo
920 920
     /**
921 921
      * Renders the radio element template.
922 922
      */
923
-    public function render_radio_template( $field ) {
924
-        $restrict    = $this->get_restrict_markup( $field, 'radio' );
923
+    public function render_radio_template($field) {
924
+        $restrict    = $this->get_restrict_markup($field, 'radio');
925 925
         $label       = "$field.label";
926 926
         $id          = $field . '.id';
927 927
         echo "
@@ -940,20 +940,20 @@  discard block
 block discarded – undo
940 940
     /**
941 941
      * Renders the radio element on the frontend.
942 942
      */
943
-    public function frontend_render_radio_template( $field ) {
943
+    public function frontend_render_radio_template($field) {
944 944
         
945 945
         echo "<div class='form-group'>";
946 946
 
947
-        if ( ! empty( $field['label'] ) ) {
948
-            $label = wp_kses_post( $field['label'] );
947
+        if (!empty($field['label'])) {
948
+            $label = wp_kses_post($field['label']);
949 949
             echo "<legend class='col-form-label'>$label</legend>";
950 950
         }
951 951
 
952
-        foreach( $field['options'] as $index => $option ) {
952
+        foreach ($field['options'] as $index => $option) {
953 953
             $id    = $field['id'] . $index;
954 954
             $name  = $field['id'];
955
-            $value = esc_attr( $option );
956
-            $label = wp_kses_post( $option );
955
+            $value = esc_attr($option);
956
+            $label = wp_kses_post($option);
957 957
 
958 958
             echo "
959 959
                 <div class='form-check'>
@@ -963,8 +963,8 @@  discard block
 block discarded – undo
963 963
             ";
964 964
         }
965 965
 
966
-        if ( ! empty( $field['description'] ) ) {
967
-            $description = wp_kses_post( $field['description'] );
966
+        if (!empty($field['description'])) {
967
+            $description = wp_kses_post($field['description']);
968 968
             echo "<small class='form-text text-muted'>$description</small>";
969 969
         }
970 970
 
@@ -975,16 +975,16 @@  discard block
 block discarded – undo
975 975
     /**
976 976
      * Renders the edit radio element template.
977 977
      */
978
-    public function edit_radio_template( $field ) {
979
-        $restrict = $this->get_restrict_markup( $field, 'radio' );
980
-        $label    = __( 'Field Label', 'invoicing' );
978
+    public function edit_radio_template($field) {
979
+        $restrict = $this->get_restrict_markup($field, 'radio');
980
+        $label    = __('Field Label', 'invoicing');
981 981
         $id       = $field . '.id + "_edit"';
982
-        $label2   = __( 'Help text', 'invoicing' );
983
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
982
+        $label2   = __('Help text', 'invoicing');
983
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
984 984
         $id2      = $field . '.id + "_edit3"';
985
-        $label4   = __( 'Is this field required?', 'invoicing' );
985
+        $label4   = __('Is this field required?', 'invoicing');
986 986
         $id3      = $field . '.id + "_edit4"';
987
-        $label5   = __( 'Available Options', 'invoicing' );
987
+        $label5   = __('Available Options', 'invoicing');
988 988
         echo "
989 989
             <div $restrict>
990 990
                 <div class='form-group'>
@@ -1018,8 +1018,8 @@  discard block
 block discarded – undo
1018 1018
     /**
1019 1019
      * Renders the address element template.
1020 1020
      */
1021
-    public function render_address_template( $field ) {
1022
-        $restrict    = $this->get_restrict_markup( $field, 'address' );
1021
+    public function render_address_template($field) {
1022
+        $restrict = $this->get_restrict_markup($field, 'address');
1023 1023
 
1024 1024
         echo "
1025 1025
             <div class='wpinv-address-wrapper' $restrict>
@@ -1041,55 +1041,55 @@  discard block
 block discarded – undo
1041 1041
     /**
1042 1042
      * Renders the address element on the frontend.
1043 1043
      */
1044
-    public function frontend_render_address_template( $field ) {
1044
+    public function frontend_render_address_template($field) {
1045 1045
         
1046 1046
         echo "<div class='wpinv-address-fields'>";
1047 1047
 
1048
-        foreach( $field['fields'] as $address_field ) {
1048
+        foreach ($field['fields'] as $address_field) {
1049 1049
 
1050
-            if ( empty( $address_field['visible'] ) ) {
1050
+            if (empty($address_field['visible'])) {
1051 1051
                 continue;
1052 1052
             }
1053 1053
 
1054
-            $class = esc_attr( $address_field['name'] );
1054
+            $class = esc_attr($address_field['name']);
1055 1055
             echo "<div class='form-group $class'>";
1056 1056
 
1057 1057
             $label = $address_field['label'];
1058 1058
 
1059
-            if ( ! empty( $address_field['required'] ) ) {
1059
+            if (!empty($address_field['required'])) {
1060 1060
                 $label .= "<span class='text-danger'> *</span>";
1061 1061
             }
1062 1062
 
1063
-            if ( 'wpinv_country' == $address_field['name'] ) {
1063
+            if ('wpinv_country' == $address_field['name']) {
1064 1064
 
1065
-                echo aui()->select( array(
1065
+                echo aui()->select(array(
1066 1066
                     'options'          => wpinv_get_country_list(),
1067
-                    'name'             => esc_attr( $address_field['name'] ),
1068
-                    'id'               => esc_attr( $address_field['name'] ),
1067
+                    'name'             => esc_attr($address_field['name']),
1068
+                    'id'               => esc_attr($address_field['name']),
1069 1069
                     'value'            => wpinv_get_default_country(),
1070
-                    'placeholder'      => esc_attr( $address_field['placeholder'] ),
1070
+                    'placeholder'      => esc_attr($address_field['placeholder']),
1071 1071
                     'required'         => (bool) $address_field['required'],
1072 1072
                     'no_wrap'          => true,
1073
-                    'label'            => wp_kses_post( $label ),
1073
+                    'label'            => wp_kses_post($label),
1074 1074
                     'select2'          => false,
1075 1075
                 ));
1076 1076
     
1077
-            } else if ( 'wpinv_state' == $address_field['name'] ) {
1077
+            } else if ('wpinv_state' == $address_field['name']) {
1078 1078
 
1079
-                $states = wpinv_get_country_states( wpinv_get_default_country() );
1079
+                $states = wpinv_get_country_states(wpinv_get_default_country());
1080 1080
                 $state  = wpinv_get_default_state();
1081 1081
 
1082
-                if ( ! empty( $states ) ) {
1082
+                if (!empty($states)) {
1083 1083
 
1084
-                    echo aui()->select( array(
1084
+                    echo aui()->select(array(
1085 1085
                         'options'          => $states,
1086
-                        'name'             => esc_attr( $address_field['name'] ),
1087
-                        'id'               => esc_attr( $address_field['name'] ),
1086
+                        'name'             => esc_attr($address_field['name']),
1087
+                        'id'               => esc_attr($address_field['name']),
1088 1088
                         'value'            => $state,
1089
-                        'placeholder'      => esc_attr( $address_field['placeholder'] ),
1089
+                        'placeholder'      => esc_attr($address_field['placeholder']),
1090 1090
                         'required'         => (bool) $address_field['required'],
1091 1091
                         'no_wrap'          => true,
1092
-                        'label'            => wp_kses_post( $label ),
1092
+                        'label'            => wp_kses_post($label),
1093 1093
                         'select2'          => false,
1094 1094
                     ));
1095 1095
 
@@ -1097,10 +1097,10 @@  discard block
 block discarded – undo
1097 1097
 
1098 1098
                     echo aui()->input(
1099 1099
                         array(
1100
-                            'name'       => esc_attr( $address_field['name'] ),
1101
-                            'id'         => esc_attr( $address_field['name'] ),
1100
+                            'name'       => esc_attr($address_field['name']),
1101
+                            'id'         => esc_attr($address_field['name']),
1102 1102
                             'required'   => (bool) $address_field['required'],
1103
-                            'label'      => wp_kses_post( $label ),
1103
+                            'label'      => wp_kses_post($label),
1104 1104
                             'no_wrap'    => true,
1105 1105
                             'type'       => 'text',
1106 1106
                         )
@@ -1112,12 +1112,12 @@  discard block
 block discarded – undo
1112 1112
 
1113 1113
                 echo aui()->input(
1114 1114
                     array(
1115
-                        'name'       => esc_attr( $address_field['name'] ),
1116
-                        'id'         => esc_attr( $address_field['name'] ),
1115
+                        'name'       => esc_attr($address_field['name']),
1116
+                        'id'         => esc_attr($address_field['name']),
1117 1117
                         'required'   => (bool) $address_field['required'],
1118
-                        'label'      => wp_kses_post( $label ),
1118
+                        'label'      => wp_kses_post($label),
1119 1119
                         'no_wrap'    => true,
1120
-                        'placeholder' => esc_attr( $address_field['placeholder'] ),
1120
+                        'placeholder' => esc_attr($address_field['placeholder']),
1121 1121
                         'type'       => 'text',
1122 1122
                     )
1123 1123
                 );
@@ -1125,8 +1125,8 @@  discard block
 block discarded – undo
1125 1125
             }
1126 1126
             
1127 1127
 
1128
-            if ( ! empty( $address_field['description'] ) ) {
1129
-                $description = wp_kses_post( $address_field['description'] );
1128
+            if (!empty($address_field['description'])) {
1129
+                $description = wp_kses_post($address_field['description']);
1130 1130
                 echo "<small class='form-text text-muted'>$description</small>";
1131 1131
             }
1132 1132
     
@@ -1141,13 +1141,13 @@  discard block
 block discarded – undo
1141 1141
     /**
1142 1142
      * Renders the edit address element template.
1143 1143
      */
1144
-    public function edit_address_template( $field ) {
1145
-        $restrict  = $this->get_restrict_markup( $field, 'address' );
1146
-        $label     = __( 'Field Label', 'invoicing' );
1147
-        $label2    = __( 'Placeholder', 'invoicing' );
1148
-        $label3    = __( 'Description', 'invoicing' );
1149
-        $label4    = __( 'Is required', 'invoicing' );
1150
-        $label5    = __( 'Is visible', 'invoicing' );
1144
+    public function edit_address_template($field) {
1145
+        $restrict  = $this->get_restrict_markup($field, 'address');
1146
+        $label     = __('Field Label', 'invoicing');
1147
+        $label2    = __('Placeholder', 'invoicing');
1148
+        $label3    = __('Description', 'invoicing');
1149
+        $label4    = __('Is required', 'invoicing');
1150
+        $label5    = __('Is visible', 'invoicing');
1151 1151
         $id        = $field . '.id + "_edit_label"';
1152 1152
         $id2       = $field . '.id + "_edit_placeholder"';
1153 1153
         $id3       = $field . '.id + "_edit_description"';
@@ -1215,8 +1215,8 @@  discard block
 block discarded – undo
1215 1215
     /**
1216 1216
      * Renders the email element template.
1217 1217
      */
1218
-    public function render_email_template( $field ) {
1219
-        $restrict = $this->get_restrict_markup( $field, 'email' );
1218
+    public function render_email_template($field) {
1219
+        $restrict = $this->get_restrict_markup($field, 'email');
1220 1220
         $label    = "$field.label";
1221 1221
         echo "
1222 1222
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1231,8 +1231,8 @@  discard block
 block discarded – undo
1231 1231
     /**
1232 1232
      * Renders the billing_email element template.
1233 1233
      */
1234
-    public function render_billing_email_template( $field ) {
1235
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1234
+    public function render_billing_email_template($field) {
1235
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
1236 1236
         $label    = "$field.label";
1237 1237
         echo "
1238 1238
             <div $restrict>
@@ -1246,24 +1246,24 @@  discard block
 block discarded – undo
1246 1246
     /**
1247 1247
      * Renders the email element on the frontend.
1248 1248
      */
1249
-    public function frontend_render_email_template( $field ) {
1249
+    public function frontend_render_email_template($field) {
1250 1250
         
1251 1251
         echo "<div class='form-group'>";
1252 1252
 
1253 1253
         echo aui()->input(
1254 1254
             array(
1255
-                'name'       => esc_attr( $field['id'] ),
1256
-                'id'         => esc_attr( $field['id'] ),
1255
+                'name'       => esc_attr($field['id']),
1256
+                'id'         => esc_attr($field['id']),
1257 1257
                 'required'   => (bool) $field['required'],
1258
-                'label'      => wp_kses_post( $field['label'] ),
1258
+                'label'      => wp_kses_post($field['label']),
1259 1259
                 'no_wrap'    => true,
1260
-                'placeholder' => esc_attr( $field['placeholder'] ),
1260
+                'placeholder' => esc_attr($field['placeholder']),
1261 1261
                 'type'       => 'email',
1262 1262
             )
1263 1263
         );
1264 1264
 
1265
-        if ( ! empty( $field['description'] ) ) {
1266
-            $description = wp_kses_post( $field['description'] );
1265
+        if (!empty($field['description'])) {
1266
+            $description = wp_kses_post($field['description']);
1267 1267
             echo "<small class='form-text text-muted'>$description</small>";
1268 1268
         }
1269 1269
 
@@ -1274,30 +1274,30 @@  discard block
 block discarded – undo
1274 1274
     /**
1275 1275
      * Renders the billing email element on the frontend.
1276 1276
      */
1277
-    public function frontend_render_billing_email_template( $field ) {
1277
+    public function frontend_render_billing_email_template($field) {
1278 1278
         
1279 1279
         echo "<div class='form-group'>";
1280 1280
         $value = '';
1281 1281
 
1282
-        if ( is_user_logged_in() ) {
1282
+        if (is_user_logged_in()) {
1283 1283
             $user  = wp_get_current_user();
1284
-            $value = sanitize_email( $user->user_email );
1284
+            $value = sanitize_email($user->user_email);
1285 1285
         }
1286 1286
         echo aui()->input(
1287 1287
             array(
1288 1288
                 'name'       => 'billing_email',
1289 1289
                 'value'      => $value,
1290
-                'id'         => esc_attr( $field['id'] ),
1290
+                'id'         => esc_attr($field['id']),
1291 1291
                 'required'   => true,
1292
-                'label'      => wp_kses_post( $field['label'] ),
1292
+                'label'      => wp_kses_post($field['label']),
1293 1293
                 'no_wrap'    => true,
1294
-                'placeholder' => esc_attr( $field['placeholder'] ),
1294
+                'placeholder' => esc_attr($field['placeholder']),
1295 1295
                 'type'       => 'email',
1296 1296
             )
1297 1297
         );
1298 1298
 
1299
-        if ( ! empty( $field['description'] ) ) {
1300
-            $description = wp_kses_post( $field['description'] );
1299
+        if (!empty($field['description'])) {
1300
+            $description = wp_kses_post($field['description']);
1301 1301
             echo "<small class='form-text text-muted'>$description</small>";
1302 1302
         }
1303 1303
 
@@ -1308,16 +1308,16 @@  discard block
 block discarded – undo
1308 1308
     /**
1309 1309
      * Renders the edit email element template.
1310 1310
      */
1311
-    public function edit_email_template( $field ) {
1312
-        $restrict = $this->get_restrict_markup( $field, 'email' );
1313
-        $label    = __( 'Field Label', 'invoicing' );
1311
+    public function edit_email_template($field) {
1312
+        $restrict = $this->get_restrict_markup($field, 'email');
1313
+        $label    = __('Field Label', 'invoicing');
1314 1314
         $id       = $field . '.id + "_edit"';
1315
-        $label2   = __( 'Placeholder text', 'invoicing' );
1315
+        $label2   = __('Placeholder text', 'invoicing');
1316 1316
         $id2      = $field . '.id + "_edit2"';
1317
-        $label3   = __( 'Help text', 'invoicing' );
1318
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1317
+        $label3   = __('Help text', 'invoicing');
1318
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1319 1319
         $id3      = $field . '.id + "_edit3"';
1320
-        $label5   = __( 'Is this field required?', 'invoicing' );
1320
+        $label5   = __('Is this field required?', 'invoicing');
1321 1321
         $id4      = $field . '.id + "_edit4"';
1322 1322
         echo "
1323 1323
             <div $restrict>
@@ -1345,16 +1345,16 @@  discard block
 block discarded – undo
1345 1345
     /**
1346 1346
      * Renders the edit billing_email element template.
1347 1347
      */
1348
-    public function edit_billing_email_template( $field ) {
1349
-        $restrict = $this->get_restrict_markup( $field, 'billing_email' );
1350
-        $label    = __( 'Field Label', 'invoicing' );
1348
+    public function edit_billing_email_template($field) {
1349
+        $restrict = $this->get_restrict_markup($field, 'billing_email');
1350
+        $label    = __('Field Label', 'invoicing');
1351 1351
         $id       = $field . '.id + "_edit"';
1352
-        $label2   = __( 'Placeholder text', 'invoicing' );
1352
+        $label2   = __('Placeholder text', 'invoicing');
1353 1353
         $id2      = $field . '.id + "_edit2"';
1354
-        $label3   = __( 'Help text', 'invoicing' );
1355
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1354
+        $label3   = __('Help text', 'invoicing');
1355
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1356 1356
         $id3      = $field . '.id + "_edit3"';
1357
-        $label5   = __( 'Is this field required?', 'invoicing' );
1357
+        $label5   = __('Is this field required?', 'invoicing');
1358 1358
         $id4      = $field . '.id + "_edit4"';
1359 1359
         echo "
1360 1360
             <div $restrict>
@@ -1378,8 +1378,8 @@  discard block
 block discarded – undo
1378 1378
     /**
1379 1379
      * Renders the website element template.
1380 1380
      */
1381
-    public function render_website_template( $field ) {
1382
-        $restrict = $this->get_restrict_markup( $field, 'website' );
1381
+    public function render_website_template($field) {
1382
+        $restrict = $this->get_restrict_markup($field, 'website');
1383 1383
         $label    = "$field.label";
1384 1384
         echo "
1385 1385
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1394,24 +1394,24 @@  discard block
 block discarded – undo
1394 1394
     /**
1395 1395
      * Renders the website element on the frontend.
1396 1396
      */
1397
-    public function frontend_render_website_template( $field ) {
1397
+    public function frontend_render_website_template($field) {
1398 1398
         
1399 1399
         echo "<div class='form-group'>";
1400 1400
 
1401 1401
         echo aui()->input(
1402 1402
             array(
1403
-                'name'       => esc_attr( $field['id'] ),
1404
-                'id'         => esc_attr( $field['id'] ),
1403
+                'name'       => esc_attr($field['id']),
1404
+                'id'         => esc_attr($field['id']),
1405 1405
                 'required'   => (bool) $field['required'],
1406
-                'label'      => wp_kses_post( $field['label'] ),
1406
+                'label'      => wp_kses_post($field['label']),
1407 1407
                 'no_wrap'    => true,
1408
-                'placeholder' => esc_attr( $field['placeholder'] ),
1408
+                'placeholder' => esc_attr($field['placeholder']),
1409 1409
                 'type'       => 'url',
1410 1410
             )
1411 1411
         );
1412 1412
 
1413
-        if ( ! empty( $field['description'] ) ) {
1414
-            $description = wp_kses_post( $field['description'] );
1413
+        if (!empty($field['description'])) {
1414
+            $description = wp_kses_post($field['description']);
1415 1415
             echo "<small class='form-text text-muted'>$description</small>";
1416 1416
         }
1417 1417
 
@@ -1422,16 +1422,16 @@  discard block
 block discarded – undo
1422 1422
     /**
1423 1423
      * Renders the edit website element template.
1424 1424
      */
1425
-    public function edit_website_template( $field ) {
1426
-        $restrict = $this->get_restrict_markup( $field, 'website' );
1427
-        $label    = __( 'Field Label', 'invoicing' );
1425
+    public function edit_website_template($field) {
1426
+        $restrict = $this->get_restrict_markup($field, 'website');
1427
+        $label    = __('Field Label', 'invoicing');
1428 1428
         $id       = $field . '.id + "_edit"';
1429
-        $label2   = __( 'Placeholder text', 'invoicing' );
1429
+        $label2   = __('Placeholder text', 'invoicing');
1430 1430
         $id2      = $field . '.id + "_edit2"';
1431
-        $label3   = __( 'Help text', 'invoicing' );
1432
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1431
+        $label3   = __('Help text', 'invoicing');
1432
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1433 1433
         $id3      = $field . '.id + "_edit3"';
1434
-        $label5   = __( 'Is this field required?', 'invoicing' );
1434
+        $label5   = __('Is this field required?', 'invoicing');
1435 1435
         $id4      = $field . '.id + "_edit4"';
1436 1436
         echo "
1437 1437
             <div $restrict>
@@ -1459,8 +1459,8 @@  discard block
 block discarded – undo
1459 1459
     /**
1460 1460
      * Renders the date element template.
1461 1461
      */
1462
-    public function render_date_template( $field ) {
1463
-        $restrict = $this->get_restrict_markup( $field, 'date' );
1462
+    public function render_date_template($field) {
1463
+        $restrict = $this->get_restrict_markup($field, 'date');
1464 1464
         $label    = "$field.label";
1465 1465
         echo "
1466 1466
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1475,23 +1475,23 @@  discard block
 block discarded – undo
1475 1475
     /**
1476 1476
      * Renders the date element on the frontend.
1477 1477
      */
1478
-    public function frontend_render_date_template( $field ) {
1478
+    public function frontend_render_date_template($field) {
1479 1479
         
1480 1480
         echo "<div class='form-group'>";
1481 1481
 
1482 1482
         echo aui()->input(
1483 1483
             array(
1484
-                'name'       => esc_attr( $field['id'] ),
1485
-                'id'         => esc_attr( $field['id'] ),
1484
+                'name'       => esc_attr($field['id']),
1485
+                'id'         => esc_attr($field['id']),
1486 1486
                 'required'   => (bool) $field['required'],
1487
-                'label'      => wp_kses_post( $field['label'] ),
1487
+                'label'      => wp_kses_post($field['label']),
1488 1488
                 'no_wrap'    => true,
1489 1489
                 'type'       => 'date',
1490 1490
             )
1491 1491
         );
1492 1492
 
1493
-        if ( ! empty( $field['description'] ) ) {
1494
-            $description = wp_kses_post( $field['description'] );
1493
+        if (!empty($field['description'])) {
1494
+            $description = wp_kses_post($field['description']);
1495 1495
             echo "<small class='form-text text-muted'>$description</small>";
1496 1496
         }
1497 1497
 
@@ -1502,14 +1502,14 @@  discard block
 block discarded – undo
1502 1502
     /**
1503 1503
      * Renders the edit date element template.
1504 1504
      */
1505
-    public function edit_date_template( $field ) {
1506
-        $restrict = $this->get_restrict_markup( $field, 'date' );
1507
-        $label    = __( 'Field Label', 'invoicing' );
1505
+    public function edit_date_template($field) {
1506
+        $restrict = $this->get_restrict_markup($field, 'date');
1507
+        $label    = __('Field Label', 'invoicing');
1508 1508
         $id       = $field . '.id + "_edit"';
1509
-        $label3   = __( 'Help text', 'invoicing' );
1510
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1509
+        $label3   = __('Help text', 'invoicing');
1510
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1511 1511
         $id3      = $field . '.id + "_edit3"';
1512
-        $label5   = __( 'Is this field required?', 'invoicing' );
1512
+        $label5   = __('Is this field required?', 'invoicing');
1513 1513
         $id4      = $field . '.id + "_edit4"';
1514 1514
         echo "
1515 1515
             <div $restrict>
@@ -1533,8 +1533,8 @@  discard block
 block discarded – undo
1533 1533
     /**
1534 1534
      * Renders the time element template.
1535 1535
      */
1536
-    public function render_time_template( $field ) {
1537
-        $restrict = $this->get_restrict_markup( $field, 'time' );
1536
+    public function render_time_template($field) {
1537
+        $restrict = $this->get_restrict_markup($field, 'time');
1538 1538
         $label    = "$field.label";
1539 1539
         echo "
1540 1540
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1549,23 +1549,23 @@  discard block
 block discarded – undo
1549 1549
     /**
1550 1550
      * Renders the time element on the frontend.
1551 1551
      */
1552
-    public function frontend_render_time_template( $field ) {
1552
+    public function frontend_render_time_template($field) {
1553 1553
         
1554 1554
         echo "<div class='form-group'>";
1555 1555
 
1556 1556
         echo aui()->input(
1557 1557
             array(
1558
-                'name'       => esc_attr( $field['id'] ),
1559
-                'id'         => esc_attr( $field['id'] ),
1558
+                'name'       => esc_attr($field['id']),
1559
+                'id'         => esc_attr($field['id']),
1560 1560
                 'required'   => (bool) $field['required'],
1561
-                'label'      => wp_kses_post( $field['label'] ),
1561
+                'label'      => wp_kses_post($field['label']),
1562 1562
                 'no_wrap'    => true,
1563 1563
                 'type'       => 'time',
1564 1564
             )
1565 1565
         );
1566 1566
 
1567
-        if ( ! empty( $field['description'] ) ) {
1568
-            $description = wp_kses_post( $field['description'] );
1567
+        if (!empty($field['description'])) {
1568
+            $description = wp_kses_post($field['description']);
1569 1569
             echo "<small class='form-text text-muted'>$description</small>";
1570 1570
         }
1571 1571
 
@@ -1576,14 +1576,14 @@  discard block
 block discarded – undo
1576 1576
     /**
1577 1577
      * Renders the edit time element template.
1578 1578
      */
1579
-    public function edit_time_template( $field ) {
1580
-        $restrict = $this->get_restrict_markup( $field, 'time' );
1581
-        $label    = __( 'Field Label', 'invoicing' );
1579
+    public function edit_time_template($field) {
1580
+        $restrict = $this->get_restrict_markup($field, 'time');
1581
+        $label    = __('Field Label', 'invoicing');
1582 1582
         $id       = $field . '.id + "_edit"';
1583
-        $label3   = __( 'Help text', 'invoicing' );
1584
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1583
+        $label3   = __('Help text', 'invoicing');
1584
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1585 1585
         $id3      = $field . '.id + "_edit3"';
1586
-        $label5   = __( 'Is this field required?', 'invoicing' );
1586
+        $label5   = __('Is this field required?', 'invoicing');
1587 1587
         $id4      = $field . '.id + "_edit4"';
1588 1588
         echo "
1589 1589
             <div $restrict>
@@ -1607,8 +1607,8 @@  discard block
 block discarded – undo
1607 1607
     /**
1608 1608
      * Renders the number element template.
1609 1609
      */
1610
-    public function render_number_template( $field ) {
1611
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1610
+    public function render_number_template($field) {
1611
+        $restrict = $this->get_restrict_markup($field, 'number');
1612 1612
         $label    = "$field.label";
1613 1613
         echo "
1614 1614
             <div $restrict class='wpinv-payment-form-field-preview'>
@@ -1623,24 +1623,24 @@  discard block
 block discarded – undo
1623 1623
     /**
1624 1624
      * Renders the number element on the frontend.
1625 1625
      */
1626
-    public function frontend_render_number_template( $field ) {
1626
+    public function frontend_render_number_template($field) {
1627 1627
         
1628 1628
         echo "<div class='form-group'>";
1629 1629
 
1630 1630
         echo aui()->input(
1631 1631
             array(
1632
-                'name'       => esc_attr( $field['id'] ),
1633
-                'id'         => esc_attr( $field['id'] ),
1632
+                'name'       => esc_attr($field['id']),
1633
+                'id'         => esc_attr($field['id']),
1634 1634
                 'required'   => (bool) $field['required'],
1635
-                'label'      => wp_kses_post( $field['label'] ),
1636
-                'placeholder' => esc_attr( $field['placeholder'] ),
1635
+                'label'      => wp_kses_post($field['label']),
1636
+                'placeholder' => esc_attr($field['placeholder']),
1637 1637
                 'no_wrap'    => true,
1638 1638
                 'type'       => 'number',
1639 1639
             )
1640 1640
         );
1641 1641
 
1642
-        if ( ! empty( $field['description'] ) ) {
1643
-            $description = wp_kses_post( $field['description'] );
1642
+        if (!empty($field['description'])) {
1643
+            $description = wp_kses_post($field['description']);
1644 1644
             echo "<small class='form-text text-muted'>$description</small>";
1645 1645
         }
1646 1646
 
@@ -1651,16 +1651,16 @@  discard block
 block discarded – undo
1651 1651
     /**
1652 1652
      * Renders the edit number element template.
1653 1653
      */
1654
-    public function edit_number_template( $field ) {
1655
-        $restrict = $this->get_restrict_markup( $field, 'number' );
1656
-        $label    = __( 'Field Label', 'invoicing' );
1654
+    public function edit_number_template($field) {
1655
+        $restrict = $this->get_restrict_markup($field, 'number');
1656
+        $label    = __('Field Label', 'invoicing');
1657 1657
         $id       = $field . '.id + "_edit"';
1658
-        $label2   = __( 'Placeholder text', 'invoicing' );
1658
+        $label2   = __('Placeholder text', 'invoicing');
1659 1659
         $id2      = $field . '.id + "_edit2"';
1660
-        $label3   = __( 'Help text', 'invoicing' );
1661
-        $label4   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1660
+        $label3   = __('Help text', 'invoicing');
1661
+        $label4   = esc_attr__('Add some help text for this field', 'invoicing');
1662 1662
         $id3      = $field . '.id + "_edit3"';
1663
-        $label5   = __( 'Is this field required?', 'invoicing' );
1663
+        $label5   = __('Is this field required?', 'invoicing');
1664 1664
         $id4      = $field . '.id + "_edit4"';
1665 1665
         echo "
1666 1666
             <div $restrict>
@@ -1688,23 +1688,23 @@  discard block
 block discarded – undo
1688 1688
     /**
1689 1689
      * Renders the separator element template.
1690 1690
      */
1691
-    public function render_separator_template( $field ) {
1692
-        $restrict = $this->get_restrict_markup( $field, 'separator' );
1691
+    public function render_separator_template($field) {
1692
+        $restrict = $this->get_restrict_markup($field, 'separator');
1693 1693
         echo "<hr class='featurette-divider mt-0 mb-2' $restrict>";
1694 1694
     }
1695 1695
 
1696 1696
     /**
1697 1697
      * Renders the separator element on the frontend.
1698 1698
      */
1699
-    public function frontend_render_separator_template( $field ) {
1699
+    public function frontend_render_separator_template($field) {
1700 1700
         echo '<hr class="featurette-divider mt-0 mb-2" />';
1701 1701
     }
1702 1702
 
1703 1703
     /**
1704 1704
      * Renders the pay button element template.
1705 1705
      */
1706
-    public function render_pay_button_template( $field ) {
1707
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1706
+    public function render_pay_button_template($field) {
1707
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1708 1708
         $label    = "$field.label";
1709 1709
         echo "
1710 1710
             <div $restrict>
@@ -1717,28 +1717,28 @@  discard block
 block discarded – undo
1717 1717
     /**
1718 1718
      * Renders the pay_button element on the frontend.
1719 1719
      */
1720
-    public function frontend_render_pay_button_template( $field ) {
1720
+    public function frontend_render_pay_button_template($field) {
1721 1721
 
1722 1722
         echo "<div class='mt-4 mb-4'>";
1723
-            do_action( 'wpinv_payment_mode_select' );
1723
+            do_action('wpinv_payment_mode_select');
1724 1724
         echo "</div>";
1725 1725
 
1726 1726
         echo "<div class='form-group'>";
1727 1727
 
1728
-        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class( $field['class'] );
1728
+        $class = 'wpinv-payment-form-submit btn btn-block submit-button ' . sanitize_html_class($field['class']);
1729 1729
         echo aui()->input(
1730 1730
             array(
1731
-                'name'       => esc_attr( $field['id'] ),
1732
-                'id'         => esc_attr( $field['id'] ),
1733
-                'value'      => esc_attr( $field['label'] ),
1731
+                'name'       => esc_attr($field['id']),
1732
+                'id'         => esc_attr($field['id']),
1733
+                'value'      => esc_attr($field['label']),
1734 1734
                 'no_wrap'    => true,
1735 1735
                 'type'       => 'submit',
1736 1736
                 'class'      => $class,
1737 1737
             )
1738 1738
         );
1739 1739
 
1740
-        if ( ! empty( $field['description'] ) ) {
1741
-            $description = wp_kses_post( $field['description'] );
1740
+        if (!empty($field['description'])) {
1741
+            $description = wp_kses_post($field['description']);
1742 1742
             echo "<small class='form-text text-muted'>$description</small>";
1743 1743
         }
1744 1744
 
@@ -1749,14 +1749,14 @@  discard block
 block discarded – undo
1749 1749
     /**
1750 1750
      * Renders the pay button element template.
1751 1751
      */
1752
-    public function edit_pay_button_template( $field ) {
1753
-        $restrict = $this->get_restrict_markup( $field, 'pay_button' );
1754
-        $label    = __( 'Button Text', 'invoicing' );
1752
+    public function edit_pay_button_template($field) {
1753
+        $restrict = $this->get_restrict_markup($field, 'pay_button');
1754
+        $label    = __('Button Text', 'invoicing');
1755 1755
         $id       = $field . '.id + "_edit"';
1756
-        $label2   = __( 'Help text', 'invoicing' );
1757
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1756
+        $label2   = __('Help text', 'invoicing');
1757
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1758 1758
         $id2      = $field . '.id + "_edit2"';
1759
-        $label4   = esc_attr__( 'Button Type', 'invoicing' );
1759
+        $label4   = esc_attr__('Button Type', 'invoicing');
1760 1760
         $id3      = $field . '.id + "_edit3"';
1761 1761
         echo "
1762 1762
             <div $restrict>
@@ -1772,15 +1772,15 @@  discard block
 block discarded – undo
1772 1772
                     <label :for='$id3'>$label4</label>
1773 1773
 
1774 1774
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1775
-                        <option value='btn-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1776
-                        <option value='btn-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1777
-                        <option value='btn-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1778
-                        <option value='btn-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1779
-                        <option value='btn-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1780
-                        <option value='btn-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1781
-                        <option value='btn-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1782
-                        <option value='btn-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1783
-                        <option value='btn-link'>"      . __( 'Link', 'invoicing' ) ."</option>
1775
+                        <option value='btn-primary'>" . __('Primary', 'invoicing') . "</option>
1776
+                        <option value='btn-secondary'>" . __('Secondary', 'invoicing') . "</option>
1777
+                        <option value='btn-success'>"   . __('Success', 'invoicing') . "</option>
1778
+                        <option value='btn-danger'>"    . __('Danger', 'invoicing') . "</option>
1779
+                        <option value='btn-warning'>"   . __('Warning', 'invoicing') . "</option>
1780
+                        <option value='btn-info'>"      . __('Info', 'invoicing') . "</option>
1781
+                        <option value='btn-light'>"     . __('Light', 'invoicing') . "</option>
1782
+                        <option value='btn-dark'>"      . __('Dark', 'invoicing') . "</option>
1783
+                        <option value='btn-link'>"      . __('Link', 'invoicing') . "</option>
1784 1784
                     </select>
1785 1785
                 </div>
1786 1786
             </div>
@@ -1791,8 +1791,8 @@  discard block
 block discarded – undo
1791 1791
     /**
1792 1792
      * Renders the alert element template.
1793 1793
      */
1794
-    public function render_alert_template( $field ) {
1795
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1794
+    public function render_alert_template($field) {
1795
+        $restrict = $this->get_restrict_markup($field, 'alert');
1796 1796
         $text     = "$field.text";
1797 1797
         echo "
1798 1798
             <div $restrict class='alert' :class='$field.class' role='alert'>
@@ -1807,15 +1807,15 @@  discard block
 block discarded – undo
1807 1807
     /**
1808 1808
      * Renders the alert element on the frontend.
1809 1809
      */
1810
-    public function frontend_render_alert_template( $field ) {
1810
+    public function frontend_render_alert_template($field) {
1811 1811
         
1812 1812
         echo "<div class='form-group'>";
1813 1813
 
1814 1814
         echo aui()->alert(
1815 1815
             array(
1816
-                'content'     => wp_kses_post( $field['text'] ),
1816
+                'content'     => wp_kses_post($field['text']),
1817 1817
                 'dismissible' => $field['dismissible'],
1818
-                'type'        => str_replace( 'alert-', '', $field['class'] ),
1818
+                'type'        => str_replace('alert-', '', $field['class']),
1819 1819
             )
1820 1820
         );
1821 1821
 
@@ -1826,14 +1826,14 @@  discard block
 block discarded – undo
1826 1826
     /**
1827 1827
      * Renders the alert element template.
1828 1828
      */
1829
-    public function edit_alert_template( $field ) {
1830
-        $restrict = $this->get_restrict_markup( $field, 'alert' );
1831
-        $label    = __( 'Alert Text', 'invoicing' );
1832
-        $label2   = esc_attr__( 'Enter your alert text here', 'invoicing' );
1829
+    public function edit_alert_template($field) {
1830
+        $restrict = $this->get_restrict_markup($field, 'alert');
1831
+        $label    = __('Alert Text', 'invoicing');
1832
+        $label2   = esc_attr__('Enter your alert text here', 'invoicing');
1833 1833
         $id       = $field . '.id + "_edit"';
1834
-        $label3   = __( 'Is Dismissible?', 'invoicing' );
1834
+        $label3   = __('Is Dismissible?', 'invoicing');
1835 1835
         $id2      = $field . '.id + "_edit2"';
1836
-        $label4   = esc_attr__( 'Alert Type', 'invoicing' );
1836
+        $label4   = esc_attr__('Alert Type', 'invoicing');
1837 1837
         $id3      = $field . '.id + "_edit3"';
1838 1838
         echo "
1839 1839
             <div $restrict>
@@ -1849,14 +1849,14 @@  discard block
 block discarded – undo
1849 1849
                     <label :for='$id3'>$label4</label>
1850 1850
 
1851 1851
                     <select class='form-control custom-select' :id='$id3' v-model='$field.class'>
1852
-                        <option value='alert-primary'>"   . __( 'Primary', 'invoicing' ) ."</option>
1853
-                        <option value='alert-secondary'>" . __( 'Secondary', 'invoicing' ) ."</option>
1854
-                        <option value='alert-success'>"   . __( 'Success', 'invoicing' ) ."</option>
1855
-                        <option value='alert-danger'>"    . __( 'Danger', 'invoicing' ) ."</option>
1856
-                        <option value='alert-warning'>"   . __( 'Warning', 'invoicing' ) ."</option>
1857
-                        <option value='alert-info'>"      . __( 'Info', 'invoicing' ) ."</option>
1858
-                        <option value='alert-light'>"     . __( 'Light', 'invoicing' ) ."</option>
1859
-                        <option value='alert-dark'>"      . __( 'Dark', 'invoicing' ) ."</option>
1852
+                        <option value='alert-primary'>" . __('Primary', 'invoicing') . "</option>
1853
+                        <option value='alert-secondary'>" . __('Secondary', 'invoicing') . "</option>
1854
+                        <option value='alert-success'>"   . __('Success', 'invoicing') . "</option>
1855
+                        <option value='alert-danger'>"    . __('Danger', 'invoicing') . "</option>
1856
+                        <option value='alert-warning'>"   . __('Warning', 'invoicing') . "</option>
1857
+                        <option value='alert-info'>"      . __('Info', 'invoicing') . "</option>
1858
+                        <option value='alert-light'>"     . __('Light', 'invoicing') . "</option>
1859
+                        <option value='alert-dark'>"      . __('Dark', 'invoicing') . "</option>
1860 1860
                     </select>
1861 1861
                 </div>
1862 1862
             </div>
@@ -1867,8 +1867,8 @@  discard block
 block discarded – undo
1867 1867
     /**
1868 1868
      * Renders the discount element template.
1869 1869
      */
1870
-    public function render_discount_template( $field ) {
1871
-        $restrict  = $this->get_restrict_markup( $field, 'discount' );
1870
+    public function render_discount_template($field) {
1871
+        $restrict = $this->get_restrict_markup($field, 'discount');
1872 1872
         ?>
1873 1873
 
1874 1874
             <div <?php echo $restrict; ?> class="discount_field  border rounded p-3">
@@ -1885,13 +1885,13 @@  discard block
 block discarded – undo
1885 1885
     /**
1886 1886
      * Renders the discount element on the frontend.
1887 1887
      */
1888
-    public function frontend_render_discount_template( $field ) {
1888
+    public function frontend_render_discount_template($field) {
1889 1889
         
1890
-        $placeholder = esc_attr( $field['input_label'] );
1891
-        $label       = sanitize_text_field( $field['button_label'] );
1890
+        $placeholder = esc_attr($field['input_label']);
1891
+        $label       = sanitize_text_field($field['button_label']);
1892 1892
         $description = '';
1893 1893
 
1894
-        if ( ! empty( $field['description'] ) ) {
1894
+        if (!empty($field['description'])) {
1895 1895
             $description = "<small class='form-text text-muted'>{$field['description']}</small>";
1896 1896
         }
1897 1897
 ?>
@@ -1912,12 +1912,12 @@  discard block
 block discarded – undo
1912 1912
     /**
1913 1913
      * Renders the discount element template.
1914 1914
      */
1915
-    public function edit_discount_template( $field ) {
1916
-        $restrict = $this->get_restrict_markup( $field, 'discount' );
1917
-        $label    = __( 'Discount Input Placeholder', 'invoicing' );
1918
-        $label2   = __( 'Help Text', 'invoicing' );
1919
-        $label3   = esc_attr__( 'Add some help text for this field', 'invoicing' );
1920
-        $label4   = __( 'Button Text', 'invoicing' );
1915
+    public function edit_discount_template($field) {
1916
+        $restrict = $this->get_restrict_markup($field, 'discount');
1917
+        $label    = __('Discount Input Placeholder', 'invoicing');
1918
+        $label2   = __('Help Text', 'invoicing');
1919
+        $label3   = esc_attr__('Add some help text for this field', 'invoicing');
1920
+        $label4   = __('Button Text', 'invoicing');
1921 1921
         $id       = $field . '.id + "_edit"';
1922 1922
         $id2      = $field . '.id + "_edit2"';
1923 1923
         $id3      = $field . '.id + "_edit3"';
@@ -1946,12 +1946,12 @@  discard block
 block discarded – undo
1946 1946
     /**
1947 1947
      * Renders the items element template.
1948 1948
      */
1949
-    public function render_items_template( $field ) {
1950
-        $restrict  = $this->get_restrict_markup( $field, 'items' );
1951
-        $label     = __( 'Item totals will appear here. Click to set items.', 'invoicing' );
1952
-        $label2    = __( 'Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing' );
1953
-        $label2   .= ' ' . __( 'To prevent this, limit customers to selecting a single item.', 'invoicing' );
1954
-        $label3    = __( 'Item totals will appear here.', 'invoicing' );
1949
+    public function render_items_template($field) {
1950
+        $restrict  = $this->get_restrict_markup($field, 'items');
1951
+        $label     = __('Item totals will appear here. Click to set items.', 'invoicing');
1952
+        $label2    = __('Your form allows customers to buy several recurring items. This is not supported and will lead to unexpected behaviour.', 'invoicing');
1953
+        $label2   .= ' ' . __('To prevent this, limit customers to selecting a single item.', 'invoicing');
1954
+        $label3    = __('Item totals will appear here.', 'invoicing');
1955 1955
         echo "
1956 1956
             <div $restrict class='item_totals text-center'>
1957 1957
                 <div v-if='!is_default'>
@@ -1968,17 +1968,17 @@  discard block
 block discarded – undo
1968 1968
     /**
1969 1969
      * Renders the items element on the frontend.
1970 1970
      */
1971
-    public function frontend_render_items_template( $field, $items ) {
1971
+    public function frontend_render_items_template($field, $items) {
1972 1972
 
1973 1973
         echo "<div class='form-group item_totals'>";
1974 1974
         
1975
-        $id = esc_attr( $field['id'] );
1975
+        $id = esc_attr($field['id']);
1976 1976
 
1977
-        if ( empty( $field[ 'items_type' ] ) ) {
1978
-            $field[ 'items_type' ] = 'total';
1977
+        if (empty($field['items_type'])) {
1978
+            $field['items_type'] = 'total';
1979 1979
         }
1980 1980
 
1981
-        if ( 'total' == $field[ 'items_type' ] ) {
1981
+        if ('total' == $field['items_type']) {
1982 1982
             $total     = 0;
1983 1983
             $tax       = 0;
1984 1984
             $sub_total = 0;
@@ -1987,16 +1987,16 @@  discard block
 block discarded – undo
1987 1987
             <div class="border item_totals_type_total">
1988 1988
 
1989 1989
                 <?php
1990
-                    foreach( $items as $item ) {
1990
+                    foreach ($items as $item) {
1991 1991
 
1992
-                        $amount = floatval( $item['price'] );
1992
+                        $amount = floatval($item['price']);
1993 1993
 
1994
-                        if ( wpinv_use_taxes() ) {
1994
+                        if (wpinv_use_taxes()) {
1995 1995
 
1996
-                            $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
1996
+                            $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
1997 1997
 
1998
-                            if ( wpinv_prices_include_tax() ) {
1999
-                                $pre_tax  = ( $amount - $amount * $rate * 0.01 );
1998
+                            if (wpinv_prices_include_tax()) {
1999
+                                $pre_tax  = ($amount - $amount * $rate * 0.01);
2000 2000
                                 $item_tax = $amount - $pre_tax;
2001 2001
                             } else {
2002 2002
                                 $pre_tax  = $amount;
@@ -2008,32 +2008,32 @@  discard block
 block discarded – undo
2008 2008
                             $total     = $sub_total + $tax;
2009 2009
 
2010 2010
                         } else {
2011
-                            $total  = $total + $amount;
2011
+                            $total = $total + $amount;
2012 2012
                         }
2013 2013
 
2014 2014
                         $class  = 'col-8';
2015 2015
                         $class2 = '';
2016 2016
 
2017
-                        if ( ! empty( $item['allow_quantities'] ) ) {
2017
+                        if (!empty($item['allow_quantities'])) {
2018 2018
                             $class = 'col-6 pt-2';
2019 2019
                             $class2 = 'pt-2';
2020 2020
                         }
2021 2021
 
2022
-                        if ( ! empty( $item['custom_price'] ) ) {
2022
+                        if (!empty($item['custom_price'])) {
2023 2023
                             $class .= ' pt-2';
2024 2024
                         }
2025 2025
 
2026 2026
                         $quantity = 1;
2027
-                        if ( ! empty( $item['quantity'] ) ) {
2028
-                            $quantity = absint( $item['quantity'] );
2027
+                        if (!empty($item['quantity'])) {
2028
+                            $quantity = absint($item['quantity']);
2029 2029
                         }
2030 2030
             
2031 2031
                 ?>
2032 2032
                     <div  class="item_totals_item">
2033 2033
                         <div class='row pl-2 pr-2 pt-2'>
2034
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2034
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2035 2035
 
2036
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2036
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2037 2037
 
2038 2038
                                 <div class='col-2'>
2039 2039
                                     <input name='wpinv-item-<?php echo (int) $item['id']; ?>-quantity' type='number' class='form-control wpinv-item-quantity-input pr-1' value='<?php echo $quantity ?>' min='1' required>
@@ -2041,11 +2041,11 @@  discard block
 block discarded – undo
2041 2041
 
2042 2042
                             <?php } else { ?>
2043 2043
                                 <input type='hidden' class='wpinv-item-quantity-input' value='<?php echo $quantity ?>'>
2044
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2044
+                            <?php } if (empty($item['custom_price'])) { ?>
2045 2045
 
2046 2046
                                 <div class='col-4 <?php echo $class2; ?>'>
2047
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2048
-                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2047
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2048
+                                    <input name='wpinv-items[<?php echo (int) $item['id']; ?>]' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2049 2049
                                 </div>
2050 2050
 
2051 2051
                             <?php } else {?>
@@ -2053,15 +2053,15 @@  discard block
 block discarded – undo
2053 2053
                                 <div class='col-4'>
2054 2054
                                     <div class='input-group'>
2055 2055
 
2056
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2056
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2057 2057
                                             <div class='input-group-prepend'>
2058 2058
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2059 2059
                                             </div>
2060 2060
                                         <?php } ?>
2061 2061
 
2062
-                                        <input type='text' 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'] ); ?>'>
2062
+                                        <input type='text' 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']); ?>'>
2063 2063
                                     
2064
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2064
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2065 2065
                                             <div class='input-group-append'>
2066 2066
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2067 2067
                                             </div>
@@ -2072,28 +2072,28 @@  discard block
 block discarded – undo
2072 2072
                             <?php } ?>
2073 2073
 
2074 2074
                         </div>
2075
-                        <?php if ( ! empty( $item['description'] )) { ?>
2076
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2075
+                        <?php if (!empty($item['description'])) { ?>
2076
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2077 2077
                         <?php } ?>
2078 2078
                     </div>
2079 2079
                 <?php } ?>
2080 2080
 
2081 2081
                 <div class='mt-4 border-top item_totals_total p-2'>
2082 2082
 
2083
-                    <?php if ( wpinv_use_taxes() ) { ?>
2083
+                    <?php if (wpinv_use_taxes()) { ?>
2084 2084
                         <div class='row'>
2085
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2086
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2085
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2086
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2087 2087
                         </div>
2088 2088
                         <div class='row'>
2089
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2090
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2089
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2090
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2091 2091
                         </div>
2092 2092
                     <?php } ?>
2093 2093
 
2094 2094
                     <div class='row'>
2095
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2096
-                        <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>
2095
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2096
+                        <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>
2097 2097
                     </div>
2098 2098
 
2099 2099
                 </div>
@@ -2101,22 +2101,22 @@  discard block
 block discarded – undo
2101 2101
             </div>
2102 2102
         <?php } ?>
2103 2103
 
2104
-        <?php if ( 'radio' == $field[ 'items_type' ] ) { ?>
2104
+        <?php if ('radio' == $field['items_type']) { ?>
2105 2105
             <div class="item_totals_type_radio">
2106 2106
 
2107 2107
                 <?php
2108
-                    foreach( $items as $index => $item ) {
2108
+                    foreach ($items as $index => $item) {
2109 2109
 
2110
-                        if ( ! empty( $item['required'] ) ) {
2110
+                        if (!empty($item['required'])) {
2111 2111
                             continue;
2112 2112
                         }
2113 2113
                 ?>
2114 2114
                     <div  class="form-check">
2115
-                        <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'>
2116
-                        <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>
2115
+                        <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'>
2116
+                        <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>
2117 2117
                     </div>
2118
-                    <?php if ( ! empty( $item['description'] )) { ?>
2119
-                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2118
+                    <?php if (!empty($item['description'])) { ?>
2119
+                        <small class='form-text text-muted pl-4 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2120 2120
                     <?php } ?>
2121 2121
                 <?php } ?>
2122 2122
 
@@ -2128,32 +2128,32 @@  discard block
 block discarded – undo
2128 2128
                         $tax       = 0;
2129 2129
                         $sub_total = 0;
2130 2130
 
2131
-                        foreach ( $items as $item ) {
2131
+                        foreach ($items as $item) {
2132 2132
 
2133 2133
                             $class  = 'col-8';
2134 2134
                             $class2 = '';
2135 2135
 
2136
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2136
+                            if (!empty($item['allow_quantities'])) {
2137 2137
                                 $class = 'col-6 pt-2';
2138 2138
                                 $class2 = 'pt-2';
2139 2139
                             }
2140 2140
 
2141
-                            if ( ! empty( $item['custom_price'] ) ) {
2141
+                            if (!empty($item['custom_price'])) {
2142 2142
                                 $class .= ' pt-2';
2143 2143
                             }
2144 2144
 
2145 2145
                             $class3 = 'd-none';
2146 2146
                             $name   = '';
2147
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_radio_item ) ) {
2147
+                            if (!empty($item['required']) || !isset($totals_selected_radio_item)) {
2148 2148
 
2149
-                                $amount = floatval( $item['price'] );
2149
+                                $amount = floatval($item['price']);
2150 2150
 
2151
-                                if ( wpinv_use_taxes() ) {
2151
+                                if (wpinv_use_taxes()) {
2152 2152
 
2153
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2153
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2154 2154
 
2155
-                                    if ( wpinv_prices_include_tax() ) {
2156
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2155
+                                    if (wpinv_prices_include_tax()) {
2156
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2157 2157
                                         $item_tax = $amount - $pre_tax;
2158 2158
                                     } else {
2159 2159
                                         $pre_tax  = $amount;
@@ -2165,13 +2165,13 @@  discard block
 block discarded – undo
2165 2165
                                     $total     = $sub_total + $tax;
2166 2166
 
2167 2167
                                 } else {
2168
-                                    $total  = $total + $amount;
2168
+                                    $total = $total + $amount;
2169 2169
                                 }
2170 2170
 
2171 2171
                                 $class3 = '';
2172 2172
                                 $name   = "wpinv-items[{$item['id']}]";
2173 2173
 
2174
-                                if ( empty( $item['required'] ) ) {
2174
+                                if (empty($item['required'])) {
2175 2175
                                     $totals_selected_radio_item = 1;
2176 2176
                                 }
2177 2177
 
@@ -2183,9 +2183,9 @@  discard block
 block discarded – undo
2183 2183
 
2184 2184
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2185 2185
                         <div class='row pl-2 pr-2 pt-2'>
2186
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2186
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2187 2187
 
2188
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2188
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2189 2189
 
2190 2190
                                 <div class='col-2'>
2191 2191
                                     <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>
@@ -2193,11 +2193,11 @@  discard block
 block discarded – undo
2193 2193
 
2194 2194
                             <?php } else { ?>
2195 2195
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2196
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2196
+                            <?php } if (empty($item['custom_price'])) { ?>
2197 2197
 
2198 2198
                                 <div class='col-4 <?php echo $class2; ?>'>
2199
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2200
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2199
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2200
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2201 2201
                                 </div>
2202 2202
 
2203 2203
                             <?php } else {?>
@@ -2205,15 +2205,15 @@  discard block
 block discarded – undo
2205 2205
                                 <div class='col-4'>
2206 2206
                                     <div class='input-group'>
2207 2207
 
2208
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2208
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2209 2209
                                             <div class='input-group-prepend'>
2210 2210
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2211 2211
                                             </div>
2212 2212
                                         <?php } ?>
2213 2213
 
2214
-                                        <input type='text' 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'] ); ?>'>
2214
+                                        <input type='text' 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']); ?>'>
2215 2215
                                     
2216
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2216
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2217 2217
                                             <div class='input-group-append'>
2218 2218
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2219 2219
                                             </div>
@@ -2224,27 +2224,27 @@  discard block
 block discarded – undo
2224 2224
                             <?php } ?>
2225 2225
 
2226 2226
                         </div>
2227
-                        <?php if ( ! empty( $item['description'] )) { ?>
2228
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2227
+                        <?php if (!empty($item['description'])) { ?>
2228
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2229 2229
                         <?php } ?>
2230 2230
                     </div>
2231 2231
                 <?php } ?>
2232 2232
 
2233 2233
                 <div class='mt-4 border-top item_totals_total p-2'>
2234
-                    <?php if ( wpinv_use_taxes() ) { ?>
2234
+                    <?php if (wpinv_use_taxes()) { ?>
2235 2235
                         <div class='row'>
2236
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2237
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2236
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2237
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2238 2238
                         </div>
2239 2239
                         <div class='row'>
2240
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2241
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2240
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2241
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2242 2242
                         </div>
2243 2243
                     <?php } ?>
2244 2244
 
2245 2245
                     <div class='row'>
2246
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2247
-                        <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>
2246
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2247
+                        <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>
2248 2248
                     </div>
2249 2249
                 </div>
2250 2250
 
@@ -2252,22 +2252,22 @@  discard block
 block discarded – undo
2252 2252
             </div>
2253 2253
         <?php } ?>
2254 2254
 
2255
-        <?php if ( 'checkbox' == $field[ 'items_type' ] ) { ?>
2255
+        <?php if ('checkbox' == $field['items_type']) { ?>
2256 2256
 
2257 2257
             <div class="item_totals_type_checkbox">
2258 2258
 
2259 2259
                 <?php
2260
-                    foreach ( $items as $index => $item ) {
2260
+                    foreach ($items as $index => $item) {
2261 2261
 
2262
-                        if ( ! empty( $item['required'] ) ) {
2262
+                        if (!empty($item['required'])) {
2263 2263
                             continue;
2264 2264
                         }
2265 2265
 
2266
-                        $title = sanitize_text_field(  $item['title'] );
2267
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2268
-                        $item_id    = esc_attr( $id . "_$index" );
2269
-                        $value = esc_attr( $item['id'] );
2270
-                        $checked = checked( ! isset( $selected_checkbox_item ), true, false );
2266
+                        $title = sanitize_text_field($item['title']);
2267
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2268
+                        $item_id = esc_attr($id . "_$index");
2269
+                        $value = esc_attr($item['id']);
2270
+                        $checked = checked(!isset($selected_checkbox_item), true, false);
2271 2271
                         $selected_checkbox_item = 1;
2272 2272
 
2273 2273
                         echo "
@@ -2276,7 +2276,7 @@  discard block
 block discarded – undo
2276 2276
                                 <label for='$item_id' class='custom-control-label'>$title &nbsp; ($price)</label>
2277 2277
                             </div>";
2278 2278
 
2279
-                        if ( ! empty( $item['description'] ) ) {
2279
+                        if (!empty($item['description'])) {
2280 2280
                             echo "<small class='form-text text-muted'>{$item['description']}</small>";
2281 2281
                         }
2282 2282
                     }
@@ -2290,31 +2290,31 @@  discard block
 block discarded – undo
2290 2290
                         $tax       = 0;
2291 2291
                         $sub_total = 0;
2292 2292
 
2293
-                        foreach ( $items as $item ) {
2293
+                        foreach ($items as $item) {
2294 2294
 
2295 2295
                             $class  = 'col-8';
2296 2296
                             $class2 = '';
2297 2297
 
2298
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2298
+                            if (!empty($item['allow_quantities'])) {
2299 2299
                                 $class = 'col-6 pt-2';
2300 2300
                                 $class2 = 'pt-2';
2301 2301
                             }
2302 2302
 
2303
-                            if ( ! empty( $item['custom_price'] ) ) {
2303
+                            if (!empty($item['custom_price'])) {
2304 2304
                                 $class .= ' pt-2';
2305 2305
                             }
2306 2306
 
2307 2307
                             $class3 = 'd-none';
2308
-                            $name  = '';
2309
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_checkbox_item ) ) {
2308
+                            $name = '';
2309
+                            if (!empty($item['required']) || !isset($totals_selected_checkbox_item)) {
2310 2310
 
2311
-                                $amount = floatval( $item['price'] );
2312
-                                if ( wpinv_use_taxes() ) {
2311
+                                $amount = floatval($item['price']);
2312
+                                if (wpinv_use_taxes()) {
2313 2313
 
2314
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2314
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2315 2315
 
2316
-                                    if ( wpinv_prices_include_tax() ) {
2317
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2316
+                                    if (wpinv_prices_include_tax()) {
2317
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2318 2318
                                         $item_tax = $amount - $pre_tax;
2319 2319
                                     } else {
2320 2320
                                         $pre_tax  = $amount;
@@ -2326,13 +2326,13 @@  discard block
 block discarded – undo
2326 2326
                                     $total     = $sub_total + $tax;
2327 2327
 
2328 2328
                                 } else {
2329
-                                    $total  = $total + $amount;
2329
+                                    $total = $total + $amount;
2330 2330
                                 }
2331 2331
 
2332 2332
                                 $class3 = '';
2333
-                                $name  = "wpinv-items[{$item['id']}]";
2333
+                                $name = "wpinv-items[{$item['id']}]";
2334 2334
 
2335
-                                if ( empty( $item['required'] ) ) {
2335
+                                if (empty($item['required'])) {
2336 2336
                                     $totals_selected_checkbox_item = 1;
2337 2337
                                 }
2338 2338
 
@@ -2344,9 +2344,9 @@  discard block
 block discarded – undo
2344 2344
 
2345 2345
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2346 2346
                         <div class='row pl-2 pr-2 pt-2'>
2347
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2347
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2348 2348
 
2349
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2349
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2350 2350
 
2351 2351
                                 <div class='col-2'>
2352 2352
                                     <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>
@@ -2354,11 +2354,11 @@  discard block
 block discarded – undo
2354 2354
 
2355 2355
                             <?php } else { ?>
2356 2356
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2357
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2357
+                            <?php } if (empty($item['custom_price'])) { ?>
2358 2358
 
2359 2359
                                 <div class='col-4 <?php echo $class2; ?>'>
2360
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2361
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2360
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2361
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2362 2362
                                 </div>
2363 2363
 
2364 2364
                             <?php } else {?>
@@ -2366,15 +2366,15 @@  discard block
 block discarded – undo
2366 2366
                                 <div class='col-4'>
2367 2367
                                     <div class='input-group'>
2368 2368
 
2369
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2369
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2370 2370
                                             <div class='input-group-prepend'>
2371 2371
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2372 2372
                                             </div>
2373 2373
                                         <?php } ?>
2374 2374
 
2375
-                                        <input type='text' 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'] ); ?>'>
2375
+                                        <input type='text' 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']); ?>'>
2376 2376
                                     
2377
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2377
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2378 2378
                                             <div class='input-group-append'>
2379 2379
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2380 2380
                                             </div>
@@ -2385,35 +2385,35 @@  discard block
 block discarded – undo
2385 2385
                             <?php } ?>
2386 2386
 
2387 2387
                         </div>
2388
-                        <?php if ( ! empty( $item['description'] )) { ?>
2389
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2388
+                        <?php if (!empty($item['description'])) { ?>
2389
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2390 2390
                         <?php } ?>
2391 2391
                     </div>
2392 2392
                 <?php } ?>
2393 2393
 
2394 2394
                 <div class='mt-4 border-top item_totals_total p-2'>
2395 2395
 
2396
-                    <?php if ( wpinv_use_taxes() ) { ?>
2396
+                    <?php if (wpinv_use_taxes()) { ?>
2397 2397
                         <div class='row'>
2398
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2399
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2398
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2399
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2400 2400
                         </div>
2401 2401
                         <div class='row'>
2402
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2403
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2402
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2403
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2404 2404
                         </div>
2405 2405
                     <?php } ?>
2406 2406
 
2407 2407
                     <div class='row'>
2408
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2409
-                        <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>
2408
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2409
+                        <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>
2410 2410
                     </div>
2411 2411
                 </div>
2412 2412
             </div>
2413 2413
             </div>
2414 2414
         <?php } ?>
2415 2415
 
2416
-        <?php if ( 'select' == $field[ 'items_type' ] ) { ?>
2416
+        <?php if ('select' == $field['items_type']) { ?>
2417 2417
 
2418 2418
             <div class="item_totals_type_select">
2419 2419
 
@@ -2421,17 +2421,17 @@  discard block
 block discarded – undo
2421 2421
 
2422 2422
                     $options  = array();
2423 2423
                     $selected = '';
2424
-                    foreach ( $items as $index => $item ) {
2424
+                    foreach ($items as $index => $item) {
2425 2425
 
2426
-                        if ( ! empty( $item['required'] ) ) {
2426
+                        if (!empty($item['required'])) {
2427 2427
                             continue;
2428 2428
                         }
2429 2429
 
2430
-                        $title = sanitize_text_field(  $item['title'] );
2431
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2432
-                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2430
+                        $title = sanitize_text_field($item['title']);
2431
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2432
+                        $options[$item['id']] = "$title &nbsp; ($price)";
2433 2433
 
2434
-                        if ( ! isset( $selected_item ) ) {
2434
+                        if (!isset($selected_item)) {
2435 2435
                             $selected = $item['id'];
2436 2436
                             $selected_item = 1;
2437 2437
                         }
@@ -2442,7 +2442,7 @@  discard block
 block discarded – undo
2442 2442
                         array(
2443 2443
                                 'name'        => 'payment-form-items',
2444 2444
                                 'id'          => $id,
2445
-                                'placeholder' => __( 'Select an item', 'invoicing' ),
2445
+                                'placeholder' => __('Select an item', 'invoicing'),
2446 2446
                                 'no_wrap'     => true,
2447 2447
                                 'options'     => $options,
2448 2448
                                 'class'       => 'wpi_select2 wpinv-items-select-selector',
@@ -2459,31 +2459,31 @@  discard block
 block discarded – undo
2459 2459
                         $tax       = 0;
2460 2460
                         $sub_total = 0;
2461 2461
 
2462
-                        foreach ( $items as $item ) {
2462
+                        foreach ($items as $item) {
2463 2463
 
2464 2464
                             $class  = 'col-8';
2465 2465
                             $class2 = '';
2466 2466
 
2467
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2467
+                            if (!empty($item['allow_quantities'])) {
2468 2468
                                 $class = 'col-6 pt-2';
2469 2469
                                 $class2 = 'pt-2';
2470 2470
                             }
2471 2471
 
2472
-                            if ( ! empty( $item['custom_price'] ) ) {
2472
+                            if (!empty($item['custom_price'])) {
2473 2473
                                 $class .= ' pt-2';
2474 2474
                             }
2475 2475
 
2476 2476
                             $class3 = 'd-none';
2477
-                            $name  = '';
2478
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2477
+                            $name = '';
2478
+                            if (!empty($item['required']) || !isset($totals_selected_select_item)) {
2479 2479
 
2480
-                                $amount = floatval( $item['price'] );
2481
-                                if ( wpinv_use_taxes() ) {
2480
+                                $amount = floatval($item['price']);
2481
+                                if (wpinv_use_taxes()) {
2482 2482
 
2483
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2483
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2484 2484
 
2485
-                                    if ( wpinv_prices_include_tax() ) {
2486
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2485
+                                    if (wpinv_prices_include_tax()) {
2486
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2487 2487
                                         $item_tax = $amount - $pre_tax;
2488 2488
                                     } else {
2489 2489
                                         $pre_tax  = $amount;
@@ -2495,13 +2495,13 @@  discard block
 block discarded – undo
2495 2495
                                     $total     = $sub_total + $tax;
2496 2496
 
2497 2497
                                 } else {
2498
-                                    $total  = $total + $amount;
2498
+                                    $total = $total + $amount;
2499 2499
                                 }
2500 2500
 
2501 2501
                                 $class3 = '';
2502
-                                $name  = "wpinv-items[{$item['id']}]";
2502
+                                $name = "wpinv-items[{$item['id']}]";
2503 2503
 
2504
-                                if ( empty( $item['required'] ) ) {
2504
+                                if (empty($item['required'])) {
2505 2505
                                     $totals_selected_select_item = 1;
2506 2506
                                 }
2507 2507
 
@@ -2513,9 +2513,9 @@  discard block
 block discarded – undo
2513 2513
 
2514 2514
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2515 2515
                         <div class='row pl-2 pr-2 pt-2'>
2516
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2516
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2517 2517
 
2518
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2518
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2519 2519
 
2520 2520
                                 <div class='col-2'>
2521 2521
                                     <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>
@@ -2523,11 +2523,11 @@  discard block
 block discarded – undo
2523 2523
 
2524 2524
                             <?php } else { ?>
2525 2525
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2526
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2526
+                            <?php } if (empty($item['custom_price'])) { ?>
2527 2527
 
2528 2528
                                 <div class='col-4 <?php echo $class2; ?>'>
2529
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2530
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2529
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2530
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2531 2531
                                 </div>
2532 2532
 
2533 2533
                             <?php } else {?>
@@ -2535,15 +2535,15 @@  discard block
 block discarded – undo
2535 2535
                                 <div class='col-4'>
2536 2536
                                     <div class='input-group'>
2537 2537
 
2538
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2538
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2539 2539
                                             <div class='input-group-prepend'>
2540 2540
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2541 2541
                                             </div>
2542 2542
                                         <?php } ?>
2543 2543
 
2544
-                                        <input type='text' 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'] ); ?>'>
2544
+                                        <input type='text' 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']); ?>'>
2545 2545
                                     
2546
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2546
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2547 2547
                                             <div class='input-group-append'>
2548 2548
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2549 2549
                                             </div>
@@ -2554,34 +2554,34 @@  discard block
 block discarded – undo
2554 2554
                             <?php } ?>
2555 2555
 
2556 2556
                         </div>
2557
-                        <?php if ( ! empty( $item['description'] )) { ?>
2558
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2557
+                        <?php if (!empty($item['description'])) { ?>
2558
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2559 2559
                         <?php } ?>
2560 2560
                     </div>
2561 2561
                 <?php } ?>
2562 2562
 
2563 2563
                 <div class='mt-4 border-top item_totals_total p-2'>
2564 2564
 
2565
-                    <?php if ( wpinv_use_taxes() ) { ?>
2565
+                    <?php if (wpinv_use_taxes()) { ?>
2566 2566
                         <div class='row'>
2567
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2568
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2567
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2568
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2569 2569
                         </div>
2570 2570
                         <div class='row'>
2571
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2572
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2571
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2572
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2573 2573
                         </div>
2574 2574
                     <?php } ?>
2575 2575
                     <div class='row'>
2576
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2577
-                        <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>
2576
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2577
+                        <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>
2578 2578
                     </div>
2579 2579
                 </div>
2580 2580
 
2581 2581
             </div>
2582 2582
         <?php } ?>
2583 2583
 
2584
-        <?php if ( 'multi_select' == $field[ 'items_type' ] ) { ?>
2584
+        <?php if ('multi_select' == $field['items_type']) { ?>
2585 2585
 
2586 2586
             <div class="item_totals_type_multi_select">
2587 2587
 
@@ -2590,18 +2590,18 @@  discard block
 block discarded – undo
2590 2590
                     $options  = array();
2591 2591
                     $selected = array();
2592 2592
 
2593
-                    foreach ( $items as $index => $item ) {
2593
+                    foreach ($items as $index => $item) {
2594 2594
 
2595
-                        if ( ! empty( $item['required'] ) ) {
2595
+                        if (!empty($item['required'])) {
2596 2596
                             continue;
2597 2597
                         }
2598 2598
 
2599
-                        $title = sanitize_text_field(  $item['title'] );
2600
-                        $price = wpinv_price( wpinv_format_amount( (float) sanitize_text_field(  $item['price'] ) ) );
2601
-                        $options[ $item['id'] ] = "$title &nbsp; ($price)";
2599
+                        $title = sanitize_text_field($item['title']);
2600
+                        $price = wpinv_price(wpinv_format_amount((float) sanitize_text_field($item['price'])));
2601
+                        $options[$item['id']] = "$title &nbsp; ($price)";
2602 2602
 
2603
-                        if ( ! isset( $selected_item ) ) {
2604
-                            $selected = array( $item['id'] );
2603
+                        if (!isset($selected_item)) {
2604
+                            $selected = array($item['id']);
2605 2605
                             $selected_item = 1;
2606 2606
                         }
2607 2607
 
@@ -2628,31 +2628,31 @@  discard block
 block discarded – undo
2628 2628
                         $tax       = 0;
2629 2629
                         $sub_total = 0;
2630 2630
 
2631
-                        foreach ( $items as $item ) {
2631
+                        foreach ($items as $item) {
2632 2632
 
2633 2633
                             $class  = 'col-8';
2634 2634
                             $class2 = '';
2635 2635
 
2636
-                            if ( ! empty( $item['allow_quantities'] ) ) {
2636
+                            if (!empty($item['allow_quantities'])) {
2637 2637
                                 $class = 'col-6 pt-2';
2638 2638
                                 $class2 = 'pt-2';
2639 2639
                             }
2640 2640
 
2641
-                            if ( ! empty( $item['custom_price'] ) ) {
2641
+                            if (!empty($item['custom_price'])) {
2642 2642
                                 $class .= ' pt-2';
2643 2643
                             }
2644 2644
 
2645 2645
                             $class3 = 'd-none';
2646
-                            $name  = '';
2647
-                            if ( ! empty( $item['required'] ) || ! isset( $totals_selected_select_item ) ) {
2646
+                            $name = '';
2647
+                            if (!empty($item['required']) || !isset($totals_selected_select_item)) {
2648 2648
 
2649
-                                $amount = floatval( $item['price'] );
2650
-                                if ( wpinv_use_taxes() ) {
2649
+                                $amount = floatval($item['price']);
2650
+                                if (wpinv_use_taxes()) {
2651 2651
 
2652
-                                    $rate = wpinv_get_tax_rate( wpinv_get_default_country(), false, (int) $item['id'] );
2652
+                                    $rate = wpinv_get_tax_rate(wpinv_get_default_country(), false, (int) $item['id']);
2653 2653
 
2654
-                                    if ( wpinv_prices_include_tax() ) {
2655
-                                        $pre_tax  = ( $amount - $amount * $rate * 0.01 );
2654
+                                    if (wpinv_prices_include_tax()) {
2655
+                                        $pre_tax  = ($amount - $amount * $rate * 0.01);
2656 2656
                                         $item_tax = $amount - $pre_tax;
2657 2657
                                     } else {
2658 2658
                                         $pre_tax  = $amount;
@@ -2664,13 +2664,13 @@  discard block
 block discarded – undo
2664 2664
                                     $total     = $sub_total + $tax;
2665 2665
 
2666 2666
                                 } else {
2667
-                                    $total  = $total + $amount;
2667
+                                    $total = $total + $amount;
2668 2668
                                 }
2669 2669
 
2670 2670
                                 $class3 = '';
2671
-                                $name  = "wpinv-items[{$item['id']}]";
2671
+                                $name = "wpinv-items[{$item['id']}]";
2672 2672
 
2673
-                                if ( empty( $item['required'] ) ) {
2673
+                                if (empty($item['required'])) {
2674 2674
                                     $totals_selected_select_item = 1;
2675 2675
                                 }
2676 2676
 
@@ -2682,9 +2682,9 @@  discard block
 block discarded – undo
2682 2682
 
2683 2683
                     <div  class="item_totals_item <?php echo $class3; ?>" data-id="<?php echo (int) $item['id']; ?>">
2684 2684
                         <div class='row pl-2 pr-2 pt-2'>
2685
-                            <div class='<?php echo $class; ?>'><?php echo esc_html( $item['title'] ) ?></div>
2685
+                            <div class='<?php echo $class; ?>'><?php echo esc_html($item['title']) ?></div>
2686 2686
 
2687
-                            <?php  if ( ! empty( $item['allow_quantities'] ) ) { ?>
2687
+                            <?php  if (!empty($item['allow_quantities'])) { ?>
2688 2688
 
2689 2689
                                 <div class='col-2'>
2690 2690
                                     <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>
@@ -2692,11 +2692,11 @@  discard block
 block discarded – undo
2692 2692
 
2693 2693
                             <?php } else { ?>
2694 2694
                                 <input type='hidden' class='wpinv-item-quantity-input' value='1'>
2695
-                            <?php } if ( empty( $item['custom_price'] ) ) { ?>
2695
+                            <?php } if (empty($item['custom_price'])) { ?>
2696 2696
 
2697 2697
                                 <div class='col-4 <?php echo $class2; ?>'>
2698
-                                    <?php echo wpinv_price( wpinv_format_amount( $item['price'] ) ) ?>
2699
-                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval( $item['price'] ); ?>'>
2698
+                                    <?php echo wpinv_price(wpinv_format_amount($item['price'])) ?>
2699
+                                    <input name='<?php echo $name; ?>' type='hidden' class='wpinv-item-price-input' value='<?php echo floatval($item['price']); ?>'>
2700 2700
                                 </div>
2701 2701
 
2702 2702
                             <?php } else {?>
@@ -2704,15 +2704,15 @@  discard block
 block discarded – undo
2704 2704
                                 <div class='col-4'>
2705 2705
                                     <div class='input-group'>
2706 2706
 
2707
-                                        <?php if ( 'left' == wpinv_currency_position() ) { ?>
2707
+                                        <?php if ('left' == wpinv_currency_position()) { ?>
2708 2708
                                             <div class='input-group-prepend'>
2709 2709
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2710 2710
                                             </div>
2711 2711
                                         <?php } ?>
2712 2712
 
2713
-                                        <input type='text' 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'] ); ?>'>
2713
+                                        <input type='text' 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']); ?>'>
2714 2714
                                     
2715
-                                        <?php if ( 'left' != wpinv_currency_position() ) { ?>
2715
+                                        <?php if ('left' != wpinv_currency_position()) { ?>
2716 2716
                                             <div class='input-group-append'>
2717 2717
                                                 <span class='input-group-text'><?php echo wpinv_currency_symbol(); ?></span>
2718 2718
                                             </div>
@@ -2723,35 +2723,35 @@  discard block
 block discarded – undo
2723 2723
                             <?php } ?>
2724 2724
 
2725 2725
                         </div>
2726
-                        <?php if ( ! empty( $item['description'] )) { ?>
2727
-                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post( $item['description'] ); ?></small>
2726
+                        <?php if (!empty($item['description'])) { ?>
2727
+                            <small class='form-text text-muted pl-2 pr-2 m-0'><?php echo wp_kses_post($item['description']); ?></small>
2728 2728
                         <?php } ?>
2729 2729
                     </div>
2730 2730
                 <?php } ?>
2731 2731
 
2732 2732
                 <div class='mt-4 border-top item_totals_total p-2'>
2733 2733
 
2734
-                    <?php if ( wpinv_use_taxes() ) { ?>
2734
+                    <?php if (wpinv_use_taxes()) { ?>
2735 2735
                         <div class='row'>
2736
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Sub Total', 'invoicing' ); ?></strong></div>
2737
-                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price( wpinv_format_amount( $sub_total ) ) ?></strong></div>
2736
+                            <div class='col-8'><strong class='mr-5'><?php _e('Sub Total', 'invoicing'); ?></strong></div>
2737
+                            <div class='col-4'><strong class='wpinv-items-sub-total'><?php echo wpinv_price(wpinv_format_amount($sub_total)) ?></strong></div>
2738 2738
                         </div>
2739 2739
                         <div class='row'>
2740
-                            <div class='col-8'><strong class='mr-5'><?php _e( 'Tax', 'invoicing' ); ?></strong></div>
2741
-                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price( wpinv_format_amount( $tax ) ) ?></strong></div>
2740
+                            <div class='col-8'><strong class='mr-5'><?php _e('Tax', 'invoicing'); ?></strong></div>
2741
+                            <div class='col-4'><strong class='wpinv-items-tax' ><?php echo wpinv_price(wpinv_format_amount($tax)) ?></strong></div>
2742 2742
                         </div>
2743 2743
                     <?php } ?>
2744 2744
 
2745 2745
                     <div class='row'>
2746
-                        <div class='col-8'><strong class='mr-5'><?php _e( 'Total', 'invoicing' ); ?></strong></div>
2747
-                        <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>
2746
+                        <div class='col-8'><strong class='mr-5'><?php _e('Total', 'invoicing'); ?></strong></div>
2747
+                        <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>
2748 2748
                     </div>
2749 2749
                 </div>
2750 2750
 
2751 2751
             </div>
2752 2752
         <?php } ?>
2753
-        <?php if ( ! empty( $field[ 'description' ] ) ) { ?>
2754
-            <small class='form-text text-muted'><?php echo wp_kses_post( $field[ 'description' ] ); ?></small>
2753
+        <?php if (!empty($field['description'])) { ?>
2754
+            <small class='form-text text-muted'><?php echo wp_kses_post($field['description']); ?></small>
2755 2755
         <?php } ?>
2756 2756
         </div>
2757 2757
         <?php
@@ -2760,57 +2760,57 @@  discard block
 block discarded – undo
2760 2760
     /**
2761 2761
      * Renders the items element template.
2762 2762
      */
2763
-    public function edit_items_template( $field ) {
2763
+    public function edit_items_template($field) {
2764 2764
         global $wpinv_euvat, $post;
2765 2765
 
2766
-        $restrict = $this->get_restrict_markup( $field, 'items' );
2767
-        $label    = __( 'Let customers...', 'invoicing' );
2768
-        $label2   = __( 'Available Items', 'invoicing' );
2769
-        $label3   = esc_attr__( 'Add some help text for this element', 'invoicing' );
2766
+        $restrict = $this->get_restrict_markup($field, 'items');
2767
+        $label    = __('Let customers...', 'invoicing');
2768
+        $label2   = __('Available Items', 'invoicing');
2769
+        $label3   = esc_attr__('Add some help text for this element', 'invoicing');
2770 2770
         $id       = $field . '.id + "_edit"';
2771 2771
         $id2      = $field . '.id + "_edit2"';
2772 2772
         $id3      = $field . '.id + "_edit3"';
2773 2773
         $id4      = $field . '.id + "_edit4"';
2774
-        $label4   = esc_attr__( 'This will be shown to the customer as the recommended price', 'invoicing' );
2775
-        $label5   = esc_attr__( 'Allow users to pay what they want', 'invoicing' );
2776
-        $label6   = esc_attr__( 'Enter the minimum price that a user can pay', 'invoicing' );
2777
-        $label7   = esc_attr__( 'Allow users to buy several quantities', 'invoicing' );
2778
-        $label8   = esc_attr__( 'This item is required', 'invoicing' );
2774
+        $label4   = esc_attr__('This will be shown to the customer as the recommended price', 'invoicing');
2775
+        $label5   = esc_attr__('Allow users to pay what they want', 'invoicing');
2776
+        $label6   = esc_attr__('Enter the minimum price that a user can pay', 'invoicing');
2777
+        $label7   = esc_attr__('Allow users to buy several quantities', 'invoicing');
2778
+        $label8   = esc_attr__('This item is required', 'invoicing');
2779 2779
 
2780 2780
         // Item types.
2781
-        $item_types      = apply_filters( 'wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post );
2781
+        $item_types      = apply_filters('wpinv_item_types_for_quick_add_item', wpinv_get_item_types(), $post);
2782 2782
         $item_types_html = '';
2783 2783
 
2784
-        foreach ( $item_types as $type => $_label ) {
2785
-            $type  = esc_attr( $type );
2786
-            $_label = esc_html( $_label );
2784
+        foreach ($item_types as $type => $_label) {
2785
+            $type = esc_attr($type);
2786
+            $_label = esc_html($_label);
2787 2787
             $item_types_html .= "<option value='$type'>$_label</type>";
2788 2788
         }
2789 2789
 
2790 2790
         // Taxes.
2791 2791
         $taxes = '';
2792
-        if ( $wpinv_euvat->allow_vat_rules() ) {
2792
+        if ($wpinv_euvat->allow_vat_rules()) {
2793 2793
             $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"rule\"'>";
2794
-            $taxes .= __( 'VAT rule type', 'invoicing' );
2794
+            $taxes .= __('VAT rule type', 'invoicing');
2795 2795
             $taxes .= "</label><select :id='$id + item.id + \"rule\"' class='form-control custom-select' v-model='item.rule'>";
2796 2796
 
2797
-            foreach ( $wpinv_euvat->get_rules() as $type => $_label ) {
2798
-                $type    = esc_attr( $type );
2799
-                $_label  = esc_html( $_label );
2797
+            foreach ($wpinv_euvat->get_rules() as $type => $_label) {
2798
+                $type    = esc_attr($type);
2799
+                $_label  = esc_html($_label);
2800 2800
                 $taxes  .= "<option value='$type'>$_label</type>";
2801 2801
             }
2802 2802
 
2803 2803
             $taxes .= '</select></div>';
2804 2804
         }
2805 2805
 
2806
-        if ( $wpinv_euvat->allow_vat_classes() ) {
2806
+        if ($wpinv_euvat->allow_vat_classes()) {
2807 2807
             $taxes .= "<div class='form-group'> <label :for='$id + item.id + \"class\"'>";
2808
-            $taxes .= __( 'VAT class', 'invoicing' );
2808
+            $taxes .= __('VAT class', 'invoicing');
2809 2809
             $taxes .= "</label><select :id='$id + item.id + \"class\"' class='form-control custom-select' v-model='item.class'>";
2810 2810
 
2811
-            foreach ( $wpinv_euvat->get_all_classes() as $type => $_label ) {
2812
-                $type    = esc_attr( $type );
2813
-                $_label  = esc_html( $_label );
2811
+            foreach ($wpinv_euvat->get_all_classes() as $type => $_label) {
2812
+                $type    = esc_attr($type);
2813
+                $_label  = esc_html($_label);
2814 2814
                 $taxes  .= "<option value='$type'>$_label</type>";
2815 2815
             }
2816 2816
 
@@ -2895,7 +2895,7 @@  discard block
 block discarded – undo
2895 2895
                 <div class='form-group mt-2' v-if='!is_default'>
2896 2896
 
2897 2897
                     <select class='form-control custom-select' v-model='selected_item' @change='addSelectedItem'>
2898
-                        <option value=''>"        . __( 'Add an existing item to the form', 'invoicing' ) ."</option>
2898
+                        <option value=''>" . __('Add an existing item to the form', 'invoicing') . "</option>
2899 2899
                         <option v-for='(item, index) in all_items' :value='index'>{{item.title}}</option>
2900 2900
                     </select>
2901 2901
 
@@ -2910,11 +2910,11 @@  discard block
 block discarded – undo
2910 2910
                     <label :for='$id2'>$label</label>
2911 2911
 
2912 2912
                     <select class='form-control custom-select' :id='$id2' v-model='$field.items_type'>
2913
-                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>"        . __( 'Buy all items on the list', 'invoicing' ) ."</option>
2914
-                        <option value='radio'>"        . __( 'Select a single item from the list', 'invoicing' ) ."</option>
2915
-                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>"     . __( 'Select one or more items on the list', 'invoicing' ) ."</option>
2916
-                        <option value='select'>"       . __( 'Select a single item from a dropdown', 'invoicing' ) ."</option>
2917
-                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __( 'Select a one or more items from a dropdown', 'invoicing' ) ."</option>
2913
+                        <option value='total' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Buy all items on the list', 'invoicing') . "</option>
2914
+                        <option value='radio'>"        . __('Select a single item from the list', 'invoicing') . "</option>
2915
+                        <option value='checkbox' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select one or more items on the list', 'invoicing') . "</option>
2916
+                        <option value='select'>"       . __('Select a single item from a dropdown', 'invoicing') . "</option>
2917
+                        <option value='multi_select' :disabled='canCheckoutSeveralSubscriptions($field)'>" . __('Select a one or more items from a dropdown', 'invoicing') . "</option>
2918 2918
                     </select>
2919 2919
 
2920 2920
                 </div>
@@ -2939,7 +2939,7 @@  discard block
 block discarded – undo
2939 2939
             'orderby'        => 'title',
2940 2940
             'order'          => 'ASC',
2941 2941
             'posts_per_page' => -1,
2942
-            'post_status'    => array( 'publish' ),
2942
+            'post_status'    => array('publish'),
2943 2943
             'meta_query'     => array(
2944 2944
                 array(
2945 2945
                     'key'       => '_wpinv_type',
@@ -2949,24 +2949,24 @@  discard block
 block discarded – undo
2949 2949
             )
2950 2950
         );
2951 2951
     
2952
-        $items = get_posts( apply_filters( 'wpinv_payment_form_item_dropdown_query_args', $item_args ) );
2952
+        $items = get_posts(apply_filters('wpinv_payment_form_item_dropdown_query_args', $item_args));
2953 2953
 
2954
-        if ( empty( $items ) ) {
2954
+        if (empty($items)) {
2955 2955
             return array();
2956 2956
         }
2957 2957
 
2958
-        $options    = array();
2959
-        foreach ( $items as $item ) {
2960
-            $title            = esc_html( $item->post_title );
2961
-            $title           .= wpinv_get_item_suffix( $item->ID, false );
2962
-            $id               = absint( $item->ID );
2963
-            $price            = wpinv_sanitize_amount( get_post_meta( $id, '_wpinv_price', true ) );
2964
-            $recurring        = (bool) get_post_meta( $id, '_wpinv_is_recurring', true );
2958
+        $options = array();
2959
+        foreach ($items as $item) {
2960
+            $title            = esc_html($item->post_title);
2961
+            $title           .= wpinv_get_item_suffix($item->ID, false);
2962
+            $id               = absint($item->ID);
2963
+            $price            = wpinv_sanitize_amount(get_post_meta($id, '_wpinv_price', true));
2964
+            $recurring        = (bool) get_post_meta($id, '_wpinv_is_recurring', true);
2965 2965
             $description      = $item->post_excerpt;
2966
-            $custom_price     = (bool) get_post_meta( $id, '_wpinv_dynamic_pricing', true );
2967
-            $minimum_price    = (float) get_post_meta( $id, '_minimum_price', true );
2966
+            $custom_price     = (bool) get_post_meta($id, '_wpinv_dynamic_pricing', true);
2967
+            $minimum_price    = (float) get_post_meta($id, '_minimum_price', true);
2968 2968
             $allow_quantities = false;
2969
-            $options[]        = compact( 'title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities' );
2969
+            $options[]        = compact('title', 'id', 'price', 'recurring', 'description', 'custom_price', 'minimum_price', 'allow_quantities');
2970 2970
 
2971 2971
         }
2972 2972
         return $options;
@@ -2976,44 +2976,44 @@  discard block
 block discarded – undo
2976 2976
     /**
2977 2977
      * Returns an array of items for the currently being edited form.
2978 2978
      */
2979
-    public function get_form_items( $id = false ) {
2979
+    public function get_form_items($id = false) {
2980 2980
         
2981
-        if ( empty( $id ) ) {
2982
-            return wpinv_get_data( 'sample-payment-form-items' );
2981
+        if (empty($id)) {
2982
+            return wpinv_get_data('sample-payment-form-items');
2983 2983
         }
2984 2984
         
2985
-        $form_elements = get_post_meta( $id, 'wpinv_form_items', true );
2985
+        $form_elements = get_post_meta($id, 'wpinv_form_items', true);
2986 2986
 
2987
-        if ( is_array( $form_elements ) ) {
2987
+        if (is_array($form_elements)) {
2988 2988
             return $form_elements;
2989 2989
         }
2990 2990
 
2991
-        return wpinv_get_data( 'sample-payment-form-items' );
2991
+        return wpinv_get_data('sample-payment-form-items');
2992 2992
 
2993 2993
     }
2994 2994
 
2995 2995
     /**
2996 2996
      * Converts form items for use.
2997 2997
      */
2998
-    public function convert_checkout_items( $items, $invoice ) {
2998
+    public function convert_checkout_items($items, $invoice) {
2999 2999
 
3000 3000
         $converted = array();
3001
-        foreach ( $items as $item ) {
3001
+        foreach ($items as $item) {
3002 3002
 
3003 3003
             $item_id = $item['id'];
3004
-            $_item   = new WPInv_Item( $item_id );
3004
+            $_item   = new WPInv_Item($item_id);
3005 3005
 
3006
-            if( ! $_item ) {
3006
+            if (!$_item) {
3007 3007
                 continue;
3008 3008
             }
3009 3009
 
3010 3010
             $converted[] = array(
3011
-                'title'            => esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $_item ),
3011
+                'title'            => esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($_item),
3012 3012
                 'id'               => $item['id'],
3013 3013
                 'price'            => $item['subtotal'],
3014 3014
                 'custom_price'     => $_item->get_is_dynamic_pricing(),
3015 3015
                 'recurring'        => $_item->is_recurring(),
3016
-                'description'      => apply_filters( 'wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice ),
3016
+                'description'      => apply_filters('wpinv_checkout_cart_line_item_summary', '', $item, $_item, $invoice),
3017 3017
                 'minimum_price'    => $_item->get_minimum_price(),
3018 3018
                 'allow_quantities' => false,
3019 3019
                 'quantity'         => $item['quantity'],
@@ -3027,27 +3027,27 @@  discard block
 block discarded – undo
3027 3027
     /**
3028 3028
      * Converts an array of id => quantity for use.
3029 3029
      */
3030
-    public function convert_normal_items( $items ) {
3030
+    public function convert_normal_items($items) {
3031 3031
 
3032 3032
         $converted = array();
3033
-        foreach ( $items as $item_id => $quantity ) {
3033
+        foreach ($items as $item_id => $quantity) {
3034 3034
 
3035
-            $item   = new WPInv_Item( $item_id );
3035
+            $item = new WPInv_Item($item_id);
3036 3036
 
3037
-            if( ! $item ) {
3037
+            if (!$item) {
3038 3038
                 continue;
3039 3039
             }
3040 3040
 
3041 3041
             $converted[] = array(
3042
-                'title'            => esc_html( $item->get_name() ) . wpinv_get_item_suffix( $item ),
3042
+                'title'            => esc_html($item->get_name()) . wpinv_get_item_suffix($item),
3043 3043
                 'id'               => $item_id,
3044 3044
                 'price'            => $item->get_price(),
3045 3045
                 'custom_price'     => $item->get_is_dynamic_pricing(),
3046 3046
                 'recurring'        => $item->is_recurring(),
3047 3047
                 'description'      => $item->get_summary(),
3048 3048
                 'minimum_price'    => $item->get_minimum_price(),
3049
-                'allow_quantities' => ! empty( $quantity ),
3050
-                'quantity'         => empty( $quantity ) ? 1 : $quantity,
3049
+                'allow_quantities' => !empty($quantity),
3050
+                'quantity'         => empty($quantity) ? 1 : $quantity,
3051 3051
                 'required'         => true,
3052 3052
             );
3053 3053
 
@@ -3060,28 +3060,28 @@  discard block
 block discarded – undo
3060 3060
     /**
3061 3061
      * Returns an array of elements for the currently being edited form.
3062 3062
      */
3063
-    public function get_form_elements( $id = false ) {
3063
+    public function get_form_elements($id = false) {
3064 3064
 
3065
-        if ( empty( $id ) ) {
3066
-            return wpinv_get_data( 'sample-payment-form' );
3065
+        if (empty($id)) {
3066
+            return wpinv_get_data('sample-payment-form');
3067 3067
         }
3068 3068
         
3069
-        $form_elements = get_post_meta( $id, 'wpinv_form_elements', true );
3069
+        $form_elements = get_post_meta($id, 'wpinv_form_elements', true);
3070 3070
 
3071
-        if ( is_array( $form_elements ) ) {
3071
+        if (is_array($form_elements)) {
3072 3072
             return $form_elements;
3073 3073
         }
3074 3074
 
3075
-        return wpinv_get_data( 'sample-payment-form' );
3075
+        return wpinv_get_data('sample-payment-form');
3076 3076
     }
3077 3077
 
3078 3078
     /**
3079 3079
      * Sends a redrect response to payment details.
3080 3080
      *
3081 3081
      */
3082
-    public function send_redirect_response( $url ) {
3083
-        $url = urlencode( $url );
3084
-        wp_send_json_success( $url );
3082
+    public function send_redirect_response($url) {
3083
+        $url = urlencode($url);
3084
+        wp_send_json_success($url);
3085 3085
     }
3086 3086
 
3087 3087
     /**
@@ -3092,12 +3092,12 @@  discard block
 block discarded – undo
3092 3092
 
3093 3093
         $errors = wpinv_get_errors();
3094 3094
 
3095
-        if ( ! empty( $errors ) ) {
3095
+        if (!empty($errors)) {
3096 3096
             wpinv_print_errors();
3097 3097
             exit;
3098 3098
         }
3099 3099
 
3100
-        wp_send_json_error( __( 'An error occured while processing your payment. Please try again.', 'invoicing' ) );
3100
+        wp_send_json_error(__('An error occured while processing your payment. Please try again.', 'invoicing'));
3101 3101
         exit;
3102 3102
 
3103 3103
     }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Spacing   +574 added lines, -574 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
  
3 3
 // MUST have WordPress.
4
-if ( !defined( 'WPINC' ) ) {
5
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
4
+if (!defined('WPINC')) {
5
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
6 6
 }
7 7
 
8 8
 /**
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
     /**
14 14
      * @var int the invoice ID.
15 15
      */
16
-    public $ID  = 0;
16
+    public $ID = 0;
17 17
 
18 18
     /**
19 19
      * @var string the invoice title.
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
     /**
259 259
      * @param int|WPInv_Invoice|WP_Post $invoice The invoice.
260 260
      */
261
-    public function __construct( $invoice = false ) {
261
+    public function __construct($invoice = false) {
262 262
         
263 263
         // Do we have an invoice?
264
-        if ( empty( $invoice ) ) {
264
+        if (empty($invoice)) {
265 265
             return false;
266 266
         }
267 267
 
268
-        $this->setup_invoice( $invoice );
268
+        $this->setup_invoice($invoice);
269 269
     }
270 270
 
271 271
     /**
272 272
      * Retrieves an invoice key.
273 273
      */
274
-    public function get( $key ) {
275
-        if ( method_exists( $this, 'get_' . $key ) ) {
276
-            $value = call_user_func( array( $this, 'get_' . $key ) );
274
+    public function get($key) {
275
+        if (method_exists($this, 'get_' . $key)) {
276
+            $value = call_user_func(array($this, 'get_' . $key));
277 277
         } else {
278 278
             $value = $this->$key;
279 279
         }
@@ -284,18 +284,18 @@  discard block
 block discarded – undo
284 284
      /**
285 285
      * Sets an invoice key.
286 286
      */
287
-    public function set( $key, $value ) {
288
-        $ignore = array( 'items', 'cart_details', 'fees', '_ID' );
287
+    public function set($key, $value) {
288
+        $ignore = array('items', 'cart_details', 'fees', '_ID');
289 289
 
290
-        if ( $key === 'status' ) {
290
+        if ($key === 'status') {
291 291
             $this->old_status = $this->status;
292 292
         }
293 293
 
294
-        if ( ! in_array( $key, $ignore ) ) {
295
-            $this->pending[ $key ] = $value;
294
+        if (!in_array($key, $ignore)) {
295
+            $this->pending[$key] = $value;
296 296
         }
297 297
 
298
-        if( '_ID' !== $key ) {
298
+        if ('_ID' !== $key) {
299 299
             $this->$key = $value;
300 300
         }
301 301
     }
@@ -303,9 +303,9 @@  discard block
 block discarded – undo
303 303
     /**
304 304
      * Checks if an invoice key is set.
305 305
      */
306
-    public function _isset( $name ) {
307
-        if ( property_exists( $this, $name) ) {
308
-            return false === empty( $this->$name );
306
+    public function _isset($name) {
307
+        if (property_exists($this, $name)) {
308
+            return false === empty($this->$name);
309 309
         } else {
310 310
             return null;
311 311
         }
@@ -314,66 +314,66 @@  discard block
 block discarded – undo
314 314
     /**
315 315
      * @param int|WPInv_Invoice|WP_Post $invoice The invoice.
316 316
      */
317
-    private function setup_invoice( $invoice ) {
317
+    private function setup_invoice($invoice) {
318 318
         global $wpdb;
319 319
         $this->pending = array();
320 320
 
321
-        if ( empty( $invoice ) ) {
321
+        if (empty($invoice)) {
322 322
             return false;
323 323
         }
324 324
 
325
-        if ( is_a( $invoice, 'WPInv_Invoice' ) ) {
326
-            foreach ( get_object_vars( $invoice ) as $prop => $value ) {
325
+        if (is_a($invoice, 'WPInv_Invoice')) {
326
+            foreach (get_object_vars($invoice) as $prop => $value) {
327 327
                 $this->$prop = $value;
328 328
             }
329 329
             return true;
330 330
         }
331 331
 
332 332
         // Retrieve post object.
333
-        $invoice      = get_post( $invoice );
333
+        $invoice = get_post($invoice);
334 334
 
335
-        if( ! $invoice || is_wp_error( $invoice ) ) {
335
+        if (!$invoice || is_wp_error($invoice)) {
336 336
             return false;
337 337
         }
338 338
 
339
-        if( ! ( 'wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type ) ) {
339
+        if (!('wpi_invoice' == $invoice->post_type OR 'wpi_quote' == $invoice->post_type)) {
340 340
             return false;
341 341
         }
342 342
 
343 343
         // Retrieve post data.
344 344
         $table = $wpdb->prefix . 'getpaid_invoices';
345 345
         $data  = $wpdb->get_row(
346
-            $wpdb->prepare( "SELECT * FROM $table WHERE post_id=%d", $invoice->ID )
346
+            $wpdb->prepare("SELECT * FROM $table WHERE post_id=%d", $invoice->ID)
347 347
         );
348 348
 
349
-        do_action( 'wpinv_pre_setup_invoice', $this, $invoice->ID, $data );
349
+        do_action('wpinv_pre_setup_invoice', $this, $invoice->ID, $data);
350 350
 
351 351
         // Primary Identifier
352
-        $this->ID              = absint( $invoice->ID );
352
+        $this->ID              = absint($invoice->ID);
353 353
         $this->post_type       = $invoice->post_type;
354 354
 
355 355
         $this->date            = $invoice->post_date;
356 356
         $this->status          = $invoice->post_status;
357 357
 
358
-        if ( 'future' == $this->status ) {
358
+        if ('future' == $this->status) {
359 359
             $this->status = 'publish';
360 360
         }
361 361
 
362 362
         $this->post_status     = $this->status;
363 363
         $this->parent_invoice  = $invoice->post_parent;
364
-        $this->post_name       = $this->setup_post_name( $invoice );
365
-        $this->status_nicename = $this->setup_status_nicename( $invoice->post_status );
364
+        $this->post_name       = $this->setup_post_name($invoice);
365
+        $this->status_nicename = $this->setup_status_nicename($invoice->post_status);
366 366
 
367
-        $this->user_id         = ! empty( $invoice->post_author ) ? $invoice->post_author : get_current_user_id();
368
-        $this->email           = get_the_author_meta( 'email', $this->user_id );
367
+        $this->user_id         = !empty($invoice->post_author) ? $invoice->post_author : get_current_user_id();
368
+        $this->email           = get_the_author_meta('email', $this->user_id);
369 369
         $this->currency        = wpinv_get_currency();
370
-        $this->setup_invoice_data( $data );
370
+        $this->setup_invoice_data($data);
371 371
 
372 372
         // Other Identifiers
373
-        $this->title           = ! empty( $invoice->post_title ) ? $invoice->post_title : $this->number;
373
+        $this->title = !empty($invoice->post_title) ? $invoice->post_title : $this->number;
374 374
 
375 375
         // Allow extensions to add items to this object via hook
376
-        do_action( 'wpinv_setup_invoice', $this, $invoice->ID, $data );
376
+        do_action('wpinv_setup_invoice', $this, $invoice->ID, $data);
377 377
 
378 378
         return true;
379 379
     }
@@ -381,16 +381,16 @@  discard block
 block discarded – undo
381 381
     /**
382 382
      * @param stdClass $data The invoice data.
383 383
      */
384
-    private function setup_invoice_data( $data ) {
384
+    private function setup_invoice_data($data) {
385 385
 
386
-        if ( empty( $data ) ) {
387
-            $this->number = $this->setup_invoice_number( $data );
386
+        if (empty($data)) {
387
+            $this->number = $this->setup_invoice_number($data);
388 388
             return;
389 389
         }
390 390
 
391
-        $data = map_deep( $data, 'maybe_unserialize' );
391
+        $data = map_deep($data, 'maybe_unserialize');
392 392
 
393
-        $this->payment_meta    = is_array( $data->custom_meta ) ? $data->custom_meta : array();
393
+        $this->payment_meta    = is_array($data->custom_meta) ? $data->custom_meta : array();
394 394
         $this->due_date        = $data->due_date;
395 395
         $this->completed_date  = $data->completed_date;
396 396
         $this->mode            = $data->mode;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
         // Items
399 399
         $this->fees            = $this->setup_fees();
400 400
         $this->cart_details    = $this->setup_cart_details();
401
-        $this->items           = ! empty( $this->payment_meta['items'] ) ? $this->payment_meta['items'] : array();
401
+        $this->items           = !empty($this->payment_meta['items']) ? $this->payment_meta['items'] : array();
402 402
 
403 403
         // Currency Based
404 404
         $this->total           = $data->total;
@@ -406,7 +406,7 @@  discard block
 block discarded – undo
406 406
         $this->tax             = $data->tax;
407 407
         $this->fees_total      = $data->fees_total;
408 408
         $this->subtotal        = $data->subtotal;
409
-        $this->currency        = empty( $data->currency ) ? wpinv_get_currency() : $data->currency ;
409
+        $this->currency        = empty($data->currency) ? wpinv_get_currency() : $data->currency;
410 410
 
411 411
         // Gateway based
412 412
         $this->gateway         = $data->gateway;
@@ -415,30 +415,30 @@  discard block
 block discarded – undo
415 415
 
416 416
         // User based
417 417
         $this->ip              = $data->user_ip;
418
-        $this->user_info       = ! empty( $this->payment_meta['user_info'] ) ? $this->payment_meta['user_info'] : array();
418
+        $this->user_info       = !empty($this->payment_meta['user_info']) ? $this->payment_meta['user_info'] : array();
419 419
 
420 420
         $this->first_name      = $data->first_name;
421 421
         $this->last_name       = $data->last_name;
422 422
         $this->company         = $data->company;
423 423
         $this->vat_number      = $data->vat_number;
424 424
         $this->vat_rate        = $data->vat_rate;
425
-        $this->adddress_confirmed  = (int) $data->adddress_confirmed;
425
+        $this->adddress_confirmed = (int) $data->adddress_confirmed;
426 426
         $this->address         = $data->address;
427 427
         $this->city            = $data->city;
428 428
         $this->country         = $data->country;
429 429
         $this->state           = $data->state;
430 430
         $this->zip             = $data->zip;
431
-        $this->phone           = ! empty( $this->user_info['phone'] ) ? $this->user_info['phone'] : '';
431
+        $this->phone           = !empty($this->user_info['phone']) ? $this->user_info['phone'] : '';
432 432
 
433
-        $this->discounts       = ! empty( $this->user_info['discount'] ) ? $this->user_info['discount'] : '';
433
+        $this->discounts       = !empty($this->user_info['discount']) ? $this->user_info['discount'] : '';
434 434
         $this->discount        = $data->discount;
435 435
         $this->discount_code   = $data->discount_code;
436 436
 
437 437
         // Other Identifiers
438 438
         $this->key             = $data->key;
439
-        $this->number          = $this->setup_invoice_number( $data );
439
+        $this->number          = $this->setup_invoice_number($data);
440 440
 
441
-        $this->full_name       = trim( $this->first_name . ' '. $this->last_name );
441
+        $this->full_name       = trim($this->first_name . ' ' . $this->last_name);
442 442
 
443 443
 
444 444
         return true;
@@ -448,52 +448,52 @@  discard block
 block discarded – undo
448 448
     /**
449 449
      * Sets up the status nice name.
450 450
      */
451
-    private function setup_status_nicename( $status ) {
452
-        $all_invoice_statuses  = wpinv_get_invoice_statuses( true, true, $this );
451
+    private function setup_status_nicename($status) {
452
+        $all_invoice_statuses = wpinv_get_invoice_statuses(true, true, $this);
453 453
 
454
-        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
455
-            $all_invoice_statuses  = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
454
+        if ($this->is_quote() && class_exists('Wpinv_Quotes_Shared')) {
455
+            $all_invoice_statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
456 456
         }
457
-        $status   = isset( $all_invoice_statuses[$status] ) ? $all_invoice_statuses[$status] : __( $status, 'invoicing' );
457
+        $status = isset($all_invoice_statuses[$status]) ? $all_invoice_statuses[$status] : __($status, 'invoicing');
458 458
 
459
-        return apply_filters( 'setup_status_nicename', $status );
459
+        return apply_filters('setup_status_nicename', $status);
460 460
     }
461 461
 
462 462
     /**
463 463
      * Set's up the invoice number.
464 464
      */
465
-    private function setup_invoice_number( $data ) {
465
+    private function setup_invoice_number($data) {
466 466
 
467
-        if ( ! empty( $data ) && ! empty( $data->number ) ) {
467
+        if (!empty($data) && !empty($data->number)) {
468 468
             return $data->number;
469 469
         }
470 470
 
471 471
         $number = $this->ID;
472 472
 
473
-        if ( $this->status == 'auto-draft' && wpinv_sequential_number_active( $this->post_type ) ) {
474
-            $next_number = wpinv_get_next_invoice_number( $this->post_type );
473
+        if ($this->status == 'auto-draft' && wpinv_sequential_number_active($this->post_type)) {
474
+            $next_number = wpinv_get_next_invoice_number($this->post_type);
475 475
             $number      = $next_number;
476 476
         }
477 477
         
478
-        return wpinv_format_invoice_number( $number, $this->post_type );
478
+        return wpinv_format_invoice_number($number, $this->post_type);
479 479
 
480 480
     }
481 481
 
482 482
     /**
483 483
      * Invoice's post name.
484 484
      */
485
-    private function setup_post_name( $post = NULL ) {
485
+    private function setup_post_name($post = NULL) {
486 486
         global $wpdb;
487 487
         
488 488
         $post_name = '';
489 489
 
490
-        if ( !empty( $post ) ) {
491
-            if( !empty( $post->post_name ) ) {
490
+        if (!empty($post)) {
491
+            if (!empty($post->post_name)) {
492 492
                 $post_name = $post->post_name;
493
-            } else if ( !empty( $post->ID ) ) {
494
-                $post_name = wpinv_generate_post_name( $post->ID );
493
+            } else if (!empty($post->ID)) {
494
+                $post_name = wpinv_generate_post_name($post->ID);
495 495
 
496
-                $wpdb->update( $wpdb->posts, array( 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
496
+                $wpdb->update($wpdb->posts, array('post_name' => $post_name), array('ID' => $post->ID));
497 497
             }
498 498
         }
499 499
 
@@ -506,18 +506,18 @@  discard block
 block discarded – undo
506 506
     public function setup_cart_details() {
507 507
         global $wpdb;
508 508
 
509
-        $table =  $wpdb->prefix . 'getpaid_invoice_items';
509
+        $table = $wpdb->prefix . 'getpaid_invoice_items';
510 510
         $items = $wpdb->get_results(
511
-            $wpdb->prepare( "SELECT * FROM $table WHERE `post_id`=%d", $this->ID )
511
+            $wpdb->prepare("SELECT * FROM $table WHERE `post_id`=%d", $this->ID)
512 512
         );
513 513
 
514
-        if ( empty( $items ) ) {
514
+        if (empty($items)) {
515 515
             return array();
516 516
         }
517 517
 
518 518
         $details = array();
519 519
 
520
-        foreach ( $items as $item ) {
520
+        foreach ($items as $item) {
521 521
             $item = (array) $item;
522 522
             $details[] = array(
523 523
                 'name'          => $item['item_name'],
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
             );
537 537
         }
538 538
 
539
-        return map_deep( $details, 'maybe_unserialize' );
539
+        return map_deep($details, 'maybe_unserialize');
540 540
 
541 541
     }
542 542
 
@@ -544,16 +544,16 @@  discard block
 block discarded – undo
544 544
      * Convert this to an array.
545 545
      */
546 546
     public function array_convert() {
547
-        return get_object_vars( $this );
547
+        return get_object_vars($this);
548 548
     }
549 549
     
550 550
     private function setup_fees() {
551
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
551
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
552 552
         return $payment_fees;
553 553
     }
554 554
 
555 555
     private function setup_gateway_title() {
556
-        $gateway_title = wpinv_get_gateway_checkout_label( $this->gateway );
556
+        $gateway_title = wpinv_get_gateway_checkout_label($this->gateway);
557 557
         return $gateway_title;
558 558
     }
559 559
     
@@ -589,16 +589,16 @@  discard block
 block discarded – undo
589 589
             'fees'         => $this->fees,
590 590
         );
591 591
 
592
-        $this->payment_meta = array_merge( $this->payment_meta, $payment_data );
592
+        $this->payment_meta = array_merge($this->payment_meta, $payment_data);
593 593
 
594 594
     }
595 595
 
596 596
     private function insert_invoice() {
597 597
 
598
-        if ( empty( $this->post_type ) ) {
599
-            if ( !empty( $this->ID ) && $post_type = get_post_type( $this->ID ) ) {
598
+        if (empty($this->post_type)) {
599
+            if (!empty($this->ID) && $post_type = get_post_type($this->ID)) {
600 600
                 $this->post_type = $post_type;
601
-            } else if ( !empty( $this->parent_invoice ) && $post_type = get_post_type( $this->parent_invoice ) ) {
601
+            } else if (!empty($this->parent_invoice) && $post_type = get_post_type($this->parent_invoice)) {
602 602
                 $this->post_type = $post_type;
603 603
             } else {
604 604
                 $this->post_type = 'wpi_invoice';
@@ -606,16 +606,16 @@  discard block
 block discarded – undo
606 606
         }
607 607
 
608 608
         $invoice_number = $this->ID;
609
-        if ( $number = $this->number ) {
609
+        if ($number = $this->number) {
610 610
             $invoice_number = $number;
611 611
         }
612 612
 
613
-        if ( empty( $this->key ) ) {
613
+        if (empty($this->key)) {
614 614
             $this->key = self::generate_key();
615 615
             $this->pending['key'] = $this->key;
616 616
         }
617 617
 
618
-        if ( empty( $this->ip ) ) {
618
+        if (empty($this->ip)) {
619 619
             $this->ip = wpinv_get_ip();
620 620
             $this->pending['ip'] = $this->ip;
621 621
         }
@@ -652,34 +652,34 @@  discard block
 block discarded – undo
652 652
             'post_status'   => $this->status,
653 653
             'post_author'   => $this->user_id,
654 654
             'post_type'     => $this->post_type,
655
-            'post_date'     => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time( 'mysql' ),
656
-            'post_date_gmt' => ! empty( $this->date ) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date( $this->date ) : current_time( 'mysql', 1 ),
655
+            'post_date'     => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? $this->date : current_time('mysql'),
656
+            'post_date_gmt' => !empty($this->date) && $this->date != '0000-00-00 00:00:00' ? get_gmt_from_date($this->date) : current_time('mysql', 1),
657 657
             'post_parent'   => $this->parent_invoice,
658 658
         );
659
-        $args = apply_filters( 'wpinv_insert_invoice_args', $post_data, $this );
659
+        $args = apply_filters('wpinv_insert_invoice_args', $post_data, $this);
660 660
 
661 661
         // Create a blank invoice
662
-        if ( !empty( $this->ID ) ) {
663
-            $args['ID']         = $this->ID;
664
-            $invoice_id = wp_update_post( $args, true );
662
+        if (!empty($this->ID)) {
663
+            $args['ID'] = $this->ID;
664
+            $invoice_id = wp_update_post($args, true);
665 665
         } else {
666
-            $invoice_id = wp_insert_post( $args, true );
666
+            $invoice_id = wp_insert_post($args, true);
667 667
         }
668 668
 
669
-        if ( is_wp_error( $invoice_id ) ) {
669
+        if (is_wp_error($invoice_id)) {
670 670
             return false;
671 671
         }
672 672
 
673
-        if ( ! empty( $invoice_id ) ) {
673
+        if (!empty($invoice_id)) {
674 674
             $this->ID  = $invoice_id;
675 675
             $this->_ID = $invoice_id;
676 676
 
677
-            $this->payment_meta = array_merge( $this->payment_meta, $payment_data );
677
+            $this->payment_meta = array_merge($this->payment_meta, $payment_data);
678 678
 
679
-            if ( ! empty( $this->payment_meta['fees'] ) ) {
680
-                $this->fees = array_merge( $this->fees, $this->payment_meta['fees'] );
681
-                foreach( $this->fees as $fee ) {
682
-                    $this->increase_fees( $fee['amount'] );
679
+            if (!empty($this->payment_meta['fees'])) {
680
+                $this->fees = array_merge($this->fees, $this->payment_meta['fees']);
681
+                foreach ($this->fees as $fee) {
682
+                    $this->increase_fees($fee['amount']);
683 683
                 }
684 684
             }
685 685
 
@@ -695,11 +695,11 @@  discard block
 block discarded – undo
695 695
      */
696 696
     public function get_special_fields() {
697 697
 
698
-        return array (
698
+        return array(
699 699
             'post_id'        => $this->ID,
700 700
             'number'         => $this->get_number(),
701 701
             'key'            => $this->get_key(),
702
-            'type'           => str_replace( 'wpi_', '', $this->post_type ),
702
+            'type'           => str_replace('wpi_', '', $this->post_type),
703 703
             'mode'           => $this->mode,
704 704
             'user_ip'        => $this->get_ip(),
705 705
             'first_name'     => $this->get_first_name(),
@@ -739,37 +739,37 @@  discard block
 block discarded – undo
739 739
         $this->refresh_payment_data();
740 740
 
741 741
         $fields = $this->get_special_fields();
742
-        $fields = array_map( 'maybe_serialize', $fields );
742
+        $fields = array_map('maybe_serialize', $fields);
743 743
 
744
-        $table =  $wpdb->prefix . 'getpaid_invoices';
744
+        $table = $wpdb->prefix . 'getpaid_invoices';
745 745
 
746 746
         $id = (int) $this->ID;
747 747
 
748
-        if ( empty( $id ) ) {
748
+        if (empty($id)) {
749 749
             return;
750 750
         }
751 751
 
752
-        if ( $wpdb->get_var( "SELECT `post_id` FROM $table WHERE `post_id`=$id" ) ) {
752
+        if ($wpdb->get_var("SELECT `post_id` FROM $table WHERE `post_id`=$id")) {
753 753
 
754
-            $wpdb->update( $table, $fields, array( 'post_id' => $id ) );
754
+            $wpdb->update($table, $fields, array('post_id' => $id));
755 755
 
756 756
         } else {
757 757
 
758
-            $wpdb->insert( $table, $fields );
758
+            $wpdb->insert($table, $fields);
759 759
 
760 760
         }
761 761
 
762
-        $table =  $wpdb->prefix . 'getpaid_invoice_items';
763
-        $wpdb->delete( $table, array( 'post_id' => $this->ID ) );
762
+        $table = $wpdb->prefix . 'getpaid_invoice_items';
763
+        $wpdb->delete($table, array('post_id' => $this->ID));
764 764
 
765
-        foreach ( $this->get_cart_details() as $details ) {
765
+        foreach ($this->get_cart_details() as $details) {
766 766
             $fields = array(
767 767
                 'post_id'          => $this->ID,
768 768
                 'item_id'          => $details['id'],
769 769
                 'item_name'        => $details['name'],
770
-                'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
770
+                'item_description' => empty($details['meta']['description']) ? '' : $details['meta']['description'],
771 771
                 'vat_rate'         => $details['vat_rate'],
772
-                'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
772
+                'vat_class'        => empty($details['vat_class']) ? '_standard' : $details['vat_class'],
773 773
                 'tax'              => $details['tax'],
774 774
                 'item_price'       => $details['item_price'],
775 775
                 'custom_price'     => $details['custom_price'],
@@ -781,41 +781,41 @@  discard block
 block discarded – undo
781 781
                 'fees'             => $details['fees'],
782 782
             );
783 783
 
784
-            $item_columns = array_keys ( $fields );
784
+            $item_columns = array_keys($fields);
785 785
 
786
-            foreach ( $fields as $key => $val ) {
787
-                if ( is_null( $val ) ) {
786
+            foreach ($fields as $key => $val) {
787
+                if (is_null($val)) {
788 788
                     $val = '';
789 789
                 }
790
-                $val = maybe_serialize( $val );
791
-                $fields[ $key ] = $wpdb->prepare( '%s', $val );
790
+                $val = maybe_serialize($val);
791
+                $fields[$key] = $wpdb->prepare('%s', $val);
792 792
             }
793 793
 
794
-            $fields = implode( ', ', $fields );
794
+            $fields = implode(', ', $fields);
795 795
             $item_rows[] = "($fields)";
796 796
         }
797 797
 
798
-        $item_rows    = implode( ', ', $item_rows );
799
-        $item_columns = implode( ', ', $item_columns );
800
-        $wpdb->query( "INSERT INTO $table ($item_columns) VALUES $item_rows" );
798
+        $item_rows    = implode(', ', $item_rows);
799
+        $item_columns = implode(', ', $item_columns);
800
+        $wpdb->query("INSERT INTO $table ($item_columns) VALUES $item_rows");
801 801
     }
802 802
 
803
-    public function save( $setup = false ) {
803
+    public function save($setup = false) {
804 804
         global $wpi_session;
805 805
         
806 806
         $saved = false;
807
-        if ( empty( $this->items ) ) {
807
+        if (empty($this->items)) {
808 808
             return $saved;
809 809
         }
810 810
 
811
-        if ( empty( $this->key ) ) {
811
+        if (empty($this->key)) {
812 812
             $this->key = self::generate_key();
813 813
         }
814 814
 
815
-        if ( empty( $this->ID ) ) {
815
+        if (empty($this->ID)) {
816 816
             $invoice_id = $this->insert_invoice();
817 817
 
818
-            if ( false === $invoice_id ) {
818
+            if (false === $invoice_id) {
819 819
                 $saved = false;
820 820
             } else {
821 821
                 $this->ID = $invoice_id;
@@ -823,28 +823,28 @@  discard block
 block discarded – undo
823 823
         }
824 824
 
825 825
         // If we have something pending, let's save it
826
-        if ( ! empty( $this->pending ) ) {
826
+        if (!empty($this->pending)) {
827 827
             $total_increase = 0;
828 828
             $total_decrease = 0;
829 829
 
830
-            foreach ( $this->pending as $key => $value ) {
830
+            foreach ($this->pending as $key => $value) {
831 831
 
832
-                switch( $key ) {
832
+                switch ($key) {
833 833
                     case 'items':
834 834
                         // Update totals for pending items
835
-                        foreach ( $this->pending[ $key ] as $item ) {
836
-                            switch( $item['action'] ) {
835
+                        foreach ($this->pending[$key] as $item) {
836
+                            switch ($item['action']) {
837 837
                                 case 'add':
838 838
                                     $price = $item['price'];
839 839
                                     $taxes = $item['tax'];
840 840
 
841
-                                    if ( 'publish' === $this->status ) {
841
+                                    if ('publish' === $this->status) {
842 842
                                         $total_increase += $price;
843 843
                                     }
844 844
                                     break;
845 845
 
846 846
                                 case 'remove':
847
-                                    if ( 'publish' === $this->status ) {
847
+                                    if ('publish' === $this->status) {
848 848
                                         $total_decrease += $item['price'];
849 849
                                     }
850 850
                                     break;
@@ -852,16 +852,16 @@  discard block
 block discarded – undo
852 852
                         }
853 853
                         break;
854 854
                     case 'fees':
855
-                        if ( 'publish' !== $this->status ) {
855
+                        if ('publish' !== $this->status) {
856 856
                             break;
857 857
                         }
858 858
 
859
-                        if ( empty( $this->pending[ $key ] ) ) {
859
+                        if (empty($this->pending[$key])) {
860 860
                             break;
861 861
                         }
862 862
 
863
-                        foreach ( $this->pending[ $key ] as $fee ) {
864
-                            switch( $fee['action'] ) {
863
+                        foreach ($this->pending[$key] as $fee) {
864
+                            switch ($fee['action']) {
865 865
                                 case 'add':
866 866
                                     $total_increase += $fee['amount'];
867 867
                                     break;
@@ -873,7 +873,7 @@  discard block
 block discarded – undo
873 873
                         }
874 874
                         break;
875 875
                     case 'status':
876
-                        $this->update_status( $this->status );
876
+                        $this->update_status($this->status);
877 877
                         break;
878 878
                     case 'first_name':
879 879
                         $this->user_info['first_name'] = $this->first_name;
@@ -905,12 +905,12 @@  discard block
 block discarded – undo
905 905
                     case 'vat_number':
906 906
                         $this->user_info['vat_number'] = $this->vat_number;
907 907
                         
908
-                        $vat_info = $wpi_session->get( 'user_vat_data' );
909
-                        if ( $this->vat_number && !empty( $vat_info ) && isset( $vat_info['number'] ) && isset( $vat_info['valid'] ) && $vat_info['number'] == $this->vat_number ) {
910
-                            $adddress_confirmed = isset( $vat_info['adddress_confirmed'] ) ? $vat_info['adddress_confirmed'] : false;
911
-                            $this->update_meta( '_wpinv_adddress_confirmed', (bool)$adddress_confirmed );
912
-                            $this->user_info['adddress_confirmed'] = (bool)$adddress_confirmed;
913
-                            $this->adddress_confirmed = (bool)$adddress_confirmed;
908
+                        $vat_info = $wpi_session->get('user_vat_data');
909
+                        if ($this->vat_number && !empty($vat_info) && isset($vat_info['number']) && isset($vat_info['valid']) && $vat_info['number'] == $this->vat_number) {
910
+                            $adddress_confirmed = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
911
+                            $this->update_meta('_wpinv_adddress_confirmed', (bool) $adddress_confirmed);
912
+                            $this->user_info['adddress_confirmed'] = (bool) $adddress_confirmed;
913
+                            $this->adddress_confirmed = (bool) $adddress_confirmed;
914 914
                         }
915 915
     
916 916
                         break;
@@ -927,34 +927,34 @@  discard block
 block discarded – undo
927 927
                             'edit_date' => true,
928 928
                         );
929 929
 
930
-                        wp_update_post( $args );
930
+                        wp_update_post($args);
931 931
                         break;
932 932
                     case 'due_date':
933
-                        if ( empty( $this->due_date ) ) {
933
+                        if (empty($this->due_date)) {
934 934
                             $this->due_date = 'none';
935 935
                         }
936 936
                         break;
937 937
                     case 'discounts':
938
-                        if ( ! is_array( $this->discounts ) ) {
939
-                            $this->discounts = explode( ',', $this->discounts );
938
+                        if (!is_array($this->discounts)) {
939
+                            $this->discounts = explode(',', $this->discounts);
940 940
                         }
941 941
 
942
-                        $this->user_info['discount'] = implode( ',', $this->discounts );
942
+                        $this->user_info['discount'] = implode(',', $this->discounts);
943 943
                         break;
944 944
                     case 'parent_invoice':
945 945
                         $args = array(
946 946
                             'ID'          => $this->ID,
947 947
                             'post_parent' => $this->parent_invoice,
948 948
                         );
949
-                        wp_update_post( $args );
949
+                        wp_update_post($args);
950 950
                         break;
951 951
                     default:
952
-                        do_action( 'wpinv_save', $this, $key );
952
+                        do_action('wpinv_save', $this, $key);
953 953
                         break;
954 954
                 }
955 955
             }
956 956
 
957
-            $this->items    = array_values( $this->items );
957
+            $this->items = array_values($this->items);
958 958
 
959 959
             $this->pending      = array();
960 960
             $saved              = true;
@@ -967,14 +967,14 @@  discard block
 block discarded – undo
967 967
             'currency'      => $this->currency,
968 968
             'user_info'     => $this->user_info,
969 969
         );
970
-        $this->payment_meta = array_merge( $this->payment_meta, $new_meta );
970
+        $this->payment_meta = array_merge($this->payment_meta, $new_meta);
971 971
         $this->update_items();
972 972
 
973 973
         $this->save_special();
974
-        do_action( 'wpinv_invoice_save', $this, $saved );
974
+        do_action('wpinv_invoice_save', $this, $saved);
975 975
 
976
-        if ( true === $saved || $setup ) {
977
-            $this->setup_invoice( $this->ID );
976
+        if (true === $saved || $setup) {
977
+            $this->setup_invoice($this->ID);
978 978
         }
979 979
 
980 980
         $this->refresh_item_ids();
@@ -982,7 +982,7 @@  discard block
 block discarded – undo
982 982
         return $saved;
983 983
     }
984 984
     
985
-    public function add_fee( $args, $global = true ) {
985
+    public function add_fee($args, $global = true) {
986 986
         $default_args = array(
987 987
             'label'       => '',
988 988
             'amount'      => 0,
@@ -992,75 +992,75 @@  discard block
 block discarded – undo
992 992
             'item_id'     => 0,
993 993
         );
994 994
 
995
-        $fee = wp_parse_args( $args, $default_args );
995
+        $fee = wp_parse_args($args, $default_args);
996 996
         
997
-        if ( empty( $fee['label'] ) ) {
997
+        if (empty($fee['label'])) {
998 998
             return false;
999 999
         }
1000 1000
         
1001
-        $fee['id']  = sanitize_title( $fee['label'] );
1001
+        $fee['id'] = sanitize_title($fee['label']);
1002 1002
         
1003
-        $this->fees[]               = $fee;
1003
+        $this->fees[] = $fee;
1004 1004
         
1005 1005
         $added_fee               = $fee;
1006 1006
         $added_fee['action']     = 'add';
1007 1007
         $this->pending['fees'][] = $added_fee;
1008
-        reset( $this->fees );
1008
+        reset($this->fees);
1009 1009
 
1010
-        $this->increase_fees( $fee['amount'] );
1010
+        $this->increase_fees($fee['amount']);
1011 1011
         return true;
1012 1012
     }
1013 1013
 
1014
-    public function remove_fee( $key ) {
1014
+    public function remove_fee($key) {
1015 1015
         $removed = false;
1016 1016
 
1017
-        if ( is_numeric( $key ) ) {
1018
-            $removed = $this->remove_fee_by( 'index', $key );
1017
+        if (is_numeric($key)) {
1018
+            $removed = $this->remove_fee_by('index', $key);
1019 1019
         }
1020 1020
 
1021 1021
         return $removed;
1022 1022
     }
1023 1023
 
1024
-    public function remove_fee_by( $key, $value, $global = false ) {
1025
-        $allowed_fee_keys = apply_filters( 'wpinv_fee_keys', array(
1024
+    public function remove_fee_by($key, $value, $global = false) {
1025
+        $allowed_fee_keys = apply_filters('wpinv_fee_keys', array(
1026 1026
             'index', 'label', 'amount', 'type',
1027
-        ) );
1027
+        ));
1028 1028
 
1029
-        if ( ! in_array( $key, $allowed_fee_keys ) ) {
1029
+        if (!in_array($key, $allowed_fee_keys)) {
1030 1030
             return false;
1031 1031
         }
1032 1032
 
1033 1033
         $removed = false;
1034
-        if ( 'index' === $key && array_key_exists( $value, $this->fees ) ) {
1035
-            $removed_fee             = $this->fees[ $value ];
1034
+        if ('index' === $key && array_key_exists($value, $this->fees)) {
1035
+            $removed_fee             = $this->fees[$value];
1036 1036
             $removed_fee['action']   = 'remove';
1037 1037
             $this->pending['fees'][] = $removed_fee;
1038 1038
 
1039
-            $this->decrease_fees( $removed_fee['amount'] );
1039
+            $this->decrease_fees($removed_fee['amount']);
1040 1040
 
1041
-            unset( $this->fees[ $value ] );
1041
+            unset($this->fees[$value]);
1042 1042
             $removed = true;
1043
-        } else if ( 'index' !== $key ) {
1044
-            foreach ( $this->fees as $index => $fee ) {
1045
-                if ( isset( $fee[ $key ] ) && $fee[ $key ] == $value ) {
1043
+        } else if ('index' !== $key) {
1044
+            foreach ($this->fees as $index => $fee) {
1045
+                if (isset($fee[$key]) && $fee[$key] == $value) {
1046 1046
                     $removed_fee             = $fee;
1047 1047
                     $removed_fee['action']   = 'remove';
1048 1048
                     $this->pending['fees'][] = $removed_fee;
1049 1049
 
1050
-                    $this->decrease_fees( $removed_fee['amount'] );
1050
+                    $this->decrease_fees($removed_fee['amount']);
1051 1051
 
1052
-                    unset( $this->fees[ $index ] );
1052
+                    unset($this->fees[$index]);
1053 1053
                     $removed = true;
1054 1054
 
1055
-                    if ( false === $global ) {
1055
+                    if (false === $global) {
1056 1056
                         break;
1057 1057
                     }
1058 1058
                 }
1059 1059
             }
1060 1060
         }
1061 1061
 
1062
-        if ( true === $removed ) {
1063
-            $this->fees = array_values( $this->fees );
1062
+        if (true === $removed) {
1063
+            $this->fees = array_values($this->fees);
1064 1064
         }
1065 1065
 
1066 1066
         return $removed;
@@ -1068,35 +1068,35 @@  discard block
 block discarded – undo
1068 1068
 
1069 1069
     
1070 1070
 
1071
-    public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
1071
+    public function add_note($note = '', $customer_type = false, $added_by_user = false, $system = false) {
1072 1072
         // Bail if no note specified
1073
-        if( !$note ) {
1073
+        if (!$note) {
1074 1074
             return false;
1075 1075
         }
1076 1076
 
1077
-        if ( empty( $this->ID ) )
1077
+        if (empty($this->ID))
1078 1078
             return false;
1079 1079
         
1080
-        if ( ( ( is_user_logged_in() && wpinv_current_user_can_manage_invoicing() ) || $added_by_user ) && !$system ) {
1081
-            $user                 = get_user_by( 'id', get_current_user_id() );
1080
+        if (((is_user_logged_in() && wpinv_current_user_can_manage_invoicing()) || $added_by_user) && !$system) {
1081
+            $user                 = get_user_by('id', get_current_user_id());
1082 1082
             $comment_author       = $user->display_name;
1083 1083
             $comment_author_email = $user->user_email;
1084 1084
         } else {
1085 1085
             $comment_author       = 'System';
1086 1086
             $comment_author_email = 'system@';
1087
-            $comment_author_email .= isset( $_SERVER['HTTP_HOST'] ) ? str_replace( 'www.', '', $_SERVER['HTTP_HOST'] ) : 'noreply.com';
1088
-            $comment_author_email = sanitize_email( $comment_author_email );
1087
+            $comment_author_email .= isset($_SERVER['HTTP_HOST']) ? str_replace('www.', '', $_SERVER['HTTP_HOST']) : 'noreply.com';
1088
+            $comment_author_email = sanitize_email($comment_author_email);
1089 1089
         }
1090 1090
 
1091
-        do_action( 'wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type );
1091
+        do_action('wpinv_pre_insert_invoice_note', $this->ID, $note, $customer_type);
1092 1092
 
1093
-        $note_id = wp_insert_comment( wp_filter_comment( array(
1093
+        $note_id = wp_insert_comment(wp_filter_comment(array(
1094 1094
             'comment_post_ID'      => $this->ID,
1095 1095
             'comment_content'      => $note,
1096 1096
             'comment_agent'        => 'WPInvoicing',
1097 1097
             'user_id'              => is_admin() ? get_current_user_id() : 0,
1098
-            'comment_date'         => current_time( 'mysql' ),
1099
-            'comment_date_gmt'     => current_time( 'mysql', 1 ),
1098
+            'comment_date'         => current_time('mysql'),
1099
+            'comment_date_gmt'     => current_time('mysql', 1),
1100 1100
             'comment_approved'     => 1,
1101 1101
             'comment_parent'       => 0,
1102 1102
             'comment_author'       => $comment_author,
@@ -1104,53 +1104,53 @@  discard block
 block discarded – undo
1104 1104
             'comment_author_url'   => '',
1105 1105
             'comment_author_email' => $comment_author_email,
1106 1106
             'comment_type'         => 'wpinv_note'
1107
-        ) ) );
1107
+        )));
1108 1108
 
1109
-        do_action( 'wpinv_insert_payment_note', $note_id, $this->ID, $note );
1109
+        do_action('wpinv_insert_payment_note', $note_id, $this->ID, $note);
1110 1110
         
1111
-        if ( $customer_type ) {
1112
-            add_comment_meta( $note_id, '_wpi_customer_note', 1 );
1111
+        if ($customer_type) {
1112
+            add_comment_meta($note_id, '_wpi_customer_note', 1);
1113 1113
 
1114
-            do_action( 'wpinv_new_customer_note', array( 'invoice_id' => $this->ID, 'user_note' => $note ) );
1114
+            do_action('wpinv_new_customer_note', array('invoice_id' => $this->ID, 'user_note' => $note));
1115 1115
         }
1116 1116
 
1117 1117
         return $note_id;
1118 1118
     }
1119 1119
 
1120
-    private function increase_subtotal( $amount = 0.00 ) {
1120
+    private function increase_subtotal($amount = 0.00) {
1121 1121
         $amount          = (float) $amount;
1122 1122
         $this->subtotal += $amount;
1123
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1123
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1124 1124
 
1125 1125
         $this->recalculate_total();
1126 1126
     }
1127 1127
 
1128
-    private function decrease_subtotal( $amount = 0.00 ) {
1128
+    private function decrease_subtotal($amount = 0.00) {
1129 1129
         $amount          = (float) $amount;
1130 1130
         $this->subtotal -= $amount;
1131
-        $this->subtotal  = wpinv_round_amount( $this->subtotal );
1131
+        $this->subtotal  = wpinv_round_amount($this->subtotal);
1132 1132
 
1133
-        if ( $this->subtotal < 0 ) {
1133
+        if ($this->subtotal < 0) {
1134 1134
             $this->subtotal = 0;
1135 1135
         }
1136 1136
 
1137 1137
         $this->recalculate_total();
1138 1138
     }
1139 1139
 
1140
-    private function increase_fees( $amount = 0.00 ) {
1141
-        $amount            = (float)$amount;
1140
+    private function increase_fees($amount = 0.00) {
1141
+        $amount            = (float) $amount;
1142 1142
         $this->fees_total += $amount;
1143
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1143
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1144 1144
 
1145 1145
         $this->recalculate_total();
1146 1146
     }
1147 1147
 
1148
-    private function decrease_fees( $amount = 0.00 ) {
1148
+    private function decrease_fees($amount = 0.00) {
1149 1149
         $amount            = (float) $amount;
1150 1150
         $this->fees_total -= $amount;
1151
-        $this->fees_total  = wpinv_round_amount( $this->fees_total );
1151
+        $this->fees_total  = wpinv_round_amount($this->fees_total);
1152 1152
 
1153
-        if ( $this->fees_total < 0 ) {
1153
+        if ($this->fees_total < 0) {
1154 1154
             $this->fees_total = 0;
1155 1155
         }
1156 1156
 
@@ -1161,54 +1161,54 @@  discard block
 block discarded – undo
1161 1161
         global $wpi_nosave;
1162 1162
         
1163 1163
         $this->total = $this->subtotal + $this->tax + $this->fees_total;
1164
-        $this->total = wpinv_round_amount( $this->total );
1164
+        $this->total = wpinv_round_amount($this->total);
1165 1165
         
1166
-        do_action( 'wpinv_invoice_recalculate_total', $this, $wpi_nosave );
1166
+        do_action('wpinv_invoice_recalculate_total', $this, $wpi_nosave);
1167 1167
     }
1168 1168
     
1169
-    public function increase_tax( $amount = 0.00 ) {
1169
+    public function increase_tax($amount = 0.00) {
1170 1170
         $amount       = (float) $amount;
1171 1171
         $this->tax   += $amount;
1172 1172
 
1173 1173
         $this->recalculate_total();
1174 1174
     }
1175 1175
 
1176
-    public function decrease_tax( $amount = 0.00 ) {
1176
+    public function decrease_tax($amount = 0.00) {
1177 1177
         $amount     = (float) $amount;
1178 1178
         $this->tax -= $amount;
1179 1179
 
1180
-        if ( $this->tax < 0 ) {
1180
+        if ($this->tax < 0) {
1181 1181
             $this->tax = 0;
1182 1182
         }
1183 1183
 
1184 1184
         $this->recalculate_total();
1185 1185
     }
1186 1186
 
1187
-    public function update_status( $new_status = false, $note = '', $manual = false ) {
1188
-        $old_status = ! empty( $this->old_status ) ? $this->old_status : get_post_status( $this->ID );
1187
+    public function update_status($new_status = false, $note = '', $manual = false) {
1188
+        $old_status = !empty($this->old_status) ? $this->old_status : get_post_status($this->ID);
1189 1189
 
1190
-        if ( $old_status === $new_status && in_array( $new_status, array_keys( wpinv_get_invoice_statuses( true ) ) ) ) {
1190
+        if ($old_status === $new_status && in_array($new_status, array_keys(wpinv_get_invoice_statuses(true)))) {
1191 1191
             return false; // Don't permit status changes that aren't changes
1192 1192
         }
1193 1193
 
1194
-        $do_change = apply_filters( 'wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status );
1194
+        $do_change = apply_filters('wpinv_should_update_invoice_status', true, $this->ID, $new_status, $old_status);
1195 1195
         $updated = false;
1196 1196
 
1197
-        if ( $do_change ) {
1198
-            do_action( 'wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status );
1197
+        if ($do_change) {
1198
+            do_action('wpinv_before_invoice_status_change', $this->ID, $new_status, $old_status);
1199 1199
 
1200 1200
             $update_post_data                   = array();
1201 1201
             $update_post_data['ID']             = $this->ID;
1202 1202
             $update_post_data['post_status']    = $new_status;
1203
-            $update_post_data['edit_date']      = current_time( 'mysql', 0 );
1204
-            $update_post_data['edit_date_gmt']  = current_time( 'mysql', 1 );
1203
+            $update_post_data['edit_date']      = current_time('mysql', 0);
1204
+            $update_post_data['edit_date_gmt']  = current_time('mysql', 1);
1205 1205
             
1206
-            $update_post_data = apply_filters( 'wpinv_update_invoice_status_fields', $update_post_data, $this->ID );
1206
+            $update_post_data = apply_filters('wpinv_update_invoice_status_fields', $update_post_data, $this->ID);
1207 1207
 
1208
-            $updated = wp_update_post( $update_post_data );     
1208
+            $updated = wp_update_post($update_post_data);     
1209 1209
            
1210 1210
             // Process any specific status functions
1211
-            switch( $new_status ) {
1211
+            switch ($new_status) {
1212 1212
                 case 'wpi-refunded':
1213 1213
                     $this->process_refund();
1214 1214
                     break;
@@ -1221,9 +1221,9 @@  discard block
 block discarded – undo
1221 1221
             }
1222 1222
             
1223 1223
             // Status was changed.
1224
-            do_action( 'wpinv_status_' . $new_status, $this->ID, $old_status );
1225
-            do_action( 'wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status );
1226
-            do_action( 'wpinv_update_status', $this->ID, $new_status, $old_status );
1224
+            do_action('wpinv_status_' . $new_status, $this->ID, $old_status);
1225
+            do_action('wpinv_status_' . $old_status . '_to_' . $new_status, $this->ID, $old_status);
1226
+            do_action('wpinv_update_status', $this->ID, $new_status, $old_status);
1227 1227
         }
1228 1228
 
1229 1229
         return $updated;
@@ -1237,68 +1237,68 @@  discard block
 block discarded – undo
1237 1237
         $this->save();
1238 1238
     }
1239 1239
 
1240
-    public function update_meta( $meta_key = '', $meta_value = '', $prev_value = '' ) {
1241
-        if ( empty( $meta_key ) ) {
1240
+    public function update_meta($meta_key = '', $meta_value = '', $prev_value = '') {
1241
+        if (empty($meta_key)) {
1242 1242
             return false;
1243 1243
         }
1244 1244
 
1245
-        if ( $meta_key == 'key' || $meta_key == 'date' ) {
1245
+        if ($meta_key == 'key' || $meta_key == 'date') {
1246 1246
             $current_meta = $this->get_meta();
1247
-            $current_meta[ $meta_key ] = $meta_value;
1247
+            $current_meta[$meta_key] = $meta_value;
1248 1248
 
1249 1249
             $meta_key     = '_wpinv_payment_meta';
1250 1250
             $meta_value   = $current_meta;
1251 1251
         }
1252 1252
 
1253
-        $key  = str_ireplace( '_wpinv_', '', $meta_key );
1253
+        $key = str_ireplace('_wpinv_', '', $meta_key);
1254 1254
         $this->$key = $meta_value;
1255 1255
 
1256
-        $special = array_keys( $this->get_special_fields() );
1257
-        if ( in_array( $key, $special ) ) {
1256
+        $special = array_keys($this->get_special_fields());
1257
+        if (in_array($key, $special)) {
1258 1258
             $this->save_special();
1259 1259
         } else {
1260
-            $meta_value = apply_filters( 'wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID );
1260
+            $meta_value = apply_filters('wpinv_update_payment_meta_' . $meta_key, $meta_value, $this->ID);
1261 1261
         }
1262 1262
 
1263
-        return update_post_meta( $this->ID, $meta_key, $meta_value, $prev_value );
1263
+        return update_post_meta($this->ID, $meta_key, $meta_value, $prev_value);
1264 1264
     }
1265 1265
 
1266 1266
     private function process_refund() {
1267 1267
         $process_refund = true;
1268 1268
 
1269 1269
         // If the payment was not in publish, don't decrement stats as they were never incremented
1270
-        if ( 'publish' != $this->old_status || 'wpi-refunded' != $this->status ) {
1270
+        if ('publish' != $this->old_status || 'wpi-refunded' != $this->status) {
1271 1271
             $process_refund = false;
1272 1272
         }
1273 1273
 
1274 1274
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1275
-        $process_refund = apply_filters( 'wpinv_should_process_refund', $process_refund, $this );
1275
+        $process_refund = apply_filters('wpinv_should_process_refund', $process_refund, $this);
1276 1276
 
1277
-        if ( false === $process_refund ) {
1277
+        if (false === $process_refund) {
1278 1278
             return;
1279 1279
         }
1280 1280
 
1281
-        do_action( 'wpinv_pre_refund_invoice', $this );
1281
+        do_action('wpinv_pre_refund_invoice', $this);
1282 1282
         
1283
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_refund', true, $this );
1284
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_refund', true, $this );
1285
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_refund', true, $this );
1283
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_refund', true, $this);
1284
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_refund', true, $this);
1285
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_refund', true, $this);
1286 1286
         
1287
-        do_action( 'wpinv_post_refund_invoice', $this );
1287
+        do_action('wpinv_post_refund_invoice', $this);
1288 1288
     }
1289 1289
 
1290 1290
     private function process_failure() {
1291 1291
         $discounts = $this->discounts;
1292
-        if ( empty( $discounts ) ) {
1292
+        if (empty($discounts)) {
1293 1293
             return;
1294 1294
         }
1295 1295
 
1296
-        if ( ! is_array( $discounts ) ) {
1297
-            $discounts = array_map( 'trim', explode( ',', $discounts ) );
1296
+        if (!is_array($discounts)) {
1297
+            $discounts = array_map('trim', explode(',', $discounts));
1298 1298
         }
1299 1299
 
1300
-        foreach ( $discounts as $discount ) {
1301
-            wpinv_decrease_discount_usage( $discount );
1300
+        foreach ($discounts as $discount) {
1301
+            wpinv_decrease_discount_usage($discount);
1302 1302
         }
1303 1303
     }
1304 1304
     
@@ -1306,92 +1306,92 @@  discard block
 block discarded – undo
1306 1306
         $process_pending = true;
1307 1307
 
1308 1308
         // If the payment was not in publish or revoked status, don't decrement stats as they were never incremented
1309
-        if ( ( 'publish' != $this->old_status && 'revoked' != $this->old_status ) || 'wpi-pending' != $this->status ) {
1309
+        if (('publish' != $this->old_status && 'revoked' != $this->old_status) || 'wpi-pending' != $this->status) {
1310 1310
             $process_pending = false;
1311 1311
         }
1312 1312
 
1313 1313
         // Allow extensions to filter for their own payment types, Example: Recurring Payments
1314
-        $process_pending = apply_filters( 'wpinv_should_process_pending', $process_pending, $this );
1314
+        $process_pending = apply_filters('wpinv_should_process_pending', $process_pending, $this);
1315 1315
 
1316
-        if ( false === $process_pending ) {
1316
+        if (false === $process_pending) {
1317 1317
             return;
1318 1318
         }
1319 1319
 
1320
-        $decrease_store_earnings = apply_filters( 'wpinv_decrease_store_earnings_on_pending', true, $this );
1321
-        $decrease_customer_value = apply_filters( 'wpinv_decrease_customer_value_on_pending', true, $this );
1322
-        $decrease_purchase_count = apply_filters( 'wpinv_decrease_customer_purchase_count_on_pending', true, $this );
1320
+        $decrease_store_earnings = apply_filters('wpinv_decrease_store_earnings_on_pending', true, $this);
1321
+        $decrease_customer_value = apply_filters('wpinv_decrease_customer_value_on_pending', true, $this);
1322
+        $decrease_purchase_count = apply_filters('wpinv_decrease_customer_purchase_count_on_pending', true, $this);
1323 1323
 
1324 1324
         $this->completed_date = '';
1325
-        $this->update_meta( '_wpinv_completed_date', '' );
1325
+        $this->update_meta('_wpinv_completed_date', '');
1326 1326
     }
1327 1327
     
1328 1328
     // get data
1329
-    public function get_meta( $meta_key = '_wpinv_payment_meta', $single = true ) {
1330
-        $meta = get_post_meta( $this->ID, $meta_key, $single );
1329
+    public function get_meta($meta_key = '_wpinv_payment_meta', $single = true) {
1330
+        $meta = get_post_meta($this->ID, $meta_key, $single);
1331 1331
 
1332
-        if ( $meta_key === '_wpinv_payment_meta' ) {
1332
+        if ($meta_key === '_wpinv_payment_meta') {
1333 1333
 
1334
-            if(!is_array($meta)){$meta = array();} // we need this to be an array so make sure it is.
1334
+            if (!is_array($meta)) {$meta = array(); } // we need this to be an array so make sure it is.
1335 1335
 
1336
-            if ( empty( $meta['key'] ) ) {
1336
+            if (empty($meta['key'])) {
1337 1337
                 $meta['key'] = $this->key;
1338 1338
             }
1339 1339
 
1340
-            if ( empty( $meta['date'] ) ) {
1341
-                $meta['date'] = get_post_field( 'post_date', $this->ID );
1340
+            if (empty($meta['date'])) {
1341
+                $meta['date'] = get_post_field('post_date', $this->ID);
1342 1342
             }
1343 1343
         }
1344 1344
 
1345
-        $meta = apply_filters( 'wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID );
1345
+        $meta = apply_filters('wpinv_get_invoice_meta_' . $meta_key, $meta, $this->ID);
1346 1346
 
1347
-        return apply_filters( 'wpinv_get_invoice_meta', $meta, $this->ID, $meta_key );
1347
+        return apply_filters('wpinv_get_invoice_meta', $meta, $this->ID, $meta_key);
1348 1348
     }
1349 1349
     
1350 1350
     public function get_description() {
1351
-        $post = get_post( $this->ID );
1351
+        $post = get_post($this->ID);
1352 1352
         
1353
-        $description = !empty( $post ) ? $post->post_content : '';
1354
-        return apply_filters( 'wpinv_get_description', $description, $this->ID, $this );
1353
+        $description = !empty($post) ? $post->post_content : '';
1354
+        return apply_filters('wpinv_get_description', $description, $this->ID, $this);
1355 1355
     }
1356 1356
     
1357
-    public function get_status( $nicename = false ) {
1358
-        if ( !$nicename ) {
1357
+    public function get_status($nicename = false) {
1358
+        if (!$nicename) {
1359 1359
             $status = $this->status;
1360 1360
         } else {
1361 1361
             $status = $this->status_nicename;
1362 1362
         }
1363 1363
         
1364
-        return apply_filters( 'wpinv_get_status', $status, $nicename, $this->ID, $this );
1364
+        return apply_filters('wpinv_get_status', $status, $nicename, $this->ID, $this);
1365 1365
     }
1366 1366
     
1367 1367
     public function get_cart_details() {
1368
-        return apply_filters( 'wpinv_cart_details', $this->cart_details, $this->ID, $this );
1368
+        return apply_filters('wpinv_cart_details', $this->cart_details, $this->ID, $this);
1369 1369
     }
1370 1370
     
1371
-    public function get_subtotal( $currency = false ) {
1372
-        $subtotal = wpinv_round_amount( $this->subtotal );
1371
+    public function get_subtotal($currency = false) {
1372
+        $subtotal = wpinv_round_amount($this->subtotal);
1373 1373
         
1374
-        if ( $currency ) {
1375
-            $subtotal = wpinv_price( wpinv_format_amount( $subtotal, NULL, !$currency ), $this->get_currency() );
1374
+        if ($currency) {
1375
+            $subtotal = wpinv_price(wpinv_format_amount($subtotal, NULL, !$currency), $this->get_currency());
1376 1376
         }
1377 1377
         
1378
-        return apply_filters( 'wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency );
1378
+        return apply_filters('wpinv_get_invoice_subtotal', $subtotal, $this->ID, $this, $currency);
1379 1379
     }
1380 1380
     
1381
-    public function get_total( $currency = false ) {        
1382
-        if ( $this->is_free_trial() ) {
1383
-            $total = wpinv_round_amount( 0 );
1381
+    public function get_total($currency = false) {        
1382
+        if ($this->is_free_trial()) {
1383
+            $total = wpinv_round_amount(0);
1384 1384
         } else {
1385
-            $total = wpinv_round_amount( $this->total );
1385
+            $total = wpinv_round_amount($this->total);
1386 1386
         }
1387
-        if ( $currency ) {
1388
-            $total = wpinv_price( wpinv_format_amount( $total, NULL, !$currency ), $this->get_currency() );
1387
+        if ($currency) {
1388
+            $total = wpinv_price(wpinv_format_amount($total, NULL, !$currency), $this->get_currency());
1389 1389
         }
1390 1390
         
1391
-        return apply_filters( 'wpinv_get_invoice_total', $total, $this->ID, $this, $currency );
1391
+        return apply_filters('wpinv_get_invoice_total', $total, $this->ID, $this, $currency);
1392 1392
     }
1393 1393
     
1394
-    public function get_recurring_details( $field = '', $currency = false ) {        
1394
+    public function get_recurring_details($field = '', $currency = false) {        
1395 1395
         $data                 = array();
1396 1396
         $data['cart_details'] = $this->cart_details;
1397 1397
         $data['subtotal']     = $this->get_subtotal();
@@ -1399,119 +1399,119 @@  discard block
 block discarded – undo
1399 1399
         $data['tax']          = $this->get_tax();
1400 1400
         $data['total']        = $this->get_total();
1401 1401
     
1402
-        if ( !empty( $this->cart_details ) && ( $this->is_parent() || $this->is_renewal() ) ) {
1402
+        if (!empty($this->cart_details) && ($this->is_parent() || $this->is_renewal())) {
1403 1403
             $is_free_trial = $this->is_free_trial();
1404
-            $discounts = $this->get_discounts( true );
1404
+            $discounts = $this->get_discounts(true);
1405 1405
             
1406
-            if ( $is_free_trial || !empty( $discounts ) ) {
1406
+            if ($is_free_trial || !empty($discounts)) {
1407 1407
                 $first_use_only = false;
1408 1408
                 
1409
-                if ( !empty( $discounts ) ) {
1410
-                    foreach ( $discounts as $key => $code ) {
1411
-                        if ( wpinv_discount_is_recurring( $code, true ) && !$this->is_renewal() ) {
1409
+                if (!empty($discounts)) {
1410
+                    foreach ($discounts as $key => $code) {
1411
+                        if (wpinv_discount_is_recurring($code, true) && !$this->is_renewal()) {
1412 1412
                             $first_use_only = true;
1413 1413
                             break;
1414 1414
                         }
1415 1415
                     }
1416 1416
                 }
1417 1417
                     
1418
-                if ( !$first_use_only ) {
1419
-                    $data['subtotal'] = wpinv_round_amount( $this->subtotal );
1420
-                    $data['discount'] = wpinv_round_amount( $this->discount );
1421
-                    $data['tax']      = wpinv_round_amount( $this->tax );
1422
-                    $data['total']    = wpinv_round_amount( $this->total );
1418
+                if (!$first_use_only) {
1419
+                    $data['subtotal'] = wpinv_round_amount($this->subtotal);
1420
+                    $data['discount'] = wpinv_round_amount($this->discount);
1421
+                    $data['tax']      = wpinv_round_amount($this->tax);
1422
+                    $data['total']    = wpinv_round_amount($this->total);
1423 1423
                 } else {
1424 1424
                     $cart_subtotal   = 0;
1425 1425
                     $cart_discount   = $this->discount;
1426 1426
                     $cart_tax        = 0;
1427 1427
 
1428
-                    foreach ( $this->cart_details as $key => $item ) {
1429
-                        $item_quantity  = $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
1430
-                        $item_subtotal  = !empty( $item['subtotal'] ) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1428
+                    foreach ($this->cart_details as $key => $item) {
1429
+                        $item_quantity  = $item['quantity'] > 0 ? absint($item['quantity']) : 1;
1430
+                        $item_subtotal  = !empty($item['subtotal']) ? $item['subtotal'] : $item['item_price'] * $item_quantity;
1431 1431
                         $item_discount  = 0;
1432
-                        $item_tax       = $item_subtotal > 0 && !empty( $item['vat_rate'] ) ? ( $item_subtotal * 0.01 * (float)$item['vat_rate'] ) : 0;
1432
+                        $item_tax       = $item_subtotal > 0 && !empty($item['vat_rate']) ? ($item_subtotal * 0.01 * (float) $item['vat_rate']) : 0;
1433 1433
                         
1434
-                        if ( wpinv_prices_include_tax() ) {
1435
-                            $item_subtotal -= wpinv_round_amount( $item_tax );
1434
+                        if (wpinv_prices_include_tax()) {
1435
+                            $item_subtotal -= wpinv_round_amount($item_tax);
1436 1436
                         }
1437 1437
                         
1438 1438
                         $item_total     = $item_subtotal - $item_discount + $item_tax;
1439 1439
                         // Do not allow totals to go negative
1440
-                        if ( $item_total < 0 ) {
1440
+                        if ($item_total < 0) {
1441 1441
                             $item_total = 0;
1442 1442
                         }
1443 1443
                         
1444
-                        $cart_subtotal  += (float)($item_subtotal);
1445
-                        $cart_discount  += (float)($item_discount);
1446
-                        $cart_tax       += (float)($item_tax);
1444
+                        $cart_subtotal  += (float) ($item_subtotal);
1445
+                        $cart_discount  += (float) ($item_discount);
1446
+                        $cart_tax       += (float) ($item_tax);
1447 1447
                         
1448
-                        $data['cart_details'][$key]['discount']   = wpinv_round_amount( $item_discount );
1449
-                        $data['cart_details'][$key]['tax']        = wpinv_round_amount( $item_tax );
1450
-                        $data['cart_details'][$key]['price']      = wpinv_round_amount( $item_total );
1448
+                        $data['cart_details'][$key]['discount']   = wpinv_round_amount($item_discount);
1449
+                        $data['cart_details'][$key]['tax']        = wpinv_round_amount($item_tax);
1450
+                        $data['cart_details'][$key]['price']      = wpinv_round_amount($item_total);
1451 1451
                     }
1452 1452
 
1453 1453
 	                $total = $data['subtotal'] - $data['discount'] + $data['tax'];
1454
-	                if ( $total < 0 ) {
1454
+	                if ($total < 0) {
1455 1455
 		                $total = 0;
1456 1456
 	                }
1457 1457
 
1458
-                    $data['subtotal'] = wpinv_round_amount( $cart_subtotal );
1459
-                    $data['discount'] = wpinv_round_amount( $cart_discount );
1460
-                    $data['tax']      = wpinv_round_amount( $cart_tax );
1461
-                    $data['total']    = wpinv_round_amount( $total );
1458
+                    $data['subtotal'] = wpinv_round_amount($cart_subtotal);
1459
+                    $data['discount'] = wpinv_round_amount($cart_discount);
1460
+                    $data['tax']      = wpinv_round_amount($cart_tax);
1461
+                    $data['total']    = wpinv_round_amount($total);
1462 1462
                 }
1463 1463
             }
1464 1464
         }
1465 1465
         
1466
-        $data = apply_filters( 'wpinv_get_invoice_recurring_details', $data, $this, $field, $currency );
1466
+        $data = apply_filters('wpinv_get_invoice_recurring_details', $data, $this, $field, $currency);
1467 1467
 
1468
-        if ( isset( $data[$field] ) ) {
1469
-            return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
1468
+        if (isset($data[$field])) {
1469
+            return ($currency ? wpinv_price($data[$field], $this->get_currency()) : $data[$field]);
1470 1470
         }
1471 1471
         
1472 1472
         return $data;
1473 1473
     }
1474 1474
     
1475
-    public function get_final_tax( $currency = false ) {        
1476
-        $final_total = wpinv_round_amount( $this->tax );
1477
-        if ( $currency ) {
1478
-            $final_total = wpinv_price( wpinv_format_amount( $final_total, NULL, !$currency ), $this->get_currency() );
1475
+    public function get_final_tax($currency = false) {        
1476
+        $final_total = wpinv_round_amount($this->tax);
1477
+        if ($currency) {
1478
+            $final_total = wpinv_price(wpinv_format_amount($final_total, NULL, !$currency), $this->get_currency());
1479 1479
         }
1480 1480
         
1481
-        return apply_filters( 'wpinv_get_invoice_final_total', $final_total, $this, $currency );
1481
+        return apply_filters('wpinv_get_invoice_final_total', $final_total, $this, $currency);
1482 1482
     }
1483 1483
     
1484
-    public function get_discounts( $array = false ) {
1484
+    public function get_discounts($array = false) {
1485 1485
         $discounts = $this->discounts;
1486
-        if ( $array && $discounts ) {
1487
-            $discounts = explode( ',', $discounts );
1486
+        if ($array && $discounts) {
1487
+            $discounts = explode(',', $discounts);
1488 1488
         }
1489
-        return apply_filters( 'wpinv_payment_discounts', $discounts, $this->ID, $this, $array );
1489
+        return apply_filters('wpinv_payment_discounts', $discounts, $this->ID, $this, $array);
1490 1490
     }
1491 1491
     
1492
-    public function get_discount( $currency = false, $dash = false ) {
1493
-        if ( !empty( $this->discounts ) ) {
1492
+    public function get_discount($currency = false, $dash = false) {
1493
+        if (!empty($this->discounts)) {
1494 1494
             global $ajax_cart_details;
1495 1495
             $ajax_cart_details = $this->get_cart_details();
1496 1496
             
1497
-            if ( !empty( $ajax_cart_details ) && count( $ajax_cart_details ) == count( $this->items ) ) {
1497
+            if (!empty($ajax_cart_details) && count($ajax_cart_details) == count($this->items)) {
1498 1498
                 $cart_items = $ajax_cart_details;
1499 1499
             } else {
1500 1500
                 $cart_items = $this->items;
1501 1501
             }
1502 1502
 
1503
-            $this->discount = wpinv_get_cart_items_discount_amount( $cart_items , $this->discounts );
1503
+            $this->discount = wpinv_get_cart_items_discount_amount($cart_items, $this->discounts);
1504 1504
         }
1505
-        $discount   = wpinv_round_amount( $this->discount );
1505
+        $discount   = wpinv_round_amount($this->discount);
1506 1506
         $dash       = $dash && $discount > 0 ? '&ndash;' : '';
1507 1507
         
1508
-        if ( $currency ) {
1509
-            $discount = wpinv_price( wpinv_format_amount( $discount, NULL, !$currency ), $this->get_currency() );
1508
+        if ($currency) {
1509
+            $discount = wpinv_price(wpinv_format_amount($discount, NULL, !$currency), $this->get_currency());
1510 1510
         }
1511 1511
         
1512
-        $discount   = $dash . $discount;
1512
+        $discount = $dash . $discount;
1513 1513
         
1514
-        return apply_filters( 'wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash );
1514
+        return apply_filters('wpinv_get_invoice_discount', $discount, $this->ID, $this, $currency, $dash);
1515 1515
     }
1516 1516
     
1517 1517
     public function get_discount_code() {
@@ -1523,163 +1523,163 @@  discard block
 block discarded – undo
1523 1523
         return (int) $this->disable_taxes === 0;
1524 1524
     }
1525 1525
 
1526
-    public function get_tax( $currency = false ) {
1527
-        $tax = wpinv_round_amount( $this->tax );
1526
+    public function get_tax($currency = false) {
1527
+        $tax = wpinv_round_amount($this->tax);
1528 1528
 
1529
-        if ( $currency ) {
1530
-            $tax = wpinv_price( wpinv_format_amount( $tax, NULL, !$currency ), $this->get_currency() );
1529
+        if ($currency) {
1530
+            $tax = wpinv_price(wpinv_format_amount($tax, NULL, !$currency), $this->get_currency());
1531 1531
         }
1532 1532
 
1533
-        if ( ! $this->is_taxable() ) {
1534
-            $tax = wpinv_round_amount( 0.00 );
1533
+        if (!$this->is_taxable()) {
1534
+            $tax = wpinv_round_amount(0.00);
1535 1535
         }
1536 1536
 
1537
-        return apply_filters( 'wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency );
1537
+        return apply_filters('wpinv_get_invoice_tax', $tax, $this->ID, $this, $currency);
1538 1538
     }
1539 1539
     
1540
-    public function get_fees( $type = 'all' ) {
1541
-        $fees    = array();
1540
+    public function get_fees($type = 'all') {
1541
+        $fees = array();
1542 1542
 
1543
-        if ( ! empty( $this->fees ) && is_array( $this->fees ) ) {
1544
-            foreach ( $this->fees as $fee ) {
1545
-                if( 'all' != $type && ! empty( $fee['type'] ) && $type != $fee['type'] ) {
1543
+        if (!empty($this->fees) && is_array($this->fees)) {
1544
+            foreach ($this->fees as $fee) {
1545
+                if ('all' != $type && !empty($fee['type']) && $type != $fee['type']) {
1546 1546
                     continue;
1547 1547
                 }
1548 1548
 
1549
-                $fee['label'] = stripslashes( $fee['label'] );
1550
-                $fee['amount_display'] = wpinv_price( $fee['amount'], $this->get_currency() );
1551
-                $fees[]    = $fee;
1549
+                $fee['label'] = stripslashes($fee['label']);
1550
+                $fee['amount_display'] = wpinv_price($fee['amount'], $this->get_currency());
1551
+                $fees[] = $fee;
1552 1552
             }
1553 1553
         }
1554 1554
 
1555
-        return apply_filters( 'wpinv_get_invoice_fees', $fees, $this->ID, $this );
1555
+        return apply_filters('wpinv_get_invoice_fees', $fees, $this->ID, $this);
1556 1556
     }
1557 1557
     
1558
-    public function get_fees_total( $type = 'all' ) {
1558
+    public function get_fees_total($type = 'all') {
1559 1559
         $fees_total = (float) 0.00;
1560 1560
 
1561
-        $payment_fees = isset( $this->payment_meta['fees'] ) ? $this->payment_meta['fees'] : array();
1562
-        if ( ! empty( $payment_fees ) ) {
1563
-            foreach ( $payment_fees as $fee ) {
1561
+        $payment_fees = isset($this->payment_meta['fees']) ? $this->payment_meta['fees'] : array();
1562
+        if (!empty($payment_fees)) {
1563
+            foreach ($payment_fees as $fee) {
1564 1564
                 $fees_total += (float) $fee['amount'];
1565 1565
             }
1566 1566
         }
1567 1567
 
1568
-        return apply_filters( 'wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this );
1568
+        return apply_filters('wpinv_get_invoice_fees_total', $fees_total, $this->ID, $this);
1569 1569
 
1570 1570
     }
1571 1571
 
1572 1572
     public function get_user_id() {
1573
-        return apply_filters( 'wpinv_user_id', $this->user_id, $this->ID, $this );
1573
+        return apply_filters('wpinv_user_id', $this->user_id, $this->ID, $this);
1574 1574
     }
1575 1575
     
1576 1576
     public function get_first_name() {
1577
-        return apply_filters( 'wpinv_first_name', $this->first_name, $this->ID, $this );
1577
+        return apply_filters('wpinv_first_name', $this->first_name, $this->ID, $this);
1578 1578
     }
1579 1579
     
1580 1580
     public function get_last_name() {
1581
-        return apply_filters( 'wpinv_last_name', $this->last_name, $this->ID, $this );
1581
+        return apply_filters('wpinv_last_name', $this->last_name, $this->ID, $this);
1582 1582
     }
1583 1583
     
1584 1584
     public function get_user_full_name() {
1585
-        return apply_filters( 'wpinv_user_full_name', $this->full_name, $this->ID, $this );
1585
+        return apply_filters('wpinv_user_full_name', $this->full_name, $this->ID, $this);
1586 1586
     }
1587 1587
     
1588 1588
     public function get_user_info() {
1589
-        return apply_filters( 'wpinv_user_info', $this->user_info, $this->ID, $this );
1589
+        return apply_filters('wpinv_user_info', $this->user_info, $this->ID, $this);
1590 1590
     }
1591 1591
     
1592 1592
     public function get_email() {
1593
-        return apply_filters( 'wpinv_user_email', $this->email, $this->ID, $this );
1593
+        return apply_filters('wpinv_user_email', $this->email, $this->ID, $this);
1594 1594
     }
1595 1595
     
1596 1596
     public function get_address() {
1597
-        return apply_filters( 'wpinv_address', $this->address, $this->ID, $this );
1597
+        return apply_filters('wpinv_address', $this->address, $this->ID, $this);
1598 1598
     }
1599 1599
     
1600 1600
     public function get_phone() {
1601
-        return apply_filters( 'wpinv_phone', $this->phone, $this->ID, $this );
1601
+        return apply_filters('wpinv_phone', $this->phone, $this->ID, $this);
1602 1602
     }
1603 1603
     
1604 1604
     public function get_number() {
1605
-        return apply_filters( 'wpinv_number', $this->number, $this->ID, $this );
1605
+        return apply_filters('wpinv_number', $this->number, $this->ID, $this);
1606 1606
     }
1607 1607
     
1608 1608
     public function get_items() {
1609
-        return apply_filters( 'wpinv_payment_meta_items', $this->items, $this->ID, $this );
1609
+        return apply_filters('wpinv_payment_meta_items', $this->items, $this->ID, $this);
1610 1610
     }
1611 1611
     
1612 1612
     public function get_key() {
1613
-        return apply_filters( 'wpinv_key', $this->key, $this->ID, $this );
1613
+        return apply_filters('wpinv_key', $this->key, $this->ID, $this);
1614 1614
     }
1615 1615
     
1616 1616
     public function get_transaction_id() {
1617
-        return apply_filters( 'wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this );
1617
+        return apply_filters('wpinv_get_invoice_transaction_id', $this->transaction_id, $this->ID, $this);
1618 1618
     }
1619 1619
     
1620 1620
     public function get_gateway() {
1621
-        return apply_filters( 'wpinv_gateway', $this->gateway, $this->ID, $this );
1621
+        return apply_filters('wpinv_gateway', $this->gateway, $this->ID, $this);
1622 1622
     }
1623 1623
     
1624 1624
     public function get_gateway_title() {
1625
-        $this->gateway_title = !empty( $this->gateway_title ) ? $this->gateway_title : wpinv_get_gateway_checkout_label( $this->gateway );
1625
+        $this->gateway_title = !empty($this->gateway_title) ? $this->gateway_title : wpinv_get_gateway_checkout_label($this->gateway);
1626 1626
         
1627
-        return apply_filters( 'wpinv_gateway_title', $this->gateway_title, $this->ID, $this );
1627
+        return apply_filters('wpinv_gateway_title', $this->gateway_title, $this->ID, $this);
1628 1628
     }
1629 1629
     
1630 1630
     public function get_currency() {
1631
-        return apply_filters( 'wpinv_currency_code', $this->currency, $this->ID, $this );
1631
+        return apply_filters('wpinv_currency_code', $this->currency, $this->ID, $this);
1632 1632
     }
1633 1633
     
1634 1634
     public function get_created_date() {
1635
-        return apply_filters( 'wpinv_created_date', $this->date, $this->ID, $this );
1635
+        return apply_filters('wpinv_created_date', $this->date, $this->ID, $this);
1636 1636
     }
1637 1637
     
1638
-    public function get_due_date( $display = false ) {
1639
-        $due_date = apply_filters( 'wpinv_due_date', $this->due_date, $this->ID, $this );
1638
+    public function get_due_date($display = false) {
1639
+        $due_date = apply_filters('wpinv_due_date', $this->due_date, $this->ID, $this);
1640 1640
         
1641
-        if ( !$display || empty( $due_date ) ) {
1641
+        if (!$display || empty($due_date)) {
1642 1642
             return $due_date;
1643 1643
         }
1644 1644
         
1645
-        return date_i18n( get_option( 'date_format' ), strtotime( $due_date ) );
1645
+        return date_i18n(get_option('date_format'), strtotime($due_date));
1646 1646
     }
1647 1647
     
1648 1648
     public function get_completed_date() {
1649
-        return apply_filters( 'wpinv_completed_date', $this->completed_date, $this->ID, $this );
1649
+        return apply_filters('wpinv_completed_date', $this->completed_date, $this->ID, $this);
1650 1650
     }
1651 1651
     
1652
-    public function get_invoice_date( $formatted = true ) {
1652
+    public function get_invoice_date($formatted = true) {
1653 1653
         $date_completed = $this->completed_date;
1654 1654
         $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
1655 1655
         
1656
-        if ( $invoice_date == '' ) {
1656
+        if ($invoice_date == '') {
1657 1657
             $date_created   = $this->date;
1658 1658
             $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? $date_created : '';
1659 1659
         }
1660 1660
         
1661
-        if ( $formatted && $invoice_date ) {
1662
-            $invoice_date   = date_i18n( get_option( 'date_format' ), strtotime( $invoice_date ) );
1661
+        if ($formatted && $invoice_date) {
1662
+            $invoice_date = date_i18n(get_option('date_format'), strtotime($invoice_date));
1663 1663
         }
1664 1664
 
1665
-        return apply_filters( 'wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this );
1665
+        return apply_filters('wpinv_get_invoice_date', $invoice_date, $formatted, $this->ID, $this);
1666 1666
     }
1667 1667
     
1668 1668
     public function get_ip() {
1669
-        return apply_filters( 'wpinv_user_ip', $this->ip, $this->ID, $this );
1669
+        return apply_filters('wpinv_user_ip', $this->ip, $this->ID, $this);
1670 1670
     }
1671 1671
         
1672
-    public function has_status( $status ) {
1673
-        return apply_filters( 'wpinv_has_status', ( is_array( $status ) && in_array( $this->get_status(), $status ) ) || $this->get_status() === $status ? true : false, $this, $status );
1672
+    public function has_status($status) {
1673
+        return apply_filters('wpinv_has_status', (is_array($status) && in_array($this->get_status(), $status)) || $this->get_status() === $status ? true : false, $this, $status);
1674 1674
     }
1675 1675
     
1676
-    public function add_item( $item_id = 0, $args = array() ) {
1676
+    public function add_item($item_id = 0, $args = array()) {
1677 1677
         global $wpi_current_id, $wpi_item_id;
1678 1678
     
1679
-        $item = new WPInv_Item( $item_id );
1679
+        $item = new WPInv_Item($item_id);
1680 1680
 
1681 1681
         // Bail if this post isn't a item
1682
-        if( !$item || $item->post_type !== 'wpi_item' ) {
1682
+        if (!$item || $item->post_type !== 'wpi_item') {
1683 1683
             return false;
1684 1684
         }
1685 1685
         
@@ -1698,8 +1698,8 @@  discard block
 block discarded – undo
1698 1698
             'fees'          => array()
1699 1699
         );
1700 1700
 
1701
-        $args = wp_parse_args( apply_filters( 'wpinv_add_item_args', $args, $item->ID ), $defaults );
1702
-        $args['quantity']   = $has_quantities && $args['quantity'] > 0 ? absint( $args['quantity'] ) : 1;
1701
+        $args = wp_parse_args(apply_filters('wpinv_add_item_args', $args, $item->ID), $defaults);
1702
+        $args['quantity'] = $has_quantities && $args['quantity'] > 0 ? absint($args['quantity']) : 1;
1703 1703
 
1704 1704
         $wpi_current_id         = $this->ID;
1705 1705
         $wpi_item_id            = $item->ID;
@@ -1711,19 +1711,19 @@  discard block
 block discarded – undo
1711 1711
         $found_cart_key         = false;
1712 1712
         
1713 1713
         if ($has_quantities) {
1714
-            $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1714
+            $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1715 1715
             
1716
-            foreach ( $this->items as $key => $cart_item ) {
1717
-                if ( (int)$item_id !== (int)$cart_item['id'] ) {
1716
+            foreach ($this->items as $key => $cart_item) {
1717
+                if ((int) $item_id !== (int) $cart_item['id']) {
1718 1718
                     continue;
1719 1719
                 }
1720 1720
 
1721
-                $this->items[ $key ]['quantity'] += $args['quantity'];
1721
+                $this->items[$key]['quantity'] += $args['quantity'];
1722 1722
                 break;
1723 1723
             }
1724 1724
             
1725
-            foreach ( $this->cart_details as $cart_key => $cart_item ) {
1726
-                if ( $item_id != $cart_item['id'] ) {
1725
+            foreach ($this->cart_details as $cart_key => $cart_item) {
1726
+                if ($item_id != $cart_item['id']) {
1727 1727
                     continue;
1728 1728
                 }
1729 1729
 
@@ -1735,29 +1735,29 @@  discard block
 block discarded – undo
1735 1735
         if ($has_quantities && $found_cart_key !== false) {
1736 1736
             $cart_item          = $this->cart_details[$found_cart_key];
1737 1737
             $item_price         = $cart_item['item_price'];
1738
-            $quantity           = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1739
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1738
+            $quantity           = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1739
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1740 1740
             
1741 1741
             $new_quantity       = $quantity + $args['quantity'];
1742 1742
             $subtotal           = $item_price * $new_quantity;
1743 1743
             
1744 1744
             $args['quantity']   = $new_quantity;
1745
-            $discount           = !empty( $args['discount'] ) ? $args['discount'] : 0;
1746
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1745
+            $discount           = !empty($args['discount']) ? $args['discount'] : 0;
1746
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1747 1747
             
1748
-            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float)$cart_item['discount'] ? $discount - (float)$cart_item['discount'] : 0;
1749
-            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float)$cart_item['tax'] ? $tax - (float)$cart_item['tax'] : 0;
1748
+            $discount_increased = $discount > 0 && $subtotal > 0 && $discount > (float) $cart_item['discount'] ? $discount - (float) $cart_item['discount'] : 0;
1749
+            $tax_increased      = $tax > 0 && $subtotal > 0 && $tax > (float) $cart_item['tax'] ? $tax - (float) $cart_item['tax'] : 0;
1750 1750
             // The total increase equals the number removed * the item_price
1751
-            $total_increased    = wpinv_round_amount( $item_price );
1751
+            $total_increased    = wpinv_round_amount($item_price);
1752 1752
             
1753
-            if ( wpinv_prices_include_tax() ) {
1754
-                $subtotal -= wpinv_round_amount( $tax );
1753
+            if (wpinv_prices_include_tax()) {
1754
+                $subtotal -= wpinv_round_amount($tax);
1755 1755
             }
1756 1756
 
1757
-            $total              = $subtotal - $discount + $tax;
1757
+            $total = $subtotal - $discount + $tax;
1758 1758
 
1759 1759
             // Do not allow totals to go negative
1760
-            if( $total < 0 ) {
1760
+            if ($total < 0) {
1761 1761
                 $total = 0;
1762 1762
             }
1763 1763
             
@@ -1773,25 +1773,25 @@  discard block
 block discarded – undo
1773 1773
             $this->cart_details[$found_cart_key] = $cart_item;
1774 1774
         } else {
1775 1775
             // Set custom price.
1776
-            if ( $args['custom_price'] !== '' ) {
1776
+            if ($args['custom_price'] !== '') {
1777 1777
                 $item_price = $args['custom_price'];
1778 1778
             } else {
1779 1779
                 // Allow overriding the price
1780
-                if ( false !== $args['item_price'] ) {
1780
+                if (false !== $args['item_price']) {
1781 1781
                     $item_price = $args['item_price'];
1782 1782
                 } else {
1783
-                    $item_price = wpinv_get_item_price( $item->ID );
1783
+                    $item_price = wpinv_get_item_price($item->ID);
1784 1784
                 }
1785 1785
             }
1786 1786
 
1787 1787
             // Sanitizing the price here so we don't have a dozen calls later
1788
-            $item_price = wpinv_sanitize_amount( $item_price );
1789
-            $subtotal   = wpinv_round_amount( $item_price * $args['quantity'] );
1788
+            $item_price = wpinv_sanitize_amount($item_price);
1789
+            $subtotal   = wpinv_round_amount($item_price * $args['quantity']);
1790 1790
         
1791
-            $discount   = !empty( $args['discount'] ) ? $args['discount'] : 0;
1792
-            $tax_class  = !empty( $args['vat_class'] ) ? $args['vat_class'] : '';
1793
-            $tax_rate   = !empty( $args['vat_rate'] ) ? $args['vat_rate'] : 0;
1794
-            $tax        = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1791
+            $discount   = !empty($args['discount']) ? $args['discount'] : 0;
1792
+            $tax_class  = !empty($args['vat_class']) ? $args['vat_class'] : '';
1793
+            $tax_rate   = !empty($args['vat_rate']) ? $args['vat_rate'] : 0;
1794
+            $tax        = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1795 1795
 
1796 1796
             // Setup the items meta item
1797 1797
             $new_item = array(
@@ -1799,29 +1799,29 @@  discard block
 block discarded – undo
1799 1799
                 'quantity' => $args['quantity'],
1800 1800
             );
1801 1801
 
1802
-            $this->items[]  = $new_item;
1802
+            $this->items[] = $new_item;
1803 1803
 
1804
-            if ( wpinv_prices_include_tax() ) {
1805
-                $subtotal -= wpinv_round_amount( $tax );
1804
+            if (wpinv_prices_include_tax()) {
1805
+                $subtotal -= wpinv_round_amount($tax);
1806 1806
             }
1807 1807
 
1808
-            $total      = $subtotal - $discount + $tax;
1808
+            $total = $subtotal - $discount + $tax;
1809 1809
 
1810 1810
             // Do not allow totals to go negative
1811
-            if( $total < 0 ) {
1811
+            if ($total < 0) {
1812 1812
                 $total = 0;
1813 1813
             }
1814 1814
         
1815 1815
             $this->cart_details[] = array(
1816 1816
                 'name'          => !empty($args['name']) ? $args['name'] : $item->get_name(),
1817 1817
                 'id'            => $item->ID,
1818
-                'item_price'    => wpinv_round_amount( $item_price ),
1819
-                'custom_price'  => ( $args['custom_price'] !== '' ? wpinv_round_amount( $args['custom_price'] ) : '' ),
1818
+                'item_price'    => wpinv_round_amount($item_price),
1819
+                'custom_price'  => ($args['custom_price'] !== '' ? wpinv_round_amount($args['custom_price']) : ''),
1820 1820
                 'quantity'      => $args['quantity'],
1821 1821
                 'discount'      => $discount,
1822
-                'subtotal'      => wpinv_round_amount( $subtotal ),
1823
-                'tax'           => wpinv_round_amount( $tax ),
1824
-                'price'         => wpinv_round_amount( $total ),
1822
+                'subtotal'      => wpinv_round_amount($subtotal),
1823
+                'tax'           => wpinv_round_amount($tax),
1824
+                'price'         => wpinv_round_amount($total),
1825 1825
                 'vat_rate'      => $tax_rate,
1826 1826
                 'vat_class'     => $tax_class,
1827 1827
                 'meta'          => $args['meta'],
@@ -1831,18 +1831,18 @@  discard block
 block discarded – undo
1831 1831
             $subtotal = $subtotal - $discount;
1832 1832
         }
1833 1833
         
1834
-        $added_item = end( $this->cart_details );
1835
-        $added_item['action']  = 'add';
1834
+        $added_item = end($this->cart_details);
1835
+        $added_item['action'] = 'add';
1836 1836
         
1837 1837
         $this->pending['items'][] = $added_item;
1838 1838
         
1839
-        $this->increase_subtotal( $subtotal );
1840
-        $this->increase_tax( $tax );
1839
+        $this->increase_subtotal($subtotal);
1840
+        $this->increase_tax($tax);
1841 1841
 
1842 1842
         return true;
1843 1843
     }
1844 1844
 
1845
-    public function remove_item( $item_id, $args = array() ) {
1845
+    public function remove_item($item_id, $args = array()) {
1846 1846
 
1847 1847
         // Set some defaults
1848 1848
         $defaults = array(
@@ -1851,51 +1851,51 @@  discard block
 block discarded – undo
1851 1851
             'custom_price'  => '',
1852 1852
             'cart_index'    => false,
1853 1853
         );
1854
-        $args = wp_parse_args( $args, $defaults );
1854
+        $args = wp_parse_args($args, $defaults);
1855 1855
 
1856 1856
         // Bail if this post isn't a item
1857
-        if ( get_post_type( $item_id ) !== 'wpi_item' ) {
1857
+        if (get_post_type($item_id) !== 'wpi_item') {
1858 1858
             return false;
1859 1859
         }
1860 1860
         
1861
-        $this->cart_details = !empty( $this->cart_details ) ? array_values( $this->cart_details ) : $this->cart_details;
1861
+        $this->cart_details = !empty($this->cart_details) ? array_values($this->cart_details) : $this->cart_details;
1862 1862
 
1863
-        foreach ( $this->items as $key => $item ) {
1864
-            if ( !empty($item['id']) && (int)$item_id !== (int)$item['id'] ) {
1863
+        foreach ($this->items as $key => $item) {
1864
+            if (!empty($item['id']) && (int) $item_id !== (int) $item['id']) {
1865 1865
                 continue;
1866 1866
             }
1867 1867
 
1868
-            if ( false !== $args['cart_index'] ) {
1869
-                $cart_index = absint( $args['cart_index'] );
1870
-                $cart_item  = ! empty( $this->cart_details[ $cart_index ] ) ? $this->cart_details[ $cart_index ] : false;
1868
+            if (false !== $args['cart_index']) {
1869
+                $cart_index = absint($args['cart_index']);
1870
+                $cart_item  = !empty($this->cart_details[$cart_index]) ? $this->cart_details[$cart_index] : false;
1871 1871
 
1872
-                if ( ! empty( $cart_item ) ) {
1872
+                if (!empty($cart_item)) {
1873 1873
                     // If the cart index item isn't the same item ID, don't remove it
1874
-                    if ( !empty($cart_item['id']) && $cart_item['id'] != $item['id'] ) {
1874
+                    if (!empty($cart_item['id']) && $cart_item['id'] != $item['id']) {
1875 1875
                         continue;
1876 1876
                     }
1877 1877
                 }
1878 1878
             }
1879 1879
 
1880
-            $item_quantity = $this->items[ $key ]['quantity'];
1881
-            if ( $item_quantity > $args['quantity'] ) {
1882
-                $this->items[ $key ]['quantity'] -= $args['quantity'];
1880
+            $item_quantity = $this->items[$key]['quantity'];
1881
+            if ($item_quantity > $args['quantity']) {
1882
+                $this->items[$key]['quantity'] -= $args['quantity'];
1883 1883
                 break;
1884 1884
             } else {
1885
-                unset( $this->items[ $key ] );
1885
+                unset($this->items[$key]);
1886 1886
                 break;
1887 1887
             }
1888 1888
         }
1889 1889
 
1890 1890
         $found_cart_key = false;
1891
-        if ( false === $args['cart_index'] ) {
1892
-            foreach ( $this->cart_details as $cart_key => $item ) {
1893
-                if ( $item_id != $item['id'] ) {
1891
+        if (false === $args['cart_index']) {
1892
+            foreach ($this->cart_details as $cart_key => $item) {
1893
+                if ($item_id != $item['id']) {
1894 1894
                     continue;
1895 1895
                 }
1896 1896
 
1897
-                if ( false !== $args['item_price'] ) {
1898
-                    if ( isset( $item['item_price'] ) && (float) $args['item_price'] != (float) $item['item_price'] ) {
1897
+                if (false !== $args['item_price']) {
1898
+                    if (isset($item['item_price']) && (float) $args['item_price'] != (float) $item['item_price']) {
1899 1899
                         continue;
1900 1900
                     }
1901 1901
                 }
@@ -1904,13 +1904,13 @@  discard block
 block discarded – undo
1904 1904
                 break;
1905 1905
             }
1906 1906
         } else {
1907
-            $cart_index = absint( $args['cart_index'] );
1907
+            $cart_index = absint($args['cart_index']);
1908 1908
 
1909
-            if ( ! array_key_exists( $cart_index, $this->cart_details ) ) {
1909
+            if (!array_key_exists($cart_index, $this->cart_details)) {
1910 1910
                 return false; // Invalid cart index passed.
1911 1911
             }
1912 1912
 
1913
-            if ( (int) $this->cart_details[ $cart_index ]['id'] > 0 && (int) $this->cart_details[ $cart_index ]['id'] !== (int) $item_id ) {
1913
+            if ((int) $this->cart_details[$cart_index]['id'] > 0 && (int) $this->cart_details[$cart_index]['id'] !== (int) $item_id) {
1914 1914
                 return false; // We still need the proper Item ID to be sure.
1915 1915
             }
1916 1916
 
@@ -1918,41 +1918,41 @@  discard block
 block discarded – undo
1918 1918
         }
1919 1919
         
1920 1920
         $cart_item  = $this->cart_details[$found_cart_key];
1921
-        $quantity   = !empty( $cart_item['quantity'] ) ? $cart_item['quantity'] : 1;
1921
+        $quantity   = !empty($cart_item['quantity']) ? $cart_item['quantity'] : 1;
1922 1922
         
1923
-        if ( count( $this->cart_details ) == 1 && ( $quantity - $args['quantity'] ) < 1 ) {
1923
+        if (count($this->cart_details) == 1 && ($quantity - $args['quantity']) < 1) {
1924 1924
             //return false; // Invoice must contain at least one item.
1925 1925
         }
1926 1926
         
1927
-        $discounts  = $this->get_discounts();
1927
+        $discounts = $this->get_discounts();
1928 1928
         
1929
-        if ( $quantity > $args['quantity'] ) {
1929
+        if ($quantity > $args['quantity']) {
1930 1930
             $item_price         = $cart_item['item_price'];
1931
-            $tax_rate           = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : 0;
1931
+            $tax_rate           = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : 0;
1932 1932
             
1933
-            $new_quantity       = max( $quantity - $args['quantity'], 1);
1933
+            $new_quantity       = max($quantity - $args['quantity'], 1);
1934 1934
             $subtotal           = $item_price * $new_quantity;
1935 1935
             
1936 1936
             $args['quantity']   = $new_quantity;
1937
-            $discount           = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1938
-            $tax                = $subtotal > 0 && $tax_rate > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
1937
+            $discount           = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1938
+            $tax                = $subtotal > 0 && $tax_rate > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
1939 1939
             
1940
-            $discount_decrease  = (float)$cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['discount'] / $quantity ) ) : 0;
1941
-            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float)$cart_item['discount'] > $discount ? (float)$cart_item['discount'] - $discount : $discount_decrease; 
1942
-            $tax_decrease       = (float)$cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount( ( (float)$cart_item['tax'] / $quantity ) ) : 0;
1943
-            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float)$cart_item['tax'] > $tax ? (float)$cart_item['tax'] - $tax : $tax_decrease;
1940
+            $discount_decrease  = (float) $cart_item['discount'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['discount'] / $quantity)) : 0;
1941
+            $discount_decrease  = $discount > 0 && $subtotal > 0 && (float) $cart_item['discount'] > $discount ? (float) $cart_item['discount'] - $discount : $discount_decrease; 
1942
+            $tax_decrease       = (float) $cart_item['tax'] > 0 && $quantity > 0 ? wpinv_round_amount(((float) $cart_item['tax'] / $quantity)) : 0;
1943
+            $tax_decrease       = $tax > 0 && $subtotal > 0 && (float) $cart_item['tax'] > $tax ? (float) $cart_item['tax'] - $tax : $tax_decrease;
1944 1944
             
1945 1945
             // The total increase equals the number removed * the item_price
1946
-            $total_decrease     = wpinv_round_amount( $item_price );
1946
+            $total_decrease     = wpinv_round_amount($item_price);
1947 1947
             
1948
-            if ( wpinv_prices_include_tax() ) {
1949
-                $subtotal -= wpinv_round_amount( $tax );
1948
+            if (wpinv_prices_include_tax()) {
1949
+                $subtotal -= wpinv_round_amount($tax);
1950 1950
             }
1951 1951
 
1952
-            $total              = $subtotal - $discount + $tax;
1952
+            $total = $subtotal - $discount + $tax;
1953 1953
 
1954 1954
             // Do not allow totals to go negative
1955
-            if( $total < 0 ) {
1955
+            if ($total < 0) {
1956 1956
                 $total = 0;
1957 1957
             }
1958 1958
             
@@ -1971,16 +1971,16 @@  discard block
 block discarded – undo
1971 1971
             
1972 1972
             $this->cart_details[$found_cart_key] = $cart_item;
1973 1973
             
1974
-            $remove_item = end( $this->cart_details );
1974
+            $remove_item = end($this->cart_details);
1975 1975
         } else {
1976 1976
             $item_price     = $cart_item['item_price'];
1977
-            $discount       = !empty( $cart_item['discount'] ) ? $cart_item['discount'] : 0;
1978
-            $tax            = !empty( $cart_item['tax'] ) ? $cart_item['tax'] : 0;
1977
+            $discount       = !empty($cart_item['discount']) ? $cart_item['discount'] : 0;
1978
+            $tax            = !empty($cart_item['tax']) ? $cart_item['tax'] : 0;
1979 1979
         
1980
-            $subtotal_decrease  = ( $item_price * $quantity ) - $discount;
1980
+            $subtotal_decrease  = ($item_price * $quantity) - $discount;
1981 1981
             $tax_decrease       = $tax;
1982 1982
 
1983
-            unset( $this->cart_details[$found_cart_key] );
1983
+            unset($this->cart_details[$found_cart_key]);
1984 1984
             
1985 1985
             $remove_item             = $args;
1986 1986
             $remove_item['id']       = $item_id;
@@ -1991,8 +1991,8 @@  discard block
 block discarded – undo
1991 1991
         $remove_item['action']      = 'remove';
1992 1992
         $this->pending['items'][]   = $remove_item;
1993 1993
                
1994
-        $this->decrease_subtotal( $subtotal_decrease );
1995
-        $this->decrease_tax( $tax_decrease );
1994
+        $this->decrease_subtotal($subtotal_decrease);
1995
+        $this->decrease_tax($tax_decrease);
1996 1996
         
1997 1997
         return true;
1998 1998
     }
@@ -2000,7 +2000,7 @@  discard block
 block discarded – undo
2000 2000
     public function update_items($temp = false) {
2001 2001
         global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpi_nosave;
2002 2002
 
2003
-        if ( ! empty( $this->cart_details ) ) {
2003
+        if (!empty($this->cart_details)) {
2004 2004
             $wpi_nosave             = $temp;
2005 2005
             $cart_subtotal          = 0;
2006 2006
             $cart_discount          = 0;
@@ -2010,65 +2010,65 @@  discard block
 block discarded – undo
2010 2010
             $_POST['wpinv_country'] = $this->country;
2011 2011
             $_POST['wpinv_state']   = $this->state;
2012 2012
 
2013
-            foreach ( $this->cart_details as $key => $item ) {
2013
+            foreach ($this->cart_details as $key => $item) {
2014 2014
                 $item_price = $item['item_price'];
2015
-                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
2016
-                $amount     = wpinv_round_amount( $item_price * $quantity );
2015
+                $quantity   = wpinv_item_quantities_enabled() && $item['quantity'] > 0 ? absint($item['quantity']) : 1;
2016
+                $amount     = wpinv_round_amount($item_price * $quantity);
2017 2017
                 $subtotal   = $item_price * $quantity;
2018 2018
 
2019 2019
                 $wpi_current_id         = $this->ID;
2020 2020
                 $wpi_item_id            = $item['id'];
2021 2021
 
2022
-                $discount   = wpinv_get_cart_item_discount_amount( $item, $this->get_discounts() );
2022
+                $discount   = wpinv_get_cart_item_discount_amount($item, $this->get_discounts());
2023 2023
 
2024
-                $tax_rate   = wpinv_get_tax_rate( $this->country, $this->state, $wpi_item_id );
2025
-                $tax_class  = $wpinv_euvat->get_item_class( $wpi_item_id );
2026
-                $tax        = $item_price > 0 ? ( ( $subtotal - $discount ) * 0.01 * (float)$tax_rate ) : 0;
2024
+                $tax_rate   = wpinv_get_tax_rate($this->country, $this->state, $wpi_item_id);
2025
+                $tax_class  = $wpinv_euvat->get_item_class($wpi_item_id);
2026
+                $tax        = $item_price > 0 ? (($subtotal - $discount) * 0.01 * (float) $tax_rate) : 0;
2027 2027
 
2028
-                if ( ! $this->is_taxable() ) {
2028
+                if (!$this->is_taxable()) {
2029 2029
                     $tax = 0;
2030 2030
                 }
2031 2031
 
2032
-                if ( wpinv_prices_include_tax() ) {
2033
-                    $subtotal -= wpinv_round_amount( $tax );
2032
+                if (wpinv_prices_include_tax()) {
2033
+                    $subtotal -= wpinv_round_amount($tax);
2034 2034
                 }
2035 2035
 
2036
-                $total      = $subtotal - $discount + $tax;
2036
+                $total = $subtotal - $discount + $tax;
2037 2037
 
2038 2038
                 // Do not allow totals to go negative
2039
-                if( $total < 0 ) {
2039
+                if ($total < 0) {
2040 2040
                     $total = 0;
2041 2041
                 }
2042 2042
 
2043 2043
                 $cart_details[] = array(
2044 2044
                     'id'          => $item['id'],
2045 2045
                     'name'        => $item['name'],
2046
-                    'item_price'  => wpinv_round_amount( $item_price ),
2047
-                    'custom_price'=> ( isset( $item['custom_price'] ) ? $item['custom_price'] : '' ),
2046
+                    'item_price'  => wpinv_round_amount($item_price),
2047
+                    'custom_price'=> (isset($item['custom_price']) ? $item['custom_price'] : ''),
2048 2048
                     'quantity'    => $quantity,
2049 2049
                     'discount'    => $discount,
2050
-                    'subtotal'    => wpinv_round_amount( $subtotal ),
2051
-                    'tax'         => wpinv_round_amount( $tax ),
2052
-                    'price'       => wpinv_round_amount( $total ),
2050
+                    'subtotal'    => wpinv_round_amount($subtotal),
2051
+                    'tax'         => wpinv_round_amount($tax),
2052
+                    'price'       => wpinv_round_amount($total),
2053 2053
                     'vat_rate'    => $tax_rate,
2054 2054
                     'vat_class'   => $tax_class,
2055 2055
                     'meta'        => isset($item['meta']) ? $item['meta'] : array(),
2056 2056
                     'fees'        => isset($item['fees']) ? $item['fees'] : array(),
2057 2057
                 );
2058 2058
 
2059
-                $cart_subtotal  += (float)($subtotal - $discount); // TODO
2060
-                $cart_discount  += (float)($discount);
2061
-                $cart_tax       += (float)($tax);
2059
+                $cart_subtotal  += (float) ($subtotal - $discount); // TODO
2060
+                $cart_discount  += (float) ($discount);
2061
+                $cart_tax       += (float) ($tax);
2062 2062
             }
2063
-            if ( $cart_subtotal < 0 ) {
2063
+            if ($cart_subtotal < 0) {
2064 2064
                 $cart_subtotal = 0;
2065 2065
             }
2066
-            if ( $cart_tax < 0 ) {
2066
+            if ($cart_tax < 0) {
2067 2067
                 $cart_tax = 0;
2068 2068
             }
2069
-            $this->subtotal = wpinv_round_amount( $cart_subtotal );
2070
-            $this->tax      = wpinv_round_amount( $cart_tax );
2071
-            $this->discount = wpinv_round_amount( $cart_discount );
2069
+            $this->subtotal = wpinv_round_amount($cart_subtotal);
2070
+            $this->tax      = wpinv_round_amount($cart_tax);
2071
+            $this->discount = wpinv_round_amount($cart_discount);
2072 2072
             
2073 2073
             $this->recalculate_total();
2074 2074
             
@@ -2080,177 +2080,177 @@  discard block
 block discarded – undo
2080 2080
     
2081 2081
     public function recalculate_totals($temp = false) {        
2082 2082
         $this->update_items($temp);
2083
-        $this->save( true );
2083
+        $this->save(true);
2084 2084
         
2085 2085
         return $this;
2086 2086
     }
2087 2087
     
2088 2088
     public function needs_payment() {
2089
-        $valid_invoice_statuses = apply_filters( 'wpinv_valid_invoice_statuses_for_payment', array( 'wpi-pending' ), $this );
2089
+        $valid_invoice_statuses = apply_filters('wpinv_valid_invoice_statuses_for_payment', array('wpi-pending'), $this);
2090 2090
 
2091
-        if ( $this->has_status( $valid_invoice_statuses ) && ( $this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free() ) ) {
2091
+        if ($this->has_status($valid_invoice_statuses) && ($this->get_total() > 0 || $this->is_free_trial() || $this->is_free() || $this->is_initial_free())) {
2092 2092
             $needs_payment = true;
2093 2093
         } else {
2094 2094
             $needs_payment = false;
2095 2095
         }
2096 2096
 
2097
-        return apply_filters( 'wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses );
2097
+        return apply_filters('wpinv_needs_payment', $needs_payment, $this, $valid_invoice_statuses);
2098 2098
     }
2099 2099
     
2100
-    public function get_checkout_payment_url( $with_key = false, $secret = false ) {
2100
+    public function get_checkout_payment_url($with_key = false, $secret = false) {
2101 2101
         $pay_url = wpinv_get_checkout_uri();
2102 2102
 
2103
-        if ( is_ssl() ) {
2104
-            $pay_url = str_replace( 'http:', 'https:', $pay_url );
2103
+        if (is_ssl()) {
2104
+            $pay_url = str_replace('http:', 'https:', $pay_url);
2105 2105
         }
2106 2106
         
2107 2107
         $key = $this->get_key();
2108 2108
 
2109
-        if ( $with_key ) {
2110
-            $pay_url = add_query_arg( 'invoice_key', $key, $pay_url );
2109
+        if ($with_key) {
2110
+            $pay_url = add_query_arg('invoice_key', $key, $pay_url);
2111 2111
         } else {
2112
-            $pay_url = add_query_arg( array( 'wpi_action' => 'pay_for_invoice', 'invoice_key' => $key ), $pay_url );
2112
+            $pay_url = add_query_arg(array('wpi_action' => 'pay_for_invoice', 'invoice_key' => $key), $pay_url);
2113 2113
         }
2114 2114
         
2115
-        if ( $secret ) {
2116
-            $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $key ) ), $pay_url );
2115
+        if ($secret) {
2116
+            $pay_url = add_query_arg(array('_wpipay' => md5($this->get_user_id() . '::' . $this->get_email() . '::' . $key)), $pay_url);
2117 2117
         }
2118 2118
 
2119
-        return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret );
2119
+        return apply_filters('wpinv_get_checkout_payment_url', $pay_url, $this, $with_key, $secret);
2120 2120
     }
2121 2121
     
2122
-    public function get_view_url( $with_key = false ) {
2123
-        $invoice_url = get_permalink( $this->ID );
2122
+    public function get_view_url($with_key = false) {
2123
+        $invoice_url = get_permalink($this->ID);
2124 2124
 
2125
-        if ( $with_key ) {
2126
-            $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
2125
+        if ($with_key) {
2126
+            $invoice_url = add_query_arg('invoice_key', $this->get_key(), $invoice_url);
2127 2127
         }
2128 2128
 
2129
-        return apply_filters( 'wpinv_get_view_url', $invoice_url, $this, $with_key );
2129
+        return apply_filters('wpinv_get_view_url', $invoice_url, $this, $with_key);
2130 2130
     }
2131 2131
     
2132
-    public function generate_key( $string = '' ) {
2133
-        $auth_key  = defined( 'AUTH_KEY' ) ? AUTH_KEY : '';
2134
-        return strtolower( md5( $string . date( 'Y-m-d H:i:s' ) . $auth_key . uniqid( 'wpinv', true ) ) );  // Unique key
2132
+    public function generate_key($string = '') {
2133
+        $auth_key = defined('AUTH_KEY') ? AUTH_KEY : '';
2134
+        return strtolower(md5($string . date('Y-m-d H:i:s') . $auth_key . uniqid('wpinv', true))); // Unique key
2135 2135
     }
2136 2136
     
2137 2137
     public function is_recurring() {
2138
-        if ( empty( $this->cart_details ) ) {
2138
+        if (empty($this->cart_details)) {
2139 2139
             return false;
2140 2140
         }
2141 2141
         
2142 2142
         $has_subscription = false;
2143
-        foreach( $this->cart_details as $cart_item ) {
2144
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2143
+        foreach ($this->cart_details as $cart_item) {
2144
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2145 2145
                 $has_subscription = true;
2146 2146
                 break;
2147 2147
             }
2148 2148
         }
2149 2149
         
2150
-        if ( count( $this->cart_details ) > 1 ) {
2150
+        if (count($this->cart_details) > 1) {
2151 2151
             $has_subscription = false;
2152 2152
         }
2153 2153
 
2154
-        return apply_filters( 'wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details );
2154
+        return apply_filters('wpinv_invoice_has_recurring_item', $has_subscription, $this->cart_details);
2155 2155
     }
2156 2156
 
2157 2157
     public function is_free_trial() {
2158 2158
         $is_free_trial = false;
2159 2159
         
2160
-        if ( $this->is_parent() && $item = $this->get_recurring( true ) ) {
2161
-            if ( !empty( $item ) && $item->has_free_trial() ) {
2160
+        if ($this->is_parent() && $item = $this->get_recurring(true)) {
2161
+            if (!empty($item) && $item->has_free_trial()) {
2162 2162
                 $is_free_trial = true;
2163 2163
             }
2164 2164
         }
2165 2165
 
2166
-        return apply_filters( 'wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this );
2166
+        return apply_filters('wpinv_invoice_is_free_trial', $is_free_trial, $this->cart_details, $this);
2167 2167
     }
2168 2168
 
2169 2169
     public function is_initial_free() {
2170 2170
         $is_initial_free = false;
2171 2171
         
2172
-        if ( ! ( (float)wpinv_round_amount( $this->get_total() ) > 0 ) && $this->is_parent() && $this->is_recurring() && ! $this->is_free_trial() && ! $this->is_free() ) {
2172
+        if (!((float) wpinv_round_amount($this->get_total()) > 0) && $this->is_parent() && $this->is_recurring() && !$this->is_free_trial() && !$this->is_free()) {
2173 2173
             $is_initial_free = true;
2174 2174
         }
2175 2175
 
2176
-        return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details );
2176
+        return apply_filters('wpinv_invoice_is_initial_free', $is_initial_free, $this->cart_details);
2177 2177
     }
2178 2178
     
2179
-    public function get_recurring( $object = false ) {
2179
+    public function get_recurring($object = false) {
2180 2180
         $item = NULL;
2181 2181
         
2182
-        if ( empty( $this->cart_details ) ) {
2182
+        if (empty($this->cart_details)) {
2183 2183
             return $item;
2184 2184
         }
2185 2185
 
2186
-        foreach( $this->cart_details as $cart_item ) {
2187
-            if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
2186
+        foreach ($this->cart_details as $cart_item) {
2187
+            if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
2188 2188
                 $item = $cart_item['id'];
2189 2189
                 break;
2190 2190
             }
2191 2191
         }
2192 2192
 
2193
-        if ( $object ) {
2194
-            $item = $item ? new WPInv_Item( $item ) : NULL;
2193
+        if ($object) {
2194
+            $item = $item ? new WPInv_Item($item) : NULL;
2195 2195
             
2196
-            apply_filters( 'wpinv_invoice_get_recurring_item', $item, $this );
2196
+            apply_filters('wpinv_invoice_get_recurring_item', $item, $this);
2197 2197
         }
2198 2198
 
2199
-        return apply_filters( 'wpinv_invoice_get_recurring_item_id', $item, $this );
2199
+        return apply_filters('wpinv_invoice_get_recurring_item_id', $item, $this);
2200 2200
     }
2201 2201
 
2202 2202
     public function get_subscription_name() {
2203
-        $item = $this->get_recurring( true );
2203
+        $item = $this->get_recurring(true);
2204 2204
 
2205
-        if ( empty( $item ) ) {
2205
+        if (empty($item)) {
2206 2206
             return NULL;
2207 2207
         }
2208 2208
 
2209
-        if ( !($name = $item->get_name()) ) {
2209
+        if (!($name = $item->get_name())) {
2210 2210
             $name = $item->post_name;
2211 2211
         }
2212 2212
 
2213
-        return apply_filters( 'wpinv_invoice_get_subscription_name', $name, $this );
2213
+        return apply_filters('wpinv_invoice_get_subscription_name', $name, $this);
2214 2214
     }
2215 2215
 
2216 2216
     public function get_subscription_id() {
2217
-        $subscription_id = $this->get_meta( '_wpinv_subscr_profile_id', true );
2217
+        $subscription_id = $this->get_meta('_wpinv_subscr_profile_id', true);
2218 2218
 
2219
-        if ( empty( $subscription_id ) && !empty( $this->parent_invoice ) ) {
2220
-            $parent_invoice = wpinv_get_invoice( $this->parent_invoice );
2219
+        if (empty($subscription_id) && !empty($this->parent_invoice)) {
2220
+            $parent_invoice = wpinv_get_invoice($this->parent_invoice);
2221 2221
 
2222
-            $subscription_id = $parent_invoice->get_meta( '_wpinv_subscr_profile_id', true );
2222
+            $subscription_id = $parent_invoice->get_meta('_wpinv_subscr_profile_id', true);
2223 2223
         }
2224 2224
         
2225 2225
         return $subscription_id;
2226 2226
     }
2227 2227
     
2228 2228
     public function is_parent() {
2229
-        $is_parent = empty( $this->parent_invoice ) ? true : false;
2229
+        $is_parent = empty($this->parent_invoice) ? true : false;
2230 2230
 
2231
-        return apply_filters( 'wpinv_invoice_is_parent', $is_parent, $this );
2231
+        return apply_filters('wpinv_invoice_is_parent', $is_parent, $this);
2232 2232
     }
2233 2233
     
2234 2234
     public function is_renewal() {
2235 2235
         $is_renewal = $this->parent_invoice && $this->parent_invoice != $this->ID ? true : false;
2236 2236
 
2237
-        return apply_filters( 'wpinv_invoice_is_renewal', $is_renewal, $this );
2237
+        return apply_filters('wpinv_invoice_is_renewal', $is_renewal, $this);
2238 2238
     }
2239 2239
     
2240 2240
     public function get_parent_payment() {
2241 2241
         $parent_payment = NULL;
2242 2242
         
2243
-        if ( $this->is_renewal() ) {
2244
-            $parent_payment = wpinv_get_invoice( $this->parent_invoice );
2243
+        if ($this->is_renewal()) {
2244
+            $parent_payment = wpinv_get_invoice($this->parent_invoice);
2245 2245
         }
2246 2246
         
2247 2247
         return $parent_payment;
2248 2248
     }
2249 2249
     
2250 2250
     public function is_paid() {
2251
-        $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2251
+        $is_paid = $this->has_status(array('publish', 'wpi-processing', 'wpi-renewal'));
2252 2252
 
2253
-        return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2253
+        return apply_filters('wpinv_invoice_is_paid', $is_paid, $this);
2254 2254
     }
2255 2255
 
2256 2256
     /**
@@ -2263,23 +2263,23 @@  discard block
 block discarded – undo
2263 2263
     }
2264 2264
     
2265 2265
     public function is_refunded() {
2266
-        $is_refunded = $this->has_status( array( 'wpi-refunded' ) );
2266
+        $is_refunded = $this->has_status(array('wpi-refunded'));
2267 2267
 
2268
-        return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2268
+        return apply_filters('wpinv_invoice_is_refunded', $is_refunded, $this);
2269 2269
     }
2270 2270
     
2271 2271
     public function is_free() {
2272 2272
         $is_free = false;
2273 2273
         
2274
-        if ( !( (float)wpinv_round_amount( $this->get_total() ) > 0 ) ) {
2275
-            if ( $this->is_parent() && $this->is_recurring() ) {
2276
-                $is_free = (float)wpinv_round_amount( $this->get_recurring_details( 'total' ) ) > 0 ? false : true;
2274
+        if (!((float) wpinv_round_amount($this->get_total()) > 0)) {
2275
+            if ($this->is_parent() && $this->is_recurring()) {
2276
+                $is_free = (float) wpinv_round_amount($this->get_recurring_details('total')) > 0 ? false : true;
2277 2277
             } else {
2278 2278
                 $is_free = true;
2279 2279
             }
2280 2280
         }
2281 2281
         
2282
-        return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2282
+        return apply_filters('wpinv_invoice_is_free', $is_free, $this);
2283 2283
     }
2284 2284
     
2285 2285
     public function has_vat() {
@@ -2287,41 +2287,41 @@  discard block
 block discarded – undo
2287 2287
         
2288 2288
         $requires_vat = false;
2289 2289
         
2290
-        if ( $this->country ) {
2290
+        if ($this->country) {
2291 2291
             $wpi_country        = $this->country;
2292 2292
             
2293
-            $requires_vat       = $wpinv_euvat->requires_vat( $requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule( $this ) );
2293
+            $requires_vat       = $wpinv_euvat->requires_vat($requires_vat, $this->get_user_id(), $wpinv_euvat->invoice_has_digital_rule($this));
2294 2294
         }
2295 2295
         
2296
-        return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2296
+        return apply_filters('wpinv_invoice_has_vat', $requires_vat, $this);
2297 2297
     }
2298 2298
 
2299 2299
     public function refresh_item_ids() {
2300 2300
         $item_ids = array();
2301 2301
         
2302
-        if ( ! empty( $this->cart_details ) ) {
2303
-            foreach ( array_keys( $this->cart_details ) as $item ) {
2304
-                if ( ! empty( $item['id'] ) ) {
2302
+        if (!empty($this->cart_details)) {
2303
+            foreach (array_keys($this->cart_details) as $item) {
2304
+                if (!empty($item['id'])) {
2305 2305
                     $item_ids[] = $item['id'];
2306 2306
                 }
2307 2307
             }
2308 2308
         }
2309 2309
         
2310
-        $item_ids = !empty( $item_ids ) ? implode( ',', array_unique( $item_ids ) ) : '';
2310
+        $item_ids = !empty($item_ids) ? implode(',', array_unique($item_ids)) : '';
2311 2311
         
2312
-        update_post_meta( $this->ID, '_wpinv_item_ids', $item_ids );
2312
+        update_post_meta($this->ID, '_wpinv_item_ids', $item_ids);
2313 2313
     }
2314 2314
     
2315
-    public function get_invoice_quote_type( $post_id ) {
2316
-        if ( empty( $post_id ) ) {
2315
+    public function get_invoice_quote_type($post_id) {
2316
+        if (empty($post_id)) {
2317 2317
             return '';
2318 2318
         }
2319 2319
 
2320
-        $type = get_post_type( $post_id );
2320
+        $type = get_post_type($post_id);
2321 2321
 
2322
-        if ( 'wpi_invoice' === $type ) {
2322
+        if ('wpi_invoice' === $type) {
2323 2323
             $post_type = __('Invoice', 'invoicing');
2324
-        } else{
2324
+        } else {
2325 2325
             $post_type = __('Quote', 'invoicing');
2326 2326
         }
2327 2327
 
Please login to merge, or discard this patch.
includes/class-wpinv-session-handler.php 2 patches
Indentation   +267 added lines, -267 removed lines patch added patch discarded remove patch
@@ -12,124 +12,124 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class WPInv_Session_Handler extends WPInv_Session {
14 14
 
15
-	/**
16
-	 * Cookie name used for the session.
17
-	 *
18
-	 * @var string cookie name
19
-	 */
20
-	protected $_cookie;
21
-
22
-	/**
23
-	 * Stores session expiry.
24
-	 *
25
-	 * @var int session due to expire timestamp
26
-	 */
27
-	protected $_session_expiring;
28
-
29
-	/**
30
-	 * Stores session due to expire timestamp.
31
-	 *
32
-	 * @var string session expiration timestamp
33
-	 */
34
-	protected $_session_expiration;
35
-
36
-	/**
37
-	 * True when the cookie exists.
38
-	 *
39
-	 * @var bool Based on whether a cookie exists.
40
-	 */
41
-	protected $_has_cookie = false;
42
-
43
-	/**
44
-	 * Table name for session data.
45
-	 *
46
-	 * @var string Custom session table name
47
-	 */
48
-	protected $_table;
49
-
50
-	/**
51
-	 * Constructor for the session class.
52
-	 */
53
-	public function __construct() {
54
-
55
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
15
+    /**
16
+     * Cookie name used for the session.
17
+     *
18
+     * @var string cookie name
19
+     */
20
+    protected $_cookie;
21
+
22
+    /**
23
+     * Stores session expiry.
24
+     *
25
+     * @var int session due to expire timestamp
26
+     */
27
+    protected $_session_expiring;
28
+
29
+    /**
30
+     * Stores session due to expire timestamp.
31
+     *
32
+     * @var string session expiration timestamp
33
+     */
34
+    protected $_session_expiration;
35
+
36
+    /**
37
+     * True when the cookie exists.
38
+     *
39
+     * @var bool Based on whether a cookie exists.
40
+     */
41
+    protected $_has_cookie = false;
42
+
43
+    /**
44
+     * Table name for session data.
45
+     *
46
+     * @var string Custom session table name
47
+     */
48
+    protected $_table;
49
+
50
+    /**
51
+     * Constructor for the session class.
52
+     */
53
+    public function __construct() {
54
+
55
+        $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
56 56
         add_action( 'init', array( $this, 'init' ), -1 );
57
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
60
-	}
61
-
62
-	/**
63
-	 * Init hooks and session data.
64
-	 *
65
-	 * @since 3.3.0
66
-	 */
67
-	public function init() {
68
-		$this->init_session_cookie();
69
-
70
-		if ( ! is_user_logged_in() ) {
71
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
72
-		}
73
-	}
74
-
75
-	/**
76
-	 * Setup cookie and customer ID.
77
-	 *
78
-	 * @since 3.6.0
79
-	 */
80
-	public function init_session_cookie() {
81
-		$cookie = $this->get_session_cookie();
82
-
83
-		if ( $cookie ) {
84
-			$this->_customer_id        = $cookie[0];
85
-			$this->_session_expiration = $cookie[1];
86
-			$this->_session_expiring   = $cookie[2];
87
-			$this->_has_cookie         = true;
88
-			$this->_data               = $this->get_session_data();
89
-
90
-			// If the user logs in, update session.
91
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
92
-				$this->_customer_id = get_current_user_id();
93
-				$this->_dirty       = true;
94
-				$this->save_data();
95
-				$this->set_customer_session_cookie( true );
96
-			}
97
-
98
-			// Update session if its close to expiring.
99
-			if ( time() > $this->_session_expiring ) {
100
-				$this->set_session_expiration();
101
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
102
-			}
103
-		} else {
104
-			$this->set_session_expiration();
105
-			$this->_customer_id = $this->generate_customer_id();
106
-			$this->_data        = $this->get_session_data();
107
-		}
108
-	}
109
-
110
-	/**
111
-	 * Sets the session cookie on-demand (usually after adding an item to the cart).
112
-	 *
113
-	 * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
114
-	 *
115
-	 * Warning: Cookies will only be set if this is called before the headers are sent.
116
-	 *
117
-	 * @param bool $set Should the session cookie be set.
118
-	 */
119
-	public function set_customer_session_cookie( $set ) {
120
-		if ( $set ) {
121
-			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
122
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
123
-			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
124
-			$this->_has_cookie = true;
125
-
126
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
127
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
128
-			}
129
-		}
130
-	}
131
-
132
-	public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
57
+        add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
+        add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
+        add_action( 'shutdown', array( $this, 'save_data' ), 20 );
60
+    }
61
+
62
+    /**
63
+     * Init hooks and session data.
64
+     *
65
+     * @since 3.3.0
66
+     */
67
+    public function init() {
68
+        $this->init_session_cookie();
69
+
70
+        if ( ! is_user_logged_in() ) {
71
+            add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
72
+        }
73
+    }
74
+
75
+    /**
76
+     * Setup cookie and customer ID.
77
+     *
78
+     * @since 3.6.0
79
+     */
80
+    public function init_session_cookie() {
81
+        $cookie = $this->get_session_cookie();
82
+
83
+        if ( $cookie ) {
84
+            $this->_customer_id        = $cookie[0];
85
+            $this->_session_expiration = $cookie[1];
86
+            $this->_session_expiring   = $cookie[2];
87
+            $this->_has_cookie         = true;
88
+            $this->_data               = $this->get_session_data();
89
+
90
+            // If the user logs in, update session.
91
+            if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
92
+                $this->_customer_id = get_current_user_id();
93
+                $this->_dirty       = true;
94
+                $this->save_data();
95
+                $this->set_customer_session_cookie( true );
96
+            }
97
+
98
+            // Update session if its close to expiring.
99
+            if ( time() > $this->_session_expiring ) {
100
+                $this->set_session_expiration();
101
+                $this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
102
+            }
103
+        } else {
104
+            $this->set_session_expiration();
105
+            $this->_customer_id = $this->generate_customer_id();
106
+            $this->_data        = $this->get_session_data();
107
+        }
108
+    }
109
+
110
+    /**
111
+     * Sets the session cookie on-demand (usually after adding an item to the cart).
112
+     *
113
+     * Since the cookie name (as of 2.1) is prepended with wp, cache systems like batcache will not cache pages when set.
114
+     *
115
+     * Warning: Cookies will only be set if this is called before the headers are sent.
116
+     *
117
+     * @param bool $set Should the session cookie be set.
118
+     */
119
+    public function set_customer_session_cookie( $set ) {
120
+        if ( $set ) {
121
+            $to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
122
+            $cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
123
+            $cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
124
+            $this->_has_cookie = true;
125
+
126
+            if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
127
+                $this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
128
+            }
129
+        }
130
+    }
131
+
132
+    public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
133 133
         if ( ! headers_sent() ) {
134 134
             setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
135 135
         } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
@@ -138,86 +138,86 @@  discard block
 block discarded – undo
138 138
         }
139 139
     }
140 140
 
141
-	/**
142
-	 * Should the session cookie be secure?
143
-	 *
144
-	 * @since 3.6.0
145
-	 * @return bool
146
-	 */
147
-	protected function use_secure_cookie() {
141
+    /**
142
+     * Should the session cookie be secure?
143
+     *
144
+     * @since 3.6.0
145
+     * @return bool
146
+     */
147
+    protected function use_secure_cookie() {
148 148
         $is_https = false !== strstr( get_option( 'home' ), 'https:' );
149
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
150
-	}
151
-
152
-	/**
153
-	 * Return true if the current user has an active session, i.e. a cookie to retrieve values.
154
-	 *
155
-	 * @return bool
156
-	 */
157
-	public function has_session() {
158
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
159
-	}
160
-
161
-	/**
162
-	 * Set session expiration.
163
-	 */
164
-	public function set_session_expiration() {
165
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
166
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
167
-	}
168
-
169
-	/**
170
-	 * Generates session ids.
171
-	 *
172
-	 * @return string
173
-	 */
174
-	public function generate_customer_id() {
175
-		require_once ABSPATH . 'wp-includes/class-phpass.php';
176
-		$hasher      = new PasswordHash( 8, false );
177
-		return md5( $hasher->get_random_bytes( 32 ) );
178
-	}
179
-
180
-	/**
181
-	 * Get the session cookie, if set. Otherwise return false.
182
-	 *
183
-	 * Session cookies without a customer ID are invalid.
184
-	 *
185
-	 * @return bool|array
186
-	 */
187
-	public function get_session_cookie() {
188
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
189
-
190
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
191
-			return false;
192
-		}
193
-
194
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
195
-
196
-		if ( empty( $customer_id ) ) {
197
-			return false;
198
-		}
199
-
200
-		// Validate hash.
201
-		$to_hash = $customer_id . '|' . $session_expiration;
202
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
203
-
204
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
205
-			return false;
206
-		}
207
-
208
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
209
-	}
210
-
211
-	/**
212
-	 * Get session data.
213
-	 *
214
-	 * @return array
215
-	 */
216
-	public function get_session_data() {
217
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
218
-	}
219
-
220
-	public function generate_key($customer_id){
149
+        return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
150
+    }
151
+
152
+    /**
153
+     * Return true if the current user has an active session, i.e. a cookie to retrieve values.
154
+     *
155
+     * @return bool
156
+     */
157
+    public function has_session() {
158
+        return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
159
+    }
160
+
161
+    /**
162
+     * Set session expiration.
163
+     */
164
+    public function set_session_expiration() {
165
+        $this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
166
+        $this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
167
+    }
168
+
169
+    /**
170
+     * Generates session ids.
171
+     *
172
+     * @return string
173
+     */
174
+    public function generate_customer_id() {
175
+        require_once ABSPATH . 'wp-includes/class-phpass.php';
176
+        $hasher      = new PasswordHash( 8, false );
177
+        return md5( $hasher->get_random_bytes( 32 ) );
178
+    }
179
+
180
+    /**
181
+     * Get the session cookie, if set. Otherwise return false.
182
+     *
183
+     * Session cookies without a customer ID are invalid.
184
+     *
185
+     * @return bool|array
186
+     */
187
+    public function get_session_cookie() {
188
+        $cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
189
+
190
+        if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
191
+            return false;
192
+        }
193
+
194
+        list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
195
+
196
+        if ( empty( $customer_id ) ) {
197
+            return false;
198
+        }
199
+
200
+        // Validate hash.
201
+        $to_hash = $customer_id . '|' . $session_expiration;
202
+        $hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
203
+
204
+        if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
205
+            return false;
206
+        }
207
+
208
+        return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
209
+    }
210
+
211
+    /**
212
+     * Get session data.
213
+     *
214
+     * @return array
215
+     */
216
+    public function get_session_data() {
217
+        return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
218
+    }
219
+
220
+    public function generate_key($customer_id){
221 221
         if(!$customer_id){
222 222
             return;
223 223
         }
@@ -225,62 +225,62 @@  discard block
 block discarded – undo
225 225
         return 'wpi_trans_'.$customer_id;
226 226
     }
227 227
 
228
-	/**
229
-	 * Save data.
230
-	 */
231
-	public function save_data() {
232
-		// Dirty if something changed - prevents saving nothing new.
233
-		if ( $this->_dirty && $this->has_session() ) {
228
+    /**
229
+     * Save data.
230
+     */
231
+    public function save_data() {
232
+        // Dirty if something changed - prevents saving nothing new.
233
+        if ( $this->_dirty && $this->has_session() ) {
234 234
 
235 235
             set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration);
236 236
 
237
-			$this->_dirty = false;
238
-		}
239
-	}
240
-
241
-	/**
242
-	 * Destroy all session data.
243
-	 */
244
-	public function destroy_session() {
245
-		$this->delete_session( $this->_customer_id );
246
-		$this->forget_session();
247
-	}
248
-
249
-	/**
250
-	 * Forget all session data without destroying it.
251
-	 */
252
-	public function forget_session() {
253
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
254
-
255
-		wpinv_empty_cart();
256
-
257
-		$this->_data        = array();
258
-		$this->_dirty       = false;
259
-		$this->_customer_id = $this->generate_customer_id();
260
-	}
261
-
262
-	/**
263
-	 * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
264
-	 *
265
-	 * @param int $uid User ID.
266
-	 * @return string
267
-	 */
268
-	public function nonce_user_logged_out( $uid ) {
269
-		return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
270
-	}
271
-
272
-	/**
273
-	 * Returns the session.
274
-	 *
275
-	 * @param string $customer_id Customer ID.
276
-	 * @param mixed  $default Default session value.
277
-	 * @return string|array
278
-	 */
279
-	public function get_session( $customer_id, $default = false ) {
280
-
281
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
282
-			return array();
283
-		}
237
+            $this->_dirty = false;
238
+        }
239
+    }
240
+
241
+    /**
242
+     * Destroy all session data.
243
+     */
244
+    public function destroy_session() {
245
+        $this->delete_session( $this->_customer_id );
246
+        $this->forget_session();
247
+    }
248
+
249
+    /**
250
+     * Forget all session data without destroying it.
251
+     */
252
+    public function forget_session() {
253
+        $this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
254
+
255
+        wpinv_empty_cart();
256
+
257
+        $this->_data        = array();
258
+        $this->_dirty       = false;
259
+        $this->_customer_id = $this->generate_customer_id();
260
+    }
261
+
262
+    /**
263
+     * When a user is logged out, ensure they have a unique nonce by using the customer/session ID.
264
+     *
265
+     * @param int $uid User ID.
266
+     * @return string
267
+     */
268
+    public function nonce_user_logged_out( $uid ) {
269
+        return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
270
+    }
271
+
272
+    /**
273
+     * Returns the session.
274
+     *
275
+     * @param string $customer_id Customer ID.
276
+     * @param mixed  $default Default session value.
277
+     * @return string|array
278
+     */
279
+    public function get_session( $customer_id, $default = false ) {
280
+
281
+        if ( defined( 'WP_SETUP_CONFIG' ) ) {
282
+            return array();
283
+        }
284 284
 
285 285
         if ( !is_user_logged_in() ) {
286 286
             if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){
@@ -295,32 +295,32 @@  discard block
 block discarded – undo
295 295
             $value = $default;
296 296
         }
297 297
 
298
-		return maybe_unserialize( $value );
299
-	}
298
+        return maybe_unserialize( $value );
299
+    }
300 300
 
301
-	/**
302
-	 * Delete the session from the cache and database.
303
-	 *
304
-	 * @param int $customer_id Customer ID.
305
-	 */
306
-	public function delete_session( $customer_id ) {
301
+    /**
302
+     * Delete the session from the cache and database.
303
+     *
304
+     * @param int $customer_id Customer ID.
305
+     */
306
+    public function delete_session( $customer_id ) {
307 307
 
308 308
         $key = $this->generate_key($customer_id);
309 309
 
310
-		delete_transient($key);
311
-	}
310
+        delete_transient($key);
311
+    }
312 312
 
313
-	/**
314
-	 * Update the session expiry timestamp.
315
-	 *
316
-	 * @param string $customer_id Customer ID.
317
-	 * @param int    $timestamp Timestamp to expire the cookie.
318
-	 */
319
-	public function update_session_timestamp( $customer_id, $timestamp ) {
313
+    /**
314
+     * Update the session expiry timestamp.
315
+     *
316
+     * @param string $customer_id Customer ID.
317
+     * @param int    $timestamp Timestamp to expire the cookie.
318
+     */
319
+    public function update_session_timestamp( $customer_id, $timestamp ) {
320 320
 
321 321
         set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp);
322 322
 
323
-	}
323
+    }
324 324
 }
325 325
 
326 326
 global $wpi_session;
Please login to merge, or discard this patch.
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * Session handler class.
@@ -52,11 +52,11 @@  discard block
 block discarded – undo
52 52
 	 */
53 53
 	public function __construct() {
54 54
 
55
-	    $this->_cookie = apply_filters( 'wpinv_cookie', 'wpinv_session_' . COOKIEHASH );
56
-        add_action( 'init', array( $this, 'init' ), -1 );
57
-		add_action( 'wp_logout', array( $this, 'destroy_session' ) );
58
-		add_action( 'wp', array( $this, 'set_customer_session_cookie' ), 10 );
59
-		add_action( 'shutdown', array( $this, 'save_data' ), 20 );
55
+	    $this->_cookie = apply_filters('wpinv_cookie', 'wpinv_session_' . COOKIEHASH);
56
+        add_action('init', array($this, 'init'), -1);
57
+		add_action('wp_logout', array($this, 'destroy_session'));
58
+		add_action('wp', array($this, 'set_customer_session_cookie'), 10);
59
+		add_action('shutdown', array($this, 'save_data'), 20);
60 60
 	}
61 61
 
62 62
 	/**
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
 	public function init() {
68 68
 		$this->init_session_cookie();
69 69
 
70
-		if ( ! is_user_logged_in() ) {
71
-			add_filter( 'nonce_user_logged_out', array( $this, 'nonce_user_logged_out' ) );
70
+		if (!is_user_logged_in()) {
71
+			add_filter('nonce_user_logged_out', array($this, 'nonce_user_logged_out'));
72 72
 		}
73 73
 	}
74 74
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	public function init_session_cookie() {
81 81
 		$cookie = $this->get_session_cookie();
82 82
 
83
-		if ( $cookie ) {
83
+		if ($cookie) {
84 84
 			$this->_customer_id        = $cookie[0];
85 85
 			$this->_session_expiration = $cookie[1];
86 86
 			$this->_session_expiring   = $cookie[2];
@@ -88,17 +88,17 @@  discard block
 block discarded – undo
88 88
 			$this->_data               = $this->get_session_data();
89 89
 
90 90
 			// If the user logs in, update session.
91
-			if ( is_user_logged_in() && get_current_user_id() != $this->_customer_id ) {
91
+			if (is_user_logged_in() && get_current_user_id() != $this->_customer_id) {
92 92
 				$this->_customer_id = get_current_user_id();
93 93
 				$this->_dirty       = true;
94 94
 				$this->save_data();
95
-				$this->set_customer_session_cookie( true );
95
+				$this->set_customer_session_cookie(true);
96 96
 			}
97 97
 
98 98
 			// Update session if its close to expiring.
99
-			if ( time() > $this->_session_expiring ) {
99
+			if (time() > $this->_session_expiring) {
100 100
 				$this->set_session_expiration();
101
-				$this->update_session_timestamp( $this->_customer_id, $this->_session_expiration );
101
+				$this->update_session_timestamp($this->_customer_id, $this->_session_expiration);
102 102
 			}
103 103
 		} else {
104 104
 			$this->set_session_expiration();
@@ -116,25 +116,25 @@  discard block
 block discarded – undo
116 116
 	 *
117 117
 	 * @param bool $set Should the session cookie be set.
118 118
 	 */
119
-	public function set_customer_session_cookie( $set ) {
120
-		if ( $set ) {
119
+	public function set_customer_session_cookie($set) {
120
+		if ($set) {
121 121
 			$to_hash           = $this->_customer_id . '|' . $this->_session_expiration;
122
-			$cookie_hash       = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
122
+			$cookie_hash       = hash_hmac('md5', $to_hash, wp_hash($to_hash));
123 123
 			$cookie_value      = $this->_customer_id . '||' . $this->_session_expiration . '||' . $this->_session_expiring . '||' . $cookie_hash;
124 124
 			$this->_has_cookie = true;
125 125
 
126
-			if ( ! isset( $_COOKIE[ $this->_cookie ] ) || $_COOKIE[ $this->_cookie ] !== $cookie_value ) {
127
-				$this->setcookie( $this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true );
126
+			if (!isset($_COOKIE[$this->_cookie]) || $_COOKIE[$this->_cookie] !== $cookie_value) {
127
+				$this->setcookie($this->_cookie, $cookie_value, $this->_session_expiration, $this->use_secure_cookie(), true);
128 128
 			}
129 129
 		}
130 130
 	}
131 131
 
132
-	public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false){
133
-        if ( ! headers_sent() ) {
134
-            setcookie( $name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters( 'wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure ) );
135
-        } elseif ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
136
-            headers_sent( $file, $line );
137
-            trigger_error( "{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE ); // @codingStandardsIgnoreLine
132
+	public function setcookie($name, $value, $expire = 0, $secure = false, $httponly = false) {
133
+        if (!headers_sent()) {
134
+            setcookie($name, $value, $expire, COOKIEPATH ? COOKIEPATH : '/', COOKIE_DOMAIN, $secure, apply_filters('wpinv_cookie_httponly', $httponly, $name, $value, $expire, $secure));
135
+        } elseif (defined('WP_DEBUG') && WP_DEBUG) {
136
+            headers_sent($file, $line);
137
+            trigger_error("{$name} cookie cannot be set - headers already sent by {$file} on line {$line}", E_USER_NOTICE); // @codingStandardsIgnoreLine
138 138
         }
139 139
     }
140 140
 
@@ -145,8 +145,8 @@  discard block
 block discarded – undo
145 145
 	 * @return bool
146 146
 	 */
147 147
 	protected function use_secure_cookie() {
148
-        $is_https = false !== strstr( get_option( 'home' ), 'https:' );
149
-		return apply_filters( 'wpinv_session_use_secure_cookie', $is_https && is_ssl() );
148
+        $is_https = false !== strstr(get_option('home'), 'https:');
149
+		return apply_filters('wpinv_session_use_secure_cookie', $is_https && is_ssl());
150 150
 	}
151 151
 
152 152
 	/**
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 	 * @return bool
156 156
 	 */
157 157
 	public function has_session() {
158
-		return isset( $_COOKIE[ $this->_cookie ] ) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
158
+		return isset($_COOKIE[$this->_cookie]) || $this->_has_cookie || is_user_logged_in(); // @codingStandardsIgnoreLine.
159 159
 	}
160 160
 
161 161
 	/**
162 162
 	 * Set session expiration.
163 163
 	 */
164 164
 	public function set_session_expiration() {
165
-		$this->_session_expiring   = time() + intval( apply_filters( 'wpinv_session_expiring', 60 * 60 * 47 ) ); // 47 Hours.
166
-		$this->_session_expiration = time() + intval( apply_filters( 'wpinv_session_expiration', 60 * 60 * 48 ) ); // 48 Hours.
165
+		$this->_session_expiring   = time() + intval(apply_filters('wpinv_session_expiring', 60 * 60 * 47)); // 47 Hours.
166
+		$this->_session_expiration = time() + intval(apply_filters('wpinv_session_expiration', 60 * 60 * 48)); // 48 Hours.
167 167
 	}
168 168
 
169 169
 	/**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
 	 */
174 174
 	public function generate_customer_id() {
175 175
 		require_once ABSPATH . 'wp-includes/class-phpass.php';
176
-		$hasher      = new PasswordHash( 8, false );
177
-		return md5( $hasher->get_random_bytes( 32 ) );
176
+		$hasher = new PasswordHash(8, false);
177
+		return md5($hasher->get_random_bytes(32));
178 178
 	}
179 179
 
180 180
 	/**
@@ -185,27 +185,27 @@  discard block
 block discarded – undo
185 185
 	 * @return bool|array
186 186
 	 */
187 187
 	public function get_session_cookie() {
188
-		$cookie_value = isset( $_COOKIE[ $this->_cookie ] ) ? wp_unslash( $_COOKIE[ $this->_cookie ] ) : false; // @codingStandardsIgnoreLine.
188
+		$cookie_value = isset($_COOKIE[$this->_cookie]) ? wp_unslash($_COOKIE[$this->_cookie]) : false; // @codingStandardsIgnoreLine.
189 189
 
190
-		if ( empty( $cookie_value ) || ! is_string( $cookie_value ) ) {
190
+		if (empty($cookie_value) || !is_string($cookie_value)) {
191 191
 			return false;
192 192
 		}
193 193
 
194
-		list( $customer_id, $session_expiration, $session_expiring, $cookie_hash ) = explode( '||', $cookie_value );
194
+		list($customer_id, $session_expiration, $session_expiring, $cookie_hash) = explode('||', $cookie_value);
195 195
 
196
-		if ( empty( $customer_id ) ) {
196
+		if (empty($customer_id)) {
197 197
 			return false;
198 198
 		}
199 199
 
200 200
 		// Validate hash.
201 201
 		$to_hash = $customer_id . '|' . $session_expiration;
202
-		$hash    = hash_hmac( 'md5', $to_hash, wp_hash( $to_hash ) );
202
+		$hash    = hash_hmac('md5', $to_hash, wp_hash($to_hash));
203 203
 
204
-		if ( empty( $cookie_hash ) || ! hash_equals( $hash, $cookie_hash ) ) {
204
+		if (empty($cookie_hash) || !hash_equals($hash, $cookie_hash)) {
205 205
 			return false;
206 206
 		}
207 207
 
208
-		return array( $customer_id, $session_expiration, $session_expiring, $cookie_hash );
208
+		return array($customer_id, $session_expiration, $session_expiring, $cookie_hash);
209 209
 	}
210 210
 
211 211
 	/**
@@ -214,15 +214,15 @@  discard block
 block discarded – undo
214 214
 	 * @return array
215 215
 	 */
216 216
 	public function get_session_data() {
217
-		return $this->has_session() ? (array) $this->get_session( $this->_customer_id ) : array();
217
+		return $this->has_session() ? (array) $this->get_session($this->_customer_id) : array();
218 218
 	}
219 219
 
220
-	public function generate_key($customer_id){
221
-        if(!$customer_id){
220
+	public function generate_key($customer_id) {
221
+        if (!$customer_id) {
222 222
             return;
223 223
         }
224 224
 
225
-        return 'wpi_trans_'.$customer_id;
225
+        return 'wpi_trans_' . $customer_id;
226 226
     }
227 227
 
228 228
 	/**
@@ -230,9 +230,9 @@  discard block
 block discarded – undo
230 230
 	 */
231 231
 	public function save_data() {
232 232
 		// Dirty if something changed - prevents saving nothing new.
233
-		if ( $this->_dirty && $this->has_session() ) {
233
+		if ($this->_dirty && $this->has_session()) {
234 234
 
235
-            set_transient( $this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration);
235
+            set_transient($this->generate_key($this->_customer_id), $this->_data, $this->_session_expiration);
236 236
 
237 237
 			$this->_dirty = false;
238 238
 		}
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 * Destroy all session data.
243 243
 	 */
244 244
 	public function destroy_session() {
245
-		$this->delete_session( $this->_customer_id );
245
+		$this->delete_session($this->_customer_id);
246 246
 		$this->forget_session();
247 247
 	}
248 248
 
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
 	 * Forget all session data without destroying it.
251 251
 	 */
252 252
 	public function forget_session() {
253
-		$this->setcookie( $this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true );
253
+		$this->setcookie($this->_cookie, '', time() - YEAR_IN_SECONDS, $this->use_secure_cookie(), true);
254 254
 
255 255
 		wpinv_empty_cart();
256 256
 
@@ -265,7 +265,7 @@  discard block
 block discarded – undo
265 265
 	 * @param int $uid User ID.
266 266
 	 * @return string
267 267
 	 */
268
-	public function nonce_user_logged_out( $uid ) {
268
+	public function nonce_user_logged_out($uid) {
269 269
 		return $this->has_session() && $this->_customer_id ? $this->_customer_id : $uid;
270 270
 	}
271 271
 
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
 	 * @param mixed  $default Default session value.
277 277
 	 * @return string|array
278 278
 	 */
279
-	public function get_session( $customer_id, $default = false ) {
279
+	public function get_session($customer_id, $default = false) {
280 280
 
281
-		if ( defined( 'WP_SETUP_CONFIG' ) ) {
281
+		if (defined('WP_SETUP_CONFIG')) {
282 282
 			return array();
283 283
 		}
284 284
 
285
-        if ( !is_user_logged_in() ) {
286
-            if(!wp_verify_nonce( $customer_id, 'wpinv-session-customer-id' )){
285
+        if (!is_user_logged_in()) {
286
+            if (!wp_verify_nonce($customer_id, 'wpinv-session-customer-id')) {
287 287
                 return array();
288 288
             }
289 289
         }
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
         $key = $this->generate_key($customer_id);
292 292
         $value = get_transient($key);
293 293
 
294
-        if ( !$value ) {
294
+        if (!$value) {
295 295
             $value = $default;
296 296
         }
297 297
 
298
-		return maybe_unserialize( $value );
298
+		return maybe_unserialize($value);
299 299
 	}
300 300
 
301 301
 	/**
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 	 *
304 304
 	 * @param int $customer_id Customer ID.
305 305
 	 */
306
-	public function delete_session( $customer_id ) {
306
+	public function delete_session($customer_id) {
307 307
 
308 308
         $key = $this->generate_key($customer_id);
309 309
 
@@ -316,9 +316,9 @@  discard block
 block discarded – undo
316 316
 	 * @param string $customer_id Customer ID.
317 317
 	 * @param int    $timestamp Timestamp to expire the cookie.
318 318
 	 */
319
-	public function update_session_timestamp( $customer_id, $timestamp ) {
319
+	public function update_session_timestamp($customer_id, $timestamp) {
320 320
 
321
-        set_transient( $this->generate_key($customer_id), maybe_serialize( $this->_data ), $timestamp);
321
+        set_transient($this->generate_key($customer_id), maybe_serialize($this->_data), $timestamp);
322 322
 
323 323
 	}
324 324
 }
Please login to merge, or discard this patch.