Passed
Pull Request — master (#50)
by Kiran
03:42
created
includes/gateways/paypal.php 1 patch
Spacing   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -21,34 +21,34 @@  discard block
 block discarded – undo
21 21
         'user_info'     => $purchase_data['user_info'],
22 22
         'cart_details'  => $purchase_data['cart_details'],
23 23
         'gateway'       => 'paypal',
24
-        'status'        => !empty( $purchase_data['buy_now'] ) ? 'private' : 'pending'
24
+        'status'        => !empty($purchase_data['buy_now']) ? 'private' : 'pending'
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $payment );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $payment);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,13 +57,13 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
 	        'lc'            => 'US' // this will force paypal site to english
69 69
         );
@@ -79,57 +79,57 @@  discard block
 block discarded – undo
79 79
             'upload' => '1'
80 80
         );
81 81
 
82
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
82
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
83 83
 
84 84
         // Add cart items
85 85
         $i = 1;
86
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
87
-            foreach ( $purchase_data['cart_details'] as $item ) {
86
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
87
+            foreach ($purchase_data['cart_details'] as $item) {
88 88
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
89
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
89
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
90 90
 
91
-                if ( $item_amount <= 0 ) {
91
+                if ($item_amount <= 0) {
92 92
                     $item_amount = 0;
93 93
                 }
94 94
 
95
-                $paypal_args['item_number_' . $i ]      = $item['id'];
96
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
97
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
98
-                $paypal_args['amount_' . $i ]           = $item_amount;
99
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
95
+                $paypal_args['item_number_' . $i]      = $item['id'];
96
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
97
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
98
+                $paypal_args['amount_' . $i]           = $item_amount;
99
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
100 100
 
101 101
                 $i++;
102 102
             }
103 103
         }
104 104
 
105 105
         // Add taxes to the cart
106
-        if ( wpinv_use_taxes() ) {
107
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 );
106
+        if (wpinv_use_taxes()) {
107
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2);
108 108
         }
109 109
 
110
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
110
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
111 111
 
112 112
         // Build query
113
-        $paypal_redirect .= http_build_query( $paypal_args );
113
+        $paypal_redirect .= http_build_query($paypal_args);
114 114
 
115 115
         // Fix for some sites that encode the entities
116
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
116
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
117 117
 
118 118
         // Get rid of cart contents
119 119
         wpinv_empty_cart();
120 120
         
121 121
         // Redirect to PayPal
122
-        wp_redirect( $paypal_redirect );
122
+        wp_redirect($paypal_redirect);
123 123
         exit;
124 124
     }
125 125
 }
126
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
126
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
127 127
 
128
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
129
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
130
-        $item   = new WPInv_Item( $item_id );
128
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
129
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
130
+        $item = new WPInv_Item($item_id);
131 131
         
132
-        if ( empty( $item ) ) {
132
+        if (empty($item)) {
133 133
             return $paypal_args;
134 134
         }
135 135
 
@@ -137,24 +137,24 @@  discard block
 block discarded – undo
137 137
         $interval           = $item->get_recurring_interval();
138 138
         $bill_times         = (int)$item->get_recurring_limit();
139 139
         
140
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
141
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
140
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
141
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
142 142
         
143 143
         $paypal_args['cmd'] = '_xclick-subscriptions';
144 144
         $paypal_args['sra'] = '1';
145 145
         $paypal_args['src'] = '1';
146 146
         
147 147
         // Set item description
148
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( array( 'id' => $item->ID ) ), ENT_COMPAT, 'UTF-8' ) );
148
+        $paypal_args['item_name'] = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name(array('id' => $item->ID)), ENT_COMPAT, 'UTF-8'));
149 149
         
150
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
150
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
151 151
             $paypal_args['a1']  = $initial_amount;
152 152
             $paypal_args['p1']  = $item->get_trial_interval();
153 153
             $paypal_args['t1']  = $item->get_trial_period();
154 154
             
155 155
             // Set the recurring amount
156 156
             $paypal_args['a3']  = $recurring_amount;
157
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
157
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
158 158
             $paypal_args['a1']  = $initial_amount;
159 159
             $paypal_args['p1']  = $interval;
160 160
             $paypal_args['t1']  = $period;
@@ -162,63 +162,63 @@  discard block
 block discarded – undo
162 162
             // Set the recurring amount
163 163
             $paypal_args['a3']  = $recurring_amount;
164 164
             
165
-            if ( $bill_times > 1 ) {
165
+            if ($bill_times > 1) {
166 166
                 $bill_times--;
167 167
             }
168 168
         } else {
169
-            $paypal_args['a3']  = $initial_amount;
169
+            $paypal_args['a3'] = $initial_amount;
170 170
         }
171 171
         
172 172
         $paypal_args['p3']  = $interval;
173 173
         $paypal_args['t3']  = $period;
174 174
         
175
-        if ( $bill_times > 1 ) {
175
+        if ($bill_times > 1) {
176 176
             // Make sure it's not over the max of 52
177
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
177
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
178 178
         }
179 179
                 
180 180
         // Remove cart items
181 181
         $i = 1;
182
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
183
-            foreach ( $purchase_data['cart_details'] as $item ) {                
184
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
185
-                    unset( $paypal_args['item_number_' . $i] );
182
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
183
+            foreach ($purchase_data['cart_details'] as $item) {                
184
+                if (isset($paypal_args['item_number_' . $i])) {
185
+                    unset($paypal_args['item_number_' . $i]);
186 186
                 }
187
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
188
-                    unset( $paypal_args['item_name_' . $i] );
187
+                if (isset($paypal_args['item_name_' . $i])) {
188
+                    unset($paypal_args['item_name_' . $i]);
189 189
                 }
190
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
191
-                    unset( $paypal_args['quantity_' . $i] );
190
+                if (isset($paypal_args['quantity_' . $i])) {
191
+                    unset($paypal_args['quantity_' . $i]);
192 192
                 }
193
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
194
-                    unset( $paypal_args['amount_' . $i] );
193
+                if (isset($paypal_args['amount_' . $i])) {
194
+                    unset($paypal_args['amount_' . $i]);
195 195
                 }
196
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
197
-                    unset( $paypal_args['discount_amount_' . $i] );
196
+                if (isset($paypal_args['discount_amount_' . $i])) {
197
+                    unset($paypal_args['discount_amount_' . $i]);
198 198
                 }
199 199
 
200 200
                 $i++;
201 201
             }
202 202
         }
203 203
         
204
-        if ( isset( $paypal_args['tax_cart'] ) ) {
205
-            unset( $paypal_args['tax_cart'] );
204
+        if (isset($paypal_args['tax_cart'])) {
205
+            unset($paypal_args['tax_cart']);
206 206
         }
207 207
                 
208
-        if ( isset( $paypal_args['upload'] ) ) {
209
-            unset( $paypal_args['upload'] );
208
+        if (isset($paypal_args['upload'])) {
209
+            unset($paypal_args['upload']);
210 210
         }
211 211
         
212
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
212
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
213 213
     }
214 214
     
215 215
     return $paypal_args;
216 216
 }
217
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
217
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
218 218
 
219 219
 function wpinv_process_paypal_ipn() {
220 220
 	// Check the request method is POST
221
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
221
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
222 222
 		return;
223 223
 	}
224 224
 
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	$post_data = '';
227 227
 
228 228
 	// Fallback just in case post_max_size is lower than needed
229
-	if ( ini_get( 'allow_url_fopen' ) ) {
230
-		$post_data = file_get_contents( 'php://input' );
229
+	if (ini_get('allow_url_fopen')) {
230
+		$post_data = file_get_contents('php://input');
231 231
 	} else {
232 232
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
233
-		ini_set( 'post_max_size', '12M' );
233
+		ini_set('post_max_size', '12M');
234 234
 	}
235 235
 	// Start the encoded data collection with notification command
236 236
 	$encoded_data = 'cmd=_notify-validate';
@@ -239,43 +239,43 @@  discard block
 block discarded – undo
239 239
 	$arg_separator = wpinv_get_php_arg_separator_output();
240 240
 
241 241
 	// Verify there is a post_data
242
-	if ( $post_data || strlen( $post_data ) > 0 ) {
242
+	if ($post_data || strlen($post_data) > 0) {
243 243
 		// Append the data
244
-		$encoded_data .= $arg_separator.$post_data;
244
+		$encoded_data .= $arg_separator . $post_data;
245 245
 	} else {
246 246
 		// Check if POST is empty
247
-		if ( empty( $_POST ) ) {
247
+		if (empty($_POST)) {
248 248
 			// Nothing to do
249 249
 			return;
250 250
 		} else {
251 251
 			// Loop through each POST
252
-			foreach ( $_POST as $key => $value ) {
252
+			foreach ($_POST as $key => $value) {
253 253
 				// Encode the value and append the data
254
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
254
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
255 255
 			}
256 256
 		}
257 257
 	}
258 258
 
259 259
 	// Convert collected post data to an array
260
-	parse_str( $encoded_data, $encoded_data_array );
260
+	parse_str($encoded_data, $encoded_data_array);
261 261
 
262
-	foreach ( $encoded_data_array as $key => $value ) {
263
-		if ( false !== strpos( $key, 'amp;' ) ) {
264
-			$new_key = str_replace( '&amp;', '&', $key );
265
-			$new_key = str_replace( 'amp;', '&' , $new_key );
262
+	foreach ($encoded_data_array as $key => $value) {
263
+		if (false !== strpos($key, 'amp;')) {
264
+			$new_key = str_replace('&amp;', '&', $key);
265
+			$new_key = str_replace('amp;', '&', $new_key);
266 266
 
267
-			unset( $encoded_data_array[ $key ] );
268
-			$encoded_data_array[ $new_key ] = $value;
267
+			unset($encoded_data_array[$key]);
268
+			$encoded_data_array[$new_key] = $value;
269 269
 		}
270 270
 	}
271 271
 
272 272
 	// Get the PayPal redirect uri
273
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
273
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
274 274
 
275
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
275
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
276 276
 		// Validate the IPN
277 277
 
278
-		$remote_post_vars      = array(
278
+		$remote_post_vars = array(
279 279
 			'method'           => 'POST',
280 280
 			'timeout'          => 45,
281 281
 			'redirection'      => 5,
@@ -293,21 +293,21 @@  discard block
 block discarded – undo
293 293
 		);
294 294
 
295 295
 		// Get response
296
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
296
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
297 297
 
298
-		if ( is_wp_error( $api_response ) ) {
299
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
298
+		if (is_wp_error($api_response)) {
299
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
300 300
 			return; // Something went wrong
301 301
 		}
302 302
 
303
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
304
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
303
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
304
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
305 305
 			return; // Response not okay
306 306
 		}
307 307
 	}
308 308
 
309 309
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
310
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
311 311
 		return;
312 312
 
313 313
 	$defaults = array(
@@ -315,215 +315,215 @@  discard block
 block discarded – undo
315 315
 		'payment_status' => ''
316 316
 	);
317 317
 
318
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
318
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
319 319
 
320
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
320
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
321 321
     
322
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
322
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
323 323
 
324
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
324
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
325 325
 		// Allow PayPal IPN types to be processed separately
326
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
326
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
327 327
 	} else {
328 328
 		// Fallback to web accept just in case the txn_type isn't present
329
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
330 330
 	}
331 331
 	exit;
332 332
 }
333
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
333
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
334 334
 
335
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
336
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
335
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
336
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
337 337
 		return;
338 338
 	}
339 339
 
340
-	if( empty( $invoice_id ) ) {
340
+	if (empty($invoice_id)) {
341 341
 		return;
342 342
 	}
343 343
 
344 344
 	// Collect payment details
345
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
345
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
346 346
 	$paypal_amount  = $data['mc_gross'];
347
-	$payment_status = strtolower( $data['payment_status'] );
348
-	$currency_code  = strtolower( $data['mc_currency'] );
349
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
350
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
347
+	$payment_status = strtolower($data['payment_status']);
348
+	$currency_code  = strtolower($data['mc_currency']);
349
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
350
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
351 351
 
352
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
352
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
353 353
 		return; // this isn't a PayPal standard IPN
354 354
 	}
355 355
 
356 356
 	// Verify payment recipient
357
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
358
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
359
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
360
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ) );
357
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
358
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
359
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
360
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'));
361 361
 		return;
362 362
 	}
363 363
 
364 364
 	// Verify payment currency
365
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
366
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
367
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
368
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ) );
365
+	if ($currency_code != strtolower($payment_meta['currency'])) {
366
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
367
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
368
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'));
369 369
 		return;
370 370
 	}
371 371
 
372
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
372
+	if (!wpinv_get_payment_user_email($invoice_id)) {
373 373
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
374 374
 		// No email associated with purchase, so store from PayPal
375
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
375
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
376 376
 
377 377
 		// Setup and store the customer's details
378 378
 		$user_info = array(
379 379
 			'user_id'    => '-1',
380
-			'email'      => sanitize_text_field( $data['payer_email'] ),
381
-			'first_name' => sanitize_text_field( $data['first_name'] ),
382
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
380
+			'email'      => sanitize_text_field($data['payer_email']),
381
+			'first_name' => sanitize_text_field($data['first_name']),
382
+			'last_name'  => sanitize_text_field($data['last_name']),
383 383
 			'discount'   => '',
384 384
 		);
385
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
386
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
387
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
388
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
389
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
385
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
386
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
387
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
388
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
389
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
390 390
 
391 391
 		$payment_meta['user_info'] = $user_info;
392
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
392
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
393 393
 	}
394 394
 
395
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
395
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
396 396
 		// Process a refund
397
-		wpinv_process_paypal_refund( $data, $invoice_id );
397
+		wpinv_process_paypal_refund($data, $invoice_id);
398 398
 	} else {
399
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
399
+		if (get_post_status($invoice_id) == 'publish') {
400 400
 			return; // Only paid payments once
401 401
 		}
402 402
 
403 403
 		// Retrieve the total purchase amount (before PayPal)
404
-		$payment_amount = wpinv_payment_total( $invoice_id );
404
+		$payment_amount = wpinv_payment_total($invoice_id);
405 405
 
406
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
406
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
407 407
 			// The prices don't match
408
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
409
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
410
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ) );
408
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
409
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
410
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'));
411 411
 			return;
412 412
 		}
413
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
413
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
414 414
 			// Purchase keys don't match
415
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
416
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
417
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ) );
415
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
416
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
417
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'));
418 418
 			return;
419 419
 		}
420 420
 
421
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
422
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ) );
423
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
424
-			wpinv_update_payment_status( $invoice_id, 'publish' );
425
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
421
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
422
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']));
423
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
424
+			wpinv_update_payment_status($invoice_id, 'publish');
425
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
426 426
 			// Look for possible pending reasons, such as an echeck
427 427
 			$note = '';
428 428
 
429
-			switch( strtolower( $data['pending_reason'] ) ) {
429
+			switch (strtolower($data['pending_reason'])) {
430 430
 				case 'echeck' :
431
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
431
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
432 432
 					break;
433 433
 				
434 434
                 case 'address' :
435
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
435
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
436 436
 					break;
437 437
 				
438 438
                 case 'intl' :
439
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
439
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
440 440
 					break;
441 441
 				
442 442
                 case 'multi-currency' :
443
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
443
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
444 444
 					break;
445 445
 				
446 446
                 case 'paymentreview' :
447 447
                 case 'regulatory_review' :
448
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
448
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
449 449
 					break;
450 450
 				
451 451
                 case 'unilateral' :
452
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
452
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
453 453
 					break;
454 454
 				
455 455
                 case 'upgrade' :
456
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
456
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
457 457
 					break;
458 458
 				
459 459
                 case 'verify' :
460
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
460
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
461 461
 					break;
462 462
 
463 463
 				case 'other' :
464
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
464
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
465 465
 					break;
466 466
 			}
467 467
 
468
-			if ( ! empty( $note ) ) {
469
-				wpinv_insert_payment_note( $invoice_id, $note );
468
+			if (!empty($note)) {
469
+				wpinv_insert_payment_note($invoice_id, $note);
470 470
 			}
471 471
 		} else {
472
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ) );
472
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status));
473 473
 		}
474 474
 	}
475 475
 }
476
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
476
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
477 477
 
478 478
 // Process PayPal subscription sign ups
479
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
479
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
480 480
 
481 481
 // Process PayPal subscription payments
482
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
482
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
483 483
 
484 484
 // Process PayPal subscription cancellations
485
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
485
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
486 486
 
487 487
 // Process PayPal subscription end of term notices
488
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
488
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
489 489
 
490 490
 // Process PayPal payment failed
491
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
491
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
492 492
 
493 493
 
494 494
 /**
495 495
  * Process the subscription started IPN.
496 496
  */
497
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
498
-    $parent_invoice_id = absint( $ipn_data['custom'] );
499
-    if( empty( $parent_invoice_id ) ) {
497
+function wpinv_process_paypal_subscr_signup($ipn_data) {
498
+    $parent_invoice_id = absint($ipn_data['custom']);
499
+    if (empty($parent_invoice_id)) {
500 500
         return;
501 501
     }
502 502
 
503
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
504
-    if ( empty( $invoice ) ) {
503
+    $invoice = wpinv_get_invoice($parent_invoice_id);
504
+    if (empty($invoice)) {
505 505
         return;
506 506
     }
507 507
 
508
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
509
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ) );
510
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['invoice'] );
508
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
509
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']));
510
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['invoice']);
511 511
     }
512 512
     
513
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
513
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
514 514
     sleep(1);
515
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ) );
515
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']));
516 516
     
