Passed
Push — master ( 919089...f59267 )
by Stiofan
41s queued 11s
created
includes/wpinv-template-functions.php 1 patch
Spacing   +703 added lines, -703 removed lines patch added patch discarded remove patch
@@ -7,91 +7,91 @@  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
-if ( !is_admin() ) {
15
-    add_filter( 'template_include', 'wpinv_template', 10, 1 );
16
-    add_action( 'wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar' );
17
-    add_action( 'wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions' );
18
-    add_action( 'wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions' );
14
+if (!is_admin()) {
15
+    add_filter('template_include', 'wpinv_template', 10, 1);
16
+    add_action('wpinv_invoice_print_body_start', 'wpinv_display_invoice_top_bar');
17
+    add_action('wpinv_invoice_top_bar_left', 'wpinv_invoice_display_left_actions');
18
+    add_action('wpinv_invoice_top_bar_right', 'wpinv_invoice_display_right_actions');
19 19
 }
20 20
 
21 21
 function wpinv_template_path() {
22
-    return apply_filters( 'wpinv_template_path', wpinv_get_theme_template_dir_name() );
22
+    return apply_filters('wpinv_template_path', wpinv_get_theme_template_dir_name());
23 23
 }
24 24
 
25
-function wpinv_display_invoice_top_bar( $invoice ) {
26
-    if ( empty( $invoice ) ) {
25
+function wpinv_display_invoice_top_bar($invoice) {
26
+    if (empty($invoice)) {
27 27
         return;
28 28
     }
29 29
     ?>
30 30
     <div class="row wpinv-top-bar no-print">
31 31
         <div class="container">
32 32
             <div class="col-xs-6">
33
-                <?php do_action( 'wpinv_invoice_top_bar_left', $invoice );?>
33
+                <?php do_action('wpinv_invoice_top_bar_left', $invoice); ?>
34 34
             </div>
35 35
             <div class="col-xs-6 text-right">
36
-                <?php do_action( 'wpinv_invoice_top_bar_right', $invoice );?>
36
+                <?php do_action('wpinv_invoice_top_bar_right', $invoice); ?>
37 37
             </div>
38 38
         </div>
39 39
     </div>
40 40
     <?php
41 41
 }
42 42
 
43
-function wpinv_invoice_display_left_actions( $invoice ) {
44
-    if ( empty( $invoice ) ) {
43
+function wpinv_invoice_display_left_actions($invoice) {
44
+    if (empty($invoice)) {
45 45
         return; // Exit if invoice is not set.
46 46
     }
47 47
     
48
-    if ( $invoice->post_type == 'wpi_invoice' ) {
49
-        if ( $invoice->needs_payment() ) {
50
-            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e( 'Pay This Invoice', 'invoicing' ); ?>" href="<?php echo esc_url( $invoice->get_checkout_payment_url() ); ?>"><?php _e( 'Pay For Invoice', 'invoicing' ); ?></a><?php
48
+    if ($invoice->post_type == 'wpi_invoice') {
49
+        if ($invoice->needs_payment()) {
50
+            ?> <a class="btn btn-success btn-sm" title="<?php esc_attr_e('Pay This Invoice', 'invoicing'); ?>" href="<?php echo esc_url($invoice->get_checkout_payment_url()); ?>"><?php _e('Pay For Invoice', 'invoicing'); ?></a><?php
51 51
         }
52 52
     }
53 53
     do_action('wpinv_invoice_display_left_actions', $invoice);
54 54
 }
55 55
 
56
-function wpinv_invoice_display_right_actions( $invoice ) {
57
-    if ( empty( $invoice ) ) {
56
+function wpinv_invoice_display_right_actions($invoice) {
57
+    if (empty($invoice)) {
58 58
         return; // Exit if invoice is not set.
59 59
     }
60 60
 
61
-    if ( $invoice->post_type == 'wpi_invoice' ) { ?>
62
-        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e( 'Print Invoice', 'invoicing' ); ?></a>
63
-        <?php if ( is_user_logged_in() ) { ?>
64
-        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url( wpinv_get_history_page_uri() ); ?>"><?php _e( 'Invoice History', 'invoicing' ); ?></a>
61
+    if ($invoice->post_type == 'wpi_invoice') { ?>
62
+        <a class="btn btn-primary btn-sm btn-print-invoice" onclick="window.print();" href="javascript:void(0)"><?php _e('Print Invoice', 'invoicing'); ?></a>
63
+        <?php if (is_user_logged_in()) { ?>
64
+        &nbsp;&nbsp;<a class="btn btn-warning btn-sm btn-invoice-history" href="<?php echo esc_url(wpinv_get_history_page_uri()); ?>"><?php _e('Invoice History', 'invoicing'); ?></a>
65 65
         <?php }
66 66
     }
67 67
     do_action('wpinv_invoice_display_right_actions', $invoice);
68 68
 }
69 69
 
70
-function wpinv_before_invoice_content( $content ) {
70
+function wpinv_before_invoice_content($content) {
71 71
     global $post;
72 72
 
73
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
73
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
74 74
         ob_start();
75
-        do_action( 'wpinv_before_invoice_content', $post->ID );
75
+        do_action('wpinv_before_invoice_content', $post->ID);
76 76
         $content = ob_get_clean() . $content;
77 77
     }
78 78
 
79 79
     return $content;
80 80
 }
81
-add_filter( 'the_content', 'wpinv_before_invoice_content' );
81
+add_filter('the_content', 'wpinv_before_invoice_content');
82 82
 
83
-function wpinv_after_invoice_content( $content ) {
83
+function wpinv_after_invoice_content($content) {
84 84
     global $post;
85 85
 
86
-    if ( !empty( $post ) && $post->post_type == 'wpi_invoice' && is_singular( 'wpi_invoice' ) && is_main_query() ) {
86
+    if (!empty($post) && $post->post_type == 'wpi_invoice' && is_singular('wpi_invoice') && is_main_query()) {
87 87
         ob_start();
88
-        do_action( 'wpinv_after_invoice_content', $post->ID );
88
+        do_action('wpinv_after_invoice_content', $post->ID);
89 89
         $content .= ob_get_clean();
90 90
     }
91 91
 
92 92
     return $content;
93 93
 }
94
-add_filter( 'the_content', 'wpinv_after_invoice_content' );
94
+add_filter('the_content', 'wpinv_after_invoice_content');
95 95
 
96 96
 function wpinv_get_templates_dir() {
97 97
     return WPINV_PLUGIN_DIR . 'templates';
@@ -101,105 +101,105 @@  discard block
 block discarded – undo
101 101
     return WPINV_PLUGIN_URL . 'templates';
102 102
 }
103 103
 
104
-function wpinv_get_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
105
-    if ( ! empty( $args ) && is_array( $args ) ) {
106
-		extract( $args );
104
+function wpinv_get_template($template_name, $args = array(), $template_path = '', $default_path = '') {
105
+    if (!empty($args) && is_array($args)) {
106
+		extract($args);
107 107
 	}
108 108
 
109
-	$located = wpinv_locate_template( $template_name, $template_path, $default_path );
109
+	$located = wpinv_locate_template($template_name, $template_path, $default_path);
110 110
 	// Allow 3rd party plugin filter template file from their plugin.
111
-	$located = apply_filters( 'wpinv_get_template', $located, $template_name, $args, $template_path, $default_path );
111
+	$located = apply_filters('wpinv_get_template', $located, $template_name, $args, $template_path, $default_path);
112 112
 
113
-	if ( ! file_exists( $located ) ) {
114
-        _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $located ), '2.1' );
113
+	if (!file_exists($located)) {
114
+        _doing_it_wrong(__FUNCTION__, sprintf('<code>%s</code> does not exist.', $located), '2.1');
115 115
 		return;
116 116
 	}
117 117
 
118
-	do_action( 'wpinv_before_template_part', $template_name, $template_path, $located, $args );
118
+	do_action('wpinv_before_template_part', $template_name, $template_path, $located, $args);
119 119
 
120
-	include( $located );
120
+	include($located);
121 121
 
122
-	do_action( 'wpinv_after_template_part', $template_name, $template_path, $located, $args );
122
+	do_action('wpinv_after_template_part', $template_name, $template_path, $located, $args);
123 123
 }
124 124
 
125
-function wpinv_get_template_html( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
125
+function wpinv_get_template_html($template_name, $args = array(), $template_path = '', $default_path = '') {
126 126
 	ob_start();
127
-	wpinv_get_template( $template_name, $args, $template_path, $default_path );
127
+	wpinv_get_template($template_name, $args, $template_path, $default_path);
128 128
 	return ob_get_clean();
129 129
 }
130 130
 
131
-function wpinv_locate_template( $template_name, $template_path = '', $default_path = '' ) {
132
-    if ( ! $template_path ) {
131
+function wpinv_locate_template($template_name, $template_path = '', $default_path = '') {
132
+    if (!$template_path) {
133 133
         $template_path = wpinv_template_path();
134 134
     }
135 135
 
136
-    if ( ! $default_path ) {
136
+    if (!$default_path) {
137 137
         $default_path = WPINV_PLUGIN_DIR . 'templates/';
138 138
     }
139 139
 
140 140
     // Look within passed path within the theme - this is priority.
141 141
     $template = locate_template(
142 142
         array(
143
-            trailingslashit( $template_path ) . $template_name,
143
+            trailingslashit($template_path) . $template_name,
144 144
             $template_name
145 145
         )
146 146
     );
147 147
 
148 148
     // Get default templates/
149
-    if ( !$template && $default_path ) {
150
-        $template = trailingslashit( $default_path ) . $template_name;
149
+    if (!$template && $default_path) {
150
+        $template = trailingslashit($default_path) . $template_name;
151 151
     }
152 152
 
153 153
     // Return what we found.
154
-    return apply_filters( 'wpinv_locate_template', $template, $template_name, $template_path );
154
+    return apply_filters('wpinv_locate_template', $template, $template_name, $template_path);
155 155
 }
156 156
 
157
-function wpinv_get_template_part( $slug, $name = null, $load = true ) {
158
-	do_action( 'get_template_part_' . $slug, $slug, $name );
157
+function wpinv_get_template_part($slug, $name = null, $load = true) {
158
+	do_action('get_template_part_' . $slug, $slug, $name);
159 159
 
160 160
 	// Setup possible parts
161 161
 	$templates = array();
162
-	if ( isset( $name ) )
162
+	if (isset($name))
163 163
 		$templates[] = $slug . '-' . $name . '.php';
164 164
 	$templates[] = $slug . '.php';
165 165
 
166 166
 	// Allow template parts to be filtered
167
-	$templates = apply_filters( 'wpinv_get_template_part', $templates, $slug, $name );
167
+	$templates = apply_filters('wpinv_get_template_part', $templates, $slug, $name);
168 168
 
169 169
 	// Return the part that is found
170
-	return wpinv_locate_tmpl( $templates, $load, false );
170
+	return wpinv_locate_tmpl($templates, $load, false);
171 171
 }
172 172
 
173
-function wpinv_locate_tmpl( $template_names, $load = false, $require_once = true ) {
173
+function wpinv_locate_tmpl($template_names, $load = false, $require_once = true) {
174 174
 	// No file found yet
175 175
 	$located = false;
176 176
 
177 177
 	// Try to find a template file
178
-	foreach ( (array)$template_names as $template_name ) {
178
+	foreach ((array)$template_names as $template_name) {
179 179
 
180 180
 		// Continue if template is empty
181
-		if ( empty( $template_name ) )
181
+		if (empty($template_name))
182 182
 			continue;
183 183
 
184 184
 		// Trim off any slashes from the template name
185
-		$template_name = ltrim( $template_name, '/' );
185
+		$template_name = ltrim($template_name, '/');
186 186
 
187 187
 		// try locating this template file by looping through the template paths
188
-		foreach( wpinv_get_theme_template_paths() as $template_path ) {
188
+		foreach (wpinv_get_theme_template_paths() as $template_path) {
189 189
 
190
-			if( file_exists( $template_path . $template_name ) ) {
190
+			if (file_exists($template_path . $template_name)) {
191 191
 				$located = $template_path . $template_name;
192 192
 				break;
193 193
 			}
194 194
 		}
195 195
 
196
-		if( !empty( $located ) ) {
196
+		if (!empty($located)) {
197 197
 			break;
198 198
 		}
199 199
 	}
200 200
 
201
-	if ( ( true == $load ) && ! empty( $located ) )
202
-		load_template( $located, $require_once );
201
+	if ((true == $load) && !empty($located))
202
+		load_template($located, $require_once);
203 203
 
204 204
 	return $located;
205 205
 }
@@ -208,149 +208,149 @@  discard block
 block discarded – undo
208 208
 	$template_dir = wpinv_get_theme_template_dir_name();
209 209
 
210 210
 	$file_paths = array(
211
-		1 => trailingslashit( get_stylesheet_directory() ) . $template_dir,
212
-		10 => trailingslashit( get_template_directory() ) . $template_dir,
211
+		1 => trailingslashit(get_stylesheet_directory()) . $template_dir,
212
+		10 => trailingslashit(get_template_directory()) . $template_dir,
213 213
 		100 => wpinv_get_templates_dir()
214 214
 	);
215 215
 
216
-	$file_paths = apply_filters( 'wpinv_template_paths', $file_paths );
216
+	$file_paths = apply_filters('wpinv_template_paths', $file_paths);
217 217
 
218 218
 	// sort the file paths based on priority
219
-	ksort( $file_paths, SORT_NUMERIC );
219
+	ksort($file_paths, SORT_NUMERIC);
220 220
 
221
-	return array_map( 'trailingslashit', $file_paths );
221
+	return array_map('trailingslashit', $file_paths);
222 222
 }
223 223
 
224 224
 function wpinv_get_theme_template_dir_name() {
225
-	return trailingslashit( apply_filters( 'wpinv_templates_dir', 'invoicing' ) );
225
+	return trailingslashit(apply_filters('wpinv_templates_dir', 'invoicing'));
226 226
 }
227 227
 
228 228
 function wpinv_checkout_meta_tags() {
229 229
 
230 230
 	$pages   = array();
231
-	$pages[] = wpinv_get_option( 'success_page' );
232
-	$pages[] = wpinv_get_option( 'failure_page' );
233
-	$pages[] = wpinv_get_option( 'invoice_history_page' );
234
-	$pages[] = wpinv_get_option( 'invoice_subscription_page' );
231
+	$pages[] = wpinv_get_option('success_page');
232
+	$pages[] = wpinv_get_option('failure_page');
233
+	$pages[] = wpinv_get_option('invoice_history_page');
234
+	$pages[] = wpinv_get_option('invoice_subscription_page');
235 235
 
236
-	if( !wpinv_is_checkout() && !is_page( $pages ) ) {
236
+	if (!wpinv_is_checkout() && !is_page($pages)) {
237 237
 		return;
238 238
 	}
239 239
 
240 240
 	echo '<meta name="robots" content="noindex,nofollow" />' . "\n";
241 241
 }
242
-add_action( 'wp_head', 'wpinv_checkout_meta_tags' );
242
+add_action('wp_head', 'wpinv_checkout_meta_tags');
243 243
 
244
-function wpinv_add_body_classes( $class ) {
244
+function wpinv_add_body_classes($class) {
245 245
 	$classes = (array)$class;
246 246
 
247
-	if( wpinv_is_checkout() ) {
247
+	if (wpinv_is_checkout()) {
248 248
 		$classes[] = 'wpinv-checkout';
249 249
 		$classes[] = 'wpinv-page';
250 250
 	}
251 251
 
252
-	if( wpinv_is_success_page() ) {
252
+	if (wpinv_is_success_page()) {
253 253
 		$classes[] = 'wpinv-success';
254 254
 		$classes[] = 'wpinv-page';
255 255
 	}
256 256
 
257
-	if( wpinv_is_failed_transaction_page() ) {
257
+	if (wpinv_is_failed_transaction_page()) {
258 258
 		$classes[] = 'wpinv-failed-transaction';
259 259
 		$classes[] = 'wpinv-page';
260 260
 	}
261 261
 
262
-	if( wpinv_is_invoice_history_page() ) {
262
+	if (wpinv_is_invoice_history_page()) {
263 263
 		$classes[] = 'wpinv-history';
264 264
 		$classes[] = 'wpinv-page';
265 265
 	}
266 266
 
267
-	if( wpinv_is_subscriptions_history_page() ) {
267
+	if (wpinv_is_subscriptions_history_page()) {
268 268
 		$classes[] = 'wpinv-subscription';
269 269
 		$classes[] = 'wpinv-page';
270 270
 	}
271 271
 
272
-	if( wpinv_is_test_mode() ) {
272
+	if (wpinv_is_test_mode()) {
273 273
 		$classes[] = 'wpinv-test-mode';
274 274
 		$classes[] = 'wpinv-page';
275 275
 	}
276 276
 
277
-	return array_unique( $classes );
277
+	return array_unique($classes);
278 278
 }
279
-add_filter( 'body_class', 'wpinv_add_body_classes' );
279
+add_filter('body_class', 'wpinv_add_body_classes');
280 280
 
281
-function wpinv_html_dropdown( $name = 'wpinv_discounts', $selected = 0, $status = '' ) {
282
-    $args = array( 'nopaging' => true );
281
+function wpinv_html_dropdown($name = 'wpinv_discounts', $selected = 0, $status = '') {
282
+    $args = array('nopaging' => true);
283 283
 
284
-    if ( ! empty( $status ) )
284
+    if (!empty($status))
285 285
         $args['post_status'] = $status;
286 286
 
287
-    $discounts = wpinv_get_discounts( $args );
287
+    $discounts = wpinv_get_discounts($args);
288 288
     $options   = array();
289 289
 
290
-    if ( $discounts ) {
291
-        foreach ( $discounts as $discount ) {
292
-            $options[ absint( $discount->ID ) ] = esc_html( get_the_title( $discount->ID ) );
290
+    if ($discounts) {
291
+        foreach ($discounts as $discount) {
292
+            $options[absint($discount->ID)] = esc_html(get_the_title($discount->ID));
293 293
         }
294 294
     } else {
295
-        $options[0] = __( 'No discounts found', 'invoicing' );
295
+        $options[0] = __('No discounts found', 'invoicing');
296 296
     }
297 297
 
298
-    $output = wpinv_html_select( array(
298
+    $output = wpinv_html_select(array(
299 299
         'name'             => $name,
300 300
         'selected'         => $selected,
301 301
         'options'          => $options,
302 302
         'show_option_all'  => false,
303 303
         'show_option_none' => false,
304
-    ) );
304
+    ));
305 305
 
306 306
     return $output;
307 307
 }
308 308
 
309
-function wpinv_html_year_dropdown( $name = 'year', $selected = 0, $years_before = 5, $years_after = 0 ) {
310
-    $current     = date( 'Y' );
311
-    $start_year  = $current - absint( $years_before );
312
-    $end_year    = $current + absint( $years_after );
313
-    $selected    = empty( $selected ) ? date( 'Y' ) : $selected;
309
+function wpinv_html_year_dropdown($name = 'year', $selected = 0, $years_before = 5, $years_after = 0) {
310
+    $current     = date('Y');
311
+    $start_year  = $current - absint($years_before);
312
+    $end_year    = $current + absint($years_after);
313
+    $selected    = empty($selected) ? date('Y') : $selected;
314 314
     $options     = array();
315 315
 
316
-    while ( $start_year <= $end_year ) {
317
-        $options[ absint( $start_year ) ] = $start_year;
316
+    while ($start_year <= $end_year) {
317
+        $options[absint($start_year)] = $start_year;
318 318
         $start_year++;
319 319
     }
320 320
 
321
-    $output = wpinv_html_select( array(
321
+    $output = wpinv_html_select(array(
322 322
         'name'             => $name,
323 323
         'selected'         => $selected,
324 324
         'options'          => $options,
325 325
         'show_option_all'  => false,
326 326
         'show_option_none' => false
327
-    ) );
327
+    ));
328 328
 
329 329
     return $output;
330 330
 }
331 331
 
332
-function wpinv_html_month_dropdown( $name = 'month', $selected = 0 ) {
332
+function wpinv_html_month_dropdown($name = 'month', $selected = 0) {
333 333
     $month   = 1;
334 334
     $options = array();
335
-    $selected = empty( $selected ) ? date( 'n' ) : $selected;
335
+    $selected = empty($selected) ? date('n') : $selected;
336 336
 
337
-    while ( $month <= 12 ) {
338
-        $options[ absint( $month ) ] = wpinv_month_num_to_name( $month );
337
+    while ($month <= 12) {
338
+        $options[absint($month)] = wpinv_month_num_to_name($month);
339 339
         $month++;
340 340
     }
341 341
 
342
-    $output = wpinv_html_select( array(
342
+    $output = wpinv_html_select(array(
343 343
         'name'             => $name,
344 344
         'selected'         => $selected,
345 345
         'options'          => $options,
346 346
         'show_option_all'  => false,
347 347
         'show_option_none' => false
348
-    ) );
348
+    ));
349 349
 
350 350
     return $output;
351 351
 }
352 352
 
353
-function wpinv_html_select( $args = array() ) {
353
+function wpinv_html_select($args = array()) {
354 354
     $defaults = array(
355 355
         'options'          => array(),
356 356
         'name'             => null,
@@ -359,8 +359,8 @@  discard block
 block discarded – undo
359 359
         'selected'         => 0,
360 360
         'placeholder'      => null,
361 361
         'multiple'         => false,
362
-        'show_option_all'  => _x( 'All', 'all dropdown items', 'invoicing' ),
363
-        'show_option_none' => _x( 'None', 'no dropdown items', 'invoicing' ),
362
+        'show_option_all'  => _x('All', 'all dropdown items', 'invoicing'),
363
+        'show_option_none' => _x('None', 'no dropdown items', 'invoicing'),
364 364
         'data'             => array(),
365 365
         'onchange'         => null,
366 366
         'required'         => false,
@@ -368,74 +368,74 @@  discard block
 block discarded – undo
368 368
         'readonly'         => false,
369 369
     );
370 370
 
371
-    $args = wp_parse_args( $args, $defaults );
371
+    $args = wp_parse_args($args, $defaults);
372 372
 
373 373
     $data_elements = '';
374
-    foreach ( $args['data'] as $key => $value ) {
375
-        $data_elements .= ' data-' . esc_attr( $key ) . '="' . esc_attr( $value ) . '"';
374
+    foreach ($args['data'] as $key => $value) {
375
+        $data_elements .= ' data-' . esc_attr($key) . '="' . esc_attr($value) . '"';
376 376
     }
377 377
 
378
-    if( $args['multiple'] ) {
378
+    if ($args['multiple']) {
379 379
         $multiple = ' MULTIPLE';
380 380
     } else {
381 381
         $multiple = '';
382 382
     }
383 383
 
384
-    if( $args['placeholder'] ) {
384
+    if ($args['placeholder']) {
385 385
         $placeholder = $args['placeholder'];
386 386
     } else {
387 387
         $placeholder = '';
388 388
     }
389 389
     
390 390
     $options = '';
391
-    if( !empty( $args['onchange'] ) ) {
392
-        $options .= ' onchange="' . esc_attr( $args['onchange'] ) . '"';
391
+    if (!empty($args['onchange'])) {
392
+        $options .= ' onchange="' . esc_attr($args['onchange']) . '"';
393 393
     }
394 394
     
395
-    if( !empty( $args['required'] ) ) {
395
+    if (!empty($args['required'])) {
396 396
         $options .= ' required="required"';
397 397
     }
398 398
     
399
-    if( !empty( $args['disabled'] ) ) {
399
+    if (!empty($args['disabled'])) {
400 400
         $options .= ' disabled';
401 401
     }
402 402
     
403
-    if( !empty( $args['readonly'] ) ) {
403
+    if (!empty($args['readonly'])) {
404 404
         $options .= ' readonly';
405 405
     }
406 406
 
407
-    $class  = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
408
-    $output = '<select name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] ) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim( $options ) . $data_elements . '>';
407
+    $class  = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
408
+    $output = '<select name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" class="wpinv-select ' . $class . '"' . $multiple . ' data-placeholder="' . $placeholder . '" ' . trim($options) . $data_elements . '>';
409 409
 
410
-    if ( $args['show_option_all'] ) {
411
-        if( $args['multiple'] ) {
412
-            $selected = selected( true, in_array( 0, $args['selected'] ), false );
410
+    if ($args['show_option_all']) {
411
+        if ($args['multiple']) {
412
+            $selected = selected(true, in_array(0, $args['selected']), false);
413 413
         } else {
414
-            $selected = selected( $args['selected'], 0, false );
414
+            $selected = selected($args['selected'], 0, false);
415 415
         }
416
-        $output .= '<option value="all"' . $selected . '>' . esc_html( $args['show_option_all'] ) . '</option>';
416
+        $output .= '<option value="all"' . $selected . '>' . esc_html($args['show_option_all']) . '</option>';
417 417
     }
418 418
 
419
-    if ( !empty( $args['options'] ) ) {
419
+    if (!empty($args['options'])) {
420 420
 
421
-        if ( $args['show_option_none'] ) {
422
-            if( $args['multiple'] ) {
423
-                $selected = selected( true, in_array( "", $args['selected'] ), false );
421
+        if ($args['show_option_none']) {
422
+            if ($args['multiple']) {
423
+                $selected = selected(true, in_array("", $args['selected']), false);
424 424
             } else {
425
-                $selected = selected( $args['selected'] === "", true, false );
425
+                $selected = selected($args['selected'] === "", true, false);
426 426
             }
427
-            $output .= '<option value=""' . $selected . '>' . esc_html( $args['show_option_none'] ) . '</option>';
427
+            $output .= '<option value=""' . $selected . '>' . esc_html($args['show_option_none']) . '</option>';
428 428
         }
429 429
 
430
-        foreach( $args['options'] as $key => $option ) {
430
+        foreach ($args['options'] as $key => $option) {
431 431
 
432
-            if( $args['multiple'] && is_array( $args['selected'] ) ) {
433
-                $selected = selected( true, (bool)in_array( $key, $args['selected'] ), false );
432
+            if ($args['multiple'] && is_array($args['selected'])) {
433
+                $selected = selected(true, (bool)in_array($key, $args['selected']), false);
434 434
             } else {
435
-                $selected = selected( $args['selected'], $key, false );
435
+                $selected = selected($args['selected'], $key, false);
436 436
             }
437 437
 
438
-            $output .= '<option value="' . esc_attr( $key ) . '"' . $selected . '>' . esc_html( $option ) . '</option>';
438
+            $output .= '<option value="' . esc_attr($key) . '"' . $selected . '>' . esc_html($option) . '</option>';
439 439
         }
440 440
     }
441 441
 
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
     return $output;
445 445
 }
446 446
 
447
-function wpinv_item_dropdown( $args = array() ) {
447
+function wpinv_item_dropdown($args = array()) {
448 448
     $defaults = array(
449 449
         'name'              => 'wpi_item',
450 450
         'id'                => 'wpi_item',
@@ -452,14 +452,14 @@  discard block
 block discarded – undo
452 452
         'multiple'          => false,
453 453
         'selected'          => 0,
454 454
         'number'            => 100,
455
-        'placeholder'       => __( 'Choose a item', 'invoicing' ),
456
-        'data'              => array( 'search-type' => 'item' ),
455
+        'placeholder'       => __('Choose a item', 'invoicing'),
456
+        'data'              => array('search-type' => 'item'),
457 457
         'show_option_all'   => false,
458 458
         'show_option_none'  => false,
459 459
         'show_recurring'    => false,
460 460
     );
461 461
 
462
-    $args = wp_parse_args( $args, $defaults );
462
+    $args = wp_parse_args($args, $defaults);
463 463
 
464 464
     $item_args = array(
465 465
         'post_type'      => 'wpi_item',
@@ -468,44 +468,44 @@  discard block
 block discarded – undo
468 468
         'posts_per_page' => $args['number']
469 469
     );
470 470
     
471
-    $item_args  = apply_filters( 'wpinv_item_dropdown_query_args', $item_args, $args, $defaults );
471
+    $item_args  = apply_filters('wpinv_item_dropdown_query_args', $item_args, $args, $defaults);
472 472
 
473
-    $items      = get_posts( $item_args );
473
+    $items      = get_posts($item_args);
474 474
     $options    = array();
475
-    if ( $items ) {
476
-        foreach ( $items as $item ) {
477
-            $title = esc_html( $item->post_title );
475
+    if ($items) {
476
+        foreach ($items as $item) {
477
+            $title = esc_html($item->post_title);
478 478
             
479
-            if ( !empty( $args['show_recurring'] ) ) {
480
-                $title .= wpinv_get_item_suffix( $item->ID, false );
479
+            if (!empty($args['show_recurring'])) {
480
+                $title .= wpinv_get_item_suffix($item->ID, false);
481 481
             }
482 482
             
483
-            $options[ absint( $item->ID ) ] = $title;
483
+            $options[absint($item->ID)] = $title;
484 484
         }
485 485
     }
486 486
 
487 487
     // This ensures that any selected items are included in the drop down
488
-    if( is_array( $args['selected'] ) ) {
489
-        foreach( $args['selected'] as $item ) {
490
-            if( ! in_array( $item, $options ) ) {
491
-                $title = get_the_title( $item );
492
-                if ( !empty( $args['show_recurring'] ) ) {
493
-                    $title .= wpinv_get_item_suffix( $item, false );
488
+    if (is_array($args['selected'])) {
489
+        foreach ($args['selected'] as $item) {
490
+            if (!in_array($item, $options)) {
491
+                $title = get_the_title($item);
492
+                if (!empty($args['show_recurring'])) {
493
+                    $title .= wpinv_get_item_suffix($item, false);
494 494
                 }
495 495
                 $options[$item] = $title;
496 496
             }
497 497
         }
498
-    } elseif ( is_numeric( $args['selected'] ) && $args['selected'] !== 0 ) {
499
-        if ( ! in_array( $args['selected'], $options ) ) {
500
-            $title = get_the_title( $args['selected'] );
501
-            if ( !empty( $args['show_recurring'] ) ) {
502
-                $title .= wpinv_get_item_suffix( $args['selected'], false );
498
+    } elseif (is_numeric($args['selected']) && $args['selected'] !== 0) {
499
+        if (!in_array($args['selected'], $options)) {
500
+            $title = get_the_title($args['selected']);
501
+            if (!empty($args['show_recurring'])) {
502
+                $title .= wpinv_get_item_suffix($args['selected'], false);
503 503
             }
504
-            $options[$args['selected']] = get_the_title( $args['selected'] );
504
+            $options[$args['selected']] = get_the_title($args['selected']);
505 505
         }
506 506
     }
507 507
 
508
-    $output = wpinv_html_select( array(
508
+    $output = wpinv_html_select(array(
509 509
         'name'             => $args['name'],
510 510
         'selected'         => $args['selected'],
511 511
         'id'               => $args['id'],
@@ -516,12 +516,12 @@  discard block
 block discarded – undo
516 516
         'show_option_all'  => $args['show_option_all'],
517 517
         'show_option_none' => $args['show_option_none'],
518 518
         'data'             => $args['data'],
519
-    ) );
519
+    ));
520 520
 
521 521
     return $output;
522 522
 }
523 523
 
524
-function wpinv_html_checkbox( $args = array() ) {
524
+function wpinv_html_checkbox($args = array()) {
525 525
     $defaults = array(
526 526
         'name'     => null,
527 527
         'current'  => null,
@@ -532,38 +532,38 @@  discard block
 block discarded – undo
532 532
         )
533 533
     );
534 534
 
535
-    $args = wp_parse_args( $args, $defaults );
535
+    $args = wp_parse_args($args, $defaults);
536 536
 
537
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
537
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
538 538
     $options = '';
539
-    if ( ! empty( $args['options']['disabled'] ) ) {
539
+    if (!empty($args['options']['disabled'])) {
540 540
         $options .= ' disabled="disabled"';
541
-    } elseif ( ! empty( $args['options']['readonly'] ) ) {
541
+    } elseif (!empty($args['options']['readonly'])) {
542 542
         $options .= ' readonly';
543 543
     }
544 544
 
545
-    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['name'] ) . '" class="' . $class . ' ' . esc_attr( $args['name'] ) . '" ' . checked( 1, $args['current'], false ) . ' />';
545
+    $output = '<input type="checkbox"' . $options . ' name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['name']) . '" class="' . $class . ' ' . esc_attr($args['name']) . '" ' . checked(1, $args['current'], false) . ' />';
546 546
 
547 547
     return $output;
548 548
 }
549 549
 
550
-function wpinv_html_text( $args = array() ) {
550
+function wpinv_html_text($args = array()) {
551 551
     // Backwards compatibility
552
-    if ( func_num_args() > 1 ) {
552
+    if (func_num_args() > 1) {
553 553
         $args = func_get_args();
554 554
 
555 555
         $name  = $args[0];
556
-        $value = isset( $args[1] ) ? $args[1] : '';
557
-        $label = isset( $args[2] ) ? $args[2] : '';
558
-        $desc  = isset( $args[3] ) ? $args[3] : '';
556
+        $value = isset($args[1]) ? $args[1] : '';
557
+        $label = isset($args[2]) ? $args[2] : '';
558
+        $desc  = isset($args[3]) ? $args[3] : '';
559 559
     }
560 560
 
561 561
     $defaults = array(
562 562
         'id'           => '',
563
-        'name'         => isset( $name )  ? $name  : 'text',
564
-        'value'        => isset( $value ) ? $value : null,
565
-        'label'        => isset( $label ) ? $label : null,
566
-        'desc'         => isset( $desc )  ? $desc  : null,
563
+        'name'         => isset($name) ? $name : 'text',
564
+        'value'        => isset($value) ? $value : null,
565
+        'label'        => isset($label) ? $label : null,
566
+        'desc'         => isset($desc) ? $desc : null,
567 567
         'placeholder'  => '',
568 568
         'class'        => 'regular-text',
569 569
         'disabled'     => false,
@@ -573,51 +573,51 @@  discard block
 block discarded – undo
573 573
         'data'         => false
574 574
     );
575 575
 
576
-    $args = wp_parse_args( $args, $defaults );
576
+    $args = wp_parse_args($args, $defaults);
577 577
 
578
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
578
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
579 579
     $options = '';
580
-    if( $args['required'] ) {
580
+    if ($args['required']) {
581 581
         $options .= ' required="required"';
582 582
     }
583
-    if( $args['readonly'] ) {
583
+    if ($args['readonly']) {
584 584
         $options .= ' readonly';
585 585
     }
586
-    if( $args['readonly'] ) {
586
+    if ($args['readonly']) {
587 587
         $options .= ' readonly';
588 588
     }
589 589
 
590 590
     $data = '';
591
-    if ( !empty( $args['data'] ) ) {
592
-        foreach ( $args['data'] as $key => $value ) {
593
-            $data .= 'data-' . wpinv_sanitize_key( $key ) . '="' . esc_attr( $value ) . '" ';
591
+    if (!empty($args['data'])) {
592
+        foreach ($args['data'] as $key => $value) {
593
+            $data .= 'data-' . wpinv_sanitize_key($key) . '="' . esc_attr($value) . '" ';
594 594
         }
595 595
     }
596 596
 
597
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
598
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['id'] ) . '">' . esc_html( $args['label'] ) . '</label>';
599
-    if ( ! empty( $args['desc'] ) ) {
600
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
597
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
598
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['id']) . '">' . esc_html($args['label']) . '</label>';
599
+    if (!empty($args['desc'])) {
600
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
601 601
     }
602 602
 
603
-    $output .= '<input type="text" name="' . esc_attr( $args['name'] ) . '" id="' . esc_attr( $args['id'] )  . '" autocomplete="' . esc_attr( $args['autocomplete'] )  . '" value="' . esc_attr( $args['value'] ) . '" placeholder="' . esc_attr( $args['placeholder'] ) . '" class="' . $class . '" ' . $data . ' ' . trim( $options ) . '/>';
603
+    $output .= '<input type="text" name="' . esc_attr($args['name']) . '" id="' . esc_attr($args['id']) . '" autocomplete="' . esc_attr($args['autocomplete']) . '" value="' . esc_attr($args['value']) . '" placeholder="' . esc_attr($args['placeholder']) . '" class="' . $class . '" ' . $data . ' ' . trim($options) . '/>';
604 604
 
605 605
     $output .= '</span>';
606 606
 
607 607
     return $output;
608 608
 }
609 609
 
610
-function wpinv_html_date_field( $args = array() ) {
611
-    if( empty( $args['class'] ) ) {
610
+function wpinv_html_date_field($args = array()) {
611
+    if (empty($args['class'])) {
612 612
         $args['class'] = 'wpiDatepicker';
613
-    } elseif( ! strpos( $args['class'], 'wpiDatepicker' ) ) {
613
+    } elseif (!strpos($args['class'], 'wpiDatepicker')) {
614 614
         $args['class'] .= ' wpiDatepicker';
615 615
     }
616 616
 
617
-    return wpinv_html_text( $args );
617
+    return wpinv_html_text($args);
618 618
 }
619 619
 
620
-function wpinv_html_textarea( $args = array() ) {
620
+function wpinv_html_textarea($args = array()) {
621 621
     $defaults = array(
622 622
         'name'        => 'textarea',
623 623
         'value'       => null,
@@ -627,31 +627,31 @@  discard block
 block discarded – undo
627 627
         'disabled'    => false
628 628
     );
629 629
 
630
-    $args = wp_parse_args( $args, $defaults );
630
+    $args = wp_parse_args($args, $defaults);
631 631
 
632
-    $class = implode( ' ', array_map( 'sanitize_html_class', explode( ' ', $args['class'] ) ) );
632
+    $class = implode(' ', array_map('sanitize_html_class', explode(' ', $args['class'])));
633 633
     $disabled = '';
634
-    if( $args['disabled'] ) {
634
+    if ($args['disabled']) {
635 635
         $disabled = ' disabled="disabled"';
636 636
     }
637 637
 
638
-    $output = '<span id="wpinv-' . wpinv_sanitize_key( $args['name'] ) . '-wrap">';
639
-    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key( $args['name'] ) . '">' . esc_html( $args['label'] ) . '</label>';
640
-    $output .= '<textarea name="' . esc_attr( $args['name'] ) . '" id="' . wpinv_sanitize_key( $args['name'] ) . '" class="' . $class . '"' . $disabled . '>' . esc_attr( $args['value'] ) . '</textarea>';
638
+    $output = '<span id="wpinv-' . wpinv_sanitize_key($args['name']) . '-wrap">';
639
+    $output .= '<label class="wpinv-label" for="' . wpinv_sanitize_key($args['name']) . '">' . esc_html($args['label']) . '</label>';
640
+    $output .= '<textarea name="' . esc_attr($args['name']) . '" id="' . wpinv_sanitize_key($args['name']) . '" class="' . $class . '"' . $disabled . '>' . esc_attr($args['value']) . '</textarea>';
641 641
 
642
-    if ( ! empty( $args['desc'] ) ) {
643
-        $output .= '<span class="wpinv-description">' . esc_html( $args['desc'] ) . '</span>';
642
+    if (!empty($args['desc'])) {
643
+        $output .= '<span class="wpinv-description">' . esc_html($args['desc']) . '</span>';
644 644
     }
645 645
     $output .= '</span>';
646 646
 
647 647
     return $output;
648 648
 }
649 649
 
650
-function wpinv_html_ajax_user_search( $args = array() ) {
650
+function wpinv_html_ajax_user_search($args = array()) {
651 651
     $defaults = array(
652 652
         'name'        => 'user_id',
653 653
         'value'       => null,
654
-        'placeholder' => __( 'Enter username', 'invoicing' ),
654
+        'placeholder' => __('Enter username', 'invoicing'),
655 655
         'label'       => null,
656 656
         'desc'        => null,
657 657
         'class'       => '',
@@ -660,13 +660,13 @@  discard block
 block discarded – undo
660 660
         'data'        => false
661 661
     );
662 662
 
663
-    $args = wp_parse_args( $args, $defaults );
663
+    $args = wp_parse_args($args, $defaults);
664 664
 
665 665
     $args['class'] = 'wpinv-ajax-user-search ' . $args['class'];
666 666
 
667 667
     $output  = '<span class="wpinv_user_search_wrap">';
668
-        $output .= wpinv_html_text( $args );
669
-        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __( 'Cancel', 'invoicing' ) . '" aria-label="' . __( 'Cancel', 'invoicing' ) . '" href="#">x</a><span></span></span>';
668
+        $output .= wpinv_html_text($args);
669
+        $output .= '<span class="wpinv_user_search_results hidden"><a class="wpinv-ajax-user-cancel" title="' . __('Cancel', 'invoicing') . '" aria-label="' . __('Cancel', 'invoicing') . '" href="#">x</a><span></span></span>';
670 670
     $output .= '</span>';
671 671
 
672 672
     return $output;
@@ -675,7 +675,7 @@  discard block
 block discarded – undo
675 675
 function wpinv_ip_geolocation() {
676 676
     global $wpinv_euvat;
677 677
     
678
-    $ip         = !empty( $_GET['ip'] ) ? sanitize_text_field( $_GET['ip'] ) : '';    
678
+    $ip         = !empty($_GET['ip']) ? sanitize_text_field($_GET['ip']) : '';    
679 679
     $content    = '';
680 680
     $iso        = '';
681 681
     $country    = '';
@@ -686,69 +686,69 @@  discard block
 block discarded – undo
686 686
     $credit     = '';
687 687
     $address    = '';
688 688
     
689
-    if ( wpinv_get_option( 'vat_ip_lookup' ) == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record( $ip ) ) {
689
+    if (wpinv_get_option('vat_ip_lookup') == 'geoip2' && $geoip2_city = $wpinv_euvat->geoip2_city_record($ip)) {
690 690
         try {
691 691
             $iso        = $geoip2_city->country->isoCode;
692 692
             $country    = $geoip2_city->country->name;
693
-            $region     = !empty( $geoip2_city->subdivisions ) && !empty( $geoip2_city->subdivisions[0]->name ) ? $geoip2_city->subdivisions[0]->name : '';
693
+            $region     = !empty($geoip2_city->subdivisions) && !empty($geoip2_city->subdivisions[0]->name) ? $geoip2_city->subdivisions[0]->name : '';
694 694
             $city       = $geoip2_city->city->name;
695 695
             $longitude  = $geoip2_city->location->longitude;
696 696
             $latitude   = $geoip2_city->location->latitude;
697
-            $credit     = __( 'Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing' );
698
-        } catch( Exception $e ) { }
697
+            $credit     = __('Geolocated using the information by MaxMind, available from <a href="http://www.maxmind.com" target="_blank">www.maxmind.com</a>', 'invoicing');
698
+        } catch (Exception $e) { }
699 699
     }
700 700
     
701
-    if ( !( $iso && $longitude && $latitude ) && function_exists( 'simplexml_load_file' ) ) {
701
+    if (!($iso && $longitude && $latitude) && function_exists('simplexml_load_file')) {
702 702
         try {
703
-            $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
703
+            $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
704 704
             
705
-            if ( !empty( $load_xml ) && isset( $load_xml->geoplugin_countryCode ) && !empty( $load_xml->geoplugin_latitude ) && !empty( $load_xml->geoplugin_longitude ) ) {
705
+            if (!empty($load_xml) && isset($load_xml->geoplugin_countryCode) && !empty($load_xml->geoplugin_latitude) && !empty($load_xml->geoplugin_longitude)) {
706 706
                 $iso        = $load_xml->geoplugin_countryCode;
707 707
                 $country    = $load_xml->geoplugin_countryName;
708
-                $region     = !empty( $load_xml->geoplugin_regionName ) ? $load_xml->geoplugin_regionName : '';
709
-                $city       = !empty( $load_xml->geoplugin_city ) ? $load_xml->geoplugin_city : '';
708
+                $region     = !empty($load_xml->geoplugin_regionName) ? $load_xml->geoplugin_regionName : '';
709
+                $city       = !empty($load_xml->geoplugin_city) ? $load_xml->geoplugin_city : '';
710 710
                 $longitude  = $load_xml->geoplugin_longitude;
711 711
                 $latitude   = $load_xml->geoplugin_latitude;
712 712
                 $credit     = $load_xml->geoplugin_credit;
713
-                $credit     = __( 'Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing' ) . '<br>' . $load_xml->geoplugin_credit;
713
+                $credit     = __('Geolocated using the information by geoPlugin, available from <a href="http://www.geoplugin.com" target="_blank">www.geoplugin.com</a>', 'invoicing') . '<br>' . $load_xml->geoplugin_credit;
714 714
             }
715
-        } catch( Exception $e ) { }
715
+        } catch (Exception $e) { }
716 716
     }
717 717
     
718
-    if ( $iso && $longitude && $latitude ) {
719
-        if ( $city ) {
718
+    if ($iso && $longitude && $latitude) {
719
+        if ($city) {
720 720
             $address .= $city . ', ';
721 721
         }
722 722
         
723
-        if ( $region ) {
723
+        if ($region) {
724 724
             $address .= $region . ', ';
725 725
         }
726 726
         
727 727
         $address .= $country . ' (' . $iso . ')';
728
-        $content = '<p>'. sprintf( __( '<b>Address:</b> %s', 'invoicing' ), $address ) . '</p>';
729
-        $content .= '<p>'. $credit . '</p>';
728
+        $content = '<p>' . sprintf(__('<b>Address:</b> %s', 'invoicing'), $address) . '</p>';
729
+        $content .= '<p>' . $credit . '</p>';
730 730
     } else {
731
-        $content = '<p>'. sprintf( __( 'Unable to find geolocation for the IP address: %s', 'invoicing' ), $ip ) . '</p>';
731
+        $content = '<p>' . sprintf(__('Unable to find geolocation for the IP address: %s', 'invoicing'), $ip) . '</p>';
732 732
     }
733 733
     ?>
734 734
 <!DOCTYPE html>
735
-<html><head><title><?php echo sprintf( __( 'IP: %s', 'invoicing' ), $ip );?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
735
+<html><head><title><?php echo sprintf(__('IP: %s', 'invoicing'), $ip); ?></title><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css" /><style>html,body{height:100%;margin:0;padding:0;width:100%}body{text-align:center;background:#fff;color:#222;font-size:small;}body,p{font-family: arial,sans-serif}#map{margin:auto;width:100%;height:calc(100% - 120px);min-height:240px}</style></head>
736 736
 <body>
737
-    <?php if ( $latitude && $latitude ) { ?>
737
+    <?php if ($latitude && $latitude) { ?>
738 738
     <div id="map"></div>
739 739
         <script src="//cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.js"></script>
740 740
         <script type="text/javascript">
741 741
         var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
742 742
             osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
743 743
             osm = L.tileLayer(osmUrl, {maxZoom: 18, attribution: osmAttrib}),
744
-            latlng = new L.LatLng(<?php echo $latitude;?>, <?php echo $longitude;?>);
744
+            latlng = new L.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
745 745
 
746 746
         var map = new L.Map('map', {center: latlng, zoom: 12, layers: [osm]});
747 747
 
748 748
         var marker = new L.Marker(latlng);
749 749
         map.addLayer(marker);
750 750
 
751
-        marker.bindPopup("<p><?php esc_attr_e( $address );?></p>");
751
+        marker.bindPopup("<p><?php esc_attr_e($address); ?></p>");
752 752
     </script>
753 753
     <?php } ?>
754 754
     <div style="height:100px"><?php echo $content; ?></div>
@@ -756,18 +756,18 @@  discard block
 block discarded – undo
756 756
 <?php
757 757
     exit;
758 758
 }
759
-add_action( 'wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
760
-add_action( 'wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation' );
759
+add_action('wp_ajax_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
760
+add_action('wp_ajax_nopriv_wpinv_ip_geolocation', 'wpinv_ip_geolocation');
761 761
 
762 762
 // Set up the template for the invoice.
763
-function wpinv_template( $template ) {
763
+function wpinv_template($template) {
764 764
     global $post, $wp_query;
765 765
     
766
-    if ( ( is_single() || is_404() ) && !empty( $post->ID ) && (get_post_type( $post->ID ) == 'wpi_invoice' or get_post_type( $post->ID ) == 'wpi_quote')) {
767
-        if ( wpinv_user_can_view_invoice( $post->ID ) ) {
768
-            $template = wpinv_get_template_part( 'wpinv-invoice-print', false, false );
766
+    if ((is_single() || is_404()) && !empty($post->ID) && (get_post_type($post->ID) == 'wpi_invoice' or get_post_type($post->ID) == 'wpi_quote')) {
767
+        if (wpinv_user_can_view_invoice($post->ID)) {
768
+            $template = wpinv_get_template_part('wpinv-invoice-print', false, false);
769 769
         } else {
770
-            $template = wpinv_get_template_part( 'wpinv-invalid-access', false, false );
770
+            $template = wpinv_get_template_part('wpinv-invalid-access', false, false);
771 771
         }
772 772
     }
773 773
 
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 
777 777
 function wpinv_get_business_address() {
778 778
     $business_address   = wpinv_store_address();
779
-    $business_address   = !empty( $business_address ) ? wpautop( wp_kses_post( $business_address ) ) : '';
779
+    $business_address   = !empty($business_address) ? wpautop(wp_kses_post($business_address)) : '';
780 780
     
781 781
     /*
782 782
     $default_country    = wpinv_get_default_country();
@@ -800,7 +800,7 @@  discard block
 block discarded – undo
800 800
     
801 801
     $business_address = $business_address ? '<div class="address">' . $business_address . '</div>' : '';
802 802
     
803
-    return apply_filters( 'wpinv_get_business_address', $business_address );
803
+    return apply_filters('wpinv_get_business_address', $business_address);
804 804
 }
805 805
 
806 806
 function wpinv_display_from_address() {
@@ -810,192 +810,192 @@  discard block
 block discarded – undo
810 810
     if (empty($from_name)) {
811 811
         $from_name = wpinv_get_business_name();
812 812
     }
813
-    ?><div class="from col-xs-2"><strong><?php _e( 'From:', 'invoicing' ) ?></strong></div>
813
+    ?><div class="from col-xs-2"><strong><?php _e('From:', 'invoicing') ?></strong></div>
814 814
     <div class="wrapper col-xs-10">
815
-        <div class="name"><?php echo esc_html( $from_name ); ?></div>
816
-        <?php if ( $address = wpinv_get_business_address() ) { ?>
817
-        <div class="address"><?php echo wpautop( wp_kses_post( $address ) );?></div>
815
+        <div class="name"><?php echo esc_html($from_name); ?></div>
816
+        <?php if ($address = wpinv_get_business_address()) { ?>
817
+        <div class="address"><?php echo wpautop(wp_kses_post($address)); ?></div>
818 818
         <?php } ?>
819
-        <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?>
820
-        <div class="email_from"><?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?></div>
819
+        <?php if ($email_from = wpinv_mail_get_from_address()) { ?>
820
+        <div class="email_from"><?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?></div>
821 821
         <?php } ?>
822 822
     </div>
823 823
     <?php
824 824
 }
825 825
 
826
-function wpinv_watermark( $id = 0 ) {
827
-    $output = wpinv_get_watermark( $id );
826
+function wpinv_watermark($id = 0) {
827
+    $output = wpinv_get_watermark($id);
828 828
     
829
-    return apply_filters( 'wpinv_get_watermark', $output, $id );
829
+    return apply_filters('wpinv_get_watermark', $output, $id);
830 830
 }
831 831
 
832
-function wpinv_get_watermark( $id ) {
833
-    if ( !$id > 0 ) {
832
+function wpinv_get_watermark($id) {
833
+    if (!$id > 0) {
834 834
         return NULL;
835 835
     }
836
-    $invoice = wpinv_get_invoice( $id );
836
+    $invoice = wpinv_get_invoice($id);
837 837
     
838
-    if ( !empty( $invoice ) && "wpi_invoice" === $invoice->post_type ) {
839
-        if ( $invoice->is_paid() ) {
840
-            return __( 'Paid', 'invoicing' );
838
+    if (!empty($invoice) && "wpi_invoice" === $invoice->post_type) {
839
+        if ($invoice->is_paid()) {
840
+            return __('Paid', 'invoicing');
841 841
         }
842
-        if ( $invoice->is_refunded() ) {
843
-            return __( 'Refunded', 'invoicing' );
842
+        if ($invoice->is_refunded()) {
843
+            return __('Refunded', 'invoicing');
844 844
         }
845
-        if ( $invoice->has_status( array( 'wpi-cancelled' ) ) ) {
846
-            return __( 'Cancelled', 'invoicing' );
845
+        if ($invoice->has_status(array('wpi-cancelled'))) {
846
+            return __('Cancelled', 'invoicing');
847 847
         }
848 848
     }
849 849
     
850 850
     return NULL;
851 851
 }
852 852
 
853
-function wpinv_display_invoice_details( $invoice ) {
853
+function wpinv_display_invoice_details($invoice) {
854 854
     global $wpinv_euvat;
855 855
     
856 856
     $invoice_id = $invoice->ID;
857 857
     $vat_name   = $wpinv_euvat->get_vat_name();
858 858
     $use_taxes  = wpinv_use_taxes();
859 859
     
860
-    $invoice_status = wpinv_get_invoice_status( $invoice_id );
860
+    $invoice_status = wpinv_get_invoice_status($invoice_id);
861 861
     ?>
862 862
     <table class="table table-bordered table-sm">
863
-        <?php if ( $invoice_number = wpinv_get_invoice_number( $invoice_id ) ) { ?>
863
+        <?php if ($invoice_number = wpinv_get_invoice_number($invoice_id)) { ?>
864 864
             <tr class="wpi-row-number">
865
-                <th><?php echo apply_filters( 'wpinv_invoice_number_label', __( 'Invoice Number', 'invoicing' ), $invoice ); ?></th>
866
-                <td><?php echo esc_html( $invoice_number ); ?></td>
865
+                <th><?php echo apply_filters('wpinv_invoice_number_label', __('Invoice Number', 'invoicing'), $invoice); ?></th>
866
+                <td><?php echo esc_html($invoice_number); ?></td>
867 867
             </tr>
868 868
         <?php } ?>
869 869
         <tr class="wpi-row-status">
870
-            <th><?php echo apply_filters( 'wpinv_invoice_status_label', __( 'Invoice Status', 'invoicing' ), $invoice ); ?></th>
871
-            <td><?php echo wpinv_invoice_status_label( $invoice_status, wpinv_get_invoice_status( $invoice_id, true ) ); ?></td>
870
+            <th><?php echo apply_filters('wpinv_invoice_status_label', __('Invoice Status', 'invoicing'), $invoice); ?></th>
871
+            <td><?php echo wpinv_invoice_status_label($invoice_status, wpinv_get_invoice_status($invoice_id, true)); ?></td>
872 872
         </tr>
873
-        <?php if ( $invoice->is_renewal() ) { ?>
873
+        <?php if ($invoice->is_renewal()) { ?>
874 874
         <tr class="wpi-row-parent">
875
-            <th><?php echo apply_filters( 'wpinv_invoice_parent_invoice_label', __( 'Parent Invoice', 'invoicing' ), $invoice ); ?></th>
876
-            <td><?php echo wpinv_invoice_link( $invoice->parent_invoice ); ?></td>
875
+            <th><?php echo apply_filters('wpinv_invoice_parent_invoice_label', __('Parent Invoice', 'invoicing'), $invoice); ?></th>
876
+            <td><?php echo wpinv_invoice_link($invoice->parent_invoice); ?></td>
877 877
         </tr>
878 878
         <?php } ?>
879
-        <?php if ( ( $gateway_name = wpinv_get_payment_gateway_name( $invoice_id ) ) && ( $invoice->is_paid() || $invoice->is_refunded() ) ) { ?>
879
+        <?php if (($gateway_name = wpinv_get_payment_gateway_name($invoice_id)) && ($invoice->is_paid() || $invoice->is_refunded())) { ?>
880 880
             <tr class="wpi-row-gateway">
881
-                <th><?php echo apply_filters( 'wpinv_invoice_payment_method_label', __( 'Payment Method', 'invoicing' ), $invoice ); ?></th>
881
+                <th><?php echo apply_filters('wpinv_invoice_payment_method_label', __('Payment Method', 'invoicing'), $invoice); ?></th>
882 882
                 <td><?php echo $gateway_name; ?></td>
883 883
             </tr>
884 884
         <?php } ?>
885
-        <?php if ( $invoice_date = wpinv_get_invoice_date( $invoice_id ) ) { ?>
885
+        <?php if ($invoice_date = wpinv_get_invoice_date($invoice_id)) { ?>
886 886
             <tr class="wpi-row-date">
887
-                <th><?php echo apply_filters( 'wpinv_invoice_date_label', __( 'Invoice Date', 'invoicing' ), $invoice ); ?></th>
887
+                <th><?php echo apply_filters('wpinv_invoice_date_label', __('Invoice Date', 'invoicing'), $invoice); ?></th>
888 888
                 <td><?php echo $invoice_date; ?></td>
889 889
             </tr>
890 890
         <?php } ?>
891
-        <?php if ( wpinv_get_option( 'overdue_active' ) && $invoice->needs_payment() && ( $due_date = $invoice->get_due_date( true ) ) ) { ?>
891
+        <?php if (wpinv_get_option('overdue_active') && $invoice->needs_payment() && ($due_date = $invoice->get_due_date(true))) { ?>
892 892
             <tr class="wpi-row-date">
893
-                <th><?php echo apply_filters( 'wpinv_invoice_due_date_label', __( 'Due Date', 'invoicing' ), $invoice ); ?></th>
893
+                <th><?php echo apply_filters('wpinv_invoice_due_date_label', __('Due Date', 'invoicing'), $invoice); ?></th>
894 894
                 <td><?php echo $due_date; ?></td>
895 895
             </tr>
896 896
         <?php } ?>
897
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
898
-        <?php if ( $owner_vat_number = $wpinv_euvat->get_vat_number() ) { ?>
897
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
898
+        <?php if ($owner_vat_number = $wpinv_euvat->get_vat_number()) { ?>
899 899
             <tr class="wpi-row-ovatno">
900
-                <th><?php echo apply_filters( 'wpinv_invoice_owner_vat_number_label', wp_sprintf( __( 'Owner %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
900
+                <th><?php echo apply_filters('wpinv_invoice_owner_vat_number_label', wp_sprintf(__('Owner %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
901 901
                 <td><?php echo $owner_vat_number; ?></td>
902 902
             </tr>
903 903
         <?php } ?>
904
-        <?php do_action( 'wpinv_display_details_after_due_date', $invoice_id ); ?>
905
-        <?php if ( $use_taxes && ( $user_vat_number = wpinv_get_invoice_vat_number( $invoice_id ) ) ) { ?>
904
+        <?php do_action('wpinv_display_details_after_due_date', $invoice_id); ?>
905
+        <?php if ($use_taxes && ($user_vat_number = wpinv_get_invoice_vat_number($invoice_id))) { ?>
906 906
             <tr class="wpi-row-uvatno">
907
-                <th><?php echo apply_filters( 'wpinv_invoice_user_vat_number_label', wp_sprintf( __( 'Invoice %s Number', 'invoicing' ), $vat_name ), $invoice, $vat_name ); ?></th>
907
+                <th><?php echo apply_filters('wpinv_invoice_user_vat_number_label', wp_sprintf(__('Invoice %s Number', 'invoicing'), $vat_name), $invoice, $vat_name); ?></th>
908 908
                 <td><?php echo $user_vat_number; ?></td>
909 909
             </tr>
910 910
         <?php } ?>
911 911
         <tr class="table-active tr-total wpi-row-total">
912
-            <th><strong><?php _e( 'Total Amount', 'invoicing' ) ?></strong></th>
913
-            <td><strong><?php echo wpinv_payment_total( $invoice_id, true ); ?></strong></td>
912
+            <th><strong><?php _e('Total Amount', 'invoicing') ?></strong></th>
913
+            <td><strong><?php echo wpinv_payment_total($invoice_id, true); ?></strong></td>
914 914
         </tr>
915 915
     </table>
916 916
 <?php
917 917
 }
918 918
 
919
-function wpinv_display_to_address( $invoice_id = 0 ) {
920
-    $invoice = wpinv_get_invoice( $invoice_id );
919
+function wpinv_display_to_address($invoice_id = 0) {
920
+    $invoice = wpinv_get_invoice($invoice_id);
921 921
     
922
-    if ( empty( $invoice ) ) {
922
+    if (empty($invoice)) {
923 923
         return NULL;
924 924
     }
925 925
     
926 926
     $billing_details = $invoice->get_user_info();
927
-    $output = '<div class="to col-xs-2"><strong>' . __( 'To:', 'invoicing' ) . '</strong></div>';
927
+    $output = '<div class="to col-xs-2"><strong>' . __('To:', 'invoicing') . '</strong></div>';
928 928
     $output .= '<div class="wrapper col-xs-10">';
929 929
     
930 930
     ob_start();
931
-    do_action( 'wpinv_display_to_address_top', $invoice );
931
+    do_action('wpinv_display_to_address_top', $invoice);
932 932
     $output .= ob_get_clean();
933 933
     
934
-    $output .= '<div class="name">' . esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) . '</div>';
935
-    if ( $company = $billing_details['company'] ) {
936
-        $output .= '<div class="company">' . wpautop( wp_kses_post( $company ) ) . '</div>';
934
+    $output .= '<div class="name">' . esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])) . '</div>';
935
+    if ($company = $billing_details['company']) {
936
+        $output .= '<div class="company">' . wpautop(wp_kses_post($company)) . '</div>';
937 937
     }
938 938
     $address_row = '';
939
-    if ( $address = $billing_details['address'] ) {
940
-        $address_row .= wpautop( wp_kses_post( $address ) );
939
+    if ($address = $billing_details['address']) {
940
+        $address_row .= wpautop(wp_kses_post($address));
941 941
     }
942 942
     
943 943
     $address_fields = array();
944
-    if ( !empty( $billing_details['city'] ) ) {
944
+    if (!empty($billing_details['city'])) {
945 945
         $address_fields[] = $billing_details['city'];
946 946
     }
947 947
     
948
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
949
-    if ( !empty( $billing_details['state'] ) ) {
950
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
948
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
949
+    if (!empty($billing_details['state'])) {
950
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
951 951
     }
952 952
 
953
-    if ( !empty( $billing_country ) ) {
954
-        $address_fields[] = wpinv_country_name( $billing_country );
953
+    if (!empty($billing_country)) {
954
+        $address_fields[] = wpinv_country_name($billing_country);
955 955
     }
956 956
 
957
-    if ( !empty( $address_fields ) ) {
958
-        $address_fields = implode( ", ", $address_fields );
957
+    if (!empty($address_fields)) {
958
+        $address_fields = implode(", ", $address_fields);
959 959
         
960
-        if ( !empty( $billing_details['zip'] ) ) {
960
+        if (!empty($billing_details['zip'])) {
961 961
             $address_fields .= ' ' . $billing_details['zip'];
962 962
         }
963 963
 
964
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
964
+        $address_row .= wpautop(wp_kses_post($address_fields));
965 965
     }
966 966
     
967
-    if ( $address_row ) {
967
+    if ($address_row) {
968 968
         $output .= '<div class="address">' . $address_row . '</div>';
969 969
     }
970 970
 
971
-    if ( $phone = $invoice->get_phone() ) {
972
-        $output .= '<div class="phone">' . wp_sprintf( __( 'Phone: %s', 'invoicing' ), esc_html( $phone ) ) . '</div>';
971
+    if ($phone = $invoice->get_phone()) {
972
+        $output .= '<div class="phone">' . wp_sprintf(__('Phone: %s', 'invoicing'), esc_html($phone)) . '</div>';
973 973
     }
974
-    if ( $email = $invoice->get_email() ) {
975
-        $output .= '<div class="email">' . wp_sprintf( __( 'Email: %s' , 'invoicing'), esc_html( $email ) ) . '</div>';
974
+    if ($email = $invoice->get_email()) {
975
+        $output .= '<div class="email">' . wp_sprintf(__('Email: %s', 'invoicing'), esc_html($email)) . '</div>';
976 976
     }
977 977
 
978 978
     ob_start();
979
-    do_action( 'wpinv_display_to_address_bottom', $invoice );
979
+    do_action('wpinv_display_to_address_bottom', $invoice);
980 980
     $output .= ob_get_clean();
981 981
     
982 982
     $output .= '</div>';
983
-    $output = apply_filters( 'wpinv_display_to_address', $output, $invoice );
983
+    $output = apply_filters('wpinv_display_to_address', $output, $invoice);
984 984
 
985 985
     echo $output;
986 986
 }
987 987
 
988
-function wpinv_display_line_items( $invoice_id = 0 ) {
988
+function wpinv_display_line_items($invoice_id = 0) {
989 989
     global $wpinv_euvat, $ajax_cart_details;
990
-    $invoice            = wpinv_get_invoice( $invoice_id );
990
+    $invoice            = wpinv_get_invoice($invoice_id);
991 991
     $quantities_enabled = wpinv_item_quantities_enabled();
992 992
     $use_taxes          = wpinv_use_taxes();
993
-    if ( !$use_taxes && (float)$invoice->get_tax() > 0 ) {
993
+    if (!$use_taxes && (float)$invoice->get_tax() > 0) {
994 994
         $use_taxes = true;
995 995
     }
996 996
     $zero_tax           = !(float)$invoice->get_tax() > 0 ? true : false;
997
-    $tax_label           = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __( 'Tax', 'invoicing' );
998
-    $tax_title          = !$zero_tax && $use_taxes ? ( wpinv_prices_include_tax() ? wp_sprintf( __( '(%s Incl.)', 'invoicing' ), $tax_label ) : wp_sprintf( __( '(%s Excl.)', 'invoicing' ), $tax_label ) ) : '';
997
+    $tax_label = $use_taxes && $invoice->has_vat() ? $wpinv_euvat->get_vat_name() : __('Tax', 'invoicing');
998
+    $tax_title          = !$zero_tax && $use_taxes ? (wpinv_prices_include_tax() ? wp_sprintf(__('(%s Incl.)', 'invoicing'), $tax_label) : wp_sprintf(__('(%s Excl.)', 'invoicing'), $tax_label)) : '';
999 999
 
1000 1000
     $cart_details       = $invoice->get_cart_details();
1001 1001
     $ajax_cart_details  = $cart_details;
@@ -1004,66 +1004,66 @@  discard block
 block discarded – undo
1004 1004
     <table class="table table-sm table-bordered table-responsive">
1005 1005
         <thead>
1006 1006
             <tr>
1007
-                <th class="name"><strong><?php _e( "Item Name", "invoicing" );?></strong></th>
1008
-                <th class="rate"><strong><?php _e( "Price", "invoicing" );?></strong></th>
1007
+                <th class="name"><strong><?php _e("Item Name", "invoicing"); ?></strong></th>
1008
+                <th class="rate"><strong><?php _e("Price", "invoicing"); ?></strong></th>
1009 1009
                 <?php if ($quantities_enabled) { ?>
1010
-                    <th class="qty"><strong><?php _e( "Qty", "invoicing" );?></strong></th>
1010
+                    <th class="qty"><strong><?php _e("Qty", "invoicing"); ?></strong></th>
1011 1011
                 <?php } ?>
1012 1012
                 <?php if ($use_taxes && !$zero_tax) { ?>
1013 1013
                     <th class="tax"><strong><?php echo $tax_label . ' <span class="normal small">(%)</span>'; ?></strong></th>
1014 1014
                 <?php } ?>
1015
-                <th class="total"><strong><?php echo __( "Item Total", "invoicing" ) . ' <span class="normal small">' . $tax_title . '<span>';?></strong></th>
1015
+                <th class="total"><strong><?php echo __("Item Total", "invoicing") . ' <span class="normal small">' . $tax_title . '<span>'; ?></strong></th>
1016 1016
             </tr>
1017 1017
         </thead>
1018 1018
         <tbody>
1019 1019
         <?php 
1020
-            if ( !empty( $cart_details ) ) {
1021
-                do_action( 'wpinv_display_line_items_start', $invoice );
1020
+            if (!empty($cart_details)) {
1021
+                do_action('wpinv_display_line_items_start', $invoice);
1022 1022
 
1023 1023
                 $count = 0;
1024 1024
                 $cols  = 3;
1025
-                foreach ( $cart_details as $key => $cart_item ) {
1026
-                    $item_id    = !empty($cart_item['id']) ? absint( $cart_item['id'] ) : '';
1027
-                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount( $cart_item["item_price"] ) : 0;
1028
-                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount( $cart_item["subtotal"] ) : 0;
1029
-                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint( $cart_item['quantity'] ) : 1;
1025
+                foreach ($cart_details as $key => $cart_item) {
1026
+                    $item_id    = !empty($cart_item['id']) ? absint($cart_item['id']) : '';
1027
+                    $item_price = isset($cart_item["item_price"]) ? wpinv_round_amount($cart_item["item_price"]) : 0;
1028
+                    $line_total = isset($cart_item["subtotal"]) ? wpinv_round_amount($cart_item["subtotal"]) : 0;
1029
+                    $quantity   = !empty($cart_item['quantity']) && (int)$cart_item['quantity'] > 0 ? absint($cart_item['quantity']) : 1;
1030 1030
 
1031
-                    $item       = $item_id ? new WPInv_Item( $item_id ) : NULL;
1031
+                    $item       = $item_id ? new WPInv_Item($item_id) : NULL;
1032 1032
                     $summary    = '';
1033 1033
                     $cols       = 3;
1034
-                    if ( !empty($item) ) {
1034
+                    if (!empty($item)) {
1035 1035
                         $item_name  = $item->get_name();
1036 1036
                         $summary    = $item->get_summary();
1037 1037
                     }
1038
-                    $item_name  = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1038
+                    $item_name = !empty($cart_item['name']) ? $cart_item['name'] : $item_name;
1039 1039
 
1040
-                    $summary = apply_filters( 'wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice );
1040
+                    $summary = apply_filters('wpinv_print_invoice_line_item_summary', $summary, $cart_item, $item, $invoice);
1041 1041
 
1042 1042
                     $item_tax       = '';
1043 1043
                     $tax_rate       = '';
1044
-                    if ( $use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1045
-                        $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1046
-                        $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1047
-                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1044
+                    if ($use_taxes && $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1045
+                        $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1046
+                        $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1047
+                        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1048 1048
                         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate">(' . $tax_rate . '%)</small>' : '';
1049 1049
                     }
1050 1050
 
1051 1051
                     $line_item_tax = $item_tax . $tax_rate;
1052 1052
 
1053
-                    if ( $line_item_tax === '' ) {
1053
+                    if ($line_item_tax === '') {
1054 1054
                         $line_item_tax = 0; // Zero tax
1055 1055
                     }
1056 1056
 
1057
-                    $action = apply_filters( 'wpinv_display_line_item_action', '', $cart_item, $invoice, $cols );
1057
+                    $action = apply_filters('wpinv_display_line_item_action', '', $cart_item, $invoice, $cols);
1058 1058
 
1059
-                    $line_item = '<tr class="row-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . ' wpinv-item">';
1060
-                        $line_item .= '<td class="name">' . $action. esc_html__( $item_name, 'invoicing' ) . wpinv_get_item_suffix( $item );
1061
-                        if ( $summary !== '' ) {
1062
-                            $line_item .= '<br/><small class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</small>';
1059
+                    $line_item = '<tr class="row-' . (($count % 2 == 0) ? 'even' : 'odd') . ' wpinv-item">';
1060
+                        $line_item .= '<td class="name">' . $action . esc_html__($item_name, 'invoicing') . wpinv_get_item_suffix($item);
1061
+                        if ($summary !== '') {
1062
+                            $line_item .= '<br/><small class="meta">' . wpautop(wp_kses_post($summary)) . '</small>';
1063 1063
                         }
1064 1064
                         $line_item .= '</td>';
1065 1065
 
1066
-                        $line_item .= '<td class="rate">' . esc_html__( wpinv_price( wpinv_format_amount( $item_price ), $invoice->get_currency() ) ) . '</td>';
1066
+                        $line_item .= '<td class="rate">' . esc_html__(wpinv_price(wpinv_format_amount($item_price), $invoice->get_currency())) . '</td>';
1067 1067
                         if ($quantities_enabled) {
1068 1068
                             $cols++;
1069 1069
                             $line_item .= '<td class="qty">' . $quantity . '</td>';
@@ -1072,55 +1072,55 @@  discard block
 block discarded – undo
1072 1072
                             $cols++;
1073 1073
                             $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1074 1074
                         }
1075
-                        $line_item .= '<td class="total">' . esc_html__( wpinv_price( wpinv_format_amount( $line_total ), $invoice->get_currency() ) ) . '</td>';
1075
+                        $line_item .= '<td class="total">' . esc_html__(wpinv_price(wpinv_format_amount($line_total), $invoice->get_currency())) . '</td>';
1076 1076
                     $line_item .= '</tr>';
1077 1077
 
1078
-                    echo apply_filters( 'wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols );
1078
+                    echo apply_filters('wpinv_display_line_item', $line_item, $cart_item, $invoice, $cols);
1079 1079
 
1080 1080
                     $count++;
1081 1081
                 }
1082 1082
 
1083
-                do_action( 'wpinv_display_before_subtotal', $invoice, $cols );
1083
+                do_action('wpinv_display_before_subtotal', $invoice, $cols);
1084 1084
                 ?>
1085 1085
                 <tr class="row-sub-total row_odd">
1086
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_subtotal_label', '<strong>' . __( 'Sub Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1087
-                    <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1086
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_subtotal_label', '<strong>' . __('Sub Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1087
+                    <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1088 1088
                 </tr>
1089 1089
                 <?php
1090
-                do_action( 'wpinv_display_after_subtotal', $invoice, $cols );
1090
+                do_action('wpinv_display_after_subtotal', $invoice, $cols);
1091 1091
                 
1092
-                if ( wpinv_discount( $invoice_id, false ) > 0 ) {
1093
-                    do_action( 'wpinv_display_before_discount', $invoice, $cols );
1092
+                if (wpinv_discount($invoice_id, false) > 0) {
1093
+                    do_action('wpinv_display_before_discount', $invoice, $cols);
1094 1094
                     ?>
1095 1095
                         <tr class="row-discount">
1096
-                            <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?>:</td>
1097
-                            <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1096
+                            <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?>:</td>
1097
+                            <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1098 1098
                         </tr>
1099 1099
                     <?php
1100
-                    do_action( 'wpinv_display_after_discount', $invoice, $cols );
1100
+                    do_action('wpinv_display_after_discount', $invoice, $cols);
1101 1101
                 }
1102 1102
 
1103
-                if ( $use_taxes ) {
1104
-                    do_action( 'wpinv_display_before_tax', $invoice, $cols );
1103
+                if ($use_taxes) {
1104
+                    do_action('wpinv_display_before_tax', $invoice, $cols);
1105 1105
                     ?>
1106 1106
                     <tr class="row-tax">
1107
-                        <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice ); ?></td>
1108
-                        <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1107
+                        <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_tax_label', '<strong>' . $tax_label . ':</strong>', $invoice); ?></td>
1108
+                        <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1109 1109
                     </tr>
1110 1110
                     <?php
1111
-                    do_action( 'wpinv_display_after_tax', $invoice, $cols );
1111
+                    do_action('wpinv_display_after_tax', $invoice, $cols);
1112 1112
                 }
1113 1113
 
1114
-                do_action( 'wpinv_display_before_total', $invoice, $cols );
1114
+                do_action('wpinv_display_before_total', $invoice, $cols);
1115 1115
                 ?>
1116 1116
                 <tr class="table-active row-total">
1117
-                    <td class="rate" colspan="<?php echo ( $cols - 1 ); ?>"><?php echo apply_filters( 'wpinv_print_cart_total_label', '<strong>' . __( 'Total', 'invoicing' ) . ':</strong>', $invoice ); ?></td>
1118
-                    <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1117
+                    <td class="rate" colspan="<?php echo ($cols - 1); ?>"><?php echo apply_filters('wpinv_print_cart_total_label', '<strong>' . __('Total', 'invoicing') . ':</strong>', $invoice); ?></td>
1118
+                    <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1119 1119
                 </tr>
1120 1120
                 <?php
1121
-                do_action( 'wpinv_display_after_total', $invoice, $cols );
1121
+                do_action('wpinv_display_after_total', $invoice, $cols);
1122 1122
 
1123
-                do_action( 'wpinv_display_line_end', $invoice, $cols );
1123
+                do_action('wpinv_display_line_end', $invoice, $cols);
1124 1124
             }
1125 1125
         ?>
1126 1126
         </tbody>
@@ -1129,35 +1129,35 @@  discard block
 block discarded – undo
1129 1129
     echo ob_get_clean();
1130 1130
 }
1131 1131
 
1132
-function wpinv_display_invoice_totals( $invoice_id = 0 ) {
1132
+function wpinv_display_invoice_totals($invoice_id = 0) {
1133 1133
     $use_taxes = wpinv_use_taxes();
1134 1134
 
1135
-    do_action( 'wpinv_before_display_totals_table', $invoice_id ); 
1135
+    do_action('wpinv_before_display_totals_table', $invoice_id); 
1136 1136
     ?>
1137 1137
     <table class="table table-sm table-bordered table-responsive">
1138 1138
         <tbody>
1139
-            <?php do_action( 'wpinv_before_display_totals' ); ?>
1139
+            <?php do_action('wpinv_before_display_totals'); ?>
1140 1140
             <tr class="row-sub-total">
1141
-                <td class="rate"><strong><?php _e( 'Sub Total', 'invoicing' ); ?></strong></td>
1142
-                <td class="total"><strong><?php _e( wpinv_subtotal( $invoice_id, true ) ) ?></strong></td>
1141
+                <td class="rate"><strong><?php _e('Sub Total', 'invoicing'); ?></strong></td>
1142
+                <td class="total"><strong><?php _e(wpinv_subtotal($invoice_id, true)) ?></strong></td>
1143 1143
             </tr>
1144
-            <?php do_action( 'wpinv_after_display_totals' ); ?>
1145
-            <?php if ( wpinv_discount( $invoice_id, false ) > 0 ) { ?>
1144
+            <?php do_action('wpinv_after_display_totals'); ?>
1145
+            <?php if (wpinv_discount($invoice_id, false) > 0) { ?>
1146 1146
                 <tr class="row-discount">
1147
-                    <td class="rate"><?php wpinv_get_discount_label( wpinv_discount_code( $invoice_id ) ); ?></td>
1148
-                    <td class="total"><?php echo wpinv_discount( $invoice_id, true, true ); ?></td>
1147
+                    <td class="rate"><?php wpinv_get_discount_label(wpinv_discount_code($invoice_id)); ?></td>
1148
+                    <td class="total"><?php echo wpinv_discount($invoice_id, true, true); ?></td>
1149 1149
                 </tr>
1150
-            <?php do_action( 'wpinv_after_display_discount' ); ?>
1150
+            <?php do_action('wpinv_after_display_discount'); ?>
1151 1151
             <?php } ?>
1152
-            <?php if ( $use_taxes ) { ?>
1152
+            <?php if ($use_taxes) { ?>
1153 1153
             <tr class="row-tax">
1154
-                <td class="rate"><?php _e( 'Tax', 'invoicing' ); ?></td>
1155
-                <td class="total"><?php _e( wpinv_tax( $invoice_id, true ) ) ?></td>
1154
+                <td class="rate"><?php _e('Tax', 'invoicing'); ?></td>
1155
+                <td class="total"><?php _e(wpinv_tax($invoice_id, true)) ?></td>
1156 1156
             </tr>
1157
-            <?php do_action( 'wpinv_after_display_tax' ); ?>
1157
+            <?php do_action('wpinv_after_display_tax'); ?>
1158 1158
             <?php } ?>
1159
-            <?php if ( $fees = wpinv_get_fees( $invoice_id ) ) { ?>
1160
-                <?php foreach ( $fees as $fee ) { ?>
1159
+            <?php if ($fees = wpinv_get_fees($invoice_id)) { ?>
1160
+                <?php foreach ($fees as $fee) { ?>
1161 1161
                     <tr class="row-fee">
1162 1162
                         <td class="rate"><?php echo $fee['label']; ?></td>
1163 1163
                         <td class="total"><?php echo $fee['amount_display']; ?></td>
@@ -1165,82 +1165,82 @@  discard block
 block discarded – undo
1165 1165
                 <?php } ?>
1166 1166
             <?php } ?>
1167 1167
             <tr class="table-active row-total">
1168
-                <td class="rate"><strong><?php _e( 'Total', 'invoicing' ) ?></strong></td>
1169
-                <td class="total"><strong><?php _e( wpinv_payment_total( $invoice_id, true ) ) ?></strong></td>
1168
+                <td class="rate"><strong><?php _e('Total', 'invoicing') ?></strong></td>
1169
+                <td class="total"><strong><?php _e(wpinv_payment_total($invoice_id, true)) ?></strong></td>
1170 1170
             </tr>
1171
-            <?php do_action( 'wpinv_after_totals' ); ?>
1171
+            <?php do_action('wpinv_after_totals'); ?>
1172 1172
         </tbody>
1173 1173
 
1174 1174
     </table>
1175 1175
 
1176
-    <?php do_action( 'wpinv_after_totals_table' );
1176
+    <?php do_action('wpinv_after_totals_table');
1177 1177
 }
1178 1178
 
1179
-function wpinv_display_payments_info( $invoice_id = 0, $echo = true ) {
1180
-    $invoice = wpinv_get_invoice( $invoice_id );
1179
+function wpinv_display_payments_info($invoice_id = 0, $echo = true) {
1180
+    $invoice = wpinv_get_invoice($invoice_id);
1181 1181
 
1182 1182
     ob_start();
1183
-    do_action( 'wpinv_before_display_payments_info', $invoice_id );
1184
-    if ( ( $gateway_title = $invoice->get_gateway_title() ) || $invoice->is_paid() || $invoice->is_refunded() ) {
1183
+    do_action('wpinv_before_display_payments_info', $invoice_id);
1184
+    if (($gateway_title = $invoice->get_gateway_title()) || $invoice->is_paid() || $invoice->is_refunded()) {
1185 1185
         ?>
1186 1186
         <div class="wpi-payment-info">
1187
-            <p class="wpi-payment-gateway"><?php echo wp_sprintf( __( 'Payment via %s', 'invoicing' ), $gateway_title ? $gateway_title : __( 'Manually', 'invoicing' ) ); ?></p>
1188
-            <?php if ( $gateway_title ) { ?>
1189
-            <p class="wpi-payment-transid"><?php echo wp_sprintf( __( 'Transaction ID: %s', 'invoicing' ), $invoice->get_transaction_id() ); ?></p>
1187
+            <p class="wpi-payment-gateway"><?php echo wp_sprintf(__('Payment via %s', 'invoicing'), $gateway_title ? $gateway_title : __('Manually', 'invoicing')); ?></p>
1188
+            <?php if ($gateway_title) { ?>
1189
+            <p class="wpi-payment-transid"><?php echo wp_sprintf(__('Transaction ID: %s', 'invoicing'), $invoice->get_transaction_id()); ?></p>
1190 1190
             <?php } ?>
1191 1191
         </div>
1192 1192
         <?php
1193 1193
     }
1194
-    do_action( 'wpinv_after_display_payments_info', $invoice_id );
1194
+    do_action('wpinv_after_display_payments_info', $invoice_id);
1195 1195
     $outout = ob_get_clean();
1196 1196
 
1197
-    if ( $echo ) {
1197
+    if ($echo) {
1198 1198
         echo $outout;
1199 1199
     } else {
1200 1200
         return $outout;
1201 1201
     }
1202 1202
 }
1203 1203
 
1204
-function wpinv_display_style( $invoice ) {
1205
-    wp_register_style( 'wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION );
1204
+function wpinv_display_style($invoice) {
1205
+    wp_register_style('wpinv-single-style', WPINV_PLUGIN_URL . 'assets/css/invoice.css', array(), WPINV_VERSION);
1206 1206
 
1207
-    wp_print_styles( 'open-sans' );
1208
-    wp_print_styles( 'wpinv-single-style' );
1207
+    wp_print_styles('open-sans');
1208
+    wp_print_styles('wpinv-single-style');
1209 1209
 
1210 1210
     $custom_css = wpinv_get_option('template_custom_css');
1211
-    if(isset($custom_css) && !empty($custom_css)){
1212
-        $custom_css     = wp_kses( $custom_css, array( '\'', '\"' ) );
1213
-        $custom_css     = str_replace( '&gt;', '>', $custom_css );
1211
+    if (isset($custom_css) && !empty($custom_css)) {
1212
+        $custom_css     = wp_kses($custom_css, array('\'', '\"'));
1213
+        $custom_css     = str_replace('&gt;', '>', $custom_css);
1214 1214
         echo '<style type="text/css">';
1215 1215
         echo $custom_css;
1216 1216
         echo '</style>';
1217 1217
     }
1218 1218
 }
1219
-add_action( 'wpinv_invoice_print_head', 'wpinv_display_style' );
1220
-add_action( 'wpinv_invalid_invoice_head', 'wpinv_display_style' );
1219
+add_action('wpinv_invoice_print_head', 'wpinv_display_style');
1220
+add_action('wpinv_invalid_invoice_head', 'wpinv_display_style');
1221 1221
 
1222 1222
 function wpinv_checkout_billing_details() {
1223 1223
     $invoice_id = (int)wpinv_get_invoice_cart_id();
1224 1224
     if (empty($invoice_id)) {
1225
-        wpinv_error_log( 'Invoice id not found', 'ERROR', __FILE__, __LINE__ );
1225
+        wpinv_error_log('Invoice id not found', 'ERROR', __FILE__, __LINE__);
1226 1226
         return null;
1227 1227
     }
1228 1228
 
1229
-    $invoice = wpinv_get_invoice_cart( $invoice_id );
1229
+    $invoice = wpinv_get_invoice_cart($invoice_id);
1230 1230
     if (empty($invoice)) {
1231
-        wpinv_error_log( 'Invoice not found', 'ERROR', __FILE__, __LINE__ );
1231
+        wpinv_error_log('Invoice not found', 'ERROR', __FILE__, __LINE__);
1232 1232
         return null;
1233 1233
     }
1234 1234
     $user_id        = $invoice->get_user_id();
1235 1235
     $user_info      = $invoice->get_user_info();
1236
-    $address_info   = wpinv_get_user_address( $user_id );
1236
+    $address_info   = wpinv_get_user_address($user_id);
1237 1237
 
1238
-    if ( empty( $user_info['first_name'] ) && !empty( $user_info['first_name'] ) ) {
1238
+    if (empty($user_info['first_name']) && !empty($user_info['first_name'])) {
1239 1239
         $user_info['first_name'] = $user_info['first_name'];
1240 1240
         $user_info['last_name'] = $user_info['last_name'];
1241 1241
     }
1242 1242
 
1243
-    if ( ( ( empty( $user_info['country'] ) && !empty( $address_info['country'] ) ) || ( empty( $user_info['state'] ) && !empty( $address_info['state'] ) && $user_info['country'] == $address_info['country'] ) ) ) {
1243
+    if (((empty($user_info['country']) && !empty($address_info['country'])) || (empty($user_info['state']) && !empty($address_info['state']) && $user_info['country'] == $address_info['country']))) {
1244 1244
         $user_info['country']   = $address_info['country'];
1245 1245
         $user_info['state']     = $address_info['state'];
1246 1246
         $user_info['city']      = $address_info['city'];
@@ -1256,98 +1256,98 @@  discard block
 block discarded – undo
1256 1256
         'address'
1257 1257
     );
1258 1258
 
1259
-    foreach ( $address_fields as $field ) {
1260
-        if ( empty( $user_info[$field] ) ) {
1259
+    foreach ($address_fields as $field) {
1260
+        if (empty($user_info[$field])) {
1261 1261
             $user_info[$field] = $address_info[$field];
1262 1262
         }
1263 1263
     }
1264 1264
 
1265
-    return apply_filters( 'wpinv_checkout_billing_details', $user_info, $invoice );
1265
+    return apply_filters('wpinv_checkout_billing_details', $user_info, $invoice);
1266 1266
 }
1267 1267
 
1268 1268
 function wpinv_admin_get_line_items($invoice = array()) {
1269 1269
     $item_quantities    = wpinv_item_quantities_enabled();
1270 1270
     $use_taxes          = wpinv_use_taxes();
1271 1271
 
1272
-    if ( empty( $invoice ) ) {
1272
+    if (empty($invoice)) {
1273 1273
         return NULL;
1274 1274
     }
1275 1275
 
1276 1276
     $cart_items = $invoice->get_cart_details();
1277
-    if ( empty( $cart_items ) ) {
1277
+    if (empty($cart_items)) {
1278 1278
         return NULL;
1279 1279
     }
1280 1280
     ob_start();
1281 1281
 
1282
-    do_action( 'wpinv_admin_before_line_items', $cart_items, $invoice );
1282
+    do_action('wpinv_admin_before_line_items', $cart_items, $invoice);
1283 1283
 
1284 1284
     $count = 0;
1285
-    foreach ( $cart_items as $key => $cart_item ) {
1285
+    foreach ($cart_items as $key => $cart_item) {
1286 1286
         $item_id    = $cart_item['id'];
1287
-        $wpi_item   = $item_id > 0 ? new WPInv_Item( $item_id ) : NULL;
1287
+        $wpi_item   = $item_id > 0 ? new WPInv_Item($item_id) : NULL;
1288 1288
 
1289 1289
         if (empty($wpi_item)) {
1290 1290
             continue;
1291 1291
         }
1292 1292
 
1293
-        $item_price     = wpinv_price( wpinv_format_amount( $cart_item['item_price'] ), $invoice->get_currency() );
1294
-        $quantity       = !empty( $cart_item['quantity'] ) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1295
-        $item_subtotal  = wpinv_price( wpinv_format_amount( $cart_item['subtotal'] ), $invoice->get_currency() );
1293
+        $item_price     = wpinv_price(wpinv_format_amount($cart_item['item_price']), $invoice->get_currency());
1294
+        $quantity       = !empty($cart_item['quantity']) && $cart_item['quantity'] > 0 ? $cart_item['quantity'] : 1;
1295
+        $item_subtotal  = wpinv_price(wpinv_format_amount($cart_item['subtotal']), $invoice->get_currency());
1296 1296
         $can_remove     = true;
1297 1297
 
1298
-        $summary = apply_filters( 'wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice );
1298
+        $summary = apply_filters('wpinv_admin_invoice_line_item_summary', '', $cart_item, $wpi_item, $invoice);
1299 1299
 
1300 1300
         $item_tax       = '';
1301 1301
         $tax_rate       = '';
1302
-        if ( $cart_item['tax'] > 0 && $cart_item['subtotal'] > 0 ) {
1303
-            $item_tax = wpinv_price( wpinv_format_amount( $cart_item['tax'] ), $invoice->get_currency() );
1304
-            $tax_rate = !empty( $cart_item['vat_rate'] ) ? $cart_item['vat_rate'] : ( $cart_item['tax'] / $cart_item['subtotal'] ) * 100;
1305
-            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
1302
+        if ($cart_item['tax'] > 0 && $cart_item['subtotal'] > 0) {
1303
+            $item_tax = wpinv_price(wpinv_format_amount($cart_item['tax']), $invoice->get_currency());
1304
+            $tax_rate = !empty($cart_item['vat_rate']) ? $cart_item['vat_rate'] : ($cart_item['tax'] / $cart_item['subtotal']) * 100;
1305
+            $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
1306 1306
             $tax_rate = $tax_rate != '' ? ' <span class="tax-rate">(' . $tax_rate . '%)</span>' : '';
1307 1307
         }
1308 1308
         $line_item_tax = $item_tax . $tax_rate;
1309 1309
 
1310
-        if ( $line_item_tax === '' ) {
1310
+        if ($line_item_tax === '') {
1311 1311
             $line_item_tax = 0; // Zero tax
1312 1312
         }
1313 1313
 
1314
-        $line_item = '<tr class="item item-' . ( ($count % 2 == 0) ? 'even' : 'odd' ) . '" data-item-id="' . $item_id . '">';
1314
+        $line_item = '<tr class="item item-' . (($count % 2 == 0) ? 'even' : 'odd') . '" data-item-id="' . $item_id . '">';
1315 1315
             $line_item .= '<td class="id">' . $item_id . '</td>';
1316
-            $line_item .= '<td class="title"><a href="' . get_edit_post_link( $item_id ) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix( $wpi_item );
1317
-            if ( $summary !== '' ) {
1318
-                $line_item .= '<span class="meta">' . wpautop( wp_kses_post( $summary ) ) . '</span>';
1316
+            $line_item .= '<td class="title"><a href="' . get_edit_post_link($item_id) . '" target="_blank">' . $cart_item['name'] . '</a>' . wpinv_get_item_suffix($wpi_item);
1317
+            if ($summary !== '') {
1318
+                $line_item .= '<span class="meta">' . wpautop(wp_kses_post($summary)) . '</span>';
1319 1319
             }
1320 1320
             $line_item .= '</td>';
1321 1321
             $line_item .= '<td class="price">' . $item_price . '</td>';
1322 1322
             
1323
-            if ( $item_quantities ) {
1324
-                if ( count( $cart_items ) == 1 && $quantity <= 1 ) {
1323
+            if ($item_quantities) {
1324
+                if (count($cart_items) == 1 && $quantity <= 1) {
1325 1325
                     $can_remove = false;
1326 1326
                 }
1327 1327
                 $line_item .= '<td class="qty" data-quantity="' . $quantity . '">&nbsp;&times;&nbsp;' . $quantity . '</td>';
1328 1328
             } else {
1329
-                if ( count( $cart_items ) == 1 ) {
1329
+                if (count($cart_items) == 1) {
1330 1330
                     $can_remove = false;
1331 1331
                 }
1332 1332
             }
1333 1333
             $line_item .= '<td class="total">' . $item_subtotal . '</td>';
1334 1334
             
1335
-            if ( $use_taxes ) {
1335
+            if ($use_taxes) {
1336 1336
                 $line_item .= '<td class="tax">' . $line_item_tax . '</td>';
1337 1337
             }
1338 1338
             $line_item .= '<td class="action">';
1339
-            if ( !$invoice->is_paid() && !$invoice->is_refunded() && $can_remove ) {
1339
+            if (!$invoice->is_paid() && !$invoice->is_refunded() && $can_remove) {
1340 1340
                 $line_item .= '<i class="fa fa-remove wpinv-item-remove"></i>';
1341 1341
             }
1342 1342
             $line_item .= '</td>';
1343 1343
         $line_item .= '</tr>';
1344 1344
 
1345
-        echo apply_filters( 'wpinv_admin_line_item', $line_item, $cart_item, $invoice );
1345
+        echo apply_filters('wpinv_admin_line_item', $line_item, $cart_item, $invoice);
1346 1346
 
1347 1347
         $count++;
1348 1348
     } 
1349 1349
 
1350
-    do_action( 'wpinv_admin_after_line_items', $cart_items, $invoice );
1350
+    do_action('wpinv_admin_after_line_items', $cart_items, $invoice);
1351 1351
 
1352 1352
     return ob_get_clean();
1353 1353
 }
@@ -1358,35 +1358,35 @@  discard block
 block discarded – undo
1358 1358
     // Set current invoice id.
1359 1359
     $wpi_checkout_id = wpinv_get_invoice_cart_id();
1360 1360
 
1361
-    $form_action  = esc_url( wpinv_get_checkout_uri() );
1361
+    $form_action = esc_url(wpinv_get_checkout_uri());
1362 1362
 
1363 1363
     ob_start();
1364 1364
         echo '<div id="wpinv_checkout_wrap">';
1365 1365
 
1366
-        if ( wpinv_get_cart_contents() || wpinv_cart_has_fees() ) {
1366
+        if (wpinv_get_cart_contents() || wpinv_cart_has_fees()) {
1367 1367
             ?>
1368 1368
             <div id="wpinv_checkout_form_wrap" class="wpinv_clearfix table-responsive">
1369
-                <?php do_action( 'wpinv_before_checkout_form' ); ?>
1369
+                <?php do_action('wpinv_before_checkout_form'); ?>
1370 1370
                 <form id="wpinv_checkout_form" class="wpi-form" action="<?php echo $form_action; ?>" method="POST">
1371 1371
                     <?php
1372
-                    do_action( 'wpinv_checkout_form_top' );
1373
-                    do_action( 'wpinv_checkout_billing_info' );
1374
-                    do_action( 'wpinv_checkout_cart' );
1375
-                    do_action( 'wpinv_payment_mode_select'  );
1376
-                    do_action( 'wpinv_checkout_form_bottom' )
1372
+                    do_action('wpinv_checkout_form_top');
1373
+                    do_action('wpinv_checkout_billing_info');
1374
+                    do_action('wpinv_checkout_cart');
1375
+                    do_action('wpinv_payment_mode_select');
1376
+                    do_action('wpinv_checkout_form_bottom')
1377 1377
                     ?>
1378 1378
                 </form>
1379
-                <?php do_action( 'wpinv_after_purchase_form' ); ?>
1379
+                <?php do_action('wpinv_after_purchase_form'); ?>
1380 1380
             </div><!--end #wpinv_checkout_form_wrap-->
1381 1381
         <?php
1382 1382
         } else {
1383
-            do_action( 'wpinv_cart_empty' );
1383
+            do_action('wpinv_cart_empty');
1384 1384
         }
1385 1385
         echo '</div><!--end #wpinv_checkout_wrap-->';
1386 1386
     return ob_get_clean();
1387 1387
 }
1388 1388
 
1389
-function wpinv_checkout_cart( $cart_details = array(), $echo = true ) {
1389
+function wpinv_checkout_cart($cart_details = array(), $echo = true) {
1390 1390
     global $ajax_cart_details;
1391 1391
     $ajax_cart_details = $cart_details;
1392 1392
     /*
@@ -1401,25 +1401,25 @@  discard block
 block discarded – undo
1401 1401
     }
1402 1402
     */
1403 1403
     ob_start();
1404
-    do_action( 'wpinv_before_checkout_cart' );
1404
+    do_action('wpinv_before_checkout_cart');
1405 1405
     echo '<div id="wpinv_checkout_cart_form" method="post">';
1406 1406
         echo '<div id="wpinv_checkout_cart_wrap">';
1407
-            wpinv_get_template_part( 'wpinv-checkout-cart' );
1407
+            wpinv_get_template_part('wpinv-checkout-cart');
1408 1408
         echo '</div>';
1409 1409
     echo '</div>';
1410
-    do_action( 'wpinv_after_checkout_cart' );
1410
+    do_action('wpinv_after_checkout_cart');
1411 1411
     $content = ob_get_clean();
1412 1412
     
1413
-    if ( $echo ) {
1413
+    if ($echo) {
1414 1414
         echo $content;
1415 1415
     } else {
1416 1416
         return $content;
1417 1417
     }
1418 1418
 }
1419
-add_action( 'wpinv_checkout_cart', 'wpinv_checkout_cart', 10 );
1419
+add_action('wpinv_checkout_cart', 'wpinv_checkout_cart', 10);
1420 1420
 
1421 1421
 function wpinv_empty_cart_message() {
1422
-	return apply_filters( 'wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __( 'Your cart is empty.', 'invoicing' ) . '</span>' );
1422
+	return apply_filters('wpinv_empty_cart_message', '<span class="wpinv_empty_cart">' . __('Your cart is empty.', 'invoicing') . '</span>');
1423 1423
 }
1424 1424
 
1425 1425
 /**
@@ -1431,91 +1431,91 @@  discard block
 block discarded – undo
1431 1431
 function wpinv_empty_checkout_cart() {
1432 1432
 	echo wpinv_empty_cart_message();
1433 1433
 }
1434
-add_action( 'wpinv_cart_empty', 'wpinv_empty_checkout_cart' );
1434
+add_action('wpinv_cart_empty', 'wpinv_empty_checkout_cart');
1435 1435
 
1436 1436
 function wpinv_save_cart_button() {
1437
-    if ( wpinv_is_cart_saving_disabled() )
1437
+    if (wpinv_is_cart_saving_disabled())
1438 1438
         return;
1439 1439
 ?>
1440
-    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url( add_query_arg( 'wpi_action', 'save_cart' ) ); ?>"><?php _e( 'Save Cart', 'invoicing' ); ?></a>
1440
+    <a class="wpinv-cart-saving-button wpinv-submit button" id="wpinv-save-cart-button" href="<?php echo esc_url(add_query_arg('wpi_action', 'save_cart')); ?>"><?php _e('Save Cart', 'invoicing'); ?></a>
1441 1441
 <?php
1442 1442
 }
1443 1443
 
1444 1444
 function wpinv_update_cart_button() {
1445
-    if ( !wpinv_item_quantities_enabled() )
1445
+    if (!wpinv_item_quantities_enabled())
1446 1446
         return;
1447 1447
 ?>
1448
-    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e( 'Update Cart', 'invoicing' ); ?>"/>
1448
+    <input type="submit" name="wpinv_update_cart_submit" class="wpinv-submit wpinv-no-js button" value="<?php _e('Update Cart', 'invoicing'); ?>"/>
1449 1449
     <input type="hidden" name="wpi_action" value="update_cart"/>
1450 1450
 <?php
1451 1451
 }
1452 1452
 
1453 1453
 function wpinv_checkout_cart_columns() {
1454 1454
     $default = 3;
1455
-    if ( wpinv_item_quantities_enabled() ) {
1455
+    if (wpinv_item_quantities_enabled()) {
1456 1456
         $default++;
1457 1457
     }
1458 1458
     
1459
-    if ( wpinv_use_taxes() ) {
1459
+    if (wpinv_use_taxes()) {
1460 1460
         $default++;
1461 1461
     }
1462 1462
 
1463
-    return apply_filters( 'wpinv_checkout_cart_columns', $default );
1463
+    return apply_filters('wpinv_checkout_cart_columns', $default);
1464 1464
 }
1465 1465
 
1466 1466
 function wpinv_display_cart_messages() {
1467 1467
     global $wpi_session;
1468 1468
 
1469
-    $messages = $wpi_session->get( 'wpinv_cart_messages' );
1469
+    $messages = $wpi_session->get('wpinv_cart_messages');
1470 1470
 
1471
-    if ( $messages ) {
1472
-        foreach ( $messages as $message_id => $message ) {
1471
+    if ($messages) {
1472
+        foreach ($messages as $message_id => $message) {
1473 1473
             // Try and detect what type of message this is
1474
-            if ( strpos( strtolower( $message ), 'error' ) ) {
1474
+            if (strpos(strtolower($message), 'error')) {
1475 1475
                 $type = 'error';
1476
-            } elseif ( strpos( strtolower( $message ), 'success' ) ) {
1476
+            } elseif (strpos(strtolower($message), 'success')) {
1477 1477
                 $type = 'success';
1478 1478
             } else {
1479 1479
                 $type = 'info';
1480 1480
             }
1481 1481
 
1482
-            $classes = apply_filters( 'wpinv_' . $type . '_class', array( 'wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type ) );
1482
+            $classes = apply_filters('wpinv_' . $type . '_class', array('wpinv_errors', 'wpinv-alert', 'wpinv-alert-' . $type));
1483 1483
 
1484
-            echo '<div class="' . implode( ' ', $classes ) . '">';
1484
+            echo '<div class="' . implode(' ', $classes) . '">';
1485 1485
                 // Loop message codes and display messages
1486 1486
                     echo '<p class="wpinv_error" id="wpinv_msg_' . $message_id . '">' . $message . '</p>';
1487 1487
             echo '</div>';
1488 1488
         }
1489 1489
 
1490 1490
         // Remove all of the cart saving messages
1491
-        $wpi_session->set( 'wpinv_cart_messages', null );
1491
+        $wpi_session->set('wpinv_cart_messages', null);
1492 1492
     }
1493 1493
 }
1494
-add_action( 'wpinv_before_checkout_cart', 'wpinv_display_cart_messages' );
1494
+add_action('wpinv_before_checkout_cart', 'wpinv_display_cart_messages');
1495 1495
 
1496 1496
 function wpinv_discount_field() {
1497
-    if ( isset( $_GET['wpi-gateway'] ) && wpinv_is_ajax_disabled() ) {
1497
+    if (isset($_GET['wpi-gateway']) && wpinv_is_ajax_disabled()) {
1498 1498
         return; // Only show before a payment method has been selected if ajax is disabled
1499 1499
     }
1500 1500
 
1501
-    if ( !wpinv_is_checkout() ) {
1501
+    if (!wpinv_is_checkout()) {
1502 1502
         return;
1503 1503
     }
1504 1504
 
1505
-    if ( wpinv_has_active_discounts() && wpinv_get_cart_total() ) {
1505
+    if (wpinv_has_active_discounts() && wpinv_get_cart_total()) {
1506 1506
     ?>
1507 1507
     <div id="wpinv-discount-field" class="panel panel-default">
1508 1508
         <div class="panel-body">
1509 1509
             <p>
1510
-                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e( 'Discount', 'invoicing' ); ?></strong></label>
1511
-                <span class="wpinv-description"><?php _e( 'Enter a discount code if you have one.', 'invoicing' ); ?></span>
1510
+                <label class="wpinv-label" for="wpinv_discount_code"><strong><?php _e('Discount', 'invoicing'); ?></strong></label>
1511
+                <span class="wpinv-description"><?php _e('Enter a discount code if you have one.', 'invoicing'); ?></span>
1512 1512
             </p>
1513 1513
             <div class="form-group row">
1514 1514
                 <div class="col-sm-4">
1515
-                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e( 'Enter discount code', 'invoicing' ); ?>"/>
1515
+                    <input class="wpinv-input form-control" type="text" id="wpinv_discount_code" name="wpinv_discount_code" placeholder="<?php _e('Enter discount code', 'invoicing'); ?>"/>
1516 1516
                 </div>
1517 1517
                 <div class="col-sm-3">
1518
-                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e( 'Apply Discount', 'invoicing' ); ?></button>
1518
+                    <button id="wpi-apply-discount" type="button" class="btn btn-success btn-sm"><?php _e('Apply Discount', 'invoicing'); ?></button>
1519 1519
                 </div>
1520 1520
                 <div style="clear:both"></div>
1521 1521
                 <div class="col-sm-12 wpinv-discount-msg">
@@ -1528,10 +1528,10 @@  discard block
 block discarded – undo
1528 1528
 <?php
1529 1529
     }
1530 1530
 }
1531
-add_action( 'wpinv_after_checkout_cart', 'wpinv_discount_field', -10 );
1531
+add_action('wpinv_after_checkout_cart', 'wpinv_discount_field', -10);
1532 1532
 
1533 1533
 function wpinv_agree_to_terms_js() {
1534
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1534
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1535 1535
 ?>
1536 1536
 <script type="text/javascript">
1537 1537
     jQuery(document).ready(function($){
@@ -1546,126 +1546,126 @@  discard block
 block discarded – undo
1546 1546
 <?php
1547 1547
     }
1548 1548
 }
1549
-add_action( 'wpinv_checkout_form_top', 'wpinv_agree_to_terms_js' );
1549
+add_action('wpinv_checkout_form_top', 'wpinv_agree_to_terms_js');
1550 1550
 
1551 1551
 function wpinv_payment_mode_select() {
1552
-    $gateways = wpinv_get_enabled_payment_gateways( true );
1553
-    $gateways = apply_filters( 'wpinv_payment_gateways_on_cart', $gateways );
1552
+    $gateways = wpinv_get_enabled_payment_gateways(true);
1553
+    $gateways = apply_filters('wpinv_payment_gateways_on_cart', $gateways);
1554 1554
     $page_URL = wpinv_get_current_page_url();
1555
-    $invoice = wpinv_get_invoice( 0, true );
1555
+    $invoice = wpinv_get_invoice(0, true);
1556 1556
 
1557 1557
     do_action('wpinv_payment_mode_top');
1558 1558
     $invoice_id = (int)$invoice->ID;
1559
-    $chosen_gateway = wpinv_get_chosen_gateway( $invoice_id );
1559
+    $chosen_gateway = wpinv_get_chosen_gateway($invoice_id);
1560 1560
     ?>
1561
-    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ( $invoice->is_free() ? 'style="display:none;" data-free="1"' : '' ); ?>>
1562
-            <?php do_action( 'wpinv_payment_mode_before_gateways_wrap' ); ?>
1561
+    <div id="wpinv_payment_mode_select" data-gateway="<?php echo $chosen_gateway; ?>" <?php echo ($invoice->is_free() ? 'style="display:none;" data-free="1"' : ''); ?>>
1562
+            <?php do_action('wpinv_payment_mode_before_gateways_wrap'); ?>
1563 1563
             <div id="wpinv-payment-mode-wrap" class="panel panel-default">
1564
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Select Payment Method', 'invoicing' ); ?></h3></div>
1564
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Select Payment Method', 'invoicing'); ?></h3></div>
1565 1565
                 <div class="panel-body list-group wpi-payment_methods">
1566 1566
                     <?php
1567
-                    do_action( 'wpinv_payment_mode_before_gateways' );
1567
+                    do_action('wpinv_payment_mode_before_gateways');
1568 1568
 
1569
-                    if ( !empty( $gateways ) ) {
1570
-                        foreach ( $gateways as $gateway_id => $gateway ) {
1571
-                            $checked = checked( $gateway_id, $chosen_gateway, false );
1572
-                            $button_label = wpinv_get_gateway_button_label( $gateway_id );
1573
-                            $description = wpinv_get_gateway_description( $gateway_id );
1569
+                    if (!empty($gateways)) {
1570
+                        foreach ($gateways as $gateway_id => $gateway) {
1571
+                            $checked = checked($gateway_id, $chosen_gateway, false);
1572
+                            $button_label = wpinv_get_gateway_button_label($gateway_id);
1573
+                            $description = wpinv_get_gateway_description($gateway_id);
1574 1574
                             ?>
1575 1575
                             <div class="list-group-item">
1576 1576
                                 <div class="radio">
1577
-                                    <label><input type="radio" data-button-text="<?php echo esc_attr( $button_label );?>" value="<?php echo esc_attr( $gateway_id ) ;?>" <?php echo $checked ;?> id="wpi_gateway_<?php echo esc_attr( $gateway_id );?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html( $gateway['checkout_label'] ); ?></label>
1577
+                                    <label><input type="radio" data-button-text="<?php echo esc_attr($button_label); ?>" value="<?php echo esc_attr($gateway_id); ?>" <?php echo $checked; ?> id="wpi_gateway_<?php echo esc_attr($gateway_id); ?>" name="wpi-gateway" class="wpi-pmethod"><?php echo esc_html($gateway['checkout_label']); ?></label>
1578 1578
                                 </div>
1579
-                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr( $gateway_id );?>" role="alert">
1580
-                                    <?php if ( !empty( $description ) ) { ?>
1581
-                                        <div class="wpi-gateway-desc alert alert-info"><?php _e( $description, 'invoicing' ); ?></div>
1579
+                                <div style="display:none;" class="payment_box wpi_gateway_<?php echo esc_attr($gateway_id); ?>" role="alert">
1580
+                                    <?php if (!empty($description)) { ?>
1581
+                                        <div class="wpi-gateway-desc alert alert-info"><?php _e($description, 'invoicing'); ?></div>
1582 1582
                                     <?php } ?>
1583
-                                    <?php do_action( 'wpinv_' . $gateway_id . '_cc_form', $invoice_id ) ;?>
1583
+                                    <?php do_action('wpinv_' . $gateway_id . '_cc_form', $invoice_id); ?>
1584 1584
                                 </div>
1585 1585
                             </div>
1586 1586
                             <?php
1587 1587
                         }
1588 1588
                     } else {
1589
-                        echo '<div class="alert alert-warning">'. __( 'No payment gateway active', 'invoicing' ) .'</div>';
1589
+                        echo '<div class="alert alert-warning">' . __('No payment gateway active', 'invoicing') . '</div>';
1590 1590
                     }
1591 1591
 
1592
-                    do_action( 'wpinv_payment_mode_after_gateways' );
1592
+                    do_action('wpinv_payment_mode_after_gateways');
1593 1593
                     ?>
1594 1594
                 </div>
1595 1595
             </div>
1596
-            <?php do_action( 'wpinv_payment_mode_after_gateways_wrap' ); ?>
1596
+            <?php do_action('wpinv_payment_mode_after_gateways_wrap'); ?>
1597 1597
     </div>
1598 1598
     <?php
1599 1599
     do_action('wpinv_payment_mode_bottom');
1600 1600
 }
1601
-add_action( 'wpinv_payment_mode_select', 'wpinv_payment_mode_select' );
1601
+add_action('wpinv_payment_mode_select', 'wpinv_payment_mode_select');
1602 1602
 
1603 1603
 function wpinv_checkout_billing_info() {
1604
-    if ( wpinv_is_checkout() ) {
1604
+    if (wpinv_is_checkout()) {
1605 1605
         $logged_in          = is_user_logged_in();
1606 1606
         $billing_details    = wpinv_checkout_billing_details();
1607
-        $selected_country   = !empty( $billing_details['country'] ) ? $billing_details['country'] : wpinv_default_billing_country();
1607
+        $selected_country   = !empty($billing_details['country']) ? $billing_details['country'] : wpinv_default_billing_country();
1608 1608
         ?>
1609 1609
         <div id="wpinv-fields" class="clearfix">
1610 1610
             <div id="wpi-billing" class="wpi-billing clearfix panel panel-default">
1611
-                <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Billing Details', 'invoicing' );?></h3></div>
1611
+                <div class="panel-heading"><h3 class="panel-title"><?php _e('Billing Details', 'invoicing'); ?></h3></div>
1612 1612
                 <div id="wpinv-fields-box" class="panel-body">
1613
-                    <?php do_action( 'wpinv_checkout_billing_fields_first', $billing_details ); ?>
1613
+                    <?php do_action('wpinv_checkout_billing_fields_first', $billing_details); ?>
1614 1614
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1615
-                        <label for="wpinv_first_name" class="wpi-label"><?php _e( 'First Name', 'invoicing' );?><?php if ( wpinv_get_option( 'fname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1615
+                        <label for="wpinv_first_name" class="wpi-label"><?php _e('First Name', 'invoicing'); ?><?php if (wpinv_get_option('fname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1616 1616
                         <?php
1617
-                        echo wpinv_html_text( array(
1617
+                        echo wpinv_html_text(array(
1618 1618
                                 'id'            => 'wpinv_first_name',
1619 1619
                                 'name'          => 'wpinv_first_name',
1620 1620
                                 'value'         => $billing_details['first_name'],
1621 1621
                                 'class'         => 'wpi-input form-control',
1622
-                                'placeholder'   => __( 'First name', 'invoicing' ),
1623
-                                'required'      => (bool)wpinv_get_option( 'fname_mandatory' ),
1624
-                            ) );
1622
+                                'placeholder'   => __('First name', 'invoicing'),
1623
+                                'required'      => (bool)wpinv_get_option('fname_mandatory'),
1624
+                            ));
1625 1625
                         ?>
1626 1626
                     </p>
1627 1627
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1628
-                        <label for="wpinv_last_name" class="wpi-label"><?php _e( 'Last Name', 'invoicing' );?><?php if ( wpinv_get_option( 'lname_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1628
+                        <label for="wpinv_last_name" class="wpi-label"><?php _e('Last Name', 'invoicing'); ?><?php if (wpinv_get_option('lname_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1629 1629
                         <?php
1630
-                        echo wpinv_html_text( array(
1630
+                        echo wpinv_html_text(array(
1631 1631
                                 'id'            => 'wpinv_last_name',
1632 1632
                                 'name'          => 'wpinv_last_name',
1633 1633
                                 'value'         => $billing_details['last_name'],
1634 1634
                                 'class'         => 'wpi-input form-control',
1635
-                                'placeholder'   => __( 'Last name', 'invoicing' ),
1636
-                                'required'      => (bool)wpinv_get_option( 'lname_mandatory' ),
1637
-                            ) );
1635
+                                'placeholder'   => __('Last name', 'invoicing'),
1636
+                                'required'      => (bool)wpinv_get_option('lname_mandatory'),
1637
+                            ));
1638 1638
                         ?>
1639 1639
                     </p>
1640 1640
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1641
-                        <label for="wpinv_address" class="wpi-label"><?php _e( 'Address', 'invoicing' );?><?php if ( wpinv_get_option( 'address_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1641
+                        <label for="wpinv_address" class="wpi-label"><?php _e('Address', 'invoicing'); ?><?php if (wpinv_get_option('address_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1642 1642
                         <?php
1643
-                        echo wpinv_html_text( array(
1643
+                        echo wpinv_html_text(array(
1644 1644
                                 'id'            => 'wpinv_address',
1645 1645
                                 'name'          => 'wpinv_address',
1646 1646
                                 'value'         => $billing_details['address'],
1647 1647
                                 'class'         => 'wpi-input form-control',
1648
-                                'placeholder'   => __( 'Address', 'invoicing' ),
1649
-                                'required'      => (bool)wpinv_get_option( 'address_mandatory' ),
1650
-                            ) );
1648
+                                'placeholder'   => __('Address', 'invoicing'),
1649
+                                'required'      => (bool)wpinv_get_option('address_mandatory'),
1650
+                            ));
1651 1651
                         ?>
1652 1652
                     </p>
1653 1653
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1654
-                        <label for="wpinv_city" class="wpi-label"><?php _e( 'City', 'invoicing' );?><?php if ( wpinv_get_option( 'city_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1654
+                        <label for="wpinv_city" class="wpi-label"><?php _e('City', 'invoicing'); ?><?php if (wpinv_get_option('city_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1655 1655
                         <?php
1656
-                        echo wpinv_html_text( array(
1656
+                        echo wpinv_html_text(array(
1657 1657
                                 'id'            => 'wpinv_city',
1658 1658
                                 'name'          => 'wpinv_city',
1659 1659
                                 'value'         => $billing_details['city'],
1660 1660
                                 'class'         => 'wpi-input form-control',
1661
-                                'placeholder'   => __( 'City', 'invoicing' ),
1662
-                                'required'      => (bool)wpinv_get_option( 'city_mandatory' ),
1663
-                            ) );
1661
+                                'placeholder'   => __('City', 'invoicing'),
1662
+                                'required'      => (bool)wpinv_get_option('city_mandatory'),
1663
+                            ));
1664 1664
                         ?>
1665 1665
                     </p>
1666 1666
                     <p id="wpinv_country_box" class="wpi-cart-field wpi-col2 wpi-colf">
1667
-                        <label for="wpinv_country" class="wpi-label"><?php _e( 'Country', 'invoicing' );?><?php if ( wpinv_get_option( 'country_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1668
-                        <?php echo wpinv_html_select( array(
1667
+                        <label for="wpinv_country" class="wpi-label"><?php _e('Country', 'invoicing'); ?><?php if (wpinv_get_option('country_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1668
+                        <?php echo wpinv_html_select(array(
1669 1669
                             'options'          => wpinv_get_country_list(),
1670 1670
                             'name'             => 'wpinv_country',
1671 1671
                             'id'               => 'wpinv_country',
@@ -1673,16 +1673,16 @@  discard block
 block discarded – undo
1673 1673
                             'show_option_all'  => false,
1674 1674
                             'show_option_none' => false,
1675 1675
                             'class'            => 'wpi-input form-control',
1676
-                            'placeholder'      => __( 'Choose a country', 'invoicing' ),
1677
-                            'required'         => (bool)wpinv_get_option( 'country_mandatory' ),
1678
-                        ) ); ?>
1676
+                            'placeholder'      => __('Choose a country', 'invoicing'),
1677
+                            'required'         => (bool)wpinv_get_option('country_mandatory'),
1678
+                        )); ?>
1679 1679
                     </p>
1680 1680
                     <p id="wpinv_state_box" class="wpi-cart-field wpi-col2 wpi-coll">
1681
-                        <label for="wpinv_state" class="wpi-label"><?php _e( 'State / Province', 'invoicing' );?><?php if ( wpinv_get_option( 'state_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1681
+                        <label for="wpinv_state" class="wpi-label"><?php _e('State / Province', 'invoicing'); ?><?php if (wpinv_get_option('state_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1682 1682
                         <?php
1683
-                        $states = wpinv_get_country_states( $selected_country );
1684
-                        if( !empty( $states ) ) {
1685
-                            echo wpinv_html_select( array(
1683
+                        $states = wpinv_get_country_states($selected_country);
1684
+                        if (!empty($states)) {
1685
+                            echo wpinv_html_select(array(
1686 1686
                                 'options'          => $states,
1687 1687
                                 'name'             => 'wpinv_state',
1688 1688
                                 'id'               => 'wpinv_state',
@@ -1690,61 +1690,61 @@  discard block
 block discarded – undo
1690 1690
                                 'show_option_all'  => false,
1691 1691
                                 'show_option_none' => false,
1692 1692
                                 'class'            => 'wpi-input form-control',
1693
-                                'placeholder'      => __( 'Choose a state', 'invoicing' ),
1694
-                                'required'         => (bool)wpinv_get_option( 'state_mandatory' ),
1695
-                            ) );
1693
+                                'placeholder'      => __('Choose a state', 'invoicing'),
1694
+                                'required'         => (bool)wpinv_get_option('state_mandatory'),
1695
+                            ));
1696 1696
                         } else {
1697
-                            echo wpinv_html_text( array(
1697
+                            echo wpinv_html_text(array(
1698 1698
                                 'name'          => 'wpinv_state',
1699 1699
                                 'value'         => $billing_details['state'],
1700 1700
                                 'id'            => 'wpinv_state',
1701 1701
                                 'class'         => 'wpi-input form-control',
1702
-                                'placeholder'   => __( 'State / Province', 'invoicing' ),
1703
-                                'required'      => (bool)wpinv_get_option( 'state_mandatory' ),
1704
-                            ) );
1702
+                                'placeholder'   => __('State / Province', 'invoicing'),
1703
+                                'required'      => (bool)wpinv_get_option('state_mandatory'),
1704
+                            ));
1705 1705
                         }
1706 1706
                         ?>
1707 1707
                     </p>
1708 1708
                     <p class="wpi-cart-field wpi-col2 wpi-colf">
1709
-                        <label for="wpinv_zip" class="wpi-label"><?php _e( 'ZIP / Postcode', 'invoicing' );?><?php if ( wpinv_get_option( 'zip_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1709
+                        <label for="wpinv_zip" class="wpi-label"><?php _e('ZIP / Postcode', 'invoicing'); ?><?php if (wpinv_get_option('zip_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1710 1710
                         <?php
1711
-                        echo wpinv_html_text( array(
1711
+                        echo wpinv_html_text(array(
1712 1712
                                 'name'          => 'wpinv_zip',
1713 1713
                                 'value'         => $billing_details['zip'],
1714 1714
                                 'id'            => 'wpinv_zip',
1715 1715
                                 'class'         => 'wpi-input form-control',
1716
-                                'placeholder'   => __( 'ZIP / Postcode', 'invoicing' ),
1717
-                                'required'      => (bool)wpinv_get_option( 'zip_mandatory' ),
1718
-                            ) );
1716
+                                'placeholder'   => __('ZIP / Postcode', 'invoicing'),
1717
+                                'required'      => (bool)wpinv_get_option('zip_mandatory'),
1718
+                            ));
1719 1719
                         ?>
1720 1720
                     </p>
1721 1721
                     <p class="wpi-cart-field wpi-col2 wpi-coll">
1722
-                        <label for="wpinv_phone" class="wpi-label"><?php _e( 'Phone', 'invoicing' );?><?php if ( wpinv_get_option( 'phone_mandatory' ) ) { echo '<span class="wpi-required">*</span>'; } ?></label>
1722
+                        <label for="wpinv_phone" class="wpi-label"><?php _e('Phone', 'invoicing'); ?><?php if (wpinv_get_option('phone_mandatory')) { echo '<span class="wpi-required">*</span>'; } ?></label>
1723 1723
                         <?php
1724
-                        echo wpinv_html_text( array(
1724
+                        echo wpinv_html_text(array(
1725 1725
                                 'id'            => 'wpinv_phone',
1726 1726
                                 'name'          => 'wpinv_phone',
1727 1727
                                 'value'         => $billing_details['phone'],
1728 1728
                                 'class'         => 'wpi-input form-control',
1729
-                                'placeholder'   => __( 'Phone', 'invoicing' ),
1730
-                                'required'      => (bool)wpinv_get_option( 'phone_mandatory' ),
1731
-                            ) );
1729
+                                'placeholder'   => __('Phone', 'invoicing'),
1730
+                                'required'      => (bool)wpinv_get_option('phone_mandatory'),
1731
+                            ));
1732 1732
                         ?>
1733 1733
                     </p>
1734
-                    <?php do_action( 'wpinv_checkout_billing_fields_last', $billing_details ); ?>
1734
+                    <?php do_action('wpinv_checkout_billing_fields_last', $billing_details); ?>
1735 1735
                     <div class="clearfix"></div>
1736 1736
                 </div>
1737 1737
             </div>
1738
-            <?php do_action( 'wpinv_after_billing_fields', $billing_details ); ?>
1738
+            <?php do_action('wpinv_after_billing_fields', $billing_details); ?>
1739 1739
         </div>
1740 1740
         <?php
1741 1741
     }
1742 1742
 }
1743
-add_action( 'wpinv_checkout_billing_info', 'wpinv_checkout_billing_info' );
1743
+add_action('wpinv_checkout_billing_info', 'wpinv_checkout_billing_info');
1744 1744
 
1745 1745
 function wpinv_checkout_hidden_fields() {
1746 1746
 ?>
1747
-    <?php if ( is_user_logged_in() ) { ?>
1747
+    <?php if (is_user_logged_in()) { ?>
1748 1748
     <input type="hidden" name="wpinv_user_id" value="<?php echo get_current_user_id(); ?>"/>
1749 1749
     <?php } ?>
1750 1750
     <input type="hidden" name="wpi_action" value="payment" />
@@ -1754,9 +1754,9 @@  discard block
 block discarded – undo
1754 1754
 function wpinv_checkout_button_purchase() {
1755 1755
     ob_start();
1756 1756
 ?>
1757
-    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>" name="wpinv_payment" value="<?php esc_attr_e( 'Proceed to Pay', 'invoicing' ) ?>"/>
1757
+    <input type="submit" class="btn btn-success wpinv-submit" id="wpinv-payment-button" data-value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>" name="wpinv_payment" value="<?php esc_attr_e('Proceed to Pay', 'invoicing') ?>"/>
1758 1758
 <?php
1759
-    return apply_filters( 'wpinv_checkout_button_purchase', ob_get_clean() );
1759
+    return apply_filters('wpinv_checkout_button_purchase', ob_get_clean());
1760 1760
 }
1761 1761
 
1762 1762
 function wpinv_checkout_total() {
@@ -1765,116 +1765,116 @@  discard block
 block discarded – undo
1765 1765
 <div id="wpinv_checkout_total" class="panel panel-info">
1766 1766
     <div class="panel-body">
1767 1767
     <?php
1768
-    do_action( 'wpinv_purchase_form_before_checkout_total' );
1768
+    do_action('wpinv_purchase_form_before_checkout_total');
1769 1769
     ?>
1770
-    <strong><?php _e( 'Invoice Total:', 'invoicing' ) ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total;?></span>
1770
+    <strong><?php _e('Invoice Total:', 'invoicing') ?></strong> <span class="wpinv-chdeckout-total"><?php echo $cart_total; ?></span>
1771 1771
     <?php
1772
-    do_action( 'wpinv_purchase_form_after_checkout_total' );
1772
+    do_action('wpinv_purchase_form_after_checkout_total');
1773 1773
     ?>
1774 1774
     </div>
1775 1775
 </div>
1776 1776
 <?php
1777 1777
 }
1778
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998 );
1778
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_total', 9998);
1779 1779
 
1780 1780
 function wpinv_checkout_accept_tandc() {
1781
-    $page = wpinv_get_option( 'tandc_page' );
1781
+    $page = wpinv_get_option('tandc_page');
1782 1782
     ?>
1783 1783
     <div id="wpinv_checkout_tandc" class="panel panel-success">
1784 1784
         <div class="panel-body">
1785 1785
             <?php echo wpinv_get_policy_text(); ?>
1786 1786
             <?php
1787
-            if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1788
-                $terms_link = esc_url( get_permalink( $page ) );
1787
+            if (isset($page) && (int)$page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1788
+                $terms_link = esc_url(get_permalink($page));
1789 1789
                 ?>
1790 1790
                 <label class="">
1791
-                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked( apply_filters( 'wpinv_terms_is_checked_default', isset( $_POST['wpi_terms'] ) ), true ); ?>> <span><?php printf( __( 'I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing' ), $terms_link ); ?></span> <span class="wpi-required">*</span>
1791
+                    <input type="checkbox" class="wpi-terms-checkbox" name="wpi_terms" id="wpi-terms" <?php checked(apply_filters('wpinv_terms_is_checked_default', isset($_POST['wpi_terms'])), true); ?>> <span><?php printf(__('I&rsquo;ve read and accept the <a href="%s" target="_blank" class="wpi-terms-and-conditions-link">terms &amp; conditions</a>', 'invoicing'), $terms_link); ?></span> <span class="wpi-required">*</span>
1792 1792
                 </label>
1793 1793
             <?php } ?>
1794 1794
         </div>
1795 1795
     </div>
1796 1796
     <?php
1797 1797
 }
1798
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995 );
1798
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_accept_tandc', 9995);
1799 1799
 
1800 1800
 function wpinv_checkout_submit() {
1801 1801
 ?>
1802 1802
 <div id="wpinv_purchase_submit" class="panel panel-success">
1803 1803
     <div class="panel-body text-center">
1804 1804
     <?php
1805
-    do_action( 'wpinv_purchase_form_before_submit' );
1805
+    do_action('wpinv_purchase_form_before_submit');
1806 1806
     wpinv_checkout_hidden_fields();
1807 1807
     echo wpinv_checkout_button_purchase();
1808
-    do_action( 'wpinv_purchase_form_after_submit' );
1808
+    do_action('wpinv_purchase_form_after_submit');
1809 1809
     ?>
1810 1810
     </div>
1811 1811
 </div>
1812 1812
 <?php
1813 1813
 }
1814
-add_action( 'wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999 );
1814
+add_action('wpinv_checkout_form_bottom', 'wpinv_checkout_submit', 9999);
1815 1815
 
1816
-function wpinv_receipt_billing_address( $invoice_id = 0 ) {
1817
-    $invoice = wpinv_get_invoice( $invoice_id );
1816
+function wpinv_receipt_billing_address($invoice_id = 0) {
1817
+    $invoice = wpinv_get_invoice($invoice_id);
1818 1818
 
1819
-    if ( empty( $invoice ) ) {
1819
+    if (empty($invoice)) {
1820 1820
         return NULL;
1821 1821
     }
1822 1822
 
1823 1823
     $billing_details = $invoice->get_user_info();
1824 1824
     $address_row = '';
1825
-    if ( $address = $billing_details['address'] ) {
1826
-        $address_row .= wpautop( wp_kses_post( $address ) );
1825
+    if ($address = $billing_details['address']) {
1826
+        $address_row .= wpautop(wp_kses_post($address));
1827 1827
     }
1828 1828
 
1829 1829
     $address_fields = array();
1830
-    if ( !empty( $billing_details['city'] ) ) {
1830
+    if (!empty($billing_details['city'])) {
1831 1831
         $address_fields[] = $billing_details['city'];
1832 1832
     }
1833 1833
 
1834
-    $billing_country = !empty( $billing_details['country'] ) ? $billing_details['country'] : '';
1835
-    if ( !empty( $billing_details['state'] ) ) {
1836
-        $address_fields[] = wpinv_state_name( $billing_details['state'], $billing_country );
1834
+    $billing_country = !empty($billing_details['country']) ? $billing_details['country'] : '';
1835
+    if (!empty($billing_details['state'])) {
1836
+        $address_fields[] = wpinv_state_name($billing_details['state'], $billing_country);
1837 1837
     }
1838 1838
 
1839
-    if ( !empty( $billing_country ) ) {
1840
-        $address_fields[] = wpinv_country_name( $billing_country );
1839
+    if (!empty($billing_country)) {
1840
+        $address_fields[] = wpinv_country_name($billing_country);
1841 1841
     }
1842 1842
 
1843
-    if ( !empty( $address_fields ) ) {
1844
-        $address_fields = implode( ", ", $address_fields );
1843
+    if (!empty($address_fields)) {
1844
+        $address_fields = implode(", ", $address_fields);
1845 1845
 
1846
-        if ( !empty( $billing_details['zip'] ) ) {
1846
+        if (!empty($billing_details['zip'])) {
1847 1847
             $address_fields .= ' ' . $billing_details['zip'];
1848 1848
         }
1849 1849
 
1850
-        $address_row .= wpautop( wp_kses_post( $address_fields ) );
1850
+        $address_row .= wpautop(wp_kses_post($address_fields));
1851 1851
     }
1852 1852
     ob_start();
1853 1853
     ?>
1854 1854
     <table class="table table-bordered table-sm wpi-billing-details">
1855 1855
         <tbody>
1856 1856
             <tr class="wpi-receipt-name">
1857
-                <th class="text-left"><?php _e( 'Name', 'invoicing' ); ?></th>
1858
-                <td><?php echo esc_html( trim( $billing_details['first_name'] . ' ' . $billing_details['last_name'] ) ) ;?></td>
1857
+                <th class="text-left"><?php _e('Name', 'invoicing'); ?></th>
1858
+                <td><?php echo esc_html(trim($billing_details['first_name'] . ' ' . $billing_details['last_name'])); ?></td>
1859 1859
             </tr>
1860 1860
             <tr class="wpi-receipt-email">
1861
-                <th class="text-left"><?php _e( 'Email', 'invoicing' ); ?></th>
1862
-                <td><?php echo $billing_details['email'] ;?></td>
1861
+                <th class="text-left"><?php _e('Email', 'invoicing'); ?></th>
1862
+                <td><?php echo $billing_details['email']; ?></td>
1863 1863
             </tr>
1864
-            <?php if ( $billing_details['company'] ) { ?>
1864
+            <?php if ($billing_details['company']) { ?>
1865 1865
             <tr class="wpi-receipt-company">
1866
-                <th class="text-left"><?php _e( 'Company', 'invoicing' ); ?></th>
1867
-                <td><?php echo esc_html( $billing_details['company'] ) ;?></td>
1866
+                <th class="text-left"><?php _e('Company', 'invoicing'); ?></th>
1867
+                <td><?php echo esc_html($billing_details['company']); ?></td>
1868 1868
             </tr>
1869 1869
             <?php } ?>
1870 1870
             <tr class="wpi-receipt-address">
1871
-                <th class="text-left"><?php _e( 'Address', 'invoicing' ); ?></th>
1872
-                <td><?php echo $address_row ;?></td>
1871
+                <th class="text-left"><?php _e('Address', 'invoicing'); ?></th>
1872
+                <td><?php echo $address_row; ?></td>
1873 1873
             </tr>
1874
-            <?php if ( $billing_details['phone'] ) { ?>
1874
+            <?php if ($billing_details['phone']) { ?>
1875 1875
             <tr class="wpi-receipt-phone">
1876
-                <th class="text-left"><?php _e( 'Phone', 'invoicing' ); ?></th>
1877
-                <td><?php echo esc_html( $billing_details['phone'] ) ;?></td>
1876
+                <th class="text-left"><?php _e('Phone', 'invoicing'); ?></th>
1877
+                <td><?php echo esc_html($billing_details['phone']); ?></td>
1878 1878
             </tr>
1879 1879
             <?php } ?>
1880 1880
         </tbody>
@@ -1882,74 +1882,74 @@  discard block
 block discarded – undo
1882 1882
     <?php
1883 1883
     $output = ob_get_clean();
1884 1884
     
1885
-    $output = apply_filters( 'wpinv_receipt_billing_address', $output, $invoice_id );
1885
+    $output = apply_filters('wpinv_receipt_billing_address', $output, $invoice_id);
1886 1886
 
1887 1887
     echo $output;
1888 1888
 }
1889 1889
 
1890
-function wpinv_filter_success_page_content( $content ) {
1891
-    if ( isset( $_GET['payment-confirm'] ) && wpinv_is_success_page() ) {
1892
-        if ( has_filter( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ) ) ) {
1893
-            $content = apply_filters( 'wpinv_payment_confirm_' . sanitize_text_field( $_GET['payment-confirm'] ), $content );
1890
+function wpinv_filter_success_page_content($content) {
1891
+    if (isset($_GET['payment-confirm']) && wpinv_is_success_page()) {
1892
+        if (has_filter('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']))) {
1893
+            $content = apply_filters('wpinv_payment_confirm_' . sanitize_text_field($_GET['payment-confirm']), $content);
1894 1894
         }
1895 1895
     }
1896 1896
 
1897 1897
     return $content;
1898 1898
 }
1899
-add_filter( 'the_content', 'wpinv_filter_success_page_content', 99999 );
1899
+add_filter('the_content', 'wpinv_filter_success_page_content', 99999);
1900 1900
 
1901
-function wpinv_receipt_actions( $invoice ) {
1902
-    if ( !empty( $invoice ) ) {
1901
+function wpinv_receipt_actions($invoice) {
1902
+    if (!empty($invoice)) {
1903 1903
         $actions = array();
1904 1904
 
1905
-        if ( wpinv_user_can_view_invoice( $invoice->ID ) ) {
1906
-            $actions['print']   = array(
1907
-                'url'  => $invoice->get_view_url( true ),
1908
-                'name' => __( 'Print Invoice', 'invoicing' ),
1905
+        if (wpinv_user_can_view_invoice($invoice->ID)) {
1906
+            $actions['print'] = array(
1907
+                'url'  => $invoice->get_view_url(true),
1908
+                'name' => __('Print Invoice', 'invoicing'),
1909 1909
                 'class' => 'btn-primary',
1910 1910
             );
1911 1911
         }
1912 1912
 
1913
-        if ( is_user_logged_in() ) {
1913
+        if (is_user_logged_in()) {
1914 1914
             $actions['history'] = array(
1915 1915
                 'url'  => wpinv_get_history_page_uri(),
1916
-                'name' => __( 'Invoice History', 'invoicing' ),
1916
+                'name' => __('Invoice History', 'invoicing'),
1917 1917
                 'class' => 'btn-warning',
1918 1918
             );
1919 1919
         }
1920 1920
 
1921
-        $actions = apply_filters( 'wpinv_invoice_receipt_actions', $actions, $invoice );
1921
+        $actions = apply_filters('wpinv_invoice_receipt_actions', $actions, $invoice);
1922 1922
 
1923
-        if ( !empty( $actions ) ) {
1923
+        if (!empty($actions)) {
1924 1924
         ?>
1925 1925
         <div class="wpinv-receipt-actions text-right">
1926
-            <?php foreach ( $actions as $key => $action ) { $class = !empty($action['class']) ? sanitize_html_class( $action['class'] ) : ''; ?>
1927
-            <a href="<?php echo esc_url( $action['url'] );?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class( $key );?>" <?php echo ( !empty($action['attrs']) ? $action['attrs'] : '' ) ;?>><?php echo esc_html( $action['name'] );?></a>
1926
+            <?php foreach ($actions as $key => $action) { $class = !empty($action['class']) ? sanitize_html_class($action['class']) : ''; ?>
1927
+            <a href="<?php echo esc_url($action['url']); ?>" class="btn btn-sm <?php echo $class . ' ' . sanitize_html_class($key); ?>" <?php echo (!empty($action['attrs']) ? $action['attrs'] : ''); ?>><?php echo esc_html($action['name']); ?></a>
1928 1928
             <?php } ?>
1929 1929
         </div>
1930 1930
         <?php
1931 1931
         }
1932 1932
     }
1933 1933
 }
1934
-add_action( 'wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1 );
1934
+add_action('wpinv_receipt_start', 'wpinv_receipt_actions', -10, 1);
1935 1935
 
1936
-function wpinv_invoice_link( $invoice_id ) {
1937
-    $invoice = wpinv_get_invoice( $invoice_id );
1936
+function wpinv_invoice_link($invoice_id) {
1937
+    $invoice = wpinv_get_invoice($invoice_id);
1938 1938
 
1939
-    if ( empty( $invoice ) ) {
1939
+    if (empty($invoice)) {
1940 1940
         return NULL;
1941 1941
     }
1942 1942
 
1943
-    $invoice_link = '<a href="' . esc_url( $invoice->get_view_url() ) . '">' . $invoice->get_number() . '</a>';
1943
+    $invoice_link = '<a href="' . esc_url($invoice->get_view_url()) . '">' . $invoice->get_number() . '</a>';
1944 1944
 
1945
-    return apply_filters( 'wpinv_get_invoice_link', $invoice_link, $invoice );
1945
+    return apply_filters('wpinv_get_invoice_link', $invoice_link, $invoice);
1946 1946
 }
1947 1947
 
1948
-function wpinv_invoice_subscription_details( $invoice ) {
1949
-    if ( !empty( $invoice ) && $invoice->is_recurring() && ! wpinv_is_subscription_payment( $invoice ) ) {
1950
-        $subscription = wpinv_get_subscription( $invoice, true );
1948
+function wpinv_invoice_subscription_details($invoice) {
1949
+    if (!empty($invoice) && $invoice->is_recurring() && !wpinv_is_subscription_payment($invoice)) {
1950
+        $subscription = wpinv_get_subscription($invoice, true);
1951 1951
 
1952
-        if ( empty( $subscription ) ) {
1952
+        if (empty($subscription)) {
1953 1953
             return;
1954 1954
         }
1955 1955
 
@@ -1960,15 +1960,15 @@  discard block
 block discarded – undo
1960 1960
         $payments = $subscription->get_child_payments();
1961 1961
         ?>
1962 1962
         <div class="wpinv-subscriptions-details">
1963
-            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters( 'wpinv_subscription_details_title', __( 'Subscription Details', 'invoicing' ) ); ?></h3>
1963
+            <h3 class="wpinv-subscriptions-t"><?php echo apply_filters('wpinv_subscription_details_title', __('Subscription Details', 'invoicing')); ?></h3>
1964 1964
             <table class="table">
1965 1965
                 <thead>
1966 1966
                     <tr>
1967
-                        <th><?php _e( 'Billing Cycle', 'invoicing' ) ;?></th>
1968
-                        <th><?php _e( 'Start Date', 'invoicing' ) ;?></th>
1969
-                        <th><?php _e( 'Expiration Date', 'invoicing' ) ;?></th>
1970
-                        <th class="text-center"><?php _e( 'Times Billed', 'invoicing' ) ;?></th>
1971
-                        <th class="text-center"><?php _e( 'Status', 'invoicing' ) ;?></th>
1967
+                        <th><?php _e('Billing Cycle', 'invoicing'); ?></th>
1968
+                        <th><?php _e('Start Date', 'invoicing'); ?></th>
1969
+                        <th><?php _e('Expiration Date', 'invoicing'); ?></th>
1970
+                        <th class="text-center"><?php _e('Times Billed', 'invoicing'); ?></th>
1971
+                        <th class="text-center"><?php _e('Status', 'invoicing'); ?></th>
1972 1972
                     </tr>
1973 1973
                 </thead>
1974 1974
                 <tbody>
@@ -1982,29 +1982,29 @@  discard block
 block discarded – undo
1982 1982
                 </tbody>
1983 1983
             </table>
1984 1984
         </div>
1985
-        <?php if ( !empty( $payments ) ) { ?>
1985
+        <?php if (!empty($payments)) { ?>
1986 1986
         <div class="wpinv-renewal-payments">
1987
-            <h3 class="wpinv-renewals-t"><?php echo apply_filters( 'wpinv_renewal_payments_title', __( 'Renewal Payments', 'invoicing' ) ); ?></h3>
1987
+            <h3 class="wpinv-renewals-t"><?php echo apply_filters('wpinv_renewal_payments_title', __('Renewal Payments', 'invoicing')); ?></h3>
1988 1988
             <table class="table">
1989 1989
                 <thead>
1990 1990
                     <tr>
1991 1991
                         <th>#</th>
1992
-                        <th><?php _e( 'Invoice', 'invoicing' ) ;?></th>
1993
-                        <th><?php _e( 'Date', 'invoicing' ) ;?></th>
1994
-                        <th class="text-right"><?php _e( 'Amount', 'invoicing' ) ;?></th>
1992
+                        <th><?php _e('Invoice', 'invoicing'); ?></th>
1993
+                        <th><?php _e('Date', 'invoicing'); ?></th>
1994
+                        <th class="text-right"><?php _e('Amount', 'invoicing'); ?></th>
1995 1995
                     </tr>
1996 1996
                 </thead>
1997 1997
                 <tbody>
1998 1998
                     <?php
1999 1999
                         $i = 1;
2000
-                        foreach ( $payments as $payment ) {
2000
+                        foreach ($payments as $payment) {
2001 2001
                             $invoice_id = $payment->ID;
2002 2002
                     ?>
2003 2003
                     <tr>
2004
-                        <th scope="row"><?php echo $i;?></th>
2005
-                        <td><?php echo wpinv_invoice_link( $invoice_id ) ;?></td>
2006
-                        <td><?php echo wpinv_get_invoice_date( $invoice_id ); ?></td>
2007
-                        <td class="text-right"><?php echo wpinv_payment_total( $invoice_id, true ); ?></td>
2004
+                        <th scope="row"><?php echo $i; ?></th>
2005
+                        <td><?php echo wpinv_invoice_link($invoice_id); ?></td>
2006
+                        <td><?php echo wpinv_get_invoice_date($invoice_id); ?></td>
2007
+                        <td class="text-right"><?php echo wpinv_payment_total($invoice_id, true); ?></td>
2008 2008
                     </tr>
2009 2009
                     <?php $i++; } ?>
2010 2010
                 </tbody>
@@ -2015,52 +2015,52 @@  discard block
 block discarded – undo
2015 2015
     }
2016 2016
 }
2017 2017
 
2018
-function wpinv_cart_total_label( $label, $invoice ) {
2019
-    if ( empty( $invoice ) ) {
2018
+function wpinv_cart_total_label($label, $invoice) {
2019
+    if (empty($invoice)) {
2020 2020
         return $label;
2021 2021
     }
2022 2022
 
2023 2023
     $prefix_label = '';
2024
-    if ( $invoice->is_parent() && $item_id = $invoice->get_recurring() ) {
2025
-        $prefix_label   = '<span class="label label-primary label-recurring">' . __( 'Recurring Payment', 'invoicing' ) . '</span> ' . wpinv_subscription_payment_desc( $invoice );
2026
-    } else if ( $invoice->is_renewal() ) {
2027
-        $prefix_label   = '<span class="label label-primary label-renewal">' . __( 'Renewal Payment', 'invoicing' ) . '</span> ';        
2024
+    if ($invoice->is_parent() && $item_id = $invoice->get_recurring()) {
2025
+        $prefix_label   = '<span class="label label-primary label-recurring">' . __('Recurring Payment', 'invoicing') . '</span> ' . wpinv_subscription_payment_desc($invoice);
2026
+    } else if ($invoice->is_renewal()) {
2027
+        $prefix_label   = '<span class="label label-primary label-renewal">' . __('Renewal Payment', 'invoicing') . '</span> ';        
2028 2028
     }
2029 2029
 
2030
-    if ( $prefix_label != '' ) {
2031
-        $label  = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2030
+    if ($prefix_label != '') {
2031
+        $label = '<span class="wpinv-cart-sub-desc">' . $prefix_label . '</span> ' . $label;
2032 2032
     }
2033 2033
 
2034 2034
     return $label;
2035 2035
 }
2036
-add_filter( 'wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2037
-add_filter( 'wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2038
-add_filter( 'wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2 );
2036
+add_filter('wpinv_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2037
+add_filter('wpinv_email_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2038
+add_filter('wpinv_print_cart_total_label', 'wpinv_cart_total_label', 10, 2);
2039 2039
 
2040
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1 );
2040
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_subscription_details', 10, 1);
2041 2041
 
2042
-function wpinv_invoice_print_description( $invoice ) {
2043
-    if ( empty( $invoice ) ) {
2042
+function wpinv_invoice_print_description($invoice) {
2043
+    if (empty($invoice)) {
2044 2044
         return NULL;
2045 2045
     }
2046
-    if ( $description = wpinv_get_invoice_description( $invoice->ID ) ) {
2046
+    if ($description = wpinv_get_invoice_description($invoice->ID)) {
2047 2047
         ?>
2048 2048
         <div class="row wpinv-lower">
2049 2049
             <div class="col-sm-12 wpinv-description">
2050
-                <?php echo wpautop( $description ); ?>
2050
+                <?php echo wpautop($description); ?>
2051 2051
             </div>
2052 2052
         </div>
2053 2053
         <?php
2054 2054
     }
2055 2055
 }
2056
-add_action( 'wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1 );
2056
+add_action('wpinv_invoice_print_middle', 'wpinv_invoice_print_description', 10.1, 1);
2057 2057
 
2058
-function wpinv_invoice_print_payment_info( $invoice ) {
2059
-    if ( empty( $invoice ) ) {
2058
+function wpinv_invoice_print_payment_info($invoice) {
2059
+    if (empty($invoice)) {
2060 2060
         return NULL;
2061 2061
     }
2062 2062
 
2063
-    if ( $payments_info = wpinv_display_payments_info( $invoice->ID, false ) ) {
2063
+    if ($payments_info = wpinv_display_payments_info($invoice->ID, false)) {
2064 2064
         ?>
2065 2065
         <div class="row wpinv-payments">
2066 2066
             <div class="col-sm-12">
@@ -2072,43 +2072,43 @@  discard block
 block discarded – undo
2072 2072
 }
2073 2073
 // add_action( 'wpinv_invoice_print_after_line_items', 'wpinv_invoice_print_payment_info', 10, 1 );
2074 2074
 
2075
-function wpinv_get_invoice_note_line_item( $note, $echo = true ) {
2076
-    if ( empty( $note ) ) {
2075
+function wpinv_get_invoice_note_line_item($note, $echo = true) {
2076
+    if (empty($note)) {
2077 2077
         return NULL;
2078 2078
     }
2079 2079
 
2080
-    if ( is_int( $note ) ) {
2081
-        $note = get_comment( $note );
2080
+    if (is_int($note)) {
2081
+        $note = get_comment($note);
2082 2082
     }
2083 2083
 
2084
-    if ( !( is_object( $note ) && is_a( $note, 'WP_Comment' ) ) ) {
2084
+    if (!(is_object($note) && is_a($note, 'WP_Comment'))) {
2085 2085
         return NULL;
2086 2086
     }
2087 2087
 
2088
-    $note_classes   = array( 'note' );
2089
-    $note_classes[] = get_comment_meta( $note->comment_ID, '_wpi_customer_note', true ) ? 'customer-note' : '';
2088
+    $note_classes   = array('note');
2089
+    $note_classes[] = get_comment_meta($note->comment_ID, '_wpi_customer_note', true) ? 'customer-note' : '';
2090 2090
     $note_classes[] = $note->comment_author === 'System' ? 'system-note' : '';
2091
-    $note_classes   = apply_filters( 'wpinv_invoice_note_class', array_filter( $note_classes ), $note );
2092
-    $note_classes   = !empty( $note_classes ) ? implode( ' ', $note_classes ) : '';
2091
+    $note_classes   = apply_filters('wpinv_invoice_note_class', array_filter($note_classes), $note);
2092
+    $note_classes   = !empty($note_classes) ? implode(' ', $note_classes) : '';
2093 2093
 
2094 2094
     ob_start();
2095 2095
     ?>
2096
-    <li rel="<?php echo absint( $note->comment_ID ) ; ?>" class="<?php echo esc_attr( $note_classes ); ?>">
2096
+    <li rel="<?php echo absint($note->comment_ID); ?>" class="<?php echo esc_attr($note_classes); ?>">
2097 2097
         <div class="note_content">
2098
-            <?php echo wpautop( wptexturize( wp_kses_post( $note->comment_content ) ) ); ?>
2098
+            <?php echo wpautop(wptexturize(wp_kses_post($note->comment_content))); ?>
2099 2099
         </div>
2100 2100
         <p class="meta">
2101
-            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf( __( '%1$s - %2$s at %3$s', 'invoicing' ), $note->comment_author, date_i18n( get_option( 'date_format' ), strtotime( $note->comment_date ) ), date_i18n( get_option( 'time_format' ), strtotime( $note->comment_date ) ) ); ?></abbr>&nbsp;&nbsp;
2102
-            <?php if ( $note->comment_author !== 'System' || current_user_can( 'manage_options' ) ) { ?>
2103
-                <a href="#" class="delete_note"><?php _e( 'Delete note', 'invoicing' ); ?></a>
2101
+            <abbr class="exact-date" title="<?php echo $note->comment_date; ?>"><?php printf(__('%1$s - %2$s at %3$s', 'invoicing'), $note->comment_author, date_i18n(get_option('date_format'), strtotime($note->comment_date)), date_i18n(get_option('time_format'), strtotime($note->comment_date))); ?></abbr>&nbsp;&nbsp;
2102
+            <?php if ($note->comment_author !== 'System' || current_user_can('manage_options')) { ?>
2103
+                <a href="#" class="delete_note"><?php _e('Delete note', 'invoicing'); ?></a>
2104 2104
             <?php } ?>
2105 2105
         </p>
2106 2106
     </li>
2107 2107
     <?php
2108 2108
     $note_content = ob_get_clean();
2109
-    $note_content = apply_filters( 'wpinv_get_invoice_note_line_item', $note_content, $note, $echo );
2109
+    $note_content = apply_filters('wpinv_get_invoice_note_line_item', $note_content, $note, $echo);
2110 2110
 
2111
-    if ( $echo ) {
2111
+    if ($echo) {
2112 2112
         echo $note_content;
2113 2113
     } else {
2114 2114
         return $note_content;
@@ -2118,43 +2118,43 @@  discard block
 block discarded – undo
2118 2118
 function wpinv_invalid_invoice_content() {
2119 2119
     global $post;
2120 2120
 
2121
-    $invoice = wpinv_get_invoice( $post->ID );
2121
+    $invoice = wpinv_get_invoice($post->ID);
2122 2122
 
2123
-    $error = __( 'This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing' );
2124
-    if ( !empty( $invoice->ID ) && $invoice->has_status( array_keys( wpinv_get_invoice_statuses() ) ) ) {
2125
-        if ( is_user_logged_in() ) {
2126
-            if ( wpinv_require_login_to_checkout() ) {
2127
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2128
-                    $error = __( 'You are not allowed to view this invoice.', 'invoicing' );
2123
+    $error = __('This invoice is only viewable by clicking on the invoice link that sent to you via email.', 'invoicing');
2124
+    if (!empty($invoice->ID) && $invoice->has_status(array_keys(wpinv_get_invoice_statuses()))) {
2125
+        if (is_user_logged_in()) {
2126
+            if (wpinv_require_login_to_checkout()) {
2127
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2128
+                    $error = __('You are not allowed to view this invoice.', 'invoicing');
2129 2129
                 }
2130 2130
             }
2131 2131
         } else {
2132
-            if ( wpinv_require_login_to_checkout() ) {
2133
-                if ( isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2134
-                    $error = __( 'You must be logged in to view this invoice.', 'invoicing' );
2132
+            if (wpinv_require_login_to_checkout()) {
2133
+                if (isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2134
+                    $error = __('You must be logged in to view this invoice.', 'invoicing');
2135 2135
                 }
2136 2136
             }
2137 2137
         }
2138 2138
     } else {
2139
-        $error = __( 'This invoice is deleted or does not exist.', 'invoicing' );
2139
+        $error = __('This invoice is deleted or does not exist.', 'invoicing');
2140 2140
     }
2141 2141
     ?>
2142 2142
     <div class="row wpinv-row-invalid">
2143 2143
         <div class="col-md-6 col-md-offset-3 wpinv-message error">
2144
-            <h3><?php _e( 'Access Denied', 'invoicing' ); ?></h3>
2144
+            <h3><?php _e('Access Denied', 'invoicing'); ?></h3>
2145 2145
             <p class="wpinv-msg-text"><?php echo $error; ?></p>
2146 2146
         </div>
2147 2147
     </div>
2148 2148
     <?php
2149 2149
 }
2150
-add_action( 'wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content' );
2150
+add_action('wpinv_invalid_invoice_content', 'wpinv_invalid_invoice_content');
2151 2151
 
2152
-add_action( 'wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2153
-function wpinv_force_company_name_field(){
2152
+add_action('wpinv_checkout_billing_fields_last', 'wpinv_force_company_name_field');
2153
+function wpinv_force_company_name_field() {
2154 2154
     $invoice = wpinv_get_invoice_cart();
2155
-    $user_id = wpinv_get_user_id( $invoice->ID );
2156
-    $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
2157
-    if ( 1 == wpinv_get_option( 'force_show_company' ) && !wpinv_use_taxes() ) {
2155
+    $user_id = wpinv_get_user_id($invoice->ID);
2156
+    $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
2157
+    if (1 == wpinv_get_option('force_show_company') && !wpinv_use_taxes()) {
2158 2158
         ?>
2159 2159
         <p class="wpi-cart-field wpi-col2 wpi-colf">
2160 2160
             <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
@@ -2179,21 +2179,21 @@  discard block
 block discarded – undo
2179 2179
  * @return string
2180 2180
  */
2181 2181
 function wpinv_get_policy_text() {
2182
-    $privacy_page_id = get_option( 'wp_page_for_privacy_policy', 0 );
2182
+    $privacy_page_id = get_option('wp_page_for_privacy_policy', 0);
2183 2183
 
2184
-    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ));
2184
+    $text = wpinv_get_option('invoicing_privacy_checkout_message', sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'));
2185 2185
 
2186
-    if(!$privacy_page_id){
2187
-        $privacy_page_id = wpinv_get_option( 'privacy_page', 0 );
2186
+    if (!$privacy_page_id) {
2187
+        $privacy_page_id = wpinv_get_option('privacy_page', 0);
2188 2188
     }
2189 2189
 
2190
-    $privacy_link    = $privacy_page_id ? '<a href="' . esc_url( get_permalink( $privacy_page_id ) ) . '" class="wpinv-privacy-policy-link" target="_blank">' . __( 'privacy policy', 'invoicing' ) . '</a>' : __( 'privacy policy', 'invoicing' );
2190
+    $privacy_link = $privacy_page_id ? '<a href="' . esc_url(get_permalink($privacy_page_id)) . '" class="wpinv-privacy-policy-link" target="_blank">' . __('privacy policy', 'invoicing') . '</a>' : __('privacy policy', 'invoicing');
2191 2191
 
2192 2192
     $find_replace = array(
2193 2193
         '[wpinv_privacy_policy]' => $privacy_link,
2194 2194
     );
2195 2195
 
2196
-    $privacy_text = str_replace( array_keys( $find_replace ), array_values( $find_replace ), $text );
2196
+    $privacy_text = str_replace(array_keys($find_replace), array_values($find_replace), $text);
2197 2197
 
2198 2198
     return wp_kses_post(wpautop($privacy_text));
2199 2199
 }
2200 2200
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 1 patch
Spacing   +751 added lines, -751 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
25
-    if ( empty( $invoice_data ) ) {
24
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
25
+    if (empty($invoice_data)) {
26 26
         return false;
27 27
     }
28 28
     
29
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
30
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0;
29
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
30
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0;
31 31
     }
32 32
     
33
-    if ( empty( $invoice_data['user_id'] ) ) {
33
+    if (empty($invoice_data['user_id'])) {
34 34
         $invoice_data['user_id'] = get_current_user_id();
35 35
     }
36 36
     
37
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
37
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0;
38 38
     
39
-    if ( empty( $invoice_data['status'] ) ) {
39
+    if (empty($invoice_data['status'])) {
40 40
         $invoice_data['status'] = 'wpi-pending';
41 41
     }
42 42
     
43
-    if ( empty( $invoice_data['ip'] ) ) {
43
+    if (empty($invoice_data['ip'])) {
44 44
         $invoice_data['ip'] = wpinv_get_ip();
45 45
     }
46 46
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
         'status'        => $invoice_data['status'],
52 52
     );
53 53
 
54
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
55
-    if ( is_wp_error( $invoice ) ) {
54
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
55
+    if (is_wp_error($invoice)) {
56 56
         return $wp_error ? $invoice : 0;
57 57
     }
58 58
     
59
-    if ( empty( $invoice_data['invoice_id'] ) ) {
59
+    if (empty($invoice_data['invoice_id'])) {
60 60
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
61 61
     }
62 62
     
@@ -79,24 +79,24 @@  discard block
 block discarded – undo
79 79
         'discount'              => array(),
80 80
     );
81 81
 
82
-    if ( $user_id = (int)$invoice->get_user_id() ) {
83
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
84
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
82
+    if ($user_id = (int)$invoice->get_user_id()) {
83
+        if ($user_address = wpinv_get_user_address($user_id)) {
84
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
85 85
         }
86 86
     }
87 87
     
88
-    if ( empty( $invoice_data['user_info'] ) ) {
88
+    if (empty($invoice_data['user_info'])) {
89 89
         $invoice_data['user_info'] = array();
90 90
     }
91 91
     
92
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
92
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
93 93
     
94
-    if ( empty( $user_info['first_name'] ) ) {
94
+    if (empty($user_info['first_name'])) {
95 95
         $user_info['first_name'] = $default_user_info['first_name'];
96 96
         $user_info['last_name'] = $default_user_info['last_name'];
97 97
     }
98 98
     
99
-    if ( empty( $user_info['country'] ) ) {
99
+    if (empty($user_info['country'])) {
100 100
         $user_info['country'] = $default_user_info['country'];
101 101
         $user_info['state'] = $default_user_info['state'];
102 102
         $user_info['city'] = $default_user_info['city'];
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
         $user_info['phone'] = $default_user_info['phone'];
106 106
     }
107 107
     
108
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
108
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
109 109
         $user_info['discount'] = (array)$user_info['discount'];
110 110
     }
111 111
 
112 112
     // Payment details
113 113
     $payment_details = array();
114
-    if ( !empty( $invoice_data['payment_details'] ) ) {
114
+    if (!empty($invoice_data['payment_details'])) {
115 115
         $default_payment_details = array(
116 116
             'gateway'           => 'manual',
117 117
             'gateway_title'     => '',
@@ -119,56 +119,56 @@  discard block
 block discarded – undo
119 119
             'transaction_id'    => '',
120 120
         );
121 121
         
122
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
122
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
123 123
         
124
-        if ( empty( $payment_details['gateway'] ) ) {
124
+        if (empty($payment_details['gateway'])) {
125 125
             $payment_details['gateway'] = 'manual';
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['currency'] ) ) {
128
+        if (empty($payment_details['currency'])) {
129 129
             $payment_details['currency'] = wpinv_get_default_country();
130 130
         }
131 131
         
132
-        if ( empty( $payment_details['gateway_title'] ) ) {
133
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
132
+        if (empty($payment_details['gateway_title'])) {
133
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
134 134
         }
135 135
     }
136 136
     
137
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
138
-    
139
-    if ( !empty( $payment_details ) ) {
140
-        $invoice->set( 'currency', $payment_details['currency'] );
141
-        $invoice->set( 'gateway', $payment_details['gateway'] );
142
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
143
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
144
-    }
145
-    
146
-    $invoice->set( 'user_info', $user_info );
147
-    $invoice->set( 'first_name', $user_info['first_name'] );
148
-    $invoice->set( 'last_name', $user_info['last_name'] );
149
-    $invoice->set( 'address', $user_info['address'] );
150
-    $invoice->set( 'company', $user_info['company'] );
151
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
152
-    $invoice->set( 'phone', $user_info['phone'] );
153
-    $invoice->set( 'city', $user_info['city'] );
154
-    $invoice->set( 'country', $user_info['country'] );
155
-    $invoice->set( 'state', $user_info['state'] );
156
-    $invoice->set( 'zip', $user_info['zip'] );
157
-    $invoice->set( 'discounts', $user_info['discount'] );
158
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
159
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
160
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
161
-    
162
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
163
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
164
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
165
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
166
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
167
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
137
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
138
+    
139
+    if (!empty($payment_details)) {
140
+        $invoice->set('currency', $payment_details['currency']);
141
+        $invoice->set('gateway', $payment_details['gateway']);
142
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
143
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
144
+    }
145
+    
146
+    $invoice->set('user_info', $user_info);
147
+    $invoice->set('first_name', $user_info['first_name']);
148
+    $invoice->set('last_name', $user_info['last_name']);
149
+    $invoice->set('address', $user_info['address']);
150
+    $invoice->set('company', $user_info['company']);
151
+    $invoice->set('vat_number', $user_info['vat_number']);
152
+    $invoice->set('phone', $user_info['phone']);
153
+    $invoice->set('city', $user_info['city']);
154
+    $invoice->set('country', $user_info['country']);
155
+    $invoice->set('state', $user_info['state']);
156
+    $invoice->set('zip', $user_info['zip']);
157
+    $invoice->set('discounts', $user_info['discount']);
158
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
159
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
160
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
161
+    
162
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
163
+        foreach ($invoice_data['cart_details'] as $key => $item) {
164
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
165
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
166
+            $name           = !empty($item['name']) ? $item['name'] : '';
167
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
168 168
             
169
-            $post_item  = new WPInv_Item( $item_id );
170
-            if ( !empty( $post_item ) ) {
171
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
169
+            $post_item = new WPInv_Item($item_id);
170
+            if (!empty($post_item)) {
171
+                $name       = !empty($name) ? $name : $post_item->get_name();
172 172
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
173 173
             } else {
174 174
                 continue;
@@ -178,253 +178,253 @@  discard block
 block discarded – undo
178 178
                 'name'          => $name,
179 179
                 'quantity'      => $quantity,
180 180
                 'item_price'    => $item_price,
181
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
182
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
183
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
184
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
185
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
181
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
182
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
183
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
184
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
185
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
186 186
             );
187 187
 
188
-            $invoice->add_item( $item_id, $args );
188
+            $invoice->add_item($item_id, $args);
189 189
         }
190 190
     }
191 191
 
192
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
192
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
193 193
 
194
-    if ( isset( $invoice_data['post_date'] ) ) {
195
-        $invoice->set( 'date', $invoice_data['post_date'] );
194
+    if (isset($invoice_data['post_date'])) {
195
+        $invoice->set('date', $invoice_data['post_date']);
196 196
     }
197 197
     
198 198
     // Invoice due date
199
-    if ( isset( $invoice_data['due_date'] ) ) {
200
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
199
+    if (isset($invoice_data['due_date'])) {
200
+        $invoice->set('due_date', $invoice_data['due_date']);
201 201
     }
202 202
     
203 203
     $invoice->save();
204 204
     
205 205
     // Add notes
206
-    if ( !empty( $invoice_data['private_note'] ) ) {
207
-        $invoice->add_note( $invoice_data['private_note'] );
206
+    if (!empty($invoice_data['private_note'])) {
207
+        $invoice->add_note($invoice_data['private_note']);
208 208
     }
209
-    if ( !empty( $invoice_data['user_note'] ) ) {
210
-        $invoice->add_note( $invoice_data['user_note'], true );
209
+    if (!empty($invoice_data['user_note'])) {
210
+        $invoice->add_note($invoice_data['user_note'], true);
211 211
     }
212 212
     
213
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
213
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
214 214
 
215
-    if ( ! empty( $invoice->ID ) ) {
215
+    if (!empty($invoice->ID)) {
216 216
         global $wpi_userID, $wpinv_ip_address_country;
217 217
         
218 218
         $checkout_session = wpinv_get_checkout_session();
219 219
         
220 220
         $data_session                   = array();
221 221
         $data_session['invoice_id']     = $invoice->ID;
222
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
222
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
223 223
         
224
-        wpinv_set_checkout_session( $data_session );
224
+        wpinv_set_checkout_session($data_session);
225 225
         
226 226
         $wpi_userID         = (int)$invoice->get_user_id();
227 227
         
228
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
228
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
229 229
         $_POST['state']     = $invoice->state;
230 230
 
231
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
232
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
231
+        $invoice->set('country', sanitize_text_field($_POST['country']));
232
+        $invoice->set('state', sanitize_text_field($_POST['state']));
233 233
         
234 234
         $wpinv_ip_address_country = $invoice->country;
235 235
         
236
-        $invoice = $invoice->recalculate_totals( true );
236
+        $invoice = $invoice->recalculate_totals(true);
237 237
         
238
-        wpinv_set_checkout_session( $checkout_session );
238
+        wpinv_set_checkout_session($checkout_session);
239 239
                     
240 240
         return $invoice;
241 241
     }
242 242
     
243
-    if ( $wp_error ) {
244
-        if ( is_wp_error( $invoice ) ) {
243
+    if ($wp_error) {
244
+        if (is_wp_error($invoice)) {
245 245
             return $invoice;
246 246
         } else {
247
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
247
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
248 248
         }
249 249
     } else {
250 250
         return 0;
251 251
     }
252 252
 }
253 253
 
254
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
255
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
254
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
255
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
256 256
 
257
-    if ( !$invoice_ID ) {
258
-        if ( $wp_error ) {
259
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
257
+    if (!$invoice_ID) {
258
+        if ($wp_error) {
259
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
260 260
         }
261 261
         return 0;
262 262
     }
263 263
 
264
-    $invoice = wpinv_get_invoice( $invoice_ID );
264
+    $invoice = wpinv_get_invoice($invoice_ID);
265 265
 
266
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
266
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
267 267
 
268
-    if ( empty( $invoice->ID ) ) {
269
-        if ( $wp_error ) {
270
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
268
+    if (empty($invoice->ID)) {
269
+        if ($wp_error) {
270
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
271 271
         }
272 272
         return 0;
273 273
     }
274 274
 
275
-    if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) {
276
-        if ( $wp_error ) {
277
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
275
+    if (!$invoice->has_status(array('wpi-pending'))) {
276
+        if ($wp_error) {
277
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
278 278
         }
279 279
         return 0;
280 280
     }
281 281
 
282 282
     // Invoice status
283
-    if ( !empty( $invoice_data['status'] ) ) {
284
-        $invoice->set( 'status', $invoice_data['status'] );
283
+    if (!empty($invoice_data['status'])) {
284
+        $invoice->set('status', $invoice_data['status']);
285 285
     }
286 286
 
287 287
     // Invoice date
288
-    if ( !empty( $invoice_data['post_date'] ) ) {
289
-        $invoice->set( 'date', $invoice_data['post_date'] );
288
+    if (!empty($invoice_data['post_date'])) {
289
+        $invoice->set('date', $invoice_data['post_date']);
290 290
     }
291 291
 
292 292
     // Invoice due date
293
-    if ( isset( $invoice_data['due_date'] ) ) {
294
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
293
+    if (isset($invoice_data['due_date'])) {
294
+        $invoice->set('due_date', $invoice_data['due_date']);
295 295
     }
296 296
 
297 297
     // Invoice IP address
298
-    if ( !empty( $invoice_data['ip'] ) ) {
299
-        $invoice->set( 'ip', $invoice_data['ip'] );
298
+    if (!empty($invoice_data['ip'])) {
299
+        $invoice->set('ip', $invoice_data['ip']);
300 300
     }
301 301
     
302 302
     // User info
303
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
304
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
303
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
304
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
305 305
 
306
-        if ( $discounts = $invoice->get_discounts() ) {
306
+        if ($discounts = $invoice->get_discounts()) {
307 307
             $set_discount = $discounts;
308 308
         } else {
309 309
             $set_discount = '';
310 310
         }
311 311
 
312 312
         // Manage discount
313
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
313
+        if (!empty($invoice_data['user_info']['discount'])) {
314 314
             // Remove discount
315
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
315
+            if ($invoice_data['user_info']['discount'] == 'none') {
316 316
                 $set_discount = '';
317 317
             } else {
318 318
                 $set_discount = $invoice_data['user_info']['discount'];
319 319
             }
320 320
 
321
-            $invoice->set( 'discounts', $set_discount );
321
+            $invoice->set('discounts', $set_discount);
322 322
         }
323 323
 
324 324
         $user_info['discount'] = $set_discount;
325 325
 
326
-        $invoice->set( 'user_info', $user_info );
326
+        $invoice->set('user_info', $user_info);
327 327
     }
328 328
 
329
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
330
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
329
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
330
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
331 331
 
332
-        if ( !empty( $remove_items[0]['id'] ) ) {
333
-            foreach ( $remove_items as $item ) {
334
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
335
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
336
-                if ( empty( $item_id ) ) {
332
+        if (!empty($remove_items[0]['id'])) {
333
+            foreach ($remove_items as $item) {
334
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
335
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
336
+                if (empty($item_id)) {
337 337
                     continue;
338 338
                 }
339 339
 
340
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
341
-                    if ( $item_id == $cart_item['id'] ) {
340
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
341
+                    if ($item_id == $cart_item['id']) {
342 342
                         $args = array(
343 343
                             'id'         => $item_id,
344 344
                             'quantity'   => $quantity,
345 345
                             'cart_index' => $cart_index
346 346
                         );
347 347
 
348
-                        $invoice->remove_item( $item_id, $args );
348
+                        $invoice->remove_item($item_id, $args);
349 349
                         break;
350 350
                     }
351 351
                 }
352 352
             }
353 353
         }
354 354
 
355
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
355
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
356 356
 
357
-        if ( !empty( $add_items[0]['id'] ) ) {
358
-            foreach ( $add_items as $item ) {
359
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
360
-                $post_item      = new WPInv_Item( $item_id );
361
-                if ( empty( $post_item ) ) {
357
+        if (!empty($add_items[0]['id'])) {
358
+            foreach ($add_items as $item) {
359
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
360
+                $post_item      = new WPInv_Item($item_id);
361
+                if (empty($post_item)) {
362 362
                     continue;
363 363
                 }
364 364
 
365 365
                 $valid_item = true;
366
-                if ( !empty( $recurring_item ) ) {
367
-                    if ( $recurring_item->ID != $item_id ) {
366
+                if (!empty($recurring_item)) {
367
+                    if ($recurring_item->ID != $item_id) {
368 368
                         $valid_item = false;
369 369
                     }
370
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
370
+                } else if (wpinv_is_recurring_item($item_id)) {
371 371
                     $valid_item = false;
372 372
                 }
373 373
                 
374
-                if ( !$valid_item ) {
375
-                    if ( $wp_error ) {
376
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
374
+                if (!$valid_item) {
375
+                    if ($wp_error) {
376
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
377 377
                     }
378 378
                     return 0;
379 379
                 }
380 380
 
381
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
382
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
383
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
381
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
382
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
383
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
384 384
 
385 385
                 $args = array(
386 386
                     'name'          => $name,
387 387
                     'quantity'      => $quantity,
388 388
                     'item_price'    => $item_price,
389
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
390
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
391
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
392
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
393
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
389
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
390
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
391
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
392
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
393
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
394 394
                 );
395 395
 
396
-                $invoice->add_item( $item_id, $args );
396
+                $invoice->add_item($item_id, $args);
397 397
             }
398 398
         }
399 399
     }
400 400
     
401 401
     // Payment details
402
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
403
-        if ( !empty( $payment_details['gateway'] ) ) {
404
-            $invoice->set( 'gateway', $payment_details['gateway'] );
402
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
403
+        if (!empty($payment_details['gateway'])) {
404
+            $invoice->set('gateway', $payment_details['gateway']);
405 405
         }
406 406
 
407
-        if ( !empty( $payment_details['transaction_id'] ) ) {
408
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
407
+        if (!empty($payment_details['transaction_id'])) {
408
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
409 409
         }
410 410
     }
411 411
 
412
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
412
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
413 413
 
414 414
     // Parent invoice
415
-    if ( !empty( $invoice_data['parent'] ) ) {
416
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
415
+    if (!empty($invoice_data['parent'])) {
416
+        $invoice->set('parent_invoice', $invoice_data['parent']);
417 417
     }
418 418
 
419 419
     // Save invoice data.
420 420
     $invoice->save();
421 421
     
422
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
423
-        if ( $wp_error ) {
424
-            if ( is_wp_error( $invoice ) ) {
422
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
423
+        if ($wp_error) {
424
+            if (is_wp_error($invoice)) {
425 425
                 return $invoice;
426 426
             } else {
427
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
427
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
428 428
             }
429 429
         } else {
430 430
             return 0;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
     }
433 433
 
434 434
     // Add private note
435
-    if ( !empty( $invoice_data['private_note'] ) ) {
436
-        $invoice->add_note( $invoice_data['private_note'] );
435
+    if (!empty($invoice_data['private_note'])) {
436
+        $invoice->add_note($invoice_data['private_note']);
437 437
     }
438 438
 
439 439
     // Add user note
440
-    if ( !empty( $invoice_data['user_note'] ) ) {
441
-        $invoice->add_note( $invoice_data['user_note'], true );
440
+    if (!empty($invoice_data['user_note'])) {
441
+        $invoice->add_note($invoice_data['user_note'], true);
442 442
     }
443 443
 
444 444
     global $wpi_userID, $wpinv_ip_address_country;
@@ -447,450 +447,450 @@  discard block
 block discarded – undo
447 447
 
448 448
     $data_session                   = array();
449 449
     $data_session['invoice_id']     = $invoice->ID;
450
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
450
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
451 451
 
452
-    wpinv_set_checkout_session( $data_session );
452
+    wpinv_set_checkout_session($data_session);
453 453
 
454 454
     $wpi_userID         = (int)$invoice->get_user_id();
455 455
 
456
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
456
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
457 457
     $_POST['state']     = $invoice->state;
458 458
 
459
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
460
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
459
+    $invoice->set('country', sanitize_text_field($_POST['country']));
460
+    $invoice->set('state', sanitize_text_field($_POST['state']));
461 461
 
462 462
     $wpinv_ip_address_country = $invoice->country;
463 463
 
464
-    $invoice = $invoice->recalculate_totals( true );
464
+    $invoice = $invoice->recalculate_totals(true);
465 465
 
466
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
466
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
467 467
 
468
-    wpinv_set_checkout_session( $checkout_session );
468
+    wpinv_set_checkout_session($checkout_session);
469 469
 
470 470
     return $invoice;
471 471
 }
472 472
 
473
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
474
-    if ( $cart && empty( $invoice_id ) ) {
473
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
474
+    if ($cart && empty($invoice_id)) {
475 475
         $invoice_id = (int)wpinv_get_invoice_cart_id();
476 476
     }
477 477
 
478
-    $invoice = new WPInv_Invoice( $invoice_id );
478
+    $invoice = new WPInv_Invoice($invoice_id);
479 479
 
480
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
480
+    if (!empty($invoice) && !empty($invoice->ID)) {
481 481
         return $invoice;
482 482
     }
483 483
     
484 484
     return NULL;
485 485
 }
486 486
 
487
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
488
-    return wpinv_get_invoice( $invoice_id, true );
487
+function wpinv_get_invoice_cart($invoice_id = 0) {
488
+    return wpinv_get_invoice($invoice_id, true);
489 489
 }
490 490
 
491
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
492
-    $invoice = new WPInv_Invoice( $invoice_id );
491
+function wpinv_get_invoice_description($invoice_id = 0) {
492
+    $invoice = new WPInv_Invoice($invoice_id);
493 493
     return $invoice->get_description();
494 494
 }
495 495
 
496
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
497
-    $invoice = new WPInv_Invoice( $invoice_id );
496
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
497
+    $invoice = new WPInv_Invoice($invoice_id);
498 498
     return $invoice->get_currency();
499 499
 }
500 500
 
501
-function wpinv_get_payment_user_email( $invoice_id ) {
502
-    $invoice = new WPInv_Invoice( $invoice_id );
501
+function wpinv_get_payment_user_email($invoice_id) {
502
+    $invoice = new WPInv_Invoice($invoice_id);
503 503
     return $invoice->get_email();
504 504
 }
505 505
 
506
-function wpinv_get_user_id( $invoice_id ) {
507
-    $invoice = new WPInv_Invoice( $invoice_id );
506
+function wpinv_get_user_id($invoice_id) {
507
+    $invoice = new WPInv_Invoice($invoice_id);
508 508
     return $invoice->get_user_id();
509 509
 }
510 510
 
511
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
512
-    $invoice = new WPInv_Invoice( $invoice_id );
511
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
512
+    $invoice = new WPInv_Invoice($invoice_id);
513 513
     
514
-    return $invoice->get_status( $return_label );
514
+    return $invoice->get_status($return_label);
515 515
 }
516 516
 
517
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
518
-    $invoice = new WPInv_Invoice( $invoice_id );
517
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
518
+    $invoice = new WPInv_Invoice($invoice_id);
519 519
     
520
-    return $invoice->get_gateway( $return_label );
520
+    return $invoice->get_gateway($return_label);
521 521
 }
522 522
 
523
-function wpinv_get_payment_gateway_name( $invoice_id ) {
524
-    $invoice = new WPInv_Invoice( $invoice_id );
523
+function wpinv_get_payment_gateway_name($invoice_id) {
524
+    $invoice = new WPInv_Invoice($invoice_id);
525 525
     
526 526
     return $invoice->get_gateway_title();
527 527
 }
528 528
 
529
-function wpinv_get_payment_transaction_id( $invoice_id ) {
530
-    $invoice = new WPInv_Invoice( $invoice_id );
529
+function wpinv_get_payment_transaction_id($invoice_id) {
530
+    $invoice = new WPInv_Invoice($invoice_id);
531 531
     
532 532
     return $invoice->get_transaction_id();
533 533
 }
534 534
 
535
-function wpinv_get_id_by_transaction_id( $key ) {
535
+function wpinv_get_id_by_transaction_id($key) {
536 536
     global $wpdb;
537 537
 
538
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
538
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
539 539
 
540
-    if ( $invoice_id != NULL )
540
+    if ($invoice_id != NULL)
541 541
         return $invoice_id;
542 542
 
543 543
     return 0;
544 544
 }
545 545
 
546
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
547
-    $invoice = new WPInv_Invoice( $invoice_id );
546
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
547
+    $invoice = new WPInv_Invoice($invoice_id);
548 548
 
549
-    return $invoice->get_meta( $meta_key, $single );
549
+    return $invoice->get_meta($meta_key, $single);
550 550
 }
551 551
 
552
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
553
-    $invoice = new WPInv_Invoice( $invoice_id );
552
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
553
+    $invoice = new WPInv_Invoice($invoice_id);
554 554
     
555
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
555
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
556 556
 }
557 557
 
558
-function wpinv_get_items( $invoice_id = 0 ) {
559
-    $invoice            = wpinv_get_invoice( $invoice_id );
558
+function wpinv_get_items($invoice_id = 0) {
559
+    $invoice            = wpinv_get_invoice($invoice_id);
560 560
     
561 561
     $items              = $invoice->get_items();
562 562
     $invoice_currency   = $invoice->get_currency();
563 563
 
564
-    if ( !empty( $items ) && is_array( $items ) ) {
565
-        foreach ( $items as $key => $item ) {
564
+    if (!empty($items) && is_array($items)) {
565
+        foreach ($items as $key => $item) {
566 566
             $items[$key]['currency'] = $invoice_currency;
567 567
 
568
-            if ( !isset( $cart_item['subtotal'] ) ) {
568
+            if (!isset($cart_item['subtotal'])) {
569 569
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
570 570
             }
571 571
         }
572 572
     }
573 573
 
574
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
574
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
575 575
 }
576 576
 
577
-function wpinv_get_fees( $invoice_id = 0 ) {
578
-    $invoice           = wpinv_get_invoice( $invoice_id );
577
+function wpinv_get_fees($invoice_id = 0) {
578
+    $invoice           = wpinv_get_invoice($invoice_id);
579 579
     $fees              = $invoice->get_fees();
580 580
 
581
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
581
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
582 582
 }
583 583
 
584
-function wpinv_get_invoice_ip( $invoice_id ) {
585
-    $invoice = new WPInv_Invoice( $invoice_id );
584
+function wpinv_get_invoice_ip($invoice_id) {
585
+    $invoice = new WPInv_Invoice($invoice_id);
586 586
     return $invoice->get_ip();
587 587
 }
588 588
 
589
-function wpinv_get_invoice_user_info( $invoice_id ) {
590
-    $invoice = new WPInv_Invoice( $invoice_id );
589
+function wpinv_get_invoice_user_info($invoice_id) {
590
+    $invoice = new WPInv_Invoice($invoice_id);
591 591
     return $invoice->get_user_info();
592 592
 }
593 593
 
594
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
595
-    $invoice = new WPInv_Invoice( $invoice_id );
594
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
595
+    $invoice = new WPInv_Invoice($invoice_id);
596 596
 
597
-    return $invoice->get_subtotal( $currency );
597
+    return $invoice->get_subtotal($currency);
598 598
 }
599 599
 
600
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
601
-    $invoice = new WPInv_Invoice( $invoice_id );
600
+function wpinv_tax($invoice_id = 0, $currency = false) {
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603
-    return $invoice->get_tax( $currency );
603
+    return $invoice->get_tax($currency);
604 604
 }
605 605
 
606
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
607
-    $invoice = wpinv_get_invoice( $invoice_id );
606
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
607
+    $invoice = wpinv_get_invoice($invoice_id);
608 608
 
609
-    return $invoice->get_discount( $currency, $dash );
609
+    return $invoice->get_discount($currency, $dash);
610 610
 }
611 611
 
612
-function wpinv_discount_code( $invoice_id = 0 ) {
613
-    $invoice = new WPInv_Invoice( $invoice_id );
612
+function wpinv_discount_code($invoice_id = 0) {
613
+    $invoice = new WPInv_Invoice($invoice_id);
614 614
 
615 615
     return $invoice->get_discount_code();
616 616
 }
617 617
 
618
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
619
-    $invoice = new WPInv_Invoice( $invoice_id );
618
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
619
+    $invoice = new WPInv_Invoice($invoice_id);
620 620
 
621
-    return $invoice->get_total( $currency );
621
+    return $invoice->get_total($currency);
622 622
 }
623 623
 
624
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
625
-    $invoice = new WPInv_Invoice( $invoice_id );
624
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
625
+    $invoice = new WPInv_Invoice($invoice_id);
626 626
 
627
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
627
+    $format         = !empty($format) ? $format : get_option('date_format');
628 628
     $date_created   = $invoice->get_created_date();
629
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
629
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
630 630
 
631 631
     return $date_created;
632 632
 }
633 633
 
634
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
635
-    $invoice = new WPInv_Invoice( $invoice_id );
634
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
635
+    $invoice = new WPInv_Invoice($invoice_id);
636 636
     
637
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
637
+    $format         = !empty($format) ? $format : get_option('date_format');
638 638
     $date_completed = $invoice->get_completed_date();
639
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
640
-    if ( $invoice_date == '' && $default ) {
641
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
639
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
640
+    if ($invoice_date == '' && $default) {
641
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
642 642
     }
643 643
 
644 644
     return $invoice_date;
645 645
 }
646 646
 
647
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
648
-    $invoice = new WPInv_Invoice( $invoice_id );
647
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
648
+    $invoice = new WPInv_Invoice($invoice_id);
649 649
     
650 650
     return $invoice->vat_number;
651 651
 }
652 652
 
653
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
654
-    $invoice = new WPInv_Invoice( $invoice_id );
653
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
654
+    $invoice = new WPInv_Invoice($invoice_id);
655 655
 
656
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
656
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
657 657
 }
658 658
 
659
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
659
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
660 660
     global $invoicing;
661 661
     
662
-    if ( empty( $invoice_id ) ) {
662
+    if (empty($invoice_id)) {
663 663
         return NULL;
664 664
     }
665 665
     
666
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
666
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
667 667
     
668
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
668
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
669 669
 }
670 670
 
671
-function wpinv_get_payment_key( $invoice_id = 0 ) {
672
-	$invoice = new WPInv_Invoice( $invoice_id );
671
+function wpinv_get_payment_key($invoice_id = 0) {
672
+	$invoice = new WPInv_Invoice($invoice_id);
673 673
     return $invoice->get_key();
674 674
 }
675 675
 
676
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
677
-    $invoice = new WPInv_Invoice( $invoice_id );
676
+function wpinv_get_invoice_number($invoice_id = 0) {
677
+    $invoice = new WPInv_Invoice($invoice_id);
678 678
     return $invoice->get_number();
679 679
 }
680 680
 
681
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
681
+function wpinv_get_cart_discountable_subtotal($code_id) {
682 682
     $cart_items = wpinv_get_cart_content_details();
683 683
     $items      = array();
684 684
 
685
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
685
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
686 686
 
687
-    if( $cart_items ) {
687
+    if ($cart_items) {
688 688
 
689
-        foreach( $cart_items as $item ) {
689
+        foreach ($cart_items as $item) {
690 690
 
691
-            if( ! in_array( $item['id'], $excluded_items ) ) {
692
-                $items[] =  $item;
691
+            if (!in_array($item['id'], $excluded_items)) {
692
+                $items[] = $item;
693 693
             }
694 694
         }
695 695
     }
696 696
 
697
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
697
+    $subtotal = wpinv_get_cart_items_subtotal($items);
698 698
 
699
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
699
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
700 700
 }
701 701
 
702
-function wpinv_get_cart_items_subtotal( $items ) {
702
+function wpinv_get_cart_items_subtotal($items) {
703 703
     $subtotal = 0.00;
704 704
 
705
-    if ( is_array( $items ) && ! empty( $items ) ) {
706
-        $prices = wp_list_pluck( $items, 'subtotal' );
705
+    if (is_array($items) && !empty($items)) {
706
+        $prices = wp_list_pluck($items, 'subtotal');
707 707
 
708
-        if( is_array( $prices ) ) {
709
-            $subtotal = array_sum( $prices );
708
+        if (is_array($prices)) {
709
+            $subtotal = array_sum($prices);
710 710
         } else {
711 711
             $subtotal = 0.00;
712 712
         }
713 713
 
714
-        if( $subtotal < 0 ) {
714
+        if ($subtotal < 0) {
715 715
             $subtotal = 0.00;
716 716
         }
717 717
     }
718 718
 
719
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
719
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
720 720
 }
721 721
 
722
-function wpinv_get_cart_subtotal( $items = array() ) {
723
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
724
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
722
+function wpinv_get_cart_subtotal($items = array()) {
723
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
724
+    $subtotal = wpinv_get_cart_items_subtotal($items);
725 725
 
726
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
726
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
727 727
 }
728 728
 
729
-function wpinv_cart_subtotal( $items = array() ) {
730
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
729
+function wpinv_cart_subtotal($items = array()) {
730
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
731 731
 
732 732
     return $price;
733 733
 }
734 734
 
735
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
736
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
737
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
738
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
735
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
736
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
737
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
738
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
739 739
     $fees      = (float)wpinv_get_cart_fee_total();
740
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
740
+    if (!empty($invoice) && $invoice->is_free_trial()) {
741 741
         $total = 0;
742 742
     } else {
743
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
743
+        $total = $subtotal - $discounts + $cart_tax + $fees;
744 744
     }
745 745
 
746
-    if ( $total < 0 ) {
746
+    if ($total < 0) {
747 747
         $total = 0.00;
748 748
     }
749 749
     
750
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
750
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
751 751
 
752
-    return wpinv_sanitize_amount( $total );
752
+    return wpinv_sanitize_amount($total);
753 753
 }
754 754
 
755
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
755
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
756 756
     global $cart_total;
757
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
758
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
757
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
758
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
759 759
     
760 760
     $cart_total = $total;
761 761
 
762
-    if ( !$echo ) {
762
+    if (!$echo) {
763 763
         return $total;
764 764
     }
765 765
 
766 766
     echo $total;
767 767
 }
768 768
 
769
-function wpinv_get_cart_tax( $items = array() ) {
769
+function wpinv_get_cart_tax($items = array()) {
770 770
     $cart_tax = 0;
771
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
771
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
772 772
 
773
-    if ( $items ) {
774
-        $taxes = wp_list_pluck( $items, 'tax' );
773
+    if ($items) {
774
+        $taxes = wp_list_pluck($items, 'tax');
775 775
 
776
-        if( is_array( $taxes ) ) {
777
-            $cart_tax = array_sum( $taxes );
776
+        if (is_array($taxes)) {
777
+            $cart_tax = array_sum($taxes);
778 778
         }
779 779
     }
780 780
 
781 781
     $cart_tax += wpinv_get_cart_fee_tax();
782 782
 
783
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
783
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
784 784
 }
785 785
 
786
-function wpinv_cart_tax( $items = array(), $echo = false ) {
787
-    $cart_tax = wpinv_get_cart_tax( $items );
788
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
786
+function wpinv_cart_tax($items = array(), $echo = false) {
787
+    $cart_tax = wpinv_get_cart_tax($items);
788
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
789 789
 
790
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
790
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
791 791
 
792
-    if ( !$echo ) {
792
+    if (!$echo) {
793 793
         return $tax;
794 794
     }
795 795
 
796 796
     echo $tax;
797 797
 }
798 798
 
799
-function wpinv_get_cart_discount_code( $items = array() ) {
799
+function wpinv_get_cart_discount_code($items = array()) {
800 800
     $invoice = wpinv_get_invoice_cart();
801
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
801
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
802 802
     
803
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
803
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
804 804
 }
805 805
 
806
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
807
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
806
+function wpinv_cart_discount_code($items = array(), $echo = false) {
807
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
808 808
 
809
-    if ( $cart_discount_code != '' ) {
809
+    if ($cart_discount_code != '') {
810 810
         $cart_discount_code = ' (' . $cart_discount_code . ')';
811 811
     }
812 812
     
813
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
813
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
814 814
 
815
-    if ( !$echo ) {
815
+    if (!$echo) {
816 816
         return $discount_code;
817 817
     }
818 818
 
819 819
     echo $discount_code;
820 820
 }
821 821
 
822
-function wpinv_get_cart_discount( $items = array() ) {
822
+function wpinv_get_cart_discount($items = array()) {
823 823
     $invoice = wpinv_get_invoice_cart();
824
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
824
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
825 825
     
826
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
826
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
827 827
 }
828 828
 
829
-function wpinv_cart_discount( $items = array(), $echo = false ) {
830
-    $cart_discount = wpinv_get_cart_discount( $items );
831
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
829
+function wpinv_cart_discount($items = array(), $echo = false) {
830
+    $cart_discount = wpinv_get_cart_discount($items);
831
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
832 832
 
833
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
833
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
834 834
 
835
-    if ( !$echo ) {
835
+    if (!$echo) {
836 836
         return $discount;
837 837
     }
838 838
 
839 839
     echo $discount;
840 840
 }
841 841
 
842
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
843
-    $item = new WPInv_Item( $item_id );
842
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
843
+    $item = new WPInv_Item($item_id);
844 844
     
845
-    return $item->get_fees( $type, $item_id );
845
+    return $item->get_fees($type, $item_id);
846 846
 }
847 847
 
848 848
 function wpinv_get_cart_fee_total() {
849
-    $total  = 0;
849
+    $total = 0;
850 850
     $fees = wpinv_get_cart_fees();
851 851
     
852
-    if ( $fees ) {
853
-        foreach ( $fees as $fee_id => $fee ) {
852
+    if ($fees) {
853
+        foreach ($fees as $fee_id => $fee) {
854 854
             $total += $fee['amount'];
855 855
         }
856 856
     }
857 857
 
858
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
858
+    return apply_filters('wpinv_get_cart_fee_total', $total);
859 859
 }
860 860
 
861 861
 function wpinv_get_cart_fee_tax() {
862 862
     $tax  = 0;
863 863
     $fees = wpinv_get_cart_fees();
864 864
 
865
-    if ( $fees ) {
866
-        foreach ( $fees as $fee_id => $fee ) {
867
-            if( ! empty( $fee['no_tax'] ) ) {
865
+    if ($fees) {
866
+        foreach ($fees as $fee_id => $fee) {
867
+            if (!empty($fee['no_tax'])) {
868 868
                 continue;
869 869
             }
870 870
 
871
-            $tax += wpinv_calculate_tax( $fee['amount'] );
871
+            $tax += wpinv_calculate_tax($fee['amount']);
872 872
         }
873 873
     }
874 874
 
875
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
875
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
876 876
 }
877 877
 
878 878
 function wpinv_cart_has_recurring_item() {
879 879
     $cart_items = wpinv_get_cart_contents();
880 880
     
881
-    if ( empty( $cart_items ) ) {
881
+    if (empty($cart_items)) {
882 882
         return false;
883 883
     }
884 884
     
885 885
     $has_subscription = false;
886
-    foreach( $cart_items as $cart_item ) {
887
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
886
+    foreach ($cart_items as $cart_item) {
887
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
888 888
             $has_subscription = true;
889 889
             break;
890 890
         }
891 891
     }
892 892
     
893
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
893
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
894 894
 }
895 895
 
896 896
 function wpinv_cart_has_free_trial() {
@@ -898,97 +898,97 @@  discard block
 block discarded – undo
898 898
     
899 899
     $free_trial = false;
900 900
     
901
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
901
+    if (!empty($invoice) && $invoice->is_free_trial()) {
902 902
         $free_trial = true;
903 903
     }
904 904
     
905
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
905
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
906 906
 }
907 907
 
908 908
 function wpinv_get_cart_contents() {
909 909
     $cart_details = wpinv_get_cart_details();
910 910
     
911
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
911
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
912 912
 }
913 913
 
914 914
 function wpinv_get_cart_content_details() {
915 915
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
916 916
     $cart_items = wpinv_get_cart_contents();
917 917
     
918
-    if ( empty( $cart_items ) ) {
918
+    if (empty($cart_items)) {
919 919
         return false;
920 920
     }
921 921
     $invoice = wpinv_get_invoice_cart();
922
-	if ( empty( $invoice ) ) {
922
+	if (empty($invoice)) {
923 923
         return false;
924 924
     }
925 925
 
926 926
     $details = array();
927
-    $length  = count( $cart_items ) - 1;
927
+    $length  = count($cart_items) - 1;
928 928
     
929
-    if ( empty( $_POST['country'] ) ) {
929
+    if (empty($_POST['country'])) {
930 930
         $_POST['country'] = $invoice->country;
931 931
     }
932
-    if ( !isset( $_POST['state'] ) ) {
932
+    if (!isset($_POST['state'])) {
933 933
         $_POST['state'] = $invoice->state;
934 934
     }
935 935
 
936
-    foreach( $cart_items as $key => $item ) {
937
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
938
-        if ( empty( $item_id ) ) {
936
+    foreach ($cart_items as $key => $item) {
937
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
938
+        if (empty($item_id)) {
939 939
             continue;
940 940
         }
941 941
         
942 942
         $wpi_current_id         = $invoice->ID;
943 943
         $wpi_item_id            = $item_id;
944 944
         
945
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
945
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
946 946
             $item_price = $item['custom_price'];
947 947
         } else {
948
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
948
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
949 949
                 $item_price = $item['item_price'];
950 950
             } else {
951
-                $item_price = wpinv_get_item_price( $item_id );
951
+                $item_price = wpinv_get_item_price($item_id);
952 952
             }
953 953
         }
954
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
955
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
956
-        $quantity           = wpinv_get_cart_item_quantity( $item );
957
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
954
+        $discount           = wpinv_get_cart_item_discount_amount($item);
955
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
956
+        $quantity           = wpinv_get_cart_item_quantity($item);
957
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
958 958
         
959 959
         $subtotal           = $item_price * $quantity;
960
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
961
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
962
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
960
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
961
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
962
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
963 963
         
964
-        if ( wpinv_prices_include_tax() ) {
965
-            $subtotal -= wpinv_round_amount( $tax );
964
+        if (wpinv_prices_include_tax()) {
965
+            $subtotal -= wpinv_round_amount($tax);
966 966
         }
967 967
         
968
-        $total              = $subtotal - $discount + $tax;
968
+        $total = $subtotal - $discount + $tax;
969 969
         
970 970
         // Do not allow totals to go negatve
971
-        if( $total < 0 ) {
971
+        if ($total < 0) {
972 972
             $total = 0;
973 973
         }
974 974
         
975
-        $details[ $key ]  = array(
975
+        $details[$key] = array(
976 976
             'id'                => $item_id,
977
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
978
-            'item_price'        => wpinv_round_amount( $item_price ),
979
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
977
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
978
+            'item_price'        => wpinv_round_amount($item_price),
979
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
980 980
             'quantity'          => $quantity,
981
-            'discount'          => wpinv_round_amount( $discount ),
982
-            'subtotal'          => wpinv_round_amount( $subtotal ),
983
-            'tax'               => wpinv_round_amount( $tax ),
984
-            'price'             => wpinv_round_amount( $total ),
981
+            'discount'          => wpinv_round_amount($discount),
982
+            'subtotal'          => wpinv_round_amount($subtotal),
983
+            'tax'               => wpinv_round_amount($tax),
984
+            'price'             => wpinv_round_amount($total),
985 985
             'vat_rates_class'   => $tax_class,
986 986
             'vat_rate'          => $tax_rate,
987
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
987
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
988 988
             'fees'              => $fees,
989 989
         );
990 990
         
991
-        if ( $wpinv_is_last_cart_item ) {
991
+        if ($wpinv_is_last_cart_item) {
992 992
             $wpinv_is_last_cart_item   = false;
993 993
             $wpinv_flat_discount_total = 0.00;
994 994
         }
@@ -997,67 +997,67 @@  discard block
 block discarded – undo
997 997
     return $details;
998 998
 }
999 999
 
1000
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1000
+function wpinv_get_cart_details($invoice_id = 0) {
1001 1001
     global $ajax_cart_details;
1002 1002
 
1003
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1003
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1004 1004
     $cart_details = $ajax_cart_details;
1005
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1005
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1006 1006
         $cart_details = $invoice->cart_details;
1007 1007
     }
1008 1008
 
1009
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1010
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1009
+    if (!empty($cart_details) && is_array($cart_details)) {
1010
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1011 1011
 
1012
-        foreach ( $cart_details as $key => $cart_item ) {
1013
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1012
+        foreach ($cart_details as $key => $cart_item) {
1013
+            $cart_details[$key]['currency'] = $invoice_currency;
1014 1014
 
1015
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1016
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1015
+            if (!isset($cart_item['subtotal'])) {
1016
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1017 1017
             }
1018 1018
         }
1019 1019
     }
1020 1020
 
1021
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1021
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1022 1022
 }
1023 1023
 
1024
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1025
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1024
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1025
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1026 1026
         return;
1027 1027
     }
1028 1028
 
1029
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1029
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1030 1030
         return;
1031 1031
     }
1032 1032
 
1033
-    $invoice    = wpinv_get_invoice( $invoice_id );
1033
+    $invoice    = wpinv_get_invoice($invoice_id);
1034 1034
     
1035
-    $old_status = wpinv_status_nicename( $old_status );
1036
-    $new_status = wpinv_status_nicename( $new_status );
1035
+    $old_status = wpinv_status_nicename($old_status);
1036
+    $new_status = wpinv_status_nicename($new_status);
1037 1037
 
1038
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1038
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1039 1039
     
1040 1040
     // Add note
1041
-    return $invoice->add_note( $status_change, false, false, true );
1041
+    return $invoice->add_note($status_change, false, false, true);
1042 1042
 }
1043
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1043
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1044 1044
 
1045
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1045
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1046 1046
     global $wpi_has_free_trial;
1047 1047
     
1048 1048
     $wpi_has_free_trial = false;
1049 1049
     
1050
-    if ( $old_status == 'publish' ) {
1050
+    if ($old_status == 'publish') {
1051 1051
         return; // Make sure that payments are only paid once
1052 1052
     }
1053 1053
 
1054 1054
     // Make sure the payment completion is only processed when new status is paid
1055
-    if ( $new_status != 'publish' ) {
1055
+    if ($new_status != 'publish') {
1056 1056
         return;
1057 1057
     }
1058 1058
 
1059
-    $invoice = new WPInv_Invoice( $invoice_id );
1060
-    if ( empty( $invoice ) ) {
1059
+    $invoice = new WPInv_Invoice($invoice_id);
1060
+    if (empty($invoice)) {
1061 1061
         return;
1062 1062
     }
1063 1063
 
@@ -1065,58 +1065,58 @@  discard block
 block discarded – undo
1065 1065
     $completed_date = $invoice->completed_date;
1066 1066
     $cart_details   = $invoice->cart_details;
1067 1067
 
1068
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1068
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1069 1069
 
1070
-    if ( is_array( $cart_details ) ) {
1070
+    if (is_array($cart_details)) {
1071 1071
         // Increase purchase count and earnings
1072
-        foreach ( $cart_details as $cart_index => $item ) {
1072
+        foreach ($cart_details as $cart_index => $item) {
1073 1073
             // Ensure these actions only run once, ever
1074
-            if ( empty( $completed_date ) ) {
1075
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1074
+            if (empty($completed_date)) {
1075
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1076 1076
             }
1077 1077
         }
1078 1078
     }
1079 1079
     
1080 1080
     // Check for discount codes and increment their use counts
1081
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1082
-        if( ! empty( $discounts ) ) {
1083
-            foreach( $discounts as $code ) {
1084
-                wpinv_increase_discount_usage( $code );
1081
+    if ($discounts = $invoice->get_discounts(true)) {
1082
+        if (!empty($discounts)) {
1083
+            foreach ($discounts as $code) {
1084
+                wpinv_increase_discount_usage($code);
1085 1085
             }
1086 1086
         }
1087 1087
     }
1088 1088
     
1089 1089
     // Ensure this action only runs once ever
1090
-    if( empty( $completed_date ) ) {
1090
+    if (empty($completed_date)) {
1091 1091
         // Save the completed date
1092
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1092
+        $invoice->set('completed_date', current_time('mysql', 0));
1093 1093
         $invoice->save();
1094 1094
 
1095
-        do_action( 'wpinv_complete_payment', $invoice_id );
1095
+        do_action('wpinv_complete_payment', $invoice_id);
1096 1096
     }
1097 1097
 
1098 1098
     // Empty the shopping cart
1099 1099
     wpinv_empty_cart();
1100 1100
 }
1101
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1101
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1102 1102
 
1103
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1104
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1103
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1104
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
1105 1105
     
1106
-    if ( empty( $invoice ) ) {
1106
+    if (empty($invoice)) {
1107 1107
         return false;
1108 1108
     }
1109 1109
     
1110
-    return $invoice->update_status( $new_status );
1110
+    return $invoice->update_status($new_status);
1111 1111
 }
1112 1112
 
1113
-function wpinv_cart_has_fees( $type = 'all' ) {
1113
+function wpinv_cart_has_fees($type = 'all') {
1114 1114
     return false;
1115 1115
 }
1116 1116
 
1117 1117
 function wpinv_validate_checkout_fields() {    
1118 1118
     // Check if there is $_POST
1119
-    if ( empty( $_POST ) ) {
1119
+    if (empty($_POST)) {
1120 1120
         return false;
1121 1121
     }
1122 1122
     
@@ -1128,11 +1128,11 @@  discard block
 block discarded – undo
1128 1128
     );
1129 1129
     
1130 1130
     // Validate agree to terms
1131
-    $page = wpinv_get_option( 'tandc_page' );
1132
-    if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1131
+    $page = wpinv_get_option('tandc_page');
1132
+    if (isset($page) && (int)$page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1133 1133
         // Validate agree to terms
1134
-        if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) {
1135
-            wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) );
1134
+        if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) {
1135
+            wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing')));
1136 1136
         }
1137 1137
     }
1138 1138
     
@@ -1148,26 +1148,26 @@  discard block
 block discarded – undo
1148 1148
     
1149 1149
     $invoice = wpinv_get_invoice_cart();
1150 1150
     $has_subscription = $invoice->is_recurring();
1151
-    if ( empty( $invoice ) ) {
1152
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1151
+    if (empty($invoice)) {
1152
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1153 1153
         return $gateway;
1154 1154
     }
1155 1155
 
1156 1156
     // Check if a gateway value is present
1157
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1158
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1157
+    if (!empty($_REQUEST['wpi-gateway'])) {
1158
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1159 1159
 
1160
-        if ( $invoice->is_free() ) {
1160
+        if ($invoice->is_free()) {
1161 1161
             $gateway = 'manual';
1162
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1163
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1164
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1165
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
1162
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1163
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1164
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1165
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
1166 1166
         }
1167 1167
     }
1168 1168
 
1169
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1170
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1169
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1170
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1171 1171
     }
1172 1172
 
1173 1173
     return $gateway;
@@ -1181,10 +1181,10 @@  discard block
 block discarded – undo
1181 1181
     
1182 1182
     $error = false;
1183 1183
     // If we have discounts, loop through them
1184
-    if ( ! empty( $discounts ) ) {
1185
-        foreach ( $discounts as $discount ) {
1184
+    if (!empty($discounts)) {
1185
+        foreach ($discounts as $discount) {
1186 1186
             // Check if valid
1187
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1187
+            if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) {
1188 1188
                 // Discount is not valid
1189 1189
                 $error = true;
1190 1190
             }
@@ -1194,20 +1194,20 @@  discard block
 block discarded – undo
1194 1194
         return NULL;
1195 1195
     }
1196 1196
 
1197
-    if ( $error && !wpinv_get_errors() ) {
1198
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1197
+    if ($error && !wpinv_get_errors()) {
1198
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1199 1199
     }
1200 1200
 
1201
-    return implode( ',', $discounts );
1201
+    return implode(',', $discounts);
1202 1202
 }
1203 1203
 
1204 1204
 function wpinv_checkout_validate_cc() {
1205 1205
     $card_data = wpinv_checkout_get_cc_info();
1206 1206
 
1207 1207
     // Validate the card zip
1208
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1209
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1210
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1208
+    if (!empty($card_data['wpinv_zip'])) {
1209
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1210
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1211 1211
         }
1212 1212
     }
1213 1213
 
@@ -1217,28 +1217,28 @@  discard block
 block discarded – undo
1217 1217
 
1218 1218
 function wpinv_checkout_get_cc_info() {
1219 1219
 	$cc_info = array();
1220
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1221
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1222
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1223
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1224
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1225
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1226
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1227
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1228
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1229
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1220
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1221
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1222
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1223
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1224
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1225
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1226
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1227
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1228
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1229
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1230 1230
 
1231 1231
 	// Return cc info
1232 1232
 	return $cc_info;
1233 1233
 }
1234 1234
 
1235
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1235
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1236 1236
     $ret = false;
1237 1237
 
1238
-    if ( empty( $zip ) || empty( $country_code ) )
1238
+    if (empty($zip) || empty($country_code))
1239 1239
         return $ret;
1240 1240
 
1241
-    $country_code = strtoupper( $country_code );
1241
+    $country_code = strtoupper($country_code);
1242 1242
 
1243 1243
     $zip_regex = array(
1244 1244
         "AD" => "AD\d{3}",
@@ -1398,17 +1398,17 @@  discard block
 block discarded – undo
1398 1398
         "ZM" => "\d{5}"
1399 1399
     );
1400 1400
 
1401
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1401
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1402 1402
         $ret = true;
1403 1403
 
1404
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1404
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1405 1405
 }
1406 1406
 
1407 1407
 function wpinv_checkout_validate_agree_to_terms() {
1408 1408
     // Validate agree to terms
1409
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1409
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1410 1410
         // User did not agree
1411
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1411
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1412 1412
     }
1413 1413
 }
1414 1414
 
@@ -1420,40 +1420,40 @@  discard block
 block discarded – undo
1420 1420
     );
1421 1421
     
1422 1422
     // Verify there is a user_ID
1423
-    if ( $user_ID == (int)$wpi_cart->get_user_id() ) {
1423
+    if ($user_ID == (int)$wpi_cart->get_user_id()) {
1424 1424
         // Get the logged in user data
1425
-        $user_data = get_userdata( $user_ID );
1426
-        $required_fields  = wpinv_checkout_required_fields();
1425
+        $user_data = get_userdata($user_ID);
1426
+        $required_fields = wpinv_checkout_required_fields();
1427 1427
 
1428 1428
         // Loop through required fields and show error messages
1429
-         if ( !empty( $required_fields ) ) {
1430
-            foreach ( $required_fields as $field_name => $value ) {
1431
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1432
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1429
+         if (!empty($required_fields)) {
1430
+            foreach ($required_fields as $field_name => $value) {
1431
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1432
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1433 1433
                 }
1434 1434
             }
1435 1435
         }
1436 1436
 
1437 1437
         // Verify data
1438
-        if ( $user_data ) {
1438
+        if ($user_data) {
1439 1439
             // Collected logged in user data
1440 1440
             $valid_user_data = array(
1441 1441
                 'user_id'     => $user_ID,
1442
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1443
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1444
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1442
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1443
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1444
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1445 1445
             );
1446 1446
 
1447
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1448
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1447
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1448
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1449 1449
             }
1450 1450
         } else {
1451 1451
             // Set invalid user error
1452
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1452
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1453 1453
         }
1454 1454
     } else {
1455 1455
         // Set invalid user error
1456
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1456
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1457 1457
     }
1458 1458
 
1459 1459
     // Return user data
@@ -1465,30 +1465,30 @@  discard block
 block discarded – undo
1465 1465
 
1466 1466
     $data = array();
1467 1467
     
1468
-    if ( is_user_logged_in() ) {
1469
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1468
+    if (is_user_logged_in()) {
1469
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) {
1470 1470
             $data['user_id'] = (int)get_current_user_id();
1471 1471
         } else {
1472
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1472
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1473 1473
         }
1474 1474
     } else {
1475 1475
         // If guest checkout allowed
1476
-        if ( !wpinv_require_login_to_checkout() ) {
1476
+        if (!wpinv_require_login_to_checkout()) {
1477 1477
             $data['user_id'] = 0;
1478 1478
         } else {
1479
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1479
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1480 1480
         }
1481 1481
     }
1482 1482
 
1483 1483
     return $data;
1484 1484
 }
1485 1485
 
1486
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1486
+function wpinv_checkout_form_get_user($valid_data = array()) {
1487 1487
     // Initialize user
1488 1488
     $user    = false;
1489
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1489
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1490 1490
 
1491
-    if ( empty( $valid_data['current_user'] ) ) {
1491
+    if (empty($valid_data['current_user'])) {
1492 1492
         $user = false;
1493 1493
     } else {
1494 1494
         // Set the valid invoice user
@@ -1496,7 +1496,7 @@  discard block
 block discarded – undo
1496 1496
     }
1497 1497
 
1498 1498
     // Verify invoice have an user
1499
-    if ( false === $user || empty( $user ) ) {
1499
+    if (false === $user || empty($user)) {
1500 1500
         return false;
1501 1501
     }
1502 1502
 
@@ -1513,11 +1513,11 @@  discard block
 block discarded – undo
1513 1513
         'zip',
1514 1514
     );
1515 1515
     
1516
-    foreach ( $address_fields as $field ) {
1517
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1516
+    foreach ($address_fields as $field) {
1517
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1518 1518
         
1519
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $user['user_id'] ) {
1520
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1519
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $user['user_id']) {
1520
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1521 1521
         }
1522 1522
     }
1523 1523
 
@@ -1525,28 +1525,28 @@  discard block
 block discarded – undo
1525 1525
     return $user;
1526 1526
 }
1527 1527
 
1528
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1528
+function wpinv_set_checkout_session($invoice_data = array()) {
1529 1529
     global $wpi_session;
1530 1530
     
1531
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1531
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1532 1532
 }
1533 1533
 
1534 1534
 function wpinv_get_checkout_session() {
1535 1535
 	global $wpi_session;
1536 1536
     
1537
-    return $wpi_session->get( 'wpinv_checkout' );
1537
+    return $wpi_session->get('wpinv_checkout');
1538 1538
 }
1539 1539
 
1540 1540
 function wpinv_empty_cart() {
1541 1541
     global $wpi_session;
1542 1542
 
1543 1543
     // Remove cart contents
1544
-    $wpi_session->set( 'wpinv_checkout', NULL );
1544
+    $wpi_session->set('wpinv_checkout', NULL);
1545 1545
 
1546 1546
     // Remove all cart fees
1547
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1547
+    $wpi_session->set('wpi_cart_fees', NULL);
1548 1548
 
1549
-    do_action( 'wpinv_empty_cart' );
1549
+    do_action('wpinv_empty_cart');
1550 1550
 }
1551 1551
 
1552 1552
 function wpinv_process_checkout() {
@@ -1555,7 +1555,7 @@  discard block
 block discarded – undo
1555 1555
     wpinv_clear_errors();
1556 1556
     
1557 1557
     $invoice = wpinv_get_invoice_cart();
1558
-    if ( empty( $invoice ) ) {
1558
+    if (empty($invoice)) {
1559 1559
         return false;
1560 1560
     }
1561 1561
     
@@ -1563,42 +1563,42 @@  discard block
 block discarded – undo
1563 1563
     
1564 1564
     $wpi_checkout_id = $invoice->ID;
1565 1565
     
1566
-    do_action( 'wpinv_pre_process_checkout' );
1566
+    do_action('wpinv_pre_process_checkout');
1567 1567
     
1568
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1568
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1569 1569
         $valid_data = false;
1570
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1570
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1571 1571
     } else {
1572 1572
         // Validate the form $_POST data
1573 1573
         $valid_data = wpinv_validate_checkout_fields();
1574 1574
         
1575 1575
         // Allow themes and plugins to hook to errors
1576
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1576
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1577 1577
     }
1578 1578
     
1579
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1579
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1580 1580
     
1581 1581
     // Validate the user
1582
-    $user = wpinv_checkout_form_get_user( $valid_data );
1582
+    $user = wpinv_checkout_form_get_user($valid_data);
1583 1583
 
1584 1584
     // Let extensions validate fields after user is logged in if user has used login/registration form
1585
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1585
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1586 1586
     
1587
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1588
-        if ( $is_ajax ) {
1589
-            do_action( 'wpinv_ajax_checkout_errors' );
1587
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1588
+        if ($is_ajax) {
1589
+            do_action('wpinv_ajax_checkout_errors');
1590 1590
             die();
1591 1591
         } else {
1592 1592
             return false;
1593 1593
         }
1594 1594
     }
1595 1595
 
1596
-    if ( $is_ajax ) {
1596
+    if ($is_ajax) {
1597 1597
         // Save address fields.
1598
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1599
-        foreach ( $address_fields as $field ) {
1600
-            if ( isset( $user[$field] ) ) {
1601
-                $invoice->set( $field, $user[$field] );
1598
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1599
+        foreach ($address_fields as $field) {
1600
+            if (isset($user[$field])) {
1601
+                $invoice->set($field, $user[$field]);
1602 1602
             }
1603 1603
             
1604 1604
             $invoice->save();
@@ -1606,15 +1606,15 @@  discard block
 block discarded – undo
1606 1606
 
1607 1607
         $response['success']            = true;
1608 1608
         $response['data']['subtotal']   = $invoice->get_subtotal();
1609
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1609
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1610 1610
         $response['data']['discount']   = $invoice->get_discount();
1611
-        $response['data']['discountf']  = $invoice->get_discount( true );
1611
+        $response['data']['discountf']  = $invoice->get_discount(true);
1612 1612
         $response['data']['tax']        = $invoice->get_tax();
1613
-        $response['data']['taxf']       = $invoice->get_tax( true );
1613
+        $response['data']['taxf']       = $invoice->get_tax(true);
1614 1614
         $response['data']['total']      = $invoice->get_total();
1615
-        $response['data']['totalf']     = $invoice->get_total( true );
1615
+        $response['data']['totalf']     = $invoice->get_total(true);
1616 1616
         
1617
-        wp_send_json( $response );
1617
+        wp_send_json($response);
1618 1618
     }
1619 1619
     
1620 1620
     $user_info = array(
@@ -1636,42 +1636,42 @@  discard block
 block discarded – undo
1636 1636
     
1637 1637
     // Setup invoice information
1638 1638
     $invoice_data = array(
1639
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1639
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1640 1640
         'items'             => $cart_items,
1641 1641
         'cart_discounts'    => $discounts,
1642
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1643
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1644
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1645
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1646
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1642
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1643
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1644
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1645
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1646
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1647 1647
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1648 1648
         'user_email'        => $user['email'],
1649
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1650
-        'user_info'         => stripslashes_deep( $user_info ),
1649
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1650
+        'user_info'         => stripslashes_deep($user_info),
1651 1651
         'post_data'         => $_POST,
1652 1652
         'cart_details'      => $cart_items,
1653 1653
         'gateway'           => $valid_data['gateway'],
1654 1654
         'card_info'         => $valid_data['cc_info']
1655 1655
     );
1656 1656
     
1657
-    $vat_info   = $wpinv_euvat->current_vat_data();
1658
-    if ( is_array( $vat_info ) ) {
1657
+    $vat_info = $wpinv_euvat->current_vat_data();
1658
+    if (is_array($vat_info)) {
1659 1659
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1660 1660
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1661
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1661
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1662 1662
 
1663 1663
         // Add the VAT rate to each item in the cart
1664
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1664
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1665 1665
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1666
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1666
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1667 1667
         }
1668 1668
     }
1669 1669
     
1670 1670
     // Save vat fields.
1671
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1672
-    foreach ( $address_fields as $field ) {
1673
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1674
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1671
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1672
+    foreach ($address_fields as $field) {
1673
+        if (isset($invoice_data['user_info'][$field])) {
1674
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1675 1675
         }
1676 1676
         
1677 1677
         $invoice->save();
@@ -1681,55 +1681,55 @@  discard block
 block discarded – undo
1681 1681
     $valid_data['user'] = $user;
1682 1682
     
1683 1683
     // Allow themes and plugins to hook before the gateway
1684
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1684
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1685 1685
     
1686 1686
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1687
-    if ( !$invoice_data['price'] ) {
1687
+    if (!$invoice_data['price']) {
1688 1688
         // Revert to manual
1689 1689
         $invoice_data['gateway'] = 'manual';
1690 1690
         $_POST['wpi-gateway'] = 'manual';
1691 1691
     }
1692 1692
     
1693 1693
     // Allow the invoice data to be modified before it is sent to the gateway
1694
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1694
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1695 1695
     
1696
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1696
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1697 1697
         $mode = 'test';
1698 1698
     } else {
1699
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1699
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1700 1700
     }
1701 1701
     
1702 1702
     // Setup the data we're storing in the purchase session
1703 1703
     $session_data = $invoice_data;
1704 1704
     // Make sure credit card numbers are never stored in sessions
1705
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1706
-        unset( $session_data['card_info']['card_number'] );
1705
+    if (!empty($session_data['card_info']['card_number'])) {
1706
+        unset($session_data['card_info']['card_number']);
1707 1707
     }
1708 1708
     
1709 1709
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1710
-    wpinv_set_checkout_session( $invoice_data );
1710
+    wpinv_set_checkout_session($invoice_data);
1711 1711
     
1712 1712
     // Set gateway
1713
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1714
-    $invoice->update_meta( '_wpinv_mode', $mode );
1715
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1713
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1714
+    $invoice->update_meta('_wpinv_mode', $mode);
1715
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1716 1716
     
1717
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1717
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1718 1718
 
1719 1719
     // Send info to the gateway for payment processing
1720
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1720
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1721 1721
     die();
1722 1722
 }
1723
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1723
+add_action('wpinv_payment', 'wpinv_process_checkout');
1724 1724
 
1725
-function wpinv_get_invoices( $args ) {
1726
-    $args = wp_parse_args( $args, array(
1727
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1725
+function wpinv_get_invoices($args) {
1726
+    $args = wp_parse_args($args, array(
1727
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1728 1728
         'type'     => 'wpi_invoice',
1729 1729
         'parent'   => null,
1730 1730
         'user'     => null,
1731 1731
         'email'    => '',
1732
-        'limit'    => get_option( 'posts_per_page' ),
1732
+        'limit'    => get_option('posts_per_page'),
1733 1733
         'offset'   => null,
1734 1734
         'page'     => 1,
1735 1735
         'exclude'  => array(),
@@ -1737,7 +1737,7 @@  discard block
 block discarded – undo
1737 1737
         'order'    => 'DESC',
1738 1738
         'return'   => 'objects',
1739 1739
         'paginate' => false,
1740
-    ) );
1740
+    ));
1741 1741
     
1742 1742
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1743 1743
     $map_legacy = array(
@@ -1750,18 +1750,18 @@  discard block
 block discarded – undo
1750 1750
         'paged'          => 'page',
1751 1751
     );
1752 1752
 
1753
-    foreach ( $map_legacy as $from => $to ) {
1754
-        if ( isset( $args[ $from ] ) ) {
1755
-            $args[ $to ] = $args[ $from ];
1753
+    foreach ($map_legacy as $from => $to) {
1754
+        if (isset($args[$from])) {
1755
+            $args[$to] = $args[$from];
1756 1756
         }
1757 1757
     }
1758 1758
 
1759
-    if ( get_query_var( 'paged' ) )
1759
+    if (get_query_var('paged'))
1760 1760
         $args['page'] = get_query_var('paged');
1761
-    else if ( get_query_var( 'page' ) )
1762
-        $args['page'] = get_query_var( 'page' );
1763
-    else if ( !empty( $args[ 'page' ] ) )
1764
-        $args['page'] = $args[ 'page' ];
1761
+    else if (get_query_var('page'))
1762
+        $args['page'] = get_query_var('page');
1763
+    else if (!empty($args['page']))
1764
+        $args['page'] = $args['page'];
1765 1765
     else
1766 1766
         $args['page'] = 1;
1767 1767
 
@@ -1774,49 +1774,49 @@  discard block
 block discarded – undo
1774 1774
         'post_status'    => $args['status'],
1775 1775
         'posts_per_page' => $args['limit'],
1776 1776
         'meta_query'     => array(),
1777
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1777
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1778 1778
         'fields'         => 'ids',
1779 1779
         'orderby'        => $args['orderby'],
1780 1780
         'order'          => $args['order'],
1781 1781
     );
1782 1782
     
1783
-    if ( !empty( $args['user'] ) ) {
1784
-        $wp_query_args['author'] = absint( $args['user'] );
1783
+    if (!empty($args['user'])) {
1784
+        $wp_query_args['author'] = absint($args['user']);
1785 1785
     }
1786 1786
 
1787
-    if ( ! is_null( $args['parent'] ) ) {
1788
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1787
+    if (!is_null($args['parent'])) {
1788
+        $wp_query_args['post_parent'] = absint($args['parent']);
1789 1789
     }
1790 1790
 
1791
-    if ( ! is_null( $args['offset'] ) ) {
1792
-        $wp_query_args['offset'] = absint( $args['offset'] );
1791
+    if (!is_null($args['offset'])) {
1792
+        $wp_query_args['offset'] = absint($args['offset']);
1793 1793
     } else {
1794
-        $wp_query_args['paged'] = absint( $args['page'] );
1794
+        $wp_query_args['paged'] = absint($args['page']);
1795 1795
     }
1796 1796
 
1797
-    if ( ! empty( $args['exclude'] ) ) {
1798
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1797
+    if (!empty($args['exclude'])) {
1798
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1799 1799
     }
1800 1800
 
1801
-    if ( ! $args['paginate' ] ) {
1801
+    if (!$args['paginate']) {
1802 1802
         $wp_query_args['no_found_rows'] = true;
1803 1803
     }
1804 1804
 
1805 1805
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1806 1806
 
1807 1807
     // Get results.
1808
-    $invoices = new WP_Query( $wp_query_args );
1808
+    $invoices = new WP_Query($wp_query_args);
1809 1809
 
1810
-    if ( 'objects' === $args['return'] ) {
1811
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1812
-    } elseif ( 'self' === $args['return'] ) {
1810
+    if ('objects' === $args['return']) {
1811
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1812
+    } elseif ('self' === $args['return']) {
1813 1813
         return $invoices;
1814 1814
     } else {
1815 1815
         $return = $invoices->posts;
1816 1816
     }
1817 1817
 
1818
-    if ( $args['paginate' ] ) {
1819
-        return (object) array(
1818
+    if ($args['paginate']) {
1819
+        return (object)array(
1820 1820
             'invoices'      => $return,
1821 1821
             'total'         => $invoices->found_posts,
1822 1822
             'max_num_pages' => $invoices->max_num_pages,
@@ -1828,22 +1828,22 @@  discard block
 block discarded – undo
1828 1828
 
1829 1829
 function wpinv_get_user_invoices_columns() {
1830 1830
     $columns = array(
1831
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1832
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1833
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1834
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1835
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1836
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1831
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1832
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1833
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1834
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1835
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1836
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1837 1837
         );
1838 1838
 
1839
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1839
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1840 1840
 }
1841 1841
 
1842
-function wpinv_payment_receipt( $atts, $content = null ) {
1842
+function wpinv_payment_receipt($atts, $content = null) {
1843 1843
     global $wpinv_receipt_args;
1844 1844
 
1845
-    $wpinv_receipt_args = shortcode_atts( array(
1846
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1845
+    $wpinv_receipt_args = shortcode_atts(array(
1846
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1847 1847
         'price'           => true,
1848 1848
         'discount'        => true,
1849 1849
         'items'           => true,
@@ -1852,195 +1852,195 @@  discard block
 block discarded – undo
1852 1852
         'invoice_key'     => false,
1853 1853
         'payment_method'  => true,
1854 1854
         'invoice_id'      => true
1855
-    ), $atts, 'wpinv_receipt' );
1855
+    ), $atts, 'wpinv_receipt');
1856 1856
 
1857 1857
     $session = wpinv_get_checkout_session();
1858
-    if ( isset( $_GET['invoice_key'] ) ) {
1859
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1860
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1858
+    if (isset($_GET['invoice_key'])) {
1859
+        $invoice_key = urldecode($_GET['invoice_key']);
1860
+    } else if ($session && isset($session['invoice_key'])) {
1861 1861
         $invoice_key = $session['invoice_key'];
1862
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1862
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1863 1863
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1864
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1865
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1864
+    } else if (isset($_GET['invoice-id'])) {
1865
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1866 1866
     }
1867 1867
 
1868 1868
     // No key found
1869
-    if ( ! isset( $invoice_key ) ) {
1869
+    if (!isset($invoice_key)) {
1870 1870
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1871 1871
     }
1872 1872
 
1873
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1874
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1875
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1873
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1874
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1875
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1876 1876
         $invoice_id     = (int)$_GET['invoice-id'];
1877
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1877
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1878 1878
     }
1879 1879
 
1880 1880
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1881
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1881
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1882 1882
         // login redirect
1883
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1883
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1884 1884
     }
1885 1885
 
1886
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1886
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1887 1887
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1888 1888
     }
1889 1889
 
1890 1890
     ob_start();
1891 1891
 
1892
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1892
+    wpinv_get_template_part('wpinv-invoice-receipt');
1893 1893
 
1894 1894
     $display = ob_get_clean();
1895 1895
 
1896 1896
     return $display;
1897 1897
 }
1898 1898
 
1899
-function wpinv_get_invoice_id_by_key( $key ) {
1899
+function wpinv_get_invoice_id_by_key($key) {
1900 1900
 	global $wpdb;
1901 1901
 
1902
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1902
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1903 1903
 
1904
-	if ( $invoice_id != NULL )
1904
+	if ($invoice_id != NULL)
1905 1905
 		return $invoice_id;
1906 1906
 
1907 1907
 	return 0;
1908 1908
 }
1909 1909
 
1910
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1910
+function wpinv_can_view_receipt($invoice_key = '') {
1911 1911
 	$return = false;
1912 1912
 
1913
-	if ( empty( $invoice_key ) ) {
1913
+	if (empty($invoice_key)) {
1914 1914
 		return $return;
1915 1915
 	}
1916 1916
 
1917 1917
 	global $wpinv_receipt_args;
1918 1918
 
1919
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1920
-	if ( isset( $_GET['invoice-id'] ) ) {
1921
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1919
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1920
+	if (isset($_GET['invoice-id'])) {
1921
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1922 1922
 	}
1923 1923
 
1924
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1924
+	if (empty($wpinv_receipt_args['id'])) {
1925 1925
 		return $return;
1926 1926
 	}
1927 1927
 
1928
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1929
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1928
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1929
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1930 1930
 		return $return;
1931 1931
 	}
1932 1932
 
1933
-	if ( is_user_logged_in() ) {
1934
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1933
+	if (is_user_logged_in()) {
1934
+		if ((int)$invoice->get_user_id() === (int)get_current_user_id()) {
1935 1935
 			$return = true;
1936 1936
 		}
1937 1937
 	}
1938 1938
 
1939 1939
 	$session = wpinv_get_checkout_session();
1940
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1941
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1940
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1941
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1942 1942
 
1943
-		if ( wpinv_require_login_to_checkout() ) {
1943
+		if (wpinv_require_login_to_checkout()) {
1944 1944
 			$return = $return && $check_key === $invoice_key;
1945 1945
 		} else {
1946 1946
 			$return = $check_key === $invoice_key;
1947 1947
 		}
1948 1948
 	}
1949 1949
 
1950
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1950
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1951 1951
 }
1952 1952
 
1953 1953
 function wpinv_pay_for_invoice() {
1954 1954
     global $wpinv_euvat;
1955 1955
     
1956
-    if ( isset( $_GET['invoice_key'] ) ) {
1956
+    if (isset($_GET['invoice_key'])) {
1957 1957
         $checkout_uri   = wpinv_get_checkout_uri();
1958
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1958
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1959 1959
         
1960
-        if ( empty( $invoice_key ) ) {
1961
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1962
-            wp_redirect( $checkout_uri );
1960
+        if (empty($invoice_key)) {
1961
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1962
+            wp_redirect($checkout_uri);
1963 1963
             wpinv_die();
1964 1964
         }
1965 1965
         
1966
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1966
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1967 1967
 
1968
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1969
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1970
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1968
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1969
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1970
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1971 1971
             $invoice_id     = (int)$_GET['invoice-id'];
1972
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1972
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1973 1973
         }
1974 1974
         
1975
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1976
-            if ( $invoice->needs_payment() ) {
1975
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1976
+            if ($invoice->needs_payment()) {
1977 1977
                 $data                   = array();
1978 1978
                 $data['invoice_id']     = $invoice_id;
1979
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1979
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1980 1980
                 
1981
-                wpinv_set_checkout_session( $data );
1981
+                wpinv_set_checkout_session($data);
1982 1982
                 
1983
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1983
+                if (wpinv_get_option('vat_ip_country_default')) {
1984 1984
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1985 1985
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1986 1986
                     
1987
-                    wpinv_recalculate_tax( true );
1987
+                    wpinv_recalculate_tax(true);
1988 1988
                 }
1989 1989
                 
1990 1990
             } else {
1991 1991
                 $checkout_uri = $invoice->get_view_url();
1992 1992
             }
1993 1993
         } else {
1994
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1994
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1995 1995
             
1996
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1996
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1997 1997
         }
1998 1998
         
1999
-        wp_redirect( $checkout_uri );
1999
+        wp_redirect($checkout_uri);
2000 2000
         wpinv_die();
2001 2001
     }
2002 2002
 }
2003
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2003
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2004 2004
 
2005
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2006
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2007
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2005
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2006
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2007
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2008 2008
             $user_id = $invoice->get_user_id();
2009
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2009
+            $secret = sanitize_text_field($_GET['_wpipay']);
2010 2010
             
2011
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2012
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2011
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2012
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2013 2013
                 
2014
-                wpinv_guest_redirect( $redirect_to, $user_id );
2014
+                wpinv_guest_redirect($redirect_to, $user_id);
2015 2015
                 wpinv_die();
2016 2016
             }
2017 2017
         }
2018 2018
     }
2019 2019
 }
2020
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2020
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2021 2021
 
2022
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2023
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2022
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2023
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2024 2024
     
2025
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2025
+    if (empty($invoice_id) && $invoice_id > 0) {
2026 2026
         return false;
2027 2027
     }
2028 2028
     
2029
-    if ( empty( $transaction_id ) ) {
2029
+    if (empty($transaction_id)) {
2030 2030
         $transaction_id = $invoice_id;
2031 2031
     }
2032 2032
 
2033
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2033
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2034 2034
     
2035
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2035
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2036 2036
 }
2037 2037
 
2038
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2039
-    if ( empty( $status_display ) ) {
2040
-        $status_display = wpinv_status_nicename( $status );
2038
+function wpinv_invoice_status_label($status, $status_display = '') {
2039
+    if (empty($status_display)) {
2040
+        $status_display = wpinv_status_nicename($status);
2041 2041
     }
2042 2042
     
2043
-    switch ( $status ) {
2043
+    switch ($status) {
2044 2044
         case 'publish' :
2045 2045
         case 'wpi-renewal' :
2046 2046
             $class = 'label-success';
@@ -2065,257 +2065,257 @@  discard block
 block discarded – undo
2065 2065
     
2066 2066
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2067 2067
     
2068
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2068
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2069 2069
 }
2070 2070
 
2071
-function wpinv_format_invoice_number( $number, $type = '' ) {
2072
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2073
-    if ( null !== $check ) {
2071
+function wpinv_format_invoice_number($number, $type = '') {
2072
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2073
+    if (null !== $check) {
2074 2074
         return $check;
2075 2075
     }
2076 2076
 
2077
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2077
+    if (!empty($number) && !is_numeric($number)) {
2078 2078
         return $number;
2079 2079
     }
2080 2080
 
2081
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2082
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2083
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2081
+    $padd = wpinv_get_option('invoice_number_padd');
2082
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2083
+    $postfix = wpinv_get_option('invoice_number_postfix');
2084 2084
     
2085
-    $padd = absint( $padd );
2086
-    $formatted_number = absint( $number );
2085
+    $padd = absint($padd);
2086
+    $formatted_number = absint($number);
2087 2087
     
2088
-    if ( $padd > 0 ) {
2089
-        $formatted_number = zeroise( $formatted_number, $padd );
2088
+    if ($padd > 0) {
2089
+        $formatted_number = zeroise($formatted_number, $padd);
2090 2090
     }    
2091 2091
 
2092 2092
     $formatted_number = $prefix . $formatted_number . $postfix;
2093 2093
 
2094
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2094
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2095 2095
 }
2096 2096
 
2097
-function wpinv_get_next_invoice_number( $type = '' ) {
2098
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2099
-    if ( null !== $check ) {
2097
+function wpinv_get_next_invoice_number($type = '') {
2098
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2099
+    if (null !== $check) {
2100 2100
         return $check;
2101 2101
     }
2102 2102
     
2103
-    if ( !wpinv_sequential_number_active() ) {
2103
+    if (!wpinv_sequential_number_active()) {
2104 2104
         return false;
2105 2105
     }
2106 2106
 
2107
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2108
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2109
-    if ( !absint( $start ) > 0 ) {
2107
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2108
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2109
+    if (!absint($start) > 0) {
2110 2110
         $start = 1;
2111 2111
     }
2112 2112
     $increment_number = true;
2113 2113
     $save_number = false;
2114 2114
 
2115
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2116
-        $number = wpinv_clean_invoice_number( $number );
2115
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2116
+        $number = wpinv_clean_invoice_number($number);
2117 2117
     }
2118 2118
 
2119
-    if ( empty( $number ) ) {
2120
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2121
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2119
+    if (empty($number)) {
2120
+        if (!($last_number === 0 || $last_number === '0')) {
2121
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2122 2122
 
2123
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2124
-                if ( is_numeric( $invoice_number ) ) {
2123
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2124
+                if (is_numeric($invoice_number)) {
2125 2125
                     $number = $invoice_number;
2126 2126
                 } else {
2127
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2127
+                    $number = wpinv_clean_invoice_number($invoice_number);
2128 2128
                 }
2129 2129
             }
2130 2130
 
2131
-            if ( empty( $number ) ) {
2131
+            if (empty($number)) {
2132 2132
                 $increment_number = false;
2133 2133
                 $number = $start;
2134
-                $save_number = ( $number - 1 );
2134
+                $save_number = ($number - 1);
2135 2135
             } else {
2136 2136
                 $save_number = $number;
2137 2137
             }
2138 2138
         }
2139 2139
     }
2140 2140
 
2141
-    if ( $start > $number ) {
2141
+    if ($start > $number) {
2142 2142
         $increment_number = false;
2143 2143
         $number = $start;
2144
-        $save_number = ( $number - 1 );
2144
+        $save_number = ($number - 1);
2145 2145
     }
2146 2146
 
2147
-    if ( $save_number !== false ) {
2148
-        update_option( 'wpinv_last_invoice_number', $save_number );
2147
+    if ($save_number !== false) {
2148
+        update_option('wpinv_last_invoice_number', $save_number);
2149 2149
     }
2150 2150
     
2151
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2151
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2152 2152
 
2153
-    if ( $increment_number ) {
2153
+    if ($increment_number) {
2154 2154
         $number++;
2155 2155
     }
2156 2156
 
2157
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2157
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2158 2158
 }
2159 2159
 
2160
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2161
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2162
-    if ( null !== $check ) {
2160
+function wpinv_clean_invoice_number($number, $type = '') {
2161
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2162
+    if (null !== $check) {
2163 2163
         return $check;
2164 2164
     }
2165 2165
     
2166
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2167
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2166
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2167
+    $postfix = wpinv_get_option('invoice_number_postfix');
2168 2168
 
2169
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2169
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2170 2170
 
2171
-    $length      = strlen( $number );
2172
-    $postfix_pos = strrpos( $number, $postfix );
2171
+    $length      = strlen($number);
2172
+    $postfix_pos = strrpos($number, $postfix);
2173 2173
     
2174
-    if ( false !== $postfix_pos ) {
2175
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2174
+    if (false !== $postfix_pos) {
2175
+        $number = substr_replace($number, '', $postfix_pos, $length);
2176 2176
     }
2177 2177
 
2178
-    $number = intval( $number );
2178
+    $number = intval($number);
2179 2179
 
2180
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2180
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2181 2181
 }
2182 2182
 
2183
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2183
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2184 2184
     global $wpdb;
2185 2185
 
2186
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2187
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2186
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2187
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2188 2188
     }
2189 2189
 
2190
-    if ( !$update ) {
2191
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2192
-        clean_post_cache( $post_ID );
2190
+    if (!$update) {
2191
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2192
+        clean_post_cache($post_ID);
2193 2193
     }
2194 2194
 }
2195
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2195
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2196 2196
 
2197
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2198
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2199
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2197
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2198
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2199
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2200 2200
     }
2201 2201
 }
2202
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2202
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2203 2203
 
2204
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2204
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2205 2205
     global $wpdb;
2206 2206
     
2207
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2208
-    if ( null !== $check ) {
2207
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2208
+    if (null !== $check) {
2209 2209
         return $check;
2210 2210
     }
2211 2211
 
2212
-    if ( wpinv_sequential_number_active() ) {
2212
+    if (wpinv_sequential_number_active()) {
2213 2213
         $number = wpinv_get_next_invoice_number();
2214 2214
 
2215
-        if ( $save_sequential ) {
2216
-            update_option( 'wpinv_last_invoice_number', $number );
2215
+        if ($save_sequential) {
2216
+            update_option('wpinv_last_invoice_number', $number);
2217 2217
         }
2218 2218
     } else {
2219 2219
         $number = $post_ID;
2220 2220
     }
2221 2221
 
2222
-    $number = wpinv_format_invoice_number( $number );
2222
+    $number = wpinv_format_invoice_number($number);
2223 2223
 
2224
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2224
+    update_post_meta($post_ID, '_wpinv_number', $number);
2225 2225
 
2226
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2226
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2227 2227
 
2228
-    clean_post_cache( $post_ID );
2228
+    clean_post_cache($post_ID);
2229 2229
 
2230 2230
     return $number;
2231 2231
 }
2232 2232
 
2233
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2234
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2233
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2234
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2235 2235
 }
2236 2236
 
2237
-function wpinv_generate_post_name( $post_ID ) {
2238
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2239
-    $post_name = sanitize_title( $prefix . $post_ID );
2237
+function wpinv_generate_post_name($post_ID) {
2238
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2239
+    $post_name = sanitize_title($prefix . $post_ID);
2240 2240
 
2241
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2241
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2242 2242
 }
2243 2243
 
2244
-function wpinv_is_invoice_viewed( $invoice_id ) {
2245
-    if ( empty( $invoice_id ) ) {
2244
+function wpinv_is_invoice_viewed($invoice_id) {
2245
+    if (empty($invoice_id)) {
2246 2246
         return false;
2247 2247
     }
2248 2248
 
2249
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2249
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2250 2250
 
2251
-    if ( isset($viewed_meta) && 1 == $viewed_meta ) {
2251
+    if (isset($viewed_meta) && 1 == $viewed_meta) {
2252 2252
         $is_viewed = true;
2253 2253
     } else {
2254 2254
         $is_viewed = false;
2255 2255
     }
2256 2256
 
2257
-    return apply_filters( 'wpinv_is_invoice_viewed', $is_viewed, $invoice_id );
2257
+    return apply_filters('wpinv_is_invoice_viewed', $is_viewed, $invoice_id);
2258 2258
 }
2259 2259
 
2260 2260
 function wpinv_mark_invoice_viewed() {
2261 2261
 
2262
-    if ( isset( $_GET['invoice_key'] ) ) {
2262
+    if (isset($_GET['invoice_key'])) {
2263 2263
         $invoice_key = urldecode($_GET['invoice_key']);
2264 2264
 
2265 2265
         $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2266 2266
         $invoice = new WPInv_Invoice($invoice_id);
2267 2267
 
2268
-        if(!$invoice_id){
2268
+        if (!$invoice_id) {
2269 2269
             return;
2270 2270
         }
2271 2271
 
2272
-        if( is_user_logged_in()){
2272
+        if (is_user_logged_in()) {
2273 2273
             $current_user = wp_get_current_user();
2274
-            if(!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()){
2275
-                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2274
+            if (!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()) {
2275
+                update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2276 2276
             }
2277 2277
         } else {
2278
-            update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2278
+            update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2279 2279
         }
2280 2280
     }
2281 2281
 
2282 2282
 }
2283
-add_action( 'init', 'wpinv_mark_invoice_viewed' );
2283
+add_action('init', 'wpinv_mark_invoice_viewed');
2284 2284
 
2285
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2286
-    if ( empty( $invoice ) ) {
2285
+function wpinv_get_subscription($invoice, $by_parent = false) {
2286
+    if (empty($invoice)) {
2287 2287
         return false;
2288 2288
     }
2289 2289
     
2290
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2291
-        $invoice = wpinv_get_invoice( $invoice );
2290
+    if (!is_object($invoice) && is_scalar($invoice)) {
2291
+        $invoice = wpinv_get_invoice($invoice);
2292 2292
     }
2293 2293
     
2294
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2294
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2295 2295
         return false;
2296 2296
     }
2297 2297
     
2298
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2298
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2299 2299
     
2300 2300
     $subs_db    = new WPInv_Subscriptions_DB;
2301
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2301
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2302 2302
     
2303
-    if ( ! empty( $subs ) ) {
2304
-        return reset( $subs );
2303
+    if (!empty($subs)) {
2304
+        return reset($subs);
2305 2305
     }
2306 2306
     
2307 2307
     return false;
2308 2308
 }
2309 2309
 
2310
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2310
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2311 2311
     global $wpdb;
2312 2312
 
2313
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2314
-        if ( !empty( $clauses['join'] ) ) {
2313
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2314
+        if (!empty($clauses['join'])) {
2315 2315
             $clauses['join'] .= " ";
2316 2316
         }
2317 2317
 
2318
-        if ( !empty( $clauses['fields'] ) ) {
2318
+        if (!empty($clauses['fields'])) {
2319 2319
             $clauses['fields'] .= ", ";
2320 2320
         }
2321 2321
 
@@ -2326,4 +2326,4 @@  discard block
 block discarded – undo
2326 2326
 
2327 2327
     return $clauses;
2328 2328
 }
2329
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2330 2329
\ No newline at end of file
2330
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2331 2331
\ No newline at end of file
Please login to merge, or discard this patch.
includes/admin/class-wpinv-users.php 1 patch
Spacing   +17 added lines, -17 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_Admin_Users {
15 15
     private static $instance;
16 16
     
17 17
     public static function run() {
18
-        if ( !isset( self::$instance ) && !( self::$instance instanceof WPInv_Admin_Users ) ) {
18
+        if (!isset(self::$instance) && !(self::$instance instanceof WPInv_Admin_Users)) {
19 19
             self::$instance = new WPInv_Admin_Users;
20 20
         }
21 21
 
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
     }
24 24
     
25 25
     public function __construct() {
26
-        add_filter( 'manage_users_columns', array( $this, 'wpinv_add_user_column') );
27
-        add_filter( 'manage_users_custom_column', array( $this, 'wpinv_user_column_content') , 10, 3 );
26
+        add_filter('manage_users_columns', array($this, 'wpinv_add_user_column'));
27
+        add_filter('manage_users_custom_column', array($this, 'wpinv_user_column_content'), 10, 3);
28 28
     }
29 29
 
30 30
     /**
@@ -34,8 +34,8 @@  discard block
 block discarded – undo
34 34
      *
35 35
      * @return mixed
36 36
      */
37
-    public function wpinv_add_user_column( $column ) {
38
-        $column['wpinvoicing'] = __('Invoicing','invoicing');
37
+    public function wpinv_add_user_column($column) {
38
+        $column['wpinvoicing'] = __('Invoicing', 'invoicing');
39 39
         return $column;
40 40
     }
41 41
 
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
      *
49 49
      * @return string
50 50
      */
51
-    function wpinv_user_column_content( $val, $column_name, $user_id ) {
51
+    function wpinv_user_column_content($val, $column_name, $user_id) {
52 52
         switch ($column_name) {
53 53
             case 'wpinvoicing' :
54
-                return $this->get_user_invoices( $user_id );
54
+                return $this->get_user_invoices($user_id);
55 55
                 break;
56 56
             default:
57 57
         }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      *
66 66
      * @return string
67 67
      */
68
-    public function get_user_invoices($user_id){
68
+    public function get_user_invoices($user_id) {
69 69
         $output = '';
70 70
         $wp_query_args = array(
71 71
             'post_type'      => 'wpi_invoice',
@@ -77,14 +77,14 @@  discard block
 block discarded – undo
77 77
 
78 78
         $wp_query_args = apply_filters('wpinv_get_user_invoices_args', $wp_query_args, $user_id);
79 79
 
80
-        $invoices = new WP_Query( $wp_query_args );
81
-        $count = absint( $invoices->found_posts );
80
+        $invoices = new WP_Query($wp_query_args);
81
+        $count = absint($invoices->found_posts);
82 82
 
83
-        if(empty($count)){
84
-            $output .= __('No Invoice(s)','invoicing');
85
-        }else{
86
-            $link_url = admin_url( "edit.php?post_type=wpi_invoice&author=".absint($user_id) );
87
-            $link_text = sprintf( __('Invoices ( %d )', 'invoicing'), $count );
83
+        if (empty($count)) {
84
+            $output .= __('No Invoice(s)', 'invoicing');
85
+        } else {
86
+            $link_url = admin_url("edit.php?post_type=wpi_invoice&author=" . absint($user_id));
87
+            $link_text = sprintf(__('Invoices ( %d )', 'invoicing'), $count);
88 88
             $output .= "<a href='$link_url' >$link_text</a>";
89 89
         }
90 90
 
Please login to merge, or discard this patch.
includes/admin/class-wpinv-admin-menus.php 1 patch
Spacing   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
  * Setup menus in WP admin.
4 4
  */
5 5
 
6
-defined( 'ABSPATH' ) || exit;
6
+defined('ABSPATH') || exit;
7 7
 
8 8
 /**
9 9
  * WC_Admin_Menus Class.
@@ -13,94 +13,94 @@  discard block
 block discarded – undo
13 13
      * Hook in tabs.
14 14
      */
15 15
     public function __construct() {
16
-        add_action( 'admin_menu', array( $this, 'admin_menu' ), 10 );
17
-        add_action( 'admin_menu', array( $this, 'remove_admin_submenus' ), 10 );
18
-        add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) );
16
+        add_action('admin_menu', array($this, 'admin_menu'), 10);
17
+        add_action('admin_menu', array($this, 'remove_admin_submenus'), 10);
18
+        add_action('admin_head-nav-menus.php', array($this, 'add_nav_menu_meta_boxes'));
19 19
     }
20 20
 
21 21
     public function admin_menu() {
22 22
         global $menu;
23 23
 
24
-        if ( !(current_user_can( 'manage_invoicing' ) || current_user_can( 'manage_options' )) ) {
24
+        if (!(current_user_can('manage_invoicing') || current_user_can('manage_options'))) {
25 25
             return;
26 26
         }
27 27
 
28
-        $capability = apply_filters( 'invoicing_capability', 'manage_invoicing' );
28
+        $capability = apply_filters('invoicing_capability', 'manage_invoicing');
29 29
 
30
-        if ( current_user_can( 'manage_options' ) ) {
31
-            $menu[] = array( '', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv' );
30
+        if (current_user_can('manage_options')) {
31
+            $menu[] = array('', 'read', 'separator-wpinv', '', 'wp-menu-separator wpinv');
32 32
         }
33 33
 
34
-        $wpi_invoice = get_post_type_object( 'wpi_invoice' );
34
+        $wpi_invoice = get_post_type_object('wpi_invoice');
35 35
 
36
-        add_menu_page( __( 'Invoicing', 'invoicing' ), __( 'Invoicing', 'invoicing' ), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460' );
36
+        add_menu_page(__('Invoicing', 'invoicing'), __('Invoicing', 'invoicing'), $capability, 'wpinv', null, $wpi_invoice->menu_icon, '54.123460');
37 37
 
38
-        add_submenu_page( 'wpinv', __( 'Invoice Settings', 'invoicing' ), __( 'Settings', 'invoicing' ), $capability, 'wpinv-settings', array( $this, 'options_page' ));
38
+        add_submenu_page('wpinv', __('Invoice Settings', 'invoicing'), __('Settings', 'invoicing'), $capability, 'wpinv-settings', array($this, 'options_page'));
39 39
     }
40 40
 
41 41
     function options_page() {
42
-        $page       = isset( $_GET['page'] )                ? strtolower( $_GET['page'] )               : false;
42
+        $page = isset($_GET['page']) ? strtolower($_GET['page']) : false;
43 43
 
44
-        if ( $page !== 'wpinv-settings' ) {
44
+        if ($page !== 'wpinv-settings') {
45 45
             return;
46 46
         }
47 47
 
48 48
         $settings_tabs = wpinv_get_settings_tabs();
49 49
         $settings_tabs = empty($settings_tabs) ? array() : $settings_tabs;
50
-        $active_tab    = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_tabs ) ? sanitize_text_field( $_GET['tab'] ) : 'general';
51
-        $sections      = wpinv_get_settings_tab_sections( $active_tab );
50
+        $active_tab    = isset($_GET['tab']) && array_key_exists($_GET['tab'], $settings_tabs) ? sanitize_text_field($_GET['tab']) : 'general';
51
+        $sections      = wpinv_get_settings_tab_sections($active_tab);
52 52
         $key           = 'main';
53 53
 
54
-        if ( is_array( $sections ) ) {
55
-            $key = key( $sections );
54
+        if (is_array($sections)) {
55
+            $key = key($sections);
56 56
         }
57 57
 
58
-        $registered_sections = wpinv_get_settings_tab_sections( $active_tab );
59
-        $section             = isset( $_GET['section'] ) && ! empty( $registered_sections ) && array_key_exists( $_GET['section'], $registered_sections ) ? $_GET['section'] : $key;
58
+        $registered_sections = wpinv_get_settings_tab_sections($active_tab);
59
+        $section             = isset($_GET['section']) && !empty($registered_sections) && array_key_exists($_GET['section'], $registered_sections) ? $_GET['section'] : $key;
60 60
         ob_start();
61 61
         ?>
62 62
         <div class="wrap">
63 63
             <h1 class="nav-tab-wrapper">
64 64
                 <?php
65
-                foreach( wpinv_get_settings_tabs() as $tab_id => $tab_name ) {
66
-                    $tab_url = add_query_arg( array(
65
+                foreach (wpinv_get_settings_tabs() as $tab_id => $tab_name) {
66
+                    $tab_url = add_query_arg(array(
67 67
                         'settings-updated' => false,
68 68
                         'tab' => $tab_id,
69
-                    ) );
69
+                    ));
70 70
 
71 71
                     // Remove the section from the tabs so we always end up at the main section
72
-                    $tab_url = remove_query_arg( 'section', $tab_url );
73
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
72
+                    $tab_url = remove_query_arg('section', $tab_url);
73
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
74 74
 
75 75
                     $active = $active_tab == $tab_id ? ' nav-tab-active' : '';
76 76
 
77
-                    echo '<a href="' . esc_url( $tab_url ) . '" title="' . esc_attr( $tab_name ) . '" class="nav-tab' . $active . '">';
78
-                    echo esc_html( $tab_name );
77
+                    echo '<a href="' . esc_url($tab_url) . '" title="' . esc_attr($tab_name) . '" class="nav-tab' . $active . '">';
78
+                    echo esc_html($tab_name);
79 79
                     echo '</a>';
80 80
                 }
81 81
                 ?>
82 82
             </h1>
83 83
             <?php
84
-            $number_of_sections = count( $sections );
84
+            $number_of_sections = count($sections);
85 85
             $number = 0;
86
-            if ( $number_of_sections > 1 ) {
86
+            if ($number_of_sections > 1) {
87 87
                 echo '<div><ul class="subsubsub">';
88
-                foreach( $sections as $section_id => $section_name ) {
88
+                foreach ($sections as $section_id => $section_name) {
89 89
                     echo '<li>';
90 90
                     $number++;
91
-                    $tab_url = add_query_arg( array(
91
+                    $tab_url = add_query_arg(array(
92 92
                         'settings-updated' => false,
93 93
                         'tab' => $active_tab,
94 94
                         'section' => $section_id
95
-                    ) );
96
-                    $tab_url = remove_query_arg( 'wpi_sub', $tab_url );
95
+                    ));
96
+                    $tab_url = remove_query_arg('wpi_sub', $tab_url);
97 97
                     $class = '';
98
-                    if ( $section == $section_id ) {
98
+                    if ($section == $section_id) {
99 99
                         $class = 'current';
100 100
                     }
101
-                    echo '<a class="' . $class . '" href="' . esc_url( $tab_url ) . '">' . $section_name . '</a>';
101
+                    echo '<a class="' . $class . '" href="' . esc_url($tab_url) . '">' . $section_name . '</a>';
102 102
 
103
-                    if ( $number != $number_of_sections ) {
103
+                    if ($number != $number_of_sections) {
104 104
                         echo ' | ';
105 105
                     }
106 106
                     echo '</li>';
@@ -112,19 +112,19 @@  discard block
 block discarded – undo
112 112
                 <form method="post" action="options.php">
113 113
                     <table class="form-table">
114 114
                         <?php
115
-                        settings_fields( 'wpinv_settings' );
115
+                        settings_fields('wpinv_settings');
116 116
 
117
-                        if ( 'main' === $section ) {
118
-                            do_action( 'wpinv_settings_tab_top', $active_tab );
117
+                        if ('main' === $section) {
118
+                            do_action('wpinv_settings_tab_top', $active_tab);
119 119
                         }
120 120
 
121
-                        do_action( 'wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section );
122
-                        do_settings_sections( 'wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section );
123
-                        do_action( 'wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section );
121
+                        do_action('wpinv_settings_tab_top_' . $active_tab . '_' . $section, $active_tab, $section);
122
+                        do_settings_sections('wpinv_settings_' . $active_tab . '_' . $section, $active_tab, $section);
123
+                        do_action('wpinv_settings_tab_bottom_' . $active_tab . '_' . $section, $active_tab, $section);
124 124
 
125 125
                         // For backwards compatibility
126
-                        if ( 'main' === $section ) {
127
-                            do_action( 'wpinv_settings_tab_bottom', $active_tab );
126
+                        if ('main' === $section) {
127
+                            do_action('wpinv_settings_tab_bottom', $active_tab);
128 128
                         }
129 129
                         ?>
130 130
                     </table>
@@ -138,52 +138,52 @@  discard block
 block discarded – undo
138 138
     }
139 139
 
140 140
     public function remove_admin_submenus() {
141
-        remove_submenu_page( 'edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice' );
141
+        remove_submenu_page('edit.php?post_type=wpi_invoice', 'post-new.php?post_type=wpi_invoice');
142 142
     }
143 143
 
144
-    public function add_nav_menu_meta_boxes(){
145
-        add_meta_box( 'wpinv_endpoints_nav_link', __( 'Invoicing Pages', 'invoicing' ), array( $this, 'nav_menu_links' ), 'nav-menus', 'side', 'low' );
144
+    public function add_nav_menu_meta_boxes() {
145
+        add_meta_box('wpinv_endpoints_nav_link', __('Invoicing Pages', 'invoicing'), array($this, 'nav_menu_links'), 'nav-menus', 'side', 'low');
146 146
     }
147 147
 
148
-    public function nav_menu_links(){
148
+    public function nav_menu_links() {
149 149
         $endpoints = $this->get_menu_items();
150 150
         ?>
151 151
         <div id="invoicing-endpoints" class="posttypediv">
152
-        <?php if(!empty($endpoints['pages'])){ ?>
152
+        <?php if (!empty($endpoints['pages'])) { ?>
153 153
             <div id="tabs-panel-invoicing-endpoints" class="tabs-panel tabs-panel-active">
154 154
                 <ul id="invoicing-endpoints-checklist" class="categorychecklist form-no-clear">
155 155
                     <?php
156 156
                     $walker = new Walker_Nav_Menu_Checklist(array());
157
-                    echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object) array('walker' => $walker));
157
+                    echo walk_nav_menu_tree(array_map('wp_setup_nav_menu_item', $endpoints['pages']), 0, (object)array('walker' => $walker));
158 158
                     ?>
159 159
                 </ul>
160 160
             </div>
161 161
         <?php } ?>
162 162
         <p class="button-controls">
163 163
         <span class="list-controls">
164
-            <a href="<?php echo admin_url( 'nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints' ); ?>" class="select-all"><?php _e( 'Select all', 'invoicing' ); ?></a>
164
+            <a href="<?php echo admin_url('nav-menus.php?page-tab=all&selectall=1#invoicing-endpoints'); ?>" class="select-all"><?php _e('Select all', 'invoicing'); ?></a>
165 165
         </span>
166 166
             <span class="add-to-menu">
167
-            <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( 'Add to menu', 'invoicing' ); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints">
167
+            <input type="submit" class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to menu', 'invoicing'); ?>" name="add-post-type-menu-item" id="submit-invoicing-endpoints">
168 168
             <span class="spinner"></span>
169 169
         </span>
170 170
         </p>
171 171
         <?php
172 172
     }
173 173
 
174
-    public function get_menu_items(){
174
+    public function get_menu_items() {
175 175
         $items = array();
176 176
 
177
-        $wpinv_history_page_id = (int)wpinv_get_option( 'invoice_history_page' );
178
-        if($wpinv_history_page_id > 0){
177
+        $wpinv_history_page_id = (int)wpinv_get_option('invoice_history_page');
178
+        if ($wpinv_history_page_id > 0) {
179 179
             $item = new stdClass();
180 180
             $item->object_id = $wpinv_history_page_id;
181 181
             $item->db_id = 0;
182
-            $item->object =  'page';
182
+            $item->object = 'page';
183 183
             $item->menu_item_parent = 0;
184 184
             $item->type = 'post_type';
185
-            $item->title = __('Invoice History Page','invoicing');
186
-            $item->url = get_permalink( $wpinv_history_page_id );
185
+            $item->title = __('Invoice History Page', 'invoicing');
186
+            $item->url = get_permalink($wpinv_history_page_id);
187 187
             $item->target = '';
188 188
             $item->attr_title = '';
189 189
             $item->classes = array('wpinv-menu-item');
@@ -192,16 +192,16 @@  discard block
 block discarded – undo
192 192
             $items['pages'][] = $item;
193 193
         }
194 194
 
195
-        $wpinv_sub_history_page_id = (int)wpinv_get_option( 'invoice_subscription_page' );
196
-        if($wpinv_sub_history_page_id > 0){
195
+        $wpinv_sub_history_page_id = (int)wpinv_get_option('invoice_subscription_page');
196
+        if ($wpinv_sub_history_page_id > 0) {
197 197
             $item = new stdClass();
198 198
             $item->object_id = $wpinv_sub_history_page_id;
199 199
             $item->db_id = 0;
200
-            $item->object =  'page';
200
+            $item->object = 'page';
201 201
             $item->menu_item_parent = 0;
202 202
             $item->type = 'post_type';
203
-            $item->title = __('Invoice Subscriptions Page','invoicing');
204
-            $item->url = get_permalink( $wpinv_sub_history_page_id );
203
+            $item->title = __('Invoice Subscriptions Page', 'invoicing');
204
+            $item->url = get_permalink($wpinv_sub_history_page_id);
205 205
             $item->target = '';
206 206
             $item->attr_title = '';
207 207
             $item->classes = array('wpinv-menu-item');
@@ -210,16 +210,16 @@  discard block
 block discarded – undo
210 210
             $items['pages'][] = $item;
211 211
         }
212 212
 
213
-        $wpinv_checkout_page_id = (int)wpinv_get_option( 'checkout_page' );
214
-        if($wpinv_checkout_page_id > 0){
213
+        $wpinv_checkout_page_id = (int)wpinv_get_option('checkout_page');
214
+        if ($wpinv_checkout_page_id > 0) {
215 215
             $item = new stdClass();
216 216
             $item->object_id = $wpinv_checkout_page_id;
217 217
             $item->db_id = 0;
218
-            $item->object =  'page';
218
+            $item->object = 'page';
219 219
             $item->menu_item_parent = 0;
220 220
             $item->type = 'post_type';
221
-            $item->title = __('Checkout Page','invoicing');
222
-            $item->url = get_permalink( $wpinv_checkout_page_id );
221
+            $item->title = __('Checkout Page', 'invoicing');
222
+            $item->url = get_permalink($wpinv_checkout_page_id);
223 223
             $item->target = '';
224 224
             $item->attr_title = '';
225 225
             $item->classes = array('wpinv-menu-item');
@@ -228,16 +228,16 @@  discard block
 block discarded – undo
228 228
             $items['pages'][] = $item;
229 229
         }
230 230
 
231
-        $wpinv_tandc_page_id = (int)wpinv_get_option( 'tandc_page' );
232
-        if($wpinv_tandc_page_id > 0){
231
+        $wpinv_tandc_page_id = (int)wpinv_get_option('tandc_page');
232
+        if ($wpinv_tandc_page_id > 0) {
233 233
             $item = new stdClass();
234 234
             $item->object_id = $wpinv_tandc_page_id;
235 235
             $item->db_id = 0;
236
-            $item->object =  'page';
236
+            $item->object = 'page';
237 237
             $item->menu_item_parent = 0;
238 238
             $item->type = 'post_type';
239
-            $item->title = __('Terms & Conditions','invoicing');
240
-            $item->url = get_permalink( $wpinv_tandc_page_id );
239
+            $item->title = __('Terms & Conditions', 'invoicing');
240
+            $item->url = get_permalink($wpinv_tandc_page_id);
241 241
             $item->target = '';
242 242
             $item->attr_title = '';
243 243
             $item->classes = array('wpinv-menu-item');
@@ -246,16 +246,16 @@  discard block
 block discarded – undo
246 246
             $items['pages'][] = $item;
247 247
         }
248 248
 
249
-        $wpinv_success_page_id = (int)wpinv_get_option( 'success_page' );
250
-        if($wpinv_success_page_id > 0){
249
+        $wpinv_success_page_id = (int)wpinv_get_option('success_page');
250
+        if ($wpinv_success_page_id > 0) {
251 251
             $item = new stdClass();
252 252
             $item->object_id = $wpinv_success_page_id;
253 253
             $item->db_id = 0;
254
-            $item->object =  'page';
254
+            $item->object = 'page';
255 255
             $item->menu_item_parent = 0;
256 256
             $item->type = 'post_type';
257
-            $item->title = __('Success Page','invoicing');
258
-            $item->url = get_permalink( $wpinv_success_page_id );
257
+            $item->title = __('Success Page', 'invoicing');
258
+            $item->url = get_permalink($wpinv_success_page_id);
259 259
             $item->target = '';
260 260
             $item->attr_title = '';
261 261
             $item->classes = array('wpinv-menu-item');
@@ -264,16 +264,16 @@  discard block
 block discarded – undo
264 264
             $items['pages'][] = $item;
265 265
         }
266 266
 
267
-        $wpinv_failure_page_id = (int)wpinv_get_option( 'failure_page' );
268
-        if($wpinv_failure_page_id > 0){
267
+        $wpinv_failure_page_id = (int)wpinv_get_option('failure_page');
268
+        if ($wpinv_failure_page_id > 0) {
269 269
             $item = new stdClass();
270 270
             $item->object_id = $wpinv_failure_page_id;
271 271
             $item->db_id = 0;
272
-            $item->object =  'page';
272
+            $item->object = 'page';
273 273
             $item->menu_item_parent = 0;
274 274
             $item->type = 'post_type';
275
-            $item->title = __('Failed Transaction Page','invoicing');
276
-            $item->url = get_permalink( $wpinv_failure_page_id );
275
+            $item->title = __('Failed Transaction Page', 'invoicing');
276
+            $item->url = get_permalink($wpinv_failure_page_id);
277 277
             $item->target = '';
278 278
             $item->attr_title = '';
279 279
             $item->classes = array('wpinv-menu-item');
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
             $items['pages'][] = $item;
283 283
         }
284 284
 
285
-        return apply_filters( 'wpinv_menu_items', $items );
285
+        return apply_filters('wpinv_menu_items', $items);
286 286
     }
287 287
 
288 288
 }
Please login to merge, or discard this patch.
includes/admin/admin-pages.php 1 patch
Spacing   +147 added lines, -147 removed lines patch added patch discarded remove patch
@@ -1,47 +1,47 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-add_filter( 'manage_wpi_discount_posts_columns', 'wpinv_discount_columns' );
8
-function wpinv_discount_columns( $existing_columns ) {
7
+add_filter('manage_wpi_discount_posts_columns', 'wpinv_discount_columns');
8
+function wpinv_discount_columns($existing_columns) {
9 9
     $columns                = array();
10 10
     $columns['cb']          = $existing_columns['cb'];
11
-    $columns['name']        = __( 'Name', 'invoicing' );
12
-    $columns['code']        = __( 'Code', 'invoicing' );
13
-    $columns['amount']      = __( 'Amount', 'invoicing' );
14
-    $columns['usage']       = __( 'Usage / Limit', 'invoicing' );
15
-    $columns['start_date']  = __( 'Start Date', 'invoicing' );
16
-    $columns['expiry_date'] = __( 'Expiry Date', 'invoicing' );
17
-    $columns['status']      = __( 'Status', 'invoicing' );
11
+    $columns['name']        = __('Name', 'invoicing');
12
+    $columns['code']        = __('Code', 'invoicing');
13
+    $columns['amount']      = __('Amount', 'invoicing');
14
+    $columns['usage']       = __('Usage / Limit', 'invoicing');
15
+    $columns['start_date']  = __('Start Date', 'invoicing');
16
+    $columns['expiry_date'] = __('Expiry Date', 'invoicing');
17
+    $columns['status']      = __('Status', 'invoicing');
18 18
 
19 19
     return $columns;
20 20
 }
21 21
 
22
-add_action( 'manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column' );
23
-function wpinv_discount_custom_column( $column ) {
22
+add_action('manage_wpi_discount_posts_custom_column', 'wpinv_discount_custom_column');
23
+function wpinv_discount_custom_column($column) {
24 24
     global $post;
25 25
     
26 26
     $discount = $post;
27 27
 
28
-    switch ( $column ) {
28
+    switch ($column) {
29 29
         case 'name' :
30
-            echo get_the_title( $discount->ID );
30
+            echo get_the_title($discount->ID);
31 31
         break;
32 32
         case 'code' :
33
-            echo wpinv_get_discount_code( $discount->ID );
33
+            echo wpinv_get_discount_code($discount->ID);
34 34
         break;
35 35
         case 'amount' :
36
-            echo wpinv_format_discount_rate( wpinv_get_discount_type( $discount->ID ), wpinv_get_discount_amount( $discount->ID ) );
36
+            echo wpinv_format_discount_rate(wpinv_get_discount_type($discount->ID), wpinv_get_discount_amount($discount->ID));
37 37
         break;
38 38
         case 'usage_limit' :
39
-            echo wpinv_get_discount_uses( $discount->ID );
39
+            echo wpinv_get_discount_uses($discount->ID);
40 40
         break;
41 41
         case 'usage' :
42
-            $usage = wpinv_get_discount_uses( $discount->ID ) . ' / ';
43
-            if ( wpinv_get_discount_max_uses( $discount->ID ) ) {
44
-                $usage .= wpinv_get_discount_max_uses( $discount->ID );
42
+            $usage = wpinv_get_discount_uses($discount->ID) . ' / ';
43
+            if (wpinv_get_discount_max_uses($discount->ID)) {
44
+                $usage .= wpinv_get_discount_max_uses($discount->ID);
45 45
             } else {
46 46
                 $usage .= ' &infin;';
47 47
             }
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
             echo $usage;
50 50
         break;
51 51
         case 'start_date' :
52
-            if ( $start_date = wpinv_get_discount_start_date( $discount->ID ) ) {
53
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $start_date ) );
52
+            if ($start_date = wpinv_get_discount_start_date($discount->ID)) {
53
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($start_date));
54 54
             } else {
55 55
                 $value = '-';
56 56
             }
@@ -58,163 +58,163 @@  discard block
 block discarded – undo
58 58
             echo $value;
59 59
         break;
60 60
         case 'expiry_date' :
61
-            if ( $expiration = wpinv_get_discount_expiration( $discount->ID ) ) {
62
-                $value = date_i18n( get_option( 'date_format' ) . ' @ ' . get_option( 'time_format' ), strtotime( $expiration ) );
61
+            if ($expiration = wpinv_get_discount_expiration($discount->ID)) {
62
+                $value = date_i18n(get_option('date_format') . ' @ ' . get_option('time_format'), strtotime($expiration));
63 63
             } else {
64
-                $value = __( 'Never', 'invoicing' );
64
+                $value = __('Never', 'invoicing');
65 65
             }
66 66
                 
67 67
             echo $value;
68 68
         break;
69 69
         break;
70 70
         case 'description' :
71
-            echo wp_kses_post( $post->post_excerpt );
71
+            echo wp_kses_post($post->post_excerpt);
72 72
         break;
73 73
         case 'status' :
74
-            $status = wpinv_is_discount_expired( $discount->ID ) ? 'expired' : $discount->post_status;
74
+            $status = wpinv_is_discount_expired($discount->ID) ? 'expired' : $discount->post_status;
75 75
             
76
-            echo wpinv_discount_status( $status );
76
+            echo wpinv_discount_status($status);
77 77
         break;
78 78
     }
79 79
 }
80 80
 
81
-add_filter( 'post_row_actions', 'wpinv_post_row_actions', 9999, 2 );
82
-function wpinv_post_row_actions( $actions, $post ) {
83
-    $post_type = !empty( $post->post_type ) ? $post->post_type : '';
81
+add_filter('post_row_actions', 'wpinv_post_row_actions', 9999, 2);
82
+function wpinv_post_row_actions($actions, $post) {
83
+    $post_type = !empty($post->post_type) ? $post->post_type : '';
84 84
     
85
-    if ( $post_type == 'wpi_invoice' ) {
85
+    if ($post_type == 'wpi_invoice') {
86 86
         $actions = array();
87 87
     }
88 88
     
89
-    if ( $post_type == 'wpi_discount' ) {
90
-        $actions = wpinv_discount_row_actions( $post, $actions );
89
+    if ($post_type == 'wpi_discount') {
90
+        $actions = wpinv_discount_row_actions($post, $actions);
91 91
     }
92 92
     
93 93
     return $actions;
94 94
 }
95 95
 
96
-function wpinv_discount_row_actions( $discount, $row_actions ) {
97
-    $row_actions  = array();
98
-    $edit_link = get_edit_post_link( $discount->ID );
99
-    $row_actions['edit'] = '<a href="' . esc_url( $edit_link ) . '">' . __( 'Edit', 'invoicing' ) . '</a>';
96
+function wpinv_discount_row_actions($discount, $row_actions) {
97
+    $row_actions = array();
98
+    $edit_link = get_edit_post_link($discount->ID);
99
+    $row_actions['edit'] = '<a href="' . esc_url($edit_link) . '">' . __('Edit', 'invoicing') . '</a>';
100 100
 
101
-    if( in_array( strtolower( $discount->post_status ),  array(  'publish' ) ) ) {
102
-        $row_actions['deactivate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'deactivate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Deactivate', 'invoicing' ) . '</a>';
103
-    } elseif( in_array( strtolower( $discount->post_status ),  array( 'pending', 'draft' ) ) ) {
104
-        $row_actions['activate'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'activate_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Activate', 'invoicing' ) . '</a>';
101
+    if (in_array(strtolower($discount->post_status), array('publish'))) {
102
+        $row_actions['deactivate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'deactivate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Deactivate', 'invoicing') . '</a>';
103
+    } elseif (in_array(strtolower($discount->post_status), array('pending', 'draft'))) {
104
+        $row_actions['activate'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'activate_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Activate', 'invoicing') . '</a>';
105 105
     }
106 106
 
107
-    if ( wpinv_get_discount_uses( $discount->ID ) > 0 ) {
108
-        if ( isset( $row_actions['delete'] ) ) {
109
-            unset( $row_actions['delete'] ); // Don't delete used discounts.
107
+    if (wpinv_get_discount_uses($discount->ID) > 0) {
108
+        if (isset($row_actions['delete'])) {
109
+            unset($row_actions['delete']); // Don't delete used discounts.
110 110
         }
111 111
     } else {
112
-        $row_actions['delete'] = '<a href="' . esc_url( wp_nonce_url( add_query_arg( array( 'wpi_action' => 'delete_discount', 'discount' => $discount->ID ) ), 'wpinv_discount_nonce' ) ) . '">' . __( 'Delete', 'invoicing' ) . '</a>';
112
+        $row_actions['delete'] = '<a href="' . esc_url(wp_nonce_url(add_query_arg(array('wpi_action' => 'delete_discount', 'discount' => $discount->ID)), 'wpinv_discount_nonce')) . '">' . __('Delete', 'invoicing') . '</a>';
113 113
     }
114 114
     
115 115
 
116
-    $row_actions = apply_filters( 'wpinv_discount_row_actions', $row_actions, $discount );
116
+    $row_actions = apply_filters('wpinv_discount_row_actions', $row_actions, $discount);
117 117
 
118 118
     return $row_actions;
119 119
 }
120 120
 
121
-add_filter( 'list_table_primary_column', 'wpinv_table_primary_column', 10, 2 );
122
-function wpinv_table_primary_column( $default, $screen_id ) {
123
-    if ( 'edit-wpi_invoice' === $screen_id ) {
121
+add_filter('list_table_primary_column', 'wpinv_table_primary_column', 10, 2);
122
+function wpinv_table_primary_column($default, $screen_id) {
123
+    if ('edit-wpi_invoice' === $screen_id) {
124 124
         return 'name';
125 125
     }
126 126
     
127 127
     return $default;
128 128
 }
129 129
 
130
-function wpinv_discount_bulk_actions( $actions, $display = false ) {    
131
-    if ( !$display ) {
130
+function wpinv_discount_bulk_actions($actions, $display = false) {    
131
+    if (!$display) {
132 132
         return array();
133 133
     }
134 134
     
135 135
     $actions = array(
136
-        'activate'   => __( 'Activate', 'invoicing' ),
137
-        'deactivate' => __( 'Deactivate', 'invoicing' ),
138
-        'delete'     => __( 'Delete', 'invoicing' ),
136
+        'activate'   => __('Activate', 'invoicing'),
137
+        'deactivate' => __('Deactivate', 'invoicing'),
138
+        'delete'     => __('Delete', 'invoicing'),
139 139
     );
140 140
     $two = '';
141 141
     $which = 'top';
142 142
     echo '</div><div class="alignleft actions bulkactions">';
143
-    echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
144
-    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">";
145
-    echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>";
143
+    echo '<label for="bulk-action-selector-' . esc_attr($which) . '" class="screen-reader-text">' . __('Select bulk action') . '</label>';
144
+    echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr($which) . "\">";
145
+    echo '<option value="-1">' . __('Bulk Actions') . "</option>";
146 146
 
147
-    foreach ( $actions as $name => $title ) {
147
+    foreach ($actions as $name => $title) {
148 148
         $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
149 149
 
150 150
         echo "" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>";
151 151
     }
152 152
     echo "</select>";
153 153
 
154
-    submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
154
+    submit_button(__('Apply'), 'action', '', false, array('id' => "doaction$two"));
155 155
     
156 156
     echo '</div><div class="alignleft actions">';
157 157
 }
158
-add_filter( 'bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10 );
158
+add_filter('bulk_actions-edit-wpi_discount', 'wpinv_discount_bulk_actions', 10);
159 159
 
160
-function wpinv_disable_months_dropdown( $disable, $post_type ) {
161
-    if ( $post_type == 'wpi_discount' ) {
160
+function wpinv_disable_months_dropdown($disable, $post_type) {
161
+    if ($post_type == 'wpi_discount') {
162 162
         $disable = true;
163 163
     }
164 164
     
165 165
     return $disable;
166 166
 }
167
-add_filter( 'disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2 );
167
+add_filter('disable_months_dropdown', 'wpinv_disable_months_dropdown', 10, 2);
168 168
 
169 169
 function wpinv_restrict_manage_posts() {
170 170
     global $typenow;
171 171
 
172
-    if( 'wpi_discount' == $typenow ) {
172
+    if ('wpi_discount' == $typenow) {
173 173
         wpinv_discount_filters();
174 174
     }
175 175
 }
176
-add_action( 'restrict_manage_posts', 'wpinv_restrict_manage_posts', 10 );
176
+add_action('restrict_manage_posts', 'wpinv_restrict_manage_posts', 10);
177 177
 
178 178
 function wpinv_discount_filters() {
179
-    echo wpinv_discount_bulk_actions( array(), true );
179
+    echo wpinv_discount_bulk_actions(array(), true);
180 180
     
181 181
     ?>
182 182
     <select name="discount_type" id="dropdown_wpinv_discount_type">
183
-        <option value=""><?php _e( 'Show all types', 'invoicing' ); ?></option>
183
+        <option value=""><?php _e('Show all types', 'invoicing'); ?></option>
184 184
         <?php
185 185
             $types = wpinv_get_discount_types();
186 186
 
187
-            foreach ( $types as $name => $type ) {
188
-                echo '<option value="' . esc_attr( $name ) . '"';
187
+            foreach ($types as $name => $type) {
188
+                echo '<option value="' . esc_attr($name) . '"';
189 189
 
190
-                if ( isset( $_GET['discount_type'] ) )
191
-                    selected( $name, $_GET['discount_type'] );
190
+                if (isset($_GET['discount_type']))
191
+                    selected($name, $_GET['discount_type']);
192 192
 
193
-                echo '>' . esc_html__( $type, 'invoicing' ) . '</option>';
193
+                echo '>' . esc_html__($type, 'invoicing') . '</option>';
194 194
             }
195 195
         ?>
196 196
     </select>
197 197
     <?php
198 198
 }
199 199
 
200
-function wpinv_request( $vars ) {
200
+function wpinv_request($vars) {
201 201
     global $typenow, $wp_query, $wp_post_statuses;
202 202
 
203
-    if ( 'wpi_invoice' === $typenow ) {
204
-        if ( !isset( $vars['post_status'] ) ) {
203
+    if ('wpi_invoice' === $typenow) {
204
+        if (!isset($vars['post_status'])) {
205 205
             $post_statuses = wpinv_get_invoice_statuses();
206 206
 
207
-            foreach ( $post_statuses as $status => $value ) {
208
-                if ( isset( $wp_post_statuses[ $status ] ) && false === $wp_post_statuses[ $status ]->show_in_admin_all_list ) {
209
-                    unset( $post_statuses[ $status ] );
207
+            foreach ($post_statuses as $status => $value) {
208
+                if (isset($wp_post_statuses[$status]) && false === $wp_post_statuses[$status]->show_in_admin_all_list) {
209
+                    unset($post_statuses[$status]);
210 210
                 }
211 211
             }
212 212
 
213
-            $vars['post_status'] = array_keys( $post_statuses );
213
+            $vars['post_status'] = array_keys($post_statuses);
214 214
         }
215 215
         
216
-        if ( isset( $vars['orderby'] ) ) {
217
-            if ( 'amount' == $vars['orderby'] ) {
216
+        if (isset($vars['orderby'])) {
217
+            if ('amount' == $vars['orderby']) {
218 218
                 $vars = array_merge(
219 219
                     $vars,
220 220
                     array(
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
                         'orderby'  => 'meta_value_num'
223 223
                     )
224 224
                 );
225
-            } else if ( 'customer' == $vars['orderby'] ) {
225
+            } else if ('customer' == $vars['orderby']) {
226 226
                 $vars = array_merge(
227 227
                     $vars,
228 228
                     array(
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
                         'orderby'  => 'meta_value'
231 231
                     )
232 232
                 );
233
-            } else if ( 'number' == $vars['orderby'] ) {
233
+            } else if ('number' == $vars['orderby']) {
234 234
                 $vars = array_merge(
235 235
                     $vars,
236 236
                     array(
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
                         'orderby'  => 'meta_value'
239 239
                     )
240 240
                 );
241
-            } else if ( 'payment_date' == $vars['orderby'] ) {
241
+            } else if ('payment_date' == $vars['orderby']) {
242 242
                 $vars = array_merge(
243 243
                     $vars,
244 244
                     array(
@@ -248,9 +248,9 @@  discard block
 block discarded – undo
248 248
                 );
249 249
             }
250 250
         }
251
-    } else if ( 'wpi_item' == $typenow ) {
251
+    } else if ('wpi_item' == $typenow) {
252 252
         // Check if 'orderby' is set to "price"
253
-        if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
253
+        if (isset($vars['orderby']) && 'price' == $vars['orderby']) {
254 254
             $vars = array_merge(
255 255
                 $vars,
256 256
                 array(
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
         }
262 262
 
263 263
         // Check if "orderby" is set to "vat_rule"
264
-        if ( isset( $vars['orderby'] ) && 'vat_rule' == $vars['orderby'] ) {
264
+        if (isset($vars['orderby']) && 'vat_rule' == $vars['orderby']) {
265 265
             $vars = array_merge(
266 266
                 $vars,
267 267
                 array(
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
         }
273 273
 
274 274
         // Check if "orderby" is set to "vat_class"
275
-        if ( isset( $vars['orderby'] ) && 'vat_class' == $vars['orderby'] ) {
275
+        if (isset($vars['orderby']) && 'vat_class' == $vars['orderby']) {
276 276
             $vars = array_merge(
277 277
                 $vars,
278 278
                 array(
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         }
284 284
         
285 285
         // Check if "orderby" is set to "type"
286
-        if ( isset( $vars['orderby'] ) && 'type' == $vars['orderby'] ) {
286
+        if (isset($vars['orderby']) && 'type' == $vars['orderby']) {
287 287
             $vars = array_merge(
288 288
                 $vars,
289 289
                 array(
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
         }
295 295
         
296 296
         // Check if "orderby" is set to "recurring"
297
-        if ( isset( $vars['orderby'] ) && 'recurring' == $vars['orderby'] ) {
297
+        if (isset($vars['orderby']) && 'recurring' == $vars['orderby']) {
298 298
             $vars = array_merge(
299 299
                 $vars,
300 300
                 array(
@@ -304,104 +304,104 @@  discard block
 block discarded – undo
304 304
             );
305 305
         }
306 306
 
307
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
307
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
308 308
         // Filter vat rule type
309
-        if ( isset( $_GET['vat_rule'] ) && $_GET['vat_rule'] !== '' ) {
309
+        if (isset($_GET['vat_rule']) && $_GET['vat_rule'] !== '') {
310 310
             $meta_query[] = array(
311 311
                     'key'   => '_wpinv_vat_rule',
312
-                    'value' => sanitize_text_field( $_GET['vat_rule'] ),
312
+                    'value' => sanitize_text_field($_GET['vat_rule']),
313 313
                     'compare' => '='
314 314
                 );
315 315
         }
316 316
         
317 317
         // Filter vat class
318
-        if ( isset( $_GET['vat_class'] ) && $_GET['vat_class'] !== '' ) {
318
+        if (isset($_GET['vat_class']) && $_GET['vat_class'] !== '') {
319 319
             $meta_query[] = array(
320 320
                     'key'   => '_wpinv_vat_class',
321
-                    'value' => sanitize_text_field( $_GET['vat_class'] ),
321
+                    'value' => sanitize_text_field($_GET['vat_class']),
322 322
                     'compare' => '='
323 323
                 );
324 324
         }
325 325
         
326 326
         // Filter item type
327
-        if ( isset( $_GET['type'] ) && $_GET['type'] !== '' ) {
327
+        if (isset($_GET['type']) && $_GET['type'] !== '') {
328 328
             $meta_query[] = array(
329 329
                     'key'   => '_wpinv_type',
330
-                    'value' => sanitize_text_field( $_GET['type'] ),
330
+                    'value' => sanitize_text_field($_GET['type']),
331 331
                     'compare' => '='
332 332
                 );
333 333
         }
334 334
         
335
-        if ( !empty( $meta_query ) ) {
335
+        if (!empty($meta_query)) {
336 336
             $vars['meta_query'] = $meta_query;
337 337
         }
338
-    } else if ( 'wpi_discount' == $typenow ) {
339
-        $meta_query = !empty( $vars['meta_query'] ) ? $vars['meta_query'] : array();
338
+    } else if ('wpi_discount' == $typenow) {
339
+        $meta_query = !empty($vars['meta_query']) ? $vars['meta_query'] : array();
340 340
         // Filter vat rule type
341
-        if ( isset( $_GET['discount_type'] ) && $_GET['discount_type'] !== '' ) {
341
+        if (isset($_GET['discount_type']) && $_GET['discount_type'] !== '') {
342 342
             $meta_query[] = array(
343 343
                     'key'   => '_wpi_discount_type',
344
-                    'value' => sanitize_text_field( $_GET['discount_type'] ),
344
+                    'value' => sanitize_text_field($_GET['discount_type']),
345 345
                     'compare' => '='
346 346
                 );
347 347
         }
348 348
         
349
-        if ( !empty( $meta_query ) ) {
349
+        if (!empty($meta_query)) {
350 350
             $vars['meta_query'] = $meta_query;
351 351
         }
352 352
     }
353 353
 
354 354
     return $vars;
355 355
 }
356
-add_filter( 'request', 'wpinv_request' );
356
+add_filter('request', 'wpinv_request');
357 357
 
358
-function wpinv_item_type_class( $classes, $class, $post_id ) {
358
+function wpinv_item_type_class($classes, $class, $post_id) {
359 359
     global $pagenow, $typenow;
360 360
 
361
-    if ( $pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type( $post_id ) == $typenow ) {
362
-        if ( $type = get_post_meta( $post_id, '_wpinv_type', true ) ) {
363
-            $classes[] = 'wpi-type-' . sanitize_html_class( $type );
361
+    if ($pagenow == 'edit.php' && $typenow == 'wpi_item' && get_post_type($post_id) == $typenow) {
362
+        if ($type = get_post_meta($post_id, '_wpinv_type', true)) {
363
+            $classes[] = 'wpi-type-' . sanitize_html_class($type);
364 364
         }
365 365
         
366
-        if ( !wpinv_item_is_editable( $post_id ) ) {
366
+        if (!wpinv_item_is_editable($post_id)) {
367 367
             $classes[] = 'wpi-editable-n';
368 368
         }
369 369
     }
370 370
     return $classes;
371 371
 }
372
-add_filter( 'post_class', 'wpinv_item_type_class', 10, 3 );
372
+add_filter('post_class', 'wpinv_item_type_class', 10, 3);
373 373
 
374 374
 function wpinv_check_quick_edit() {
375 375
     global $pagenow, $current_screen, $wpinv_item_screen;
376 376
 
377
-    if ( $pagenow == 'edit.php' && !empty( $current_screen->post_type ) ) {
378
-        if ( empty( $wpinv_item_screen ) ) {
379
-            if ( $current_screen->post_type == 'wpi_item' ) {
377
+    if ($pagenow == 'edit.php' && !empty($current_screen->post_type)) {
378
+        if (empty($wpinv_item_screen)) {
379
+            if ($current_screen->post_type == 'wpi_item') {
380 380
                 $wpinv_item_screen = 'y';
381 381
             } else {
382 382
                 $wpinv_item_screen = 'n';
383 383
             }
384 384
         }
385 385
 
386
-        if ( $wpinv_item_screen == 'y' && $pagenow == 'edit.php' ) {
387
-            add_filter( 'post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
388
-            add_filter( 'page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2 );
386
+        if ($wpinv_item_screen == 'y' && $pagenow == 'edit.php') {
387
+            add_filter('post_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
388
+            add_filter('page_row_actions', 'wpinv_item_disable_quick_edit', 10, 2);
389 389
         }
390 390
     }
391 391
 }
392
-add_action( 'admin_head', 'wpinv_check_quick_edit', 10 );
392
+add_action('admin_head', 'wpinv_check_quick_edit', 10);
393 393
 
394
-function wpinv_item_disable_quick_edit( $actions = array(), $row = null ) {
395
-    if ( isset( $actions['inline hide-if-no-js'] ) ) {
396
-        unset( $actions['inline hide-if-no-js'] );
394
+function wpinv_item_disable_quick_edit($actions = array(), $row = null) {
395
+    if (isset($actions['inline hide-if-no-js'])) {
396
+        unset($actions['inline hide-if-no-js']);
397 397
     }
398 398
     
399
-    if ( !empty( $row->post_type ) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable( $row ) ) {
400
-        if ( isset( $actions['trash'] ) ) {
401
-            unset( $actions['trash'] );
399
+    if (!empty($row->post_type) && $row->post_type == 'wpi_item' && !wpinv_item_is_editable($row)) {
400
+        if (isset($actions['trash'])) {
401
+            unset($actions['trash']);
402 402
         }
403
-        if ( isset( $actions['delete'] ) ) {
404
-            unset( $actions['delete'] );
403
+        if (isset($actions['delete'])) {
404
+            unset($actions['delete']);
405 405
         }
406 406
     }
407 407
 
@@ -418,19 +418,19 @@  discard block
 block discarded – undo
418 418
  * @param int $post_parent (default: 0) Parent for the new page
419 419
  * @return int page ID
420 420
  */
421
-function wpinv_create_page( $slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0 ) {
421
+function wpinv_create_page($slug, $option = '', $page_title = '', $page_content = '', $post_parent = 0) {
422 422
     global $wpdb;
423 423
 
424
-    $option_value = wpinv_get_option( $option );
424
+    $option_value = wpinv_get_option($option);
425 425
 
426
-    if ( $option_value > 0 && ( $page_object = get_post( $option_value ) ) ) {
427
-        if ( 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ) ) ) {
426
+    if ($option_value > 0 && ($page_object = get_post($option_value))) {
427
+        if ('page' === $page_object->post_type && !in_array($page_object->post_status, array('pending', 'trash', 'future', 'auto-draft'))) {
428 428
             // Valid page is already in place
429 429
             return $page_object->ID;
430 430
         }
431 431
     }
432 432
 
433
-    if(!empty($post_parent)){
433
+    if (!empty($post_parent)) {
434 434
         $page = get_page_by_path($post_parent);
435 435
         if ($page) {
436 436
             $post_parent = $page->ID;
@@ -439,40 +439,40 @@  discard block
 block discarded – undo
439 439
         }
440 440
     }
441 441
 
442
-    if ( strlen( $page_content ) > 0 ) {
442
+    if (strlen($page_content) > 0) {
443 443
         // Search for an existing page with the specified page content (typically a shortcode)
444
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
444
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
445 445
     } else {
446 446
         // Search for an existing page with the specified page slug
447
-        $valid_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug ) );
447
+        $valid_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' )  AND post_name = %s LIMIT 1;", $slug));
448 448
     }
449 449
 
450
-    $valid_page_found = apply_filters( 'wpinv_create_page_id', $valid_page_found, $slug, $page_content );
450
+    $valid_page_found = apply_filters('wpinv_create_page_id', $valid_page_found, $slug, $page_content);
451 451
 
452
-    if ( $valid_page_found ) {
453
-        if ( $option ) {
454
-            wpinv_update_option( $option, $valid_page_found );
452
+    if ($valid_page_found) {
453
+        if ($option) {
454
+            wpinv_update_option($option, $valid_page_found);
455 455
         }
456 456
         return $valid_page_found;
457 457
     }
458 458
 
459 459
     // Search for a matching valid trashed page
460
-    if ( strlen( $page_content ) > 0 ) {
460
+    if (strlen($page_content) > 0) {
461 461
         // Search for an existing page with the specified page content (typically a shortcode)
462
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%" ) );
462
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_content LIKE %s LIMIT 1;", "%{$page_content}%"));
463 463
     } else {
464 464
         // Search for an existing page with the specified page slug
465
-        $trashed_page_found = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug ) );
465
+        $trashed_page_found = $wpdb->get_var($wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status = 'trash' AND post_name = %s LIMIT 1;", $slug));
466 466
     }
467 467
 
468
-    if ( $trashed_page_found ) {
468
+    if ($trashed_page_found) {
469 469
         $page_id   = $trashed_page_found;
470 470
         $page_data = array(
471 471
             'ID'             => $page_id,
472 472
             'post_status'    => 'publish',
473 473
             'post_parent'    => $post_parent,
474 474
         );
475
-        wp_update_post( $page_data );
475
+        wp_update_post($page_data);
476 476
     } else {
477 477
         $page_data = array(
478 478
             'post_status'    => 'publish',
@@ -484,11 +484,11 @@  discard block
 block discarded – undo
484 484
             'post_parent'    => $post_parent,
485 485
             'comment_status' => 'closed',
486 486
         );
487
-        $page_id = wp_insert_post( $page_data );
487
+        $page_id = wp_insert_post($page_data);
488 488
     }
489 489
 
490
-    if ( $option ) {
491
-        wpinv_update_option( $option, (int)$page_id );
490
+    if ($option) {
491
+        wpinv_update_option($option, (int)$page_id);
492 492
     }
493 493
 
494 494
     return $page_id;
Please login to merge, or discard this patch.
includes/libraries/wpinv-euvat/class-wpinv-euvat.php 1 patch
Spacing   +712 added lines, -712 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,138 +17,138 @@  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
-        $vars['checkoutNonce'] = wp_create_nonce( 'wpinv_checkout_nonce' );
130
+        $vars['checkoutNonce'] = wp_create_nonce('wpinv_checkout_nonce');
131 131
         $vars['baseCountry'] = wpinv_get_default_country();
132
-        $vars['disableVATSameCountry'] = ( self::same_country_rule() == 'no' ? true : false );
133
-        $vars['disableVATSimpleCheck'] = wpinv_get_option( 'vat_offline_check' ) ? true : false;
132
+        $vars['disableVATSameCountry'] = (self::same_country_rule() == 'no' ? true : false);
133
+        $vars['disableVATSimpleCheck'] = wpinv_get_option('vat_offline_check') ? true : false;
134 134
 
135
-        wp_enqueue_script( 'wpinv-vat-validation-script' );
136
-        wp_enqueue_script( 'wpinv-vat-script' );
137
-        wp_localize_script( 'wpinv-vat-script', 'WPInv_VAT_Vars', $vars );
135
+        wp_enqueue_script('wpinv-vat-validation-script');
136
+        wp_enqueue_script('wpinv-vat-script');
137
+        wp_localize_script('wpinv-vat-script', 'WPInv_VAT_Vars', $vars);
138 138
     }
139 139
 
140 140
     public static function enqueue_admin_scripts() {
141
-        if( isset( $_GET['page'] ) && 'wpinv-settings' == $_GET['page'] ) {
141
+        if (isset($_GET['page']) && 'wpinv-settings' == $_GET['page']) {
142 142
             self::load_vat_scripts();
143 143
         }
144 144
     }
145 145
     
146
-    public static function section_vat_settings( $sections ) {
147
-        if ( !empty( $sections ) ) {
148
-            $sections['vat'] = __( 'EU VAT Settings', 'invoicing' );
146
+    public static function section_vat_settings($sections) {
147
+        if (!empty($sections)) {
148
+            $sections['vat'] = __('EU VAT Settings', 'invoicing');
149 149
             
150
-            if ( self::allow_vat_classes() ) {
151
-                $sections['vat_rates'] = __( 'EU VAT Rates', 'invoicing' );
150
+            if (self::allow_vat_classes()) {
151
+                $sections['vat_rates'] = __('EU VAT Rates', 'invoicing');
152 152
             }
153 153
         }
154 154
         return $sections;
@@ -157,51 +157,51 @@  discard block
 block discarded – undo
157 157
     public static function vat_rates_settings() {
158 158
         $vat_classes = self::get_rate_classes();
159 159
         $vat_rates = array();
160
-        $vat_class = isset( $_REQUEST['wpi_sub'] ) && $_REQUEST['wpi_sub'] !== '' && isset( $vat_classes[$_REQUEST['wpi_sub']] )? sanitize_text_field( $_REQUEST['wpi_sub'] ) : '_new';
161
-        $current_url = remove_query_arg( 'wpi_sub' );
160
+        $vat_class = isset($_REQUEST['wpi_sub']) && $_REQUEST['wpi_sub'] !== '' && isset($vat_classes[$_REQUEST['wpi_sub']]) ? sanitize_text_field($_REQUEST['wpi_sub']) : '_new';
161
+        $current_url = remove_query_arg('wpi_sub');
162 162
         
163 163
         $vat_rates['vat_rates_header'] = array(
164 164
             'id' => 'vat_rates_header',
165
-            'name' => '<h3>' . __( 'Manage VAT Rates', 'invoicing' ) . '</h3>',
165
+            'name' => '<h3>' . __('Manage VAT Rates', 'invoicing') . '</h3>',
166 166
             'desc' => '',
167 167
             'type' => 'header',
168 168
             'size' => 'regular'
169 169
         );
170 170
         $vat_rates['vat_rates_class'] = array(
171 171
             'id'          => 'vat_rates_class',
172
-            'name'        => __( 'Edit VAT Rates', 'invoicing' ),
173
-            'desc'        => __( 'The standard rate will apply where no explicit rate is provided.', 'invoicing' ),
172
+            'name'        => __('Edit VAT Rates', 'invoicing'),
173
+            'desc'        => __('The standard rate will apply where no explicit rate is provided.', 'invoicing'),
174 174
             'type'        => 'select',
175
-            'options'     => array_merge( $vat_classes, array( '_new' => __( 'Add New Rate Class', 'invoicing' ) ) ),
176
-            'placeholder' => __( 'Select a VAT Rate', 'invoicing' ),
175
+            'options'     => array_merge($vat_classes, array('_new' => __('Add New Rate Class', 'invoicing'))),
176
+            'placeholder' => __('Select a VAT Rate', 'invoicing'),
177 177
             'selected'    => $vat_class,
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,21 +283,21 @@  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
             );
297 297
 
298 298
             $vat_settings['vat_checkout_title'] = array(
299 299
                 'id' => 'vat_checkout_title',
300
-                'name' => '<h3>' . __( 'Checkout Fields', 'invoicing' ) . '</h3>',
300
+                'name' => '<h3>' . __('Checkout Fields', 'invoicing') . '</h3>',
301 301
                 'desc' => '',
302 302
                 'type' => 'header',
303 303
                 'size' => 'regular'
@@ -305,14 +305,14 @@  discard block
 block discarded – undo
305 305
 
306 306
             $vat_settings['vat_disable_fields'] = array(
307 307
                 'id' => 'vat_disable_fields',
308
-                'name' => __( 'Disable VAT Fields', 'invoicing' ),
309
-                '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>',
308
+                'name' => __('Disable VAT Fields', 'invoicing'),
309
+                '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>',
310 310
                 'type' => 'checkbox'
311 311
             );
312 312
 
313 313
             $vat_settings['vat_ip_lookup'] = array(
314 314
                 'id'   => 'vat_ip_lookup',
315
-                'name' => __( 'IP Country Look-up', 'invoicing' ),
315
+                'name' => __('IP Country Look-up', 'invoicing'),
316 316
                 'type' => 'vat_ip_lookup',
317 317
                 'size' => 'regular',
318 318
                 'std' => 'default'
@@ -320,21 +320,21 @@  discard block
 block discarded – undo
320 320
 
321 321
             $vat_settings['hide_ip_address'] = array(
322 322
                 'id' => 'hide_ip_address',
323
-                'name' => __( 'Hide IP Info at Checkout', 'invoicing' ),
324
-                'desc' => __( 'Hide the user IP info at checkout.', 'invoicing' ),
323
+                'name' => __('Hide IP Info at Checkout', 'invoicing'),
324
+                'desc' => __('Hide the user IP info at checkout.', 'invoicing'),
325 325
                 'type' => 'checkbox'
326 326
             );
327 327
 
328 328
             $vat_settings['vat_ip_country_default'] = array(
329 329
                 'id' => 'vat_ip_country_default',
330
-                'name' => __( 'Enable IP Country as Default', 'invoicing' ),
331
-                'desc' => __( 'Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing' ),
330
+                'name' => __('Enable IP Country as Default', 'invoicing'),
331
+                'desc' => __('Show the country of the users IP as the default country, otherwise the site default country will be used.', 'invoicing'),
332 332
                 'type' => 'checkbox'
333 333
             );
334 334
 
335 335
             $vat_settings['vies_validation_title'] = array(
336 336
                 'id' => 'vies_validation_title',
337
-                'name' => '<h3>' . __( 'VIES Validation', 'invoicing' ) . '</h3>',
337
+                'name' => '<h3>' . __('VIES Validation', 'invoicing') . '</h3>',
338 338
                 'desc' => '',
339 339
                 'type' => 'header',
340 340
                 'size' => 'regular'
@@ -342,37 +342,37 @@  discard block
 block discarded – undo
342 342
 
343 343
             $vat_settings['vat_vies_check'] = array(
344 344
                 'id' => 'vat_vies_check',
345
-                'name' => __( 'Disable VIES VAT ID Check', 'invoicing' ),
346
-                '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>' ),
345
+                'name' => __('Disable VIES VAT ID Check', 'invoicing'),
346
+                '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 347
                 'type' => 'checkbox'
348 348
             );
349 349
 
350 350
             $vat_settings['vat_disable_company_name_check'] = array(
351 351
                 'id' => 'vat_disable_company_name_check',
352
-                'name' => __( 'Disable VIES Name Check', 'invoicing' ),
353
-                '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>' ),
352
+                'name' => __('Disable VIES Name Check', 'invoicing'),
353
+                '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 354
                 'type' => 'checkbox'
355 355
             );
356 356
 
357 357
             $vat_settings['vat_offline_check'] = array(
358 358
                 'id' => 'vat_offline_check',
359
-                'name' => __( 'Disable Basic Checks', 'invoicing' ),
360
-                'desc' => __( 'Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing' ),
359
+                'name' => __('Disable Basic Checks', 'invoicing'),
360
+                'desc' => __('Disable basic JS checks for correct format of VAT number. (Not Recommended)', 'invoicing'),
361 361
                 'type' => 'checkbox'
362 362
             );
363 363
             
364 364
 
365 365
             $settings['vat'] = $vat_settings;
366 366
             
367
-            if ( self::allow_vat_classes() ) {
367
+            if (self::allow_vat_classes()) {
368 368
                 $settings['vat_rates'] = self::vat_rates_settings();
369 369
             }
370 370
             
371 371
             $eu_fallback_rate = array(
372 372
                 'id'   => 'eu_fallback_rate',
373
-                'name' => '<h3>' . __( 'VAT rate for EU member states', 'invoicing' ) . '</h3>',
373
+                'name' => '<h3>' . __('VAT rate for EU member states', 'invoicing') . '</h3>',
374 374
                 'type' => 'eu_fallback_rate',
375
-                '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' ),
375
+                'desc' => __('Enter the VAT rate to be charged for EU member states. You can edit the rates for each member state when a country rate has been set up by pressing this button.', 'invoicing'),
376 376
                 'std'  => '20',
377 377
                 'size' => 'small'
378 378
             );
@@ -388,11 +388,11 @@  discard block
 block discarded – undo
388 388
         $database_url       = 'http' . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] === 'on' ? 's' : '') . '://geolite.maxmind.com/download/geoip/database/';
389 389
         $destination_dir    = $upload_dir['basedir'] . '/invoicing';
390 390
         
391
-        if ( !is_dir( $destination_dir ) ) { 
392
-            mkdir( $destination_dir );
391
+        if (!is_dir($destination_dir)) { 
392
+            mkdir($destination_dir);
393 393
         }
394 394
         
395
-        $database_files     = array(
395
+        $database_files = array(
396 396
             'country'   => array(
397 397
                 'source'        => $database_url . 'GeoLite2-Country.mmdb.gz',
398 398
                 'destination'   => $destination_dir . '/GeoLite2-Country.mmdb',
@@ -403,57 +403,57 @@  discard block
 block discarded – undo
403 403
             )
404 404
         );
405 405
 
406
-        foreach( $database_files as $database => $files ) {
407
-            $result = self::geoip2_download_file( $files['source'], $files['destination'] );
406
+        foreach ($database_files as $database => $files) {
407
+            $result = self::geoip2_download_file($files['source'], $files['destination']);
408 408
             
409
-            if ( empty( $result['success'] ) ) {
409
+            if (empty($result['success'])) {
410 410
                 echo $result['message'];
411 411
                 exit;
412 412
             }
413 413
             
414
-            wpinv_update_option( 'wpinv_geoip2_date_updated', current_time( 'timestamp' ) );
415
-            echo sprintf(__( 'GeoIP2 %s database updated successfully.', 'invoicing' ), $database ) . ' ';
414
+            wpinv_update_option('wpinv_geoip2_date_updated', current_time('timestamp'));
415
+            echo sprintf(__('GeoIP2 %s database updated successfully.', 'invoicing'), $database) . ' ';
416 416
         }
417 417
         
418 418
         exit;
419 419
     }
420 420
     
421
-    public static function geoip2_download_file( $source_url, $destination_file ) {
421
+    public static function geoip2_download_file($source_url, $destination_file) {
422 422
         $success    = false;
423 423
         $message    = '';
424 424
         
425
-        if ( !function_exists( 'download_url' ) ) {
426
-            require_once( ABSPATH . 'wp-admin/includes/file.php' );
425
+        if (!function_exists('download_url')) {
426
+            require_once(ABSPATH . 'wp-admin/includes/file.php');
427 427
         }
428 428
 
429
-        $temp_file  = download_url( $source_url );
429
+        $temp_file = download_url($source_url);
430 430
         
431
-        if ( is_wp_error( $temp_file ) ) {
432
-            $message = sprintf( __( 'Error while downloading GeoIp2 database( %s ): %s', 'invoicing' ), $source_url, $temp_file->get_error_message() );
431
+        if (is_wp_error($temp_file)) {
432
+            $message = sprintf(__('Error while downloading GeoIp2 database( %s ): %s', 'invoicing'), $source_url, $temp_file->get_error_message());
433 433
         } else {
434
-            $handle = gzopen( $temp_file, 'rb' );
434
+            $handle = gzopen($temp_file, 'rb');
435 435
             
436
-            if ( $handle ) {
437
-                $fopen  = fopen( $destination_file, 'wb' );
438
-                if ( $fopen ) {
439
-                    while ( ( $data = gzread( $handle, 4096 ) ) != false ) {
440
-                        fwrite( $fopen, $data );
436
+            if ($handle) {
437
+                $fopen = fopen($destination_file, 'wb');
438
+                if ($fopen) {
439
+                    while (($data = gzread($handle, 4096)) != false) {
440
+                        fwrite($fopen, $data);
441 441
                     }
442 442
 
443
-                    gzclose( $handle );
444
-                    fclose( $fopen );
443
+                    gzclose($handle);
444
+                    fclose($fopen);
445 445
                         
446 446
                     $success = true;
447 447
                 } else {
448
-                    gzclose( $handle );
449
-                    $message = sprintf( __( 'Error could not open destination GeoIp2 database file for writing: %s', 'invoicing' ), $destination_file );
448
+                    gzclose($handle);
449
+                    $message = sprintf(__('Error could not open destination GeoIp2 database file for writing: %s', 'invoicing'), $destination_file);
450 450
                 }
451 451
             } else {
452
-                $message = sprintf( __( 'Error could not open GeoIp2 database file for reading: %s', 'invoicing' ), $temp_file );
452
+                $message = sprintf(__('Error could not open GeoIp2 database file for reading: %s', 'invoicing'), $temp_file);
453 453
             }
454 454
             
455
-            if ( file_exists( $temp_file ) ) {
456
-                unlink( $temp_file );
455
+            if (file_exists($temp_file)) {
456
+                unlink($temp_file);
457 457
             }
458 458
         }
459 459
         
@@ -465,11 +465,11 @@  discard block
 block discarded – undo
465 465
     }
466 466
     
467 467
     public static function load_geoip2() {
468
-        if ( defined( 'WPINV_GEOIP2_LODDED' ) ) {
468
+        if (defined('WPINV_GEOIP2_LODDED')) {
469 469
             return;
470 470
         }
471 471
         
472
-        if ( !class_exists( '\MaxMind\Db\Reader' ) ) {
472
+        if (!class_exists('\MaxMind\Db\Reader')) {
473 473
             $maxmind_db_files = array(
474 474
                 'Reader/Decoder.php',
475 475
                 'Reader/InvalidDatabaseException.php',
@@ -478,12 +478,12 @@  discard block
 block discarded – undo
478 478
                 'Reader.php',
479 479
             );
480 480
             
481
-            foreach ( $maxmind_db_files as $key => $file ) {
482
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file );
481
+            foreach ($maxmind_db_files as $key => $file) {
482
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/MaxMind/Db/' . $file);
483 483
             }
484 484
         }
485 485
         
486
-        if ( !class_exists( '\GeoIp2\Database\Reader' ) ) {        
486
+        if (!class_exists('\GeoIp2\Database\Reader')) {        
487 487
             $geoip2_files = array(
488 488
                 'ProviderInterface.php',
489 489
                 'Compat/JsonSerializable.php',
@@ -517,23 +517,23 @@  discard block
 block discarded – undo
517 517
                 'WebService/Client.php',
518 518
             );
519 519
             
520
-            foreach ( $geoip2_files as $key => $file ) {
521
-                require_once( WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file );
520
+            foreach ($geoip2_files as $key => $file) {
521
+                require_once(WPINV_PLUGIN_DIR . 'includes/libraries/GeoIp2/' . $file);
522 522
             }
523 523
         }
524 524
 
525
-        define( 'WPINV_GEOIP2_LODDED', true );
525
+        define('WPINV_GEOIP2_LODDED', true);
526 526
     }
527 527
 
528 528
     public static function geoip2_country_dbfile() {
529 529
         $upload_dir = wp_upload_dir();
530 530
 
531
-        if ( !isset( $upload_dir['basedir'] ) ) {
531
+        if (!isset($upload_dir['basedir'])) {
532 532
             return false;
533 533
         }
534 534
 
535 535
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-Country.mmdb';
536
-        if ( !file_exists( $filename ) ) {
536
+        if (!file_exists($filename)) {
537 537
             return false;
538 538
         }
539 539
         
@@ -543,12 +543,12 @@  discard block
 block discarded – undo
543 543
     public static function geoip2_city_dbfile() {
544 544
         $upload_dir = wp_upload_dir();
545 545
 
546
-        if ( !isset( $upload_dir['basedir'] ) ) {
546
+        if (!isset($upload_dir['basedir'])) {
547 547
             return false;
548 548
         }
549 549
 
550 550
         $filename = $upload_dir['basedir'] . '/invoicing/GeoLite2-City.mmdb';
551
-        if ( !file_exists( $filename ) ) {
551
+        if (!file_exists($filename)) {
552 552
             return false;
553 553
         }
554 554
         
@@ -559,10 +559,10 @@  discard block
 block discarded – undo
559 559
         try {
560 560
             self::load_geoip2();
561 561
 
562
-            if ( $filename = self::geoip2_country_dbfile() ) {
563
-                return new \GeoIp2\Database\Reader( $filename );
562
+            if ($filename = self::geoip2_country_dbfile()) {
563
+                return new \GeoIp2\Database\Reader($filename);
564 564
             }
565
-        } catch( Exception $e ) {
565
+        } catch (Exception $e) {
566 566
             return false;
567 567
         }
568 568
         
@@ -573,173 +573,173 @@  discard block
 block discarded – undo
573 573
         try {
574 574
             self::load_geoip2();
575 575
 
576
-            if ( $filename = self::geoip2_city_dbfile() ) {
577
-                return new \GeoIp2\Database\Reader( $filename );
576
+            if ($filename = self::geoip2_city_dbfile()) {
577
+                return new \GeoIp2\Database\Reader($filename);
578 578
             }
579
-        } catch( Exception $e ) {
579
+        } catch (Exception $e) {
580 580
             return false;
581 581
         }
582 582
         
583 583
         return false;
584 584
     }
585 585
 
586
-    public static function geoip2_country_record( $ip_address ) {
586
+    public static function geoip2_country_record($ip_address) {
587 587
         try {
588 588
             $reader = self::geoip2_country_reader();
589 589
 
590
-            if ( $reader ) {
591
-                $record = $reader->country( $ip_address );
590
+            if ($reader) {
591
+                $record = $reader->country($ip_address);
592 592
                 
593
-                if ( !empty( $record->country->isoCode ) ) {
593
+                if (!empty($record->country->isoCode)) {
594 594
                     return $record;
595 595
                 }
596 596
             }
597
-        } catch(\InvalidArgumentException $e) {
598
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
597
+        } catch (\InvalidArgumentException $e) {
598
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
599 599
             
600 600
             return false;
601
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
602
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
601
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
602
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
603 603
             
604 604
             return false;
605
-        } catch( Exception $e ) {
605
+        } catch (Exception $e) {
606 606
             return false;
607 607
         }
608 608
         
609 609
         return false;
610 610
     }
611 611
 
612
-    public static function geoip2_city_record( $ip_address ) {
612
+    public static function geoip2_city_record($ip_address) {
613 613
         try {
614 614
             $reader = self::geoip2_city_reader();
615 615
 
616
-            if ( $reader ) {
617
-                $record = $reader->city( $ip_address );
616
+            if ($reader) {
617
+                $record = $reader->city($ip_address);
618 618
                 
619
-                if ( !empty( $record->country->isoCode ) ) {
619
+                if (!empty($record->country->isoCode)) {
620 620
                     return $record;
621 621
                 }
622 622
             }
623
-        } catch(\InvalidArgumentException $e) {
624
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
623
+        } catch (\InvalidArgumentException $e) {
624
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
625 625
             
626 626
             return false;
627
-        } catch(\GeoIp2\Exception\AddressNotFoundException $e) {
628
-            wpinv_error_log( $e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )' );
627
+        } catch (\GeoIp2\Exception\AddressNotFoundException $e) {
628
+            wpinv_error_log($e->getMessage(), 'GeoIp2 Lookup( ' . $ip_address . ' )');
629 629
             
630 630
             return false;
631
-        } catch( Exception $e ) {
631
+        } catch (Exception $e) {
632 632
             return false;
633 633
         }
634 634
         
635 635
         return false;
636 636
     }
637 637
 
638
-    public static function geoip2_country_code( $ip_address ) {
639
-        $record = self::geoip2_country_record( $ip_address );
640
-        return !empty( $record->country->isoCode ) ? $record->country->isoCode : wpinv_get_default_country();
638
+    public static function geoip2_country_code($ip_address) {
639
+        $record = self::geoip2_country_record($ip_address);
640
+        return !empty($record->country->isoCode) ? $record->country->isoCode : wpinv_get_default_country();
641 641
     }
642 642
 
643 643
     // Find country by IP address.
644
-    public static function get_country_by_ip( $ip = '' ) {
644
+    public static function get_country_by_ip($ip = '') {
645 645
         global $wpinv_ip_address_country;
646 646
         
647
-        if ( !empty( $wpinv_ip_address_country ) ) {
647
+        if (!empty($wpinv_ip_address_country)) {
648 648
             return $wpinv_ip_address_country;
649 649
         }
650 650
         
651
-        if ( empty( $ip ) ) {
651
+        if (empty($ip)) {
652 652
             $ip = wpinv_get_ip();
653 653
         }
654 654
 
655
-        $ip_country_service = wpinv_get_option( 'vat_ip_lookup' );
656
-        $is_default         = empty( $ip_country_service ) || $ip_country_service === 'default' ? true : false;
655
+        $ip_country_service = wpinv_get_option('vat_ip_lookup');
656
+        $is_default         = empty($ip_country_service) || $ip_country_service === 'default' ? true : false;
657 657
 
658
-        if ( !empty( $ip ) && $ip !== '127.0.0.1' ) { // For 127.0.0.1(localhost) use default country.
659
-            if ( function_exists( 'geoip_country_code_by_name') && ( $ip_country_service === 'geoip' || $is_default ) ) {
658
+        if (!empty($ip) && $ip !== '127.0.0.1') { // For 127.0.0.1(localhost) use default country.
659
+            if (function_exists('geoip_country_code_by_name') && ($ip_country_service === 'geoip' || $is_default)) {
660 660
                 try {
661
-                    $wpinv_ip_address_country = geoip_country_code_by_name( $ip );
662
-                } catch( Exception $e ) {
663
-                    wpinv_error_log( $e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )' );
661
+                    $wpinv_ip_address_country = geoip_country_code_by_name($ip);
662
+                } catch (Exception $e) {
663
+                    wpinv_error_log($e->getMessage(), 'GeoIP Lookup( ' . $ip . ' )');
664 664
                 }
665
-            } else if ( self::geoip2_country_dbfile() && ( $ip_country_service === 'geoip2' || $is_default ) ) {
666
-                $wpinv_ip_address_country = self::geoip2_country_code( $ip );
667
-            } else if ( function_exists( 'simplexml_load_file' ) && ( $ip_country_service === 'geoplugin' || $is_default ) ) {
668
-                $load_xml = simplexml_load_file( 'http://www.geoplugin.net/xml.gp?ip=' . $ip );
665
+            } else if (self::geoip2_country_dbfile() && ($ip_country_service === 'geoip2' || $is_default)) {
666
+                $wpinv_ip_address_country = self::geoip2_country_code($ip);
667
+            } else if (function_exists('simplexml_load_file') && ($ip_country_service === 'geoplugin' || $is_default)) {
668
+                $load_xml = simplexml_load_file('http://www.geoplugin.net/xml.gp?ip=' . $ip);
669 669
                 
670
-                if ( !empty( $load_xml ) && !empty( $load_xml->geoplugin_countryCode ) ) {
670
+                if (!empty($load_xml) && !empty($load_xml->geoplugin_countryCode)) {
671 671
                     $wpinv_ip_address_country = (string)$load_xml->geoplugin_countryCode;
672 672
                 }
673 673
             }
674 674
         }
675 675
 
676
-        if ( empty( $wpinv_ip_address_country ) ) {
676
+        if (empty($wpinv_ip_address_country)) {
677 677
             $wpinv_ip_address_country = wpinv_get_default_country();
678 678
         }
679 679
 
680 680
         return $wpinv_ip_address_country;
681 681
     }
682 682
     
683
-    public static function sanitize_vat_settings( $input ) {
683
+    public static function sanitize_vat_settings($input) {
684 684
         global $wpinv_options;
685 685
         
686 686
         $valid      = false;
687 687
         $message    = '';
688 688
         
689
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
690
-            if ( empty( $wpinv_options['vat_offline_check'] ) ) {
691
-                $valid = self::offline_check( $input['vat_number'] );
689
+        if (!empty($wpinv_options['vat_vies_check'])) {
690
+            if (empty($wpinv_options['vat_offline_check'])) {
691
+                $valid = self::offline_check($input['vat_number']);
692 692
             } else {
693 693
                 $valid = true;
694 694
             }
695 695
             
696
-            $message = $valid ? '' : __( 'VAT number not validated', 'invoicing' );
696
+            $message = $valid ? '' : __('VAT number not validated', 'invoicing');
697 697
         } else {
698
-            $result = self::check_vat( $input['vat_number'] );
698
+            $result = self::check_vat($input['vat_number']);
699 699
             
700
-            if ( empty( $result['valid'] ) ) {
700
+            if (empty($result['valid'])) {
701 701
                 $valid      = false;
702 702
                 $message    = $result['message'];
703 703
             } else {
704
-                $valid      = ( isset( $result['company'] ) && ( $result['company'] == '---' || ( strcasecmp( trim( $result['company'] ), trim( $input['vat_company_name'] ) ) == 0 ) ) ) || !empty( $wpinv_options['vat_disable_company_name_check'] );
705
-                $message    = $valid ? '' : __( 'The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing' );
704
+                $valid      = (isset($result['company']) && ($result['company'] == '---' || (strcasecmp(trim($result['company']), trim($input['vat_company_name'])) == 0))) || !empty($wpinv_options['vat_disable_company_name_check']);
705
+                $message    = $valid ? '' : __('The company name associated with the VAT number provided is not the same as the company name provided.', 'invoicing');
706 706
             }
707 707
         }
708 708
 
709
-        if ( $message && self::is_vat_validated() != $valid ) {
710
-            add_settings_error( 'wpinv-notices', '', $message, ( $valid ? 'updated' : 'error' ) );
709
+        if ($message && self::is_vat_validated() != $valid) {
710
+            add_settings_error('wpinv-notices', '', $message, ($valid ? 'updated' : 'error'));
711 711
         }
712 712
 
713 713
         $input['vat_valid'] = $valid;
714 714
         return $input;
715 715
     }
716 716
     
717
-    public static function sanitize_vat_rates( $input ) {
718
-        if( !current_user_can( 'manage_options' ) ) {
719
-            add_settings_error( 'wpinv-notices', '', __( 'Your account does not have permission to add rate classes.', 'invoicing' ), 'error' );
717
+    public static function sanitize_vat_rates($input) {
718
+        if (!current_user_can('manage_options')) {
719
+            add_settings_error('wpinv-notices', '', __('Your account does not have permission to add rate classes.', 'invoicing'), 'error');
720 720
             return $input;
721 721
         }
722 722
         
723 723
         $vat_classes = self::get_rate_classes();
724
-        $vat_class = !empty( $_REQUEST['wpi_vat_class'] ) && isset( $vat_classes[$_REQUEST['wpi_vat_class']] )? sanitize_text_field( $_REQUEST['wpi_vat_class'] ) : '';
724
+        $vat_class = !empty($_REQUEST['wpi_vat_class']) && isset($vat_classes[$_REQUEST['wpi_vat_class']]) ? sanitize_text_field($_REQUEST['wpi_vat_class']) : '';
725 725
         
726
-        if ( empty( $vat_class ) ) {
727
-            add_settings_error( 'wpinv-notices', '', __( 'No valid VAT rates class contained in the request to save rates.', 'invoicing' ), 'error' );
726
+        if (empty($vat_class)) {
727
+            add_settings_error('wpinv-notices', '', __('No valid VAT rates class contained in the request to save rates.', 'invoicing'), 'error');
728 728
             
729 729
             return $input;
730 730
         }
731 731
 
732
-        $new_rates = ! empty( $_POST['vat_rates'] ) ? array_values( $_POST['vat_rates'] ) : array();
732
+        $new_rates = !empty($_POST['vat_rates']) ? array_values($_POST['vat_rates']) : array();
733 733
 
734
-        if ( $vat_class === '_standard' ) {
734
+        if ($vat_class === '_standard') {
735 735
             // Save the active rates in the invoice settings
736
-            update_option( 'wpinv_tax_rates', $new_rates );
736
+            update_option('wpinv_tax_rates', $new_rates);
737 737
         } else {
738 738
             // Get the existing set of rates
739 739
             $rates = self::get_non_standard_rates();
740 740
             $rates[$vat_class] = $new_rates;
741 741
 
742
-            update_option( 'wpinv_vat_rates', $rates );
742
+            update_option('wpinv_vat_rates', $rates);
743 743
         }
744 744
         
745 745
         return $input;
@@ -749,71 +749,71 @@  discard block
 block discarded – undo
749 749
         $response = array();
750 750
         $response['success'] = false;
751 751
         
752
-        if ( !current_user_can( 'manage_options' ) ) {
753
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
754
-            wp_send_json( $response );
752
+        if (!current_user_can('manage_options')) {
753
+            $response['error'] = __('Invalid access!', 'invoicing');
754
+            wp_send_json($response);
755 755
         }
756 756
         
757
-        $vat_class_name = !empty( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : false;
758
-        $vat_class_desc = !empty( $_POST['desc'] ) ? sanitize_text_field( $_POST['desc'] ) : false;
757
+        $vat_class_name = !empty($_POST['name']) ? sanitize_text_field($_POST['name']) : false;
758
+        $vat_class_desc = !empty($_POST['desc']) ? sanitize_text_field($_POST['desc']) : false;
759 759
         
760
-        if ( empty( $vat_class_name ) ) {
761
-            $response['error'] = __( 'Select the VAT rate name', 'invoicing' );
762
-            wp_send_json( $response );
760
+        if (empty($vat_class_name)) {
761
+            $response['error'] = __('Select the VAT rate name', 'invoicing');
762
+            wp_send_json($response);
763 763
         }
764 764
         
765 765
         $vat_classes = (array)self::get_rate_classes();
766 766
 
767
-        if ( !empty( $vat_classes ) && in_array( strtolower( $vat_class_name ), array_map( 'strtolower', array_values( $vat_classes ) ) ) ) {
768
-            $response['error'] = wp_sprintf( __( 'A VAT Rate name "%s" already exists', 'invoicing' ), $vat_class_name );
769
-            wp_send_json( $response );
767
+        if (!empty($vat_classes) && in_array(strtolower($vat_class_name), array_map('strtolower', array_values($vat_classes)))) {
768
+            $response['error'] = wp_sprintf(__('A VAT Rate name "%s" already exists', 'invoicing'), $vat_class_name);
769
+            wp_send_json($response);
770 770
         }
771 771
         
772
-        $rate_class_key = normalize_whitespace( 'wpi-' . $vat_class_name );
773
-        $rate_class_key = sanitize_key( str_replace( " ", "-", $rate_class_key ) );
772
+        $rate_class_key = normalize_whitespace('wpi-' . $vat_class_name);
773
+        $rate_class_key = sanitize_key(str_replace(" ", "-", $rate_class_key));
774 774
         
775
-        $vat_classes = (array)self::get_rate_classes( true );
776
-        $vat_classes[$rate_class_key] = array( 'name' => $vat_class_name, 'desc' => $vat_class_desc );
775
+        $vat_classes = (array)self::get_rate_classes(true);
776
+        $vat_classes[$rate_class_key] = array('name' => $vat_class_name, 'desc' => $vat_class_desc);
777 777
         
778
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
778
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
779 779
         
780 780
         $response['success'] = true;
781
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key );
781
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=' . $rate_class_key);
782 782
         
783
-        wp_send_json( $response );
783
+        wp_send_json($response);
784 784
     }
785 785
     
786 786
     public static function delete_class() {
787 787
         $response = array();
788 788
         $response['success'] = false;
789 789
         
790
-        if ( !current_user_can( 'manage_options' ) || !isset( $_POST['class'] ) ) {
791
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
792
-            wp_send_json( $response );
790
+        if (!current_user_can('manage_options') || !isset($_POST['class'])) {
791
+            $response['error'] = __('Invalid access!', 'invoicing');
792
+            wp_send_json($response);
793 793
         }
794 794
         
795
-        $vat_class = isset( $_POST['class'] ) && $_POST['class'] !== '' ? sanitize_text_field( $_POST['class'] ) : false;
795
+        $vat_class = isset($_POST['class']) && $_POST['class'] !== '' ? sanitize_text_field($_POST['class']) : false;
796 796
         $vat_classes = (array)self::get_rate_classes();
797 797
 
798
-        if ( !isset( $vat_classes[$vat_class] ) ) {
799
-            $response['error'] = __( 'Requested class does not exists', 'invoicing' );
800
-            wp_send_json( $response );
798
+        if (!isset($vat_classes[$vat_class])) {
799
+            $response['error'] = __('Requested class does not exists', 'invoicing');
800
+            wp_send_json($response);
801 801
         }
802 802
         
803
-        if ( $vat_class == '_new' || $vat_class == '_standard' ) {
804
-            $response['error'] = __( 'You can not delete standard rates class', 'invoicing' );
805
-            wp_send_json( $response );
803
+        if ($vat_class == '_new' || $vat_class == '_standard') {
804
+            $response['error'] = __('You can not delete standard rates class', 'invoicing');
805
+            wp_send_json($response);
806 806
         }
807 807
             
808
-        $vat_classes = (array)self::get_rate_classes( true );
809
-        unset( $vat_classes[$vat_class] );
808
+        $vat_classes = (array)self::get_rate_classes(true);
809
+        unset($vat_classes[$vat_class]);
810 810
         
811
-        update_option( '_wpinv_vat_rate_classes', $vat_classes );
811
+        update_option('_wpinv_vat_rate_classes', $vat_classes);
812 812
         
813 813
         $response['success'] = true;
814
-        $response['redirect'] = admin_url( 'admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new' );
814
+        $response['redirect'] = admin_url('admin.php?page=wpinv-settings&tab=taxes&section=vat_rates&wpi_sub=_new');
815 815
         
816
-        wp_send_json( $response );
816
+        wp_send_json($response);
817 817
     }
818 818
     
819 819
     public static function update_eu_rates() {        
@@ -822,72 +822,72 @@  discard block
 block discarded – undo
822 822
         $response['error']      = null;
823 823
         $response['data']       = null;
824 824
         
825
-        if ( !current_user_can( 'manage_options' ) ) {
826
-            $response['error'] = __( 'Invalid access!', 'invoicing' );
827
-            wp_send_json( $response );
825
+        if (!current_user_can('manage_options')) {
826
+            $response['error'] = __('Invalid access!', 'invoicing');
827
+            wp_send_json($response);
828 828
         }
829 829
         
830
-        $group      = !empty( $_POST['group'] ) ? sanitize_text_field( $_POST['group'] ) : '';
831
-        $euvatrates = self::request_euvatrates( $group );
830
+        $group      = !empty($_POST['group']) ? sanitize_text_field($_POST['group']) : '';
831
+        $euvatrates = self::request_euvatrates($group);
832 832
         
833
-        if ( !empty( $euvatrates ) ) {
834
-            if ( !empty( $euvatrates['success'] ) && !empty( $euvatrates['rates'] ) ) {
833
+        if (!empty($euvatrates)) {
834
+            if (!empty($euvatrates['success']) && !empty($euvatrates['rates'])) {
835 835
                 $response['success']        = true;
836 836
                 $response['data']['rates']  = $euvatrates['rates'];
837
-            } else if ( !empty( $euvatrates['error'] ) ) {
837
+            } else if (!empty($euvatrates['error'])) {
838 838
                 $response['error']          = $euvatrates['error'];
839 839
             }
840 840
         }
841 841
             
842
-        wp_send_json( $response );
842
+        wp_send_json($response);
843 843
     }
844 844
     
845 845
     public static function hide_vat_fields() {
846
-        $hide = wpinv_get_option( 'vat_disable_fields' );
846
+        $hide = wpinv_get_option('vat_disable_fields');
847 847
         
848
-        return apply_filters( 'wpinv_hide_vat_fields', $hide );
848
+        return apply_filters('wpinv_hide_vat_fields', $hide);
849 849
     }
850 850
     
851 851
     public static function same_country_rule() {
852
-        $same_country_rule = wpinv_get_option( 'vat_same_country_rule' );
852
+        $same_country_rule = wpinv_get_option('vat_same_country_rule');
853 853
         
854
-        return apply_filters( 'wpinv_vat_same_country_rule', $same_country_rule );
854
+        return apply_filters('wpinv_vat_same_country_rule', $same_country_rule);
855 855
     }
856 856
     
857 857
     public static function get_vat_name() {
858
-        $vat_name   = wpinv_get_option( 'vat_name' );
859
-        $vat_name   = !empty( $vat_name ) ? $vat_name : 'VAT';
858
+        $vat_name   = wpinv_get_option('vat_name');
859
+        $vat_name   = !empty($vat_name) ? $vat_name : 'VAT';
860 860
         
861
-        return apply_filters( 'wpinv_get_owner_vat_name', $vat_name );
861
+        return apply_filters('wpinv_get_owner_vat_name', $vat_name);
862 862
     }
863 863
     
864 864
     public static function get_company_name() {
865
-        $company_name = wpinv_get_option( 'vat_company_name' );
865
+        $company_name = wpinv_get_option('vat_company_name');
866 866
         
867
-        return apply_filters( 'wpinv_get_owner_company_name', $company_name );
867
+        return apply_filters('wpinv_get_owner_company_name', $company_name);
868 868
     }
869 869
     
870 870
     public static function get_vat_number() {
871
-        $vat_number = wpinv_get_option( 'vat_number' );
871
+        $vat_number = wpinv_get_option('vat_number');
872 872
         
873
-        return apply_filters( 'wpinv_get_owner_vat_number', $vat_number );
873
+        return apply_filters('wpinv_get_owner_vat_number', $vat_number);
874 874
     }
875 875
     
876 876
     public static function is_vat_validated() {
877
-        $validated = self::get_vat_number() && wpinv_get_option( 'vat_valid' );
877
+        $validated = self::get_vat_number() && wpinv_get_option('vat_valid');
878 878
         
879
-        return apply_filters( 'wpinv_is_owner_vat_validated', $validated );
879
+        return apply_filters('wpinv_is_owner_vat_validated', $validated);
880 880
     }
881 881
     
882
-    public static function sanitize_vat( $vat_number, $country_code = '' ) {        
883
-        $vat_number = str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
882
+    public static function sanitize_vat($vat_number, $country_code = '') {        
883
+        $vat_number = str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
884 884
         
885
-        if ( empty( $country_code ) ) {
886
-            $country_code = substr( $vat_number, 0, 2 );
885
+        if (empty($country_code)) {
886
+            $country_code = substr($vat_number, 0, 2);
887 887
         }
888 888
         
889
-        if ( strpos( $vat_number , $country_code ) === 0 ) {
890
-            $vat = str_replace( $country_code, '', $vat_number );
889
+        if (strpos($vat_number, $country_code) === 0) {
890
+            $vat = str_replace($country_code, '', $vat_number);
891 891
         } else {
892 892
             $vat = $country_code . $vat_number;
893 893
         }
@@ -900,140 +900,140 @@  discard block
 block discarded – undo
900 900
         return $return;
901 901
     }
902 902
     
903
-    public static function offline_check( $vat_number, $country_code = '', $formatted = false ) {
904
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
903
+    public static function offline_check($vat_number, $country_code = '', $formatted = false) {
904
+        $vat            = self::sanitize_vat($vat_number, $country_code);
905 905
         $vat_number     = $vat['vat_number'];
906 906
         $country_code   = $vat['iso'];
907 907
         $regex          = array();
908 908
         
909
-        switch ( $country_code ) {
909
+        switch ($country_code) {
910 910
             case 'AT':
911
-                $regex[] = '/^(AT)U(\d{8})$/';                           // Austria
911
+                $regex[] = '/^(AT)U(\d{8})$/'; // Austria
912 912
                 break;
913 913
             case 'BE':
914
-                $regex[] = '/^(BE)(0?\d{9})$/';                          // Belgium
914
+                $regex[] = '/^(BE)(0?\d{9})$/'; // Belgium
915 915
                 break;
916 916
             case 'BG':
917
-                $regex[] = '/^(BG)(\d{9,10})$/';                         // Bulgaria
917
+                $regex[] = '/^(BG)(\d{9,10})$/'; // Bulgaria
918 918
                 break;
919 919
             case 'CH':
920 920
             case 'CHE':
921
-                $regex[] = '/^(CHE)(\d{9})MWST$/';                       // Switzerland (Not EU)
921
+                $regex[] = '/^(CHE)(\d{9})MWST$/'; // Switzerland (Not EU)
922 922
                 break;
923 923
             case 'CY':
924
-                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/';                // Cyprus
924
+                $regex[] = '/^(CY)([0-5|9]\d{7}[A-Z])$/'; // Cyprus
925 925
                 break;
926 926
             case 'CZ':
927
-                $regex[] = '/^(CZ)(\d{8,13})$/';                         // Czech Republic
927
+                $regex[] = '/^(CZ)(\d{8,13})$/'; // Czech Republic
928 928
                 break;
929 929
             case 'DE':
930
-                $regex[] = '/^(DE)([1-9]\d{8})$/';                       // Germany
930
+                $regex[] = '/^(DE)([1-9]\d{8})$/'; // Germany
931 931
                 break;
932 932
             case 'DK':
933
-                $regex[] = '/^(DK)(\d{8})$/';                            // Denmark
933
+                $regex[] = '/^(DK)(\d{8})$/'; // Denmark
934 934
                 break;
935 935
             case 'EE':
936
-                $regex[] = '/^(EE)(10\d{7})$/';                          // Estonia
936
+                $regex[] = '/^(EE)(10\d{7})$/'; // Estonia
937 937
                 break;
938 938
             case 'EL':
939
-                $regex[] = '/^(EL)(\d{9})$/';                            // Greece
939
+                $regex[] = '/^(EL)(\d{9})$/'; // Greece
940 940
                 break;
941 941
             case 'ES':
942
-                $regex[] = '/^(ES)([A-Z]\d{8})$/';                       // Spain (National juridical entities)
943
-                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/';            // Spain (Other juridical entities)
944
-                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/';              // Spain (Personal entities type 1)
945
-                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/';              // Spain (Personal entities type 2)
942
+                $regex[] = '/^(ES)([A-Z]\d{8})$/'; // Spain (National juridical entities)
943
+                $regex[] = '/^(ES)([A-H|N-S|W]\d{7}[A-J])$/'; // Spain (Other juridical entities)
944
+                $regex[] = '/^(ES)([0-9|Y|Z]\d{7}[A-Z])$/'; // Spain (Personal entities type 1)
945
+                $regex[] = '/^(ES)([K|L|M|X]\d{7}[A-Z])$/'; // Spain (Personal entities type 2)
946 946
                 break;
947 947
             case 'EU':
948
-                $regex[] = '/^(EU)(\d{9})$/';                            // EU-type
948
+                $regex[] = '/^(EU)(\d{9})$/'; // EU-type
949 949
                 break;
950 950
             case 'FI':
951
-                $regex[] = '/^(FI)(\d{8})$/';                            // Finland
951
+                $regex[] = '/^(FI)(\d{8})$/'; // Finland
952 952
                 break;
953 953
             case 'FR':
954
-                $regex[] = '/^(FR)(\d{11})$/';                           // France (1)
955
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/';        // France (2)
956
-                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/';       // France (3)
957
-                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/';      // France (4)
954
+                $regex[] = '/^(FR)(\d{11})$/'; // France (1)
955
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)](\d{10})$/'; // France (2)
956
+                $regex[] = '/^(FR)\d[(A-H)|(J-N)|(P-Z)](\d{9})$/'; // France (3)
957
+                $regex[] = '/^(FR)[(A-H)|(J-N)|(P-Z)]{2}(\d{9})$/'; // France (4)
958 958
                 break;
959 959
             case 'GB':
960
-                $regex[] = '/^(GB)?(\d{9})$/';                           // UK (Standard)
961
-                $regex[] = '/^(GB)?(\d{12})$/';                          // UK (Branches)
962
-                $regex[] = '/^(GB)?(GD\d{3})$/';                         // UK (Government)
963
-                $regex[] = '/^(GB)?(HA\d{3})$/';                         // UK (Health authority)
960
+                $regex[] = '/^(GB)?(\d{9})$/'; // UK (Standard)
961
+                $regex[] = '/^(GB)?(\d{12})$/'; // UK (Branches)
962
+                $regex[] = '/^(GB)?(GD\d{3})$/'; // UK (Government)
963
+                $regex[] = '/^(GB)?(HA\d{3})$/'; // UK (Health authority)
964 964
                 break;
965 965
             case 'GR':
966
-                $regex[] = '/^(GR)(\d{8,9})$/';                          // Greece
966
+                $regex[] = '/^(GR)(\d{8,9})$/'; // Greece
967 967
                 break;
968 968
             case 'HR':
969
-                $regex[] = '/^(HR)(\d{11})$/';                           // Croatia
969
+                $regex[] = '/^(HR)(\d{11})$/'; // Croatia
970 970
                 break;
971 971
             case 'HU':
972
-                $regex[] = '/^(HU)(\d{8})$/';                            // Hungary
972
+                $regex[] = '/^(HU)(\d{8})$/'; // Hungary
973 973
                 break;
974 974
             case 'IE':
975
-                $regex[] = '/^(IE)(\d{7}[A-W])$/';                       // Ireland (1)
976
-                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/';        // Ireland (2)
977
-                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/';                   // Ireland (3) (new format from 1 Jan 2013)
975
+                $regex[] = '/^(IE)(\d{7}[A-W])$/'; // Ireland (1)
976
+                $regex[] = '/^(IE)([7-9][A-Z\*\+)]\d{5}[A-W])$/'; // Ireland (2)
977
+                $regex[] = '/^(IE)(\d{7}[A-Z][AH])$/'; // Ireland (3) (new format from 1 Jan 2013)
978 978
                 break;
979 979
             case 'IT':
980
-                $regex[] = '/^(IT)(\d{11})$/';                           // Italy
980
+                $regex[] = '/^(IT)(\d{11})$/'; // Italy
981 981
                 break;
982 982
             case 'LV':
983
-                $regex[] = '/^(LV)(\d{11})$/';                           // Latvia
983
+                $regex[] = '/^(LV)(\d{11})$/'; // Latvia
984 984
                 break;
985 985
             case 'LT':
986
-                $regex[] = '/^(LT)(\d{9}|\d{12})$/';                     // Lithuania
986
+                $regex[] = '/^(LT)(\d{9}|\d{12})$/'; // Lithuania
987 987
                 break;
988 988
             case 'LU':
989
-                $regex[] = '/^(LU)(\d{8})$/';                            // Luxembourg
989
+                $regex[] = '/^(LU)(\d{8})$/'; // Luxembourg
990 990
                 break;
991 991
             case 'MT':
992
-                $regex[] = '/^(MT)([1-9]\d{7})$/';                       // Malta
992
+                $regex[] = '/^(MT)([1-9]\d{7})$/'; // Malta
993 993
                 break;
994 994
             case 'NL':
995
-                $regex[] = '/^(NL)(\d{9})B\d{2}$/';                      // Netherlands
995
+                $regex[] = '/^(NL)(\d{9})B\d{2}$/'; // Netherlands
996 996
                 break;
997 997
             case 'NO':
998
-                $regex[] = '/^(NO)(\d{9})$/';                            // Norway (Not EU)
998
+                $regex[] = '/^(NO)(\d{9})$/'; // Norway (Not EU)
999 999
                 break;
1000 1000
             case 'PL':
1001
-                $regex[] = '/^(PL)(\d{10})$/';                           // Poland
1001
+                $regex[] = '/^(PL)(\d{10})$/'; // Poland
1002 1002
                 break;
1003 1003
             case 'PT':
1004
-                $regex[] = '/^(PT)(\d{9})$/';                            // Portugal
1004
+                $regex[] = '/^(PT)(\d{9})$/'; // Portugal
1005 1005
                 break;
1006 1006
             case 'RO':
1007
-                $regex[] = '/^(RO)([1-9]\d{1,9})$/';                     // Romania
1007
+                $regex[] = '/^(RO)([1-9]\d{1,9})$/'; // Romania
1008 1008
                 break;
1009 1009
             case 'RS':
1010
-                $regex[] = '/^(RS)(\d{9})$/';                            // Serbia (Not EU)
1010
+                $regex[] = '/^(RS)(\d{9})$/'; // Serbia (Not EU)
1011 1011
                 break;
1012 1012
             case 'SI':
1013
-                $regex[] = '/^(SI)([1-9]\d{7})$/';                       // Slovenia
1013
+                $regex[] = '/^(SI)([1-9]\d{7})$/'; // Slovenia
1014 1014
                 break;
1015 1015
             case 'SK':
1016
-                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/';        // Slovakia Republic
1016
+                $regex[] = '/^(SK)([1-9]\d[(2-4)|(6-9)]\d{7})$/'; // Slovakia Republic
1017 1017
                 break;
1018 1018
             case 'SE':
1019
-                $regex[] = '/^(SE)(\d{10}01)$/';                         // Sweden
1019
+                $regex[] = '/^(SE)(\d{10}01)$/'; // Sweden
1020 1020
                 break;
1021 1021
             default:
1022 1022
                 $regex = array();
1023 1023
             break;
1024 1024
         }
1025 1025
         
1026
-        if ( empty( $regex ) ) {
1026
+        if (empty($regex)) {
1027 1027
             return false;
1028 1028
         }
1029 1029
         
1030
-        foreach ( $regex as $pattern ) {
1030
+        foreach ($regex as $pattern) {
1031 1031
             $matches = null;
1032
-            preg_match_all( $pattern, $vat_number, $matches );
1032
+            preg_match_all($pattern, $vat_number, $matches);
1033 1033
             
1034
-            if ( !empty( $matches[1][0] ) && !empty( $matches[2][0] ) ) {
1035
-                if ( $formatted ) {
1036
-                    return array( 'code' => $matches[1][0], 'number' => $matches[2][0] );
1034
+            if (!empty($matches[1][0]) && !empty($matches[2][0])) {
1035
+                if ($formatted) {
1036
+                    return array('code' => $matches[1][0], 'number' => $matches[2][0]);
1037 1037
                 } else {
1038 1038
                     return true;
1039 1039
                 }
@@ -1043,75 +1043,75 @@  discard block
 block discarded – undo
1043 1043
         return false;
1044 1044
     }
1045 1045
     
1046
-    public static function vies_check( $vat_number, $country_code = '', $result = false ) {
1047
-        $vat            = self::sanitize_vat( $vat_number, $country_code );
1046
+    public static function vies_check($vat_number, $country_code = '', $result = false) {
1047
+        $vat            = self::sanitize_vat($vat_number, $country_code);
1048 1048
         $vat_number     = $vat['vat'];
1049 1049
         $iso            = $vat['iso'];
1050 1050
         
1051
-        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode( $iso ) . '&iso=' . urlencode( $iso ) . '&vat=' . urlencode( $vat_number );
1051
+        $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms=' . urlencode($iso) . '&iso=' . urlencode($iso) . '&vat=' . urlencode($vat_number);
1052 1052
         
1053
-        if ( ini_get( 'allow_url_fopen' ) ) {
1054
-            $response = file_get_contents( $url );
1055
-        } else if ( function_exists( 'curl_init' ) ) {
1053
+        if (ini_get('allow_url_fopen')) {
1054
+            $response = file_get_contents($url);
1055
+        } else if (function_exists('curl_init')) {
1056 1056
             $ch = curl_init();
1057 1057
             
1058
-            curl_setopt( $ch, CURLOPT_URL, $url );
1059
-            curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
1060
-            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
1061
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
1062
-            curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
1058
+            curl_setopt($ch, CURLOPT_URL, $url);
1059
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
1060
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
1061
+            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
1062
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
1063 1063
             
1064
-            $response = curl_exec( $ch );
1064
+            $response = curl_exec($ch);
1065 1065
             
1066
-            if ( curl_errno( $ch ) ) {
1067
-                wpinv_error_log( curl_error( $ch ), 'VIES CHECK ERROR' );
1066
+            if (curl_errno($ch)) {
1067
+                wpinv_error_log(curl_error($ch), 'VIES CHECK ERROR');
1068 1068
                 $response = '';
1069 1069
             }
1070 1070
             
1071
-            curl_close( $ch );
1071
+            curl_close($ch);
1072 1072
         } else {
1073
-            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' );
1073
+            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');
1074 1074
         }
1075 1075
         
1076
-        if ( empty( $response ) ) {
1076
+        if (empty($response)) {
1077 1077
             return $result;
1078 1078
         }
1079 1079
 
1080
-        if ( preg_match( '/invalid VAT number/i', $response ) ) {
1080
+        if (preg_match('/invalid VAT number/i', $response)) {
1081 1081
             return false;
1082
-        } else if ( preg_match( '/valid VAT number/i', $response, $matches ) ) {
1083
-            $content = explode( "valid VAT number", htmlentities( $response ) );
1082
+        } else if (preg_match('/valid VAT number/i', $response, $matches)) {
1083
+            $content = explode("valid VAT number", htmlentities($response));
1084 1084
             
1085
-            if ( !empty( $content[1] ) ) {
1086
-                preg_match_all( '/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode( $content[1] ), $matches );
1085
+            if (!empty($content[1])) {
1086
+                preg_match_all('/<tr>(.*?)<td.*?>(.*?)<\/td>(.*?)<\/tr>/si', html_entity_decode($content[1]), $matches);
1087 1087
                 
1088
-                if ( !empty( $matches[2] ) && $matches[3] ) {
1088
+                if (!empty($matches[2]) && $matches[3]) {
1089 1089
                     $return = array();
1090 1090
                     
1091
-                    foreach ( $matches[2] as $key => $label ) {
1092
-                        $label = trim( $label );
1091
+                    foreach ($matches[2] as $key => $label) {
1092
+                        $label = trim($label);
1093 1093
                         
1094
-                        switch ( strtolower( $label ) ) {
1094
+                        switch (strtolower($label)) {
1095 1095
                             case 'member state':
1096
-                                $return['state'] = trim( strip_tags( $matches[3][$key] ) );
1096
+                                $return['state'] = trim(strip_tags($matches[3][$key]));
1097 1097
                             break;
1098 1098
                             case 'vat number':
1099
-                                $return['number'] = trim( strip_tags( $matches[3][$key] ) );
1099
+                                $return['number'] = trim(strip_tags($matches[3][$key]));
1100 1100
                             break;
1101 1101
                             case 'name':
1102
-                                $return['company'] = trim( strip_tags( $matches[3][$key] ) );
1102
+                                $return['company'] = trim(strip_tags($matches[3][$key]));
1103 1103
                             break;
1104 1104
                             case 'address':
1105
-                                $address           = str_replace( array( "<br><br>", "<br /><br />", "<br/><br/>" ), "<br>", html_entity_decode( trim( $matches[3][$key] ) ) );
1106
-                                $return['address'] = trim( strip_tags( $address, '<br>' ) );
1105
+                                $address           = str_replace(array("<br><br>", "<br /><br />", "<br/><br/>"), "<br>", html_entity_decode(trim($matches[3][$key])));
1106
+                                $return['address'] = trim(strip_tags($address, '<br>'));
1107 1107
                             break;
1108 1108
                             case 'consultation number':
1109
-                                $return['consultation'] = trim( strip_tags( $matches[3][$key] ) );
1109
+                                $return['consultation'] = trim(strip_tags($matches[3][$key]));
1110 1110
                             break;
1111 1111
                         }
1112 1112
                     }
1113 1113
                     
1114
-                    if ( !empty( $return ) ) {
1114
+                    if (!empty($return)) {
1115 1115
                         return $return;
1116 1116
                     }
1117 1117
                 }
@@ -1123,55 +1123,55 @@  discard block
 block discarded – undo
1123 1123
         }
1124 1124
     }
1125 1125
     
1126
-    public static function check_vat( $vat_number, $country_code = '' ) {        
1126
+    public static function check_vat($vat_number, $country_code = '') {        
1127 1127
         $vat_name           = self::get_vat_name();
1128 1128
         
1129 1129
         $return             = array();
1130 1130
         $return['valid']    = false;
1131
-        $return['message']  = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1131
+        $return['message']  = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1132 1132
                 
1133
-        if ( !wpinv_get_option( 'vat_offline_check' ) && !self::offline_check( $vat_number, $country_code ) ) {
1133
+        if (!wpinv_get_option('vat_offline_check') && !self::offline_check($vat_number, $country_code)) {
1134 1134
             return $return;
1135 1135
         }
1136 1136
             
1137
-        $response = self::vies_check( $vat_number, $country_code );
1137
+        $response = self::vies_check($vat_number, $country_code);
1138 1138
         
1139
-        if ( $response ) {
1140
-            $return['valid']    = true;
1139
+        if ($response) {
1140
+            $return['valid'] = true;
1141 1141
             
1142
-            if ( is_array( $response ) ) {
1143
-                $return['company'] = isset( $response['company'] ) ? $response['company'] : '';
1144
-                $return['address'] = isset( $response['address'] ) ? $response['address'] : '';
1142
+            if (is_array($response)) {
1143
+                $return['company'] = isset($response['company']) ? $response['company'] : '';
1144
+                $return['address'] = isset($response['address']) ? $response['address'] : '';
1145 1145
                 $return['message'] = $return['company'] . '<br/>' . $return['address'];
1146 1146
             }
1147 1147
         } else {
1148 1148
             $return['valid']    = false;
1149
-            $return['message']  = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1149
+            $return['message']  = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1150 1150
         }
1151 1151
         
1152 1152
         return $return;
1153 1153
     }
1154 1154
     
1155
-    public static function request_euvatrates( $group ) {
1155
+    public static function request_euvatrates($group) {
1156 1156
         $response               = array();
1157 1157
         $response['success']    = false;
1158 1158
         $response['error']      = null;
1159 1159
         $response['eurates']    = null;
1160 1160
         
1161 1161
         $euvatrates_url = 'https://euvatrates.com/rates.json';
1162
-        $euvatrates_url = apply_filters( 'wpinv_euvatrates_url', $euvatrates_url );
1163
-        $api_response   = wp_remote_get( $euvatrates_url );
1162
+        $euvatrates_url = apply_filters('wpinv_euvatrates_url', $euvatrates_url);
1163
+        $api_response   = wp_remote_get($euvatrates_url);
1164 1164
     
1165 1165
         try {
1166
-            if ( is_wp_error( $api_response ) ) {
1167
-                $response['error']      = __( $api_response->get_error_message(), 'invoicing' );
1166
+            if (is_wp_error($api_response)) {
1167
+                $response['error'] = __($api_response->get_error_message(), 'invoicing');
1168 1168
             } else {
1169
-                $body = json_decode( $api_response['body'] );
1169
+                $body = json_decode($api_response['body']);
1170 1170
                 
1171
-                if ( isset( $body->rates ) ) {
1171
+                if (isset($body->rates)) {
1172 1172
                     $rates = array();
1173 1173
                     
1174
-                    foreach ( $body->rates as $country_code => $rate ) {
1174
+                    foreach ($body->rates as $country_code => $rate) {
1175 1175
                         $vat_rate = array();
1176 1176
                         $vat_rate['country']        = $rate->country;
1177 1177
                         $vat_rate['standard']       = (float)$rate->standard_rate;
@@ -1179,7 +1179,7 @@  discard block
 block discarded – undo
1179 1179
                         $vat_rate['superreduced']   = (float)$rate->super_reduced_rate;
1180 1180
                         $vat_rate['parking']        = (float)$rate->parking_rate;
1181 1181
                         
1182
-                        if ( $group !== '' && in_array( $group, array( 'standard', 'reduced', 'superreduced', 'parking' ) ) ) {
1182
+                        if ($group !== '' && in_array($group, array('standard', 'reduced', 'superreduced', 'parking'))) {
1183 1183
                             $vat_rate_group = array();
1184 1184
                             $vat_rate_group['country'] = $rate->country;
1185 1185
                             $vat_rate_group[$group]    = $vat_rate[$group];
@@ -1191,79 +1191,79 @@  discard block
 block discarded – undo
1191 1191
                     }
1192 1192
                     
1193 1193
                     $response['success']    = true;                                
1194
-                    $response['rates']      = apply_filters( 'wpinv_process_euvatrates', $rates, $api_response, $group );
1194
+                    $response['rates']      = apply_filters('wpinv_process_euvatrates', $rates, $api_response, $group);
1195 1195
                 } else {
1196
-                    $response['error']      = __( 'No EU rates found!', 'invoicing' );
1196
+                    $response['error']      = __('No EU rates found!', 'invoicing');
1197 1197
                 }
1198 1198
             }
1199
-        } catch ( Exception $e ) {
1200
-            $response['error'] = __( $e->getMessage(), 'invoicing' );
1199
+        } catch (Exception $e) {
1200
+            $response['error'] = __($e->getMessage(), 'invoicing');
1201 1201
         }
1202 1202
         
1203
-        return apply_filters( 'wpinv_response_euvatrates', $response, $group );
1203
+        return apply_filters('wpinv_response_euvatrates', $response, $group);
1204 1204
     }    
1205 1205
     
1206
-    public static function requires_vat( $requires_vat = false, $user_id = 0, $is_digital = null ) {
1206
+    public static function requires_vat($requires_vat = false, $user_id = 0, $is_digital = null) {
1207 1207
         global $wpi_item_id, $wpi_country;
1208 1208
         
1209
-        if ( !empty( $_POST['wpinv_country'] ) ) {
1210
-            $country_code = trim( $_POST['wpinv_country'] );
1211
-        } else if ( !empty( $_POST['country'] ) ) {
1212
-            $country_code = trim( $_POST['country'] );
1213
-        } else if ( !empty( $wpi_country ) ) {
1209
+        if (!empty($_POST['wpinv_country'])) {
1210
+            $country_code = trim($_POST['wpinv_country']);
1211
+        } else if (!empty($_POST['country'])) {
1212
+            $country_code = trim($_POST['country']);
1213
+        } else if (!empty($wpi_country)) {
1214 1214
             $country_code = $wpi_country;
1215 1215
         } else {
1216
-            $country_code = self::get_user_country( '', $user_id );
1216
+            $country_code = self::get_user_country('', $user_id);
1217 1217
         }
1218 1218
         
1219
-        if ( $is_digital === null && $wpi_item_id ) {
1220
-            $is_digital = $wpi_item_id ? self::item_has_digital_rule( $wpi_item_id ) : self::allow_vat_rules();
1219
+        if ($is_digital === null && $wpi_item_id) {
1220
+            $is_digital = $wpi_item_id ? self::item_has_digital_rule($wpi_item_id) : self::allow_vat_rules();
1221 1221
         }
1222 1222
         
1223
-        if ( !empty( $country_code ) ) {
1224
-            $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 ) );
1223
+        if (!empty($country_code)) {
1224
+            $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 1225
         }
1226 1226
         
1227
-        return apply_filters( 'wpinv_requires_vat', $requires_vat, $user_id );
1227
+        return apply_filters('wpinv_requires_vat', $requires_vat, $user_id);
1228 1228
     }
1229 1229
     
1230
-    public static function tax_label( $label = '' ) {
1230
+    public static function tax_label($label = '') {
1231 1231
         global $wpi_requires_vat;
1232 1232
         
1233
-        if ( !( $wpi_requires_vat !== 0 && $wpi_requires_vat ) ) {
1234
-            $wpi_requires_vat = self::requires_vat( 0, false );
1233
+        if (!($wpi_requires_vat !== 0 && $wpi_requires_vat)) {
1234
+            $wpi_requires_vat = self::requires_vat(0, false);
1235 1235
         }
1236 1236
         
1237
-        return $wpi_requires_vat ? __( self::get_vat_name(), 'invoicing' ) : ( $label ? $label : __( 'Tax', 'invoicing' ) );
1237
+        return $wpi_requires_vat ? __(self::get_vat_name(), 'invoicing') : ($label ? $label : __('Tax', 'invoicing'));
1238 1238
     }
1239 1239
     
1240 1240
     public static function standard_rates_label() {
1241
-        return __( 'Standard Rates', 'invoicing' );
1241
+        return __('Standard Rates', 'invoicing');
1242 1242
     }
1243 1243
     
1244
-    public static function get_rate_classes( $with_desc = false ) {        
1245
-        $rate_classes_option = get_option( '_wpinv_vat_rate_classes', true );
1246
-        $classes = maybe_unserialize( $rate_classes_option );
1244
+    public static function get_rate_classes($with_desc = false) {        
1245
+        $rate_classes_option = get_option('_wpinv_vat_rate_classes', true);
1246
+        $classes = maybe_unserialize($rate_classes_option);
1247 1247
         
1248
-        if ( empty( $classes ) || !is_array( $classes ) ) {
1248
+        if (empty($classes) || !is_array($classes)) {
1249 1249
             $classes = array();
1250 1250
         }
1251 1251
 
1252 1252
         $rate_classes = array();
1253
-        if ( !array_key_exists( '_standard', $classes ) ) {
1254
-            if ( $with_desc ) {
1255
-                $rate_classes['_standard'] = array( 'name' => self::standard_rates_label(), 'desc' => __( 'EU member states standard VAT rates', 'invoicing' ) );
1253
+        if (!array_key_exists('_standard', $classes)) {
1254
+            if ($with_desc) {
1255
+                $rate_classes['_standard'] = array('name' => self::standard_rates_label(), 'desc' => __('EU member states standard VAT rates', 'invoicing'));
1256 1256
             } else {
1257 1257
                 $rate_classes['_standard'] = self::standard_rates_label();
1258 1258
             }
1259 1259
         }
1260 1260
         
1261
-        foreach ( $classes as $key => $class ) {
1262
-            $name = !empty( $class['name'] ) ? __( $class['name'], 'invoicing' ) : $key;
1263
-            $desc = !empty( $class['desc'] ) ? __( $class['desc'], 'invoicing' ) : '';
1261
+        foreach ($classes as $key => $class) {
1262
+            $name = !empty($class['name']) ? __($class['name'], 'invoicing') : $key;
1263
+            $desc = !empty($class['desc']) ? __($class['desc'], 'invoicing') : '';
1264 1264
             
1265
-            if ( $with_desc ) {
1266
-                $rate_classes[$key] = array( 'name' => $name, 'desc' => $desc );
1265
+            if ($with_desc) {
1266
+                $rate_classes[$key] = array('name' => $name, 'desc' => $desc);
1267 1267
             } else {
1268 1268
                 $rate_classes[$key] = $name;
1269 1269
             }
@@ -1274,15 +1274,15 @@  discard block
 block discarded – undo
1274 1274
     
1275 1275
     public static function get_all_classes() {        
1276 1276
         $classes            = self::get_rate_classes();
1277
-        $classes['_exempt'] = __( 'Exempt (0%)', 'invoicing' );
1277
+        $classes['_exempt'] = __('Exempt (0%)', 'invoicing');
1278 1278
         
1279
-        return apply_filters( 'wpinv_vat_get_all_classes', $classes );
1279
+        return apply_filters('wpinv_vat_get_all_classes', $classes);
1280 1280
     }
1281 1281
     
1282
-    public static function get_class_desc( $rate_class ) {        
1283
-        $rate_classes = self::get_rate_classes( true );
1282
+    public static function get_class_desc($rate_class) {        
1283
+        $rate_classes = self::get_rate_classes(true);
1284 1284
 
1285
-        if ( !empty( $rate_classes ) && isset( $rate_classes[$rate_class] ) && isset( $rate_classes[$rate_class]['desc'] ) ) {
1285
+        if (!empty($rate_classes) && isset($rate_classes[$rate_class]) && isset($rate_classes[$rate_class]['desc'])) {
1286 1286
             return $rate_classes[$rate_class]['desc'];
1287 1287
         }
1288 1288
         
@@ -1298,106 +1298,106 @@  discard block
 block discarded – undo
1298 1298
             'increased'     => 'Increased'
1299 1299
         );
1300 1300
         
1301
-        return apply_filters( 'wpinv_get_vat_groups', $vat_groups );
1301
+        return apply_filters('wpinv_get_vat_groups', $vat_groups);
1302 1302
     }
1303 1303
 
1304 1304
     public static function get_rules() {
1305 1305
         $vat_rules = array(
1306
-            'digital' => __( 'Digital Product', 'invoicing' ),
1307
-            'physical' => __( 'Physical Product', 'invoicing' )
1306
+            'digital' => __('Digital Product', 'invoicing'),
1307
+            'physical' => __('Physical Product', 'invoicing')
1308 1308
         );
1309
-        return apply_filters( 'wpinv_get_vat_rules', $vat_rules );
1309
+        return apply_filters('wpinv_get_vat_rules', $vat_rules);
1310 1310
     }
1311 1311
 
1312
-    public static function get_vat_rates( $class ) {
1313
-        if ( $class === '_standard' ) {
1312
+    public static function get_vat_rates($class) {
1313
+        if ($class === '_standard') {
1314 1314
             return wpinv_get_tax_rates();
1315 1315
         }
1316 1316
 
1317 1317
         $rates = self::get_non_standard_rates();
1318 1318
 
1319
-        return array_key_exists( $class, $rates ) ? $rates[$class] : array();
1319
+        return array_key_exists($class, $rates) ? $rates[$class] : array();
1320 1320
     }
1321 1321
 
1322 1322
     public static function get_non_standard_rates() {
1323
-        $option = get_option( 'wpinv_vat_rates', array());
1324
-        return is_array( $option ) ? $option : array();
1323
+        $option = get_option('wpinv_vat_rates', array());
1324
+        return is_array($option) ? $option : array();
1325 1325
     }
1326 1326
     
1327 1327
     public static function allow_vat_rules() {
1328
-        return ( wpinv_use_taxes() && wpinv_get_option( 'apply_vat_rules' ) ? true : false );
1328
+        return (wpinv_use_taxes() && wpinv_get_option('apply_vat_rules') ? true : false);
1329 1329
     }
1330 1330
     
1331 1331
     public static function allow_vat_classes() {
1332 1332
         return false; // TODO
1333
-        return ( wpinv_get_option( 'vat_allow_classes' ) ? true : false );
1333
+        return (wpinv_get_option('vat_allow_classes') ? true : false);
1334 1334
     }
1335 1335
     
1336
-    public static function get_item_class( $postID ) {
1337
-        $class = get_post_meta( $postID, '_wpinv_vat_class', true );
1336
+    public static function get_item_class($postID) {
1337
+        $class = get_post_meta($postID, '_wpinv_vat_class', true);
1338 1338
 
1339
-        if ( empty( $class ) ) {
1339
+        if (empty($class)) {
1340 1340
             $class = '_standard';
1341 1341
         }
1342 1342
         
1343
-        return apply_filters( 'wpinv_get_item_vat_class', $class, $postID );
1343
+        return apply_filters('wpinv_get_item_vat_class', $class, $postID);
1344 1344
     }
1345 1345
     
1346
-    public static function item_class_label( $postID ) {        
1346
+    public static function item_class_label($postID) {        
1347 1347
         $vat_classes = self::get_all_classes();
1348 1348
         
1349
-        $class = self::get_item_class( $postID );
1350
-        $class = isset( $vat_classes[$class] ) ? $vat_classes[$class] : __( $class, 'invoicing' );
1349
+        $class = self::get_item_class($postID);
1350
+        $class = isset($vat_classes[$class]) ? $vat_classes[$class] : __($class, 'invoicing');
1351 1351
         
1352
-        return apply_filters( 'wpinv_item_class_label', $class, $postID );
1352
+        return apply_filters('wpinv_item_class_label', $class, $postID);
1353 1353
     }
1354 1354
     
1355
-    public static function get_item_rule( $postID ) {        
1356
-        $rule_type = get_post_meta( $postID, '_wpinv_vat_rule', true );
1355
+    public static function get_item_rule($postID) {        
1356
+        $rule_type = get_post_meta($postID, '_wpinv_vat_rule', true);
1357 1357
         
1358
-        if ( empty( $rule_type ) ) {        
1358
+        if (empty($rule_type)) {        
1359 1359
             $rule_type = self::allow_vat_rules() ? 'digital' : 'physical';
1360 1360
         }
1361 1361
         
1362
-        return apply_filters( 'wpinv_item_get_vat_rule', $rule_type, $postID );
1362
+        return apply_filters('wpinv_item_get_vat_rule', $rule_type, $postID);
1363 1363
     }
1364 1364
     
1365
-    public static function item_rule_label( $postID ) {
1365
+    public static function item_rule_label($postID) {
1366 1366
         $vat_rules  = self::get_rules();
1367
-        $vat_rule   = self::get_item_rule( $postID );
1368
-        $vat_rule   = isset( $vat_rules[$vat_rule] ) ? $vat_rules[$vat_rule] : $vat_rule;
1367
+        $vat_rule   = self::get_item_rule($postID);
1368
+        $vat_rule   = isset($vat_rules[$vat_rule]) ? $vat_rules[$vat_rule] : $vat_rule;
1369 1369
         
1370
-        return apply_filters( 'wpinv_item_rule_label', $vat_rule, $postID );
1370
+        return apply_filters('wpinv_item_rule_label', $vat_rule, $postID);
1371 1371
     }
1372 1372
     
1373
-    public static function item_has_digital_rule( $item_id = 0 ) {        
1374
-        return self::get_item_rule( $item_id ) == 'digital' ? true : false;
1373
+    public static function item_has_digital_rule($item_id = 0) {        
1374
+        return self::get_item_rule($item_id) == 'digital' ? true : false;
1375 1375
     }
1376 1376
     
1377
-    public static function invoice_has_digital_rule( $invoice = 0 ) {        
1378
-        if ( !self::allow_vat_rules() ) {
1377
+    public static function invoice_has_digital_rule($invoice = 0) {        
1378
+        if (!self::allow_vat_rules()) {
1379 1379
             return false;
1380 1380
         }
1381 1381
         
1382
-        if ( empty( $invoice ) ) {
1382
+        if (empty($invoice)) {
1383 1383
             return true;
1384 1384
         }
1385 1385
         
1386
-        if ( is_int( $invoice ) ) {
1387
-            $invoice = new WPInv_Invoice( $invoice );
1386
+        if (is_int($invoice)) {
1387
+            $invoice = new WPInv_Invoice($invoice);
1388 1388
         }
1389 1389
         
1390
-        if ( !( is_object( $invoice ) && is_a( $invoice, 'WPInv_Invoice' ) ) ) {
1390
+        if (!(is_object($invoice) && is_a($invoice, 'WPInv_Invoice'))) {
1391 1391
             return true;
1392 1392
         }
1393 1393
         
1394
-        $cart_items  = $invoice->get_cart_details();
1394
+        $cart_items = $invoice->get_cart_details();
1395 1395
         
1396
-        if ( !empty( $cart_items ) ) {
1396
+        if (!empty($cart_items)) {
1397 1397
             $has_digital_rule = false;
1398 1398
             
1399
-            foreach ( $cart_items as $key => $item ) {
1400
-                if ( self::item_has_digital_rule( $item['id'] ) ) {
1399
+            foreach ($cart_items as $key => $item) {
1400
+                if (self::item_has_digital_rule($item['id'])) {
1401 1401
                     $has_digital_rule = true;
1402 1402
                     break;
1403 1403
                 }
@@ -1409,67 +1409,67 @@  discard block
 block discarded – undo
1409 1409
         return $has_digital_rule;
1410 1410
     }
1411 1411
     
1412
-    public static function item_is_taxable( $item_id = 0, $country = false, $state = false ) {        
1413
-        if ( !wpinv_use_taxes() ) {
1412
+    public static function item_is_taxable($item_id = 0, $country = false, $state = false) {        
1413
+        if (!wpinv_use_taxes()) {
1414 1414
             return false;
1415 1415
         }
1416 1416
         
1417 1417
         $is_taxable = true;
1418 1418
 
1419
-        if ( !empty( $item_id ) && self::get_item_class( $item_id ) == '_exempt' ) {
1419
+        if (!empty($item_id) && self::get_item_class($item_id) == '_exempt') {
1420 1420
             $is_taxable = false;
1421 1421
         }
1422 1422
         
1423
-        return apply_filters( 'wpinv_item_is_taxable', $is_taxable, $item_id, $country , $state );
1423
+        return apply_filters('wpinv_item_is_taxable', $is_taxable, $item_id, $country, $state);
1424 1424
     }
1425 1425
     
1426
-    public static function find_rate( $country, $state, $rate, $class ) {
1426
+    public static function find_rate($country, $state, $rate, $class) {
1427 1427
         global $wpi_zero_tax;
1428 1428
 
1429
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1429
+        if ($class === '_exempt' || $wpi_zero_tax) {
1430 1430
             return 0;
1431 1431
         }
1432 1432
 
1433
-        $tax_rates   = wpinv_get_tax_rates();
1433
+        $tax_rates = wpinv_get_tax_rates();
1434 1434
         
1435
-        if ( $class !== '_standard' ) {
1436
-            $class_rates = self::get_vat_rates( $class );
1435
+        if ($class !== '_standard') {
1436
+            $class_rates = self::get_vat_rates($class);
1437 1437
             
1438
-            if ( is_array( $class_rates ) ) {
1438
+            if (is_array($class_rates)) {
1439 1439
                 $indexed_class_rates = array();
1440 1440
                 
1441
-                foreach ( $class_rates as $key => $cr ) {
1441
+                foreach ($class_rates as $key => $cr) {
1442 1442
                     $indexed_class_rates[$cr['country']] = $cr;
1443 1443
                 }
1444 1444
 
1445
-                $tax_rates = array_map( function( $tr ) use( $indexed_class_rates ) {
1445
+                $tax_rates = array_map(function($tr) use($indexed_class_rates) {
1446 1446
                     $tr_country = $tr['country'];
1447
-                    if ( !isset( $indexed_class_rates[$tr_country] ) ) {
1447
+                    if (!isset($indexed_class_rates[$tr_country])) {
1448 1448
                         return $tr;
1449 1449
                     }
1450 1450
                     $icr = $indexed_class_rates[$tr_country];
1451
-                    return ( empty( $icr['rate'] ) && $icr['rate'] !== '0' ) ? $tr : $icr;
1451
+                    return (empty($icr['rate']) && $icr['rate'] !== '0') ? $tr : $icr;
1452 1452
 
1453
-                }, $tax_rates, $class_rates );
1453
+                }, $tax_rates, $class_rates);
1454 1454
             }
1455 1455
         }
1456 1456
 
1457
-        if ( !empty( $tax_rates ) ) {
1458
-            foreach ( $tax_rates as $key => $tax_rate ) {
1459
-                if ( $country != $tax_rate['country'] )
1457
+        if (!empty($tax_rates)) {
1458
+            foreach ($tax_rates as $key => $tax_rate) {
1459
+                if ($country != $tax_rate['country'])
1460 1460
                     continue;
1461 1461
 
1462
-                if ( !empty( $tax_rate['global'] ) ) {
1463
-                    if ( 0 !== $tax_rate['rate'] || !empty( $tax_rate['rate'] ) ) {
1464
-                        $rate = number_format( $tax_rate['rate'], 4 );
1462
+                if (!empty($tax_rate['global'])) {
1463
+                    if (0 !== $tax_rate['rate'] || !empty($tax_rate['rate'])) {
1464
+                        $rate = number_format($tax_rate['rate'], 4);
1465 1465
                     }
1466 1466
                 } else {
1467
-                    if ( empty( $tax_rate['state'] ) || strtolower( $state ) != strtolower( $tax_rate['state'] ) )
1467
+                    if (empty($tax_rate['state']) || strtolower($state) != strtolower($tax_rate['state']))
1468 1468
                         continue;
1469 1469
 
1470 1470
                     $state_rate = $tax_rate['rate'];
1471
-                    if ( 0 !== $state_rate || !empty( $state_rate ) ) {
1472
-                        $rate = number_format( $state_rate, 4 );
1471
+                    if (0 !== $state_rate || !empty($state_rate)) {
1472
+                        $rate = number_format($state_rate, 4);
1473 1473
                     }
1474 1474
                 }
1475 1475
             }
@@ -1478,84 +1478,84 @@  discard block
 block discarded – undo
1478 1478
         return $rate;
1479 1479
     }
1480 1480
     
1481
-    public static function get_rate( $rate = 1, $country = '', $state = '', $item_id = 0 ) {
1481
+    public static function get_rate($rate = 1, $country = '', $state = '', $item_id = 0) {
1482 1482
         global $wpinv_options, $wpi_session, $wpi_item_id, $wpi_zero_tax;
1483 1483
         
1484 1484
         $item_id = $item_id > 0 ? $item_id : $wpi_item_id;
1485 1485
         $allow_vat_classes = self::allow_vat_classes();
1486
-        $class = $item_id ? self::get_item_class( $item_id ) : '_standard';
1486
+        $class = $item_id ? self::get_item_class($item_id) : '_standard';
1487 1487
 
1488
-        if ( $class === '_exempt' || $wpi_zero_tax ) {
1488
+        if ($class === '_exempt' || $wpi_zero_tax) {
1489 1489
             return 0;
1490
-        } else if ( !$allow_vat_classes ) {
1490
+        } else if (!$allow_vat_classes) {
1491 1491
             $class = '_standard';
1492 1492
         }
1493 1493
 
1494
-        if( !empty( $_POST['wpinv_country'] ) ) {
1494
+        if (!empty($_POST['wpinv_country'])) {
1495 1495
             $post_country = $_POST['wpinv_country'];
1496
-        } elseif( !empty( $_POST['wpinv_country'] ) ) {
1496
+        } elseif (!empty($_POST['wpinv_country'])) {
1497 1497
             $post_country = $_POST['wpinv_country'];
1498
-        } elseif( !empty( $_POST['country'] ) ) {
1498
+        } elseif (!empty($_POST['country'])) {
1499 1499
             $post_country = $_POST['country'];
1500 1500
         } else {
1501 1501
             $post_country = '';
1502 1502
         }
1503 1503
 
1504
-        $country        = !empty( $post_country ) ? $post_country : wpinv_default_billing_country( $country );
1505
-        $base_country   = wpinv_is_base_country( $country );
1504
+        $country        = !empty($post_country) ? $post_country : wpinv_default_billing_country($country);
1505
+        $base_country   = wpinv_is_base_country($country);
1506 1506
         
1507
-        $requires_vat   = self::requires_vat( 0, false );
1508
-        $is_digital     = self::get_item_rule( $item_id ) == 'digital' ;
1509
-        $rate           = $requires_vat && isset( $wpinv_options['eu_fallback_rate'] ) ? $wpinv_options['eu_fallback_rate'] : $rate;
1507
+        $requires_vat   = self::requires_vat(0, false);
1508
+        $is_digital     = self::get_item_rule($item_id) == 'digital';
1509
+        $rate           = $requires_vat && isset($wpinv_options['eu_fallback_rate']) ? $wpinv_options['eu_fallback_rate'] : $rate;
1510 1510
           
1511
-        if ( self::same_country_rule() == 'no' && $base_country ) { // Disable VAT to same country
1511
+        if (self::same_country_rule() == 'no' && $base_country) { // Disable VAT to same country
1512 1512
             $rate = 0;
1513
-        } else if ( $requires_vat ) {
1514
-            $vat_number = self::get_user_vat_number( '', 0, true );
1513
+        } else if ($requires_vat) {
1514
+            $vat_number = self::get_user_vat_number('', 0, true);
1515 1515
             $vat_info   = self::current_vat_data();
1516 1516
             
1517
-            if ( is_array( $vat_info ) ) {
1518
-                $vat_number = isset( $vat_info['number'] ) && !empty( $vat_info['valid'] ) ? $vat_info['number'] : "";
1517
+            if (is_array($vat_info)) {
1518
+                $vat_number = isset($vat_info['number']) && !empty($vat_info['valid']) ? $vat_info['number'] : "";
1519 1519
             }
1520 1520
             
1521
-            if ( $country == 'UK' ) {
1521
+            if ($country == 'UK') {
1522 1522
                 $country = 'GB';
1523 1523
             }
1524 1524
 
1525
-            if ( !empty( $vat_number ) ) {
1525
+            if (!empty($vat_number)) {
1526 1526
                 $rate = 0;
1527 1527
             } else {
1528
-                $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
1528
+                $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
1529 1529
             }
1530 1530
 
1531
-            if ( empty( $vat_number ) && !$is_digital ) {
1532
-                if ( $base_country ) {
1533
-                    $rate = self::find_rate( $country, null, $rate, $class );
1531
+            if (empty($vat_number) && !$is_digital) {
1532
+                if ($base_country) {
1533
+                    $rate = self::find_rate($country, null, $rate, $class);
1534 1534
                 } else {
1535
-                    if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1535
+                    if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1536 1536
                         $rate = $wpinv_options['eu_fallback_rate'];
1537
-                    } else if( !empty( $country ) ) {
1538
-                        $rate = self::find_rate( $country, $state, $rate, $class );
1537
+                    } else if (!empty($country)) {
1538
+                        $rate = self::find_rate($country, $state, $rate, $class);
1539 1539
                     }
1540 1540
                 }
1541
-            } else if ( empty( $vat_number ) || ( self::same_country_rule() == 'always' && $base_country ) ) {
1542
-                if ( empty( $country ) && isset( $wpinv_options['eu_fallback_rate'] ) ) {
1541
+            } else if (empty($vat_number) || (self::same_country_rule() == 'always' && $base_country)) {
1542
+                if (empty($country) && isset($wpinv_options['eu_fallback_rate'])) {
1543 1543
                     $rate = $wpinv_options['eu_fallback_rate'];
1544
-                } else if( !empty( $country ) ) {
1545
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1544
+                } else if (!empty($country)) {
1545
+                    $rate = self::find_rate($country, $state, $rate, $class);
1546 1546
                 }
1547 1547
             }
1548 1548
         } else {
1549
-            if ( $is_digital ) {
1549
+            if ($is_digital) {
1550 1550
                 $ip_country_code = self::get_country_by_ip();
1551 1551
                 
1552
-                if ( $ip_country_code && self::is_eu_state( $ip_country_code ) ) {
1553
-                    $rate = self::find_rate( $ip_country_code, '', 0, $class );
1552
+                if ($ip_country_code && self::is_eu_state($ip_country_code)) {
1553
+                    $rate = self::find_rate($ip_country_code, '', 0, $class);
1554 1554
                 } else {
1555
-                    $rate = self::find_rate( $country, $state, $rate, $class );
1555
+                    $rate = self::find_rate($country, $state, $rate, $class);
1556 1556
                 }
1557 1557
             } else {
1558
-                $rate = self::find_rate( $country, $state, $rate, $class );
1558
+                $rate = self::find_rate($country, $state, $rate, $class);
1559 1559
             }
1560 1560
         }
1561 1561
 
@@ -1565,48 +1565,48 @@  discard block
 block discarded – undo
1565 1565
     public static function current_vat_data() {
1566 1566
         global $wpi_session;
1567 1567
         
1568
-        return $wpi_session->get( 'user_vat_data' );
1568
+        return $wpi_session->get('user_vat_data');
1569 1569
     }
1570 1570
     
1571
-    public static function get_user_country( $country = '', $user_id = 0 ) {
1572
-        $user_address = wpinv_get_user_address( $user_id, false );
1571
+    public static function get_user_country($country = '', $user_id = 0) {
1572
+        $user_address = wpinv_get_user_address($user_id, false);
1573 1573
         
1574
-        if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1574
+        if (wpinv_get_option('vat_ip_country_default')) {
1575 1575
             $country = '';
1576 1576
         }
1577 1577
         
1578
-        $country    = empty( $user_address ) || !isset( $user_address['country'] ) || empty( $user_address['country'] ) ? $country : $user_address['country'];
1579
-        $result     = apply_filters( 'wpinv_get_user_country', $country, $user_id );
1578
+        $country    = empty($user_address) || !isset($user_address['country']) || empty($user_address['country']) ? $country : $user_address['country'];
1579
+        $result     = apply_filters('wpinv_get_user_country', $country, $user_id);
1580 1580
 
1581
-        if ( empty( $result ) ) {
1581
+        if (empty($result)) {
1582 1582
             $result = self::get_country_by_ip();
1583 1583
         }
1584 1584
 
1585 1585
         return $result;
1586 1586
     }
1587 1587
     
1588
-    public static function set_user_country( $country = '', $user_id = 0 ) {
1588
+    public static function set_user_country($country = '', $user_id = 0) {
1589 1589
         global $wpi_userID;
1590 1590
         
1591
-        if ( empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID ) {
1591
+        if (empty($country) && !empty($wpi_userID) && get_current_user_id() != $wpi_userID) {
1592 1592
             $country = wpinv_get_default_country();
1593 1593
         }
1594 1594
         
1595 1595
         return $country;
1596 1596
     }
1597 1597
     
1598
-    public static function get_user_vat_number( $vat_number = '', $user_id = 0, $is_valid = false ) {
1598
+    public static function get_user_vat_number($vat_number = '', $user_id = 0, $is_valid = false) {
1599 1599
         global $wpi_current_id, $wpi_userID;
1600 1600
         
1601
-        if ( !empty( $_POST['new_user'] ) ) {
1601
+        if (!empty($_POST['new_user'])) {
1602 1602
             return '';
1603 1603
         }
1604 1604
         
1605
-        if ( empty( $user_id ) ) {
1606
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1605
+        if (empty($user_id)) {
1606
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1607 1607
         }
1608 1608
 
1609
-        $vat_number = empty( $user_id ) ? '' : get_user_meta( $user_id, '_wpinv_vat_number', true );
1609
+        $vat_number = empty($user_id) ? '' : get_user_meta($user_id, '_wpinv_vat_number', true);
1610 1610
         
1611 1611
         /* TODO
1612 1612
         if ( $is_valid && $vat_number ) {
@@ -1617,38 +1617,38 @@  discard block
 block discarded – undo
1617 1617
         }
1618 1618
         */
1619 1619
 
1620
-        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid );
1620
+        return apply_filters('wpinv_get_user_vat_number', $vat_number, $user_id, $is_valid);
1621 1621
     }
1622 1622
     
1623
-    public static function get_user_company( $company = '', $user_id = 0 ) {
1623
+    public static function get_user_company($company = '', $user_id = 0) {
1624 1624
         global $wpi_current_id, $wpi_userID;
1625 1625
         
1626
-        if ( empty( $user_id ) ) {
1627
-            $user_id = !empty( $wpi_userID ) ? $wpi_userID : ( $wpi_current_id ? wpinv_get_user_id( $wpi_current_id ) : get_current_user_id() );
1626
+        if (empty($user_id)) {
1627
+            $user_id = !empty($wpi_userID) ? $wpi_userID : ($wpi_current_id ? wpinv_get_user_id($wpi_current_id) : get_current_user_id());
1628 1628
         }
1629 1629
 
1630
-        $company = empty( $user_id ) ? "" : get_user_meta( $user_id, '_wpinv_company', true );
1630
+        $company = empty($user_id) ? "" : get_user_meta($user_id, '_wpinv_company', true);
1631 1631
 
1632
-        return apply_filters( 'wpinv_user_company', $company, $user_id );
1632
+        return apply_filters('wpinv_user_company', $company, $user_id);
1633 1633
     }
1634 1634
     
1635
-    public static function save_user_vat_details( $company = '', $vat_number = '' ) {
1636
-        $save = apply_filters( 'wpinv_allow_save_user_vat_details', true );
1635
+    public static function save_user_vat_details($company = '', $vat_number = '') {
1636
+        $save = apply_filters('wpinv_allow_save_user_vat_details', true);
1637 1637
 
1638
-        if ( is_user_logged_in() && $save ) {
1638
+        if (is_user_logged_in() && $save) {
1639 1639
             $user_id = get_current_user_id();
1640 1640
 
1641
-            if ( !empty( $vat_number ) ) {
1642
-                update_user_meta( $user_id, '_wpinv_vat_number', $vat_number );
1641
+            if (!empty($vat_number)) {
1642
+                update_user_meta($user_id, '_wpinv_vat_number', $vat_number);
1643 1643
             } else {
1644
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1644
+                delete_user_meta($user_id, '_wpinv_vat_number');
1645 1645
             }
1646 1646
 
1647
-            if ( !empty( $company ) ) {
1648
-                update_user_meta( $user_id, '_wpinv_company', $company );
1647
+            if (!empty($company)) {
1648
+                update_user_meta($user_id, '_wpinv_company', $company);
1649 1649
             } else {
1650
-                delete_user_meta( $user_id, '_wpinv_company');
1651
-                delete_user_meta( $user_id, '_wpinv_vat_number');
1650
+                delete_user_meta($user_id, '_wpinv_company');
1651
+                delete_user_meta($user_id, '_wpinv_vat_number');
1652 1652
             }
1653 1653
         }
1654 1654
 
@@ -1658,113 +1658,113 @@  discard block
 block discarded – undo
1658 1658
     public static function ajax_vat_validate() {
1659 1659
         global $wpinv_options, $wpi_session;
1660 1660
         
1661
-        $is_checkout            = ( !empty( $_POST['source'] ) && $_POST['source'] == 'checkout' ) ? true : false;
1661
+        $is_checkout            = (!empty($_POST['source']) && $_POST['source'] == 'checkout') ? true : false;
1662 1662
         $response               = array();
1663 1663
         $response['success']    = false;
1664 1664
         
1665
-        if ( empty( $_REQUEST['_wpi_nonce'] ) || ( !empty( $_REQUEST['_wpi_nonce'] ) && !wp_verify_nonce( $_REQUEST['_wpi_nonce'], 'vat_validation' ) ) ) {
1666
-            $response['error'] = __( 'Invalid security nonce', 'invoicing' );
1667
-            wp_send_json( $response );
1665
+        if (empty($_REQUEST['_wpi_nonce']) || (!empty($_REQUEST['_wpi_nonce']) && !wp_verify_nonce($_REQUEST['_wpi_nonce'], 'vat_validation'))) {
1666
+            $response['error'] = __('Invalid security nonce', 'invoicing');
1667
+            wp_send_json($response);
1668 1668
         }
1669 1669
         
1670
-        $vat_name   = self::get_vat_name();
1670
+        $vat_name = self::get_vat_name();
1671 1671
         
1672
-        if ( $is_checkout ) {
1672
+        if ($is_checkout) {
1673 1673
             $invoice = wpinv_get_invoice_cart();
1674 1674
             
1675
-            if ( !self::requires_vat( false, 0, self::invoice_has_digital_rule( $invoice ) ) ) {
1675
+            if (!self::requires_vat(false, 0, self::invoice_has_digital_rule($invoice))) {
1676 1676
                 $vat_info = array();
1677
-                $wpi_session->set( 'user_vat_data', $vat_info );
1677
+                $wpi_session->set('user_vat_data', $vat_info);
1678 1678
 
1679 1679
                 self::save_user_vat_details();
1680 1680
                 
1681 1681
                 $response['success'] = true;
1682
-                $response['message'] = wp_sprintf( __( 'Ignore %s', 'invoicing' ), $vat_name );
1683
-                wp_send_json( $response );
1682
+                $response['message'] = wp_sprintf(__('Ignore %s', 'invoicing'), $vat_name);
1683
+                wp_send_json($response);
1684 1684
             }
1685 1685
         }
1686 1686
         
1687
-        $company    = !empty( $_POST['company'] ) ? sanitize_text_field( $_POST['company'] ) : '';
1688
-        $vat_number = !empty( $_POST['number'] ) ? sanitize_text_field( $_POST['number'] ) : '';
1687
+        $company    = !empty($_POST['company']) ? sanitize_text_field($_POST['company']) : '';
1688
+        $vat_number = !empty($_POST['number']) ? sanitize_text_field($_POST['number']) : '';
1689 1689
         
1690
-        $vat_info = $wpi_session->get( 'user_vat_data' );
1691
-        if ( !is_array( $vat_info ) || empty( $vat_info ) ) {
1692
-            $vat_info = array( 'company'=> $company, 'number' => '', 'valid' => true );
1690
+        $vat_info = $wpi_session->get('user_vat_data');
1691
+        if (!is_array($vat_info) || empty($vat_info)) {
1692
+            $vat_info = array('company'=> $company, 'number' => '', 'valid' => true);
1693 1693
         }
1694 1694
         
1695
-        if ( empty( $vat_number ) ) {
1696
-            if ( $is_checkout ) {
1695
+        if (empty($vat_number)) {
1696
+            if ($is_checkout) {
1697 1697
                 $response['success'] = true;
1698
-                $response['message'] = wp_sprintf( __( 'No %s number has been applied. %s will be added to invoice totals', 'invoicing' ), $vat_name, $vat_name );
1698
+                $response['message'] = wp_sprintf(__('No %s number has been applied. %s will be added to invoice totals', 'invoicing'), $vat_name, $vat_name);
1699 1699
                 
1700
-                $vat_info = $wpi_session->get( 'user_vat_data' );
1700
+                $vat_info = $wpi_session->get('user_vat_data');
1701 1701
                 $vat_info['number'] = "";
1702 1702
                 $vat_info['valid'] = true;
1703 1703
                 
1704
-                self::save_user_vat_details( $company );
1704
+                self::save_user_vat_details($company);
1705 1705
             } else {
1706
-                $response['error'] = wp_sprintf( __( 'Please enter your %s number!', 'invoicing' ), $vat_name );
1706
+                $response['error'] = wp_sprintf(__('Please enter your %s number!', 'invoicing'), $vat_name);
1707 1707
                 
1708 1708
                 $vat_info['valid'] = false;
1709 1709
             }
1710 1710
 
1711
-            $wpi_session->set( 'user_vat_data', $vat_info );
1712
-            wp_send_json( $response );
1711
+            $wpi_session->set('user_vat_data', $vat_info);
1712
+            wp_send_json($response);
1713 1713
         }
1714 1714
         
1715
-        if ( empty( $company ) ) {
1715
+        if (empty($company)) {
1716 1716
             $vat_info['valid'] = false;
1717
-            $wpi_session->set( 'user_vat_data', $vat_info );
1717
+            $wpi_session->set('user_vat_data', $vat_info);
1718 1718
             
1719
-            $response['error'] = __( 'Please enter your registered company name!', 'invoicing' );
1720
-            wp_send_json( $response );
1719
+            $response['error'] = __('Please enter your registered company name!', 'invoicing');
1720
+            wp_send_json($response);
1721 1721
         }
1722 1722
         
1723
-        if ( !empty( $wpinv_options['vat_vies_check'] ) ) {
1724
-            if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1723
+        if (!empty($wpinv_options['vat_vies_check'])) {
1724
+            if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1725 1725
                 $vat_info['valid'] = false;
1726
-                $wpi_session->set( 'user_vat_data', $vat_info );
1726
+                $wpi_session->set('user_vat_data', $vat_info);
1727 1727
                 
1728
-                $response['error'] = wp_sprintf( __( '%s number not validated', 'invoicing' ), $vat_name );
1729
-                wp_send_json( $response );
1728
+                $response['error'] = wp_sprintf(__('%s number not validated', 'invoicing'), $vat_name);
1729
+                wp_send_json($response);
1730 1730
             }
1731 1731
             
1732 1732
             $response['success'] = true;
1733
-            $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1733
+            $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1734 1734
         } else {
1735
-            $result = self::check_vat( $vat_number );
1735
+            $result = self::check_vat($vat_number);
1736 1736
             
1737
-            if ( empty( $result['valid'] ) ) {
1737
+            if (empty($result['valid'])) {
1738 1738
                 $response['error'] = $result['message'];
1739
-                wp_send_json( $response );
1739
+                wp_send_json($response);
1740 1740
             }
1741 1741
             
1742
-            $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1743
-            $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1742
+            $vies_company = !empty($result['company']) ? $result['company'] : '';
1743
+            $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1744 1744
             
1745
-            $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1745
+            $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1746 1746
 
1747
-            if ( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) {
1747
+            if (!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company) {
1748 1748
                 $response['success'] = true;
1749
-                $response['message'] = wp_sprintf( __( '%s number validated', 'invoicing' ), $vat_name );
1749
+                $response['message'] = wp_sprintf(__('%s number validated', 'invoicing'), $vat_name);
1750 1750
             } else {           
1751 1751
                 $vat_info['valid'] = false;
1752
-                $wpi_session->set( 'user_vat_data', $vat_info );
1752
+                $wpi_session->set('user_vat_data', $vat_info);
1753 1753
                 
1754 1754
                 $response['success'] = false;
1755
-                $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 );
1756
-                wp_send_json( $response );
1755
+                $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);
1756
+                wp_send_json($response);
1757 1757
             }
1758 1758
         }
1759 1759
         
1760
-        if ( $is_checkout ) {
1761
-            self::save_user_vat_details( $company, $vat_number );
1760
+        if ($is_checkout) {
1761
+            self::save_user_vat_details($company, $vat_number);
1762 1762
 
1763
-            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true );
1764
-            $wpi_session->set( 'user_vat_data', $vat_info );
1763
+            $vat_info = array('company' => $company, 'number' => $vat_number, 'valid' => true);
1764
+            $wpi_session->set('user_vat_data', $vat_info);
1765 1765
         }
1766 1766
 
1767
-        wp_send_json( $response );
1767
+        wp_send_json($response);
1768 1768
     }
1769 1769
     
1770 1770
     public static function ajax_vat_reset() {
@@ -1773,161 +1773,161 @@  discard block
 block discarded – undo
1773 1773
         $company    = is_user_logged_in() ? self::get_user_company() : '';
1774 1774
         $vat_number = self::get_user_vat_number();
1775 1775
         
1776
-        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false );
1777
-        $wpi_session->set( 'user_vat_data', $vat_info );
1776
+        $vat_info   = array('company' => $company, 'number' => $vat_number, 'valid' => false);
1777
+        $wpi_session->set('user_vat_data', $vat_info);
1778 1778
         
1779 1779
         $response                       = array();
1780 1780
         $response['success']            = true;
1781 1781
         $response['data']['company']    = $company;
1782 1782
         $response['data']['number']     = $vat_number;
1783 1783
         
1784
-        wp_send_json( $response );
1784
+        wp_send_json($response);
1785 1785
     }
1786 1786
     
1787
-    public static function checkout_vat_validate( $valid_data, $post ) {
1787
+    public static function checkout_vat_validate($valid_data, $post) {
1788 1788
         global $wpinv_options, $wpi_session;
1789 1789
         
1790
-        $vat_name  = __( self::get_vat_name(), 'invoicing' );
1790
+        $vat_name = __(self::get_vat_name(), 'invoicing');
1791 1791
         
1792
-        if ( !isset( $_POST['_wpi_nonce'] ) || !wp_verify_nonce( $_POST['_wpi_nonce'], 'vat_validation' ) ) {
1793
-            wpinv_set_error( 'vat_validation', wp_sprintf( __( "Invalid %s validation request.", 'invoicing' ), $vat_name ) );
1792
+        if (!isset($_POST['_wpi_nonce']) || !wp_verify_nonce($_POST['_wpi_nonce'], 'vat_validation')) {
1793
+            wpinv_set_error('vat_validation', wp_sprintf(__("Invalid %s validation request.", 'invoicing'), $vat_name));
1794 1794
             return;
1795 1795
         }
1796 1796
         
1797
-        $vat_saved = $wpi_session->get( 'user_vat_data' );
1798
-        $wpi_session->set( 'user_vat_data', null );
1797
+        $vat_saved = $wpi_session->get('user_vat_data');
1798
+        $wpi_session->set('user_vat_data', null);
1799 1799
         
1800 1800
         $invoice        = wpinv_get_invoice_cart();
1801 1801
         $amount         = $invoice->get_total();
1802
-        $is_digital     = self::invoice_has_digital_rule( $invoice );
1803
-        $no_vat         = !self::requires_vat( 0, false, $is_digital );
1802
+        $is_digital     = self::invoice_has_digital_rule($invoice);
1803
+        $no_vat         = !self::requires_vat(0, false, $is_digital);
1804 1804
         
1805
-        $company        = !empty( $_POST['wpinv_company'] ) ? $_POST['wpinv_company'] : null;
1806
-        $vat_number     = !empty( $_POST['wpinv_vat_number'] ) ? $_POST['wpinv_vat_number'] : null;
1807
-        $country        = !empty( $_POST['wpinv_country'] ) ? $_POST['wpinv_country'] : $invoice->country;
1808
-        if ( empty( $country ) ) {
1805
+        $company        = !empty($_POST['wpinv_company']) ? $_POST['wpinv_company'] : null;
1806
+        $vat_number     = !empty($_POST['wpinv_vat_number']) ? $_POST['wpinv_vat_number'] : null;
1807
+        $country        = !empty($_POST['wpinv_country']) ? $_POST['wpinv_country'] : $invoice->country;
1808
+        if (empty($country)) {
1809 1809
             $country = wpinv_default_billing_country();
1810 1810
         }
1811 1811
         
1812
-        if ( !$is_digital && $no_vat ) {
1812
+        if (!$is_digital && $no_vat) {
1813 1813
             return;
1814 1814
         }
1815 1815
             
1816
-        $vat_data           = array( 'company' => '', 'number' => '', 'valid' => false );
1816
+        $vat_data           = array('company' => '', 'number' => '', 'valid' => false);
1817 1817
         
1818 1818
         $ip_country_code    = self::get_country_by_ip();
1819
-        $is_eu_state        = self::is_eu_state( $country );
1820
-        $is_eu_state_ip     = self::is_eu_state( $ip_country_code );
1819
+        $is_eu_state        = self::is_eu_state($country);
1820
+        $is_eu_state_ip     = self::is_eu_state($ip_country_code);
1821 1821
         $is_non_eu_user     = !$is_eu_state && !$is_eu_state_ip;
1822 1822
         
1823
-        if ( $is_digital && !$is_non_eu_user && empty( $vat_number ) && apply_filters( 'wpinv_checkout_requires_country', true, $amount ) ) {
1823
+        if ($is_digital && !$is_non_eu_user && empty($vat_number) && apply_filters('wpinv_checkout_requires_country', true, $amount)) {
1824 1824
             $vat_data['adddress_confirmed'] = false;
1825 1825
             
1826
-            if ( !isset( $_POST['wpinv_adddress_confirmed'] ) ) {
1827
-                if ( $ip_country_code != $country ) {
1828
-                    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>' ) );
1826
+            if (!isset($_POST['wpinv_adddress_confirmed'])) {
1827
+                if ($ip_country_code != $country) {
1828
+                    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>'));
1829 1829
                 }
1830 1830
             } else {
1831 1831
                 $vat_data['adddress_confirmed'] = true;
1832 1832
             }
1833 1833
         }
1834 1834
         
1835
-        if ( !empty( $wpinv_options['vat_prevent_b2c_purchase'] ) && !$is_non_eu_user && ( empty( $vat_number ) || $no_vat ) ) {
1836
-            if ( $is_eu_state ) {
1837
-                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 ) );
1838
-            } else if ( $is_digital && $is_eu_state_ip ) {
1839
-                wpinv_set_error( 'vat_validation', wp_sprintf( __( 'Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing' ), $vat_name ) );
1835
+        if (!empty($wpinv_options['vat_prevent_b2c_purchase']) && !$is_non_eu_user && (empty($vat_number) || $no_vat)) {
1836
+            if ($is_eu_state) {
1837
+                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));
1838
+            } else if ($is_digital && $is_eu_state_ip) {
1839
+                wpinv_set_error('vat_validation', wp_sprintf(__('Sales to non-EU countries cannot be completed because %s must be applied.', 'invoicing'), $vat_name));
1840 1840
             }
1841 1841
         }
1842 1842
         
1843
-        if ( !$is_eu_state || $no_vat || empty( $vat_number ) ) {
1843
+        if (!$is_eu_state || $no_vat || empty($vat_number)) {
1844 1844
             return;
1845 1845
         }
1846 1846
 
1847
-        if ( !empty( $vat_saved ) && isset( $vat_saved['valid'] ) ) {
1848
-            $vat_data['valid']  = $vat_saved['valid'];
1847
+        if (!empty($vat_saved) && isset($vat_saved['valid'])) {
1848
+            $vat_data['valid'] = $vat_saved['valid'];
1849 1849
         }
1850 1850
             
1851
-        if ( $company !== null ) {
1851
+        if ($company !== null) {
1852 1852
             $vat_data['company'] = $company;
1853 1853
         }
1854 1854
 
1855 1855
         $message = '';
1856
-        if ( $vat_number !== null ) {
1856
+        if ($vat_number !== null) {
1857 1857
             $vat_data['number'] = $vat_number;
1858 1858
             
1859
-            if ( !$vat_data['valid'] || ( $vat_saved['number'] !== $vat_data['number'] ) || ( $vat_saved['company'] !== $vat_data['company'] ) ) {
1860
-                if ( !empty( $wpinv_options['vat_vies_check'] ) ) {            
1861
-                    if ( empty( $wpinv_options['vat_offline_check'] ) && !self::offline_check( $vat_number ) ) {
1859
+            if (!$vat_data['valid'] || ($vat_saved['number'] !== $vat_data['number']) || ($vat_saved['company'] !== $vat_data['company'])) {
1860
+                if (!empty($wpinv_options['vat_vies_check'])) {            
1861
+                    if (empty($wpinv_options['vat_offline_check']) && !self::offline_check($vat_number)) {
1862 1862
                         $vat_data['valid'] = false;
1863 1863
                     }
1864 1864
                 } else {
1865
-                    $result = self::check_vat( $vat_number );
1865
+                    $result = self::check_vat($vat_number);
1866 1866
                     
1867
-                    if ( !empty( $result['valid'] ) ) {                
1867
+                    if (!empty($result['valid'])) {                
1868 1868
                         $vat_data['valid'] = true;
1869
-                        $vies_company = !empty( $result['company'] ) ? $result['company'] : '';
1870
-                        $vies_company = apply_filters( 'wpinv_vies_company_name', $vies_company );
1869
+                        $vies_company = !empty($result['company']) ? $result['company'] : '';
1870
+                        $vies_company = apply_filters('wpinv_vies_company_name', $vies_company);
1871 1871
                     
1872
-                        $valid_company = $vies_company && $company && ( $vies_company == '---' || strcasecmp( trim( $vies_company ), trim( $company ) ) == 0 ) ? true : false;
1872
+                        $valid_company = $vies_company && $company && ($vies_company == '---' || strcasecmp(trim($vies_company), trim($company)) == 0) ? true : false;
1873 1873
 
1874
-                        if ( !( !empty( $wpinv_options['vat_disable_company_name_check'] ) || $valid_company ) ) {         
1874
+                        if (!(!empty($wpinv_options['vat_disable_company_name_check']) || $valid_company)) {         
1875 1875
                             $vat_data['valid'] = false;
1876 1876
                             
1877
-                            $message = wp_sprintf( __( 'The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing' ), $vat_name );
1877
+                            $message = wp_sprintf(__('The company name associated with the %s number provided is not the same as the company name provided.', 'invoicing'), $vat_name);
1878 1878
                         }
1879 1879
                     } else {
1880
-                        $message = wp_sprintf( __( 'Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing' ), $vat_name );
1880
+                        $message = wp_sprintf(__('Fail to validate the %s number: EU Commission VAT server (VIES) check fails.', 'invoicing'), $vat_name);
1881 1881
                     }
1882 1882
                 }
1883 1883
                 
1884
-                if ( !$vat_data['valid'] ) {
1885
-                    $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 . ' )' : '' );
1886
-                    wpinv_set_error( 'vat_validation', $error );
1884
+                if (!$vat_data['valid']) {
1885
+                    $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 . ' )' : '');
1886
+                    wpinv_set_error('vat_validation', $error);
1887 1887
                 }
1888 1888
             }
1889 1889
         }
1890 1890
 
1891
-        $wpi_session->set( 'user_vat_data', $vat_data );
1891
+        $wpi_session->set('user_vat_data', $vat_data);
1892 1892
     }
1893 1893
     
1894
-    public static function checkout_vat_fields( $billing_details ) {
1894
+    public static function checkout_vat_fields($billing_details) {
1895 1895
         global $wpi_session, $wpinv_options, $wpi_country, $wpi_requires_vat;
1896 1896
         
1897 1897
         $ip_address         = wpinv_get_ip();
1898 1898
         $ip_country_code    = self::get_country_by_ip();
1899 1899
         
1900
-        $tax_label          = __( self::get_vat_name(), 'invoicing' );
1900
+        $tax_label          = __(self::get_vat_name(), 'invoicing');
1901 1901
         $invoice            = wpinv_get_invoice_cart();
1902
-        $is_digital         = self::invoice_has_digital_rule( $invoice );
1902
+        $is_digital         = self::invoice_has_digital_rule($invoice);
1903 1903
         $wpi_country        = $invoice->country;
1904 1904
         
1905
-        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat( 0, false, $is_digital );
1905
+        $requires_vat       = !self::hide_vat_fields() && !$invoice->is_free() && self::requires_vat(0, false, $is_digital);
1906 1906
         $wpi_requires_vat   = $requires_vat;
1907 1907
         
1908 1908
         $company            = self::get_user_company();
1909 1909
         $vat_number         = self::get_user_vat_number();
1910 1910
         
1911
-        $validated          = $vat_number ? self::get_user_vat_number( '', 0, true ) : 1;
1912
-        $vat_info           = $wpi_session->get( 'user_vat_data' );
1911
+        $validated          = $vat_number ? self::get_user_vat_number('', 0, true) : 1;
1912
+        $vat_info           = $wpi_session->get('user_vat_data');
1913 1913
 
1914
-        if ( is_array( $vat_info ) ) {
1915
-            $company    = isset( $vat_info['company'] ) ? $vat_info['company'] : '';
1916
-            $vat_number = isset( $vat_info['number'] ) ? $vat_info['number'] : '';
1917
-            $validated  = isset( $vat_info['valid'] ) ? $vat_info['valid'] : false;
1914
+        if (is_array($vat_info)) {
1915
+            $company    = isset($vat_info['company']) ? $vat_info['company'] : '';
1916
+            $vat_number = isset($vat_info['number']) ? $vat_info['number'] : '';
1917
+            $validated  = isset($vat_info['valid']) ? $vat_info['valid'] : false;
1918 1918
         }
1919 1919
         
1920 1920
         $selected_country = $invoice->country ? $invoice->country : wpinv_default_billing_country();
1921 1921
 
1922
-        if ( $ip_country_code == 'UK' ) {
1922
+        if ($ip_country_code == 'UK') {
1923 1923
             $ip_country_code = 'GB';
1924 1924
         }
1925 1925
         
1926
-        if ( $selected_country == 'UK' ) {
1926
+        if ($selected_country == 'UK') {
1927 1927
             $selected_country = 'GB';
1928 1928
         }
1929 1929
         
1930
-        if ( $requires_vat && ( self::same_country_rule() == 'no' && wpinv_is_base_country( $selected_country ) || !self::allow_vat_rules() ) ) {
1930
+        if ($requires_vat && (self::same_country_rule() == 'no' && wpinv_is_base_country($selected_country) || !self::allow_vat_rules())) {
1931 1931
             $requires_vat = false;
1932 1932
         }
1933 1933
 
@@ -1935,52 +1935,52 @@  discard block
 block discarded – undo
1935 1935
         $display_validate_btn   = 'none';
1936 1936
         $display_reset_btn      = 'none';
1937 1937
         
1938
-        if ( !empty( $vat_number ) && $validated ) {
1939
-            $vat_vailidated_text    = wp_sprintf( __( '%s number validated', 'invoicing' ), $tax_label );
1938
+        if (!empty($vat_number) && $validated) {
1939
+            $vat_vailidated_text    = wp_sprintf(__('%s number validated', 'invoicing'), $tax_label);
1940 1940
             $vat_vailidated_class   = 'wpinv-vat-stat-1';
1941 1941
             $display_reset_btn      = 'block';
1942 1942
         } else {
1943
-            $vat_vailidated_text    = empty( $vat_number ) ? '' : wp_sprintf( __( '%s number not validated', 'invoicing' ), $tax_label );
1944
-            $vat_vailidated_class   = empty( $vat_number ) ? '' : 'wpinv-vat-stat-0';
1943
+            $vat_vailidated_text    = empty($vat_number) ? '' : wp_sprintf(__('%s number not validated', 'invoicing'), $tax_label);
1944
+            $vat_vailidated_class   = empty($vat_number) ? '' : 'wpinv-vat-stat-0';
1945 1945
             $display_validate_btn   = 'block';
1946 1946
         }
1947 1947
         
1948
-        $show_ip_country        = $is_digital && ( empty( $vat_number ) || !$requires_vat ) && $ip_country_code != $selected_country ? 'block' : 'none';
1948
+        $show_ip_country = $is_digital && (empty($vat_number) || !$requires_vat) && $ip_country_code != $selected_country ? 'block' : 'none';
1949 1949
         ?>
1950 1950
         <div id="wpi-vat-details" class="wpi-vat-details clearfix" style="display:<?php echo $display_vat_details; ?>">
1951 1951
             <div id="wpi_vat_info" class="clearfix panel panel-default">
1952
-                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf( __( '%s Details', 'invoicing' ), $tax_label );?></h3></div>
1952
+                <div class="panel-heading"><h3 class="panel-title"><?php echo wp_sprintf(__('%s Details', 'invoicing'), $tax_label); ?></h3></div>
1953 1953
                 <div id="wpinv-fields-box" class="panel-body">
1954 1954
                     <p id="wpi_show_vat_note">
1955
-                        <?php echo wp_sprintf( __( 'Validate your registered %s number to exclude tax.', 'invoicing' ), $tax_label ); ?>
1955
+                        <?php echo wp_sprintf(__('Validate your registered %s number to exclude tax.', 'invoicing'), $tax_label); ?>
1956 1956
                     </p>
1957 1957
                     <div id="wpi_vat_fields" class="wpi_vat_info">
1958 1958
                         <p class="wpi-cart-field wpi-col2 wpi-colf">
1959
-                            <label for="wpinv_company" class="wpi-label"><?php _e( 'Company Name', 'invoicing' );?></label>
1959
+                            <label for="wpinv_company" class="wpi-label"><?php _e('Company Name', 'invoicing'); ?></label>
1960 1960
                             <?php
1961
-                            echo wpinv_html_text( array(
1961
+                            echo wpinv_html_text(array(
1962 1962
                                     'id'            => 'wpinv_company',
1963 1963
                                     'name'          => 'wpinv_company',
1964 1964
                                     'value'         => $company,
1965 1965
                                     'class'         => 'wpi-input form-control',
1966
-                                    'placeholder'   => __( 'Company name', 'invoicing' ),
1967
-                                ) );
1966
+                                    'placeholder'   => __('Company name', 'invoicing'),
1967
+                                ));
1968 1968
                             ?>
1969 1969
                         </p>
1970 1970
                         <p class="wpi-cart-field wpi-col2 wpi-coll wpi-cart-field-vat">
1971
-                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf( __( '%s Number', 'invoicing' ), $tax_label );?></label>
1971
+                            <label for="wpinv_vat_number" class="wpi-label"><?php echo wp_sprintf(__('%s Number', 'invoicing'), $tax_label); ?></label>
1972 1972
                             <span id="wpinv_vat_number-wrap">
1973 1973
                                 <label for="wpinv_vat_number" class="wpinv-label"></label>
1974
-                                <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">
1975
-                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class;?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text;?></font></span>
1974
+                                <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">
1975
+                                <span class="wpinv-vat-stat <?php echo $vat_vailidated_class; ?>"><i class="fa"></i>&nbsp;<font><?php echo $vat_vailidated_text; ?></font></span>
1976 1976
                             </span>
1977 1977
                         </p>
1978 1978
                         <p class="wpi-cart-field wpi-col wpi-colf wpi-cart-field-actions">
1979
-                            <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>
1980
-                            <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>
1979
+                            <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>
1980
+                            <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 1981
                             <span class="wpi-vat-box wpi-vat-box-info"><span id="text"></span></span>
1982 1982
                             <span class="wpi-vat-box wpi-vat-box-error"><span id="text"></span></span>
1983
-                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce( 'vat_validation' ) ?>" />
1983
+                            <input type="hidden" name="_wpi_nonce" value="<?php echo wp_create_nonce('vat_validation') ?>" />
1984 1984
                         </p>
1985 1985
                     </div>
1986 1986
                 </div>
@@ -1994,32 +1994,32 @@  discard block
 block discarded – undo
1994 1994
                 </span>
1995 1995
             </div>
1996 1996
         </div>
1997
-        <?php if ( empty( $wpinv_options['hide_ip_address'] ) ) { 
1998
-            $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>';
1997
+        <?php if (empty($wpinv_options['hide_ip_address'])) { 
1998
+            $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 1999
         ?>
2000 2000
         <div class="wpi-ip-info clearfix panel panel-info">
2001 2001
             <div id="wpinv-fields-box" class="panel-body">
2002
-                <span><?php echo wp_sprintf( __( "Your IP address is: %s", 'invoicing' ), $ip_link ); ?></span>
2002
+                <span><?php echo wp_sprintf(__("Your IP address is: %s", 'invoicing'), $ip_link); ?></span>
2003 2003
             </div>
2004 2004
         </div>
2005 2005
         <?php }
2006 2006
     }
2007 2007
     
2008
-    public static function show_vat_notice( $invoice ) {
2009
-        if ( empty( $invoice ) ) {
2008
+    public static function show_vat_notice($invoice) {
2009
+        if (empty($invoice)) {
2010 2010
             return NULL;
2011 2011
         }
2012 2012
         
2013
-        $label      = wpinv_get_option( 'vat_invoice_notice_label' );
2014
-        $notice     = wpinv_get_option( 'vat_invoice_notice' );
2015
-        if ( $label || $notice ) {
2013
+        $label      = wpinv_get_option('vat_invoice_notice_label');
2014
+        $notice     = wpinv_get_option('vat_invoice_notice');
2015
+        if ($label || $notice) {
2016 2016
         ?>
2017 2017
         <div class="row wpinv-vat-notice">
2018 2018
             <div class="col-sm-12">
2019
-                <?php if ( $label ) { ?>
2020
-                <strong><?php _e( $label, 'invoicing' ); ?></strong>
2021
-                <?php } if ( $notice ) { ?>
2022
-                <?php echo wpautop( wptexturize( __( $notice, 'invoicing' ) ) ) ?>
2019
+                <?php if ($label) { ?>
2020
+                <strong><?php _e($label, 'invoicing'); ?></strong>
2021
+                <?php } if ($notice) { ?>
2022
+                <?php echo wpautop(wptexturize(__($notice, 'invoicing'))) ?>
2023 2023
                 <?php } ?>
2024 2024
             </div>
2025 2025
         </div>
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 1 patch
Spacing   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-5">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-5">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-3">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-5">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,192 +83,192 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
 
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
 
104 104
         $errors = wpinv_get_errors();
105 105
 
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
 
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
 
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
 
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
 
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
 
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
 
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
 
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
 
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
 
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
 
160 160
             try {
161 161
 
162
-                if ( $is_recurring ) {
162
+                if ($is_recurring) {
163 163
                     $trx_type = wpinv_get_option('authorizenet_transaction_type_recurring', 'authorize_only');
164
-                    if('authorize_capture' == $trx_type){
164
+                    if ('authorize_capture' == $trx_type) {
165 165
                         $response = $authorizeAIM->authorizeAndCapture();
166 166
                     } else {
167 167
                         $response = $authorizeAIM->authorizeOnly();
168 168
                     }
169 169
                 } else {
170 170
                     $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture');
171
-                    if('authorize_capture' == $trx_type){
171
+                    if ('authorize_capture' == $trx_type) {
172 172
                         $response = $authorizeAIM->authorizeAndCapture();
173 173
                     } else {
174 174
                         $response = $authorizeAIM->authorizeOnly();
175 175
                     }
176 176
                 }
177 177
 
178
-                if ( $response->approved || $response->held ) {
179
-                    if ( $response->approved ) {
180
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
178
+                if ($response->approved || $response->held) {
179
+                    if ($response->approved) {
180
+                        wpinv_update_payment_status($invoice_id, 'publish');
181 181
                     }
182
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
182
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
183 183
 
184
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true );
185
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true );
184
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true);
185
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true);
186 186
 
187
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
187
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
188 188
 
189 189
                     wpinv_clear_errors();
190 190
                     wpinv_empty_cart();
191 191
 
192
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
192
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
193 193
                 } else {
194
-                    if ( !empty( $response->response_reason_text ) ) {
195
-                        $error = __( $response->response_reason_text, 'invoicing' );
196
-                    } else if ( !empty( $response->error_message ) ) {
197
-                        $error = __( $response->error_message, 'invoicing' );
194
+                    if (!empty($response->response_reason_text)) {
195
+                        $error = __($response->response_reason_text, 'invoicing');
196
+                    } else if (!empty($response->error_message)) {
197
+                        $error = __($response->error_message, 'invoicing');
198 198
                     } else {
199
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
199
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
200 200
                     } 
201 201
 
202
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
202
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
203 203
 
204
-                    wpinv_set_error( 'payment_error', $error );
205
-                    wpinv_record_gateway_error( $error, $response );
206
-                    wpinv_insert_payment_note( $invoice_id, $error, '', '', true );
204
+                    wpinv_set_error('payment_error', $error);
205
+                    wpinv_record_gateway_error($error, $response);
206
+                    wpinv_insert_payment_note($invoice_id, $error, '', '', true);
207 207
 
208
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
208
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
209 209
                 }
210
-            } catch ( AuthorizeNetException $e ) {
211
-                wpinv_set_error( 'request_error', $e->getMessage() );
212
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
213
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
210
+            } catch (AuthorizeNetException $e) {
211
+                wpinv_set_error('request_error', $e->getMessage());
212
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
213
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
214 214
             }
215 215
         } else {
216
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
216
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
217 217
         }
218 218
     } else {
219
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
220
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
219
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
220
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
221 221
     }
222 222
 }
223
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
223
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
224 224
 
225
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
226
-    if ( empty( $subscription_id ) ) {
225
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
226
+    if (empty($subscription_id)) {
227 227
         return false;
228 228
     }
229 229
 
230 230
     try {
231 231
         $authnetXML = wpinv_authorizenet_XML();
232
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
232
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
233 233
         return $authnetXML->isSuccessful();
234
-    } catch( Exception $e ) {
235
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
234
+    } catch (Exception $e) {
235
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
236 236
     }
237 237
 
238 238
     return false;
239 239
 }
240 240
 
241
-function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) {
242
-    if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) {
243
-        return wpinv_authorizenet_cancel_subscription( $subscription->profile_id );
241
+function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) {
242
+    if (!empty($valid) && !empty($subscription->profile_id)) {
243
+        return wpinv_authorizenet_cancel_subscription($subscription->profile_id);
244 244
     }
245 245
     
246 246
     return false;
247 247
 }
248
-add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 );
248
+add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2);
249 249
 
250
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
251
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
252
-    if ( empty( $authorizenet_md5_hash ) ) {
250
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
251
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
252
+    if (empty($authorizenet_md5_hash)) {
253 253
         return true;
254 254
     }
255 255
 
256
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
256
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
257 257
 
258
-    return hash_equals( $compare_md5, $md5_hash );
258
+    return hash_equals($compare_md5, $md5_hash);
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_AIM() {
262
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
262
+    if (!class_exists('AuthorizeNetException')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
264 264
     }
265 265
 
266
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
266
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
267 267
 
268
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
269
-        $authorizeAIM->setSandbox( true );
268
+    if (wpinv_is_test_mode('authorizenet')) {
269
+        $authorizeAIM->setSandbox(true);
270 270
     } else {
271
-        $authorizeAIM->setSandbox( false );
271
+        $authorizeAIM->setSandbox(false);
272 272
     }
273 273
 
274 274
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -277,250 +277,250 @@  discard block
 block discarded – undo
277 277
 }
278 278
 
279 279
 function wpinv_authorizenet_XML() {
280
-    if ( !class_exists( 'AuthnetXML' ) ) {
281
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
280
+    if (!class_exists('AuthnetXML')) {
281
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
282 282
     }
283 283
     
284
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
284
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
285 285
     
286 286
     return $authnetXML;
287 287
 }
288 288
 
289
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
290
-    if ( empty( $response ) || empty( $invoice ) ) {
289
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
290
+    if (empty($response) || empty($invoice)) {
291 291
         return false;
292 292
     }
293 293
 
294
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
295
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
294
+    if ($invoice->is_recurring() && !empty($response->approved)) {
295
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
296 296
         $success = false;
297
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
297
+        if (wpinv_is_test_mode('authorizenet')) {
298 298
             $success = true;
299 299
         } else {
300 300
             $success = $subscription->isSuccessful();
301 301
         }
302 302
 
303
-        if ( !empty( $subscription ) && $success ) {
304
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
303
+        if (!empty($subscription) && $success) {
304
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
305 305
 
306
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
306
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
307 307
 
308
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
308
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
309 309
         } else {
310
-            if ( isset( $subscription->messages->message ) ) {
310
+            if (isset($subscription->messages->message)) {
311 311
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
312
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
312
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
313 313
             } else {
314
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
315
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
314
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
315
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
316 316
             }
317 317
 
318
-            wpinv_record_gateway_error( $error, $subscription );
318
+            wpinv_record_gateway_error($error, $subscription);
319 319
 
320
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true );
320
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true);
321 321
         }
322 322
     }
323 323
 }
324
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
324
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
325 325
 
326
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
327
-    if ( empty( $invoice ) ) {
326
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
327
+    if (empty($invoice)) {
328 328
         return false;
329 329
     }
330 330
 
331
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
331
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
332 332
 
333 333
     try {
334 334
         $authnetXML = wpinv_authorizenet_XML();
335
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
336
-    } catch( Exception $e ) {
335
+        $authnetXML->ARBCreateSubscriptionRequest($params);
336
+    } catch (Exception $e) {
337 337
         $authnetXML = array();
338
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
338
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
339 339
     }
340 340
 
341 341
     return $authnetXML;
342 342
 }
343 343
 
344
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
345
-    if ( empty( $invoice ) ) {
344
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
345
+    if (empty($invoice)) {
346 346
         return false;
347 347
     }
348 348
 
349
-    $subscription_item = $invoice->get_recurring( true );
350
-    if ( empty( $subscription_item->ID ) ) {
349
+    $subscription_item = $invoice->get_recurring(true);
350
+    if (empty($subscription_item->ID)) {
351 351
         return false;
352 352
     }
353 353
 
354
-    $item = $invoice->get_recurring( true );
354
+    $item = $invoice->get_recurring(true);
355 355
 
356
-    if ( empty( $item ) ) {
356
+    if (empty($item)) {
357 357
         $name = '';
358 358
     }
359 359
 
360
-    if ( !( $name = $item->get_name() ) ) {
360
+    if (!($name = $item->get_name())) {
361 361
         $name = $item->post_name;
362 362
     }
363 363
 
364
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
364
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
365 365
     $subscription_name  = $invoice->get_subscription_name();
366
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
367
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
366
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
367
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
368 368
     $interval           = $subscription_item->get_recurring_interval();
369 369
     $period             = $subscription_item->get_recurring_period();
370 370
     $bill_times         = (int)$subscription_item->get_recurring_limit();
371 371
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
372 372
 
373
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
373
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
374 374
     $interval           = $time_period['interval'];
375 375
     $period             = $time_period['period'];
376 376
 
377 377
     $current_tz = date_default_timezone_get();
378
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
379
-    $today = date( 'Y-m-d' );
380
-    date_default_timezone_set( $current_tz );
378
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
379
+    $today = date('Y-m-d');
380
+    date_default_timezone_set($current_tz);
381 381
 
382 382
     $free_trial = $invoice->is_free_trial();
383
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
383
+    if ($free_trial && $subscription_item->has_free_trial()) {
384 384
         $trial_interval    = $subscription_item->get_trial_interval();
385
-        $trial_period      = $subscription_item->get_trial_period( true );
385
+        $trial_period      = $subscription_item->get_trial_period(true);
386 386
     }
387 387
 
388 388
     $subscription = array();
389 389
     $subscription['name'] = $subscription_name;
390 390
 
391 391
     $subscription['paymentSchedule'] = array(
392
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
392
+        'interval'         => array('length' => $interval, 'unit' => $period),
393 393
         'startDate'        => $today,
394 394
         'totalOccurrences' => $bill_times,
395
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
395
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
396 396
     );
397 397
 
398 398
     $subscription['amount'] = $recurring_amount;
399 399
     $subscription['trialAmount'] = $initial_amount;
400
-    $subscription['payment'] = array( 'creditCard' => $card_details );
401
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
402
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
400
+    $subscription['payment'] = array('creditCard' => $card_details);
401
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
402
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
403 403
 
404 404
     $subscription['billTo'] = array(
405 405
         'firstName' => $invoice->get_first_name(),
406 406
         'lastName'  => $invoice->get_last_name(),
407 407
         'company'   => $invoice->company,
408
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
408
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
409 409
         'city'      => $invoice->city,
410 410
         'state'     => $invoice->state,
411 411
         'zip'       => $invoice->zip,
412 412
         'country'   => $invoice->country,
413 413
     );
414 414
 
415
-    $params = array( 'subscription' => $subscription );
415
+    $params = array('subscription' => $subscription);
416 416
 
417
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
417
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
418 418
 }
419 419
 
420
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
421
-    $card_defaults      = array(
420
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
421
+    $card_defaults = array(
422 422
         'cc_owner'          => null,
423 423
         'cc_number'         => null,
424 424
         'cc_expire_month'   => null,
425 425
         'cc_expire_year'    => null,
426 426
         'cc_cvv2'           => null,
427 427
     );
428
-    $card_info = wp_parse_args( $card_info, $card_defaults );
428
+    $card_info = wp_parse_args($card_info, $card_defaults);
429 429
 
430 430
     $card_details = array(
431
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
432
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
433
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
431
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
432
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
433
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
434 434
     );
435 435
 
436 436
     return $card_details;
437 437
 }
438 438
 
439
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
440
-    $parent_invoice_id = absint( $invoice->ID );
439
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
440
+    $parent_invoice_id = absint($invoice->ID);
441 441
 
442
-    if( empty( $parent_invoice_id ) ) {
442
+    if (empty($parent_invoice_id)) {
443 443
         return;
444 444
     }
445 445
 
446
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
447
-    if ( empty( $invoice ) ) {
446
+    $invoice = wpinv_get_invoice($parent_invoice_id);
447
+    if (empty($invoice)) {
448 448
         return;
449 449
     }
450 450
 
451 451
     $subscriptionId     = (array)$subscription->subscriptionId;
452
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
452
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
453 453
 
454
-    $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id );
454
+    $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id);
455 455
 
456
-    if ( false === $subscription ) {
456
+    if (false === $subscription) {
457 457
         return;
458 458
     }
459 459
 
460 460
     // Set payment to complete
461
-    wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' );
461
+    wpinv_update_payment_status($subscription->parent_payment_id, 'publish');
462 462
     sleep(1);
463
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true );
464
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id);
463
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true);
464
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id);
465 465
 
466 466
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
467
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
468
-    $created    = date_i18n( 'Y-m-d H:i:s' );
469
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
467
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
468
+    $created    = date_i18n('Y-m-d H:i:s');
469
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
470 470
 
471 471
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
472
-    $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
472
+    $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration));
473 473
 }
474 474
 
475
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
476
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
475
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
476
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
477 477
         $error = false;
478 478
         
479
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
479
+        if (empty($post['authorizenet']['cc_owner'])) {
480 480
             $error = true;
481
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
481
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
482 482
         }
483
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
483
+        if (empty($post['authorizenet']['cc_number'])) {
484 484
             $error = true;
485
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
485
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
486 486
         }
487
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
487
+        if (empty($post['authorizenet']['cc_expire_month'])) {
488 488
             $error = true;
489
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
489
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
490 490
         }
491
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
491
+        if (empty($post['authorizenet']['cc_expire_year'])) {
492 492
             $error = true;
493
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
493
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
494 494
         }
495
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
495
+        if (empty($post['authorizenet']['cc_cvv2'])) {
496 496
             $error = true;
497
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
497
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
498 498
         }
499 499
 
500
-        if ( $error ) {
500
+        if ($error) {
501 501
             return;
502 502
         }
503 503
 
504 504
         $invoice = wpinv_get_invoice_cart();
505 505
 
506
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
507
-            $subscription_item = $invoice->get_recurring( true );
506
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
507
+            $subscription_item = $invoice->get_recurring(true);
508 508
 
509 509
             $interval   = $subscription_item->get_recurring_interval();
510 510
             $period     = $subscription_item->get_recurring_period();
511 511
 
512
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
513
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
512
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
513
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
514 514
             }
515 515
         }
516 516
     }
517 517
 }
518
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
518
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
519 519
 
520
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
521
-    $subscription_interval = absint( $subscription_interval );
520
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
521
+    $subscription_interval = absint($subscription_interval);
522 522
 
523
-    switch( $subscription_period ) {
523
+    switch ($subscription_period) {
524 524
         case 'W':
525 525
         case 'week':
526 526
         case 'weeks':
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
         case 'M':
531 531
         case 'month':
532 532
         case 'months':
533
-            if ( $subscription_interval > 12 ) {
533
+            if ($subscription_interval > 12) {
534 534
                 $subscription_interval = 12;
535 535
             }
536 536
 
537 537
             $interval = $subscription_interval;
538 538
             $period   = 'months';
539 539
             
540
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
540
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
541 541
                 $interval = $subscription_interval * 30;
542 542
                 $period   = 'days';
543 543
             }
@@ -554,30 +554,30 @@  discard block
 block discarded – undo
554 554
             break;
555 555
     }
556 556
 
557
-    return compact( 'interval', 'period' );
557
+    return compact('interval', 'period');
558 558
 }
559 559
 
560 560
 function wpinv_authorizenet_process_ipn() {
561
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
561
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
562 562
         return;
563 563
     }
564 564
 
565
-    $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false;
565
+    $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false;
566 566
 
567
-    if ( $subscription_id ) {
568
-        $response_code  = intval( $_POST['x_response_code'] );
569
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
567
+    if ($subscription_id) {
568
+        $response_code  = intval($_POST['x_response_code']);
569
+        $reason_code    = intval($_POST['x_response_reason_code']);
570 570
 
571
-        $subscription = new WPInv_Subscription( $subscription_id, true );
571
+        $subscription = new WPInv_Subscription($subscription_id, true);
572 572
 
573
-        if ( !$subscription->id ) {
573
+        if (!$subscription->id) {
574 574
             return;
575 575
         }
576 576
 
577
-        if ( 1 == $response_code ) {
577
+        if (1 == $response_code) {
578 578
             // Approved
579
-            $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
580
-            $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
579
+            $transaction_id = sanitize_text_field($_POST['x_trans_id']);
580
+            $renewal_amount = sanitize_text_field($_POST['x_amount']);
581 581
 
582 582
             $args = array(
583 583
                 'amount'         => $renewal_amount,
@@ -585,63 +585,63 @@  discard block
 block discarded – undo
585 585
                 'gateway'        => 'authorizenet'
586 586
             );
587 587
 
588
-            $subscription->add_payment( $args );
588
+            $subscription->add_payment($args);
589 589
             $subscription->renew();
590 590
 
591
-            do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription );
592
-            do_action( 'wpinv_authorizenet_renewal_payment', $subscription );
593
-        } else if ( 2 == $response_code ) {
591
+            do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription);
592
+            do_action('wpinv_authorizenet_renewal_payment', $subscription);
593
+        } else if (2 == $response_code) {
594 594
             // Declined
595 595
             $subscription->failing();
596
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
597
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
598
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
596
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
597
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
598
+        } else if (3 == $response_code || 8 == $reason_code) {
599 599
             // An expired card
600 600
             $subscription->failing();
601
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
602
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
601
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
602
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
603 603
         } else {
604 604
             // Other Error
605
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
605
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
606 606
         }
607 607
 
608 608
         exit;
609 609
     }
610 610
 }
611
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
611
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
612 612
 
613 613
 /**
614 614
  * Retrieve the subscription
615 615
  */
616
-function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) {
617
-    $parent_invoice_id = absint( $invoice_id );
616
+function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) {
617
+    $parent_invoice_id = absint($invoice_id);
618 618
 
619
-    if ( empty( $subscription_data ) ) {
619
+    if (empty($subscription_data)) {
620 620
         return false;
621 621
     }
622 622
 
623
-    if ( empty( $parent_invoice_id ) ) {
623
+    if (empty($parent_invoice_id)) {
624 624
         return false;
625 625
     }
626 626
 
627
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
628
-    if ( empty( $invoice ) ) {
627
+    $invoice = wpinv_get_invoice($parent_invoice_id);
628
+    if (empty($invoice)) {
629 629
         return false;
630 630
     }
631 631
 
632 632
     $subscriptionId     = (array)$subscription_data->subscriptionId;
633
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
633
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
634 634
 
635
-    $subscription = new WPInv_Subscription( $subscription_id, true );
635
+    $subscription = new WPInv_Subscription($subscription_id, true);
636 636
 
637
-    if ( ! $subscription || $subscription->id < 1 ) {
637
+    if (!$subscription || $subscription->id < 1) {
638 638
         $subs_db      = new WPInv_Subscriptions_DB;
639
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) );
640
-        $subscription = reset( $subs );
639
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1));
640
+        $subscription = reset($subs);
641 641
 
642
-        if ( $subscription && $subscription->id > 0 ) {
642
+        if ($subscription && $subscription->id > 0) {
643 643
             // Update the profile ID so it is set for future renewals
644
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) );
644
+            $subscription->update(array('profile_id' => sanitize_text_field($subscription_id)));
645 645
         } else {
646 646
             // No subscription found with a matching payment ID, bail
647 647
             return false;
@@ -652,67 +652,67 @@  discard block
 block discarded – undo
652 652
 }
653 653
 
654 654
 function wpinv_is_authorizenet_valid_for_use() {
655
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) );
655
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR')));
656 656
 }
657
-function wpinv_check_authorizenet_currency_support( $gateway_list ) {
658
-    if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) {
659
-        unset( $gateway_list['authorizenet'] );
657
+function wpinv_check_authorizenet_currency_support($gateway_list) {
658
+    if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) {
659
+        unset($gateway_list['authorizenet']);
660 660
     }
661 661
     return $gateway_list;
662 662
 }
663
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
663
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1);
664 664
 
665
-function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
666
-    if ( $transaction_id == $invoice_id ) {
665
+function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) {
666
+    if ($transaction_id == $invoice_id) {
667 667
         $link = $transaction_id;
668 668
     } else {
669
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
669
+        if (!empty($invoice) && !empty($invoice->mode)) {
670 670
             $mode = $invoice->mode;
671 671
         } else {
672
-            $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live';
672
+            $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live';
673 673
         }
674 674
 
675 675
         $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/';
676 676
         $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id;
677 677
 
678
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>';
678
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>';
679 679
     }
680 680
 
681
-    return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice );
681
+    return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice);
682 682
 }
683
-add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 );
683
+add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3);
684 684
 
685
-function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) {
686
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
687
-        $invoice = wpinv_get_invoice( $invoice_id );
685
+function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) {
686
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
687
+        $invoice = wpinv_get_invoice($invoice_id);
688 688
 
689
-        if ( ! empty( $invoice ) ) {
690
-            return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice );
689
+        if (!empty($invoice)) {
690
+            return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice);
691 691
         }        
692 692
     }
693 693
     
694 694
     return $transaction_id;
695 695
 }
696
-add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 );
696
+add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2);
697 697
 
698
-function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) {
698
+function wpinv_authorizenet_profile_id_link($profile_id, $subscription) {
699 699
     $link = $profile_id;
700 700
 
701
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
702
-        $invoice = wpinv_get_invoice( $invoice_id );
701
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
702
+        $invoice = wpinv_get_invoice($invoice_id);
703 703
 
704
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
704
+        if (!empty($invoice) && !empty($invoice->mode)) {
705 705
             $mode = $invoice->mode;
706 706
         } else {
707
-            $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live';
707
+            $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live';
708 708
         }
709 709
 
710 710
         $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/';
711 711
         $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id;
712 712
 
713
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
713
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
714 714
     }
715 715
     
716
-    return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription );
716
+    return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription);
717 717
 }
718
-add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 );
719 718
\ No newline at end of file
719
+add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2);
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
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,137 +417,137 @@  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
         'options'     => array(
537
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
538
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
537
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
538
+            'authorize_only' => __('Authorize Only', 'invoicing'),
539 539
         ),
540 540
         'std'         => 'authorize_capture'
541 541
     );
542 542
 
543 543
     $setting['authorizenet_transaction_type_recurring'] = array(
544 544
         'id'          => 'authorizenet_transaction_type_recurring',
545
-        'name'        => __( 'Transaction Type for Recurring', 'invoicing' ),
546
-        'desc'        => __( 'Choose transaction type for recurring payments.', 'invoicing' ),
545
+        'name'        => __('Transaction Type for Recurring', 'invoicing'),
546
+        'desc'        => __('Choose transaction type for recurring payments.', 'invoicing'),
547 547
         'type'        => 'select',
548 548
         'options'     => array(
549
-            'authorize_capture' => __( 'Authorize And Capture', 'invoicing' ),
550
-            'authorize_only' => __( 'Authorize Only', 'invoicing' ),
549
+            'authorize_capture' => __('Authorize And Capture', 'invoicing'),
550
+            'authorize_only' => __('Authorize Only', 'invoicing'),
551 551
         ),
552 552
         'std'         => 'authorize_only'
553 553
     );
@@ -555,9 +555,9 @@  discard block
 block discarded – undo
555 555
     $setting['authorizenet_ipn_url'] = array(
556 556
             'type' => 'ipn_url',
557 557
             'id'   => 'authorizenet_ipn_url',
558
-            'name' => __( 'Silent Post URL', 'invoicing' ),
559
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
560
-            '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' ),
558
+            'name' => __('Silent Post URL', 'invoicing'),
559
+            'std' => wpinv_get_ipn_url('authorizenet'),
560
+            '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'),
561 561
             'size' => 'large',
562 562
             'custom' => 'authorizenet',
563 563
             'readonly' => true
@@ -565,26 +565,26 @@  discard block
 block discarded – undo
565 565
         
566 566
     return $setting;
567 567
 }
568
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
568
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
569 569
 
570 570
 // Worldpay settings
571
-function wpinv_gateway_settings_worldpay( $setting ) {
572
-    $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' );
573
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing' );
571
+function wpinv_gateway_settings_worldpay($setting) {
572
+    $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');
573
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process Credit card / Debit card transactions.', 'invoicing');
574 574
     
575 575
     $setting['worldpay_sandbox'] = array(
576 576
             'type' => 'checkbox',
577 577
             'id'   => 'worldpay_sandbox',
578
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
579
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
578
+            'name' => __('Worldpay Test Mode', 'invoicing'),
579
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
580 580
             'std'  => 1
581 581
         );
582 582
         
583 583
     $setting['worldpay_instId'] = array(
584 584
             'type' => 'text',
585 585
             'id'   => 'worldpay_instId',
586
-            'name' => __( 'Installation Id', 'invoicing' ),
587
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
586
+            'name' => __('Installation Id', 'invoicing'),
587
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
588 588
             'std' => '211616',
589 589
         );
590 590
     /*
@@ -600,9 +600,9 @@  discard block
 block discarded – undo
600 600
     $setting['worldpay_ipn_url'] = array(
601 601
             'type' => 'ipn_url',
602 602
             'id'   => 'worldpay_ipn_url',
603
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
604
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
605
-            '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>' ),
603
+            'name' => __('Worldpay Callback Url', 'invoicing'),
604
+            'std' => wpinv_get_ipn_url('worldpay'),
605
+            '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>'),
606 606
             'size' => 'large',
607 607
             'custom' => 'worldpay',
608 608
             'readonly' => true
@@ -610,99 +610,99 @@  discard block
 block discarded – undo
610 610
         
611 611
     return $setting;
612 612
 }
613
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
613
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
614 614
 
615
-function wpinv_ipn_url_callback( $args ) {    
616
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
615
+function wpinv_ipn_url_callback($args) {    
616
+    $sanitize_id = wpinv_sanitize_key($args['id']);
617 617
     
618 618
     $attrs = $args['readonly'] ? ' readonly' : '';
619 619
 
620
-    $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">';
621
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
620
+    $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">';
621
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
622 622
 
623 623
     echo $html;
624 624
 }
625 625
 
626
-function wpinv_is_test_mode( $gateway = '' ) {
627
-    if ( empty( $gateway ) ) {
626
+function wpinv_is_test_mode($gateway = '') {
627
+    if (empty($gateway)) {
628 628
         return false;
629 629
     }
630 630
     
631
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
631
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
632 632
     
633
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
633
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
634 634
 }
635 635
 
636
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
637
-    $data = array( 'wpi-listener' => 'IPN' );
636
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
637
+    $data = array('wpi-listener' => 'IPN');
638 638
     
639
-    if ( !empty( $gateway ) ) {
640
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
639
+    if (!empty($gateway)) {
640
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
641 641
     }
642 642
     
643
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
643
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
644 644
     
645
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
645
+    $ipn_url = add_query_arg($args, home_url('index.php'));
646 646
     
647
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
647
+    return apply_filters('wpinv_ipn_url', $ipn_url);
648 648
 }
649 649
 
650 650
 function wpinv_listen_for_payment_ipn() {
651 651
     // Regular PayPal IPN
652
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
653
-        do_action( 'wpinv_verify_payment_ipn' );
652
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
653
+        do_action('wpinv_verify_payment_ipn');
654 654
         
655
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
656
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'WP Invoicing IPN', __FILE__, __LINE__ );
657
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
655
+        if (!empty($_GET['wpi-gateway'])) {
656
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'WP Invoicing IPN', __FILE__, __LINE__);
657
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
658 658
         }
659 659
     }
660 660
 }
661
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
661
+add_action('init', 'wpinv_listen_for_payment_ipn');
662 662
 
663 663
 function wpinv_get_bank_instructions() {
664
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
664
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
665 665
     
666
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
666
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
667 667
 }
668 668
 
669
-function wpinv_get_bank_info( $filtered = false ) {
669
+function wpinv_get_bank_info($filtered = false) {
670 670
     $bank_fields = array(
671
-        'bank_transfer_ac_name'     => __( 'Account Name', 'invoicing' ),
672
-        'bank_transfer_ac_no'       => __( 'Account Number', 'invoicing' ),
673
-        'bank_transfer_bank_name'   => __( 'Bank Name', 'invoicing' ),
674
-        'bank_transfer_ifsc'        => __( 'IFSC code', 'invoicing' ),
675
-        'bank_transfer_iban'        => __( 'IBAN', 'invoicing' ),
676
-        'bank_transfer_bic'         => __( 'BIC/Swift code', 'invoicing' ),
677
-        'bank_transfer_sort_code'   => __( 'Sort Code', 'invoicing' )
671
+        'bank_transfer_ac_name'     => __('Account Name', 'invoicing'),
672
+        'bank_transfer_ac_no'       => __('Account Number', 'invoicing'),
673
+        'bank_transfer_bank_name'   => __('Bank Name', 'invoicing'),
674
+        'bank_transfer_ifsc'        => __('IFSC code', 'invoicing'),
675
+        'bank_transfer_iban'        => __('IBAN', 'invoicing'),
676
+        'bank_transfer_bic'         => __('BIC/Swift code', 'invoicing'),
677
+        'bank_transfer_sort_code'   => __('Sort Code', 'invoicing')
678 678
     );
679 679
     
680 680
     $bank_info = array();
681
-    foreach ( $bank_fields as $field => $label ) {
682
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
681
+    foreach ($bank_fields as $field => $label) {
682
+        if ($filtered && !($value = wpinv_get_option($field))) {
683 683
             continue;
684 684
         }
685 685
         
686
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
686
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
687 687
     }
688 688
     
689
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
689
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
690 690
 }
691 691
 
692
-function wpinv_get_post_data( $method = 'request' ) {
692
+function wpinv_get_post_data($method = 'request') {
693 693
     $data       = array();
694 694
     $request    = $_REQUEST;
695 695
     
696
-    if ( $method == 'post' ) {
697
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
696
+    if ($method == 'post') {
697
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
698 698
             return $data;
699 699
         }
700 700
         
701 701
         $request = $_POST;
702 702
     }
703 703
     
704
-    if ( $method == 'get' ) {
705
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
704
+    if ($method == 'get') {
705
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
706 706
             return $data;
707 707
         }
708 708
         
@@ -713,11 +713,11 @@  discard block
 block discarded – undo
713 713
     $post_data = '';
714 714
     
715 715
     // Fallback just in case post_max_size is lower than needed
716
-    if ( ini_get( 'allow_url_fopen' ) ) {
717
-        $post_data = file_get_contents( 'php://input' );
716
+    if (ini_get('allow_url_fopen')) {
717
+        $post_data = file_get_contents('php://input');
718 718
     } else {
719 719
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
720
-        ini_set( 'post_max_size', '12M' );
720
+        ini_set('post_max_size', '12M');
721 721
     }
722 722
     // Start the encoded data collection with notification command
723 723
     $encoded_data = 'cmd=_notify-validate';
@@ -726,58 +726,58 @@  discard block
 block discarded – undo
726 726
     $arg_separator = wpinv_get_php_arg_separator_output();
727 727
 
728 728
     // Verify there is a post_data
729
-    if ( $post_data || strlen( $post_data ) > 0 ) {
729
+    if ($post_data || strlen($post_data) > 0) {
730 730
         // Append the data
731 731
         $encoded_data .= $arg_separator . $post_data;
732 732
     } else {
733 733
         // Check if POST is empty
734
-        if ( empty( $request ) ) {
734
+        if (empty($request)) {
735 735
             // Nothing to do
736 736
             return;
737 737
         } else {
738 738
             // Loop through each POST
739
-            foreach ( $request as $key => $value ) {
739
+            foreach ($request as $key => $value) {
740 740
                 // Encode the value and append the data
741
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
741
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
742 742
             }
743 743
         }
744 744
     }
745 745
 
746 746
     // Convert collected post data to an array
747
-    parse_str( $encoded_data, $data );
747
+    parse_str($encoded_data, $data);
748 748
 
749
-    foreach ( $data as $key => $value ) {
750
-        if ( false !== strpos( $key, 'amp;' ) ) {
751
-            $new_key = str_replace( '&amp;', '&', $key );
752
-            $new_key = str_replace( 'amp;', '&' , $new_key );
749
+    foreach ($data as $key => $value) {
750
+        if (false !== strpos($key, 'amp;')) {
751
+            $new_key = str_replace('&amp;', '&', $key);
752
+            $new_key = str_replace('amp;', '&', $new_key);
753 753
 
754
-            unset( $data[ $key ] );
755
-            $data[ $new_key ] = sanitize_text_field( $value );
754
+            unset($data[$key]);
755
+            $data[$new_key] = sanitize_text_field($value);
756 756
         }
757 757
     }
758 758
     
759 759
     return $data;
760 760
 }
761 761
 
762
-function wpinv_gateway_support_subscription( $gateway ) {
762
+function wpinv_gateway_support_subscription($gateway) {
763 763
     $return = false;
764 764
     
765
-    if ( wpinv_is_gateway_active( $gateway ) ) {
766
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
765
+    if (wpinv_is_gateway_active($gateway)) {
766
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
767 767
     }
768 768
     
769 769
     return $return;
770 770
 }
771 771
 
772
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
773
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
774
-        foreach ( $gateways as $gateway => $info ) {
775
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
776
-                unset( $gateways[$gateway] );
772
+function wpinv_payment_gateways_on_cart($gateways = array()) {
773
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
774
+        foreach ($gateways as $gateway => $info) {
775
+            if (!wpinv_gateway_support_subscription($gateway)) {
776
+                unset($gateways[$gateway]);
777 777
             }
778 778
         }
779 779
     }
780 780
     
781 781
     return $gateways;
782 782
 }
783
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
784 783
\ No newline at end of file
784
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
785 785
\ No newline at end of file
Please login to merge, or discard this patch.
vendor/ayecode/wp-super-duper/wp-super-duper.php 3 patches
Doc Comments   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -268,7 +268,7 @@  discard block
 block discarded – undo
268 268
 		 * @param string $id
269 269
 		 * @param string $search_for_id
270 270
 		 *
271
-		 * @return mixed
271
+		 * @return string
272 272
 		 */
273 273
 		public static function shortcode_button( $id = '', $search_for_id = '' ) {
274 274
 			ob_start();
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
 		 * Makes SD work with the siteOrigin page builder.
299 299
 		 *
300 300
 		 * @since 1.0.6
301
-		 * @return mixed
301
+		 * @return string
302 302
 		 */
303 303
 		public static function siteorigin_js() {
304 304
 			ob_start();
@@ -857,7 +857,7 @@  discard block
 block discarded – undo
857 857
 		/**
858 858
 		 * Gets some CSS for the widgets screen.
859 859
 		 *
860
-		 * @return mixed
860
+		 * @return string
861 861
 		 */
862 862
 		public function widget_css() {
863 863
 			ob_start();
@@ -897,7 +897,7 @@  discard block
 block discarded – undo
897 897
 		/**
898 898
 		 * Gets some JS for the widgets screen.
899 899
 		 *
900
-		 * @return mixed
900
+		 * @return string
901 901
 		 */
902 902
 		public function widget_js() {
903 903
 			ob_start();
@@ -1347,7 +1347,7 @@  discard block
 block discarded – undo
1347 1347
 		 *
1348 1348
 		 * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
1349 1349
 		 * @since 1.0.9 Save numbers as numbers and not strings.
1350
-		 * @return mixed
1350
+		 * @return string
1351 1351
 		 */
1352 1352
 		public function block() {
1353 1353
 			ob_start();
Please login to merge, or discard this patch.
Indentation   +1360 added lines, -1360 removed lines patch added patch discarded remove patch
@@ -1,141 +1,141 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 if ( ! class_exists( 'WP_Super_Duper' ) ) {
7 7
 
8 8
 
9
-	/**
10
-	 * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
11
-	 *
12
-	 * Should not be called direct but extended instead.
13
-	 *
14
-	 * Class WP_Super_Duper
15
-	 * @since 1.0.3 is_block_content_call() method added.
16
-	 * @since 1.0.3 Placeholder text will be shown for widget that return no block content.
17
-	 * @since 1.0.4 is_elementor_widget_output() method added.
18
-	 * @since 1.0.4 is_elementor_preview() method added.
19
-	 * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED
20
-	 * @since 1.0.6 Some refactoring for page builders - CHANGED
21
-	 * @since 1.0.7 Some refactoring for page builders - CHANGED
22
-	 * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED
23
-	 * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED
24
-	 * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED
25
-	 * @ver 1.0.10
26
-	 */
27
-	class WP_Super_Duper extends WP_Widget {
28
-
29
-		public $version = "1.0.10";
30
-		public $block_code;
31
-		public $options;
32
-		public $base_id;
33
-		public $arguments = array();
34
-		public $instance = array();
35
-		private $class_name;
36
-
37
-		/**
38
-		 * Take the array options and use them to build.
39
-		 */
40
-		public function __construct( $options ) {
41
-			global $sd_widgets;
42
-
43
-			$sd_widgets[ $options['base_id'] ] = array(
44
-				'name'       => $options['name'],
45
-				'class_name' => $options['class_name']
46
-			);
47
-			$this->base_id                     = $options['base_id'];
48
-			// lets filter the options before we do anything
49
-			$options       = apply_filters( "wp_super_duper_options", $options );
50
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
51
-			$options       = $this->add_name_from_key( $options );
52
-			$this->options = $options;
53
-
54
-			$this->base_id   = $options['base_id'];
55
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
56
-
57
-			// init parent
58
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
59
-
60
-			if ( isset( $options['class_name'] ) ) {
61
-				// register widget
62
-				$this->class_name = $options['class_name'];
63
-
64
-				// register shortcode
65
-				$this->register_shortcode();
66
-
67
-				// register block
68
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
69
-			}
70
-
71
-			// add the CSS and JS we need ONCE
72
-			global $sd_widget_scripts;
73
-
74
-			if ( ! $sd_widget_scripts ) {
75
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
76
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
77
-				wp_add_inline_style( 'widgets', $this->widget_css() );
78
-
79
-				$sd_widget_scripts = true;
80
-
81
-				// add shortcode insert button once
82
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
83
-				if ( $this->is_preview() ) {
84
-					add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
85
-					// this makes the insert button work for elementor
86
-					add_action( 'elementor/editor/after_enqueue_scripts', array(
87
-						$this,
88
-						'shortcode_insert_button_script'
89
-					) ); // for elementor
90
-				}
91
-				// this makes the insert button work for cornerstone
92
-				add_action( 'cornerstone_load_builder', array(
93
-					$this,
94
-					'shortcode_insert_button_script'
95
-				) ); // for cornerstone builder (this is the preview)
96
-
97
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
98
-				add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
99
-
100
-				// add generator text to admin head
101
-				add_action( 'admin_head', array( $this, 'generator' ) );
102
-			}
103
-
104
-			do_action( 'wp_super_duper_widget_init', $options, $this );
105
-		}
106
-
107
-		/**
108
-		 * A function to ge the shortcode builder picker html.
109
-		 *
110
-		 * @param string $editor_id
111
-		 *
112
-		 * @return string
113
-		 */
114
-		public static function get_picker( $editor_id = '' ) {
115
-
116
-			ob_start();
117
-			if ( isset( $_POST['editor_id'] ) ) {
118
-				$editor_id = esc_attr( $_POST['editor_id'] );
119
-			} elseif ( isset( $_REQUEST['et_fb'] ) ) {
120
-				$editor_id = 'main_content_content_vb_tiny_mce';
121
-			}
122
-
123
-			global $sd_widgets;
124
-			?>
9
+    /**
10
+     * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress.
11
+     *
12
+     * Should not be called direct but extended instead.
13
+     *
14
+     * Class WP_Super_Duper
15
+     * @since 1.0.3 is_block_content_call() method added.
16
+     * @since 1.0.3 Placeholder text will be shown for widget that return no block content.
17
+     * @since 1.0.4 is_elementor_widget_output() method added.
18
+     * @since 1.0.4 is_elementor_preview() method added.
19
+     * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED
20
+     * @since 1.0.6 Some refactoring for page builders - CHANGED
21
+     * @since 1.0.7 Some refactoring for page builders - CHANGED
22
+     * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED
23
+     * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED
24
+     * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED
25
+     * @ver 1.0.10
26
+     */
27
+    class WP_Super_Duper extends WP_Widget {
28
+
29
+        public $version = "1.0.10";
30
+        public $block_code;
31
+        public $options;
32
+        public $base_id;
33
+        public $arguments = array();
34
+        public $instance = array();
35
+        private $class_name;
36
+
37
+        /**
38
+         * Take the array options and use them to build.
39
+         */
40
+        public function __construct( $options ) {
41
+            global $sd_widgets;
42
+
43
+            $sd_widgets[ $options['base_id'] ] = array(
44
+                'name'       => $options['name'],
45
+                'class_name' => $options['class_name']
46
+            );
47
+            $this->base_id                     = $options['base_id'];
48
+            // lets filter the options before we do anything
49
+            $options       = apply_filters( "wp_super_duper_options", $options );
50
+            $options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
51
+            $options       = $this->add_name_from_key( $options );
52
+            $this->options = $options;
53
+
54
+            $this->base_id   = $options['base_id'];
55
+            $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
56
+
57
+            // init parent
58
+            parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
59
+
60
+            if ( isset( $options['class_name'] ) ) {
61
+                // register widget
62
+                $this->class_name = $options['class_name'];
63
+
64
+                // register shortcode
65
+                $this->register_shortcode();
66
+
67
+                // register block
68
+                add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
69
+            }
70
+
71
+            // add the CSS and JS we need ONCE
72
+            global $sd_widget_scripts;
73
+
74
+            if ( ! $sd_widget_scripts ) {
75
+                wp_add_inline_script( 'admin-widgets', $this->widget_js() );
76
+                wp_add_inline_script( 'customize-controls', $this->widget_js() );
77
+                wp_add_inline_style( 'widgets', $this->widget_css() );
78
+
79
+                $sd_widget_scripts = true;
80
+
81
+                // add shortcode insert button once
82
+                add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
83
+                if ( $this->is_preview() ) {
84
+                    add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
85
+                    // this makes the insert button work for elementor
86
+                    add_action( 'elementor/editor/after_enqueue_scripts', array(
87
+                        $this,
88
+                        'shortcode_insert_button_script'
89
+                    ) ); // for elementor
90
+                }
91
+                // this makes the insert button work for cornerstone
92
+                add_action( 'cornerstone_load_builder', array(
93
+                    $this,
94
+                    'shortcode_insert_button_script'
95
+                ) ); // for cornerstone builder (this is the preview)
96
+
97
+                add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
98
+                add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
99
+
100
+                // add generator text to admin head
101
+                add_action( 'admin_head', array( $this, 'generator' ) );
102
+            }
103
+
104
+            do_action( 'wp_super_duper_widget_init', $options, $this );
105
+        }
106
+
107
+        /**
108
+         * A function to ge the shortcode builder picker html.
109
+         *
110
+         * @param string $editor_id
111
+         *
112
+         * @return string
113
+         */
114
+        public static function get_picker( $editor_id = '' ) {
115
+
116
+            ob_start();
117
+            if ( isset( $_POST['editor_id'] ) ) {
118
+                $editor_id = esc_attr( $_POST['editor_id'] );
119
+            } elseif ( isset( $_REQUEST['et_fb'] ) ) {
120
+                $editor_id = 'main_content_content_vb_tiny_mce';
121
+            }
122
+
123
+            global $sd_widgets;
124
+            ?>
125 125
 
126 126
 			<div class="sd-shortcode-left-wrap">
127 127
 				<?php
128
-				asort( $sd_widgets );
129
-				if ( ! empty( $sd_widgets ) ) {
130
-					echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
131
-					echo "<option>" . __( 'Select shortcode' ) . "</option>";
132
-					foreach ( $sd_widgets as $shortcode => $class ) {
133
-						echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
134
-					}
135
-					echo "</select>";
136
-
137
-				}
138
-				?>
128
+                asort( $sd_widgets );
129
+                if ( ! empty( $sd_widgets ) ) {
130
+                    echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
131
+                    echo "<option>" . __( 'Select shortcode' ) . "</option>";
132
+                    foreach ( $sd_widgets as $shortcode => $class ) {
133
+                        echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
134
+                    }
135
+                    echo "</select>";
136
+
137
+                }
138
+                ?>
139 139
 				<div class="sd-shortcode-settings"></div>
140 140
 
141 141
 			</div>
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 					<?php if ( $editor_id != '' ) { ?>
147 147
 						<button class="button sd-insert-shortcode-button"
148 148
 						        onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) {
149
-							        echo "'" . $editor_id . "'";
150
-						        } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
149
+                                    echo "'" . $editor_id . "'";
150
+                                } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
151 151
 					<?php } ?>
152 152
 					<button class="button"
153 153
 					        onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button>
@@ -155,129 +155,129 @@  discard block
 block discarded – undo
155 155
 			</div>
156 156
 			<?php
157 157
 
158
-			$html = ob_get_clean();
159
-
160
-			if ( wp_doing_ajax() ) {
161
-				echo $html;
162
-				$should_die = true;
163
-
164
-				// some builder get the editor via ajax so we should not die on those ocasions
165
-				$dont_die = array(
166
-					'parent_tag',// WP Bakery
167
-					'avia_request' // enfold
168
-				);
169
-
170
-				foreach ( $dont_die as $request ) {
171
-					if ( isset( $_REQUEST[ $request ] ) ) {
172
-						$should_die = false;
173
-					}
174
-				}
175
-
176
-				if ( $should_die ) {
177
-					wp_die();
178
-				}
179
-
180
-			} else {
181
-				return $html;
182
-			}
183
-
184
-			return '';
185
-
186
-		}
187
-
188
-		/**
189
-		 * Output the version in the admin header.
190
-		 */
191
-		public function generator() {
192
-			echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />';
193
-		}
194
-
195
-		/**
196
-		 * Get widget settings.
197
-		 *
198
-		 * @since 1.0.0
199
-		 */
200
-		public static function get_widget_settings() {
201
-			global $sd_widgets;
202
-
203
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
204
-			if ( ! $shortcode ) {
205
-				wp_die();
206
-			}
207
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
208
-			if ( ! $widget_args ) {
209
-				wp_die();
210
-			}
211
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
212
-			if ( ! $class_name ) {
213
-				wp_die();
214
-			}
215
-
216
-			// invoke an instance method
217
-			$widget = new $class_name;
218
-
219
-			ob_start();
220
-			$widget->form( array() );
221
-			$form = ob_get_clean();
222
-			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
223
-			echo "<style>" . $widget->widget_css() . "</style>";
224
-			echo "<script>" . $widget->widget_js() . "</script>";
225
-			?>
158
+            $html = ob_get_clean();
159
+
160
+            if ( wp_doing_ajax() ) {
161
+                echo $html;
162
+                $should_die = true;
163
+
164
+                // some builder get the editor via ajax so we should not die on those ocasions
165
+                $dont_die = array(
166
+                    'parent_tag',// WP Bakery
167
+                    'avia_request' // enfold
168
+                );
169
+
170
+                foreach ( $dont_die as $request ) {
171
+                    if ( isset( $_REQUEST[ $request ] ) ) {
172
+                        $should_die = false;
173
+                    }
174
+                }
175
+
176
+                if ( $should_die ) {
177
+                    wp_die();
178
+                }
179
+
180
+            } else {
181
+                return $html;
182
+            }
183
+
184
+            return '';
185
+
186
+        }
187
+
188
+        /**
189
+         * Output the version in the admin header.
190
+         */
191
+        public function generator() {
192
+            echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />';
193
+        }
194
+
195
+        /**
196
+         * Get widget settings.
197
+         *
198
+         * @since 1.0.0
199
+         */
200
+        public static function get_widget_settings() {
201
+            global $sd_widgets;
202
+
203
+            $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
204
+            if ( ! $shortcode ) {
205
+                wp_die();
206
+            }
207
+            $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
208
+            if ( ! $widget_args ) {
209
+                wp_die();
210
+            }
211
+            $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
212
+            if ( ! $class_name ) {
213
+                wp_die();
214
+            }
215
+
216
+            // invoke an instance method
217
+            $widget = new $class_name;
218
+
219
+            ob_start();
220
+            $widget->form( array() );
221
+            $form = ob_get_clean();
222
+            echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
223
+            echo "<style>" . $widget->widget_css() . "</style>";
224
+            echo "<script>" . $widget->widget_js() . "</script>";
225
+            ?>
226 226
 			<?php
227
-			wp_die();
228
-		}
229
-
230
-		/**
231
-		 * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
232
-		 *
233
-		 * @since 1.0.0
234
-		 *
235
-		 * @param string $editor_id Optional. Shortcode editor id. Default null.
236
-		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
237
-		 */
238
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
239
-			global $sd_widgets, $shortcode_insert_button_once;
240
-			if ( $shortcode_insert_button_once ) {
241
-				return;
242
-			}
243
-			add_thickbox();
244
-
245
-
246
-			/**
247
-			 * Cornerstone makes us play dirty tricks :/
248
-			 * 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.
249
-			 */
250
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
251
-				echo '<span id="insert-media-button">';
252
-			}
253
-
254
-			echo self::shortcode_button( 'this', 'true' );
255
-
256
-			// see opening note
257
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
258
-				echo '</span>'; // end #insert-media-button
259
-			}
260
-
261
-			self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
262
-			$shortcode_insert_button_once = true;
263
-		}
264
-
265
-		/**
266
-		 * Gets the shortcode insert button html.
267
-		 *
268
-		 * @param string $id
269
-		 * @param string $search_for_id
270
-		 *
271
-		 * @return mixed
272
-		 */
273
-		public static function shortcode_button( $id = '', $search_for_id = '' ) {
274
-			ob_start();
275
-			?>
227
+            wp_die();
228
+        }
229
+
230
+        /**
231
+         * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
232
+         *
233
+         * @since 1.0.0
234
+         *
235
+         * @param string $editor_id Optional. Shortcode editor id. Default null.
236
+         * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
237
+         */
238
+        public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
239
+            global $sd_widgets, $shortcode_insert_button_once;
240
+            if ( $shortcode_insert_button_once ) {
241
+                return;
242
+            }
243
+            add_thickbox();
244
+
245
+
246
+            /**
247
+             * Cornerstone makes us play dirty tricks :/
248
+             * 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.
249
+             */
250
+            if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
251
+                echo '<span id="insert-media-button">';
252
+            }
253
+
254
+            echo self::shortcode_button( 'this', 'true' );
255
+
256
+            // see opening note
257
+            if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
258
+                echo '</span>'; // end #insert-media-button
259
+            }
260
+
261
+            self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
262
+            $shortcode_insert_button_once = true;
263
+        }
264
+
265
+        /**
266
+         * Gets the shortcode insert button html.
267
+         *
268
+         * @param string $id
269
+         * @param string $search_for_id
270
+         *
271
+         * @return mixed
272
+         */
273
+        public static function shortcode_button( $id = '', $search_for_id = '' ) {
274
+            ob_start();
275
+            ?>
276 276
 			<span class="sd-lable-shortcode-inserter">
277 277
 				<a onclick="sd_ajax_get_picker(<?php echo $id;
278
-				if ( $search_for_id ) {
279
-					echo "," . $search_for_id;
280
-				} ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
278
+                if ( $search_for_id ) {
279
+                    echo "," . $search_for_id;
280
+                } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
281 281
 				   class="thickbox button super-duper-content-open" title="Add Shortcode">
282 282
 					<span style="vertical-align: middle;line-height: 18px;font-size: 20px;"
283 283
 					      class="dashicons dashicons-screenoptions"></span>
@@ -288,21 +288,21 @@  discard block
 block discarded – undo
288 288
 			</span>
289 289
 
290 290
 			<?php
291
-			$html = ob_get_clean();
292
-
293
-			// remove line breaks so we can use it in js
294
-			return preg_replace( "/\r|\n/", "", trim( $html ) );
295
-		}
296
-
297
-		/**
298
-		 * Makes SD work with the siteOrigin page builder.
299
-		 *
300
-		 * @since 1.0.6
301
-		 * @return mixed
302
-		 */
303
-		public static function siteorigin_js() {
304
-			ob_start();
305
-			?>
291
+            $html = ob_get_clean();
292
+
293
+            // remove line breaks so we can use it in js
294
+            return preg_replace( "/\r|\n/", "", trim( $html ) );
295
+        }
296
+
297
+        /**
298
+         * Makes SD work with the siteOrigin page builder.
299
+         *
300
+         * @since 1.0.6
301
+         * @return mixed
302
+         */
303
+        public static function siteorigin_js() {
304
+            ob_start();
305
+            ?>
306 306
 			<script>
307 307
 				/**
308 308
 				 * Check a form to see what items shoudl be shown or hidden.
@@ -380,28 +380,28 @@  discard block
 block discarded – undo
380 380
 				});
381 381
 			</script>
382 382
 			<?php
383
-			$output = ob_get_clean();
383
+            $output = ob_get_clean();
384 384
 
385
-			/*
385
+            /*
386 386
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
387 387
 			 */
388 388
 
389
-			return str_replace( array(
390
-				'<script>',
391
-				'</script>'
392
-			), '', $output );
393
-		}
394
-
395
-		/**
396
-		 * Output the JS and CSS for the shortcode insert button.
397
-		 *
398
-		 * @since 1.0.6
399
-		 *
400
-		 * @param string $editor_id
401
-		 * @param string $insert_shortcode_function
402
-		 */
403
-		public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
404
-			?>
389
+            return str_replace( array(
390
+                '<script>',
391
+                '</script>'
392
+            ), '', $output );
393
+        }
394
+
395
+        /**
396
+         * Output the JS and CSS for the shortcode insert button.
397
+         *
398
+         * @since 1.0.6
399
+         *
400
+         * @param string $editor_id
401
+         * @param string $insert_shortcode_function
402
+         */
403
+        public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
404
+            ?>
405 405
 			<style>
406 406
 				.sd-shortcode-left-wrap {
407 407
 					float: left;
@@ -520,22 +520,22 @@  discard block
 block discarded – undo
520 520
 				}
521 521
 			</style>
522 522
 			<?php
523
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
524
-				echo "<script>" . self::siteorigin_js() . "</script>";
525
-			}
526
-			?>
523
+            if ( class_exists( 'SiteOrigin_Panels' ) ) {
524
+                echo "<script>" . self::siteorigin_js() . "</script>";
525
+            }
526
+            ?>
527 527
 			<script>
528 528
 				<?php
529
-				if(! empty( $insert_shortcode_function )){
530
-					echo $insert_shortcode_function;
531
-				}else{
532
-
533
-				/**
534
-				 * Function for super duper insert shortcode.
535
-				 *
536
-				 * @since 1.0.0
537
-				 */
538
-				?>
529
+                if(! empty( $insert_shortcode_function )){
530
+                    echo $insert_shortcode_function;
531
+                }else{
532
+
533
+                /**
534
+                 * Function for super duper insert shortcode.
535
+                 *
536
+                 * @since 1.0.0
537
+                 */
538
+                ?>
539 539
 				function sd_insert_shortcode($editor_id) {
540 540
 					$shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val();
541 541
 					if ($shortcode) {
@@ -543,14 +543,14 @@  discard block
 block discarded – undo
543 543
 						if (!$editor_id) {
544 544
 
545 545
 							<?php
546
-							if ( isset( $_REQUEST['et_fb'] ) ) {
547
-								echo '$editor_id = "#main_content_content_vb_tiny_mce";';
548
-							} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
549
-								echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
550
-							} else {
551
-								echo '$editor_id = "#wp-content-editor-container textarea";';
552
-							}
553
-							?>
546
+                            if ( isset( $_REQUEST['et_fb'] ) ) {
547
+                                echo '$editor_id = "#main_content_content_vb_tiny_mce";';
548
+                            } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
549
+                                echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
550
+                            } else {
551
+                                echo '$editor_id = "#wp-content-editor-container textarea";';
552
+                            }
553
+                            ?>
554 554
 						} else {
555 555
 							$editor_id = '#' + $editor_id;
556 556
 						}
@@ -852,16 +852,16 @@  discard block
 block discarded – undo
852 852
 			</script>
853 853
 
854 854
 			<?php
855
-		}
856
-
857
-		/**
858
-		 * Gets some CSS for the widgets screen.
859
-		 *
860
-		 * @return mixed
861
-		 */
862
-		public function widget_css() {
863
-			ob_start();
864
-			?>
855
+        }
856
+
857
+        /**
858
+         * Gets some CSS for the widgets screen.
859
+         *
860
+         * @return mixed
861
+         */
862
+        public function widget_css() {
863
+            ob_start();
864
+            ?>
865 865
 			<style>
866 866
 				.sd-advanced-setting {
867 867
 					display: none;
@@ -882,26 +882,26 @@  discard block
 block discarded – undo
882 882
 				}
883 883
 			</style>
884 884
 			<?php
885
-			$output = ob_get_clean();
885
+            $output = ob_get_clean();
886 886
 
887
-			/*
887
+            /*
888 888
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
889 889
 			 */
890 890
 
891
-			return str_replace( array(
892
-				'<style>',
893
-				'</style>'
894
-			), '', $output );
895
-		}
896
-
897
-		/**
898
-		 * Gets some JS for the widgets screen.
899
-		 *
900
-		 * @return mixed
901
-		 */
902
-		public function widget_js() {
903
-			ob_start();
904
-			?>
891
+            return str_replace( array(
892
+                '<style>',
893
+                '</style>'
894
+            ), '', $output );
895
+        }
896
+
897
+        /**
898
+         * Gets some JS for the widgets screen.
899
+         *
900
+         * @return mixed
901
+         */
902
+        public function widget_js() {
903
+            ob_start();
904
+            ?>
905 905
 			<script>
906 906
 
907 907
 				/**
@@ -1056,302 +1056,302 @@  discard block
 block discarded – undo
1056 1056
 				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
1057 1057
 			</script>
1058 1058
 			<?php
1059
-			$output = ob_get_clean();
1059
+            $output = ob_get_clean();
1060 1060
 
1061
-			/*
1061
+            /*
1062 1062
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1063 1063
 			 */
1064 1064
 
1065
-			return str_replace( array(
1066
-				'<script>',
1067
-				'</script>'
1068
-			), '', $output );
1069
-		}
1070
-
1071
-
1072
-		/**
1073
-		 * Set the name from the argument key.
1074
-		 *
1075
-		 * @param $options
1076
-		 *
1077
-		 * @return mixed
1078
-		 */
1079
-		private function add_name_from_key( $options, $arguments = false ) {
1080
-			if ( ! empty( $options['arguments'] ) ) {
1081
-				foreach ( $options['arguments'] as $key => $val ) {
1082
-					$options['arguments'][ $key ]['name'] = $key;
1083
-				}
1084
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1085
-				foreach ( $options as $key => $val ) {
1086
-					$options[ $key ]['name'] = $key;
1087
-				}
1088
-			}
1089
-
1090
-			return $options;
1091
-		}
1092
-
1093
-		/**
1094
-		 * Register the parent shortcode.
1095
-		 *
1096
-		 * @since 1.0.0
1097
-		 */
1098
-		public function register_shortcode() {
1099
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1100
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
1101
-		}
1102
-
1103
-		/**
1104
-		 * Render the shortcode via ajax so we can return it to Gutenberg.
1105
-		 *
1106
-		 * @since 1.0.0
1107
-		 */
1108
-		public static function render_shortcode() {
1109
-
1110
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1111
-			if ( ! current_user_can( 'manage_options' ) ) {
1112
-				wp_die();
1113
-			}
1114
-
1115
-			// we might need the $post value here so lets set it.
1116
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1117
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
1118
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
1119
-					global $post;
1120
-					$post = $post_obj;
1121
-				}
1122
-			}
1123
-
1124
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1125
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1126
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1127
-				$attributes       = '';
1128
-				if ( ! empty( $attributes_array ) ) {
1129
-					foreach ( $attributes_array as $key => $value ) {
1130
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
1131
-					}
1132
-				}
1133
-
1134
-				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1135
-
1136
-				echo do_shortcode( $shortcode );
1137
-
1138
-			}
1139
-			wp_die();
1140
-		}
1141
-
1142
-		/**
1143
-		 * Output the shortcode.
1144
-		 *
1145
-		 * @param array $args
1146
-		 * @param string $content
1147
-		 *
1148
-		 * @return string
1149
-		 */
1150
-		public function shortcode_output( $args = array(), $content = '' ) {
1151
-			$args = self::argument_values( $args );
1152
-
1153
-			// add extra argument so we know its a output to gutenberg
1154
-			//$args
1155
-			$args = $this->string_to_bool( $args );
1156
-
1157
-
1158
-			$calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1159
-
1160
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
1161
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
1162
-
1163
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1164
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1165
-
1166
-			$shortcode_args = array();
1167
-			$output         = '';
1168
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1169
-			$main_content   = $this->output( $args, $shortcode_args, $content );
1170
-			if ( $main_content && ! $no_wrap ) {
1171
-				// wrap the shortcode in a dive with the same class as the widget
1172
-				$output .= '<div class="' . $calss . '" ' . $attrs . '>';
1173
-				if ( ! empty( $args['title'] ) ) {
1174
-					// if its a shortcode and there is a title try to grab the title wrappers
1175
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1176
-					if ( empty( $instance ) ) {
1177
-						global $wp_registered_sidebars;
1178
-						if ( ! empty( $wp_registered_sidebars ) ) {
1179
-							foreach ( $wp_registered_sidebars as $sidebar ) {
1180
-								if ( ! empty( $sidebar['before_title'] ) ) {
1181
-									$shortcode_args['before_title'] = $sidebar['before_title'];
1182
-									$shortcode_args['after_title']  = $sidebar['after_title'];
1183
-									break;
1184
-								}
1185
-							}
1186
-						}
1187
-					}
1188
-					$output .= $this->output_title( $shortcode_args, $args );
1189
-				}
1190
-				$output .= $main_content;
1191
-				$output .= '</div>';
1192
-			} elseif ( $main_content && $no_wrap ) {
1193
-				$output .= $main_content;
1194
-			}
1195
-
1196
-			// if preview show a placeholder if empty
1197
-			if ( $this->is_preview() && $output == '' ) {
1198
-				$output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" );
1199
-			}
1200
-
1201
-			return $output;
1202
-		}
1203
-
1204
-		/**
1205
-		 * Placeholder text to show if output is empty and we are on a preview/builder page.
1206
-		 *
1207
-		 * @param string $name
1208
-		 *
1209
-		 * @return string
1210
-		 */
1211
-		public function preview_placeholder_text( $name = '' ) {
1212
-			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1213
-		}
1214
-
1215
-		/**
1216
-		 * Sometimes booleans values can be turned to strings, so we fix that.
1217
-		 *
1218
-		 * @param $options
1219
-		 *
1220
-		 * @return mixed
1221
-		 */
1222
-		public function string_to_bool( $options ) {
1223
-			// convert bool strings to booleans
1224
-			foreach ( $options as $key => $val ) {
1225
-				if ( $val == 'false' ) {
1226
-					$options[ $key ] = false;
1227
-				} elseif ( $val == 'true' ) {
1228
-					$options[ $key ] = true;
1229
-				}
1230
-			}
1231
-
1232
-			return $options;
1233
-		}
1234
-
1235
-		/**
1236
-		 * Get the argument values that are also filterable.
1237
-		 *
1238
-		 * @param $instance
1239
-		 *
1240
-		 * @return array
1241
-		 */
1242
-		public function argument_values( $instance ) {
1243
-			$argument_values = array();
1244
-
1245
-			// set widget instance
1246
-			$this->instance = $instance;
1247
-
1248
-			if ( empty( $this->arguments ) ) {
1249
-				$this->arguments = $this->get_arguments();
1250
-			}
1251
-
1252
-			if ( ! empty( $this->arguments ) ) {
1253
-				foreach ( $this->arguments as $key => $args ) {
1254
-					// set the input name from the key
1255
-					$args['name'] = $key;
1256
-					//
1257
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1258
-					if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1259
-						$argument_values[ $key ] = $args['default'];
1260
-					}
1261
-				}
1262
-			}
1263
-
1264
-			return $argument_values;
1265
-		}
1266
-
1267
-		/**
1268
-		 * Set arguments in super duper.
1269
-		 *
1270
-		 * @since 1.0.0
1271
-		 *
1272
-		 * @return array Set arguments.
1273
-		 */
1274
-		public function set_arguments() {
1275
-			return $this->arguments;
1276
-		}
1277
-
1278
-		/**
1279
-		 * Get arguments in super duper.
1280
-		 *
1281
-		 * @since 1.0.0
1282
-		 *
1283
-		 * @return array Get arguments.
1284
-		 */
1285
-		public function get_arguments() {
1286
-			if ( empty( $this->arguments ) ) {
1287
-				$this->arguments = $this->set_arguments();
1288
-			}
1289
-
1290
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1291
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
1292
-
1293
-			return $this->arguments;
1294
-		}
1295
-
1296
-		/**
1297
-		 * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1298
-		 *
1299
-		 * @param array $args
1300
-		 * @param array $widget_args
1301
-		 * @param string $content
1302
-		 */
1303
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
1304
-
1305
-		}
1306
-
1307
-		/**
1308
-		 * Add the dynamic block code inline when the wp-block in enqueued.
1309
-		 */
1310
-		public function register_block() {
1311
-			wp_add_inline_script( 'wp-blocks', $this->block() );
1312
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
1313
-
1314
-				wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1315
-
1316
-			}
1317
-		}
1318
-
1319
-		/**
1320
-		 * Check if we need to show advanced options.
1321
-		 *
1322
-		 * @return bool
1323
-		 */
1324
-		public function block_show_advanced() {
1325
-
1326
-			$show      = false;
1327
-			$arguments = $this->arguments;
1328
-
1329
-			if ( empty( $arguments ) ) {
1330
-				$arguments = $this->get_arguments();
1331
-			}
1332
-
1333
-			if ( ! empty( $arguments ) ) {
1334
-				foreach ( $arguments as $argument ) {
1335
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1336
-						$show = true;
1337
-					}
1338
-				}
1339
-			}
1340
-
1341
-			return $show;
1342
-		}
1343
-
1344
-
1345
-		/**
1346
-		 * Output the JS for building the dynamic Guntenberg block.
1347
-		 *
1348
-		 * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
1349
-		 * @since 1.0.9 Save numbers as numbers and not strings.
1350
-		 * @return mixed
1351
-		 */
1352
-		public function block() {
1353
-			ob_start();
1354
-			?>
1065
+            return str_replace( array(
1066
+                '<script>',
1067
+                '</script>'
1068
+            ), '', $output );
1069
+        }
1070
+
1071
+
1072
+        /**
1073
+         * Set the name from the argument key.
1074
+         *
1075
+         * @param $options
1076
+         *
1077
+         * @return mixed
1078
+         */
1079
+        private function add_name_from_key( $options, $arguments = false ) {
1080
+            if ( ! empty( $options['arguments'] ) ) {
1081
+                foreach ( $options['arguments'] as $key => $val ) {
1082
+                    $options['arguments'][ $key ]['name'] = $key;
1083
+                }
1084
+            } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1085
+                foreach ( $options as $key => $val ) {
1086
+                    $options[ $key ]['name'] = $key;
1087
+                }
1088
+            }
1089
+
1090
+            return $options;
1091
+        }
1092
+
1093
+        /**
1094
+         * Register the parent shortcode.
1095
+         *
1096
+         * @since 1.0.0
1097
+         */
1098
+        public function register_shortcode() {
1099
+            add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1100
+            add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
1101
+        }
1102
+
1103
+        /**
1104
+         * Render the shortcode via ajax so we can return it to Gutenberg.
1105
+         *
1106
+         * @since 1.0.0
1107
+         */
1108
+        public static function render_shortcode() {
1109
+
1110
+            check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1111
+            if ( ! current_user_can( 'manage_options' ) ) {
1112
+                wp_die();
1113
+            }
1114
+
1115
+            // we might need the $post value here so lets set it.
1116
+            if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1117
+                $post_obj = get_post( absint( $_POST['post_id'] ) );
1118
+                if ( ! empty( $post_obj ) && empty( $post ) ) {
1119
+                    global $post;
1120
+                    $post = $post_obj;
1121
+                }
1122
+            }
1123
+
1124
+            if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1125
+                $shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1126
+                $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1127
+                $attributes       = '';
1128
+                if ( ! empty( $attributes_array ) ) {
1129
+                    foreach ( $attributes_array as $key => $value ) {
1130
+                        $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
1131
+                    }
1132
+                }
1133
+
1134
+                $shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1135
+
1136
+                echo do_shortcode( $shortcode );
1137
+
1138
+            }
1139
+            wp_die();
1140
+        }
1141
+
1142
+        /**
1143
+         * Output the shortcode.
1144
+         *
1145
+         * @param array $args
1146
+         * @param string $content
1147
+         *
1148
+         * @return string
1149
+         */
1150
+        public function shortcode_output( $args = array(), $content = '' ) {
1151
+            $args = self::argument_values( $args );
1152
+
1153
+            // add extra argument so we know its a output to gutenberg
1154
+            //$args
1155
+            $args = $this->string_to_bool( $args );
1156
+
1157
+
1158
+            $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1159
+
1160
+            $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
1161
+            $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
1162
+
1163
+            $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1164
+            $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1165
+
1166
+            $shortcode_args = array();
1167
+            $output         = '';
1168
+            $no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1169
+            $main_content   = $this->output( $args, $shortcode_args, $content );
1170
+            if ( $main_content && ! $no_wrap ) {
1171
+                // wrap the shortcode in a dive with the same class as the widget
1172
+                $output .= '<div class="' . $calss . '" ' . $attrs . '>';
1173
+                if ( ! empty( $args['title'] ) ) {
1174
+                    // if its a shortcode and there is a title try to grab the title wrappers
1175
+                    $shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1176
+                    if ( empty( $instance ) ) {
1177
+                        global $wp_registered_sidebars;
1178
+                        if ( ! empty( $wp_registered_sidebars ) ) {
1179
+                            foreach ( $wp_registered_sidebars as $sidebar ) {
1180
+                                if ( ! empty( $sidebar['before_title'] ) ) {
1181
+                                    $shortcode_args['before_title'] = $sidebar['before_title'];
1182
+                                    $shortcode_args['after_title']  = $sidebar['after_title'];
1183
+                                    break;
1184
+                                }
1185
+                            }
1186
+                        }
1187
+                    }
1188
+                    $output .= $this->output_title( $shortcode_args, $args );
1189
+                }
1190
+                $output .= $main_content;
1191
+                $output .= '</div>';
1192
+            } elseif ( $main_content && $no_wrap ) {
1193
+                $output .= $main_content;
1194
+            }
1195
+
1196
+            // if preview show a placeholder if empty
1197
+            if ( $this->is_preview() && $output == '' ) {
1198
+                $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" );
1199
+            }
1200
+
1201
+            return $output;
1202
+        }
1203
+
1204
+        /**
1205
+         * Placeholder text to show if output is empty and we are on a preview/builder page.
1206
+         *
1207
+         * @param string $name
1208
+         *
1209
+         * @return string
1210
+         */
1211
+        public function preview_placeholder_text( $name = '' ) {
1212
+            return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1213
+        }
1214
+
1215
+        /**
1216
+         * Sometimes booleans values can be turned to strings, so we fix that.
1217
+         *
1218
+         * @param $options
1219
+         *
1220
+         * @return mixed
1221
+         */
1222
+        public function string_to_bool( $options ) {
1223
+            // convert bool strings to booleans
1224
+            foreach ( $options as $key => $val ) {
1225
+                if ( $val == 'false' ) {
1226
+                    $options[ $key ] = false;
1227
+                } elseif ( $val == 'true' ) {
1228
+                    $options[ $key ] = true;
1229
+                }
1230
+            }
1231
+
1232
+            return $options;
1233
+        }
1234
+
1235
+        /**
1236
+         * Get the argument values that are also filterable.
1237
+         *
1238
+         * @param $instance
1239
+         *
1240
+         * @return array
1241
+         */
1242
+        public function argument_values( $instance ) {
1243
+            $argument_values = array();
1244
+
1245
+            // set widget instance
1246
+            $this->instance = $instance;
1247
+
1248
+            if ( empty( $this->arguments ) ) {
1249
+                $this->arguments = $this->get_arguments();
1250
+            }
1251
+
1252
+            if ( ! empty( $this->arguments ) ) {
1253
+                foreach ( $this->arguments as $key => $args ) {
1254
+                    // set the input name from the key
1255
+                    $args['name'] = $key;
1256
+                    //
1257
+                    $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1258
+                    if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1259
+                        $argument_values[ $key ] = $args['default'];
1260
+                    }
1261
+                }
1262
+            }
1263
+
1264
+            return $argument_values;
1265
+        }
1266
+
1267
+        /**
1268
+         * Set arguments in super duper.
1269
+         *
1270
+         * @since 1.0.0
1271
+         *
1272
+         * @return array Set arguments.
1273
+         */
1274
+        public function set_arguments() {
1275
+            return $this->arguments;
1276
+        }
1277
+
1278
+        /**
1279
+         * Get arguments in super duper.
1280
+         *
1281
+         * @since 1.0.0
1282
+         *
1283
+         * @return array Get arguments.
1284
+         */
1285
+        public function get_arguments() {
1286
+            if ( empty( $this->arguments ) ) {
1287
+                $this->arguments = $this->set_arguments();
1288
+            }
1289
+
1290
+            $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1291
+            $this->arguments = $this->add_name_from_key( $this->arguments, true );
1292
+
1293
+            return $this->arguments;
1294
+        }
1295
+
1296
+        /**
1297
+         * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
1298
+         *
1299
+         * @param array $args
1300
+         * @param array $widget_args
1301
+         * @param string $content
1302
+         */
1303
+        public function output( $args = array(), $widget_args = array(), $content = '' ) {
1304
+
1305
+        }
1306
+
1307
+        /**
1308
+         * Add the dynamic block code inline when the wp-block in enqueued.
1309
+         */
1310
+        public function register_block() {
1311
+            wp_add_inline_script( 'wp-blocks', $this->block() );
1312
+            if ( class_exists( 'SiteOrigin_Panels' ) ) {
1313
+
1314
+                wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1315
+
1316
+            }
1317
+        }
1318
+
1319
+        /**
1320
+         * Check if we need to show advanced options.
1321
+         *
1322
+         * @return bool
1323
+         */
1324
+        public function block_show_advanced() {
1325
+
1326
+            $show      = false;
1327
+            $arguments = $this->arguments;
1328
+
1329
+            if ( empty( $arguments ) ) {
1330
+                $arguments = $this->get_arguments();
1331
+            }
1332
+
1333
+            if ( ! empty( $arguments ) ) {
1334
+                foreach ( $arguments as $argument ) {
1335
+                    if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1336
+                        $show = true;
1337
+                    }
1338
+                }
1339
+            }
1340
+
1341
+            return $show;
1342
+        }
1343
+
1344
+
1345
+        /**
1346
+         * Output the JS for building the dynamic Guntenberg block.
1347
+         *
1348
+         * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap.
1349
+         * @since 1.0.9 Save numbers as numbers and not strings.
1350
+         * @return mixed
1351
+         */
1352
+        public function block() {
1353
+            ob_start();
1354
+            ?>
1355 1355
 			<script>
1356 1356
 				/**
1357 1357
 				 * BLOCK: Basic
@@ -1390,76 +1390,76 @@  discard block
 block discarded – undo
1390 1390
 						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/.
1391 1391
 						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.
1392 1392
 						<?php if ( isset( $this->options['block-keywords'] ) ) {
1393
-						echo "keywords : " . $this->options['block-keywords'] . ",";
1394
-					}?>
1393
+                        echo "keywords : " . $this->options['block-keywords'] . ",";
1394
+                    }?>
1395 1395
 
1396 1396
 						<?php
1397 1397
 
1398
-						$show_advanced = $this->block_show_advanced();
1399
-
1400
-						$show_alignment = false;
1401
-
1402
-						if ( ! empty( $this->arguments ) ) {
1403
-							echo "attributes : {";
1404
-
1405
-							if ( $show_advanced ) {
1406
-								echo "show_advanced: {";
1407
-								echo "	type: 'boolean',";
1408
-								echo "  default: false,";
1409
-								echo "},";
1410
-							}
1411
-
1412
-							// block wrap element
1413
-							if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
1414
-								echo "block_wrap: {";
1415
-								echo "	type: 'string',";
1416
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
1417
-								echo "},";
1418
-							}
1419
-
1420
-
1421
-							foreach ( $this->arguments as $key => $args ) {
1422
-
1423
-								// set if we should show alignment
1424
-								if ( $key == 'alignment' ) {
1425
-									$show_alignment = true;
1426
-								}
1427
-
1428
-								$extra = '';
1429
-
1430
-								if ( $args['type'] == 'checkbox' ) {
1431
-									$type    = 'boolean';
1432
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
1433
-								} elseif ( $args['type'] == 'number' ) {
1434
-									$type    = 'number';
1435
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1436
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
1437
-									$type = 'array';
1438
-									if ( is_array( $args['default'] ) ) {
1439
-										$default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
1440
-									} else {
1441
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1442
-									}
1443
-								} elseif ( $args['type'] == 'multiselect' ) {
1444
-									$type    = 'array';
1445
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1446
-								} else {
1447
-									$type    = 'string';
1448
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1449
-								}
1450
-								echo $key . " : {";
1451
-								echo "type : '$type',";
1452
-								echo "default : $default,";
1453
-								echo "},";
1454
-							}
1455
-
1456
-							echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
1457
-
1458
-							echo "},";
1459
-
1460
-						}
1461
-
1462
-						?>
1398
+                        $show_advanced = $this->block_show_advanced();
1399
+
1400
+                        $show_alignment = false;
1401
+
1402
+                        if ( ! empty( $this->arguments ) ) {
1403
+                            echo "attributes : {";
1404
+
1405
+                            if ( $show_advanced ) {
1406
+                                echo "show_advanced: {";
1407
+                                echo "	type: 'boolean',";
1408
+                                echo "  default: false,";
1409
+                                echo "},";
1410
+                            }
1411
+
1412
+                            // block wrap element
1413
+                            if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
1414
+                                echo "block_wrap: {";
1415
+                                echo "	type: 'string',";
1416
+                                echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
1417
+                                echo "},";
1418
+                            }
1419
+
1420
+
1421
+                            foreach ( $this->arguments as $key => $args ) {
1422
+
1423
+                                // set if we should show alignment
1424
+                                if ( $key == 'alignment' ) {
1425
+                                    $show_alignment = true;
1426
+                                }
1427
+
1428
+                                $extra = '';
1429
+
1430
+                                if ( $args['type'] == 'checkbox' ) {
1431
+                                    $type    = 'boolean';
1432
+                                    $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
1433
+                                } elseif ( $args['type'] == 'number' ) {
1434
+                                    $type    = 'number';
1435
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1436
+                                } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
1437
+                                    $type = 'array';
1438
+                                    if ( is_array( $args['default'] ) ) {
1439
+                                        $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
1440
+                                    } else {
1441
+                                        $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1442
+                                    }
1443
+                                } elseif ( $args['type'] == 'multiselect' ) {
1444
+                                    $type    = 'array';
1445
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1446
+                                } else {
1447
+                                    $type    = 'string';
1448
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1449
+                                }
1450
+                                echo $key . " : {";
1451
+                                echo "type : '$type',";
1452
+                                echo "default : $default,";
1453
+                                echo "},";
1454
+                            }
1455
+
1456
+                            echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
1457
+
1458
+                            echo "},";
1459
+
1460
+                        }
1461
+
1462
+                        ?>
1463 1463
 
1464 1464
 						// The "edit" property must be a valid function.
1465 1465
 						edit: function (props) {
@@ -1478,8 +1478,8 @@  discard block
 block discarded – undo
1478 1478
 										'shortcode': '<?php echo $this->options['base_id'];?>',
1479 1479
 										'attributes': props.attributes,
1480 1480
 										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
1481
-										echo $post->ID;
1482
-									}?>,
1481
+                                        echo $post->ID;
1482
+                                    }?>,
1483 1483
 										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
1484 1484
 									};
1485 1485
 
@@ -1526,10 +1526,10 @@  discard block
 block discarded – undo
1526 1526
 
1527 1527
 									<?php
1528 1528
 
1529
-									if(! empty( $this->arguments )){
1529
+                                    if(! empty( $this->arguments )){
1530 1530
 
1531
-									if ( $show_advanced ) {
1532
-									?>
1531
+                                    if ( $show_advanced ) {
1532
+                                    ?>
1533 1533
 									el(
1534 1534
 										wp.components.ToggleControl,
1535 1535
 										{
@@ -1542,73 +1542,73 @@  discard block
 block discarded – undo
1542 1542
 									),
1543 1543
 									<?php
1544 1544
 
1545
-									}
1546
-
1547
-									foreach($this->arguments as $key => $args){
1548
-									$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
1549
-									$options = '';
1550
-									$extra = '';
1551
-									$require = '';
1552
-									$onchange = "props.setAttributes({ $key: $key } )";
1553
-									$value = "props.attributes.$key";
1554
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1555
-									if ( in_array( $args['type'], $text_type ) ) {
1556
-										$type = 'TextControl';
1557
-										// Save numbers as numbers and not strings
1558
-										if ( $args['type'] == 'number' ) {
1559
-											$onchange = "props.setAttributes({ $key: Number($key) } )";
1560
-										}
1561
-									}
1545
+                                    }
1546
+
1547
+                                    foreach($this->arguments as $key => $args){
1548
+                                    $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
1549
+                                    $options = '';
1550
+                                    $extra = '';
1551
+                                    $require = '';
1552
+                                    $onchange = "props.setAttributes({ $key: $key } )";
1553
+                                    $value = "props.attributes.$key";
1554
+                                    $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1555
+                                    if ( in_array( $args['type'], $text_type ) ) {
1556
+                                        $type = 'TextControl';
1557
+                                        // Save numbers as numbers and not strings
1558
+                                        if ( $args['type'] == 'number' ) {
1559
+                                            $onchange = "props.setAttributes({ $key: Number($key) } )";
1560
+                                        }
1561
+                                    }
1562 1562
 //									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
1563 1563
 //										$type = 'ColorPicker';
1564 1564
 //									}
1565
-									elseif ( $args['type'] == 'checkbox' ) {
1566
-										$type = 'CheckboxControl';
1567
-										$extra .= "checked: props.attributes.$key,";
1568
-										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1569
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1570
-										$type = 'SelectControl';
1571
-										if ( ! empty( $args['options'] ) ) {
1572
-											$options .= "options  : [";
1573
-											foreach ( $args['options'] as $option_val => $option_label ) {
1574
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1575
-											}
1576
-											$options .= "],";
1577
-										}
1578
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1579
-											$extra .= ' multiple: true, ';
1580
-											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1581
-											//$value = "['edit', 'delete']";
1582
-										}
1583
-									} elseif ( $args['type'] == 'alignment' ) {
1584
-										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1585
-									} else {
1586
-										continue;// if we have not implemented the control then don't break the JS.
1587
-									}
1588
-
1589
-									// add show only if advanced
1590
-									if ( ! empty( $args['advanced'] ) ) {
1591
-										echo "props.attributes.show_advanced && ";
1592
-									}
1593
-									// add setting require if defined
1594
-									if ( ! empty( $args['element_require'] ) ) {
1595
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1596
-									}
1597
-									?>
1565
+                                    elseif ( $args['type'] == 'checkbox' ) {
1566
+                                        $type = 'CheckboxControl';
1567
+                                        $extra .= "checked: props.attributes.$key,";
1568
+                                        $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1569
+                                    } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1570
+                                        $type = 'SelectControl';
1571
+                                        if ( ! empty( $args['options'] ) ) {
1572
+                                            $options .= "options  : [";
1573
+                                            foreach ( $args['options'] as $option_val => $option_label ) {
1574
+                                                $options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1575
+                                            }
1576
+                                            $options .= "],";
1577
+                                        }
1578
+                                        if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1579
+                                            $extra .= ' multiple: true, ';
1580
+                                            //$onchange = "props.setAttributes({ $key: ['edit'] } )";
1581
+                                            //$value = "['edit', 'delete']";
1582
+                                        }
1583
+                                    } elseif ( $args['type'] == 'alignment' ) {
1584
+                                        $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1585
+                                    } else {
1586
+                                        continue;// if we have not implemented the control then don't break the JS.
1587
+                                    }
1588
+
1589
+                                    // add show only if advanced
1590
+                                    if ( ! empty( $args['advanced'] ) ) {
1591
+                                        echo "props.attributes.show_advanced && ";
1592
+                                    }
1593
+                                    // add setting require if defined
1594
+                                    if ( ! empty( $args['element_require'] ) ) {
1595
+                                        echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1596
+                                    }
1597
+                                    ?>
1598 1598
 									el(
1599 1599
 										wp.components.<?php echo esc_attr( $type );?>,
1600 1600
 										{
1601 1601
 											label: '<?php echo esc_attr( $args['title'] );?>',
1602 1602
 											help: '<?php if ( isset( $args['desc'] ) ) {
1603
-												echo esc_attr( $args['desc'] );
1604
-											}?>',
1603
+                                                echo esc_attr( $args['desc'] );
1604
+                                            }?>',
1605 1605
 											value: <?php echo $value;?>,
1606 1606
 											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1607
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1608
-										}?>
1607
+                                            echo "type: '" . esc_attr( $args['type'] ) . "',";
1608
+                                        }?>
1609 1609
 											<?php if ( ! empty( $args['placeholder'] ) ) {
1610
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1611
-										}?>
1610
+                                            echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1611
+                                        }?>
1612 1612
 											<?php echo $options;?>
1613 1613
 											<?php echo $extra;?>
1614 1614
 											<?php echo $custom_attributes;?>
@@ -1618,27 +1618,27 @@  discard block
 block discarded – undo
1618 1618
 										}
1619 1619
 									),
1620 1620
 									<?php
1621
-									}
1622
-									}
1623
-									?>
1621
+                                    }
1622
+                                    }
1623
+                                    ?>
1624 1624
 
1625 1625
 								),
1626 1626
 
1627 1627
 								<?php
1628
-								// If the user sets block-output array then build it
1629
-								if ( ! empty( $this->options['block-output'] ) ) {
1630
-								$this->block_element( $this->options['block-output'] );
1631
-							}else{
1632
-								// if no block-output is set then we try and get the shortcode html output via ajax.
1633
-								?>
1628
+                                // If the user sets block-output array then build it
1629
+                                if ( ! empty( $this->options['block-output'] ) ) {
1630
+                                $this->block_element( $this->options['block-output'] );
1631
+                            }else{
1632
+                                // if no block-output is set then we try and get the shortcode html output via ajax.
1633
+                                ?>
1634 1634
 								el('div', {
1635 1635
 									dangerouslySetInnerHTML: {__html: onChangeContent()},
1636 1636
 									className: props.className,
1637 1637
 									style: {'min-height': '30px'}
1638 1638
 								})
1639 1639
 								<?php
1640
-								}
1641
-								?>
1640
+                                }
1641
+                                ?>
1642 1642
 							]; // end return
1643 1643
 						},
1644 1644
 
@@ -1655,17 +1655,17 @@  discard block
 block discarded – undo
1655 1655
 							var content = "[<?php echo $this->options['base_id'];?>";
1656 1656
 							<?php
1657 1657
 
1658
-							if(! empty( $this->arguments )){
1659
-							foreach($this->arguments as $key => $args){
1660
-							?>
1658
+                            if(! empty( $this->arguments )){
1659
+                            foreach($this->arguments as $key => $args){
1660
+                            ?>
1661 1661
 							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1662 1662
 								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1663 1663
 							}
1664 1664
 							<?php
1665
-							}
1666
-							}
1665
+                            }
1666
+                            }
1667 1667
 
1668
-							?>
1668
+                            ?>
1669 1669
 							content += "]";
1670 1670
 
1671 1671
 
@@ -1694,456 +1694,456 @@  discard block
 block discarded – undo
1694 1694
 				})();
1695 1695
 			</script>
1696 1696
 			<?php
1697
-			$output = ob_get_clean();
1697
+            $output = ob_get_clean();
1698 1698
 
1699
-			/*
1699
+            /*
1700 1700
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1701 1701
 			 */
1702 1702
 
1703
-			return str_replace( array(
1704
-				'<script>',
1705
-				'</script>'
1706
-			), '', $output );
1707
-		}
1708
-
1709
-		/**
1710
-		 * Convert an array of attributes to block string.
1711
-		 *
1712
-		 * @todo there is prob a faster way to do this, also we could add some validation here.
1713
-		 *
1714
-		 * @param $custom_attributes
1715
-		 *
1716
-		 * @return string
1717
-		 */
1718
-		public function array_to_attributes( $custom_attributes, $html = false ) {
1719
-			$attributes = '';
1720
-			if ( ! empty( $custom_attributes ) ) {
1721
-
1722
-				if ( $html ) {
1723
-					foreach ( $custom_attributes as $key => $val ) {
1724
-						$attributes .= " $key='$val' ";
1725
-					}
1726
-				} else {
1727
-					foreach ( $custom_attributes as $key => $val ) {
1728
-						$attributes .= "'$key': '$val',";
1729
-					}
1730
-				}
1731
-			}
1732
-
1733
-			return $attributes;
1734
-		}
1735
-
1736
-		/**
1737
-		 * A self looping function to create the output for JS block elements.
1738
-		 *
1739
-		 * This is what is output in the WP Editor visual view.
1740
-		 *
1741
-		 * @param $args
1742
-		 */
1743
-		public function block_element( $args ) {
1744
-
1745
-
1746
-			if ( ! empty( $args ) ) {
1747
-				foreach ( $args as $element => $new_args ) {
1748
-
1749
-					if ( is_array( $new_args ) ) { // its an element
1750
-
1751
-
1752
-						if ( isset( $new_args['element'] ) ) {
1753
-
1754
-							if ( isset( $new_args['element_require'] ) ) {
1755
-								echo str_replace( array(
1756
-										"'+",
1757
-										"+'"
1758
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1759
-								unset( $new_args['element_require'] );
1760
-							}
1761
-
1762
-							echo "\n el( '" . $new_args['element'] . "', {";
1763
-
1764
-							// get the attributes
1765
-							foreach ( $new_args as $new_key => $new_value ) {
1766
-
1767
-
1768
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1769
-									// do nothing
1770
-								} else {
1771
-									echo $this->block_element( array( $new_key => $new_value ) );
1772
-								}
1773
-							}
1774
-
1775
-							echo "},";// end attributes
1776
-
1777
-							// get the content
1778
-							$first_item = 0;
1779
-							foreach ( $new_args as $new_key => $new_value ) {
1780
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1781
-
1782
-									if ( $new_key === 'content' ) {
1783
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1784
-									}
1785
-
1786
-									if ( is_array( $new_value ) ) {
1787
-
1788
-										if ( isset( $new_value['element_require'] ) ) {
1789
-											echo str_replace( array(
1790
-													"'+",
1791
-													"+'"
1792
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1793
-											unset( $new_value['element_require'] );
1794
-										}
1795
-
1796
-										if ( isset( $new_value['element_repeat'] ) ) {
1797
-											$x = 1;
1798
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1799
-												$this->block_element( array( '' => $new_value ) );
1800
-												$x ++;
1801
-											}
1802
-										} else {
1803
-											$this->block_element( array( '' => $new_value ) );
1804
-										}
1805
-									}
1806
-									$first_item ++;
1807
-								}
1808
-							}
1809
-
1810
-							echo ")";// end content
1811
-
1812
-							echo ", \n";
1813
-
1814
-						}
1815
-					} else {
1816
-
1817
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1818
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1819
-						} elseif ( $element == 'style' ) {
1820
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1821
-						} else {
1822
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1823
-						}
1824
-
1825
-					}
1826
-				}
1827
-			}
1828
-		}
1829
-
1830
-		/**
1831
-		 * Replace block attributes placeholders with the proper naming.
1832
-		 *
1833
-		 * @param $string
1834
-		 *
1835
-		 * @return mixed
1836
-		 */
1837
-		public function block_props_replace( $string, $no_wrap = false ) {
1838
-
1839
-			if ( $no_wrap ) {
1840
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1841
-			} else {
1842
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1843
-			}
1844
-
1845
-			return $string;
1846
-		}
1847
-
1848
-		/**
1849
-		 * Outputs the content of the widget
1850
-		 *
1851
-		 * @param array $args
1852
-		 * @param array $instance
1853
-		 */
1854
-		public function widget( $args, $instance ) {
1855
-
1856
-			// get the filtered values
1857
-			$argument_values = $this->argument_values( $instance );
1858
-			$argument_values = $this->string_to_bool( $argument_values );
1859
-			$output          = $this->output( $argument_values, $args );
1860
-
1861
-			if ( $output ) {
1862
-				// Before widget
1863
-				$before_widget = $args['before_widget'];
1864
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1865
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1866
-
1867
-				// After widget
1868
-				$after_widget = $args['after_widget'];
1869
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1870
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1871
-
1872
-				echo $before_widget;
1873
-				// elementor strips the widget wrapping div so we check for and add it back if needed
1874
-				if ( $this->is_elementor_widget_output() ) {
1875
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1876
-				}
1877
-				echo $this->output_title( $args, $instance );
1878
-				echo $output;
1879
-				if ( $this->is_elementor_widget_output() ) {
1880
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1881
-				}
1882
-				echo $after_widget;
1883
-			} elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
1884
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1885
-				echo $output;
1886
-			}
1887
-		}
1888
-
1889
-		/**
1890
-		 * Tests if the current output is inside a elementor container.
1891
-		 *
1892
-		 * @since 1.0.4
1893
-		 * @return bool
1894
-		 */
1895
-		public function is_elementor_widget_output() {
1896
-			$result = false;
1897
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1898
-				$result = true;
1899
-			}
1900
-
1901
-			return $result;
1902
-		}
1903
-
1904
-		/**
1905
-		 * Tests if the current output is inside a elementor preview.
1906
-		 *
1907
-		 * @since 1.0.4
1908
-		 * @return bool
1909
-		 */
1910
-		public function is_elementor_preview() {
1911
-			$result = false;
1912
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
1913
-				$result = true;
1914
-			}
1915
-
1916
-			return $result;
1917
-		}
1918
-
1919
-		/**
1920
-		 * Tests if the current output is inside a Divi preview.
1921
-		 *
1922
-		 * @since 1.0.6
1923
-		 * @return bool
1924
-		 */
1925
-		public function is_divi_preview() {
1926
-			$result = false;
1927
-			if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1928
-				$result = true;
1929
-			}
1930
-
1931
-			return $result;
1932
-		}
1933
-
1934
-		/**
1935
-		 * Tests if the current output is inside a Beaver builder preview.
1936
-		 *
1937
-		 * @since 1.0.6
1938
-		 * @return bool
1939
-		 */
1940
-		public function is_beaver_preview() {
1941
-			$result = false;
1942
-			if ( isset( $_REQUEST['fl_builder'] ) ) {
1943
-				$result = true;
1944
-			}
1945
-
1946
-			return $result;
1947
-		}
1948
-
1949
-		/**
1950
-		 * Tests if the current output is inside a siteorigin builder preview.
1951
-		 *
1952
-		 * @since 1.0.6
1953
-		 * @return bool
1954
-		 */
1955
-		public function is_siteorigin_preview() {
1956
-			$result = false;
1957
-			if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
1958
-				$result = true;
1959
-			}
1960
-
1961
-			return $result;
1962
-		}
1963
-
1964
-		/**
1965
-		 * Tests if the current output is inside a cornerstone builder preview.
1966
-		 *
1967
-		 * @since 1.0.8
1968
-		 * @return bool
1969
-		 */
1970
-		public function is_cornerstone_preview() {
1971
-			$result = false;
1972
-			if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
1973
-				$result = true;
1974
-			}
1975
-
1976
-			return $result;
1977
-		}
1978
-
1979
-		/**
1980
-		 * General function to check if we are in a preview situation.
1981
-		 *
1982
-		 * @since 1.0.6
1983
-		 * @return bool
1984
-		 */
1985
-		public function is_preview() {
1986
-			$preview = false;
1987
-			if ( $this->is_divi_preview() ) {
1988
-				$preview = true;
1989
-			} elseif ( $this->is_elementor_preview() ) {
1990
-				$preview = true;
1991
-			} elseif ( $this->is_beaver_preview() ) {
1992
-				$preview = true;
1993
-			} elseif ( $this->is_siteorigin_preview() ) {
1994
-				$preview = true;
1995
-			} elseif ( $this->is_cornerstone_preview() ) {
1996
-				$preview = true;
1997
-			}
1998
-
1999
-			return $preview;
2000
-		}
2001
-
2002
-		/**
2003
-		 * Output the super title.
2004
-		 *
2005
-		 * @param $args
2006
-		 * @param array $instance
2007
-		 *
2008
-		 * @return string
2009
-		 */
2010
-		public function output_title( $args, $instance = array() ) {
2011
-			$output = '';
2012
-			if ( ! empty( $instance['title'] ) ) {
2013
-				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
2014
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2015
-				$output = $args['before_title'] . $title . $args['after_title'];
2016
-			}
2017
-
2018
-			return $output;
2019
-		}
2020
-
2021
-		/**
2022
-		 * Outputs the options form inputs for the widget.
2023
-		 *
2024
-		 * @param array $instance The widget options.
2025
-		 */
2026
-		public function form( $instance ) {
2027
-
2028
-			// set widget instance
2029
-			$this->instance = $instance;
2030
-
2031
-			// set it as a SD widget
2032
-			echo $this->widget_advanced_toggle();
2033
-
2034
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
2035
-			$arguments = $this->get_arguments();
2036
-
2037
-			if ( is_array( $arguments ) ) {
2038
-				foreach ( $arguments as $key => $args ) {
2039
-					$this->widget_inputs( $args, $instance );
2040
-				}
2041
-			}
2042
-		}
2043
-
2044
-		/**
2045
-		 * Get the hidden input that when added makes the advanced button show on widget settings.
2046
-		 *
2047
-		 * @return string
2048
-		 */
2049
-		public function widget_advanced_toggle() {
2050
-
2051
-			$output = '';
2052
-			if ( $this->block_show_advanced() ) {
2053
-				$val = 1;
2054
-			} else {
2055
-				$val = 0;
2056
-			}
2057
-
2058
-			$output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
2059
-
2060
-			return $output;
2061
-		}
2062
-
2063
-		/**
2064
-		 * Convert require element.
2065
-		 *
2066
-		 * @since 1.0.0
2067
-		 *
2068
-		 * @param string $input Input element.
2069
-		 *
2070
-		 * @return string $output
2071
-		 */
2072
-		public function convert_element_require( $input ) {
2073
-
2074
-			$input = str_replace( "'", '"', $input );// we only want double quotes
2075
-
2076
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
2077
-				"jQuery(form).find('[data-argument=\"",
2078
-				"\"]').find('input,select').val()"
2079
-			), $input ) );
2080
-
2081
-			return $output;
2082
-		}
2083
-
2084
-		/**
2085
-		 * Builds the inputs for the widget options.
2086
-		 *
2087
-		 * @param $args
2088
-		 * @param $instance
2089
-		 */
2090
-		public function widget_inputs( $args, $instance ) {
2091
-
2092
-			$class             = "";
2093
-			$element_require   = "";
2094
-			$custom_attributes = "";
2095
-
2096
-			// get value
2097
-			if ( isset( $instance[ $args['name'] ] ) ) {
2098
-				$value = $instance[ $args['name'] ];
2099
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
2100
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
2101
-			} else {
2102
-				$value = '';
2103
-			}
2104
-
2105
-			// get placeholder
2106
-			if ( ! empty( $args['placeholder'] ) ) {
2107
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
2108
-			} else {
2109
-				$placeholder = '';
2110
-			}
2111
-
2112
-			// get if advanced
2113
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
2114
-				$class .= " sd-advanced-setting ";
2115
-			}
2116
-
2117
-			// element_require
2118
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
2119
-				$element_require = $args['element_require'];
2120
-			}
2121
-
2122
-			// custom_attributes
2123
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
2124
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
2125
-			}
2126
-
2127
-			// before wrapper
2128
-			?>
1703
+            return str_replace( array(
1704
+                '<script>',
1705
+                '</script>'
1706
+            ), '', $output );
1707
+        }
1708
+
1709
+        /**
1710
+         * Convert an array of attributes to block string.
1711
+         *
1712
+         * @todo there is prob a faster way to do this, also we could add some validation here.
1713
+         *
1714
+         * @param $custom_attributes
1715
+         *
1716
+         * @return string
1717
+         */
1718
+        public function array_to_attributes( $custom_attributes, $html = false ) {
1719
+            $attributes = '';
1720
+            if ( ! empty( $custom_attributes ) ) {
1721
+
1722
+                if ( $html ) {
1723
+                    foreach ( $custom_attributes as $key => $val ) {
1724
+                        $attributes .= " $key='$val' ";
1725
+                    }
1726
+                } else {
1727
+                    foreach ( $custom_attributes as $key => $val ) {
1728
+                        $attributes .= "'$key': '$val',";
1729
+                    }
1730
+                }
1731
+            }
1732
+
1733
+            return $attributes;
1734
+        }
1735
+
1736
+        /**
1737
+         * A self looping function to create the output for JS block elements.
1738
+         *
1739
+         * This is what is output in the WP Editor visual view.
1740
+         *
1741
+         * @param $args
1742
+         */
1743
+        public function block_element( $args ) {
1744
+
1745
+
1746
+            if ( ! empty( $args ) ) {
1747
+                foreach ( $args as $element => $new_args ) {
1748
+
1749
+                    if ( is_array( $new_args ) ) { // its an element
1750
+
1751
+
1752
+                        if ( isset( $new_args['element'] ) ) {
1753
+
1754
+                            if ( isset( $new_args['element_require'] ) ) {
1755
+                                echo str_replace( array(
1756
+                                        "'+",
1757
+                                        "+'"
1758
+                                    ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1759
+                                unset( $new_args['element_require'] );
1760
+                            }
1761
+
1762
+                            echo "\n el( '" . $new_args['element'] . "', {";
1763
+
1764
+                            // get the attributes
1765
+                            foreach ( $new_args as $new_key => $new_value ) {
1766
+
1767
+
1768
+                                if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1769
+                                    // do nothing
1770
+                                } else {
1771
+                                    echo $this->block_element( array( $new_key => $new_value ) );
1772
+                                }
1773
+                            }
1774
+
1775
+                            echo "},";// end attributes
1776
+
1777
+                            // get the content
1778
+                            $first_item = 0;
1779
+                            foreach ( $new_args as $new_key => $new_value ) {
1780
+                                if ( $new_key === 'content' || is_array( $new_value ) ) {
1781
+
1782
+                                    if ( $new_key === 'content' ) {
1783
+                                        echo "'" . $this->block_props_replace( $new_value ) . "'";
1784
+                                    }
1785
+
1786
+                                    if ( is_array( $new_value ) ) {
1787
+
1788
+                                        if ( isset( $new_value['element_require'] ) ) {
1789
+                                            echo str_replace( array(
1790
+                                                    "'+",
1791
+                                                    "+'"
1792
+                                                ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1793
+                                            unset( $new_value['element_require'] );
1794
+                                        }
1795
+
1796
+                                        if ( isset( $new_value['element_repeat'] ) ) {
1797
+                                            $x = 1;
1798
+                                            while ( $x <= absint( $new_value['element_repeat'] ) ) {
1799
+                                                $this->block_element( array( '' => $new_value ) );
1800
+                                                $x ++;
1801
+                                            }
1802
+                                        } else {
1803
+                                            $this->block_element( array( '' => $new_value ) );
1804
+                                        }
1805
+                                    }
1806
+                                    $first_item ++;
1807
+                                }
1808
+                            }
1809
+
1810
+                            echo ")";// end content
1811
+
1812
+                            echo ", \n";
1813
+
1814
+                        }
1815
+                    } else {
1816
+
1817
+                        if ( substr( $element, 0, 3 ) === "if_" ) {
1818
+                            echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1819
+                        } elseif ( $element == 'style' ) {
1820
+                            echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1821
+                        } else {
1822
+                            echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1823
+                        }
1824
+
1825
+                    }
1826
+                }
1827
+            }
1828
+        }
1829
+
1830
+        /**
1831
+         * Replace block attributes placeholders with the proper naming.
1832
+         *
1833
+         * @param $string
1834
+         *
1835
+         * @return mixed
1836
+         */
1837
+        public function block_props_replace( $string, $no_wrap = false ) {
1838
+
1839
+            if ( $no_wrap ) {
1840
+                $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1841
+            } else {
1842
+                $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1843
+            }
1844
+
1845
+            return $string;
1846
+        }
1847
+
1848
+        /**
1849
+         * Outputs the content of the widget
1850
+         *
1851
+         * @param array $args
1852
+         * @param array $instance
1853
+         */
1854
+        public function widget( $args, $instance ) {
1855
+
1856
+            // get the filtered values
1857
+            $argument_values = $this->argument_values( $instance );
1858
+            $argument_values = $this->string_to_bool( $argument_values );
1859
+            $output          = $this->output( $argument_values, $args );
1860
+
1861
+            if ( $output ) {
1862
+                // Before widget
1863
+                $before_widget = $args['before_widget'];
1864
+                $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1865
+                $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1866
+
1867
+                // After widget
1868
+                $after_widget = $args['after_widget'];
1869
+                $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1870
+                $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1871
+
1872
+                echo $before_widget;
1873
+                // elementor strips the widget wrapping div so we check for and add it back if needed
1874
+                if ( $this->is_elementor_widget_output() ) {
1875
+                    echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1876
+                }
1877
+                echo $this->output_title( $args, $instance );
1878
+                echo $output;
1879
+                if ( $this->is_elementor_widget_output() ) {
1880
+                    echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1881
+                }
1882
+                echo $after_widget;
1883
+            } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
1884
+                $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1885
+                echo $output;
1886
+            }
1887
+        }
1888
+
1889
+        /**
1890
+         * Tests if the current output is inside a elementor container.
1891
+         *
1892
+         * @since 1.0.4
1893
+         * @return bool
1894
+         */
1895
+        public function is_elementor_widget_output() {
1896
+            $result = false;
1897
+            if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1898
+                $result = true;
1899
+            }
1900
+
1901
+            return $result;
1902
+        }
1903
+
1904
+        /**
1905
+         * Tests if the current output is inside a elementor preview.
1906
+         *
1907
+         * @since 1.0.4
1908
+         * @return bool
1909
+         */
1910
+        public function is_elementor_preview() {
1911
+            $result = false;
1912
+            if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
1913
+                $result = true;
1914
+            }
1915
+
1916
+            return $result;
1917
+        }
1918
+
1919
+        /**
1920
+         * Tests if the current output is inside a Divi preview.
1921
+         *
1922
+         * @since 1.0.6
1923
+         * @return bool
1924
+         */
1925
+        public function is_divi_preview() {
1926
+            $result = false;
1927
+            if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1928
+                $result = true;
1929
+            }
1930
+
1931
+            return $result;
1932
+        }
1933
+
1934
+        /**
1935
+         * Tests if the current output is inside a Beaver builder preview.
1936
+         *
1937
+         * @since 1.0.6
1938
+         * @return bool
1939
+         */
1940
+        public function is_beaver_preview() {
1941
+            $result = false;
1942
+            if ( isset( $_REQUEST['fl_builder'] ) ) {
1943
+                $result = true;
1944
+            }
1945
+
1946
+            return $result;
1947
+        }
1948
+
1949
+        /**
1950
+         * Tests if the current output is inside a siteorigin builder preview.
1951
+         *
1952
+         * @since 1.0.6
1953
+         * @return bool
1954
+         */
1955
+        public function is_siteorigin_preview() {
1956
+            $result = false;
1957
+            if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
1958
+                $result = true;
1959
+            }
1960
+
1961
+            return $result;
1962
+        }
1963
+
1964
+        /**
1965
+         * Tests if the current output is inside a cornerstone builder preview.
1966
+         *
1967
+         * @since 1.0.8
1968
+         * @return bool
1969
+         */
1970
+        public function is_cornerstone_preview() {
1971
+            $result = false;
1972
+            if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
1973
+                $result = true;
1974
+            }
1975
+
1976
+            return $result;
1977
+        }
1978
+
1979
+        /**
1980
+         * General function to check if we are in a preview situation.
1981
+         *
1982
+         * @since 1.0.6
1983
+         * @return bool
1984
+         */
1985
+        public function is_preview() {
1986
+            $preview = false;
1987
+            if ( $this->is_divi_preview() ) {
1988
+                $preview = true;
1989
+            } elseif ( $this->is_elementor_preview() ) {
1990
+                $preview = true;
1991
+            } elseif ( $this->is_beaver_preview() ) {
1992
+                $preview = true;
1993
+            } elseif ( $this->is_siteorigin_preview() ) {
1994
+                $preview = true;
1995
+            } elseif ( $this->is_cornerstone_preview() ) {
1996
+                $preview = true;
1997
+            }
1998
+
1999
+            return $preview;
2000
+        }
2001
+
2002
+        /**
2003
+         * Output the super title.
2004
+         *
2005
+         * @param $args
2006
+         * @param array $instance
2007
+         *
2008
+         * @return string
2009
+         */
2010
+        public function output_title( $args, $instance = array() ) {
2011
+            $output = '';
2012
+            if ( ! empty( $instance['title'] ) ) {
2013
+                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
2014
+                $title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2015
+                $output = $args['before_title'] . $title . $args['after_title'];
2016
+            }
2017
+
2018
+            return $output;
2019
+        }
2020
+
2021
+        /**
2022
+         * Outputs the options form inputs for the widget.
2023
+         *
2024
+         * @param array $instance The widget options.
2025
+         */
2026
+        public function form( $instance ) {
2027
+
2028
+            // set widget instance
2029
+            $this->instance = $instance;
2030
+
2031
+            // set it as a SD widget
2032
+            echo $this->widget_advanced_toggle();
2033
+
2034
+            echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
2035
+            $arguments = $this->get_arguments();
2036
+
2037
+            if ( is_array( $arguments ) ) {
2038
+                foreach ( $arguments as $key => $args ) {
2039
+                    $this->widget_inputs( $args, $instance );
2040
+                }
2041
+            }
2042
+        }
2043
+
2044
+        /**
2045
+         * Get the hidden input that when added makes the advanced button show on widget settings.
2046
+         *
2047
+         * @return string
2048
+         */
2049
+        public function widget_advanced_toggle() {
2050
+
2051
+            $output = '';
2052
+            if ( $this->block_show_advanced() ) {
2053
+                $val = 1;
2054
+            } else {
2055
+                $val = 0;
2056
+            }
2057
+
2058
+            $output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
2059
+
2060
+            return $output;
2061
+        }
2062
+
2063
+        /**
2064
+         * Convert require element.
2065
+         *
2066
+         * @since 1.0.0
2067
+         *
2068
+         * @param string $input Input element.
2069
+         *
2070
+         * @return string $output
2071
+         */
2072
+        public function convert_element_require( $input ) {
2073
+
2074
+            $input = str_replace( "'", '"', $input );// we only want double quotes
2075
+
2076
+            $output = esc_attr( str_replace( array( "[%", "%]" ), array(
2077
+                "jQuery(form).find('[data-argument=\"",
2078
+                "\"]').find('input,select').val()"
2079
+            ), $input ) );
2080
+
2081
+            return $output;
2082
+        }
2083
+
2084
+        /**
2085
+         * Builds the inputs for the widget options.
2086
+         *
2087
+         * @param $args
2088
+         * @param $instance
2089
+         */
2090
+        public function widget_inputs( $args, $instance ) {
2091
+
2092
+            $class             = "";
2093
+            $element_require   = "";
2094
+            $custom_attributes = "";
2095
+
2096
+            // get value
2097
+            if ( isset( $instance[ $args['name'] ] ) ) {
2098
+                $value = $instance[ $args['name'] ];
2099
+            } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
2100
+                $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
2101
+            } else {
2102
+                $value = '';
2103
+            }
2104
+
2105
+            // get placeholder
2106
+            if ( ! empty( $args['placeholder'] ) ) {
2107
+                $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
2108
+            } else {
2109
+                $placeholder = '';
2110
+            }
2111
+
2112
+            // get if advanced
2113
+            if ( isset( $args['advanced'] ) && $args['advanced'] ) {
2114
+                $class .= " sd-advanced-setting ";
2115
+            }
2116
+
2117
+            // element_require
2118
+            if ( isset( $args['element_require'] ) && $args['element_require'] ) {
2119
+                $element_require = $args['element_require'];
2120
+            }
2121
+
2122
+            // custom_attributes
2123
+            if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
2124
+                $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
2125
+            }
2126
+
2127
+            // before wrapper
2128
+            ?>
2129 2129
 			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
2130 2130
 			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
2131 2131
 			   data-element_require='<?php if ( $element_require ) {
2132
-				   echo $this->convert_element_require( $element_require );
2133
-			   } ?>'
2132
+                    echo $this->convert_element_require( $element_require );
2133
+                } ?>'
2134 2134
 			>
2135 2135
 				<?php
2136 2136
 
2137
-				switch ( $args['type'] ) {
2138
-					//array('text','password','number','email','tel','url','color')
2139
-					case "text":
2140
-					case "password":
2141
-					case "number":
2142
-					case "email":
2143
-					case "tel":
2144
-					case "url":
2145
-					case "color":
2146
-						?>
2137
+                switch ( $args['type'] ) {
2138
+                    //array('text','password','number','email','tel','url','color')
2139
+                    case "text":
2140
+                    case "password":
2141
+                    case "number":
2142
+                    case "email":
2143
+                    case "tel":
2144
+                    case "url":
2145
+                    case "color":
2146
+                        ?>
2147 2147
 						<label
2148 2148
 							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>
2149 2149
 						<input <?php echo $placeholder; ?> class="widefat"
@@ -2154,47 +2154,47 @@  discard block
 block discarded – undo
2154 2154
 							                               value="<?php echo esc_attr( $value ); ?>">
2155 2155
 						<?php
2156 2156
 
2157
-						break;
2158
-					case "select":
2159
-						$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
2160
-						if ( $multiple ) {
2161
-							if ( empty( $value ) ) {
2162
-								$value = array();
2163
-							}
2164
-						}
2165
-						?>
2157
+                        break;
2158
+                    case "select":
2159
+                        $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
2160
+                        if ( $multiple ) {
2161
+                            if ( empty( $value ) ) {
2162
+                                $value = array();
2163
+                            }
2164
+                        }
2165
+                        ?>
2166 2166
 						<label
2167 2167
 							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>
2168 2168
 						<select <?php echo $placeholder; ?> class="widefat"
2169 2169
 							<?php echo $custom_attributes; ?>
2170 2170
 							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2171 2171
 							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
2172
-							                                if ( $multiple ) {
2173
-								                                echo "[]";
2174
-							                                } ?>"
2172
+                                                            if ( $multiple ) {
2173
+                                                                echo "[]";
2174
+                                                            } ?>"
2175 2175
 							<?php if ( $multiple ) {
2176
-								echo "multiple";
2177
-							} //@todo not implemented yet due to gutenberg not supporting it
2178
-							?>
2176
+                                echo "multiple";
2177
+                            } //@todo not implemented yet due to gutenberg not supporting it
2178
+                            ?>
2179 2179
 						>
2180 2180
 							<?php
2181 2181
 
2182
-							if ( ! empty( $args['options'] ) ) {
2183
-								foreach ( $args['options'] as $val => $label ) {
2184
-									if ( $multiple ) {
2185
-										$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
2186
-									} else {
2187
-										$selected = selected( $value, $val, false );
2188
-									}
2189
-									echo "<option value='$val' " . $selected . ">$label</option>";
2190
-								}
2191
-							}
2192
-							?>
2182
+                            if ( ! empty( $args['options'] ) ) {
2183
+                                foreach ( $args['options'] as $val => $label ) {
2184
+                                    if ( $multiple ) {
2185
+                                        $selected = in_array( $val, $value ) ? 'selected="selected"' : '';
2186
+                                    } else {
2187
+                                        $selected = selected( $value, $val, false );
2188
+                                    }
2189
+                                    echo "<option value='$val' " . $selected . ">$label</option>";
2190
+                                }
2191
+                            }
2192
+                            ?>
2193 2193
 						</select>
2194 2194
 						<?php
2195
-						break;
2196
-					case "checkbox":
2197
-						?>
2195
+                        break;
2196
+                    case "checkbox":
2197
+                        ?>
2198 2198
 						<input <?php echo $placeholder; ?>
2199 2199
 							<?php checked( 1, $value, true ) ?>
2200 2200
 							<?php echo $custom_attributes; ?>
@@ -2204,136 +2204,136 @@  discard block
 block discarded – undo
2204 2204
 						<label
2205 2205
 							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>
2206 2206
 						<?php
2207
-						break;
2208
-					case "hidden":
2209
-						?>
2207
+                        break;
2208
+                    case "hidden":
2209
+                        ?>
2210 2210
 						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2211 2211
 						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
2212 2212
 						       value="<?php echo esc_attr( $value ); ?>">
2213 2213
 						<?php
2214
-						break;
2215
-					default:
2216
-						echo "No input type found!"; // @todo we need to add more input types.
2217
-				}
2214
+                        break;
2215
+                    default:
2216
+                        echo "No input type found!"; // @todo we need to add more input types.
2217
+                }
2218 2218
 
2219
-				// after wrapper
2220
-				?>
2219
+                // after wrapper
2220
+                ?>
2221 2221
 			</p>
2222 2222
 			<?php
2223 2223
 
2224
-		}
2225
-
2226
-		/**
2227
-		 * Get the widget input description html.
2228
-		 *
2229
-		 * @param $args
2230
-		 *
2231
-		 * @return string
2232
-		 * @todo, need to make its own tooltip script
2233
-		 */
2234
-		public function widget_field_desc( $args ) {
2235
-
2236
-			$description = '';
2237
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
2238
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
2239
-					$description = $this->desc_tip( $args['desc'] );
2240
-				} else {
2241
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
2242
-				}
2243
-			}
2244
-
2245
-			return $description;
2246
-		}
2247
-
2248
-		/**
2249
-		 * Get the tool tip html.
2250
-		 *
2251
-		 * @param $tip
2252
-		 * @param bool $allow_html
2253
-		 *
2254
-		 * @return string
2255
-		 */
2256
-		function desc_tip( $tip, $allow_html = false ) {
2257
-			if ( $allow_html ) {
2258
-				$tip = $this->sanitize_tooltip( $tip );
2259
-			} else {
2260
-				$tip = esc_attr( $tip );
2261
-			}
2262
-
2263
-			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
2264
-		}
2265
-
2266
-		/**
2267
-		 * Sanitize a string destined to be a tooltip.
2268
-		 *
2269
-		 * @param string $var
2270
-		 *
2271
-		 * @return string
2272
-		 */
2273
-		public function sanitize_tooltip( $var ) {
2274
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
2275
-				'br'     => array(),
2276
-				'em'     => array(),
2277
-				'strong' => array(),
2278
-				'small'  => array(),
2279
-				'span'   => array(),
2280
-				'ul'     => array(),
2281
-				'li'     => array(),
2282
-				'ol'     => array(),
2283
-				'p'      => array(),
2284
-			) ) );
2285
-		}
2286
-
2287
-		/**
2288
-		 * Processing widget options on save
2289
-		 *
2290
-		 * @param array $new_instance The new options
2291
-		 * @param array $old_instance The previous options
2292
-		 *
2293
-		 * @return array
2294
-		 * @todo we should add some sanitation here.
2295
-		 */
2296
-		public function update( $new_instance, $old_instance ) {
2297
-
2298
-			//save the widget
2299
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
2300
-
2301
-			// set widget instance
2302
-			$this->instance = $instance;
2303
-
2304
-			if ( empty( $this->arguments ) ) {
2305
-				$this->get_arguments();
2306
-			}
2307
-
2308
-			// check for checkboxes
2309
-			if ( ! empty( $this->arguments ) ) {
2310
-				foreach ( $this->arguments as $argument ) {
2311
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
2312
-						$instance[ $argument['name'] ] = '0';
2313
-					}
2314
-				}
2315
-			}
2316
-
2317
-			return $instance;
2318
-		}
2319
-
2320
-		/**
2321
-		 * Checks if the current call is a ajax call to get the block content.
2322
-		 *
2323
-		 * This can be used in your widget to return different content as the block content.
2324
-		 *
2325
-		 * @since 1.0.3
2326
-		 * @return bool
2327
-		 */
2328
-		public function is_block_content_call() {
2329
-			$result = false;
2330
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
2331
-				$result = true;
2332
-			}
2333
-
2334
-			return $result;
2335
-		}
2336
-
2337
-	}
2224
+        }
2225
+
2226
+        /**
2227
+         * Get the widget input description html.
2228
+         *
2229
+         * @param $args
2230
+         *
2231
+         * @return string
2232
+         * @todo, need to make its own tooltip script
2233
+         */
2234
+        public function widget_field_desc( $args ) {
2235
+
2236
+            $description = '';
2237
+            if ( isset( $args['desc'] ) && $args['desc'] ) {
2238
+                if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
2239
+                    $description = $this->desc_tip( $args['desc'] );
2240
+                } else {
2241
+                    $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
2242
+                }
2243
+            }
2244
+
2245
+            return $description;
2246
+        }
2247
+
2248
+        /**
2249
+         * Get the tool tip html.
2250
+         *
2251
+         * @param $tip
2252
+         * @param bool $allow_html
2253
+         *
2254
+         * @return string
2255
+         */
2256
+        function desc_tip( $tip, $allow_html = false ) {
2257
+            if ( $allow_html ) {
2258
+                $tip = $this->sanitize_tooltip( $tip );
2259
+            } else {
2260
+                $tip = esc_attr( $tip );
2261
+            }
2262
+
2263
+            return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
2264
+        }
2265
+
2266
+        /**
2267
+         * Sanitize a string destined to be a tooltip.
2268
+         *
2269
+         * @param string $var
2270
+         *
2271
+         * @return string
2272
+         */
2273
+        public function sanitize_tooltip( $var ) {
2274
+            return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
2275
+                'br'     => array(),
2276
+                'em'     => array(),
2277
+                'strong' => array(),
2278
+                'small'  => array(),
2279
+                'span'   => array(),
2280
+                'ul'     => array(),
2281
+                'li'     => array(),
2282
+                'ol'     => array(),
2283
+                'p'      => array(),
2284
+            ) ) );
2285
+        }
2286
+
2287
+        /**
2288
+         * Processing widget options on save
2289
+         *
2290
+         * @param array $new_instance The new options
2291
+         * @param array $old_instance The previous options
2292
+         *
2293
+         * @return array
2294
+         * @todo we should add some sanitation here.
2295
+         */
2296
+        public function update( $new_instance, $old_instance ) {
2297
+
2298
+            //save the widget
2299
+            $instance = array_merge( (array) $old_instance, (array) $new_instance );
2300
+
2301
+            // set widget instance
2302
+            $this->instance = $instance;
2303
+
2304
+            if ( empty( $this->arguments ) ) {
2305
+                $this->get_arguments();
2306
+            }
2307
+
2308
+            // check for checkboxes
2309
+            if ( ! empty( $this->arguments ) ) {
2310
+                foreach ( $this->arguments as $argument ) {
2311
+                    if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
2312
+                        $instance[ $argument['name'] ] = '0';
2313
+                    }
2314
+                }
2315
+            }
2316
+
2317
+            return $instance;
2318
+        }
2319
+
2320
+        /**
2321
+         * Checks if the current call is a ajax call to get the block content.
2322
+         *
2323
+         * This can be used in your widget to return different content as the block content.
2324
+         *
2325
+         * @since 1.0.3
2326
+         * @return bool
2327
+         */
2328
+        public function is_block_content_call() {
2329
+            $result = false;
2330
+            if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
2331
+                $result = true;
2332
+            }
2333
+
2334
+            return $result;
2335
+        }
2336
+
2337
+    }
2338 2338
 
2339 2339
 }
2340 2340
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +364 added lines, -364 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
 	/**
@@ -37,27 +37,27 @@  discard block
 block discarded – undo
37 37
 		/**
38 38
 		 * Take the array options and use them to build.
39 39
 		 */
40
-		public function __construct( $options ) {
40
+		public function __construct($options) {
41 41
 			global $sd_widgets;
42 42
 
43
-			$sd_widgets[ $options['base_id'] ] = array(
43
+			$sd_widgets[$options['base_id']] = array(
44 44
 				'name'       => $options['name'],
45 45
 				'class_name' => $options['class_name']
46 46
 			);
47
-			$this->base_id                     = $options['base_id'];
47
+			$this->base_id = $options['base_id'];
48 48
 			// lets filter the options before we do anything
49
-			$options       = apply_filters( "wp_super_duper_options", $options );
50
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
51
-			$options       = $this->add_name_from_key( $options );
49
+			$options       = apply_filters("wp_super_duper_options", $options);
50
+			$options       = apply_filters("wp_super_duper_options_{$this->base_id}", $options);
51
+			$options       = $this->add_name_from_key($options);
52 52
 			$this->options = $options;
53 53
 
54 54
 			$this->base_id   = $options['base_id'];
55
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
55
+			$this->arguments = isset($options['arguments']) ? $options['arguments'] : array();
56 56
 
57 57
 			// init parent
58
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
58
+			parent::__construct($options['base_id'], $options['name'], $options['widget_ops']);
59 59
 
60
-			if ( isset( $options['class_name'] ) ) {
60
+			if (isset($options['class_name'])) {
61 61
 				// register widget
62 62
 				$this->class_name = $options['class_name'];
63 63
 
@@ -65,43 +65,43 @@  discard block
 block discarded – undo
65 65
 				$this->register_shortcode();
66 66
 
67 67
 				// register block
68
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
68
+				add_action('admin_enqueue_scripts', array($this, 'register_block'));
69 69
 			}
70 70
 
71 71
 			// add the CSS and JS we need ONCE
72 72
 			global $sd_widget_scripts;
73 73
 
74
-			if ( ! $sd_widget_scripts ) {
75
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
76
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
77
-				wp_add_inline_style( 'widgets', $this->widget_css() );
74
+			if (!$sd_widget_scripts) {
75
+				wp_add_inline_script('admin-widgets', $this->widget_js());
76
+				wp_add_inline_script('customize-controls', $this->widget_js());
77
+				wp_add_inline_style('widgets', $this->widget_css());
78 78
 
79 79
 				$sd_widget_scripts = true;
80 80
 
81 81
 				// add shortcode insert button once
82
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
83
-				if ( $this->is_preview() ) {
84
-					add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) );
82
+				add_action('media_buttons', array($this, 'shortcode_insert_button'));
83
+				if ($this->is_preview()) {
84
+					add_action('wp_footer', array($this, 'shortcode_insert_button_script'));
85 85
 					// this makes the insert button work for elementor
86
-					add_action( 'elementor/editor/after_enqueue_scripts', array(
86
+					add_action('elementor/editor/after_enqueue_scripts', array(
87 87
 						$this,
88 88
 						'shortcode_insert_button_script'
89
-					) ); // for elementor
89
+					)); // for elementor
90 90
 				}
91 91
 				// this makes the insert button work for cornerstone
92
-				add_action( 'cornerstone_load_builder', array(
92
+				add_action('cornerstone_load_builder', array(
93 93
 					$this,
94 94
 					'shortcode_insert_button_script'
95
-				) ); // for cornerstone builder (this is the preview)
95
+				)); // for cornerstone builder (this is the preview)
96 96
 
97
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
98
-				add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) );
97
+				add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings'));
98
+				add_action('wp_ajax_super_duper_get_picker', array(__CLASS__, 'get_picker'));
99 99
 
100 100
 				// add generator text to admin head
101
-				add_action( 'admin_head', array( $this, 'generator' ) );
101
+				add_action('admin_head', array($this, 'generator'));
102 102
 			}
103 103
 
104
-			do_action( 'wp_super_duper_widget_init', $options, $this );
104
+			do_action('wp_super_duper_widget_init', $options, $this);
105 105
 		}
106 106
 
107 107
 		/**
@@ -111,12 +111,12 @@  discard block
 block discarded – undo
111 111
 		 *
112 112
 		 * @return string
113 113
 		 */
114
-		public static function get_picker( $editor_id = '' ) {
114
+		public static function get_picker($editor_id = '') {
115 115
 
116 116
 			ob_start();
117
-			if ( isset( $_POST['editor_id'] ) ) {
118
-				$editor_id = esc_attr( $_POST['editor_id'] );
119
-			} elseif ( isset( $_REQUEST['et_fb'] ) ) {
117
+			if (isset($_POST['editor_id'])) {
118
+				$editor_id = esc_attr($_POST['editor_id']);
119
+			} elseif (isset($_REQUEST['et_fb'])) {
120 120
 				$editor_id = 'main_content_content_vb_tiny_mce';
121 121
 			}
122 122
 
@@ -125,12 +125,12 @@  discard block
 block discarded – undo
125 125
 
126 126
 			<div class="sd-shortcode-left-wrap">
127 127
 				<?php
128
-				asort( $sd_widgets );
129
-				if ( ! empty( $sd_widgets ) ) {
128
+				asort($sd_widgets);
129
+				if (!empty($sd_widgets)) {
130 130
 					echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">';
131
-					echo "<option>" . __( 'Select shortcode' ) . "</option>";
132
-					foreach ( $sd_widgets as $shortcode => $class ) {
133
-						echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
131
+					echo "<option>" . __('Select shortcode') . "</option>";
132
+					foreach ($sd_widgets as $shortcode => $class) {
133
+						echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>";
134 134
 					}
135 135
 					echo "</select>";
136 136
 
@@ -143,37 +143,37 @@  discard block
 block discarded – undo
143 143
 			<div class="sd-shortcode-right-wrap">
144 144
 				<textarea id='sd-shortcode-output' disabled></textarea>
145 145
 				<div id='sd-shortcode-output-actions'>
146
-					<?php if ( $editor_id != '' ) { ?>
146
+					<?php if ($editor_id != '') { ?>
147 147
 						<button class="button sd-insert-shortcode-button"
148
-						        onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) {
148
+						        onclick="sd_insert_shortcode(<?php if (!empty($editor_id)) {
149 149
 							        echo "'" . $editor_id . "'";
150
-						        } ?>)"><?php _e( 'Insert shortcode' ); ?></button>
150
+						        } ?>)"><?php _e('Insert shortcode'); ?></button>
151 151
 					<?php } ?>
152 152
 					<button class="button"
153
-					        onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button>
153
+					        onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button>
154 154
 				</div>
155 155
 			</div>
156 156
 			<?php
157 157
 
158 158
 			$html = ob_get_clean();
159 159
 
160
-			if ( wp_doing_ajax() ) {
160
+			if (wp_doing_ajax()) {
161 161
 				echo $html;
162 162
 				$should_die = true;
163 163
 
164 164
 				// some builder get the editor via ajax so we should not die on those ocasions
165 165
 				$dont_die = array(
166
-					'parent_tag',// WP Bakery
166
+					'parent_tag', // WP Bakery
167 167
 					'avia_request' // enfold
168 168
 				);
169 169
 
170
-				foreach ( $dont_die as $request ) {
171
-					if ( isset( $_REQUEST[ $request ] ) ) {
170
+				foreach ($dont_die as $request) {
171
+					if (isset($_REQUEST[$request])) {
172 172
 						$should_die = false;
173 173
 					}
174 174
 				}
175 175
 
176
-				if ( $should_die ) {
176
+				if ($should_die) {
177 177
 					wp_die();
178 178
 				}
179 179
 
@@ -200,16 +200,16 @@  discard block
 block discarded – undo
200 200
 		public static function get_widget_settings() {
201 201
 			global $sd_widgets;
202 202
 
203
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
204
-			if ( ! $shortcode ) {
203
+			$shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : '';
204
+			if (!$shortcode) {
205 205
 				wp_die();
206 206
 			}
207
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
208
-			if ( ! $widget_args ) {
207
+			$widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : '';
208
+			if (!$widget_args) {
209 209
 				wp_die();
210 210
 			}
211
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
212
-			if ( ! $class_name ) {
211
+			$class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
212
+			if (!$class_name) {
213 213
 				wp_die();
214 214
 			}
215 215
 
@@ -217,7 +217,7 @@  discard block
 block discarded – undo
217 217
 			$widget = new $class_name;
218 218
 
219 219
 			ob_start();
220
-			$widget->form( array() );
220
+			$widget->form(array());
221 221
 			$form = ob_get_clean();
222 222
 			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
223 223
 			echo "<style>" . $widget->widget_css() . "</style>";
@@ -235,9 +235,9 @@  discard block
 block discarded – undo
235 235
 		 * @param string $editor_id Optional. Shortcode editor id. Default null.
236 236
 		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
237 237
 		 */
238
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
238
+		public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') {
239 239
 			global $sd_widgets, $shortcode_insert_button_once;
240
-			if ( $shortcode_insert_button_once ) {
240
+			if ($shortcode_insert_button_once) {
241 241
 				return;
242 242
 			}
243 243
 			add_thickbox();
@@ -247,18 +247,18 @@  discard block
 block discarded – undo
247 247
 			 * Cornerstone makes us play dirty tricks :/
248 248
 			 * 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.
249 249
 			 */
250
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
250
+			if (function_exists('cornerstone_plugin_init') && !is_admin()) {
251 251
 				echo '<span id="insert-media-button">';
252 252
 			}
253 253
 
254
-			echo self::shortcode_button( 'this', 'true' );
254
+			echo self::shortcode_button('this', 'true');
255 255
 
256 256
 			// see opening note
257
-			if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) {
257
+			if (function_exists('cornerstone_plugin_init') && !is_admin()) {
258 258
 				echo '</span>'; // end #insert-media-button
259 259
 			}
260 260
 
261
-			self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function );
261
+			self::shortcode_insert_button_script($editor_id, $insert_shortcode_function);
262 262
 			$shortcode_insert_button_once = true;
263 263
 		}
264 264
 
@@ -270,12 +270,12 @@  discard block
 block discarded – undo
270 270
 		 *
271 271
 		 * @return mixed
272 272
 		 */
273
-		public static function shortcode_button( $id = '', $search_for_id = '' ) {
273
+		public static function shortcode_button($id = '', $search_for_id = '') {
274 274
 			ob_start();
275 275
 			?>
276 276
 			<span class="sd-lable-shortcode-inserter">
277 277
 				<a onclick="sd_ajax_get_picker(<?php echo $id;
278
-				if ( $search_for_id ) {
278
+				if ($search_for_id) {
279 279
 					echo "," . $search_for_id;
280 280
 				} ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed"
281 281
 				   class="thickbox button super-duper-content-open" title="Add Shortcode">
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 			$html = ob_get_clean();
292 292
 
293 293
 			// remove line breaks so we can use it in js
294
-			return preg_replace( "/\r|\n/", "", trim( $html ) );
294
+			return preg_replace("/\r|\n/", "", trim($html));
295 295
 		}
296 296
 
297 297
 		/**
@@ -349,7 +349,7 @@  discard block
 block discarded – undo
349 349
 						jQuery($this).data('sd-widget-enabled', true);
350 350
 					}
351 351
 
352
-					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>';
352
+					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>';
353 353
 					var form = jQuery($this).parents('' + $selector + '');
354 354
 
355 355
 					if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) {
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
387 387
 			 */
388 388
 
389
-			return str_replace( array(
389
+			return str_replace(array(
390 390
 				'<script>',
391 391
 				'</script>'
392
-			), '', $output );
392
+			), '', $output);
393 393
 		}
394 394
 
395 395
 		/**
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 		 * @param string $editor_id
401 401
 		 * @param string $insert_shortcode_function
402 402
 		 */
403
-		public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) {
403
+		public static function shortcode_insert_button_script($editor_id = '', $insert_shortcode_function = '') {
404 404
 			?>
405 405
 			<style>
406 406
 				.sd-shortcode-left-wrap {
@@ -520,15 +520,15 @@  discard block
 block discarded – undo
520 520
 				}
521 521
 			</style>
522 522
 			<?php
523
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
523
+			if (class_exists('SiteOrigin_Panels')) {
524 524
 				echo "<script>" . self::siteorigin_js() . "</script>";
525 525
 			}
526 526
 			?>
527 527
 			<script>
528 528
 				<?php
529
-				if(! empty( $insert_shortcode_function )){
529
+				if (!empty($insert_shortcode_function)) {
530 530
 					echo $insert_shortcode_function;
531
-				}else{
531
+				} else {
532 532
 
533 533
 				/**
534 534
 				 * Function for super duper insert shortcode.
@@ -543,9 +543,9 @@  discard block
 block discarded – undo
543 543
 						if (!$editor_id) {
544 544
 
545 545
 							<?php
546
-							if ( isset( $_REQUEST['et_fb'] ) ) {
546
+							if (isset($_REQUEST['et_fb'])) {
547 547
 								echo '$editor_id = "#main_content_content_vb_tiny_mce";';
548
-							} elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) {
548
+							} elseif (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') {
549 549
 								echo '$editor_id = "#elementor-controls .wp-editor-container textarea";';
550 550
 							} else {
551 551
 								echo '$editor_id = "#wp-content-editor-container textarea";';
@@ -625,11 +625,11 @@  discard block
 block discarded – undo
625 625
 							'shortcode': $short_code,
626 626
 							'attributes': 123,
627 627
 							'post_id': 321,
628
-							'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
628
+							'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
629 629
 						};
630 630
 
631 631
 						if (typeof ajaxurl === 'undefined') {
632
-							var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' );?>";
632
+							var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
633 633
 						}
634 634
 
635 635
 						jQuery.post(ajaxurl, data, function (response) {
@@ -818,11 +818,11 @@  discard block
 block discarded – undo
818 818
 					var data = {
819 819
 						'action': 'super_duper_get_picker',
820 820
 						'editor_id': $id,
821
-						'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_picker' );?>'
821
+						'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_picker'); ?>'
822 822
 					};
823 823
 
824 824
 					if (!ajaxurl) {
825
-						var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
825
+						var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>";
826 826
 					}
827 827
 
828 828
 					jQuery.post(ajaxurl, data, function (response) {
@@ -843,9 +843,9 @@  discard block
 block discarded – undo
843 843
 				 */
844 844
 				function sd_shortcode_button($id) {
845 845
 					if ($id) {
846
-						return '<?php echo self::shortcode_button( "\\''+\$id+'\\'" );?>';
846
+						return '<?php echo self::shortcode_button("\\''+\$id+'\\'"); ?>';
847 847
 					} else {
848
-						return '<?php echo self::shortcode_button();?>';
848
+						return '<?php echo self::shortcode_button(); ?>';
849 849
 					}
850 850
 				}
851 851
 
@@ -888,10 +888,10 @@  discard block
 block discarded – undo
888 888
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
889 889
 			 */
890 890
 
891
-			return str_replace( array(
891
+			return str_replace(array(
892 892
 				'<style>',
893 893
 				'</style>'
894
-			), '', $output );
894
+			), '', $output);
895 895
 		}
896 896
 
897 897
 		/**
@@ -961,7 +961,7 @@  discard block
 block discarded – undo
961 961
 						jQuery($this).data('sd-widget-enabled', true);
962 962
 					}
963 963
 
964
-					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>';
964
+					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>';
965 965
 					var form = jQuery($this).parents('' + $selector + '');
966 966
 
967 967
 					if (jQuery($this).val() == '1' && jQuery(form).find('.sd-advanced-button').length == 0) {
@@ -1053,7 +1053,7 @@  discard block
 block discarded – undo
1053 1053
 					});
1054 1054
 
1055 1055
 				}
1056
-				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
1056
+				<?php do_action('wp_super_duper_widget_js', $this); ?>
1057 1057
 			</script>
1058 1058
 			<?php
1059 1059
 			$output = ob_get_clean();
@@ -1062,10 +1062,10 @@  discard block
 block discarded – undo
1062 1062
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1063 1063
 			 */
1064 1064
 
1065
-			return str_replace( array(
1065
+			return str_replace(array(
1066 1066
 				'<script>',
1067 1067
 				'</script>'
1068
-			), '', $output );
1068
+			), '', $output);
1069 1069
 		}
1070 1070
 
1071 1071
 
@@ -1076,14 +1076,14 @@  discard block
 block discarded – undo
1076 1076
 		 *
1077 1077
 		 * @return mixed
1078 1078
 		 */
1079
-		private function add_name_from_key( $options, $arguments = false ) {
1080
-			if ( ! empty( $options['arguments'] ) ) {
1081
-				foreach ( $options['arguments'] as $key => $val ) {
1082
-					$options['arguments'][ $key ]['name'] = $key;
1079
+		private function add_name_from_key($options, $arguments = false) {
1080
+			if (!empty($options['arguments'])) {
1081
+				foreach ($options['arguments'] as $key => $val) {
1082
+					$options['arguments'][$key]['name'] = $key;
1083 1083
 				}
1084
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
1085
-				foreach ( $options as $key => $val ) {
1086
-					$options[ $key ]['name'] = $key;
1084
+			} elseif ($arguments && is_array($options) && !empty($options)) {
1085
+				foreach ($options as $key => $val) {
1086
+					$options[$key]['name'] = $key;
1087 1087
 				}
1088 1088
 			}
1089 1089
 
@@ -1096,8 +1096,8 @@  discard block
 block discarded – undo
1096 1096
 		 * @since 1.0.0
1097 1097
 		 */
1098 1098
 		public function register_shortcode() {
1099
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
1100
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
1099
+			add_shortcode($this->base_id, array($this, 'shortcode_output'));
1100
+			add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode'));
1101 1101
 		}
1102 1102
 
1103 1103
 		/**
@@ -1107,33 +1107,33 @@  discard block
 block discarded – undo
1107 1107
 		 */
1108 1108
 		public static function render_shortcode() {
1109 1109
 
1110
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
1111
-			if ( ! current_user_can( 'manage_options' ) ) {
1110
+			check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true);
1111
+			if (!current_user_can('manage_options')) {
1112 1112
 				wp_die();
1113 1113
 			}
1114 1114
 
1115 1115
 			// we might need the $post value here so lets set it.
1116
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
1117
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
1118
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
1116
+			if (isset($_POST['post_id']) && $_POST['post_id']) {
1117
+				$post_obj = get_post(absint($_POST['post_id']));
1118
+				if (!empty($post_obj) && empty($post)) {
1119 1119
 					global $post;
1120 1120
 					$post = $post_obj;
1121 1121
 				}
1122 1122
 			}
1123 1123
 
1124
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
1125
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
1126
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
1124
+			if (isset($_POST['shortcode']) && $_POST['shortcode']) {
1125
+				$shortcode_name   = sanitize_title_with_dashes($_POST['shortcode']);
1126
+				$attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array();
1127 1127
 				$attributes       = '';
1128
-				if ( ! empty( $attributes_array ) ) {
1129
-					foreach ( $attributes_array as $key => $value ) {
1130
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
1128
+				if (!empty($attributes_array)) {
1129
+					foreach ($attributes_array as $key => $value) {
1130
+						$attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' ";
1131 1131
 					}
1132 1132
 				}
1133 1133
 
1134 1134
 				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
1135 1135
 
1136
-				echo do_shortcode( $shortcode );
1136
+				echo do_shortcode($shortcode);
1137 1137
 
1138 1138
 			}
1139 1139
 			wp_die();
@@ -1147,37 +1147,37 @@  discard block
 block discarded – undo
1147 1147
 		 *
1148 1148
 		 * @return string
1149 1149
 		 */
1150
-		public function shortcode_output( $args = array(), $content = '' ) {
1151
-			$args = self::argument_values( $args );
1150
+		public function shortcode_output($args = array(), $content = '') {
1151
+			$args = self::argument_values($args);
1152 1152
 
1153 1153
 			// add extra argument so we know its a output to gutenberg
1154 1154
 			//$args
1155
-			$args = $this->string_to_bool( $args );
1155
+			$args = $this->string_to_bool($args);
1156 1156
 
1157 1157
 
1158
-			$calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
1158
+			$calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : '';
1159 1159
 
1160
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
1161
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
1160
+			$calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this);
1161
+			$calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this);
1162 1162
 
1163
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
1164
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
1163
+			$attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this);
1164
+			$attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this);
1165 1165
 
1166 1166
 			$shortcode_args = array();
1167 1167
 			$output         = '';
1168
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
1169
-			$main_content   = $this->output( $args, $shortcode_args, $content );
1170
-			if ( $main_content && ! $no_wrap ) {
1168
+			$no_wrap        = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false;
1169
+			$main_content   = $this->output($args, $shortcode_args, $content);
1170
+			if ($main_content && !$no_wrap) {
1171 1171
 				// wrap the shortcode in a dive with the same class as the widget
1172 1172
 				$output .= '<div class="' . $calss . '" ' . $attrs . '>';
1173
-				if ( ! empty( $args['title'] ) ) {
1173
+				if (!empty($args['title'])) {
1174 1174
 					// if its a shortcode and there is a title try to grab the title wrappers
1175
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
1176
-					if ( empty( $instance ) ) {
1175
+					$shortcode_args = array('before_title' => '', 'after_title' => '');
1176
+					if (empty($instance)) {
1177 1177
 						global $wp_registered_sidebars;
1178
-						if ( ! empty( $wp_registered_sidebars ) ) {
1179
-							foreach ( $wp_registered_sidebars as $sidebar ) {
1180
-								if ( ! empty( $sidebar['before_title'] ) ) {
1178
+						if (!empty($wp_registered_sidebars)) {
1179
+							foreach ($wp_registered_sidebars as $sidebar) {
1180
+								if (!empty($sidebar['before_title'])) {
1181 1181
 									$shortcode_args['before_title'] = $sidebar['before_title'];
1182 1182
 									$shortcode_args['after_title']  = $sidebar['after_title'];
1183 1183
 									break;
@@ -1185,17 +1185,17 @@  discard block
 block discarded – undo
1185 1185
 							}
1186 1186
 						}
1187 1187
 					}
1188
-					$output .= $this->output_title( $shortcode_args, $args );
1188
+					$output .= $this->output_title($shortcode_args, $args);
1189 1189
 				}
1190 1190
 				$output .= $main_content;
1191 1191
 				$output .= '</div>';
1192
-			} elseif ( $main_content && $no_wrap ) {
1192
+			} elseif ($main_content && $no_wrap) {
1193 1193
 				$output .= $main_content;
1194 1194
 			}
1195 1195
 
1196 1196
 			// if preview show a placeholder if empty
1197
-			if ( $this->is_preview() && $output == '' ) {
1198
-				$output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" );
1197
+			if ($this->is_preview() && $output == '') {
1198
+				$output = $this->preview_placeholder_text("[{" . $this->base_id . "}]");
1199 1199
 			}
1200 1200
 
1201 1201
 			return $output;
@@ -1208,8 +1208,8 @@  discard block
 block discarded – undo
1208 1208
 		 *
1209 1209
 		 * @return string
1210 1210
 		 */
1211
-		public function preview_placeholder_text( $name = '' ) {
1212
-			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>";
1211
+		public function preview_placeholder_text($name = '') {
1212
+			return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf(__('Placeholder for: %s'), $name) . "</div>";
1213 1213
 		}
1214 1214
 
1215 1215
 		/**
@@ -1219,13 +1219,13 @@  discard block
 block discarded – undo
1219 1219
 		 *
1220 1220
 		 * @return mixed
1221 1221
 		 */
1222
-		public function string_to_bool( $options ) {
1222
+		public function string_to_bool($options) {
1223 1223
 			// convert bool strings to booleans
1224
-			foreach ( $options as $key => $val ) {
1225
-				if ( $val == 'false' ) {
1226
-					$options[ $key ] = false;
1227
-				} elseif ( $val == 'true' ) {
1228
-					$options[ $key ] = true;
1224
+			foreach ($options as $key => $val) {
1225
+				if ($val == 'false') {
1226
+					$options[$key] = false;
1227
+				} elseif ($val == 'true') {
1228
+					$options[$key] = true;
1229 1229
 				}
1230 1230
 			}
1231 1231
 
@@ -1239,24 +1239,24 @@  discard block
 block discarded – undo
1239 1239
 		 *
1240 1240
 		 * @return array
1241 1241
 		 */
1242
-		public function argument_values( $instance ) {
1242
+		public function argument_values($instance) {
1243 1243
 			$argument_values = array();
1244 1244
 
1245 1245
 			// set widget instance
1246 1246
 			$this->instance = $instance;
1247 1247
 
1248
-			if ( empty( $this->arguments ) ) {
1248
+			if (empty($this->arguments)) {
1249 1249
 				$this->arguments = $this->get_arguments();
1250 1250
 			}
1251 1251
 
1252
-			if ( ! empty( $this->arguments ) ) {
1253
-				foreach ( $this->arguments as $key => $args ) {
1252
+			if (!empty($this->arguments)) {
1253
+				foreach ($this->arguments as $key => $args) {
1254 1254
 					// set the input name from the key
1255 1255
 					$args['name'] = $key;
1256 1256
 					//
1257
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
1258
-					if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
1259
-						$argument_values[ $key ] = $args['default'];
1257
+					$argument_values[$key] = isset($instance[$key]) ? $instance[$key] : '';
1258
+					if ($argument_values[$key] == '' && isset($args['default'])) {
1259
+						$argument_values[$key] = $args['default'];
1260 1260
 					}
1261 1261
 				}
1262 1262
 			}
@@ -1283,12 +1283,12 @@  discard block
 block discarded – undo
1283 1283
 		 * @return array Get arguments.
1284 1284
 		 */
1285 1285
 		public function get_arguments() {
1286
-			if ( empty( $this->arguments ) ) {
1286
+			if (empty($this->arguments)) {
1287 1287
 				$this->arguments = $this->set_arguments();
1288 1288
 			}
1289 1289
 
1290
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
1291
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
1290
+			$this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance);
1291
+			$this->arguments = $this->add_name_from_key($this->arguments, true);
1292 1292
 
1293 1293
 			return $this->arguments;
1294 1294
 		}
@@ -1300,7 +1300,7 @@  discard block
 block discarded – undo
1300 1300
 		 * @param array $widget_args
1301 1301
 		 * @param string $content
1302 1302
 		 */
1303
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
1303
+		public function output($args = array(), $widget_args = array(), $content = '') {
1304 1304
 
1305 1305
 		}
1306 1306
 
@@ -1308,10 +1308,10 @@  discard block
 block discarded – undo
1308 1308
 		 * Add the dynamic block code inline when the wp-block in enqueued.
1309 1309
 		 */
1310 1310
 		public function register_block() {
1311
-			wp_add_inline_script( 'wp-blocks', $this->block() );
1312
-			if ( class_exists( 'SiteOrigin_Panels' ) ) {
1311
+			wp_add_inline_script('wp-blocks', $this->block());
1312
+			if (class_exists('SiteOrigin_Panels')) {
1313 1313
 
1314
-				wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() );
1314
+				wp_add_inline_script('wp-blocks', $this->siteorigin_js());
1315 1315
 
1316 1316
 			}
1317 1317
 		}
@@ -1326,13 +1326,13 @@  discard block
 block discarded – undo
1326 1326
 			$show      = false;
1327 1327
 			$arguments = $this->arguments;
1328 1328
 
1329
-			if ( empty( $arguments ) ) {
1329
+			if (empty($arguments)) {
1330 1330
 				$arguments = $this->get_arguments();
1331 1331
 			}
1332 1332
 
1333
-			if ( ! empty( $arguments ) ) {
1334
-				foreach ( $arguments as $argument ) {
1335
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
1333
+			if (!empty($arguments)) {
1334
+				foreach ($arguments as $argument) {
1335
+					if (isset($argument['advanced']) && $argument['advanced']) {
1336 1336
 						$show = true;
1337 1337
 					}
1338 1338
 				}
@@ -1384,12 +1384,12 @@  discard block
 block discarded – undo
1384 1384
 					 * @return {?WPBlock}          The block, if it has been successfully
1385 1385
 					 *                             registered; otherwise `undefined`.
1386 1386
 					 */
1387
-					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.
1388
-						title: '<?php echo $this->options['name'];?>', // Block title.
1389
-						description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title.
1390
-						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/.
1391
-						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.
1392
-						<?php if ( isset( $this->options['block-keywords'] ) ) {
1387
+					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.
1388
+						title: '<?php echo $this->options['name']; ?>', // Block title.
1389
+						description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title.
1390
+						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/.
1391
+						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.
1392
+						<?php if (isset($this->options['block-keywords'])) {
1393 1393
 						echo "keywords : " . $this->options['block-keywords'] . ",";
1394 1394
 					}?>
1395 1395
 
@@ -1399,10 +1399,10 @@  discard block
 block discarded – undo
1399 1399
 
1400 1400
 						$show_alignment = false;
1401 1401
 
1402
-						if ( ! empty( $this->arguments ) ) {
1402
+						if (!empty($this->arguments)) {
1403 1403
 							echo "attributes : {";
1404 1404
 
1405
-							if ( $show_advanced ) {
1405
+							if ($show_advanced) {
1406 1406
 								echo "show_advanced: {";
1407 1407
 								echo "	type: 'boolean',";
1408 1408
 								echo "  default: false,";
@@ -1410,42 +1410,42 @@  discard block
 block discarded – undo
1410 1410
 							}
1411 1411
 
1412 1412
 							// block wrap element
1413
-							if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
1413
+							if (isset($this->options['block-wrap'])) { //@todo we should validate this?
1414 1414
 								echo "block_wrap: {";
1415 1415
 								echo "	type: 'string',";
1416
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
1416
+								echo "  default: '" . esc_attr($this->options['block-wrap']) . "',";
1417 1417
 								echo "},";
1418 1418
 							}
1419 1419
 
1420 1420
 
1421
-							foreach ( $this->arguments as $key => $args ) {
1421
+							foreach ($this->arguments as $key => $args) {
1422 1422
 
1423 1423
 								// set if we should show alignment
1424
-								if ( $key == 'alignment' ) {
1424
+								if ($key == 'alignment') {
1425 1425
 									$show_alignment = true;
1426 1426
 								}
1427 1427
 
1428 1428
 								$extra = '';
1429 1429
 
1430
-								if ( $args['type'] == 'checkbox' ) {
1430
+								if ($args['type'] == 'checkbox') {
1431 1431
 									$type    = 'boolean';
1432
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
1433
-								} elseif ( $args['type'] == 'number' ) {
1432
+									$default = isset($args['default']) && $args['default'] ? 'true' : 'false';
1433
+								} elseif ($args['type'] == 'number') {
1434 1434
 									$type    = 'number';
1435
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1436
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
1435
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1436
+								} elseif ($args['type'] == 'select' && !empty($args['multiple'])) {
1437 1437
 									$type = 'array';
1438
-									if ( is_array( $args['default'] ) ) {
1439
-										$default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
1438
+									if (is_array($args['default'])) {
1439
+										$default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]";
1440 1440
 									} else {
1441
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1441
+										$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1442 1442
 									}
1443
-								} elseif ( $args['type'] == 'multiselect' ) {
1443
+								} elseif ($args['type'] == 'multiselect') {
1444 1444
 									$type    = 'array';
1445
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1445
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1446 1446
 								} else {
1447 1447
 									$type    = 'string';
1448
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
1448
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
1449 1449
 								}
1450 1450
 								echo $key . " : {";
1451 1451
 								echo "type : '$type',";
@@ -1475,12 +1475,12 @@  discard block
 block discarded – undo
1475 1475
 									is_fetching = true;
1476 1476
 									var data = {
1477 1477
 										'action': 'super_duper_output_shortcode',
1478
-										'shortcode': '<?php echo $this->options['base_id'];?>',
1478
+										'shortcode': '<?php echo $this->options['base_id']; ?>',
1479 1479
 										'attributes': props.attributes,
1480
-										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
1480
+										'post_id': <?php global $post; if (isset($post->ID)) {
1481 1481
 										echo $post->ID;
1482 1482
 									}?>,
1483
-										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
1483
+										'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
1484 1484
 									};
1485 1485
 
1486 1486
 									jQuery.post(ajaxurl, data, function (response) {
@@ -1489,7 +1489,7 @@  discard block
 block discarded – undo
1489 1489
 
1490 1490
 										// if the content is empty then we place some placeholder text
1491 1491
 										if (env == '') {
1492
-											env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>";
1492
+											env = "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>";
1493 1493
 										}
1494 1494
 
1495 1495
 										props.setAttributes({content: env});
@@ -1508,7 +1508,7 @@  discard block
 block discarded – undo
1508 1508
 
1509 1509
 								el(wp.editor.BlockControls, {key: 'controls'},
1510 1510
 
1511
-									<?php if($show_alignment){?>
1511
+									<?php if ($show_alignment) {?>
1512 1512
 									el(
1513 1513
 										wp.editor.AlignmentToolbar,
1514 1514
 										{
@@ -1526,9 +1526,9 @@  discard block
 block discarded – undo
1526 1526
 
1527 1527
 									<?php
1528 1528
 
1529
-									if(! empty( $this->arguments )){
1529
+									if (!empty($this->arguments)) {
1530 1530
 
1531
-									if ( $show_advanced ) {
1531
+									if ($show_advanced) {
1532 1532
 									?>
1533 1533
 									el(
1534 1534
 										wp.components.ToggleControl,
@@ -1544,76 +1544,76 @@  discard block
 block discarded – undo
1544 1544
 
1545 1545
 									}
1546 1546
 
1547
-									foreach($this->arguments as $key => $args){
1548
-									$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
1547
+									foreach ($this->arguments as $key => $args) {
1548
+									$custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : '';
1549 1549
 									$options = '';
1550 1550
 									$extra = '';
1551 1551
 									$require = '';
1552 1552
 									$onchange = "props.setAttributes({ $key: $key } )";
1553 1553
 									$value = "props.attributes.$key";
1554
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1555
-									if ( in_array( $args['type'], $text_type ) ) {
1554
+									$text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color');
1555
+									if (in_array($args['type'], $text_type)) {
1556 1556
 										$type = 'TextControl';
1557 1557
 										// Save numbers as numbers and not strings
1558
-										if ( $args['type'] == 'number' ) {
1558
+										if ($args['type'] == 'number') {
1559 1559
 											$onchange = "props.setAttributes({ $key: Number($key) } )";
1560 1560
 										}
1561 1561
 									}
1562 1562
 //									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
1563 1563
 //										$type = 'ColorPicker';
1564 1564
 //									}
1565
-									elseif ( $args['type'] == 'checkbox' ) {
1565
+									elseif ($args['type'] == 'checkbox') {
1566 1566
 										$type = 'CheckboxControl';
1567 1567
 										$extra .= "checked: props.attributes.$key,";
1568 1568
 										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1569
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1569
+									} elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') {
1570 1570
 										$type = 'SelectControl';
1571
-										if ( ! empty( $args['options'] ) ) {
1571
+										if (!empty($args['options'])) {
1572 1572
 											$options .= "options  : [";
1573
-											foreach ( $args['options'] as $option_val => $option_label ) {
1574
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1573
+											foreach ($args['options'] as $option_val => $option_label) {
1574
+												$options .= "{ value : '" . esc_attr($option_val) . "',     label : '" . esc_attr($option_label) . "'     },";
1575 1575
 											}
1576 1576
 											$options .= "],";
1577 1577
 										}
1578
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1578
+										if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1579 1579
 											$extra .= ' multiple: true, ';
1580 1580
 											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1581 1581
 											//$value = "['edit', 'delete']";
1582 1582
 										}
1583
-									} elseif ( $args['type'] == 'alignment' ) {
1583
+									} elseif ($args['type'] == 'alignment') {
1584 1584
 										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1585 1585
 									} else {
1586
-										continue;// if we have not implemented the control then don't break the JS.
1586
+										continue; // if we have not implemented the control then don't break the JS.
1587 1587
 									}
1588 1588
 
1589 1589
 									// add show only if advanced
1590
-									if ( ! empty( $args['advanced'] ) ) {
1590
+									if (!empty($args['advanced'])) {
1591 1591
 										echo "props.attributes.show_advanced && ";
1592 1592
 									}
1593 1593
 									// add setting require if defined
1594
-									if ( ! empty( $args['element_require'] ) ) {
1595
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1594
+									if (!empty($args['element_require'])) {
1595
+										echo $this->block_props_replace($args['element_require'], true) . " && ";
1596 1596
 									}
1597 1597
 									?>
1598 1598
 									el(
1599
-										wp.components.<?php echo esc_attr( $type );?>,
1599
+										wp.components.<?php echo esc_attr($type); ?>,
1600 1600
 										{
1601
-											label: '<?php echo esc_attr( $args['title'] );?>',
1602
-											help: '<?php if ( isset( $args['desc'] ) ) {
1603
-												echo esc_attr( $args['desc'] );
1601
+											label: '<?php echo esc_attr($args['title']); ?>',
1602
+											help: '<?php if (isset($args['desc'])) {
1603
+												echo esc_attr($args['desc']);
1604 1604
 											}?>',
1605
-											value: <?php echo $value;?>,
1606
-											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1607
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1605
+											value: <?php echo $value; ?>,
1606
+											<?php if ($type == 'TextControl' && $args['type'] != 'text') {
1607
+											echo "type: '" . esc_attr($args['type']) . "',";
1608 1608
 										}?>
1609
-											<?php if ( ! empty( $args['placeholder'] ) ) {
1610
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1609
+											<?php if (!empty($args['placeholder'])) {
1610
+											echo "placeholder: '" . esc_attr($args['placeholder']) . "',";
1611 1611
 										}?>
1612
-											<?php echo $options;?>
1613
-											<?php echo $extra;?>
1614
-											<?php echo $custom_attributes;?>
1615
-											onChange: function ( <?php echo $key;?> ) {
1616
-												<?php echo $onchange;?>
1612
+											<?php echo $options; ?>
1613
+											<?php echo $extra; ?>
1614
+											<?php echo $custom_attributes; ?>
1615
+											onChange: function ( <?php echo $key; ?> ) {
1616
+												<?php echo $onchange; ?>
1617 1617
 											}
1618 1618
 										}
1619 1619
 									),
@@ -1626,9 +1626,9 @@  discard block
 block discarded – undo
1626 1626
 
1627 1627
 								<?php
1628 1628
 								// If the user sets block-output array then build it
1629
-								if ( ! empty( $this->options['block-output'] ) ) {
1630
-								$this->block_element( $this->options['block-output'] );
1631
-							}else{
1629
+								if (!empty($this->options['block-output'])) {
1630
+								$this->block_element($this->options['block-output']);
1631
+							} else {
1632 1632
 								// if no block-output is set then we try and get the shortcode html output via ajax.
1633 1633
 								?>
1634 1634
 								el('div', {
@@ -1652,14 +1652,14 @@  discard block
 block discarded – undo
1652 1652
 							var align = '';
1653 1653
 
1654 1654
 							// build the shortcode.
1655
-							var content = "[<?php echo $this->options['base_id'];?>";
1655
+							var content = "[<?php echo $this->options['base_id']; ?>";
1656 1656
 							<?php
1657 1657
 
1658
-							if(! empty( $this->arguments )){
1659
-							foreach($this->arguments as $key => $args){
1658
+							if (!empty($this->arguments)) {
1659
+							foreach ($this->arguments as $key => $args) {
1660 1660
 							?>
1661
-							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1662
-								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1661
+							if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) {
1662
+								content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' ";
1663 1663
 							}
1664 1664
 							<?php
1665 1665
 							}
@@ -1700,10 +1700,10 @@  discard block
 block discarded – undo
1700 1700
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1701 1701
 			 */
1702 1702
 
1703
-			return str_replace( array(
1703
+			return str_replace(array(
1704 1704
 				'<script>',
1705 1705
 				'</script>'
1706
-			), '', $output );
1706
+			), '', $output);
1707 1707
 		}
1708 1708
 
1709 1709
 		/**
@@ -1715,16 +1715,16 @@  discard block
 block discarded – undo
1715 1715
 		 *
1716 1716
 		 * @return string
1717 1717
 		 */
1718
-		public function array_to_attributes( $custom_attributes, $html = false ) {
1718
+		public function array_to_attributes($custom_attributes, $html = false) {
1719 1719
 			$attributes = '';
1720
-			if ( ! empty( $custom_attributes ) ) {
1720
+			if (!empty($custom_attributes)) {
1721 1721
 
1722
-				if ( $html ) {
1723
-					foreach ( $custom_attributes as $key => $val ) {
1722
+				if ($html) {
1723
+					foreach ($custom_attributes as $key => $val) {
1724 1724
 						$attributes .= " $key='$val' ";
1725 1725
 					}
1726 1726
 				} else {
1727
-					foreach ( $custom_attributes as $key => $val ) {
1727
+					foreach ($custom_attributes as $key => $val) {
1728 1728
 						$attributes .= "'$key': '$val',";
1729 1729
 					}
1730 1730
 				}
@@ -1740,86 +1740,86 @@  discard block
 block discarded – undo
1740 1740
 		 *
1741 1741
 		 * @param $args
1742 1742
 		 */
1743
-		public function block_element( $args ) {
1743
+		public function block_element($args) {
1744 1744
 
1745 1745
 
1746
-			if ( ! empty( $args ) ) {
1747
-				foreach ( $args as $element => $new_args ) {
1746
+			if (!empty($args)) {
1747
+				foreach ($args as $element => $new_args) {
1748 1748
 
1749
-					if ( is_array( $new_args ) ) { // its an element
1749
+					if (is_array($new_args)) { // its an element
1750 1750
 
1751 1751
 
1752
-						if ( isset( $new_args['element'] ) ) {
1752
+						if (isset($new_args['element'])) {
1753 1753
 
1754
-							if ( isset( $new_args['element_require'] ) ) {
1755
-								echo str_replace( array(
1754
+							if (isset($new_args['element_require'])) {
1755
+								echo str_replace(array(
1756 1756
 										"'+",
1757 1757
 										"+'"
1758
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1759
-								unset( $new_args['element_require'] );
1758
+									), '', $this->block_props_replace($new_args['element_require'])) . " &&  ";
1759
+								unset($new_args['element_require']);
1760 1760
 							}
1761 1761
 
1762 1762
 							echo "\n el( '" . $new_args['element'] . "', {";
1763 1763
 
1764 1764
 							// get the attributes
1765
-							foreach ( $new_args as $new_key => $new_value ) {
1765
+							foreach ($new_args as $new_key => $new_value) {
1766 1766
 
1767 1767
 
1768
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1768
+								if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) {
1769 1769
 									// do nothing
1770 1770
 								} else {
1771
-									echo $this->block_element( array( $new_key => $new_value ) );
1771
+									echo $this->block_element(array($new_key => $new_value));
1772 1772
 								}
1773 1773
 							}
1774 1774
 
1775
-							echo "},";// end attributes
1775
+							echo "},"; // end attributes
1776 1776
 
1777 1777
 							// get the content
1778 1778
 							$first_item = 0;
1779
-							foreach ( $new_args as $new_key => $new_value ) {
1780
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1779
+							foreach ($new_args as $new_key => $new_value) {
1780
+								if ($new_key === 'content' || is_array($new_value)) {
1781 1781
 
1782
-									if ( $new_key === 'content' ) {
1783
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1782
+									if ($new_key === 'content') {
1783
+										echo "'" . $this->block_props_replace($new_value) . "'";
1784 1784
 									}
1785 1785
 
1786
-									if ( is_array( $new_value ) ) {
1786
+									if (is_array($new_value)) {
1787 1787
 
1788
-										if ( isset( $new_value['element_require'] ) ) {
1789
-											echo str_replace( array(
1788
+										if (isset($new_value['element_require'])) {
1789
+											echo str_replace(array(
1790 1790
 													"'+",
1791 1791
 													"+'"
1792
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1793
-											unset( $new_value['element_require'] );
1792
+												), '', $this->block_props_replace($new_value['element_require'])) . " &&  ";
1793
+											unset($new_value['element_require']);
1794 1794
 										}
1795 1795
 
1796
-										if ( isset( $new_value['element_repeat'] ) ) {
1796
+										if (isset($new_value['element_repeat'])) {
1797 1797
 											$x = 1;
1798
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1799
-												$this->block_element( array( '' => $new_value ) );
1800
-												$x ++;
1798
+											while ($x <= absint($new_value['element_repeat'])) {
1799
+												$this->block_element(array('' => $new_value));
1800
+												$x++;
1801 1801
 											}
1802 1802
 										} else {
1803
-											$this->block_element( array( '' => $new_value ) );
1803
+											$this->block_element(array('' => $new_value));
1804 1804
 										}
1805 1805
 									}
1806
-									$first_item ++;
1806
+									$first_item++;
1807 1807
 								}
1808 1808
 							}
1809 1809
 
1810
-							echo ")";// end content
1810
+							echo ")"; // end content
1811 1811
 
1812 1812
 							echo ", \n";
1813 1813
 
1814 1814
 						}
1815 1815
 					} else {
1816 1816
 
1817
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1818
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1819
-						} elseif ( $element == 'style' ) {
1820
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1817
+						if (substr($element, 0, 3) === "if_") {
1818
+							echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ",";
1819
+						} elseif ($element == 'style') {
1820
+							echo $element . ": " . $this->block_props_replace($new_args) . ",";
1821 1821
 						} else {
1822
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1822
+							echo $element . ": '" . $this->block_props_replace($new_args) . "',";
1823 1823
 						}
1824 1824
 
1825 1825
 					}
@@ -1834,12 +1834,12 @@  discard block
 block discarded – undo
1834 1834
 		 *
1835 1835
 		 * @return mixed
1836 1836
 		 */
1837
-		public function block_props_replace( $string, $no_wrap = false ) {
1837
+		public function block_props_replace($string, $no_wrap = false) {
1838 1838
 
1839
-			if ( $no_wrap ) {
1840
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1839
+			if ($no_wrap) {
1840
+				$string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string);
1841 1841
 			} else {
1842
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1842
+				$string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string);
1843 1843
 			}
1844 1844
 
1845 1845
 			return $string;
@@ -1851,37 +1851,37 @@  discard block
 block discarded – undo
1851 1851
 		 * @param array $args
1852 1852
 		 * @param array $instance
1853 1853
 		 */
1854
-		public function widget( $args, $instance ) {
1854
+		public function widget($args, $instance) {
1855 1855
 
1856 1856
 			// get the filtered values
1857
-			$argument_values = $this->argument_values( $instance );
1858
-			$argument_values = $this->string_to_bool( $argument_values );
1859
-			$output          = $this->output( $argument_values, $args );
1857
+			$argument_values = $this->argument_values($instance);
1858
+			$argument_values = $this->string_to_bool($argument_values);
1859
+			$output          = $this->output($argument_values, $args);
1860 1860
 
1861
-			if ( $output ) {
1861
+			if ($output) {
1862 1862
 				// Before widget
1863 1863
 				$before_widget = $args['before_widget'];
1864
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1865
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1864
+				$before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this);
1865
+				$before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this);
1866 1866
 
1867 1867
 				// After widget
1868 1868
 				$after_widget = $args['after_widget'];
1869
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1870
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1869
+				$after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this);
1870
+				$after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this);
1871 1871
 
1872 1872
 				echo $before_widget;
1873 1873
 				// elementor strips the widget wrapping div so we check for and add it back if needed
1874
-				if ( $this->is_elementor_widget_output() ) {
1875
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1874
+				if ($this->is_elementor_widget_output()) {
1875
+					echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : '';
1876 1876
 				}
1877
-				echo $this->output_title( $args, $instance );
1877
+				echo $this->output_title($args, $instance);
1878 1878
 				echo $output;
1879
-				if ( $this->is_elementor_widget_output() ) {
1880
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1879
+				if ($this->is_elementor_widget_output()) {
1880
+					echo !empty($this->options['widget_ops']['classname']) ? "</span>" : '';
1881 1881
 				}
1882 1882
 				echo $after_widget;
1883
-			} elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty
1884
-				$output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" );
1883
+			} elseif ($this->is_preview() && $output == '') {// if preview show a placeholder if empty
1884
+				$output = $this->preview_placeholder_text("{{" . $this->base_id . "}}");
1885 1885
 				echo $output;
1886 1886
 			}
1887 1887
 		}
@@ -1894,7 +1894,7 @@  discard block
 block discarded – undo
1894 1894
 		 */
1895 1895
 		public function is_elementor_widget_output() {
1896 1896
 			$result = false;
1897
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1897
+			if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') {
1898 1898
 				$result = true;
1899 1899
 			}
1900 1900
 
@@ -1909,7 +1909,7 @@  discard block
 block discarded – undo
1909 1909
 		 */
1910 1910
 		public function is_elementor_preview() {
1911 1911
 			$result = false;
1912
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) {
1912
+			if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor') || (isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor_ajax')) {
1913 1913
 				$result = true;
1914 1914
 			}
1915 1915
 
@@ -1924,7 +1924,7 @@  discard block
 block discarded – undo
1924 1924
 		 */
1925 1925
 		public function is_divi_preview() {
1926 1926
 			$result = false;
1927
-			if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1927
+			if (isset($_REQUEST['et_fb']) || isset($_REQUEST['et_pb_preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) {
1928 1928
 				$result = true;
1929 1929
 			}
1930 1930
 
@@ -1939,7 +1939,7 @@  discard block
 block discarded – undo
1939 1939
 		 */
1940 1940
 		public function is_beaver_preview() {
1941 1941
 			$result = false;
1942
-			if ( isset( $_REQUEST['fl_builder'] ) ) {
1942
+			if (isset($_REQUEST['fl_builder'])) {
1943 1943
 				$result = true;
1944 1944
 			}
1945 1945
 
@@ -1954,7 +1954,7 @@  discard block
 block discarded – undo
1954 1954
 		 */
1955 1955
 		public function is_siteorigin_preview() {
1956 1956
 			$result = false;
1957
-			if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) {
1957
+			if (!empty($_REQUEST['siteorigin_panels_live_editor'])) {
1958 1958
 				$result = true;
1959 1959
 			}
1960 1960
 
@@ -1969,7 +1969,7 @@  discard block
 block discarded – undo
1969 1969
 		 */
1970 1970
 		public function is_cornerstone_preview() {
1971 1971
 			$result = false;
1972
-			if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) {
1972
+			if (!empty($_REQUEST['cornerstone_preview']) || basename($_SERVER['REQUEST_URI']) == 'cornerstone-endpoint') {
1973 1973
 				$result = true;
1974 1974
 			}
1975 1975
 
@@ -1984,15 +1984,15 @@  discard block
 block discarded – undo
1984 1984
 		 */
1985 1985
 		public function is_preview() {
1986 1986
 			$preview = false;
1987
-			if ( $this->is_divi_preview() ) {
1987
+			if ($this->is_divi_preview()) {
1988 1988
 				$preview = true;
1989
-			} elseif ( $this->is_elementor_preview() ) {
1989
+			} elseif ($this->is_elementor_preview()) {
1990 1990
 				$preview = true;
1991
-			} elseif ( $this->is_beaver_preview() ) {
1991
+			} elseif ($this->is_beaver_preview()) {
1992 1992
 				$preview = true;
1993
-			} elseif ( $this->is_siteorigin_preview() ) {
1993
+			} elseif ($this->is_siteorigin_preview()) {
1994 1994
 				$preview = true;
1995
-			} elseif ( $this->is_cornerstone_preview() ) {
1995
+			} elseif ($this->is_cornerstone_preview()) {
1996 1996
 				$preview = true;
1997 1997
 			}
1998 1998
 
@@ -2007,11 +2007,11 @@  discard block
 block discarded – undo
2007 2007
 		 *
2008 2008
 		 * @return string
2009 2009
 		 */
2010
-		public function output_title( $args, $instance = array() ) {
2010
+		public function output_title($args, $instance = array()) {
2011 2011
 			$output = '';
2012
-			if ( ! empty( $instance['title'] ) ) {
2012
+			if (!empty($instance['title'])) {
2013 2013
 				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
2014
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
2014
+				$title  = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
2015 2015
 				$output = $args['before_title'] . $title . $args['after_title'];
2016 2016
 			}
2017 2017
 
@@ -2023,7 +2023,7 @@  discard block
 block discarded – undo
2023 2023
 		 *
2024 2024
 		 * @param array $instance The widget options.
2025 2025
 		 */
2026
-		public function form( $instance ) {
2026
+		public function form($instance) {
2027 2027
 
2028 2028
 			// set widget instance
2029 2029
 			$this->instance = $instance;
@@ -2031,12 +2031,12 @@  discard block
 block discarded – undo
2031 2031
 			// set it as a SD widget
2032 2032
 			echo $this->widget_advanced_toggle();
2033 2033
 
2034
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
2034
+			echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>";
2035 2035
 			$arguments = $this->get_arguments();
2036 2036
 
2037
-			if ( is_array( $arguments ) ) {
2038
-				foreach ( $arguments as $key => $args ) {
2039
-					$this->widget_inputs( $args, $instance );
2037
+			if (is_array($arguments)) {
2038
+				foreach ($arguments as $key => $args) {
2039
+					$this->widget_inputs($args, $instance);
2040 2040
 				}
2041 2041
 			}
2042 2042
 		}
@@ -2049,7 +2049,7 @@  discard block
 block discarded – undo
2049 2049
 		public function widget_advanced_toggle() {
2050 2050
 
2051 2051
 			$output = '';
2052
-			if ( $this->block_show_advanced() ) {
2052
+			if ($this->block_show_advanced()) {
2053 2053
 				$val = 1;
2054 2054
 			} else {
2055 2055
 				$val = 0;
@@ -2069,14 +2069,14 @@  discard block
 block discarded – undo
2069 2069
 		 *
2070 2070
 		 * @return string $output
2071 2071
 		 */
2072
-		public function convert_element_require( $input ) {
2072
+		public function convert_element_require($input) {
2073 2073
 
2074
-			$input = str_replace( "'", '"', $input );// we only want double quotes
2074
+			$input = str_replace("'", '"', $input); // we only want double quotes
2075 2075
 
2076
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
2076
+			$output = esc_attr(str_replace(array("[%", "%]"), array(
2077 2077
 				"jQuery(form).find('[data-argument=\"",
2078 2078
 				"\"]').find('input,select').val()"
2079
-			), $input ) );
2079
+			), $input));
2080 2080
 
2081 2081
 			return $output;
2082 2082
 		}
@@ -2087,54 +2087,54 @@  discard block
 block discarded – undo
2087 2087
 		 * @param $args
2088 2088
 		 * @param $instance
2089 2089
 		 */
2090
-		public function widget_inputs( $args, $instance ) {
2090
+		public function widget_inputs($args, $instance) {
2091 2091
 
2092 2092
 			$class             = "";
2093 2093
 			$element_require   = "";
2094 2094
 			$custom_attributes = "";
2095 2095
 
2096 2096
 			// get value
2097
-			if ( isset( $instance[ $args['name'] ] ) ) {
2098
-				$value = $instance[ $args['name'] ];
2099
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
2100
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
2097
+			if (isset($instance[$args['name']])) {
2098
+				$value = $instance[$args['name']];
2099
+			} elseif (!isset($instance[$args['name']]) && !empty($args['default'])) {
2100
+				$value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']);
2101 2101
 			} else {
2102 2102
 				$value = '';
2103 2103
 			}
2104 2104
 
2105 2105
 			// get placeholder
2106
-			if ( ! empty( $args['placeholder'] ) ) {
2107
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
2106
+			if (!empty($args['placeholder'])) {
2107
+				$placeholder = "placeholder='" . esc_html($args['placeholder']) . "'";
2108 2108
 			} else {
2109 2109
 				$placeholder = '';
2110 2110
 			}
2111 2111
 
2112 2112
 			// get if advanced
2113
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
2113
+			if (isset($args['advanced']) && $args['advanced']) {
2114 2114
 				$class .= " sd-advanced-setting ";
2115 2115
 			}
2116 2116
 
2117 2117
 			// element_require
2118
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
2118
+			if (isset($args['element_require']) && $args['element_require']) {
2119 2119
 				$element_require = $args['element_require'];
2120 2120
 			}
2121 2121
 
2122 2122
 			// custom_attributes
2123
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
2124
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
2123
+			if (isset($args['custom_attributes']) && $args['custom_attributes']) {
2124
+				$custom_attributes = $this->array_to_attributes($args['custom_attributes'], true);
2125 2125
 			}
2126 2126
 
2127 2127
 			// before wrapper
2128 2128
 			?>
2129
-			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
2130
-			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
2131
-			   data-element_require='<?php if ( $element_require ) {
2132
-				   echo $this->convert_element_require( $element_require );
2129
+			<p class="sd-argument <?php echo esc_attr($class); ?>"
2130
+			   data-argument='<?php echo esc_attr($args['name']); ?>'
2131
+			   data-element_require='<?php if ($element_require) {
2132
+				   echo $this->convert_element_require($element_require);
2133 2133
 			   } ?>'
2134 2134
 			>
2135 2135
 				<?php
2136 2136
 
2137
-				switch ( $args['type'] ) {
2137
+				switch ($args['type']) {
2138 2138
 					//array('text','password','number','email','tel','url','color')
2139 2139
 					case "text":
2140 2140
 					case "password":
@@ -2145,46 +2145,46 @@  discard block
 block discarded – undo
2145 2145
 					case "color":
2146 2146
 						?>
2147 2147
 						<label
2148
-							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>
2148
+							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>
2149 2149
 						<input <?php echo $placeholder; ?> class="widefat"
2150 2150
 							<?php echo $custom_attributes; ?>
2151
-							                               id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2152
-							                               name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>"
2153
-							                               type="<?php echo esc_attr( $args['type'] ); ?>"
2154
-							                               value="<?php echo esc_attr( $value ); ?>">
2151
+							                               id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2152
+							                               name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>"
2153
+							                               type="<?php echo esc_attr($args['type']); ?>"
2154
+							                               value="<?php echo esc_attr($value); ?>">
2155 2155
 						<?php
2156 2156
 
2157 2157
 						break;
2158 2158
 					case "select":
2159
-						$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
2160
-						if ( $multiple ) {
2161
-							if ( empty( $value ) ) {
2159
+						$multiple = isset($args['multiple']) && $args['multiple'] ? true : false;
2160
+						if ($multiple) {
2161
+							if (empty($value)) {
2162 2162
 								$value = array();
2163 2163
 							}
2164 2164
 						}
2165 2165
 						?>
2166 2166
 						<label
2167
-							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>
2167
+							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>
2168 2168
 						<select <?php echo $placeholder; ?> class="widefat"
2169 2169
 							<?php echo $custom_attributes; ?>
2170
-							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2171
-							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
2172
-							                                if ( $multiple ) {
2170
+							                                id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2171
+							                                name="<?php echo esc_attr($this->get_field_name($args['name']));
2172
+							                                if ($multiple) {
2173 2173
 								                                echo "[]";
2174 2174
 							                                } ?>"
2175
-							<?php if ( $multiple ) {
2175
+							<?php if ($multiple) {
2176 2176
 								echo "multiple";
2177 2177
 							} //@todo not implemented yet due to gutenberg not supporting it
2178 2178
 							?>
2179 2179
 						>
2180 2180
 							<?php
2181 2181
 
2182
-							if ( ! empty( $args['options'] ) ) {
2183
-								foreach ( $args['options'] as $val => $label ) {
2184
-									if ( $multiple ) {
2185
-										$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
2182
+							if (!empty($args['options'])) {
2183
+								foreach ($args['options'] as $val => $label) {
2184
+									if ($multiple) {
2185
+										$selected = in_array($val, $value) ? 'selected="selected"' : '';
2186 2186
 									} else {
2187
-										$selected = selected( $value, $val, false );
2187
+										$selected = selected($value, $val, false);
2188 2188
 									}
2189 2189
 									echo "<option value='$val' " . $selected . ">$label</option>";
2190 2190
 								}
@@ -2196,20 +2196,20 @@  discard block
 block discarded – undo
2196 2196
 					case "checkbox":
2197 2197
 						?>
2198 2198
 						<input <?php echo $placeholder; ?>
2199
-							<?php checked( 1, $value, true ) ?>
2199
+							<?php checked(1, $value, true) ?>
2200 2200
 							<?php echo $custom_attributes; ?>
2201
-							class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2202
-							name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox"
2201
+							class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2202
+							name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox"
2203 2203
 							value="1">
2204 2204
 						<label
2205
-							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>
2205
+							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>
2206 2206
 						<?php
2207 2207
 						break;
2208 2208
 					case "hidden":
2209 2209
 						?>
2210
-						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
2211
-						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
2212
-						       value="<?php echo esc_attr( $value ); ?>">
2210
+						<input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
2211
+						       name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden"
2212
+						       value="<?php echo esc_attr($value); ?>">
2213 2213
 						<?php
2214 2214
 						break;
2215 2215
 					default:
@@ -2231,14 +2231,14 @@  discard block
 block discarded – undo
2231 2231
 		 * @return string
2232 2232
 		 * @todo, need to make its own tooltip script
2233 2233
 		 */
2234
-		public function widget_field_desc( $args ) {
2234
+		public function widget_field_desc($args) {
2235 2235
 
2236 2236
 			$description = '';
2237
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
2238
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
2239
-					$description = $this->desc_tip( $args['desc'] );
2237
+			if (isset($args['desc']) && $args['desc']) {
2238
+				if (isset($args['desc_tip']) && $args['desc_tip']) {
2239
+					$description = $this->desc_tip($args['desc']);
2240 2240
 				} else {
2241
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
2241
+					$description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>';
2242 2242
 				}
2243 2243
 			}
2244 2244
 
@@ -2253,11 +2253,11 @@  discard block
 block discarded – undo
2253 2253
 		 *
2254 2254
 		 * @return string
2255 2255
 		 */
2256
-		function desc_tip( $tip, $allow_html = false ) {
2257
-			if ( $allow_html ) {
2258
-				$tip = $this->sanitize_tooltip( $tip );
2256
+		function desc_tip($tip, $allow_html = false) {
2257
+			if ($allow_html) {
2258
+				$tip = $this->sanitize_tooltip($tip);
2259 2259
 			} else {
2260
-				$tip = esc_attr( $tip );
2260
+				$tip = esc_attr($tip);
2261 2261
 			}
2262 2262
 
2263 2263
 			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -2270,8 +2270,8 @@  discard block
 block discarded – undo
2270 2270
 		 *
2271 2271
 		 * @return string
2272 2272
 		 */
2273
-		public function sanitize_tooltip( $var ) {
2274
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
2273
+		public function sanitize_tooltip($var) {
2274
+			return htmlspecialchars(wp_kses(html_entity_decode($var), array(
2275 2275
 				'br'     => array(),
2276 2276
 				'em'     => array(),
2277 2277
 				'strong' => array(),
@@ -2281,7 +2281,7 @@  discard block
 block discarded – undo
2281 2281
 				'li'     => array(),
2282 2282
 				'ol'     => array(),
2283 2283
 				'p'      => array(),
2284
-			) ) );
2284
+			)));
2285 2285
 		}
2286 2286
 
2287 2287
 		/**
@@ -2293,23 +2293,23 @@  discard block
 block discarded – undo
2293 2293
 		 * @return array
2294 2294
 		 * @todo we should add some sanitation here.
2295 2295
 		 */
2296
-		public function update( $new_instance, $old_instance ) {
2296
+		public function update($new_instance, $old_instance) {
2297 2297
 
2298 2298
 			//save the widget
2299
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
2299
+			$instance = array_merge((array)$old_instance, (array)$new_instance);
2300 2300
 
2301 2301
 			// set widget instance
2302 2302
 			$this->instance = $instance;
2303 2303
 
2304
-			if ( empty( $this->arguments ) ) {
2304
+			if (empty($this->arguments)) {
2305 2305
 				$this->get_arguments();
2306 2306
 			}
2307 2307
 
2308 2308
 			// check for checkboxes
2309
-			if ( ! empty( $this->arguments ) ) {
2310
-				foreach ( $this->arguments as $argument ) {
2311
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
2312
-						$instance[ $argument['name'] ] = '0';
2309
+			if (!empty($this->arguments)) {
2310
+				foreach ($this->arguments as $argument) {
2311
+					if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) {
2312
+						$instance[$argument['name']] = '0';
2313 2313
 					}
2314 2314
 				}
2315 2315
 			}
@@ -2327,7 +2327,7 @@  discard block
 block discarded – undo
2327 2327
 		 */
2328 2328
 		public function is_block_content_call() {
2329 2329
 			$result = false;
2330
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
2330
+			if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') {
2331 2331
 				$result = true;
2332 2332
 			}
2333 2333
 
Please login to merge, or discard this patch.