Passed
Push — master ( 9e37cd...7382ee )
by Brian
09:54
created
includes/admin/register-settings.php 1 patch
Indentation   +326 added lines, -326 removed lines patch added patch discarded remove patch
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
     $cb      = "wpinv_{$option['type']}_callback";
197 197
     $section = "wpinv_settings_{$tab}_$section";
198 198
 
199
-	if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
-		$tip   = wpinv_clean( $option['desc'] );
201
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
-		unset( $option['desc'] );
203
-	}
199
+    if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
+        $tip   = wpinv_clean( $option['desc'] );
201
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
+        unset( $option['desc'] );
203
+    }
204 204
 
205 205
     // Loop through all tabs.
206 206
     add_settings_field(
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
             'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
228 228
             'onchange'    => isset( $option['onchange'] )   ? $option['onchange']     : '',
229 229
             'custom'      => isset( $option['custom'] )     ? $option['custom']       : '',
230
-			'default_content' => isset( $option['default_content'] )     ? $option['default_content']       : '',
231
-			'class'       => isset( $option['class'] )     ? $option['class']         : '',
232
-			'style'       => isset( $option['style'] )     ? $option['style']         : '',
230
+            'default_content' => isset( $option['default_content'] )     ? $option['default_content']       : '',
231
+            'class'       => isset( $option['class'] )     ? $option['class']         : '',
232
+            'style'       => isset( $option['style'] )     ? $option['style']         : '',
233 233
             'cols'        => isset( $option['cols'] ) && (int) $option['cols'] > 0 ? (int) $option['cols'] : 50,
234 234
             'rows'        => isset( $option['rows'] ) && (int) $option['rows'] > 0 ? (int) $option['rows'] : 5,
235 235
         )
@@ -243,7 +243,7 @@  discard block
 block discarded – undo
243 243
  * @return array
244 244
  */
245 245
 function wpinv_get_registered_settings() {
246
-	return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
246
+    return array_filter( apply_filters( 'wpinv_registered_settings', wpinv_get_data( 'admin-settings' ) ) );
247 247
 }
248 248
 
249 249
 /**
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
  */
263 263
 function wpinv_settings_sanitize( $input = array() ) {
264 264
 
265
-	$wpinv_options = wpinv_get_options();
266
-	$raw_referrer  = wp_get_raw_referer();
265
+    $wpinv_options = wpinv_get_options();
266
+    $raw_referrer  = wp_get_raw_referer();
267 267
 
268 268
     if ( empty( $raw_referrer ) ) {
269 269
         return $input;
@@ -271,9 +271,9 @@  discard block
 block discarded – undo
271 271
 
272 272
     wp_parse_str( $raw_referrer, $referrer );
273 273
 
274
-	if ( empty( $referrer['tab'] ) ) {
274
+    if ( empty( $referrer['tab'] ) ) {
275 275
         return $input;
276
-	}
276
+    }
277 277
 
278 278
     $settings = wpinv_get_registered_settings();
279 279
     $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
@@ -295,10 +295,10 @@  discard block
 block discarded – undo
295 295
         }
296 296
 
297 297
         // General filter
298
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
298
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
299 299
 
300
-		// Key specific filter.
301
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
300
+        // Key specific filter.
301
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
302 302
     }
303 303
 
304 304
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -354,14 +354,14 @@  discard block
 block discarded – undo
354 354
 
355 355
     foreach ( $new_rates as $rate ) {
356 356
 
357
-		$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
358
-		$rate['name']    = sanitize_text_field( $rate['name'] );
359
-		$rate['state']   = sanitize_text_field( $rate['state'] );
360
-		$rate['country'] = sanitize_text_field( $rate['country'] );
361
-		$rate['global']  = empty( $rate['state'] );
362
-		$tax_rates[]     = $rate;
357
+        $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
358
+        $rate['name']    = sanitize_text_field( $rate['name'] );
359
+        $rate['state']   = sanitize_text_field( $rate['state'] );
360
+        $rate['country'] = sanitize_text_field( $rate['country'] );
361
+        $rate['global']  = empty( $rate['state'] );
362
+        $tax_rates[]     = $rate;
363 363
 
364
-	}
364
+    }
365 365
 
366 366
     update_option( 'wpinv_tax_rates', $tax_rates );
367 367
 
@@ -379,11 +379,11 @@  discard block
 block discarded – undo
379 379
     $tabs['general']  = __( 'General', 'invoicing' );
380 380
     $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
381 381
     $tabs['taxes']    = __( 'Taxes', 'invoicing' );
382
-	$tabs['emails']   = __( 'Emails', 'invoicing' );
382
+    $tabs['emails']   = __( 'Emails', 'invoicing' );
383 383
 
384
-	if ( count( getpaid_get_integration_settings() ) > 0 ) {
385
-		$tabs['integrations'] = __( 'Integrations', 'invoicing' );
386
-	}
384
+    if ( count( getpaid_get_integration_settings() ) > 0 ) {
385
+        $tabs['integrations'] = __( 'Integrations', 'invoicing' );
386
+    }
387 387
 
388 388
     $tabs['privacy']  = __( 'Privacy', 'invoicing' );
389 389
     $tabs['misc']     = __( 'Misc', 'invoicing' );
@@ -421,14 +421,14 @@  discard block
 block discarded – undo
421 421
         ) ),
422 422
         'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
423 423
             'main'  => __( 'Tax Settings', 'invoicing' ),
424
-			'rates' => __( 'Tax Rates', 'invoicing' ),
425
-			'vat'   => __( 'EU VAT Settings', 'invoicing' )
424
+            'rates' => __( 'Tax Rates', 'invoicing' ),
425
+            'vat'   => __( 'EU VAT Settings', 'invoicing' )
426 426
         ) ),
427 427
         'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
428 428
             'main' => __( 'Email Settings', 'invoicing' ),
429
-		) ),
429
+        ) ),
430 430
 
431
-		'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
431
+        'integrations' => wp_list_pluck( getpaid_get_integration_settings(), 'label', 'id' ),
432 432
 
433 433
         'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
434 434
             'main' => __( 'Privacy policy', 'invoicing' ),
@@ -448,51 +448,51 @@  discard block
 block discarded – undo
448 448
 }
449 449
 
450 450
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
451
-	$pages_options = array();
451
+    $pages_options = array();
452 452
 
453
-	if( $default_label !== NULL && $default_label !== false ) {
454
-		$pages_options = array( '' => $default_label ); // Blank option
455
-	}
453
+    if( $default_label !== NULL && $default_label !== false ) {
454
+        $pages_options = array( '' => $default_label ); // Blank option
455
+    }
456 456
 
457
-	$pages = get_pages();
458
-	if ( $pages ) {
459
-		foreach ( $pages as $page ) {
460
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
457
+    $pages = get_pages();
458
+    if ( $pages ) {
459
+        foreach ( $pages as $page ) {
460
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
461 461
             $pages_options[ $page->ID ] = $title;
462
-		}
463
-	}
462
+        }
463
+    }
464 464
 
465
-	return $pages_options;
465
+    return $pages_options;
466 466
 }
467 467
 
