Passed
Pull Request — master (#377)
by Brian
05:03
created
includes/wpinv-general-functions.php 3 patches
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -67,8 +67,9 @@  discard block
 block discarded – undo
67 67
     
68 68
     if ( !empty( $args ) ) {
69 69
         // Check for backward compatibility
70
-        if ( is_string( $args ) )
71
-            $args = str_replace( '?', '', $args );
70
+        if ( is_string( $args ) ) {
71
+                    $args = str_replace( '?', '', $args );
72
+        }
72 73
 
73 74
         $args = wp_parse_args( $args );
74 75
 
@@ -87,8 +88,9 @@  discard block
 block discarded – undo
87 88
     
88 89
     if ( !empty( $args ) ) {
89 90
         // Check for backward compatibility
90
-        if ( is_string( $args ) )
91
-            $args = str_replace( '?', '', $args );
91
+        if ( is_string( $args ) ) {
92
+                    $args = str_replace( '?', '', $args );
93
+        }
92 94
 
93 95
         $args = wp_parse_args( $args );
94 96
 
@@ -108,8 +110,9 @@  discard block
 block discarded – undo
108 110
 
109 111
 	if ( !empty( $args ) ) {
110 112
 		// Check for backward compatibility
111
-		if ( is_string( $args ) )
112
-			$args = str_replace( '?', '', $args );
113
+		if ( is_string( $args ) ) {
114
+					$args = str_replace( '?', '', $args );
115
+		}
113 116
 
114 117
 		$args = wp_parse_args( $args );
115 118
 
@@ -132,8 +135,9 @@  discard block
 block discarded – undo
132 135
 
133 136
 	if ( ! empty( $args ) ) {
134 137
 		// Check for backward compatibility
135
-		if ( is_string( $args ) )
136
-			$args = str_replace( '?', '', $args );
138
+		if ( is_string( $args ) ) {
139
+					$args = str_replace( '?', '', $args );
140
+		}
137 141
 
138 142
 		$args = wp_parse_args( $args );
139 143
 
@@ -148,8 +152,9 @@  discard block
 block discarded – undo
148 152
 	$success_page = wpinv_get_option( 'success_page', 0 );
149 153
 	$success_page = get_permalink( $success_page );
150 154
 
151
-	if ( $query_string )
152
-		$success_page .= $query_string;
155
+	if ( $query_string ) {
156
+			$success_page .= $query_string;
157
+	}
153 158
 
154 159
 	return apply_filters( 'wpinv_success_page_url', $success_page );
155 160
 }
@@ -158,8 +163,9 @@  discard block
 block discarded – undo
158 163
 	$uri = wpinv_get_option( 'failure_page', '' );
159 164
 	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
160 165
 
161
-	if ( $extras )
162
-		$uri .= $extras;
166
+	if ( $extras ) {
167
+			$uri .= $extras;
168
+	}
163 169
 
164 170
 	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
165 171
 }
Please login to merge, or discard this patch.
Indentation   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -30,36 +30,36 @@  discard block
 block discarded – undo
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33
-	$can_checkout = true; // Always true for now
33
+    $can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+    return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+    $page_id = wpinv_get_option( 'success_page', 0 );
40
+    $page_id = absint( $page_id );
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+    return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+    $page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
+    $page_id = absint( $page_id );
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+    return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+    $is_success_page = wpinv_get_option( 'success_page', false );
54
+    $is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+    return apply_filters( 'wpinv_is_success_page', $is_success_page );
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+    $ret = wpinv_get_option( 'invoice_history_page', false );
61
+    $ret = $ret ? is_page( $ret ) : false;
62
+    return apply_filters( 'wpinv_is_invoice_history_page', $ret );
63 63
 }
64 64
 
65 65
 function wpinv_is_subscriptions_history_page() {
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 function wpinv_send_to_success_page( $args = null ) {
72
-	$redirect = wpinv_get_success_page_uri();
72
+    $redirect = wpinv_get_success_page_uri();
73 73
     
74 74
     if ( !empty( $args ) ) {
75 75
         // Check for backward compatibility
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 }
90 90
 
91 91
 function wpinv_send_to_failed_page( $args = null ) {
92
-	$redirect = wpinv_get_failed_transaction_uri();
92
+    $redirect = wpinv_get_failed_transaction_uri();
93 93
     
94 94
     if ( !empty( $args ) ) {
95 95
         // Check for backward compatibility
@@ -109,73 +109,73 @@  discard block
 block discarded – undo
109 109
 }
110 110
 
111 111
 function wpinv_get_checkout_uri( $args = array() ) {
112
-	$uri = wpinv_get_option( 'checkout_page', false );
113
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
112
+    $uri = wpinv_get_option( 'checkout_page', false );
113
+    $uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
114 114
 
115
-	if ( !empty( $args ) ) {
116
-		// Check for backward compatibility
117
-		if ( is_string( $args ) )
118
-			$args = str_replace( '?', '', $args );
115
+    if ( !empty( $args ) ) {
116
+        // Check for backward compatibility
117
+        if ( is_string( $args ) )
118
+            $args = str_replace( '?', '', $args );
119 119
 
120
-		$args = wp_parse_args( $args );
120
+        $args = wp_parse_args( $args );
121 121
 
122
-		$uri = add_query_arg( $args, $uri );
123
-	}
122
+        $uri = add_query_arg( $args, $uri );
123
+    }
124 124
 
125
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
125
+    $scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
126 126
 
127
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
127
+    $ajax_url = admin_url( 'admin-ajax.php', $scheme );
128 128
 
129
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
131
-	}
129
+    if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
+        $uri = preg_replace( '/^http:/', 'https:', $uri );
131
+    }
132 132
 
133
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
133
+    return apply_filters( 'wpinv_get_checkout_uri', $uri );
134 134
 }
135 135
 
136 136
 function wpinv_send_back_to_checkout( $args = array() ) {
137
-	$redirect = wpinv_get_checkout_uri();
137
+    $redirect = wpinv_get_checkout_uri();
138 138
 
139
-	if ( ! empty( $args ) ) {
140
-		// Check for backward compatibility
141
-		if ( is_string( $args ) )
142
-			$args = str_replace( '?', '', $args );
139
+    if ( ! empty( $args ) ) {
140
+        // Check for backward compatibility
141
+        if ( is_string( $args ) )
142
+            $args = str_replace( '?', '', $args );
143 143
 
144
-		$args = wp_parse_args( $args );
144
+        $args = wp_parse_args( $args );
145 145
 
146
-		$redirect = add_query_arg( $args, $redirect );
147
-	}
146
+        $redirect = add_query_arg( $args, $redirect );
147
+    }
148 148
 
149 149
     do_action( 'wpinv_pre_send_back_to_checkout', $args );
150
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
151
-	exit;
150
+    wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
151
+    exit;
152 152
 }
153 153
 
154 154
 function wpinv_get_success_page_url( $query_string = null ) {
155
-	$success_page = wpinv_get_option( 'success_page', 0 );
156
-	$success_page = get_permalink( $success_page );
155
+    $success_page = wpinv_get_option( 'success_page', 0 );
156
+    $success_page = get_permalink( $success_page );
157 157
 
158
-	if ( $query_string )
159
-		$success_page .= $query_string;
158
+    if ( $query_string )
159
+        $success_page .= $query_string;
160 160
 
161
-	return apply_filters( 'wpinv_success_page_url', $success_page );
161
+    return apply_filters( 'wpinv_success_page_url', $success_page );
162 162
 }
163 163
 
164 164
 function wpinv_get_failed_transaction_uri( $extras = false ) {
165
-	$uri = wpinv_get_option( 'failure_page', '' );
166
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
165
+    $uri = wpinv_get_option( 'failure_page', '' );
166
+    $uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
167 167
 
168
-	if ( $extras )
169
-		$uri .= $extras;
168
+    if ( $extras )
169
+        $uri .= $extras;
170 170
 
171
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
171
+    return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
172 172
 }
173 173
 
174 174
 function wpinv_is_failed_transaction_page() {
175
-	$ret = wpinv_get_option( 'failure_page', false );
176
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
175
+    $ret = wpinv_get_option( 'failure_page', false );
176
+    $ret = isset( $ret ) ? is_page( $ret ) : false;
177 177
 
178
-	return apply_filters( 'wpinv_is_failure_page', $ret );
178
+    return apply_filters( 'wpinv_is_failure_page', $ret );
179 179
 }
180 180
 
181 181
 function wpinv_transaction_query( $type = 'start' ) {
@@ -325,36 +325,36 @@  discard block
 block discarded – undo
325 325
     $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
326 326
     
327 327
     if ( $require_billing_details ) {
328
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
329
-			$required_fields['first_name'] = array(
330
-				'error_id' => 'invalid_first_name',
331
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
332
-			);
333
-		}
334
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
335
-			$required_fields['address'] = array(
336
-				'error_id' => 'invalid_address',
337
-				'error_message' => __( 'Please enter your address', 'invoicing' )
338
-			);
339
-		}
340
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
341
-			$required_fields['city'] = array(
342
-				'error_id' => 'invalid_city',
343
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
344
-			);
345
-		}
346
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
347
-			$required_fields['state'] = array(
348
-				'error_id' => 'invalid_state',
349
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
350
-			);
351
-		}
352
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
353
-			$required_fields['country'] = array(
354
-				'error_id' => 'invalid_country',
355
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
356
-			);
357
-		}
328
+        if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
329
+            $required_fields['first_name'] = array(
330
+                'error_id' => 'invalid_first_name',
331
+                'error_message' => __( 'Please enter your first name', 'invoicing' )
332
+            );
333
+        }
334
+        if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
335
+            $required_fields['address'] = array(
336
+                'error_id' => 'invalid_address',
337
+                'error_message' => __( 'Please enter your address', 'invoicing' )
338
+            );
339
+        }
340
+        if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
341
+            $required_fields['city'] = array(
342
+                'error_id' => 'invalid_city',
343
+                'error_message' => __( 'Please enter your billing city', 'invoicing' )
344
+            );
345
+        }
346
+        if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
347
+            $required_fields['state'] = array(
348
+                'error_id' => 'invalid_state',
349
+                'error_message' => __( 'Please enter billing state / province', 'invoicing' )
350
+            );
351
+        }
352
+        if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
353
+            $required_fields['country'] = array(
354
+                'error_id' => 'invalid_country',
355
+                'error_message' => __( 'Please select your billing country', 'invoicing' )
356
+            );
357
+        }
358 358
     }
359 359
 
360 360
     return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
Please login to merge, or discard this patch.
Spacing   +186 added lines, -186 removed lines patch added patch discarded remove patch
@@ -7,202 +7,202 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $is_checkout      = is_page( wpinv_get_option( 'checkout_page' ) );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $is_checkout      = is_page(wpinv_get_option('checkout_page'));
20 20
 
21
-    if ( !$is_object_set ) {
22
-        unset( $wp_query->queried_object );
21
+    if (!$is_object_set) {
22
+        unset($wp_query->queried_object);
23 23
     }
24 24
 
25
-    if ( !$is_object_id_set ) {
26
-        unset( $wp_query->queried_object_id );
25
+    if (!$is_object_id_set) {
26
+        unset($wp_query->queried_object_id);
27 27
     }
28 28
 
29
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
29
+    return apply_filters('wpinv_is_checkout', $is_checkout);
30 30
 }
31 31
 
32 32
 function wpinv_can_checkout() {
33 33
 	$can_checkout = true; // Always true for now
34 34
 
35
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
35
+	return (bool) apply_filters('wpinv_can_checkout', $can_checkout);
36 36
 }
37 37
 
38 38
 function wpinv_get_success_page_uri() {
39
-	$page_id = wpinv_get_option( 'success_page', 0 );
40
-	$page_id = absint( $page_id );
39
+	$page_id = wpinv_get_option('success_page', 0);
40
+	$page_id = absint($page_id);
41 41
 
42
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
42
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
43 43
 }
44 44
 
45 45
 function wpinv_get_history_page_uri() {
46
-	$page_id = wpinv_get_option( 'invoice_history_page', 0 );
47
-	$page_id = absint( $page_id );
46
+	$page_id = wpinv_get_option('invoice_history_page', 0);
47
+	$page_id = absint($page_id);
48 48
 
49
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ) );
49
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id));
50 50
 }
51 51
 
52 52
 function wpinv_is_success_page() {
53
-	$is_success_page = wpinv_get_option( 'success_page', false );
54
-	$is_success_page = isset( $is_success_page ) ? is_page( $is_success_page ) : false;
53
+	$is_success_page = wpinv_get_option('success_page', false);
54
+	$is_success_page = isset($is_success_page) ? is_page($is_success_page) : false;
55 55
 
56
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
56
+	return apply_filters('wpinv_is_success_page', $is_success_page);
57 57
 }
58 58
 
59 59
 function wpinv_is_invoice_history_page() {
60
-	$ret = wpinv_get_option( 'invoice_history_page', false );
61
-	$ret = $ret ? is_page( $ret ) : false;
62
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
60
+	$ret = wpinv_get_option('invoice_history_page', false);
61
+	$ret = $ret ? is_page($ret) : false;
62
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
63 63
 }
64 64
 
65 65
 function wpinv_is_subscriptions_history_page() {
66
-    $ret = wpinv_get_option( 'invoice_subscription_page', false );
67
-    $ret = $ret ? is_page( $ret ) : false;
68
-    return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );
66
+    $ret = wpinv_get_option('invoice_subscription_page', false);
67
+    $ret = $ret ? is_page($ret) : false;
68
+    return apply_filters('wpinv_is_subscriptions_history_page', $ret);
69 69
 }
70 70
 
