Passed
Pull Request — master (#185)
by
unknown
05:49
created
vendor/ayecode/wp-super-duper/wp-super-duper.php 2 patches
Indentation   +1014 added lines, -1014 removed lines patch added patch discarded remove patch
@@ -1,166 +1,166 @@  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
-	 * @ver 1.0.3
18
-	 */
19
-	class WP_Super_Duper extends WP_Widget {
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
+     * @ver 1.0.3
18
+     */
19
+    class WP_Super_Duper extends WP_Widget {
20 20
 
21 21
 
22
-		public $version = "1.0.3";
23
-		public $block_code;
24
-		public $options;
25
-		public $base_id;
26
-		public $arguments = array();
27
-		public $instance = array();
28
-		private $class_name;
22
+        public $version = "1.0.3";
23
+        public $block_code;
24
+        public $options;
25
+        public $base_id;
26
+        public $arguments = array();
27
+        public $instance = array();
28
+        private $class_name;
29 29
 
30
-		/**
31
-		 * Take the array options and use them to build.
32
-		 */
33
-		public function __construct( $options ) {
34
-			global $sd_widgets;
30
+        /**
31
+         * Take the array options and use them to build.
32
+         */
33
+        public function __construct( $options ) {
34
+            global $sd_widgets;
35 35
 
36 36
 
37 37
 
38
-			//print_r($options);exit;
39
-			$sd_widgets[$options['base_id']] = array('name'=> $options['name'],'class_name'=>$options['class_name']);
40
-			$this->base_id = $options['base_id'];
41
-			// lets filter the options before we do anything
42
-			$options       = apply_filters( "wp_super_duper_options", $options );
43
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
44
-			$options       = $this->add_name_from_key( $options );
45
-			$this->options = $options;
38
+            //print_r($options);exit;
39
+            $sd_widgets[$options['base_id']] = array('name'=> $options['name'],'class_name'=>$options['class_name']);
40
+            $this->base_id = $options['base_id'];
41
+            // lets filter the options before we do anything
42
+            $options       = apply_filters( "wp_super_duper_options", $options );
43
+            $options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
44
+            $options       = $this->add_name_from_key( $options );
45
+            $this->options = $options;
46 46
 
47
-			$this->base_id   = $options['base_id'];
48
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
47
+            $this->base_id   = $options['base_id'];
48
+            $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
49 49
 
50 50
 
51
-			// init parent
52
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
51
+            // init parent
52
+            parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
53 53
 
54 54
 
55
-			if ( isset( $options['class_name'] ) ) {
56
-				// register widget
57
-				$this->class_name = $options['class_name'];
55
+            if ( isset( $options['class_name'] ) ) {
56
+                // register widget
57
+                $this->class_name = $options['class_name'];
58 58
 
59
-				// register shortcode
60
-				$this->register_shortcode();
59
+                // register shortcode
60
+                $this->register_shortcode();
61 61
 
62
-				// register block
63
-				//$this->register_block();
64
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
65
-			}
62
+                // register block
63
+                //$this->register_block();
64
+                add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
65
+            }
66 66
 
67
-			// add the CSS and JS we need ONCE
68
-			global $sd_widget_scripts;
67
+            // add the CSS and JS we need ONCE
68
+            global $sd_widget_scripts;
69 69
 
70
-			if ( ! $sd_widget_scripts ) {
71
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
72
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
73
-				wp_add_inline_style( 'widgets', $this->widget_css() );
70
+            if ( ! $sd_widget_scripts ) {
71
+                wp_add_inline_script( 'admin-widgets', $this->widget_js() );
72
+                wp_add_inline_script( 'customize-controls', $this->widget_js() );
73
+                wp_add_inline_style( 'widgets', $this->widget_css() );
74 74
 
75
-				// seems ashame to add this for one icon but i love it :(
76
-				//wp_register_script('font-awesome', 'https://use.fontawesome.com/releases/v5.4.1/js/all.js', array('font-awesome-shim'), $this->version);
77
-				//wp_register_script('font-awesome-shim', 'https://use.fontawesome.com/releases/v5.4.1/js/v4-shims.js', array(), $this->version);
75
+                // seems ashame to add this for one icon but i love it :(
76
+                //wp_register_script('font-awesome', 'https://use.fontawesome.com/releases/v5.4.1/js/all.js', array('font-awesome-shim'), $this->version);
77
+                //wp_register_script('font-awesome-shim', 'https://use.fontawesome.com/releases/v5.4.1/js/v4-shims.js', array(), $this->version);
78 78
 
79
-				//echo '###';
80
-				$sd_widget_scripts = true;
79
+                //echo '###';
80
+                $sd_widget_scripts = true;
81 81
 
82
-				// add shortcode insert button once
83
-				add_action( 'media_buttons',array( $this, 'shortcode_insert_button' ) );
84
-				//if( !wp_doing_ajax() ){
85
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
86
-				//}
82
+                // add shortcode insert button once
83
+                add_action( 'media_buttons',array( $this, 'shortcode_insert_button' ) );
84
+                //if( !wp_doing_ajax() ){
85
+                add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
86
+                //}
87 87
 
88
-			}
88
+            }
89 89
 
90
-			do_action( 'wp_super_duper_widget_init', $options, $this );
90
+            do_action( 'wp_super_duper_widget_init', $options, $this );
91 91
 
92
-		}
92
+        }
93 93
 
94
-		/**
95
-		 * Get widget settings.
96
-		 *
97
-		 * @since 2.0.0
98
-		 */
99
-		public static function get_widget_settings(){
100
-			global $sd_widgets;
94
+        /**
95
+         * Get widget settings.
96
+         *
97
+         * @since 2.0.0
98
+         */
99
+        public static function get_widget_settings(){
100
+            global $sd_widgets;
101 101
 //			print_r($_REQUEST);
102 102
 //			echo '####';
103 103
 
104
-			$shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : '';
105
-			if(!$shortcode){wp_die();}
106
-			$widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] :'';
107
-			if(!$widget_args){wp_die();}
108
-			$class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
109
-			if(!$class_name){wp_die();}
104
+            $shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : '';
105
+            if(!$shortcode){wp_die();}
106
+            $widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] :'';
107
+            if(!$widget_args){wp_die();}
108
+            $class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
109
+            if(!$class_name){wp_die();}
110 110
 
111 111
 
112 112
 
113
-			//print_r( $sd_widgets );
113
+            //print_r( $sd_widgets );
114 114
 
115 115
 
116
-			// invoke an instance method
116
+            // invoke an instance method
117 117
 //			$instance = new Instance();
118 118
 //			call_user_func( array( $instance, 'method' ) );
119
-			$widget = new $class_name;
119
+            $widget = new $class_name;
120 120
 
121 121
 //			print_r($widget->form(array()));
122
-			ob_start();
123
-			$widget->form(array());
124
-			$form = ob_get_clean();
125
-			echo "<form id='$shortcode'>".$form."<div class=\"widget-control-save\"></div></form>";
122
+            ob_start();
123
+            $widget->form(array());
124
+            $form = ob_get_clean();
125
+            echo "<form id='$shortcode'>".$form."<div class=\"widget-control-save\"></div></form>";
126 126
 //			echo "<div id='sd-shortcode-output'></div>";
127 127
 
128
-			echo "<style>".$widget->widget_css()."</style>";
129
-			echo "<script>".$widget->widget_js()."</script>";
130
-			?>
128
+            echo "<style>".$widget->widget_css()."</style>";
129
+            echo "<script>".$widget->widget_js()."</script>";
130
+            ?>
131 131
 			<?php
132
-			wp_die();
133
-		}
134
-
135
-		/**
136
-		 * Insert button in shortcode.
137
-		 *
138
-		 * @since 2.0.0
139
-		 *
140
-		 * @param string $editor_id Optional. Shortcode editor id. Default null.
141
-		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
142
-		 */
143
-		public static function shortcode_insert_button($editor_id = '',$insert_shortcode_function=''){
144
-			global $sd_widgets,$shortcode_insert_button_once;
145
-			if($shortcode_insert_button_once){return;}
146
-			add_thickbox();
147
-			?>
132
+            wp_die();
133
+        }
134
+
135
+        /**
136
+         * Insert button in shortcode.
137
+         *
138
+         * @since 2.0.0
139
+         *
140
+         * @param string $editor_id Optional. Shortcode editor id. Default null.
141
+         * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
142
+         */
143
+        public static function shortcode_insert_button($editor_id = '',$insert_shortcode_function=''){
144
+            global $sd_widgets,$shortcode_insert_button_once;
145
+            if($shortcode_insert_button_once){return;}
146
+            add_thickbox();
147
+            ?>
148 148
 			<div id="super-duper-content" style="display:none;">
149 149
 
150 150
 				<div class="sd-shortcode-left-wrap">
151 151
 					<?php
152
-					//print_r( $sd_widgets );
153
-					asort($sd_widgets );
154
-					if(!empty($sd_widgets)){
155
-						echo '<select onchange="sd_get_shortcode_options(this);">';
156
-						echo "<option>".__('Select shortcode')."</option>";
157
-						foreach($sd_widgets as $shortcode => $class){
158
-							echo "<option value='".esc_attr($shortcode)."'>".esc_attr($shortcode)." (".esc_attr($class['name']).")</option>";
159
-						}
160
-						echo "</select>";
161
-
162
-					}
163
-					?>
152
+                    //print_r( $sd_widgets );
153
+                    asort($sd_widgets );
154
+                    if(!empty($sd_widgets)){
155
+                        echo '<select onchange="sd_get_shortcode_options(this);">';
156
+                        echo "<option>".__('Select shortcode')."</option>";
157
+                        foreach($sd_widgets as $shortcode => $class){
158
+                            echo "<option value='".esc_attr($shortcode)."'>".esc_attr($shortcode)." (".esc_attr($class['name']).")</option>";
159
+                        }
160
+                        echo "</select>";
161
+
162
+                    }
163
+                    ?>
164 164
 					<div class="sd-shortcode-settings"></div>
165 165
 
166 166
 				</div>
@@ -198,16 +198,16 @@  discard block
 block discarded – undo
198 198
 			<script>
199 199
 
200 200
 				<?php
201
-				if(!empty($insert_shortcode_function)){
202
-					echo $insert_shortcode_function;
203
-				}else{
204
-
205
-				/**
206
-				 * Function for super duper insert shortcode.
207
-				 *
208
-				 * @since 2.0.0
209
-				 */
210
-				?>
201
+                if(!empty($insert_shortcode_function)){
202
+                    echo $insert_shortcode_function;
203
+                }else{
204
+
205
+                /**
206
+                 * Function for super duper insert shortcode.
207
+                 *
208
+                 * @since 2.0.0
209
+                 */
210
+                ?>
211 211
 				function sd_insert_shortcode(){
212 212
 					$shortcode = jQuery('#sd-shortcode-output').val();
213 213
 					if($shortcode){
@@ -347,12 +347,12 @@  discard block
 block discarded – undo
347 347
 				}
348 348
 			</script>
349 349
 			<?php
350
-			$shortcode_insert_button_once = true;
351
-		}
350
+            $shortcode_insert_button_once = true;
351
+        }
352 352
 
353
-		public function widget_css() {
354
-			ob_start();
355
-			?>
353
+        public function widget_css() {
354
+            ob_start();
355
+            ?>
356 356
 			<style>
357 357
 				/*body {display: none;}*/
358 358
 				.sd-advanced-setting {
@@ -374,21 +374,21 @@  discard block
 block discarded – undo
374 374
 				}
375 375
 			</style>
376 376
 			<?php
377
-			$output = ob_get_clean();
377
+            $output = ob_get_clean();
378 378
 
379
-			/*
379
+            /*
380 380
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
381 381
 			 */
382 382
 
383
-			return str_replace( array(
384
-				'<style>',
385
-				'</style>'
386
-			), '', $output );
387
-		}
383
+            return str_replace( array(
384
+                '<style>',
385
+                '</style>'
386
+            ), '', $output );
387
+        }
388 388
 
389
-		public function widget_js() {
390
-			ob_start();
391
-			?>
389
+        public function widget_js() {
390
+            ob_start();
391
+            ?>
392 392
 			<script>
393 393
 
394 394
 				/**
@@ -544,280 +544,280 @@  discard block
 block discarded – undo
544 544
 				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
545 545
 			</script>
546 546
 			<?php
547
-			$output = ob_get_clean();
547
+            $output = ob_get_clean();
548 548
 
549
-			/*
549
+            /*
550 550
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
551 551
 			 */
552 552
 
553
-			return str_replace( array(
554
-				'<script>',
555
-				'</script>'
556
-			), '', $output );
557
-		}
558
-
559
-
560
-		/**
561
-		 * Set the name from the argument key.
562
-		 *
563
-		 * @param $options
564
-		 *
565
-		 * @return mixed
566
-		 */
567
-		private function add_name_from_key( $options, $arguments = false ) {
568
-			if ( ! empty( $options['arguments'] ) ) {
569
-				foreach ( $options['arguments'] as $key => $val ) {
570
-					$options['arguments'][ $key ]['name'] = $key;
571
-				}
572
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
573
-				foreach ( $options as $key => $val ) {
574
-					$options[ $key ]['name'] = $key;
575
-				}
576
-			}
577
-
578
-			return $options;
579
-		}
580
-
581
-		/**
582
-		 * Register the parent shortcode.
583
-		 *
584
-		 * @since 2.0.0
585
-		 */
586
-		public function register_shortcode() {
587
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
588
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
589
-		}
590
-
591
-		/**
592
-		 * Render the shortcode via ajax so we can return it to Gutenberg.
593
-		 *
594
-		 * @since 2.0.0
595
-		 */
596
-		public static function render_shortcode() {
597
-
598
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
599
-			if ( ! current_user_can( 'manage_options' ) ) {
600
-				wp_die();
601
-			}
602
-
603
-			// we might need the $post value here so lets set it.
604
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
605
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
606
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
607
-					global $post;
608
-					$post = $post_obj;
609
-				}
610
-			}
611
-
612
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
613
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
614
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
615
-				$attributes       = '';
616
-				if ( ! empty( $attributes_array ) ) {
617
-					foreach ( $attributes_array as $key => $value ) {
618
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
619
-					}
620
-				}
621
-
622
-				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
623
-
624
-				echo do_shortcode( $shortcode );
625
-
626
-			}
627
-			wp_die();
628
-		}
629
-
630
-		/**
631
-		 * Output the shortcode.
632
-		 *
633
-		 * @param array $args
634
-		 * @param string $content
635
-		 */
636
-		public function shortcode_output( $args = array(), $content = '' ) {
637
-			$args = self::argument_values( $args );
638
-
639
-			// add extra argument so we know its a output to gutenberg
640
-			//$args
641
-			$args = $this->string_to_bool( $args );
642
-
643
-
644
-			$calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : '';
645
-
646
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
647
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
648
-
649
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
650
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
651
-
652
-			$shortcode_args = array();
653
-			$output = '';
654
-			$no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ?  true : false;
655
-			$main_content = $this->output( $args, $shortcode_args, $content );
656
-			if($main_content && !$no_wrap){
657
-				// wrap the shortcode in a dive with the same class as the widget
658
-				$output .= '<div class="'.$calss.'" ' . $attrs . '>';
659
-				if(!empty($args['title'])){
660
-					// if its a shortcode and there is a title try to grab the title wrappers
661
-					$shortcode_args = array('before_title'=>'', 'after_title' => '');
662
-					if(empty($instance)){
663
-						global $wp_registered_sidebars;
664
-						if(!empty($wp_registered_sidebars)){
665
-							foreach($wp_registered_sidebars as $sidebar){
666
-								if(!empty($sidebar['before_title'])){
667
-									$shortcode_args['before_title'] = $sidebar['before_title'];
668
-									$shortcode_args['after_title'] = $sidebar['after_title'];
669
-									break;
670
-								}
671
-							}
672
-						}
673
-					}
674
-					$output .= $this->output_title($shortcode_args,$args);
675
-				}
676
-				$output .= $main_content;
677
-				$output .= '</div>';
678
-			}elseif($main_content && $no_wrap){
679
-				$output .= $main_content;
680
-			}
681
-
682
-			return $output;
683
-		}
684
-
685
-
686
-		/**
687
-		 * Sometimes booleans values can be turned to strings, so we fix that.
688
-		 *
689
-		 * @param $options
690
-		 *
691
-		 * @return mixed
692
-		 */
693
-		public function string_to_bool( $options ) {
694
-			// convert bool strings to booleans
695
-			foreach ( $options as $key => $val ) {
696
-				if ( $val == 'false' ) {
697
-					$options[ $key ] = false;
698
-				} elseif ( $val == 'true' ) {
699
-					$options[ $key ] = true;
700
-				}
701
-			}
702
-
703
-			return $options;
704
-		}
705
-
706
-		/**
707
-		 * Get the argument values that are also filterable.
708
-		 *
709
-		 * @param $instance
710
-		 *
711
-		 * @return array
712
-		 */
713
-		public function argument_values( $instance ) {
714
-			$argument_values = array();
715
-
716
-			// set widget instance
717
-			$this->instance = $instance;
718
-
719
-			if ( empty( $this->arguments ) ) {
720
-				$this->arguments = $this->get_arguments();
721
-			}
722
-
723
-			if ( ! empty( $this->arguments ) ) {
724
-				foreach ( $this->arguments as $key => $args ) {
725
-					// set the input name from the key
726
-					$args['name'] = $key;
727
-					//
728
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
729
-					if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
730
-						$argument_values[ $key ] = $args['default'];
731
-					}
732
-				}
733
-			}
734
-
735
-			return $argument_values;
736
-		}
737
-
738
-		/**
739
-		 * Set arguments in super duper.
740
-		 *
741
-		 * @since 2.0.0
742
-		 *
743
-		 * @return array Set arguments.
744
-		 */
745
-		public function set_arguments() {
746
-			return $this->arguments;
747
-		}
748
-
749
-		/**
750
-		 * Get arguments in super duper.
751
-		 *
752
-		 * @since 2.0.0
753
-		 *
754
-		 * @return array Get arguments.
755
-		 */
756
-		public function get_arguments() {
757
-			if ( empty( $this->arguments ) ) {
758
-				$this->arguments =  $this->set_arguments();
759
-			}
760
-
761
-			$this->arguments = apply_filters('wp_super_duper_arguments',$this->arguments,$this->options, $this->instance);
762
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
763
-
764
-
765
-			return $this->arguments;
766
-		}
767
-
768
-		/**
769
-		 * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
770
-		 *
771
-		 * @param array $args
772
-		 * @param array $widget_args
773
-		 * @param string $content
774
-		 */
775
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
776
-
777
-		}
778
-
779
-		/**
780
-		 * Add the dyanmic block code inline when the wp-block in enqueued.
781
-		 */
782
-		public function register_block() {
783
-			wp_add_inline_script( 'wp-blocks', $this->block() );
784
-		}
785
-
786
-
787
-		/**
788
-		 * Check if we need to show advanced options.
789
-		 *
790
-		 * @return bool
791
-		 */
792
-		public function block_show_advanced() {
793
-			//$this->arguments
794
-			$show      = false;
795
-			$arguments = $this->arguments;
796
-
797
-			if(empty($arguments)){
798
-				$arguments = $this->get_arguments();
799
-			}
800
-
801
-			if ( ! empty( $arguments ) ) {
802
-				foreach ( $arguments as $argument ) {
803
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
804
-						$show = true;
805
-					}
806
-				}
807
-			}
808
-
809
-			return $show;
810
-		}
811
-
812
-
813
-		/**
814
-		 * Output the JS for building the dynamic Guntenberg block.
815
-		 *
816
-		 * @return mixed
817
-		 */
818
-		public function block() {
819
-			ob_start();
820
-			?>
553
+            return str_replace( array(
554
+                '<script>',
555
+                '</script>'
556
+            ), '', $output );
557
+        }
558
+
559
+
560
+        /**
561
+         * Set the name from the argument key.
562
+         *
563
+         * @param $options
564
+         *
565
+         * @return mixed
566
+         */
567
+        private function add_name_from_key( $options, $arguments = false ) {
568
+            if ( ! empty( $options['arguments'] ) ) {
569
+                foreach ( $options['arguments'] as $key => $val ) {
570
+                    $options['arguments'][ $key ]['name'] = $key;
571
+                }
572
+            } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
573
+                foreach ( $options as $key => $val ) {
574
+                    $options[ $key ]['name'] = $key;
575
+                }
576
+            }
577
+
578
+            return $options;
579
+        }
580
+
581
+        /**
582
+         * Register the parent shortcode.
583
+         *
584
+         * @since 2.0.0
585
+         */
586
+        public function register_shortcode() {
587
+            add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
588
+            add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
589
+        }
590
+
591
+        /**
592
+         * Render the shortcode via ajax so we can return it to Gutenberg.
593
+         *
594
+         * @since 2.0.0
595
+         */
596
+        public static function render_shortcode() {
597
+
598
+            check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
599
+            if ( ! current_user_can( 'manage_options' ) ) {
600
+                wp_die();
601
+            }
602
+
603
+            // we might need the $post value here so lets set it.
604
+            if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
605
+                $post_obj = get_post( absint( $_POST['post_id'] ) );
606
+                if ( ! empty( $post_obj ) && empty( $post ) ) {
607
+                    global $post;
608
+                    $post = $post_obj;
609
+                }
610
+            }
611
+
612
+            if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
613
+                $shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
614
+                $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
615
+                $attributes       = '';
616
+                if ( ! empty( $attributes_array ) ) {
617
+                    foreach ( $attributes_array as $key => $value ) {
618
+                        $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
619
+                    }
620
+                }
621
+
622
+                $shortcode = "[" . $shortcode_name . " " . $attributes . "]";
623
+
624
+                echo do_shortcode( $shortcode );
625
+
626
+            }
627
+            wp_die();
628
+        }
629
+
630
+        /**
631
+         * Output the shortcode.
632
+         *
633
+         * @param array $args
634
+         * @param string $content
635
+         */
636
+        public function shortcode_output( $args = array(), $content = '' ) {
637
+            $args = self::argument_values( $args );
638
+
639
+            // add extra argument so we know its a output to gutenberg
640
+            //$args
641
+            $args = $this->string_to_bool( $args );
642
+
643
+
644
+            $calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : '';
645
+
646
+            $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
647
+            $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
648
+
649
+            $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
650
+            $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
651
+
652
+            $shortcode_args = array();
653
+            $output = '';
654
+            $no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ?  true : false;
655
+            $main_content = $this->output( $args, $shortcode_args, $content );
656
+            if($main_content && !$no_wrap){
657
+                // wrap the shortcode in a dive with the same class as the widget
658
+                $output .= '<div class="'.$calss.'" ' . $attrs . '>';
659
+                if(!empty($args['title'])){
660
+                    // if its a shortcode and there is a title try to grab the title wrappers
661
+                    $shortcode_args = array('before_title'=>'', 'after_title' => '');
662
+                    if(empty($instance)){
663
+                        global $wp_registered_sidebars;
664
+                        if(!empty($wp_registered_sidebars)){
665
+                            foreach($wp_registered_sidebars as $sidebar){
666
+                                if(!empty($sidebar['before_title'])){
667
+                                    $shortcode_args['before_title'] = $sidebar['before_title'];
668
+                                    $shortcode_args['after_title'] = $sidebar['after_title'];
669
+                                    break;
670
+                                }
671
+                            }
672
+                        }
673
+                    }
674
+                    $output .= $this->output_title($shortcode_args,$args);
675
+                }
676
+                $output .= $main_content;
677
+                $output .= '</div>';
678
+            }elseif($main_content && $no_wrap){
679
+                $output .= $main_content;
680
+            }
681
+
682
+            return $output;
683
+        }
684
+
685
+
686
+        /**
687
+         * Sometimes booleans values can be turned to strings, so we fix that.
688
+         *
689
+         * @param $options
690
+         *
691
+         * @return mixed
692
+         */
693
+        public function string_to_bool( $options ) {
694
+            // convert bool strings to booleans
695
+            foreach ( $options as $key => $val ) {
696
+                if ( $val == 'false' ) {
697
+                    $options[ $key ] = false;
698
+                } elseif ( $val == 'true' ) {
699
+                    $options[ $key ] = true;
700
+                }
701
+            }
702
+
703
+            return $options;
704
+        }
705
+
706
+        /**
707
+         * Get the argument values that are also filterable.
708
+         *
709
+         * @param $instance
710
+         *
711
+         * @return array
712
+         */
713
+        public function argument_values( $instance ) {
714
+            $argument_values = array();
715
+
716
+            // set widget instance
717
+            $this->instance = $instance;
718
+
719
+            if ( empty( $this->arguments ) ) {
720
+                $this->arguments = $this->get_arguments();
721
+            }
722
+
723
+            if ( ! empty( $this->arguments ) ) {
724
+                foreach ( $this->arguments as $key => $args ) {
725
+                    // set the input name from the key
726
+                    $args['name'] = $key;
727
+                    //
728
+                    $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
729
+                    if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
730
+                        $argument_values[ $key ] = $args['default'];
731
+                    }
732
+                }
733
+            }
734
+
735
+            return $argument_values;
736
+        }
737
+
738
+        /**
739
+         * Set arguments in super duper.
740
+         *
741
+         * @since 2.0.0
742
+         *
743
+         * @return array Set arguments.
744
+         */
745
+        public function set_arguments() {
746
+            return $this->arguments;
747
+        }
748
+
749
+        /**
750
+         * Get arguments in super duper.
751
+         *
752
+         * @since 2.0.0
753
+         *
754
+         * @return array Get arguments.
755
+         */
756
+        public function get_arguments() {
757
+            if ( empty( $this->arguments ) ) {
758
+                $this->arguments =  $this->set_arguments();
759
+            }
760
+
761
+            $this->arguments = apply_filters('wp_super_duper_arguments',$this->arguments,$this->options, $this->instance);
762
+            $this->arguments = $this->add_name_from_key( $this->arguments, true );
763
+
764
+
765
+            return $this->arguments;
766
+        }
767
+
768
+        /**
769
+         * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class.
770
+         *
771
+         * @param array $args
772
+         * @param array $widget_args
773
+         * @param string $content
774
+         */
775
+        public function output( $args = array(), $widget_args = array(), $content = '' ) {
776
+
777
+        }
778
+
779
+        /**
780
+         * Add the dyanmic block code inline when the wp-block in enqueued.
781
+         */
782
+        public function register_block() {
783
+            wp_add_inline_script( 'wp-blocks', $this->block() );
784
+        }
785
+
786
+
787
+        /**
788
+         * Check if we need to show advanced options.
789
+         *
790
+         * @return bool
791
+         */
792
+        public function block_show_advanced() {
793
+            //$this->arguments
794
+            $show      = false;
795
+            $arguments = $this->arguments;
796
+
797
+            if(empty($arguments)){
798
+                $arguments = $this->get_arguments();
799
+            }
800
+
801
+            if ( ! empty( $arguments ) ) {
802
+                foreach ( $arguments as $argument ) {
803
+                    if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
804
+                        $show = true;
805
+                    }
806
+                }
807
+            }
808
+
809
+            return $show;
810
+        }
811
+
812
+
813
+        /**
814
+         * Output the JS for building the dynamic Guntenberg block.
815
+         *
816
+         * @return mixed
817
+         */
818
+        public function block() {
819
+            ob_start();
820
+            ?>
821 821
 			<script>
822 822
 				/**
823 823
 				 * BLOCK: Basic
@@ -856,67 +856,67 @@  discard block
 block discarded – undo
856 856
 						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/.
857 857
 						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.
858 858
 						<?php if ( isset( $this->options['block-keywords'] ) ) {
859
-						echo "keywords : " . $this->options['block-keywords'] . ",";
860
-					}?>
859
+                        echo "keywords : " . $this->options['block-keywords'] . ",";
860
+                    }?>
861 861
 
862 862
 						<?php
863 863
 
864
-						$show_advanced = $this->block_show_advanced();
865
-
866
-						$show_alignment = false;
867
-
868
-						if ( ! empty( $this->arguments ) ) {
869
-							echo "attributes : {";
870
-
871
-							if ( $show_advanced ) {
872
-								echo "show_advanced: {";
873
-								echo "	type: 'boolean',";
874
-								echo "  default: false,";
875
-								echo "},";
876
-							}
877
-
878
-							foreach ( $this->arguments as $key => $args ) {
879
-
880
-								// set if we should show alignment
881
-								if ( $key == 'alignment' ) {
882
-									$show_alignment = true;
883
-								}
884
-
885
-								$extra = '';
886
-
887
-								if ( $args['type'] == 'checkbox' ) {
888
-									$type    = 'boolean';
889
-									$default = isset( $args['default'] ) && "'" . $args['default'] . "'" ? 'true' : 'false';
890
-								} elseif ( $args['type'] == 'number' ) {
891
-									$type    = 'number';
892
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
893
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
894
-									$type    = 'array';
895
-									if(is_array($args['default'])){
896
-										$default = isset( $args['default'] ) ? "['" . implode("','", $args['default']) . "']" : "[]";
897
-									}else{
898
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
899
-									}
900
-								} elseif ( $args['type'] == 'multiselect' ) {
901
-									$type    = 'array';
902
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
903
-								} else {
904
-									$type    = 'string';
905
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
906
-								}
907
-								echo $key . " : {";
908
-								echo "type : '$type',";
909
-								echo "default : $default,";
910
-								echo "},";
911
-							}
912
-
913
-							echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
914
-
915
-							echo "},";
916
-
917
-						}
918
-
919
-						?>
864
+                        $show_advanced = $this->block_show_advanced();
865
+
866
+                        $show_alignment = false;
867
+
868
+                        if ( ! empty( $this->arguments ) ) {
869
+                            echo "attributes : {";
870
+
871
+                            if ( $show_advanced ) {
872
+                                echo "show_advanced: {";
873
+                                echo "	type: 'boolean',";
874
+                                echo "  default: false,";
875
+                                echo "},";
876
+                            }
877
+
878
+                            foreach ( $this->arguments as $key => $args ) {
879
+
880
+                                // set if we should show alignment
881
+                                if ( $key == 'alignment' ) {
882
+                                    $show_alignment = true;
883
+                                }
884
+
885
+                                $extra = '';
886
+
887
+                                if ( $args['type'] == 'checkbox' ) {
888
+                                    $type    = 'boolean';
889
+                                    $default = isset( $args['default'] ) && "'" . $args['default'] . "'" ? 'true' : 'false';
890
+                                } elseif ( $args['type'] == 'number' ) {
891
+                                    $type    = 'number';
892
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
893
+                                } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
894
+                                    $type    = 'array';
895
+                                    if(is_array($args['default'])){
896
+                                        $default = isset( $args['default'] ) ? "['" . implode("','", $args['default']) . "']" : "[]";
897
+                                    }else{
898
+                                        $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
899
+                                    }
900
+                                } elseif ( $args['type'] == 'multiselect' ) {
901
+                                    $type    = 'array';
902
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
903
+                                } else {
904
+                                    $type    = 'string';
905
+                                    $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
906
+                                }
907
+                                echo $key . " : {";
908
+                                echo "type : '$type',";
909
+                                echo "default : $default,";
910
+                                echo "},";
911
+                            }
912
+
913
+                            echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},";
914
+
915
+                            echo "},";
916
+
917
+                        }
918
+
919
+                        ?>
920 920
 
921 921
 						// The "edit" property must be a valid function.
922 922
 						edit: function (props) {
@@ -935,8 +935,8 @@  discard block
 block discarded – undo
935 935
 										'shortcode': '<?php echo $this->options['base_id'];?>',
936 936
 										'attributes': props.attributes,
937 937
 										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
938
-										echo $post->ID;
939
-									}?>,
938
+                                        echo $post->ID;
939
+                                    }?>,
940 940
 										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
941 941
 									};
942 942
 
@@ -984,10 +984,10 @@  discard block
 block discarded – undo
984 984
 
985 985
 									<?php
986 986
 
987
-									if(! empty( $this->arguments )){
987
+                                    if(! empty( $this->arguments )){
988 988
 
989
-									if ( $show_advanced ) {
990
-									?>
989
+                                    if ( $show_advanced ) {
990
+                                    ?>
991 991
 									el(
992 992
 										wp.components.ToggleControl,
993 993
 										{
@@ -1000,65 +1000,65 @@  discard block
 block discarded – undo
1000 1000
 									),
1001 1001
 									<?php
1002 1002
 
1003
-									}
1004
-
1005
-									foreach($this->arguments as $key => $args){
1006
-									$custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : '';
1007
-									$options = '';
1008
-									$extra = '';
1009
-									$require = '';
1010
-									$onchange = "props.setAttributes({ $key: $key } )";
1011
-									$value = "props.attributes.$key";
1012
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1013
-									if ( in_array( $args['type'], $text_type ) ) {
1014
-										$type = 'TextControl';
1015
-									} elseif ( $args['type'] == 'checkbox' ) {
1016
-										$type = 'CheckboxControl';
1017
-										$extra .= "checked: props.attributes.$key,";
1018
-										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1019
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1020
-										$type = 'SelectControl';
1021
-										if ( ! empty( $args['options'] ) ) {
1022
-											$options .= "options  : [";
1023
-											foreach ( $args['options'] as $option_val => $option_label ) {
1024
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1025
-											}
1026
-											$options .= "],";
1027
-										}
1028
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1029
-											$extra .= ' multiple: true, ';
1030
-											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1031
-											//$value = "['edit', 'delete']";
1032
-										}
1033
-									} elseif ( $args['type'] == 'alignment' ) {
1034
-										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1035
-									} else {
1036
-										continue;// if we have not implemented the control then don't break the JS.
1037
-									}
1038
-
1039
-									// add show only if advanced
1040
-									if ( ! empty( $args['advanced'] ) ) {
1041
-										echo "props.attributes.show_advanced && ";
1042
-									}
1043
-									// add setting require if defined
1044
-									if ( ! empty( $args['element_require'] ) ) {
1045
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1046
-									}
1047
-									?>
1003
+                                    }
1004
+
1005
+                                    foreach($this->arguments as $key => $args){
1006
+                                    $custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : '';
1007
+                                    $options = '';
1008
+                                    $extra = '';
1009
+                                    $require = '';
1010
+                                    $onchange = "props.setAttributes({ $key: $key } )";
1011
+                                    $value = "props.attributes.$key";
1012
+                                    $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1013
+                                    if ( in_array( $args['type'], $text_type ) ) {
1014
+                                        $type = 'TextControl';
1015
+                                    } elseif ( $args['type'] == 'checkbox' ) {
1016
+                                        $type = 'CheckboxControl';
1017
+                                        $extra .= "checked: props.attributes.$key,";
1018
+                                        $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1019
+                                    } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1020
+                                        $type = 'SelectControl';
1021
+                                        if ( ! empty( $args['options'] ) ) {
1022
+                                            $options .= "options  : [";
1023
+                                            foreach ( $args['options'] as $option_val => $option_label ) {
1024
+                                                $options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1025
+                                            }
1026
+                                            $options .= "],";
1027
+                                        }
1028
+                                        if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1029
+                                            $extra .= ' multiple: true, ';
1030
+                                            //$onchange = "props.setAttributes({ $key: ['edit'] } )";
1031
+                                            //$value = "['edit', 'delete']";
1032
+                                        }
1033
+                                    } elseif ( $args['type'] == 'alignment' ) {
1034
+                                        $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1035
+                                    } else {
1036
+                                        continue;// if we have not implemented the control then don't break the JS.
1037
+                                    }
1038
+
1039
+                                    // add show only if advanced
1040
+                                    if ( ! empty( $args['advanced'] ) ) {
1041
+                                        echo "props.attributes.show_advanced && ";
1042
+                                    }
1043
+                                    // add setting require if defined
1044
+                                    if ( ! empty( $args['element_require'] ) ) {
1045
+                                        echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1046
+                                    }
1047
+                                    ?>
1048 1048
 									el(
1049 1049
 										wp.components.<?php echo esc_attr( $type );?>,
1050 1050
 										{
1051 1051
 											label: '<?php echo esc_attr( $args['title'] );?>',
1052 1052
 											help: '<?php if ( isset( $args['desc'] ) ) {
1053
-												echo esc_attr( $args['desc'] );
1054
-											}?>',
1053
+                                                echo esc_attr( $args['desc'] );
1054
+                                            }?>',
1055 1055
 											value: <?php echo $value;?>,
1056 1056
 											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1057
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1058
-										}?>
1057
+                                            echo "type: '" . esc_attr( $args['type'] ) . "',";
1058
+                                        }?>
1059 1059
 											<?php if ( ! empty( $args['placeholder'] ) ) {
1060
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1061
-										}?>
1060
+                                            echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1061
+                                        }?>
1062 1062
 											<?php echo $options;?>
1063 1063
 											<?php echo $extra;?>
1064 1064
 											<?php echo $custom_attributes;?>
@@ -1068,27 +1068,27 @@  discard block
 block discarded – undo
1068 1068
 										}
1069 1069
 									),
1070 1070
 									<?php
1071
-									}
1072
-									}
1073
-									?>
1071
+                                    }
1072
+                                    }
1073
+                                    ?>
1074 1074
 
1075 1075
 								),
1076 1076
 
1077 1077
 								<?php
1078
-								// If the user sets block-output array then build it
1079
-								if ( ! empty( $this->options['block-output'] ) ) {
1080
-								$this->block_element( $this->options['block-output'] );
1081
-							}else{
1082
-								// if no block-output is set then we try and get the shortcode html output via ajax.
1083
-								?>
1078
+                                // If the user sets block-output array then build it
1079
+                                if ( ! empty( $this->options['block-output'] ) ) {
1080
+                                $this->block_element( $this->options['block-output'] );
1081
+                            }else{
1082
+                                // if no block-output is set then we try and get the shortcode html output via ajax.
1083
+                                ?>
1084 1084
 								el('div', {
1085 1085
 									dangerouslySetInnerHTML: {__html: onChangeContent()},
1086 1086
 									className: props.className,
1087 1087
 									style: {'min-height': '30px'}
1088 1088
 								})
1089 1089
 								<?php
1090
-								}
1091
-								?>
1090
+                                }
1091
+                                ?>
1092 1092
 							]; // end return
1093 1093
 						},
1094 1094
 
@@ -1105,17 +1105,17 @@  discard block
 block discarded – undo
1105 1105
 							var content = "[<?php echo $this->options['base_id'];?>";
1106 1106
 							<?php
1107 1107
 
1108
-							if(! empty( $this->arguments )){
1109
-							foreach($this->arguments as $key => $args){
1110
-							?>
1108
+                            if(! empty( $this->arguments )){
1109
+                            foreach($this->arguments as $key => $args){
1110
+                            ?>
1111 1111
 							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1112 1112
 								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1113 1113
 							}
1114 1114
 							<?php
1115
-							}
1116
-							}
1115
+                            }
1116
+                            }
1117 1117
 
1118
-							?>
1118
+                            ?>
1119 1119
 							content += "]";
1120 1120
 
1121 1121
 
@@ -1140,367 +1140,367 @@  discard block
 block discarded – undo
1140 1140
 				})();
1141 1141
 			</script>
1142 1142
 			<?php
1143
-			$output = ob_get_clean();
1143
+            $output = ob_get_clean();
1144 1144
 
1145
-			/*
1145
+            /*
1146 1146
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1147 1147
 			 */
1148 1148
 
1149
-			return str_replace( array(
1150
-				'<script>',
1151
-				'</script>'
1152
-			), '', $output );
1153
-		}
1154
-
1155
-		/**
1156
-		 * Convert an array of attributes to block string.
1157
-		 *
1158
-		 * @todo there is prob a faster way to do this, also we could add some validation here.
1159
-		 * @param $custom_attributes
1160
-		 *
1161
-		 * @return string
1162
-		 */
1163
-		public function array_to_attributes($custom_attributes, $html = false){
1164
-			$attributes = '';
1165
-			if(!empty($custom_attributes)){
1166
-
1167
-				if($html){
1168
-					foreach($custom_attributes as $key => $val){
1169
-						$attributes .= " $key='$val' ";
1170
-					}
1171
-				}else{
1172
-					foreach($custom_attributes as $key => $val){
1173
-						$attributes .= "'$key': '$val',";
1174
-					}
1175
-				}
1176
-			}
1177
-
1178
-			return $attributes;
1179
-		}
1180
-
1181
-
1182
-		/**
1183
-		 * A self looping function to create the output for JS block elements.
1184
-		 *
1185
-		 * This is what is output in the WP Editor visual view.
1186
-		 *
1187
-		 * @param $args
1188
-		 */
1189
-		public function block_element( $args ) {
1190
-
1191
-
1192
-			if ( ! empty( $args ) ) {
1193
-				foreach ( $args as $element => $new_args ) {
1194
-
1195
-					if ( is_array( $new_args ) ) { // its an element
1196
-
1197
-
1198
-						if ( isset( $new_args['element'] ) ) {
1199
-
1200
-							//print_r($new_args);
1201
-
1202
-							if ( isset( $new_args['element_require'] ) ) {
1203
-								echo str_replace( array(
1204
-										"'+",
1205
-										"+'"
1206
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1207
-								unset( $new_args['element_require'] );
1208
-							}
1209
-
1210
-							echo "\n el( '" . $new_args['element'] . "', {";
1211
-
1212
-							// get the attributes
1213
-							foreach ( $new_args as $new_key => $new_value ) {
1214
-
1215
-
1216
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1217
-									// do nothing
1218
-								} else {
1219
-									echo $this->block_element( array( $new_key => $new_value ) );
1220
-								}
1221
-							}
1222
-
1223
-							echo "},";// end attributes
1224
-
1225
-							// get the content
1226
-							$first_item = 0;
1227
-							foreach ( $new_args as $new_key => $new_value ) {
1228
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1229
-									//echo ",".$first_item;// separate the children
1230
-
1231
-
1232
-									if ( $first_item > 0 ) {
1233
-										//echo ",";// separate the children
1234
-									} else {
1235
-										//echo '####'.$first_item;
1236
-									}
1237
-
1238
-									if ( $new_key === 'content' ) {
1239
-										//print_r($new_args);
1240
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1241
-									}
1242
-
1243
-									if ( is_array( $new_value ) ) {
1244
-
1245
-										if ( isset( $new_value['element_require'] ) ) {
1246
-											echo str_replace( array(
1247
-													"'+",
1248
-													"+'"
1249
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1250
-											unset( $new_value['element_require'] );
1251
-										}
1252
-
1253
-										if ( isset( $new_value['element_repeat'] ) ) {
1254
-											$x = 1;
1255
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1256
-												$this->block_element( array( '' => $new_value ) );
1257
-												$x ++;
1258
-											}
1259
-										} else {
1260
-											$this->block_element( array( '' => $new_value ) );
1261
-										}
1262
-										//print_r($new_value);
1263
-									}
1264
-									$first_item ++;
1265
-								}
1266
-							}
1267
-
1268
-							echo ")";// end content
1269
-
1270
-							//if($first_item>0){
1271
-							echo ", \n";
1272
-							//}
1273
-
1274
-
1275
-						}
1276
-						//$this->block_element($new_args);
1277
-					} else {
1278
-
1279
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1280
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1281
-						} elseif ( $element == 'style' ) {
1282
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1283
-						} else {
1284
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1285
-						}
1286
-
1287
-					}
1288
-
1289
-
1290
-				}
1291
-			}
1292
-		}
1293
-
1294
-		/**
1295
-		 * Replace block attributes placeholders with the proper naming.
1296
-		 *
1297
-		 * @param $string
1298
-		 *
1299
-		 * @return mixed
1300
-		 */
1301
-		public function block_props_replace( $string, $no_wrap = false ) {
1302
-
1303
-			if ( $no_wrap ) {
1304
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1305
-			} else {
1306
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1307
-			}
1308
-
1309
-			return $string;
1310
-		}
1311
-
1312
-		/**
1313
-		 * Outputs the content of the widget
1314
-		 *
1315
-		 * @param array $args
1316
-		 * @param array $instance
1317
-		 */
1318
-		public function widget( $args, $instance ) {
1319
-			// outputs the content of the widget
1320
-
1321
-			// get the filtered values
1322
-			$argument_values = $this->argument_values( $instance );
1323
-			$argument_values = $this->string_to_bool( $argument_values );
1324
-			$output = $this->output( $argument_values, $args );
1325
-
1326
-			if ( $output ) {
1327
-				// Before widget
1328
-				$before_widget = $args['before_widget'];
1329
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1330
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1331
-
1332
-				// After widget
1333
-				$after_widget = $args['after_widget'];
1334
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1335
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1336
-
1337
-				echo $before_widget;
1338
-				echo $this->output_title($args, $instance);
1339
-				echo $output;
1340
-				echo $after_widget;
1341
-			}
1342
-		}
1343
-
1344
-		/**
1345
-		 * Output the super title.
1346
-		 *
1347
-		 * @param $args
1348
-		 * @param array $instance
1349
-		 *
1350
-		 * @return string
1351
-		 */
1352
-		public function output_title($args, $instance = array()){
1353
-			$output = '';
1354
-			if ( ! empty( $instance['title'] ) ) {
1355
-				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
1356
-				$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
1357
-				$output = $args['before_title'] . $title . $args['after_title'];
1358
-			}
1359
-			return $output;
1360
-		}
1361
-
1362
-		/**
1363
-		 * Outputs the options form inputs for the widget.
1364
-		 *
1365
-		 * @param array $instance The widget options.
1366
-		 */
1367
-		public function form( $instance ) {
1368
-
1369
-			// set widget instance
1370
-			$this->instance = $instance;
1371
-
1372
-			// set it as a SD widget
1373
-			echo $this->widget_advanced_toggle();
1374
-
1375
-
1376
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
1377
-			$arguments = $this->get_arguments();
1149
+            return str_replace( array(
1150
+                '<script>',
1151
+                '</script>'
1152
+            ), '', $output );
1153
+        }
1154
+
1155
+        /**
1156
+         * Convert an array of attributes to block string.
1157
+         *
1158
+         * @todo there is prob a faster way to do this, also we could add some validation here.
1159
+         * @param $custom_attributes
1160
+         *
1161
+         * @return string
1162
+         */
1163
+        public function array_to_attributes($custom_attributes, $html = false){
1164
+            $attributes = '';
1165
+            if(!empty($custom_attributes)){
1166
+
1167
+                if($html){
1168
+                    foreach($custom_attributes as $key => $val){
1169
+                        $attributes .= " $key='$val' ";
1170
+                    }
1171
+                }else{
1172
+                    foreach($custom_attributes as $key => $val){
1173
+                        $attributes .= "'$key': '$val',";
1174
+                    }
1175
+                }
1176
+            }
1177
+
1178
+            return $attributes;
1179
+        }
1180
+
1181
+
1182
+        /**
1183
+         * A self looping function to create the output for JS block elements.
1184
+         *
1185
+         * This is what is output in the WP Editor visual view.
1186
+         *
1187
+         * @param $args
1188
+         */
1189
+        public function block_element( $args ) {
1190
+
1191
+
1192
+            if ( ! empty( $args ) ) {
1193
+                foreach ( $args as $element => $new_args ) {
1194
+
1195
+                    if ( is_array( $new_args ) ) { // its an element
1196
+
1197
+
1198
+                        if ( isset( $new_args['element'] ) ) {
1199
+
1200
+                            //print_r($new_args);
1201
+
1202
+                            if ( isset( $new_args['element_require'] ) ) {
1203
+                                echo str_replace( array(
1204
+                                        "'+",
1205
+                                        "+'"
1206
+                                    ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1207
+                                unset( $new_args['element_require'] );
1208
+                            }
1209
+
1210
+                            echo "\n el( '" . $new_args['element'] . "', {";
1211
+
1212
+                            // get the attributes
1213
+                            foreach ( $new_args as $new_key => $new_value ) {
1214
+
1215
+
1216
+                                if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1217
+                                    // do nothing
1218
+                                } else {
1219
+                                    echo $this->block_element( array( $new_key => $new_value ) );
1220
+                                }
1221
+                            }
1222
+
1223
+                            echo "},";// end attributes
1224
+
1225
+                            // get the content
1226
+                            $first_item = 0;
1227
+                            foreach ( $new_args as $new_key => $new_value ) {
1228
+                                if ( $new_key === 'content' || is_array( $new_value ) ) {
1229
+                                    //echo ",".$first_item;// separate the children
1230
+
1231
+
1232
+                                    if ( $first_item > 0 ) {
1233
+                                        //echo ",";// separate the children
1234
+                                    } else {
1235
+                                        //echo '####'.$first_item;
1236
+                                    }
1237
+
1238
+                                    if ( $new_key === 'content' ) {
1239
+                                        //print_r($new_args);
1240
+                                        echo "'" . $this->block_props_replace( $new_value ) . "'";
1241
+                                    }
1242
+
1243
+                                    if ( is_array( $new_value ) ) {
1244
+
1245
+                                        if ( isset( $new_value['element_require'] ) ) {
1246
+                                            echo str_replace( array(
1247
+                                                    "'+",
1248
+                                                    "+'"
1249
+                                                ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1250
+                                            unset( $new_value['element_require'] );
1251
+                                        }
1252
+
1253
+                                        if ( isset( $new_value['element_repeat'] ) ) {
1254
+                                            $x = 1;
1255
+                                            while ( $x <= absint( $new_value['element_repeat'] ) ) {
1256
+                                                $this->block_element( array( '' => $new_value ) );
1257
+                                                $x ++;
1258
+                                            }
1259
+                                        } else {
1260
+                                            $this->block_element( array( '' => $new_value ) );
1261
+                                        }
1262
+                                        //print_r($new_value);
1263
+                                    }
1264
+                                    $first_item ++;
1265
+                                }
1266
+                            }
1267
+
1268
+                            echo ")";// end content
1269
+
1270
+                            //if($first_item>0){
1271
+                            echo ", \n";
1272
+                            //}
1273
+
1274
+
1275
+                        }
1276
+                        //$this->block_element($new_args);
1277
+                    } else {
1278
+
1279
+                        if ( substr( $element, 0, 3 ) === "if_" ) {
1280
+                            echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1281
+                        } elseif ( $element == 'style' ) {
1282
+                            echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1283
+                        } else {
1284
+                            echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1285
+                        }
1286
+
1287
+                    }
1288
+
1289
+
1290
+                }
1291
+            }
1292
+        }
1293
+
1294
+        /**
1295
+         * Replace block attributes placeholders with the proper naming.
1296
+         *
1297
+         * @param $string
1298
+         *
1299
+         * @return mixed
1300
+         */
1301
+        public function block_props_replace( $string, $no_wrap = false ) {
1302
+
1303
+            if ( $no_wrap ) {
1304
+                $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1305
+            } else {
1306
+                $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1307
+            }
1308
+
1309
+            return $string;
1310
+        }
1311
+
1312
+        /**
1313
+         * Outputs the content of the widget
1314
+         *
1315
+         * @param array $args
1316
+         * @param array $instance
1317
+         */
1318
+        public function widget( $args, $instance ) {
1319
+            // outputs the content of the widget
1320
+
1321
+            // get the filtered values
1322
+            $argument_values = $this->argument_values( $instance );
1323
+            $argument_values = $this->string_to_bool( $argument_values );
1324
+            $output = $this->output( $argument_values, $args );
1325
+
1326
+            if ( $output ) {
1327
+                // Before widget
1328
+                $before_widget = $args['before_widget'];
1329
+                $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1330
+                $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1331
+
1332
+                // After widget
1333
+                $after_widget = $args['after_widget'];
1334
+                $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1335
+                $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1336
+
1337
+                echo $before_widget;
1338
+                echo $this->output_title($args, $instance);
1339
+                echo $output;
1340
+                echo $after_widget;
1341
+            }
1342
+        }
1343
+
1344
+        /**
1345
+         * Output the super title.
1346
+         *
1347
+         * @param $args
1348
+         * @param array $instance
1349
+         *
1350
+         * @return string
1351
+         */
1352
+        public function output_title($args, $instance = array()){
1353
+            $output = '';
1354
+            if ( ! empty( $instance['title'] ) ) {
1355
+                /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
1356
+                $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
1357
+                $output = $args['before_title'] . $title . $args['after_title'];
1358
+            }
1359
+            return $output;
1360
+        }
1361
+
1362
+        /**
1363
+         * Outputs the options form inputs for the widget.
1364
+         *
1365
+         * @param array $instance The widget options.
1366
+         */
1367
+        public function form( $instance ) {
1368
+
1369
+            // set widget instance
1370
+            $this->instance = $instance;
1371
+
1372
+            // set it as a SD widget
1373
+            echo $this->widget_advanced_toggle();
1374
+
1375
+
1376
+            echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
1377
+            $arguments = $this->get_arguments();
1378 1378
 //			print_r($instance );
1379 1379
 //			echo '###';
1380 1380
 //			print_r($arguments  );
1381 1381
 
1382
-			if ( is_array( $arguments ) ) {
1383
-				foreach ( $arguments as $key => $args ) {
1384
-					$this->widget_inputs( $args, $instance );
1385
-				}
1386
-			}
1387
-		}
1388
-
1389
-		/**
1390
-		 * Get the hidden input that when added makes the advanced button show on widget settings.
1391
-		 *
1392
-		 * @return string
1393
-		 */
1394
-		public function widget_advanced_toggle() {
1395
-
1396
-			$output = '';
1397
-			if ( $this->block_show_advanced() ) {
1398
-				$val = 1;
1399
-			} else {
1400
-				$val = 0;
1401
-			}
1402
-			if($val){
1382
+            if ( is_array( $arguments ) ) {
1383
+                foreach ( $arguments as $key => $args ) {
1384
+                    $this->widget_inputs( $args, $instance );
1385
+                }
1386
+            }
1387
+        }
1388
+
1389
+        /**
1390
+         * Get the hidden input that when added makes the advanced button show on widget settings.
1391
+         *
1392
+         * @return string
1393
+         */
1394
+        public function widget_advanced_toggle() {
1395
+
1396
+            $output = '';
1397
+            if ( $this->block_show_advanced() ) {
1398
+                $val = 1;
1399
+            } else {
1400
+                $val = 0;
1401
+            }
1402
+            if($val){
1403 1403
 //				$output .=  '<span class="sd-advanced-button-container"><button class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button></span>';
1404
-			}
1404
+            }
1405 1405
 
1406
-			$output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
1406
+            $output .= "<input type='hidden'  class='sd-show-advanced' value='$val' />";
1407 1407
 
1408 1408
 
1409 1409
 
1410 1410
 
1411
-			return $output;
1411
+            return $output;
1412 1412
 
1413
-		}
1413
+        }
1414 1414
 
1415
-		/**
1416
-		 * Convert require element.
1417
-		 *
1418
-		 * @since 2.0.0
1419
-		 *
1420
-		 * @param string $input Input element.
1421
-		 * @return string $output
1422
-		 */
1423
-		public function convert_element_require( $input ) {
1415
+        /**
1416
+         * Convert require element.
1417
+         *
1418
+         * @since 2.0.0
1419
+         *
1420
+         * @param string $input Input element.
1421
+         * @return string $output
1422
+         */
1423
+        public function convert_element_require( $input ) {
1424 1424
 
1425
-			$input = str_replace( "'", '"', $input );// we only want double quotes
1425
+            $input = str_replace( "'", '"', $input );// we only want double quotes
1426 1426
 
1427
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
1428
-				"jQuery(form).find('[data-argument=\"",
1429
-				"\"]').find('input,select').val()"
1430
-			), $input ) );
1427
+            $output = esc_attr( str_replace( array( "[%", "%]" ), array(
1428
+                "jQuery(form).find('[data-argument=\"",
1429
+                "\"]').find('input,select').val()"
1430
+            ), $input ) );
1431 1431
 
1432 1432
 
1433
-			return $output;
1434
-		}
1433
+            return $output;
1434
+        }
1435 1435
 