468 468
 function wpinv_header_callback( $args ) {
469
-	if ( !empty( $args['desc'] ) ) {
469
+    if ( !empty( $args['desc'] ) ) {
470 470
         echo $args['desc'];
471 471
     }
472 472
 }
473 473
 
474 474
 function wpinv_hidden_callback( $args ) {
475
-	global $wpinv_options;
476
-
477
-	if ( isset( $args['set_value'] ) ) {
478
-		$value = $args['set_value'];
479
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
480
-		$value = $wpinv_options[ $args['id'] ];
481
-	} else {
482
-		$value = isset( $args['std'] ) ? $args['std'] : '';
483
-	}
484
-
485
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
486
-		$args['readonly'] = true;
487
-		$value = isset( $args['std'] ) ? $args['std'] : '';
488
-		$name  = '';
489
-	} else {
490
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
491
-	}
492
-
493
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
475
+    global $wpinv_options;
476
+
477
+    if ( isset( $args['set_value'] ) ) {
478
+        $value = $args['set_value'];
479
+    } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
480
+        $value = $wpinv_options[ $args['id'] ];
481
+    } else {
482
+        $value = isset( $args['std'] ) ? $args['std'] : '';
483
+    }
484
+
485
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
486
+        $args['readonly'] = true;
487
+        $value = isset( $args['std'] ) ? $args['std'] : '';
488
+        $name  = '';
489
+    } else {
490
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
491
+    }
492
+
493
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
494 494
     
495
-	echo $html;
495
+    echo $html;
496 496
 }
497 497
 
498 498
 /**
@@ -500,12 +500,12 @@  discard block
 block discarded – undo
500 500
  */
501 501
 function wpinv_checkbox_callback( $args ) {
502 502
 
503
-	$std = isset( $args['std'] ) ? $args['std'] : '';
504
-	$std = wpinv_get_option( $args['id'], $std );
505
-	$id  = esc_attr( $args['id'] );
503
+    $std = isset( $args['std'] ) ? $args['std'] : '';
504
+    $std = wpinv_get_option( $args['id'], $std );
505
+    $id  = esc_attr( $args['id'] );
506 506
 
507
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
508
-	?>
507
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
508
+    ?>
509 509
 		<fieldset>
510 510
 			<label>
511 511
 				<input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -517,77 +517,77 @@  discard block
 block discarded – undo
517 517
 
518 518
 function wpinv_multicheck_callback( $args ) {
519 519
 	
520
-	global $wpinv_options;
520
+    global $wpinv_options;
521 521
 
522
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
523
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
522
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
523
+    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
524 524
 
525
-	if ( ! empty( $args['options'] ) ) {
525
+    if ( ! empty( $args['options'] ) ) {
526 526
 
527
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
528
-		$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
527
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
528
+        $value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
529 529
 
530
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
530
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
531 531
         foreach( $args['options'] as $key => $option ):
532
-			$sanitize_key = wpinv_sanitize_key( $key );
533
-			if ( in_array( $sanitize_key, $value ) ) { 
534
-				$enabled = $sanitize_key;
535
-			} else { 
536
-				$enabled = NULL; 
537
-			}
538
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
539
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
540
-		endforeach;
541
-		echo '</div>';
542
-		echo '<p class="description">' . $args['desc'] . '</p>';
543
-	}
532
+            $sanitize_key = wpinv_sanitize_key( $key );
533
+            if ( in_array( $sanitize_key, $value ) ) { 
534
+                $enabled = $sanitize_key;
535
+            } else { 
536
+                $enabled = NULL; 
537
+            }
538
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
539
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
540
+        endforeach;
541
+        echo '</div>';
542
+        echo '<p class="description">' . $args['desc'] . '</p>';
543
+    }
544 544
 }
545 545
 
546 546
 function wpinv_payment_icons_callback( $args ) {
547
-	global $wpinv_options;
547
+    global $wpinv_options;
548 548
     
549 549
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
550 550
 
551
-	if ( ! empty( $args['options'] ) ) {
552
-		foreach( $args['options'] as $key => $option ) {
551
+    if ( ! empty( $args['options'] ) ) {
552
+        foreach( $args['options'] as $key => $option ) {
553 553
             $sanitize_key = wpinv_sanitize_key( $key );
554 554
             
555
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
556
-				$enabled = $option;
557
-			} else {
558
-				$enabled = NULL;
559
-			}
560
-
561
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
562
-
563
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
564
-
565
-				if ( wpinv_string_is_image_url( $key ) ) {
566
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
567
-				} else {
568
-					$card = strtolower( str_replace( ' ', '', $option ) );
569
-
570
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
571
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
572
-					} else {
573
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
574
-						$content_dir = WP_CONTENT_DIR;
575
-
576
-						if ( function_exists( 'wp_normalize_path' ) ) {
577
-							// Replaces backslashes with forward slashes for Windows systems
578
-							$image = wp_normalize_path( $image );
579
-							$content_dir = wp_normalize_path( $content_dir );
580
-						}
581
-
582
-						$image = str_replace( $content_dir, content_url(), $image );
583
-					}
584
-
585
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
586
-				}
587
-			echo $option . '</label>';
588
-		}
589
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
590
-	}
555
+            if( isset( $wpinv_options[$args['id']][$key] ) ) {
556
+                $enabled = $option;
557
+            } else {
558
+                $enabled = NULL;
559
+            }
560
+
561
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
562
+
563
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
564
+
565
+                if ( wpinv_string_is_image_url( $key ) ) {
566
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
567
+                } else {
568
+                    $card = strtolower( str_replace( ' ', '', $option ) );
569
+
570
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
571
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
572
+                    } else {
573
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
574
+                        $content_dir = WP_CONTENT_DIR;
575
+
576
+                        if ( function_exists( 'wp_normalize_path' ) ) {
577
+                            // Replaces backslashes with forward slashes for Windows systems
578
+                            $image = wp_normalize_path( $image );
579
+                            $content_dir = wp_normalize_path( $content_dir );
580
+                        }
581
+
582
+                        $image = str_replace( $content_dir, content_url(), $image );
583
+                    }
584
+
585
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
586
+                }
587
+            echo $option . '</label>';
588
+        }
589
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
590
+    }
591 591
 }
592 592
 
593 593
 /**
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
  */
596 596
 function wpinv_radio_callback( $args ) {
597 597
 
598
-	$std = isset( $args['std'] ) ? $args['std'] : '';
599
-	$std = wpinv_get_option( $args['id'], $std );
600
-	?>
598
+    $std = isset( $args['std'] ) ? $args['std'] : '';
599
+    $std = wpinv_get_option( $args['id'], $std );
600
+    ?>
601 601
 		<fieldset>
602 602
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
603 603
 				<?php foreach( $args['options'] as $key => $option ) : ?>
@@ -611,7 +611,7 @@  discard block
 block discarded – undo
611 611
 			</ul>
612 612
 		</fieldset>
613 613
 	<?php
614
-	getpaid_settings_description_callback( $args );
614
+    getpaid_settings_description_callback( $args );
615 615
 }
616 616
 
617 617
 /**
@@ -619,10 +619,10 @@  discard block
 block discarded – undo
619 619
  */
620 620
 function getpaid_settings_description_callback( $args ) {
621 621
 
622
-	if ( ! empty( $args['desc'] ) ) {
623
-		$description = wp_kses_post( $args['desc'] );
624
-		echo "<p class='description'>$description</p>";
625
-	}
622
+    if ( ! empty( $args['desc'] ) ) {
623
+        $description = wp_kses_post( $args['desc'] );
624
+        echo "<p class='description'>$description</p>";
625
+    }
626 626
 
627 627
 }