517
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
518
-    if ( false === $subscription ) {
517
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
518
+    if (false === $subscription) {
519 519
         return;
520 520
     }
521 521
 
522
-    $cart_details   = $invoice->cart_details;
522
+    $cart_details = $invoice->cart_details;
523 523
 
524
-    if ( !empty( $cart_details ) ) {
525
-        foreach ( $cart_details as $cart_item ) {
526
-            $item = new WPInv_Item( $cart_item['id'] );
524
+    if (!empty($cart_details)) {
525
+        foreach ($cart_details as $cart_item) {
526
+            $item = new WPInv_Item($cart_item['id']);
527 527
             
528 528
             $status = $invoice->is_free_trial() && $item->has_free_trial() ? 'trialing' : 'active';
529 529
             
@@ -532,15 +532,15 @@  discard block
 block discarded – undo
532 532
                 'status'            => $status,
533 533
                 'period'            => $item->get_recurring_period(),
534 534
                 'initial_amount'    => $invoice->get_total(),
535
-                'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
535
+                'recurring_amount'  => $invoice->get_recurring_details('total'),
536 536
                 'interval'          => $item->get_recurring_interval(),
537 537
                 'bill_times'        => $item->get_recurring_limit(),
538
-                'expiration'        => $invoice->get_new_expiration( $cart_item['id'] ),
538
+                'expiration'        => $invoice->get_new_expiration($cart_item['id']),
539 539
                 'profile_id'        => $ipn_data['subscr_id'],
540
-                'created'           => date_i18n( 'Y-m-d H:i:s', strtotime( $ipn_data['subscr_date'] ) )
540
+                'created'           => date_i18n('Y-m-d H:i:s', strtotime($ipn_data['subscr_date']))
541 541
             );
542 542
             
543
-            if ( $item->has_free_trial() ) {
543
+            if ($item->has_free_trial()) {
544 544
                 $args['trial_period']      = $item->get_trial_period();
545 545
                 $args['trial_interval']    = $item->get_trial_interval();
546 546
             } else {
@@ -549,7 +549,7 @@  discard block
 block discarded – undo
549 549
             }
550 550
             
551 551
 
552
-            $subscription->update_subscription( $args );
552
+            $subscription->update_subscription($args);
553 553
         }
554 554
     }
555 555
 }
@@ -557,39 +557,39 @@  discard block
 block discarded – undo
557 557
 /**
558 558
  * Process the subscription payment received IPN.
559 559
  */
560
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
561
-    $parent_invoice_id = absint( $ipn_data['custom'] );
560
+function wpinv_process_paypal_subscr_payment($ipn_data) {
561
+    $parent_invoice_id = absint($ipn_data['custom']);
562 562
     
563
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
564
-    if ( false === $subscription ) {
563
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
564
+    if (false === $subscription) {
565 565
         return;
566 566
     }
567 567
     
568
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
569
-    $signup_date    = strtotime( $subscription->get_subscription_created() );
570
-    $today          = date_i18n( 'Y-m-d', $signup_date ) == date_i18n( 'Y-m-d', strtotime( $ipn_data['payment_date'] ) );
568
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
569
+    $signup_date    = strtotime($subscription->get_subscription_created());
570
+    $today          = date_i18n('Y-m-d', $signup_date) == date_i18n('Y-m-d', strtotime($ipn_data['payment_date']));
571 571
 
572 572
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
573
-    if ( $today && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
574
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
573
+    if ($today && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
574
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
575 575
         sleep(1);
576 576
         
577 577
         // This is the very first payment
578
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
579
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
578
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
579
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
580 580
         return;
581 581
     }
582 582
     
583
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
583
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
584 584
         return; // Payment already recorded
585 585
     }
586 586
 
587
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
587
+    $currency_code = strtolower($ipn_data['mc_currency']);
588 588
 
589 589
     // verify details
590
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
590
+    if ($currency_code != strtolower(wpinv_get_currency())) {
591 591
         // the currency code is invalid
592
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
592
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
593 593
         return;
594 594
     }
595 595
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         'transaction_id' => $ipn_data['txn_id']
599 599
     );
600 600
     
601
-    $invoice = wpinv_recurring_add_subscription_payment( $parent_invoice_id, $args );
601
+    $invoice = wpinv_recurring_add_subscription_payment($parent_invoice_id, $args);
602 602
     
603
-    if ( !empty( $invoice ) ) {
603
+    if (!empty($invoice)) {
604 604
         sleep(1);
605
-        wpinv_insert_payment_note( $invoice->ID, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ) );
605
+        wpinv_insert_payment_note($invoice->ID, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']));
606 606
 
607 607
         $invoice->renew_subscription();
608 608
     }
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription canceled IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,10 +624,10 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription expired IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_eot($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
@@ -637,45 +637,45 @@  discard block
 block discarded – undo
637 637
 /**
638 638
  * Process the subscription payment failed IPN.
639 639
  */
640
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
641
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
640
+function wpinv_process_paypal_subscr_failed($ipn_data) {
641
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
642 642
 
643
-    if( false === $subscription ) {
643
+    if (false === $subscription) {
644 644
         return;
645 645
     }
646 646
 
647 647
     $subscription->failing_subscription();
648 648
 
649
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
649
+    do_action('wpinv_recurring_payment_failed', $subscription);
650 650
 }
651 651
 
652 652
 /**
653 653
  * Retrieve the subscription this IPN notice is for.
654 654
  */
655
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
656
-    $parent_invoice_id = absint( $ipn_data['custom'] );
655
+function wpinv_get_paypal_subscription($ipn_data = array()) {
656
+    $parent_invoice_id = absint($ipn_data['custom']);
657 657
 
658
-    if( empty( $parent_invoice_id ) ) {
658
+    if (empty($parent_invoice_id)) {
659 659
         return false;
660 660
     }
661 661
 
662
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
663
-    if ( empty( $invoice ) ) {
662
+    $invoice = wpinv_get_invoice($parent_invoice_id);
663
+    if (empty($invoice)) {
664 664
         return false;
665 665
     }
666 666
 
667
-    $subscription = wpinv_get_subscription( $ipn_data['subscr_id'], true );
667
+    $subscription = wpinv_get_subscription($ipn_data['subscr_id'], true);
668 668
 
669
-    if ( empty( $subscription ) ) {
670
-        $subs         = wpinv_get_subscriptions( array( 'parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1 ) );
671
-        $subscription = reset( $subs );
669
+    if (empty($subscription)) {
670
+        $subs         = wpinv_get_subscriptions(array('parent_invoice_id' => $parent_invoice_id, 'numberposts' => 1));
671
+        $subscription = reset($subs);
672 672
 
673
-        if ( $subscription && $subscription->ID > 0 ) {
673
+        if ($subscription && $subscription->ID > 0) {
674 674
             // Update the profile ID so it is set for future renewals
675
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
675
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
676 676
         } else {
677 677
             $subscription = $invoice;
678
-            $subscription->update_subscription( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
678
+            $subscription->update_subscription(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
679 679
             // No subscription found with a matching payment ID, bail
680 680
             //return false;
681 681
         }
@@ -685,39 +685,39 @@  discard block
 block discarded – undo
685 685
 
686 686
 }
687 687
 
688
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
688
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
689 689
 	// Collect payment details
690 690
 
691
-	if( empty( $invoice_id ) ) {
691
+	if (empty($invoice_id)) {
692 692
 		return;
693 693
 	}
694 694
 
695
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
695
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
696 696
 		return; // Only refund payments once
697 697
 	}
698 698
 
699
-	$payment_amount = wpinv_payment_total( $invoice_id );
699
+	$payment_amount = wpinv_payment_total($invoice_id);
700 700
 	$refund_amount  = $data['mc_gross'] * -1;
701 701
 
702
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
703
-		wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Partial PayPal refund processed: %s', 'invoicing' ), $data['parent_txn_id'] ) );
702
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
703
+		wpinv_insert_payment_note($invoice_id, sprintf(__('Partial PayPal refund processed: %s', 'invoicing'), $data['parent_txn_id']));
704 704
 		return; // This is a partial refund
705 705
 	}
706 706
 
707
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ) );
708
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ) );
709
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
707
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']));
708
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']));
709
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
710 710
 }
711 711
 
712
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
713
-    if ( is_ssl() || ! $ssl_check ) {
712
+function wpinv_get_paypal_redirect($ssl_check = false) {
713
+    if (is_ssl() || !$ssl_check) {
714 714
         $protocol = 'https://';
715 715
     } else {
716 716
         $protocol = 'http://';
717 717
     }
718 718
 
719 719
     // Check the current payment mode
720
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
720
+    if (wpinv_is_test_mode('paypal')) {
721 721
         // Test mode
722 722
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
723 723
     } else {
@@ -725,67 +725,67 @@  discard block
 block discarded – undo
725 725
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
726 726
     }
727 727
 
728
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
728
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
729 729
 }
730 730
 
731
-function wpinv_paypal_success_page_content( $content ) {
731
+function wpinv_paypal_success_page_content($content) {
732 732
     global $wpi_invoice;
733 733
     
734 734
     $session = wpinv_get_checkout_session();
735 735
 
736
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
736
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
737 737
         return $content;
738 738
     }
739 739
 
740
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
740
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
741 741
 
742
-    if ( empty(  $invoice_id ) ) {
742
+    if (empty($invoice_id)) {
743 743
         return $content;
744 744
     }
745 745
 
746
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
746
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
747 747
     
748
-    if ( !empty( $wpi_invoice ) && 'pending' == $wpi_invoice->status ) {
748
+    if (!empty($wpi_invoice) && 'pending' == $wpi_invoice->status) {
749 749
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
750 750
         ob_start();
751
-        wpinv_get_template_part( 'wpinv-payment-processing' );
751
+        wpinv_get_template_part('wpinv-payment-processing');
752 752
         $content = ob_get_clean();
753 753
     }
754 754
 
755 755
     return $content;
756 756
 }
757
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
757
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
758 758
 
759
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
759
+function wpinv_paypal_get_transaction_id($invoice_id) {
760 760
     $transaction_id = '';
761
-    $notes = wpinv_get_invoice_notes( $invoice_id );
761
+    $notes = wpinv_get_invoice_notes($invoice_id);
762 762
 
763
-    foreach ( $notes as $note ) {
764
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
763
+    foreach ($notes as $note) {
764
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
765 765
             $transaction_id = $match[1];
766 766
             continue;
767 767
         }
768 768
     }
769 769
 
770
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
770
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
771 771
 }
772
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
772
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
773 773
 
774
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
775
-    if ( $invoice->is_free_trial() || $transaction_id == $invoice_id ) { // Free trial does not have transaction at PayPal.
774
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
775
+    if ($invoice->is_free_trial() || $transaction_id == $invoice_id) { // Free trial does not have transaction at PayPal.
776 776
         $transaction_url = $invoice->get_view_url();
777 777
     } else {
778
-        $sandbox = wpinv_is_test_mode( 'paypal' ) ? '.sandbox' : '';
778
+        $sandbox = wpinv_is_test_mode('paypal') ? '.sandbox' : '';
779 779
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_view-a-trans&id=' . $transaction_id;
780 780
     }
781 781
 
782
-    $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
782
+    $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
783 783
 
784
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice );
784
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $invoice);
785 785
 }
786
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
786
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
787 787
 
788 788
 function wpinv_gateway_paypal_button_label($label) {
789
-    return __( 'Proceed to PayPal', 'invoicing' );
789
+    return __('Proceed to PayPal', 'invoicing');
790 790
 }
791
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
792 791
\ No newline at end of file
792
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
793 793
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 1 patch
Spacing   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-4 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-8">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-4 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-8">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-4 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-2">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-4 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-8">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
     
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,174 +83,174 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
         
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
         
104 104
         $errors = wpinv_get_errors();
105 105
     
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
             
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
             
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
                 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
             
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
             
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
                 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
             
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
             
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
             
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
             
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
             
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
             
160 160
             try {
161
-                if ( $is_recurring ) {
161
+                if ($is_recurring) {
162 162
                     $response = $authorizeAIM->authorizeOnly();
163 163
                 } else {
164 164
                     $response = $authorizeAIM->authorizeAndCapture();
165 165
                 }
166 166
                 
167
-                if ( $response->approved || $response->held ) {
168
-                    if ( $response->approved ) {
169
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
167
+                if ($response->approved || $response->held) {
168
+                    if ($response->approved) {
169
+                        wpinv_update_payment_status($invoice_id, 'publish');
170 170
                     }
171
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
171
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
172 172
                     
173
-                    $message = wp_sprintf( __( 'Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing' ), $response->response_reason_text, $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code );
173
+                    $message = wp_sprintf(__('Authorize.Net Payment: %s with transaction id %s using %s and authorization code %s', 'invoicing'), $response->response_reason_text, $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code);
174 174
                     
175
-                    wpinv_insert_payment_note( $invoice_id, $message );
175
+                    wpinv_insert_payment_note($invoice_id, $message);
176 176
                     
177
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
177
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
178 178
                     
179 179
                     wpinv_clear_errors();
180 180
                     wpinv_empty_cart();
181 181
                     
182
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
182
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
183 183
                 } else {
184
-                    if ( !empty( $response->response_reason_text ) ) {
185
-                        $error = __( $response->response_reason_text, 'invoicing' );
186
-                    } else if ( !empty( $response->error_message ) ) {
187
-                        $error = __( $response->error_message, 'invoicing' );
184
+                    if (!empty($response->response_reason_text)) {
185
+                        $error = __($response->response_reason_text, 'invoicing');
186
+                    } else if (!empty($response->error_message)) {
187
+                        $error = __($response->error_message, 'invoicing');
188 188
                     } else {
189
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
189
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
190 190
                     } 
191 191
                     
192
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
192
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
193 193
                     
194
-                    wpinv_set_error( 'payment_error', $error );
195
-                    wpinv_record_gateway_error( $error, $response );
196
-                    wpinv_insert_payment_note( $invoice_id, $error );
194
+                    wpinv_set_error('payment_error', $error);
195
+                    wpinv_record_gateway_error($error, $response);
196
+                    wpinv_insert_payment_note($invoice_id, $error);
197 197
                     
198
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
198
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
199 199
                 }
200
-            } catch ( AuthorizeNetException $e ) {
201
-                wpinv_set_error( 'request_error', $e->getMessage() );
202
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
203
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
200
+            } catch (AuthorizeNetException $e) {
201
+                wpinv_set_error('request_error', $e->getMessage());
202
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
203
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
204 204
             }
205 205
         } else {
206
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
206
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
207 207
         }
208 208
     } else {
209
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
210
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
209
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
210
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
211 211
     }
212 212
 }
213
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
213
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
214 214
 
215
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
216
-    if ( empty( $subscription_id ) ) {
215
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
216
+    if (empty($subscription_id)) {
217 217
         return false;
218 218
     }
219 219
     
220 220
     try {
221 221
         $authnetXML = wpinv_authorizenet_XML();
222
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
222
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
223 223
 
224 224
         return $authnetXML->isSuccessful();
225
-    } catch( Exception $e ) {
226
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
225
+    } catch (Exception $e) {
226
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
227 227
     }
228 228
     
229 229
     return false;
230 230
 }
231 231
 
232
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
233
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
234
-    if ( empty( $authorizenet_md5_hash ) ) {
232
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
233
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
234
+    if (empty($authorizenet_md5_hash)) {
235 235
         return true;
236 236
     }
237 237
     
238
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
238
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
239 239
     
240
-    return hash_equals( $compare_md5, $md5_hash );
240
+    return hash_equals($compare_md5, $md5_hash);
241 241
 }
242 242
 
243 243
 function wpinv_authorizenet_AIM() {
244
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
245
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
244
+    if (!class_exists('AuthorizeNetException')) {
245
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
246 246
     }
247 247
     
248
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
248
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
249 249
     
250
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
251
-        $authorizeAIM->setSandbox( true );
250
+    if (wpinv_is_test_mode('authorizenet')) {
251
+        $authorizeAIM->setSandbox(true);
252 252
     } else {
253
-        $authorizeAIM->setSandbox( false );
253
+        $authorizeAIM->setSandbox(false);
254 254
     }
255 255
     
256 256
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -259,164 +259,164 @@  discard block
 block discarded – undo
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_XML() {
262
-    if ( !class_exists( 'AuthnetXML' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
262
+    if (!class_exists('AuthnetXML')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
264 264
     }
265 265
     
266
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
266
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
267 267
     
268 268
     return $authnetXML;
269 269
 }
270 270
 
271
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
272
-    if ( empty( $response ) || empty( $invoice ) ) {
271
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
272
+    if (empty($response) || empty($invoice)) {
273 273
         return false;
274 274
     }
275 275
     
276
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
277
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
276
+    if ($invoice->is_recurring() && !empty($response->approved)) {
277
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
278 278
 
279
-        if ( !empty( $subscription ) && $subscription->isSuccessful() ) {
280
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
279
+        if (!empty($subscription) && $subscription->isSuccessful()) {
280
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
281 281
             
282
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
282
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
283 283
             
284
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
284
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
285 285
         } else {
286
-            if ( isset( $subscription->messages->message ) ) {
286
+            if (isset($subscription->messages->message)) {
287 287
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
288
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
288
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
289 289
             } else {
290
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
291
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
290
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
291
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
292 292
             }
293 293
             
294
-            wpinv_record_gateway_error( $error, $subscription );
294
+            wpinv_record_gateway_error($error, $subscription);
295 295
             
296
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ) );
296
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error));
297 297
         }
298 298
     }
299 299
 }
300
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
300
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
301 301
 
302
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
303
-    if ( empty( $invoice ) ) {
302
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
303
+    if (empty($invoice)) {
304 304
         return false;
305 305
     }
306 306
     
307
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
307
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
308 308
     
309 309
     try {
310 310
         $authnetXML = wpinv_authorizenet_XML();
311
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
312
-    } catch( Exception $e ) {
311
+        $authnetXML->ARBCreateSubscriptionRequest($params);
312
+    } catch (Exception $e) {
313 313
         $authnetXML = array();
314
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
314
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
315 315
     }
316 316
     
317 317
     return $authnetXML;
318 318
 }
319 319
 
320
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
321
-    if ( empty( $invoice ) ) {
320
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
321
+    if (empty($invoice)) {
322 322
         return false;
323 323
     }
324 324
     
325
-    $subscription_item = $invoice->get_recurring( true );
326
-    if ( empty( $subscription_item ) ) {
325
+    $subscription_item = $invoice->get_recurring(true);
326
+    if (empty($subscription_item)) {
327 327
         return false;
328 328
     }
329 329
     
330
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
330
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
331 331
     $subscription_name  = $invoice->get_subscription_name();
332
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
333
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
332
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
333
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
334 334
     $interval           = $subscription_item->get_recurring_interval();
335 335
     $period             = $subscription_item->get_recurring_period();
336 336
     $bill_times         = (int)$subscription_item->get_recurring_limit();
337 337
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
338 338
     
339
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
339
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
340 340
     $interval           = $time_period['interval'];
341 341
     $period             = $time_period['period'];
342 342
     
343 343
     $current_tz = date_default_timezone_get();
344
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
-    $today = date( 'Y-m-d' );
346
-    date_default_timezone_set( $current_tz );
344
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
345
+    $today = date('Y-m-d');
346
+    date_default_timezone_set($current_tz);
347 347
     
348 348
     $free_trial = $invoice->is_free_trial();
349
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
349
+    if ($free_trial && $subscription_item->has_free_trial()) {
350 350
         $trial_interval    = $subscription_item->get_trial_interval();
351
-        $trial_period      = $subscription_item->get_trial_period( true );
351
+        $trial_period      = $subscription_item->get_trial_period(true);
352 352
     }
353 353
     
354 354
     $subscription = array();
355 355
     $subscription['name'] = $subscription_name;
356 356
     
357 357
     $subscription['paymentSchedule'] = array(
358
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
358
+        'interval'         => array('length' => $interval, 'unit' => $period),
359 359
         'startDate'        => $today,
360 360
         'totalOccurrences' => $bill_times,
361
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
361
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
362 362
     );
363 363
     
364 364
     $subscription['amount'] = $recurring_amount;
365 365
     $subscription['trialAmount'] = $initial_amount;
366
-    $subscription['payment'] = array( 'creditCard' => $card_details );
367
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
368
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
366
+    $subscription['payment'] = array('creditCard' => $card_details);
367
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
368
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
369 369
     
370 370
     $subscription['billTo'] = array(
371 371
         'firstName' => $invoice->get_first_name(),
372 372
         'lastName'  => $invoice->get_last_name(),
373 373
         'company'   => $invoice->company,
374
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
374
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
375 375
         'city'      => $invoice->city,
376 376
         'state'     => $invoice->state,
377 377
         'zip'       => $invoice->zip,
378 378
         'country'   => $invoice->country,
379 379
     );
380 380
     
381
-    $params = array( 'subscription' => $subscription );
381
+    $params = array('subscription' => $subscription);
382 382
     
383
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
383
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
384 384
 }
385 385
 
386
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
387
-    $card_defaults      = array(
386
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
387
+    $card_defaults = array(
388 388
         'cc_owner'          => null,
389 389
         'cc_number'         => null,
390 390
         'cc_expire_month'   => null,
391 391
         'cc_expire_year'    => null,
392 392
         'cc_cvv2'           => null,
393 393
     );
394
-    $card_info = wp_parse_args( $card_info, $card_defaults );
394
+    $card_info = wp_parse_args($card_info, $card_defaults);
395 395
         
396 396
     $card_details = array(
397
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
398
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
399
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
397
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
398
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
399
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
400 400
     );
401 401
 
402 402
     return $card_details;
403 403
 }
404 404
 
405
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
406
-    if ( empty( $invoice ) || empty( $subscription ) ) {
405
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
406
+    if (empty($invoice) || empty($subscription)) {
407 407
         return false;
408 408
     }
409 409
     
410
-    $subscription_item = $invoice->get_recurring( true );
411
-    if ( empty( $subscription_item ) ) {
410
+    $subscription_item = $invoice->get_recurring(true);
411
+    if (empty($subscription_item)) {
412 412
         return false;
413 413
     }
414 414
     
415 415
     $invoice_id         = $invoice->ID;
416 416
     $subscriptionId     = (array)$subscription->subscriptionId;
417
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $invoice_id;
417
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $invoice_id;
418 418
 
419
-    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ) );
419
+    wpinv_insert_payment_note($invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id));
420 420
     
421 421
     $status = $invoice->is_free_trial() && $subscription_item->has_free_trial() ? 'trialing' : 'active';
422 422
     
@@ -424,16 +424,16 @@  discard block
 block discarded – undo
424 424
         'profile_id'        => $subscription_id,
425 425
         'item_id'           => $subscription_item->ID,
426 426
         'initial_amount'    => $invoice->get_total(),
427
-        'recurring_amount'  => $invoice->get_recurring_details( 'total' ),
427
+        'recurring_amount'  => $invoice->get_recurring_details('total'),
428 428
         'period'            => $subscription_item->get_recurring_period(),
429 429
         'interval'          => $subscription_item->get_recurring_interval(),
430 430
         'bill_times'        => $subscription_item->get_recurring_limit(),
431
-        'expiration'        => $invoice->get_new_expiration( $subscription_item->ID ),
431
+        'expiration'        => $invoice->get_new_expiration($subscription_item->ID),
432 432
         'status'            => $status,
433
-        'created'           => current_time( 'mysql', 0 )
433
+        'created'           => current_time('mysql', 0)
434 434
     );
435 435
     
436
-    if ( $invoice->is_free_trial() && $subscription_item->has_free_trial() ) {
436
+    if ($invoice->is_free_trial() && $subscription_item->has_free_trial()) {
437 437
         $args['trial_period']      = $subscription_item->get_trial_period();
438 438
         $args['trial_interval']    = $subscription_item->get_trial_interval();
439 439
     } else {
@@ -441,58 +441,58 @@  discard block
 block discarded – undo
441 441
         $args['trial_interval']    = 0;
442 442
     }
443 443
     
444
-    return $invoice->update_subscription( $args );
444
+    return $invoice->update_subscription($args);
445 445
 }
446 446
 
447
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
448
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
447
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
448
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
449 449
         $error = false;
450 450
         
451
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
451
+        if (empty($post['authorizenet']['cc_owner'])) {
452 452
             $error = true;
453
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
453
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
454 454
         }
455
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
455
+        if (empty($post['authorizenet']['cc_number'])) {
456 456
             $error = true;
457
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
457
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
458 458
         }
459
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
459
+        if (empty($post['authorizenet']['cc_expire_month'])) {
460 460
             $error = true;
461
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
461
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
462 462
         }
463
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
463
+        if (empty($post['authorizenet']['cc_expire_year'])) {
464 464
             $error = true;
465
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
465
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
466 466
         }
467
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
467
+        if (empty($post['authorizenet']['cc_cvv2'])) {
468 468
             $error = true;
469
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
469
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
470 470
         }
471 471
         
472
-        if ( $error ) {
472
+        if ($error) {
473 473
             return;
474 474
         }
475 475
         
476 476
         $invoice = wpinv_get_invoice_cart();
477 477
         
478
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
479
-            $subscription_item = $invoice->get_recurring( true );
478
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
479
+            $subscription_item = $invoice->get_recurring(true);
480 480
             
481 481
             $interval   = $subscription_item->get_recurring_interval();
482 482
             $period     = $subscription_item->get_recurring_period();
483 483
             
484
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
485
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
484
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
485
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
486 486
             }
487 487
         }
488 488
     }
489 489
 }
490
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
490
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
491 491
 
492
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
493
-    $subscription_interval = absint( $subscription_interval );
492
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
493
+    $subscription_interval = absint($subscription_interval);
494 494
 
495
-    switch( $subscription_period ) {
495
+    switch ($subscription_period) {
496 496
         case 'W':
497 497
         case 'week':
498 498
         case 'weeks':
@@ -502,14 +502,14 @@  discard block
 block discarded – undo
502 502
         case 'M':
503 503
         case 'month':
504 504
         case 'months':
505
-            if ( $subscription_interval > 12 ) {
505
+            if ($subscription_interval > 12) {
506 506
                 $subscription_interval = 12;
507 507
             }
508 508
             
509 509
             $interval = $subscription_interval;
510 510
             $period   = 'months';
511 511
             
512
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
512
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
513 513
                 $interval = $subscription_interval * 30;
514 514
                 $period   = 'days';
515 515
             }
@@ -526,40 +526,40 @@  discard block
 block discarded – undo
526 526
             break;
527 527
     }
528 528
 
529
-    return compact( 'interval', 'period' );
529
+    return compact('interval', 'period');
530 530
 }
531 531
 
532 532
 function wpinv_authorizenet_process_ipn() {
533
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
533
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
534 534
         return;
535 535
     }
536 536
     
537
-    $subscription_id = intval( $_POST['x_subscription_id'] );
537
+    $subscription_id = intval($_POST['x_subscription_id']);
538 538
     
539
-    if ( $subscription_id ) {
540
-        $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
541
-        $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
542
-        $response_code  = intval( $_POST['x_response_code'] );
543
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
539
+    if ($subscription_id) {
540
+        $transaction_id = sanitize_text_field($_POST['x_trans_id']);
541
+        $renewal_amount = sanitize_text_field($_POST['x_amount']);
542
+        $response_code  = intval($_POST['x_response_code']);
543
+        $reason_code    = intval($_POST['x_response_reason_code']);
544 544
 
545
-        if ( 1 == $response_code ) {
545
+        if (1 == $response_code) {
546 546
             // Approved
547
-            do_action( 'wpinv_authorizenet_renewal_payment', $transaction_id );
548
-        } else if ( 2 == $response_code ) {
547
+            do_action('wpinv_authorizenet_renewal_payment', $transaction_id);
548
+        } else if (2 == $response_code) {
549 549
             // Declined
550
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
551
-            do_action( 'wpinv_authorizenet_renewal_error', $transaction_id );
552
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
550
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
551
+            do_action('wpinv_authorizenet_renewal_error', $transaction_id);
552
+        } else if (3 == $response_code || 8 == $reason_code) {
553 553
             // An expired card
554
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $transaction_id );
555
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $transaction_id );
554
+            do_action('wpinv_authorizenet_renewal_payment_failed', $transaction_id);
555
+            do_action('wpinv_authorizenet_renewal_payment_error', $transaction_id);
556 556
 
557 557
         } else {
558 558
             // Other Error
559
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
559
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
560 560
         }
561 561
         
562 562
         exit;
563 563
     }
564 564
 }
565
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
566 565
\ No newline at end of file
566
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
567 567
\ No newline at end of file
Please login to merge, or discard this patch.
templates/emails/wpinv-email-invoice-items.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // don't load directly
3
-if ( !defined('ABSPATH') )
3
+if (!defined('ABSPATH'))
4 4
     die('-1');
5 5
 
6 6
 global $wpinv_euvat, $ajax_cart_details;
@@ -11,158 +11,158 @@  discard block
 block discarded – undo
11 11
 $quantities_enabled = wpinv_item_quantities_enabled();
12 12
 $use_taxes          = wpinv_use_taxes();
13 13
 $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
14
-$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
15
-$tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
14
+$tax_label          = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
15
+$tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
16 16
 
17
-do_action( 'wpinv_before_email_items', $invoice ); ?>
17
+do_action('wpinv_before_email_items', $invoice); ?>
18 18
 <div id="wpinv-email-items">
19
-    <h3 class="wpinv-items-t"><?php echo apply_filters( 'wpinv_email_items_title', __( 'Items', 'invoicing' ) ); ?></h3>
19
+    <h3 class="wpinv-items-t"><?php echo apply_filters('wpinv_email_items_title', __('Items', 'invoicing')); ?></h3>
20 20
     <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
21 21
         <thead>
22 22
             <tr class="wpinv_cart_header_row">
23
-                <?php do_action( 'wpinv_email_items_table_header_first' ); ?>
24
-                <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
25
-                <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
26
-                <?php if ( $quantities_enabled ) { ?>
27
-                <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
23
+                <?php do_action('wpinv_email_items_table_header_first'); ?>
24
+                <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
25
+                <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
26
+                <?php if ($quantities_enabled) { ?>
27
+                <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
28 28
                 <?php } ?>
29
-                <?php if ( !$zero_tax && $use_taxes ) { ?>
29
+                <?php if (!$zero_tax && $use_taxes) { ?>
30 30
                 <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
31 31
                 <?php } ?>
32
-                <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
-                <?php do_action( 'wpinv_email_items_table_header_last' ); ?>
32
+                <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
33
+                <?php do_action('wpinv_email_items_table_header_last'); ?>
34 34
             </tr>
35 35
         </thead>
36 36
         <tbody>
37 37
             <?php
38
-                do_action( 'wpinv_email_items_before' );
39
-                if ( $cart_items ) {
40
-                    foreach ( $cart_items as $key => $item ) {
41
-                        $wpi_item = $item['id'] ? new WPInv_Item( $item['id'] ) : NULL;
38
+                do_action('wpinv_email_items_before');
39
+                if ($cart_items) {
40
+                    foreach ($cart_items as $key => $item) {
41
+                        $wpi_item = $item['id'] ? new WPInv_Item($item['id']) : NULL;
42 42
                     ?>
43
-                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
44
-                        <?php do_action( 'wpinv_email_items_table_body_first', $item ); ?>
43
+                    <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
44
+                        <?php do_action('wpinv_email_items_table_body_first', $item); ?>
45 45
                         <td class="wpinv_cart_item_name text-left">
46 46
                             <?php
47
-                                if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
47
+                                if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
48 48
                                     echo '<div class="wpinv_cart_item_image">';
49
-                                        echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
49
+                                        echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
50 50
                                     echo '</div>';
51 51
                                 }
52
-                                $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
52
+                                $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
53 53
                                 echo '<span class="wpinv_email_cart_item_title">' . $item_title . '</span>';
54 54
                                 
55 55
                                 $summary = '';
56
-                                if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) {
57
-                                    $post_link = '<a href="' . get_permalink( $item['meta']['post_id'] ) .'" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id']) ) . '</a>';
58
-                                    $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
56
+                                if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) {
57
+                                    $post_link = '<a href="' . get_permalink($item['meta']['post_id']) . '" target="_blank">' . (!empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id'])) . '</a>';
58
+                                    $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
59 59
                                 }
60 60
                                 
61
-                                $summary = apply_filters( 'wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice );
62
-                                if ( !empty( $summary ) ) {
61
+                                $summary = apply_filters('wpinv_email_invoice_line_item_summary', $summary, $item, $wpi_item, $invoice);
62
+                                if (!empty($summary)) {
63 63
                                     echo '<p class="small">' . $summary . '</p>';
64 64
                                 }
65 65
     
66
-                                do_action( 'wpinv_email_cart_item_title_after', $item, $key );
66
+                                do_action('wpinv_email_cart_item_title_after', $item, $key);
67 67
                             ?>
68 68
                         </td>
69 69
                         <td class="wpinv_cart_item_price text-right">
70 70
                             <?php 
71
-                            echo wpinv_cart_item_price( $item );
72
-                            do_action( 'wpinv_email_cart_item_price_after', $item, $key );
71
+                            echo wpinv_cart_item_price($item);
72
+                            do_action('wpinv_email_cart_item_price_after', $item, $key);
73 73
                             ?>
74 74
                         </td>
75
-                        <?php if ( $quantities_enabled ) { ?>
75
+                        <?php if ($quantities_enabled) { ?>
76 76
                         <td class="wpinv_cart_item_qty text-right">
77 77
                             <?php
78
-                            echo wpinv_get_cart_item_quantity( $item );
79
-                            do_action( 'wpinv_email_item_quantitiy', $item, $key );
78
+                            echo wpinv_get_cart_item_quantity($item);
79
+                            do_action('wpinv_email_item_quantitiy', $item, $key);
80 80
                             ?>
81 81
                         </td>
82 82
                         <?php } ?>
83
-                        <?php if ( !$zero_tax && $use_taxes ) { ?>
83
+                        <?php if (!$zero_tax && $use_taxes) { ?>
84 84
                         <td class="wpinv_cart_item_tax text-right">
85 85
                             <?php
86
-                            echo wpinv_cart_item_tax( $item );
87
-                            do_action( 'wpinv_email_item_tax', $item, $key );
86
+                            echo wpinv_cart_item_tax($item);
87
+                            do_action('wpinv_email_item_tax', $item, $key);
88 88
                             ?>
89 89
                         </td>
90 90
                         <?php } ?>
91 91
                         <td class="wpinv_cart_item_subtotal text-right">
92 92
                             <?php
93
-                            echo wpinv_cart_item_subtotal( $item );
94
-                            do_action( 'wpinv_email_item_subtotal', $item, $key );
93
+                            echo wpinv_cart_item_subtotal($item);
94
+                            do_action('wpinv_email_item_subtotal', $item, $key);
95 95
                             ?>
96 96
                         </td>
97
-                        <?php do_action( 'wpinv_email_items_table_body_last', $item, $key ); ?>
97
+                        <?php do_action('wpinv_email_items_table_body_last', $item, $key); ?>
98 98
                     </tr>
99 99
                 <?php } ?>
100 100
             <?php } ?>
101
-            <?php do_action( 'wpinv_email_items_middle' ); ?>
102
-            <?php do_action( 'wpinv_email_items_after' ); ?>
101
+            <?php do_action('wpinv_email_items_middle'); ?>
102
+            <?php do_action('wpinv_email_items_after'); ?>
103 103
         </tbody>
104 104
         <tfoot>
105
-            <?php $cart_columns = wpinv_checkout_cart_columns(); if ( $zero_tax && $use_taxes ) { $cart_columns--; } ?>
106
-            <?php if ( has_action( 'wpinv_email_footer_buttons' ) ) { ?>
105
+            <?php $cart_columns = wpinv_checkout_cart_columns(); if ($zero_tax && $use_taxes) { $cart_columns--; } ?>
106
+            <?php if (has_action('wpinv_email_footer_buttons')) { ?>
107 107
                 <tr class="wpinv_cart_footer_row">
108
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
109
-                    <td colspan="<?php echo ( $cart_columns ); ?>">
110
-                        <?php do_action( 'wpinv_email_footer_buttons' ); ?>
108
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
109
+                    <td colspan="<?php echo ($cart_columns); ?>">
110
+                        <?php do_action('wpinv_email_footer_buttons'); ?>
111 111
                     </td>
112
-                    <?php do_action( 'wpinv_email_items_table_buttons_first', $cart_items ); ?>
112
+                    <?php do_action('wpinv_email_items_table_buttons_first', $cart_items); ?>
113 113
                 </tr>
114 114
             <?php } ?>
115 115
 
116
-            <?php if ( !$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed() ) { ?>
116
+            <?php if (!$zero_tax && $use_taxes && !wpinv_prices_include_tax() && wpinv_is_cart_taxed()) { ?>
117 117
                 <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row">
118
-                    <?php do_action( 'wpinv_email_items_table_subtotal_first', $cart_items ); ?>
119
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
120
-                        <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
118
+                    <?php do_action('wpinv_email_items_table_subtotal_first', $cart_items); ?>
119
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
120
+                        <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
121 121
                     </td>
122 122
                     <td class="wpinv_cart_subtotal text-right">
123
-                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal( true ); ?></span>
123
+                        <span class="wpinv_cart_subtotal_amount bold"><?php echo $invoice->get_subtotal(true); ?></span>
124 124
                     </td>
125
-                    <?php do_action( 'wpinv_email_items_table_subtotal_last', $cart_items, $invoice ); ?>
125
+                    <?php do_action('wpinv_email_items_table_subtotal_last', $cart_items, $invoice); ?>
126 126
                 </tr>
127 127
             <?php } ?>
128 128
             
129
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
129
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
130 130
                 <tr class="wpinv_cart_footer_row wpinv_cart_discount_row">
131
-                    <?php do_action( 'wpinv_receipt_items_table_discount_first', $cart_items, $invoice ); ?>
132
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_discount_label text-right">
133
-                        <strong><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</strong>
131
+                    <?php do_action('wpinv_receipt_items_table_discount_first', $cart_items, $invoice); ?>
132
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_discount_label text-right">
133
+                        <strong><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</strong>
134 134
                     </td>
135 135
                     <td class="wpinv_cart_discount text-right">
136
-                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount( $invoice_id, true, true ); ?></span>
136
+                        <span class="wpinv_cart_discount_amount"><?php echo wpinv_discount($invoice_id, true, true); ?></span>
137 137
                     </td>
138
-                    <?php do_action( 'wpinv_receipt_items_table_discount_last', $cart_items, $invoice ); ?>
138
+                    <?php do_action('wpinv_receipt_items_table_discount_last', $cart_items, $invoice); ?>
139 139
                 </tr>
140 140
             <?php } ?>
141 141
 
142
-            <?php if ( !$zero_tax && $use_taxes && wpinv_is_cart_taxed() ) { ?>
142
+            <?php if (!$zero_tax && $use_taxes && wpinv_is_cart_taxed()) { ?>
143 143
                 <tr class="wpinv_cart_footer_row wpinv_cart_tax_row">
144
-                    <?php do_action( 'wpinv_email_items_table_tax_first', $cart_items, $invoice ); ?>
145
-                    <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
144
+                    <?php do_action('wpinv_email_items_table_tax_first', $cart_items, $invoice); ?>
145
+                    <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
146 146
                         <strong><?php echo $tax_label; ?>:</strong>
147 147
                     </td>
148 148
                     <td class="wpinv_cart_tax text-right">
149
-                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax( true ); ?></span>
149
+                        <span class="wpinv_cart_tax_amount"><?php echo $invoice->get_tax(true); ?></span>
150 150
                     </td>
151
-                    <?php do_action( 'wpinv_email_items_table_tax_last', $cart_items, $invoice ); ?>
151
+                    <?php do_action('wpinv_email_items_table_tax_last', $cart_items, $invoice); ?>
152 152
                 </tr>
153 153
             <?php } ?>
154 154
 
155 155
             <tr class="wpinv_cart_footer_row">
156
-                <?php do_action( 'wpinv_email_items_table_footer_first', $cart_items, $invoice ); ?>
157
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
158
-                    <?php echo apply_filters( 'wpinv_email_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
156
+                <?php do_action('wpinv_email_items_table_footer_first', $cart_items, $invoice); ?>
157
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
158
+                    <?php echo apply_filters('wpinv_email_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
159 159
                 </td>
160 160
                 <td class="wpinv_cart_total text-right">
161
-                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total( true ); ?></span>
161
+                    <span class="wpinv_cart_amount bold"><?php echo $invoice->get_total(true); ?></span>
162 162
                 </td>
163
-                <?php do_action( 'wpinv_email_items_table_footer_last', $cart_items, $invoice ); ?>
163
+                <?php do_action('wpinv_email_items_table_footer_last', $cart_items, $invoice); ?>
164 164
             </tr>
165 165
         </tfoot>
166 166
     </table>
167 167
 </div>
168
-<?php do_action( 'wpinv_after_email_items', $invoice ); ?>
169 168
\ No newline at end of file
169
+<?php do_action('wpinv_after_email_items', $invoice); ?>
170 170
\ No newline at end of file
Please login to merge, or discard this patch.
templates/wpinv-checkout-cart.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -5,140 +5,140 @@
 block discarded – undo
5 5
 
6 6
 global $wpinv_euvat, $post, $ajax_cart_details, $wpi_cart_columns, $wpi_session;
7 7
 $invoice            = wpinv_get_invoice_cart();
8
-$cart_items         = !empty( $ajax_cart_details ) ? $ajax_cart_details : wpinv_get_cart_content_details();
8
+$cart_items         = !empty($ajax_cart_details) ? $ajax_cart_details : wpinv_get_cart_content_details();
9 9
 $quantities_enabled = wpinv_item_quantities_enabled();
10 10
 $use_taxes          = wpinv_use_taxes();
11 11
 $tax_label          = $wpinv_euvat->tax_label();
12
-$tax_title          = $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
12
+$tax_title          = $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
13 13
 ?>
14 14
 <table id="wpinv_checkout_cart" class="table table-bordered table-hover">
15 15
     <thead>
16 16
         <tr class="wpinv_cart_header_row">
17
-            <?php do_action( 'wpinv_checkout_table_header_first' ); ?>
18
-            <th class="wpinv_cart_item_name text-left"><?php _e( 'Item Name', 'invoicing' ); ?></th>
19
-            <th class="wpinv_cart_item_price text-right"><?php _e( 'Item Price', 'invoicing' ); ?></th>
20
-            <?php if ( $quantities_enabled ) { ?>
21
-            <th class="wpinv_cart_item_qty text-right"><?php _e( 'Qty', 'invoicing' ); ?></th>
17
+            <?php do_action('wpinv_checkout_table_header_first'); ?>
18
+            <th class="wpinv_cart_item_name text-left"><?php _e('Item Name', 'invoicing'); ?></th>
19
+            <th class="wpinv_cart_item_price text-right"><?php _e('Item Price', 'invoicing'); ?></th>
20
+            <?php if ($quantities_enabled) { ?>
21
+            <th class="wpinv_cart_item_qty text-right"><?php _e('Qty', 'invoicing'); ?></th>
22 22
             <?php } ?>
23
-            <?php if ( $use_taxes ) { ?>
23
+            <?php if ($use_taxes) { ?>
24 24
             <th class="wpinv_cart_item_tax text-right"><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></th>
25 25
             <?php } ?>
26
-            <th class="wpinv_cart_item_subtotal text-right"><?php echo __( 'Item Total', 'invoicing' ) . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
-            <?php do_action( 'wpinv_checkout_table_header_last' ); ?>
26
+            <th class="wpinv_cart_item_subtotal text-right"><?php echo __('Item Total', 'invoicing') . ' <span class="normal small">' . $tax_title . '<span>'; ?></th>
27
+            <?php do_action('wpinv_checkout_table_header_last'); ?>
28 28
         </tr>
29 29
     </thead>
30 30
     <tbody>
31 31
         <?php
32
-            do_action( 'wpinv_cart_items_before' );
32
+            do_action('wpinv_cart_items_before');
33 33
             
34
-            if ( $cart_items ) {
35
-                foreach ( $cart_items as $key => $item ) {
36
-                    $wpi_item = !empty( $item['id'] ) ? new WPInv_Item( $item['id'] ) : NULL;
34
+            if ($cart_items) {
35
+                foreach ($cart_items as $key => $item) {
36
+                    $wpi_item = !empty($item['id']) ? new WPInv_Item($item['id']) : NULL;
37 37
                 ?>
38
-                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr( $key ) . '_' . esc_attr( $item['id'] ); ?>" data-item-id="<?php echo esc_attr( $item['id'] ); ?>">
39
-                    <?php do_action( 'wpinv_checkout_table_body_first', $item ); ?>
38
+                <tr class="wpinv_cart_item" id="wpinv_cart_item_<?php echo esc_attr($key) . '_' . esc_attr($item['id']); ?>" data-item-id="<?php echo esc_attr($item['id']); ?>">
39
+                    <?php do_action('wpinv_checkout_table_body_first', $item); ?>
40 40
                     <td class="wpinv_cart_item_name text-left">
41 41
                         <?php
42
-                            if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $item['id'] ) ) {
42
+                            if (current_theme_supports('post-thumbnails') && has_post_thumbnail($item['id'])) {
43 43
                                 echo '<div class="wpinv_cart_item_image">';
44
-                                    echo get_the_post_thumbnail( $item['id'], apply_filters( 'wpinv_checkout_image_size', array( 25,25 ) ) );
44
+                                    echo get_the_post_thumbnail($item['id'], apply_filters('wpinv_checkout_image_size', array(25, 25)));
45 45
                                 echo '</div>';
46 46
                             }
47
-                            $item_title = esc_html( wpinv_get_cart_item_name( $item ) ) . wpinv_get_item_suffix( $wpi_item );
47
+                            $item_title = esc_html(wpinv_get_cart_item_name($item)) . wpinv_get_item_suffix($wpi_item);
48 48
                             echo '<span class="wpinv_checkout_cart_item_title">' . $item_title . '</span>';
49
-                            if ( !empty( $wpi_item ) && $wpi_item->is_package() && !empty( $item['meta']['post_id'] ) ) {
50
-                                $post_link = !empty( $item['meta']['invoice_title'] ) ? $item['meta']['invoice_title'] : get_the_title( $item['meta']['post_id'] );
51
-                                $summary = wp_sprintf( __( '%s: %s', 'invoicing' ), $wpi_item->get_custom_singular_name(), $post_link );
52
-                                echo '<small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
49
+                            if (!empty($wpi_item) && $wpi_item->is_package() && !empty($item['meta']['post_id'])) {
50
+                                $post_link = !empty($item['meta']['invoice_title']) ? $item['meta']['invoice_title'] : get_the_title($item['meta']['post_id']);
51
+                                $summary = wp_sprintf(__('%s: %s', 'invoicing'), $wpi_item->get_custom_singular_name(), $post_link);
52
+                                echo '<small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
53 53
                             }
54
-                            do_action( 'wpinv_checkout_cart_item_title_after', $item, $key );
54
+                            do_action('wpinv_checkout_cart_item_title_after', $item, $key);
55 55
                         ?>
56 56
                     </td>
57 57
                     <td class="wpinv_cart_item_price text-right">
58 58
                         <?php 
59
-                        echo wpinv_cart_item_price( $item );
60
-                        do_action( 'wpinv_checkout_cart_item_price_after', $item, $key );
59
+                        echo wpinv_cart_item_price($item);
60
+                        do_action('wpinv_checkout_cart_item_price_after', $item, $key);
61 61
                         ?>
62 62
                     </td>
63
-                    <?php if ( $quantities_enabled ) { ?>
63
+                    <?php if ($quantities_enabled) { ?>
64 64
                     <td class="wpinv_cart_item_qty text-right">
65 65
                         <?php
66
-                        echo wpinv_get_cart_item_quantity( $item );
67
-                        do_action( 'wpinv_cart_item_quantitiy', $item, $key );
66
+                        echo wpinv_get_cart_item_quantity($item);
67
+                        do_action('wpinv_cart_item_quantitiy', $item, $key);
68 68
                         ?>
69 69
                     </td>
70 70
                     <?php } ?>
71
-                    <?php if ( $use_taxes ) { ?>
71
+                    <?php if ($use_taxes) { ?>
72 72
                     <td class="wpinv_cart_item_tax text-right">
73 73
                         <?php
74
-                        echo wpinv_cart_item_tax( $item );
74
+                        echo wpinv_cart_item_tax($item);
75 75
                         //echo wpinv_get_cart_item_tax( $wpi_item->ID, $subtotal = '', $options = array() );
76
-                        do_action( 'wpinv_cart_item_tax', $item, $key );
76
+                        do_action('wpinv_cart_item_tax', $item, $key);
77 77
                         ?>
78 78
                     </td>
79 79
                     <?php } ?>
80 80
                     <td class="wpinv_cart_item_subtotal text-right">
81 81
                         <?php
82
-                        echo wpinv_cart_item_subtotal( $item );
83
-                        do_action( 'wpinv_cart_item_subtotal', $item, $key );
82
+                        echo wpinv_cart_item_subtotal($item);
83
+                        do_action('wpinv_cart_item_subtotal', $item, $key);
84 84
                         ?>
85 85
                     </td>
86
-                    <?php do_action( 'wpinv_checkout_table_body_last', $item, $key ); ?>
86
+                    <?php do_action('wpinv_checkout_table_body_last', $item, $key); ?>
87 87
                 </tr>
88 88
             <?php } ?>
89 89
         <?php } ?>
90
-        <?php do_action( 'wpinv_cart_items_middle' ); ?>
91
-        <?php do_action( 'wpinv_cart_items_after' ); ?>
90
+        <?php do_action('wpinv_cart_items_middle'); ?>
91
+        <?php do_action('wpinv_cart_items_after'); ?>
92 92
     </tbody>
93 93
     <tfoot>
94 94
         <?php $cart_columns = wpinv_checkout_cart_columns(); ?>
95
-        <?php if ( has_action( 'wpinv_cart_footer_buttons' ) ) { ?>
95
+        <?php if (has_action('wpinv_cart_footer_buttons')) { ?>
96 96
             <tr class="wpinv_cart_footer_row">
97
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
98
-                <td colspan="<?php echo ( $cart_columns ); ?>">
99
-                    <?php do_action( 'wpinv_cart_footer_buttons' ); ?>
97
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
98
+                <td colspan="<?php echo ($cart_columns); ?>">
99
+                    <?php do_action('wpinv_cart_footer_buttons'); ?>
100 100
                 </td>
101
-                <?php do_action( 'wpinv_checkout_table_buttons_first', $cart_items ); ?>
101
+                <?php do_action('wpinv_checkout_table_buttons_first', $cart_items); ?>
102 102
             </tr>
103 103
         <?php } ?>
104 104
 
105
-        <?php if ( $use_taxes && !wpinv_prices_include_tax() ) { ?>
106
-            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if ( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
107
-                <?php do_action( 'wpinv_checkout_table_subtotal_first', $cart_items ); ?>
108
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_subtotal_label text-right">
109
-                    <strong><?php _e( 'Sub-Total', 'invoicing' ); ?>:</strong>
105
+        <?php if ($use_taxes && !wpinv_prices_include_tax()) { ?>
106
+            <tr class="wpinv_cart_footer_row wpinv_cart_subtotal_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
107
+                <?php do_action('wpinv_checkout_table_subtotal_first', $cart_items); ?>
108
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_subtotal_label text-right">
109
+                    <strong><?php _e('Sub-Total', 'invoicing'); ?>:</strong>
110 110
                 </td>
111 111
                 <td class="wpinv_cart_subtotal text-right">
112
-                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal( $cart_items ); ?></span>
112
+                    <span class="wpinv_cart_subtotal_amount bold"><?php echo wpinv_cart_subtotal($cart_items); ?></span>
113 113
                 </td>
114
-                <?php do_action( 'wpinv_checkout_table_subtotal_last', $cart_items ); ?>
114
+                <?php do_action('wpinv_checkout_table_subtotal_last', $cart_items); ?>
115 115
             </tr>
116 116
         <?php } ?>
117 117
         
118
-        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html( $cart_items ); ?>
118
+        <?php $wpi_cart_columns = $cart_columns - 1; wpinv_cart_discounts_html($cart_items); ?>
119 119
 
120
-        <?php if ( $use_taxes ) { ?>
121
-            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if( !wpinv_is_cart_taxed() ) echo ' style="display:none;"'; ?>>
122
-                <?php do_action( 'wpinv_checkout_table_tax_first' ); ?>
123
-                <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_tax_label text-right">
120
+        <?php if ($use_taxes) { ?>
121
+            <tr class="wpinv_cart_footer_row wpinv_cart_tax_row"<?php if (!wpinv_is_cart_taxed()) echo ' style="display:none;"'; ?>>
122
+                <?php do_action('wpinv_checkout_table_tax_first'); ?>
123
+                <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_tax_label text-right">
124 124
                     <strong><?php echo $tax_label; ?>:</strong>
125 125
                 </td>
126 126
                 <td class="wpinv_cart_tax text-right">
127
-                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax( $cart_items ); ?>"><?php echo esc_html( wpinv_cart_tax( $cart_items ) ); ?></span>
127
+                    <span class="wpinv_cart_tax_amount" data-tax="<?php echo wpinv_get_cart_tax($cart_items); ?>"><?php echo esc_html(wpinv_cart_tax($cart_items)); ?></span>
128 128
                 </td>
129
-                <?php do_action( 'wpinv_checkout_table_tax_last' ); ?>
129
+                <?php do_action('wpinv_checkout_table_tax_last'); ?>
130 130
             </tr>
131 131
         <?php } ?>
132 132
 
133 133
         <tr class="wpinv_cart_footer_row wpinv_cart_total_row">
134
-            <?php do_action( 'wpinv_checkout_table_footer_first' ); ?>
135
-            <td colspan="<?php echo ( $cart_columns - 1 ); ?>" class="wpinv_cart_total_label text-right">
136
-                <?php echo apply_filters( 'wpinv_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?>
134
+            <?php do_action('wpinv_checkout_table_footer_first'); ?>
135
+            <td colspan="<?php echo ($cart_columns - 1); ?>" class="wpinv_cart_total_label text-right">
136
+                <?php echo apply_filters('wpinv_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?>
137 137
             </td>
138 138
             <td class="wpinv_cart_total text-right">
139
-                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total( $cart_items ); ?>" data-total="<?php echo wpinv_get_cart_total( NULL, NULL, $invoice ); ?>"><?php wpinv_cart_total( $cart_items, true, $invoice ); ?></span>
139
+                <span class="wpinv_cart_amount bold" data-subtotal="<?php echo wpinv_get_cart_total($cart_items); ?>" data-total="<?php echo wpinv_get_cart_total(NULL, NULL, $invoice); ?>"><?php wpinv_cart_total($cart_items, true, $invoice); ?></span>
140 140
             </td>
141
-            <?php do_action( 'wpinv_checkout_table_footer_last' ); ?>
141
+            <?php do_action('wpinv_checkout_table_footer_last'); ?>
142 142
         </tr>
143 143
     </tfoot>
144 144
 </table>
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 2 patches
Doc Comments   +28 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,6 +31,9 @@  discard block
 block discarded – undo
31 31
     return apply_filters( 'wpinv_get_ip', $ip );
32 32
 }
33 33
 
34
+/**
35
+ * @return string
36
+ */
34 37
 function wpinv_get_user_agent() {
35 38
     if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36 39
         $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
@@ -41,6 +44,9 @@  discard block
 block discarded – undo
41 44
     return apply_filters( 'wpinv_get_user_agent', $user_agent );
42 45
 }
43 46
 
47
+/**
48
+ * @param integer $decimals
49
+ */
44 50
 function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
45 51
     $is_negative   = false;
46 52
     $thousands_sep = wpinv_thousands_separator();
@@ -79,6 +85,9 @@  discard block
 block discarded – undo
79 85
 }
80 86
 add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
81 87
 
88
+/**
89
+ * @param integer $decimals
90
+ */
82 91
 function wpinv_round_amount( $amount, $decimals = NULL ) {
83 92
     if ( $decimals === NULL ) {
84 93
         $decimals = wpinv_decimals();
@@ -117,6 +126,9 @@  discard block
 block discarded – undo
117 126
     return $status;
118 127
 }
119 128
 
129
+/**
130
+ * @return string
131
+ */
120 132
 function wpinv_get_currency() {
121 133
     $currency = wpinv_get_option( 'currency', 'USD' );
122 134
     
@@ -187,6 +199,9 @@  discard block
 block discarded – undo
187 199
     return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
188 200
 }
189 201
 
202
+/**
203
+ * @return string
204
+ */
190 205
 function wpinv_currency_position() {
191 206
     $position = wpinv_get_option( 'currency_position', 'left' );
192 207
     
@@ -315,6 +330,9 @@  discard block
 block discarded – undo
315 330
     return $price;
316 331
 }
317 332
 
333
+/**
334
+ * @return string
335
+ */
318 336
 function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
319 337
     $thousands_sep = wpinv_thousands_separator();
320 338
     $decimal_sep   = wpinv_decimal_separator();
@@ -365,6 +383,9 @@  discard block
 block discarded – undo
365 383
     return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
366 384
 }
367 385
 
386
+/**
387
+ * @return string
388
+ */
368 389
 function wpinv_get_file_extension( $str ) {
369 390
     $parts = explode( '.', $str );
370 391
     return end( $parts );
@@ -569,6 +590,9 @@  discard block
 block discarded – undo
569 590
     return strlen( $str );
570 591
 }
571 592
 
593
+/**
594
+ * @param string $str
595
+ */
572 596
 function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
573 597
     if ( function_exists( 'mb_strtolower' ) ) {
574 598
         return mb_strtolower( $str, $encoding );
@@ -577,6 +601,9 @@  discard block
 block discarded – undo
577 601
     return strtolower( $str );
578 602
 }
579 603
 
604
+/**
605
+ * @param string $str
606
+ */
580 607
 function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
581 608
     if ( function_exists( 'mb_strtoupper' ) ) {
582 609
         return mb_strtoupper( $str, $encoding );
@@ -654,7 +681,7 @@  discard block
 block discarded – undo
654 681
  *
655 682
  * @param string $str The string being decoded.
656 683
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
657
- * @return string The width of string.
684
+ * @return integer The width of string.
658 685
  */
659 686
 function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
660 687
     if ( function_exists( 'mb_strwidth' ) ) {
Please login to merge, or discard this patch.
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,89 +7,89 @@  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_item_quantities_enabled() {
15
-    $ret = wpinv_get_option( 'item_quantities', true );
15
+    $ret = wpinv_get_option('item_quantities', true);
16 16
     
17
-    return (bool) apply_filters( 'wpinv_item_quantities_enabled', $ret );
17
+    return (bool)apply_filters('wpinv_item_quantities_enabled', $ret);
18 18
 }
19 19
 
20 20
 function wpinv_get_ip() {
21 21
     $ip = '127.0.0.1';
22 22
 
23
-    if ( !empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
24
-        $ip = sanitize_text_field( $_SERVER['HTTP_CLIENT_IP'] );
25
-    } elseif ( !empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
26
-        $ip = sanitize_text_field( $_SERVER['HTTP_X_FORWARDED_FOR'] );
27
-    } elseif( !empty( $_SERVER['REMOTE_ADDR'] ) ) {
28
-        $ip = sanitize_text_field( $_SERVER['REMOTE_ADDR'] );
23
+    if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
24
+        $ip = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
25
+    } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
26
+        $ip = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
27
+    } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
28
+        $ip = sanitize_text_field($_SERVER['REMOTE_ADDR']);
29 29
     }
30 30
     
31
-    return apply_filters( 'wpinv_get_ip', $ip );
31
+    return apply_filters('wpinv_get_ip', $ip);
32 32
 }
33 33
 
34 34
 function wpinv_get_user_agent() {
35
-    if ( ! empty( $_SERVER['HTTP_USER_AGENT'] ) ) {
36
-        $user_agent = sanitize_text_field( $_SERVER['HTTP_USER_AGENT'] );
35
+    if (!empty($_SERVER['HTTP_USER_AGENT'])) {
36
+        $user_agent = sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
37 37
     } else {
38 38
         $user_agent = '';
39 39
     }
40 40
     
41
-    return apply_filters( 'wpinv_get_user_agent', $user_agent );
41
+    return apply_filters('wpinv_get_user_agent', $user_agent);
42 42
 }
43 43
 
44
-function wpinv_sanitize_amount( $amount, $decimals = NULL ) {
44
+function wpinv_sanitize_amount($amount, $decimals = NULL) {
45 45
     $is_negative   = false;
46 46
     $thousands_sep = wpinv_thousands_separator();
47 47
     $decimal_sep   = wpinv_decimal_separator();
48
-    if ( $decimals === NULL ) {
48
+    if ($decimals === NULL) {
49 49
         $decimals = wpinv_decimals();
50 50
     }
51 51
 
52 52
     // Sanitize the amount
53
-    if ( $decimal_sep == ',' && false !== ( $found = strpos( $amount, $decimal_sep ) ) ) {
54
-        if ( ( $thousands_sep == '.' || $thousands_sep == ' ' ) && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
55
-            $amount = str_replace( $thousands_sep, '', $amount );
56
-        } elseif( empty( $thousands_sep ) && false !== ( $found = strpos( $amount, '.' ) ) ) {
57
-            $amount = str_replace( '.', '', $amount );
53
+    if ($decimal_sep == ',' && false !== ($found = strpos($amount, $decimal_sep))) {
54
+        if (($thousands_sep == '.' || $thousands_sep == ' ') && false !== ($found = strpos($amount, $thousands_sep))) {
55
+            $amount = str_replace($thousands_sep, '', $amount);
56
+        } elseif (empty($thousands_sep) && false !== ($found = strpos($amount, '.'))) {
57
+            $amount = str_replace('.', '', $amount);
58 58
         }
59 59
 
60
-        $amount = str_replace( $decimal_sep, '.', $amount );
61
-    } elseif( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
62
-        $amount = str_replace( $thousands_sep, '', $amount );
60
+        $amount = str_replace($decimal_sep, '.', $amount);
61
+    } elseif ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
62
+        $amount = str_replace($thousands_sep, '', $amount);
63 63
     }
64 64
 
65
-    if( $amount < 0 ) {
65
+    if ($amount < 0) {
66 66
         $is_negative = true;
67 67
     }
68 68
 
69
-    $amount   = preg_replace( '/[^0-9\.]/', '', $amount );
69
+    $amount   = preg_replace('/[^0-9\.]/', '', $amount);
70 70
 
71
-    $decimals = apply_filters( 'wpinv_sanitize_amount_decimals', absint( $decimals ), $amount );
72
-    $amount   = number_format( (double) $amount, absint( $decimals ), '.', '' );
71
+    $decimals = apply_filters('wpinv_sanitize_amount_decimals', absint($decimals), $amount);
72
+    $amount   = number_format((double)$amount, absint($decimals), '.', '');
73 73
 
74
-    if( $is_negative ) {
74
+    if ($is_negative) {
75 75
         $amount *= -1;
76 76
     }
77 77
 
78
-    return apply_filters( 'wpinv_sanitize_amount', $amount, $decimals );
78
+    return apply_filters('wpinv_sanitize_amount', $amount, $decimals);
79 79
 }
80
-add_filter( 'wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
80
+add_filter('wpinv_sanitize_amount_decimals', 'wpinv_currency_decimal_filter', 10, 1);
81 81
 
82
-function wpinv_round_amount( $amount, $decimals = NULL ) {
83
-    if ( $decimals === NULL ) {
82
+function wpinv_round_amount($amount, $decimals = NULL) {
83
+    if ($decimals === NULL) {
84 84
         $decimals = wpinv_decimals();
85 85
     }
86 86
     
87
-    $amount = round( (double)$amount, wpinv_currency_decimal_filter( absint( $decimals ) ) );
87
+    $amount = round((double)$amount, wpinv_currency_decimal_filter(absint($decimals)));
88 88
 
89
-    return apply_filters( 'wpinv_round_amount', $amount, $decimals );
89
+    return apply_filters('wpinv_round_amount', $amount, $decimals);
90 90
 }
91 91
 
92
-function wpinv_get_invoice_statuses( $trashed = false ) {
92
+function wpinv_get_invoice_statuses($trashed = false) {
93 93
     global $post;
94 94
     $invoice_statuses = array();
95 95
     $invoice_statuses = array(
@@ -103,32 +103,32 @@  discard block
 block discarded – undo
103 103
         'wpi-renewal' => __('Renewal Payment', 'invoicing')
104 104
     );
105 105
     
106
-    if ( $trashed ) {
107
-        $invoice_statuses['trash'] = __( 'Trash', 'invoicing' );
106
+    if ($trashed) {
107
+        $invoice_statuses['trash'] = __('Trash', 'invoicing');
108 108
     }
109 109
 
110
-    return apply_filters( 'wpinv_statuses', $invoice_statuses );
110
+    return apply_filters('wpinv_statuses', $invoice_statuses);
111 111
 }
112 112
 
113
-function wpinv_status_nicename( $status ) {
113
+function wpinv_status_nicename($status) {
114 114
     $statuses = wpinv_get_invoice_statuses();
115
-    $status   = isset( $statuses[$status] ) ? $statuses[$status] : __( $status, 'invoicing' );
115
+    $status   = isset($statuses[$status]) ? $statuses[$status] : __($status, 'invoicing');
116 116
 
117 117
     return $status;
118 118
 }
119 119
 
120 120
 function wpinv_get_currency() {
121
-    $currency = wpinv_get_option( 'currency', 'USD' );
121
+    $currency = wpinv_get_option('currency', 'USD');
122 122
     
123
-    return apply_filters( 'wpinv_currency', $currency );
123
+    return apply_filters('wpinv_currency', $currency);
124 124
 }
125 125
 
126
-function wpinv_currency_symbol( $currency = '' ) {
127
-    if ( empty( $currency ) ) {
126
+function wpinv_currency_symbol($currency = '') {
127
+    if (empty($currency)) {
128 128
         $currency = wpinv_get_currency();
129 129
     }
130 130
     
131
-    $symbols = apply_filters( 'wpinv_currency_symbols', array(
131
+    $symbols = apply_filters('wpinv_currency_symbols', array(
132 132
         'AED' => 'د.إ',
133 133
         'ARS' => '&#36;',
134 134
         'AUD' => '&#36;',
@@ -180,78 +180,78 @@  discard block
 block discarded – undo
180 180
         'USD' => '&#36;',
181 181
         'VND' => '&#8363;',
182 182
         'ZAR' => '&#82;',
183
-    ) );
183
+    ));
184 184
 
185
-    $currency_symbol = isset( $symbols[$currency] ) ? $symbols[$currency] : '&#36;';
185
+    $currency_symbol = isset($symbols[$currency]) ? $symbols[$currency] : '&#36;';
186 186
 
187
-    return apply_filters( 'wpinv_currency_symbol', $currency_symbol, $currency );
187
+    return apply_filters('wpinv_currency_symbol', $currency_symbol, $currency);
188 188
 }
189 189
 
190 190
 function wpinv_currency_position() {
191
-    $position = wpinv_get_option( 'currency_position', 'left' );
191
+    $position = wpinv_get_option('currency_position', 'left');
192 192
     
193
-    return apply_filters( 'wpinv_currency_position', $position );
193
+    return apply_filters('wpinv_currency_position', $position);
194 194
 }
195 195
 
196 196
 function wpinv_thousands_separator() {
197
-    $thousand_sep = wpinv_get_option( 'thousands_separator', ',' );
197
+    $thousand_sep = wpinv_get_option('thousands_separator', ',');
198 198
     
199
-    return apply_filters( 'wpinv_thousands_separator', $thousand_sep );
199
+    return apply_filters('wpinv_thousands_separator', $thousand_sep);
200 200
 }
201 201
 
202 202
 function wpinv_decimal_separator() {
203
-    $decimal_sep = wpinv_get_option( 'decimal_separator', '.' );
203
+    $decimal_sep = wpinv_get_option('decimal_separator', '.');
204 204
     
205
-    return apply_filters( 'wpinv_decimal_separator', $decimal_sep );
205
+    return apply_filters('wpinv_decimal_separator', $decimal_sep);
206 206
 }
207 207
 
208 208
 function wpinv_decimals() {
209
-    $decimals = apply_filters( 'wpinv_decimals', wpinv_get_option( 'decimals', 2 ) );
209
+    $decimals = apply_filters('wpinv_decimals', wpinv_get_option('decimals', 2));
210 210
     
211
-    return absint( $decimals );
211
+    return absint($decimals);
212 212
 }
213 213
 
214 214
 function wpinv_get_currencies() {
215 215
     $currencies = array(
216
-        'USD'  => __( 'US Dollars (&#36;)', 'invoicing' ),
217
-        'EUR'  => __( 'Euros (&euro;)', 'invoicing' ),
218
-        'GBP'  => __( 'Pounds Sterling (&pound;)', 'invoicing' ),
219
-        'AUD'  => __( 'Australian Dollars (&#36;)', 'invoicing' ),
220
-        'BRL'  => __( 'Brazilian Real (R&#36;)', 'invoicing' ),
221
-        'CAD'  => __( 'Canadian Dollars (&#36;)', 'invoicing' ),
222
-        'CLP'  => __( 'Chilean Peso (&#36;)', 'invoicing' ),
223
-        'CNY'  => __( 'Chinese Yuan (&yen;)', 'invoicing' ),
224
-        'CZK'  => __( 'Czech Koruna (&#75;&#269;)', 'invoicing' ),
225
-        'DKK'  => __( 'Danish Krone (DKK)', 'invoicing' ),
226
-        'HKD'  => __( 'Hong Kong Dollar (&#36;)', 'invoicing' ),
227
-        'HUF'  => __( 'Hungarian Forint (&#70;&#116;)', 'invoicing' ),
228
-        'INR'  => __( 'Indian Rupee (&#8377;)', 'invoicing' ),
229
-        'ILS'  => __( 'Israeli Shekel (&#8362;)', 'invoicing' ),
230
-        'JPY'  => __( 'Japanese Yen (&yen;)', 'invoicing' ),
231
-        'MYR'  => __( 'Malaysian Ringgit (&#82;&#77;)', 'invoicing' ),
232
-        'MXN'  => __( 'Mexican Peso (&#36;)', 'invoicing' ),
233
-        'NZD'  => __( 'New Zealand Dollar (&#36;)', 'invoicing' ),
234
-        'NOK'  => __( 'Norwegian Krone (&#107;&#114;)', 'invoicing' ),
235
-        'PHP'  => __( 'Philippine Peso (&#8369;)', 'invoicing' ),
236
-        'PLN'  => __( 'Polish Zloty (&#122;&#322;)', 'invoicing' ),
237
-        'SGD'  => __( 'Singapore Dollar (&#36;)', 'invoicing' ),
238
-        'SEK'  => __( 'Swedish Krona (&#107;&#114;)', 'invoicing' ),
239
-        'CHF'  => __( 'Swiss Franc (&#67;&#72;&#70;)', 'invoicing' ),
240
-        'TWD'  => __( 'Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing' ),
241
-        'THB'  => __( 'Thai Baht (&#3647;)', 'invoicing' ),
242
-        'TRY'  => __( 'Turkish Lira (&#8378;)', 'invoicing' ),
243
-        'RIAL' => __( 'Iranian Rial (&#65020;)', 'invoicing' ),
244
-        'RUB'  => __( 'Russian Ruble (&#8381;)', 'invoicing' ),
245
-        'ZAR'  => __( 'South African Rand (&#82;)', 'invoicing' )
216
+        'USD'  => __('US Dollars (&#36;)', 'invoicing'),
217
+        'EUR'  => __('Euros (&euro;)', 'invoicing'),
218
+        'GBP'  => __('Pounds Sterling (&pound;)', 'invoicing'),
219
+        'AUD'  => __('Australian Dollars (&#36;)', 'invoicing'),
220
+        'BRL'  => __('Brazilian Real (R&#36;)', 'invoicing'),
221
+        'CAD'  => __('Canadian Dollars (&#36;)', 'invoicing'),
222
+        'CLP'  => __('Chilean Peso (&#36;)', 'invoicing'),
223
+        'CNY'  => __('Chinese Yuan (&yen;)', 'invoicing'),
224
+        'CZK'  => __('Czech Koruna (&#75;&#269;)', 'invoicing'),
225
+        'DKK'  => __('Danish Krone (DKK)', 'invoicing'),
226
+        'HKD'  => __('Hong Kong Dollar (&#36;)', 'invoicing'),
227
+        'HUF'  => __('Hungarian Forint (&#70;&#116;)', 'invoicing'),
228
+        'INR'  => __('Indian Rupee (&#8377;)', 'invoicing'),
229
+        'ILS'  => __('Israeli Shekel (&#8362;)', 'invoicing'),
230
+        'JPY'  => __('Japanese Yen (&yen;)', 'invoicing'),
231
+        'MYR'  => __('Malaysian Ringgit (&#82;&#77;)', 'invoicing'),
232
+        'MXN'  => __('Mexican Peso (&#36;)', 'invoicing'),
233
+        'NZD'  => __('New Zealand Dollar (&#36;)', 'invoicing'),
234
+        'NOK'  => __('Norwegian Krone (&#107;&#114;)', 'invoicing'),
235
+        'PHP'  => __('Philippine Peso (&#8369;)', 'invoicing'),
236
+        'PLN'  => __('Polish Zloty (&#122;&#322;)', 'invoicing'),
237
+        'SGD'  => __('Singapore Dollar (&#36;)', 'invoicing'),
238
+        'SEK'  => __('Swedish Krona (&#107;&#114;)', 'invoicing'),
239
+        'CHF'  => __('Swiss Franc (&#67;&#72;&#70;)', 'invoicing'),
240
+        'TWD'  => __('Taiwan New Dollar (&#78;&#84;&#36;)', 'invoicing'),
241
+        'THB'  => __('Thai Baht (&#3647;)', 'invoicing'),
242
+        'TRY'  => __('Turkish Lira (&#8378;)', 'invoicing'),
243
+        'RIAL' => __('Iranian Rial (&#65020;)', 'invoicing'),
244
+        'RUB'  => __('Russian Ruble (&#8381;)', 'invoicing'),
245
+        'ZAR'  => __('South African Rand (&#82;)', 'invoicing')
246 246
     );
247 247
     
248
-    asort( $currencies );
248
+    asort($currencies);
249 249
 
250
-    return apply_filters( 'wpinv_currencies', $currencies );
250
+    return apply_filters('wpinv_currencies', $currencies);
251 251
 }
252 252
 
253
-function wpinv_price( $amount = '', $currency = '' ) {
254
-    if( empty( $currency ) ) {
253
+function wpinv_price($amount = '', $currency = '') {
254
+    if (empty($currency)) {
255 255
         $currency = wpinv_get_currency();
256 256
     }
257 257
 
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
 
260 260
     $negative = $amount < 0;
261 261
 
262
-    if ( $negative ) {
263
-        $amount = substr( $amount, 1 );
262
+    if ($negative) {
263
+        $amount = substr($amount, 1);
264 264
     }
265 265
 
266
-    $symbol = wpinv_currency_symbol( $currency );
266
+    $symbol = wpinv_currency_symbol($currency);
267 267
 
268
-    if ( $position == 'left' || $position == 'left_space' ) {
269
-        switch ( $currency ) {
268
+    if ($position == 'left' || $position == 'left_space') {
269
+        switch ($currency) {
270 270
             case "GBP" :
271 271
             case "BRL" :
272 272
             case "EUR" :
@@ -278,15 +278,15 @@  discard block
 block discarded – undo
278 278
             case "NZD" :
279 279
             case "SGD" :
280 280
             case "JPY" :
281
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
281
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
282 282
                 break;
283 283
             default :
284 284
                 //$price = $currency . ' ' . $amount;
285
-                $price = $position == 'left_space' ? $symbol . ' ' .  $amount : $symbol . $amount;
285
+                $price = $position == 'left_space' ? $symbol . ' ' . $amount : $symbol . $amount;
286 286
                 break;
287 287
         }
288 288
     } else {
289
-        switch ( $currency ) {
289
+        switch ($currency) {
290 290
             case "GBP" :
291 291
             case "BRL" :
292 292
             case "EUR" :
@@ -297,83 +297,83 @@  discard block
 block discarded – undo
297 297
             case "MXN" :
298 298
             case "SGD" :
299 299
             case "JPY" :
300
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
300
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
301 301
                 break;
302 302
             default :
303 303
                 //$price = $amount . ' ' . $currency;
304
-                $price = $position == 'right_space' ? $amount . ' ' .  $symbol : $amount . $symbol;
304
+                $price = $position == 'right_space' ? $amount . ' ' . $symbol : $amount . $symbol;
305 305
                 break;
306 306
         }
307 307
     }
308 308
     
309
-    if ( $negative ) {
309
+    if ($negative) {
310 310
         $price = '-' . $price;
311 311
     }
312 312
     
313
-    $price = apply_filters( 'wpinv_' . strtolower( $currency ) . '_currency_filter_' . $position, $price, $currency, $amount );
313
+    $price = apply_filters('wpinv_' . strtolower($currency) . '_currency_filter_' . $position, $price, $currency, $amount);
314 314
 
315 315
     return $price;
316 316
 }
317 317
 
318
-function wpinv_format_amount( $amount, $decimals = NULL, $calculate = false ) {
318
+function wpinv_format_amount($amount, $decimals = NULL, $calculate = false) {
319 319
     $thousands_sep = wpinv_thousands_separator();
320 320
     $decimal_sep   = wpinv_decimal_separator();
321 321
 
322
-    if ( $decimals === NULL ) {
322
+    if ($decimals === NULL) {
323 323
         $decimals = wpinv_decimals();
324 324
     }
325 325
 
326
-    if ( $decimal_sep == ',' && false !== ( $sep_found = strpos( $amount, $decimal_sep ) ) ) {
327
-        $whole = substr( $amount, 0, $sep_found );
328
-        $part = substr( $amount, $sep_found + 1, ( strlen( $amount ) - 1 ) );
326
+    if ($decimal_sep == ',' && false !== ($sep_found = strpos($amount, $decimal_sep))) {
327
+        $whole = substr($amount, 0, $sep_found);
328
+        $part = substr($amount, $sep_found + 1, (strlen($amount) - 1));
329 329
         $amount = $whole . '.' . $part;
330 330
     }
331 331
 
332
-    if ( $thousands_sep == ',' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
333
-        $amount = str_replace( ',', '', $amount );
332
+    if ($thousands_sep == ',' && false !== ($found = strpos($amount, $thousands_sep))) {
333
+        $amount = str_replace(',', '', $amount);
334 334
     }
335 335
 
336
-    if ( $thousands_sep == ' ' && false !== ( $found = strpos( $amount, $thousands_sep ) ) ) {
337
-        $amount = str_replace( ' ', '', $amount );
336
+    if ($thousands_sep == ' ' && false !== ($found = strpos($amount, $thousands_sep))) {
337
+        $amount = str_replace(' ', '', $amount);
338 338
     }
339 339
 
340
-    if ( empty( $amount ) ) {
340
+    if (empty($amount)) {
341 341
         $amount = 0;
342 342
     }
343 343
     
344
-    $decimals  = apply_filters( 'wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate );
345
-    $formatted = number_format( (float)$amount, $decimals, $decimal_sep, $thousands_sep );
344
+    $decimals  = apply_filters('wpinv_amount_format_decimals', $decimals ? $decimals : 0, $amount, $calculate);
345
+    $formatted = number_format((float)$amount, $decimals, $decimal_sep, $thousands_sep);
346 346
     
347
-    if ( $calculate ) {
348
-        if ( $thousands_sep === "," ) {
349
-            $formatted = str_replace( ",", "", $formatted );
347
+    if ($calculate) {
348
+        if ($thousands_sep === ",") {
349
+            $formatted = str_replace(",", "", $formatted);
350 350
         }
351 351
         
352
-        if ( $decimal_sep === "," ) {
353
-            $formatted = str_replace( ",", ".", $formatted );
352
+        if ($decimal_sep === ",") {
353
+            $formatted = str_replace(",", ".", $formatted);
354 354
         }
355 355
     }
356 356
 
357
-    return apply_filters( 'wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate );
357
+    return apply_filters('wpinv_amount_format', $formatted, $amount, $decimals, $decimal_sep, $thousands_sep, $calculate);
358 358
 }
359
-add_filter( 'wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1 );
359
+add_filter('wpinv_amount_format_decimals', 'wpinv_currency_decimal_filter', 10, 1);
360 360
 
361
-function wpinv_sanitize_key( $key ) {
361
+function wpinv_sanitize_key($key) {
362 362
     $raw_key = $key;
363
-    $key = preg_replace( '/[^a-zA-Z0-9_\-\.\:\/]/', '', $key );
363
+    $key = preg_replace('/[^a-zA-Z0-9_\-\.\:\/]/', '', $key);
364 364
 
365
-    return apply_filters( 'wpinv_sanitize_key', $key, $raw_key );
365
+    return apply_filters('wpinv_sanitize_key', $key, $raw_key);
366 366
 }
367 367
 
368
-function wpinv_get_file_extension( $str ) {
369
-    $parts = explode( '.', $str );
370
-    return end( $parts );
368
+function wpinv_get_file_extension($str) {
369
+    $parts = explode('.', $str);
370
+    return end($parts);
371 371
 }
372 372
 
373
-function wpinv_string_is_image_url( $str ) {
374
-    $ext = wpinv_get_file_extension( $str );
373
+function wpinv_string_is_image_url($str) {
374
+    $ext = wpinv_get_file_extension($str);
375 375
 
376
-    switch ( strtolower( $ext ) ) {
376
+    switch (strtolower($ext)) {
377 377
         case 'jpeg';
378 378
         case 'jpg';
379 379
             $return = true;
@@ -389,32 +389,32 @@  discard block
 block discarded – undo
389 389
             break;
390 390
     }
391 391
 
392
-    return (bool)apply_filters( 'wpinv_string_is_image', $return, $str );
392
+    return (bool)apply_filters('wpinv_string_is_image', $return, $str);
393 393
 }
394 394
 
395
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
396
-    $should_log = apply_filters( 'wpinv_log_errors', WP_DEBUG );
395
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
396
+    $should_log = apply_filters('wpinv_log_errors', WP_DEBUG);
397 397
     
398
-    if ( true === $should_log ) {
398
+    if (true === $should_log) {
399 399
         $label = '';
400
-        if ( $file && $file !== '' ) {
401
-            $label .= basename( $file ) . ( $line ? '(' . $line . ')' : '' );
400
+        if ($file && $file !== '') {
401
+            $label .= basename($file) . ($line ? '(' . $line . ')' : '');
402 402
         }
403 403
         
404
-        if ( $title && $title !== '' ) {
404
+        if ($title && $title !== '') {
405 405
             $label = $label !== '' ? $label . ' ' : '';
406 406
             $label .= $title . ' ';
407 407
         }
408 408
         
409
-        $label = $label !== '' ? trim( $label ) . ' : ' : '';
409
+        $label = $label !== '' ? trim($label) . ' : ' : '';
410 410
         
411
-        if ( is_array( $log ) || is_object( $log ) ) {
412
-            error_log( $label . print_r( $log, true ) );
411
+        if (is_array($log) || is_object($log)) {
412
+            error_log($label . print_r($log, true));
413 413
         } else {
414
-            error_log( $label . $log );
414
+            error_log($label . $log);
415 415
         }
416 416
         
417
-        if ( $exit ) {
417
+        if ($exit) {
418 418
             exit;
419 419
         }
420 420
     }
@@ -422,65 +422,65 @@  discard block
 block discarded – undo
422 422
 
423 423
 function wpinv_is_ajax_disabled() {
424 424
     $retval = false;
425
-    return apply_filters( 'wpinv_is_ajax_disabled', $retval );
425
+    return apply_filters('wpinv_is_ajax_disabled', $retval);
426 426
 }
427 427
 
428
-function wpinv_get_current_page_url( $nocache = false ) {
428
+function wpinv_get_current_page_url($nocache = false) {
429 429
     global $wp;
430 430
 
431
-    if ( get_option( 'permalink_structure' ) ) {
432
-        $base = trailingslashit( home_url( $wp->request ) );
431
+    if (get_option('permalink_structure')) {
432
+        $base = trailingslashit(home_url($wp->request));
433 433
     } else {
434
-        $base = add_query_arg( $wp->query_string, '', trailingslashit( home_url( $wp->request ) ) );
435
-        $base = remove_query_arg( array( 'post_type', 'name' ), $base );
434
+        $base = add_query_arg($wp->query_string, '', trailingslashit(home_url($wp->request)));
435
+        $base = remove_query_arg(array('post_type', 'name'), $base);
436 436
     }
437 437
 
438 438
     $scheme = is_ssl() ? 'https' : 'http';
439
-    $uri    = set_url_scheme( $base, $scheme );
439
+    $uri    = set_url_scheme($base, $scheme);
440 440
 
441
-    if ( is_front_page() ) {
442
-        $uri = home_url( '/' );
443
-    } elseif ( wpinv_is_checkout( array(), false ) ) {
441
+    if (is_front_page()) {
442
+        $uri = home_url('/');
443
+    } elseif (wpinv_is_checkout(array(), false)) {
444 444
         $uri = wpinv_get_checkout_uri();
445 445
     }
446 446
 
447
-    $uri = apply_filters( 'wpinv_get_current_page_url', $uri );
447
+    $uri = apply_filters('wpinv_get_current_page_url', $uri);
448 448
 
449
-    if ( $nocache ) {
450
-        $uri = wpinv_add_cache_busting( $uri );
449
+    if ($nocache) {
450
+        $uri = wpinv_add_cache_busting($uri);
451 451
     }
452 452
 
453 453
     return $uri;
454 454
 }
455 455
 
456 456
 function wpinv_get_php_arg_separator_output() {
457
-	return ini_get( 'arg_separator.output' );
457
+	return ini_get('arg_separator.output');
458 458
 }
459 459
 
460
-function wpinv_rgb_from_hex( $color ) {
461
-    $color = str_replace( '#', '', $color );
460
+function wpinv_rgb_from_hex($color) {
461
+    $color = str_replace('#', '', $color);
462 462
     // Convert shorthand colors to full format, e.g. "FFF" -> "FFFFFF"
463
-    $color = preg_replace( '~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color );
463
+    $color = preg_replace('~^(.)(.)(.)$~', '$1$1$2$2$3$3', $color);
464 464
 
465 465
     $rgb      = array();
466
-    $rgb['R'] = hexdec( $color{0}.$color{1} );
467
-    $rgb['G'] = hexdec( $color{2}.$color{3} );
468
-    $rgb['B'] = hexdec( $color{4}.$color{5} );
466
+    $rgb['R'] = hexdec($color{0} . $color{1} );
467
+    $rgb['G'] = hexdec($color{2} . $color{3} );
468
+    $rgb['B'] = hexdec($color{4} . $color{5} );
469 469
 
470 470
     return $rgb;
471 471
 }
472 472
 
473
-function wpinv_hex_darker( $color, $factor = 30 ) {
474
-    $base  = wpinv_rgb_from_hex( $color );
473
+function wpinv_hex_darker($color, $factor = 30) {
474
+    $base  = wpinv_rgb_from_hex($color);
475 475
     $color = '#';
476 476
 
477
-    foreach ( $base as $k => $v ) {
477
+    foreach ($base as $k => $v) {
478 478
         $amount      = $v / 100;
479
-        $amount      = round( $amount * $factor );
479
+        $amount      = round($amount * $factor);
480 480
         $new_decimal = $v - $amount;
481 481
 
482
-        $new_hex_component = dechex( $new_decimal );
483
-        if ( strlen( $new_hex_component ) < 2 ) {
482
+        $new_hex_component = dechex($new_decimal);
483
+        if (strlen($new_hex_component) < 2) {
484 484
             $new_hex_component = "0" . $new_hex_component;
485 485
         }
486 486
         $color .= $new_hex_component;
@@ -489,18 +489,18 @@  discard block
 block discarded – undo
489 489
     return $color;
490 490
 }
491 491
 
492
-function wpinv_hex_lighter( $color, $factor = 30 ) {
493
-    $base  = wpinv_rgb_from_hex( $color );
492
+function wpinv_hex_lighter($color, $factor = 30) {
493
+    $base  = wpinv_rgb_from_hex($color);
494 494
     $color = '#';
495 495
 
496
-    foreach ( $base as $k => $v ) {
496
+    foreach ($base as $k => $v) {
497 497
         $amount      = 255 - $v;
498 498
         $amount      = $amount / 100;
499
-        $amount      = round( $amount * $factor );
499
+        $amount      = round($amount * $factor);
500 500
         $new_decimal = $v + $amount;
501 501
 
502
-        $new_hex_component = dechex( $new_decimal );
503
-        if ( strlen( $new_hex_component ) < 2 ) {
502
+        $new_hex_component = dechex($new_decimal);
503
+        if (strlen($new_hex_component) < 2) {
504 504
             $new_hex_component = "0" . $new_hex_component;
505 505
         }
506 506
         $color .= $new_hex_component;
@@ -509,22 +509,22 @@  discard block
 block discarded – undo
509 509
     return $color;
510 510
 }
511 511
 
512
-function wpinv_light_or_dark( $color, $dark = '#000000', $light = '#FFFFFF' ) {
513
-    $hex = str_replace( '#', '', $color );
512
+function wpinv_light_or_dark($color, $dark = '#000000', $light = '#FFFFFF') {
513
+    $hex = str_replace('#', '', $color);
514 514
 
515
-    $c_r = hexdec( substr( $hex, 0, 2 ) );
516
-    $c_g = hexdec( substr( $hex, 2, 2 ) );
517
-    $c_b = hexdec( substr( $hex, 4, 2 ) );
515
+    $c_r = hexdec(substr($hex, 0, 2));
516
+    $c_g = hexdec(substr($hex, 2, 2));
517
+    $c_b = hexdec(substr($hex, 4, 2));
518 518
 
519
-    $brightness = ( ( $c_r * 299 ) + ( $c_g * 587 ) + ( $c_b * 114 ) ) / 1000;
519
+    $brightness = (($c_r * 299) + ($c_g * 587) + ($c_b * 114)) / 1000;
520 520
 
521 521
     return $brightness > 155 ? $dark : $light;
522 522
 }
523 523
 
524
-function wpinv_format_hex( $hex ) {
525
-    $hex = trim( str_replace( '#', '', $hex ) );
524
+function wpinv_format_hex($hex) {
525
+    $hex = trim(str_replace('#', '', $hex));
526 526
 
527
-    if ( strlen( $hex ) == 3 ) {
527
+    if (strlen($hex) == 3) {
528 528
         $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
529 529
     }
530 530
 
@@ -544,12 +544,12 @@  discard block
 block discarded – undo
544 544
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
545 545
  * @return string
546 546
  */
547
-function wpinv_utf8_strimwidth( $str, $start, $width, $trimmaker = '', $encoding = 'UTF-8' ) {
548
-    if ( function_exists( 'mb_strimwidth' ) ) {
549
-        return mb_strimwidth( $str, $start, $width, $trimmaker, $encoding );
547
+function wpinv_utf8_strimwidth($str, $start, $width, $trimmaker = '', $encoding = 'UTF-8') {
548
+    if (function_exists('mb_strimwidth')) {
549
+        return mb_strimwidth($str, $start, $width, $trimmaker, $encoding);
550 550
     }
551 551
     
552
-    return wpinv_utf8_substr( $str, $start, $width, $encoding ) . $trimmaker;
552
+    return wpinv_utf8_substr($str, $start, $width, $encoding) . $trimmaker;
553 553
 }
554 554
 
555 555
 /**
@@ -561,28 +561,28 @@  discard block
 block discarded – undo
561 561
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
562 562
  * @return int Returns the number of characters in string.
563 563
  */
564
-function wpinv_utf8_strlen( $str, $encoding = 'UTF-8' ) {
565
-    if ( function_exists( 'mb_strlen' ) ) {
566
-        return mb_strlen( $str, $encoding );
564
+function wpinv_utf8_strlen($str, $encoding = 'UTF-8') {
565
+    if (function_exists('mb_strlen')) {
566
+        return mb_strlen($str, $encoding);
567 567
     }
568 568
         
569
-    return strlen( $str );
569
+    return strlen($str);
570 570
 }
571 571
 
572
-function wpinv_utf8_strtolower( $str, $encoding = 'UTF-8' ) {
573
-    if ( function_exists( 'mb_strtolower' ) ) {
574
-        return mb_strtolower( $str, $encoding );
572
+function wpinv_utf8_strtolower($str, $encoding = 'UTF-8') {
573
+    if (function_exists('mb_strtolower')) {
574
+        return mb_strtolower($str, $encoding);
575 575
     }
576 576
     
577
-    return strtolower( $str );
577
+    return strtolower($str);
578 578
 }
579 579
 
580
-function wpinv_utf8_strtoupper( $str, $encoding = 'UTF-8' ) {
581
-    if ( function_exists( 'mb_strtoupper' ) ) {
582
-        return mb_strtoupper( $str, $encoding );
580
+function wpinv_utf8_strtoupper($str, $encoding = 'UTF-8') {
581
+    if (function_exists('mb_strtoupper')) {
582
+        return mb_strtoupper($str, $encoding);
583 583
     }
584 584
     
585
-    return strtoupper( $str );
585
+    return strtoupper($str);
586 586
 }
587 587
 
588 588
 /**
@@ -596,12 +596,12 @@  discard block
 block discarded – undo
596 596
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
597 597
  * @return int Returns the position of the first occurrence of search in the string.
598 598
  */
599
-function wpinv_utf8_strpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
600
-    if ( function_exists( 'mb_strpos' ) ) {
601
-        return mb_strpos( $str, $find, $offset, $encoding );
599
+function wpinv_utf8_strpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
600
+    if (function_exists('mb_strpos')) {
601
+        return mb_strpos($str, $find, $offset, $encoding);
602 602
     }
603 603
         
604
-    return strpos( $str, $find, $offset );
604
+    return strpos($str, $find, $offset);
605 605
 }
606 606
 
607 607
 /**
@@ -615,12 +615,12 @@  discard block
 block discarded – undo
615 615
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
616 616
  * @return int Returns the position of the last occurrence of search.
617 617
  */
618
-function wpinv_utf8_strrpos( $str, $find, $offset = 0, $encoding = 'UTF-8' ) {
619
-    if ( function_exists( 'mb_strrpos' ) ) {
620
-        return mb_strrpos( $str, $find, $offset, $encoding );
618
+function wpinv_utf8_strrpos($str, $find, $offset = 0, $encoding = 'UTF-8') {
619
+    if (function_exists('mb_strrpos')) {
620
+        return mb_strrpos($str, $find, $offset, $encoding);
621 621
     }
622 622
         
623
-    return strrpos( $str, $find, $offset );
623
+    return strrpos($str, $find, $offset);
624 624
 }
625 625
 
626 626
 /**
@@ -635,16 +635,16 @@  discard block
 block discarded – undo
635 635
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
636 636
  * @return string
637 637
  */
638
-function wpinv_utf8_substr( $str, $start, $length = null, $encoding = 'UTF-8' ) {
639
-    if ( function_exists( 'mb_substr' ) ) {
640
-        if ( $length === null ) {
641
-            return mb_substr( $str, $start, wpinv_utf8_strlen( $str, $encoding ), $encoding );
638
+function wpinv_utf8_substr($str, $start, $length = null, $encoding = 'UTF-8') {
639
+    if (function_exists('mb_substr')) {
640
+        if ($length === null) {
641
+            return mb_substr($str, $start, wpinv_utf8_strlen($str, $encoding), $encoding);
642 642
         } else {
643
-            return mb_substr( $str, $start, $length, $encoding );
643
+            return mb_substr($str, $start, $length, $encoding);
644 644
         }
645 645
     }
646 646
         
647
-    return substr( $str, $start, $length );
647
+    return substr($str, $start, $length);
648 648
 }
649 649
 
650 650
 /**
@@ -656,48 +656,48 @@  discard block
 block discarded – undo
656 656
  * @param string $encoding The encoding parameter is the character encoding. Default "UTF-8".
657 657
  * @return string The width of string.
658 658
  */
659
-function wpinv_utf8_strwidth( $str, $encoding = 'UTF-8' ) {
660
-    if ( function_exists( 'mb_strwidth' ) ) {
661
-        return mb_strwidth( $str, $encoding );
659
+function wpinv_utf8_strwidth($str, $encoding = 'UTF-8') {
660
+    if (function_exists('mb_strwidth')) {
661
+        return mb_strwidth($str, $encoding);
662 662
     }
663 663
     
664
-    return wpinv_utf8_strlen( $str, $encoding );
664
+    return wpinv_utf8_strlen($str, $encoding);
665 665
 }
666 666
 
667
-function wpinv_utf8_ucfirst( $str, $lower_str_end = false, $encoding = 'UTF-8' ) {
668
-    if ( function_exists( 'mb_strlen' ) ) {
669
-        $first_letter = wpinv_utf8_strtoupper( wpinv_utf8_substr( $str, 0, 1, $encoding ), $encoding );
667
+function wpinv_utf8_ucfirst($str, $lower_str_end = false, $encoding = 'UTF-8') {
668
+    if (function_exists('mb_strlen')) {
669
+        $first_letter = wpinv_utf8_strtoupper(wpinv_utf8_substr($str, 0, 1, $encoding), $encoding);
670 670
         $str_end = "";
671 671
         
672
-        if ( $lower_str_end ) {
673
-            $str_end = wpinv_utf8_strtolower( wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding ), $encoding );
672
+        if ($lower_str_end) {
673
+            $str_end = wpinv_utf8_strtolower(wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding), $encoding);
674 674
         } else {
675
-            $str_end = wpinv_utf8_substr( $str, 1, wpinv_utf8_strlen( $str, $encoding ), $encoding );
675
+            $str_end = wpinv_utf8_substr($str, 1, wpinv_utf8_strlen($str, $encoding), $encoding);
676 676
         }
677 677
 
678 678
         return $first_letter . $str_end;
679 679
     }
680 680
     
681
-    return ucfirst( $str );
681
+    return ucfirst($str);
682 682
 }
683 683
 
684
-function wpinv_utf8_ucwords( $str, $encoding = 'UTF-8' ) {
685
-    if ( function_exists( 'mb_convert_case' ) ) {
686
-        return mb_convert_case( $str, MB_CASE_TITLE, $encoding );
684
+function wpinv_utf8_ucwords($str, $encoding = 'UTF-8') {
685
+    if (function_exists('mb_convert_case')) {
686
+        return mb_convert_case($str, MB_CASE_TITLE, $encoding);
687 687
     }
688 688
     
689
-    return ucwords( $str );
689
+    return ucwords($str);
690 690
 }
691 691
 
692
-function wpinv_period_in_days( $period, $unit ) {
693
-    $period = absint( $period );
692
+function wpinv_period_in_days($period, $unit) {
693
+    $period = absint($period);
694 694
     
695
-    if ( $period > 0 ) {
696
-        if ( in_array( strtolower( $unit ), array( 'w', 'week', 'weeks' ) ) ) {
695
+    if ($period > 0) {
696
+        if (in_array(strtolower($unit), array('w', 'week', 'weeks'))) {
697 697
             $period = $period * 7;
698
-        } else if ( in_array( strtolower( $unit ), array( 'm', 'month', 'months' ) ) ) {
698
+        } else if (in_array(strtolower($unit), array('m', 'month', 'months'))) {
699 699
             $period = $period * 30;
700
-        } else if ( in_array( strtolower( $unit ), array( 'y', 'year', 'years' ) ) ) {
700
+        } else if (in_array(strtolower($unit), array('y', 'year', 'years'))) {
701 701
             $period = $period * 365;
702 702
         }
703 703
     }
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +469 added lines, -469 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  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( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
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( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
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( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
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']     = 'gd_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
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,99 +189,99 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
     
216
-    $start_timestamp        = strtotime( $meta['start'] );
216
+    $start_timestamp        = strtotime($meta['start']);
217 217
 
218
-    if ( !empty( $meta['start'] ) ) {
219
-        $meta['start']      = date( 'Y-m-d H:i:s', $start_timestamp );
218
+    if (!empty($meta['start'])) {
219
+        $meta['start']      = date('Y-m-d H:i:s', $start_timestamp);
220 220
     }
221 221
         
222
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
222
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
223 223
         $meta['amount'] = 100;
224 224
     }
225 225
 
226
-    if ( !empty( $meta['expiration'] ) ) {
227
-        $meta['expiration'] = date( 'Y-m-d H:i:s', strtotime( date( 'Y-m-d', strtotime( $meta['expiration'] ) ) . ' 23:59:59' ) );
228
-        $end_timestamp      = strtotime( $meta['expiration'] );
226
+    if (!empty($meta['expiration'])) {
227
+        $meta['expiration'] = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($meta['expiration'])) . ' 23:59:59'));
228
+        $end_timestamp      = strtotime($meta['expiration']);
229 229
 
230
-        if ( !empty( $meta['start'] ) && $start_timestamp > $end_timestamp ) {
230
+        if (!empty($meta['start']) && $start_timestamp > $end_timestamp) {
231 231
             $meta['expiration'] = $meta['start']; // Set the expiration date to the start date if start is later than expiration date.
232 232
         }
233 233
     }
234 234
     
235
-    if ( $meta['uses'] === false ) {
236
-        unset( $meta['uses'] );
235
+    if ($meta['uses'] === false) {
236
+        unset($meta['uses']);
237 237
     }
238 238
     
239
-    if ( ! empty( $meta['items'] ) ) {
240
-        foreach ( $meta['items'] as $key => $item ) {
241
-            if ( 0 === intval( $item ) ) {
242
-                unset( $meta['items'][ $key ] );
239
+    if (!empty($meta['items'])) {
240
+        foreach ($meta['items'] as $key => $item) {
241
+            if (0 === intval($item)) {
242
+                unset($meta['items'][$key]);
243 243
             }
244 244
         }
245 245
     }
246 246
     
247
-    if ( ! empty( $meta['excluded_items'] ) ) {
248
-        foreach ( $meta['excluded_items'] as $key => $item ) {
249
-            if ( 0 === intval( $item ) ) {
250
-                unset( $meta['excluded_items'][ $key ] );
247
+    if (!empty($meta['excluded_items'])) {
248
+        foreach ($meta['excluded_items'] as $key => $item) {
249
+            if (0 === intval($item)) {
250
+                unset($meta['excluded_items'][$key]);
251 251
             }
252 252
         }
253 253
     }
254 254
     
255
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
255
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
256 256
     
257
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
257
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
258 258
     
259
-    foreach( $meta as $key => $value ) {
260
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
259
+    foreach ($meta as $key => $value) {
260
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
261 261
     }
262 262
     
263
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
263
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
264 264
     
265 265
     return $post_id;
266 266
 }
267 267
 
268
-function wpinv_remove_discount( $discount_id = 0 ) {
269
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
268
+function wpinv_remove_discount($discount_id = 0) {
269
+    do_action('wpinv_pre_delete_discount', $discount_id);
270 270
 
271
-    wp_delete_post( $discount_id, true );
271
+    wp_delete_post($discount_id, true);
272 272
 
273
-    do_action( 'wpinv_post_delete_discount', $discount_id );
273
+    do_action('wpinv_post_delete_discount', $discount_id);
274 274
 }
275 275
 
276
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
277
-    $discount = wpinv_get_discount(  $code_id );
276
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
277
+    $discount = wpinv_get_discount($code_id);
278 278
 
279
-    if ( $discount ) {
280
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
279
+    if ($discount) {
280
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
281 281
 
282
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
282
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
283 283
 
284
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
284
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
285 285
 
286 286
         return true;
287 287
     }
@@ -289,173 +289,173 @@  discard block
 block discarded – undo
289 289
     return false;
290 290
 }
291 291
 
292
-function wpinv_discount_exists( $code_id ) {
293
-    if ( wpinv_get_discount(  $code_id ) ) {
292
+function wpinv_discount_exists($code_id) {
293
+    if (wpinv_get_discount($code_id)) {
294 294
         return true;
295 295
     }
296 296
 
297 297
     return false;
298 298
 }
299 299
 
300
-function wpinv_is_discount_active( $code_id = null ) {
301
-    $discount = wpinv_get_discount(  $code_id );
300
+function wpinv_is_discount_active($code_id = null) {
301
+    $discount = wpinv_get_discount($code_id);
302 302
     $return   = false;
303 303
 
304
-    if ( $discount ) {
305
-        if ( wpinv_is_discount_expired( $code_id ) ) {
306
-            if( defined( 'DOING_AJAX' ) ) {
307
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
304
+    if ($discount) {
305
+        if (wpinv_is_discount_expired($code_id)) {
306
+            if (defined('DOING_AJAX')) {
307
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
308 308
             }
309
-        } elseif ( $discount->post_status == 'publish' ) {
309
+        } elseif ($discount->post_status == 'publish') {
310 310
             $return = true;
311 311
         } else {
312
-            if( defined( 'DOING_AJAX' ) ) {
313
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
312
+            if (defined('DOING_AJAX')) {
313
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
314 314
             }
315 315
         }
316 316
     }
317 317
 
318
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
318
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
319 319
 }
320 320
 
321
-function wpinv_get_discount_code( $code_id = null ) {
322
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
321
+function wpinv_get_discount_code($code_id = null) {
322
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
323 323
 
324
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
324
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
325 325
 }
326 326
 
327
-function wpinv_get_discount_start_date( $code_id = null ) {
328
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
327
+function wpinv_get_discount_start_date($code_id = null) {
328
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
329 329
 
330
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
330
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
331 331
 }
332 332
 
333
-function wpinv_get_discount_expiration( $code_id = null ) {
334
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
333
+function wpinv_get_discount_expiration($code_id = null) {
334
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
335 335
 
336
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
336
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
337 337
 }
338 338
 
339
-function wpinv_get_discount_max_uses( $code_id = null ) {
340
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
339
+function wpinv_get_discount_max_uses($code_id = null) {
340
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
341 341
 
342
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
342
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
343 343
 }
344 344
 
345
-function wpinv_get_discount_uses( $code_id = null ) {
346
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
345
+function wpinv_get_discount_uses($code_id = null) {
346
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
347 347
 
348
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
348
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
349 349
 }
350 350
 
351
-function wpinv_get_discount_min_total( $code_id = null ) {
352
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
351
+function wpinv_get_discount_min_total($code_id = null) {
352
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
353 353
 
354
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
354
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
355 355
 }
356 356
 
357
-function wpinv_get_discount_max_total( $code_id = null ) {
358
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
357
+function wpinv_get_discount_max_total($code_id = null) {
358
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
359 359
 
360
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
360
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
361 361
 }
362 362
 
363
-function wpinv_get_discount_amount( $code_id = null ) {
364
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
363
+function wpinv_get_discount_amount($code_id = null) {
364
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
365 365
 
366
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
366
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
367 367
 }
368 368
 
369
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
370
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
369
+function wpinv_get_discount_type($code_id = null, $name = false) {
370
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
371 371
     
372
-    if ( $name ) {
373
-        $name = wpinv_get_discount_type_name( $type );
372
+    if ($name) {
373
+        $name = wpinv_get_discount_type_name($type);
374 374
         
375
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
375
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
376 376
     }
377 377
 
378
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
378
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
379 379
 }
380 380
 
381
-function wpinv_discount_status( $status ) {
382
-    switch( $status ){
381
+function wpinv_discount_status($status) {
382
+    switch ($status) {
383 383
         case 'expired' :
384
-            $name = __( 'Expired', 'invoicing' );
384
+            $name = __('Expired', 'invoicing');
385 385
             break;
386 386
         case 'publish' :
387 387
         case 'active' :
388
-            $name = __( 'Active', 'invoicing' );
388
+            $name = __('Active', 'invoicing');
389 389
             break;
390 390
         default :
391
-            $name = __( 'Inactive', 'invoicing' );
391
+            $name = __('Inactive', 'invoicing');
392 392
             break;
393 393
     }
394 394
     return $name;
395 395
 }
396 396
 
397
-function wpinv_get_discount_excluded_items( $code_id = null ) {
398
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
397
+function wpinv_get_discount_excluded_items($code_id = null) {
398
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
399 399
 
400
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
400
+    if (empty($excluded_items) || !is_array($excluded_items)) {
401 401
         $excluded_items = array();
402 402
     }
403 403
 
404
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
404
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
405 405
 }
406 406
 
407
-function wpinv_get_discount_item_reqs( $code_id = null ) {
408
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
407
+function wpinv_get_discount_item_reqs($code_id = null) {
408
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
409 409
 
410
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
410
+    if (empty($item_reqs) || !is_array($item_reqs)) {
411 411
         $item_reqs = array();
412 412
     }
413 413
 
414
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
414
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
415 415
 }
416 416
 
417
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
418
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
417
+function wpinv_get_discount_item_condition($code_id = 0) {
418
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
419 419
 }
420 420
 
421
-function wpinv_is_discount_not_global( $code_id = 0 ) {
422
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
421
+function wpinv_is_discount_not_global($code_id = 0) {
422
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
423 423
 }
424 424
 
425
-function wpinv_is_discount_expired( $code_id = null ) {
426
-    $discount = wpinv_get_discount(  $code_id );
425
+function wpinv_is_discount_expired($code_id = null) {
426
+    $discount = wpinv_get_discount($code_id);
427 427
     $return   = false;
428 428
 
429
-    if ( $discount ) {
430
-        $expiration = wpinv_get_discount_expiration( $code_id );
431
-        if ( $expiration ) {
432
-            $expiration = strtotime( $expiration );
433
-            if ( $expiration < current_time( 'timestamp' ) ) {
429
+    if ($discount) {
430
+        $expiration = wpinv_get_discount_expiration($code_id);
431
+        if ($expiration) {
432
+            $expiration = strtotime($expiration);
433
+            if ($expiration < current_time('timestamp')) {
434 434
                 // Discount is expired
435
-                wpinv_update_discount_status( $code_id, 'pending' );
435
+                wpinv_update_discount_status($code_id, 'pending');
436 436
                 $return = true;
437 437
             }
438 438
         }
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
441
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
442 442
 }
443 443
 
444
-function wpinv_is_discount_started( $code_id = null ) {
445
-    $discount = wpinv_get_discount(  $code_id );
444
+function wpinv_is_discount_started($code_id = null) {
445
+    $discount = wpinv_get_discount($code_id);
446 446
     $return   = false;
447 447
 
448
-    if ( $discount ) {
449
-        $start_date = wpinv_get_discount_start_date( $code_id );
448
+    if ($discount) {
449
+        $start_date = wpinv_get_discount_start_date($code_id);
450 450
 
451
-        if ( $start_date ) {
452
-            $start_date = strtotime( $start_date );
451
+        if ($start_date) {
452
+            $start_date = strtotime($start_date);
453 453
 
454
-            if ( $start_date < current_time( 'timestamp' ) ) {
454
+            if ($start_date < current_time('timestamp')) {
455 455
                 // Discount has past the start date
456 456
                 $return = true;
457 457
             } else {
458
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
458
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
459 459
             }
460 460
         } else {
461 461
             // No start date for this discount, so has to be true
@@ -463,159 +463,159 @@  discard block
 block discarded – undo
463 463
         }
464 464
     }
465 465
 
466
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
466
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
467 467
 }
468 468
 
469
-function wpinv_check_discount_dates( $code_id = null ) {
470
-    $discount = wpinv_get_discount(  $code_id );
469
+function wpinv_check_discount_dates($code_id = null) {
470
+    $discount = wpinv_get_discount($code_id);
471 471
     $return   = false;
472 472
 
473
-    if ( $discount ) {
474
-        $start_date = wpinv_get_discount_start_date( $code_id );
473
+    if ($discount) {
474
+        $start_date = wpinv_get_discount_start_date($code_id);
475 475
 
476
-        if ( $start_date ) {
477
-            $start_date = strtotime( $start_date );
476
+        if ($start_date) {
477
+            $start_date = strtotime($start_date);
478 478
 
479
-            if ( $start_date < current_time( 'timestamp' ) ) {
479
+            if ($start_date < current_time('timestamp')) {
480 480
                 // Discount has past the start date
481 481
                 $return = true;
482 482
             } else {
483
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
483
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
484 484
             }
485 485
         } else {
486 486
             // No start date for this discount, so has to be true
487 487
             $return = true;
488 488
         }
489 489
         
490
-        if ( $return ) {
491
-            $expiration = wpinv_get_discount_expiration( $code_id );
490
+        if ($return) {
491
+            $expiration = wpinv_get_discount_expiration($code_id);
492 492
             
493
-            if ( $expiration ) {
494
-                $expiration = strtotime( $expiration );
495
-                if ( $expiration < current_time( 'timestamp' ) ) {
493
+            if ($expiration) {
494
+                $expiration = strtotime($expiration);
495
+                if ($expiration < current_time('timestamp')) {
496 496
                     // Discount is expired
497
-                    wpinv_update_discount_status( $code_id, 'pending' );
497
+                    wpinv_update_discount_status($code_id, 'pending');
498 498
                     $return = true;
499 499
                 }
500 500
             }
501 501
         }
502 502
     }
503 503
     
504
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
504
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
505 505
 }
506 506
 
507
-function wpinv_is_discount_maxed_out( $code_id = null ) {
508
-    $discount = wpinv_get_discount(  $code_id );
507
+function wpinv_is_discount_maxed_out($code_id = null) {
508
+    $discount = wpinv_get_discount($code_id);
509 509
     $return   = false;
510 510
 
511
-    if ( $discount ) {
512
-        $uses = wpinv_get_discount_uses( $code_id );
511
+    if ($discount) {
512
+        $uses = wpinv_get_discount_uses($code_id);
513 513
         // Large number that will never be reached
514
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
514
+        $max_uses = wpinv_get_discount_max_uses($code_id);
515 515
         // Should never be greater than, but just in case
516
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
516
+        if ($uses >= $max_uses && !empty($max_uses)) {
517 517
             // Discount is maxed out
518
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
518
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
519 519
             $return = true;
520 520
         }
521 521
     }
522 522
 
523
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
523
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
524 524
 }
525 525
 
526
-function wpinv_discount_is_min_met( $code_id = null ) {
527
-    $discount = wpinv_get_discount( $code_id );
526
+function wpinv_discount_is_min_met($code_id = null) {
527
+    $discount = wpinv_get_discount($code_id);
528 528
     $return   = false;
529 529
 
530
-    if ( $discount ) {
531
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
532
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
530
+    if ($discount) {
531
+        $min         = (float)wpinv_get_discount_min_total($code_id);
532
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
533 533
 
534
-        if ( !$min > 0 || $cart_amount >= $min ) {
534
+        if (!$min > 0 || $cart_amount >= $min) {
535 535
             // Minimum has been met
536 536
             $return = true;
537 537
         } else {
538
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
538
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
539 539
         }
540 540
     }
541 541
 
542
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
542
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
543 543
 }
544 544
 
545
-function wpinv_discount_is_max_met( $code_id = null ) {
546
-    $discount = wpinv_get_discount( $code_id );
545
+function wpinv_discount_is_max_met($code_id = null) {
546
+    $discount = wpinv_get_discount($code_id);
547 547
     $return   = false;
548 548
 
549
-    if ( $discount ) {
550
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
551
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
549
+    if ($discount) {
550
+        $max         = (float)wpinv_get_discount_max_total($code_id);
551
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
552 552
 
553
-        if ( !$max > 0 || $cart_amount <= $max ) {
553
+        if (!$max > 0 || $cart_amount <= $max) {
554 554
             // Minimum has been met
555 555
             $return = true;
556 556
         } else {
557
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice of %s not met.', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
557
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice of %s not met.', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
558 558
         }
559 559
     }
560 560
 
561
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
561
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
562 562
 }
563 563
 
564
-function wpinv_discount_is_single_use( $code_id = 0 ) {
565
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
566
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
564
+function wpinv_discount_is_single_use($code_id = 0) {
565
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
566
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
567 567
 }
568 568
 
569
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
570
-    if ( $code ) {
571
-        $discount = wpinv_get_discount_by_code( $code_id );
569
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
570
+    if ($code) {
571
+        $discount = wpinv_get_discount_by_code($code_id);
572 572
         
573
-        if ( !empty( $discount ) ) {
573
+        if (!empty($discount)) {
574 574
             $code_id = $discount->ID;
575 575
         }
576 576
     }
577 577
     
578
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
578
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
579 579
     
580
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
580
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
581 581
 }
582 582
 
583
-function wpinv_discount_item_reqs_met( $code_id = null ) {
584
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
585
-    $condition    = wpinv_get_discount_item_condition( $code_id );
586
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
583
+function wpinv_discount_item_reqs_met($code_id = null) {
584
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
585
+    $condition    = wpinv_get_discount_item_condition($code_id);
586
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
587 587
     $cart_items   = wpinv_get_cart_contents();
588
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
588
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
589 589
     $ret          = false;
590 590
 
591
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
591
+    if (empty($item_reqs) && empty($excluded_ps)) {
592 592
         $ret = true;
593 593
     }
594 594
 
595 595
     // Normalize our data for item requirements, exclusions and cart data
596 596
     // First absint the items, then sort, and reset the array keys
597
-    $item_reqs = array_map( 'absint', $item_reqs );
598
-    asort( $item_reqs );
599
-    $item_reqs = array_values( $item_reqs );
597
+    $item_reqs = array_map('absint', $item_reqs);
598
+    asort($item_reqs);
599
+    $item_reqs = array_values($item_reqs);
600 600
 
601
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
602
-    asort( $excluded_ps );
603
-    $excluded_ps  = array_values( $excluded_ps );
601
+    $excluded_ps  = array_map('absint', $excluded_ps);
602
+    asort($excluded_ps);
603
+    $excluded_ps  = array_values($excluded_ps);
604 604
 
605
-    $cart_ids     = array_map( 'absint', $cart_ids );
606
-    asort( $cart_ids );
607
-    $cart_ids     = array_values( $cart_ids );
605
+    $cart_ids     = array_map('absint', $cart_ids);
606
+    asort($cart_ids);
607
+    $cart_ids     = array_values($cart_ids);
608 608
 
609 609
     // Ensure we have requirements before proceeding
610
-    if ( !$ret && ! empty( $item_reqs ) ) {
611
-        switch( $condition ) {
610
+    if (!$ret && !empty($item_reqs)) {
611
+        switch ($condition) {
612 612
             case 'all' :
613 613
                 // Default back to true
614 614
                 $ret = true;
615 615
 
616
-                foreach ( $item_reqs as $item_id ) {
617
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
618
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
616
+                foreach ($item_reqs as $item_id) {
617
+                    if (!wpinv_item_in_cart($item_id)) {
618
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
619 619
                         $ret = false;
620 620
                         break;
621 621
                     }
@@ -624,15 +624,15 @@  discard block
 block discarded – undo
624 624
                 break;
625 625
 
626 626
             default : // Any
627
-                foreach ( $item_reqs as $item_id ) {
628
-                    if ( wpinv_item_in_cart( $item_id ) ) {
627
+                foreach ($item_reqs as $item_id) {
628
+                    if (wpinv_item_in_cart($item_id)) {
629 629
                         $ret = true;
630 630
                         break;
631 631
                     }
632 632
                 }
633 633
 
634
-                if( ! $ret ) {
635
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
634
+                if (!$ret) {
635
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
636 636
                 }
637 637
 
638 638
                 break;
@@ -641,68 +641,68 @@  discard block
 block discarded – undo
641 641
         $ret = true;
642 642
     }
643 643
 
644
-    if( ! empty( $excluded_ps ) ) {
644
+    if (!empty($excluded_ps)) {
645 645
         // Check that there are items other than excluded ones in the cart
646
-        if( $cart_ids == $excluded_ps ) {
647
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
646
+        if ($cart_ids == $excluded_ps) {
647
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
648 648
             $ret = false;
649 649
         }
650 650
     }
651 651
 
652
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
652
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
653 653
 }
654 654
 
655
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
655
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
656 656
     global $wpi_checkout_id;
657 657
     
658 658
     $return = false;
659 659
 
660
-    if ( empty( $code_id ) ) {
661
-        $code_id = wpinv_get_discount_id_by_code( $code );
660
+    if (empty($code_id)) {
661
+        $code_id = wpinv_get_discount_id_by_code($code);
662 662
         
663
-        if( empty( $code_id ) ) {
663
+        if (empty($code_id)) {
664 664
             return false; // No discount was found
665 665
         }
666 666
     }
667 667
 
668
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
668
+    if (wpinv_discount_is_single_use($code_id)) {
669 669
         $payments = array();
670 670
 
671 671
         $user_id = 0;
672
-        if ( is_int( $user ) ) {
672
+        if (is_int($user)) {
673 673
             $user_id = $user;
674
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
674
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
675 675
             $user_id = $user_data->ID;
676
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
676
+        } else if ($user_data = get_user_by('login', $user)) {
677 677
             $user_id = $user_data->ID;
678 678
         }
679 679
 
680
-        if ( !$user_id ) {
681
-            $query    = array( 'user' => $user_id, 'limit' => false );
682
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching email
680
+        if (!$user_id) {
681
+            $query    = array('user' => $user_id, 'limit' => false);
682
+            $payments = wpinv_get_invoices($query); // Get all payments with matching email
683 683
         }
684 684
 
685
-        if ( $payments ) {
686
-            foreach ( $payments as $payment ) {
687
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
685
+        if ($payments) {
686
+            foreach ($payments as $payment) {
687
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
688 688
                     continue;
689 689
                 }
690 690
 
691 691
                 // Don't count discount used for current invoice chekcout.
692
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
692
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
693 693
                     continue;
694 694
                 }
695 695
 
696
-                $discounts = $payment->get_discounts( true );
697
-                if ( empty( $discounts ) ) {
696
+                $discounts = $payment->get_discounts(true);
697
+                if (empty($discounts)) {
698 698
                     continue;
699 699
                 }
700 700
 
701
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
701
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
702 702
 
703
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
704
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
705
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
703
+                if (!empty($discounts) && is_array($discounts)) {
704
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
705
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
706 706
                         $return = true;
707 707
                         break;
708 708
                     }
@@ -711,61 +711,61 @@  discard block
 block discarded – undo
711 711
         }
712 712
     }
713 713
 
714
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
714
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
715 715
 }
716 716
 
717
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
717
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
718 718
     $return      = false;
719
-    $discount_id = wpinv_get_discount_id_by_code( $code );
720
-    $user        = trim( $user );
719
+    $discount_id = wpinv_get_discount_id_by_code($code);
720
+    $user        = trim($user);
721 721
 
722
-    if ( wpinv_get_cart_contents() ) {
723
-        if ( $discount_id ) {
722
+    if (wpinv_get_cart_contents()) {
723
+        if ($discount_id) {
724 724
             if (
725
-                wpinv_is_discount_active( $discount_id ) &&
726
-                wpinv_check_discount_dates( $discount_id ) &&
727
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
728
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
729
-                wpinv_discount_is_min_met( $discount_id ) &&
730
-                wpinv_discount_is_max_met( $discount_id ) &&
731
-                wpinv_discount_item_reqs_met( $discount_id )
725
+                wpinv_is_discount_active($discount_id) &&
726
+                wpinv_check_discount_dates($discount_id) &&
727
+                !wpinv_is_discount_maxed_out($discount_id) &&
728
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
729
+                wpinv_discount_is_min_met($discount_id) &&
730
+                wpinv_discount_is_max_met($discount_id) &&
731
+                wpinv_discount_item_reqs_met($discount_id)
732 732
             ) {
733 733
                 $return = true;
734 734
             }
735
-        } elseif( $set_error ) {
736
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
735
+        } elseif ($set_error) {
736
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
737 737
         }
738 738
     }
739 739
 
740
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
740
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
741 741
 }
742 742
 
743
-function wpinv_get_discount_id_by_code( $code ) {
744
-    $discount = wpinv_get_discount_by_code( $code );
745
-    if( $discount ) {
743
+function wpinv_get_discount_id_by_code($code) {
744
+    $discount = wpinv_get_discount_by_code($code);
745
+    if ($discount) {
746 746
         return $discount->ID;
747 747
     }
748 748
     return false;
749 749
 }
750 750
 
751
-function wpinv_get_discounted_amount( $code, $base_price ) {
751
+function wpinv_get_discounted_amount($code, $base_price) {
752 752
     $amount      = $base_price;
753
-    $discount_id = wpinv_get_discount_id_by_code( $code );
753
+    $discount_id = wpinv_get_discount_id_by_code($code);
754 754
 
755
-    if( $discount_id ) {
756
-        $type        = wpinv_get_discount_type( $discount_id );
757
-        $rate        = wpinv_get_discount_amount( $discount_id );
755
+    if ($discount_id) {
756
+        $type        = wpinv_get_discount_type($discount_id);
757
+        $rate        = wpinv_get_discount_amount($discount_id);
758 758
 
759
-        if ( $type == 'flat' ) {
759
+        if ($type == 'flat') {
760 760
             // Set amount
761 761
             $amount = $base_price - $rate;
762
-            if ( $amount < 0 ) {
762
+            if ($amount < 0) {
763 763
                 $amount = 0;
764 764
             }
765 765
 
766 766
         } else {
767 767
             // Percentage discount
768
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
768
+            $amount = $base_price - ($base_price * ($rate / 100));
769 769
         }
770 770
 
771 771
     } else {
@@ -774,108 +774,108 @@  discard block
 block discarded – undo
774 774
 
775 775
     }
776 776
 
777
-    return apply_filters( 'wpinv_discounted_amount', $amount );
777
+    return apply_filters('wpinv_discounted_amount', $amount);
778 778
 }
779 779
 
780
-function wpinv_increase_discount_usage( $code ) {
780
+function wpinv_increase_discount_usage($code) {
781 781
 
782
-    $id   = wpinv_get_discount_id_by_code( $code );
783
-    $uses = wpinv_get_discount_uses( $id );
782
+    $id   = wpinv_get_discount_id_by_code($code);
783
+    $uses = wpinv_get_discount_uses($id);
784 784
 
785
-    if ( $uses ) {
785
+    if ($uses) {
786 786
         $uses++;
787 787
     } else {
788 788
         $uses = 1;
789 789
     }
790 790
 
791
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
791
+    update_post_meta($id, '_wpi_discount_uses', $uses);
792 792
 
793
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
793
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
794 794
 
795 795
     return $uses;
796 796
 
797 797
 }
798 798
 
799
-function wpinv_decrease_discount_usage( $code ) {
799
+function wpinv_decrease_discount_usage($code) {
800 800
 
801
-    $id   = wpinv_get_discount_id_by_code( $code );
802
-    $uses = wpinv_get_discount_uses( $id );
801
+    $id   = wpinv_get_discount_id_by_code($code);
802
+    $uses = wpinv_get_discount_uses($id);
803 803
 
804
-    if ( $uses ) {
804
+    if ($uses) {
805 805
         $uses--;
806 806
     }
807 807
 
808
-    if ( $uses < 0 ) {
808
+    if ($uses < 0) {
809 809
         $uses = 0;
810 810
     }
811 811
 
812
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
812
+    update_post_meta($id, '_wpi_discount_uses', $uses);
813 813
 
814
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
814
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
815 815
 
816 816
     return $uses;
817 817
 
818 818
 }
819 819
 
820
-function wpinv_format_discount_rate( $type, $amount ) {
821
-    if ( $type == 'flat' ) {
822
-        return wpinv_price( wpinv_format_amount( $amount ) );
820
+function wpinv_format_discount_rate($type, $amount) {
821
+    if ($type == 'flat') {
822
+        return wpinv_price(wpinv_format_amount($amount));
823 823
     } else {
824 824
         return $amount . '%';
825 825
     }
826 826
 }
827 827
 
828
-function wpinv_set_cart_discount( $code = '' ) {    
829
-    if ( wpinv_multiple_discounts_allowed() ) {
828
+function wpinv_set_cart_discount($code = '') {    
829
+    if (wpinv_multiple_discounts_allowed()) {
830 830
         // Get all active cart discounts
831 831
         $discounts = wpinv_get_cart_discounts();
832 832
     } else {
833 833
         $discounts = false; // Only one discount allowed per purchase, so override any existing
834 834
     }
835 835
 
836
-    if ( $discounts ) {
837
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
838
-        if( false !== $key ) {
839
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
836
+    if ($discounts) {
837
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
838
+        if (false !== $key) {
839
+            unset($discounts[$key]); // Can't set the same discount more than once
840 840
         }
841 841
         $discounts[] = $code;
842 842
     } else {
843 843
         $discounts = array();
844 844
         $discounts[] = $code;
845 845
     }
846
-    $discounts = array_values( $discounts );
846
+    $discounts = array_values($discounts);
847 847
     
848 848
     $data = wpinv_get_checkout_session();
849
-    if ( empty( $data ) ) {
849
+    if (empty($data)) {
850 850
         $data = array();
851 851
     } else {
852
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
853
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
854
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
852
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
853
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
854
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
855 855
         }
856 856
     }
857 857
     $data['cart_discounts'] = $discounts;
858 858
     
859
-    wpinv_set_checkout_session( $data );
859
+    wpinv_set_checkout_session($data);
860 860
     
861 861
     return $discounts;
862 862
 }
863 863
 
864
-function wpinv_unset_cart_discount( $code = '' ) {    
864
+function wpinv_unset_cart_discount($code = '') {    
865 865
     $discounts = wpinv_get_cart_discounts();
866 866
 
867
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
868
-        $key = array_search( $code, $discounts );
869
-        unset( $discounts[ $key ] );
867
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
868
+        $key = array_search($code, $discounts);
869
+        unset($discounts[$key]);
870 870
             
871 871
         $data = wpinv_get_checkout_session();
872 872
         $data['cart_discounts'] = $discounts;
873
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
874
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
875
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
873
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
874
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
875
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
876 876
         }
877 877
         
878
-        wpinv_set_checkout_session( $data );
878
+        wpinv_set_checkout_session($data);
879 879
     }
880 880
 
881 881
     return $discounts;
@@ -884,27 +884,27 @@  discard block
 block discarded – undo
884 884
 function wpinv_unset_all_cart_discounts() {
885 885
     $data = wpinv_get_checkout_session();
886 886
     
887
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
888
-        unset( $data['cart_discounts'] );
887
+    if (!empty($data) && isset($data['cart_discounts'])) {
888
+        unset($data['cart_discounts']);
889 889
         
890
-         wpinv_set_checkout_session( $data );
890
+         wpinv_set_checkout_session($data);
891 891
          return true;
892 892
     }
893 893
     
894 894
     return false;
895 895
 }
896 896
 
897
-function wpinv_get_cart_discounts( $items = array() ) {
897
+function wpinv_get_cart_discounts($items = array()) {
898 898
     $session = wpinv_get_checkout_session();
899 899
     
900
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
900
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
901 901
     return $discounts;
902 902
 }
903 903
 
904
-function wpinv_cart_has_discounts( $items = array() ) {
904
+function wpinv_cart_has_discounts($items = array()) {
905 905
     $ret = false;
906 906
 
907
-    if ( wpinv_get_cart_discounts( $items ) ) {
907
+    if (wpinv_get_cart_discounts($items)) {
908 908
         $ret = true;
909 909
     }
910 910
     
@@ -915,131 +915,131 @@  discard block
 block discarded – undo
915 915
     }
916 916
     */
917 917
 
918
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
918
+    return apply_filters('wpinv_cart_has_discounts', $ret);
919 919
 }
920 920
 
921
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
921
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
922 922
     $amount = 0.00;
923
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
923
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
924 924
 
925
-    if ( $items ) {
926
-        $discounts = wp_list_pluck( $items, 'discount' );
925
+    if ($items) {
926
+        $discounts = wp_list_pluck($items, 'discount');
927 927
 
928
-        if ( is_array( $discounts ) ) {
929
-            $discounts = array_map( 'floatval', $discounts );
930
-            $amount    = array_sum( $discounts );
928
+        if (is_array($discounts)) {
929
+            $discounts = array_map('floatval', $discounts);
930
+            $amount    = array_sum($discounts);
931 931
         }
932 932
     }
933 933
 
934
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
934
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
935 935
 }
936 936
 
937
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
938
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
937
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
938
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
939 939
     
940
-    if ( empty( $discount ) || empty( $items ) ) {
940
+    if (empty($discount) || empty($items)) {
941 941
         return 0;
942 942
     }
943 943
 
944 944
     $amount = 0;
945 945
     
946
-    foreach ( $items as $item ) {
947
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
946
+    foreach ($items as $item) {
947
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
948 948
     }
949 949
     
950
-    $amount = wpinv_round_amount( $amount );
950
+    $amount = wpinv_round_amount($amount);
951 951
 
952 952
     return $amount;
953 953
 }
954 954
 
955
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
955
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
956 956
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
957 957
     
958 958
     $amount = 0;
959 959
 
960
-    if ( empty( $item ) || empty( $item['id'] ) ) {
960
+    if (empty($item) || empty($item['id'])) {
961 961
         return $amount;
962 962
     }
963 963
 
964
-    if ( empty( $item['quantity'] ) ) {
964
+    if (empty($item['quantity'])) {
965 965
         return $amount;
966 966
     }
967 967
 
968
-    if ( empty( $item['options'] ) ) {
968
+    if (empty($item['options'])) {
969 969
         $item['options'] = array();
970 970
     }
971 971
 
972
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
972
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
973 973
     $discounted_price = $price;
974 974
 
975 975
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
976
-    if ( empty( $discounts ) ) {
976
+    if (empty($discounts)) {
977 977
         return $amount;
978 978
     }
979 979
 
980
-    if ( $discounts ) {
981
-        if ( is_array( $discounts ) ) {
982
-            $discounts = array_values( $discounts );
980
+    if ($discounts) {
981
+        if (is_array($discounts)) {
982
+            $discounts = array_values($discounts);
983 983
         } else {
984
-            $discounts = explode( ',', $discounts );
984
+            $discounts = explode(',', $discounts);
985 985
         }
986 986
     }
987 987
 
988
-    if( $discounts ) {
989
-        foreach ( $discounts as $discount ) {
990
-            $code_id = wpinv_get_discount_id_by_code( $discount );
988
+    if ($discounts) {
989
+        foreach ($discounts as $discount) {
990
+            $code_id = wpinv_get_discount_id_by_code($discount);
991 991
 
992 992
             // Check discount exists
993
-            if( ! $code_id ) {
993
+            if (!$code_id) {
994 994
                 continue;
995 995
             }
996 996
 
997
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
998
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
997
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
998
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
999 999
 
1000 1000
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1001
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1002
-                foreach ( $reqs as $item_id ) {
1003
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1004
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1001
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1002
+                foreach ($reqs as $item_id) {
1003
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1004
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1005 1005
                     }
1006 1006
                 }
1007 1007
             } else {
1008 1008
                 // This is a global cart discount
1009
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1010
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1009
+                if (!in_array($item['id'], $excluded_items)) {
1010
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1011 1011
                         $items_subtotal    = 0.00;
1012 1012
                         $cart_items        = wpinv_get_cart_contents();
1013 1013
                         
1014
-                        foreach ( $cart_items as $cart_item ) {
1015
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1016
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1017
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1014
+                        foreach ($cart_items as $cart_item) {
1015
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1016
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1017
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1018 1018
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1019 1019
                             }
1020 1020
                         }
1021 1021
 
1022
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1023
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1022
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1023
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1024 1024
                         $discounted_amount = $code_amount * $subtotal_percent;
1025 1025
                         $discounted_price -= $discounted_amount;
1026 1026
 
1027
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1027
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1028 1028
 
1029
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1029
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1030 1030
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1031 1031
                             $discounted_price -= $adjustment;
1032 1032
                         }
1033 1033
                     } else {
1034
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1034
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1035 1035
                     }
1036 1036
                 }
1037 1037
             }
1038 1038
         }
1039 1039
 
1040
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1040
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1041 1041
 
1042
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1042
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1043 1043
             $amount = $amount * $item['quantity'];
1044 1044
         }
1045 1045
     }
@@ -1047,59 +1047,59 @@  discard block
 block discarded – undo
1047 1047
     return $amount;
1048 1048
 }
1049 1049
 
1050
-function wpinv_cart_discounts_html( $items = array() ) {
1051
-    echo wpinv_get_cart_discounts_html( $items );
1050
+function wpinv_cart_discounts_html($items = array()) {
1051
+    echo wpinv_get_cart_discounts_html($items);
1052 1052
 }
1053 1053
 
1054
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1054
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1055 1055
     global $wpi_cart_columns;
1056 1056
     
1057
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1057
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1058 1058
     
1059
-    if ( !$discounts ) {
1060
-        $discounts = wpinv_get_cart_discounts( $items );
1059
+    if (!$discounts) {
1060
+        $discounts = wpinv_get_cart_discounts($items);
1061 1061
     }
1062 1062
 
1063
-    if ( !$discounts ) {
1063
+    if (!$discounts) {
1064 1064
         return;
1065 1065
     }
1066 1066
     
1067
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1067
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1068 1068
     
1069 1069
     $html = '';
1070 1070
 
1071
-    foreach ( $discounts as $discount ) {
1072
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1073
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1074
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1075
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1076
-        $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> ';
1071
+    foreach ($discounts as $discount) {
1072
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1073
+        $discount_value = wpinv_get_discount_amount($discount_id);
1074
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1075
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1076
+        $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> ';
1077 1077
         
1078 1078
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1079 1079
         ob_start();
1080
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1080
+        do_action('wpinv_checkout_table_discount_first', $items);
1081 1081
         $html .= ob_get_clean();
1082
-        $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>';
1082
+        $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>';
1083 1083
         ob_start();
1084
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1084
+        do_action('wpinv_checkout_table_discount_last', $items);
1085 1085
         $html .= ob_get_clean();
1086 1086
         $html .= '</tr>';
1087 1087
     }
1088 1088
 
1089
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1089
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1090 1090
 }
1091 1091
 
1092
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1092
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1093 1093
     $discounts = wpinv_get_cart_discounts();
1094 1094
 
1095
-    if ( empty( $discounts ) ) {
1095
+    if (empty($discounts)) {
1096 1096
         return false;
1097 1097
     }
1098 1098
 
1099
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1100
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1099
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1100
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1101 1101
 
1102
-    if ( $echo ) {
1102
+    if ($echo) {
1103 1103
         echo $amount;
1104 1104
     }
1105 1105
 
@@ -1107,133 +1107,133 @@  discard block
 block discarded – undo
1107 1107
 }
1108 1108
 
1109 1109
 function wpinv_remove_cart_discount() {
1110
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1110
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1111 1111
         return;
1112 1112
     }
1113 1113
 
1114
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1114
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1115 1115
 
1116
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1116
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1117 1117
 
1118
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1118
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1119 1119
 
1120
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1120
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1121 1121
 }
1122
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1122
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1123 1123
 
1124
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1124
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1125 1125
     $discounts = wpinv_get_cart_discounts();
1126 1126
 
1127
-    if ( !$discounts ) {
1127
+    if (!$discounts) {
1128 1128
         return;
1129 1129
     }
1130 1130
 
1131
-    foreach ( $discounts as $discount ) {
1132
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1133
-            wpinv_unset_cart_discount( $discount );
1131
+    foreach ($discounts as $discount) {
1132
+        if (!wpinv_is_discount_valid($discount)) {
1133
+            wpinv_unset_cart_discount($discount);
1134 1134
         }
1135 1135
     }
1136 1136
 }
1137
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1137
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1138 1138
 
1139 1139
 function wpinv_multiple_discounts_allowed() {
1140
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1141
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1140
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1141
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1142 1142
 }
1143 1143
 
1144 1144
 function wpinv_listen_for_cart_discount() {
1145 1145
     global $wpi_session;
1146 1146
     
1147
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1147
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1148 1148
         return;
1149 1149
     }
1150 1150
 
1151
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1151
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1152 1152
 
1153
-    $wpi_session->set( 'preset_discount', $code );
1153
+    $wpi_session->set('preset_discount', $code);
1154 1154
 }
1155 1155
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1156 1156
 
1157 1157
 function wpinv_apply_preset_discount() {
1158 1158
     global $wpi_session;
1159 1159
     
1160
-    $code = $wpi_session->get( 'preset_discount' );
1160
+    $code = $wpi_session->get('preset_discount');
1161 1161
 
1162
-    if ( !$code ) {
1162
+    if (!$code) {
1163 1163
         return;
1164 1164
     }
1165 1165
 
1166
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1166
+    if (!wpinv_is_discount_valid($code, '', false)) {
1167 1167
         return;
1168 1168
     }
1169 1169
     
1170
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1170
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1171 1171
 
1172
-    wpinv_set_cart_discount( $code );
1172
+    wpinv_set_cart_discount($code);
1173 1173
 
1174
-    $wpi_session->set( 'preset_discount', null );
1174
+    $wpi_session->set('preset_discount', null);
1175 1175
 }
1176 1176
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1177 1177
 
1178
-function wpinv_get_discount_label( $code, $echo = true ) {
1179
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1180
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1178
+function wpinv_get_discount_label($code, $echo = true) {
1179
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1180
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1181 1181
 
1182
-    if ( $echo ) {
1182
+    if ($echo) {
1183 1183
         echo $label;
1184 1184
     } else {
1185 1185
         return $label;
1186 1186
     }
1187 1187
 }
1188 1188
 
1189
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1190
-    $label = wp_sprintf( __( '%1$s Discount: %2$s', 'invoicing' ), $rate, $code );
1191
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1189
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1190
+    $label = wp_sprintf(__('%1$s Discount: %2$s', 'invoicing'), $rate, $code);
1191
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1192 1192
 
1193
-    if ( $echo ) {
1193
+    if ($echo) {
1194 1194
         echo $label;
1195 1195
     } else {
1196 1196
         return $label;
1197 1197
     }
1198 1198
 }
1199 1199
 
1200
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1201
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1200
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1201
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1202 1202
         return true;
1203 1203
     }
1204 1204
     
1205 1205
     return $check;
1206 1206
 }
1207
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1207
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1208 1208
 
1209 1209
 function wpinv_checkout_form_validate_discounts() {
1210 1210
     $discounts = wpinv_get_cart_discounts();
1211 1211
     
1212
-    if ( !empty( $discounts ) ) {
1212
+    if (!empty($discounts)) {
1213 1213
         $invalid = false;
1214 1214
         
1215
-        foreach ( $discounts as $key => $code ) {
1216
-            if ( !wpinv_is_discount_valid( $code, get_current_user_id() ) ) {
1215
+        foreach ($discounts as $key => $code) {
1216
+            if (!wpinv_is_discount_valid($code, get_current_user_id())) {
1217 1217
                 $invalid = true;
1218 1218
                 
1219
-                wpinv_unset_cart_discount( $code );
1219
+                wpinv_unset_cart_discount($code);
1220 1220
             }
1221 1221
         }
1222 1222
         
1223
-        if ( $invalid ) {
1223
+        if ($invalid) {
1224 1224
             $errors = wpinv_get_errors();
1225
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1227
-            wpinv_set_error( 'wpinv-discount-error', $error );
1225
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1226
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1227
+            wpinv_set_error('wpinv-discount-error', $error);
1228 1228
             
1229
-            wpinv_recalculate_tax( true );
1229
+            wpinv_recalculate_tax(true);
1230 1230
         }
1231 1231
     }
1232 1232
 }
1233
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1233
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1234 1234
 
1235 1235
 function wpinv_discount_amount() {
1236 1236
     $output = 0.00;
1237 1237
     
1238
-    return apply_filters( 'wpinv_discount_amount', $output );
1238
+    return apply_filters('wpinv_discount_amount', $output);
1239 1239
 }
1240 1240
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +245 added lines, -245 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = get_post( $value );
14
+            $item = get_post($value);
15 15
 
16
-            if( get_post_type( $item ) != 'wpi_item' ) {
16
+            if (get_post_type($item) != 'wpi_item') {
17 17
                 return false;
18 18
             }
19 19
 
@@ -21,16 +21,16 @@  discard block
 block discarded – undo
21 21
 
22 22
         case 'slug':
23 23
         case 'name':
24
-            $posts = get_posts( array(
24
+            $posts = get_posts(array(
25 25
                 'post_type'      => 'wpi_item',
26 26
                 'name'           => $value,
27 27
                 'posts_per_page' => 1,
28 28
                 'post_status'    => 'any'
29
-            ) );
29
+            ));
30 30
 
31 31
             break;
32 32
         case 'custom_id':
33
-            if ( empty( $value ) || empty( $type ) ) {
33
+            if (empty($value) || empty($type)) {
34 34
                 return false;
35 35
             }
36 36
             
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
                 'post_status'    => 'any',
51 51
                 'orderby'        => 'ID',
52 52
                 'order'          => 'ASC',
53
-                'meta_query'     => array( $meta_query )
53
+                'meta_query'     => array($meta_query)
54 54
             );
55 55
             
56
-            $posts = get_posts( $args );
56
+            $posts = get_posts($args);
57 57
 
58 58
             break;
59 59
 
@@ -61,17 +61,17 @@  discard block
 block discarded – undo
61 61
             return false;
62 62
     }
63 63
     
64
-    if ( !empty( $posts[0] ) ) {
65
-        return new WPInv_Item( $posts[0]->ID );
64
+    if (!empty($posts[0])) {
65
+        return new WPInv_Item($posts[0]->ID);
66 66
     }
67 67
 
68 68
     return false;
69 69
 }
70 70
 
71
-function wpinv_get_item( $item = 0 ) {
72
-    if ( is_numeric( $item ) ) {
73
-        $item = get_post( $item );
74
-        if ( ! $item || 'wpi_item' !== $item->post_type )
71
+function wpinv_get_item($item = 0) {
72
+    if (is_numeric($item)) {
73
+        $item = get_post($item);
74
+        if (!$item || 'wpi_item' !== $item->post_type)
75 75
             return null;
76 76
         return $item;
77 77
     }
@@ -84,136 +84,136 @@  discard block
 block discarded – undo
84 84
 
85 85
     $item = get_posts($args);
86 86
 
87
-    if ( $item ) {
87
+    if ($item) {
88 88
         return $item[0];
89 89
     }
90 90
 
91 91
     return null;
92 92
 }
93 93
 
94
-function wpinv_is_free_item( $item_id = 0 ) {
95
-    if( empty( $item_id ) ) {
94
+function wpinv_is_free_item($item_id = 0) {
95
+    if (empty($item_id)) {
96 96
         return false;
97 97
     }
98 98
 
99
-    $item = new WPInv_Item( $item_id );
99
+    $item = new WPInv_Item($item_id);
100 100
     
101 101
     return $item->is_free();
102 102
 }
103 103
 
104
-function wpinv_get_item_price( $item_id = 0 ) {
105
-    if( empty( $item_id ) ) {
104
+function wpinv_get_item_price($item_id = 0) {
105
+    if (empty($item_id)) {
106 106
         return false;
107 107
     }
108 108
 
109
-    $item = new WPInv_Item( $item_id );
109
+    $item = new WPInv_Item($item_id);
110 110
     
111 111
     return $item->get_price();
112 112
 }
113 113
 
114
-function wpinv_is_recurring_item( $item_id = 0 ) {
115
-    if( empty( $item_id ) ) {
114
+function wpinv_is_recurring_item($item_id = 0) {
115
+    if (empty($item_id)) {
116 116
         return false;
117 117
     }
118 118
 
119
-    $item = new WPInv_Item( $item_id );
119
+    $item = new WPInv_Item($item_id);
120 120
     
121 121
     return $item->is_recurring();
122 122
 }
123 123
 
124
-function wpinv_item_price( $item_id = 0 ) {
125
-    if( empty( $item_id ) ) {
124
+function wpinv_item_price($item_id = 0) {
125
+    if (empty($item_id)) {
126 126
         return false;
127 127
     }
128 128
 
129
-    $price = wpinv_get_item_price( $item_id );
130
-    $price = wpinv_price( wpinv_format_amount( $price ) );
129
+    $price = wpinv_get_item_price($item_id);
130
+    $price = wpinv_price(wpinv_format_amount($price));
131 131
     
132
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
132
+    return apply_filters('wpinv_item_price', $price, $item_id);
133 133
 }
134 134
 
135
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
136
-    if ( empty( $item_id ) ) {
135
+function wpinv_item_show_price($item_id = 0, $echo = true) {
136
+    if (empty($item_id)) {
137 137
         $item_id = get_the_ID();
138 138
     }
139 139
 
140
-    $price = wpinv_item_price( $item_id );
140
+    $price = wpinv_item_price($item_id);
141 141
 
142
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
142
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
143 143
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
144
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
144
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
145 145
 
146
-    if ( $echo ) {
146
+    if ($echo) {
147 147
         echo $formatted_price;
148 148
     } else {
149 149
         return $formatted_price;
150 150
     }
151 151
 }
152 152
 
153
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
154
-    if ( is_null( $amount_override ) ) {
155
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
153
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
154
+    if (is_null($amount_override)) {
155
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
156 156
     } else {
157 157
         $original_price = $amount_override;
158 158
     }
159 159
     
160 160
     $price = $original_price;
161 161
 
162
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
162
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
163 163
 }
164 164
 
165
-function wpinv_item_custom_singular_name( $item_id ) {
166
-    if( empty( $item_id ) ) {
165
+function wpinv_item_custom_singular_name($item_id) {
166
+    if (empty($item_id)) {
167 167
         return false;
168 168
     }
169 169
 
170
-    $item = new WPInv_Item( $item_id );
170
+    $item = new WPInv_Item($item_id);
171 171
     
172 172
     return $item->get_custom_singular_name();
173 173
 }
174 174
 
175 175
 function wpinv_get_item_types() {
176 176
     $item_types = array(
177
-            'custom'    => __( 'Standard', 'invoicing' ),
178
-            'fee'       => __( 'Fee', 'invoicing' ),
177
+            'custom'    => __('Standard', 'invoicing'),
178
+            'fee'       => __('Fee', 'invoicing'),
179 179
         );
180
-    return apply_filters( 'wpinv_get_item_types', $item_types );
180
+    return apply_filters('wpinv_get_item_types', $item_types);
181 181
 }
182 182
 
183 183
 function wpinv_item_types() {
184 184
     $item_types = wpinv_get_item_types();
185 185
     
186
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
186
+    return (!empty($item_types) ? array_keys($item_types) : array());
187 187
 }
188 188
 
189
-function wpinv_get_item_type( $item_id ) {
190
-    if( empty( $item_id ) ) {
189
+function wpinv_get_item_type($item_id) {
190
+    if (empty($item_id)) {
191 191
         return false;
192 192
     }
193 193
 
194
-    $item = new WPInv_Item( $item_id );
194
+    $item = new WPInv_Item($item_id);
195 195
     
196 196
     return $item->get_type();
197 197
 }
198 198
 
199
-function wpinv_item_type( $item_id ) {
199
+function wpinv_item_type($item_id) {
200 200
     $item_types = wpinv_get_item_types();
201 201
     
202
-    $item_type = wpinv_get_item_type( $item_id );
202
+    $item_type = wpinv_get_item_type($item_id);
203 203
     
204
-    if ( empty( $item_type ) ) {
204
+    if (empty($item_type)) {
205 205
         $item_type = '-';
206 206
     }
207 207
     
208
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
208
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
209 209
 
210
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
210
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
211 211
 }
212 212
 
213
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
213
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
214 214
     global $wpinv_logs;
215 215
     
216
-    if ( empty( $wpinv_logs ) ) {
216
+    if (empty($wpinv_logs)) {
217 217
         return false;
218 218
     }
219 219
 
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
         'log_type'		=> 'wpi_item'
223 223
     );
224 224
 
225
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
225
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
226 226
 
227 227
     $log_meta = array(
228 228
         'user_info'	=> $user_info,
@@ -232,253 +232,253 @@  discard block
 block discarded – undo
232 232
         'invoice_id'=> $invoice_id,
233 233
     );
234 234
 
235
-    $wpinv_logs->insert_log( $log_data, $log_meta );
235
+    $wpinv_logs->insert_log($log_data, $log_meta);
236 236
 }
237 237
 
238
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
239
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
238
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
239
+    if ('wpi_item' !== get_post_type($item_id))
240 240
         return;
241 241
 
242 242
     global $wpinv_logs;
243 243
     
244
-    if ( empty( $wpinv_logs ) ) {
244
+    if (empty($wpinv_logs)) {
245 245
         return false;
246 246
     }
247 247
 
248 248
     // Remove all log entries related to this item
249
-    $wpinv_logs->delete_logs( $item_id );
249
+    $wpinv_logs->delete_logs($item_id);
250 250
 }
251
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
251
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
252 252
 
253
-function wpinv_get_random_item( $post_ids = true ) {
254
-    wpinv_get_random_items( 1, $post_ids );
253
+function wpinv_get_random_item($post_ids = true) {
254
+    wpinv_get_random_items(1, $post_ids);
255 255
 }
256 256
 
257
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
258
-    if ( $post_ids ) {
259
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
257
+function wpinv_get_random_items($num = 3, $post_ids = true) {
258
+    if ($post_ids) {
259
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
260 260
     } else {
261
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
261
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
262 262
     }
263 263
     
264
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
264
+    $args = apply_filters('wpinv_get_random_items', $args);
265 265
     
266
-    return get_posts( $args );
266
+    return get_posts($args);
267 267
 }
268 268
 
269
-function wpinv_get_item_token( $url = '' ) {
269
+function wpinv_get_item_token($url = '') {
270 270
     $args    = array();
271
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
272
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
271
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
272
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
273 273
 
274
-    $parts   = parse_url( $url );
274
+    $parts   = parse_url($url);
275 275
     $options = array();
276 276
 
277
-    if ( isset( $parts['query'] ) ) {
278
-        wp_parse_str( $parts['query'], $query_args );
277
+    if (isset($parts['query'])) {
278
+        wp_parse_str($parts['query'], $query_args);
279 279
 
280
-        if ( ! empty( $query_args['o'] ) ) {
281
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
280
+        if (!empty($query_args['o'])) {
281
+            $options = explode(':', rawurldecode($query_args['o']));
282 282
 
283
-            if ( in_array( 'ip', $options ) ) {
283
+            if (in_array('ip', $options)) {
284 284
                 $args['ip'] = wpinv_get_ip();
285 285
             }
286 286
 
287
-            if ( in_array( 'ua', $options ) ) {
287
+            if (in_array('ua', $options)) {
288 288
                 $ua = wpinv_get_user_agent();
289
-                $args['user_agent'] = rawurlencode( $ua );
289
+                $args['user_agent'] = rawurlencode($ua);
290 290
             }
291 291
         }
292 292
     }
293 293
 
294
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
294
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
295 295
 
296 296
     $args['secret'] = $secret;
297 297
     $args['token']  = false;
298 298
 
299
-    $url   = add_query_arg( $args, $url );
300
-    $parts = parse_url( $url );
299
+    $url   = add_query_arg($args, $url);
300
+    $parts = parse_url($url);
301 301
 
302
-    if ( ! isset( $parts['path'] ) ) {
302
+    if (!isset($parts['path'])) {
303 303
         $parts['path'] = '';
304 304
     }
305 305
 
306
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
306
+    $token = md5($parts['path'] . '?' . $parts['query']);
307 307
 
308 308
     return $token;
309 309
 }
310 310
 
311
-function wpinv_validate_url_token( $url = '' ) {
311
+function wpinv_validate_url_token($url = '') {
312 312
     $ret   = false;
313
-    $parts = parse_url( $url );
313
+    $parts = parse_url($url);
314 314
 
315
-    if ( isset( $parts['query'] ) ) {
316
-        wp_parse_str( $parts['query'], $query_args );
315
+    if (isset($parts['query'])) {
316
+        wp_parse_str($parts['query'], $query_args);
317 317
 
318
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
318
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
319 319
             'item',
320 320
             'ttl',
321 321
             'token'
322
-        ) );
322
+        ));
323 323
 
324 324
         $remove = array();
325 325
 
326
-        foreach( $query_args as $key => $value ) {
327
-            if( false === in_array( $key, $allowed ) ) {
326
+        foreach ($query_args as $key => $value) {
327
+            if (false === in_array($key, $allowed)) {
328 328
                 $remove[] = $key;
329 329
             }
330 330
         }
331 331
 
332
-        if( ! empty( $remove ) ) {
333
-            $url = remove_query_arg( $remove, $url );
332
+        if (!empty($remove)) {
333
+            $url = remove_query_arg($remove, $url);
334 334
         }
335 335
 
336
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
337
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
336
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
337
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
338 338
         }
339 339
 
340
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
340
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
341 341
             $ret = true;
342 342
         }
343 343
 
344 344
     }
345 345
 
346
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
346
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
347 347
 }
348 348
 
349
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
349
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
350 350
     $cart_items = wpinv_get_cart_contents();
351 351
 
352 352
     $ret = false;
353 353
 
354
-    if ( is_array( $cart_items ) ) {
355
-        foreach ( $cart_items as $item ) {
356
-            if ( $item['id'] == $item_id ) {
354
+    if (is_array($cart_items)) {
355
+        foreach ($cart_items as $item) {
356
+            if ($item['id'] == $item_id) {
357 357
                 $ret = true;
358 358
                 break;
359 359
             }
360 360
         }
361 361
     }
362 362
 
363
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
363
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
364 364
 }
365 365
 
366
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
366
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
367 367
     $tax = 0;
368
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
369
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
370
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
368
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
369
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
370
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
371 371
 
372
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
372
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
375
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
376 376
 }
377 377
 
378
-function wpinv_cart_item_price( $item ) {
378
+function wpinv_cart_item_price($item) {
379 379
     $use_taxes  = wpinv_use_taxes();
380
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
381
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
382
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
383
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
384
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
385
-    
386
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
387
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
380
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
381
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
382
+    $options    = isset($item['options']) ? $item['options'] : array();
383
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
384
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
385
+    
386
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
387
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
388 388
             $price += $tax;
389 389
         }
390 390
         
391
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
391
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
392 392
             $price -= $tax;
393 393
         }        
394 394
     }
395 395
 
396
-    $price = wpinv_price( wpinv_format_amount( $price ) );
396
+    $price = wpinv_price(wpinv_format_amount($price));
397 397
 
398
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
398
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
399 399
 }
400 400
 
401
-function wpinv_cart_item_subtotal( $item ) {
402
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
403
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
401
+function wpinv_cart_item_subtotal($item) {
402
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
403
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
404 404
 
405
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
405
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
406 406
 }
407 407
 
408
-function wpinv_cart_item_tax( $item ) {
408
+function wpinv_cart_item_tax($item) {
409 409
     $tax        = '';
410 410
     $tax_rate   = '';
411 411
     
412
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
413
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
414
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
415
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
412
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
413
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
414
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
415
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
416 416
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
417 417
     }
418 418
     
419
-    $tax        = $tax . $tax_rate;
419
+    $tax = $tax . $tax_rate;
420 420
     
421
-    if ( $tax === '' ) {
421
+    if ($tax === '') {
422 422
         $tax = 0; // Zero tax
423 423
     }
424 424
 
425
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
425
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
426 426
 }
427 427
 
428
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
428
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
429 429
     $price = 0;
430 430
     
431 431
     // Set custom price
432
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
432
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
433 433
         $price = $cart_item['custom_price'];
434 434
     } else {
435
-        $variable_prices = wpinv_has_variable_prices( $item_id );
435
+        $variable_prices = wpinv_has_variable_prices($item_id);
436 436
 
437
-        if ( $variable_prices ) {
438
-            $prices = wpinv_get_variable_prices( $item_id );
437
+        if ($variable_prices) {
438
+            $prices = wpinv_get_variable_prices($item_id);
439 439
 
440
-            if ( $prices ) {
441
-                if( ! empty( $options ) ) {
442
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
440
+            if ($prices) {
441
+                if (!empty($options)) {
442
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
443 443
                 } else {
444 444
                     $price = false;
445 445
                 }
446 446
             }
447 447
         }
448 448
 
449
-        if( ! $variable_prices || false === $price ) {
449
+        if (!$variable_prices || false === $price) {
450 450
             // Get the standard Item price if not using variable prices
451
-            $price = wpinv_get_item_price( $item_id );
451
+            $price = wpinv_get_item_price($item_id);
452 452
         }
453 453
     }
454 454
 
455
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
456
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
455
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
456
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
457 457
     }
458 458
 
459
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
459
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
460 460
 }
461 461
 
462
-function wpinv_get_cart_item_price_id( $item = array() ) {
463
-    if( isset( $item['item_number'] ) ) {
464
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
462
+function wpinv_get_cart_item_price_id($item = array()) {
463
+    if (isset($item['item_number'])) {
464
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
465 465
     } else {
466
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
466
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
467 467
     }
468 468
     return $price_id;
469 469
 }
470 470
 
471
-function wpinv_get_cart_item_price_name( $item = array() ) {
472
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
473
-    $prices   = wpinv_get_variable_prices( $item['id'] );
474
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
475
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
471
+function wpinv_get_cart_item_price_name($item = array()) {
472
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
473
+    $prices   = wpinv_get_variable_prices($item['id']);
474
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
475
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
476 476
 }
477 477
 
478
-function wpinv_get_cart_item_name( $item = array() ) {
479
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
478
+function wpinv_get_cart_item_name($item = array()) {
479
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
480 480
 
481
-    if ( empty( $item_title ) ) {
481
+    if (empty($item_title)) {
482 482
         $item_title = $item['id'];
483 483
     }
484 484
 
@@ -488,23 +488,23 @@  discard block
 block discarded – undo
488 488
     }
489 489
     */
490 490
 
491
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
491
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
492 492
 }
493 493
 
494
-function wpinv_has_variable_prices( $item_id = 0 ) {
494
+function wpinv_has_variable_prices($item_id = 0) {
495 495
     return false;
496 496
 }
497 497
 
498
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
498
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
499 499
     $cart_items = wpinv_get_cart_contents();
500 500
 
501
-    if ( !is_array( $cart_items ) ) {
501
+    if (!is_array($cart_items)) {
502 502
         return false; // Empty cart
503 503
     } else {
504
-        foreach ( $cart_items as $position => $item ) {
505
-            if ( $item['id'] == $item_id ) {
506
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
507
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
504
+        foreach ($cart_items as $position => $item) {
505
+            if ($item['id'] == $item_id) {
506
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
507
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
508 508
                         return $position;
509 509
                     }
510 510
                 } else {
@@ -517,80 +517,80 @@  discard block
 block discarded – undo
517 517
     return false; // Not found
518 518
 }
519 519
 
520
-function wpinv_get_cart_item_quantity( $item ) {
521
-    if ( wpinv_item_quantities_enabled() ) {
522
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
520
+function wpinv_get_cart_item_quantity($item) {
521
+    if (wpinv_item_quantities_enabled()) {
522
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
523 523
     } else {
524 524
         $quantity = 1;
525 525
     }
526 526
     
527
-    if ( $quantity < 1 ) {
527
+    if ($quantity < 1) {
528 528
         $quantity = 1;
529 529
     }
530 530
     
531
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
531
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
532 532
 }
533 533
 
534
-function wpinv_get_item_suffix( $item, $html = true ) {
535
-    if ( empty( $item ) ) {
534
+function wpinv_get_item_suffix($item, $html = true) {
535
+    if (empty($item)) {
536 536
         return NULL;
537 537
     }
538 538
     
539
-    if ( is_int( $item ) ) {
540
-        $item = new WPInv_Item( $item );
539
+    if (is_int($item)) {
540
+        $item = new WPInv_Item($item);
541 541
     }
542 542
     
543
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
543
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
544 544
         return NULL;
545 545
     }
546 546
     
547
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
547
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
548 548
     
549
-    if ( !$html && $suffix ) {
550
-        $suffix = strip_tags( $suffix );
549
+    if (!$html && $suffix) {
550
+        $suffix = strip_tags($suffix);
551 551
     }
552 552
     
553
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
553
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
554 554
 }
555 555
 
556
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
557
-    if ( empty( $item ) ) {
556
+function wpinv_remove_item($item = 0, $force_delete = false) {
557
+    if (empty($item)) {
558 558
         return NULL;
559 559
     }
560 560
     
561
-    if ( is_int( $item ) ) {
562
-        $item = new WPInv_Item( $item );
561
+    if (is_int($item)) {
562
+        $item = new WPInv_Item($item);
563 563
     }
564 564
     
565
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
565
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
566 566
         return NULL;
567 567
     }
568 568
     
569
-    do_action( 'wpinv_pre_delete_item', $item );
569
+    do_action('wpinv_pre_delete_item', $item);
570 570
 
571
-    wp_delete_post( $item->ID, $force_delete );
571
+    wp_delete_post($item->ID, $force_delete);
572 572
 
573
-    do_action( 'wpinv_post_delete_item', $item );
573
+    do_action('wpinv_post_delete_item', $item);
574 574
 }
575 575
 
576
-function wpinv_can_delete_item( $post_id ) {
577
-    $return = current_user_can( 'manage_options' ) ? true : false;
576
+function wpinv_can_delete_item($post_id) {
577
+    $return = current_user_can('manage_options') ? true : false;
578 578
     
579
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
579
+    if ($return && wpinv_item_in_use($post_id)) {
580 580
         $return = false; // Don't delete item already use in invoices.
581 581
     }
582 582
     
583
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
583
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
584 584
 }
585 585
 
586 586
 function wpinv_admin_action_delete() {
587 587
     $screen = get_current_screen();
588 588
     
589
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
589
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
590 590
         $post_ids = array();
591 591
         
592
-        foreach ( $_REQUEST['post'] as $post_id ) {
593
-            if ( !wpinv_can_delete_item( $post_id ) ) {
592
+        foreach ($_REQUEST['post'] as $post_id) {
593
+            if (!wpinv_can_delete_item($post_id)) {
594 594
                 continue;
595 595
             }
596 596
             
@@ -600,80 +600,80 @@  discard block
 block discarded – undo
600 600
         $_REQUEST['post'] = $post_ids;
601 601
     }
602 602
 }
603
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
604
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
603
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
604
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
605 605
 
606
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
607
-    if ( $post->post_type == 'wpi_item' ) {
608
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
606
+function wpinv_check_delete_item($check, $post, $force_delete) {
607
+    if ($post->post_type == 'wpi_item') {
608
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
609 609
             return true;
610 610
         }
611 611
     }
612 612
     
613 613
     return $check;
614 614
 }
615
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
615
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
616 616
 
617
-function wpinv_item_in_use( $item_id ) {
617
+function wpinv_item_in_use($item_id) {
618 618
     global $wpdb, $wpi_items_in_use;
619 619
     
620
-    if ( !$item_id > 0 ) {
620
+    if (!$item_id > 0) {
621 621
         return false;
622 622
     }
623 623
     
624
-    if ( !empty( $wpi_items_in_use ) ) {
625
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
624
+    if (!empty($wpi_items_in_use)) {
625
+        if (isset($wpi_items_in_use[$item_id])) {
626 626
             return $wpi_items_in_use[$item_id];
627 627
         }
628 628
     } else {
629 629
         $wpi_items_in_use = array();
630 630
     }
631 631
     
632
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true ) );
632
+    $statuses = array_keys(wpinv_get_invoice_statuses(true));
633 633
     
634
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
635
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
634
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
635
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
636 636
     
637 637
     $wpi_items_in_use[$item_id] = $in_use;
638 638
     
639 639
     return $in_use;
640 640
 }
641 641
 
642
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
642
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
643 643
     // Set some defaults
644 644
     $defaults = array(
645
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
646
-        'title'                => '',                                                      // Required. Item title.
647
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
648
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
649
-        'status'               => 'pending',                                               // Optional. pending, publish
650
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
651
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
652
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
653
-        'excerpt'              => '',                                                      // Optional. Item short description
645
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
646
+        'title'                => '', // Required. Item title.
647
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
648
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
649
+        'status'               => 'pending', // Optional. pending, publish
650
+        'custom_name'          => '', // Optional. Plural sub title for item.
651
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
652
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
653
+        'excerpt'              => '', // Optional. Item short description
654 654
         /* Recurring item fields */
655
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
656
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
657
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
658
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
659
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
660
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
661
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
655
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
656
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
657
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
658
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
659
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
660
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
661
+        'trial_interval'       => 0, // Optional. Any integer number.
662 662
     );
663 663
     
664
-    $data = wp_parse_args( $args, $defaults );
664
+    $data = wp_parse_args($args, $defaults);
665 665
     
666
-    if ( empty( $data['type'] ) ) {
666
+    if (empty($data['type'])) {
667 667
         $data['type'] = 'custom';
668 668
     }
669 669
     
670
-    if ( !empty( $data['custom_id'] ) ) {
671
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
670
+    if (!empty($data['custom_id'])) {
671
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
672 672
     } else {
673 673
         $item = NULL;
674 674
     }
675 675
     
676
-    if ( !$force_update && !empty( $item ) ) {
676
+    if (!$force_update && !empty($item)) {
677 677
         return $item;
678 678
     }
679 679
         
@@ -682,18 +682,18 @@  discard block
 block discarded – undo
682 682
     $meta['custom_id']              = $data['custom_id'];
683 683
     $meta['custom_singular_name']   = $data['custom_singular_name'];
684 684
     $meta['custom_name']            = $data['custom_name'];
685
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
685
+    $meta['price']                  = wpinv_round_amount($data['price']);
686 686
     $meta['vat_rule']               = $data['vat_rule'];
687 687
     $meta['vat_class']              = '_standard';
688 688
     
689
-    if ( !empty( $data['is_recurring'] ) ) {
689
+    if (!empty($data['is_recurring'])) {
690 690
         $meta['is_recurring']       = $data['is_recurring'];
691 691
         $meta['recurring_period']   = $data['recurring_period'];
692
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
693
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
692
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
693
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
694 694
         $meta['free_trial']         = $data['free_trial'];
695 695
         $meta['trial_period']       = $data['trial_period'];
696
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
696
+        $meta['trial_interval']     = absint($data['trial_interval']);
697 697
     } else {
698 698
         $meta['is_recurring']       = 0;
699 699
         $meta['recurring_period']   = '';
@@ -704,18 +704,18 @@  discard block
 block discarded – undo
704 704
         $meta['trial_interval']     = '';
705 705
     }
706 706
     
707
-    $post_data  = array( 
707
+    $post_data = array( 
708 708
         'post_title'    => $data['title'],
709 709
         'post_excerpt'  => $data['excerpt'],
710 710
         'post_status'   => $data['status'],
711 711
         'meta'          => $meta
712 712
     );
713 713
 
714
-    if ( !empty( $item ) ) {
715
-        $item->update( $post_data, $wp_error );
714
+    if (!empty($item)) {
715
+        $item->update($post_data, $wp_error);
716 716
     } else {
717 717
         $item = new WPInv_Item();
718
-        $item->create( $post_data, $wp_error );
718
+        $item->create($post_data, $wp_error);
719 719
     }
720 720
     
721 721
     return $item;
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
             self::$instance->reports    = new WPInv_Reports();
24 24
         }
25 25
         
26
-        do_action( 'wpinv_loaded' );
26
+        do_action('wpinv_loaded');
27 27
         
28 28
         return self::$instance;
29 29
     }
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
     }
34 34
     
35 35
     public function define_constants() {
36
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
37
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
36
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
37
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
38 38
     }
39 39
     
40 40
     private function actions() {
41 41
         /* Internationalize the text strings used. */
42
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
42
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
43 43
         
44 44
         /* Perform actions on admin initialization. */
45
-        add_action( 'admin_init', array( &$this, 'admin_init') );
46
-        add_action( 'init', array( &$this, 'init' ), 3 );
47
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
48
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
45
+        add_action('admin_init', array(&$this, 'admin_init'));
46
+        add_action('init', array(&$this, 'init'), 3);
47
+        add_action('init', array('WPInv_Shortcodes', 'init'));
48
+        add_action('init', array(&$this, 'wpinv_actions'));
49 49
         
50
-        if ( class_exists( 'BuddyPress' ) ) {
51
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
50
+        if (class_exists('BuddyPress')) {
51
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
52 52
         }
53 53
 
54
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
54
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
55 55
         
56
-        if ( is_admin() ) {
57
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
58
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
56
+        if (is_admin()) {
57
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
58
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
59 59
         } else {
60
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
60
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
61 61
         }
62 62
         
63 63
         /**
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
          *
68 68
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
69 69
          */
70
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
70
+        do_action_ref_array('wpinv_actions', array(&$this));
71 71
 
72
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
72
+        add_action('admin_init', array(&$this, 'activation_redirect'));
73 73
     }
74 74
     
75 75
     public function plugins_loaded() {
@@ -83,193 +83,193 @@  discard block
 block discarded – undo
83 83
      * @since 1.0
84 84
      */
85 85
     public function load_textdomain() {
86
-        $locale = apply_filters( 'plugin_locale', get_locale(), 'invoicing' );
86
+        $locale = apply_filters('plugin_locale', get_locale(), 'invoicing');
87 87
         
88
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
89
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
88
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
89
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
90 90
         
91 91
         /**
92 92
          * Define language constants.
93 93
          */
94
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
94
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
95 95
     }
96 96
         
97 97
     public function includes() {
98 98
         global $wpinv_options;
99 99
         
100
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
100
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
101 101
         $wpinv_options = wpinv_get_settings();
102 102
         
103
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
104
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
106
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
107
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
103
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
104
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
106
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
107
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gd-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
118 118
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
119 119
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
121 121
         //require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscription.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
129
-        if ( !class_exists( 'Geodir_EUVat' ) ) {
130
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
129
+        if (!class_exists('Geodir_EUVat')) {
130
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
131 131
         }
132 132
         
133
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
134
-        if ( !empty( $gateways ) ) {
135
-            foreach ( $gateways as $gateway ) {
136
-                if ( $gateway == 'manual' ) {
133
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
134
+        if (!empty($gateways)) {
135
+            foreach ($gateways as $gateway) {
136
+                if ($gateway == 'manual') {
137 137
                     continue;
138 138
                 }
139 139
                 
140 140
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
141 141
                 
142
-                if ( file_exists( $gateway_file ) ) {
143
-                    require_once( $gateway_file );
142
+                if (file_exists($gateway_file)) {
143
+                    require_once($gateway_file);
144 144
                 }
145 145
             }
146 146
         }
147
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
147
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
148 148
         
149
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
150
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
151
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
152
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
149
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
150
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
151
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
152
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
153 153
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
154
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
155
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
156
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
157
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
158
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
154
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
155
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
156
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
157
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
158
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
159 159
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
160 160
         }
161 161
         
162 162
         // include css inliner
163
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
164
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
163
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
164
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
165 165
         }
166 166
         
167
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
167
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
168 168
     }
169 169
     
170 170
     public function init() {
171 171
     }
172 172
     
173 173
     public function admin_init() {
174
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
174
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
175 175
         }
176 176
         
177
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
177
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
178 178
     }
179 179
 
180 180
     public function activation_redirect() {
181 181
         // Bail if no activation redirect
182
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
182
+        if (!get_transient('_wpinv_activation_redirect')) {
183 183
             return;
184 184
         }
185 185
 
186 186
         // Delete the redirect transient
187
-        delete_transient( '_wpinv_activation_redirect' );
187
+        delete_transient('_wpinv_activation_redirect');
188 188
 
189 189
         // Bail if activating from network, or bulk
190
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
190
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
191 191
             return;
192 192
         }
193 193
 
194
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
194
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
195 195
         exit;
196 196
     }
197 197
     
198 198
     public function enqueue_scripts() {
199
-        $suffix       = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
199
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
200 200
         
201
-        wp_deregister_style( 'font-awesome' );
202
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
203
-        wp_enqueue_style( 'font-awesome' );
201
+        wp_deregister_style('font-awesome');
202
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
203
+        wp_enqueue_style('font-awesome');
204 204
         
205
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
206
-        wp_enqueue_style( 'wpinv_front_style' );
205
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
206
+        wp_enqueue_style('wpinv_front_style');
207 207
                
208 208
         // Register scripts
209
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
210
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array( 'jquery', 'wpinv-vat-script' ),  WPINV_VERSION );
209
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
210
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front' . $suffix . '.js', array('jquery', 'wpinv-vat-script'), WPINV_VERSION);
211 211
         
212 212
         $localize                         = array();
213
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
214
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
213
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
214
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
215 215
         $localize['currency_symbol']      = wpinv_currency_symbol();
216 216
         $localize['currency_pos']         = wpinv_currency_position();
217 217
         $localize['thousand_sep']         = wpinv_thousands_separator();
218 218
         $localize['decimal_sep']          = wpinv_decimal_separator();
219 219
         $localize['decimals']             = wpinv_decimals();
220 220
         
221
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
221
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
222 222
         
223
-        wp_enqueue_script( 'jquery-blockui' );
224
-        wp_enqueue_script( 'wpinv-front-script' );
225
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
223
+        wp_enqueue_script('jquery-blockui');
224
+        wp_enqueue_script('wpinv-front-script');
225
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
226 226
     }
227 227
     
228 228
     public function admin_enqueue_scripts() {
229 229
         global $post, $pagenow;
230 230
         
231 231
         $post_type  = wpinv_admin_post_type();
232
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
232
+        $suffix     = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
233 233
         
234
-        wp_deregister_style( 'font-awesome' );
235
-        wp_register_style( 'font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0' );
236
-        wp_enqueue_style( 'font-awesome' );
234
+        wp_deregister_style('font-awesome');
235
+        wp_register_style('font-awesome', '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome' . $suffix . '.css', array(), '4.7.0');
236
+        wp_enqueue_style('font-awesome');
237 237
         
238
-        wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
239
-        wp_enqueue_style( 'jquery-ui-css' );
238
+        wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
239
+        wp_enqueue_style('jquery-ui-css');
240 240
         
241
-        wp_register_style( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2' );
242
-        wp_enqueue_style( 'jquery-chosen' );
241
+        wp_register_style('jquery-chosen', WPINV_PLUGIN_URL . 'assets/css/chosen' . $suffix . '.css', array(), '1.6.2');
242
+        wp_enqueue_style('jquery-chosen');
243 243
 
244
-        wp_register_script( 'jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array( 'jquery' ), '1.6.2' );
245
-        wp_enqueue_script( 'jquery-chosen' );
244
+        wp_register_script('jquery-chosen', WPINV_PLUGIN_URL . 'assets/js/chosen.jquery' . $suffix . '.js', array('jquery'), '1.6.2');
245
+        wp_enqueue_script('jquery-chosen');
246 246
         
247
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
248
-        wp_enqueue_style( 'wpinv_meta_box_style' );
247
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
248
+        wp_enqueue_style('wpinv_meta_box_style');
249 249
         
250
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
251
-        wp_enqueue_style( 'wpinv_admin_style' );
250
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
251
+        wp_enqueue_style('wpinv_admin_style');
252 252
         
253
-        if ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
254
-            wp_enqueue_script( 'jquery-ui-datepicker' );
253
+        if ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
254
+            wp_enqueue_script('jquery-ui-datepicker');
255 255
         }
256 256
 
257
-        wp_enqueue_style( 'wp-color-picker' );
258
-        wp_enqueue_script( 'wp-color-picker' );
257
+        wp_enqueue_style('wp-color-picker');
258
+        wp_enqueue_script('wp-color-picker');
259 259
         
260
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
260
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
261 261
         
262
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array( 'jquery', 'jquery-blockui' ),  WPINV_VERSION );
263
-        wp_enqueue_script( 'wpinv-admin-script' );
262
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin' . $suffix . '.js', array('jquery', 'jquery-blockui'), WPINV_VERSION);
263
+        wp_enqueue_script('wpinv-admin-script');
264 264
         
265 265
         $localize                               = array();
266
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
267
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
268
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
269
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
270
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
271
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
272
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
266
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
267
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
268
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
269
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
270
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
271
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
272
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
273 273
         $localize['tax']                        = wpinv_tax_amount();
274 274
         $localize['discount']                   = wpinv_discount_amount();
275 275
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -277,55 +277,55 @@  discard block
 block discarded – undo
277 277
         $localize['thousand_sep']               = wpinv_thousands_separator();
278 278
         $localize['decimal_sep']                = wpinv_decimal_separator();
279 279
         $localize['decimals']                   = wpinv_decimals();
280
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
281
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
282
-        $localize['status_pending']             = wpinv_status_nicename( 'pending' );
283
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
284
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
285
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
286
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
287
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
288
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
289
-        $localize['hasGD']                      = wpinv_gd_active();;
280
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
281
+        $localize['status_publish']             = wpinv_status_nicename('publish');
282
+        $localize['status_pending']             = wpinv_status_nicename('pending');
283
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
284
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
285
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
286
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
287
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
288
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
289
+        $localize['hasGD']                      = wpinv_gd_active(); ;
290 290
         $localize['hasPM']                      = wpinv_pm_active();
291
-        $localize['emptyInvoice']               = __( 'Add atleast one item to save invoice!', 'invoicing' );
292
-        $localize['deletePackage']              = __( 'GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing' );
293
-        $localize['deletePackages']             = __( 'GD package items should be deleted from GD payment manager only', 'invoicing' );
294
-        $localize['deleteInvoiceFirst']         = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
291
+        $localize['emptyInvoice']               = __('Add atleast one item to save invoice!', 'invoicing');
292
+        $localize['deletePackage']              = __('GD package items should be deleted from GD payment manager only, otherwise it will break invoices that created with this package!', 'invoicing');
293
+        $localize['deletePackages']             = __('GD package items should be deleted from GD payment manager only', 'invoicing');
294
+        $localize['deleteInvoiceFirst']         = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
295 295
         
296
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
296
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
297 297
     }
298 298
     
299
-    public function admin_body_class( $classes ) {
299
+    public function admin_body_class($classes) {
300 300
         global $pagenow;
301 301
         
302
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
302
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
303 303
 
304 304
         $add_class = false;
305
-        if ( $pagenow == 'admin.php' && $page ) {
306
-            $add_class = strpos( $page, 'wpinv-' );
305
+        if ($pagenow == 'admin.php' && $page) {
306
+            $add_class = strpos($page, 'wpinv-');
307 307
         }
308 308
         
309 309
         $settings_class = array();
310
-        if ( $page == 'wpinv-settings' ) {
311
-            if ( !empty( $_REQUEST['tab'] ) ) {
312
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
310
+        if ($page == 'wpinv-settings') {
311
+            if (!empty($_REQUEST['tab'])) {
312
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
313 313
             }
314 314
             
315
-            if ( !empty( $_REQUEST['section'] ) ) {
316
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
315
+            if (!empty($_REQUEST['section'])) {
316
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
317 317
             }
318 318
             
319
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
319
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
320 320
         }
321 321
         
322
-        if ( !empty( $settings_class ) ) {
323
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
322
+        if (!empty($settings_class)) {
323
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
324 324
         }
325 325
         
326 326
         $post_type = wpinv_admin_post_type();
327 327
         
328
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
328
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
329 329
             return $classes .= ' wpinv';
330 330
         } else {
331 331
             return $classes;
@@ -337,26 +337,26 @@  discard block
 block discarded – undo
337 337
     public function admin_print_scripts_edit_php() {
338 338
         $post_type = wpinv_admin_post_type();
339 339
         
340
-        if ( $post_type == 'wpi_item' ) {
341
-            wp_enqueue_script( 'wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array( 'jquery', 'inline-edit-post' ), '', true );
340
+        if ($post_type == 'wpi_item') {
341
+            wp_enqueue_script('wpinv-inline-edit-post', WPINV_PLUGIN_URL . 'assets/js/quick-edit.js', array('jquery', 'inline-edit-post'), '', true);
342 342
         }
343 343
     }
344 344
     
345 345
     public function wpinv_actions() {
346
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
347
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
346
+        if (isset($_REQUEST['wpi_action'])) {
347
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
348 348
         }
349 349
     }
350 350
     
351
-    public function pre_get_posts( $wp_query ) {
352
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
353
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
351
+    public function pre_get_posts($wp_query) {
352
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
353
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
354 354
         }
355 355
         
356 356
         return $wp_query;
357 357
     }
358 358
     
359 359
     public function bp_invoicing_init() {
360
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
360
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
361 361
     }
362 362
 }
363 363
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +484 added lines, -484 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  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
-function wpinv_get_option( $key = '', $default = false ) {
7
+function wpinv_get_option($key = '', $default = false) {
8 8
     global $wpinv_options;
9 9
 
10
-    $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default;
11
-    $value = apply_filters( 'wpinv_get_option', $value, $key, $default );
10
+    $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default;
11
+    $value = apply_filters('wpinv_get_option', $value, $key, $default);
12 12
 
13
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
13
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
14 14
 }
15 15
 
16
-function wpinv_update_option( $key = '', $value = false ) {
16
+function wpinv_update_option($key = '', $value = false) {
17 17
     // If no key, exit
18
-    if ( empty( $key ) ) {
18
+    if (empty($key)) {
19 19
         return false;
20 20
     }
21 21
 
22
-    if ( empty( $value ) ) {
23
-        $remove_option = wpinv_delete_option( $key );
22
+    if (empty($value)) {
23
+        $remove_option = wpinv_delete_option($key);
24 24
         return $remove_option;
25 25
     }
26 26
 
27 27
     // First let's grab the current settings
28
-    $options = get_option( 'wpinv_settings' );
28
+    $options = get_option('wpinv_settings');
29 29
 
30 30
     // Let's let devs alter that value coming in
31
-    $value = apply_filters( 'wpinv_update_option', $value, $key );
31
+    $value = apply_filters('wpinv_update_option', $value, $key);
32 32
 
33 33
     // Next let's try to update the value
34
-    $options[ $key ] = $value;
35
-    $did_update = update_option( 'wpinv_settings', $options );
34
+    $options[$key] = $value;
35
+    $did_update = update_option('wpinv_settings', $options);
36 36
 
37 37
     // If it updated, let's update the global variable
38
-    if ( $did_update ) {
38
+    if ($did_update) {
39 39
         global $wpinv_options;
40
-        $wpinv_options[ $key ] = $value;
40
+        $wpinv_options[$key] = $value;
41 41
     }
42 42
 
43 43
     return $did_update;
44 44
 }
45 45
 
46
-function wpinv_delete_option( $key = '' ) {
46
+function wpinv_delete_option($key = '') {
47 47
     // If no key, exit
48
-    if ( empty( $key ) ) {
48
+    if (empty($key)) {
49 49
         return false;
50 50
     }
51 51
 
52 52
     // First let's grab the current settings
53
-    $options = get_option( 'wpinv_settings' );
53
+    $options = get_option('wpinv_settings');
54 54
 
55 55
     // Next let's try to update the value
56
-    if( isset( $options[ $key ] ) ) {
57
-        unset( $options[ $key ] );
56
+    if (isset($options[$key])) {
57
+        unset($options[$key]);
58 58
     }
59 59
 
60
-    $did_update = update_option( 'wpinv_settings', $options );
60
+    $did_update = update_option('wpinv_settings', $options);
61 61
 
62 62
     // If it updated, let's update the global variable
63
-    if ( $did_update ){
63
+    if ($did_update) {
64 64
         global $wpinv_options;
65 65
         $wpinv_options = $options;
66 66
     }
@@ -69,37 +69,37 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 function wpinv_get_settings() {
72
-    $settings = get_option( 'wpinv_settings' );
72
+    $settings = get_option('wpinv_settings');
73 73
 
74
-    if ( empty( $settings ) ) {
74
+    if (empty($settings)) {
75 75
         // Update old settings with new single option
76
-        $general_settings   = is_array( get_option( 'wpinv_settings_general' ) )    ? get_option( 'wpinv_settings_general' )    : array();
77
-        $gateways_settings  = is_array( get_option( 'wpinv_settings_gateways' ) )   ? get_option( 'wpinv_settings_gateways' )   : array();
78
-        $email_settings     = is_array( get_option( 'wpinv_settings_emails' ) )     ? get_option( 'wpinv_settings_emails' )     : array();
79
-        $tax_settings       = is_array( get_option( 'wpinv_settings_taxes' ) )      ? get_option( 'wpinv_settings_taxes' )      : array();
80
-        $misc_settings      = is_array( get_option( 'wpinv_settings_misc' ) )       ? get_option( 'wpinv_settings_misc' )       : array();
81
-        $tool_settings      = is_array( get_option( 'wpinv_settings_tools' ) )      ? get_option( 'wpinv_settings_tools' )      : array();
76
+        $general_settings   = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array();
77
+        $gateways_settings  = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array();
78
+        $email_settings     = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array();
79
+        $tax_settings       = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array();
80
+        $misc_settings      = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array();
81
+        $tool_settings      = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array();
82 82
 
83
-        $settings = array_merge( $general_settings, $gateways_settings, $tax_settings, $tool_settings );
83
+        $settings = array_merge($general_settings, $gateways_settings, $tax_settings, $tool_settings);
84 84
 
85
-        update_option( 'wpinv_settings', $settings );
85
+        update_option('wpinv_settings', $settings);
86 86
 
87 87
     }
88
-    return apply_filters( 'wpinv_get_settings', $settings );
88
+    return apply_filters('wpinv_get_settings', $settings);
89 89
 }
90 90
 
91 91
 function wpinv_register_settings() {
92
-    if ( false == get_option( 'wpinv_settings' ) ) {
93
-        add_option( 'wpinv_settings' );
92
+    if (false == get_option('wpinv_settings')) {
93
+        add_option('wpinv_settings');
94 94
     }
95 95
     
96 96
     $register_settings = wpinv_get_registered_settings();
97 97
     
98
-    foreach ( $register_settings as $tab => $sections ) {
99
-        foreach ( $sections as $section => $settings) {
98
+    foreach ($register_settings as $tab => $sections) {
99
+        foreach ($sections as $section => $settings) {
100 100
             // Check for backwards compatibility
101
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
102
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
101
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
102
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
103 103
                 $section = 'main';
104 104
                 $settings = $sections;
105 105
             }
@@ -111,42 +111,42 @@  discard block
 block discarded – undo
111 111
                 'wpinv_settings_' . $tab . '_' . $section
112 112
             );
113 113
 
114
-            foreach ( $settings as $option ) {
114
+            foreach ($settings as $option) {
115 115
                 // For backwards compatibility
116
-                if ( empty( $option['id'] ) ) {
116
+                if (empty($option['id'])) {
117 117
                     continue;
118 118
                 }
119 119
 
120
-                $name = isset( $option['name'] ) ? $option['name'] : '';
120
+                $name = isset($option['name']) ? $option['name'] : '';
121 121
 
122 122
                 add_settings_field(
123 123
                     'wpinv_settings[' . $option['id'] . ']',
124 124
                     $name,
125
-                    function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
125
+                    function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
126 126
                     'wpinv_settings_' . $tab . '_' . $section,
127 127
                     'wpinv_settings_' . $tab . '_' . $section,
128 128
                     array(
129 129
                         'section'     => $section,
130
-                        'id'          => isset( $option['id'] )          ? $option['id']          : null,
131
-                        'desc'        => ! empty( $option['desc'] )      ? $option['desc']        : '',
132
-                        'name'        => isset( $option['name'] )        ? $option['name']        : null,
133
-                        'size'        => isset( $option['size'] )        ? $option['size']        : null,
134
-                        'options'     => isset( $option['options'] )     ? $option['options']     : '',
135
-                        'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
136
-                        'std'         => isset( $option['std'] )         ? $option['std']         : '',
137
-                        'min'         => isset( $option['min'] )         ? $option['min']         : null,
138
-                        'max'         => isset( $option['max'] )         ? $option['max']         : null,
139
-                        'step'        => isset( $option['step'] )        ? $option['step']        : null,
140
-                        'chosen'      => isset( $option['chosen'] )      ? $option['chosen']      : null,
141
-                        'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
142
-                        'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
143
-                        'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
144
-                        'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
145
-                        'onchange'    => !empty( $option['onchange'] )   ? $option['onchange']    : '',
146
-                        'custom'      => !empty( $option['custom'] )     ? $option['custom']      : '',
147
-                        'class'       =>  !empty( $option['class'] )     ? $option['class']      : '',
148
-                        'cols'        => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
-                        'rows'        => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
130
+                        'id'          => isset($option['id']) ? $option['id'] : null,
131
+                        'desc'        => !empty($option['desc']) ? $option['desc'] : '',
132
+                        'name'        => isset($option['name']) ? $option['name'] : null,
133
+                        'size'        => isset($option['size']) ? $option['size'] : null,
134
+                        'options'     => isset($option['options']) ? $option['options'] : '',
135
+                        'selected'    => isset($option['selected']) ? $option['selected'] : null,
136
+                        'std'         => isset($option['std']) ? $option['std'] : '',
137
+                        'min'         => isset($option['min']) ? $option['min'] : null,
138
+                        'max'         => isset($option['max']) ? $option['max'] : null,
139
+                        'step'        => isset($option['step']) ? $option['step'] : null,
140
+                        'chosen'      => isset($option['chosen']) ? $option['chosen'] : null,
141
+                        'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
142
+                        'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
143
+                        'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
144
+                        'faux'        => isset($option['faux']) ? $option['faux'] : false,
145
+                        'onchange'    => !empty($option['onchange']) ? $option['onchange'] : '',
146
+                        'custom'      => !empty($option['custom']) ? $option['custom'] : '',
147
+                        'class'       =>  !empty($option['class']) ? $option['class'] : '',
148
+                        'cols'        => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
149
+                        'rows'        => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
150 150
                     )
151 151
                 );
152 152
             }
@@ -154,21 +154,21 @@  discard block
 block discarded – undo
154 154
     }
155 155
 
156 156
     // Creates our settings in the options table
157
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
157
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
158 158
 }
159
-add_action( 'admin_init', 'wpinv_register_settings' );
159
+add_action('admin_init', 'wpinv_register_settings');
160 160
 
161 161
 function wpinv_get_registered_settings() {
162
-    $pages = wpinv_get_pages( true );
162
+    $pages = wpinv_get_pages(true);
163 163
     
164 164
     $due_payment_options       = array();
165
-    $due_payment_options[0]    = __( 'Now', 'invoicing' );
166
-    for ( $i = 1; $i <= 30; $i++ ) {
165
+    $due_payment_options[0]    = __('Now', 'invoicing');
166
+    for ($i = 1; $i <= 30; $i++) {
167 167
         $due_payment_options[$i] = $i;
168 168
     }
169 169
     
170 170
     $invoice_number_padd_options = array();
171
-    for ( $i = 0; $i <= 20; $i++ ) {
171
+    for ($i = 0; $i <= 20; $i++) {
172 172
         $invoice_number_padd_options[$i] = $i;
173 173
     }
174 174
     
@@ -177,141 +177,141 @@  discard block
 block discarded – undo
177 177
     $alert_wrapper_start = '<p style="color: #F00">';
178 178
     $alert_wrapper_close = '</p>';
179 179
     $wpinv_settings = array(
180
-        'general' => apply_filters( 'wpinv_settings_general',
180
+        'general' => apply_filters('wpinv_settings_general',
181 181
             array(
182 182
                 'main' => array(
183 183
                     'location_settings' => array(
184 184
                         'id'   => 'location_settings',
185
-                        'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
185
+                        'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
186 186
                         'desc' => '',
187 187
                         'type' => 'header',
188 188
                     ),
189 189
                     'default_country' => array(
190 190
                         'id'      => 'default_country',
191
-                        'name'    => __( 'Default Country', 'invoicing' ),
192
-                        'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
191
+                        'name'    => __('Default Country', 'invoicing'),
192
+                        'desc'    => __('Where does your store operate from?', 'invoicing'),
193 193
                         'type'    => 'select',
194 194
                         'options' => wpinv_get_country_list(),
195 195
                         'std'     => 'GB',
196 196
                         'chosen'  => true,
197
-                        'placeholder' => __( 'Select a country', 'invoicing' ),
197
+                        'placeholder' => __('Select a country', 'invoicing'),
198 198
                     ),
199 199
                     'default_state' => array(
200 200
                         'id'      => 'default_state',
201
-                        'name'    => __( 'Default State / Province', 'invoicing' ),
202
-                        'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
201
+                        'name'    => __('Default State / Province', 'invoicing'),
202
+                        'desc'    => __('What state / province does your store operate from?', 'invoicing'),
203 203
                         'type'    => 'country_states',
204
-                        'placeholder' => __( 'Select a state', 'invoicing' ),
204
+                        'placeholder' => __('Select a state', 'invoicing'),
205 205
                     ),
206 206
                     'store_name' => array(
207 207
                         'id'   => 'store_name',
208
-                        'name' => __( 'Store Name', 'invoicing' ),
209
-                        'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
208
+                        'name' => __('Store Name', 'invoicing'),
209
+                        'desc' => __('Store name to print on invoices.', 'invoicing'),
210 210
                         'std'     => get_option('blogname'),
211 211
                         'type' => 'text',
212 212
                     ),
213 213
                     'logo' => array(
214 214
                         'id'   => 'logo',
215
-                        'name' => __( 'Logo URL', 'invoicing' ),
216
-                        'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
215
+                        'name' => __('Logo URL', 'invoicing'),
216
+                        'desc' => __('Store logo to print on invoices.', 'invoicing'),
217 217
                         'type' => 'text',
218 218
                     ),
219 219
                     'store_address' => array(
220 220
                         'id'   => 'store_address',
221
-                        'name' => __( 'Store Address', 'invoicing' ),
222
-                        'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
221
+                        'name' => __('Store Address', 'invoicing'),
222
+                        'desc' => __('Enter the store address to display on invoice', 'invoicing'),
223 223
                         'type' => 'textarea',
224 224
                     ),
225 225
                     'page_settings' => array(
226 226
                         'id'   => 'page_settings',
227
-                        'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
227
+                        'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
228 228
                         'desc' => '',
229 229
                         'type' => 'header',
230 230
                     ),
231 231
                     'checkout_page' => array(
232 232
                         'id'          => 'checkout_page',
233
-                        'name'        => __( 'Checkout Page', 'invoicing' ),
234
-                        'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
233
+                        'name'        => __('Checkout Page', 'invoicing'),
234
+                        'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
235 235
                         'type'        => 'select',
236 236
                         'options'     => $pages,
237 237
                         'chosen'      => true,
238
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
238
+                        'placeholder' => __('Select a page', 'invoicing'),
239 239
                     ),
240 240
                     'success_page' => array(
241 241
                         'id'          => 'success_page',
242
-                        'name'        => __( 'Success Page', 'invoicing' ),
243
-                        'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
242
+                        'name'        => __('Success Page', 'invoicing'),
243
+                        'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
244 244
                         'type'        => 'select',
245 245
                         'options'     => $pages,
246 246
                         'chosen'      => true,
247
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
247
+                        'placeholder' => __('Select a page', 'invoicing'),
248 248
                     ),
249 249
                     'failure_page' => array(
250 250
                         'id'          => 'failure_page',
251
-                        'name'        => __( 'Failed Transaction Page', 'invoicing' ),
252
-                        'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing' ),
251
+                        'name'        => __('Failed Transaction Page', 'invoicing'),
252
+                        'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails', 'invoicing'),
253 253
                         'type'        => 'select',
254 254
                         'options'     => $pages,
255 255
                         'chosen'      => true,
256
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
256
+                        'placeholder' => __('Select a page', 'invoicing'),
257 257
                     ),
258 258
                     'invoice_history_page' => array(
259 259
                         'id'          => 'invoice_history_page',
260
-                        'name'        => __( 'Invoice History Page', 'invoicing' ),
261
-                        'desc'        => __( 'This page shows a invoice history for the current user', 'invoicing' ),
260
+                        'name'        => __('Invoice History Page', 'invoicing'),
261
+                        'desc'        => __('This page shows a invoice history for the current user', 'invoicing'),
262 262
                         'type'        => 'select',
263 263
                         'options'     => $pages,
264 264
                         'chosen'      => true,
265
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
265
+                        'placeholder' => __('Select a page', 'invoicing'),
266 266
                     )
267 267
                 ),
268 268
                 'currency_section' => array(
269 269
                     'currency_settings' => array(
270 270
                         'id'   => 'currency_settings',
271
-                        'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
271
+                        'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
272 272
                         'desc' => '',
273 273
                         'type' => 'header',
274 274
                     ),
275 275
                     'currency' => array(
276 276
                         'id'      => 'currency',
277
-                        'name'    => __( 'Currency', 'invoicing' ),
278
-                        'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
277
+                        'name'    => __('Currency', 'invoicing'),
278
+                        'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
279 279
                         'type'    => 'select',
280 280
                         'options' => wpinv_get_currencies(),
281 281
                         'chosen'  => true,
282 282
                     ),
283 283
                     'currency_position' => array(
284 284
                         'id'      => 'currency_position',
285
-                        'name'    => __( 'Currency Position', 'invoicing' ),
286
-                        'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
285
+                        'name'    => __('Currency Position', 'invoicing'),
286
+                        'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
287 287
                         'type'    => 'select',
288 288
                         'options'  => array(
289
-                            'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
290
-                            'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
291
-                            'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
292
-                            'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
289
+                            'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
290
+                            'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
291
+                            'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
292
+                            'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
293 293
                         )
294 294
                     ),
295 295
                     'thousands_separator' => array(
296 296
                         'id'   => 'thousands_separator',
297
-                        'name' => __( 'Thousands Separator', 'invoicing' ),
298
-                        'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
297
+                        'name' => __('Thousands Separator', 'invoicing'),
298
+                        'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
299 299
                         'type' => 'text',
300 300
                         'size' => 'small',
301 301
                         'std'  => ',',
302 302
                     ),
303 303
                     'decimal_separator' => array(
304 304
                         'id'   => 'decimal_separator',
305
-                        'name' => __( 'Decimal Separator', 'invoicing' ),
306
-                        'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
305
+                        'name' => __('Decimal Separator', 'invoicing'),
306
+                        'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
307 307
                         'type' => 'text',
308 308
                         'size' => 'small',
309 309
                         'std'  => '.',
310 310
                     ),
311 311
                     'decimals' => array(
312 312
                         'id'   => 'decimals',
313
-                        'name' => __( 'Number of Decimals', 'invoicing' ),
314
-                        'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
313
+                        'name' => __('Number of Decimals', 'invoicing'),
314
+                        'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
315 315
                         'type' => 'number',
316 316
                         'size' => 'small',
317 317
                         'std'  => '2',
@@ -323,29 +323,29 @@  discard block
 block discarded – undo
323 323
                 'labels' => array(
324 324
                     'labels' => array(
325 325
                         'id'   => 'labels_settings',
326
-                        'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
326
+                        'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
327 327
                         'desc' => '',
328 328
                         'type' => 'header',
329 329
                     ),
330 330
                     'vat_name' => array(
331 331
                         'id' => 'vat_name',
332
-                        'name' => __( 'VAT Name', 'invoicing' ),
333
-                        'desc' => __( 'Enter the VAT name', 'invoicing' ),
332
+                        'name' => __('VAT Name', 'invoicing'),
333
+                        'desc' => __('Enter the VAT name', 'invoicing'),
334 334
                         'type' => 'text',
335 335
                         'size' => 'regular',
336 336
                         'std' => 'VAT'
337 337
                     ),
338 338
                     'vat_invoice_notice_label' => array(
339 339
                         'id' => 'vat_invoice_notice_label',
340
-                        'name' => __( 'Invoice notice label', 'invoicing' ),
341
-                        'desc' => __( 'Use this to add a invoice notice section (label) to your invoices', 'invoicing' ),
340
+                        'name' => __('Invoice notice label', 'invoicing'),
341
+                        'desc' => __('Use this to add a invoice notice section (label) to your invoices', 'invoicing'),
342 342
                         'type' => 'text',
343 343
                         'size' => 'regular',
344 344
                     ),
345 345
                     'vat_invoice_notice' => array(
346 346
                         'id' => 'vat_invoice_notice',
347
-                        'name' => __( 'Invoice notice', 'invoicing' ),
348
-                        'desc' =>   __( 'Use this to add a invoice notice section (description) to your invoices', 'invoicing' ),
347
+                        'name' => __('Invoice notice', 'invoicing'),
348
+                        'desc' =>   __('Use this to add a invoice notice section (description) to your invoices', 'invoicing'),
349 349
                         'type' => 'text',
350 350
                         'size' => 'regular',
351 351
                     )
@@ -357,22 +357,22 @@  discard block
 block discarded – undo
357 357
                 'main' => array(
358 358
                     'gateway_settings' => array(
359 359
                         'id'   => 'api_header',
360
-                        'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
360
+                        'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
361 361
                         'desc' => '',
362 362
                         'type' => 'header',
363 363
                     ),
364 364
                     'gateways' => array(
365 365
                         'id'      => 'gateways',
366
-                        'name'    => __( 'Payment Gateways', 'invoicing' ),
367
-                        'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
366
+                        'name'    => __('Payment Gateways', 'invoicing'),
367
+                        'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
368 368
                         'type'    => 'gateways',
369 369
                         'std'     => array('manual'=>1),
370 370
                         'options' => wpinv_get_payment_gateways(),
371 371
                     ),
372 372
                     'default_gateway' => array(
373 373
                         'id'      => 'default_gateway',
374
-                        'name'    => __( 'Default Gateway', 'invoicing' ),
375
-                        'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
374
+                        'name'    => __('Default Gateway', 'invoicing'),
375
+                        'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
376 376
                         'type'    => 'gateway_select',
377 377
                         'std'     => 'manual',
378 378
                         'options' => wpinv_get_payment_gateways(),
@@ -386,19 +386,19 @@  discard block
 block discarded – undo
386 386
                 'main' => array(
387 387
                     'tax_settings' => array(
388 388
                         'id'   => 'tax_settings',
389
-                        'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
389
+                        'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
390 390
                         'type' => 'header',
391 391
                     ),
392 392
                     'enable_taxes' => array(
393 393
                         'id'   => 'enable_taxes',
394
-                        'name' => __( 'Enable Taxes', 'invoicing' ),
395
-                        'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
394
+                        'name' => __('Enable Taxes', 'invoicing'),
395
+                        'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
396 396
                         'type' => 'checkbox',
397 397
                     ),
398 398
                     'tax_rate' => array(
399 399
                         'id'   => 'tax_rate',
400
-                        'name' => __( 'Fallback Tax Rate', 'invoicing' ),
401
-                        'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
400
+                        'name' => __('Fallback Tax Rate', 'invoicing'),
401
+                        'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
402 402
                         'type' => 'number',
403 403
                         'size' => 'small',
404 404
                         'min'  => '0',
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
                 'rates' => array(
411 411
                     'tax_rates' => array(
412 412
                         'id'   => 'tax_rates',
413
-                        'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
414
-                        'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
413
+                        'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
414
+                        'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
415 415
                         'type' => 'tax_rates',
416 416
                     ),
417 417
                 )
@@ -423,62 +423,62 @@  discard block
 block discarded – undo
423 423
                 'main' => array(
424 424
                     'email_settings_header' => array(
425 425
                         'id'   => 'email_settings_header',
426
-                        'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
426
+                        'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
427 427
                         'type' => 'header',
428 428
                     ),
429 429
                     'email_from_name' => array(
430 430
                         'id'   => 'email_from_name',
431
-                        'name' => __( 'From Name', 'invoicing' ),
432
-                        'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
433
-                        'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
431
+                        'name' => __('From Name', 'invoicing'),
432
+                        'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
433
+                        'std' => esc_attr(get_bloginfo('name', 'display')),
434 434
                         'type' => 'text',
435 435
                     ),
436 436
                     'email_from' => array(
437 437
                         'id'   => 'email_from',
438
-                        'name' => __( 'From Email', 'invoicing' ),
439
-                        'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
440
-                        'std' => get_option( 'admin_email' ),
438
+                        'name' => __('From Email', 'invoicing'),
439
+                        'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
440
+                        'std' => get_option('admin_email'),
441 441
                         'type' => 'text',
442 442
                     ),
443 443
                     'overdue_settings_header' => array(
444 444
                         'id'   => 'overdue_settings_header',
445
-                        'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
445
+                        'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
446 446
                         'type' => 'header',
447 447
                     ),
448 448
                     'overdue_active' => array(
449 449
                         'id'   => 'overdue_active',
450
-                        'name' => __( 'Enable Due Date', 'invoicing' ),
451
-                        'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
450
+                        'name' => __('Enable Due Date', 'invoicing'),
451
+                        'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
452 452
                         'type' => 'checkbox',
453 453
                         'std'  => false,
454 454
                     ),
455 455
                     'overdue_days' => array(
456 456
                         'id'          => 'overdue_days',
457
-                        'name'        => __( 'Default Due Date', 'invoicing' ),
458
-                        'desc'        => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ),
457
+                        'name'        => __('Default Due Date', 'invoicing'),
458
+                        'desc'        => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'),
459 459
                         'type'        => 'select',
460 460
                         'options'     => $due_payment_options,
461 461
                         'chosen'      => true,
462 462
                         'std'         => 0,
463
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
463
+                        'placeholder' => __('Select a page', 'invoicing'),
464 464
                     ),
465 465
                     'email_template_header' => array(
466 466
                         'id'   => 'email_template_header',
467
-                        'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
467
+                        'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
468 468
                         'type' => 'header',
469 469
                     ),
470 470
                     'email_header_image' => array(
471 471
                         'id'   => 'email_header_image',
472
-                        'name' => __( 'Header Image', 'invoicing' ),
473
-                        'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
472
+                        'name' => __('Header Image', 'invoicing'),
473
+                        'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
474 474
                         'std' => '',
475 475
                         'type' => 'text',
476 476
                     ),
477 477
                     'email_footer_text' => array(
478 478
                         'id'   => 'email_footer_text',
479
-                        'name' => __( 'Footer Text', 'invoicing' ),
480
-                        'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
481
-                        'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
479
+                        'name' => __('Footer Text', 'invoicing'),
480
+                        'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
481
+                        'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
482 482
                         'type' => 'textarea',
483 483
                         'class' => 'regular-text',
484 484
                         'rows' => 2,
@@ -486,29 +486,29 @@  discard block
 block discarded – undo
486 486
                     ),
487 487
                     'email_base_color' => array(
488 488
                         'id'   => 'email_base_color',
489
-                        'name' => __( 'Base Color', 'invoicing' ),
490
-                        'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
489
+                        'name' => __('Base Color', 'invoicing'),
490
+                        'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
491 491
                         'std' => '#557da2',
492 492
                         'type' => 'color',
493 493
                     ),
494 494
                     'email_background_color' => array(
495 495
                         'id'   => 'email_background_color',
496
-                        'name' => __( 'Background Color', 'invoicing' ),
497
-                        'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
496
+                        'name' => __('Background Color', 'invoicing'),
497
+                        'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
498 498
                         'std' => '#f5f5f5',
499 499
                         'type' => 'color',
500 500
                     ),
501 501
                     'email_body_background_color' => array(
502 502
                         'id'   => 'email_body_background_color',
503
-                        'name' => __( 'Body Background Color', 'invoicing' ),
504
-                        'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
503
+                        'name' => __('Body Background Color', 'invoicing'),
504
+                        'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
505 505
                         'std' => '#fdfdfd',
506 506
                         'type' => 'color',
507 507
                     ),
508 508
                     'email_text_color' => array(
509 509
                         'id'   => 'email_text_color',
510
-                        'name' => __( 'Body Text Color', 'invoicing' ),
511
-                        'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
510
+                        'name' => __('Body Text Color', 'invoicing'),
511
+                        'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
512 512
                         'std' => '#505050',
513 513
                         'type' => 'color',
514 514
                     ),
@@ -527,67 +527,67 @@  discard block
 block discarded – undo
527 527
                 'main' => array(
528 528
                     'fields_settings' => array(
529 529
                         'id'   => 'fields_settings',
530
-                        'name' => '<h3>' . __( 'Fields Settings', 'invoicing' ) . '</h3>',
531
-                        'desc' => __( 'Tick fields which are mandatory in invoice address fields.', 'invoicing' ),
530
+                        'name' => '<h3>' . __('Fields Settings', 'invoicing') . '</h3>',
531
+                        'desc' => __('Tick fields which are mandatory in invoice address fields.', 'invoicing'),
532 532
                         'type' => 'header',
533 533
                     ),
534 534
                     'fname_mandatory' => array(
535 535
                         'id'   => 'fname_mandatory',
536
-                        'name' => __( 'First Name Mandatory?', 'invoicing' ),
536
+                        'name' => __('First Name Mandatory?', 'invoicing'),
537 537
                         'type' => 'checkbox',
538 538
                         'std'  => true,
539 539
                     ),
540 540
                     'lname_mandatory' => array(
541 541
                         'id'   => 'lname_mandatory',
542
-                        'name' => __( 'Last Name Mandatory?', 'invoicing' ),
542
+                        'name' => __('Last Name Mandatory?', 'invoicing'),
543 543
                         'type' => 'checkbox',
544 544
                         'std'  => true,
545 545
                     ),
546 546
                     'address_mandatory' => array(
547 547
                         'id'   => 'address_mandatory',
548
-                        'name' => __( 'Address Mandatory?', 'invoicing' ),
548
+                        'name' => __('Address Mandatory?', 'invoicing'),
549 549
                         'type' => 'checkbox',
550 550
                         'std'  => true,
551 551
                     ),
552 552
                     'city_mandatory' => array(
553 553
                         'id'   => 'city_mandatory',
554
-                        'name' => __( 'City Mandatory?', 'invoicing' ),
554
+                        'name' => __('City Mandatory?', 'invoicing'),
555 555
                         'type' => 'checkbox',
556 556
                         'std'  => true,
557 557
                     ),
558 558
                     'country_mandatory' => array(
559 559
                         'id'   => 'country_mandatory',
560
-                        'name' => __( 'Country Mandatory?', 'invoicing' ),
560
+                        'name' => __('Country Mandatory?', 'invoicing'),
561 561
                         'type' => 'checkbox',
562 562
                         'std'  => true,
563 563
                     ),
564 564
                     'state_mandatory' => array(
565 565
                         'id'   => 'state_mandatory',
566
-                        'name' => __( 'State / Province Mandatory?', 'invoicing' ),
566
+                        'name' => __('State / Province Mandatory?', 'invoicing'),
567 567
                         'type' => 'checkbox',
568 568
                         'std'  => true,
569 569
                     ),
570 570
                     'zip_mandatory' => array(
571 571
                         'id'   => 'zip_mandatory',
572
-                        'name' => __( 'ZIP / Postcode Mandatory?', 'invoicing' ),
572
+                        'name' => __('ZIP / Postcode Mandatory?', 'invoicing'),
573 573
                         'type' => 'checkbox',
574 574
                         'std'  => true,
575 575
                     ),
576 576
                     'phone_mandatory' => array(
577 577
                         'id'   => 'phone_mandatory',
578
-                        'name' => __( 'Phone No. Mandatory?', 'invoicing' ),
578
+                        'name' => __('Phone No. Mandatory?', 'invoicing'),
579 579
                         'type' => 'checkbox',
580 580
                         'std'  => true,
581 581
                     ),
582 582
                     'invoice_number_format_settings' => array(
583 583
                         'id'   => 'invoice_number_format_settings',
584
-                        'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
584
+                        'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
585 585
                         'type' => 'header',
586 586
                     ),
587 587
                     'invoice_number_padd' => array(
588 588
                         'id'      => 'invoice_number_padd',
589
-                        'name'    => __( 'Minimum digits', 'invoicing' ),
590
-                        'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
589
+                        'name'    => __('Minimum digits', 'invoicing'),
590
+                        'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
591 591
                         'type'    => 'select',
592 592
                         'options' => $invoice_number_padd_options,
593 593
                         'std'     => 5,
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
                     ),
596 596
                     'invoice_number_prefix' => array(
597 597
                         'id' => 'invoice_number_prefix',
598
-                        'name' => __( 'Invoice Number prefix', 'invoicing' ),
599
-                        'desc' => __( 'A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing' ),
598
+                        'name' => __('Invoice Number prefix', 'invoicing'),
599
+                        'desc' => __('A prefix to prepend to all invoice numbers. Ex: WPINV-', 'invoicing'),
600 600
                         'type' => 'text',
601 601
                         'size' => 'regular',
602 602
                         'std' => 'WPINV-',
@@ -604,25 +604,25 @@  discard block
 block discarded – undo
604 604
                     ),
605 605
                     'invoice_number_postfix' => array(
606 606
                         'id' => 'invoice_number_postfix',
607
-                        'name' => __( 'Invoice Number postfix', 'invoicing' ),
608
-                        'desc' => __( 'A postfix to append to all invoice numbers.', 'invoicing' ),
607
+                        'name' => __('Invoice Number postfix', 'invoicing'),
608
+                        'desc' => __('A postfix to append to all invoice numbers.', 'invoicing'),
609 609
                         'type' => 'text',
610 610
                         'size' => 'regular',
611 611
                         'std' => ''
612 612
                     ),
613 613
                     'guest_checkout_settings' => array(
614 614
                         'id'   => 'guest_checkout_settings',
615
-                        'name' => '<h3>' . __( 'Pay via Invoice Link', 'invoicing' ) . '</h3>',
615
+                        'name' => '<h3>' . __('Pay via Invoice Link', 'invoicing') . '</h3>',
616 616
                         'type' => 'header',
617 617
                     ),
618 618
                     'guest_checkout' => array(
619 619
                         'type'    => 'radio',
620 620
                         'id'      => 'guest_checkout',
621
-                        'name'    => __( 'Pay via Invoice Link for non logged in user', 'invoicing' ),
622
-                        'desc'    => __( 'Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing' ),
621
+                        'name'    => __('Pay via Invoice Link for non logged in user', 'invoicing'),
622
+                        'desc'    => __('Select how invoice should be paid when non logged in user clicks on the invoice link that sent to them via for pay for invoice.', 'invoicing'),
623 623
                         'options' => array(
624
-                            0 => __( 'Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing' ),
625
-                            1 => __( 'Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing' ),
624
+                            0 => __('Ask them to log-in and redirect back to invoice checkout to pay.', 'invoicing'),
625
+                            1 => __('Auto log-in the user via invoice link and take them to invoice checkout to pay.', 'invoicing'),
626 626
                         ),
627 627
                         'std'     => 0,
628 628
                     ),
@@ -635,8 +635,8 @@  discard block
 block discarded – undo
635 635
                 'main' => array(
636 636
                     'tool_settings' => array(
637 637
                         'id'   => 'tool_settings',
638
-                        'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
639
-                        'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
638
+                        'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
639
+                        'desc' => __('Invoicing diagnostic tools', 'invoicing'),
640 640
                         'type' => 'tools',
641 641
                     ),
642 642
                 ),
@@ -644,135 +644,135 @@  discard block
 block discarded – undo
644 644
         )
645 645
     );
646 646
 
647
-    return apply_filters( 'wpinv_registered_settings', $wpinv_settings );
647
+    return apply_filters('wpinv_registered_settings', $wpinv_settings);
648 648
 }
649 649
 
650
-function wpinv_settings_sanitize( $input = array() ) {
650
+function wpinv_settings_sanitize($input = array()) {
651 651
     global $wpinv_options;
652 652
 
653
-    if ( empty( $_POST['_wp_http_referer'] ) ) {
653
+    if (empty($_POST['_wp_http_referer'])) {
654 654
         return $input;
655 655
     }
656 656
 
657
-    parse_str( $_POST['_wp_http_referer'], $referrer );
657
+    parse_str($_POST['_wp_http_referer'], $referrer);
658 658
 
659 659
     $settings = wpinv_get_registered_settings();
660
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
661
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
660
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
661
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
662 662
 
663 663
     $input = $input ? $input : array();
664
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
665
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
664
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
665
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
666 666
 
667 667
     // Loop through each setting being saved and pass it through a sanitization filter
668
-    foreach ( $input as $key => $value ) {
668
+    foreach ($input as $key => $value) {
669 669
         // Get the setting type (checkbox, select, etc)
670
-        $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
670
+        $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
671 671
 
672
-        if ( $type ) {
672
+        if ($type) {
673 673
             // Field type specific filter
674
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
674
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
675 675
         }
676 676
 
677 677
         // General filter
678
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
678
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
679 679
     }
680 680
 
681 681
     // Loop through the whitelist and unset any that are empty for the tab being saved
682
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
683
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
682
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
683
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
684 684
 
685
-    $found_settings = array_merge( $main_settings, $section_settings );
685
+    $found_settings = array_merge($main_settings, $section_settings);
686 686
 
687
-    if ( ! empty( $found_settings ) ) {
688
-        foreach ( $found_settings as $key => $value ) {
687
+    if (!empty($found_settings)) {
688
+        foreach ($found_settings as $key => $value) {
689 689
 
690 690
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
691
-            if ( is_numeric( $key ) ) {
691
+            if (is_numeric($key)) {
692 692
                 $key = $value['id'];
693 693
             }
694 694
 
695
-            if ( empty( $input[ $key ] ) ) {
696
-                unset( $wpinv_options[ $key ] );
695
+            if (empty($input[$key])) {
696
+                unset($wpinv_options[$key]);
697 697
             }
698 698
         }
699 699
     }
700 700
 
701 701
     // Merge our new settings with the existing
702
-    $output = array_merge( $wpinv_options, $input );
702
+    $output = array_merge($wpinv_options, $input);
703 703
 
704
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
704
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
705 705
 
706 706
     return $output;
707 707
 }
708 708
 
709
-function wpinv_settings_sanitize_misc_accounting( $input ) {
709
+function wpinv_settings_sanitize_misc_accounting($input) {
710 710
     global $wpinv_options, $wpi_session;
711 711
 
712
-    if ( !current_user_can( 'manage_options' ) ) {
712
+    if (!current_user_can('manage_options')) {
713 713
         return $input;
714 714
     }
715 715
 
716
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
716
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
717 717
         // Shows an admin notice about upgrading previous order numbers
718
-        $wpi_session->set( 'upgrade_sequential', '1' );
718
+        $wpi_session->set('upgrade_sequential', '1');
719 719
     }
720 720
 
721 721
     return $input;
722 722
 }
723
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
723
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
724 724
 
725
-function wpinv_settings_sanitize_tax_rates( $input ) {
726
-    if( !current_user_can( 'manage_options' ) ) {
725
+function wpinv_settings_sanitize_tax_rates($input) {
726
+    if (!current_user_can('manage_options')) {
727 727
         return $input;
728 728
     }
729 729
 
730
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
730
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
731 731
 
732 732
     $tax_rates = array();
733 733
 
734
-    if ( !empty( $new_rates ) ) {
735
-        foreach ( $new_rates as $rate ) {
736
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
734
+    if (!empty($new_rates)) {
735
+        foreach ($new_rates as $rate) {
736
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
737 737
                 continue;
738 738
             }
739 739
             
740
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
740
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
741 741
             
742 742
             $tax_rates[] = $rate;
743 743
         }
744 744
     }
745 745
 
746
-    update_option( 'wpinv_tax_rates', $tax_rates );
746
+    update_option('wpinv_tax_rates', $tax_rates);
747 747
 
748 748
     return $input;
749 749
 }
750
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
750
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
751 751
 
752
-function wpinv_sanitize_text_field( $input ) {
753
-    return trim( $input );
752
+function wpinv_sanitize_text_field($input) {
753
+    return trim($input);
754 754
 }
755
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
755
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
756 756
 
757 757
 function wpinv_get_settings_tabs() {
758 758
     $tabs             = array();
759
-    $tabs['general']  = __( 'General', 'invoicing' );
760
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
761
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
762
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
763
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
764
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
765
-
766
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
759
+    $tabs['general']  = __('General', 'invoicing');
760
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
761
+    $tabs['taxes']    = __('Taxes', 'invoicing');
762
+    $tabs['emails']   = __('Emails', 'invoicing');
763
+    $tabs['misc']     = __('Misc', 'invoicing');
764
+    $tabs['tools']    = __('Tools', 'invoicing');
765
+
766
+    return apply_filters('wpinv_settings_tabs', $tabs);
767 767
 }
768 768
 
769
-function wpinv_get_settings_tab_sections( $tab = false ) {
769
+function wpinv_get_settings_tab_sections($tab = false) {
770 770
     $tabs     = false;
771 771
     $sections = wpinv_get_registered_settings_sections();
772 772
 
773
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
774
-        $tabs = $sections[ $tab ];
775
-    } else if ( $tab ) {
773
+    if ($tab && !empty($sections[$tab])) {
774
+        $tabs = $sections[$tab];
775
+    } else if ($tab) {
776 776
         $tabs = false;
777 777
     }
778 778
 
@@ -782,135 +782,135 @@  discard block
 block discarded – undo
782 782
 function wpinv_get_registered_settings_sections() {
783 783
     static $sections = false;
784 784
 
785
-    if ( false !== $sections ) {
785
+    if (false !== $sections) {
786 786
         return $sections;
787 787
     }
788 788
 
789 789
     $sections = array(
790
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
791
-            'main' => __( 'General Settings', 'invoicing' ),
792
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
793
-            'labels' => __( 'Label Texts', 'invoicing' ),
794
-        ) ),
795
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
796
-            'main' => __( 'Gateway Settings', 'invoicing' ),
797
-        ) ),
798
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
799
-            'main' => __( 'Tax Settings', 'invoicing' ),
800
-            'rates' => __( 'Tax Rates', 'invoicing' ),
801
-        ) ),
802
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
803
-            'main' => __( 'Email Settings', 'invoicing' ),
804
-        ) ),
805
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
806
-            'main' => __( 'Misc Settings', 'invoicing' ),
807
-        ) ),
808
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
809
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
810
-        ) ),
790
+        'general' => apply_filters('wpinv_settings_sections_general', array(
791
+            'main' => __('General Settings', 'invoicing'),
792
+            'currency_section' => __('Currency Settings', 'invoicing'),
793
+            'labels' => __('Label Texts', 'invoicing'),
794
+        )),
795
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
796
+            'main' => __('Gateway Settings', 'invoicing'),
797
+        )),
798
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
799
+            'main' => __('Tax Settings', 'invoicing'),
800
+            'rates' => __('Tax Rates', 'invoicing'),
801
+        )),
802
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
803
+            'main' => __('Email Settings', 'invoicing'),
804
+        )),
805
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
806
+            'main' => __('Misc Settings', 'invoicing'),
807
+        )),
808
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
809
+            'main' => __('Diagnostic Tools', 'invoicing'),
810
+        )),
811 811
     );
812 812
 
813
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
813
+    $sections = apply_filters('wpinv_settings_sections', $sections);
814 814
 
815 815
     return $sections;
816 816
 }
817 817
 
818
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
818
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
819 819
 	$pages_options = array();
820 820
 
821
-	if( $default_label !== NULL && $default_label !== false ) {
822
-		$pages_options = array( '' => $default_label ); // Blank option
821
+	if ($default_label !== NULL && $default_label !== false) {
822
+		$pages_options = array('' => $default_label); // Blank option
823 823
 	}
824 824
 
825 825
 	$pages = get_pages();
826
-	if ( $pages ) {
827
-		foreach ( $pages as $page ) {
826
+	if ($pages) {
827
+		foreach ($pages as $page) {
828 828
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
829
-            $pages_options[ $page->ID ] = $title;
829
+            $pages_options[$page->ID] = $title;
830 830
 		}
831 831
 	}
832 832
 
833 833
 	return $pages_options;
834 834
 }
835 835
 
836
-function wpinv_header_callback( $args ) {
837
-	if ( !empty( $args['desc'] ) ) {
836
+function wpinv_header_callback($args) {
837
+	if (!empty($args['desc'])) {
838 838
         echo $args['desc'];
839 839
     }
840 840
 }
841 841
 
842
-function wpinv_hidden_callback( $args ) {
842
+function wpinv_hidden_callback($args) {
843 843
 	global $wpinv_options;
844 844
 
845
-	if ( isset( $args['set_value'] ) ) {
845
+	if (isset($args['set_value'])) {
846 846
 		$value = $args['set_value'];
847
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
848
-		$value = $wpinv_options[ $args['id'] ];
847
+	} elseif (isset($wpinv_options[$args['id']])) {
848
+		$value = $wpinv_options[$args['id']];
849 849
 	} else {
850
-		$value = isset( $args['std'] ) ? $args['std'] : '';
850
+		$value = isset($args['std']) ? $args['std'] : '';
851 851
 	}
852 852
 
853
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
853
+	if (isset($args['faux']) && true === $args['faux']) {
854 854
 		$args['readonly'] = true;
855
-		$value = isset( $args['std'] ) ? $args['std'] : '';
855
+		$value = isset($args['std']) ? $args['std'] : '';
856 856
 		$name  = '';
857 857
 	} else {
858
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
858
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
859 859
 	}
860 860
 
861
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
861
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
862 862
     
863 863
 	echo $html;
864 864
 }
865 865
 
866
-function wpinv_checkbox_callback( $args ) {
866
+function wpinv_checkbox_callback($args) {
867 867
 	global $wpinv_options;
868 868
     
869
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
869
+    $sanitize_id = wpinv_sanitize_key($args['id']);
870 870
 
871
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
871
+	if (isset($args['faux']) && true === $args['faux']) {
872 872
 		$name = '';
873 873
 	} else {
874 874
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
875 875
 	}
876 876
 
877
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
877
+	$checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : '';
878 878
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
879
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
879
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
880 880
 
881 881
 	echo $html;
882 882
 }
883 883
 
884
-function wpinv_multicheck_callback( $args ) {
884
+function wpinv_multicheck_callback($args) {
885 885
 	global $wpinv_options;
886 886
 	
887
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
887
+	$sanitize_id = wpinv_sanitize_key($args['id']);
888 888
 	
889
-	if ( ! empty( $args['options'] ) ) {
890
-		foreach( $args['options'] as $key => $option ):
891
-			$sanitize_key = wpinv_sanitize_key( $key );
892
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
889
+	if (!empty($args['options'])) {
890
+		foreach ($args['options'] as $key => $option):
891
+			$sanitize_key = wpinv_sanitize_key($key);
892
+			if (isset($wpinv_options[$args['id']][$sanitize_key])) { 
893 893
 				$enabled = $sanitize_key;
894 894
 			} else { 
895 895
 				$enabled = NULL; 
896 896
 			}
897
-			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
898
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label><br/>';
897
+			echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($sanitize_key) . '" ' . checked($sanitize_key, $enabled, false) . '/>&nbsp;';
898
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label><br/>';
899 899
 		endforeach;
900 900
 		echo '<p class="description">' . $args['desc'] . '</p>';
901 901
 	}
902 902
 }
903 903
 
904
-function wpinv_payment_icons_callback( $args ) {
904
+function wpinv_payment_icons_callback($args) {
905 905
 	global $wpinv_options;
906 906
     
907
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
907
+    $sanitize_id = wpinv_sanitize_key($args['id']);
908 908
 
909
-	if ( ! empty( $args['options'] ) ) {
910
-		foreach( $args['options'] as $key => $option ) {
911
-            $sanitize_key = wpinv_sanitize_key( $key );
909
+	if (!empty($args['options'])) {
910
+		foreach ($args['options'] as $key => $option) {
911
+            $sanitize_key = wpinv_sanitize_key($key);
912 912
             
913
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
913
+			if (isset($wpinv_options[$args['id']][$key])) {
914 914
 				$enabled = $option;
915 915
 			} else {
916 916
 				$enabled = NULL;
@@ -918,194 +918,194 @@  discard block
 block discarded – undo
918 918
 
919 919
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
920 920
 
921
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
921
+				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr($option) . '" ' . checked($option, $enabled, false) . '/>&nbsp;';
922 922
 
923
-				if ( wpinv_string_is_image_url( $key ) ) {
924
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
923
+				if (wpinv_string_is_image_url($key)) {
924
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
925 925
 				} else {
926
-					$card = strtolower( str_replace( ' ', '', $option ) );
926
+					$card = strtolower(str_replace(' ', '', $option));
927 927
 
928
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
929
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
928
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
929
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
930 930
 					} else {
931
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
931
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
932 932
 						$content_dir = WP_CONTENT_DIR;
933 933
 
934
-						if ( function_exists( 'wp_normalize_path' ) ) {
934
+						if (function_exists('wp_normalize_path')) {
935 935
 							// Replaces backslashes with forward slashes for Windows systems
936
-							$image = wp_normalize_path( $image );
937
-							$content_dir = wp_normalize_path( $content_dir );
936
+							$image = wp_normalize_path($image);
937
+							$content_dir = wp_normalize_path($content_dir);
938 938
 						}
939 939
 
940
-						$image = str_replace( $content_dir, content_url(), $image );
940
+						$image = str_replace($content_dir, content_url(), $image);
941 941
 					}
942 942
 
943
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
943
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
944 944
 				}
945 945
 			echo $option . '</label>';
946 946
 		}
947
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
947
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
948 948
 	}
949 949
 }
950 950
 
951
-function wpinv_radio_callback( $args ) {
951
+function wpinv_radio_callback($args) {
952 952
 	global $wpinv_options;
953 953
     
954
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
954
+    $sanitize_id = wpinv_sanitize_key($args['id']);
955 955
     
956
-    foreach ( $args['options'] as $key => $option ) :
957
-		$sanitize_key = wpinv_sanitize_key( $key );
956
+    foreach ($args['options'] as $key => $option) :
957
+		$sanitize_key = wpinv_sanitize_key($key);
958 958
         
959 959
         $checked = false;
960 960
 
961
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
961
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
962 962
 			$checked = true;
963
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
963
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
964 964
 			$checked = true;
965 965
 
966 966
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
967
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
967
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
968 968
 	endforeach;
969 969
 
970
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
970
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
971 971
 }
972 972
 
973
-function wpinv_gateways_callback( $args ) {
973
+function wpinv_gateways_callback($args) {
974 974
 	global $wpinv_options;
975 975
     
976
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
976
+    $sanitize_id = wpinv_sanitize_key($args['id']);
977 977
 
978
-	foreach ( $args['options'] as $key => $option ) :
979
-		$sanitize_key = wpinv_sanitize_key( $key );
978
+	foreach ($args['options'] as $key => $option) :
979
+		$sanitize_key = wpinv_sanitize_key($key);
980 980
         
981
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
981
+        if (isset($wpinv_options['gateways'][$key]))
982 982
 			$enabled = '1';
983 983
 		else
984 984
 			$enabled = null;
985 985
 
986
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
987
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
986
+		echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
987
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
988 988
 	endforeach;
989 989
 }
990 990
 
991 991
 function wpinv_gateway_select_callback($args) {
992 992
 	global $wpinv_options;
993 993
     
994
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
994
+    $sanitize_id = wpinv_sanitize_key($args['id']);
995 995
 
996 996
 	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
997 997
 
998
-	foreach ( $args['options'] as $key => $option ) :
999
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1000
-            $selected = selected( $key, $args['selected'], false );
998
+	foreach ($args['options'] as $key => $option) :
999
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1000
+            $selected = selected($key, $args['selected'], false);
1001 1001
         } else {
1002
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
1002
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
1003 1003
         }
1004
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1004
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
1005 1005
 	endforeach;
1006 1006
 
1007 1007
 	echo '</select>';
1008
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1008
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1009 1009
 }
1010 1010
 
1011
-function wpinv_text_callback( $args ) {
1011
+function wpinv_text_callback($args) {
1012 1012
 	global $wpinv_options;
1013 1013
     
1014
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1014
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1015 1015
 
1016
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1017
-		$value = $wpinv_options[ $args['id'] ];
1016
+	if (isset($wpinv_options[$args['id']])) {
1017
+		$value = $wpinv_options[$args['id']];
1018 1018
 	} else {
1019
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1019
+		$value = isset($args['std']) ? $args['std'] : '';
1020 1020
 	}
1021 1021
 
1022
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1022
+	if (isset($args['faux']) && true === $args['faux']) {
1023 1023
 		$args['readonly'] = true;
1024
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1024
+		$value = isset($args['std']) ? $args['std'] : '';
1025 1025
 		$name  = '';
1026 1026
 	} else {
1027
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1027
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1028 1028
 	}
1029 1029
 
1030 1030
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1031
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1032
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1033
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1031
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1032
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
1033
+	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1034 1034
 
1035 1035
 	echo $html;
1036 1036
 }
1037 1037
 
1038
-function wpinv_number_callback( $args ) {
1038
+function wpinv_number_callback($args) {
1039 1039
 	global $wpinv_options;
1040 1040
     
1041
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1041
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1042 1042
 
1043
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1044
-		$value = $wpinv_options[ $args['id'] ];
1043
+	if (isset($wpinv_options[$args['id']])) {
1044
+		$value = $wpinv_options[$args['id']];
1045 1045
 	} else {
1046
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1046
+		$value = isset($args['std']) ? $args['std'] : '';
1047 1047
 	}
1048 1048
 
1049
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1049
+	if (isset($args['faux']) && true === $args['faux']) {
1050 1050
 		$args['readonly'] = true;
1051
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1051
+		$value = isset($args['std']) ? $args['std'] : '';
1052 1052
 		$name  = '';
1053 1053
 	} else {
1054
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1054
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1055 1055
 	}
1056 1056
 
1057
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1058
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1059
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1057
+	$max  = isset($args['max']) ? $args['max'] : 999999;
1058
+	$min  = isset($args['min']) ? $args['min'] : 0;
1059
+	$step = isset($args['step']) ? $args['step'] : 1;
1060 1060
 
1061
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1062
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1063
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1061
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1062
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
1063
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1064 1064
 
1065 1065
 	echo $html;
1066 1066
 }
1067 1067
 
1068
-function wpinv_textarea_callback( $args ) {
1068
+function wpinv_textarea_callback($args) {
1069 1069
 	global $wpinv_options;
1070 1070
     
1071
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1071
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1072 1072
 
1073
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1074
-		$value = $wpinv_options[ $args['id'] ];
1073
+	if (isset($wpinv_options[$args['id']])) {
1074
+		$value = $wpinv_options[$args['id']];
1075 1075
 	} else {
1076
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1076
+		$value = isset($args['std']) ? $args['std'] : '';
1077 1077
 	}
1078 1078
     
1079
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1080
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1079
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1080
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
1081 1081
 
1082
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1083
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1082
+	$html = '<textarea class="' . sanitize_html_class($class) . ' txtarea-' . sanitize_html_class($size) . ' wpi-' . esc_attr(sanitize_html_class($sanitize_id)) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']">' . esc_textarea(stripslashes($value)) . '</textarea>';
1083
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1084 1084
 
1085 1085
 	echo $html;
1086 1086
 }
1087 1087
 
1088
-function wpinv_password_callback( $args ) {
1088
+function wpinv_password_callback($args) {
1089 1089
 	global $wpinv_options;
1090 1090
     
1091
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1091
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1092 1092
 
1093
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1094
-		$value = $wpinv_options[ $args['id'] ];
1093
+	if (isset($wpinv_options[$args['id']])) {
1094
+		$value = $wpinv_options[$args['id']];
1095 1095
 	} else {
1096
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1096
+		$value = isset($args['std']) ? $args['std'] : '';
1097 1097
 	}
1098 1098
 
1099
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1100
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
1101
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1099
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1100
+	$html = '<input type="password" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '"/>';
1101
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1102 1102
 
1103 1103
 	echo $html;
1104 1104
 }
1105 1105
 
1106 1106
 function wpinv_missing_callback($args) {
1107 1107
 	printf(
1108
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1108
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
1109 1109
 		'<strong>' . $args['id'] . '</strong>'
1110 1110
 	);
1111 1111
 }
@@ -1113,137 +1113,137 @@  discard block
 block discarded – undo
1113 1113
 function wpinv_select_callback($args) {
1114 1114
 	global $wpinv_options;
1115 1115
     
1116
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1116
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1117 1117
 
1118
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1119
-		$value = $wpinv_options[ $args['id'] ];
1118
+	if (isset($wpinv_options[$args['id']])) {
1119
+		$value = $wpinv_options[$args['id']];
1120 1120
 	} else {
1121
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1121
+		$value = isset($args['std']) ? $args['std'] : '';
1122 1122
 	}
1123 1123
     
1124
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1124
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1125 1125
         $value = $args['selected'];
1126 1126
     }
1127 1127
 
1128
-	if ( isset( $args['placeholder'] ) ) {
1128
+	if (isset($args['placeholder'])) {
1129 1129
 		$placeholder = $args['placeholder'];
1130 1130
 	} else {
1131 1131
 		$placeholder = '';
1132 1132
 	}
1133 1133
 
1134
-	if ( isset( $args['chosen'] ) ) {
1134
+	if (isset($args['chosen'])) {
1135 1135
 		$chosen = 'class="wpinv-chosen"';
1136 1136
 	} else {
1137 1137
 		$chosen = '';
1138 1138
 	}
1139 1139
     
1140
-    if( !empty( $args['onchange'] ) ) {
1141
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
1140
+    if (!empty($args['onchange'])) {
1141
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
1142 1142
     } else {
1143 1143
         $onchange = '';
1144 1144
     }
1145 1145
 
1146
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" ' . $chosen . 'data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1146
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" ' . $chosen . 'data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
1147 1147
 
1148
-	foreach ( $args['options'] as $option => $name ) {
1149
-		$selected = selected( $option, $value, false );
1150
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1148
+	foreach ($args['options'] as $option => $name) {
1149
+		$selected = selected($option, $value, false);
1150
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1151 1151
 	}
1152 1152
 
1153 1153
 	$html .= '</select>';
1154
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1154
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1155 1155
 
1156 1156
 	echo $html;
1157 1157
 }
1158 1158
 
1159
-function wpinv_color_select_callback( $args ) {
1159
+function wpinv_color_select_callback($args) {
1160 1160
 	global $wpinv_options;
1161 1161
     
1162
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1162
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1163 1163
 
1164
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1165
-		$value = $wpinv_options[ $args['id'] ];
1164
+	if (isset($wpinv_options[$args['id']])) {
1165
+		$value = $wpinv_options[$args['id']];
1166 1166
 	} else {
1167
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1167
+		$value = isset($args['std']) ? $args['std'] : '';
1168 1168
 	}
1169 1169
 
1170
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1170
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
1171 1171
 
1172
-	foreach ( $args['options'] as $option => $color ) {
1173
-		$selected = selected( $option, $value, false );
1174
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1172
+	foreach ($args['options'] as $option => $color) {
1173
+		$selected = selected($option, $value, false);
1174
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
1175 1175
 	}
1176 1176
 
1177 1177
 	$html .= '</select>';
1178
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1178
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1179 1179
 
1180 1180
 	echo $html;
1181 1181
 }
1182 1182
 
1183
-function wpinv_rich_editor_callback( $args ) {
1183
+function wpinv_rich_editor_callback($args) {
1184 1184
 	global $wpinv_options, $wp_version;
1185 1185
     
1186
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1186
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1187 1187
 
1188
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1189
-		$value = $wpinv_options[ $args['id'] ];
1188
+	if (isset($wpinv_options[$args['id']])) {
1189
+		$value = $wpinv_options[$args['id']];
1190 1190
 
1191
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1192
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1191
+		if (empty($args['allow_blank']) && empty($value)) {
1192
+			$value = isset($args['std']) ? $args['std'] : '';
1193 1193
 		}
1194 1194
 	} else {
1195
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1195
+		$value = isset($args['std']) ? $args['std'] : '';
1196 1196
 	}
1197 1197
 
1198
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1198
+	$rows = isset($args['size']) ? $args['size'] : 20;
1199 1199
 
1200
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1200
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
1201 1201
 		ob_start();
1202
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ) ) );
1202
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows)));
1203 1203
 		$html = ob_get_clean();
1204 1204
 	} else {
1205
-		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
1205
+		$html = '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" class="wpi-' . esc_attr(sanitize_html_class($args['id'])) . '">' . esc_textarea(stripslashes($value)) . '</textarea>';
1206 1206
 	}
1207 1207
 
1208
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1208
+	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1209 1209
 
1210 1210
 	echo $html;
1211 1211
 }
1212 1212
 
1213
-function wpinv_upload_callback( $args ) {
1213
+function wpinv_upload_callback($args) {
1214 1214
 	global $wpinv_options;
1215 1215
     
1216
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1216
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1217 1217
 
1218
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1218
+	if (isset($wpinv_options[$args['id']])) {
1219 1219
 		$value = $wpinv_options[$args['id']];
1220 1220
 	} else {
1221 1221
 		$value = isset($args['std']) ? $args['std'] : '';
1222 1222
 	}
1223 1223
 
1224
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1225
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1226
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1227
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1224
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1225
+	$html = '<input type="text" class="' . sanitize_html_class($size) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr(stripslashes($value)) . '"/>';
1226
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
1227
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1228 1228
 
1229 1229
 	echo $html;
1230 1230
 }
1231 1231
 
1232
-function wpinv_color_callback( $args ) {
1232
+function wpinv_color_callback($args) {
1233 1233
 	global $wpinv_options;
1234 1234
     
1235
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1235
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1236 1236
 
1237
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1238
-		$value = $wpinv_options[ $args['id'] ];
1237
+	if (isset($wpinv_options[$args['id']])) {
1238
+		$value = $wpinv_options[$args['id']];
1239 1239
 	} else {
1240
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1240
+		$value = isset($args['std']) ? $args['std'] : '';
1241 1241
 	}
1242 1242
 
1243
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1243
+	$default = isset($args['std']) ? $args['std'] : '';
1244 1244
 
1245
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
1246
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1245
+	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" value="' . esc_attr($value) . '" data-default-color="' . esc_attr($default) . '" />';
1246
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1247 1247
 
1248 1248
 	echo $html;
1249 1249
 }
@@ -1251,9 +1251,9 @@  discard block
 block discarded – undo
1251 1251
 function wpinv_country_states_callback($args) {
1252 1252
 	global $wpinv_options;
1253 1253
     
1254
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1254
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1255 1255
 
1256
-	if ( isset( $args['placeholder'] ) ) {
1256
+	if (isset($args['placeholder'])) {
1257 1257
 		$placeholder = $args['placeholder'];
1258 1258
 	} else {
1259 1259
 		$placeholder = '';
@@ -1261,17 +1261,17 @@  discard block
 block discarded – undo
1261 1261
 
1262 1262
 	$states = wpinv_get_country_states();
1263 1263
 
1264
-	$chosen = ( $args['chosen'] ? ' wpinv-chosen' : '' );
1265
-	$class = empty( $states ) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1266
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1264
+	$chosen = ($args['chosen'] ? ' wpinv-chosen' : '');
1265
+	$class = empty($states) ? ' class="wpinv-no-states' . $chosen . '"' : 'class="' . $chosen . '"';
1266
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
1267 1267
 
1268
-	foreach ( $states as $option => $name ) {
1269
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1270
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1268
+	foreach ($states as $option => $name) {
1269
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
1270
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1271 1271
 	}
1272 1272
 
1273 1273
 	$html .= '</select>';
1274
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1274
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1275 1275
 
1276 1276
 	echo $html;
1277 1277
 }
@@ -1286,25 +1286,25 @@  discard block
 block discarded – undo
1286 1286
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
1287 1287
 		<thead>
1288 1288
 			<tr>
1289
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
1290
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
1291
-                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
1292
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
1293
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
1294
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
1289
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
1290
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
1291
+                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
1292
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
1293
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
1294
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
1295 1295
 			</tr>
1296 1296
 		</thead>
1297 1297
         <tbody>
1298
-		<?php if( !empty( $rates ) ) : ?>
1299
-			<?php foreach( $rates as $key => $rate ) : ?>
1298
+		<?php if (!empty($rates)) : ?>
1299
+			<?php foreach ($rates as $key => $rate) : ?>
1300 1300
             <?php 
1301
-            $sanitized_key = wpinv_sanitize_key( $key );
1301
+            $sanitized_key = wpinv_sanitize_key($key);
1302 1302
             ?>
1303 1303
 			<tr>
1304 1304
 				<td class="wpinv_tax_country">
1305 1305
 					<?php
1306
-					echo wpinv_html_select( array(
1307
-						'options'          => wpinv_get_country_list( true ),
1306
+					echo wpinv_html_select(array(
1307
+						'options'          => wpinv_get_country_list(true),
1308 1308
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1309 1309
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1310 1310
 						'selected'         => $rate['country'],
@@ -1312,72 +1312,72 @@  discard block
 block discarded – undo
1312 1312
 						'show_option_none' => false,
1313 1313
 						'class'            => 'wpinv-tax-country',
1314 1314
 						'chosen'           => false,
1315
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1316
-					) );
1315
+						'placeholder'      => __('Choose a country', 'invoicing')
1316
+					));
1317 1317
 					?>
1318 1318
 				</td>
1319 1319
 				<td class="wpinv_tax_state">
1320 1320
 					<?php
1321
-					$states = wpinv_get_country_states( $rate['country'] );
1322
-					if( !empty( $states ) ) {
1323
-						echo wpinv_html_select( array(
1324
-							'options'          => array_merge( array( '' => '' ), $states ),
1321
+					$states = wpinv_get_country_states($rate['country']);
1322
+					if (!empty($states)) {
1323
+						echo wpinv_html_select(array(
1324
+							'options'          => array_merge(array('' => ''), $states),
1325 1325
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1326 1326
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1327 1327
 							'selected'         => $rate['state'],
1328 1328
 							'show_option_all'  => false,
1329 1329
 							'show_option_none' => false,
1330 1330
 							'chosen'           => false,
1331
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1332
-						) );
1331
+							'placeholder'      => __('Choose a state', 'invoicing')
1332
+						));
1333 1333
 					} else {
1334
-						echo wpinv_html_text( array(
1334
+						echo wpinv_html_text(array(
1335 1335
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1336
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1336
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
1337 1337
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1338
-						) );
1338
+						));
1339 1339
 					}
1340 1340
 					?>
1341 1341
 				</td>
1342 1342
 				<td class="wpinv_tax_global">
1343
-					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
1344
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1343
+					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/>
1344
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1345 1345
 				</td>
1346
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td>
1347
-                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td>
1348
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1346
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td>
1347
+                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td>
1348
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1349 1349
 			</tr>
1350 1350
 			<?php endforeach; ?>
1351 1351
 		<?php else : ?>
1352 1352
 			<tr>
1353 1353
 				<td class="wpinv_tax_country">
1354 1354
 					<?php
1355
-					echo wpinv_html_select( array(
1356
-						'options'          => wpinv_get_country_list( true ),
1355
+					echo wpinv_html_select(array(
1356
+						'options'          => wpinv_get_country_list(true),
1357 1357
 						'name'             => 'tax_rates[0][country]',
1358 1358
 						'show_option_all'  => false,
1359 1359
 						'show_option_none' => false,
1360 1360
 						'class'            => 'wpinv-tax-country',
1361 1361
 						'chosen'           => false,
1362
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1363
-					) ); ?>
1362
+						'placeholder'      => __('Choose a country', 'invoicing')
1363
+					)); ?>
1364 1364
 				</td>
1365 1365
 				<td class="wpinv_tax_state">
1366
-					<?php echo wpinv_html_text( array(
1366
+					<?php echo wpinv_html_text(array(
1367 1367
 						'name' => 'tax_rates[0][state]'
1368
-					) ); ?>
1368
+					)); ?>
1369 1369
 				</td>
1370 1370
 				<td class="wpinv_tax_global">
1371 1371
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
1372
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1372
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1373 1373
 				</td>
1374
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td>
1374
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td>
1375 1375
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
1376
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1376
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1377 1377
 			</tr>
1378 1378
 		<?php endif; ?>
1379 1379
         </tbody>
1380
-        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1380
+        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot>
1381 1381
 	</table>
1382 1382
 	<?php
1383 1383
 	echo ob_get_clean();
@@ -1388,44 +1388,44 @@  discard block
 block discarded – undo
1388 1388
     ob_start(); ?>
1389 1389
     </td><tr>
1390 1390
     <td colspan="2" class="wpinv_tools_tdbox">
1391
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1392
-    <?php do_action( 'wpinv_tools_before' ); ?>
1391
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1392
+    <?php do_action('wpinv_tools_before'); ?>
1393 1393
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1394 1394
         <thead>
1395 1395
             <tr>
1396
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1397
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1398
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1396
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1397
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1398
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1399 1399
             </tr>
1400 1400
         </thead>
1401
-            <?php do_action( 'wpinv_tools_row' ); ?>
1401
+            <?php do_action('wpinv_tools_row'); ?>
1402 1402
         <tbody>
1403 1403
         </tbody>
1404 1404
     </table>
1405
-    <?php do_action( 'wpinv_tools_after' ); ?>
1405
+    <?php do_action('wpinv_tools_after'); ?>
1406 1406
     <?php
1407 1407
     echo ob_get_clean();
1408 1408
 }
1409 1409
 
1410
-function wpinv_descriptive_text_callback( $args ) {
1411
-	echo wp_kses_post( $args['desc'] );
1410
+function wpinv_descriptive_text_callback($args) {
1411
+	echo wp_kses_post($args['desc']);
1412 1412
 }
1413 1413
 
1414
-function wpinv_hook_callback( $args ) {
1415
-	do_action( 'wpinv_' . $args['id'], $args );
1414
+function wpinv_hook_callback($args) {
1415
+	do_action('wpinv_' . $args['id'], $args);
1416 1416
 }
1417 1417
 
1418 1418
 function wpinv_set_settings_cap() {
1419 1419
 	return 'manage_options';
1420 1420
 }
1421
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1421
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1422 1422
 
1423
-function wpinv_settings_sanitize_input( $value, $key ) {
1424
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1425
-        $value = wpinv_sanitize_amount( $value, 4 );
1423
+function wpinv_settings_sanitize_input($value, $key) {
1424
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1425
+        $value = wpinv_sanitize_amount($value, 4);
1426 1426
         $value = $value >= 100 ? 99 : $value;
1427 1427
     }
1428 1428
         
1429 1429
     return $value;
1430 1430
 }
1431
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1432 1431
\ No newline at end of file
1432
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1433 1433
\ No newline at end of file
Please login to merge, or discard this patch.