1436
-		/**
1437
-		 * Builds the inputs for the widget options.
1438
-		 *
1439
-		 * @param $args
1440
-		 * @param $instance
1441
-		 */
1442
-		public function widget_inputs( $args, $instance ) {
1436
+        /**
1437
+         * Builds the inputs for the widget options.
1438
+         *
1439
+         * @param $args
1440
+         * @param $instance
1441
+         */
1442
+        public function widget_inputs( $args, $instance ) {
1443 1443
 
1444 1444
 //print_r($instance );echo '###';
1445 1445
 //print_r($args );
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
-
1482
-
1483
-
1484
-			// before wrapper
1485
-			?>
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
+
1482
+
1483
+
1484
+            // before wrapper
1485
+            ?>
1486 1486
 			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
1487 1487
 			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
1488 1488
 			   data-element_require='<?php if ( $element_require ) {
1489
-				   echo $this->convert_element_require( $element_require );
1490
-			   } ?>'
1489
+                    echo $this->convert_element_require( $element_require );
1490
+                } ?>'
1491 1491
 			>
1492 1492
 				<?php
1493 1493
 
1494
-				switch ( $args['type'] ) {
1495
-					//array('text','password','number','email','tel','url','color')
1496
-					case "text":
1497
-					case "password":
1498
-					case "number":
1499
-					case "email":
1500
-					case "tel":
1501
-					case "url":
1502
-					case "color":
1503
-						?>
1494
+                switch ( $args['type'] ) {
1495
+                    //array('text','password','number','email','tel','url','color')
1496
+                    case "text":
1497
+                    case "password":
1498
+                    case "number":
1499
+                    case "email":
1500
+                    case "tel":
1501
+                    case "url":
1502
+                    case "color":
1503
+                        ?>
1504 1504
 						<label
1505 1505
 							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>
1506 1506
 						<input <?php echo $placeholder; ?> class="widefat"
@@ -1511,11 +1511,11 @@  discard block
 block discarded – undo
1511 1511
 							                               value="<?php echo esc_attr( $value ); ?>">
1512 1512
 						<?php
1513 1513
 
1514
-						break;
1515
-					case "select":
1516
-						$multiple = isset( $args['multiple'] ) && $args['multiple']  ? true : false;
1517
-						if($multiple){if(empty($value)){$value = array();}}
1518
-						?>
1514
+                        break;
1515
+                    case "select":
1516
+                        $multiple = isset( $args['multiple'] ) && $args['multiple']  ? true : false;
1517
+                        if($multiple){if(empty($value)){$value = array();}}
1518
+                        ?>
1519 1519
 						<label
1520 1520
 							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 1521
 						<select <?php echo $placeholder; ?> class="widefat"
@@ -1523,28 +1523,28 @@  discard block
 block discarded – undo
1523 1523
 							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1524 1524
 							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); if($multiple){echo "[]";}?>"
1525 1525
 							<?php if ($multiple) {
1526
-								echo "multiple";
1527
-							} //@todo not implemented yet due to gutenberg not supporting it
1528
-							?>
1526
+                                echo "multiple";
1527
+                            } //@todo not implemented yet due to gutenberg not supporting it
1528
+                            ?>
1529 1529
 						>
