Passed
Push — master ( 03dff3...2bff3c )
by Stiofan
01:08 queued 13s
created
vendor/ayecode/wp-super-duper/wp-super-duper.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -795,7 +795,7 @@
 block discarded – undo
795 795
 		 * Output the JS for building the dynamic Guntenberg block.
796 796
 		 *
797 797
 		 * @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.
798
-		 * @return mixed
798
+		 * @return string
799 799
 		 */
800 800
 		public function block() {
801 801
 			ob_start();
Please login to merge, or discard this patch.
Indentation   +1081 added lines, -1081 removed lines patch added patch discarded remove patch
@@ -1,151 +1,151 @@  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
-	 * @ver 1.0.5
21
-	 */
22
-	class WP_Super_Duper extends WP_Widget {
23
-
24
-
25
-		public $version = "1.0.5";
26
-		public $block_code;
27
-		public $options;
28
-		public $base_id;
29
-		public $arguments = array();
30
-		public $instance = array();
31
-		private $class_name;
32
-
33
-		/**
34
-		 * Take the array options and use them to build.
35
-		 */
36
-		public function __construct( $options ) {
37
-			global $sd_widgets;
38
-
39
-			$sd_widgets[ $options['base_id'] ] = array( 'name'       => $options['name'],
40
-			                                            'class_name' => $options['class_name']
41
-			);
42
-			$this->base_id                     = $options['base_id'];
43
-			// lets filter the options before we do anything
44
-			$options       = apply_filters( "wp_super_duper_options", $options );
45
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
46
-			$options       = $this->add_name_from_key( $options );
47
-			$this->options = $options;
48
-
49
-			$this->base_id   = $options['base_id'];
50
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
51
-
52
-			// init parent
53
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
54
-
55
-			if ( isset( $options['class_name'] ) ) {
56
-				// register widget
57
-				$this->class_name = $options['class_name'];
58
-
59
-				// register shortcode
60
-				$this->register_shortcode();
61
-
62
-				// register block
63
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
64
-			}
65
-
66
-			// add the CSS and JS we need ONCE
67
-			global $sd_widget_scripts;
68
-
69
-			if ( ! $sd_widget_scripts ) {
70
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
71
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
72
-				wp_add_inline_style( 'widgets', $this->widget_css() );
73
-
74
-				$sd_widget_scripts = true;
75
-
76
-				// add shortcode insert button once
77
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
78
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
79
-			}
80
-
81
-			do_action( 'wp_super_duper_widget_init', $options, $this );
82
-		}
83
-
84
-		/**
85
-		 * Get widget settings.
86
-		 *
87
-		 * @since 1.0.0
88
-		 */
89
-		public static function get_widget_settings() {
90
-			global $sd_widgets;
91
-
92
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
93
-			if ( ! $shortcode ) {
94
-				wp_die();
95
-			}
96
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
97
-			if ( ! $widget_args ) {
98
-				wp_die();
99
-			}
100
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
101
-			if ( ! $class_name ) {
102
-				wp_die();
103
-			}
104
-
105
-			// invoke an instance method
106
-			$widget = new $class_name;
107
-
108
-			ob_start();
109
-			$widget->form( array() );
110
-			$form = ob_get_clean();
111
-			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
112
-			echo "<style>" . $widget->widget_css() . "</style>";
113
-			echo "<script>" . $widget->widget_js() . "</script>";
114
-			?>
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
+     * @ver 1.0.5
21
+     */
22
+    class WP_Super_Duper extends WP_Widget {
23
+
24
+
25
+        public $version = "1.0.5";
26
+        public $block_code;
27
+        public $options;
28
+        public $base_id;
29
+        public $arguments = array();
30
+        public $instance = array();
31
+        private $class_name;
32
+
33
+        /**
34
+         * Take the array options and use them to build.
35
+         */
36
+        public function __construct( $options ) {
37
+            global $sd_widgets;
38
+
39
+            $sd_widgets[ $options['base_id'] ] = array( 'name'       => $options['name'],
40
+                                                        'class_name' => $options['class_name']
41
+            );
42
+            $this->base_id                     = $options['base_id'];
43
+            // lets filter the options before we do anything
44
+            $options       = apply_filters( "wp_super_duper_options", $options );
45
+            $options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
46
+            $options       = $this->add_name_from_key( $options );
47
+            $this->options = $options;
48
+
49
+            $this->base_id   = $options['base_id'];
50
+            $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
51
+
52
+            // init parent
53
+            parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
54
+
55
+            if ( isset( $options['class_name'] ) ) {
56
+                // register widget
57
+                $this->class_name = $options['class_name'];
58
+
59
+                // register shortcode
60
+                $this->register_shortcode();
61
+
62
+                // register block
63
+                add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
64
+            }
65
+
66
+            // add the CSS and JS we need ONCE
67
+            global $sd_widget_scripts;
68
+
69
+            if ( ! $sd_widget_scripts ) {
70
+                wp_add_inline_script( 'admin-widgets', $this->widget_js() );
71
+                wp_add_inline_script( 'customize-controls', $this->widget_js() );
72
+                wp_add_inline_style( 'widgets', $this->widget_css() );
73
+
74
+                $sd_widget_scripts = true;
75
+
76
+                // add shortcode insert button once
77
+                add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
78
+                add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
79
+            }
80
+
81
+            do_action( 'wp_super_duper_widget_init', $options, $this );
82
+        }
83
+
84
+        /**
85
+         * Get widget settings.
86
+         *
87
+         * @since 1.0.0
88
+         */
89
+        public static function get_widget_settings() {
90
+            global $sd_widgets;
91
+
92
+            $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
93
+            if ( ! $shortcode ) {
94
+                wp_die();
95
+            }
96
+            $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
97
+            if ( ! $widget_args ) {
98
+                wp_die();
99
+            }
100
+            $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
101
+            if ( ! $class_name ) {
102
+                wp_die();
103
+            }
104
+
105
+            // invoke an instance method
106
+            $widget = new $class_name;
107
+
108
+            ob_start();
109
+            $widget->form( array() );
110
+            $form = ob_get_clean();
111
+            echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
112
+            echo "<style>" . $widget->widget_css() . "</style>";
113
+            echo "<script>" . $widget->widget_js() . "</script>";
114
+            ?>
115 115
 			<?php
116
-			wp_die();
117
-		}
118
-
119
-		/**
120
-		 * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
121
-		 *
122
-		 * @since 1.0.0
123
-		 *
124
-		 * @param string $editor_id Optional. Shortcode editor id. Default null.
125
-		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
126
-		 */
127
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
128
-			global $sd_widgets, $shortcode_insert_button_once;
129
-			if ( $shortcode_insert_button_once ) {
130
-				return;
131
-			}
132
-			add_thickbox();
133
-			?>
116
+            wp_die();
117
+        }
118
+
119
+        /**
120
+         * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed).
121
+         *
122
+         * @since 1.0.0
123
+         *
124
+         * @param string $editor_id Optional. Shortcode editor id. Default null.
125
+         * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
126
+         */
127
+        public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
128
+            global $sd_widgets, $shortcode_insert_button_once;
129
+            if ( $shortcode_insert_button_once ) {
130
+                return;
131
+            }
132
+            add_thickbox();
133
+            ?>
134 134
 			<div id="super-duper-content" style="display:none;">
135 135
 
136 136
 				<div class="sd-shortcode-left-wrap">
137 137
 					<?php
138
-					asort( $sd_widgets );
139
-					if ( ! empty( $sd_widgets ) ) {
140
-						echo '<select onchange="sd_get_shortcode_options(this);">';
141
-						echo "<option>" . __( 'Select shortcode' ) . "</option>";
142
-						foreach ( $sd_widgets as $shortcode => $class ) {
143
-							echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
144
-						}
145
-						echo "</select>";
146
-
147
-					}
148
-					?>
138
+                    asort( $sd_widgets );
139
+                    if ( ! empty( $sd_widgets ) ) {
140
+                        echo '<select onchange="sd_get_shortcode_options(this);">';
141
+                        echo "<option>" . __( 'Select shortcode' ) . "</option>";
142
+                        foreach ( $sd_widgets as $shortcode => $class ) {
143
+                            echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
144
+                        }
145
+                        echo "</select>";
146
+
147
+                    }
148
+                    ?>
149 149
 					<div class="sd-shortcode-settings"></div>
150 150
 
151 151
 				</div>
@@ -163,9 +163,9 @@  discard block
 block discarded – undo
163 163
 			</div>
164 164
 
165 165
 			<?php
166
-			// if Font Awesome is available then show a icon if not show a WP icon.
167
-			$button_string = wp_style_is( 'font-awesome', 'enqueued' ) && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>';
168
-			?>
166
+            // if Font Awesome is available then show a icon if not show a WP icon.
167
+            $button_string = wp_style_is( 'font-awesome', 'enqueued' ) && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>';
168
+            ?>
169 169
 
170 170
 			<a href="#TB_inline?width=100%&height=550&inlineId=super-duper-content"
171 171
 			   class="thickbox button super-duper-content-open"
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
 			<script>
195 195
 
196 196
 				<?php
197
-				if(! empty( $insert_shortcode_function )){
198
-					echo $insert_shortcode_function;
199
-				}else{
200
-
201
-				/**
202
-				 * Function for super duper insert shortcode.
203
-				 *
204
-				 * @since 1.0.0
205
-				 */
206
-				?>
197
+                if(! empty( $insert_shortcode_function )){
198
+                    echo $insert_shortcode_function;
199
+                }else{
200
+
201
+                /**
202
+                 * Function for super duper insert shortcode.
203
+                 *
204
+                 * @since 1.0.0
205
+                 */
206
+                ?>
207 207
 				function sd_insert_shortcode() {
208 208
 					$shortcode = jQuery('#sd-shortcode-output').val();
209 209
 					if ($shortcode) {
@@ -333,12 +333,12 @@  discard block
 block discarded – undo
333 333
 				}
334 334
 			</script>
335 335
 			<?php
336
-			$shortcode_insert_button_once = true;
337
-		}
336
+            $shortcode_insert_button_once = true;
337
+        }
338 338
 
339
-		public function widget_css() {
340
-			ob_start();
341
-			?>
339
+        public function widget_css() {
340
+            ob_start();
341
+            ?>
342 342
 			<style>
343 343
 				.sd-advanced-setting {
344 344
 					display: none;
@@ -359,20 +359,20 @@  discard block
 block discarded – undo
359 359
 				}
360 360
 			</style>
361 361
 			<?php
362
-			$output = ob_get_clean();
362
+            $output = ob_get_clean();
363 363
 
364
-			/*
364
+            /*
365 365
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
366 366
 			 */
367
-			return str_replace( array(
368
-				'<style>',
369
-				'</style>'
370
-			), '', $output );
371
-		}
372
-
373
-		public function widget_js() {
374
-			ob_start();
375
-			?>
367
+            return str_replace( array(
368
+                '<style>',
369
+                '</style>'
370
+            ), '', $output );
371
+        }
372
+
373
+        public function widget_js() {
374
+            ob_start();
375
+            ?>
376 376
 			<script>
377 377
 
378 378
 				/**
@@ -527,279 +527,279 @@  discard block
 block discarded – undo
527 527
 				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
528 528
 			</script>
529 529
 			<?php
530
-			$output = ob_get_clean();
530
+            $output = ob_get_clean();
531 531
 
532
-			/*
532
+            /*
533 533
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
534 534
 			 */
535
-			return str_replace( array(
536
-				'<script>',
537
-				'</script>'
538
-			), '', $output );
539
-		}
540
-
541
-
542
-		/**
543
-		 * Set the name from the argument key.
544
-		 *
545
-		 * @param $options
546
-		 *
547
-		 * @return mixed
548
-		 */
549
-		private function add_name_from_key( $options, $arguments = false ) {
550
-			if ( ! empty( $options['arguments'] ) ) {
551
-				foreach ( $options['arguments'] as $key => $val ) {
552
-					$options['arguments'][ $key ]['name'] = $key;
553
-				}
554
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
555
-				foreach ( $options as $key => $val ) {
556
-					$options[ $key ]['name'] = $key;
557
-				}
558
-			}
559
-
560
-			return $options;
561
-		}
562
-
563
-		/**
564
-		 * Register the parent shortcode.
565
-		 *
566
-		 * @since 1.0.0
567
-		 */
568
-		public function register_shortcode() {
569
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
570
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
571
-		}
572
-
573
-		/**
574
-		 * Render the shortcode via ajax so we can return it to Gutenberg.
575
-		 *
576
-		 * @since 1.0.0
577
-		 */
578
-		public static function render_shortcode() {
579
-
580
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
581
-			if ( ! current_user_can( 'manage_options' ) ) {
582
-				wp_die();
583
-			}
584
-
585
-			// we might need the $post value here so lets set it.
586
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
587
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
588
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
589
-					global $post;
590
-					$post = $post_obj;
591
-				}
592
-			}
593
-
594
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
595
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
596
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
597
-				$attributes       = '';
598
-				if ( ! empty( $attributes_array ) ) {
599
-					foreach ( $attributes_array as $key => $value ) {
600
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
601
-					}
602
-				}
603
-
604
-				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
605
-
606
-				echo do_shortcode( $shortcode );
607
-
608
-			}
609
-			wp_die();
610
-		}
611
-
612
-		/**
613
-		 * Output the shortcode.
614
-		 *
615
-		 * @param array $args
616
-		 * @param string $content
617
-		 *
618
-		 * @return string
619
-		 */
620
-		public function shortcode_output( $args = array(), $content = '' ) {
621
-			$args = self::argument_values( $args );
622
-
623
-			// add extra argument so we know its a output to gutenberg
624
-			//$args
625
-			$args = $this->string_to_bool( $args );
626
-
627
-
628
-			$calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
629
-
630
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
631
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
632
-
633
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
634
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
635
-
636
-			$shortcode_args = array();
637
-			$output         = '';
638
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
639
-			$main_content   = $this->output( $args, $shortcode_args, $content );
640
-			if ( $main_content && ! $no_wrap ) {
641
-				// wrap the shortcode in a dive with the same class as the widget
642
-				$output .= '<div class="' . $calss . '" ' . $attrs . '>';
643
-				if ( ! empty( $args['title'] ) ) {
644
-					// if its a shortcode and there is a title try to grab the title wrappers
645
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
646
-					if ( empty( $instance ) ) {
647
-						global $wp_registered_sidebars;
648
-						if ( ! empty( $wp_registered_sidebars ) ) {
649
-							foreach ( $wp_registered_sidebars as $sidebar ) {
650
-								if ( ! empty( $sidebar['before_title'] ) ) {
651
-									$shortcode_args['before_title'] = $sidebar['before_title'];
652
-									$shortcode_args['after_title']  = $sidebar['after_title'];
653
-									break;
654
-								}
655
-							}
656
-						}
657
-					}
658
-					$output .= $this->output_title( $shortcode_args, $args );
659
-				}
660
-				$output .= $main_content;
661
-				$output .= '</div>';
662
-			} elseif ( $main_content && $no_wrap ) {
663
-				$output .= $main_content;
664
-			}
665
-
666
-			return $output;
667
-		}
668
-
669
-		/**
670
-		 * Sometimes booleans values can be turned to strings, so we fix that.
671
-		 *
672
-		 * @param $options
673
-		 *
674
-		 * @return mixed
675
-		 */
676
-		public function string_to_bool( $options ) {
677
-			// convert bool strings to booleans
678
-			foreach ( $options as $key => $val ) {
679
-				if ( $val == 'false' ) {
680
-					$options[ $key ] = false;
681
-				} elseif ( $val == 'true' ) {
682
-					$options[ $key ] = true;
683
-				}
684
-			}
685
-
686
-			return $options;
687
-		}
688
-
689
-		/**
690
-		 * Get the argument values that are also filterable.
691
-		 *
692
-		 * @param $instance
693
-		 *
694
-		 * @return array
695
-		 */
696
-		public function argument_values( $instance ) {
697
-			$argument_values = array();
698
-
699
-			// set widget instance
700
-			$this->instance = $instance;
701
-
702
-			if ( empty( $this->arguments ) ) {
703
-				$this->arguments = $this->get_arguments();
704
-			}
705
-
706
-			if ( ! empty( $this->arguments ) ) {
707
-				foreach ( $this->arguments as $key => $args ) {
708
-					// set the input name from the key
709
-					$args['name'] = $key;
710
-					//
711
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
712
-					if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
713
-						$argument_values[ $key ] = $args['default'];
714
-					}
715
-				}
716
-			}
717
-
718
-			return $argument_values;
719
-		}
720
-
721
-		/**
722
-		 * Set arguments in super duper.
723
-		 *
724
-		 * @since 1.0.0
725
-		 *
726
-		 * @return array Set arguments.
727
-		 */
728
-		public function set_arguments() {
729
-			return $this->arguments;
730
-		}
731
-
732
-		/**
733
-		 * Get arguments in super duper.
734
-		 *
735
-		 * @since 1.0.0
736
-		 *
737
-		 * @return array Get arguments.
738
-		 */
739
-		public function get_arguments() {
740
-			if ( empty( $this->arguments ) ) {
741
-				$this->arguments = $this->set_arguments();
742
-			}
743
-
744
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
745
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
746
-
747
-			return $this->arguments;
748
-		}
749
-
750
-		/**
751
-		 * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
752
-		 *
753
-		 * @param array $args
754
-		 * @param array $widget_args
755
-		 * @param string $content
756
-		 */
757
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
758
-
759
-		}
760
-
761
-		/**
762
-		 * Add the dynamic block code inline when the wp-block in enqueued.
763
-		 */
764
-		public function register_block() {
765
-			wp_add_inline_script( 'wp-blocks', $this->block() );
766
-		}
767
-
768
-		/**
769
-		 * Check if we need to show advanced options.
770
-		 *
771
-		 * @return bool
772
-		 */
773
-		public function block_show_advanced() {
774
-
775
-			$show      = false;
776
-			$arguments = $this->arguments;
777
-
778
-			if ( empty( $arguments ) ) {
779
-				$arguments = $this->get_arguments();
780
-			}
781
-
782
-			if ( ! empty( $arguments ) ) {
783
-				foreach ( $arguments as $argument ) {
784
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
785
-						$show = true;
786
-					}
787
-				}
788
-			}
789
-
790
-			return $show;
791
-		}
792
-
793
-
794
-		/**
795
-		 * Output the JS for building the dynamic Guntenberg block.
796
-		 *
797
-		 * @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.
798
-		 * @return mixed
799
-		 */
800
-		public function block() {
801
-			ob_start();
802
-			?>
535
+            return str_replace( array(
536
+                '<script>',
537
+                '</script>'
538
+            ), '', $output );
539
+        }
540
+
541
+
542
+        /**
543
+         * Set the name from the argument key.
544
+         *
545
+         * @param $options
546
+         *
547
+         * @return mixed
548
+         */
549
+        private function add_name_from_key( $options, $arguments = false ) {
550
+            if ( ! empty( $options['arguments'] ) ) {
551
+                foreach ( $options['arguments'] as $key => $val ) {
552
+                    $options['arguments'][ $key ]['name'] = $key;
553
+                }
554
+            } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
555
+                foreach ( $options as $key => $val ) {
556
+                    $options[ $key ]['name'] = $key;
557
+                }
558
+            }
559
+
560
+            return $options;
561
+        }
562
+
563
+        /**
564
+         * Register the parent shortcode.
565
+         *
566
+         * @since 1.0.0
567
+         */
568
+        public function register_shortcode() {
569
+            add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
570
+            add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
571
+        }
572
+
573
+        /**
574
+         * Render the shortcode via ajax so we can return it to Gutenberg.
575
+         *
576
+         * @since 1.0.0
577
+         */
578
+        public static function render_shortcode() {
579
+
580
+            check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
581
+            if ( ! current_user_can( 'manage_options' ) ) {
582
+                wp_die();
583
+            }
584
+
585
+            // we might need the $post value here so lets set it.
586
+            if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
587
+                $post_obj = get_post( absint( $_POST['post_id'] ) );
588
+                if ( ! empty( $post_obj ) && empty( $post ) ) {
589
+                    global $post;
590
+                    $post = $post_obj;
591
+                }
592
+            }
593
+
594
+            if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
595
+                $shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
596
+                $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
597
+                $attributes       = '';
598
+                if ( ! empty( $attributes_array ) ) {
599
+                    foreach ( $attributes_array as $key => $value ) {
600
+                        $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
601
+                    }
602
+                }
603
+
604
+                $shortcode = "[" . $shortcode_name . " " . $attributes . "]";
605
+
606
+                echo do_shortcode( $shortcode );
607
+
608
+            }
609
+            wp_die();
610
+        }
611
+
612
+        /**
613
+         * Output the shortcode.
614
+         *
615
+         * @param array $args
616
+         * @param string $content
617
+         *
618
+         * @return string
619
+         */
620
+        public function shortcode_output( $args = array(), $content = '' ) {
621
+            $args = self::argument_values( $args );
622
+
623
+            // add extra argument so we know its a output to gutenberg
624
+            //$args
625
+            $args = $this->string_to_bool( $args );
626
+
627
+
628
+            $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
629
+
630
+            $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
631
+            $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
632
+
633
+            $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
634
+            $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
635
+
636
+            $shortcode_args = array();
637
+            $output         = '';
638
+            $no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
639
+            $main_content   = $this->output( $args, $shortcode_args, $content );
640
+            if ( $main_content && ! $no_wrap ) {
641
+                // wrap the shortcode in a dive with the same class as the widget
642
+                $output .= '<div class="' . $calss . '" ' . $attrs . '>';
643
+                if ( ! empty( $args['title'] ) ) {
644
+                    // if its a shortcode and there is a title try to grab the title wrappers
645
+                    $shortcode_args = array( 'before_title' => '', 'after_title' => '' );
646
+                    if ( empty( $instance ) ) {
647
+                        global $wp_registered_sidebars;
648
+                        if ( ! empty( $wp_registered_sidebars ) ) {
649
+                            foreach ( $wp_registered_sidebars as $sidebar ) {
650
+                                if ( ! empty( $sidebar['before_title'] ) ) {
651
+                                    $shortcode_args['before_title'] = $sidebar['before_title'];
652
+                                    $shortcode_args['after_title']  = $sidebar['after_title'];
653
+                                    break;
654
+                                }
655
+                            }
656
+                        }
657
+                    }
658
+                    $output .= $this->output_title( $shortcode_args, $args );
659
+                }
660
+                $output .= $main_content;
661
+                $output .= '</div>';
662
+            } elseif ( $main_content && $no_wrap ) {
663
+                $output .= $main_content;
664
+            }
665
+
666
+            return $output;
667
+        }
668
+
669
+        /**
670
+         * Sometimes booleans values can be turned to strings, so we fix that.
671
+         *
672
+         * @param $options
673
+         *
674
+         * @return mixed
675
+         */
676
+        public function string_to_bool( $options ) {
677
+            // convert bool strings to booleans
678
+            foreach ( $options as $key => $val ) {
679
+                if ( $val == 'false' ) {
680
+                    $options[ $key ] = false;
681
+                } elseif ( $val == 'true' ) {
682
+                    $options[ $key ] = true;
683
+                }
684
+            }
685
+
686
+            return $options;
687
+        }
688
+
689
+        /**
690
+         * Get the argument values that are also filterable.
691
+         *
692
+         * @param $instance
693
+         *
694
+         * @return array
695
+         */
696
+        public function argument_values( $instance ) {
697
+            $argument_values = array();
698
+
699
+            // set widget instance
700
+            $this->instance = $instance;
701
+
702
+            if ( empty( $this->arguments ) ) {
703
+                $this->arguments = $this->get_arguments();
704
+            }
705
+
706
+            if ( ! empty( $this->arguments ) ) {
707
+                foreach ( $this->arguments as $key => $args ) {
708
+                    // set the input name from the key
709
+                    $args['name'] = $key;
710
+                    //
711
+                    $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
712
+                    if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
713
+                        $argument_values[ $key ] = $args['default'];
714
+                    }
715
+                }
716
+            }
717
+
718
+            return $argument_values;
719
+        }
720
+
721
+        /**
722
+         * Set arguments in super duper.
723
+         *
724
+         * @since 1.0.0
725
+         *
726
+         * @return array Set arguments.
727
+         */
728
+        public function set_arguments() {
729
+            return $this->arguments;
730
+        }
731
+
732
+        /**
733
+         * Get arguments in super duper.
734
+         *
735
+         * @since 1.0.0
736
+         *
737
+         * @return array Get arguments.
738
+         */
739
+        public function get_arguments() {
740
+            if ( empty( $this->arguments ) ) {
741
+                $this->arguments = $this->set_arguments();
742
+            }
743
+
744
+            $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
745
+            $this->arguments = $this->add_name_from_key( $this->arguments, true );
746
+
747
+            return $this->arguments;
748
+        }
749
+
750
+        /**
751
+         * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
752
+         *
753
+         * @param array $args
754
+         * @param array $widget_args
755
+         * @param string $content
756
+         */
757
+        public function output( $args = array(), $widget_args = array(), $content = '' ) {
758
+
759
+        }
760
+
761
+        /**
762
+         * Add the dynamic block code inline when the wp-block in enqueued.
763
+         */
764
+        public function register_block() {
765
+            wp_add_inline_script( 'wp-blocks', $this->block() );
766
+        }
767
+
768
+        /**
769
+         * Check if we need to show advanced options.
770
+         *
771
+         * @return bool
772
+         */
773
+        public function block_show_advanced() {
774
+
775
+            $show      = false;
776
+            $arguments = $this->arguments;
777
+
778
+            if ( empty( $arguments ) ) {
779
+                $arguments = $this->get_arguments();
780
+            }
781
+
782
+            if ( ! empty( $arguments ) ) {
783
+                foreach ( $arguments as $argument ) {
784
+                    if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
785
+                        $show = true;
786
+                    }
787
+                }
788
+            }
789
+
790
+            return $show;
791
+        }
792
+
793
+
794
+        /**
795
+         * Output the JS for building the dynamic Guntenberg block.
796
+         *
797
+         * @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.
798
+         * @return mixed
799
+         */
800
+        public function block() {
801
+            ob_start();
802
+            ?>
803 803
 			<script>
804 804
 				/**
805 805
 				 * BLOCK: Basic
@@ -838,76 +838,76 @@  discard block
 block discarded – undo
838 838
 						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/.
839 839
 						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.
840 840
 						<?php if ( isset( $this->options['block-keywords'] ) ) {
841
-						echo "keywords : " . $this->options['block-keywords'] . ",";
842
-					}?>
841
+                        echo "keywords : " . $this->options['block-keywords'] . ",";
842
+                    }?>
843 843
 
844 844
 						<?php
845 845
 
846
-						$show_advanced = $this->block_show_advanced();
847
-
848
-						$show_alignment = false;
849
-
850
-						if ( ! empty( $this->arguments ) ) {
851
-							echo "attributes : {";
852
-
853
-							if ( $show_advanced ) {
854
-								echo "show_advanced: {";
855
-								echo "	type: 'boolean',";
856
-								echo "  default: false,";
857
-								echo "},";
858
-							}
859
-
860
-							// block wrap element
861
-							if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
862
-								echo "block_wrap: {";
863
-								echo "	type: 'string',";
864
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
865
-								echo "},";
866
-							}
867
-
868
-
869
-							foreach ( $this->arguments as $key => $args ) {
870
-
871
-								// set if we should show alignment
872
-								if ( $key == 'alignment' ) {
873
-									$show_alignment = true;
874
-								}
875
-
876
-								$extra = '';
877
-
878
-								if ( $args['type'] == 'checkbox' ) {
879
-									$type    = 'boolean';
880
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
881
-								} elseif ( $args['type'] == 'number' ) {
882
-									$type    = 'number';
883
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
884
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
885
-									$type = 'array';
886
-									if ( is_array( $args['default'] ) ) {
887
-										$default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
888
-									} else {
889
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
890
-									}
891
-								} elseif ( $args['type'] == 'multiselect' ) {
892
-									$type    = 'array';
893
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
894
-								} else {
895
-									$type    = 'string';
896
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
897
-								}
898
-								echo $key . " : {";
899
-								echo "type : '$type',";
900
-								echo "default : $default,";
901
-								echo "},";
902
-							}
903
-
904
-							echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
905
-
906
-							echo "},";
907
-
908
-						}
909
-
910
-						?>
846
+                        $show_advanced = $this->block_show_advanced();
847
+
848
+                        $show_alignment = false;
849
+
850
+                        if ( ! empty( $this->arguments ) ) {
851
+                            echo "attributes : {";
852
+
853
+                            if ( $show_advanced ) {
854
+                                echo "show_advanced: {";
855
+                                echo "	type: 'boolean',";
856
+                                echo "  default: false,";
857
+                                echo "},";
858
+                            }
859
+
860
+                            // block wrap element
861
+                            if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
862
+                                echo "block_wrap: {";
863
+                                echo "	type: 'string',";
864
+                                echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
865
+                                echo "},";
866
+                            }
867
+
868
+
869
+                            foreach ( $this->arguments as $key => $args ) {
870
+
871
+                                // set if we should show alignment
872
+                                if ( $key == 'alignment' ) {
873
+                                    $show_alignment = true;
874
+                                }
875
+
876
+                                $extra = '';
877
+
878
+                                if ( $args['type'] == 'checkbox' ) {
879
+                                    $type    = 'boolean';
880
+                                    $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
881
+                                } elseif ( $args['type'] == 'number' ) {
882
+                                    $type    = 'number';
883
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
884
+                                } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
885
+                                    $type = 'array';
886
+                                    if ( is_array( $args['default'] ) ) {
887
+                                        $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
888
+                                    } else {
889
+                                        $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
890
+                                    }
891
+                                } elseif ( $args['type'] == 'multiselect' ) {
892
+                                    $type    = 'array';
893
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
894
+                                } else {
895
+                                    $type    = 'string';
896
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
897
+                                }
898
+                                echo $key . " : {";
899
+                                echo "type : '$type',";
900
+                                echo "default : $default,";
901
+                                echo "},";
902
+                            }
903
+
904
+                            echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
905
+
906
+                            echo "},";
907
+
908
+                        }
909
+
910
+                        ?>
911 911
 
912 912
 						// The "edit" property must be a valid function.
913 913
 						edit: function (props) {
@@ -926,8 +926,8 @@  discard block
 block discarded – undo
926 926
 										'shortcode': '<?php echo $this->options['base_id'];?>',
927 927
 										'attributes': props.attributes,
928 928
 										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
929
-										echo $post->ID;
930
-									}?>,
929
+                                        echo $post->ID;
930
+                                    }?>,
931 931
 										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
932 932
 									};
933 933
 
@@ -974,10 +974,10 @@  discard block
 block discarded – undo
974 974
 
975 975
 									<?php
976 976
 
977
-									if(! empty( $this->arguments )){
977
+                                    if(! empty( $this->arguments )){
978 978
 
979
-									if ( $show_advanced ) {
980
-									?>
979
+                                    if ( $show_advanced ) {
980
+                                    ?>
981 981
 									el(
982 982
 										wp.components.ToggleControl,
983 983
 										{
@@ -990,65 +990,65 @@  discard block
 block discarded – undo
990 990
 									),
991 991
 									<?php
992 992
 
993
-									}
994
-
995
-									foreach($this->arguments as $key => $args){
996
-									$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
997
-									$options = '';
998
-									$extra = '';
999
-									$require = '';
1000
-									$onchange = "props.setAttributes({ $key: $key } )";
1001
-									$value = "props.attributes.$key";
1002
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1003
-									if ( in_array( $args['type'], $text_type ) ) {
1004
-										$type = 'TextControl';
1005
-									} elseif ( $args['type'] == 'checkbox' ) {
1006
-										$type = 'CheckboxControl';
1007
-										$extra .= "checked: props.attributes.$key,";
1008
-										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1009
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1010
-										$type = 'SelectControl';
1011
-										if ( ! empty( $args['options'] ) ) {
1012
-											$options .= "options  : [";
1013
-											foreach ( $args['options'] as $option_val => $option_label ) {
1014
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1015
-											}
1016
-											$options .= "],";
1017
-										}
1018
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1019
-											$extra .= ' multiple: true, ';
1020
-											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1021
-											//$value = "['edit', 'delete']";
1022
-										}
1023
-									} elseif ( $args['type'] == 'alignment' ) {
1024
-										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1025
-									} else {
1026
-										continue;// if we have not implemented the control then don't break the JS.
1027
-									}
1028
-
1029
-									// add show only if advanced
1030
-									if ( ! empty( $args['advanced'] ) ) {
1031
-										echo "props.attributes.show_advanced && ";
1032
-									}
1033
-									// add setting require if defined
1034
-									if ( ! empty( $args['element_require'] ) ) {
1035
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1036
-									}
1037
-									?>
993
+                                    }
994
+
995
+                                    foreach($this->arguments as $key => $args){
996
+                                    $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
997
+                                    $options = '';
998
+                                    $extra = '';
999
+                                    $require = '';
1000
+                                    $onchange = "props.setAttributes({ $key: $key } )";
1001
+                                    $value = "props.attributes.$key";
1002
+                                    $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1003
+                                    if ( in_array( $args['type'], $text_type ) ) {
1004
+                                        $type = 'TextControl';
1005
+                                    } elseif ( $args['type'] == 'checkbox' ) {
1006
+                                        $type = 'CheckboxControl';
1007
+                                        $extra .= "checked: props.attributes.$key,";
1008
+                                        $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1009
+                                    } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1010
+                                        $type = 'SelectControl';
1011
+                                        if ( ! empty( $args['options'] ) ) {
1012
+                                            $options .= "options  : [";
1013
+                                            foreach ( $args['options'] as $option_val => $option_label ) {
1014
+                                                $options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1015
+                                            }
1016
+                                            $options .= "],";
1017
+                                        }
1018
+                                        if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1019
+                                            $extra .= ' multiple: true, ';
1020
+                                            //$onchange = "props.setAttributes({ $key: ['edit'] } )";
1021
+                                            //$value = "['edit', 'delete']";
1022
+                                        }
1023
+                                    } elseif ( $args['type'] == 'alignment' ) {
1024
+                                        $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1025
+                                    } else {
1026
+                                        continue;// if we have not implemented the control then don't break the JS.
1027
+                                    }
1028
+
1029
+                                    // add show only if advanced
1030
+                                    if ( ! empty( $args['advanced'] ) ) {
1031
+                                        echo "props.attributes.show_advanced && ";
1032
+                                    }
1033
+                                    // add setting require if defined
1034
+                                    if ( ! empty( $args['element_require'] ) ) {
1035
+                                        echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1036
+                                    }
1037
+                                    ?>
1038 1038
 									el(
1039 1039
 										wp.components.<?php echo esc_attr( $type );?>,
1040 1040
 										{
1041 1041
 											label: '<?php echo esc_attr( $args['title'] );?>',
1042 1042
 											help: '<?php if ( isset( $args['desc'] ) ) {
1043
-												echo esc_attr( $args['desc'] );
1044
-											}?>',
1043
+                                                echo esc_attr( $args['desc'] );
1044
+                                            }?>',
1045 1045
 											value: <?php echo $value;?>,
1046 1046
 											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1047
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1048
-										}?>
1047
+                                            echo "type: '" . esc_attr( $args['type'] ) . "',";
1048
+                                        }?>
1049 1049
 											<?php if ( ! empty( $args['placeholder'] ) ) {
1050
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1051
-										}?>
1050
+                                            echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1051
+                                        }?>
1052 1052
 											<?php echo $options;?>
1053 1053
 											<?php echo $extra;?>
1054 1054
 											<?php echo $custom_attributes;?>
@@ -1058,27 +1058,27 @@  discard block
 block discarded – undo
1058 1058
 										}
1059 1059
 									),
1060 1060
 									<?php
1061
-									}
1062
-									}
1063
-									?>
1061
+                                    }
1062
+                                    }
1063
+                                    ?>
1064 1064
 
1065 1065
 								),
1066 1066
 
1067 1067
 								<?php
1068
-								// If the user sets block-output array then build it
1069
-								if ( ! empty( $this->options['block-output'] ) ) {
1070
-								$this->block_element( $this->options['block-output'] );
1071
-							}else{
1072
-								// if no block-output is set then we try and get the shortcode html output via ajax.
1073
-								?>
1068
+                                // If the user sets block-output array then build it
1069
+                                if ( ! empty( $this->options['block-output'] ) ) {
1070
+                                $this->block_element( $this->options['block-output'] );
1071
+                            }else{
1072
+                                // if no block-output is set then we try and get the shortcode html output via ajax.
1073
+                                ?>
1074 1074
 								el('div', {
1075 1075
 									dangerouslySetInnerHTML: {__html: onChangeContent()},
1076 1076
 									className: props.className,
1077 1077
 									style: {'min-height': '30px'}
1078 1078
 								})
1079 1079
 								<?php
1080
-								}
1081
-								?>
1080
+                                }
1081
+                                ?>
1082 1082
 							]; // end return
1083 1083
 						},
1084 1084
 
@@ -1095,17 +1095,17 @@  discard block
 block discarded – undo
1095 1095
 							var content = "[<?php echo $this->options['base_id'];?>";
1096 1096
 							<?php
1097 1097
 
1098
-							if(! empty( $this->arguments )){
1099
-							foreach($this->arguments as $key => $args){
1100
-							?>
1098
+                            if(! empty( $this->arguments )){
1099
+                            foreach($this->arguments as $key => $args){
1100
+                            ?>
1101 1101
 							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1102 1102
 								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1103 1103
 							}
1104 1104
 							<?php
1105
-							}
1106
-							}
1105
+                            }
1106
+                            }
1107 1107
 
1108
-							?>
1108
+                            ?>
1109 1109
 							content += "]";
1110 1110
 
1111 1111
 
@@ -1134,370 +1134,370 @@  discard block
 block discarded – undo
1134 1134
 				})();
1135 1135
 			</script>
1136 1136
 			<?php
1137
-			$output = ob_get_clean();
1137
+            $output = ob_get_clean();
1138 1138
 
1139
-			/*
1139
+            /*
1140 1140
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1141 1141
 			 */
1142 1142
 
1143
-			return str_replace( array(
1144
-				'<script>',
1145
-				'</script>'
1146
-			), '', $output );
1147
-		}
1148
-
1149
-		/**
1150
-		 * Convert an array of attributes to block string.
1151
-		 *
1152
-		 * @todo there is prob a faster way to do this, also we could add some validation here.
1153
-		 *
1154
-		 * @param $custom_attributes
1155
-		 *
1156
-		 * @return string
1157
-		 */
1158
-		public function array_to_attributes( $custom_attributes, $html = false ) {
1159
-			$attributes = '';
1160
-			if ( ! empty( $custom_attributes ) ) {
1161
-
1162
-				if ( $html ) {
1163
-					foreach ( $custom_attributes as $key => $val ) {
1164
-						$attributes .= " $key='$val' ";
1165
-					}
1166
-				} else {
1167
-					foreach ( $custom_attributes as $key => $val ) {
1168
-						$attributes .= "'$key': '$val',";
1169
-					}
1170
-				}
1171
-			}
1172
-
1173
-			return $attributes;
1174
-		}
1175
-
1176
-		/**
1177
-		 * A self looping function to create the output for JS block elements.
1178
-		 *
1179
-		 * This is what is output in the WP Editor visual view.
1180
-		 *
1181
-		 * @param $args
1182
-		 */
1183
-		public function block_element( $args ) {
1184
-
1185
-
1186
-			if ( ! empty( $args ) ) {
1187
-				foreach ( $args as $element => $new_args ) {
1188
-
1189
-					if ( is_array( $new_args ) ) { // its an element
1190
-
1191
-
1192
-						if ( isset( $new_args['element'] ) ) {
1193
-
1194
-							if ( isset( $new_args['element_require'] ) ) {
1195
-								echo str_replace( array(
1196
-										"'+",
1197
-										"+'"
1198
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1199
-								unset( $new_args['element_require'] );
1200
-							}
1201
-
1202
-							echo "\n el( '" . $new_args['element'] . "', {";
1203
-
1204
-							// get the attributes
1205
-							foreach ( $new_args as $new_key => $new_value ) {
1206
-
1207
-
1208
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1209
-									// do nothing
1210
-								} else {
1211
-									echo $this->block_element( array( $new_key => $new_value ) );
1212
-								}
1213
-							}
1214
-
1215
-							echo "},";// end attributes
1216
-
1217
-							// get the content
1218
-							$first_item = 0;
1219
-							foreach ( $new_args as $new_key => $new_value ) {
1220
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1221
-
1222
-									if ( $new_key === 'content' ) {
1223
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1224
-									}
1225
-
1226
-									if ( is_array( $new_value ) ) {
1227
-
1228
-										if ( isset( $new_value['element_require'] ) ) {
1229
-											echo str_replace( array(
1230
-													"'+",
1231
-													"+'"
1232
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1233
-											unset( $new_value['element_require'] );
1234
-										}
1235
-
1236
-										if ( isset( $new_value['element_repeat'] ) ) {
1237
-											$x = 1;
1238
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1239
-												$this->block_element( array( '' => $new_value ) );
1240
-												$x ++;
1241
-											}
1242
-										} else {
1243
-											$this->block_element( array( '' => $new_value ) );
1244
-										}
1245
-									}
1246
-									$first_item ++;
1247
-								}
1248
-							}
1249
-
1250
-							echo ")";// end content
1251
-
1252
-							echo ", \n";
1253
-
1254
-						}
1255
-					} else {
1256
-
1257
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1258
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1259
-						} elseif ( $element == 'style' ) {
1260
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1261
-						} else {
1262
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1263
-						}
1264
-
1265
-					}
1266
-				}
1267
-			}
1268
-		}
1269
-
1270
-		/**
1271
-		 * Replace block attributes placeholders with the proper naming.
1272
-		 *
1273
-		 * @param $string
1274
-		 *
1275
-		 * @return mixed
1276
-		 */
1277
-		public function block_props_replace( $string, $no_wrap = false ) {
1278
-
1279
-			if ( $no_wrap ) {
1280
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1281
-			} else {
1282
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1283
-			}
1284
-
1285
-			return $string;
1286
-		}
1287
-
1288
-		/**
1289
-		 * Outputs the content of the widget
1290
-		 *
1291
-		 * @param array $args
1292
-		 * @param array $instance
1293
-		 */
1294
-		public function widget( $args, $instance ) {
1295
-
1296
-			// get the filtered values
1297
-			$argument_values = $this->argument_values( $instance );
1298
-			$argument_values = $this->string_to_bool( $argument_values );
1299
-			$output          = $this->output( $argument_values, $args );
1300
-
1301
-			if ( $output ) {
1302
-				// Before widget
1303
-				$before_widget = $args['before_widget'];
1304
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1305
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1306
-
1307
-				// After widget
1308
-				$after_widget = $args['after_widget'];
1309
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1310
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1311
-
1312
-				echo $before_widget;
1313
-				// elementor strips the widget wrapping div so we check for and add it back if needed
1314
-				if ( $this->is_elementor_widget_output() ) {
1315
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1316
-				}
1317
-				echo $this->output_title( $args, $instance );
1318
-				echo $output;
1319
-				if ( $this->is_elementor_widget_output() ) {
1320
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1321
-				}
1322
-				echo $after_widget;
1323
-			}
1324
-		}
1325
-
1326
-		/**
1327
-		 * Tests if the current output is inside a elementor container.
1328
-		 *
1329
-		 * @since 1.0.4
1330
-		 * @return bool
1331
-		 */
1332
-		public function is_elementor_widget_output() {
1333
-			$result = false;
1334
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1335
-				$result = true;
1336
-			}
1337
-
1338
-			return $result;
1339
-		}
1340
-
1341
-		/**
1342
-		 * Tests if the current output is inside a elementor preview.
1343
-		 *
1344
-		 * @since 1.0.4
1345
-		 * @return bool
1346
-		 */
1347
-		public function is_elementor_preview() {
1348
-			$result = false;
1349
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1350
-				$result = true;
1351
-			}
1352
-
1353
-			return $result;
1354
-		}
1355
-
1356
-		/**
1357
-		 * Output the super title.
1358
-		 *
1359
-		 * @param $args
1360
-		 * @param array $instance
1361
-		 *
1362
-		 * @return string
1363
-		 */
1364
-		public function output_title( $args, $instance = array() ) {
1365
-			$output = '';
1366
-			if ( ! empty( $instance['title'] ) ) {
1367
-				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
1368
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
1369
-				$output = $args['before_title'] . $title . $args['after_title'];
1370
-			}
1371
-
1372
-			return $output;
1373
-		}
1374
-
1375
-		/**
1376
-		 * Outputs the options form inputs for the widget.
1377
-		 *
1378
-		 * @param array $instance The widget options.
1379
-		 */
1380
-		public function form( $instance ) {
1381
-
1382
-			// set widget instance
1383
-			$this->instance = $instance;
1384
-
1385
-			// set it as a SD widget
1386
-			echo $this->widget_advanced_toggle();
1387
-
1388
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
1389
-			$arguments = $this->get_arguments();
1390
-
1391
-			if ( is_array( $arguments ) ) {
1392
-				foreach ( $arguments as $key => $args ) {
1393
-					$this->widget_inputs( $args, $instance );
1394
-				}
1395
-			}
1396
-		}
1397
-
1398
-		/**
1399
-		 * Get the hidden input that when added makes the advanced button show on widget settings.
1400
-		 *
1401
-		 * @return string
1402
-		 */
1403
-		public function widget_advanced_toggle() {
1404
-
1405
-			$output = '';
1406
-			if ( $this->block_show_advanced() ) {
1407
-				$val = 1;
1408
-			} else {
1409
-				$val = 0;
1410
-			}
1411
-
1412
-			$output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
1413
-
1414
-			return $output;
1415
-		}
1416
-
1417
-		/**
1418
-		 * Convert require element.
1419
-		 *
1420
-		 * @since 1.0.0
1421
-		 *
1422
-		 * @param string $input Input element.
1423
-		 *
1424
-		 * @return string $output
1425
-		 */
1426
-		public function convert_element_require( $input ) {
1427
-
1428
-			$input = str_replace( "'", '"', $input );// we only want double quotes
1429
-
1430
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
1431
-				"jQuery(form).find('[data-argument=\"",
1432
-				"\"]').find('input,select').val()"
1433
-			), $input ) );
1434
-
1435
-			return $output;
1436
-		}
1437
-
1438
-		/**
1439
-		 * Builds the inputs for the widget options.
1440
-		 *
1441
-		 * @param $args
1442
-		 * @param $instance
1443
-		 */
1444
-		public function widget_inputs( $args, $instance ) {
1445
-
1446
-			$class             = "";
1447
-			$element_require   = "";
1448
-			$custom_attributes = "";
1449
-
1450
-			// get value
1451
-			if ( isset( $instance[ $args['name'] ] ) ) {
1452
-				$value = $instance[ $args['name'] ];
1453
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
1454
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
1455
-			} else {
1456
-				$value = '';
1457
-			}
1458
-
1459
-			// get placeholder
1460
-			if ( ! empty( $args['placeholder'] ) ) {
1461
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
1462
-			} else {
1463
-				$placeholder = '';
1464
-			}
1465
-
1466
-			// get if advanced
1467
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
1468
-				$class .= " sd-advanced-setting ";
1469
-			}
1470
-
1471
-			// element_require
1472
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
1473
-				$element_require = $args['element_require'];
1474
-			}
1475
-
1476
-			// custom_attributes
1477
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
1478
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
1479
-			}
1480
-
1481
-			// before wrapper
1482
-			?>
1143
+            return str_replace( array(
1144
+                '<script>',
1145
+                '</script>'
1146
+            ), '', $output );
1147
+        }
1148
+
1149
+        /**
1150
+         * Convert an array of attributes to block string.
1151
+         *
1152
+         * @todo there is prob a faster way to do this, also we could add some validation here.
1153
+         *
1154
+         * @param $custom_attributes
1155
+         *
1156
+         * @return string
1157
+         */
1158
+        public function array_to_attributes( $custom_attributes, $html = false ) {
1159
+            $attributes = '';
1160
+            if ( ! empty( $custom_attributes ) ) {
1161
+
1162
+                if ( $html ) {
1163
+                    foreach ( $custom_attributes as $key => $val ) {
1164
+                        $attributes .= " $key='$val' ";
1165
+                    }
1166
+                } else {
1167
+                    foreach ( $custom_attributes as $key => $val ) {
1168
+                        $attributes .= "'$key': '$val',";
1169
+                    }
1170
+                }
1171
+            }
1172
+
1173
+            return $attributes;
1174
+        }
1175
+
1176
+        /**
1177
+         * A self looping function to create the output for JS block elements.
1178
+         *
1179
+         * This is what is output in the WP Editor visual view.
1180
+         *
1181
+         * @param $args
1182
+         */
1183
+        public function block_element( $args ) {
1184
+
1185
+
1186
+            if ( ! empty( $args ) ) {
1187
+                foreach ( $args as $element => $new_args ) {
1188
+
1189
+                    if ( is_array( $new_args ) ) { // its an element
1190
+
1191
+
1192
+                        if ( isset( $new_args['element'] ) ) {
1193
+
1194
+                            if ( isset( $new_args['element_require'] ) ) {
1195
+                                echo str_replace( array(
1196
+                                        "'+",
1197
+                                        "+'"
1198
+                                    ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1199
+                                unset( $new_args['element_require'] );
1200
+                            }
1201
+
1202
+                            echo "\n el( '" . $new_args['element'] . "', {";
1203
+
1204
+                            // get the attributes
1205
+                            foreach ( $new_args as $new_key => $new_value ) {
1206
+
1207
+
1208
+                                if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1209
+                                    // do nothing
1210
+                                } else {
1211
+                                    echo $this->block_element( array( $new_key => $new_value ) );
1212
+                                }
1213
+                            }
1214
+
1215
+                            echo "},";// end attributes
1216
+
1217
+                            // get the content
1218
+                            $first_item = 0;
1219
+                            foreach ( $new_args as $new_key => $new_value ) {
1220
+                                if ( $new_key === 'content' || is_array( $new_value ) ) {
1221
+
1222
+                                    if ( $new_key === 'content' ) {
1223
+                                        echo "'" . $this->block_props_replace( $new_value ) . "'";
1224
+                                    }
1225
+
1226
+                                    if ( is_array( $new_value ) ) {
1227
+
1228
+                                        if ( isset( $new_value['element_require'] ) ) {
1229
+                                            echo str_replace( array(
1230
+                                                    "'+",
1231
+                                                    "+'"
1232
+                                                ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1233
+                                            unset( $new_value['element_require'] );
1234
+                                        }
1235
+
1236
+                                        if ( isset( $new_value['element_repeat'] ) ) {
1237
+                                            $x = 1;
1238
+                                            while ( $x <= absint( $new_value['element_repeat'] ) ) {
1239
+                                                $this->block_element( array( '' => $new_value ) );
1240
+                                                $x ++;
1241
+                                            }
1242
+                                        } else {
1243
+                                            $this->block_element( array( '' => $new_value ) );
1244
+                                        }
1245
+                                    }
1246
+                                    $first_item ++;
1247
+                                }
1248
+                            }
1249
+
1250
+                            echo ")";// end content
1251
+
1252
+                            echo ", \n";
1253
+
1254
+                        }
1255
+                    } else {
1256
+
1257
+                        if ( substr( $element, 0, 3 ) === "if_" ) {
1258
+                            echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1259
+                        } elseif ( $element == 'style' ) {
1260
+                            echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1261
+                        } else {
1262
+                            echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1263
+                        }
1264
+
1265
+                    }
1266
+                }
1267
+            }
1268
+        }
1269
+
1270
+        /**
1271
+         * Replace block attributes placeholders with the proper naming.
1272
+         *
1273
+         * @param $string
1274
+         *
1275
+         * @return mixed
1276
+         */
1277
+        public function block_props_replace( $string, $no_wrap = false ) {
1278
+
1279
+            if ( $no_wrap ) {
1280
+                $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1281
+            } else {
1282
+                $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1283
+            }
1284
+
1285
+            return $string;
1286
+        }
1287
+
1288
+        /**
1289
+         * Outputs the content of the widget
1290
+         *
1291
+         * @param array $args
1292
+         * @param array $instance
1293
+         */
1294
+        public function widget( $args, $instance ) {
1295
+
1296
+            // get the filtered values
1297
+            $argument_values = $this->argument_values( $instance );
1298
+            $argument_values = $this->string_to_bool( $argument_values );
1299
+            $output          = $this->output( $argument_values, $args );
1300
+
1301
+            if ( $output ) {
1302
+                // Before widget
1303
+                $before_widget = $args['before_widget'];
1304
+                $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1305
+                $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1306
+
1307
+                // After widget
1308
+                $after_widget = $args['after_widget'];
1309
+                $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1310
+                $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1311
+
1312
+                echo $before_widget;
1313
+                // elementor strips the widget wrapping div so we check for and add it back if needed
1314
+                if ( $this->is_elementor_widget_output() ) {
1315
+                    echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1316
+                }
1317
+                echo $this->output_title( $args, $instance );
1318
+                echo $output;
1319
+                if ( $this->is_elementor_widget_output() ) {
1320
+                    echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1321
+                }
1322
+                echo $after_widget;
1323
+            }
1324
+        }
1325
+
1326
+        /**
1327
+         * Tests if the current output is inside a elementor container.
1328
+         *
1329
+         * @since 1.0.4
1330
+         * @return bool
1331
+         */
1332
+        public function is_elementor_widget_output() {
1333
+            $result = false;
1334
+            if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1335
+                $result = true;
1336
+            }
1337
+
1338
+            return $result;
1339
+        }
1340
+
1341
+        /**
1342
+         * Tests if the current output is inside a elementor preview.
1343
+         *
1344
+         * @since 1.0.4
1345
+         * @return bool
1346
+         */
1347
+        public function is_elementor_preview() {
1348
+            $result = false;
1349
+            if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1350
+                $result = true;
1351
+            }
1352
+
1353
+            return $result;
1354
+        }
1355
+
1356
+        /**
1357
+         * Output the super title.
1358
+         *
1359
+         * @param $args
1360
+         * @param array $instance
1361
+         *
1362
+         * @return string
1363
+         */
1364
+        public function output_title( $args, $instance = array() ) {
1365
+            $output = '';
1366
+            if ( ! empty( $instance['title'] ) ) {
1367
+                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
1368
+                $title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
1369
+                $output = $args['before_title'] . $title . $args['after_title'];
1370
+            }
1371
+
1372
+            return $output;
1373
+        }
1374
+
1375
+        /**
1376
+         * Outputs the options form inputs for the widget.
1377
+         *
1378
+         * @param array $instance The widget options.
1379
+         */
1380
+        public function form( $instance ) {
1381
+
1382
+            // set widget instance
1383
+            $this->instance = $instance;
1384
+
1385
+            // set it as a SD widget
1386
+            echo $this->widget_advanced_toggle();
1387
+
1388
+            echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
1389
+            $arguments = $this->get_arguments();
1390
+
1391
+            if ( is_array( $arguments ) ) {
1392
+                foreach ( $arguments as $key => $args ) {
1393
+                    $this->widget_inputs( $args, $instance );
1394
+                }
1395
+            }
1396
+        }
1397
+
1398
+        /**
1399
+         * Get the hidden input that when added makes the advanced button show on widget settings.
1400
+         *
1401
+         * @return string
1402
+         */
1403
+        public function widget_advanced_toggle() {
1404
+
1405
+            $output = '';
1406
+            if ( $this->block_show_advanced() ) {
1407
+                $val = 1;
1408
+            } else {
1409
+                $val = 0;
1410
+            }
1411
+
1412
+            $output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
1413
+
1414
+            return $output;
1415
+        }
1416
+
1417
+        /**
1418
+         * Convert require element.
1419
+         *
1420
+         * @since 1.0.0
1421
+         *
1422
+         * @param string $input Input element.
1423
+         *
1424
+         * @return string $output
1425
+         */
1426
+        public function convert_element_require( $input ) {
1427
+
1428
+            $input = str_replace( "'", '"', $input );// we only want double quotes
1429
+
1430
+            $output = esc_attr( str_replace( array( "[%", "%]" ), array(
1431
+                "jQuery(form).find('[data-argument=\"",
1432
+                "\"]').find('input,select').val()"
1433
+            ), $input ) );
1434
+
1435
+            return $output;
1436
+        }
1437
+
1438
+        /**
1439
+         * Builds the inputs for the widget options.
1440
+         *
1441
+         * @param $args
1442
+         * @param $instance
1443
+         */
1444
+        public function widget_inputs( $args, $instance ) {
1445
+
1446
+            $class             = "";
1447
+            $element_require   = "";
1448
+            $custom_attributes = "";
1449
+
1450
+            // get value
1451
+            if ( isset( $instance[ $args['name'] ] ) ) {
1452
+                $value = $instance[ $args['name'] ];
1453
+            } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
1454
+                $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
1455
+            } else {
1456
+                $value = '';
1457
+            }
1458
+
1459
+            // get placeholder
1460
+            if ( ! empty( $args['placeholder'] ) ) {
1461
+                $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
1462
+            } else {
1463
+                $placeholder = '';
1464
+            }
1465
+
1466
+            // get if advanced
1467
+            if ( isset( $args['advanced'] ) && $args['advanced'] ) {
1468
+                $class .= " sd-advanced-setting ";
1469
+            }
1470
+
1471
+            // element_require
1472
+            if ( isset( $args['element_require'] ) && $args['element_require'] ) {
1473
+                $element_require = $args['element_require'];
1474
+            }
1475
+
1476
+            // custom_attributes
1477
+            if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
1478
+                $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
1479
+            }
1480
+
1481
+            // before wrapper
1482
+            ?>
1483 1483
 			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
1484 1484
 			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
1485 1485
 			   data-element_require='<?php if ( $element_require ) {
1486
-				   echo $this->convert_element_require( $element_require );
1487
-			   } ?>'
1486
+                    echo $this->convert_element_require( $element_require );
1487
+                } ?>'
1488 1488
 			>
1489 1489
 				<?php
1490 1490
 
1491
-				switch ( $args['type'] ) {
1492
-					//array('text','password','number','email','tel','url','color')
1493
-					case "text":
1494
-					case "password":
1495
-					case "number":
1496
-					case "email":
1497
-					case "tel":
1498
-					case "url":
1499
-					case "color":
1500
-						?>
1491
+                switch ( $args['type'] ) {
1492
+                    //array('text','password','number','email','tel','url','color')
1493
+                    case "text":
1494
+                    case "password":
1495
+                    case "number":
1496
+                    case "email":
1497
+                    case "tel":
1498
+                    case "url":
1499
+                    case "color":
1500
+                        ?>
1501 1501
 						<label
1502 1502
 							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>
1503 1503
 						<input <?php echo $placeholder; ?> class="widefat"
@@ -1508,47 +1508,47 @@  discard block
 block discarded – undo
1508 1508
 							                               value="<?php echo esc_attr( $value ); ?>">
1509 1509
 						<?php
1510 1510
 
1511
-						break;
1512
-					case "select":
1513
-						$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
1514
-						if ( $multiple ) {
1515
-							if ( empty( $value ) ) {
1516
-								$value = array();
1517
-							}
1518
-						}
1519
-						?>
1511
+                        break;
1512
+                    case "select":
1513
+                        $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
1514
+                        if ( $multiple ) {
1515
+                            if ( empty( $value ) ) {
1516
+                                $value = array();
1517
+                            }
1518
+                        }
1519
+                        ?>
1520 1520
 						<label
1521 1521
 							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>
1522 1522
 						<select <?php echo $placeholder; ?> class="widefat"
1523 1523
 							<?php echo $custom_attributes; ?>
1524 1524
 							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1525 1525
 							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
1526
-							                                if ( $multiple ) {
1527
-								                                echo "[]";
1528
-							                                } ?>"
1526
+                                                            if ( $multiple ) {
1527
+                                                                echo "[]";
1528
+                                                            } ?>"
1529 1529
 							<?php if ( $multiple ) {
1530
-								echo "multiple";
1531
-							} //@todo not implemented yet due to gutenberg not supporting it
1532
-							?>
1530
+                                echo "multiple";
1531
+                            } //@todo not implemented yet due to gutenberg not supporting it
1532
+                            ?>
1533 1533
 						>
1534 1534
 							<?php
1535 1535
 
1536
-							if ( ! empty( $args['options'] ) ) {
1537
-								foreach ( $args['options'] as $val => $label ) {
1538
-									if ( $multiple ) {
1539
-										$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
1540
-									} else {
1541
-										$selected = selected( $value, $val, false );
1542
-									}
1543
-									echo "<option value='$val' " . $selected . ">$label</option>";
1544
-								}
1545
-							}
1546
-							?>
1536
+                            if ( ! empty( $args['options'] ) ) {
1537
+                                foreach ( $args['options'] as $val => $label ) {
1538
+                                    if ( $multiple ) {
1539
+                                        $selected = in_array( $val, $value ) ? 'selected="selected"' : '';
1540
+                                    } else {
1541
+                                        $selected = selected( $value, $val, false );
1542
+                                    }
1543
+                                    echo "<option value='$val' " . $selected . ">$label</option>";
1544
+                                }
1545
+                            }
1546
+                            ?>
1547 1547
 						</select>
1548 1548
 						<?php
1549
-						break;
1550
-					case "checkbox":
1551
-						?>
1549
+                        break;
1550
+                    case "checkbox":
1551
+                        ?>
1552 1552
 						<input <?php echo $placeholder; ?>
1553 1553
 							<?php checked( 1, $value, true ) ?>
1554 1554
 							<?php echo $custom_attributes; ?>
@@ -1558,136 +1558,136 @@  discard block
 block discarded – undo
1558 1558
 						<label
1559 1559
 							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>
1560 1560
 						<?php
1561
-						break;
1562
-					case "hidden":
1563
-						?>
1561
+                        break;
1562
+                    case "hidden":
1563
+                        ?>
1564 1564
 						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1565 1565
 						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
1566 1566
 						       value="<?php echo esc_attr( $value ); ?>">
1567 1567
 						<?php
1568
-						break;
1569
-					default:
1570
-						echo "No input type found!"; // @todo we need to add more input types.
1571
-				}
1568
+                        break;
1569
+                    default:
1570
+                        echo "No input type found!"; // @todo we need to add more input types.
1571
+                }
1572 1572
 
1573
-				// after wrapper
1574
-				?>
1573
+                // after wrapper
1574
+                ?>
1575 1575
 			</p>
1576 1576
 			<?php
1577 1577
 
1578
-		}
1579
-
1580
-		/**
1581
-		 * Get the widget input description html.
1582
-		 *
1583
-		 * @param $args
1584
-		 *
1585
-		 * @return string
1586
-		 * @todo, need to make its own tooltip script
1587
-		 */
1588
-		public function widget_field_desc( $args ) {
1589
-
1590
-			$description = '';
1591
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
1592
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
1593
-					$description = $this->desc_tip( $args['desc'] );
1594
-				} else {
1595
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
1596
-				}
1597
-			}
1598
-
1599
-			return $description;
1600
-		}
1601
-
1602
-		/**
1603
-		 * Get the tool tip html.
1604
-		 *
1605
-		 * @param $tip
1606
-		 * @param bool $allow_html
1607
-		 *
1608
-		 * @return string
1609
-		 */
1610
-		function desc_tip( $tip, $allow_html = false ) {
1611
-			if ( $allow_html ) {
1612
-				$tip = $this->sanitize_tooltip( $tip );
1613
-			} else {
1614
-				$tip = esc_attr( $tip );
1615
-			}
1616
-
1617
-			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
1618
-		}
1619
-
1620
-		/**
1621
-		 * Sanitize a string destined to be a tooltip.
1622
-		 *
1623
-		 * @param string $var
1624
-		 *
1625
-		 * @return string
1626
-		 */
1627
-		public function sanitize_tooltip( $var ) {
1628
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1629
-				'br'     => array(),
1630
-				'em'     => array(),
1631
-				'strong' => array(),
1632
-				'small'  => array(),
1633
-				'span'   => array(),
1634
-				'ul'     => array(),
1635
-				'li'     => array(),
1636
-				'ol'     => array(),
1637
-				'p'      => array(),
1638
-			) ) );
1639
-		}
1640
-
1641
-		/**
1642
-		 * Processing widget options on save
1643
-		 *
1644
-		 * @param array $new_instance The new options
1645
-		 * @param array $old_instance The previous options
1646
-		 *
1647
-		 * @return array
1648
-		 * @todo we should add some sanitation here.
1649
-		 */
1650
-		public function update( $new_instance, $old_instance ) {
1651
-
1652
-			//save the widget
1653
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
1654
-
1655
-			// set widget instance
1656
-			$this->instance = $instance;
1657
-
1658
-			if ( empty( $this->arguments ) ) {
1659
-				$this->get_arguments();
1660
-			}
1661
-
1662
-			// check for checkboxes
1663
-			if ( ! empty( $this->arguments ) ) {
1664
-				foreach ( $this->arguments as $argument ) {
1665
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
1666
-						$instance[ $argument['name'] ] = '0';
1667
-					}
1668
-				}
1669
-			}
1670
-
1671
-			return $instance;
1672
-		}
1673
-
1674
-		/**
1675
-		 * Checks if the current call is a ajax call to get the block content.
1676
-		 *
1677
-		 * This can be used in your widget to return different content as the block content.
1678
-		 *
1679
-		 * @since 1.0.3
1680
-		 * @return bool
1681
-		 */
1682
-		public function is_block_content_call() {
1683
-			$result = false;
1684
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
1685
-				$result = true;
1686
-			}
1687
-
1688
-			return $result;
1689
-		}
1690
-
1691
-	}
1578
+        }
1579
+
1580
+        /**
1581
+         * Get the widget input description html.
1582
+         *
1583
+         * @param $args
1584
+         *
1585
+         * @return string
1586
+         * @todo, need to make its own tooltip script
1587
+         */
1588
+        public function widget_field_desc( $args ) {
1589
+
1590
+            $description = '';
1591
+            if ( isset( $args['desc'] ) && $args['desc'] ) {
1592
+                if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
1593
+                    $description = $this->desc_tip( $args['desc'] );
1594
+                } else {
1595
+                    $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
1596
+                }
1597
+            }
1598
+
1599
+            return $description;
1600
+        }
1601
+
1602
+        /**
1603
+         * Get the tool tip html.
1604
+         *
1605
+         * @param $tip
1606
+         * @param bool $allow_html
1607
+         *
1608
+         * @return string
1609
+         */
1610
+        function desc_tip( $tip, $allow_html = false ) {
1611
+            if ( $allow_html ) {
1612
+                $tip = $this->sanitize_tooltip( $tip );
1613
+            } else {
1614
+                $tip = esc_attr( $tip );
1615
+            }
1616
+
1617
+            return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
1618
+        }
1619
+
1620
+        /**
1621
+         * Sanitize a string destined to be a tooltip.
1622
+         *
1623
+         * @param string $var
1624
+         *
1625
+         * @return string
1626
+         */
1627
+        public function sanitize_tooltip( $var ) {
1628
+            return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1629
+                'br'     => array(),
1630
+                'em'     => array(),
1631
+                'strong' => array(),
1632
+                'small'  => array(),
1633
+                'span'   => array(),
1634
+                'ul'     => array(),
1635
+                'li'     => array(),
1636
+                'ol'     => array(),
1637
+                'p'      => array(),
1638
+            ) ) );
1639
+        }
1640
+
1641
+        /**
1642
+         * Processing widget options on save
1643
+         *
1644
+         * @param array $new_instance The new options
1645
+         * @param array $old_instance The previous options
1646
+         *
1647
+         * @return array
1648
+         * @todo we should add some sanitation here.
1649
+         */
1650
+        public function update( $new_instance, $old_instance ) {
1651
+
1652
+            //save the widget
1653
+            $instance = array_merge( (array) $old_instance, (array) $new_instance );
1654
+
1655
+            // set widget instance
1656
+            $this->instance = $instance;
1657
+
1658
+            if ( empty( $this->arguments ) ) {
1659
+                $this->get_arguments();
1660
+            }
1661
+
1662
+            // check for checkboxes
1663
+            if ( ! empty( $this->arguments ) ) {
1664
+                foreach ( $this->arguments as $argument ) {
1665
+                    if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
1666
+                        $instance[ $argument['name'] ] = '0';
1667
+                    }
1668
+                }
1669
+            }
1670
+
1671
+            return $instance;
1672
+        }
1673
+
1674
+        /**
1675
+         * Checks if the current call is a ajax call to get the block content.
1676
+         *
1677
+         * This can be used in your widget to return different content as the block content.
1678
+         *
1679
+         * @since 1.0.3
1680
+         * @return bool
1681
+         */
1682
+        public function is_block_content_call() {
1683
+            $result = false;
1684
+            if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
1685
+                $result = true;
1686
+            }
1687
+
1688
+            return $result;
1689
+        }
1690
+
1691
+    }
1692 1692
 
1693 1693
 }
1694 1694
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +308 added lines, -308 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
 	/**
@@ -33,26 +33,26 @@  discard block
 block discarded – undo
33 33
 		/**
34 34
 		 * Take the array options and use them to build.
35 35
 		 */
36
-		public function __construct( $options ) {
36
+		public function __construct($options) {
37 37
 			global $sd_widgets;
38 38
 
39
-			$sd_widgets[ $options['base_id'] ] = array( 'name'       => $options['name'],
39
+			$sd_widgets[$options['base_id']] = array('name'       => $options['name'],
40 40
 			                                            'class_name' => $options['class_name']
41 41
 			);
42 42
 			$this->base_id                     = $options['base_id'];
43 43
 			// lets filter the options before we do anything
44
-			$options       = apply_filters( "wp_super_duper_options", $options );
45
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
46
-			$options       = $this->add_name_from_key( $options );
44
+			$options       = apply_filters("wp_super_duper_options", $options);
45
+			$options       = apply_filters("wp_super_duper_options_{$this->base_id}", $options);
46
+			$options       = $this->add_name_from_key($options);
47 47
 			$this->options = $options;
48 48
 
49 49
 			$this->base_id   = $options['base_id'];
50
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
50
+			$this->arguments = isset($options['arguments']) ? $options['arguments'] : array();
51 51
 
52 52
 			// init parent
53
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
53
+			parent::__construct($options['base_id'], $options['name'], $options['widget_ops']);
54 54
 
55
-			if ( isset( $options['class_name'] ) ) {
55
+			if (isset($options['class_name'])) {
56 56
 				// register widget
57 57
 				$this->class_name = $options['class_name'];
58 58
 
@@ -60,25 +60,25 @@  discard block
 block discarded – undo
60 60
 				$this->register_shortcode();
61 61
 
62 62
 				// register block
63
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
63
+				add_action('admin_enqueue_scripts', array($this, 'register_block'));
64 64
 			}
65 65
 
66 66
 			// add the CSS and JS we need ONCE
67 67
 			global $sd_widget_scripts;
68 68
 
69
-			if ( ! $sd_widget_scripts ) {
70
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
71
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
72
-				wp_add_inline_style( 'widgets', $this->widget_css() );
69
+			if (!$sd_widget_scripts) {
70
+				wp_add_inline_script('admin-widgets', $this->widget_js());
71
+				wp_add_inline_script('customize-controls', $this->widget_js());
72
+				wp_add_inline_style('widgets', $this->widget_css());
73 73
 
74 74
 				$sd_widget_scripts = true;
75 75
 
76 76
 				// add shortcode insert button once
77
-				add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) );
78
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
77
+				add_action('media_buttons', array($this, 'shortcode_insert_button'));
78
+				add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings'));
79 79
 			}
80 80
 
81
-			do_action( 'wp_super_duper_widget_init', $options, $this );
81
+			do_action('wp_super_duper_widget_init', $options, $this);
82 82
 		}
83 83
 
84 84
 		/**
@@ -89,16 +89,16 @@  discard block
 block discarded – undo
89 89
 		public static function get_widget_settings() {
90 90
 			global $sd_widgets;
91 91
 
92
-			$shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : '';
93
-			if ( ! $shortcode ) {
92
+			$shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : '';
93
+			if (!$shortcode) {
94 94
 				wp_die();
95 95
 			}
96
-			$widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : '';
97
-			if ( ! $widget_args ) {
96
+			$widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : '';
97
+			if (!$widget_args) {
98 98
 				wp_die();
99 99
 			}
100
-			$class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
101
-			if ( ! $class_name ) {
100
+			$class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
101
+			if (!$class_name) {
102 102
 				wp_die();
103 103
 			}
104 104
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 			$widget = new $class_name;
107 107
 
108 108
 			ob_start();
109
-			$widget->form( array() );
109
+			$widget->form(array());
110 110
 			$form = ob_get_clean();
111 111
 			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
112 112
 			echo "<style>" . $widget->widget_css() . "</style>";
@@ -124,9 +124,9 @@  discard block
 block discarded – undo
124 124
 		 * @param string $editor_id Optional. Shortcode editor id. Default null.
125 125
 		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
126 126
 		 */
127
-		public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) {
127
+		public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') {
128 128
 			global $sd_widgets, $shortcode_insert_button_once;
129
-			if ( $shortcode_insert_button_once ) {
129
+			if ($shortcode_insert_button_once) {
130 130
 				return;
131 131
 			}
132 132
 			add_thickbox();
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
 
136 136
 				<div class="sd-shortcode-left-wrap">
137 137
 					<?php
138
-					asort( $sd_widgets );
139
-					if ( ! empty( $sd_widgets ) ) {
138
+					asort($sd_widgets);
139
+					if (!empty($sd_widgets)) {
140 140
 						echo '<select onchange="sd_get_shortcode_options(this);">';
141
-						echo "<option>" . __( 'Select shortcode' ) . "</option>";
142
-						foreach ( $sd_widgets as $shortcode => $class ) {
143
-							echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>";
141
+						echo "<option>" . __('Select shortcode') . "</option>";
142
+						foreach ($sd_widgets as $shortcode => $class) {
143
+							echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>";
144 144
 						}
145 145
 						echo "</select>";
146 146
 
@@ -154,9 +154,9 @@  discard block
 block discarded – undo
154 154
 					<textarea id='sd-shortcode-output' disabled></textarea>
155 155
 					<div id='sd-shortcode-output-actions'>
156 156
 						<button class="button"
157
-						        onclick="sd_insert_shortcode()"><?php _e( 'Insert shortcode' ); ?></button>
157
+						        onclick="sd_insert_shortcode()"><?php _e('Insert shortcode'); ?></button>
158 158
 						<button class="button"
159
-						        onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button>
159
+						        onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button>
160 160
 					</div>
161 161
 				</div>
162 162
 
@@ -164,12 +164,12 @@  discard block
 block discarded – undo
164 164
 
165 165
 			<?php
166 166
 			// if Font Awesome is available then show a icon if not show a WP icon.
167
-			$button_string = wp_style_is( 'font-awesome', 'enqueued' ) && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>';
167
+			$button_string = wp_style_is('font-awesome', 'enqueued') && 1 == 2 ? '<i class="fas fa-cubes" aria-hidden="true"></i>' : '<span style="padding-top: 3px;" class="dashicons dashicons-screenoptions"></span>';
168 168
 			?>
169 169
 
170 170
 			<a href="#TB_inline?width=100%&height=550&inlineId=super-duper-content"
171 171
 			   class="thickbox button super-duper-content-open"
172
-			   title="<?php _e( 'Add Shortcode' ); ?>"><?php echo $button_string; ?></a>
172
+			   title="<?php _e('Add Shortcode'); ?>"><?php echo $button_string; ?></a>
173 173
 
174 174
 			<style>
175 175
 				.sd-shortcode-left-wrap {
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
 			<script>
195 195
 
196 196
 				<?php
197
-				if(! empty( $insert_shortcode_function )){
197
+				if (!empty($insert_shortcode_function)) {
198 198
 					echo $insert_shortcode_function;
199
-				}else{
199
+				} else {
200 200
 
201 201
 				/**
202 202
 				 * Function for super duper insert shortcode.
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 							'shortcode': $short_code,
247 247
 							'attributes': 123,
248 248
 							'post_id': 321,
249
-							'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
249
+							'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
250 250
 						};
251 251
 
252 252
 						jQuery.post(ajaxurl, data, function (response) {
@@ -364,10 +364,10 @@  discard block
 block discarded – undo
364 364
 			/*
365 365
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
366 366
 			 */
367
-			return str_replace( array(
367
+			return str_replace(array(
368 368
 				'<style>',
369 369
 				'</style>'
370
-			), '', $output );
370
+			), '', $output);
371 371
 		}
372 372
 
373 373
 		public function widget_js() {
@@ -524,7 +524,7 @@  discard block
 block discarded – undo
524 524
 					});
525 525
 
526 526
 				}
527
-				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
527
+				<?php do_action('wp_super_duper_widget_js', $this); ?>
528 528
 			</script>
529 529
 			<?php
530 530
 			$output = ob_get_clean();
@@ -532,10 +532,10 @@  discard block
 block discarded – undo
532 532
 			/*
533 533
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
534 534
 			 */
535
-			return str_replace( array(
535
+			return str_replace(array(
536 536
 				'<script>',
537 537
 				'</script>'
538
-			), '', $output );
538
+			), '', $output);
539 539
 		}
540 540
 
541 541
 
@@ -546,14 +546,14 @@  discard block
 block discarded – undo
546 546
 		 *
547 547
 		 * @return mixed
548 548
 		 */
549
-		private function add_name_from_key( $options, $arguments = false ) {
550
-			if ( ! empty( $options['arguments'] ) ) {
551
-				foreach ( $options['arguments'] as $key => $val ) {
552
-					$options['arguments'][ $key ]['name'] = $key;
549
+		private function add_name_from_key($options, $arguments = false) {
550
+			if (!empty($options['arguments'])) {
551
+				foreach ($options['arguments'] as $key => $val) {
552
+					$options['arguments'][$key]['name'] = $key;
553 553
 				}
554
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
555
-				foreach ( $options as $key => $val ) {
556
-					$options[ $key ]['name'] = $key;
554
+			} elseif ($arguments && is_array($options) && !empty($options)) {
555
+				foreach ($options as $key => $val) {
556
+					$options[$key]['name'] = $key;
557 557
 				}
558 558
 			}
559 559
 
@@ -566,8 +566,8 @@  discard block
 block discarded – undo
566 566
 		 * @since 1.0.0
567 567
 		 */
568 568
 		public function register_shortcode() {
569
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
570
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
569
+			add_shortcode($this->base_id, array($this, 'shortcode_output'));
570
+			add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode'));
571 571
 		}
572 572
 
573 573
 		/**
@@ -577,33 +577,33 @@  discard block
 block discarded – undo
577 577
 		 */
578 578
 		public static function render_shortcode() {
579 579
 
580
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
581
-			if ( ! current_user_can( 'manage_options' ) ) {
580
+			check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true);
581
+			if (!current_user_can('manage_options')) {
582 582
 				wp_die();
583 583
 			}
584 584
 
585 585
 			// we might need the $post value here so lets set it.
586
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
587
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
588
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
586
+			if (isset($_POST['post_id']) && $_POST['post_id']) {
587
+				$post_obj = get_post(absint($_POST['post_id']));
588
+				if (!empty($post_obj) && empty($post)) {
589 589
 					global $post;
590 590
 					$post = $post_obj;
591 591
 				}
592 592
 			}
593 593
 
594
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
595
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
596
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
594
+			if (isset($_POST['shortcode']) && $_POST['shortcode']) {
595
+				$shortcode_name   = sanitize_title_with_dashes($_POST['shortcode']);
596
+				$attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array();
597 597
 				$attributes       = '';
598
-				if ( ! empty( $attributes_array ) ) {
599
-					foreach ( $attributes_array as $key => $value ) {
600
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
598
+				if (!empty($attributes_array)) {
599
+					foreach ($attributes_array as $key => $value) {
600
+						$attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' ";
601 601
 					}
602 602
 				}
603 603
 
604 604
 				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
605 605
 
606
-				echo do_shortcode( $shortcode );
606
+				echo do_shortcode($shortcode);
607 607
 
608 608
 			}
609 609
 			wp_die();
@@ -617,37 +617,37 @@  discard block
 block discarded – undo
617 617
 		 *
618 618
 		 * @return string
619 619
 		 */
620
-		public function shortcode_output( $args = array(), $content = '' ) {
621
-			$args = self::argument_values( $args );
620
+		public function shortcode_output($args = array(), $content = '') {
621
+			$args = self::argument_values($args);
622 622
 
623 623
 			// add extra argument so we know its a output to gutenberg
624 624
 			//$args
625
-			$args = $this->string_to_bool( $args );
625
+			$args = $this->string_to_bool($args);
626 626
 
627 627
 
628
-			$calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : '';
628
+			$calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : '';
629 629
 
630
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
631
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
630
+			$calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this);
631
+			$calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this);
632 632
 
633
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
634
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
633
+			$attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this);
634
+			$attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this);
635 635
 
636 636
 			$shortcode_args = array();
637 637
 			$output         = '';
638
-			$no_wrap        = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false;
639
-			$main_content   = $this->output( $args, $shortcode_args, $content );
640
-			if ( $main_content && ! $no_wrap ) {
638
+			$no_wrap        = isset($this->options['no_wrap']) && $this->options['no_wrap'] ? true : false;
639
+			$main_content   = $this->output($args, $shortcode_args, $content);
640
+			if ($main_content && !$no_wrap) {
641 641
 				// wrap the shortcode in a dive with the same class as the widget
642 642
 				$output .= '<div class="' . $calss . '" ' . $attrs . '>';
643
-				if ( ! empty( $args['title'] ) ) {
643
+				if (!empty($args['title'])) {
644 644
 					// if its a shortcode and there is a title try to grab the title wrappers
645
-					$shortcode_args = array( 'before_title' => '', 'after_title' => '' );
646
-					if ( empty( $instance ) ) {
645
+					$shortcode_args = array('before_title' => '', 'after_title' => '');
646
+					if (empty($instance)) {
647 647
 						global $wp_registered_sidebars;
648
-						if ( ! empty( $wp_registered_sidebars ) ) {
649
-							foreach ( $wp_registered_sidebars as $sidebar ) {
650
-								if ( ! empty( $sidebar['before_title'] ) ) {
648
+						if (!empty($wp_registered_sidebars)) {
649
+							foreach ($wp_registered_sidebars as $sidebar) {
650
+								if (!empty($sidebar['before_title'])) {
651 651
 									$shortcode_args['before_title'] = $sidebar['before_title'];
652 652
 									$shortcode_args['after_title']  = $sidebar['after_title'];
653 653
 									break;
@@ -655,11 +655,11 @@  discard block
 block discarded – undo
655 655
 							}
656 656
 						}
657 657
 					}
658
-					$output .= $this->output_title( $shortcode_args, $args );
658
+					$output .= $this->output_title($shortcode_args, $args);
659 659
 				}
660 660
 				$output .= $main_content;
661 661
 				$output .= '</div>';
662
-			} elseif ( $main_content && $no_wrap ) {
662
+			} elseif ($main_content && $no_wrap) {
663 663
 				$output .= $main_content;
664 664
 			}
665 665
 
@@ -673,13 +673,13 @@  discard block
 block discarded – undo
673 673
 		 *
674 674
 		 * @return mixed
675 675
 		 */
676
-		public function string_to_bool( $options ) {
676
+		public function string_to_bool($options) {
677 677
 			// convert bool strings to booleans
678
-			foreach ( $options as $key => $val ) {
679
-				if ( $val == 'false' ) {
680
-					$options[ $key ] = false;
681
-				} elseif ( $val == 'true' ) {
682
-					$options[ $key ] = true;
678
+			foreach ($options as $key => $val) {
679
+				if ($val == 'false') {
680
+					$options[$key] = false;
681
+				} elseif ($val == 'true') {
682
+					$options[$key] = true;
683 683
 				}
684 684
 			}
685 685
 
@@ -693,24 +693,24 @@  discard block
 block discarded – undo
693 693
 		 *
694 694
 		 * @return array
695 695
 		 */
696
-		public function argument_values( $instance ) {
696
+		public function argument_values($instance) {
697 697
 			$argument_values = array();
698 698
 
699 699
 			// set widget instance
700 700
 			$this->instance = $instance;
701 701
 
702
-			if ( empty( $this->arguments ) ) {
702
+			if (empty($this->arguments)) {
703 703
 				$this->arguments = $this->get_arguments();
704 704
 			}
705 705
 
706
-			if ( ! empty( $this->arguments ) ) {
707
-				foreach ( $this->arguments as $key => $args ) {
706
+			if (!empty($this->arguments)) {
707
+				foreach ($this->arguments as $key => $args) {
708 708
 					// set the input name from the key
709 709
 					$args['name'] = $key;
710 710
 					//
711
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
712
-					if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
713
-						$argument_values[ $key ] = $args['default'];
711
+					$argument_values[$key] = isset($instance[$key]) ? $instance[$key] : '';
712
+					if ($argument_values[$key] == '' && isset($args['default'])) {
713
+						$argument_values[$key] = $args['default'];
714 714
 					}
715 715
 				}
716 716
 			}
@@ -737,12 +737,12 @@  discard block
 block discarded – undo
737 737
 		 * @return array Get arguments.
738 738
 		 */
739 739
 		public function get_arguments() {
740
-			if ( empty( $this->arguments ) ) {
740
+			if (empty($this->arguments)) {
741 741
 				$this->arguments = $this->set_arguments();
742 742
 			}
743 743
 
744
-			$this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance );
745
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
744
+			$this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance);
745
+			$this->arguments = $this->add_name_from_key($this->arguments, true);
746 746
 
747 747
 			return $this->arguments;
748 748
 		}
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 		 * @param array $widget_args
755 755
 		 * @param string $content
756 756
 		 */
757
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
757
+		public function output($args = array(), $widget_args = array(), $content = '') {
758 758
 
759 759
 		}
760 760
 
@@ -762,7 +762,7 @@  discard block
 block discarded – undo
762 762
 		 * Add the dynamic block code inline when the wp-block in enqueued.
763 763
 		 */
764 764
 		public function register_block() {
765
-			wp_add_inline_script( 'wp-blocks', $this->block() );
765
+			wp_add_inline_script('wp-blocks', $this->block());
766 766
 		}
767 767
 
768 768
 		/**
@@ -775,13 +775,13 @@  discard block
 block discarded – undo
775 775
 			$show      = false;
776 776
 			$arguments = $this->arguments;
777 777
 
778
-			if ( empty( $arguments ) ) {
778
+			if (empty($arguments)) {
779 779
 				$arguments = $this->get_arguments();
780 780
 			}
781 781
 
782
-			if ( ! empty( $arguments ) ) {
783
-				foreach ( $arguments as $argument ) {
784
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
782
+			if (!empty($arguments)) {
783
+				foreach ($arguments as $argument) {
784
+					if (isset($argument['advanced']) && $argument['advanced']) {
785 785
 						$show = true;
786 786
 					}
787 787
 				}
@@ -832,12 +832,12 @@  discard block
 block discarded – undo
832 832
 					 * @return {?WPBlock}          The block, if it has been successfully
833 833
 					 *                             registered; otherwise `undefined`.
834 834
 					 */
835
-					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.
836
-						title: '<?php echo $this->options['name'];?>', // Block title.
837
-						description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title.
838
-						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/.
839
-						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.
840
-						<?php if ( isset( $this->options['block-keywords'] ) ) {
835
+					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.
836
+						title: '<?php echo $this->options['name']; ?>', // Block title.
837
+						description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title.
838
+						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/.
839
+						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.
840
+						<?php if (isset($this->options['block-keywords'])) {
841 841
 						echo "keywords : " . $this->options['block-keywords'] . ",";
842 842
 					}?>
843 843
 
@@ -847,10 +847,10 @@  discard block
 block discarded – undo
847 847
 
848 848
 						$show_alignment = false;
849 849
 
850
-						if ( ! empty( $this->arguments ) ) {
850
+						if (!empty($this->arguments)) {
851 851
 							echo "attributes : {";
852 852
 
853
-							if ( $show_advanced ) {
853
+							if ($show_advanced) {
854 854
 								echo "show_advanced: {";
855 855
 								echo "	type: 'boolean',";
856 856
 								echo "  default: false,";
@@ -858,42 +858,42 @@  discard block
 block discarded – undo
858 858
 							}
859 859
 
860 860
 							// block wrap element
861
-							if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this?
861
+							if (isset($this->options['block-wrap'])) { //@todo we should validate this?
862 862
 								echo "block_wrap: {";
863 863
 								echo "	type: 'string',";
864
-								echo "  default: '" . esc_attr( $this->options['block-wrap'] ) . "',";
864
+								echo "  default: '" . esc_attr($this->options['block-wrap']) . "',";
865 865
 								echo "},";
866 866
 							}
867 867
 
868 868
 
869
-							foreach ( $this->arguments as $key => $args ) {
869
+							foreach ($this->arguments as $key => $args) {
870 870
 
871 871
 								// set if we should show alignment
872
-								if ( $key == 'alignment' ) {
872
+								if ($key == 'alignment') {
873 873
 									$show_alignment = true;
874 874
 								}
875 875
 
876 876
 								$extra = '';
877 877
 
878
-								if ( $args['type'] == 'checkbox' ) {
878
+								if ($args['type'] == 'checkbox') {
879 879
 									$type    = 'boolean';
880
-									$default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false';
881
-								} elseif ( $args['type'] == 'number' ) {
880
+									$default = isset($args['default']) && $args['default'] ? 'true' : 'false';
881
+								} elseif ($args['type'] == 'number') {
882 882
 									$type    = 'number';
883
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
884
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
883
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
884
+								} elseif ($args['type'] == 'select' && !empty($args['multiple'])) {
885 885
 									$type = 'array';
886
-									if ( is_array( $args['default'] ) ) {
887
-										$default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]";
886
+									if (is_array($args['default'])) {
887
+										$default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]";
888 888
 									} else {
889
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
889
+										$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
890 890
 									}
891
-								} elseif ( $args['type'] == 'multiselect' ) {
891
+								} elseif ($args['type'] == 'multiselect') {
892 892
 									$type    = 'array';
893
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
893
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
894 894
 								} else {
895 895
 									$type    = 'string';
896
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
896
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
897 897
 								}
898 898
 								echo $key . " : {";
899 899
 								echo "type : '$type',";
@@ -923,12 +923,12 @@  discard block
 block discarded – undo
923 923
 									is_fetching = true;
924 924
 									var data = {
925 925
 										'action': 'super_duper_output_shortcode',
926
-										'shortcode': '<?php echo $this->options['base_id'];?>',
926
+										'shortcode': '<?php echo $this->options['base_id']; ?>',
927 927
 										'attributes': props.attributes,
928
-										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
928
+										'post_id': <?php global $post; if (isset($post->ID)) {
929 929
 										echo $post->ID;
930 930
 									}?>,
931
-										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
931
+										'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
932 932
 									};
933 933
 
934 934
 									jQuery.post(ajaxurl, data, function (response) {
@@ -937,7 +937,7 @@  discard block
 block discarded – undo
937 937
 
938 938
 										// if the content is empty then we place some placeholder text
939 939
 										if (env == '') {
940
-											env = "<div style='background:#0185ba33;padding: 10px;'>" + "<?php _e( 'Placeholder for: ' );?>" + props.name + "</div>";
940
+											env = "<div style='background:#0185ba33;padding: 10px;'>" + "<?php _e('Placeholder for: '); ?>" + props.name + "</div>";
941 941
 										}
942 942
 
943 943
 										props.setAttributes({content: env});
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
 
957 957
 								el(wp.editor.BlockControls, {key: 'controls'},
958 958
 
959
-									<?php if($show_alignment){?>
959
+									<?php if ($show_alignment) {?>
960 960
 									el(
961 961
 										wp.editor.AlignmentToolbar,
962 962
 										{
@@ -974,9 +974,9 @@  discard block
 block discarded – undo
974 974
 
975 975
 									<?php
976 976
 
977
-									if(! empty( $this->arguments )){
977
+									if (!empty($this->arguments)) {
978 978
 
979
-									if ( $show_advanced ) {
979
+									if ($show_advanced) {
980 980
 									?>
981 981
 									el(
982 982
 										wp.components.ToggleControl,
@@ -992,68 +992,68 @@  discard block
 block discarded – undo
992 992
 
993 993
 									}
994 994
 
995
-									foreach($this->arguments as $key => $args){
996
-									$custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : '';
995
+									foreach ($this->arguments as $key => $args) {
996
+									$custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : '';
997 997
 									$options = '';
998 998
 									$extra = '';
999 999
 									$require = '';
1000 1000
 									$onchange = "props.setAttributes({ $key: $key } )";
1001 1001
 									$value = "props.attributes.$key";
1002
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1003
-									if ( in_array( $args['type'], $text_type ) ) {
1002
+									$text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color');
1003
+									if (in_array($args['type'], $text_type)) {
1004 1004
 										$type = 'TextControl';
1005
-									} elseif ( $args['type'] == 'checkbox' ) {
1005
+									} elseif ($args['type'] == 'checkbox') {
1006 1006
 										$type = 'CheckboxControl';
1007 1007
 										$extra .= "checked: props.attributes.$key,";
1008 1008
 										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1009
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1009
+									} elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') {
1010 1010
 										$type = 'SelectControl';
1011
-										if ( ! empty( $args['options'] ) ) {
1011
+										if (!empty($args['options'])) {
1012 1012
 											$options .= "options  : [";
1013
-											foreach ( $args['options'] as $option_val => $option_label ) {
1014
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1013
+											foreach ($args['options'] as $option_val => $option_label) {
1014
+												$options .= "{ value : '" . esc_attr($option_val) . "',     label : '" . esc_attr($option_label) . "'     },";
1015 1015
 											}
1016 1016
 											$options .= "],";
1017 1017
 										}
1018
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1018
+										if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1019 1019
 											$extra .= ' multiple: true, ';
1020 1020
 											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1021 1021
 											//$value = "['edit', 'delete']";
1022 1022
 										}
1023
-									} elseif ( $args['type'] == 'alignment' ) {
1023
+									} elseif ($args['type'] == 'alignment') {
1024 1024
 										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1025 1025
 									} else {
1026
-										continue;// if we have not implemented the control then don't break the JS.
1026
+										continue; // if we have not implemented the control then don't break the JS.
1027 1027
 									}
1028 1028
 
1029 1029
 									// add show only if advanced
1030
-									if ( ! empty( $args['advanced'] ) ) {
1030
+									if (!empty($args['advanced'])) {
1031 1031
 										echo "props.attributes.show_advanced && ";
1032 1032
 									}
1033 1033
 									// add setting require if defined
1034
-									if ( ! empty( $args['element_require'] ) ) {
1035
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1034
+									if (!empty($args['element_require'])) {
1035
+										echo $this->block_props_replace($args['element_require'], true) . " && ";
1036 1036
 									}
1037 1037
 									?>
1038 1038
 									el(
1039
-										wp.components.<?php echo esc_attr( $type );?>,
1039
+										wp.components.<?php echo esc_attr($type); ?>,
1040 1040
 										{
1041
-											label: '<?php echo esc_attr( $args['title'] );?>',
1042
-											help: '<?php if ( isset( $args['desc'] ) ) {
1043
-												echo esc_attr( $args['desc'] );
1041
+											label: '<?php echo esc_attr($args['title']); ?>',
1042
+											help: '<?php if (isset($args['desc'])) {
1043
+												echo esc_attr($args['desc']);
1044 1044
 											}?>',
1045
-											value: <?php echo $value;?>,
1046
-											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1047
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1045
+											value: <?php echo $value; ?>,
1046
+											<?php if ($type == 'TextControl' && $args['type'] != 'text') {
1047
+											echo "type: '" . esc_attr($args['type']) . "',";
1048 1048
 										}?>
1049
-											<?php if ( ! empty( $args['placeholder'] ) ) {
1050
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1049
+											<?php if (!empty($args['placeholder'])) {
1050
+											echo "placeholder: '" . esc_attr($args['placeholder']) . "',";
1051 1051
 										}?>
1052
-											<?php echo $options;?>
1053
-											<?php echo $extra;?>
1054
-											<?php echo $custom_attributes;?>
1055
-											onChange: function ( <?php echo $key;?> ) {
1056
-												<?php echo $onchange;?>
1052
+											<?php echo $options; ?>
1053
+											<?php echo $extra; ?>
1054
+											<?php echo $custom_attributes; ?>
1055
+											onChange: function ( <?php echo $key; ?> ) {
1056
+												<?php echo $onchange; ?>
1057 1057
 											}
1058 1058
 										}
1059 1059
 									),
@@ -1066,9 +1066,9 @@  discard block
 block discarded – undo
1066 1066
 
1067 1067
 								<?php
1068 1068
 								// If the user sets block-output array then build it
1069
-								if ( ! empty( $this->options['block-output'] ) ) {
1070
-								$this->block_element( $this->options['block-output'] );
1071
-							}else{
1069
+								if (!empty($this->options['block-output'])) {
1070
+								$this->block_element($this->options['block-output']);
1071
+							} else {
1072 1072
 								// if no block-output is set then we try and get the shortcode html output via ajax.
1073 1073
 								?>
1074 1074
 								el('div', {
@@ -1092,14 +1092,14 @@  discard block
 block discarded – undo
1092 1092
 							var align = '';
1093 1093
 
1094 1094
 							// build the shortcode.
1095
-							var content = "[<?php echo $this->options['base_id'];?>";
1095
+							var content = "[<?php echo $this->options['base_id']; ?>";
1096 1096
 							<?php
1097 1097
 
1098
-							if(! empty( $this->arguments )){
1099
-							foreach($this->arguments as $key => $args){
1098
+							if (!empty($this->arguments)) {
1099
+							foreach ($this->arguments as $key => $args) {
1100 1100
 							?>
1101
-							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1102
-								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1101
+							if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) {
1102
+								content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' ";
1103 1103
 							}
1104 1104
 							<?php
1105 1105
 							}
@@ -1140,10 +1140,10 @@  discard block
 block discarded – undo
1140 1140
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1141 1141
 			 */
1142 1142
 
1143
-			return str_replace( array(
1143
+			return str_replace(array(
1144 1144
 				'<script>',
1145 1145
 				'</script>'
1146
-			), '', $output );
1146
+			), '', $output);
1147 1147
 		}
1148 1148
 
1149 1149
 		/**
@@ -1155,16 +1155,16 @@  discard block
 block discarded – undo
1155 1155
 		 *
1156 1156
 		 * @return string
1157 1157
 		 */
1158
-		public function array_to_attributes( $custom_attributes, $html = false ) {
1158
+		public function array_to_attributes($custom_attributes, $html = false) {
1159 1159
 			$attributes = '';
1160
-			if ( ! empty( $custom_attributes ) ) {
1160
+			if (!empty($custom_attributes)) {
1161 1161
 
1162
-				if ( $html ) {
1163
-					foreach ( $custom_attributes as $key => $val ) {
1162
+				if ($html) {
1163
+					foreach ($custom_attributes as $key => $val) {
1164 1164
 						$attributes .= " $key='$val' ";
1165 1165
 					}
1166 1166
 				} else {
1167
-					foreach ( $custom_attributes as $key => $val ) {
1167
+					foreach ($custom_attributes as $key => $val) {
1168 1168
 						$attributes .= "'$key': '$val',";
1169 1169
 					}
1170 1170
 				}
@@ -1180,86 +1180,86 @@  discard block
 block discarded – undo
1180 1180
 		 *
1181 1181
 		 * @param $args
1182 1182
 		 */
1183
-		public function block_element( $args ) {
1183
+		public function block_element($args) {
1184 1184
 
1185 1185
 
1186
-			if ( ! empty( $args ) ) {
1187
-				foreach ( $args as $element => $new_args ) {
1186
+			if (!empty($args)) {
1187
+				foreach ($args as $element => $new_args) {
1188 1188
 
1189
-					if ( is_array( $new_args ) ) { // its an element
1189
+					if (is_array($new_args)) { // its an element
1190 1190
 
1191 1191
 
1192
-						if ( isset( $new_args['element'] ) ) {
1192
+						if (isset($new_args['element'])) {
1193 1193
 
1194
-							if ( isset( $new_args['element_require'] ) ) {
1195
-								echo str_replace( array(
1194
+							if (isset($new_args['element_require'])) {
1195
+								echo str_replace(array(
1196 1196
 										"'+",
1197 1197
 										"+'"
1198
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1199
-								unset( $new_args['element_require'] );
1198
+									), '', $this->block_props_replace($new_args['element_require'])) . " &&  ";
1199
+								unset($new_args['element_require']);
1200 1200
 							}
1201 1201
 
1202 1202
 							echo "\n el( '" . $new_args['element'] . "', {";
1203 1203
 
1204 1204
 							// get the attributes
1205
-							foreach ( $new_args as $new_key => $new_value ) {
1205
+							foreach ($new_args as $new_key => $new_value) {
1206 1206
 
1207 1207
 
1208
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1208
+								if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) {
1209 1209
 									// do nothing
1210 1210
 								} else {
1211
-									echo $this->block_element( array( $new_key => $new_value ) );
1211
+									echo $this->block_element(array($new_key => $new_value));
1212 1212
 								}
1213 1213
 							}
1214 1214
 
1215
-							echo "},";// end attributes
1215
+							echo "},"; // end attributes
1216 1216
 
1217 1217
 							// get the content
1218 1218
 							$first_item = 0;
1219
-							foreach ( $new_args as $new_key => $new_value ) {
1220
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1219
+							foreach ($new_args as $new_key => $new_value) {
1220
+								if ($new_key === 'content' || is_array($new_value)) {
1221 1221
 
1222
-									if ( $new_key === 'content' ) {
1223
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1222
+									if ($new_key === 'content') {
1223
+										echo "'" . $this->block_props_replace($new_value) . "'";
1224 1224
 									}
1225 1225
 
1226
-									if ( is_array( $new_value ) ) {
1226
+									if (is_array($new_value)) {
1227 1227
 
1228
-										if ( isset( $new_value['element_require'] ) ) {
1229
-											echo str_replace( array(
1228
+										if (isset($new_value['element_require'])) {
1229
+											echo str_replace(array(
1230 1230
 													"'+",
1231 1231
 													"+'"
1232
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1233
-											unset( $new_value['element_require'] );
1232
+												), '', $this->block_props_replace($new_value['element_require'])) . " &&  ";
1233
+											unset($new_value['element_require']);
1234 1234
 										}
1235 1235
 
1236
-										if ( isset( $new_value['element_repeat'] ) ) {
1236
+										if (isset($new_value['element_repeat'])) {
1237 1237
 											$x = 1;
1238
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1239
-												$this->block_element( array( '' => $new_value ) );
1240
-												$x ++;
1238
+											while ($x <= absint($new_value['element_repeat'])) {
1239
+												$this->block_element(array('' => $new_value));
1240
+												$x++;
1241 1241
 											}
1242 1242
 										} else {
1243
-											$this->block_element( array( '' => $new_value ) );
1243
+											$this->block_element(array('' => $new_value));
1244 1244
 										}
1245 1245
 									}
1246
-									$first_item ++;
1246
+									$first_item++;
1247 1247
 								}
1248 1248
 							}
1249 1249
 
1250
-							echo ")";// end content
1250
+							echo ")"; // end content
1251 1251
 
1252 1252
 							echo ", \n";
1253 1253
 
1254 1254
 						}
1255 1255
 					} else {
1256 1256
 
1257
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1258
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1259
-						} elseif ( $element == 'style' ) {
1260
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1257
+						if (substr($element, 0, 3) === "if_") {
1258
+							echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ",";
1259
+						} elseif ($element == 'style') {
1260
+							echo $element . ": " . $this->block_props_replace($new_args) . ",";
1261 1261
 						} else {
1262
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1262
+							echo $element . ": '" . $this->block_props_replace($new_args) . "',";
1263 1263
 						}
1264 1264
 
1265 1265
 					}
@@ -1274,12 +1274,12 @@  discard block
 block discarded – undo
1274 1274
 		 *
1275 1275
 		 * @return mixed
1276 1276
 		 */
1277
-		public function block_props_replace( $string, $no_wrap = false ) {
1277
+		public function block_props_replace($string, $no_wrap = false) {
1278 1278
 
1279
-			if ( $no_wrap ) {
1280
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1279
+			if ($no_wrap) {
1280
+				$string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string);
1281 1281
 			} else {
1282
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1282
+				$string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string);
1283 1283
 			}
1284 1284
 
1285 1285
 			return $string;
@@ -1291,33 +1291,33 @@  discard block
 block discarded – undo
1291 1291
 		 * @param array $args
1292 1292
 		 * @param array $instance
1293 1293
 		 */
1294
-		public function widget( $args, $instance ) {
1294
+		public function widget($args, $instance) {
1295 1295
 
1296 1296
 			// get the filtered values
1297
-			$argument_values = $this->argument_values( $instance );
1298
-			$argument_values = $this->string_to_bool( $argument_values );
1299
-			$output          = $this->output( $argument_values, $args );
1297
+			$argument_values = $this->argument_values($instance);
1298
+			$argument_values = $this->string_to_bool($argument_values);
1299
+			$output          = $this->output($argument_values, $args);
1300 1300
 
1301
-			if ( $output ) {
1301
+			if ($output) {
1302 1302
 				// Before widget
1303 1303
 				$before_widget = $args['before_widget'];
1304
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1305
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1304
+				$before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this);
1305
+				$before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this);
1306 1306
 
1307 1307
 				// After widget
1308 1308
 				$after_widget = $args['after_widget'];
1309
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1310
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1309
+				$after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this);
1310
+				$after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this);
1311 1311
 
1312 1312
 				echo $before_widget;
1313 1313
 				// elementor strips the widget wrapping div so we check for and add it back if needed
1314
-				if ( $this->is_elementor_widget_output() ) {
1315
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : '';
1314
+				if ($this->is_elementor_widget_output()) {
1315
+					echo !empty($this->options['widget_ops']['classname']) ? "<span class='" . esc_attr($this->options['widget_ops']['classname']) . "'>" : '';
1316 1316
 				}
1317
-				echo $this->output_title( $args, $instance );
1317
+				echo $this->output_title($args, $instance);
1318 1318
 				echo $output;
1319
-				if ( $this->is_elementor_widget_output() ) {
1320
-					echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : '';
1319
+				if ($this->is_elementor_widget_output()) {
1320
+					echo !empty($this->options['widget_ops']['classname']) ? "</span>" : '';
1321 1321
 				}
1322 1322
 				echo $after_widget;
1323 1323
 			}
@@ -1331,7 +1331,7 @@  discard block
 block discarded – undo
1331 1331
 		 */
1332 1332
 		public function is_elementor_widget_output() {
1333 1333
 			$result = false;
1334
-			if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) {
1334
+			if (defined('ELEMENTOR_VERSION') && isset($this->number) && $this->number == 'REPLACE_TO_ID') {
1335 1335
 				$result = true;
1336 1336
 			}
1337 1337
 
@@ -1346,7 +1346,7 @@  discard block
 block discarded – undo
1346 1346
 		 */
1347 1347
 		public function is_elementor_preview() {
1348 1348
 			$result = false;
1349
-			if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) {
1349
+			if (isset($_REQUEST['elementor-preview']) || (is_admin() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'elementor')) {
1350 1350
 				$result = true;
1351 1351
 			}
1352 1352
 
@@ -1361,11 +1361,11 @@  discard block
 block discarded – undo
1361 1361
 		 *
1362 1362
 		 * @return string
1363 1363
 		 */
1364
-		public function output_title( $args, $instance = array() ) {
1364
+		public function output_title($args, $instance = array()) {
1365 1365
 			$output = '';
1366
-			if ( ! empty( $instance['title'] ) ) {
1366
+			if (!empty($instance['title'])) {
1367 1367
 				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
1368
-				$title  = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
1368
+				$title  = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
1369 1369
 				$output = $args['before_title'] . $title . $args['after_title'];
1370 1370
 			}
1371 1371
 
@@ -1377,7 +1377,7 @@  discard block
 block discarded – undo
1377 1377
 		 *
1378 1378
 		 * @param array $instance The widget options.
1379 1379
 		 */
1380
-		public function form( $instance ) {
1380
+		public function form($instance) {
1381 1381
 
1382 1382
 			// set widget instance
1383 1383
 			$this->instance = $instance;
@@ -1385,12 +1385,12 @@  discard block
 block discarded – undo
1385 1385
 			// set it as a SD widget
1386 1386
 			echo $this->widget_advanced_toggle();
1387 1387
 
1388
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
1388
+			echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>";
1389 1389
 			$arguments = $this->get_arguments();
1390 1390
 
1391
-			if ( is_array( $arguments ) ) {
1392
-				foreach ( $arguments as $key => $args ) {
1393
-					$this->widget_inputs( $args, $instance );
1391
+			if (is_array($arguments)) {
1392
+				foreach ($arguments as $key => $args) {
1393
+					$this->widget_inputs($args, $instance);
1394 1394
 				}
1395 1395
 			}
1396 1396
 		}
@@ -1403,7 +1403,7 @@  discard block
 block discarded – undo
1403 1403
 		public function widget_advanced_toggle() {
1404 1404
 
1405 1405
 			$output = '';
1406
-			if ( $this->block_show_advanced() ) {
1406
+			if ($this->block_show_advanced()) {
1407 1407
 				$val = 1;
1408 1408
 			} else {
1409 1409
 				$val = 0;
@@ -1423,14 +1423,14 @@  discard block
 block discarded – undo
1423 1423
 		 *
1424 1424
 		 * @return string $output
1425 1425
 		 */
1426
-		public function convert_element_require( $input ) {
1426
+		public function convert_element_require($input) {
1427 1427
 
1428
-			$input = str_replace( "'", '"', $input );// we only want double quotes
1428
+			$input = str_replace("'", '"', $input); // we only want double quotes
1429 1429
 
1430
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
1430
+			$output = esc_attr(str_replace(array("[%", "%]"), array(
1431 1431
 				"jQuery(form).find('[data-argument=\"",
1432 1432
 				"\"]').find('input,select').val()"
1433
-			), $input ) );
1433
+			), $input));
1434 1434
 
1435 1435
 			return $output;
1436 1436
 		}
@@ -1441,54 +1441,54 @@  discard block
 block discarded – undo
1441 1441
 		 * @param $args
1442 1442
 		 * @param $instance
1443 1443
 		 */
1444
-		public function widget_inputs( $args, $instance ) {
1444
+		public function widget_inputs($args, $instance) {
1445 1445
 
1446 1446
 			$class             = "";
1447 1447
 			$element_require   = "";
1448 1448
 			$custom_attributes = "";
1449 1449
 
1450 1450
 			// get value
1451
-			if ( isset( $instance[ $args['name'] ] ) ) {
1452
-				$value = $instance[ $args['name'] ];
1453
-			} elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) {
1454
-				$value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] );
1451
+			if (isset($instance[$args['name']])) {
1452
+				$value = $instance[$args['name']];
1453
+			} elseif (!isset($instance[$args['name']]) && !empty($args['default'])) {
1454
+				$value = is_array($args['default']) ? array_map("esc_html", $args['default']) : esc_html($args['default']);
1455 1455
 			} else {
1456 1456
 				$value = '';
1457 1457
 			}
1458 1458
 
1459 1459
 			// get placeholder
1460
-			if ( ! empty( $args['placeholder'] ) ) {
1461
-				$placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'";
1460
+			if (!empty($args['placeholder'])) {
1461
+				$placeholder = "placeholder='" . esc_html($args['placeholder']) . "'";
1462 1462
 			} else {
1463 1463
 				$placeholder = '';
1464 1464
 			}
1465 1465
 
1466 1466
 			// get if advanced
1467
-			if ( isset( $args['advanced'] ) && $args['advanced'] ) {
1467
+			if (isset($args['advanced']) && $args['advanced']) {
1468 1468
 				$class .= " sd-advanced-setting ";
1469 1469
 			}
1470 1470
 
1471 1471
 			// element_require
1472
-			if ( isset( $args['element_require'] ) && $args['element_require'] ) {
1472
+			if (isset($args['element_require']) && $args['element_require']) {
1473 1473
 				$element_require = $args['element_require'];
1474 1474
 			}
1475 1475
 
1476 1476
 			// custom_attributes
1477
-			if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) {
1478
-				$custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true );
1477
+			if (isset($args['custom_attributes']) && $args['custom_attributes']) {
1478
+				$custom_attributes = $this->array_to_attributes($args['custom_attributes'], true);
1479 1479
 			}
1480 1480
 
1481 1481
 			// before wrapper
1482 1482
 			?>
1483
-			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
1484
-			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
1485
-			   data-element_require='<?php if ( $element_require ) {
1486
-				   echo $this->convert_element_require( $element_require );
1483
+			<p class="sd-argument <?php echo esc_attr($class); ?>"
1484
+			   data-argument='<?php echo esc_attr($args['name']); ?>'
1485
+			   data-element_require='<?php if ($element_require) {
1486
+				   echo $this->convert_element_require($element_require);
1487 1487
 			   } ?>'
1488 1488
 			>
1489 1489
 				<?php
1490 1490
 
1491
-				switch ( $args['type'] ) {
1491
+				switch ($args['type']) {
1492 1492
 					//array('text','password','number','email','tel','url','color')
1493 1493
 					case "text":
1494 1494
 					case "password":
@@ -1499,46 +1499,46 @@  discard block
 block discarded – undo
1499 1499
 					case "color":
1500 1500
 						?>
1501 1501
 						<label
1502
-							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>
1502
+							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>
1503 1503
 						<input <?php echo $placeholder; ?> class="widefat"
1504 1504
 							<?php echo $custom_attributes; ?>
1505
-							                               id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1506
-							                               name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>"
1507
-							                               type="<?php echo esc_attr( $args['type'] ); ?>"
1508
-							                               value="<?php echo esc_attr( $value ); ?>">
1505
+							                               id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1506
+							                               name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>"
1507
+							                               type="<?php echo esc_attr($args['type']); ?>"
1508
+							                               value="<?php echo esc_attr($value); ?>">
1509 1509
 						<?php
1510 1510
 
1511 1511
 						break;
1512 1512
 					case "select":
1513
-						$multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false;
1514
-						if ( $multiple ) {
1515
-							if ( empty( $value ) ) {
1513
+						$multiple = isset($args['multiple']) && $args['multiple'] ? true : false;
1514
+						if ($multiple) {
1515
+							if (empty($value)) {
1516 1516
 								$value = array();
1517 1517
 							}
1518 1518
 						}
1519 1519
 						?>
1520 1520
 						<label
1521
-							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>
1521
+							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>
1522 1522
 						<select <?php echo $placeholder; ?> class="widefat"
1523 1523
 							<?php echo $custom_attributes; ?>
1524
-							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1525
-							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) );
1526
-							                                if ( $multiple ) {
1524
+							                                id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1525
+							                                name="<?php echo esc_attr($this->get_field_name($args['name']));
1526
+							                                if ($multiple) {
1527 1527
 								                                echo "[]";
1528 1528
 							                                } ?>"
1529
-							<?php if ( $multiple ) {
1529
+							<?php if ($multiple) {
1530 1530
 								echo "multiple";
1531 1531
 							} //@todo not implemented yet due to gutenberg not supporting it
1532 1532
 							?>
1533 1533
 						>
1534 1534
 							<?php
1535 1535
 
1536
-							if ( ! empty( $args['options'] ) ) {
1537
-								foreach ( $args['options'] as $val => $label ) {
1538
-									if ( $multiple ) {
1539
-										$selected = in_array( $val, $value ) ? 'selected="selected"' : '';
1536
+							if (!empty($args['options'])) {
1537
+								foreach ($args['options'] as $val => $label) {
1538
+									if ($multiple) {
1539
+										$selected = in_array($val, $value) ? 'selected="selected"' : '';
1540 1540
 									} else {
1541
-										$selected = selected( $value, $val, false );
1541
+										$selected = selected($value, $val, false);
1542 1542
 									}
1543 1543
 									echo "<option value='$val' " . $selected . ">$label</option>";
1544 1544
 								}
@@ -1550,20 +1550,20 @@  discard block
 block discarded – undo
1550 1550
 					case "checkbox":
1551 1551
 						?>
1552 1552
 						<input <?php echo $placeholder; ?>
1553
-							<?php checked( 1, $value, true ) ?>
1553
+							<?php checked(1, $value, true) ?>
1554 1554
 							<?php echo $custom_attributes; ?>
1555
-							class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1556
-							name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox"
1555
+							class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1556
+							name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox"
1557 1557
 							value="1">
1558 1558
 						<label
1559
-							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>
1559
+							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>
1560 1560
 						<?php
1561 1561
 						break;
1562 1562
 					case "hidden":
1563 1563
 						?>
1564
-						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1565
-						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
1566
-						       value="<?php echo esc_attr( $value ); ?>">
1564
+						<input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1565
+						       name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden"
1566
+						       value="<?php echo esc_attr($value); ?>">
1567 1567
 						<?php
1568 1568
 						break;
1569 1569
 					default:
@@ -1585,14 +1585,14 @@  discard block
 block discarded – undo
1585 1585
 		 * @return string
1586 1586
 		 * @todo, need to make its own tooltip script
1587 1587
 		 */
1588
-		public function widget_field_desc( $args ) {
1588
+		public function widget_field_desc($args) {
1589 1589
 
1590 1590
 			$description = '';
1591
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
1592
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
1593
-					$description = $this->desc_tip( $args['desc'] );
1591
+			if (isset($args['desc']) && $args['desc']) {
1592
+				if (isset($args['desc_tip']) && $args['desc_tip']) {
1593
+					$description = $this->desc_tip($args['desc']);
1594 1594
 				} else {
1595
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
1595
+					$description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>';
1596 1596
 				}
1597 1597
 			}
1598 1598
 
@@ -1607,11 +1607,11 @@  discard block
 block discarded – undo
1607 1607
 		 *
1608 1608
 		 * @return string
1609 1609
 		 */
1610
-		function desc_tip( $tip, $allow_html = false ) {
1611
-			if ( $allow_html ) {
1612
-				$tip = $this->sanitize_tooltip( $tip );
1610
+		function desc_tip($tip, $allow_html = false) {
1611
+			if ($allow_html) {
1612
+				$tip = $this->sanitize_tooltip($tip);
1613 1613
 			} else {
1614
-				$tip = esc_attr( $tip );
1614
+				$tip = esc_attr($tip);
1615 1615
 			}
1616 1616
 
1617 1617
 			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -1624,8 +1624,8 @@  discard block
 block discarded – undo
1624 1624
 		 *
1625 1625
 		 * @return string
1626 1626
 		 */
1627
-		public function sanitize_tooltip( $var ) {
1628
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1627
+		public function sanitize_tooltip($var) {
1628
+			return htmlspecialchars(wp_kses(html_entity_decode($var), array(
1629 1629
 				'br'     => array(),
1630 1630
 				'em'     => array(),
1631 1631
 				'strong' => array(),
@@ -1635,7 +1635,7 @@  discard block
 block discarded – undo
1635 1635
 				'li'     => array(),
1636 1636
 				'ol'     => array(),
1637 1637
 				'p'      => array(),
1638
-			) ) );
1638
+			)));
1639 1639
 		}
1640 1640
 
1641 1641
 		/**
@@ -1647,23 +1647,23 @@  discard block
 block discarded – undo
1647 1647
 		 * @return array
1648 1648
 		 * @todo we should add some sanitation here.
1649 1649
 		 */
1650
-		public function update( $new_instance, $old_instance ) {
1650
+		public function update($new_instance, $old_instance) {
1651 1651
 
1652 1652
 			//save the widget
1653
-			$instance = array_merge( (array) $old_instance, (array) $new_instance );
1653
+			$instance = array_merge((array)$old_instance, (array)$new_instance);
1654 1654
 
1655 1655
 			// set widget instance
1656 1656
 			$this->instance = $instance;
1657 1657
 
1658
-			if ( empty( $this->arguments ) ) {
1658
+			if (empty($this->arguments)) {
1659 1659
 				$this->get_arguments();
1660 1660
 			}
1661 1661
 
1662 1662
 			// check for checkboxes
1663
-			if ( ! empty( $this->arguments ) ) {
1664
-				foreach ( $this->arguments as $argument ) {
1665
-					if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) {
1666
-						$instance[ $argument['name'] ] = '0';
1663
+			if (!empty($this->arguments)) {
1664
+				foreach ($this->arguments as $argument) {
1665
+					if (isset($argument['type']) && $argument['type'] == 'checkbox' && !isset($new_instance[$argument['name']])) {
1666
+						$instance[$argument['name']] = '0';
1667 1667
 					}
1668 1668
 				}
1669 1669
 			}
@@ -1681,7 +1681,7 @@  discard block
 block discarded – undo
1681 1681
 		 */
1682 1682
 		public function is_block_content_call() {
1683 1683
 			$result = false;
1684
-			if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) {
1684
+			if (wp_doing_ajax() && isset($_REQUEST['action']) && $_REQUEST['action'] == 'super_duper_output_shortcode') {
1685 1685
 				$result = true;
1686 1686
 			}
1687 1687
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
 				<?php
197 197
 				if(! empty( $insert_shortcode_function )){
198 198
 					echo $insert_shortcode_function;
199
-				}else{
199
+				} else{
200 200
 
201 201
 				/**
202 202
 				 * Function for super duper insert shortcode.
@@ -1068,7 +1068,7 @@  discard block
 block discarded – undo
1068 1068
 								// If the user sets block-output array then build it
1069 1069
 								if ( ! empty( $this->options['block-output'] ) ) {
1070 1070
 								$this->block_element( $this->options['block-output'] );
1071
-							}else{
1071
+							} else{
1072 1072
 								// if no block-output is set then we try and get the shortcode html output via ajax.
1073 1073
 								?>
1074 1074
 								el('div', {
Please login to merge, or discard this patch.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 2 patches
Indentation   +353 added lines, -353 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
  * Bail if we are not in WP.
14 14
  */
15 15
 if ( ! defined( 'ABSPATH' ) ) {
16
-	exit;
16
+    exit;
17 17
 }
18 18
 
19 19
 /**
@@ -21,285 +21,285 @@  discard block
 block discarded – undo
21 21
  */
22 22
 if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
23 23
 
24
-	/**
25
-	 * A Class to be able to change settings for Font Awesome.
26
-	 *
27
-	 * Class WP_Font_Awesome_Settings
28
-	 * @since 1.0.10 Now able to pass wp.org theme check.
29
-	 * @ver 1.0.10
30
-	 * @todo decide how to implement textdomain
31
-	 */
32
-	class WP_Font_Awesome_Settings {
33
-
34
-		/**
35
-		 * Class version version.
36
-		 *
37
-		 * @var string
38
-		 */
39
-		public $version = '1.0.10';
40
-
41
-		/**
42
-		 * Class textdomain.
43
-		 *
44
-		 * @var string
45
-		 */
46
-		public $textdomain = 'font-awesome-settings';
47
-
48
-		/**
49
-		 * Latest version of Font Awesome at time of publish published.
50
-		 *
51
-		 * @var string
52
-		 */
53
-		public $latest = "5.6.1";
54
-
55
-		/**
56
-		 * The title.
57
-		 *
58
-		 * @var string
59
-		 */
60
-		public $name = 'Font Awesome';
61
-
62
-		/**
63
-		 * Holds the settings values.
64
-		 *
65
-		 * @var array
66
-		 */
67
-		private $settings;
68
-
69
-		/**
70
-		 * WP_Font_Awesome_Settings instance.
71
-		 *
72
-		 * @access private
73
-		 * @since  1.0.0
74
-		 * @var    WP_Font_Awesome_Settings There can be only one!
75
-		 */
76
-		private static $instance = null;
77
-
78
-		/**
79
-		 * Main WP_Font_Awesome_Settings Instance.
80
-		 *
81
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
82
-		 *
83
-		 * @since 1.0.0
84
-		 * @static
85
-		 * @return WP_Font_Awesome_Settings - Main instance.
86
-		 */
87
-		public static function instance() {
88
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
89
-				self::$instance = new WP_Font_Awesome_Settings;
90
-
91
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
92
-
93
-				if ( is_admin() ) {
94
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
95
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
96
-				}
97
-
98
-				do_action( 'wp_font_awesome_settings_loaded' );
99
-			}
100
-
101
-			return self::$instance;
102
-		}
103
-
104
-		/**
105
-		 * Initiate the settings and add the required action hooks.
106
-		 *
107
-		 * @since 1.0.8 Settings name wrong - FIXED
108
-		 */
109
-		public function init() {
110
-			$this->settings = $this->get_settings();
111
-
112
-			if ( $this->settings['type'] == 'CSS' ) {
113
-
114
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
115
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit;
116
-				}
117
-
118
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
119
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
120
-				}
121
-
122
-			} else {
123
-
124
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
125
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit;
126
-				}
127
-
128
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
129
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
130
-				}
131
-			}
132
-
133
-			// remove font awesome if set to do so
134
-			if ( $this->settings['dequeue'] == '1' ) {
135
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
136
-			}
137
-
138
-		}
139
-
140
-		/**
141
-		 * Adds the Font Awesome styles.
142
-		 */
143
-		public function enqueue_style() {
144
-			// build url
145
-			$url = $this->get_url();
146
-
147
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
148
-			wp_register_style( 'font-awesome', $url, array(), null );
149
-			wp_enqueue_style( 'font-awesome' );
150
-
151
-			if ( $this->settings['shims'] ) {
152
-				$url = $this->get_url( true );
153
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
154
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
155
-				wp_enqueue_style( 'font-awesome-shims' );
156
-			}
157
-		}
158
-
159
-		/**
160
-		 * Adds the Font Awesome JS.
161
-		 */
162
-		public function enqueue_scripts() {
163
-			// build url
164
-			$url = $this->get_url();
165
-
166
-			$deregister_function = 'wp'.'_'.'deregister'.'_'.'script';
167
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
168
-			wp_register_script( 'font-awesome', $url, array(), null );
169
-			wp_enqueue_script( 'font-awesome' );
170
-
171
-			if ( $this->settings['shims'] ) {
172
-				$url = $this->get_url( true );
173
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
174
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
175
-				wp_enqueue_script( 'font-awesome-shims' );
176
-			}
177
-		}
178
-
179
-		/**
180
-		 * Get the url of the Font Awesome files.
181
-		 *
182
-		 * @param bool $shims If this is a shim file or not.
183
-		 *
184
-		 * @return string The url to the file.
185
-		 */
186
-		public function get_url( $shims = false ) {
187
-			$script  = $shims ? 'v4-shims' : 'all';
188
-			$type    = $this->settings['type'];
189
-			$version = $this->settings['version'];
190
-
191
-			$url = "https://use.fontawesome.com/releases/"; // CDN
192
-			$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
193
-			$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
194
-			$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
195
-			$url .= "?wpfas=true"; // set our var so our version is not removed
196
-
197
-			return $url;
198
-		}
199
-
200
-		/**
201
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
202
-		 *
203
-		 * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
204
-		 *
205
-		 * @param $url
206
-		 * @param $original_url
207
-		 * @param $_context
208
-		 *
209
-		 * @return string The filtered url.
210
-		 */
211
-		public function remove_font_awesome( $url, $original_url, $_context ) {
212
-
213
-			if ( $_context == 'display'
214
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
215
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
216
-			) {// it's a font-awesome-url (probably)
217
-
218
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
219
-					if ( $this->settings['type'] == 'JS' ) {
220
-						if ( $this->settings['js-pseudo'] ) {
221
-							$url .= "' data-search-pseudo-elements defer='defer";
222
-						} else {
223
-							$url .= "' defer='defer";
224
-						}
225
-					}
226
-				} else {
227
-					$url = ''; // removing the url removes the file
228
-				}
229
-
230
-			}
231
-
232
-			return $url;
233
-		}
234
-
235
-		/**
236
-		 * Register the database settings with WordPress.
237
-		 */
238
-		public function register_settings() {
239
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
240
-		}
241
-
242
-		/**
243
-		 * Add the WordPress settings menu item.
244
-		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
245
-		 */
246
-		public function menu_item() {
247
-			$menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme
248
-			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
249
-				$this,
250
-				'settings_page'
251
-			) );
252
-		}
253
-
254
-		/**
255
-		 * Get the current Font Awesome output settings.
256
-		 *
257
-		 * @return array The array of settings.
258
-		 */
259
-		public function get_settings() {
260
-
261
-			$db_settings = get_option( 'wp-font-awesome-settings' );
262
-
263
-			$defaults = array(
264
-				'type'      => 'CSS', // type to use, CSS or JS
265
-				'version'   => '', // latest
266
-				'enqueue'   => '', // front and backend
267
-				'shims'     => '1', // default on for now, @todo maybe change to off in 2020
268
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
269
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
270
-			);
271
-
272
-			$settings = wp_parse_args( $db_settings, $defaults );
273
-
274
-			/**
275
-			 * Filter the Font Awesome settings.
276
-			 *
277
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
278
-			 */
279
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
280
-		}
281
-
282
-
283
-		/**
284
-		 * The settings page html output.
285
-		 */
286
-		public function settings_page() {
287
-			if ( ! current_user_can( 'manage_options' ) ) {
288
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
289
-			}
290
-
291
-			// a hidden way to force the update of the verison number vai api instead of waiting the 48 hours
292
-			if(isset($_REQUEST['force-version-check'])){
293
-				$this->get_latest_version($force_api = true);
294
-			}
295
-			?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @since 1.0.10 Now able to pass wp.org theme check.
29
+     * @ver 1.0.10
30
+     * @todo decide how to implement textdomain
31
+     */
32
+    class WP_Font_Awesome_Settings {
33
+
34
+        /**
35
+         * Class version version.
36
+         *
37
+         * @var string
38
+         */
39
+        public $version = '1.0.10';
40
+
41
+        /**
42
+         * Class textdomain.
43
+         *
44
+         * @var string
45
+         */
46
+        public $textdomain = 'font-awesome-settings';
47
+
48
+        /**
49
+         * Latest version of Font Awesome at time of publish published.
50
+         *
51
+         * @var string
52
+         */
53
+        public $latest = "5.6.1";
54
+
55
+        /**
56
+         * The title.
57
+         *
58
+         * @var string
59
+         */
60
+        public $name = 'Font Awesome';
61
+
62
+        /**
63
+         * Holds the settings values.
64
+         *
65
+         * @var array
66
+         */
67
+        private $settings;
68
+
69
+        /**
70
+         * WP_Font_Awesome_Settings instance.
71
+         *
72
+         * @access private
73
+         * @since  1.0.0
74
+         * @var    WP_Font_Awesome_Settings There can be only one!
75
+         */
76
+        private static $instance = null;
77
+
78
+        /**
79
+         * Main WP_Font_Awesome_Settings Instance.
80
+         *
81
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
82
+         *
83
+         * @since 1.0.0
84
+         * @static
85
+         * @return WP_Font_Awesome_Settings - Main instance.
86
+         */
87
+        public static function instance() {
88
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
89
+                self::$instance = new WP_Font_Awesome_Settings;
90
+
91
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
92
+
93
+                if ( is_admin() ) {
94
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
95
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
96
+                }
97
+
98
+                do_action( 'wp_font_awesome_settings_loaded' );
99
+            }
100
+
101
+            return self::$instance;
102
+        }
103
+
104
+        /**
105
+         * Initiate the settings and add the required action hooks.
106
+         *
107
+         * @since 1.0.8 Settings name wrong - FIXED
108
+         */
109
+        public function init() {
110
+            $this->settings = $this->get_settings();
111
+
112
+            if ( $this->settings['type'] == 'CSS' ) {
113
+
114
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
115
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit;
116
+                }
117
+
118
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
119
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
120
+                }
121
+
122
+            } else {
123
+
124
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
125
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit;
126
+                }
127
+
128
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
129
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
130
+                }
131
+            }
132
+
133
+            // remove font awesome if set to do so
134
+            if ( $this->settings['dequeue'] == '1' ) {
135
+                add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
136
+            }
137
+
138
+        }
139
+
140
+        /**
141
+         * Adds the Font Awesome styles.
142
+         */
143
+        public function enqueue_style() {
144
+            // build url
145
+            $url = $this->get_url();
146
+
147
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
148
+            wp_register_style( 'font-awesome', $url, array(), null );
149
+            wp_enqueue_style( 'font-awesome' );
150
+
151
+            if ( $this->settings['shims'] ) {
152
+                $url = $this->get_url( true );
153
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
154
+                wp_register_style( 'font-awesome-shims', $url, array(), null );
155
+                wp_enqueue_style( 'font-awesome-shims' );
156
+            }
157
+        }
158
+
159
+        /**
160
+         * Adds the Font Awesome JS.
161
+         */
162
+        public function enqueue_scripts() {
163
+            // build url
164
+            $url = $this->get_url();
165
+
166
+            $deregister_function = 'wp'.'_'.'deregister'.'_'.'script';
167
+            call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
168
+            wp_register_script( 'font-awesome', $url, array(), null );
169
+            wp_enqueue_script( 'font-awesome' );
170
+
171
+            if ( $this->settings['shims'] ) {
172
+                $url = $this->get_url( true );
173
+                call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
174
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
175
+                wp_enqueue_script( 'font-awesome-shims' );
176
+            }
177
+        }
178
+
179
+        /**
180
+         * Get the url of the Font Awesome files.
181
+         *
182
+         * @param bool $shims If this is a shim file or not.
183
+         *
184
+         * @return string The url to the file.
185
+         */
186
+        public function get_url( $shims = false ) {
187
+            $script  = $shims ? 'v4-shims' : 'all';
188
+            $type    = $this->settings['type'];
189
+            $version = $this->settings['version'];
190
+
191
+            $url = "https://use.fontawesome.com/releases/"; // CDN
192
+            $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
193
+            $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
194
+            $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
195
+            $url .= "?wpfas=true"; // set our var so our version is not removed
196
+
197
+            return $url;
198
+        }
199
+
200
+        /**
201
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
202
+         *
203
+         * Uses the clean_url filter to try and remove any other Font Awesome files added, it can also add pseudo-elements flag for the JS version.
204
+         *
205
+         * @param $url
206
+         * @param $original_url
207
+         * @param $_context
208
+         *
209
+         * @return string The filtered url.
210
+         */
211
+        public function remove_font_awesome( $url, $original_url, $_context ) {
212
+
213
+            if ( $_context == 'display'
214
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
215
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
216
+            ) {// it's a font-awesome-url (probably)
217
+
218
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
219
+                    if ( $this->settings['type'] == 'JS' ) {
220
+                        if ( $this->settings['js-pseudo'] ) {
221
+                            $url .= "' data-search-pseudo-elements defer='defer";
222
+                        } else {
223
+                            $url .= "' defer='defer";
224
+                        }
225
+                    }
226
+                } else {
227
+                    $url = ''; // removing the url removes the file
228
+                }
229
+
230
+            }
231
+
232
+            return $url;
233
+        }
234
+
235
+        /**
236
+         * Register the database settings with WordPress.
237
+         */
238
+        public function register_settings() {
239
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
240
+        }
241
+
242
+        /**
243
+         * Add the WordPress settings menu item.
244
+         * @since 1.0.10 Calling function name direct will fail theme check so we don't.
245
+         */
246
+        public function menu_item() {
247
+            $menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme
248
+            call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
249
+                $this,
250
+                'settings_page'
251
+            ) );
252
+        }
253
+
254
+        /**
255
+         * Get the current Font Awesome output settings.
256
+         *
257
+         * @return array The array of settings.
258
+         */
259
+        public function get_settings() {
260
+
261
+            $db_settings = get_option( 'wp-font-awesome-settings' );
262
+
263
+            $defaults = array(
264
+                'type'      => 'CSS', // type to use, CSS or JS
265
+                'version'   => '', // latest
266
+                'enqueue'   => '', // front and backend
267
+                'shims'     => '1', // default on for now, @todo maybe change to off in 2020
268
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
269
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
270
+            );
271
+
272
+            $settings = wp_parse_args( $db_settings, $defaults );
273
+
274
+            /**
275
+             * Filter the Font Awesome settings.
276
+             *
277
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
278
+             */
279
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
280
+        }
281
+
282
+
283
+        /**
284
+         * The settings page html output.
285
+         */
286
+        public function settings_page() {
287
+            if ( ! current_user_can( 'manage_options' ) ) {
288
+                wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
289
+            }
290
+
291
+            // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours
292
+            if(isset($_REQUEST['force-version-check'])){
293
+                $this->get_latest_version($force_api = true);
294
+            }
295
+            ?>
296 296
 			<div class="wrap">
297 297
 				<h1><?php echo $this->name; ?></h1>
298 298
 				<form method="post" action="options.php">
299 299
 					<?php
300
-					settings_fields( 'wp-font-awesome-settings' );
301
-					do_settings_sections( 'wp-font-awesome-settings' );
302
-					?>
300
+                    settings_fields( 'wp-font-awesome-settings' );
301
+                    do_settings_sections( 'wp-font-awesome-settings' );
302
+                    ?>
303 303
 					<table class="form-table">
304 304
 						<tr valign="top">
305 305
 							<th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th>
@@ -396,87 +396,87 @@  discard block
 block discarded – undo
396 396
 
397 397
 					</table>
398 398
 					<?php
399
-					submit_button();
400
-					?>
399
+                    submit_button();
400
+                    ?>
401 401
 				</form>
402 402
 
403 403
 				<div id="wpfas-version"><?php echo $this->version; ?></div>
404 404
 			</div>
405 405
 
406 406
 			<?php
407
-		}
408
-
409
-		/**
410
-		 * Check a version number is valid and if so return it or else return an empty string.
411
-		 *
412
-		 * @param $version string The version number to check.
413
-		 * @since 1.0.6
414
-		 *
415
-		 * @return string Either a valid version number or an empty string.
416
-		 */
417
-		public function validate_version_number( $version ) {
418
-
419
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
420
-				// valid
421
-			} else {
422
-				$version = '';// not validated
423
-			}
424
-
425
-			return $version;
426
-		}
427
-
428
-
429
-		/**
430
-		 * Get the latest version of Font Awesome.
431
-		 *
432
-		 * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours.
433
-		 *
434
-		 * @since 1.0.7
435
-		 * @return mixed|string The latest version number found.
436
-		 */
437
-		public function get_latest_version($force_api = false) {
438
-			$latest_version = $this->latest;
439
-
440
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
441
-
442
-			if ( $cache === false || $force_api) { // its not set
443
-				$api_ver = $this->get_latest_version_from_api();
444
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
445
-					$latest_version = $api_ver;
446
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
447
-				}
448
-			} elseif ( $this->validate_version_number( $cache ) ) {
449
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
450
-					$latest_version = $cache;
451
-				}
452
-			}
453
-
454
-			return $latest_version;
455
-		}
456
-
457
-		/**
458
-		 * Get the latest Font Awesome version from the github API.
459
-		 *
460
-		 * @since 1.0.7
461
-		 * @return string The latest version number or `0` on API fail.
462
-		 */
463
-		public function get_latest_version_from_api() {
464
-			$version  = "0";
465
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
466
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
467
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
468
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
469
-					$version = $api_response['tag_name'];
470
-				}
471
-			}
472
-
473
-			return $version;
474
-		}
475
-
476
-	}
477
-
478
-	/**
479
-	 * Run the class if found.
480
-	 */
481
-	WP_Font_Awesome_Settings::instance();
407
+        }
408
+
409
+        /**
410
+         * Check a version number is valid and if so return it or else return an empty string.
411
+         *
412
+         * @param $version string The version number to check.
413
+         * @since 1.0.6
414
+         *
415
+         * @return string Either a valid version number or an empty string.
416
+         */
417
+        public function validate_version_number( $version ) {
418
+
419
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
420
+                // valid
421
+            } else {
422
+                $version = '';// not validated
423
+            }
424
+
425
+            return $version;
426
+        }
427
+
428
+
429
+        /**
430
+         * Get the latest version of Font Awesome.
431
+         *
432
+         * We check for a cached bersion and if none we will check for a live version via API and then cache it for 48 hours.
433
+         *
434
+         * @since 1.0.7
435
+         * @return mixed|string The latest version number found.
436
+         */
437
+        public function get_latest_version($force_api = false) {
438
+            $latest_version = $this->latest;
439
+
440
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
441
+
442
+            if ( $cache === false || $force_api) { // its not set
443
+                $api_ver = $this->get_latest_version_from_api();
444
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
445
+                    $latest_version = $api_ver;
446
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
447
+                }
448
+            } elseif ( $this->validate_version_number( $cache ) ) {
449
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
450
+                    $latest_version = $cache;
451
+                }
452
+            }
453
+
454
+            return $latest_version;
455
+        }
456
+
457
+        /**
458
+         * Get the latest Font Awesome version from the github API.
459
+         *
460
+         * @since 1.0.7
461
+         * @return string The latest version number or `0` on API fail.
462
+         */
463
+        public function get_latest_version_from_api() {
464
+            $version  = "0";
465
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
466
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
467
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
468
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
469
+                    $version = $api_response['tag_name'];
470
+                }
471
+            }
472
+
473
+            return $version;
474
+        }
475
+
476
+    }
477
+
478
+    /**
479
+     * Run the class if found.
480
+     */
481
+    WP_Font_Awesome_Settings::instance();
482 482
 }
483 483
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
 /**
13 13
  * Bail if we are not in WP.
14 14
  */
15
-if ( ! defined( 'ABSPATH' ) ) {
15
+if (!defined('ABSPATH')) {
16 16
 	exit;
17 17
 }
18 18
 
19 19
 /**
20 20
  * Only add if the class does not already exist.
21 21
  */
22
-if ( ! class_exists( 'WP_Font_Awesome_Settings' ) ) {
22
+if (!class_exists('WP_Font_Awesome_Settings')) {
23 23
 
24 24
 	/**
25 25
 	 * A Class to be able to change settings for Font Awesome.
@@ -85,17 +85,17 @@  discard block
 block discarded – undo
85 85
 		 * @return WP_Font_Awesome_Settings - Main instance.
86 86
 		 */
87 87
 		public static function instance() {
88
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
88
+			if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) {
89 89
 				self::$instance = new WP_Font_Awesome_Settings;
90 90
 
91
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
91
+				add_action('init', array(self::$instance, 'init')); // set settings
92 92
 
93
-				if ( is_admin() ) {
94
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
95
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
93
+				if (is_admin()) {
94
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
95
+					add_action('admin_init', array(self::$instance, 'register_settings'));
96 96
 				}
97 97
 
98
-				do_action( 'wp_font_awesome_settings_loaded' );
98
+				do_action('wp_font_awesome_settings_loaded');
99 99
 			}
100 100
 
101 101
 			return self::$instance;
@@ -109,30 +109,30 @@  discard block
 block discarded – undo
109 109
 		public function init() {
110 110
 			$this->settings = $this->get_settings();
111 111
 
112
-			if ( $this->settings['type'] == 'CSS' ) {
112
+			if ($this->settings['type'] == 'CSS') {
113 113
 
114
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
115
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit;
114
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
115
+					add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); //echo '###';exit;
116 116
 				}
117 117
 
118
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
119
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
118
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
119
+					add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000);
120 120
 				}
121 121
 
122 122
 			} else {
123 123
 
124
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
125
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit;
124
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
125
+					add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); //echo '###';exit;
126 126
 				}
127 127
 
128
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
129
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
128
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
129
+					add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000);
130 130
 				}
131 131
 			}
132 132
 
133 133
 			// remove font awesome if set to do so
134
-			if ( $this->settings['dequeue'] == '1' ) {
135
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
134
+			if ($this->settings['dequeue'] == '1') {
135
+				add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3);
136 136
 			}
137 137
 
138 138
 		}
@@ -144,15 +144,15 @@  discard block
 block discarded – undo
144 144
 			// build url
145 145
 			$url = $this->get_url();
146 146
 
147
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
148
-			wp_register_style( 'font-awesome', $url, array(), null );
149
-			wp_enqueue_style( 'font-awesome' );
147
+			wp_deregister_style('font-awesome'); // deregister in case its already there
148
+			wp_register_style('font-awesome', $url, array(), null);
149
+			wp_enqueue_style('font-awesome');
150 150
 
151
-			if ( $this->settings['shims'] ) {
152
-				$url = $this->get_url( true );
153
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
154
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
155
-				wp_enqueue_style( 'font-awesome-shims' );
151
+			if ($this->settings['shims']) {
152
+				$url = $this->get_url(true);
153
+				wp_deregister_style('font-awesome-shims'); // deregister in case its already there
154
+				wp_register_style('font-awesome-shims', $url, array(), null);
155
+				wp_enqueue_style('font-awesome-shims');
156 156
 			}
157 157
 		}
158 158
 
@@ -163,16 +163,16 @@  discard block
 block discarded – undo
163 163
 			// build url
164 164
 			$url = $this->get_url();
165 165
 
166
-			$deregister_function = 'wp'.'_'.'deregister'.'_'.'script';
167
-			call_user_func( $deregister_function, 'font-awesome' ); // deregister in case its already there
168
-			wp_register_script( 'font-awesome', $url, array(), null );
169
-			wp_enqueue_script( 'font-awesome' );
166
+			$deregister_function = 'wp' . '_' . 'deregister' . '_' . 'script';
167
+			call_user_func($deregister_function, 'font-awesome'); // deregister in case its already there
168
+			wp_register_script('font-awesome', $url, array(), null);
169
+			wp_enqueue_script('font-awesome');
170 170
 
171
-			if ( $this->settings['shims'] ) {
172
-				$url = $this->get_url( true );
173
-				call_user_func( $deregister_function, 'font-awesome-shims' ); // deregister in case its already there
174
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
175
-				wp_enqueue_script( 'font-awesome-shims' );
171
+			if ($this->settings['shims']) {
172
+				$url = $this->get_url(true);
173
+				call_user_func($deregister_function, 'font-awesome-shims'); // deregister in case its already there
174
+				wp_register_script('font-awesome-shims', $url, array(), null);
175
+				wp_enqueue_script('font-awesome-shims');
176 176
 			}
177 177
 		}
178 178
 
@@ -183,13 +183,13 @@  discard block
 block discarded – undo
183 183
 		 *
184 184
 		 * @return string The url to the file.
185 185
 		 */
186
-		public function get_url( $shims = false ) {
186
+		public function get_url($shims = false) {
187 187
 			$script  = $shims ? 'v4-shims' : 'all';
188 188
 			$type    = $this->settings['type'];
189 189
 			$version = $this->settings['version'];
190 190
 
191 191
 			$url = "https://use.fontawesome.com/releases/"; // CDN
192
-			$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
192
+			$url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
193 193
 			$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
194 194
 			$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
195 195
 			$url .= "?wpfas=true"; // set our var so our version is not removed
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
 		 *
209 209
 		 * @return string The filtered url.
210 210
 		 */
211
-		public function remove_font_awesome( $url, $original_url, $_context ) {
211
+		public function remove_font_awesome($url, $original_url, $_context) {
212 212
 
213
-			if ( $_context == 'display'
214
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
215
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
213
+			if ($_context == 'display'
214
+			     && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false)
215
+			     && (strstr($url, ".js") !== false || strstr($url, ".css") !== false)
216 216
 			) {// it's a font-awesome-url (probably)
217 217
 
218
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
219
-					if ( $this->settings['type'] == 'JS' ) {
220
-						if ( $this->settings['js-pseudo'] ) {
218
+				if (strstr($url, "wpfas=true") !== false) {
219
+					if ($this->settings['type'] == 'JS') {
220
+						if ($this->settings['js-pseudo']) {
221 221
 							$url .= "' data-search-pseudo-elements defer='defer";
222 222
 						} else {
223 223
 							$url .= "' defer='defer";
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 		 * Register the database settings with WordPress.
237 237
 		 */
238 238
 		public function register_settings() {
239
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
239
+			register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings');
240 240
 		}
241 241
 
242 242
 		/**
@@ -244,11 +244,11 @@  discard block
 block discarded – undo
244 244
 		 * @since 1.0.10 Calling function name direct will fail theme check so we don't.
245 245
 		 */
246 246
 		public function menu_item() {
247
-			$menu_function = 'add'.'_'.'options'.'_'.'page'; // won't pass theme check if function name present in theme
247
+			$menu_function = 'add' . '_' . 'options' . '_' . 'page'; // won't pass theme check if function name present in theme
248 248
 			call_user_func($menu_function, $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
249 249
 				$this,
250 250
 				'settings_page'
251
-			) );
251
+			));
252 252
 		}
253 253
 
254 254
 		/**
@@ -258,7 +258,7 @@  discard block
 block discarded – undo
258 258
 		 */
259 259
 		public function get_settings() {
260 260
 
261
-			$db_settings = get_option( 'wp-font-awesome-settings' );
261
+			$db_settings = get_option('wp-font-awesome-settings');
262 262
 
263 263
 			$defaults = array(
264 264
 				'type'      => 'CSS', // type to use, CSS or JS
@@ -269,14 +269,14 @@  discard block
 block discarded – undo
269 269
 				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
270 270
 			);
271 271
 
272
-			$settings = wp_parse_args( $db_settings, $defaults );
272
+			$settings = wp_parse_args($db_settings, $defaults);
273 273
 
274 274
 			/**
275 275
 			 * Filter the Font Awesome settings.
276 276
 			 *
277 277
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
278 278
 			 */
279
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
279
+			return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults);
280 280
 		}
281 281
 
282 282
 
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
 		 * The settings page html output.
285 285
 		 */
286 286
 		public function settings_page() {
287
-			if ( ! current_user_can( 'manage_options' ) ) {
288
-				wp_die( __( 'You do not have sufficient permissions to access this page.', 'font-awesome-settings' ) );
287
+			if (!current_user_can('manage_options')) {
288
+				wp_die(__('You do not have sufficient permissions to access this page.', 'font-awesome-settings'));
289 289
 			}
290 290
 
291 291
 			// a hidden way to force the update of the verison number vai api instead of waiting the 48 hours
292
-			if(isset($_REQUEST['force-version-check'])){
292
+			if (isset($_REQUEST['force-version-check'])) {
293 293
 				$this->get_latest_version($force_api = true);
294 294
 			}
295 295
 			?>
@@ -297,47 +297,47 @@  discard block
 block discarded – undo
297 297
 				<h1><?php echo $this->name; ?></h1>
298 298
 				<form method="post" action="options.php">
299 299
 					<?php
300
-					settings_fields( 'wp-font-awesome-settings' );
301
-					do_settings_sections( 'wp-font-awesome-settings' );
300
+					settings_fields('wp-font-awesome-settings');
301
+					do_settings_sections('wp-font-awesome-settings');
302 302
 					?>
303 303
 					<table class="form-table">
304 304
 						<tr valign="top">
305
-							<th scope="row"><label for="wpfas-type"><?php _e( 'Type', 'font-awesome-settings' ); ?></label></th>
305
+							<th scope="row"><label for="wpfas-type"><?php _e('Type', 'font-awesome-settings'); ?></label></th>
306 306
 							<td>
307 307
 								<select name="wp-font-awesome-settings[type]" id="wpfas-type">
308 308
 									<option
309
-										value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)', 'font-awesome-settings' ); ?></option>
310
-									<option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option>
309
+										value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)', 'font-awesome-settings'); ?></option>
310
+									<option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option>
311 311
 								</select>
312 312
 							</td>
313 313
 						</tr>
314 314
 
315 315
 						<tr valign="top">
316
-							<th scope="row"><label for="wpfas-version"><?php _e( 'Version', 'font-awesome-settings' ); ?></label></th>
316
+							<th scope="row"><label for="wpfas-version"><?php _e('Version', 'font-awesome-settings'); ?></label></th>
317 317
 							<td>
318 318
 								<select name="wp-font-awesome-settings[version]" id="wpfas-version">
319 319
 									<option
320
-										value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)', 'font-awesome-settings' ), $this->get_latest_version() ); ?>
320
+										value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)', 'font-awesome-settings'), $this->get_latest_version()); ?>
321 321
 									</option>
322
-									<option value="5.6.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>
322
+									<option value="5.6.0" <?php selected($this->settings['version'], '5.6.0'); ?>>
323 323
 										5.6.0
324 324
 									</option>
325
-									<option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>
325
+									<option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>
326 326
 										5.5.0
327 327
 									</option>
328
-									<option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>
328
+									<option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>
329 329
 										5.4.0
330 330
 									</option>
331
-									<option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>
331
+									<option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>
332 332
 										5.3.0
333 333
 									</option>
334
-									<option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>
334
+									<option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>
335 335
 										5.2.0
336 336
 									</option>
337
-									<option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>
337
+									<option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>
338 338
 										5.1.0
339 339
 									</option>
340
-									<option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>
340
+									<option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>
341 341
 										4.7.1 (CSS only)
342 342
 									</option>
343 343
 								</select>
@@ -345,51 +345,51 @@  discard block
 block discarded – undo
345 345
 						</tr>
346 346
 
347 347
 						<tr valign="top">
348
-							<th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue', 'font-awesome-settings' ); ?></label></th>
348
+							<th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue', 'font-awesome-settings'); ?></label></th>
349 349
 							<td>
350 350
 								<select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue">
351 351
 									<option
352
-										value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)', 'font-awesome-settings' ); ?></option>
352
+										value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)', 'font-awesome-settings'); ?></option>
353 353
 									<option
354
-										value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend', 'font-awesome-settings' ); ?></option>
354
+										value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend', 'font-awesome-settings'); ?></option>
355 355
 									<option
356
-										value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend', 'font-awesome-settings' ); ?></option>
356
+										value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend', 'font-awesome-settings'); ?></option>
357 357
 								</select>
358 358
 							</td>
359 359
 						</tr>
360 360
 
361 361
 						<tr valign="top">
362 362
 							<th scope="row"><label
363
-									for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility', 'font-awesome-settings' ); ?></label></th>
363
+									for="wpfas-shims"><?php _e('Enable v4 shims compatibility', 'font-awesome-settings'); ?></label></th>
364 364
 							<td>
365 365
 								<input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/>
366 366
 								<input type="checkbox" name="wp-font-awesome-settings[shims]"
367
-								       value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/>
368
-								<span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings' ); ?></span>
367
+								       value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/>
368
+								<span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.', 'font-awesome-settings'); ?></span>
369 369
 							</td>
370 370
 						</tr>
371 371
 
372 372
 						<tr valign="top">
373 373
 							<th scope="row"><label
374
-									for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)', 'font-awesome-settings' ); ?></label>
374
+									for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)', 'font-awesome-settings'); ?></label>
375 375
 							</th>
376 376
 							<td>
377 377
 								<input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/>
378 378
 								<input type="checkbox" name="wp-font-awesome-settings[js-pseudo]"
379
-								       value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?>
379
+								       value="1" <?php checked($this->settings['js-pseudo'], '1'); ?>
380 380
 								       id="wpfas-js-pseudo"/>
381
-								<span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings' ); ?></span>
381
+								<span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.', 'font-awesome-settings'); ?></span>
382 382
 							</td>
383 383
 						</tr>
384 384
 
385 385
 						<tr valign="top">
386
-							<th scope="row"><label for="wpfas-dequeue"><?php _e( 'Dequeue', 'font-awesome-settings' ); ?></label></th>
386
+							<th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue', 'font-awesome-settings'); ?></label></th>
387 387
 							<td>
388 388
 								<input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/>
389 389
 								<input type="checkbox" name="wp-font-awesome-settings[dequeue]"
390
-								       value="1" <?php checked( $this->settings['dequeue'], '1' ); ?>
390
+								       value="1" <?php checked($this->settings['dequeue'], '1'); ?>
391 391
 								       id="wpfas-dequeue"/>
392
-								<span><?php _e( 'This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings' ); ?></span>
392
+								<span><?php _e('This will try to dequeue any other Font Awesome versions loaded by other sources if they are added with `font-awesome` or `fontawesome` in the name.', 'font-awesome-settings'); ?></span>
393 393
 							</td>
394 394
 						</tr>
395 395
 
@@ -414,12 +414,12 @@  discard block
 block discarded – undo
414 414
 		 *
415 415
 		 * @return string Either a valid version number or an empty string.
416 416
 		 */
417
-		public function validate_version_number( $version ) {
417
+		public function validate_version_number($version) {
418 418
 
419
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
419
+			if (version_compare($version, '0.0.1', '>=') >= 0) {
420 420
 				// valid
421 421
 			} else {
422
-				$version = '';// not validated
422
+				$version = ''; // not validated
423 423
 			}
424 424
 
425 425
 			return $version;
@@ -437,16 +437,16 @@  discard block
 block discarded – undo
437 437
 		public function get_latest_version($force_api = false) {
438 438
 			$latest_version = $this->latest;
439 439
 
440
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
440
+			$cache = get_transient('wp-font-awesome-settings-version');
441 441
 
442
-			if ( $cache === false || $force_api) { // its not set
442
+			if ($cache === false || $force_api) { // its not set
443 443
 				$api_ver = $this->get_latest_version_from_api();
444
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
444
+				if (version_compare($api_ver, $this->latest, '>=') >= 0) {
445 445
 					$latest_version = $api_ver;
446
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
446
+					set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS);
447 447
 				}
448
-			} elseif ( $this->validate_version_number( $cache ) ) {
449
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
448
+			} elseif ($this->validate_version_number($cache)) {
449
+				if (version_compare($cache, $this->latest, '>=') >= 0) {
450 450
 					$latest_version = $cache;
451 451
 				}
452 452
 			}
@@ -462,10 +462,10 @@  discard block
 block discarded – undo
462 462
 		 */
463 463
 		public function get_latest_version_from_api() {
464 464
 			$version  = "0";
465
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
466
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
467
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
468
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
465
+			$response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest");
466
+			if (!is_wp_error($response) && is_array($response)) {
467
+				$api_response = json_decode(wp_remote_retrieve_body($response), true);
468
+				if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) {
469 469
 					$version = $api_response['tag_name'];
470 470
 				}
471 471
 			}
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Spacing   +547 added lines, -547 removed lines patch added patch discarded remove patch
@@ -1,66 +1,66 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // MUST have WordPress.
3
-if ( !defined( 'WPINC' ) ) {
4
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
3
+if (!defined('WPINC')) {
4
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
5 5
 }
6 6
 
7
-function wpinv_get_option( $key = '', $default = false ) {
7
+function wpinv_get_option($key = '', $default = false) {
8 8
     global $wpinv_options;
9 9
 
10
-    $value = isset( $wpinv_options[ $key ] ) ? $wpinv_options[ $key ] : $default;
11
-    $value = apply_filters( 'wpinv_get_option', $value, $key, $default );
10
+    $value = isset($wpinv_options[$key]) ? $wpinv_options[$key] : $default;
11
+    $value = apply_filters('wpinv_get_option', $value, $key, $default);
12 12
 
13
-    return apply_filters( 'wpinv_get_option_' . $key, $value, $key, $default );
13
+    return apply_filters('wpinv_get_option_' . $key, $value, $key, $default);
14 14
 }
15 15
 
16
-function wpinv_update_option( $key = '', $value = false ) {
16
+function wpinv_update_option($key = '', $value = false) {
17 17
     // If no key, exit
18
-    if ( empty( $key ) ) {
18
+    if (empty($key)) {
19 19
         return false;
20 20
     }
21 21
 
22
-    if ( empty( $value ) ) {
23
-        $remove_option = wpinv_delete_option( $key );
22
+    if (empty($value)) {
23
+        $remove_option = wpinv_delete_option($key);
24 24
         return $remove_option;
25 25
     }
26 26
 
27 27
     // First let's grab the current settings
28
-    $options = get_option( 'wpinv_settings' );
28
+    $options = get_option('wpinv_settings');
29 29
 
30 30
     // Let other plugin alter the value
31
-    $value = apply_filters( 'wpinv_update_option', $value, $key );
31
+    $value = apply_filters('wpinv_update_option', $value, $key);
32 32
 
33 33
     // Next let's try to update the value
34
-    $options[ $key ] = $value;
35
-    $did_update = update_option( 'wpinv_settings', $options );
34
+    $options[$key] = $value;
35
+    $did_update = update_option('wpinv_settings', $options);
36 36
 
37 37
     // If it's updated, let's update the global variable
38
-    if ( $did_update ) {
38
+    if ($did_update) {
39 39
         global $wpinv_options;
40
-        $wpinv_options[ $key ] = $value;
40
+        $wpinv_options[$key] = $value;
41 41
     }
42 42
 
43 43
     return $did_update;
44 44
 }
45 45
 
46
-function wpinv_delete_option( $key = '' ) {
46
+function wpinv_delete_option($key = '') {
47 47
     // If no key, exit
48
-    if ( empty( $key ) ) {
48
+    if (empty($key)) {
49 49
         return false;
50 50
     }
51 51
 
52 52
     // First let's grab the current settings
53
-    $options = get_option( 'wpinv_settings' );
53
+    $options = get_option('wpinv_settings');
54 54
 
55 55
     // Next let's try to update the value
56
-    if( isset( $options[ $key ] ) ) {
57
-        unset( $options[ $key ] );
56
+    if (isset($options[$key])) {
57
+        unset($options[$key]);
58 58
     }
59 59
 
60
-    $did_update = update_option( 'wpinv_settings', $options );
60
+    $did_update = update_option('wpinv_settings', $options);
61 61
 
62 62
     // If it updated, let's update the global variable
63
-    if ( $did_update ){
63
+    if ($did_update) {
64 64
         global $wpinv_options;
65 65
         $wpinv_options = $options;
66 66
     }
@@ -69,37 +69,37 @@  discard block
 block discarded – undo
69 69
 }
70 70
 
71 71
 function wpinv_get_settings() {
72
-    $settings = get_option( 'wpinv_settings' );
72
+    $settings = get_option('wpinv_settings');
73 73
 
74
-    if ( empty( $settings ) ) {
74
+    if (empty($settings)) {
75 75
         // Update old settings with new single option
76
-        $general_settings   = is_array( get_option( 'wpinv_settings_general' ) )    ? get_option( 'wpinv_settings_general' )    : array();
77
-        $gateways_settings  = is_array( get_option( 'wpinv_settings_gateways' ) )   ? get_option( 'wpinv_settings_gateways' )   : array();
78
-        $email_settings     = is_array( get_option( 'wpinv_settings_emails' ) )     ? get_option( 'wpinv_settings_emails' )     : array();
79
-        $tax_settings       = is_array( get_option( 'wpinv_settings_taxes' ) )      ? get_option( 'wpinv_settings_taxes' )      : array();
80
-        $misc_settings      = is_array( get_option( 'wpinv_settings_misc' ) )       ? get_option( 'wpinv_settings_misc' )       : array();
81
-        $tool_settings      = is_array( get_option( 'wpinv_settings_tools' ) )      ? get_option( 'wpinv_settings_tools' )      : array();
76
+        $general_settings   = is_array(get_option('wpinv_settings_general')) ? get_option('wpinv_settings_general') : array();
77
+        $gateways_settings  = is_array(get_option('wpinv_settings_gateways')) ? get_option('wpinv_settings_gateways') : array();
78
+        $email_settings     = is_array(get_option('wpinv_settings_emails')) ? get_option('wpinv_settings_emails') : array();
79
+        $tax_settings       = is_array(get_option('wpinv_settings_taxes')) ? get_option('wpinv_settings_taxes') : array();
80
+        $misc_settings      = is_array(get_option('wpinv_settings_misc')) ? get_option('wpinv_settings_misc') : array();
81
+        $tool_settings      = is_array(get_option('wpinv_settings_tools')) ? get_option('wpinv_settings_tools') : array();
82 82
 
83
-        $settings = array_merge( $general_settings, $gateways_settings, $tax_settings, $tool_settings );
83
+        $settings = array_merge($general_settings, $gateways_settings, $tax_settings, $tool_settings);
84 84
 
85
-        update_option( 'wpinv_settings', $settings );
85
+        update_option('wpinv_settings', $settings);
86 86
 
87 87
     }
88
-    return apply_filters( 'wpinv_get_settings', $settings );
88
+    return apply_filters('wpinv_get_settings', $settings);
89 89
 }
90 90
 
91 91
 function wpinv_register_settings() {
92
-    if ( false == get_option( 'wpinv_settings' ) ) {
93
-        add_option( 'wpinv_settings' );
92
+    if (false == get_option('wpinv_settings')) {
93
+        add_option('wpinv_settings');
94 94
     }
95 95
     
96 96
     $register_settings = wpinv_get_registered_settings();
97 97
     
98
-    foreach ( $register_settings as $tab => $sections ) {
99
-        foreach ( $sections as $section => $settings) {
98
+    foreach ($register_settings as $tab => $sections) {
99
+        foreach ($sections as $section => $settings) {
100 100
             // Check for backwards compatibility
101
-            $section_tabs = wpinv_get_settings_tab_sections( $tab );
102
-            if ( ! is_array( $section_tabs ) || ! array_key_exists( $section, $section_tabs ) ) {
101
+            $section_tabs = wpinv_get_settings_tab_sections($tab);
102
+            if (!is_array($section_tabs) || !array_key_exists($section, $section_tabs)) {
103 103
                 $section = 'main';
104 104
                 $settings = $sections;
105 105
             }
@@ -111,41 +111,41 @@  discard block
 block discarded – undo
111 111
                 'wpinv_settings_' . $tab . '_' . $section
112 112
             );
113 113
 
114
-            foreach ( $settings as $option ) {
114
+            foreach ($settings as $option) {
115 115
                 // For backwards compatibility
116
-                if ( empty( $option['id'] ) ) {
116
+                if (empty($option['id'])) {
117 117
                     continue;
118 118
                 }
119 119
 
120
-                $name = isset( $option['name'] ) ? $option['name'] : '';
120
+                $name = isset($option['name']) ? $option['name'] : '';
121 121
 
122 122
                 add_settings_field(
123 123
                     'wpinv_settings[' . $option['id'] . ']',
124 124
                     $name,
125
-                    function_exists( 'wpinv_' . $option['type'] . '_callback' ) ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
125
+                    function_exists('wpinv_' . $option['type'] . '_callback') ? 'wpinv_' . $option['type'] . '_callback' : 'wpinv_missing_callback',
126 126
                     'wpinv_settings_' . $tab . '_' . $section,
127 127
                     'wpinv_settings_' . $tab . '_' . $section,
128 128
                     array(
129 129
                         'section'     => $section,
130
-                        'id'          => isset( $option['id'] )          ? $option['id']          : null,
131
-                        'desc'        => ! empty( $option['desc'] )      ? $option['desc']        : '',
132
-                        'name'        => isset( $option['name'] )        ? $option['name']        : null,
133
-                        'size'        => isset( $option['size'] )        ? $option['size']        : null,
134
-                        'options'     => isset( $option['options'] )     ? $option['options']     : '',
135
-                        'selected'    => isset( $option['selected'] )    ? $option['selected']    : null,
136
-                        'std'         => isset( $option['std'] )         ? $option['std']         : '',
137
-                        'min'         => isset( $option['min'] )         ? $option['min']         : null,
138
-                        'max'         => isset( $option['max'] )         ? $option['max']         : null,
139
-                        'step'        => isset( $option['step'] )        ? $option['step']        : null,
140
-                        'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null,
141
-                        'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true,
142
-                        'readonly'    => isset( $option['readonly'] )    ? $option['readonly']    : false,
143
-                        'faux'        => isset( $option['faux'] )        ? $option['faux']        : false,
144
-                        'onchange'    => !empty( $option['onchange'] )   ? $option['onchange']    : '',
145
-                        'custom'      => !empty( $option['custom'] )     ? $option['custom']      : '',
146
-                        'class'       =>  !empty( $option['class'] )     ? $option['class']      : '',
147
-                        'cols'        => !empty( $option['cols'] ) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
148
-                        'rows'        => !empty( $option['rows'] ) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
130
+                        'id'          => isset($option['id']) ? $option['id'] : null,
131
+                        'desc'        => !empty($option['desc']) ? $option['desc'] : '',
132
+                        'name'        => isset($option['name']) ? $option['name'] : null,
133
+                        'size'        => isset($option['size']) ? $option['size'] : null,
134
+                        'options'     => isset($option['options']) ? $option['options'] : '',
135
+                        'selected'    => isset($option['selected']) ? $option['selected'] : null,
136
+                        'std'         => isset($option['std']) ? $option['std'] : '',
137
+                        'min'         => isset($option['min']) ? $option['min'] : null,
138
+                        'max'         => isset($option['max']) ? $option['max'] : null,
139
+                        'step'        => isset($option['step']) ? $option['step'] : null,
140
+                        'placeholder' => isset($option['placeholder']) ? $option['placeholder'] : null,
141
+                        'allow_blank' => isset($option['allow_blank']) ? $option['allow_blank'] : true,
142
+                        'readonly'    => isset($option['readonly']) ? $option['readonly'] : false,
143
+                        'faux'        => isset($option['faux']) ? $option['faux'] : false,
144
+                        'onchange'    => !empty($option['onchange']) ? $option['onchange'] : '',
145
+                        'custom'      => !empty($option['custom']) ? $option['custom'] : '',
146
+                        'class'       =>  !empty($option['class']) ? $option['class'] : '',
147
+                        'cols'        => !empty($option['cols']) && (int)$option['cols'] > 0 ? (int)$option['cols'] : 50,
148
+                        'rows'        => !empty($option['rows']) && (int)$option['rows'] > 0 ? (int)$option['rows'] : 5,
149 149
                     )
150 150
                 );
151 151
             }
@@ -153,194 +153,194 @@  discard block
 block discarded – undo
153 153
     }
154 154
 
155 155
     // Creates our settings in the options table
156
-    register_setting( 'wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize' );
156
+    register_setting('wpinv_settings', 'wpinv_settings', 'wpinv_settings_sanitize');
157 157
 }
158
-add_action( 'admin_init', 'wpinv_register_settings' );
158
+add_action('admin_init', 'wpinv_register_settings');
159 159
 
160 160
 function wpinv_get_registered_settings() {
161
-    $pages = wpinv_get_pages( true );
161
+    $pages = wpinv_get_pages(true);
162 162
     
163 163
     $currencies = wpinv_get_currencies();
164 164
     
165 165
     $currency_code_options = array();
166
-    foreach ( $currencies as $code => $name ) {
167
-        $currency_code_options[ $code ] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol( $code ) . ')';
166
+    foreach ($currencies as $code => $name) {
167
+        $currency_code_options[$code] = $code . ' - ' . $name . ' (' . wpinv_currency_symbol($code) . ')';
168 168
     }
169 169
     
170 170
     $due_payment_options       = array();
171
-    $due_payment_options[0]    = __( 'Now', 'invoicing' );
172
-    for ( $i = 1; $i <= 30; $i++ ) {
171
+    $due_payment_options[0]    = __('Now', 'invoicing');
172
+    for ($i = 1; $i <= 30; $i++) {
173 173
         $due_payment_options[$i] = $i;
174 174
     }
175 175
     
176 176
     $invoice_number_padd_options = array();
177
-    for ( $i = 0; $i <= 20; $i++ ) {
177
+    for ($i = 0; $i <= 20; $i++) {
178 178
         $invoice_number_padd_options[$i] = $i;
179 179
     }
180 180
     
181 181
     $currency_symbol = wpinv_currency_symbol();
182 182
     
183 183
     $last_number = $reset_number = '';
184
-    if ( $last_invoice_number = get_option( 'wpinv_last_invoice_number' ) ) {
185
-        $last_invoice_number = is_numeric( $last_invoice_number ) ? $last_invoice_number : wpinv_clean_invoice_number( $last_invoice_number );
184
+    if ($last_invoice_number = get_option('wpinv_last_invoice_number')) {
185
+        $last_invoice_number = is_numeric($last_invoice_number) ? $last_invoice_number : wpinv_clean_invoice_number($last_invoice_number);
186 186
 
187
-        if ( !empty( $last_invoice_number ) ) {
188
-            $last_number = ' ' . wp_sprintf( __( "( Last Invoice's sequential number: <b>%s</b> )", 'invoicing' ), $last_invoice_number );
187
+        if (!empty($last_invoice_number)) {
188
+            $last_number = ' ' . wp_sprintf(__("( Last Invoice's sequential number: <b>%s</b> )", 'invoicing'), $last_invoice_number);
189 189
         }
190 190
 
191 191
         $nonce = wp_create_nonce('reset_invoice_count');
192
-        $reset_number = '<a href="'.add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)).'" class="btn button">'.__('Force Reset Sequence', 'invoicing' ). '</a>';
192
+        $reset_number = '<a href="' . add_query_arg(array('reset_invoice_count' => 1, '_nonce' => $nonce)) . '" class="btn button">' . __('Force Reset Sequence', 'invoicing') . '</a>';
193 193
     }
194 194
     
195 195
     $alert_wrapper_start = '<p style="color: #F00">';
196 196
     $alert_wrapper_close = '</p>';
197 197
     $wpinv_settings = array(
198
-        'general' => apply_filters( 'wpinv_settings_general',
198
+        'general' => apply_filters('wpinv_settings_general',
199 199
             array(
200 200
                 'main' => array(
201 201
                     'location_settings' => array(
202 202
                         'id'   => 'location_settings',
203
-                        'name' => '<h3>' . __( 'Default Location', 'invoicing' ) . '</h3>',
203
+                        'name' => '<h3>' . __('Default Location', 'invoicing') . '</h3>',
204 204
                         'desc' => '',
205 205
                         'type' => 'header',
206 206
                     ),
207 207
                     'default_country' => array(
208 208
                         'id'      => 'default_country',
209
-                        'name'    => __( 'Default Country', 'invoicing' ),
210
-                        'desc'    => __( 'Where does your store operate from?', 'invoicing' ),
209
+                        'name'    => __('Default Country', 'invoicing'),
210
+                        'desc'    => __('Where does your store operate from?', 'invoicing'),
211 211
                         'type'    => 'select',
212 212
                         'options' => wpinv_get_country_list(),
213 213
                         'std'     => 'GB',
214
-                        'placeholder' => __( 'Select a country', 'invoicing' ),
214
+                        'placeholder' => __('Select a country', 'invoicing'),
215 215
                     ),
216 216
                     'default_state' => array(
217 217
                         'id'      => 'default_state',
218
-                        'name'    => __( 'Default State / Province', 'invoicing' ),
219
-                        'desc'    => __( 'What state / province does your store operate from?', 'invoicing' ),
218
+                        'name'    => __('Default State / Province', 'invoicing'),
219
+                        'desc'    => __('What state / province does your store operate from?', 'invoicing'),
220 220
                         'type'    => 'country_states',
221
-                        'placeholder' => __( 'Select a state', 'invoicing' ),
221
+                        'placeholder' => __('Select a state', 'invoicing'),
222 222
                     ),
223 223
                     'store_name' => array(
224 224
                         'id'   => 'store_name',
225
-                        'name' => __( 'Store Name', 'invoicing' ),
226
-                        'desc' => __( 'Store name to print on invoices.', 'invoicing' ),
225
+                        'name' => __('Store Name', 'invoicing'),
226
+                        'desc' => __('Store name to print on invoices.', 'invoicing'),
227 227
                         'std'     => get_option('blogname'),
228 228
                         'type' => 'text',
229 229
                     ),
230 230
                     'logo' => array(
231 231
                         'id'   => 'logo',
232
-                        'name' => __( 'Logo URL', 'invoicing' ),
233
-                        'desc' => __( 'Store logo to print on invoices.', 'invoicing' ),
232
+                        'name' => __('Logo URL', 'invoicing'),
233
+                        'desc' => __('Store logo to print on invoices.', 'invoicing'),
234 234
                         'type' => 'text',
235 235
                     ),
236 236
                     'store_address' => array(
237 237
                         'id'   => 'store_address',
238
-                        'name' => __( 'Store Address', 'invoicing' ),
239
-                        'desc' => __( 'Enter the store address to display on invoice', 'invoicing' ),
238
+                        'name' => __('Store Address', 'invoicing'),
239
+                        'desc' => __('Enter the store address to display on invoice', 'invoicing'),
240 240
                         'type' => 'textarea',
241 241
                     ),
242 242
                     'page_settings' => array(
243 243
                         'id'   => 'page_settings',
244
-                        'name' => '<h3>' . __( 'Page Settings', 'invoicing' ) . '</h3>',
244
+                        'name' => '<h3>' . __('Page Settings', 'invoicing') . '</h3>',
245 245
                         'desc' => '',
246 246
                         'type' => 'header',
247 247
                     ),
248 248
                     'checkout_page' => array(
249 249
                         'id'          => 'checkout_page',
250
-                        'name'        => __( 'Checkout Page', 'invoicing' ),
251
-                        'desc'        => __( 'This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing' ),
250
+                        'name'        => __('Checkout Page', 'invoicing'),
251
+                        'desc'        => __('This is the checkout page where buyers will complete their payments. The <b>[wpinv_checkout]</b> short code must be on this page.', 'invoicing'),
252 252
                         'type'        => 'select',
253 253
                         'options'     => $pages,
254
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
254
+                        'placeholder' => __('Select a page', 'invoicing'),
255 255
                     ),
256 256
                     'tandc_page' => array(
257 257
                         'id'          => 'tandc_page',
258
-                        'name'        => __( 'Terms & Conditions', 'invoicing' ),
259
-                        'desc'        => __( 'If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing' ),
258
+                        'name'        => __('Terms & Conditions', 'invoicing'),
259
+                        'desc'        => __('If you select a "Terms & Conditions" page here the customer will be asked to accept them on checkout.', 'invoicing'),
260 260
                         'type'        => 'select',
261
-                        'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
261
+                        'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
262 262
                         'chosen'      => true,
263
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
263
+                        'placeholder' => __('Select a page', 'invoicing'),
264 264
                     ),
265 265
                     'success_page' => array(
266 266
                         'id'          => 'success_page',
267
-                        'name'        => __( 'Success Page', 'invoicing' ),
268
-                        'desc'        => __( 'This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing' ),
267
+                        'name'        => __('Success Page', 'invoicing'),
268
+                        'desc'        => __('This is the page buyers are sent to after completing their payments. The <b>[wpinv_receipt]</b> short code should be on this page.', 'invoicing'),
269 269
                         'type'        => 'select',
270 270
                         'options'     => $pages,
271
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
271
+                        'placeholder' => __('Select a page', 'invoicing'),
272 272
                     ),
273 273
                     'failure_page' => array(
274 274
                         'id'          => 'failure_page',
275
-                        'name'        => __( 'Failed Transaction Page', 'invoicing' ),
276
-                        'desc'        => __( 'This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing' ),
275
+                        'name'        => __('Failed Transaction Page', 'invoicing'),
276
+                        'desc'        => __('This is the page buyers are sent to if their transaction is cancelled or fails.', 'invoicing'),
277 277
                         'type'        => 'select',
278 278
                         'options'     => $pages,
279
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
279
+                        'placeholder' => __('Select a page', 'invoicing'),
280 280
                     ),
281 281
                     'invoice_history_page' => array(
282 282
                         'id'          => 'invoice_history_page',
283
-                        'name'        => __( 'Invoice History Page', 'invoicing' ),
284
-                        'desc'        => __( 'This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing' ),
283
+                        'name'        => __('Invoice History Page', 'invoicing'),
284
+                        'desc'        => __('This page shows an invoice history for the current user. The <b>[wpinv_history]</b> short code should be on this page.', 'invoicing'),
285 285
                         'type'        => 'select',
286 286
                         'options'     => $pages,
287
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
287
+                        'placeholder' => __('Select a page', 'invoicing'),
288 288
                     ),
289 289
                     'invoice_subscription_page' => array(
290 290
                         'id'          => 'invoice_subscription_page',
291
-                        'name'        => __( 'Invoice Subscriptions Page', 'invoicing' ),
292
-                        'desc'        => __( 'This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing' ),
291
+                        'name'        => __('Invoice Subscriptions Page', 'invoicing'),
292
+                        'desc'        => __('This page shows subscriptions history for the current user. The <b>[wpinv_subscriptions]</b> short code should be on this page.', 'invoicing'),
293 293
                         'type'        => 'select',
294 294
                         'options'     => $pages,
295
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
295
+                        'placeholder' => __('Select a page', 'invoicing'),
296 296
                     ),
297 297
                 ),
298 298
                 'currency_section' => array(
299 299
                     'currency_settings' => array(
300 300
                         'id'   => 'currency_settings',
301
-                        'name' => '<h3>' . __( 'Currency Settings', 'invoicing' ) . '</h3>',
301
+                        'name' => '<h3>' . __('Currency Settings', 'invoicing') . '</h3>',
302 302
                         'desc' => '',
303 303
                         'type' => 'header',
304 304
                     ),
305 305
                     'currency' => array(
306 306
                         'id'      => 'currency',
307
-                        'name'    => __( 'Currency', 'invoicing' ),
308
-                        'desc'    => __( 'Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing' ),
307
+                        'name'    => __('Currency', 'invoicing'),
308
+                        'desc'    => __('Choose your currency. Note that some payment gateways have currency restrictions.', 'invoicing'),
309 309
                         'type'    => 'select',
310 310
                         'options' => $currency_code_options,
311 311
                     ),
312 312
                     'currency_position' => array(
313 313
                         'id'      => 'currency_position',
314
-                        'name'    => __( 'Currency Position', 'invoicing' ),
315
-                        'desc'    => __( 'Choose the location of the currency sign.', 'invoicing' ),
314
+                        'name'    => __('Currency Position', 'invoicing'),
315
+                        'desc'    => __('Choose the location of the currency sign.', 'invoicing'),
316 316
                         'type'    => 'select',
317 317
                         'options'  => array(
318
-                            'left'        => __( 'Left', 'invoicing' ) . ' (' . $currency_symbol . wpinv_format_amount( '99.99' ) . ')',
319
-                            'right'       => __( 'Right', 'invoicing' ) . ' ('. wpinv_format_amount( '99.99' ) . $currency_symbol . ')',
320
-                            'left_space'  => __( 'Left with space', 'invoicing' ) . ' (' . $currency_symbol . ' ' . wpinv_format_amount( '99.99' ) . ')',
321
-                            'right_space' => __( 'Right with space', 'invoicing' ) . ' (' . wpinv_format_amount( '99.99' ) . ' ' . $currency_symbol . ')'
318
+                            'left'        => __('Left', 'invoicing') . ' (' . $currency_symbol . wpinv_format_amount('99.99') . ')',
319
+                            'right'       => __('Right', 'invoicing') . ' (' . wpinv_format_amount('99.99') . $currency_symbol . ')',
320
+                            'left_space'  => __('Left with space', 'invoicing') . ' (' . $currency_symbol . ' ' . wpinv_format_amount('99.99') . ')',
321
+                            'right_space' => __('Right with space', 'invoicing') . ' (' . wpinv_format_amount('99.99') . ' ' . $currency_symbol . ')'
322 322
                         )
323 323
                     ),
324 324
                     'thousands_separator' => array(
325 325
                         'id'   => 'thousands_separator',
326
-                        'name' => __( 'Thousands Separator', 'invoicing' ),
327
-                        'desc' => __( 'The symbol (usually , or .) to separate thousands', 'invoicing' ),
326
+                        'name' => __('Thousands Separator', 'invoicing'),
327
+                        'desc' => __('The symbol (usually , or .) to separate thousands', 'invoicing'),
328 328
                         'type' => 'text',
329 329
                         'size' => 'small',
330 330
                         'std'  => ',',
331 331
                     ),
332 332
                     'decimal_separator' => array(
333 333
                         'id'   => 'decimal_separator',
334
-                        'name' => __( 'Decimal Separator', 'invoicing' ),
335
-                        'desc' => __( 'The symbol (usually , or .) to separate decimal points', 'invoicing' ),
334
+                        'name' => __('Decimal Separator', 'invoicing'),
335
+                        'desc' => __('The symbol (usually , or .) to separate decimal points', 'invoicing'),
336 336
                         'type' => 'text',
337 337
                         'size' => 'small',
338 338
                         'std'  => '.',
339 339
                     ),
340 340
                     'decimals' => array(
341 341
                         'id'   => 'decimals',
342
-                        'name' => __( 'Number of Decimals', 'invoicing' ),
343
-                        'desc' => __( 'This sets the number of decimal points shown in displayed prices.', 'invoicing' ),
342
+                        'name' => __('Number of Decimals', 'invoicing'),
343
+                        'desc' => __('This sets the number of decimal points shown in displayed prices.', 'invoicing'),
344 344
                         'type' => 'number',
345 345
                         'size' => 'small',
346 346
                         'std'  => '2',
@@ -352,29 +352,29 @@  discard block
 block discarded – undo
352 352
                 'labels' => array(
353 353
                     'labels' => array(
354 354
                         'id'   => 'labels_settings',
355
-                        'name' => '<h3>' . __( 'Invoice Labels', 'invoicing' ) . '</h3>',
355
+                        'name' => '<h3>' . __('Invoice Labels', 'invoicing') . '</h3>',
356 356
                         'desc' => '',
357 357
                         'type' => 'header',
358 358
                     ),
359 359
                     'vat_name' => array(
360 360
                         'id' => 'vat_name',
361
-                        'name' => __( 'VAT Name', 'invoicing' ),
362
-                        'desc' => __( 'Enter the VAT name', 'invoicing' ),
361
+                        'name' => __('VAT Name', 'invoicing'),
362
+                        'desc' => __('Enter the VAT name', 'invoicing'),
363 363
                         'type' => 'text',
364 364
                         'size' => 'regular',
365 365
                         'std' => 'VAT'
366 366
                     ),
367 367
                     'vat_invoice_notice_label' => array(
368 368
                         'id' => 'vat_invoice_notice_label',
369
-                        'name' => __( 'Invoice Notice Label', 'invoicing' ),
370
-                        'desc' => __( 'Use this to add an invoice notice section (label) to your invoices', 'invoicing' ),
369
+                        'name' => __('Invoice Notice Label', 'invoicing'),
370
+                        'desc' => __('Use this to add an invoice notice section (label) to your invoices', 'invoicing'),
371 371
                         'type' => 'text',
372 372
                         'size' => 'regular',
373 373
                     ),
374 374
                     'vat_invoice_notice' => array(
375 375
                         'id' => 'vat_invoice_notice',
376
-                        'name' => __( 'Invoice notice', 'invoicing' ),
377
-                        'desc' =>   __( 'Use this to add an invoice notice section (description) to your invoices', 'invoicing' ),
376
+                        'name' => __('Invoice notice', 'invoicing'),
377
+                        'desc' =>   __('Use this to add an invoice notice section (description) to your invoices', 'invoicing'),
378 378
                         'type' => 'text',
379 379
                         'size' => 'regular',
380 380
                     )
@@ -386,22 +386,22 @@  discard block
 block discarded – undo
386 386
                 'main' => array(
387 387
                     'gateway_settings' => array(
388 388
                         'id'   => 'api_header',
389
-                        'name' => '<h3>' . __( 'Gateway Settings', 'invoicing' ) . '</h3>',
389
+                        'name' => '<h3>' . __('Gateway Settings', 'invoicing') . '</h3>',
390 390
                         'desc' => '',
391 391
                         'type' => 'header',
392 392
                     ),
393 393
                     'gateways' => array(
394 394
                         'id'      => 'gateways',
395
-                        'name'    => __( 'Payment Gateways', 'invoicing' ),
396
-                        'desc'    => __( 'Choose the payment gateways you want to enable.', 'invoicing' ),
395
+                        'name'    => __('Payment Gateways', 'invoicing'),
396
+                        'desc'    => __('Choose the payment gateways you want to enable.', 'invoicing'),
397 397
                         'type'    => 'gateways',
398 398
                         'std'     => array('manual'=>1),
399 399
                         'options' => wpinv_get_payment_gateways(),
400 400
                     ),
401 401
                     'default_gateway' => array(
402 402
                         'id'      => 'default_gateway',
403
-                        'name'    => __( 'Default Gateway', 'invoicing' ),
404
-                        'desc'    => __( 'This gateway will be loaded automatically with the checkout page.', 'invoicing' ),
403
+                        'name'    => __('Default Gateway', 'invoicing'),
404
+                        'desc'    => __('This gateway will be loaded automatically with the checkout page.', 'invoicing'),
405 405
                         'type'    => 'gateway_select',
406 406
                         'std'     => 'manual',
407 407
                         'options' => wpinv_get_payment_gateways(),
@@ -415,19 +415,19 @@  discard block
 block discarded – undo
415 415
                 'main' => array(
416 416
                     'tax_settings' => array(
417 417
                         'id'   => 'tax_settings',
418
-                        'name' => '<h3>' . __( 'Tax Settings', 'invoicing' ) . '</h3>',
418
+                        'name' => '<h3>' . __('Tax Settings', 'invoicing') . '</h3>',
419 419
                         'type' => 'header',
420 420
                     ),
421 421
                     'enable_taxes' => array(
422 422
                         'id'   => 'enable_taxes',
423
-                        'name' => __( 'Enable Taxes', 'invoicing' ),
424
-                        'desc' => __( 'Check this to enable taxes on invoices.', 'invoicing' ),
423
+                        'name' => __('Enable Taxes', 'invoicing'),
424
+                        'desc' => __('Check this to enable taxes on invoices.', 'invoicing'),
425 425
                         'type' => 'checkbox',
426 426
                     ),
427 427
                     'tax_rate' => array(
428 428
                         'id'   => 'tax_rate',
429
-                        'name' => __( 'Fallback Tax Rate', 'invoicing' ),
430
-                        'desc' => __( 'Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing' ),
429
+                        'name' => __('Fallback Tax Rate', 'invoicing'),
430
+                        'desc' => __('Enter a percentage, such as 6.5. Customers not in a specific rate will be charged this rate.', 'invoicing'),
431 431
                         'type' => 'number',
432 432
                         'size' => 'small',
433 433
                         'min'  => '0',
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
                 'rates' => array(
440 440
                     'tax_rates' => array(
441 441
                         'id'   => 'tax_rates',
442
-                        'name' => '<h3>' . __( 'Tax Rates', 'invoicing' ) . '</h3>',
443
-                        'desc' => __( 'Enter tax rates for specific regions.', 'invoicing' ),
442
+                        'name' => '<h3>' . __('Tax Rates', 'invoicing') . '</h3>',
443
+                        'desc' => __('Enter tax rates for specific regions.', 'invoicing'),
444 444
                         'type' => 'tax_rates',
445 445
                     ),
446 446
                 )
@@ -452,61 +452,61 @@  discard block
 block discarded – undo
452 452
                 'main' => array(
453 453
                     'email_settings_header' => array(
454 454
                         'id'   => 'email_settings_header',
455
-                        'name' => '<h3>' . __( 'Email Sender Options', 'invoicing' ) . '</h3>',
455
+                        'name' => '<h3>' . __('Email Sender Options', 'invoicing') . '</h3>',
456 456
                         'type' => 'header',
457 457
                     ),
458 458
                     'email_from_name' => array(
459 459
                         'id'   => 'email_from_name',
460
-                        'name' => __( 'From Name', 'invoicing' ),
461
-                        'desc' => __( 'Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing' ),
462
-                        'std' => esc_attr( get_bloginfo( 'name', 'display' ) ),
460
+                        'name' => __('From Name', 'invoicing'),
461
+                        'desc' => __('Enter the sender\'s name appears in outgoing invoice emails. This should be your site name.', 'invoicing'),
462
+                        'std' => esc_attr(get_bloginfo('name', 'display')),
463 463
                         'type' => 'text',
464 464
                     ),
465 465
                     'email_from' => array(
466 466
                         'id'   => 'email_from',
467
-                        'name' => __( 'From Email', 'invoicing' ),
468
-                        'desc' => sprintf (__( 'Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing' ), $alert_wrapper_start, $alert_wrapper_close),
469
-                        'std' => get_option( 'admin_email' ),
467
+                        'name' => __('From Email', 'invoicing'),
468
+                        'desc' => sprintf(__('Email address to send invoice emails from. This will act as the "from" and "reply-to" address. %s If emails are not being sent it may be that your hosting prevents emails being sent if the email domains do not match.%s', 'invoicing'), $alert_wrapper_start, $alert_wrapper_close),
469
+                        'std' => get_option('admin_email'),
470 470
                         'type' => 'text',
471 471
                     ),
472 472
                     'overdue_settings_header' => array(
473 473
                         'id'   => 'overdue_settings_header',
474
-                        'name' => '<h3>' . __( 'Due Date Settings', 'invoicing' ) . '</h3>',
474
+                        'name' => '<h3>' . __('Due Date Settings', 'invoicing') . '</h3>',
475 475
                         'type' => 'header',
476 476
                     ),
477 477
                     'overdue_active' => array(
478 478
                         'id'   => 'overdue_active',
479
-                        'name' => __( 'Enable Due Date', 'invoicing' ),
480
-                        'desc' => __( 'Check this to enable due date option for invoices.', 'invoicing' ),
479
+                        'name' => __('Enable Due Date', 'invoicing'),
480
+                        'desc' => __('Check this to enable due date option for invoices.', 'invoicing'),
481 481
                         'type' => 'checkbox',
482 482
                         'std'  => false,
483 483
                     ),
484 484
                     'overdue_days' => array(
485 485
                         'id'          => 'overdue_days',
486
-                        'name'        => __( 'Default Due Date', 'invoicing' ),
487
-                        'desc'        => __( 'Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing' ),
486
+                        'name'        => __('Default Due Date', 'invoicing'),
487
+                        'desc'        => __('Number of days each Invoice is due after the created date. This will automatically set the date in the "Due Date" field. Can be overridden on individual Invoices.', 'invoicing'),
488 488
                         'type'        => 'select',
489 489
                         'options'     => $due_payment_options,
490 490
                         'std'         => 0,
491
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
491
+                        'placeholder' => __('Select a page', 'invoicing'),
492 492
                     ),
493 493
                     'email_template_header' => array(
494 494
                         'id'   => 'email_template_header',
495
-                        'name' => '<h3>' . __( 'Email Template', 'invoicing' ) . '</h3>',
495
+                        'name' => '<h3>' . __('Email Template', 'invoicing') . '</h3>',
496 496
                         'type' => 'header',
497 497
                     ),
498 498
                     'email_header_image' => array(
499 499
                         'id'   => 'email_header_image',
500
-                        'name' => __( 'Header Image', 'invoicing' ),
501
-                        'desc' => __( 'URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing' ),
500
+                        'name' => __('Header Image', 'invoicing'),
501
+                        'desc' => __('URL to an image you want to show in the email header. Upload images using the media uploader (Admin > Media).', 'invoicing'),
502 502
                         'std' => '',
503 503
                         'type' => 'text',
504 504
                     ),
505 505
                     'email_footer_text' => array(
506 506
                         'id'   => 'email_footer_text',
507
-                        'name' => __( 'Footer Text', 'invoicing' ),
508
-                        'desc' => __( 'The text to appear in the footer of all invoice emails.', 'invoicing' ),
509
-                        'std' => get_bloginfo( 'name', 'display' ) . ' - ' . __( 'Powered by GeoDirectory', 'invoicing' ),
507
+                        'name' => __('Footer Text', 'invoicing'),
508
+                        'desc' => __('The text to appear in the footer of all invoice emails.', 'invoicing'),
509
+                        'std' => get_bloginfo('name', 'display') . ' - ' . __('Powered by GeoDirectory', 'invoicing'),
510 510
                         'type' => 'textarea',
511 511
                         'class' => 'regular-text',
512 512
                         'rows' => 2,
@@ -514,29 +514,29 @@  discard block
 block discarded – undo
514 514
                     ),
515 515
                     'email_base_color' => array(
516 516
                         'id'   => 'email_base_color',
517
-                        'name' => __( 'Base Color', 'invoicing' ),
518
-                        'desc' => __( 'The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing' ),
517
+                        'name' => __('Base Color', 'invoicing'),
518
+                        'desc' => __('The base color for invoice email template. Default <code>#557da2</code>.', 'invoicing'),
519 519
                         'std' => '#557da2',
520 520
                         'type' => 'color',
521 521
                     ),
522 522
                     'email_background_color' => array(
523 523
                         'id'   => 'email_background_color',
524
-                        'name' => __( 'Background Color', 'invoicing' ),
525
-                        'desc' => __( 'The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing' ),
524
+                        'name' => __('Background Color', 'invoicing'),
525
+                        'desc' => __('The background color of email template. Default <code>#f5f5f5</code>.', 'invoicing'),
526 526
                         'std' => '#f5f5f5',
527 527
                         'type' => 'color',
528 528
                     ),
529 529
                     'email_body_background_color' => array(
530 530
                         'id'   => 'email_body_background_color',
531
-                        'name' => __( 'Body Background Color', 'invoicing' ),
532
-                        'desc' => __( 'The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing' ),
531
+                        'name' => __('Body Background Color', 'invoicing'),
532
+                        'desc' => __('The main body background color of email template. Default <code>#fdfdfd</code>.', 'invoicing'),
533 533
                         'std' => '#fdfdfd',
534 534
                         'type' => 'color',
535 535
                     ),
536 536
                     'email_text_color' => array(
537 537
                         'id'   => 'email_text_color',
538
-                        'name' => __( 'Body Text Color', 'invoicing' ),
539
-                        'desc' => __( 'The main body text color. Default <code>#505050</code>.', 'invoicing' ),
538
+                        'name' => __('Body Text Color', 'invoicing'),
539
+                        'desc' => __('The main body text color. Default <code>#505050</code>.', 'invoicing'),
540 540
                         'std' => '#505050',
541 541
                         'type' => 'color',
542 542
                     ),
@@ -555,26 +555,26 @@  discard block
 block discarded – undo
555 555
                 'main' => array(
556 556
                     'invoicing_privacy_policy_settings' => array(
557 557
                         'id'   => 'invoicing_privacy_policy_settings',
558
-                        'name' => '<h3>' . __( 'Privacy Policy', 'invoicing' ) . '</h3>',
558
+                        'name' => '<h3>' . __('Privacy Policy', 'invoicing') . '</h3>',
559 559
                         'type' => 'header',
560 560
                     ),
561 561
                     'privacy_page' => array(
562 562
                         'id'          => 'privacy_page',
563
-                        'name'        => __( 'Privacy Page', 'invoicing' ),
564
-                        'desc'        => __( 'If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing' ),
563
+                        'name'        => __('Privacy Page', 'invoicing'),
564
+                        'desc'        => __('If no privacy policy page set in Settings->Privacy default settings, this page will be used on checkout page.', 'invoicing'),
565 565
                         'type'        => 'select',
566
-                        'options'     => wpinv_get_pages( true,  __( 'Select a page', 'invoicing' )),
566
+                        'options'     => wpinv_get_pages(true, __('Select a page', 'invoicing')),
567 567
                         'chosen'      => true,
568
-                        'placeholder' => __( 'Select a page', 'invoicing' ),
568
+                        'placeholder' => __('Select a page', 'invoicing'),
569 569
                     ),
570 570
                     'invoicing_privacy_checkout_message' => array(
571 571
                         'id' => 'invoicing_privacy_checkout_message',
572
-                        'name' => __( 'Checkout privacy policy', 'invoicing' ),
573
-                        'desc' => __( 'Optionally add privacy policy message which will display on checkout page.', 'invoicing' ),
572
+                        'name' => __('Checkout privacy policy', 'invoicing'),
573
+                        'desc' => __('Optionally add privacy policy message which will display on checkout page.', 'invoicing'),
574 574
                         'type' => 'textarea',
575 575
                         'class'=> 'regular-text',
576 576
                         'rows' => 4,
577
-                        'std'  => sprintf( __( 'Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing' ), '[wpinv_privacy_policy]' ),
577
+                        'std'  => sprintf(__('Your personal data will be used to process your invoice, payment and for other purposes described in our %s.', 'invoicing'), '[wpinv_privacy_policy]'),
578 578
                     ),
579 579
                 ),
580 580
             )
@@ -585,19 +585,19 @@  discard block
 block discarded – undo
585 585
                 'main' => array(
586 586
                     'invoice_number_format_settings' => array(
587 587
                         'id'   => 'invoice_number_format_settings',
588
-                        'name' => '<h3>' . __( 'Invoice Number', 'invoicing' ) . '</h3>',
588
+                        'name' => '<h3>' . __('Invoice Number', 'invoicing') . '</h3>',
589 589
                         'type' => 'header',
590 590
                     ),
591 591
                     'sequential_invoice_number' => array(
592 592
                         'id'   => 'sequential_invoice_number',
593
-                        'name' => __( 'Sequential Invoice Numbers', 'invoicing' ),
594
-                        'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing' ) . $reset_number,
593
+                        'name' => __('Sequential Invoice Numbers', 'invoicing'),
594
+                        'desc' => __('Check this box to enable sequential invoice numbers.', 'invoicing') . $reset_number,
595 595
                         'type' => 'checkbox',
596 596
                     ),
597 597
                     'invoice_sequence_start' => array(
598 598
                         'id'   => 'invoice_sequence_start',
599
-                        'name' => __( 'Sequential Starting Number', 'invoicing' ),
600
-                        'desc' => __( 'The number at which the invoice number sequence should begin.', 'invoicing' ) . $last_number,
599
+                        'name' => __('Sequential Starting Number', 'invoicing'),
600
+                        'desc' => __('The number at which the invoice number sequence should begin.', 'invoicing') . $last_number,
601 601
                         'type' => 'number',
602 602
                         'size' => 'small',
603 603
                         'std'  => '1',
@@ -605,16 +605,16 @@  discard block
 block discarded – undo
605 605
                     ),
606 606
                     'invoice_number_padd' => array(
607 607
                         'id'      => 'invoice_number_padd',
608
-                        'name'    => __( 'Minimum Digits', 'invoicing' ),
609
-                        'desc'    => __( 'If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing' ),
608
+                        'name'    => __('Minimum Digits', 'invoicing'),
609
+                        'desc'    => __('If the invoice number has less digits than this number, it is left padded with 0s. Ex: invoice number 108 will padded to 00108 if digits set to 5. The default 0 means no padding.', 'invoicing'),
610 610
                         'type'    => 'select',
611 611
                         'options' => $invoice_number_padd_options,
612 612
                         'std'     => 5,
613 613
                     ),
614 614
                     'invoice_number_prefix' => array(
615 615
                         'id' => 'invoice_number_prefix',
616
-                        'name' => __( 'Invoice Number Prefix', 'invoicing' ),
617
-                        'desc' => __( 'Prefix for all invoice numbers. Ex: WPINV-', 'invoicing' ),
616
+                        'name' => __('Invoice Number Prefix', 'invoicing'),
617
+                        'desc' => __('Prefix for all invoice numbers. Ex: WPINV-', 'invoicing'),
618 618
                         'type' => 'text',
619 619
                         'size' => 'regular',
620 620
                         'std' => 'WPINV-',
@@ -622,32 +622,32 @@  discard block
 block discarded – undo
622 622
                     ),
623 623
                     'invoice_number_postfix' => array(
624 624
                         'id' => 'invoice_number_postfix',
625
-                        'name' => __( 'Invoice Number Postfix', 'invoicing' ),
626
-                        'desc' => __( 'Postfix for all invoice numbers.', 'invoicing' ),
625
+                        'name' => __('Invoice Number Postfix', 'invoicing'),
626
+                        'desc' => __('Postfix for all invoice numbers.', 'invoicing'),
627 627
                         'type' => 'text',
628 628
                         'size' => 'regular',
629 629
                         'std' => ''
630 630
                     ),
631 631
                     'checkout_settings' => array(
632 632
                         'id'   => 'checkout_settings',
633
-                        'name' => '<h3>' . __( 'Checkout Settings', 'invoicing' ) . '</h3>',
633
+                        'name' => '<h3>' . __('Checkout Settings', 'invoicing') . '</h3>',
634 634
                         'type' => 'header',
635 635
                     ),
636 636
                     'login_to_checkout' => array(
637 637
                         'id'   => 'login_to_checkout',
638
-                        'name' => __( 'Require Login To Checkout', 'invoicing' ),
639
-                        'desc' => __( 'If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing' ),
638
+                        'name' => __('Require Login To Checkout', 'invoicing'),
639
+                        'desc' => __('If ticked then user needs to be logged in to view or pay invoice, can only view or pay their own invoice. If unticked then anyone can view or pay the invoice.', 'invoicing'),
640 640
                         'type' => 'checkbox',
641 641
                     ),
642 642
                     'uninstall_settings' => array(
643 643
                         'id'   => 'uninstall_settings',
644
-                        'name' => '<h3>' . __( 'Uninstall Settings', 'invoicing' ) . '</h3>',
644
+                        'name' => '<h3>' . __('Uninstall Settings', 'invoicing') . '</h3>',
645 645
                         'type' => 'header',
646 646
                     ),
647 647
                     'remove_data_on_unistall' => array(
648 648
                         'id'   => 'remove_data_on_unistall',
649
-                        'name' => __( 'Remove Data on Uninstall?', 'invoicing' ),
650
-                        'desc' => __( 'Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing' ),
649
+                        'name' => __('Remove Data on Uninstall?', 'invoicing'),
650
+                        'desc' => __('Check this box if you would like Invoicing plugin to completely remove all of its data when the plugin is deleted/uninstalled.', 'invoicing'),
651 651
                         'type' => 'checkbox',
652 652
                         'std'  => ''
653 653
                     ),
@@ -655,80 +655,80 @@  discard block
 block discarded – undo
655 655
                 'fields' => array(
656 656
                     'fields_settings' => array(
657 657
                         'id'   => 'fields_settings',
658
-                        'name' => '<h3>' . __( 'Address Fields', 'invoicing' ) . '</h3>',
659
-                        'desc' => __( 'Tick fields which are mandatory in invoice address fields.', 'invoicing' ),
658
+                        'name' => '<h3>' . __('Address Fields', 'invoicing') . '</h3>',
659
+                        'desc' => __('Tick fields which are mandatory in invoice address fields.', 'invoicing'),
660 660
                         'type' => 'header',
661 661
                     ),
662 662
                     'fname_mandatory' => array(
663 663
                         'id'   => 'fname_mandatory',
664
-                        'name' => __( 'First Name', 'invoicing' ),
664
+                        'name' => __('First Name', 'invoicing'),
665 665
                         'type' => 'checkbox',
666 666
                         'std'  => true,
667 667
                     ),
668 668
                     'lname_mandatory' => array(
669 669
                         'id'   => 'lname_mandatory',
670
-                        'name' => __( 'Last Name', 'invoicing' ),
670
+                        'name' => __('Last Name', 'invoicing'),
671 671
                         'type' => 'checkbox',
672 672
                         'std'  => true,
673 673
                     ),
674 674
                     'address_mandatory' => array(
675 675
                         'id'   => 'address_mandatory',
676
-                        'name' => __( 'Address', 'invoicing' ),
676
+                        'name' => __('Address', 'invoicing'),
677 677
                         'type' => 'checkbox',
678 678
                         'std'  => true,
679 679
                     ),
680 680
                     'city_mandatory' => array(
681 681
                         'id'   => 'city_mandatory',
682
-                        'name' => __( 'City', 'invoicing' ),
682
+                        'name' => __('City', 'invoicing'),
683 683
                         'type' => 'checkbox',
684 684
                         'std'  => true,
685 685
                     ),
686 686
                     'country_mandatory' => array(
687 687
                         'id'   => 'country_mandatory',
688
-                        'name' => __( 'Country', 'invoicing' ),
688
+                        'name' => __('Country', 'invoicing'),
689 689
                         'type' => 'checkbox',
690 690
                         'std'  => true,
691 691
                     ),
692 692
                     'state_mandatory' => array(
693 693
                         'id'   => 'state_mandatory',
694
-                        'name' => __( 'State / Province', 'invoicing' ),
694
+                        'name' => __('State / Province', 'invoicing'),
695 695
                         'type' => 'checkbox',
696 696
                         'std'  => true,
697 697
                     ),
698 698
                     'zip_mandatory' => array(
699 699
                         'id'   => 'zip_mandatory',
700
-                        'name' => __( 'ZIP / Postcode', 'invoicing' ),
700
+                        'name' => __('ZIP / Postcode', 'invoicing'),
701 701
                         'type' => 'checkbox',
702 702
                         'std'  => true,
703 703
                     ),
704 704
                     'phone_mandatory' => array(
705 705
                         'id'   => 'phone_mandatory',
706
-                        'name' => __( 'Phone Number', 'invoicing' ),
706
+                        'name' => __('Phone Number', 'invoicing'),
707 707
                         'type' => 'checkbox',
708 708
                         'std'  => true,
709 709
                     ),
710 710
                     'force_show_company' => array(
711 711
                         'id'   => 'force_show_company',
712
-                        'name' => __( 'Force show company name at checkout.', 'invoicing' ),
712
+                        'name' => __('Force show company name at checkout.', 'invoicing'),
713 713
                         'type' => 'checkbox',
714 714
                         'std'  => false,
715 715
                     ),
716 716
                     'address_autofill_settings' => array(
717 717
                         'id'   => 'address_autofill_settings',
718
-                        'name' => '<h3>' . __( 'Google Address Auto Complete', 'invoicing' ) . '</h3>',
718
+                        'name' => '<h3>' . __('Google Address Auto Complete', 'invoicing') . '</h3>',
719 719
                         'type' => 'header',
720 720
                     ),
721 721
                     'address_autofill_active' => array(
722 722
                         'id'   => 'address_autofill_active',
723
-                        'name' => __( 'Enable/Disable', 'invoicing' ),
724
-                        'desc' => __( 'Enable google address auto complete', 'invoicing' ),
723
+                        'name' => __('Enable/Disable', 'invoicing'),
724
+                        'desc' => __('Enable google address auto complete', 'invoicing'),
725 725
                         'type' => 'checkbox',
726 726
                         'std'  => 0
727 727
                     ),
728 728
                     'address_autofill_api' => array(
729 729
                         'id' => 'address_autofill_api',
730
-                        'name' => __( 'Google Place API Key', 'invoicing' ),
731
-                        'desc' => wp_sprintf(__( 'Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing' ), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>' ),
730
+                        'name' => __('Google Place API Key', 'invoicing'),
731
+                        'desc' => wp_sprintf(__('Enter google place API key. For more information go to google place API %sdocumenation%s', 'invoicing'), '<a href="https://developers.google.com/maps/documentation/javascript/places-autocomplete" target="_blank">', '</a>'),
732 732
                         'type' => 'text',
733 733
                         'size' => 'regular',
734 734
                         'std' => ''
@@ -737,13 +737,13 @@  discard block
 block discarded – undo
737 737
                 'custom-css' => array(
738 738
                     'css_settings' => array(
739 739
                         'id'   => 'css_settings',
740
-                        'name' => '<h3>' . __( 'Custom CSS', 'invoicing' ) . '</h3>',
740
+                        'name' => '<h3>' . __('Custom CSS', 'invoicing') . '</h3>',
741 741
                         'type' => 'header',
742 742
                     ),
743 743
                     'template_custom_css' => array(
744 744
                         'id' => 'template_custom_css',
745
-                        'name' => __( 'Invoice Template CSS', 'invoicing' ),
746
-                        'desc' => __( 'Add CSS to modify appearance of the print invoice page.', 'invoicing' ),
745
+                        'name' => __('Invoice Template CSS', 'invoicing'),
746
+                        'desc' => __('Add CSS to modify appearance of the print invoice page.', 'invoicing'),
747 747
                         'type' => 'textarea',
748 748
                         'class'=> 'regular-text',
749 749
                         'rows' => 10,
@@ -757,8 +757,8 @@  discard block
 block discarded – undo
757 757
                 'main' => array(
758 758
                     'tool_settings' => array(
759 759
                         'id'   => 'tool_settings',
760
-                        'name' => '<h3>' . __( 'Diagnostic Tools', 'invoicing' ) . '</h3>',
761
-                        'desc' => __( 'Invoicing diagnostic tools', 'invoicing' ),
760
+                        'name' => '<h3>' . __('Diagnostic Tools', 'invoicing') . '</h3>',
761
+                        'desc' => __('Invoicing diagnostic tools', 'invoicing'),
762 762
                         'type' => 'tools',
763 763
                     ),
764 764
                 ),
@@ -766,136 +766,136 @@  discard block
 block discarded – undo
766 766
         )
767 767
     );
768 768
 
769
-    return apply_filters( 'wpinv_registered_settings', $wpinv_settings );
769
+    return apply_filters('wpinv_registered_settings', $wpinv_settings);
770 770
 }
771 771
 
772
-function wpinv_settings_sanitize( $input = array() ) {
772
+function wpinv_settings_sanitize($input = array()) {
773 773
     global $wpinv_options;
774 774
 
775
-    if ( empty( $_POST['_wp_http_referer'] ) ) {
775
+    if (empty($_POST['_wp_http_referer'])) {
776 776
         return $input;
777 777
     }
778 778
 
779
-    parse_str( $_POST['_wp_http_referer'], $referrer );
779
+    parse_str($_POST['_wp_http_referer'], $referrer);
780 780
 
781 781
     $settings = wpinv_get_registered_settings();
782
-    $tab      = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general';
783
-    $section  = isset( $referrer['section'] ) ? $referrer['section'] : 'main';
782
+    $tab      = isset($referrer['tab']) ? $referrer['tab'] : 'general';
783
+    $section  = isset($referrer['section']) ? $referrer['section'] : 'main';
784 784
 
785 785
     $input = $input ? $input : array();
786
-    $input = apply_filters( 'wpinv_settings_tab_' . $tab . '_sanitize', $input );
787
-    $input = apply_filters( 'wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input );
786
+    $input = apply_filters('wpinv_settings_tab_' . $tab . '_sanitize', $input);
787
+    $input = apply_filters('wpinv_settings_' . $tab . '-' . $section . '_sanitize', $input);
788 788
 
789 789
     // Loop through each setting being saved and pass it through a sanitization filter
790
-    foreach ( $input as $key => $value ) {
790
+    foreach ($input as $key => $value) {
791 791
         // Get the setting type (checkbox, select, etc)
792
-        $type = isset( $settings[ $tab ][ $key ]['type'] ) ? $settings[ $tab ][ $key ]['type'] : false;
792
+        $type = isset($settings[$tab][$key]['type']) ? $settings[$tab][$key]['type'] : false;
793 793
 
794
-        if ( $type ) {
794
+        if ($type) {
795 795
             // Field type specific filter
796
-            $input[$key] = apply_filters( 'wpinv_settings_sanitize_' . $type, $value, $key );
796
+            $input[$key] = apply_filters('wpinv_settings_sanitize_' . $type, $value, $key);
797 797
         }
798 798
 
799 799
         // General filter
800
-        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
800
+        $input[$key] = apply_filters('wpinv_settings_sanitize', $input[$key], $key);
801 801
     }
802 802
 
803 803
     // Loop through the whitelist and unset any that are empty for the tab being saved
804
-    $main_settings    = $section == 'main' ? $settings[ $tab ] : array(); // Check for extensions that aren't using new sections
805
-    $section_settings = ! empty( $settings[ $tab ][ $section ] ) ? $settings[ $tab ][ $section ] : array();
804
+    $main_settings    = $section == 'main' ? $settings[$tab] : array(); // Check for extensions that aren't using new sections
805
+    $section_settings = !empty($settings[$tab][$section]) ? $settings[$tab][$section] : array();
806 806
 
807
-    $found_settings = array_merge( $main_settings, $section_settings );
807
+    $found_settings = array_merge($main_settings, $section_settings);
808 808
 
809
-    if ( ! empty( $found_settings ) ) {
810
-        foreach ( $found_settings as $key => $value ) {
809
+    if (!empty($found_settings)) {
810
+        foreach ($found_settings as $key => $value) {
811 811
 
812 812
             // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work
813
-            if ( is_numeric( $key ) ) {
813
+            if (is_numeric($key)) {
814 814
                 $key = $value['id'];
815 815
             }
816 816
 
817
-            if ( empty( $input[ $key ] ) ) {
818
-                unset( $wpinv_options[ $key ] );
817
+            if (empty($input[$key])) {
818
+                unset($wpinv_options[$key]);
819 819
             }
820 820
         }
821 821
     }
822 822
 
823 823
     // Merge our new settings with the existing
824
-    $output = array_merge( $wpinv_options, $input );
824
+    $output = array_merge($wpinv_options, $input);
825 825
 
826
-    add_settings_error( 'wpinv-notices', '', __( 'Settings updated.', 'invoicing' ), 'updated' );
826
+    add_settings_error('wpinv-notices', '', __('Settings updated.', 'invoicing'), 'updated');
827 827
 
828 828
     return $output;
829 829
 }
830 830
 
831
-function wpinv_settings_sanitize_misc_accounting( $input ) {
831
+function wpinv_settings_sanitize_misc_accounting($input) {
832 832
     global $wpinv_options, $wpi_session;
833 833
 
834
-    if ( !current_user_can( 'manage_options' ) ) {
834
+    if (!current_user_can('manage_options')) {
835 835
         return $input;
836 836
     }
837 837
 
838
-    if( ! empty( $input['enable_sequential'] ) && !wpinv_get_option( 'enable_sequential' ) ) {
838
+    if (!empty($input['enable_sequential']) && !wpinv_get_option('enable_sequential')) {
839 839
         // Shows an admin notice about upgrading previous order numbers
840
-        $wpi_session->set( 'upgrade_sequential', '1' );
840
+        $wpi_session->set('upgrade_sequential', '1');
841 841
     }
842 842
 
843 843
     return $input;
844 844
 }
845
-add_filter( 'wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting' );
845
+add_filter('wpinv_settings_misc-accounting_sanitize', 'wpinv_settings_sanitize_misc_accounting');
846 846
 
847
-function wpinv_settings_sanitize_tax_rates( $input ) {
848
-    if( !current_user_can( 'manage_options' ) ) {
847
+function wpinv_settings_sanitize_tax_rates($input) {
848
+    if (!current_user_can('manage_options')) {
849 849
         return $input;
850 850
     }
851 851
 
852
-    $new_rates = !empty( $_POST['tax_rates'] ) ? array_values( $_POST['tax_rates'] ) : array();
852
+    $new_rates = !empty($_POST['tax_rates']) ? array_values($_POST['tax_rates']) : array();
853 853
 
854 854
     $tax_rates = array();
855 855
 
856
-    if ( !empty( $new_rates ) ) {
857
-        foreach ( $new_rates as $rate ) {
858
-            if ( isset( $rate['country'] ) && empty( $rate['country'] ) && empty( $rate['state'] ) ) {
856
+    if (!empty($new_rates)) {
857
+        foreach ($new_rates as $rate) {
858
+            if (isset($rate['country']) && empty($rate['country']) && empty($rate['state'])) {
859 859
                 continue;
860 860
             }
861 861
             
862
-            $rate['rate'] = wpinv_sanitize_amount( $rate['rate'], 4 );
862
+            $rate['rate'] = wpinv_sanitize_amount($rate['rate'], 4);
863 863
             
864 864
             $tax_rates[] = $rate;
865 865
         }
866 866
     }
867 867
 
868
-    update_option( 'wpinv_tax_rates', $tax_rates );
868
+    update_option('wpinv_tax_rates', $tax_rates);
869 869
 
870 870
     return $input;
871 871
 }
872
-add_filter( 'wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates' );
872
+add_filter('wpinv_settings_taxes-rates_sanitize', 'wpinv_settings_sanitize_tax_rates');
873 873
 
874
-function wpinv_sanitize_text_field( $input ) {
875
-    return trim( $input );
874
+function wpinv_sanitize_text_field($input) {
875
+    return trim($input);
876 876
 }
877
-add_filter( 'wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field' );
877
+add_filter('wpinv_settings_sanitize_text', 'wpinv_sanitize_text_field');
878 878
 
879 879
 function wpinv_get_settings_tabs() {
880 880
     $tabs             = array();
881
-    $tabs['general']  = __( 'General', 'invoicing' );
882
-    $tabs['gateways'] = __( 'Payment Gateways', 'invoicing' );
883
-    $tabs['taxes']    = __( 'Taxes', 'invoicing' );
884
-    $tabs['emails']   = __( 'Emails', 'invoicing' );
885
-    $tabs['privacy']  = __( 'Privacy', 'invoicing' );
886
-    $tabs['misc']     = __( 'Misc', 'invoicing' );
887
-    $tabs['tools']    = __( 'Tools', 'invoicing' );
888
-
889
-    return apply_filters( 'wpinv_settings_tabs', $tabs );
881
+    $tabs['general']  = __('General', 'invoicing');
882
+    $tabs['gateways'] = __('Payment Gateways', 'invoicing');
883
+    $tabs['taxes']    = __('Taxes', 'invoicing');
884
+    $tabs['emails']   = __('Emails', 'invoicing');
885
+    $tabs['privacy']  = __('Privacy', 'invoicing');
886
+    $tabs['misc']     = __('Misc', 'invoicing');
887
+    $tabs['tools']    = __('Tools', 'invoicing');
888
+
889
+    return apply_filters('wpinv_settings_tabs', $tabs);
890 890
 }
891 891
 
892
-function wpinv_get_settings_tab_sections( $tab = false ) {
892
+function wpinv_get_settings_tab_sections($tab = false) {
893 893
     $tabs     = false;
894 894
     $sections = wpinv_get_registered_settings_sections();
895 895
 
896
-    if( $tab && ! empty( $sections[ $tab ] ) ) {
897
-        $tabs = $sections[ $tab ];
898
-    } else if ( $tab ) {
896
+    if ($tab && !empty($sections[$tab])) {
897
+        $tabs = $sections[$tab];
898
+    } else if ($tab) {
899 899
         $tabs = false;
900 900
     }
901 901
 
@@ -905,143 +905,143 @@  discard block
 block discarded – undo
905 905
 function wpinv_get_registered_settings_sections() {
906 906
     static $sections = false;
907 907
 
908
-    if ( false !== $sections ) {
908
+    if (false !== $sections) {
909 909
         return $sections;
910 910
     }
911 911
 
912 912
     $sections = array(
913
-        'general' => apply_filters( 'wpinv_settings_sections_general', array(
914
-            'main' => __( 'General Settings', 'invoicing' ),
915
-            'currency_section' => __( 'Currency Settings', 'invoicing' ),
916
-            'labels' => __( 'Label Texts', 'invoicing' ),
917
-        ) ),
918
-        'gateways' => apply_filters( 'wpinv_settings_sections_gateways', array(
919
-            'main' => __( 'Gateway Settings', 'invoicing' ),
920
-        ) ),
921
-        'taxes' => apply_filters( 'wpinv_settings_sections_taxes', array(
922
-            'main' => __( 'Tax Settings', 'invoicing' ),
923
-            'rates' => __( 'Tax Rates', 'invoicing' ),
924
-        ) ),
925
-        'emails' => apply_filters( 'wpinv_settings_sections_emails', array(
926
-            'main' => __( 'Email Settings', 'invoicing' ),
927
-        ) ),
928
-        'privacy' => apply_filters( 'wpinv_settings_sections_privacy', array(
929
-            'main' => __( 'Privacy policy', 'invoicing' ),
930
-        ) ),
931
-        'misc' => apply_filters( 'wpinv_settings_sections_misc', array(
932
-            'main' => __( 'Miscellaneous', 'invoicing' ),
933
-            'fields' => __( 'Fields Settings', 'invoicing' ),
934
-            'custom-css' => __( 'Custom CSS', 'invoicing' ),
935
-        ) ),
936
-        'tools' => apply_filters( 'wpinv_settings_sections_tools', array(
937
-            'main' => __( 'Diagnostic Tools', 'invoicing' ),
938
-        ) ),
913
+        'general' => apply_filters('wpinv_settings_sections_general', array(
914
+            'main' => __('General Settings', 'invoicing'),
915
+            'currency_section' => __('Currency Settings', 'invoicing'),
916
+            'labels' => __('Label Texts', 'invoicing'),
917
+        )),
918
+        'gateways' => apply_filters('wpinv_settings_sections_gateways', array(
919
+            'main' => __('Gateway Settings', 'invoicing'),
920
+        )),
921
+        'taxes' => apply_filters('wpinv_settings_sections_taxes', array(
922
+            'main' => __('Tax Settings', 'invoicing'),
923
+            'rates' => __('Tax Rates', 'invoicing'),
924
+        )),
925
+        'emails' => apply_filters('wpinv_settings_sections_emails', array(
926
+            'main' => __('Email Settings', 'invoicing'),
927
+        )),
928
+        'privacy' => apply_filters('wpinv_settings_sections_privacy', array(
929
+            'main' => __('Privacy policy', 'invoicing'),
930
+        )),
931
+        'misc' => apply_filters('wpinv_settings_sections_misc', array(
932
+            'main' => __('Miscellaneous', 'invoicing'),
933
+            'fields' => __('Fields Settings', 'invoicing'),
934
+            'custom-css' => __('Custom CSS', 'invoicing'),
935
+        )),
936
+        'tools' => apply_filters('wpinv_settings_sections_tools', array(
937
+            'main' => __('Diagnostic Tools', 'invoicing'),
938
+        )),
939 939
     );
940 940
 
941
-    $sections = apply_filters( 'wpinv_settings_sections', $sections );
941
+    $sections = apply_filters('wpinv_settings_sections', $sections);
942 942
 
943 943
     return $sections;
944 944
 }
945 945
 
946
-function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
946
+function wpinv_get_pages($with_slug = false, $default_label = NULL) {
947 947
 	$pages_options = array();
948 948
 
949
-	if( $default_label !== NULL && $default_label !== false ) {
950
-		$pages_options = array( '' => $default_label ); // Blank option
949
+	if ($default_label !== NULL && $default_label !== false) {
950
+		$pages_options = array('' => $default_label); // Blank option
951 951
 	}
952 952
 
953 953
 	$pages = get_pages();
954
-	if ( $pages ) {
955
-		foreach ( $pages as $page ) {
954
+	if ($pages) {
955
+		foreach ($pages as $page) {
956 956
 			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
957
-            $pages_options[ $page->ID ] = $title;
957
+            $pages_options[$page->ID] = $title;
958 958
 		}
959 959
 	}
960 960
 
961 961
 	return $pages_options;
962 962
 }
963 963
 
964
-function wpinv_header_callback( $args ) {
965
-	if ( !empty( $args['desc'] ) ) {
964
+function wpinv_header_callback($args) {
965
+	if (!empty($args['desc'])) {
966 966
         echo $args['desc'];
967 967
     }
968 968
 }
969 969
 
970
-function wpinv_hidden_callback( $args ) {
970
+function wpinv_hidden_callback($args) {
971 971
 	global $wpinv_options;
972 972
 
973
-	if ( isset( $args['set_value'] ) ) {
973
+	if (isset($args['set_value'])) {
974 974
 		$value = $args['set_value'];
975
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
976
-		$value = $wpinv_options[ $args['id'] ];
975
+	} elseif (isset($wpinv_options[$args['id']])) {
976
+		$value = $wpinv_options[$args['id']];
977 977
 	} else {
978
-		$value = isset( $args['std'] ) ? $args['std'] : '';
978
+		$value = isset($args['std']) ? $args['std'] : '';
979 979
 	}
980 980
 
981
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
981
+	if (isset($args['faux']) && true === $args['faux']) {
982 982
 		$args['readonly'] = true;
983
-		$value = isset( $args['std'] ) ? $args['std'] : '';
983
+		$value = isset($args['std']) ? $args['std'] : '';
984 984
 		$name  = '';
985 985
 	} else {
986
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
986
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
987 987
 	}
988 988
 
989
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
989
+	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key($args['id']) . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '" />';
990 990
     
991 991
 	echo $html;
992 992
 }
993 993
 
994
-function wpinv_checkbox_callback( $args ) {
994
+function wpinv_checkbox_callback($args) {
995 995
 	global $wpinv_options;
996 996
     
997
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
997
+    $sanitize_id = wpinv_sanitize_key($args['id']);
998 998
 
999
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
999
+	if (isset($args['faux']) && true === $args['faux']) {
1000 1000
 		$name = '';
1001 1001
 	} else {
1002 1002
 		$name = 'name="wpinv_settings[' . $sanitize_id . ']"';
1003 1003
 	}
1004 1004
 
1005
-	$checked = isset( $wpinv_options[ $args['id'] ] ) ? checked( 1, $wpinv_options[ $args['id'] ], false ) : '';
1005
+	$checked = isset($wpinv_options[$args['id']]) ? checked(1, $wpinv_options[$args['id']], false) : '';
1006 1006
 	$html = '<input type="checkbox" id="wpinv_settings[' . $sanitize_id . ']"' . $name . ' value="1" ' . $checked . '/>';
1007
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1007
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1008 1008
 
1009 1009
 	echo $html;
1010 1010
 }
1011 1011
 
1012
-function wpinv_multicheck_callback( $args ) {
1012
+function wpinv_multicheck_callback($args) {
1013 1013
 	global $wpinv_options;
1014 1014
 
1015
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
1016
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
1015
+	$sanitize_id = wpinv_sanitize_key($args['id']);
1016
+	$class = !empty($args['class']) ? ' ' . esc_attr($args['class']) : '';
1017 1017
 
1018
-	if ( ! empty( $args['options'] ) ) {
1018
+	if (!empty($args['options'])) {
1019 1019
 		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
1020
-        foreach( $args['options'] as $key => $option ):
1021
-			$sanitize_key = wpinv_sanitize_key( $key );
1022
-			if ( isset( $wpinv_options[$args['id']][$sanitize_key] ) ) { 
1020
+        foreach ($args['options'] as $key => $option):
1021
+			$sanitize_key = wpinv_sanitize_key($key);
1022
+			if (isset($wpinv_options[$args['id']][$sanitize_key])) { 
1023 1023
 				$enabled = $sanitize_key;
1024 1024
 			} else { 
1025 1025
 				$enabled = NULL; 
1026 1026
 			}
1027
-			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;';
1028
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
1027
+			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;';
1028
+			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post($option) . '</label></div>';
1029 1029
 		endforeach;
1030 1030
 		echo '</div>';
1031 1031
 		echo '<p class="description">' . $args['desc'] . '</p>';
1032 1032
 	}
1033 1033
 }
1034 1034
 
1035
-function wpinv_payment_icons_callback( $args ) {
1035
+function wpinv_payment_icons_callback($args) {
1036 1036
 	global $wpinv_options;
1037 1037
     
1038
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1038
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1039 1039
 
1040
-	if ( ! empty( $args['options'] ) ) {
1041
-		foreach( $args['options'] as $key => $option ) {
1042
-            $sanitize_key = wpinv_sanitize_key( $key );
1040
+	if (!empty($args['options'])) {
1041
+		foreach ($args['options'] as $key => $option) {
1042
+            $sanitize_key = wpinv_sanitize_key($key);
1043 1043
             
1044
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
1044
+			if (isset($wpinv_options[$args['id']][$key])) {
1045 1045
 				$enabled = $option;
1046 1046
 			} else {
1047 1047
 				$enabled = NULL;
@@ -1049,196 +1049,196 @@  discard block
 block discarded – undo
1049 1049
 
1050 1050
 			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
1051 1051
 
1052
-				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;';
1052
+				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;';
1053 1053
 
1054
-				if ( wpinv_string_is_image_url( $key ) ) {
1055
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1054
+				if (wpinv_string_is_image_url($key)) {
1055
+					echo '<img class="payment-icon" src="' . esc_url($key) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1056 1056
 				} else {
1057
-					$card = strtolower( str_replace( ' ', '', $option ) );
1057
+					$card = strtolower(str_replace(' ', '', $option));
1058 1058
 
1059
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
1060
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
1059
+					if (has_filter('wpinv_accepted_payment_' . $card . '_image')) {
1060
+						$image = apply_filters('wpinv_accepted_payment_' . $card . '_image', '');
1061 1061
 					} else {
1062
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
1062
+						$image       = wpinv_locate_template('images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false);
1063 1063
 						$content_dir = WP_CONTENT_DIR;
1064 1064
 
1065
-						if ( function_exists( 'wp_normalize_path' ) ) {
1065
+						if (function_exists('wp_normalize_path')) {
1066 1066
 							// Replaces backslashes with forward slashes for Windows systems
1067
-							$image = wp_normalize_path( $image );
1068
-							$content_dir = wp_normalize_path( $content_dir );
1067
+							$image = wp_normalize_path($image);
1068
+							$content_dir = wp_normalize_path($content_dir);
1069 1069
 						}
1070 1070
 
1071
-						$image = str_replace( $content_dir, content_url(), $image );
1071
+						$image = str_replace($content_dir, content_url(), $image);
1072 1072
 					}
1073 1073
 
1074
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1074
+					echo '<img class="payment-icon" src="' . esc_url($image) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
1075 1075
 				}
1076 1076
 			echo $option . '</label>';
1077 1077
 		}
1078
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
1078
+		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post($args['desc']) . '</p>';
1079 1079
 	}
1080 1080
 }
1081 1081
 
1082
-function wpinv_radio_callback( $args ) {
1082
+function wpinv_radio_callback($args) {
1083 1083
 	global $wpinv_options;
1084 1084
     
1085
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1085
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1086 1086
     
1087
-    foreach ( $args['options'] as $key => $option ) :
1088
-		$sanitize_key = wpinv_sanitize_key( $key );
1087
+    foreach ($args['options'] as $key => $option) :
1088
+		$sanitize_key = wpinv_sanitize_key($key);
1089 1089
         
1090 1090
         $checked = false;
1091 1091
 
1092
-		if ( isset( $wpinv_options[ $args['id'] ] ) && $wpinv_options[ $args['id'] ] == $key )
1092
+		if (isset($wpinv_options[$args['id']]) && $wpinv_options[$args['id']] == $key)
1093 1093
 			$checked = true;
1094
-		elseif( isset( $args['std'] ) && $args['std'] == $key && ! isset( $wpinv_options[ $args['id'] ] ) )
1094
+		elseif (isset($args['std']) && $args['std'] == $key && !isset($wpinv_options[$args['id']]))
1095 1095
 			$checked = true;
1096 1096
 
1097 1097
 		echo '<input name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="radio" value="' . $sanitize_key . '" ' . checked(true, $checked, false) . '/>&nbsp;';
1098
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option ) . '</label><br/>';
1098
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option) . '</label><br/>';
1099 1099
 	endforeach;
1100 1100
 
1101
-	echo '<p class="description">' . wp_kses_post( $args['desc'] ) . '</p>';
1101
+	echo '<p class="description">' . wp_kses_post($args['desc']) . '</p>';
1102 1102
 }
1103 1103
 
1104
-function wpinv_gateways_callback( $args ) {
1104
+function wpinv_gateways_callback($args) {
1105 1105
 	global $wpinv_options;
1106 1106
     
1107
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1107
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1108 1108
 
1109
-	foreach ( $args['options'] as $key => $option ) :
1110
-		$sanitize_key = wpinv_sanitize_key( $key );
1109
+	foreach ($args['options'] as $key => $option) :
1110
+		$sanitize_key = wpinv_sanitize_key($key);
1111 1111
         
1112
-        if ( isset( $wpinv_options['gateways'][ $key ] ) )
1112
+        if (isset($wpinv_options['gateways'][$key]))
1113 1113
 			$enabled = '1';
1114 1114
 		else
1115 1115
 			$enabled = null;
1116 1116
 
1117
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
1118
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
1117
+		echo '<input name="wpinv_settings[' . esc_attr($args['id']) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
1118
+		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html($option['admin_label']) . '</label><br/>';
1119 1119
 	endforeach;
1120 1120
 }
1121 1121
 
1122 1122
 function wpinv_gateway_select_callback($args) {
1123 1123
 	global $wpinv_options;
1124 1124
     
1125
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1125
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1126 1126
 
1127 1127
 	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']">';
1128 1128
 
1129
-	foreach ( $args['options'] as $key => $option ) :
1130
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1131
-            $selected = selected( $key, $args['selected'], false );
1129
+	foreach ($args['options'] as $key => $option) :
1130
+		if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1131
+            $selected = selected($key, $args['selected'], false);
1132 1132
         } else {
1133
-            $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
1133
+            $selected = isset($wpinv_options[$args['id']]) ? selected($key, $wpinv_options[$args['id']], false) : '';
1134 1134
         }
1135
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
1135
+		echo '<option value="' . wpinv_sanitize_key($key) . '"' . $selected . '>' . esc_html($option['admin_label']) . '</option>';
1136 1136
 	endforeach;
1137 1137
 
1138 1138
 	echo '</select>';
1139
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1139
+	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1140 1140
 }
1141 1141
 
1142
-function wpinv_text_callback( $args ) {
1142
+function wpinv_text_callback($args) {
1143 1143
 	global $wpinv_options;
1144 1144
     
1145
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1145
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1146 1146
 
1147
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1148
-		$value = $wpinv_options[ $args['id'] ];
1147
+	if (isset($wpinv_options[$args['id']])) {
1148
+		$value = $wpinv_options[$args['id']];
1149 1149
 	} else {
1150
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1150
+		$value = isset($args['std']) ? $args['std'] : '';
1151 1151
 	}
1152 1152
 
1153
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1153
+	if (isset($args['faux']) && true === $args['faux']) {
1154 1154
 		$args['readonly'] = true;
1155
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1155
+		$value = isset($args['std']) ? $args['std'] : '';
1156 1156
 		$name  = '';
1157 1157
 	} else {
1158
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1158
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1159 1159
 	}
1160
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1160
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
1161 1161
 
1162 1162
 	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
1163
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1164
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
1165
-	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1163
+	$size     = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1164
+	$html     = '<input type="text" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"' . $readonly . '/>';
1165
+	$html    .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1166 1166
 
1167 1167
 	echo $html;
1168 1168
 }
1169 1169
 
1170
-function wpinv_number_callback( $args ) {
1170
+function wpinv_number_callback($args) {
1171 1171
 	global $wpinv_options;
1172 1172
     
1173
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1173
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1174 1174
 
1175
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1176
-		$value = $wpinv_options[ $args['id'] ];
1175
+	if (isset($wpinv_options[$args['id']])) {
1176
+		$value = $wpinv_options[$args['id']];
1177 1177
 	} else {
1178
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1178
+		$value = isset($args['std']) ? $args['std'] : '';
1179 1179
 	}
1180 1180
 
1181
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
1181
+	if (isset($args['faux']) && true === $args['faux']) {
1182 1182
 		$args['readonly'] = true;
1183
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1183
+		$value = isset($args['std']) ? $args['std'] : '';
1184 1184
 		$name  = '';
1185 1185
 	} else {
1186
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
1186
+		$name = 'name="wpinv_settings[' . esc_attr($args['id']) . ']"';
1187 1187
 	}
1188 1188
 
1189
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
1190
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
1191
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
1192
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
1189
+	$max  = isset($args['max']) ? $args['max'] : 999999;
1190
+	$min  = isset($args['min']) ? $args['min'] : 0;
1191
+	$step = isset($args['step']) ? $args['step'] : 1;
1192
+	$class = !empty($args['class']) ? sanitize_html_class($args['class']) : '';
1193 1193
 
1194
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1195
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
1196
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1194
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1195
+	$html = '<input type="number" step="' . esc_attr($step) . '" max="' . esc_attr($max) . '" min="' . esc_attr($min) . '" class="' . sanitize_html_class($size) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr(stripslashes($value)) . '"/>';
1196
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1197 1197
 
1198 1198
 	echo $html;
1199 1199
 }
1200 1200
 
1201
-function wpinv_textarea_callback( $args ) {
1201
+function wpinv_textarea_callback($args) {
1202 1202
 	global $wpinv_options;
1203 1203
     
1204
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1204
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1205 1205
 
1206
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1207
-		$value = $wpinv_options[ $args['id'] ];
1206
+	if (isset($wpinv_options[$args['id']])) {
1207
+		$value = $wpinv_options[$args['id']];
1208 1208
 	} else {
1209
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1209
+		$value = isset($args['std']) ? $args['std'] : '';
1210 1210
 	}
1211 1211
     
1212
-    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1213
-    $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
1212
+    $size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1213
+    $class = (isset($args['class']) && !is_null($args['class'])) ? $args['class'] : 'large-text';
1214 1214
 
1215
-	$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>';
1216
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1215
+	$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>';
1216
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1217 1217
 
1218 1218
 	echo $html;
1219 1219
 }
1220 1220
 
1221
-function wpinv_password_callback( $args ) {
1221
+function wpinv_password_callback($args) {
1222 1222
 	global $wpinv_options;
1223 1223
     
1224
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1224
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1225 1225
 
1226
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1227
-		$value = $wpinv_options[ $args['id'] ];
1226
+	if (isset($wpinv_options[$args['id']])) {
1227
+		$value = $wpinv_options[$args['id']];
1228 1228
 	} else {
1229
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1229
+		$value = isset($args['std']) ? $args['std'] : '';
1230 1230
 	}
1231 1231
 
1232
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1233
-	$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 ) . '"/>';
1234
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1232
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1233
+	$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) . '"/>';
1234
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1235 1235
 
1236 1236
 	echo $html;
1237 1237
 }
1238 1238
 
1239 1239
 function wpinv_missing_callback($args) {
1240 1240
 	printf(
1241
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
1241
+		__('The callback function used for the %s setting is missing.', 'invoicing'),
1242 1242
 		'<strong>' . $args['id'] . '</strong>'
1243 1243
 	);
1244 1244
 }
@@ -1246,131 +1246,131 @@  discard block
 block discarded – undo
1246 1246
 function wpinv_select_callback($args) {
1247 1247
 	global $wpinv_options;
1248 1248
     
1249
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1249
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1250 1250
 
1251
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1252
-		$value = $wpinv_options[ $args['id'] ];
1251
+	if (isset($wpinv_options[$args['id']])) {
1252
+		$value = $wpinv_options[$args['id']];
1253 1253
 	} else {
1254
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1254
+		$value = isset($args['std']) ? $args['std'] : '';
1255 1255
 	}
1256 1256
     
1257
-    if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
1257
+    if (isset($args['selected']) && $args['selected'] !== null && $args['selected'] !== false) {
1258 1258
         $value = $args['selected'];
1259 1259
     }
1260 1260
 
1261
-	if ( isset( $args['placeholder'] ) ) {
1261
+	if (isset($args['placeholder'])) {
1262 1262
 		$placeholder = $args['placeholder'];
1263 1263
 	} else {
1264 1264
 		$placeholder = '';
1265 1265
 	}
1266 1266
     
1267
-    if( !empty( $args['onchange'] ) ) {
1268
-        $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
1267
+    if (!empty($args['onchange'])) {
1268
+        $onchange = ' onchange="' . esc_attr($args['onchange']) . '"';
1269 1269
     } else {
1270 1270
         $onchange = '';
1271 1271
     }
1272 1272
 
1273
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
1273
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']" data-placeholder="' . esc_html($placeholder) . '"' . $onchange . ' />';
1274 1274
 
1275
-	foreach ( $args['options'] as $option => $name ) {
1276
-		$selected = selected( $option, $value, false );
1277
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1275
+	foreach ($args['options'] as $option => $name) {
1276
+		$selected = selected($option, $value, false);
1277
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1278 1278
 	}
1279 1279
 
1280 1280
 	$html .= '</select>';
1281
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1281
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1282 1282
 
1283 1283
 	echo $html;
1284 1284
 }
1285 1285
 
1286
-function wpinv_color_select_callback( $args ) {
1286
+function wpinv_color_select_callback($args) {
1287 1287
 	global $wpinv_options;
1288 1288
     
1289
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1289
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1290 1290
 
1291
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1292
-		$value = $wpinv_options[ $args['id'] ];
1291
+	if (isset($wpinv_options[$args['id']])) {
1292
+		$value = $wpinv_options[$args['id']];
1293 1293
 	} else {
1294
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1294
+		$value = isset($args['std']) ? $args['std'] : '';
1295 1295
 	}
1296 1296
 
1297
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
1297
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"/>';
1298 1298
 
1299
-	foreach ( $args['options'] as $option => $color ) {
1300
-		$selected = selected( $option, $value, false );
1301
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
1299
+	foreach ($args['options'] as $option => $color) {
1300
+		$selected = selected($option, $value, false);
1301
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($color['label']) . '</option>';
1302 1302
 	}
1303 1303
 
1304 1304
 	$html .= '</select>';
1305
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1305
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1306 1306
 
1307 1307
 	echo $html;
1308 1308
 }
1309 1309
 
1310
-function wpinv_rich_editor_callback( $args ) {
1310
+function wpinv_rich_editor_callback($args) {
1311 1311
 	global $wpinv_options, $wp_version;
1312 1312
     
1313
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1313
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1314 1314
 
1315
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1316
-		$value = $wpinv_options[ $args['id'] ];
1315
+	if (isset($wpinv_options[$args['id']])) {
1316
+		$value = $wpinv_options[$args['id']];
1317 1317
 
1318
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
1319
-			$value = isset( $args['std'] ) ? $args['std'] : '';
1318
+		if (empty($args['allow_blank']) && empty($value)) {
1319
+			$value = isset($args['std']) ? $args['std'] : '';
1320 1320
 		}
1321 1321
 	} else {
1322
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1322
+		$value = isset($args['std']) ? $args['std'] : '';
1323 1323
 	}
1324 1324
 
1325
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
1325
+	$rows = isset($args['size']) ? $args['size'] : 20;
1326 1326
 
1327
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
1327
+	if ($wp_version >= 3.3 && function_exists('wp_editor')) {
1328 1328
 		ob_start();
1329
-		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 ) );
1329
+		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));
1330 1330
 		$html = ob_get_clean();
1331 1331
 	} else {
1332
-		$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>';
1332
+		$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>';
1333 1333
 	}
1334 1334
 
1335
-	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1335
+	$html .= '<br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1336 1336
 
1337 1337
 	echo $html;
1338 1338
 }
1339 1339
 
1340
-function wpinv_upload_callback( $args ) {
1340
+function wpinv_upload_callback($args) {
1341 1341
 	global $wpinv_options;
1342 1342
     
1343
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1343
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1344 1344
 
1345
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1345
+	if (isset($wpinv_options[$args['id']])) {
1346 1346
 		$value = $wpinv_options[$args['id']];
1347 1347
 	} else {
1348 1348
 		$value = isset($args['std']) ? $args['std'] : '';
1349 1349
 	}
1350 1350
 
1351
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
1352
-	$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 ) ) . '"/>';
1353
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
1354
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
1351
+	$size = (isset($args['size']) && !is_null($args['size'])) ? $args['size'] : 'regular';
1352
+	$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)) . '"/>';
1353
+	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __('Upload File', 'invoicing') . '"/></span>';
1354
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1355 1355
 
1356 1356
 	echo $html;
1357 1357
 }
1358 1358
 
1359
-function wpinv_color_callback( $args ) {
1359
+function wpinv_color_callback($args) {
1360 1360
 	global $wpinv_options;
1361 1361
     
1362
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1362
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1363 1363
 
1364
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
1365
-		$value = $wpinv_options[ $args['id'] ];
1364
+	if (isset($wpinv_options[$args['id']])) {
1365
+		$value = $wpinv_options[$args['id']];
1366 1366
 	} else {
1367
-		$value = isset( $args['std'] ) ? $args['std'] : '';
1367
+		$value = isset($args['std']) ? $args['std'] : '';
1368 1368
 	}
1369 1369
 
1370
-	$default = isset( $args['std'] ) ? $args['std'] : '';
1370
+	$default = isset($args['std']) ? $args['std'] : '';
1371 1371
 
1372
-	$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 ) . '" />';
1373
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1372
+	$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) . '" />';
1373
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1374 1374
 
1375 1375
 	echo $html;
1376 1376
 }
@@ -1378,9 +1378,9 @@  discard block
 block discarded – undo
1378 1378
 function wpinv_country_states_callback($args) {
1379 1379
 	global $wpinv_options;
1380 1380
     
1381
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
1381
+    $sanitize_id = wpinv_sanitize_key($args['id']);
1382 1382
 
1383
-	if ( isset( $args['placeholder'] ) ) {
1383
+	if (isset($args['placeholder'])) {
1384 1384
 		$placeholder = $args['placeholder'];
1385 1385
 	} else {
1386 1386
 		$placeholder = '';
@@ -1388,16 +1388,16 @@  discard block
 block discarded – undo
1388 1388
 
1389 1389
 	$states = wpinv_get_country_states();
1390 1390
 
1391
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : '';
1392
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
1391
+	$class = empty($states) ? ' class="wpinv-no-states"' : '';
1392
+	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr($args['id']) . ']"' . $class . 'data-placeholder="' . esc_html($placeholder) . '"/>';
1393 1393
 
1394
-	foreach ( $states as $option => $name ) {
1395
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
1396
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
1394
+	foreach ($states as $option => $name) {
1395
+		$selected = isset($wpinv_options[$args['id']]) ? selected($option, $wpinv_options[$args['id']], false) : '';
1396
+		$html .= '<option value="' . esc_attr($option) . '" ' . $selected . '>' . esc_html($name) . '</option>';
1397 1397
 	}
1398 1398
 
1399 1399
 	$html .= '</select>';
1400
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
1400
+	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post($args['desc']) . '</label>';
1401 1401
 
1402 1402
 	echo $html;
1403 1403
 }
@@ -1412,95 +1412,95 @@  discard block
 block discarded – undo
1412 1412
 	<table id="wpinv_tax_rates" class="wp-list-table widefat fixed posts">
1413 1413
 		<thead>
1414 1414
 			<tr>
1415
-				<th scope="col" class="wpinv_tax_country"><?php _e( 'Country', 'invoicing' ); ?></th>
1416
-				<th scope="col" class="wpinv_tax_state"><?php _e( 'State / Province', 'invoicing' ); ?></th>
1417
-                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e( 'Apply rate to whole country, regardless of state / province', 'invoicing' ); ?>"><?php _e( 'Country Wide', 'invoicing' ); ?></th>
1418
-                <th scope="col" class="wpinv_tax_rate"><?php _e( 'Rate %', 'invoicing' ); ?></th> 
1419
-                <th scope="col" class="wpinv_tax_name"><?php _e( 'Tax Name', 'invoicing' ); ?></th>
1420
-				<th scope="col" class="wpinv_tax_action"><?php _e( 'Remove', 'invoicing' ); ?></th>
1415
+				<th scope="col" class="wpinv_tax_country"><?php _e('Country', 'invoicing'); ?></th>
1416
+				<th scope="col" class="wpinv_tax_state"><?php _e('State / Province', 'invoicing'); ?></th>
1417
+                <th scope="col" class="wpinv_tax_global" title="<?php esc_attr_e('Apply rate to whole country, regardless of state / province', 'invoicing'); ?>"><?php _e('Country Wide', 'invoicing'); ?></th>
1418
+                <th scope="col" class="wpinv_tax_rate"><?php _e('Rate %', 'invoicing'); ?></th> 
1419
+                <th scope="col" class="wpinv_tax_name"><?php _e('Tax Name', 'invoicing'); ?></th>
1420
+				<th scope="col" class="wpinv_tax_action"><?php _e('Remove', 'invoicing'); ?></th>
1421 1421
 			</tr>
1422 1422
 		</thead>
1423 1423
         <tbody>
1424
-		<?php if( !empty( $rates ) ) : ?>
1425
-			<?php foreach( $rates as $key => $rate ) : ?>
1424
+		<?php if (!empty($rates)) : ?>
1425
+			<?php foreach ($rates as $key => $rate) : ?>
1426 1426
             <?php 
1427
-            $sanitized_key = wpinv_sanitize_key( $key );
1427
+            $sanitized_key = wpinv_sanitize_key($key);
1428 1428
             ?>
1429 1429
 			<tr>
1430 1430
 				<td class="wpinv_tax_country">
1431 1431
 					<?php
1432
-					echo wpinv_html_select( array(
1433
-						'options'          => wpinv_get_country_list( true ),
1432
+					echo wpinv_html_select(array(
1433
+						'options'          => wpinv_get_country_list(true),
1434 1434
 						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
1435 1435
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
1436 1436
 						'selected'         => $rate['country'],
1437 1437
 						'show_option_all'  => false,
1438 1438
 						'show_option_none' => false,
1439 1439
 						'class'            => 'wpinv-tax-country',
1440
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1441
-					) );
1440
+						'placeholder'      => __('Choose a country', 'invoicing')
1441
+					));
1442 1442
 					?>
1443 1443
 				</td>
1444 1444
 				<td class="wpinv_tax_state">
1445 1445
 					<?php
1446
-					$states = wpinv_get_country_states( $rate['country'] );
1447
-					if( !empty( $states ) ) {
1448
-						echo wpinv_html_select( array(
1449
-							'options'          => array_merge( array( '' => '' ), $states ),
1446
+					$states = wpinv_get_country_states($rate['country']);
1447
+					if (!empty($states)) {
1448
+						echo wpinv_html_select(array(
1449
+							'options'          => array_merge(array('' => ''), $states),
1450 1450
 							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
1451 1451
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
1452 1452
 							'selected'         => $rate['state'],
1453 1453
 							'show_option_all'  => false,
1454 1454
 							'show_option_none' => false,
1455
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
1456
-						) );
1455
+							'placeholder'      => __('Choose a state', 'invoicing')
1456
+						));
1457 1457
 					} else {
1458
-						echo wpinv_html_text( array(
1458
+						echo wpinv_html_text(array(
1459 1459
 							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
1460
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
1460
+							'value' => !empty($rate['state']) ? $rate['state'] : '',
1461 1461
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
1462
-						) );
1462
+						));
1463 1463
 					}
1464 1464
 					?>
1465 1465
 				</td>
1466 1466
 				<td class="wpinv_tax_global">
1467
-					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
1468
-					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1467
+					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked(true, !empty($rate['global'])); ?>/>
1468
+					<label for="tax_rates[<?php echo $sanitized_key; ?>][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1469 1469
 				</td>
1470
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html( $rate['rate'] ); ?>"/></td>
1471
-                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html( $rate['name'] ); ?>"/></td>
1472
-				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1470
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[<?php echo $sanitized_key; ?>][rate]" value="<?php echo esc_html($rate['rate']); ?>"/></td>
1471
+                <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[<?php echo $sanitized_key; ?>][name]" value="<?php echo esc_html($rate['name']); ?>"/></td>
1472
+				<td class="wpinv_tax_action"><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1473 1473
 			</tr>
1474 1474
 			<?php endforeach; ?>
1475 1475
 		<?php else : ?>
1476 1476
 			<tr>
1477 1477
 				<td class="wpinv_tax_country">
1478 1478
 					<?php
1479
-					echo wpinv_html_select( array(
1480
-						'options'          => wpinv_get_country_list( true ),
1479
+					echo wpinv_html_select(array(
1480
+						'options'          => wpinv_get_country_list(true),
1481 1481
 						'name'             => 'tax_rates[0][country]',
1482 1482
 						'show_option_all'  => false,
1483 1483
 						'show_option_none' => false,
1484 1484
 						'class'            => 'wpinv-tax-country',
1485
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
1486
-					) ); ?>
1485
+						'placeholder'      => __('Choose a country', 'invoicing')
1486
+					)); ?>
1487 1487
 				</td>
1488 1488
 				<td class="wpinv_tax_state">
1489
-					<?php echo wpinv_html_text( array(
1489
+					<?php echo wpinv_html_text(array(
1490 1490
 						'name' => 'tax_rates[0][state]'
1491
-					) ); ?>
1491
+					)); ?>
1492 1492
 				</td>
1493 1493
 				<td class="wpinv_tax_global">
1494 1494
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
1495
-					<label for="tax_rates[0][global]"><?php _e( 'Apply to whole country', 'invoicing' ); ?></label>
1495
+					<label for="tax_rates[0][global]"><?php _e('Apply to whole country', 'invoicing'); ?></label>
1496 1496
 				</td>
1497
-				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>" value="<?php echo (float)wpinv_get_option( 'tax_rate', 0 ) ;?>"/></td>
1497
+				<td class="wpinv_tax_rate"><input type="number" class="small-text" step="any" min="0" max="99" name="tax_rates[0][rate]" placeholder="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>" value="<?php echo (float)wpinv_get_option('tax_rate', 0); ?>"/></td>
1498 1498
                 <td class="wpinv_tax_name"><input type="text" class="regular-text" name="tax_rates[0][name]" /></td>
1499
-				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e( 'Remove Rate', 'invoicing' ); ?></span></td>
1499
+				<td><span class="wpinv_remove_tax_rate button-secondary"><?php _e('Remove Rate', 'invoicing'); ?></span></td>
1500 1500
 			</tr>
1501 1501
 		<?php endif; ?>
1502 1502
         </tbody>
1503
-        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1503
+        <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e('Add Tax Rate', 'invoicing'); ?></span></td></tr></tfoot>
1504 1504
 	</table>
1505 1505
 	<?php
1506 1506
 	echo ob_get_clean();
@@ -1511,76 +1511,76 @@  discard block
 block discarded – undo
1511 1511
     ob_start(); ?>
1512 1512
     </td><tr>
1513 1513
     <td colspan="2" class="wpinv_tools_tdbox">
1514
-    <?php if ( $args['desc'] ) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1515
-    <?php do_action( 'wpinv_tools_before' ); ?>
1514
+    <?php if ($args['desc']) { ?><p><?php echo $args['desc']; ?></p><?php } ?>
1515
+    <?php do_action('wpinv_tools_before'); ?>
1516 1516
     <table id="wpinv_tools_table" class="wp-list-table widefat fixed posts">
1517 1517
         <thead>
1518 1518
             <tr>
1519
-                <th scope="col" class="wpinv-th-tool"><?php _e( 'Tool', 'invoicing' ); ?></th>
1520
-                <th scope="col" class="wpinv-th-desc"><?php _e( 'Description', 'invoicing' ); ?></th>
1521
-                <th scope="col" class="wpinv-th-action"><?php _e( 'Action', 'invoicing' ); ?></th>
1519
+                <th scope="col" class="wpinv-th-tool"><?php _e('Tool', 'invoicing'); ?></th>
1520
+                <th scope="col" class="wpinv-th-desc"><?php _e('Description', 'invoicing'); ?></th>
1521
+                <th scope="col" class="wpinv-th-action"><?php _e('Action', 'invoicing'); ?></th>
1522 1522
             </tr>
1523 1523
         </thead>
1524
-            <?php do_action( 'wpinv_tools_row' ); ?>
1524
+            <?php do_action('wpinv_tools_row'); ?>
1525 1525
         <tbody>
1526 1526
         </tbody>
1527 1527
     </table>
1528
-    <?php do_action( 'wpinv_tools_after' ); ?>
1528
+    <?php do_action('wpinv_tools_after'); ?>
1529 1529
     <?php
1530 1530
     echo ob_get_clean();
1531 1531
 }
1532 1532
 
1533
-function wpinv_descriptive_text_callback( $args ) {
1534
-	echo wp_kses_post( $args['desc'] );
1533
+function wpinv_descriptive_text_callback($args) {
1534
+	echo wp_kses_post($args['desc']);
1535 1535
 }
1536 1536
 
1537
-function wpinv_hook_callback( $args ) {
1538
-	do_action( 'wpinv_' . $args['id'], $args );
1537
+function wpinv_hook_callback($args) {
1538
+	do_action('wpinv_' . $args['id'], $args);
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_set_settings_cap() {
1542 1542
 	return 'manage_options';
1543 1543
 }
1544
-add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1544
+add_filter('option_page_capability_wpinv_settings', 'wpinv_set_settings_cap');
1545 1545
 
1546
-function wpinv_settings_sanitize_input( $value, $key ) {
1547
-    if ( $key == 'tax_rate' || $key == 'eu_fallback_rate' ) {
1548
-        $value = wpinv_sanitize_amount( $value, 4 );
1546
+function wpinv_settings_sanitize_input($value, $key) {
1547
+    if ($key == 'tax_rate' || $key == 'eu_fallback_rate') {
1548
+        $value = wpinv_sanitize_amount($value, 4);
1549 1549
         $value = $value >= 100 ? 99 : $value;
1550 1550
     }
1551 1551
         
1552 1552
     return $value;
1553 1553
 }
1554
-add_filter( 'wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2 );
1554
+add_filter('wpinv_settings_sanitize', 'wpinv_settings_sanitize_input', 10, 2);
1555 1555
 
1556
-function wpinv_on_update_settings( $old_value, $value, $option ) {
1557
-    $old = !empty( $old_value['remove_data_on_unistall'] ) ? 1 : '';
1558
-    $new = !empty( $value['remove_data_on_unistall'] ) ? 1 : '';
1556
+function wpinv_on_update_settings($old_value, $value, $option) {
1557
+    $old = !empty($old_value['remove_data_on_unistall']) ? 1 : '';
1558
+    $new = !empty($value['remove_data_on_unistall']) ? 1 : '';
1559 1559
     
1560
-    if ( $old != $new ) {
1561
-        update_option( 'wpinv_remove_data_on_invoice_unistall', $new );
1560
+    if ($old != $new) {
1561
+        update_option('wpinv_remove_data_on_invoice_unistall', $new);
1562 1562
     }
1563 1563
 }
1564
-add_action( 'update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3 );
1565
-add_action( 'wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1566
-add_action( 'wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1567
-add_action( 'wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1568
-add_action( 'wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1569
-add_action( 'wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1570
-add_action( 'wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1571
-add_action( 'wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1572
-add_action( 'wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1573
-add_action( 'wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1574
-add_action( 'wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2 );
1575
-
1576
-function wpinv_settings_tab_bottom_emails( $active_tab, $section ) {
1564
+add_action('update_option_wpinv_settings', 'wpinv_on_update_settings', 10, 3);
1565
+add_action('wpinv_settings_tab_bottom_emails_new_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1566
+add_action('wpinv_settings_tab_bottom_emails_cancelled_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1567
+add_action('wpinv_settings_tab_bottom_emails_failed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1568
+add_action('wpinv_settings_tab_bottom_emails_onhold_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1569
+add_action('wpinv_settings_tab_bottom_emails_processing_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1570
+add_action('wpinv_settings_tab_bottom_emails_completed_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1571
+add_action('wpinv_settings_tab_bottom_emails_refunded_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1572
+add_action('wpinv_settings_tab_bottom_emails_user_invoice', 'wpinv_settings_tab_bottom_emails', 10, 2);
1573
+add_action('wpinv_settings_tab_bottom_emails_user_note', 'wpinv_settings_tab_bottom_emails', 10, 2);
1574
+add_action('wpinv_settings_tab_bottom_emails_overdue', 'wpinv_settings_tab_bottom_emails', 10, 2);
1575
+
1576
+function wpinv_settings_tab_bottom_emails($active_tab, $section) {
1577 1577
     ?>
1578 1578
     <div class="wpinv-email-wc-row ">
1579 1579
         <div class="wpinv-email-wc-td">
1580
-            <h3 class="wpinv-email-wc-title"><?php echo apply_filters( 'wpinv_settings_email_wildcards_title', __( 'Wildcards For Emails', 'invoicing' ) ); ?></h3>
1580
+            <h3 class="wpinv-email-wc-title"><?php echo apply_filters('wpinv_settings_email_wildcards_title', __('Wildcards For Emails', 'invoicing')); ?></h3>
1581 1581
             <p class="wpinv-email-wc-description">
1582 1582
                 <?php
1583
-                $description = __( 'The following wildcards can be used in email subjects, heading and content:<br>
1583
+                $description = __('The following wildcards can be used in email subjects, heading and content:<br>
1584 1584
                     <strong>{site_title} :</strong> Site Title<br>
1585 1585
                     <strong>{name} :</strong> Customer\'s full name<br>
1586 1586
                     <strong>{first_name} :</strong> Customer\'s first name<br>
@@ -1594,7 +1594,7 @@  discard block
 block discarded – undo
1594 1594
                     <strong>{invoice_due_date} :</strong> The date the invoice is due<br>
1595 1595
                     <strong>{date} :</strong> Today\'s date.<br>
1596 1596
                     <strong>{is_was} :</strong> If due date of invoice is past, displays "was" otherwise displays "is"<br>
1597
-                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing' );
1597
+                    <strong>{invoice_label} :</strong> Invoices/quotes singular name. Ex: Invoice/Quote<br>', 'invoicing');
1598 1598
                 echo apply_filters('wpinv_settings_email_wildcards_description', $description, $active_tab, $section);
1599 1599
                 ?>
1600 1600
             </p>
Please login to merge, or discard this patch.
includes/admin/wpinv-admin-functions.php 1 patch
Spacing   +235 added lines, -235 removed lines patch added patch discarded remove patch
@@ -7,245 +7,245 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14
-function wpinv_columns( $columns ) {
14
+function wpinv_columns($columns) {
15 15
     $columns = array(
16 16
         'cb'                => $columns['cb'],
17
-        'number'            => __( 'Number', 'invoicing' ),
18
-        'customer'          => __( 'Customer', 'invoicing' ),
19
-        'amount'            => __( 'Amount', 'invoicing' ),
20
-        'invoice_date'      => __( 'Created Date', 'invoicing' ),
21
-        'payment_date'      => __( 'Payment Date', 'invoicing' ),
22
-        'status'            => __( 'Status', 'invoicing' ),
23
-        'ID'                => __( 'ID', 'invoicing' ),
24
-        'wpi_actions'       => __( 'Actions', 'invoicing' ),
17
+        'number'            => __('Number', 'invoicing'),
18
+        'customer'          => __('Customer', 'invoicing'),
19
+        'amount'            => __('Amount', 'invoicing'),
20
+        'invoice_date'      => __('Created Date', 'invoicing'),
21
+        'payment_date'      => __('Payment Date', 'invoicing'),
22
+        'status'            => __('Status', 'invoicing'),
23
+        'ID'                => __('ID', 'invoicing'),
24
+        'wpi_actions'       => __('Actions', 'invoicing'),
25 25
     );
26 26
 
27
-    return apply_filters( 'wpi_invoice_table_columns', $columns );
27
+    return apply_filters('wpi_invoice_table_columns', $columns);
28 28
 }
29
-add_filter( 'manage_wpi_invoice_posts_columns', 'wpinv_columns' );
29
+add_filter('manage_wpi_invoice_posts_columns', 'wpinv_columns');
30 30
 
31
-function wpinv_bulk_actions( $actions ) {
32
-    if ( isset( $actions['edit'] ) ) {
33
-        unset( $actions['edit'] );
31
+function wpinv_bulk_actions($actions) {
32
+    if (isset($actions['edit'])) {
33
+        unset($actions['edit']);
34 34
     }
35 35
 
36 36
     return $actions;
37 37
 }
38
-add_filter( 'bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions' );
39
-add_filter( 'bulk_actions-edit-wpi_item', 'wpinv_bulk_actions' );
38
+add_filter('bulk_actions-edit-wpi_invoice', 'wpinv_bulk_actions');
39
+add_filter('bulk_actions-edit-wpi_item', 'wpinv_bulk_actions');
40 40
 
41
-function wpinv_sortable_columns( $columns ) {
41
+function wpinv_sortable_columns($columns) {
42 42
     $columns = array(
43
-        'ID'            => array( 'ID', true ),
44
-        'number'        => array( 'number', false ),
45
-        'amount'        => array( 'amount', false ),
46
-        'invoice_date'  => array( 'date', false ),
47
-        'payment_date'  => array( 'payment_date', true ),
48
-        'customer'      => array( 'customer', false ),
49
-        'status'        => array( 'status', false ),
43
+        'ID'            => array('ID', true),
44
+        'number'        => array('number', false),
45
+        'amount'        => array('amount', false),
46
+        'invoice_date'  => array('date', false),
47
+        'payment_date'  => array('payment_date', true),
48
+        'customer'      => array('customer', false),
49
+        'status'        => array('status', false),
50 50
     );
51 51
     
52
-    return apply_filters( 'wpi_invoice_table_sortable_columns', $columns );
52
+    return apply_filters('wpi_invoice_table_sortable_columns', $columns);
53 53
 }
54
-add_filter( 'manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns' );
54
+add_filter('manage_edit-wpi_invoice_sortable_columns', 'wpinv_sortable_columns');
55 55
 
56
-add_action( 'manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
-function wpinv_posts_custom_column( $column_name, $post_id = 0 ) {
56
+add_action('manage_wpi_invoice_posts_custom_column', 'wpinv_posts_custom_column');
57
+function wpinv_posts_custom_column($column_name, $post_id = 0) {
58 58
     global $post, $wpi_invoice;
59 59
     
60
-    if ( empty( $wpi_invoice ) || ( !empty( $wpi_invoice ) && $post->ID != $wpi_invoice->ID ) ) {
61
-        $wpi_invoice = new WPInv_Invoice( $post->ID );
60
+    if (empty($wpi_invoice) || (!empty($wpi_invoice) && $post->ID != $wpi_invoice->ID)) {
61
+        $wpi_invoice = new WPInv_Invoice($post->ID);
62 62
     }
63 63
 
64 64
     $value = NULL;
65 65
     
66
-    switch ( $column_name ) {
66
+    switch ($column_name) {
67 67
         case 'email' :
68
-            $value   = $wpi_invoice->get_email();
68
+            $value = $wpi_invoice->get_email();
69 69
             break;
70 70
         case 'customer' :
71 71
             $customer_name = $wpi_invoice->get_user_full_name();
72
-            $customer_name = $customer_name != '' ? $customer_name : __( 'Customer', 'invoicing' );
73
-            $value = '<a href="' . esc_url( get_edit_user_link( $wpi_invoice->get_user_id() ) ) . '">' . $customer_name . '</a>';
74
-            if ( $email = $wpi_invoice->get_email() ) {
72
+            $customer_name = $customer_name != '' ? $customer_name : __('Customer', 'invoicing');
73
+            $value = '<a href="' . esc_url(get_edit_user_link($wpi_invoice->get_user_id())) . '">' . $customer_name . '</a>';
74
+            if ($email = $wpi_invoice->get_email()) {
75 75
                 $value .= '<br><a class="email" href="mailto:' . $email . '">' . $email . '</a>';
76 76
             }
77 77
             break;
78 78
         case 'amount' :
79
-            echo $wpi_invoice->get_total( true );
79
+            echo $wpi_invoice->get_total(true);
80 80
             break;
81 81
         case 'invoice_date' :
82
-            $date_format = get_option( 'date_format' );
83
-            $time_format = get_option( 'time_format' );
84
-            $date_time_format = $date_format . ' '. $time_format;
82
+            $date_format = get_option('date_format');
83
+            $time_format = get_option('time_format');
84
+            $date_time_format = $date_format . ' ' . $time_format;
85 85
             
86 86
             $m_time = $post->post_date;
87
-            $h_time = mysql2date( $date_format, $m_time );
87
+            $h_time = mysql2date($date_format, $m_time);
88 88
             
89
-            $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
89
+            $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
90 90
             break;
91 91
         case 'payment_date' :
92
-            if ( $date_completed = $wpi_invoice->get_meta( '_wpinv_completed_date', true ) ) {
93
-                $date_format = get_option( 'date_format' );
94
-                $time_format = get_option( 'time_format' );
95
-                $date_time_format = $date_format . ' '. $time_format;
92
+            if ($date_completed = $wpi_invoice->get_meta('_wpinv_completed_date', true)) {
93
+                $date_format = get_option('date_format');
94
+                $time_format = get_option('time_format');
95
+                $date_time_format = $date_format . ' ' . $time_format;
96 96
                 
97 97
                 $m_time = $date_completed;
98
-                $h_time = mysql2date( $date_format, $m_time );
98
+                $h_time = mysql2date($date_format, $m_time);
99 99
                 
100
-                $value   = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
100
+                $value = '<abbr title="' . $m_time . '">' . $h_time . '</abbr>';
101 101
             } else {
102 102
                 $value = '-';
103 103
             }
104 104
             break;
105 105
         case 'status' :
106
-            $value   = $wpi_invoice->get_status( true ) . ( $wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '' );
107
-            $is_viewed = wpinv_is_invoice_viewed( $wpi_invoice->ID );
108
-            if ( 1 == $is_viewed ) {
109
-                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="'.__( 'Viewed by Customer', 'invoicing' ).'"></i>';
106
+            $value = $wpi_invoice->get_status(true) . ($wpi_invoice->is_recurring() && $wpi_invoice->is_parent() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '');
107
+            $is_viewed = wpinv_is_invoice_viewed($wpi_invoice->ID);
108
+            if (1 == $is_viewed) {
109
+                $value .= '&nbsp;&nbsp;<i class="fa fa-eye" title="' . __('Viewed by Customer', 'invoicing') . '"></i>';
110 110
             }
111
-            if ( ( $wpi_invoice->is_paid() || $wpi_invoice->is_refunded() ) && ( $gateway_title = wpinv_get_gateway_admin_label( $wpi_invoice->get_gateway() ) ) ) {
112
-                $value .= '<br><small class="meta gateway">' . wp_sprintf( __( 'Via %s', 'invoicing' ), $gateway_title ) . '</small>';
111
+            if (($wpi_invoice->is_paid() || $wpi_invoice->is_refunded()) && ($gateway_title = wpinv_get_gateway_admin_label($wpi_invoice->get_gateway()))) {
112
+                $value .= '<br><small class="meta gateway">' . wp_sprintf(__('Via %s', 'invoicing'), $gateway_title) . '</small>';
113 113
             }
114 114
             break;
115 115
         case 'number' :
116
-            $edit_link = get_edit_post_link( $post->ID );
117
-            $value = '<a title="' . esc_attr__( 'View Invoice Details', 'invoicing' ) . '" href="' . esc_url( $edit_link ) . '">' . $wpi_invoice->get_number() . '</a>';
116
+            $edit_link = get_edit_post_link($post->ID);
117
+            $value = '<a title="' . esc_attr__('View Invoice Details', 'invoicing') . '" href="' . esc_url($edit_link) . '">' . $wpi_invoice->get_number() . '</a>';
118 118
             break;
119 119
         case 'wpi_actions' :
120 120
             $value = '';
121
-            if ( !empty( $post->post_name ) ) {
122
-                $value .= '<a title="' . esc_attr__( 'Print invoice', 'invoicing' ) . '" href="' . esc_url( get_permalink( $post->ID ) ) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
121
+            if (!empty($post->post_name)) {
122
+                $value .= '<a title="' . esc_attr__('Print invoice', 'invoicing') . '" href="' . esc_url(get_permalink($post->ID)) . '" class="button ui-tip column-act-btn" title="" target="_blank"><span class="dashicons dashicons-print"><i style="" class="fa fa-print"></i></span></a>';
123 123
             }
124 124
             
125
-            if ( $email = $wpi_invoice->get_email() ) {
126
-                $value .= '<a title="' . esc_attr__( 'Send invoice to customer', 'invoicing' ) . '" href="' . esc_url( add_query_arg( array( 'wpi_action' => 'send_invoice', 'invoice_id' => $post->ID ) ) ) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
125
+            if ($email = $wpi_invoice->get_email()) {
126
+                $value .= '<a title="' . esc_attr__('Send invoice to customer', 'invoicing') . '" href="' . esc_url(add_query_arg(array('wpi_action' => 'send_invoice', 'invoice_id' => $post->ID))) . '" class="button ui-tip column-act-btn"><span class="dashicons dashicons-email-alt"></span></a>';
127 127
             }
128 128
             
129 129
             break;
130 130
         default:
131
-            $value = isset( $post->$column_name ) ? $post->$column_name : '';
131
+            $value = isset($post->$column_name) ? $post->$column_name : '';
132 132
             break;
133 133
 
134 134
     }
135
-    $value = apply_filters( 'wpinv_payments_table_column', $value, $post->ID, $column_name );
135
+    $value = apply_filters('wpinv_payments_table_column', $value, $post->ID, $column_name);
136 136
     
137
-    if ( $value !== NULL ) {
137
+    if ($value !== NULL) {
138 138
         echo $value;
139 139
     }
140 140
 }
141 141
 
142
-function wpinv_admin_post_id( $id = 0 ) {
142
+function wpinv_admin_post_id($id = 0) {
143 143
     global $post;
144 144
 
145
-    if ( isset( $id ) && ! empty( $id ) ) {
145
+    if (isset($id) && !empty($id)) {
146 146
         return (int)$id;
147
-    } else if ( get_the_ID() ) {
148
-        return (int) get_the_ID();
149
-    } else if ( isset( $post->ID ) && !empty( $post->ID ) ) {
150
-        return (int) $post->ID;
151
-    } else if ( isset( $_GET['post'] ) && !empty( $_GET['post'] ) ) {
152
-        return (int) $_GET['post'];
153
-    } else if ( isset( $_GET['id'] ) && !empty( $_GET['id'] ) ) {
154
-        return (int) $_GET['id'];
155
-    } else if ( isset( $_POST['id'] ) && !empty( $_POST['id'] ) ) {
156
-        return (int) $_POST['id'];
147
+    } else if (get_the_ID()) {
148
+        return (int)get_the_ID();
149
+    } else if (isset($post->ID) && !empty($post->ID)) {
150
+        return (int)$post->ID;
151
+    } else if (isset($_GET['post']) && !empty($_GET['post'])) {
152
+        return (int)$_GET['post'];
153
+    } else if (isset($_GET['id']) && !empty($_GET['id'])) {
154
+        return (int)$_GET['id'];
155
+    } else if (isset($_POST['id']) && !empty($_POST['id'])) {
156
+        return (int)$_POST['id'];
157 157
     } 
158 158
 
159 159
     return null;
160 160
 }
161 161
     
162
-function wpinv_admin_post_type( $id = 0 ) {
163
-    if ( !$id ) {
162
+function wpinv_admin_post_type($id = 0) {
163
+    if (!$id) {
164 164
         $id = wpinv_admin_post_id();
165 165
     }
166 166
     
167
-    $type = get_post_type( $id );
167
+    $type = get_post_type($id);
168 168
     
169
-    if ( !$type ) {
170
-        $type = isset( $_GET['post_type'] ) && !empty( $_GET['post_type'] ) ? $_GET['post_type'] : null;
169
+    if (!$type) {
170
+        $type = isset($_GET['post_type']) && !empty($_GET['post_type']) ? $_GET['post_type'] : null;
171 171
     }
172 172
     
173
-    return apply_filters( 'wpinv_admin_post_type', $type, $id );
173
+    return apply_filters('wpinv_admin_post_type', $type, $id);
174 174
 }
175 175
 
176 176
 function wpinv_admin_messages() {
177 177
 	global $wpinv_options, $pagenow, $post;
178 178
 
179
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
180
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-added', __( 'Discount code added.', 'invoicing' ), 'updated' );
179
+	if (isset($_GET['wpinv-message']) && 'discount_added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
180
+		 add_settings_error('wpinv-notices', 'wpinv-discount-added', __('Discount code added.', 'invoicing'), 'updated');
181 181
 	}
182 182
 
183
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
184
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-add-fail', __( 'There was a problem adding your discount code, please try again.', 'invoicing' ), 'error' );
183
+	if (isset($_GET['wpinv-message']) && 'discount_add_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
184
+		add_settings_error('wpinv-notices', 'wpinv-discount-add-fail', __('There was a problem adding your discount code, please try again.', 'invoicing'), 'error');
185 185
 	}
186 186
 
187
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
188
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-exists', __( 'A discount with that code already exists, please use a different code.', 'invoicing' ), 'error' );
187
+	if (isset($_GET['wpinv-message']) && 'discount_exists' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
188
+		add_settings_error('wpinv-notices', 'wpinv-discount-exists', __('A discount with that code already exists, please use a different code.', 'invoicing'), 'error');
189 189
 	}
190 190
 
191
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
192
-		 add_settings_error( 'wpinv-notices', 'wpinv-discount-updated', __( 'Discount code updated.', 'invoicing' ), 'updated' );
191
+	if (isset($_GET['wpinv-message']) && 'discount_updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
192
+		 add_settings_error('wpinv-notices', 'wpinv-discount-updated', __('Discount code updated.', 'invoicing'), 'updated');
193 193
 	}
194 194
 
195
-	if ( isset( $_GET['wpinv-message'] ) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
196
-		add_settings_error( 'wpinv-notices', 'wpinv-discount-updated-fail', __( 'There was a problem updating your discount code, please try again.', 'invoicing' ), 'error' );
195
+	if (isset($_GET['wpinv-message']) && 'discount_update_failed' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
196
+		add_settings_error('wpinv-notices', 'wpinv-discount-updated-fail', __('There was a problem updating your discount code, please try again.', 'invoicing'), 'error');
197 197
 	}
198 198
 
199
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
200
-		add_settings_error( 'wpinv-notices', 'wpinv-deleted', __( 'The invoice has been deleted.', 'invoicing' ), 'updated' );
199
+	if (isset($_GET['wpinv-message']) && 'invoice_deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
200
+		add_settings_error('wpinv-notices', 'wpinv-deleted', __('The invoice has been deleted.', 'invoicing'), 'updated');
201 201
 	}
202 202
 
203
-	if ( isset( $_GET['wpinv-message'] ) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
204
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Email notification is disabled. Please check settings.', 'invoicing' ), 'error' );
203
+	if (isset($_GET['wpinv-message']) && 'email_disabled' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
204
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Email notification is disabled. Please check settings.', 'invoicing'), 'error');
205 205
 	}
206 206
 
207
-	if ( isset( $_GET['wpinv-message'] ) && 'email_sent' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
208
-		add_settings_error( 'wpinv-notices', 'wpinv-sent', __( 'The email has been sent to customer.', 'invoicing' ), 'updated' );
207
+	if (isset($_GET['wpinv-message']) && 'email_sent' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
208
+		add_settings_error('wpinv-notices', 'wpinv-sent', __('The email has been sent to customer.', 'invoicing'), 'updated');
209 209
     }
210 210
     
211
-    if ( isset( $_GET['wpinv-message'] ) && 'email_fail' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
212
-		add_settings_error( 'wpinv-notices', 'wpinv-sent-fail', __( 'Fail to send email to the customer.', 'invoicing' ), 'error' );
211
+    if (isset($_GET['wpinv-message']) && 'email_fail' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
212
+		add_settings_error('wpinv-notices', 'wpinv-sent-fail', __('Fail to send email to the customer.', 'invoicing'), 'error');
213 213
     }
214 214
 
215
-    if ( isset( $_GET['wpinv-message'] ) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
216
-        add_settings_error( 'wpinv-notices', 'wpinv-note-deleted', __( 'The invoice note has been deleted.', 'invoicing' ), 'updated' );
215
+    if (isset($_GET['wpinv-message']) && 'invoice-note-deleted' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
216
+        add_settings_error('wpinv-notices', 'wpinv-note-deleted', __('The invoice note has been deleted.', 'invoicing'), 'updated');
217 217
     }
218 218
 
219
-	if ( isset( $_GET['wpinv-message'] ) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
220
-		add_settings_error( 'wpinv-notices', 'wpinv-settings-imported', __( 'The settings have been imported.', 'invoicing' ), 'updated' );
219
+	if (isset($_GET['wpinv-message']) && 'settings-imported' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
220
+		add_settings_error('wpinv-notices', 'wpinv-settings-imported', __('The settings have been imported.', 'invoicing'), 'updated');
221 221
 	}
222 222
 
223
-	if ( isset( $_GET['wpinv-message'] ) && 'note-added' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
224
-		add_settings_error( 'wpinv-notices', 'wpinv-note-added', __( 'The invoice note has been added successfully.', 'invoicing' ), 'updated' );
223
+	if (isset($_GET['wpinv-message']) && 'note-added' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
224
+		add_settings_error('wpinv-notices', 'wpinv-note-added', __('The invoice note has been added successfully.', 'invoicing'), 'updated');
225 225
 	}
226 226
 
227
-	if ( isset( $_GET['wpinv-message'] ) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can( 'manage_options' ) ) {
228
-		add_settings_error( 'wpinv-notices', 'wpinv-updated', __( 'The invoice has been successfully updated.', 'invoicing' ), 'updated' );
227
+	if (isset($_GET['wpinv-message']) && 'invoice-updated' == $_GET['wpinv-message'] && current_user_can('manage_options')) {
228
+		add_settings_error('wpinv-notices', 'wpinv-updated', __('The invoice has been successfully updated.', 'invoicing'), 'updated');
229 229
 	}
230 230
     
231
-	if ( $pagenow == 'post.php' && !empty( $post->post_type ) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable( $post ) ) {
232
-		$message = apply_filters( 'wpinv_item_non_editable_message', __( 'This item in not editable.', 'invoicing' ), $post->ID );
231
+	if ($pagenow == 'post.php' && !empty($post->post_type) && $post->post_type == 'wpi_item' && !wpinv_item_is_editable($post)) {
232
+		$message = apply_filters('wpinv_item_non_editable_message', __('This item in not editable.', 'invoicing'), $post->ID);
233 233
 
234
-		if ( !empty( $message ) ) {
235
-			add_settings_error( 'wpinv-notices', 'wpinv-edit-n', $message, 'updated' );
234
+		if (!empty($message)) {
235
+			add_settings_error('wpinv-notices', 'wpinv-edit-n', $message, 'updated');
236 236
 		}
237 237
 	}
238 238
 
239
-	settings_errors( 'wpinv-notices' );
239
+	settings_errors('wpinv-notices');
240 240
 }
241
-add_action( 'admin_notices', 'wpinv_admin_messages' );
241
+add_action('admin_notices', 'wpinv_admin_messages');
242 242
 
243
-add_action( 'admin_init', 'wpinv_show_test_payment_gateway_notice' );
244
-function wpinv_show_test_payment_gateway_notice(){
245
-    add_action( 'admin_notices', 'wpinv_test_payment_gateway_messages' );
243
+add_action('admin_init', 'wpinv_show_test_payment_gateway_notice');
244
+function wpinv_show_test_payment_gateway_notice() {
245
+    add_action('admin_notices', 'wpinv_test_payment_gateway_messages');
246 246
 }
247 247
 
248
-function wpinv_test_payment_gateway_messages(){
248
+function wpinv_test_payment_gateway_messages() {
249 249
     $gateways = wpinv_get_enabled_payment_gateways();
250 250
     $name = array(); $test_gateways = '';
251 251
     if ($gateways) {
@@ -256,9 +256,9 @@  discard block
 block discarded – undo
256 256
         }
257 257
         $test_gateways = implode(', ', $name);
258 258
     }
259
-    if(isset($test_gateways) && !empty($test_gateways)){
259
+    if (isset($test_gateways) && !empty($test_gateways)) {
260 260
         $link = admin_url('admin.php?page=wpinv-settings&tab=gateways');
261
-        $notice = wp_sprintf( __('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link );
261
+        $notice = wp_sprintf(__('<strong>Important:</strong> Payment Gateway(s) %s are in testing mode and will not receive real payments. Go to <a href="%s"> Gateway Settings</a>.', 'invoicing'), $test_gateways, $link);
262 262
         ?>
263 263
         <div class="notice notice-warning is-dismissible">
264 264
             <p><?php echo $notice; ?></p>
@@ -267,29 +267,29 @@  discard block
 block discarded – undo
267 267
     }
268 268
 }
269 269
 
270
-function wpinv_items_columns( $existing_columns ) {
270
+function wpinv_items_columns($existing_columns) {
271 271
     global $wpinv_euvat;
272 272
     
273 273
     $columns                = array();
274 274
     $columns['cb']          = $existing_columns['cb'];
275
-    $columns['title']       = __( 'Title', 'invoicing' );
276
-    $columns['price']       = __( 'Price', 'invoicing' );
277
-    if ( $wpinv_euvat->allow_vat_rules() ) {
278
-        $columns['vat_rule']    = __( 'VAT rule type', 'invoicing' );
275
+    $columns['title']       = __('Title', 'invoicing');
276
+    $columns['price']       = __('Price', 'invoicing');
277
+    if ($wpinv_euvat->allow_vat_rules()) {
278
+        $columns['vat_rule']    = __('VAT rule type', 'invoicing');
279 279
     }
280
-    if ( $wpinv_euvat->allow_vat_classes() ) {
281
-        $columns['vat_class']   = __( 'VAT class', 'invoicing' );
280
+    if ($wpinv_euvat->allow_vat_classes()) {
281
+        $columns['vat_class']   = __('VAT class', 'invoicing');
282 282
     }
283
-    $columns['type']        = __( 'Type', 'invoicing' );
284
-    $columns['recurring']   = __( 'Recurring', 'invoicing' );
285
-    $columns['date']        = __( 'Date', 'invoicing' );
286
-    $columns['id']          = __( 'ID', 'invoicing' );
283
+    $columns['type']        = __('Type', 'invoicing');
284
+    $columns['recurring']   = __('Recurring', 'invoicing');
285
+    $columns['date']        = __('Date', 'invoicing');
286
+    $columns['id']          = __('ID', 'invoicing');
287 287
 
288
-    return apply_filters( 'wpinv_items_columns', $columns );
288
+    return apply_filters('wpinv_items_columns', $columns);
289 289
 }
290
-add_filter( 'manage_wpi_item_posts_columns', 'wpinv_items_columns' );
290
+add_filter('manage_wpi_item_posts_columns', 'wpinv_items_columns');
291 291
 
292
-function wpinv_items_sortable_columns( $columns ) {
292
+function wpinv_items_sortable_columns($columns) {
293 293
     $columns['price']       = 'price';
294 294
     $columns['vat_rule']    = 'vat_rule';
295 295
     $columns['vat_class']   = 'vat_class';
@@ -299,151 +299,151 @@  discard block
 block discarded – undo
299 299
 
300 300
     return $columns;
301 301
 }
302
-add_filter( 'manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns' );
302
+add_filter('manage_edit-wpi_item_sortable_columns', 'wpinv_items_sortable_columns');
303 303
 
304
-function wpinv_items_table_custom_column( $column ) {
304
+function wpinv_items_table_custom_column($column) {
305 305
     global $wpinv_euvat, $post, $wpi_item;
306 306
     
307
-    if ( empty( $wpi_item ) || ( !empty( $wpi_item ) && $post->ID != $wpi_item->ID ) ) {
308
-        $wpi_item = new WPInv_Item( $post->ID );
307
+    if (empty($wpi_item) || (!empty($wpi_item) && $post->ID != $wpi_item->ID)) {
308
+        $wpi_item = new WPInv_Item($post->ID);
309 309
     }
310 310
 
311
-    switch ( $column ) {
311
+    switch ($column) {
312 312
         case 'price' :
313
-            echo wpinv_item_price( $post->ID );
313
+            echo wpinv_item_price($post->ID);
314 314
         break;
315 315
         case 'vat_rule' :
316
-            echo $wpinv_euvat->item_rule_label( $post->ID );
316
+            echo $wpinv_euvat->item_rule_label($post->ID);
317 317
         break;
318 318
         case 'vat_class' :
319
-            echo $wpinv_euvat->item_class_label( $post->ID );
319
+            echo $wpinv_euvat->item_class_label($post->ID);
320 320
         break;
321 321
         case 'type' :
322
-            echo wpinv_item_type( $post->ID ) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
322
+            echo wpinv_item_type($post->ID) . '<span class="meta">' . $wpi_item->get_custom_singular_name() . '</span>';
323 323
         break;
324 324
         case 'recurring' :
325
-            echo ( wpinv_is_recurring_item( $post->ID ) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>' );
325
+            echo (wpinv_is_recurring_item($post->ID) ? '<i class="fa fa-check fa-recurring-y"></i>' : '<i class="fa fa-close fa-recurring-n"></i>');
326 326
         break;
327 327
         case 'id' :
328 328
            echo $post->ID;
329 329
            echo '<div class="hidden" id="wpinv_inline-' . $post->ID . '">
330
-                    <div class="price">' . wpinv_get_item_price( $post->ID ) . '</div>';
331
-                    if ( $wpinv_euvat->allow_vat_rules() ) {
332
-                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule( $post->ID ) . '</div>';
330
+                    <div class="price">' . wpinv_get_item_price($post->ID) . '</div>';
331
+                    if ($wpinv_euvat->allow_vat_rules()) {
332
+                        echo '<div class="vat_rule">' . $wpinv_euvat->get_item_rule($post->ID) . '</div>';
333 333
                     }
334
-                    if ( $wpinv_euvat->allow_vat_classes() ) {
335
-                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class( $post->ID ) . '</div>';
334
+                    if ($wpinv_euvat->allow_vat_classes()) {
335
+                        echo '<div class="vat_class">' . $wpinv_euvat->get_item_class($post->ID) . '</div>';
336 336
                     }
337
-                    echo '<div class="type">' . wpinv_get_item_type( $post->ID ) . '</div>
337
+                    echo '<div class="type">' . wpinv_get_item_type($post->ID) . '</div>
338 338
                 </div>';
339 339
         break;
340 340
     }
341 341
     
342
-    do_action( 'wpinv_items_table_column_item_' . $column, $wpi_item, $post );
342
+    do_action('wpinv_items_table_column_item_' . $column, $wpi_item, $post);
343 343
 }
344
-add_action( 'manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column' );
344
+add_action('manage_wpi_item_posts_custom_column', 'wpinv_items_table_custom_column');
345 345
 
346 346
 function wpinv_add_items_filters() {
347 347
     global $wpinv_euvat, $typenow;
348 348
 
349 349
     // Checks if the current post type is 'item'
350
-    if ( $typenow == 'wpi_item') {
351
-        if ( $wpinv_euvat->allow_vat_rules() ) {
352
-            echo wpinv_html_select( array(
353
-                    'options'          => array_merge( array( '' => __( 'All VAT rules', 'invoicing' ) ), $wpinv_euvat->get_rules() ),
350
+    if ($typenow == 'wpi_item') {
351
+        if ($wpinv_euvat->allow_vat_rules()) {
352
+            echo wpinv_html_select(array(
353
+                    'options'          => array_merge(array('' => __('All VAT rules', 'invoicing')), $wpinv_euvat->get_rules()),
354 354
                     'name'             => 'vat_rule',
355 355
                     'id'               => 'vat_rule',
356
-                    'selected'         => ( isset( $_GET['vat_rule'] ) ? $_GET['vat_rule'] : '' ),
356
+                    'selected'         => (isset($_GET['vat_rule']) ? $_GET['vat_rule'] : ''),
357 357
                     'show_option_all'  => false,
358 358
                     'show_option_none' => false,
359 359
                     'class'            => 'gdmbx2-text-medium',
360
-                ) );
360
+                ));
361 361
         }
362 362
         
363
-        if ( $wpinv_euvat->allow_vat_classes() ) {
364
-            echo wpinv_html_select( array(
365
-                    'options'          => array_merge( array( '' => __( 'All VAT classes', 'invoicing' ) ), $wpinv_euvat->get_all_classes() ),
363
+        if ($wpinv_euvat->allow_vat_classes()) {
364
+            echo wpinv_html_select(array(
365
+                    'options'          => array_merge(array('' => __('All VAT classes', 'invoicing')), $wpinv_euvat->get_all_classes()),
366 366
                     'name'             => 'vat_class',
367 367
                     'id'               => 'vat_class',
368
-                    'selected'         => ( isset( $_GET['vat_class'] ) ? $_GET['vat_class'] : '' ),
368
+                    'selected'         => (isset($_GET['vat_class']) ? $_GET['vat_class'] : ''),
369 369
                     'show_option_all'  => false,
370 370
                     'show_option_none' => false,
371 371
                     'class'            => 'gdmbx2-text-medium',
372
-                ) );
372
+                ));
373 373
         }
374 374
             
375
-        echo wpinv_html_select( array(
376
-                'options'          => array_merge( array( '' => __( 'All item types', 'invoicing' ) ), wpinv_get_item_types() ),
375
+        echo wpinv_html_select(array(
376
+                'options'          => array_merge(array('' => __('All item types', 'invoicing')), wpinv_get_item_types()),
377 377
                 'name'             => 'type',
378 378
                 'id'               => 'type',
379
-                'selected'         => ( isset( $_GET['type'] ) ? $_GET['type'] : '' ),
379
+                'selected'         => (isset($_GET['type']) ? $_GET['type'] : ''),
380 380
                 'show_option_all'  => false,
381 381
                 'show_option_none' => false,
382 382
                 'class'            => 'gdmbx2-text-medium',
383
-            ) );
383
+            ));
384 384
 
385
-        if ( isset( $_REQUEST['all_posts'] ) && '1' === $_REQUEST['all_posts'] ) {
385
+        if (isset($_REQUEST['all_posts']) && '1' === $_REQUEST['all_posts']) {
386 386
             echo '<input type="hidden" name="all_posts" value="1" />';
387 387
         }
388 388
     }
389 389
 }
390
-add_action( 'restrict_manage_posts', 'wpinv_add_items_filters', 100 );
390
+add_action('restrict_manage_posts', 'wpinv_add_items_filters', 100);
391 391
 
392
-function wpinv_send_invoice_after_save( $invoice ) {
393
-    if ( empty( $_POST['wpi_save_send'] ) ) {
392
+function wpinv_send_invoice_after_save($invoice) {
393
+    if (empty($_POST['wpi_save_send'])) {
394 394
         return;
395 395
     }
396 396
     
397
-    if ( !empty( $invoice->ID ) && !empty( $invoice->post_type ) && 'wpi_invoice' == $invoice->post_type ) {
398
-        wpinv_user_invoice_notification( $invoice->ID );
397
+    if (!empty($invoice->ID) && !empty($invoice->post_type) && 'wpi_invoice' == $invoice->post_type) {
398
+        wpinv_user_invoice_notification($invoice->ID);
399 399
     }
400 400
 }
401
-add_action( 'wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1 );
401
+add_action('wpinv_invoice_metabox_saved', 'wpinv_send_invoice_after_save', 100, 1);
402 402
 
403
-function wpinv_send_register_new_user( $data, $postarr ) {
404
-    if ( current_user_can( 'manage_options' ) && !empty( $data['post_type'] ) && ( 'wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'] ) ) {
405
-        $is_new_user = !empty( $postarr['wpinv_new_user'] ) ? true : false;
406
-        $email = !empty( $postarr['wpinv_email'] ) && $postarr['wpinv_email'] && is_email( $postarr['wpinv_email'] ) ? $postarr['wpinv_email'] : NULL;
403
+function wpinv_send_register_new_user($data, $postarr) {
404
+    if (current_user_can('manage_options') && !empty($data['post_type']) && ('wpi_invoice' == $data['post_type'] || 'wpi_quote' == $data['post_type'])) {
405
+        $is_new_user = !empty($postarr['wpinv_new_user']) ? true : false;
406
+        $email = !empty($postarr['wpinv_email']) && $postarr['wpinv_email'] && is_email($postarr['wpinv_email']) ? $postarr['wpinv_email'] : NULL;
407 407
         
408
-        if ( $is_new_user && $email && !email_exists( $email ) ) {
409
-            $first_name = !empty( $postarr['wpinv_first_name'] ) ? sanitize_text_field( $postarr['wpinv_first_name'] ) : '';
410
-            $last_name = !empty( $postarr['wpinv_last_name'] ) ? sanitize_text_field( $postarr['wpinv_last_name'] ) : '';
411
-            $display_name = $first_name || $last_name ? trim( $first_name . ' ' . $last_name ) : '';
412
-            $user_nicename = $display_name ? trim( $display_name ) : $email;
413
-            $user_company = !empty( $postarr['wpinv_company'] ) ? sanitize_text_field( $postarr['wpinv_company'] ) : '';
408
+        if ($is_new_user && $email && !email_exists($email)) {
409
+            $first_name = !empty($postarr['wpinv_first_name']) ? sanitize_text_field($postarr['wpinv_first_name']) : '';
410
+            $last_name = !empty($postarr['wpinv_last_name']) ? sanitize_text_field($postarr['wpinv_last_name']) : '';
411
+            $display_name = $first_name || $last_name ? trim($first_name . ' ' . $last_name) : '';
412
+            $user_nicename = $display_name ? trim($display_name) : $email;
413
+            $user_company = !empty($postarr['wpinv_company']) ? sanitize_text_field($postarr['wpinv_company']) : '';
414 414
             
415
-            $user_login = sanitize_user( str_replace( ' ', '', $display_name ), true );
416
-            if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
415
+            $user_login = sanitize_user(str_replace(' ', '', $display_name), true);
416
+            if (!(validate_username($user_login) && !username_exists($user_login))) {
417 417
                 $new_user_login = strstr($email, '@', true);
418
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
419
-                    $user_login = sanitize_user($new_user_login, true );
418
+                if (validate_username($user_login) && username_exists($user_login)) {
419
+                    $user_login = sanitize_user($new_user_login, true);
420 420
                 }
421
-                if ( validate_username( $user_login ) && username_exists( $user_login ) ) {
422
-                    $user_append_text = rand(10,1000);
423
-                    $user_login = sanitize_user($new_user_login.$user_append_text, true );
421
+                if (validate_username($user_login) && username_exists($user_login)) {
422
+                    $user_append_text = rand(10, 1000);
423
+                    $user_login = sanitize_user($new_user_login . $user_append_text, true);
424 424
                 }
425 425
                 
426
-                if ( !( validate_username( $user_login ) && !username_exists( $user_login ) ) ) {
426
+                if (!(validate_username($user_login) && !username_exists($user_login))) {
427 427
                     $user_login = $email;
428 428
                 }
429 429
             }
430 430
             
431 431
             $userdata = array(
432 432
                 'user_login' => $user_login,
433
-                'user_pass' => wp_generate_password( 12, false ),
434
-                'user_email' => sanitize_text_field( $email ),
433
+                'user_pass' => wp_generate_password(12, false),
434
+                'user_email' => sanitize_text_field($email),
435 435
                 'first_name' => $first_name,
436 436
                 'last_name' => $last_name,
437
-                'user_nicename' => wpinv_utf8_substr( $user_nicename, 0, 50 ),
437
+                'user_nicename' => wpinv_utf8_substr($user_nicename, 0, 50),
438 438
                 'nickname' => $display_name,
439 439
                 'display_name' => $display_name,
440 440
             );
441 441
 
442
-            $userdata = apply_filters( 'wpinv_register_new_user_data', $userdata );
442
+            $userdata = apply_filters('wpinv_register_new_user_data', $userdata);
443 443
             
444
-            $new_user_id = wp_insert_user( $userdata );
444
+            $new_user_id = wp_insert_user($userdata);
445 445
             
446
-            if ( !is_wp_error( $new_user_id ) ) {
446
+            if (!is_wp_error($new_user_id)) {
447 447
                 $data['post_author'] = $new_user_id;
448 448
                 $_POST['post_author'] = $new_user_id;
449 449
                 $_POST['post_author_override'] = $new_user_id;
@@ -464,72 +464,72 @@  discard block
 block discarded – undo
464 464
                 
465 465
                 $meta = array();
466 466
                 ///$meta['_wpinv_user_id'] = $new_user_id;
467
-                foreach ( $meta_fields as $field ) {
468
-                    $meta['_wpinv_' . $field] = isset( $postarr['wpinv_' . $field] ) ? sanitize_text_field( $postarr['wpinv_' . $field] ) : '';
467
+                foreach ($meta_fields as $field) {
468
+                    $meta['_wpinv_' . $field] = isset($postarr['wpinv_' . $field]) ? sanitize_text_field($postarr['wpinv_' . $field]) : '';
469 469
                 }
470 470
                 
471
-                $meta = apply_filters( 'wpinv_register_new_user_meta', $meta, $new_user_id );
471
+                $meta = apply_filters('wpinv_register_new_user_meta', $meta, $new_user_id);
472 472
 
473 473
                 // Update user meta.
474
-                foreach ( $meta as $key => $value ) {
475
-                    update_user_meta( $new_user_id, $key, $value );
474
+                foreach ($meta as $key => $value) {
475
+                    update_user_meta($new_user_id, $key, $value);
476 476
                 }
477 477
                 
478
-                if ( function_exists( 'wp_send_new_user_notifications' ) ) {
478
+                if (function_exists('wp_send_new_user_notifications')) {
479 479
                     // Send email notifications related to the creation of new user.
480
-                    wp_send_new_user_notifications( $new_user_id, 'user' );
480
+                    wp_send_new_user_notifications($new_user_id, 'user');
481 481
                 }
482 482
             } else {
483
-                wpinv_error_log( $new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__ );
483
+                wpinv_error_log($new_user_id->get_error_message(), 'Invoice add new user', __FILE__, __LINE__);
484 484
             }
485 485
         }
486 486
     }
487 487
     
488 488
     return $data;
489 489
 }
490
-add_filter( 'wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2 );
490
+add_filter('wp_insert_post_data', 'wpinv_send_register_new_user', 10, 2);
491 491
 
492
-function wpinv_show_recurring_supported_gateways( $item_ID ) {
492
+function wpinv_show_recurring_supported_gateways($item_ID) {
493 493
     $all_gateways = wpinv_get_payment_gateways();
494 494
 
495
-    if ( !empty( $all_gateways ) ) {
495
+    if (!empty($all_gateways)) {
496 496
         $gateways = array();
497 497
 
498
-        foreach ( $all_gateways as $key => $gateway ) {
499
-            if ( wpinv_gateway_support_subscription( $key ) ) {
498
+        foreach ($all_gateways as $key => $gateway) {
499
+            if (wpinv_gateway_support_subscription($key)) {
500 500
                 $gateways[] = $gateway['admin_label'];
501 501
             }
502 502
         }
503 503
 
504
-        if ( !empty( $gateways ) ) {
504
+        if (!empty($gateways)) {
505 505
             ?>
506
-            <span class="description"><?php echo wp_sprintf( __( 'Recurring payments only supported by: %s', 'invoicing' ), implode( ', ', $gateways ) ); ?></span>
506
+            <span class="description"><?php echo wp_sprintf(__('Recurring payments only supported by: %s', 'invoicing'), implode(', ', $gateways)); ?></span>
507 507
             <?php
508 508
         }
509 509
     }
510 510
 }
511
-add_action( 'wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1 );
511
+add_action('wpinv_item_price_field', 'wpinv_show_recurring_supported_gateways', -10, 1);
512 512
 
513
-function wpinv_post_updated_messages( $messages ) {
513
+function wpinv_post_updated_messages($messages) {
514 514
     global $post, $post_ID;
515 515
 
516 516
     $messages['wpi_discount'] = array(
517 517
         0   => '',
518
-        1   => __( 'Discount updated.', 'invoicing' ),
519
-        2   => __( 'Custom field updated.', 'invoicing' ),
520
-        3   => __( 'Custom field deleted.', 'invoicing' ),
521
-        4   => __( 'Discount updated.', 'invoicing' ),
522
-        5   => isset( $_GET['revision'] ) ? wp_sprintf( __( 'Discount restored to revision from %s', 'invoicing' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
523
-        6   => __( 'Discount updated.', 'invoicing' ),
524
-        7   => __( 'Discount saved.', 'invoicing' ),
525
-        8   => __( 'Discount submitted.', 'invoicing' ),
526
-        9   => wp_sprintf( __( 'Discount scheduled for: <strong>%1$s</strong>.', 'invoicing' ), date_i18n( __( 'M j, Y @ G:i', 'invoicing' ), strtotime( $post->post_date ) ) ),
527
-        10  => __( 'Discount draft updated.', 'invoicing' ),
518
+        1   => __('Discount updated.', 'invoicing'),
519
+        2   => __('Custom field updated.', 'invoicing'),
520
+        3   => __('Custom field deleted.', 'invoicing'),
521
+        4   => __('Discount updated.', 'invoicing'),
522
+        5   => isset($_GET['revision']) ? wp_sprintf(__('Discount restored to revision from %s', 'invoicing'), wp_post_revision_title((int)$_GET['revision'], false)) : false,
523
+        6   => __('Discount updated.', 'invoicing'),
524
+        7   => __('Discount saved.', 'invoicing'),
525
+        8   => __('Discount submitted.', 'invoicing'),
526
+        9   => wp_sprintf(__('Discount scheduled for: <strong>%1$s</strong>.', 'invoicing'), date_i18n(__('M j, Y @ G:i', 'invoicing'), strtotime($post->post_date))),
527
+        10  => __('Discount draft updated.', 'invoicing'),
528 528
     );
529 529
 
530 530
     return $messages;
531 531
 }
532
-add_filter( 'post_updated_messages', 'wpinv_post_updated_messages', 10, 1 );
532
+add_filter('post_updated_messages', 'wpinv_post_updated_messages', 10, 1);
533 533
 
534 534
 add_action('admin_init', 'admin_init_example_type');
535 535
 
@@ -539,7 +539,7 @@  discard block
 block discarded – undo
539 539
 function admin_init_example_type() {
540 540
     global $typenow;
541 541
 
542
-    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote' ) {
542
+    if ($typenow === 'wpi_invoice' || $typenow === 'wpi_quote') {
543 543
         add_filter('posts_search', 'posts_search_example_type', 10, 2);
544 544
     }
545 545
 }
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
     global $wpdb;
555 555
 
556 556
     if ($query->is_main_query() && !empty($query->query['s'])) {
557
-        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql( $query->query['s'] ) . "%' )";
558
-        if ( ! empty( $search ) ) {
559
-            $search = preg_replace( '/^ AND /', '', $search );
557
+        $conditions_str = "{$wpdb->posts}.post_author IN ( SELECT ID FROM {$wpdb->users} WHERE user_email LIKE '%" . esc_sql($query->query['s']) . "%' )";
558
+        if (!empty($search)) {
559
+            $search = preg_replace('/^ AND /', '', $search);
560 560
             $search = " AND ( {$search} OR ( {$conditions_str} ) )";
561 561
         } else {
562 562
             $search = " AND ( {$conditions_str} )";
@@ -566,9 +566,9 @@  discard block
 block discarded – undo
566 566
     return $search;
567 567
 }
568 568
 
569
-add_action( 'admin_init', 'wpinv_reset_invoice_count' );
570
-function wpinv_reset_invoice_count(){
571
-    if(isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
569
+add_action('admin_init', 'wpinv_reset_invoice_count');
570
+function wpinv_reset_invoice_count() {
571
+    if (isset($_GET['reset_invoice_count']) && 1 == $_GET['reset_invoice_count'] && isset($_GET['_nonce']) && wp_verify_nonce($_GET['_nonce'], 'reset_invoice_count')) {
572 572
         wpinv_update_option('invoice_sequence_start', 1);
573 573
         delete_option('wpinv_last_invoice_number');
574 574
         $url = add_query_arg(array('reset_invoice_done' => 1));
@@ -579,8 +579,8 @@  discard block
 block discarded – undo
579 579
 }
580 580
 
581 581
 add_action('admin_notices', 'wpinv_invoice_count_reset_message');
582
-function wpinv_invoice_count_reset_message(){
583
-    if(isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
582
+function wpinv_invoice_count_reset_message() {
583
+    if (isset($_GET['reset_invoice_done']) && 1 == $_GET['reset_invoice_done']) {
584 584
         $notice = __('Invoice number sequence reset successfully.', 'invoicing');
585 585
         ?>
586 586
         <div class="notice notice-success is-dismissible">
Please login to merge, or discard this patch.
includes/wpinv-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,47 +1774,47 @@  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
     // Get results.
1806
-    $invoices = new WP_Query( $wp_query_args );
1806
+    $invoices = new WP_Query($wp_query_args);
1807 1807
 
1808
-    if ( 'objects' === $args['return'] ) {
1809
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1810
-    } elseif ( 'self' === $args['return'] ) {
1808
+    if ('objects' === $args['return']) {
1809
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1810
+    } elseif ('self' === $args['return']) {
1811 1811
         return $invoices;
1812 1812
     } else {
1813 1813
         $return = $invoices->posts;
1814 1814
     }
1815 1815
 
1816
-    if ( $args['paginate' ] ) {
1817
-        return (object) array(
1816
+    if ($args['paginate']) {
1817
+        return (object)array(
1818 1818
             'invoices'      => $return,
1819 1819
             'total'         => $invoices->found_posts,
1820 1820
             'max_num_pages' => $invoices->max_num_pages,
@@ -1826,22 +1826,22 @@  discard block
 block discarded – undo
1826 1826
 
1827 1827
 function wpinv_get_user_invoices_columns() {
1828 1828
     $columns = array(
1829
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1830
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1831
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1832
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1833
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1834
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1829
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1830
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1831
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1832
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1833
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1834
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1835 1835
         );
1836 1836
 
1837
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1837
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1838 1838
 }
1839 1839
 
1840
-function wpinv_payment_receipt( $atts, $content = null ) {
1840
+function wpinv_payment_receipt($atts, $content = null) {
1841 1841
     global $wpinv_receipt_args;
1842 1842
 
1843
-    $wpinv_receipt_args = shortcode_atts( array(
1844
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1843
+    $wpinv_receipt_args = shortcode_atts(array(
1844
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1845 1845
         'price'           => true,
1846 1846
         'discount'        => true,
1847 1847
         'items'           => true,
@@ -1850,195 +1850,195 @@  discard block
 block discarded – undo
1850 1850
         'invoice_key'     => false,
1851 1851
         'payment_method'  => true,
1852 1852
         'invoice_id'      => true
1853
-    ), $atts, 'wpinv_receipt' );
1853
+    ), $atts, 'wpinv_receipt');
1854 1854
 
1855 1855
     $session = wpinv_get_checkout_session();
1856
-    if ( isset( $_GET['invoice_key'] ) ) {
1857
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1858
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1856
+    if (isset($_GET['invoice_key'])) {
1857
+        $invoice_key = urldecode($_GET['invoice_key']);
1858
+    } else if ($session && isset($session['invoice_key'])) {
1859 1859
         $invoice_key = $session['invoice_key'];
1860
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1860
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1861 1861
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1862
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1863
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1862
+    } else if (isset($_GET['invoice-id'])) {
1863
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1864 1864
     }
1865 1865
 
1866 1866
     // No key found
1867
-    if ( ! isset( $invoice_key ) ) {
1867
+    if (!isset($invoice_key)) {
1868 1868
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1869 1869
     }
1870 1870
 
1871
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1872
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1873
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1871
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1872
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1873
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1874 1874
         $invoice_id     = (int)$_GET['invoice-id'];
1875
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1875
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1876 1876
     }
1877 1877
 
1878 1878
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1879
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1879
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1880 1880
         // login redirect
1881
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1881
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1882 1882
     }
1883 1883
 
1884
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1884
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1885 1885
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1886 1886
     }
1887 1887
 
1888 1888
     ob_start();
1889 1889
 
1890
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1890
+    wpinv_get_template_part('wpinv-invoice-receipt');
1891 1891
 
1892 1892
     $display = ob_get_clean();
1893 1893
 
1894 1894
     return $display;
1895 1895
 }
1896 1896
 
1897
-function wpinv_get_invoice_id_by_key( $key ) {
1897
+function wpinv_get_invoice_id_by_key($key) {
1898 1898
 	global $wpdb;
1899 1899
 
1900
-	$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 ) );
1900
+	$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));
1901 1901
 
1902
-	if ( $invoice_id != NULL )
1902
+	if ($invoice_id != NULL)
1903 1903
 		return $invoice_id;
1904 1904
 
1905 1905
 	return 0;
1906 1906
 }
1907 1907
 
1908
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1908
+function wpinv_can_view_receipt($invoice_key = '') {
1909 1909
 	$return = false;
1910 1910
 
1911
-	if ( empty( $invoice_key ) ) {
1911
+	if (empty($invoice_key)) {
1912 1912
 		return $return;
1913 1913
 	}
1914 1914
 
1915 1915
 	global $wpinv_receipt_args;
1916 1916
 
1917
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1918
-	if ( isset( $_GET['invoice-id'] ) ) {
1919
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1917
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1918
+	if (isset($_GET['invoice-id'])) {
1919
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1920 1920
 	}
1921 1921
 
1922
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1922
+	if (empty($wpinv_receipt_args['id'])) {
1923 1923
 		return $return;
1924 1924
 	}
1925 1925
 
1926
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1927
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1926
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1927
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1928 1928
 		return $return;
1929 1929
 	}
1930 1930
 
1931
-	if ( is_user_logged_in() ) {
1932
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1931
+	if (is_user_logged_in()) {
1932
+		if ((int)$invoice->get_user_id() === (int)get_current_user_id()) {
1933 1933
 			$return = true;
1934 1934
 		}
1935 1935
 	}
1936 1936
 
1937 1937
 	$session = wpinv_get_checkout_session();
1938
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1939
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1938
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1939
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1940 1940
 
1941
-		if ( wpinv_require_login_to_checkout() ) {
1941
+		if (wpinv_require_login_to_checkout()) {
1942 1942
 			$return = $return && $check_key === $invoice_key;
1943 1943
 		} else {
1944 1944
 			$return = $check_key === $invoice_key;
1945 1945
 		}
1946 1946
 	}
1947 1947
 
1948
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1948
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1949 1949
 }
1950 1950
 
1951 1951
 function wpinv_pay_for_invoice() {
1952 1952
     global $wpinv_euvat;
1953 1953
     
1954
-    if ( isset( $_GET['invoice_key'] ) ) {
1954
+    if (isset($_GET['invoice_key'])) {
1955 1955
         $checkout_uri   = wpinv_get_checkout_uri();
1956
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1956
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1957 1957
         
1958
-        if ( empty( $invoice_key ) ) {
1959
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1960
-            wp_redirect( $checkout_uri );
1958
+        if (empty($invoice_key)) {
1959
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1960
+            wp_redirect($checkout_uri);
1961 1961
             wpinv_die();
1962 1962
         }
1963 1963
         
1964
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1964
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1965 1965
 
1966
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1967
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1968
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1966
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1967
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1968
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1969 1969
             $invoice_id     = (int)$_GET['invoice-id'];
1970
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1970
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1971 1971
         }
1972 1972
         
1973
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1974
-            if ( $invoice->needs_payment() ) {
1973
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1974
+            if ($invoice->needs_payment()) {
1975 1975
                 $data                   = array();
1976 1976
                 $data['invoice_id']     = $invoice_id;
1977
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1977
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1978 1978
                 
1979
-                wpinv_set_checkout_session( $data );
1979
+                wpinv_set_checkout_session($data);
1980 1980
                 
1981
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1981
+                if (wpinv_get_option('vat_ip_country_default')) {
1982 1982
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1983 1983
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1984 1984
                     
1985
-                    wpinv_recalculate_tax( true );
1985
+                    wpinv_recalculate_tax(true);
1986 1986
                 }
1987 1987
                 
1988 1988
             } else {
1989 1989
                 $checkout_uri = $invoice->get_view_url();
1990 1990
             }
1991 1991
         } else {
1992
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1992
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1993 1993
             
1994
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1994
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1995 1995
         }
1996 1996
         
1997
-        wp_redirect( $checkout_uri );
1997
+        wp_redirect($checkout_uri);
1998 1998
         wpinv_die();
1999 1999
     }
2000 2000
 }
2001
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2001
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2002 2002
 
2003
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2004
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2005
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2003
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2004
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2005
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2006 2006
             $user_id = $invoice->get_user_id();
2007
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2007
+            $secret = sanitize_text_field($_GET['_wpipay']);
2008 2008
             
2009
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2010
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2009
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2010
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2011 2011
                 
2012
-                wpinv_guest_redirect( $redirect_to, $user_id );
2012
+                wpinv_guest_redirect($redirect_to, $user_id);
2013 2013
                 wpinv_die();
2014 2014
             }
2015 2015
         }
2016 2016
     }
2017 2017
 }
2018
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2018
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2019 2019
 
2020
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2021
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2020
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2021
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2022 2022
     
2023
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2023
+    if (empty($invoice_id) && $invoice_id > 0) {
2024 2024
         return false;
2025 2025
     }
2026 2026
     
2027
-    if ( empty( $transaction_id ) ) {
2027
+    if (empty($transaction_id)) {
2028 2028
         $transaction_id = $invoice_id;
2029 2029
     }
2030 2030
 
2031
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2031
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2032 2032
     
2033
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2033
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2034 2034
 }
2035 2035
 
2036
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2037
-    if ( empty( $status_display ) ) {
2038
-        $status_display = wpinv_status_nicename( $status );
2036
+function wpinv_invoice_status_label($status, $status_display = '') {
2037
+    if (empty($status_display)) {
2038
+        $status_display = wpinv_status_nicename($status);
2039 2039
     }
2040 2040
     
2041
-    switch ( $status ) {
2041
+    switch ($status) {
2042 2042
         case 'publish' :
2043 2043
         case 'wpi-renewal' :
2044 2044
             $class = 'label-success';
@@ -2063,257 +2063,257 @@  discard block
 block discarded – undo
2063 2063
     
2064 2064
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2065 2065
     
2066
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2066
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2067 2067
 }
2068 2068
 
2069
-function wpinv_format_invoice_number( $number, $type = '' ) {
2070
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2071
-    if ( null !== $check ) {
2069
+function wpinv_format_invoice_number($number, $type = '') {
2070
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2071
+    if (null !== $check) {
2072 2072
         return $check;
2073 2073
     }
2074 2074
 
2075
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2075
+    if (!empty($number) && !is_numeric($number)) {
2076 2076
         return $number;
2077 2077
     }
2078 2078
 
2079
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2080
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2081
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2079
+    $padd = wpinv_get_option('invoice_number_padd');
2080
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2081
+    $postfix = wpinv_get_option('invoice_number_postfix');
2082 2082
     
2083
-    $padd = absint( $padd );
2084
-    $formatted_number = absint( $number );
2083
+    $padd = absint($padd);
2084
+    $formatted_number = absint($number);
2085 2085
     
2086
-    if ( $padd > 0 ) {
2087
-        $formatted_number = zeroise( $formatted_number, $padd );
2086
+    if ($padd > 0) {
2087
+        $formatted_number = zeroise($formatted_number, $padd);
2088 2088
     }    
2089 2089
 
2090 2090
     $formatted_number = $prefix . $formatted_number . $postfix;
2091 2091
 
2092
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2092
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2093 2093
 }
2094 2094
 
2095
-function wpinv_get_next_invoice_number( $type = '' ) {
2096
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2097
-    if ( null !== $check ) {
2095
+function wpinv_get_next_invoice_number($type = '') {
2096
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2097
+    if (null !== $check) {
2098 2098
         return $check;
2099 2099
     }
2100 2100
     
2101
-    if ( !wpinv_sequential_number_active() ) {
2101
+    if (!wpinv_sequential_number_active()) {
2102 2102
         return false;
2103 2103
     }
2104 2104
 
2105
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2106
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2107
-    if ( !absint( $start ) > 0 ) {
2105
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2106
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2107
+    if (!absint($start) > 0) {
2108 2108
         $start = 1;
2109 2109
     }
2110 2110
     $increment_number = true;
2111 2111
     $save_number = false;
2112 2112
 
2113
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2114
-        $number = wpinv_clean_invoice_number( $number );
2113
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2114
+        $number = wpinv_clean_invoice_number($number);
2115 2115
     }
2116 2116
 
2117
-    if ( empty( $number ) ) {
2118
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2119
-            $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 ) ) ) );
2117
+    if (empty($number)) {
2118
+        if (!($last_number === 0 || $last_number === '0')) {
2119
+            $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))));
2120 2120
 
2121
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2122
-                if ( is_numeric( $invoice_number ) ) {
2121
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2122
+                if (is_numeric($invoice_number)) {
2123 2123
                     $number = $invoice_number;
2124 2124
                 } else {
2125
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2125
+                    $number = wpinv_clean_invoice_number($invoice_number);
2126 2126
                 }
2127 2127
             }
2128 2128
 
2129
-            if ( empty( $number ) ) {
2129
+            if (empty($number)) {
2130 2130
                 $increment_number = false;
2131 2131
                 $number = $start;
2132
-                $save_number = ( $number - 1 );
2132
+                $save_number = ($number - 1);
2133 2133
             } else {
2134 2134
                 $save_number = $number;
2135 2135
             }
2136 2136
         }
2137 2137
     }
2138 2138
 
2139
-    if ( $start > $number ) {
2139
+    if ($start > $number) {
2140 2140
         $increment_number = false;
2141 2141
         $number = $start;
2142
-        $save_number = ( $number - 1 );
2142
+        $save_number = ($number - 1);
2143 2143
     }
2144 2144
 
2145
-    if ( $save_number !== false ) {
2146
-        update_option( 'wpinv_last_invoice_number', $save_number );
2145
+    if ($save_number !== false) {
2146
+        update_option('wpinv_last_invoice_number', $save_number);
2147 2147
     }
2148 2148
     
2149
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2149
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2150 2150
 
2151
-    if ( $increment_number ) {
2151
+    if ($increment_number) {
2152 2152
         $number++;
2153 2153
     }
2154 2154
 
2155
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2155
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2156 2156
 }
2157 2157
 
2158
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2159
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2160
-    if ( null !== $check ) {
2158
+function wpinv_clean_invoice_number($number, $type = '') {
2159
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2160
+    if (null !== $check) {
2161 2161
         return $check;
2162 2162
     }
2163 2163
     
2164
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2165
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2164
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2165
+    $postfix = wpinv_get_option('invoice_number_postfix');
2166 2166
 
2167
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2167
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2168 2168
 
2169
-    $length      = strlen( $number );
2170
-    $postfix_pos = strrpos( $number, $postfix );
2169
+    $length      = strlen($number);
2170
+    $postfix_pos = strrpos($number, $postfix);
2171 2171
     
2172
-    if ( false !== $postfix_pos ) {
2173
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2172
+    if (false !== $postfix_pos) {
2173
+        $number = substr_replace($number, '', $postfix_pos, $length);
2174 2174
     }
2175 2175
 
2176
-    $number = intval( $number );
2176
+    $number = intval($number);
2177 2177
 
2178
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2178
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2179 2179
 }
2180 2180
 
2181
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2181
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2182 2182
     global $wpdb;
2183 2183
 
2184
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2185
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2184
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2185
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2186 2186
     }
2187 2187
 
2188
-    if ( !$update ) {
2189
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2190
-        clean_post_cache( $post_ID );
2188
+    if (!$update) {
2189
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2190
+        clean_post_cache($post_ID);
2191 2191
     }
2192 2192
 }
2193
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2193
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2194 2194
 
2195
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2196
-    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 ) {
2197
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2195
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2196
+    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) {
2197
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2198 2198
     }
2199 2199
 }
2200
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2200
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2201 2201
 
2202
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2202
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2203 2203
     global $wpdb;
2204 2204
     
2205
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2206
-    if ( null !== $check ) {
2205
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2206
+    if (null !== $check) {
2207 2207
         return $check;
2208 2208
     }
2209 2209
 
2210
-    if ( wpinv_sequential_number_active() ) {
2210
+    if (wpinv_sequential_number_active()) {
2211 2211
         $number = wpinv_get_next_invoice_number();
2212 2212
 
2213
-        if ( $save_sequential ) {
2214
-            update_option( 'wpinv_last_invoice_number', $number );
2213
+        if ($save_sequential) {
2214
+            update_option('wpinv_last_invoice_number', $number);
2215 2215
         }
2216 2216
     } else {
2217 2217
         $number = $post_ID;
2218 2218
     }
2219 2219
 
2220
-    $number = wpinv_format_invoice_number( $number );
2220
+    $number = wpinv_format_invoice_number($number);
2221 2221
 
2222
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2222
+    update_post_meta($post_ID, '_wpinv_number', $number);
2223 2223
 
2224
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2224
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2225 2225
 
2226
-    clean_post_cache( $post_ID );
2226
+    clean_post_cache($post_ID);
2227 2227
 
2228 2228
     return $number;
2229 2229
 }
2230 2230
 
2231
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2232
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2231
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2232
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2233 2233
 }
2234 2234
 
2235
-function wpinv_generate_post_name( $post_ID ) {
2236
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2237
-    $post_name = sanitize_title( $prefix . $post_ID );
2235
+function wpinv_generate_post_name($post_ID) {
2236
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2237
+    $post_name = sanitize_title($prefix . $post_ID);
2238 2238
 
2239
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2239
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2240 2240
 }
2241 2241
 
2242
-function wpinv_is_invoice_viewed( $invoice_id ) {
2243
-    if ( empty( $invoice_id ) ) {
2242
+function wpinv_is_invoice_viewed($invoice_id) {
2243
+    if (empty($invoice_id)) {
2244 2244
         return false;
2245 2245
     }
2246 2246
 
2247
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2247
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2248 2248
 
2249
-    if ( isset($viewed_meta) && 1 == $viewed_meta ) {
2249
+    if (isset($viewed_meta) && 1 == $viewed_meta) {
2250 2250
         $is_viewed = true;
2251 2251
     } else {
2252 2252
         $is_viewed = false;
2253 2253
     }
2254 2254
 
2255
-    return apply_filters( 'wpinv_is_invoice_viewed', $is_viewed, $invoice_id );
2255
+    return apply_filters('wpinv_is_invoice_viewed', $is_viewed, $invoice_id);
2256 2256
 }
2257 2257
 
2258 2258
 function wpinv_mark_invoice_viewed() {
2259 2259
 
2260
-    if ( isset( $_GET['invoice_key'] ) ) {
2260
+    if (isset($_GET['invoice_key'])) {
2261 2261
         $invoice_key = urldecode($_GET['invoice_key']);
2262 2262
 
2263 2263
         $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2264 2264
         $invoice = new WPInv_Invoice($invoice_id);
2265 2265
 
2266
-        if(!$invoice_id){
2266
+        if (!$invoice_id) {
2267 2267
             return;
2268 2268
         }
2269 2269
 
2270
-        if( is_user_logged_in()){
2270
+        if (is_user_logged_in()) {
2271 2271
             $current_user = wp_get_current_user();
2272
-            if(!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()){
2273
-                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2272
+            if (!current_user_can('administrator') && $current_user->user_email == $invoice->get_email()) {
2273
+                update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2274 2274
             }
2275 2275
         } else {
2276
-            update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2276
+            update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2277 2277
         }
2278 2278
     }
2279 2279
 
2280 2280
 }
2281
-add_action( 'init', 'wpinv_mark_invoice_viewed' );
2281
+add_action('init', 'wpinv_mark_invoice_viewed');
2282 2282
 
2283
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2284
-    if ( empty( $invoice ) ) {
2283
+function wpinv_get_subscription($invoice, $by_parent = false) {
2284
+    if (empty($invoice)) {
2285 2285
         return false;
2286 2286
     }
2287 2287
     
2288
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2289
-        $invoice = wpinv_get_invoice( $invoice );
2288
+    if (!is_object($invoice) && is_scalar($invoice)) {
2289
+        $invoice = wpinv_get_invoice($invoice);
2290 2290
     }
2291 2291
     
2292
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2292
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2293 2293
         return false;
2294 2294
     }
2295 2295
     
2296
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2296
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2297 2297
     
2298 2298
     $subs_db    = new WPInv_Subscriptions_DB;
2299
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2299
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2300 2300
     
2301
-    if ( ! empty( $subs ) ) {
2302
-        return reset( $subs );
2301
+    if (!empty($subs)) {
2302
+        return reset($subs);
2303 2303
     }
2304 2304
     
2305 2305
     return false;
2306 2306
 }
2307 2307
 
2308
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2308
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2309 2309
     global $wpdb;
2310 2310
 
2311
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2312
-        if ( !empty( $clauses['join'] ) ) {
2311
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2312
+        if (!empty($clauses['join'])) {
2313 2313
             $clauses['join'] .= " ";
2314 2314
         }
2315 2315
 
2316
-        if ( !empty( $clauses['fields'] ) ) {
2316
+        if (!empty($clauses['fields'])) {
2317 2317
             $clauses['fields'] .= ", ";
2318 2318
         }
2319 2319
 
@@ -2324,4 +2324,4 @@  discard block
 block discarded – undo
2324 2324
 
2325 2325
     return $clauses;
2326 2326
 }
2327
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2328 2327
\ No newline at end of file
2328
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2329 2329
\ No newline at end of file
Please login to merge, or discard this patch.