628 628
 
@@ -631,7 +631,7 @@  discard block
 block discarded – undo
631 631
  */
632 632
 function wpinv_gateways_callback() {
633 633
 
634
-	?>
634
+    ?>
635 635
 		</td>
636 636
 	</tr>
637 637
 	<tr class="bsui">
@@ -642,24 +642,24 @@  discard block
 block discarded – undo
642 642
 }
643 643
 
644 644
 function wpinv_gateway_select_callback($args) {
645
-	global $wpinv_options;
645
+    global $wpinv_options;
646 646
     
647 647
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
648 648
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
649 649
 
650
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
650
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
651 651
 
652
-	foreach ( $args['options'] as $key => $option ) :
653
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
652
+    foreach ( $args['options'] as $key => $option ) :
653
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
654 654
             $selected = selected( $key, $args['selected'], false );
655 655
         } else {
656 656
             $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
657 657
         }
658
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
659
-	endforeach;
658
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
659
+    endforeach;
660 660
 
661
-	echo '</select>';
662
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
661
+    echo '</select>';
662
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
663 663
 }
664 664
 
665 665
 /**
@@ -670,29 +670,29 @@  discard block
 block discarded – undo
670 670
  */
671 671
 function wpinv_settings_attrs_helper( $args ) {
672 672
 
673
-	$value        = isset( $args['std'] ) ? $args['std'] : '';
674
-	$id           = esc_attr( $args['id'] );
675
-	$placeholder  = esc_attr( $args['placeholder'] );
673
+    $value        = isset( $args['std'] ) ? $args['std'] : '';
674
+    $id           = esc_attr( $args['id'] );
675
+    $placeholder  = esc_attr( $args['placeholder'] );
676 676
 
677
-	if ( ! empty( $args['faux'] ) ) {
678
-		$args['readonly'] = true;
679
-		$name             = '';
680
-	} else {
681
-		$value  = wpinv_get_option( $args['id'], $value );
682
-		$name   = "wpinv_settings[$id]";
683
-	}
677
+    if ( ! empty( $args['faux'] ) ) {
678
+        $args['readonly'] = true;
679
+        $name             = '';
680
+    } else {
681
+        $value  = wpinv_get_option( $args['id'], $value );
682
+        $name   = "wpinv_settings[$id]";
683
+    }
684 684
 
685
-	$value    = is_scalar( $value ) ? esc_attr( $value ) : '';
686
-	$class    = esc_attr( $args['class'] );
687
-	$style    = esc_attr( $args['style'] );
688
-	$readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
685
+    $value    = is_scalar( $value ) ? esc_attr( $value ) : '';
686
+    $class    = esc_attr( $args['class'] );
687
+    $style    = esc_attr( $args['style'] );
688
+    $readonly = empty( $args['readonly'] ) ? '' : 'readonly onclick="this.select()"';
689 689
 
690
-	$onchange = '';
690
+    $onchange = '';
691 691
     if ( ! empty( $args['onchange'] ) ) {
692 692
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
693
-	}
693
+    }
694 694
 
695
-	return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
695
+    return "name='$name' id='wpinv-settings-$id' style='$style' value='$value' class='$class' placeholder='$placeholder' data-placeholder='$placeholder' $onchange $readonly";
696 696
 }
697 697
 
698 698
 /**
@@ -700,11 +700,11 @@  discard block
 block discarded – undo
700 700
  */
701 701
 function wpinv_text_callback( $args ) {
702 702
 
703
-	$desc = wp_kses_post( $args['desc'] );
704
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
705
-	$attr = wpinv_settings_attrs_helper( $args );
703
+    $desc = wp_kses_post( $args['desc'] );
704
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
705
+    $attr = wpinv_settings_attrs_helper( $args );
706 706
 
707
-	?>
707
+    ?>
708 708
 		<label style="width: 100%;">
709 709
 			<input type="text" <?php echo $attr; ?>>
710 710
 			<?php echo $desc; ?>
@@ -718,14 +718,14 @@  discard block
 block discarded – undo
718 718
  */
719 719
 function wpinv_number_callback( $args ) {
720 720
 
721
-	$desc = wp_kses_post( $args['desc'] );
722
-	$desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
723
-	$attr = wpinv_settings_attrs_helper( $args );
724
-	$max  = intval( $args['max'] );
725
-	$min  = intval( $args['min'] );
726
-	$step = floatval( $args['step'] );
721
+    $desc = wp_kses_post( $args['desc'] );
722
+    $desc = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
723
+    $attr = wpinv_settings_attrs_helper( $args );
724
+    $max  = intval( $args['max'] );
725
+    $min  = intval( $args['min'] );
726
+    $step = floatval( $args['step'] );
727 727
 
728
-	?>
728
+    ?>
729 729
 		<label style="width: 100%;">
730 730
 			<input type="number" step="<?php echo $step; ?>" max="<?php echo $max; ?>" min="<?php echo $min; ?>" <?php echo $attr; ?>>
731 731
 			<?php echo $desc; ?>
@@ -735,48 +735,48 @@  discard block
 block discarded – undo
735 735
 }
736 736
 
737 737
 function wpinv_textarea_callback( $args ) {
738
-	global $wpinv_options;
738
+    global $wpinv_options;
739 739
     
740 740
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
741 741
 
742
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
743
-		$value = $wpinv_options[ $args['id'] ];
744
-	} else {
745
-		$value = isset( $args['std'] ) ? $args['std'] : '';
746
-	}
742
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
743
+        $value = $wpinv_options[ $args['id'] ];
744
+    } else {
745
+        $value = isset( $args['std'] ) ? $args['std'] : '';
746
+    }
747 747
     
748 748
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
749 749
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
750 750
 
751
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
752
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
751
+    $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
752
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
753 753
 
754
-	echo $html;
754
+    echo $html;
755 755
 }
756 756
 
757 757
 function wpinv_password_callback( $args ) {
758
-	global $wpinv_options;
758
+    global $wpinv_options;
759 759
     
760 760
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
761 761
 
762
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
763
-		$value = $wpinv_options[ $args['id'] ];
764
-	} else {
765
-		$value = isset( $args['std'] ) ? $args['std'] : '';
766
-	}
762
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
763
+        $value = $wpinv_options[ $args['id'] ];
764
+    } else {
765
+        $value = isset( $args['std'] ) ? $args['std'] : '';
766
+    }
767 767
 
768
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
769
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
770
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
768
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
769
+    $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
770
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
771 771
 
772
-	echo $html;
772
+    echo $html;
773 773
 }
774 774
 
775 775
 function wpinv_missing_callback($args) {
776
-	printf(
777
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
778
-		'<strong>' . $args['id'] . '</strong>'
779
-	);
776
+    printf(
777
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
778
+        '<strong>' . $args['id'] . '</strong>'
779
+    );
780 780
 }
781 781
 
782 782
 /**
@@ -784,14 +784,14 @@  discard block
 block discarded – undo
784 784
  */