1530 1530
 							<?php
1531 1531
 
1532 1532
 
1533
-							if ( ! empty( $args['options'] ) ) {
1534
-								foreach ( $args['options'] as $val => $label ) {
1533
+                            if ( ! empty( $args['options'] ) ) {
1534
+                                foreach ( $args['options'] as $val => $label ) {
1535 1535
 //									print_r($value);
1536 1536
 //									echo '@@@'.print_r($val,true),'@@@';
1537 1537
 //									echo '###'.$value.'###';
1538
-									if ($multiple) {$selected = in_array($val,$value) ? 'selected="selected"' : ''; }else{$selected = selected( $value, $val, false );}
1539
-									echo "<option value='$val' " . $selected . ">$label</option>";
1540
-								}
1541
-							}
1542
-							?>
1538
+                                    if ($multiple) {$selected = in_array($val,$value) ? 'selected="selected"' : ''; }else{$selected = selected( $value, $val, false );}
1539
+                                    echo "<option value='$val' " . $selected . ">$label</option>";
1540
+                                }
1541
+                            }
1542
+                            ?>
1543 1543
 						</select>
1544 1544
 						<?php
1545
-						break;
1546
-					case "checkbox":
1547
-						?>
1545
+                        break;
1546
+                    case "checkbox":
1547
+                        ?>
1548 1548
 						<input <?php echo $placeholder; ?>
1549 1549
 							<?php checked( 1, $value, true ) ?>
1550 1550
 							<?php echo $custom_attributes;?>
@@ -1554,140 +1554,140 @@  discard block
 block discarded – undo
1554 1554
 						<label
1555 1555
 							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>
1556 1556
 						<?php
1557
-						break;
1558
-					case "hidden":
1559
-						?>
1557
+                        break;
1558
+                    case "hidden":
1559
+                        ?>
1560 1560
 						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1561 1561
 						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
1562 1562
 						       value="<?php echo esc_attr( $value ); ?>">
1563 1563
 						<?php
1564
-						break;
1565
-					default:
1566
-						echo "No input type found!"; // @todo we need to add more input types.
1567
-				}
1564
+                        break;
1565
+                    default:
1566
+                        echo "No input type found!"; // @todo we need to add more input types.
1567
+                }
1568 1568
 