71
-function wpinv_send_to_success_page( $args = null ) {
71
+function wpinv_send_to_success_page($args = null) {
72 72
 	$redirect = wpinv_get_success_page_uri();
73 73
     
74
-    if ( !empty( $args ) ) {
74
+    if (!empty($args)) {
75 75
         // Check for backward compatibility
76
-        if ( is_string( $args ) )
77
-            $args = str_replace( '?', '', $args );
76
+        if (is_string($args))
77
+            $args = str_replace('?', '', $args);
78 78
 
79
-        $args = wp_parse_args( $args );
79
+        $args = wp_parse_args($args);
80 80
 
81
-        $redirect = add_query_arg( $args, $redirect );
81
+        $redirect = add_query_arg($args, $redirect);
82 82
     }
83 83
 
84
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
84
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
85 85
     
86
-    $redirect = apply_filters( 'wpinv_success_page_redirect', $redirect, $gateway, $args );
87
-    wp_redirect( $redirect );
86
+    $redirect = apply_filters('wpinv_success_page_redirect', $redirect, $gateway, $args);
87
+    wp_redirect($redirect);
88 88
     exit;
89 89
 }
90 90
 
91
-function wpinv_send_to_failed_page( $args = null ) {
91
+function wpinv_send_to_failed_page($args = null) {
92 92
 	$redirect = wpinv_get_failed_transaction_uri();
93 93
     
94
-    if ( !empty( $args ) ) {
94
+    if (!empty($args)) {
95 95
         // Check for backward compatibility
96
-        if ( is_string( $args ) )
97
-            $args = str_replace( '?', '', $args );
96
+        if (is_string($args))
97
+            $args = str_replace('?', '', $args);
98 98
 
99
-        $args = wp_parse_args( $args );
99
+        $args = wp_parse_args($args);
100 100
 
101
-        $redirect = add_query_arg( $args, $redirect );
101
+        $redirect = add_query_arg($args, $redirect);
102 102
     }
103 103
 
104
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
104
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
105 105
     
106
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
107
-    wp_redirect( $redirect );
106
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
107
+    wp_redirect($redirect);
108 108
     exit;
109 109
 }
110 110
 
111
-function wpinv_get_checkout_uri( $args = array() ) {
112
-	$uri = wpinv_get_option( 'checkout_page', false );
113
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
111
+function wpinv_get_checkout_uri($args = array()) {
112
+	$uri = wpinv_get_option('checkout_page', false);
113
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
114 114
 
115
-	if ( !empty( $args ) ) {
115
+	if (!empty($args)) {
116 116
 		// Check for backward compatibility
117
-		if ( is_string( $args ) )
118
-			$args = str_replace( '?', '', $args );
117
+		if (is_string($args))
118
+			$args = str_replace('?', '', $args);
119 119
 
120
-		$args = wp_parse_args( $args );
120
+		$args = wp_parse_args($args);
121 121
 
122
-		$uri = add_query_arg( $args, $uri );
122
+		$uri = add_query_arg($args, $uri);
123 123
 	}
124 124
 
125
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
125
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
126 126
 
127
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
127
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
128 128
 
129
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
129
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
130
+		$uri = preg_replace('/^http:/', 'https:', $uri);
131 131
 	}
132 132
 
133
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
133
+	return apply_filters('wpinv_get_checkout_uri', $uri);
134 134
 }
135 135
 
136
-function wpinv_send_back_to_checkout( $args = array() ) {
136
+function wpinv_send_back_to_checkout($args = array()) {
137 137
 	$redirect = wpinv_get_checkout_uri();
138 138
 
139
-	if ( ! empty( $args ) ) {
139
+	if (!empty($args)) {
140 140
 		// Check for backward compatibility
141
-		if ( is_string( $args ) )
142
-			$args = str_replace( '?', '', $args );
141
+		if (is_string($args))
142
+			$args = str_replace('?', '', $args);
143 143
 
144
-		$args = wp_parse_args( $args );
144
+		$args = wp_parse_args($args);
145 145
 
146
-		$redirect = add_query_arg( $args, $redirect );
146
+		$redirect = add_query_arg($args, $redirect);
147 147
 	}
148 148
 
149
-    do_action( 'wpinv_pre_send_back_to_checkout', $args );
150
-	wp_redirect( apply_filters( 'wpinv_send_back_to_checkout', $redirect, $args ) );
149
+    do_action('wpinv_pre_send_back_to_checkout', $args);
150
+	wp_redirect(apply_filters('wpinv_send_back_to_checkout', $redirect, $args));
151 151
 	exit;
152 152
 }
153 153
 
154
-function wpinv_get_success_page_url( $query_string = null ) {
155
-	$success_page = wpinv_get_option( 'success_page', 0 );
156
-	$success_page = get_permalink( $success_page );
154
+function wpinv_get_success_page_url($query_string = null) {
155
+	$success_page = wpinv_get_option('success_page', 0);
156
+	$success_page = get_permalink($success_page);
157 157
 
158
-	if ( $query_string )
158
+	if ($query_string)
159 159
 		$success_page .= $query_string;
160 160
 
161
-	return apply_filters( 'wpinv_success_page_url', $success_page );
161
+	return apply_filters('wpinv_success_page_url', $success_page);
162 162
 }
163 163
 
164
-function wpinv_get_failed_transaction_uri( $extras = false ) {
165
-	$uri = wpinv_get_option( 'failure_page', '' );
166
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
164
+function wpinv_get_failed_transaction_uri($extras = false) {
165
+	$uri = wpinv_get_option('failure_page', '');
166
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
167 167
 
168
-	if ( $extras )
168
+	if ($extras)
169 169
 		$uri .= $extras;
170 170
 
171
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
171
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
172 172
 }
173 173
 
174 174
 function wpinv_is_failed_transaction_page() {
175
-	$ret = wpinv_get_option( 'failure_page', false );
176
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
175
+	$ret = wpinv_get_option('failure_page', false);
176
+	$ret = isset($ret) ? is_page($ret) : false;
177 177
 
178
-	return apply_filters( 'wpinv_is_failure_page', $ret );
178
+	return apply_filters('wpinv_is_failure_page', $ret);
179 179
 }
180 180
 
181
-function wpinv_transaction_query( $type = 'start' ) {
181
+function wpinv_transaction_query($type = 'start') {
182 182
     global $wpdb;
183 183
 
184 184
     $wpdb->hide_errors();
185 185
 
186
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
187
-        define( 'WPINV_USE_TRANSACTIONS', true );
186
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
187
+        define('WPINV_USE_TRANSACTIONS', true);
188 188
     }
189 189
 
190
-    if ( WPINV_USE_TRANSACTIONS ) {
191
-        switch ( $type ) {
190
+    if (WPINV_USE_TRANSACTIONS) {
191
+        switch ($type) {
192 192
             case 'commit' :
193
-                $wpdb->query( 'COMMIT' );
193
+                $wpdb->query('COMMIT');
194 194
                 break;
195 195
             case 'rollback' :
196
-                $wpdb->query( 'ROLLBACK' );
196
+                $wpdb->query('ROLLBACK');
197 197
                 break;
198 198
             default :
199
-                $wpdb->query( 'START TRANSACTION' );
199
+                $wpdb->query('START TRANSACTION');
200 200
             break;
201 201
         }
202 202
     }
203 203
 }
204 204
 
205
-function wpinv_create_invoice( $args = array(), $data = array(), $wp_error = false ) {
205
+function wpinv_create_invoice($args = array(), $data = array(), $wp_error = false) {
206 206
     $default_args = array(
207 207
         'status'        => '',
208 208
         'user_id'       => null,
@@ -213,66 +213,66 @@  discard block
 block discarded – undo
213 213
         'post_type'     => 'wpi_invoice'
214 214
     );
215 215
 
216
-    $args           = wp_parse_args( $args, $default_args );
216
+    $args           = wp_parse_args($args, $default_args);
217 217
     $invoice_data   = array();
218 218
 
219
-    if ( $args['invoice_id'] > 0 ) {
220
-        $updating           = true;
219
+    if ($args['invoice_id'] > 0) {
220
+        $updating = true;
221 221
         $invoice_data['post_type']  = $args['post_type'];
222 222
         $invoice_data['ID']         = $args['invoice_id'];
223 223
     } else {
224 224
         $updating                       = false;
225 225
         $invoice_data['post_type']      = $args['post_type'];
226
-        $invoice_data['post_status']    = apply_filters( 'wpinv_default_invoice_status', 'wpi-pending' );
226
+        $invoice_data['post_status']    = apply_filters('wpinv_default_invoice_status', 'wpi-pending');
227 227
         $invoice_data['ping_status']    = 'closed';
228
-        $invoice_data['post_author']    = !empty( $args['user_id'] ) ? $args['user_id'] : get_current_user_id();
229
-        $invoice_data['post_title']     = wpinv_format_invoice_number( '0' );
230
-        $invoice_data['post_parent']    = absint( $args['parent'] );
231
-        if ( !empty( $args['created_date'] ) ) {
228
+        $invoice_data['post_author']    = !empty($args['user_id']) ? $args['user_id'] : get_current_user_id();
229
+        $invoice_data['post_title']     = wpinv_format_invoice_number('0');
230
+        $invoice_data['post_parent']    = absint($args['parent']);
231
+        if (!empty($args['created_date'])) {
232 232
             $invoice_data['post_date']      = $args['created_date'];
233
-            $invoice_data['post_date_gmt']  = get_gmt_from_date( $args['created_date'] );
233
+            $invoice_data['post_date_gmt']  = get_gmt_from_date($args['created_date']);
234 234
         }
235 235
     }
236 236
 
237
-    if ( $args['status'] ) {
238
-        if ( ! in_array( $args['status'], array_keys( wpinv_get_invoice_statuses() ) ) && 'wpi_invoice' === $invoice_data['post_type'] ) {
239
-            return new WP_Error( 'wpinv_invalid_invoice_status', wp_sprintf( __( 'Invalid invoice status: %s', 'invoicing' ), $args['status'] ) );
237
+    if ($args['status']) {
238
+        if (!in_array($args['status'], array_keys(wpinv_get_invoice_statuses())) && 'wpi_invoice' === $invoice_data['post_type']) {
239
+            return new WP_Error('wpinv_invalid_invoice_status', wp_sprintf(__('Invalid invoice status: %s', 'invoicing'), $args['status']));
240 240
         }
241
-        $invoice_data['post_status']    = $args['status'];
241
+        $invoice_data['post_status'] = $args['status'];
242 242
     }
243 243
 
244
-    if ( ! is_null( $args['user_note'] ) ) {
245
-        $invoice_data['post_excerpt']   = $args['user_note'];
244
+    if (!is_null($args['user_note'])) {
245
+        $invoice_data['post_excerpt'] = $args['user_note'];
246 246
     }
247 247
 
248
-    if ( $updating ) {
249
-        $invoice_id = wp_update_post( $invoice_data, true );
248
+    if ($updating) {
249
+        $invoice_id = wp_update_post($invoice_data, true);
250 250
     } else {
251
-        $invoice_id = wp_insert_post( apply_filters( 'wpinv_new_invoice_data', $invoice_data ), true );
251
+        $invoice_id = wp_insert_post(apply_filters('wpinv_new_invoice_data', $invoice_data), true);
252 252
     }
253 253
 
254
-    if ( is_wp_error( $invoice_id ) ) {
254
+    if (is_wp_error($invoice_id)) {
255 255
         return $wp_error ? $invoice_id : 0;
256 256
     }
257 257
     
258
-    $invoice = wpinv_get_invoice( $invoice_id );
259
-
260
-    if ( !$updating ) {
261
-        update_post_meta( $invoice_id, '_wpinv_key', apply_filters( 'wpinv_generate_invoice_key', uniqid( 'wpinv_' ) ) );
262
-        update_post_meta( $invoice_id, '_wpinv_currency', wpinv_get_currency() );
263
-        update_post_meta( $invoice_id, '_wpinv_include_tax', get_option( 'wpinv_prices_include_tax' ) );
264
-        update_post_meta( $invoice_id, '_wpinv_user_ip', wpinv_get_ip() );
265
-        update_post_meta( $invoice_id, '_wpinv_user_agent', wpinv_get_user_agent() );
266
-        update_post_meta( $invoice_id, '_wpinv_created_via', sanitize_text_field( $args['created_via'] ) );
258
+    $invoice = wpinv_get_invoice($invoice_id);
259
+
260
+    if (!$updating) {
261
+        update_post_meta($invoice_id, '_wpinv_key', apply_filters('wpinv_generate_invoice_key', uniqid('wpinv_')));
262
+        update_post_meta($invoice_id, '_wpinv_currency', wpinv_get_currency());
263
+        update_post_meta($invoice_id, '_wpinv_include_tax', get_option('wpinv_prices_include_tax'));
264
+        update_post_meta($invoice_id, '_wpinv_user_ip', wpinv_get_ip());
265
+        update_post_meta($invoice_id, '_wpinv_user_agent', wpinv_get_user_agent());
266
+        update_post_meta($invoice_id, '_wpinv_created_via', sanitize_text_field($args['created_via']));
267 267
         
268 268
         // Add invoice note
269
-        if ( ! $invoice->is_quote() ) {
270
-            $invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
269
+        if (!$invoice->is_quote()) {
270
+            $invoice->add_note(wp_sprintf(__('Invoice is created with status %s.', 'invoicing'), wpinv_status_nicename($invoice->status)));
271 271
         }
272 272
         
273 273
     }
274 274
 
275
-    update_post_meta( $invoice_id, '_wpinv_version', WPINV_VERSION );
275
+    update_post_meta($invoice_id, '_wpinv_version', WPINV_VERSION);
276 276
 
277 277
     return $invoice;
278 278
 }
@@ -280,193 +280,193 @@  discard block
 block discarded – undo
280 280
 function wpinv_get_prefix() {
281 281
     $invoice_prefix = 'INV-';
282 282
     
283
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
283
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
284 284
 }
285 285
 
286 286
 function wpinv_get_business_logo() {
287
-    $business_logo = wpinv_get_option( 'logo' );
288
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
287
+    $business_logo = wpinv_get_option('logo');
288
+    return apply_filters('wpinv_get_business_logo', $business_logo);
289 289
 }
290 290
 
291 291
 function wpinv_get_business_name() {
292 292
     $business_name = wpinv_get_option('store_name');
293
-    return apply_filters( 'wpinv_get_business_name', $business_name );
293
+    return apply_filters('wpinv_get_business_name', $business_name);
294 294
 }
295 295
 
296 296
 function wpinv_get_blogname() {
297
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
297
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
298 298
 }
299 299
 
300 300
 function wpinv_get_admin_email() {
301
-    $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) );
302
-    return apply_filters( 'wpinv_admin_email', $admin_email );
301
+    $admin_email = wpinv_get_option('admin_email', get_option('admin_email'));
302
+    return apply_filters('wpinv_admin_email', $admin_email);
303 303
 }
304 304
 
305 305
 function wpinv_get_business_website() {
306
-    $business_website = home_url( '/' );
307
-    return apply_filters( 'wpinv_get_business_website', $business_website );
306
+    $business_website = home_url('/');
307
+    return apply_filters('wpinv_get_business_website', $business_website);
308 308
 }
309 309
 
310
-function wpinv_get_terms_text( $invoice_id = 0 ) {
310
+function wpinv_get_terms_text($invoice_id = 0) {
311 311
     $terms_text = '';
312
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
312
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
313 313
 }
314 314
 
315 315
 function wpinv_get_business_footer() {
316
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
317
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
318
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
316
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
317
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
318
+    return apply_filters('wpinv_get_business_footer', $business_footer);
319 319
 }
320 320
 
321 321
 function wpinv_checkout_required_fields() {
322 322
     $required_fields = array();
323 323
     
324 324
     // Let payment gateways and other extensions determine if address fields should be required
325
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
325
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
326 326
     
327
-    if ( $require_billing_details ) {
328
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
327
+    if ($require_billing_details) {
328
+		if ((bool) wpinv_get_option('fname_mandatory')) {
329 329
 			$required_fields['first_name'] = array(
330 330
 				'error_id' => 'invalid_first_name',
331
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
331
+				'error_message' => __('Please enter your first name', 'invoicing')
332 332
 			);
333 333
 		}
334
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
334
+		if ((bool) wpinv_get_option('address_mandatory')) {
335 335
 			$required_fields['address'] = array(
336 336
 				'error_id' => 'invalid_address',
337
-				'error_message' => __( 'Please enter your address', 'invoicing' )
337
+				'error_message' => __('Please enter your address', 'invoicing')
338 338
 			);
339 339
 		}
340
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
340
+		if ((bool) wpinv_get_option('city_mandatory')) {
341 341
 			$required_fields['city'] = array(
342 342
 				'error_id' => 'invalid_city',
343
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
343
+				'error_message' => __('Please enter your billing city', 'invoicing')
344 344
 			);
345 345
 		}
346
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
346
+		if ((bool) wpinv_get_option('state_mandatory')) {
347 347
 			$required_fields['state'] = array(
348 348
 				'error_id' => 'invalid_state',
349
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
349
+				'error_message' => __('Please enter billing state / province', 'invoicing')
350 350
 			);
351 351
 		}
352
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
352
+		if ((bool) wpinv_get_option('country_mandatory')) {
353 353
 			$required_fields['country'] = array(
354 354
 				'error_id' => 'invalid_country',
355
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
355
+				'error_message' => __('Please select your billing country', 'invoicing')
356 356
 			);
357 357
 		}
358 358
     }
359 359
 
360
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
360
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
361 361
 }
362 362
 
363 363
 function wpinv_is_ssl_enforced() {
364
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
365
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
364
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
365
+    return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
366 366
 }
367 367
 
368
-function wpinv_user_can_view_invoice( $post ) {
368
+function wpinv_user_can_view_invoice($post) {
369 369
     $allow = false;
370 370
 
371
-    $post = get_post( $post );
371
+    $post = get_post($post);
372 372
 
373
-    if ( empty( $post->ID ) ) {
373
+    if (empty($post->ID)) {
374 374
         return $allow;
375 375
     }
376 376
 
377
-    $invoice = wpinv_get_invoice( $post->ID );
378
-    if ( empty( $invoice->ID ) ) {
377
+    $invoice = wpinv_get_invoice($post->ID);
378
+    if (empty($invoice->ID)) {
379 379
         return $allow;
380 380
     }
381 381
 
382 382
     // Don't allow trash, draft status
383
-    if ( $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
384
-        if ( wpinv_current_user_can_manage_invoicing() || current_user_can( 'view_invoices', $invoice->ID ) ) { // Admin user
383
+    if ($invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
384
+        if (wpinv_current_user_can_manage_invoicing() || current_user_can('view_invoices', $invoice->ID)) { // Admin user
385 385
             $allow = true;
386 386
         } else {
387
-            if ( is_user_logged_in() ) {
388
-                if ( (int)$invoice->get_user_id() === (int)get_current_user_id() ) {
387
+            if (is_user_logged_in()) {
388
+                if ((int) $invoice->get_user_id() === (int) get_current_user_id()) {
389 389
                     $allow = true;
390
-                } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
390
+                } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
391 391
                     $allow = true;
392 392
                 }
393 393
             } else {
394
-                if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
394
+                if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
395 395
                     $allow = true;
396 396
                 }
397 397
             }
398 398
         }
399 399
     }
400 400
     
401
-    return apply_filters( 'wpinv_can_print_invoice', $allow, $post, $invoice );
401
+    return apply_filters('wpinv_can_print_invoice', $allow, $post, $invoice);
402 402
 }
403 403
 
404 404
 function wpinv_schedule_events() {
405 405
 
406 406
     // Get the timestamp for the next event.
407
-    $timestamp = wp_next_scheduled( 'wpinv_register_schedule_event_twicedaily' );
407
+    $timestamp = wp_next_scheduled('wpinv_register_schedule_event_twicedaily');
408 408
 
409
-    if ( $timestamp ) {
410
-        wp_unschedule_event( $timestamp, 'wpinv_register_schedule_event_twicedaily' );
409
+    if ($timestamp) {
410
+        wp_unschedule_event($timestamp, 'wpinv_register_schedule_event_twicedaily');
411 411
     }
412 412
 
413
-    if ( ! wp_next_scheduled( 'wpinv_register_schedule_event_daily' ) ) {
414
-        wp_schedule_event( current_time( 'timestamp' ), 'daily', 'wpinv_register_schedule_event_daily' );
413
+    if (!wp_next_scheduled('wpinv_register_schedule_event_daily')) {
414
+        wp_schedule_event(current_time('timestamp'), 'daily', 'wpinv_register_schedule_event_daily');
415 415
     }
416 416
 }
417
-add_action( 'wp', 'wpinv_schedule_events' );
417
+add_action('wp', 'wpinv_schedule_events');
418 418
 
419 419
 function wpinv_schedule_event_twicedaily() {
420 420
     wpinv_email_payment_reminders();
421 421
     wpinv_email_renewal_reminders();
422 422
 }
423
-add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' );
423
+add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily');
424 424
 
425 425
 function wpinv_require_login_to_checkout() {
426
-    $return = wpinv_get_option( 'login_to_checkout', false );
427
-    return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );
426
+    $return = wpinv_get_option('login_to_checkout', false);
427
+    return (bool) apply_filters('wpinv_require_login_to_checkout', $return);
428 428
 }
429 429
 
430
-function wpinv_sequential_number_active( $type = '' ) {
431
-    $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );
432
-    if ( null !== $check ) {
430
+function wpinv_sequential_number_active($type = '') {
431
+    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type);
432
+    if (null !== $check) {
433 433
         return $check;
434 434
     }
435 435
     
436
-    return wpinv_get_option( 'sequential_invoice_number' );
436
+    return wpinv_get_option('sequential_invoice_number');
437 437
 }
438 438
 
439
-function wpinv_switch_to_locale( $locale = NULL ) {
439
+function wpinv_switch_to_locale($locale = NULL) {
440 440
     global $invoicing, $wpi_switch_locale;
441 441
 
442
-    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) {
443
-        $locale = empty( $locale ) ? get_locale() : $locale;
442
+    if (!empty($invoicing) && function_exists('switch_to_locale')) {
443
+        $locale = empty($locale) ? get_locale() : $locale;
444 444
 
445
-        switch_to_locale( $locale );
445
+        switch_to_locale($locale);
446 446
 
447 447
         $wpi_switch_locale = $locale;
448 448
 
449
-        add_filter( 'plugin_locale', 'get_locale' );
449
+        add_filter('plugin_locale', 'get_locale');
450 450
 
451 451
         $invoicing->load_textdomain();
452 452
 
453
-        do_action( 'wpinv_switch_to_locale', $locale );
453
+        do_action('wpinv_switch_to_locale', $locale);
454 454
     }
455 455
 }
456 456
 
457 457
 function wpinv_restore_locale() {
458 458
     global $invoicing, $wpi_switch_locale;
459 459
     
460
-    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) {
460
+    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) {
461 461
         restore_previous_locale();
462 462
 
463 463
         $wpi_switch_locale = NULL;
464 464
 
465
-        remove_filter( 'plugin_locale', 'get_locale' );
465
+        remove_filter('plugin_locale', 'get_locale');
466 466
 
467 467
         $invoicing->load_textdomain();
468 468
 
469
-        do_action( 'wpinv_restore_locale' );
469
+        do_action('wpinv_restore_locale');
470 470
     }
471 471
 }
472 472
 
@@ -474,22 +474,22 @@  discard block
 block discarded – undo
474 474
  * Returns the default form's id.
475 475
  */
476 476
 function wpinv_get_default_payment_form() {
477
-    $form = get_option( 'wpinv_default_payment_form' );
477
+    $form = get_option('wpinv_default_payment_form');
478 478
 
479
-    if ( empty( $form ) || 'publish' != get_post_status( $form ) ) {
479
+    if (empty($form) || 'publish' != get_post_status($form)) {
480 480
         $form = wp_insert_post(
481 481
             array(
482 482
                 'post_type'   => 'wpi_payment_form',
483
-                'post_title'  => __( 'Checkout (default)', 'invoicing' ),
483
+                'post_title'  => __('Checkout (default)', 'invoicing'),
484 484
                 'post_status' => 'publish',
485 485
                 'meta_input'  => array(
486
-                    'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ),
486
+                    'wpinv_form_elements' => wpinv_get_data('default-payment-form'),
487 487
                     'wpinv_form_items'    => array(),
488 488
                 )
489 489
             )
490 490
         );
491 491
 
492
-        update_option( 'wpinv_default_payment_form', $form );
492
+        update_option('wpinv_default_payment_form', $form);
493 493
     }
494 494
 
495 495
     return $form;
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -196,8 +196,9 @@
 block discarded – undo
196 196
             foreach ( $types as $name => $type ) {
197 197
                 echo '<option value="' . esc_attr( $name ) . '"';
198 198
 
199
-                if ( isset( $_GET['discount_type'] ) )
200
-                    selected( $name, $_GET['discount_type'] );
199
+                if ( isset( $_GET['discount_type'] ) ) {
200
+                                    selected( $name, $_GET['discount_type'] );
201
+                }
201 202
 
202 203
                 echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
203 204
             }
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -1,38 +1,38 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_filter( 'manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns' );
8
-function wpinv_payment_form_columns( $existing_columns ) {
7
+add_filter('manage_wpi_payment_form_posts_columns', 'wpinv_payment_form_columns');
8
+function wpinv_payment_form_columns($existing_columns) {
9 9
     $date = $existing_columns['date'];
10
-    unset( $existing_columns['date'] );
11
-    $existing_columns['shortcode'] = __( 'Shortcode', 'invoicing' );
10
+    unset($existing_columns['date']);
11
+    $existing_columns['shortcode'] = __('Shortcode', 'invoicing');
12 12
     $existing_columns['date'] = $date;
13 13
     return $existing_columns;
14 14
 }
15 15
 
16
-add_action( 'manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column' );
17
-function wpinv_payment_form_custom_column( $column ) {
16
+add_action('manage_wpi_payment_form_posts_custom_column', 'wpinv_payment_form_custom_column');
17
+function wpinv_payment_form_custom_column($column) {
18 18
     global $post;
19 19
 
20
-    if( 'shortcode' == $column ) {
21
-        WPInv_Meta_Box_Payment_Form::output_shortcode( $post );
20
+    if ('shortcode' == $column) {
21
+        WPInv_Meta_Box_Payment_Form::output_shortcode($post);
22 22
     }
23 23
 
24 24
 }
25 25
 
26
-function wpinv_filter_discount_post_state( $post_states, $post ) {
26
+function wpinv_filter_discount_post_state($post_states, $post) {
27 27
 
28
-    if ( 'wpi_discount' == $post->post_type ) {
29
-        $discount = new WPInv_Discount( $post );
28
+    if ('wpi_discount' == $post->post_type) {
29
+        $discount = new WPInv_Discount($post);
30 30
 
31 31
         $status = $discount->is_expired() ? 'expired' : $discount->get_status();
32 32
 
33
-        if ( $status != 'publish' ) {
33
+        if ($status != 'publish') {
34 34
             return array(
35
-                'discount_status' => wpinv_discount_status( $status ),
35
+                'discount_status' => wpinv_discount_status($status),
36 36
             );
37 37
         }
38 38
 
@@ -43,35 +43,35 @@  discard block
 block discarded – undo
43 43
     return $post_states;
44 44
 
45 45
 }
46
-add_filter( 'display_post_states', 'wpinv_filter_discount_post_state', 10, 2 );
46
+add_filter('display_post_states', 'wpinv_filter_discount_post_state', 10, 2);
47 47
 
48
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
49
-function wpinv_discount_columns( $columns ) {
48
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
49
+function wpinv_discount_columns($columns) {
50 50
     
51
-    if ( isset( $columns['date'] ) ) {
52
-        unset( $columns['date'] );
51
+    if (isset($columns['date'])) {
52
+        unset($columns['date']);
53 53
     }
54 54
 
55
-    if ( isset( $columns['title'] ) ) {
56
-        $columns['title'] = __( 'Name', 'invoicing' );
55
+    if (isset($columns['title'])) {
56
+        $columns['title'] = __('Name', 'invoicing');
57 57
     }
58 58
 
59
-    $columns['code']        = __( 'Code', 'invoicing' );
60
-    $columns['amount']      = __( 'Amount', 'invoicing' );
61
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
62
-    $columns['start_date']  = __( 'Start Date', 'invoicing' );
63
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
59
+    $columns['code']        = __('Code', 'invoicing');
60
+    $columns['amount']      = __('Amount', 'invoicing');
61
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
62
+    $columns['start_date']  = __('Start Date', 'invoicing');
63
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
64 64
 
65 65
     return $columns;
66 66
 }
67 67
 
68
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
69
-function wpinv_discount_custom_column( $column ) {
68
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
69
+function wpinv_discount_custom_column($column) {
70 70
     global $post;
71 71
 
72
-    $discount = new WPInv_Discount( $post );
72
+    $discount = new WPInv_Discount($post);
73 73
 
74
-    switch ( $column ) {
74
+    switch ($column) {
75 75
         case 'code' :
76 76
             echo $discount->get_code();
77 77
         break;
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
             echo $discount->get_usage();
83 83
         break;
84 84
         case 'start_date' :
85
-            if ( $discount->has_start_date() ) {
86
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $discount->get_start_date() ) );
85
+            if ($discount->has_start_date()) {
86
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($discount->get_start_date()));
87 87
             } else {
88 88
                 $value = '&mdash;';
89 89
             }
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
             echo $value;
92 92
         break;
93 93
         case 'expiry_date' :
94
-            if ( $discount->has_expiration_date() ) {
95
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $discount->get_expiration_date() ) );
94
+            if ($discount->has_expiration_date()) {
95
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($discount->get_expiration_date()));
96 96
             } else {
97
-                $value = __( 'Never', 'invoicing' );
97
+                $value = __('Never', 'invoicing');
98 98
             }
99 99
 
100 100
             echo $value;
@@ -102,30 +102,30 @@  discard block
 block discarded – undo
102 102
     }
103 103
 }
104 104
 
105
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
106
-function wpinv_post_row_actions( $actions, $post ) {
107
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
105
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
106
+function wpinv_post_row_actions($actions, $post) {
107
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
108 108
 
109
-    if ( $post_type == 'wpi_invoice' ) {
109
+    if ($post_type == 'wpi_invoice') {
110 110
         $actions = array();
111 111
     }
112 112
 
113
-    if ( $post_type == 'wpi_discount' ) {
114
-        $actions = wpinv_discount_row_actions( $post, $actions );
113
+    if ($post_type == 'wpi_discount') {
114
+        $actions = wpinv_discount_row_actions($post, $actions);
115 115
     }
116 116
 
117 117
     return $actions;
118 118
 }
119 119
 
120
-function wpinv_discount_row_actions( $discount, $row_actions ) {
121
-    $row_actions  = array();
122
-    $edit_link = get_edit_post_link( $discount->ID );
123
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
120
+function wpinv_discount_row_actions($discount, $row_actions) {
121
+    $row_actions = array();
122
+    $edit_link = get_edit_post_link($discount->ID);
123
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
124 124
 
125
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
126
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
127
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
128
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
125
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
126
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
127
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
128
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
129 129
     }
130 130
 
131 131
     $delete_url = esc_url(
@@ -139,110 +139,110 @@  discard block
 block discarded – undo
139 139
             'wpinv_discount_nonce'
140 140
         )
141 141
     );
142
-    $row_actions['delete'] = '<a href="' . $delete_url . '">' . __( 'Delete', 'invoicing' ) . '</a>';
142
+    $row_actions['delete'] = '<a href="' . $delete_url . '">' . __('Delete', 'invoicing') . '</a>';
143 143
 
144
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
144
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
145 145
 
146 146
     return $row_actions;
147 147
 }
148 148
 
149
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
150
-function wpinv_table_primary_column( $default, $screen_id ) {
151
-    if ( 'edit-wpi_invoice' === $screen_id ) {
149
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
150
+function wpinv_table_primary_column($default, $screen_id) {
151
+    if ('edit-wpi_invoice' === $screen_id) {
152 152
         return 'name';
153 153
     }
154 154
 
155 155
     return $default;
156 156
 }
157 157
 
158
-function wpinv_discount_bulk_actions( $actions, $display = false ) {
159
-    if ( !$display ) {
158
+function wpinv_discount_bulk_actions($actions, $display = false) {
159
+    if (!$display) {
160 160
         return array();
161 161
     }
162 162
 
163 163
     $actions = array(
164
-        'activate'   => __( 'Activate', 'invoicing' ),
165
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
166
-        'delete'     => __( 'Delete', 'invoicing' ),
164
+        'activate'   => __('Activate', 'invoicing'),
165
+        'deactivate' => __('Deactivate', 'invoicing'),
166
+        'delete'     => __('Delete', 'invoicing'),
167 167
     );
168 168
     $two = '';
169 169
     $which = 'top';
170 170
     echo '</div><div class="alignleft actions bulkactions">';
171
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
172
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
173
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
171
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
172
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
173
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
174 174
 
175
-    foreach ( $actions as $name => $title ) {
175
+    foreach ($actions as $name => $title) {
176 176
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
177 177
 
178 178
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
179 179
     }
180 180
     echo "</select>";
181 181
 
182
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
182
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
183 183
 
184 184
     echo '</div><div class="alignleft actions">';
185 185
 }
186
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
186
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
187 187
 
188
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
189
-    if ( $post_type == 'wpi_discount' ) {
188
+function wpinv_disable_months_dropdown($disable, $post_type) {
189
+    if ($post_type == 'wpi_discount') {
190 190
         $disable = true;
191 191
     }
192 192
 
193 193
     return $disable;
194 194
 }
195
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
195
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
196 196
 
197 197
 function wpinv_restrict_manage_posts() {
198 198
     global $typenow;
199 199
 
200
-    if( 'wpi_discount' == $typenow ) {
200
+    if ('wpi_discount' == $typenow) {
201 201
         wpinv_discount_filters();
202 202
     }
203 203
 }
204
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
204
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
205 205
 
206 206
 function wpinv_discount_filters() {
207
-    echo wpinv_discount_bulk_actions( array(), true );
207
+    echo wpinv_discount_bulk_actions(array(), true);
208 208
 
209 209
     ?>
210 210
     <select name="discount_type" id="dropdown_wpinv_discount_type">
211
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
211
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
212 212
         <?php
213 213
             $types = wpinv_get_discount_types();
214 214
 
215
-            foreach ( $types as $name => $type ) {
216
-                echo '<option value="' . esc_attr( $name ) . '"';
215
+            foreach ($types as $name => $type) {
216
+                echo '<option value="' . esc_attr($name) . '"';
217 217
 
218
-                if ( isset( $_GET['discount_type'] ) )
219
-                    selected( $name, $_GET['discount_type'] );
218
+                if (isset($_GET['discount_type']))
219
+                    selected($name, $_GET['discount_type']);
220 220
 
221
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
221
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
222 222
             }
223 223
         ?>
224 224
     </select>
225 225
     <?php
226 226
 }
227 227
 
228
-function wpinv_request( $vars ) {
228
+function wpinv_request($vars) {
229 229
     global $typenow, $wp_query, $wp_post_statuses;
230 230
 
231
-    if ( 'wpi_invoice' === $typenow ) {
232
-        if ( !isset( $vars['post_status'] ) ) {
231
+    if ('wpi_invoice' === $typenow) {
232
+        if (!isset($vars['post_status'])) {
233 233
             $post_statuses = wpinv_get_invoice_statuses();
234 234
 
235
-            foreach ( $post_statuses as $status => $value ) {
236
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
237
-                    unset( $post_statuses[ $status ] );
235
+            foreach ($post_statuses as $status => $value) {
236
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
237
+                    unset($post_statuses[$status]);
238 238
                 }
239 239
             }
240 240
 
241
-            $vars['post_status'] = array_keys( $post_statuses );
241
+            $vars['post_status'] = array_keys($post_statuses);
242 242
         }
243 243
 
244
-        if ( isset( $vars['orderby'] ) ) {
245
-            if ( 'amount' == $vars['orderby'] ) {
244
+        if (isset($vars['orderby'])) {
245
+            if ('amount' == $vars['orderby']) {
246 246
                 $vars = array_merge(
247 247
                     $vars,
248 248
                     array(
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
                         'orderby'  => 'meta_value_num'
251 251
                     )
252 252
                 );
253
-            } else if ( 'customer' == $vars['orderby'] ) {
253
+            } else if ('customer' == $vars['orderby']) {
254 254
                 $vars = array_merge(
255 255
                     $vars,
256 256
                     array(
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
                         'orderby'  => 'meta_value'
259 259
                     )
260 260
                 );
261
-            } else if ( 'number' == $vars['orderby'] ) {
261
+            } else if ('number' == $vars['orderby']) {
262 262
                 $vars = array_merge(
263 263
                     $vars,
264 264
                     array(
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
                         'orderby'  => 'meta_value'
267 267
                     )
268 268
                 );
269
-            } else if ( 'payment_date' == $vars['orderby'] ) {
269
+            } else if ('payment_date' == $vars['orderby']) {
270 270
                 $vars = array_merge(
271 271
                     $vars,
272 272
                     array(
@@ -276,9 +276,9 @@  discard block
 block discarded – undo
276 276
                 );
277 277
             }
278 278
         }
279
-    } else if ( 'wpi_item' == $typenow ) {
279
+    } else if ('wpi_item' == $typenow) {
280 280
         // Check if 'orderby' is set to "price"
281
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
281
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
282 282
             $vars = array_merge(
283 283
                 $vars,
284 284
                 array(
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         }
290 290
 
291 291
         // Check if "orderby" is set to "vat_rule"
292
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
292
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
293 293
             $vars = array_merge(
294 294
                 $vars,
295 295
                 array(
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
         }
301 301
 
302 302
         // Check if "orderby" is set to "vat_class"
303
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
303
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
304 304
             $vars = array_merge(
305 305
                 $vars,
306 306
                 array(
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
         }
312 312
 
313 313
         // Check if "orderby" is set to "type"
314
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
314
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
315 315
             $vars = array_merge(
316 316
                 $vars,
317 317
                 array(
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
         }
323 323
 
324 324
         // Check if "orderby" is set to "recurring"
325
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
325
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
326 326
             $vars = array_merge(
327 327
                 $vars,
328 328
                 array(
@@ -332,104 +332,104 @@  discard block
 block discarded – undo
332 332
             );
333 333
         }
334 334
 
335
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
335
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
336 336
         // Filter vat rule type
337
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
337
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
338 338
             $meta_query[] = array(
339 339
                     'key'   => '_wpinv_vat_rule',
340
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
340
+                    'value' => sanitize_text_field($_GET['vat_rule']),
341 341
                     'compare' => '='
342 342
                 );
343 343
         }
344 344
 
345 345
         // Filter vat class
346
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
346
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
347 347
             $meta_query[] = array(
348 348
                     'key'   => '_wpinv_vat_class',
349
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
349
+                    'value' => sanitize_text_field($_GET['vat_class']),
350 350
                     'compare' => '='
351 351
                 );
352 352
         }
353 353
 
354 354
         // Filter item type
355
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
355
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
356 356
             $meta_query[] = array(
357 357
                     'key'   => '_wpinv_type',
358
-                    'value' => sanitize_text_field( $_GET['type'] ),
358
+                    'value' => sanitize_text_field($_GET['type']),
359 359
                     'compare' => '='
360 360
                 );
361 361
         }
362 362
 
363
-        if ( !empty( $meta_query ) ) {
363
+        if (!empty($meta_query)) {
364 364
             $vars['meta_query'] = $meta_query;
365 365
         }
366
-    } else if ( 'wpi_discount' == $typenow ) {
367
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
366
+    } else if ('wpi_discount' == $typenow) {
367
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
368 368
         // Filter vat rule type
369
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
369
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
370 370
             $meta_query[] = array(
371 371
                     'key'   => '_wpi_discount_type',
372
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
372
+                    'value' => sanitize_text_field($_GET['discount_type']),
373 373
                     'compare' => '='
374 374
                 );
375 375
         }
376 376
 
377
-        if ( !empty( $meta_query ) ) {
377
+        if (!empty($meta_query)) {
378 378
             $vars['meta_query'] = $meta_query;
379 379
         }
380 380
     }
381 381
 
382 382
     return $vars;
383 383
 }
384
-add_filter( 'request', 'wpinv_request' );
384
+add_filter('request', 'wpinv_request');
385 385
 
386
-function wpinv_item_type_class( $classes, $class, $post_id ) {
386
+function wpinv_item_type_class($classes, $class, $post_id) {
387 387
     global $pagenow, $typenow;
388 388
 
389
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
390
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
391
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
389
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
390
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
391
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
392 392
         }
393 393
 
394
-        if ( !wpinv_item_is_editable( $post_id ) ) {
394
+        if (!wpinv_item_is_editable($post_id)) {
395 395
             $classes[] = 'wpi-editable-n';
396 396
         }
397 397
     }
398 398
     return $classes;
399 399
 }
400
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
400
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
401 401
 
402 402
 function wpinv_check_quick_edit() {
403 403
     global $pagenow, $current_screen, $wpinv_item_screen;
404 404
 
405
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
406
-        if ( empty( $wpinv_item_screen ) ) {
407
-            if ( $current_screen->post_type == 'wpi_item' ) {
405
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
406
+        if (empty($wpinv_item_screen)) {
407
+            if ($current_screen->post_type == 'wpi_item') {
408 408
                 $wpinv_item_screen = 'y';
409 409
             } else {
410 410
                 $wpinv_item_screen = 'n';
411 411
             }
412 412
         }
413 413
 
414
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
415
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
416
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
414
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
415
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
416
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
417 417
         }
418 418
     }
419 419
 }
420
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
420
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
421 421
 
422
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
423
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
424
-        unset( $actions['inline hide-if-no-js'] );
422
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
423
+    if (isset($actions['inline hide-if-no-js'])) {
424
+        unset($actions['inline hide-if-no-js']);
425 425
     }
426 426
 
427
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
428
-        if ( isset( $actions['trash'] ) ) {
429
-            unset( $actions['trash'] );
427
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
428
+        if (isset($actions['trash'])) {
429
+            unset($actions['trash']);
430 430
         }
431
-        if ( isset( $actions['delete'] ) ) {
432
-            unset( $actions['delete'] );
431
+        if (isset($actions['delete'])) {
432
+            unset($actions['delete']);
433 433
         }
434 434
     }
435 435
 
@@ -446,19 +446,19 @@  discard block
 block discarded – undo
446 446
  * @param int $post_parent (default: 0) Parent for the new page
447 447
  * @return int page ID
448 448
  */
449
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
449
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
450 450
     global $wpdb;
451 451
 
452
-    $option_value = wpinv_get_option( $option );
452
+    $option_value = wpinv_get_option($option);
453 453
 
454
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
455
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
454
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
455
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
456 456
             // Valid page is already in place
457 457
             return $page_object->ID;
458 458
         }
459 459
     }
460 460
 
461
-    if(!empty($post_parent)){
461
+    if (!empty($post_parent)) {
462 462
         $page = get_page_by_path($post_parent);
463 463
         if ($page) {
464 464
             $post_parent = $page->ID;
@@ -467,40 +467,40 @@  discard block
 block discarded – undo
467 467
         }
468 468
     }
469 469
 
470
-    if ( strlen( $page_content ) > 0 ) {
470
+    if (strlen($page_content) > 0) {
471 471
         // Search for an existing page with the specified page content (typically a shortcode)
472
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
472
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
473 473
     } else {
474 474
         // Search for an existing page with the specified page slug
475
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
475
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
476 476
     }
477 477
 
478
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
478
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
479 479
 
480
-    if ( $valid_page_found ) {
481
-        if ( $option ) {
482
-            wpinv_update_option( $option, $valid_page_found );
480
+    if ($valid_page_found) {
481
+        if ($option) {
482
+            wpinv_update_option($option, $valid_page_found);
483 483
         }
484 484
         return $valid_page_found;
485 485
     }
486 486
 
487 487
     // Search for a matching valid trashed page
488
-    if ( strlen( $page_content ) > 0 ) {
488
+    if (strlen($page_content) > 0) {
489 489
         // Search for an existing page with the specified page content (typically a shortcode)
490
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
490
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
491 491
     } else {
492 492
         // Search for an existing page with the specified page slug
493
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
493
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
494 494
     }
495 495
 
496
-    if ( $trashed_page_found ) {
496
+    if ($trashed_page_found) {
497 497
         $page_id   = $trashed_page_found;
498 498
         $page_data = array(
499 499
             'ID'             => $page_id,
500 500
             'post_status'    => 'publish',
501 501
             'post_parent'    => $post_parent,
502 502
         );
503
-        wp_update_post( $page_data );
503
+        wp_update_post($page_data);
504 504
     } else {
505 505
         $page_data = array(
506 506
             'post_status'    => 'publish',
@@ -512,11 +512,11 @@  discard block
 block discarded – undo
512 512
             'post_parent'    => $post_parent,
513 513
             'comment_status' => 'closed',
514 514
         );
515
-        $page_id = wp_insert_post( $page_data );
515
+        $page_id = wp_insert_post($page_data);
516 516
     }
517 517
 
518
-    if ( $option ) {
519
-        wpinv_update_option( $option, (int)$page_id );
518
+    if ($option) {
519
+        wpinv_update_option($option, (int) $page_id);
520 520
     }
521 521
 
522 522
     return $page_id;
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 3 patches
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -286,26 +286,26 @@  discard block
 block discarded – undo
286 286
 }
287 287
 
288 288
 function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
289
+    $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
290 290
 
291 291
     $chosen = false;
292 292
     if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+    $chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
300
-	}
298
+    if ( false !== $chosen ) {
299
+        $chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
300
+    }
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
305
-		$enabled_gateway = 'manual';
306
-	} else {
307
-		$enabled_gateway = wpinv_get_default_gateway();
308
-	}
302
+    if ( ! empty ( $chosen ) ) {
303
+        $enabled_gateway = urldecode( $chosen );
304
+    } else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
305
+        $enabled_gateway = 'manual';
306
+    } else {
307
+        $enabled_gateway = wpinv_get_default_gateway();
308
+    }
309 309
     
310 310
     if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311 311
         if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+    return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
320 320
 }
321 321
 
322 322
 function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
@@ -324,21 +324,21 @@  discard block
 block discarded – undo
324 324
 }
325 325
 
326 326
 function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
327
-	$ret  = 0;
328
-	$args = array(
329
-		'meta_key'    => '_wpinv_gateway',
330
-		'meta_value'  => $gateway_id,
331
-		'nopaging'    => true,
332
-		'post_type'   => 'wpi_invoice',
333
-		'post_status' => $status,
334
-		'fields'      => 'ids'
335
-	);
336
-
337
-	$payments = new WP_Query( $args );
338
-
339
-	if( $payments )
340
-		$ret = $payments->post_count;
341
-	return $ret;
327
+    $ret  = 0;
328
+    $args = array(
329
+        'meta_key'    => '_wpinv_gateway',
330
+        'meta_value'  => $gateway_id,
331
+        'nopaging'    => true,
332
+        'post_type'   => 'wpi_invoice',
333
+        'post_status' => $status,
334
+        'fields'      => 'ids'
335
+    );
336
+
337
+    $payments = new WP_Query( $args );
338
+
339
+    if( $payments )
340
+        $ret = $payments->post_count;
341
+    return $ret;
342 342
 }
343 343
 
344 344
 function wpinv_settings_update_gateways( $input ) {
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -310,7 +310,7 @@  discard block
 block discarded – undo
310 310
     if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311 311
         if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else{
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
@@ -336,8 +336,9 @@  discard block
 block discarded – undo
336 336
 
337 337
 	$payments = new WP_Query( $args );
338 338
 
339
-	if( $payments )
340
-		$ret = $payments->post_count;
339
+	if( $payments ) {
340
+			$ret = $payments->post_count;
341
+	}
341 342
 	return $ret;
342 343
 }
343 344
 
Please login to merge, or discard this patch.
Spacing   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  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_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Manual Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Manual Payment', 'invoicing' ),
38
+            'admin_label'    => __('Manual Payment', 'invoicing'),
39
+            'checkout_label' => __('Manual Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
 
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
 
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
 
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
 
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
129
-            $label = __( 'Free Purchase', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (!((float) wpinv_payment_total($payment) > 0)) {
129
+            $label = __('Free Purchase', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,27 +383,27 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
391
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
391
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
392 392
     
393 393
     $setting['paypal_sandbox'] = array(
394 394
             'type' => 'checkbox',
395 395
             'id'   => 'paypal_sandbox',
396
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
397
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
396
+            'name' => __('PayPal Sandbox', 'invoicing'),
397
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
398 398
             'std'  => 1
399 399
         );
400 400
         
401 401
     $setting['paypal_email'] = array(
402 402
             'type' => 'text',
403 403
             'id'   => 'paypal_email',
404
-            'name' => __( 'PayPal Email', 'invoicing' ),
405
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
406
-            'std' => __( '[email protected]', 'invoicing' ),
404
+            'name' => __('PayPal Email', 'invoicing'),
405
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
406
+            'std' => __('[email protected]', 'invoicing'),
407 407
         );
408 408
     /*
409 409
     $setting['paypal_ipn_url'] = array(
@@ -417,139 +417,139 @@  discard block
 block discarded – undo
417 417
         
418 418
     return $setting;
419 419
 }
420
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
420
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
421 421
 
422 422
 // Pre Bank Transfer settings
423
-function wpinv_gateway_settings_bank_transfer( $setting ) {
424
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
423
+function wpinv_gateway_settings_bank_transfer($setting) {
424
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
425 425
     
426 426
     $setting['bank_transfer_ac_name'] = array(
427 427
             'type' => 'text',
428 428
             'id' => 'bank_transfer_ac_name',
429
-            'name' => __( 'Account Name', 'invoicing' ),
430
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
431
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
429
+            'name' => __('Account Name', 'invoicing'),
430
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
431
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
432 432
         );
433 433
     
434 434
     $setting['bank_transfer_ac_no'] = array(
435 435
             'type' => 'text',
436 436
             'id' => 'bank_transfer_ac_no',
437
-            'name' => __( 'Account Number', 'invoicing' ),
438
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
439
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
437
+            'name' => __('Account Number', 'invoicing'),
438
+            'desc' => __('Enter your bank account number.', 'invoicing'),
439
+            'std'  =>  __('TEST1234567890', 'invoicing'),
440 440
         );
441 441
     
442 442
     $setting['bank_transfer_bank_name'] = array(
443 443
             'type' => 'text',
444 444
             'id'   => 'bank_transfer_bank_name',
445
-            'name' => __( 'Bank Name', 'invoicing' ),
446
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
447
-            'std' => __( 'ICICI Bank', 'invoicing' ),
445
+            'name' => __('Bank Name', 'invoicing'),
446
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
447
+            'std' => __('ICICI Bank', 'invoicing'),
448 448
         );
449 449
     
450 450
     $setting['bank_transfer_ifsc'] = array(
451 451
             'type' => 'text',
452 452
             'id'   => 'bank_transfer_ifsc',
453
-            'name' => __( 'IFSC Code', 'invoicing' ),
454
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
455
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
453
+            'name' => __('IFSC Code', 'invoicing'),
454
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
455
+            'std'  =>  __('ICIC0001234', 'invoicing'),
456 456
         );
457 457
         
458 458
     $setting['bank_transfer_iban'] = array(
459 459
             'type' => 'text',
460 460
             'id'   => 'bank_transfer_iban',
461
-            'name' => __( 'IBAN', 'invoicing' ),
462
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
463
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
461
+            'name' => __('IBAN', 'invoicing'),
462
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
463
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
464 464
         );
465 465
         
466 466
     $setting['bank_transfer_bic'] = array(
467 467
             'type' => 'text',
468 468
             'id'   => 'bank_transfer_bic',
469
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
470
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
469
+            'name' => __('BIC/Swift Code', 'invoicing'),
470
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
471 471
         );
472 472
 
473 473
     $setting['bank_transfer_sort_code'] = array(
474 474
         'type' => 'text',
475 475
         'id'   => 'bank_transfer_sort_code',
476
-        'name' => __( 'Sort Code', 'invoicing' ),
477
-        'std'  =>  __( '12-34-56', 'invoicing' ),
476
+        'name' => __('Sort Code', 'invoicing'),
477
+        'std'  =>  __('12-34-56', 'invoicing'),
478 478
     );
479 479
         
480 480
     $setting['bank_transfer_info'] = array(
481 481
             'id'   => 'bank_transfer_info',
482
-            'name' => __( 'Instructions', 'invoicing' ),
483
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
482
+            'name' => __('Instructions', 'invoicing'),
483
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
484 484
             'type' => 'textarea',
485
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
485
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
486 486
             'cols' => 37,
487 487
             'rows' => 5
488 488
         );
489 489
         
490 490
     return $setting;
491 491
 }
492
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
492
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
493 493
 
494 494
 // Authorize.Net settings
495
-function wpinv_gateway_settings_authorizenet( $setting ) {
496
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
497
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' );
495
+function wpinv_gateway_settings_authorizenet($setting) {
496
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
497
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing');
498 498
     
499 499
     $setting['authorizenet_sandbox'] = array(
500 500
             'type' => 'checkbox',
501 501
             'id'   => 'authorizenet_sandbox',
502
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
503
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
502
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
503
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
504 504
             'std'  => 1
505 505
         );
506 506
         
507 507
     $setting['authorizenet_login_id'] = array(
508 508
             'type' => 'text',
509 509
             'id'   => 'authorizenet_login_id',
510
-            'name' => __( 'API Login ID', 'invoicing' ),
511
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
510
+            'name' => __('API Login ID', 'invoicing'),
511
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
512 512
             'std' => '2j4rBekUnD',
513 513
         );
514 514
     
515 515
     $setting['authorizenet_transaction_key'] = array(
516 516
             'type' => 'text',
517 517
             'id'   => 'authorizenet_transaction_key',
518
-            'name' => __( 'Transaction Key', 'invoicing' ),
519
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
518
+            'name' => __('Transaction Key', 'invoicing'),
519
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
520 520
             'std' => '4vyBUOJgR74679xa',
521 521
         );
522 522
         
523 523
     $setting['authorizenet_md5_hash'] = array(
524 524
             'type' => 'text',
525 525
             'id'   => 'authorizenet_md5_hash',
526
-            'name' => __( 'MD5-Hash', 'invoicing' ),
527
-            'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
526
+            'name' => __('MD5-Hash', 'invoicing'),
527
+            'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
528 528
             'std' => '',
529 529
         );
530 530
 
531 531
     $setting['authorizenet_transaction_type'] = array(
532 532
         'id'          => 'authorizenet_transaction_type',
533
-        'name'        => __( 'Transaction Type', 'invoicing' ),
534
-        'desc'        => __( 'Choose transaction type.', 'invoicing' ),
533
+        'name'        => __('Transaction Type', 'invoicing'),
534
+        'desc'        => __('Choose transaction type.', 'invoicing'),
535 535
         'type'        => 'select',
536 536
         'class'       => 'wpi_select2',
537 537
         'options'     => array(
538
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
539
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
538
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
539
+            'authorize_only' => __('Authorize Only', 'invoicing'),
540 540
         ),
541 541
         'std'         => 'authorize_capture'
542 542
     );
543 543
 
544 544
     $setting['authorizenet_transaction_type_recurring'] = array(
545 545
         'id'          => 'authorizenet_transaction_type_recurring',
546
-        'name'        => __( 'Transaction Type for Recurring', 'invoicing' ),
547
-        'desc'        => __( 'Choose transaction type for recurring payments.', 'invoicing' ),
546
+        'name'        => __('Transaction Type for Recurring', 'invoicing'),
547
+        'desc'        => __('Choose transaction type for recurring payments.', 'invoicing'),
548 548
         'type'        => 'select',
549 549
         'class'       => 'wpi_select2',
550 550
         'options'     => array(
551
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
552
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
551
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
552
+            'authorize_only' => __('Authorize Only', 'invoicing'),
553 553
         ),
554 554
         'std'         => 'authorize_only'
555 555
     );
@@ -557,9 +557,9 @@  discard block
 block discarded – undo
557 557
     $setting['authorizenet_ipn_url'] = array(
558 558
             'type' => 'ipn_url',
559 559
             'id'   => 'authorizenet_ipn_url',
560
-            'name' => __( 'Silent Post URL', 'invoicing' ),
561
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
562
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
560
+            'name' => __('Silent Post URL', 'invoicing'),
561
+            'std' => wpinv_get_ipn_url('authorizenet'),
562
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
563 563
             'size' => 'large',
564 564
             'custom' => 'authorizenet',
565 565
             'readonly' => true
@@ -567,26 +567,26 @@  discard block
 block discarded – undo
567 567
         
568 568
     return $setting;
569 569
 }
570
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
570
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
571 571
 
572 572
 // Worldpay settings
573
-function wpinv_gateway_settings_worldpay( $setting ) {
574
-    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' );
575
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' );
573
+function wpinv_gateway_settings_worldpay($setting) {
574
+    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing');
575
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing');
576 576
     
577 577
     $setting['worldpay_sandbox'] = array(
578 578
             'type' => 'checkbox',
579 579
             'id'   => 'worldpay_sandbox',
580
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
581
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
580
+            'name' => __('Worldpay Test Mode', 'invoicing'),
581
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
582 582
             'std'  => 1
583 583
         );
584 584
         
585 585
     $setting['worldpay_instId'] = array(
586 586
             'type' => 'text',
587 587
             'id'   => 'worldpay_instId',
588
-            'name' => __( 'Installation Id', 'invoicing' ),
589
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
588
+            'name' => __('Installation Id', 'invoicing'),
589
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
590 590
             'std' => '211616',
591 591
         );
592 592
     /*
@@ -602,9 +602,9 @@  discard block
 block discarded – undo
602 602
     $setting['worldpay_ipn_url'] = array(
603 603
             'type' => 'ipn_url',
604 604
             'id'   => 'worldpay_ipn_url',
605
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
606
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
607
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
605
+            'name' => __('Worldpay Callback Url', 'invoicing'),
606
+            'std' => wpinv_get_ipn_url('worldpay'),
607
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
608 608
             'size' => 'large',
609 609
             'custom' => 'worldpay',
610 610
             'readonly' => true
@@ -612,99 +612,99 @@  discard block
 block discarded – undo
612 612
         
613 613
     return $setting;
614 614
 }
615
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
615
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
616 616
 
617
-function wpinv_ipn_url_callback( $args ) {    
618
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
617
+function wpinv_ipn_url_callback($args) {    
618
+    $sanitize_id = wpinv_sanitize_key($args['id']);
619 619
     
620 620
     $attrs = $args['readonly'] ? ' readonly' : '';
621 621
 
622
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
623
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
622
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
623
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
624 624
 
625 625
     echo $html;
626 626
 }
627 627
 
628
-function wpinv_is_test_mode( $gateway = '' ) {
629
-    if ( empty( $gateway ) ) {
628
+function wpinv_is_test_mode($gateway = '') {
629
+    if (empty($gateway)) {
630 630
         return false;
631 631
     }
632 632
     
633
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
633
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
634 634
     
635
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
635
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
636 636
 }
637 637
 
638
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
639
-    $data = array( 'wpi-listener' => 'IPN' );
638
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
639
+    $data = array('wpi-listener' => 'IPN');
640 640
     
641
-    if ( !empty( $gateway ) ) {
642
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
641
+    if (!empty($gateway)) {
642
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
643 643
     }
644 644
     
645
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
645
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
646 646
     
647
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
647
+    $ipn_url = add_query_arg($args, home_url('index.php'));
648 648
     
649
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
649
+    return apply_filters('wpinv_ipn_url', $ipn_url);
650 650
 }
651 651
 
652 652
 function wpinv_listen_for_payment_ipn() {
653 653
     // Regular PayPal IPN
654
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
655
-        do_action( 'wpinv_verify_payment_ipn' );
654
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
655
+        do_action('wpinv_verify_payment_ipn');
656 656
         
657
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
658
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ );
659
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
657
+        if (!empty($_GET['wpi-gateway'])) {
658
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__);
659
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
660 660
         }
661 661
     }
662 662
 }
663
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
663
+add_action('init', 'wpinv_listen_for_payment_ipn');
664 664
 
665 665
 function wpinv_get_bank_instructions() {
666
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
666
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
667 667
     
668
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
668
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
669 669
 }
670 670
 
671
-function wpinv_get_bank_info( $filtered = false ) {
671
+function wpinv_get_bank_info($filtered = false) {
672 672
     $bank_fields = array(
673
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
674
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
675
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
676
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
677
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
678
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
679
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
673
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
674
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
675
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
676
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
677
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
678
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
679
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
680 680
     );
681 681
     
682 682
     $bank_info = array();
683
-    foreach ( $bank_fields as $field => $label ) {
684
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
683
+    foreach ($bank_fields as $field => $label) {
684
+        if ($filtered && !($value = wpinv_get_option($field))) {
685 685
             continue;
686 686
         }
687 687
         
688
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
688
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
689 689
     }
690 690
     
691
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
691
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
692 692
 }
693 693
 
694
-function wpinv_get_post_data( $method = 'request' ) {
694
+function wpinv_get_post_data($method = 'request') {
695 695
     $data       = array();
696 696
     $request    = $_REQUEST;
697 697
     
698
-    if ( $method == 'post' ) {
699
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
698
+    if ($method == 'post') {
699
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
700 700
             return $data;
701 701
         }
702 702
         
703 703
         $request = $_POST;
704 704
     }
705 705
     
706
-    if ( $method == 'get' ) {
707
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
706
+    if ($method == 'get') {
707
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
708 708
             return $data;
709 709
         }
710 710
         
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
     $post_data = '';
716 716
     
717 717
     // Fallback just in case post_max_size is lower than needed
718
-    if ( ini_get( 'allow_url_fopen' ) ) {
719
-        $post_data = file_get_contents( 'php://input' );
718
+    if (ini_get('allow_url_fopen')) {
719
+        $post_data = file_get_contents('php://input');
720 720
     } else {
721 721
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
722
-        ini_set( 'post_max_size', '12M' );
722
+        ini_set('post_max_size', '12M');
723 723
     }
724 724
     // Start the encoded data collection with notification command
725 725
     $encoded_data = 'cmd=_notify-validate';
@@ -728,58 +728,58 @@  discard block
 block discarded – undo
728 728
     $arg_separator = wpinv_get_php_arg_separator_output();
729 729
 
730 730
     // Verify there is a post_data
731
-    if ( $post_data || strlen( $post_data ) > 0 ) {
731
+    if ($post_data || strlen($post_data) > 0) {
732 732
         // Append the data
733 733
         $encoded_data .= $arg_separator . $post_data;
734 734
     } else {
735 735
         // Check if POST is empty
736
-        if ( empty( $request ) ) {
736
+        if (empty($request)) {
737 737
             // Nothing to do
738 738
             return;
739 739
         } else {
740 740
             // Loop through each POST
741
-            foreach ( $request as $key => $value ) {
741
+            foreach ($request as $key => $value) {
742 742
                 // Encode the value and append the data
743
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
743
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
744 744
             }
745 745
         }
746 746
     }
747 747
 
748 748
     // Convert collected post data to an array
749
-    wp_parse_str( $encoded_data, $data );
749
+    wp_parse_str($encoded_data, $data);
750 750
 
751
-    foreach ( $data as $key => $value ) {
752
-        if ( false !== strpos( $key, 'amp;' ) ) {
753
-            $new_key = str_replace( '&amp;', '&', $key );
754
-            $new_key = str_replace( 'amp;', '&' , $new_key );
751
+    foreach ($data as $key => $value) {
752
+        if (false !== strpos($key, 'amp;')) {
753
+            $new_key = str_replace('&amp;', '&', $key);
754
+            $new_key = str_replace('amp;', '&', $new_key);
755 755
 
756
-            unset( $data[ $key ] );
757
-            $data[ $new_key ] = sanitize_text_field( $value );
756
+            unset($data[$key]);
757
+            $data[$new_key] = sanitize_text_field($value);
758 758
         }
759 759
     }
760 760
     
761 761
     return $data;
762 762
 }
763 763
 
764
-function wpinv_gateway_support_subscription( $gateway ) {
764
+function wpinv_gateway_support_subscription($gateway) {
765 765
     $return = false;
766 766
     
767
-    if ( wpinv_is_gateway_active( $gateway ) ) {
768
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
767
+    if (wpinv_is_gateway_active($gateway)) {
768
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
769 769
     }
770 770
     
771 771
     return $return;
772 772
 }
773 773
 
774
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
775
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
776
-        foreach ( $gateways as $gateway => $info ) {
777
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
778
-                unset( $gateways[$gateway] );
774
+function wpinv_payment_gateways_on_cart($gateways = array()) {
775
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
776
+        foreach ($gateways as $gateway => $info) {
777
+            if (!wpinv_gateway_support_subscription($gateway)) {
778
+                unset($gateways[$gateway]);
779 779
             }
780 780
         }
781 781
     }
782 782
     
783 783
     return $gateways;
784 784
 }
785
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
786 785
\ No newline at end of file
786
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
787 787
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 3 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -512,7 +512,7 @@
 block discarded – undo
512 512
             
513 513
             $response['success'] = true;
514 514
             $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
515
-        }  else {
515
+        } else {
516 516
             $errors = wpinv_get_errors();
517 517
             if ( !empty( $errors['wpinv-discount-error'] ) ) {
518 518
                 $response['msg'] = $errors['wpinv-discount-error'];
Please login to merge, or discard this patch.
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -714,24 +714,24 @@
 block discarded – undo
714 714
         }
715 715
 
716 716
         // Is the request set up correctly?
717
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
718
-			echo aui()->alert(
719
-				array(
720
-					'type'    => 'warning',
721
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
722
-				)
717
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
718
+            echo aui()->alert(
719
+                array(
720
+                    'type'    => 'warning',
721
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
722
+                )
723 723
             );
724 724
             exit;
725 725
         }
726 726
 
727 727
         // Payment form or button?
728
-		if ( ! empty( $_GET['form'] ) ) {
728
+        if ( ! empty( $_GET['form'] ) ) {
729 729
             echo getpaid_display_payment_form( $_GET['form'] );
730
-		} else if( $_GET['invoice'] ) {
731
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
730
+        } else if( $_GET['invoice'] ) {
731
+            echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
732 732
         } else {
733
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
734
-		    echo getpaid_display_item_payment_form( $items );
733
+            $items = getpaid_convert_items_to_array( $_GET['item'] );
734
+            echo getpaid_display_item_payment_form( $items );
735 735
         }
736 736
         
737 737
         exit;
Please login to merge, or discard this patch.
Spacing   +421 added lines, -421 removed lines patch added patch discarded remove patch
@@ -7,28 +7,28 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Ajax {
15 15
     public static function init() {
16
-        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
17
-        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
16
+        add_action('init', array(__CLASS__, 'define_ajax'), 0);
17
+        add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
18 18
         self::add_ajax_events();
19 19
     }
20 20
 
21 21
     public static function define_ajax() {
22
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
23
-            if ( ! defined( 'DOING_AJAX' ) ) {
24
-                define( 'DOING_AJAX', true );
22
+        if (!empty($_GET['wpinv-ajax'])) {
23
+            if (!defined('DOING_AJAX')) {
24
+                define('DOING_AJAX', true);
25 25
             }
26
-            if ( ! defined( 'WC_DOING_AJAX' ) ) {
27
-                define( 'WC_DOING_AJAX', true );
26
+            if (!defined('WC_DOING_AJAX')) {
27
+                define('WC_DOING_AJAX', true);
28 28
             }
29 29
             // Turn off display_errors during AJAX events to prevent malformed JSON
30
-            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
31
-                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+            if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
31
+                /** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
32 32
             }
33 33
             $GLOBALS['wpdb']->hide_errors();
34 34
         }
@@ -37,24 +37,24 @@  discard block
 block discarded – undo
37 37
     public static function do_wpinv_ajax() {
38 38
         global $wp_query;
39 39
 
40
-        if ( !empty( $_GET['wpinv-ajax'] ) ) {
41
-            $wp_query->set( 'wpinv-ajax', sanitize_text_field( $_GET['wpinv-ajax'] ) );
40
+        if (!empty($_GET['wpinv-ajax'])) {
41
+            $wp_query->set('wpinv-ajax', sanitize_text_field($_GET['wpinv-ajax']));
42 42
         }
43 43
 
44
-        if ( $action = $wp_query->get( 'wpinv-ajax' ) ) {
44
+        if ($action = $wp_query->get('wpinv-ajax')) {
45 45
             self::wpinv_ajax_headers();
46
-            do_action( 'wpinv_ajax_' . sanitize_text_field( $action ) );
46
+            do_action('wpinv_ajax_' . sanitize_text_field($action));
47 47
             die();
48 48
         }
49 49
     }
50 50
     
51 51
     private static function wpinv_ajax_headers() {
52 52
         send_origin_headers();
53
-        /** @scrutinizer ignore-unhandled */ @header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
54
-        /** @scrutinizer ignore-unhandled */ @header( 'X-Robots-Tag: noindex' );
53
+        /** @scrutinizer ignore-unhandled */ @header('Content-Type: text/html; charset=' . get_option('blog_charset'));
54
+        /** @scrutinizer ignore-unhandled */ @header('X-Robots-Tag: noindex');
55 55
         send_nosniff_header();
56 56
         nocache_headers();
57
-        status_header( 200 );
57
+        status_header(200);
58 58
     }
59 59
     
60 60
     public static function add_ajax_events() {
@@ -86,41 +86,41 @@  discard block
 block discarded – undo
86 86
             'payment_form_refresh_prices' => true,
87 87
         );
88 88
 
89
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
90
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
91
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
89
+        foreach ($ajax_events as $ajax_event => $nopriv) {
90
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
91
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
92 92
             
93
-            if ( !defined( 'WPI_AJAX_' . strtoupper( $nopriv ) ) ) {
94
-                define( 'WPI_AJAX_' . strtoupper( $nopriv ), 1 );
93
+            if (!defined('WPI_AJAX_' . strtoupper($nopriv))) {
94
+                define('WPI_AJAX_' . strtoupper($nopriv), 1);
95 95
             }
96 96
 
97
-            if ( $nopriv ) {
98
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
99
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
97
+            if ($nopriv) {
98
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
99
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
100 100
 
101
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
101
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
102 102
             }
103 103
         }
104 104
     }
105 105
     
106 106
     public static function add_note() {
107
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
107
+        check_ajax_referer('add-invoice-note', '_nonce');
108 108
 
109
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
109
+        if (!wpinv_current_user_can_manage_invoicing()) {
110 110
             die(-1);
111 111
         }
112 112
 
113
-        $post_id   = absint( $_POST['post_id'] );
114
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
115
-        $note_type = sanitize_text_field( $_POST['note_type'] );
113
+        $post_id   = absint($_POST['post_id']);
114
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
115
+        $note_type = sanitize_text_field($_POST['note_type']);
116 116
 
117 117
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
118 118
 
119
-        if ( $post_id > 0 ) {
120
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
119
+        if ($post_id > 0) {
120
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
121 121
 
122
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
123
-                wpinv_get_invoice_note_line_item( $note_id );
122
+            if ($note_id > 0 && !is_wp_error($note_id)) {
123
+                wpinv_get_invoice_note_line_item($note_id);
124 124
             }
125 125
         }
126 126
 
@@ -128,16 +128,16 @@  discard block
 block discarded – undo
128 128
     }
129 129
 
130 130
     public static function delete_note() {
131
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
131
+        check_ajax_referer('delete-invoice-note', '_nonce');
132 132
 
133
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
133
+        if (!wpinv_current_user_can_manage_invoicing()) {
134 134
             die(-1);
135 135
         }
136 136
 
137
-        $note_id = (int)$_POST['note_id'];
137
+        $note_id = (int) $_POST['note_id'];
138 138
 
139
-        if ( $note_id > 0 ) {
140
-            wp_delete_comment( $note_id, true );
139
+        if ($note_id > 0) {
140
+            wp_delete_comment($note_id, true);
141 141
         }
142 142
 
143 143
         die();
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
     }
151 151
     
152 152
     public static function checkout() {
153
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
154
-            define( 'WPINV_CHECKOUT', true );
153
+        if (!defined('WPINV_CHECKOUT')) {
154
+            define('WPINV_CHECKOUT', true);
155 155
         }
156 156
 
157 157
         wpinv_process_checkout();
@@ -160,53 +160,53 @@  discard block
 block discarded – undo
160 160
     
161 161
     public static function add_invoice_item() {
162 162
         global $wpi_userID, $wpinv_ip_address_country;
163
-        check_ajax_referer( 'invoice-item', '_nonce' );
164
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
163
+        check_ajax_referer('invoice-item', '_nonce');
164
+        if (!wpinv_current_user_can_manage_invoicing()) {
165 165
             die(-1);
166 166
         }
167 167
         
168
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
169
-        $invoice_id = absint( $_POST['invoice_id'] );
168
+        $item_id    = sanitize_text_field($_POST['item_id']);
169
+        $invoice_id = absint($_POST['invoice_id']);
170 170
         
171
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
171
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
172 172
             die();
173 173
         }
174 174
         
175
-        $invoice    = wpinv_get_invoice( $invoice_id );
176
-        if ( empty( $invoice ) ) {
175
+        $invoice = wpinv_get_invoice($invoice_id);
176
+        if (empty($invoice)) {
177 177
             die();
178 178
         }
179 179
         
180
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
180
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
181 181
             die(); // Don't allow modify items for paid invoice.
182 182
         }
183 183
         
184
-        if ( !empty( $_POST['user_id'] ) ) {
185
-            $wpi_userID = absint( $_POST['user_id'] ); 
184
+        if (!empty($_POST['user_id'])) {
185
+            $wpi_userID = absint($_POST['user_id']); 
186 186
         }
187 187
 
188
-        $item = new WPInv_Item( $item_id );
189
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
188
+        $item = new WPInv_Item($item_id);
189
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
190 190
             die();
191 191
         }
192 192
         
193 193
         // Validate item before adding to invoice because recurring item must be paid individually.
194
-        if ( !empty( $invoice->cart_details ) ) {
194
+        if (!empty($invoice->cart_details)) {
195 195
             $valid = true;
196 196
             
197
-            if ( $recurring_item = $invoice->get_recurring() ) {
198
-                if ( $recurring_item != $item_id ) {
197
+            if ($recurring_item = $invoice->get_recurring()) {
198
+                if ($recurring_item != $item_id) {
199 199
                     $valid = false;
200 200
                 }
201
-            } else if ( wpinv_is_recurring_item( $item_id ) ) {
201
+            } else if (wpinv_is_recurring_item($item_id)) {
202 202
                 $valid = false;
203 203
             }
204 204
             
205
-            if ( !$valid ) {
205
+            if (!$valid) {
206 206
                 $response               = array();
207 207
                 $response['success']    = false;
208
-                $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
209
-                wp_send_json( $response );
208
+                $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
209
+                wp_send_json($response);
210 210
             }
211 211
         }
212 212
         
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
         
215 215
         $data                   = array();
216 216
         $data['invoice_id']     = $invoice_id;
217
-        $data['cart_discounts'] = $invoice->get_discounts( true );
217
+        $data['cart_discounts'] = $invoice->get_discounts(true);
218 218
         
219
-        wpinv_set_checkout_session( $data );
219
+        wpinv_set_checkout_session($data);
220 220
         
221
-        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int)$_POST['qty'] > 0 ? (int)$_POST['qty'] : 1;
221
+        $quantity = wpinv_item_quantities_enabled() && !empty($_POST['qty']) && (int) $_POST['qty'] > 0 ? (int) $_POST['qty'] : 1;
222 222
 
223 223
         $args = array(
224 224
             'id'            => $item_id,
@@ -231,21 +231,21 @@  discard block
 block discarded – undo
231 231
             'fees'          => array()
232 232
         );
233 233
 
234
-        $invoice->add_item( $item_id, $args );
234
+        $invoice->add_item($item_id, $args);
235 235
         $invoice->save();
236 236
         
237
-        if ( empty( $_POST['country'] ) ) {
237
+        if (empty($_POST['country'])) {
238 238
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
239 239
         }
240
-        if ( empty( $_POST['state'] ) ) {
240
+        if (empty($_POST['state'])) {
241 241
             $_POST['state'] = $invoice->state;
242 242
         }
243 243
          
244
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
245
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
244
+        $invoice->country   = sanitize_text_field($_POST['country']);
245
+        $invoice->state     = sanitize_text_field($_POST['state']);
246 246
         
247
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
248
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
247
+        $invoice->set('country', sanitize_text_field($_POST['country']));
248
+        $invoice->set('state', sanitize_text_field($_POST['state']));
249 249
         
250 250
         $wpinv_ip_address_country = $invoice->country;
251 251
 
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
         
254 254
         $response                       = array();
255 255
         $response['success']            = true;
256
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
256
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
257 257
         $response['data']['subtotal']   = $invoice->get_subtotal();
258 258
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
259 259
         $response['data']['tax']        = $invoice->get_tax();
@@ -265,41 +265,41 @@  discard block
 block discarded – undo
265 265
         
266 266
         wpinv_set_checkout_session($checkout_session);
267 267
         
268
-        wp_send_json( $response );
268
+        wp_send_json($response);
269 269
     }
270 270
 
271 271
 
272 272
     public static function remove_invoice_item() {
273 273
         global $wpi_userID, $wpinv_ip_address_country;
274 274
         
275
-        check_ajax_referer( 'invoice-item', '_nonce' );
276
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
275
+        check_ajax_referer('invoice-item', '_nonce');
276
+        if (!wpinv_current_user_can_manage_invoicing()) {
277 277
             die(-1);
278 278
         }
279 279
         
280
-        $item_id    = sanitize_text_field( $_POST['item_id'] );
281
-        $invoice_id = absint( $_POST['invoice_id'] );
282
-        $cart_index = isset( $_POST['index'] ) && $_POST['index'] >= 0 ? $_POST['index'] : false;
280
+        $item_id    = sanitize_text_field($_POST['item_id']);
281
+        $invoice_id = absint($_POST['invoice_id']);
282
+        $cart_index = isset($_POST['index']) && $_POST['index'] >= 0 ? $_POST['index'] : false;
283 283
         
284
-        if ( !is_numeric( $invoice_id ) || !is_numeric( $item_id ) ) {
284
+        if (!is_numeric($invoice_id) || !is_numeric($item_id)) {
285 285
             die();
286 286
         }
287 287
 
288
-        $invoice    = wpinv_get_invoice( $invoice_id );
289
-        if ( empty( $invoice ) ) {
288
+        $invoice = wpinv_get_invoice($invoice_id);
289
+        if (empty($invoice)) {
290 290
             die();
291 291
         }
292 292
         
293
-        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
293
+        if ($invoice->is_paid() || $invoice->is_refunded()) {
294 294
             die(); // Don't allow modify items for paid invoice.
295 295
         }
296 296
         
297
-        if ( !empty( $_POST['user_id'] ) ) {
298
-            $wpi_userID = absint( $_POST['user_id'] ); 
297
+        if (!empty($_POST['user_id'])) {
298
+            $wpi_userID = absint($_POST['user_id']); 
299 299
         }
300 300
 
301
-        $item       = new WPInv_Item( $item_id );
302
-        if ( !( !empty( $item ) && $item->post_type == 'wpi_item' ) ) {
301
+        $item = new WPInv_Item($item_id);
302
+        if (!(!empty($item) && $item->post_type == 'wpi_item')) {
303 303
             die();
304 304
         }
305 305
         
@@ -307,9 +307,9 @@  discard block
 block discarded – undo
307 307
         
308 308
         $data                   = array();
309 309
         $data['invoice_id']     = $invoice_id;
310
-        $data['cart_discounts'] = $invoice->get_discounts( true );
310
+        $data['cart_discounts'] = $invoice->get_discounts(true);
311 311
         
312
-        wpinv_set_checkout_session( $data );
312
+        wpinv_set_checkout_session($data);
313 313
 
314 314
         $args = array(
315 315
             'id'         => $item_id,
@@ -317,21 +317,21 @@  discard block
 block discarded – undo
317 317
             'cart_index' => $cart_index
318 318
         );
319 319
 
320
-        $invoice->remove_item( $item_id, $args );
320
+        $invoice->remove_item($item_id, $args);
321 321
         $invoice->save();
322 322
         
323
-        if ( empty( $_POST['country'] ) ) {
323
+        if (empty($_POST['country'])) {
324 324
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
325 325
         }
326
-        if ( empty( $_POST['state'] ) ) {
326
+        if (empty($_POST['state'])) {
327 327
             $_POST['state'] = $invoice->state;
328 328
         }
329 329
          
330
-        $invoice->country   = sanitize_text_field( $_POST['country'] );
331
-        $invoice->state     = sanitize_text_field( $_POST['state'] );
330
+        $invoice->country   = sanitize_text_field($_POST['country']);
331
+        $invoice->state     = sanitize_text_field($_POST['state']);
332 332
         
333
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
334
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
333
+        $invoice->set('country', sanitize_text_field($_POST['country']));
334
+        $invoice->set('state', sanitize_text_field($_POST['state']));
335 335
         
336 336
         $wpinv_ip_address_country = $invoice->country;
337 337
         
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
         
340 340
         $response                       = array();
341 341
         $response['success']            = true;
342
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
342
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
343 343
         $response['data']['subtotal']   = $invoice->get_subtotal();
344 344
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
345 345
         $response['data']['tax']        = $invoice->get_tax();
@@ -351,55 +351,55 @@  discard block
 block discarded – undo
351 351
         
352 352
         wpinv_set_checkout_session($checkout_session);
353 353
         
354
-        wp_send_json( $response );
354
+        wp_send_json($response);
355 355
     }
356 356
     
357 357
     public static function create_invoice_item() {
358
-        check_ajax_referer( 'invoice-item', '_nonce' );
359
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
358
+        check_ajax_referer('invoice-item', '_nonce');
359
+        if (!wpinv_current_user_can_manage_invoicing()) {
360 360
             die(-1);
361 361
         }
362 362
         
363
-        $invoice_id = absint( $_POST['invoice_id'] );
363
+        $invoice_id = absint($_POST['invoice_id']);
364 364
 
365 365
         // Find the item
366
-        if ( !is_numeric( $invoice_id ) ) {
366
+        if (!is_numeric($invoice_id)) {
367 367
             die();
368 368
         }        
369 369
         
370
-        $invoice     = wpinv_get_invoice( $invoice_id );
371
-        if ( empty( $invoice ) ) {
370
+        $invoice = wpinv_get_invoice($invoice_id);
371
+        if (empty($invoice)) {
372 372
             die();
373 373
         }
374 374
         
375 375
         // Validate item before adding to invoice because recurring item must be paid individually.
376
-        if ( !empty( $invoice->cart_details ) && $invoice->get_recurring() ) {
376
+        if (!empty($invoice->cart_details) && $invoice->get_recurring()) {
377 377
             $response               = array();
378 378
             $response['success']    = false;
379
-            $response['msg']        = __( 'You can not add item because recurring item must be paid individually!', 'invoicing' );
380
-            wp_send_json( $response );
379
+            $response['msg']        = __('You can not add item because recurring item must be paid individually!', 'invoicing');
380
+            wp_send_json($response);
381 381
         }        
382 382
         
383
-        $save_item = wp_unslash( $_POST['_wpinv_quick'] );
383
+        $save_item = wp_unslash($_POST['_wpinv_quick']);
384 384
         
385 385
         $meta               = array();
386 386
         $meta['type']       = !empty($save_item['type']) ? sanitize_text_field($save_item['type']) : 'custom';
387
-        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount( $save_item['price'] ) : 0;
387
+        $meta['price']      = !empty($save_item['price']) ? wpinv_sanitize_amount($save_item['price']) : 0;
388 388
         $meta['vat_rule']   = !empty($save_item['vat_rule']) ? sanitize_text_field($save_item['vat_rule']) : 'digital';
389 389
         $meta['vat_class']  = !empty($save_item['vat_class']) ? sanitize_text_field($save_item['vat_class']) : '_standard';
390 390
         
391 391
         $data                   = array();
392 392
         $data['post_title']     = sanitize_text_field($save_item['name']);
393 393
         $data['post_status']    = 'publish';
394
-        $data['post_excerpt']   = ! empty( $save_item['excerpt'] ) ? wp_kses_post( $save_item['excerpt'] ) : '';
394
+        $data['post_excerpt']   = !empty($save_item['excerpt']) ? wp_kses_post($save_item['excerpt']) : '';
395 395
         $data['meta']           = $meta;
396 396
         
397 397
         $item = new WPInv_Item();
398
-        $item->create( $data );
398
+        $item->create($data);
399 399
         
400
-        if ( !empty( $item ) ) {
400
+        if (!empty($item)) {
401 401
             $_POST['item_id']   = $item->ID;
402
-            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int)$save_item['qty'] : 1;
402
+            $_POST['qty']       = !empty($save_item['qty']) && $save_item['qty'] > 0 ? (int) $save_item['qty'] : 1;
403 403
             
404 404
             self::add_invoice_item();
405 405
         }
@@ -412,48 +412,48 @@  discard block
 block discarded – undo
412 412
     public static function get_billing_details() {
413 413
 
414 414
         // Verify nonce.
415
-        check_ajax_referer( 'wpinv-nonce' );
415
+        check_ajax_referer('wpinv-nonce');
416 416
 
417 417
         // Can the user manage the plugin?
418
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
418
+        if (!wpinv_current_user_can_manage_invoicing()) {
419 419
             die(-1);
420 420
         }
421 421
 
422 422
         // Do we have a user id?
423 423
         $user_id = $_GET['user_id'];
424 424
 
425
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
425
+        if (empty($user_id) || !is_numeric($user_id)) {
426 426
             die(-1);
427 427
         }
428 428
 
429 429
         // Fetch the billing details.
430
-        $billing_details    = wpinv_get_user_address( $user_id );
431
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
430
+        $billing_details    = wpinv_get_user_address($user_id);
431
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
432 432
 
433 433
         // unset the user id and email.
434
-        $to_ignore = array( 'user_id', 'email' );
434
+        $to_ignore = array('user_id', 'email');
435 435
 
436
-        foreach ( $to_ignore as $key ) {
437
-            if ( isset( $billing_details[ $key ] ) ) {
438
-                unset( $billing_details[ $key ] );
436
+        foreach ($to_ignore as $key) {
437
+            if (isset($billing_details[$key])) {
438
+                unset($billing_details[$key]);
439 439
             }
440 440
         }
441 441
 
442
-        wp_send_json_success( $billing_details );
442
+        wp_send_json_success($billing_details);
443 443
 
444 444
     }
445 445
     
446 446
     public static function admin_recalculate_totals() {
447 447
         global $wpi_userID, $wpinv_ip_address_country;
448 448
         
449
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
450
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
449
+        check_ajax_referer('wpinv-nonce', '_nonce');
450
+        if (!wpinv_current_user_can_manage_invoicing()) {
451 451
             die(-1);
452 452
         }
453 453
         
454
-        $invoice_id = absint( $_POST['invoice_id'] );        
455
-        $invoice    = wpinv_get_invoice( $invoice_id );
456
-        if ( empty( $invoice ) ) {
454
+        $invoice_id = absint($_POST['invoice_id']);        
455
+        $invoice    = wpinv_get_invoice($invoice_id);
456
+        if (empty($invoice)) {
457 457
             die();
458 458
         }
459 459
 
@@ -461,29 +461,29 @@  discard block
 block discarded – undo
461 461
 
462 462
         $data                   = array();
463 463
         $data['invoice_id']     = $invoice_id;
464
-        $data['cart_discounts'] = $invoice->get_discounts( true );
464
+        $data['cart_discounts'] = $invoice->get_discounts(true);
465 465
 
466
-        wpinv_set_checkout_session( $data );
466
+        wpinv_set_checkout_session($data);
467 467
         
468
-        if ( !empty( $_POST['user_id'] ) ) {
469
-            $wpi_userID = absint( $_POST['user_id'] ); 
468
+        if (!empty($_POST['user_id'])) {
469
+            $wpi_userID = absint($_POST['user_id']); 
470 470
         }
471 471
         
472
-        if ( empty( $_POST['country'] ) ) {
472
+        if (empty($_POST['country'])) {
473 473
             $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
474 474
         }
475 475
 
476 476
         $disable_taxes = 0;
477
-        if ( ! empty( $_POST['disable_taxes'] ) ) {
477
+        if (!empty($_POST['disable_taxes'])) {
478 478
             $disable_taxes = 1;
479 479
         }
480
-        $invoice->set( 'disable_taxes', $disable_taxes );
480
+        $invoice->set('disable_taxes', $disable_taxes);
481 481
 
482
-        $invoice->country = sanitize_text_field( $_POST['country'] );
483
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
484
-        if ( isset( $_POST['state'] ) ) {
485
-            $invoice->state = sanitize_text_field( $_POST['state'] );
486
-            $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
482
+        $invoice->country = sanitize_text_field($_POST['country']);
483
+        $invoice->set('country', sanitize_text_field($_POST['country']));
484
+        if (isset($_POST['state'])) {
485
+            $invoice->state = sanitize_text_field($_POST['state']);
486
+            $invoice->set('state', sanitize_text_field($_POST['state']));
487 487
         }
488 488
         
489 489
         $wpinv_ip_address_country = $invoice->country;
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
         
493 493
         $response                       = array();
494 494
         $response['success']            = true;
495
-        $response['data']['items']      = wpinv_admin_get_line_items( $invoice );
495
+        $response['data']['items']      = wpinv_admin_get_line_items($invoice);
496 496
         $response['data']['subtotal']   = $invoice->get_subtotal();
497 497
         $response['data']['subtotalf']  = $invoice->get_subtotal(true);
498 498
         $response['data']['tax']        = $invoice->get_tax();
@@ -504,25 +504,25 @@  discard block
 block discarded – undo
504 504
         
505 505
         wpinv_set_checkout_session($checkout_session);
506 506
 
507
-        wp_send_json( $response );
507
+        wp_send_json($response);
508 508
     }
509 509
     
510 510
     public static function admin_apply_discount() {
511 511
         global $wpi_userID;
512 512
         
513
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
514
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
513
+        check_ajax_referer('wpinv-nonce', '_nonce');
514
+        if (!wpinv_current_user_can_manage_invoicing()) {
515 515
             die(-1);
516 516
         }
517 517
         
518
-        $invoice_id = absint( $_POST['invoice_id'] );
519
-        $discount_code = sanitize_text_field( $_POST['code'] );
520
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
518
+        $invoice_id = absint($_POST['invoice_id']);
519
+        $discount_code = sanitize_text_field($_POST['code']);
520
+        if (empty($invoice_id) || empty($discount_code)) {
521 521
             die();
522 522
         }
523 523
         
524
-        $invoice = wpinv_get_invoice( $invoice_id );
525
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
524
+        $invoice = wpinv_get_invoice($invoice_id);
525
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
526 526
             die();
527 527
         }
528 528
         
@@ -530,49 +530,49 @@  discard block
 block discarded – undo
530 530
         
531 531
         $data                   = array();
532 532
         $data['invoice_id']     = $invoice_id;
533
-        $data['cart_discounts'] = $invoice->get_discounts( true );
533
+        $data['cart_discounts'] = $invoice->get_discounts(true);
534 534
         
535
-        wpinv_set_checkout_session( $data );
535
+        wpinv_set_checkout_session($data);
536 536
         
537 537
         $response               = array();
538 538
         $response['success']    = false;
539
-        $response['msg']        = __( 'This discount is invalid.', 'invoicing' );
539
+        $response['msg']        = __('This discount is invalid.', 'invoicing');
540 540
         $response['data']['code'] = $discount_code;
541 541
         
542
-        if ( wpinv_is_discount_valid( $discount_code, $invoice->get_user_id() ) ) {
543
-            $discounts = wpinv_set_cart_discount( $discount_code );
542
+        if (wpinv_is_discount_valid($discount_code, $invoice->get_user_id())) {
543
+            $discounts = wpinv_set_cart_discount($discount_code);
544 544
             
545 545
             $response['success'] = true;
546
-            $response['msg'] = __( 'Discount has been applied successfully.', 'invoicing' );
547
-        }  else {
546
+            $response['msg'] = __('Discount has been applied successfully.', 'invoicing');
547
+        } else {
548 548
             $errors = wpinv_get_errors();
549
-            if ( !empty( $errors['wpinv-discount-error'] ) ) {
549
+            if (!empty($errors['wpinv-discount-error'])) {
550 550
                 $response['msg'] = $errors['wpinv-discount-error'];
551 551
             }
552
-            wpinv_unset_error( 'wpinv-discount-error' );
552
+            wpinv_unset_error('wpinv-discount-error');
553 553
         }
554 554
         
555 555
         wpinv_set_checkout_session($checkout_session);
556 556
         
557
-        wp_send_json( $response );
557
+        wp_send_json($response);
558 558
     }
559 559
     
560 560
     public static function admin_remove_discount() {
561 561
         global $wpi_userID;
562 562
         
563
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
564
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
563
+        check_ajax_referer('wpinv-nonce', '_nonce');
564
+        if (!wpinv_current_user_can_manage_invoicing()) {
565 565
             die(-1);
566 566
         }
567 567
         
568
-        $invoice_id = absint( $_POST['invoice_id'] );
569
-        $discount_code = sanitize_text_field( $_POST['code'] );
570
-        if ( empty( $invoice_id ) || empty( $discount_code ) ) {
568
+        $invoice_id = absint($_POST['invoice_id']);
569
+        $discount_code = sanitize_text_field($_POST['code']);
570
+        if (empty($invoice_id) || empty($discount_code)) {
571 571
             die();
572 572
         }
573 573
         
574
-        $invoice = wpinv_get_invoice( $invoice_id );
575
-        if ( empty( $invoice ) || ( !empty( $invoice ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) ) {
574
+        $invoice = wpinv_get_invoice($invoice_id);
575
+        if (empty($invoice) || (!empty($invoice) && ($invoice->is_paid() || $invoice->is_refunded()))) {
576 576
             die();
577 577
         }
578 578
         
@@ -580,21 +580,21 @@  discard block
 block discarded – undo
580 580
         
581 581
         $data                   = array();
582 582
         $data['invoice_id']     = $invoice_id;
583
-        $data['cart_discounts'] = $invoice->get_discounts( true );
583
+        $data['cart_discounts'] = $invoice->get_discounts(true);
584 584
         
585
-        wpinv_set_checkout_session( $data );
585
+        wpinv_set_checkout_session($data);
586 586
         
587 587
         $response               = array();
588 588
         $response['success']    = false;
589 589
         $response['msg']        = NULL;
590 590
         
591
-        $discounts  = wpinv_unset_cart_discount( $discount_code );
591
+        $discounts = wpinv_unset_cart_discount($discount_code);
592 592
         $response['success'] = true;
593
-        $response['msg'] = __( 'Discount has been removed successfully.', 'invoicing' );
593
+        $response['msg'] = __('Discount has been removed successfully.', 'invoicing');
594 594
         
595 595
         wpinv_set_checkout_session($checkout_session);
596 596
         
597
-        wp_send_json( $response );
597
+        wp_send_json($response);
598 598
     }
599 599
 
600 600
     /**
@@ -603,80 +603,80 @@  discard block
 block discarded – undo
603 603
     public static function check_new_user_email() {
604 604
 
605 605
         // Verify nonce.
606
-        check_ajax_referer( 'wpinv-nonce' );
606
+        check_ajax_referer('wpinv-nonce');
607 607
 
608 608
         // Can the user manage the plugin?
609
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
609
+        if (!wpinv_current_user_can_manage_invoicing()) {
610 610
             die(-1);
611 611
         }
612 612
 
613 613
         // We need an email address.
614
-        if ( empty( $_GET['email'] ) ) {
615
-            _e( "Provide the new user's email address", 'invoicing' );
614
+        if (empty($_GET['email'])) {
615
+            _e("Provide the new user's email address", 'invoicing');
616 616
             exit;
617 617
         }
618 618
 
619 619
         // Ensure the email is valid.
620
-        $email = sanitize_text_field( $_GET['email'] );
621
-        if ( ! is_email( $email ) ) {
622
-            _e( 'Invalid email address', 'invoicing' );
620
+        $email = sanitize_text_field($_GET['email']);
621
+        if (!is_email($email)) {
622
+            _e('Invalid email address', 'invoicing');
623 623
             exit;
624 624
         }
625 625
 
626 626
         // And it does not exist.
627
-        if ( email_exists( $email ) ) {
628
-            _e( 'A user with this email address already exists', 'invoicing' );
627
+        if (email_exists($email)) {
628
+            _e('A user with this email address already exists', 'invoicing');
629 629
             exit;
630 630
         }
631 631
 
632
-        wp_send_json_success( true );
632
+        wp_send_json_success(true);
633 633
     }
634 634
     
635 635
     public static function run_tool() {
636
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
637
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
636
+        check_ajax_referer('wpinv-nonce', '_nonce');
637
+        if (!wpinv_current_user_can_manage_invoicing()) {
638 638
             die(-1);
639 639
         }
640 640
         
641
-        $tool = sanitize_text_field( $_POST['tool'] );
641
+        $tool = sanitize_text_field($_POST['tool']);
642 642
         
643
-        do_action( 'wpinv_run_tool' );
643
+        do_action('wpinv_run_tool');
644 644
         
645
-        if ( !empty( $tool ) ) {
646
-            do_action( 'wpinv_tool_' . $tool );
645
+        if (!empty($tool)) {
646
+            do_action('wpinv_tool_' . $tool);
647 647
         }
648 648
     }
649 649
     
650 650
     public static function apply_discount() {
651 651
         global $wpi_userID;
652 652
         
653
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
653
+        check_ajax_referer('wpinv-nonce', '_nonce');
654 654
         
655 655
         $response = array();
656 656
         
657
-        if ( isset( $_POST['code'] ) ) {
658
-            $discount_code = sanitize_text_field( $_POST['code'] );
657
+        if (isset($_POST['code'])) {
658
+            $discount_code = sanitize_text_field($_POST['code']);
659 659
 
660 660
             $response['success']        = false;
661 661
             $response['msg']            = '';
662 662
             $response['data']['code']   = $discount_code;
663 663
             
664 664
             $invoice = wpinv_get_invoice_cart();
665
-            if ( empty( $invoice->ID ) ) {
666
-                $response['msg'] = __( 'Invalid checkout request.', 'invoicing' );
667
-                wp_send_json( $response );
665
+            if (empty($invoice->ID)) {
666
+                $response['msg'] = __('Invalid checkout request.', 'invoicing');
667
+                wp_send_json($response);
668 668
             }
669 669
 
670 670
             $wpi_userID = $invoice->get_user_id();
671 671
 
672
-            if ( wpinv_is_discount_valid( $discount_code, $wpi_userID ) ) {
673
-                $discount       = wpinv_get_discount_by_code( $discount_code );
674
-                $discounts      = wpinv_set_cart_discount( $discount_code );
675
-                $amount         = wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
676
-                $total          = wpinv_get_cart_total( null, $discounts );
677
-                $cart_totals    = wpinv_recalculate_tax( true );
672
+            if (wpinv_is_discount_valid($discount_code, $wpi_userID)) {
673
+                $discount       = wpinv_get_discount_by_code($discount_code);
674
+                $discounts      = wpinv_set_cart_discount($discount_code);
675
+                $amount         = wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
676
+                $total          = wpinv_get_cart_total(null, $discounts);
677
+                $cart_totals    = wpinv_recalculate_tax(true);
678 678
             
679
-                if ( !empty( $cart_totals ) ) {
679
+                if (!empty($cart_totals)) {
680 680
                     $response['success']        = true;
681 681
                     $response['data']           = $cart_totals;
682 682
                     $response['data']['code']   = $discount_code;
@@ -685,29 +685,29 @@  discard block
 block discarded – undo
685 685
                 }
686 686
             } else {
687 687
                 $errors = wpinv_get_errors();
688
-                $response['msg']  = $errors['wpinv-discount-error'];
689
-                wpinv_unset_error( 'wpinv-discount-error' );
688
+                $response['msg'] = $errors['wpinv-discount-error'];
689
+                wpinv_unset_error('wpinv-discount-error');
690 690
             }
691 691
 
692 692
             // Allow for custom discount code handling
693
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
693
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
694 694
         }
695 695
         
696
-        wp_send_json( $response );
696
+        wp_send_json($response);
697 697
     }
698 698
     
699 699
     public static function remove_discount() {
700
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
700
+        check_ajax_referer('wpinv-nonce', '_nonce');
701 701
         
702 702
         $response = array();
703 703
         
704
-        if ( isset( $_POST['code'] ) ) {
705
-            $discount_code  = sanitize_text_field( $_POST['code'] );
706
-            $discounts      = wpinv_unset_cart_discount( $discount_code );
707
-            $total          = wpinv_get_cart_total( null, $discounts );
708
-            $cart_totals    = wpinv_recalculate_tax( true );
704
+        if (isset($_POST['code'])) {
705
+            $discount_code  = sanitize_text_field($_POST['code']);
706
+            $discounts      = wpinv_unset_cart_discount($discount_code);
707
+            $total          = wpinv_get_cart_total(null, $discounts);
708
+            $cart_totals    = wpinv_recalculate_tax(true);
709 709
             
710
-            if ( !empty( $cart_totals ) ) {
710
+            if (!empty($cart_totals)) {
711 711
                 $response['success']        = true;
712 712
                 $response['data']           = $cart_totals;
713 713
                 $response['data']['code']   = $discount_code;
@@ -716,10 +716,10 @@  discard block
 block discarded – undo
716 716
             }
717 717
             
718 718
             // Allow for custom discount code handling
719
-            $response = apply_filters( 'wpinv_ajax_discount_response', $response );
719
+            $response = apply_filters('wpinv_ajax_discount_response', $response);
720 720
         }
721 721
         
722
-        wp_send_json( $response );
722
+        wp_send_json($response);
723 723
     }
724 724
 
725 725
     /**
@@ -728,30 +728,30 @@  discard block
 block discarded – undo
728 728
     public static function get_payment_form() {
729 729
 
730 730
         // Check nonce.
731
-        if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'getpaid_ajax_form' ) ) {
732
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
731
+        if (!isset($_GET['nonce']) || !wp_verify_nonce($_GET['nonce'], 'getpaid_ajax_form')) {
732
+            _e('Error: Reload the page and try again.', 'invoicing');
733 733
             exit;
734 734
         }
735 735
 
736 736
         // Is the request set up correctly?
737
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
737
+		if (empty($_GET['form']) && empty($_GET['item'])) {
738 738
 			echo aui()->alert(
739 739
 				array(
740 740
 					'type'    => 'warning',
741
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
741
+					'content' => __('No payment form or item provided', 'invoicing'),
742 742
 				)
743 743
             );
744 744
             exit;
745 745
         }
746 746
 
747 747
         // Payment form or button?
748
-		if ( ! empty( $_GET['form'] ) ) {
749
-            echo getpaid_display_payment_form( $_GET['form'] );
750
-		} else if( $_GET['invoice'] ) {
751
-		    echo getpaid_display_invoice_payment_form( $_GET['invoice'] );
748
+		if (!empty($_GET['form'])) {
749
+            echo getpaid_display_payment_form($_GET['form']);
750
+		} else if ($_GET['invoice']) {
751
+		    echo getpaid_display_invoice_payment_form($_GET['invoice']);
752 752
         } else {
753
-			$items = getpaid_convert_items_to_array( $_GET['item'] );
754
-		    echo getpaid_display_item_payment_form( $items );
753
+			$items = getpaid_convert_items_to_array($_GET['item']);
754
+		    echo getpaid_display_item_payment_form($items);
755 755
         }
756 756
         
757 757
         exit;
@@ -767,11 +767,11 @@  discard block
 block discarded – undo
767 767
         global $invoicing, $wpi_checkout_id, $cart_total;
768 768
 
769 769
         // Check nonce.
770
-        check_ajax_referer( 'getpaid_form_nonce' );
770
+        check_ajax_referer('getpaid_form_nonce');
771 771
 
772 772
         // ... form fields...
773
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
774
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
773
+        if (empty($_POST['getpaid_payment_form_submission'])) {
774
+            _e('Error: Reload the page and try again.', 'invoicing');
775 775
             exit;
776 776
         }
777 777
 
@@ -779,25 +779,25 @@  discard block
 block discarded – undo
779 779
         $submission = new GetPaid_Payment_Form_Submission();
780 780
 
781 781
         // Do we have an error?
782
-        if ( ! empty( $submission->last_error ) ) {
782
+        if (!empty($submission->last_error)) {
783 783
             echo $submission->last_error;
784 784
             exit;
785 785
         }
786 786
 
787 787
         // We need a billing email.
788
-        if ( ! $submission->has_billing_email() || ! is_email( $submission->get_billing_email() ) ) {
789
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
788
+        if (!$submission->has_billing_email() || !is_email($submission->get_billing_email())) {
789
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
790 790
         }
791 791
 
792 792
         // Prepare items.
793 793
         $items            = $submission->get_items();
794 794
         $prepared_items   = array();
795 795
 
796
-        if ( ! empty( $items ) ) {
796
+        if (!empty($items)) {
797 797
 
798
-            foreach( $items as $item_id => $item ) {
798
+            foreach ($items as $item_id => $item) {
799 799
 
800
-                if ( $item->can_purchase() ) {
800
+                if ($item->can_purchase()) {
801 801
                     $prepared_items[] = array(
802 802
                         'id'           => $item_id,
803 803
                         'item_price'   => $item->get_price(),
@@ -811,90 +811,90 @@  discard block
 block discarded – undo
811 811
 
812 812
         }
813 813
 
814
-        if ( empty( $prepared_items ) ) {
815
-            wp_send_json_error( __( 'You have not selected any items.', 'invoicing' ) );
814
+        if (empty($prepared_items)) {
815
+            wp_send_json_error(__('You have not selected any items.', 'invoicing'));
816 816
         }
817 817
 
818
-        if ( $submission->has_recurring && 1 != count( $prepared_items ) ) {
819
-            wp_send_json_error( __( 'Recurring items should be bought individually.', 'invoicing' ) );
818
+        if ($submission->has_recurring && 1 != count($prepared_items)) {
819
+            wp_send_json_error(__('Recurring items should be bought individually.', 'invoicing'));
820 820
         }
821 821
 
822 822
         // Prepare the submission details.
823 823
         $prepared = array(
824
-            'billing_email'                    => sanitize_email( $submission->get_billing_email() ),
825
-            __( 'Billing Email', 'invoicing' ) => sanitize_email( $submission->get_billing_email() ),
826
-            __( 'Form Id', 'invoicing' )       => absint( $submission->payment_form->get_id() ),
824
+            'billing_email'                    => sanitize_email($submission->get_billing_email()),
825
+            __('Billing Email', 'invoicing') => sanitize_email($submission->get_billing_email()),
826
+            __('Form Id', 'invoicing')       => absint($submission->payment_form->get_id()),
827 827
         );
828 828
 
829 829
         // Address fields.
830 830
         $address_fields = array();
831 831
 
832 832
         // Add discount code.
833
-        if ( $submission->has_discount_code() ) {
834
-            $address_fields['discount'] = array( $submission->get_discount_code() );
833
+        if ($submission->has_discount_code()) {
834
+            $address_fields['discount'] = array($submission->get_discount_code());
835 835
         }
836 836
 
837 837
         // Are all required fields provided?
838 838
         $data = $submission->get_data();
839 839
 
840
-        foreach ( $submission->payment_form->get_elements() as $field ) {
840
+        foreach ($submission->payment_form->get_elements() as $field) {
841 841
 
842
-            if ( ! empty( $field['premade'] ) ) {
842
+            if (!empty($field['premade'])) {
843 843
                 continue;
844 844
             }
845 845
 
846
-            if ( ! $submission->is_required_field_set( $field ) ) {
847
-                wp_send_json_error( __( 'Fill all required fields.', 'invoicing' ) );
846
+            if (!$submission->is_required_field_set($field)) {
847
+                wp_send_json_error(__('Fill all required fields.', 'invoicing'));
848 848
             }
849 849
 
850
-            if ( $field['type'] == 'address' ) {
850
+            if ($field['type'] == 'address') {
851 851
 
852
-                foreach ( $field['fields'] as $address_field ) {
852
+                foreach ($field['fields'] as $address_field) {
853 853
 
854
-                    if ( empty( $address_field['visible'] ) ) {
854
+                    if (empty($address_field['visible'])) {
855 855
                         continue;
856 856
                     }
857 857
 
858
-                    if ( ! empty( $address_field['required'] ) && empty( $data[ $address_field['name'] ] ) ) {
859
-                        wp_send_json_error( __( 'Some required fields have not been filled.', 'invoicing' ) );
858
+                    if (!empty($address_field['required']) && empty($data[$address_field['name']])) {
859
+                        wp_send_json_error(__('Some required fields have not been filled.', 'invoicing'));
860 860
                     }
861 861
 
862
-                    if ( isset( $data[ $address_field['name'] ] ) ) {
863
-                        $label = str_replace( 'wpinv_', '', $address_field['name'] );
864
-                        $address_fields[ $label ] = wpinv_clean( $data[ $address_field['name'] ] );
862
+                    if (isset($data[$address_field['name']])) {
863
+                        $label = str_replace('wpinv_', '', $address_field['name']);
864
+                        $address_fields[$label] = wpinv_clean($data[$address_field['name']]);
865 865
                     }
866 866
 
867 867
                 }
868 868
 
869
-            } else if ( isset( $data[ $field['id'] ] ) ) {
869
+            } else if (isset($data[$field['id']])) {
870 870
                 $label = $field['id'];
871 871
 
872
-                if ( isset( $field['label'] ) ) {
872
+                if (isset($field['label'])) {
873 873
                     $label = $field['label'];
874 874
                 }
875 875
 
876
-                $prepared[ wpinv_clean( $label ) ] = wpinv_clean( $data[ $field['id'] ] );
876
+                $prepared[wpinv_clean($label)] = wpinv_clean($data[$field['id']]);
877 877
             }
878 878
 
879 879
         }
880 880
 
881 881
         // (Maybe) create the user.
882
-        $user = get_user_by( 'email', $prepared['billing_email'] );
882
+        $user = get_user_by('email', $prepared['billing_email']);
883 883
 
884
-        if ( empty( $user ) ) {
885
-            $user = wpinv_create_user( $prepared['billing_email'] );
884
+        if (empty($user)) {
885
+            $user = wpinv_create_user($prepared['billing_email']);
886 886
         }
887 887
 
888
-        if ( is_wp_error( $user ) ) {
889
-            wp_send_json_error( $user->get_error_message() );
888
+        if (is_wp_error($user)) {
889
+            wp_send_json_error($user->get_error_message());
890 890
         }
891 891
 
892
-        if ( is_numeric( $user ) ) {
893
-            $user = get_user_by( 'id', $user );
892
+        if (is_numeric($user)) {
893
+            $user = get_user_by('id', $user);
894 894
         }
895 895
 
896 896
         // Create the invoice.
897
-        if ( ! $submission->has_invoice() ) {
897
+        if (!$submission->has_invoice()) {
898 898
 
899 899
             $invoice = wpinv_insert_invoice(
900 900
                 array(
@@ -911,8 +911,8 @@  discard block
 block discarded – undo
911 911
 
912 912
             $invoice = $submission->get_invoice();
913 913
 
914
-            if ( $invoice->is_paid() ) {
915
-                wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
914
+            if ($invoice->is_paid()) {
915
+                wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
916 916
             }
917 917
 
918 918
             $invoice = wpinv_update_invoice(
@@ -927,34 +927,34 @@  discard block
 block discarded – undo
927 927
 
928 928
         }
929 929
 
930
-        if ( is_wp_error( $invoice ) ) {
931
-            wp_send_json_error( $invoice->get_error_message() );
930
+        if (is_wp_error($invoice)) {
931
+            wp_send_json_error($invoice->get_error_message());
932 932
         }
933 933
 
934
-        if ( empty( $invoice ) ) {
935
-            wp_send_json_error( __( 'Could not create your invoice.', 'invoicing' ) );
934
+        if (empty($invoice)) {
935
+            wp_send_json_error(__('Could not create your invoice.', 'invoicing'));
936 936
         }
937 937
 
938
-        unset( $prepared['billing_email'] );
939
-        update_post_meta( $invoice->ID, 'payment_form_data', $prepared );
938
+        unset($prepared['billing_email']);
939
+        update_post_meta($invoice->ID, 'payment_form_data', $prepared);
940 940
 
941 941
         $wpi_checkout_id = $invoice->ID;
942 942
         $cart_total = wpinv_price(
943 943
             wpinv_format_amount(
944
-                wpinv_get_cart_total( $invoice->get_cart_details(), NULL, $invoice ) ),
944
+                wpinv_get_cart_total($invoice->get_cart_details(), NULL, $invoice) ),
945 945
                 $invoice->get_currency()
946 946
         );
947 947
 
948 948
         $data                   = array();
949 949
         $data['invoice_id']     = $invoice->ID;
950
-        $data['cart_discounts'] = $invoice->get_discounts( true );
950
+        $data['cart_discounts'] = $invoice->get_discounts(true);
951 951
 
952
-        wpinv_set_checkout_session( $data );
953
-        add_filter( 'wp_redirect', array( $invoicing->form_elements, 'send_redirect_response' ) );
954
-        add_action( 'wpinv_pre_send_back_to_checkout', array( $invoicing->form_elements, 'checkout_error' ) );
952
+        wpinv_set_checkout_session($data);
953
+        add_filter('wp_redirect', array($invoicing->form_elements, 'send_redirect_response'));
954
+        add_action('wpinv_pre_send_back_to_checkout', array($invoicing->form_elements, 'checkout_error'));
955 955
         
956
-        if ( ! defined( 'WPINV_CHECKOUT' ) ) {
957
-            define( 'WPINV_CHECKOUT', true );
956
+        if (!defined('WPINV_CHECKOUT')) {
957
+            define('WPINV_CHECKOUT', true);
958 958
         }
959 959
 
960 960
         wpinv_process_checkout();
@@ -972,51 +972,51 @@  discard block
 block discarded – undo
972 972
     public static function get_payment_form_states_field() {
973 973
         global $invoicing;
974 974
 
975
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
975
+        if (empty($_GET['country']) || empty($_GET['form'])) {
976 976
             exit;
977 977
         }
978 978
 
979
-        $elements = $invoicing->form_elements->get_form_elements( $_GET['form'] );
979
+        $elements = $invoicing->form_elements->get_form_elements($_GET['form']);
980 980
 
981
-        if ( empty( $elements ) ) {
981
+        if (empty($elements)) {
982 982
             exit;
983 983
         }
984 984
 
985 985
         $address_fields = array();
986
-        foreach ( $elements as $element ) {
987
-            if ( 'address' === $element['type'] ) {
986
+        foreach ($elements as $element) {
987
+            if ('address' === $element['type']) {
988 988
                 $address_fields = $element;
989 989
                 break;
990 990
             }
991 991
         }
992 992
 
993
-        if ( empty( $address_fields ) ) {
993
+        if (empty($address_fields)) {
994 994
             exit;
995 995
         }
996 996
 
997
-        foreach( $address_fields['fields'] as $address_field ) {
997
+        foreach ($address_fields['fields'] as $address_field) {
998 998
 
999
-            if ( 'wpinv_state' == $address_field['name'] ) {
999
+            if ('wpinv_state' == $address_field['name']) {
1000 1000
 
1001 1001
                 $label = $address_field['label'];
1002 1002
 
1003
-                if ( ! empty( $address_field['required'] ) ) {
1003
+                if (!empty($address_field['required'])) {
1004 1004
                     $label .= "<span class='text-danger'> *</span>";
1005 1005
                 }
1006 1006
 
1007
-                $states = wpinv_get_country_states( $_GET['country'] );
1007
+                $states = wpinv_get_country_states($_GET['country']);
1008 1008
 
1009
-                if ( ! empty( $states ) ) {
1009
+                if (!empty($states)) {
1010 1010
 
1011 1011
                     $html = aui()->select(
1012 1012
                             array(
1013 1013
                                 'options'          => $states,
1014
-                                'name'             => esc_attr( $address_field['name'] ),
1015
-                                'id'               => esc_attr( $address_field['name'] ),
1016
-                                'placeholder'      => esc_attr( $address_field['placeholder'] ),
1014
+                                'name'             => esc_attr($address_field['name']),
1015
+                                'id'               => esc_attr($address_field['name']),
1016
+                                'placeholder'      => esc_attr($address_field['placeholder']),
1017 1017
                                 'required'         => (bool) $address_field['required'],
1018 1018
                                 'no_wrap'          => true,
1019
-                                'label'            => wp_kses_post( $label ),
1019
+                                'label'            => wp_kses_post($label),
1020 1020
                                 'select2'          => false,
1021 1021
                             )
1022 1022
                         );
@@ -1025,10 +1025,10 @@  discard block
 block discarded – undo
1025 1025
 
1026 1026
                     $html = aui()->input(
1027 1027
                             array(
1028
-                                'name'       => esc_attr( $address_field['name'] ),
1029
-                                'id'         => esc_attr( $address_field['name'] ),
1028
+                                'name'       => esc_attr($address_field['name']),
1029
+                                'id'         => esc_attr($address_field['name']),
1030 1030
                                 'required'   => (bool) $address_field['required'],
1031
-                                'label'      => wp_kses_post( $label ),
1031
+                                'label'      => wp_kses_post($label),
1032 1032
                                 'no_wrap'    => true,
1033 1033
                                 'type'       => 'text',
1034 1034
                             )
@@ -1036,7 +1036,7 @@  discard block
 block discarded – undo
1036 1036
 
1037 1037
                 }
1038 1038
 
1039
-                wp_send_json_success( str_replace( 'sr-only', '', $html ) );
1039
+                wp_send_json_success(str_replace('sr-only', '', $html));
1040 1040
                 exit;
1041 1041
 
1042 1042
             }
@@ -1052,33 +1052,33 @@  discard block
 block discarded – undo
1052 1052
     public static function get_invoice_items() {
1053 1053
 
1054 1054
         // Verify nonce.
1055
-        check_ajax_referer( 'wpinv-nonce' );
1055
+        check_ajax_referer('wpinv-nonce');
1056 1056
 
1057
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
1057
+        if (!wpinv_current_user_can_manage_invoicing()) {
1058 1058
             exit;
1059 1059
         }
1060 1060
 
1061 1061
         // We need an invoice and items.
1062
-        if ( empty( $_POST['post_id'] ) ) {
1062
+        if (empty($_POST['post_id'])) {
1063 1063
             exit;
1064 1064
         }
1065 1065
 
1066 1066
         // Fetch the invoice.
1067
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
1067
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
1068 1068
 
1069 1069
         // Ensure it exists.
1070
-        if ( ! $invoice->get_id() ) {
1070
+        if (!$invoice->get_id()) {
1071 1071
             exit;
1072 1072
         }
1073 1073
 
1074 1074
         // Return an array of invoice items.
1075 1075
         $items = array();
1076 1076
 
1077
-        foreach ( $invoice->get_items() as $item_id => $item ) {
1078
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax();
1077
+        foreach ($invoice->get_items() as $item_id => $item) {
1078
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax();
1079 1079
         }
1080 1080
 
1081
-        wp_send_json_success( compact( 'items' ) );
1081
+        wp_send_json_success(compact('items'));
1082 1082
     }
1083 1083
 
1084 1084
     /**
@@ -1087,48 +1087,48 @@  discard block
 block discarded – undo
1087 1087
     public static function edit_invoice_item() {
1088 1088
 
1089 1089
         // Verify nonce.
1090
-        check_ajax_referer( 'wpinv-nonce' );
1090
+        check_ajax_referer('wpinv-nonce');
1091 1091
 
1092
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
1092
+        if (!wpinv_current_user_can_manage_invoicing()) {
1093 1093
             exit;
1094 1094
         }
1095 1095
 
1096 1096
         // We need an invoice and item details.
1097
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
1097
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
1098 1098
             exit;
1099 1099
         }
1100 1100
 
1101 1101
         // Fetch the invoice.
1102
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
1102
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
1103 1103
 
1104 1104
         // Ensure it exists and its not been paid for.
1105
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
1105
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
1106 1106
             exit;
1107 1107
         }
1108 1108
 
1109 1109
         // Format the data.
1110
-        $data = wp_list_pluck( $_POST['data'], 'value', 'field' );
1110
+        $data = wp_list_pluck($_POST['data'], 'value', 'field');
1111 1111
 
1112 1112
         // Ensure that we have an item id.
1113
-        if ( empty( $data['id'] ) ) {
1113
+        if (empty($data['id'])) {
1114 1114
             exit;
1115 1115
         }
1116 1116
 
1117 1117
         // Abort if the invoice does not have the specified item.
1118
-        $item = $invoice->get_item( (int) $data['id'] );
1118
+        $item = $invoice->get_item((int) $data['id']);
1119 1119
 
1120
-        if ( empty( $item ) ) {
1120
+        if (empty($item)) {
1121 1121
             exit;
1122 1122
         }
1123 1123
 
1124 1124
         // Update the item.
1125
-        $item->set_price( $data['price'] );
1126
-        $item->set_name( $data['name'] );
1127
-        $item->set_description( $data['description'] );
1128
-        $item->set_quantity( $data['quantity'] );
1125
+        $item->set_price($data['price']);
1126
+        $item->set_name($data['name']);
1127
+        $item->set_description($data['description']);
1128
+        $item->set_quantity($data['quantity']);
1129 1129
 
1130 1130
         // Add it to the invoice.
1131
-        $invoice->add_item( $item );
1131
+        $invoice->add_item($item);
1132 1132
 
1133 1133
         // Update totals.
1134 1134
         $invoice->recalculate_total();
@@ -1139,11 +1139,11 @@  discard block
 block discarded – undo
1139 1139
         // Return an array of invoice items.
1140 1140
         $items = array();
1141 1141
 
1142
-        foreach ( $invoice->get_items() as $item_id => $item ) {
1143
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax();
1142
+        foreach ($invoice->get_items() as $item_id => $item) {
1143
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax();
1144 1144
         }
1145 1145
 
1146
-        wp_send_json_success( compact( 'items' ) );
1146
+        wp_send_json_success(compact('items'));
1147 1147
     }
1148 1148
     /**
1149 1149
      * Adds a items to an invoice.
@@ -1151,38 +1151,38 @@  discard block
 block discarded – undo
1151 1151
     public static function add_invoice_items() {
1152 1152
 
1153 1153
         // Verify nonce.
1154
-        check_ajax_referer( 'wpinv-nonce' );
1154
+        check_ajax_referer('wpinv-nonce');
1155 1155
 
1156
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
1156
+        if (!wpinv_current_user_can_manage_invoicing()) {
1157 1157
             exit;
1158 1158
         }
1159 1159
 
1160 1160
         // We need an invoice and items.
1161
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
1161
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
1162 1162
             exit;
1163 1163
         }
1164 1164
 
1165 1165
         // Fetch the invoice.
1166
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
1166
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
1167 1167
         $alert   = false;
1168 1168
 
1169 1169
         // Ensure it exists and its not been paid for.
1170
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
1170
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
1171 1171
             exit;
1172 1172
         }
1173 1173
 
1174 1174
         // Add the items.
1175
-        foreach ( $_POST['items'] as $data ) {
1175
+        foreach ($_POST['items'] as $data) {
1176 1176
 
1177
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
1177
+            $item = new GetPaid_Form_Item($data['id']);
1178 1178
 
1179
-            if ( is_numeric( $data[ 'qty' ] ) && (int) $data[ 'qty' ] > 0 ) {
1180
-                $item->set_quantity( $data[ 'qty' ] );
1179
+            if (is_numeric($data['qty']) && (int) $data['qty'] > 0) {
1180
+                $item->set_quantity($data['qty']);
1181 1181
             }
1182 1182
 
1183
-            if ( $item->get_id() > 0 ) {
1184
-                if ( ! $invoice->add_item( $item ) ) {
1185
-                    $alert = __( 'An invoice can only contain one recurring item', 'invoicing' );
1183
+            if ($item->get_id() > 0) {
1184
+                if (!$invoice->add_item($item)) {
1185
+                    $alert = __('An invoice can only contain one recurring item', 'invoicing');
1186 1186
                 }
1187 1187
             }
1188 1188
 
@@ -1195,11 +1195,11 @@  discard block
 block discarded – undo
1195 1195
         // Return an array of invoice items.
1196 1196
         $items = array();
1197 1197
 
1198
-        foreach ( $invoice->get_items() as $item_id => $item ) {
1199
-            $items[ $item_id ] = $item->prepare_data_for_invoice_edit_ajax();
1198
+        foreach ($invoice->get_items() as $item_id => $item) {
1199
+            $items[$item_id] = $item->prepare_data_for_invoice_edit_ajax();
1200 1200
         }
1201 1201
 
1202
-        wp_send_json_success( compact( 'items', 'alert' ) );
1202
+        wp_send_json_success(compact('items', 'alert'));
1203 1203
     }
1204 1204
 
1205 1205
     /**
@@ -1208,15 +1208,15 @@  discard block
 block discarded – undo
1208 1208
     public static function get_invoicing_items() {
1209 1209
 
1210 1210
         // Verify nonce.
1211
-        check_ajax_referer( 'wpinv-nonce' );
1211
+        check_ajax_referer('wpinv-nonce');
1212 1212
 
1213
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
1213
+        if (!wpinv_current_user_can_manage_invoicing()) {
1214 1214
             exit;
1215 1215
         }
1216 1216
 
1217 1217
         // We need a search term.
1218
-        if ( empty( $_GET['search'] ) ) {
1219
-            wp_send_json_success( array() );
1218
+        if (empty($_GET['search'])) {
1219
+            wp_send_json_success(array());
1220 1220
         }
1221 1221
 
1222 1222
         // Retrieve items.
@@ -1225,8 +1225,8 @@  discard block
 block discarded – undo
1225 1225
             'orderby'        => 'title',
1226 1226
             'order'          => 'ASC',
1227 1227
             'posts_per_page' => -1,
1228
-            'post_status'    => array( 'publish' ),
1229
-            's'              => trim( $_GET['search'] ),
1228
+            'post_status'    => array('publish'),
1229
+            's'              => trim($_GET['search']),
1230 1230
             'meta_query'     => array(
1231 1231
                 array(
1232 1232
                     'key'       => '_wpinv_type',
@@ -1236,18 +1236,18 @@  discard block
 block discarded – undo
1236 1236
             )
1237 1237
         );
1238 1238
 
1239
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
1239
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
1240 1240
         $data  = array();
1241 1241
 
1242
-        foreach ( $items as $item ) {
1243
-            $item      = new GetPaid_Form_Item( $item );
1242
+        foreach ($items as $item) {
1243
+            $item = new GetPaid_Form_Item($item);
1244 1244
             $data[] = array(
1245 1245
                 'id'   => $item->get_id(),
1246 1246
                 'text' => $item->get_name()
1247 1247
             );
1248 1248
         }
1249 1249
 
1250
-        wp_send_json_success( $data );
1250
+        wp_send_json_success($data);
1251 1251
 
1252 1252
     }
1253 1253
 
@@ -1257,24 +1257,24 @@  discard block
 block discarded – undo
1257 1257
     public static function get_aui_states_field() {
1258 1258
 
1259 1259
         // Verify nonce.
1260
-        check_ajax_referer( 'wpinv-nonce' );
1260
+        check_ajax_referer('wpinv-nonce');
1261 1261
 
1262 1262
         // We need a country.
1263
-        if ( empty( $_GET['country'] ) ) {
1263
+        if (empty($_GET['country'])) {
1264 1264
             exit;
1265 1265
         }
1266 1266
 
1267
-        $states = wpinv_get_country_states( trim( $_GET['country'] ) );
1268
-        $state  = isset( $_GET['state'] ) ? trim( $_GET['state'] ) : wpinv_get_default_state();
1267
+        $states = wpinv_get_country_states(trim($_GET['country']));
1268
+        $state  = isset($_GET['state']) ? trim($_GET['state']) : wpinv_get_default_state();
1269 1269
 
1270
-        if ( empty( $states ) ) {
1270
+        if (empty($states)) {
1271 1271
 
1272 1272
             $html = aui()->input(
1273 1273
                 array(
1274 1274
                     'type'        => 'text',
1275 1275
                     'id'          => 'wpinv_state',
1276 1276
                     'name'        => 'wpinv_state',
1277
-                    'label'       => __( 'State', 'invoicing' ),
1277
+                    'label'       => __('State', 'invoicing'),
1278 1278
                     'label_type'  => 'vertical',
1279 1279
                     'placeholder' => 'Liège',
1280 1280
                     'class'       => 'form-control-sm',
@@ -1288,9 +1288,9 @@  discard block
 block discarded – undo
1288 1288
                 array(
1289 1289
                     'id'          => 'wpinv_state',
1290 1290
                     'name'        => 'wpinv_state',
1291
-                    'label'       => __( 'State', 'invoicing' ),
1291
+                    'label'       => __('State', 'invoicing'),
1292 1292
                     'label_type'  => 'vertical',
1293
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
1293
+                    'placeholder' => __('Select a state', 'invoicing'),
1294 1294
                     'class'       => 'form-control-sm',
1295 1295
                     'value'       => $state,
1296 1296
                     'options'     => $states,
@@ -1304,7 +1304,7 @@  discard block
 block discarded – undo
1304 1304
         wp_send_json_success(
1305 1305
             array(
1306 1306
                 'html'   => $html,
1307
-                'select' => ! empty ( $states )
1307
+                'select' => !empty ($states)
1308 1308
             )
1309 1309
         );
1310 1310
 
@@ -1318,11 +1318,11 @@  discard block
 block discarded – undo
1318 1318
     public static function payment_form_refresh_prices() {
1319 1319
 
1320 1320
         // Check nonce.
1321
-        check_ajax_referer( 'getpaid_form_nonce' );
1321
+        check_ajax_referer('getpaid_form_nonce');
1322 1322
 
1323 1323
         // ... form fields...
1324
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1325
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
1324
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1325
+            _e('Error: Reload the page and try again.', 'invoicing');
1326 1326
             exit;
1327 1327
         }
1328 1328
 
@@ -1330,7 +1330,7 @@  discard block
 block discarded – undo
1330 1330
         $submission = new GetPaid_Payment_Form_Submission();
1331 1331
 
1332 1332
         // Do we have an error?
1333
-        if ( ! empty( $submission->last_error ) ) {
1333
+        if (!empty($submission->last_error)) {
1334 1334
             echo $submission->last_error;
1335 1335
             exit;
1336 1336
         }
@@ -1341,38 +1341,38 @@  discard block
 block discarded – undo
1341 1341
             'has_recurring' => $submission->has_recurring,
1342 1342
             'is_free'       => $submission->get_payment_details(),
1343 1343
             'totals'        => array(
1344
-                'subtotal'  => wpinv_price( wpinv_format_amount( $submission->subtotal_amount ), $submission->get_currency() ),
1345
-                'discount'  => wpinv_price( wpinv_format_amount( $submission->get_total_discount() ), $submission->get_currency() ),
1346
-                'fees'      => wpinv_price( wpinv_format_amount( $submission->get_total_fees() ), $submission->get_currency() ),
1347
-                'tax'       => wpinv_price( wpinv_format_amount( $submission->get_total_tax() ), $submission->get_currency() ),
1348
-                'total'     => wpinv_price( wpinv_format_amount( $submission->get_total() ), $submission->get_currency() ),
1344
+                'subtotal'  => wpinv_price(wpinv_format_amount($submission->subtotal_amount), $submission->get_currency()),
1345
+                'discount'  => wpinv_price(wpinv_format_amount($submission->get_total_discount()), $submission->get_currency()),
1346
+                'fees'      => wpinv_price(wpinv_format_amount($submission->get_total_fees()), $submission->get_currency()),
1347
+                'tax'       => wpinv_price(wpinv_format_amount($submission->get_total_tax()), $submission->get_currency()),
1348
+                'total'     => wpinv_price(wpinv_format_amount($submission->get_total()), $submission->get_currency()),
1349 1349
             ),
1350 1350
         );
1351 1351
 
1352 1352
         // Add items.
1353 1353
         $items = $submission->get_items();
1354
-        if ( ! empty( $items ) ) {
1354
+        if (!empty($items)) {
1355 1355
             $result['items'] = array();
1356 1356
 
1357
-            foreach( $items as $item_id => $item ) {
1358
-                $result['items']["$item_id"] = wpinv_price( wpinv_format_amount( $item->get_price() * $item->get_qantity() ) );
1357
+            foreach ($items as $item_id => $item) {
1358
+                $result['items']["$item_id"] = wpinv_price(wpinv_format_amount($item->get_price() * $item->get_qantity()));
1359 1359
             }
1360 1360
         }
1361 1361
 
1362 1362
         // Add invoice.
1363
-        if ( $submission->has_invoice() ) {
1363
+        if ($submission->has_invoice()) {
1364 1364
             $result['invoice'] = $submission->get_invoice()->ID;
1365 1365
         }
1366 1366
 
1367 1367
         // Add discount code.
1368
-        if ( $submission->has_discount_code() ) {
1368
+        if ($submission->has_discount_code()) {
1369 1369
             $result['discount_code'] = $submission->get_discount_code();
1370 1370
         }
1371 1371
 
1372 1372
         // Filter the result.
1373
-        $result = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $result, $submission );
1373
+        $result = apply_filters('getpaid_payment_form_ajax_refresh_prices', $result, $submission);
1374 1374
 
1375
-        wp_send_json_success( $result );
1375
+        wp_send_json_success($result);
1376 1376
     }
1377 1377
 
1378 1378
     /**
@@ -1383,53 +1383,53 @@  discard block
 block discarded – undo
1383 1383
     public static function buy_items() {
1384 1384
         $user_id = get_current_user_id();
1385 1385
 
1386
-        if ( empty( $user_id ) ) { // If not logged in then lets redirect to the login page
1387
-            wp_send_json( array(
1388
-                'success' => wp_login_url( wp_get_referer() )
1389
-            ) );
1386
+        if (empty($user_id)) { // If not logged in then lets redirect to the login page
1387
+            wp_send_json(array(
1388
+                'success' => wp_login_url(wp_get_referer())
1389
+            ));
1390 1390
         } else {
1391 1391
             // Only check nonce if logged in as it could be cached when logged out.
1392
-            if ( ! isset( $_POST['wpinv_buy_nonce'] ) || ! wp_verify_nonce( $_POST['wpinv_buy_nonce'], 'wpinv_buy_items' ) ) {
1393
-                wp_send_json( array(
1394
-                    'error' => __( 'Security checks failed.', 'invoicing' )
1395
-                ) );
1392
+            if (!isset($_POST['wpinv_buy_nonce']) || !wp_verify_nonce($_POST['wpinv_buy_nonce'], 'wpinv_buy_items')) {
1393
+                wp_send_json(array(
1394
+                    'error' => __('Security checks failed.', 'invoicing')
1395
+                ));
1396 1396
                 wp_die();
1397 1397
             }
1398 1398
 
1399 1399
             // allow to set a custom price through post_id
1400 1400
             $items = $_POST['items'];
1401
-            $related_post_id = isset( $_POST['post_id'] ) ? (int)$_POST['post_id'] : 0;
1402
-            $custom_item_price = $related_post_id ? abs( get_post_meta( $related_post_id, '_wpi_custom_price', true ) ) : 0;
1401
+            $related_post_id = isset($_POST['post_id']) ? (int) $_POST['post_id'] : 0;
1402
+            $custom_item_price = $related_post_id ? abs(get_post_meta($related_post_id, '_wpi_custom_price', true)) : 0;
1403 1403
 
1404 1404
             $cart_items = array();
1405
-            if ( $items ) {
1406
-                $items = explode( ',', $items );
1405
+            if ($items) {
1406
+                $items = explode(',', $items);
1407 1407
 
1408
-                foreach( $items as $item ) {
1408
+                foreach ($items as $item) {
1409 1409
                     $item_id = $item;
1410 1410
                     $quantity = 1;
1411 1411
 
1412
-                    if ( strpos( $item, '|' ) !== false ) {
1413
-                        $item_parts = explode( '|', $item );
1412
+                    if (strpos($item, '|') !== false) {
1413
+                        $item_parts = explode('|', $item);
1414 1414
                         $item_id = $item_parts[0];
1415 1415
                         $quantity = $item_parts[1];
1416 1416
                     }
1417 1417
 
1418
-                    if ( $item_id && $quantity ) {
1418
+                    if ($item_id && $quantity) {
1419 1419
                         $cart_items_arr = array(
1420
-                            'id'            => (int)$item_id,
1421
-                            'quantity'      => (int)$quantity
1420
+                            'id'            => (int) $item_id,
1421
+                            'quantity'      => (int) $quantity
1422 1422
                         );
1423 1423
 
1424 1424
                         // If there is a related post id then add it to meta
1425
-                        if ( $related_post_id ) {
1425
+                        if ($related_post_id) {
1426 1426
                             $cart_items_arr['meta'] = array(
1427 1427
                                 'post_id'   => $related_post_id
1428 1428
                             );
1429 1429
                         }
1430 1430
 
1431 1431
                         // If there is a custom price then set it.
1432
-                        if ( $custom_item_price ) {
1432
+                        if ($custom_item_price) {
1433 1433
                             $cart_items_arr['custom_price'] = $custom_item_price;
1434 1434
                         }
1435 1435
 
@@ -1445,37 +1445,37 @@  discard block
 block discarded – undo
1445 1445
              * @param int $related_post_id The related post id if any.
1446 1446
              * @since 1.0.0
1447 1447
              */
1448
-            $cart_items = apply_filters( 'wpinv_buy_cart_items', $cart_items, $related_post_id );
1448
+            $cart_items = apply_filters('wpinv_buy_cart_items', $cart_items, $related_post_id);
1449 1449
 
1450 1450
             // Make sure its not in the cart already, if it is then redirect to checkout.
1451 1451
             $cart_invoice = wpinv_get_invoice_cart();
1452 1452
 
1453
-            if ( isset( $cart_invoice->items ) && !empty( $cart_invoice->items ) && !empty( $cart_items ) && serialize( $cart_invoice->items ) == serialize( $cart_items ) ) {
1454
-                wp_send_json( array(
1453
+            if (isset($cart_invoice->items) && !empty($cart_invoice->items) && !empty($cart_items) && serialize($cart_invoice->items) == serialize($cart_items)) {
1454
+                wp_send_json(array(
1455 1455
                     'success' =>  $cart_invoice->get_checkout_payment_url()
1456
-                ) );
1456
+                ));
1457 1457
                 wp_die();
1458 1458
             }
1459 1459
 
1460 1460
             // Check if user has invoice with same items waiting to be paid.
1461
-            $user_invoices = wpinv_get_users_invoices( $user_id , 10 , false , 'wpi-pending' );
1462
-            if ( !empty( $user_invoices ) ) {
1463
-                foreach( $user_invoices as $user_invoice ) {
1461
+            $user_invoices = wpinv_get_users_invoices($user_id, 10, false, 'wpi-pending');
1462
+            if (!empty($user_invoices)) {
1463
+                foreach ($user_invoices as $user_invoice) {
1464 1464
                     $user_cart_details = array();
1465
-                    $invoice  = wpinv_get_invoice( $user_invoice->ID );
1465
+                    $invoice = wpinv_get_invoice($user_invoice->ID);
1466 1466
                     $cart_details = $invoice->get_cart_details();
1467 1467
 
1468
-                    if ( !empty( $cart_details ) ) {
1469
-                        foreach ( $cart_details as $invoice_item ) {
1468
+                    if (!empty($cart_details)) {
1469
+                        foreach ($cart_details as $invoice_item) {
1470 1470
                             $ii_arr = array();
1471
-                            $ii_arr['id'] = (int)$invoice_item['id'];
1472
-                            $ii_arr['quantity'] = (int)$invoice_item['quantity'];
1471
+                            $ii_arr['id'] = (int) $invoice_item['id'];
1472
+                            $ii_arr['quantity'] = (int) $invoice_item['quantity'];
1473 1473
 
1474
-                            if (isset( $invoice_item['meta'] ) && !empty( $invoice_item['meta'] ) ) {
1474
+                            if (isset($invoice_item['meta']) && !empty($invoice_item['meta'])) {
1475 1475
                                 $ii_arr['meta'] = $invoice_item['meta'];
1476 1476
                             }
1477 1477
 
1478
-                            if ( isset( $invoice_item['custom_price'] ) && !empty( $invoice_item['custom_price'] ) ) {
1478
+                            if (isset($invoice_item['custom_price']) && !empty($invoice_item['custom_price'])) {
1479 1479
                                 $ii_arr['custom_price'] = $invoice_item['custom_price'];
1480 1480
                             }
1481 1481
 
@@ -1483,17 +1483,17 @@  discard block
 block discarded – undo
1483 1483
                         }
1484 1484
                     }
1485 1485
 
1486
-                    if ( !empty( $user_cart_details ) && serialize( $cart_items ) == serialize( $user_cart_details ) ) {
1487
-                        wp_send_json( array(
1486
+                    if (!empty($user_cart_details) && serialize($cart_items) == serialize($user_cart_details)) {
1487
+                        wp_send_json(array(
1488 1488
                             'success' =>  $invoice->get_checkout_payment_url()
1489
-                        ) );
1489
+                        ));
1490 1490
                         wp_die();
1491 1491
                     }
1492 1492
                 }
1493 1493
             }
1494 1494
 
1495 1495
             // Create invoice and send user to checkout
1496
-            if ( !empty( $cart_items ) ) {
1496
+            if (!empty($cart_items)) {
1497 1497
                 $invoice_data = array(
1498 1498
                     'status'        =>  'wpi-pending',
1499 1499
                     'created_via'   =>  'wpi',
@@ -1501,21 +1501,21 @@  discard block
 block discarded – undo
1501 1501
                     'cart_details'  =>  $cart_items,
1502 1502
                 );
1503 1503
 
1504
-                $invoice = wpinv_insert_invoice( $invoice_data, true );
1504
+                $invoice = wpinv_insert_invoice($invoice_data, true);
1505 1505
 
1506
-                if ( !empty( $invoice ) && isset( $invoice->ID ) ) {
1507
-                    wp_send_json( array(
1506
+                if (!empty($invoice) && isset($invoice->ID)) {
1507
+                    wp_send_json(array(
1508 1508
                         'success' =>  $invoice->get_checkout_payment_url()
1509
-                    ) );
1509
+                    ));
1510 1510
                 } else {
1511
-                    wp_send_json( array(
1512
-                        'error' => __( 'Invoice failed to create', 'invoicing' )
1513
-                    ) );
1511
+                    wp_send_json(array(
1512
+                        'error' => __('Invoice failed to create', 'invoicing')
1513
+                    ));
1514 1514
                 }
1515 1515
             } else {
1516
-                wp_send_json( array(
1517
-                    'error' => __( 'Items not valid.', 'invoicing' )
1518
-                ) );
1516
+                wp_send_json(array(
1517
+                    'error' => __('Items not valid.', 'invoicing')
1518
+                ));
1519 1519
             }
1520 1520
         }
1521 1521
 
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -887,8 +887,8 @@
 block discarded – undo
887 887
     if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888 888
         unset( $data['cart_discounts'] );
889 889
         
890
-         wpinv_set_checkout_session( $data );
891
-         return true;
890
+            wpinv_set_checkout_session( $data );
891
+            return true;
892 892
     }
893 893
     
894 894
     return false;
Please login to merge, or discard this patch.
Spacing   +398 added lines, -398 removed lines patch added patch discarded remove patch
@@ -7,110 +7,110 @@  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_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array) apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!wpinv_current_user_can_manage_invoicing()) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!wpinv_current_user_can_manage_invoicing()) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!wpinv_current_user_can_manage_invoicing()) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
97 97
     return false;
98 98
 }
99 99
 
100
-function wpinv_get_all_discounts( $args = array() ) {
100
+function wpinv_get_all_discounts($args = array()) {
101 101
 
102
-    $args = wp_parse_args( $args, array(
103
-        'status'         => array( 'publish' ),
104
-        'limit'          => get_option( 'posts_per_page' ),
102
+    $args = wp_parse_args($args, array(
103
+        'status'         => array('publish'),
104
+        'limit'          => get_option('posts_per_page'),
105 105
         'page'           => 1,
106 106
         'exclude'        => array(),
107 107
         'orderby'        => 'date',
108 108
         'order'          => 'DESC',
109
-        'type'           => array_keys( wpinv_get_discount_types() ),
109
+        'type'           => array_keys(wpinv_get_discount_types()),
110 110
         'meta_query'     => array(),
111 111
         'return'         => 'objects',
112 112
         'paginate'       => false,
113
-    ) );
113
+    ));
114 114
 
115 115
     $wp_query_args = array(
116 116
         'post_type'      => 'wpi_discount',
@@ -120,18 +120,18 @@  discard block
 block discarded – undo
120 120
         'fields'         => 'ids',
121 121
         'orderby'        => $args['orderby'],
122 122
         'order'          => $args['order'],
123
-        'paged'          => absint( $args['page'] ),
123
+        'paged'          => absint($args['page']),
124 124
     );
125 125
 
126
-    if ( ! empty( $args['exclude'] ) ) {
127
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
126
+    if (!empty($args['exclude'])) {
127
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
128 128
     }
129 129
 
130
-    if ( ! $args['paginate' ] ) {
130
+    if (!$args['paginate']) {
131 131
         $wp_query_args['no_found_rows'] = true;
132 132
     }
133 133
 
134
-    if ( ! empty( $args['search'] ) ) {
134
+    if (!empty($args['search'])) {
135 135
 
136 136
         $wp_query_args['meta_query'][] = array(
137 137
             'key'     => '_wpi_discount_code',
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 
142 142
     }
143 143
 
144
-    if ( ! empty( $args['type'] ) ) {
145
-        $types = wpinv_parse_list( $args['type'] );
144
+    if (!empty($args['type'])) {
145
+        $types = wpinv_parse_list($args['type']);
146 146
         $wp_query_args['meta_query'][] = array(
147 147
             'key'     => '_wpi_discount_type',
148
-            'value'   => implode( ',', $types ),
148
+            'value'   => implode(',', $types),
149 149
             'compare' => 'IN',
150 150
         );
151 151
     }
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
     $wp_query_args = apply_filters('wpinv_get_discount_args', $wp_query_args, $args);
154 154
 
155 155
     // Get results.
156
-    $discounts = new WP_Query( $wp_query_args );
156
+    $discounts = new WP_Query($wp_query_args);
157 157
 
158
-    if ( 'objects' === $args['return'] ) {
159
-        $return = array_map( 'get_post', $discounts->posts );
160
-    } elseif ( 'self' === $args['return'] ) {
158
+    if ('objects' === $args['return']) {
159
+        $return = array_map('get_post', $discounts->posts);
160
+    } elseif ('self' === $args['return']) {
161 161
         return $discounts;
162 162
     } else {
163 163
         $return = $discounts->posts;
164 164
     }
165 165
 
166
-    if ( $args['paginate' ] ) {
166
+    if ($args['paginate']) {
167 167
         return (object) array(
168 168
             'discounts'      => $return,
169 169
             'total'         => $discounts->found_posts,
@@ -180,9 +180,9 @@  discard block
 block discarded – undo
180 180
 
181 181
     $discounts  = wpinv_get_discounts();
182 182
 
183
-    if ( $discounts) {
184
-        foreach ( $discounts as $discount ) {
185
-            if ( wpinv_is_discount_active( $discount->ID, true ) ) {
183
+    if ($discounts) {
184
+        foreach ($discounts as $discount) {
185
+            if (wpinv_is_discount_active($discount->ID, true)) {
186 186
                 $has_active = true;
187 187
                 break;
188 188
             }
@@ -191,16 +191,16 @@  discard block
 block discarded – undo
191 191
     return $has_active;
192 192
 }
193 193
 
194
-function wpinv_get_discount( $discount_id = 0 ) {
195
-    if( empty( $discount_id ) ) {
194
+function wpinv_get_discount($discount_id = 0) {
195
+    if (empty($discount_id)) {
196 196
         return false;
197 197
     }
198 198
 
199
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
199
+    if (get_post_type($discount_id) != 'wpi_discount') {
200 200
         return false;
201 201
     }
202 202
 
203
-    $discount = get_post( $discount_id );
203
+    $discount = get_post($discount_id);
204 204
 
205 205
     return $discount;
206 206
 }
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
  * @since 1.0.15
213 213
  * @return WPInv_Discount
214 214
  */
215
-function wpinv_get_discount_obj( $discount = 0 ) {
216
-    return new WPInv_Discount( $discount );
215
+function wpinv_get_discount_obj($discount = 0) {
216
+    return new WPInv_Discount($discount);
217 217
 }
218 218
 
219 219
 /**
@@ -222,8 +222,8 @@  discard block
 block discarded – undo
222 222
  * @param string $code The discount code.
223 223
  * @return bool|WP_Post
224 224
  */
225
-function wpinv_get_discount_by_code( $code = '' ) {
226
-    return wpinv_get_discount_by( 'code', $code );
225
+function wpinv_get_discount_by_code($code = '') {
226
+    return wpinv_get_discount_by('code', $code);
227 227
 }
228 228
 
229 229
 /**
@@ -233,13 +233,13 @@  discard block
 block discarded – undo
233 233
  * @param string|int $value The field value
234 234
  * @return bool|WP_Post
235 235
  */
236
-function wpinv_get_discount_by( $field = '', $value = '' ) {
237
-    $data = WPInv_Discount::get_data_by( $field, $value );
238
-    if( empty( $data ) ) {
236
+function wpinv_get_discount_by($field = '', $value = '') {
237
+    $data = WPInv_Discount::get_data_by($field, $value);
238
+    if (empty($data)) {
239 239
         return false;
240 240
     }
241 241
 
242
-    return get_post( $data['ID'] );
242
+    return get_post($data['ID']);
243 243
 }
244 244
 
245 245
 /**
@@ -249,68 +249,68 @@  discard block
 block discarded – undo
249 249
  * @param array $data The discount's properties.
250 250
  * @return bool
251 251
  */
252
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
252
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
253 253
     $meta = array(
254
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
255
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
256
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
257
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
258
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
259
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
260
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
261
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
262
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
263
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
264
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
265
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
266
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
254
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
255
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
256
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
257
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
258
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
259
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
260
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
261
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
262
+        'items'             => isset($data['items']) ? $data['items'] : array(),
263
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
264
+        'is_recurring'      => isset($data['recurring']) ? (bool) $data['recurring'] : false,
265
+        'is_single_use'     => isset($data['single_use']) ? (bool) $data['single_use'] : false,
266
+        'uses'              => isset($data['uses']) ? (int) $data['uses'] : false,
267 267
     );
268 268
 
269
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
269
+    if ($meta['type'] == 'percent' && (float) $meta['amount'] > 100) {
270 270
         $meta['amount'] = 100;
271 271
     }
272 272
 
273
-    if ( !empty( $meta['start'] ) ) {
274
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
273
+    if (!empty($meta['start'])) {
274
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
275 275
     }
276 276
 
277
-    if ( !empty( $meta['expiration'] ) ) {
278
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
277
+    if (!empty($meta['expiration'])) {
278
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
279 279
 
280
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
280
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
281 281
             $meta['expiration'] = $meta['start'];
282 282
         }
283 283
     }
284 284
 
285
-    if ( $meta['uses'] === false ) {
286
-        unset( $meta['uses'] );
285
+    if ($meta['uses'] === false) {
286
+        unset($meta['uses']);
287 287
     }
288 288
 
289
-    if ( ! empty( $meta['items'] ) ) {
290
-        foreach ( $meta['items'] as $key => $item ) {
291
-            if ( 0 === intval( $item ) ) {
292
-                unset( $meta['items'][ $key ] );
289
+    if (!empty($meta['items'])) {
290
+        foreach ($meta['items'] as $key => $item) {
291
+            if (0 === intval($item)) {
292
+                unset($meta['items'][$key]);
293 293
             }
294 294
         }
295 295
     }
296 296
 
297
-    if ( ! empty( $meta['excluded_items'] ) ) {
298
-        foreach ( $meta['excluded_items'] as $key => $item ) {
299
-            if ( 0 === intval( $item ) ) {
300
-                unset( $meta['excluded_items'][ $key ] );
297
+    if (!empty($meta['excluded_items'])) {
298
+        foreach ($meta['excluded_items'] as $key => $item) {
299
+            if (0 === intval($item)) {
300
+                unset($meta['excluded_items'][$key]);
301 301
             }
302 302
         }
303 303
     }
304 304
 
305
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
305
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
306 306
 
307
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
307
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
308 308
 
309
-    foreach( $meta as $key => $value ) {
310
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
309
+    foreach ($meta as $key => $value) {
310
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
311 311
     }
312 312
 
313
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
313
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
314 314
 
315 315
     return $post_id;
316 316
 }
@@ -321,10 +321,10 @@  discard block
 block discarded – undo
321 321
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
322 322
  * @return bool
323 323
  */
324
-function wpinv_remove_discount( $discount = 0 ) {
324
+function wpinv_remove_discount($discount = 0) {
325 325
 
326
-    $discount = wpinv_get_discount_obj( $discount );
327
-    if( ! $discount->exists() ) {
326
+    $discount = wpinv_get_discount_obj($discount);
327
+    if (!$discount->exists()) {
328 328
         return false;
329 329
     }
330 330
 
@@ -339,9 +339,9 @@  discard block
 block discarded – undo
339 339
  * @param string $new_status
340 340
  * @return bool
341 341
  */
342
-function wpinv_update_discount_status( $discount = 0, $new_status = 'publish' ) {
343
-    $discount = wpinv_get_discount_obj( $discount );
344
-    return $discount->update_status( $new_status );
342
+function wpinv_update_discount_status($discount = 0, $new_status = 'publish') {
343
+    $discount = wpinv_get_discount_obj($discount);
344
+    return $discount->update_status($new_status);
345 345
 }
346 346
 
347 347
 /**
@@ -350,48 +350,48 @@  discard block
 block discarded – undo
350 350
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
351 351
  * @return bool
352 352
  */
353
-function wpinv_discount_exists( $discount ) {
354
-    $discount = wpinv_get_discount_obj( $discount );
353
+function wpinv_discount_exists($discount) {
354
+    $discount = wpinv_get_discount_obj($discount);
355 355
     return $discount->exists();
356 356
 }
357 357
 
358
-function wpinv_is_discount_active( $code_id = null, $silent = false ) {
359
-    $discount = wpinv_get_discount(  $code_id );
358
+function wpinv_is_discount_active($code_id = null, $silent = false) {
359
+    $discount = wpinv_get_discount($code_id);
360 360
     $return   = false;
361 361
 
362
-    if ( $discount ) {
363
-        if ( wpinv_is_discount_expired( $code_id, $silent ) ) {
364
-            if( defined( 'DOING_AJAX' ) && ! $silent ) {
365
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
362
+    if ($discount) {
363
+        if (wpinv_is_discount_expired($code_id, $silent)) {
364
+            if (defined('DOING_AJAX') && !$silent) {
365
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
366 366
             }
367
-        } elseif ( $discount->post_status == 'publish' ) {
367
+        } elseif ($discount->post_status == 'publish') {
368 368
             $return = true;
369 369
         } else {
370
-            if( defined( 'DOING_AJAX' ) && ! $silent ) {
371
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
370
+            if (defined('DOING_AJAX') && !$silent) {
371
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
372 372
             }
373 373
         }
374 374
     }
375 375
 
376
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
376
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
377 377
 }
378 378
 
379
-function wpinv_get_discount_code( $code_id = null ) {
380
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
379
+function wpinv_get_discount_code($code_id = null) {
380
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
381 381
 
382
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
382
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
383 383
 }
384 384
 
385
-function wpinv_get_discount_start_date( $code_id = null ) {
386
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
385
+function wpinv_get_discount_start_date($code_id = null) {
386
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
387 387
 
388
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
388
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
389 389
 }
390 390
 
391
-function wpinv_get_discount_expiration( $code_id = null ) {
392
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
391
+function wpinv_get_discount_expiration($code_id = null) {
392
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
393 393
 
394
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
394
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
395 395
 }
396 396
 
397 397
 /**
@@ -400,8 +400,8 @@  discard block
 block discarded – undo
400 400
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
401 401
  * @return int
402 402
  */
403
-function wpinv_get_discount_max_uses( $discount = array() ) {
404
-    $discount = wpinv_get_discount_obj( $discount );
403
+function wpinv_get_discount_max_uses($discount = array()) {
404
+    $discount = wpinv_get_discount_obj($discount);
405 405
     return (int) $discount->max_uses;
406 406
 }
407 407
 
@@ -411,8 +411,8 @@  discard block
 block discarded – undo
411 411
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
412 412
  * @return int
413 413
  */
414
-function wpinv_get_discount_uses( $discount = array() ) {
415
-    $discount = wpinv_get_discount_obj( $discount );
414
+function wpinv_get_discount_uses($discount = array()) {
415
+    $discount = wpinv_get_discount_obj($discount);
416 416
     return (int) $discount->uses;
417 417
 }
418 418
 
@@ -422,8 +422,8 @@  discard block
 block discarded – undo
422 422
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
423 423
  * @return float
424 424
  */
425
-function wpinv_get_discount_min_total( $discount = array() ) {
426
-    $discount = wpinv_get_discount_obj( $discount );
425
+function wpinv_get_discount_min_total($discount = array()) {
426
+    $discount = wpinv_get_discount_obj($discount);
427 427
     return (float) $discount->min_total;
428 428
 }
429 429
 
@@ -433,8 +433,8 @@  discard block
 block discarded – undo
433 433
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
434 434
  * @return float
435 435
  */
436
-function wpinv_get_discount_max_total( $discount = array() ) {
437
-    $discount = wpinv_get_discount_obj( $discount );
436
+function wpinv_get_discount_max_total($discount = array()) {
437
+    $discount = wpinv_get_discount_obj($discount);
438 438
     return (float) $discount->max_total;
439 439
 }
440 440
 
@@ -444,8 +444,8 @@  discard block
 block discarded – undo
444 444
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
445 445
  * @return float
446 446
  */
447
-function wpinv_get_discount_amount( $discount = array() ) {
448
-    $discount = wpinv_get_discount_obj( $discount );
447
+function wpinv_get_discount_amount($discount = array()) {
448
+    $discount = wpinv_get_discount_obj($discount);
449 449
     return (float) $discount->amount;
450 450
 }
451 451
 
@@ -456,28 +456,28 @@  discard block
 block discarded – undo
456 456
  * @param bool $name
457 457
  * @return string
458 458
  */
459
-function wpinv_get_discount_type( $discount = array(), $name = false ) {
460
-    $discount = wpinv_get_discount_obj( $discount );
459
+function wpinv_get_discount_type($discount = array(), $name = false) {
460
+    $discount = wpinv_get_discount_obj($discount);
461 461
 
462 462
     // Are we returning the name or just the type.
463
-    if( $name ) {
463
+    if ($name) {
464 464
         return $discount->type_name;
465 465
     }
466 466
 
467 467
     return $discount->type;
468 468
 }
469 469
 
470
-function wpinv_discount_status( $status ) {
471
-    switch( $status ){
470
+function wpinv_discount_status($status) {
471
+    switch ($status) {
472 472
         case 'expired' :
473
-            $name = __( 'Expired', 'invoicing' );
473
+            $name = __('Expired', 'invoicing');
474 474
             break;
475 475
         case 'publish' :
476 476
         case 'active' :
477
-            $name = __( 'Active', 'invoicing' );
477
+            $name = __('Active', 'invoicing');
478 478
             break;
479 479
         default :
480
-            $name = __( 'Inactive', 'invoicing' );
480
+            $name = __('Inactive', 'invoicing');
481 481
             break;
482 482
     }
483 483
     return $name;
@@ -489,8 +489,8 @@  discard block
 block discarded – undo
489 489
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
490 490
  * @return array
491 491
  */
492
-function wpinv_get_discount_excluded_items( $discount = array() ) {
493
-    $discount = wpinv_get_discount_obj( $discount );
492
+function wpinv_get_discount_excluded_items($discount = array()) {
493
+    $discount = wpinv_get_discount_obj($discount);
494 494
     return $discount->excluded_items;
495 495
 }
496 496
 
@@ -500,17 +500,17 @@  discard block
 block discarded – undo
500 500
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
501 501
  * @return array
502 502
  */
503
-function wpinv_get_discount_item_reqs( $discount = array() ) {
504
-    $discount = wpinv_get_discount_obj( $discount );
503
+function wpinv_get_discount_item_reqs($discount = array()) {
504
+    $discount = wpinv_get_discount_obj($discount);
505 505
     return $discount->items;
506 506
 }
507 507
 
508
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
509
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
508
+function wpinv_get_discount_item_condition($code_id = 0) {
509
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
510 510
 }
511 511
 
512
-function wpinv_is_discount_not_global( $code_id = 0 ) {
513
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
512
+function wpinv_is_discount_not_global($code_id = 0) {
513
+    return (bool) get_post_meta($code_id, '_wpi_discount_is_not_global', true);
514 514
 }
515 515
 
516 516
 /**
@@ -519,14 +519,14 @@  discard block
 block discarded – undo
519 519
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
520 520
  * @return bool
521 521
  */
522
-function wpinv_is_discount_expired( $discount = array(), $silent = false ) {
523
-    $discount = wpinv_get_discount_obj( $discount );
522
+function wpinv_is_discount_expired($discount = array(), $silent = false) {
523
+    $discount = wpinv_get_discount_obj($discount);
524 524
 
525
-    if ( $discount->is_expired() ) {
526
-        $discount->update_status( 'pending' );
525
+    if ($discount->is_expired()) {
526
+        $discount->update_status('pending');
527 527
 
528
-        if( empty( $silent ) ) {
529
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has expired.', 'invoicing' ) );
528
+        if (empty($silent)) {
529
+            wpinv_set_error('wpinv-discount-error', __('This discount has expired.', 'invoicing'));
530 530
         }
531 531
         return true;
532 532
     }
@@ -540,12 +540,12 @@  discard block
 block discarded – undo
540 540
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
541 541
  * @return bool
542 542
  */
543
-function wpinv_is_discount_started( $discount = array() ) {
544
-    $discount = wpinv_get_discount_obj( $discount );
543
+function wpinv_is_discount_started($discount = array()) {
544
+    $discount = wpinv_get_discount_obj($discount);
545 545
     $started  = $discount->has_started();
546 546
 
547
-    if( empty( $started ) ) {
548
-        wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
547
+    if (empty($started)) {
548
+        wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
549 549
     }
550 550
 
551 551
     return $started;
@@ -557,10 +557,10 @@  discard block
 block discarded – undo
557 557
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
558 558
  * @return bool
559 559
  */
560
-function wpinv_check_discount_dates( $discount ) {
561
-    $discount = wpinv_get_discount_obj( $discount );
562
-    $return   = wpinv_is_discount_started( $discount ) && ! wpinv_is_discount_expired( $discount );
563
-    return apply_filters( 'wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code );
560
+function wpinv_check_discount_dates($discount) {
561
+    $discount = wpinv_get_discount_obj($discount);
562
+    $return   = wpinv_is_discount_started($discount) && !wpinv_is_discount_expired($discount);
563
+    return apply_filters('wpinv_check_discount_dates', $return, $discount->ID, $discount, $discount->code);
564 564
 }
565 565
 
566 566
 /**
@@ -569,12 +569,12 @@  discard block
 block discarded – undo
569 569
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
570 570
  * @return bool
571 571
  */
572
-function wpinv_is_discount_maxed_out( $discount ) {
573
-    $discount    = wpinv_get_discount_obj( $discount );
572
+function wpinv_is_discount_maxed_out($discount) {
573
+    $discount    = wpinv_get_discount_obj($discount);
574 574
     $maxed_out   = $discount->has_exceeded_limit();
575 575
 
576
-    if ( $maxed_out ) {
577
-        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
576
+    if ($maxed_out) {
577
+        wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
578 578
     }
579 579
 
580 580
     return $maxed_out;
@@ -586,13 +586,13 @@  discard block
 block discarded – undo
586 586
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
587 587
  * @return bool
588 588
  */
589
-function wpinv_discount_is_min_met( $discount ) {
590
-    $discount    = wpinv_get_discount_obj( $discount );
591
-    $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID );
592
-    $min_met     = $discount->is_minimum_amount_met( $cart_amount );
589
+function wpinv_discount_is_min_met($discount) {
590
+    $discount    = wpinv_get_discount_obj($discount);
591
+    $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID);
592
+    $min_met     = $discount->is_minimum_amount_met($cart_amount);
593 593
 
594
-    if ( ! $min_met ) {
595
-        wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->min_total ) ) ) );
594
+    if (!$min_met) {
595
+        wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->min_total))));
596 596
     }
597 597
 
598 598
     return $min_met;
@@ -604,13 +604,13 @@  discard block
 block discarded – undo
604 604
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
605 605
  * @return bool
606 606
  */
607
-function wpinv_discount_is_max_met( $discount ) {
608
-    $discount    = wpinv_get_discount_obj( $discount );
609
-    $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $discount->ID );
610
-    $max_met     = $discount->is_maximum_amount_met( $cart_amount );
607
+function wpinv_discount_is_max_met($discount) {
608
+    $discount    = wpinv_get_discount_obj($discount);
609
+    $cart_amount = (float) wpinv_get_cart_discountable_subtotal($discount->ID);
610
+    $max_met     = $discount->is_maximum_amount_met($cart_amount);
611 611
 
612
-    if ( ! $max_met ) {
613
-        wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $discount->max_total ) ) ) );
612
+    if (!$max_met) {
613
+        wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($discount->max_total))));
614 614
     }
615 615
 
616 616
     return $max_met;
@@ -622,8 +622,8 @@  discard block
 block discarded – undo
622 622
  * @param int|array|string|WPInv_Discount $discount discount data, object, ID or code.
623 623
  * @return bool
624 624
  */
625
-function wpinv_discount_is_single_use( $discount ) {
626
-    $discount    = wpinv_get_discount_obj( $discount );
625
+function wpinv_discount_is_single_use($discount) {
626
+    $discount = wpinv_get_discount_obj($discount);
627 627
     return $discount->is_single_use;
628 628
 }
629 629
 
@@ -634,53 +634,53 @@  discard block
 block discarded – undo
634 634
  * @param int|array|string|WPInv_Discount $code discount data, object, ID or code.
635 635
  * @return bool
636 636
  */
637
-function wpinv_discount_is_recurring( $discount = 0, $code = 0 ) {
637
+function wpinv_discount_is_recurring($discount = 0, $code = 0) {
638 638
 
639
-    if( ! empty( $discount ) ) {
640
-        $discount    = wpinv_get_discount_obj( $discount );
639
+    if (!empty($discount)) {
640
+        $discount    = wpinv_get_discount_obj($discount);
641 641
     } else {
642
-        $discount    = wpinv_get_discount_obj( $code );
642
+        $discount    = wpinv_get_discount_obj($code);
643 643
     }
644 644
 
645 645
     return $discount->get_is_recurring();
646 646
 }
647 647
 
648
-function wpinv_discount_item_reqs_met( $code_id = null ) {
649
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
650
-    $condition    = wpinv_get_discount_item_condition( $code_id );
651
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
648
+function wpinv_discount_item_reqs_met($code_id = null) {
649
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
650
+    $condition    = wpinv_get_discount_item_condition($code_id);
651
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
652 652
     $cart_items   = wpinv_get_cart_contents();
653
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
653
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
654 654
     $ret          = false;
655 655
 
656
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
656
+    if (empty($item_reqs) && empty($excluded_ps)) {
657 657
         $ret = true;
658 658
     }
659 659
 
660 660
     // Normalize our data for item requirements, exclusions and cart data
661 661
     // First absint the items, then sort, and reset the array keys
662
-    $item_reqs = array_map( 'absint', $item_reqs );
663
-    asort( $item_reqs );
664
-    $item_reqs = array_values( $item_reqs );
662
+    $item_reqs = array_map('absint', $item_reqs);
663
+    asort($item_reqs);
664
+    $item_reqs = array_values($item_reqs);
665 665
 
666
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
667
-    asort( $excluded_ps );
668
-    $excluded_ps  = array_values( $excluded_ps );
666
+    $excluded_ps  = array_map('absint', $excluded_ps);
667
+    asort($excluded_ps);
668
+    $excluded_ps  = array_values($excluded_ps);
669 669
 
670
-    $cart_ids     = array_map( 'absint', $cart_ids );
671
-    asort( $cart_ids );
672
-    $cart_ids     = array_values( $cart_ids );
670
+    $cart_ids     = array_map('absint', $cart_ids);
671
+    asort($cart_ids);
672
+    $cart_ids     = array_values($cart_ids);
673 673
 
674 674
     // Ensure we have requirements before proceeding
675
-    if ( !$ret && ! empty( $item_reqs ) ) {
676
-        switch( $condition ) {
675
+    if (!$ret && !empty($item_reqs)) {
676
+        switch ($condition) {
677 677
             case 'all' :
678 678
                 // Default back to true
679 679
                 $ret = true;
680 680
 
681
-                foreach ( $item_reqs as $item_id ) {
682
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
683
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
681
+                foreach ($item_reqs as $item_id) {
682
+                    if (!wpinv_item_in_cart($item_id)) {
683
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
684 684
                         $ret = false;
685 685
                         break;
686 686
                     }
@@ -689,15 +689,15 @@  discard block
 block discarded – undo
689 689
                 break;
690 690
 
691 691
             default : // Any
692
-                foreach ( $item_reqs as $item_id ) {
693
-                    if ( wpinv_item_in_cart( $item_id ) ) {
692
+                foreach ($item_reqs as $item_id) {
693
+                    if (wpinv_item_in_cart($item_id)) {
694 694
                         $ret = true;
695 695
                         break;
696 696
                     }
697 697
                 }
698 698
 
699
-                if( ! $ret ) {
700
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
699
+                if (!$ret) {
700
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
701 701
                 }
702 702
 
703 703
                 break;
@@ -706,15 +706,15 @@  discard block
 block discarded – undo
706 706
         $ret = true;
707 707
     }
708 708
 
709
-    if( ! empty( $excluded_ps ) ) {
709
+    if (!empty($excluded_ps)) {
710 710
         // Check that there are items other than excluded ones in the cart
711
-        if( $cart_ids == $excluded_ps ) {
712
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
711
+        if ($cart_ids == $excluded_ps) {
712
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
713 713
             $ret = false;
714 714
         }
715 715
     }
716 716
 
717
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
717
+    return (bool) apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
718 718
 }
719 719
 
720 720
 /**
@@ -725,59 +725,59 @@  discard block
 block discarded – undo
725 725
  * @param int|array|string|WPInv_Discount $code_id discount data, object, ID or code.
726 726
  * @return bool
727 727
  */
728
-function wpinv_is_discount_used( $discount = array(), $user = '', $code_id = array() ) {
728
+function wpinv_is_discount_used($discount = array(), $user = '', $code_id = array()) {
729 729
 
730
-    if( ! empty( $discount ) ) {
731
-        $discount = wpinv_get_discount_obj( $discount );
730
+    if (!empty($discount)) {
731
+        $discount = wpinv_get_discount_obj($discount);
732 732
     } else {
733
-        $discount = wpinv_get_discount_obj( $code_id );
733
+        $discount = wpinv_get_discount_obj($code_id);
734 734
     }
735 735
 
736
-    $is_used = ! $discount->is_valid_for_user( $user );
737
-    $is_used = apply_filters( 'wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount );
736
+    $is_used = !$discount->is_valid_for_user($user);
737
+    $is_used = apply_filters('wpinv_is_discount_used', $is_used, $discount->code, $user, $discount->ID, $discount);
738 738
 
739
-    if( $is_used ) {
740
-        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
739
+    if ($is_used) {
740
+        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
741 741
     }
742 742
 
743 743
     return $is_used;
744 744
 }
745 745
 
746
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
746
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
747 747
 
748 748
     // Abort early if there is no discount code.
749
-    if ( empty( $code ) ) {
749
+    if (empty($code)) {
750 750
         return false;
751 751
     }
752 752
 
753 753
     $return      = false;
754
-    $discount_id = wpinv_get_discount_id_by_code( $code );
755
-    $user        = trim( $user );
754
+    $discount_id = wpinv_get_discount_id_by_code($code);
755
+    $user        = trim($user);
756 756
 
757
-    if ( wpinv_get_cart_contents() ) {
758
-        if ( $discount_id !== false ) {
757
+    if (wpinv_get_cart_contents()) {
758
+        if ($discount_id !== false) {
759 759
             if (
760
-                wpinv_is_discount_active( $discount_id ) &&
761
-                wpinv_check_discount_dates( $discount_id ) &&
762
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
763
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
764
-                wpinv_discount_is_min_met( $discount_id ) &&
765
-                wpinv_discount_is_max_met( $discount_id ) &&
766
-                wpinv_discount_item_reqs_met( $discount_id )
760
+                wpinv_is_discount_active($discount_id) &&
761
+                wpinv_check_discount_dates($discount_id) &&
762
+                !wpinv_is_discount_maxed_out($discount_id) &&
763
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
764
+                wpinv_discount_is_min_met($discount_id) &&
765
+                wpinv_discount_is_max_met($discount_id) &&
766
+                wpinv_discount_item_reqs_met($discount_id)
767 767
             ) {
768 768
                 $return = true;
769 769
             }
770
-        } elseif( $set_error ) {
771
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
770
+        } elseif ($set_error) {
771
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
772 772
         }
773 773
     }
774 774
 
775
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
775
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
776 776
 }
777 777
 
778
-function wpinv_get_discount_id_by_code( $code ) {
779
-    $discount = wpinv_get_discount_by_code( $code );
780
-    if( $discount ) {
778
+function wpinv_get_discount_id_by_code($code) {
779
+    $discount = wpinv_get_discount_by_code($code);
780
+    if ($discount) {
781 781
         return $discount->ID;
782 782
     }
783 783
     return false;
@@ -790,9 +790,9 @@  discard block
 block discarded – undo
790 790
  * @param float $base_price The number of usages to increase by
791 791
  * @return float
792 792
  */
793
-function wpinv_get_discounted_amount( $discount, $base_price ) {
794
-    $discount = wpinv_get_discount_obj( $discount );
795
-    return $discount->get_discounted_amount( $base_price );
793
+function wpinv_get_discounted_amount($discount, $base_price) {
794
+    $discount = wpinv_get_discount_obj($discount);
795
+    return $discount->get_discounted_amount($base_price);
796 796
 }
797 797
 
798 798
 /**
@@ -802,9 +802,9 @@  discard block
 block discarded – undo
802 802
  * @param int $by The number of usages to increase by.
803 803
  * @return int the new number of uses.
804 804
  */
805
-function wpinv_increase_discount_usage( $discount, $by = 1 ) {
806
-    $discount   = wpinv_get_discount_obj( $discount );
807
-    return $discount->increase_usage( $by );
805
+function wpinv_increase_discount_usage($discount, $by = 1) {
806
+    $discount = wpinv_get_discount_obj($discount);
807
+    return $discount->increase_usage($by);
808 808
 }
809 809
 
810 810
 /**
@@ -814,72 +814,72 @@  discard block
 block discarded – undo
814 814
  * @param int $by The number of usages to decrease by.
815 815
  * @return int the new number of uses.
816 816
  */
817
-function wpinv_decrease_discount_usage( $discount, $by = 1 ) {
818
-    $discount   = wpinv_get_discount_obj( $discount );
819
-    return $discount->increase_usage( 0 - $by );
817
+function wpinv_decrease_discount_usage($discount, $by = 1) {
818
+    $discount = wpinv_get_discount_obj($discount);
819
+    return $discount->increase_usage(0 - $by);
820 820
 }
821 821
 
822
-function wpinv_format_discount_rate( $type, $amount ) {
823
-    if ( $type == 'flat' ) {
824
-        $rate = wpinv_price( wpinv_format_amount( $amount ) );
822
+function wpinv_format_discount_rate($type, $amount) {
823
+    if ($type == 'flat') {
824
+        $rate = wpinv_price(wpinv_format_amount($amount));
825 825
     } else {
826 826
         $rate = $amount . '%';
827 827
     }
828 828
 
829
-    return apply_filters( 'wpinv_format_discount_rate', $rate, $type, $amount );
829
+    return apply_filters('wpinv_format_discount_rate', $rate, $type, $amount);
830 830
 }
831 831
 
832
-function wpinv_set_cart_discount( $code = '' ) {
833
-    if ( wpinv_multiple_discounts_allowed() ) {
832
+function wpinv_set_cart_discount($code = '') {
833
+    if (wpinv_multiple_discounts_allowed()) {
834 834
         // Get all active cart discounts
835 835
         $discounts = wpinv_get_cart_discounts();
836 836
     } else {
837 837
         $discounts = false; // Only one discount allowed per purchase, so override any existing
838 838
     }
839 839
 
840
-    if ( $discounts ) {
841
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
842
-        if( false !== $key ) {
843
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
840
+    if ($discounts) {
841
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
842
+        if (false !== $key) {
843
+            unset($discounts[$key]); // Can't set the same discount more than once
844 844
         }
845 845
         $discounts[] = $code;
846 846
     } else {
847 847
         $discounts = array();
848 848
         $discounts[] = $code;
849 849
     }
850
-    $discounts = array_values( $discounts );
850
+    $discounts = array_values($discounts);
851 851
 
852 852
     $data = wpinv_get_checkout_session();
853
-    if ( empty( $data ) ) {
853
+    if (empty($data)) {
854 854
         $data = array();
855 855
     } else {
856
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
857
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
858
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
856
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
857
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
858
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
859 859
         }
860 860
     }
861 861
     $data['cart_discounts'] = $discounts;
862 862
 
863
-    wpinv_set_checkout_session( $data );
863
+    wpinv_set_checkout_session($data);
864 864
 
865 865
     return $discounts;
866 866
 }
867 867
 
868
-function wpinv_unset_cart_discount( $code = '' ) {
868
+function wpinv_unset_cart_discount($code = '') {
869 869
     $discounts = wpinv_get_cart_discounts();
870 870
 
871
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
872
-        $key = array_search( $code, $discounts );
873
-        unset( $discounts[ $key ] );
871
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
872
+        $key = array_search($code, $discounts);
873
+        unset($discounts[$key]);
874 874
 
875 875
         $data = wpinv_get_checkout_session();
876 876
         $data['cart_discounts'] = $discounts;
877
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
878
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
879
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
877
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
878
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
879
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
880 880
         }
881 881
 
882
-        wpinv_set_checkout_session( $data );
882
+        wpinv_set_checkout_session($data);
883 883
     }
884 884
 
885 885
     return $discounts;
@@ -888,10 +888,10 @@  discard block
 block discarded – undo
888 888
 function wpinv_unset_all_cart_discounts() {
889 889
     $data = wpinv_get_checkout_session();
890 890
 
891
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
892
-        unset( $data['cart_discounts'] );
891
+    if (!empty($data) && isset($data['cart_discounts'])) {
892
+        unset($data['cart_discounts']);
893 893
 
894
-         wpinv_set_checkout_session( $data );
894
+         wpinv_set_checkout_session($data);
895 895
          return true;
896 896
     }
897 897
 
@@ -900,13 +900,13 @@  discard block
 block discarded – undo
900 900
 
901 901
 function wpinv_get_cart_discounts() {
902 902
     $session = wpinv_get_checkout_session();
903
-    return empty( $session['cart_discounts'] ) ? false : $session['cart_discounts'];
903
+    return empty($session['cart_discounts']) ? false : $session['cart_discounts'];
904 904
 }
905 905
 
906
-function wpinv_cart_has_discounts( $items = array() ) {
906
+function wpinv_cart_has_discounts($items = array()) {
907 907
     $ret = false;
908 908
 
909
-    if ( wpinv_get_cart_discounts( $items ) ) {
909
+    if (wpinv_get_cart_discounts($items)) {
910 910
         $ret = true;
911 911
     }
912 912
 
@@ -917,131 +917,131 @@  discard block
 block discarded – undo
917 917
     }
918 918
     */
919 919
 
920
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
920
+    return apply_filters('wpinv_cart_has_discounts', $ret);
921 921
 }
922 922
 
923
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
923
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
924 924
     $amount = 0.00;
925
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
925
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
926 926
 
927
-    if ( $items ) {
928
-        $discounts = wp_list_pluck( $items, 'discount' );
927
+    if ($items) {
928
+        $discounts = wp_list_pluck($items, 'discount');
929 929
 
930
-        if ( is_array( $discounts ) ) {
931
-            $discounts = array_map( 'floatval', $discounts );
932
-            $amount    = array_sum( $discounts );
930
+        if (is_array($discounts)) {
931
+            $discounts = array_map('floatval', $discounts);
932
+            $amount    = array_sum($discounts);
933 933
         }
934 934
     }
935 935
 
936
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
936
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
937 937
 }
938 938
 
939
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
940
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
939
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
940
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
941 941
 
942
-    if ( empty( $discount ) || empty( $items ) ) {
942
+    if (empty($discount) || empty($items)) {
943 943
         return 0;
944 944
     }
945 945
 
946 946
     $amount = 0;
947 947
 
948
-    foreach ( $items as $item ) {
949
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
948
+    foreach ($items as $item) {
949
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
950 950
     }
951 951
 
952
-    $amount = wpinv_round_amount( $amount );
952
+    $amount = wpinv_round_amount($amount);
953 953
 
954 954
     return $amount;
955 955
 }
956 956
 
957
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
957
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
958 958
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
959 959
 
960 960
     $amount = 0;
961 961
 
962
-    if ( empty( $item ) || empty( $item['id'] ) ) {
962
+    if (empty($item) || empty($item['id'])) {
963 963
         return $amount;
964 964
     }
965 965
 
966
-    if ( empty( $item['quantity'] ) ) {
966
+    if (empty($item['quantity'])) {
967 967
         return $amount;
968 968
     }
969 969
 
970
-    if ( empty( $item['options'] ) ) {
970
+    if (empty($item['options'])) {
971 971
         $item['options'] = array();
972 972
     }
973 973
 
974
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
974
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
975 975
     $discounted_price = $price;
976 976
 
977 977
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
978
-    if ( empty( $discounts ) ) {
978
+    if (empty($discounts)) {
979 979
         return $amount;
980 980
     }
981 981
 
982
-    if ( $discounts ) {
983
-        if ( is_array( $discounts ) ) {
984
-            $discounts = array_values( $discounts );
982
+    if ($discounts) {
983
+        if (is_array($discounts)) {
984
+            $discounts = array_values($discounts);
985 985
         } else {
986
-            $discounts = explode( ',', $discounts );
986
+            $discounts = explode(',', $discounts);
987 987
         }
988 988
     }
989 989
 
990
-    if( $discounts ) {
991
-        foreach ( $discounts as $discount ) {
992
-            $code_id = wpinv_get_discount_id_by_code( $discount );
990
+    if ($discounts) {
991
+        foreach ($discounts as $discount) {
992
+            $code_id = wpinv_get_discount_id_by_code($discount);
993 993
 
994 994
             // Check discount exists
995
-            if( $code_id === false ) {
995
+            if ($code_id === false) {
996 996
                 continue;
997 997
             }
998 998
 
999
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
1000
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
999
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
1000
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
1001 1001
 
1002 1002
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1003
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1004
-                foreach ( $reqs as $item_id ) {
1005
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1006
-                        $discounted_price -= wpinv_get_discounted_amount( $discount, $price );
1003
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1004
+                foreach ($reqs as $item_id) {
1005
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1006
+                        $discounted_price -= wpinv_get_discounted_amount($discount, $price);
1007 1007
                     }
1008 1008
                 }
1009 1009
             } else {
1010 1010
                 // This is a global cart discount
1011
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1012
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1011
+                if (!in_array($item['id'], $excluded_items)) {
1012
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1013 1013
                         $items_subtotal    = 0.00;
1014 1014
                         $cart_items        = wpinv_get_cart_contents();
1015 1015
 
1016
-                        foreach ( $cart_items as $cart_item ) {
1017
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1018
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1019
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1016
+                        foreach ($cart_items as $cart_item) {
1017
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1018
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1019
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1020 1020
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1021 1021
                             }
1022 1022
                         }
1023 1023
 
1024
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1025
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1024
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1025
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1026 1026
                         $discounted_amount = $code_amount * $subtotal_percent;
1027 1027
                         $discounted_price -= $discounted_amount;
1028 1028
 
1029
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1029
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1030 1030
 
1031
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1031
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1032 1032
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1033 1033
                             $discounted_price -= $adjustment;
1034 1034
                         }
1035 1035
                     } else {
1036
-                        $discounted_price -= wpinv_get_discounted_amount( $discount, $price );
1036
+                        $discounted_price -= wpinv_get_discounted_amount($discount, $price);
1037 1037
                     }
1038 1038
                 }
1039 1039
             }
1040 1040
         }
1041 1041
 
1042
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1042
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1043 1043
 
1044
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1044
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1045 1045
             $amount = $amount * $item['quantity'];
1046 1046
         }
1047 1047
     }
@@ -1049,59 +1049,59 @@  discard block
 block discarded – undo
1049 1049
     return $amount;
1050 1050
 }
1051 1051
 
1052
-function wpinv_cart_discounts_html( $items = array() ) {
1053
-    echo wpinv_get_cart_discounts_html( $items );
1052
+function wpinv_cart_discounts_html($items = array()) {
1053
+    echo wpinv_get_cart_discounts_html($items);
1054 1054
 }
1055 1055
 
1056
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1056
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1057 1057
     global $wpi_cart_columns;
1058 1058
 
1059
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1059
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1060 1060
 
1061
-    if ( !$discounts ) {
1062
-        $discounts = wpinv_get_cart_discounts( $items );
1061
+    if (!$discounts) {
1062
+        $discounts = wpinv_get_cart_discounts($items);
1063 1063
     }
1064 1064
 
1065
-    if ( !$discounts ) {
1065
+    if (!$discounts) {
1066 1066
         return;
1067 1067
     }
1068 1068
 
1069
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1069
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1070 1070
 
1071 1071
     $html = '';
1072 1072
 
1073
-    foreach ( $discounts as $discount ) {
1074
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1075
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1076
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1077
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1078
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1073
+    foreach ($discounts as $discount) {
1074
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1075
+        $discount_value = wpinv_get_discount_amount($discount_id);
1076
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1077
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1078
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1079 1079
 
1080 1080
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1081 1081
         ob_start();
1082
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1082
+        do_action('wpinv_checkout_table_discount_first', $items);
1083 1083
         $html .= ob_get_clean();
1084
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1084
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1085 1085
         ob_start();
1086
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1086
+        do_action('wpinv_checkout_table_discount_last', $items);
1087 1087
         $html .= ob_get_clean();
1088 1088
         $html .= '</tr>';
1089 1089
     }
1090 1090
 
1091
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1091
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1092 1092
 }
1093 1093
 
1094
-function wpinv_display_cart_discount( /** @scrutinizer ignore-unused */ $formatted = false, $echo = false ) {
1094
+function wpinv_display_cart_discount(/** @scrutinizer ignore-unused */ $formatted = false, $echo = false) {
1095 1095
     $discounts = wpinv_get_cart_discounts();
1096 1096
 
1097
-    if ( empty( $discounts ) ) {
1097
+    if (empty($discounts)) {
1098 1098
         return false;
1099 1099
     }
1100 1100
 
1101
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1102
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1101
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1102
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1103 1103
 
1104
-    if ( $echo ) {
1104
+    if ($echo) {
1105 1105
         echo $amount;
1106 1106
     }
1107 1107
 
@@ -1109,65 +1109,65 @@  discard block
 block discarded – undo
1109 1109
 }
1110 1110
 
1111 1111
 function wpinv_remove_cart_discount() {
1112
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1112
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1113 1113
         return;
1114 1114
     }
1115 1115
 
1116
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1116
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1117 1117
 
1118
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1118
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1119 1119
 
1120
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1120
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1121 1121
 
1122
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1122
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1123 1123
 }
1124
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1124
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1125 1125
 
1126 1126
 function wpinv_maybe_remove_cart_discount() {
1127 1127
     $discounts = wpinv_get_cart_discounts();
1128 1128
 
1129
-    if ( !$discounts ) {
1129
+    if (!$discounts) {
1130 1130
         return;
1131 1131
     }
1132 1132
 
1133
-    $discounts = array_filter( $discounts );
1134
-    foreach ( $discounts as $discount ) {
1135
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1136
-            wpinv_unset_cart_discount( $discount );
1133
+    $discounts = array_filter($discounts);
1134
+    foreach ($discounts as $discount) {
1135
+        if (!wpinv_is_discount_valid($discount)) {
1136
+            wpinv_unset_cart_discount($discount);
1137 1137
         }
1138 1138
     }
1139 1139
 }
1140
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1140
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1141 1141
 
1142 1142
 function wpinv_multiple_discounts_allowed() {
1143
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1144
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1143
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1144
+    return (bool) apply_filters('wpinv_multiple_discounts_allowed', $ret);
1145 1145
 }
1146 1146
 
1147
-function wpinv_get_discount_label( $code, $echo = true ) {
1148
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1149
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1147
+function wpinv_get_discount_label($code, $echo = true) {
1148
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1149
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1150 1150
 
1151
-    if ( $echo ) {
1151
+    if ($echo) {
1152 1152
         echo $label;
1153 1153
     } else {
1154 1154
         return $label;
1155 1155
     }
1156 1156
 }
1157 1157
 
1158
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1159
-    $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code );
1160
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1158
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1159
+    $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code);
1160
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1161 1161
 
1162
-    if ( $echo ) {
1162
+    if ($echo) {
1163 1163
         echo $label;
1164 1164
     } else {
1165 1165
         return $label;
1166 1166
     }
1167 1167
 }
1168 1168
 
1169
-function wpinv_check_delete_discount( $check, $post ) {
1170
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1169
+function wpinv_check_delete_discount($check, $post) {
1170
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1171 1171
         return true;
1172 1172
     }
1173 1173
 
@@ -1178,33 +1178,33 @@  discard block
 block discarded – undo
1178 1178
     global $wpi_checkout_id;
1179 1179
 
1180 1180
     $discounts = wpinv_get_cart_discounts();
1181
-    $discounts = array_filter( $discounts );
1181
+    $discounts = array_filter($discounts);
1182 1182
 
1183
-    if ( !empty( $discounts ) ) {
1183
+    if (!empty($discounts)) {
1184 1184
         $invalid = false;
1185 1185
 
1186
-        foreach ( $discounts as $key => $code ) {
1187
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1186
+        foreach ($discounts as $key => $code) {
1187
+            if (!wpinv_is_discount_valid($code, (int) wpinv_get_user_id($wpi_checkout_id))) {
1188 1188
                 $invalid = true;
1189 1189
 
1190
-                wpinv_unset_cart_discount( $code );
1190
+                wpinv_unset_cart_discount($code);
1191 1191
             }
1192 1192
         }
1193 1193
 
1194
-        if ( $invalid ) {
1194
+        if ($invalid) {
1195 1195
             $errors = wpinv_get_errors();
1196
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1197
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1198
-            wpinv_set_error( 'wpinv-discount-error', $error );
1196
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1197
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1198
+            wpinv_set_error('wpinv-discount-error', $error);
1199 1199
 
1200
-            wpinv_recalculate_tax( true );
1200
+            wpinv_recalculate_tax(true);
1201 1201
         }
1202 1202
     }
1203 1203
 }
1204
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1204
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1205 1205
 
1206 1206
 function wpinv_discount_amount() {
1207 1207
     $output = 0.00;
1208 1208
 
1209
-    return apply_filters( 'wpinv_discount_amount', $output );
1209
+    return apply_filters('wpinv_discount_amount', $output);
1210 1210
 }
Please login to merge, or discard this patch.
includes/wpinv-tax-functions.php 2 patches
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -70,8 +70,9 @@  discard block
 block discarded – undo
70 70
         if( !empty( $tax_rates ) ) {
71 71
             // Locate the tax rate for this country / state, if it exists
72 72
             foreach( $tax_rates as $key => $tax_rate ) {
73
-                if( $country != $tax_rate['country'] )
74
-                    continue;
73
+                if( $country != $tax_rate['country'] ) {
74
+                                    continue;
75
+                }
75 76
 
76 77
                 if( !empty( $tax_rate['global'] ) ) {
77 78
                     if( !empty( $tax_rate['rate'] ) ) {
@@ -79,8 +80,9 @@  discard block
 block discarded – undo
79 80
                     }
80 81
                 } else {
81 82
 
82
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
83
-                        continue;
83
+                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) ) {
84
+                                            continue;
85
+                    }
84 86
 
85 87
                     $state_rate = $tax_rate['rate'];
86 88
                     if( 0 !== $state_rate || !empty( $state_rate ) ) {
@@ -183,8 +185,9 @@  discard block
 block discarded – undo
183 185
 }
184 186
 
185 187
 function wpinv_cart_needs_tax_address_fields() {
186
-    if( !wpinv_is_cart_taxed() )
187
-        return false;
188
+    if( !wpinv_is_cart_taxed() ) {
189
+            return false;
190
+    }
188 191
 
189 192
     return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
190 193
 }
Please login to merge, or discard this patch.
Spacing   +172 added lines, -172 removed lines patch added patch discarded remove patch
@@ -1,121 +1,121 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7 7
 function wpinv_use_taxes() {
8
-    $ret = wpinv_get_option( 'enable_taxes', false );
8
+    $ret = wpinv_get_option('enable_taxes', false);
9 9
     
10
-    return (bool) apply_filters( 'wpinv_use_taxes', $ret );
10
+    return (bool) apply_filters('wpinv_use_taxes', $ret);
11 11
 }
12 12
 
13 13
 function wpinv_get_tax_rates() {
14
-    $rates = get_option( 'wpinv_tax_rates', array() );
14
+    $rates = get_option('wpinv_tax_rates', array());
15 15
     
16
-    return apply_filters( 'wpinv_get_tax_rates', $rates );
16
+    return apply_filters('wpinv_get_tax_rates', $rates);
17 17
 }
18 18
 
19
-function wpinv_get_tax_rate( $country = false, $state = false, $item_id = 0 ) {
19
+function wpinv_get_tax_rate($country = false, $state = false, $item_id = 0) {
20 20
     global $wpinv_euvat, $wpi_tax_rates, $wpi_userID;
21
-    $wpi_tax_rates = !empty( $wpi_tax_rates ) ? $wpi_tax_rates : array();
21
+    $wpi_tax_rates = !empty($wpi_tax_rates) ? $wpi_tax_rates : array();
22 22
     
23
-    if ( !empty( $wpi_tax_rates ) && !empty( $item_id ) && isset( $wpi_tax_rates[$item_id] ) ) {
23
+    if (!empty($wpi_tax_rates) && !empty($item_id) && isset($wpi_tax_rates[$item_id])) {
24 24
         return $wpi_tax_rates[$item_id];
25 25
     }
26 26
     
27
-    if ( !$wpinv_euvat->item_is_taxable( $item_id, $country, $state ) ) {
27
+    if (!$wpinv_euvat->item_is_taxable($item_id, $country, $state)) {
28 28
         $wpi_tax_rates[$item_id] = 0;
29 29
         return 0;
30 30
     }
31 31
 
32 32
     $is_global = false;
33
-    if ( $item_id == 'global' ) {
33
+    if ($item_id == 'global') {
34 34
         $is_global = true;
35 35
         $item_id = 0;
36 36
     }
37 37
     
38
-    $rate           = (float)wpinv_get_option( 'tax_rate', 0 );
39
-    $user_address   = wpinv_get_user_address( $wpi_userID );
38
+    $rate           = (float) wpinv_get_option('tax_rate', 0);
39
+    $user_address   = wpinv_get_user_address($wpi_userID);
40 40
     
41
-    if( empty( $country ) ) {
42
-        if( !empty( $_POST['wpinv_country'] ) ) {
41
+    if (empty($country)) {
42
+        if (!empty($_POST['wpinv_country'])) {
43 43
             $country = $_POST['wpinv_country'];
44
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
44
+        } elseif (!empty($_POST['wpinv_country'])) {
45 45
             $country = $_POST['wpinv_country'];
46
-        } elseif( !empty( $_POST['country'] ) ) {
46
+        } elseif (!empty($_POST['country'])) {
47 47
             $country = $_POST['country'];
48
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
48
+        } elseif (is_user_logged_in() && !empty($user_address)) {
49 49
             $country = $user_address['country'];
50 50
         }
51
-        $country = !empty( $country ) ? $country : wpinv_get_default_country();
51
+        $country = !empty($country) ? $country : wpinv_get_default_country();
52 52
     }
53 53
 
54
-    if( empty( $state ) ) {
55
-        if( !empty( $_POST['wpinv_state'] ) ) {
54
+    if (empty($state)) {
55
+        if (!empty($_POST['wpinv_state'])) {
56 56
             $state = $_POST['wpinv_state'];
57
-        } elseif( !empty( $_POST['wpinv_state'] ) ) {
57
+        } elseif (!empty($_POST['wpinv_state'])) {
58 58
             $state = $_POST['wpinv_state'];
59
-        } elseif( !empty( $_POST['state'] ) ) {
59
+        } elseif (!empty($_POST['state'])) {
60 60
             $state = $_POST['state'];
61
-        } elseif( is_user_logged_in() && !empty( $user_address ) ) {
61
+        } elseif (is_user_logged_in() && !empty($user_address)) {
62 62
             $state = $user_address['state'];
63 63
         }
64
-        $state = !empty( $state ) ? $state : wpinv_get_default_state();
64
+        $state = !empty($state) ? $state : wpinv_get_default_state();
65 65
     }
66 66
     
67
-    if( !empty( $country ) ) {
68
-        $tax_rates   = wpinv_get_tax_rates();
67
+    if (!empty($country)) {
68
+        $tax_rates = wpinv_get_tax_rates();
69 69
 
70
-        if( !empty( $tax_rates ) ) {
70
+        if (!empty($tax_rates)) {
71 71
             // Locate the tax rate for this country / state, if it exists
72
-            foreach( $tax_rates as $key => $tax_rate ) {
73
-                if( $country != $tax_rate['country'] )
72
+            foreach ($tax_rates as $key => $tax_rate) {
73
+                if ($country != $tax_rate['country'])
74 74
                     continue;
75 75
 
76
-                if( !empty( $tax_rate['global'] ) ) {
77
-                    if( !empty( $tax_rate['rate'] ) ) {
78
-                        $rate = number_format( $tax_rate['rate'], 4 );
76
+                if (!empty($tax_rate['global'])) {
77
+                    if (!empty($tax_rate['rate'])) {
78
+                        $rate = number_format($tax_rate['rate'], 4);
79 79
                     }
80 80
                 } else {
81 81
 
82
-                    if( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
82
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
83 83
                         continue;
84 84
 
85 85
                     $state_rate = $tax_rate['rate'];
86
-                    if( 0 !== $state_rate || !empty( $state_rate ) ) {
87
-                        $rate = number_format( $state_rate, 4 );
86
+                    if (0 !== $state_rate || !empty($state_rate)) {
87
+                        $rate = number_format($state_rate, 4);
88 88
                     }
89 89
                 }
90 90
             }
91 91
         }
92 92
     }
93 93
     
94
-    $rate = apply_filters( 'wpinv_tax_rate', $rate, $country, $state, $item_id );
94
+    $rate = apply_filters('wpinv_tax_rate', $rate, $country, $state, $item_id);
95 95
     
96
-    if ( !empty( $item_id ) ) {
96
+    if (!empty($item_id)) {
97 97
         $wpi_tax_rates[$item_id] = $rate;
98
-    } else if ( $is_global ) {
98
+    } else if ($is_global) {
99 99
         $wpi_tax_rates['global'] = $rate;
100 100
     }
101 101
     
102 102
     return $rate;
103 103
 }
104 104
 
105
-function wpinv_get_formatted_tax_rate( $country = false, $state = false, $item_id ) {
106
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
107
-    $rate = round( $rate, 4 );
105
+function wpinv_get_formatted_tax_rate($country = false, $state = false, $item_id) {
106
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
107
+    $rate = round($rate, 4);
108 108
     $formatted = $rate .= '%';
109
-    return apply_filters( 'wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id );
109
+    return apply_filters('wpinv_formatted_tax_rate', $formatted, $rate, $country, $state, $item_id);
110 110
 }
111 111
 
112
-function wpinv_calculate_tax( $amount = 0, $country = false, $state = false, $item_id = 0 ) {
113
-    $rate = wpinv_get_tax_rate( $country, $state, $item_id );
112
+function wpinv_calculate_tax($amount = 0, $country = false, $state = false, $item_id = 0) {
113
+    $rate = wpinv_get_tax_rate($country, $state, $item_id);
114 114
     $tax  = 0.00;
115 115
 
116
-    if ( wpinv_use_taxes() ) {        
117
-        if ( wpinv_prices_include_tax() ) {
118
-            $pre_tax = ( $amount / ( ( 1 + $rate ) * 0.01 ) );
116
+    if (wpinv_use_taxes()) {        
117
+        if (wpinv_prices_include_tax()) {
118
+            $pre_tax = ($amount / ((1 + $rate) * 0.01));
119 119
             $tax     = $amount - $pre_tax;
120 120
         } else {
121 121
             $tax = $amount * $rate * 0.01;
@@ -123,46 +123,46 @@  discard block
 block discarded – undo
123 123
 
124 124
     }
125 125
 
126
-    return apply_filters( 'wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id );
126
+    return apply_filters('wpinv_taxed_amount', $tax, $rate, $country, $state, $item_id);
127 127
 }
128 128
 
129 129
 function wpinv_prices_include_tax() {
130 130
     return false; // TODO
131
-    $ret = ( wpinv_get_option( 'prices_include_tax', false ) == 'yes' && wpinv_use_taxes() );
131
+    $ret = (wpinv_get_option('prices_include_tax', false) == 'yes' && wpinv_use_taxes());
132 132
 
133
-    return apply_filters( 'wpinv_prices_include_tax', $ret );
133
+    return apply_filters('wpinv_prices_include_tax', $ret);
134 134
 }
135 135
 
136
-function wpinv_sales_tax_for_year( $year = null ) {
137
-    return wpinv_price( wpinv_format_amount( wpinv_get_sales_tax_for_year( $year ) ) );
136
+function wpinv_sales_tax_for_year($year = null) {
137
+    return wpinv_price(wpinv_format_amount(wpinv_get_sales_tax_for_year($year)));
138 138
 }
139 139
 
140
-function wpinv_get_sales_tax_for_year( $year = null ) {
140
+function wpinv_get_sales_tax_for_year($year = null) {
141 141
     global $wpdb;
142 142
 
143 143
     // Start at zero
144 144
     $tax = 0;
145 145
 
146
-    if ( ! empty( $year ) ) {
146
+    if (!empty($year)) {
147 147
         $args = array(
148 148
             'post_type'      => 'wpi_invoice',
149
-            'post_status'    => array( 'publish' ),
149
+            'post_status'    => array('publish'),
150 150
             'posts_per_page' => -1,
151 151
             'year'           => $year,
152 152
             'fields'         => 'ids'
153 153
         );
154 154
 
155
-        $payments    = get_posts( $args );
156
-        $payment_ids = implode( ',', $payments );
155
+        $payments    = get_posts($args);
156
+        $payment_ids = implode(',', $payments);
157 157
 
158
-        if ( count( $payments ) > 0 ) {
158
+        if (count($payments) > 0) {
159 159
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
160
-            $tax = $wpdb->get_var( $sql );
160
+            $tax = $wpdb->get_var($sql);
161 161
         }
162 162
 
163 163
     }
164 164
 
165
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
165
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
166 166
 }
167 167
 
168 168
 function wpinv_is_cart_taxed() {
@@ -171,33 +171,33 @@  discard block
 block discarded – undo
171 171
 
172 172
 function wpinv_prices_show_tax_on_checkout() {
173 173
     return false; // TODO
174
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
174
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
175 175
 
176
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
176
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
177 177
 }
178 178
 
179 179
 function wpinv_display_tax_rate() {
180
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
180
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
181 181
 
182
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
182
+    return apply_filters('wpinv_display_tax_rate', $ret);
183 183
 }
184 184
 
185 185
 function wpinv_cart_needs_tax_address_fields() {
186
-    if( !wpinv_is_cart_taxed() )
186
+    if (!wpinv_is_cart_taxed())
187 187
         return false;
188 188
 
189
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
189
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
190 190
 }
191 191
 
192
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
193
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
194
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
192
+function wpinv_item_is_tax_exclusive($item_id = 0) {
193
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
194
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
195 195
 }
196 196
 
197
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
197
+function wpinv_currency_decimal_filter($decimals = 2) {
198 198
     $currency = wpinv_get_currency();
199 199
 
200
-    switch ( $currency ) {
200
+    switch ($currency) {
201 201
         case 'RIAL' :
202 202
         case 'JPY' :
203 203
         case 'TWD' :
@@ -206,48 +206,48 @@  discard block
 block discarded – undo
206 206
             break;
207 207
     }
208 208
 
209
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
209
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
210 210
 }
211 211
 
212 212
 function wpinv_tax_amount() {
213 213
     $output = 0.00;
214 214
     
215
-    return apply_filters( 'wpinv_tax_amount', $output );
215
+    return apply_filters('wpinv_tax_amount', $output);
216 216
 }
217 217
 
218 218
 function wpinv_recalculated_tax() {
219
-    define( 'WPINV_RECALCTAX', true );
219
+    define('WPINV_RECALCTAX', true);
220 220
 }
221
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1 );
221
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculated_tax', 1);
222 222
 
223
-function wpinv_recalculate_tax( $return = false ) {
224
-    $invoice_id = (int)wpinv_get_invoice_cart_id();
225
-    if ( empty( $invoice_id ) ) {
223
+function wpinv_recalculate_tax($return = false) {
224
+    $invoice_id = (int) wpinv_get_invoice_cart_id();
225
+    if (empty($invoice_id)) {
226 226
         return false;
227 227
     }
228 228
     
229
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
229
+    $invoice = wpinv_get_invoice_cart($invoice_id);
230 230
 
231
-    if ( empty( $invoice ) ) {
231
+    if (empty($invoice)) {
232 232
         return false;
233 233
     }
234 234
 
235
-    if ( empty( $_POST['country'] ) ) {
235
+    if (empty($_POST['country'])) {
236 236
         $_POST['country'] = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
237 237
     }
238 238
         
239 239
     $invoice->country = sanitize_text_field($_POST['country']);
240
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
240
+    $invoice->set('country', sanitize_text_field($_POST['country']));
241 241
     if (isset($_POST['state'])) {
242 242
         $invoice->state = sanitize_text_field($_POST['state']);
243
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
243
+        $invoice->set('state', sanitize_text_field($_POST['state']));
244 244
     }
245 245
 
246 246
     $invoice->cart_details  = wpinv_get_cart_content_details();
247 247
     
248
-    $subtotal               = wpinv_get_cart_subtotal( $invoice->cart_details );
249
-    $tax                    = wpinv_get_cart_tax( $invoice->cart_details );
250
-    $total                  = wpinv_get_cart_total( $invoice->cart_details );
248
+    $subtotal               = wpinv_get_cart_subtotal($invoice->cart_details);
249
+    $tax                    = wpinv_get_cart_tax($invoice->cart_details);
250
+    $total                  = wpinv_get_cart_total($invoice->cart_details);
251 251
 
252 252
     $invoice->tax           = $tax;
253 253
     $invoice->subtotal      = $subtotal;
@@ -255,61 +255,61 @@  discard block
 block discarded – undo
255 255
 
256 256
     $invoice->save();
257 257
     
258
-    if ( $invoice->is_free_trial() ) {
258
+    if ($invoice->is_free_trial()) {
259 259
         $total = 0;
260 260
     }
261 261
     
262 262
     $response = array(
263
-        'total'        => html_entity_decode( wpinv_price( wpinv_format_amount( $total ) ), ENT_COMPAT, 'UTF-8' ),
263
+        'total'        => html_entity_decode(wpinv_price(wpinv_format_amount($total)), ENT_COMPAT, 'UTF-8'),
264 264
         'total_raw'    => $total,
265
-        'free'         => !( (float)$total > 0 ) && $invoice->is_free() ? true : false,
266
-        'html'         => wpinv_checkout_cart( $invoice->cart_details, false ),
265
+        'free'         => !((float) $total > 0) && $invoice->is_free() ? true : false,
266
+        'html'         => wpinv_checkout_cart($invoice->cart_details, false),
267 267
     );
268 268
     
269
-    if ( $return ) {
269
+    if ($return) {
270 270
         return $response;
271 271
     }
272 272
 
273
-    wp_send_json( $response );
273
+    wp_send_json($response);
274 274
 }
275
-add_action( 'wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
276
-add_action( 'wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax' );
275
+add_action('wp_ajax_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
276
+add_action('wp_ajax_nopriv_wpinv_recalculate_tax', 'wpinv_recalculate_tax');
277 277
 
278 278
 // VAT Settings
279
-function wpinv_vat_rate_add_callback( $args ) {
279
+function wpinv_vat_rate_add_callback($args) {
280 280
     ?>
281
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e( 'Add', 'invoicing' );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
281
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_add" type="button" value="<?php esc_attr_e('Add', 'invoicing'); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
282 282
     <?php
283 283
 }
284 284
 
285
-function wpinv_vat_rate_delete_callback( $args ) {
285
+function wpinv_vat_rate_delete_callback($args) {
286 286
     global $wpinv_euvat;
287 287
     
288 288
     $vat_classes = $wpinv_euvat->get_rate_classes();
289
-    $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '';
290
-    if ( isset( $vat_classes[$vat_class] ) ) {
289
+    $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '';
290
+    if (isset($vat_classes[$vat_class])) {
291 291
     ?>
292
-    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf( esc_attr__( 'Delete class "%s"', 'invoicing' ), $vat_classes[$vat_class] );?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
292
+    <p class="wpi-vat-rate-actions"><input id="wpi_vat_rate_delete" type="button" value="<?php echo wp_sprintf(esc_attr__('Delete class "%s"', 'invoicing'), $vat_classes[$vat_class]); ?>" class="button button-primary" />&nbsp;&nbsp;<i style="display:none;" class="fa fa-refresh fa-spin"></i></p>
293 293
     <?php
294 294
     }
295 295
 }
296 296
 
297
-function wpinv_vat_rates_callback( $args ) {
297
+function wpinv_vat_rates_callback($args) {
298 298
     global $wpinv_euvat;
299 299
     
300 300
     $vat_classes    = $wpinv_euvat->get_rate_classes();
301
-    $vat_class      = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_standard';
301
+    $vat_class      = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_standard';
302 302
     
303 303
     $eu_states      = $wpinv_euvat->get_eu_states();
304 304
     $countries      = wpinv_get_country_list();
305 305
     $vat_groups     = $wpinv_euvat->get_vat_groups();
306
-    $rates          = $wpinv_euvat->get_vat_rates( $vat_class );
306
+    $rates          = $wpinv_euvat->get_vat_rates($vat_class);
307 307
     ob_start();
308 308
 ?>
309 309
 </td><tr>
310 310
     <td colspan="2" class="wpinv_vat_tdbox">
311
-    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class;?>" />
312
-    <p><?php echo ( isset( $args['desc'] ) ? $args['desc'] : '' ); ?></p>
311
+    <input type="hidden" name="wpi_vat_class" value="<?php echo $vat_class; ?>" />
312
+    <p><?php echo (isset($args['desc']) ? $args['desc'] : ''); ?></p>
313 313
     <table id="wpinv_vat_rates" class="wp-list-table widefat fixed posts">
314 314
         <colgroup>
315 315
             <col width="50px" />
@@ -321,43 +321,43 @@  discard block
 block discarded – undo
321 321
         </colgroup>
322 322
         <thead>
323 323
             <tr>
324
-                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e( 'Country', 'invoicing' ); ?></th>
325
-                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e( 'Apply rate to whole country', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
326
-                <th scope="col" class="wpinv_vat_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
327
-                <th scope="col" class="wpinv_vat_name"><?php _e( 'VAT Name', 'invoicing' ); ?></th>
328
-                <th scope="col" class="wpinv_vat_group"><?php _e( 'Tax Group', 'invoicing' ); ?></th>
324
+                <th scope="col" colspan="2" class="wpinv_vat_country_name"><?php _e('Country', 'invoicing'); ?></th>
325
+                <th scope="col" class="wpinv_vat_global" title="<?php esc_attr_e('Apply rate to whole country', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
326
+                <th scope="col" class="wpinv_vat_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
327
+                <th scope="col" class="wpinv_vat_name"><?php _e('VAT Name', 'invoicing'); ?></th>
328
+                <th scope="col" class="wpinv_vat_group"><?php _e('Tax Group', 'invoicing'); ?></th>
329 329
             </tr>
330 330
         </thead>
331 331
         <tbody>
332
-        <?php if( !empty( $eu_states ) ) { ?>
332
+        <?php if (!empty($eu_states)) { ?>
333 333
         <?php 
334
-        foreach ( $eu_states as $state ) { 
335
-            $country_name = isset( $countries[$state] ) ? $countries[$state] : '';
334
+        foreach ($eu_states as $state) { 
335
+            $country_name = isset($countries[$state]) ? $countries[$state] : '';
336 336
             
337 337
             // Filter the rate for each country
338
-            $country_rate = array_filter( $rates, function( $rate ) use( $state ) { return $rate['country'] === $state; } );
338
+            $country_rate = array_filter($rates, function($rate) use($state) { return $rate['country'] === $state; } );
339 339
             
340 340
             // If one does not exist create a default
341
-            $country_rate = is_array( $country_rate ) && count( $country_rate ) > 0 ? reset( $country_rate ) : array();
341
+            $country_rate = is_array($country_rate) && count($country_rate) > 0 ? reset($country_rate) : array();
342 342
             
343
-            $vat_global = isset( $country_rate['global'] ) ? !empty( $country_rate['global'] ) : true;
344
-            $vat_rate = isset( $country_rate['rate'] ) ? $country_rate['rate'] : '';
345
-            $vat_name = !empty( $country_rate['name'] ) ? esc_attr( stripslashes( $country_rate['name'] ) ) : '';
346
-            $vat_group = !empty( $country_rate['group'] ) ? $country_rate['group'] : ( $vat_class === '_standard' ? 'standard' : 'reduced' );
343
+            $vat_global = isset($country_rate['global']) ? !empty($country_rate['global']) : true;
344
+            $vat_rate = isset($country_rate['rate']) ? $country_rate['rate'] : '';
345
+            $vat_name = !empty($country_rate['name']) ? esc_attr(stripslashes($country_rate['name'])) : '';
346
+            $vat_group = !empty($country_rate['group']) ? $country_rate['group'] : ($vat_class === '_standard' ? 'standard' : 'reduced');
347 347
         ?>
348 348
         <tr>
349 349
             <td class="wpinv_vat_country"><?php echo $state; ?><input type="hidden" name="vat_rates[<?php echo $state; ?>][country]" value="<?php echo $state; ?>" /><input type="hidden" name="vat_rates[<?php echo $state; ?>][state]" value="" /></td>
350 350
             <td class="wpinv_vat_country_name"><?php echo $country_name; ?></td>
351 351
             <td class="wpinv_vat_global">
352
-                <input type="checkbox" name="vat_rates[<?php echo $state;?>][global]" id="vat_rates[<?php echo $state;?>][global]" value="1" <?php checked( true, $vat_global );?> disabled="disabled" />
353
-                <label for="tax_rates[<?php echo $state;?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
354
-                <input type="hidden" name="vat_rates[<?php echo $state;?>][global]" value="1" checked="checked" />
352
+                <input type="checkbox" name="vat_rates[<?php echo $state; ?>][global]" id="vat_rates[<?php echo $state; ?>][global]" value="1" <?php checked(true, $vat_global); ?> disabled="disabled" />
353
+                <label for="tax_rates[<?php echo $state; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
354
+                <input type="hidden" name="vat_rates[<?php echo $state; ?>][global]" value="1" checked="checked" />
355 355
             </td>
356
-            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state;?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
-            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state;?>][name]" value="<?php echo $vat_name; ?>" /></td>
356
+            <td class="wpinv_vat_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="vat_rates[<?php echo $state; ?>][rate]" value="<?php echo $vat_rate; ?>" /></td>
357
+            <td class="wpinv_vat_name"><input type="text" class="regular-text" name="vat_rates[<?php echo $state; ?>][name]" value="<?php echo $vat_name; ?>" /></td>
358 358
             <td class="wpinv_vat_group">
359 359
             <?php
360
-            echo wpinv_html_select( array(
360
+            echo wpinv_html_select(array(
361 361
                                         'name'             => 'vat_rates[' . $state . '][group]',
362 362
                                         'selected'         => $vat_group,
363 363
                                         'id'               => 'vat_rates[' . $state . '][group]',
@@ -366,14 +366,14 @@  discard block
 block discarded – undo
366 366
                                         'multiple'         => false,
367 367
                                         'show_option_all'  => false,
368 368
                                         'show_option_none' => false
369
-                                    ) );
369
+                                    ));
370 370
             ?>
371 371
             </td>
372 372
         </tr>
373 373
         <?php } ?>
374 374
         <tr>
375 375
             <td colspan="6" style="background-color:#fafafa;">
376
-                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e( 'Update EU VAT Rates', 'invoicing' ); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
376
+                <span><input id="wpi_vat_get_rates_group" type="button" class="button-secondary" value="<?php esc_attr_e('Update EU VAT Rates', 'invoicing'); ?>" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span><span id="wpinv-rates-error-wrap" class="wpinv_errors" style="display:none;"></span>
377 377
             </td>
378 378
         </tr>
379 379
         <?php } ?>
@@ -385,35 +385,35 @@  discard block
 block discarded – undo
385 385
     echo $content;
386 386
 }
387 387
 
388
-function wpinv_vat_number_callback( $args ) {
388
+function wpinv_vat_number_callback($args) {
389 389
     global $wpinv_euvat;
390 390
     
391 391
     $vat_number     = $wpinv_euvat->get_vat_number();
392 392
     $vat_valid      = $wpinv_euvat->is_vat_validated();
393 393
 
394
-    $size           = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'regular';
395
-    $validated_text = $vat_valid ? __( 'VAT number validated', 'invoicing' ) : __( 'VAT number not validated', 'invoicing' );
394
+    $size           = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
395
+    $validated_text = $vat_valid ? __('VAT number validated', 'invoicing') : __('VAT number not validated', 'invoicing');
396 396
     $disabled       = $vat_valid ? 'disabled="disabled"' : " ";
397 397
     
398
-    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr( stripslashes( $vat_number ) ) . '"/>';
399
-    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__( 'Validate VAT Number', 'invoicing' ) . '" /></span>';
400
-    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int)$vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
-    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __( 'Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing' ).'</p>' . '</label>';
402
-    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce( 'vat_validation' ) . '">';
398
+    $html = '<input type="text" class="' . $size . '-text" id="wpinv_settings[' . $args['id'] . ']" name="wpinv_settings[' . $args['id'] . ']" placeholder="GB123456789" value="' . esc_attr(stripslashes($vat_number)) . '"/>';
399
+    $html .= '<span>&nbsp;<input type="button" id="wpinv_vat_validate" class="wpinv_validate_vat_button button-secondary" ' . $disabled . ' value="' . esc_attr__('Validate VAT Number', 'invoicing') . '" /></span>';
400
+    $html .= '<span class="wpinv-vat-stat wpinv-vat-stat-' . (int) $vat_valid . '"><i class="fa"></i> <font>' . $validated_text . '</font></span>';
401
+    $html .= '<label for="wpinv_settings[' . $args['id'] . ']">' . '<p>' . __('Enter your VAT number including country identifier, eg: GB123456789 (Settings must be saved after validation)', 'invoicing') . '</p>' . '</label>';
402
+    $html .= '<input type="hidden" name="_wpi_nonce" value="' . wp_create_nonce('vat_validation') . '">';
403 403
 
404 404
     echo $html;
405 405
 }
406 406
 
407
-function wpinv_eu_fallback_rate_callback( $args ) {
407
+function wpinv_eu_fallback_rate_callback($args) {
408 408
     global $wpinv_options;
409 409
 
410
-    $value = isset( $wpinv_options[$args['id']] ) ? $wpinv_options[ $args['id'] ] : ( isset( $args['std'] ) ? $args['std'] : '' );
411
-    $size = ( isset( $args['size'] ) && !is_null( $args['size'] ) ) ? $args['size'] : 'small';
410
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : '');
411
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'small';
412 412
     
413
-    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr( stripslashes( $value ) ) . '" />';
414
-    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Add EU Member States', 'invoicing' ) . '" /></span>';
415
-    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__( 'Remove EU Member States', 'invoicing' ) . '" /></span>';
416
-    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__( 'Update EU VAT Rates', 'invoicing' ) . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
413
+    $html = '<input type="number" min="0" max="99" step="any" class="' . $size . '-text" id="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '" name="wpinv_settings[' . $args['id'] . ']" value="' . esc_attr(stripslashes($value)) . '" />';
414
+    $html .= '<span>&nbsp;<input id="wpi_add_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Add EU Member States', 'invoicing') . '" /></span>';
415
+    $html .= '<span>&nbsp;<input id="wpi_remove_eu_states" type="button" class="button-secondary" value="' . esc_attr__('Remove EU Member States', 'invoicing') . '" /></span>';
416
+    $html .= '<span>&nbsp;<input id="wpi_vat_get_rates" type="button" class="button-secondary" value="' . esc_attr__('Update EU VAT Rates', 'invoicing') . '" />&nbsp;&nbsp;<i style="display:none" class="fa fa-refresh fa-spin"></i></span>';
417 417
     $html .= '<p><label for="wpinv_settings_' . $args['section'] . '_' . $args['id'] . '">' . $args['desc'] . '</label></p>';
418 418
     echo $html;
419 419
     ?>
@@ -421,36 +421,36 @@  discard block
 block discarded – undo
421 421
     <?php
422 422
 }
423 423
 
424
-function wpinv_vat_ip_lookup_callback( $args ) {
424
+function wpinv_vat_ip_lookup_callback($args) {
425 425
     global $wpinv_options, $wpinv_euvat;
426 426
 
427
-    $value =  isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ]  : ( isset( $args['std'] ) ? $args['std'] : 'default' );
427
+    $value = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : (isset($args['std']) ? $args['std'] : 'default');
428 428
     
429 429
     $options = array();
430
-    if ( function_exists( 'geoip_country_code_by_name' ) ) {
431
-        $options['geoip'] = __( 'PHP GeoIP extension', 'invoicing' );
430
+    if (function_exists('geoip_country_code_by_name')) {
431
+        $options['geoip'] = __('PHP GeoIP extension', 'invoicing');
432 432
     }
433 433
     
434 434
     $geoip2_database = $wpinv_euvat->geoip2_country_dbfile();
435 435
     
436
-    if ( !function_exists( 'bcadd' ) ) {
437
-        $geoip2_message = __( 'GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing' );
436
+    if (!function_exists('bcadd')) {
437
+        $geoip2_message = __('GeoIP2 service requires the BC Math PHP extension, it is not loaded in your version of PHP!', 'invoicing');
438 438
     } else {
439
-        $geoip2_message = ini_get('safe_mode') ? __( 'GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing' ) : '';
439
+        $geoip2_message = ini_get('safe_mode') ? __('GeoIP2 is not supported with PHP safe mode enabled!', 'invoicing') : '';
440 440
     }
441 441
     
442
-    if ( $geoip2_database !== false && empty( $geoip2_message ) ) {
443
-        $options['geoip2'] = __( 'GeoIP2 Database', 'invoicing' );
442
+    if ($geoip2_database !== false && empty($geoip2_message)) {
443
+        $options['geoip2'] = __('GeoIP2 Database', 'invoicing');
444 444
     }
445 445
     
446
-    if ( function_exists( 'simplexml_load_file' ) ) {
447
-        $options['geoplugin'] = __( 'geoPlugin Web Service', 'invoicing' );
446
+    if (function_exists('simplexml_load_file')) {
447
+        $options['geoplugin'] = __('geoPlugin Web Service', 'invoicing');
448 448
     }
449 449
     
450
-    $options['site']    = __( 'Use default country', 'invoicing' );
451
-    $options['default'] = __( 'Auto', 'invoicing' );
450
+    $options['site']    = __('Use default country', 'invoicing');
451
+    $options['default'] = __('Auto', 'invoicing');
452 452
 
453
-    $html = wpinv_html_select( array(
453
+    $html = wpinv_html_select(array(
454 454
         'name'             => "wpinv_settings[{$args['id']}]",
455 455
         'selected'         => $value,
456 456
         'id'               => "wpinv_settings[{$args['id']}]",
@@ -462,23 +462,23 @@  discard block
 block discarded – undo
462 462
     ));
463 463
     
464 464
     $desc = '<label for="wpinv_settings[' . $args['id'] . ']">';
465
-    $desc .= __( 'Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing' );
465
+    $desc .= __('Select the option Invoicing should use to determine the country from the IP address of the user.', 'invoicing');
466 466
     $desc .= '<p>';
467
-    if ( empty( $geoip2_message ) ) {
468
-        if ( $geoip2_database ) {
467
+    if (empty($geoip2_message)) {
468
+        if ($geoip2_database) {
469 469
             $last_updated = '';
470
-            if ( $time_updated = wpinv_get_option( 'wpinv_geoip2_date_updated' ) ) {
471
-                $date_updated = date_i18n( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ), $time_updated );
472
-                $last_updated = '<br>' . sprintf( __( 'The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing' ), $date_updated );
470
+            if ($time_updated = wpinv_get_option('wpinv_geoip2_date_updated')) {
471
+                $date_updated = date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $time_updated);
472
+                $last_updated = '<br>' . sprintf(__('The GeoIP2 database was last updated on: <b>%s</b>', 'invoicing'), $date_updated);
473 473
             }
474
-            $desc .= __(  'GeoIP2 database exists:', 'invoicing' ) . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __( 'Update GeoIP2 database now (~30MB)', 'invoicing' ) . '"></input>';
474
+            $desc .= __('GeoIP2 database exists:', 'invoicing') . $last_updated . '&nbsp;<input type="button" id="wpi_geoip2" action="update" class="wpinv-refresh-geoip2-btn button-secondary" value="' . __('Update GeoIP2 database now (~30MB)', 'invoicing') . '"></input>';
475 475
         } else {
476
-            $desc .= __( 'GeoIP2 database does not exist:', 'invoicing' ) . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __( 'Download GeoIP2 database now', 'invoicing' ) . ' (~30MB)"></input><br>' . __(  'After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing' );
476
+            $desc .= __('GeoIP2 database does not exist:', 'invoicing') . '&nbsp;<input type="button" id="wpi_geoip2" action="download" class="wpinv-download-geoip2-btn button-secondary" value="' . __('Download GeoIP2 database now', 'invoicing') . ' (~30MB)"></input><br>' . __('After downloading the GeoIP2 database the GeoIP2 lookup option will show.', 'invoicing');
477 477
         }
478 478
     } else {
479 479
         $desc .= $geoip2_message;
480 480
     }
481
-    $desc .= '</p><p>'. __( 'geoPlugin is a great free service please consider supporting them: ', 'invoicing' ) . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
481
+    $desc .= '</p><p>' . __('geoPlugin is a great free service please consider supporting them: ', 'invoicing') . ' <a href="http://www.geoplugin.com/" target="_blank">GeoPlugin.com</a></p>';
482 482
     $desc .= '</label>';
483 483
     
484 484
     $html .= $desc;
@@ -494,23 +494,23 @@  discard block
 block discarded – undo
494 494
  * 
495 495
  * @param string|bool|null $vat_rule
496 496
  */
497
-function getpaid_filter_vat_rule( $vat_rule ) {
497
+function getpaid_filter_vat_rule($vat_rule) {
498 498
     global $wpinv_euvat;
499 499
 
500
-    if ( empty( $vat_rule ) ) {        
500
+    if (empty($vat_rule)) {        
501 501
         return $wpinv_euvat->allow_vat_rules() ? 'digital' : 'physical';
502 502
     }
503 503
 
504 504
     return $vat_rule;
505 505
 }
506
-add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' );
506
+add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule');
507 507
 
508 508
 /**
509 509
  * Filters the VAT class to ensure that each item has a VAT class.
510 510
  * 
511 511
  * @param string|bool|null $vat_rule
512 512
  */
513
-function getpaid_filter_vat_class( $vat_class ) {
514
-    return empty( $vat_class ) ? '_standard' : $vat_class;
513
+function getpaid_filter_vat_class($vat_class) {
514
+    return empty($vat_class) ? '_standard' : $vat_class;
515 515
 }
516
-add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' );
517 516
\ No newline at end of file
517
+add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class');
518 518
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-post-types.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -140,8 +140,8 @@  discard block
 block discarded – undo
140 140
 
141 141
 function wpinv_get_default_labels() {
142 142
     $defaults = array(
143
-       'singular' => __( 'Invoice', 'invoicing' ),
144
-       'plural'   => __( 'Invoices', 'invoicing' )
143
+        'singular' => __( 'Invoice', 'invoicing' ),
144
+        'plural'   => __( 'Invoices', 'invoicing' )
145 145
     );
146 146
     
147 147
     return apply_filters( 'wpinv_default_invoices_name', $defaults );
@@ -160,20 +160,20 @@  discard block
 block discarded – undo
160 160
 }
161 161
 
162 162
 function wpinv_change_default_title( $title ) {
163
-     if ( !is_admin() ) {
163
+        if ( !is_admin() ) {
164 164
         $label = wpinv_get_label_singular();
165 165
         $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
166 166
         return $title;
167
-     }
167
+        }
168 168
 
169
-     $screen = get_current_screen();
169
+        $screen = get_current_screen();
170 170
 
171
-     if ( 'wpi_invoice' == $screen->post_type ) {
171
+        if ( 'wpi_invoice' == $screen->post_type ) {
172 172
         $label = wpinv_get_label_singular();
173 173
         $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
174
-     }
174
+        }
175 175
 
176
-     return $title;
176
+        return $title;
177 177
 }
178 178
 add_filter( 'enter_title_here', 'wpinv_change_default_title' );
179 179
 
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 removed lines patch added patch discarded remove patch
@@ -7,41 +7,41 @@  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
-add_action( 'init', 'wpinv_register_post_types', 1 );
14
+add_action('init', 'wpinv_register_post_types', 1);
15 15
 function wpinv_register_post_types() {
16 16
 
17 17
     $items_labels = array(
18
-        'name'               => _x( 'Items', 'post type general name', 'invoicing' ),
19
-        'singular_name'      => _x( 'Item', 'post type singular name', 'invoicing' ),
20
-        'menu_name'          => _x( 'Items', 'admin menu', 'invoicing' ),
21
-        'add_new'            => _x( 'Add New', 'wpi_item', 'invoicing' ),
22
-        'add_new_item'       => __( 'Add New Item', 'invoicing' ),
23
-        'new_item'           => __( 'New Item', 'invoicing' ),
24
-        'edit_item'          => __( 'Edit Item', 'invoicing' ),
25
-        'view_item'          => __( 'View Item', 'invoicing' ),
26
-        'all_items'          => __( 'Items', 'invoicing' ),
27
-        'search_items'       => __( 'Search Items', 'invoicing' ),
18
+        'name'               => _x('Items', 'post type general name', 'invoicing'),
19
+        'singular_name'      => _x('Item', 'post type singular name', 'invoicing'),
20
+        'menu_name'          => _x('Items', 'admin menu', 'invoicing'),
21
+        'add_new'            => _x('Add New', 'wpi_item', 'invoicing'),
22
+        'add_new_item'       => __('Add New Item', 'invoicing'),
23
+        'new_item'           => __('New Item', 'invoicing'),
24
+        'edit_item'          => __('Edit Item', 'invoicing'),
25
+        'view_item'          => __('View Item', 'invoicing'),
26
+        'all_items'          => __('Items', 'invoicing'),
27
+        'search_items'       => __('Search Items', 'invoicing'),
28 28
         'parent_item_colon'  => '',
29
-        'not_found'          => __( 'No items found.', 'invoicing' ),
30
-        'not_found_in_trash' => __( 'No items found in trash.', 'invoicing' )
29
+        'not_found'          => __('No items found.', 'invoicing'),
30
+        'not_found_in_trash' => __('No items found in trash.', 'invoicing')
31 31
     );
32
-    $items_labels = apply_filters( 'wpinv_items_labels', $items_labels );
32
+    $items_labels = apply_filters('wpinv_items_labels', $items_labels);
33 33
 
34 34
     $cap_type          = 'wpi_item';
35 35
     $invoice_item_args = array(
36 36
         'labels'                => $items_labels,
37
-        'description'           => __( 'This is where you can add new invoice items.', 'invoicing' ),
37
+        'description'           => __('This is where you can add new invoice items.', 'invoicing'),
38 38
         'public'                => false,
39 39
         'has_archive'           => false,
40 40
         '_builtin'              => false,
41 41
         'show_ui'               => true,
42 42
         'show_in_menu'          => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : false,
43 43
         'show_in_nav_menus'     => false,
44
-        'supports'              => array( 'title', 'excerpt' ),
44
+        'supports'              => array('title', 'excerpt'),
45 45
         'register_meta_box_cb'  => 'wpinv_register_item_meta_boxes',
46 46
         'rewrite'               => false,
47 47
         'query_var'             => false,
@@ -68,9 +68,9 @@  discard block
 block discarded – undo
68 68
         ),
69 69
         'can_export'            => true,
70 70
     );
71
-    $invoice_item_args = apply_filters( 'wpinv_register_post_type_invoice_item', $invoice_item_args );
71
+    $invoice_item_args = apply_filters('wpinv_register_post_type_invoice_item', $invoice_item_args);
72 72
 
73
-    register_post_type( 'wpi_item', $invoice_item_args );
73
+    register_post_type('wpi_item', $invoice_item_args);
74 74
 
75 75
     $cap_type = 'wpi_payment_form';
76 76
     register_post_type(
@@ -79,22 +79,22 @@  discard block
 block discarded – undo
79 79
             'wpinv_register_post_type_payment_form',
80 80
             array(
81 81
                 'labels'             => array(
82
-                    'name'               => _x( 'Payment Forms', 'post type general name', 'invoicing' ),
83
-                    'singular_name'      => _x( 'Payment Form', 'post type singular name', 'invoicing' ),
84
-                    'menu_name'          => _x( 'Payment Forms', 'admin menu', 'invoicing' ),
85
-                    'name_admin_bar'     => _x( 'Payment Form', 'add new on admin bar', 'invoicing' ),
86
-                    'add_new'            => _x( 'Add New', 'Payment Form', 'invoicing' ),
87
-                    'add_new_item'       => __( 'Add New Payment Form', 'invoicing' ),
88
-                    'new_item'           => __( 'New Payment Form', 'invoicing' ),
89
-                    'edit_item'          => __( 'Edit Payment Form', 'invoicing' ),
90
-                    'view_item'          => __( 'View Payment Form', 'invoicing' ),
91
-                    'all_items'          => __( 'Payment Forms', 'invoicing' ),
92
-                    'search_items'       => __( 'Search Payment Forms', 'invoicing' ),
93
-                    'parent_item_colon'  => __( 'Parent Payment Forms:', 'invoicing' ),
94
-                    'not_found'          => __( 'No payment forms found.', 'invoicing' ),
95
-                    'not_found_in_trash' => __( 'No payment forms found in trash.', 'invoicing' )
82
+                    'name'               => _x('Payment Forms', 'post type general name', 'invoicing'),
83
+                    'singular_name'      => _x('Payment Form', 'post type singular name', 'invoicing'),
84
+                    'menu_name'          => _x('Payment Forms', 'admin menu', 'invoicing'),
85
+                    'name_admin_bar'     => _x('Payment Form', 'add new on admin bar', 'invoicing'),
86
+                    'add_new'            => _x('Add New', 'Payment Form', 'invoicing'),
87
+                    'add_new_item'       => __('Add New Payment Form', 'invoicing'),
88
+                    'new_item'           => __('New Payment Form', 'invoicing'),
89
+                    'edit_item'          => __('Edit Payment Form', 'invoicing'),
90
+                    'view_item'          => __('View Payment Form', 'invoicing'),
91
+                    'all_items'          => __('Payment Forms', 'invoicing'),
92
+                    'search_items'       => __('Search Payment Forms', 'invoicing'),
93
+                    'parent_item_colon'  => __('Parent Payment Forms:', 'invoicing'),
94
+                    'not_found'          => __('No payment forms found.', 'invoicing'),
95
+                    'not_found_in_trash' => __('No payment forms found in trash.', 'invoicing')
96 96
                 ),
97
-                'description'        => __( 'Stores payment forms.', 'invoicing' ),
97
+                'description'        => __('Stores payment forms.', 'invoicing'),
98 98
                 'public'             => false,
99 99
                 'show_ui'            => true,
100 100
                 'show_in_menu'       => wpinv_current_user_can_manage_invoicing() ? 'wpinv' : true,
@@ -105,37 +105,37 @@  discard block
 block discarded – undo
105 105
                 'has_archive'        => false,
106 106
                 'hierarchical'       => false,
107 107
                 'menu_position'      => null,
108
-                'supports'           => array( 'title' ),
108
+                'supports'           => array('title'),
109 109
                 'menu_icon'          => 'dashicons-media-form',
110 110
             )
111 111
         )
112 112
     );
113 113
 
114 114
     $labels = array(
115
-        'name'               => _x( 'Invoices', 'post type general name', 'invoicing' ),
116
-        'singular_name'      => _x( 'Invoice', 'post type singular name', 'invoicing' ),
117
-        'menu_name'          => _x( 'Invoices', 'admin menu', 'invoicing' ),
118
-        'name_admin_bar'     => _x( 'Invoice', 'add new on admin bar', 'invoicing' ),
119
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
120
-        'add_new_item'       => __( 'Add New Invoice', 'invoicing' ),
121
-        'new_item'           => __( 'New Invoice', 'invoicing' ),
122
-        'edit_item'          => __( 'Edit Invoice', 'invoicing' ),
123
-        'view_item'          => __( 'View Invoice', 'invoicing' ),
124
-        'all_items'          => __( 'Invoices', 'invoicing' ),
125
-        'search_items'       => __( 'Search Invoices', 'invoicing' ),
126
-        'parent_item_colon'  => __( 'Parent Invoices:', 'invoicing' ),
127
-        'not_found'          => __( 'No invoices found.', 'invoicing' ),
128
-        'not_found_in_trash' => __( 'No invoices found in trash.', 'invoicing' )
115
+        'name'               => _x('Invoices', 'post type general name', 'invoicing'),
116
+        'singular_name'      => _x('Invoice', 'post type singular name', 'invoicing'),
117
+        'menu_name'          => _x('Invoices', 'admin menu', 'invoicing'),
118
+        'name_admin_bar'     => _x('Invoice', 'add new on admin bar', 'invoicing'),
119
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
120
+        'add_new_item'       => __('Add New Invoice', 'invoicing'),
121
+        'new_item'           => __('New Invoice', 'invoicing'),
122
+        'edit_item'          => __('Edit Invoice', 'invoicing'),
123
+        'view_item'          => __('View Invoice', 'invoicing'),
124
+        'all_items'          => __('Invoices', 'invoicing'),
125
+        'search_items'       => __('Search Invoices', 'invoicing'),
126
+        'parent_item_colon'  => __('Parent Invoices:', 'invoicing'),
127
+        'not_found'          => __('No invoices found.', 'invoicing'),
128
+        'not_found_in_trash' => __('No invoices found in trash.', 'invoicing')
129 129
     );
130
-    $labels = apply_filters( 'wpinv_labels', $labels );
130
+    $labels = apply_filters('wpinv_labels', $labels);
131 131
     
132 132
     $menu_icon = WPINV_PLUGIN_URL . '/assets/images/favicon.ico';
133
-    $menu_icon = apply_filters( 'wpinv_menu_icon_invoice', $menu_icon );
133
+    $menu_icon = apply_filters('wpinv_menu_icon_invoice', $menu_icon);
134 134
 
135 135
     $cap_type = 'wpi_invoice';
136 136
     $args = array(
137 137
         'labels'             => $labels,
138
-        'description'        => __( 'This is where invoices are stored.', 'invoicing' ),
138
+        'description'        => __('This is where invoices are stored.', 'invoicing'),
139 139
         'public'             => true,
140 140
         'can_export'         => true,
141 141
         '_builtin'           => false,
@@ -168,37 +168,37 @@  discard block
 block discarded – undo
168 168
         'has_archive'        => false,
169 169
         'hierarchical'       => false,
170 170
         'menu_position'      => null,
171
-        'supports'           => array( 'title', 'author', 'excerpt'  ),
171
+        'supports'           => array('title', 'author', 'excerpt'),
172 172
         'menu_icon'          => 'dashicons-media-spreadsheet',
173 173
     );
174 174
             
175
-    $args = apply_filters( 'wpinv_register_post_type_invoice', $args );
175
+    $args = apply_filters('wpinv_register_post_type_invoice', $args);
176 176
     
177
-    register_post_type( 'wpi_invoice', $args );
177
+    register_post_type('wpi_invoice', $args);
178 178
 
179 179
     $labels = array(
180
-        'name'               => _x( 'Discounts', 'post type general name', 'invoicing' ),
181
-        'singular_name'      => _x( 'Discount', 'post type singular name', 'invoicing' ),
182
-        'menu_name'          => _x( 'Discounts', 'admin menu', 'invoicing' ),
183
-        'name_admin_bar'     => _x( 'Discount', 'add new on admin bar', 'invoicing' ),
184
-        'add_new'            => _x( 'Add New', 'book', 'invoicing' ),
185
-        'add_new_item'       => __( 'Add New Discount', 'invoicing' ),
186
-        'new_item'           => __( 'New Discount', 'invoicing' ),
187
-        'edit_item'          => __( 'Edit Discount', 'invoicing' ),
188
-        'view_item'          => __( 'View Discount', 'invoicing' ),
189
-        'all_items'          => __( 'Discounts', 'invoicing' ),
190
-        'search_items'       => __( 'Search Discounts', 'invoicing' ),
191
-        'parent_item_colon'  => __( 'Parent Discounts:', 'invoicing' ),
192
-        'not_found'          => __( 'No discounts found.', 'invoicing' ),
193
-        'not_found_in_trash' => __( 'No discounts found in trash.', 'invoicing' )
180
+        'name'               => _x('Discounts', 'post type general name', 'invoicing'),
181
+        'singular_name'      => _x('Discount', 'post type singular name', 'invoicing'),
182
+        'menu_name'          => _x('Discounts', 'admin menu', 'invoicing'),
183
+        'name_admin_bar'     => _x('Discount', 'add new on admin bar', 'invoicing'),
184
+        'add_new'            => _x('Add New', 'book', 'invoicing'),
185
+        'add_new_item'       => __('Add New Discount', 'invoicing'),
186
+        'new_item'           => __('New Discount', 'invoicing'),
187
+        'edit_item'          => __('Edit Discount', 'invoicing'),
188
+        'view_item'          => __('View Discount', 'invoicing'),
189
+        'all_items'          => __('Discounts', 'invoicing'),
190
+        'search_items'       => __('Search Discounts', 'invoicing'),
191
+        'parent_item_colon'  => __('Parent Discounts:', 'invoicing'),
192
+        'not_found'          => __('No discounts found.', 'invoicing'),
193
+        'not_found_in_trash' => __('No discounts found in trash.', 'invoicing')
194 194
     );
195
-    $labels = apply_filters( 'wpinv_discounts_labels', $labels );
195
+    $labels = apply_filters('wpinv_discounts_labels', $labels);
196 196
 
197 197
     $cap_type = 'wpi_discount';
198 198
     
199 199
     $args = array(
200 200
         'labels'             => $labels,
201
-        'description'        => __( 'This is where you can add new discounts that users can use in invoices.', 'invoicing' ),
201
+        'description'        => __('This is where you can add new discounts that users can use in invoices.', 'invoicing'),
202 202
         'public'             => false,
203 203
         'can_export'         => true,
204 204
         '_builtin'           => false,
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         ),
230 230
         'has_archive'        => false,
231 231
         'hierarchical'       => false,
232
-        'supports'           => array( 'title', 'excerpt' ),
232
+        'supports'           => array('title', 'excerpt'),
233 233
         'register_meta_box_cb'  => 'wpinv_register_discount_meta_boxes',
234 234
         'show_in_nav_menus'  => false,
235 235
         'show_in_admin_bar'  => true,
@@ -237,106 +237,106 @@  discard block
 block discarded – undo
237 237
         'menu_position'      => null,
238 238
     );
239 239
             
240
-    $args = apply_filters( 'wpinv_register_post_type_discount', $args );
240
+    $args = apply_filters('wpinv_register_post_type_discount', $args);
241 241
     
242
-    register_post_type( 'wpi_discount', $args );
242
+    register_post_type('wpi_discount', $args);
243 243
 }
244 244
 
245 245
 function wpinv_get_default_labels() {
246 246
     $defaults = array(
247
-       'singular' => __( 'Invoice', 'invoicing' ),
248
-       'plural'   => __( 'Invoices', 'invoicing' )
247
+       'singular' => __('Invoice', 'invoicing'),
248
+       'plural'   => __('Invoices', 'invoicing')
249 249
     );
250 250
     
251
-    return apply_filters( 'wpinv_default_invoices_name', $defaults );
251
+    return apply_filters('wpinv_default_invoices_name', $defaults);
252 252
 }
253 253
 
254
-function wpinv_get_label_singular( $lowercase = false ) {
254
+function wpinv_get_label_singular($lowercase = false) {
255 255
     $defaults = wpinv_get_default_labels();
256 256
     
257
-    return ($lowercase) ? strtolower( $defaults['singular'] ) : $defaults['singular'];
257
+    return ($lowercase) ? strtolower($defaults['singular']) : $defaults['singular'];
258 258
 }
259 259
 
260
-function wpinv_get_label_plural( $lowercase = false ) {
260
+function wpinv_get_label_plural($lowercase = false) {
261 261
     $defaults = wpinv_get_default_labels();
262 262
     
263
-    return ( $lowercase ) ? strtolower( $defaults['plural'] ) : $defaults['plural'];
263
+    return ($lowercase) ? strtolower($defaults['plural']) : $defaults['plural'];
264 264
 }
265 265
 
266
-function wpinv_change_default_title( $title ) {
267
-     if ( !is_admin() ) {
266
+function wpinv_change_default_title($title) {
267
+     if (!is_admin()) {
268 268
         $label = wpinv_get_label_singular();
269
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
269
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
270 270
         return $title;
271 271
      }
272 272
 
273 273
      $screen = get_current_screen();
274 274
 
275
-     if ( 'wpi_invoice' == $screen->post_type ) {
275
+     if ('wpi_invoice' == $screen->post_type) {
276 276
         $label = wpinv_get_label_singular();
277
-        $title = sprintf( __( 'Enter %s name here', 'invoicing' ), $label );
277
+        $title = sprintf(__('Enter %s name here', 'invoicing'), $label);
278 278
      }
279 279
 
280 280
      return $title;
281 281
 }
282
-add_filter( 'enter_title_here', 'wpinv_change_default_title' );
282
+add_filter('enter_title_here', 'wpinv_change_default_title');
283 283
 
284 284
 function wpinv_register_post_status() {
285
-    register_post_status( 'wpi-pending', array(
286
-        'label'                     => _x( 'Pending', 'Invoice status', 'invoicing' ),
285
+    register_post_status('wpi-pending', array(
286
+        'label'                     => _x('Pending', 'Invoice status', 'invoicing'),
287 287
         'public'                    => true,
288 288
         'exclude_from_search'       => true,
289 289
         'show_in_admin_all_list'    => true,
290 290
         'show_in_admin_status_list' => true,
291
-        'label_count'               => _n_noop( 'Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing' )
292
-    ) );
293
-    register_post_status( 'wpi-processing', array(
294
-        'label'                     => _x( 'Processing', 'Invoice status', 'invoicing' ),
291
+        'label_count'               => _n_noop('Pending <span class="count">(%s)</span>', 'Pending <span class="count">(%s)</span>', 'invoicing')
292
+    ));
293
+    register_post_status('wpi-processing', array(
294
+        'label'                     => _x('Processing', 'Invoice status', 'invoicing'),
295 295
         'public'                    => true,
296 296
         'exclude_from_search'       => true,
297 297
         'show_in_admin_all_list'    => true,
298 298
         'show_in_admin_status_list' => true,
299
-        'label_count'               => _n_noop( 'Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing' )
300
-    ) );
301
-    register_post_status( 'wpi-onhold', array(
302
-        'label'                     => _x( 'On Hold', 'Invoice status', 'invoicing' ),
299
+        'label_count'               => _n_noop('Processing <span class="count">(%s)</span>', 'Processing <span class="count">(%s)</span>', 'invoicing')
300
+    ));
301
+    register_post_status('wpi-onhold', array(
302
+        'label'                     => _x('On Hold', 'Invoice status', 'invoicing'),
303 303
         'public'                    => true,
304 304
         'exclude_from_search'       => true,
305 305
         'show_in_admin_all_list'    => true,
306 306
         'show_in_admin_status_list' => true,
307
-        'label_count'               => _n_noop( 'On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing' )
308
-    ) );
309
-    register_post_status( 'wpi-cancelled', array(
310
-        'label'                     => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
307
+        'label_count'               => _n_noop('On Hold <span class="count">(%s)</span>', 'On Hold <span class="count">(%s)</span>', 'invoicing')
308
+    ));
309
+    register_post_status('wpi-cancelled', array(
310
+        'label'                     => _x('Cancelled', 'Invoice status', 'invoicing'),
311 311
         'public'                    => true,
312 312
         'exclude_from_search'       => true,
313 313
         'show_in_admin_all_list'    => true,
314 314
         'show_in_admin_status_list' => true,
315
-        'label_count'               => _n_noop( 'Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing' )
316
-    ) );
317
-    register_post_status( 'wpi-refunded', array(
318
-        'label'                     => _x( 'Refunded', 'Invoice status', 'invoicing' ),
315
+        'label_count'               => _n_noop('Cancelled <span class="count">(%s)</span>', 'Cancelled <span class="count">(%s)</span>', 'invoicing')
316
+    ));
317
+    register_post_status('wpi-refunded', array(
318
+        'label'                     => _x('Refunded', 'Invoice status', 'invoicing'),
319 319
         'public'                    => true,
320 320
         'exclude_from_search'       => true,
321 321
         'show_in_admin_all_list'    => true,
322 322
         'show_in_admin_status_list' => true,
323
-        'label_count'               => _n_noop( 'Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing' )
324
-    ) );
325
-    register_post_status( 'wpi-failed', array(
326
-        'label'                     => _x( 'Failed', 'Invoice status', 'invoicing' ),
323
+        'label_count'               => _n_noop('Refunded <span class="count">(%s)</span>', 'Refunded <span class="count">(%s)</span>', 'invoicing')
324
+    ));
325
+    register_post_status('wpi-failed', array(
326
+        'label'                     => _x('Failed', 'Invoice status', 'invoicing'),
327 327
         'public'                    => true,
328 328
         'exclude_from_search'       => true,
329 329
         'show_in_admin_all_list'    => true,
330 330
         'show_in_admin_status_list' => true,
331
-        'label_count'               => _n_noop( 'Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing' )
332
-    ) );
333
-    register_post_status( 'wpi-renewal', array(
334
-        'label'                     => _x( 'Renewal', 'Invoice status', 'invoicing' ),
331
+        'label_count'               => _n_noop('Failed <span class="count">(%s)</span>', 'Failed <span class="count">(%s)</span>', 'invoicing')
332
+    ));
333
+    register_post_status('wpi-renewal', array(
334
+        'label'                     => _x('Renewal', 'Invoice status', 'invoicing'),
335 335
         'public'                    => true,
336 336
         'exclude_from_search'       => true,
337 337
         'show_in_admin_all_list'    => true,
338 338
         'show_in_admin_status_list' => true,
339
-        'label_count'               => _n_noop( 'Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing' )
340
-    ) );
339
+        'label_count'               => _n_noop('Renewal <span class="count">(%s)</span>', 'Renewal <span class="count">(%s)</span>', 'invoicing')
340
+    ));
341 341
 }
342
-add_action( 'init', 'wpinv_register_post_status', 10 );
342
+add_action('init', 'wpinv_register_post_status', 10);
Please login to merge, or discard this patch.
includes/libraries/GeoIp2/Model/City.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -130,7 +130,6 @@
 block discarded – undo
130 130
     private function mostSpecificSubdivision()
131 131
     {
132 132
         return empty($this->subdivisions) ?
133
-            new \GeoIp2\Record\Subdivision(array(), $this->locales) :
134
-            end($this->subdivisions);
133
+            new \GeoIp2\Record\Subdivision(array(), $this->locales) : end($this->subdivisions);
135 134
     }
136 135
 }
Please login to merge, or discard this patch.
includes/libraries/GeoIp2/WebService/Client.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
         // This is for backwards compatibility. Do not remove except for a
77 77
         // major version bump.
78 78
         if (is_string($options)) {
79
-            $options = array( 'host' => $options );
79
+            $options = array('host' => $options);
80 80
         }
81 81
 
82 82
         if (!isset($options['host'])) {
Please login to merge, or discard this patch.