785 785
 function wpinv_select_callback( $args ) {
786 786
 
787
-	$desc   = wp_kses_post( $args['desc'] );
788
-	$desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
789
-	$attr   = wpinv_settings_attrs_helper( $args );
790
-	$value  = isset( $args['std'] ) ? $args['std'] : '';
791
-	$value  = wpinv_get_option( $args['id'], $value );
792
-	$rand   = uniqid( 'random_id' );
787
+    $desc   = wp_kses_post( $args['desc'] );
788
+    $desc   = empty( $desc ) ? '' : "<p class='description'>$desc</p>";
789
+    $attr   = wpinv_settings_attrs_helper( $args );
790
+    $value  = isset( $args['std'] ) ? $args['std'] : '';
791
+    $value  = wpinv_get_option( $args['id'], $value );
792
+    $rand   = uniqid( 'random_id' );
793 793
 
794
-	?>
794
+    ?>
795 795
 		<label style="width: 100%;">
796 796
 			<select <?php echo $attr; ?>>
797 797
 				<?php foreach ( $args['options'] as $option => $name ) : ?>
@@ -822,123 +822,123 @@  discard block
 block discarded – undo
822 822
 }
823 823
 
824 824
 function wpinv_color_select_callback( $args ) {
825
-	global $wpinv_options;
825
+    global $wpinv_options;
826 826
     
827 827
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
828 828
 
829
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
830
-		$value = $wpinv_options[ $args['id'] ];
831
-	} else {
832
-		$value = isset( $args['std'] ) ? $args['std'] : '';
833
-	}
829
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
830
+        $value = $wpinv_options[ $args['id'] ];
831
+    } else {
832
+        $value = isset( $args['std'] ) ? $args['std'] : '';
833
+    }
834 834
 
835
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
835
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
836 836
 
837
-	foreach ( $args['options'] as $option => $color ) {
838
-		$selected = selected( $option, $value, false );
839
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
840
-	}
837
+    foreach ( $args['options'] as $option => $color ) {
838
+        $selected = selected( $option, $value, false );
839
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
840
+    }
841 841
 
842
-	$html .= '</select>';
843
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
842
+    $html .= '</select>';
843
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
844 844
 
845
-	echo $html;
845
+    echo $html;
846 846
 }
847 847
 
848 848
 function wpinv_rich_editor_callback( $args ) {
849
-	global $wpinv_options, $wp_version;
849
+    global $wpinv_options, $wp_version;
850 850
     
851 851
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
852 852
 
853
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
854
-		$value = $wpinv_options[ $args['id'] ];
853
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
854
+        $value = $wpinv_options[ $args['id'] ];
855 855
 
856
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
857
-			$value = isset( $args['std'] ) ? $args['std'] : '';
858
-		}
859
-	} else {
860
-		$value = isset( $args['std'] ) ? $args['std'] : '';
861
-	}
856
+        if( empty( $args['allow_blank'] ) && empty( $value ) ) {
857
+            $value = isset( $args['std'] ) ? $args['std'] : '';
858
+        }
859
+    } else {
860
+        $value = isset( $args['std'] ) ? $args['std'] : '';
861
+    }
862 862
 
863
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
863
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
864 864
 
865
-	$html = '<div class="getpaid-settings-editor-input">';
866
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
867
-		ob_start();
868
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
869
-		$html .= ob_get_clean();
870
-	} else {
871
-		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
872
-	}
865
+    $html = '<div class="getpaid-settings-editor-input">';
866
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
867
+        ob_start();
868
+        wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
869
+        $html .= ob_get_clean();
870
+    } else {
871
+        $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
872
+    }
873 873
 
874
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
874
+    $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
875 875
 
876
-	echo $html;
876
+    echo $html;
877 877
 }
878 878
 
879 879
 function wpinv_upload_callback( $args ) {
880
-	global $wpinv_options;
880
+    global $wpinv_options;
881 881
     
882 882
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
883 883
 
884
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
885
-		$value = $wpinv_options[$args['id']];
886
-	} else {
887
-		$value = isset($args['std']) ? $args['std'] : '';
888
-	}
884
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
885
+        $value = $wpinv_options[$args['id']];
886
+    } else {
887
+        $value = isset($args['std']) ? $args['std'] : '';
888
+    }
889 889
 
890
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
891
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
892
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
893
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
890
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
891
+    $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
892
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
893
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
894 894
 
895
-	echo $html;
895
+    echo $html;
896 896
 }
897 897
 
898 898
 function wpinv_color_callback( $args ) {
899
-	global $wpinv_options;
899
+    global $wpinv_options;
900 900
     
901 901
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
902 902
 
903
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
904
-		$value = $wpinv_options[ $args['id'] ];
905
-	} else {
906
-		$value = isset( $args['std'] ) ? $args['std'] : '';
907
-	}
903
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
904
+        $value = $wpinv_options[ $args['id'] ];
905
+    } else {
906
+        $value = isset( $args['std'] ) ? $args['std'] : '';
907
+    }
908 908
 
909
-	$default = isset( $args['std'] ) ? $args['std'] : '';
909
+    $default = isset( $args['std'] ) ? $args['std'] : '';
910 910
 
911
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
912
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
911
+    $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
912
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
913 913
 
914
-	echo $html;
914
+    echo $html;
915 915
 }
916 916
 
917 917
 function wpinv_country_states_callback($args) {
918
-	global $wpinv_options;
918
+    global $wpinv_options;
919 919
     
920 920
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
921 921
 
922
-	if ( isset( $args['placeholder'] ) ) {
923
-		$placeholder = $args['placeholder'];
924
-	} else {
925
-		$placeholder = '';
926
-	}
922
+    if ( isset( $args['placeholder'] ) ) {
923
+        $placeholder = $args['placeholder'];
924
+    } else {
925
+        $placeholder = '';
926
+    }
927 927
 
928
-	$states = wpinv_get_country_states();
928
+    $states = wpinv_get_country_states();
929 929
 
930
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
931
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
930
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
931
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
932 932
 
933
-	foreach ( $states as $option => $name ) {
934
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
935
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
936
-	}
933
+    foreach ( $states as $option => $name ) {
934
+        $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
935
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
936
+    }
937 937
 
938
-	$html .= '</select>';
939
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
938
+    $html .= '</select>';
939
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
940 940
 
941
-	echo $html;
941
+    echo $html;
942 942
 }
943 943
 
944 944
 /**
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
  */