1569
-				// after wrapper
1570
-				?>
1569
+                // after wrapper
1570
+                ?>
1571 1571
 			</p>
1572 1572
 			<?php
1573 1573
 
1574
-		}
1575
-
1576
-
1577
-		/**
1578
-		 * Get the widget input description html.
1579
-		 *
1580
-		 * @param $args
1581
-		 *
1582
-		 * @return string
1583
-		 * @todo, need to make its own tooltip script
1584
-		 */
1585
-		public function widget_field_desc( $args ) {
1586
-
1587
-			$description = '';
1588
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
1589
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
1590
-					$description = $this->desc_tip( $args['desc'] );
1591
-				} else {
1592
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
1593
-				}
1594
-			}
1595
-
1596
-			return $description;
1597
-		}
1598
-
1599
-
1600
-		/**
1601
-		 * Get the tool tip html.
1602
-		 *
1603
-		 * @param $tip
1604
-		 * @param bool $allow_html
1605
-		 *
1606
-		 * @return string
1607
-		 */
1608
-		function desc_tip( $tip, $allow_html = false ) {
1609
-			if ( $allow_html ) {
1610
-				$tip = $this->sanitize_tooltip( $tip );
1611
-			} else {
1612
-				$tip = esc_attr( $tip );
1613
-			}
1614
-
1615
-			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
1616
-		}
1617
-
1618
-		/**
1619
-		 * Sanitize a string destined to be a tooltip.
1620
-		 *
1621
-		 * @param string $var
1622
-		 *
1623
-		 * @return string
1624
-		 */
1625
-		public function sanitize_tooltip( $var ) {
1626
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1627
-				'br'     => array(),
1628
-				'em'     => array(),
1629
-				'strong' => array(),
1630
-				'small'  => array(),
1631
-				'span'   => array(),
1632
-				'ul'     => array(),
1633
-				'li'     => array(),
1634
-				'ol'     => array(),
1635
-				'p'      => array(),
1636
-			) ) );
1637
-		}
1638
-
1639
-		/**
1640
-		 * Processing widget options on save
1641
-		 *
1642
-		 * @param array $new_instance The new options
1643
-		 * @param array $old_instance The previous options
1644
-		 *
1645
-		 * @return array
1646
-		 * @todo we should add some sanitation here.
1647
-		 */
1648
-		public function update( $new_instance, $old_instance ) {
1574
+        }
1575
+
1576
+
1577
+        /**
1578
+         * Get the widget input description html.
1579
+         *
1580
+         * @param $args
1581
+         *
1582
+         * @return string
1583
+         * @todo, need to make its own tooltip script
1584
+         */
1585
+        public function widget_field_desc( $args ) {
1586
+
1587
+            $description = '';
1588
+            if ( isset( $args['desc'] ) && $args['desc'] ) {
1589
+                if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
1590
+                    $description = $this->desc_tip( $args['desc'] );
1591
+                } else {
1592
+                    $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
1593
+                }
1594
+            }
1595
+
1596
+            return $description;
1597
+        }
1598
+
1599
+
1600
+        /**
1601
+         * Get the tool tip html.
1602
+         *
1603
+         * @param $tip
1604
+         * @param bool $allow_html
1605
+         *
1606
+         * @return string
1607
+         */
1608
+        function desc_tip( $tip, $allow_html = false ) {
1609
+            if ( $allow_html ) {
1610
+                $tip = $this->sanitize_tooltip( $tip );
1611
+            } else {
1612
+                $tip = esc_attr( $tip );
1613
+            }
1614
+
1615
+            return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
1616
+        }
1617
+
1618
+        /**
1619
+         * Sanitize a string destined to be a tooltip.
1620
+         *
1621
+         * @param string $var
1622
+         *
1623
+         * @return string
1624
+         */
1625
+        public function sanitize_tooltip( $var ) {
1626
+            return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1627
+                'br'     => array(),
1628
+                'em'     => array(),
1629
+                'strong' => array(),
1630
+                'small'  => array(),
1631
+                'span'   => array(),
1632
+                'ul'     => array(),
1633
+                'li'     => array(),
1634
+                'ol'     => array(),
1635
+                'p'      => array(),
1636
+            ) ) );
1637
+        }
1638
+
1639
+        /**
1640
+         * Processing widget options on save
1641
+         *
1642
+         * @param array $new_instance The new options
1643
+         * @param array $old_instance The previous options
1644
+         *
1645
+         * @return array
1646
+         * @todo we should add some sanitation here.
1647
+         */
1648
+        public function update( $new_instance, $old_instance ) {
1649 1649
 //			print_r($new_instance);
1650 1650
 //			print_r($old_instance);
1651 1651
 //			exit;
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
-	}
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
 }
Please login to merge, or discard this patch.
Spacing   +301 added lines, -301 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
 	/**
@@ -30,29 +30,29 @@  discard block
 block discarded – undo
30 30
 		/**
31 31
 		 * Take the array options and use them to build.
32 32
 		 */
33
-		public function __construct( $options ) {
33
+		public function __construct($options) {
34 34
 			global $sd_widgets;
35 35
 
36 36
 
37 37
 
38 38
 			//print_r($options);exit;
39
-			$sd_widgets[$options['base_id']] = array('name'=> $options['name'],'class_name'=>$options['class_name']);
39
+			$sd_widgets[$options['base_id']] = array('name'=> $options['name'], 'class_name'=>$options['class_name']);
40 40
 			$this->base_id = $options['base_id'];
41 41
 			// lets filter the options before we do anything
42
-			$options       = apply_filters( "wp_super_duper_options", $options );
43
-			$options       = apply_filters( "wp_super_duper_options_{$this->base_id}", $options );
44
-			$options       = $this->add_name_from_key( $options );
42
+			$options       = apply_filters("wp_super_duper_options", $options);
43
+			$options       = apply_filters("wp_super_duper_options_{$this->base_id}", $options);
44
+			$options       = $this->add_name_from_key($options);
45 45
 			$this->options = $options;
46 46
 
47 47
 			$this->base_id   = $options['base_id'];
48
-			$this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array();
48
+			$this->arguments = isset($options['arguments']) ? $options['arguments'] : array();
49 49
 
50 50
 
51 51
 			// init parent
52
-			parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] );
52
+			parent::__construct($options['base_id'], $options['name'], $options['widget_ops']);
53 53
 
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
 
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
 
62 62
 				// register block
63 63
 				//$this->register_block();
64
-				add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) );
64
+				add_action('admin_enqueue_scripts', array($this, 'register_block'));
65 65
 			}
66 66
 
67 67
 			// add the CSS and JS we need ONCE
68 68
 			global $sd_widget_scripts;
69 69
 
70
-			if ( ! $sd_widget_scripts ) {
71
-				wp_add_inline_script( 'admin-widgets', $this->widget_js() );
72
-				wp_add_inline_script( 'customize-controls', $this->widget_js() );
73
-				wp_add_inline_style( 'widgets', $this->widget_css() );
70
+			if (!$sd_widget_scripts) {
71
+				wp_add_inline_script('admin-widgets', $this->widget_js());
72
+				wp_add_inline_script('customize-controls', $this->widget_js());
73
+				wp_add_inline_style('widgets', $this->widget_css());
74 74
 
75 75
 				// seems ashame to add this for one icon but i love it :(
76 76
 				//wp_register_script('font-awesome', 'https://use.fontawesome.com/releases/v5.4.1/js/all.js', array('font-awesome-shim'), $this->version);
@@ -80,14 +80,14 @@  discard block
 block discarded – undo
80 80
 				$sd_widget_scripts = true;
81 81
 
82 82
 				// add shortcode insert button once
83
-				add_action( 'media_buttons',array( $this, 'shortcode_insert_button' ) );
83
+				add_action('media_buttons', array($this, 'shortcode_insert_button'));
84 84
 				//if( !wp_doing_ajax() ){
85
-				add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) );
85
+				add_action('wp_ajax_super_duper_get_widget_settings', array(__CLASS__, 'get_widget_settings'));
86 86
 				//}
87 87
 
88 88
 			}
89 89
 
90
-			do_action( 'wp_super_duper_widget_init', $options, $this );
90
+			do_action('wp_super_duper_widget_init', $options, $this);
91 91
 
92 92
 		}
93 93
 
@@ -96,17 +96,17 @@  discard block
 block discarded – undo
96 96
 		 *
97 97
 		 * @since 2.0.0
98 98
 		 */
