Passed
Push — master ( 5bb76a...9b8253 )
by Brian
09:28 queued 05:23
created
includes/wpinv-gateway-functions.php 1 patch
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Contains gateway functions.
4 4
  *
5 5
  */
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * Returns an array of payment gateways.
@@ -11,82 +11,82 @@  discard block
 block discarded – undo
11 11
  * @return array
12 12
  */
13 13
 function wpinv_get_payment_gateways() {
14
-    return apply_filters( 'wpinv_payment_gateways', array() );
14
+    return apply_filters('wpinv_payment_gateways', array());
15 15
 }
16 16
 
17
-function wpinv_payment_gateway_titles( $all_gateways ) {
17
+function wpinv_payment_gateway_titles($all_gateways) {
18 18
     global $wpinv_options;
19 19
 
20 20
     $gateways = array();
21
-    foreach ( $all_gateways as $key => $gateway ) {
22
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
23
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
21
+    foreach ($all_gateways as $key => $gateway) {
22
+        if (!empty($wpinv_options[$key . '_title'])) {
23
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
24 24
         }
25 25
 
26
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
26
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
27 27
     }
28 28
 
29
-    asort( $gateways );
29
+    asort($gateways);
30 30
 
31
-    foreach ( $gateways as $gateway => $key ) {
31
+    foreach ($gateways as $gateway => $key) {
32 32
         $gateways[$gateway] = $all_gateways[$gateway];
33 33
     }
34 34
 
35 35
     return $gateways;
36 36
 }
37
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
37
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
38 38
 
39
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
39
+function wpinv_get_enabled_payment_gateways($sort = false) {
40 40
     $gateways = wpinv_get_payment_gateways();
41
-    $enabled  = wpinv_get_option( 'gateways', false );
41
+    $enabled  = wpinv_get_option('gateways', false);
42 42
 
43 43
     $gateway_list = array();
44 44
 
45
-    foreach ( $gateways as $key => $gateway ) {
46
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
47
-            $gateway_list[ $key ] = $gateway;
45
+    foreach ($gateways as $key => $gateway) {
46
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
47
+            $gateway_list[$key] = $gateway;
48 48
         }
49 49
     }
50 50
 
51
-    if ( true === $sort ) {
52
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
51
+    if (true === $sort) {
52
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
53 53
         
54 54
         // Reorder our gateways so the default is first
55 55
         $default_gateway_id = wpinv_get_default_gateway();
56 56
 
57
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
58
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
59
-            unset( $gateway_list[ $default_gateway_id ] );
57
+        if (wpinv_is_gateway_active($default_gateway_id)) {
58
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
59
+            unset($gateway_list[$default_gateway_id]);
60 60
 
61
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
61
+            $gateway_list = array_merge($default_gateway, $gateway_list);
62 62
         }
63 63
     }
64 64
 
65
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
65
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
66 66
 }
67 67
 
68
-function wpinv_sort_gateway_order( $a, $b ) {
68
+function wpinv_sort_gateway_order($a, $b) {
69 69
     return $a['ordering'] - $b['ordering'];
70 70
 }
71 71
 
72
-function wpinv_is_gateway_active( $gateway ) {
72
+function wpinv_is_gateway_active($gateway) {
73 73
     $gateways = wpinv_get_enabled_payment_gateways();
74 74
 
75
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
75
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
76 76
 
77
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
77
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
78 78
 }
79 79
 
80 80
 function wpinv_get_default_gateway() {
81
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
81
+    $default = wpinv_get_option('default_gateway', 'paypal');
82 82
 
83
-    if ( !wpinv_is_gateway_active( $default ) ) {
83
+    if (!wpinv_is_gateway_active($default)) {
84 84
         $gateways = wpinv_get_enabled_payment_gateways();
85
-        $gateways = array_keys( $gateways );
86
-        $default  = reset( $gateways );
85
+        $gateways = array_keys($gateways);
86
+        $default  = reset($gateways);
87 87
     }
88 88
 
89
-    return apply_filters( 'wpinv_default_gateway', $default );
89
+    return apply_filters('wpinv_default_gateway', $default);
90 90
 }
91 91
 
92 92
 /**
@@ -95,17 +95,17 @@  discard block
 block discarded – undo
95 95
  * @param string $gateway The gateway to key.
96 96
  * @return string
97 97
  */
98
-function wpinv_get_gateway_admin_label( $gateway ) {
98
+function wpinv_get_gateway_admin_label($gateway) {
99 99
 
100
-    if ( empty( $gateway ) || 'none' == $gateway ) {
101
-        return esc_html__( 'No Gateway', 'invoicing' );
100
+    if (empty($gateway) || 'none' == $gateway) {
101
+        return esc_html__('No Gateway', 'invoicing');
102 102
     }
103 103
 
104 104
     $gateways = wpinv_get_payment_gateways();
105
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
106
-    $gateway  = apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
105
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
106
+    $gateway  = apply_filters('wpinv_gateway_admin_label', $label, $gateway);
107 107
 
108
-    return wpinv_clean( $gateway );
108
+    return wpinv_clean($gateway);
109 109
 }
110 110
 
111 111
 /**
@@ -113,49 +113,49 @@  discard block
 block discarded – undo
113 113
  * 
114 114
  * @param string $gateway
115 115
  */
116
-function wpinv_get_gateway_description( $gateway ) {
116
+function wpinv_get_gateway_description($gateway) {
117 117
     global $wpinv_options;
118 118
 
119
-    $description = ! empty( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
119
+    $description = !empty($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
120 120
 
121
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
121
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
122 122
 }
123 123
 
124
-function wpinv_get_gateway_button_label( $gateway ) {
125
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
124
+function wpinv_get_gateway_button_label($gateway) {
125
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
126 126
 }
127 127
 
128
-function wpinv_get_gateway_checkout_label( $gateway ) {
128
+function wpinv_get_gateway_checkout_label($gateway) {
129 129
     $gateways = wpinv_get_payment_gateways();
130
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
130
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
131 131
 
132
-    if ( $gateway == 'none' ) {
133
-        $label = __( 'None', 'invoicing' );
132
+    if ($gateway == 'none') {
133
+        $label = __('None', 'invoicing');
134 134
     }
135 135
 
136
-    return apply_filters( 'wpinv_gateway_checkout_label', ucfirst( $label ), $gateway );
136
+    return apply_filters('wpinv_gateway_checkout_label', ucfirst($label), $gateway);
137 137
 }
138 138
 
139
-function wpinv_settings_sections_gateways( $settings ) {
139
+function wpinv_settings_sections_gateways($settings) {
140 140
     $gateways = wpinv_get_payment_gateways();
141 141
     
142 142
     if (!empty($gateways)) {
143
-        foreach  ($gateways as $key => $gateway) {
143
+        foreach ($gateways as $key => $gateway) {
144 144
             $settings[$key] = $gateway['admin_label'];
145 145
         }
146 146
     }
147 147
     
148 148
     return $settings;    
149 149
 }
150
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
150
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
151 151
 
152 152
 /**
153 153
  * Adds GateWay settings.
154 154
  */
155
-function wpinv_settings_gateways( $settings ) {
155
+function wpinv_settings_gateways($settings) {
156 156
 
157 157
     // Loop through each gateway.
158
-    foreach  ( wpinv_get_payment_gateways() as $key => $gateway ) {
158
+    foreach (wpinv_get_payment_gateways() as $key => $gateway) {
159 159
 
160 160
         $gateway_settings = array(
161 161
 
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
             "{$key}_header" => array(
164 164
 
165 165
                 'id'     => "{$key}_gateway_header",
166
-                'name'   => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
166
+                'name'   => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
167 167
                 'custom' => $key,
168 168
                 'type'   => 'gateway_header',
169 169
 
@@ -172,56 +172,56 @@  discard block
 block discarded – undo
172 172
             // Activate/Deactivate a gateway.
173 173
             "{$key}_active" => array(
174 174
                 'id'   => $key . '_active',
175
-                'name' => __( 'Activate', 'invoicing' ),
176
-                'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
175
+                'name' => __('Activate', 'invoicing'),
176
+                'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
177 177
                 'type' => 'checkbox',
178 178
             ),
179 179
 
180 180
             // Activate/Deactivate sandbox.
181 181
             "{$key}_sandbox" => array(
182 182
                 'id'   => $key . '_sandbox',
183
-                'name' => __( 'Sandbox', 'invoicing' ),
184
-                'desc' => __( 'Enable sandbox to test payments', 'invoicing' ),
183
+                'name' => __('Sandbox', 'invoicing'),
184
+                'desc' => __('Enable sandbox to test payments', 'invoicing'),
185 185
                 'type' => 'checkbox',
186 186
             ),
187 187
 
188 188
             // Checkout title.
189 189
             "{$key}_title" => array(
190 190
                 'id'   => $key . '_title',
191
-                'name' => __( 'Checkout Title', 'invoicing' ),
192
-                'std'  => isset( $gateway['checkout_label'] ) ? $gateway['checkout_label'] : '',
191
+                'name' => __('Checkout Title', 'invoicing'),
192
+                'std'  => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : '',
193 193
                 'type' => 'text',
194 194
             ),
195 195
 
196 196
             // Checkout description.
197 197
             "{$key}_desc" => array(
198 198
                 'id'   => $key . '_desc',
199
-                'name' => __( 'Checkout Description', 'invoicing' ),
200
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
199
+                'name' => __('Checkout Description', 'invoicing'),
200
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
201 201
                 'type' => 'text',
202 202
             ),
203 203
 
204 204
             // Checkout order.
205 205
             "{$key}_ordering" => array(
206 206
                 'id'   => $key . '_ordering',
207
-                'name' => __( 'Priority', 'invoicing' ),
208
-                'std'  => apply_filters( "getpaid_default_{$key}_checkout_description", '' ),
207
+                'name' => __('Priority', 'invoicing'),
208
+                'std'  => apply_filters("getpaid_default_{$key}_checkout_description", ''),
209 209
                 'type' => 'number',
210 210
                 'step' => '1',
211 211
                 'min'  => '-100000',
212 212
                 'max'  => '100000',
213
-                'std'  => isset( $gateway['ordering'] ) ? $gateway['ordering'] : '10',
213
+                'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
214 214
             ),
215 215
 
216 216
         );
217 217
 
218 218
         // Maybe remove the sandbox.
219
-        if ( ! apply_filters( "wpinv_{$key}_supports_sandbox", false ) ) {
220
-            unset( $gateway_settings["{$key}_sandbox"] );
219
+        if (!apply_filters("wpinv_{$key}_supports_sandbox", false)) {
220
+            unset($gateway_settings["{$key}_sandbox"]);
221 221
         }
222 222
   
223
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings', $gateway_settings, $key, $gateway );
224
-        $gateway_settings = apply_filters( 'wpinv_gateway_settings_' . $key, $gateway_settings, $gateway );
223
+        $gateway_settings = apply_filters('wpinv_gateway_settings', $gateway_settings, $key, $gateway);
224
+        $gateway_settings = apply_filters('wpinv_gateway_settings_' . $key, $gateway_settings, $gateway);
225 225
         
226 226
         $settings[$key] = $gateway_settings;
227 227
     }
@@ -229,57 +229,57 @@  discard block
 block discarded – undo
229 229
     return $settings;
230 230
 
231 231
 }
232
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
232
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
233 233
 
234
-function wpinv_gateway_header_callback( $args ) {
235
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
234
+function wpinv_gateway_header_callback($args) {
235
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
236 236
 }
237 237
 
238
-function wpinv_get_gateway_supports( $gateway ) {
238
+function wpinv_get_gateway_supports($gateway) {
239 239
     $gateways = wpinv_get_enabled_payment_gateways();
240
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
241
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
240
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
241
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
242 242
 }
243 243
 
244
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
245
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
244
+function wpinv_get_chosen_gateway($invoice_id = 0) {
245
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
246 246
 
247 247
     $chosen = false;
248
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
248
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
249 249
         $chosen = $invoice->get_gateway();
250 250
     }
251 251
 
252
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
252
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
253 253
 
254
-	if ( false !== $chosen ) {
255
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
254
+	if (false !== $chosen) {
255
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
256 256
 	}
257 257
 
258
-	if ( ! empty ( $chosen ) ) {
259
-		$enabled_gateway = urldecode( $chosen );
260
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
258
+	if (!empty ($chosen)) {
259
+		$enabled_gateway = urldecode($chosen);
260
+	} else if (!empty($invoice) && (float) $invoice->get_subtotal() <= 0) {
261 261
 		$enabled_gateway = 'manual';
262 262
 	} else {
263 263
 		$enabled_gateway = wpinv_get_default_gateway();
264 264
 	}
265 265
     
266
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
267
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
266
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
267
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
268 268
             $enabled_gateway = wpinv_get_default_gateway();
269
-        }else{
269
+        } else {
270 270
             $enabled_gateway = $gateways[0];
271 271
         }
272 272
 
273 273
     }
274 274
 
275
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
275
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
276 276
 }
277 277
 
278
-function wpinv_record_gateway_error( $title = '', $message = '' ) {
279
-    return wpinv_error_log( $message, $title );
278
+function wpinv_record_gateway_error($title = '', $message = '') {
279
+    return wpinv_error_log($message, $title);
280 280
 }
281 281
 
282
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
282
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
283 283
 	$ret  = 0;
284 284
 	$args = array(
285 285
 		'meta_key'    => '_wpinv_gateway',
@@ -290,48 +290,48 @@  discard block
 block discarded – undo
290 290
 		'fields'      => 'ids'
291 291
 	);
292 292
 
293
-	$payments = new WP_Query( $args );
293
+	$payments = new WP_Query($args);
294 294
 
295
-	if( $payments )
295
+	if ($payments)
296 296
 		$ret = $payments->post_count;
297 297
 	return $ret;
298 298
 }
299 299
 
300
-function wpinv_settings_update_gateways( $input ) {
300
+function wpinv_settings_update_gateways($input) {
301 301
     global $wpinv_options;
302 302
     
303
-    if ( !empty( $input['save_gateway'] ) ) {
304
-        $gateways = wpinv_get_option( 'gateways', false );
303
+    if (!empty($input['save_gateway'])) {
304
+        $gateways = wpinv_get_option('gateways', false);
305 305
         $gateways = !empty($gateways) ? $gateways : array();
306 306
         $gateway = $input['save_gateway'];
307 307
         
308
-        if ( !empty( $input[$gateway . '_active'] ) ) {
308
+        if (!empty($input[$gateway . '_active'])) {
309 309
             $gateways[$gateway] = 1;
310 310
         } else {
311
-            if ( isset( $gateways[$gateway] ) ) {
312
-                unset( $gateways[$gateway] );
311
+            if (isset($gateways[$gateway])) {
312
+                unset($gateways[$gateway]);
313 313
             }
314 314
         }
315 315
         
316 316
         $input['gateways'] = $gateways;
317 317
     }
318 318
     
319
-    if ( !empty( $input['default_gateway'] ) ) {
319
+    if (!empty($input['default_gateway'])) {
320 320
         $gateways = wpinv_get_payment_gateways();
321 321
         
322
-        foreach ( $gateways as $key => $gateway ) {
323
-            $active   = 0;
324
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
322
+        foreach ($gateways as $key => $gateway) {
323
+            $active = 0;
324
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
325 325
                 $active = 1;
326 326
             }
327 327
             
328 328
             $input[$key . '_active'] = $active;
329 329
             
330
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
330
+            if (empty($wpinv_options[$key . '_title'])) {
331 331
                 $input[$key . '_title'] = $gateway['checkout_label'];
332 332
             }
333 333
             
334
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
334
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
335 335
                 $input[$key . '_ordering'] = $gateway['ordering'];
336 336
             }
337 337
         }
@@ -339,27 +339,27 @@  discard block
 block discarded – undo
339 339
     
340 340
     return $input;
341 341
 }
342
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
342
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
343 343
 
344 344
 // PayPal Standard settings
345
-function wpinv_gateway_settings_paypal( $setting ) {    
346
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
347
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
345
+function wpinv_gateway_settings_paypal($setting) {    
346
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
347
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
348 348
     
349 349
     $setting['paypal_sandbox'] = array(
350 350
             'type' => 'checkbox',
351 351
             'id'   => 'paypal_sandbox',
352
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
353
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
352
+            'name' => __('PayPal Sandbox', 'invoicing'),
353
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
354 354
             'std'  => 1
355 355
         );
356 356
         
357 357
     $setting['paypal_email'] = array(
358 358
             'type' => 'text',
359 359
             'id'   => 'paypal_email',
360
-            'name' => __( 'PayPal Email', 'invoicing' ),
361
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
362
-            'std' => __( '[email protected]', 'invoicing' ),
360
+            'name' => __('PayPal Email', 'invoicing'),
361
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
362
+            'std' => __('[email protected]', 'invoicing'),
363 363
         );
364 364
     /*
365 365
     $setting['paypal_ipn_url'] = array(
@@ -373,18 +373,18 @@  discard block
 block discarded – undo
373 373
         
374 374
     return $setting;
375 375
 }
376
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
376
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
377 377
 
378 378
 /**
379 379
  * Displays the ipn url field.
380 380
  */
381
-function wpinv_ipn_url_callback( $args ) {
382
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
381
+function wpinv_ipn_url_callback($args) {
382
+    $sanitize_id = wpinv_sanitize_key($args['id']);
383 383
     
384 384
     $attrs = $args['readonly'] ? ' readonly' : '';
385 385
 
386
-    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
387
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
386
+    $html = '<input class="regular-text" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" onClick="this.select()">';
387
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
388 388
 
389 389
     echo $html;
390 390
 }
@@ -396,9 +396,9 @@  discard block
 block discarded – undo
396 396
  * 
397 397
  * @return bool
398 398
  */
399
-function wpinv_is_test_mode( $gateway = '' ) {
400
-    $sandbox = empty( $gateway ) ? false : wpinv_get_option( "{$gateway}_sandbox", false );
401
-    return apply_filters( 'wpinv_is_test_mode', $sandbox, $gateway );
399
+function wpinv_is_test_mode($gateway = '') {
400
+    $sandbox = empty($gateway) ? false : wpinv_get_option("{$gateway}_sandbox", false);
401
+    return apply_filters('wpinv_is_test_mode', $sandbox, $gateway);
402 402
 }
403 403
 
404 404
 /**
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
  * 
410 410
  * @return string
411 411
  */
412
-function wpinv_get_ipn_url( $gateway = false, $args = array() ) {
412
+function wpinv_get_ipn_url($gateway = false, $args = array()) {
413 413
     $args = wp_parse_args(
414 414
         array(
415 415
             'wpi-listener' => 'IPN',
@@ -418,37 +418,37 @@  discard block
 block discarded – undo
418 418
         $args
419 419
     );
420 420
 
421
-    return apply_filters( 'wpinv_ipn_url', add_query_arg( $args,  home_url( 'index.php' ) ), $gateway, $args );
421
+    return apply_filters('wpinv_ipn_url', add_query_arg($args, home_url('index.php')), $gateway, $args);
422 422
 
423 423
 }
424 424
 
425 425
 /**
426 426
  * Retrieves request data with slashes removed slashes.
427 427
  */
428
-function wpinv_get_post_data( $method = 'request' ) {
428
+function wpinv_get_post_data($method = 'request') {
429 429
 
430
-    if ( $method == 'post' ) {
431
-        return wp_unslash( $_POST );
430
+    if ($method == 'post') {
431
+        return wp_unslash($_POST);
432 432
     }
433 433
 
434
-    if ( $method == 'get' ) {
435
-        return wp_unslash( $_GET );
434
+    if ($method == 'get') {
435
+        return wp_unslash($_GET);
436 436
     }
437 437
 
438
-    return wp_unslash( $_REQUEST );
438
+    return wp_unslash($_REQUEST);
439 439
   
440 440
 }
441 441
 
442 442
 /**
443 443
  * Checks if a given gateway supports subscription payments.
444 444
  */
445
-function wpinv_gateway_support_subscription( $gateway ) {
445
+function wpinv_gateway_support_subscription($gateway) {
446 446
     $supports = false;
447 447
 
448
-    if ( wpinv_is_gateway_active( $gateway ) ) {
449
-        $supports = apply_filters( 'wpinv_' . $gateway . '_support_subscription', $supports );
448
+    if (wpinv_is_gateway_active($gateway)) {
449
+        $supports = apply_filters('wpinv_' . $gateway . '_support_subscription', $supports);
450 450
 
451
-        $supports = apply_filters( 'getapid_gateway_supports_subscription', $supports, $gateway );
451
+        $supports = apply_filters('getapid_gateway_supports_subscription', $supports, $gateway);
452 452
     }
453 453
 
454 454
     return $supports;
@@ -460,14 +460,14 @@  discard block
 block discarded – undo
460 460
  * @param array $gateways an array of gateways.
461 461
  * @param GetPaid_Payment_Form $form payment form.
462 462
  */
463
-function wpinv_payment_gateways_on_cart( $gateways, $form ) {
463
+function wpinv_payment_gateways_on_cart($gateways, $form) {
464 464
 
465
-    if ( $form->is_recurring() ) {
465
+    if ($form->is_recurring()) {
466 466
 
467
-        foreach ( array_keys( $gateways ) as $gateway ) {
467
+        foreach (array_keys($gateways) as $gateway) {
468 468
 
469
-            if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
470
-                unset( $gateways[$gateway] );
469
+            if (!wpinv_gateway_support_subscription($gateway)) {
470
+                unset($gateways[$gateway]);
471 471
             }
472 472
 
473 473
         }
@@ -476,4 +476,4 @@  discard block
 block discarded – undo
476 476
 
477 477
     return $gateways;
478 478
 }
479
-add_filter( 'getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2 );
479
+add_filter('getpaid_payment_form_gateways', 'wpinv_payment_gateways_on_cart', 10, 2);
Please login to merge, or discard this patch.
templates/payment-forms-admin/edit/heading.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -8,23 +8,23 @@
 block discarded – undo
8 8
  */
9 9
 
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13 13
 ?>
14 14
 
15 15
 <div class='form-group'>
16
-    <label :for="active_form_element.id + '_edit_heading'"><?php esc_html_e( 'Heading', 'invoicing' ) ?></label>
16
+    <label :for="active_form_element.id + '_edit_heading'"><?php esc_html_e('Heading', 'invoicing') ?></label>
17 17
     <input :id="active_form_element.id + '_edit_heading'" v-model='active_form_element.text' class='form-control' type='text' />
18 18
 </div>
19 19
 
20 20
 <div class='form-group'>
21
-    <label :for="active_form_element.id + '_edit_level'"><?php esc_html_e( 'Select Heading Level', 'invoicing' ) ?></label>
21
+    <label :for="active_form_element.id + '_edit_level'"><?php esc_html_e('Select Heading Level', 'invoicing') ?></label>
22 22
     <select class='form-control custom-select' :id="active_form_element.id + '_edit_level'" v-model='active_form_element.level'>
23
-        <option value='h1'><?php esc_html_e( 'H1', 'invoicing' ); ?></option>
24
-        <option value='h2'><?php esc_html_e( 'H2', 'invoicing' ); ?></option>
25
-        <option value='h3'><?php esc_html_e( 'H3', 'invoicing' ); ?></option>
26
-        <option value='h4'><?php esc_html_e( 'H4', 'invoicing' ); ?></option>
27
-        <option value='h5'><?php esc_html_e( 'H5', 'invoicing' ); ?></option>
28
-        <option value='h6'><?php esc_html_e( 'H6', 'invoicing' ); ?></option>
23
+        <option value='h1'><?php esc_html_e('H1', 'invoicing'); ?></option>
24
+        <option value='h2'><?php esc_html_e('H2', 'invoicing'); ?></option>
25
+        <option value='h3'><?php esc_html_e('H3', 'invoicing'); ?></option>
26
+        <option value='h4'><?php esc_html_e('H4', 'invoicing'); ?></option>
27
+        <option value='h5'><?php esc_html_e('H5', 'invoicing'); ?></option>
28
+        <option value='h6'><?php esc_html_e('H6', 'invoicing'); ?></option>
29 29
     </select>
30 30
 </div>
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +335 added lines, -335 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
     exit; // Exit if accessed directly
4 4
 }
5 5
 
@@ -21,79 +21,79 @@  discard block
 block discarded – undo
21 21
     public function init() {
22 22
         global $wp_filesystem;
23 23
 
24
-        if ( empty( $wp_filesystem ) ) {
25
-            require_once( ABSPATH . '/wp-admin/includes/file.php' );
24
+        if (empty($wp_filesystem)) {
25
+            require_once(ABSPATH . '/wp-admin/includes/file.php');
26 26
             WP_Filesystem();
27 27
             global $wp_filesystem;
28 28
         }
29 29
         $this->wp_filesystem    = $wp_filesystem;
30 30
 
31 31
         $this->export_dir       = $this->export_location();
32
-        $this->export_url       = $this->export_location( true );
32
+        $this->export_url       = $this->export_location(true);
33 33
         $this->export           = 'invoicing';
34 34
         $this->filetype         = 'csv';
35 35
         $this->per_page         = 20;
36 36
 
37
-        do_action( 'wpinv_class_reports_init', $this );
37
+        do_action('wpinv_class_reports_init', $this);
38 38
     }
39 39
 
40 40
     public function includes() {
41
-        do_action( 'wpinv_class_reports_includes', $this );
41
+        do_action('wpinv_class_reports_includes', $this);
42 42
     }
43 43
 
44 44
     public function actions() {
45
-        if ( is_admin() ) {
46
-            add_action( 'admin_menu', array( $this, 'add_submenu' ), 20 );
47
-            add_action( 'wpinv_reports_tab_reports', array( $this, 'reports' ) );
48
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
49
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
50
-            add_action( 'wp_ajax_wpinv_ajax_discount_use_export', array( $this, 'discount_use_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 20);
47
+            add_action('wpinv_reports_tab_reports', array($this, 'reports'));
48
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
49
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
50
+            add_action('wp_ajax_wpinv_ajax_discount_use_export', array($this, 'discount_use_export'));
51 51
 
52 52
             // Export Invoices.
53
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
54
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
55
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
56
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
53
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
54
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
55
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
56
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
57 57
 
58 58
             // Reports.
59
-            add_action( 'wpinv_reports_view_earnings', array( $this, 'earnings_report' ) );
60
-            add_action( 'wpinv_reports_view_gateways', array( $this, 'gateways_report' ) );
61
-            add_action( 'wpinv_reports_view_items', array( $this, 'items_report' ) );
62
-            add_action( 'wpinv_reports_view_taxes', array( $this, 'tax_report' ) );
59
+            add_action('wpinv_reports_view_earnings', array($this, 'earnings_report'));
60
+            add_action('wpinv_reports_view_gateways', array($this, 'gateways_report'));
61
+            add_action('wpinv_reports_view_items', array($this, 'items_report'));
62
+            add_action('wpinv_reports_view_taxes', array($this, 'tax_report'));
63 63
         }
64
-        do_action( 'wpinv_class_reports_actions', $this );
64
+        do_action('wpinv_class_reports_actions', $this);
65 65
     }
66 66
 
67 67
     public function add_submenu() {
68 68
         global $wpi_reports_page;
69
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), wpinv_get_capability(), 'wpinv-reports', array( $this, 'reports_page' ) );
69
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), wpinv_get_capability(), 'wpinv-reports', array($this, 'reports_page'));
70 70
     }
71 71
 
72 72
     public function reports_page() {
73 73
 
74
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
75
-            wp_enqueue_script( 'postbox' );
74
+        if (!wp_script_is('postbox', 'enqueued')) {
75
+            wp_enqueue_script('postbox');
76 76
         }
77 77
 
78
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
79
-            wp_enqueue_script( 'jquery-ui-datepicker' );
78
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
79
+            wp_enqueue_script('jquery-ui-datepicker');
80 80
         }
81 81
 
82
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
83
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports';
82
+        $current_page = admin_url('admin.php?page=wpinv-reports');
83
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports';
84 84
         ?>
85 85
         <div class="wrap wpi-reports-wrap">
86
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
86
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
87 87
             <h2 class="nav-tab-wrapper wp-clearfix">
88
-                <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'reports', 'settings-updated' => false ), $current_page ) ); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Reports', 'invoicing' ); ?></a>
89
-                <a href="<?php echo esc_url( add_query_arg( array( 'tab' => 'export', 'settings-updated' => false ), $current_page ) ); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e( 'Export', 'invoicing' ); ?></a>
90
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
88
+                <a href="<?php echo esc_url(add_query_arg(array('tab' => 'reports', 'settings-updated' => false), $current_page)); ?>" class="nav-tab <?php echo $active_tab == 'reports' ? 'nav-tab-active' : ''; ?>"><?php _e('Reports', 'invoicing'); ?></a>
89
+                <a href="<?php echo esc_url(add_query_arg(array('tab' => 'export', 'settings-updated' => false), $current_page)); ?>" class="nav-tab <?php echo $active_tab == 'export' ? 'nav-tab-active' : ''; ?>"><?php _e('Export', 'invoicing'); ?></a>
90
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
91 91
             </h2>
92
-            <div class="wpi-reports-content wpi-reports-<?php echo esc_attr( $active_tab ); ?>">
92
+            <div class="wpi-reports-content wpi-reports-<?php echo esc_attr($active_tab); ?>">
93 93
             <?php
94
-                do_action( 'wpinv_reports_page_top' );
95
-                do_action( 'wpinv_reports_tab_' . $active_tab );
96
-                do_action( 'wpinv_reports_page_bottom' );
94
+                do_action('wpinv_reports_page_top');
95
+                do_action('wpinv_reports_tab_' . $active_tab);
96
+                do_action('wpinv_reports_page_bottom');
97 97
             ?>
98 98
             </div>
99 99
         </div>
@@ -106,139 +106,139 @@  discard block
 block discarded – undo
106 106
     public function reports() {
107 107
 
108 108
         $views = array(
109
-            'earnings'   => __( 'Earnings', 'invoicing' ),
110
-            'items'      => __( 'Items', 'invoicing' ),
111
-            'gateways'   => __( 'Payment Methods', 'invoicing' ),
112
-            'taxes'      => __( 'Taxes', 'invoicing' ),
109
+            'earnings'   => __('Earnings', 'invoicing'),
110
+            'items'      => __('Items', 'invoicing'),
111
+            'gateways'   => __('Payment Methods', 'invoicing'),
112
+            'taxes'      => __('Taxes', 'invoicing'),
113 113
         );
114 114
 
115
-        $views   = apply_filters( 'wpinv_report_views', $views );
115
+        $views   = apply_filters('wpinv_report_views', $views);
116 116
         $current = 'earnings';
117 117
 
118
-        if ( isset( $_GET['view'] ) && array_key_exists( $_GET['view'], $views ) )
118
+        if (isset($_GET['view']) && array_key_exists($_GET['view'], $views))
119 119
 		$current = $_GET['view'];
120 120
 
121 121
         ?>
122 122
 	        <form id="wpinv-reports-filter" method="get" class="tablenav">
123 123
 		        <select id="wpinv-reports-view" name="view">
124
-			        <option value="-1" disabled><?php _e( 'Report Type', 'invoicing' ); ?></option>
125
-			            <?php foreach ( $views as $view_id => $label ) : ?>
126
-				            <option value="<?php echo esc_attr( $view_id ); ?>" <?php selected( $view_id, $current ); ?>><?php echo $label; ?></option>
124
+			        <option value="-1" disabled><?php _e('Report Type', 'invoicing'); ?></option>
125
+			            <?php foreach ($views as $view_id => $label) : ?>
126
+				            <option value="<?php echo esc_attr($view_id); ?>" <?php selected($view_id, $current); ?>><?php echo $label; ?></option>
127 127
 			            <?php endforeach; ?>
128 128
 		        </select>
129 129
 
130
-		        <?php do_action( 'wpinv_report_view_actions' ); ?>
130
+		        <?php do_action('wpinv_report_view_actions'); ?>
131 131
 
132 132
 		        <input type="hidden" name="page" value="wpinv-reports"/>
133
-		        <?php submit_button( __( 'Show', 'invoicing' ), 'secondary', 'submit', false ); ?>
133
+		        <?php submit_button(__('Show', 'invoicing'), 'secondary', 'submit', false); ?>
134 134
 	        </form>
135 135
         <?php
136 136
 
137
-	    do_action( 'wpinv_reports_view_' . $current );
137
+	    do_action('wpinv_reports_view_' . $current);
138 138
 
139 139
     }
140 140
 
141 141
     public function export() {
142
-        $statuses = wpinv_get_invoice_statuses( true );
143
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
142
+        $statuses = wpinv_get_invoice_statuses(true);
143
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
144 144
         ?>
145 145
         <div class="metabox-holder">
146 146
             <div id="post-body">
147 147
                 <div id="post-body-content">
148
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
148
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
149 149
 
150 150
                     <div class="postbox wpi-export-invoices">
151
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
151
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
152 152
                         <div class="inside">
153
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
153
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
154 154
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
155
-                                <?php echo wpinv_html_date_field( array(
155
+                                <?php echo wpinv_html_date_field(array(
156 156
                                     'id' => 'wpi_export_from_date',
157 157
                                     'name' => 'from_date',
158 158
                                     'data' => array(
159 159
                                         'dateFormat' => 'yy-mm-dd'
160 160
                                     ),
161
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
161
+                                    'placeholder' => __('From date', 'invoicing') )
162 162
                                 ); ?>
163
-                                <?php echo wpinv_html_date_field( array(
163
+                                <?php echo wpinv_html_date_field(array(
164 164
                                     'id' => 'wpi_export_to_date',
165 165
                                     'name' => 'to_date',
166 166
                                     'data' => array(
167 167
                                         'dateFormat' => 'yy-mm-dd'
168 168
                                     ),
169
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
169
+                                    'placeholder' => __('To date', 'invoicing') )
170 170
                                 ); ?>
171 171
                                 <span id="wpinv-status-wrap">
172
-                                <?php echo wpinv_html_select( array(
172
+                                <?php echo wpinv_html_select(array(
173 173
                                     'options'          => $statuses,
174 174
                                     'name'             => 'status',
175 175
                                     'id'               => 'wpi_export_status',
176 176
                                     'show_option_all'  => false,
177 177
                                     'show_option_none' => false,
178 178
                                     'class'            => 'wpi_select2',
179
-                                ) ); ?>
180
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
179
+                                )); ?>
180
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
181 181
                                 </span>
182 182
                                 <span id="wpinv-submit-wrap">
183 183
                                     <input type="hidden" value="invoices" name="export" />
184
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
184
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
185 185
                                 </span>
186 186
                             </form>
187 187
                         </div>
188 188
                     </div>
189 189
 
190 190
                     <div class="postbox wpi-export-discount-uses">
191
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Discount Use','invoicing' ); ?></span></h2>
191
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Discount Use', 'invoicing'); ?></span></h2>
192 192
                         <div class="inside">
193
-                            <p><?php _e( 'Download a CSV of discount uses.', 'invoicing' ); ?></p>
194
-                            <a class="button-primary" href="<?php echo esc_url( wp_nonce_url( admin_url( 'admin-ajax.php?action=wpinv_ajax_discount_use_export' ), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export' ) ); ?>"><?php _e( 'Generate CSV', 'invoicing' ); ?></a>
193
+                            <p><?php _e('Download a CSV of discount uses.', 'invoicing'); ?></p>
194
+                            <a class="button-primary" href="<?php echo esc_url(wp_nonce_url(admin_url('admin-ajax.php?action=wpinv_ajax_discount_use_export'), 'wpi_discount_ajax_export', 'wpi_discount_ajax_export')); ?>"><?php _e('Generate CSV', 'invoicing'); ?></a>
195 195
                         </div>
196 196
                     </div>
197 197
 
198
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
198
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
199 199
                 </div>
200 200
             </div>
201 201
         </div>
202 202
         <?php
203 203
     }
204 204
 
205
-    public function export_location( $relative = false ) {
205
+    public function export_location($relative = false) {
206 206
         $upload_dir         = wp_upload_dir();
207
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
208
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
207
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
208
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
209 209
 
210
-        return trailingslashit( $export_location );
210
+        return trailingslashit($export_location);
211 211
     }
212 212
 
213 213
     public function check_export_location() {
214 214
         try {
215
-            if ( empty( $this->wp_filesystem ) ) {
216
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
215
+            if (empty($this->wp_filesystem)) {
216
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
217 217
             }
218 218
 
219
-            if ( is_wp_error( $this->wp_filesystem ) ) {
220
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
219
+            if (is_wp_error($this->wp_filesystem)) {
220
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
221 221
             }
222 222
 
223
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
224
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
223
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
224
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
225 225
 
226
-            if ( $is_dir && $is_writeable ) {
226
+            if ($is_dir && $is_writeable) {
227 227
                return true;
228
-            } else if ( $is_dir && !$is_writeable ) {
229
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
230
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
228
+            } else if ($is_dir && !$is_writeable) {
229
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
230
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
231 231
                }
232 232
 
233 233
                return true;
234 234
             } else {
235
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
236
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
235
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
236
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
237 237
                 }
238 238
 
239 239
                 return true;
240 240
             }
241
-        } catch ( Exception $e ) {
241
+        } catch (Exception $e) {
242 242
             return $e->getMessage();
243 243
         }
244 244
     }
@@ -246,59 +246,59 @@  discard block
 block discarded – undo
246 246
     public function ajax_export() {
247 247
         $response               = array();
248 248
         $response['success']    = false;
249
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
249
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
250 250
 
251
-        if ( empty( $_POST['data'] ) || ! wpinv_current_user_can_manage_invoicing() ) {
252
-            wp_send_json( $response );
251
+        if (empty($_POST['data']) || !wpinv_current_user_can_manage_invoicing()) {
252
+            wp_send_json($response);
253 253
         }
254 254
 
255
-        parse_str( $_POST['data'], $data );
255
+        parse_str($_POST['data'], $data);
256 256
 
257
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
257
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
258 258
 
259
-        $_REQUEST = (array)$data;
260
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
261
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
262
-            wp_send_json( $response );
259
+        $_REQUEST = (array) $data;
260
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
261
+            $response['msg'] = __('Security check failed.', 'invoicing');
262
+            wp_send_json($response);
263 263
         }
264 264
 
265
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
266
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
267
-            wp_send_json( $response );
265
+        if (($error = $this->check_export_location(true)) !== true) {
266
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
267
+            wp_send_json($response);
268 268
         }
269 269
 
270
-        $this->set_export_params( $_REQUEST );
270
+        $this->set_export_params($_REQUEST);
271 271
 
272 272
         $return = $this->process_export_step();
273 273
         $done   = $this->get_export_status();
274 274
 
275
-        if ( $return ) {
275
+        if ($return) {
276 276
             $this->step += 1;
277 277
 
278 278
             $response['success']    = true;
279 279
             $response['msg']        = '';
280 280
 
281
-            if ( $done >= 100 ) {
281
+            if ($done >= 100) {
282 282
                 $this->step     = 'done';
283
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
283
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
284 284
                 $new_file       = $this->export_dir . $new_filename;
285 285
 
286
-                if ( file_exists( $this->file ) ) {
287
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
286
+                if (file_exists($this->file)) {
287
+                    $this->wp_filesystem->move($this->file, $new_file, true);
288 288
                 }
289 289
 
290
-                if ( file_exists( $new_file ) ) {
291
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
290
+                if (file_exists($new_file)) {
291
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
292 292
                 }
293 293
             }
294 294
 
295 295
             $response['data']['step']   = $this->step;
296 296
             $response['data']['done']   = $done;
297 297
         } else {
298
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
298
+            $response['msg'] = __('No data found for export.', 'invoicing');
299 299
         }
300 300
 
301
-        wp_send_json( $response );
301
+        wp_send_json($response);
302 302
     }
303 303
 
304 304
     /**
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
      */
307 307
     public function discount_use_export() {
308 308
 
309
-        if ( ! wp_verify_nonce( $_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export' ) || ! wpinv_current_user_can_manage_invoicing() ) {
309
+        if (!wp_verify_nonce($_GET['wpi_discount_ajax_export'], 'wpi_discount_ajax_export') || !wpinv_current_user_can_manage_invoicing()) {
310 310
             wp_die( -1, 403 );
311 311
         }
312 312
 
@@ -316,115 +316,115 @@  discard block
 block discarded – undo
316 316
             'posts_per_page' => -1,
317 317
         );
318 318
 
319
-        $discounts = get_posts( $args );
319
+        $discounts = get_posts($args);
320 320
 
321
-        if ( empty( $discounts ) ) {
322
-            die ( __( 'You have not set up any discounts', 'invoicing' ) );
321
+        if (empty($discounts)) {
322
+            die (__('You have not set up any discounts', 'invoicing'));
323 323
         }
324 324
 
325
-        $output  = fopen( 'php://output', 'w' ) or die( 'Unsupported server' );
325
+        $output = fopen('php://output', 'w') or die('Unsupported server');
326 326
 
327 327
         // Let the browser know what content we're streaming and how it should save the content.
328 328
 		$name = time();
329
-		header( "Content-Type:application/csv" );
330
-        header( "Content-Disposition:attachment;filename=getpaid-discounts-$name.csv" );
329
+		header("Content-Type:application/csv");
330
+        header("Content-Disposition:attachment;filename=getpaid-discounts-$name.csv");
331 331
 
332 332
         // Output the csv column headers.
333 333
 		fputcsv(
334 334
             $output,
335 335
             array(
336
-                __( 'Discount Id', 'invoicing' ),
337
-                __( 'Discount Code', 'invoicing' ),
338
-                __( 'Discount Type', 'invoicing' ),
339
-                __( 'Discount Amount', 'invoicing' ),
340
-                __( 'Uses', 'invoicing' ),
336
+                __('Discount Id', 'invoicing'),
337
+                __('Discount Code', 'invoicing'),
338
+                __('Discount Type', 'invoicing'),
339
+                __('Discount Amount', 'invoicing'),
340
+                __('Uses', 'invoicing'),
341 341
             )
342 342
         );
343 343
 
344
-        foreach ( $discounts as $discount ) {
344
+        foreach ($discounts as $discount) {
345 345
 
346 346
             $discount = (int) $discount;
347 347
             $row      = array(
348 348
                 $discount,
349
-                get_post_meta( $discount, '_wpi_discount_code', true ),
350
-                get_post_meta( $discount, '_wpi_discount_type', true ),
351
-                get_post_meta( $discount, '_wpi_discount_amount', true ),
352
-                (int) get_post_meta( $discount, '_wpi_discount_uses', true )
349
+                get_post_meta($discount, '_wpi_discount_code', true),
350
+                get_post_meta($discount, '_wpi_discount_type', true),
351
+                get_post_meta($discount, '_wpi_discount_amount', true),
352
+                (int) get_post_meta($discount, '_wpi_discount_uses', true)
353 353
             );
354
-            fputcsv( $output, $row );
354
+            fputcsv($output, $row);
355 355
         }
356 356
 
357
-        fclose( $output );
357
+        fclose($output);
358 358
         exit;
359 359
 
360 360
     }
361 361
 
362
-    public function set_export_params( $request ) {
362
+    public function set_export_params($request) {
363 363
         $this->empty    = false;
364
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
365
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
364
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
365
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
366 366
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
367 367
         $this->file     = $this->export_dir . $this->filename;
368 368
 
369
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
369
+        do_action('wpinv_export_set_params_' . $this->export, $request);
370 370
     }
371 371
 
372 372
     public function get_columns() {
373 373
         $columns = array();
374 374
 
375
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
375
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
376 376
     }
377 377
 
378 378
     protected function get_export_file() {
379 379
         $file = '';
380 380
 
381
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
382
-            $file = $this->wp_filesystem->get_contents( $this->file );
381
+        if ($this->wp_filesystem->exists($this->file)) {
382
+            $file = $this->wp_filesystem->get_contents($this->file);
383 383
         } else {
384
-            $this->wp_filesystem->put_contents( $this->file, '' );
384
+            $this->wp_filesystem->put_contents($this->file, '');
385 385
         }
386 386
 
387 387
         return $file;
388 388
     }
389 389
 
390
-    protected function attach_export_data( $data = '' ) {
391
-        $filedata   = $this->get_export_file();
392
-        $filedata   .= $data;
390
+    protected function attach_export_data($data = '') {
391
+        $filedata = $this->get_export_file();
392
+        $filedata .= $data;
393 393
 
394
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
394
+        $this->wp_filesystem->put_contents($this->file, $filedata);
395 395
 
396
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
396
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
397 397
         $columns    = $this->get_columns();
398
-        $columns    = empty( $columns ) ? 0 : 1;
398
+        $columns    = empty($columns) ? 0 : 1;
399 399
 
400
-        $this->empty = count( $rows ) == $columns ? true : false;
400
+        $this->empty = count($rows) == $columns ? true : false;
401 401
     }
402 402
 
403 403
     public function print_columns() {
404 404
         $column_data    = '';
405 405
         $columns        = $this->get_columns();
406 406
         $i              = 1;
407
-        foreach( $columns as $key => $column ) {
408
-            $column_data .= '"' . addslashes( $column ) . '"';
409
-            $column_data .= $i == count( $columns ) ? '' : ',';
407
+        foreach ($columns as $key => $column) {
408
+            $column_data .= '"' . addslashes($column) . '"';
409
+            $column_data .= $i == count($columns) ? '' : ',';
410 410
             $i++;
411 411
         }
412 412
         $column_data .= "\r\n";
413 413
 
414
-        $this->attach_export_data( $column_data );
414
+        $this->attach_export_data($column_data);
415 415
 
416 416
         return $column_data;
417 417
     }
418 418
 
419 419
     public function process_export_step() {
420
-        if ( $this->step < 2 ) {
421
-            /** @scrutinizer ignore-unhandled */ @unlink( $this->file );
420
+        if ($this->step < 2) {
421
+            /** @scrutinizer ignore-unhandled */ @unlink($this->file);
422 422
             $this->print_columns();
423 423
         }
424 424
 
425 425
         $return = $this->print_rows();
426 426
 
427
-        if ( $return ) {
427
+        if ($return) {
428 428
             return true;
429 429
         } else {
430 430
             return false;
@@ -433,14 +433,14 @@  discard block
 block discarded – undo
433 433
 
434 434
     public function get_export_status() {
435 435
         $status = 100;
436
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
436
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
437 437
     }
438 438
 
439 439
     public function get_export_data() {
440 440
         $data = array();
441 441
 
442
-        $data = apply_filters( 'wpinv_export_get_data', $data );
443
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
442
+        $data = apply_filters('wpinv_export_get_data', $data);
443
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
444 444
 
445 445
         return $data;
446 446
     }
@@ -450,20 +450,20 @@  discard block
 block discarded – undo
450 450
         $data       = $this->get_export_data();
451 451
         $columns    = $this->get_columns();
452 452
 
453
-        if ( $data ) {
454
-            foreach ( $data as $row ) {
453
+        if ($data) {
454
+            foreach ($data as $row) {
455 455
                 $i = 1;
456
-                foreach ( $row as $key => $column ) {
457
-                    if ( array_key_exists( $key, $columns ) ) {
458
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
459
-                        $row_data .= $i == count( $columns ) ? '' : ',';
456
+                foreach ($row as $key => $column) {
457
+                    if (array_key_exists($key, $columns)) {
458
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
459
+                        $row_data .= $i == count($columns) ? '' : ',';
460 460
                         $i++;
461 461
                     }
462 462
                 }
463 463
                 $row_data .= "\r\n";
464 464
             }
465 465
 
466
-            $this->attach_export_data( $row_data );
466
+            $this->attach_export_data($row_data);
467 467
 
468 468
             return $row_data;
469 469
         }
@@ -472,48 +472,48 @@  discard block
 block discarded – undo
472 472
     }
473 473
 
474 474
     // Export Invoices.
475
-    public function set_invoices_export( $request ) {
476
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
477
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
478
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish';
475
+    public function set_invoices_export($request) {
476
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
477
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
478
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish';
479 479
     }
480 480
 
481
-    public function get_invoices_columns( $columns = array() ) {
481
+    public function get_invoices_columns($columns = array()) {
482 482
         $columns = array(
483
-            'id'            => __( 'ID',   'invoicing' ),
484
-            'number'        => __( 'Number',   'invoicing' ),
485
-            'date'          => __( 'Date', 'invoicing' ),
486
-            'due_date'      => __( 'Due Date', 'invoicing' ),
487
-            'completed_date'=> __( 'Payment Done Date', 'invoicing' ),
488
-            'amount'        => __( 'Amount', 'invoicing' ),
489
-            'currency'      => __( 'Currency', 'invoicing' ),
490
-            'items'        => __( 'Items', 'invoicing' ),
491
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
492
-            'status'        => __( 'Status', 'invoicing' ),
493
-            'tax'           => __( 'Tax', 'invoicing' ),
494
-            'discount'      => __( 'Discount', 'invoicing' ),
495
-            'user_id'       => __( 'User ID', 'invoicing' ),
496
-            'email'         => __( 'Email', 'invoicing' ),
497
-            'first_name'    => __( 'First Name', 'invoicing' ),
498
-            'last_name'     => __( 'Last Name', 'invoicing' ),
499
-            'address'       => __( 'Address', 'invoicing' ),
500
-            'city'          => __( 'City', 'invoicing' ),
501
-            'state'         => __( 'State', 'invoicing' ),
502
-            'country'       => __( 'Country', 'invoicing' ),
503
-            'zip'           => __( 'Zipcode', 'invoicing' ),
504
-            'phone'         => __( 'Phone', 'invoicing' ),
505
-            'company'       => __( 'Company', 'invoicing' ),
506
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
507
-            'ip'            => __( 'IP', 'invoicing' ),
508
-            'gateway'       => __( 'Gateway', 'invoicing' ),
509
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
510
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
483
+            'id'            => __('ID', 'invoicing'),
484
+            'number'        => __('Number', 'invoicing'),
485
+            'date'          => __('Date', 'invoicing'),
486
+            'due_date'      => __('Due Date', 'invoicing'),
487
+            'completed_date'=> __('Payment Done Date', 'invoicing'),
488
+            'amount'        => __('Amount', 'invoicing'),
489
+            'currency'      => __('Currency', 'invoicing'),
490
+            'items'        => __('Items', 'invoicing'),
491
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
492
+            'status'        => __('Status', 'invoicing'),
493
+            'tax'           => __('Tax', 'invoicing'),
494
+            'discount'      => __('Discount', 'invoicing'),
495
+            'user_id'       => __('User ID', 'invoicing'),
496
+            'email'         => __('Email', 'invoicing'),
497
+            'first_name'    => __('First Name', 'invoicing'),
498
+            'last_name'     => __('Last Name', 'invoicing'),
499
+            'address'       => __('Address', 'invoicing'),
500
+            'city'          => __('City', 'invoicing'),
501
+            'state'         => __('State', 'invoicing'),
502
+            'country'       => __('Country', 'invoicing'),
503
+            'zip'           => __('Zipcode', 'invoicing'),
504
+            'phone'         => __('Phone', 'invoicing'),
505
+            'company'       => __('Company', 'invoicing'),
506
+            'vat_number'    => __('Vat Number', 'invoicing'),
507
+            'ip'            => __('IP', 'invoicing'),
508
+            'gateway'       => __('Gateway', 'invoicing'),
509
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
510
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
511 511
         );
512 512
 
513 513
         return $columns;
514 514
     }
515 515
 
516
-    public function get_invoices_data( $response = array() ) {
516
+    public function get_invoices_data($response = array()) {
517 517
         $args = array(
518 518
             'limit'    => $this->per_page,
519 519
             'page'     => $this->step,
@@ -521,42 +521,42 @@  discard block
 block discarded – undo
521 521
             'orderby'  => 'date',
522 522
         );
523 523
 
524
-        if ( $this->status != 'any' ) {
524
+        if ($this->status != 'any') {
525 525
             $args['status'] = $this->status;
526 526
         } else {
527
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
527
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
528 528
         }
529 529
 
530
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
530
+        if (!empty($this->from_date) || !empty($this->to_date)) {
531 531
             $args['date_query'] = array(
532 532
                 array(
533
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
534
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
533
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
534
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
535 535
                     'inclusive' => true
536 536
                 )
537 537
             );
538 538
         }
539 539
 
540
-        $invoices = wpinv_get_invoices( $args );
540
+        $invoices = wpinv_get_invoices($args);
541 541
 
542 542
         $data = array();
543 543
 
544
-        if ( !empty( $invoices ) ) {
545
-            foreach ( $invoices as $invoice ) {
544
+        if (!empty($invoices)) {
545
+            foreach ($invoices as $invoice) {
546 546
                 $items = $this->get_invoice_items($invoice);
547 547
                 $row = array(
548 548
                     'id'            => $invoice->ID,
549 549
                     'number'        => $invoice->get_number(),
550
-                    'date'          => $invoice->get_invoice_date( false ),
551
-                    'due_date'      => $invoice->get_due_date( false ),
550
+                    'date'          => $invoice->get_invoice_date(false),
551
+                    'due_date'      => $invoice->get_due_date(false),
552 552
                     'completed_date'=> $invoice->get_completed_date(),
553
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
553
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
554 554
                     'currency'      => $invoice->get_currency(),
555 555
                     'items'         => $items,
556
-                    'status_nicename' => $invoice->get_status( true ),
556
+                    'status_nicename' => $invoice->get_status(true),
557 557
                     'status'        => $invoice->get_status(),
558
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
559
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
558
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
559
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
560 560
                     'user_id'       => $invoice->get_user_id(),
561 561
                     'email'         => $invoice->get_email(),
562 562
                     'first_name'    => $invoice->get_first_name(),
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
                     'transaction_id'=> $invoice->gateway ? $invoice->get_transaction_id() : '',
576 576
                 );
577 577
 
578
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
578
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
579 579
             }
580 580
 
581 581
             return $data;
@@ -591,44 +591,44 @@  discard block
 block discarded – undo
591 591
             'return'   => 'ids',
592 592
         );
593 593
 
594
-        if ( $this->status != 'any' ) {
594
+        if ($this->status != 'any') {
595 595
             $args['status'] = $this->status;
596 596
         } else {
597
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
597
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
598 598
         }
599 599
 
600
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
600
+        if (!empty($this->from_date) || !empty($this->to_date)) {
601 601
             $args['date_query'] = array(
602 602
                 array(
603
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
604
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
603
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
604
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
605 605
                     'inclusive' => true
606 606
                 )
607 607
             );
608 608
         }
609 609
 
610
-        $invoices   = wpinv_get_invoices( $args );
611
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
610
+        $invoices   = wpinv_get_invoices($args);
611
+        $total      = !empty($invoices) ? count($invoices) : 0;
612 612
         $status     = 100;
613 613
 
614
-        if ( $total > 0 ) {
615
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
614
+        if ($total > 0) {
615
+            $status = (($this->per_page * $this->step) / $total) * 100;
616 616
         }
617 617
 
618
-        if ( $status > 100 ) {
618
+        if ($status > 100) {
619 619
             $status = 100;
620 620
         }
621 621
 
622 622
         return $status;
623 623
     }
624 624
 
625
-    public function get_invoice_items($invoice){
626
-        if(!$invoice){
625
+    public function get_invoice_items($invoice) {
626
+        if (!$invoice) {
627 627
             return '';
628 628
         }
629 629
 
630 630
         $cart_details = $invoice->get_cart_details();
631
-        if(!empty($cart_details)){
631
+        if (!empty($cart_details)) {
632 632
             $cart_details = maybe_serialize($cart_details);
633 633
         } else {
634 634
             $cart_details = '';
@@ -640,14 +640,14 @@  discard block
 block discarded – undo
640 640
     /**
641 641
      * Returns the periods filter.
642 642
      */
643
-    public function period_filter( $args = array() ) {
643
+    public function period_filter($args = array()) {
644 644
 
645 645
         ob_start();
646 646
 
647 647
         echo '<form id="wpinv-graphs-filter" method="get" style="margin-bottom: 10px;" class="tablenav">';
648 648
         echo '<input type="hidden" name="page" value="wpinv-reports">';
649 649
 
650
-        foreach ( $args as $key => $val ) {
650
+        foreach ($args as $key => $val) {
651 651
             $key = esc_attr($key);
652 652
             $val = esc_attr($val);
653 653
             echo "<input type='hidden' name='$key' value='$val'>";
@@ -656,21 +656,21 @@  discard block
 block discarded – undo
656 656
         echo '<select id="wpinv-graphs-date-options" name="range" style="min-width: 200px;" onChange="this.form.submit()">';
657 657
 
658 658
         $ranges = array(
659
-            'today'        => __( 'Today', 'invoicing' ),
660
-            'yesterday'    => __( 'Yesterday', 'invoicing' ),
661
-            'this_week'    => __( 'This Week', 'invoicing' ),
662
-            'last_week'    => __( 'Last Week', 'invoicing' ),
663
-            '7_days_ago'   => __( 'Last 7 Days', 'invoicing' ),
664
-            '30_days_ago'  => __( 'Last 30 Days', 'invoicing' ),
665
-            'this_month'   => __( 'This Month', 'invoicing' ),
666
-            'this_year'    => __( 'This Year', 'invoicing' ),
667
-            'last_year'    => __( 'Last Year', 'invoicing' ),
659
+            'today'        => __('Today', 'invoicing'),
660
+            'yesterday'    => __('Yesterday', 'invoicing'),
661
+            'this_week'    => __('This Week', 'invoicing'),
662
+            'last_week'    => __('Last Week', 'invoicing'),
663
+            '7_days_ago'   => __('Last 7 Days', 'invoicing'),
664
+            '30_days_ago'  => __('Last 30 Days', 'invoicing'),
665
+            'this_month'   => __('This Month', 'invoicing'),
666
+            'this_year'    => __('This Year', 'invoicing'),
667
+            'last_year'    => __('Last Year', 'invoicing'),
668 668
         );
669 669
 
670
-        $range = isset( $_GET['range'] ) && isset( $ranges[ $_GET['range'] ] ) ? $_GET['range'] : '7_days_ago';
670
+        $range = isset($_GET['range']) && isset($ranges[$_GET['range']]) ? $_GET['range'] : '7_days_ago';
671 671
 
672
-        foreach ( $ranges as $val => $label ) {
673
-            $selected = selected( $range, $val, false );
672
+        foreach ($ranges as $val => $label) {
673
+            $selected = selected($range, $val, false);
674 674
             echo "<option value='$val' $selected>$label</option>";
675 675
         }
676 676
 
@@ -682,28 +682,28 @@  discard block
 block discarded – undo
682 682
     /**
683 683
      * Returns the the current date range.
684 684
      */
685
-    public function get_sql_clauses( $range ) {
685
+    public function get_sql_clauses($range) {
686 686
 
687 687
         $date     = 'CAST(meta.completed_date AS DATE)';
688 688
         $datetime = 'meta.completed_date';
689 689
 
690 690
         // Prepare durations.
691
-        $today                = current_time( 'Y-m-d' );
692
-        $yesterday            = date( 'Y-m-d', strtotime( '-1 day', current_time( 'timestamp' ) ) );
693
-        $sunday               = date( 'Y-m-d', strtotime( 'sunday this week', current_time( 'timestamp' ) ) );
694
-        $monday               = date( 'Y-m-d', strtotime( 'monday this week', current_time( 'timestamp' ) ) );
695
-        $last_sunday          = date( 'Y-m-d', strtotime( 'sunday last week', current_time( 'timestamp' ) ) );
696
-        $last_monday          = date( 'Y-m-d', strtotime( 'monday last week', current_time( 'timestamp' ) ) );
697
-        $seven_days_ago       = date( 'Y-m-d', strtotime( '-7 days', current_time( 'timestamp' ) ) );
698
-        $thirty_days_ago      = date( 'Y-m-d', strtotime( '-30 days', current_time( 'timestamp' ) ) );
699
-        $first_day_month  	  = date( 'Y-m-1', current_time( 'timestamp' ) );
700
-        $last_day_month  	  = date( 'Y-m-t', current_time( 'timestamp' ) );
701
-		$first_day_last_month = date( 'Y-m-d', strtotime( 'first day of last month', current_time( 'timestamp' ) ) );
702
-        $last_day_last_month  = date( 'Y-m-d', strtotime( 'last day of last month', current_time( 'timestamp' ) ) );
703
-        $first_day_year  	  = date( 'Y-1-1', current_time( 'timestamp' ) );
704
-        $last_day_year  	  = date( 'Y-12-31', current_time( 'timestamp' ) );
705
-		$first_day_last_year  = date( 'Y-m-d', strtotime( 'first day of last year', current_time( 'timestamp' ) ) );
706
-		$last_day_last_year   = date( 'Y-m-d', strtotime( 'last day of last year', current_time( 'timestamp' ) ) );
691
+        $today                = current_time('Y-m-d');
692
+        $yesterday            = date('Y-m-d', strtotime('-1 day', current_time('timestamp')));
693
+        $sunday               = date('Y-m-d', strtotime('sunday this week', current_time('timestamp')));
694
+        $monday               = date('Y-m-d', strtotime('monday this week', current_time('timestamp')));
695
+        $last_sunday          = date('Y-m-d', strtotime('sunday last week', current_time('timestamp')));
696
+        $last_monday          = date('Y-m-d', strtotime('monday last week', current_time('timestamp')));
697
+        $seven_days_ago       = date('Y-m-d', strtotime('-7 days', current_time('timestamp')));
698
+        $thirty_days_ago      = date('Y-m-d', strtotime('-30 days', current_time('timestamp')));
699
+        $first_day_month = date('Y-m-1', current_time('timestamp'));
700
+        $last_day_month  	  = date('Y-m-t', current_time('timestamp'));
701
+		$first_day_last_month = date('Y-m-d', strtotime('first day of last month', current_time('timestamp')));
702
+        $last_day_last_month = date('Y-m-d', strtotime('last day of last month', current_time('timestamp')));
703
+        $first_day_year  	  = date('Y-1-1', current_time('timestamp'));
704
+        $last_day_year = date('Y-12-31', current_time('timestamp'));
705
+		$first_day_last_year  = date('Y-m-d', strtotime('first day of last year', current_time('timestamp')));
706
+		$last_day_last_year   = date('Y-m-d', strtotime('last day of last year', current_time('timestamp')));
707 707
 
708 708
         $ranges = array(
709 709
 
@@ -759,21 +759,21 @@  discard block
 block discarded – undo
759 759
 
760 760
         );
761 761
 
762
-        if ( ! isset( $ranges[ $range ] ) ) {
762
+        if (!isset($ranges[$range])) {
763 763
             return $ranges['7_days_ago'];
764 764
         }
765
-        return $ranges[ $range ];
765
+        return $ranges[$range];
766 766
 
767 767
     }
768 768
 
769 769
     /**
770 770
      * Returns the the current date ranges results.
771 771
      */
772
-    public function get_report_results( $range ) {
772
+    public function get_report_results($range) {
773 773
         global $wpdb;
774 774
 
775 775
         $table   = $wpdb->prefix . 'getpaid_invoices';
776
-        $clauses = $this->get_sql_clauses( $range );
776
+        $clauses = $this->get_sql_clauses($range);
777 777
         $sql     = "SELECT
778 778
                 {$clauses[0]} AS completed_date,
779 779
                 SUM( meta.total ) AS total,
@@ -789,30 +789,30 @@  discard block
 block discarded – undo
789 789
             GROUP BY {$clauses[0]}
790 790
         ";
791 791
 
792
-        return $wpdb->get_results( $sql );
792
+        return $wpdb->get_results($sql);
793 793
     }
794 794
 
795 795
     /**
796 796
      * Fill nulls.
797 797
      */
798
-    public function fill_nulls( $data, $range ) {
798
+    public function fill_nulls($data, $range) {
799 799
 
800 800
         $return = array();
801 801
         $time   = current_time('timestamp');
802 802
 
803
-        switch ( $range ) {
803
+        switch ($range) {
804 804
             case 'today' :
805 805
             case 'yesterday' :
806
-                $hour  = 0;
806
+                $hour = 0;
807 807
 
808
-                while ( $hour < 23 ) {
808
+                while ($hour < 23) {
809 809
                     $amount = 0;
810
-                    if ( isset( $data[$hour] ) ) {
811
-                        $amount = floatval( $data[$hour] );
810
+                    if (isset($data[$hour])) {
811
+                        $amount = floatval($data[$hour]);
812 812
                     }
813 813
 
814
-                    $time = strtotime( "$range $hour:00:00" ) * 1000;
815
-                    $return[] = array( $time, $amount );
814
+                    $time = strtotime("$range $hour:00:00") * 1000;
815
+                    $return[] = array($time, $amount);
816 816
                     $hour++;
817 817
                 }
818 818
 
@@ -820,24 +820,24 @@  discard block
 block discarded – undo
820 820
 
821 821
             case 'this_month' :
822 822
             case 'last_month' :
823
-                $_range = str_replace( '_', ' ', $range );
824
-                $month  = date( 'n', strtotime( $_range, $time ) );
825
-                $year   = date( 'Y', strtotime( $_range, $time ) );
823
+                $_range = str_replace('_', ' ', $range);
824
+                $month  = date('n', strtotime($_range, $time));
825
+                $year   = date('Y', strtotime($_range, $time));
826 826
                 $days   = cal_days_in_month(
827
-                    defined( 'CAL_GREGORIAN' ) ? CAL_GREGORIAN : 1,
827
+                    defined('CAL_GREGORIAN') ? CAL_GREGORIAN : 1,
828 828
                     $month,
829 829
                     $year
830 830
                 );
831 831
 
832 832
                 $day = 1;
833
-                while ( $days != $day ) {
833
+                while ($days != $day) {
834 834
                     $amount = 0;
835
-                    if ( isset( $data[$day] ) ) {
836
-                        $amount = floatval( $data[$day] );
835
+                    if (isset($data[$day])) {
836
+                        $amount = floatval($data[$day]);
837 837
                     }
838 838
 
839
-                    $time = strtotime( "$year-$month-$day" ) * 1000;
840
-                    $return[] = array( $time, $amount );
839
+                    $time = strtotime("$year-$month-$day") * 1000;
840
+                    $return[] = array($time, $amount);
841 841
                     $day++;
842 842
                 }
843 843
 
@@ -845,52 +845,52 @@  discard block
 block discarded – undo
845 845
 
846 846
             case 'this_week' :
847 847
             case 'last_week' :
848
-                $_range = str_replace( '_', ' ', $range );
849
-                $days   = array( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' );
848
+                $_range = str_replace('_', ' ', $range);
849
+                $days   = array('monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday');
850 850
 
851
-                foreach ( $days as $day ) {
851
+                foreach ($days as $day) {
852 852
 
853 853
                     $amount = 0;
854
-                    if ( isset( $data[ ucfirst( $day ) ] ) ) {
855
-                        $amount = floatval( $data[ ucfirst( $day ) ] );
854
+                    if (isset($data[ucfirst($day)])) {
855
+                        $amount = floatval($data[ucfirst($day)]);
856 856
                     }
857 857
 
858
-                    $time = strtotime( "$_range $day" ) * 1000;
859
-                    $return[] = array( $time, $amount );
858
+                    $time = strtotime("$_range $day") * 1000;
859
+                    $return[] = array($time, $amount);
860 860
                 }
861 861
 
862 862
                 break;
863 863
 
864 864
             case 'this_year' :
865 865
             case 'last_year' :
866
-                $_range = str_replace( '_', ' ', $range );
867
-                $year   = date( 'Y', strtotime( $_range, $time ) );
868
-                $months = array( '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12' );
866
+                $_range = str_replace('_', ' ', $range);
867
+                $year   = date('Y', strtotime($_range, $time));
868
+                $months = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12');
869 869
 
870
-                foreach ( $months as $month ) {
870
+                foreach ($months as $month) {
871 871
 
872 872
                     $amount = 0;
873
-                    if ( isset( $data[$month] ) ) {
874
-                        $amount = floatval( $data[$month] );
873
+                    if (isset($data[$month])) {
874
+                        $amount = floatval($data[$month]);
875 875
                     }
876 876
 
877
-                    $_time     = strtotime("$year-$month-01") * 1000;
878
-                    $return[] = array( $_time, $amount );
877
+                    $_time = strtotime("$year-$month-01") * 1000;
878
+                    $return[] = array($_time, $amount);
879 879
                 }
880 880
 
881 881
                 break;
882 882
             case '30_days_ago' :
883 883
                 $days = 30;
884 884
 
885
-                while ( $days > 1 ) {
885
+                while ($days > 1) {
886 886
                     $amount = 0;
887
-                    $date   = date( 'j', strtotime( "-$days days", $time ) );
888
-                    if ( isset( $data[$date] ) ) {
889
-                        $amount = floatval( $data[$date] );
887
+                    $date   = date('j', strtotime("-$days days", $time));
888
+                    if (isset($data[$date])) {
889
+                        $amount = floatval($data[$date]);
890 890
                     }
891 891
 
892
-                    $_time = strtotime( "-$days days", $time ) * 1000;
893
-                    $return[] = array( $_time, $amount );
892
+                    $_time = strtotime("-$days days", $time) * 1000;
893
+                    $return[] = array($_time, $amount);
894 894
                     $days--;
895 895
                 }
896 896
 
@@ -899,15 +899,15 @@  discard block
 block discarded – undo
899 899
             default:
900 900
                 $days = 7;
901 901
 
902
-                while ( $days > 1 ) {
902
+                while ($days > 1) {
903 903
                     $amount = 0;
904
-                    $date   = date( 'j', strtotime( "-$days days", $time ) );
905
-                    if ( isset( $data[$date] ) ) {
906
-                        $amount = floatval( $data[$date] );
904
+                    $date   = date('j', strtotime("-$days days", $time));
905
+                    if (isset($data[$date])) {
906
+                        $amount = floatval($data[$date]);
907 907
                     }
908 908
 
909
-                    $_time = strtotime( "-$days days", $time ) * 1000;
910
-                    $return[] = array( $_time, $amount );
909
+                    $_time = strtotime("-$days days", $time) * 1000;
910
+                    $return[] = array($_time, $amount);
911 911
                     $days--;
912 912
                 }
913 913
 
@@ -922,33 +922,33 @@  discard block
 block discarded – undo
922 922
      * Retrieves the stats.
923 923
      */
924 924
     public function get_stats() {
925
-        $range     = isset( $_GET['range'] ) ? $_GET['range'] : '7_days_ago';
926
-        $results   = $this->get_report_results( $range );
927
-        $earnings  = wp_list_pluck( $results, 'total', 'completed_date' );
928
-        $taxes     = wp_list_pluck( $results, 'tax', 'completed_date' );
929
-        $discounts = wp_list_pluck( $results, 'discount', 'completed_date' );
930
-        $fees      = wp_list_pluck( $results, 'fees_total', 'completed_date' );
925
+        $range     = isset($_GET['range']) ? $_GET['range'] : '7_days_ago';
926
+        $results   = $this->get_report_results($range);
927
+        $earnings  = wp_list_pluck($results, 'total', 'completed_date');
928
+        $taxes     = wp_list_pluck($results, 'tax', 'completed_date');
929
+        $discounts = wp_list_pluck($results, 'discount', 'completed_date');
930
+        $fees      = wp_list_pluck($results, 'fees_total', 'completed_date');
931 931
 
932 932
         return array(
933 933
 
934 934
             array(
935
-                'label' => __( 'Earnings', 'invoicing' ),
936
-                'data'  => $this->fill_nulls( $earnings, $range ),
935
+                'label' => __('Earnings', 'invoicing'),
936
+                'data'  => $this->fill_nulls($earnings, $range),
937 937
             ),
938 938
 
939 939
             array(
940
-                'label' => __( 'Taxes', 'invoicing' ),
941
-                'data'  => $this->fill_nulls( $taxes, $range ),
940
+                'label' => __('Taxes', 'invoicing'),
941
+                'data'  => $this->fill_nulls($taxes, $range),
942 942
             ),
943 943
 
944 944
             array(
945
-                'label' => __( 'Discounts', 'invoicing' ),
946
-                'data'  => $this->fill_nulls( $discounts, $range ),
945
+                'label' => __('Discounts', 'invoicing'),
946
+                'data'  => $this->fill_nulls($discounts, $range),
947 947
             ),
948 948
 
949 949
             array(
950
-                'label' => __( 'Fees', 'invoicing' ),
951
-                'data'  => $this->fill_nulls( $fees, $range ),
950
+                'label' => __('Fees', 'invoicing'),
951
+                'data'  => $this->fill_nulls($fees, $range),
952 952
             )
953 953
         );
954 954
 
@@ -958,34 +958,34 @@  discard block
 block discarded – undo
958 958
      * Retrieves the time format for stats.
959 959
      */
960 960
     public function get_time_format() {
961
-        $range    = isset( $_GET['range'] ) ? $_GET['range'] : '7_days_ago';
961
+        $range = isset($_GET['range']) ? $_GET['range'] : '7_days_ago';
962 962
 
963
-        switch ( $range ) {
963
+        switch ($range) {
964 964
             case 'today' :
965 965
             case 'yesterday' :
966
-                return array( 'hour', '%h %p' );
966
+                return array('hour', '%h %p');
967 967
                 break;
968 968
 
969 969
             case 'this_month' :
970 970
             case 'last_month' :
971
-                return array( 'day', '%b %d' );
971
+                return array('day', '%b %d');
972 972
                 break;
973 973
 
974 974
             case 'this_week' :
975 975
             case 'last_week' :
976
-                return array( 'day', '%b %d' );
976
+                return array('day', '%b %d');
977 977
                 break;
978 978
 
979 979
             case 'this_year' :
980 980
             case 'last_year' :
981
-                return array( 'month', '%b' );
981
+                return array('month', '%b');
982 982
                 break;
983 983
             case '30_days_ago' :
984
-                return array( 'day', '%b %d' );
984
+                return array('day', '%b %d');
985 985
                 break;
986 986
 
987 987
             default:
988
-                return array( 'day', '%b %d' );
988
+                return array('day', '%b %d');
989 989
                 break;
990 990
 
991 991
         }
@@ -996,11 +996,11 @@  discard block
 block discarded – undo
996 996
      */
997 997
     public function earnings_report() {
998 998
 
999
-        $data        = wp_json_encode( $this->get_stats() );
999
+        $data        = wp_json_encode($this->get_stats());
1000 1000
         $time_format = $this->get_time_format();
1001 1001
         echo '
1002 1002
             <div class="wpinv-report-container">
1003
-                <h3><span>' . __( 'Earnings Over Time', 'invoicing' ) .'</span></h3>
1003
+                <h3><span>' . __('Earnings Over Time', 'invoicing') . '</span></h3>
1004 1004
                 ' . $this->period_filter() . '
1005 1005
                 <div id="wpinv_report_graph" style="height: 450px;"></div>
1006 1006
             </div>
@@ -1009,12 +1009,12 @@  discard block
 block discarded – undo
1009 1009
                 jQuery(document).ready( function() {
1010 1010
                     jQuery.plot(
1011 1011
                         jQuery("#wpinv_report_graph"),
1012
-                        ' . $data .',
1012
+                        ' . $data . ',
1013 1013
                         {
1014 1014
                             xaxis:{
1015 1015
                                 mode: "time",
1016
-                                timeformat: "' . $time_format[1] .'",
1017
-                                minTickSize: [0.5, "' . $time_format[0] .'"]
1016
+                                timeformat: "' . $time_format[1] . '",
1017
+                                minTickSize: [0.5, "' . $time_format[0] . '"]
1018 1018
                             },
1019 1019
 
1020 1020
                             yaxis: {
@@ -1042,7 +1042,7 @@  discard block
 block discarded – undo
1042 1042
      * Displays the gateways report.
1043 1043
      */
1044 1044
     public function gateways_report() {
1045
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-gateways-report-table.php' );
1045
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-gateways-report-table.php');
1046 1046
 
1047 1047
         $table = new WPInv_Gateways_Report_Table();
1048 1048
         $table->prepare_items();
@@ -1053,12 +1053,12 @@  discard block
 block discarded – undo
1053 1053
      * Displays the items report.
1054 1054
      */
1055 1055
     public function items_report() {
1056
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-items-report-table.php' );
1056
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-items-report-table.php');
1057 1057
 
1058 1058
         $table = new WPInv_Items_Report_Table();
1059 1059
         $table->prepare_items();
1060 1060
         $table->display();
1061
-        echo __( '* Items with no sales not shown.', 'invoicing' );
1061
+        echo __('* Items with no sales not shown.', 'invoicing');
1062 1062
     }
1063 1063
 
1064 1064
     /**
@@ -1068,27 +1068,27 @@  discard block
 block discarded – undo
1068 1068
      */
1069 1069
     public function tax_report() {
1070 1070
 
1071
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-taxes-report-table.php' );
1071
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-taxes-report-table.php');
1072 1072
         $table = new WPInv_Taxes_Reports_Table();
1073 1073
         $table->prepare_items();
1074
-        $year = isset( $_GET['year'] ) ? absint( $_GET['year'] ) : date( 'Y' );
1074
+        $year = isset($_GET['year']) ? absint($_GET['year']) : date('Y');
1075 1075
         ?>
1076 1076
 
1077 1077
         <div class="metabox-holder" style="padding-top: 0;">
1078 1078
             <div class="postbox">
1079
-                <h3><span><?php _e('Tax Report','invoicing' ); ?></span></h3>
1079
+                <h3><span><?php _e('Tax Report', 'invoicing'); ?></span></h3>
1080 1080
                 <div class="inside">
1081
-                    <p><?php _e( 'This report shows the total amount collected in sales tax for the given year.', 'invoicing' ); ?></p>
1081
+                    <p><?php _e('This report shows the total amount collected in sales tax for the given year.', 'invoicing'); ?></p>
1082 1082
                     <form method="get">
1083
-                        <span><?php echo $year; ?></span>: <strong><?php echo wpinv_sales_tax_for_year( $year ); ?></strong>&nbsp;&mdash;&nbsp;
1083
+                        <span><?php echo $year; ?></span>: <strong><?php echo wpinv_sales_tax_for_year($year); ?></strong>&nbsp;&mdash;&nbsp;
1084 1084
                         <select name="year">
1085
-                            <?php for ( $i = 2014; $i <= date( 'Y' ); $i++ ) : ?>
1086
-                            <option value="<?php echo $i; ?>"<?php selected( $year, $i ); ?>><?php echo $i; ?></option>
1085
+                            <?php for ($i = 2014; $i <= date('Y'); $i++) : ?>
1086
+                            <option value="<?php echo $i; ?>"<?php selected($year, $i); ?>><?php echo $i; ?></option>
1087 1087
                             <?php endfor; ?>
1088 1088
                         </select>
1089 1089
                         <input type="hidden" name="view" value="taxes" />
1090 1090
                         <input type="hidden" name="page" value="wpinv-reports"/>
1091
-                        <?php submit_button( __( 'Submit', 'invoicing' ), 'secondary', 'submit', false ); ?>
1091
+                        <?php submit_button(__('Submit', 'invoicing'), 'secondary', 'submit', false); ?>
1092 1092
                     </form>
1093 1093
                 </div><!-- .inside -->
1094 1094
             </div><!-- .postbox -->
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +395 added lines, -395 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @since   1.0.0
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Retrieves all default settings.
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
 function wpinv_get_settings() {
17 17
     $defaults = array();
18 18
 
19
-    foreach ( array_values( wpinv_get_registered_settings() ) as $tab_settings ) {
19
+    foreach (array_values(wpinv_get_registered_settings()) as $tab_settings) {
20 20
 
21
-        foreach ( array_values( $tab_settings ) as $section_settings ) {
21
+        foreach (array_values($tab_settings) as $section_settings) {
22 22
 
23
-            foreach ( $section_settings as $key => $setting ) {
24
-                if ( isset( $setting['std'] ) ) {
25
-                    $defaults[ $key ] = $setting['std'];
23
+            foreach ($section_settings as $key => $setting) {
24
+                if (isset($setting['std'])) {
25
+                    $defaults[$key] = $setting['std'];
26 26
                 }
27 27
             }
28 28
 
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
     global $wpinv_options;
44 44
 
45 45
     // Try fetching the saved options.
46
-    if ( ! is_array( $wpinv_options ) ) {
47
-        $wpinv_options = get_option( 'wpinv_settings' );
46
+    if (!is_array($wpinv_options)) {
47
+        $wpinv_options = get_option('wpinv_settings');
48 48
     }
49 49
 
50 50
     // If that fails, don't fetch the default settings to prevent a loop.
51
-    if ( ! is_array( $wpinv_options ) ) {
51
+    if (!is_array($wpinv_options)) {
52 52
         $wpinv_options = array();
53 53
     }
54 54
 
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
  * @param mixed $default The default value to use if the setting has not been set.
63 63
  * @return mixed
64 64
  */
65
-function wpinv_get_option( $key = '', $default = false ) {
65
+function wpinv_get_option($key = '', $default = false) {
66 66
 
67 67
     $options = wpinv_get_options();
68
-    $value   = isset( $options[ $key ] ) ? $options[ $key ] : $default;
69
-    $value   = apply_filters( 'wpinv_get_option', $value, $key, $default );
68
+    $value   = isset($options[$key]) ? $options[$key] : $default;
69
+    $value   = apply_filters('wpinv_get_option', $value, $key, $default);
70 70
 
71
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
71
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
72 72
 }
73 73
 
74 74
 /**
@@ -77,11 +77,11 @@  discard block
 block discarded – undo
77 77
  * @param array $options the new options.
78 78
  * @return bool
79 79
  */
80
-function wpinv_update_options( $options ) {
80
+function wpinv_update_options($options) {
81 81
     global $wpinv_options;
82 82
 
83 83
     // update the option.
84
-    if ( is_array( $options ) && update_option( 'wpinv_settings', $options ) ) {
84
+    if (is_array($options) && update_option('wpinv_settings', $options)) {
85 85
         $wpinv_options = $options;
86 86
         return true;
87 87
     }
@@ -96,24 +96,24 @@  discard block
 block discarded – undo
96 96
  * @param mixed $value The setting value.
97 97
  * @return bool
98 98
  */
99
-function wpinv_update_option( $key = '', $value = false ) {
99
+function wpinv_update_option($key = '', $value = false) {
100 100
 
101 101
     // If no key, exit.
102
-    if ( empty( $key ) ) {
102
+    if (empty($key)) {
103 103
         return false;
104 104
     }
105 105
 
106 106
     // Maybe delete the option instead.
107
-    if ( is_null( $value ) ) {
108
-        return wpinv_delete_option( $key );
107
+    if (is_null($value)) {
108
+        return wpinv_delete_option($key);
109 109
     }
110 110
 
111 111
     // Prepare the new options.
112 112
     $options         = wpinv_get_options();
113
-    $options[ $key ] = apply_filters( 'wpinv_update_option', $value, $key );
113
+    $options[$key] = apply_filters('wpinv_update_option', $value, $key);
114 114
 
115 115
     // Save the new options.
116
-    return wpinv_update_options( $options );
116
+    return wpinv_update_options($options);
117 117
 
118 118
 }
119 119
 
@@ -123,18 +123,18 @@  discard block
 block discarded – undo
123 123
  * @param string $key the setting key.
124 124
  * @return bool
125 125
  */
126
-function wpinv_delete_option( $key = '' ) {
126
+function wpinv_delete_option($key = '') {
127 127
 
128 128
     // If no key, exit
129
-    if ( empty( $key ) ) {
129
+    if (empty($key)) {
130 130
         return false;
131 131
     }
132 132
 
133 133
     $options = wpinv_get_options();
134 134
 
135
-    if ( isset( $options[ $key ] ) ) {
136
-        unset( $options[ $key ] );
137
-        return wpinv_update_options( $options );
135
+    if (isset($options[$key])) {
136
+        unset($options[$key]);
137
+        return wpinv_update_options($options);
138 138
     }
139 139
 
140 140
     return true;
@@ -148,14 +148,14 @@  discard block
 block discarded – undo
148 148
 function wpinv_register_settings() {
149 149
 
150 150
     // Loop through all tabs.
151
-    foreach ( wpinv_get_registered_settings() as $tab => $sections ) {
151
+    foreach (wpinv_get_registered_settings() as $tab => $sections) {
152 152
 
153 153
         // In each tab, loop through sections.
154
-        foreach ( $sections as $section => $settings ) {
154
+        foreach ($sections as $section => $settings) {
155 155
 
156 156
             // Check for backwards compatibility
157
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
158
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
157
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
158
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
159 159
                 $section = 'main';
160 160
                 $settings = $sections;
161 161
             }
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
                 'wpinv_settings_' . $tab . '_' . $section
169 169
             );
170 170
 
171
-            foreach ( $settings as $option ) {
172
-                if ( ! empty( $option['id'] ) ) {
173
-                    wpinv_register_settings_option( $tab, $section, $option );
171
+            foreach ($settings as $option) {
172
+                if (!empty($option['id'])) {
173
+                    wpinv_register_settings_option($tab, $section, $option);
174 174
                 }
175 175
             }
176 176
 
@@ -178,9 +178,9 @@  discard block
 block discarded – undo
178 178
     }
179 179
 
180 180
     // Creates our settings in the options table.
181
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
181
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
182 182
 }
183
-add_action( 'admin_init', 'wpinv_register_settings' );
183
+add_action('admin_init', 'wpinv_register_settings');
184 184
 
185 185
 /**
186 186
  * Register a single settings option.
@@ -190,46 +190,46 @@  discard block
 block discarded – undo
190 190
  * @param string $option
191 191
  * 
192 192
  */
193
-function wpinv_register_settings_option( $tab, $section, $option ) {
193
+function wpinv_register_settings_option($tab, $section, $option) {
194 194
 
195
-    $name    = isset( $option['name'] ) ? $option['name'] : '';
195
+    $name    = isset($option['name']) ? $option['name'] : '';
196 196
     $cb      = "wpinv_{$option['type']}_callback";
197 197
     $section = "wpinv_settings_{$tab}_$section";
198 198
 
199
-	if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
-		$tip   = esc_attr( $option['desc'] );
199
+	if (isset($option['desc']) && !empty($option['help-tip'])) {
200
+		$tip   = esc_attr($option['desc']);
201 201
 		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
-		unset( $option['desc'] );
202
+		unset($option['desc']);
203 203
 	}
204 204
 
205 205
     // Loop through all tabs.
206 206
     add_settings_field(
207 207
         'wpinv_settings[' . $option['id'] . ']',
208 208
         $name,
209
-        function_exists( $cb ) ? $cb : 'wpinv_missing_callback',
209
+        function_exists($cb) ? $cb : 'wpinv_missing_callback',
210 210
         $section,
211 211
         $section,
212 212
         array(
213 213
             'section'     => $section,
214
-            'id'          => isset( $option['id'] )          ? $option['id']          : null,
215
-            'desc'        => isset( $option['desc'] )        ? $option['desc']        : '',
214
+            'id'          => isset($option['id']) ? $option['id'] : null,
215
+            'desc'        => isset($option['desc']) ? $option['desc'] : '',
216 216
             'name'        => $name,
217
-            'size'        => isset( $option['size'] )        ? $option['size']        : null,
218
-            'options'     => isset( $option['options'] )     ? $option['options']     : '',
219
-            'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
220
-            'std'         => isset( $option['std'] )         ? $option['std']         : '',
221
-            'min'         => isset( $option['min'] )         ? $option['min']         : null,
222
-            'max'         => isset( $option['max'] )         ? $option['max']         : null,
223
-            'step'        => isset( $option['step'] )        ? $option['step']        : null,
224
-            'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
225
-            'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
226
-            'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
227
-            'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
228
-            'onchange'    => isset( $option['onchange'] )   ? $option['onchange']     : '',
229
-            'custom'      => isset( $option['custom'] )     ? $option['custom']       : '',
230
-            'class'       => isset( $option['class'] )     ? $option['class']         : '',
231
-            'cols'        => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
-            'rows'        => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
217
+            'size'        => isset($option['size']) ? $option['size'] : null,
218
+            'options'     => isset($option['options']) ? $option['options'] : '',
219
+            'selected'    => isset($option['selected']) ? $option['selected'] : null,
220
+            'std'         => isset($option['std']) ? $option['std'] : '',
221
+            'min'         => isset($option['min']) ? $option['min'] : null,
222
+            'max'         => isset($option['max']) ? $option['max'] : null,
223
+            'step'        => isset($option['step']) ? $option['step'] : null,
224
+            'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
225
+            'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
226
+            'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
227
+            'faux'        => isset($option['faux']) ? $option['faux'] : false,
228
+            'onchange'    => isset($option['onchange']) ? $option['onchange'] : '',
229
+            'custom'      => isset($option['custom']) ? $option['custom'] : '',
230
+            'class'       => isset($option['class']) ? $option['class'] : '',
231
+            'cols'        => isset($option['cols']) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
232
+            'rows'        => isset($option['rows']) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
233 233
         )
234 234
     );
235 235
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
  * @return array
242 242
  */
243 243
 function wpinv_get_registered_settings() {
244
-    return apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) );
244
+    return apply_filters('wpinv_registered_settings', wpinv_get_data('admin-settings'));
245 245
 }
246 246
 
247 247
 /**
@@ -249,134 +249,134 @@  discard block
 block discarded – undo
249 249
  * 
250 250
  * @return array
251 251
  */
252
-function wpinv_settings_sanitize( $input = array() ) {
252
+function wpinv_settings_sanitize($input = array()) {
253 253
 
254 254
     $wpinv_options = wpinv_get_options();
255 255
 
256
-    if ( empty( wp_get_raw_referer() ) ) {
256
+    if (empty(wp_get_raw_referer())) {
257 257
         return $input;
258 258
     }
259 259
 
260
-    wp_parse_str( wp_get_raw_referer(), $referrer );
260
+    wp_parse_str(wp_get_raw_referer(), $referrer);
261 261
 
262 262
     $settings = wpinv_get_registered_settings();
263
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
264
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
263
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
264
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
265 265
 
266 266
     $input = $input ? $input : array();
267
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
268
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
267
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
268
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
269 269
 
270 270
     // Loop through each setting being saved and pass it through a sanitization filter
271
-    foreach ( $input as $key => $value ) {
271
+    foreach ($input as $key => $value) {
272 272
 
273 273
         // Get the setting type (checkbox, select, etc)
274
-        $type = isset( $settings[ $tab ][$section][ $key ]['type'] ) ? $settings[ $tab ][$section][ $key ]['type'] : false;
274
+        $type = isset($settings[$tab][$section][$key]['type']) ? $settings[$tab][$section][$key]['type'] : false;
275 275
 
276
-        if ( $type ) {
276
+        if ($type) {
277 277
             // Field type specific filter
278
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
278
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
279 279
         }
280 280
 
281 281
         // General filter
282
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
282
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
283 283
     }
284 284
 
285 285
     // Loop through the whitelist and unset any that are empty for the tab being saved
286
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
287
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
286
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
287
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
288 288
 
289
-    $found_settings = array_merge( $main_settings, $section_settings );
289
+    $found_settings = array_merge($main_settings, $section_settings);
290 290
 
291
-    if ( ! empty( $found_settings ) ) {
292
-        foreach ( $found_settings as $key => $value ) {
291
+    if (!empty($found_settings)) {
292
+        foreach ($found_settings as $key => $value) {
293 293
 
294 294
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
295
-            if ( is_numeric( $key ) ) {
295
+            if (is_numeric($key)) {
296 296
                 $key = $value['id'];
297 297
             }
298 298
 
299
-            if ( ! isset( $input[ $key ] ) && isset( $wpinv_options[ $key ] ) ) {
300
-                unset( $wpinv_options[ $key ] );
299
+            if (!isset($input[$key]) && isset($wpinv_options[$key])) {
300
+                unset($wpinv_options[$key]);
301 301
             }
302 302
         }
303 303
     }
304 304
 
305 305
     // Merge our new settings with the existing
306
-    $output = array_merge( $wpinv_options, $input );
306
+    $output = array_merge($wpinv_options, $input);
307 307
 
308
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
308
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
309 309
 
310 310
     return $output;
311 311
 }
312 312
 
313
-function wpinv_settings_sanitize_misc_accounting( $input ) {
313
+function wpinv_settings_sanitize_misc_accounting($input) {
314 314
 
315
-    if ( ! wpinv_current_user_can_manage_invoicing() ) {
315
+    if (!wpinv_current_user_can_manage_invoicing()) {
316 316
         return $input;
317 317
     }
318 318
 
319
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
319
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
320 320
         // Shows an admin notice about upgrading previous order numbers
321
-        getpaid_session()->set( 'upgrade_sequential', '1' );
321
+        getpaid_session()->set('upgrade_sequential', '1');
322 322
     }
323 323
 
324 324
     return $input;
325 325
 }
326
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
326
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
327 327
 
328
-function wpinv_settings_sanitize_tax_rates( $input ) {
329
-    if( ! wpinv_current_user_can_manage_invoicing() ) {
328
+function wpinv_settings_sanitize_tax_rates($input) {
329
+    if (!wpinv_current_user_can_manage_invoicing()) {
330 330
         return $input;
331 331
     }
332 332
 
333
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
333
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
334 334
 
335 335
     $tax_rates = array();
336 336
 
337
-    if ( !empty( $new_rates ) ) {
338
-        foreach ( $new_rates as $rate ) {
339
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
337
+    if (!empty($new_rates)) {
338
+        foreach ($new_rates as $rate) {
339
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
340 340
                 continue;
341 341
             }
342 342
             
343
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
343
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
344 344
             
345 345
             $tax_rates[] = $rate;
346 346
         }
347 347
     }
348 348
 
349
-    update_option( 'wpinv_tax_rates', $tax_rates );
349
+    update_option('wpinv_tax_rates', $tax_rates);
350 350
 
351 351
     return $input;
352 352
 }
353
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
353
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
354 354
 
355
-function wpinv_sanitize_text_field( $input ) {
356
-    return trim( $input );
355
+function wpinv_sanitize_text_field($input) {
356
+    return trim($input);
357 357
 }
358
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
358
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
359 359
 
360 360
 function wpinv_get_settings_tabs() {
361 361
     $tabs             = array();
362
-    $tabs['general']  = __( 'General', 'invoicing' );
363
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
364
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
365
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
366
-    $tabs['privacy']  = __( 'Privacy', 'invoicing' );
367
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
368
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
369
-
370
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
362
+    $tabs['general']  = __('General', 'invoicing');
363
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
364
+    $tabs['taxes']    = __('Taxes', 'invoicing');
365
+    $tabs['emails']   = __('Emails', 'invoicing');
366
+    $tabs['privacy']  = __('Privacy', 'invoicing');
367
+    $tabs['misc']     = __('Misc', 'invoicing');
368
+    $tabs['tools']    = __('Tools', 'invoicing');
369
+
370
+    return apply_filters('wpinv_settings_tabs', $tabs);
371 371
 }
372 372
 
373
-function wpinv_get_settings_tab_sections( $tab = false ) {
373
+function wpinv_get_settings_tab_sections($tab = false) {
374 374
     $tabs     = false;
375 375
     $sections = wpinv_get_registered_settings_sections();
376 376
 
377
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
378
-        $tabs = $sections[ $tab ];
379
-    } else if ( $tab ) {
377
+    if ($tab && !empty($sections[$tab])) {
378
+        $tabs = $sections[$tab];
379
+    } else if ($tab) {
380 380
         $tabs = false;
381 381
     }
382 382
 
@@ -386,149 +386,149 @@  discard block
 block discarded – undo
386 386
 function wpinv_get_registered_settings_sections() {
387 387
     static $sections = false;
388 388
 
389
-    if ( false !== $sections ) {
389
+    if (false !== $sections) {
390 390
         return $sections;
391 391
     }
392 392
 
393 393
     $sections = array(
394
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
395
-            'main' => __( 'General Settings', 'invoicing' ),
396
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
397
-            'labels' => __( 'Label Texts', 'invoicing' ),
398
-        ) ),
399
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
400
-            'main' => __( 'Gateway Settings', 'invoicing' ),
401
-        ) ),
402
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
403
-            'main' => __( 'Tax Settings', 'invoicing' ),
404
-            'rates' => __( 'Tax Rates', 'invoicing' ),
405
-        ) ),
406
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
407
-            'main' => __( 'Email Settings', 'invoicing' ),
408
-        ) ),
409
-        'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
410
-            'main' => __( 'Privacy policy', 'invoicing' ),
411
-        ) ),
412
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
413
-            'main' => __( 'Miscellaneous', 'invoicing' ),
414
-            'custom-css' => __( 'Custom CSS', 'invoicing' ),
415
-        ) ),
416
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
417
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
418
-        ) ),
394
+        'general' => apply_filters('wpinv_settings_sections_general', array(
395
+            'main' => __('General Settings', 'invoicing'),
396
+            'currency_section' => __('Currency Settings', 'invoicing'),
397
+            'labels' => __('Label Texts', 'invoicing'),
398
+        )),
399
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
400
+            'main' => __('Gateway Settings', 'invoicing'),
401
+        )),
402
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
403
+            'main' => __('Tax Settings', 'invoicing'),
404
+            'rates' => __('Tax Rates', 'invoicing'),
405
+        )),
406
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
407
+            'main' => __('Email Settings', 'invoicing'),
408
+        )),
409
+        'privacy' => apply_filters('wpinv_settings_sections_privacy', array(
410
+            'main' => __('Privacy policy', 'invoicing'),
411
+        )),
412
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
413
+            'main' => __('Miscellaneous', 'invoicing'),
414
+            'custom-css' => __('Custom CSS', 'invoicing'),
415
+        )),
416
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
417
+            'main' => __('Diagnostic Tools', 'invoicing'),
418
+        )),
419 419
     );
420 420
 
421
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
421
+    $sections = apply_filters('wpinv_settings_sections', $sections);
422 422
 
423 423
     return $sections;
424 424
 }
425 425
 
426
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
426
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
427 427
 	$pages_options = array();
428 428
 
429
-	if( $default_label !== NULL && $default_label !== false ) {
430
-		$pages_options = array( '' => $default_label ); // Blank option
429
+	if ($default_label !== NULL && $default_label !== false) {
430
+		$pages_options = array('' => $default_label); // Blank option
431 431
 	}
432 432
 
433 433
 	$pages = get_pages();
434
-	if ( $pages ) {
435
-		foreach ( $pages as $page ) {
434
+	if ($pages) {
435
+		foreach ($pages as $page) {
436 436
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
437
-            $pages_options[ $page->ID ] = $title;
437
+            $pages_options[$page->ID] = $title;
438 438
 		}
439 439
 	}
440 440
 
441 441
 	return $pages_options;
442 442
 }
443 443
 
444
-function wpinv_header_callback( $args ) {
445
-	if ( !empty( $args['desc'] ) ) {
444
+function wpinv_header_callback($args) {
445
+	if (!empty($args['desc'])) {
446 446
         echo $args['desc'];
447 447
     }
448 448
 }
449 449
 
450
-function wpinv_hidden_callback( $args ) {
450
+function wpinv_hidden_callback($args) {
451 451
 	global $wpinv_options;
452 452
 
453
-	if ( isset( $args['set_value'] ) ) {
453
+	if (isset($args['set_value'])) {
454 454
 		$value = $args['set_value'];
455
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
456
-		$value = $wpinv_options[ $args['id'] ];
455
+	} elseif (isset($wpinv_options[$args['id']])) {
456
+		$value = $wpinv_options[$args['id']];
457 457
 	} else {
458
-		$value = isset( $args['std'] ) ? $args['std'] : '';
458
+		$value = isset($args['std']) ? $args['std'] : '';
459 459
 	}
460 460
 
461
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
461
+	if (isset($args['faux']) && true === $args['faux']) {
462 462
 		$args['readonly'] = true;
463
-		$value = isset( $args['std'] ) ? $args['std'] : '';
463
+		$value = isset($args['std']) ? $args['std'] : '';
464 464
 		$name  = '';
465 465
 	} else {
466
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
466
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
467 467
 	}
468 468
 
469
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
469
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
470 470
     
471 471
 	echo $html;
472 472
 }
473 473
 
474
-function wpinv_checkbox_callback( $args ) {
474
+function wpinv_checkbox_callback($args) {
475 475
 	global $wpinv_options;
476 476
     
477
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
477
+    $sanitize_id = wpinv_sanitize_key($args['id']);
478 478
 
479
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
479
+	if (isset($args['faux']) && true === $args['faux']) {
480 480
 		$name = '';
481 481
 	} else {
482 482
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
483 483
 	}
484 484
 
485
-	$std     = isset( $args['std'] ) ? $args['std'] : 0;
486
-	$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
487
-	$checked = checked( empty( $value ), false, false );
485
+	$std     = isset($args['std']) ? $args['std'] : 0;
486
+	$value   = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std;
487
+	$checked = checked(empty($value), false, false);
488 488
 
489 489
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
490
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
490
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
491 491
 
492 492
 	echo $html;
493 493
 }
494 494
 
495
-function wpinv_multicheck_callback( $args ) {
495
+function wpinv_multicheck_callback($args) {
496 496
 	global $wpinv_options;
497 497
 
498
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
499
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
498
+	$sanitize_id = wpinv_sanitize_key($args['id']);
499
+	$class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
500 500
 
501
-	if ( ! empty( $args['options'] ) ) {
501
+	if (!empty($args['options'])) {
502 502
 
503
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
504
-		$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
503
+		$std     = isset($args['std']) ? $args['std'] : array();
504
+		$value   = isset($wpinv_options[$args['id']]) ? $wpinv_options[$args['id']] : $std;
505 505
 
506 506
 		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
507
-        foreach( $args['options'] as $key => $option ):
508
-			$sanitize_key = wpinv_sanitize_key( $key );
509
-			if ( in_array( $sanitize_key, $value ) ) { 
507
+        foreach ($args['options'] as $key => $option):
508
+			$sanitize_key = wpinv_sanitize_key($key);
509
+			if (in_array($sanitize_key, $value)) { 
510 510
 				$enabled = $sanitize_key;
511 511
 			} else { 
512 512
 				$enabled = NULL; 
513 513
 			}
514
-			echo '<div class="wpi-mcheck-row"><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;';
515
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
514
+			echo '<div class="wpi-mcheck-row"><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;';
515
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>';
516 516
 		endforeach;
517 517
 		echo '</div>';
518 518
 		echo '<p class="description">' . $args['desc'] . '</p>';
519 519
 	}
520 520
 }
521 521
 
522
-function wpinv_payment_icons_callback( $args ) {
522
+function wpinv_payment_icons_callback($args) {
523 523
 	global $wpinv_options;
524 524
     
525
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
525
+    $sanitize_id = wpinv_sanitize_key($args['id']);
526 526
 
527
-	if ( ! empty( $args['options'] ) ) {
528
-		foreach( $args['options'] as $key => $option ) {
529
-            $sanitize_key = wpinv_sanitize_key( $key );
527
+	if (!empty($args['options'])) {
528
+		foreach ($args['options'] as $key => $option) {
529
+            $sanitize_key = wpinv_sanitize_key($key);
530 530
             
531
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
531
+			if (isset($wpinv_options[$args['id']][$key])) {
532 532
 				$enabled = $option;
533 533
 			} else {
534 534
 				$enabled = NULL;
@@ -536,197 +536,197 @@  discard block
 block discarded – undo
536 536
 
537 537
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
538 538
 
539
-				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;';
539
+				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;';
540 540
 
541
-				if ( wpinv_string_is_image_url( $key ) ) {
542
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
541
+				if (wpinv_string_is_image_url($key)) {
542
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
543 543
 				} else {
544
-					$card = strtolower( str_replace( ' ', '', $option ) );
544
+					$card = strtolower(str_replace(' ', '', $option));
545 545
 
546
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
547
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
546
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
547
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
548 548
 					} else {
549
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
549
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
550 550
 						$content_dir = WP_CONTENT_DIR;
551 551
 
552
-						if ( function_exists( 'wp_normalize_path' ) ) {
552
+						if (function_exists('wp_normalize_path')) {
553 553
 							// Replaces backslashes with forward slashes for Windows systems
554
-							$image = wp_normalize_path( $image );
555
-							$content_dir = wp_normalize_path( $content_dir );
554
+							$image = wp_normalize_path($image);
555
+							$content_dir = wp_normalize_path($content_dir);
556 556
 						}
557 557
 
558
-						$image = str_replace( $content_dir, content_url(), $image );
558
+						$image = str_replace($content_dir, content_url(), $image);
559 559
 					}
560 560
 
561
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
561
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
562 562
 				}
563 563
 			echo $option . '</label>';
564 564
 		}
565
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
565
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
566 566
 	}
567 567
 }
568 568
 
569
-function wpinv_radio_callback( $args ) {
569
+function wpinv_radio_callback($args) {
570 570
 	global $wpinv_options;
571 571
     
572
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
572
+    $sanitize_id = wpinv_sanitize_key($args['id']);
573 573
     
574
-    foreach ( $args['options'] as $key => $option ) :
575
-		$sanitize_key = wpinv_sanitize_key( $key );
574
+    foreach ($args['options'] as $key => $option) :
575
+		$sanitize_key = wpinv_sanitize_key($key);
576 576
         
577 577
         $checked = false;
578 578
 
579
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
579
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
580 580
 			$checked = true;
581
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
581
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
582 582
 			$checked = true;
583 583
 
584 584
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
585
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
585
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
586 586
 	endforeach;
587 587
 
588
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
588
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
589 589
 }
590 590
 
591
-function wpinv_gateways_callback( $args ) {
591
+function wpinv_gateways_callback($args) {
592 592
 	global $wpinv_options;
593 593
     
594
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
594
+    $sanitize_id = wpinv_sanitize_key($args['id']);
595 595
 
596
-	foreach ( $args['options'] as $key => $option ) :
597
-		$sanitize_key = wpinv_sanitize_key( $key );
596
+	foreach ($args['options'] as $key => $option) :
597
+		$sanitize_key = wpinv_sanitize_key($key);
598 598
         
599
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
599
+        if (isset($wpinv_options['gateways'][$key]))
600 600
 			$enabled = '1';
601 601
 		else
602 602
 			$enabled = null;
603 603
 
604
-		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;';
605
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
604
+		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;';
605
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
606 606
 	endforeach;
607 607
 }
608 608
 
609 609
 function wpinv_gateway_select_callback($args) {
610 610
 	global $wpinv_options;
611 611
     
612
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
613
-    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
612
+    $sanitize_id = wpinv_sanitize_key($args['id']);
613
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
614 614
 
615
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
615
+	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '" >';
616 616
 
617
-	foreach ( $args['options'] as $key => $option ) :
618
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
619
-            $selected = selected( $key, $args['selected'], false );
617
+	foreach ($args['options'] as $key => $option) :
618
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
619
+            $selected = selected($key, $args['selected'], false);
620 620
         } else {
621
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
621
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
622 622
         }
623
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
623
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
624 624
 	endforeach;
625 625
 
626 626
 	echo '</select>';
627
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
627
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
628 628
 }
629 629
 
630
-function wpinv_text_callback( $args ) {
630
+function wpinv_text_callback($args) {
631 631
 	global $wpinv_options;
632 632
     
633
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
633
+    $sanitize_id = wpinv_sanitize_key($args['id']);
634 634
 
635
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
636
-		$value = $wpinv_options[ $args['id'] ];
635
+	if (isset($wpinv_options[$args['id']])) {
636
+		$value = $wpinv_options[$args['id']];
637 637
 	} else {
638
-		$value = isset( $args['std'] ) ? $args['std'] : '';
638
+		$value = isset($args['std']) ? $args['std'] : '';
639 639
 	}
640 640
 
641
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
641
+	if (isset($args['faux']) && true === $args['faux']) {
642 642
 		$args['readonly'] = true;
643
-		$value = isset( $args['std'] ) ? $args['std'] : '';
643
+		$value = isset($args['std']) ? $args['std'] : '';
644 644
 		$name  = '';
645 645
 	} else {
646
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
646
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
647 647
 	}
648
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
648
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
649 649
 
650 650
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
651
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
652
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
653
-	$html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
651
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
652
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
653
+	$html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
654 654
 
655 655
 	echo $html;
656 656
 }
657 657
 
658
-function wpinv_number_callback( $args ) {
658
+function wpinv_number_callback($args) {
659 659
 	global $wpinv_options;
660 660
     
661
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
661
+    $sanitize_id = wpinv_sanitize_key($args['id']);
662 662
 
663
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
664
-		$value = $wpinv_options[ $args['id'] ];
663
+	if (isset($wpinv_options[$args['id']])) {
664
+		$value = $wpinv_options[$args['id']];
665 665
 	} else {
666
-		$value = isset( $args['std'] ) ? $args['std'] : '';
666
+		$value = isset($args['std']) ? $args['std'] : '';
667 667
 	}
668 668
 
669
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
669
+	if (isset($args['faux']) && true === $args['faux']) {
670 670
 		$args['readonly'] = true;
671
-		$value = isset( $args['std'] ) ? $args['std'] : '';
671
+		$value = isset($args['std']) ? $args['std'] : '';
672 672
 		$name  = '';
673 673
 	} else {
674
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
674
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
675 675
 	}
676 676
 
677
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
678
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
679
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
680
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
677
+	$max  = isset($args['max']) ? $args['max'] : 999999;
678
+	$min  = isset($args['min']) ? $args['min'] : 0;
679
+	$step = isset($args['step']) ? $args['step'] : 1;
680
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
681 681
 
682
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
683
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
684
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
682
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
683
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
684
+	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
685 685
 
686 686
 	echo $html;
687 687
 }
688 688
 
689
-function wpinv_textarea_callback( $args ) {
689
+function wpinv_textarea_callback($args) {
690 690
 	global $wpinv_options;
691 691
     
692
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
692
+    $sanitize_id = wpinv_sanitize_key($args['id']);
693 693
 
694
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
695
-		$value = $wpinv_options[ $args['id'] ];
694
+	if (isset($wpinv_options[$args['id']])) {
695
+		$value = $wpinv_options[$args['id']];
696 696
 	} else {
697
-		$value = isset( $args['std'] ) ? $args['std'] : '';
697
+		$value = isset($args['std']) ? $args['std'] : '';
698 698
 	}
699 699
     
700
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
701
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
700
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
701
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
702 702
 
703
-	$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>';
704
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
703
+	$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>';
704
+	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
705 705
 
706 706
 	echo $html;
707 707
 }
708 708
 
709
-function wpinv_password_callback( $args ) {
709
+function wpinv_password_callback($args) {
710 710
 	global $wpinv_options;
711 711
     
712
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
712
+    $sanitize_id = wpinv_sanitize_key($args['id']);
713 713
 
714
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
715
-		$value = $wpinv_options[ $args['id'] ];
714
+	if (isset($wpinv_options[$args['id']])) {
715
+		$value = $wpinv_options[$args['id']];
716 716
 	} else {
717
-		$value = isset( $args['std'] ) ? $args['std'] : '';
717
+		$value = isset($args['std']) ? $args['std'] : '';
718 718
 	}
719 719
 
720
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
721
-	$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 ) . '"/>';
722
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
720
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
721
+	$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) . '"/>';
722
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
723 723
 
724 724
 	echo $html;
725 725
 }
726 726
 
727 727
 function wpinv_missing_callback($args) {
728 728
 	printf(
729
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
729
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
730 730
 		'<strong>' . $args['id'] . '</strong>'
731 731
 	);
732 732
 }
@@ -734,134 +734,134 @@  discard block
 block discarded – undo
734 734
 function wpinv_select_callback($args) {
735 735
 	global $wpinv_options;
736 736
     
737
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
737
+    $sanitize_id = wpinv_sanitize_key($args['id']);
738 738
 
739
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
740
-		$value = $wpinv_options[ $args['id'] ];
739
+	if (isset($wpinv_options[$args['id']])) {
740
+		$value = $wpinv_options[$args['id']];
741 741
 	} else {
742
-		$value = isset( $args['std'] ) ? $args['std'] : '';
742
+		$value = isset($args['std']) ? $args['std'] : '';
743 743
 	}
744 744
     
745
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
745
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
746 746
         $value = $args['selected'];
747 747
     }
748 748
 
749
-	if ( isset( $args['placeholder'] ) ) {
749
+	if (isset($args['placeholder'])) {
750 750
 		$placeholder = $args['placeholder'];
751 751
 	} else {
752 752
 		$placeholder = '';
753 753
 	}
754 754
     
755
-    if( !empty( $args['onchange'] ) ) {
756
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
755
+    if (!empty($args['onchange'])) {
756
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
757 757
     } else {
758 758
         $onchange = '';
759 759
     }
760 760
 
761
-    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
761
+    $class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
762 762
 
763
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
763
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="' . $class . '"  name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
764 764
 
765
-	foreach ( $args['options'] as $option => $name ) {
766
-		$selected = selected( $option, $value, false );
767
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
765
+	foreach ($args['options'] as $option => $name) {
766
+		$selected = selected($option, $value, false);
767
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
768 768
 	}
769 769
 
770 770
 	$html .= '</select>';
771
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
771
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
772 772
 
773 773
 	echo $html;
774 774
 }
775 775
 
776
-function wpinv_color_select_callback( $args ) {
776
+function wpinv_color_select_callback($args) {
777 777
 	global $wpinv_options;
778 778
     
779
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
779
+    $sanitize_id = wpinv_sanitize_key($args['id']);
780 780
 
781
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
782
-		$value = $wpinv_options[ $args['id'] ];
781
+	if (isset($wpinv_options[$args['id']])) {
782
+		$value = $wpinv_options[$args['id']];
783 783
 	} else {
784
-		$value = isset( $args['std'] ) ? $args['std'] : '';
784
+		$value = isset($args['std']) ? $args['std'] : '';
785 785
 	}
786 786
 
787
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
787
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
788 788
 
789
-	foreach ( $args['options'] as $option => $color ) {
790
-		$selected = selected( $option, $value, false );
791
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
789
+	foreach ($args['options'] as $option => $color) {
790
+		$selected = selected($option, $value, false);
791
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
792 792
 	}
793 793
 
794 794
 	$html .= '</select>';
795
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
795
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
796 796
 
797 797
 	echo $html;
798 798
 }
799 799
 
800
-function wpinv_rich_editor_callback( $args ) {
800
+function wpinv_rich_editor_callback($args) {
801 801
 	global $wpinv_options, $wp_version;
802 802
     
803
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
803
+    $sanitize_id = wpinv_sanitize_key($args['id']);
804 804
 
805
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
806
-		$value = $wpinv_options[ $args['id'] ];
805
+	if (isset($wpinv_options[$args['id']])) {
806
+		$value = $wpinv_options[$args['id']];
807 807
 
808
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
809
-			$value = isset( $args['std'] ) ? $args['std'] : '';
808
+		if (empty($args['allow_blank']) && empty($value)) {
809
+			$value = isset($args['std']) ? $args['std'] : '';
810 810
 		}
811 811
 	} else {
812
-		$value = isset( $args['std'] ) ? $args['std'] : '';
812
+		$value = isset($args['std']) ? $args['std'] : '';
813 813
 	}
814 814
 
815
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
815
+	$rows = isset($args['size']) ? $args['size'] : 20;
816 816
 
817 817
 	$html = '<div class="getpaid-settings-editor-input">';
818
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
818
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
819 819
 		ob_start();
820
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
820
+		wp_editor(stripslashes($value), 'wpinv_settings_' . esc_attr($args['id']), array('textarea_name' => 'wpinv_settings[' . esc_attr($args['id']) . ']', 'textarea_rows' => absint($rows), 'media_buttons' => false));
821 821
 		$html .= ob_get_clean();
822 822
 	} else {
823
-		$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>';
823
+		$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>';
824 824
 	}
825 825
 
826
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
826
+	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
827 827
 
828 828
 	echo $html;
829 829
 }
830 830
 
831
-function wpinv_upload_callback( $args ) {
831
+function wpinv_upload_callback($args) {
832 832
 	global $wpinv_options;
833 833
     
834
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
834
+    $sanitize_id = wpinv_sanitize_key($args['id']);
835 835
 
836
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
836
+	if (isset($wpinv_options[$args['id']])) {
837 837
 		$value = $wpinv_options[$args['id']];
838 838
 	} else {
839 839
 		$value = isset($args['std']) ? $args['std'] : '';
840 840
 	}
841 841
 
842
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
843
-	$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 ) ) . '"/>';
844
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
845
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
842
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
843
+	$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)) . '"/>';
844
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
845
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
846 846
 
847 847
 	echo $html;
848 848
 }
849 849
 
850
-function wpinv_color_callback( $args ) {
850
+function wpinv_color_callback($args) {
851 851
 	global $wpinv_options;
852 852
     
853
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
853
+    $sanitize_id = wpinv_sanitize_key($args['id']);
854 854
 
855
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
856
-		$value = $wpinv_options[ $args['id'] ];
855
+	if (isset($wpinv_options[$args['id']])) {
856
+		$value = $wpinv_options[$args['id']];
857 857
 	} else {
858
-		$value = isset( $args['std'] ) ? $args['std'] : '';
858
+		$value = isset($args['std']) ? $args['std'] : '';
859 859
 	}
860 860
 
861
-	$default = isset( $args['std'] ) ? $args['std'] : '';
861
+	$default = isset($args['std']) ? $args['std'] : '';
862 862
 
863
-	$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 ) . '" />';
864
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
863
+	$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) . '" />';
864
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
865 865
 
866 866
 	echo $html;
867 867
 }
@@ -869,9 +869,9 @@  discard block
 block discarded – undo
869 869
 function wpinv_country_states_callback($args) {
870 870
 	global $wpinv_options;
871 871
     
872
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
872
+    $sanitize_id = wpinv_sanitize_key($args['id']);
873 873
 
874
-	if ( isset( $args['placeholder'] ) ) {
874
+	if (isset($args['placeholder'])) {
875 875
 		$placeholder = $args['placeholder'];
876 876
 	} else {
877 877
 		$placeholder = '';
@@ -879,16 +879,16 @@  discard block
 block discarded – undo
879 879
 
880 880
 	$states = wpinv_get_country_states();
881 881
 
882
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
883
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
882
+	$class = empty($states) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
883
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
884 884
 
885
-	foreach ( $states as $option => $name ) {
886
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
887
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
885
+	foreach ($states as $option => $name) {
886
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
887
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
888 888
 	}
889 889
 
890 890
 	$html .= '</select>';
891
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
891
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
892 892
 
893 893
 	echo $html;
894 894
 }
@@ -903,96 +903,96 @@  discard block
 block discarded – undo
903 903
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
904 904
 		<thead>
905 905
 			<tr>
906
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
907
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
908
-                <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>
909
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
910
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
911
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
906
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
907
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
908
+                <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>
909
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
910
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
911
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
912 912
 			</tr>
913 913
 		</thead>
914 914
         <tbody>
915
-		<?php if( !empty( $rates ) ) : ?>
916
-			<?php foreach( $rates as $key => $rate ) : ?>
915
+		<?php if (!empty($rates)) : ?>
916
+			<?php foreach ($rates as $key => $rate) : ?>
917 917
             <?php 
918
-            $sanitized_key = wpinv_sanitize_key( $key );
918
+            $sanitized_key = wpinv_sanitize_key($key);
919 919
             ?>
920 920
 			<tr>
921 921
 				<td class="wpinv_tax_country">
922 922
 					<?php
923
-					echo wpinv_html_select( array(
924
-						'options'          => wpinv_get_country_list( true ),
923
+					echo wpinv_html_select(array(
924
+						'options'          => wpinv_get_country_list(true),
925 925
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
926 926
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
927 927
 						'selected'         => $rate['country'],
928 928
 						'show_option_all'  => false,
929 929
 						'show_option_none' => false,
930 930
 						'class'            => 'wpinv-tax-country wpi_select2',
931
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
932
-					) );
931
+						'placeholder'      => __('Choose a country', 'invoicing')
932
+					));
933 933
 					?>
934 934
 				</td>
935 935
 				<td class="wpinv_tax_state">
936 936
 					<?php
937
-					$states = wpinv_get_country_states( $rate['country'] );
938
-					if( !empty( $states ) ) {
939
-						echo wpinv_html_select( array(
940
-							'options'          => array_merge( array( '' => '' ), $states ),
937
+					$states = wpinv_get_country_states($rate['country']);
938
+					if (!empty($states)) {
939
+						echo wpinv_html_select(array(
940
+							'options'          => array_merge(array('' => ''), $states),
941 941
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
942 942
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
943 943
 							'selected'         => $rate['state'],
944 944
 							'show_option_all'  => false,
945 945
 							'show_option_none' => false,
946 946
                             'class'            => 'wpi_select2',
947
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
948
-						) );
947
+							'placeholder'      => __('Choose a state', 'invoicing')
948
+						));
949 949
 					} else {
950
-						echo wpinv_html_text( array(
950
+						echo wpinv_html_text(array(
951 951
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
952
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
952
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
953 953
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
954
-						) );
954
+						));
955 955
 					}
956 956
 					?>
957 957
 				</td>
958 958
 				<td class="wpinv_tax_global">
959
-					<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'] ) ); ?>/>
960
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
959
+					<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'])); ?>/>
960
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
961 961
 				</td>
962
-				<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>
963
-                <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>
964
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
962
+				<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>
963
+                <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>
964
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
965 965
 			</tr>
966 966
 			<?php endforeach; ?>
967 967
 		<?php else : ?>
968 968
 			<tr>
969 969
 				<td class="wpinv_tax_country">
970 970
 					<?php
971
-					echo wpinv_html_select( array(
972
-						'options'          => wpinv_get_country_list( true ),
971
+					echo wpinv_html_select(array(
972
+						'options'          => wpinv_get_country_list(true),
973 973
 						'name'             => 'tax_rates[0][country]',
974 974
 						'show_option_all'  => false,
975 975
 						'show_option_none' => false,
976 976
 						'class'            => 'wpinv-tax-country wpi_select2',
977
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
978
-					) ); ?>
977
+						'placeholder'      => __('Choose a country', 'invoicing')
978
+					)); ?>
979 979
 				</td>
980 980
 				<td class="wpinv_tax_state">
981
-					<?php echo wpinv_html_text( array(
981
+					<?php echo wpinv_html_text(array(
982 982
 						'name' => 'tax_rates[0][state]'
983
-					) ); ?>
983
+					)); ?>
984 984
 				</td>
985 985
 				<td class="wpinv_tax_global">
986 986
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
987
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
987
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
988 988
 				</td>
989
-				<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>
989
+				<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>
990 990
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
991
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
991
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
992 992
 			</tr>
993 993
 		<?php endif; ?>
994 994
         </tbody>
995
-        <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>
995
+        <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>
996 996
 	</table>
997 997
 	<?php
998 998
 	echo ob_get_clean();
@@ -1003,76 +1003,76 @@  discard block
 block discarded – undo
1003 1003
     ob_start(); ?>
1004 1004
     </td><tr>
1005 1005
     <td colspan="2" class="wpinv_tools_tdbox">
1006
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1007
-    <?php do_action( 'wpinv_tools_before' ); ?>
1006
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1007
+    <?php do_action('wpinv_tools_before'); ?>
1008 1008
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1009 1009
         <thead>
1010 1010
             <tr>
1011
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1012
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1013
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1011
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1012
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1013
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1014 1014
             </tr>
1015 1015
         </thead>
1016
-            <?php do_action( 'wpinv_tools_row' ); ?>
1016
+            <?php do_action('wpinv_tools_row'); ?>
1017 1017
         <tbody>
1018 1018
         </tbody>
1019 1019
     </table>
1020
-    <?php do_action( 'wpinv_tools_after' ); ?>
1020
+    <?php do_action('wpinv_tools_after'); ?>
1021 1021
     <?php
1022 1022
     echo ob_get_clean();
1023 1023
 }
1024 1024
 
1025
-function wpinv_descriptive_text_callback( $args ) {
1026
-	echo wp_kses_post( $args['desc'] );
1025
+function wpinv_descriptive_text_callback($args) {
1026
+	echo wp_kses_post($args['desc']);
1027 1027
 }
1028 1028
 
1029
-function wpinv_hook_callback( $args ) {
1030
-	do_action( 'wpinv_' . $args['id'], $args );
1029
+function wpinv_hook_callback($args) {
1030
+	do_action('wpinv_' . $args['id'], $args);
1031 1031
 }
1032 1032
 
1033 1033
 function wpinv_set_settings_cap() {
1034 1034
 	return wpinv_get_capability();
1035 1035
 }
1036
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1036
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1037 1037
 
1038
-function wpinv_settings_sanitize_input( $value, $key ) {
1039
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1040
-        $value = wpinv_sanitize_amount( $value, 4 );
1038
+function wpinv_settings_sanitize_input($value, $key) {
1039
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1040
+        $value = wpinv_sanitize_amount($value, 4);
1041 1041
         $value = $value >= 100 ? 99 : $value;
1042 1042
     }
1043 1043
         
1044 1044
     return $value;
1045 1045
 }
1046
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1046
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1047 1047
 
1048
-function wpinv_on_update_settings( $old_value, $value, $option ) {
1049
-    $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : '';
1050
-    $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : '';
1048
+function wpinv_on_update_settings($old_value, $value, $option) {
1049
+    $old = !empty($old_value['remove_data_on_unistall']) ? 1 : '';
1050
+    $new = !empty($value['remove_data_on_unistall']) ? 1 : '';
1051 1051
     
1052
-    if ( $old != $new ) {
1053
-        update_option( 'wpinv_remove_data_on_invoice_unistall', $new );
1052
+    if ($old != $new) {
1053
+        update_option('wpinv_remove_data_on_invoice_unistall', $new);
1054 1054
     }
1055 1055
 }
1056
-add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 );
1057
-add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1058
-add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1059
-add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1060
-add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1061
-add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1062
-add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1063
-add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1064
-add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1065
-add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1066
-add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1067
-
1068
-function wpinv_settings_tab_bottom_emails( $active_tab, $section ) {
1056
+add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3);
1057
+add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1058
+add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1059
+add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1060
+add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1061
+add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1062
+add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1063
+add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1064
+add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1065
+add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2);
1066
+add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2);
1067
+
1068
+function wpinv_settings_tab_bottom_emails($active_tab, $section) {
1069 1069
     ?>
1070 1070
     <div class="wpinv-email-wc-row ">
1071 1071
         <div class="wpinv-email-wc-td">
1072
-            <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3>
1072
+            <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3>
1073 1073
             <p class="wpinv-email-wc-description">
1074 1074
                 <?php
1075
-                $description = __( 'The following wildcards can be used in email subjects, heading and content:<br>
1075
+                $description = __('The following wildcards can be used in email subjects, heading and content:<br>
1076 1076
                     <strong>{site_title} :</strong> Site Title<br>
1077 1077
                     <strong>{name} :</strong> Customer\'s full name<br>
1078 1078
                     <strong>{first_name} :</strong> Customer\'s first name<br>
@@ -1086,7 +1086,7 @@  discard block
 block discarded – undo
1086 1086
                     <strong>{invoice_due_date} :</strong> The date the invoice is due<br>
1087 1087
                     <strong>{date} :</strong> Today\'s date.<br>
1088 1088
                     <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br>
1089
-                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' );
1089
+                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing');
1090 1090
                 echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section);
1091 1091
                 ?>
1092 1092
             </p>
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +624 added lines, -624 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 class WPInv_EUVat {
10 10
 
@@ -24,128 +24,128 @@  discard block
 block discarded – undo
24 24
     public function init() {
25 25
 
26 26
         // If this is an admin page...
27
-        if ( is_admin() ) {
27
+        if (is_admin()) {
28 28
 
29 29
             // Register our scripts.
30
-            add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
31
-            add_action( 'wpinv_settings_sections_taxes', array( $this, 'section_vat_settings' ) );
32
-            add_action( 'wpinv_settings_taxes', array( $this, 'vat_settings' ) );
33
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( $this, 'sanitize_vat_settings' ) );
34
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( $this, 'sanitize_vat_rates' ) );
35
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( $this, 'add_class' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( $this, 'add_class' ) );
37
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( $this, 'delete_class' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( $this, 'delete_class' ) );
39
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( $this, 'update_eu_rates' ) );
40
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( $this, 'update_eu_rates' ) );
41
-            add_action( 'wp_ajax_wpinv_geoip2', array( $this, 'geoip2_download_database' ) );
42
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( $this, 'geoip2_download_database' ) );
30
+            add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_scripts'));
31
+            add_action('wpinv_settings_sections_taxes', array($this, 'section_vat_settings'));
32
+            add_action('wpinv_settings_taxes', array($this, 'vat_settings'));
33
+            add_filter('wpinv_settings_taxes-vat_sanitize', array($this, 'sanitize_vat_settings'));
34
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array($this, 'sanitize_vat_rates'));
35
+            add_action('wp_ajax_wpinv_add_vat_class', array($this, 'add_class'));
36
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array($this, 'add_class'));
37
+            add_action('wp_ajax_wpinv_delete_vat_class', array($this, 'delete_class'));
38
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array($this, 'delete_class'));
39
+            add_action('wp_ajax_wpinv_update_vat_rates', array($this, 'update_eu_rates'));
40
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array($this, 'update_eu_rates'));
41
+            add_action('wp_ajax_wpinv_geoip2', array($this, 'geoip2_download_database'));
42
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array($this, 'geoip2_download_database'));
43 43
         }
44 44
 
45
-        add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_vat_scripts' ) );
46
-        add_filter( 'wpinv_default_billing_country', array( $this, 'get_user_country' ), 10 );
47
-        add_filter( 'wpinv_get_user_country', array( $this, 'set_user_country' ), 10 );
48
-        add_action( 'wp_ajax_wpinv_vat_validate', array( $this, 'ajax_vat_validate' ) );
49
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( $this, 'ajax_vat_validate' ) );
45
+        add_action('wp_enqueue_scripts', array($this, 'enqueue_vat_scripts'));
46
+        add_filter('wpinv_default_billing_country', array($this, 'get_user_country'), 10);
47
+        add_filter('wpinv_get_user_country', array($this, 'set_user_country'), 10);
48
+        add_action('wp_ajax_wpinv_vat_validate', array($this, 'ajax_vat_validate'));
49
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array($this, 'ajax_vat_validate'));
50 50
 
51
-        if ( wpinv_use_taxes() && self::allow_vat_rules() ) {
52
-            add_filter( 'wpinv_tax_rate', array( $this, 'get_rate' ), 10, 4 );
51
+        if (wpinv_use_taxes() && self::allow_vat_rules()) {
52
+            add_filter('wpinv_tax_rate', array($this, 'get_rate'), 10, 4);
53 53
         }
54 54
     }
55 55
 
56
-    public static function get_eu_states( $sort = true ) {
57
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
58
-        if ( $sort ) {
59
-            $sort = sort( $eu_states );
56
+    public static function get_eu_states($sort = true) {
57
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
58
+        if ($sort) {
59
+            $sort = sort($eu_states);
60 60
         }
61 61
 
62
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
62
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
63 63
     }
64 64
 
65
-    public static function get_gst_countries( $sort = true ) {
66
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
65
+    public static function get_gst_countries($sort = true) {
66
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
67 67
 
68
-        if ( $sort ) {
69
-            $sort = sort( $gst_countries );
68
+        if ($sort) {
69
+            $sort = sort($gst_countries);
70 70
         }
71 71
 
72
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
72
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
73 73
     }
74 74
 
75
-    public static function is_eu_state( $country_code ) {
76
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
75
+    public static function is_eu_state($country_code) {
76
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
77 77
 
78
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
78
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
79 79
     }
80 80
 
81
-    public static function is_gst_country( $country_code ) {
82
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
81
+    public static function is_gst_country($country_code) {
82
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
83 83
 
84
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
84
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
85 85
     }
86 86
 
87 87
     public function enqueue_vat_scripts() {
88
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
88
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
89 89
             $this->load_vat_scripts();
90 90
         }
91 91
     }
92 92
 
93
-    public function load_vat_scripts(){
94
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
93
+    public function load_vat_scripts() {
94
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95 95
 
96
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
97
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
96
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
97
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
98 98
 
99
-        $vat_name   = $this->get_vat_name();
99
+        $vat_name = $this->get_vat_name();
100 100
 
101 101
         $vars = array();
102 102
         $vars['UseTaxes'] = wpinv_use_taxes();
103 103
         $vars['EUStates'] = self::get_eu_states();
104
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
105
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
106
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
107
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
108
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
109
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
110
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
111
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
104
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
105
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
106
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
107
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
108
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
109
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
110
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
111
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
112 112
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
113 113
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
114
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
115
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
116
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
117
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
118
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
119
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
120
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
121
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
122
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
123
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
124
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
125
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
126
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
114
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
115
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
116
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
117
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
118
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
119
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
120
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
121
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
122
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
123
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
124
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
125
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
126
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
127 127
         $vars['isFront'] = is_admin() ? false : true;
128 128
         $vars['baseCountry'] = wpinv_get_default_country();
129
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
130
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
129
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
130
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
131 131
 
132
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
133
-        wp_enqueue_script( 'wpinv-vat-script' );
134
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
132
+        wp_enqueue_script('wpinv-vat-validation-script');
133
+        wp_enqueue_script('wpinv-vat-script');
134
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
135 135
     }
136 136
 
137 137
     public static function enqueue_admin_scripts() {
138
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
138
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
139 139
             self::load_vat_scripts();
140 140
         }
141 141
     }
142 142
 
143
-    public static function section_vat_settings( $sections ) {
144
-        if ( !empty( $sections ) ) {
145
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
143
+    public static function section_vat_settings($sections) {
144
+        if (!empty($sections)) {
145
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
146 146
 
147
-            if ( self::allow_vat_classes() ) {
148
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
147
+            if (self::allow_vat_classes()) {
148
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
149 149
             }
150 150
         }
151 151
         return $sections;
@@ -154,52 +154,52 @@  discard block
 block discarded – undo
154 154
     public static function vat_rates_settings() {
155 155
         $vat_classes = self::get_rate_classes();
156 156
         $vat_rates = array();
157
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
158
-        $current_url = remove_query_arg( 'wpi_sub' );
157
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
158
+        $current_url = remove_query_arg('wpi_sub');
159 159
 
160 160
         $vat_rates['vat_rates_header'] = array(
161 161
             'id' => 'vat_rates_header',
162
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
162
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
163 163
             'desc' => '',
164 164
             'type' => 'header',
165 165
             'size' => 'regular'
166 166
         );
167 167
         $vat_rates['vat_rates_class'] = array(
168 168
             'id'          => 'vat_rates_class',
169
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
170
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
169
+            'name'        => __('Edit VAT Rates', 'invoicing'),
170
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
171 171
             'type'        => 'select',
172
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
173
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
172
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
173
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
174 174
             'selected'    => $vat_class,
175 175
             'class'       => 'wpi_select2',
176 176
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
177 177
         );
178 178
 
179
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
179
+        if ($vat_class != '_standard' && $vat_class != '_new') {
180 180
             $vat_rates['vat_rate_delete'] = array(
181 181
                 'id'   => 'vat_rate_delete',
182 182
                 'type' => 'vat_rate_delete',
183 183
             );
184 184
         }
185 185
 
186
-        if ( $vat_class == '_new' ) {
186
+        if ($vat_class == '_new') {
187 187
             $vat_rates['vat_rates_settings'] = array(
188 188
                 'id' => 'vat_rates_settings',
189
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
189
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
190 190
                 'type' => 'header',
191 191
             );
192 192
             $vat_rates['vat_rate_name'] = array(
193 193
                 'id'   => 'vat_rate_name',
194
-                'name' => __( 'Name', 'invoicing' ),
195
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
194
+                'name' => __('Name', 'invoicing'),
195
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
196 196
                 'type' => 'text',
197 197
                 'size' => 'regular',
198 198
             );
199 199
             $vat_rates['vat_rate_desc'] = array(
200 200
                 'id'   => 'vat_rate_desc',
201
-                'name' => __( 'Description', 'invoicing' ),
202
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
201
+                'name' => __('Description', 'invoicing'),
202
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
203 203
                 'type' => 'text',
204 204
                 'size' => 'regular',
205 205
             );
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
             $vat_rates['vat_rates'] = array(
212 212
                 'id'   => 'vat_rates',
213 213
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
214
-                'desc' => self::get_class_desc( $vat_class ),
214
+                'desc' => self::get_class_desc($vat_class),
215 215
                 'type' => 'vat_rates',
216 216
             );
217 217
         }
@@ -219,12 +219,12 @@  discard block
 block discarded – undo
219 219
         return $vat_rates;
220 220
     }
221 221
 
222
-    public static function vat_settings( $settings ) {
223
-        if ( !empty( $settings ) ) {
222
+    public static function vat_settings($settings) {
223
+        if (!empty($settings)) {
224 224
             $vat_settings = array();
225 225
             $vat_settings['vat_company_title'] = array(
226 226
                 'id' => 'vat_company_title',
227
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
227
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
228 228
                 'desc' => '',
229 229
                 'type' => 'header',
230 230
                 'size' => 'regular'
@@ -232,22 +232,22 @@  discard block
 block discarded – undo
232 232
 
233 233
             $vat_settings['vat_company_name'] = array(
234 234
                 'id' => 'vat_company_name',
235
-                'name' => __( 'Your Company Name', 'invoicing' ),
236
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
235
+                'name' => __('Your Company Name', 'invoicing'),
236
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
237 237
                 'type' => 'text',
238 238
                 'size' => 'regular',
239 239
             );
240 240
 
241 241
             $vat_settings['vat_number'] = array(
242 242
                 'id'   => 'vat_number',
243
-                'name' => __( 'Your VAT Number', 'invoicing' ),
243
+                'name' => __('Your VAT Number', 'invoicing'),
244 244
                 'type' => 'vat_number',
245 245
                 'size' => 'regular',
246 246
             );
247 247
 
248 248
             $vat_settings['vat_settings_title'] = array(
249 249
                 'id' => 'vat_settings_title',
250
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
250
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
251 251
                 'desc' => '',
252 252
                 'type' => 'header',
253 253
                 'size' => 'regular'
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 
256 256
             $vat_settings['apply_vat_rules'] = array(
257 257
                 'id' => 'apply_vat_rules',
258
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
259
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
258
+                'name' => __('Enable VAT Rules', 'invoicing'),
259
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
260 260
                 'type' => 'checkbox',
261 261
                 'std' => '1'
262 262
             );
@@ -272,8 +272,8 @@  discard block
 block discarded – undo
272 272
 
273 273
             $vat_settings['vat_prevent_b2c_purchase'] = array(
274 274
                 'id' => 'vat_prevent_b2c_purchase',
275
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
276
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
275
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
276
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
277 277
                 'type' => 'checkbox'
278 278
             );
279 279
 
@@ -281,22 +281,22 @@  discard block
 block discarded – undo
281 281
 
282 282
             $vat_settings['vat_same_country_rule'] = array(
283 283
                 'id'          => 'vat_same_country_rule',
284
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
285
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
284
+                'name'        => __('Same Country Rule', 'invoicing'),
285
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
286 286
                 'type'        => 'select',
287 287
                 'options'     => array(
288
-                    ''          => __( 'Normal', 'invoicing' ),
289
-                    'no'        => __( 'No VAT', 'invoicing' ),
290
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
288
+                    ''          => __('Normal', 'invoicing'),
289
+                    'no'        => __('No VAT', 'invoicing'),
290
+                    'always'    => __('Always apply VAT', 'invoicing'),
291 291
                 ),
292
-                'placeholder' => __( 'Select an option', 'invoicing' ),
292
+                'placeholder' => __('Select an option', 'invoicing'),
293 293
                 'std'         => '',
294 294
                 'class'   => 'wpi_select2',
295 295
             );
296 296
 
297 297
             $vat_settings['vat_checkout_title'] = array(
298 298
                 'id' => 'vat_checkout_title',
299
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
299
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
300 300
                 'desc' => '',
301 301
                 'type' => 'header',
302 302
                 'size' => 'regular'
@@ -304,22 +304,22 @@  discard block
 block discarded – undo
304 304
 
305 305
             $vat_settings['vat_disable_fields'] = array(
306 306
                 'id' => 'vat_disable_fields',
307
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
308
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
307
+                'name' => __('Disable VAT Fields', 'invoicing'),
308
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
309 309
                 'type' => 'checkbox'
310 310
             );
311 311
 
312 312
             $vat_settings['maxmind_license_key'] = array(
313 313
                 'id'   => 'maxmind_license_key',
314
-                'name' => __( 'MaxMind License Key', 'invoicing' ),
314
+                'name' => __('MaxMind License Key', 'invoicing'),
315 315
                 'type' => 'text',
316 316
                 'size' => 'regular',
317
-                'desc' => '<a href="https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/">' . __( 'The key that will be used when dealing with MaxMind Geolocation services.', 'invoicing' ) . '</a>',
317
+                'desc' => '<a href="https://support.maxmind.com/account-faq/license-keys/how-do-i-generate-a-license-key/">' . __('The key that will be used when dealing with MaxMind Geolocation services.', 'invoicing') . '</a>',
318 318
             );
319 319
 
320 320
             $vat_settings['vat_ip_lookup'] = array(
321 321
                 'id'   => 'vat_ip_lookup',
322
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
322
+                'name' => __('IP Country Look-up', 'invoicing'),
323 323
                 'type' => 'vat_ip_lookup',
324 324
                 'size' => 'regular',
325 325
                 'std' => 'default',
@@ -328,14 +328,14 @@  discard block
 block discarded – undo
328 328
 
329 329
             $vat_settings['vat_ip_country_default'] = array(
330 330
                 'id' => 'vat_ip_country_default',
331
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
332
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
331
+                'name' => __('Enable IP Country as Default', 'invoicing'),
332
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
333 333
                 'type' => 'checkbox'
334 334
             );
335 335
 
336 336
             $vat_settings['vies_validation_title'] = array(
337 337
                 'id' => 'vies_validation_title',
338
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
338
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
339 339
                 'desc' => '',
340 340
                 'type' => 'header',
341 341
                 'size' => 'regular'
@@ -343,37 +343,37 @@  discard block
 block discarded – undo
343 343
 
344 344
             $vat_settings['vat_vies_check'] = array(
345 345
                 'id' => 'vat_vies_check',
346
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
347
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
346
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
347
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
348 348
                 'type' => 'checkbox'
349 349
             );
350 350
 
351 351
             $vat_settings['vat_disable_company_name_check'] = array(
352 352
                 'id' => 'vat_disable_company_name_check',
353
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
354
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
353
+                'name' => __('Disable VIES Name Check', 'invoicing'),
354
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
355 355
                 'type' => 'checkbox'
356 356
             );
357 357
 
358 358
             $vat_settings['vat_offline_check'] = array(
359 359
                 'id' => 'vat_offline_check',
360
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
361
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
360
+                'name' => __('Disable Basic Checks', 'invoicing'),
361
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
362 362
                 'type' => 'checkbox'
363 363
             );
364 364
 
365 365
 
366 366
             $settings['vat'] = $vat_settings;
367 367
 
368
-            if ( self::allow_vat_classes() ) {
368
+            if (self::allow_vat_classes()) {
369 369
                 $settings['vat_rates'] = self::vat_rates_settings();
370 370
             }
371 371
 
372 372
             $eu_fallback_rate = array(
373 373
                 'id'   => 'eu_fallback_rate',
374
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
374
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
375 375
                 'type' => 'eu_fallback_rate',
376
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
376
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
377 377
                 'std'  => '20',
378 378
                 'size' => 'small'
379 379
             );
@@ -388,7 +388,7 @@  discard block
 block discarded – undo
388 388
      */
389 389
     public static function maxmind_folder() {
390 390
 
391
-        $upload_dir      = wp_upload_dir();
391
+        $upload_dir = wp_upload_dir();
392 392
         return $upload_dir['basedir'] . '/invoicing';
393 393
 
394 394
     }
@@ -405,39 +405,39 @@  discard block
 block discarded – undo
405 405
 		WP_Filesystem();
406 406
         global $wp_filesystem;
407 407
 
408
-        $license_key = wpinv_get_option( 'maxmind_license_key' );
408
+        $license_key = wpinv_get_option('maxmind_license_key');
409 409
 
410
-        if ( empty( $license_key ) ) {
411
-            echo __( 'Please enter your MaxMind license key then save the settings first before downloading the databases.', 'invoicing' );
410
+        if (empty($license_key)) {
411
+            echo __('Please enter your MaxMind license key then save the settings first before downloading the databases.', 'invoicing');
412 412
             exit;
413 413
         }
414 414
 
415 415
         // The database files that we will download.
416
-        $database_files     = array( 'GeoLite2-Country', 'GeoLite2-City' );
416
+        $database_files = array('GeoLite2-Country', 'GeoLite2-City');
417 417
 
418 418
         // The destination dir of all databases.
419 419
         $destination_dir = self::maxmind_folder();
420 420
 
421
-        if ( ! $wp_filesystem->is_dir( $destination_dir ) ) {
422
-            $wp_filesystem->mkdir( $destination_dir );
421
+        if (!$wp_filesystem->is_dir($destination_dir)) {
422
+            $wp_filesystem->mkdir($destination_dir);
423 423
         }
424 424
 
425
-        foreach( $database_files as $database ) {
425
+        foreach ($database_files as $database) {
426 426
 
427
-            $database_path = self::geoip2_download_file( $license_key, $database );
428
-            $target_path   = trailingslashit( $destination_dir ) .  $database . '.mmdb';
427
+            $database_path = self::geoip2_download_file($license_key, $database);
428
+            $target_path   = trailingslashit($destination_dir) . $database . '.mmdb';
429 429
 
430
-            if ( is_wp_error( $database_path ) ) {
430
+            if (is_wp_error($database_path)) {
431 431
                 echo $database_path->get_error_message();
432 432
                 exit;
433 433
             }
434 434
 
435 435
             // Move the new database into position.
436
-		    $wp_filesystem->move( $database_path, $target_path, true );
437
-            $wp_filesystem->delete( dirname( $database_path ) );
436
+		    $wp_filesystem->move($database_path, $target_path, true);
437
+            $wp_filesystem->delete(dirname($database_path));
438 438
 
439
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
440
-            echo sprintf( __( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
439
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
440
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
441 441
         }
442 442
 
443 443
         exit;
@@ -448,12 +448,12 @@  discard block
 block discarded – undo
448 448
      *
449 449
      * @return string|WP_Error
450 450
      */
451
-    public static function geoip2_download_file( $license_key, $database ) {
451
+    public static function geoip2_download_file($license_key, $database) {
452 452
 
453 453
         // The download URI of the database.
454 454
         $source_url = add_query_arg(
455 455
 			array(
456
-                'license_key' => urlencode( sanitize_text_field( $license_key ) ),
456
+                'license_key' => urlencode(sanitize_text_field($license_key)),
457 457
                 'edition_id'  => $database,
458 458
 				'suffix'      => 'tar.gz',
459 459
 			),
@@ -464,54 +464,54 @@  discard block
 block discarded – undo
464 464
 		require_once ABSPATH . 'wp-admin/includes/file.php';
465 465
 
466 466
         // Download the file.
467
-        $tmp_archive_path = download_url( esc_url_raw( $source_url ) );
467
+        $tmp_archive_path = download_url(esc_url_raw($source_url));
468 468
 
469 469
         // Did we encounter an error?
470
-        if ( is_wp_error( $tmp_archive_path ) ) {
470
+        if (is_wp_error($tmp_archive_path)) {
471 471
 
472 472
             // Transform the error into something more informative.
473 473
 			$error_data = $tmp_archive_path->get_error_data();
474
-			if ( isset( $error_data['code'] ) ) {
475
-				switch ( $error_data['code'] ) {
474
+			if (isset($error_data['code'])) {
475
+				switch ($error_data['code']) {
476 476
 					case 401:
477 477
 						return new WP_Error(
478 478
 							'invoicing_maxmind_geolocation_database_license_key',
479
-							__( 'The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing' )
479
+							__('The MaxMind license key is invalid. If you have recently created this key, you may need to wait for it to become active.', 'invoicing')
480 480
 						);
481 481
 				}
482 482
 			}
483 483
 
484
-            return new WP_Error( 'invoicing_maxmind_geolocation_database_download', __( 'Failed to download the MaxMind database.', 'invoicing' ) );
484
+            return new WP_Error('invoicing_maxmind_geolocation_database_download', __('Failed to download the MaxMind database.', 'invoicing'));
485 485
 
486 486
         }
487 487
 
488 488
         // Extract the database from the archive.
489 489
         try {
490
-			$file      = new PharData( $tmp_archive_path );
491
-            $file_path = trailingslashit( dirname( $tmp_archive_path ) ) . trailingslashit( $file->current()->getFilename() ) . $database . '.mmdb';
490
+			$file = new PharData($tmp_archive_path);
491
+            $file_path = trailingslashit(dirname($tmp_archive_path)) . trailingslashit($file->current()->getFilename()) . $database . '.mmdb';
492 492
 
493 493
 			$file->extractTo(
494
-				dirname( $tmp_archive_path ),
495
-				trailingslashit( $file->current()->getFilename() ) . $database . '.mmdb',
494
+				dirname($tmp_archive_path),
495
+				trailingslashit($file->current()->getFilename()) . $database . '.mmdb',
496 496
 				true
497 497
             );
498 498
 
499
-		} catch ( Exception $exception ) {
500
-			return new WP_Error( 'invoicing_maxmind_geolocation_database_archive', $exception->getMessage() );
499
+		} catch (Exception $exception) {
500
+			return new WP_Error('invoicing_maxmind_geolocation_database_archive', $exception->getMessage());
501 501
 		} finally {
502 502
 			// Remove the archive since we only care about a single file in it.
503
-            unlink( $tmp_archive_path );
503
+            unlink($tmp_archive_path);
504 504
         }
505 505
 
506 506
         return $file_path;
507 507
     }
508 508
 
509 509
     public static function load_geoip2() {
510
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
510
+        if (defined('WPINV_GEOIP2_LODDED')) {
511 511
             return;
512 512
         }
513 513
 
514
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
514
+        if (!class_exists('\MaxMind\Db\Reader')) {
515 515
             $maxmind_db_files = array(
516 516
                 'Reader/Decoder.php',
517 517
                 'Reader/InvalidDatabaseException.php',
@@ -520,12 +520,12 @@  discard block
 block discarded – undo
520 520
                 'Reader.php',
521 521
             );
522 522
 
523
-            foreach ( $maxmind_db_files as $key => $file ) {
524
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
523
+            foreach ($maxmind_db_files as $key => $file) {
524
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
525 525
             }
526 526
         }
527 527
 
528
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {
528
+        if (!class_exists('\GeoIp2\Database\Reader')) {
529 529
             $geoip2_files = array(
530 530
                 'ProviderInterface.php',
531 531
                 'Compat/JsonSerializable.php',
@@ -559,23 +559,23 @@  discard block
 block discarded – undo
559 559
                 'WebService/Client.php',
560 560
             );
561 561
 
562
-            foreach ( $geoip2_files as $key => $file ) {
563
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
562
+            foreach ($geoip2_files as $key => $file) {
563
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
564 564
             }
565 565
         }
566 566
 
567
-        define( 'WPINV_GEOIP2_LODDED', true );
567
+        define('WPINV_GEOIP2_LODDED', true);
568 568
     }
569 569
 
570 570
     public static function geoip2_country_dbfile() {
571 571
         $upload_dir = wp_upload_dir();
572 572
 
573
-        if ( !isset( $upload_dir['basedir'] ) ) {
573
+        if (!isset($upload_dir['basedir'])) {
574 574
             return false;
575 575
         }
576 576
 
577 577
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
578
-        if ( !file_exists( $filename ) ) {
578
+        if (!file_exists($filename)) {
579 579
             return false;
580 580
         }
581 581
 
@@ -585,12 +585,12 @@  discard block
 block discarded – undo
585 585
     public static function geoip2_city_dbfile() {
586 586
         $upload_dir = wp_upload_dir();
587 587
 
588
-        if ( !isset( $upload_dir['basedir'] ) ) {
588
+        if (!isset($upload_dir['basedir'])) {
589 589
             return false;
590 590
         }
591 591
 
592 592
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
593
-        if ( !file_exists( $filename ) ) {
593
+        if (!file_exists($filename)) {
594 594
             return false;
595 595
         }
596 596
 
@@ -601,10 +601,10 @@  discard block
 block discarded – undo
601 601
         try {
602 602
             self::load_geoip2();
603 603
 
604
-            if ( $filename = self::geoip2_country_dbfile() ) {
605
-                return new \GeoIp2\Database\Reader( $filename );
604
+            if ($filename = self::geoip2_country_dbfile()) {
605
+                return new \GeoIp2\Database\Reader($filename);
606 606
             }
607
-        } catch( Exception $e ) {
607
+        } catch (Exception $e) {
608 608
             return false;
609 609
         }
610 610
 
@@ -615,183 +615,183 @@  discard block
 block discarded – undo
615 615
         try {
616 616
             self::load_geoip2();
617 617
 
618
-            if ( $filename = self::geoip2_city_dbfile() ) {
619
-                return new \GeoIp2\Database\Reader( $filename );
618
+            if ($filename = self::geoip2_city_dbfile()) {
619
+                return new \GeoIp2\Database\Reader($filename);
620 620
             }
621
-        } catch( Exception $e ) {
621
+        } catch (Exception $e) {
622 622
             return false;
623 623
         }
624 624
 
625 625
         return false;
626 626
     }
627 627
 
628
-    public static function geoip2_country_record( $ip_address ) {
628
+    public static function geoip2_country_record($ip_address) {
629 629
         try {
630 630
             $reader = self::geoip2_country_reader();
631 631
 
632
-            if ( $reader ) {
633
-                $record = $reader->country( $ip_address );
632
+            if ($reader) {
633
+                $record = $reader->country($ip_address);
634 634
 
635
-                if ( !empty( $record->country->isoCode ) ) {
635
+                if (!empty($record->country->isoCode)) {
636 636
                     return $record;
637 637
                 }
638 638
             }
639
-        } catch(\InvalidArgumentException $e) {
640
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
639
+        } catch (\InvalidArgumentException $e) {
640
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
641 641
 
642 642
             return false;
643
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
644
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
643
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
644
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
645 645
 
646 646
             return false;
647
-        } catch( Exception $e ) {
647
+        } catch (Exception $e) {
648 648
             return false;
649 649
         }
650 650
 
651 651
         return false;
652 652
     }
653 653
 
654
-    public static function geoip2_city_record( $ip_address ) {
654
+    public static function geoip2_city_record($ip_address) {
655 655
         try {
656 656
             $reader = self::geoip2_city_reader();
657 657
 
658
-            if ( $reader ) {
659
-                $record = $reader->city( $ip_address );
658
+            if ($reader) {
659
+                $record = $reader->city($ip_address);
660 660
 
661
-                if ( !empty( $record->country->isoCode ) ) {
661
+                if (!empty($record->country->isoCode)) {
662 662
                     return $record;
663 663
                 }
664 664
             }
665
-        } catch(\InvalidArgumentException $e) {
666
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
665
+        } catch (\InvalidArgumentException $e) {
666
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
667 667
 
668 668
             return false;
669
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
670
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
669
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
670
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
671 671
 
672 672
             return false;
673
-        } catch( Exception $e ) {
673
+        } catch (Exception $e) {
674 674
             return false;
675 675
         }
676 676
 
677 677
         return false;
678 678
     }
679 679
 
680
-    public static function geoip2_country_code( $ip_address ) {
681
-        $record = self::geoip2_country_record( $ip_address );
682
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
680
+    public static function geoip2_country_code($ip_address) {
681
+        $record = self::geoip2_country_record($ip_address);
682
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
683 683
     }
684 684
 
685 685
     // Find country by IP address.
686
-    public static function get_country_by_ip( $ip = '' ) {
686
+    public static function get_country_by_ip($ip = '') {
687 687
         global $wpinv_ip_address_country;
688 688
         return '';
689
-        if ( !empty( $wpinv_ip_address_country ) ) {
689
+        if (!empty($wpinv_ip_address_country)) {
690 690
             return $wpinv_ip_address_country;
691 691
         }
692 692
 
693
-        if ( empty( $ip ) ) {
693
+        if (empty($ip)) {
694 694
             $ip = wpinv_get_ip();
695 695
         }
696 696
 
697
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
698
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
697
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
698
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
699 699
 
700
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
701
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
700
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
701
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
702 702
                 try {
703
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
704
-                } catch( Exception $e ) {
705
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
703
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
704
+                } catch (Exception $e) {
705
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
706 706
                 }
707
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
708
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
709
-            } else if ( function_exists( 'simplexml_load_file' ) && ini_get('allow_url_fopen') && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
710
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
707
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
708
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
709
+            } else if (function_exists('simplexml_load_file') && ini_get('allow_url_fopen') && ($ip_country_service === 'geoplugin' || $is_default)) {
710
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
711 711
 
712
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
713
-                    $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
712
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
713
+                    $wpinv_ip_address_country = (string) $load_xml->geoplugin_countryCode;
714 714
                 }
715
-            }elseif(!empty( $ip )){
715
+            }elseif (!empty($ip)) {
716 716
                 $url = 'http://ip-api.com/json/' . $ip;
717 717
                 $response = wp_remote_get($url);
718 718
 
719
-                if ( is_array( $response ) && wp_remote_retrieve_response_code( $response ) == '200' ) {
720
-                    $data = json_decode(wp_remote_retrieve_body( $response ),true);
721
-                    if(!empty($data['countryCode'])){
722
-                        $wpinv_ip_address_country = (string)$data['countryCode'];
719
+                if (is_array($response) && wp_remote_retrieve_response_code($response) == '200') {
720
+                    $data = json_decode(wp_remote_retrieve_body($response), true);
721
+                    if (!empty($data['countryCode'])) {
722
+                        $wpinv_ip_address_country = (string) $data['countryCode'];
723 723
                     }
724 724
                 }
725 725
             }
726 726
         }
727 727
 
728
-        if ( empty( $wpinv_ip_address_country ) ) {
728
+        if (empty($wpinv_ip_address_country)) {
729 729
             $wpinv_ip_address_country = wpinv_get_default_country();
730 730
         }
731 731
 
732 732
         return $wpinv_ip_address_country;
733 733
     }
734 734
 
735
-    public static function sanitize_vat_settings( $input ) {
735
+    public static function sanitize_vat_settings($input) {
736 736
         global $wpinv_options;
737 737
 
738 738
         $valid      = false;
739 739
         $message    = '';
740 740
 
741
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
742
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
743
-                $valid = self::offline_check( $input['vat_number'] );
741
+        if (!empty($wpinv_options['vat_vies_check'])) {
742
+            if (empty($wpinv_options['vat_offline_check'])) {
743
+                $valid = self::offline_check($input['vat_number']);
744 744
             } else {
745 745
                 $valid = true;
746 746
             }
747 747
 
748
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
748
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
749 749
         } else {
750
-            $result = self::check_vat( $input['vat_number'] );
750
+            $result = self::check_vat($input['vat_number']);
751 751
 
752
-            if ( empty( $result['valid'] ) ) {
752
+            if (empty($result['valid'])) {
753 753
                 $valid      = false;
754 754
                 $message    = $result['message'];
755 755
             } else {
756
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
757
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
756
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
757
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
758 758
             }
759 759
         }
760 760
 
761
-        if ( $message && self::is_vat_validated() != $valid ) {
762
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
761
+        if ($message && self::is_vat_validated() != $valid) {
762
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
763 763
         }
764 764
 
765 765
         $input['vat_valid'] = $valid;
766 766
         return $input;
767 767
     }
768 768
 
769
-    public static function sanitize_vat_rates( $input ) {
770
-        if( !wpinv_current_user_can_manage_invoicing() ) {
771
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
769
+    public static function sanitize_vat_rates($input) {
770
+        if (!wpinv_current_user_can_manage_invoicing()) {
771
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
772 772
             return $input;
773 773
         }
774 774
 
775 775
         $vat_classes = self::get_rate_classes();
776
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
776
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
777 777
 
778
-        if ( empty( $vat_class ) ) {
779
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
778
+        if (empty($vat_class)) {
779
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
780 780
 
781 781
             return $input;
782 782
         }
783 783
 
784
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
784
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
785 785
 
786
-        if ( $vat_class === '_standard' ) {
786
+        if ($vat_class === '_standard') {
787 787
             // Save the active rates in the invoice settings
788
-            update_option( 'wpinv_tax_rates', $new_rates );
788
+            update_option('wpinv_tax_rates', $new_rates);
789 789
         } else {
790 790
             // Get the existing set of rates
791 791
             $rates = self::get_non_standard_rates();
792 792
             $rates[$vat_class] = $new_rates;
793 793
 
794
-            update_option( 'wpinv_vat_rates', $rates );
794
+            update_option('wpinv_vat_rates', $rates);
795 795
         }
796 796
 
797 797
         return $input;
@@ -801,71 +801,71 @@  discard block
 block discarded – undo
801 801
         $response = array();
802 802
         $response['success'] = false;
803 803
 
804
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
805
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
806
-            wp_send_json( $response );
804
+        if (!wpinv_current_user_can_manage_invoicing()) {
805
+            $response['error'] = __('Invalid access!', 'invoicing');
806
+            wp_send_json($response);
807 807
         }
808 808
 
809
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
810
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
809
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
810
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
811 811
 
812
-        if ( empty( $vat_class_name ) ) {
813
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
814
-            wp_send_json( $response );
812
+        if (empty($vat_class_name)) {
813
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
814
+            wp_send_json($response);
815 815
         }
816 816
 
817
-        $vat_classes = (array)self::get_rate_classes();
817
+        $vat_classes = (array) self::get_rate_classes();
818 818
 
819
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
820
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
821
-            wp_send_json( $response );
819
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
820
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
821
+            wp_send_json($response);
822 822
         }
823 823
 
824
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
825
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
824
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
825
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
826 826
 
827
-        $vat_classes = (array)self::get_rate_classes( true );
828
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
827
+        $vat_classes = (array) self::get_rate_classes(true);
828
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
829 829
 
830
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
830
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
831 831
 
832 832
         $response['success'] = true;
833
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
833
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
834 834
 
835
-        wp_send_json( $response );
835
+        wp_send_json($response);
836 836
     }
837 837
 
838 838
     public static function delete_class() {
839 839
         $response = array();
840 840
         $response['success'] = false;
841 841
 
842
-        if ( !wpinv_current_user_can_manage_invoicing() || !isset( $_POST['class'] ) ) {
843
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
844
-            wp_send_json( $response );
842
+        if (!wpinv_current_user_can_manage_invoicing() || !isset($_POST['class'])) {
843
+            $response['error'] = __('Invalid access!', 'invoicing');
844
+            wp_send_json($response);
845 845
         }
846 846
 
847
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
848
-        $vat_classes = (array)self::get_rate_classes();
847
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
848
+        $vat_classes = (array) self::get_rate_classes();
849 849
 
850
-        if ( !isset( $vat_classes[$vat_class] ) ) {
851
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
852
-            wp_send_json( $response );
850
+        if (!isset($vat_classes[$vat_class])) {
851
+            $response['error'] = __('Requested class does not exists', 'invoicing');
852
+            wp_send_json($response);
853 853
         }
854 854
 
855
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
856
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
857
-            wp_send_json( $response );
855
+        if ($vat_class == '_new' || $vat_class == '_standard') {
856
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
857
+            wp_send_json($response);
858 858
         }
859 859
 
860
-        $vat_classes = (array)self::get_rate_classes( true );
861
-        unset( $vat_classes[$vat_class] );
860
+        $vat_classes = (array) self::get_rate_classes(true);
861
+        unset($vat_classes[$vat_class]);
862 862
 
863
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
863
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
864 864
 
865 865
         $response['success'] = true;
866
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
866
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
867 867
 
868
-        wp_send_json( $response );
868
+        wp_send_json($response);
869 869
     }
870 870
 
871 871
     public static function update_eu_rates() {
@@ -874,73 +874,73 @@  discard block
 block discarded – undo
874 874
         $response['error']      = null;
875 875
         $response['data']       = null;
876 876
 
877
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
878
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
879
-            wp_send_json( $response );
877
+        if (!wpinv_current_user_can_manage_invoicing()) {
878
+            $response['error'] = __('Invalid access!', 'invoicing');
879
+            wp_send_json($response);
880 880
         }
881 881
 
882
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
883
-        $euvatrates = self::request_euvatrates( $group );
882
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
883
+        $euvatrates = self::request_euvatrates($group);
884 884
 
885
-        if ( !empty( $euvatrates ) ) {
886
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
885
+        if (!empty($euvatrates)) {
886
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
887 887
                 $response['success']        = true;
888 888
                 $response['data']['rates']  = $euvatrates['rates'];
889
-            } else if ( !empty( $euvatrates['error'] ) ) {
889
+            } else if (!empty($euvatrates['error'])) {
890 890
                 $response['error']          = $euvatrates['error'];
891 891
             }
892 892
         }
893 893
 
894
-        wp_send_json( $response );
894
+        wp_send_json($response);
895 895
     }
896 896
 
897 897
     public static function hide_vat_fields() {
898
-        $hide = wpinv_get_option( 'vat_disable_fields' );
898
+        $hide = wpinv_get_option('vat_disable_fields');
899 899
 
900
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
900
+        return apply_filters('wpinv_hide_vat_fields', $hide);
901 901
     }
902 902
 
903 903
     public static function same_country_rule() {
904
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
904
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
905 905
 
906
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
906
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
907 907
     }
908 908
 
909 909
     /**
910 910
      * Retrieves the vat name.
911 911
      */
912 912
     public function get_vat_name() {
913
-        $vat_name = wpinv_get_option( 'vat_name' );
914
-        return empty( $vat_name ) ? __( 'VAT', 'invoicing' ) : sanitize_text_field( $vat_name );
913
+        $vat_name = wpinv_get_option('vat_name');
914
+        return empty($vat_name) ? __('VAT', 'invoicing') : sanitize_text_field($vat_name);
915 915
     }
916 916
 
917 917
     public static function get_company_name() {
918
-        $company_name = wpinv_get_option( 'vat_company_name' );
918
+        $company_name = wpinv_get_option('vat_company_name');
919 919
 
920
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
920
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
921 921
     }
922 922
 
923 923
     public static function get_vat_number() {
924
-        $vat_number = wpinv_get_option( 'vat_number' );
924
+        $vat_number = wpinv_get_option('vat_number');
925 925
 
926
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
926
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
927 927
     }
928 928
 
929 929
     public static function is_vat_validated() {
930
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
930
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
931 931
 
932
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
932
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
933 933
     }
934 934
 
935
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {
936
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
935
+    public static function sanitize_vat($vat_number, $country_code = '') {
936
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
937 937
 
938
-        if ( empty( $country_code ) ) {
939
-            $country_code = substr( $vat_number, 0, 2 );
938
+        if (empty($country_code)) {
939
+            $country_code = substr($vat_number, 0, 2);
940 940
         }
941 941
 
942
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
943
-            $vat = str_replace( $country_code, '', $vat_number );
942
+        if (strpos($vat_number, $country_code) === 0) {
943
+            $vat = str_replace($country_code, '', $vat_number);
944 944
         } else {
945 945
             $vat = $country_code . $vat_number;
946 946
         }
@@ -953,140 +953,140 @@  discard block
 block discarded – undo
953 953
         return $return;
954 954
     }
955 955
 
956
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
957
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
956
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
957
+        $vat            = self::sanitize_vat($vat_number, $country_code);
958 958
         $vat_number     = $vat['vat_number'];
959 959
         $country_code   = $vat['iso'];
960 960
         $regex          = array();
961 961
 
962
-        switch ( $country_code ) {
962
+        switch ($country_code) {
963 963
             case 'AT':
964
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
964
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
965 965
                 break;
966 966
             case 'BE':
967
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
967
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
968 968
                 break;
969 969
             case 'BG':
970
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
970
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
971 971
                 break;
972 972
             case 'CH':
973 973
             case 'CHE':
974
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
974
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
975 975
                 break;
976 976
             case 'CY':
977
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
977
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
978 978
                 break;
979 979
             case 'CZ':
980
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
980
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
981 981
                 break;
982 982
             case 'DE':
983
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
983
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
984 984
                 break;
985 985
             case 'DK':
986
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
986
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
987 987
                 break;
988 988
             case 'EE':
989
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
989
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
990 990
                 break;
991 991
             case 'EL':
992
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
992
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
993 993
                 break;
994 994
             case 'ES':
995
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
996
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
997
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
998
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
995
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
996
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
997
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
998
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
999 999
                 break;
1000 1000
             case 'EU':
1001
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
1001
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
1002 1002
                 break;
1003 1003
             case 'FI':
1004
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
1004
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
1005 1005
                 break;
1006 1006
             case 'FR':
1007
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
1008
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
1009
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
1010
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
1007
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
1008
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
1009
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
1010
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
1011 1011
                 break;
1012 1012
             case 'GB':
1013
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
1014
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
1015
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
1016
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
1013
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
1014
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
1015
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
1016
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
1017 1017
                 break;
1018 1018
             case 'GR':
1019
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
1019
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
1020 1020
                 break;
1021 1021
             case 'HR':
1022
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
1022
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
1023 1023
                 break;
1024 1024
             case 'HU':
1025
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
1025
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
1026 1026
                 break;
1027 1027
             case 'IE':
1028
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
1029
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
1030
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
1028
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
1029
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
1030
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
1031 1031
                 break;
1032 1032
             case 'IT':
1033
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
1033
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
1034 1034
                 break;
1035 1035
             case 'LV':
1036
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
1036
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
1037 1037
                 break;
1038 1038
             case 'LT':
1039
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
1039
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
1040 1040
                 break;
1041 1041
             case 'LU':
1042
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
1042
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
1043 1043
                 break;
1044 1044
             case 'MT':
1045
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
1045
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
1046 1046
                 break;
1047 1047
             case 'NL':
1048
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
1048
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
1049 1049
                 break;
1050 1050
             case 'NO':
1051
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
1051
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
1052 1052
                 break;
1053 1053
             case 'PL':
1054
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1054
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1055 1055
                 break;
1056 1056
             case 'PT':
1057
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1057
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1058 1058
                 break;
1059 1059
             case 'RO':
1060
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1060
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1061 1061
                 break;
1062 1062
             case 'RS':
1063
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1063
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1064 1064
                 break;
1065 1065
             case 'SI':
1066
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1066
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1067 1067
                 break;
1068 1068
             case 'SK':
1069
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1069
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1070 1070
                 break;
1071 1071
             case 'SE':
1072
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1072
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1073 1073
                 break;
1074 1074
             default:
1075 1075
                 $regex = array();
1076 1076
             break;
1077 1077
         }
1078 1078
 
1079
-        if ( empty( $regex ) ) {
1079
+        if (empty($regex)) {
1080 1080
             return false;
1081 1081
         }
1082 1082
 
1083
-        foreach ( $regex as $pattern ) {
1083
+        foreach ($regex as $pattern) {
1084 1084
             $matches = null;
1085
-            preg_match_all( $pattern, $vat_number, $matches );
1085
+            preg_match_all($pattern, $vat_number, $matches);
1086 1086
 
1087
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1088
-                if ( $formatted ) {
1089
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1087
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1088
+                if ($formatted) {
1089
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1090 1090
                 } else {
1091 1091
                     return true;
1092 1092
                 }
@@ -1096,75 +1096,75 @@  discard block
 block discarded – undo
1096 1096
         return false;
1097 1097
     }
1098 1098
 
1099
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1100
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1099
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1100
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1101 1101
         $vat_number     = $vat['vat'];
1102 1102
         $iso            = $vat['iso'];
1103 1103
 
1104
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1104
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1105 1105
 
1106
-        if ( ini_get( 'allow_url_fopen' ) ) {
1107
-            $response = file_get_contents( $url );
1108
-        } else if ( function_exists( 'curl_init' ) ) {
1106
+        if (ini_get('allow_url_fopen')) {
1107
+            $response = file_get_contents($url);
1108
+        } else if (function_exists('curl_init')) {
1109 1109
             $ch = curl_init();
1110 1110
 
1111
-            curl_setopt( $ch, CURLOPT_URL, $url );
1112
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1113
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1114
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1115
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1111
+            curl_setopt($ch, CURLOPT_URL, $url);
1112
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1113
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1114
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1115
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1116 1116
 
1117
-            $response = curl_exec( $ch );
1117
+            $response = curl_exec($ch);
1118 1118
 
1119
-            if ( curl_errno( $ch ) ) {
1120
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1119
+            if (curl_errno($ch)) {
1120
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1121 1121
                 $response = '';
1122 1122
             }
1123 1123
 
1124
-            curl_close( $ch );
1124
+            curl_close($ch);
1125 1125
         } else {
1126
-            wpinv_error_log( 'To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR' );
1126
+            wpinv_error_log('To use VIES CHECK you must have allow_url_fopen is ON or cURL installed & active on your server.', 'VIES CHECK ERROR');
1127 1127
         }
1128 1128
 
1129
-        if ( empty( $response ) ) {
1129
+        if (empty($response)) {
1130 1130
             return $result;
1131 1131
         }
1132 1132
 
1133
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1133
+        if (preg_match('/invalid VAT number/i', $response)) {
1134 1134
             return false;
1135
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1136
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1135
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1136
+            $content = explode("valid VAT number", htmlentities($response));
1137 1137
 
1138
-            if ( !empty( $content[1] ) ) {
1139
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1138
+            if (!empty($content[1])) {
1139
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1140 1140
 
1141
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1141
+                if (!empty($matches[2]) && $matches[3]) {
1142 1142
                     $return = array();
1143 1143
 
1144
-                    foreach ( $matches[2] as $key => $label ) {
1145
-                        $label = trim( $label );
1144
+                    foreach ($matches[2] as $key => $label) {
1145
+                        $label = trim($label);
1146 1146
 
1147
-                        switch ( strtolower( $label ) ) {
1147
+                        switch (strtolower($label)) {
1148 1148
                             case 'member state':
1149
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1149
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1150 1150
                             break;
1151 1151
                             case 'vat number':
1152
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1152
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1153 1153
                             break;
1154 1154
                             case 'name':
1155
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1155
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1156 1156
                             break;
1157 1157
                             case 'address':
1158
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1159
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1158
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1159
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1160 1160
                             break;
1161 1161
                             case 'consultation number':
1162
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1162
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1163 1163
                             break;
1164 1164
                         }
1165 1165
                     }
1166 1166
 
1167
-                    if ( !empty( $return ) ) {
1167
+                    if (!empty($return)) {
1168 1168
                         return $return;
1169 1169
                     }
1170 1170
                 }
@@ -1176,62 +1176,62 @@  discard block
 block discarded – undo
1176 1176
         }
1177 1177
     }
1178 1178
 
1179
-    public static function check_vat( $vat_number, $country_code = '' ) {
1179
+    public static function check_vat($vat_number, $country_code = '') {
1180 1180
         $vat_name           = getpaid_vat_name();
1181 1181
 
1182 1182
         $return             = array();
1183 1183
         $return['valid']    = false;
1184
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1184
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1185 1185
 
1186
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1186
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1187 1187
             return $return;
1188 1188
         }
1189 1189
 
1190
-        $response = self::vies_check( $vat_number, $country_code );
1190
+        $response = self::vies_check($vat_number, $country_code);
1191 1191
 
1192
-        if ( $response ) {
1193
-            $return['valid']    = true;
1192
+        if ($response) {
1193
+            $return['valid'] = true;
1194 1194
 
1195
-            if ( is_array( $response ) ) {
1196
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1197
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1195
+            if (is_array($response)) {
1196
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1197
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1198 1198
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1199 1199
             }
1200 1200
         } else {
1201 1201
             $return['valid']    = false;
1202
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1202
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1203 1203
         }
1204 1204
 
1205 1205
         return $return;
1206 1206
     }
1207 1207
 
1208
-    public static function request_euvatrates( $group ) {
1208
+    public static function request_euvatrates($group) {
1209 1209
         $response               = array();
1210 1210
         $response['success']    = false;
1211 1211
         $response['error']      = null;
1212 1212
         $response['eurates']    = null;
1213 1213
 
1214 1214
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1215
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1216
-        $api_response   = wp_remote_get( $euvatrates_url );
1215
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1216
+        $api_response   = wp_remote_get($euvatrates_url);
1217 1217
 
1218 1218
         try {
1219
-            if ( is_wp_error( $api_response ) ) {
1220
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1219
+            if (is_wp_error($api_response)) {
1220
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1221 1221
             } else {
1222
-                $body = json_decode( $api_response['body'] );
1223
-                if ( isset( $body->rates ) ) {
1222
+                $body = json_decode($api_response['body']);
1223
+                if (isset($body->rates)) {
1224 1224
                     $rates = array();
1225 1225
 
1226
-                    foreach ( $body->rates as $country_code => $rate ) {
1226
+                    foreach ($body->rates as $country_code => $rate) {
1227 1227
                         $vat_rate = array();
1228 1228
                         $vat_rate['country']        = $rate->country;
1229
-                        $vat_rate['standard']       = (float)$rate->standard_rate;
1230
-                        $vat_rate['reduced']        = (float)$rate->reduced_rate;
1231
-                        $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1232
-                        $vat_rate['parking']        = (float)$rate->parking_rate;
1229
+                        $vat_rate['standard']       = (float) $rate->standard_rate;
1230
+                        $vat_rate['reduced']        = (float) $rate->reduced_rate;
1231
+                        $vat_rate['superreduced']   = (float) $rate->super_reduced_rate;
1232
+                        $vat_rate['parking']        = (float) $rate->parking_rate;
1233 1233
 
1234
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1234
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1235 1235
                             $vat_rate_group = array();
1236 1236
                             $vat_rate_group['country'] = $rate->country;
1237 1237
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1243,79 +1243,79 @@  discard block
 block discarded – undo
1243 1243
                     }
1244 1244
 
1245 1245
                     $response['success']    = true;
1246
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1246
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1247 1247
                 } else {
1248
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1248
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1249 1249
                 }
1250 1250
             }
1251
-        } catch ( Exception $e ) {
1252
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1251
+        } catch (Exception $e) {
1252
+            $response['error'] = __($e->getMessage(), 'invoicing');
1253 1253
         }
1254 1254
 
1255
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1255
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1256 1256
     }
1257 1257
 
1258
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1258
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1259 1259
         global $wpi_item_id, $wpi_country;
1260 1260
 
1261
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1262
-            $country_code = trim( $_POST['wpinv_country'] );
1263
-        } else if ( !empty( $_POST['country'] ) ) {
1264
-            $country_code = trim( $_POST['country'] );
1265
-        } else if ( !empty( $wpi_country ) ) {
1261
+        if (!empty($_POST['wpinv_country'])) {
1262
+            $country_code = trim($_POST['wpinv_country']);
1263
+        } else if (!empty($_POST['country'])) {
1264
+            $country_code = trim($_POST['country']);
1265
+        } else if (!empty($wpi_country)) {
1266 1266
             $country_code = $wpi_country;
1267 1267
         } else {
1268
-            $country_code = self::get_user_country( '', $user_id );
1268
+            $country_code = self::get_user_country('', $user_id);
1269 1269
         }
1270 1270
 
1271
-        if ( $is_digital === null && $wpi_item_id ) {
1272
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1271
+        if ($is_digital === null && $wpi_item_id) {
1272
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1273 1273
         }
1274 1274
 
1275
-        if ( !empty( $country_code ) ) {
1276
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( wpinv_get_default_country() ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( wpinv_get_default_country() ) );
1275
+        if (!empty($country_code)) {
1276
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(wpinv_get_default_country()) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(wpinv_get_default_country()));
1277 1277
         }
1278 1278
 
1279
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1279
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1280 1280
     }
1281 1281
 
1282
-    public static function tax_label( $label = '' ) {
1282
+    public static function tax_label($label = '') {
1283 1283
         global $wpi_requires_vat;
1284 1284
 
1285
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1286
-            $wpi_requires_vat = self::requires_vat( 0, false );
1285
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1286
+            $wpi_requires_vat = self::requires_vat(0, false);
1287 1287
         }
1288 1288
 
1289
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1289
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1290 1290
     }
1291 1291
 
1292 1292
     public static function standard_rates_label() {
1293
-        return __( 'Standard Rates', 'invoicing' );
1293
+        return __('Standard Rates', 'invoicing');
1294 1294
     }
1295 1295
 
1296
-    public static function get_rate_classes( $with_desc = false ) {
1297
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1298
-        $classes = maybe_unserialize( $rate_classes_option );
1296
+    public static function get_rate_classes($with_desc = false) {
1297
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1298
+        $classes = maybe_unserialize($rate_classes_option);
1299 1299
 
1300
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1300
+        if (empty($classes) || !is_array($classes)) {
1301 1301
             $classes = array();
1302 1302
         }
1303 1303
 
1304 1304
         $rate_classes = array();
1305
-        if ( !array_key_exists( '_standard', $classes ) ) {
1306
-            if ( $with_desc ) {
1307
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1305
+        if (!array_key_exists('_standard', $classes)) {
1306
+            if ($with_desc) {
1307
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1308 1308
             } else {
1309 1309
                 $rate_classes['_standard'] = self::standard_rates_label();
1310 1310
             }
1311 1311
         }
1312 1312
 
1313
-        foreach ( $classes as $key => $class ) {
1314
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1315
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1313
+        foreach ($classes as $key => $class) {
1314
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1315
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1316 1316
 
1317
-            if ( $with_desc ) {
1318
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1317
+            if ($with_desc) {
1318
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1319 1319
             } else {
1320 1320
                 $rate_classes[$key] = $name;
1321 1321
             }
@@ -1326,15 +1326,15 @@  discard block
 block discarded – undo
1326 1326
 
1327 1327
     public static function get_all_classes() {
1328 1328
         $classes            = self::get_rate_classes();
1329
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1329
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1330 1330
 
1331
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1331
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1332 1332
     }
1333 1333
 
1334
-    public static function get_class_desc( $rate_class ) {
1335
-        $rate_classes = self::get_rate_classes( true );
1334
+    public static function get_class_desc($rate_class) {
1335
+        $rate_classes = self::get_rate_classes(true);
1336 1336
 
1337
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1337
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1338 1338
             return $rate_classes[$rate_class]['desc'];
1339 1339
         }
1340 1340
 
@@ -1350,107 +1350,107 @@  discard block
 block discarded – undo
1350 1350
             'increased'     => 'Increased'
1351 1351
         );
1352 1352
 
1353
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1353
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1354 1354
     }
1355 1355
 
1356 1356
     public static function get_rules() {
1357 1357
         $vat_rules = array(
1358
-            'digital' => __( 'Digital Product', 'invoicing' ),
1359
-            'physical' => __( 'Physical Product', 'invoicing' ),
1360
-            '_exempt' => __( 'Tax-Free Product', 'invoicing' ),
1358
+            'digital' => __('Digital Product', 'invoicing'),
1359
+            'physical' => __('Physical Product', 'invoicing'),
1360
+            '_exempt' => __('Tax-Free Product', 'invoicing'),
1361 1361
         );
1362
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1362
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1363 1363
     }
1364 1364
 
1365
-    public static function get_vat_rates( $class ) {
1366
-        if ( $class === '_standard' ) {
1365
+    public static function get_vat_rates($class) {
1366
+        if ($class === '_standard') {
1367 1367
             return wpinv_get_tax_rates();
1368 1368
         }
1369 1369
 
1370 1370
         $rates = self::get_non_standard_rates();
1371 1371
 
1372
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1372
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1373 1373
     }
1374 1374
 
1375 1375
     public static function get_non_standard_rates() {
1376
-        $option = get_option( 'wpinv_vat_rates', array());
1377
-        return is_array( $option ) ? $option : array();
1376
+        $option = get_option('wpinv_vat_rates', array());
1377
+        return is_array($option) ? $option : array();
1378 1378
     }
1379 1379
 
1380 1380
     public static function allow_vat_rules() {
1381
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1381
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1382 1382
     }
1383 1383
 
1384 1384
     public static function allow_vat_classes() {
1385 1385
         return false; // TODO
1386
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1386
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1387 1387
     }
1388 1388
 
1389
-    public static function get_item_class( $postID ) {
1390
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1389
+    public static function get_item_class($postID) {
1390
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1391 1391
 
1392
-        if ( empty( $class ) ) {
1392
+        if (empty($class)) {
1393 1393
             $class = '_standard';
1394 1394
         }
1395 1395
 
1396
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1396
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1397 1397
     }
1398 1398
 
1399
-    public static function item_class_label( $postID ) {
1399
+    public static function item_class_label($postID) {
1400 1400
         $vat_classes = self::get_all_classes();
1401 1401
 
1402
-        $class = self::get_item_class( $postID );
1403
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1402
+        $class = self::get_item_class($postID);
1403
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1404 1404
 
1405
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1405
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1406 1406
     }
1407 1407
 
1408
-    public static function get_item_rule( $postID ) {
1409
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1408
+    public static function get_item_rule($postID) {
1409
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1410 1410
 
1411
-        if ( empty( $rule_type ) ) {
1411
+        if (empty($rule_type)) {
1412 1412
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1413 1413
         }
1414 1414
 
1415
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1415
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1416 1416
     }
1417 1417
 
1418
-    public static function item_rule_label( $postID ) {
1418
+    public static function item_rule_label($postID) {
1419 1419
         $vat_rules  = self::get_rules();
1420
-        $vat_rule   = self::get_item_rule( $postID );
1421
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1420
+        $vat_rule   = self::get_item_rule($postID);
1421
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1422 1422
 
1423
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1423
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1424 1424
     }
1425 1425
 
1426
-    public static function item_has_digital_rule( $item_id = 0 ) {
1427
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1426
+    public static function item_has_digital_rule($item_id = 0) {
1427
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1428 1428
     }
1429 1429
 
1430
-    public static function invoice_has_digital_rule( $invoice = 0 ) {
1431
-        if ( !self::allow_vat_rules() ) {
1430
+    public static function invoice_has_digital_rule($invoice = 0) {
1431
+        if (!self::allow_vat_rules()) {
1432 1432
             return false;
1433 1433
         }
1434 1434
 
1435
-        if ( empty( $invoice ) ) {
1435
+        if (empty($invoice)) {
1436 1436
             return true;
1437 1437
         }
1438 1438
 
1439
-        if ( is_int( $invoice ) ) {
1440
-            $invoice = new WPInv_Invoice( $invoice );
1439
+        if (is_int($invoice)) {
1440
+            $invoice = new WPInv_Invoice($invoice);
1441 1441
         }
1442 1442
 
1443
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1443
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1444 1444
             return true;
1445 1445
         }
1446 1446
 
1447
-        $cart_items  = $invoice->get_cart_details();
1447
+        $cart_items = $invoice->get_cart_details();
1448 1448
 
1449
-        if ( !empty( $cart_items ) ) {
1449
+        if (!empty($cart_items)) {
1450 1450
             $has_digital_rule = false;
1451 1451
 
1452
-            foreach ( $cart_items as $key => $item ) {
1453
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1452
+            foreach ($cart_items as $key => $item) {
1453
+                if (self::item_has_digital_rule($item['id'])) {
1454 1454
                     $has_digital_rule = true;
1455 1455
                     break;
1456 1456
                 }
@@ -1462,71 +1462,71 @@  discard block
 block discarded – undo
1462 1462
         return $has_digital_rule;
1463 1463
     }
1464 1464
 
1465
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {
1466
-        if ( !wpinv_use_taxes() ) {
1465
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {
1466
+        if (!wpinv_use_taxes()) {
1467 1467
             return false;
1468 1468
         }
1469 1469
 
1470 1470
         $is_taxable = true;
1471 1471
 
1472
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1472
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1473 1473
             $is_taxable = false;
1474 1474
         }
1475 1475
 
1476
-        if ( !empty( $item_id ) && self::get_item_rule( $item_id ) == '_exempt' ) {
1476
+        if (!empty($item_id) && self::get_item_rule($item_id) == '_exempt') {
1477 1477
             $is_taxable = false;
1478 1478
         }
1479 1479
 
1480
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1480
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1481 1481
     }
1482 1482
 
1483
-    public static function find_rate( $country, $state, $rate, $class ) {
1483
+    public static function find_rate($country, $state, $rate, $class) {
1484 1484
         global $wpi_zero_tax;
1485 1485
 
1486
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1486
+        if ($class === '_exempt' || $wpi_zero_tax) {
1487 1487
             return 0;
1488 1488
         }
1489 1489
 
1490
-        $tax_rates   = wpinv_get_tax_rates();
1490
+        $tax_rates = wpinv_get_tax_rates();
1491 1491
 
1492
-        if ( $class !== '_standard' ) {
1493
-            $class_rates = self::get_vat_rates( $class );
1492
+        if ($class !== '_standard') {
1493
+            $class_rates = self::get_vat_rates($class);
1494 1494
 
1495
-            if ( is_array( $class_rates ) ) {
1495
+            if (is_array($class_rates)) {
1496 1496
                 $indexed_class_rates = array();
1497 1497
 
1498
-                foreach ( $class_rates as $key => $cr ) {
1498
+                foreach ($class_rates as $key => $cr) {
1499 1499
                     $indexed_class_rates[$cr['country']] = $cr;
1500 1500
                 }
1501 1501
 
1502
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1502
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1503 1503
                     $tr_country = $tr['country'];
1504
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1504
+                    if (!isset($indexed_class_rates[$tr_country])) {
1505 1505
                         return $tr;
1506 1506
                     }
1507 1507
                     $icr = $indexed_class_rates[$tr_country];
1508
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1508
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1509 1509
 
1510
-                }, $tax_rates, $class_rates );
1510
+                }, $tax_rates, $class_rates);
1511 1511
             }
1512 1512
         }
1513 1513
 
1514
-        if ( !empty( $tax_rates ) ) {
1515
-            foreach ( $tax_rates as $key => $tax_rate ) {
1516
-                if ( $country != $tax_rate['country'] )
1514
+        if (!empty($tax_rates)) {
1515
+            foreach ($tax_rates as $key => $tax_rate) {
1516
+                if ($country != $tax_rate['country'])
1517 1517
                     continue;
1518 1518
 
1519
-                if ( !empty( $tax_rate['global'] ) ) {
1520
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1521
-                        $rate = number_format( $tax_rate['rate'], 4 );
1519
+                if (!empty($tax_rate['global'])) {
1520
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1521
+                        $rate = number_format($tax_rate['rate'], 4);
1522 1522
                     }
1523 1523
                 } else {
1524
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1524
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1525 1525
                         continue;
1526 1526
 
1527 1527
                     $state_rate = $tax_rate['rate'];
1528
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1529
-                        $rate = number_format( $state_rate, 4 );
1528
+                    if (0 !== $state_rate || !empty($state_rate)) {
1529
+                        $rate = number_format($state_rate, 4);
1530 1530
                     }
1531 1531
                 }
1532 1532
             }
@@ -1535,84 +1535,84 @@  discard block
 block discarded – undo
1535 1535
         return $rate;
1536 1536
     }
1537 1537
 
1538
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1538
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1539 1539
         global $wpinv_options, $wpi_item_id, $wpi_zero_tax;
1540 1540
 
1541 1541
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1542 1542
         $allow_vat_classes = self::allow_vat_classes();
1543
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1543
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1544 1544
 
1545
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1545
+        if ($class === '_exempt' || $wpi_zero_tax) {
1546 1546
             return 0;
1547
-        } else if ( !$allow_vat_classes ) {
1547
+        } else if (!$allow_vat_classes) {
1548 1548
             $class = '_standard';
1549 1549
         }
1550 1550
 
1551
-        if( !empty( $_POST['wpinv_country'] ) ) {
1551
+        if (!empty($_POST['wpinv_country'])) {
1552 1552
             $post_country = $_POST['wpinv_country'];
1553
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1553
+        } elseif (!empty($_POST['wpinv_country'])) {
1554 1554
             $post_country = $_POST['wpinv_country'];
1555
-        } elseif( !empty( $_POST['country'] ) ) {
1555
+        } elseif (!empty($_POST['country'])) {
1556 1556
             $post_country = $_POST['country'];
1557 1557
         } else {
1558 1558
             $post_country = '';
1559 1559
         }
1560 1560
 
1561
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1562
-        $base_country   = wpinv_is_base_country( $country );
1561
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1562
+        $base_country   = wpinv_is_base_country($country);
1563 1563
 
1564
-        $requires_vat   = self::requires_vat( 0, false );
1565
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1566
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1564
+        $requires_vat   = self::requires_vat(0, false);
1565
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1566
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1567 1567
 
1568
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1568
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1569 1569
             $rate = 0;
1570
-        } else if ( $requires_vat ) {
1571
-            $vat_number = self::get_user_vat_number( '', 0, true );
1570
+        } else if ($requires_vat) {
1571
+            $vat_number = self::get_user_vat_number('', 0, true);
1572 1572
             $vat_info   = self::current_vat_data();
1573 1573
 
1574
-            if ( is_array( $vat_info ) ) {
1575
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1574
+            if (is_array($vat_info)) {
1575
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1576 1576
             }
1577 1577
 
1578
-            if ( $country == 'UK' ) {
1578
+            if ($country == 'UK') {
1579 1579
                 $country = 'GB';
1580 1580
             }
1581 1581
 
1582
-            if ( !empty( $vat_number ) ) {
1582
+            if (!empty($vat_number)) {
1583 1583
                 $rate = 0;
1584 1584
             } else {
1585
-                $rate = self::find_rate( $country, $state, $rate, $class ); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1585
+                $rate = self::find_rate($country, $state, $rate, $class); // Fix if there are no tax rated and you try to pay an invoice it does not add the fallback tax rate
1586 1586
             }
1587 1587
 
1588
-            if ( empty( $vat_number ) && !$is_digital ) {
1589
-                if ( $base_country ) {
1590
-                    $rate = self::find_rate( $country, null, $rate, $class );
1588
+            if (empty($vat_number) && !$is_digital) {
1589
+                if ($base_country) {
1590
+                    $rate = self::find_rate($country, null, $rate, $class);
1591 1591
                 } else {
1592
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1592
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1593 1593
                         $rate = $wpinv_options['eu_fallback_rate'];
1594
-                    } else if( !empty( $country ) ) {
1595
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1594
+                    } else if (!empty($country)) {
1595
+                        $rate = self::find_rate($country, $state, $rate, $class);
1596 1596
                     }
1597 1597
                 }
1598
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1599
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1598
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1599
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1600 1600
                     $rate = $wpinv_options['eu_fallback_rate'];
1601
-                } else if( !empty( $country ) ) {
1602
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1601
+                } else if (!empty($country)) {
1602
+                    $rate = self::find_rate($country, $state, $rate, $class);
1603 1603
                 }
1604 1604
             }
1605 1605
         } else {
1606
-            if ( $is_digital ) {
1606
+            if ($is_digital) {
1607 1607
                 $ip_country_code = self::get_country_by_ip();
1608 1608
 
1609
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1610
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1609
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1610
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1611 1611
                 } else {
1612
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1612
+                    $rate = self::find_rate($country, $state, $rate, $class);
1613 1613
                 }
1614 1614
             } else {
1615
-                $rate = self::find_rate( $country, $state, $rate, $class );
1615
+                $rate = self::find_rate($country, $state, $rate, $class);
1616 1616
             }
1617 1617
         }
1618 1618
 
@@ -1620,48 +1620,48 @@  discard block
 block discarded – undo
1620 1620
     }
1621 1621
 
1622 1622
     public static function current_vat_data() {
1623
-        return getpaid_session()->get( 'user_vat_data' );
1623
+        return getpaid_session()->get('user_vat_data');
1624 1624
     }
1625 1625
 
1626
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1627
-        $user_address = wpinv_get_user_address( $user_id, false );
1626
+    public static function get_user_country($country = '', $user_id = 0) {
1627
+        $user_address = wpinv_get_user_address($user_id, false);
1628 1628
 
1629
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1629
+        if (wpinv_get_option('vat_ip_country_default')) {
1630 1630
             $country = '';
1631 1631
         }
1632 1632
 
1633
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1634
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1633
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1634
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1635 1635
 
1636
-        if ( empty( $result ) ) {
1636
+        if (empty($result)) {
1637 1637
             $result = self::get_country_by_ip();
1638 1638
         }
1639 1639
 
1640 1640
         return $result;
1641 1641
     }
1642 1642
 
1643
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1643
+    public static function set_user_country($country = '', $user_id = 0) {
1644 1644
         global $wpi_userID;
1645 1645
 
1646
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1646
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1647 1647
             $country = wpinv_get_default_country();
1648 1648
         }
1649 1649
 
1650 1650
         return $country;
1651 1651
     }
1652 1652
 
1653
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1653
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1654 1654
         global $wpi_current_id, $wpi_userID;
1655 1655
 
1656
-        if ( !empty( $_POST['new_user'] ) ) {
1656
+        if (!empty($_POST['new_user'])) {
1657 1657
             return '';
1658 1658
         }
1659 1659
 
1660
-        if ( empty( $user_id ) ) {
1661
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1660
+        if (empty($user_id)) {
1661
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1662 1662
         }
1663 1663
 
1664
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1664
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1665 1665
 
1666 1666
         /* TODO
1667 1667
         if ( $is_valid && $vat_number ) {
@@ -1672,38 +1672,38 @@  discard block
 block discarded – undo
1672 1672
         }
1673 1673
         */
1674 1674
 
1675
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1675
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1676 1676
     }
1677 1677
 
1678
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1678
+    public static function get_user_company($company = '', $user_id = 0) {
1679 1679
         global $wpi_current_id, $wpi_userID;
1680 1680
 
1681
-        if ( empty( $user_id ) ) {
1682
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1681
+        if (empty($user_id)) {
1682
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1683 1683
         }
1684 1684
 
1685
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1685
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1686 1686
 
1687
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1687
+        return apply_filters('wpinv_user_company', $company, $user_id);
1688 1688
     }
1689 1689
 
1690
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1691
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1690
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1691
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1692 1692
 
1693
-        if ( is_user_logged_in() && $save ) {
1693
+        if (is_user_logged_in() && $save) {
1694 1694
             $user_id = get_current_user_id();
1695 1695
 
1696
-            if ( !empty( $vat_number ) ) {
1697
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1696
+            if (!empty($vat_number)) {
1697
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1698 1698
             } else {
1699
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1699
+                delete_user_meta($user_id, '_wpinv_vat_number');
1700 1700
             }
1701 1701
 
1702
-            if ( !empty( $company ) ) {
1703
-                update_user_meta( $user_id, '_wpinv_company', $company );
1702
+            if (!empty($company)) {
1703
+                update_user_meta($user_id, '_wpinv_company', $company);
1704 1704
             } else {
1705
-                delete_user_meta( $user_id, '_wpinv_company');
1706
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1705
+                delete_user_meta($user_id, '_wpinv_company');
1706
+                delete_user_meta($user_id, '_wpinv_vat_number');
1707 1707
             }
1708 1708
         }
1709 1709
 
@@ -1716,74 +1716,74 @@  discard block
 block discarded – undo
1716 1716
         $response               = array();
1717 1717
         $response['success']    = false;
1718 1718
 
1719
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1720
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1721
-            wp_send_json( $response );
1719
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1720
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1721
+            wp_send_json($response);
1722 1722
         }
1723 1723
 
1724 1724
         $vat_name   = self::get_vat_name();
1725 1725
 
1726
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1727
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1726
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1727
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1728 1728
 
1729
-        $vat_info = getpaid_session()->get( 'user_vat_data' );
1730
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1731
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1729
+        $vat_info = getpaid_session()->get('user_vat_data');
1730
+        if (!is_array($vat_info) || empty($vat_info)) {
1731
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1732 1732
         }
1733 1733
 
1734
-        if ( empty( $vat_number ) ) {
1735
-            $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1734
+        if (empty($vat_number)) {
1735
+            $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1736 1736
             $vat_info['valid'] = false;
1737
-            getpaid_session()->set( 'user_vat_data', $vat_info );
1738
-            wp_send_json( $response );
1737
+            getpaid_session()->set('user_vat_data', $vat_info);
1738
+            wp_send_json($response);
1739 1739
         }
1740 1740
 
1741
-        if ( empty( $company ) ) {
1741
+        if (empty($company)) {
1742 1742
             $vat_info['valid'] = false;
1743
-            getpaid_session()->set( 'user_vat_data', $vat_info );
1743
+            getpaid_session()->set('user_vat_data', $vat_info);
1744 1744
 
1745
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1746
-            wp_send_json( $response );
1745
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1746
+            wp_send_json($response);
1747 1747
         }
1748 1748
 
1749
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1750
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1749
+        if (!empty($wpinv_options['vat_vies_check'])) {
1750
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1751 1751
                 $vat_info['valid'] = false;
1752
-                getpaid_session()->set( 'user_vat_data', $vat_info );
1752
+                getpaid_session()->set('user_vat_data', $vat_info);
1753 1753
 
1754
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1755
-                wp_send_json( $response );
1754
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1755
+                wp_send_json($response);
1756 1756
             }
1757 1757
 
1758 1758
             $response['success'] = true;
1759
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1759
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1760 1760
         } else {
1761
-            $result = self::check_vat( $vat_number );
1761
+            $result = self::check_vat($vat_number);
1762 1762
 
1763
-            if ( empty( $result['valid'] ) ) {
1763
+            if (empty($result['valid'])) {
1764 1764
                 $response['error'] = $result['message'];
1765
-                wp_send_json( $response );
1765
+                wp_send_json($response);
1766 1766
             }
1767 1767
 
1768
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1769
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1768
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1769
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1770 1770
 
1771
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1771
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1772 1772
 
1773
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1773
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1774 1774
                 $response['success'] = true;
1775
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1775
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1776 1776
             } else {
1777 1777
                 $vat_info['valid'] = false;
1778
-                getpaid_session()->set( 'user_vat_data', $vat_info );
1778
+                getpaid_session()->set('user_vat_data', $vat_info);
1779 1779
 
1780 1780
                 $response['success'] = false;
1781
-                $response['message'] = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1782
-                wp_send_json( $response );
1781
+                $response['message'] = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1782
+                wp_send_json($response);
1783 1783
             }
1784 1784
         }
1785 1785
 
1786
-        wp_send_json( $response );
1786
+        wp_send_json($response);
1787 1787
     }
1788 1788
 
1789 1789
     /**
@@ -1791,16 +1791,16 @@  discard block
 block discarded – undo
1791 1791
      * 
1792 1792
      * @return string
1793 1793
      */
1794
-    public static function validate_vat_number( $vat_number, $company, $country ) {
1794
+    public static function validate_vat_number($vat_number, $company, $country) {
1795 1795
         global $wpinv_options;
1796 1796
 
1797 1797
         // If we are not checking the vat number via view...
1798
-        if ( ! empty( $wpinv_options['vat_vies_check'] ) ) {
1798
+        if (!empty($wpinv_options['vat_vies_check'])) {
1799 1799
 
1800 1800
             // Try validating via regex.
1801
-            if ( empty( $wpinv_options['vat_offline_check'] ) && ! self::offline_check( $vat_number, $country ) ) {
1801
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number, $country)) {
1802 1802
                 return wp_sprintf(
1803
-                    __( 'Your %s number is invalid', 'invoicing' ),
1803
+                    __('Your %s number is invalid', 'invoicing'),
1804 1804
                     getpaid_vat_name()
1805 1805
                 );
1806 1806
             }
@@ -1809,23 +1809,23 @@  discard block
 block discarded – undo
1809 1809
         }
1810 1810
 
1811 1811
         // Validate the vat number.
1812
-        $result = self::check_vat( $vat_number, $country );
1812
+        $result = self::check_vat($vat_number, $country);
1813 1813
 
1814
-        if ( empty( $result['valid'] ) ) {
1814
+        if (empty($result['valid'])) {
1815 1815
             return wp_sprintf(
1816
-                __( 'Failed to validate the %s number via EU Commission VAT server (VIES).', 'invoicing' ),
1816
+                __('Failed to validate the %s number via EU Commission VAT server (VIES).', 'invoicing'),
1817 1817
                 getpaid_vat_name()
1818 1818
             );
1819 1819
         }
1820 1820
 
1821 1821
         // Validate the company.
1822
-        $vies_company  = ! empty( $result['company'] ) ? $result['company'] : '';
1823
-        $vies_company  = apply_filters( 'wpinv_vies_company_name', $vies_company );
1824
-        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1822
+        $vies_company  = !empty($result['company']) ? $result['company'] : '';
1823
+        $vies_company  = apply_filters('wpinv_vies_company_name', $vies_company);
1824
+        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1825 1825
 
1826
-        if ( ! $valid_company && ! empty( $wpinv_options['vat_disable_company_name_check'] ) ) {
1826
+        if (!$valid_company && !empty($wpinv_options['vat_disable_company_name_check'])) {
1827 1827
            return wp_sprintf(
1828
-                __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ),
1828
+                __('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'),
1829 1829
                 getpaid_vat_name()
1830 1830
             );
1831 1831
         }
Please login to merge, or discard this patch.
includes/data/admin-settings.php 1 patch
Spacing   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -8,201 +8,201 @@  discard block
 block discarded – undo
8 8
  * @version 1.0.19
9 9
  */
10 10
 
11
-defined( 'ABSPATH' ) || exit;
11
+defined('ABSPATH') || exit;
12 12
 
13
-$pages = wpinv_get_pages( true );
13
+$pages = wpinv_get_pages(true);
14 14
     
15 15
 $currencies = wpinv_get_currencies();
16 16
     
17 17
 $currency_code_options = array();
18
-foreach ( $currencies as $code => $name ) {
19
-    $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')';
18
+foreach ($currencies as $code => $name) {
19
+    $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')';
20 20
 }
21 21
     
22 22
 $due_payment_options       = array();
23
-$due_payment_options[0]    = __( 'Now', 'invoicing' );
24
-for ( $i = 1; $i <= 30; $i++ ) {
23
+$due_payment_options[0]    = __('Now', 'invoicing');
24
+for ($i = 1; $i <= 30; $i++) {
25 25
     $due_payment_options[$i] = $i;
26 26
 }
27 27
     
28 28
 $invoice_number_padd_options = array();
29
-for ( $i = 0; $i <= 20; $i++ ) {
29
+for ($i = 0; $i <= 20; $i++) {
30 30
     $invoice_number_padd_options[$i] = $i;
31 31
 }
32 32
     
33 33
 $currency_symbol = wpinv_currency_symbol();
34 34
     
35 35
 $last_number = $reset_number = '';
36
-if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) {
37
-    $last_invoice_number = preg_replace( '/[^0-9]/', '', $last_invoice_number );
36
+if ($last_invoice_number = get_option('wpinv_last_invoice_number')) {
37
+    $last_invoice_number = preg_replace('/[^0-9]/', '', $last_invoice_number);
38 38
 
39
-    if ( !empty( $last_invoice_number ) ) {
40
-        $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number );
39
+    if (!empty($last_invoice_number)) {
40
+        $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number);
41 41
     }
42 42
 
43 43
     $nonce = wp_create_nonce('reset_invoice_count');
44
-    $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>';
44
+    $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>';
45 45
 }
46 46
     
47 47
 $alert_wrapper_start = '<p style="color: #F00">';
48 48
 $alert_wrapper_close = '</p>';
49 49
 
50 50
 return array(
51
-    'general' => apply_filters( 'wpinv_settings_general',
51
+    'general' => apply_filters('wpinv_settings_general',
52 52
         array(
53 53
             'main' => array(
54 54
                 'location_settings' => array(
55 55
                     'id'   => 'location_settings',
56
-                    'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
56
+                    'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
57 57
                     'desc' => '',
58 58
                     'type' => 'header',
59 59
                 ),
60 60
                 'default_country' => array(
61 61
                     'id'      => 'default_country',
62
-                    'name'    => __( 'Default Country', 'invoicing' ),
63
-                    'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
62
+                    'name'    => __('Default Country', 'invoicing'),
63
+                    'desc'    => __('Where does your store operate from?', 'invoicing'),
64 64
                     'type'    => 'select',
65 65
                     'options' => wpinv_get_country_list(),
66 66
                     'std'     => 'GB',
67 67
                     'class'   => 'wpi_select2',
68
-                    'placeholder' => __( 'Select a country', 'invoicing' ),
68
+                    'placeholder' => __('Select a country', 'invoicing'),
69 69
                 ),
70 70
                 'default_state' => array(
71 71
                     'id'      => 'default_state',
72
-                    'name'    => __( 'Default State / Province', 'invoicing' ),
73
-                    'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
72
+                    'name'    => __('Default State / Province', 'invoicing'),
73
+                    'desc'    => __('What state / province does your store operate from?', 'invoicing'),
74 74
                     'type'    => 'country_states',
75 75
                     'class'   => 'wpi_select2',
76
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
76
+                    'placeholder' => __('Select a state', 'invoicing'),
77 77
                 ),
78 78
                 'store_name' => array(
79 79
                     'id'   => 'store_name',
80
-                    'name' => __( 'Store Name', 'invoicing' ),
81
-                    'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
80
+                    'name' => __('Store Name', 'invoicing'),
81
+                    'desc' => __('Store name to print on invoices.', 'invoicing'),
82 82
                     'std'     => get_option('blogname'),
83 83
                     'type' => 'text',
84 84
                 ),
85 85
                 'logo' => array(
86 86
                     'id'   => 'logo',
87
-                    'name' => __( 'Logo URL', 'invoicing' ),
88
-                    'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
87
+                    'name' => __('Logo URL', 'invoicing'),
88
+                    'desc' => __('Store logo to print on invoices.', 'invoicing'),
89 89
                     'type' => 'text',
90 90
                 ),
91 91
                 'store_address' => array(
92 92
                     'id'   => 'store_address',
93
-                    'name' => __( 'Store Address', 'invoicing' ),
94
-                    'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
93
+                    'name' => __('Store Address', 'invoicing'),
94
+                    'desc' => __('Enter the store address to display on invoice', 'invoicing'),
95 95
                     'type' => 'textarea',
96 96
                 ),
97 97
                 'page_settings' => array(
98 98
                     'id'   => 'page_settings',
99
-                    'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
99
+                    'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
100 100
                     'desc' => '',
101 101
                     'type' => 'header',
102 102
                 ),
103 103
                 'checkout_page' => array(
104 104
                     'id'          => 'checkout_page',
105
-                    'name'        => __( 'Checkout Page', 'invoicing' ),
106
-                    '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' ),
105
+                    'name'        => __('Checkout Page', 'invoicing'),
106
+                    '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'),
107 107
                     'type'        => 'select',
108 108
                     'options'     => $pages,
109 109
                     'class'       => 'wpi_select2',
110
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
110
+                    'placeholder' => __('Select a page', 'invoicing'),
111 111
                 ),
112 112
                 'tandc_page' => array(
113 113
                     'id'          => 'tandc_page',
114
-                    'name'        => __( 'Terms & Conditions', 'invoicing' ),
115
-                    'desc'        => __( 'If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing' ),
114
+                    'name'        => __('Terms & Conditions', 'invoicing'),
115
+                    'desc'        => __('If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing'),
116 116
                     'type'        => 'select',
117
-                    'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
117
+                    'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
118 118
                     'class'       => 'wpi_select2',
119
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
119
+                    'placeholder' => __('Select a page', 'invoicing'),
120 120
                 ),
121 121
                 'success_page' => array(
122 122
                     'id'          => 'success_page',
123
-                    'name'        => __( 'Success Page', 'invoicing' ),
124
-                    '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' ),
123
+                    'name'        => __('Success Page', 'invoicing'),
124
+                    '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'),
125 125
                     'type'        => 'select',
126 126
                     'options'     => $pages,
127 127
                     'class'       => 'wpi_select2',
128
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
128
+                    'placeholder' => __('Select a page', 'invoicing'),
129 129
                 ),
130 130
                 'failure_page' => array(
131 131
                     'id'          => 'failure_page',
132
-                    'name'        => __( 'Failed Transaction Page', 'invoicing' ),
133
-                    'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ),
132
+                    'name'        => __('Failed Transaction Page', 'invoicing'),
133
+                    'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'),
134 134
                     'type'        => 'select',
135 135
                     'options'     => $pages,
136 136
                     'class'       => 'wpi_select2',
137
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
137
+                    'placeholder' => __('Select a page', 'invoicing'),
138 138
                 ),
139 139
                 'invoice_history_page' => array(
140 140
                     'id'          => 'invoice_history_page',
141
-                    'name'        => __( 'Invoice History Page', 'invoicing' ),
142
-                    'desc'        => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ),
141
+                    'name'        => __('Invoice History Page', 'invoicing'),
142
+                    'desc'        => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'),
143 143
                     'type'        => 'select',
144 144
                     'options'     => $pages,
145 145
                     'class'       => 'wpi_select2',
146
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
146
+                    'placeholder' => __('Select a page', 'invoicing'),
147 147
                 ),
148 148
                 'invoice_subscription_page' => array(
149 149
                     'id'          => 'invoice_subscription_page',
150
-                    'name'        => __( 'Invoice Subscriptions Page', 'invoicing' ),
151
-                    'desc'        => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ),
150
+                    'name'        => __('Invoice Subscriptions Page', 'invoicing'),
151
+                    'desc'        => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'),
152 152
                     'type'        => 'select',
153 153
                     'options'     => $pages,
154 154
                     'class'       => 'wpi_select2',
155
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
155
+                    'placeholder' => __('Select a page', 'invoicing'),
156 156
                 ),
157 157
             ),
158 158
             'currency_section' => array(
159 159
                 'currency_settings' => array(
160 160
                     'id'   => 'currency_settings',
161
-                    'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
161
+                    'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
162 162
                     'desc' => '',
163 163
                     'type' => 'header',
164 164
                 ),
165 165
                 'currency' => array(
166 166
                     'id'      => 'currency',
167
-                    'name'    => __( 'Currency', 'invoicing' ),
168
-                    'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
167
+                    'name'    => __('Currency', 'invoicing'),
168
+                    'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
169 169
                     'type'    => 'select',
170 170
                     'class'       => 'wpi_select2',
171 171
                     'options' => $currency_code_options,
172 172
                 ),
173 173
                 'currency_position' => array(
174 174
                     'id'      => 'currency_position',
175
-                    'name'    => __( 'Currency Position', 'invoicing' ),
176
-                    'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
175
+                    'name'    => __('Currency Position', 'invoicing'),
176
+                    'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
177 177
                     'type'    => 'select',
178 178
                     'class'   => 'wpi_select2',
179 179
                     'options'  => array(
180
-                        'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
181
-                        'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
182
-                        'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
183
-                        'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
180
+                        'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
181
+                        'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
182
+                        'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
183
+                        'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
184 184
                     )
185 185
                 ),
186 186
                 'thousands_separator' => array(
187 187
                     'id'   => 'thousands_separator',
188
-                    'name' => __( 'Thousands Separator', 'invoicing' ),
189
-                    'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
188
+                    'name' => __('Thousands Separator', 'invoicing'),
189
+                    'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
190 190
                     'type' => 'text',
191 191
                     'size' => 'small',
192 192
                     'std'  => ',',
193 193
                 ),
194 194
                 'decimal_separator' => array(
195 195
                     'id'   => 'decimal_separator',
196
-                    'name' => __( 'Decimal Separator', 'invoicing' ),
197
-                    'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
196
+                    'name' => __('Decimal Separator', 'invoicing'),
197
+                    'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
198 198
                     'type' => 'text',
199 199
                     'size' => 'small',
200 200
                     'std'  => '.',
201 201
                 ),
202 202
                 'decimals' => array(
203 203
                     'id'   => 'decimals',
204
-                    'name' => __( 'Number of Decimals', 'invoicing' ),
205
-                    'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
204
+                    'name' => __('Number of Decimals', 'invoicing'),
205
+                    'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
206 206
                     'type' => 'number',
207 207
                     'size' => 'small',
208 208
                     'std'  => '2',
@@ -214,29 +214,29 @@  discard block
 block discarded – undo
214 214
             'labels' => array(
215 215
                 'labels' => array(
216 216
                     'id'   => 'labels_settings',
217
-                    'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
217
+                    'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
218 218
                     'desc' => '',
219 219
                     'type' => 'header',
220 220
                 ),
221 221
                 'vat_name' => array(
222 222
                     'id' => 'vat_name',
223
-                    'name' => __( 'VAT Name', 'invoicing' ),
224
-                    'desc' => __( 'Enter the VAT name', 'invoicing' ),
223
+                    'name' => __('VAT Name', 'invoicing'),
224
+                    'desc' => __('Enter the VAT name', 'invoicing'),
225 225
                     'type' => 'text',
226 226
                     'size' => 'regular',
227
-                    'std' => __( 'VAT', 'invoicing' ),
227
+                    'std' => __('VAT', 'invoicing'),
228 228
                 ),
229 229
                 'vat_invoice_notice_label' => array(
230 230
                     'id' => 'vat_invoice_notice_label',
231
-                    'name' => __( 'Invoice Notice Label', 'invoicing' ),
232
-                    'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ),
231
+                    'name' => __('Invoice Notice Label', 'invoicing'),
232
+                    'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'),
233 233
                     'type' => 'text',
234 234
                     'size' => 'regular',
235 235
                 ),
236 236
                 'vat_invoice_notice' => array(
237 237
                     'id' => 'vat_invoice_notice',
238
-                    'name' => __( 'Invoice notice', 'invoicing' ),
239
-                    'desc' =>   __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ),
238
+                    'name' => __('Invoice notice', 'invoicing'),
239
+                    'desc' =>   __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'),
240 240
                     'type' => 'text',
241 241
                     'size' => 'regular',
242 242
                 ),
@@ -248,22 +248,22 @@  discard block
 block discarded – undo
248 248
             'main' => array(
249 249
                 'gateway_settings' => array(
250 250
                     'id'   => 'api_header',
251
-                    'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
251
+                    'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
252 252
                     'desc' => '',
253 253
                     'type' => 'header',
254 254
                 ),
255 255
                 'gateways' => array(
256 256
                     'id'      => 'gateways',
257
-                    'name'    => __( 'Payment Gateways', 'invoicing' ),
258
-                    'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
257
+                    'name'    => __('Payment Gateways', 'invoicing'),
258
+                    'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
259 259
                     'type'    => 'gateways',
260 260
                     'std'     => array('manual'=>1),
261 261
                     'options' => wpinv_get_payment_gateways(),
262 262
                 ),
263 263
                 'default_gateway' => array(
264 264
                     'id'      => 'default_gateway',
265
-                    'name'    => __( 'Default Gateway', 'invoicing' ),
266
-                    'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
265
+                    'name'    => __('Default Gateway', 'invoicing'),
266
+                    'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
267 267
                     'type'    => 'gateway_select',
268 268
                     'std'     => 'manual',
269 269
                     'class'   => 'wpi_select2',
@@ -278,19 +278,19 @@  discard block
 block discarded – undo
278 278
             'main' => array(
279 279
                 'tax_settings' => array(
280 280
                     'id'   => 'tax_settings',
281
-                    'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
281
+                    'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
282 282
                     'type' => 'header',
283 283
                 ),
284 284
                 'enable_taxes' => array(
285 285
                     'id'   => 'enable_taxes',
286
-                    'name' => __( 'Enable Taxes', 'invoicing' ),
287
-                    'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
286
+                    'name' => __('Enable Taxes', 'invoicing'),
287
+                    'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
288 288
                     'type' => 'checkbox',
289 289
                 ),
290 290
                 'tax_rate' => array(
291 291
                     'id'   => 'tax_rate',
292
-                    'name' => __( 'Fallback Tax Rate', 'invoicing' ),
293
-                    'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
292
+                    'name' => __('Fallback Tax Rate', 'invoicing'),
293
+                    'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
294 294
                     'type' => 'number',
295 295
                     'size' => 'small',
296 296
                     'min'  => '0',
@@ -302,8 +302,8 @@  discard block
 block discarded – undo
302 302
             'rates' => array(
303 303
                 'tax_rates' => array(
304 304
                     'id'   => 'tax_rates',
305
-                    'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
306
-                    'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
305
+                    'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
306
+                    'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
307 307
                     'type' => 'tax_rates',
308 308
                 ),
309 309
             )
@@ -315,68 +315,68 @@  discard block
 block discarded – undo
315 315
             'main' => array(
316 316
                 'email_settings_header' => array(
317 317
                     'id'   => 'email_settings_header',
318
-                    'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
318
+                    'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
319 319
                     'type' => 'header',
320 320
                 ),
321 321
                 'email_from_name' => array(
322 322
                     'id'   => 'email_from_name',
323
-                    'name' => __( 'From Name', 'invoicing' ),
324
-                    'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
325
-                    'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
323
+                    'name' => __('From Name', 'invoicing'),
324
+                    'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
325
+                    'std' => esc_attr(get_bloginfo('name', 'display')),
326 326
                     'type' => 'text',
327 327
                 ),
328 328
                 'email_from' => array(
329 329
                     'id'   => 'email_from',
330
-                    'name' => __( 'From Email', 'invoicing' ),
331
-                    '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),
332
-                    'std' => get_option( 'admin_email' ),
330
+                    'name' => __('From Email', 'invoicing'),
331
+                    '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),
332
+                    'std' => get_option('admin_email'),
333 333
                     'type' => 'text',
334 334
                 ),
335 335
                 'admin_email' => array(
336 336
                     'id'   => 'admin_email',
337
-                    'name' => __( 'Admin Email', 'invoicing' ),
338
-                    'desc' => __( 'Where should we send admin notifications?', 'invoicing' ),
339
-                    'std' => get_option( 'admin_email' ),
337
+                    'name' => __('Admin Email', 'invoicing'),
338
+                    'desc' => __('Where should we send admin notifications?', 'invoicing'),
339
+                    'std' => get_option('admin_email'),
340 340
                     'type' => 'text',
341 341
                 ),
342 342
                 'overdue_settings_header' => array(
343 343
                     'id'   => 'overdue_settings_header',
344
-                    'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
344
+                    'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
345 345
                     'type' => 'header',
346 346
                 ),
347 347
                 'overdue_active' => array(
348 348
                     'id'   => 'overdue_active',
349
-                    'name' => __( 'Enable Due Date', 'invoicing' ),
350
-                    'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
349
+                    'name' => __('Enable Due Date', 'invoicing'),
350
+                    'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
351 351
                     'type' => 'checkbox',
352 352
                     'std'  => false,
353 353
                 ),
354 354
                 'overdue_days' => array(
355 355
                     'id'          => 'overdue_days',
356
-                    'name'        => __( 'Default Due Date', 'invoicing' ),
357
-                    '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' ),
356
+                    'name'        => __('Default Due Date', 'invoicing'),
357
+                    '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'),
358 358
                     'type'        => 'select',
359 359
                     'options'     => $due_payment_options,
360 360
                     'std'         => 0,
361
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
361
+                    'placeholder' => __('Select a page', 'invoicing'),
362 362
                 ),
363 363
                 'email_template_header' => array(
364 364
                     'id'   => 'email_template_header',
365
-                    'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
365
+                    'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
366 366
                     'type' => 'header',
367 367
                 ),
368 368
                 'email_header_image' => array(
369 369
                     'id'   => 'email_header_image',
370
-                    'name' => __( 'Header Image', 'invoicing' ),
371
-                    'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
370
+                    'name' => __('Header Image', 'invoicing'),
371
+                    'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
372 372
                     'std' => '',
373 373
                     'type' => 'text',
374 374
                 ),
375 375
                 'email_footer_text' => array(
376 376
                     'id'   => 'email_footer_text',
377
-                    'name' => __( 'Footer Text', 'invoicing' ),
378
-                    'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
379
-                    'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
377
+                    'name' => __('Footer Text', 'invoicing'),
378
+                    'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
379
+                    'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
380 380
                     'type' => 'textarea',
381 381
                     'class' => 'regular-text',
382 382
                     'rows' => 2,
@@ -384,29 +384,29 @@  discard block
 block discarded – undo
384 384
                 ),
385 385
                 'email_base_color' => array(
386 386
                     'id'   => 'email_base_color',
387
-                    'name' => __( 'Base Color', 'invoicing' ),
388
-                    'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
387
+                    'name' => __('Base Color', 'invoicing'),
388
+                    'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
389 389
                     'std' => '#557da2',
390 390
                     'type' => 'color',
391 391
                 ),
392 392
                 'email_background_color' => array(
393 393
                     'id'   => 'email_background_color',
394
-                    'name' => __( 'Background Color', 'invoicing' ),
395
-                    'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
394
+                    'name' => __('Background Color', 'invoicing'),
395
+                    'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
396 396
                     'std' => '#f5f5f5',
397 397
                     'type' => 'color',
398 398
                 ),
399 399
                 'email_body_background_color' => array(
400 400
                     'id'   => 'email_body_background_color',
401
-                    'name' => __( 'Body Background Color', 'invoicing' ),
402
-                    'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
401
+                    'name' => __('Body Background Color', 'invoicing'),
402
+                    'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
403 403
                     'std' => '#fdfdfd',
404 404
                     'type' => 'color',
405 405
                 ),
406 406
                 'email_text_color' => array(
407 407
                     'id'   => 'email_text_color',
408
-                    'name' => __( 'Body Text Color', 'invoicing' ),
409
-                    'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
408
+                    'name' => __('Body Text Color', 'invoicing'),
409
+                    'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
410 410
                     'std' => '#505050',
411 411
                     'type' => 'color',
412 412
                 ),
@@ -425,17 +425,17 @@  discard block
 block discarded – undo
425 425
             'main' => array(
426 426
                 'invoicing_privacy_policy_settings' => array(
427 427
                     'id'   => 'invoicing_privacy_policy_settings',
428
-                    'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>',
428
+                    'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>',
429 429
                     'type' => 'header',
430 430
                 ),
431 431
                 'privacy_page' => array(
432 432
                     'id'          => 'privacy_page',
433
-                    'name'        => __( 'Privacy Page', 'invoicing' ),
434
-                    'desc'        => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ),
433
+                    'name'        => __('Privacy Page', 'invoicing'),
434
+                    'desc'        => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'),
435 435
                     'type'        => 'select',
436
-                    'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
436
+                    'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
437 437
                     'class'       => 'wpi_select2',
438
-                    'placeholder' => __( 'Select a page', 'invoicing' ),
438
+                    'placeholder' => __('Select a page', 'invoicing'),
439 439
                 ),
440 440
             ),
441 441
         )
@@ -446,19 +446,19 @@  discard block
 block discarded – undo
446 446
             'main' => array(
447 447
                 'invoice_number_format_settings' => array(
448 448
                     'id'   => 'invoice_number_format_settings',
449
-                    'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
449
+                    'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
450 450
                     'type' => 'header',
451 451
                 ),
452 452
                 'sequential_invoice_number' => array(
453 453
                     'id'   => 'sequential_invoice_number',
454
-                    'name' => __( 'Sequential Invoice Numbers', 'invoicing' ),
455
-                    'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number,
454
+                    'name' => __('Sequential Invoice Numbers', 'invoicing'),
455
+                    'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number,
456 456
                     'type' => 'checkbox',
457 457
                 ),
458 458
                 'invoice_sequence_start' => array(
459 459
                     'id'   => 'invoice_sequence_start',
460
-                    'name' => __( 'Sequential Starting Number', 'invoicing' ),
461
-                    'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number,
460
+                    'name' => __('Sequential Starting Number', 'invoicing'),
461
+                    'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number,
462 462
                     'type' => 'number',
463 463
                     'size' => 'small',
464 464
                     'std'  => '1',
@@ -466,8 +466,8 @@  discard block
 block discarded – undo
466 466
                 ),
467 467
                 'invoice_number_padd' => array(
468 468
                     'id'      => 'invoice_number_padd',
469
-                    'name'    => __( 'Minimum Digits', 'invoicing' ),
470
-                    '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' ),
469
+                    'name'    => __('Minimum Digits', 'invoicing'),
470
+                    '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'),
471 471
                     'type'    => 'select',
472 472
                     'options' => $invoice_number_padd_options,
473 473
                     'std'     => 5,
@@ -475,8 +475,8 @@  discard block
 block discarded – undo
475 475
                 ),
476 476
                 'invoice_number_prefix' => array(
477 477
                     'id' => 'invoice_number_prefix',
478
-                    'name' => __( 'Invoice Number Prefix', 'invoicing' ),
479
-                    'desc' => __( 'Prefix for all invoice numbers. Ex: INV-', 'invoicing' ),
478
+                    'name' => __('Invoice Number Prefix', 'invoicing'),
479
+                    'desc' => __('Prefix for all invoice numbers. Ex: INV-', 'invoicing'),
480 480
                     'type' => 'text',
481 481
                     'size' => 'regular',
482 482
                     'std' => 'INV-',
@@ -484,32 +484,32 @@  discard block
 block discarded – undo
484 484
                 ),
485 485
                 'invoice_number_postfix' => array(
486 486
                     'id' => 'invoice_number_postfix',
487
-                    'name' => __( 'Invoice Number Postfix', 'invoicing' ),
488
-                    'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ),
487
+                    'name' => __('Invoice Number Postfix', 'invoicing'),
488
+                    'desc' => __('Postfix for all invoice numbers.', 'invoicing'),
489 489
                     'type' => 'text',
490 490
                     'size' => 'regular',
491 491
                     'std' => ''
492 492
                 ),
493 493
                 'checkout_settings' => array(
494 494
                     'id'   => 'checkout_settings',
495
-                    'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>',
495
+                    'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>',
496 496
                     'type' => 'header',
497 497
                 ),
498 498
                 'login_to_checkout' => array(
499 499
                     'id'   => 'login_to_checkout',
500
-                    'name' => __( 'Require Login To Checkout', 'invoicing' ),
501
-                    'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ),
500
+                    'name' => __('Require Login To Checkout', 'invoicing'),
501
+                    'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'),
502 502
                     'type' => 'checkbox',
503 503
                 ),
504 504
                 'uninstall_settings' => array(
505 505
                     'id'   => 'uninstall_settings',
506
-                    'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>',
506
+                    'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>',
507 507
                     'type' => 'header',
508 508
                 ),
509 509
                 'remove_data_on_unistall' => array(
510 510
                     'id'   => 'remove_data_on_unistall',
511
-                    'name' => __( 'Remove Data on Uninstall?', 'invoicing' ),
512
-                    'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ),
511
+                    'name' => __('Remove Data on Uninstall?', 'invoicing'),
512
+                    'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'),
513 513
                     'type' => 'checkbox',
514 514
                     'std'  => ''
515 515
                 ),
@@ -518,13 +518,13 @@  discard block
 block discarded – undo
518 518
             'custom-css' => array(
519 519
                 'css_settings' => array(
520 520
                     'id'   => 'css_settings',
521
-                    'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>',
521
+                    'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>',
522 522
                     'type' => 'header',
523 523
                 ),
524 524
                 'template_custom_css' => array(
525 525
                     'id' => 'template_custom_css',
526
-                    'name' => __( 'Invoice Template CSS', 'invoicing' ),
527
-                    'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ),
526
+                    'name' => __('Invoice Template CSS', 'invoicing'),
527
+                    'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'),
528 528
                     'type' => 'textarea',
529 529
                     'class'=> 'regular-text',
530 530
                     'rows' => 10,
@@ -538,8 +538,8 @@  discard block
 block discarded – undo
538 538
             'main' => array(
539 539
                 'tool_settings' => array(
540 540
                     'id'   => 'tool_settings',
541
-                    'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
542
-                    'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
541
+                    'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
542
+                    'desc' => __('Invoicing diagnostic tools', 'invoicing'),
543 543
                     'type' => 'tools',
544 544
                 ),
545 545
             ),
Please login to merge, or discard this patch.
includes/class-getpaid-template.php 1 patch
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
 	 */
27 27
 	public function __construct() {
28 28
 
29
-        $this->templates_dir = apply_filters( 'getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates' );
30
-        $this->templates_url = apply_filters( 'getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates' );
29
+        $this->templates_dir = apply_filters('getpaid_default_templates_dir', WPINV_PLUGIN_DIR . 'templates');
30
+        $this->templates_url = apply_filters('getpaid_default_templates_url', WPINV_PLUGIN_URL . 'templates');
31 31
     }
32 32
 
33 33
     /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @return bool
55 55
 	 */
56 56
 	public function is_elementor_preview() {
57
-		return isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' );
57
+		return isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax');
58 58
 	}
59 59
 
60 60
 	/**
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	 * @return bool
65 65
 	 */
66 66
 	public function is_divi_preview() {
67
-		return isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'et_pb' );
67
+		return isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'et_pb');
68 68
 	}
69 69
 
70 70
 	/**
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 	 * @return bool
75 75
 	 */
76 76
 	public function is_beaver_preview() {
77
-		return isset( $_REQUEST['fl_builder'] );
77
+		return isset($_REQUEST['fl_builder']);
78 78
 	}
79 79
 
80 80
 	/**
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 	 * @return bool
85 85
 	 */
86 86
 	public function is_siteorigin_preview() {
87
-		return ! empty( $_REQUEST['siteorigin_panels_live_editor'] );
87
+		return !empty($_REQUEST['siteorigin_panels_live_editor']);
88 88
 	}
89 89
 
90 90
 	/**
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 	 * @return bool
95 95
 	 */
96 96
 	public function is_cornerstone_preview() {
97
-		return ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint';
97
+		return !empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint';
98 98
 	}
99 99
 
100 100
 	/**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @return bool
105 105
 	 */
106 106
 	public function is_fusion_preview() {
107
-		return ! empty( $_REQUEST['fb-edit'] ) || ! empty( $_REQUEST['fusion_load_nonce'] );
107
+		return !empty($_REQUEST['fb-edit']) || !empty($_REQUEST['fusion_load_nonce']);
108 108
 	}
109 109
 
110 110
 	/**
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
 	 * @return bool
115 115
 	 */
116 116
 	public function is_oxygen_preview() {
117
-		return ! empty( $_REQUEST['ct_builder'] ) || ( ! empty( $_REQUEST['action'] ) && ( substr( $_REQUEST['action'], 0, 11 ) === "oxy_render_" || substr( $_REQUEST['action'], 0, 10 ) === "ct_render_" ) );
117
+		return !empty($_REQUEST['ct_builder']) || (!empty($_REQUEST['action']) && (substr($_REQUEST['action'], 0, 11) === "oxy_render_" || substr($_REQUEST['action'], 0, 10) === "ct_render_"));
118 118
     }
119 119
 
120 120
     /**
@@ -124,25 +124,25 @@  discard block
 block discarded – undo
124 124
      * @param string $template_path The template path relative to the theme's root dir. Defaults to 'invoicing'.
125 125
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
126 126
      */
127
-	public function locate_template( $template_name, $template_path = '', $default_path = '' ) {
127
+	public function locate_template($template_name, $template_path = '', $default_path = '') {
128 128
 
129 129
         // Load the defaults for the template path and default path.
130
-        $template_path = empty( $template_path ) ? 'invoicing' : $template_path;
131
-        $default_path  = empty( $default_path ) ? $this->templates_dir : $default_path;
132
-        $default_path  = apply_filters( 'getpaid_template_default_template_path', $default_path, $template_name );
130
+        $template_path = empty($template_path) ? 'invoicing' : $template_path;
131
+        $default_path  = empty($default_path) ? $this->templates_dir : $default_path;
132
+        $default_path  = apply_filters('getpaid_template_default_template_path', $default_path, $template_name);
133 133
 
134 134
         // Is it overidden?
135 135
         $template = locate_template(
136
-            array( trailingslashit( $template_path ) . $template_name ),
137
-            array( 'wpinv-' . $template_name )
136
+            array(trailingslashit($template_path) . $template_name),
137
+            array('wpinv-' . $template_name)
138 138
         );
139 139
 
140 140
         // If not, load the default template.
141
-        if ( empty( $template ) ) {
142
-            $template = trailingslashit( $default_path ) . $template_name;
141
+        if (empty($template)) {
142
+            $template = trailingslashit($default_path) . $template_name;
143 143
         }
144 144
 
145
-        return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path, $default_path );
145
+        return apply_filters('wpinv_locate_template', $template, $template_name, $template_path, $default_path);
146 146
     }
147 147
     
148 148
     /**
@@ -151,20 +151,20 @@  discard block
 block discarded – undo
151 151
 	 * @since 1.0.19
152 152
 	 * @return bool
153 153
 	 */
154
-	protected function load_template( $template_name, $template_path, $args ) {
154
+	protected function load_template($template_name, $template_path, $args) {
155 155
 
156
-        if ( is_array( $args ) ){
157
-            extract( $args );
156
+        if (is_array($args)) {
157
+            extract($args);
158 158
         }
159 159
 
160 160
         // Fires before loading a template.
161
-	    do_action( 'wpinv_before_template_part', $template_name, $template_path, $args );
161
+	    do_action('wpinv_before_template_part', $template_name, $template_path, $args);
162 162
 
163 163
         // Load the template.
164
-	    include( $template_path );
164
+	    include($template_path);
165 165
 
166 166
         // Fires after loading a template.
167
-        do_action( 'wpinv_after_template_part', $template_name, $template_path, $args );
167
+        do_action('wpinv_after_template_part', $template_name, $template_path, $args);
168 168
 
169 169
     }
170 170
 
@@ -178,18 +178,18 @@  discard block
 block discarded – undo
178 178
      * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
179 179
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
180 180
      */
181
-	public function display_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
181
+	public function display_template($template_name, $args = array(), $template_path = '', $default_path = '') {
182 182
 
183 183
         // Locate the template.
184
-        $located = wpinv_locate_template( $template_name, $template_path, $default_path );
184
+        $located = wpinv_locate_template($template_name, $template_path, $default_path);
185 185
 
186 186
         // Abort if the file does not exist.
187
-        if ( ! file_exists( $located ) ) {
188
-            getpaid_doing_it_wrong( __CLASS__ . '::' .__METHOD__, sprintf( '<code>%s</code> does not exist.', $located ), '1.0.19' );
187
+        if (!file_exists($located)) {
188
+            getpaid_doing_it_wrong(__CLASS__ . '::' . __METHOD__, sprintf('<code>%s</code> does not exist.', $located), '1.0.19');
189 189
             return;
190 190
         }
191 191
 
192
-        $this->load_template( $template_name, $located, $args );
192
+        $this->load_template($template_name, $located, $args);
193 193
 
194 194
     }
195 195
     
@@ -203,9 +203,9 @@  discard block
 block discarded – undo
203 203
      * @param string $template_path The templates directory relative to the theme's root dir. Defaults to 'invoicing'.
204 204
      * @param string $default_path The root path to the default template. Defaults to invoicing/templates
205 205
      */
206
-	public function get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
206
+	public function get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
207 207
         ob_start();
208
-        $this->display_template( $template_name, $args, $template_path, $default_path );
208
+        $this->display_template($template_name, $args, $template_path, $default_path);
209 209
         return ob_get_clean();
210 210
     }
211 211
 
Please login to merge, or discard this patch.
includes/wpinv-general-functions.php 1 patch
Spacing   +135 added lines, -135 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_is_checkout() {
15 15
     global $wp_query;
16 16
 
17
-    $is_object_set    = isset( $wp_query->queried_object );
18
-    $is_object_id_set = isset( $wp_query->queried_object_id );
19
-    $checkout_page    = wpinv_get_option( 'checkout_page' );
20
-    $is_checkout      = ! empty( $checkout_page ) && is_page( $checkout_page );
17
+    $is_object_set    = isset($wp_query->queried_object);
18
+    $is_object_id_set = isset($wp_query->queried_object_id);
19
+    $checkout_page    = wpinv_get_option('checkout_page');
20
+    $is_checkout      = !empty($checkout_page) && is_page($checkout_page);
21 21
 
22
-    if ( !$is_object_set ) {
23
-        unset( $wp_query->queried_object );
22
+    if (!$is_object_set) {
23
+        unset($wp_query->queried_object);
24 24
     }
25 25
 
26
-    if ( !$is_object_id_set ) {
27
-        unset( $wp_query->queried_object_id );
26
+    if (!$is_object_id_set) {
27
+        unset($wp_query->queried_object_id);
28 28
     }
29 29
 
30
-    return apply_filters( 'wpinv_is_checkout', $is_checkout );
30
+    return apply_filters('wpinv_is_checkout', $is_checkout);
31 31
 }
32 32
 
33 33
 function wpinv_can_checkout() {
34 34
 	$can_checkout = true; // Always true for now
35 35
 
36
-	return (bool) apply_filters( 'wpinv_can_checkout', $can_checkout );
36
+	return (bool) apply_filters('wpinv_can_checkout', $can_checkout);
37 37
 }
38 38
 
39 39
 function wpinv_get_success_page_uri() {
40
-	$page_id = wpinv_get_option( 'success_page', 0 );
41
-	$page_id = absint( $page_id );
40
+	$page_id = wpinv_get_option('success_page', 0);
41
+	$page_id = absint($page_id);
42 42
 
43
-	return apply_filters( 'wpinv_get_success_page_uri', get_permalink( $page_id ) );
43
+	return apply_filters('wpinv_get_success_page_uri', get_permalink($page_id));
44 44
 }
45 45
 
46 46
 /**
@@ -49,136 +49,136 @@  discard block
 block discarded – undo
49 49
  * @param string $post_type The post type or invoice type.
50 50
  * @return string The history page URL.
51 51
  */
52
-function wpinv_get_history_page_uri( $post_type = 'wpi_invoice' ) {
53
-    $post_type = sanitize_key( str_replace( 'wpi_', '', $post_type ) );
54
-	$page_id   = wpinv_get_option( "{$post_type}_history_page", 0 );
55
-	$page_id   = absint( $page_id );
56
-	return apply_filters( 'wpinv_get_history_page_uri', get_permalink( $page_id ), $post_type );
52
+function wpinv_get_history_page_uri($post_type = 'wpi_invoice') {
53
+    $post_type = sanitize_key(str_replace('wpi_', '', $post_type));
54
+	$page_id   = wpinv_get_option("{$post_type}_history_page", 0);
55
+	$page_id   = absint($page_id);
56
+	return apply_filters('wpinv_get_history_page_uri', get_permalink($page_id), $post_type);
57 57
 }
58 58
 
59 59
 function wpinv_is_success_page() {
60
-	$is_success_page = wpinv_get_option( 'success_page', false );
61
-	$is_success_page = ! empty( $is_success_page ) ? is_page( $is_success_page ) : false;
60
+	$is_success_page = wpinv_get_option('success_page', false);
61
+	$is_success_page = !empty($is_success_page) ? is_page($is_success_page) : false;
62 62
 
63
-	return apply_filters( 'wpinv_is_success_page', $is_success_page );
63
+	return apply_filters('wpinv_is_success_page', $is_success_page);
64 64
 }
65 65
 
66 66
 function wpinv_is_invoice_history_page() {
67
-	$ret = wpinv_get_option( 'invoice_history_page', false );
68
-	$ret = $ret ? is_page( $ret ) : false;
69
-	return apply_filters( 'wpinv_is_invoice_history_page', $ret );
67
+	$ret = wpinv_get_option('invoice_history_page', false);
68
+	$ret = $ret ? is_page($ret) : false;
69
+	return apply_filters('wpinv_is_invoice_history_page', $ret);
70 70
 }
71 71
 
72 72
 function wpinv_is_subscriptions_history_page() {
73
-    $ret = wpinv_get_option( 'invoice_subscription_page', false );
74
-    $ret = $ret ? is_page( $ret ) : false;
75
-    return apply_filters( 'wpinv_is_subscriptions_history_page', $ret );
73
+    $ret = wpinv_get_option('invoice_subscription_page', false);
74
+    $ret = $ret ? is_page($ret) : false;
75
+    return apply_filters('wpinv_is_subscriptions_history_page', $ret);
76 76
 }
77 77
 
78 78
 /**
79 79
  * Redirects a user the success page.
80 80
  */
81
-function wpinv_send_to_success_page( $args = array() ) {
81
+function wpinv_send_to_success_page($args = array()) {
82 82
     $redirect = add_query_arg(
83
-        wp_parse_args( $args ),
83
+        wp_parse_args($args),
84 84
         wpinv_get_success_page_uri()
85 85
     );
86 86
 
87
-    wp_redirect( $redirect );
87
+    wp_redirect($redirect);
88 88
     exit;
89 89
 }
90 90
 
91
-function wpinv_send_to_failed_page( $args = null ) {
91
+function wpinv_send_to_failed_page($args = null) {
92 92
 	$redirect = wpinv_get_failed_transaction_uri();
93 93
     
94
-    if ( !empty( $args ) ) {
94
+    if (!empty($args)) {
95 95
         // Check for backward compatibility
96
-        if ( is_string( $args ) )
97
-            $args = str_replace( '?', '', $args );
96
+        if (is_string($args))
97
+            $args = str_replace('?', '', $args);
98 98
 
99
-        $args = wp_parse_args( $args );
99
+        $args = wp_parse_args($args);
100 100
 
101
-        $redirect = add_query_arg( $args, $redirect );
101
+        $redirect = add_query_arg($args, $redirect);
102 102
     }
103 103
 
104
-    $gateway = isset( $_REQUEST['wpi-gateway'] ) ? $_REQUEST['wpi-gateway'] : '';
104
+    $gateway = isset($_REQUEST['wpi-gateway']) ? $_REQUEST['wpi-gateway'] : '';
105 105
     
106
-    $redirect = apply_filters( 'wpinv_failed_page_redirect', $redirect, $gateway, $args );
107
-    wp_redirect( $redirect );
106
+    $redirect = apply_filters('wpinv_failed_page_redirect', $redirect, $gateway, $args);
107
+    wp_redirect($redirect);
108 108
     exit;
109 109
 }
110 110
 
111
-function wpinv_get_checkout_uri( $args = array() ) {
112
-	$uri = wpinv_get_option( 'checkout_page', false );
113
-	$uri = isset( $uri ) ? get_permalink( $uri ) : NULL;
111
+function wpinv_get_checkout_uri($args = array()) {
112
+	$uri = wpinv_get_option('checkout_page', false);
113
+	$uri = isset($uri) ? get_permalink($uri) : NULL;
114 114
 
115
-	if ( !empty( $args ) ) {
115
+	if (!empty($args)) {
116 116
 		// Check for backward compatibility
117
-		if ( is_string( $args ) )
118
-			$args = str_replace( '?', '', $args );
117
+		if (is_string($args))
118
+			$args = str_replace('?', '', $args);
119 119
 
120
-		$args = wp_parse_args( $args );
120
+		$args = wp_parse_args($args);
121 121
 
122
-		$uri = add_query_arg( $args, $uri );
122
+		$uri = add_query_arg($args, $uri);
123 123
 	}
124 124
 
125
-	$scheme = defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN ? 'https' : 'admin';
125
+	$scheme = defined('FORCE_SSL_ADMIN') && FORCE_SSL_ADMIN ? 'https' : 'admin';
126 126
 
127
-	$ajax_url = admin_url( 'admin-ajax.php', $scheme );
127
+	$ajax_url = admin_url('admin-ajax.php', $scheme);
128 128
 
129
-	if ( ( ! preg_match( '/^https/', $uri ) && preg_match( '/^https/', $ajax_url ) ) || wpinv_is_ssl_enforced() ) {
130
-		$uri = preg_replace( '/^http:/', 'https:', $uri );
129
+	if ((!preg_match('/^https/', $uri) && preg_match('/^https/', $ajax_url)) || wpinv_is_ssl_enforced()) {
130
+		$uri = preg_replace('/^http:/', 'https:', $uri);
131 131
 	}
132 132
 
133
-	return apply_filters( 'wpinv_get_checkout_uri', $uri );
133
+	return apply_filters('wpinv_get_checkout_uri', $uri);
134 134
 }
135 135
 
136
-function wpinv_get_success_page_url( $query_string = null ) {
137
-	$success_page = wpinv_get_option( 'success_page', 0 );
138
-	$success_page = get_permalink( $success_page );
136
+function wpinv_get_success_page_url($query_string = null) {
137
+	$success_page = wpinv_get_option('success_page', 0);
138
+	$success_page = get_permalink($success_page);
139 139
 
140
-	if ( $query_string )
140
+	if ($query_string)
141 141
 		$success_page .= $query_string;
142 142
 
143
-	return apply_filters( 'wpinv_success_page_url', $success_page );
143
+	return apply_filters('wpinv_success_page_url', $success_page);
144 144
 }
145 145
 
146
-function wpinv_get_failed_transaction_uri( $extras = false ) {
147
-	$uri = wpinv_get_option( 'failure_page', '' );
148
-	$uri = ! empty( $uri ) ? trailingslashit( get_permalink( $uri ) ) : home_url();
146
+function wpinv_get_failed_transaction_uri($extras = false) {
147
+	$uri = wpinv_get_option('failure_page', '');
148
+	$uri = !empty($uri) ? trailingslashit(get_permalink($uri)) : home_url();
149 149
 
150
-	if ( $extras )
150
+	if ($extras)
151 151
 		$uri .= $extras;
152 152
 
153
-	return apply_filters( 'wpinv_get_failed_transaction_uri', $uri );
153
+	return apply_filters('wpinv_get_failed_transaction_uri', $uri);
154 154
 }
155 155
 
156 156
 function wpinv_is_failed_transaction_page() {
157
-	$ret = wpinv_get_option( 'failure_page', false );
158
-	$ret = isset( $ret ) ? is_page( $ret ) : false;
157
+	$ret = wpinv_get_option('failure_page', false);
158
+	$ret = isset($ret) ? is_page($ret) : false;
159 159
 
160
-	return apply_filters( 'wpinv_is_failure_page', $ret );
160
+	return apply_filters('wpinv_is_failure_page', $ret);
161 161
 }
162 162
 
163
-function wpinv_transaction_query( $type = 'start' ) {
163
+function wpinv_transaction_query($type = 'start') {
164 164
     global $wpdb;
165 165
 
166 166
     $wpdb->hide_errors();
167 167
 
168
-    if ( ! defined( 'WPINV_USE_TRANSACTIONS' ) ) {
169
-        define( 'WPINV_USE_TRANSACTIONS', true );
168
+    if (!defined('WPINV_USE_TRANSACTIONS')) {
169
+        define('WPINV_USE_TRANSACTIONS', true);
170 170
     }
171 171
 
172
-    if ( WPINV_USE_TRANSACTIONS ) {
173
-        switch ( $type ) {
172
+    if (WPINV_USE_TRANSACTIONS) {
173
+        switch ($type) {
174 174
             case 'commit' :
175
-                $wpdb->query( 'COMMIT' );
175
+                $wpdb->query('COMMIT');
176 176
                 break;
177 177
             case 'rollback' :
178
-                $wpdb->query( 'ROLLBACK' );
178
+                $wpdb->query('ROLLBACK');
179 179
                 break;
180 180
             default :
181
-                $wpdb->query( 'START TRANSACTION' );
181
+                $wpdb->query('START TRANSACTION');
182 182
             break;
183 183
         }
184 184
     }
@@ -187,141 +187,141 @@  discard block
 block discarded – undo
187 187
 function wpinv_get_prefix() {
188 188
     $invoice_prefix = 'INV-';
189 189
     
190
-    return apply_filters( 'wpinv_get_prefix', $invoice_prefix );
190
+    return apply_filters('wpinv_get_prefix', $invoice_prefix);
191 191
 }
192 192
 
193 193
 function wpinv_get_business_logo() {
194
-    $business_logo = wpinv_get_option( 'logo' );
195
-    return apply_filters( 'wpinv_get_business_logo', $business_logo );
194
+    $business_logo = wpinv_get_option('logo');
195
+    return apply_filters('wpinv_get_business_logo', $business_logo);
196 196
 }
197 197
 
198 198
 function wpinv_get_business_name() {
199 199
     $business_name = wpinv_get_option('store_name');
200
-    return apply_filters( 'wpinv_get_business_name', $business_name );
200
+    return apply_filters('wpinv_get_business_name', $business_name);
201 201
 }
202 202
 
203 203
 function wpinv_get_blogname() {
204
-    return wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
204
+    return wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
205 205
 }
206 206
 
207 207
 function wpinv_get_admin_email() {
208
-    $admin_email = wpinv_get_option( 'admin_email', get_option( 'admin_email' ) );
209
-    return apply_filters( 'wpinv_admin_email', $admin_email );
208
+    $admin_email = wpinv_get_option('admin_email', get_option('admin_email'));
209
+    return apply_filters('wpinv_admin_email', $admin_email);
210 210
 }
211 211
 
212 212
 function wpinv_get_business_website() {
213
-    $business_website = home_url( '/' );
214
-    return apply_filters( 'wpinv_get_business_website', $business_website );
213
+    $business_website = home_url('/');
214
+    return apply_filters('wpinv_get_business_website', $business_website);
215 215
 }
216 216
 
217
-function wpinv_get_terms_text( $invoice_id = 0 ) {
217
+function wpinv_get_terms_text($invoice_id = 0) {
218 218
     $terms_text = '';
219
-    return apply_filters( 'wpinv_get_terms_text', $terms_text, $invoice_id );
219
+    return apply_filters('wpinv_get_terms_text', $terms_text, $invoice_id);
220 220
 }
221 221
 
222 222
 function wpinv_get_business_footer() {
223
-    $site_link = '<a target="_blank" href="' . esc_url( wpinv_get_business_website() ) . '">' . esc_html( wpinv_get_business_name() ) . '</a>';
224
-    $business_footer = wp_sprintf( __( 'Thanks for using %s', 'invoicing' ), $site_link );
225
-    return apply_filters( 'wpinv_get_business_footer', $business_footer );
223
+    $site_link = '<a target="_blank" href="' . esc_url(wpinv_get_business_website()) . '">' . esc_html(wpinv_get_business_name()) . '</a>';
224
+    $business_footer = wp_sprintf(__('Thanks for using %s', 'invoicing'), $site_link);
225
+    return apply_filters('wpinv_get_business_footer', $business_footer);
226 226
 }
227 227
 
228 228
 function wpinv_checkout_required_fields() {
229 229
     $required_fields = array();
230 230
     
231 231
     // Let payment gateways and other extensions determine if address fields should be required
232
-    $require_billing_details = apply_filters( 'wpinv_checkout_required_billing_details', wpinv_use_taxes() );
232
+    $require_billing_details = apply_filters('wpinv_checkout_required_billing_details', wpinv_use_taxes());
233 233
     
234
-    if ( $require_billing_details ) {
235
-		if ( (bool)wpinv_get_option( 'fname_mandatory' ) ) {
234
+    if ($require_billing_details) {
235
+		if ((bool) wpinv_get_option('fname_mandatory')) {
236 236
 			$required_fields['first_name'] = array(
237 237
 				'error_id' => 'invalid_first_name',
238
-				'error_message' => __( 'Please enter your first name', 'invoicing' )
238
+				'error_message' => __('Please enter your first name', 'invoicing')
239 239
 			);
240 240
 		}
241
-		if ( (bool)wpinv_get_option( 'address_mandatory' ) ) {
241
+		if ((bool) wpinv_get_option('address_mandatory')) {
242 242
 			$required_fields['address'] = array(
243 243
 				'error_id' => 'invalid_address',
244
-				'error_message' => __( 'Please enter your address', 'invoicing' )
244
+				'error_message' => __('Please enter your address', 'invoicing')
245 245
 			);
246 246
 		}
247
-		if ( (bool)wpinv_get_option( 'city_mandatory' ) ) {
247
+		if ((bool) wpinv_get_option('city_mandatory')) {
248 248
 			$required_fields['city'] = array(
249 249
 				'error_id' => 'invalid_city',
250
-				'error_message' => __( 'Please enter your billing city', 'invoicing' )
250
+				'error_message' => __('Please enter your billing city', 'invoicing')
251 251
 			);
252 252
 		}
253
-		if ( (bool)wpinv_get_option( 'state_mandatory' ) ) {
253
+		if ((bool) wpinv_get_option('state_mandatory')) {
254 254
 			$required_fields['state'] = array(
255 255
 				'error_id' => 'invalid_state',
256
-				'error_message' => __( 'Please enter billing state / province', 'invoicing' )
256
+				'error_message' => __('Please enter billing state / province', 'invoicing')
257 257
 			);
258 258
 		}
259
-		if ( (bool)wpinv_get_option( 'country_mandatory' ) ) {
259
+		if ((bool) wpinv_get_option('country_mandatory')) {
260 260
 			$required_fields['country'] = array(
261 261
 				'error_id' => 'invalid_country',
262
-				'error_message' => __( 'Please select your billing country', 'invoicing' )
262
+				'error_message' => __('Please select your billing country', 'invoicing')
263 263
 			);
264 264
 		}
265 265
     }
266 266
 
267
-    return apply_filters( 'wpinv_checkout_required_fields', $required_fields );
267
+    return apply_filters('wpinv_checkout_required_fields', $required_fields);
268 268
 }
269 269
 
270 270
 function wpinv_is_ssl_enforced() {
271
-    $ssl_enforced = wpinv_get_option( 'enforce_ssl', false );
272
-    return (bool) apply_filters( 'wpinv_is_ssl_enforced', $ssl_enforced );
271
+    $ssl_enforced = wpinv_get_option('enforce_ssl', false);
272
+    return (bool) apply_filters('wpinv_is_ssl_enforced', $ssl_enforced);
273 273
 }
274 274
 
275 275
 function wpinv_schedule_event_twicedaily() {
276 276
     wpinv_email_payment_reminders();
277 277
 }
278
-add_action( 'wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily' );
278
+add_action('wpinv_register_schedule_event_daily', 'wpinv_schedule_event_twicedaily');
279 279
 
280 280
 function wpinv_require_login_to_checkout() {
281
-    $return = wpinv_get_option( 'login_to_checkout', false );
282
-    return (bool) apply_filters( 'wpinv_require_login_to_checkout', $return );
281
+    $return = wpinv_get_option('login_to_checkout', false);
282
+    return (bool) apply_filters('wpinv_require_login_to_checkout', $return);
283 283
 }
284 284
 
285
-function wpinv_sequential_number_active( $type = '' ) {
286
-    $check = apply_filters( 'wpinv_pre_check_sequential_number_active', null, $type );
287
-    if ( null !== $check ) {
285
+function wpinv_sequential_number_active($type = '') {
286
+    $check = apply_filters('wpinv_pre_check_sequential_number_active', null, $type);
287
+    if (null !== $check) {
288 288
         return $check;
289 289
     }
290 290
     
291
-    return wpinv_get_option( 'sequential_invoice_number' );
291
+    return wpinv_get_option('sequential_invoice_number');
292 292
 }
293 293
 
294
-function wpinv_switch_to_locale( $locale = NULL ) {
294
+function wpinv_switch_to_locale($locale = NULL) {
295 295
     global $invoicing, $wpi_switch_locale;
296 296
 
297
-    if ( ! empty( $invoicing ) && function_exists( 'switch_to_locale' ) ) {
298
-        $locale = empty( $locale ) ? get_locale() : $locale;
297
+    if (!empty($invoicing) && function_exists('switch_to_locale')) {
298
+        $locale = empty($locale) ? get_locale() : $locale;
299 299
 
300
-        switch_to_locale( $locale );
300
+        switch_to_locale($locale);
301 301
 
302 302
         $wpi_switch_locale = $locale;
303 303
 
304
-        add_filter( 'plugin_locale', 'get_locale' );
304
+        add_filter('plugin_locale', 'get_locale');
305 305
 
306 306
         $invoicing->load_textdomain();
307 307
 
308
-        do_action( 'wpinv_switch_to_locale', $locale );
308
+        do_action('wpinv_switch_to_locale', $locale);
309 309
     }
310 310
 }
311 311
 
312 312
 function wpinv_restore_locale() {
313 313
     global $invoicing, $wpi_switch_locale;
314 314
     
315
-    if ( ! empty( $invoicing ) && function_exists( 'restore_previous_locale' ) && $wpi_switch_locale ) {
315
+    if (!empty($invoicing) && function_exists('restore_previous_locale') && $wpi_switch_locale) {
316 316
         restore_previous_locale();
317 317
 
318 318
         $wpi_switch_locale = NULL;
319 319
 
320
-        remove_filter( 'plugin_locale', 'get_locale' );
320
+        remove_filter('plugin_locale', 'get_locale');
321 321
 
322 322
         $invoicing->load_textdomain();
323 323
 
324
-        do_action( 'wpinv_restore_locale' );
324
+        do_action('wpinv_restore_locale');
325 325
     }
326 326
 }
327 327
 
@@ -329,22 +329,22 @@  discard block
 block discarded – undo
329 329
  * Returns the default form's id.
330 330
  */
331 331
 function wpinv_get_default_payment_form() {
332
-    $form = get_option( 'wpinv_default_payment_form' );
332
+    $form = get_option('wpinv_default_payment_form');
333 333
 
334
-    if ( empty( $form ) || 'publish' != get_post_status( $form ) ) {
334
+    if (empty($form) || 'publish' != get_post_status($form)) {
335 335
         $form = wp_insert_post(
336 336
             array(
337 337
                 'post_type'   => 'wpi_payment_form',
338
-                'post_title'  => __( 'Checkout (default)', 'invoicing' ),
338
+                'post_title'  => __('Checkout (default)', 'invoicing'),
339 339
                 'post_status' => 'publish',
340 340
                 'meta_input'  => array(
341
-                    'wpinv_form_elements' => wpinv_get_data( 'default-payment-form' ),
341
+                    'wpinv_form_elements' => wpinv_get_data('default-payment-form'),
342 342
                     'wpinv_form_items'    => array(),
343 343
                 )
344 344
             )
345 345
         );
346 346
 
347
-        update_option( 'wpinv_default_payment_form', $form );
347
+        update_option('wpinv_default_payment_form', $form);
348 348
     }
349 349
 
350 350
     return $form;
@@ -355,19 +355,19 @@  discard block
 block discarded – undo
355 355
  * 
356 356
  * @param int $payment_form
357 357
  */
358
-function getpaid_get_payment_form_elements( $payment_form ) {
358
+function getpaid_get_payment_form_elements($payment_form) {
359 359
 
360
-    if ( empty( $payment_form ) ) {
361
-        return wpinv_get_data( 'sample-payment-form' );
360
+    if (empty($payment_form)) {
361
+        return wpinv_get_data('sample-payment-form');
362 362
     }
363 363
 
364
-    $form_elements = get_post_meta( $payment_form, 'wpinv_form_elements', true );
364
+    $form_elements = get_post_meta($payment_form, 'wpinv_form_elements', true);
365 365
 
366
-    if ( is_array( $form_elements ) ) {
366
+    if (is_array($form_elements)) {
367 367
         return $form_elements;
368 368
     }
369 369
 
370
-    return wpinv_get_data( 'sample-payment-form' );
370
+    return wpinv_get_data('sample-payment-form');
371 371
 
372 372
 }
373 373
 
@@ -376,13 +376,13 @@  discard block
 block discarded – undo
376 376
  * 
377 377
  * @param int $payment_form
378 378
  */
379
-function gepaid_get_form_items( $id ) {
380
-    $form = new GetPaid_Payment_Form( $id );
379
+function gepaid_get_form_items($id) {
380
+    $form = new GetPaid_Payment_Form($id);
381 381
 
382 382
     // Is this a default form?
383
-    if ( $form->is_default() ) {
383
+    if ($form->is_default()) {
384 384
         return array();
385 385
     }
386 386
 
387
-    return $form->get_items( 'view', 'arrays' );
387
+    return $form->get_items('view', 'arrays');
388 388
 }
Please login to merge, or discard this patch.
includes/api/class-wpinv-rest-invoice-controller.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  * @version 1.0.19
6 6
  */
7 7
 
8
-defined( 'ABSPATH' ) || exit;
8
+defined('ABSPATH') || exit;
9 9
 
10 10
 /**
11 11
  * REST API invoices controller class.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 
53 53
 
54 54
 				'customers' => array(
55
-					'description'       => __( 'Limit result set to invoices for specific user ids.', 'invoicing' ),
55
+					'description'       => __('Limit result set to invoices for specific user ids.', 'invoicing'),
56 56
 					'type'              => 'array',
57 57
 					'items'             => array(
58 58
 						'type'          => 'integer',
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 				),
63 63
 
64 64
 				'exclude_customers'  	=> array(
65
-					'description' 		=> __( 'Exclude invoices to specific users.', 'invoicing' ),
65
+					'description' 		=> __('Exclude invoices to specific users.', 'invoicing'),
66 66
 					'type'        		=> 'array',
67 67
 					'items'       		=> array(
68 68
 						'type'          => 'integer',
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
 				),
73 73
 
74 74
 				'parent'  	            => array(
75
-					'description'       => __( 'Limit result set to those of particular parent IDs.', 'invoicing' ),
75
+					'description'       => __('Limit result set to those of particular parent IDs.', 'invoicing'),
76 76
 					'type'              => 'array',
77 77
 					'items'             => array(
78 78
 						'type'          => 'integer',
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 				),
83 83
 
84 84
 				'parent_exclude'  	    => array(
85
-					'description'       => __( 'Limit result set to all items except those of a particular parent ID.', 'invoicing' ),
85
+					'description'       => __('Limit result set to all items except those of a particular parent ID.', 'invoicing'),
86 86
 					'type'              => 'array',
87 87
 					'items'             => array(
88 88
 						'type'          => 'integer',
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 		);
97 97
 
98 98
 		// Filter collection parameters for the invoices controller.
99
-		return apply_filters( 'getpaid_rest_invoices_collection_params', $params, $this );
99
+		return apply_filters('getpaid_rest_invoices_collection_params', $params, $this);
100 100
 	}
101 101
 
102 102
 	/**
@@ -107,21 +107,21 @@  discard block
 block discarded – undo
107 107
 	 * @param WP_REST_Request $request Request object.
108 108
 	 * @return array          $query_args
109 109
 	 */
110
-	protected function prepare_items_query( $prepared_args = array(), $request = null ) {
110
+	protected function prepare_items_query($prepared_args = array(), $request = null) {
111 111
 
112
-		$query_args = parent::prepare_items_query( $prepared_args );
112
+		$query_args = parent::prepare_items_query($prepared_args);
113 113
 
114 114
 		// Retrieve invoices for specific customers.
115
-		if ( ! empty( $request['customers'] ) ) {
115
+		if (!empty($request['customers'])) {
116 116
 			$query_args['author__in'] = $request['customers'];
117 117
 		}
118 118
 
119 119
 		// Skip invoices for specific customers.
120
-		if ( ! empty( $request['exclude_customers'] ) ) {
120
+		if (!empty($request['exclude_customers'])) {
121 121
 			$query_args['author__not_in'] = $request['exclude_customers'];
122 122
 		}
123 123
 
124
-		return apply_filters( 'getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this );
124
+		return apply_filters('getpaid_rest_invoices_prepare_items_query', $query_args, $request, $this);
125 125
 
126 126
 	}
127 127
 
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 	 * @return array A list of registered item statuses.
134 134
 	 */
135 135
 	public function get_post_statuses() {
136
-		return array_keys( wpinv_get_invoice_statuses( true, false, $this->post_type ) );
136
+		return array_keys(wpinv_get_invoice_statuses(true, false, $this->post_type));
137 137
 	}
138 138
 
139 139
 	/**
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
 	 * @param WPInv_Invoice $invoice Invoice to save.
143 143
 	 * @return WP_Error|WPInv_Invoice
144 144
 	 */
145
-	protected function save_object( $invoice ) {
145
+	protected function save_object($invoice) {
146 146
 		$invoice->recalculate_total();
147
-		return parent::save_object( $invoice );
147
+		return parent::save_object($invoice);
148 148
 	}
149 149
 
150 150
 }
Please login to merge, or discard this patch.