947 947
 function wpinv_tax_rates_callback() {
948 948
 	
949
-	?>
949
+    ?>
950 950
 		</td>
951 951
 	</tr>
952 952
 	<tr class="bsui">
@@ -961,17 +961,17 @@  discard block
 block discarded – undo
961 961
  * Displays a tax rate' edit row.
962 962
  */
963 963
 function wpinv_tax_rate_callback( $tax_rate, $key, $echo = true ) {
964
-	ob_start();
964
+    ob_start();
965 965
 
966
-	$key                      = sanitize_key( $key );
967
-	$tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
968
-	include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
966
+    $key                      = sanitize_key( $key );
967
+    $tax_rate['reduced_rate'] = empty( $tax_rate['reduced_rate'] ) ? 0 : $tax_rate['reduced_rate'];
968
+    include plugin_dir_path( __FILE__ ) . 'views/html-tax-rate-edit.php';
969 969
 
970
-	if ( $echo ) {
971
-		echo ob_get_clean();
972
-	} else {
973
-		return ob_get_clean(); 
974
-	}
970
+    if ( $echo ) {
971
+        echo ob_get_clean();
972
+    } else {
973
+        return ob_get_clean(); 
974
+    }
975 975
 
976 976
 }
977 977
 
@@ -999,14 +999,14 @@  discard block
 block discarded – undo
999 999
                 </td>
1000 1000
                 <td>
1001 1001
 					<a href="<?php
1002
-						echo esc_url(
1003
-							wp_nonce_url(
1004
-								add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
1005
-								'getpaid-nonce',
1006
-								'getpaid-nonce'
1007
-							)
1008
-						);
1009
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
1002
+                        echo esc_url(
1003
+                            wp_nonce_url(
1004
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_pages' ),
1005
+                                'getpaid-nonce',
1006
+                                'getpaid-nonce'
1007
+                            )
1008
+                        );
1009
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
1010 1010
                 </td>
1011 1011
             </tr>
1012 1012
 			<tr>
@@ -1016,14 +1016,14 @@  discard block
 block discarded – undo
1016 1016
                 </td>
1017 1017
                 <td>
1018 1018
 					<a href="<?php
1019
-						echo esc_url(
1020
-							wp_nonce_url(
1021
-								add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
1022
-								'getpaid-nonce',
1023
-								'getpaid-nonce'
1024
-							)
1025
-						);
1026
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
1019
+                        echo esc_url(
1020
+                            wp_nonce_url(
1021
+                                add_query_arg( 'getpaid-admin-action', 'create_missing_tables' ),
1022
+                                'getpaid-nonce',
1023
+                                'getpaid-nonce'
1024
+                            )
1025
+                        );
1026
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
1027 1027
                 </td>
1028 1028
             </tr>
1029 1029
 			<tr>
@@ -1033,14 +1033,14 @@  discard block
 block discarded – undo
1033 1033
                 </td>
1034 1034
                 <td>
1035 1035
 					<a href="<?php
1036
-						echo esc_url(
1037
-							wp_nonce_url(
1038
-								add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1039
-								'getpaid-nonce',
1040
-								'getpaid-nonce'
1041
-							)
1042
-						);
1043
-					?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
1036
+                        echo esc_url(
1037
+                            wp_nonce_url(
1038
+                                add_query_arg( 'getpaid-admin-action', 'migrate_old_invoices' ),
1039
+                                'getpaid-nonce',
1040
+                                'getpaid-nonce'
1041
+                            )
1042
+                        );
1043
+                    ?>" class="button button-primary"><?php _e('Run', 'invoicing');?></a>
1044 1044
                 </td>
1045 1045
             </tr>
1046 1046
 
@@ -1051,14 +1051,14 @@  discard block
 block discarded – undo
1051 1051
                 </td>
1052 1052
                 <td>
1053 1053
 					<a href="<?php
1054
-						echo esc_url(
1055
-							wp_nonce_url(
1056
-								add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1057
-								'getpaid-nonce',
1058
-								'getpaid-nonce'
1059
-							)
1060
-						);
1061
-					?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a>
1054
+                        echo esc_url(
1055
+                            wp_nonce_url(
1056
+                                add_query_arg( 'getpaid-admin-action', 'recalculate_discounts' ),
1057
+                                'getpaid-nonce',
1058
+                                'getpaid-nonce'
1059
+                            )
1060
+                        );
1061
+                    ?>" class="button button-primary"><?php _e( 'Run', 'invoicing' );?></a>
1062 1062
                 </td>
1063 1063
             </tr>
1064 1064
 
@@ -1072,19 +1072,19 @@  discard block
 block discarded – undo
1072 1072
 
1073 1073
 
1074 1074
 function wpinv_descriptive_text_callback( $args ) {
1075
-	echo wp_kses_post( $args['desc'] );
1075
+    echo wp_kses_post( $args['desc'] );
1076 1076
 }
1077 1077
 
1078 1078
 function wpinv_raw_html_callback( $args ) {
1079
-	echo $args['desc'];
1079
+    echo $args['desc'];
1080 1080
 }
1081 1081
 
1082 1082
 function wpinv_hook_callback( $args ) {
1083
-	do_action( 'wpinv_' . $args['id'], $args );
1083
+    do_action( 'wpinv_' . $args['id'], $args );
1084 1084
 }
1085 1085
 
1086 1086
 function wpinv_set_settings_cap() {
1087
-	return wpinv_get_capability();
1087
+    return wpinv_get_capability();
1088 1088
 }
1089 1089
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1090 1090
 
@@ -1118,15 +1118,15 @@  discard block
 block discarded – undo
1118 1118
  */
1119 1119
 function wpinv_get_merge_tags_help_text( $subscription = false ) {
1120 1120
 
1121
-	$url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1122
-	$link = sprintf(
1123
-		'<strong><a href="%s" target="_blank">%s</a></strong>',
1124
-		$url,
1125
-		esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1126
-	);
1121
+    $url  = $subscription ? 'https://gist.github.com/picocodes/3d213982d57c34edf7a46fd3f0e8583e' : 'https://gist.github.com/picocodes/43bdc4d4bbba844534b2722e2af0b58f';
1122
+    $link = sprintf(
1123
+        '<strong><a href="%s" target="_blank">%s</a></strong>',
1124
+        $url,
1125
+        esc_html__( 'View available merge tags.', 'wpinv-quotes' )
1126
+    );
1127 1127
 
1128
-	$description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1128
+    $description = esc_html__( 'The content of the email (Merge Tags and HTML are allowed).', 'invoicing' );
1129 1129
 
1130
-	return "$description $link";
1130
+    return "$description $link";
1131 1131
 
1132 1132
 }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +369 added lines, -369 removed lines patch added patch discarded remove patch
@@ -20,222 +20,222 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	/**
24
-	 * Upgrades the install.
25
-	 *
26
-	 * @param string $upgrade_from The current invoicing version.
27
-	 */
28
-	public function upgrade_db( $upgrade_from ) {
29
-
30
-		// Save the current invoicing version.
31
-		update_option( 'wpinv_version', WPINV_VERSION );
32
-
33
-		// Setup the invoice Custom Post Type.
34
-		GetPaid_Post_Types::register_post_types();
35
-
36
-		// Clear the permalinks
37
-		flush_rewrite_rules();
38
-
39
-		// Maybe create new/missing pages.
40
-		$this->create_pages();
41
-
42
-		// Maybe re(add) admin capabilities.
43
-		$this->add_capabilities();
44
-
45
-		// Maybe create the default payment form.
46
-		wpinv_get_default_payment_form();
47
-
48
-		// Create any missing database tables.
49
-		$method = "upgrade_from_$upgrade_from";
50
-
51
-		if ( method_exists( $this, $method ) ) {
52
-			$this->$method();
53
-		}
54
-
55
-	}
56
-
57
-	/**
58
-	 * Do a fresh install.
59
-	 *
60
-	 */
61
-	public function upgrade_from_0() {
62
-		$this->create_subscriptions_table();
63
-		$this->create_invoices_table();
64
-		$this->create_invoice_items_table();
65
-
66
-		// Save default tax rates.
67
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
68
-	}
69
-
70
-	/**
71
-	 * Upgrade to 0.0.5
72
-	 *
73
-	 */
74
-	public function upgrade_from_004() {
75
-		global $wpdb;
76
-
77
-		// Invoices.
78
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
-		if ( ! empty( $results ) ) {
80
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
81
-
82
-			// Clean post cache
83
-			foreach ( $results as $row ) {
84
-				clean_post_cache( $row->ID );
85
-			}
86
-
87
-		}
88
-
89
-		// Item meta key changes
90
-		$query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
-		$results = $wpdb->get_results( $query );
92
-
93
-		if ( ! empty( $results ) ) {
94
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
-			$wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
97
-
98
-			foreach ( $results as $row ) {
99
-				clean_post_cache( $row->post_id );
100
-			}
101
-
102
-		}
103
-
104
-		$this->upgrade_from_102();
105
-	}
106
-
107
-	/**
108
-	 * Upgrade to 1.0.3
109
-	 *
110
-	 */
111
-	public function upgrade_from_102() {
112
-		$this->create_subscriptions_table();
113
-		$this->upgrade_from_118();
114
-	}
115
-
116
-	/**
117
-	 * Upgrade to version 2.0.0.
118
-	 *
119
-	 */
120
-	public function upgrade_from_118() {
121
-		$this->create_invoices_table();
122
-		$this->create_invoice_items_table();
123
-		$this->migrate_old_invoices();
124
-	}
125
-
126
-	/**
127
-	 * Upgrade to version 2.0.8.
128
-	 *
129
-	 */
130
-	public function upgrade_from_207() {
131
-		global $wpdb;
132
-		$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
133
-	}
134
-
135
-	/**
136
-	 * Give administrators the capability to manage GetPaid.
137
-	 *
138
-	 */
139
-	public function add_capabilities() {
140
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
141
-	}
142
-
143
-	/**
144
-	 * Retreives GetPaid pages.
145
-	 *
146
-	 */
147
-	public static function get_pages() {
148
-
149
-		return apply_filters(
150
-			'wpinv_create_pages',
151
-			array(
152
-
153
-				// Checkout page.
154
-				'checkout_page' => array(
155
-					'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
156
-					'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
157
-					'content'   => '
23
+    /**
24
+     * Upgrades the install.
25
+     *
26
+     * @param string $upgrade_from The current invoicing version.
27
+     */
28
+    public function upgrade_db( $upgrade_from ) {
29
+
30
+        // Save the current invoicing version.
31
+        update_option( 'wpinv_version', WPINV_VERSION );
32
+
33
+        // Setup the invoice Custom Post Type.
34
+        GetPaid_Post_Types::register_post_types();
35
+
36
+        // Clear the permalinks
37
+        flush_rewrite_rules();
38
+
39
+        // Maybe create new/missing pages.
40
+        $this->create_pages();
41
+
42
+        // Maybe re(add) admin capabilities.
43
+        $this->add_capabilities();
44
+
45
+        // Maybe create the default payment form.
46
+        wpinv_get_default_payment_form();
47
+
48
+        // Create any missing database tables.
49
+        $method = "upgrade_from_$upgrade_from";
50
+
51
+        if ( method_exists( $this, $method ) ) {
52
+            $this->$method();
53
+        }
54
+
55
+    }
56
+
57
+    /**
58
+     * Do a fresh install.
59
+     *
60
+     */
61
+    public function upgrade_from_0() {
62
+        $this->create_subscriptions_table();
63
+        $this->create_invoices_table();
64
+        $this->create_invoice_items_table();
65
+
66
+        // Save default tax rates.
67
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
68
+    }
69
+
70
+    /**
71
+     * Upgrade to 0.0.5
72
+     *
73
+     */
74
+    public function upgrade_from_004() {
75
+        global $wpdb;
76
+
77
+        // Invoices.
78
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
79
+        if ( ! empty( $results ) ) {
80
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
81
+
82
+            // Clean post cache
83
+            foreach ( $results as $row ) {
84
+                clean_post_cache( $row->ID );
85
+            }
86
+
87
+        }
88
+
89
+        // Item meta key changes
90
+        $query = "SELECT DISTINCT post_id FROM " . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
91
+        $results = $wpdb->get_results( $query );
92
+
93
+        if ( ! empty( $results ) ) {
94
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
95
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
96
+            $wpdb->query( "UPDATE " . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
97
+
98
+            foreach ( $results as $row ) {
99
+                clean_post_cache( $row->post_id );
100
+            }
101
+
102
+        }
103
+
104
+        $this->upgrade_from_102();
105
+    }
106
+
107
+    /**
108
+     * Upgrade to 1.0.3
109
+     *
110
+     */
111
+    public function upgrade_from_102() {
112
+        $this->create_subscriptions_table();
113
+        $this->upgrade_from_118();
114
+    }
115
+
116
+    /**
117
+     * Upgrade to version 2.0.0.
118
+     *
119
+     */
120
+    public function upgrade_from_118() {
121
+        $this->create_invoices_table();
122
+        $this->create_invoice_items_table();
123
+        $this->migrate_old_invoices();
124
+    }
125
+
126
+    /**
127
+     * Upgrade to version 2.0.8.
128
+     *
129
+     */
130
+    public function upgrade_from_207() {
131
+        global $wpdb;
132
+        $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoice_items MODIFY COLUMN quantity FLOAT(20);" );
133
+    }
134
+
135
+    /**
136
+     * Give administrators the capability to manage GetPaid.
137
+     *
138
+     */
139
+    public function add_capabilities() {
140
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
141
+    }
142
+
143
+    /**
144
+     * Retreives GetPaid pages.
145
+     *
146
+     */
147
+    public static function get_pages() {
148
+
149
+        return apply_filters(
150
+            'wpinv_create_pages',
151
+            array(
152
+
153
+                // Checkout page.
154
+                'checkout_page' => array(
155
+                    'name'      => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
156
+                    'title'     => _x( 'Checkout', 'Page title', 'invoicing' ),
157
+                    'content'   => '
158 158
 						<!-- wp:shortcode -->
159 159
 						[wpinv_checkout]
160 160
 						<!-- /wp:shortcode -->
161 161
 					',
162
-					'parent'    => '',
163
-				),
164
-
165
-				// Invoice history page.
166
-				'invoice_history_page' => array(
167
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
168
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
169
-					'content' => '
162
+                    'parent'    => '',
163
+                ),
164
+
165
+                // Invoice history page.
166
+                'invoice_history_page' => array(
167
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
168
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
169
+                    'content' => '
170 170
 					<!-- wp:shortcode -->
171 171
 					[wpinv_history]
172 172
 					<!-- /wp:shortcode -->
173 173
 				',
174
-					'parent'  => '',
175
-				),
176
-
177
-				// Success page content.
178
-				'success_page' => array(
179
-					'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
180
-					'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
181
-					'content'  => '
174
+                    'parent'  => '',
175
+                ),
176
+
177
+                // Success page content.
178
+                'success_page' => array(
179
+                    'name'     => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
180
+                    'title'    => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
181
+                    'content'  => '
182 182
 					<!-- wp:shortcode -->
183 183
 					[wpinv_receipt]
184 184
 					<!-- /wp:shortcode -->
185 185
 				',
186
-					'parent'   => 'gp-checkout',
187
-				),
188
-
189
-				// Failure page content.
190
-				'failure_page' => array(
191
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
192
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
193
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
194
-					'parent'  => 'gp-checkout',
195
-				),
196
-
197
-				// Subscriptions history page.
198
-				'invoice_subscription_page' => array(
199
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
200
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
201
-					'content' => '
186
+                    'parent'   => 'gp-checkout',
187
+                ),
188
+
189
+                // Failure page content.
190
+                'failure_page' => array(
191
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
192
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
193
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
194
+                    'parent'  => 'gp-checkout',
195
+                ),
196
+
197
+                // Subscriptions history page.
198
+                'invoice_subscription_page' => array(
199
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
200
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
201
+                    'content' => '
202 202
 					<!-- wp:shortcode -->
203 203
 					[wpinv_subscriptions]
204 204
 					<!-- /wp:shortcode -->
205 205
 				',
206
-					'parent' => '',
207
-				),
206
+                    'parent' => '',
207
+                ),
208 208
 
209
-			)
210
-		);
209
+            )
210
+        );
211 211
 
212
-	}
212
+    }
213 213
 
214
-	/**
215
-	 * Re-create GetPaid pages.
216
-	 *
217
-	 */
218
-	public function create_pages() {
214
+    /**
215
+     * Re-create GetPaid pages.
216
+     *
217
+     */
218
+    public function create_pages() {
219 219
 
220
-		foreach ( self::get_pages() as $key => $page ) {
221
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
222
-		}
220
+        foreach ( self::get_pages() as $key => $page ) {
221
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
222
+        }
223 223
 
224
-	}
224
+    }
225 225
 
226
-	/**
227
-	 * Create subscriptions table.
228
-	 *
229
-	 */
230
-	public function create_subscriptions_table() {
226
+    /**
227
+     * Create subscriptions table.
228
+     *
229
+     */
230
+    public function create_subscriptions_table() {
231 231
 
232
-		global $wpdb;
232
+        global $wpdb;
233 233
 
234
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
234
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
235 235
 
236
-		// Create tables.
237
-		$charset_collate = $wpdb->get_charset_collate();
238
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
236
+        // Create tables.
237
+        $charset_collate = $wpdb->get_charset_collate();
238
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}wpinv_subscriptions (
239 239
 			id bigint(20) unsigned NOT NULL auto_increment,
240 240
 			customer_id bigint(20) NOT NULL,
241 241
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -258,22 +258,22 @@  discard block
 block discarded – undo
258 258
 			KEY customer_and_status (customer_id, status)
259 259
 		  ) $charset_collate;";
260 260
 
261
-		dbDelta( $sql );
261
+        dbDelta( $sql );
262 262
 
263
-	}
263
+    }
264 264
 
265
-	/**
266
-	 * Create invoices table.
267
-	 *
268
-	 */
269
-	public function create_invoices_table() {
270
-		global $wpdb;
265
+    /**
266
+     * Create invoices table.
267
+     *
268
+     */
269
+    public function create_invoices_table() {
270
+        global $wpdb;
271 271
 
272
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
272
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
273 273
 
274
-		// Create tables.
275
-		$charset_collate = $wpdb->get_charset_collate();
276
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
274
+        // Create tables.
275
+        $charset_collate = $wpdb->get_charset_collate();
276
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoices (
277 277
 			post_id BIGINT(20) NOT NULL,
278 278
             `number` VARCHAR(100),
279 279
             `key` VARCHAR(100),
@@ -309,22 +309,22 @@  discard block
 block discarded – undo
309 309
 			KEY `key` (`key`)
310 310
 		  ) $charset_collate;";
311 311
 
312
-		dbDelta( $sql );
312
+        dbDelta( $sql );
313 313
 
314
-	}
314
+    }
315 315
 
316
-	/**
317
-	 * Create invoice items table.
318
-	 *
319
-	 */
320
-	public function create_invoice_items_table() {
321
-		global $wpdb;
316
+    /**
317
+     * Create invoice items table.
318
+     *
319
+     */
320
+    public function create_invoice_items_table() {
321
+        global $wpdb;
322 322
 
323
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
323
+        require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
324 324
 
325
-		// Create tables.
326
-		$charset_collate = $wpdb->get_charset_collate();
327
-		$sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
325
+        // Create tables.
326
+        $charset_collate = $wpdb->get_charset_collate();
327
+        $sql             = "CREATE TABLE IF NOT EXISTS {$wpdb->prefix}getpaid_invoice_items (
328 328
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
329 329
             post_id BIGINT(20) NOT NULL,
330 330
             item_id BIGINT(20) NOT NULL,
@@ -346,159 +346,159 @@  discard block
 block discarded – undo
346 346
 			KEY post_id (post_id)
347 347
 		  ) $charset_collate;";
348 348
 
349
-		dbDelta( $sql );
350
-
351
-	}
352
-
353
-	/**
354
-	 * Migrates old invoices to new invoices.
355
-	 *
356
-	 */
357
-	public function migrate_old_invoices() {
358
-		global $wpdb;
359
-
360
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
361
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
362
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
363
-		$invoices            = array_unique(
364
-			get_posts(
365
-				array(
366
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
367
-					'posts_per_page' => -1,
368
-					'fields'         => 'ids',
369
-					'post_status'    => array_keys( get_post_stati() ),
370
-					'exclude'        => (array) $migrated,
371
-				)
372
-			)
373
-		);
374
-
375
-		// Abort if we do not have any invoices.
376
-		if ( empty( $invoices ) ) {
377
-			return;
378
-		}
379
-
380
-		require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
381
-
382
-		$invoice_rows = array();
383
-		foreach ( $invoices as $invoice ) {
384
-
385
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
386
-
387
-			if ( empty( $invoice->ID ) ) {
388
-				return;
389
-			}
390
-
391
-			$fields = array (
392
-				'post_id'        => $invoice->ID,
393
-				'number'         => $invoice->get_number(),
394
-				'key'            => $invoice->get_key(),
395
-				'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
396
-				'mode'           => $invoice->mode,
397
-				'user_ip'        => $invoice->get_ip(),
398
-				'first_name'     => $invoice->get_first_name(),
399
-				'last_name'      => $invoice->get_last_name(),
400
-				'address'        => $invoice->get_address(),
401
-				'city'           => $invoice->city,
402
-				'state'          => $invoice->state,
403
-				'country'        => $invoice->country,
404
-				'zip'            => $invoice->zip,
405
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
406
-				'gateway'        => $invoice->get_gateway(),
407
-				'transaction_id' => $invoice->get_transaction_id(),
408
-				'currency'       => $invoice->get_currency(),
409
-				'subtotal'       => $invoice->get_subtotal(),
410
-				'tax'            => $invoice->get_tax(),
411
-				'fees_total'     => $invoice->get_fees_total(),
412
-				'total'          => $invoice->get_total(),
413
-				'discount'       => $invoice->get_discount(),
414
-				'discount_code'  => $invoice->get_discount_code(),
415
-				'disable_taxes'  => $invoice->disable_taxes,
416
-				'due_date'       => $invoice->get_due_date(),
417
-				'completed_date' => $invoice->get_completed_date(),
418
-				'company'        => $invoice->company,
419
-				'vat_number'     => $invoice->vat_number,
420
-				'vat_rate'       => $invoice->vat_rate,
421
-				'custom_meta'    => $invoice->payment_meta
422
-			);
423
-
424
-			foreach ( $fields as $key => $val ) {
425
-				if ( is_null( $val ) ) {
426
-					$val = '';
427
-				}
428
-				$val = maybe_serialize( $val );
429
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
430
-			}
431
-
432
-			$fields = implode( ', ', $fields );
433
-			$invoice_rows[] = "($fields)";
434
-
435
-			$item_rows    = array();
436
-			$item_columns = array();
437
-			foreach ( $invoice->get_cart_details() as $details ) {
438
-				$fields = array(
439
-					'post_id'          => $invoice->ID,
440
-					'item_id'          => $details['id'],
441
-					'item_name'        => $details['name'],
442
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
443
-					'vat_rate'         => $details['vat_rate'],
444
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
445
-					'tax'              => $details['tax'],
446
-					'item_price'       => $details['item_price'],
447
-					'custom_price'     => $details['custom_price'],
448
-					'quantity'         => $details['quantity'],
449
-					'discount'         => $details['discount'],
450
-					'subtotal'         => $details['subtotal'],
451
-					'price'            => $details['price'],
452
-					'meta'             => $details['meta'],
453
-					'fees'             => $details['fees'],
454
-				);
455
-
456
-				$item_columns = array_keys ( $fields );
457
-
458
-				foreach ( $fields as $key => $val ) {
459
-					if ( is_null( $val ) ) {
460
-						$val = '';
461
-					}
462
-					$val = maybe_serialize( $val );
463
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
464
-				}
465
-
466
-				$fields = implode( ', ', $fields );
467
-				$item_rows[] = "($fields)";
468
-			}
469
-
470
-			$item_rows    = implode( ', ', $item_rows );
471
-			$item_columns = implode( ', ', $item_columns );
472
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
473
-		}
474
-
475
-		if ( empty( $invoice_rows ) ) {
476
-			return;
477
-		}
478
-
479
-		$invoice_rows = implode( ', ', $invoice_rows );
480
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
481
-
482
-	}
483
-
484
-	/**
485
-	 * Migrates old invoices to new invoices.
486
-	 *
487
-	 */
488
-	public static function rename_gateways_label() {
489
-		global $wpdb;
490
-
491
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
492
-
493
-			$wpdb->update(
494
-				$wpdb->prefix . 'getpaid_invoices',
495
-				array( 'gateway' => $gateway ),
496
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
497
-				'%s',
498
-				'%s'
499
-			);
500
-
501
-		}
502
-	}
349
+        dbDelta( $sql );
350
+
351
+    }
352
+
353
+    /**
354
+     * Migrates old invoices to new invoices.
355
+     *
356
+     */
357
+    public function migrate_old_invoices() {
358
+        global $wpdb;
359
+
360
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
361
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
362
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
363
+        $invoices            = array_unique(
364
+            get_posts(
365
+                array(
366
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
367
+                    'posts_per_page' => -1,
368
+                    'fields'         => 'ids',
369
+                    'post_status'    => array_keys( get_post_stati() ),
370
+                    'exclude'        => (array) $migrated,
371
+                )
372
+            )
373
+        );
374
+
375
+        // Abort if we do not have any invoices.
376
+        if ( empty( $invoices ) ) {
377
+            return;
378
+        }
379
+
380
+        require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php' );
381
+
382
+        $invoice_rows = array();
383
+        foreach ( $invoices as $invoice ) {
384
+
385
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
386
+
387
+            if ( empty( $invoice->ID ) ) {
388
+                return;
389
+            }
390
+
391
+            $fields = array (
392
+                'post_id'        => $invoice->ID,
393
+                'number'         => $invoice->get_number(),
394
+                'key'            => $invoice->get_key(),
395
+                'type'           => str_replace( 'wpi_', '', $invoice->post_type ),
396
+                'mode'           => $invoice->mode,
397
+                'user_ip'        => $invoice->get_ip(),
398
+                'first_name'     => $invoice->get_first_name(),
399
+                'last_name'      => $invoice->get_last_name(),
400
+                'address'        => $invoice->get_address(),
401
+                'city'           => $invoice->city,
402
+                'state'          => $invoice->state,
403
+                'country'        => $invoice->country,
404
+                'zip'            => $invoice->zip,
405
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
406
+                'gateway'        => $invoice->get_gateway(),
407
+                'transaction_id' => $invoice->get_transaction_id(),
408
+                'currency'       => $invoice->get_currency(),
409
+                'subtotal'       => $invoice->get_subtotal(),
410
+                'tax'            => $invoice->get_tax(),
411
+                'fees_total'     => $invoice->get_fees_total(),
412
+                'total'          => $invoice->get_total(),
413
+                'discount'       => $invoice->get_discount(),
414
+                'discount_code'  => $invoice->get_discount_code(),
415
+                'disable_taxes'  => $invoice->disable_taxes,
416
+                'due_date'       => $invoice->get_due_date(),
417
+                'completed_date' => $invoice->get_completed_date(),
418
+                'company'        => $invoice->company,
419
+                'vat_number'     => $invoice->vat_number,
420
+                'vat_rate'       => $invoice->vat_rate,
421
+                'custom_meta'    => $invoice->payment_meta
422
+            );
423
+
424
+            foreach ( $fields as $key => $val ) {
425
+                if ( is_null( $val ) ) {
426
+                    $val = '';
427
+                }
428
+                $val = maybe_serialize( $val );
429
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
430
+            }
431
+
432
+            $fields = implode( ', ', $fields );
433
+            $invoice_rows[] = "($fields)";
434
+
435
+            $item_rows    = array();
436
+            $item_columns = array();
437
+            foreach ( $invoice->get_cart_details() as $details ) {
438
+                $fields = array(
439
+                    'post_id'          => $invoice->ID,
440
+                    'item_id'          => $details['id'],
441
+                    'item_name'        => $details['name'],
442
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
443
+                    'vat_rate'         => $details['vat_rate'],
444
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
445
+                    'tax'              => $details['tax'],
446
+                    'item_price'       => $details['item_price'],
447
+                    'custom_price'     => $details['custom_price'],
448
+                    'quantity'         => $details['quantity'],
449
+                    'discount'         => $details['discount'],
450
+                    'subtotal'         => $details['subtotal'],
451
+                    'price'            => $details['price'],
452
+                    'meta'             => $details['meta'],
453
+                    'fees'             => $details['fees'],
454
+                );
455
+
456
+                $item_columns = array_keys ( $fields );
457
+
458
+                foreach ( $fields as $key => $val ) {
459
+                    if ( is_null( $val ) ) {
460
+                        $val = '';
461
+                    }
462
+                    $val = maybe_serialize( $val );
463
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
464
+                }
465
+
466
+                $fields = implode( ', ', $fields );
467
+                $item_rows[] = "($fields)";
468
+            }
469
+
470
+            $item_rows    = implode( ', ', $item_rows );
471
+            $item_columns = implode( ', ', $item_columns );
472
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
473
+        }
474
+
475
+        if ( empty( $invoice_rows ) ) {
476
+            return;
477
+        }
478
+
479
+        $invoice_rows = implode( ', ', $invoice_rows );
480
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
481
+
482
+    }
483
+
484
+    /**
485
+     * Migrates old invoices to new invoices.
486
+     *
487
+     */
488
+    public static function rename_gateways_label() {
489
+        global $wpdb;
490
+
491
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
492
+
493
+            $wpdb->update(
494
+                $wpdb->prefix . 'getpaid_invoices',
495
+                array( 'gateway' => $gateway ),
496
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
497
+                '%s',
498
+                '%s'
499
+            );
500
+
501
+        }
502
+    }
503 503
 
504 504
 }
Please login to merge, or discard this patch.