99
-		public static function get_widget_settings(){
99
+		public static function get_widget_settings() {
100 100
 			global $sd_widgets;
101 101
 //			print_r($_REQUEST);
102 102
 //			echo '####';
103 103
 
104 104
 			$shortcode = isset($_REQUEST['shortcode']) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes($_REQUEST['shortcode']) : '';
105
-			if(!$shortcode){wp_die();}
106
-			$widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] :'';
107
-			if(!$widget_args){wp_die();}
105
+			if (!$shortcode) {wp_die(); }
106
+			$widget_args = isset($sd_widgets[$shortcode]) ? $sd_widgets[$shortcode] : '';
107
+			if (!$widget_args) {wp_die(); }
108 108
 			$class_name = isset($widget_args['class_name']) && $widget_args['class_name'] ? $widget_args['class_name'] : '';
109
-			if(!$class_name){wp_die();}
109
+			if (!$class_name) {wp_die(); }
110 110
 
111 111
 
112 112
 
@@ -122,11 +122,11 @@  discard block
 block discarded – undo
122 122
 			ob_start();
123 123
 			$widget->form(array());
124 124
 			$form = ob_get_clean();
125
-			echo "<form id='$shortcode'>".$form."<div class=\"widget-control-save\"></div></form>";
125
+			echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>";
126 126
 //			echo "<div id='sd-shortcode-output'></div>";
127 127
 
128
-			echo "<style>".$widget->widget_css()."</style>";
129
-			echo "<script>".$widget->widget_js()."</script>";
128
+			echo "<style>" . $widget->widget_css() . "</style>";
129
+			echo "<script>" . $widget->widget_js() . "</script>";
130 130
 			?>
131 131
 			<?php
132 132
 			wp_die();
@@ -140,9 +140,9 @@  discard block
 block discarded – undo
140 140
 		 * @param string $editor_id Optional. Shortcode editor id. Default null.
141 141
 		 * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null.
142 142
 		 */
143
-		public static function shortcode_insert_button($editor_id = '',$insert_shortcode_function=''){
144
-			global $sd_widgets,$shortcode_insert_button_once;
145
-			if($shortcode_insert_button_once){return;}
143
+		public static function shortcode_insert_button($editor_id = '', $insert_shortcode_function = '') {
144
+			global $sd_widgets, $shortcode_insert_button_once;
145
+			if ($shortcode_insert_button_once) {return; }
146 146
 			add_thickbox();
147 147
 			?>
148 148
 			<div id="super-duper-content" style="display:none;">
@@ -150,12 +150,12 @@  discard block
 block discarded – undo
150 150
 				<div class="sd-shortcode-left-wrap">
151 151
 					<?php
152 152
 					//print_r( $sd_widgets );
153
-					asort($sd_widgets );
154
-					if(!empty($sd_widgets)){
153
+					asort($sd_widgets);
154
+					if (!empty($sd_widgets)) {
155 155
 						echo '<select onchange="sd_get_shortcode_options(this);">';
156
-						echo "<option>".__('Select shortcode')."</option>";
157
-						foreach($sd_widgets as $shortcode => $class){
158
-							echo "<option value='".esc_attr($shortcode)."'>".esc_attr($shortcode)." (".esc_attr($class['name']).")</option>";
156
+						echo "<option>" . __('Select shortcode') . "</option>";
157
+						foreach ($sd_widgets as $shortcode => $class) {
158
+							echo "<option value='" . esc_attr($shortcode) . "'>" . esc_attr($shortcode) . " (" . esc_attr($class['name']) . ")</option>";
159 159
 						}
160 160
 						echo "</select>";
161 161
 
@@ -168,15 +168,15 @@  discard block
 block discarded – undo
168 168
 				<div  class="sd-shortcode-right-wrap">
169 169
 					<textarea id='sd-shortcode-output' disabled></textarea>
170 170
 					<div id='sd-shortcode-output-actions'>
171
-						<button class="button" onclick="sd_insert_shortcode()"><?php _e('Insert shortcode');?></button>
172
-						<button class="button" onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode');?></button>
171
+						<button class="button" onclick="sd_insert_shortcode()"><?php _e('Insert shortcode'); ?></button>
172
+						<button class="button" onclick="sd_copy_to_clipboard()"><?php _e('Copy shortcode'); ?></button>
173 173
 					</div>
174 174
 				</div>
175 175
 
176 176
 			</div>
177 177
 
178 178
 
179
-			<a href="#TB_inline?width=100%&height=550&inlineId=super-duper-content" class="thickbox button super-duper-content-open" title="<?php _e('Add Shortcode');?>"><i class="fas fa-cubes" aria-hidden="true"></i></a>
179
+			<a href="#TB_inline?width=100%&height=550&inlineId=super-duper-content" class="thickbox button super-duper-content-open" title="<?php _e('Add Shortcode'); ?>"><i class="fas fa-cubes" aria-hidden="true"></i></a>
180 180
 
181 181
 			<style>
182 182
 				.sd-shortcode-left-wrap{
@@ -198,9 +198,9 @@  discard block
 block discarded – undo
198 198
 			<script>
199 199
 
200 200
 				<?php
201
-				if(!empty($insert_shortcode_function)){
201
+				if (!empty($insert_shortcode_function)) {
202 202
 					echo $insert_shortcode_function;
203
-				}else{
203
+				} else {
204 204
 
205 205
 				/**
206 206
 				 * Function for super duper insert shortcode.
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 							'shortcode': $short_code,
255 255
 							'attributes': 123,
256 256
 							'post_id': 321,
257
-							'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
257
+							'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
258 258
 						};
259 259
 
260 260
 						jQuery.post(ajaxurl, data, function (response) {
@@ -380,10 +380,10 @@  discard block
 block discarded – undo
380 380
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
381 381
 			 */
382 382
 
383
-			return str_replace( array(
383
+			return str_replace(array(
384 384
 				'<style>',
385 385
 				'</style>'
386
-			), '', $output );
386
+			), '', $output);
387 387
 		}
388 388
 
389 389
 		public function widget_js() {
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
 					});
542 542
 
543 543
 				}
544
-				<?php do_action( 'wp_super_duper_widget_js', $this ); ?>
544
+				<?php do_action('wp_super_duper_widget_js', $this); ?>
545 545
 			</script>
546 546
 			<?php
547 547
 			$output = ob_get_clean();
@@ -550,10 +550,10 @@  discard block
 block discarded – undo
550 550
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
551 551
 			 */
552 552
 
553
-			return str_replace( array(
553
+			return str_replace(array(
554 554
 				'<script>',
555 555
 				'</script>'
556
-			), '', $output );
556
+			), '', $output);
557 557
 		}
558 558
 
559 559
 
@@ -564,14 +564,14 @@  discard block
 block discarded – undo
564 564
 		 *
565 565
 		 * @return mixed
566 566
 		 */
567
-		private function add_name_from_key( $options, $arguments = false ) {
568
-			if ( ! empty( $options['arguments'] ) ) {
569
-				foreach ( $options['arguments'] as $key => $val ) {
570
-					$options['arguments'][ $key ]['name'] = $key;
567
+		private function add_name_from_key($options, $arguments = false) {
568
+			if (!empty($options['arguments'])) {
569
+				foreach ($options['arguments'] as $key => $val) {
570
+					$options['arguments'][$key]['name'] = $key;
571 571
 				}
572
-			} elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) {
573
-				foreach ( $options as $key => $val ) {
574
-					$options[ $key ]['name'] = $key;
572
+			} elseif ($arguments && is_array($options) && !empty($options)) {
573
+				foreach ($options as $key => $val) {
574
+					$options[$key]['name'] = $key;
575 575
 				}
576 576
 			}
577 577
 
@@ -584,8 +584,8 @@  discard block
 block discarded – undo
584 584
 		 * @since 2.0.0
585 585
 		 */
586 586
 		public function register_shortcode() {
587
-			add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) );
588
-			add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) );
587
+			add_shortcode($this->base_id, array($this, 'shortcode_output'));
588
+			add_action('wp_ajax_super_duper_output_shortcode', array(__CLASS__, 'render_shortcode'));
589 589
 		}
590 590
 
591 591
 		/**
@@ -595,33 +595,33 @@  discard block
 block discarded – undo
595 595
 		 */
596 596
 		public static function render_shortcode() {
597 597
 
598
-			check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true );
599
-			if ( ! current_user_can( 'manage_options' ) ) {
598
+			check_ajax_referer('super_duper_output_shortcode', '_ajax_nonce', true);
599
+			if (!current_user_can('manage_options')) {
600 600
 				wp_die();
601 601
 			}
602 602
 
603 603
 			// we might need the $post value here so lets set it.
604
-			if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) {
605
-				$post_obj = get_post( absint( $_POST['post_id'] ) );
606
-				if ( ! empty( $post_obj ) && empty( $post ) ) {
604
+			if (isset($_POST['post_id']) && $_POST['post_id']) {
605
+				$post_obj = get_post(absint($_POST['post_id']));
606
+				if (!empty($post_obj) && empty($post)) {
607 607
 					global $post;
608 608
 					$post = $post_obj;
609 609
 				}
610 610
 			}
611 611
 
612
-			if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) {
613
-				$shortcode_name   = sanitize_title_with_dashes( $_POST['shortcode'] );
614
-				$attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array();
612
+			if (isset($_POST['shortcode']) && $_POST['shortcode']) {
613
+				$shortcode_name   = sanitize_title_with_dashes($_POST['shortcode']);
614
+				$attributes_array = isset($_POST['attributes']) && $_POST['attributes'] ? $_POST['attributes'] : array();
615 615
 				$attributes       = '';
616
-				if ( ! empty( $attributes_array ) ) {
617
-					foreach ( $attributes_array as $key => $value ) {
618
-						$attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' ";
616
+				if (!empty($attributes_array)) {
617
+					foreach ($attributes_array as $key => $value) {
618
+						$attributes .= " " . sanitize_title_with_dashes($key) . "='" . wp_slash($value) . "' ";
619 619
 					}
620 620
 				}
621 621
 
622 622
 				$shortcode = "[" . $shortcode_name . " " . $attributes . "]";
623 623
 
624
-				echo do_shortcode( $shortcode );
624
+				echo do_shortcode($shortcode);
625 625
 
626 626
 			}
627 627
 			wp_die();
@@ -633,37 +633,37 @@  discard block
 block discarded – undo
633 633
 		 * @param array $args
634 634
 		 * @param string $content
635 635
 		 */
636
-		public function shortcode_output( $args = array(), $content = '' ) {
637
-			$args = self::argument_values( $args );
636
+		public function shortcode_output($args = array(), $content = '') {
637
+			$args = self::argument_values($args);
638 638
 
639 639
 			// add extra argument so we know its a output to gutenberg
640 640
 			//$args
641
-			$args = $this->string_to_bool( $args );
641
+			$args = $this->string_to_bool($args);
642 642
 
643 643
 
644 644
 			$calss = isset($this->options['widget_ops']['classname']) ? esc_attr($this->options['widget_ops']['classname']) : '';
645 645
 
646
-			$calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this );
647
-			$calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this );
646
+			$calss = apply_filters('wp_super_duper_div_classname', $calss, $args, $this);
647
+			$calss = apply_filters('wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this);
648 648
 
649
-			$attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this );
650
-			$attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this );
649
+			$attrs = apply_filters('wp_super_duper_div_attrs', '', $args, $this);
650
+			$attrs = apply_filters('wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this);
651 651
 
652 652
 			$shortcode_args = array();
653 653
 			$output = '';
654 654
 			$no_wrap = isset($this->options['no_wrap']) && $this->options['no_wrap'] ?  true : false;
655
-			$main_content = $this->output( $args, $shortcode_args, $content );
656
-			if($main_content && !$no_wrap){
655
+			$main_content = $this->output($args, $shortcode_args, $content);
656
+			if ($main_content && !$no_wrap) {
657 657
 				// wrap the shortcode in a dive with the same class as the widget
658
-				$output .= '<div class="'.$calss.'" ' . $attrs . '>';
659
-				if(!empty($args['title'])){
658
+				$output .= '<div class="' . $calss . '" ' . $attrs . '>';
659
+				if (!empty($args['title'])) {
660 660
 					// if its a shortcode and there is a title try to grab the title wrappers
661 661
 					$shortcode_args = array('before_title'=>'', 'after_title' => '');
662
-					if(empty($instance)){
662
+					if (empty($instance)) {
663 663
 						global $wp_registered_sidebars;
664
-						if(!empty($wp_registered_sidebars)){
665
-							foreach($wp_registered_sidebars as $sidebar){
666
-								if(!empty($sidebar['before_title'])){
664
+						if (!empty($wp_registered_sidebars)) {
665
+							foreach ($wp_registered_sidebars as $sidebar) {
666
+								if (!empty($sidebar['before_title'])) {
667 667
 									$shortcode_args['before_title'] = $sidebar['before_title'];
668 668
 									$shortcode_args['after_title'] = $sidebar['after_title'];
669 669
 									break;
@@ -671,11 +671,11 @@  discard block
 block discarded – undo
671 671
 							}
672 672
 						}
673 673
 					}
674
-					$output .= $this->output_title($shortcode_args,$args);
674
+					$output .= $this->output_title($shortcode_args, $args);
675 675
 				}
676 676
 				$output .= $main_content;
677 677
 				$output .= '</div>';
678
-			}elseif($main_content && $no_wrap){
678
+			}elseif ($main_content && $no_wrap) {
679 679
 				$output .= $main_content;
680 680
 			}
681 681
 
@@ -690,13 +690,13 @@  discard block
 block discarded – undo
690 690
 		 *
691 691
 		 * @return mixed
692 692
 		 */
693
-		public function string_to_bool( $options ) {
693
+		public function string_to_bool($options) {
694 694
 			// convert bool strings to booleans
695
-			foreach ( $options as $key => $val ) {
696
-				if ( $val == 'false' ) {
697
-					$options[ $key ] = false;
698
-				} elseif ( $val == 'true' ) {
699
-					$options[ $key ] = true;
695
+			foreach ($options as $key => $val) {
696
+				if ($val == 'false') {
697
+					$options[$key] = false;
698
+				} elseif ($val == 'true') {
699
+					$options[$key] = true;
700 700
 				}
701 701
 			}
702 702
 
@@ -710,24 +710,24 @@  discard block
 block discarded – undo
710 710
 		 *
711 711
 		 * @return array
712 712
 		 */
713
-		public function argument_values( $instance ) {
713
+		public function argument_values($instance) {
714 714
 			$argument_values = array();
715 715
 
716 716
 			// set widget instance
717 717
 			$this->instance = $instance;
718 718
 
719
-			if ( empty( $this->arguments ) ) {
719
+			if (empty($this->arguments)) {
720 720
 				$this->arguments = $this->get_arguments();
721 721
 			}
722 722
 
723
-			if ( ! empty( $this->arguments ) ) {
724
-				foreach ( $this->arguments as $key => $args ) {
723
+			if (!empty($this->arguments)) {
724
+				foreach ($this->arguments as $key => $args) {
725 725
 					// set the input name from the key
726 726
 					$args['name'] = $key;
727 727
 					//
728
-					$argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : '';
729
-					if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) {
730
-						$argument_values[ $key ] = $args['default'];
728
+					$argument_values[$key] = isset($instance[$key]) ? $instance[$key] : '';
729
+					if ($argument_values[$key] == '' && isset($args['default'])) {
730
+						$argument_values[$key] = $args['default'];
731 731
 					}
732 732
 				}
733 733
 			}
@@ -754,12 +754,12 @@  discard block
 block discarded – undo
754 754
 		 * @return array Get arguments.
755 755
 		 */
756 756
 		public function get_arguments() {
757
-			if ( empty( $this->arguments ) ) {
758
-				$this->arguments =  $this->set_arguments();
757
+			if (empty($this->arguments)) {
758
+				$this->arguments = $this->set_arguments();
759 759
 			}
760 760
 
761
-			$this->arguments = apply_filters('wp_super_duper_arguments',$this->arguments,$this->options, $this->instance);
762
-			$this->arguments = $this->add_name_from_key( $this->arguments, true );
761
+			$this->arguments = apply_filters('wp_super_duper_arguments', $this->arguments, $this->options, $this->instance);
762
+			$this->arguments = $this->add_name_from_key($this->arguments, true);
763 763
 
764 764
 
765 765
 			return $this->arguments;
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
 		 * @param array $widget_args
773 773
 		 * @param string $content
774 774
 		 */
775
-		public function output( $args = array(), $widget_args = array(), $content = '' ) {
775
+		public function output($args = array(), $widget_args = array(), $content = '') {
776 776
 
777 777
 		}
778 778
 
@@ -780,7 +780,7 @@  discard block
 block discarded – undo
780 780
 		 * Add the dyanmic block code inline when the wp-block in enqueued.
781 781
 		 */
782 782
 		public function register_block() {
783
-			wp_add_inline_script( 'wp-blocks', $this->block() );
783
+			wp_add_inline_script('wp-blocks', $this->block());
784 784
 		}
785 785
 
786 786
 
@@ -794,13 +794,13 @@  discard block
 block discarded – undo
794 794
 			$show      = false;
795 795
 			$arguments = $this->arguments;
796 796
 
797
-			if(empty($arguments)){
797
+			if (empty($arguments)) {
798 798
 				$arguments = $this->get_arguments();
799 799
 			}
800 800
 
801
-			if ( ! empty( $arguments ) ) {
802
-				foreach ( $arguments as $argument ) {
803
-					if ( isset( $argument['advanced'] ) && $argument['advanced'] ) {
801
+			if (!empty($arguments)) {
802
+				foreach ($arguments as $argument) {
803
+					if (isset($argument['advanced']) && $argument['advanced']) {
804 804
 						$show = true;
805 805
 					}
806 806
 				}
@@ -850,12 +850,12 @@  discard block
 block discarded – undo
850 850
 					 * @return {?WPBlock}          The block, if it has been successfully
851 851
 					 *                             registered; otherwise `undefined`.
852 852
 					 */
853
-					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.
854
-						title: '<?php echo $this->options['name'];?>', // Block title.
855
-						description: '<?php echo esc_attr( $this->options['widget_ops']['description'] )?>', // Block title.
856
-						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/.
857
-						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.
858
-						<?php if ( isset( $this->options['block-keywords'] ) ) {
853
+					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.
854
+						title: '<?php echo $this->options['name']; ?>', // Block title.
855
+						description: '<?php echo esc_attr($this->options['widget_ops']['description'])?>', // Block title.
856
+						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/.
857
+						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.
858
+						<?php if (isset($this->options['block-keywords'])) {
859 859
 						echo "keywords : " . $this->options['block-keywords'] . ",";
860 860
 					}?>
861 861
 
@@ -865,44 +865,44 @@  discard block
 block discarded – undo
865 865
 
866 866
 						$show_alignment = false;
867 867
 
868
-						if ( ! empty( $this->arguments ) ) {
868
+						if (!empty($this->arguments)) {
869 869
 							echo "attributes : {";
870 870
 
871
-							if ( $show_advanced ) {
871
+							if ($show_advanced) {
872 872
 								echo "show_advanced: {";
873 873
 								echo "	type: 'boolean',";
874 874
 								echo "  default: false,";
875 875
 								echo "},";
876 876
 							}
877 877
 
878
-							foreach ( $this->arguments as $key => $args ) {
878
+							foreach ($this->arguments as $key => $args) {
879 879
 
880 880
 								// set if we should show alignment
881
-								if ( $key == 'alignment' ) {
881
+								if ($key == 'alignment') {
882 882
 									$show_alignment = true;
883 883
 								}
884 884
 
885 885
 								$extra = '';
886 886
 
887
-								if ( $args['type'] == 'checkbox' ) {
887
+								if ($args['type'] == 'checkbox') {
888 888
 									$type    = 'boolean';
889
-									$default = isset( $args['default'] ) && "'" . $args['default'] . "'" ? 'true' : 'false';
890
-								} elseif ( $args['type'] == 'number' ) {
889
+									$default = isset($args['default']) && "'" . $args['default'] . "'" ? 'true' : 'false';
890
+								} elseif ($args['type'] == 'number') {
891 891
 									$type    = 'number';
892
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
893
-								} elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) {
892
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
893
+								} elseif ($args['type'] == 'select' && !empty($args['multiple'])) {
894 894
 									$type    = 'array';
895
-									if(is_array($args['default'])){
896
-										$default = isset( $args['default'] ) ? "['" . implode("','", $args['default']) . "']" : "[]";
897
-									}else{
898
-										$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
895
+									if (is_array($args['default'])) {
896
+										$default = isset($args['default']) ? "['" . implode("','", $args['default']) . "']" : "[]";
897
+									} else {
898
+										$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
899 899
 									}
900
-								} elseif ( $args['type'] == 'multiselect' ) {
900
+								} elseif ($args['type'] == 'multiselect') {
901 901
 									$type    = 'array';
902
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
902
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
903 903
 								} else {
904 904
 									$type    = 'string';
905
-									$default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''";
905
+									$default = isset($args['default']) ? "'" . $args['default'] . "'" : "''";
906 906
 								}
907 907
 								echo $key . " : {";
908 908
 								echo "type : '$type',";
@@ -932,12 +932,12 @@  discard block
 block discarded – undo
932 932
 									is_fetching = true;
933 933
 									var data = {
934 934
 										'action': 'super_duper_output_shortcode',
935
-										'shortcode': '<?php echo $this->options['base_id'];?>',
935
+										'shortcode': '<?php echo $this->options['base_id']; ?>',
936 936
 										'attributes': props.attributes,
937
-										'post_id': <?php global $post; if ( isset( $post->ID ) ) {
937
+										'post_id': <?php global $post; if (isset($post->ID)) {
938 938
 										echo $post->ID;
939 939
 									}?>,
940
-										'_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>'
940
+										'_ajax_nonce': '<?php echo wp_create_nonce('super_duper_output_shortcode'); ?>'
941 941
 									};
942 942
 
943 943
 									jQuery.post(ajaxurl, data, function (response) {
@@ -946,7 +946,7 @@  discard block
 block discarded – undo
946 946
 
947 947
 										// if the content is empty then we place some placeholder text
948 948
 										if(env==''){
949
-											env = "<div style='background:#0185ba33;padding: 10px;'>"+"<?php _e('Placeholder for: ');?>"+props.name+"</div>";
949
+											env = "<div style='background:#0185ba33;padding: 10px;'>"+"<?php _e('Placeholder for: '); ?>"+props.name+"</div>";
950 950
 										}
951 951
 
952 952
 										props.setAttributes({content: env});
@@ -966,7 +966,7 @@  discard block
 block discarded – undo
966 966
 
967 967
 								el(wp.editor.BlockControls, {key: 'controls'},
968 968
 
969
-									<?php if($show_alignment){?>
969
+									<?php if ($show_alignment) {?>
970 970
 									el(
971 971
 										wp.editor.AlignmentToolbar,
972 972
 										{
@@ -984,9 +984,9 @@  discard block
 block discarded – undo
984 984
 
985 985
 									<?php
986 986
 
987
-									if(! empty( $this->arguments )){
987
+									if (!empty($this->arguments)) {
988 988
 
989
-									if ( $show_advanced ) {
989
+									if ($show_advanced) {
990 990
 									?>
991 991
 									el(
992 992
 										wp.components.ToggleControl,
@@ -1002,68 +1002,68 @@  discard block
 block discarded – undo
1002 1002
 
1003 1003
 									}
1004 1004
 
1005
-									foreach($this->arguments as $key => $args){
1005
+									foreach ($this->arguments as $key => $args) {
1006 1006
 									$custom_attributes = !empty($args['custom_attributes']) ? $this->array_to_attributes($args['custom_attributes']) : '';
1007 1007
 									$options = '';
1008 1008
 									$extra = '';
1009 1009
 									$require = '';
1010 1010
 									$onchange = "props.setAttributes({ $key: $key } )";
1011 1011
 									$value = "props.attributes.$key";
1012
-									$text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' );
1013
-									if ( in_array( $args['type'], $text_type ) ) {
1012
+									$text_type = array('text', 'password', 'number', 'email', 'tel', 'url', 'color');
1013
+									if (in_array($args['type'], $text_type)) {
1014 1014
 										$type = 'TextControl';
1015
-									} elseif ( $args['type'] == 'checkbox' ) {
1015
+									} elseif ($args['type'] == 'checkbox') {
1016 1016
 										$type = 'CheckboxControl';
1017 1017
 										$extra .= "checked: props.attributes.$key,";
1018 1018
 										$onchange = "props.setAttributes({ $key: ! props.attributes.$key } )";
1019
-									} elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) {
1019
+									} elseif ($args['type'] == 'select' || $args['type'] == 'multiselect') {
1020 1020
 										$type = 'SelectControl';
1021
-										if ( ! empty( $args['options'] ) ) {
1021
+										if (!empty($args['options'])) {
1022 1022
 											$options .= "options  : [";
1023
-											foreach ( $args['options'] as $option_val => $option_label ) {
1024
-												$options .= "{ value : '" . esc_attr( $option_val ) . "',     label : '" . esc_attr( $option_label ) . "'     },";
1023
+											foreach ($args['options'] as $option_val => $option_label) {
1024
+												$options .= "{ value : '" . esc_attr($option_val) . "',     label : '" . esc_attr($option_label) . "'     },";
1025 1025
 											}
1026 1026
 											$options .= "],";
1027 1027
 										}
1028
-										if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1028
+										if (isset($args['multiple']) && $args['multiple']) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550
1029 1029
 											$extra .= ' multiple: true, ';
1030 1030
 											//$onchange = "props.setAttributes({ $key: ['edit'] } )";
1031 1031
 											//$value = "['edit', 'delete']";
1032 1032
 										}
1033
-									} elseif ( $args['type'] == 'alignment' ) {
1033
+									} elseif ($args['type'] == 'alignment') {
1034 1034
 										$type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example
1035 1035
 									} else {
1036
-										continue;// if we have not implemented the control then don't break the JS.
1036
+										continue; // if we have not implemented the control then don't break the JS.
1037 1037
 									}
1038 1038
 
1039 1039
 									// add show only if advanced
1040
-									if ( ! empty( $args['advanced'] ) ) {
1040
+									if (!empty($args['advanced'])) {
1041 1041
 										echo "props.attributes.show_advanced && ";
1042 1042
 									}
1043 1043
 									// add setting require if defined
1044
-									if ( ! empty( $args['element_require'] ) ) {
1045
-										echo $this->block_props_replace( $args['element_require'], true ) . " && ";
1044
+									if (!empty($args['element_require'])) {
1045
+										echo $this->block_props_replace($args['element_require'], true) . " && ";
1046 1046
 									}
1047 1047
 									?>
1048 1048
 									el(
1049
-										wp.components.<?php echo esc_attr( $type );?>,
1049
+										wp.components.<?php echo esc_attr($type); ?>,
1050 1050
 										{
1051
-											label: '<?php echo esc_attr( $args['title'] );?>',
1052
-											help: '<?php if ( isset( $args['desc'] ) ) {
1053
-												echo esc_attr( $args['desc'] );
1051
+											label: '<?php echo esc_attr($args['title']); ?>',
1052
+											help: '<?php if (isset($args['desc'])) {
1053
+												echo esc_attr($args['desc']);
1054 1054
 											}?>',
1055
-											value: <?php echo $value;?>,
1056
-											<?php if ( $type == 'TextControl' && $args['type'] != 'text' ) {
1057
-											echo "type: '" . esc_attr( $args['type'] ) . "',";
1055
+											value: <?php echo $value; ?>,
1056
+											<?php if ($type == 'TextControl' && $args['type'] != 'text') {
1057
+											echo "type: '" . esc_attr($args['type']) . "',";
1058 1058
 										}?>
1059
-											<?php if ( ! empty( $args['placeholder'] ) ) {
1060
-											echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',";
1059
+											<?php if (!empty($args['placeholder'])) {
1060
+											echo "placeholder: '" . esc_attr($args['placeholder']) . "',";
1061 1061
 										}?>
1062
-											<?php echo $options;?>
1063
-											<?php echo $extra;?>
1064
-											<?php echo $custom_attributes;?>
1065
-											onChange: function ( <?php echo $key;?> ) {
1066
-												<?php echo $onchange;?>
1062
+											<?php echo $options; ?>
1063
+											<?php echo $extra; ?>
1064
+											<?php echo $custom_attributes; ?>
1065
+											onChange: function ( <?php echo $key; ?> ) {
1066
+												<?php echo $onchange; ?>
1067 1067
 											}
1068 1068
 										}
1069 1069
 									),
@@ -1076,9 +1076,9 @@  discard block
 block discarded – undo
1076 1076
 
1077 1077
 								<?php
1078 1078
 								// If the user sets block-output array then build it
1079
-								if ( ! empty( $this->options['block-output'] ) ) {
1080
-								$this->block_element( $this->options['block-output'] );
1081
-							}else{
1079
+								if (!empty($this->options['block-output'])) {
1080
+								$this->block_element($this->options['block-output']);
1081
+							} else {
1082 1082
 								// if no block-output is set then we try and get the shortcode html output via ajax.
1083 1083
 								?>
1084 1084
 								el('div', {
@@ -1102,14 +1102,14 @@  discard block
 block discarded – undo
1102 1102
 							var align = '';
1103 1103
 
1104 1104
 							// build the shortcode.
1105
-							var content = "[<?php echo $this->options['base_id'];?>";
1105
+							var content = "[<?php echo $this->options['base_id']; ?>";
1106 1106
 							<?php
1107 1107
 
1108
-							if(! empty( $this->arguments )){
1109
-							foreach($this->arguments as $key => $args){
1108
+							if (!empty($this->arguments)) {
1109
+							foreach ($this->arguments as $key => $args) {
1110 1110
 							?>
1111
-							if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) {
1112
-								content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' ";
1111
+							if (attr.hasOwnProperty("<?php echo esc_attr($key); ?>")) {
1112
+								content += " <?php echo esc_attr($key); ?>='" + attr.<?php echo esc_attr($key); ?>+ "' ";
1113 1113
 							}
1114 1114
 							<?php
1115 1115
 							}
@@ -1146,10 +1146,10 @@  discard block
 block discarded – undo
1146 1146
 			 * We only add the <script> tags for code highlighting, so we strip them from the output.
1147 1147
 			 */
1148 1148
 
1149
-			return str_replace( array(
1149
+			return str_replace(array(
1150 1150
 				'<script>',
1151 1151
 				'</script>'
1152
-			), '', $output );
1152
+			), '', $output);
1153 1153
 		}
1154 1154
 
1155 1155
 		/**
@@ -1160,16 +1160,16 @@  discard block
 block discarded – undo
1160 1160
 		 *
1161 1161
 		 * @return string
1162 1162
 		 */
1163
-		public function array_to_attributes($custom_attributes, $html = false){
1163
+		public function array_to_attributes($custom_attributes, $html = false) {
1164 1164
 			$attributes = '';
1165
-			if(!empty($custom_attributes)){
1165
+			if (!empty($custom_attributes)) {
1166 1166
 
1167
-				if($html){
1168
-					foreach($custom_attributes as $key => $val){
1167
+				if ($html) {
1168
+					foreach ($custom_attributes as $key => $val) {
1169 1169
 						$attributes .= " $key='$val' ";
1170 1170
 					}
1171
-				}else{
1172
-					foreach($custom_attributes as $key => $val){
1171
+				} else {
1172
+					foreach ($custom_attributes as $key => $val) {
1173 1173
 						$attributes .= "'$key': '$val',";
1174 1174
 					}
1175 1175
 				}
@@ -1186,86 +1186,86 @@  discard block
 block discarded – undo
1186 1186
 		 *
1187 1187
 		 * @param $args
1188 1188
 		 */
1189
-		public function block_element( $args ) {
1189
+		public function block_element($args) {
1190 1190
 
1191 1191
 
1192
-			if ( ! empty( $args ) ) {
1193
-				foreach ( $args as $element => $new_args ) {
1192
+			if (!empty($args)) {
1193
+				foreach ($args as $element => $new_args) {
1194 1194
 
1195
-					if ( is_array( $new_args ) ) { // its an element
1195
+					if (is_array($new_args)) { // its an element
1196 1196
 
1197 1197
 
1198
-						if ( isset( $new_args['element'] ) ) {
1198
+						if (isset($new_args['element'])) {
1199 1199
 
1200 1200
 							//print_r($new_args);
1201 1201
 
1202
-							if ( isset( $new_args['element_require'] ) ) {
1203
-								echo str_replace( array(
1202
+							if (isset($new_args['element_require'])) {
1203
+								echo str_replace(array(
1204 1204
 										"'+",
1205 1205
 										"+'"
1206
-									), '', $this->block_props_replace( $new_args['element_require'] ) ) . " &&  ";
1207
-								unset( $new_args['element_require'] );
1206
+									), '', $this->block_props_replace($new_args['element_require'])) . " &&  ";
1207
+								unset($new_args['element_require']);
1208 1208
 							}
1209 1209
 
1210 1210
 							echo "\n el( '" . $new_args['element'] . "', {";
1211 1211
 
1212 1212
 							// get the attributes
1213
-							foreach ( $new_args as $new_key => $new_value ) {
1213
+							foreach ($new_args as $new_key => $new_value) {
1214 1214
 
1215 1215
 
1216
-								if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) {
1216
+								if ($new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array($new_value)) {
1217 1217
 									// do nothing
1218 1218
 								} else {
1219
-									echo $this->block_element( array( $new_key => $new_value ) );
1219
+									echo $this->block_element(array($new_key => $new_value));
1220 1220
 								}
1221 1221
 							}
1222 1222
 
1223
-							echo "},";// end attributes
1223
+							echo "},"; // end attributes
1224 1224
 
1225 1225
 							// get the content
1226 1226
 							$first_item = 0;
1227
-							foreach ( $new_args as $new_key => $new_value ) {
1228
-								if ( $new_key === 'content' || is_array( $new_value ) ) {
1227
+							foreach ($new_args as $new_key => $new_value) {
1228
+								if ($new_key === 'content' || is_array($new_value)) {
1229 1229
 									//echo ",".$first_item;// separate the children
1230 1230
 
1231 1231
 
1232
-									if ( $first_item > 0 ) {
1232
+									if ($first_item > 0) {
1233 1233
 										//echo ",";// separate the children
1234 1234
 									} else {
1235 1235
 										//echo '####'.$first_item;
1236 1236
 									}
1237 1237
 
1238
-									if ( $new_key === 'content' ) {
1238
+									if ($new_key === 'content') {
1239 1239
 										//print_r($new_args);
1240
-										echo "'" . $this->block_props_replace( $new_value ) . "'";
1240
+										echo "'" . $this->block_props_replace($new_value) . "'";
1241 1241
 									}
1242 1242
 
1243
-									if ( is_array( $new_value ) ) {
1243
+									if (is_array($new_value)) {
1244 1244
 
1245
-										if ( isset( $new_value['element_require'] ) ) {
1246
-											echo str_replace( array(
1245
+										if (isset($new_value['element_require'])) {
1246
+											echo str_replace(array(
1247 1247
 													"'+",
1248 1248
 													"+'"
1249
-												), '', $this->block_props_replace( $new_value['element_require'] ) ) . " &&  ";
1250
-											unset( $new_value['element_require'] );
1249
+												), '', $this->block_props_replace($new_value['element_require'])) . " &&  ";
1250
+											unset($new_value['element_require']);
1251 1251
 										}
1252 1252
 
1253
-										if ( isset( $new_value['element_repeat'] ) ) {
1253
+										if (isset($new_value['element_repeat'])) {
1254 1254
 											$x = 1;
1255
-											while ( $x <= absint( $new_value['element_repeat'] ) ) {
1256
-												$this->block_element( array( '' => $new_value ) );
1257
-												$x ++;
1255
+											while ($x <= absint($new_value['element_repeat'])) {
1256
+												$this->block_element(array('' => $new_value));
1257
+												$x++;
1258 1258
 											}
1259 1259
 										} else {
1260
-											$this->block_element( array( '' => $new_value ) );
1260
+											$this->block_element(array('' => $new_value));
1261 1261
 										}
1262 1262
 										//print_r($new_value);
1263 1263
 									}
1264
-									$first_item ++;
1264
+									$first_item++;
1265 1265
 								}
1266 1266
 							}
1267 1267
 
1268
-							echo ")";// end content
1268
+							echo ")"; // end content
1269 1269
 
1270 1270
 							//if($first_item>0){
1271 1271
 							echo ", \n";
@@ -1276,12 +1276,12 @@  discard block
 block discarded – undo
1276 1276
 						//$this->block_element($new_args);
1277 1277
 					} else {
1278 1278
 
1279
-						if ( substr( $element, 0, 3 ) === "if_" ) {
1280
-							echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ",";
1281
-						} elseif ( $element == 'style' ) {
1282
-							echo $element . ": " . $this->block_props_replace( $new_args ) . ",";
1279
+						if (substr($element, 0, 3) === "if_") {
1280
+							echo str_replace("if_", "", $element) . ": " . $this->block_props_replace($new_args, true) . ",";
1281
+						} elseif ($element == 'style') {
1282
+							echo $element . ": " . $this->block_props_replace($new_args) . ",";
1283 1283
 						} else {
1284
-							echo $element . ": '" . $this->block_props_replace( $new_args ) . "',";
1284
+							echo $element . ": '" . $this->block_props_replace($new_args) . "',";
1285 1285
 						}
1286 1286
 
1287 1287
 					}
@@ -1298,12 +1298,12 @@  discard block
 block discarded – undo
1298 1298
 		 *
1299 1299
 		 * @return mixed
1300 1300
 		 */
1301
-		public function block_props_replace( $string, $no_wrap = false ) {
1301
+		public function block_props_replace($string, $no_wrap = false) {
1302 1302
 
1303
-			if ( $no_wrap ) {
1304
-				$string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string );
1303
+			if ($no_wrap) {
1304
+				$string = str_replace(array("[%", "%]"), array("props.attributes.", ""), $string);
1305 1305
 			} else {
1306
-				$string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string );
1306
+				$string = str_replace(array("[%", "%]"), array("'+props.attributes.", "+'"), $string);
1307 1307
 			}
1308 1308
 
1309 1309
 			return $string;
@@ -1315,24 +1315,24 @@  discard block
 block discarded – undo
1315 1315
 		 * @param array $args
1316 1316
 		 * @param array $instance
1317 1317
 		 */
1318
-		public function widget( $args, $instance ) {
1318
+		public function widget($args, $instance) {
1319 1319
 			// outputs the content of the widget
1320 1320
 
1321 1321
 			// get the filtered values
1322
-			$argument_values = $this->argument_values( $instance );
1323
-			$argument_values = $this->string_to_bool( $argument_values );
1324
-			$output = $this->output( $argument_values, $args );
1322
+			$argument_values = $this->argument_values($instance);
1323
+			$argument_values = $this->string_to_bool($argument_values);
1324
+			$output = $this->output($argument_values, $args);
1325 1325
 
1326
-			if ( $output ) {
1326
+			if ($output) {
1327 1327
 				// Before widget
1328 1328
 				$before_widget = $args['before_widget'];
1329
-				$before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this );
1330
-				$before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this );
1329
+				$before_widget = apply_filters('wp_super_duper_before_widget', $before_widget, $args, $instance, $this);
1330
+				$before_widget = apply_filters('wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this);
1331 1331
 
1332 1332
 				// After widget
1333 1333
 				$after_widget = $args['after_widget'];
1334
-				$after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this );
1335
-				$after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this );
1334
+				$after_widget = apply_filters('wp_super_duper_after_widget', $after_widget, $args, $instance, $this);
1335
+				$after_widget = apply_filters('wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this);
1336 1336
 
1337 1337
 				echo $before_widget;
1338 1338
 				echo $this->output_title($args, $instance);
@@ -1349,11 +1349,11 @@  discard block
 block discarded – undo
1349 1349
 		 *
1350 1350
 		 * @return string
1351 1351
 		 */
1352
-		public function output_title($args, $instance = array()){
1352
+		public function output_title($args, $instance = array()) {
1353 1353
 			$output = '';
1354
-			if ( ! empty( $instance['title'] ) ) {
1354
+			if (!empty($instance['title'])) {
1355 1355
 				/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
1356
-				$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
1356
+				$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
1357 1357
 				$output = $args['before_title'] . $title . $args['after_title'];
1358 1358
 			}
1359 1359
 			return $output;
@@ -1364,7 +1364,7 @@  discard block
 block discarded – undo
1364 1364
 		 *
1365 1365
 		 * @param array $instance The widget options.
1366 1366
 		 */
1367
-		public function form( $instance ) {
1367
+		public function form($instance) {
1368 1368
 
1369 1369
 			// set widget instance
1370 1370
 			$this->instance = $instance;
@@ -1373,15 +1373,15 @@  discard block
 block discarded – undo
1373 1373
 			echo $this->widget_advanced_toggle();
1374 1374
 
1375 1375
 
1376
-			echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>";
1376
+			echo "<p>" . esc_attr($this->options['widget_ops']['description']) . "</p>";
1377 1377
 			$arguments = $this->get_arguments();
1378 1378
 //			print_r($instance );
1379 1379
 //			echo '###';
1380 1380
 //			print_r($arguments  );
1381 1381
 
1382
-			if ( is_array( $arguments ) ) {
1383
-				foreach ( $arguments as $key => $args ) {
1384
-					$this->widget_inputs( $args, $instance );
1382
+			if (is_array($arguments)) {
1383
+				foreach ($arguments as $key => $args) {
1384
+					$this->widget_inputs($args, $instance);
1385 1385
 				}
1386 1386
 			}
1387 1387
 		}
@@ -1394,12 +1394,12 @@  discard block
 block discarded – undo
1394 1394
 		public function widget_advanced_toggle() {
1395 1395
 
1396 1396
 			$output = '';
1397
-			if ( $this->block_show_advanced() ) {
1397
+			if ($this->block_show_advanced()) {
1398 1398
 				$val = 1;
1399 1399
 			} else {
1400 1400
 				$val = 0;
1401 1401
 			}
1402
-			if($val){
1402
+			if ($val) {
1403 1403
 //				$output .=  '<span class="sd-advanced-button-container"><button class="button button-primary right sd-advanced-button" onclick="sd_toggle_advanced(this);return false;"><i class="fas fa-sliders-h" aria-hidden="true"></i></button></span>';
1404 1404
 			}
1405 1405
 
@@ -1420,14 +1420,14 @@  discard block
 block discarded – undo
1420 1420
 		 * @param string $input Input element.
1421 1421
 		 * @return string $output
1422 1422
 		 */
1423
-		public function convert_element_require( $input ) {
1423
+		public function convert_element_require($input) {
1424 1424
 
1425
-			$input = str_replace( "'", '"', $input );// we only want double quotes
1425
+			$input = str_replace("'", '"', $input); // we only want double quotes
1426 1426
 
1427
-			$output = esc_attr( str_replace( array( "[%", "%]" ), array(
1427
+			$output = esc_attr(str_replace(array("[%", "%]"), array(
1428 1428
 				"jQuery(form).find('[data-argument=\"",
1429 1429
 				"\"]').find('input,select').val()"
1430
-			), $input ) );
1430
+			), $input));
1431 1431
 
1432 1432
 
1433 1433
 			return $output;
@@ -1439,7 +1439,7 @@  discard block
 block discarded – undo
1439 1439
 		 * @param $args
1440 1440
 		 * @param $instance
1441 1441
 		 */
1442
-		public function widget_inputs( $args, $instance ) {
1442
+		public function widget_inputs($args, $instance) {
1443 1443
 
1444 1444
 //print_r($instance );echo '###';
1445 1445
 //print_r($args );
@@ -1448,34 +1448,34 @@  discard block
 block discarded – undo
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
 
@@ -1483,15 +1483,15 @@  discard block
 block discarded – undo
1483 1483
 
1484 1484
 			// before wrapper
1485 1485
 			?>
1486
-			<p class="sd-argument <?php echo esc_attr( $class ); ?>"
1487
-			   data-argument='<?php echo esc_attr( $args['name'] ); ?>'
1488
-			   data-element_require='<?php if ( $element_require ) {
1489
-				   echo $this->convert_element_require( $element_require );
1486
+			<p class="sd-argument <?php echo esc_attr($class); ?>"
1487
+			   data-argument='<?php echo esc_attr($args['name']); ?>'
1488
+			   data-element_require='<?php if ($element_require) {
1489
+				   echo $this->convert_element_require($element_require);
1490 1490
 			   } ?>'
1491 1491
 			>
1492 1492
 				<?php
1493 1493
 
1494
-				switch ( $args['type'] ) {
1494
+				switch ($args['type']) {
1495 1495
 					//array('text','password','number','email','tel','url','color')
1496 1496
 					case "text":
1497 1497
 					case "password":
@@ -1502,26 +1502,26 @@  discard block
 block discarded – undo
1502 1502
 					case "color":
1503 1503
 						?>
1504 1504
 						<label
1505
-							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>
1505
+							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>
1506 1506
 						<input <?php echo $placeholder; ?> class="widefat"
1507
-							<?php echo $custom_attributes;?>
1508
-							                               id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1509
-							                               name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>"
1510
-							                               type="<?php echo esc_attr( $args['type'] ); ?>"
1511
-							                               value="<?php echo esc_attr( $value ); ?>">
1507
+							<?php echo $custom_attributes; ?>
1508
+							                               id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1509
+							                               name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>"
1510
+							                               type="<?php echo esc_attr($args['type']); ?>"
1511
+							                               value="<?php echo esc_attr($value); ?>">
1512 1512
 						<?php
1513 1513
 
1514 1514
 						break;
1515 1515
 					case "select":
1516
-						$multiple = isset( $args['multiple'] ) && $args['multiple']  ? true : false;
1517
-						if($multiple){if(empty($value)){$value = array();}}
1516
+						$multiple = isset($args['multiple']) && $args['multiple'] ? true : false;
1517
+						if ($multiple) {if (empty($value)) {$value = array(); }}
1518 1518
 						?>
1519 1519
 						<label
1520
-							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>
1520
+							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 1521
 						<select <?php echo $placeholder; ?> class="widefat"
1522
-							<?php echo $custom_attributes;?>
1523
-							                                id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1524
-							                                name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); if($multiple){echo "[]";}?>"
1522
+							<?php echo $custom_attributes; ?>
1523
+							                                id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1524
+							                                name="<?php echo esc_attr($this->get_field_name($args['name'])); if ($multiple) {echo "[]"; }?>"
1525 1525
 							<?php if ($multiple) {
1526 1526
 								echo "multiple";
1527 1527
 							} //@todo not implemented yet due to gutenberg not supporting it
@@ -1530,12 +1530,12 @@  discard block
 block discarded – undo
1530 1530
 							<?php
1531 1531
 
1532 1532
 
1533
-							if ( ! empty( $args['options'] ) ) {
1534
-								foreach ( $args['options'] as $val => $label ) {
1533
+							if (!empty($args['options'])) {
1534
+								foreach ($args['options'] as $val => $label) {
1535 1535
 //									print_r($value);
1536 1536
 //									echo '@@@'.print_r($val,true),'@@@';
1537 1537
 //									echo '###'.$value.'###';
1538
-									if ($multiple) {$selected = in_array($val,$value) ? 'selected="selected"' : ''; }else{$selected = selected( $value, $val, false );}
1538
+									if ($multiple) {$selected = in_array($val, $value) ? 'selected="selected"' : ''; } else {$selected = selected($value, $val, false); }
1539 1539
 									echo "<option value='$val' " . $selected . ">$label</option>";
1540 1540
 								}
1541 1541
 							}
@@ -1546,20 +1546,20 @@  discard block
 block discarded – undo
1546 1546
 					case "checkbox":
1547 1547
 						?>
1548 1548
 						<input <?php echo $placeholder; ?>
1549
-							<?php checked( 1, $value, true ) ?>
1550
-							<?php echo $custom_attributes;?>
1551
-							class="widefat" id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1552
-							name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="checkbox"
1549
+							<?php checked(1, $value, true) ?>
1550
+							<?php echo $custom_attributes; ?>
1551
+							class="widefat" id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1552
+							name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="checkbox"
1553 1553
 							value="1">
1554 1554
 						<label
1555
-							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>
1555
+							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>
1556 1556
 						<?php
1557 1557
 						break;
1558 1558
 					case "hidden":
1559 1559
 						?>
1560
-						<input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>"
1561
-						       name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden"
1562
-						       value="<?php echo esc_attr( $value ); ?>">
1560
+						<input id="<?php echo esc_attr($this->get_field_id($args['name'])); ?>"
1561
+						       name="<?php echo esc_attr($this->get_field_name($args['name'])); ?>" type="hidden"
1562
+						       value="<?php echo esc_attr($value); ?>">
1563 1563
 						<?php
1564 1564
 						break;
1565 1565
 					default:
@@ -1582,14 +1582,14 @@  discard block
 block discarded – undo
1582 1582
 		 * @return string
1583 1583
 		 * @todo, need to make its own tooltip script
1584 1584
 		 */
1585
-		public function widget_field_desc( $args ) {
1585
+		public function widget_field_desc($args) {
1586 1586
 
1587 1587
 			$description = '';
1588
-			if ( isset( $args['desc'] ) && $args['desc'] ) {
1589
-				if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) {
1590
-					$description = $this->desc_tip( $args['desc'] );
1588
+			if (isset($args['desc']) && $args['desc']) {
1589
+				if (isset($args['desc_tip']) && $args['desc_tip']) {
1590
+					$description = $this->desc_tip($args['desc']);
1591 1591
 				} else {
1592
-					$description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>';
1592
+					$description = '<span class="description">' . wp_kses_post($args['desc']) . '</span>';
1593 1593
 				}
1594 1594
 			}
1595 1595
 
@@ -1605,11 +1605,11 @@  discard block
 block discarded – undo
1605 1605
 		 *
1606 1606
 		 * @return string
1607 1607
 		 */
1608
-		function desc_tip( $tip, $allow_html = false ) {
1609
-			if ( $allow_html ) {
1610
-				$tip = $this->sanitize_tooltip( $tip );
1608
+		function desc_tip($tip, $allow_html = false) {
1609
+			if ($allow_html) {
1610
+				$tip = $this->sanitize_tooltip($tip);
1611 1611
 			} else {
1612
-				$tip = esc_attr( $tip );
1612
+				$tip = esc_attr($tip);
1613 1613
 			}
1614 1614
 
1615 1615
 			return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>';
@@ -1622,8 +1622,8 @@  discard block
 block discarded – undo
1622 1622
 		 *
1623 1623
 		 * @return string
1624 1624
 		 */
1625
-		public function sanitize_tooltip( $var ) {
1626
-			return htmlspecialchars( wp_kses( html_entity_decode( $var ), array(
1625
+		public function sanitize_tooltip($var) {
1626
+			return htmlspecialchars(wp_kses(html_entity_decode($var), array(
1627 1627
 				'br'     => array(),
1628 1628
 				'em'     => array(),
1629 1629
 				'strong' => array(),
@@ -1633,7 +1633,7 @@  discard block
 block discarded – undo
1633 1633
 				'li'     => array(),
1634 1634
 				'ol'     => array(),
1635 1635
 				'p'      => array(),
1636
-			) ) );
1636
+			)));
1637 1637
 		}
1638 1638
 
1639 1639
 		/**
@@ -1645,25 +1645,25 @@  discard block
 block discarded – undo
1645 1645
 		 * @return array
1646 1646
 		 * @todo we should add some sanitation here.
1647 1647
 		 */
1648
-		public function update( $new_instance, $old_instance ) {
1648
+		public function update($new_instance, $old_instance) {
1649 1649
 //			print_r($new_instance);
1650 1650
 //			print_r($old_instance);
1651 1651
 //			exit;
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
 			}
@@ -1679,9 +1679,9 @@  discard block
 block discarded – undo
1679 1679
 		 * @since 1.0.3
1680 1680
 		 * @return bool
1681 1681
 		 */
1682
-		public function is_block_content_call(){
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.
vendor/ayecode/wp-font-awesome-settings/wp-font-awesome-settings.php 2 patches
Indentation   +342 added lines, -342 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,274 +21,274 @@  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
-	 * @ver 1.0.8
29
-	 * @todo decide how to implement textdomain
30
-	 */
31
-	class WP_Font_Awesome_Settings {
32
-
33
-		/**
34
-		 * Class version version.
35
-		 *
36
-		 * @var string
37
-		 */
38
-		public $version = '1.0.8';
39
-
40
-		/**
41
-		 * Latest version of Font Awesome at time of publish published.
42
-		 *
43
-		 * @var string
44
-		 */
45
-		public $latest = "5.6.0";
46
-
47
-		/**
48
-		 * The title.
49
-		 *
50
-		 * @var string
51
-		 */
52
-		public $name = 'Font Awesome';
53
-
54
-		/**
55
-		 * Holds the settings values.
56
-		 *
57
-		 * @var array
58
-		 */
59
-		private $settings;
60
-
61
-		/**
62
-		 * WP_Font_Awesome_Settings instance.
63
-		 *
64
-		 * @access private
65
-		 * @since  1.0.0
66
-		 * @var    WP_Font_Awesome_Settings There can be only one!
67
-		 */
68
-		private static $instance = null;
69
-
70
-		/**
71
-		 * Main WP_Font_Awesome_Settings Instance.
72
-		 *
73
-		 * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
74
-		 *
75
-		 * @since 1.0.0
76
-		 * @static
77
-		 * @return WP_Font_Awesome_Settings - Main instance.
78
-		 */
79
-		public static function instance() {
80
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
81
-				self::$instance = new WP_Font_Awesome_Settings;
82
-
83
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
84
-
85
-				if ( is_admin() ) {
86
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
87
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
88
-				}
89
-
90
-				do_action( 'wp_font_awesome_settings_loaded' );
91
-			}
92
-
93
-			return self::$instance;
94
-		}
95
-
96
-		/**
97
-		 * Initiate the settings and add the required action hooks.
98
-		 *
99
-		 * @since 1.0.8 Settings name wrong - FIXED
100
-		 */
101
-		public function init() {
102
-			$this->settings = $this->get_settings();
103
-
104
-			if ( $this->settings['type'] == 'CSS' ) {
105
-
106
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
107
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit;
108
-				}
109
-
110
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
111
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
112
-				}
113
-
114
-			} else {
115
-
116
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
117
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit;
118
-				}
119
-
120
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
121
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
122
-				}
123
-			}
124
-
125
-			// remove font awesome if set to do so
126
-			if ( $this->settings['dequeue'] == '1' ) {
127
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
128
-			}
129
-
130
-		}
131
-
132
-		/**
133
-		 * Adds the Font Awesome styles.
134
-		 */
135
-		public function enqueue_style() {
136
-			// build url
137
-			$url = $this->get_url();
138
-
139
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
140
-			wp_register_style( 'font-awesome', $url, array(), null );
141
-			wp_enqueue_style( 'font-awesome' );
142
-
143
-			if ( $this->settings['shims'] ) {
144
-				$url = $this->get_url( true );
145
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
146
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
147
-				wp_enqueue_style( 'font-awesome-shims' );
148
-			}
149
-		}
150
-
151
-		/**
152
-		 * Adds the Font Awesome JS.
153
-		 */
154
-		public function enqueue_scripts() {
155
-			// build url
156
-			$url = $this->get_url();
157
-
158
-			wp_deregister_script( 'font-awesome' ); // deregister in case its already there
159
-			wp_register_script( 'font-awesome', $url, array(), null );
160
-			wp_enqueue_script( 'font-awesome' );
161
-
162
-			if ( $this->settings['shims'] ) {
163
-				$url = $this->get_url( true );
164
-				wp_deregister_script( 'font-awesome-shims' ); // deregister in case its already there
165
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
166
-				wp_enqueue_script( 'font-awesome-shims' );
167
-			}
168
-		}
169
-
170
-		/**
171
-		 * Get the url of the Font Awesome files.
172
-		 *
173
-		 * @param bool $shims If this is a shim file or not.
174
-		 *
175
-		 * @return string The url to the file.
176
-		 */
177
-		public function get_url( $shims = false ) {
178
-			$script  = $shims ? 'v4-shims' : 'all';
179
-			$type    = $this->settings['type'];
180
-			$version = $this->settings['version'];
181
-
182
-			$url = "https://use.fontawesome.com/releases/"; // CDN
183
-			$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
184
-			$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
185
-			$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
186
-			$url .= "?wpfas=true"; // set our var so our version is not removed
187
-
188
-			return $url;
189
-		}
190
-
191
-		/**
192
-		 * Try and remove any other versions of Font Awesome added by other plugins/themes.
193
-		 *
194
-		 * 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.
195
-		 *
196
-		 * @param $url
197
-		 * @param $original_url
198
-		 * @param $_context
199
-		 *
200
-		 * @return string The filtered url.
201
-		 */
202
-		public function remove_font_awesome( $url, $original_url, $_context ) {
203
-
204
-			if ( $_context == 'display'
205
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
206
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
207
-			) {// it's a font-awesome-url (probably)
208
-
209
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
210
-					if ( $this->settings['type'] == 'JS' ) {
211
-						if ( $this->settings['js-pseudo'] ) {
212
-							$url .= "' data-search-pseudo-elements defer='defer";
213
-						} else {
214
-							$url .= "' defer='defer";
215
-						}
216
-					}
217
-				} else {
218
-					$url = ''; // removing the url removes the file
219
-				}
220
-
221
-			}
222
-
223
-			return $url;
224
-		}
225
-
226
-		/**
227
-		 * Register the database settings with WordPress.
228
-		 */
229
-		public function register_settings() {
230
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
231
-		}
232
-
233
-		/**
234
-		 * Add the WordPress settings menu item.
235
-		 */
236
-		public function menu_item() {
237
-			add_options_page( $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
238
-				$this,
239
-				'settings_page'
240
-			) );
241
-		}
242
-
243
-		/**
244
-		 * Get the current Font Awesome output settings.
245
-		 *
246
-		 * @return array The array of settings.
247
-		 */
248
-		public function get_settings() {
249
-
250
-			$db_settings = get_option( 'wp-font-awesome-settings' );
251
-
252
-			$defaults = array(
253
-				'type'      => 'CSS', // type to use, CSS or JS
254
-				'version'   => '', // latest
255
-				'enqueue'   => '', // front and backend
256
-				'shims'     => '1', // default on for now, @todo maybe change to off in 2020
257
-				'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
258
-				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
259
-			);
260
-
261
-			$settings = wp_parse_args( $db_settings, $defaults );
262
-
263
-			/**
264
-			 * Filter the Font Awesome settings.
265
-			 *
266
-			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
267
-			 */
268
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
269
-		}
270
-
271
-
272
-		/**
273
-		 * The settings page html output.
274
-		 */
275
-		public function settings_page() {
276
-			if ( ! current_user_can( 'manage_options' ) ) {
277
-				wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
278
-			}
279
-
280
-			// a hidden way to force the update of the verison number vai api instead of waiting the 48 hours
281
-			if(isset($_REQUEST['force-version-check'])){
282
-				$this->get_latest_version($force_api = true);
283
-			}
284
-			?>
24
+    /**
25
+     * A Class to be able to change settings for Font Awesome.
26
+     *
27
+     * Class WP_Font_Awesome_Settings
28
+     * @ver 1.0.8
29
+     * @todo decide how to implement textdomain
30
+     */
31
+    class WP_Font_Awesome_Settings {
32
+
33
+        /**
34
+         * Class version version.
35
+         *
36
+         * @var string
37
+         */
38
+        public $version = '1.0.8';
39
+
40
+        /**
41
+         * Latest version of Font Awesome at time of publish published.
42
+         *
43
+         * @var string
44
+         */
45
+        public $latest = "5.6.0";
46
+
47
+        /**
48
+         * The title.
49
+         *
50
+         * @var string
51
+         */
52
+        public $name = 'Font Awesome';
53
+
54
+        /**
55
+         * Holds the settings values.
56
+         *
57
+         * @var array
58
+         */
59
+        private $settings;
60
+
61
+        /**
62
+         * WP_Font_Awesome_Settings instance.
63
+         *
64
+         * @access private
65
+         * @since  1.0.0
66
+         * @var    WP_Font_Awesome_Settings There can be only one!
67
+         */
68
+        private static $instance = null;
69
+
70
+        /**
71
+         * Main WP_Font_Awesome_Settings Instance.
72
+         *
73
+         * Ensures only one instance of WP_Font_Awesome_Settings is loaded or can be loaded.
74
+         *
75
+         * @since 1.0.0
76
+         * @static
77
+         * @return WP_Font_Awesome_Settings - Main instance.
78
+         */
79
+        public static function instance() {
80
+            if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
81
+                self::$instance = new WP_Font_Awesome_Settings;
82
+
83
+                add_action( 'init', array( self::$instance, 'init' ) ); // set settings
84
+
85
+                if ( is_admin() ) {
86
+                    add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
87
+                    add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
88
+                }
89
+
90
+                do_action( 'wp_font_awesome_settings_loaded' );
91
+            }
92
+
93
+            return self::$instance;
94
+        }
95
+
96
+        /**
97
+         * Initiate the settings and add the required action hooks.
98
+         *
99
+         * @since 1.0.8 Settings name wrong - FIXED
100
+         */
101
+        public function init() {
102
+            $this->settings = $this->get_settings();
103
+
104
+            if ( $this->settings['type'] == 'CSS' ) {
105
+
106
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
107
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit;
108
+                }
109
+
110
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
111
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
112
+                }
113
+
114
+            } else {
115
+
116
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
117
+                    add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit;
118
+                }
119
+
120
+                if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
121
+                    add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
122
+                }
123
+            }
124
+
125
+            // remove font awesome if set to do so
126
+            if ( $this->settings['dequeue'] == '1' ) {
127
+                add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
128
+            }
129
+
130
+        }
131
+
132
+        /**
133
+         * Adds the Font Awesome styles.
134
+         */
135
+        public function enqueue_style() {
136
+            // build url
137
+            $url = $this->get_url();
138
+
139
+            wp_deregister_style( 'font-awesome' ); // deregister in case its already there
140
+            wp_register_style( 'font-awesome', $url, array(), null );
141
+            wp_enqueue_style( 'font-awesome' );
142
+
143
+            if ( $this->settings['shims'] ) {
144
+                $url = $this->get_url( true );
145
+                wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
146
+                wp_register_style( 'font-awesome-shims', $url, array(), null );
147
+                wp_enqueue_style( 'font-awesome-shims' );
148
+            }
149
+        }
150
+
151
+        /**
152
+         * Adds the Font Awesome JS.
153
+         */
154
+        public function enqueue_scripts() {
155
+            // build url
156
+            $url = $this->get_url();
157
+
158
+            wp_deregister_script( 'font-awesome' ); // deregister in case its already there
159
+            wp_register_script( 'font-awesome', $url, array(), null );
160
+            wp_enqueue_script( 'font-awesome' );
161
+
162
+            if ( $this->settings['shims'] ) {
163
+                $url = $this->get_url( true );
164
+                wp_deregister_script( 'font-awesome-shims' ); // deregister in case its already there
165
+                wp_register_script( 'font-awesome-shims', $url, array(), null );
166
+                wp_enqueue_script( 'font-awesome-shims' );
167
+            }
168
+        }
169
+
170
+        /**
171
+         * Get the url of the Font Awesome files.
172
+         *
173
+         * @param bool $shims If this is a shim file or not.
174
+         *
175
+         * @return string The url to the file.
176
+         */
177
+        public function get_url( $shims = false ) {
178
+            $script  = $shims ? 'v4-shims' : 'all';
179
+            $type    = $this->settings['type'];
180
+            $version = $this->settings['version'];
181
+
182
+            $url = "https://use.fontawesome.com/releases/"; // CDN
183
+            $url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
184
+            $url .= $type == 'CSS' ? 'css/' : 'js/'; // type
185
+            $url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
186
+            $url .= "?wpfas=true"; // set our var so our version is not removed
187
+
188
+            return $url;
189
+        }
190
+
191
+        /**
192
+         * Try and remove any other versions of Font Awesome added by other plugins/themes.
193
+         *
194
+         * 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.
195
+         *
196
+         * @param $url
197
+         * @param $original_url
198
+         * @param $_context
199
+         *
200
+         * @return string The filtered url.
201
+         */
202
+        public function remove_font_awesome( $url, $original_url, $_context ) {
203
+
204
+            if ( $_context == 'display'
205
+                 && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
206
+                 && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
207
+            ) {// it's a font-awesome-url (probably)
208
+
209
+                if ( strstr( $url, "wpfas=true" ) !== false ) {
210
+                    if ( $this->settings['type'] == 'JS' ) {
211
+                        if ( $this->settings['js-pseudo'] ) {
212
+                            $url .= "' data-search-pseudo-elements defer='defer";
213
+                        } else {
214
+                            $url .= "' defer='defer";
215
+                        }
216
+                    }
217
+                } else {
218
+                    $url = ''; // removing the url removes the file
219
+                }
220
+
221
+            }
222
+
223
+            return $url;
224
+        }
225
+
226
+        /**
227
+         * Register the database settings with WordPress.
228
+         */
229
+        public function register_settings() {
230
+            register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
231
+        }
232
+
233
+        /**
234
+         * Add the WordPress settings menu item.
235
+         */
236
+        public function menu_item() {
237
+            add_options_page( $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
238
+                $this,
239
+                'settings_page'
240
+            ) );
241
+        }
242
+
243
+        /**
244
+         * Get the current Font Awesome output settings.
245
+         *
246
+         * @return array The array of settings.
247
+         */
248
+        public function get_settings() {
249
+
250
+            $db_settings = get_option( 'wp-font-awesome-settings' );
251
+
252
+            $defaults = array(
253
+                'type'      => 'CSS', // type to use, CSS or JS
254
+                'version'   => '', // latest
255
+                'enqueue'   => '', // front and backend
256
+                'shims'     => '1', // default on for now, @todo maybe change to off in 2020
257
+                'js-pseudo' => '0', // if the pseudo elements flag should be set (CPU intensive)
258
+                'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
259
+            );
260
+
261
+            $settings = wp_parse_args( $db_settings, $defaults );
262
+
263
+            /**
264
+             * Filter the Font Awesome settings.
265
+             *
266
+             * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
267
+             */
268
+            return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
269
+        }
270
+
271
+
272
+        /**
273
+         * The settings page html output.
274
+         */
275
+        public function settings_page() {
276
+            if ( ! current_user_can( 'manage_options' ) ) {
277
+                wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
278
+            }
279
+
280
+            // a hidden way to force the update of the verison number vai api instead of waiting the 48 hours
281
+            if(isset($_REQUEST['force-version-check'])){
282
+                $this->get_latest_version($force_api = true);
283
+            }
284
+            ?>
285 285
 			<div class="wrap">
286 286
 				<h1><?php echo $this->name; ?></h1>
287 287
 				<form method="post" action="options.php">
288 288
 					<?php
289
-					settings_fields( 'wp-font-awesome-settings' );
290
-					do_settings_sections( 'wp-font-awesome-settings' );
291
-					?>
289
+                    settings_fields( 'wp-font-awesome-settings' );
290
+                    do_settings_sections( 'wp-font-awesome-settings' );
291
+                    ?>
292 292
 					<table class="form-table">
293 293
 						<tr valign="top">
294 294
 							<th scope="row"><label for="wpfas-type"><?php _e( 'Type' ); ?></label></th>
@@ -384,87 +384,87 @@  discard block
 block discarded – undo
384 384
 
385 385
 					</table>
386 386
 					<?php
387
-					submit_button();
388
-					?>
387
+                    submit_button();
388
+                    ?>
389 389
 				</form>
390 390
 
391 391
 				<div id="wpfas-version"><?php echo $this->version; ?></div>
392 392
 			</div>
393 393
 
394 394
 			<?php
395
-		}
396
-
397
-		/**
398
-		 * Check a version number is valid and if so return it or else return an empty string.
399
-		 *
400
-		 * @param $version string The version number to check.
401
-		 * @since 1.0.6
402
-		 *
403
-		 * @return string Either a valid version number or an empty string.
404
-		 */
405
-		public function validate_version_number( $version ) {
406
-
407
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
408
-				// valid
409
-			} else {
410
-				$version = '';// not validated
411
-			}
412
-
413
-			return $version;
414
-		}
415
-
416
-
417
-		/**
418
-		 * Get the latest version of Font Awesome.
419
-		 *
420
-		 * 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.
421
-		 *
422
-		 * @since 1.0.7
423
-		 * @return mixed|string The latest version number found.
424
-		 */
425
-		public function get_latest_version($force_api = false) {
426
-			$latest_version = $this->latest;
427
-
428
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
429
-
430
-			if ( $cache === false || $force_api) { // its not set
431
-				$api_ver = $this->get_latest_version_from_api();
432
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
433
-					$latest_version = $api_ver;
434
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
435
-				}
436
-			} elseif ( $this->validate_version_number( $cache ) ) {
437
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
438
-					$latest_version = $cache;
439
-				}
440
-			}
441
-
442
-			return $latest_version;
443
-		}
444
-
445
-		/**
446
-		 * Get the latest Font Awesome version from the github API.
447
-		 *
448
-		 * @since 1.0.7
449
-		 * @return string The latest version number or `0` on API fail.
450
-		 */
451
-		public function get_latest_version_from_api() {
452
-			$version  = "0";
453
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
454
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
455
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
456
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
457
-					$version = $api_response['tag_name'];
458
-				}
459
-			}
460
-
461
-			return $version;
462
-		}
463
-
464
-	}
465
-
466
-	/**
467
-	 * Run the class if found.
468
-	 */
469
-	WP_Font_Awesome_Settings::instance();
395
+        }
396
+
397
+        /**
398
+         * Check a version number is valid and if so return it or else return an empty string.
399
+         *
400
+         * @param $version string The version number to check.
401
+         * @since 1.0.6
402
+         *
403
+         * @return string Either a valid version number or an empty string.
404
+         */
405
+        public function validate_version_number( $version ) {
406
+
407
+            if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
408
+                // valid
409
+            } else {
410
+                $version = '';// not validated
411
+            }
412
+
413
+            return $version;
414
+        }
415
+
416
+
417
+        /**
418
+         * Get the latest version of Font Awesome.
419
+         *
420
+         * 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.
421
+         *
422
+         * @since 1.0.7
423
+         * @return mixed|string The latest version number found.
424
+         */
425
+        public function get_latest_version($force_api = false) {
426
+            $latest_version = $this->latest;
427
+
428
+            $cache = get_transient( 'wp-font-awesome-settings-version' );
429
+
430
+            if ( $cache === false || $force_api) { // its not set
431
+                $api_ver = $this->get_latest_version_from_api();
432
+                if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
433
+                    $latest_version = $api_ver;
434
+                    set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
435
+                }
436
+            } elseif ( $this->validate_version_number( $cache ) ) {
437
+                if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
438
+                    $latest_version = $cache;
439
+                }
440
+            }
441
+
442
+            return $latest_version;
443
+        }
444
+
445
+        /**
446
+         * Get the latest Font Awesome version from the github API.
447
+         *
448
+         * @since 1.0.7
449
+         * @return string The latest version number or `0` on API fail.
450
+         */
451
+        public function get_latest_version_from_api() {
452
+            $version  = "0";
453
+            $response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
454
+            if ( ! is_wp_error( $response ) && is_array( $response ) ) {
455
+                $api_response = json_decode( wp_remote_retrieve_body( $response ), true );
456
+                if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
457
+                    $version = $api_response['tag_name'];
458
+                }
459
+            }
460
+
461
+            return $version;
462
+        }
463
+
464
+    }
465
+
466
+    /**
467
+     * Run the class if found.
468
+     */
469
+    WP_Font_Awesome_Settings::instance();
470 470
 }
471 471
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +93 added lines, -93 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.
@@ -77,17 +77,17 @@  discard block
 block discarded – undo
77 77
 		 * @return WP_Font_Awesome_Settings - Main instance.
78 78
 		 */
79 79
 		public static function instance() {
80
-			if ( ! isset( self::$instance ) && ! ( self::$instance instanceof WP_Font_Awesome_Settings ) ) {
80
+			if (!isset(self::$instance) && !(self::$instance instanceof WP_Font_Awesome_Settings)) {
81 81
 				self::$instance = new WP_Font_Awesome_Settings;
82 82
 
83
-				add_action( 'init', array( self::$instance, 'init' ) ); // set settings
83
+				add_action('init', array(self::$instance, 'init')); // set settings
84 84
 
85
-				if ( is_admin() ) {
86
-					add_action( 'admin_menu', array( self::$instance, 'menu_item' ) );
87
-					add_action( 'admin_init', array( self::$instance, 'register_settings' ) );
85
+				if (is_admin()) {
86
+					add_action('admin_menu', array(self::$instance, 'menu_item'));
87
+					add_action('admin_init', array(self::$instance, 'register_settings'));
88 88
 				}
89 89
 
90
-				do_action( 'wp_font_awesome_settings_loaded' );
90
+				do_action('wp_font_awesome_settings_loaded');
91 91
 			}
92 92
 
93 93
 			return self::$instance;
@@ -101,30 +101,30 @@  discard block
 block discarded – undo
101 101
 		public function init() {
102 102
 			$this->settings = $this->get_settings();
103 103
 
104
-			if ( $this->settings['type'] == 'CSS' ) {
104
+			if ($this->settings['type'] == 'CSS') {
105 105
 
106
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
107
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );//echo '###';exit;
106
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
107
+					add_action('wp_enqueue_scripts', array($this, 'enqueue_style'), 5000); //echo '###';exit;
108 108
 				}
109 109
 
110
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
111
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_style' ), 5000 );
110
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
111
+					add_action('admin_enqueue_scripts', array($this, 'enqueue_style'), 5000);
112 112
 				}
113 113
 
114 114
 			} else {
115 115
 
116
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend' ) {
117
-					add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );//echo '###';exit;
116
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'frontend') {
117
+					add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5000); //echo '###';exit;
118 118
 				}
119 119
 
120
-				if ( $this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend' ) {
121
-					add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ), 5000 );
120
+				if ($this->settings['enqueue'] == '' || $this->settings['enqueue'] == 'backend') {
121
+					add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'), 5000);
122 122
 				}
123 123
 			}
124 124
 
125 125
 			// remove font awesome if set to do so
126
-			if ( $this->settings['dequeue'] == '1' ) {
127
-				add_action( 'clean_url', array( $this, 'remove_font_awesome' ), 5000, 3 );
126
+			if ($this->settings['dequeue'] == '1') {
127
+				add_action('clean_url', array($this, 'remove_font_awesome'), 5000, 3);
128 128
 			}
129 129
 
130 130
 		}
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 			// build url
137 137
 			$url = $this->get_url();
138 138
 
139
-			wp_deregister_style( 'font-awesome' ); // deregister in case its already there
140
-			wp_register_style( 'font-awesome', $url, array(), null );
141
-			wp_enqueue_style( 'font-awesome' );
139
+			wp_deregister_style('font-awesome'); // deregister in case its already there
140
+			wp_register_style('font-awesome', $url, array(), null);
141
+			wp_enqueue_style('font-awesome');
142 142
 
143
-			if ( $this->settings['shims'] ) {
144
-				$url = $this->get_url( true );
145
-				wp_deregister_style( 'font-awesome-shims' ); // deregister in case its already there
146
-				wp_register_style( 'font-awesome-shims', $url, array(), null );
147
-				wp_enqueue_style( 'font-awesome-shims' );
143
+			if ($this->settings['shims']) {
144
+				$url = $this->get_url(true);
145
+				wp_deregister_style('font-awesome-shims'); // deregister in case its already there
146
+				wp_register_style('font-awesome-shims', $url, array(), null);
147
+				wp_enqueue_style('font-awesome-shims');
148 148
 			}
149 149
 		}
150 150
 
@@ -155,15 +155,15 @@  discard block
 block discarded – undo
155 155
 			// build url
156 156
 			$url = $this->get_url();
157 157
 
158
-			wp_deregister_script( 'font-awesome' ); // deregister in case its already there
159
-			wp_register_script( 'font-awesome', $url, array(), null );
160
-			wp_enqueue_script( 'font-awesome' );
158
+			wp_deregister_script('font-awesome'); // deregister in case its already there
159
+			wp_register_script('font-awesome', $url, array(), null);
160
+			wp_enqueue_script('font-awesome');
161 161
 
162
-			if ( $this->settings['shims'] ) {
163
-				$url = $this->get_url( true );
164
-				wp_deregister_script( 'font-awesome-shims' ); // deregister in case its already there
165
-				wp_register_script( 'font-awesome-shims', $url, array(), null );
166
-				wp_enqueue_script( 'font-awesome-shims' );
162
+			if ($this->settings['shims']) {
163
+				$url = $this->get_url(true);
164
+				wp_deregister_script('font-awesome-shims'); // deregister in case its already there
165
+				wp_register_script('font-awesome-shims', $url, array(), null);
166
+				wp_enqueue_script('font-awesome-shims');
167 167
 			}
168 168
 		}
169 169
 
@@ -174,13 +174,13 @@  discard block
 block discarded – undo
174 174
 		 *
175 175
 		 * @return string The url to the file.
176 176
 		 */
177
-		public function get_url( $shims = false ) {
177
+		public function get_url($shims = false) {
178 178
 			$script  = $shims ? 'v4-shims' : 'all';
179 179
 			$type    = $this->settings['type'];
180 180
 			$version = $this->settings['version'];
181 181
 
182 182
 			$url = "https://use.fontawesome.com/releases/"; // CDN
183
-			$url .= ! empty( $version ) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
183
+			$url .= !empty($version) ? "v" . $version . '/' : "v" . $this->get_latest_version() . '/'; // version
184 184
 			$url .= $type == 'CSS' ? 'css/' : 'js/'; // type
185 185
 			$url .= $type == 'CSS' ? $script . '.css' : $script . '.js'; // type
186 186
 			$url .= "?wpfas=true"; // set our var so our version is not removed
@@ -199,16 +199,16 @@  discard block
 block discarded – undo
199 199
 		 *
200 200
 		 * @return string The filtered url.
201 201
 		 */
202
-		public function remove_font_awesome( $url, $original_url, $_context ) {
202
+		public function remove_font_awesome($url, $original_url, $_context) {
203 203
 
204
-			if ( $_context == 'display'
205
-			     && ( strstr( $url, "fontawesome" ) !== false || strstr( $url, "font-awesome" ) !== false )
206
-			     && ( strstr( $url, ".js" ) !== false || strstr( $url, ".css" ) !== false )
204
+			if ($_context == 'display'
205
+			     && (strstr($url, "fontawesome") !== false || strstr($url, "font-awesome") !== false)
206
+			     && (strstr($url, ".js") !== false || strstr($url, ".css") !== false)
207 207
 			) {// it's a font-awesome-url (probably)
208 208
 
209
-				if ( strstr( $url, "wpfas=true" ) !== false ) {
210
-					if ( $this->settings['type'] == 'JS' ) {
211
-						if ( $this->settings['js-pseudo'] ) {
209
+				if (strstr($url, "wpfas=true") !== false) {
210
+					if ($this->settings['type'] == 'JS') {
211
+						if ($this->settings['js-pseudo']) {
212 212
 							$url .= "' data-search-pseudo-elements defer='defer";
213 213
 						} else {
214 214
 							$url .= "' defer='defer";
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
 		 * Register the database settings with WordPress.
228 228
 		 */
229 229
 		public function register_settings() {
230
-			register_setting( 'wp-font-awesome-settings', 'wp-font-awesome-settings' );
230
+			register_setting('wp-font-awesome-settings', 'wp-font-awesome-settings');
231 231
 		}
232 232
 
233 233
 		/**
234 234
 		 * Add the WordPress settings menu item.
235 235
 		 */
236 236
 		public function menu_item() {
237
-			add_options_page( $this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
237
+			add_options_page($this->name, $this->name, 'manage_options', 'wp-font-awesome-settings', array(
238 238
 				$this,
239 239
 				'settings_page'
240
-			) );
240
+			));
241 241
 		}
242 242
 
243 243
 		/**
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 		 */
248 248
 		public function get_settings() {
249 249
 
250
-			$db_settings = get_option( 'wp-font-awesome-settings' );
250
+			$db_settings = get_option('wp-font-awesome-settings');
251 251
 
252 252
 			$defaults = array(
253 253
 				'type'      => 'CSS', // type to use, CSS or JS
@@ -258,14 +258,14 @@  discard block
 block discarded – undo
258 258
 				'dequeue'   => '0', // if we should try to remove other versions added by other plugins/themes
259 259
 			);
260 260
 
261
-			$settings = wp_parse_args( $db_settings, $defaults );
261
+			$settings = wp_parse_args($db_settings, $defaults);
262 262
 
263 263
 			/**
264 264
 			 * Filter the Font Awesome settings.
265 265
 			 *
266 266
 			 * @todo if we add this filer people might use it and then it defeates the purpose of this class :/
267 267
 			 */
268
-			return $this->settings = apply_filters( 'wp-font-awesome-settings', $settings, $db_settings, $defaults );
268
+			return $this->settings = apply_filters('wp-font-awesome-settings', $settings, $db_settings, $defaults);
269 269
 		}
270 270
 
271 271
 
@@ -273,12 +273,12 @@  discard block
 block discarded – undo
273 273
 		 * The settings page html output.
274 274
 		 */
275 275
 		public function settings_page() {
276
-			if ( ! current_user_can( 'manage_options' ) ) {
277
-				wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
276
+			if (!current_user_can('manage_options')) {
277
+				wp_die(__('You do not have sufficient permissions to access this page.'));
278 278
 			}
279 279
 
280 280
 			// a hidden way to force the update of the verison number vai api instead of waiting the 48 hours
281
-			if(isset($_REQUEST['force-version-check'])){
281
+			if (isset($_REQUEST['force-version-check'])) {
282 282
 				$this->get_latest_version($force_api = true);
283 283
 			}
284 284
 			?>
@@ -286,46 +286,46 @@  discard block
 block discarded – undo
286 286
 				<h1><?php echo $this->name; ?></h1>
287 287
 				<form method="post" action="options.php">
288 288
 					<?php
289
-					settings_fields( 'wp-font-awesome-settings' );
290
-					do_settings_sections( 'wp-font-awesome-settings' );
289
+					settings_fields('wp-font-awesome-settings');
290
+					do_settings_sections('wp-font-awesome-settings');
291 291
 					?>
292 292
 					<table class="form-table">
293 293
 						<tr valign="top">
294
-							<th scope="row"><label for="wpfas-type"><?php _e( 'Type' ); ?></label></th>
294
+							<th scope="row"><label for="wpfas-type"><?php _e('Type'); ?></label></th>
295 295
 							<td>
296 296
 								<select name="wp-font-awesome-settings[type]" id="wpfas-type">
297 297
 									<option
298
-										value="CSS" <?php selected( $this->settings['type'], 'CSS' ); ?>><?php _e( 'CSS (default)' ); ?></option>
299
-									<option value="JS" <?php selected( $this->settings['type'], 'JS' ); ?>>JS</option>
298
+										value="CSS" <?php selected($this->settings['type'], 'CSS'); ?>><?php _e('CSS (default)'); ?></option>
299
+									<option value="JS" <?php selected($this->settings['type'], 'JS'); ?>>JS</option>
300 300
 								</select>
301 301
 							</td>
302 302
 						</tr>
303 303
 
304 304
 						<tr valign="top">
305
-							<th scope="row"><label for="wpfas-version"><?php _e( 'Version' ); ?></label></th>
305
+							<th scope="row"><label for="wpfas-version"><?php _e('Version'); ?></label></th>
306 306
 							<td>
307 307
 								<select name="wp-font-awesome-settings[version]" id="wpfas-version">
308 308
 									<option
309
-										value="" <?php selected( $this->settings['version'], '' ); ?>><?php echo sprintf( __( 'Latest - %s (default)' ), $this->get_latest_version() ); ?></option>
310
-									<option value="5.5.0" <?php selected( $this->settings['version'], '5.6.0' ); ?>>
309
+										value="" <?php selected($this->settings['version'], ''); ?>><?php echo sprintf(__('Latest - %s (default)'), $this->get_latest_version()); ?></option>
310
+									<option value="5.5.0" <?php selected($this->settings['version'], '5.6.0'); ?>>
311 311
 										5.6.0
312 312
 									</option>
313
-									<option value="5.5.0" <?php selected( $this->settings['version'], '5.5.0' ); ?>>
313
+									<option value="5.5.0" <?php selected($this->settings['version'], '5.5.0'); ?>>
314 314
 										5.5.0
315 315
 									</option>
316
-									<option value="5.4.0" <?php selected( $this->settings['version'], '5.4.0' ); ?>>
316
+									<option value="5.4.0" <?php selected($this->settings['version'], '5.4.0'); ?>>
317 317
 										5.4.0
318 318
 									</option>
319
-									<option value="5.3.0" <?php selected( $this->settings['version'], '5.3.0' ); ?>>
319
+									<option value="5.3.0" <?php selected($this->settings['version'], '5.3.0'); ?>>
320 320
 										5.3.0
321 321
 									</option>
322
-									<option value="5.2.0" <?php selected( $this->settings['version'], '5.2.0' ); ?>>
322
+									<option value="5.2.0" <?php selected($this->settings['version'], '5.2.0'); ?>>
323 323
 										5.2.0
324 324
 									</option>
325
-									<option value="5.1.0" <?php selected( $this->settings['version'], '5.1.0' ); ?>>
325
+									<option value="5.1.0" <?php selected($this->settings['version'], '5.1.0'); ?>>
326 326
 										5.1.0
327 327
 									</option>
328
-									<option value="4.7.0" <?php selected( $this->settings['version'], '4.7.0' ); ?>>
328
+									<option value="4.7.0" <?php selected($this->settings['version'], '4.7.0'); ?>>
329 329
 										4.7.1 (CSS only)
330 330
 									</option>
331 331
 								</select>
@@ -333,51 +333,51 @@  discard block
 block discarded – undo
333 333
 						</tr>
334 334
 
335 335
 						<tr valign="top">
336
-							<th scope="row"><label for="wpfas-enqueue"><?php _e( 'Enqueue' ); ?></label></th>
336
+							<th scope="row"><label for="wpfas-enqueue"><?php _e('Enqueue'); ?></label></th>
337 337
 							<td>
338 338
 								<select name="wp-font-awesome-settings[enqueue]" id="wpfas-enqueue">
339 339
 									<option
340
-										value="" <?php selected( $this->settings['enqueue'], '' ); ?>><?php _e( 'Frontend + Backend (default)' ); ?></option>
340
+										value="" <?php selected($this->settings['enqueue'], ''); ?>><?php _e('Frontend + Backend (default)'); ?></option>
341 341
 									<option
342
-										value="frontend" <?php selected( $this->settings['enqueue'], 'frontend' ); ?>><?php _e( 'Frontend' ); ?></option>
342
+										value="frontend" <?php selected($this->settings['enqueue'], 'frontend'); ?>><?php _e('Frontend'); ?></option>
343 343
 									<option
344
-										value="backend" <?php selected( $this->settings['enqueue'], 'backend' ); ?>><?php _e( 'Backend' ); ?></option>
344
+										value="backend" <?php selected($this->settings['enqueue'], 'backend'); ?>><?php _e('Backend'); ?></option>
345 345
 								</select>
346 346
 							</td>
347 347
 						</tr>
348 348
 
349 349
 						<tr valign="top">
350 350
 							<th scope="row"><label
351
-									for="wpfas-shims"><?php _e( 'Enable v4 shims compatibility' ); ?></label></th>
351
+									for="wpfas-shims"><?php _e('Enable v4 shims compatibility'); ?></label></th>
352 352
 							<td>
353 353
 								<input type="hidden" name="wp-font-awesome-settings[shims]" value="0"/>
354 354
 								<input type="checkbox" name="wp-font-awesome-settings[shims]"
355
-								       value="1" <?php checked( $this->settings['shims'], '1' ); ?> id="wpfas-shims"/>
356
-								<span><?php _e( 'This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.' ); ?></span>
355
+								       value="1" <?php checked($this->settings['shims'], '1'); ?> id="wpfas-shims"/>
356
+								<span><?php _e('This enables v4 classes to work with v5, sort of like a band-aid until everyone has updated everything to v5.'); ?></span>
357 357
 							</td>
358 358
 						</tr>
359 359
 
360 360
 						<tr valign="top">
361 361
 							<th scope="row"><label
362
-									for="wpfas-js-pseudo"><?php _e( 'Enable JS pseudo elements (not recommended)' ); ?></label>
362
+									for="wpfas-js-pseudo"><?php _e('Enable JS pseudo elements (not recommended)'); ?></label>
363 363
 							</th>
364 364
 							<td>
365 365
 								<input type="hidden" name="wp-font-awesome-settings[js-pseudo]" value="0"/>
366 366
 								<input type="checkbox" name="wp-font-awesome-settings[js-pseudo]"
367
-								       value="1" <?php checked( $this->settings['js-pseudo'], '1' ); ?>
367
+								       value="1" <?php checked($this->settings['js-pseudo'], '1'); ?>
368 368
 								       id="wpfas-js-pseudo"/>
369
-								<span><?php _e( 'Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.' ); ?></span>
369
+								<span><?php _e('Used only with the JS version, this will make pseudo-elements work but can be CPU intensive on some sites.'); ?></span>
370 370
 							</td>
371 371
 						</tr>
372 372
 
373 373
 						<tr valign="top">
374
-							<th scope="row"><label for="wpfas-dequeue"><?php _e( 'Dequeue' ); ?></label></th>
374
+							<th scope="row"><label for="wpfas-dequeue"><?php _e('Dequeue'); ?></label></th>
375 375
 							<td>
376 376
 								<input type="hidden" name="wp-font-awesome-settings[dequeue]" value="0"/>
377 377
 								<input type="checkbox" name="wp-font-awesome-settings[dequeue]"
378
-								       value="1" <?php checked( $this->settings['dequeue'], '1' ); ?>
378
+								       value="1" <?php checked($this->settings['dequeue'], '1'); ?>
379 379
 								       id="wpfas-dequeue"/>
380
-								<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.' ); ?></span>
380
+								<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.'); ?></span>
381 381
 							</td>
382 382
 						</tr>
383 383
 
@@ -402,12 +402,12 @@  discard block
 block discarded – undo
402 402
 		 *
403 403
 		 * @return string Either a valid version number or an empty string.
404 404
 		 */
405
-		public function validate_version_number( $version ) {
405
+		public function validate_version_number($version) {
406 406
 
407
-			if ( version_compare( $version, '0.0.1', '>=' ) >= 0 ) {
407
+			if (version_compare($version, '0.0.1', '>=') >= 0) {
408 408
 				// valid
409 409
 			} else {
410
-				$version = '';// not validated
410
+				$version = ''; // not validated
411 411
 			}
412 412
 
413 413
 			return $version;
@@ -425,16 +425,16 @@  discard block
 block discarded – undo
425 425
 		public function get_latest_version($force_api = false) {
426 426
 			$latest_version = $this->latest;
427 427
 
428
-			$cache = get_transient( 'wp-font-awesome-settings-version' );
428
+			$cache = get_transient('wp-font-awesome-settings-version');
429 429
 
430
-			if ( $cache === false || $force_api) { // its not set
430
+			if ($cache === false || $force_api) { // its not set
431 431
 				$api_ver = $this->get_latest_version_from_api();
432
-				if ( version_compare( $api_ver, $this->latest, '>=' ) >= 0 ) {
432
+				if (version_compare($api_ver, $this->latest, '>=') >= 0) {
433 433
 					$latest_version = $api_ver;
434
-					set_transient( 'wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS );
434
+					set_transient('wp-font-awesome-settings-version', $api_ver, 48 * HOUR_IN_SECONDS);
435 435
 				}
436
-			} elseif ( $this->validate_version_number( $cache ) ) {
437
-				if ( version_compare( $cache, $this->latest, '>=' ) >= 0 ) {
436
+			} elseif ($this->validate_version_number($cache)) {
437
+				if (version_compare($cache, $this->latest, '>=') >= 0) {
438 438
 					$latest_version = $cache;
439 439
 				}
440 440
 			}
@@ -450,10 +450,10 @@  discard block
 block discarded – undo
450 450
 		 */
451 451
 		public function get_latest_version_from_api() {
452 452
 			$version  = "0";
453
-			$response = wp_remote_get( "https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest" );
454
-			if ( ! is_wp_error( $response ) && is_array( $response ) ) {
455
-				$api_response = json_decode( wp_remote_retrieve_body( $response ), true );
456
-				if ( isset( $api_response['tag_name'] ) && version_compare( $api_response['tag_name'], $this->latest, '>=' ) >= 0 && empty( $api_response['prerelease'] ) ) {
453
+			$response = wp_remote_get("https://api.github.com/repos/FortAwesome/Font-Awesome/releases/latest");
454
+			if (!is_wp_error($response) && is_array($response)) {
455
+				$api_response = json_decode(wp_remote_retrieve_body($response), true);
456
+				if (isset($api_response['tag_name']) && version_compare($api_response['tag_name'], $this->latest, '>=') >= 0 && empty($api_response['prerelease'])) {
457 457
 					$version = $api_response['tag_name'];
458 458
 				}
459 459
 			}
Please login to merge, or discard this patch.