Passed
Push — master ( 1a4515...55ed87 )
by Stiofan
02:32 queued 12s
created
includes/wpinv-gateway-functions.php 1 patch
Spacing   +258 added lines, -258 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Test Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Test Payment', 'invoicing' ),
38
+            'admin_label'    => __('Test Payment', 'invoicing'),
39
+            'checkout_label' => __('Test Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
     
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
         
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
     
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
     
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( !( (float)wpinv_payment_total( $payment ) > 0 ) ) {
129
-            $label = __( 'Free Purchase', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (!((float)wpinv_payment_total($payment) > 0)) {
129
+            $label = __('Free Purchase', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,27 +383,27 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing' );
391
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_active']['desc'] = $setting['paypal_active']['desc'] . ' ' . __('( Supported Currencies: AUD, BRL, CAD, CZK, DKK, EUR, HKD, HUF, ILS, JPY, MYR, MXN, NOK, NZD, PHP, PLN, GBP, SGD, SEK, CHF, TWD, THB, USD )', 'invoicing');
391
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
392 392
     
393 393
     $setting['paypal_sandbox'] = array(
394 394
             'type' => 'checkbox',
395 395
             'id'   => 'paypal_sandbox',
396
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
397
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
396
+            'name' => __('PayPal Sandbox', 'invoicing'),
397
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
398 398
             'std'  => 1
399 399
         );
400 400
         
401 401
     $setting['paypal_email'] = array(
402 402
             'type' => 'text',
403 403
             'id'   => 'paypal_email',
404
-            'name' => __( 'PayPal Email', 'invoicing' ),
405
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
406
-            'std' => __( '[email protected]', 'invoicing' ),
404
+            'name' => __('PayPal Email', 'invoicing'),
405
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
406
+            'std' => __('[email protected]', 'invoicing'),
407 407
         );
408 408
     /*
409 409
     $setting['paypal_ipn_url'] = array(
@@ -417,139 +417,139 @@  discard block
 block discarded – undo
417 417
         
418 418
     return $setting;
419 419
 }
420
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
420
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
421 421
 
422 422
 // Pre Bank Transfer settings
423
-function wpinv_gateway_settings_bank_transfer( $setting ) {
424
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
423
+function wpinv_gateway_settings_bank_transfer($setting) {
424
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
425 425
     
426 426
     $setting['bank_transfer_ac_name'] = array(
427 427
             'type' => 'text',
428 428
             'id' => 'bank_transfer_ac_name',
429
-            'name' => __( 'Account Name', 'invoicing' ),
430
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
431
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
429
+            'name' => __('Account Name', 'invoicing'),
430
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
431
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
432 432
         );
433 433
     
434 434
     $setting['bank_transfer_ac_no'] = array(
435 435
             'type' => 'text',
436 436
             'id' => 'bank_transfer_ac_no',
437
-            'name' => __( 'Account Number', 'invoicing' ),
438
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
439
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
437
+            'name' => __('Account Number', 'invoicing'),
438
+            'desc' => __('Enter your bank account number.', 'invoicing'),
439
+            'std'  =>  __('TEST1234567890', 'invoicing'),
440 440
         );
441 441
     
442 442
     $setting['bank_transfer_bank_name'] = array(
443 443
             'type' => 'text',
444 444
             'id'   => 'bank_transfer_bank_name',
445
-            'name' => __( 'Bank Name', 'invoicing' ),
446
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
447
-            'std' => __( 'ICICI Bank', 'invoicing' ),
445
+            'name' => __('Bank Name', 'invoicing'),
446
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
447
+            'std' => __('ICICI Bank', 'invoicing'),
448 448
         );
449 449
     
450 450
     $setting['bank_transfer_ifsc'] = array(
451 451
             'type' => 'text',
452 452
             'id'   => 'bank_transfer_ifsc',
453
-            'name' => __( 'IFSC Code', 'invoicing' ),
454
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
455
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
453
+            'name' => __('IFSC Code', 'invoicing'),
454
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
455
+            'std'  =>  __('ICIC0001234', 'invoicing'),
456 456
         );
457 457
         
458 458
     $setting['bank_transfer_iban'] = array(
459 459
             'type' => 'text',
460 460
             'id'   => 'bank_transfer_iban',
461
-            'name' => __( 'IBAN', 'invoicing' ),
462
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
463
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
461
+            'name' => __('IBAN', 'invoicing'),
462
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
463
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
464 464
         );
465 465
         
466 466
     $setting['bank_transfer_bic'] = array(
467 467
             'type' => 'text',
468 468
             'id'   => 'bank_transfer_bic',
469
-            'name' => __( 'BIC/Swift Code', 'invoicing' ),
470
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
469
+            'name' => __('BIC/Swift Code', 'invoicing'),
470
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
471 471
         );
472 472
 
473 473
     $setting['bank_transfer_sort_code'] = array(
474 474
         'type' => 'text',
475 475
         'id'   => 'bank_transfer_sort_code',
476
-        'name' => __( 'Sort Code', 'invoicing' ),
477
-        'std'  =>  __( '12-34-56', 'invoicing' ),
476
+        'name' => __('Sort Code', 'invoicing'),
477
+        'std'  =>  __('12-34-56', 'invoicing'),
478 478
     );
479 479
         
480 480
     $setting['bank_transfer_info'] = array(
481 481
             'id'   => 'bank_transfer_info',
482
-            'name' => __( 'Instructions', 'invoicing' ),
483
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
482
+            'name' => __('Instructions', 'invoicing'),
483
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
484 484
             'type' => 'textarea',
485
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
485
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
486 486
             'cols' => 37,
487 487
             'rows' => 5
488 488
         );
489 489
         
490 490
     return $setting;
491 491
 }
492
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
492
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
493 493
 
494 494
 // Authorize.Net settings
495
-function wpinv_gateway_settings_authorizenet( $setting ) {
496
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
497
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing' );
495
+function wpinv_gateway_settings_authorizenet($setting) {
496
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( Supported Currencies: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
497
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process Credit card / Debit card transactions.', 'invoicing');
498 498
     
499 499
     $setting['authorizenet_sandbox'] = array(
500 500
             'type' => 'checkbox',
501 501
             'id'   => 'authorizenet_sandbox',
502
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
503
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
502
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
503
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
504 504
             'std'  => 1
505 505
         );
506 506
         
507 507
     $setting['authorizenet_login_id'] = array(
508 508
             'type' => 'text',
509 509
             'id'   => 'authorizenet_login_id',
510
-            'name' => __( 'API Login ID', 'invoicing' ),
511
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
510
+            'name' => __('API Login ID', 'invoicing'),
511
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
512 512
             'std' => '2j4rBekUnD',
513 513
         );
514 514
     
515 515
     $setting['authorizenet_transaction_key'] = array(
516 516
             'type' => 'text',
517 517
             'id'   => 'authorizenet_transaction_key',
518
-            'name' => __( 'Transaction Key', 'invoicing' ),
519
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
518
+            'name' => __('Transaction Key', 'invoicing'),
519
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
520 520
             'std' => '4vyBUOJgR74679xa',
521 521
         );
522 522
         
523 523
     $setting['authorizenet_md5_hash'] = array(
524 524
             'type' => 'text',
525 525
             'id'   => 'authorizenet_md5_hash',
526
-            'name' => __( 'MD5-Hash', 'invoicing' ),
527
-            'desc' => __( 'The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
526
+            'name' => __('MD5-Hash', 'invoicing'),
527
+            'desc' => __('The MD5 Hash security feature allows to authenticate transaction responses from the Authorize.Net for recurring payments. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
528 528
             'std' => '',
529 529
         );
530 530
 
531 531
     $setting['authorizenet_transaction_type'] = array(
532 532
         'id'          => 'authorizenet_transaction_type',
533
-        'name'        => __( 'Transaction Type', 'invoicing' ),
534
-        'desc'        => __( 'Choose transaction type.', 'invoicing' ),
533
+        'name'        => __('Transaction Type', 'invoicing'),
534
+        'desc'        => __('Choose transaction type.', 'invoicing'),
535 535
         'type'        => 'select',
536 536
         'class'       => 'wpi_select2',
537 537
         'options'     => array(
538
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
539
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
538
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
539
+            'authorize_only' => __('Authorize Only', 'invoicing'),
540 540
         ),
541 541
         'std'         => 'authorize_capture'
542 542
     );
543 543
 
544 544
     $setting['authorizenet_transaction_type_recurring'] = array(
545 545
         'id'          => 'authorizenet_transaction_type_recurring',
546
-        'name'        => __( 'Transaction Type for Recurring', 'invoicing' ),
547
-        'desc'        => __( 'Choose transaction type for recurring payments.', 'invoicing' ),
546
+        'name'        => __('Transaction Type for Recurring', 'invoicing'),
547
+        'desc'        => __('Choose transaction type for recurring payments.', 'invoicing'),
548 548
         'type'        => 'select',
549 549
         'class'       => 'wpi_select2',
550 550
         'options'     => array(
551
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
552
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
551
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
552
+            'authorize_only' => __('Authorize Only', 'invoicing'),
553 553
         ),
554 554
         'std'         => 'authorize_only'
555 555
     );
@@ -557,9 +557,9 @@  discard block
 block discarded – undo
557 557
     $setting['authorizenet_ipn_url'] = array(
558 558
             'type' => 'ipn_url',
559 559
             'id'   => 'authorizenet_ipn_url',
560
-            'name' => __( 'Silent Post URL', 'invoicing' ),
561
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
562
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
560
+            'name' => __('Silent Post URL', 'invoicing'),
561
+            'std' => wpinv_get_ipn_url('authorizenet'),
562
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
563 563
             'size' => 'large',
564 564
             'custom' => 'authorizenet',
565 565
             'readonly' => true
@@ -567,26 +567,26 @@  discard block
 block discarded – undo
567 567
         
568 568
     return $setting;
569 569
 }
570
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
570
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
571 571
 
572 572
 // Worldpay settings
573
-function wpinv_gateway_settings_worldpay( $setting ) {
574
-    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __( '( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing' );
575
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' );
573
+function wpinv_gateway_settings_worldpay($setting) {
574
+    $setting['worldpay_active']['desc'] = $setting['worldpay_active']['desc'] . ' ' . __('( Supported Currencies: AUD, ARS, CAD, CHF, DKK, EUR, HKD, MYR, GBP, NZD, NOK, SGD, LKR, SEK, TRY, USD, ZAR )', 'invoicing');
575
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing');
576 576
     
577 577
     $setting['worldpay_sandbox'] = array(
578 578
             'type' => 'checkbox',
579 579
             'id'   => 'worldpay_sandbox',
580
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
581
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
580
+            'name' => __('Worldpay Test Mode', 'invoicing'),
581
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
582 582
             'std'  => 1
583 583
         );
584 584
         
585 585
     $setting['worldpay_instId'] = array(
586 586
             'type' => 'text',
587 587
             'id'   => 'worldpay_instId',
588
-            'name' => __( 'Installation Id', 'invoicing' ),
589
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
588
+            'name' => __('Installation Id', 'invoicing'),
589
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
590 590
             'std' => '211616',
591 591
         );
592 592
     /*
@@ -602,9 +602,9 @@  discard block
 block discarded – undo
602 602
     $setting['worldpay_ipn_url'] = array(
603 603
             'type' => 'ipn_url',
604 604
             'id'   => 'worldpay_ipn_url',
605
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
606
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
607
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
605
+            'name' => __('Worldpay Callback Url', 'invoicing'),
606
+            'std' => wpinv_get_ipn_url('worldpay'),
607
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
608 608
             'size' => 'large',
609 609
             'custom' => 'worldpay',
610 610
             'readonly' => true
@@ -612,99 +612,99 @@  discard block
 block discarded – undo
612 612
         
613 613
     return $setting;
614 614
 }
615
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
615
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
616 616
 
617
-function wpinv_ipn_url_callback( $args ) {    
618
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
617
+function wpinv_ipn_url_callback($args) {    
618
+    $sanitize_id = wpinv_sanitize_key($args['id']);
619 619
     
620 620
     $attrs = $args['readonly'] ? ' readonly' : '';
621 621
 
622
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
623
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
622
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
623
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
624 624
 
625 625
     echo $html;
626 626
 }
627 627
 
628
-function wpinv_is_test_mode( $gateway = '' ) {
629
-    if ( empty( $gateway ) ) {
628
+function wpinv_is_test_mode($gateway = '') {
629
+    if (empty($gateway)) {
630 630
         return false;
631 631
     }
632 632
     
633
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
633
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
634 634
     
635
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
635
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
636 636
 }
637 637
 
638
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
639
-    $data = array( 'wpi-listener' => 'IPN' );
638
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
639
+    $data = array('wpi-listener' => 'IPN');
640 640
     
641
-    if ( !empty( $gateway ) ) {
642
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
641
+    if (!empty($gateway)) {
642
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
643 643
     }
644 644
     
645
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
645
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
646 646
     
647
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
647
+    $ipn_url = add_query_arg($args, home_url('index.php'));
648 648
     
649
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
649
+    return apply_filters('wpinv_ipn_url', $ipn_url);
650 650
 }
651 651
 
652 652
 function wpinv_listen_for_payment_ipn() {
653 653
     // Regular PayPal IPN
654
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
655
-        do_action( 'wpinv_verify_payment_ipn' );
654
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
655
+        do_action('wpinv_verify_payment_ipn');
656 656
         
657
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
658
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ );
659
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
657
+        if (!empty($_GET['wpi-gateway'])) {
658
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__);
659
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
660 660
         }
661 661
     }
662 662
 }
663
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
663
+add_action('init', 'wpinv_listen_for_payment_ipn');
664 664
 
665 665
 function wpinv_get_bank_instructions() {
666
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
666
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
667 667
     
668
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
668
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
669 669
 }
670 670
 
671
-function wpinv_get_bank_info( $filtered = false ) {
671
+function wpinv_get_bank_info($filtered = false) {
672 672
     $bank_fields = array(
673
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
674
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
675
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
676
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
677
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
678
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
679
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
673
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
674
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
675
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
676
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
677
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
678
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
679
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
680 680
     );
681 681
     
682 682
     $bank_info = array();
683
-    foreach ( $bank_fields as $field => $label ) {
684
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
683
+    foreach ($bank_fields as $field => $label) {
684
+        if ($filtered && !($value = wpinv_get_option($field))) {
685 685
             continue;
686 686
         }
687 687
         
688
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
688
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
689 689
     }
690 690
     
691
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
691
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
692 692
 }
693 693
 
694
-function wpinv_get_post_data( $method = 'request' ) {
694
+function wpinv_get_post_data($method = 'request') {
695 695
     $data       = array();
696 696
     $request    = $_REQUEST;
697 697
     
698
-    if ( $method == 'post' ) {
699
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
698
+    if ($method == 'post') {
699
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
700 700
             return $data;
701 701
         }
702 702
         
703 703
         $request = $_POST;
704 704
     }
705 705
     
706
-    if ( $method == 'get' ) {
707
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
706
+    if ($method == 'get') {
707
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
708 708
             return $data;
709 709
         }
710 710
         
@@ -715,11 +715,11 @@  discard block
 block discarded – undo
715 715
     $post_data = '';
716 716
     
717 717
     // Fallback just in case post_max_size is lower than needed
718
-    if ( ini_get( 'allow_url_fopen' ) ) {
719
-        $post_data = file_get_contents( 'php://input' );
718
+    if (ini_get('allow_url_fopen')) {
719
+        $post_data = file_get_contents('php://input');
720 720
     } else {
721 721
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
722
-        ini_set( 'post_max_size', '12M' );
722
+        ini_set('post_max_size', '12M');
723 723
     }
724 724
     // Start the encoded data collection with notification command
725 725
     $encoded_data = 'cmd=_notify-validate';
@@ -728,58 +728,58 @@  discard block
 block discarded – undo
728 728
     $arg_separator = wpinv_get_php_arg_separator_output();
729 729
 
730 730
     // Verify there is a post_data
731
-    if ( $post_data || strlen( $post_data ) > 0 ) {
731
+    if ($post_data || strlen($post_data) > 0) {
732 732
         // Append the data
733 733
         $encoded_data .= $arg_separator . $post_data;
734 734
     } else {
735 735
         // Check if POST is empty
736
-        if ( empty( $request ) ) {
736
+        if (empty($request)) {
737 737
             // Nothing to do
738 738
             return;
739 739
         } else {
740 740
             // Loop through each POST
741
-            foreach ( $request as $key => $value ) {
741
+            foreach ($request as $key => $value) {
742 742
                 // Encode the value and append the data
743
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
743
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
744 744
             }
745 745
         }
746 746
     }
747 747
 
748 748
     // Convert collected post data to an array
749
-    parse_str( $encoded_data, $data );
749
+    parse_str($encoded_data, $data);
750 750
 
751
-    foreach ( $data as $key => $value ) {
752
-        if ( false !== strpos( $key, 'amp;' ) ) {
753
-            $new_key = str_replace( '&amp;', '&', $key );
754
-            $new_key = str_replace( 'amp;', '&' , $new_key );
751
+    foreach ($data as $key => $value) {
752
+        if (false !== strpos($key, 'amp;')) {
753
+            $new_key = str_replace('&amp;', '&', $key);
754
+            $new_key = str_replace('amp;', '&', $new_key);
755 755
 
756
-            unset( $data[ $key ] );
757
-            $data[ $new_key ] = sanitize_text_field( $value );
756
+            unset($data[$key]);
757
+            $data[$new_key] = sanitize_text_field($value);
758 758
         }
759 759
     }
760 760
     
761 761
     return $data;
762 762
 }
763 763
 
764
-function wpinv_gateway_support_subscription( $gateway ) {
764
+function wpinv_gateway_support_subscription($gateway) {
765 765
     $return = false;
766 766
     
767
-    if ( wpinv_is_gateway_active( $gateway ) ) {
768
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
767
+    if (wpinv_is_gateway_active($gateway)) {
768
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
769 769
     }
770 770
     
771 771
     return $return;
772 772
 }
773 773
 
774
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
775
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
776
-        foreach ( $gateways as $gateway => $info ) {
777
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
778
-                unset( $gateways[$gateway] );
774
+function wpinv_payment_gateways_on_cart($gateways = array()) {
775
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
776
+        foreach ($gateways as $gateway => $info) {
777
+            if (!wpinv_gateway_support_subscription($gateway)) {
778
+                unset($gateways[$gateway]);
779 779
             }
780 780
         }
781 781
     }
782 782
     
783 783
     return $gateways;
784 784
 }
785
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
786 785
\ No newline at end of file
786
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
787 787
\ No newline at end of file
Please login to merge, or discard this patch.
includes/class-wpinv-reports.php 1 patch
Spacing   +172 added lines, -172 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,166 +21,166 @@  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' ), 10 );
47
-            add_action( 'wpinv_reports_tab_export', array( $this, 'export' ) );
48
-            add_action( 'wp_ajax_wpinv_ajax_export', array( $this, 'ajax_export' ) );
45
+        if (is_admin()) {
46
+            add_action('admin_menu', array($this, 'add_submenu'), 10);
47
+            add_action('wpinv_reports_tab_export', array($this, 'export'));
48
+            add_action('wp_ajax_wpinv_ajax_export', array($this, 'ajax_export'));
49 49
             
50 50
             // Export Invoices.
51
-            add_action( 'wpinv_export_set_params_invoices', array( $this, 'set_invoices_export' ) );
52
-            add_filter( 'wpinv_export_get_columns_invoices', array( $this, 'get_invoices_columns' ) );
53
-            add_filter( 'wpinv_export_get_data_invoices', array( $this, 'get_invoices_data' ) );
54
-            add_filter( 'wpinv_get_export_status_invoices', array( $this, 'invoices_export_status' ) );
51
+            add_action('wpinv_export_set_params_invoices', array($this, 'set_invoices_export'));
52
+            add_filter('wpinv_export_get_columns_invoices', array($this, 'get_invoices_columns'));
53
+            add_filter('wpinv_export_get_data_invoices', array($this, 'get_invoices_data'));
54
+            add_filter('wpinv_get_export_status_invoices', array($this, 'invoices_export_status'));
55 55
         }
56
-        do_action( 'wpinv_class_reports_actions', $this );
56
+        do_action('wpinv_class_reports_actions', $this);
57 57
     }
58 58
     
59 59
     public function add_submenu() {
60 60
         global $wpi_reports_page;
61
-        $wpi_reports_page = add_submenu_page( 'wpinv', __( 'Reports', 'invoicing' ), __( 'Reports', 'invoicing' ), 'manage_options', 'wpinv-reports', array( $this, 'reports_page' ) );
61
+        $wpi_reports_page = add_submenu_page('wpinv', __('Reports', 'invoicing'), __('Reports', 'invoicing'), 'manage_options', 'wpinv-reports', array($this, 'reports_page'));
62 62
     }
63 63
     
64 64
     public function reports_page() {
65
-        if ( !wp_script_is( 'postbox', 'enqueued' ) ) {
66
-            wp_enqueue_script( 'postbox' );
65
+        if (!wp_script_is('postbox', 'enqueued')) {
66
+            wp_enqueue_script('postbox');
67 67
         }
68
-        if ( !wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
69
-            wp_enqueue_script( 'jquery-ui-datepicker' );
68
+        if (!wp_script_is('jquery-ui-datepicker', 'enqueued')) {
69
+            wp_enqueue_script('jquery-ui-datepicker');
70 70
         }
71 71
         
72
-        $current_page = admin_url( 'admin.php?page=wpinv-reports' );
73
-        $active_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'export';
72
+        $current_page = admin_url('admin.php?page=wpinv-reports');
73
+        $active_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'export';
74 74
         ?>
75 75
         <div class="wrap wpi-reports-wrap">
76
-            <h1><?php echo esc_html( __( 'Reports', 'invoicing' ) ); ?></h1>
76
+            <h1><?php echo esc_html(__('Reports', 'invoicing')); ?></h1>
77 77
             <h2 class="nav-tab-wrapper wp-clearfix">
78
-                <a href="<?php echo 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>
79
-                <?php do_action( 'wpinv_reports_page_tabs' ); ;?>
78
+                <a href="<?php echo 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>
79
+                <?php do_action('wpinv_reports_page_tabs'); ;?>
80 80
             </h2>
81 81
             <div class="wpi-reports-content wpi-reports-<?php echo $active_tab; ?>">
82 82
             <?php
83
-                do_action( 'wpinv_reports_page_top' );
84
-                do_action( 'wpinv_reports_tab_' . $active_tab );
85
-                do_action( 'wpinv_reports_page_bottom' );
83
+                do_action('wpinv_reports_page_top');
84
+                do_action('wpinv_reports_tab_' . $active_tab);
85
+                do_action('wpinv_reports_page_bottom');
86 86
             ?>
87 87
         </div>
88 88
         <?php
89 89
     }
90 90
     
91 91
     public function export() {
92
-        $statuses = wpinv_get_invoice_statuses( true );
93
-        $statuses = array_merge( array( 'any' => __( 'All Statuses', 'invoicing' ) ), $statuses );
92
+        $statuses = wpinv_get_invoice_statuses(true);
93
+        $statuses = array_merge(array('any' => __('All Statuses', 'invoicing')), $statuses);
94 94
         ?>
95 95
         <div class="metabox-holder">
96 96
             <div id="post-body">
97 97
                 <div id="post-body-content">
98
-                    <?php do_action( 'wpinv_reports_tab_export_content_top' ); ?>
98
+                    <?php do_action('wpinv_reports_tab_export_content_top'); ?>
99 99
                     
100 100
                     <div class="postbox wpi-export-invoices">
101
-                        <h2 class="hndle ui-sortabled-handle"><span><?php _e( 'Invoices','invoicing' ); ?></span></h2>
101
+                        <h2 class="hndle ui-sortabled-handle"><span><?php _e('Invoices', 'invoicing'); ?></span></h2>
102 102
                         <div class="inside">
103
-                            <p><?php _e( 'Download a CSV of all payment invoices.', 'invoicing' ); ?></p>
103
+                            <p><?php _e('Download a CSV of all payment invoices.', 'invoicing'); ?></p>
104 104
                             <form id="wpi-export-invoices" class="wpi-export-form" method="post">
105
-                                <?php echo wpinv_html_date_field( array( 
105
+                                <?php echo wpinv_html_date_field(array( 
106 106
                                     'id' => 'wpi_export_from_date', 
107 107
                                     'name' => 'from_date',
108 108
                                     'data' => array(
109 109
                                         'dateFormat' => 'yy-mm-dd'
110 110
                                     ),
111
-                                    'placeholder' => __( 'From date', 'invoicing' ) )
111
+                                    'placeholder' => __('From date', 'invoicing') )
112 112
                                 ); ?>
113
-                                <?php echo wpinv_html_date_field( array( 
113
+                                <?php echo wpinv_html_date_field(array( 
114 114
                                     'id' => 'wpi_export_to_date',
115 115
                                     'name' => 'to_date',
116 116
                                     'data' => array(
117 117
                                         'dateFormat' => 'yy-mm-dd'
118 118
                                     ),
119
-                                    'placeholder' => __( 'To date', 'invoicing' ) )
119
+                                    'placeholder' => __('To date', 'invoicing') )
120 120
                                 ); ?>
121 121
                                 <span id="wpinv-status-wrap">
122
-                                <?php echo wpinv_html_select( array(
122
+                                <?php echo wpinv_html_select(array(
123 123
                                     'options'          => $statuses,
124 124
                                     'name'             => 'status',
125 125
                                     'id'               => 'wpi_export_status',
126 126
                                     'show_option_all'  => false,
127 127
                                     'show_option_none' => false,
128 128
                                     'class'            => 'wpi_select2',
129
-                                ) ); ?>
130
-                                <?php wp_nonce_field( 'wpi_ajax_export', 'wpi_ajax_export' ); ?>
129
+                                )); ?>
130
+                                <?php wp_nonce_field('wpi_ajax_export', 'wpi_ajax_export'); ?>
131 131
                                 </span>
132 132
                                 <span id="wpinv-submit-wrap">
133 133
                                     <input type="hidden" value="invoices" name="export" />
134
-                                    <input type="submit" value="<?php _e( 'Generate CSV', 'invoicing' ); ?>" class="button-primary" />
134
+                                    <input type="submit" value="<?php _e('Generate CSV', 'invoicing'); ?>" class="button-primary" />
135 135
                                 </span>
136 136
                             </form>
137 137
                         </div>
138 138
                     </div>
139 139
                     
140
-                    <?php do_action( 'wpinv_reports_tab_export_content_bottom' ); ?>
140
+                    <?php do_action('wpinv_reports_tab_export_content_bottom'); ?>
141 141
                 </div>
142 142
             </div>
143 143
         </div>
144 144
         <?php
145 145
     }
146 146
     
147
-    public function export_location( $relative = false ) {
147
+    public function export_location($relative = false) {
148 148
         $upload_dir         = wp_upload_dir();
149
-        $export_location    = $relative ? trailingslashit( $upload_dir['baseurl'] ) . 'cache' : trailingslashit( $upload_dir['basedir'] ) . 'cache';
150
-        $export_location    = apply_filters( 'wpinv_export_location', $export_location, $relative );
149
+        $export_location    = $relative ? trailingslashit($upload_dir['baseurl']) . 'cache' : trailingslashit($upload_dir['basedir']) . 'cache';
150
+        $export_location    = apply_filters('wpinv_export_location', $export_location, $relative);
151 151
         
152
-        return trailingslashit( $export_location );
152
+        return trailingslashit($export_location);
153 153
     }
154 154
     
155 155
     public function check_export_location() {
156 156
         try {
157
-            if ( empty( $this->wp_filesystem ) ) {
158
-                return __( 'Filesystem ERROR: Could not access filesystem.', 'invoicing' );
157
+            if (empty($this->wp_filesystem)) {
158
+                return __('Filesystem ERROR: Could not access filesystem.', 'invoicing');
159 159
             }
160 160
 
161
-            if ( is_wp_error( $this->wp_filesystem ) ) {
162
-                return __( 'Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing' );
161
+            if (is_wp_error($this->wp_filesystem)) {
162
+                return __('Filesystem ERROR: ' . $this->wp_filesystem->get_error_message(), 'invoicing');
163 163
             }
164 164
         
165
-            $is_dir         = $this->wp_filesystem->is_dir( $this->export_dir );
166
-            $is_writeable   = $is_dir && is_writeable( $this->export_dir );
165
+            $is_dir         = $this->wp_filesystem->is_dir($this->export_dir);
166
+            $is_writeable   = $is_dir && is_writeable($this->export_dir);
167 167
             
168
-            if ( $is_dir && $is_writeable ) {
168
+            if ($is_dir && $is_writeable) {
169 169
                return true;
170
-            } else if ( $is_dir && !$is_writeable ) {
171
-               if ( !$this->wp_filesystem->chmod( $this->export_dir, FS_CHMOD_DIR ) ) {
172
-                   return wp_sprintf( __( 'Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing' ), $this->export_dir );
170
+            } else if ($is_dir && !$is_writeable) {
171
+               if (!$this->wp_filesystem->chmod($this->export_dir, FS_CHMOD_DIR)) {
172
+                   return wp_sprintf(__('Filesystem ERROR: Export location %s is not writable, check your file permissions.', 'invoicing'), $this->export_dir);
173 173
                }
174 174
                
175 175
                return true;
176 176
             } else {
177
-                if ( !$this->wp_filesystem->mkdir( $this->export_dir, FS_CHMOD_DIR ) ) {
178
-                    return wp_sprintf( __( 'Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing' ), $this->export_dir );
177
+                if (!$this->wp_filesystem->mkdir($this->export_dir, FS_CHMOD_DIR)) {
178
+                    return wp_sprintf(__('Filesystem ERROR: Could not create directory %s. This is usually due to inconsistent file permissions.', 'invoicing'), $this->export_dir);
179 179
                 }
180 180
                 
181 181
                 return true;
182 182
             }
183
-        } catch ( Exception $e ) {
183
+        } catch (Exception $e) {
184 184
             return $e->getMessage();
185 185
         }
186 186
     }
@@ -188,130 +188,130 @@  discard block
 block discarded – undo
188 188
     public function ajax_export() {
189 189
         $response               = array();
190 190
         $response['success']    = false;
191
-        $response['msg']        = __( 'Invalid export request found.', 'invoicing' );
191
+        $response['msg']        = __('Invalid export request found.', 'invoicing');
192 192
         
193
-        if ( empty( $_POST['data'] ) || !current_user_can( 'manage_options' ) ) {
194
-            wp_send_json( $response );
193
+        if (empty($_POST['data']) || !current_user_can('manage_options')) {
194
+            wp_send_json($response);
195 195
         }
196 196
 
197
-        parse_str( $_POST['data'], $data );
197
+        parse_str($_POST['data'], $data);
198 198
         
199
-        $data['step']   = !empty( $_POST['step'] ) ? absint( $_POST['step'] ) : 1;
199
+        $data['step'] = !empty($_POST['step']) ? absint($_POST['step']) : 1;
200 200
 
201 201
         $_REQUEST = (array)$data;
202
-        if ( !( !empty( $_REQUEST['wpi_ajax_export'] ) && wp_verify_nonce( $_REQUEST['wpi_ajax_export'], 'wpi_ajax_export' ) ) ) {
203
-            $response['msg']    = __( 'Security check failed.', 'invoicing' );
204
-            wp_send_json( $response );
202
+        if (!(!empty($_REQUEST['wpi_ajax_export']) && wp_verify_nonce($_REQUEST['wpi_ajax_export'], 'wpi_ajax_export'))) {
203
+            $response['msg'] = __('Security check failed.', 'invoicing');
204
+            wp_send_json($response);
205 205
         }
206 206
         
207
-        if ( ( $error = $this->check_export_location( true ) ) !== true ) {
208
-            $response['msg'] = __( 'Filesystem ERROR: ' . $error, 'invoicing' );
209
-            wp_send_json( $response );
207
+        if (($error = $this->check_export_location(true)) !== true) {
208
+            $response['msg'] = __('Filesystem ERROR: ' . $error, 'invoicing');
209
+            wp_send_json($response);
210 210
         }
211 211
                         
212
-        $this->set_export_params( $_REQUEST );
212
+        $this->set_export_params($_REQUEST);
213 213
         
214 214
         $return = $this->process_export_step();
215 215
         $done   = $this->get_export_status();
216 216
         
217
-        if ( $return ) {
217
+        if ($return) {
218 218
             $this->step += 1;
219 219
             
220 220
             $response['success']    = true;
221 221
             $response['msg']        = '';
222 222
             
223
-            if ( $done >= 100 ) {
223
+            if ($done >= 100) {
224 224
                 $this->step     = 'done';
225
-                $new_filename   = 'wpi-' . $this->export . '-' . date( 'y-m-d-H-i' ) . '.' . $this->filetype;
225
+                $new_filename   = 'wpi-' . $this->export . '-' . date('y-m-d-H-i') . '.' . $this->filetype;
226 226
                 $new_file       = $this->export_dir . $new_filename;
227 227
                 
228
-                if ( file_exists( $this->file ) ) {
229
-                    $this->wp_filesystem->move( $this->file, $new_file, true );
228
+                if (file_exists($this->file)) {
229
+                    $this->wp_filesystem->move($this->file, $new_file, true);
230 230
                 }
231 231
                 
232
-                if ( file_exists( $new_file ) ) {
233
-                    $response['data']['file'] = array( 'u' => $this->export_url . $new_filename, 's' => size_format( filesize( $new_file ), 2 ) );
232
+                if (file_exists($new_file)) {
233
+                    $response['data']['file'] = array('u' => $this->export_url . $new_filename, 's' => size_format(filesize($new_file), 2));
234 234
                 }
235 235
             }
236 236
             
237 237
             $response['data']['step']   = $this->step;
238 238
             $response['data']['done']   = $done;
239 239
         } else {
240
-            $response['msg']    = __( 'No data found for export.', 'invoicing' );
240
+            $response['msg'] = __('No data found for export.', 'invoicing');
241 241
         }
242 242
 
243
-        wp_send_json( $response );
243
+        wp_send_json($response);
244 244
     }
245 245
     
246
-    public function set_export_params( $request ) {
246
+    public function set_export_params($request) {
247 247
         $this->empty    = false;
248
-        $this->step     = !empty( $request['step'] ) ? absint( $request['step'] ) : 1;
249
-        $this->export   = !empty( $request['export'] ) ? $request['export'] : $this->export;
248
+        $this->step     = !empty($request['step']) ? absint($request['step']) : 1;
249
+        $this->export   = !empty($request['export']) ? $request['export'] : $this->export;
250 250
         $this->filename = 'wpi-' . $this->export . '-' . $request['wpi_ajax_export'] . '.' . $this->filetype;
251 251
         $this->file     = $this->export_dir . $this->filename;
252 252
         
253
-        do_action( 'wpinv_export_set_params_' . $this->export, $request );
253
+        do_action('wpinv_export_set_params_' . $this->export, $request);
254 254
     }
255 255
     
256 256
     public function get_columns() {
257 257
         $columns = array(
258
-            'id'   => __( 'ID',   'invoicing' ),
259
-            'date' => __( 'Date', 'invoicing' )
258
+            'id'   => __('ID', 'invoicing'),
259
+            'date' => __('Date', 'invoicing')
260 260
         );
261 261
         
262
-        return apply_filters( 'wpinv_export_get_columns_' . $this->export, $columns );
262
+        return apply_filters('wpinv_export_get_columns_' . $this->export, $columns);
263 263
     }
264 264
     
265 265
     protected function get_export_file() {
266 266
         $file = '';
267 267
 
268
-        if ( $this->wp_filesystem->exists( $this->file ) ) {
269
-            $file = $this->wp_filesystem->get_contents( $this->file );
268
+        if ($this->wp_filesystem->exists($this->file)) {
269
+            $file = $this->wp_filesystem->get_contents($this->file);
270 270
         } else {
271
-            $this->wp_filesystem->put_contents( $this->file, '' );
271
+            $this->wp_filesystem->put_contents($this->file, '');
272 272
         }
273 273
 
274 274
         return $file;
275 275
     }
276 276
     
277
-    protected function attach_export_data( $data = '' ) {
278
-        $filedata   = $this->get_export_file();
279
-        $filedata   .= $data;
277
+    protected function attach_export_data($data = '') {
278
+        $filedata = $this->get_export_file();
279
+        $filedata .= $data;
280 280
         
281
-        $this->wp_filesystem->put_contents( $this->file, $filedata );
281
+        $this->wp_filesystem->put_contents($this->file, $filedata);
282 282
 
283
-        $rows       = file( $this->file, FILE_SKIP_EMPTY_LINES );
283
+        $rows       = file($this->file, FILE_SKIP_EMPTY_LINES);
284 284
         $columns    = $this->get_columns();
285
-        $columns    = empty( $columns ) ? 0 : 1;
285
+        $columns    = empty($columns) ? 0 : 1;
286 286
 
287
-        $this->empty = count( $rows ) == $columns ? true : false;
287
+        $this->empty = count($rows) == $columns ? true : false;
288 288
     }
289 289
     
290 290
     public function print_columns() {
291 291
         $column_data    = '';
292 292
         $columns        = $this->get_columns();
293 293
         $i              = 1;
294
-        foreach( $columns as $key => $column ) {
295
-            $column_data .= '"' . addslashes( $column ) . '"';
296
-            $column_data .= $i == count( $columns ) ? '' : ',';
294
+        foreach ($columns as $key => $column) {
295
+            $column_data .= '"' . addslashes($column) . '"';
296
+            $column_data .= $i == count($columns) ? '' : ',';
297 297
             $i++;
298 298
         }
299 299
         $column_data .= "\r\n";
300 300
 
301
-        $this->attach_export_data( $column_data );
301
+        $this->attach_export_data($column_data);
302 302
 
303 303
         return $column_data;
304 304
     }
305 305
     
306 306
     public function process_export_step() {
307
-        if ( $this->step < 2 ) {
308
-            @unlink( $this->file );
307
+        if ($this->step < 2) {
308
+            @unlink($this->file);
309 309
             $this->print_columns();
310 310
         }
311 311
         
312 312
         $return = $this->print_rows();
313 313
         
314
-        if ( $return ) {
314
+        if ($return) {
315 315
             return true;
316 316
         } else {
317 317
             return false;
@@ -320,23 +320,23 @@  discard block
 block discarded – undo
320 320
     
321 321
     public function get_export_status() {
322 322
         $status = 100;
323
-        return apply_filters( 'wpinv_get_export_status_' . $this->export, $status );
323
+        return apply_filters('wpinv_get_export_status_' . $this->export, $status);
324 324
     }
325 325
     
326 326
     public function get_export_data() {
327 327
         $data = array(
328 328
             0 => array(
329 329
                 'id'   => '',
330
-                'data' => date( 'F j, Y' )
330
+                'data' => date('F j, Y')
331 331
             ),
332 332
             1 => array(
333 333
                 'id'   => '',
334
-                'data' => date( 'F j, Y' )
334
+                'data' => date('F j, Y')
335 335
             )
336 336
         );
337 337
 
338
-        $data = apply_filters( 'wpinv_export_get_data', $data );
339
-        $data = apply_filters( 'wpinv_export_get_data_' . $this->export, $data );
338
+        $data = apply_filters('wpinv_export_get_data', $data);
339
+        $data = apply_filters('wpinv_export_get_data_' . $this->export, $data);
340 340
 
341 341
         return $data;
342 342
     }
@@ -346,20 +346,20 @@  discard block
 block discarded – undo
346 346
         $data       = $this->get_export_data();
347 347
         $columns    = $this->get_columns();
348 348
 
349
-        if ( $data ) {
350
-            foreach ( $data as $row ) {
349
+        if ($data) {
350
+            foreach ($data as $row) {
351 351
                 $i = 1;
352
-                foreach ( $row as $key => $column ) {
353
-                    if ( array_key_exists( $key, $columns ) ) {
354
-                        $row_data .= '"' . addslashes( preg_replace( "/\"/","'", $column ) ) . '"';
355
-                        $row_data .= $i == count( $columns ) ? '' : ',';
352
+                foreach ($row as $key => $column) {
353
+                    if (array_key_exists($key, $columns)) {
354
+                        $row_data .= '"' . addslashes(preg_replace("/\"/", "'", $column)) . '"';
355
+                        $row_data .= $i == count($columns) ? '' : ',';
356 356
                         $i++;
357 357
                     }
358 358
                 }
359 359
                 $row_data .= "\r\n";
360 360
             }
361 361
 
362
-            $this->attach_export_data( $row_data );
362
+            $this->attach_export_data($row_data);
363 363
 
364 364
             return $row_data;
365 365
         }
@@ -368,46 +368,46 @@  discard block
 block discarded – undo
368 368
     }
369 369
     
370 370
     // Export Invoices.
371
-    public function set_invoices_export( $request ) {
372
-        $this->from_date    = isset( $request['from_date'] ) ? sanitize_text_field( $request['from_date'] ) : '';
373
-        $this->to_date      = isset( $request['to_date'] ) ? sanitize_text_field( $request['to_date'] ) : '';
374
-        $this->status       = isset( $request['status'] ) ? sanitize_text_field( $request['status'] ) : 'publish';
371
+    public function set_invoices_export($request) {
372
+        $this->from_date    = isset($request['from_date']) ? sanitize_text_field($request['from_date']) : '';
373
+        $this->to_date      = isset($request['to_date']) ? sanitize_text_field($request['to_date']) : '';
374
+        $this->status       = isset($request['status']) ? sanitize_text_field($request['status']) : 'publish';
375 375
     }
376 376
     
377
-    public function get_invoices_columns( $columns = array() ) {
377
+    public function get_invoices_columns($columns = array()) {
378 378
         $columns = array(
379
-            'id'            => __( 'ID',   'invoicing' ),
380
-            'number'        => __( 'Number',   'invoicing' ),
381
-            'date'          => __( 'Date', 'invoicing' ),
382
-            'amount'        => __( 'Amount', 'invoicing' ),
383
-            'status_nicename'  => __( 'Status Nicename', 'invoicing' ),
384
-            'status'        => __( 'Status', 'invoicing' ),
385
-            'tax'           => __( 'Tax', 'invoicing' ),
386
-            'discount'      => __( 'Discount', 'invoicing' ),
387
-            'user_id'       => __( 'User ID', 'invoicing' ),
388
-            'email'         => __( 'Email', 'invoicing' ),
389
-            'first_name'    => __( 'First Name', 'invoicing' ),
390
-            'last_name'     => __( 'Last Name', 'invoicing' ),
391
-            'address'       => __( 'Address', 'invoicing' ),
392
-            'city'          => __( 'City', 'invoicing' ),
393
-            'state'         => __( 'State', 'invoicing' ),
394
-            'country'       => __( 'Country', 'invoicing' ),
395
-            'zip'           => __( 'Zipcode', 'invoicing' ),
396
-            'phone'         => __( 'Phone', 'invoicing' ),
397
-            'company'       => __( 'Company', 'invoicing' ),
398
-            'vat_number'    => __( 'Vat Number', 'invoicing' ),
399
-            'ip'            => __( 'IP', 'invoicing' ),
400
-            'gateway'       => __( 'Gateway', 'invoicing' ),
401
-            'gateway_nicename'       => __( 'Gateway Nicename', 'invoicing' ),
402
-            'transaction_id'=> __( 'Transaction ID', 'invoicing' ),
403
-            'currency'      => __( 'Currency', 'invoicing' ),
404
-            'due_date'      => __( 'Due Date', 'invoicing' ),
379
+            'id'            => __('ID', 'invoicing'),
380
+            'number'        => __('Number', 'invoicing'),
381
+            'date'          => __('Date', 'invoicing'),
382
+            'amount'        => __('Amount', 'invoicing'),
383
+            'status_nicename'  => __('Status Nicename', 'invoicing'),
384
+            'status'        => __('Status', 'invoicing'),
385
+            'tax'           => __('Tax', 'invoicing'),
386
+            'discount'      => __('Discount', 'invoicing'),
387
+            'user_id'       => __('User ID', 'invoicing'),
388
+            'email'         => __('Email', 'invoicing'),
389
+            'first_name'    => __('First Name', 'invoicing'),
390
+            'last_name'     => __('Last Name', 'invoicing'),
391
+            'address'       => __('Address', 'invoicing'),
392
+            'city'          => __('City', 'invoicing'),
393
+            'state'         => __('State', 'invoicing'),
394
+            'country'       => __('Country', 'invoicing'),
395
+            'zip'           => __('Zipcode', 'invoicing'),
396
+            'phone'         => __('Phone', 'invoicing'),
397
+            'company'       => __('Company', 'invoicing'),
398
+            'vat_number'    => __('Vat Number', 'invoicing'),
399
+            'ip'            => __('IP', 'invoicing'),
400
+            'gateway'       => __('Gateway', 'invoicing'),
401
+            'gateway_nicename'       => __('Gateway Nicename', 'invoicing'),
402
+            'transaction_id'=> __('Transaction ID', 'invoicing'),
403
+            'currency'      => __('Currency', 'invoicing'),
404
+            'due_date'      => __('Due Date', 'invoicing'),
405 405
         );
406 406
 
407 407
         return $columns;
408 408
     }
409 409
         
410
-    public function get_invoices_data( $response = array() ) {
410
+    public function get_invoices_data($response = array()) {
411 411
         $args = array(
412 412
             'limit'    => $this->per_page,
413 413
             'page'     => $this->step,
@@ -415,37 +415,37 @@  discard block
 block discarded – undo
415 415
             'orderby'  => 'date',
416 416
         );
417 417
         
418
-        if ( $this->status != 'any' ) {
418
+        if ($this->status != 'any') {
419 419
             $args['status'] = $this->status;
420 420
         } else {
421
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
421
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
422 422
         }
423 423
 
424
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
424
+        if (!empty($this->from_date) || !empty($this->to_date)) {
425 425
             $args['date_query'] = array(
426 426
                 array(
427
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
428
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
427
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
428
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
429 429
                     'inclusive' => true
430 430
                 )
431 431
             );
432 432
         }
433 433
 
434
-        $invoices = wpinv_get_invoices( $args );
434
+        $invoices = wpinv_get_invoices($args);
435 435
         
436 436
         $data = array();
437 437
         
438
-        if ( !empty( $invoices ) ) {
439
-            foreach ( $invoices as $invoice ) {
438
+        if (!empty($invoices)) {
439
+            foreach ($invoices as $invoice) {
440 440
                 $row = array(
441 441
                     'id'            => $invoice->ID,
442 442
                     'number'        => $invoice->get_number(),
443
-                    'date'          => $invoice->get_invoice_date( false ),
444
-                    'amount'        => wpinv_round_amount( $invoice->get_total() ),
445
-                    'status_nicename' => $invoice->get_status( true ),
443
+                    'date'          => $invoice->get_invoice_date(false),
444
+                    'amount'        => wpinv_round_amount($invoice->get_total()),
445
+                    'status_nicename' => $invoice->get_status(true),
446 446
                     'status'        => $invoice->get_status(),
447
-                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount( $invoice->get_tax() ) : '',
448
-                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount( $invoice->get_discount() ) : '',
447
+                    'tax'           => $invoice->get_tax() > 0 ? wpinv_round_amount($invoice->get_tax()) : '',
448
+                    'discount'      => $invoice->get_discount() > 0 ? wpinv_round_amount($invoice->get_discount()) : '',
449 449
                     'user_id'       => $invoice->get_user_id(),
450 450
                     'email'         => $invoice->get_email(),
451 451
                     'first_name'    => $invoice->get_first_name(),
@@ -466,7 +466,7 @@  discard block
 block discarded – undo
466 466
                     'due_date'      => $invoice->needs_payment() || $invoice->status == 'draft' ? $invoice->get_due_date() : '',
467 467
                 );
468 468
                 
469
-                $data[] = apply_filters( 'wpinv_export_invoice_row', $row, $invoice );
469
+                $data[] = apply_filters('wpinv_export_invoice_row', $row, $invoice);
470 470
             }
471 471
 
472 472
             return $data;
@@ -482,31 +482,31 @@  discard block
 block discarded – undo
482 482
             'return'   => 'ids',
483 483
         );
484 484
         
485
-        if ( $this->status != 'any' ) {
485
+        if ($this->status != 'any') {
486 486
             $args['status'] = $this->status;
487 487
         } else {
488
-            $args['status'] = array_keys( wpinv_get_invoice_statuses( true ) );
488
+            $args['status'] = array_keys(wpinv_get_invoice_statuses(true));
489 489
         }
490 490
 
491
-        if ( !empty( $this->from_date ) || !empty( $this->to_date ) ) {
491
+        if (!empty($this->from_date) || !empty($this->to_date)) {
492 492
             $args['date_query'] = array(
493 493
                 array(
494
-                    'after'     => date( 'Y-n-d 00:00:00', strtotime( $this->from_date ) ),
495
-                    'before'    => date( 'Y-n-d 23:59:59', strtotime( $this->to_date ) ),
494
+                    'after'     => date('Y-n-d 00:00:00', strtotime($this->from_date)),
495
+                    'before'    => date('Y-n-d 23:59:59', strtotime($this->to_date)),
496 496
                     'inclusive' => true
497 497
                 )
498 498
             );
499 499
         }
500 500
 
501
-        $invoices   = wpinv_get_invoices( $args );
502
-        $total      = !empty( $invoices ) ? count( $invoices ) : 0;
501
+        $invoices   = wpinv_get_invoices($args);
502
+        $total      = !empty($invoices) ? count($invoices) : 0;
503 503
         $status     = 100;
504 504
 
505
-        if ( $total > 0 ) {
506
-            $status = ( ( $this->per_page * $this->step ) / $total ) * 100;
505
+        if ($total > 0) {
506
+            $status = (($this->per_page * $this->step) / $total) * 100;
507 507
         }
508 508
 
509
-        if ( $status > 100 ) {
509
+        if ($status > 100) {
510 510
             $status = 100;
511 511
         }
512 512
 
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +711 added lines, -711 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly.
3
-if (!defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5 5
 class WPInv_EUVat {
6 6
     private static $is_ajax = false;
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
     private static $instance = false;
9 9
     
10 10
     public static function get_instance() {
11
-        if ( !self::$instance ) {
11
+        if (!self::$instance) {
12 12
             self::$instance = new self();
13 13
             self::$instance->actions();
14 14
         }
@@ -17,137 +17,137 @@  discard block
 block discarded – undo
17 17
     }
18 18
     
19 19
     public function __construct() {
20
-        self::$is_ajax          = defined( 'DOING_AJAX' ) && DOING_AJAX;
20
+        self::$is_ajax          = defined('DOING_AJAX') && DOING_AJAX;
21 21
         self::$default_country  = wpinv_get_default_country();
22 22
     }
23 23
     
24 24
     public static function actions() {
25
-        if ( is_admin() ) {
26
-            add_action( 'admin_enqueue_scripts', array( self::$instance, 'enqueue_admin_scripts' ) );
27
-            add_action( 'wpinv_settings_sections_taxes', array( self::$instance, 'section_vat_settings' ) ); 
28
-            add_action( 'wpinv_settings_taxes', array( self::$instance, 'vat_settings' ) );
29
-            add_filter( 'wpinv_settings_taxes-vat_sanitize', array( self::$instance, 'sanitize_vat_settings' ) );
30
-            add_filter( 'wpinv_settings_taxes-vat_rates_sanitize', array( self::$instance, 'sanitize_vat_rates' ) );
31
-            add_action( 'wp_ajax_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
32
-            add_action( 'wp_ajax_nopriv_wpinv_add_vat_class', array( self::$instance, 'add_class' ) );
33
-            add_action( 'wp_ajax_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
34
-            add_action( 'wp_ajax_nopriv_wpinv_delete_vat_class', array( self::$instance, 'delete_class' ) );
35
-            add_action( 'wp_ajax_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
36
-            add_action( 'wp_ajax_nopriv_wpinv_update_vat_rates', array( self::$instance, 'update_eu_rates' ) );
37
-            add_action( 'wp_ajax_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
38
-            add_action( 'wp_ajax_nopriv_wpinv_geoip2', array( self::$instance, 'geoip2_download_database' ) );
39
-        }
40
-        
41
-        add_action( 'wp_enqueue_scripts', array( self::$instance, 'enqueue_vat_scripts' ) );
42
-        add_filter( 'wpinv_default_billing_country', array( self::$instance, 'get_user_country' ), 10 );
43
-        add_filter( 'wpinv_get_user_country', array( self::$instance, 'set_user_country' ), 10 );
44
-        add_action( 'wp_ajax_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
45
-        add_action( 'wp_ajax_nopriv_wpinv_vat_validate', array( self::$instance, 'ajax_vat_validate' ) );
46
-        add_action( 'wp_ajax_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
47
-        add_action( 'wp_ajax_nopriv_wpinv_vat_reset', array( self::$instance, 'ajax_vat_reset' ) );
48
-        add_action( 'wpinv_invoice_print_after_line_items', array( self::$instance, 'show_vat_notice' ), 999, 1 );
49
-        if ( wpinv_use_taxes() ) {
50
-            add_action( 'wpinv_after_billing_fields', array( self::$instance, 'checkout_vat_fields' ) );
51
-            if ( self::allow_vat_rules() ) {
52
-                add_action( 'wpinv_checkout_error_checks', array( self::$instance, 'checkout_vat_validate' ), 10, 2 );
53
-                add_filter( 'wpinv_tax_rate', array( self::$instance, 'get_rate' ), 10, 4 );
25
+        if (is_admin()) {
26
+            add_action('admin_enqueue_scripts', array(self::$instance, 'enqueue_admin_scripts'));
27
+            add_action('wpinv_settings_sections_taxes', array(self::$instance, 'section_vat_settings')); 
28
+            add_action('wpinv_settings_taxes', array(self::$instance, 'vat_settings'));
29
+            add_filter('wpinv_settings_taxes-vat_sanitize', array(self::$instance, 'sanitize_vat_settings'));
30
+            add_filter('wpinv_settings_taxes-vat_rates_sanitize', array(self::$instance, 'sanitize_vat_rates'));
31
+            add_action('wp_ajax_wpinv_add_vat_class', array(self::$instance, 'add_class'));
32
+            add_action('wp_ajax_nopriv_wpinv_add_vat_class', array(self::$instance, 'add_class'));
33
+            add_action('wp_ajax_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
34
+            add_action('wp_ajax_nopriv_wpinv_delete_vat_class', array(self::$instance, 'delete_class'));
35
+            add_action('wp_ajax_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
36
+            add_action('wp_ajax_nopriv_wpinv_update_vat_rates', array(self::$instance, 'update_eu_rates'));
37
+            add_action('wp_ajax_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
38
+            add_action('wp_ajax_nopriv_wpinv_geoip2', array(self::$instance, 'geoip2_download_database'));
39
+        }
40
+        
41
+        add_action('wp_enqueue_scripts', array(self::$instance, 'enqueue_vat_scripts'));
42
+        add_filter('wpinv_default_billing_country', array(self::$instance, 'get_user_country'), 10);
43
+        add_filter('wpinv_get_user_country', array(self::$instance, 'set_user_country'), 10);
44
+        add_action('wp_ajax_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
45
+        add_action('wp_ajax_nopriv_wpinv_vat_validate', array(self::$instance, 'ajax_vat_validate'));
46
+        add_action('wp_ajax_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
47
+        add_action('wp_ajax_nopriv_wpinv_vat_reset', array(self::$instance, 'ajax_vat_reset'));
48
+        add_action('wpinv_invoice_print_after_line_items', array(self::$instance, 'show_vat_notice'), 999, 1);
49
+        if (wpinv_use_taxes()) {
50
+            add_action('wpinv_after_billing_fields', array(self::$instance, 'checkout_vat_fields'));
51
+            if (self::allow_vat_rules()) {
52
+                add_action('wpinv_checkout_error_checks', array(self::$instance, 'checkout_vat_validate'), 10, 2);
53
+                add_filter('wpinv_tax_rate', array(self::$instance, 'get_rate'), 10, 4);
54 54
             }
55 55
         }
56 56
     }        
57 57
     
58
-    public static function get_eu_states( $sort = true ) {
59
-        $eu_states = array( 'AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE' );
60
-        if ( $sort ) {
61
-            $sort = sort( $eu_states );
58
+    public static function get_eu_states($sort = true) {
59
+        $eu_states = array('AT', 'BE', 'BG', 'HR', 'CY', 'CZ', 'DK', 'EE', 'FI', 'FR', 'DE', 'GB', 'GR', 'HU', 'IE', 'IT', 'LV', 'LT', 'LU', 'MT', 'NL', 'PL', 'PT', 'RO', 'SK', 'SI', 'ES', 'SE');
60
+        if ($sort) {
61
+            $sort = sort($eu_states);
62 62
         }
63 63
         
64
-        return apply_filters( 'wpinv_get_eu_states', $eu_states, $sort );
64
+        return apply_filters('wpinv_get_eu_states', $eu_states, $sort);
65 65
     }
66 66
     
67
-    public static function get_gst_countries( $sort = true ) {
68
-        $gst_countries  = array( 'AU', 'NZ', 'CA', 'CN' );
67
+    public static function get_gst_countries($sort = true) {
68
+        $gst_countries = array('AU', 'NZ', 'CA', 'CN');
69 69
         
70
-        if ( $sort ) {
71
-            $sort = sort( $gst_countries );
70
+        if ($sort) {
71
+            $sort = sort($gst_countries);
72 72
         }
73 73
         
74
-        return apply_filters( 'wpinv_get_gst_countries', $gst_countries, $sort );
74
+        return apply_filters('wpinv_get_gst_countries', $gst_countries, $sort);
75 75
     }
76 76
     
77
-    public static function is_eu_state( $country_code ) {
78
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_eu_states() ) ? true : false;
77
+    public static function is_eu_state($country_code) {
78
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_eu_states()) ? true : false;
79 79
                 
80
-        return apply_filters( 'wpinv_is_eu_state', $return, $country_code );
80
+        return apply_filters('wpinv_is_eu_state', $return, $country_code);
81 81
     }
82 82
     
83
-    public static function is_gst_country( $country_code ) {
84
-        $return = !empty( $country_code ) && in_array( strtoupper( $country_code ), self::get_gst_countries() ) ? true : false;
83
+    public static function is_gst_country($country_code) {
84
+        $return = !empty($country_code) && in_array(strtoupper($country_code), self::get_gst_countries()) ? true : false;
85 85
                 
86
-        return apply_filters( 'wpinv_is_gst_country', $return, $country_code );
86
+        return apply_filters('wpinv_is_gst_country', $return, $country_code);
87 87
     }
88 88
     
89 89
     public static function enqueue_vat_scripts() {
90
-        if( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ) {
90
+        if (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules')) {
91 91
             self::load_vat_scripts();
92 92
         }
93 93
     }
94 94
 
95
-    public static function load_vat_scripts(){
96
-        $suffix     = '';//defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
95
+    public static function load_vat_scripts() {
96
+        $suffix = ''; //defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
97 97
 
98
-        wp_register_script( 'wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
99
-        wp_register_script( 'wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array( 'jquery' ),  WPINV_VERSION );
98
+        wp_register_script('wpinv-vat-validation-script', WPINV_PLUGIN_URL . 'assets/js/jsvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
99
+        wp_register_script('wpinv-vat-script', WPINV_PLUGIN_URL . 'assets/js/euvat' . $suffix . '.js', array('jquery'), WPINV_VERSION);
100 100
 
101
-        $vat_name   = self::get_vat_name();
101
+        $vat_name = self::get_vat_name();
102 102
 
103 103
         $vars = array();
104 104
         $vars['UseTaxes'] = wpinv_use_taxes();
105 105
         $vars['EUStates'] = self::get_eu_states();
106
-        $vars['NoRateSet'] = __( 'You have not set a rate. Do you want to continue?', 'invoicing' );
107
-        $vars['EmptyCompany'] = __( 'Please enter your registered company name!', 'invoicing' );
108
-        $vars['EmptyVAT'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
109
-        $vars['TotalsRefreshed'] = wp_sprintf( __( 'The invoice totals will be refreshed to update the %s.', 'invoicing' ), $vat_name );
110
-        $vars['ErrValidateVAT'] = wp_sprintf( __( 'Fail to validate the %s number!', 'invoicing' ), $vat_name );
111
-        $vars['ErrResetVAT'] = wp_sprintf( __( 'Fail to reset the %s number!', 'invoicing' ), $vat_name );
112
-        $vars['ErrInvalidVat'] = wp_sprintf( __( 'The %s number supplied does not have a valid format!', 'invoicing' ), $vat_name );
113
-        $vars['ErrInvalidResponse'] = __( 'An invalid response has been received from the server!', 'invoicing' );
106
+        $vars['NoRateSet'] = __('You have not set a rate. Do you want to continue?', 'invoicing');
107
+        $vars['EmptyCompany'] = __('Please enter your registered company name!', 'invoicing');
108
+        $vars['EmptyVAT'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
109
+        $vars['TotalsRefreshed'] = wp_sprintf(__('The invoice totals will be refreshed to update the %s.', 'invoicing'), $vat_name);
110
+        $vars['ErrValidateVAT'] = wp_sprintf(__('Fail to validate the %s number!', 'invoicing'), $vat_name);
111
+        $vars['ErrResetVAT'] = wp_sprintf(__('Fail to reset the %s number!', 'invoicing'), $vat_name);
112
+        $vars['ErrInvalidVat'] = wp_sprintf(__('The %s number supplied does not have a valid format!', 'invoicing'), $vat_name);
113
+        $vars['ErrInvalidResponse'] = __('An invalid response has been received from the server!', 'invoicing');
114 114
         $vars['ApplyVATRules'] = $vars['UseTaxes'] ? self::allow_vat_rules() : false;
115 115
         $vars['HideVatFields'] = $vars['ApplyVATRules'] ? self::hide_vat_fields() : true;
116
-        $vars['ErrResponse'] = __( 'The request response is invalid!', 'invoicing' );
117
-        $vars['ErrRateResponse'] = __( 'The get rate request response is invalid', 'invoicing' );
118
-        $vars['PageRefresh'] = __( 'The page will be refreshed in 10 seconds to show the new options.', 'invoicing' );
119
-        $vars['RequestResponseNotValidJSON'] = __( 'The get rate request response is not valid JSON', 'invoicing' );
120
-        $vars['GetRateRequestFailed'] = __( 'The get rate request failed: ', 'invoicing' );
121
-        $vars['NoRateInformationInResponse'] = __( 'The get rate request response does not contain any rate information', 'invoicing' );
122
-        $vars['RatesUpdated'] = __( 'The rates have been updated. Press the save button to record these new rates.', 'invoicing' );
123
-        $vars['IPAddressInformation'] = __( 'IP Address Information', 'invoicing' );
124
-        $vars['VatValidating'] = wp_sprintf( __( 'Validating %s number...', 'invoicing' ), $vat_name );
125
-        $vars['VatReseting'] = __( 'Reseting...', 'invoicing' );
126
-        $vars['VatValidated'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
127
-        $vars['VatNotValidated'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
128
-        $vars['ConfirmDeleteClass'] = __( 'Are you sure you wish to delete this rates class?', 'invoicing' );
116
+        $vars['ErrResponse'] = __('The request response is invalid!', 'invoicing');
117
+        $vars['ErrRateResponse'] = __('The get rate request response is invalid', 'invoicing');
118
+        $vars['PageRefresh'] = __('The page will be refreshed in 10 seconds to show the new options.', 'invoicing');
119
+        $vars['RequestResponseNotValidJSON'] = __('The get rate request response is not valid JSON', 'invoicing');
120
+        $vars['GetRateRequestFailed'] = __('The get rate request failed: ', 'invoicing');
121
+        $vars['NoRateInformationInResponse'] = __('The get rate request response does not contain any rate information', 'invoicing');
122
+        $vars['RatesUpdated'] = __('The rates have been updated. Press the save button to record these new rates.', 'invoicing');
123
+        $vars['IPAddressInformation'] = __('IP Address Information', 'invoicing');
124
+        $vars['VatValidating'] = wp_sprintf(__('Validating %s number...', 'invoicing'), $vat_name);
125
+        $vars['VatReseting'] = __('Reseting...', 'invoicing');
126
+        $vars['VatValidated'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
127
+        $vars['VatNotValidated'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
128
+        $vars['ConfirmDeleteClass'] = __('Are you sure you wish to delete this rates class?', 'invoicing');
129 129
         $vars['isFront'] = is_admin() ? false : true;
130 130
         $vars['baseCountry'] = wpinv_get_default_country();
131
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
132
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
131
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
132
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
133 133
 
134
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
135
-        wp_enqueue_script( 'wpinv-vat-script' );
136
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
134
+        wp_enqueue_script('wpinv-vat-validation-script');
135
+        wp_enqueue_script('wpinv-vat-script');
136
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
137 137
     }
138 138
 
139 139
     public static function enqueue_admin_scripts() {
140
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
140
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
141 141
             self::load_vat_scripts();
142 142
         }
143 143
     }
144 144
     
145
-    public static function section_vat_settings( $sections ) {
146
-        if ( !empty( $sections ) ) {
147
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
145
+    public static function section_vat_settings($sections) {
146
+        if (!empty($sections)) {
147
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
148 148
             
149
-            if ( self::allow_vat_classes() ) {
150
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
149
+            if (self::allow_vat_classes()) {
150
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
151 151
             }
152 152
         }
153 153
         return $sections;
@@ -156,52 +156,52 @@  discard block
 block discarded – undo
156 156
     public static function vat_rates_settings() {
157 157
         $vat_classes = self::get_rate_classes();
158 158
         $vat_rates = array();
159
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
160
-        $current_url = remove_query_arg( 'wpi_sub' );
159
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
160
+        $current_url = remove_query_arg('wpi_sub');
161 161
         
162 162
         $vat_rates['vat_rates_header'] = array(
163 163
             'id' => 'vat_rates_header',
164
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
164
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
165 165
             'desc' => '',
166 166
             'type' => 'header',
167 167
             'size' => 'regular'
168 168
         );
169 169
         $vat_rates['vat_rates_class'] = array(
170 170
             'id'          => 'vat_rates_class',
171
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
172
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
171
+            'name'        => __('Edit VAT Rates', 'invoicing'),
172
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
173 173
             'type'        => 'select',
174
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
175
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
174
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
175
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
176 176
             'selected'    => $vat_class,
177 177
             'class'       => 'wpi_select2',
178 178
             'onchange'    => 'document.location.href="' . $current_url . '&wpi_sub=" + this.value;',
179 179
         );
180 180
         
181
-        if ( $vat_class != '_standard' && $vat_class != '_new' ) {
181
+        if ($vat_class != '_standard' && $vat_class != '_new') {
182 182
             $vat_rates['vat_rate_delete'] = array(
183 183
                 'id'   => 'vat_rate_delete',
184 184
                 'type' => 'vat_rate_delete',
185 185
             );
186 186
         }
187 187
                     
188
-        if ( $vat_class == '_new' ) {
188
+        if ($vat_class == '_new') {
189 189
             $vat_rates['vat_rates_settings'] = array(
190 190
                 'id' => 'vat_rates_settings',
191
-                'name' => '<h3>' . __( 'Add New Rate Class', 'invoicing' ) . '</h3>',
191
+                'name' => '<h3>' . __('Add New Rate Class', 'invoicing') . '</h3>',
192 192
                 'type' => 'header',
193 193
             );
194 194
             $vat_rates['vat_rate_name'] = array(
195 195
                 'id'   => 'vat_rate_name',
196
-                'name' => __( 'Name', 'invoicing' ),
197
-                'desc' => __( 'A short name for the new VAT Rate class', 'invoicing' ),
196
+                'name' => __('Name', 'invoicing'),
197
+                'desc' => __('A short name for the new VAT Rate class', 'invoicing'),
198 198
                 'type' => 'text',
199 199
                 'size' => 'regular',
200 200
             );
201 201
             $vat_rates['vat_rate_desc'] = array(
202 202
                 'id'   => 'vat_rate_desc',
203
-                'name' => __( 'Description', 'invoicing' ),
204
-                'desc' => __( 'Manage VAT Rate class', 'invoicing' ),
203
+                'name' => __('Description', 'invoicing'),
204
+                'desc' => __('Manage VAT Rate class', 'invoicing'),
205 205
                 'type' => 'text',
206 206
                 'size' => 'regular',
207 207
             );
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
             $vat_rates['vat_rates'] = array(
214 214
                 'id'   => 'vat_rates',
215 215
                 'name' => '<h3>' . $vat_classes[$vat_class] . '</h3>',
216
-                'desc' => self::get_class_desc( $vat_class ),
216
+                'desc' => self::get_class_desc($vat_class),
217 217
                 'type' => 'vat_rates',
218 218
             );
219 219
         }
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
         return $vat_rates;
222 222
     }
223 223
     
224
-    public static function vat_settings( $settings ) {
225
-        if ( !empty( $settings ) ) {    
224
+    public static function vat_settings($settings) {
225
+        if (!empty($settings)) {    
226 226
             $vat_settings = array();
227 227
             $vat_settings['vat_company_title'] = array(
228 228
                 'id' => 'vat_company_title',
229
-                'name' => '<h3>' . __( 'Your Company Details', 'invoicing' ) . '</h3>',
229
+                'name' => '<h3>' . __('Your Company Details', 'invoicing') . '</h3>',
230 230
                 'desc' => '',
231 231
                 'type' => 'header',
232 232
                 'size' => 'regular'
@@ -234,22 +234,22 @@  discard block
 block discarded – undo
234 234
             
235 235
             $vat_settings['vat_company_name'] = array(
236 236
                 'id' => 'vat_company_name',
237
-                'name' => __( 'Your Company Name', 'invoicing' ),
238
-                'desc' => wp_sprintf(__( 'Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
237
+                'name' => __('Your Company Name', 'invoicing'),
238
+                'desc' => wp_sprintf(__('Your company name as it appears on your VAT return, you can verify it via your VAT ID on the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
239 239
                 'type' => 'text',
240 240
                 'size' => 'regular',
241 241
             );
242 242
             
243 243
             $vat_settings['vat_number'] = array(
244 244
                 'id'   => 'vat_number',
245
-                'name' => __( 'Your VAT Number', 'invoicing' ),
245
+                'name' => __('Your VAT Number', 'invoicing'),
246 246
                 'type' => 'vat_number',
247 247
                 'size' => 'regular',
248 248
             );
249 249
 
250 250
             $vat_settings['vat_settings_title'] = array(
251 251
                 'id' => 'vat_settings_title',
252
-                'name' => '<h3>' . __( 'Apply VAT Settings', 'invoicing' ) . '</h3>',
252
+                'name' => '<h3>' . __('Apply VAT Settings', 'invoicing') . '</h3>',
253 253
                 'desc' => '',
254 254
                 'type' => 'header',
255 255
                 'size' => 'regular'
@@ -257,8 +257,8 @@  discard block
 block discarded – undo
257 257
 
258 258
             $vat_settings['apply_vat_rules'] = array(
259 259
                 'id' => 'apply_vat_rules',
260
-                'name' => __( 'Enable VAT Rules', 'invoicing' ),
261
-                'desc' => __( 'Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable unless you know what you are doing.', 'invoicing' ) . '</font>',
260
+                'name' => __('Enable VAT Rules', 'invoicing'),
261
+                'desc' => __('Apply VAT to consumer sales from IP addresses within the EU, even if the billing address is outside the EU.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable unless you know what you are doing.', 'invoicing') . '</font>',
262 262
                 'type' => 'checkbox',
263 263
                 'std' => '1'
264 264
             );
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 
275 275
             $vat_settings['vat_prevent_b2c_purchase'] = array(
276 276
                 'id' => 'vat_prevent_b2c_purchase',
277
-                'name' => __( 'Prevent EU B2C Sales', 'invoicing' ),
278
-                'desc' => __( 'Enable this option if you are not registered for VAT in the EU.', 'invoicing' ),
277
+                'name' => __('Prevent EU B2C Sales', 'invoicing'),
278
+                'desc' => __('Enable this option if you are not registered for VAT in the EU.', 'invoicing'),
279 279
                 'type' => 'checkbox'
280 280
             );
281 281
 
@@ -283,22 +283,22 @@  discard block
 block discarded – undo
283 283
 
284 284
             $vat_settings['vat_same_country_rule'] = array(
285 285
                 'id'          => 'vat_same_country_rule',
286
-                'name'        => __( 'Same Country Rule', 'invoicing' ),
287
-                'desc'        => __( 'Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing' ),
286
+                'name'        => __('Same Country Rule', 'invoicing'),
287
+                'desc'        => __('Select how you want to handle VAT charge if sales are in the same country as the base country.', 'invoicing'),
288 288
                 'type'        => 'select',
289 289
                 'options'     => array(
290
-                    ''          => __( 'Normal', 'invoicing' ),
291
-                    'no'        => __( 'No VAT', 'invoicing' ),
292
-                    'always'    => __( 'Always apply VAT', 'invoicing' ),
290
+                    ''          => __('Normal', 'invoicing'),
291
+                    'no'        => __('No VAT', 'invoicing'),
292
+                    'always'    => __('Always apply VAT', 'invoicing'),
293 293
                 ),
294
-                'placeholder' => __( 'Select an option', 'invoicing' ),
294
+                'placeholder' => __('Select an option', 'invoicing'),
295 295
                 'std'         => '',
296 296
                 'class'   => 'wpi_select2',
297 297
             );
298 298
 
299 299
             $vat_settings['vat_checkout_title'] = array(
300 300
                 'id' => 'vat_checkout_title',
301
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
301
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
302 302
                 'desc' => '',
303 303
                 'type' => 'header',
304 304
                 'size' => 'regular'
@@ -306,14 +306,14 @@  discard block
 block discarded – undo
306 306
 
307 307
             $vat_settings['vat_disable_fields'] = array(
308 308
                 'id' => 'vat_disable_fields',
309
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
310
-                'desc' => __( 'Disable VAT fields if Invoicing is being used for GST.', 'invoicing' ) . '<br><font style="color:red">' . __( 'Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing' ) . '</font>',
309
+                'name' => __('Disable VAT Fields', 'invoicing'),
310
+                'desc' => __('Disable VAT fields if Invoicing is being used for GST.', 'invoicing') . '<br><font style="color:red">' . __('Do not disable if you have enabled Prevent EU B2C sales, otherwise Prevent EU B2C sales setting will not work.', 'invoicing') . '</font>',
311 311
                 'type' => 'checkbox'
312 312
             );
313 313
 
314 314
             $vat_settings['vat_ip_lookup'] = array(
315 315
                 'id'   => 'vat_ip_lookup',
316
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
316
+                'name' => __('IP Country Look-up', 'invoicing'),
317 317
                 'type' => 'vat_ip_lookup',
318 318
                 'size' => 'regular',
319 319
                 'std' => 'default',
@@ -322,21 +322,21 @@  discard block
 block discarded – undo
322 322
 
323 323
             $vat_settings['hide_ip_address'] = array(
324 324
                 'id' => 'hide_ip_address',
325
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
326
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
325
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
326
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
327 327
                 'type' => 'checkbox'
328 328
             );
329 329
 
330 330
             $vat_settings['vat_ip_country_default'] = array(
331 331
                 'id' => 'vat_ip_country_default',
332
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
333
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
332
+                'name' => __('Enable IP Country as Default', 'invoicing'),
333
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
334 334
                 'type' => 'checkbox'
335 335
             );
336 336
 
337 337
             $vat_settings['vies_validation_title'] = array(
338 338
                 'id' => 'vies_validation_title',
339
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
339
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
340 340
                 'desc' => '',
341 341
                 'type' => 'header',
342 342
                 'size' => 'regular'
@@ -344,37 +344,37 @@  discard block
 block discarded – undo
344 344
 
345 345
             $vat_settings['vat_vies_check'] = array(
346 346
                 'id' => 'vat_vies_check',
347
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
348
-                'desc' => wp_sprintf( __( 'Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
347
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
348
+                'desc' => wp_sprintf(__('Prevent VAT numbers from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
349 349
                 'type' => 'checkbox'
350 350
             );
351 351
 
352 352
             $vat_settings['vat_disable_company_name_check'] = array(
353 353
                 'id' => 'vat_disable_company_name_check',
354
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
355
-                'desc' => wp_sprintf( __( 'Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing' ), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>' ),
354
+                'name' => __('Disable VIES Name Check', 'invoicing'),
355
+                'desc' => wp_sprintf(__('Prevent company name from being validated by the %sEU VIES System.%s', 'invoicing'), '<a href="http://ec.europa.eu/taxation_customs/vies/" target="_blank">', '</a>'),
356 356
                 'type' => 'checkbox'
357 357
             );
358 358
 
359 359
             $vat_settings['vat_offline_check'] = array(
360 360
                 'id' => 'vat_offline_check',
361
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
362
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
361
+                'name' => __('Disable Basic Checks', 'invoicing'),
362
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
363 363
                 'type' => 'checkbox'
364 364
             );
365 365
             
366 366
 
367 367
             $settings['vat'] = $vat_settings;
368 368
             
369
-            if ( self::allow_vat_classes() ) {
369
+            if (self::allow_vat_classes()) {
370 370
                 $settings['vat_rates'] = self::vat_rates_settings();
371 371
             }
372 372
             
373 373
             $eu_fallback_rate = array(
374 374
                 'id'   => 'eu_fallback_rate',
375
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
375
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
376 376
                 'type' => 'eu_fallback_rate',
377
-                'desc' => __( 'Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing' ),
377
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
378 378
                 'std'  => '20',
379 379
                 'size' => 'small'
380 380
             );
@@ -390,11 +390,11 @@  discard block
 block discarded – undo
390 390
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
391 391
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
392 392
         
393
-        if ( !is_dir( $destination_dir ) ) { 
394
-            mkdir( $destination_dir );
393
+        if (!is_dir($destination_dir)) { 
394
+            mkdir($destination_dir);
395 395
         }
396 396
         
397
-        $database_files     = array(
397
+        $database_files = array(
398 398
             'country'   => array(
399 399
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
400 400
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -405,57 +405,57 @@  discard block
 block discarded – undo
405 405
             )
406 406
         );
407 407
 
408
-        foreach( $database_files as $database => $files ) {
409
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
408
+        foreach ($database_files as $database => $files) {
409
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
410 410
             
411
-            if ( empty( $result['success'] ) ) {
411
+            if (empty($result['success'])) {
412 412
                 echo $result['message'];
413 413
                 exit;
414 414
             }
415 415
             
416
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
417
-            echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
416
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
417
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
418 418
         }
419 419
         
420 420
         exit;
421 421
     }
422 422
     
423
-    public static function geoip2_download_file( $source_url, $destination_file ) {
423
+    public static function geoip2_download_file($source_url, $destination_file) {
424 424
         $success    = false;
425 425
         $message    = '';
426 426
         
427
-        if ( !function_exists( 'download_url' ) ) {
428
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
427
+        if (!function_exists('download_url')) {
428
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
429 429
         }
430 430
 
431
-        $temp_file  = download_url( $source_url );
431
+        $temp_file = download_url($source_url);
432 432
         
433
-        if ( is_wp_error( $temp_file ) ) {
434
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
433
+        if (is_wp_error($temp_file)) {
434
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
435 435
         } else {
436
-            $handle = gzopen( $temp_file, 'rb' );
436
+            $handle = gzopen($temp_file, 'rb');
437 437
             
438
-            if ( $handle ) {
439
-                $fopen  = fopen( $destination_file, 'wb' );
440
-                if ( $fopen ) {
441
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
442
-                        fwrite( $fopen, $data );
438
+            if ($handle) {
439
+                $fopen = fopen($destination_file, 'wb');
440
+                if ($fopen) {
441
+                    while (($data = gzread($handle, 4096)) != false) {
442
+                        fwrite($fopen, $data);
443 443
                     }
444 444
 
445
-                    gzclose( $handle );
446
-                    fclose( $fopen );
445
+                    gzclose($handle);
446
+                    fclose($fopen);
447 447
                         
448 448
                     $success = true;
449 449
                 } else {
450
-                    gzclose( $handle );
451
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
450
+                    gzclose($handle);
451
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
452 452
                 }
453 453
             } else {
454
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
454
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
455 455
             }
456 456
             
457
-            if ( file_exists( $temp_file ) ) {
458
-                unlink( $temp_file );
457
+            if (file_exists($temp_file)) {
458
+                unlink($temp_file);
459 459
             }
460 460
         }
461 461
         
@@ -467,11 +467,11 @@  discard block
 block discarded – undo
467 467
     }
468 468
     
469 469
     public static function load_geoip2() {
470
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
470
+        if (defined('WPINV_GEOIP2_LODDED')) {
471 471
             return;
472 472
         }
473 473
         
474
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
474
+        if (!class_exists('\MaxMind\Db\Reader')) {
475 475
             $maxmind_db_files = array(
476 476
                 'Reader/Decoder.php',
477 477
                 'Reader/InvalidDatabaseException.php',
@@ -480,12 +480,12 @@  discard block
 block discarded – undo
480 480
                 'Reader.php',
481 481
             );
482 482
             
483
-            foreach ( $maxmind_db_files as $key => $file ) {
484
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
483
+            foreach ($maxmind_db_files as $key => $file) {
484
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
485 485
             }
486 486
         }
487 487
         
488
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
488
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
489 489
             $geoip2_files = array(
490 490
                 'ProviderInterface.php',
491 491
                 'Compat/JsonSerializable.php',
@@ -519,23 +519,23 @@  discard block
 block discarded – undo
519 519
                 'WebService/Client.php',
520 520
             );
521 521
             
522
-            foreach ( $geoip2_files as $key => $file ) {
523
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
522
+            foreach ($geoip2_files as $key => $file) {
523
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
524 524
             }
525 525
         }
526 526
 
527
-        define( 'WPINV_GEOIP2_LODDED', true );
527
+        define('WPINV_GEOIP2_LODDED', true);
528 528
     }
529 529
 
530 530
     public static function geoip2_country_dbfile() {
531 531
         $upload_dir = wp_upload_dir();
532 532
 
533
-        if ( !isset( $upload_dir['basedir'] ) ) {
533
+        if (!isset($upload_dir['basedir'])) {
534 534
             return false;
535 535
         }
536 536
 
537 537
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
538
-        if ( !file_exists( $filename ) ) {
538
+        if (!file_exists($filename)) {
539 539
             return false;
540 540
         }
541 541
         
@@ -545,12 +545,12 @@  discard block
 block discarded – undo
545 545
     public static function geoip2_city_dbfile() {
546 546
         $upload_dir = wp_upload_dir();
547 547
 
548
-        if ( !isset( $upload_dir['basedir'] ) ) {
548
+        if (!isset($upload_dir['basedir'])) {
549 549
             return false;
550 550
         }
551 551
 
552 552
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
553
-        if ( !file_exists( $filename ) ) {
553
+        if (!file_exists($filename)) {
554 554
             return false;
555 555
         }
556 556
         
@@ -561,10 +561,10 @@  discard block
 block discarded – undo
561 561
         try {
562 562
             self::load_geoip2();
563 563
 
564
-            if ( $filename = self::geoip2_country_dbfile() ) {
565
-                return new \GeoIp2\Database\Reader( $filename );
564
+            if ($filename = self::geoip2_country_dbfile()) {
565
+                return new \GeoIp2\Database\Reader($filename);
566 566
             }
567
-        } catch( Exception $e ) {
567
+        } catch (Exception $e) {
568 568
             return false;
569 569
         }
570 570
         
@@ -575,173 +575,173 @@  discard block
 block discarded – undo
575 575
         try {
576 576
             self::load_geoip2();
577 577
 
578
-            if ( $filename = self::geoip2_city_dbfile() ) {
579
-                return new \GeoIp2\Database\Reader( $filename );
578
+            if ($filename = self::geoip2_city_dbfile()) {
579
+                return new \GeoIp2\Database\Reader($filename);
580 580
             }
581
-        } catch( Exception $e ) {
581
+        } catch (Exception $e) {
582 582
             return false;
583 583
         }
584 584
         
585 585
         return false;
586 586
     }
587 587
 
588
-    public static function geoip2_country_record( $ip_address ) {
588
+    public static function geoip2_country_record($ip_address) {
589 589
         try {
590 590
             $reader = self::geoip2_country_reader();
591 591
 
592
-            if ( $reader ) {
593
-                $record = $reader->country( $ip_address );
592
+            if ($reader) {
593
+                $record = $reader->country($ip_address);
594 594
                 
595
-                if ( !empty( $record->country->isoCode ) ) {
595
+                if (!empty($record->country->isoCode)) {
596 596
                     return $record;
597 597
                 }
598 598
             }
599
-        } catch(\InvalidArgumentException $e) {
600
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
599
+        } catch (\InvalidArgumentException $e) {
600
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
601 601
             
602 602
             return false;
603
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
604
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
603
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
604
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
605 605
             
606 606
             return false;
607
-        } catch( Exception $e ) {
607
+        } catch (Exception $e) {
608 608
             return false;
609 609
         }
610 610
         
611 611
         return false;
612 612
     }
613 613
 
614
-    public static function geoip2_city_record( $ip_address ) {
614
+    public static function geoip2_city_record($ip_address) {
615 615
         try {
616 616
             $reader = self::geoip2_city_reader();
617 617
 
618
-            if ( $reader ) {
619
-                $record = $reader->city( $ip_address );
618
+            if ($reader) {
619
+                $record = $reader->city($ip_address);
620 620
                 
621
-                if ( !empty( $record->country->isoCode ) ) {
621
+                if (!empty($record->country->isoCode)) {
622 622
                     return $record;
623 623
                 }
624 624
             }
625
-        } catch(\InvalidArgumentException $e) {
626
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
625
+        } catch (\InvalidArgumentException $e) {
626
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
627 627
             
628 628
             return false;
629
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
630
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
629
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
630
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
631 631
             
632 632
             return false;
633
-        } catch( Exception $e ) {
633
+        } catch (Exception $e) {
634 634
             return false;
635 635
         }
636 636
         
637 637
         return false;
638 638
     }
639 639
 
640
-    public static function geoip2_country_code( $ip_address ) {
641
-        $record = self::geoip2_country_record( $ip_address );
642
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
640
+    public static function geoip2_country_code($ip_address) {
641
+        $record = self::geoip2_country_record($ip_address);
642
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
643 643
     }
644 644
 
645 645
     // Find country by IP address.
646
-    public static function get_country_by_ip( $ip = '' ) {
646
+    public static function get_country_by_ip($ip = '') {
647 647
         global $wpinv_ip_address_country;
648 648
         
649
-        if ( !empty( $wpinv_ip_address_country ) ) {
649
+        if (!empty($wpinv_ip_address_country)) {
650 650
             return $wpinv_ip_address_country;
651 651
         }
652 652
         
653
-        if ( empty( $ip ) ) {
653
+        if (empty($ip)) {
654 654
             $ip = wpinv_get_ip();
655 655
         }
656 656
 
657
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
658
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
657
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
658
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
659 659
 
660
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
661
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
660
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
661
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
662 662
                 try {
663
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
664
-                } catch( Exception $e ) {
665
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
663
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
664
+                } catch (Exception $e) {
665
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
666 666
                 }
667
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
668
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
669
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
670
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
667
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
668
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
669
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
670
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
671 671
                 
672
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
672
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
673 673
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
674 674
                 }
675 675
             }
676 676
         }
677 677
 
678
-        if ( empty( $wpinv_ip_address_country ) ) {
678
+        if (empty($wpinv_ip_address_country)) {
679 679
             $wpinv_ip_address_country = wpinv_get_default_country();
680 680
         }
681 681
 
682 682
         return $wpinv_ip_address_country;
683 683
     }
684 684
     
685
-    public static function sanitize_vat_settings( $input ) {
685
+    public static function sanitize_vat_settings($input) {
686 686
         global $wpinv_options;
687 687
         
688 688
         $valid      = false;
689 689
         $message    = '';
690 690
         
691
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
692
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
693
-                $valid = self::offline_check( $input['vat_number'] );
691
+        if (!empty($wpinv_options['vat_vies_check'])) {
692
+            if (empty($wpinv_options['vat_offline_check'])) {
693
+                $valid = self::offline_check($input['vat_number']);
694 694
             } else {
695 695
                 $valid = true;
696 696
             }
697 697
             
698
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
698
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
699 699
         } else {
700
-            $result = self::check_vat( $input['vat_number'] );
700
+            $result = self::check_vat($input['vat_number']);
701 701
             
702
-            if ( empty( $result['valid'] ) ) {
702
+            if (empty($result['valid'])) {
703 703
                 $valid      = false;
704 704
                 $message    = $result['message'];
705 705
             } else {
706
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
707
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
706
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
707
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
708 708
             }
709 709
         }
710 710
 
711
-        if ( $message && self::is_vat_validated() != $valid ) {
712
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
711
+        if ($message && self::is_vat_validated() != $valid) {
712
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
713 713
         }
714 714
 
715 715
         $input['vat_valid'] = $valid;
716 716
         return $input;
717 717
     }
718 718
     
719
-    public static function sanitize_vat_rates( $input ) {
720
-        if( !current_user_can( 'manage_options' ) ) {
721
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
719
+    public static function sanitize_vat_rates($input) {
720
+        if (!current_user_can('manage_options')) {
721
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
722 722
             return $input;
723 723
         }
724 724
         
725 725
         $vat_classes = self::get_rate_classes();
726
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
726
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
727 727
         
728
-        if ( empty( $vat_class ) ) {
729
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
728
+        if (empty($vat_class)) {
729
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
730 730
             
731 731
             return $input;
732 732
         }
733 733
 
734
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
734
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
735 735
 
736
-        if ( $vat_class === '_standard' ) {
736
+        if ($vat_class === '_standard') {
737 737
             // Save the active rates in the invoice settings
738
-            update_option( 'wpinv_tax_rates', $new_rates );
738
+            update_option('wpinv_tax_rates', $new_rates);
739 739
         } else {
740 740
             // Get the existing set of rates
741 741
             $rates = self::get_non_standard_rates();
742 742
             $rates[$vat_class] = $new_rates;
743 743
 
744
-            update_option( 'wpinv_vat_rates', $rates );
744
+            update_option('wpinv_vat_rates', $rates);
745 745
         }
746 746
         
747 747
         return $input;
@@ -751,71 +751,71 @@  discard block
 block discarded – undo
751 751
         $response = array();
752 752
         $response['success'] = false;
753 753
         
754
-        if ( !current_user_can( 'manage_options' ) ) {
755
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
756
-            wp_send_json( $response );
754
+        if (!current_user_can('manage_options')) {
755
+            $response['error'] = __('Invalid access!', 'invoicing');
756
+            wp_send_json($response);
757 757
         }
758 758
         
759
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
760
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
759
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
760
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
761 761
         
762
-        if ( empty( $vat_class_name ) ) {
763
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
764
-            wp_send_json( $response );
762
+        if (empty($vat_class_name)) {
763
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
764
+            wp_send_json($response);
765 765
         }
766 766
         
767 767
         $vat_classes = (array)self::get_rate_classes();
768 768
 
769
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
770
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
771
-            wp_send_json( $response );
769
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
770
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
771
+            wp_send_json($response);
772 772
         }
773 773
         
774
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
775
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
774
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
775
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
776 776
         
777
-        $vat_classes = (array)self::get_rate_classes( true );
778
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
777
+        $vat_classes = (array)self::get_rate_classes(true);
778
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
779 779
         
780
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
780
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
781 781
         
782 782
         $response['success'] = true;
783
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
783
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
784 784
         
785
-        wp_send_json( $response );
785
+        wp_send_json($response);
786 786
     }
787 787
     
788 788
     public static function delete_class() {
789 789
         $response = array();
790 790
         $response['success'] = false;
791 791
         
792
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
793
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
794
-            wp_send_json( $response );
792
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
793
+            $response['error'] = __('Invalid access!', 'invoicing');
794
+            wp_send_json($response);
795 795
         }
796 796
         
797
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
797
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
798 798
         $vat_classes = (array)self::get_rate_classes();
799 799
 
800
-        if ( !isset( $vat_classes[$vat_class] ) ) {
801
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
802
-            wp_send_json( $response );
800
+        if (!isset($vat_classes[$vat_class])) {
801
+            $response['error'] = __('Requested class does not exists', 'invoicing');
802
+            wp_send_json($response);
803 803
         }
804 804
         
805
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
806
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
807
-            wp_send_json( $response );
805
+        if ($vat_class == '_new' || $vat_class == '_standard') {
806
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
807
+            wp_send_json($response);
808 808
         }
809 809
             
810
-        $vat_classes = (array)self::get_rate_classes( true );
811
-        unset( $vat_classes[$vat_class] );
810
+        $vat_classes = (array)self::get_rate_classes(true);
811
+        unset($vat_classes[$vat_class]);
812 812
         
813
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
813
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
814 814
         
815 815
         $response['success'] = true;
816
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
816
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
817 817
         
818
-        wp_send_json( $response );
818
+        wp_send_json($response);
819 819
     }
820 820
     
821 821
     public static function update_eu_rates() {        
@@ -824,72 +824,72 @@  discard block
 block discarded – undo
824 824
         $response['error']      = null;
825 825
         $response['data']       = null;
826 826
         
827
-        if ( !current_user_can( 'manage_options' ) ) {
828
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
829
-            wp_send_json( $response );
827
+        if (!current_user_can('manage_options')) {
828
+            $response['error'] = __('Invalid access!', 'invoicing');
829
+            wp_send_json($response);
830 830
         }
831 831
         
832
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
833
-        $euvatrates = self::request_euvatrates( $group );
832
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
833
+        $euvatrates = self::request_euvatrates($group);
834 834
         
835
-        if ( !empty( $euvatrates ) ) {
836
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
835
+        if (!empty($euvatrates)) {
836
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
837 837
                 $response['success']        = true;
838 838
                 $response['data']['rates']  = $euvatrates['rates'];
839
-            } else if ( !empty( $euvatrates['error'] ) ) {
839
+            } else if (!empty($euvatrates['error'])) {
840 840
                 $response['error']          = $euvatrates['error'];
841 841
             }
842 842
         }
843 843
             
844
-        wp_send_json( $response );
844
+        wp_send_json($response);
845 845
     }
846 846
     
847 847
     public static function hide_vat_fields() {
848
-        $hide = wpinv_get_option( 'vat_disable_fields' );
848
+        $hide = wpinv_get_option('vat_disable_fields');
849 849
         
850
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
850
+        return apply_filters('wpinv_hide_vat_fields', $hide);
851 851
     }
852 852
     
853 853
     public static function same_country_rule() {
854
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
854
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
855 855
         
856
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
856
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
857 857
     }
858 858
     
859 859
     public static function get_vat_name() {
860
-        $vat_name   = wpinv_get_option( 'vat_name' );
861
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
860
+        $vat_name   = wpinv_get_option('vat_name');
861
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
862 862
         
863
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
863
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
864 864
     }
865 865
     
866 866
     public static function get_company_name() {
867
-        $company_name = wpinv_get_option( 'vat_company_name' );
867
+        $company_name = wpinv_get_option('vat_company_name');
868 868
         
869
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
869
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
870 870
     }
871 871
     
872 872
     public static function get_vat_number() {
873
-        $vat_number = wpinv_get_option( 'vat_number' );
873
+        $vat_number = wpinv_get_option('vat_number');
874 874
         
875
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
875
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
876 876
     }
877 877
     
878 878
     public static function is_vat_validated() {
879
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
879
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
880 880
         
881
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
881
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
882 882
     }
883 883
     
884
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
885
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
884
+    public static function sanitize_vat($vat_number, $country_code = '') {        
885
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
886 886
         
887
-        if ( empty( $country_code ) ) {
888
-            $country_code = substr( $vat_number, 0, 2 );
887
+        if (empty($country_code)) {
888
+            $country_code = substr($vat_number, 0, 2);
889 889
         }
890 890
         
891
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
892
-            $vat = str_replace( $country_code, '', $vat_number );
891
+        if (strpos($vat_number, $country_code) === 0) {
892
+            $vat = str_replace($country_code, '', $vat_number);
893 893
         } else {
894 894
             $vat = $country_code . $vat_number;
895 895
         }
@@ -902,140 +902,140 @@  discard block
 block discarded – undo
902 902
         return $return;
903 903
     }
904 904
     
905
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
906
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
905
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
906
+        $vat            = self::sanitize_vat($vat_number, $country_code);
907 907
         $vat_number     = $vat['vat_number'];
908 908
         $country_code   = $vat['iso'];
909 909
         $regex          = array();
910 910
         
911
-        switch ( $country_code ) {
911
+        switch ($country_code) {
912 912
             case 'AT':
913
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
913
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
914 914
                 break;
915 915
             case 'BE':
916
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
916
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
917 917
                 break;
918 918
             case 'BG':
919
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
919
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
920 920
                 break;
921 921
             case 'CH':
922 922
             case 'CHE':
923
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
923
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
924 924
                 break;
925 925
             case 'CY':
926
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
926
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
927 927
                 break;
928 928
             case 'CZ':
929
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
929
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
930 930
                 break;
931 931
             case 'DE':
932
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
932
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
933 933
                 break;
934 934
             case 'DK':
935
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
935
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
936 936
                 break;
937 937
             case 'EE':
938
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
938
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
939 939
                 break;
940 940
             case 'EL':
941
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
941
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
942 942
                 break;
943 943
             case 'ES':
944
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
945
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
946
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
947
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
944
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
945
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
946
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
947
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
948 948
                 break;
949 949
             case 'EU':
950
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
950
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
951 951
                 break;
952 952
             case 'FI':
953
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
953
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
954 954
                 break;
955 955
             case 'FR':
956
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
957
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
958
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
959
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
956
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
957
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
958
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
959
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
960 960
                 break;
961 961
             case 'GB':
962
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
963
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
964
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
965
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
962
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
963
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
964
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
965
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
966 966
                 break;
967 967
             case 'GR':
968
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
968
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
969 969
                 break;
970 970
             case 'HR':
971
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
971
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
972 972
                 break;
973 973
             case 'HU':
974
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
974
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
975 975
                 break;
976 976
             case 'IE':
977
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
978
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
979
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
977
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
978
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
979
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
980 980
                 break;
981 981
             case 'IT':
982
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
982
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
983 983
                 break;
984 984
             case 'LV':
985
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
985
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
986 986
                 break;
987 987
             case 'LT':
988
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
988
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
989 989
                 break;
990 990
             case 'LU':
991
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
991
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
992 992
                 break;
993 993
             case 'MT':
994
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
994
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
995 995
                 break;
996 996
             case 'NL':
997
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
997
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
998 998
                 break;
999 999
             case 'NO':
1000
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
1000
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
1001 1001
                 break;
1002 1002
             case 'PL':
1003
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1003
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1004 1004
                 break;
1005 1005
             case 'PT':
1006
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1006
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1007 1007
                 break;
1008 1008
             case 'RO':
1009
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1009
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1010 1010
                 break;
1011 1011
             case 'RS':
1012
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1012
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1013 1013
                 break;
1014 1014
             case 'SI':
1015
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1015
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1016 1016
                 break;
1017 1017
             case 'SK':
1018
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1018
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1019 1019
                 break;
1020 1020
             case 'SE':
1021
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1021
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1022 1022
                 break;
1023 1023
             default:
1024 1024
                 $regex = array();
1025 1025
             break;
1026 1026
         }
1027 1027
         
1028
-        if ( empty( $regex ) ) {
1028
+        if (empty($regex)) {
1029 1029
             return false;
1030 1030
         }
1031 1031
         
1032
-        foreach ( $regex as $pattern ) {
1032
+        foreach ($regex as $pattern) {
1033 1033
             $matches = null;
1034
-            preg_match_all( $pattern, $vat_number, $matches );
1034
+            preg_match_all($pattern, $vat_number, $matches);
1035 1035
             
1036
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1037
-                if ( $formatted ) {
1038
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1036
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1037
+                if ($formatted) {
1038
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1039 1039
                 } else {
1040 1040
                     return true;
1041 1041
                 }
@@ -1045,75 +1045,75 @@  discard block
 block discarded – undo
1045 1045
         return false;
1046 1046
     }
1047 1047
     
1048
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1049
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1048
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1049
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1050 1050
         $vat_number     = $vat['vat'];
1051 1051
         $iso            = $vat['iso'];
1052 1052
         
1053
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1053
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1054 1054
         
1055
-        if ( ini_get( 'allow_url_fopen' ) ) {
1056
-            $response = file_get_contents( $url );
1057
-        } else if ( function_exists( 'curl_init' ) ) {
1055
+        if (ini_get('allow_url_fopen')) {
1056
+            $response = file_get_contents($url);
1057
+        } else if (function_exists('curl_init')) {
1058 1058
             $ch = curl_init();
1059 1059
             
1060
-            curl_setopt( $ch, CURLOPT_URL, $url );
1061
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1062
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1063
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1064
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1060
+            curl_setopt($ch, CURLOPT_URL, $url);
1061
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1062
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1063
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1064
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1065 1065
             
1066
-            $response = curl_exec( $ch );
1066
+            $response = curl_exec($ch);
1067 1067
             
1068
-            if ( curl_errno( $ch ) ) {
1069
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1068
+            if (curl_errno($ch)) {
1069
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1070 1070
                 $response = '';
1071 1071
             }
1072 1072
             
1073
-            curl_close( $ch );
1073
+            curl_close($ch);
1074 1074
         } else {
1075
-            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' );
1075
+            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');
1076 1076
         }
1077 1077
         
1078
-        if ( empty( $response ) ) {
1078
+        if (empty($response)) {
1079 1079
             return $result;
1080 1080
         }
1081 1081
 
1082
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1082
+        if (preg_match('/invalid VAT number/i', $response)) {
1083 1083
             return false;
1084
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1085
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1084
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1085
+            $content = explode("valid VAT number", htmlentities($response));
1086 1086
             
1087
-            if ( !empty( $content[1] ) ) {
1088
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1087
+            if (!empty($content[1])) {
1088
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1089 1089
                 
1090
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1090
+                if (!empty($matches[2]) && $matches[3]) {
1091 1091
                     $return = array();
1092 1092
                     
1093
-                    foreach ( $matches[2] as $key => $label ) {
1094
-                        $label = trim( $label );
1093
+                    foreach ($matches[2] as $key => $label) {
1094
+                        $label = trim($label);
1095 1095
                         
1096
-                        switch ( strtolower( $label ) ) {
1096
+                        switch (strtolower($label)) {
1097 1097
                             case 'member state':
1098
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1098
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1099 1099
                             break;
1100 1100
                             case 'vat number':
1101
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1101
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1102 1102
                             break;
1103 1103
                             case 'name':
1104
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1104
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1105 1105
                             break;
1106 1106
                             case 'address':
1107
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1108
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1107
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1108
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1109 1109
                             break;
1110 1110
                             case 'consultation number':
1111
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1111
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1112 1112
                             break;
1113 1113
                         }
1114 1114
                     }
1115 1115
                     
1116
-                    if ( !empty( $return ) ) {
1116
+                    if (!empty($return)) {
1117 1117
                         return $return;
1118 1118
                     }
1119 1119
                 }
@@ -1125,55 +1125,55 @@  discard block
 block discarded – undo
1125 1125
         }
1126 1126
     }
1127 1127
     
1128
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1128
+    public static function check_vat($vat_number, $country_code = '') {        
1129 1129
         $vat_name           = self::get_vat_name();
1130 1130
         
1131 1131
         $return             = array();
1132 1132
         $return['valid']    = false;
1133
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1133
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1134 1134
                 
1135
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1135
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1136 1136
             return $return;
1137 1137
         }
1138 1138
             
1139
-        $response = self::vies_check( $vat_number, $country_code );
1139
+        $response = self::vies_check($vat_number, $country_code);
1140 1140
         
1141
-        if ( $response ) {
1142
-            $return['valid']    = true;
1141
+        if ($response) {
1142
+            $return['valid'] = true;
1143 1143
             
1144
-            if ( is_array( $response ) ) {
1145
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1146
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1144
+            if (is_array($response)) {
1145
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1146
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1147 1147
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1148 1148
             }
1149 1149
         } else {
1150 1150
             $return['valid']    = false;
1151
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1151
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1152 1152
         }
1153 1153
         
1154 1154
         return $return;
1155 1155
     }
1156 1156
     
1157
-    public static function request_euvatrates( $group ) {
1157
+    public static function request_euvatrates($group) {
1158 1158
         $response               = array();
1159 1159
         $response['success']    = false;
1160 1160
         $response['error']      = null;
1161 1161
         $response['eurates']    = null;
1162 1162
         
1163 1163
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1164
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1165
-        $api_response   = wp_remote_get( $euvatrates_url );
1164
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1165
+        $api_response   = wp_remote_get($euvatrates_url);
1166 1166
     
1167 1167
         try {
1168
-            if ( is_wp_error( $api_response ) ) {
1169
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1168
+            if (is_wp_error($api_response)) {
1169
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1170 1170
             } else {
1171
-                $body = json_decode( $api_response['body'] );
1171
+                $body = json_decode($api_response['body']);
1172 1172
                 
1173
-                if ( isset( $body->rates ) ) {
1173
+                if (isset($body->rates)) {
1174 1174
                     $rates = array();
1175 1175
                     
1176
-                    foreach ( $body->rates as $country_code => $rate ) {
1176
+                    foreach ($body->rates as $country_code => $rate) {
1177 1177
                         $vat_rate = array();
1178 1178
                         $vat_rate['country']        = $rate->country;
1179 1179
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1181,7 +1181,7 @@  discard block
 block discarded – undo
1181 1181
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1182 1182
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1183 1183
                         
1184
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1184
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1185 1185
                             $vat_rate_group = array();
1186 1186
                             $vat_rate_group['country'] = $rate->country;
1187 1187
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1193,79 +1193,79 @@  discard block
 block discarded – undo
1193 1193
                     }
1194 1194
                     
1195 1195
                     $response['success']    = true;                                
1196
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1196
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1197 1197
                 } else {
1198
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1198
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1199 1199
                 }
1200 1200
             }
1201
-        } catch ( Exception $e ) {
1202
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1201
+        } catch (Exception $e) {
1202
+            $response['error'] = __($e->getMessage(), 'invoicing');
1203 1203
         }
1204 1204
         
1205
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1205
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1206 1206
     }    
1207 1207
     
1208
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1208
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1209 1209
         global $wpi_item_id, $wpi_country;
1210 1210
         
1211
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1212
-            $country_code = trim( $_POST['wpinv_country'] );
1213
-        } else if ( !empty( $_POST['country'] ) ) {
1214
-            $country_code = trim( $_POST['country'] );
1215
-        } else if ( !empty( $wpi_country ) ) {
1211
+        if (!empty($_POST['wpinv_country'])) {
1212
+            $country_code = trim($_POST['wpinv_country']);
1213
+        } else if (!empty($_POST['country'])) {
1214
+            $country_code = trim($_POST['country']);
1215
+        } else if (!empty($wpi_country)) {
1216 1216
             $country_code = $wpi_country;
1217 1217
         } else {
1218
-            $country_code = self::get_user_country( '', $user_id );
1218
+            $country_code = self::get_user_country('', $user_id);
1219 1219
         }
1220 1220
         
1221
-        if ( $is_digital === null && $wpi_item_id ) {
1222
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1221
+        if ($is_digital === null && $wpi_item_id) {
1222
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1223 1223
         }
1224 1224
         
1225
-        if ( !empty( $country_code ) ) {
1226
-            $requires_vat = ( self::is_eu_state( $country_code ) && ( self::is_eu_state( self::$default_country ) || $is_digital ) ) || ( self::is_gst_country( $country_code ) && self::is_gst_country( self::$default_country ) );
1225
+        if (!empty($country_code)) {
1226
+            $requires_vat = (self::is_eu_state($country_code) && (self::is_eu_state(self::$default_country) || $is_digital)) || (self::is_gst_country($country_code) && self::is_gst_country(self::$default_country));
1227 1227
         }
1228 1228
         
1229
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1229
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1230 1230
     }
1231 1231
     
1232
-    public static function tax_label( $label = '' ) {
1232
+    public static function tax_label($label = '') {
1233 1233
         global $wpi_requires_vat;
1234 1234
         
1235
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1236
-            $wpi_requires_vat = self::requires_vat( 0, false );
1235
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1236
+            $wpi_requires_vat = self::requires_vat(0, false);
1237 1237
         }
1238 1238
         
1239
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1239
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1240 1240
     }
1241 1241
     
1242 1242
     public static function standard_rates_label() {
1243
-        return __( 'Standard Rates', 'invoicing' );
1243
+        return __('Standard Rates', 'invoicing');
1244 1244
     }
1245 1245
     
1246
-    public static function get_rate_classes( $with_desc = false ) {        
1247
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1248
-        $classes = maybe_unserialize( $rate_classes_option );
1246
+    public static function get_rate_classes($with_desc = false) {        
1247
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1248
+        $classes = maybe_unserialize($rate_classes_option);
1249 1249
         
1250
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1250
+        if (empty($classes) || !is_array($classes)) {
1251 1251
             $classes = array();
1252 1252
         }
1253 1253
 
1254 1254
         $rate_classes = array();
1255
-        if ( !array_key_exists( '_standard', $classes ) ) {
1256
-            if ( $with_desc ) {
1257
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1255
+        if (!array_key_exists('_standard', $classes)) {
1256
+            if ($with_desc) {
1257
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1258 1258
             } else {
1259 1259
                 $rate_classes['_standard'] = self::standard_rates_label();
1260 1260
             }
1261 1261
         }
1262 1262
         
1263
-        foreach ( $classes as $key => $class ) {
1264
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1265
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1263
+        foreach ($classes as $key => $class) {
1264
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1265
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1266 1266
             
1267
-            if ( $with_desc ) {
1268
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1267
+            if ($with_desc) {
1268
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1269 1269
             } else {
1270 1270
                 $rate_classes[$key] = $name;
1271 1271
             }
@@ -1276,15 +1276,15 @@  discard block
 block discarded – undo
1276 1276
     
1277 1277
     public static function get_all_classes() {        
1278 1278
         $classes            = self::get_rate_classes();
1279
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1279
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1280 1280
         
1281
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1281
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1282 1282
     }
1283 1283
     
1284
-    public static function get_class_desc( $rate_class ) {        
1285
-        $rate_classes = self::get_rate_classes( true );
1284
+    public static function get_class_desc($rate_class) {        
1285
+        $rate_classes = self::get_rate_classes(true);
1286 1286
 
1287
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1287
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1288 1288
             return $rate_classes[$rate_class]['desc'];
1289 1289
         }
1290 1290
         
@@ -1300,106 +1300,106 @@  discard block
 block discarded – undo
1300 1300
             'increased'     => 'Increased'
1301 1301
         );
1302 1302
         
1303
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1303
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1304 1304
     }
1305 1305
 
1306 1306
     public static function get_rules() {
1307 1307
         $vat_rules = array(
1308
-            'digital' => __( 'Digital Product', 'invoicing' ),
1309
-            'physical' => __( 'Physical Product', 'invoicing' )
1308
+            'digital' => __('Digital Product', 'invoicing'),
1309
+            'physical' => __('Physical Product', 'invoicing')
1310 1310
         );
1311
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1311
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1312 1312
     }
1313 1313
 
1314
-    public static function get_vat_rates( $class ) {
1315
-        if ( $class === '_standard' ) {
1314
+    public static function get_vat_rates($class) {
1315
+        if ($class === '_standard') {
1316 1316
             return wpinv_get_tax_rates();
1317 1317
         }
1318 1318
 
1319 1319
         $rates = self::get_non_standard_rates();
1320 1320
 
1321
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1321
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1322 1322
     }
1323 1323
 
1324 1324
     public static function get_non_standard_rates() {
1325
-        $option = get_option( 'wpinv_vat_rates', array());
1326
-        return is_array( $option ) ? $option : array();
1325
+        $option = get_option('wpinv_vat_rates', array());
1326
+        return is_array($option) ? $option : array();
1327 1327
     }
1328 1328
     
1329 1329
     public static function allow_vat_rules() {
1330
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1330
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1331 1331
     }
1332 1332
     
1333 1333
     public static function allow_vat_classes() {
1334 1334
         return false; // TODO
1335
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1335
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1336 1336
     }
1337 1337
     
1338
-    public static function get_item_class( $postID ) {
1339
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1338
+    public static function get_item_class($postID) {
1339
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1340 1340
 
1341
-        if ( empty( $class ) ) {
1341
+        if (empty($class)) {
1342 1342
             $class = '_standard';
1343 1343
         }
1344 1344
         
1345
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1345
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1346 1346
     }
1347 1347
     
1348
-    public static function item_class_label( $postID ) {        
1348
+    public static function item_class_label($postID) {        
1349 1349
         $vat_classes = self::get_all_classes();
1350 1350
         
1351
-        $class = self::get_item_class( $postID );
1352
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1351
+        $class = self::get_item_class($postID);
1352
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1353 1353
         
1354
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1354
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1355 1355
     }
1356 1356
     
1357
-    public static function get_item_rule( $postID ) {        
1358
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1357
+    public static function get_item_rule($postID) {        
1358
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1359 1359
         
1360
-        if ( empty( $rule_type ) ) {        
1360
+        if (empty($rule_type)) {        
1361 1361
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1362 1362
         }
1363 1363
         
1364
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1364
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1365 1365
     }
1366 1366
     
1367
-    public static function item_rule_label( $postID ) {
1367
+    public static function item_rule_label($postID) {
1368 1368
         $vat_rules  = self::get_rules();
1369
-        $vat_rule   = self::get_item_rule( $postID );
1370
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1369
+        $vat_rule   = self::get_item_rule($postID);
1370
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1371 1371
         
1372
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1372
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1373 1373
     }
1374 1374
     
1375
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1376
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1375
+    public static function item_has_digital_rule($item_id = 0) {        
1376
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1377 1377
     }
1378 1378
     
1379
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1380
-        if ( !self::allow_vat_rules() ) {
1379
+    public static function invoice_has_digital_rule($invoice = 0) {        
1380
+        if (!self::allow_vat_rules()) {
1381 1381
             return false;
1382 1382
         }
1383 1383
         
1384
-        if ( empty( $invoice ) ) {
1384
+        if (empty($invoice)) {
1385 1385
             return true;
1386 1386
         }
1387 1387
         
1388
-        if ( is_int( $invoice ) ) {
1389
-            $invoice = new WPInv_Invoice( $invoice );
1388
+        if (is_int($invoice)) {
1389
+            $invoice = new WPInv_Invoice($invoice);
1390 1390
         }
1391 1391
         
1392
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1392
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1393 1393
             return true;
1394 1394
         }
1395 1395
         
1396
-        $cart_items  = $invoice->get_cart_details();
1396
+        $cart_items = $invoice->get_cart_details();
1397 1397
         
1398
-        if ( !empty( $cart_items ) ) {
1398
+        if (!empty($cart_items)) {
1399 1399
             $has_digital_rule = false;
1400 1400
             
1401
-            foreach ( $cart_items as $key => $item ) {
1402
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1401
+            foreach ($cart_items as $key => $item) {
1402
+                if (self::item_has_digital_rule($item['id'])) {
1403 1403
                     $has_digital_rule = true;
1404 1404
                     break;
1405 1405
                 }
@@ -1411,67 +1411,67 @@  discard block
 block discarded – undo
1411 1411
         return $has_digital_rule;
1412 1412
     }
1413 1413
     
1414
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1415
-        if ( !wpinv_use_taxes() ) {
1414
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1415
+        if (!wpinv_use_taxes()) {
1416 1416
             return false;
1417 1417
         }
1418 1418
         
1419 1419
         $is_taxable = true;
1420 1420
 
1421
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1421
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1422 1422
             $is_taxable = false;
1423 1423
         }
1424 1424
         
1425
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1425
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1426 1426
     }
1427 1427
     
1428
-    public static function find_rate( $country, $state, $rate, $class ) {
1428
+    public static function find_rate($country, $state, $rate, $class) {
1429 1429
         global $wpi_zero_tax;
1430 1430
 
1431
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1431
+        if ($class === '_exempt' || $wpi_zero_tax) {
1432 1432
             return 0;
1433 1433
         }
1434 1434
 
1435
-        $tax_rates   = wpinv_get_tax_rates();
1435
+        $tax_rates = wpinv_get_tax_rates();
1436 1436
         
1437
-        if ( $class !== '_standard' ) {
1438
-            $class_rates = self::get_vat_rates( $class );
1437
+        if ($class !== '_standard') {
1438
+            $class_rates = self::get_vat_rates($class);
1439 1439
             
1440
-            if ( is_array( $class_rates ) ) {
1440
+            if (is_array($class_rates)) {
1441 1441
                 $indexed_class_rates = array();
1442 1442
                 
1443
-                foreach ( $class_rates as $key => $cr ) {
1443
+                foreach ($class_rates as $key => $cr) {
1444 1444
                     $indexed_class_rates[$cr['country']] = $cr;
1445 1445
                 }
1446 1446
 
1447
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1447
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1448 1448
                     $tr_country = $tr['country'];
1449
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1449
+                    if (!isset($indexed_class_rates[$tr_country])) {
1450 1450
                         return $tr;
1451 1451
                     }
1452 1452
                     $icr = $indexed_class_rates[$tr_country];
1453
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1453
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1454 1454
 
1455
-                }, $tax_rates, $class_rates );
1455
+                }, $tax_rates, $class_rates);
1456 1456
             }
1457 1457
         }
1458 1458
 
1459
-        if ( !empty( $tax_rates ) ) {
1460
-            foreach ( $tax_rates as $key => $tax_rate ) {
1461
-                if ( $country != $tax_rate['country'] )
1459
+        if (!empty($tax_rates)) {
1460
+            foreach ($tax_rates as $key => $tax_rate) {
1461
+                if ($country != $tax_rate['country'])
1462 1462
                     continue;
1463 1463
 
1464
-                if ( !empty( $tax_rate['global'] ) ) {
1465
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1466
-                        $rate = number_format( $tax_rate['rate'], 4 );
1464
+                if (!empty($tax_rate['global'])) {
1465
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1466
+                        $rate = number_format($tax_rate['rate'], 4);
1467 1467
                     }
1468 1468
                 } else {
1469
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1469
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1470 1470
                         continue;
1471 1471
 
1472 1472
                     $state_rate = $tax_rate['rate'];
1473
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1474
-                        $rate = number_format( $state_rate, 4 );
1473
+                    if (0 !== $state_rate || !empty($state_rate)) {
1474
+                        $rate = number_format($state_rate, 4);
1475 1475
                     }
1476 1476
                 }
1477 1477
             }
@@ -1480,84 +1480,84 @@  discard block
 block discarded – undo
1480 1480
         return $rate;
1481 1481
     }
1482 1482
     
1483
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1483
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1484 1484
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1485 1485
         
1486 1486
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1487 1487
         $allow_vat_classes = self::allow_vat_classes();
1488
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1488
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1489 1489
 
1490
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1490
+        if ($class === '_exempt' || $wpi_zero_tax) {
1491 1491
             return 0;
1492
-        } else if ( !$allow_vat_classes ) {
1492
+        } else if (!$allow_vat_classes) {
1493 1493
             $class = '_standard';
1494 1494
         }
1495 1495
 
1496
-        if( !empty( $_POST['wpinv_country'] ) ) {
1496
+        if (!empty($_POST['wpinv_country'])) {
1497 1497
             $post_country = $_POST['wpinv_country'];
1498
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1498
+        } elseif (!empty($_POST['wpinv_country'])) {
1499 1499
             $post_country = $_POST['wpinv_country'];
1500
-        } elseif( !empty( $_POST['country'] ) ) {
1500
+        } elseif (!empty($_POST['country'])) {
1501 1501
             $post_country = $_POST['country'];
1502 1502
         } else {
1503 1503
             $post_country = '';
1504 1504
         }
1505 1505
 
1506
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1507
-        $base_country   = wpinv_is_base_country( $country );
1506
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1507
+        $base_country   = wpinv_is_base_country($country);
1508 1508
         
1509
-        $requires_vat   = self::requires_vat( 0, false );
1510
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1511
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1509
+        $requires_vat   = self::requires_vat(0, false);
1510
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1511
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1512 1512
           
1513
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1513
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1514 1514
             $rate = 0;
1515
-        } else if ( $requires_vat ) {
1516
-            $vat_number = self::get_user_vat_number( '', 0, true );
1515
+        } else if ($requires_vat) {
1516
+            $vat_number = self::get_user_vat_number('', 0, true);
1517 1517
             $vat_info   = self::current_vat_data();
1518 1518
             
1519
-            if ( is_array( $vat_info ) ) {
1520
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1519
+            if (is_array($vat_info)) {
1520
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1521 1521
             }
1522 1522
             
1523
-            if ( $country == 'UK' ) {
1523
+            if ($country == 'UK') {
1524 1524
                 $country = 'GB';
1525 1525
             }
1526 1526
 
1527
-            if ( !empty( $vat_number ) ) {
1527
+            if (!empty($vat_number)) {
1528 1528
                 $rate = 0;
1529 1529
             } else {
1530
-                $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
1530
+                $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
1531 1531
             }
1532 1532
 
1533
-            if ( empty( $vat_number ) && !$is_digital ) {
1534
-                if ( $base_country ) {
1535
-                    $rate = self::find_rate( $country, null, $rate, $class );
1533
+            if (empty($vat_number) && !$is_digital) {
1534
+                if ($base_country) {
1535
+                    $rate = self::find_rate($country, null, $rate, $class);
1536 1536
                 } else {
1537
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1537
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1538 1538
                         $rate = $wpinv_options['eu_fallback_rate'];
1539
-                    } else if( !empty( $country ) ) {
1540
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1539
+                    } else if (!empty($country)) {
1540
+                        $rate = self::find_rate($country, $state, $rate, $class);
1541 1541
                     }
1542 1542
                 }
1543
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1544
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1543
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1544
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1545 1545
                     $rate = $wpinv_options['eu_fallback_rate'];
1546
-                } else if( !empty( $country ) ) {
1547
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1546
+                } else if (!empty($country)) {
1547
+                    $rate = self::find_rate($country, $state, $rate, $class);
1548 1548
                 }
1549 1549
             }
1550 1550
         } else {
1551
-            if ( $is_digital ) {
1551
+            if ($is_digital) {
1552 1552
                 $ip_country_code = self::get_country_by_ip();
1553 1553
                 
1554
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1555
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1554
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1555
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1556 1556
                 } else {
1557
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1557
+                    $rate = self::find_rate($country, $state, $rate, $class);
1558 1558
                 }
1559 1559
             } else {
1560
-                $rate = self::find_rate( $country, $state, $rate, $class );
1560
+                $rate = self::find_rate($country, $state, $rate, $class);
1561 1561
             }
1562 1562
         }
1563 1563
 
@@ -1567,48 +1567,48 @@  discard block
 block discarded – undo
1567 1567
     public static function current_vat_data() {
1568 1568
         global $wpi_session;
1569 1569
         
1570
-        return $wpi_session->get( 'user_vat_data' );
1570
+        return $wpi_session->get('user_vat_data');
1571 1571
     }
1572 1572
     
1573
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1574
-        $user_address = wpinv_get_user_address( $user_id, false );
1573
+    public static function get_user_country($country = '', $user_id = 0) {
1574
+        $user_address = wpinv_get_user_address($user_id, false);
1575 1575
         
1576
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1576
+        if (wpinv_get_option('vat_ip_country_default')) {
1577 1577
             $country = '';
1578 1578
         }
1579 1579
         
1580
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1581
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1580
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1581
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1582 1582
 
1583
-        if ( empty( $result ) ) {
1583
+        if (empty($result)) {
1584 1584
             $result = self::get_country_by_ip();
1585 1585
         }
1586 1586
 
1587 1587
         return $result;
1588 1588
     }
1589 1589
     
1590
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1590
+    public static function set_user_country($country = '', $user_id = 0) {
1591 1591
         global $wpi_userID;
1592 1592
         
1593
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1593
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1594 1594
             $country = wpinv_get_default_country();
1595 1595
         }
1596 1596
         
1597 1597
         return $country;
1598 1598
     }
1599 1599
     
1600
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1600
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1601 1601
         global $wpi_current_id, $wpi_userID;
1602 1602
         
1603
-        if ( !empty( $_POST['new_user'] ) ) {
1603
+        if (!empty($_POST['new_user'])) {
1604 1604
             return '';
1605 1605
         }
1606 1606
         
1607
-        if ( empty( $user_id ) ) {
1608
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1607
+        if (empty($user_id)) {
1608
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1609 1609
         }
1610 1610
 
1611
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1611
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1612 1612
         
1613 1613
         /* TODO
1614 1614
         if ( $is_valid && $vat_number ) {
@@ -1619,38 +1619,38 @@  discard block
 block discarded – undo
1619 1619
         }
1620 1620
         */
1621 1621
 
1622
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1622
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1623 1623
     }
1624 1624
     
1625
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1625
+    public static function get_user_company($company = '', $user_id = 0) {
1626 1626
         global $wpi_current_id, $wpi_userID;
1627 1627
         
1628
-        if ( empty( $user_id ) ) {
1629
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1628
+        if (empty($user_id)) {
1629
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1630 1630
         }
1631 1631
 
1632
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1632
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1633 1633
 
1634
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1634
+        return apply_filters('wpinv_user_company', $company, $user_id);
1635 1635
     }
1636 1636
     
1637
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1638
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1637
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1638
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1639 1639
 
1640
-        if ( is_user_logged_in() && $save ) {
1640
+        if (is_user_logged_in() && $save) {
1641 1641
             $user_id = get_current_user_id();
1642 1642
 
1643
-            if ( !empty( $vat_number ) ) {
1644
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1643
+            if (!empty($vat_number)) {
1644
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1645 1645
             } else {
1646
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1646
+                delete_user_meta($user_id, '_wpinv_vat_number');
1647 1647
             }
1648 1648
 
1649
-            if ( !empty( $company ) ) {
1650
-                update_user_meta( $user_id, '_wpinv_company', $company );
1649
+            if (!empty($company)) {
1650
+                update_user_meta($user_id, '_wpinv_company', $company);
1651 1651
             } else {
1652
-                delete_user_meta( $user_id, '_wpinv_company');
1653
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1652
+                delete_user_meta($user_id, '_wpinv_company');
1653
+                delete_user_meta($user_id, '_wpinv_vat_number');
1654 1654
             }
1655 1655
         }
1656 1656
 
@@ -1660,113 +1660,113 @@  discard block
 block discarded – undo
1660 1660
     public static function ajax_vat_validate() {
1661 1661
         global $wpinv_options, $wpi_session;
1662 1662
         
1663
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1663
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1664 1664
         $response               = array();
1665 1665
         $response['success']    = false;
1666 1666
         
1667
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1668
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1669
-            wp_send_json( $response );
1667
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1668
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1669
+            wp_send_json($response);
1670 1670
         }
1671 1671
         
1672
-        $vat_name   = self::get_vat_name();
1672
+        $vat_name = self::get_vat_name();
1673 1673
         
1674
-        if ( $is_checkout ) {
1674
+        if ($is_checkout) {
1675 1675
             $invoice = wpinv_get_invoice_cart();
1676 1676
             
1677
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1677
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1678 1678
                 $vat_info = array();
1679
-                $wpi_session->set( 'user_vat_data', $vat_info );
1679
+                $wpi_session->set('user_vat_data', $vat_info);
1680 1680
 
1681 1681
                 self::save_user_vat_details();
1682 1682
                 
1683 1683
                 $response['success'] = true;
1684
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1685
-                wp_send_json( $response );
1684
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1685
+                wp_send_json($response);
1686 1686
             }
1687 1687
         }
1688 1688
         
1689
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1690
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1689
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1690
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1691 1691
         
1692
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1693
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1694
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1692
+        $vat_info = $wpi_session->get('user_vat_data');
1693
+        if (!is_array($vat_info) || empty($vat_info)) {
1694
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1695 1695
         }
1696 1696
         
1697
-        if ( empty( $vat_number ) ) {
1698
-            if ( $is_checkout ) {
1697
+        if (empty($vat_number)) {
1698
+            if ($is_checkout) {
1699 1699
                 $response['success'] = true;
1700
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1700
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1701 1701
                 
1702
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1702
+                $vat_info = $wpi_session->get('user_vat_data');
1703 1703
                 $vat_info['number'] = "";
1704 1704
                 $vat_info['valid'] = true;
1705 1705
                 
1706
-                self::save_user_vat_details( $company );
1706
+                self::save_user_vat_details($company);
1707 1707
             } else {
1708
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1708
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1709 1709
                 
1710 1710
                 $vat_info['valid'] = false;
1711 1711
             }
1712 1712
 
1713
-            $wpi_session->set( 'user_vat_data', $vat_info );
1714
-            wp_send_json( $response );
1713
+            $wpi_session->set('user_vat_data', $vat_info);
1714
+            wp_send_json($response);
1715 1715
         }
1716 1716
         
1717
-        if ( empty( $company ) ) {
1717
+        if (empty($company)) {
1718 1718
             $vat_info['valid'] = false;
1719
-            $wpi_session->set( 'user_vat_data', $vat_info );
1719
+            $wpi_session->set('user_vat_data', $vat_info);
1720 1720
             
1721
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1722
-            wp_send_json( $response );
1721
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1722
+            wp_send_json($response);
1723 1723
         }
1724 1724
         
1725
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1726
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1725
+        if (!empty($wpinv_options['vat_vies_check'])) {
1726
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1727 1727
                 $vat_info['valid'] = false;
1728
-                $wpi_session->set( 'user_vat_data', $vat_info );
1728
+                $wpi_session->set('user_vat_data', $vat_info);
1729 1729
                 
1730
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1731
-                wp_send_json( $response );
1730
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1731
+                wp_send_json($response);
1732 1732
             }
1733 1733
             
1734 1734
             $response['success'] = true;
1735
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1735
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1736 1736
         } else {
1737
-            $result = self::check_vat( $vat_number );
1737
+            $result = self::check_vat($vat_number);
1738 1738
             
1739
-            if ( empty( $result['valid'] ) ) {
1739
+            if (empty($result['valid'])) {
1740 1740
                 $response['error'] = $result['message'];
1741
-                wp_send_json( $response );
1741
+                wp_send_json($response);
1742 1742
             }
1743 1743
             
1744
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1745
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1744
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1745
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1746 1746
             
1747
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1747
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1748 1748
 
1749
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1749
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1750 1750
                 $response['success'] = true;
1751
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1751
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1752 1752
             } else {           
1753 1753
                 $vat_info['valid'] = false;
1754
-                $wpi_session->set( 'user_vat_data', $vat_info );
1754
+                $wpi_session->set('user_vat_data', $vat_info);
1755 1755
                 
1756 1756
                 $response['success'] = false;
1757
-                $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 );
1758
-                wp_send_json( $response );
1757
+                $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);
1758
+                wp_send_json($response);
1759 1759
             }
1760 1760
         }
1761 1761
         
1762
-        if ( $is_checkout ) {
1763
-            self::save_user_vat_details( $company, $vat_number );
1762
+        if ($is_checkout) {
1763
+            self::save_user_vat_details($company, $vat_number);
1764 1764
 
1765
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1766
-            $wpi_session->set( 'user_vat_data', $vat_info );
1765
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1766
+            $wpi_session->set('user_vat_data', $vat_info);
1767 1767
         }
1768 1768
 
1769
-        wp_send_json( $response );
1769
+        wp_send_json($response);
1770 1770
     }
1771 1771
     
1772 1772
     public static function ajax_vat_reset() {
@@ -1775,161 +1775,161 @@  discard block
 block discarded – undo
1775 1775
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1776 1776
         $vat_number = self::get_user_vat_number();
1777 1777
         
1778
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1779
-        $wpi_session->set( 'user_vat_data', $vat_info );
1778
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1779
+        $wpi_session->set('user_vat_data', $vat_info);
1780 1780
         
1781 1781
         $response                       = array();
1782 1782
         $response['success']            = true;
1783 1783
         $response['data']['company']    = $company;
1784 1784
         $response['data']['number']     = $vat_number;
1785 1785
         
1786
-        wp_send_json( $response );
1786
+        wp_send_json($response);
1787 1787
     }
1788 1788
     
1789
-    public static function checkout_vat_validate( $valid_data, $post ) {
1789
+    public static function checkout_vat_validate($valid_data, $post) {
1790 1790
         global $wpinv_options, $wpi_session;
1791 1791
         
1792
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1792
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1793 1793
         
1794
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1795
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1794
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1795
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1796 1796
             return;
1797 1797
         }
1798 1798
         
1799
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1800
-        $wpi_session->set( 'user_vat_data', null );
1799
+        $vat_saved = $wpi_session->get('user_vat_data');
1800
+        $wpi_session->set('user_vat_data', null);
1801 1801
         
1802 1802
         $invoice        = wpinv_get_invoice_cart();
1803 1803
         $amount         = $invoice->get_total();
1804
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1805
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1804
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1805
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1806 1806
         
1807
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1808
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1809
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1810
-        if ( empty( $country ) ) {
1807
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1808
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1809
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1810
+        if (empty($country)) {
1811 1811
             $country = wpinv_default_billing_country();
1812 1812
         }
1813 1813
         
1814
-        if ( !$is_digital && $no_vat ) {
1814
+        if (!$is_digital && $no_vat) {
1815 1815
             return;
1816 1816
         }
1817 1817
             
1818
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1818
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1819 1819
         
1820 1820
         $ip_country_code    = self::get_country_by_ip();
1821
-        $is_eu_state        = self::is_eu_state( $country );
1822
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1821
+        $is_eu_state        = self::is_eu_state($country);
1822
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1823 1823
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1824 1824
         
1825
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1825
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1826 1826
             $vat_data['adddress_confirmed'] = false;
1827 1827
             
1828
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1829
-                if ( $ip_country_code != $country ) {
1830
-                    wpinv_set_error( 'vat_validation', sprintf( __( 'The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing' ), '<a href="#wpinv_adddress_confirm">', '</a>' ) );
1828
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1829
+                if ($ip_country_code != $country) {
1830
+                    wpinv_set_error('vat_validation', sprintf(__('The country of your current location must be the same as the country of your billing location or you must %s confirm %s the billing address is your home country.', 'invoicing'), '<a href="#wpinv_adddress_confirm">', '</a>'));
1831 1831
                 }
1832 1832
             } else {
1833 1833
                 $vat_data['adddress_confirmed'] = true;
1834 1834
             }
1835 1835
         }
1836 1836
         
1837
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1838
-            if ( $is_eu_state ) {
1839
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing' ), $vat_name ) );
1840
-            } else if ( $is_digital && $is_eu_state_ip ) {
1841
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1837
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1838
+            if ($is_eu_state) {
1839
+                wpinv_set_error('vat_validation', wp_sprintf(__('Please enter and validate your %s number to verify your purchase is by an EU business.', 'invoicing'), $vat_name));
1840
+            } else if ($is_digital && $is_eu_state_ip) {
1841
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1842 1842
             }
1843 1843
         }
1844 1844
         
1845
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1845
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1846 1846
             return;
1847 1847
         }
1848 1848
 
1849
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1850
-            $vat_data['valid']  = $vat_saved['valid'];
1849
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1850
+            $vat_data['valid'] = $vat_saved['valid'];
1851 1851
         }
1852 1852
             
1853
-        if ( $company !== null ) {
1853
+        if ($company !== null) {
1854 1854
             $vat_data['company'] = $company;
1855 1855
         }
1856 1856
 
1857 1857
         $message = '';
1858
-        if ( $vat_number !== null ) {
1858
+        if ($vat_number !== null) {
1859 1859
             $vat_data['number'] = $vat_number;
1860 1860
             
1861
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1862
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1863
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1861
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1862
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1863
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1864 1864
                         $vat_data['valid'] = false;
1865 1865
                     }
1866 1866
                 } else {
1867
-                    $result = self::check_vat( $vat_number );
1867
+                    $result = self::check_vat($vat_number);
1868 1868
                     
1869
-                    if ( !empty( $result['valid'] ) ) {                
1869
+                    if (!empty($result['valid'])) {                
1870 1870
                         $vat_data['valid'] = true;
1871
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1872
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1871
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1872
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1873 1873
                     
1874
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1874
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1875 1875
 
1876
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1876
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1877 1877
                             $vat_data['valid'] = false;
1878 1878
                             
1879
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1879
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1880 1880
                         }
1881 1881
                     } else {
1882
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1882
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1883 1883
                     }
1884 1884
                 }
1885 1885
                 
1886
-                if ( !$vat_data['valid'] ) {
1887
-                    $error = wp_sprintf( __( 'The %s %s number %s you have entered has not been validated', 'invoicing' ), '<a href="#wpi-vat-details">', $vat_name, '</a>' ) . ( $message ? ' ( ' . $message . ' )' : '' );
1888
-                    wpinv_set_error( 'vat_validation', $error );
1886
+                if (!$vat_data['valid']) {
1887
+                    $error = wp_sprintf(__('The %s %s number %s you have entered has not been validated', 'invoicing'), '<a href="#wpi-vat-details">', $vat_name, '</a>') . ($message ? ' ( ' . $message . ' )' : '');
1888
+                    wpinv_set_error('vat_validation', $error);
1889 1889
                 }
1890 1890
             }
1891 1891
         }
1892 1892
 
1893
-        $wpi_session->set( 'user_vat_data', $vat_data );
1893
+        $wpi_session->set('user_vat_data', $vat_data);
1894 1894
     }
1895 1895
     
1896
-    public static function checkout_vat_fields( $billing_details ) {
1896
+    public static function checkout_vat_fields($billing_details) {
1897 1897
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1898 1898
         
1899 1899
         $ip_address         = wpinv_get_ip();
1900 1900
         $ip_country_code    = self::get_country_by_ip();
1901 1901
         
1902
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1902
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1903 1903
         $invoice            = wpinv_get_invoice_cart();
1904
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1904
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1905 1905
         $wpi_country        = $invoice->country;
1906 1906
         
1907
-        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital );
1907
+        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital);
1908 1908
         $wpi_requires_vat   = $requires_vat;
1909 1909
         
1910 1910
         $company            = self::get_user_company();
1911 1911
         $vat_number         = self::get_user_vat_number();
1912 1912
         
1913
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1914
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1913
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1914
+        $vat_info           = $wpi_session->get('user_vat_data');
1915 1915
 
1916
-        if ( is_array( $vat_info ) ) {
1917
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1918
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1919
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1916
+        if (is_array($vat_info)) {
1917
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1918
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1919
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1920 1920
         }
1921 1921
         
1922 1922
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1923 1923
 
1924
-        if ( $ip_country_code == 'UK' ) {
1924
+        if ($ip_country_code == 'UK') {
1925 1925
             $ip_country_code = 'GB';
1926 1926
         }
1927 1927
         
1928
-        if ( $selected_country == 'UK' ) {
1928
+        if ($selected_country == 'UK') {
1929 1929
             $selected_country = 'GB';
1930 1930
         }
1931 1931
         
1932
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1932
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1933 1933
             $requires_vat = false;
1934 1934
         }
1935 1935
 
@@ -1937,52 +1937,52 @@  discard block
 block discarded – undo
1937 1937
         $display_validate_btn   = 'none';
1938 1938
         $display_reset_btn      = 'none';
1939 1939
         
1940
-        if ( !empty( $vat_number ) && $validated ) {
1941
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1940
+        if (!empty($vat_number) && $validated) {
1941
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1942 1942
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1943 1943
             $display_reset_btn      = 'block';
1944 1944
         } else {
1945
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1946
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1945
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1946
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1947 1947
             $display_validate_btn   = 'block';
1948 1948
         }
1949 1949
         
1950
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1950
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1951 1951
         ?>
1952 1952
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1953 1953
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1954
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1954
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1955 1955
                 <div id="wpinv-fields-box" class="panel-body">
1956 1956
                     <p id="wpi_show_vat_note">
1957
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1957
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1958 1958
                     </p>
1959 1959
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1960 1960
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1961
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1961
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1962 1962
                             <?php
1963
-                            echo wpinv_html_text( array(
1963
+                            echo wpinv_html_text(array(
1964 1964
                                     'id'            => 'wpinv_company',
1965 1965
                                     'name'          => 'wpinv_company',
1966 1966
                                     'value'         => $company,
1967 1967
                                     'class'         => 'wpi-input form-control',
1968
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1969
-                                ) );
1968
+                                    'placeholder'   => __('Company name', 'invoicing'),
1969
+                                ));
1970 1970
                             ?>
1971 1971
                         </p>
1972 1972
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1973
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1973
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1974 1974
                             <span id="wpinv_vat_number-wrap">
1975 1975
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1976
-                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr( wp_sprintf( __( '%s number', 'invoicing' ), $tax_label ) );?>" value="<?php esc_attr_e( $vat_number );?>" id="wpinv_vat_number" name="wpinv_vat_number">
1977
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1976
+                                <input type="text" class="wpi-input form-control" placeholder="<?php echo esc_attr(wp_sprintf(__('%s number', 'invoicing'), $tax_label)); ?>" value="<?php esc_attr_e($vat_number); ?>" id="wpinv_vat_number" name="wpinv_vat_number">
1977
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1978 1978
                             </span>
1979 1979
                         </p>
1980 1980
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1981
-                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf( __("Validate %s Number", 'invoicing'), $tax_label ); ?></button>
1982
-                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf( __("Reset %s", 'invoicing'), $tax_label ); ?></button>
1981
+                            <button class="btn btn-success btn-sm wpinv-vat-validate" type="button" id="wpinv_vat_validate" style="display:<?php echo $display_validate_btn; ?>"><?php echo wp_sprintf(__("Validate %s Number", 'invoicing'), $tax_label); ?></button>
1982
+                            <button class="btn btn-danger btn-sm wpinv-vat-reset" type="button" id="wpinv_vat_reset" style="display:<?php echo $display_reset_btn; ?>"><?php echo wp_sprintf(__("Reset %s", 'invoicing'), $tax_label); ?></button>
1983 1983
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1984 1984
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1985
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1985
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1986 1986
                         </p>
1987 1987
                     </div>
1988 1988
                 </div>
@@ -1996,32 +1996,32 @@  discard block
 block discarded – undo
1996 1996
                 </span>
1997 1997
             </div>
1998 1998
         </div>
1999
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
2000
-            $ip_link = '<a title="' . esc_attr( __( 'View more details on map', 'invoicing' ) ) . '" target="_blank" href="' . esc_url( admin_url( 'admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address ) ) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
1999
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
2000
+            $ip_link = '<a title="' . esc_attr(__('View more details on map', 'invoicing')) . '" target="_blank" href="' . esc_url(admin_url('admin-ajax.php?action=wpinv_ip_geolocation&ip=' . $ip_address)) . '" class="wpi-ip-address-link">' . $ip_address . '&nbsp;&nbsp;<i class="fa fa-external-link-square" aria-hidden="true"></i></a>';
2001 2001
         ?>
2002 2002
         <div class="wpi-ip-info clearfix panel panel-info">
2003 2003
             <div id="wpinv-fields-box" class="panel-body">
2004
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
2004
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
2005 2005
             </div>
2006 2006
         </div>
2007 2007
         <?php }
2008 2008
     }
2009 2009
     
2010
-    public static function show_vat_notice( $invoice ) {
2011
-        if ( empty( $invoice ) ) {
2010
+    public static function show_vat_notice($invoice) {
2011
+        if (empty($invoice)) {
2012 2012
             return NULL;
2013 2013
         }
2014 2014
         
2015
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2016
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2017
-        if ( $label || $notice ) {
2015
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2016
+        $notice     = wpinv_get_option('vat_invoice_notice');
2017
+        if ($label || $notice) {
2018 2018
         ?>
2019 2019
         <div class="row wpinv-vat-notice">
2020 2020
             <div class="col-sm-12">
2021
-                <?php if ( $label ) { ?>
2022
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2023
-                <?php } if ( $notice ) { ?>
2024
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2021
+                <?php if ($label) { ?>
2022
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2023
+                <?php } if ($notice) { ?>
2024
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2025 2025
                 <?php } ?>
2026 2026
             </div>
2027 2027
         </div>
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Spacing   +182 added lines, -182 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 class WPInv_Plugin {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Plugin ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Plugin)) {
19 19
             self::$instance = new WPInv_Plugin;
20 20
             self::$instance->includes();
21 21
             self::$instance->actions();
@@ -31,31 +31,31 @@  discard block
 block discarded – undo
31 31
     }
32 32
     
33 33
     public function define_constants() {
34
-        define( 'WPINV_PLUGIN_DIR', plugin_dir_path( WPINV_PLUGIN_FILE ) );
35
-        define( 'WPINV_PLUGIN_URL', plugin_dir_url( WPINV_PLUGIN_FILE ) );
34
+        define('WPINV_PLUGIN_DIR', plugin_dir_path(WPINV_PLUGIN_FILE));
35
+        define('WPINV_PLUGIN_URL', plugin_dir_url(WPINV_PLUGIN_FILE));
36 36
     }
37 37
     
38 38
     private function actions() {
39 39
         /* Internationalize the text strings used. */
40
-        add_action( 'plugins_loaded', array( &$this, 'plugins_loaded' ) );
40
+        add_action('plugins_loaded', array(&$this, 'plugins_loaded'));
41 41
         
42 42
         /* Perform actions on admin initialization. */
43
-        add_action( 'admin_init', array( &$this, 'admin_init') );
44
-        add_action( 'init', array( &$this, 'init' ), 3 );
45
-        add_action( 'init', array( 'WPInv_Shortcodes', 'init' ) );
46
-        add_action( 'init', array( &$this, 'wpinv_actions' ) );
43
+        add_action('admin_init', array(&$this, 'admin_init'));
44
+        add_action('init', array(&$this, 'init'), 3);
45
+        add_action('init', array('WPInv_Shortcodes', 'init'));
46
+        add_action('init', array(&$this, 'wpinv_actions'));
47 47
         
48
-        if ( class_exists( 'BuddyPress' ) ) {
49
-            add_action( 'bp_include', array( &$this, 'bp_invoicing_init' ) );
48
+        if (class_exists('BuddyPress')) {
49
+            add_action('bp_include', array(&$this, 'bp_invoicing_init'));
50 50
         }
51 51
 
52
-        add_action( 'wp_enqueue_scripts', array( &$this, 'enqueue_scripts' ) );
52
+        add_action('wp_enqueue_scripts', array(&$this, 'enqueue_scripts'));
53 53
         
54
-        if ( is_admin() ) {
55
-            add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) );
56
-            add_action( 'admin_body_class', array( &$this, 'admin_body_class' ) );
54
+        if (is_admin()) {
55
+            add_action('admin_enqueue_scripts', array(&$this, 'admin_enqueue_scripts'));
56
+            add_action('admin_body_class', array(&$this, 'admin_body_class'));
57 57
         } else {
58
-            add_filter( 'pre_get_posts', array( &$this, 'pre_get_posts' ) );
58
+            add_filter('pre_get_posts', array(&$this, 'pre_get_posts'));
59 59
         }
60 60
         
61 61
         /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
          *
66 66
          * @param WPInv_Plugin $this. Current WPInv_Plugin instance. Passed by reference.
67 67
          */
68
-        do_action_ref_array( 'wpinv_actions', array( &$this ) );
68
+        do_action_ref_array('wpinv_actions', array(&$this));
69 69
 
70
-        add_action( 'admin_init', array( &$this, 'activation_redirect') );
70
+        add_action('admin_init', array(&$this, 'activation_redirect'));
71 71
     }
72 72
     
73 73
     public function plugins_loaded() {
74 74
         /* Internationalize the text strings used. */
75 75
         $this->load_textdomain();
76 76
 
77
-        do_action( 'wpinv_loaded' );
77
+        do_action('wpinv_loaded');
78 78
     }
79 79
     
80 80
     /**
@@ -82,217 +82,217 @@  discard block
 block discarded – undo
82 82
      *
83 83
      * @since 1.0
84 84
      */
85
-    public function load_textdomain( $locale = NULL ) {
86
-        if ( empty( $locale ) ) {
87
-            $locale = is_admin() && function_exists( 'get_user_locale' ) ? get_user_locale() : get_locale();
85
+    public function load_textdomain($locale = NULL) {
86
+        if (empty($locale)) {
87
+            $locale = is_admin() && function_exists('get_user_locale') ? get_user_locale() : get_locale();
88 88
         }
89 89
 
90
-        $locale = apply_filters( 'plugin_locale', $locale, 'invoicing' );
90
+        $locale = apply_filters('plugin_locale', $locale, 'invoicing');
91 91
         
92
-        unload_textdomain( 'invoicing' );
93
-        load_textdomain( 'invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo' );
94
-        load_plugin_textdomain( 'invoicing', false, WPINV_PLUGIN_DIR . 'languages' );
92
+        unload_textdomain('invoicing');
93
+        load_textdomain('invoicing', WP_LANG_DIR . '/invoicing/invoicing-' . $locale . '.mo');
94
+        load_plugin_textdomain('invoicing', false, WPINV_PLUGIN_DIR . 'languages');
95 95
         
96 96
         /**
97 97
          * Define language constants.
98 98
          */
99
-        require_once( WPINV_PLUGIN_DIR . 'language.php' );
99
+        require_once(WPINV_PLUGIN_DIR . 'language.php');
100 100
     }
101 101
         
102 102
     public function includes() {
103 103
         global $wpinv_options;
104 104
         
105
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php' );
105
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/register-settings.php');
106 106
         $wpinv_options = wpinv_get_settings();
107 107
         
108
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php' );
109
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php' );
110
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php' );
111
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php' );
112
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php' );
113
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php' );
114
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php' );
115
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php' );
116
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php' );
117
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php' );
118
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php' );
119
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php' );
120
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php' );
121
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
122
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php' );
123
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php' );
124
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php' );
125
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php' );
126
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php' );
127
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php' );
128
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php' );
129
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php' );
130
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php' );
131
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php' );
132
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
133
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php' );
134
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php' );
135
-        require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php' );
136
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php' );
137
-        require_once( WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php' );
138
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
139
-        require_once( WPINV_PLUGIN_DIR . 'vendor/autoload.php' );
108
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-post-types.php');
109
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-email-functions.php');
110
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-general-functions.php');
111
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-helper-functions.php');
112
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-tax-functions.php');
113
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-template-functions.php');
114
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-address-functions.php');
115
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-invoice-functions.php');
116
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-item-functions.php');
117
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-discount-functions.php');
118
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-gateway-functions.php');
119
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-payment-functions.php');
120
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-user-functions.php');
121
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php');
122
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-invoice.php');
123
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-item.php');
124
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-notes.php');
125
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-session.php');
126
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-ajax.php');
127
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-api.php');
128
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-reports.php');
129
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-shortcodes.php');
130
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-cache-helper.php');
131
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-db.php');
132
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php');
133
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions-db.php');
134
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-subscriptions.php');
135
+        require_once(WPINV_PLUGIN_DIR . 'includes/wpinv-subscription.php');
136
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-subscriptions-list-table.php');
137
+        require_once(WPINV_PLUGIN_DIR . 'includes/abstract-wpinv-privacy.php');
138
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php');
139
+        require_once(WPINV_PLUGIN_DIR . 'vendor/autoload.php');
140 140
 
141
-        if ( !class_exists( 'WPInv_EUVat' ) ) {
142
-            require_once( WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php' );
141
+        if (!class_exists('WPInv_EUVat')) {
142
+            require_once(WPINV_PLUGIN_DIR . 'includes/libraries/wpinv-euvat/class-wpinv-euvat.php');
143 143
         }
144 144
         
145
-        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
146
-        if ( !empty( $gateways ) ) {
147
-            foreach ( $gateways as $gateway ) {
148
-                if ( $gateway == 'manual' ) {
145
+        $gateways = array_keys(wpinv_get_enabled_payment_gateways());
146
+        if (!empty($gateways)) {
147
+            foreach ($gateways as $gateway) {
148
+                if ($gateway == 'manual') {
149 149
                     continue;
150 150
                 }
151 151
                 
152 152
                 $gateway_file = WPINV_PLUGIN_DIR . 'includes/gateways/' . $gateway . '.php';
153 153
                 
154
-                if ( file_exists( $gateway_file ) ) {
155
-                    require_once( $gateway_file );
154
+                if (file_exists($gateway_file)) {
155
+                    require_once($gateway_file);
156 156
                 }
157 157
             }
158 158
         }
159
-        require_once( WPINV_PLUGIN_DIR . 'includes/gateways/manual.php' );
159
+        require_once(WPINV_PLUGIN_DIR . 'includes/gateways/manual.php');
160 160
         
161
-        if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) {
162
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php' );
163
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php' );
164
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php' );
161
+        if (is_admin() || (defined('WP_CLI') && WP_CLI)) {
162
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-upgrade-functions.php');
163
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/wpinv-admin-functions.php');
164
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-meta-boxes.php');
165 165
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-recurring-admin.php' );
166
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php' );
167
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php' );
168
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php' );
169
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php' );
170
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php' );
171
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php' );
172
-            require_once( WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php' );
166
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-details.php');
167
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-items.php');
168
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-notes.php');
169
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/meta-boxes/class-mb-invoice-address.php');
170
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/admin-pages.php');
171
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-admin-menus.php');
172
+            require_once(WPINV_PLUGIN_DIR . 'includes/admin/class-wpinv-users.php');
173 173
             //require_once( WPINV_PLUGIN_DIR . 'includes/admin/subscriptions.php' );
174 174
             // load the user class only on the users.php page
175 175
             global $pagenow;
176
-            if($pagenow=='users.php'){
176
+            if ($pagenow == 'users.php') {
177 177
                 new WPInv_Admin_Users();
178 178
             }
179 179
         }
180 180
         
181 181
         // include css inliner
182
-        if ( ! class_exists( 'Emogrifier' ) && class_exists( 'DOMDocument' ) ) {
183
-            include_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php' );
182
+        if (!class_exists('Emogrifier') && class_exists('DOMDocument')) {
183
+            include_once(WPINV_PLUGIN_DIR . 'includes/libraries/class-emogrifier.php');
184 184
         }
185 185
         
186
-        require_once( WPINV_PLUGIN_DIR . 'includes/admin/install.php' );
186
+        require_once(WPINV_PLUGIN_DIR . 'includes/admin/install.php');
187 187
     }
188 188
     
189 189
     public function init() {
190 190
     }
191 191
     
192 192
     public function admin_init() {
193
-        if (!(defined( 'DOING_AJAX' ) && DOING_AJAX)) {
193
+        if (!(defined('DOING_AJAX') && DOING_AJAX)) {
194 194
         }
195 195
         
196
-        add_action( 'admin_print_scripts-edit.php', array( &$this, 'admin_print_scripts_edit_php' ) );
196
+        add_action('admin_print_scripts-edit.php', array(&$this, 'admin_print_scripts_edit_php'));
197 197
     }
198 198
 
199 199
     public function activation_redirect() {
200 200
         // Bail if no activation redirect
201
-        if ( !get_transient( '_wpinv_activation_redirect' ) ) {
201
+        if (!get_transient('_wpinv_activation_redirect')) {
202 202
             return;
203 203
         }
204 204
 
205 205
         // Delete the redirect transient
206
-        delete_transient( '_wpinv_activation_redirect' );
206
+        delete_transient('_wpinv_activation_redirect');
207 207
 
208 208
         // Bail if activating from network, or bulk
209
-        if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
209
+        if (is_network_admin() || isset($_GET['activate-multi'])) {
210 210
             return;
211 211
         }
212 212
 
213
-        wp_safe_redirect( admin_url( 'admin.php?page=wpinv-settings&tab=general' ) );
213
+        wp_safe_redirect(admin_url('admin.php?page=wpinv-settings&tab=general'));
214 214
         exit;
215 215
     }
216 216
     
217 217
     public function enqueue_scripts() {
218
-        $suffix       = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
218
+        $suffix = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
219 219
         
220
-        wp_register_style( 'wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION );
221
-        wp_enqueue_style( 'wpinv_front_style' );
220
+        wp_register_style('wpinv_front_style', WPINV_PLUGIN_URL . 'assets/css/invoice-front.css', array(), WPINV_VERSION);
221
+        wp_enqueue_style('wpinv_front_style');
222 222
                
223 223
         // Register scripts
224
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
225
-        wp_register_script( 'wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array( 'jquery' ),  WPINV_VERSION );
224
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
225
+        wp_register_script('wpinv-front-script', WPINV_PLUGIN_URL . 'assets/js/invoice-front.js', array('jquery'), WPINV_VERSION);
226 226
 
227 227
         $localize                         = array();
228
-        $localize['ajax_url']             = admin_url( 'admin-ajax.php' );
229
-        $localize['nonce']                = wp_create_nonce( 'wpinv-nonce' );
228
+        $localize['ajax_url']             = admin_url('admin-ajax.php');
229
+        $localize['nonce']                = wp_create_nonce('wpinv-nonce');
230 230
         $localize['currency_symbol']      = wpinv_currency_symbol();
231 231
         $localize['currency_pos']         = wpinv_currency_position();
232 232
         $localize['thousand_sep']         = wpinv_thousands_separator();
233 233
         $localize['decimal_sep']          = wpinv_decimal_separator();
234 234
         $localize['decimals']             = wpinv_decimals();
235
-        $localize['txtComplete']          = __( 'Complete', 'invoicing' );
235
+        $localize['txtComplete']          = __('Complete', 'invoicing');
236 236
         $localize['UseTaxes']             = wpinv_use_taxes();
237
-        $localize['checkoutNonce']        = wp_create_nonce( 'wpinv_checkout_nonce' );
237
+        $localize['checkoutNonce']        = wp_create_nonce('wpinv_checkout_nonce');
238 238
 
239
-        $localize = apply_filters( 'wpinv_front_js_localize', $localize );
239
+        $localize = apply_filters('wpinv_front_js_localize', $localize);
240 240
         
241
-        wp_enqueue_script( 'jquery-blockui' );
241
+        wp_enqueue_script('jquery-blockui');
242 242
         $autofill_api = wpinv_get_option('address_autofill_api');
243 243
         $autofill_active = wpinv_get_option('address_autofill_active');
244
-        if ( isset( $autofill_active ) && 1 == $autofill_active && !empty( $autofill_api ) && wpinv_is_checkout() ) {
245
-            if ( wp_script_is( 'google-maps-api', 'enqueued' ) ) {
246
-                wp_dequeue_script( 'google-maps-api' );
244
+        if (isset($autofill_active) && 1 == $autofill_active && !empty($autofill_api) && wpinv_is_checkout()) {
245
+            if (wp_script_is('google-maps-api', 'enqueued')) {
246
+                wp_dequeue_script('google-maps-api');
247 247
             }
248
-            wp_enqueue_script( 'google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array( 'jquery' ), '', false );
249
-            wp_enqueue_script( 'google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array( 'jquery', 'google-maps-api' ), '', true );
248
+            wp_enqueue_script('google-maps-api', 'https://maps.googleapis.com/maps/api/js?key=' . $autofill_api . '&libraries=places', array('jquery'), '', false);
249
+            wp_enqueue_script('google-maps-init', WPINV_PLUGIN_URL . 'assets/js/gaaf.js', array('jquery', 'google-maps-api'), '', true);
250 250
         }
251 251
 
252
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
253
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
252
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
253
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
254 254
 
255
-        wp_enqueue_script( 'wpinv-front-script' );
256
-        wp_localize_script( 'wpinv-front-script', 'WPInv', $localize );
255
+        wp_enqueue_script('wpinv-front-script');
256
+        wp_localize_script('wpinv-front-script', 'WPInv', $localize);
257 257
     }
258 258
 
259 259
     public function admin_enqueue_scripts() {
260 260
         global $post, $pagenow;
261 261
         
262 262
         $post_type  = wpinv_admin_post_type();
263
-        $suffix     = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
264
-        $page       = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : '';
263
+        $suffix     = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ? '' : '.min';
264
+        $page       = isset($_GET['page']) ? strtolower($_GET['page']) : '';
265 265
 
266 266
         $jquery_ui_css = false;
267
-        if ( ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount' ) && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) ) {
267
+        if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $post_type == 'wpi_discount') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
268 268
             $jquery_ui_css = true;
269
-        } else if ( $page == 'wpinv-settings' || $page == 'wpinv-reports' ) {
269
+        } else if ($page == 'wpinv-settings' || $page == 'wpinv-reports') {
270 270
             $jquery_ui_css = true;
271 271
         }
272
-        if ( $jquery_ui_css ) {
273
-            wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
274
-            wp_enqueue_style( 'jquery-ui-css' );
272
+        if ($jquery_ui_css) {
273
+            wp_register_style('jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16');
274
+            wp_enqueue_style('jquery-ui-css');
275 275
         }
276 276
 
277
-        wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
278
-        wp_enqueue_style( 'wpinv_meta_box_style' );
277
+        wp_register_style('wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION);
278
+        wp_enqueue_style('wpinv_meta_box_style');
279 279
         
280
-        wp_register_style( 'wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION );
281
-        wp_enqueue_style( 'wpinv_admin_style' );
280
+        wp_register_style('wpinv_admin_style', WPINV_PLUGIN_URL . 'assets/css/admin.css', array(), WPINV_VERSION);
281
+        wp_enqueue_style('wpinv_admin_style');
282 282
 
283
-        $enqueue = ( $post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ( $pagenow == 'post-new.php' || $pagenow == 'post.php' ) );
284
-        if ( $page == 'wpinv-subscriptions' ) {
285
-            wp_enqueue_script( 'jquery-ui-datepicker' );
283
+        $enqueue = ($post_type == 'wpi_discount' || $post_type == 'wpi_invoice' && ($pagenow == 'post-new.php' || $pagenow == 'post.php'));
284
+        if ($page == 'wpinv-subscriptions') {
285
+            wp_enqueue_script('jquery-ui-datepicker');
286 286
         }
287 287
         
288
-        if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
289
-            wp_enqueue_script( 'jquery-ui-datepicker' );
288
+        if ($enqueue_datepicker = apply_filters('wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue)) {
289
+            wp_enqueue_script('jquery-ui-datepicker');
290 290
         }
291 291
 
292
-        wp_enqueue_style( 'wp-color-picker' );
293
-        wp_enqueue_script( 'wp-color-picker' );
292
+        wp_enqueue_style('wp-color-picker');
293
+        wp_enqueue_script('wp-color-picker');
294 294
         
295
-        wp_register_script( 'jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array( 'jquery' ), '2.70', true );
295
+        wp_register_script('jquery-blockui', WPINV_PLUGIN_URL . 'assets/js/jquery.blockUI.min.js', array('jquery'), '2.70', true);
296 296
 
297 297
         if (($post_type == 'wpi_invoice' || $post_type == 'wpi_quote') && ($pagenow == 'post-new.php' || $pagenow == 'post.php')) {
298 298
             $autofill_api = wpinv_get_option('address_autofill_api');
@@ -303,20 +303,20 @@  discard block
 block discarded – undo
303 303
             }
304 304
         }
305 305
 
306
-        wp_enqueue_style( "select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all' );
307
-        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array( 'jquery' ), WPINV_VERSION );
306
+        wp_enqueue_style("select2", WPINV_PLUGIN_URL . 'assets/css/select2/select2.css', array(), WPINV_VERSION, 'all');
307
+        wp_enqueue_script('select2', WPINV_PLUGIN_URL . 'assets/js/select2/select2.full' . $suffix . '.js', array('jquery'), WPINV_VERSION);
308 308
 
309
-        wp_register_script( 'wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery', 'jquery-blockui','jquery-ui-tooltip' ),  WPINV_VERSION );
310
-        wp_enqueue_script( 'wpinv-admin-script' );
309
+        wp_register_script('wpinv-admin-script', WPINV_PLUGIN_URL . 'assets/js/admin.js', array('jquery', 'jquery-blockui', 'jquery-ui-tooltip'), WPINV_VERSION);
310
+        wp_enqueue_script('wpinv-admin-script');
311 311
         
312 312
         $localize                               = array();
313
-        $localize['ajax_url']                   = admin_url( 'admin-ajax.php' );
314
-        $localize['post_ID']                    = isset( $post->ID ) ? $post->ID : '';
315
-        $localize['wpinv_nonce']                = wp_create_nonce( 'wpinv-nonce' );
316
-        $localize['add_invoice_note_nonce']     = wp_create_nonce( 'add-invoice-note' );
317
-        $localize['delete_invoice_note_nonce']  = wp_create_nonce( 'delete-invoice-note' );
318
-        $localize['invoice_item_nonce']         = wp_create_nonce( 'invoice-item' );
319
-        $localize['billing_details_nonce']      = wp_create_nonce( 'get-billing-details' );
313
+        $localize['ajax_url']                   = admin_url('admin-ajax.php');
314
+        $localize['post_ID']                    = isset($post->ID) ? $post->ID : '';
315
+        $localize['wpinv_nonce']                = wp_create_nonce('wpinv-nonce');
316
+        $localize['add_invoice_note_nonce']     = wp_create_nonce('add-invoice-note');
317
+        $localize['delete_invoice_note_nonce']  = wp_create_nonce('delete-invoice-note');
318
+        $localize['invoice_item_nonce']         = wp_create_nonce('invoice-item');
319
+        $localize['billing_details_nonce']      = wp_create_nonce('get-billing-details');
320 320
         $localize['tax']                        = wpinv_tax_amount();
321 321
         $localize['discount']                   = wpinv_discount_amount();
322 322
         $localize['currency_symbol']            = wpinv_currency_symbol();
@@ -324,69 +324,69 @@  discard block
 block discarded – undo
324 324
         $localize['thousand_sep']               = wpinv_thousands_separator();
325 325
         $localize['decimal_sep']                = wpinv_decimal_separator();
326 326
         $localize['decimals']                   = wpinv_decimals();
327
-        $localize['save_invoice']               = __( 'Save Invoice', 'invoicing' );
328
-        $localize['status_publish']             = wpinv_status_nicename( 'publish' );
329
-        $localize['status_pending']             = wpinv_status_nicename( 'wpi-pending' );
330
-        $localize['delete_tax_rate']            = __( 'Are you sure you wish to delete this tax rate?', 'invoicing' );
331
-        $localize['OneItemMin']                 = __( 'Invoice must contain at least one item', 'invoicing' );
332
-        $localize['DeleteInvoiceItem']          = __( 'Are you sure you wish to delete this item?', 'invoicing' );
333
-        $localize['FillBillingDetails']         = __( 'Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing' );
334
-        $localize['confirmCalcTotals']          = __( 'Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing' );
335
-        $localize['AreYouSure']                 = __( 'Are you sure?', 'invoicing' );
336
-        $localize['emptyInvoice']               = __( 'Add at least one item to save invoice!', 'invoicing' );
337
-        $localize['errDeleteItem']              = __( 'This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing' );
338
-        $localize['delete_subscription']        = __( 'Are you sure you want to delete this subscription?', 'invoicing' );
339
-        $localize['action_edit']                = __( 'Edit', 'invoicing' );
340
-        $localize['action_cancel']              = __( 'Cancel', 'invoicing' );
327
+        $localize['save_invoice']               = __('Save Invoice', 'invoicing');
328
+        $localize['status_publish']             = wpinv_status_nicename('publish');
329
+        $localize['status_pending']             = wpinv_status_nicename('wpi-pending');
330
+        $localize['delete_tax_rate']            = __('Are you sure you wish to delete this tax rate?', 'invoicing');
331
+        $localize['OneItemMin']                 = __('Invoice must contain at least one item', 'invoicing');
332
+        $localize['DeleteInvoiceItem']          = __('Are you sure you wish to delete this item?', 'invoicing');
333
+        $localize['FillBillingDetails']         = __('Fill the user\'s billing information? This will remove any currently entered billing information', 'invoicing');
334
+        $localize['confirmCalcTotals']          = __('Recalculate totals? This will recalculate totals based on the user billing country. If no billing country is set it will use the base country.', 'invoicing');
335
+        $localize['AreYouSure']                 = __('Are you sure?', 'invoicing');
336
+        $localize['emptyInvoice']               = __('Add at least one item to save invoice!', 'invoicing');
337
+        $localize['errDeleteItem']              = __('This item is in use! Before delete this item, you need to delete all the invoice(s) using this item.', 'invoicing');
338
+        $localize['delete_subscription']        = __('Are you sure you want to delete this subscription?', 'invoicing');
339
+        $localize['action_edit']                = __('Edit', 'invoicing');
340
+        $localize['action_cancel']              = __('Cancel', 'invoicing');
341 341
 
342
-        $localize = apply_filters( 'wpinv_admin_js_localize', $localize );
342
+        $localize = apply_filters('wpinv_admin_js_localize', $localize);
343 343
 
344
-        wp_localize_script( 'wpinv-admin-script', 'WPInv_Admin', $localize );
344
+        wp_localize_script('wpinv-admin-script', 'WPInv_Admin', $localize);
345 345
 
346
-        if ( $page == 'wpinv-subscriptions' ) {
347
-            wp_register_script( 'wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array( 'wpinv-admin-script' ),  WPINV_VERSION );
348
-            wp_enqueue_script( 'wpinv-sub-admin-script' );
346
+        if ($page == 'wpinv-subscriptions') {
347
+            wp_register_script('wpinv-sub-admin-script', WPINV_PLUGIN_URL . 'assets/js/subscriptions.js', array('wpinv-admin-script'), WPINV_VERSION);
348
+            wp_enqueue_script('wpinv-sub-admin-script');
349 349
         }
350 350
     }
351 351
     
352
-    public function admin_body_class( $classes ) {
352
+    public function admin_body_class($classes) {
353 353
         global $pagenow, $post, $current_screen;
354 354
         
355
-        if ( !empty( $current_screen->post_type ) && ( $current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote' ) ) {
355
+        if (!empty($current_screen->post_type) && ($current_screen->post_type == 'wpi_invoice' || $current_screen->post_type == 'wpi_quote')) {
356 356
             $classes .= ' wpinv-cpt';
357 357
         }
358 358
         
359
-        $page = isset( $_GET['page'] ) ? strtolower( $_GET['page'] ) : false;
359
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
360 360
 
361
-        $add_class = $page && $pagenow == 'admin.php' && strpos( $page, 'wpinv-' ) === 0 ? true : false;
362
-        if ( $add_class ) {
363
-            $classes .= ' wpi-' . wpinv_sanitize_key( $page );
361
+        $add_class = $page && $pagenow == 'admin.php' && strpos($page, 'wpinv-') === 0 ? true : false;
362
+        if ($add_class) {
363
+            $classes .= ' wpi-' . wpinv_sanitize_key($page);
364 364
         }
365 365
         
366 366
         $settings_class = array();
367
-        if ( $page == 'wpinv-settings' ) {
368
-            if ( !empty( $_REQUEST['tab'] ) ) {
369
-                $settings_class[] = sanitize_text_field( $_REQUEST['tab'] );
367
+        if ($page == 'wpinv-settings') {
368
+            if (!empty($_REQUEST['tab'])) {
369
+                $settings_class[] = sanitize_text_field($_REQUEST['tab']);
370 370
             }
371 371
             
372
-            if ( !empty( $_REQUEST['section'] ) ) {
373
-                $settings_class[] = sanitize_text_field( $_REQUEST['section'] );
372
+            if (!empty($_REQUEST['section'])) {
373
+                $settings_class[] = sanitize_text_field($_REQUEST['section']);
374 374
             }
375 375
             
376
-            $settings_class[] = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field( $_REQUEST['wpi_sub'] ) : 'main';
376
+            $settings_class[] = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' ? sanitize_text_field($_REQUEST['wpi_sub']) : 'main';
377 377
         }
378 378
         
379
-        if ( !empty( $settings_class ) ) {
380
-            $classes .= ' wpi-' . wpinv_sanitize_key( implode( $settings_class, '-' ) );
379
+        if (!empty($settings_class)) {
380
+            $classes .= ' wpi-' . wpinv_sanitize_key(implode($settings_class, '-'));
381 381
         }
382 382
         
383 383
         $post_type = wpinv_admin_post_type();
384 384
 
385
-        if ( $post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false ) {
385
+        if ($post_type == 'wpi_invoice' || $post_type == 'wpi_quote' || $add_class !== false) {
386 386
             return $classes .= ' wpinv';
387 387
         }
388 388
         
389
-        if ( $pagenow == 'post.php' && $post_type == 'wpi_item' && !empty( $post ) && !wpinv_item_is_editable( $post ) ) {
389
+        if ($pagenow == 'post.php' && $post_type == 'wpi_item' && !empty($post) && !wpinv_item_is_editable($post)) {
390 390
             $classes .= ' wpi-editable-n';
391 391
         }
392 392
 
@@ -398,20 +398,20 @@  discard block
 block discarded – undo
398 398
     }
399 399
     
400 400
     public function wpinv_actions() {
401
-        if ( isset( $_REQUEST['wpi_action'] ) ) {
402
-            do_action( 'wpinv_' . wpinv_sanitize_key( $_REQUEST['wpi_action'] ), $_REQUEST );
401
+        if (isset($_REQUEST['wpi_action'])) {
402
+            do_action('wpinv_' . wpinv_sanitize_key($_REQUEST['wpi_action']), $_REQUEST);
403 403
         }
404 404
     }
405 405
     
406
-    public function pre_get_posts( $wp_query ) {
407
-        if ( !empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query() ) {
408
-            $wp_query->query_vars['post_status'] = array_keys( wpinv_get_invoice_statuses() );
406
+    public function pre_get_posts($wp_query) {
407
+        if (!empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] == 'wpi_invoice' && is_user_logged_in() && is_single() && $wp_query->is_main_query()) {
408
+            $wp_query->query_vars['post_status'] = array_keys(wpinv_get_invoice_statuses());
409 409
         }
410 410
         
411 411
         return $wp_query;
412 412
     }
413 413
     
414 414
     public function bp_invoicing_init() {
415
-        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
415
+        require_once(WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php');
416 416
     }
417 417
 }
418 418
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/wp-super-duper.php 1 patch
Spacing   +366 added lines, -366 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
6
-if ( ! class_exists( 'WP_Super_Duper' ) ) {
6
+if (!class_exists('WP_Super_Duper')) {
7 7
 
8 8
 
9 9
 	/**
@@ -39,27 +39,27 @@  discard block
 block discarded – undo
39 39
 		/**
40 40
 		 * Take the array options and use them to build.
41 41
 		 */
42
-		public function __construct( $options ) {
42
+		public function __construct($options) {
43 43
 			global $sd_widgets;
44 44
 
45
-			$sd_widgets[ $options['base_id'] ] = array(
45
+			$sd_widgets[$options['base_id']] = array(
46 46
 				'name'       => $options['name'],
47 47
 				'class_name' => $options['class_name']
48 48
 			);
49
-			$this->base_id                     = $options['base_id'];
49
+			$this->base_id = $options['base_id'];
50 50
 			// lets filter the options before we do anything
51
-			$options       = apply_filters( "wp_super_duper_options", $options );
52
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
53
-			$options       = $this->add_name_from_key( $options );
51
+			$options       = apply_filters("wp_super_duper_options", $options);
52
+			$options       = apply_filters("wp_super_duper_options_{$this->base_id}", $options);
53
+			$options       = $this->add_name_from_key($options);
54 54
 			$this->options = $options;
55 55
 
56 56
 			$this->base_id   = $options['base_id'];
57
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
57
+			$this->arguments = isset($options['arguments']) ? $options['arguments'] : array();
58 58
 
59 59
 			// init parent
60
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
60
+			parent::__construct($options['base_id'], $options['name'], $options['widget_ops']);
61 61
 
62
-			if ( isset( $options['class_name'] ) ) {
62
+			if (isset($options['class_name'])) {
63 63
 				// register widget
64 64
 				$this->class_name = $options['class_name'];
65 65
 
@@ -67,47 +67,47 @@  discard block
 block discarded – undo
67 67
 				$this->register_shortcode();
68 68
 
69 69
 				// register block
70
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
70
+				add_action('admin_enqueue_scripts', array($this, 'register_block'));
71 71
 			}
72 72
 
73 73
 			// add the CSS and JS we need ONCE
74 74
 			global $sd_widget_scripts;
75 75
 
76
-			if ( ! $sd_widget_scripts ) {
77
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
78
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
79
-				wp_add_inline_style( 'widgets', $this->widget_css() );
76
+			if (!$sd_widget_scripts) {
77
+				wp_add_inline_script('admin-widgets', $this->widget_js());
78
+				wp_add_inline_script('customize-controls', $this->widget_js());
79
+				wp_add_inline_style('widgets', $this->widget_css());
80 80
 
81 81
 				$sd_widget_scripts = true;
82 82
 
83 83
 				// add shortcode insert button once
84
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
85
-				if ( $this->is_preview() ) {
86
-					add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
84
+				add_action('media_buttons', array($this, 'shortcode_insert_button'));
85
+				if ($this->is_preview()) {
86
+					add_action('wp_footer', array($this, 'shortcode_insert_button_script'));
87 87
 					// this makes the insert button work for elementor
88
-					add_action( 'elementor/editor/after_enqueue_scripts', array(
88
+					add_action('elementor/editor/after_enqueue_scripts', array(
89 89
 						$this,
90 90
 						'shortcode_insert_button_script'
91
-					) ); // for elementor
91
+					)); // for elementor
92 92
 				}
93 93
 				// this makes the insert button work for cornerstone
94
-				add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' ));
94
+				add_action('wp_print_footer_scripts', array(__CLASS__, 'maybe_cornerstone_builder'));
95 95
 
96
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
97
-				add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
96
+				add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings'));
97
+				add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker'));
98 98
 
99 99
 				// add generator text to admin head
100
-				add_action( 'admin_head', array( $this, 'generator' ) );
100
+				add_action('admin_head', array($this, 'generator'));
101 101
 			}
102 102
 
103
-			do_action( 'wp_super_duper_widget_init', $options, $this );
103
+			do_action('wp_super_duper_widget_init', $options, $this);
104 104
 		}
105 105
 
106 106
 		/**
107 107
 		 * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder
108 108
 		 */
109
-		public static function maybe_cornerstone_builder(){
110
-			if(did_action('cornerstone_before_boot_app')){
109
+		public static function maybe_cornerstone_builder() {
110
+			if (did_action('cornerstone_before_boot_app')) {
111 111
 				self::shortcode_insert_button_script();
112 112
 			}
113 113
 		}
@@ -119,12 +119,12 @@  discard block
 block discarded – undo
119 119
 		 *
120 120
 		 * @return string
121 121
 		 */
122
-		public static function get_picker( $editor_id = '' ) {
122
+		public static function get_picker($editor_id = '') {
123 123
 
124 124
 			ob_start();
125
-			if ( isset( $_POST['editor_id'] ) ) {
126
-				$editor_id = esc_attr( $_POST['editor_id'] );
127
-			} elseif ( isset( $_REQUEST['et_fb'] ) ) {
125
+			if (isset($_POST['editor_id'])) {
126
+				$editor_id = esc_attr($_POST['editor_id']);
127
+			} elseif (isset($_REQUEST['et_fb'])) {
128 128
 				$editor_id = 'main_content_content_vb_tiny_mce';
129 129
 			}
130 130
 
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
 
134 134
 			<div class="sd-shortcode-left-wrap">
135 135
 				<?php
136
-				asort( $sd_widgets );
137
-				if ( ! empty( $sd_widgets ) ) {
136
+				asort($sd_widgets);
137
+				if (!empty($sd_widgets)) {
138 138
 					echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
139
-					echo "<option>" . __( 'Select shortcode' ) . "</option>";
140
-					foreach ( $sd_widgets as $shortcode => $class ) {
141
-						echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
139
+					echo "<option>" . __('Select shortcode') . "</option>";
140
+					foreach ($sd_widgets as $shortcode => $class) {
141
+						echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>";
142 142
 					}
143 143
 					echo "</select>";
144 144
 
@@ -151,37 +151,37 @@  discard block
 block discarded – undo
151 151
 			<div class="sd-shortcode-right-wrap">
152 152
 				<textarea id='sd-shortcode-output' disabled></textarea>
153 153
 				<div id='sd-shortcode-output-actions'>
154
-					<?php if ( $editor_id != '' ) { ?>
154
+					<?php if ($editor_id != '') { ?>
155 155
 						<button class="button sd-insert-shortcode-button"
156
-						        onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) {
156
+						        onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) {
157 157
 							        echo "'" . $editor_id . "'";
158
-						        } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
158
+						        } ?>)"><?php _e('Insert shortcode'); ?></button>
159 159
 					<?php } ?>
160 160
 					<button class="button"
161
-					        onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button>
161
+					        onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button>
162 162
 				</div>
163 163
 			</div>
164 164
 			<?php
165 165
 
166 166
 			$html = ob_get_clean();
167 167
 
168
-			if ( wp_doing_ajax() ) {
168
+			if (wp_doing_ajax()) {
169 169
 				echo $html;
170 170
 				$should_die = true;
171 171
 
172 172
 				// some builder get the editor via ajax so we should not die on those ocasions
173 173
 				$dont_die = array(
174
-					'parent_tag',// WP Bakery
174
+					'parent_tag', // WP Bakery
175 175
 					'avia_request' // enfold
176 176
 				);
177 177
 
178
-				foreach ( $dont_die as $request ) {
179
-					if ( isset( $_REQUEST[ $request ] ) ) {
178
+				foreach ($dont_die as $request) {
179
+					if (isset($_REQUEST[$request])) {
180 180
 						$should_die = false;
181 181
 					}
182 182
 				}
183 183
 
184
-				if ( $should_die ) {
184
+				if ($should_die) {
185 185
 					wp_die();
186 186
 				}
187 187
 
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
 		public static function get_widget_settings() {
209 209
 			global $sd_widgets;
210 210
 
211
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
212
-			if ( ! $shortcode ) {
211
+			$shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : '';
212
+			if (!$shortcode) {
213 213
 				wp_die();
214 214
 			}
215
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
216
-			if ( ! $widget_args ) {
215
+			$widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : '';
216
+			if (!$widget_args) {
217 217
 				wp_die();
218 218
 			}
219
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
220
-			if ( ! $class_name ) {
219
+			$class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
220
+			if (!$class_name) {
221 221
 				wp_die();
222 222
 			}
223 223
 
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 			$widget = new $class_name;
226 226
 
227 227
 			ob_start();
228
-			$widget->form( array() );
228
+			$widget->form(array());
229 229
 			$form = ob_get_clean();
230 230
 			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
231 231
 			echo "<style>" . $widget->widget_css() . "</style>";
@@ -243,9 +243,9 @@  discard block
 block discarded – undo
243 243
 		 * @param string $editor_id Optional. Shortcode editor id. Default null.
244 244
 		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
245 245
 		 */
246
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
246
+		public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') {
247 247
 			global $sd_widgets, $shortcode_insert_button_once;
248
-			if ( $shortcode_insert_button_once ) {
248
+			if ($shortcode_insert_button_once) {
249 249
 				return;
250 250
 			}
251 251
 			add_thickbox();
@@ -255,18 +255,18 @@  discard block
 block discarded – undo
255 255
 			 * Cornerstone makes us play dirty tricks :/
256 256
 			 * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed.
257 257
 			 */
258
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
258
+			if (function_exists('cornerstone_plugin_init') && !is_admin()) {
259 259
 				echo '<span id="insert-media-button">';
260 260
 			}
261 261
 
262
-			echo self::shortcode_button( 'this', 'true' );
262
+			echo self::shortcode_button('this', 'true');
263 263
 
264 264
 			// see opening note
265
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
265
+			if (function_exists('cornerstone_plugin_init') && !is_admin()) {
266 266
 				echo '</span>'; // end #insert-media-button
267 267
 			}
268 268
 
269
-			self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
269
+			self::shortcode_insert_button_script($editor_id, $insert_shortcode_function);
270 270
 			$shortcode_insert_button_once = true;
271 271
 		}
272 272
 
@@ -278,12 +278,12 @@  discard block
 block discarded – undo
278 278
 		 *
279 279
 		 * @return mixed
280 280
 		 */
281
-		public static function shortcode_button( $id = '', $search_for_id = '' ) {
281
+		public static function shortcode_button($id = '', $search_for_id = '') {
282 282
 			ob_start();
283 283
 			?>
284 284
 			<span class="sd-lable-shortcode-inserter">
285 285
 				<a onclick="sd_ajax_get_picker(<?php echo $id;
286
-				if ( $search_for_id ) {
286
+				if ($search_for_id) {
287 287
 					echo "," . $search_for_id;
288 288
 				} ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
289 289
 				   class="thickbox button super-duper-content-open" title="Add Shortcode">
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
 			$html = ob_get_clean();
300 300
 
301 301
 			// remove line breaks so we can use it in js
302
-			return preg_replace( "/\r|\n/", "", trim( $html ) );
302
+			return preg_replace("/\r|\n/", "", trim($html));
303 303
 		}
304 304
 
305 305
 		/**
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
 						jQuery($this).data('sd-widget-enabled', true);
358 358
 					}
359 359
 
360
-					var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>';
360
+					var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_so_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button>';
361 361
 					var form = jQuery($this).parents('' + $selector + '');
362 362
 
363 363
 					if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) {
@@ -394,10 +394,10 @@  discard block
 block discarded – undo
394 394
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
395 395
 			 */
396 396
 
397
-			return str_replace( array(
397
+			return str_replace(array(
398 398
 				'<script>',
399 399
 				'</script>'
400
-			), '', $output );
400
+			), '', $output);
401 401
 		}
402 402
 
403 403
 		/**
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 		 * @param string $editor_id
409 409
 		 * @param string $insert_shortcode_function
410 410
 		 */
411
-		public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
411
+		public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') {
412 412
 			?>
413 413
 			<style>
414 414
 				.sd-shortcode-left-wrap {
@@ -528,15 +528,15 @@  discard block
 block discarded – undo
528 528
 				}
529 529
 			</style>
530 530
 			<?php
531
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
531
+			if (class_exists('SiteOrigin_Panels')) {
532 532
 				echo "<script>" . self::siteorigin_js() . "</script>";
533 533
 			}
534 534
 			?>
535 535
 			<script>
536 536
 				<?php
537
-				if(! empty( $insert_shortcode_function )){
537
+				if (!empty($insert_shortcode_function)) {
538 538
 					echo $insert_shortcode_function;
539
-				}else{
539
+				} else {
540 540
 
541 541
 				/**
542 542
 				 * Function for super duper insert shortcode.
@@ -551,9 +551,9 @@  discard block
 block discarded – undo
551 551
 						if (!$editor_id) {
552 552
 
553 553
 							<?php
554
-							if ( isset( $_REQUEST['et_fb'] ) ) {
554
+							if (isset($_REQUEST['et_fb'])) {
555 555
 								echo '$editor_id = "#main_content_content_vb_tiny_mce";';
556
-							} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
556
+							} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') {
557 557
 								echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
558 558
 							} else {
559 559
 								echo '$editor_id = "#wp-content-editor-container textarea";';
@@ -633,11 +633,11 @@  discard block
 block discarded – undo
633 633
 							'shortcode': $short_code,
634 634
 							'attributes': 123,
635 635
 							'post_id': 321,
636
-							'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
636
+							'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
637 637
 						};
638 638
 
639 639
 						if (typeof ajaxurl === 'undefined') {
640
-							var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>";
640
+							var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
641 641
 						}
642 642
 
643 643
 						jQuery.post(ajaxurl, data, function (response) {
@@ -835,11 +835,11 @@  discard block
 block discarded – undo
835 835
 					var data = {
836 836
 						'action': 'super_duper_get_picker',
837 837
 						'editor_id': $id,
838
-						'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>'
838
+						'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>'
839 839
 					};
840 840
 
841 841
 					if (!ajaxurl) {
842
-						var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
842
+						var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
843 843
 					}
844 844
 
845 845
 					jQuery.post(ajaxurl, data, function (response) {
@@ -860,9 +860,9 @@  discard block
 block discarded – undo
860 860
 				 */
861 861
 				function sd_shortcode_button($id) {
862 862
 					if ($id) {
863
-						return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>';
863
+						return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>';
864 864
 					} else {
865
-						return '<?php echo self::shortcode_button();?>';
865
+						return '<?php echo self::shortcode_button(); ?>';
866 866
 					}
867 867
 				}
868 868
 
@@ -904,10 +904,10 @@  discard block
 block discarded – undo
904 904
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
905 905
 			 */
906 906
 
907
-			return str_replace( array(
907
+			return str_replace(array(
908 908
 				'<style>',
909 909
 				'</style>'
910
-			), '', $output );
910
+			), '', $output);
911 911
 		}
912 912
 
913 913
 		/**
@@ -977,7 +977,7 @@  discard block
 block discarded – undo
977 977
 						jQuery($this).data('sd-widget-enabled', true);
978 978
 					}
979 979
 
980
-					var $button = '<button title="<?php _e( 'Advanced Settings' );?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>';
980
+					var $button = '<button title="<?php _e('Advanced Settings'); ?>" class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><span class="dashicons dashicons-admin-settings" style="width: 28px;font-size: 28px;"></span></button>';
981 981
 					var form = jQuery($this).parents('' + $selector + '');
982 982
 
983 983
 					if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) {
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
 					});
1070 1070
 
1071 1071
 				}
1072
-				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
1072
+				<?php do_action('wp_super_duper_widget_js', $this); ?>
1073 1073
 			</script>
1074 1074
 			<?php
1075 1075
 			$output = ob_get_clean();
@@ -1078,10 +1078,10 @@  discard block
 block discarded – undo
1078 1078
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1079 1079
 			 */
1080 1080
 
1081
-			return str_replace( array(
1081
+			return str_replace(array(
1082 1082
 				'<script>',
1083 1083
 				'</script>'
1084
-			), '', $output );
1084
+			), '', $output);
1085 1085
 		}
1086 1086
 
1087 1087
 
@@ -1092,14 +1092,14 @@  discard block
 block discarded – undo
1092 1092
 		 *
1093 1093
 		 * @return mixed
1094 1094
 		 */
1095
-		private function add_name_from_key( $options, $arguments = false ) {
1096
-			if ( ! empty( $options['arguments'] ) ) {
1097
-				foreach ( $options['arguments'] as $key => $val ) {
1098
-					$options['arguments'][ $key ]['name'] = $key;
1095
+		private function add_name_from_key($options, $arguments = false) {
1096
+			if (!empty($options['arguments'])) {
1097
+				foreach ($options['arguments'] as $key => $val) {
1098
+					$options['arguments'][$key]['name'] = $key;
1099 1099
 				}
1100
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1101
-				foreach ( $options as $key => $val ) {
1102
-					$options[ $key ]['name'] = $key;
1100
+			} elseif ($arguments && is_array($options) && !empty($options)) {
1101
+				foreach ($options as $key => $val) {
1102
+					$options[$key]['name'] = $key;
1103 1103
 				}
1104 1104
 			}
1105 1105
 
@@ -1112,8 +1112,8 @@  discard block
 block discarded – undo
1112 1112
 		 * @since 1.0.0
1113 1113
 		 */
1114 1114
 		public function register_shortcode() {
1115
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1116
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
1115
+			add_shortcode($this->base_id, array($this, 'shortcode_output'));
1116
+			add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode'));
1117 1117
 		}
1118 1118
 
1119 1119
 		/**
@@ -1123,33 +1123,33 @@  discard block
 block discarded – undo
1123 1123
 		 */
1124 1124
 		public static function render_shortcode() {
1125 1125
 
1126
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1127
-			if ( ! current_user_can( 'manage_options' ) ) {
1126
+			check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true);
1127
+			if (!current_user_can('manage_options')) {
1128 1128
 				wp_die();
1129 1129
 			}
1130 1130
 
1131 1131
 			// we might need the $post value here so lets set it.
1132
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1133
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
1134
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
1132
+			if (isset($_POST['post_id']) && $_POST['post_id']) {
1133
+				$post_obj = get_post(absint($_POST['post_id']));
1134
+				if (!empty($post_obj) && empty($post)) {
1135 1135
 					global $post;
1136 1136
 					$post = $post_obj;
1137 1137
 				}
1138 1138
 			}
1139 1139
 
1140
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1141
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1142
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1140
+			if (isset($_POST['shortcode']) && $_POST['shortcode']) {
1141
+				$shortcode_name   = sanitize_title_with_dashes($_POST['shortcode']);
1142
+				$attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array();
1143 1143
 				$attributes       = '';
1144
-				if ( ! empty( $attributes_array ) ) {
1145
-					foreach ( $attributes_array as $key => $value ) {
1146
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
1144
+				if (!empty($attributes_array)) {
1145
+					foreach ($attributes_array as $key => $value) {
1146
+						$attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' ";
1147 1147
 					}
1148 1148
 				}
1149 1149
 
1150 1150
 				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1151 1151
 
1152
-				echo do_shortcode( $shortcode );
1152
+				echo do_shortcode($shortcode);
1153 1153
 
1154 1154
 			}
1155 1155
 			wp_die();
@@ -1163,37 +1163,37 @@  discard block
 block discarded – undo
1163 1163
 		 *
1164 1164
 		 * @return string
1165 1165
 		 */
1166
-		public function shortcode_output( $args = array(), $content = '' ) {
1167
-			$args = self::argument_values( $args );
1166
+		public function shortcode_output($args = array(), $content = '') {
1167
+			$args = self::argument_values($args);
1168 1168
 
1169 1169
 			// add extra argument so we know its a output to gutenberg
1170 1170
 			//$args
1171
-			$args = $this->string_to_bool( $args );
1171
+			$args = $this->string_to_bool($args);
1172 1172
 
1173 1173
 
1174
-			$calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1174
+			$calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : '';
1175 1175
 
1176
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
1177
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
1176
+			$calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this);
1177
+			$calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this);
1178 1178
 
1179
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1180
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1179
+			$attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this);
1180
+			$attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this);
1181 1181
 
1182 1182
 			$shortcode_args = array();
1183 1183
 			$output         = '';
1184
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1185
-			$main_content   = $this->output( $args, $shortcode_args, $content );
1186
-			if ( $main_content && ! $no_wrap ) {
1184
+			$no_wrap        = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false;
1185
+			$main_content   = $this->output($args, $shortcode_args, $content);
1186
+			if ($main_content && !$no_wrap) {
1187 1187
 				// wrap the shortcode in a dive with the same class as the widget
1188 1188
 				$output .= '<div class="' . $calss . '" ' . $attrs . '>';
1189
-				if ( ! empty( $args['title'] ) ) {
1189
+				if (!empty($args['title'])) {
1190 1190
 					// if its a shortcode and there is a title try to grab the title wrappers
1191
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1192
-					if ( empty( $instance ) ) {
1191
+					$shortcode_args = array('before_title' => '', 'after_title' => '');
1192
+					if (empty($instance)) {
1193 1193
 						global $wp_registered_sidebars;
1194
-						if ( ! empty( $wp_registered_sidebars ) ) {
1195
-							foreach ( $wp_registered_sidebars as $sidebar ) {
1196
-								if ( ! empty( $sidebar['before_title'] ) ) {
1194
+						if (!empty($wp_registered_sidebars)) {
1195
+							foreach ($wp_registered_sidebars as $sidebar) {
1196
+								if (!empty($sidebar['before_title'])) {
1197 1197
 									$shortcode_args['before_title'] = $sidebar['before_title'];
1198 1198
 									$shortcode_args['after_title']  = $sidebar['after_title'];
1199 1199
 									break;
@@ -1201,17 +1201,17 @@  discard block
 block discarded – undo
1201 1201
 							}
1202 1202
 						}
1203 1203
 					}
1204
-					$output .= $this->output_title( $shortcode_args, $args );
1204
+					$output .= $this->output_title($shortcode_args, $args);
1205 1205
 				}
1206 1206
 				$output .= $main_content;
1207 1207
 				$output .= '</div>';
1208
-			} elseif ( $main_content && $no_wrap ) {
1208
+			} elseif ($main_content && $no_wrap) {
1209 1209
 				$output .= $main_content;
1210 1210
 			}
1211 1211
 
1212 1212
 			// if preview show a placeholder if empty
1213
-			if ( $this->is_preview() && $output == '' ) {
1214
-				$output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" );
1213
+			if ($this->is_preview() && $output == '') {
1214
+				$output = $this->preview_placeholder_text("[{" . $this->base_id . "}]");
1215 1215
 			}
1216 1216
 
1217 1217
 			return $output;
@@ -1224,8 +1224,8 @@  discard block
 block discarded – undo
1224 1224
 		 *
1225 1225
 		 * @return string
1226 1226
 		 */
1227
-		public function preview_placeholder_text( $name = '' ) {
1228
-			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1227
+		public function preview_placeholder_text($name = '') {
1228
+			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>";
1229 1229
 		}
1230 1230
 
1231 1231
 		/**
@@ -1235,13 +1235,13 @@  discard block
 block discarded – undo
1235 1235
 		 *
1236 1236
 		 * @return mixed
1237 1237
 		 */
1238
-		public function string_to_bool( $options ) {
1238
+		public function string_to_bool($options) {
1239 1239
 			// convert bool strings to booleans
1240
-			foreach ( $options as $key => $val ) {
1241
-				if ( $val == 'false' ) {
1242
-					$options[ $key ] = false;
1243
-				} elseif ( $val == 'true' ) {
1244
-					$options[ $key ] = true;
1240
+			foreach ($options as $key => $val) {
1241
+				if ($val == 'false') {
1242
+					$options[$key] = false;
1243
+				} elseif ($val == 'true') {
1244
+					$options[$key] = true;
1245 1245
 				}
1246 1246
 			}
1247 1247
 
@@ -1257,27 +1257,27 @@  discard block
 block discarded – undo
1257 1257
 		 *
1258 1258
 		 * @return array
1259 1259
 		 */
1260
-		public function argument_values( $instance ) {
1260
+		public function argument_values($instance) {
1261 1261
 			$argument_values = array();
1262 1262
 
1263 1263
 			// set widget instance
1264 1264
 			$this->instance = $instance;
1265 1265
 
1266
-			if ( empty( $this->arguments ) ) {
1266
+			if (empty($this->arguments)) {
1267 1267
 				$this->arguments = $this->get_arguments();
1268 1268
 			}
1269 1269
 
1270
-			if ( ! empty( $this->arguments ) ) {
1271
-				foreach ( $this->arguments as $key => $args ) {
1270
+			if (!empty($this->arguments)) {
1271
+				foreach ($this->arguments as $key => $args) {
1272 1272
 					// set the input name from the key
1273 1273
 					$args['name'] = $key;
1274 1274
 					//
1275
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1276
-					if($args['type']=='checkbox' && $argument_values[ $key ] == ''){
1275
+					$argument_values[$key] = isset($instance[$key]) ? $instance[$key] : '';
1276
+					if ($args['type'] == 'checkbox' && $argument_values[$key] == '') {
1277 1277
 						// don't set default for an empty checkbox
1278 1278
 					}
1279
-					elseif ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1280
-						$argument_values[ $key ] = $args['default'];
1279
+					elseif ($argument_values[$key] == '' && isset($args['default'])) {
1280
+						$argument_values[$key] = $args['default'];
1281 1281
 					}
1282 1282
 				}
1283 1283
 			}
@@ -1304,12 +1304,12 @@  discard block
 block discarded – undo
1304 1304
 		 * @return array Get arguments.
1305 1305
 		 */
1306 1306
 		public function get_arguments() {
1307
-			if ( empty( $this->arguments ) ) {
1307
+			if (empty($this->arguments)) {
1308 1308
 				$this->arguments = $this->set_arguments();
1309 1309
 			}
1310 1310
 
1311
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1312
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
1311
+			$this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance);
1312
+			$this->arguments = $this->add_name_from_key($this->arguments, true);
1313 1313
 
1314 1314
 			return $this->arguments;
1315 1315
 		}
@@ -1321,7 +1321,7 @@  discard block
 block discarded – undo
1321 1321
 		 * @param array $widget_args
1322 1322
 		 * @param string $content
1323 1323
 		 */
1324
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
1324
+		public function output($args = array(), $widget_args = array(), $content = '') {
1325 1325
 
1326 1326
 		}
1327 1327
 
@@ -1329,10 +1329,10 @@  discard block
 block discarded – undo
1329 1329
 		 * Add the dynamic block code inline when the wp-block in enqueued.
1330 1330
 		 */
1331 1331
 		public function register_block() {
1332
-			wp_add_inline_script( 'wp-blocks', $this->block() );
1333
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
1332
+			wp_add_inline_script('wp-blocks', $this->block());
1333
+			if (class_exists('SiteOrigin_Panels')) {
1334 1334
 
1335
-				wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1335
+				wp_add_inline_script('wp-blocks', $this->siteorigin_js());
1336 1336
 
1337 1337
 			}
1338 1338
 		}
@@ -1347,13 +1347,13 @@  discard block
 block discarded – undo
1347 1347
 			$show      = false;
1348 1348
 			$arguments = $this->arguments;
1349 1349
 
1350
-			if ( empty( $arguments ) ) {
1350
+			if (empty($arguments)) {
1351 1351
 				$arguments = $this->get_arguments();
1352 1352
 			}
1353 1353
 
1354
-			if ( ! empty( $arguments ) ) {
1355
-				foreach ( $arguments as $argument ) {
1356
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1354
+			if (!empty($arguments)) {
1355
+				foreach ($arguments as $argument) {
1356
+					if (isset($argument['advanced']) && $argument['advanced']) {
1357 1357
 						$show = true;
1358 1358
 					}
1359 1359
 				}
@@ -1405,12 +1405,12 @@  discard block
 block discarded – undo
1405 1405
 					 * @return {?WPBlock}          The block, if it has been successfully
1406 1406
 					 *                             registered; otherwise `undefined`.
1407 1407
 					 */
1408
-					registerBlockType('<?php echo str_replace( "_", "-", sanitize_title_with_dashes( $this->options['textdomain'] ) . '/' . sanitize_title_with_dashes( $this->options['class_name'] ) );  ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block.
1409
-						title: '<?php echo $this->options['name'];?>', // Block title.
1410
-						description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title.
1411
-						icon: '<?php echo isset( $this->options['block-icon'] ) ? esc_attr( $this->options['block-icon'] ) : 'shield-alt';?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
1412
-						category: '<?php echo isset( $this->options['block-category'] ) ? esc_attr( $this->options['block-category'] ) : 'common';?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
1413
-						<?php if ( isset( $this->options['block-keywords'] ) ) {
1408
+					registerBlockType('<?php echo str_replace("_", "-", sanitize_title_with_dashes($this->options['textdomain']) . '/' . sanitize_title_with_dashes($this->options['class_name'])); ?>', { // Block name. Block names must be string that contains a namespace prefix. Example: my-plugin/my-custom-block.
1409
+						title: '<?php echo $this->options['name']; ?>', // Block title.
1410
+						description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title.
1411
+						icon: '<?php echo isset($this->options['block-icon']) ? esc_attr($this->options['block-icon']) : 'shield-alt'; ?>', // Block icon from Dashicons → https://developer.wordpress.org/resource/dashicons/.
1412
+						category: '<?php echo isset($this->options['block-category']) ? esc_attr($this->options['block-category']) : 'common'; ?>', // Block category — Group blocks together based on common traits E.g. common, formatting, layout widgets, embed.
1413
+						<?php if (isset($this->options['block-keywords'])) {
1414 1414
 						echo "keywords : " . $this->options['block-keywords'] . ",";
1415 1415
 					}?>
1416 1416
 
@@ -1420,10 +1420,10 @@  discard block
 block discarded – undo
1420 1420
 
1421 1421
 						$show_alignment = false;
1422 1422
 
1423
-						if ( ! empty( $this->arguments ) ) {
1423
+						if (!empty($this->arguments)) {
1424 1424
 							echo "attributes : {";
1425 1425
 
1426
-							if ( $show_advanced ) {
1426
+							if ($show_advanced) {
1427 1427
 								echo "show_advanced: {";
1428 1428
 								echo "	type: 'boolean',";
1429 1429
 								echo "  default: false,";
@@ -1431,42 +1431,42 @@  discard block
 block discarded – undo
1431 1431
 							}
1432 1432
 
1433 1433
 							// block wrap element
1434
-							if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
1434
+							if (isset($this->options['block-wrap'])) { //@todo we should validate this?
1435 1435
 								echo "block_wrap: {";
1436 1436
 								echo "	type: 'string',";
1437
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
1437
+								echo "  default: '" . esc_attr($this->options['block-wrap']) . "',";
1438 1438
 								echo "},";
1439 1439
 							}
1440 1440
 
1441 1441
 
1442
-							foreach ( $this->arguments as $key => $args ) {
1442
+							foreach ($this->arguments as $key => $args) {
1443 1443
 
1444 1444
 								// set if we should show alignment
1445
-								if ( $key == 'alignment' ) {
1445
+								if ($key == 'alignment') {
1446 1446
 									$show_alignment = true;
1447 1447
 								}
1448 1448
 
1449 1449
 								$extra = '';
1450 1450
 
1451
-								if ( $args['type'] == 'checkbox' ) {
1451
+								if ($args['type'] == 'checkbox') {
1452 1452
 									$type    = 'boolean';
1453
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
1454
-								} elseif ( $args['type'] == 'number' ) {
1453
+									$default = isset($args['default']) && $args['default'] ? 'true' : 'false';
1454
+								} elseif ($args['type'] == 'number') {
1455 1455
 									$type    = 'number';
1456
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1457
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
1456
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1457
+								} elseif ($args['type'] == 'select' && !empty($args['multiple'])) {
1458 1458
 									$type = 'array';
1459
-									if ( is_array( $args['default'] ) ) {
1460
-										$default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
1459
+									if (is_array($args['default'])) {
1460
+										$default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]";
1461 1461
 									} else {
1462
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1462
+										$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1463 1463
 									}
1464
-								} elseif ( $args['type'] == 'multiselect' ) {
1464
+								} elseif ($args['type'] == 'multiselect') {
1465 1465
 									$type    = 'array';
1466
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1466
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1467 1467
 								} else {
1468 1468
 									$type    = 'string';
1469
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1469
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1470 1470
 								}
1471 1471
 								echo $key . " : {";
1472 1472
 								echo "type : '$type',";
@@ -1496,12 +1496,12 @@  discard block
 block discarded – undo
1496 1496
 									is_fetching = true;
1497 1497
 									var data = {
1498 1498
 										'action': 'super_duper_output_shortcode',
1499
-										'shortcode': '<?php echo $this->options['base_id'];?>',
1499
+										'shortcode': '<?php echo $this->options['base_id']; ?>',
1500 1500
 										'attributes': props.attributes,
1501
-										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
1501
+										'post_id': <?php global $post; if (isset($post->ID)) {
1502 1502
 										echo $post->ID;
1503 1503
 									}?>,
1504
-										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
1504
+										'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
1505 1505
 									};
1506 1506
 
1507 1507
 									jQuery.post(ajaxurl, data, function (response) {
@@ -1510,7 +1510,7 @@  discard block
 block discarded – undo
1510 1510
 
1511 1511
 										// if the content is empty then we place some placeholder text
1512 1512
 										if (env == '') {
1513
-											env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>";
1513
+											env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>";
1514 1514
 										}
1515 1515
 
1516 1516
 										props.setAttributes({content: env});
@@ -1529,7 +1529,7 @@  discard block
 block discarded – undo
1529 1529
 
1530 1530
 								el(wp.editor.BlockControls, {key: 'controls'},
1531 1531
 
1532
-									<?php if($show_alignment){?>
1532
+									<?php if ($show_alignment) {?>
1533 1533
 									el(
1534 1534
 										wp.editor.AlignmentToolbar,
1535 1535
 										{
@@ -1547,9 +1547,9 @@  discard block
 block discarded – undo
1547 1547
 
1548 1548
 									<?php
1549 1549
 
1550
-									if(! empty( $this->arguments )){
1550
+									if (!empty($this->arguments)) {
1551 1551
 
1552
-									if ( $show_advanced ) {
1552
+									if ($show_advanced) {
1553 1553
 									?>
1554 1554
 									el(
1555 1555
 										wp.components.ToggleControl,
@@ -1565,76 +1565,76 @@  discard block
 block discarded – undo
1565 1565
 
1566 1566
 									}
1567 1567
 
1568
-									foreach($this->arguments as $key => $args){
1569
-									$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
1568
+									foreach ($this->arguments as $key => $args) {
1569
+									$custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : '';
1570 1570
 									$options = '';
1571 1571
 									$extra = '';
1572 1572
 									$require = '';
1573 1573
 									$onchange = "props.setAttributes({ $key: $key } )";
1574 1574
 									$value = "props.attributes.$key";
1575
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1576
-									if ( in_array( $args['type'], $text_type ) ) {
1575
+									$text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color');
1576
+									if (in_array($args['type'], $text_type)) {
1577 1577
 										$type = 'TextControl';
1578 1578
 										// Save numbers as numbers and not strings
1579
-										if ( $args['type'] == 'number' ) {
1579
+										if ($args['type'] == 'number') {
1580 1580
 											$onchange = "props.setAttributes({ $key: Number($key) } )";
1581 1581
 										}
1582 1582
 									}
1583 1583
 //									elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378
1584 1584
 //										$type = 'ColorPicker';
1585 1585
 //									}
1586
-									elseif ( $args['type'] == 'checkbox' ) {
1586
+									elseif ($args['type'] == 'checkbox') {
1587 1587
 										$type = 'CheckboxControl';
1588 1588
 										$extra .= "checked: props.attributes.$key,";
1589 1589
 										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1590
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1590
+									} elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') {
1591 1591
 										$type = 'SelectControl';
1592
-										if ( ! empty( $args['options'] ) ) {
1592
+										if (!empty($args['options'])) {
1593 1593
 											$options .= "options  : [";
1594
-											foreach ( $args['options'] as $option_val => $option_label ) {
1595
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1594
+											foreach ($args['options'] as $option_val => $option_label) {
1595
+												$options .= "{ value : '" . esc_attr($option_val) . "',     label : '" . esc_attr($option_label) . "'     },";
1596 1596
 											}
1597 1597
 											$options .= "],";
1598 1598
 										}
1599
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1599
+										if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1600 1600
 											$extra .= ' multiple: true, ';
1601 1601
 											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1602 1602
 											//$value = "['edit', 'delete']";
1603 1603
 										}
1604
-									} elseif ( $args['type'] == 'alignment' ) {
1604
+									} elseif ($args['type'] == 'alignment') {
1605 1605
 										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1606 1606
 									} else {
1607
-										continue;// if we have not implemented the control then don't break the JS.
1607
+										continue; // if we have not implemented the control then don't break the JS.
1608 1608
 									}
1609 1609
 
1610 1610
 									// add show only if advanced
1611
-									if ( ! empty( $args['advanced'] ) ) {
1611
+									if (!empty($args['advanced'])) {
1612 1612
 										echo "props.attributes.show_advanced && ";
1613 1613
 									}
1614 1614
 									// add setting require if defined
1615
-									if ( ! empty( $args['element_require'] ) ) {
1616
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1615
+									if (!empty($args['element_require'])) {
1616
+										echo $this->block_props_replace($args['element_require'], true) . " && ";
1617 1617
 									}
1618 1618
 									?>
1619 1619
 									el(
1620
-										wp.components.<?php echo esc_attr( $type );?>,
1620
+										wp.components.<?php echo esc_attr($type); ?>,
1621 1621
 										{
1622
-											label: '<?php echo esc_attr( $args['title'] );?>',
1623
-											help: '<?php if ( isset( $args['desc'] ) ) {
1624
-												echo esc_attr( $args['desc'] );
1622
+											label: '<?php echo esc_attr($args['title']); ?>',
1623
+											help: '<?php if (isset($args['desc'])) {
1624
+												echo esc_attr($args['desc']);
1625 1625
 											}?>',
1626
-											value: <?php echo $value;?>,
1627
-											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1628
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1626
+											value: <?php echo $value; ?>,
1627
+											<?php if ($type == 'TextControl' && $args['type'] != 'text') {
1628
+											echo "type: '" . esc_attr($args['type']) . "',";
1629 1629
 										}?>
1630
-											<?php if ( ! empty( $args['placeholder'] ) ) {
1631
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1630
+											<?php if (!empty($args['placeholder'])) {
1631
+											echo "placeholder: '" . esc_attr($args['placeholder']) . "',";
1632 1632
 										}?>
1633
-											<?php echo $options;?>
1634
-											<?php echo $extra;?>
1635
-											<?php echo $custom_attributes;?>
1636
-											onChange: function ( <?php echo $key;?> ) {
1637
-												<?php echo $onchange;?>
1633
+											<?php echo $options; ?>
1634
+											<?php echo $extra; ?>
1635
+											<?php echo $custom_attributes; ?>
1636
+											onChange: function ( <?php echo $key; ?> ) {
1637
+												<?php echo $onchange; ?>
1638 1638
 											}
1639 1639
 										}
1640 1640
 									),
@@ -1647,9 +1647,9 @@  discard block
 block discarded – undo
1647 1647
 
1648 1648
 								<?php
1649 1649
 								// If the user sets block-output array then build it
1650
-								if ( ! empty( $this->options['block-output'] ) ) {
1651
-								$this->block_element( $this->options['block-output'] );
1652
-							}else{
1650
+								if (!empty($this->options['block-output'])) {
1651
+								$this->block_element($this->options['block-output']);
1652
+							} else {
1653 1653
 								// if no block-output is set then we try and get the shortcode html output via ajax.
1654 1654
 								?>
1655 1655
 								el('div', {
@@ -1673,14 +1673,14 @@  discard block
 block discarded – undo
1673 1673
 							var align = '';
1674 1674
 
1675 1675
 							// build the shortcode.
1676
-							var content = "[<?php echo $this->options['base_id'];?>";
1676
+							var content = "[<?php echo $this->options['base_id']; ?>";
1677 1677
 							<?php
1678 1678
 
1679
-							if(! empty( $this->arguments )){
1680
-							foreach($this->arguments as $key => $args){
1679
+							if (!empty($this->arguments)) {
1680
+							foreach ($this->arguments as $key => $args) {
1681 1681
 							?>
1682
-							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1683
-								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1682
+							if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) {
1683
+								content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' ";
1684 1684
 							}
1685 1685
 							<?php
1686 1686
 							}
@@ -1721,10 +1721,10 @@  discard block
 block discarded – undo
1721 1721
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1722 1722
 			 */
1723 1723
 
1724
-			return str_replace( array(
1724
+			return str_replace(array(
1725 1725
 				'<script>',
1726 1726
 				'</script>'
1727
-			), '', $output );
1727
+			), '', $output);
1728 1728
 		}
1729 1729
 
1730 1730
 		/**
@@ -1736,16 +1736,16 @@  discard block
 block discarded – undo
1736 1736
 		 *
1737 1737
 		 * @return string
1738 1738
 		 */
1739
-		public function array_to_attributes( $custom_attributes, $html = false ) {
1739
+		public function array_to_attributes($custom_attributes, $html = false) {
1740 1740
 			$attributes = '';
1741
-			if ( ! empty( $custom_attributes ) ) {
1741
+			if (!empty($custom_attributes)) {
1742 1742
 
1743
-				if ( $html ) {
1744
-					foreach ( $custom_attributes as $key => $val ) {
1743
+				if ($html) {
1744
+					foreach ($custom_attributes as $key => $val) {
1745 1745
 						$attributes .= " $key='$val' ";
1746 1746
 					}
1747 1747
 				} else {
1748
-					foreach ( $custom_attributes as $key => $val ) {
1748
+					foreach ($custom_attributes as $key => $val) {
1749 1749
 						$attributes .= "'$key': '$val',";
1750 1750
 					}
1751 1751
 				}
@@ -1761,86 +1761,86 @@  discard block
 block discarded – undo
1761 1761
 		 *
1762 1762
 		 * @param $args
1763 1763
 		 */
1764
-		public function block_element( $args ) {
1764
+		public function block_element($args) {
1765 1765
 
1766 1766
 
1767
-			if ( ! empty( $args ) ) {
1768
-				foreach ( $args as $element => $new_args ) {
1767
+			if (!empty($args)) {
1768
+				foreach ($args as $element => $new_args) {
1769 1769
 
1770
-					if ( is_array( $new_args ) ) { // its an element
1770
+					if (is_array($new_args)) { // its an element
1771 1771
 
1772 1772
 
1773
-						if ( isset( $new_args['element'] ) ) {
1773
+						if (isset($new_args['element'])) {
1774 1774
 
1775
-							if ( isset( $new_args['element_require'] ) ) {
1776
-								echo str_replace( array(
1775
+							if (isset($new_args['element_require'])) {
1776
+								echo str_replace(array(
1777 1777
 										"'+",
1778 1778
 										"+'"
1779
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1780
-								unset( $new_args['element_require'] );
1779
+									), '', $this->block_props_replace($new_args['element_require'])) . " &&  ";
1780
+								unset($new_args['element_require']);
1781 1781
 							}
1782 1782
 
1783 1783
 							echo "\n el( '" . $new_args['element'] . "', {";
1784 1784
 
1785 1785
 							// get the attributes
1786
-							foreach ( $new_args as $new_key => $new_value ) {
1786
+							foreach ($new_args as $new_key => $new_value) {
1787 1787
 
1788 1788
 
1789
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1789
+								if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) {
1790 1790
 									// do nothing
1791 1791
 								} else {
1792
-									echo $this->block_element( array( $new_key => $new_value ) );
1792
+									echo $this->block_element(array($new_key => $new_value));
1793 1793
 								}
1794 1794
 							}
1795 1795
 
1796
-							echo "},";// end attributes
1796
+							echo "},"; // end attributes
1797 1797
 
1798 1798
 							// get the content
1799 1799
 							$first_item = 0;
1800
-							foreach ( $new_args as $new_key => $new_value ) {
1801
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1800
+							foreach ($new_args as $new_key => $new_value) {
1801
+								if ($new_key === 'content' || is_array($new_value)) {
1802 1802
 
1803
-									if ( $new_key === 'content' ) {
1804
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1803
+									if ($new_key === 'content') {
1804
+										echo "'" . $this->block_props_replace($new_value) . "'";
1805 1805
 									}
1806 1806
 
1807
-									if ( is_array( $new_value ) ) {
1807
+									if (is_array($new_value)) {
1808 1808
 
1809
-										if ( isset( $new_value['element_require'] ) ) {
1810
-											echo str_replace( array(
1809
+										if (isset($new_value['element_require'])) {
1810
+											echo str_replace(array(
1811 1811
 													"'+",
1812 1812
 													"+'"
1813
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1814
-											unset( $new_value['element_require'] );
1813
+												), '', $this->block_props_replace($new_value['element_require'])) . " &&  ";
1814
+											unset($new_value['element_require']);
1815 1815
 										}
1816 1816
 
1817
-										if ( isset( $new_value['element_repeat'] ) ) {
1817
+										if (isset($new_value['element_repeat'])) {
1818 1818
 											$x = 1;
1819
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1820
-												$this->block_element( array( '' => $new_value ) );
1821
-												$x ++;
1819
+											while ($x <= absint($new_value['element_repeat'])) {
1820
+												$this->block_element(array('' => $new_value));
1821
+												$x++;
1822 1822
 											}
1823 1823
 										} else {
1824
-											$this->block_element( array( '' => $new_value ) );
1824
+											$this->block_element(array('' => $new_value));
1825 1825
 										}
1826 1826
 									}
1827
-									$first_item ++;
1827
+									$first_item++;
1828 1828
 								}
1829 1829
 							}
1830 1830
 
1831
-							echo ")";// end content
1831
+							echo ")"; // end content
1832 1832
 
1833 1833
 							echo ", \n";
1834 1834
 
1835 1835
 						}
1836 1836
 					} else {
1837 1837
 
1838
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1839
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1840
-						} elseif ( $element == 'style' ) {
1841
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1838
+						if (substr($element, 0, 3) === "if_") {
1839
+							echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ",";
1840
+						} elseif ($element == 'style') {
1841
+							echo $element . ": " . $this->block_props_replace($new_args) . ",";
1842 1842
 						} else {
1843
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1843
+							echo $element . ": '" . $this->block_props_replace($new_args) . "',";
1844 1844
 						}
1845 1845
 
1846 1846
 					}
@@ -1855,12 +1855,12 @@  discard block
 block discarded – undo
1855 1855
 		 *
1856 1856
 		 * @return mixed
1857 1857
 		 */
1858
-		public function block_props_replace( $string, $no_wrap = false ) {
1858
+		public function block_props_replace($string, $no_wrap = false) {
1859 1859
 
1860
-			if ( $no_wrap ) {
1861
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1860
+			if ($no_wrap) {
1861
+				$string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string);
1862 1862
 			} else {
1863
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1863
+				$string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string);
1864 1864
 			}
1865 1865
 
1866 1866
 			return $string;
@@ -1872,37 +1872,37 @@  discard block
 block discarded – undo
1872 1872
 		 * @param array $args
1873 1873
 		 * @param array $instance
1874 1874
 		 */
1875
-		public function widget( $args, $instance ) {
1875
+		public function widget($args, $instance) {
1876 1876
 
1877 1877
 			// get the filtered values
1878
-			$argument_values = $this->argument_values( $instance );
1879
-			$argument_values = $this->string_to_bool( $argument_values );
1880
-			$output          = $this->output( $argument_values, $args );
1878
+			$argument_values = $this->argument_values($instance);
1879
+			$argument_values = $this->string_to_bool($argument_values);
1880
+			$output          = $this->output($argument_values, $args);
1881 1881
 
1882
-			if ( $output ) {
1882
+			if ($output) {
1883 1883
 				// Before widget
1884 1884
 				$before_widget = $args['before_widget'];
1885
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1886
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1885
+				$before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this);
1886
+				$before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this);
1887 1887
 
1888 1888
 				// After widget
1889 1889
 				$after_widget = $args['after_widget'];
1890
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1891
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1890
+				$after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this);
1891
+				$after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this);
1892 1892
 
1893 1893
 				echo $before_widget;
1894 1894
 				// elementor strips the widget wrapping div so we check for and add it back if needed
1895
-				if ( $this->is_elementor_widget_output() ) {
1896
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1895
+				if ($this->is_elementor_widget_output()) {
1896
+					echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : '';
1897 1897
 				}
1898
-				echo $this->output_title( $args, $instance );
1898
+				echo $this->output_title($args, $instance);
1899 1899
 				echo $output;
1900
-				if ( $this->is_elementor_widget_output() ) {
1901
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1900
+				if ($this->is_elementor_widget_output()) {
1901
+					echo !empty($this->options['widget_ops']['classname']) ? "</span>" : '';
1902 1902
 				}
1903 1903
 				echo $after_widget;
1904
-			} elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
1905
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1904
+			} elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty
1905
+				$output = $this->preview_placeholder_text("{{" . $this->base_id . "}}");
1906 1906
 				echo $output;
1907 1907
 			}
1908 1908
 		}
@@ -1915,7 +1915,7 @@  discard block
 block discarded – undo
1915 1915
 		 */
1916 1916
 		public function is_elementor_widget_output() {
1917 1917
 			$result = false;
1918
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1918
+			if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') {
1919 1919
 				$result = true;
1920 1920
 			}
1921 1921
 
@@ -1930,7 +1930,7 @@  discard block
 block discarded – undo
1930 1930
 		 */
1931 1931
 		public function is_elementor_preview() {
1932 1932
 			$result = false;
1933
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
1933
+			if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) {
1934 1934
 				$result = true;
1935 1935
 			}
1936 1936
 
@@ -1945,7 +1945,7 @@  discard block
 block discarded – undo
1945 1945
 		 */
1946 1946
 		public function is_divi_preview() {
1947 1947
 			$result = false;
1948
-			if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1948
+			if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) {
1949 1949
 				$result = true;
1950 1950
 			}
1951 1951
 
@@ -1960,7 +1960,7 @@  discard block
 block discarded – undo
1960 1960
 		 */
1961 1961
 		public function is_beaver_preview() {
1962 1962
 			$result = false;
1963
-			if ( isset( $_REQUEST['fl_builder'] ) ) {
1963
+			if (isset($_REQUEST['fl_builder'])) {
1964 1964
 				$result = true;
1965 1965
 			}
1966 1966
 
@@ -1975,7 +1975,7 @@  discard block
 block discarded – undo
1975 1975
 		 */
1976 1976
 		public function is_siteorigin_preview() {
1977 1977
 			$result = false;
1978
-			if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
1978
+			if (!empty($_REQUEST['siteorigin_panels_live_editor'])) {
1979 1979
 				$result = true;
1980 1980
 			}
1981 1981
 
@@ -1990,7 +1990,7 @@  discard block
 block discarded – undo
1990 1990
 		 */
1991 1991
 		public function is_cornerstone_preview() {
1992 1992
 			$result = false;
1993
-			if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
1993
+			if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') {
1994 1994
 				$result = true;
1995 1995
 			}
1996 1996
 
@@ -2005,15 +2005,15 @@  discard block
 block discarded – undo
2005 2005
 		 */
2006 2006
 		public function is_preview() {
2007 2007
 			$preview = false;
2008
-			if ( $this->is_divi_preview() ) {
2008
+			if ($this->is_divi_preview()) {
2009 2009
 				$preview = true;
2010
-			} elseif ( $this->is_elementor_preview() ) {
2010
+			} elseif ($this->is_elementor_preview()) {
2011 2011
 				$preview = true;
2012
-			} elseif ( $this->is_beaver_preview() ) {
2012
+			} elseif ($this->is_beaver_preview()) {
2013 2013
 				$preview = true;
2014
-			} elseif ( $this->is_siteorigin_preview() ) {
2014
+			} elseif ($this->is_siteorigin_preview()) {
2015 2015
 				$preview = true;
2016
-			} elseif ( $this->is_cornerstone_preview() ) {
2016
+			} elseif ($this->is_cornerstone_preview()) {
2017 2017
 				$preview = true;
2018 2018
 			}
2019 2019
 
@@ -2028,11 +2028,11 @@  discard block
 block discarded – undo
2028 2028
 		 *
2029 2029
 		 * @return string
2030 2030
 		 */
2031
-		public function output_title( $args, $instance = array() ) {
2031
+		public function output_title($args, $instance = array()) {
2032 2032
 			$output = '';
2033
-			if ( ! empty( $instance['title'] ) ) {
2033
+			if (!empty($instance['title'])) {
2034 2034
 				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
2035
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2035
+				$title  = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
2036 2036
 				$output = $args['before_title'] . $title . $args['after_title'];
2037 2037
 			}
2038 2038
 
@@ -2044,7 +2044,7 @@  discard block
 block discarded – undo
2044 2044
 		 *
2045 2045
 		 * @param array $instance The widget options.
2046 2046
 		 */
2047
-		public function form( $instance ) {
2047
+		public function form($instance) {
2048 2048
 
2049 2049
 			// set widget instance
2050 2050
 			$this->instance = $instance;
@@ -2052,12 +2052,12 @@  discard block
 block discarded – undo
2052 2052
 			// set it as a SD widget
2053 2053
 			echo $this->widget_advanced_toggle();
2054 2054
 
2055
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
2055
+			echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>";
2056 2056
 			$arguments = $this->get_arguments();
2057 2057
 
2058
-			if ( is_array( $arguments ) ) {
2059
-				foreach ( $arguments as $key => $args ) {
2060
-					$this->widget_inputs( $args, $instance );
2058
+			if (is_array($arguments)) {
2059
+				foreach ($arguments as $key => $args) {
2060
+					$this->widget_inputs($args, $instance);
2061 2061
 				}
2062 2062
 			}
2063 2063
 		}
@@ -2070,7 +2070,7 @@  discard block
 block discarded – undo
2070 2070
 		public function widget_advanced_toggle() {
2071 2071
 
2072 2072
 			$output = '';
2073
-			if ( $this->block_show_advanced() ) {
2073
+			if ($this->block_show_advanced()) {
2074 2074
 				$val = 1;
2075 2075
 			} else {
2076 2076
 				$val = 0;
@@ -2090,14 +2090,14 @@  discard block
 block discarded – undo
2090 2090
 		 *
2091 2091
 		 * @return string $output
2092 2092
 		 */
2093
-		public function convert_element_require( $input ) {
2093
+		public function convert_element_require($input) {
2094 2094
 
2095
-			$input = str_replace( "'", '"', $input );// we only want double quotes
2095
+			$input = str_replace("'", '"', $input); // we only want double quotes
2096 2096
 
2097
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
2097
+			$output = esc_attr(str_replace(array("[%", "%]"), array(
2098 2098
 				"jQuery(form).find('[data-argument=\"",
2099 2099
 				"\"]').find('input,select').val()"
2100
-			), $input ) );
2100
+			), $input));
2101 2101
 
2102 2102
 			return $output;
2103 2103
 		}
@@ -2108,54 +2108,54 @@  discard block
 block discarded – undo
2108 2108
 		 * @param $args
2109 2109
 		 * @param $instance
2110 2110
 		 */
2111
-		public function widget_inputs( $args, $instance ) {
2111
+		public function widget_inputs($args, $instance) {
2112 2112
 
2113 2113
 			$class             = "";
2114 2114
 			$element_require   = "";
2115 2115
 			$custom_attributes = "";
2116 2116
 
2117 2117
 			// get value
2118
-			if ( isset( $instance[ $args['name'] ] ) ) {
2119
-				$value = $instance[ $args['name'] ];
2120
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
2121
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
2118
+			if (isset($instance[$args['name']])) {
2119
+				$value = $instance[$args['name']];
2120
+			} elseif (!isset($instance[$args['name']]) && !empty($args['default'])) {
2121
+				$value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']);
2122 2122
 			} else {
2123 2123
 				$value = '';
2124 2124
 			}
2125 2125
 
2126 2126
 			// get placeholder
2127
-			if ( ! empty( $args['placeholder'] ) ) {
2128
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
2127
+			if (!empty($args['placeholder'])) {
2128
+				$placeholder = "placeholder='" . esc_html($args['placeholder']) . "'";
2129 2129
 			} else {
2130 2130
 				$placeholder = '';
2131 2131
 			}
2132 2132
 
2133 2133
 			// get if advanced
2134
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
2134
+			if (isset($args['advanced']) && $args['advanced']) {
2135 2135
 				$class .= " sd-advanced-setting ";
2136 2136
 			}
2137 2137
 
2138 2138
 			// element_require
2139
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
2139
+			if (isset($args['element_require']) && $args['element_require']) {
2140 2140
 				$element_require = $args['element_require'];
2141 2141
 			}
2142 2142
 
2143 2143
 			// custom_attributes
2144
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
2145
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
2144
+			if (isset($args['custom_attributes']) && $args['custom_attributes']) {
2145
+				$custom_attributes = $this->array_to_attributes($args['custom_attributes'], true);
2146 2146
 			}
2147 2147
 
2148 2148
 			// before wrapper
2149 2149
 			?>
2150
-			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
2151
-			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
2152
-			   data-element_require='<?php if ( $element_require ) {
2153
-				   echo $this->convert_element_require( $element_require );
2150
+			<p class="sd-argument <?php echo esc_attr($class); ?>"
2151
+			   data-argument='<?php echo esc_attr($args['name']); ?>'
2152
+			   data-element_require='<?php if ($element_require) {
2153
+				   echo $this->convert_element_require($element_require);
2154 2154
 			   } ?>'
2155 2155
 			>
2156 2156
 				<?php
2157 2157
 
2158
-				switch ( $args['type'] ) {
2158
+				switch ($args['type']) {
2159 2159
 					//array('text','password','number','email','tel','url','color')
2160 2160
 					case "text":
2161 2161
 					case "password":
@@ -2166,46 +2166,46 @@  discard block
 block discarded – undo
2166 2166
 					case "color":
2167 2167
 						?>
2168 2168
 						<label
2169
-							for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
2169
+							for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label>
2170 2170
 						<input <?php echo $placeholder; ?> class="widefat"
2171 2171
 							<?php echo $custom_attributes; ?>
2172
-							                               id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2173
-							                               name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>"
2174
-							                               type="<?php echo esc_attr( $args['type'] ); ?>"
2175
-							                               value="<?php echo esc_attr( $value ); ?>">
2172
+							                               id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2173
+							                               name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>"
2174
+							                               type="<?php echo esc_attr($args['type']); ?>"
2175
+							                               value="<?php echo esc_attr($value); ?>">
2176 2176
 						<?php
2177 2177
 
2178 2178
 						break;
2179 2179
 					case "select":
2180
-						$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
2181
-						if ( $multiple ) {
2182
-							if ( empty( $value ) ) {
2180
+						$multiple = isset($args['multiple']) && $args['multiple'] ? true : false;
2181
+						if ($multiple) {
2182
+							if (empty($value)) {
2183 2183
 								$value = array();
2184 2184
 							}
2185 2185
 						}
2186 2186
 						?>
2187 2187
 						<label
2188
-							for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
2188
+							for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label>
2189 2189
 						<select <?php echo $placeholder; ?> class="widefat"
2190 2190
 							<?php echo $custom_attributes; ?>
2191
-							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2192
-							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
2193
-							                                if ( $multiple ) {
2191
+							                                id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2192
+							                                name="<?php echo esc_attr($this->get_field_name($args['name']));
2193
+							                                if ($multiple) {
2194 2194
 								                                echo "[]";
2195 2195
 							                                } ?>"
2196
-							<?php if ( $multiple ) {
2196
+							<?php if ($multiple) {
2197 2197
 								echo "multiple";
2198 2198
 							} //@todo not implemented yet due to gutenberg not supporting it
2199 2199
 							?>
2200 2200
 						>
2201 2201
 							<?php
2202 2202
 
2203
-							if ( ! empty( $args['options'] ) ) {
2204
-								foreach ( $args['options'] as $val => $label ) {
2205
-									if ( $multiple ) {
2206
-										$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
2203
+							if (!empty($args['options'])) {
2204
+								foreach ($args['options'] as $val => $label) {
2205
+									if ($multiple) {
2206
+										$selected = in_array($val, $value) ? 'selected="selected"' : '';
2207 2207
 									} else {
2208
-										$selected = selected( $value, $val, false );
2208
+										$selected = selected($value, $val, false);
2209 2209
 									}
2210 2210
 									echo "<option value='$val' " . $selected . ">$label</option>";
2211 2211
 								}
@@ -2217,20 +2217,20 @@  discard block
 block discarded – undo
2217 2217
 					case "checkbox":
2218 2218
 						?>
2219 2219
 						<input <?php echo $placeholder; ?>
2220
-							<?php checked( 1, $value, true ) ?>
2220
+							<?php checked(1, $value, true) ?>
2221 2221
 							<?php echo $custom_attributes; ?>
2222
-							class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2223
-							name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox"
2222
+							class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2223
+							name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox"
2224 2224
 							value="1">
2225 2225
 						<label
2226
-							for="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"><?php echo esc_attr( $args['title'] ); ?><?php echo $this->widget_field_desc( $args ); ?></label>
2226
+							for="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"><?php echo esc_attr($args['title']); ?><?php echo $this->widget_field_desc($args); ?></label>
2227 2227
 						<?php
2228 2228
 						break;
2229 2229
 					case "hidden":
2230 2230
 						?>
2231
-						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2232
-						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
2233
-						       value="<?php echo esc_attr( $value ); ?>">
2231
+						<input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2232
+						       name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden"
2233
+						       value="<?php echo esc_attr($value); ?>">
2234 2234
 						<?php
2235 2235
 						break;
2236 2236
 					default:
@@ -2252,14 +2252,14 @@  discard block
 block discarded – undo
2252 2252
 		 * @return string
2253 2253
 		 * @todo, need to make its own tooltip script
2254 2254
 		 */
2255
-		public function widget_field_desc( $args ) {
2255
+		public function widget_field_desc($args) {
2256 2256
 
2257 2257
 			$description = '';
2258
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
2259
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
2260
-					$description = $this->desc_tip( $args['desc'] );
2258
+			if (isset($args['desc']) && $args['desc']) {
2259
+				if (isset($args['desc_tip']) && $args['desc_tip']) {
2260
+					$description = $this->desc_tip($args['desc']);
2261 2261
 				} else {
2262
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
2262
+					$description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>';
2263 2263
 				}
2264 2264
 			}
2265 2265
 
@@ -2274,11 +2274,11 @@  discard block
 block discarded – undo
2274 2274
 		 *
2275 2275
 		 * @return string
2276 2276
 		 */
2277
-		function desc_tip( $tip, $allow_html = false ) {
2278
-			if ( $allow_html ) {
2279
-				$tip = $this->sanitize_tooltip( $tip );
2277
+		function desc_tip($tip, $allow_html = false) {
2278
+			if ($allow_html) {
2279
+				$tip = $this->sanitize_tooltip($tip);
2280 2280
 			} else {
2281
-				$tip = esc_attr( $tip );
2281
+				$tip = esc_attr($tip);
2282 2282
 			}
2283 2283
 
2284 2284
 			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -2291,8 +2291,8 @@  discard block
 block discarded – undo
2291 2291
 		 *
2292 2292
 		 * @return string
2293 2293
 		 */
2294
-		public function sanitize_tooltip( $var ) {
2295
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
2294
+		public function sanitize_tooltip($var) {
2295
+			return htmlspecialchars(wp_kses(html_entity_decode($var), array(
2296 2296
 				'br'     => array(),
2297 2297
 				'em'     => array(),
2298 2298
 				'strong' => array(),
@@ -2302,7 +2302,7 @@  discard block
 block discarded – undo
2302 2302
 				'li'     => array(),
2303 2303
 				'ol'     => array(),
2304 2304
 				'p'      => array(),
2305
-			) ) );
2305
+			)));
2306 2306
 		}
2307 2307
 
2308 2308
 		/**
@@ -2314,23 +2314,23 @@  discard block
 block discarded – undo
2314 2314
 		 * @return array
2315 2315
 		 * @todo we should add some sanitation here.
2316 2316
 		 */
2317
-		public function update( $new_instance, $old_instance ) {
2317
+		public function update($new_instance, $old_instance) {
2318 2318
 
2319 2319
 			//save the widget
2320
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
2320
+			$instance = array_merge((array)$old_instance, (array)$new_instance);
2321 2321
 
2322 2322
 			// set widget instance
2323 2323
 			$this->instance = $instance;
2324 2324
 
2325
-			if ( empty( $this->arguments ) ) {
2325
+			if (empty($this->arguments)) {
2326 2326
 				$this->get_arguments();
2327 2327
 			}
2328 2328
 
2329 2329
 			// check for checkboxes
2330
-			if ( ! empty( $this->arguments ) ) {
2331
-				foreach ( $this->arguments as $argument ) {
2332
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
2333
-						$instance[ $argument['name'] ] = '0';
2330
+			if (!empty($this->arguments)) {
2331
+				foreach ($this->arguments as $argument) {
2332
+					if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) {
2333
+						$instance[$argument['name']] = '0';
2334 2334
 					}
2335 2335
 				}
2336 2336
 			}
@@ -2348,7 +2348,7 @@  discard block
 block discarded – undo
2348 2348
 		 */
2349 2349
 		public function is_block_content_call() {
2350 2350
 			$result = false;
2351
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
2351
+			if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') {
2352 2352
 				$result = true;
2353 2353
 			}
2354 2354
 
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,245 +7,245 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
83
-            $time_format = get_option( 'time_format' );
84
-            $date_time_format = $date_format . ' '. $time_format;
82
+            $date_format = get_option('date_format');
83
+            $time_format = get_option('time_format');
84
+            $date_time_format = $date_format . ' ' . $time_format;
85 85
             
86 86
             $m_time = $post->post_date;
87
-            $h_time = mysql2date( $date_format, $m_time );
87
+            $h_time = mysql2date($date_format, $m_time);
88 88
             
89
-            $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
89
+            $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
90 90
             break;
91 91
         case 'payment_date' :
92
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
93
-                $date_format = get_option( 'date_format' );
94
-                $time_format = get_option( 'time_format' );
95
-                $date_time_format = $date_format . ' '. $time_format;
92
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
93
+                $date_format = get_option('date_format');
94
+                $time_format = get_option('time_format');
95
+                $date_time_format = $date_format . ' ' . $time_format;
96 96
                 
97 97
                 $m_time = $date_completed;
98
-                $h_time = mysql2date( $date_format, $m_time );
98
+                $h_time = mysql2date($date_format, $m_time);
99 99
                 
100
-                $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
100
+                $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
101 101
             } else {
102 102
                 $value = '-';
103 103
             }
104 104
             break;
105 105
         case 'status' :
106
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
107
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
108
-            if ( 1 == $is_viewed ) {
109
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
106
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
107
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
108
+            if (1 == $is_viewed) {
109
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
110 110
             }
111
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && ( $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ) ) ) {
112
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
111
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && ($gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()))) {
112
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
113 113
             }
114 114
             break;
115 115
         case 'number' :
116
-            $edit_link = get_edit_post_link( $post->ID );
117
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
116
+            $edit_link = get_edit_post_link($post->ID);
117
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
118 118
             break;
119 119
         case 'wpi_actions' :
120 120
             $value = '';
121
-            if ( !empty( $post->post_name ) ) {
122
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121
+            if (!empty($post->post_name)) {
122
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123 123
             }
124 124
             
125
-            if ( $email = $wpi_invoice->get_email() ) {
126
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125
+            if ($email = $wpi_invoice->get_email()) {
126
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127 127
             }
128 128
             
129 129
             break;
130 130
         default:
131
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
131
+            $value = isset($post->$column_name) ? $post->$column_name : '';
132 132
             break;
133 133
 
134 134
     }
135
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
135
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
136 136
     
137
-    if ( $value !== NULL ) {
137
+    if ($value !== NULL) {
138 138
         echo $value;
139 139
     }
140 140
 }
141 141
 
142
-function wpinv_admin_post_id( $id = 0 ) {
142
+function wpinv_admin_post_id($id = 0) {
143 143
     global $post;
144 144
 
145
-    if ( isset( $id ) && ! empty( $id ) ) {
145
+    if (isset($id) && !empty($id)) {
146 146
         return (int)$id;
147
-    } else if ( get_the_ID() ) {
148
-        return (int) get_the_ID();
149
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
150
-        return (int) $post->ID;
151
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
152
-        return (int) $_GET['post'];
153
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
154
-        return (int) $_GET['id'];
155
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
156
-        return (int) $_POST['id'];
147
+    } else if (get_the_ID()) {
148
+        return (int)get_the_ID();
149
+    } else if (isset($post->ID) && !empty($post->ID)) {
150
+        return (int)$post->ID;
151
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
152
+        return (int)$_GET['post'];
153
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
154
+        return (int)$_GET['id'];
155
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
156
+        return (int)$_POST['id'];
157 157
     } 
158 158
 
159 159
     return null;
160 160
 }
161 161
     
162
-function wpinv_admin_post_type( $id = 0 ) {
163
-    if ( !$id ) {
162
+function wpinv_admin_post_type($id = 0) {
163
+    if (!$id) {
164 164
         $id = wpinv_admin_post_id();
165 165
     }
166 166
     
167
-    $type = get_post_type( $id );
167
+    $type = get_post_type($id);
168 168
     
169
-    if ( !$type ) {
170
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
169
+    if (!$type) {
170
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
171 171
     }
172 172
     
173
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
173
+    return apply_filters('wpinv_admin_post_type', $type, $id);
174 174
 }
175 175
 
176 176
 function wpinv_admin_messages() {
177 177
 	global $wpinv_options, $pagenow, $post;
178 178
 
179
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
180
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
179
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
180
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
181 181
 	}
182 182
 
183
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
184
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
183
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
184
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
185 185
 	}
186 186
 
187
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
188
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
187
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
188
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
189 189
 	}
190 190
 
191
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
192
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
191
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
192
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
193 193
 	}
194 194
 
195
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
196
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
195
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
196
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
197 197
 	}
198 198
 
199
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
200
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
199
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
200
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
201 201
 	}
202 202
 
203
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
204
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
203
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
204
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
205 205
 	}
206 206
 
207
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
208
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
207
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
208
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
209 209
     }
210 210
     
211
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
212
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
211
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
212
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
213 213
     }
214 214
 
215
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
216
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
215
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
216
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
217 217
     }
218 218
 
219
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
220
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
219
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
220
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
221 221
 	}
222 222
 
223
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
224
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
223
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
224
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
225 225
 	}
226 226
 
227
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
228
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
227
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
228
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
229 229
 	}
230 230
     
231
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
232
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
231
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
232
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
233 233
 
234
-		if ( !empty( $message ) ) {
235
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
234
+		if (!empty($message)) {
235
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
236 236
 		}
237 237
 	}
238 238
 
239
-	settings_errors( 'wpinv-notices' );
239
+	settings_errors('wpinv-notices');
240 240
 }
241
-add_action( 'admin_notices', 'wpinv_admin_messages' );
241
+add_action('admin_notices', 'wpinv_admin_messages');
242 242
 
243
-add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' );
244
-function wpinv_show_test_payment_gateway_notice(){
245
-    add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' );
243
+add_action('admin_init', 'wpinv_show_test_payment_gateway_notice');
244
+function wpinv_show_test_payment_gateway_notice() {
245
+    add_action('admin_notices', 'wpinv_test_payment_gateway_messages');
246 246
 }
247 247
 
248
-function wpinv_test_payment_gateway_messages(){
248
+function wpinv_test_payment_gateway_messages() {
249 249
     $gateways = wpinv_get_enabled_payment_gateways();
250 250
     $name = array(); $test_gateways = '';
251 251
     if ($gateways) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         }
257 257
         $test_gateways = implode(', ', $name);
258 258
     }
259
-    if(isset($test_gateways) && !empty($test_gateways)){
259
+    if (isset($test_gateways) && !empty($test_gateways)) {
260 260
         $link = admin_url('admin.php?page=wpinv-settings&tab=gateways');
261
-        $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link );
261
+        $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link);
262 262
         ?>
263 263
         <div class="notice notice-warning is-dismissible">
264 264
             <p><?php echo $notice; ?></p>
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
     }
268 268
 }
269 269
 
270
-function wpinv_items_columns( $existing_columns ) {
270
+function wpinv_items_columns($existing_columns) {
271 271
     global $wpinv_euvat;
272 272
     
273 273
     $columns                = array();
274 274
     $columns['cb']          = $existing_columns['cb'];
275
-    $columns['title']       = __( 'Title', 'invoicing' );
276
-    $columns['price']       = __( 'Price', 'invoicing' );
277
-    if ( $wpinv_euvat->allow_vat_rules() ) {
278
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
275
+    $columns['title']       = __('Title', 'invoicing');
276
+    $columns['price']       = __('Price', 'invoicing');
277
+    if ($wpinv_euvat->allow_vat_rules()) {
278
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
279 279
     }
280
-    if ( $wpinv_euvat->allow_vat_classes() ) {
281
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
280
+    if ($wpinv_euvat->allow_vat_classes()) {
281
+        $columns['vat_class']   = __('VAT class', 'invoicing');
282 282
     }
283
-    $columns['type']        = __( 'Type', 'invoicing' );
284
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
285
-    $columns['date']        = __( 'Date', 'invoicing' );
286
-    $columns['id']          = __( 'ID', 'invoicing' );
283
+    $columns['type']        = __('Type', 'invoicing');
284
+    $columns['recurring']   = __('Recurring', 'invoicing');
285
+    $columns['date']        = __('Date', 'invoicing');
286
+    $columns['id']          = __('ID', 'invoicing');
287 287
 
288
-    return apply_filters( 'wpinv_items_columns', $columns );
288
+    return apply_filters('wpinv_items_columns', $columns);
289 289
 }
290
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
290
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
291 291
 
292
-function wpinv_items_sortable_columns( $columns ) {
292
+function wpinv_items_sortable_columns($columns) {
293 293
     $columns['price']       = 'price';
294 294
     $columns['vat_rule']    = 'vat_rule';
295 295
     $columns['vat_class']   = 'vat_class';
@@ -299,151 +299,151 @@  discard block
 block discarded – undo
299 299
 
300 300
     return $columns;
301 301
 }
302
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
302
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
303 303
 
304
-function wpinv_items_table_custom_column( $column ) {
304
+function wpinv_items_table_custom_column($column) {
305 305
     global $wpinv_euvat, $post, $wpi_item;
306 306
     
307
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
308
-        $wpi_item = new WPInv_Item( $post->ID );
307
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
308
+        $wpi_item = new WPInv_Item($post->ID);
309 309
     }
310 310
 
311
-    switch ( $column ) {
311
+    switch ($column) {
312 312
         case 'price' :
313
-            echo wpinv_item_price( $post->ID );
313
+            echo wpinv_item_price($post->ID);
314 314
         break;
315 315
         case 'vat_rule' :
316
-            echo $wpinv_euvat->item_rule_label( $post->ID );
316
+            echo $wpinv_euvat->item_rule_label($post->ID);
317 317
         break;
318 318
         case 'vat_class' :
319
-            echo $wpinv_euvat->item_class_label( $post->ID );
319
+            echo $wpinv_euvat->item_class_label($post->ID);
320 320
         break;
321 321
         case 'type' :
322
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
322
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
323 323
         break;
324 324
         case 'recurring' :
325
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
325
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
326 326
         break;
327 327
         case 'id' :
328 328
            echo $post->ID;
329 329
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
330
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
331
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
332
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
330
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
331
+                    if ($wpinv_euvat->allow_vat_rules()) {
332
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
333 333
                     }
334
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
335
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
334
+                    if ($wpinv_euvat->allow_vat_classes()) {
335
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
336 336
                     }
337
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
337
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
338 338
                 </div>';
339 339
         break;
340 340
     }
341 341
     
342
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
342
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
343 343
 }
344
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
344
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
345 345
 
346 346
 function wpinv_add_items_filters() {
347 347
     global $wpinv_euvat, $typenow;
348 348
 
349 349
     // Checks if the current post type is 'item'
350
-    if ( $typenow == 'wpi_item') {
351
-        if ( $wpinv_euvat->allow_vat_rules() ) {
352
-            echo wpinv_html_select( array(
353
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
350
+    if ($typenow == 'wpi_item') {
351
+        if ($wpinv_euvat->allow_vat_rules()) {
352
+            echo wpinv_html_select(array(
353
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
354 354
                     'name'             => 'vat_rule',
355 355
                     'id'               => 'vat_rule',
356
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
356
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
357 357
                     'show_option_all'  => false,
358 358
                     'show_option_none' => false,
359 359
                     'class'            => 'gdmbx2-text-medium wpi_select2',
360
-                ) );
360
+                ));
361 361
         }
362 362
         
363
-        if ( $wpinv_euvat->allow_vat_classes() ) {
364
-            echo wpinv_html_select( array(
365
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
363
+        if ($wpinv_euvat->allow_vat_classes()) {
364
+            echo wpinv_html_select(array(
365
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
366 366
                     'name'             => 'vat_class',
367 367
                     'id'               => 'vat_class',
368
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
368
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
369 369
                     'show_option_all'  => false,
370 370
                     'show_option_none' => false,
371 371
                     'class'            => 'gdmbx2-text-medium wpi_select2',
372
-                ) );
372
+                ));
373 373
         }
374 374
             
375
-        echo wpinv_html_select( array(
376
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
375
+        echo wpinv_html_select(array(
376
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
377 377
                 'name'             => 'type',
378 378
                 'id'               => 'type',
379
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
379
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
380 380
                 'show_option_all'  => false,
381 381
                 'show_option_none' => false,
382 382
                 'class'            => 'gdmbx2-text-medium',
383
-            ) );
383
+            ));
384 384
 
385
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
385
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
386 386
             echo '<input type="hidden" name="all_posts" value="1" />';
387 387
         }
388 388
     }
389 389
 }
390
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
390
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
391 391
 
392
-function wpinv_send_invoice_after_save( $invoice ) {
393
-    if ( empty( $_POST['wpi_save_send'] ) ) {
392
+function wpinv_send_invoice_after_save($invoice) {
393
+    if (empty($_POST['wpi_save_send'])) {
394 394
         return;
395 395
     }
396 396
     
397
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
398
-        wpinv_user_invoice_notification( $invoice->ID );
397
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
398
+        wpinv_user_invoice_notification($invoice->ID);
399 399
     }
400 400
 }
401
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
401
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
402 402
 
403
-function wpinv_send_register_new_user( $data, $postarr ) {
404
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
405
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
406
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
403
+function wpinv_send_register_new_user($data, $postarr) {
404
+    if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
405
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
406
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
407 407
         
408
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
409
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
410
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
411
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
412
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
413
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
408
+        if ($is_new_user && $email && !email_exists($email)) {
409
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
410
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
411
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
412
+            $user_nicename = $display_name ? trim($display_name) : $email;
413
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
414 414
             
415
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
416
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
415
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
416
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
417 417
                 $new_user_login = strstr($email, '@', true);
418
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
419
-                    $user_login = sanitize_user($new_user_login, true );
418
+                if (validate_username($user_login) && username_exists($user_login)) {
419
+                    $user_login = sanitize_user($new_user_login, true);
420 420
                 }
421
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
422
-                    $user_append_text = rand(10,1000);
423
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
421
+                if (validate_username($user_login) && username_exists($user_login)) {
422
+                    $user_append_text = rand(10, 1000);
423
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
424 424
                 }
425 425
                 
426
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
426
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
427 427
                     $user_login = $email;
428 428
                 }
429 429
             }
430 430
             
431 431
             $userdata = array(
432 432
                 'user_login' => $user_login,
433
-                'user_pass' => wp_generate_password( 12, false ),
434
-                'user_email' => sanitize_text_field( $email ),
433
+                'user_pass' => wp_generate_password(12, false),
434
+                'user_email' => sanitize_text_field($email),
435 435
                 'first_name' => $first_name,
436 436
                 'last_name' => $last_name,
437
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
437
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
438 438
                 'nickname' => $display_name,
439 439
                 'display_name' => $display_name,
440 440
             );
441 441
 
442
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
442
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
443 443
             
444
-            $new_user_id = wp_insert_user( $userdata );
444
+            $new_user_id = wp_insert_user($userdata);
445 445
             
446
-            if ( !is_wp_error( $new_user_id ) ) {
446
+            if (!is_wp_error($new_user_id)) {
447 447
                 $data['post_author'] = $new_user_id;
448 448
                 $_POST['post_author'] = $new_user_id;
449 449
                 $_POST['post_author_override'] = $new_user_id;
@@ -464,72 +464,72 @@  discard block
 block discarded – undo
464 464
                 
465 465
                 $meta = array();
466 466
                 ///$meta['_wpinv_user_id'] = $new_user_id;
467
-                foreach ( $meta_fields as $field ) {
468
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
467
+                foreach ($meta_fields as $field) {
468
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
469 469
                 }
470 470
                 
471
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
471
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
472 472
 
473 473
                 // Update user meta.
474
-                foreach ( $meta as $key => $value ) {
475
-                    update_user_meta( $new_user_id, $key, $value );
474
+                foreach ($meta as $key => $value) {
475
+                    update_user_meta($new_user_id, $key, $value);
476 476
                 }
477 477
                 
478
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
478
+                if (function_exists('wp_send_new_user_notifications')) {
479 479
                     // Send email notifications related to the creation of new user.
480
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
480
+                    wp_send_new_user_notifications($new_user_id, 'user');
481 481
                 }
482 482
             } else {
483
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
483
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
484 484
             }
485 485
         }
486 486
     }
487 487
     
488 488
     return $data;
489 489
 }
490
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
490
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
491 491
 
492
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
492
+function wpinv_show_recurring_supported_gateways($item_ID) {
493 493
     $all_gateways = wpinv_get_payment_gateways();
494 494
 
495
-    if ( !empty( $all_gateways ) ) {
495
+    if (!empty($all_gateways)) {
496 496
         $gateways = array();
497 497
 
498
-        foreach ( $all_gateways as $key => $gateway ) {
499
-            if ( wpinv_gateway_support_subscription( $key ) ) {
498
+        foreach ($all_gateways as $key => $gateway) {
499
+            if (wpinv_gateway_support_subscription($key)) {
500 500
                 $gateways[] = $gateway['admin_label'];
501 501
             }
502 502
         }
503 503
 
504
-        if ( !empty( $gateways ) ) {
504
+        if (!empty($gateways)) {
505 505
             ?>
506
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
506
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
507 507
             <?php
508 508
         }
509 509
     }
510 510
 }
511
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
511
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
512 512
 
513
-function wpinv_post_updated_messages( $messages ) {
513
+function wpinv_post_updated_messages($messages) {
514 514
     global $post, $post_ID;
515 515
 
516 516
     $messages['wpi_discount'] = array(
517 517
         0   => '',
518
-        1   => __( 'Discount updated.', 'invoicing' ),
519
-        2   => __( 'Custom field updated.', 'invoicing' ),
520
-        3   => __( 'Custom field deleted.', 'invoicing' ),
521
-        4   => __( 'Discount updated.', 'invoicing' ),
522
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
523
-        6   => __( 'Discount updated.', 'invoicing' ),
524
-        7   => __( 'Discount saved.', 'invoicing' ),
525
-        8   => __( 'Discount submitted.', 'invoicing' ),
526
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
527
-        10  => __( 'Discount draft updated.', 'invoicing' ),
518
+        1   => __('Discount updated.', 'invoicing'),
519
+        2   => __('Custom field updated.', 'invoicing'),
520
+        3   => __('Custom field deleted.', 'invoicing'),
521
+        4   => __('Discount updated.', 'invoicing'),
522
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
523
+        6   => __('Discount updated.', 'invoicing'),
524
+        7   => __('Discount saved.', 'invoicing'),
525
+        8   => __('Discount submitted.', 'invoicing'),
526
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
527
+        10  => __('Discount draft updated.', 'invoicing'),
528 528
     );
529 529
 
530 530
     return $messages;
531 531
 }
532
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
532
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
533 533
 
534 534
 add_action('admin_init', 'admin_init_example_type');
535 535
 
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 function admin_init_example_type() {
540 540
     global $typenow;
541 541
 
542
-    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) {
542
+    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') {
543 543
         add_filter('posts_search', 'posts_search_example_type', 10, 2);
544 544
     }
545 545
 }
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
     global $wpdb;
555 555
 
556 556
     if ($query->is_main_query() && !empty($query->query['s'])) {
557
-        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )";
558
-        if ( ! empty( $search ) ) {
559
-            $search = preg_replace( '/^ AND /', '', $search );
557
+        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )";
558
+        if (!empty($search)) {
559
+            $search = preg_replace('/^ AND /', '', $search);
560 560
             $search = " AND ( {$search} OR ( {$conditions_str} ) )";
561 561
         } else {
562 562
             $search = " AND ( {$conditions_str} )";
@@ -566,9 +566,9 @@  discard block
 block discarded – undo
566 566
     return $search;
567 567
 }
568 568
 
569
-add_action( 'admin_init', 'wpinv_reset_invoice_count' );
570
-function wpinv_reset_invoice_count(){
571
-    if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
569
+add_action('admin_init', 'wpinv_reset_invoice_count');
570
+function wpinv_reset_invoice_count() {
571
+    if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
572 572
         wpinv_update_option('invoice_sequence_start', 1);
573 573
         delete_option('wpinv_last_invoice_number');
574 574
         $url = add_query_arg(array('reset_invoice_done' => 1));
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
 }
580 580
 
581 581
 add_action('admin_notices', 'wpinv_invoice_count_reset_message');
582
-function wpinv_invoice_count_reset_message(){
583
-    if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
582
+function wpinv_invoice_count_reset_message() {
583
+    if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
584 584
         $notice = __('Invoice number sequence reset successfully.', 'invoicing');
585 585
         ?>
586 586
         <div class="notice notice-success is-dismissible">
Please login to merge, or discard this patch.
includes/wpinv-discount-functions.php 1 patch
Spacing   +470 added lines, -470 removed lines patch added patch discarded remove patch
@@ -7,90 +7,90 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_discount_types() {
15 15
     $discount_types = array(
16
-                        'percent'   => __( 'Percentage', 'invoicing' ),
17
-                        'flat'     => __( 'Flat Amount', 'invoicing' ),
16
+                        'percent'   => __('Percentage', 'invoicing'),
17
+                        'flat'     => __('Flat Amount', 'invoicing'),
18 18
                     );
19
-    return (array)apply_filters( 'wpinv_discount_types', $discount_types );
19
+    return (array)apply_filters('wpinv_discount_types', $discount_types);
20 20
 }
21 21
 
22
-function wpinv_get_discount_type_name( $type = '' ) {
22
+function wpinv_get_discount_type_name($type = '') {
23 23
     $types = wpinv_get_discount_types();
24
-    return isset( $types[ $type ] ) ? $types[ $type ] : '';
24
+    return isset($types[$type]) ? $types[$type] : '';
25 25
 }
26 26
 
27
-function wpinv_delete_discount( $data ) {
28
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
29
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
27
+function wpinv_delete_discount($data) {
28
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
29
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
30 30
     }
31 31
 
32
-    if( ! current_user_can( 'manage_options' ) ) {
33
-        wp_die( __( 'You do not have permission to delete discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
32
+    if (!current_user_can('manage_options')) {
33
+        wp_die(__('You do not have permission to delete discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
34 34
     }
35 35
 
36 36
     $discount_id = $data['discount'];
37
-    wpinv_remove_discount( $discount_id );
37
+    wpinv_remove_discount($discount_id);
38 38
 }
39
-add_action( 'wpinv_delete_discount', 'wpinv_delete_discount' );
39
+add_action('wpinv_delete_discount', 'wpinv_delete_discount');
40 40
 
41
-function wpinv_activate_discount( $data ) {
42
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
43
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
41
+function wpinv_activate_discount($data) {
42
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
43
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
44 44
     }
45 45
 
46
-    if( ! current_user_can( 'manage_options' ) ) {
47
-        wp_die( __( 'You do not have permission to edit discount codes', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
46
+    if (!current_user_can('manage_options')) {
47
+        wp_die(__('You do not have permission to edit discount codes', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
48 48
     }
49 49
 
50
-    $id = absint( $data['discount'] );
51
-    wpinv_update_discount_status( $id, 'publish' );
50
+    $id = absint($data['discount']);
51
+    wpinv_update_discount_status($id, 'publish');
52 52
 }
53
-add_action( 'wpinv_activate_discount', 'wpinv_activate_discount' );
53
+add_action('wpinv_activate_discount', 'wpinv_activate_discount');
54 54
 
55
-function wpinv_deactivate_discount( $data ) {
56
-    if ( ! isset( $data['_wpnonce'] ) || ! wp_verify_nonce( $data['_wpnonce'], 'wpinv_discount_nonce' ) ) {
57
-        wp_die( __( 'Trying to cheat or something?', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_deactivate_discount($data) {
56
+    if (!isset($data['_wpnonce']) || !wp_verify_nonce($data['_wpnonce'], 'wpinv_discount_nonce')) {
57
+        wp_die(__('Trying to cheat or something?', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60
-    if( ! current_user_can( 'manage_options' ) ) {
61
-        wp_die( __( 'You do not have permission to create discount codes', 'invoicing' ), array( 'response' => 403 ) );
60
+    if (!current_user_can('manage_options')) {
61
+        wp_die(__('You do not have permission to create discount codes', 'invoicing'), array('response' => 403));
62 62
     }
63 63
 
64
-    $id = absint( $data['discount'] );
65
-    wpinv_update_discount_status( $id, 'pending' );
64
+    $id = absint($data['discount']);
65
+    wpinv_update_discount_status($id, 'pending');
66 66
 }
67
-add_action( 'wpinv_deactivate_discount', 'wpinv_deactivate_discount' );
67
+add_action('wpinv_deactivate_discount', 'wpinv_deactivate_discount');
68 68
 
69
-function wpinv_get_discounts( $args = array() ) {
69
+function wpinv_get_discounts($args = array()) {
70 70
     $defaults = array(
71 71
         'post_type'      => 'wpi_discount',
72 72
         'posts_per_page' => 20,
73 73
         'paged'          => null,
74
-        'post_status'    => array( 'publish', 'pending', 'draft', 'expired' )
74
+        'post_status'    => array('publish', 'pending', 'draft', 'expired')
75 75
     );
76 76
 
77
-    $args = wp_parse_args( $args, $defaults );
77
+    $args = wp_parse_args($args, $defaults);
78 78
 
79
-    $discounts = get_posts( $args );
79
+    $discounts = get_posts($args);
80 80
 
81
-    if ( $discounts ) {
81
+    if ($discounts) {
82 82
         return $discounts;
83 83
     }
84 84
 
85
-    if( ! $discounts && ! empty( $args['s'] ) ) {
85
+    if (!$discounts && !empty($args['s'])) {
86 86
         $args['meta_key']     = '_wpi_discount_code';
87 87
         $args['meta_value']   = $args['s'];
88 88
         $args['meta_compare'] = 'LIKE';
89
-        unset( $args['s'] );
90
-        $discounts = get_posts( $args );
89
+        unset($args['s']);
90
+        $discounts = get_posts($args);
91 91
     }
92 92
 
93
-    if( $discounts ) {
93
+    if ($discounts) {
94 94
         return $discounts;
95 95
     }
96 96
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 
103 103
     $discounts  = wpinv_get_discounts();
104 104
 
105
-    if ( $discounts) {
106
-        foreach ( $discounts as $discount ) {
107
-            if ( wpinv_is_discount_active( $discount->ID ) ) {
105
+    if ($discounts) {
106
+        foreach ($discounts as $discount) {
107
+            if (wpinv_is_discount_active($discount->ID)) {
108 108
                 $has_active = true;
109 109
                 break;
110 110
             }
@@ -113,38 +113,38 @@  discard block
 block discarded – undo
113 113
     return $has_active;
114 114
 }
115 115
 
116
-function wpinv_get_discount( $discount_id = 0 ) {
117
-    if( empty( $discount_id ) ) {
116
+function wpinv_get_discount($discount_id = 0) {
117
+    if (empty($discount_id)) {
118 118
         return false;
119 119
     }
120 120
     
121
-    if ( get_post_type( $discount_id ) != 'wpi_discount' ) {
121
+    if (get_post_type($discount_id) != 'wpi_discount') {
122 122
         return false;
123 123
     }
124 124
 
125
-    $discount = get_post( $discount_id );
125
+    $discount = get_post($discount_id);
126 126
 
127 127
     return $discount;
128 128
 }
129 129
 
130
-function wpinv_get_discount_by_code( $code = '' ) {
131
-    if( empty( $code ) || ! is_string( $code ) ) {
130
+function wpinv_get_discount_by_code($code = '') {
131
+    if (empty($code) || !is_string($code)) {
132 132
         return false;
133 133
     }
134 134
 
135
-    return wpinv_get_discount_by( 'code', $code );
135
+    return wpinv_get_discount_by('code', $code);
136 136
 }
137 137
 
138
-function wpinv_get_discount_by( $field = '', $value = '' ) {
139
-    if( empty( $field ) || empty( $value ) ) {
138
+function wpinv_get_discount_by($field = '', $value = '') {
139
+    if (empty($field) || empty($value)) {
140 140
         return false;
141 141
     }
142 142
 
143
-    if( ! is_string( $field ) ) {
143
+    if (!is_string($field)) {
144 144
         return false;
145 145
     }
146 146
 
147
-    switch( strtolower( $field ) ) {
147
+    switch (strtolower($field)) {
148 148
 
149 149
         case 'code':
150 150
             $meta_query     = array();
@@ -154,32 +154,32 @@  discard block
 block discarded – undo
154 154
                 'compare' => '='
155 155
             );
156 156
             
157
-            $discount = wpinv_get_discounts( array(
157
+            $discount = wpinv_get_discounts(array(
158 158
                 'posts_per_page' => 1,
159 159
                 'post_status'    => 'any',
160 160
                 'meta_query'     => $meta_query,
161
-            ) );
161
+            ));
162 162
             
163
-            if( $discount ) {
163
+            if ($discount) {
164 164
                 $discount = $discount[0];
165 165
             }
166 166
 
167 167
             break;
168 168
 
169 169
         case 'id':
170
-            $discount = wpinv_get_discount( $value );
170
+            $discount = wpinv_get_discount($value);
171 171
 
172 172
             break;
173 173
 
174 174
         case 'name':
175
-            $discount = get_posts( array(
175
+            $discount = get_posts(array(
176 176
                 'post_type'      => 'wpi_discount',
177 177
                 'name'           => $value,
178 178
                 'posts_per_page' => 1,
179 179
                 'post_status'    => 'any'
180
-            ) );
180
+            ));
181 181
 
182
-            if( $discount ) {
182
+            if ($discount) {
183 183
                 $discount = $discount[0];
184 184
             }
185 185
 
@@ -189,96 +189,96 @@  discard block
 block discarded – undo
189 189
             return false;
190 190
     }
191 191
 
192
-    if( ! empty( $discount ) ) {
192
+    if (!empty($discount)) {
193 193
         return $discount;
194 194
     }
195 195
 
196 196
     return false;
197 197
 }
198 198
 
199
-function wpinv_store_discount( $post_id, $data, $post, $update = false ) {
199
+function wpinv_store_discount($post_id, $data, $post, $update = false) {
200 200
     $meta = array(
201
-        'code'              => isset( $data['code'] )             ? sanitize_text_field( $data['code'] )              : '',
202
-        'type'              => isset( $data['type'] )             ? sanitize_text_field( $data['type'] )              : 'percent',
203
-        'amount'            => isset( $data['amount'] )           ? wpinv_sanitize_amount( $data['amount'] )          : '',
204
-        'start'             => isset( $data['start'] )            ? sanitize_text_field( $data['start'] )             : '',
205
-        'expiration'        => isset( $data['expiration'] )       ? sanitize_text_field( $data['expiration'] )        : '',
206
-        'min_total'         => isset( $data['min_total'] )        ? wpinv_sanitize_amount( $data['min_total'] )       : '',
207
-        'max_total'         => isset( $data['max_total'] )        ? wpinv_sanitize_amount( $data['max_total'] )       : '',
208
-        'max_uses'          => isset( $data['max_uses'] )         ? absint( $data['max_uses'] )                       : '',
209
-        'items'             => isset( $data['items'] )            ? $data['items']                                    : array(),
210
-        'excluded_items'    => isset( $data['excluded_items'] )   ? $data['excluded_items']                           : array(),
211
-        'is_recurring'      => isset( $data['recurring'] )        ? (bool)$data['recurring']                          : false,
212
-        'is_single_use'     => isset( $data['single_use'] )       ? (bool)$data['single_use']                         : false,
213
-        'uses'              => isset( $data['uses'] )             ? (int)$data['uses']                                : false,
201
+        'code'              => isset($data['code']) ? sanitize_text_field($data['code']) : '',
202
+        'type'              => isset($data['type']) ? sanitize_text_field($data['type']) : 'percent',
203
+        'amount'            => isset($data['amount']) ? wpinv_sanitize_amount($data['amount']) : '',
204
+        'start'             => isset($data['start']) ? sanitize_text_field($data['start']) : '',
205
+        'expiration'        => isset($data['expiration']) ? sanitize_text_field($data['expiration']) : '',
206
+        'min_total'         => isset($data['min_total']) ? wpinv_sanitize_amount($data['min_total']) : '',
207
+        'max_total'         => isset($data['max_total']) ? wpinv_sanitize_amount($data['max_total']) : '',
208
+        'max_uses'          => isset($data['max_uses']) ? absint($data['max_uses']) : '',
209
+        'items'             => isset($data['items']) ? $data['items'] : array(),
210
+        'excluded_items'    => isset($data['excluded_items']) ? $data['excluded_items'] : array(),
211
+        'is_recurring'      => isset($data['recurring']) ? (bool)$data['recurring'] : false,
212
+        'is_single_use'     => isset($data['single_use']) ? (bool)$data['single_use'] : false,
213
+        'uses'              => isset($data['uses']) ? (int)$data['uses'] : false,
214 214
     );
215 215
 
216
-    if ( $meta['type'] == 'percent' && (float)$meta['amount'] > 100 ) {
216
+    if ($meta['type'] == 'percent' && (float)$meta['amount'] > 100) {
217 217
         $meta['amount'] = 100;
218 218
     }
219 219
 
220
-    if ( !empty( $meta['start'] ) ) {
221
-        $meta['start']      = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['start'] ) );
220
+    if (!empty($meta['start'])) {
221
+        $meta['start'] = date_i18n('Y-m-d H:i:s', strtotime($meta['start']));
222 222
     }
223 223
 
224
-    if ( !empty( $meta['expiration'] ) ) {
225
-        $meta['expiration'] = date_i18n( 'Y-m-d H:i:s', strtotime( $meta['expiration'] ) );
224
+    if (!empty($meta['expiration'])) {
225
+        $meta['expiration'] = date_i18n('Y-m-d H:i:s', strtotime($meta['expiration']));
226 226
 
227
-        if ( !empty( $meta['start'] ) && strtotime( $meta['start'] ) > strtotime( $meta['expiration'] ) ) {
227
+        if (!empty($meta['start']) && strtotime($meta['start']) > strtotime($meta['expiration'])) {
228 228
             $meta['expiration'] = $meta['start'];
229 229
         }
230 230
     }
231 231
     
232
-    if ( $meta['uses'] === false ) {
233
-        unset( $meta['uses'] );
232
+    if ($meta['uses'] === false) {
233
+        unset($meta['uses']);
234 234
     }
235 235
     
236
-    if ( ! empty( $meta['items'] ) ) {
237
-        foreach ( $meta['items'] as $key => $item ) {
238
-            if ( 0 === intval( $item ) ) {
239
-                unset( $meta['items'][ $key ] );
236
+    if (!empty($meta['items'])) {
237
+        foreach ($meta['items'] as $key => $item) {
238
+            if (0 === intval($item)) {
239
+                unset($meta['items'][$key]);
240 240
             }
241 241
         }
242 242
     }
243 243
     
244
-    if ( ! empty( $meta['excluded_items'] ) ) {
245
-        foreach ( $meta['excluded_items'] as $key => $item ) {
246
-            if ( 0 === intval( $item ) ) {
247
-                unset( $meta['excluded_items'][ $key ] );
244
+    if (!empty($meta['excluded_items'])) {
245
+        foreach ($meta['excluded_items'] as $key => $item) {
246
+            if (0 === intval($item)) {
247
+                unset($meta['excluded_items'][$key]);
248 248
             }
249 249
         }
250 250
     }
251 251
     
252
-    $meta = apply_filters( 'wpinv_update_discount', $meta, $post_id, $post );
252
+    $meta = apply_filters('wpinv_update_discount', $meta, $post_id, $post);
253 253
     
254
-    do_action( 'wpinv_pre_update_discount', $meta, $post_id, $post );
254
+    do_action('wpinv_pre_update_discount', $meta, $post_id, $post);
255 255
     
256
-    foreach( $meta as $key => $value ) {
257
-        update_post_meta( $post_id, '_wpi_discount_' . $key, $value );
256
+    foreach ($meta as $key => $value) {
257
+        update_post_meta($post_id, '_wpi_discount_' . $key, $value);
258 258
     }
259 259
     
260
-    do_action( 'wpinv_post_update_discount', $meta, $post_id, $post );
260
+    do_action('wpinv_post_update_discount', $meta, $post_id, $post);
261 261
     
262 262
     return $post_id;
263 263
 }
264 264
 
265
-function wpinv_remove_discount( $discount_id = 0 ) {
266
-    do_action( 'wpinv_pre_delete_discount', $discount_id );
265
+function wpinv_remove_discount($discount_id = 0) {
266
+    do_action('wpinv_pre_delete_discount', $discount_id);
267 267
 
268
-    wp_delete_post( $discount_id, true );
268
+    wp_delete_post($discount_id, true);
269 269
 
270
-    do_action( 'wpinv_post_delete_discount', $discount_id );
270
+    do_action('wpinv_post_delete_discount', $discount_id);
271 271
 }
272 272
 
273
-function wpinv_update_discount_status( $code_id = 0, $new_status = 'publish' ) {
274
-    $discount = wpinv_get_discount(  $code_id );
273
+function wpinv_update_discount_status($code_id = 0, $new_status = 'publish') {
274
+    $discount = wpinv_get_discount($code_id);
275 275
 
276
-    if ( $discount ) {
277
-        do_action( 'wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status );
276
+    if ($discount) {
277
+        do_action('wpinv_pre_update_discount_status', $code_id, $new_status, $discount->post_status);
278 278
 
279
-        wp_update_post( array( 'ID' => $code_id, 'post_status' => $new_status ) );
279
+        wp_update_post(array('ID' => $code_id, 'post_status' => $new_status));
280 280
 
281
-        do_action( 'wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status );
281
+        do_action('wpinv_post_update_discount_status', $code_id, $new_status, $discount->post_status);
282 282
 
283 283
         return true;
284 284
     }
@@ -286,173 +286,173 @@  discard block
 block discarded – undo
286 286
     return false;
287 287
 }
288 288
 
289
-function wpinv_discount_exists( $code_id ) {
290
-    if ( wpinv_get_discount(  $code_id ) ) {
289
+function wpinv_discount_exists($code_id) {
290
+    if (wpinv_get_discount($code_id)) {
291 291
         return true;
292 292
     }
293 293
 
294 294
     return false;
295 295
 }
296 296
 
297
-function wpinv_is_discount_active( $code_id = null ) {
298
-    $discount = wpinv_get_discount(  $code_id );
297
+function wpinv_is_discount_active($code_id = null) {
298
+    $discount = wpinv_get_discount($code_id);
299 299
     $return   = false;
300 300
 
301
-    if ( $discount ) {
302
-        if ( wpinv_is_discount_expired( $code_id ) ) {
303
-            if( defined( 'DOING_AJAX' ) ) {
304
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is expired.', 'invoicing' ) );
301
+    if ($discount) {
302
+        if (wpinv_is_discount_expired($code_id)) {
303
+            if (defined('DOING_AJAX')) {
304
+                wpinv_set_error('wpinv-discount-error', __('This discount is expired.', 'invoicing'));
305 305
             }
306
-        } elseif ( $discount->post_status == 'publish' ) {
306
+        } elseif ($discount->post_status == 'publish') {
307 307
             $return = true;
308 308
         } else {
309
-            if( defined( 'DOING_AJAX' ) ) {
310
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active.', 'invoicing' ) );
309
+            if (defined('DOING_AJAX')) {
310
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active.', 'invoicing'));
311 311
             }
312 312
         }
313 313
     }
314 314
 
315
-    return apply_filters( 'wpinv_is_discount_active', $return, $code_id );
315
+    return apply_filters('wpinv_is_discount_active', $return, $code_id);
316 316
 }
317 317
 
318
-function wpinv_get_discount_code( $code_id = null ) {
319
-    $code = get_post_meta( $code_id, '_wpi_discount_code', true );
318
+function wpinv_get_discount_code($code_id = null) {
319
+    $code = get_post_meta($code_id, '_wpi_discount_code', true);
320 320
 
321
-    return apply_filters( 'wpinv_get_discount_code', $code, $code_id );
321
+    return apply_filters('wpinv_get_discount_code', $code, $code_id);
322 322
 }
323 323
 
324
-function wpinv_get_discount_start_date( $code_id = null ) {
325
-    $start_date = get_post_meta( $code_id, '_wpi_discount_start', true );
324
+function wpinv_get_discount_start_date($code_id = null) {
325
+    $start_date = get_post_meta($code_id, '_wpi_discount_start', true);
326 326
 
327
-    return apply_filters( 'wpinv_get_discount_start_date', $start_date, $code_id );
327
+    return apply_filters('wpinv_get_discount_start_date', $start_date, $code_id);
328 328
 }
329 329
 
330
-function wpinv_get_discount_expiration( $code_id = null ) {
331
-    $expiration = get_post_meta( $code_id, '_wpi_discount_expiration', true );
330
+function wpinv_get_discount_expiration($code_id = null) {
331
+    $expiration = get_post_meta($code_id, '_wpi_discount_expiration', true);
332 332
 
333
-    return apply_filters( 'wpinv_get_discount_expiration', $expiration, $code_id );
333
+    return apply_filters('wpinv_get_discount_expiration', $expiration, $code_id);
334 334
 }
335 335
 
336
-function wpinv_get_discount_max_uses( $code_id = null ) {
337
-    $max_uses = get_post_meta( $code_id, '_wpi_discount_max_uses', true );
336
+function wpinv_get_discount_max_uses($code_id = null) {
337
+    $max_uses = get_post_meta($code_id, '_wpi_discount_max_uses', true);
338 338
 
339
-    return (int) apply_filters( 'wpinv_get_discount_max_uses', $max_uses, $code_id );
339
+    return (int)apply_filters('wpinv_get_discount_max_uses', $max_uses, $code_id);
340 340
 }
341 341
 
342
-function wpinv_get_discount_uses( $code_id = null ) {
343
-    $uses = get_post_meta( $code_id, '_wpi_discount_uses', true );
342
+function wpinv_get_discount_uses($code_id = null) {
343
+    $uses = get_post_meta($code_id, '_wpi_discount_uses', true);
344 344
 
345
-    return (int) apply_filters( 'wpinv_get_discount_uses', $uses, $code_id );
345
+    return (int)apply_filters('wpinv_get_discount_uses', $uses, $code_id);
346 346
 }
347 347
 
348
-function wpinv_get_discount_min_total( $code_id = null ) {
349
-    $min_total = get_post_meta( $code_id, '_wpi_discount_min_total', true );
348
+function wpinv_get_discount_min_total($code_id = null) {
349
+    $min_total = get_post_meta($code_id, '_wpi_discount_min_total', true);
350 350
 
351
-    return (float) apply_filters( 'wpinv_get_discount_min_total', $min_total, $code_id );
351
+    return (float)apply_filters('wpinv_get_discount_min_total', $min_total, $code_id);
352 352
 }
353 353
 
354
-function wpinv_get_discount_max_total( $code_id = null ) {
355
-    $max_total = get_post_meta( $code_id, '_wpi_discount_max_total', true );
354
+function wpinv_get_discount_max_total($code_id = null) {
355
+    $max_total = get_post_meta($code_id, '_wpi_discount_max_total', true);
356 356
 
357
-    return (float) apply_filters( 'wpinv_get_discount_max_total', $max_total, $code_id );
357
+    return (float)apply_filters('wpinv_get_discount_max_total', $max_total, $code_id);
358 358
 }
359 359
 
360
-function wpinv_get_discount_amount( $code_id = null ) {
361
-    $amount = get_post_meta( $code_id, '_wpi_discount_amount', true );
360
+function wpinv_get_discount_amount($code_id = null) {
361
+    $amount = get_post_meta($code_id, '_wpi_discount_amount', true);
362 362
 
363
-    return (float) apply_filters( 'wpinv_get_discount_amount', $amount, $code_id );
363
+    return (float)apply_filters('wpinv_get_discount_amount', $amount, $code_id);
364 364
 }
365 365
 
366
-function wpinv_get_discount_type( $code_id = null, $name = false ) {
367
-    $type = strtolower( get_post_meta( $code_id, '_wpi_discount_type', true ) );
366
+function wpinv_get_discount_type($code_id = null, $name = false) {
367
+    $type = strtolower(get_post_meta($code_id, '_wpi_discount_type', true));
368 368
     
369
-    if ( $name ) {
370
-        $name = wpinv_get_discount_type_name( $type );
369
+    if ($name) {
370
+        $name = wpinv_get_discount_type_name($type);
371 371
         
372
-        return apply_filters( 'wpinv_get_discount_type_name', $name, $code_id );
372
+        return apply_filters('wpinv_get_discount_type_name', $name, $code_id);
373 373
     }
374 374
 
375
-    return apply_filters( 'wpinv_get_discount_type', $type, $code_id );
375
+    return apply_filters('wpinv_get_discount_type', $type, $code_id);
376 376
 }
377 377
 
378
-function wpinv_discount_status( $status ) {
379
-    switch( $status ){
378
+function wpinv_discount_status($status) {
379
+    switch ($status) {
380 380
         case 'expired' :
381
-            $name = __( 'Expired', 'invoicing' );
381
+            $name = __('Expired', 'invoicing');
382 382
             break;
383 383
         case 'publish' :
384 384
         case 'active' :
385
-            $name = __( 'Active', 'invoicing' );
385
+            $name = __('Active', 'invoicing');
386 386
             break;
387 387
         default :
388
-            $name = __( 'Inactive', 'invoicing' );
388
+            $name = __('Inactive', 'invoicing');
389 389
             break;
390 390
     }
391 391
     return $name;
392 392
 }
393 393
 
394
-function wpinv_get_discount_excluded_items( $code_id = null ) {
395
-    $excluded_items = get_post_meta( $code_id, '_wpi_discount_excluded_items', true );
394
+function wpinv_get_discount_excluded_items($code_id = null) {
395
+    $excluded_items = get_post_meta($code_id, '_wpi_discount_excluded_items', true);
396 396
 
397
-    if ( empty( $excluded_items ) || ! is_array( $excluded_items ) ) {
397
+    if (empty($excluded_items) || !is_array($excluded_items)) {
398 398
         $excluded_items = array();
399 399
     }
400 400
 
401
-    return (array) apply_filters( 'wpinv_get_discount_excluded_items', $excluded_items, $code_id );
401
+    return (array)apply_filters('wpinv_get_discount_excluded_items', $excluded_items, $code_id);
402 402
 }
403 403
 
404
-function wpinv_get_discount_item_reqs( $code_id = null ) {
405
-    $item_reqs = get_post_meta( $code_id, '_wpi_discount_items', true );
404
+function wpinv_get_discount_item_reqs($code_id = null) {
405
+    $item_reqs = get_post_meta($code_id, '_wpi_discount_items', true);
406 406
 
407
-    if ( empty( $item_reqs ) || ! is_array( $item_reqs ) ) {
407
+    if (empty($item_reqs) || !is_array($item_reqs)) {
408 408
         $item_reqs = array();
409 409
     }
410 410
 
411
-    return (array) apply_filters( 'wpinv_get_discount_item_reqs', $item_reqs, $code_id );
411
+    return (array)apply_filters('wpinv_get_discount_item_reqs', $item_reqs, $code_id);
412 412
 }
413 413
 
414
-function wpinv_get_discount_item_condition( $code_id = 0 ) {
415
-    return get_post_meta( $code_id, '_wpi_discount_item_condition', true );
414
+function wpinv_get_discount_item_condition($code_id = 0) {
415
+    return get_post_meta($code_id, '_wpi_discount_item_condition', true);
416 416
 }
417 417
 
418
-function wpinv_is_discount_not_global( $code_id = 0 ) {
419
-    return (bool) get_post_meta( $code_id, '_wpi_discount_is_not_global', true );
418
+function wpinv_is_discount_not_global($code_id = 0) {
419
+    return (bool)get_post_meta($code_id, '_wpi_discount_is_not_global', true);
420 420
 }
421 421
 
422
-function wpinv_is_discount_expired( $code_id = null ) {
423
-    $discount = wpinv_get_discount(  $code_id );
422
+function wpinv_is_discount_expired($code_id = null) {
423
+    $discount = wpinv_get_discount($code_id);
424 424
     $return   = false;
425 425
 
426
-    if ( $discount ) {
427
-        $expiration = wpinv_get_discount_expiration( $code_id );
428
-        if ( $expiration ) {
429
-            $expiration = strtotime( $expiration );
430
-            if ( $expiration < current_time( 'timestamp' ) ) {
426
+    if ($discount) {
427
+        $expiration = wpinv_get_discount_expiration($code_id);
428
+        if ($expiration) {
429
+            $expiration = strtotime($expiration);
430
+            if ($expiration < current_time('timestamp')) {
431 431
                 // Discount is expired
432
-                wpinv_update_discount_status( $code_id, 'pending' );
432
+                wpinv_update_discount_status($code_id, 'pending');
433 433
                 $return = true;
434 434
             }
435 435
         }
436 436
     }
437 437
 
438
-    return apply_filters( 'wpinv_is_discount_expired', $return, $code_id );
438
+    return apply_filters('wpinv_is_discount_expired', $return, $code_id);
439 439
 }
440 440
 
441
-function wpinv_is_discount_started( $code_id = null ) {
442
-    $discount = wpinv_get_discount(  $code_id );
441
+function wpinv_is_discount_started($code_id = null) {
442
+    $discount = wpinv_get_discount($code_id);
443 443
     $return   = false;
444 444
 
445
-    if ( $discount ) {
446
-        $start_date = wpinv_get_discount_start_date( $code_id );
445
+    if ($discount) {
446
+        $start_date = wpinv_get_discount_start_date($code_id);
447 447
 
448
-        if ( $start_date ) {
449
-            $start_date = strtotime( $start_date );
448
+        if ($start_date) {
449
+            $start_date = strtotime($start_date);
450 450
 
451
-            if ( $start_date < current_time( 'timestamp' ) ) {
451
+            if ($start_date < current_time('timestamp')) {
452 452
                 // Discount has past the start date
453 453
                 $return = true;
454 454
             } else {
455
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
455
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
456 456
             }
457 457
         } else {
458 458
             // No start date for this discount, so has to be true
@@ -460,159 +460,159 @@  discard block
 block discarded – undo
460 460
         }
461 461
     }
462 462
 
463
-    return apply_filters( 'wpinv_is_discount_started', $return, $code_id );
463
+    return apply_filters('wpinv_is_discount_started', $return, $code_id);
464 464
 }
465 465
 
466
-function wpinv_check_discount_dates( $code_id = null ) {
467
-    $discount = wpinv_get_discount(  $code_id );
466
+function wpinv_check_discount_dates($code_id = null) {
467
+    $discount = wpinv_get_discount($code_id);
468 468
     $return   = false;
469 469
 
470
-    if ( $discount ) {
471
-        $start_date = wpinv_get_discount_start_date( $code_id );
470
+    if ($discount) {
471
+        $start_date = wpinv_get_discount_start_date($code_id);
472 472
 
473
-        if ( $start_date ) {
474
-            $start_date = strtotime( $start_date );
473
+        if ($start_date) {
474
+            $start_date = strtotime($start_date);
475 475
 
476
-            if ( $start_date < current_time( 'timestamp' ) ) {
476
+            if ($start_date < current_time('timestamp')) {
477 477
                 // Discount has past the start date
478 478
                 $return = true;
479 479
             } else {
480
-                wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not active yet.', 'invoicing' ) );
480
+                wpinv_set_error('wpinv-discount-error', __('This discount is not active yet.', 'invoicing'));
481 481
             }
482 482
         } else {
483 483
             // No start date for this discount, so has to be true
484 484
             $return = true;
485 485
         }
486 486
         
487
-        if ( $return ) {
488
-            $expiration = wpinv_get_discount_expiration( $code_id );
487
+        if ($return) {
488
+            $expiration = wpinv_get_discount_expiration($code_id);
489 489
             
490
-            if ( $expiration ) {
491
-                $expiration = strtotime( $expiration );
492
-                if ( $expiration < current_time( 'timestamp' ) ) {
490
+            if ($expiration) {
491
+                $expiration = strtotime($expiration);
492
+                if ($expiration < current_time('timestamp')) {
493 493
                     // Discount is expired
494
-                    wpinv_update_discount_status( $code_id, 'pending' );
494
+                    wpinv_update_discount_status($code_id, 'pending');
495 495
                     $return = true;
496 496
                 }
497 497
             }
498 498
         }
499 499
     }
500 500
     
501
-    return apply_filters( 'wpinv_check_discount_dates', $return, $code_id );
501
+    return apply_filters('wpinv_check_discount_dates', $return, $code_id);
502 502
 }
503 503
 
504
-function wpinv_is_discount_maxed_out( $code_id = null ) {
505
-    $discount = wpinv_get_discount(  $code_id );
504
+function wpinv_is_discount_maxed_out($code_id = null) {
505
+    $discount = wpinv_get_discount($code_id);
506 506
     $return   = false;
507 507
 
508
-    if ( $discount ) {
509
-        $uses = wpinv_get_discount_uses( $code_id );
508
+    if ($discount) {
509
+        $uses = wpinv_get_discount_uses($code_id);
510 510
         // Large number that will never be reached
511
-        $max_uses = wpinv_get_discount_max_uses( $code_id );
511
+        $max_uses = wpinv_get_discount_max_uses($code_id);
512 512
         // Should never be greater than, but just in case
513
-        if ( $uses >= $max_uses && ! empty( $max_uses ) ) {
513
+        if ($uses >= $max_uses && !empty($max_uses)) {
514 514
             // Discount is maxed out
515
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount has reached its maximum usage.', 'invoicing' ) );
515
+            wpinv_set_error('wpinv-discount-error', __('This discount has reached its maximum usage.', 'invoicing'));
516 516
             $return = true;
517 517
         }
518 518
     }
519 519
 
520
-    return apply_filters( 'wpinv_is_discount_maxed_out', $return, $code_id );
520
+    return apply_filters('wpinv_is_discount_maxed_out', $return, $code_id);
521 521
 }
522 522
 
523
-function wpinv_discount_is_min_met( $code_id = null ) {
524
-    $discount = wpinv_get_discount( $code_id );
523
+function wpinv_discount_is_min_met($code_id = null) {
524
+    $discount = wpinv_get_discount($code_id);
525 525
     $return   = false;
526 526
 
527
-    if ( $discount ) {
528
-        $min         = (float)wpinv_get_discount_min_total( $code_id );
529
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
527
+    if ($discount) {
528
+        $min         = (float)wpinv_get_discount_min_total($code_id);
529
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
530 530
 
531
-        if ( !$min > 0 || $cart_amount >= $min ) {
531
+        if (!$min > 0 || $cart_amount >= $min) {
532 532
             // Minimum has been met
533 533
             $return = true;
534 534
         } else {
535
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Minimum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $min ) ) ) );
535
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Minimum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($min))));
536 536
         }
537 537
     }
538 538
 
539
-    return apply_filters( 'wpinv_is_discount_min_met', $return, $code_id );
539
+    return apply_filters('wpinv_is_discount_min_met', $return, $code_id);
540 540
 }
541 541
 
542
-function wpinv_discount_is_max_met( $code_id = null ) {
543
-    $discount = wpinv_get_discount( $code_id );
542
+function wpinv_discount_is_max_met($code_id = null) {
543
+    $discount = wpinv_get_discount($code_id);
544 544
     $return   = false;
545 545
 
546
-    if ( $discount ) {
547
-        $max         = (float)wpinv_get_discount_max_total( $code_id );
548
-        $cart_amount = (float)wpinv_get_cart_discountable_subtotal( $code_id );
546
+    if ($discount) {
547
+        $max         = (float)wpinv_get_discount_max_total($code_id);
548
+        $cart_amount = (float)wpinv_get_cart_discountable_subtotal($code_id);
549 549
 
550
-        if ( !$max > 0 || $cart_amount <= $max ) {
550
+        if (!$max > 0 || $cart_amount <= $max) {
551 551
             // Minimum has been met
552 552
             $return = true;
553 553
         } else {
554
-            wpinv_set_error( 'wpinv-discount-error', sprintf( __( 'Maximum invoice amount should be %s', 'invoicing' ), wpinv_price( wpinv_format_amount( $max ) ) ) );
554
+            wpinv_set_error('wpinv-discount-error', sprintf(__('Maximum invoice amount should be %s', 'invoicing'), wpinv_price(wpinv_format_amount($max))));
555 555
         }
556 556
     }
557 557
 
558
-    return apply_filters( 'wpinv_is_discount_max_met', $return, $code_id );
558
+    return apply_filters('wpinv_is_discount_max_met', $return, $code_id);
559 559
 }
560 560
 
561
-function wpinv_discount_is_single_use( $code_id = 0 ) {
562
-    $single_use = get_post_meta( $code_id, '_wpi_discount_is_single_use', true );
563
-    return (bool) apply_filters( 'wpinv_is_discount_single_use', $single_use, $code_id );
561
+function wpinv_discount_is_single_use($code_id = 0) {
562
+    $single_use = get_post_meta($code_id, '_wpi_discount_is_single_use', true);
563
+    return (bool)apply_filters('wpinv_is_discount_single_use', $single_use, $code_id);
564 564
 }
565 565
 
566
-function wpinv_discount_is_recurring( $code_id = 0, $code = false ) {
567
-    if ( $code ) {
568
-        $discount = wpinv_get_discount_by_code( $code_id );
566
+function wpinv_discount_is_recurring($code_id = 0, $code = false) {
567
+    if ($code) {
568
+        $discount = wpinv_get_discount_by_code($code_id);
569 569
         
570
-        if ( !empty( $discount ) ) {
570
+        if (!empty($discount)) {
571 571
             $code_id = $discount->ID;
572 572
         }
573 573
     }
574 574
     
575
-    $recurring = get_post_meta( $code_id, '_wpi_discount_is_recurring', true );
575
+    $recurring = get_post_meta($code_id, '_wpi_discount_is_recurring', true);
576 576
     
577
-    return (bool) apply_filters( 'wpinv_is_discount_recurring', $recurring, $code_id, $code );
577
+    return (bool)apply_filters('wpinv_is_discount_recurring', $recurring, $code_id, $code);
578 578
 }
579 579
 
580
-function wpinv_discount_item_reqs_met( $code_id = null ) {
581
-    $item_reqs    = wpinv_get_discount_item_reqs( $code_id );
582
-    $condition    = wpinv_get_discount_item_condition( $code_id );
583
-    $excluded_ps  = wpinv_get_discount_excluded_items( $code_id );
580
+function wpinv_discount_item_reqs_met($code_id = null) {
581
+    $item_reqs    = wpinv_get_discount_item_reqs($code_id);
582
+    $condition    = wpinv_get_discount_item_condition($code_id);
583
+    $excluded_ps  = wpinv_get_discount_excluded_items($code_id);
584 584
     $cart_items   = wpinv_get_cart_contents();
585
-    $cart_ids     = $cart_items ? wp_list_pluck( $cart_items, 'id' ) : null;
585
+    $cart_ids     = $cart_items ? wp_list_pluck($cart_items, 'id') : null;
586 586
     $ret          = false;
587 587
 
588
-    if ( empty( $item_reqs ) && empty( $excluded_ps ) ) {
588
+    if (empty($item_reqs) && empty($excluded_ps)) {
589 589
         $ret = true;
590 590
     }
591 591
 
592 592
     // Normalize our data for item requirements, exclusions and cart data
593 593
     // First absint the items, then sort, and reset the array keys
594
-    $item_reqs = array_map( 'absint', $item_reqs );
595
-    asort( $item_reqs );
596
-    $item_reqs = array_values( $item_reqs );
594
+    $item_reqs = array_map('absint', $item_reqs);
595
+    asort($item_reqs);
596
+    $item_reqs = array_values($item_reqs);
597 597
 
598
-    $excluded_ps  = array_map( 'absint', $excluded_ps );
599
-    asort( $excluded_ps );
600
-    $excluded_ps  = array_values( $excluded_ps );
598
+    $excluded_ps  = array_map('absint', $excluded_ps);
599
+    asort($excluded_ps);
600
+    $excluded_ps  = array_values($excluded_ps);
601 601
 
602
-    $cart_ids     = array_map( 'absint', $cart_ids );
603
-    asort( $cart_ids );
604
-    $cart_ids     = array_values( $cart_ids );
602
+    $cart_ids     = array_map('absint', $cart_ids);
603
+    asort($cart_ids);
604
+    $cart_ids     = array_values($cart_ids);
605 605
 
606 606
     // Ensure we have requirements before proceeding
607
-    if ( !$ret && ! empty( $item_reqs ) ) {
608
-        switch( $condition ) {
607
+    if (!$ret && !empty($item_reqs)) {
608
+        switch ($condition) {
609 609
             case 'all' :
610 610
                 // Default back to true
611 611
                 $ret = true;
612 612
 
613
-                foreach ( $item_reqs as $item_id ) {
614
-                    if ( !wpinv_item_in_cart( $item_id ) ) {
615
-                        wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
613
+                foreach ($item_reqs as $item_id) {
614
+                    if (!wpinv_item_in_cart($item_id)) {
615
+                        wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
616 616
                         $ret = false;
617 617
                         break;
618 618
                     }
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
                 break;
622 622
 
623 623
             default : // Any
624
-                foreach ( $item_reqs as $item_id ) {
625
-                    if ( wpinv_item_in_cart( $item_id ) ) {
624
+                foreach ($item_reqs as $item_id) {
625
+                    if (wpinv_item_in_cart($item_id)) {
626 626
                         $ret = true;
627 627
                         break;
628 628
                     }
629 629
                 }
630 630
 
631
-                if( ! $ret ) {
632
-                    wpinv_set_error( 'wpinv-discount-error', __( 'The item requirements for this discount are not met.', 'invoicing' ) );
631
+                if (!$ret) {
632
+                    wpinv_set_error('wpinv-discount-error', __('The item requirements for this discount are not met.', 'invoicing'));
633 633
                 }
634 634
 
635 635
                 break;
@@ -638,70 +638,70 @@  discard block
 block discarded – undo
638 638
         $ret = true;
639 639
     }
640 640
 
641
-    if( ! empty( $excluded_ps ) ) {
641
+    if (!empty($excluded_ps)) {
642 642
         // Check that there are items other than excluded ones in the cart
643
-        if( $cart_ids == $excluded_ps ) {
644
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is not valid for the cart contents.', 'invoicing' ) );
643
+        if ($cart_ids == $excluded_ps) {
644
+            wpinv_set_error('wpinv-discount-error', __('This discount is not valid for the cart contents.', 'invoicing'));
645 645
             $ret = false;
646 646
         }
647 647
     }
648 648
 
649
-    return (bool) apply_filters( 'wpinv_is_discount_item_req_met', $ret, $code_id, $condition );
649
+    return (bool)apply_filters('wpinv_is_discount_item_req_met', $ret, $code_id, $condition);
650 650
 }
651 651
 
652
-function wpinv_is_discount_used( $code = null, $user = '', $code_id = 0 ) {
652
+function wpinv_is_discount_used($code = null, $user = '', $code_id = 0) {
653 653
     global $wpi_checkout_id;
654 654
     
655 655
     $return = false;
656 656
 
657
-    if ( empty( $code_id ) ) {
658
-        $code_id = wpinv_get_discount_id_by_code( $code );
657
+    if (empty($code_id)) {
658
+        $code_id = wpinv_get_discount_id_by_code($code);
659 659
         
660
-        if( empty( $code_id ) ) {
660
+        if (empty($code_id)) {
661 661
             return false; // No discount was found
662 662
         }
663 663
     }
664 664
 
665
-    if ( wpinv_discount_is_single_use( $code_id ) ) {
665
+    if (wpinv_discount_is_single_use($code_id)) {
666 666
         $payments = array();
667 667
 
668 668
         $user_id = 0;
669
-        if ( is_int( $user ) ) {
670
-            $user_id = absint( $user );
671
-        } else if ( is_email( $user ) && $user_data = get_user_by( 'email', $user ) ) {
669
+        if (is_int($user)) {
670
+            $user_id = absint($user);
671
+        } else if (is_email($user) && $user_data = get_user_by('email', $user)) {
672 672
             $user_id = $user_data->ID;
673
-        } else if ( $user_data = get_user_by( 'login', $user ) ) {
673
+        } else if ($user_data = get_user_by('login', $user)) {
674 674
             $user_id = $user_data->ID;
675
-        } else if ( absint( $user ) > 0 ) {
676
-            $user_id = absint( $user );
675
+        } else if (absint($user) > 0) {
676
+            $user_id = absint($user);
677 677
         }
678 678
 
679
-        if ( !empty( $user_id ) ) {
680
-            $query    = array( 'user' => $user_id, 'limit' => false );
681
-            $payments = wpinv_get_invoices( $query ); // Get all payments with matching user id
679
+        if (!empty($user_id)) {
680
+            $query    = array('user' => $user_id, 'limit' => false);
681
+            $payments = wpinv_get_invoices($query); // Get all payments with matching user id
682 682
         }
683 683
 
684
-        if ( $payments ) {
685
-            foreach ( $payments as $payment ) {
684
+        if ($payments) {
685
+            foreach ($payments as $payment) {
686 686
                 // Don't count discount used for current invoice chekcout.
687
-                if ( !empty( $wpi_checkout_id ) && $wpi_checkout_id == $payment->ID ) {
687
+                if (!empty($wpi_checkout_id) && $wpi_checkout_id == $payment->ID) {
688 688
                     continue;
689 689
                 }
690 690
                 
691
-                if ( $payment->has_status( array( 'wpi-cancelled', 'wpi-failed' ) ) ) {
691
+                if ($payment->has_status(array('wpi-cancelled', 'wpi-failed'))) {
692 692
                     continue;
693 693
                 }
694 694
 
695
-                $discounts = $payment->get_discounts( true );
696
-                if ( empty( $discounts ) ) {
695
+                $discounts = $payment->get_discounts(true);
696
+                if (empty($discounts)) {
697 697
                     continue;
698 698
                 }
699 699
 
700
-                $discounts = $discounts && !is_array( $discounts ) ? explode( ',', $discounts ) : $discounts;
700
+                $discounts = $discounts && !is_array($discounts) ? explode(',', $discounts) : $discounts;
701 701
 
702
-                if ( !empty( $discounts ) && is_array( $discounts ) ) {
703
-                    if ( in_array( strtolower( $code ), array_map( 'strtolower', $discounts ) ) ) {
704
-                        wpinv_set_error( 'wpinv-discount-error', __( 'This discount has already been redeemed.', 'invoicing' ) );
702
+                if (!empty($discounts) && is_array($discounts)) {
703
+                    if (in_array(strtolower($code), array_map('strtolower', $discounts))) {
704
+                        wpinv_set_error('wpinv-discount-error', __('This discount has already been redeemed.', 'invoicing'));
705 705
                         $return = true;
706 706
                         break;
707 707
                     }
@@ -710,61 +710,61 @@  discard block
 block discarded – undo
710 710
         }
711 711
     }
712 712
 
713
-    return apply_filters( 'wpinv_is_discount_used', $return, $code, $user );
713
+    return apply_filters('wpinv_is_discount_used', $return, $code, $user);
714 714
 }
715 715
 
716
-function wpinv_is_discount_valid( $code = '', $user = '', $set_error = true ) {
716
+function wpinv_is_discount_valid($code = '', $user = '', $set_error = true) {
717 717
     $return      = false;
718
-    $discount_id = wpinv_get_discount_id_by_code( $code );
719
-    $user        = trim( $user );
718
+    $discount_id = wpinv_get_discount_id_by_code($code);
719
+    $user        = trim($user);
720 720
 
721
-    if ( wpinv_get_cart_contents() ) {
722
-        if ( $discount_id ) {
721
+    if (wpinv_get_cart_contents()) {
722
+        if ($discount_id) {
723 723
             if (
724
-                wpinv_is_discount_active( $discount_id ) &&
725
-                wpinv_check_discount_dates( $discount_id ) &&
726
-                !wpinv_is_discount_maxed_out( $discount_id ) &&
727
-                !wpinv_is_discount_used( $code, $user, $discount_id ) &&
728
-                wpinv_discount_is_min_met( $discount_id ) &&
729
-                wpinv_discount_is_max_met( $discount_id ) &&
730
-                wpinv_discount_item_reqs_met( $discount_id )
724
+                wpinv_is_discount_active($discount_id) &&
725
+                wpinv_check_discount_dates($discount_id) &&
726
+                !wpinv_is_discount_maxed_out($discount_id) &&
727
+                !wpinv_is_discount_used($code, $user, $discount_id) &&
728
+                wpinv_discount_is_min_met($discount_id) &&
729
+                wpinv_discount_is_max_met($discount_id) &&
730
+                wpinv_discount_item_reqs_met($discount_id)
731 731
             ) {
732 732
                 $return = true;
733 733
             }
734
-        } elseif( $set_error ) {
735
-            wpinv_set_error( 'wpinv-discount-error', __( 'This discount is invalid.', 'invoicing' ) );
734
+        } elseif ($set_error) {
735
+            wpinv_set_error('wpinv-discount-error', __('This discount is invalid.', 'invoicing'));
736 736
         }
737 737
     }
738 738
 
739
-    return apply_filters( 'wpinv_is_discount_valid', $return, $discount_id, $code, $user );
739
+    return apply_filters('wpinv_is_discount_valid', $return, $discount_id, $code, $user);
740 740
 }
741 741
 
742
-function wpinv_get_discount_id_by_code( $code ) {
743
-    $discount = wpinv_get_discount_by_code( $code );
744
-    if( $discount ) {
742
+function wpinv_get_discount_id_by_code($code) {
743
+    $discount = wpinv_get_discount_by_code($code);
744
+    if ($discount) {
745 745
         return $discount->ID;
746 746
     }
747 747
     return false;
748 748
 }
749 749
 
750
-function wpinv_get_discounted_amount( $code, $base_price ) {
750
+function wpinv_get_discounted_amount($code, $base_price) {
751 751
     $amount      = $base_price;
752
-    $discount_id = wpinv_get_discount_id_by_code( $code );
752
+    $discount_id = wpinv_get_discount_id_by_code($code);
753 753
 
754
-    if( $discount_id ) {
755
-        $type        = wpinv_get_discount_type( $discount_id );
756
-        $rate        = wpinv_get_discount_amount( $discount_id );
754
+    if ($discount_id) {
755
+        $type        = wpinv_get_discount_type($discount_id);
756
+        $rate        = wpinv_get_discount_amount($discount_id);
757 757
 
758
-        if ( $type == 'flat' ) {
758
+        if ($type == 'flat') {
759 759
             // Set amount
760 760
             $amount = $base_price - $rate;
761
-            if ( $amount < 0 ) {
761
+            if ($amount < 0) {
762 762
                 $amount = 0;
763 763
             }
764 764
 
765 765
         } else {
766 766
             // Percentage discount
767
-            $amount = $base_price - ( $base_price * ( $rate / 100 ) );
767
+            $amount = $base_price - ($base_price * ($rate / 100));
768 768
         }
769 769
 
770 770
     } else {
@@ -773,108 +773,108 @@  discard block
 block discarded – undo
773 773
 
774 774
     }
775 775
 
776
-    return apply_filters( 'wpinv_discounted_amount', $amount );
776
+    return apply_filters('wpinv_discounted_amount', $amount);
777 777
 }
778 778
 
779
-function wpinv_increase_discount_usage( $code ) {
779
+function wpinv_increase_discount_usage($code) {
780 780
 
781
-    $id   = wpinv_get_discount_id_by_code( $code );
782
-    $uses = wpinv_get_discount_uses( $id );
781
+    $id   = wpinv_get_discount_id_by_code($code);
782
+    $uses = wpinv_get_discount_uses($id);
783 783
 
784
-    if ( $uses ) {
784
+    if ($uses) {
785 785
         $uses++;
786 786
     } else {
787 787
         $uses = 1;
788 788
     }
789 789
 
790
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
790
+    update_post_meta($id, '_wpi_discount_uses', $uses);
791 791
 
792
-    do_action( 'wpinv_discount_increase_use_count', $uses, $id, $code );
792
+    do_action('wpinv_discount_increase_use_count', $uses, $id, $code);
793 793
 
794 794
     return $uses;
795 795
 
796 796
 }
797 797
 
798
-function wpinv_decrease_discount_usage( $code ) {
798
+function wpinv_decrease_discount_usage($code) {
799 799
 
800
-    $id   = wpinv_get_discount_id_by_code( $code );
801
-    $uses = wpinv_get_discount_uses( $id );
800
+    $id   = wpinv_get_discount_id_by_code($code);
801
+    $uses = wpinv_get_discount_uses($id);
802 802
 
803
-    if ( $uses ) {
803
+    if ($uses) {
804 804
         $uses--;
805 805
     }
806 806
 
807
-    if ( $uses < 0 ) {
807
+    if ($uses < 0) {
808 808
         $uses = 0;
809 809
     }
810 810
 
811
-    update_post_meta( $id, '_wpi_discount_uses', $uses );
811
+    update_post_meta($id, '_wpi_discount_uses', $uses);
812 812
 
813
-    do_action( 'wpinv_discount_decrease_use_count', $uses, $id, $code );
813
+    do_action('wpinv_discount_decrease_use_count', $uses, $id, $code);
814 814
 
815 815
     return $uses;
816 816
 
817 817
 }
818 818
 
819
-function wpinv_format_discount_rate( $type, $amount ) {
820
-    if ( $type == 'flat' ) {
821
-        return wpinv_price( wpinv_format_amount( $amount ) );
819
+function wpinv_format_discount_rate($type, $amount) {
820
+    if ($type == 'flat') {
821
+        return wpinv_price(wpinv_format_amount($amount));
822 822
     } else {
823 823
         return $amount . '%';
824 824
     }
825 825
 }
826 826
 
827
-function wpinv_set_cart_discount( $code = '' ) {    
828
-    if ( wpinv_multiple_discounts_allowed() ) {
827
+function wpinv_set_cart_discount($code = '') {    
828
+    if (wpinv_multiple_discounts_allowed()) {
829 829
         // Get all active cart discounts
830 830
         $discounts = wpinv_get_cart_discounts();
831 831
     } else {
832 832
         $discounts = false; // Only one discount allowed per purchase, so override any existing
833 833
     }
834 834
 
835
-    if ( $discounts ) {
836
-        $key = array_search( strtolower( $code ), array_map( 'strtolower', $discounts ) );
837
-        if( false !== $key ) {
838
-            unset( $discounts[ $key ] ); // Can't set the same discount more than once
835
+    if ($discounts) {
836
+        $key = array_search(strtolower($code), array_map('strtolower', $discounts));
837
+        if (false !== $key) {
838
+            unset($discounts[$key]); // Can't set the same discount more than once
839 839
         }
840 840
         $discounts[] = $code;
841 841
     } else {
842 842
         $discounts = array();
843 843
         $discounts[] = $code;
844 844
     }
845
-    $discounts = array_values( $discounts );
845
+    $discounts = array_values($discounts);
846 846
     
847 847
     $data = wpinv_get_checkout_session();
848
-    if ( empty( $data ) ) {
848
+    if (empty($data)) {
849 849
         $data = array();
850 850
     } else {
851
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
852
-            $payment_meta['user_info']['discount']  = implode( ',', $discounts );
853
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
851
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
852
+            $payment_meta['user_info']['discount'] = implode(',', $discounts);
853
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
854 854
         }
855 855
     }
856 856
     $data['cart_discounts'] = $discounts;
857 857
     
858
-    wpinv_set_checkout_session( $data );
858
+    wpinv_set_checkout_session($data);
859 859
     
860 860
     return $discounts;
861 861
 }
862 862
 
863
-function wpinv_unset_cart_discount( $code = '' ) {    
863
+function wpinv_unset_cart_discount($code = '') {    
864 864
     $discounts = wpinv_get_cart_discounts();
865 865
 
866
-    if ( $code && !empty( $discounts ) && in_array( $code, $discounts ) ) {
867
-        $key = array_search( $code, $discounts );
868
-        unset( $discounts[ $key ] );
866
+    if ($code && !empty($discounts) && in_array($code, $discounts)) {
867
+        $key = array_search($code, $discounts);
868
+        unset($discounts[$key]);
869 869
             
870 870
         $data = wpinv_get_checkout_session();
871 871
         $data['cart_discounts'] = $discounts;
872
-        if ( !empty( $data['invoice_id'] ) && $payment_meta = wpinv_get_invoice_meta( $data['invoice_id'] ) ) {
873
-            $payment_meta['user_info']['discount']  = !empty( $discounts ) ? implode( ',', $discounts ) : '';
874
-            update_post_meta( $data['invoice_id'], '_wpinv_payment_meta', $payment_meta );
872
+        if (!empty($data['invoice_id']) && $payment_meta = wpinv_get_invoice_meta($data['invoice_id'])) {
873
+            $payment_meta['user_info']['discount'] = !empty($discounts) ? implode(',', $discounts) : '';
874
+            update_post_meta($data['invoice_id'], '_wpinv_payment_meta', $payment_meta);
875 875
         }
876 876
         
877
-        wpinv_set_checkout_session( $data );
877
+        wpinv_set_checkout_session($data);
878 878
     }
879 879
 
880 880
     return $discounts;
@@ -883,27 +883,27 @@  discard block
 block discarded – undo
883 883
 function wpinv_unset_all_cart_discounts() {
884 884
     $data = wpinv_get_checkout_session();
885 885
     
886
-    if ( !empty( $data ) && isset( $data['cart_discounts'] ) ) {
887
-        unset( $data['cart_discounts'] );
886
+    if (!empty($data) && isset($data['cart_discounts'])) {
887
+        unset($data['cart_discounts']);
888 888
         
889
-         wpinv_set_checkout_session( $data );
889
+         wpinv_set_checkout_session($data);
890 890
          return true;
891 891
     }
892 892
     
893 893
     return false;
894 894
 }
895 895
 
896
-function wpinv_get_cart_discounts( $items = array() ) {
896
+function wpinv_get_cart_discounts($items = array()) {
897 897
     $session = wpinv_get_checkout_session();
898 898
     
899
-    $discounts = !empty( $session['cart_discounts'] ) ? $session['cart_discounts'] : false;
899
+    $discounts = !empty($session['cart_discounts']) ? $session['cart_discounts'] : false;
900 900
     return $discounts;
901 901
 }
902 902
 
903
-function wpinv_cart_has_discounts( $items = array() ) {
903
+function wpinv_cart_has_discounts($items = array()) {
904 904
     $ret = false;
905 905
 
906
-    if ( wpinv_get_cart_discounts( $items ) ) {
906
+    if (wpinv_get_cart_discounts($items)) {
907 907
         $ret = true;
908 908
     }
909 909
     
@@ -914,131 +914,131 @@  discard block
 block discarded – undo
914 914
     }
915 915
     */
916 916
 
917
-    return apply_filters( 'wpinv_cart_has_discounts', $ret );
917
+    return apply_filters('wpinv_cart_has_discounts', $ret);
918 918
 }
919 919
 
920
-function wpinv_get_cart_discounted_amount( $items = array(), $discounts = false ) {
920
+function wpinv_get_cart_discounted_amount($items = array(), $discounts = false) {
921 921
     $amount = 0.00;
922
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
922
+    $items  = !empty($items) ? $items : wpinv_get_cart_content_details();
923 923
 
924
-    if ( $items ) {
925
-        $discounts = wp_list_pluck( $items, 'discount' );
924
+    if ($items) {
925
+        $discounts = wp_list_pluck($items, 'discount');
926 926
 
927
-        if ( is_array( $discounts ) ) {
928
-            $discounts = array_map( 'floatval', $discounts );
929
-            $amount    = array_sum( $discounts );
927
+        if (is_array($discounts)) {
928
+            $discounts = array_map('floatval', $discounts);
929
+            $amount    = array_sum($discounts);
930 930
         }
931 931
     }
932 932
 
933
-    return apply_filters( 'wpinv_get_cart_discounted_amount', $amount );
933
+    return apply_filters('wpinv_get_cart_discounted_amount', $amount);
934 934
 }
935 935
 
936
-function wpinv_get_cart_items_discount_amount( $items = array(), $discount = false ) {
937
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
936
+function wpinv_get_cart_items_discount_amount($items = array(), $discount = false) {
937
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
938 938
     
939
-    if ( empty( $discount ) || empty( $items ) ) {
939
+    if (empty($discount) || empty($items)) {
940 940
         return 0;
941 941
     }
942 942
 
943 943
     $amount = 0;
944 944
     
945
-    foreach ( $items as $item ) {
946
-        $amount += wpinv_get_cart_item_discount_amount( $item, $discount );
945
+    foreach ($items as $item) {
946
+        $amount += wpinv_get_cart_item_discount_amount($item, $discount);
947 947
     }
948 948
     
949
-    $amount = wpinv_round_amount( $amount );
949
+    $amount = wpinv_round_amount($amount);
950 950
 
951 951
     return $amount;
952 952
 }
953 953
 
954
-function wpinv_get_cart_item_discount_amount( $item = array(), $discount = false ) {
954
+function wpinv_get_cart_item_discount_amount($item = array(), $discount = false) {
955 955
     global $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
956 956
     
957 957
     $amount = 0;
958 958
 
959
-    if ( empty( $item ) || empty( $item['id'] ) ) {
959
+    if (empty($item) || empty($item['id'])) {
960 960
         return $amount;
961 961
     }
962 962
 
963
-    if ( empty( $item['quantity'] ) ) {
963
+    if (empty($item['quantity'])) {
964 964
         return $amount;
965 965
     }
966 966
 
967
-    if ( empty( $item['options'] ) ) {
967
+    if (empty($item['options'])) {
968 968
         $item['options'] = array();
969 969
     }
970 970
 
971
-    $price            = wpinv_get_cart_item_price( $item['id'], $item, $item['options'] );
971
+    $price            = wpinv_get_cart_item_price($item['id'], $item, $item['options']);
972 972
     $discounted_price = $price;
973 973
 
974 974
     $discounts = false === $discount ? wpinv_get_cart_discounts() : $discount;
975
-    if ( empty( $discounts ) ) {
975
+    if (empty($discounts)) {
976 976
         return $amount;
977 977
     }
978 978
 
979
-    if ( $discounts ) {
980
-        if ( is_array( $discounts ) ) {
981
-            $discounts = array_values( $discounts );
979
+    if ($discounts) {
980
+        if (is_array($discounts)) {
981
+            $discounts = array_values($discounts);
982 982
         } else {
983
-            $discounts = explode( ',', $discounts );
983
+            $discounts = explode(',', $discounts);
984 984
         }
985 985
     }
986 986
 
987
-    if( $discounts ) {
988
-        foreach ( $discounts as $discount ) {
989
-            $code_id = wpinv_get_discount_id_by_code( $discount );
987
+    if ($discounts) {
988
+        foreach ($discounts as $discount) {
989
+            $code_id = wpinv_get_discount_id_by_code($discount);
990 990
 
991 991
             // Check discount exists
992
-            if( ! $code_id ) {
992
+            if (!$code_id) {
993 993
                 continue;
994 994
             }
995 995
 
996
-            $reqs           = wpinv_get_discount_item_reqs( $code_id );
997
-            $excluded_items = wpinv_get_discount_excluded_items( $code_id );
996
+            $reqs           = wpinv_get_discount_item_reqs($code_id);
997
+            $excluded_items = wpinv_get_discount_excluded_items($code_id);
998 998
 
999 999
             // Make sure requirements are set and that this discount shouldn't apply to the whole cart
1000
-            if ( !empty( $reqs ) && wpinv_is_discount_not_global( $code_id ) ) {
1001
-                foreach ( $reqs as $item_id ) {
1002
-                    if ( $item_id == $item['id'] && ! in_array( $item['id'], $excluded_items ) ) {
1003
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1000
+            if (!empty($reqs) && wpinv_is_discount_not_global($code_id)) {
1001
+                foreach ($reqs as $item_id) {
1002
+                    if ($item_id == $item['id'] && !in_array($item['id'], $excluded_items)) {
1003
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1004 1004
                     }
1005 1005
                 }
1006 1006
             } else {
1007 1007
                 // This is a global cart discount
1008
-                if ( !in_array( $item['id'], $excluded_items ) ) {
1009
-                    if ( 'flat' === wpinv_get_discount_type( $code_id ) ) {
1008
+                if (!in_array($item['id'], $excluded_items)) {
1009
+                    if ('flat' === wpinv_get_discount_type($code_id)) {
1010 1010
                         $items_subtotal    = 0.00;
1011 1011
                         $cart_items        = wpinv_get_cart_contents();
1012 1012
                         
1013
-                        foreach ( $cart_items as $cart_item ) {
1014
-                            if ( ! in_array( $cart_item['id'], $excluded_items ) ) {
1015
-                                $options = !empty( $cart_item['options'] ) ? $cart_item['options'] : array();
1016
-                                $item_price      = wpinv_get_cart_item_price( $cart_item['id'], $cart_item, $options );
1013
+                        foreach ($cart_items as $cart_item) {
1014
+                            if (!in_array($cart_item['id'], $excluded_items)) {
1015
+                                $options = !empty($cart_item['options']) ? $cart_item['options'] : array();
1016
+                                $item_price      = wpinv_get_cart_item_price($cart_item['id'], $cart_item, $options);
1017 1017
                                 $items_subtotal += $item_price * $cart_item['quantity'];
1018 1018
                             }
1019 1019
                         }
1020 1020
 
1021
-                        $subtotal_percent  = ( ( $price * $item['quantity'] ) / $items_subtotal );
1022
-                        $code_amount       = wpinv_get_discount_amount( $code_id );
1021
+                        $subtotal_percent  = (($price * $item['quantity']) / $items_subtotal);
1022
+                        $code_amount       = wpinv_get_discount_amount($code_id);
1023 1023
                         $discounted_amount = $code_amount * $subtotal_percent;
1024 1024
                         $discounted_price -= $discounted_amount;
1025 1025
 
1026
-                        $wpinv_flat_discount_total += round( $discounted_amount, wpinv_currency_decimal_filter() );
1026
+                        $wpinv_flat_discount_total += round($discounted_amount, wpinv_currency_decimal_filter());
1027 1027
 
1028
-                        if ( $wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount ) {
1028
+                        if ($wpinv_is_last_cart_item && $wpinv_flat_discount_total < $code_amount) {
1029 1029
                             $adjustment = $code_amount - $wpinv_flat_discount_total;
1030 1030
                             $discounted_price -= $adjustment;
1031 1031
                         }
1032 1032
                     } else {
1033
-                        $discounted_price -= $price - wpinv_get_discounted_amount( $discount, $price );
1033
+                        $discounted_price -= $price - wpinv_get_discounted_amount($discount, $price);
1034 1034
                     }
1035 1035
                 }
1036 1036
             }
1037 1037
         }
1038 1038
 
1039
-        $amount = ( $price - apply_filters( 'wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price ) );
1039
+        $amount = ($price - apply_filters('wpinv_get_cart_item_discounted_amount', $discounted_price, $discounts, $item, $price));
1040 1040
 
1041
-        if ( 'flat' !== wpinv_get_discount_type( $code_id ) ) {
1041
+        if ('flat' !== wpinv_get_discount_type($code_id)) {
1042 1042
             $amount = $amount * $item['quantity'];
1043 1043
         }
1044 1044
     }
@@ -1046,59 +1046,59 @@  discard block
 block discarded – undo
1046 1046
     return $amount;
1047 1047
 }
1048 1048
 
1049
-function wpinv_cart_discounts_html( $items = array() ) {
1050
-    echo wpinv_get_cart_discounts_html( $items );
1049
+function wpinv_cart_discounts_html($items = array()) {
1050
+    echo wpinv_get_cart_discounts_html($items);
1051 1051
 }
1052 1052
 
1053
-function wpinv_get_cart_discounts_html( $items = array(), $discounts = false ) {
1053
+function wpinv_get_cart_discounts_html($items = array(), $discounts = false) {
1054 1054
     global $wpi_cart_columns;
1055 1055
     
1056
-    $items  = !empty( $items ) ? $items : wpinv_get_cart_content_details();
1056
+    $items = !empty($items) ? $items : wpinv_get_cart_content_details();
1057 1057
     
1058
-    if ( !$discounts ) {
1059
-        $discounts = wpinv_get_cart_discounts( $items );
1058
+    if (!$discounts) {
1059
+        $discounts = wpinv_get_cart_discounts($items);
1060 1060
     }
1061 1061
 
1062
-    if ( !$discounts ) {
1062
+    if (!$discounts) {
1063 1063
         return;
1064 1064
     }
1065 1065
     
1066
-    $discounts = is_array( $discounts ) ? $discounts : array( $discounts );
1066
+    $discounts = is_array($discounts) ? $discounts : array($discounts);
1067 1067
     
1068 1068
     $html = '';
1069 1069
 
1070
-    foreach ( $discounts as $discount ) {
1071
-        $discount_id    = wpinv_get_discount_id_by_code( $discount );
1072
-        $discount_value = wpinv_get_discount_amount( $discount_id );
1073
-        $rate           = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), $discount_value );
1074
-        $amount         = wpinv_get_cart_items_discount_amount( $items, $discount );
1075
-        $remove_btn     = '<a title="' . esc_attr__( 'Remove discount', 'invoicing' ) . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1070
+    foreach ($discounts as $discount) {
1071
+        $discount_id    = wpinv_get_discount_id_by_code($discount);
1072
+        $discount_value = wpinv_get_discount_amount($discount_id);
1073
+        $rate           = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), $discount_value);
1074
+        $amount         = wpinv_get_cart_items_discount_amount($items, $discount);
1075
+        $remove_btn     = '<a title="' . esc_attr__('Remove discount', 'invoicing') . '" data-code="' . $discount . '" data-value="' . $discount_value . '" class="wpi-discount-remove" href="javascript:void(0);">[<i class="fa fa-times" aria-hidden="true"></i>]</a> ';
1076 1076
         
1077 1077
         $html .= '<tr class="wpinv_cart_footer_row wpinv_cart_discount_row">';
1078 1078
         ob_start();
1079
-        do_action( 'wpinv_checkout_table_discount_first', $items );
1079
+        do_action('wpinv_checkout_table_discount_first', $items);
1080 1080
         $html .= ob_get_clean();
1081
-        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label( $discount, $rate, false ) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price( wpinv_format_amount( $amount ) ) . '</span></td>';
1081
+        $html .= '<td class="wpinv_cart_discount_label text-right" colspan="' . $wpi_cart_columns . '">' . $remove_btn . '<strong>' . wpinv_cart_discount_label($discount, $rate, false) . '</strong></td><td class="wpinv_cart_discount text-right"><span data-discount="' . $amount . '" class="wpinv_cart_discount_amount">&ndash;' . wpinv_price(wpinv_format_amount($amount)) . '</span></td>';
1082 1082
         ob_start();
1083
-        do_action( 'wpinv_checkout_table_discount_last', $items );
1083
+        do_action('wpinv_checkout_table_discount_last', $items);
1084 1084
         $html .= ob_get_clean();
1085 1085
         $html .= '</tr>';
1086 1086
     }
1087 1087
 
1088
-    return apply_filters( 'wpinv_get_cart_discounts_html', $html, $discounts, $rate );
1088
+    return apply_filters('wpinv_get_cart_discounts_html', $html, $discounts, $rate);
1089 1089
 }
1090 1090
 
1091
-function wpinv_display_cart_discount( $formatted = false, $echo = false ) {
1091
+function wpinv_display_cart_discount($formatted = false, $echo = false) {
1092 1092
     $discounts = wpinv_get_cart_discounts();
1093 1093
 
1094
-    if ( empty( $discounts ) ) {
1094
+    if (empty($discounts)) {
1095 1095
         return false;
1096 1096
     }
1097 1097
 
1098
-    $discount_id  = wpinv_get_discount_id_by_code( $discounts[0] );
1099
-    $amount       = wpinv_format_discount_rate( wpinv_get_discount_type( $discount_id ), wpinv_get_discount_amount( $discount_id ) );
1098
+    $discount_id  = wpinv_get_discount_id_by_code($discounts[0]);
1099
+    $amount       = wpinv_format_discount_rate(wpinv_get_discount_type($discount_id), wpinv_get_discount_amount($discount_id));
1100 1100
 
1101
-    if ( $echo ) {
1101
+    if ($echo) {
1102 1102
         echo $amount;
1103 1103
     }
1104 1104
 
@@ -1106,135 +1106,135 @@  discard block
 block discarded – undo
1106 1106
 }
1107 1107
 
1108 1108
 function wpinv_remove_cart_discount() {
1109
-    if ( !isset( $_GET['discount_id'] ) || ! isset( $_GET['discount_code'] ) ) {
1109
+    if (!isset($_GET['discount_id']) || !isset($_GET['discount_code'])) {
1110 1110
         return;
1111 1111
     }
1112 1112
 
1113
-    do_action( 'wpinv_pre_remove_cart_discount', absint( $_GET['discount_id'] ) );
1113
+    do_action('wpinv_pre_remove_cart_discount', absint($_GET['discount_id']));
1114 1114
 
1115
-    wpinv_unset_cart_discount( urldecode( $_GET['discount_code'] ) );
1115
+    wpinv_unset_cart_discount(urldecode($_GET['discount_code']));
1116 1116
 
1117
-    do_action( 'wpinv_post_remove_cart_discount', absint( $_GET['discount_id'] ) );
1117
+    do_action('wpinv_post_remove_cart_discount', absint($_GET['discount_id']));
1118 1118
 
1119
-    wp_redirect( wpinv_get_checkout_uri() ); wpinv_die();
1119
+    wp_redirect(wpinv_get_checkout_uri()); wpinv_die();
1120 1120
 }
1121
-add_action( 'wpinv_remove_cart_discount', 'wpinv_remove_cart_discount' );
1121
+add_action('wpinv_remove_cart_discount', 'wpinv_remove_cart_discount');
1122 1122
 
1123
-function wpinv_maybe_remove_cart_discount( $cart_key = 0 ) {
1123
+function wpinv_maybe_remove_cart_discount($cart_key = 0) {
1124 1124
     $discounts = wpinv_get_cart_discounts();
1125 1125
 
1126
-    if ( !$discounts ) {
1126
+    if (!$discounts) {
1127 1127
         return;
1128 1128
     }
1129 1129
 
1130
-    foreach ( $discounts as $discount ) {
1131
-        if ( !wpinv_is_discount_valid( $discount ) ) {
1132
-            wpinv_unset_cart_discount( $discount );
1130
+    foreach ($discounts as $discount) {
1131
+        if (!wpinv_is_discount_valid($discount)) {
1132
+            wpinv_unset_cart_discount($discount);
1133 1133
         }
1134 1134
     }
1135 1135
 }
1136
-add_action( 'wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount' );
1136
+add_action('wpinv_post_remove_from_cart', 'wpinv_maybe_remove_cart_discount');
1137 1137
 
1138 1138
 function wpinv_multiple_discounts_allowed() {
1139
-    $ret = wpinv_get_option( 'allow_multiple_discounts', false );
1140
-    return (bool) apply_filters( 'wpinv_multiple_discounts_allowed', $ret );
1139
+    $ret = wpinv_get_option('allow_multiple_discounts', false);
1140
+    return (bool)apply_filters('wpinv_multiple_discounts_allowed', $ret);
1141 1141
 }
1142 1142
 
1143 1143
 function wpinv_listen_for_cart_discount() {
1144 1144
     global $wpi_session;
1145 1145
     
1146
-    if ( empty( $_REQUEST['discount'] ) || is_array( $_REQUEST['discount'] ) ) {
1146
+    if (empty($_REQUEST['discount']) || is_array($_REQUEST['discount'])) {
1147 1147
         return;
1148 1148
     }
1149 1149
 
1150
-    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount'] );
1150
+    $code = preg_replace('/[^a-zA-Z0-9-_]+/', '', $_REQUEST['discount']);
1151 1151
 
1152
-    $wpi_session->set( 'preset_discount', $code );
1152
+    $wpi_session->set('preset_discount', $code);
1153 1153
 }
1154 1154
 //add_action( 'init', 'wpinv_listen_for_cart_discount', 0 );
1155 1155
 
1156 1156
 function wpinv_apply_preset_discount() {
1157 1157
     global $wpi_session;
1158 1158
     
1159
-    $code = $wpi_session->get( 'preset_discount' );
1159
+    $code = $wpi_session->get('preset_discount');
1160 1160
 
1161
-    if ( !$code ) {
1161
+    if (!$code) {
1162 1162
         return;
1163 1163
     }
1164 1164
 
1165
-    if ( !wpinv_is_discount_valid( $code, '', false ) ) {
1165
+    if (!wpinv_is_discount_valid($code, '', false)) {
1166 1166
         return;
1167 1167
     }
1168 1168
     
1169
-    $code = apply_filters( 'wpinv_apply_preset_discount', $code );
1169
+    $code = apply_filters('wpinv_apply_preset_discount', $code);
1170 1170
 
1171
-    wpinv_set_cart_discount( $code );
1171
+    wpinv_set_cart_discount($code);
1172 1172
 
1173
-    $wpi_session->set( 'preset_discount', null );
1173
+    $wpi_session->set('preset_discount', null);
1174 1174
 }
1175 1175
 //add_action( 'init', 'wpinv_apply_preset_discount', 999 );
1176 1176
 
1177
-function wpinv_get_discount_label( $code, $echo = true ) {
1178
-    $label = wp_sprintf( __( 'Discount%1$s', 'invoicing' ), ( $code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)': '' ) );
1179
-    $label = apply_filters( 'wpinv_get_discount_label', $label, $code );
1177
+function wpinv_get_discount_label($code, $echo = true) {
1178
+    $label = wp_sprintf(__('Discount%1$s', 'invoicing'), ($code != '' && $code != 'none' ? ' (<code>' . $code . '</code>)' : ''));
1179
+    $label = apply_filters('wpinv_get_discount_label', $label, $code);
1180 1180
 
1181
-    if ( $echo ) {
1181
+    if ($echo) {
1182 1182
         echo $label;
1183 1183
     } else {
1184 1184
         return $label;
1185 1185
     }
1186 1186
 }
1187 1187
 
1188
-function wpinv_cart_discount_label( $code, $rate, $echo = true ) {
1189
-    $label = wp_sprintf( __( 'Discount: %s', 'invoicing' ), $code );
1190
-    $label = apply_filters( 'wpinv_cart_discount_label', $label, $code, $rate );
1188
+function wpinv_cart_discount_label($code, $rate, $echo = true) {
1189
+    $label = wp_sprintf(__('Discount: %s', 'invoicing'), $code);
1190
+    $label = apply_filters('wpinv_cart_discount_label', $label, $code, $rate);
1191 1191
 
1192
-    if ( $echo ) {
1192
+    if ($echo) {
1193 1193
         echo $label;
1194 1194
     } else {
1195 1195
         return $label;
1196 1196
     }
1197 1197
 }
1198 1198
 
1199
-function wpinv_check_delete_discount( $check, $post, $force_delete ) {
1200
-    if ( $post->post_type == 'wpi_discount' && wpinv_get_discount_uses( $post->ID ) > 0 ) {
1199
+function wpinv_check_delete_discount($check, $post, $force_delete) {
1200
+    if ($post->post_type == 'wpi_discount' && wpinv_get_discount_uses($post->ID) > 0) {
1201 1201
         return true;
1202 1202
     }
1203 1203
     
1204 1204
     return $check;
1205 1205
 }
1206
-add_filter( 'pre_delete_post', 'wpinv_check_delete_discount', 10, 3 );
1206
+add_filter('pre_delete_post', 'wpinv_check_delete_discount', 10, 3);
1207 1207
 
1208 1208
 function wpinv_checkout_form_validate_discounts() {
1209 1209
     global $wpi_checkout_id;
1210 1210
     
1211 1211
     $discounts = wpinv_get_cart_discounts();
1212 1212
     
1213
-    if ( !empty( $discounts ) ) {
1213
+    if (!empty($discounts)) {
1214 1214
         $invalid = false;
1215 1215
         
1216
-        foreach ( $discounts as $key => $code ) {
1217
-            if ( !wpinv_is_discount_valid( $code, (int)wpinv_get_user_id( $wpi_checkout_id ) ) ) {
1216
+        foreach ($discounts as $key => $code) {
1217
+            if (!wpinv_is_discount_valid($code, (int)wpinv_get_user_id($wpi_checkout_id))) {
1218 1218
                 $invalid = true;
1219 1219
                 
1220
-                wpinv_unset_cart_discount( $code );
1220
+                wpinv_unset_cart_discount($code);
1221 1221
             }
1222 1222
         }
1223 1223
         
1224
-        if ( $invalid ) {
1224
+        if ($invalid) {
1225 1225
             $errors = wpinv_get_errors();
1226
-            $error  = !empty( $errors['wpinv-discount-error'] ) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
-            $error  .= __( 'The discount has been removed from cart.', 'invoicing' );
1228
-            wpinv_set_error( 'wpinv-discount-error', $error );
1226
+            $error  = !empty($errors['wpinv-discount-error']) ? $errors['wpinv-discount-error'] . ' ' : '';
1227
+            $error .= __('The discount has been removed from cart.', 'invoicing');
1228
+            wpinv_set_error('wpinv-discount-error', $error);
1229 1229
             
1230
-            wpinv_recalculate_tax( true );
1230
+            wpinv_recalculate_tax(true);
1231 1231
         }
1232 1232
     }
1233 1233
 }
1234
-add_action( 'wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10 );
1234
+add_action('wpinv_before_checkout_form', 'wpinv_checkout_form_validate_discounts', -10);
1235 1235
 
1236 1236
 function wpinv_discount_amount() {
1237 1237
     $output = 0.00;
1238 1238
     
1239
-    return apply_filters( 'wpinv_discount_amount', $output );
1239
+    return apply_filters('wpinv_discount_amount', $output);
1240 1240
 }
1241 1241
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 1 patch
Spacing   +284 added lines, -284 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = new WPInv_Item( $value );
14
+            $item = new WPInv_Item($value);
15 15
 
16
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
16
+            if (!empty($item) && $item->post_type == 'wpi_item') {
17 17
                 return $item;
18 18
             }
19 19
             return false;
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 
23 23
         case 'slug':
24 24
         case 'name':
25
-            $posts = get_posts( array(
25
+            $posts = get_posts(array(
26 26
                 'post_type'      => 'wpi_item',
27 27
                 'name'           => $value,
28 28
                 'posts_per_page' => 1,
29 29
                 'post_status'    => 'any'
30
-            ) );
30
+            ));
31 31
 
32 32
             break;
33 33
         case 'custom_id':
34
-            if ( empty( $value ) || empty( $type ) ) {
34
+            if (empty($value) || empty($type)) {
35 35
                 return false;
36 36
             }
37 37
             
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
                 'post_status'    => 'any',
52 52
                 'orderby'        => 'ID',
53 53
                 'order'          => 'ASC',
54
-                'meta_query'     => array( $meta_query )
54
+                'meta_query'     => array($meta_query)
55 55
             );
56 56
             
57
-            $posts = get_posts( $args );
57
+            $posts = get_posts($args);
58 58
 
59 59
             break;
60 60
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
             return false;
63 63
     }
64 64
     
65
-    if ( !empty( $posts[0] ) ) {
66
-        $item = new WPInv_Item( $posts[0]->ID );
65
+    if (!empty($posts[0])) {
66
+        $item = new WPInv_Item($posts[0]->ID);
67 67
 
68
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
68
+        if (!empty($item) && $item->post_type == 'wpi_item') {
69 69
             return $item;
70 70
         }
71 71
     }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
     return false;
74 74
 }
75 75
 
76
-function wpinv_get_item( $item = 0 ) {
77
-    if ( is_numeric( $item ) ) {
78
-        $item = get_post( $item );
79
-        if ( ! $item || 'wpi_item' !== $item->post_type )
76
+function wpinv_get_item($item = 0) {
77
+    if (is_numeric($item)) {
78
+        $item = get_post($item);
79
+        if (!$item || 'wpi_item' !== $item->post_type)
80 80
             return null;
81 81
         return $item;
82 82
     }
@@ -89,150 +89,150 @@  discard block
 block discarded – undo
89 89
 
90 90
     $item = get_posts($args);
91 91
 
92
-    if ( $item ) {
92
+    if ($item) {
93 93
         return $item[0];
94 94
     }
95 95
 
96 96
     return null;
97 97
 }
98 98
 
99
-function wpinv_is_free_item( $item_id = 0 ) {
100
-    if( empty( $item_id ) ) {
99
+function wpinv_is_free_item($item_id = 0) {
100
+    if (empty($item_id)) {
101 101
         return false;
102 102
     }
103 103
 
104
-    $item = new WPInv_Item( $item_id );
104
+    $item = new WPInv_Item($item_id);
105 105
     
106 106
     return $item->is_free();
107 107
 }
108 108
 
109
-function wpinv_item_is_editable( $item = 0 ) {
110
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
109
+function wpinv_item_is_editable($item = 0) {
110
+    if (!empty($item) && is_a($item, 'WP_Post')) {
111 111
         $item = $item->ID;
112 112
     }
113 113
         
114
-    if ( empty( $item ) ) {
114
+    if (empty($item)) {
115 115
         return true;
116 116
     }
117 117
 
118
-    $item = new WPInv_Item( $item );
118
+    $item = new WPInv_Item($item);
119 119
     
120
-    return (bool) $item->is_editable();
120
+    return (bool)$item->is_editable();
121 121
 }
122 122
 
123
-function wpinv_get_item_price( $item_id = 0 ) {
124
-    if( empty( $item_id ) ) {
123
+function wpinv_get_item_price($item_id = 0) {
124
+    if (empty($item_id)) {
125 125
         return false;
126 126
     }
127 127
 
128
-    $item = new WPInv_Item( $item_id );
128
+    $item = new WPInv_Item($item_id);
129 129
     
130 130
     return $item->get_price();
131 131
 }
132 132
 
133
-function wpinv_is_recurring_item( $item_id = 0 ) {
134
-    if( empty( $item_id ) ) {
133
+function wpinv_is_recurring_item($item_id = 0) {
134
+    if (empty($item_id)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $item = new WPInv_Item( $item_id );
138
+    $item = new WPInv_Item($item_id);
139 139
     
140 140
     return $item->is_recurring();
141 141
 }
142 142
 
143
-function wpinv_item_price( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_item_price($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $price = wpinv_get_item_price( $item_id );
149
-    $price = wpinv_price( wpinv_format_amount( $price ) );
148
+    $price = wpinv_get_item_price($item_id);
149
+    $price = wpinv_price(wpinv_format_amount($price));
150 150
     
151
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
151
+    return apply_filters('wpinv_item_price', $price, $item_id);
152 152
 }
153 153
 
154
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_item_show_price($item_id = 0, $echo = true) {
155
+    if (empty($item_id)) {
156 156
         $item_id = get_the_ID();
157 157
     }
158 158
 
159
-    $price = wpinv_item_price( $item_id );
159
+    $price = wpinv_item_price($item_id);
160 160
 
161
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
161
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
162 162
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
163
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
163
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
164 164
 
165
-    if ( $echo ) {
165
+    if ($echo) {
166 166
         echo $formatted_price;
167 167
     } else {
168 168
         return $formatted_price;
169 169
     }
170 170
 }
171 171
 
172
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
173
-    if ( is_null( $amount_override ) ) {
174
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
172
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
173
+    if (is_null($amount_override)) {
174
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
175 175
     } else {
176 176
         $original_price = $amount_override;
177 177
     }
178 178
     
179 179
     $price = $original_price;
180 180
 
181
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
181
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_custom_singular_name( $item_id ) {
185
-    if( empty( $item_id ) ) {
184
+function wpinv_item_custom_singular_name($item_id) {
185
+    if (empty($item_id)) {
186 186
         return false;
187 187
     }
188 188
 
189
-    $item = new WPInv_Item( $item_id );
189
+    $item = new WPInv_Item($item_id);
190 190
     
191 191
     return $item->get_custom_singular_name();
192 192
 }
193 193
 
194 194
 function wpinv_get_item_types() {
195 195
     $item_types = array(
196
-            'custom'    => __( 'Standard', 'invoicing' ),
197
-            'fee'       => __( 'Fee', 'invoicing' ),
196
+            'custom'    => __('Standard', 'invoicing'),
197
+            'fee'       => __('Fee', 'invoicing'),
198 198
         );
199
-    return apply_filters( 'wpinv_get_item_types', $item_types );
199
+    return apply_filters('wpinv_get_item_types', $item_types);
200 200
 }
201 201
 
202 202
 function wpinv_item_types() {
203 203
     $item_types = wpinv_get_item_types();
204 204
     
205
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
205
+    return (!empty($item_types) ? array_keys($item_types) : array());
206 206
 }
207 207
 
208
-function wpinv_get_item_type( $item_id ) {
209
-    if( empty( $item_id ) ) {
208
+function wpinv_get_item_type($item_id) {
209
+    if (empty($item_id)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    $item = new WPInv_Item( $item_id );
213
+    $item = new WPInv_Item($item_id);
214 214
     
215 215
     return $item->get_type();
216 216
 }
217 217
 
218
-function wpinv_item_type( $item_id ) {
218
+function wpinv_item_type($item_id) {
219 219
     $item_types = wpinv_get_item_types();
220 220
     
221
-    $item_type = wpinv_get_item_type( $item_id );
221
+    $item_type = wpinv_get_item_type($item_id);
222 222
     
223
-    if ( empty( $item_type ) ) {
223
+    if (empty($item_type)) {
224 224
         $item_type = '-';
225 225
     }
226 226
     
227
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
227
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
228 228
 
229
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
229
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
230 230
 }
231 231
 
232
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
232
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
233 233
     global $wpinv_logs;
234 234
     
235
-    if ( empty( $wpinv_logs ) ) {
235
+    if (empty($wpinv_logs)) {
236 236
         return false;
237 237
     }
238 238
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         'log_type'		=> 'wpi_item'
242 242
     );
243 243
 
244
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
244
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
245 245
 
246 246
     $log_meta = array(
247 247
         'user_info'	=> $user_info,
@@ -251,257 +251,257 @@  discard block
 block discarded – undo
251 251
         'invoice_id'=> $invoice_id,
252 252
     );
253 253
 
254
-    $wpinv_logs->insert_log( $log_data, $log_meta );
254
+    $wpinv_logs->insert_log($log_data, $log_meta);
255 255
 }
256 256
 
257
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
258
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
257
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
258
+    if ('wpi_item' !== get_post_type($item_id))
259 259
         return;
260 260
 
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
267 267
     // Remove all log entries related to this item
268
-    $wpinv_logs->delete_logs( $item_id );
268
+    $wpinv_logs->delete_logs($item_id);
269 269
 }
270
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
270
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
271 271
 
272
-function wpinv_get_random_item( $post_ids = true ) {
273
-    wpinv_get_random_items( 1, $post_ids );
272
+function wpinv_get_random_item($post_ids = true) {
273
+    wpinv_get_random_items(1, $post_ids);
274 274
 }
275 275
 
276
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
277
-    if ( $post_ids ) {
278
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
276
+function wpinv_get_random_items($num = 3, $post_ids = true) {
277
+    if ($post_ids) {
278
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
279 279
     } else {
280
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
280
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
281 281
     }
282 282
     
283
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
283
+    $args = apply_filters('wpinv_get_random_items', $args);
284 284
     
285
-    return get_posts( $args );
285
+    return get_posts($args);
286 286
 }
287 287
 
288
-function wpinv_get_item_token( $url = '' ) {
288
+function wpinv_get_item_token($url = '') {
289 289
     $args    = array();
290
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
291
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
290
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
291
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
292 292
 
293
-    $parts   = parse_url( $url );
293
+    $parts   = parse_url($url);
294 294
     $options = array();
295 295
 
296
-    if ( isset( $parts['query'] ) ) {
297
-        wp_parse_str( $parts['query'], $query_args );
296
+    if (isset($parts['query'])) {
297
+        wp_parse_str($parts['query'], $query_args);
298 298
 
299
-        if ( ! empty( $query_args['o'] ) ) {
300
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
299
+        if (!empty($query_args['o'])) {
300
+            $options = explode(':', rawurldecode($query_args['o']));
301 301
 
302
-            if ( in_array( 'ip', $options ) ) {
302
+            if (in_array('ip', $options)) {
303 303
                 $args['ip'] = wpinv_get_ip();
304 304
             }
305 305
 
306
-            if ( in_array( 'ua', $options ) ) {
306
+            if (in_array('ua', $options)) {
307 307
                 $ua = wpinv_get_user_agent();
308
-                $args['user_agent'] = rawurlencode( $ua );
308
+                $args['user_agent'] = rawurlencode($ua);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
313
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
314 314
 
315 315
     $args['secret'] = $secret;
316 316
     $args['token']  = false;
317 317
 
318
-    $url   = add_query_arg( $args, $url );
319
-    $parts = parse_url( $url );
318
+    $url   = add_query_arg($args, $url);
319
+    $parts = parse_url($url);
320 320
 
321
-    if ( ! isset( $parts['path'] ) ) {
321
+    if (!isset($parts['path'])) {
322 322
         $parts['path'] = '';
323 323
     }
324 324
 
325
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
325
+    $token = md5($parts['path'] . '?' . $parts['query']);
326 326
 
327 327
     return $token;
328 328
 }
329 329
 
330
-function wpinv_validate_url_token( $url = '' ) {
330
+function wpinv_validate_url_token($url = '') {
331 331
     $ret   = false;
332
-    $parts = parse_url( $url );
332
+    $parts = parse_url($url);
333 333
 
334
-    if ( isset( $parts['query'] ) ) {
335
-        wp_parse_str( $parts['query'], $query_args );
334
+    if (isset($parts['query'])) {
335
+        wp_parse_str($parts['query'], $query_args);
336 336
 
337
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
337
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
338 338
             'item',
339 339
             'ttl',
340 340
             'token'
341
-        ) );
341
+        ));
342 342
 
343 343
         $remove = array();
344 344
 
345
-        foreach( $query_args as $key => $value ) {
346
-            if( false === in_array( $key, $allowed ) ) {
345
+        foreach ($query_args as $key => $value) {
346
+            if (false === in_array($key, $allowed)) {
347 347
                 $remove[] = $key;
348 348
             }
349 349
         }
350 350
 
351
-        if( ! empty( $remove ) ) {
352
-            $url = remove_query_arg( $remove, $url );
351
+        if (!empty($remove)) {
352
+            $url = remove_query_arg($remove, $url);
353 353
         }
354 354
 
355
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
356
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
355
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
356
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
357 357
         }
358 358
 
359
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
359
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
360 360
             $ret = true;
361 361
         }
362 362
 
363 363
     }
364 364
 
365
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
365
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
366 366
 }
367 367
 
368
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
368
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
369 369
     $cart_items = wpinv_get_cart_contents();
370 370
 
371 371
     $ret = false;
372 372
 
373
-    if ( is_array( $cart_items ) ) {
374
-        foreach ( $cart_items as $item ) {
375
-            if ( $item['id'] == $item_id ) {
373
+    if (is_array($cart_items)) {
374
+        foreach ($cart_items as $item) {
375
+            if ($item['id'] == $item_id) {
376 376
                 $ret = true;
377 377
                 break;
378 378
             }
379 379
         }
380 380
     }
381 381
 
382
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
382
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
383 383
 }
384 384
 
385
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
385
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
386 386
     $tax = 0;
387
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
388
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
389
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
387
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
388
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
389
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
390 390
 
391
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
391
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
392 392
     }
393 393
 
394
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
394
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
395 395
 }
396 396
 
397
-function wpinv_cart_item_price( $item ) {
397
+function wpinv_cart_item_price($item) {
398 398
     $use_taxes  = wpinv_use_taxes();
399
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
400
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
401
-    $options    = isset( $item['options'] ) ? $item['options'] : array();
402
-    $price_id   = isset( $options['price_id'] ) ? $options['price_id'] : false;
403
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
404
-    
405
-    if ( !wpinv_is_free_item( $item_id, $price_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
406
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
399
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
400
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
401
+    $options    = isset($item['options']) ? $item['options'] : array();
402
+    $price_id   = isset($options['price_id']) ? $options['price_id'] : false;
403
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
404
+    
405
+    if (!wpinv_is_free_item($item_id, $price_id) && !wpinv_item_is_tax_exclusive($item_id)) {
406
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
407 407
             $price += $tax;
408 408
         }
409 409
         
410
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
410
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
411 411
             $price -= $tax;
412 412
         }        
413 413
     }
414 414
 
415
-    $price = wpinv_price( wpinv_format_amount( $price ) );
415
+    $price = wpinv_price(wpinv_format_amount($price));
416 416
 
417
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
417
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
418 418
 }
419 419
 
420
-function wpinv_cart_item_subtotal( $item ) {
421
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
422
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
420
+function wpinv_cart_item_subtotal($item) {
421
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
422
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
423 423
 
424
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
424
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
425 425
 }
426 426
 
427
-function wpinv_cart_item_tax( $item ) {
427
+function wpinv_cart_item_tax($item) {
428 428
     $tax        = '';
429 429
     $tax_rate   = '';
430 430
     
431
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
432
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
433
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
434
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
431
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
432
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
433
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
434
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
435 435
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
436 436
     }
437 437
     
438
-    $tax        = $tax . $tax_rate;
438
+    $tax = $tax . $tax_rate;
439 439
     
440
-    if ( $tax === '' ) {
440
+    if ($tax === '') {
441 441
         $tax = 0; // Zero tax
442 442
     }
443 443
 
444
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
444
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
445 445
 }
446 446
 
447
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
447
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
448 448
     $price = 0;
449 449
     
450 450
     // Set custom price
451
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
451
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
452 452
         $price = $cart_item['custom_price'];
453 453
     } else {
454
-        $variable_prices = wpinv_has_variable_prices( $item_id );
454
+        $variable_prices = wpinv_has_variable_prices($item_id);
455 455
 
456
-        if ( $variable_prices ) {
457
-            $prices = wpinv_get_variable_prices( $item_id );
456
+        if ($variable_prices) {
457
+            $prices = wpinv_get_variable_prices($item_id);
458 458
 
459
-            if ( $prices ) {
460
-                if( ! empty( $options ) ) {
461
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
459
+            if ($prices) {
460
+                if (!empty($options)) {
461
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
462 462
                 } else {
463 463
                     $price = false;
464 464
                 }
465 465
             }
466 466
         }
467 467
 
468
-        if( ! $variable_prices || false === $price ) {
469
-            if($cart_item['item_price'] > 0){
468
+        if (!$variable_prices || false === $price) {
469
+            if ($cart_item['item_price'] > 0) {
470 470
                 $price = $cart_item['item_price'];
471 471
             } else {
472 472
                 // Get the standard Item price if not using variable prices
473
-                $price = wpinv_get_item_price( $item_id );
473
+                $price = wpinv_get_item_price($item_id);
474 474
             }
475 475
         }
476 476
     }
477 477
 
478
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
479
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
478
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
479
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
480 480
     }
481 481
 
482
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
482
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
483 483
 }
484 484
 
485
-function wpinv_get_cart_item_price_id( $item = array() ) {
486
-    if( isset( $item['item_number'] ) ) {
487
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
485
+function wpinv_get_cart_item_price_id($item = array()) {
486
+    if (isset($item['item_number'])) {
487
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
488 488
     } else {
489
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
489
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
490 490
     }
491 491
     return $price_id;
492 492
 }
493 493
 
494
-function wpinv_get_cart_item_price_name( $item = array() ) {
495
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
496
-    $prices   = wpinv_get_variable_prices( $item['id'] );
497
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
498
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
494
+function wpinv_get_cart_item_price_name($item = array()) {
495
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
496
+    $prices   = wpinv_get_variable_prices($item['id']);
497
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
498
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
499 499
 }
500 500
 
501
-function wpinv_get_cart_item_name( $item = array() ) {
502
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
501
+function wpinv_get_cart_item_name($item = array()) {
502
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
503 503
 
504
-    if ( empty( $item_title ) ) {
504
+    if (empty($item_title)) {
505 505
         $item_title = $item['id'];
506 506
     }
507 507
 
@@ -511,23 +511,23 @@  discard block
 block discarded – undo
511 511
     }
512 512
     */
513 513
 
514
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
514
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
515 515
 }
516 516
 
517
-function wpinv_has_variable_prices( $item_id = 0 ) {
517
+function wpinv_has_variable_prices($item_id = 0) {
518 518
     return false;
519 519
 }
520 520
 
521
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
521
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
522 522
     $cart_items = wpinv_get_cart_contents();
523 523
 
524
-    if ( !is_array( $cart_items ) ) {
524
+    if (!is_array($cart_items)) {
525 525
         return false; // Empty cart
526 526
     } else {
527
-        foreach ( $cart_items as $position => $item ) {
528
-            if ( $item['id'] == $item_id ) {
529
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
530
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
527
+        foreach ($cart_items as $position => $item) {
528
+            if ($item['id'] == $item_id) {
529
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
530
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
531 531
                         return $position;
532 532
                     }
533 533
                 } else {
@@ -540,80 +540,80 @@  discard block
 block discarded – undo
540 540
     return false; // Not found
541 541
 }
542 542
 
543
-function wpinv_get_cart_item_quantity( $item ) {
544
-    if ( wpinv_item_quantities_enabled() ) {
545
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
543
+function wpinv_get_cart_item_quantity($item) {
544
+    if (wpinv_item_quantities_enabled()) {
545
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
546 546
     } else {
547 547
         $quantity = 1;
548 548
     }
549 549
     
550
-    if ( $quantity < 1 ) {
550
+    if ($quantity < 1) {
551 551
         $quantity = 1;
552 552
     }
553 553
     
554
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
554
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
555 555
 }
556 556
 
557
-function wpinv_get_item_suffix( $item, $html = true ) {
558
-    if ( empty( $item ) ) {
557
+function wpinv_get_item_suffix($item, $html = true) {
558
+    if (empty($item)) {
559 559
         return NULL;
560 560
     }
561 561
     
562
-    if ( is_int( $item ) ) {
563
-        $item = new WPInv_Item( $item );
562
+    if (is_int($item)) {
563
+        $item = new WPInv_Item($item);
564 564
     }
565 565
     
566
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
566
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
567 567
         return NULL;
568 568
     }
569 569
     
570
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
570
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
571 571
     
572
-    if ( !$html && $suffix ) {
573
-        $suffix = strip_tags( $suffix );
572
+    if (!$html && $suffix) {
573
+        $suffix = strip_tags($suffix);
574 574
     }
575 575
     
576
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
576
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
577 577
 }
578 578
 
579
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
580
-    if ( empty( $item ) ) {
579
+function wpinv_remove_item($item = 0, $force_delete = false) {
580
+    if (empty($item)) {
581 581
         return NULL;
582 582
     }
583 583
     
584
-    if ( is_int( $item ) ) {
585
-        $item = new WPInv_Item( $item );
584
+    if (is_int($item)) {
585
+        $item = new WPInv_Item($item);
586 586
     }
587 587
     
588
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
588
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
589 589
         return NULL;
590 590
     }
591 591
     
592
-    do_action( 'wpinv_pre_delete_item', $item );
592
+    do_action('wpinv_pre_delete_item', $item);
593 593
 
594
-    wp_delete_post( $item->ID, $force_delete );
594
+    wp_delete_post($item->ID, $force_delete);
595 595
 
596
-    do_action( 'wpinv_post_delete_item', $item );
596
+    do_action('wpinv_post_delete_item', $item);
597 597
 }
598 598
 
599
-function wpinv_can_delete_item( $post_id ) {
600
-    $return = current_user_can( 'manage_options' ) ? true : false;
599
+function wpinv_can_delete_item($post_id) {
600
+    $return = current_user_can('manage_options') ? true : false;
601 601
     
602
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
602
+    if ($return && wpinv_item_in_use($post_id)) {
603 603
         $return = false; // Don't delete item already use in invoices.
604 604
     }
605 605
     
606
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
606
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
607 607
 }
608 608
 
609 609
 function wpinv_admin_action_delete() {
610 610
     $screen = get_current_screen();
611 611
     
612
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
612
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
613 613
         $post_ids = array();
614 614
         
615
-        foreach ( $_REQUEST['post'] as $post_id ) {
616
-            if ( !wpinv_can_delete_item( $post_id ) ) {
615
+        foreach ($_REQUEST['post'] as $post_id) {
616
+            if (!wpinv_can_delete_item($post_id)) {
617 617
                 continue;
618 618
             }
619 619
             
@@ -623,86 +623,86 @@  discard block
 block discarded – undo
623 623
         $_REQUEST['post'] = $post_ids;
624 624
     }
625 625
 }
626
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
627
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
626
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
627
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
628 628
 
629
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
630
-    if ( $post->post_type == 'wpi_item' ) {
631
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
629
+function wpinv_check_delete_item($check, $post, $force_delete) {
630
+    if ($post->post_type == 'wpi_item') {
631
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
632 632
             return true;
633 633
         }
634 634
     }
635 635
     
636 636
     return $check;
637 637
 }
638
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
638
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
639 639
 
640
-function wpinv_item_in_use( $item_id ) {
640
+function wpinv_item_in_use($item_id) {
641 641
     global $wpdb, $wpi_items_in_use;
642 642
     
643
-    if ( !$item_id > 0 ) {
643
+    if (!$item_id > 0) {
644 644
         return false;
645 645
     }
646 646
     
647
-    if ( !empty( $wpi_items_in_use ) ) {
648
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
647
+    if (!empty($wpi_items_in_use)) {
648
+        if (isset($wpi_items_in_use[$item_id])) {
649 649
             return $wpi_items_in_use[$item_id];
650 650
         }
651 651
     } else {
652 652
         $wpi_items_in_use = array();
653 653
     }
654 654
     
655
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
655
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
656 656
     
657
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
658
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
657
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
658
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
659 659
     
660 660
     $wpi_items_in_use[$item_id] = $in_use;
661 661
     
662 662
     return $in_use;
663 663
 }
664 664
 
665
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
665
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
666 666
     // Set some defaults
667 667
     $defaults = array(
668
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
669
-        'title'                => '',                                                      // Required. Item title.
670
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
671
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
672
-        'status'               => 'pending',                                               // Optional. pending, publish
673
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
674
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
675
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
676
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
677
-        'excerpt'              => '',                                                      // Optional. Item short description
668
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
669
+        'title'                => '', // Required. Item title.
670
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
671
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
672
+        'status'               => 'pending', // Optional. pending, publish
673
+        'custom_name'          => '', // Optional. Plural sub title for item.
674
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
675
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
676
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
677
+        'excerpt'              => '', // Optional. Item short description
678 678
         /* Recurring item fields */
679
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
680
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
682
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
683
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
684
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
685
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
679
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
680
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
681
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
682
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
683
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
684
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
685
+        'trial_interval'       => 0, // Optional. Any integer number.
686 686
     );
687 687
 
688
-    $data = wp_parse_args( $args, $defaults );
688
+    $data = wp_parse_args($args, $defaults);
689 689
 
690
-    if ( empty( $data['type'] ) ) {
690
+    if (empty($data['type'])) {
691 691
         $data['type'] = 'custom';
692 692
     }
693 693
 
694
-    if ( !empty( $data['custom_id'] ) ) {
695
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
694
+    if (!empty($data['custom_id'])) {
695
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
696 696
     } else {
697 697
         $item = NULL;
698 698
     }
699 699
 
700
-    if ( !empty( $item ) ) {
701
-        if ( $force_update ) {
702
-            if ( empty( $args['ID'] ) ) {
700
+    if (!empty($item)) {
701
+        if ($force_update) {
702
+            if (empty($args['ID'])) {
703 703
                 $args['ID'] = $item->ID;
704 704
             }
705
-            return wpinv_update_item( $args, $wp_error );
705
+            return wpinv_update_item($args, $wp_error);
706 706
         }
707 707
 
708 708
         return $item;
@@ -713,19 +713,19 @@  discard block
 block discarded – undo
713 713
     $meta['custom_id']              = $data['custom_id'];
714 714
     $meta['custom_singular_name']   = $data['custom_singular_name'];
715 715
     $meta['custom_name']            = $data['custom_name'];
716
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
716
+    $meta['price']                  = wpinv_round_amount($data['price']);
717 717
     $meta['editable']               = (int)$data['editable'];
718 718
     $meta['vat_rule']               = $data['vat_rule'];
719 719
     $meta['vat_class']              = '_standard';
720 720
     
721
-    if ( !empty( $data['is_recurring'] ) ) {
721
+    if (!empty($data['is_recurring'])) {
722 722
         $meta['is_recurring']       = $data['is_recurring'];
723 723
         $meta['recurring_period']   = $data['recurring_period'];
724
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
725
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
724
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
725
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
726 726
         $meta['free_trial']         = $data['free_trial'];
727 727
         $meta['trial_period']       = $data['trial_period'];
728
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
728
+        $meta['trial_interval']     = absint($data['trial_interval']);
729 729
     } else {
730 730
         $meta['is_recurring']       = 0;
731 731
         $meta['recurring_period']   = '';
@@ -736,7 +736,7 @@  discard block
 block discarded – undo
736 736
         $meta['trial_interval']     = '';
737 737
     }
738 738
     
739
-    $post_data  = array( 
739
+    $post_data = array( 
740 740
         'post_title'    => $data['title'],
741 741
         'post_excerpt'  => $data['excerpt'],
742 742
         'post_status'   => $data['status'],
@@ -744,89 +744,89 @@  discard block
 block discarded – undo
744 744
     );
745 745
 
746 746
     $item = new WPInv_Item();
747
-    $return = $item->create( $post_data, $wp_error );
747
+    $return = $item->create($post_data, $wp_error);
748 748
 
749
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
749
+    if ($return && !empty($item) && !is_wp_error($return)) {
750 750
         return $item;
751 751
     }
752 752
 
753
-    if ( $wp_error && is_wp_error( $return ) ) {
753
+    if ($wp_error && is_wp_error($return)) {
754 754
         return $return;
755 755
     }
756 756
     return 0;
757 757
 }
758 758
 
759
-function wpinv_update_item( $args = array(), $wp_error = false ) {
760
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
759
+function wpinv_update_item($args = array(), $wp_error = false) {
760
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
761 761
 
762
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
763
-        if ( $wp_error ) {
764
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
762
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
763
+        if ($wp_error) {
764
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
765 765
         }
766 766
         return 0;
767 767
     }
768 768
     
769
-    if ( !empty( $args['custom_id'] ) ) {
770
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
769
+    if (!empty($args['custom_id'])) {
770
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
771 771
         
772
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
773
-            if ( $wp_error ) {
774
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
772
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
773
+            if ($wp_error) {
774
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
775 775
             }
776 776
             return 0;
777 777
         }
778 778
     }
779 779
 
780
-    $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' );
780
+    $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval');
781 781
 
782 782
     $post_data = array();
783
-    if ( isset( $args['title'] ) ) { 
783
+    if (isset($args['title'])) { 
784 784
         $post_data['post_title'] = $args['title'];
785 785
     }
786
-    if ( isset( $args['excerpt'] ) ) { 
786
+    if (isset($args['excerpt'])) { 
787 787
         $post_data['post_excerpt'] = $args['excerpt'];
788 788
     }
789
-    if ( isset( $args['status'] ) ) { 
789
+    if (isset($args['status'])) { 
790 790
         $post_data['post_status'] = $args['status'];
791 791
     }
792 792
     
793
-    foreach ( $meta_fields as $meta_field ) {
794
-        if ( isset( $args[ $meta_field ] ) ) { 
795
-            $value = $args[ $meta_field ];
793
+    foreach ($meta_fields as $meta_field) {
794
+        if (isset($args[$meta_field])) { 
795
+            $value = $args[$meta_field];
796 796
 
797
-            switch ( $meta_field ) {
797
+            switch ($meta_field) {
798 798
                 case 'price':
799
-                    $value = wpinv_round_amount( $value );
799
+                    $value = wpinv_round_amount($value);
800 800
                 break;
801 801
                 case 'recurring_interval':
802 802
                 case 'recurring_limit':
803 803
                 case 'trial_interval':
804
-                    $value = absint( $value );
804
+                    $value = absint($value);
805 805
                 break;
806 806
 				case 'editable':
807
-                    $value = (int) $value;
807
+                    $value = (int)$value;
808 808
                 break;
809 809
             }
810 810
 
811
-            $post_data['meta'][ $meta_field ] = $value;
811
+            $post_data['meta'][$meta_field] = $value;
812 812
         };
813 813
     }
814 814
 
815
-    if ( empty( $post_data ) ) {
816
-        if ( $wp_error ) {
817
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
815
+    if (empty($post_data)) {
816
+        if ($wp_error) {
817
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
818 818
         }
819 819
         return 0;
820 820
     }
821 821
     $post_data['ID'] = $args['ID'];
822 822
 
823
-    $return = $item->update( $post_data, $wp_error );
823
+    $return = $item->update($post_data, $wp_error);
824 824
 
825
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
825
+    if ($return && !empty($item) && !is_wp_error($return)) {
826 826
         return $item;
827 827
     }
828 828
 
829
-    if ( $wp_error && is_wp_error( $return ) ) {
829
+    if ($wp_error && is_wp_error($return)) {
830 830
         return $return;
831 831
     }
832 832
     return 0;
Please login to merge, or discard this patch.